-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[DWARF] Identify prologue_end by instruction rather than DILocation #107264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Seemingly this goes back to fd07a2a in 2015 -- I anticipate that back then the metadata layout was radically different. But nowadays at least, we can just directly look up the subprogram.
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.
@llvm/pr-subscribers-debuginfo Author: Jeremy Morse (jmorse) ChangesI'm aiming to refactor this area a little bit, for scenarios where there are no source-locations in the entry blocks to connect prologue_end with. To that end, this patch identifies the position of the prologue_end flag by specific It should (TM) be NFC. Note that it's only the latest commit in this PR, as github doesn't do stacked reviews. Full diff: https://github.com/llvm/llvm-project/pull/107264.diff 3 Files Affected:
diff --git a/llvm/include/llvm/CodeGen/DebugHandlerBase.h b/llvm/include/llvm/CodeGen/DebugHandlerBase.h
index 85046c200ff9b1..d39e7e68cb2558 100644
--- a/llvm/include/llvm/CodeGen/DebugHandlerBase.h
+++ b/llvm/include/llvm/CodeGen/DebugHandlerBase.h
@@ -74,7 +74,7 @@ class DebugHandlerBase {
/// This location indicates end of function prologue and beginning of
/// function body.
- DebugLoc PrologEndLoc;
+ const MachineInstr *PrologEndLoc;
/// This block includes epilogue instructions.
const MachineBasicBlock *EpilogBeginBlock = nullptr;
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index f111b4aea06f1b..f8515ab6ff11fa 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -2114,9 +2114,9 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
// (The new location might be an explicit line 0, which we do emit.)
if (DL.getLine() == 0 && LastAsmLine == 0)
return;
- if (DL == PrologEndLoc) {
+ if (MI == PrologEndLoc) {
Flags |= DWARF2_FLAG_PROLOGUE_END | DWARF2_FLAG_IS_STMT;
- PrologEndLoc = DebugLoc();
+ PrologEndLoc = nullptr;
}
// If the line changed, we call that a new statement; unless we went to
// line 0 and came back, in which case it is not a new statement.
@@ -2132,10 +2132,11 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
PrevInstLoc = DL;
}
-static std::pair<DebugLoc, bool> findPrologueEndLoc(const MachineFunction *MF) {
+static std::pair<const MachineInstr *, bool>
+findPrologueEndLoc(const MachineFunction *MF) {
// First known non-DBG_VALUE and non-frame setup location marks
// the beginning of the function body.
- DebugLoc LineZeroLoc;
+ const MachineInstr *LineZeroLoc = nullptr;
const Function &F = MF->getFunction();
// Some instructions may be inserted into prologue after this function. Must
@@ -2152,9 +2153,9 @@ static std::pair<DebugLoc, bool> findPrologueEndLoc(const MachineFunction *MF) {
// meaningful breakpoint. If none is found, return the first
// location after the frame setup.
if (MI.getDebugLoc().getLine())
- return std::make_pair(MI.getDebugLoc(), IsEmptyPrologue);
+ return std::make_pair(&MI, IsEmptyPrologue);
- LineZeroLoc = MI.getDebugLoc();
+ LineZeroLoc = &MI;
}
IsEmptyPrologue = false;
}
@@ -2185,10 +2186,10 @@ static void recordSourceLine(AsmPrinter &Asm, unsigned Line, unsigned Col,
Discriminator, Fn);
}
-DebugLoc DwarfDebug::emitInitialLocDirective(const MachineFunction &MF,
- unsigned CUID) {
- std::pair<DebugLoc, bool> PrologEnd = findPrologueEndLoc(&MF);
- DebugLoc PrologEndLoc = PrologEnd.first;
+const MachineInstr *
+DwarfDebug::emitInitialLocDirective(const MachineFunction &MF, unsigned CUID) {
+ std::pair<const MachineInstr *, bool> PrologEnd = findPrologueEndLoc(&MF);
+ const MachineInstr *PrologEndLoc = PrologEnd.first;
bool IsEmptyPrologue = PrologEnd.second;
// Get beginning of function.
@@ -2199,16 +2200,15 @@ DebugLoc DwarfDebug::emitInitialLocDirective(const MachineFunction &MF,
// Ensure the compile unit is created if the function is called before
// beginFunction().
- (void)getOrCreateDwarfCompileUnit(
- MF.getFunction().getSubprogram()->getUnit());
+ DISubprogram *SP = MF.getFunction().getSubprogram();
+ (void)getOrCreateDwarfCompileUnit(SP->getUnit());
// We'd like to list the prologue as "not statements" but GDB behaves
// poorly if we do that. Revisit this with caution/GDB (7.5+) testing.
- const DISubprogram *SP = PrologEndLoc->getInlinedAtScope()->getSubprogram();
::recordSourceLine(*Asm, SP->getScopeLine(), 0, SP, DWARF2_FLAG_IS_STMT,
CUID, getDwarfVersion(), getUnits());
return PrologEndLoc;
}
- return DebugLoc();
+ return nullptr;
}
// Gather pre-function debug information. Assumes being called immediately
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
index 6e379396ea079e..19f5b677bb8d06 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
@@ -724,8 +724,10 @@ class DwarfDebug : public DebugHandlerBase {
/// Emit all Dwarf sections that should come after the content.
void endModule() override;
- /// Emits inital debug location directive.
- DebugLoc emitInitialLocDirective(const MachineFunction &MF, unsigned CUID);
+ /// Emits inital debug location directive. Returns instruction at which
+ /// the function prologue ends.
+ const MachineInstr *emitInitialLocDirective(const MachineFunction &MF,
+ unsigned CUID);
/// Process beginning of an instruction.
void beginInstruction(const MachineInstr *MI) override;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I'm aiming to refactor this area a little bit, for scenarios where there are no source-locations in the entry blocks to connect prologue_end with. To that end, this patch identifies the position of the prologue_end flag by specific
MachineInstr*
rather than by the source location attached to an instruction, which is much more precise IMO.It should (TM) be NFC. Note that it's only the latest commit in this PR, as github doesn't do stacked reviews.