summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp32
1 files changed, 27 insertions, 5 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index d4d94cabe83..589f88d1de6 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -455,6 +455,16 @@ void DwarfDebug::constructAndAddImportedEntityDIE(DwarfCompileUnit &TheCU,
D->addChild(TheCU.constructImportedEntityDIE(N));
}
+bool DwarfDebug::collectLocalScopedNode(DIScope *S, const DINode *N,
+ DwarfCompileUnit &CU) {
+ if (auto LS = dyn_cast_or_null<DILocalScope>(S)) {
+ getLocalScopes(LS->getSubprogram()).insert(LS);
+ CU.addLocalDeclNode(N, LS);
+ return true;
+ }
+ return false;
+}
+
// Emit all Dwarf sections that should come prior to the content. Create
// global DIEs and emit initial debug info sections. This is invoked by
// the target AsmPrinter.
@@ -474,10 +484,9 @@ void DwarfDebug::beginModule() {
for (MDNode *N : CU_Nodes->operands()) {
auto *CUNode = cast<DICompileUnit>(N);
DwarfCompileUnit &CU = constructDwarfCompileUnit(CUNode);
- for (auto *IE : CUNode->getImportedEntities())
- CU.addImportedEntity(IE);
for (auto *GV : CUNode->getGlobalVariables())
- CU.getOrCreateGlobalVariableDIE(GV);
+ if (!collectLocalScopedNode(GV->getScope(), GV, CU))
+ CU.getOrCreateGlobalVariableDIE(GV);
for (auto *SP : CUNode->getSubprograms())
SPMap.insert(std::make_pair(SP, &CU));
for (auto *Ty : CUNode->getEnumTypes()) {
@@ -489,14 +498,17 @@ void DwarfDebug::beginModule() {
// The retained types array by design contains pointers to
// MDNodes rather than DIRefs. Unique them here.
DIType *RT = cast<DIType>(resolve(Ty->getRef()));
- if (!RT->isExternalTypeRef())
+ if (RT->isExternalTypeRef())
// There is no point in force-emitting a forward declaration.
+ continue;
+ if (!collectLocalScopedNode(resolve(Ty->getScope()), RT, CU))
CU.getOrCreateTypeDIE(RT);
}
// Emit imported_modules last so that the relevant context is already
// available.
for (auto *IE : CUNode->getImportedEntities())
- constructAndAddImportedEntityDIE(CU, IE);
+ if (!collectLocalScopedNode(IE->getScope(), IE, CU))
+ constructAndAddImportedEntityDIE(CU, IE);
}
// Tell MMI that we have debug info.
@@ -529,6 +541,11 @@ void DwarfDebug::finishSubprogramDefinitions() {
});
}
+void DwarfDebug::finishLocalScopeDefinitions() {
+ for (const auto &I : CUMap)
+ I.second->finishLocalScopeDefinitions();
+}
+
// Collect info for variables that were optimized out.
void DwarfDebug::collectDeadVariables() {
const Module *M = MMI->getModule();
@@ -554,6 +571,8 @@ void DwarfDebug::finalizeModuleInfo() {
finishSubprogramDefinitions();
+ finishLocalScopeDefinitions();
+
finishVariableDefinitions();
// Collect info for variables that were optimized out.
@@ -1164,6 +1183,9 @@ void DwarfDebug::endFunction(const MachineFunction *MF) {
assert(LScopes.getAbstractScopesList().size() == NumAbstractScopes
&& "ensureAbstractVariableIsCreated inserted abstract scopes");
}
+ // Assure abstract local scope created for each one contains local DIEs.
+ for (const DILocalScope *LS : getLocalScopes(SP))
+ LScopes.getOrCreateAbstractScope(LS);
constructAbstractSubprogramScopeDIE(AScope);
}
OpenPOWER on IntegriCloud