@@ -80,43 +80,41 @@ void mlir::getForwardSlice(Value root, SetVector<Operation *> *forwardSlice,
8080 forwardSlice->insert (v.rbegin (), v.rend ());
8181}
8282
83- static LogicalResult getBackwardSliceImpl (Operation *op,
84- SetVector<Operation *> *backwardSlice,
85- const BackwardSliceOptions &options) {
83+ static void getBackwardSliceImpl (Operation *op,
84+ SetVector<Operation *> *backwardSlice,
85+ const BackwardSliceOptions &options) {
8686 if (!op || op->hasTrait <OpTrait::IsIsolatedFromAbove>())
87- return success () ;
87+ return ;
8888
8989 // Evaluate whether we should keep this def.
9090 // This is useful in particular to implement scoping; i.e. return the
9191 // transitive backwardSlice in the current scope.
9292 if (options.filter && !options.filter (op))
93- return success () ;
93+ return ;
9494
9595 auto processValue = [&](Value value) {
9696 if (auto *definingOp = value.getDefiningOp ()) {
9797 if (backwardSlice->count (definingOp) == 0 )
98- return getBackwardSliceImpl (definingOp, backwardSlice, options);
98+ getBackwardSliceImpl (definingOp, backwardSlice, options);
9999 } else if (auto blockArg = dyn_cast<BlockArgument>(value)) {
100100 if (options.omitBlockArguments )
101- return success () ;
101+ return ;
102102
103103 Block *block = blockArg.getOwner ();
104104 Operation *parentOp = block->getParentOp ();
105105 // TODO: determine whether we want to recurse backward into the other
106106 // blocks of parentOp, which are not technically backward unless they flow
107107 // into us. For now, just bail.
108108 if (parentOp && backwardSlice->count (parentOp) == 0 ) {
109- if (parentOp->getNumRegions () == 1 &&
110- llvm::hasSingleElement (parentOp->getRegion (0 ).getBlocks ())) {
111- return getBackwardSliceImpl (parentOp, backwardSlice, options);
112- }
109+ assert (parentOp->getNumRegions () == 1 &&
110+ llvm::hasSingleElement (parentOp->getRegion (0 ).getBlocks ()));
111+ getBackwardSliceImpl (parentOp, backwardSlice, options);
113112 }
113+ } else {
114+ llvm_unreachable (" No definingOp and not a block argument." );
114115 }
115- return failure ();
116116 };
117117
118- bool succeeded = true ;
119-
120118 if (!options.omitUsesFromAbove ) {
121119 llvm::for_each (op->getRegions (), [&](Region ®ion) {
122120 // Walk this region recursively to collect the regions that descend from
@@ -127,41 +125,36 @@ static LogicalResult getBackwardSliceImpl(Operation *op,
127125 region.walk ([&](Operation *op) {
128126 for (OpOperand &operand : op->getOpOperands ()) {
129127 if (!descendents.contains (operand.get ().getParentRegion ()))
130- if (!processValue (operand.get ()).succeeded ()) {
131- return WalkResult::interrupt ();
132- }
128+ processValue (operand.get ());
133129 }
134- return WalkResult::advance ();
135130 });
136131 });
137132 }
138133 llvm::for_each (op->getOperands (), processValue);
139134
140135 backwardSlice->insert (op);
141- return success (succeeded);
142136}
143137
144- LogicalResult mlir::getBackwardSlice (Operation *op,
145- SetVector<Operation *> *backwardSlice,
146- const BackwardSliceOptions &options) {
147- LogicalResult result = getBackwardSliceImpl (op, backwardSlice, options);
138+ void mlir::getBackwardSlice (Operation *op,
139+ SetVector<Operation *> *backwardSlice,
140+ const BackwardSliceOptions &options) {
141+ getBackwardSliceImpl (op, backwardSlice, options);
148142
149143 if (!options.inclusive ) {
150144 // Don't insert the top level operation, we just queried on it and don't
151145 // want it in the results.
152146 backwardSlice->remove (op);
153147 }
154- return result;
155148}
156149
157- LogicalResult mlir::getBackwardSlice (Value root,
158- SetVector<Operation *> *backwardSlice,
159- const BackwardSliceOptions &options) {
150+ void mlir::getBackwardSlice (Value root, SetVector<Operation *> *backwardSlice,
151+ const BackwardSliceOptions &options) {
160152 if (Operation *definingOp = root.getDefiningOp ()) {
161- return getBackwardSlice (definingOp, backwardSlice, options);
153+ getBackwardSlice (definingOp, backwardSlice, options);
154+ return ;
162155 }
163156 Operation *bbAargOwner = cast<BlockArgument>(root).getOwner ()->getParentOp ();
164- return getBackwardSlice (bbAargOwner, backwardSlice, options);
157+ getBackwardSlice (bbAargOwner, backwardSlice, options);
165158}
166159
167160SetVector<Operation *>
@@ -177,9 +170,7 @@ mlir::getSlice(Operation *op, const BackwardSliceOptions &backwardSliceOptions,
177170 auto *currentOp = (slice)[currentIndex];
178171 // Compute and insert the backwardSlice starting from currentOp.
179172 backwardSlice.clear ();
180- LogicalResult result =
181- getBackwardSlice (currentOp, &backwardSlice, backwardSliceOptions);
182- assert (result.succeeded ());
173+ getBackwardSlice (currentOp, &backwardSlice, backwardSliceOptions);
183174 slice.insert_range (backwardSlice);
184175
185176 // Compute and insert the forwardSlice starting from currentOp.
@@ -202,8 +193,7 @@ static bool dependsOnCarriedVals(Value value,
202193 sliceOptions.filter = [&](Operation *op) {
203194 return !ancestorOp->isAncestor (op);
204195 };
205- LogicalResult result = getBackwardSlice (value, &slice, sliceOptions);
206- assert (result.succeeded ());
196+ getBackwardSlice (value, &slice, sliceOptions);
207197
208198 // Check that none of the operands of the operations in the backward slice are
209199 // loop iteration arguments, and neither is the value itself.
0 commit comments