aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/DIBuilder.cpp
diff options
context:
space:
mode:
authorAdrian Prantl <aprantl@apple.com>2016-04-15 15:57:41 +0000
committerAdrian Prantl <aprantl@apple.com>2016-04-15 15:57:41 +0000
commit75819aedf6d774a424e35793b266442708e57050 (patch)
treee4eabf3bd19e9dee6ed3aefc8f4e2cb16d6bb285 /llvm/lib/IR/DIBuilder.cpp
parente76bda544bbf52d9ff3b55e6018b494a1e6bbc00 (diff)
downloadllvm-75819aedf6d774a424e35793b266442708e57050.zip
llvm-75819aedf6d774a424e35793b266442708e57050.tar.gz
llvm-75819aedf6d774a424e35793b266442708e57050.tar.bz2
[PR27284] Reverse the ownership between DICompileUnit and DISubprogram.
Currently each Function points to a DISubprogram and DISubprogram has a scope field. For member functions the scope is a DICompositeType. DIScopes point to the DICompileUnit to facilitate type uniquing. Distinct DISubprograms (with isDefinition: true) are not part of the type hierarchy and cannot be uniqued. This change removes the subprograms list from DICompileUnit and instead adds a pointer to the owning compile unit to distinct DISubprograms. This would make it easy for ThinLTO to strip unneeded DISubprograms and their transitively referenced debug info. Motivation ---------- Materializing DISubprograms is currently the most expensive operation when doing a ThinLTO build of clang. We want the DISubprogram to be stored in a separate Bitcode block (or the same block as the function body) so we can avoid having to expensively deserialize all DISubprograms together with the global metadata. If a function has been inlined into another subprogram we need to store a reference the block containing the inlined subprogram. Attached to https://llvm.org/bugs/show_bug.cgi?id=27284 is a python script that updates LLVM IR testcases to the new format. http://reviews.llvm.org/D19034 <rdar://problem/25256815> llvm-svn: 266446
Diffstat (limited to 'llvm/lib/IR/DIBuilder.cpp')
-rw-r--r--llvm/lib/IR/DIBuilder.cpp40
1 files changed, 23 insertions, 17 deletions
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index aa9ffcf..5c9a3c4 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -96,17 +96,19 @@ void DIBuilder::finalize() {
CUNode->replaceRetainedTypes(MDTuple::get(VMContext, RetainValues));
DISubprogramArray SPs = MDTuple::get(VMContext, AllSubprograms);
- if (!AllSubprograms.empty())
- CUNode->replaceSubprograms(SPs.get());
-
- for (auto *SP : SPs) {
+ auto resolveVariables = [&](DISubprogram *SP) {
if (MDTuple *Temp = SP->getVariables().get()) {
const auto &PV = PreservedVariables.lookup(SP);
SmallVector<Metadata *, 4> Variables(PV.begin(), PV.end());
DINodeArray AV = getOrCreateArray(Variables);
TempMDTuple(Temp)->replaceAllUsesWith(AV.get());
}
- }
+ };
+ for (auto *SP : SPs)
+ resolveVariables(SP);
+ for (auto *N : RetainValues)
+ if (auto *SP = dyn_cast<DISubprogram>(N))
+ resolveVariables(SP);
if (!AllGVs.empty())
CUNode->replaceGlobalVariables(MDTuple::get(VMContext, AllGVs));
@@ -148,8 +150,8 @@ DICompileUnit *DIBuilder::createCompileUnit(
assert(!CUNode && "Can only make one compile unit per DIBuilder instance");
CUNode = DICompileUnit::getDistinct(
VMContext, Lang, DIFile::get(VMContext, Filename, Directory), Producer,
- isOptimized, Flags, RunTimeVer, SplitName, Kind, nullptr,
- nullptr, nullptr, nullptr, nullptr, nullptr, DWOId);
+ isOptimized, Flags, RunTimeVer, SplitName, Kind, nullptr, nullptr,
+ nullptr, nullptr, nullptr, DWOId);
// Create a named metadata so that it is easier to find cu in a module.
NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
@@ -505,8 +507,11 @@ DIType *DIBuilder::createObjectPointerType(DIType *Ty) {
return createTypeWithFlags(VMContext, Ty, Flags);
}
-void DIBuilder::retainType(DIType *T) {
+void DIBuilder::retainType(DIScope *T) {
assert(T && "Expected non-null type");
+ assert((isa<DIType>(T) || (isa<DISubprogram>(T) &&
+ cast<DISubprogram>(T)->isDefinition() == false)) &&
+ "Expected type or subprogram declaration");
AllRetainTypes.emplace_back(T);
}
@@ -684,12 +689,12 @@ DISubprogram *DIBuilder::createFunction(
unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
bool isDefinition, unsigned ScopeLine, unsigned Flags, bool isOptimized,
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, TParams, Decl,
- MDTuple::getTemporary(VMContext, None).release());
+ 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,
+ MDTuple::getTemporary(VMContext, None).release());
if (isDefinition)
AllSubprograms.push_back(Node);
@@ -705,8 +710,8 @@ DISubprogram *DIBuilder::createTempFunctionFwdDecl(
return DISubprogram::getTemporary(
VMContext, DIScopeRef::get(getNonCompileUnitScope(Context)), Name,
LinkageName, File, LineNo, Ty, isLocalToUnit, isDefinition,
- ScopeLine, nullptr, 0, 0, Flags, isOptimized, TParams, Decl,
- nullptr)
+ ScopeLine, nullptr, 0, 0, Flags, isOptimized,
+ isDefinition ? CUNode : nullptr, TParams, Decl, nullptr)
.release();
}
@@ -724,7 +729,8 @@ DIBuilder::createMethod(DIScope *Context, StringRef Name, StringRef LinkageName,
/* IsDistinct = */ isDefinition, VMContext,
DIScopeRef::get(cast<DIScope>(Context)), Name, LinkageName, F, LineNo, Ty,
isLocalToUnit, isDefinition, LineNo, DITypeRef::get(VTableHolder), VK,
- VIndex, Flags, isOptimized, TParams, nullptr, nullptr);
+ VIndex, Flags, isOptimized, isDefinition ? CUNode : nullptr, TParams,
+ nullptr, nullptr);
if (isDefinition)
AllSubprograms.push_back(SP);