Skip to content

JIT: replace fgWalkTree callbacks with GenTreeVisitor implementations - #132469

Merged
jakobbotsch merged 4 commits into
dotnet:mainfrom
jakobbotsch:jit-remove-fgwalktree
Aug 20, 2026
Merged

JIT: replace fgWalkTree callbacks with GenTreeVisitor implementations#132469
jakobbotsch merged 4 commits into
dotnet:mainfrom
jakobbotsch:jit-remove-fgwalktree

Conversation

@jakobbotsch

Copy link
Copy Markdown
Member

The fgWalkTreePre/fgWalkTreePost/fgWalkTree family dispatched every node visit through a function pointer stored in fgWalkData. That indirect call could not be inlined into GenTreeVisitor::WalkTree and, on Windows, went through a Control Flow Guard dispatch stub per node.

Convert the remaining users to direct GenTreeVisitor implementations and delete fgWalkTreePre, fgWalkTreePost, fgWalkTree, fgWalkAllTreesPre, GenericTreeWalker, fgWalkData and the fgWalkPreFn/fgWalkPostFn typedefs.

Several parameters turned out to be already dead and are gone with them: GenericTreeWalker hardcoded ComputeStack to false and nothing read fgWalkData::parentStack, so computeStack had no effect; lclVarsOnly had no remaining users; and fgWalkData::printModified was never set. The unused fgSplitPredicate typedef is removed as well.

gtHasCatchArg is reimplemented on the existing gtFindNodeInTree helper. Descending only into subtrees with GTF_ORDER_SIDEEFF preserves its previous root-level early-out and additionally prunes at every level; GT_CATCH_ARG sets that flag on itself and effect flags propagate to parents, so a subtree without it cannot contain one.

SuperPMI asmdiffs over all 11 windows-x64 collections show no diffs. Throughput on benchmarks.run, measured as instructions retired: -1.94% for the checked JIT and -0.33% for release built with NoPgoOptimize.

The fgWalkTreePre/fgWalkTreePost/fgWalkTree family dispatched every node
visit through a function pointer stored in fgWalkData. That indirect call
could not be inlined into GenTreeVisitor::WalkTree and, on Windows, went
through a Control Flow Guard dispatch stub per node.
Convert the remaining users to direct GenTreeVisitor implementations and
delete fgWalkTreePre, fgWalkTreePost, fgWalkTree, fgWalkAllTreesPre,
GenericTreeWalker, fgWalkData and the fgWalkPreFn/fgWalkPostFn typedefs.
Several parameters turned out to be already dead and are gone with them:
GenericTreeWalker hardcoded ComputeStack to false and nothing read
fgWalkData::parentStack, so computeStack had no effect; lclVarsOnly had no
remaining users; and fgWalkData::printModified was never set. The unused
fgSplitPredicate typedef is removed as well.
gtHasCatchArg is reimplemented on the existing gtFindNodeInTree helper.
Descending only into subtrees with GTF_ORDER_SIDEEFF preserves its previous
root-level early-out and additionally prunes at every level; GT_CATCH_ARG
sets that flag on itself and effect flags propagate to parents, so a subtree
without it cannot contain one.
SuperPMI asmdiffs over all 11 windows-x64 collections show no diffs.
Throughput on benchmarks.run, measured as instructions retired: -1.94% for
the checked JIT and -0.33% for release built with NoPgoOptimize. A default
release build instead shows +0.19%, because the checked-in PGO profile is
trained on the old code shape.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 064035bf-fb1f-450e-afd2-08a7700aa736
CopilotAI lite review requested due to automatic review settings August 18, 2026 14:12
@github-actionsgithub-actionsBot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Aug 18, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors CoreCLR JIT IR tree walking by replacing the legacy fgWalkTreePre/fgWalkTreePost/fgWalkTree* function-pointer callback mechanism with direct GenTreeVisitor implementations, and removes the associated callback/walker infrastructure. It also reworks a few helpers that previously used fgWalkTree* (e.g., gtHasCatchArg) to use existing visitor/find-node helpers.

Changes:

  • Convert remaining fgWalkTree* users to dedicated GenTreeVisitor types across multiple JIT passes (morph, loop cloning, assertion prop, diagnostics, etc.).
  • Delete the fgWalkTree* APIs and supporting types (fgWalkData, GenericTreeWalker, callback typedefs) from compiler.h / compiler.hpp.
  • Reimplement gtHasCatchArg via gtFindNodeInTree with pruning based on GTF_ORDER_SIDEEFF.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
FileDescription
src/coreclr/jit/rangecheckcloning.cppReplace debug-only bounds-check search walk with a small GenTreeVisitor.
src/coreclr/jit/morph.cppReplace colon-conditional marking walk with a dedicated visitor.
src/coreclr/jit/loopcloning.cppReplace loop cloning profitability/tree scanning callback with a visitor.
src/coreclr/jit/lclvars.cppReplace lcl-fld stress walker callback with a visitor and a member helper.
src/coreclr/jit/indirectcalltransformer.cppReplace debug validation callback with a visitor.
src/coreclr/jit/importercalls.cppReplace ret_expr spill callback with a GenTreeVisitor helper.
src/coreclr/jit/gentree.cppReplace colon-cond clearing walk; reimplement gtHasCatchArg via gtFindNodeInTree.
src/coreclr/jit/fgopt.cppReplace node-counting callback with a visitor.
src/coreclr/jit/fginline.cppReplace debug inline-candidate validation walks with visitors (adds a friend for one case).
src/coreclr/jit/fgdiagnostic.cppReplace debug stress-mul and uniqueness-check callbacks with visitors.
src/coreclr/jit/compiler.hppRemove inline implementations of fgWalkTreePre/Post/Tree and related helpers.
src/coreclr/jit/compiler.hRemove declarations/types for the deleted walkers; add Mark/ClearColonCondVisitor in-header visitors.

Comment threadsrc/coreclr/jit/assertionprop.cpp
CopilotAI review requested due to automatic review settings August 18, 2026 14:29

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.

CopilotAI review requested due to automatic review settings August 18, 2026 14:38

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.

@jakobbotsch

Copy link
Copy Markdown
MemberAuthor

cc @dotnet/jit-contrib PTAL @EgorBo

No diffs. TP improvements in release and bigger ones in checked.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@EgorBoEgorBo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice!

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings August 19, 2026 13:25

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.

@jakobbotsch
jakobbotsch merged commit 979e1ef into dotnet:mainAug 20, 2026
128 checks passed
@jakobbotsch
jakobbotsch deleted the jit-remove-fgwalktree branch August 20, 2026 15:15
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@jakobbotsch@EgorBo