Skip to content

Commit 57f9210

Browse files
committed
fix
1 parent f1f9ca6 commit 57f9210

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

mlir/include/mlir/Analysis/SliceAnalysis.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ void getForwardSlice(Value root, SetVector<Operation *> *forwardSlice,
138138
/// Assuming all local orders match the numbering order:
139139
/// {1, 2, 5, 3, 4, 6}
140140
///
141+
/// This function returns whether the backwards slice was able to be successfully
142+
/// computed, and failure if it was unable to determine the slice.
141143
LogicalResult getBackwardSlice(Operation *op,
142144
SetVector<Operation *> *backwardSlice,
143145
const BackwardSliceOptions &options = {});

mlir/lib/Analysis/SliceAnalysis.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,14 @@ static LogicalResult getBackwardSliceImpl(Operation *op,
9292
if (options.filter && !options.filter(op))
9393
return success();
9494

95-
bool succeeded = true;
96-
9795
auto processValue = [&](Value value) {
9896
if (auto *definingOp = value.getDefiningOp()) {
9997
if (backwardSlice->count(definingOp) == 0)
100-
succeeded &= getBackwardSliceImpl(definingOp, backwardSlice, options)
98+
return getBackwardSliceImpl(definingOp, backwardSlice, options)
10199
.succeeded();
102100
} else if (auto blockArg = dyn_cast<BlockArgument>(value)) {
103101
if (options.omitBlockArguments)
104-
return;
102+
return success();
105103

106104
Block *block = blockArg.getOwner();
107105
Operation *parentOp = block->getParentOp();
@@ -111,17 +109,18 @@ static LogicalResult getBackwardSliceImpl(Operation *op,
111109
if (parentOp && backwardSlice->count(parentOp) == 0) {
112110
if (parentOp->getNumRegions() == 1 &&
113111
llvm::hasSingleElement(parentOp->getRegion(0).getBlocks())) {
114-
succeeded &= getBackwardSliceImpl(parentOp, backwardSlice, options)
115-
.succeeded();
112+
return getBackwardSliceImpl(parentOp, backwardSlice, options);
116113
} else {
117-
succeeded = false;
114+
return failure();
118115
}
119116
}
120117
} else {
121-
llvm_unreachable("No definingOp and not a block argument.");
118+
return failure()
122119
}
123120
};
124121

122+
bool succeeded = true;
123+
125124
if (!options.omitUsesFromAbove) {
126125
llvm::for_each(op->getRegions(), [&](Region &region) {
127126
// Walk this region recursively to collect the regions that descend from
@@ -132,8 +131,11 @@ static LogicalResult getBackwardSliceImpl(Operation *op,
132131
region.walk([&](Operation *op) {
133132
for (OpOperand &operand : op->getOpOperands()) {
134133
if (!descendents.contains(operand.get().getParentRegion()))
135-
processValue(operand.get());
134+
if (!processValue(operand.get()).succeeded()) {
135+
return WalkResult::interrupt();
136+
}
136137
}
138+
return WalkResult::advance();
137139
});
138140
});
139141
}

0 commit comments

Comments
 (0)