Skip to content

Commit 8c83c3d

Browse files
committed
[mlir][scf] Add no_inline attribute to scf.execute_region
More control over the IR. Enabling users to explicitly specify which regions should be preserved, uncovers additional opportunities to utilize `scf.execute_region`.
1 parent 807a82d commit 8c83c3d

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

mlir/include/mlir/Dialect/SCF/IR/SCFOps.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ def ExecuteRegionOp : SCF_Op<"execute_region", [
119119
```
120120
}];
121121

122+
let arguments = (ins
123+
UnitAttr:$no_inline
124+
);
125+
122126
let results = (outs Variadic<AnyType>);
123127

124128
let regions = (region AnyRegion:$region);

mlir/lib/Dialect/SCF/IR/SCF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ struct SingleBlockExecuteInliner : public OpRewritePattern<ExecuteRegionOp> {
184184

185185
LogicalResult matchAndRewrite(ExecuteRegionOp op,
186186
PatternRewriter &rewriter) const override {
187-
if (!op.getRegion().hasOneBlock())
187+
if (!op.getRegion().hasOneBlock() || op.getNoInline())
188188
return failure();
189189
replaceOpWithRegion(rewriter, op, op.getRegion());
190190
return success();

mlir/test/Dialect/SCF/canonicalize.mlir

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,6 +1461,28 @@ func.func @execute_region_elim() {
14611461

14621462
// -----
14631463

1464+
// CHECK-LABEL: func @execute_region_elim_noinline
1465+
func.func @execute_region_elim_noinline() {
1466+
affine.for %i = 0 to 100 {
1467+
"test.foo"() : () -> ()
1468+
%v = scf.execute_region -> i64 {
1469+
%x = "test.val"() : () -> i64
1470+
scf.yield %x : i64
1471+
} {no_inline}
1472+
"test.bar"(%v) : (i64) -> ()
1473+
}
1474+
return
1475+
}
1476+
1477+
// CHECK-NEXT: affine.for %arg0 = 0 to 100 {
1478+
// CHECK-NEXT: "test.foo"() : () -> ()
1479+
// CHECK-NEXT: scf.execute_region
1480+
// CHECK-NEXT: %[[VAL:.*]] = "test.val"() : () -> i64
1481+
// CHECK-NEXT: scf.yield %[[VAL]] : i64
1482+
// CHECK-NEXT: }
1483+
1484+
// -----
1485+
14641486
// CHECK-LABEL: func @func_execute_region_elim
14651487
func.func @func_execute_region_elim() {
14661488
"test.foo"() : () -> ()

0 commit comments

Comments
 (0)