Skip to content

[DebugInfo] Remove spare bits mask from LLVM IR and DWARF #9425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ struct DescriptorFinderForwarder : public swift::reflection::DescriptorFinder {
return nullptr;
}

std::unique_ptr<swift::reflection::MultiPayloadEnumDescriptorBase>
getMultiPayloadEnumDescriptor(const swift::reflection::TypeRef *TR) override {
if (!m_descriptor_finders.empty() && shouldConsultDescriptorFinder())
return m_descriptor_finders.back()->getMultiPayloadEnumDescriptor(TR);
return nullptr;
}

void PushExternalDescriptorFinder(
swift::reflection::DescriptorFinder *descriptor_finder) {
m_descriptor_finders.push_back(descriptor_finder);
Expand Down
4 changes: 0 additions & 4 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserSwift.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ class DWARFASTParserSwift : public lldb_private::plugin::dwarf::DWARFASTParser,
std::unique_ptr<swift::reflection::BuiltinTypeDescriptorBase>
getBuiltinTypeDescriptor(const swift::reflection::TypeRef *TR) override;

/// Returns a builtin descriptor constructed from DWARF info.
std::unique_ptr<swift::reflection::MultiPayloadEnumDescriptorBase>
getMultiPayloadEnumDescriptor(const swift::reflection::TypeRef *TR) override;

private:
/// Returns the canonical demangle tree of a die's type.
NodePointer GetCanonicalDemangleTree(DWARFDIE &die);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,53 +280,6 @@ class DWARFFieldDescriptorImpl : public swift::reflection::FieldDescriptorBase {
return payload_fields;
}
};

class DWARFMultiPayloadEnumDescriptorImpl
: public swift::reflection::MultiPayloadEnumDescriptorBase {
ConstString m_mangled_name;
DIERef m_die_ref;
std::vector<uint8_t> m_spare_bits_mask;
uint64_t m_byte_offset;

public:
~DWARFMultiPayloadEnumDescriptorImpl() override = default;

DWARFMultiPayloadEnumDescriptorImpl(ConstString mangled_name, DIERef die_ref,
std::vector<uint8_t> &&spare_bits_mask,
uint64_t byte_offset)
: swift::reflection::MultiPayloadEnumDescriptorBase(),
m_mangled_name(mangled_name), m_die_ref(die_ref),
m_spare_bits_mask(std::move(spare_bits_mask)),
m_byte_offset(byte_offset) {}

llvm::StringRef getMangledTypeName() override {
return m_mangled_name.GetStringRef();
}

uint32_t getContentsSizeInWords() const override {
return m_spare_bits_mask.size() / 4;
}

size_t getSizeInBytes() const override { return m_spare_bits_mask.size(); }

uint32_t getFlags() const override { return usesPayloadSpareBits(); }

bool usesPayloadSpareBits() const override {
return !m_spare_bits_mask.empty();
}

uint32_t getPayloadSpareBitMaskByteOffset() const override {
return m_byte_offset;
}

uint32_t getPayloadSpareBitMaskByteCount() const override {
return getSizeInBytes();
}

const uint8_t *getPayloadSpareBits() const override {
return m_spare_bits_mask.data();
}
};
} // namespace

/// Constructs a builtin type descriptor from DWARF information.
Expand Down Expand Up @@ -374,85 +327,6 @@ DWARFASTParserSwift::getBuiltinTypeDescriptor(
type.GetMangledTypeName());
}

