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/Bitcode/Writer/BitcodeWriter.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/Bitcode/Writer/BitcodeWriter.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index ee9cc4b..de01750 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1863,6 +1863,7 @@ void ModuleBitcodeWriter::writeDIBasicType(const DIBasicType *N, Record.push_back(N->getAlignInBits()); Record.push_back(N->getEncoding()); Record.push_back(N->getFlags()); + Record.push_back(N->getNumExtraInhabitants()); Stream.EmitRecord(bitc::METADATA_BASIC_TYPE, Record, Abbrev); Record.clear(); @@ -1945,6 +1946,7 @@ void ModuleBitcodeWriter::writeDICompositeType( Record.push_back(VE.getMetadataOrNullID(N->getRawAllocated())); Record.push_back(VE.getMetadataOrNullID(N->getRawRank())); Record.push_back(VE.getMetadataOrNullID(N->getAnnotations().get())); + Record.push_back(N->getNumExtraInhabitants()); Stream.EmitRecord(bitc::METADATA_COMPOSITE_TYPE, Record, Abbrev); Record.clear(); |