[MLIR][OpenMP] Allow the single operation to have a region
authorKiran Chandramohan <kiran.chandramohan@arm.com>
Mon, 31 Oct 2022 10:34:39 +0000 (10:34 +0000)
committerKiran Chandramohan <kiran.chandramohan@arm.com>
Mon, 31 Oct 2022 10:48:14 +0000 (10:48 +0000)
The OpenMP standard specifies the region inside to be a structured
block. This means that branches into or out of the region is not
permitted but branches are permitted inside the OpenMP single region.
This is currently modeled by having a region of kind `AnyRegion` for
all the OpenMP ops. In future we can have a more strictly defined
region.

Fixes #58396.

Reviewed By: peixin

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

mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
mlir/test/Dialect/OpenMP/ops.mlir

index 800da7c..e6fde2d 100644 (file)
@@ -229,7 +229,7 @@ def SingleOp : OpenMP_Op<"single", [AttrSizedOperandSegments]> {
                        Variadic<AnyType>:$allocators_vars,
                        UnitAttr:$nowait);
 
-  let regions = (region SizedRegion<1>:$region);
+  let regions = (region AnyRegion:$region);
 
   let assemblyFormat = [{
     oilist(`allocate` `(`
index 51b7dba..74dc12e 100644 (file)
@@ -1349,6 +1349,18 @@ func.func @omp_single_allocate_nowait(%data_var: memref<i32>) {
   return
 }
 
+// CHECK-LABEL: func @omp_single_multiple_blocks
+func.func @omp_single_multiple_blocks() {
+  // CHECK: omp.single {
+  omp.single {
+    cf.br ^bb2
+    ^bb2:
+    // CHECK: omp.terminator
+    omp.terminator
+  }
+  return
+}
+
 // CHECK-LABEL: @omp_task
 // CHECK-SAME: (%[[bool_var:.*]]: i1, %[[i64_var:.*]]: i64, %[[i32_var:.*]]: i32, %[[data_var:.*]]: memref<i32>)
 func.func @omp_task(%bool_var: i1, %i64_var: i64, %i32_var: i32, %data_var: memref<i32>) {