diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/AsmParser/LLParser.cpp | 18 | ||||
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 43 | ||||
-rw-r--r-- | llvm/lib/IR/DebugInfoMetadata.cpp | 26 | ||||
-rw-r--r-- | llvm/lib/IR/LLVMContext.cpp | 6 |
4 files changed, 62 insertions, 31 deletions
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index c906b7b22db..fb27ab5353f 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -3841,13 +3841,15 @@ bool LLParser::ParseDICompositeType(MDNode *&Result, bool IsDistinct) { // If this isn't a forward declaration and it has a UUID, check for it in the // type map in the context. - DICompositeType **MappedT = nullptr; - if (!(flags.Val & DINode::FlagFwdDecl) && identifier.Val && - (MappedT = Context.getOrInsertODRUniquedType(*identifier.Val)) && - *MappedT) { - Result = *MappedT; - return false; - } + if (!(flags.Val & DINode::FlagFwdDecl) && identifier.Val) + if (auto *CT = DICompositeType::getODRType( + Context, *identifier.Val, tag.Val, name.Val, file.Val, line.Val, + scope.Val, baseType.Val, size.Val, align.Val, offset.Val, flags.Val, + elements.Val, runtimeLang.Val, vtableHolder.Val, + templateParams.Val)) { + Result = CT; + return false; + } // Create a new node, and save it in the context if it belongs in the type // map. @@ -3856,8 +3858,6 @@ bool LLParser::ParseDICompositeType(MDNode *&Result, bool IsDistinct) { (Context, tag.Val, name.Val, file.Val, line.Val, scope.Val, baseType.Val, size.Val, align.Val, offset.Val, flags.Val, elements.Val, runtimeLang.Val, vtableHolder.Val, templateParams.Val, identifier.Val)); - if (MappedT) - *MappedT = cast<DICompositeType>(Result); return false; } diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index d454eb1fd4c..dba0fd41755 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -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); - - // 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; - } + CT = DICompositeType::getODRType( + Context, *Identifier, Tag, Name, File, Line, Scope, BaseType, + SizeInBits, AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, + VTableHolder, TemplateParams); + + // 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; diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp index 3e6400785fd..37986f73ab1 100644 --- a/llvm/lib/IR/DebugInfoMetadata.cpp +++ b/llvm/lib/IR/DebugInfoMetadata.cpp @@ -266,6 +266,32 @@ DICompositeType *DICompositeType::getImpl( Ops); } +DICompositeType *DICompositeType::getODRType( + LLVMContext &Context, MDString &Identifier, unsigned Tag, MDString *Name, + Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, + uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits, + unsigned Flags, Metadata *Elements, unsigned RuntimeLang, + Metadata *VTableHolder, Metadata *TemplateParams) { + assert(!Identifier.getString().empty() && "Expected valid identifier"); + if (!Context.isODRUniquingDebugTypes()) + return nullptr; + auto *&CT = (*Context.pImpl->DITypeMap)[&Identifier]; + if (!CT) + CT = DICompositeType::getDistinct( + Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, + AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang, VTableHolder, + TemplateParams, &Identifier); + return CT; +} + +DICompositeType *DICompositeType::getODRTypeIfExists(LLVMContext &Context, + MDString &Identifier) { + assert(!Identifier.getString().empty() && "Expected valid identifier"); + if (!Context.isODRUniquingDebugTypes()) + return nullptr; + return Context.pImpl->DITypeMap->lookup(&Identifier); +} + DISubroutineType *DISubroutineType::getImpl(LLVMContext &Context, unsigned Flags, Metadata *TypeArray, StorageType Storage, diff --git a/llvm/lib/IR/LLVMContext.cpp b/llvm/lib/IR/LLVMContext.cpp index 7c0d18d028a..0d4f7242b76 100644 --- a/llvm/lib/IR/LLVMContext.cpp +++ b/llvm/lib/IR/LLVMContext.cpp @@ -323,12 +323,6 @@ void LLVMContext::enableDebugTypeODRUniquing() { void LLVMContext::disableDebugTypeODRUniquing() { pImpl->DITypeMap.reset(); } -DICompositeType **LLVMContext::getOrInsertODRUniquedType(const MDString &S) { - if (!isODRUniquingDebugTypes()) - return nullptr; - return &(*pImpl->DITypeMap)[&S]; -} - void LLVMContext::setDiscardValueNames(bool Discard) { pImpl->DiscardValueNames = Discard; } |