Skip to content

Change scope nested CFG passes to use a stack instead of recursion#8227

Merged
jenatali merged 3 commits intomicrosoft:mainfrom
jenatali:scope-nested-fix
Apr 7, 2026
Merged

Change scope nested CFG passes to use a stack instead of recursion#8227
jenatali merged 3 commits intomicrosoft:mainfrom
jenatali:scope-nested-fix

Conversation

@jenatali
Copy link
Copy Markdown
Member

@jenatali jenatali commented Mar 5, 2026

Fixes #8224

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 5, 2026

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

Copy link
Copy Markdown
Collaborator

@llvm-beanz llvm-beanz left a comment

Choose a reason for hiding this comment

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

This does not conform to our coding standards some obvious violations include:

@github-project-automation github-project-automation Bot moved this from New to In progress in HLSL Roadmap Mar 5, 2026
Comment thread projects/dxilconv/lib/DxilConvPasses/ScopeNestedCFG.cpp Outdated
Comment thread projects/dxilconv/lib/DxilConvPasses/ScopeNestedCFG.cpp Outdated
Comment thread projects/dxilconv/lib/DxilConvPasses/ScopeNestedCFG.cpp Outdated
Comment thread projects/dxilconv/lib/DxilConvPasses/ScopeNestedCFG.cpp Outdated
Copy link
Copy Markdown
Collaborator

@llvm-beanz llvm-beanz left a comment

Choose a reason for hiding this comment

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

Thank you for the cleanups! I just have two small nits, otherwise this looks good to me.

Comment thread projects/dxilconv/lib/DxilConvPasses/ScopeNestedCFG.cpp Outdated
Comment thread projects/dxilconv/lib/DxilConvPasses/ScopeNestedCFG.cpp Outdated
Co-authored-by: Chris B <beanz@abolishcrlf.org>
(*ReachableBBs) |= (*BTO.GetReachableBBs(pSuccBB));
}
if (PushedChild)
continue;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I can't wrap my mind around how this is logically equivalent to the previous code, this looks like a behavioral change. Lines 1054-1074 here are the only lines I can't see the equivalent iterative translation for. Can you explain why we continue here? Maybe that would help explain the previous lines to me also. Other than those lines, this change looks good to me.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The previous logic would:

  • Check for work to do for the target block
  • For each successor:
    • Recurse
    • After recursion for a specific block, update the reachable blocks
  • After all recursion, update the late watermark and append to BTO

The new logic will:

  • In an iteration, check if this is the "before recursion" phase (based on the initialized flag), and if so, do the pre-recursion work.
  • Process one successor: For the current successor, if we haven't processed it, then push a stack frame, break out of the successor loop, and immediately proceed back to the top of the iteration loop (i.e. begin processing that new frame). If we've already processed the successor, then iterate until we find one we haven't processed, or until we've checked all of them.
  • If we didn't push a recursive stack frame, then process the post-recursion work.

Copy link
Copy Markdown
Collaborator

@bob80905 bob80905 left a comment

Choose a reason for hiding this comment

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

The continue makes sense now. There is an extra DXAssert that is being introduced that I don't think was in the previous version, and it might be redundant since this assert already exists earlier in the function on what appears to be an already-processed frame. But otherwise LGTM.

@jenatali jenatali merged commit 33656f6 into microsoft:main Apr 7, 2026
12 checks passed
@github-project-automation github-project-automation Bot moved this from In progress to Done in HLSL Roadmap Apr 7, 2026
@jenatali jenatali deleted the scope-nested-fix branch April 7, 2026 17:24
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.

ScopeNestedCFG pass stack overflow in large shaders with debug builds

3 participants