-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Support cloning loops with array of struct indexing expressions #55612
Merged
BruceForstall
merged 2 commits into
dotnet:main
from
BruceForstall:GeneralizedLoopCloningArrayIndex
Jul 15, 2021
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8533,7 +8533,7 @@ void Compiler::gtUpdateSideEffects(Statement* stmt, GenTree* tree) | |
// | ||
// Arguments: | ||
// tree - Tree to update the side effects for | ||
|
||
// | ||
void Compiler::gtUpdateTreeAncestorsSideEffects(GenTree* tree) | ||
{ | ||
assert(fgStmtListThreaded); | ||
|
@@ -8549,7 +8549,7 @@ void Compiler::gtUpdateTreeAncestorsSideEffects(GenTree* tree) | |
// | ||
// Arguments: | ||
// stmt - The statement to update side effects on | ||
|
||
// | ||
void Compiler::gtUpdateStmtSideEffects(Statement* stmt) | ||
{ | ||
fgWalkTree(stmt->GetRootNodePointer(), fgUpdateSideEffectsPre, fgUpdateSideEffectsPost); | ||
|
@@ -8565,7 +8565,7 @@ void Compiler::gtUpdateStmtSideEffects(Statement* stmt) | |
// This method currently only updates GTF_EXCEPT, GTF_ASG, and GTF_CALL flags. | ||
// The other side effect flags may remain unnecessarily (conservatively) set. | ||
// The caller of this method is expected to update the flags based on the children's flags. | ||
|
||
// | ||
void Compiler::gtUpdateNodeOperSideEffects(GenTree* tree) | ||
{ | ||
if (tree->OperMayThrow(this)) | ||
|
@@ -8600,6 +8600,38 @@ void Compiler::gtUpdateNodeOperSideEffects(GenTree* tree) | |
} | ||
} | ||
|
||
//------------------------------------------------------------------------ | ||
// gtUpdateNodeOperSideEffectsPost: Update the side effects based on the node operation, | ||
// in the post-order visit of a tree walk. It is expected that the pre-order visit cleared | ||
// the bits, so the post-order visit only sets them. This is important for binary nodes | ||
// where one child already may have set the GTF_EXCEPT bit. Note that `SetIndirExceptionFlags` | ||
// looks at its child, which is why we need to do this in a bottom-up walk. | ||
// | ||
// Arguments: | ||
// tree - Tree to update the side effects on | ||
// | ||
// Notes: | ||
// This method currently only updates GTF_ASG, GTF_CALL, and GTF_EXCEPT flags. | ||
// The other side effect flags may remain unnecessarily (conservatively) set. | ||
// | ||
void Compiler::gtUpdateNodeOperSideEffectsPost(GenTree* tree) | ||
{ | ||
if (tree->OperMayThrow(this)) | ||
{ | ||
tree->gtFlags |= GTF_EXCEPT; | ||
} | ||
|
||
if (tree->OperRequiresAsgFlag()) | ||
{ | ||
tree->gtFlags |= GTF_ASG; | ||
} | ||
|
||
if (tree->OperRequiresCallFlag(this)) | ||
{ | ||
tree->gtFlags |= GTF_CALL; | ||
} | ||
} | ||
|
||
//------------------------------------------------------------------------ | ||
// gtUpdateNodeSideEffects: Update the side effects based on the node operation and | ||
// children's side efects. | ||
|
@@ -8608,9 +8640,9 @@ void Compiler::gtUpdateNodeOperSideEffects(GenTree* tree) | |
// tree - Tree to update the side effects on | ||
// | ||
// Notes: | ||
// This method currently only updates GTF_EXCEPT and GTF_ASG flags. The other side effect | ||
// flags may remain unnecessarily (conservatively) set. | ||
|
||
// This method currently only updates GTF_EXCEPT, GTF_ASG, and GTF_CALL flags. | ||
// The other side effect flags may remain unnecessarily (conservatively) set. | ||
// | ||
void Compiler::gtUpdateNodeSideEffects(GenTree* tree) | ||
{ | ||
gtUpdateNodeOperSideEffects(tree); | ||
|
@@ -8627,24 +8659,23 @@ void Compiler::gtUpdateNodeSideEffects(GenTree* tree) | |
|
||
//------------------------------------------------------------------------ | ||
// fgUpdateSideEffectsPre: Update the side effects based on the tree operation. | ||
// The pre-visit walk clears GTF_ASG, GTF_CALL, and GTF_EXCEPT; the post-visit walk sets | ||
// the bits as necessary. | ||
// | ||
// Arguments: | ||
// pTree - Pointer to the tree to update the side effects | ||
// fgWalkPre - Walk data | ||
// | ||
// Notes: | ||
// This method currently only updates GTF_EXCEPT and GTF_ASG flags. The other side effect | ||
// flags may remain unnecessarily (conservatively) set. | ||
|
||
Compiler::fgWalkResult Compiler::fgUpdateSideEffectsPre(GenTree** pTree, fgWalkData* fgWalkPre) | ||
{ | ||
fgWalkPre->compiler->gtUpdateNodeOperSideEffects(*pTree); | ||
GenTree* tree = *pTree; | ||
tree->gtFlags &= ~(GTF_ASG | GTF_CALL | GTF_EXCEPT); | ||
|
||
return WALK_CONTINUE; | ||
} | ||
|
||
//------------------------------------------------------------------------ | ||
// fgUpdateSideEffectsPost: Update the side effects of the parent based on the tree's flags. | ||
// fgUpdateSideEffectsPost: Update the side effects of the node and parent based on the tree's flags. | ||
// | ||
// Arguments: | ||
// pTree - Pointer to the tree | ||
|
@@ -8653,10 +8684,23 @@ Compiler::fgWalkResult Compiler::fgUpdateSideEffectsPre(GenTree** pTree, fgWalkD | |
// Notes: | ||
// The routine is used for updating the stale side effect flags for ancestor | ||
// nodes starting from treeParent up to the top-level stmt expr. | ||
|
||
// | ||
Compiler::fgWalkResult Compiler::fgUpdateSideEffectsPost(GenTree** pTree, fgWalkData* fgWalkPost) | ||
{ | ||
GenTree* tree = *pTree; | ||
GenTree* tree = *pTree; | ||
|
||
// Update the node's side effects first. | ||
fgWalkPost->compiler->gtUpdateNodeOperSideEffectsPost(tree); | ||
|
||
// If this node is an indir or array length, and it doesn't have the GTF_EXCEPT bit set, we | ||
// set the GTF_IND_NONFAULTING bit. This needs to be done after all children, and this node, have | ||
// been processed. | ||
if (tree->OperIsIndirOrArrLength() && ((tree->gtFlags & GTF_EXCEPT) == 0)) | ||
{ | ||
tree->gtFlags |= GTF_IND_NONFAULTING; | ||
} | ||
|
||
// Then update the parent's side effects based on this node. | ||
GenTree* parent = fgWalkPost->parent; | ||
if (parent != nullptr) | ||
{ | ||
|
@@ -9908,9 +9952,16 @@ bool GenTree::Precedes(GenTree* other) | |
// Arguments: | ||
// comp - compiler instance | ||
// | ||
|
||
void GenTree::SetIndirExceptionFlags(Compiler* comp) | ||
{ | ||
assert(OperIsIndirOrArrLength()); | ||
|
||
if (OperMayThrow(comp)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just a refactoring: don't calculate |
||
{ | ||
gtFlags |= GTF_EXCEPT; | ||
return; | ||
} | ||
|
||
GenTree* addr = nullptr; | ||
if (OperIsIndir()) | ||
{ | ||
|
@@ -9922,7 +9973,7 @@ void GenTree::SetIndirExceptionFlags(Compiler* comp) | |
addr = AsArrLen()->ArrRef(); | ||
} | ||
|
||
if (OperMayThrow(comp) || ((addr->gtFlags & GTF_EXCEPT) != 0)) | ||
if ((addr->gtFlags & GTF_EXCEPT) != 0) | ||
{ | ||
gtFlags |= GTF_EXCEPT; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is similar to
gtUpdateNodeOperSideEffects
, but different. I didn't want to touch the other users, and they might actually be doing the right thing as long as they are changing a node whose children are already correct (such as when creating a new node).