[Mlir-commits] [mlir] 15b76e6 - [mlir][ODS] Fix `VariadicRegion` code generation for `NoTerminator` Ops

Vladislav Vinogradov llvmlistbot at llvm.org
Fri Mar 26 04:26:22 PDT 2021


Author: Vladislav Vinogradov
Date: 2021-03-26T14:24:36+03:00
New Revision: 15b76e6ca0a0788206fcaac7a1df0f39113c4bd8

URL: https://github.com/llvm/llvm-project/commit/15b76e6ca0a0788206fcaac7a1df0f39113c4bd8
DIFF: https://github.com/llvm/llvm-project/commit/15b76e6ca0a0788206fcaac7a1df0f39113c4bd8.diff

LOG: [mlir][ODS] Fix `VariadicRegion` code generation for `NoTerminator` Ops

The issue was introduced in D98468.

The `{0}Regions` is an array of `std::unique_ptr<Region>` objects,
so it should be processed accordingly.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D99332

Added: 
    

Modified: 
    mlir/test/IR/region.mlir
    mlir/test/lib/Dialect/Test/TestOps.td
    mlir/tools/mlir-tblgen/OpFormatGen.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/test/IR/region.mlir b/mlir/test/IR/region.mlir
index 8f9d707b6f18..fc0f2da36af4 100644
--- a/mlir/test/IR/region.mlir
+++ b/mlir/test/IR/region.mlir
@@ -81,3 +81,23 @@ func @named_region_has_wrong_number_of_blocks() {
 "test.unregistered_without_terminator"() ( {
   ^bb0:  // no predecessors
 }) : () -> ()
+
+// -----
+
+// CHECK: test.single_no_terminator_op
+"test.single_no_terminator_op"() (
+  {
+    func @foo1() { return }
+    func @foo2() { return }
+  }
+) : () -> ()
+
+// CHECK: test.variadic_no_terminator_op
+"test.variadic_no_terminator_op"() (
+  {
+    func @foo1() { return }
+  },
+  {
+    func @foo2() { return }
+  }
+) : () -> ()

diff  --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td
index be53ee230f4a..25cd7f2ce67c 100644
--- a/mlir/test/lib/Dialect/Test/TestOps.td
+++ b/mlir/test/lib/Dialect/Test/TestOps.td
@@ -333,6 +333,22 @@ def SizedRegionOp : TEST_Op<"sized_region_op", []> {
   let regions = (region SizedRegion<2>:$my_region, SizedRegion<1>);
 }
 
+//===----------------------------------------------------------------------===//
+// NoTerminator Operation
+//===----------------------------------------------------------------------===//
+
+def SingleNoTerminatorOp : TEST_Op<"single_no_terminator_op", GraphRegionNoTerminator.traits> {
+  let regions = (region SizedRegion<1>:$my_region);
+
+  let assemblyFormat = "attr-dict `:` $my_region";
+}
+
+def VariadicNoTerminatorOp : TEST_Op<"variadic_no_terminator_op", GraphRegionNoTerminator.traits> {
+  let regions = (region VariadicRegion<SizedRegion<1>>:$my_regions);
+
+  let assemblyFormat = "attr-dict `:` $my_regions";
+}
+
 //===----------------------------------------------------------------------===//
 // Test Call Interfaces
 //===----------------------------------------------------------------------===//

diff  --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
index e5d8db9342cc..93d2155c3c82 100644
--- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp
@@ -695,7 +695,7 @@ const char *regionListEnsureTerminatorParserCode = R"(
 /// {0}: The name of the region list.
 const char *regionListEnsureSingleBlockParserCode = R"(
   for (auto &region : {0}Regions)
-    if (region.empty()) *{0}Region.emplaceBlock();
+    if (region->empty()) region->emplaceBlock();
 )";
 
 /// The code snippet used to generate a parser call for an optional region.


        


More information about the Mlir-commits mailing list