[llvm] af82e14 - [KeyInstr] Fully support mixed key/non-key inlining modes (#144103)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 30 01:57:03 PDT 2025


Author: Orlando Cazalet-Hyams
Date: 2025-06-30T09:56:56+01:00
New Revision: af82e14c4a351227c50cb4db4fd3aeb2c99627ef

URL: https://github.com/llvm/llvm-project/commit/af82e14c4a351227c50cb4db4fd3aeb2c99627ef
DIFF: https://github.com/llvm/llvm-project/commit/af82e14c4a351227c50cb4db4fd3aeb2c99627ef.diff

LOG: [KeyInstr] Fully support mixed key/non-key inlining modes (#144103)

Patch 3/4 adding bitcode support, though the final patch doesn't depend on this
one.

Prior to this patch, a Key Instructions function inlined into a
Not-Key-Instructions function fell back to Not-Key-Instructions handling.

In order to fully support inlining mixed modes we need to run
`computeKeyInstructions` (in case there's a Key Instructions scope) and
`findForceIsStmtInstrs` (in case there's a Not-Key-Instructions scope) on all
functions. This has a slight performance cost for all configurations - see PR
for details.

Added: 
    

Modified: 
    llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
    llvm/test/DebugInfo/KeyInstructions/X86/dwarf-inline-modes.mir

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 9a44d03242b45..47c44efa8e73c 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -2082,12 +2082,11 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
   // There may be a mixture of scopes using and not using Key Instructions.
   // Not-Key-Instructions functions inlined into Key Instructions functions
   // should use not-key is_stmt handling. Key Instructions functions inlined
-  // into not-key-instructions functions currently fall back to not-key
-  // handling to avoid having to run computeKeyInstructions for all functions
-  // (which will impact non-key-instructions builds).
-  // TODO: Investigate the performance impact of doing that.
+  // into Not-Key-Instructions functions should use Key Instructions is_stmt
+  // handling.
   bool ScopeUsesKeyInstructions =
-      KeyInstructionsAreStmts && DL && SP->getKeyInstructionsEnabled();
+      KeyInstructionsAreStmts && DL &&
+      DL->getScope()->getSubprogram()->getKeyInstructionsEnabled();
 
   bool IsKey = false;
   if (ScopeUsesKeyInstructions && DL && DL.getLine())
@@ -2663,17 +2662,12 @@ void DwarfDebug::beginFunctionImpl(const MachineFunction *MF) {
   PrologEndLoc = emitInitialLocDirective(
       *MF, Asm->OutStreamer->getContext().getDwarfCompileUnitID());
 
-  // If this function wasn't built with Key Instructions but has a function
-  // inlined into it that was, we treat the inlined instance as if it wasn't
-  // built with Key Instructions. If this function was built with Key
-  // Instructions but a function inlined into it wasn't then we continue to use
-  // Key Instructions for this function and fall back to non-key behaviour for
-  // the inlined function (except it doesn't benefit from
-  // findForceIsStmtInstrs).
-  if (KeyInstructionsAreStmts && SP->getKeyInstructionsEnabled())
+  // Run both `findForceIsStmtInstrs` and `computeKeyInstructions` because
+  // Not-Key-Instructions functions may be inlined into Key Instructions
+  // functions and vice versa.
+  if (KeyInstructionsAreStmts)
     computeKeyInstructions(MF);
-  else
-    findForceIsStmtInstrs(MF);
+  findForceIsStmtInstrs(MF);
 }
 
 unsigned

diff  --git a/llvm/test/DebugInfo/KeyInstructions/X86/dwarf-inline-modes.mir b/llvm/test/DebugInfo/KeyInstructions/X86/dwarf-inline-modes.mir
index 5926d23967cb6..273d5cbdfda24 100644
--- a/llvm/test/DebugInfo/KeyInstructions/X86/dwarf-inline-modes.mir
+++ b/llvm/test/DebugInfo/KeyInstructions/X86/dwarf-inline-modes.mir
@@ -79,19 +79,13 @@ body:             |
     ; OBJ-NEXT: 2a: movl $0x3, %eax
     ; OBJ-NEXT: 2f: retq
     ;
-    ; TODO: Currently key inlined into not-key is treated as not-key. Investigate
-    ; performance implications of honouring the flag in this scenario.
-    ;
     ;           Address            Line   Column File   ISA Discriminator OpIndex Flags
     ;           ------------------ ------ ------ ------ --- ------------- ------- -------------
     ; DBG-NEXT: 0x0000000000000020      1      0      0   0             0       0  is_stmt prologue_end
-    ; DBG-NEXT: 0x0000000000000025      2      0      0   0             0       0  is_stmt
+    ; DBG-NEXT: 0x0000000000000025      2      0      0   0             0       0
     ; DBG-NEXT: 0x000000000000002a      3      0      0   0             0       0  is_stmt
     ; DBG-NEXT: 0x000000000000002f      3      0      0   0             0       0
     ;
-    ; NOTE: The `is_stmt` comments at the end of the lines reflects what we want
-    ; to see if the TODO above is resolved.
-    ;
     $eax = MOV32ri 1,  debug-location !DILocation(line: 1, scope: !9)                                            ; is_stmt (prologue_end)
     $eax = MOV32ri 2,  debug-location !DILocation(line: 2, scope: !5, inlinedAt: !11, atomGroup: 1, atomRank: 2)
     $eax = MOV32ri 3,  debug-location !DILocation(line: 3, scope: !5, inlinedAt: !11, atomGroup: 1, atomRank: 1) ; is_stmt (key)


        


More information about the llvm-commits mailing list