Skip to content

Commit 3299bc8

Browse files
authored
[DWARF] Identify prologue_end by instruction rather than DILocation (#107264)
Currently, we identify the end of the prologue as being "the instruction that first has *this* DebugLoc". It works well enough, but I feel identifying a position in a function is best communicated by a MachineInstr. Plus, I've got some patches coming that depend upon this.
1 parent d0278cf commit 3299bc8

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

llvm/include/llvm/CodeGen/DebugHandlerBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class DebugHandlerBase {
7474

7575
/// This location indicates end of function prologue and beginning of
7676
/// function body.
77-
DebugLoc PrologEndLoc;
77+
const MachineInstr *PrologEndLoc;
7878

7979
/// This block includes epilogue instructions.
8080
const MachineBasicBlock *EpilogBeginBlock = nullptr;

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,9 +2111,9 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
21112111
// (The new location might be an explicit line 0, which we do emit.)
21122112
if (DL.getLine() == 0 && LastAsmLine == 0)
21132113
return;
2114-
if (DL == PrologEndLoc) {
2114+
if (MI == PrologEndLoc) {
21152115
Flags |= DWARF2_FLAG_PROLOGUE_END | DWARF2_FLAG_IS_STMT;
2116-
PrologEndLoc = DebugLoc();
2116+
PrologEndLoc = nullptr;
21172117
}
21182118
// If the line changed, we call that a new statement; unless we went to
21192119
// line 0 and came back, in which case it is not a new statement. We also
@@ -2131,10 +2131,11 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
21312131
PrevInstLoc = DL;
21322132
}
21332133

2134-
static std::pair<DebugLoc, bool> findPrologueEndLoc(const MachineFunction *MF) {
2134+
static std::pair<const MachineInstr *, bool>
2135+
findPrologueEndLoc(const MachineFunction *MF) {
21352136
// First known non-DBG_VALUE and non-frame setup location marks
21362137
// the beginning of the function body.
2137-
DebugLoc LineZeroLoc;
2138+
const MachineInstr *LineZeroLoc = nullptr;
21382139
const Function &F = MF->getFunction();
21392140

21402141
// Some instructions may be inserted into prologue after this function. Must
@@ -2151,9 +2152,9 @@ static std::pair<DebugLoc, bool> findPrologueEndLoc(const MachineFunction *MF) {
21512152
// meaningful breakpoint. If none is found, return the first
21522153
// location after the frame setup.
21532154
if (MI.getDebugLoc().getLine())
2154-
return std::make_pair(MI.getDebugLoc(), IsEmptyPrologue);
2155+
return std::make_pair(&MI, IsEmptyPrologue);
21552156

2156-
LineZeroLoc = MI.getDebugLoc();
2157+
LineZeroLoc = &MI;
21572158
}
21582159
IsEmptyPrologue = false;
21592160
}
@@ -2184,10 +2185,10 @@ static void recordSourceLine(AsmPrinter &Asm, unsigned Line, unsigned Col,
21842185
Discriminator, Fn);
21852186
}
21862187

2187-
DebugLoc DwarfDebug::emitInitialLocDirective(const MachineFunction &MF,
2188-
unsigned CUID) {
2189-
std::pair<DebugLoc, bool> PrologEnd = findPrologueEndLoc(&MF);
2190-
DebugLoc PrologEndLoc = PrologEnd.first;
2188+
const MachineInstr *
2189+
DwarfDebug::emitInitialLocDirective(const MachineFunction &MF, unsigned CUID) {
2190+
std::pair<const MachineInstr *, bool> PrologEnd = findPrologueEndLoc(&MF);
2191+
const MachineInstr *PrologEndLoc = PrologEnd.first;
21912192
bool IsEmptyPrologue = PrologEnd.second;
21922193

21932194
// Get beginning of function.
@@ -2206,7 +2207,7 @@ DebugLoc DwarfDebug::emitInitialLocDirective(const MachineFunction &MF,
22062207
CUID, getDwarfVersion(), getUnits());
22072208
return PrologEndLoc;
22082209
}
2209-
return DebugLoc();
2210+
return nullptr;
22102211
}
22112212

22122213
// Gather pre-function debug information. Assumes being called immediately

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,10 @@ class DwarfDebug : public DebugHandlerBase {
724724
/// Emit all Dwarf sections that should come after the content.
725725
void endModule() override;
726726

727-
/// Emits inital debug location directive.
728-
DebugLoc emitInitialLocDirective(const MachineFunction &MF, unsigned CUID);
727+
/// Emits inital debug location directive. Returns instruction at which
728+
/// the function prologue ends.
729+
const MachineInstr *emitInitialLocDirective(const MachineFunction &MF,
730+
unsigned CUID);
729731

730732
/// Process beginning of an instruction.
731733
void beginInstruction(const MachineInstr *MI) override;

0 commit comments

Comments
 (0)