Thanks to visit codestin.com
Credit goes to github.com

Skip to content

JIT: more bv-centric refactoring for escape analysis #115291

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

Merged

Conversation

AndyAyersMS
Copy link
Member

Rework connection graph building in anticipation of having potentially different sorts of escapes happen as we walk up a tree and switch which resource we are tracking.

For example we may discover that a local doesn't escape in this tree, but its fields can escape.

Make the ancestor walk responsible for recording escapes, instead of deferring to its caller.

Also address a few small things deferred from the previous refactor.

Rework connection graph building in anticipation of having
potentially different sorts of escapes happen as we walk up a tree
and switch which resource we are tracking.

For example we may discover that a local doesn't escape in this tree,
but its fields can escape.

Make the ancestor walk responsible for recording escapes, instead
of deferring to its caller.

Also address a few small things deferred from the previous refactor.
@Copilot Copilot AI review requested due to automatic review settings May 5, 2025 00:41
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label May 5, 2025
Copy link
Contributor

@Copilot Copilot AI left a 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 escape analysis in the JIT to be more bit-vector–centric, reworking the connection graph building and the handling of escapes when traversing the tree.

  • Replaces the local escape checks with a new index-based approach
  • Renames and refactors functions from CanLclVarEscapeViaParentStack to AnalyzeParentStack for clearer responsibility
  • Updates related JIT diagnostic messages and connection graph edge additions

Reviewed Changes

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

File Description
src/coreclr/jit/objectalloc.h Added new API CanIndexEscape with associated inline implementation
src/coreclr/jit/objectalloc.cpp Refactored escape analysis flow to use the new index-based methods
Comments suppressed due to low confidence (1)

src/coreclr/jit/objectalloc.cpp:619

  • The condition was changed from checking if the local can escape to verifying if the local is tracked. Please confirm that this inversion correctly reflects the intended logic for escape analysis.
if (!m_allocator->IsTrackedLocal(lclNum))

bool ObjectAllocator::CanLclVarEscapeViaParentStack(ArrayStack<GenTree*>* parentStack,
unsigned int lclNum,
BasicBlock* block)
void ObjectAllocator::AnalyzeParentStack(ArrayStack<GenTree*>* parentStack, unsigned int lclIndex, BasicBlock* block)
{
assert(parentStack != nullptr);
Copy link
Preview

Copilot AI May 5, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider adding a clarifying comment explaining why it is asserted that the local index must not already be marked as escaping at this point.

Suggested change
assert(parentStack != nullptr);
assert(parentStack != nullptr);
// At this point, it is guaranteed that the local index (lclIndex) has not been marked as escaping.
// This is because AnalyzeParentStack is only called for tracked, unescaped locals, and the logic
// leading to this point ensures that no escaping has occurred. The assertion acts as a safeguard
// to verify this invariant.

Copilot uses AI. Check for mistakes.

Copy link
Contributor

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

@AndyAyersMS
Copy link
Member Author

@dotnet/jit-contrib PTAL

Should be no diff, perhaps a tiny TP improvement.

I also realized we can see GT_LCL_FLD early on in JIT IR, and we should handle it better. Will do that in a subsequent PR.

@AndyAyersMS
Copy link
Member Author

/ba-g build analysis hanging

@AndyAyersMS AndyAyersMS merged commit 2f3b6e9 into dotnet:main May 5, 2025
105 of 109 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CodeGen-coreclr CLR 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.

2 participants