File tree Expand file tree Collapse file tree 4 files changed +47
-1
lines changed Expand file tree Collapse file tree 4 files changed +47
-1
lines changed Original file line number Diff line number Diff line change 13
13
#include " mlir/IR/Builders.h"
14
14
#include " mlir/IR/Dominance.h"
15
15
#include " mlir/IR/PatternMatch.h"
16
+ #include " mlir/IR/RegionKindInterface.h"
16
17
#include " mlir/IR/Value.h"
17
18
#include " mlir/Interfaces/ControlFlowInterfaces.h"
18
19
#include " mlir/Interfaces/MemorySlotInterfaces.h"
@@ -255,6 +256,18 @@ LogicalResult MemorySlotPromotionAnalyzer::computeBlockingUses(
255
256
// delete itself). We thus need to start from the use of the slot pointer and
256
257
// propagate further requests through the forward slice.
257
258
259
+ // Because this pass currently only supports analysing the parent region of
260
+ // the slot pointer, if a promotable memory op that needs promotion is within
261
+ // a graph region, the slot may only be used in a graph region and should
262
+ // therefore be ignored.
263
+ Region *slotPtrRegion = slot.ptr .getParentRegion ();
264
+ auto slotPtrRegionOp =
265
+ dyn_cast<RegionKindInterface>(slotPtrRegion->getParentOp ());
266
+ if (slotPtrRegionOp &&
267
+ slotPtrRegionOp.getRegionKind (slotPtrRegion->getRegionNumber ()) ==
268
+ RegionKind::Graph)
269
+ return failure ();
270
+
258
271
// First insert that all immediate users of the slot pointer must no longer
259
272
// use it.
260
273
for (OpOperand &use : slot.ptr .getUses ()) {
Original file line number Diff line number Diff line change 1
- // RUN: mlir-opt %s --pass-pipeline='builtin.module(func.func (mem2reg))' --split-input-file | FileCheck %s
1
+ // RUN: mlir-opt %s --pass-pipeline='builtin.module(any (mem2reg))' --split-input-file | FileCheck %s
2
2
3
3
// Verifies that allocators with mutliple slots are handled properly.
4
4
@@ -26,3 +26,16 @@ func.func @multi_slot_alloca_only_second() -> (i32, i32) {
26
26
%4 = memref.load %2 [] : memref <i32 >
27
27
return %3 , %4 : i32 , i32
28
28
}
29
+
30
+ // -----
31
+
32
+ // Checks that slots are not promoted if used in a graph region.
33
+
34
+ // CHECK-LABEL: test.isolated_graph_region
35
+ test.isolated_graph_region {
36
+ // CHECK: %{{[[:alnum:]]+}} = test.multi_slot_alloca
37
+ %slot = test.multi_slot_alloca : () -> (memref <i32 >)
38
+ memref.store %a , %slot [] : memref <i32 >
39
+ %a = memref.load %slot [] : memref <i32 >
40
+ " test.foo" () : () -> ()
41
+ }
Original file line number Diff line number Diff line change @@ -126,6 +126,14 @@ RegionKind GraphRegionOp::getRegionKind(unsigned index) {
126
126
return RegionKind::Graph;
127
127
}
128
128
129
+ // ===----------------------------------------------------------------------===//
130
+ // IsolatedGraphRegionOp
131
+ // ===----------------------------------------------------------------------===//
132
+
133
+ RegionKind IsolatedGraphRegionOp::getRegionKind (unsigned index) {
134
+ return RegionKind::Graph;
135
+ }
136
+
129
137
// ===----------------------------------------------------------------------===//
130
138
// AffineScopeOp
131
139
// ===----------------------------------------------------------------------===//
Original file line number Diff line number Diff line change @@ -2048,6 +2048,18 @@ def GraphRegionOp : TEST_Op<"graph_region", [
2048
2048
let assemblyFormat = "attr-dict-with-keyword $region";
2049
2049
}
2050
2050
2051
+ def IsolatedGraphRegionOp : TEST_Op<"isolated_graph_region", [
2052
+ DeclareOpInterfaceMethods<RegionKindInterface>,
2053
+ IsolatedFromAbove]> {
2054
+ let summary = "isolated from above operation with a graph region";
2055
+ let description = [{
2056
+ Test op that defines a graph region which is isolated from above.
2057
+ }];
2058
+
2059
+ let regions = (region AnyRegion:$region);
2060
+ let assemblyFormat = "attr-dict-with-keyword $region";
2061
+ }
2062
+
2051
2063
def AffineScopeOp : TEST_Op<"affine_scope", [AffineScope]> {
2052
2064
let summary = "affine scope operation";
2053
2065
let description = [{
You can’t perform that action at this time.
0 commit comments