Skip to content

Commit 21c92a2

Browse files
committed
Let attribute as a keyword
1 parent 8c83c3d commit 21c92a2

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ def ExecuteRegionOp : SCF_Op<"execute_region", [
8787
be accessed inside the op. The op's region can have multiple blocks and the
8888
blocks can have multiple distinct terminators. Values returned from this op's
8989
region define the op's results.
90+
Canonicalizer inlines an ExecuteRegionOp into its parent if it only contains
91+
one block or its parent can contain multiple blocks, 'no_inline' attribute
92+
can be set to prevent an ExecuteRegionOp from being inlined.
9093

9194
Example:
9295

@@ -98,6 +101,14 @@ def ExecuteRegionOp : SCF_Op<"execute_region", [
98101
}
99102
}
100103

104+
// the same as above but with no_inline attribute
105+
scf.for %i = 0 to 128 step %c1 {
106+
%y = scf.execute_region -> i32 no_inline {
107+
%x = load %A[%i] : memref<128xi32>
108+
scf.yield %x : i32
109+
}
110+
}
111+
101112
affine.for %i = 0 to 100 {
102113
"foo"() : () -> ()
103114
%v = scf.execute_region -> i64 {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ ParseResult ExecuteRegionOp::parse(OpAsmParser &parser,
137137
if (parser.parseOptionalArrowTypeList(result.types))
138138
return failure();
139139

140+
if (succeeded(parser.parseOptionalKeyword("no_inline")))
141+
result.addAttribute("no_inline", parser.getBuilder().getUnitAttr());
142+
140143
// Introduce the body region and parse it.
141144
Region *body = result.addRegion();
142145
if (parser.parseRegion(*body, /*arguments=*/{}, /*argTypes=*/{}) ||
@@ -148,8 +151,9 @@ ParseResult ExecuteRegionOp::parse(OpAsmParser &parser,
148151

149152
void ExecuteRegionOp::print(OpAsmPrinter &p) {
150153
p.printOptionalArrowTypeList(getResultTypes());
151-
152154
p << ' ';
155+
if(getNoInline())
156+
p << "no_inline ";
153157
p.printRegion(getRegion(),
154158
/*printEntryBlockArgs=*/false,
155159
/*printBlockTerminators=*/true);

mlir/test/Dialect/SCF/canonicalize.mlir

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,8 +1440,8 @@ func.func @propagate_into_execute_region() {
14401440

14411441
// -----
14421442

1443-
// CHECK-LABEL: func @execute_region_elim
1444-
func.func @execute_region_elim() {
1443+
// CHECK-LABEL: func @execute_region_inline
1444+
func.func @execute_region_inline() {
14451445
affine.for %i = 0 to 100 {
14461446
"test.foo"() : () -> ()
14471447
%v = scf.execute_region -> i64 {
@@ -1461,14 +1461,14 @@ func.func @execute_region_elim() {
14611461

14621462
// -----
14631463

1464-
// CHECK-LABEL: func @execute_region_elim_noinline
1465-
func.func @execute_region_elim_noinline() {
1464+
// CHECK-LABEL: func @execute_region_no_inline
1465+
func.func @execute_region_no_inline() {
14661466
affine.for %i = 0 to 100 {
14671467
"test.foo"() : () -> ()
1468-
%v = scf.execute_region -> i64 {
1468+
%v = scf.execute_region -> i64 no_inline {
14691469
%x = "test.val"() : () -> i64
14701470
scf.yield %x : i64
1471-
} {no_inline}
1471+
}
14721472
"test.bar"(%v) : (i64) -> ()
14731473
}
14741474
return
@@ -1483,8 +1483,8 @@ func.func @execute_region_elim_noinline() {
14831483

14841484
// -----
14851485

1486-
// CHECK-LABEL: func @func_execute_region_elim
1487-
func.func @func_execute_region_elim() {
1486+
// CHECK-LABEL: func @func_execute_region_inline
1487+
func.func @func_execute_region_inline() {
14881488
"test.foo"() : () -> ()
14891489
%v = scf.execute_region -> i64 {
14901490
%c = "test.cmp"() : () -> i1
@@ -1518,8 +1518,8 @@ func.func @func_execute_region_elim() {
15181518

15191519
// -----
15201520

1521-
// CHECK-LABEL: func @func_execute_region_elim_multi_yield
1522-
func.func @func_execute_region_elim_multi_yield() {
1521+
// CHECK-LABEL: func @func_execute_region_inline_multi_yield
1522+
func.func @func_execute_region_inline_multi_yield() {
15231523
"test.foo"() : () -> ()
15241524
%v = scf.execute_region -> i64 {
15251525
%c = "test.cmp"() : () -> i1

0 commit comments

Comments
 (0)