[llvm] c5e4546 - [DwarfDebug] Slightly optimize computeKeyInstructions() (NFC) (#146357)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 1 00:06:21 PDT 2025
Author: Nikita Popov
Date: 2025-07-01T09:06:17+02:00
New Revision: c5e4546a01195fd278c65cb989882a349f4d9f8d
URL: https://github.com/llvm/llvm-project/commit/c5e4546a01195fd278c65cb989882a349f4d9f8d
DIFF: https://github.com/llvm/llvm-project/commit/c5e4546a01195fd278c65cb989882a349f4d9f8d.diff
LOG: [DwarfDebug] Slightly optimize computeKeyInstructions() (NFC) (#146357)
Fetch the DILocation once, instead of many times. This is pretty
trivial, but goes through out-of-line code.
Added:
Modified:
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 47c44efa8e73c..11b85763a3fb1 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -2383,6 +2383,8 @@ void DwarfDebug::computeKeyInstructions(const MachineFunction *MF) {
std::pair<uint8_t, SmallVector<const MachineInstr *, 2>>>
GroupCandidates;
+ const auto &TII = *MF->getSubtarget().getInstrInfo();
+
// For each instruction:
// * Skip insts without DebugLoc, AtomGroup or AtomRank, and line zeros.
// * Check if insts in this group have been seen already in GroupCandidates.
@@ -2411,24 +2413,20 @@ void DwarfDebug::computeKeyInstructions(const MachineFunction *MF) {
if (MI.isMetaInstruction())
continue;
- if (!MI.getDebugLoc() || !MI.getDebugLoc().getLine())
+ const DILocation *Loc = MI.getDebugLoc().get();
+ if (!Loc || !Loc->getLine())
continue;
// Reset the Buoy to this instruction if it has a
diff erent line number.
- if (!Buoy ||
- Buoy->getDebugLoc().getLine() != MI.getDebugLoc().getLine()) {
+ if (!Buoy || Buoy->getDebugLoc().getLine() != Loc->getLine()) {
Buoy = &MI;
BuoyAtom = 0; // Set later when we know which atom the buoy is used by.
}
// Call instructions are handled specially - we always mark them as key
// regardless of atom info.
- const auto &TII =
- *MI.getParent()->getParent()->getSubtarget().getInstrInfo();
bool IsCallLike = MI.isCall() || TII.isTailCall(MI);
if (IsCallLike) {
- assert(MI.getDebugLoc() && "Unexpectedly missing DL");
-
// Calls are always key. Put the buoy (may not be the call) into
// KeyInstructions directly rather than the candidate map to avoid it
// being erased (and we may not have a group number for the call).
@@ -2438,14 +2436,13 @@ void DwarfDebug::computeKeyInstructions(const MachineFunction *MF) {
Buoy = nullptr;
BuoyAtom = 0;
- if (!MI.getDebugLoc()->getAtomGroup() ||
- !MI.getDebugLoc()->getAtomRank())
+ if (!Loc->getAtomGroup() || !Loc->getAtomRank())
continue;
}
- auto *InlinedAt = MI.getDebugLoc()->getInlinedAt();
- uint64_t Group = MI.getDebugLoc()->getAtomGroup();
- uint8_t Rank = MI.getDebugLoc()->getAtomRank();
+ auto *InlinedAt = Loc->getInlinedAt();
+ uint64_t Group = Loc->getAtomGroup();
+ uint8_t Rank = Loc->getAtomRank();
if (!Group || !Rank)
continue;
@@ -2487,8 +2484,8 @@ void DwarfDebug::computeKeyInstructions(const MachineFunction *MF) {
CandidateInsts.push_back(Buoy);
CandidateRank = Rank;
- assert(!BuoyAtom || BuoyAtom == MI.getDebugLoc()->getAtomGroup());
- BuoyAtom = MI.getDebugLoc()->getAtomGroup();
+ assert(!BuoyAtom || BuoyAtom == Loc->getAtomGroup());
+ BuoyAtom = Loc->getAtomGroup();
} else {
// Don't add calls, because they've been dealt with already. This means
// CandidateInsts might now be empty - handle that.
More information about the llvm-commits
mailing list