-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[mlir][Analysis] Remove return value from getBackwardSlice
#163749
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
Open
matthias-springer
wants to merge
1
commit into
main
Choose a base branch
from
users/matthias-springer/simplify_backward_slice
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -105,52 +105,47 @@ void mlir::getForwardSlice(Value root, SetVector<Operation *> *forwardSlice, | |
forwardSlice->insert(v.rbegin(), v.rend()); | ||
} | ||
|
||
static LogicalResult getBackwardSliceImpl(Operation *op, | ||
DenseSet<Operation *> &visited, | ||
SetVector<Operation *> *backwardSlice, | ||
const BackwardSliceOptions &options) { | ||
static void getBackwardSliceImpl(Operation *op, DenseSet<Operation *> &visited, | ||
SetVector<Operation *> *backwardSlice, | ||
const BackwardSliceOptions &options) { | ||
if (!op) | ||
return success(); | ||
return; | ||
|
||
// Evaluate whether we should keep this def. | ||
// This is useful in particular to implement scoping; i.e. return the | ||
// transitive backwardSlice in the current scope. | ||
if (options.filter && !options.filter(op)) | ||
return success(); | ||
return; | ||
|
||
auto processValue = [&](Value value) { | ||
if (auto *definingOp = value.getDefiningOp()) { | ||
if (backwardSlice->count(definingOp) == 0 && | ||
visited.insert(definingOp).second) | ||
return getBackwardSliceImpl(definingOp, visited, backwardSlice, | ||
options); | ||
visited.insert(definingOp).second) { | ||
getBackwardSliceImpl(definingOp, visited, backwardSlice, options); | ||
return; | ||
} | ||
|
||
visited.erase(definingOp); | ||
} else if (auto blockArg = dyn_cast<BlockArgument>(value)) { | ||
if (options.omitBlockArguments) | ||
return success(); | ||
|
||
Block *block = blockArg.getOwner(); | ||
Operation *parentOp = block->getParentOp(); | ||
// TODO: determine whether we want to recurse backward into the other | ||
// blocks of parentOp, which are not technically backward unless they flow | ||
// into us. For now, just bail. | ||
if (parentOp && backwardSlice->count(parentOp) == 0) { | ||
if (!parentOp->hasTrait<OpTrait::IsIsolatedFromAbove>() && | ||
parentOp->getNumRegions() == 1 && | ||
parentOp->getRegion(0).hasOneBlock()) { | ||
return getBackwardSliceImpl(parentOp, visited, backwardSlice, | ||
options); | ||
} | ||
return; | ||
} | ||
auto blockArg = cast<BlockArgument>(value); | ||
if (options.omitBlockArguments) | ||
return; | ||
|
||
Block *block = blockArg.getOwner(); | ||
Operation *parentOp = block->getParentOp(); | ||
// TODO: determine whether we want to recurse backward into the other | ||
// blocks of parentOp, which are not technically backward unless they flow | ||
// into us. For now, just bail. | ||
if (parentOp && backwardSlice->count(parentOp) == 0) { | ||
if (!parentOp->hasTrait<OpTrait::IsIsolatedFromAbove>() && | ||
parentOp->getNumRegions() == 1 && | ||
parentOp->getRegion(0).hasOneBlock()) { | ||
getBackwardSliceImpl(parentOp, visited, backwardSlice, options); | ||
} | ||
} else { | ||
return failure(); | ||
} | ||
return success(); | ||
}; | ||
|
||
bool succeeded = true; | ||
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. Note: This variable is always |
||
|
||
if (!options.omitUsesFromAbove && | ||
!op->hasTrait<OpTrait::IsIsolatedFromAbove>()) { | ||
llvm::for_each(op->getRegions(), [&](Region ®ion) { | ||
|
@@ -162,44 +157,38 @@ static LogicalResult getBackwardSliceImpl(Operation *op, | |
region.walk([&](Operation *op) { | ||
for (OpOperand &operand : op->getOpOperands()) { | ||
if (!descendents.contains(operand.get().getParentRegion())) | ||
if (!processValue(operand.get()).succeeded()) { | ||
return WalkResult::interrupt(); | ||
} | ||
processValue(operand.get()); | ||
} | ||
return WalkResult::advance(); | ||
}); | ||
}); | ||
} | ||
llvm::for_each(op->getOperands(), processValue); | ||
|
||
backwardSlice->insert(op); | ||
return success(succeeded); | ||
} | ||
|
||
LogicalResult mlir::getBackwardSlice(Operation *op, | ||
SetVector<Operation *> *backwardSlice, | ||
const BackwardSliceOptions &options) { | ||
void mlir::getBackwardSlice(Operation *op, | ||
SetVector<Operation *> *backwardSlice, | ||
const BackwardSliceOptions &options) { | ||
DenseSet<Operation *> visited; | ||
visited.insert(op); | ||
LogicalResult result = | ||
getBackwardSliceImpl(op, visited, backwardSlice, options); | ||
getBackwardSliceImpl(op, visited, backwardSlice, options); | ||
|
||
if (!options.inclusive) { | ||
// Don't insert the top level operation, we just queried on it and don't | ||
// want it in the results. | ||
backwardSlice->remove(op); | ||
} | ||
return result; | ||
} | ||
|
||
LogicalResult mlir::getBackwardSlice(Value root, | ||
SetVector<Operation *> *backwardSlice, | ||
const BackwardSliceOptions &options) { | ||
void mlir::getBackwardSlice(Value root, SetVector<Operation *> *backwardSlice, | ||
const BackwardSliceOptions &options) { | ||
if (Operation *definingOp = root.getDefiningOp()) { | ||
return getBackwardSlice(definingOp, backwardSlice, options); | ||
getBackwardSlice(definingOp, backwardSlice, options); | ||
return; | ||
} | ||
Operation *bbAargOwner = cast<BlockArgument>(root).getOwner()->getParentOp(); | ||
return getBackwardSlice(bbAargOwner, backwardSlice, options); | ||
Operation *bbArgOwner = cast<BlockArgument>(root).getOwner()->getParentOp(); | ||
getBackwardSlice(bbArgOwner, backwardSlice, options); | ||
} | ||
|
||
SetVector<Operation *> | ||
|
@@ -215,10 +204,7 @@ mlir::getSlice(Operation *op, const BackwardSliceOptions &backwardSliceOptions, | |
auto *currentOp = (slice)[currentIndex]; | ||
// Compute and insert the backwardSlice starting from currentOp. | ||
backwardSlice.clear(); | ||
LogicalResult result = | ||
getBackwardSlice(currentOp, &backwardSlice, backwardSliceOptions); | ||
assert(result.succeeded()); | ||
(void)result; | ||
getBackwardSlice(currentOp, &backwardSlice, backwardSliceOptions); | ||
slice.insert_range(backwardSlice); | ||
|
||
// Compute and insert the forwardSlice starting from currentOp. | ||
|
@@ -241,9 +227,7 @@ static bool dependsOnCarriedVals(Value value, | |
sliceOptions.filter = [&](Operation *op) { | ||
return !ancestorOp->isAncestor(op); | ||
}; | ||
LogicalResult result = getBackwardSlice(value, &slice, sliceOptions); | ||
assert(result.succeeded()); | ||
(void)result; | ||
getBackwardSlice(value, &slice, sliceOptions); | ||
|
||
// Check that none of the operands of the operations in the backward slice are | ||
// loop iteration arguments, and neither is the value itself. | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
Note that this case can never happen: An SSA value is always either an OpResult or a BlockArgument.