Skip to content

Conversation

@nikic
Copy link
Contributor

@nikic nikic commented Jun 30, 2025

Fetch the DILocation once, instead of many times. This is pretty trivial, but goes through out-of-line code.

It's a very minor improvement: https://llvm-compile-time-tracker.com/compare.php?from=652630b3c918c807fca8785eabdb92393b87043a&to=ee035faadfa6f68f6447ae7e0051d44965d1556c&stat=instructions:u

Fetch the DILocation once, instead of many times. This is pretty
trivial, but goes through out-of-line code.
@llvmbot
Copy link
Member

llvmbot commented Jun 30, 2025

@llvm/pr-subscribers-debuginfo

Author: Nikita Popov (nikic)

Changes

Fetch the DILocation once, instead of many times. This is pretty trivial, but goes through out-of-line code.

It's a very minor improvement: https://llvm-compile-time-tracker.com/compare.php?from=652630b3c918c807fca8785eabdb92393b87043a&to=ee035faadfa6f68f6447ae7e0051d44965d1556c&stat=instructions:u


Full diff: https://github.com/llvm/llvm-project/pull/146357.diff

1 Files Affected:

  • (modified) llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (+11-14)
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 different 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.

Copy link
Contributor

@OCHyams OCHyams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for this

@nikic nikic merged commit c5e4546 into llvm:main Jul 1, 2025
9 of 10 checks passed
@nikic nikic deleted the compute-key-instr branch July 1, 2025 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants