[llvm] [KeyInstr] Fully support mixed key/non-key inlining modes (PR #144103)
Orlando Cazalet-Hyams via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 30 01:05:14 PDT 2025
https://github.com/OCHyams updated https://github.com/llvm/llvm-project/pull/144103
>From f899c3e0ab429c2acc81fbedfd3f3ecb6a3dcdf6 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams <orlando.hyams at sony.com>
Date: Fri, 13 Jun 2025 14:28:38 +0100
Subject: [PATCH] [KeyInstr] Fully support mixed key/non-key inlining modes
<link to cost>
---
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 26 +++++++------------
.../X86/dwarf-inline-modes.mir | 8 +-----
2 files changed, 11 insertions(+), 23 deletions(-)
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 9a44d03242b45..87ec9550c0ebb 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -2081,13 +2081,12 @@ 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.
+ // should use not-key is_stmt handling. Key instructions functions inlined
+ // 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