Skip to content

Commit a9a8351

Browse files
authored
Revert "Extend getBackwardSlice to track values captured from above" (#114432)
Reverts #113478 Bot is broken when building with shared libs.
1 parent 42fae38 commit a9a8351

File tree

4 files changed

+6
-47
lines changed

4 files changed

+6
-47
lines changed

mlir/include/mlir/Analysis/SliceAnalysis.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ struct BackwardSliceOptions : public SliceOptions {
4747
/// backward slice computation traverses block arguments and asserts that the
4848
/// parent op has a single region with a single block.
4949
bool omitBlockArguments = false;
50-
51-
/// When omitUsesFromAbove is true, the backward slice computation omits
52-
/// traversing values that are captured from above.
53-
/// TODO: this should default to `false` after users have been updated.
54-
bool omitUsesFromAbove = true;
5550
};
5651

5752
using ForwardSliceOptions = SliceOptions;

mlir/lib/Analysis/SliceAnalysis.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
#include "mlir/IR/Operation.h"
1717
#include "mlir/Interfaces/SideEffectInterfaces.h"
1818
#include "mlir/Support/LLVM.h"
19-
#include "mlir/Transforms/RegionUtils.h"
20-
#include "llvm/ADT/STLExtras.h"
2119
#include "llvm/ADT/SetVector.h"
2220
#include "llvm/ADT/SmallPtrSet.h"
2321

@@ -93,13 +91,14 @@ static void getBackwardSliceImpl(Operation *op,
9391
if (options.filter && !options.filter(op))
9492
return;
9593

96-
auto processValue = [&](Value value) {
97-
if (auto *definingOp = value.getDefiningOp()) {
94+
for (const auto &en : llvm::enumerate(op->getOperands())) {
95+
auto operand = en.value();
96+
if (auto *definingOp = operand.getDefiningOp()) {
9897
if (backwardSlice->count(definingOp) == 0)
9998
getBackwardSliceImpl(definingOp, backwardSlice, options);
100-
} else if (auto blockArg = dyn_cast<BlockArgument>(value)) {
99+
} else if (auto blockArg = dyn_cast<BlockArgument>(operand)) {
101100
if (options.omitBlockArguments)
102-
return;
101+
continue;
103102

104103
Block *block = blockArg.getOwner();
105104
Operation *parentOp = block->getParentOp();
@@ -114,14 +113,7 @@ static void getBackwardSliceImpl(Operation *op,
114113
} else {
115114
llvm_unreachable("No definingOp and not a block argument.");
116115
}
117-
};
118-
119-
if (!options.omitUsesFromAbove) {
120-
visitUsedValuesDefinedAbove(op->getRegions(), [&](OpOperand *operand) {
121-
processValue(operand->get());
122-
});
123116
}
124-
llvm::for_each(op->getOperands(), processValue);
125117

126118
backwardSlice->insert(op);
127119
}

mlir/test/IR/slice.mlir

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt -slice-analysis-test -split-input-file %s | FileCheck %s
1+
// RUN: mlir-opt -slice-analysis-test %s | FileCheck %s
22

33
func.func @slicing_linalg_op(%arg0 : index, %arg1 : index, %arg2 : index) {
44
%a = memref.alloc(%arg0, %arg2) : memref<?x?xf32>
@@ -33,29 +33,3 @@ func.func @slicing_linalg_op(%arg0 : index, %arg1 : index, %arg2 : index) {
3333
// CHECK-DAG: %[[B:.+]] = memref.alloc(%[[ARG2]], %[[ARG1]]) : memref<?x?xf32>
3434
// CHECK-DAG: %[[C:.+]] = memref.alloc(%[[ARG0]], %[[ARG1]]) : memref<?x?xf32>
3535
// CHECK: return
36-
37-
// -----
38-
39-
#map = affine_map<(d0, d1) -> (d0, d1)>
40-
func.func @slice_use_from_above(%arg0: tensor<5x5xf32>, %arg1: tensor<5x5xf32>) {
41-
%0 = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel", "parallel"]} ins(%arg0 : tensor<5x5xf32>) outs(%arg1 : tensor<5x5xf32>) {
42-
^bb0(%in: f32, %out: f32):
43-
%2 = arith.addf %in, %in : f32
44-
linalg.yield %2 : f32
45-
} -> tensor<5x5xf32>
46-
%collapsed = tensor.collapse_shape %0 [[0, 1]] : tensor<5x5xf32> into tensor<25xf32>
47-
%1 = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel", "parallel"]} ins(%0 : tensor<5x5xf32>) outs(%arg1 : tensor<5x5xf32>) {
48-
^bb0(%in: f32, %out: f32):
49-
%c2 = arith.constant 2 : index
50-
%extracted = tensor.extract %collapsed[%c2] : tensor<25xf32>
51-
%2 = arith.addf %extracted, %extracted : f32
52-
linalg.yield %2 : f32
53-
} -> tensor<5x5xf32>
54-
return
55-
}
56-
57-
// CHECK-LABEL: func @slice_use_from_above__backward_slice__0
58-
// CHECK-SAME: %[[ARG0:[a-zA-Z0-9_]+]]: tensor
59-
// CHECK: %[[A:.+]] = linalg.generic {{.*}} ins(%[[ARG0]]
60-
// CHECK: %[[B:.+]] = tensor.collapse_shape %[[A]]
61-
// CHECK: return

mlir/test/lib/IR/TestSlicing.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ static LogicalResult createBackwardSliceFunction(Operation *op,
3939
SetVector<Operation *> slice;
4040
BackwardSliceOptions options;
4141
options.omitBlockArguments = omitBlockArguments;
42-
// TODO: Make this default.
43-
options.omitUsesFromAbove = false;
4442
getBackwardSlice(op, &slice, options);
4543
for (Operation *slicedOp : slice)
4644
builder.clone(*slicedOp, mapper);

0 commit comments

Comments
 (0)