[llvm] [DWARF] Don't search scope chain to find DISubprogram for prologues (PR #107261)

Jeremy Morse via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 4 08:48:01 PDT 2024


https://github.com/jmorse created https://github.com/llvm/llvm-project/pull/107261

Despite having a DISubprogram to hand, this code calls `getInlinedAtScope` to step through all inlined scopes to the outermost one and retrieve... the same DISubprogram. Seemingly this goes back to fd07a2af23c in 2015 -- I anticipate that back then the metadata layout was radically different, and the code simply hasn't been changed since then as it isn't broken.

Nowadays at least, we can just directly look up the subprogram (and I'd like to refactor this area a little).

>From 60750e7c4459e1164894e2acb4bded6b9bcbc246 Mon Sep 17 00:00:00 2001
From: Jeremy Morse <jeremy.morse at sony.com>
Date: Mon, 2 Sep 2024 17:01:47 +0100
Subject: [PATCH] [DebugInfo] Don't search scope chain to find Subprogram

Seemingly this goes back to fd07a2af23c 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.
---
 llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index f111b4aea06f1b..1d57b5e4400dc2 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -2199,11 +2199,10 @@ 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;



More information about the llvm-commits mailing list