diff options
author | Augusto Noronha <anoronha@apple.com> | 2024-11-06 15:48:04 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-06 15:48:04 -0800 |
commit | f6617d65e496823c748236cdbe8e42bf4c8d8a55 (patch) | |
tree | db20439d1164297bcc08a3c2031a9ff48df340bf /llvm/lib/IR/DIBuilder.cpp | |
parent | bd3a3959dc5b72ccbc83334132dece3f38957666 (diff) | |
download | llvm-f6617d65e496823c748236cdbe8e42bf4c8d8a55.zip llvm-f6617d65e496823c748236cdbe8e42bf4c8d8a55.tar.gz llvm-f6617d65e496823c748236cdbe8e42bf4c8d8a55.tar.bz2 |
[DebugInfo] Add num_extra_inhabitants to debug info (#112590)
An extra inhabitant is a bit pattern that does not represent a valid
value for instances of a given type. The number of extra inhabitants is
the number of those bit configurations.
This is used by Swift to save space when composing types. For example,
because Bool only needs 2 bit patterns to represent all of its values
(true and false), an Optional<Bool> only occupies 1 byte in memory by
using a bit configuration that is unused by Bool. Which bit patterns are
unused are part of the ABI of the language.
Since Swift generics are not monomorphized, by using dynamic libraries
you can have generic types whose size, alignment, etc, are known only
at runtime (which is why this feature is needed).
This patch adds num_extra_inhabitants to LLVM-IR debug info and in DWARF
as an Apple extension.
Diffstat (limited to 'llvm/lib/IR/DIBuilder.cpp')
-rw-r--r-- | llvm/lib/IR/DIBuilder.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp index a0aaea4..8bc8c2d 100644 --- a/llvm/lib/IR/DIBuilder.cpp +++ b/llvm/lib/IR/DIBuilder.cpp @@ -265,10 +265,11 @@ DIBasicType *DIBuilder::createNullPtrType() { DIBasicType *DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits, unsigned Encoding, - DINode::DIFlags Flags) { + DINode::DIFlags Flags, + uint32_t NumExtraInhabitants) { assert(!Name.empty() && "Unable to create type without name"); return DIBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, SizeInBits, - 0, Encoding, Flags); + 0, Encoding, NumExtraInhabitants, Flags); } DIStringType *DIBuilder::createStringType(StringRef Name, uint64_t SizeInBits) { @@ -520,11 +521,14 @@ DICompositeType *DIBuilder::createStructType( DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang, - DIType *VTableHolder, StringRef UniqueIdentifier) { + DIType *VTableHolder, StringRef UniqueIdentifier, + uint32_t NumExtraInhabitants) { auto *R = DICompositeType::get( VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber, getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, 0, - Flags, Elements, RunTimeLang, VTableHolder, nullptr, UniqueIdentifier); + Flags, Elements, RunTimeLang, VTableHolder, nullptr, UniqueIdentifier, + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, + NumExtraInhabitants); trackIfUnresolved(R); return R; } @@ -550,7 +554,7 @@ DIBuilder::createVariantPart(DIScope *Scope, StringRef Name, DIFile *File, auto *R = DICompositeType::get( VMContext, dwarf::DW_TAG_variant_part, Name, File, LineNumber, getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags, - Elements, 0, nullptr, nullptr, UniqueIdentifier, Discriminator); + Elements, 0, nullptr, nullptr, UniqueIdentifier, 0, Discriminator); trackIfUnresolved(R); return R; } |