Skip to content

Commit a961604

Browse files
committed
Revert "[DwarfDebug] Support emitting function-local declaration for a lexical block"
This reverts commits * ee69197 (D113741), * 79d3132 (D114705) due to lldb and dexter test failures.
1 parent 729bf9b commit a961604

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+7120
-8077
lines changed

lld/test/wasm/debuginfo.test

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,9 @@ CHECK-NEXT: DW_AT_producer ("clang version 7.0.0 (trunk {{.*}})")
4444
CHECK-NEXT: DW_AT_language (DW_LANG_C99)
4545
CHECK-NEXT: DW_AT_name ("hi_foo.c")
4646

47-
CHECK: DW_TAG_subprogram
48-
CHECK-NEXT: DW_AT_low_pc
49-
CHECK-NEXT: DW_AT_high_pc
50-
CHECK-NEXT: DW_AT_frame_base
51-
CHECK-NEXT: DW_AT_name ("foo")
52-
CHECK-NEXT: DW_AT_decl_file ("{{.*}}hi_foo.c")
53-
CHECK-NEXT: DW_AT_decl_line (3)
54-
55-
CHECK: DW_TAG_formal_parameter
56-
CHECK-NEXT: DW_AT_location (DW_OP_WASM_location 0x0 0x0, DW_OP_stack_value)
57-
CHECK-NEXT: DW_AT_name ("p")
58-
CHECK-NEXT: DW_AT_decl_file ("{{.*}}hi_foo.c")
59-
CHECK-NEXT: DW_AT_decl_line (3)
60-
6147
CHECK: DW_TAG_variable
6248
CHECK-NEXT: DW_AT_name ("y")
63-
CHECK-NEXT: DW_AT_type (0x000000d4 "int[2]")
49+
CHECK-NEXT: DW_AT_type (0x000000ac "int[2]")
6450
CHECK-NEXT: DW_AT_external (true)
6551
CHECK-NEXT: DW_AT_decl_file ("{{.*}}hi_foo.c")
6652
CHECK-NEXT: DW_AT_decl_line (1)
@@ -82,9 +68,23 @@ CHECK-NEXT: DW_AT_encoding (DW_ATE_unsigned)
8268

8369
CHECK: DW_TAG_variable
8470
CHECK-NEXT: DW_AT_name ("z")
85-
CHECK-NEXT: DW_AT_type (0x000000d4 "int[2]")
71+
CHECK-NEXT: DW_AT_type (0x000000ac "int[2]")
8672
CHECK-NEXT: DW_AT_external (true)
8773
CHECK-NEXT: DW_AT_decl_file ("{{.*}}hi_foo.c")
8874
CHECK-NEXT: DW_AT_decl_line (8)
8975
CHECK-NEXT: DW_AT_location (DW_OP_addr 0xffffffff)
9076

77+
CHECK: DW_TAG_subprogram
78+
CHECK-NEXT: DW_AT_low_pc
79+
CHECK-NEXT: DW_AT_high_pc
80+
CHECK-NEXT: DW_AT_frame_base
81+
CHECK-NEXT: DW_AT_name ("foo")
82+
CHECK-NEXT: DW_AT_decl_file ("{{.*}}hi_foo.c")
83+
CHECK-NEXT: DW_AT_decl_line (3)
84+
85+
CHECK: DW_TAG_formal_parameter
86+
CHECK-NEXT: DW_AT_location (DW_OP_WASM_location 0x0 0x0, DW_OP_stack_value)
87+
CHECK-NEXT: DW_AT_name ("p")
88+
CHECK-NEXT: DW_AT_decl_file ("{{.*}}hi_foo.c")
89+
CHECK-NEXT: DW_AT_decl_line (3)
90+

llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp

Lines changed: 36 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -551,18 +551,8 @@ void DwarfCompileUnit::constructScopeDIE(LexicalScope *Scope,
551551
// Emit lexical blocks.
552552
DIE *ScopeDIE = constructLexicalScopeDIE(Scope);
553553
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-
}
565554