std::unique_ptr<swift::reflection::MultiPayloadEnumDescriptorBase>
DWARFASTParserSwift::getMultiPayloadEnumDescriptor(
const swift::reflection::TypeRef *TR) {
assert(ModuleList::GetGlobalModuleListProperties()
.GetSwiftEnableFullDwarfDebugging() !=
lldb_private::AutoBool::False &&
"Full DWARF debugging for Swift is disabled!");

auto pair = getTypeAndDie(m_swift_typesystem, TR);
if (!pair)
return nullptr;

auto [type, die] = *pair;
if (!die)
return nullptr;

auto kind = getFieldDescriptorKindForDie(type);
if (!kind)
return nullptr;

auto child_die = die.GetFirstChild();
auto bit_offset =
child_die.GetAttributeValueAsUnsigned(llvm::dwarf::DW_AT_bit_offset, 0);

auto byte_offset = (bit_offset + 7) / 8;

const auto &attributes = child_die.GetAttributes();
auto spare_bits_mask_idx =
attributes.FindAttributeIndex(llvm::dwarf::DW_AT_APPLE_spare_bits_mask);
if (spare_bits_mask_idx == UINT32_MAX)
return nullptr;

DWARFFormValue form_value;
attributes.ExtractFormValueAtIndex(spare_bits_mask_idx, form_value);

if (!form_value.IsValid()) {
if (auto *log = GetLog(LLDBLog::Types)) {
std::stringstream ss;
TR->dump(ss);
LLDB_LOG(log,
"Could not produce MultiPayloadEnumTypeInfo for typeref: {0}",
ss.str());
}
return nullptr;
}
// If there's a block data, this is a number bigger than 64 bits already
// encoded as an array.
if (form_value.BlockData()) {
uint64_t block_length = form_value.Unsigned();
std::vector<uint8_t> bytes(form_value.BlockData(),
form_value.BlockData() + block_length);
return std::make_unique<DWARFMultiPayloadEnumDescriptorImpl>(
type.GetMangledTypeName(), *die.GetDIERef(),
std::move(bytes), byte_offset);
}

// If there is no block data, the spare bits mask is encoded as a single 64
// bit number. Convert this to a byte array with only the amount of bytes
// necessary to cover the whole number (see
// MultiPayloadEnumDescriptorBuilder::layout on GenReflection.cpp for a
// similar calculation when emitting this into metadata).
llvm::APInt bits(64, form_value.Unsigned());
auto bitsInMask = bits.getActiveBits();
uint32_t bytesInMask = (bitsInMask + 7) / 8;
auto wordsInMask = (bytesInMask + 3) / 4;
bits = bits.zextOrTrunc(wordsInMask * 32);

std::vector<uint8_t> bytes;
for (size_t i = 0; i < bytesInMask; ++i) {
uint8_t byte = bits.extractBitsAsZExtValue(8, 0);
bytes.push_back(byte);
bits.lshrInPlace(8);
}

return std::make_unique<DWARFMultiPayloadEnumDescriptorImpl>(
type.GetMangledTypeName(), *die.GetDIERef(), std::move(bytes),
byte_offset);
}

