@@ -537,9 +537,8 @@ void DwarfCompileUnit::addWasmRelocBaseGlobal(DIELoc *Loc, StringRef GlobalName,
537
537
// and DW_AT_high_pc attributes. If there are global variables in this
538
538
// scope then create and insert DIEs for these variables.
539
539
DIE &DwarfCompileUnit::updateSubprogramScopeDIE (const DISubprogram *SP,
540
- const Function &F,
541
540
MCSymbol *LineTableSym) {
542
- DIE *SPDie = getOrCreateSubprogramDIE (SP, &F, includeMinimalInlineScopes ());
541
+ DIE *SPDie = getOrCreateSubprogramDIE (SP, includeMinimalInlineScopes ());
543
542
SmallVector<RangeSpan, 2 > BB_List;
544
543
// If basic block sections are on, ranges for each basic block section has
545
544
// to be emitted separately.
@@ -1123,10 +1122,9 @@ sortLocalVars(SmallVectorImpl<DbgVariable *> &Input) {
1123
1122
}
1124
1123
1125
1124
DIE &DwarfCompileUnit::constructSubprogramScopeDIE (const DISubprogram *Sub,
1126
- const Function &F,
1127
1125
LexicalScope *Scope,
1128
1126
MCSymbol *LineTableSym) {
1129
- DIE &ScopeDIE = updateSubprogramScopeDIE (Sub, F, LineTableSym);
1127
+ DIE &ScopeDIE = updateSubprogramScopeDIE (Sub, LineTableSym);
1130
1128
1131
1129
if (Scope) {
1132
1130
assert (!Scope->getInlinedAt ());
@@ -1200,17 +1198,32 @@ DIE *DwarfCompileUnit::createAndAddScopeChildren(LexicalScope *Scope,
1200
1198
return ObjectPointer;
1201
1199
}
1202
1200
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 ;
1207
1206
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
+ }
1211
1226
1212
- DIE &DwarfCompileUnit::createAbstractSubprogramDIE (
1213
- const DISubprogram *SP, DIE *ContextDIE, DwarfCompileUnit *ContextCU) {
1214
1227
// Passing null as the associated node because the abstract definition
1215
1228
// shouldn't be found by lookup.
1216
1229
DIE &AbsDef = ContextCU->createAndAddDIE (dwarf::DW_TAG_subprogram,
@@ -1224,45 +1237,8 @@ DIE &DwarfCompileUnit::createAbstractSubprogramDIE(
1224
1237
DD->getDwarfVersion () <= 4 ? std::optional<dwarf::Form>()
1225
1238
: dwarf::DW_FORM_implicit_const,
1226
1239
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);
1266
1242
}
1267
1243
1268
1244
bool DwarfCompileUnit::useGNUAnalogForDwarf5Feature () const {
@@ -1317,9 +1293,9 @@ DwarfCompileUnit::getDwarf5OrGNULocationAtom(dwarf::LocationAtom Loc) const {
1317
1293
}
1318
1294
1319
1295
DIE &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) {
1323
1299
// Insert a call site entry DIE within ScopeDIE.
1324
1300
DIE &CallSiteDIE = createAndAddDIE (getDwarf5OrGNUTag (dwarf::DW_TAG_call_site),
1325
1301
ScopeDIE, nullptr );
@@ -1329,7 +1305,7 @@ DIE &DwarfCompileUnit::constructCallSiteEntryDIE(
1329
1305
addAddress (CallSiteDIE, getDwarf5OrGNUAttr (dwarf::DW_AT_call_target),
1330
1306
MachineLocation (CallReg));
1331
1307
} else if (CalleeSP) {
1332
- DIE *CalleeDIE = getOrCreateSubprogramDIE (CalleeSP, CalleeF );
1308
+ DIE *CalleeDIE = getOrCreateSubprogramDIE (CalleeSP);
1333
1309
assert (CalleeDIE && " Could not create DIE for call site entry origin" );
1334
1310
if (AddLinkageNamesToDeclCallOriginsForTuning (DD) &&
1335
1311
!CalleeSP->isDefinition () &&
@@ -1420,7 +1396,7 @@ DIE *DwarfCompileUnit::constructImportedEntityDIE(
1420
1396
if (auto *AbsSPDie = getAbstractScopeDIEs ().lookup (SP))
1421
1397
EntityDie = AbsSPDie;
1422
1398
else
1423
- EntityDie = getOrCreateSubprogramDIE (SP, nullptr );
1399
+ EntityDie = getOrCreateSubprogramDIE (SP);
1424
1400
} else if (auto *T = dyn_cast<DIType>(Entity))
1425
1401
EntityDie = getOrCreateTypeDIE (T);
1426
1402
else if (auto *GV = dyn_cast<DIGlobalVariable>(Entity))
@@ -1829,16 +1805,3 @@ DIE *DwarfCompileUnit::getOrCreateContextDIE(const DIScope *Context) {
1829
1805
}
1830
1806
return DwarfUnit::getOrCreateContextDIE (Context);
1831
1807
}
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