summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp153
-rw-r--r--llvm/lib/Bitcode/Writer/BitcodeWriter.cpp6
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp24
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h21
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp2
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h2
-rw-r--r--llvm/lib/IR/DIBuilder.cpp174
-rw-r--r--llvm/lib/IR/DebugInfo.cpp59
-rw-r--r--llvm/lib/IR/DebugInfoMetadata.cpp6
-rw-r--r--llvm/lib/IR/LLVMContextImpl.h25
-rw-r--r--llvm/lib/IR/Verifier.cpp172
11 files changed, 279 insertions, 365 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 734d317234b..ecd05c245d7 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -114,6 +114,14 @@ class BitcodeReaderMetadataList {
/// move) on resize, and TrackingMDRef is very expensive to copy.
SmallVector<TrackingMDRef, 1> MetadataPtrs;
+ /// Structures for resolving old type refs.
+ struct {
+ SmallDenseMap<MDString *, TempMDTuple, 1> Unknown;
+ SmallDenseMap<MDString *, DICompositeType *, 1> Final;
+ SmallDenseMap<MDString *, DICompositeType *, 1> FwdDecls;
+ std::vector<std::pair<TrackingMDRef, TempMDTuple>> Arrays;
+ } OldTypeRefs;
+
LLVMContext &Context;
public:
BitcodeReaderMetadataList(LLVMContext &C)
@@ -159,6 +167,18 @@ public:
void assignValue(Metadata *MD, unsigned Idx);
void tryToResolveCycles();
bool hasFwdRefs() const { return AnyFwdRefs; }
+
+ /// Upgrade a type that had an MDString reference.
+ void addTypeRef(MDString &UUID, DICompositeType &CT);
+
+ /// Upgrade a type that had an MDString reference.
+ Metadata *upgradeTypeRef(Metadata *MaybeUUID);
+
+ /// Upgrade a type ref array that may have MDString references.
+ Metadata *upgradeTypeRefArray(Metadata *MaybeTuple);
+
+private:
+ Metadata *resolveTypeRefArray(Metadata *MaybeTuple);
};
class BitcodeReader : public GVMaterializer {
@@ -1118,14 +1138,34 @@ MDNode *BitcodeReaderMetadataList::getMDNodeFwdRefOrNull(unsigned Idx) {
}
void BitcodeReaderMetadataList::tryToResolveCycles() {
- if (!AnyFwdRefs)
- // Nothing to do.
- return;
-
if (NumFwdRefs)
// Still forward references... can't resolve cycles.
return;
+ // Give up on finding a full definition for any forward decls that remain.
+ for (const auto &Ref : OldTypeRefs.FwdDecls)
+ OldTypeRefs.Final.insert(Ref);
+ OldTypeRefs.FwdDecls.clear();
+
+ // Upgrade from old type ref arrays. In strange cases, this could add to
+ // OldTypeRefs.Unknown.
+ for (const auto &Array : OldTypeRefs.Arrays)
+ Array.second->replaceAllUsesWith(resolveTypeRefArray(Array.first.get()));
+
+ // Replace old string-based type refs with the resolved node, if possible.
+ // If we haven't seen the node, leave it to the verifier to complain about
+ // the invalid string reference.
+ for (const auto &Ref : OldTypeRefs.Unknown)
+ if (DICompositeType *CT = OldTypeRefs.Final.lookup(Ref.first))
+ Ref.second->replaceAllUsesWith(CT);
+ else
+ Ref.second->replaceAllUsesWith(Ref.first);
+ OldTypeRefs.Unknown.clear();
+
+ if (!AnyFwdRefs)
+ // Nothing to do.
+ return;
+
// Resolve any cycles.
for (unsigned I = MinFwdRef, E = MaxFwdRef + 1; I != E; ++I) {
auto &MD = MetadataPtrs[I];
@@ -1141,6 +1181,60 @@ void BitcodeReaderMetadataList::tryToResolveCycles() {
AnyFwdRefs = false;
}
+void BitcodeReaderMetadataList::addTypeRef(MDString &UUID,
+ DICompositeType &CT) {
+ assert(CT.getRawIdentifier() == &UUID && "Mismatched UUID");
+ if (CT.isForwardDecl())
+ OldTypeRefs.FwdDecls.insert(std::make_pair(&UUID, &CT));
+ else
+ OldTypeRefs.Final.insert(std::make_pair(&UUID, &CT));
+}
+
+Metadata *BitcodeReaderMetadataList::upgradeTypeRef(Metadata *MaybeUUID) {
+ auto *UUID = dyn_cast_or_null<MDString>(MaybeUUID);
+ if (LLVM_LIKELY(!UUID))
+ return MaybeUUID;
+
+ if (auto *CT = OldTypeRefs.Final.lookup(UUID))
+ return CT;
+
+ auto &Ref = OldTypeRefs.Unknown[UUID];
+ if (!Ref)
+ Ref = MDNode::getTemporary(Context, None);
+ return Ref.get();
+}
+
+Metadata *BitcodeReaderMetadataList::upgradeTypeRefArray(Metadata *MaybeTuple) {
+ auto *Tuple = dyn_cast_or_null<MDTuple>(MaybeTuple);
+ if (!Tuple || Tuple->isDistinct())
+ return MaybeTuple;
+
+ // Look through the array immediately if possible.
+ if (!Tuple->isTemporary())
+ return resolveTypeRefArray(Tuple);
+
+ // Create and return a placeholder to use for now. Eventually
+ // resolveTypeRefArrays() will be resolve this forward reference.
+ OldTypeRefs.Arrays.emplace_back(
+ std::piecewise_construct, std::make_tuple(Tuple),
+ std::make_tuple(MDTuple::getTemporary(Context, None)));
+ return OldTypeRefs.Arrays.back().second.get();
+}
+
+Metadata *BitcodeReaderMetadataList::resolveTypeRefArray(Metadata *MaybeTuple) {
+ auto *Tuple = dyn_cast_or_null<MDTuple>(MaybeTuple);
+ if (!Tuple || Tuple->isDistinct())
+ return MaybeTuple;
+
+ // Look through the DITypeRefArray, upgrading each DITypeRef.
+ SmallVector<Metadata *, 32> Ops;
+ Ops.reserve(Tuple->getNumOperands());
+ for (Metadata *MD : Tuple->operands())
+ Ops.push_back(upgradeTypeRef(MD));
+
+ return MDTuple::get(Context, Ops);
+}
+
Type *BitcodeReader::getTypeByID(unsigned ID) {
// The type table size is always specified correctly.
if (ID >= TypeList.size())
@@ -2021,6 +2115,11 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
return cast_or_null<MDString>(getMDOrNull(ID));
};
+ // Support for old type refs.
+ auto getDITypeRefOrNull = [&](unsigned ID) {
+ return MetadataList.upgradeTypeRef(getMDOrNull(ID));
+ };
+
#define GET_OR_DISTINCT(CLASS, ARGS) \
(IsDistinct ? CLASS::getDistinct ARGS : CLASS::get ARGS)
@@ -2234,9 +2333,9 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
GET_OR_DISTINCT(DIDerivedType,
(Context, Record[1], getMDString(Record[2]),
getMDOrNull(Record[3]), Record[4],
- getMDOrNull(Record[5]), getMDOrNull(Record[6]),
- Record[7], Record[8], Record[9], Record[10],
- getMDOrNull(Record[11]))),
+ getDITypeRefOrNull(Record[5]),
+ getDITypeRefOrNull(Record[6]), Record[7], Record[8],
+ Record[9], Record[10], getMDOrNull(Record[11]))),
NextMetadataNo++);
break;
}
@@ -2246,20 +2345,21 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
// If we have a UUID and this is not a forward declaration, lookup the
// mapping.
- IsDistinct = Record[0];
+ IsDistinct = Record[0] & 0x1;
+ bool IsNotUsedInTypeRef = Record[0] >= 2;
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]);
+ Metadata *Scope = getDITypeRefOrNull(Record[5]);
+ Metadata *BaseType = getDITypeRefOrNull(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 *VTableHolder = getDITypeRefOrNull(Record[13]);
Metadata *TemplateParams = getMDOrNull(Record[14]);
auto *Identifier = getMDString(Record[15]);
DICompositeType *CT = nullptr;
@@ -2276,6 +2376,8 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
SizeInBits, AlignInBits, OffsetInBits, Flags,
Elements, RuntimeLang, VTableHolder,
TemplateParams, Identifier));
+ if (!IsNotUsedInTypeRef && Identifier)
+ MetadataList.addTypeRef(*Identifier, *cast<DICompositeType>(CT));
MetadataList.assignValue(CT, NextMetadataNo++);
break;
@@ -2284,10 +2386,14 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
if (Record.size() != 3)
return error("Invalid record");
- IsDistinct = Record[0];
+ IsDistinct = Record[0] & 0x1;
+ bool IsOldTypeRefArray = Record[0] < 2;
+ Metadata *Types = getMDOrNull(Record[2]);
+ if (LLVM_UNLIKELY(IsOldTypeRefArray))
+ Types = MetadataList.upgradeTypeRefArray(Types);
+
MetadataList.assignValue(
- GET_OR_DISTINCT(DISubroutineType,
- (Context, Record[1], getMDOrNull(Record[2]))),
+ GET_OR_DISTINCT(DISubroutineType, (Context, Record[1], Types)),
NextMetadataNo++);
break;
}
@@ -2354,10 +2460,10 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
bool HasCU = Offset && !HasFn;
DISubprogram *SP = GET_OR_DISTINCT(
DISubprogram,
- (Context, getMDOrNull(Record[1]), getMDString(Record[2]),
+ (Context, getDITypeRefOrNull(Record[1]), getMDString(Record[2]),
getMDString(Record[3]), getMDOrNull(Record[4]), Record[5],
getMDOrNull(Record[6]), Record[7], Record[8], Record[9],
- getMDOrNull(Record[10]), Record[11], Record[12], Record[13],
+ getDITypeRefOrNull(Record[10]), Record[11], Record[12], Record[13],
Record[14], HasCU ? CUorFn : nullptr,
getMDOrNull(Record[15 + Offset]), getMDOrNull(Record[16 + Offset]),
getMDOrNull(Record[17 + Offset])));
@@ -2444,7 +2550,7 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
IsDistinct = Record[0];
MetadataList.assignValue(GET_OR_DISTINCT(DITemplateTypeParameter,
(Context, getMDString(Record[1]),
- getMDOrNull(Record[2]))),
+ getDITypeRefOrNull(Record[2]))),
NextMetadataNo++);
break;
}
@@ -2456,7 +2562,8 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
MetadataList.assignValue(
GET_OR_DISTINCT(DITemplateValueParameter,
(Context, Record[1], getMDString(Record[2]),
- getMDOrNull(Record[3]), getMDOrNull(Record[4]))),
+ getDITypeRefOrNull(Record[3]),
+ getMDOrNull(Record[4]))),
NextMetadataNo++);
break;
}
@@ -2470,7 +2577,7 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
(Context, getMDOrNull(Record[1]),
getMDString(Record[2]), getMDString(Record[3]),
getMDOrNull(Record[4]), Record[5],
- getMDOrNull(Record[6]), Record[7], Record[8],
+ getDITypeRefOrNull(Record[6]), Record[7], Record[8],
getMDOrNull(Record[9]), getMDOrNull(Record[10]))),
NextMetadataNo++);
break;
@@ -2489,8 +2596,8 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
(Context, getMDOrNull(Record[1 + HasTag]),
getMDString(Record[2 + HasTag]),
getMDOrNull(Record[3 + HasTag]), Record[4 + HasTag],
- getMDOrNull(Record[5 + HasTag]), Record[6 + HasTag],
- Record[7 + HasTag])),
+ getDITypeRefOrNull(Record[5 + HasTag]),
+ Record[6 + HasTag], Record[7 + HasTag])),
NextMetadataNo++);
break;
}
@@ -2515,7 +2622,7 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
(Context, getMDString(Record[1]),
getMDOrNull(Record[2]), Record[3],
getMDString(Record[4]), getMDString(Record[5]),
- Record[6], getMDOrNull(Record[7]))),
+ Record[6], getDITypeRefOrNull(Record[7]))),
NextMetadataNo++);
break;
}
@@ -2527,7 +2634,7 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
MetadataList.assignValue(
GET_OR_DISTINCT(DIImportedEntity,
(Context, Record[1], getMDOrNull(Record[2]),
- getMDOrNull(Record[3]), Record[4],
+ getDITypeRefOrNull(Record[3]), Record[4],
getMDString(Record[5]))),
NextMetadataNo++);
break;
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 71905364c1d..3be4fe03d51 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1273,7 +1273,8 @@ void ModuleBitcodeWriter::writeDIDerivedType(const DIDerivedType *N,
void ModuleBitcodeWriter::writeDICompositeType(
const DICompositeType *N, SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev) {
- Record.push_back(N->isDistinct());
+ const unsigned IsNotUsedInOldTypeRef = 0x2;
+ Record.push_back(IsNotUsedInOldTypeRef | N->isDistinct());
Record.push_back(N->getTag());
Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
Record.push_back(VE.getMetadataOrNullID(N->getFile()));
@@ -1297,7 +1298,8 @@ void ModuleBitcodeWriter::writeDICompositeType(
void ModuleBitcodeWriter::writeDISubroutineType(
const DISubroutineType *N, SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev) {
- Record.push_back(N->isDistinct());
+ const unsigned HasNoOldTypeRefs = 0x2;
+ Record.push_back(HasNoOldTypeRefs | N->isDistinct());
Record.push_back(N->getFlags());
Record.push_back(VE.getMetadataOrNullID(N->getTypeArray().get()));
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 373b7e7daa3..dcd49acb250 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -145,21 +145,13 @@ bool DebugLocDwarfExpression::isFrameRegister(unsigned MachineReg) {
//===----------------------------------------------------------------------===//
-/// resolve - Look in the DwarfDebug map for the MDNode that
-/// corresponds to the reference.
-template <typename T> T *DbgVariable::resolve(TypedDINodeRef<T> Ref) const {
- return DD->resolve(Ref);
-}
-
bool DbgVariable::isBlockByrefVariable() const {
assert(Var && "Invalid complex DbgVariable!");
- return Var->getType()
- .resolve(DD->getTypeIdentifierMap())
- ->isBlockByrefStruct();
+ return Var->getType().resolve()->isBlockByrefStruct();
}
const DIType *DbgVariable::getType() const {
- DIType *Ty = Var->getType().resolve(DD->getTypeIdentifierMap());
+ DIType *Ty = Var->getType().resolve();
// FIXME: isBlockByrefVariable should be reformulated in terms of complex
// addresses instead.
if (Ty->isBlockByrefStruct()) {
@@ -474,7 +466,6 @@ void DwarfDebug::beginModule() {
const Module *M = MMI->getModule();
- TypeIdentifierMap = generateDITypeIdentifierMap(*M);
unsigned NumDebugCUs = 0;
for (DICompileUnit *CUNode : M->debug_compile_units()) {
(void)CUNode;
@@ -494,12 +485,12 @@ void DwarfDebug::beginModule() {
for (auto *Ty : CUNode->getEnumTypes()) {
// The enum types array by design contains pointers to
// MDNodes rather than DIRefs. Unique them here.
- CU.getOrCreateTypeDIE(cast<DIType>(resolve(Ty->getRef())));
+ CU.getOrCreateTypeDIE(cast<DIType>(Ty));
}
for (auto *Ty : CUNode->getRetainedTypes()) {
// The retained types array by design contains pointers to
// MDNodes rather than DIRefs. Unique them here.
- if (DIType *RT = dyn_cast<DIType>(resolve(Ty->getRef())))
+ if (DIType *RT = dyn_cast<DIType>(Ty))
if (!RT->isExternalTypeRef())
// There is no point in force-emitting a forward declaration.
CU.getOrCreateTypeDIE(RT);
@@ -705,7 +696,7 @@ DbgVariable *DwarfDebug::getExistingAbstractVariable(InlinedVariable IV) {
void DwarfDebug::createAbstractVariable(const DILocalVariable *Var,
LexicalScope *Scope) {
- auto AbsDbgVariable = make_unique<DbgVariable>(Var, /* IA */ nullptr, this);
+ auto AbsDbgVariable = make_unique<DbgVariable>(Var, /* IA */ nullptr);
InfoHolder.addScopeVariable(Scope, AbsDbgVariable.get());
AbstractVariables[Var] = std::move(AbsDbgVariable);
}
@@ -749,7 +740,7 @@ void DwarfDebug::collectVariableInfoFromMMITable(
continue;
ensureAbstractVariableIsCreatedIfScoped(Var, Scope->getScopeNode());
- auto RegVar = make_unique<DbgVariable>(Var.first, Var.second, this);
+ auto RegVar = make_unique<DbgVariable>(Var.first, Var.second);
RegVar->initializeMMI(VI.Expr, VI.Slot);
if (InfoHolder.addScopeVariable(Scope, RegVar.get()))
ConcreteVariables.push_back(std::move(RegVar));
@@ -923,8 +914,7 @@ DwarfDebug::buildLocationList(SmallVectorImpl<DebugLocEntry> &DebugLoc,
DbgVariable *DwarfDebug::createConcreteVariable(LexicalScope &Scope,
InlinedVariable IV) {
ensureAbstractVariableIsCreatedIfScoped(IV, Scope.getScopeNode());
- ConcreteVariables.push_back(
- make_unique<DbgVariable>(IV.first, IV.second, this));
+ ConcreteVariables.push_back(make_unique<DbgVariable>(IV.first, IV.second));
InfoHolder.addScopeVariable(&Scope, ConcreteVariables.back().get());
return ConcreteVariables.back().get();
}
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
index ad0241cb99b..039a5b9fc99 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
@@ -68,15 +68,14 @@ class DbgVariable {
unsigned DebugLocListIndex = ~0u; /// Offset in DebugLocs.
const MachineInstr *MInsn = nullptr; /// DBG_VALUE instruction.
SmallVector<int, 1> FrameIndex; /// Frame index.
- DwarfDebug *DD;
public:
/// Construct a DbgVariable.
///
/// Creates a variable without any DW_AT_location. Call \a initializeMMI()
/// for MMI entries, or \a initializeDbgValue() for DBG_VALUE instructions.
- DbgVariable(const DILocalVariable *V, const DILocation *IA, DwarfDebug *DD)
- : Var(V), IA(IA), DD(DD) {}
+ DbgVariable(const DILocalVariable *V, const DILocation *IA)
+ : Var(V), IA(IA) {}
/// Initialize from the MMI table.
void initializeMMI(const DIExpression *E, int FI) {
@@ -177,9 +176,9 @@ public:
const DIType *getType() const;
private:
- /// Look in the DwarfDebug map for the MDNode that
- /// corresponds to the reference.
- template <typename T> T *resolve(TypedDINodeRef<T> Ref) const;
+ template <typename T> T *resolve(TypedDINodeRef<T> Ref) const {
+ return Ref.resolve();
+ }
};
@@ -255,9 +254,6 @@ class DwarfDebug : public DebugHandlerBase {
/// Version of dwarf we're emitting.
unsigned DwarfVersion;
- /// Maps from a type identifier to the actual MDNode.
- DITypeIdentifierMap TypeIdentifierMap;
-
/// DWARF5 Experimental Options
/// @{
bool HasDwarfAccelTables;
@@ -525,12 +521,7 @@ public:
/// Find the MDNode for the given reference.
template <typename T> T *resolve(TypedDINodeRef<T> Ref) const {
- return Ref.resolve(TypeIdentifierMap);
- }
-
- /// Return the TypeIdentifierMap.
- const DITypeIdentifierMap &getTypeIdentifierMap() const {
- return TypeIdentifierMap;
+ return Ref.resolve();
}
/// Find the DwarfCompileUnit for the given CU Die.
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index 9003af528d0..91c490f0e9d 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -718,8 +718,6 @@ DIE *DwarfUnit::getOrCreateTypeDIE(const MDNode *TyNode) {
return nullptr;
auto *Ty = cast<DIType>(TyNode);
- assert(Ty == resolve(Ty->getRef()) &&
- "type was not uniqued, possible ODR violation.");
// DW_TAG_restrict_type is not supported in DWARF2
if (Ty->getTag() == dwarf::DW_TAG_restrict_type && DD->getDwarfVersion() <= 2)
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
index a79add630b3..e225f92116d 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
@@ -328,7 +328,7 @@ protected:
/// Look in the DwarfDebug map for the MDNode that corresponds to the
/// reference.
template <typename T> T *resolve(TypedDINodeRef<T> Ref) const {
- return DD->resolve(Ref);
+ return Ref.resolve();
}
private:
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index e46de241dfc..f0baff74be6 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -206,8 +206,7 @@ DIImportedEntity *DIBuilder::createImportedDeclaration(DIScope *Context,
// Make sure to use the unique identifier based metadata reference for
// types that have one.
return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration,
- Context, DINodeRef::get(Decl), Line, Name,
- AllImportedModules);
+ Context, Decl, Line, Name, AllImportedModules);
}
DIFile *DIBuilder::createFile(StringRef Filename, StringRef Directory) {
@@ -237,8 +236,8 @@ DIBasicType *DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits,
}
DIDerivedType *DIBuilder::createQualifiedType(unsigned Tag, DIType *FromTy) {
- return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr,
- DITypeRef::get(FromTy), 0, 0, 0, 0);
+ return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, FromTy, 0,
+ 0, 0, 0);
}
DIDerivedType *DIBuilder::createPointerType(DIType *PointeeTy,
@@ -247,8 +246,8 @@ DIDerivedType *DIBuilder::createPointerType(DIType *PointeeTy,
StringRef Name) {
// FIXME: Why is there a name here?
return DIDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name,
- nullptr, 0, nullptr, DITypeRef::get(PointeeTy),
- SizeInBits, AlignInBits, 0, 0);
+ nullptr, 0, nullptr, PointeeTy, SizeInBits,
+ AlignInBits, 0, 0);
}
DIDerivedType *DIBuilder::createMemberPointerType(DIType *PointeeTy,
@@ -256,34 +255,31 @@ DIDerivedType *DIBuilder::createMemberPointerType(DIType *PointeeTy,
uint64_t SizeInBits,
uint64_t AlignInBits) {
return DIDerivedType::get(VMContext, dwarf::DW_TAG_ptr_to_member_type, "",
- nullptr, 0, nullptr, DITypeRef::get(PointeeTy),
- SizeInBits, AlignInBits, 0, 0,
- DITypeRef::get(Base));
+ nullptr, 0, nullptr, PointeeTy, SizeInBits,
+ AlignInBits, 0, 0, Base);
}
DIDerivedType *DIBuilder::createReferenceType(unsigned Tag, DIType *RTy,
uint64_t SizeInBits,
uint64_t AlignInBits) {
assert(RTy && "Unable to create reference type");
- return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr,
- DITypeRef::get(RTy), SizeInBits, AlignInBits, 0, 0);
+ return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, RTy,
+ SizeInBits, AlignInBits, 0, 0);
}
DIDerivedType *DIBuilder::createTypedef(DIType *Ty, StringRef Name,
DIFile *File, unsigned LineNo,
DIScope *Context) {
return DIDerivedType::get(VMContext, dwarf::DW_TAG_typedef, Name, File,
- LineNo,
- DIScopeRef::get(getNonCompileUnitScope(Context)),
- DITypeRef::get(Ty), 0, 0, 0, 0);
+ LineNo, getNonCompileUnitScope(Context), Ty, 0, 0,
+ 0, 0);
}
DIDerivedType *DIBuilder::createFriend(DIType *Ty, DIType *FriendTy) {
assert(Ty && "Invalid type!");
assert(FriendTy && "Invalid friend type!");
- return DIDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0,
- DITypeRef::get(Ty), DITypeRef::get(FriendTy), 0, 0,
- 0, 0);
+ return DIDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0, Ty,
+ FriendTy, 0, 0, 0, 0);
}
DIDerivedType *DIBuilder::createInheritance(DIType *Ty, DIType *BaseTy,
@@ -291,8 +287,7 @@ DIDerivedType *DIBuilder::createInheritance(DIType *Ty, DIType *BaseTy,
unsigned Flags) {
assert(Ty && "Unable to create inheritance");
return DIDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr,
- 0, DITypeRef::get(Ty), DITypeRef::get(BaseTy), 0, 0,
- BaseOffset, Flags);
+ 0, Ty, BaseTy, 0, 0, BaseOffset, Flags);
}
DIDerivedType *DIBuilder::createMemberType(DIScope *Scope, StringRef Name,
@@ -301,10 +296,9 @@ DIDerivedType *DIBuilder::createMemberType(DIScope *Scope, StringRef Name,
uint64_t AlignInBits,
uint64_t OffsetInBits,
unsigned Flags, DIType *Ty) {
- return DIDerivedType::get(
- VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
- DIScopeRef::get(getNonCompileUnitScope(Scope)), DITypeRef::get(Ty),
- SizeInBits, AlignInBits, OffsetInBits, Flags);
+ return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
+ LineNumber, getNonCompileUnitScope(Scope), Ty,
+ SizeInBits, AlignInBits, OffsetInBits, Flags);
}
static ConstantAsMetadata *getConstantOrNull(Constant *C) {
@@ -319,10 +313,9 @@ DIDerivedType *DIBuilder::createStaticMemberType(DIScope *Scope, StringRef Name,
DIType *Ty, unsigned Flags,
llvm::Constant *Val) {
Flags |= DINode::FlagStaticMember;
- return DIDerivedType::get(
- VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
- DIScopeRef::get(getNonCompileUnitScope(Scope)), DITypeRef::get(Ty), 0, 0,
- 0, Flags, getConstantOrNull(Val));
+ return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
+ LineNumber, getNonCompileUnitScope(Scope), Ty, 0, 0,
+ 0, Flags, getConstantOrNull(Val));
}
DIDerivedType *DIBuilder::createObjCIVar(StringRef Name, DIFile *File,
@@ -331,10 +324,10 @@ DIDerivedType *DIBuilder::createObjCIVar(StringRef Name, DIFile *File,
uint64_t AlignInBits,
uint64_t OffsetInBits, unsigned Flags,
DIType *Ty, MDNode *PropertyNode) {
- return DIDerivedType::get(
- VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
- DIScopeRef::get(getNonCompileUnitScope(File)), DITypeRef::get(Ty),
- SizeInBits, AlignInBits, OffsetInBits, Flags, PropertyNode);
+ return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
+ LineNumber, getNonCompileUnitScope(File), Ty,
+ SizeInBits, AlignInBits, OffsetInBits, Flags,
+ PropertyNode);
}
DIObjCProperty *
@@ -342,15 +335,14 @@ DIBuilder::createObjCProperty(StringRef Name, DIFile *File, unsigned LineNumber,
StringRef GetterName, StringRef SetterName,
unsigned PropertyAttributes, DIType *Ty) {
return DIObjCProperty::get(VMContext, Name, File, LineNumber, GetterName,
- SetterName, PropertyAttributes,
- DITypeRef::get(Ty));
+ SetterName, PropertyAttributes, Ty);
}
DITemplateTypeParameter *
DIBuilder::createTemplateTypeParameter(DIScope *Context, StringRef Name,
DIType *Ty) {
assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit");
- return DITemplateTypeParameter::get(VMContext, Name, DITypeRef::get(Ty));
+ return DITemplateTypeParameter::get(VMContext, Name, Ty);
}
static DITemplateValueParameter *
@@ -358,8 +350,7 @@ createTemplateValueParameterHelper(LLVMContext &VMContext, unsigned Tag,
DIScope *Context, StringRef Name, DIType *Ty,
Metadata *MD) {
assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit");
- return DITemplateValueParameter::get(VMContext, Tag, Name, DITypeRef::get(Ty),
- MD);
+ return DITemplateValueParameter::get(VMContext, Tag, Name, Ty, MD);
}
DITemplateValueParameter *
@@ -396,12 +387,9 @@ DICompositeType *DIBuilder::createClassType(
auto *R = DICompositeType::get(
VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
- DIScopeRef::get(getNonCompileUnitScope(Context)),
- DITypeRef::get(DerivedFrom), SizeInBits, AlignInBits, OffsetInBits, Flags,
- Elements, 0, DITypeRef::get(VTableHolder),
+ getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits,
+ OffsetInBits, Flags, Elements, 0, VTableHolder,
cast_or_null<MDTuple>(TemplateParams), UniqueIdentifier);
- if (!UniqueIdentifier.empty())
- retainType(R);
trackIfUnresolved(R);
return R;
}
@@ -413,11 +401,8 @@ DICompositeType *DIBuilder::createStructType(
DIType *VTableHolder, StringRef UniqueIdentifier) {
auto *R = DICompositeType::get(
VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
- DIScopeRef::get(getNonCompileUnitScope(Context)),
- DITypeRef::get(DerivedFrom), SizeInBits, AlignInBits, 0, Flags, Elements,
- RunTimeLang, DITypeRef::get(VTableHolder), nullptr, UniqueIdentifier);
- if (!UniqueIdentifier.empty())
- retainType(R);
+ getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, 0,
+ Flags, Elements, RunTimeLang, VTableHolder, nullptr, UniqueIdentifier);
trackIfUnresolved(R);
return R;
}
@@ -428,11 +413,8 @@ DICompositeType *DIBuilder::createUnionType(
DINodeArray Elements, unsigned RunTimeLang, StringRef UniqueIdentifier) {
auto *R = DICompositeType::get(
VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber,
- DIScopeRef::get(getNonCompileUnitScope(Scope)), nullptr, SizeInBits,
- AlignInBits, 0, Flags, Elements, RunTimeLang, nullptr, nullptr,
- UniqueIdentifier);
- if (!UniqueIdentifier.empty())
- retainType(R);
+ getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags,
+ Elements, RunTimeLang, nullptr, nullptr, UniqueIdentifier);
trackIfUnresolved(R);
return R;
}
@@ -445,13 +427,9 @@ DISubroutineType *DIBuilder::createSubroutineType(DITypeRefArray ParameterTypes,
DICompositeType *DIBuilder::createExternalTypeRef(unsigned Tag, DIFile *File,
StringRef UniqueIdentifier) {
assert(!UniqueIdentifier.empty() && "external type ref without uid");
- auto *CTy =
- DICompositeType::get(VMContext, Tag, "", nullptr, 0, nullptr, nullptr, 0,
- 0, 0, DINode::FlagExternalTypeRef, nullptr, 0,
- nullptr, nullptr, UniqueIdentifier);
- // Types with unique IDs need to be in the type map.
- retainType(CTy);
- return CTy;
+ return DICompositeType::get(VMContext, Tag, "", nullptr, 0, nullptr, nullptr,
+ 0, 0, 0, DINode::FlagExternalTypeRef, nullptr, 0,
+ nullptr, nullptr, UniqueIdentifier);
}
DICompositeType *DIBuilder::createEnumerationType(
@@ -460,12 +438,9 @@ DICompositeType *DIBuilder::createEnumerationType(
DIType *UnderlyingType, StringRef UniqueIdentifier) {
auto *CTy = DICompositeType::get(
VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber,
- DIScopeRef::get(getNonCompileUnitScope(Scope)),
- DITypeRef::get(UnderlyingType), SizeInBits, AlignInBits, 0, 0, Elements,
- 0, nullptr, nullptr, UniqueIdentifier);
+ getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 0,
+ 0, Elements, 0, nullptr, nullptr, UniqueIdentifier);
AllEnumTypes.push_back(CTy);
- if (!UniqueIdentifier.empty())
- retainType(CTy);
trackIfUnresolved(CTy);
return CTy;
}
@@ -474,8 +449,8 @@ DICompositeType *DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits,
DIType *Ty,
DINodeArray Subscripts) {
auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "",
- nullptr, 0, nullptr, DITypeRef::get(Ty), Size,
- AlignInBits, 0, 0, Subscripts, 0, nullptr);
+ nullptr, 0, nullptr, Ty, Size, AlignInBits, 0,
+ 0, Subscripts, 0, nullptr);
trackIfUnresolved(R);
return R;
}
@@ -483,10 +458,9 @@ DICompositeType *DIBuilder::createArrayType(uint64_t Size, uint64_t AlignInBits,
DICompositeType *DIBuilder::createVectorType(uint64_t Size,
uint64_t AlignInBits, DIType *Ty,
DINodeArray Subscripts) {
- auto *R =
- DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "", nullptr, 0,
- nullptr, DITypeRef::get(Ty), Size, AlignInBits, 0,
- DINode::FlagVector, Subscripts, 0, nullptr);
+ auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "",
+ nullptr, 0, nullptr, Ty, Size, AlignInBits, 0,
+ DINode::FlagVector, Subscripts, 0, nullptr);
trackIfUnresolved(R);
return R;
}
@@ -531,12 +505,9 @@ DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIScope *Scope,
// FIXME: Define in terms of createReplaceableForwardDecl() by calling
// replaceWithUniqued().
auto *RetTy = DICompositeType::get(
- VMContext, Tag, Name, F, Line,
- DIScopeRef::get(getNonCompileUnitScope(Scope)), nullptr, SizeInBits,
- AlignInBits, 0, DINode::FlagFwdDecl, nullptr, RuntimeLang, nullptr,
- nullptr, UniqueIdentifier);
- if (!UniqueIdentifier.empty())
- retainType(RetTy);
+ VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
+ SizeInBits, AlignInBits, 0, DINode::FlagFwdDecl, nullptr, RuntimeLang,
+ nullptr, nullptr, UniqueIdentifier);
trackIfUnresolved(RetTy);
return RetTy;
}
@@ -545,14 +516,12 @@ DICompositeType *DIBuilder::createReplaceableCompositeType(
unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line,
unsigned RuntimeLang, uint64_t SizeInBits, uint64_t AlignInBits,
unsigned Flags, StringRef UniqueIdentifier) {
- auto *RetTy = DICompositeType::getTemporary(
- VMContext, Tag, Name, F, Line,
- DIScopeRef::get(getNonCompileUnitScope(Scope)), nullptr,
- SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang,
- nullptr, nullptr, UniqueIdentifier)
- .release();
- if (!UniqueIdentifier.empty())
- retainType(RetTy);
+ auto *RetTy =
+ DICompositeType::getTemporary(
+ VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr,
+ SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang, nullptr,
+ nullptr, UniqueIdentifier)
+ .release();
trackIfUnresolved(RetTy);
return RetTy;
}
@@ -565,7 +534,7 @@ DITypeRefArray DIBuilder::getOrCreateTypeArray(ArrayRef<Metadata *> Elements) {
SmallVector<llvm::Metadata *, 16> Elts;
for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
if (Elements[i] && isa<MDNode>(Elements[i]))
- Elts.push_back(DITypeRef::get(cast<DIType>(Elements[i])));
+ Elts.push_back(cast<DIType>(Elements[i]));
else
Elts.push_back(Elements[i]);
}
@@ -591,10 +560,10 @@ DIGlobalVariable *DIBuilder::createGlobalVariable(
MDNode *Decl) {
checkGlobalVariableScope(Context);
- auto *N = DIGlobalVariable::get(VMContext, cast_or_null<DIScope>(Context),
- Name, LinkageName, F, LineNumber,
- DITypeRef::get(Ty), isLocalToUnit, true, Val,
- cast_or_null<DIDerivedType>(Decl));
+ auto *N =
+ DIGlobalVariable::get(VMContext, cast_or_null<DIScope>(Context), Name,
+ LinkageName, F, LineNumber, Ty, isLocalToUnit, true,
+ Val, cast_or_null<DIDerivedType>(Decl));
AllGVs.push_back(N);
return N;
}
@@ -607,7 +576,7 @@ DIGlobalVariable *DIBuilder::createTempGlobalVariableFwdDecl(
return DIGlobalVariable::getTemporary(
VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
- LineNumber, DITypeRef::get(Ty), isLocalToUnit, false, Val,
+ LineNumber, Ty, isLocalToUnit, false, Val,
cast_or_null<DIDerivedType>(Decl))
.release();
}
@@ -625,7 +594,7 @@ static DILocalVariable *createLocalVariable(
auto *Node =
DILocalVariable::get(VMContext, cast_or_null<DILocalScope>(Context), Name,
- File, LineNo, DITypeRef::get(Ty), ArgNo, Flags);
+ File, LineNo, Ty, ArgNo, Flags);
if (AlwaysPreserve) {
// The optimizer may remove local variables. If there is an interest
// to preserve variable info in such situation then stash it in a
@@ -684,9 +653,9 @@ DISubprogram *DIBuilder::createFunction(
DITemplateParameterArray TParams, DISubprogram *Decl) {
auto *Node = getSubprogram(
/* IsDistinct = */ isDefinition, VMContext,
- DIScopeRef::get(getNonCompileUnitScope(Context)), Name, LinkageName, File,
- LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine, nullptr, 0, 0, Flags,
- isOptimized, isDefinition ? CUNode : nullptr, TParams, Decl,
+ getNonCompileUnitScope(Context), Name, LinkageName, File, LineNo, Ty,
+ isLocalToUnit, isDefinition, ScopeLine, nullptr, 0, 0, Flags, isOptimized,
+ isDefinition ? CUNode : nullptr, TParams, Decl,
MDTuple::getTemporary(VMContext, None).release());
if (isDefinition)
@@ -701,10 +670,10 @@ DISubprogram *DIBuilder::createTempFunctionFwdDecl(
bool isDefinition, unsigned ScopeLine, unsigned Flags, bool isOptimized,
DITemplateParameterArray TParams, DISubprogram *Decl) {
return DISubprogram::getTemporary(
- VMContext, DIScopeRef::get(getNonCompileUnitScope(Context)), Name,
- LinkageName, File, LineNo, Ty, isLocalToUnit, isDefinition,
- ScopeLine, nullptr, 0, 0, Flags, isOptimized,
- isDefinition ? CUNode : nullptr, TParams, Decl, nullptr)
+ VMContext, getNonCompileUnitScope(Context), Name, LinkageName,
+ File, LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine, nullptr,
+ 0, 0, Flags, isOptimized, isDefinition ? CUNode : nullptr, TParams,
+ Decl, nullptr)
.release();
}
@@ -719,11 +688,10 @@ DIBuilder::createMethod(DIScope *Context, StringRef Name, StringRef LinkageName,
"the compile unit.");
// FIXME: Do we want to use different scope/lines?
auto *SP = getSubprogram(
- /* IsDistinct = */ isDefinition, VMContext,
- DIScopeRef::get(cast<DIScope>(Context)), Name, LinkageName, F, LineNo, Ty,
- isLocalToUnit, isDefinition, LineNo, DITypeRef::get(VTableHolder), VK,
- VIndex, Flags, isOptimized, isDefinition ? CUNode : nullptr, TParams,
- nullptr, nullptr);
+ /* IsDistinct = */ isDefinition, VMContext, cast<DIScope>(Context), Name,
+ LinkageName, F, LineNo, Ty, isLocalToUnit, isDefinition, LineNo,
+ VTableHolder, VK, VIndex, Flags, isOptimized,
+ isDefinition ? CUNode : nullptr, TParams, nullptr, nullptr);
if (isDefinition)
AllSubprograms.push_back(SP);
@@ -863,7 +831,7 @@ void DIBuilder::replaceVTableHolder(DICompositeType *&T,
DICompositeType *VTableHolder) {
{
TypedTrackingMDRef<DICompositeType> N(T);
- N->replaceVTableHolder(DITypeRef::get(VTableHolder));
+ N->replaceVTableHolder(VTableHolder);
T = N.get();
}
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 78dc910807f..e8c62961eba 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -37,30 +37,6 @@ DISubprogram *llvm::getDISubprogram(const MDNode *Scope) {
return nullptr;
}
-DITypeIdentifierMap
-llvm::generateDITypeIdentifierMap(const Module &M) {
- DITypeIdentifierMap Map;
- for (DICompileUnit *CU : M.debug_compile_units()) {
- DINodeArray Retain = CU->getRetainedTypes();
- for (unsigned Ti = 0, Te = Retain.size(); Ti != Te; ++Ti) {
- if (!isa<DICompositeType>(Retain[Ti]))
- continue;
- auto *Ty = cast<DICompositeType>(Retain[Ti]);
- if (MDString *TypeId = Ty->getRawIdentifier()) {
- // Definition has priority over declaration.
- // Try to insert (TypeId, Ty) to Map.
- std::pair<DITypeIdentifierMap::iterator, bool> P =
- Map.insert(std::make_pair(TypeId, Ty));
- // If TypeId already exists in Map and this is a definition, replace
- // whatever we had (declaration or definition) with the definition.
- if (!P.second && !Ty->isForwardDecl())
- P.first->second = Ty;
- }
- }
- }
- return Map;
-}
-
//===----------------------------------------------------------------------===//
// DebugInfoFinder implementations.
//===----------------------------------------------------------------------===//
@@ -72,25 +48,15 @@ void DebugInfoFinder::reset() {
TYs.clear();
Scopes.clear();
NodesSeen.clear();
- TypeIdentifierMap.clear();
- TypeMapInitialized = false;
-}
-
-void DebugInfoFinder::InitializeTypeMap(const Module &M) {
- if (TypeMapInitialized)
- return;
- TypeIdentifierMap = generateDITypeIdentifierMap(M);
- TypeMapInitialized = true;
}
void DebugInfoFinder::processModule(const Module &M) {
- InitializeTypeMap(M);
for (auto *CU : M.debug_compile_units()) {
addCompileUnit(CU);
for (auto *DIG : CU->getGlobalVariables()) {
if (addGlobalVariable(DIG)) {
processScope(DIG->getScope());
- processType(DIG->getType().resolve(TypeIdentifierMap));
+ processType(DIG->getType().resolve());
}
}
for (auto *ET : CU->getEnumTypes())
@@ -101,7 +67,7 @@ void DebugInfoFinder::processModule(const Module &M) {
else
processSubprogram(cast<DISubprogram>(RT));
for (auto *Import : CU->getImportedEntities()) {
- auto *Entity = Import->getEntity().resolve(TypeIdentifierMap);
+ auto *Entity = Import->getEntity().resolve();
if (auto *T = dyn_cast<DIType>(Entity))
processType(T);
else if (auto *SP = dyn_cast<DISubprogram>(Entity))
@@ -120,7 +86,6 @@ void DebugInfoFinder::processModule(const Module &M) {
void DebugInfoFinder::processLocation(const Module &M, const DILocation *Loc) {
if (!Loc)
return;
- InitializeTypeMap(M);
processScope(Loc->getScope());
processLocation(M, Loc->getInlinedAt());
}
@@ -128,14 +93,14 @@ void DebugInfoFinder::processLocation(const Module &M, const DILocation *Loc) {
void DebugInfoFinder::processType(DIType *DT) {
if (!addType(DT))
return;
- processScope(DT->getScope().resolve(TypeIdentifierMap));
+ processScope(DT->getScope().resolve());
if (auto *ST = dyn_cast<DISubroutineType>(DT)) {
for (DITypeRef Ref : ST->getTypeArray())
- processType(Ref.resolve(TypeIdentifierMap));
+ processType(Ref.resolve());
return;
}
if (auto *DCT = dyn_cast<DICompositeType>(DT)) {
- processType(DCT->getBaseType().resolve(TypeIdentifierMap));
+ processType(DCT->getBaseType().resolve());
for (Metadata *D : DCT->getElements()) {
if (auto *T = dyn_cast<DIType>(D))
processType(T);
@@ -145,7 +110,7 @@ void DebugInfoFinder::processType(DIType *DT) {
return;
}
if (auto *DDT = dyn_cast<DIDerivedType>(DT)) {
- processType(DDT->getBaseType().resolve(TypeIdentifierMap));
+ processType(DDT->getBaseType().resolve());
}
}
@@ -178,13 +143,13 @@ void DebugInfoFinder::processScope(DIScope *Scope) {
void DebugInfoFinder::processSubprogram(DISubprogram *SP) {
if (!addSubprogram(SP))
return;
- processScope(SP->getScope().resolve(TypeIdentifierMap));
+ processScope(SP->getScope().resolve());
processType(SP->getType());
for (auto *Element : SP->getTemplateParams()) {
if (auto *TType = dyn_cast<DITemplateTypeParameter>(Element)) {
- processType(TType->getType().resolve(TypeIdentifierMap));
+ processType(TType->getType().resolve());
} else if (auto *TVal = dyn_cast<DITemplateValueParameter>(Element)) {
- processType(TVal->getType().resolve(TypeIdentifierMap));
+ processType(TVal->getType().resolve());
}
}
}
@@ -194,7 +159,6 @@ void DebugInfoFinder::processDeclare(const Module &M,
auto *N = dyn_cast<MDNode>(DDI->getVariable());
if (!N)
return;
- InitializeTypeMap(M);
auto *DV = dyn_cast<DILocalVariable>(N);
if (!DV)
@@ -203,14 +167,13 @@ void DebugInfoFinder::processDeclare(const Module &M,
if (!NodesSeen.insert(DV).second)
return;
processScope(DV->getScope());
- processType(DV->getType().resolve(TypeIdentifierMap));
+ processType(DV->getType().resolve());
}
void DebugInfoFinder::processValue(const Module &M, const DbgValueInst *DVI) {
auto *N = dyn_cast<MDNode>(DVI->getVariable());
if (!N)
return;
- InitializeTypeMap(M);
auto *DV = dyn_cast<DILocalVariable>(N);
if (!DV)
@@ -219,7 +182,7 @@ void DebugInfoFinder::processValue(const Module &M, const DbgValueInst *DVI) {
if (!NodesSeen.insert(DV).second)
return;
processScope(DV->getScope());
- processType(DV->getType().resolve(TypeIdentifierMap));
+ processType(DV->getType().resolve());
}
bool DebugInfoFinder::addType(DIType *DT) {
diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp
index 2c9873078c4..4c5ff16df2f 100644
--- a/llvm/lib/IR/DebugInfoMetadata.cpp
+++ b/llvm/lib/IR/DebugInfoMetadata.cpp
@@ -115,13 +115,13 @@ DIScopeRef DIScope::getScope() const {
return SP->getScope();
if (auto *LB = dyn_cast<DILexicalBlockBase>(this))
- return DIScopeRef(LB->getScope());
+ return LB->getScope();
if (auto *NS = dyn_cast<DINamespace>(this))
- return DIScopeRef(NS->getScope());
+ return NS->getScope();
if (auto *M = dyn_cast<DIModule>(this))
- return DIScopeRef(M->getScope());
+ return M->getScope();
assert((isa<DIFile>(this) || isa<DICompileUnit>(this)) &&
"Unhandled type of scope.");
diff --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h
index a4d7b7eaf9e..7d7be4492c7 100644
--- a/llvm/lib/IR/LLVMContextImpl.h
+++ b/llvm/lib/IR/LLVMContextImpl.h
@@ -380,8 +380,10 @@ template <> struct MDNodeKeyImpl<DIDerivedType> {
// If this is a member inside an ODR type, only hash the type and the name.
// Otherwise the hash will be stronger than
// MDNodeSubsetEqualImpl::isODRMember().
- if (Tag == dwarf::DW_TAG_member && Name && Scope && isa<MDString>(Scope))
- return hash_combine(Name, Scope);
+ if (Tag == dwarf::DW_TAG_member && Name)
+ if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
+ if (CT->getRawIdentifier())
+ return hash_combine(Name, Scope);
// Intentionally computes the hash on a subset of the operands for
// performance reason. The subset has to be significant enough to avoid
@@ -406,7 +408,11 @@ template <> struct MDNodeSubsetEqualImpl<DIDerivedType> {
static bool isODRMember(unsigned Tag, const Metadata *Scope,
const MDString *Name, const DIDerivedType *RHS) {
// Check whether the LHS is eligible.
- if (Tag != dwarf::DW_TAG_member || !Name || !Scope || !isa<MDString>(Scope))
+ if (Tag != dwarf::DW_TAG_member || !Name)
+ return false;
+
+ auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
+ if (!CT || !CT->getRawIdentifier())
return false;
// Compare to the RHS.
@@ -571,8 +577,10 @@ template <> struct MDNodeKeyImpl<DISubprogram> {
// If this is a declaration inside an ODR type, only hash the type and the
// name. Otherwise the hash will be stronger than
// MDNodeSubsetEqualImpl::isDeclarationOfODRMember().
- if (!IsDefinition && LinkageName && Scope && isa<MDString>(Scope))
- return hash_combine(LinkageName, Scope);
+ if (!IsDefinition && LinkageName)
+ if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
+ if (CT->getRawIdentifier())
+ return hash_combine(LinkageName, Scope);
// Intentionally computes the hash on a subset of the operands for
// performance reason. The subset has to be significant enough to avoid
@@ -599,8 +607,11 @@ template <> struct MDNodeSubsetEqualImpl<DISubprogram> {
const MDString *LinkageName,
const DISubprogram *RHS) {
// Check whether the LHS is eligible.
- if (IsDefinition || !Scope || !LinkageName || !Scope ||
- !isa<MDString>(Scope))
+ if (IsDefinition || !Scope || !LinkageName)
+ return false;
+
+ auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
+ if (!CT || !CT->getRawIdentifier())
return false;
// Compare to the RHS.
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index cf507c4459c..30f3715b08e 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -203,9 +203,6 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
/// Track all DICompileUnits visited.
SmallPtrSet<const Metadata *, 2> CUVisited;
- /// \brief Track unresolved string-based type references.
- SmallDenseMap<const MDString *, const MDNode *, 32> UnresolvedTypeRefs;
-
/// \brief The result type for a landingpad.
Type *LandingPadResultTy;
@@ -323,9 +320,6 @@ public:
verifyCompileUnits();
- // Verify type references last.
- verifyTypeRefs();
-
return !Broken;
}
@@ -362,27 +356,6 @@ private:
void visitTemplateParams(const MDNode &N, const Metadata &RawParams);
- /// \brief Check for a valid string-based type reference.
- ///
- /// Checks if \c MD is a string-based type reference. If it is, keeps track
- /// of it (and its user, \c N) for error messages later.
- bool isValidUUID(const MDNode &N, const Metadata *MD);
-
- /// \brief Check for a valid type reference.
- ///
- /// Checks for subclasses of \a DIType, or \a isValidUUID().
- bool isTypeRef(const MDNode &N, const Metadata *MD);
-
- /// \brief Check for a valid scope reference.
- ///
- /// Checks for subclasses of \a DIScope, or \a isValidUUID().
- bool isScopeRef(const MDNode &N, const Metadata *MD);
-
- /// \brief Check for a valid debug info reference.
- ///
- /// Checks for subclasses of \a DINode, or \a isValidUUID().
- bool isDIRef(const MDNode &N, const Metadata *MD);
-
// InstVisitor overrides...
using InstVisitor<Verifier>::visit;
void visit(Instruction &I);
@@ -467,15 +440,10 @@ private:
void verifyFrameRecoverIndices();
void verifySiblingFuncletUnwinds();
- /// @{
+ void verifyBitPieceExpression(const DbgInfoIntrinsic &I);
+
/// Module-level debug info verification...
- void verifyTypeRefs();
void verifyCompileUnits();
- template <class MapTy>
- void verifyBitPieceExpression(const DbgInfoIntrinsic &I,
- const MapTy &TypeRefs);
- void visitUnresolvedTypeRef(const MDString *S, const MDNode *N);
- /// @}
};
} // End anonymous namespace
@@ -774,31 +742,9 @@ void Verifier::visitMetadataAsValue(const MetadataAsValue &MDV, Function *F) {
visitValueAsMetadata(*V, F);
}
-bool Verifier::isValidUUID(const MDNode &N, const Metadata *MD) {
- auto *S = dyn_cast<MDString>(MD);
- if (!S || S->getString().empty())
- return false;
-
- // Keep track of names of types referenced via UUID so we can check that they
- // actually exist.
- UnresolvedTypeRefs.insert(std::make_pair(S, &N));
- return true;
-}
-
-/// \brief Check if a value can be a reference to a type.
-bool Verifier::isTypeRef(const MDNode &N, const Metadata *MD) {
- return !MD || isValidUUID(N, MD) || isa<DIType>(MD);
-}
-
-/// \brief Check if a value can be a ScopeRef.
-bool Verifier::isScopeRef(const MDNode &N, const Metadata *MD) {
- return !MD || isValidUUID(N, MD) || isa<DIScope>(MD);
-}
-
-/// \brief Check if a value can be a debug info ref.
-bool Verifier::isDIRef(const MDNode &N, const Metadata *MD) {
- return !MD || isValidUUID(N, MD) || isa<DINode>(MD);
-}
+static bool isType(const Metadata *MD) { return !MD || isa<DIType>(MD); }
+static bool isScope(const Metadata *MD) { return !MD || isa<DIScope>(MD); }
+static bool isDINode(const Metadata *MD) { return !MD || isa<DINode>(MD); }
template <class Ty>
bool isValidMetadataArrayImpl(const MDTuple &N, bool AllowNull) {
@@ -872,13 +818,13 @@ void Verifier::visitDIDerivedType(const DIDerivedType &N) {
N.getTag() == dwarf::DW_TAG_friend,
"invalid tag", &N);
if (N.getTag() == dwarf::DW_TAG_ptr_to_member_type) {
- Assert(isTypeRef(N, N.getExtraData()), "invalid pointer to member type", &N,
- N.getExtraData());
+ Assert(isType(N.getRawExtraData()), "invalid pointer to member type", &N,
+ N.getRawExtraData());
}
- Assert(isScopeRef(N, N.getScope()), "invalid scope", &N, N.getRawScope());
- Assert(isTypeRef(N, N.getBaseType()), "invalid base type", &N,
- N.getBaseType());
+ Assert(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope());
+ Assert(isType(N.getRawBaseType()), "invalid base type", &N,
+ N.getRawBaseType());
}
static bool hasConflictingReferenceFlags(unsigned Flags) {
@@ -906,13 +852,13 @@ void Verifier::visitDICompositeType(const DICompositeType &N) {
N.getTag() == dwarf::DW_TAG_class_type,
"invalid tag", &N);
- Assert(isScopeRef(N, N.getScope()), "invalid scope", &N, N.getRawScope());
- Assert(isTypeRef(N, N.getBaseType()), "invalid base type", &N,
- N.getBaseType());
+ Assert(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope());
+ Assert(isType(N.getRawBaseType()), "invalid base type", &N,
+ N.getRawBaseType());
Assert(!N.getRawElements() || isa<MDTuple>(N.getRawElements()),
"invalid composite elements", &N, N.getRawElements());
- Assert(isTypeRef(N, N.getRawVTableHolder()), "invalid vtable holder", &N,
+ Assert(isType(N.getRawVTableHolder()), "invalid vtable holder", &N,
N.getRawVTableHolder());
Assert(!hasConflictingReferenceFlags(N.getFlags()), "invalid reference flags",
&N);
@@ -931,7 +877,7 @@ void Verifier::visitDISubroutineType(const DISubroutineType &N) {
if (auto *Types = N.getRawTypeArray()) {
Assert(isa<MDTuple>(Types), "invalid composite elements", &N, Types);
for (Metadata *Ty : N.getTypeArray()->operands()) {
- Assert(isTypeRef(N, Ty), "invalid subroutine type ref", &N, Types, Ty);
+ Assert(isType(Ty), "invalid subroutine type ref", &N, Types, Ty);
}
}
Assert(!hasConflictingReferenceFlags(N.getFlags()), "invalid reference flags",
@@ -998,12 +944,12 @@ void Verifier::visitDICompileUnit(const DICompileUnit &N) {
void Verifier::visitDISubprogram(const DISubprogram &N) {
Assert(N.getTag() == dwarf::DW_TAG_subprogram, "invalid tag", &N);
- Assert(isScopeRef(N, N.getRawScope()), "invalid scope", &N, N.getRawScope());
+ Assert(isScope(N.getRawScope()), "invalid scope", &N, N.getRawScope());
if (auto *F = N.getRawFile())
Assert(isa<DIFile>(F), "invalid file", &N, F);
if (auto *T = N.getRawType())
Assert(isa<DISubroutineType>(T), "invalid subroutine type", &N, T);
- Assert(isTypeRef(N, N.getRawContainingType()), "invalid containing type", &N,
+ Assert(isType(N.getRawContainingType()), "invalid containing type", &N,
N.getRawContainingType());
if (auto *Params = N.getRawTemplateParams())
visitTemplateParams(N, *Params);
@@ -1086,7 +1032,7 @@ void Verifier::visitDIModule(const DIModule &N) {
}
void Verifier::visitDITemplateParameter(const DITemplateParameter &N) {
- Assert(isTypeRef(N, N.getType()), "invalid type ref", &N, N.getType());
+ Assert(isType(N.getRawType()), "invalid type ref", &N, N.getRawType());
}
void Verifier::visitDITemplateTypeParameter(const DITemplateTypeParameter &N) {
@@ -1109,7 +1055,7 @@ void Verifier::visitDITemplateValueParameter(
void Verifier::visitDIVariable(const DIVariable &N) {
if (auto *S = N.getRawScope())
Assert(isa<DIScope>(S), "invalid scope", &N, S);
- Assert(isTypeRef(N, N.getRawType()), "invalid type ref", &N, N.getRawType());
+ Assert(isType(N.getRawType()), "invalid type ref", &N, N.getRawType());
if (auto *F = N.getRawFile())
Assert(isa<DIFile>(F), "invalid file", &N, F);
}
@@ -1148,7 +1094,7 @@ void Verifier::visitDIExpression(const DIExpression &N) {
void Verifier::visitDIObjCProperty(const DIObjCProperty &N) {
Assert(N.getTag() == dwarf::DW_TAG_APPLE_property, "invalid tag", &N);
if (auto *T = N.getRawType())
- Assert(isTypeRef(N, T), "invalid type ref", &N, T);
+ Assert(isType(T), "invalid type ref", &N, T);
if (auto *F = N.getRawFile())
Assert(isa<DIFile>(F), "invalid file", &N, F);
}
@@ -1159,8 +1105,8 @@ void Verifier::visitDIImportedEntity(const DIImportedEntity &N) {
"invalid tag", &N);
if (auto *S = N.getRawScope())
Assert(isa<DIScope>(S), "invalid scope for imported entity", &N, S);
- Assert(isDIRef(N, N.getEntity()), "invalid imported entity", &N,
- N.getEntity());
+ Assert(isDINode(N.getRawEntity()), "invalid imported entity", &N,
+ N.getRawEntity());
}
void Verifier::visitComdat(const Comdat &C) {
@@ -3725,6 +3671,9 @@ void Verifier::visitInstruction(Instruction &I) {
visitMDNode(*N);
}
+ if (auto *DII = dyn_cast<DbgInfoIntrinsic>(&I))
+ verifyBitPieceExpression(*DII);
+
InstsInThisBlock.insert(&I);
}
@@ -4335,8 +4284,7 @@ void Verifier::visitDbgIntrinsic(StringRef Kind, DbgIntrinsicTy &DII) {
Loc->getScope()->getSubprogram());
}
-template <class MapTy>
-static uint64_t getVariableSize(const DILocalVariable &V, const MapTy &Map) {
+static uint64_t getVariableSize(const DILocalVariable &V) {
// Be careful of broken types (checked elsewhere).
const Metadata *RawType = V.getRawType();
while (RawType) {
@@ -4351,12 +4299,6 @@ static uint64_t getVariableSize(const DILocalVariable &V, const MapTy &Map) {
continue;
}
- if (auto *S = dyn_cast<MDString>(RawType)) {
- // Don't error on missing types (checked elsewhere).
- RawType = Map.lookup(S);
- continue;
- }
-
// Missing type or size.
break;
}
@@ -4365,9 +4307,7 @@ static uint64_t getVariableSize(const DILocalVariable &V, const MapTy &Map) {
return 0;
}
-template <class MapTy>
-void Verifier::verifyBitPieceExpression(const DbgInfoIntrinsic &I,
- const MapTy &TypeRefs) {
+void Verifier::verifyBitPieceExpression(const DbgInfoIntrinsic &I) {
DILocalVariable *V;
DIExpression *E;
if (auto *DVI = dyn_cast<DbgValueInst>(&I)) {
@@ -4398,7 +4338,7 @@ void Verifier::verifyBitPieceExpression(const DbgInfoIntrinsic &I,
// If there's no size, the type is broken, but that should be checked
// elsewhere.
- uint64_t VarSize = getVariableSize(*V, TypeRefs);
+ uint64_t VarSize = getVariableSize(*V);
if (!VarSize)
return;
@@ -4409,12 +4349,6 @@ void Verifier::verifyBitPieceExpression(const DbgInfoIntrinsic &I,
Assert(PieceSize != VarSize, "piece covers entire variable", &I, V, E);
}
-void Verifier::visitUnresolvedTypeRef(const MDString *S, const MDNode *N) {
- // This is in its own function so we get an error for each bad type ref (not
- // just the first).
- Assert(false, "unresolved type ref", S, N);
-}
-
void Verifier::verifyCompileUnits() {
auto *CUs = M->getNamedMetadata("llvm.dbg.cu");
SmallPtrSet<const Metadata *, 2> Listed;
@@ -4427,56 +4361,6 @@ void Verifier::verifyCompileUnits() {
CUVisited.clear();
}
-void Verifier::verifyTypeRefs() {
- auto *CUs = M->getNamedMetadata("llvm.dbg.cu");
- if (!CUs)
- return;
-
- // Visit all the compile units again to map the type references.
- SmallDenseMap<const MDString *, const DIType *, 32> TypeRefs;
- for (auto *MD : CUs->operands()) {
- auto *CU = dyn_cast<DICompileUnit>(MD);
- if (!CU)
- continue;
- auto *Array = CU->getRawRetainedTypes();
- if (!Array || !isa<MDTuple>(Array))
- continue;
- for (DIScope *Op : CU->getRetainedTypes())
- if (auto *T = dyn_cast_or_null<DICompositeType>(Op))
- if (auto *S = T->getRawIdentifier()) {
- UnresolvedTypeRefs.erase(S);
- TypeRefs.insert(std::make_pair(S, T));
- }
- }
-
- // Verify debug info intrinsic bit piece expressions. This needs a second
- // pass through the intructions, since we haven't built TypeRefs yet when
- // verifying functions, and simply queuing the DbgInfoIntrinsics to evaluate
- // later/now would queue up some that could be later deleted.
- for (const Function &F : *M)
- for (const BasicBlock &BB : F)
- for (const Instruction &I : BB)
- if (auto *DII = dyn_cast<DbgInfoIntrinsic>(&I))
- verifyBitPieceExpression(*DII, TypeRefs);
-
- // Return early if all typerefs were resolved.
- if (UnresolvedTypeRefs.empty())
- return;
-
- // Sort the unresolved references by name so the output is deterministic.
- typedef std::pair<const MDString *, const MDNode *> TypeRef;
- SmallVector<TypeRef, 32> Unresolved(UnresolvedTypeRefs.begin(),
- UnresolvedTypeRefs.end());
- std::sort(Unresolved.begin(), Unresolved.end(),
- [](const TypeRef &LHS, const TypeRef &RHS) {
- return LHS.first->getString() < RHS.first->getString();
- });
-
- // Visit the unresolved refs (printing out the errors).
- for (const TypeRef &TR : Unresolved)
- visitUnresolvedTypeRef(TR.first, TR.second);
-}
-
//===----------------------------------------------------------------------===//
// Implement the public interfaces to this file...
//===----------------------------------------------------------------------===//
OpenPOWER on IntegriCloud