Skip to content

Commit 9d8003d

Browse files
author
Alex B
committed
Reimplement with better encapsulation
1 parent ab07e40 commit 9d8003d

File tree

7 files changed

+51
-67
lines changed

7 files changed

+51
-67
lines changed

llvm/include/llvm/MC/MCStreamer.h

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,6 @@ class MCStreamer {
251251
/// discussion for future inclusion.
252252
bool AllowAutoPadding = false;
253253

254-
// Flag specifying weather functions will have an offset into the line table
255-
// where the line data for that function starts
256-
bool GenerateFuncLineTableOffsets = false;
257-
258-
// Symbol that tracks the stream symbol for first line of the current function
259-
// being generated. This symbol can be used to reference where the line
260-
// entries for the function start in the generated line table.
261-
MCSymbol *CurrentFuncFirstLineStreamSym;
262-
263254
protected:
264255
MCFragment *CurFrag = nullptr;
265256

@@ -322,23 +313,7 @@ class MCStreamer {
322313
void setAllowAutoPadding(bool v) { AllowAutoPadding = v; }
323314
bool getAllowAutoPadding() const { return AllowAutoPadding; }
324315

325-
void setGenerateFuncLineTableOffsets(bool v) {
326-
GenerateFuncLineTableOffsets = v;
327-
}
328-
bool getGenerateFuncLineTableOffsets() const {
329-
return GenerateFuncLineTableOffsets;
330-
}
331-
332-
// Use the below functions to track the symbol that points to the current
333-
// function's line info in the output stream.
334-
void beginFunction() { CurrentFuncFirstLineStreamSym = nullptr; }
335-
void emittedLineStreamSym(MCSymbol *StreamSym) {
336-
if (!CurrentFuncFirstLineStreamSym)
337-
CurrentFuncFirstLineStreamSym = StreamSym;
338-
}
339-
MCSymbol *getCurrentFuncFirstLineStreamSym() {
340-
return CurrentFuncFirstLineStreamSym;
341-
}
316+
MCSymbol *emitLineTableLabel();
342317

343318
/// When emitting an object file, create and emit a real label. When emitting
344319
/// textual assembly, this should do nothing to avoid polluting our output.

llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ cl::opt<cl::boolOrDefault> AddLinkageNamesToDeclCallOrigins(
4949
"referenced by DW_AT_call_origin attributes. Enabled by default "
5050
"for -gsce debugger tuning."));
5151

52+
static cl::opt<bool> EmitFuncLineTableOffsetsOption(
53+
"emit-func-debug-line-table-offsets", cl::Hidden,
54+
cl::desc("Include line table offset in function's debug info and emit end "
55+
"sequence after each function's line data."),
56+
cl::init(false));
57+
5258
static bool AddLinkageNamesToDeclCallOriginsForTuning(const DwarfDebug *DD) {
5359
bool EnabledByDefault = DD->tuneForSCE();
5460
if (EnabledByDefault)
@@ -511,7 +517,8 @@ void DwarfCompileUnit::addWasmRelocBaseGlobal(DIELoc *Loc, StringRef GlobalName,
511517
// Find DIE for the given subprogram and attach appropriate DW_AT_low_pc
512518
// and DW_AT_high_pc attributes. If there are global variables in this
513519
// scope then create and insert DIEs for these variables.
514-
DIE &DwarfCompileUnit::updateSubprogramScopeDIE(const DISubprogram *SP) {
520+
DIE &DwarfCompileUnit::updateSubprogramScopeDIE(const DISubprogram *SP,
521+
MCSymbol *LineTableSym) {
515522
DIE *SPDie = getOrCreateSubprogramDIE(SP, includeMinimalInlineScopes());
516523
SmallVector<RangeSpan, 2> BB_List;
517524
// If basic block sections are on, ranges for each basic block section has
@@ -526,11 +533,9 @@ DIE &DwarfCompileUnit::updateSubprogramScopeDIE(const DISubprogram *SP) {
526533
*DD->getCurrentFunction()))
527534
addFlag(*SPDie, dwarf::DW_AT_APPLE_omit_frame_ptr);
528535

529-
if (Asm->OutStreamer->getGenerateFuncLineTableOffsets() &&
530-
Asm->OutStreamer->getCurrentFuncFirstLineStreamSym()) {
536+
if (emitFuncLineTableOffsets() && LineTableSym) {
531537
addSectionLabel(
532-
*SPDie, dwarf::DW_AT_LLVM_stmt_sequence,
533-
Asm->OutStreamer->getCurrentFuncFirstLineStreamSym(),
538+
*SPDie, dwarf::DW_AT_LLVM_stmt_sequence, LineTableSym,
534539
Asm->getObjFileLowering().getDwarfLineSection()->getBeginSymbol());
535540
}
536541

@@ -1104,8 +1109,9 @@ sortLocalVars(SmallVectorImpl<DbgVariable *> &Input) {
11041109
}
11051110

11061111
DIE &DwarfCompileUnit::constructSubprogramScopeDIE(const DISubprogram *Sub,
1107-
LexicalScope *Scope) {
1108-
DIE &ScopeDIE = updateSubprogramScopeDIE(Sub);
1112+
LexicalScope *Scope,
1113+
MCSymbol *LineTableSym) {
1114+
DIE &ScopeDIE = updateSubprogramScopeDIE(Sub, LineTableSym);
11091115

11101116
if (Scope) {
11111117
assert(!Scope->getInlinedAt());
@@ -1699,6 +1705,10 @@ bool DwarfCompileUnit::includeMinimalInlineScopes() const {
16991705
(DD->useSplitDwarf() && !Skeleton);
17001706
}
17011707

1708+
bool DwarfCompileUnit::emitFuncLineTableOffsets() const {
1709+
return EmitFuncLineTableOffsetsOption;
1710+
}
1711+
17021712
void DwarfCompileUnit::addAddrTableBase() {
17031713
const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
17041714
MCSymbol *Label = DD->getAddressPool().getLabel();

llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ class DwarfCompileUnit final : public DwarfUnit {
152152

153153
bool includeMinimalInlineScopes() const;
154154

155+
bool emitFuncLineTableOffsets() const;
156+
155157
void initStmtList();
156158

157159
/// Apply the DW_AT_stmt_list from this compile unit to the specified DIE.
@@ -207,10 +209,10 @@ class DwarfCompileUnit final : public DwarfUnit {
207209
void attachLowHighPC(DIE &D, const MCSymbol *Begin, const MCSymbol *End);
208210

209211
/// Find DIE for the given subprogram and attach appropriate
210-
/// DW_AT_low_pc and DW_AT_high_pc attributes. If there are global
211-
/// variables in this scope then create and insert DIEs for these
212-
/// variables.
213-
DIE &updateSubprogramScopeDIE(const DISubprogram *SP);
212+
/// DW_AT_low_pc, DW_AT_high_pc and DW_AT_LLVM_stmt_sequence attributes.
213+
/// If there are global variables in this scope then create and insert DIEs
214+
/// for these variables.
215+
DIE &updateSubprogramScopeDIE(const DISubprogram *SP, MCSymbol *LineTableSym);
214216

215217
void constructScopeDIE(LexicalScope *Scope, DIE &ParentScopeDIE);
216218

@@ -254,8 +256,8 @@ class DwarfCompileUnit final : public DwarfUnit {
254256
DIE *getOrCreateContextDIE(const DIScope *Ty) override;
255257

256258
/// Construct a DIE for this subprogram scope.
257-
DIE &constructSubprogramScopeDIE(const DISubprogram *Sub,
258-
LexicalScope *Scope);
259+
DIE &constructSubprogramScopeDIE(const DISubprogram *Sub, LexicalScope *Scope,
260+
MCSymbol *LineTableSym);
259261

260262
DIE *createAndAddScopeChildren(LexicalScope *Scope, DIE &ScopeDIE);
261263

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,6 @@ static cl::opt<DwarfDebug::MinimizeAddrInV5> MinimizeAddrInV5Option(
170170
"Stuff")),
171171
cl::init(DwarfDebug::MinimizeAddrInV5::Default));
172172

173-
static cl::opt<bool> EmitFuncLineTableOffsetsOption(
174-
"emit-func-debug-line-table-offsets", cl::Hidden,
175-
cl::desc("Include line table offset in function's debug info and emit end "
176-
"sequence after each function's line data."),
177-
cl::init(false));
178-
179173
static constexpr unsigned ULEB128PadSize = 4;
180174

181175
void DebugLocDwarfExpression::emitOp(uint8_t Op, const char *Comment) {
@@ -447,8 +441,6 @@ DwarfDebug::DwarfDebug(AsmPrinter *A)
447441
Asm->OutStreamer->getContext().setDwarfVersion(DwarfVersion);
448442
Asm->OutStreamer->getContext().setDwarfFormat(Dwarf64 ? dwarf::DWARF64
449443
: dwarf::DWARF32);
450-
Asm->OutStreamer->setGenerateFuncLineTableOffsets(
451-
EmitFuncLineTableOffsetsOption);
452444
}
453445

454446
// Define out of line so we don't have to include DwarfUnit.h in DwarfDebug.h.
@@ -2230,11 +2222,10 @@ void DwarfDebug::beginFunctionImpl(const MachineFunction *MF) {
22302222
if (SP->getUnit()->getEmissionKind() == DICompileUnit::NoDebug)
22312223
return;
22322224

2233-
// Notify the streamer that we are beginning a function - this will reset the
2234-
// label pointing to the currently generated function's first line entry
2235-
Asm->OutStreamer->beginFunction();
2236-
22372225
DwarfCompileUnit &CU = getOrCreateDwarfCompileUnit(SP->getUnit());
2226+
FunctionLineTableLabel = CU.emitFuncLineTableOffsets()
2227+
? Asm->OutStreamer->emitLineTableLabel()
2228+
: nullptr;
22382229

22392230
Asm->OutStreamer->getContext().setDwarfCompileUnitID(
22402231
getDwarfCompileUnitIDForLineTable(CU));
@@ -2346,11 +2337,14 @@ void DwarfDebug::endFunctionImpl(const MachineFunction *MF) {
23462337
}
23472338

23482339
ProcessedSPNodes.insert(SP);
2349-
DIE &ScopeDIE = TheCU.constructSubprogramScopeDIE(SP, FnScope);
2340+
DIE &ScopeDIE =
2341+
TheCU.constructSubprogramScopeDIE(SP, FnScope, FunctionLineTableLabel);
23502342
if (auto *SkelCU = TheCU.getSkeleton())
23512343
if (!LScopes.getAbstractScopesList().empty() &&
23522344
TheCU.getCUNode()->getSplitDebugInlining())
2353-
SkelCU->constructSubprogramScopeDIE(SP, FnScope);
2345+
SkelCU->constructSubprogramScopeDIE(SP, FnScope, FunctionLineTableLabel);
2346+
2347+
FunctionLineTableLabel = nullptr;
23542348

23552349
// Construct call site entries.
23562350
constructCallSiteEntryDIEs(*SP, TheCU, ScopeDIE, *MF);

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,9 @@ class DwarfDebug : public DebugHandlerBase {
408408
std::pair<std::unique_ptr<DwarfTypeUnit>, const DICompositeType *>, 1>
409409
TypeUnitsUnderConstruction;
410410

411+
/// Symbol pointing to the current function's DWARF line table entries.
412+
MCSymbol *FunctionLineTableLabel;
413+
411414
/// Used to set a uniqe ID for a Type Unit.
412415
/// This counter represents number of DwarfTypeUnits created, not necessarily
413416
/// number of type units that will be emitted.

llvm/lib/MC/MCDwarf.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,6 @@ void MCDwarfLineEntry::make(MCStreamer *MCOS, MCSection *Section) {
104104
// Get the current .loc info saved in the context.
105105
const MCDwarfLoc &DwarfLoc = MCOS->getContext().getCurrentDwarfLoc();
106106

107-
// If functions need offsets into the generated line table, then we need to
108-
// create a label referencing where the line was generated in the output
109-
// stream
110-
if (MCOS->getGenerateFuncLineTableOffsets() &&
111-
!MCOS->getCurrentFuncFirstLineStreamSym()) {
112-
MCSymbol *LineStreamLabel = MCOS->getContext().createTempSymbol();
113-
MCOS->emittedLineStreamSym(LineStreamLabel);
114-
MCDwarfLineEntry LabelLineEntry(LineSym, DwarfLoc, LineStreamLabel);
115-
MCOS->getContext()
116-
.getMCDwarfLineTable(MCOS->getContext().getDwarfCompileUnitID())
117-
.getMCLineSections()
118-
.addLineEntry(LabelLineEntry, Section);
119-
}
120-
121107
// Create a (local) line entry with the symbol and the current .loc info.
122108
MCDwarfLineEntry LineEntry(LineSym, DwarfLoc);
123109

llvm/lib/MC/MCStreamer.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,20 @@ void MCStreamer::emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
483483
Frame.End = (MCSymbol *)1;
484484
}
485485

486+
MCSymbol *MCStreamer::emitLineTableLabel() {
487+
// Create a label and insert it into the line table and return this label
488+
const MCDwarfLoc &DwarfLoc = getContext().getCurrentDwarfLoc();
489+
490+
MCSymbol *LineStreamLabel = getContext().createTempSymbol();
491+
MCDwarfLineEntry LabelLineEntry(nullptr, DwarfLoc, LineStreamLabel);
492+
getContext()
493+
.getMCDwarfLineTable(getContext().getDwarfCompileUnitID())
494+
.getMCLineSections()
495+
.addLineEntry(LabelLineEntry, getCurrentSectionOnly() /*Section*/);
496+
497+
return LineStreamLabel;
498+
}
499+
486500
MCSymbol *MCStreamer::emitCFILabel() {
487501
// Return a dummy non-null value so that label fields appear filled in when
488502
// generating textual assembly.

0 commit comments

Comments
 (0)