[Mlir-commits] [mlir] [mlir][scf] Add `no_inline` attribute to `scf.execute_region` (PR #151352)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Jul 30 08:24:56 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Jungwook Park (jungpark-mlir)
<details>
<summary>Changes</summary>
More control over the IR.
Enabling users to explicitly specify which regions should be preserved, uncovers additional opportunities to utilize `scf.execute_region` op.
---
Full diff: https://github.com/llvm/llvm-project/pull/151352.diff
3 Files Affected:
- (modified) mlir/include/mlir/Dialect/SCF/IR/SCFOps.td (+4)
- (modified) mlir/lib/Dialect/SCF/IR/SCF.cpp (+1-1)
- (modified) mlir/test/Dialect/SCF/canonicalize.mlir (+22)
``````````diff
diff --git a/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td b/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
index 2d15544e871b3..e6b83fca771a9 100644
--- a/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
+++ b/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
@@ -119,6 +119,10 @@ def ExecuteRegionOp : SCF_Op<"execute_region", [
```
}];
+ let arguments = (ins
+ UnitAttr:$no_inline
+ );
+
let results = (outs Variadic<AnyType>);
let regions = (region AnyRegion:$region);
diff --git a/mlir/lib/Dialect/SCF/IR/SCF.cpp b/mlir/lib/Dialect/SCF/IR/SCF.cpp
index 759e58b617578..6b7f11a3469d6 100644
--- a/mlir/lib/Dialect/SCF/IR/SCF.cpp
+++ b/mlir/lib/Dialect/SCF/IR/SCF.cpp
@@ -184,7 +184,7 @@ struct SingleBlockExecuteInliner : public OpRewritePattern<ExecuteRegionOp> {
LogicalResult matchAndRewrite(ExecuteRegionOp op,
PatternRewriter &rewriter) const override {
- if (!op.getRegion().hasOneBlock())
+ if (!op.getRegion().hasOneBlock() || op.getNoInline())
return failure();
replaceOpWithRegion(rewriter, op, op.getRegion());
return success();
diff --git a/mlir/test/Dialect/SCF/canonicalize.mlir b/mlir/test/Dialect/SCF/canonicalize.mlir
index 12d30e17f4a8f..ae02144f06f32 100644
--- a/mlir/test/Dialect/SCF/canonicalize.mlir
+++ b/mlir/test/Dialect/SCF/canonicalize.mlir
@@ -1461,6 +1461,28 @@ func.func @execute_region_elim() {
// -----
+// CHECK-LABEL: func @execute_region_elim_noinline
+func.func @execute_region_elim_noinline() {
+ affine.for %i = 0 to 100 {
+ "test.foo"() : () -> ()
+ %v = scf.execute_region -> i64 {
+ %x = "test.val"() : () -> i64
+ scf.yield %x : i64
+ } {no_inline}
+ "test.bar"(%v) : (i64) -> ()
+ }
+ return
+}
+
+// CHECK-NEXT: affine.for %arg0 = 0 to 100 {
+// CHECK-NEXT: "test.foo"() : () -> ()
+// CHECK-NEXT: scf.execute_region
+// CHECK-NEXT: %[[VAL:.*]] = "test.val"() : () -> i64
+// CHECK-NEXT: scf.yield %[[VAL]] : i64
+// CHECK-NEXT: }
+
+// -----
+
// CHECK-LABEL: func @func_execute_region_elim
func.func @func_execute_region_elim() {
"test.foo"() : () -> ()
``````````
</details>
https://github.com/llvm/llvm-project/pull/151352
More information about the Mlir-commits
mailing list