Skip to content

Commit a43cae4

Browse files
author
git apple-llvm automerger
committed
Merge commit '310811af6de8' from llvm.org/main into next
2 parents 5ace7ab + 310811a commit a43cae4

20 files changed

+84
-451
lines changed

llvm/include/llvm/CodeGen/DebugHandlerBase.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ class DebugHandlerBase : public AsmPrinterHandler {
145145
static bool isUnsignedDIType(const DIType *Ty);
146146

147147
const InstructionOrdering &getInstOrdering() const { return InstOrdering; }
148-
149-
const LexicalScopes &getLexicalScopes() const { return LScopes; }
150148
};
151149

152150
} // namespace llvm

llvm/include/llvm/CodeGen/LexicalScopes.h

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,12 @@ class LexicalScopes {
141141
public:
142142
LexicalScopes() = default;
143143

144-
/// Scan module to build subprogram-to-function map.
145-
LLVM_ABI void initialize(const Module &);
146-
147144
/// Scan machine function and constuct lexical scope nest, resets
148145
/// the instance if necessary.
149-
LLVM_ABI void scanFunction(const MachineFunction &);
150-
151-
/// Reset the instance so that it's prepared for another module.
152-
LLVM_ABI void resetModule();
146+
LLVM_ABI void initialize(const MachineFunction &);
153147

154-
/// Reset the instance so that it's prepared for another function.
155-
LLVM_ABI void resetFunction();
148+
/// Release memory.
149+
LLVM_ABI void reset();
156150

157151
/// Return true if there is any lexical scope information available.
158152
bool empty() { return CurrentFnLexicalScope == nullptr; }
@@ -202,11 +196,6 @@ class LexicalScopes {
202196
/// Find or create an abstract lexical scope.
203197
LLVM_ABI LexicalScope *getOrCreateAbstractScope(const DILocalScope *Scope);
204198

205-
/// Get function to which the given subprogram is attached, if exists.
206-
const Function *getFunction(const DISubprogram *SP) const {
207-
return FunctionMap.lookup(SP);
208-
}
209-
210199
private:
211200
/// Find lexical scope for the given Scope/IA. If not available
212201
/// then create new lexical scope.
@@ -236,9 +225,6 @@ class LexicalScopes {
236225

237226
const MachineFunction *MF = nullptr;
238227

239-
/// Mapping between DISubprograms and IR functions.
240-
DenseMap<const DISubprogram *, const Function *> FunctionMap;
241-
242228
/// Tracks the scopes in the current function.
243229
// Use an unordered_map to ensure value pointer validity over insertion.
244230
std::unordered_map<const DILocalScope *, LexicalScope> LexicalScopeMap;

llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ DebugHandlerBase::~DebugHandlerBase() = default;
105105
void DebugHandlerBase::beginModule(Module *M) {
106106
if (M->debug_compile_units().empty())
107107
Asm = nullptr;
108-
else
109-
LScopes.initialize(*M);
110108
}
111109

112110
// Each LexicalScope has first instruction and last instruction to mark
@@ -275,7 +273,7 @@ void DebugHandlerBase::beginFunction(const MachineFunction *MF) {
275273

276274
// Grab the lexical scopes for the function, if we don't have any of those
277275
// then we're not going to be able to do anything.
278-
LScopes.scanFunction(*MF);
276+
LScopes.initialize(*MF);
279277
if (LScopes.empty()) {
280278
beginFunctionImpl(MF);
281279
return;

llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp

Lines changed: 33 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
539539
DIE &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

11251124
DIE &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

12681244
bool DwarfCompileUnit::useGNUAnalogForDwarf5Feature() const {
@@ -1317,9 +1293,9 @@ DwarfCompileUnit::getDwarf5OrGNULocationAtom(dwarf::LocationAtom Loc) const {
13171293
}
13181294

13191295
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) {
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-
}

llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ class DwarfCompileUnit final : public DwarfUnit {
8181

8282
// List of abstract local scopes (either DISubprogram or DILexicalBlock).
8383
DenseMap<const DILocalScope *, DIE *> AbstractLocalScopeDIEs;
84-
SmallPtrSet<const DISubprogram *, 8> FinalizedAbstractSubprograms;
8584

8685
// List of inlined lexical block scopes that belong to subprograms within this
8786
// CU.
@@ -138,28 +137,12 @@ class DwarfCompileUnit final : public DwarfUnit {
138137
return DU->getAbstractEntities();
139138
}
140139

141-
auto &getFinalizedAbstractSubprograms() {
142-
if (isDwoUnit() && !DD->shareAcrossDWOCUs())
143-
return FinalizedAbstractSubprograms;
144-
return DU->getFinalizedAbstractSubprograms();
145-
}
146-
147140
void finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) override;
148141

149142
/// Add info for Wasm-global-based relocation.
150143
void addWasmRelocBaseGlobal(DIELoc *Loc, StringRef GlobalName,
151144
uint64_t GlobalIndex);
152145

153-
/// Create context DIE for abstract subprogram.
154-
/// \returns The context DIE and the compile unit where abstract
155-
/// DIE should be constructed.
156-
std::pair<DIE *, DwarfCompileUnit *>
157-
getOrCreateAbstractSubprogramContextDIE(const DISubprogram *SP);
158-
159-
/// Create new DIE for abstract subprogram.
160-
DIE &createAbstractSubprogramDIE(const DISubprogram *SP, DIE *ContextDIE,
161-
DwarfCompileUnit *ContextCU);
162-
163146
public:
164147
DwarfCompileUnit(unsigned UID, const DICompileUnit *Node, AsmPrinter *A,
165148
DwarfDebug *DW, DwarfFile *DWU,
@@ -233,8 +216,7 @@ class DwarfCompileUnit final : public DwarfUnit {
233216
/// DW_AT_low_pc, DW_AT_high_pc and DW_AT_LLVM_stmt_sequence attributes.
234217
/// If there are global variables in this scope then create and insert DIEs
235218
/// for these variables.
236-
DIE &updateSubprogramScopeDIE(const DISubprogram *SP, const Function &F,
237-
MCSymbol *LineTableSym);
219+
DIE &updateSubprogramScopeDIE(const DISubprogram *SP, MCSymbol *LineTableSym);
238220

239221
void constructScopeDIE(LexicalScope *Scope, DIE &ParentScopeDIE);
240222

@@ -277,18 +259,12 @@ class DwarfCompileUnit final : public DwarfUnit {
277259
/// This instance of 'getOrCreateContextDIE()' can handle DILocalScope.
278260
DIE *getOrCreateContextDIE(const DIScope *Ty) override;
279261

280-
DIE *getOrCreateSubprogramDIE(const DISubprogram *SP, const Function *F,
281-
bool Minimal = false) override;
282-
283262
/// Construct a DIE for this subprogram scope.
284-
DIE &constructSubprogramScopeDIE(const DISubprogram *Sub, const Function &F,
285-
LexicalScope *Scope, MCSymbol *LineTableSym);
263+
DIE &constructSubprogramScopeDIE(const DISubprogram *Sub, LexicalScope *Scope,
264+
MCSymbol *LineTableSym);
286265

287266
DIE *createAndAddScopeChildren(LexicalScope *Scope, DIE &ScopeDIE);
288267

289-
/// Create an abstract subprogram DIE, that should later be populated
290-
/// by \ref constructAbstractSubprogramScopeDIE.
291-
DIE &getOrCreateAbstractSubprogramDIE(const DISubprogram *SP);
292268
void constructAbstractSubprogramScopeDIE(LexicalScope *Scope);
293269

294270
/// Whether to use the GNU analog for a DWARF5 tag, attribute, or location
@@ -305,15 +281,14 @@ class DwarfCompileUnit final : public DwarfUnit {
305281
dwarf::LocationAtom getDwarf5OrGNULocationAtom(dwarf::LocationAtom Loc) const;
306282

307283
/// Construct a call site entry DIE describing a call within \p Scope to a
308-
/// callee described by \p CalleeSP and \p CalleeF.
284+
/// callee described by \p CalleeSP.
309285
/// \p IsTail specifies whether the call is a tail call.
310286
/// \p PCAddr points to the PC value after the call instruction.
311287
/// \p CallAddr points to the PC value at the call instruction (or is null).
312288
/// \p CallReg is a register location for an indirect call. For direct calls
313289
/// the \p CallReg is set to 0.
314290
DIE &constructCallSiteEntryDIE(DIE &ScopeDIE, const DISubprogram *CalleeSP,
315-
const Function *CalleeF, bool IsTail,
316-
const MCSymbol *PCAddr,
291+
bool IsTail, const MCSymbol *PCAddr,
317292
const MCSymbol *CallAddr, unsigned CallReg,
318293
DIType *AllocSiteTy);
319294
/// Construct call site parameter DIEs for the \p CallSiteDIE. The \p Params

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,9 +1005,8 @@ void DwarfDebug::constructCallSiteEntryDIEs(const DISubprogram &SP,
10051005
->getName(CallReg)))
10061006
<< (IsTail ? " [IsTail]" : "") << "\n");
10071007

1008-
DIE &CallSiteDIE =
1009-
CU.constructCallSiteEntryDIE(ScopeDIE, CalleeSP, CalleeDecl, IsTail,
1010-
PCAddr, CallAddr, CallReg, AllocSiteTy);
1008+
DIE &CallSiteDIE = CU.constructCallSiteEntryDIE(
1009+
ScopeDIE, CalleeSP, IsTail, PCAddr, CallAddr, CallReg, AllocSiteTy);
10111010

10121011
// Optionally emit call-site-param debug info.
10131012
if (emitDebugEntryValues()) {
@@ -2731,8 +2730,7 @@ void DwarfDebug::skippedNonDebugFunction() {
27312730

27322731
// Gather and emit post-function debug information.
27332732
void DwarfDebug::endFunctionImpl(const MachineFunction *MF) {
2734-
const Function &F = MF->getFunction();
2735-
const DISubprogram *SP = F.getSubprogram();
2733+
const DISubprogram *SP = MF->getFunction().getSubprogram();
27362734

27372735
assert(CurFn == MF &&
27382736
"endFunction should be called with the same function as beginFunction");
@@ -2801,12 +2799,11 @@ void DwarfDebug::endFunctionImpl(const MachineFunction *MF) {
28012799

28022800
ProcessedSPNodes.insert(SP);
28032801
DIE &ScopeDIE =
2804-
TheCU.constructSubprogramScopeDIE(SP, F, FnScope, FunctionLineTableLabel);
2802+
TheCU.constructSubprogramScopeDIE(SP, FnScope, FunctionLineTableLabel);
28052803
if (auto *SkelCU = TheCU.getSkeleton())
28062804
if (!LScopes.getAbstractScopesList().empty() &&
28072805
TheCU.getCUNode()->getSplitDebugInlining())
2808-
SkelCU->constructSubprogramScopeDIE(SP, F, FnScope,
2809-
FunctionLineTableLabel);
2806+
SkelCU->constructSubprogramScopeDIE(SP, FnScope, FunctionLineTableLabel);
28102807

28112808
FunctionLineTableLabel = nullptr;
28122809

llvm/lib/CodeGen/AsmPrinter/DwarfFile.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include "DwarfStringPool.h"
1313
#include "llvm/ADT/DenseMap.h"
14-
#include "llvm/ADT/SmallPtrSet.h"
1514
#include "llvm/ADT/SmallVector.h"
1615
#include "llvm/ADT/StringRef.h"
1716
#include "llvm/CodeGen/DIE.h"
@@ -28,7 +27,6 @@ class DbgVariable;
2827
class DbgLabel;
2928
class DINode;
3029
class DILocalScope;
31-
class DISubprogram;
3230
class DwarfCompileUnit;
3331
class DwarfUnit;
3432
class LexicalScope;
@@ -96,9 +94,6 @@ class DwarfFile {
9694
// Collection of abstract subprogram DIEs.
9795
DenseMap<const DILocalScope *, DIE *> AbstractLocalScopeDIEs;
9896
DenseMap<const DINode *, std::unique_ptr<DbgEntity>> AbstractEntities;
99-
/// Keeps track of abstract subprograms to populate them only once.
100-
// FIXME: merge creation and population of abstract scopes.
101-
SmallPtrSet<const DISubprogram *, 8> FinalizedAbstractSubprograms;
10297

10398
/// Maps MDNodes for type system with the corresponding DIEs. These DIEs can
10499
/// be shared across CUs, that is why we keep the map here instead
@@ -179,10 +174,6 @@ class DwarfFile {
179174
return AbstractEntities;
180175
}
181176

182-
auto &getFinalizedAbstractSubprograms() {
183-
return FinalizedAbstractSubprograms;
184-
}
185-
186177
void insertDIE(const MDNode *TypeMD, DIE *Die) {
187178
DITypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
188179
}

0 commit comments

Comments
 (0)