namespace {
DWARFDIE FindSuperClassDIE(DWARFDIE &die) {
const auto inheritance_die_it =
Expand Down
1 change: 0 additions & 1 deletion llvm/include/llvm/BinaryFormat/Dwarf.def
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,6 @@ HANDLE_DW_AT(0x3fee, APPLE_objc_direct, 0, APPLE)
HANDLE_DW_AT(0x3fef, APPLE_sdk, 0, APPLE)
HANDLE_DW_AT(0x3ff0, APPLE_origin, 0, APPLE)
HANDLE_DW_AT(0x3ff1, APPLE_num_extra_inhabitants, 0, APPLE)
HANDLE_DW_AT(0x3ff2, APPLE_spare_bits_mask, 0, APPLE)

// Attribute form encodings.
HANDLE_DW_FORM(0x01, addr, 2, DWARF)
Expand Down
7 changes: 1 addition & 6 deletions llvm/include/llvm/IR/DIBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -533,17 +533,12 @@ namespace llvm {
/// \param Discriminator Discriminant member
/// \param Elements Variant elements.
/// \param UniqueIdentifier A unique identifier for the union.
/// \param OffsetInBits The offset of the variant payload in the variant
/// type.
/// \param SpareBitMask A mask of spare bits of the payload, spare bits are
/// bits that aren't used in any of the variant's cases.
DICompositeType *
createVariantPart(DIScope *Scope, StringRef Name, DIFile *File,
unsigned LineNumber, uint64_t SizeInBits,
uint32_t AlignInBits, DINode::DIFlags Flags,
DIDerivedType *Discriminator, DINodeArray Elements,
StringRef UniqueIdentifier = "",
uint64_t OffsetInBits = 0, APInt SpareBitsMask = APInt());
StringRef UniqueIdentifier = "");

/// Create debugging information for template
/// type parameter.
Expand Down
51 changes: 24 additions & 27 deletions llvm/include/llvm/IR/DebugInfoMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -1172,16 +1172,15 @@ class DICompositeType : public DIType {
friend class MDNode;

unsigned RuntimeLang;
llvm::APInt SpareBitsMask;

DICompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
uint32_t AlignInBits, uint64_t OffsetInBits,
uint32_t NumExtraInhabitants, APInt SpareBitsMask,
DIFlags Flags, ArrayRef<Metadata *> Ops)
uint32_t NumExtraInhabitants, DIFlags Flags,
ArrayRef<Metadata *> Ops)
: DIType(C, DICompositeTypeKind, Storage, Tag, Line, SizeInBits,
AlignInBits, OffsetInBits, NumExtraInhabitants, Flags, Ops),
RuntimeLang(RuntimeLang), SpareBitsMask(SpareBitsMask) {}
RuntimeLang(RuntimeLang) {}
~DICompositeType() = default;

/// Change fields in place.
Expand All @@ -1199,20 +1198,20 @@ class DICompositeType : public DIType {
getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
unsigned Line, DIScope *Scope, DIType *BaseType, uint64_t SizeInBits,
uint32_t AlignInBits, uint64_t OffsetInBits, DIType *SpecificationOf,
uint32_t NumExtraInhabitants, APInt SpareBitsMask, DIFlags Flags,
DINodeArray Elements, unsigned RuntimeLang, DIType *VTableHolder,
uint32_t NumExtraInhabitants, DIFlags Flags, DINodeArray Elements,
unsigned RuntimeLang, DIType *VTableHolder,
DITemplateParameterArray TemplateParams, StringRef Identifier,
DIDerivedType *Discriminator, Metadata *DataLocation,
Metadata *Associated, Metadata *Allocated, Metadata *Rank,
DINodeArray Annotations, StorageType Storage,
bool ShouldCreate = true) {
return getImpl(
Context, Tag, getCanonicalMDString(Context, Name), File, Line, Scope,
BaseType, SizeInBits, AlignInBits, OffsetInBits, Flags, Elements.get(),
RuntimeLang, VTableHolder, TemplateParams.get(),
getCanonicalMDString(Context, Identifier), Discriminator, DataLocation,
Associated, Allocated, Rank, Annotations.get(), SpecificationOf,
NumExtraInhabitants, SpareBitsMask, Storage, ShouldCreate);
return getImpl(Context, Tag, getCanonicalMDString(Context, Name), File,
Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
Flags, Elements.get(), RuntimeLang, VTableHolder,
TemplateParams.get(),
getCanonicalMDString(Context, Identifier), Discriminator,
DataLocation, Associated, Allocated, Rank, Annotations.get(),
SpecificationOf, NumExtraInhabitants, Storage, ShouldCreate);
}
static DICompositeType *
getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
Expand All @@ -1223,8 +1222,8 @@ class DICompositeType : public DIType {
MDString *Identifier, Metadata *Discriminator, Metadata *DataLocation,
Metadata *Associated, Metadata *Allocated, Metadata *Rank,
Metadata *Annotations, Metadata *SpecificationOf,
uint32_t NumExtraInhabitants, APInt SpareBitsMask,
StorageType Storage, bool ShouldCreate = true);
uint32_t NumExtraInhabitants, StorageType Storage,
bool ShouldCreate = true);

TempDICompositeType cloneImpl() const {
return getTemporary(
Expand All @@ -1234,7 +1233,7 @@ class DICompositeType : public DIType {
getTemplateParams(), getIdentifier(), getDiscriminator(),
getRawDataLocation(), getRawAssociated(), getRawAllocated(),
getRawRank(), getAnnotations(), getSpecificationOf(),
getNumExtraInhabitants(), getSpareBitsMask());
getNumExtraInhabitants());
}

public:
Expand All @@ -1249,11 +1248,11 @@ class DICompositeType : public DIType {
Metadata *DataLocation = nullptr, Metadata *Associated = nullptr,
Metadata *Allocated = nullptr, Metadata *Rank = nullptr,
DINodeArray Annotations = nullptr, DIType *SpecificationOf = nullptr,
uint32_t NumExtraInhabitants = 0, APInt SpareBitsMask = APInt()),
uint32_t NumExtraInhabitants = 0),
(Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits,
OffsetInBits, SpecificationOf, NumExtraInhabitants, SpareBitsMask, Flags,
Elements, RuntimeLang, VTableHolder, TemplateParams, Identifier,
Discriminator, DataLocation, Associated, Allocated, Rank, Annotations))
OffsetInBits, SpecificationOf, NumExtraInhabitants, Flags, Elements,
RuntimeLang, VTableHolder, TemplateParams, Identifier, Discriminator,
DataLocation, Associated, Allocated, Rank, Annotations))
DEFINE_MDNODE_GET(
DICompositeType,
(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
Expand All @@ -1264,12 +1263,11 @@ class DICompositeType : public DIType {
Metadata *Discriminator = nullptr, Metadata *DataLocation = nullptr,
Metadata *Associated = nullptr, Metadata *Allocated = nullptr,
Metadata *Rank = nullptr, Metadata *Annotations = nullptr,
Metadata *SpecificationOf = nullptr, uint32_t NumExtraInhabitants = 0,
APInt SpareBitsMask = APInt()),
Metadata *SpecificationOf = nullptr, uint32_t NumExtraInhabitants = 0),
(Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits,
OffsetInBits, Flags, Elements, RuntimeLang, VTableHolder, TemplateParams,
Identifier, Discriminator, DataLocation, Associated, Allocated, Rank,
Annotations, SpecificationOf, NumExtraInhabitants, SpareBitsMask))
Annotations, SpecificationOf, NumExtraInhabitants))

