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