[Mlir-commits] [mlir] e05d324 - [mlir][openacc] Keep region when applying data operand conversion

Valentin Clement llvmlistbot at llvm.org
Wed Apr 19 10:32:42 PDT 2023


Author: Valentin Clement
Date: 2023-04-19T10:32:36-07:00
New Revision: e05d324cd0a991af76c4190972c13f2f2dee7b71

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

LOG: [mlir][openacc] Keep region when applying data operand conversion

Keep the region when the operation has one. The previous code
was throwing away the region when creating the new version
of the operation.

Reviewed By: razvanlupusoru

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

Added: 
    

Modified: 
    mlir/lib/Conversion/OpenACCToLLVM/OpenACCToLLVM.cpp
    mlir/test/Conversion/OpenACCToLLVM/convert-data-operands-to-llvmir.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/OpenACCToLLVM/OpenACCToLLVM.cpp b/mlir/lib/Conversion/OpenACCToLLVM/OpenACCToLLVM.cpp
index 90c34f9e7152c..be60afac04222 100644
--- a/mlir/lib/Conversion/OpenACCToLLVM/OpenACCToLLVM.cpp
+++ b/mlir/lib/Conversion/OpenACCToLLVM/OpenACCToLLVM.cpp
@@ -135,8 +135,18 @@ class LegalizeDataOpForLLVMTranslation : public ConvertOpToLLVMPattern<Op> {
       }
     }
 
-    builder.replaceOpWithNewOp<Op>(op, TypeRange(), convertedOperands,
-                                   op.getOperation()->getAttrs());
+    if constexpr (std::is_same_v<Op, acc::ParallelOp> ||
+                  std::is_same_v<Op, acc::DataOp>) {
+      auto newOp =
+          builder.create<Op>(op.getLoc(), TypeRange(), convertedOperands,
+                             op.getOperation()->getAttrs());
+      builder.inlineRegionBefore(op.getRegion(), newOp.getRegion(),
+                                 newOp.getRegion().end());
+      builder.eraseOp(op);
+    } else {
+      builder.replaceOpWithNewOp<Op>(op, TypeRange(), convertedOperands,
+                                     op.getOperation()->getAttrs());
+    }
 
     return success();
   }

diff  --git a/mlir/test/Conversion/OpenACCToLLVM/convert-data-operands-to-llvmir.mlir b/mlir/test/Conversion/OpenACCToLLVM/convert-data-operands-to-llvmir.mlir
index 3a63863ebe945..f6966f3f9f056 100644
--- a/mlir/test/Conversion/OpenACCToLLVM/convert-data-operands-to-llvmir.mlir
+++ b/mlir/test/Conversion/OpenACCToLLVM/convert-data-operands-to-llvmir.mlir
@@ -113,11 +113,18 @@ func.func @testupdateop(%a: memref<10xf32>, %b: memref<10xf32>) -> () {
 
 func.func @testdataregion(%a: memref<10xf32>, %b: memref<10xf32>) -> () {
   acc.data copy(%b : memref<10xf32>) copyout(%a : memref<10xf32>) {
+    acc.parallel {
+      acc.yield
+    }
+    acc.terminator
   }
   return
 }
 
 // CHECK: acc.data copy(%{{.*}} : !llvm.struct<"openacc_data", (struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>, ptr, i64)>) copyout(%{{.*}} : !llvm.struct<"openacc_data.1", (struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>, ptr, i64)>)
+// CHECK: acc.parallel
+// CHECK: acc.yield
+// CHECK: acc.terminator
 
 // -----
 
@@ -215,9 +222,13 @@ func.func @testparallelop(%a: memref<10xf32>, %b: memref<10xf32>) -> () {
 
 func.func @testparallelop(%i: i64, %a: memref<10xf32>, %b: memref<10xf32>) -> () {
   acc.parallel num_gangs(%i: i64) present(%a, %b : memref<10xf32>, memref<10xf32>) {
+    %0 = arith.constant 0 : i32
+    acc.yield
   } attributes {async}
   return
 }
 
 // CHECK: acc.parallel num_gangs(%{{.*}}: i64) present(%{{.*}}, %{{.*}} : !llvm.struct<"openacc_data", (struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>, ptr, i64)>, !llvm.struct<"openacc_data.1", (struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>, ptr, i64)>)
-// CHECK-NEXT: } attributes {async}
+// CHECK:   %c0_i32 = arith.constant 0 : i32
+// CHECK:   acc.yield
+// CHECK: } attributes {async}


        


More information about the Mlir-commits mailing list