diff --git a/mlir/include/mlir/Dialect/CMakeLists.txt b/mlir/include/mlir/Dialect/CMakeLists.txt --- a/mlir/include/mlir/Dialect/CMakeLists.txt +++ b/mlir/include/mlir/Dialect/CMakeLists.txt @@ -4,6 +4,7 @@ add_subdirectory(Linalg) add_subdirectory(LLVMIR) add_subdirectory(LoopOps) +add_subdirectory(OpenMP) add_subdirectory(QuantOps) add_subdirectory(SPIRV) add_subdirectory(StandardOps) diff --git a/mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt b/mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/mlir/include/mlir/Dialect/OpenMP/CMakeLists.txt @@ -0,0 +1 @@ +add_mlir_dialect(OpenMPOps OpenMPOps) diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPDialect.h b/mlir/include/mlir/Dialect/OpenMP/OpenMPDialect.h new file mode 100644 --- /dev/null +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPDialect.h @@ -0,0 +1,26 @@ +#ifndef MLIR_DIALECT_OPENMP_OPENMPDIALECT_H_ +#define MLIR_DIALECT_OPENMP_OPENMPDIALECT_H_ + +#include "mlir/IR/Dialect.h" +#include "mlir/IR/OpDefinition.h" +#include "mlir/IR/FunctionSupport.h" +#include "mlir/IR/OpImplementation.h" + + +namespace mlir { +namespace openmp { + +#define GET_OP_CLASSES +#include "mlir/Dialect/OpenMP/OpenMPOps.h.inc" + +class OpenMPDialect : public Dialect { +public: + explicit OpenMPDialect(MLIRContext *context); + + static StringRef getDialectNamespace() { return "omp"; } +}; + +} // namespace openmp +} // namespace mlir + +#endif /* MLIR_DIALECT_OPENMP_OPENMPDIALECT_H_ */ diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td new file mode 100644 --- /dev/null +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td @@ -0,0 +1,25 @@ +#ifndef OPENMP_OPS +#define OPENMP_OPS + +include "mlir/IR/OpBase.td" + +def OpenMP_Dialect : Dialect { + let name = "omp"; + let cppNamespace = "openmp"; +} + +class OpenMP_Op traits = []> : + Op; + +def BarrierOp : OpenMP_Op<"barrier"> { + let summary = "barrier construct"; + let description = [{ + The barrier construct specifies an explicit barrier at the point at which + the construct appears. + }]; + + let parser = [{ return success(); }]; + let printer = [{ p << getOperationName(); }]; +} + +#endif //OPENMP_OPS diff --git a/mlir/lib/Dialect/CMakeLists.txt b/mlir/lib/Dialect/CMakeLists.txt --- a/mlir/lib/Dialect/CMakeLists.txt +++ b/mlir/lib/Dialect/CMakeLists.txt @@ -4,6 +4,7 @@ add_subdirectory(Linalg) add_subdirectory(LLVMIR) add_subdirectory(LoopOps) +add_subdirectory(OpenMP) add_subdirectory(QuantOps) add_subdirectory(SDBM) add_subdirectory(SPIRV) diff --git a/mlir/lib/Dialect/OpenMP/CMakeLists.txt b/mlir/lib/Dialect/OpenMP/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/mlir/lib/Dialect/OpenMP/CMakeLists.txt @@ -0,0 +1,8 @@ +add_llvm_library(MLIROpenMP + IR/OpenMPDialect.cpp + + ADDITIONAL_HEADER_DIRS + ${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/OpenMP + ) + +add_dependencies(MLIROpenMP MLIROpenMPOpsIncGen) diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp new file mode 100644 --- /dev/null +++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp @@ -0,0 +1,22 @@ +#include "mlir/Dialect/OpenMP/OpenMPDialect.h" +#include "mlir/IR/MLIRContext.h" +#include "mlir/IR/Operation.h" +#include "mlir/IR/OperationSupport.h" + +namespace mlir { +namespace openmp { + +OpenMPDialect::OpenMPDialect(MLIRContext *context) : Dialect("omp", context) { + addOperations< +#define GET_OP_LIST +#include "mlir/Dialect/OpenMP/OpenMPOps.cpp.inc" + >(); +} + +#define GET_OP_CLASSES +#include "mlir/Dialect/OpenMP/OpenMPOps.cpp.inc" + +static DialectRegistration openmpDialect; + +} // namespace openmp +} // namespace mlir diff --git a/mlir/test/Dialect/OpenMP/ops.mlir b/mlir/test/Dialect/OpenMP/ops.mlir new file mode 100644 --- /dev/null +++ b/mlir/test/Dialect/OpenMP/ops.mlir @@ -0,0 +1,7 @@ +// RUN: mlir-opt -verify-diagnostics %s | FileCheck %s + +func @omp_barrier() -> () { + // CHECK: omp.barrier + omp.barrier + return +} diff --git a/mlir/tools/mlir-opt/CMakeLists.txt b/mlir/tools/mlir-opt/CMakeLists.txt --- a/mlir/tools/mlir-opt/CMakeLists.txt +++ b/mlir/tools/mlir-opt/CMakeLists.txt @@ -33,6 +33,7 @@ MLIRLLVMIR MLIRLoopOps MLIRNVVMIR + MLIROpenMP MLIROptMain MLIRParser MLIRPass