Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MLIR][CAPI] Add MemRef pass bindings to the C API #73949

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

apaszke
Copy link
Member

@apaszke apaszke commented Nov 30, 2023

No description provided.

@llvmbot llvmbot added the mlir label Nov 30, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 30, 2023

@llvm/pr-subscribers-mlir

Author: Adam Paszke (apaszke)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/73949.diff

4 Files Affected:

  • (modified) mlir/include/mlir-c/Dialect/MemRef.h (+2)
  • (modified) mlir/lib/CAPI/Dialect/CMakeLists.txt (+1)
  • (added) mlir/lib/CAPI/Dialect/MemRefPasses.cpp (+27)
  • (modified) utils/bazel/llvm-project-overlay/mlir/BUILD.bazel (+21-1)
diff --git a/mlir/include/mlir-c/Dialect/MemRef.h b/mlir/include/mlir-c/Dialect/MemRef.h
index 087a4b3f85b1d80..327fe25143f8e8e 100644
--- a/mlir/include/mlir-c/Dialect/MemRef.h
+++ b/mlir/include/mlir-c/Dialect/MemRef.h
@@ -30,4 +30,6 @@ MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(MemRef, memref);
 }
 #endif
 
+#include "mlir/Dialect/MemRef/Transforms/Passes.capi.h.inc"
+
 #endif // MLIR_C_DIALECT_MEMREF_H
diff --git a/mlir/lib/CAPI/Dialect/CMakeLists.txt b/mlir/lib/CAPI/Dialect/CMakeLists.txt
index d815eba48d9b9df..b9cafcd299b94f6 100644
--- a/mlir/lib/CAPI/Dialect/CMakeLists.txt
+++ b/mlir/lib/CAPI/Dialect/CMakeLists.txt
@@ -51,6 +51,7 @@ add_mlir_upstream_c_api_library(MLIRCAPIMath
 
 add_mlir_upstream_c_api_library(MLIRCAPIMemRef
   MemRef.cpp
+  MemRefPasses.cpp
 
   PARTIAL_SOURCES_INTENDED
   LINK_LIBS PUBLIC
diff --git a/mlir/lib/CAPI/Dialect/MemRefPasses.cpp b/mlir/lib/CAPI/Dialect/MemRefPasses.cpp
new file mode 100644
index 000000000000000..ddc95a4f7733526
--- /dev/null
+++ b/mlir/lib/CAPI/Dialect/MemRefPasses.cpp
@@ -0,0 +1,27 @@
+//===- MemRefPasses.cpp - C API for MemRef 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/MemRef/Transforms/Passes.h"
+#include "mlir/Pass/Pass.h"
+
+// Must include the declarations as they carry important visibility attributes.
+#include "mlir/Dialect/MemRef/Transforms/Passes.capi.h.inc"
+
+using namespace mlir::memref;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "mlir/Dialect/MemRef/Transforms/Passes.capi.cpp.inc"
+
+#ifdef __cplusplus
+}
+#endif
+
diff --git a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
index 6ecf28424ba4a5c..1f20bb4f5aaf428 100644
--- a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
@@ -551,14 +551,20 @@ mlir_c_api_cc_library(
 
 mlir_c_api_cc_library(
     name = "CAPIMemRef",
-    srcs = ["lib/CAPI/Dialect/MemRef.cpp"],
+    srcs = [
+        "lib/CAPI/Dialect/MemRef.cpp",
+        "lib/CAPI/Dialect/MemRefPasses.cpp",
+    ],
     hdrs = ["include/mlir-c/Dialect/MemRef.h"],
     capi_deps = [
         ":CAPIIR",
     ],
+    header_deps = [":MemRefPassIncGen"],
     includes = ["include"],
     deps = [
         ":MemRefDialect",
+        ":MemRefTransforms",
+        ":Pass",
     ],
 )
 
@@ -12382,6 +12388,20 @@ gentbl_cc_library(
             ],
             "include/mlir/Dialect/MemRef/Transforms/Passes.h.inc",
         ),
+        (
+            [
+                "-gen-pass-capi-header",
+                "--prefix=MemRef",
+            ],
+            "include/mlir/Dialect/MemRef/Transforms/Passes.capi.h.inc",
+        ),
+        (
+            [
+                "-gen-pass-capi-impl",
+                "--prefix=MemRef",
+            ],
+            "include/mlir/Dialect/MemRef/Transforms/Passes.capi.cpp.inc",
+        ),
     ],
     tblgen = ":mlir-tblgen",
     td_file = "include/mlir/Dialect/MemRef/Transforms/Passes.td",

Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff 5234fe31547737f4fc9d312946cb647968734da1 b43e1c9fbd50829f795b22077ac5a7c2cd806624 -- mlir/lib/CAPI/Dialect/MemRefPasses.cpp mlir/include/mlir-c/Dialect/MemRef.h
View the diff from clang-format here.
diff --git a/mlir/lib/CAPI/Dialect/MemRefPasses.cpp b/mlir/lib/CAPI/Dialect/MemRefPasses.cpp
index ddc95a4f77..9928470e6e 100644
--- a/mlir/lib/CAPI/Dialect/MemRefPasses.cpp
+++ b/mlir/lib/CAPI/Dialect/MemRefPasses.cpp
@@ -24,4 +24,3 @@ extern "C" {
 #ifdef __cplusplus
 }
 #endif
-

Comment on lines +12391 to +12404
(
[
"-gen-pass-capi-header",
"--prefix=MemRef",
],
"include/mlir/Dialect/MemRef/Transforms/Passes.capi.h.inc",
),
(
[
"-gen-pass-capi-impl",
"--prefix=MemRef",
],
"include/mlir/Dialect/MemRef/Transforms/Passes.capi.cpp.inc",
),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need equivalent cmake changes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants