@@ -551,18 +551,8 @@ void DwarfCompileUnit::constructScopeDIE(LexicalScope *Scope,
551
551
// Emit lexical blocks.
552
552
DIE *ScopeDIE = constructLexicalScopeDIE (Scope);
553
553
assert (ScopeDIE && " Scope DIE should not be null." );
554
- ParentScopeDIE.addChild (ScopeDIE);
555
-
556
- // Track abstract and concrete lexical block scopes.
557
- if (Scope->isAbstractScope ()) {
558
- assert (!getAbstractScopeDIEs ().count (DS) &&
559
- " Abstract DIE for this scope exists!" );
560
- getAbstractScopeDIEs ()[DS] = ScopeDIE;
561
- } else if (!Scope->getInlinedAt ()) {
562
- assert (!LocalScopeDIEs.count (DS) && " Concrete DIE for this scope exists!" );
563
- LocalScopeDIEs[DS] = ScopeDIE;
564
- }
565
554
555
+ ParentScopeDIE.addChild (ScopeDIE);
566
556
createAndAddScopeChildren (Scope, *ScopeDIE);
567
557
}
568
558
@@ -656,7 +646,7 @@ DIE *DwarfCompileUnit::constructInlinedScopeDIE(LexicalScope *Scope) {
656
646
auto *InlinedSP = getDISubprogram (DS);
657
647
// Find the subprogram's DwarfCompileUnit in the SPMap in case the subprogram
658
648
// was inlined from another compile unit.
659
- DIE *OriginDIE = getAbstractScopeDIEs ()[InlinedSP];
649
+ DIE *OriginDIE = getAbstractSPDies ()[InlinedSP];
660
650
assert (OriginDIE && " Unable to find original DIE for an inlined subprogram." );
661
651
662
652
auto ScopeDIE = DIE::get (DIEValueAllocator, dwarf::DW_TAG_inlined_subroutine);
@@ -1011,12 +1001,6 @@ DIE &DwarfCompileUnit::constructSubprogramScopeDIE(const DISubprogram *Sub,
1011
1001
if (Scope) {
1012
1002
assert (!Scope->getInlinedAt ());
1013
1003
assert (!Scope->isAbstractScope ());
1014
-
1015
- // Remember the subrogram before creating child entities.
1016
- assert (!LocalScopeDIEs.count (Sub) &&
1017
- " Concrete DIE for the subprogram exists!" );
1018
- LocalScopeDIEs[Sub] = &ScopeDIE;
1019
-
1020
1004
// Collect lexical scope children first.
1021
1005
// ObjectPointer might be a local (non-argument) local variable if it's a
1022
1006
// block's synthetic this pointer.
@@ -1052,18 +1036,27 @@ DIE *DwarfCompileUnit::createAndAddScopeChildren(LexicalScope *Scope,
1052
1036
for (DbgVariable *DV : Locals)
1053
1037
ScopeDIE.addChild (constructVariableDIE (*DV, *Scope, ObjectPointer));
1054
1038
1039
+ // Emit imported entities (skipped in gmlt-like data).
1040
+ if (!includeMinimalInlineScopes ()) {
1041
+ for (const auto *IE : ImportedEntities[Scope->getScopeNode ()])
1042
+ ScopeDIE.addChild (constructImportedEntityDIE (cast<DIImportedEntity>(IE)));
1043
+ }
1044
+
1055
1045
// Emit labels.
1056
1046
for (DbgLabel *DL : DU->getScopeLabels ().lookup (Scope))
1057
1047
ScopeDIE.addChild (constructLabelDIE (*DL, *Scope));
1058
1048
1059
1049
// Emit inner lexical scopes.
1060
- auto needToEmitLexicalScope = [this ](LexicalScope *LS) -> bool {
1050
+ auto needToEmitLexicalScope = [this ](LexicalScope *LS) {
1061
1051
if (isa<DISubprogram>(LS->getScopeNode ()))
1062
1052
return true ;
1063
1053
auto Vars = DU->getScopeVariables ().lookup (LS);
1064
1054
if (!Vars.Args .empty () || !Vars.Locals .empty ())
1065
1055
return true ;
1066
- return LocalScopesWithLocalDecls.count (LS->getScopeNode ());
1056
+ if (!includeMinimalInlineScopes () &&
1057
+ !ImportedEntities[LS->getScopeNode ()].empty ())
1058
+ return true ;
1059
+ return false ;
1067
1060
};
1068
1061
for (LexicalScope *LS : Scope->getChildren ()) {
1069
1062
// If the lexical block doesn't have non-scope children, skip
@@ -1079,10 +1072,11 @@ DIE *DwarfCompileUnit::createAndAddScopeChildren(LexicalScope *Scope,
1079
1072
1080
1073
void DwarfCompileUnit::constructAbstractSubprogramScopeDIE (
1081
1074
LexicalScope *Scope) {
1075
+ DIE *&AbsDef = getAbstractSPDies ()[Scope->getScopeNode ()];
1076
+ if (AbsDef)
1077
+ return ;
1082
1078
1083
1079
auto *SP = cast<DISubprogram>(Scope->getScopeNode ());
1084
- if (auto *SPDie = getAbstractScopeDIEs ().lookup (SP))
1085
- return ;
1086
1080
1087
1081
DIE *ContextDIE;
1088
1082
DwarfCompileUnit *ContextCU = this ;
@@ -1106,19 +1100,14 @@ void DwarfCompileUnit::constructAbstractSubprogramScopeDIE(
1106
1100
1107
1101
// Passing null as the associated node because the abstract definition
1108
1102
// shouldn't be found by lookup.
1109
- DIE &AbsDef = ContextCU->createAndAddDIE (dwarf::DW_TAG_subprogram,
1110
- *ContextDIE, nullptr );
1111
-
1112
- // Store the DIE before creating children.
1113
- getAbstractScopeDIEs ()[SP] = &AbsDef;
1114
-
1115
- ContextCU->applySubprogramAttributesToDefinition (SP, AbsDef);
1116
- ContextCU->addSInt (AbsDef, dwarf::DW_AT_inline,
1103
+ AbsDef = &ContextCU->createAndAddDIE (dwarf::DW_TAG_subprogram, *ContextDIE, nullptr );
1104
+ ContextCU->applySubprogramAttributesToDefinition (SP, *AbsDef);
1105
+ ContextCU->addSInt (*AbsDef, dwarf::DW_AT_inline,
1117
1106
DD->getDwarfVersion () <= 4 ? Optional<dwarf::Form>()
1118
1107
: dwarf::DW_FORM_implicit_const,
1119
1108
dwarf::DW_INL_inlined);
1120
- if (DIE *ObjectPointer = ContextCU->createAndAddScopeChildren (Scope, AbsDef))
1121
- ContextCU->addDIEEntry (AbsDef, dwarf::DW_AT_object_pointer, *ObjectPointer);
1109
+ if (DIE *ObjectPointer = ContextCU->createAndAddScopeChildren (Scope, * AbsDef))
1110
+ ContextCU->addDIEEntry (* AbsDef, dwarf::DW_AT_object_pointer, *ObjectPointer);
1122
1111
}
1123
1112
1124
1113
bool DwarfCompileUnit::useGNUAnalogForDwarf5Feature () const {
@@ -1252,61 +1241,47 @@ void DwarfCompileUnit::constructCallSiteParmEntryDIEs(
1252
1241
}
1253
1242
}
1254
1243
1255
- DIE *DwarfCompileUnit::createImportedEntityDIE ( const DIImportedEntity *IE) {
1256
- DIE *IMDie = DIE::get (DIEValueAllocator, (dwarf::Tag)IE-> getTag ());
1257
- insertDIE (IE, IMDie );
1258
-
1244
+ DIE *DwarfCompileUnit::constructImportedEntityDIE (
1245
+ const DIImportedEntity *Module) {
1246
+ DIE *IMDie = DIE::get (DIEValueAllocator, (dwarf::Tag)Module-> getTag () );
1247
+ insertDIE (Module, IMDie);
1259
1248
DIE *EntityDie;
1260
- auto *Entity = IE ->getEntity ();
1249
+ auto *Entity = Module ->getEntity ();
1261
1250
if (auto *NS = dyn_cast<DINamespace>(Entity))
1262
1251
EntityDie = getOrCreateNameSpace (NS);
1263
1252
else if (auto *M = dyn_cast<DIModule>(Entity))
1264
1253
EntityDie = getOrCreateModule (M);
1265
- else if (auto *SP = dyn_cast<DISubprogram>(Entity)) {
1266
- // If we have abstract subprogram created, refer it.
1267
- if (auto *AbsSPDie = getAbstractScopeDIEs ().lookup (SP))
1268
- EntityDie = AbsSPDie;
1269
- else
1270
- EntityDie = getOrCreateSubprogramDIE (SP);
1271
- } else if (auto *T = dyn_cast<DIType>(Entity))
1254
+ else if (auto *SP = dyn_cast<DISubprogram>(Entity))
1255
+ EntityDie = getOrCreateSubprogramDIE (SP);
1256
+ else if (auto *T = dyn_cast<DIType>(Entity))
1272
1257
EntityDie = getOrCreateTypeDIE (T);
1273
1258
else if (auto *GV = dyn_cast<DIGlobalVariable>(Entity))
1274
1259
EntityDie = getOrCreateGlobalVariableDIE (GV, {});
1275
1260
else
1276
1261
EntityDie = getDIE (Entity);
1277
1262
assert (EntityDie);
1278
-
1279
- addSourceLine (*IMDie, IE->getLine (), IE->getFile ());
1263
+ addSourceLine (*IMDie, Module->getLine (), Module->getFile ());
1280
1264
addDIEEntry (*IMDie, dwarf::DW_AT_import, *EntityDie);
1281
- StringRef Name = IE ->getName ();
1265
+ StringRef Name = Module ->getName ();
1282
1266
if (!Name.empty ())
1283
1267
addString (*IMDie, dwarf::DW_AT_name, Name);
1284
1268
1285
1269
// This is for imported module with renamed entities (such as variables and
1286
1270
// subprograms).
1287
- DINodeArray Elements = IE ->getElements ();
1271
+ DINodeArray Elements = Module ->getElements ();
1288
1272
for (const auto *Element : Elements) {
1289
1273
if (!Element)
1290
1274
continue ;
1291
- IMDie->addChild (createImportedEntityDIE (cast<DIImportedEntity>(Element)));
1275
+ IMDie->addChild (
1276
+ constructImportedEntityDIE (cast<DIImportedEntity>(Element)));
1292
1277
}
1293
- return IMDie;
1294
- }
1295
1278
1296
- void DwarfCompileUnit::createAndAddImportedEntityDIE (
1297
- const DIImportedEntity *IE) {
1298
- DIE *ContextDIE = getOrCreateContextDIE (IE->getScope ());
1299
- assert (ContextDIE &&
1300
- " Could not get or create scope for the imported entity!" );
1301
- if (!ContextDIE)
1302
- return ;
1303
-
1304
- ContextDIE->addChild (createImportedEntityDIE (IE));
1279
+ return IMDie;
1305
1280
}
1306
1281
1307
1282
void DwarfCompileUnit::finishSubprogramDefinition (const DISubprogram *SP) {
1308
1283
DIE *D = getDIE (SP);
1309
- if (DIE *AbsSPDIE = getAbstractScopeDIEs ().lookup (SP)) {
1284
+ if (DIE *AbsSPDIE = getAbstractSPDies ().lookup (SP)) {
1310
1285
if (D)
1311
1286
// If this subprogram has an abstract definition, reference that
1312
1287
addDIEEntry (*D, dwarf::DW_AT_abstract_origin, *AbsSPDIE);
@@ -1596,38 +1571,3 @@ void DwarfCompileUnit::createBaseTypeDIEs() {
1596
1571
Btr.Die = &Die;
1597
1572
}
1598
1573
}
1599
-
1600
- static DIE *
1601
- findLocalScopeDIE (const DILocalScope *LS,
1602
- DenseMap<const DILocalScope *, DIE *> &ScopeDIEs) {
1603
- DIE *ScopeDIE = ScopeDIEs.lookup (LS);
1604
- if (isa<DISubprogram>(LS) && !ScopeDIE)
1605
- return nullptr ;
1606
- if (!ScopeDIE)
1607
- return findLocalScopeDIE (cast<DILocalScope>(LS->getScope ()), ScopeDIEs);
1608
- return ScopeDIE;
1609
- }
1610
-
1611
- DIE *DwarfCompileUnit::findLocalScopeDIE (const DIScope *S) {
1612
- auto *LScope = dyn_cast_or_null<DILocalScope>(S);
1613
- if (!LScope)
1614
- return nullptr ;
1615
-
1616
- // Check if we have an abstract tree.
1617
- if (getAbstractScopeDIEs ().count (LScope->getSubprogram ()))
1618
- return ::findLocalScopeDIE (LScope, getAbstractScopeDIEs ());
1619
-
1620
- return ::findLocalScopeDIE (LScope, LocalScopeDIEs);
1621
- }
1622
-
1623
- DIE *DwarfCompileUnit::getOrCreateContextDIE (const DIScope *Context) {
1624
- if (auto *LScope = dyn_cast_or_null<DILocalScope>(Context)) {
1625
- if (DIE *ScopeDIE = findLocalScopeDIE (LScope))
1626
- return ScopeDIE;
1627
-
1628
- // If nothing was found, fall back to DISubprogram and let
1629
- // DwarfUnit::getOrCreateContextDIE() create a new DIE for it.
1630
- Context = LScope->getSubprogram ();
1631
- }
1632
- return DwarfUnit::getOrCreateContextDIE (Context);
1633
- }
0 commit comments