TempDICompositeType clone() const { return cloneImpl(); }

Expand All @@ -1285,7 +1283,7 @@ class DICompositeType : public DIType {
MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
Metadata *BaseType, uint64_t SizeInBits, uint32_t AlignInBits,
uint64_t OffsetInBits, Metadata *SpecificationOf,
uint32_t NumExtraInhabitants, APInt SpareBitsMask, DIFlags Flags,
uint32_t NumExtraInhabitants, DIFlags Flags,
Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder,
Metadata *TemplateParams, Metadata *Discriminator,
Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
Expand All @@ -1307,8 +1305,8 @@ class DICompositeType : public DIType {
MDString *Name, Metadata *File, unsigned Line, Metadata *Scope,
Metadata *BaseType, uint64_t SizeInBits, uint32_t AlignInBits,
uint64_t OffsetInBits, Metadata *SpecificationOf,
uint32_t NumExtraInhabitants, APInt SpareBitsMask, DIFlags Flags,
Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder,
uint32_t NumExtraInhabitants, DIFlags Flags, Metadata *Elements,
unsigned RuntimeLang, Metadata *VTableHolder,
Metadata *TemplateParams, Metadata *Discriminator,
Metadata *DataLocation, Metadata *Associated,
Metadata *Allocated, Metadata *Rank, Metadata *Annotations);
Expand All @@ -1325,7 +1323,6 @@ class DICompositeType : public DIType {
}
StringRef getIdentifier() const { return getStringOperand(7); }
unsigned getRuntimeLang() const { return RuntimeLang; }
const APInt &getSpareBitsMask() const { return SpareBitsMask; }

Metadata *getRawBaseType() const { return getOperand(3); }
Metadata *getRawElements() const { return getOperand(4); }
Expand Down
15 changes: 6 additions & 9 deletions llvm/lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5433,8 +5433,7 @@ bool LLParser::parseDICompositeType(MDNode *&Result, bool IsDistinct) {
OPTIONAL(rank, MDSignedOrMDField, ); \
OPTIONAL(annotations, MDField, ); \
OPTIONAL(num_extra_inhabitants, MDUnsignedField, (0, UINT32_MAX)); \
OPTIONAL(specification_of, MDField, ); \
OPTIONAL(spare_bits_mask, MDAPSIntField, );
OPTIONAL(specification_of, MDField, );
PARSE_MD_FIELDS();
#undef VISIT_MD_FIELDS

Expand All @@ -5450,11 +5449,10 @@ bool LLParser::parseDICompositeType(MDNode *&Result, bool IsDistinct) {
if (auto *CT = DICompositeType::buildODRType(
Context, *identifier.Val, tag.Val, name.Val, file.Val, line.Val,
scope.Val, baseType.Val, size.Val, align.Val, offset.Val,
specification_of.Val, num_extra_inhabitants.Val,
spare_bits_mask.Val, flags.Val, elements.Val, runtimeLang.Val,
vtableHolder.Val, templateParams.Val, discriminator.Val,
dataLocation.Val, associated.Val, allocated.Val, Rank,
annotations.Val)) {
specification_of.Val, num_extra_inhabitants.Val, flags.Val,
elements.Val, runtimeLang.Val, vtableHolder.Val, templateParams.Val,
discriminator.Val, dataLocation.Val, associated.Val, allocated.Val,
Rank, annotations.Val)) {
Result = CT;
return false;
}
Expand All @@ -5467,8 +5465,7 @@ bool LLParser::parseDICompositeType(MDNode *&Result, bool IsDistinct) {
size.Val, align.Val, offset.Val, flags.Val, elements.Val,
runtimeLang.Val, vtableHolder.Val, templateParams.Val, identifier.Val,
discriminator.Val, dataLocation.Val, associated.Val, allocated.Val, Rank,
annotations.Val, specification_of.Val, num_extra_inhabitants.Val,
spare_bits_mask.Val));
annotations.Val, specification_of.Val, num_extra_inhabitants.Val));
return false;
}

Expand Down
Loading