[PATCH] D72962: [MLIR, OpenMP] Translation of OpenMP barrier construct to LLVM IR

Kiran Chandramohan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 20 13:44:09 PST 2020


kiranchandramohan updated this revision to Diff 245732.
kiranchandramohan added a comment.

Added LLVMFrontendOpenMP and MLIROpenMP to the dependency of MLIRLLVMIR and also linking these libraries along with MLIRLLVMIR. Removed from other clients.

@mehdi_amini hope this is what you suggested. Thanks.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72962/new/

https://reviews.llvm.org/D72962

Files:
  mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
  mlir/lib/Dialect/LLVMIR/CMakeLists.txt
  mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
  mlir/test/Target/openmp-llvm.mlir


Index: mlir/test/Target/openmp-llvm.mlir
===================================================================
--- /dev/null
+++ mlir/test/Target/openmp-llvm.mlir
@@ -0,0 +1,10 @@
+// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
+
+// CHECK-LABEL: define void @empty()
+// CHECK: [[OMP_THREAD:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @{{[0-9]+}})
+// CHECK-NEXT:  call void @__kmpc_barrier(%struct.ident_t* @{{[0-9]+}}, i32 [[OMP_THREAD]])
+// CHECK-NEXT:    ret void
+llvm.func @empty() {
+  omp.barrier
+  llvm.return
+}
Index: mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
===================================================================
--- mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -15,12 +15,14 @@
 
 #include "DebugTranslation.h"
 #include "mlir/Dialect/LLVMIR/LLVMDialect.h"
+#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
 #include "mlir/IR/Attributes.h"
 #include "mlir/IR/Module.h"
 #include "mlir/IR/StandardTypes.h"
 #include "mlir/Support/LLVM.h"
 
 #include "llvm/ADT/SetVector.h"
+#include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DerivedTypes.h"
@@ -374,6 +376,22 @@
     return success();
   }
 
+  if (opInst.getDialect() ==
+      opInst.getContext()->getRegisteredDialect<omp::OpenMPDialect>()) {
+    if (!OMPBuilder) {
+      OMPBuilder =
+          std::move(std::make_unique<llvm::OpenMPIRBuilder>(*llvmModule));
+      OMPBuilder->initialize();
+    }
+
+    if (isa<omp::BarrierOp>(opInst)) {
+      OMPBuilder->CreateBarrier(builder.saveIP(), llvm::omp::OMPD_barrier);
+      return success();
+    }
+    return opInst.emitError("unsupported OpenMP operation: ")
+           << opInst.getName();
+  }
+
   return opInst.emitError("unsupported or non-LLVM operation: ")
          << opInst.getName();
 }
Index: mlir/lib/Dialect/LLVMIR/CMakeLists.txt
===================================================================
--- mlir/lib/Dialect/LLVMIR/CMakeLists.txt
+++ mlir/lib/Dialect/LLVMIR/CMakeLists.txt
@@ -4,8 +4,8 @@
   ADDITIONAL_HEADER_DIRS
   ${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/LLVMIR
   )
-add_dependencies(MLIRLLVMIR MLIRLLVMOpsIncGen MLIRLLVMConversionsIncGen LLVMAsmParser LLVMCore LLVMSupport)
-target_link_libraries(MLIRLLVMIR LLVMAsmParser LLVMCore LLVMSupport MLIRIR)
+add_dependencies(MLIRLLVMIR MLIRLLVMOpsIncGen MLIRLLVMConversionsIncGen MLIROpenMP LLVMFrontendOpenMP LLVMAsmParser LLVMCore LLVMSupport)
+target_link_libraries(MLIRLLVMIR LLVMAsmParser LLVMCore LLVMSupport LLVMFrontendOpenMP MLIROpenMP MLIRIR)
 
 add_llvm_library(MLIRNVVMIR
   IR/NVVMDialect.cpp
Index: mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
===================================================================
--- mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
+++ mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
@@ -19,6 +19,7 @@
 #include "mlir/IR/Module.h"
 #include "mlir/IR/Value.h"
 
+#include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/IRBuilder.h"
@@ -102,6 +103,9 @@
   /// A converter for translating debug information.
   std::unique_ptr<detail::DebugTranslation> debugTranslation;
 
+  /// Builder for LLVM IR generation of OpenMP constructs.
+  std::unique_ptr<llvm::OpenMPIRBuilder> OMPBuilder;
+
   /// Mappings between llvm.mlir.global definitions and corresponding globals.
   DenseMap<Operation *, llvm::GlobalValue *> globalsMapping;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72962.245732.patch
Type: text/x-patch
Size: 3535 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200220/ea1a5350/attachment.bin>


More information about the llvm-commits mailing list