Skip to content

[KeyInstr] Fully support mixed key/non-key inlining modes #144103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading