Skip to content

Commit dca325e

Browse files
committed
[DebugInfo] Identify end of prologue by instruction
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 60750e7 commit dca325e

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
@@ -2114,9 +2114,9 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
21142114
// (The new location might be an explicit line 0, which we do emit.)
21152115
if (DL.getLine() == 0 && LastAsmLine == 0)
21162116
return;
2117-
if (DL == PrologEndLoc) {
2117+
if (MI == PrologEndLoc) {
21182118
Flags |= DWARF2_FLAG_PROLOGUE_END | DWARF2_FLAG_IS_STMT;
2119-
PrologEndLoc = DebugLoc();
2119+
PrologEndLoc = nullptr;
21202120
}
21212121
// If the line changed, we call that a new statement; unless we went to
21222122
// line 0 and came back, in which case it is not a new statement.
@@ -2132,10 +2132,11 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
21322132
PrevInstLoc = DL;
21332133
}
21342134

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

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

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

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

21942195
// Get beginning of function.
@@ -2207,7 +2208,7 @@ DebugLoc DwarfDebug::emitInitialLocDirective(const MachineFunction &MF,
22072208
CUID, getDwarfVersion(), getUnits());
22082209
return PrologEndLoc;
22092210
}
2210-
return DebugLoc();
2211+
return nullptr;
22112212
}
22122213

22132214
// 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)