Skip to content

[region-isolation] Include the region -> transferring operand map in the dataflow convergence. #72955

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 3 commits into from
Apr 11, 2024

Conversation

gottesmm
Copy link
Contributor

@gottesmm gottesmm commented Apr 10, 2024

This PR contains a few different that add up to doing the title of the PR.

Specifically:

Changing the representation of the region -> transferring operand map from a SmallDenseMap to a SmallMapVector

The first commit changes our representation of the region -> transferring
operand map from a SmallDenseMap to a SmallMapVector. I am doing this since to
do the dataflow convergence, I need to check for equality implying I would need
to traverse the map and iterating over a hash table can lead to performance
issues.

Refactoring the region -> transferring operand map to use bare Operand * instead of TransferringOperand *.

In the second commit, I refactored the region -> transferring operand map such
that it just tracks bare operands and eliminated the transferring operand
abstraction in favor of just storing a global map from operand -> extra
transferring state.

Originally, we mapped a region number to an immutable pointer set containing
Operand * where the region was tranferred. This worked great for a time... until
I began to need to propagate other information from the transferring code in the
analysis to the actual diagnostic emitter.

To be able to do that, my thought was to make a wrapper type around Operand
called TransferringOperand that contained the operand and the other information
I needed. This seemed to provide me what I wanted but I later found that since
the immutable pointer set was tracking TransferringOperands which were always
newly wrapped with an Operand *, we actually always created new pointer
sets. This is of course wasteful from a memory perspective, but also prevents me
from tracking transferring operand sets during the dataflow since we would never
converge.

Include the region -> transferring operand map in the dataflow convergence.

The reason why I am doing this is that really we are running two different
dataflow equations at the same time... one for propagating tracking transferring
sets and the other for propagating regions. Since at the source level the two
dataflow problems are very interrelated, I was unable to come up with an example
where we fail to iterate because of this, but I would like to be sure that we do
not hit one, so I am fixing this here.

rdar://126170014

gottesmm added 3 commits April 9, 2024 10:56
…se a MapVector instead of a DenseMap.

This ensures that we can efficiently iterate over the map which we will need to
do for equality queries.

I am going to add the equality queries in a subsequent commit. Just chopping off
a larger commit.
…nline in a TransferringOperand data structure.

This is backing out an approach that I thought would be superior, but ended up
causing problems.

Originally, we mapped a region number to an immutable pointer set containing
Operand * where the region was tranferred. This worked great for a time... until
I began to need to propagate other information from the transferring code in the
analysis to the actual diagnostic emitter.

To be able to do that, my thought was to make a wrapper type around Operand
called TransferringOperand that contained the operand and the other information
I needed. This seemed to provide me what I wanted but I later found that since
the immutable pointer set was tracking TransferringOperands which were always
newly wrapped with an Operand *, we actually always created new pointer
sets. This is of course wasteful from a memory perspective, but also prevents me
from tracking transferring operand sets during the dataflow since we would never
converge.

In this commit, I fix that issue by again tracking just an Operand * in the
TransferringOperandSet and instead map each operand to a state structure which
we merge dataflow state into whenever we visit it. This provides us with
everything we need to in the next commit to including a region -> transferring
operand set equality check in our dataflow equations and always converge.
…the dataflow convergence.

The reason why I am doing this is that really we are running two different
dataflow equations at the same time... one for propagating tracking transferring
sets and the other for propagating regions. Since at the source level the two
dataflow problems are very interrelated, I was unable to come up with an example
where we fail to iterate because of this, but I would like to be sure that we do
not hit one, so I am fixing this here.

rdar://126170014
@gottesmm gottesmm requested a review from ktoso as a code owner April 10, 2024 17:44
@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

@gottesmm gottesmm enabled auto-merge April 10, 2024 20:12
@gottesmm
Copy link
Contributor Author

Windows failure was a timeout in Foundation that is unrelated.

@gottesmm
Copy link
Contributor Author

@swift-ci test windows platform

@gottesmm gottesmm merged commit df4fb64 into swiftlang:main Apr 11, 2024
@gottesmm gottesmm deleted the rdar126170014 branch April 11, 2024 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant