1717#include " mlir/Interfaces/SideEffectInterfaces.h"
1818#include " mlir/Support/LLVM.h"
1919#include " mlir/Transforms/RegionUtils.h"
20+ #include " llvm/ADT/STLExtras.h"
2021#include " llvm/ADT/SetVector.h"
2122#include " llvm/ADT/SmallPtrSet.h"
2223
@@ -92,20 +93,13 @@ static void getBackwardSliceImpl(Operation *op,
9293 if (options.filter && !options.filter (op))
9394 return ;
9495
95- auto operands = op->getOperands ();
96- SetVector<Value> valuesToFollow (operands.begin (), operands.end ());
97- if (!options.omitUsesFromAbove ) {
98- getUsedValuesDefinedAbove (op->getRegions (), valuesToFollow);
99- }
100-
101- for (const auto &en : llvm::enumerate (valuesToFollow)) {
102- auto operand = en.value ();
103- if (auto *definingOp = operand.getDefiningOp ()) {
96+ auto processValue = [&](Value value) {
97+ if (auto *definingOp = value.getDefiningOp ()) {
10498 if (backwardSlice->count (definingOp) == 0 )
10599 getBackwardSliceImpl (definingOp, backwardSlice, options);
106- } else if (auto blockArg = dyn_cast<BlockArgument>(operand )) {
100+ } else if (auto blockArg = dyn_cast<BlockArgument>(value )) {
107101 if (options.omitBlockArguments )
108- continue ;
102+ return ;
109103
110104 Block *block = blockArg.getOwner ();
111105 Operation *parentOp = block->getParentOp ();
@@ -120,7 +114,14 @@ static void getBackwardSliceImpl(Operation *op,
120114 } else {
121115 llvm_unreachable (" No definingOp and not a block argument." );
122116 }
117+ };
118+
119+ if (!options.omitUsesFromAbove ) {
120+ visitUsedValuesDefinedAbove (op->getRegions (), [&](OpOperand *operand) {
121+ processValue (operand->get ());
122+ });
123123 }
124+ llvm::for_each (op->getOperands (), processValue);
124125
125126 backwardSlice->insert (op);
126127}
0 commit comments