aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/DebugInfoMetadata.cpp
diff options
context:
space:
mode:
authorAugusto Noronha <anoronha@apple.com>2024-11-06 15:48:04 -0800
committerGitHub <noreply@github.com>2024-11-06 15:48:04 -0800
commitf6617d65e496823c748236cdbe8e42bf4c8d8a55 (patch)
treedb20439d1164297bcc08a3c2031a9ff48df340bf /llvm/lib/IR/DebugInfoMetadata.cpp
parentbd3a3959dc5b72ccbc83334132dece3f38957666 (diff)
downloadllvm-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/DebugInfoMetadata.cpp')
-rw-r--r--llvm/lib/IR/DebugInfoMetadata.cpp53
1 files changed, 28 insertions, 25 deletions
diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp
index fb4326e..f7268a5 100644
--- a/llvm/lib/IR/DebugInfoMetadata.cpp
+++ b/llvm/lib/IR/DebugInfoMetadata.cpp
@@ -663,14 +663,16 @@ DIEnumerator *DIEnumerator::getImpl(LLVMContext &Context, const APInt &Value,
DIBasicType *DIBasicType::getImpl(LLVMContext &Context, unsigned Tag,
MDString *Name, uint64_t SizeInBits,
uint32_t AlignInBits, unsigned Encoding,
- DIFlags Flags, StorageType Storage,
- bool ShouldCreate) {
+ uint32_t NumExtraInhabitants, DIFlags Flags,
+ StorageType Storage, bool ShouldCreate) {
assert(isCanonical(Name) && "Expected canonical MDString");
- DEFINE_GETIMPL_LOOKUP(DIBasicType,
- (Tag, Name, SizeInBits, AlignInBits, Encoding, Flags));
+ DEFINE_GETIMPL_LOOKUP(DIBasicType, (Tag, Name, SizeInBits, AlignInBits,
+ Encoding, NumExtraInhabitants, Flags));
Metadata *Ops[] = {nullptr, nullptr, Name};
- DEFINE_GETIMPL_STORE(DIBasicType,
- (Tag, SizeInBits, AlignInBits, Encoding, Flags), Ops);
+ DEFINE_GETIMPL_STORE(
+ DIBasicType,
+ (Tag, SizeInBits, AlignInBits, Encoding, NumExtraInhabitants, Flags),
+ Ops);
}
std::optional<DIBasicType::Signedness> DIBasicType::getSignedness() const {
@@ -768,8 +770,8 @@ DICompositeType *DICompositeType::getImpl(
Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder,
Metadata *TemplateParams, MDString *Identifier, Metadata *Discriminator,
Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
- Metadata *Rank, Metadata *Annotations, StorageType Storage,
- bool ShouldCreate) {
+ Metadata *Rank, Metadata *Annotations, uint32_t NumExtraInhabitants,
+ StorageType Storage, bool ShouldCreate) {
assert(isCanonical(Name) && "Expected canonical MDString");
// Keep this in sync with buildODRType.
@@ -778,25 +780,25 @@ DICompositeType *DICompositeType::getImpl(
AlignInBits, OffsetInBits, Flags, Elements,
RuntimeLang, VTableHolder, TemplateParams, Identifier,
Discriminator, DataLocation, Associated, Allocated,
- Rank, Annotations));
+ Rank, Annotations, NumExtraInhabitants));
Metadata *Ops[] = {File, Scope, Name, BaseType,
Elements, VTableHolder, TemplateParams, Identifier,
Discriminator, DataLocation, Associated, Allocated,
Rank, Annotations};
- DEFINE_GETIMPL_STORE(
- DICompositeType,
- (Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits, Flags),
- Ops);
+ DEFINE_GETIMPL_STORE(DICompositeType,
+ (Tag, Line, RuntimeLang, SizeInBits, AlignInBits,
+ OffsetInBits, NumExtraInhabitants, Flags),
+ Ops);
}
DICompositeType *DICompositeType::buildODRType(
LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
- DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
- Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator,
- Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
- Metadata *Rank, Metadata *Annotations) {
+ 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) {
assert(!Identifier.getString().empty() && "Expected valid identifier");
if (!Context.isODRUniquingDebugTypes())
return nullptr;
@@ -806,7 +808,8 @@ DICompositeType *DICompositeType::buildODRType(
Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
VTableHolder, TemplateParams, &Identifier, Discriminator,
- DataLocation, Associated, Allocated, Rank, Annotations);
+ DataLocation, Associated, Allocated, Rank, Annotations,
+ NumExtraInhabitants);
if (CT->getTag() != Tag)
return nullptr;
@@ -818,7 +821,7 @@ DICompositeType *DICompositeType::buildODRType(
// Mutate CT in place. Keep this in sync with getImpl.
CT->mutate(Tag, Line, RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
- Flags);
+ NumExtraInhabitants, Flags);
Metadata *Ops[] = {File, Scope, Name, BaseType,
Elements, VTableHolder, TemplateParams, &Identifier,
Discriminator, DataLocation, Associated, Allocated,
@@ -835,10 +838,10 @@ DICompositeType *DICompositeType::getODRType(
LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name,
Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType,
uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
- DIFlags Flags, Metadata *Elements, unsigned RuntimeLang,
- Metadata *VTableHolder, Metadata *TemplateParams, Metadata *Discriminator,
- Metadata *DataLocation, Metadata *Associated, Metadata *Allocated,
- Metadata *Rank, Metadata *Annotations) {
+ 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) {
assert(!Identifier.getString().empty() && "Expected valid identifier");
if (!Context.isODRUniquingDebugTypes())
return nullptr;
@@ -848,7 +851,7 @@ DICompositeType *DICompositeType::getODRType(
Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits,
AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, VTableHolder,
TemplateParams, &Identifier, Discriminator, DataLocation, Associated,
- Allocated, Rank, Annotations);
+ Allocated, Rank, Annotations, NumExtraInhabitants);
} else {
if (CT->getTag() != Tag)
return nullptr;
@@ -867,7 +870,7 @@ DISubroutineType::DISubroutineType(LLVMContext &C, StorageType Storage,
DIFlags Flags, uint8_t CC,
ArrayRef<Metadata *> Ops)
: DIType(C, DISubroutineTypeKind, Storage, dwarf::DW_TAG_subroutine_type, 0,
- 0, 0, 0, Flags, Ops),
+ 0, 0, 0, 0, Flags, Ops),
CC(CC) {}
DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context, DIFlags Flags,