diff --git a/mlir/include/mlir-c/Dialect/OpenMP.h b/mlir/include/mlir-c/Dialect/OpenMP.h new file mode 100644 --- /dev/null +++ b/mlir/include/mlir-c/Dialect/OpenMP.h @@ -0,0 +1,26 @@ +//===-- mlir-c/Dialect/OpenMP.h - C API for OpenMP Dialect --------------*- 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 +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_C_DIALECT_OPENM_H +#define MLIR_C_DIALECT_OPENM_H + +#include "mlir-c/IR.h" + +#ifdef __cplusplus +extern "C" { +#endif + +MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(OpenMP, omp); + +#ifdef __cplusplus +} +#endif + +#endif // MLIR_C_DIALECT_OPENM_H diff --git a/mlir/lib/CAPI/Dialect/CMakeLists.txt b/mlir/lib/CAPI/Dialect/CMakeLists.txt --- a/mlir/lib/CAPI/Dialect/CMakeLists.txt +++ b/mlir/lib/CAPI/Dialect/CMakeLists.txt @@ -198,6 +198,15 @@ MLIRQuantDialect ) +add_mlir_upstream_c_api_library(MLIRCAPIOpenMP + OpenMP.cpp + + PARTIAL_SOURCES_INTENDED + LINK_LIBS PUBLIC + MLIRCAPIIR + MLIROpenMPDialect +) + add_mlir_upstream_c_api_library(MLIRCAPIPDL PDL.cpp diff --git a/mlir/lib/CAPI/Dialect/OpenMP.cpp b/mlir/lib/CAPI/Dialect/OpenMP.cpp new file mode 100644 --- /dev/null +++ b/mlir/lib/CAPI/Dialect/OpenMP.cpp @@ -0,0 +1,16 @@ +//===- OPENMP.cpp - C Interface for OPENMP dialect +//------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "mlir-c/Dialect/OpenMP.h" +#include "mlir/CAPI/Registration.h" +#include "mlir/Dialect/OpenMP/OpenMPDialect.h" + +using namespace mlir; + +MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(OpenMP, omp, omp::OpenMPDialect) diff --git a/mlir/python/CMakeLists.txt b/mlir/python/CMakeLists.txt --- a/mlir/python/CMakeLists.txt +++ b/mlir/python/CMakeLists.txt @@ -315,6 +315,14 @@ _mlir_libs/_mlir/dialects/pdl.pyi DIALECT_NAME pdl) +declare_mlir_dialect_python_bindings( + ADD_TO_PARENT MLIRPythonSources.Dialects + ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir" + TD_FILE dialects/OpenMPOps.td + SOURCES + dialects/openmp.py + DIALECT_NAME omp) + declare_mlir_dialect_python_bindings( ADD_TO_PARENT MLIRPythonSources.Dialects ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir" diff --git a/mlir/python/mlir/dialects/OpenMPOps.td b/mlir/python/mlir/dialects/OpenMPOps.td new file mode 100644 --- /dev/null +++ b/mlir/python/mlir/dialects/OpenMPOps.td @@ -0,0 +1,14 @@ +//===-- OpenMPOps.td - Entry point for OpenMPOps bind ------------*- 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 +// +//===----------------------------------------------------------------------===// + +#ifndef PYTHON_BINDINGS_OPENMP_OPS +#define PYTHON_BINDINGS_OPENMP_OPS + +include "mlir/Dialect/OpenMP/OpenMPOps.td" + +#endif diff --git a/mlir/python/mlir/dialects/openmp.py b/mlir/python/mlir/dialects/openmp.py new file mode 100644 --- /dev/null +++ b/mlir/python/mlir/dialects/openmp.py @@ -0,0 +1,5 @@ +# 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 + +from ._omp_ops_gen import * diff --git a/mlir/test/python/dialects/openmp_ops.py b/mlir/test/python/dialects/openmp_ops.py new file mode 100644 --- /dev/null +++ b/mlir/test/python/dialects/openmp_ops.py @@ -0,0 +1,23 @@ +# RUN: %PYTHON %s | FileCheck %s + +from mlir.ir import * +from mlir.dialects.openmp import * + + +def constructAndPrintInModule(f): + print("\nTEST:", f.__name__) + with Context(), Location.unknown(): + module = Module.create() + with InsertionPoint(module.body): + f() + print(module) + return f + + +# CHECK-LABEL: test_barrier +# CHECK: module { +# CHECK: omp.barrier +# CHECK: } +@constructAndPrintInModule +def test_barrier(): + barrier = BarrierOp()