[Mlir-commits] [mlir] 3c0d470 - [mlir][OpenMP] omp.single translation to LLVM IR

Shraiysh Vaishay llvmlistbot at llvm.org
Wed Mar 23 21:37:40 PDT 2022


Author: Shraiysh Vaishay
Date: 2022-03-24T10:07:30+05:30
New Revision: 3c0d47086511131764450841d4f7411f5577c7d9

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

LOG: [mlir][OpenMP] omp.single translation to LLVM IR

This patch adds translation from omp.single to LLVM IR.

Depends on D122288

Reviewed By: ftynse, kiranchandramohan

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

Added: 
    

Modified: 
    mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
    mlir/test/Target/LLVMIR/openmp-llvm.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index b71f5d9173d64..4f21e24e6f6c1 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -637,6 +637,25 @@ convertOmpSections(Operation &opInst, llvm::IRBuilderBase &builder,
   return bodyGenStatus;
 }
 
+/// Converts an OpenMP single construct into LLVM IR using OpenMPIRBuilder.
+static LogicalResult
+convertOmpSingle(omp::SingleOp &singleOp, llvm::IRBuilderBase &builder,
+                 LLVM::ModuleTranslation &moduleTranslation) {
+  using InsertPointTy = llvm::OpenMPIRBuilder::InsertPointTy;
+  llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
+  LogicalResult bodyGenStatus = success();
+  auto bodyCB = [&](InsertPointTy allocaIP, InsertPointTy codegenIP,
+                    llvm::BasicBlock &continuationBB) {
+    convertOmpOpRegions(singleOp.region(), "omp.single.region",
+                        *codegenIP.getBlock(), continuationBB, builder,
+                        moduleTranslation, bodyGenStatus);
+  };
+  auto finiCB = [&](InsertPointTy codeGenIP) {};
+  builder.restoreIP(moduleTranslation.getOpenMPBuilder()->createSingle(
+      ompLoc, bodyCB, finiCB, /*DidIt=*/nullptr));
+  return bodyGenStatus;
+}
+
 /// Converts an OpenMP workshare loop into LLVM IR using OpenMPIRBuilder.
 static LogicalResult
 convertOmpWsLoop(Operation &opInst, llvm::IRBuilderBase &builder,
@@ -1355,6 +1374,9 @@ LogicalResult OpenMPDialectLLVMIRTranslationInterface::convertOperation(
       .Case([&](omp::SectionsOp) {
         return convertOmpSections(*op, builder, moduleTranslation);
       })
+      .Case([&](omp::SingleOp op) {
+        return convertOmpSingle(op, builder, moduleTranslation);
+      })
       .Case<omp::YieldOp, omp::TerminatorOp, omp::ReductionDeclareOp,
             omp::CriticalDeclareOp>([](auto op) {
         // `yield` and `terminator` can be just omitted. The block structure

diff  --git a/mlir/test/Target/LLVMIR/openmp-llvm.mlir b/mlir/test/Target/LLVMIR/openmp-llvm.mlir
index 7fc8ecdbf4a49..c1d5b0da63d5c 100644
--- a/mlir/test/Target/LLVMIR/openmp-llvm.mlir
+++ b/mlir/test/Target/LLVMIR/openmp-llvm.mlir
@@ -1822,3 +1822,21 @@ llvm.func @repeated_successor(%arg0: i64, %arg1: i64, %arg2: i64, %arg3: i1) {
   }
   llvm.return
 }
+
+// -----
+
+// CHECK-LABEL: @single
+// CHECK-SAME: (i32 %[[x:.*]], i32 %[[y:.*]], i32* %[[zaddr:.*]])
+llvm.func @single(%x: i32, %y: i32, %zaddr: !llvm.ptr<i32>) {
+  // CHECK: call i32 @__kmpc_single
+  omp.single {
+    // CHECK: %[[z:.*]] = add i32 %[[x]], %[[y]]
+    %z = llvm.add %x, %y : i32
+    // CHECK: store i32 %[[z]], i32* %[[zaddr]]
+    llvm.store %z, %zaddr : !llvm.ptr<i32>
+    // CHECK: call void @__kmpc_end_single
+    omp.terminator
+  }
+  // CHECK: ret void
+  llvm.return
+}


        


More information about the Mlir-commits mailing list