[Mlir-commits] [mlir] fbfff1c - [MLIR][CAPI] Add C API dialect registration methods for Arith, Math, MemRef and Vector dialects

Alex Zinenko llvmlistbot at llvm.org
Mon Jul 17 07:45:56 PDT 2023


Author: Adam Paszke
Date: 2023-07-17T14:45:49Z
New Revision: fbfff1caff18eee5841c3946e58fa2d7964a1286

URL: https://github.com/llvm/llvm-project/commit/fbfff1caff18eee5841c3946e58fa2d7964a1286
DIFF: https://github.com/llvm/llvm-project/commit/fbfff1caff18eee5841c3946e58fa2d7964a1286.diff

LOG: [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

Added: 
    mlir/include/mlir-c/Dialect/Arith.h
    mlir/include/mlir-c/Dialect/Math.h
    mlir/include/mlir-c/Dialect/MemRef.h
    mlir/include/mlir-c/Dialect/Vector.h
    mlir/lib/CAPI/Dialect/Arith.cpp
    mlir/lib/CAPI/Dialect/Math.cpp
    mlir/lib/CAPI/Dialect/MemRef.cpp
    mlir/lib/CAPI/Dialect/Vector.cpp

Modified: 
    mlir/lib/CAPI/Dialect/CMakeLists.txt
    utils/bazel/llvm-project-overlay/mlir/BUILD.bazel

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir-c/Dialect/Arith.h b/mlir/include/mlir-c/Dialect/Arith.h
new file mode 100644
index 00000000000000..41e7cb2b3a34a2
--- /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 00000000000000..5269e1a1b2cb04
--- /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 00000000000000..087a4b3f85b1d8
--- /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 00000000000000..6256c82d172cef
--- /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 00000000000000..993f77e555ad99
--- /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 6c8454a79aa204..4b4ab74e6fc341 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 00000000000000..483e549a3cda56
--- /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 00000000000000..cfcdea9743ca3e
--- /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 00000000000000..c744b83b6990d9
--- /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 7e1d873572cdf3..3387854995366d 100644
--- a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
@@ -439,6 +439,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 = [
@@ -500,6 +513,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 = [
@@ -621,6 +660,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"],


        


More information about the Mlir-commits mailing list