[Mlir-commits] [mlir] d68ba1f - [mlir] Register Linalg passes in C API and Python Bindings
Alex Zinenko
llvmlistbot at llvm.org
Sat Mar 27 01:58:03 PDT 2021
Author: Alex Zinenko
Date: 2021-03-27T09:57:56+01:00
New Revision: d68ba1fe50325fd29bbf1f589de9e55cbed017b0
URL: https://github.com/llvm/llvm-project/commit/d68ba1fe50325fd29bbf1f589de9e55cbed017b0
DIFF: https://github.com/llvm/llvm-project/commit/d68ba1fe50325fd29bbf1f589de9e55cbed017b0.diff
LOG: [mlir] Register Linalg passes in C API and Python Bindings
Provide a registration mechanism for Linalg dialect-specific passes in C
API and Python bindings. These are being built into the dialect library
but exposed in separate headers (C) or modules (Python).
Differential Revision: https://reviews.llvm.org/D99431
Added:
mlir/lib/Bindings/Python/LinalgPasses.cpp
mlir/lib/Bindings/Python/mlir/dialects/linalg/passes/__init__.py
mlir/lib/CAPI/Dialect/LinalgPasses.cpp
Modified:
mlir/include/mlir-c/Dialect/Linalg.h
mlir/include/mlir/Dialect/Linalg/CMakeLists.txt
mlir/lib/Bindings/Python/CMakeLists.txt
mlir/lib/CAPI/Dialect/CMakeLists.txt
Removed:
################################################################################
diff --git a/mlir/include/mlir-c/Dialect/Linalg.h b/mlir/include/mlir-c/Dialect/Linalg.h
index 56258ac19af4..be73a5c8c207 100644
--- a/mlir/include/mlir-c/Dialect/Linalg.h
+++ b/mlir/include/mlir-c/Dialect/Linalg.h
@@ -11,6 +11,7 @@
#define MLIR_C_DIALECT_LINALG_H
#include "mlir-c/Registration.h"
+#include "mlir-c/Support.h"
#ifdef __cplusplus
extern "C" {
@@ -22,4 +23,6 @@ MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(Linalg, linalg);
}
#endif
+#include "mlir/Dialect/Linalg/Passes.capi.h.inc"
+
#endif // MLIR_C_DIALECT_LINALG_H
diff --git a/mlir/include/mlir/Dialect/Linalg/CMakeLists.txt b/mlir/include/mlir/Dialect/Linalg/CMakeLists.txt
index d0edae3979e0..2c74207d6c95 100644
--- a/mlir/include/mlir/Dialect/Linalg/CMakeLists.txt
+++ b/mlir/include/mlir/Dialect/Linalg/CMakeLists.txt
@@ -2,6 +2,8 @@ add_subdirectory(IR)
set(LLVM_TARGET_DEFINITIONS Passes.td)
mlir_tablegen(Passes.h.inc -gen-pass-decls -name Linalg)
+mlir_tablegen(Passes.capi.h.inc -gen-pass-capi-header --prefix Linalg)
+mlir_tablegen(Passes.capi.cpp.inc -gen-pass-capi-impl --prefix Linalg)
add_public_tablegen_target(MLIRLinalgPassIncGen)
add_mlir_doc(Passes -gen-pass-doc LinalgPasses ./)
diff --git a/mlir/lib/Bindings/Python/CMakeLists.txt b/mlir/lib/Bindings/Python/CMakeLists.txt
index 5fefa80398c7..43d6275d4d20 100644
--- a/mlir/lib/Bindings/Python/CMakeLists.txt
+++ b/mlir/lib/Bindings/Python/CMakeLists.txt
@@ -118,3 +118,11 @@ endif()
add_subdirectory(Transforms)
add_subdirectory(Conversions)
+
+add_mlir_python_extension(MLIRLinalgPassesBindingsPythonExtension _mlirLinalgPasses
+ INSTALL_DIR
+ python
+ SOURCES
+ LinalgPasses.cpp
+)
+add_dependencies(MLIRBindingsPythonExtension MLIRLinalgPassesBindingsPythonExtension)
diff --git a/mlir/lib/Bindings/Python/LinalgPasses.cpp b/mlir/lib/Bindings/Python/LinalgPasses.cpp
new file mode 100644
index 000000000000..3f230207a421
--- /dev/null
+++ b/mlir/lib/Bindings/Python/LinalgPasses.cpp
@@ -0,0 +1,22 @@
+//===- LinalgPasses.cpp - Pybind module for the Linalg passes -------------===//
+//
+// 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/Linalg.h"
+
+#include <pybind11/pybind11.h>
+
+// -----------------------------------------------------------------------------
+// Module initialization.
+// -----------------------------------------------------------------------------
+
+PYBIND11_MODULE(_mlirLinalgPasses, m) {
+ m.doc() = "MLIR Linalg Dialect Passes";
+
+ // Register all Linalg passes on load.
+ mlirRegisterLinalgPasses();
+}
diff --git a/mlir/lib/Bindings/Python/mlir/dialects/linalg/passes/__init__.py b/mlir/lib/Bindings/Python/mlir/dialects/linalg/passes/__init__.py
new file mode 100644
index 000000000000..6555ad69a523
--- /dev/null
+++ b/mlir/lib/Bindings/Python/mlir/dialects/linalg/passes/__init__.py
@@ -0,0 +1,6 @@
+# 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 ...._cext_loader import _load_extension
+_cextLinalgPasses = _load_extension("_mlirLinalgPasses")
diff --git a/mlir/lib/CAPI/Dialect/CMakeLists.txt b/mlir/lib/CAPI/Dialect/CMakeLists.txt
index d256309bf8f0..41c659d6ab75 100644
--- a/mlir/lib/CAPI/Dialect/CMakeLists.txt
+++ b/mlir/lib/CAPI/Dialect/CMakeLists.txt
@@ -1,6 +1,7 @@
# TODO: Make the check source feature optional as an argument on *_add_library.
set(LLVM_OPTIONAL_SOURCES
Linalg.cpp
+ LinalgPasses.cpp
SCF.cpp
Shape.cpp
Standard.cpp
@@ -9,10 +10,16 @@ set(LLVM_OPTIONAL_SOURCES
add_mlir_public_c_api_library(MLIRCAPILinalg
Linalg.cpp
+ LinalgPasses.cpp
+
+ DEPENDS
+ MLIRLinalgPassIncGen
LINK_LIBS PUBLIC
MLIRCAPIIR
MLIRLinalg
+ MLIRPass
+ MLIRLinalgTransforms
)
add_mlir_public_c_api_library(MLIRCAPISCF
diff --git a/mlir/lib/CAPI/Dialect/LinalgPasses.cpp b/mlir/lib/CAPI/Dialect/LinalgPasses.cpp
new file mode 100644
index 000000000000..6677476d8a18
--- /dev/null
+++ b/mlir/lib/CAPI/Dialect/LinalgPasses.cpp
@@ -0,0 +1,26 @@
+//===- LinalgPasses.cpp - C API for Linalg Dialect Passes -----------------===//
+//
+// 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/CAPI/Pass.h"
+#include "mlir/Dialect/Linalg/Passes.h"
+#include "mlir/Pass/Pass.h"
+
+// Must include the declarations as they carry important visibility attributes.
+#include "mlir/Dialect/Linalg/Passes.capi.h.inc"
+
+using namespace mlir;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "mlir/Dialect/Linalg/Passes.capi.cpp.inc"
+
+#ifdef __cplusplus
+}
+#endif
More information about the Mlir-commits
mailing list