From fbfff1caff18eee5841c3946e58fa2d7964a1286 Mon Sep 17 00:00:00 2001 From: Adam Paszke Date: Mon, 17 Jul 2023 14:32:31 +0000 Subject: [PATCH] [MLIR][CAPI] Add C API dialect registration methods for Arith, Math, MemRef and Vector dialects Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D155450 --- mlir/include/mlir-c/Dialect/Arith.h | 33 ++++++++++++++ mlir/include/mlir-c/Dialect/Math.h | 33 ++++++++++++++ mlir/include/mlir-c/Dialect/MemRef.h | 33 ++++++++++++++ mlir/include/mlir-c/Dialect/Vector.h | 33 ++++++++++++++ mlir/lib/CAPI/Dialect/Arith.cpp | 13 ++++++ mlir/lib/CAPI/Dialect/CMakeLists.txt | 36 ++++++++++++++++ mlir/lib/CAPI/Dialect/Math.cpp | 13 ++++++ mlir/lib/CAPI/Dialect/MemRef.cpp | 14 ++++++ mlir/lib/CAPI/Dialect/Vector.cpp | 14 ++++++ utils/bazel/llvm-project-overlay/mlir/BUILD.bazel | 52 +++++++++++++++++++++++ 10 files changed, 274 insertions(+) create mode 100644 mlir/include/mlir-c/Dialect/Arith.h create mode 100644 mlir/include/mlir-c/Dialect/Math.h create mode 100644 mlir/include/mlir-c/Dialect/MemRef.h create mode 100644 mlir/include/mlir-c/Dialect/Vector.h create mode 100644 mlir/lib/CAPI/Dialect/Arith.cpp create mode 100644 mlir/lib/CAPI/Dialect/Math.cpp create mode 100644 mlir/lib/CAPI/Dialect/MemRef.cpp create mode 100644 mlir/lib/CAPI/Dialect/Vector.cpp diff --git a/mlir/include/mlir-c/Dialect/Arith.h b/mlir/include/mlir-c/Dialect/Arith.h new file mode 100644 index 0000000..41e7cb2 --- /dev/null +++ b/mlir/include/mlir-c/Dialect/Arith.h @@ -0,0 +1,33 @@ +//===-- mlir-c/Dialect/Arith.h - C API for Arith 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 +// +//===----------------------------------------------------------------------===// +// +// This header declares the C interface for registering and accessing the +// Arith dialect. A dialect should be registered with a context to make it +// available to users of the context. These users must load the dialect +// before using any of its attributes, operations or types. Parser and pass +// manager can load registered dialects automatically. +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_C_DIALECT_ARITH_H +#define MLIR_C_DIALECT_ARITH_H + +#include "mlir-c/IR.h" + +#ifdef __cplusplus +extern "C" { +#endif + +MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(Arith, arith); + +#ifdef __cplusplus +} +#endif + +#endif // MLIR_C_DIALECT_ARITH_H diff --git a/mlir/include/mlir-c/Dialect/Math.h b/mlir/include/mlir-c/Dialect/Math.h new file mode 100644 index 0000000..5269e1a --- /dev/null +++ b/mlir/include/mlir-c/Dialect/Math.h @@ -0,0 +1,33 @@ +//===-- mlir-c/Dialect/Math.h - C API for Math 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 +// +//===----------------------------------------------------------------------===// +// +// This header declares the C interface for registering and accessing the +// Math dialect. A dialect should be registered with a context to make it +// available to users of the context. These users must load the dialect +// before using any of its attributes, operations or types. Parser and pass +// manager can load registered dialects automatically. +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_C_DIALECT_MATH_H +#define MLIR_C_DIALECT_MATH_H + +#include "mlir-c/IR.h" + +#ifdef __cplusplus +extern "C" { +#endif + +MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(Math, math); + +#ifdef __cplusplus +} +#endif + +#endif // MLIR_C_DIALECT_MATH_H diff --git a/mlir/include/mlir-c/Dialect/MemRef.h b/mlir/include/mlir-c/Dialect/MemRef.h new file mode 100644 index 0000000..087a4b3 --- /dev/null +++ b/mlir/include/mlir-c/Dialect/MemRef.h @@ -0,0 +1,33 @@ +//===-- mlir-c/Dialect/MemRef.h - C API for MemRef 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 +// +//===----------------------------------------------------------------------===// +// +// This header declares the C interface for registering and accessing the +// MemRef dialect. A dialect should be registered with a context to make it +// available to users of the context. These users must load the dialect +// before using any of its attributes, operations or types. Parser and pass +// manager can load registered dialects automatically. +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_C_DIALECT_MEMREF_H +#define MLIR_C_DIALECT_MEMREF_H + +#include "mlir-c/IR.h" + +#ifdef __cplusplus +extern "C" { +#endif + +MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(MemRef, memref); + +#ifdef __cplusplus +} +#endif + +#endif // MLIR_C_DIALECT_MEMREF_H diff --git a/mlir/include/mlir-c/Dialect/Vector.h b/mlir/include/mlir-c/Dialect/Vector.h new file mode 100644 index 0000000..6256c82 --- /dev/null +++ b/mlir/include/mlir-c/Dialect/Vector.h @@ -0,0 +1,33 @@ +//===-- mlir-c/Dialect/Vector.h - C API for Vector 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 +// +//===----------------------------------------------------------------------===// +// +// This header declares the C interface for registering and accessing the +// Vector dialect. A dialect should be registered with a context to make it +// available to users of the context. These users must load the dialect +// before using any of its attributes, operations or types. Parser and pass +// manager can load registered dialects automatically. +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_C_DIALECT_VECTOR_H +#define MLIR_C_DIALECT_VECTOR_H + +#include "mlir-c/IR.h" + +#ifdef __cplusplus +extern "C" { +#endif + +MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(Vector, vector); + +#ifdef __cplusplus +} +#endif + +#endif // MLIR_C_DIALECT_VECTOR_H diff --git a/mlir/lib/CAPI/Dialect/Arith.cpp b/mlir/lib/CAPI/Dialect/Arith.cpp new file mode 100644 index 0000000..993f77e --- /dev/null +++ b/mlir/lib/CAPI/Dialect/Arith.cpp @@ -0,0 +1,13 @@ +//===- Arith.cpp - C Interface for Arith 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/Arith.h" +#include "mlir/CAPI/Registration.h" +#include "mlir/Dialect/Arith/IR/Arith.h" + +MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Arith, arith, mlir::arith::ArithDialect) diff --git a/mlir/lib/CAPI/Dialect/CMakeLists.txt b/mlir/lib/CAPI/Dialect/CMakeLists.txt index 6c8454a..4b4ab74 100644 --- a/mlir/lib/CAPI/Dialect/CMakeLists.txt +++ b/mlir/lib/CAPI/Dialect/CMakeLists.txt @@ -1,3 +1,12 @@ +add_mlir_upstream_c_api_library(MLIRCAPIArith + Arith.cpp + + PARTIAL_SOURCES_INTENDED + LINK_LIBS PUBLIC + MLIRCAPIIR + MLIRArithDialect +) + add_mlir_upstream_c_api_library(MLIRCAPIAsync Async.cpp AsyncPasses.cpp @@ -22,6 +31,24 @@ add_mlir_upstream_c_api_library(MLIRCAPIControlFlow MLIRControlFlowDialect ) +add_mlir_upstream_c_api_library(MLIRCAPIMath + Math.cpp + + PARTIAL_SOURCES_INTENDED + LINK_LIBS PUBLIC + MLIRCAPIIR + MLIRMathDialect +) + +add_mlir_upstream_c_api_library(MLIRCAPIMemRef + MemRef.cpp + + PARTIAL_SOURCES_INTENDED + LINK_LIBS PUBLIC + MLIRCAPIIR + MLIRMemRefDialect +) + add_mlir_upstream_c_api_library(MLIRCAPIGPU GPU.cpp GPUPasses.cpp @@ -142,3 +169,12 @@ add_mlir_upstream_c_api_library(MLIRCAPIPDL MLIRCAPIIR MLIRPDLDialect ) + +add_mlir_upstream_c_api_library(MLIRCAPIVector + Vector.cpp + + PARTIAL_SOURCES_INTENDED + LINK_LIBS PUBLIC + MLIRCAPIIR + MLIRVectorDialect +) diff --git a/mlir/lib/CAPI/Dialect/Math.cpp b/mlir/lib/CAPI/Dialect/Math.cpp new file mode 100644 index 0000000..483e549 --- /dev/null +++ b/mlir/lib/CAPI/Dialect/Math.cpp @@ -0,0 +1,13 @@ +//===- Math.cpp - C Interface for Math 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/Math.h" +#include "mlir/CAPI/Registration.h" +#include "mlir/Dialect/Math/IR/Math.h" + +MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Math, math, mlir::math::MathDialect) diff --git a/mlir/lib/CAPI/Dialect/MemRef.cpp b/mlir/lib/CAPI/Dialect/MemRef.cpp new file mode 100644 index 0000000..cfcdea9 --- /dev/null +++ b/mlir/lib/CAPI/Dialect/MemRef.cpp @@ -0,0 +1,14 @@ +//===- MemRef.cpp - C Interface for MemRef 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/MemRef.h" +#include "mlir/CAPI/Registration.h" +#include "mlir/Dialect/MemRef/IR/MemRef.h" + +MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(MemRef, memref, + mlir::memref::MemRefDialect) diff --git a/mlir/lib/CAPI/Dialect/Vector.cpp b/mlir/lib/CAPI/Dialect/Vector.cpp new file mode 100644 index 0000000..c744b83 --- /dev/null +++ b/mlir/lib/CAPI/Dialect/Vector.cpp @@ -0,0 +1,14 @@ +//===- Vector.cpp - C Interface for Vector 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/Vector.h" +#include "mlir/CAPI/Registration.h" +#include "mlir/Dialect/Vector/IR/VectorOps.h" + +MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Vector, vector, + mlir::vector::VectorDialect) diff --git a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel index 7e1d873..3387854 100644 --- a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel @@ -440,6 +440,19 @@ mlir_c_api_cc_library( ) mlir_c_api_cc_library( + name = "CAPIArith", + srcs = ["lib/CAPI/Dialect/Arith.cpp"], + hdrs = ["include/mlir-c/Dialect/Arith.h"], + capi_deps = [ + ":CAPIIR", + ], + includes = ["include"], + deps = [ + ":ArithDialect", + ], +) + +mlir_c_api_cc_library( name = "CAPIAsync", srcs = [ "lib/CAPI/Dialect/Async.cpp", @@ -501,6 +514,32 @@ mlir_c_api_cc_library( ) mlir_c_api_cc_library( + name = "CAPIMath", + srcs = ["lib/CAPI/Dialect/Math.cpp"], + hdrs = ["include/mlir-c/Dialect/Math.h"], + capi_deps = [ + ":CAPIIR", + ], + includes = ["include"], + deps = [ + ":MathDialect", + ], +) + +mlir_c_api_cc_library( + name = "CAPIMemRef", + srcs = ["lib/CAPI/Dialect/MemRef.cpp"], + hdrs = ["include/mlir-c/Dialect/MemRef.h"], + capi_deps = [ + ":CAPIIR", + ], + includes = ["include"], + deps = [ + ":MemRefDialect", + ], +) + +mlir_c_api_cc_library( name = "CAPIGPU", srcs = [ "lib/CAPI/Dialect/GPU.cpp", @@ -622,6 +661,19 @@ mlir_c_api_cc_library( ) mlir_c_api_cc_library( + name = "CAPIVector", + srcs = ["lib/CAPI/Dialect/Vector.cpp"], + hdrs = ["include/mlir-c/Dialect/Vector.h"], + capi_deps = [ + ":CAPIIR", + ], + includes = ["include"], + deps = [ + ":VectorDialect", + ], +) + +mlir_c_api_cc_library( name = "CAPIConversion", srcs = ["lib/CAPI/Conversion/Passes.cpp"], hdrs = ["include/mlir-c/Conversion.h"], -- 2.7.4