IR: getOrInsertODRUniquedType => DICompositeType::getODRType, NFC

Lift the API for debug info ODR type uniquing up a layer.  Instead of
clients managing the map directly on the LLVMContext, add a static
method to DICompositeType called getODRType and handle the map in the
background.  Also adds DICompositeType::getODRTypeIfExists, so far just
for convenience in the unit tests.

This simplifies the logic in LLParser and BitcodeReader.  Because of
argument spam there are actually a few more lines of code now; I'll see
if I come up with a reasonable way to clean that up.

llvm-svn: 266742
This commit is contained in:
Duncan P. N. Exon Smith
2016-04-19 14:55:09 +00:00
parent 171b92f1e1
commit 0b0271ef97
8 changed files with 103 additions and 60 deletions

View File

@@ -2190,25 +2190,36 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
// If we have a UUID and this is not a forward declaration, lookup the
// mapping.
bool IsDistinct = Record[0];
unsigned Tag = Record[1];
MDString *Name = getMDString(Record[2]);
Metadata *File = getMDOrNull(Record[3]);
unsigned Line = Record[4];
Metadata *Scope = getMDOrNull(Record[5]);
Metadata *BaseType = getMDOrNull(Record[6]);
uint64_t SizeInBits = Record[7];
uint64_t AlignInBits = Record[8];
uint64_t OffsetInBits = Record[9];
unsigned Flags = Record[10];
Metadata *Elements = getMDOrNull(Record[11]);
unsigned RuntimeLang = Record[12];
Metadata *VTableHolder = getMDOrNull(Record[13]);
Metadata *TemplateParams = getMDOrNull(Record[14]);
auto *Identifier = getMDString(Record[15]);
DICompositeType **MappedT = nullptr;
DICompositeType *CT = nullptr;
if (!(Flags & DINode::FlagFwdDecl) && Identifier)
MappedT = Context.getOrInsertODRUniquedType(*Identifier);
CT = DICompositeType::getODRType(
Context, *Identifier, Tag, Name, File, Line, Scope, BaseType,
SizeInBits, AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
VTableHolder, TemplateParams);
// Use the mapped type node, or create a new one if necessary.
DICompositeType *CT = MappedT ? *MappedT : nullptr;
if (!CT) {
CT = GET_OR_DISTINCT(
DICompositeType, Record[0],
(Context, Record[1], getMDString(Record[2]), getMDOrNull(Record[3]),
Record[4], getMDOrNull(Record[5]), getMDOrNull(Record[6]),
Record[7], Record[8], Record[9], Flags, getMDOrNull(Record[11]),
Record[12], getMDOrNull(Record[13]), getMDOrNull(Record[14]),
Identifier));
if (MappedT)
*MappedT = CT;
}
// Create a node if we didn't get a lazy ODR type.
if (!CT)
CT = GET_OR_DISTINCT(DICompositeType, IsDistinct,
(Context, Tag, Name, File, Line, Scope, BaseType,
SizeInBits, AlignInBits, OffsetInBits, Flags,
Elements, RuntimeLang, VTableHolder,
TemplateParams, Identifier));
MetadataList.assignValue(CT, NextMetadataNo++);
break;