Skip to content

Added debug info for localized global variables for inlined scopes.#7799

Merged
adam-yang merged 7 commits intomicrosoft:mainfrom
adam-yang:local_global_var_debug_info
Nov 17, 2025
Merged

Added debug info for localized global variables for inlined scopes.#7799
adam-yang merged 7 commits intomicrosoft:mainfrom
adam-yang:local_global_var_debug_info

Conversation

@adam-yang
Copy link
Contributor

@adam-yang adam-yang commented Oct 4, 2025

Previously, global variables converted to alloca's, their debug info is written as a dbg.value for a fake local variable prefixed with "global.". This was only done for the entry function's DISubprogram, which makes the variable inaccessible for all inlined function scopes.

This change creates a dbg.value for each inlined DISubprogram, each pointing to a new DILocalVariable with the inlined DISubprogram as its scope.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 4, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@adam-yang adam-yang self-assigned this Oct 6, 2025
@adam-yang adam-yang marked this pull request as ready for review October 6, 2025 21:08
@adam-yang adam-yang requested a review from llvm-beanz November 13, 2025 19:15
Copy link
Member

@damyanp damyanp left a comment

Choose a reason for hiding this comment

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

LGTM

FWIW, I wasn't sure what the .ll test was testing (mostly through my ignorance), but I checked out the branch and reverted the functional changes and that test started failing, which convinced me at least that it is testing something.

I would recommend getting a review from someone more familiar with the codebase than I am!

@adam-yang adam-yang requested a review from tex3d November 17, 2025 18:53
@adam-yang adam-yang merged commit 450bbe5 into microsoft:main Nov 17, 2025
12 checks passed
@github-project-automation github-project-automation bot moved this from New to Done in HLSL Roadmap Nov 17, 2025
damyanp added a commit to damyanp/DirectXShaderCompiler that referenced this pull request Feb 19, 2026
…oft#8174)

PR microsoft#7799 added debug info for global variables across all inlined
subprograms, creating O(subprograms x globals) debug instructions.
This caused 2-3x slower compilation for shaders with many globals
and deeply-inlined functions.

Fix: Instead of collecting ALL subprograms for a function (walking
every instruction), only collect subprograms from the alloca's actual
users -- the instructions that reference the specific global variable.
This preserves the debug info feature (globals visible in inlined
scopes that use them) while eliminating work for unrelated scopes.

The 'Lower static global into Alloca' pass is 3.8x faster on the
stress test (41ms -> 11ms), and overall debug compilation is ~10%
faster.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
tex3d pushed a commit that referenced this pull request Feb 20, 2026
…ateDxilComputeAndNodeCommonInputs() (#8022)

As a result of
#7799, the HLSL
entry function can now contain `dbg.value` calls with !dbg location
metadata with scopes corresponding to functions which have been inlined.
The `HLSignatureLower::GenerateDxilComputeAndNodeCommonInputs()` creates
`@dx.op.threadId` intrinsic calls, using the default dbg loc when
creating an `IRBuilder`. When the first instruction in the entry block
is one of the `dbg,value` calls, its dbg location is copied to the
`@dx.op.threadId` calls. That makes the DXIL unreadable by the modern
LLVM IR reader since it fails the IR module verification because of !dbg
pointing to a different subprogram scope.

This change sets the dbg location for IRBuilder to be the !dbg node of
the first non-PHI and non-debug instruction in the block.

---------

Co-authored-by: Konstantin <konstantin.pyzhov@amd.com>
Copilot AI added a commit that referenced this pull request Feb 20, 2026
… inlined scopes

Co-authored-by: alsepkow <5620315+alsepkow@users.noreply.github.com>
alsepkow added a commit to alsepkow/DirectXShaderCompiler that referenced this pull request Feb 20, 2026
alsepkow added a commit that referenced this pull request Feb 20, 2026
…copes. (#7799)" (#8185)

This reverts commit
[450bbe5](450bbe5).

A bug was discovered and we have decided to revert this change in the
6.9 release branch while we work on the fix.
luciechoi pushed a commit to luciechoi/DirectXShaderCompiler that referenced this pull request Feb 20, 2026
…ateDxilComputeAndNodeCommonInputs() (microsoft#8022)

As a result of
microsoft#7799, the HLSL
entry function can now contain `dbg.value` calls with !dbg location
metadata with scopes corresponding to functions which have been inlined.
The `HLSignatureLower::GenerateDxilComputeAndNodeCommonInputs()` creates
`@dx.op.threadId` intrinsic calls, using the default dbg loc when
creating an `IRBuilder`. When the first instruction in the entry block
is one of the `dbg,value` calls, its dbg location is copied to the
`@dx.op.threadId` calls. That makes the DXIL unreadable by the modern
LLVM IR reader since it fails the IR module verification because of !dbg
pointing to a different subprogram scope.

This change sets the dbg location for IRBuilder to be the !dbg node of
the first non-PHI and non-debug instruction in the block.

---------

Co-authored-by: Konstantin <konstantin.pyzhov@amd.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants