[llvm] 3299bc8 - [DWARF] Identify prologue_end by instruction rather than DILocation (#107264)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 5 03:18:33 PDT 2024
Author: Jeremy Morse
Date: 2024-09-05T11:18:29+01:00
New Revision: 3299bc863fd74613fdfad2a2fde3f75de79bd645
URL: https://github.com/llvm/llvm-project/commit/3299bc863fd74613fdfad2a2fde3f75de79bd645
DIFF: https://github.com/llvm/llvm-project/commit/3299bc863fd74613fdfad2a2fde3f75de79bd645.diff
LOG: [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.
Added:
Modified:
llvm/include/llvm/CodeGen/DebugHandlerBase.h
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
Removed:
################################################################################
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 9da9382baf8634..ea3fed8817d893 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -2111,9 +2111,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. We also
@@ -2131,10 +2131,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
@@ -2151,9 +2152,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;
}
@@ -2184,10 +2185,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.
@@ -2206,7 +2207,7 @@ DebugLoc DwarfDebug::emitInitialLocDirective(const MachineFunction &MF,
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;
More information about the llvm-commits
mailing list