555+
ParentScopeDIE.addChild(ScopeDIE);
566556
createAndAddScopeChildren(Scope, *ScopeDIE);
567557
}
568558

@@ -656,7 +646,7 @@ DIE *DwarfCompileUnit::constructInlinedScopeDIE(LexicalScope *Scope) {
656646
auto *InlinedSP = getDISubprogram(DS);
657647
// Find the subprogram's DwarfCompileUnit in the SPMap in case the subprogram
658648
// was inlined from another compile unit.
659-
DIE *OriginDIE = getAbstractScopeDIEs()[InlinedSP];
649+
DIE *OriginDIE = getAbstractSPDies()[InlinedSP];
660650
assert(OriginDIE && "Unable to find original DIE for an inlined subprogram.");
661651

662652
auto ScopeDIE = DIE::get(DIEValueAllocator, dwarf::DW_TAG_inlined_subroutine);
@@ -1011,12 +1001,6 @@ DIE &DwarfCompileUnit::constructSubprogramScopeDIE(const DISubprogram *Sub,
10111001
if (Scope) {
10121002
assert(!Scope->getInlinedAt());
10131003
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-
10201004
// Collect lexical scope children first.
10211005
// ObjectPointer might be a local (non-argument) local variable if it's a
10221006
// block's synthetic this pointer.
@@ -1052,18 +1036,27 @@ DIE *DwarfCompileUnit::createAndAddScopeChildren(LexicalScope *Scope,
10521036
for (DbgVariable *DV : Locals)
10531037
ScopeDIE.addChild(constructVariableDIE(*DV, *Scope, ObjectPointer));
10541038

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+
10551045
// Emit labels.
10561046
for (DbgLabel *DL : DU->getScopeLabels().lookup(Scope))
10571047
ScopeDIE.addChild(constructLabelDIE(*DL, *Scope));
10581048

10591049
// Emit inner lexical scopes.
1060-
auto needToEmitLexicalScope = [this](LexicalScope *LS) -> bool {
1050+
auto needToEmitLexicalScope = [this](LexicalScope *LS) {
10611051
if (isa<DISubprogram>(LS->getScopeNode()))
10621052
return true;
10631053
auto Vars = DU->getScopeVariables().lookup(LS);
10641054
if (!Vars.Args.empty() || !Vars.Locals.empty())
10651055
return true;
1066-
return LocalScopesWithLocalDecls.count(LS->getScopeNode());
1056+
if (!includeMinimalInlineScopes() &&
1057+
!ImportedEntities[LS->getScopeNode()].empty())
1058+
return true;
1059+
return false;
10671060
};
10681061
for (LexicalScope *LS : Scope->getChildren()) {
10691062
// If the lexical block doesn't have non-scope children, skip
@@ -1079,10 +1072,11 @@ DIE *DwarfCompileUnit::createAndAddScopeChildren(LexicalScope *Scope,
10791072

10801073
void DwarfCompileUnit::constructAbstractSubprogramScopeDIE(
10811074
LexicalScope *Scope) {
1075+
DIE *&AbsDef = getAbstractSPDies()[Scope->getScopeNode()];
1076+
if (AbsDef)
1077+
return;
10821078

10831079
auto *SP = cast<DISubprogram>(Scope->getScopeNode());
1084-
if (auto *SPDie = getAbstractScopeDIEs().lookup(SP))
1085-
return;
10861080

10871081
DIE *ContextDIE;
10881082
DwarfCompileUnit *ContextCU = this;
@@ -1106,19 +1100,14 @@ void DwarfCompileUnit::constructAbstractSubprogramScopeDIE(
11061100

11071101
// Passing null as the associated node because the abstract definition
11081102
// 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,
11171106
DD->getDwarfVersion() <= 4 ? Optional<dwarf::Form>()
11181107
: dwarf::DW_FORM_implicit_const,
11191108
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);
11221111
}
11231112

11241113
bool DwarfCompileUnit::useGNUAnalogForDwarf5Feature() const {
@@ -1252,61 +1241,47 @@ void DwarfCompileUnit::constructCallSiteParmEntryDIEs(
12521241
}
12531242
}
12541243

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);
12591248
DIE *EntityDie;
1260-
auto *Entity = IE->getEntity();
1249+
auto *Entity = Module->getEntity();
12611250
if (auto *NS = dyn_cast<DINamespace>(Entity))
12621251
EntityDie = getOrCreateNameSpace(NS);
12631252
else if (auto *M = dyn_cast<DIModule>(Entity))
12641253
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))
12721257
EntityDie = getOrCreateTypeDIE(T);
12731258
else if (auto *GV = dyn_cast<DIGlobalVariable>(Entity))
12741259
EntityDie = getOrCreateGlobalVariableDIE(GV, {});
12751260
else
12761261
EntityDie = getDIE(Entity);
12771262
assert(EntityDie);
1278-
1279-
addSourceLine(*IMDie, IE->getLine(), IE->getFile());
1263+
addSourceLine(*IMDie, Module->getLine(), Module->getFile());
12801264
addDIEEntry(*IMDie, dwarf::DW_AT_import, *EntityDie);
1281-
StringRef Name = IE->getName();
1265+
StringRef Name = Module->getName();
12821266
if (!Name.empty())
12831267
addString(*IMDie, dwarf::DW_AT_name, Name);
12841268

12851269
// This is for imported module with renamed entities (such as variables and
12861270
// subprograms).
1287-
DINodeArray Elements = IE->getElements();
1271+
DINodeArray Elements = Module->getElements();
12881272
for (const auto *Element : Elements) {
12891273
if (!Element)
12901274
continue;
1291-
IMDie->addChild(createImportedEntityDIE(cast<DIImportedEntity>(Element)));
1275+
IMDie->addChild(
1276+
constructImportedEntityDIE(cast<DIImportedEntity>(Element)));
12921277
}
1293-
return IMDie;
1294-
}
12951278

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;
13051280
}
13061281

13071282
void DwarfCompileUnit::finishSubprogramDefinition(const DISubprogram *SP) {
13081283
DIE *D = getDIE(SP);
1309-
if (DIE *AbsSPDIE = getAbstractScopeDIEs().lookup(SP)) {
1284+
if (DIE *AbsSPDIE = getAbstractSPDies().lookup(SP)) {
13101285
if (D)
13111286
// If this subprogram has an abstract definition, reference that
13121287
addDIEEntry(*D, dwarf::DW_AT_abstract_origin, *AbsSPDIE);
@@ -1596,38 +1571,3 @@ void DwarfCompileUnit::createBaseTypeDIEs() {
15961571
Btr.Die = &Die;
15971572
}
15981573
}
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-
}

llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ class DwarfCompileUnit final : public DwarfUnit {
6262
/// The start of the unit macro info within macro section.
6363
MCSymbol *MacroLabelBegin;
6464

65+
using ImportedEntityList = SmallVector<const MDNode *, 8>;
66+
using ImportedEntityMap = DenseMap<const MDNode *, ImportedEntityList>;
67+
68+
ImportedEntityMap ImportedEntities;
69+
6570
/// GlobalNames - A map of globally visible named entities for this unit.
6671
StringMap<const DIE *> GlobalNames;
6772

@@ -75,14 +80,9 @@ class DwarfCompileUnit final : public DwarfUnit {
7580
// ranges/locs.
7681
const MCSymbol *BaseAddress = nullptr;
7782

78-
DenseMap<const DILocalScope *, DIE *> LocalScopeDIEs;
79-
DenseMap<const DILocalScope *, DIE *> AbstractLocalScopeDIEs;
83+
DenseMap<const MDNode *, DIE *> AbstractSPDies;
8084
DenseMap<const DINode *, std::unique_ptr<DbgEntity>> AbstractEntities;
8185

82-
/// LocalScopesWithLocalDecls - A list of non-empty local scopes
83-
/// (with declaraions of static locals, function-local types, or imports).
84-
SmallPtrSet<const DILocalScope *, 8> LocalScopesWithLocalDecls;
85-
8686
/// DWO ID for correlating skeleton and split units.
8787
uint64_t DWOId = 0;
8888

@@ -92,10 +92,10 @@ class DwarfCompileUnit final : public DwarfUnit {
9292

9393
bool isDwoUnit() const override;
9494

95-
DenseMap<const DILocalScope *, DIE *> &getAbstractScopeDIEs() {
95+
DenseMap<const MDNode *, DIE *> &getAbstractSPDies() {
9696
if (isDwoUnit() && !DD->shareAcrossDWOCUs())
97-
return AbstractLocalScopeDIEs;
98-
return DU->getAbstractScopeDIEs();
97+
return AbstractSPDies;
98+
return DU->getAbstractSPDies();
9999
}
100100

101101
DenseMap<const DINode *, std::unique_ptr<DbgEntity>> &getAbstractEntities() {
@@ -169,6 +169,17 @@ class DwarfCompileUnit final : public DwarfUnit {
169169

170170
unsigned getOrCreateSourceID(const DIFile *File) override;
171171

172+
void addImportedEntity(const DIImportedEntity* IE) {
173+
DIScope *Scope = IE->getScope();
174+
assert(Scope && "Invalid Scope encoding!");
175+
if (!isa<DILocalScope>(Scope))
176+
// No need to add imported enities that are not local declaration.
177+
return;
178+
179+
auto *LocalScope = cast<DILocalScope>(Scope)->getNonLexicalBlockFileScope();
180+
ImportedEntities[LocalScope].push_back(IE);
181+
}
182+
172183
/// addRange - Add an address range to the list of ranges for this unit.
173184
void addRange(RangeSpan Range);
174185

@@ -210,9 +221,6 @@ class DwarfCompileUnit final : public DwarfUnit {
210221

211222
void createBaseTypeDIEs();
212223

213-
DIE *findLocalScopeDIE(const DIScope *S);
214-
DIE *getOrCreateContextDIE(const DIScope *Ty) override;
215-
216224
/// Construct a DIE for this subprogram scope.
217225
DIE &constructSubprogramScopeDIE(const DISubprogram *Sub,
218226
LexicalScope *Scope);
@@ -251,9 +259,8 @@ class DwarfCompileUnit final : public DwarfUnit {
251259
void constructCallSiteParmEntryDIEs(DIE &CallSiteDIE,
252260
SmallVector<DbgCallSiteParam, 4> &Params);
253261

254-
/// Construct DIE for an imported entity.
255-
DIE *createImportedEntityDIE(const DIImportedEntity *IE);
256-
void createAndAddImportedEntityDIE(const DIImportedEntity *IE);
262+
/// Construct import_module DIE.
263+
DIE *constructImportedEntityDIE(const DIImportedEntity *Module);
257264

258265
void finishSubprogramDefinition(const DISubprogram *SP);
259266
void finishEntityDefinition(const DbgEntity *Entity);
@@ -350,10 +357,6 @@ class DwarfCompileUnit final : public DwarfUnit {
350357
bool hasDwarfPubSections() const;
351358

352359
void addBaseTypeRef(DIEValueList &Die, int64_t Idx);
353-
354-
void recordLocalScopeWithDecls(const DILocalScope *S) {
355-
LocalScopesWithLocalDecls.insert(S);
356-
}
357360
};
358361

359362
} // end namespace llvm

0 commit comments

Comments
 (0)