diff options
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp')
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp | 128 |
1 files changed, 33 insertions, 95 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp index 58ed213..fd583a3 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -694,7 +694,7 @@ DIE *DwarfCompileUnit::constructInlinedScopeDIE(LexicalScope *Scope, auto *InlinedSP = getDISubprogram(DS); // Find the subprogram's DwarfCompileUnit in the SPMap in case the subprogram // was inlined from another compile unit. - DIE *OriginDIE = getAbstractScopeDIEs()[InlinedSP]; + DIE *OriginDIE = getAbstractSPDies()[InlinedSP]; assert(OriginDIE && "Unable to find original DIE for an inlined subprogram."); auto ScopeDIE = DIE::get(DIEValueAllocator, dwarf::DW_TAG_inlined_subroutine); @@ -726,20 +726,10 @@ DIE *DwarfCompileUnit::constructInlinedScopeDIE(LexicalScope *Scope, DIE *DwarfCompileUnit::constructLexicalScopeDIE(LexicalScope *Scope) { if (DD->isLexicalScopeDIENull(Scope)) return nullptr; - const auto *DS = Scope->getScopeNode(); auto ScopeDIE = DIE::get(DIEValueAllocator, dwarf::DW_TAG_lexical_block); - if (Scope->isAbstractScope()) { - assert(!getAbstractScopeDIEs().count(DS) && - "Abstract DIE for this scope exists!"); - getAbstractScopeDIEs()[DS] = ScopeDIE; + if (Scope->isAbstractScope()) return ScopeDIE; - } - if (!Scope->getInlinedAt()) { - assert(!LexicalBlockDIEs.count(DS) && - "Concrete out-of-line DIE for this scope exists!"); - LexicalBlockDIEs[DS] = ScopeDIE; - } attachRangesOrLowHighPC(*ScopeDIE, Scope->getRanges()); @@ -1107,35 +1097,35 @@ DIE *DwarfCompileUnit::createAndAddScopeChildren(LexicalScope *Scope, for (DbgVariable *DV : Locals) ScopeDIE.addChild(constructVariableDIE(*DV, *Scope, ObjectPointer)); + // Emit imported entities (skipped in gmlt-like data). + if (!includeMinimalInlineScopes()) { + for (const auto *IE : ImportedEntities[Scope->getScopeNode()]) + ScopeDIE.addChild(constructImportedEntityDIE(cast<DIImportedEntity>(IE))); + } + // Emit labels. for (DbgLabel *DL : DU->getScopeLabels().lookup(Scope)) ScopeDIE.addChild(constructLabelDIE(*DL, *Scope)); - // Track other local entities (skipped in gmlt-like data). - // This creates mapping between CU and a set of local declarations that - // should be emitted for subprograms in this CU. - if (!includeMinimalInlineScopes() && !Scope->getInlinedAt()) { - auto &LocalDecls = DD->getLocalDeclsForScope(Scope->getScopeNode()); - DeferredLocalDecls.insert(LocalDecls.begin(), LocalDecls.end()); - } - // Emit inner lexical scopes. - auto skipLexicalScope = [this](LexicalScope *S) -> bool { - if (isa<DISubprogram>(S->getScopeNode())) - return false; - auto Vars = DU->getScopeVariables().lookup(S); + auto needToEmitLexicalScope = [this](LexicalScope *LS) { + if (isa<DISubprogram>(LS->getScopeNode())) + return true; + auto Vars = DU->getScopeVariables().lookup(LS); if (!Vars.Args.empty() || !Vars.Locals.empty()) - return false; - return includeMinimalInlineScopes() || - DD->getLocalDeclsForScope(S->getScopeNode()).empty(); + return true; + if (!includeMinimalInlineScopes() && + !ImportedEntities[LS->getScopeNode()].empty()) + return true; + return false; }; for (LexicalScope *LS : Scope->getChildren()) { // If the lexical block doesn't have non-scope children, skip // its emission and put its children directly to the parent scope. - if (skipLexicalScope(LS)) - createAndAddScopeChildren(LS, ScopeDIE); - else + if (needToEmitLexicalScope(LS)) constructScopeDIE(LS, ScopeDIE); + else + createAndAddScopeChildren(LS, ScopeDIE); } return ObjectPointer; @@ -1143,10 +1133,12 @@ DIE *DwarfCompileUnit::createAndAddScopeChildren(LexicalScope *Scope, void DwarfCompileUnit::constructAbstractSubprogramScopeDIE( LexicalScope *Scope) { - auto *SP = cast<DISubprogram>(Scope->getScopeNode()); - if (getAbstractScopeDIEs().count(SP)) + DIE *&AbsDef = getAbstractSPDies()[Scope->getScopeNode()]; + if (AbsDef) return; + auto *SP = cast<DISubprogram>(Scope->getScopeNode()); + DIE *ContextDIE; DwarfCompileUnit *ContextCU = this; @@ -1169,19 +1161,14 @@ void DwarfCompileUnit::constructAbstractSubprogramScopeDIE( // Passing null as the associated node because the abstract definition // shouldn't be found by lookup. - DIE &AbsDef = ContextCU->createAndAddDIE(dwarf::DW_TAG_subprogram, - *ContextDIE, nullptr); - - // Store the DIE before creating children. - ContextCU->getAbstractScopeDIEs()[SP] = &AbsDef; - - ContextCU->applySubprogramAttributesToDefinition(SP, AbsDef); - ContextCU->addSInt(AbsDef, dwarf::DW_AT_inline, + AbsDef = &ContextCU->createAndAddDIE(dwarf::DW_TAG_subprogram, *ContextDIE, nullptr); + ContextCU->applySubprogramAttributesToDefinition(SP, *AbsDef); + ContextCU->addSInt(*AbsDef, dwarf::DW_AT_inline, DD->getDwarfVersion() <= 4 ? std::optional<dwarf::Form>() : dwarf::DW_FORM_implicit_const, dwarf::DW_INL_inlined); - if (DIE *ObjectPointer = ContextCU->createAndAddScopeChildren(Scope, AbsDef)) - ContextCU->addDIEEntry(AbsDef, dwarf::DW_AT_object_pointer, *ObjectPointer); + if (DIE *ObjectPointer = ContextCU->createAndAddScopeChildren(Scope, *AbsDef)) + ContextCU->addDIEEntry(*AbsDef, dwarf::DW_AT_object_pointer, *ObjectPointer); } bool DwarfCompileUnit::useGNUAnalogForDwarf5Feature() const { @@ -1325,20 +1312,12 @@ DIE *DwarfCompileUnit::constructImportedEntityDIE( EntityDie = getOrCreateNameSpace(NS); else if (auto *M = dyn_cast<DIModule>(Entity)) EntityDie = getOrCreateModule(M); - else if (auto *SP = dyn_cast<DISubprogram>(Entity)) { - // If there is an abstract subprogram, refer to it. Note that this assumes - // that all the abstract subprograms have been already created (which is - // correct until imported entities get emitted in DwarfDebug::endModule()). - if (auto *AbsSPDie = getAbstractScopeDIEs().lookup(SP)) - EntityDie = AbsSPDie; - else - EntityDie = getOrCreateSubprogramDIE(SP); - } else if (auto *T = dyn_cast<DIType>(Entity)) + else if (auto *SP = dyn_cast<DISubprogram>(Entity)) + EntityDie = getOrCreateSubprogramDIE(SP); + else if (auto *T = dyn_cast<DIType>(Entity)) EntityDie = getOrCreateTypeDIE(T); else if (auto *GV = dyn_cast<DIGlobalVariable>(Entity)) EntityDie = getOrCreateGlobalVariableDIE(GV, {}); - else if (auto *IE = dyn_cast<DIImportedEntity>(Entity)) - EntityDie = getOrCreateImportedEntityDIE(IE); else EntityDie = getDIE(Entity); assert(EntityDie); @@ -1369,24 +1348,9 @@ DIE *DwarfCompileUnit::constructImportedEntityDIE( return IMDie; } -DIE *DwarfCompileUnit::getOrCreateImportedEntityDIE( - const DIImportedEntity *IE) { - - // Check for pre-existence. - if (DIE *Die = getDIE(IE)) - return Die; - - DIE *ContextDIE = getOrCreateContextDIE(IE->getScope()); - assert(ContextDIE && "Empty scope for the imported entity!"); - - DIE *IMDie = constructImportedEntityDIE(IE); - ContextDIE->addChild(IMDie); - return IMDie; -} - void DwarfCompileUnit::finishSubprogramDefinition(const DISubprogram *SP) { DIE *D = getDIE(SP); - if (DIE *AbsSPDIE = getAbstractScopeDIEs().lookup(SP)) { + if (DIE *AbsSPDIE = getAbstractSPDies().lookup(SP)) { if (D) // If this subprogram has an abstract definition, reference that addDIEEntry(*D, dwarf::DW_AT_abstract_origin, *AbsSPDIE); @@ -1680,29 +1644,3 @@ void DwarfCompileUnit::createBaseTypeDIEs() { Btr.Die = &Die; } } - -DIE *DwarfCompileUnit::getLexicalBlockDIE(const DILexicalBlock *LB) { - // Assume if there is an abstract tree all the DIEs are already emitted. - bool isAbstract = getAbstractScopeDIEs().count(LB->getSubprogram()); - if (isAbstract && getAbstractScopeDIEs().count(LB)) - return getAbstractScopeDIEs()[LB]; - assert(!isAbstract && "Missed lexical block DIE in abstract tree!"); - - // Return a concrete DIE if it exists or nullptr otherwise. - return LexicalBlockDIEs.lookup(LB); -} - -DIE *DwarfCompileUnit::getOrCreateContextDIE(const DIScope *Context) { - if (isa_and_nonnull<DILocalScope>(Context)) { - if (auto *LFScope = dyn_cast<DILexicalBlockFile>(Context)) - Context = LFScope->getNonLexicalBlockFileScope(); - if (auto *LScope = dyn_cast<DILexicalBlock>(Context)) - return getLexicalBlockDIE(LScope); - - // Otherwise the context must be a DISubprogram. - auto *SPScope = cast<DISubprogram>(Context); - if (getAbstractScopeDIEs().count(SPScope)) - return getAbstractScopeDIEs()[SPScope]; - } - return DwarfUnit::getOrCreateContextDIE(Context); -} |