Skip to content

Commit c5e4546

Browse files
authored
[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.
1 parent 72b40f7 commit c5e4546

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,6 +2383,8 @@ void DwarfDebug::computeKeyInstructions(const MachineFunction *MF) {
23832383
std::pair<uint8_t, SmallVector<const MachineInstr *, 2>>>
23842384
GroupCandidates;
23852385

2386+
const auto &TII = *MF->getSubtarget().getInstrInfo();
2387+
23862388
// For each instruction:
23872389
// * Skip insts without DebugLoc, AtomGroup or AtomRank, and line zeros.
23882390
// * Check if insts in this group have been seen already in GroupCandidates.
@@ -2411,24 +2413,20 @@ void DwarfDebug::computeKeyInstructions(const MachineFunction *MF) {
24112413
if (MI.isMetaInstruction())
24122414
continue;
24132415

2414-
if (!MI.getDebugLoc() || !MI.getDebugLoc().getLine())
2416+
const DILocation *Loc = MI.getDebugLoc().get();
2417+
if (!Loc || !Loc->getLine())
24152418
continue;
24162419

24172420
// Reset the Buoy to this instruction if it has a different line number.
2418-
if (!Buoy ||
2419-
Buoy->getDebugLoc().getLine() != MI.getDebugLoc().getLine()) {
2421+
if (!Buoy || Buoy->getDebugLoc().getLine() != Loc->getLine()) {
24202422
Buoy = &MI;
24212423
BuoyAtom = 0; // Set later when we know which atom the buoy is used by.
24222424
}
24232425

24242426
// Call instructions are handled specially - we always mark them as key
24252427
// regardless of atom info.
2426-
const auto &TII =
2427-
*MI.getParent()->getParent()->getSubtarget().getInstrInfo();
24282428
bool IsCallLike = MI.isCall() || TII.isTailCall(MI);
24292429
if (IsCallLike) {
2430-
assert(MI.getDebugLoc() && "Unexpectedly missing DL");
2431-
24322430
// Calls are always key. Put the buoy (may not be the call) into
24332431
// KeyInstructions directly rather than the candidate map to avoid it
24342432
// being erased (and we may not have a group number for the call).
@@ -2438,14 +2436,13 @@ void DwarfDebug::computeKeyInstructions(const MachineFunction *MF) {
24382436
Buoy = nullptr;
24392437
BuoyAtom = 0;
24402438

2441-
if (!MI.getDebugLoc()->getAtomGroup() ||
2442-
!MI.getDebugLoc()->getAtomRank())
2439+
if (!Loc->getAtomGroup() || !Loc->getAtomRank())
24432440
continue;
24442441
}
24452442

2446-
auto *InlinedAt = MI.getDebugLoc()->getInlinedAt();
2447-
uint64_t Group = MI.getDebugLoc()->getAtomGroup();
2448-
uint8_t Rank = MI.getDebugLoc()->getAtomRank();
2443+
auto *InlinedAt = Loc->getInlinedAt();
2444+
uint64_t Group = Loc->getAtomGroup();
2445+
uint8_t Rank = Loc->getAtomRank();
24492446
if (!Group || !Rank)
24502447
continue;
24512448

@@ -2487,8 +2484,8 @@ void DwarfDebug::computeKeyInstructions(const MachineFunction *MF) {
24872484
CandidateInsts.push_back(Buoy);
24882485
CandidateRank = Rank;
24892486

2490-
assert(!BuoyAtom || BuoyAtom == MI.getDebugLoc()->getAtomGroup());
2491-
BuoyAtom = MI.getDebugLoc()->getAtomGroup();
2487+
assert(!BuoyAtom || BuoyAtom == Loc->getAtomGroup());
2488+
BuoyAtom = Loc->getAtomGroup();
24922489
} else {
24932490
// Don't add calls, because they've been dealt with already. This means
24942491
// CandidateInsts might now be empty - handle that.

0 commit comments

Comments
 (0)