-
Notifications
You must be signed in to change notification settings - Fork 5.2k
JIT: Devirtualize generic virtual methods #122023
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
base: main
Are you sure you want to change the base?
Conversation
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
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 enables devirtualization support for generic virtual methods in the JIT compiler, allowing calls to generic virtual methods to be devirtualized when the exact type is known at JIT time. This optimization eliminates virtual dispatch overhead and enables further optimizations like inlining.
Key changes:
- Removes the assertion that previously blocked generic method devirtualization
- Generalizes array interface devirtualization to support generic virtual methods by renaming
wasArrayInterfaceDevirttoneedsMethodContext - Adds runtime lookup support for generic method instantiation parameters
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/vm/jitinterface.cpp | Removes assertion blocking generic method devirtualization and adds logic to handle generic virtual methods using FindOrCreateAssociatedMethodDesc |
| src/coreclr/inc/corinfo.h | Renames wasArrayInterfaceDevirt to needsMethodContext to generalize the field meaning |
| src/coreclr/jit/jitconfigvalues.h | Adds JitEnableGenericVirtualDevirtualization configuration flag to control the feature |
| src/coreclr/jit/gentree.h | Adds IsGenericVirtual() helper method to identify generic virtual method calls |
| src/coreclr/jit/gentree.cpp | Updates IsDevirtualizationCandidate() to include generic virtual methods (non-AOT only) |
| src/coreclr/jit/importercalls.cpp | Implements devirtualization logic for generic virtual methods including runtime lookup handling, updates comments and variable names, and introduces DEVIRT label for control flow |
| src/coreclr/jit/inline.h | Renames arrayInterface field to needsMethodContext in InlineCandidateInfo struct |
| src/coreclr/jit/indirectcalltransformer.cpp | Updates to use renamed needsMethodContext field |
| src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs | Updates managed struct definition to match renamed field |
| src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs | Updates to use renamed field in managed implementation |
| src/coreclr/tools/superpmi/superpmi-shared/agnostic.h | Updates SuperPMI data structure with renamed field |
| src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp | Updates SuperPMI recording/replay to use renamed field |
530e75d to
6e678a5
Compare
|
@MihuBot |
Enable devirtualization support for generic virtual methods.
When we see a base method having a method instantiation, we use
FindOrCreateAssociatedMethodDescto obtain the devirted method. Then we need insert the lookup node to the inst param.Also introduced a jit knob so that it can be turned off at any time.
AOT support is not included in this PR, which needs additional work in managed type system.
Example:
Codegen diff:
Contributes to #112596
cc: @dotnet/jit-contrib