@@ -537,9 +537,8 @@ void DwarfCompileUnit::addWasmRelocBaseGlobal(DIELoc *Loc, StringRef GlobalName,
537537// and DW_AT_high_pc attributes. If there are global variables in this
538538// scope then create and insert DIEs for these variables.
539539DIE &DwarfCompileUnit::updateSubprogramScopeDIE (const DISubprogram *SP,
540- const Function &F,
541540 MCSymbol *LineTableSym) {
542- DIE *SPDie = getOrCreateSubprogramDIE (SP, &F, includeMinimalInlineScopes ());
541+ DIE *SPDie = getOrCreateSubprogramDIE (SP, includeMinimalInlineScopes ());
543542 SmallVector<RangeSpan, 2 > BB_List;
544543 // If basic block sections are on, ranges for each basic block section has
545544 // to be emitted separately.
@@ -1123,10 +1122,9 @@ sortLocalVars(SmallVectorImpl<DbgVariable *> &Input) {
11231122}
11241123
11251124DIE &DwarfCompileUnit::constructSubprogramScopeDIE (const DISubprogram *Sub,
1126- const Function &F,
11271125 LexicalScope *Scope,
11281126 MCSymbol *LineTableSym) {
1129- DIE &ScopeDIE = updateSubprogramScopeDIE (Sub, F, LineTableSym);
1127+ DIE &ScopeDIE = updateSubprogramScopeDIE (Sub, LineTableSym);
11301128
11311129 if (Scope) {
11321130 assert (!Scope->getInlinedAt ());
@@ -1200,17 +1198,32 @@ DIE *DwarfCompileUnit::createAndAddScopeChildren(LexicalScope *Scope,
12001198 return ObjectPointer;
12011199}
12021200
1203- DIE &DwarfCompileUnit::getOrCreateAbstractSubprogramDIE (
1204- const DISubprogram *SP) {
1205- if (auto *AbsDef = getAbstractScopeDIEs ().lookup (SP))
1206- return *AbsDef;
1201+ void DwarfCompileUnit::constructAbstractSubprogramScopeDIE (
1202+ LexicalScope *Scope) {
1203+ auto *SP = cast<DISubprogram>(Scope->getScopeNode ());
1204+ if (getAbstractScopeDIEs ().count (SP))
1205+ return ;
12071206
1208- auto [ContextDIE, ContextCU] = getOrCreateAbstractSubprogramContextDIE (SP);
1209- return createAbstractSubprogramDIE (SP, ContextDIE, ContextCU);
1210- }
1207+ DIE *ContextDIE;
1208+ DwarfCompileUnit *ContextCU = this ;
1209+
1210+ if (includeMinimalInlineScopes ())
1211+ ContextDIE = &getUnitDie ();
1212+ // Some of this is duplicated from DwarfUnit::getOrCreateSubprogramDIE, with
1213+ // the important distinction that the debug node is not associated with the
1214+ // DIE (since the debug node will be associated with the concrete DIE, if
1215+ // any). It could be refactored to some common utility function.
1216+ else if (auto *SPDecl = SP->getDeclaration ()) {
1217+ ContextDIE = &getUnitDie ();
1218+ getOrCreateSubprogramDIE (SPDecl);
1219+ } else {
1220+ ContextDIE = getOrCreateContextDIE (SP->getScope ());
1221+ // The scope may be shared with a subprogram that has already been
1222+ // constructed in another CU, in which case we need to construct this
1223+ // subprogram in the same CU.
1224+ ContextCU = DD->lookupCU (ContextDIE->getUnitDie ());
1225+ }
12111226
1212- DIE &DwarfCompileUnit::createAbstractSubprogramDIE (
1213- const DISubprogram *SP, DIE *ContextDIE, DwarfCompileUnit *ContextCU) {
12141227 // Passing null as the associated node because the abstract definition
12151228 // shouldn't be found by lookup.
12161229 DIE &AbsDef = ContextCU->createAndAddDIE (dwarf::DW_TAG_subprogram,
@@ -1224,45 +1237,8 @@ DIE &DwarfCompileUnit::createAbstractSubprogramDIE(
12241237 DD->getDwarfVersion () <= 4 ? std::optional<dwarf::Form>()
12251238 : dwarf::DW_FORM_implicit_const,
12261239 dwarf::DW_INL_inlined);
1227-
1228- return AbsDef;
1229- }
1230-
1231- std::pair<DIE *, DwarfCompileUnit *>
1232- DwarfCompileUnit::getOrCreateAbstractSubprogramContextDIE (
1233- const DISubprogram *SP) {
1234- bool Minimal = includeMinimalInlineScopes ();
1235- bool IgnoreScope = shouldPlaceInUnitDIE (SP, Minimal);
1236- DIE *ContextDIE = getOrCreateSubprogramContextDIE (SP, IgnoreScope);
1237-
1238- if (auto *SPDecl = SP->getDeclaration ())
1239- if (!Minimal)
1240- getOrCreateSubprogramDIE (SPDecl, nullptr );
1241-
1242- // The scope may be shared with a subprogram that has already been
1243- // constructed in another CU, in which case we need to construct this
1244- // subprogram in the same CU.
1245- auto *ContextCU = IgnoreScope ? this : DD->lookupCU (ContextDIE->getUnitDie ());
1246-
1247- return std::make_pair (ContextDIE, ContextCU);
1248- }
1249-
1250- void DwarfCompileUnit::constructAbstractSubprogramScopeDIE (
1251- LexicalScope *Scope) {
1252- auto *SP = cast<DISubprogram>(Scope->getScopeNode ());
1253-
1254- // Populate subprogram DIE only once.
1255- if (!getFinalizedAbstractSubprograms ().insert (SP).second )
1256- return ;
1257-
1258- auto [ContextDIE, ContextCU] = getOrCreateAbstractSubprogramContextDIE (SP);
1259- DIE *AbsDef = getAbstractScopeDIEs ().lookup (SP);
1260- if (!AbsDef)
1261- AbsDef = &createAbstractSubprogramDIE (SP, ContextDIE, ContextCU);
1262-
1263- if (DIE *ObjectPointer = ContextCU->createAndAddScopeChildren (Scope, *AbsDef))
1264- ContextCU->addDIEEntry (*AbsDef, dwarf::DW_AT_object_pointer,
1265- *ObjectPointer);
1240+ if (DIE *ObjectPointer = ContextCU->createAndAddScopeChildren (Scope, AbsDef))
1241+ ContextCU->addDIEEntry (AbsDef, dwarf::DW_AT_object_pointer, *ObjectPointer);
12661242}
12671243
12681244bool DwarfCompileUnit::useGNUAnalogForDwarf5Feature () const {
@@ -1317,9 +1293,9 @@ DwarfCompileUnit::getDwarf5OrGNULocationAtom(dwarf::LocationAtom Loc) const {
13171293}
13181294
13191295DIE &DwarfCompileUnit::constructCallSiteEntryDIE (
1320- DIE &ScopeDIE, const DISubprogram *CalleeSP, const Function *CalleeF ,
1321- bool IsTail, const MCSymbol *PCAddr, const MCSymbol *CallAddr,
1322- unsigned CallReg, DIType *AllocSiteTy) {
1296+ DIE &ScopeDIE, const DISubprogram *CalleeSP, bool IsTail ,
1297+ const MCSymbol *PCAddr, const MCSymbol *CallAddr, unsigned CallReg ,
1298+ DIType *AllocSiteTy) {
13231299 // Insert a call site entry DIE within ScopeDIE.
13241300 DIE &CallSiteDIE = createAndAddDIE (getDwarf5OrGNUTag (dwarf::DW_TAG_call_site),
13251301 ScopeDIE, nullptr );
@@ -1329,7 +1305,7 @@ DIE &DwarfCompileUnit::constructCallSiteEntryDIE(
13291305 addAddress (CallSiteDIE, getDwarf5OrGNUAttr (dwarf::DW_AT_call_target),
13301306 MachineLocation (CallReg));
13311307 } else if (CalleeSP) {
1332- DIE *CalleeDIE = getOrCreateSubprogramDIE (CalleeSP, CalleeF );
1308+ DIE *CalleeDIE = getOrCreateSubprogramDIE (CalleeSP);
13331309 assert (CalleeDIE && " Could not create DIE for call site entry origin" );
13341310 if (AddLinkageNamesToDeclCallOriginsForTuning (DD) &&
13351311 !CalleeSP->isDefinition () &&
@@ -1420,7 +1396,7 @@ DIE *DwarfCompileUnit::constructImportedEntityDIE(
14201396 if (auto *AbsSPDie = getAbstractScopeDIEs ().lookup (SP))
14211397 EntityDie = AbsSPDie;
14221398 else
1423- EntityDie = getOrCreateSubprogramDIE (SP, nullptr );
1399+ EntityDie = getOrCreateSubprogramDIE (SP);
14241400 } else if (auto *T = dyn_cast<DIType>(Entity))
14251401 EntityDie = getOrCreateTypeDIE (T);
14261402 else if (auto *GV = dyn_cast<DIGlobalVariable>(Entity))
@@ -1829,16 +1805,3 @@ DIE *DwarfCompileUnit::getOrCreateContextDIE(const DIScope *Context) {
18291805 }
18301806 return DwarfUnit::getOrCreateContextDIE (Context);
18311807}
1832-
1833- DIE *DwarfCompileUnit::getOrCreateSubprogramDIE (const DISubprogram *SP,
1834- const Function *F,
1835- bool Minimal) {
1836- if (!F && SP->isDefinition ()) {
1837- F = DD->getLexicalScopes ().getFunction (SP);
1838-
1839- if (!F)
1840- return &getCU ().getOrCreateAbstractSubprogramDIE (SP);
1841- }
1842-
1843- return DwarfUnit::getOrCreateSubprogramDIE (SP, F, Minimal);
1844- }
0 commit comments