diff options
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter')
| -rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp | 29 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h | 7 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 29 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h | 17 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp | 11 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h | 4 |
6 files changed, 62 insertions, 35 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp index fc54a2925be..86389f89783 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -101,7 +101,7 @@ static const ConstantExpr *getMergedGlobalExpr(const Value *V) { /// getOrCreateGlobalVariableDIE - get or create global variable DIE. DIE *DwarfCompileUnit::getOrCreateGlobalVariableDIE( - const DIGlobalVariable *GV) { + const DIGlobalVariable *GV, DIE *ContextDIE) { // Check for pre-existence. if (DIE *Die = getDIE(GV)) return Die; @@ -113,7 +113,8 @@ DIE *DwarfCompileUnit::getOrCreateGlobalVariableDIE( // Construct the context before querying for the existence of the DIE in // case such construction creates the DIE. - DIE *ContextDIE = getOrCreateContextDIE(GVContext); + if (ContextDIE == nullptr) + ContextDIE = getOrCreateContextDIE(GVContext); // Add to map. DIE *VariableDIE = &createAndAddDIE(GV->getTag(), *ContextDIE, GV); @@ -335,17 +336,16 @@ void DwarfCompileUnit::constructScopeDIE( // null and the children will be added to the scope DIE. createScopeChildrenDIE(Scope, Children, &ChildScopeCount); - // Skip imported directives in gmlt-like data. - if (!includeMinimalInlineScopes()) { - // There is no need to emit empty lexical block DIE. - for (const auto &E : DD->findImportedEntitiesForScope(DS)) - Children.push_back( - constructImportedEntityDIE(cast<DIImportedEntity>(E.second))); - } + + DwarfDebug::LocalDeclMapRange LocalDeclNodeRangeForScope(nullptr, nullptr); + // Skip local decls in gmlt-like data. + if (!includeMinimalInlineScopes()) + LocalDeclNodeRangeForScope = DD->findLocalDeclNodesForScope(DS); // If there are only other scopes as children, put them directly in the // parent instead, as this scope would serve no purpose. - if (Children.size() == ChildScopeCount) { + if (Children.size() == ChildScopeCount && + empty(LocalDeclNodeRangeForScope)) { FinalChildren.insert(FinalChildren.end(), std::make_move_iterator(Children.begin()), std::make_move_iterator(Children.end())); @@ -353,6 +353,15 @@ void DwarfCompileUnit::constructScopeDIE( } ScopeDIE = constructLexicalScopeDIE(Scope); assert(ScopeDIE && "Scope DIE should not be null."); + + for (const auto &DI : LocalDeclNodeRangeForScope) { + if (auto *IE = dyn_cast<DIImportedEntity>(DI.second)) + Children.push_back(constructImportedEntityDIE(IE)); + else if (auto *GV = dyn_cast<DIGlobalVariable>(DI.second)) + getOrCreateGlobalVariableDIE(GV, ScopeDIE); + else if (auto *RT = dyn_cast<DIType>(DI.second)) + getOrCreateTypeDIE(RT, ScopeDIE); + } } // Add children diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h index 509c9432bcb..132b06885a3 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h @@ -77,8 +77,11 @@ public: /// Apply the DW_AT_stmt_list from this compile unit to the specified DIE. void applyStmtList(DIE &D); - /// getOrCreateGlobalVariableDIE - get or create global variable DIE. - DIE *getOrCreateGlobalVariableDIE(const DIGlobalVariable *GV); + /// Get or create global variable DIE. + /// \param GV Global Variable Node + /// \param ContextDIE DIE scope for GV Node, if available. + DIE *getOrCreateGlobalVariableDIE(const DIGlobalVariable *GV, + DIE *ContextDIE = nullptr); /// addLabelAddress - Add a dwarf label attribute data and value using /// either DW_FORM_addr or DW_FORM_GNU_addr_index. diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 7d03a3930d7..363311e8c9e 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -449,14 +449,14 @@ void DwarfDebug::beginModule() { auto *CUNode = cast<DICompileUnit>(N); DwarfCompileUnit &CU = constructDwarfCompileUnit(CUNode); for (auto *IE : CUNode->getImportedEntities()) - ScopesWithImportedEntities.push_back(std::make_pair(IE->getScope(), IE)); - // Stable sort to preserve the order of appearance of imported entities. - // This is to avoid out-of-order processing of interdependent declarations - // within the same scope, e.g. { namespace A = base; namespace B = A; } - std::stable_sort(ScopesWithImportedEntities.begin(), - ScopesWithImportedEntities.end(), less_first()); - for (auto *GV : CUNode->getGlobalVariables()) - CU.getOrCreateGlobalVariableDIE(GV); + ScopesWithLocalDeclNodes.push_back(std::make_pair(IE->getScope(), IE)); + for (auto *GV : CUNode->getGlobalVariables()) { + auto *Context = GV->getScope(); + if (Context && isa<DILexicalBlockBase>(Context)) + ScopesWithLocalDeclNodes.push_back(std::make_pair(Context, GV)); + else + CU.getOrCreateGlobalVariableDIE(GV); + } for (auto *SP : CUNode->getSubprograms()) SPMap.insert(std::make_pair(SP, &CU)); for (auto *Ty : CUNode->getEnumTypes()) { @@ -467,12 +467,23 @@ void DwarfDebug::beginModule() { for (auto *Ty : CUNode->getRetainedTypes()) { // The retained types array by design contains pointers to // MDNodes rather than DIRefs. Unique them here. - CU.getOrCreateTypeDIE(cast<DIType>(resolve(Ty->getRef()))); + DIType *RT = cast<DIType>(resolve(Ty->getRef())); + auto *Context = resolve(Ty->getScope()); + if (Context && isa<DILexicalBlockBase>(Context)) + ScopesWithLocalDeclNodes.push_back(std::make_pair(Context, RT)); + else + CU.getOrCreateTypeDIE(RT); } // Emit imported_modules last so that the relevant context is already // available. for (auto *IE : CUNode->getImportedEntities()) constructAndAddImportedEntityDIE(CU, IE); + + // Stable sort to preserve the order of appearance of imported entities. + // This is to avoid out-of-order processing of interdependent declarations + // within the same scope, e.g. { namespace A = base; namespace B = A; } + std::stable_sort(ScopesWithLocalDeclNodes.begin(), + ScopesWithLocalDeclNodes.end(), less_first()); } // Tell MMI that we have debug info. diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h index 1c3e2aec64a..3a583e71c4c 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -278,13 +278,10 @@ class DwarfDebug : public AsmPrinterHandler { // Holder for the file specific debug information. DwarfFile InfoHolder; - // Holders for the various debug information flags that we might need to - // have exposed. See accessor functions below for description. - - // Holder for imported entities. + // Holder for local declaration DI nodes per scope. typedef SmallVector<std::pair<const MDNode *, const MDNode *>, 32> - ImportedEntityMap; - ImportedEntityMap ScopesWithImportedEntities; + LocalDeclMap; + LocalDeclMap ScopesWithLocalDeclNodes; // Map from MDNodes for user-defined types to the type units that describe // them. @@ -619,10 +616,12 @@ public: const MachineFunction *getCurrentFunction() const { return CurFn; } - iterator_range<ImportedEntityMap::const_iterator> - findImportedEntitiesForScope(const MDNode *Scope) const { + typedef iterator_range<LocalDeclMap::const_iterator> LocalDeclMapRange; + + LocalDeclMapRange findLocalDeclNodesForScope(const MDNode *Scope) const { + assert(DILexicalBlockBase::classof(Scope) && "Expected LexicalBlock scope"); return make_range(std::equal_range( - ScopesWithImportedEntities.begin(), ScopesWithImportedEntities.end(), + ScopesWithLocalDeclNodes.begin(), ScopesWithLocalDeclNodes.end(), std::pair<const MDNode *, const MDNode *>(Scope, nullptr), less_first())); } diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp index 355582298e5..6334be5f027 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -704,7 +704,7 @@ DIE *DwarfUnit::createTypeDIE(const DICompositeType *Ty) { return &TyDIE; } -DIE *DwarfUnit::getOrCreateTypeDIE(const MDNode *TyNode) { +DIE *DwarfUnit::getOrCreateTypeDIE(const MDNode *TyNode, DIE *ContextDIE) { if (!TyNode) return nullptr; @@ -714,17 +714,20 @@ DIE *DwarfUnit::getOrCreateTypeDIE(const MDNode *TyNode) { // DW_TAG_restrict_type is not supported in DWARF2 if (Ty->getTag() == dwarf::DW_TAG_restrict_type && DD->getDwarfVersion() <= 2) - return getOrCreateTypeDIE(resolve(cast<DIDerivedType>(Ty)->getBaseType())); + return getOrCreateTypeDIE(resolve(cast<DIDerivedType>(Ty)->getBaseType()), + ContextDIE); // Construct the context before querying for the existence of the DIE in case // such construction creates the DIE. auto *Context = resolve(Ty->getScope()); - DIE *ContextDIE = getOrCreateContextDIE(Context); - assert(ContextDIE); + if (ContextDIE == nullptr) + ContextDIE = getOrCreateContextDIE(Context); if (DIE *TyDIE = getDIE(Ty)) return TyDIE; + assert(ContextDIE); + // Create new type. DIE &TyDIE = createAndAddDIE(Ty->getTag(), *ContextDIE, Ty); diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h index 4000ae48a85..3f4809974f3 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h @@ -298,7 +298,9 @@ public: bool Minimal = false); /// \brief Find existing DIE or create new DIE for the given type. - DIE *getOrCreateTypeDIE(const MDNode *N); + /// \param N Type Node + /// \param ContextDIE DIE scope for N Node, if available. + DIE *getOrCreateTypeDIE(const MDNode *N, DIE *ContextDIE = nullptr); /// \brief Get context owner's DIE. DIE *createTypeDIE(const DICompositeType *Ty); |

