Skip to content
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

Ssa: Refactor shared SSA in preparation for eliminating phi-read definitions #18819

Merged
merged 30 commits into from
Feb 21, 2025

Conversation

aschackmull
Copy link
Contributor

I want to reinterpret phi-reads as reads rather than definitions and hide them from the exposed interface of the SSA library. For normal SSA usage they should be irrelevant: they're only useful for getting an optimised use-use step relation, in particular for use in data-flow.

This PR leaves most of the existing implementation intact, but adds alternative predicates and switches the internal implementation of several others in preparation for this change.

The PR is structured as a long sequence of individually simple commits, so commit-by-commit review is very much encouraged.

There's more work to come, but each of the commits should make sense on their own, and I'd gathered so many that I wanted to merge them to main before adding too many more.

This yields a tiny bit of additional tuples consistent with the prior
Java implementation.
@aschackmull aschackmull added the no-change-note-required This PR does not need a change note label Feb 20, 2025
@Copilot Copilot bot review requested due to automatic review settings February 20, 2025 09:05
@aschackmull aschackmull requested review from a team as code owners February 20, 2025 09:05
@github-actions github-actions bot added C# Java Ruby Rust Pull requests that update Rust code labels Feb 20, 2025
@aschackmull aschackmull requested a review from hvitved February 20, 2025 09:05
Copilot

This comment was marked as off-topic.

This is a result of the bugfix in the commit named
"C#/Ruby/Rust: Fix bug in adjacentReadPairSameVar"
Copy link
Contributor

@hvitved hvitved left a comment

Choose a reason for hiding this comment

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

Thanks a lot for making this PR reviewable in individual commits. I have just two questions. Also, remember DCA.

* Holds if we should synthesize a pseudo-read of `v` at the beginning of `bb`.
*
* These reads are named phi-reads, since they are constructed in the same
* way as ordinary phi nodes except all all reads are treated as potential
Copy link
Contributor

Choose a reason for hiding this comment

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

remove the extra all.

Comment on lines 370 to 371
variableWrite(bb, i, v, false) and
k = SsaActualRead()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is it that we have "pseudo-reads associated with uncertain writes"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes it much simpler to calculate uncertainWriteDefinitionInput.

BasicBlock bb1, int i1, BasicBlock bb2, int i2, SourceVariable v, boolean samevar
) {
adjacentRefs(bb1, i1, bb2, i2, v) and
variableRead(bb2, i2, v, _) and
Copy link
Contributor

Choose a reason for hiding this comment

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

The QL doc mentions certain read, so should _ be true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That should be implied and hence an unnecessary join due to the restriction in ssaRef to only include certain reads.

Comment on lines +466 to +467
variableWrite(bb, i, v, false) and
k = Read()
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand now, per your comment, why this case is needed for uncertainWriteDefinitionInput in SsaDefReachesNew. Why is it needed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Once we've added phi-read nodes, the use-use calculation can be done in exactly the same way as def-use: Any non-phi reference will be dominated by the prior reference. So for actual reads and uncertain writes there exist a unique previous reference, which we calculate in adjacentRefRead, and including k = Read() for uncertain writes make it easy to include those cases that way in adjacentRefRead. And note that we subsequently need those when we calculate the samevar=false flavour of use-use pairs in firstUseAfterRef, which exactly skips forward over references that aren't actual certain reads.

@aschackmull aschackmull merged commit 1c616d1 into github:main Feb 21, 2025
54 checks passed
@aschackmull aschackmull deleted the ssa/refactor-phiread3 branch February 21, 2025 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C# Java no-change-note-required This PR does not need a change note Ruby Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants