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,35 @@ +//===- OpenMPDialect.h - MLIR Dialect for OpenMP ----------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file declares the OpenMP dialect in MLIR. +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_DIALECT_OPENMP_OPENMPDIALECT_H_ +#define MLIR_DIALECT_OPENMP_OPENMPDIALECT_H_ + +#include "mlir/IR/Dialect.h" +#include "mlir/IR/OpDefinition.h" + +namespace mlir { +namespace omp { + +#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 omp +} // 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,37 @@ +//===-- OpenMPOps.td - OpenMP dialect operation definitions *- tablegen -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file defines the basic operations for the OpenMP dialect. +// +//===----------------------------------------------------------------------===// + + +#ifndef OPENMP_OPS +#define OPENMP_OPS + +include "mlir/IR/OpBase.td" + +def OpenMP_Dialect : Dialect { + let name = "omp"; +} + +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,34 @@ +//===- OpenMPDialect.cpp - MLIR Dialect for OpenMP implementation ---------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file implements the OpenMP dialect and its operations. +// +//===----------------------------------------------------------------------===// + +#include "mlir/Dialect/OpenMP/OpenMPDialect.h" +#include "mlir/IR/OpImplementation.h" + +using namespace mlir; +using namespace mlir::omp; + +OpenMPDialect::OpenMPDialect(MLIRContext *context) + : Dialect(getDialectNamespace(), context) { + addOperations< +#define GET_OP_LIST +#include "mlir/Dialect/OpenMP/OpenMPOps.cpp.inc" + >(); +} + +namespace mlir { +namespace omp { +#define GET_OP_CLASSES +#include "mlir/Dialect/OpenMP/OpenMPOps.cpp.inc" +} // namespace omp +} // namespace mlir + +static DialectRegistration ompDialect; 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