aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Reader/MetadataLoader.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/Bitcode/Reader/MetadataLoader.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/Bitcode/Reader/MetadataLoader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/MetadataLoader.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
index ada1597..8ca46a4 100644
--- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
+++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
@@ -1525,18 +1525,19 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
break;
}
case bitc::METADATA_BASIC_TYPE: {
- if (Record.size() < 6 || Record.size() > 7)
+ if (Record.size() < 6 || Record.size() > 8)
return error("Invalid record");
IsDistinct = Record[0];
DINode::DIFlags Flags = (Record.size() > 6)
? static_cast<DINode::DIFlags>(Record[6])
: DINode::FlagZero;
+ uint32_t NumExtraInhabitants = (Record.size() > 7) ? Record[7] : 0;
MetadataList.assignValue(
GET_OR_DISTINCT(DIBasicType,
(Context, Record[1], getMDString(Record[2]), Record[3],
- Record[4], Record[5], Flags)),
+ Record[4], Record[5], NumExtraInhabitants, Flags)),
NextMetadataNo);
NextMetadataNo++;
break;
@@ -1599,7 +1600,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
break;
}
case bitc::METADATA_COMPOSITE_TYPE: {
- if (Record.size() < 16 || Record.size() > 22)
+ if (Record.size() < 16 || Record.size() > 23)
return error("Invalid record");
// If we have a UUID and this is not a forward declaration, lookup the
@@ -1617,6 +1618,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
return error("Alignment value is too large");
uint32_t AlignInBits = Record[8];
uint64_t OffsetInBits = 0;
+ uint32_t NumExtraInhabitants = (Record.size() > 22) ? Record[22] : 0;
DINode::DIFlags Flags = static_cast<DINode::DIFlags>(Record[10]);
Metadata *Elements = nullptr;
unsigned RuntimeLang = Record[12];
@@ -1681,9 +1683,9 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
if (Identifier)
CT = DICompositeType::buildODRType(
Context, *Identifier, Tag, Name, File, Line, Scope, BaseType,
- SizeInBits, AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
- VTableHolder, TemplateParams, Discriminator, DataLocation, Associated,
- Allocated, Rank, Annotations);
+ SizeInBits, AlignInBits, OffsetInBits, NumExtraInhabitants, Flags,
+ Elements, RuntimeLang, VTableHolder, TemplateParams, Discriminator,
+ DataLocation, Associated, Allocated, Rank, Annotations);
// Create a node if we didn't get a lazy ODR type.
if (!CT)
@@ -1692,7 +1694,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
SizeInBits, AlignInBits, OffsetInBits, Flags,
Elements, RuntimeLang, VTableHolder, TemplateParams,
Identifier, Discriminator, DataLocation, Associated,
- Allocated, Rank, Annotations));
+ Allocated, Rank, Annotations, NumExtraInhabitants));
if (!IsNotUsedInTypeRef && Identifier)
MetadataList.addTypeRef(*Identifier, *cast<DICompositeType>(CT));