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

Skip to content

JIT: refactor escape analysis to be more bv-centric #115213

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
merged 1 commit into from
May 4, 2025

Conversation

AndyAyersMS
Copy link
Member

@AndyAyersMS AndyAyersMS commented May 1, 2025

Make the "bv index" the primary concept for computations; translate
from local var nums to their indices when needed.

Allocate all the connection BVs at once, since the connection matrix
will now have a dense set of entries.

This is prep work for tracking fields of stack allocatable objects,
where we will introduce new classes of things tracked by the
connection graph.

@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 1, 2025
Copy link
Contributor

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

Make the "bv index" the primary concept for computations; translate
from local var nums to their indices when needed.

Allocate all the connection BVs at once, since the connection matrix
will now have a dense set of entries.

This is prep work for tracking fields of stack allocatable objects,
where we will introduce new classes of things tracked by the
connection graph.
@AndyAyersMS AndyAyersMS changed the title refactor JIT: refactor escape analysis to be more bv-centric May 1, 2025
@AndyAyersMS AndyAyersMS marked this pull request as ready for review May 1, 2025 18:50
@Copilot Copilot AI review requested due to automatic review settings May 1, 2025 18:50
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 focus on bitvector (bv) indices rather than local variable numbers. Key changes include renaming pseudo-local variables to pseudo-indices, replacing HasIndex with IsTrackedLocal in escape checks, and introducing new index-based functions for stack allocation analysis.

Comments suppressed due to low confidence (1)

src/coreclr/jit/objectalloc.h:187

  • The parameter name 'lclNum' in MarkIndexAsEscaping is inconsistent with other index-based functions; consider renaming it to 'index' for clarity.
void         MarkIndexAsEscaping(unsigned int lclNum);

@AndyAyersMS
Copy link
Member Author

AndyAyersMS commented May 1, 2025

PTAL @dotnet/jit-contrib

No diffs.

Likely somewhat tedious to review. Quite a bit of renaming (eg "pseudo var/local" - > "pseudo"), and trying to consistently use BV indices to describe non-local things, and to use DumpIndex to describe what the bv bits mean.

Small TP win as we no longer repeatedly translate back and forth from local to index, eg in ComputeStackObjectPointers

Diffs

I reran this because of some infra issues, so the diff report has duplicated sections.

@@ -360,9 +373,9 @@ void ObjectAllocator::PrepareAnalysis()
//
// If conditional escape analysis is enabled, we reserve the range [N...N+M-1]
// for locals allocated during the conditional escape analysis expansions,
// where N is the maximum number of pseudo-vars.
// where N is the maximum number of pseudos.
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you mean M?

Suggested change
// where N is the maximum number of pseudos.
// where M is the maximum number of pseudos.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah. I will fix that in a subsequent PR, if there isn't any other feedback here.

@AndyAyersMS
Copy link
Member Author

@dotnet/jit-contrib ping

//
BitVec pseudoLocalAdjacencies = m_ConnGraphAdjacencyMatrix[LocalToIndex(pseudoLocal)];
BitVec PseudoAdjacencies = m_ConnGraphAdjacencyMatrix[pseudoIndex];
Copy link
Member

@jakobbotsch jakobbotsch May 4, 2025

Choose a reason for hiding this comment

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

Nit: naming conventions

Copy link
Member Author

Choose a reason for hiding this comment

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

Will fix this in the next stage...

Copy link
Member

@jakobbotsch jakobbotsch left a comment

Choose a reason for hiding this comment

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

LGTM. Looks simpler now without the multiple numbering schemes.

I didn't see it here, but do we limit the sizes of the bit vectors we create somewhere? Seems we should do that since the closure computation is inherently superlinear.

@AndyAyersMS
Copy link
Member Author

LGTM. Looks simpler now without the multiple numbering schemes.

I didn't see it here, but do we limit the sizes of the bit vectors we create somewhere? Seems we should do that since the closure computation is inherently superlinear.

No limits right now (other than implicitly limited by the number of escape-tracked locals). I can add something similar to the limit we have for regular tracked locals.

@AndyAyersMS AndyAyersMS merged commit 712b3fc into dotnet:main May 4, 2025
110 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.

3 participants