-
Notifications
You must be signed in to change notification settings - Fork 5.2k
JIT: Rework *ComplexityExceeds
helpers to take caller-defined complexity computation
#118046
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
JIT: Rework *ComplexityExceeds
helpers to take caller-defined complexity computation
#118046
Conversation
There was a problem hiding this comment.
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 the complexity checking system in the JIT compiler to use callback functions instead of hardcoded node counting. The change allows for more flexible complexity computations while maintaining the current behavior of counting tree nodes as the default complexity metric.
Key changes:
- Converted
gtComplexityExceeds
and related functions to use template parameters with callback functions - Moved complexity checking implementations from
.cpp
files to header files as templates - Updated all call sites to provide lambda functions that maintain existing node-counting behavior
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
src/coreclr/jit/compiler.h |
Updated function signatures to use template parameters for complexity callbacks |
src/coreclr/jit/compiler.hpp |
Added template implementations of complexity checking functions |
src/coreclr/jit/block.h |
Updated ComplexityExceeds method signatures to use template parameters |
src/coreclr/jit/block.cpp |
Removed concrete implementations that were moved to header as templates |
src/coreclr/jit/gentree.cpp |
Removed original gtComplexityExceeds implementation |
src/coreclr/jit/optimizer.cpp |
Updated call site and removed optLoopComplexityExceeds implementation |
src/coreclr/jit/objectalloc.cpp |
Updated call site with lambda callback |
src/coreclr/jit/morph.cpp |
Updated call sites with lambda callbacks |
src/coreclr/jit/loopcloning.cpp |
Updated call site with lambda callback |
src/coreclr/jit/forwardsub.cpp |
Updated call sites with lambda callbacks |
src/coreclr/jit/rangecheckcloning.cpp |
Updated call site with lambda callback that also updates external counter |
Comments suppressed due to low confidence (1)
src/coreclr/jit/rangecheckcloning.cpp:447
- [nitpick] The lambda parameter name 'tree' is inconsistent with other similar lambdas in the codebase that use 'node' as the parameter name.
auto countNode = [&actual](GenTree* tree) -> unsigned {
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
@dotnet/jit-contrib PTAL. No diffs. Thanks! |
/ba-g #118064 |
Allow
Compiler::gtComplexityExceeds
et al to compute the complexity of a tree as something other than the count of its nodes by relying on a callback function. We don't diverge from this definition of complexity anywhere at the moment, though this means callers can compute additional information, like the total node count for a block or loop, without needing out parameters by simply including such computations in the callback. I was motivated to do this by a want for additional insight into the optimization potential of loop inversion candidates, like whether a loop might also benefit from cloning because it contains bounds checks. Such information can be included in the callback to the complexity check.In the near future, we might want to diverge from the number of nodes in a code segment as our definition of complexity and employ something more sophisticated. These changes should make that easy to try out.