-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[MLIR][Python] enable ptr dialect bindings #167270
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
Open
makslevental
wants to merge
2
commits into
main
Choose a base branch
from
users/makslevental/ptr-dialectpython
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
|
@llvm/pr-subscribers-mlir Author: Maksim Levental (makslevental) ChangesThis PR enables basic Python bindings for the Full diff: https://github.com/llvm/llvm-project/pull/167270.diff 4 Files Affected:
diff --git a/mlir/python/CMakeLists.txt b/mlir/python/CMakeLists.txt
index 51c75764faf3c..aa11090ac8463 100644
--- a/mlir/python/CMakeLists.txt
+++ b/mlir/python/CMakeLists.txt
@@ -516,6 +516,15 @@ declare_mlir_dialect_python_bindings(
GEN_ENUM_BINDINGS
)
+declare_mlir_dialect_python_bindings(
+ ADD_TO_PARENT MLIRPythonSources.Dialects
+ ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
+ TD_FILE dialects/PtrOps.td
+ SOURCES dialects/ptr.py
+ DIALECT_NAME ptr
+ GEN_ENUM_BINDINGS
+)
+
################################################################################
# Python extensions.
# The sources for these are all in lib/Bindings/Python, but since they have to
diff --git a/mlir/python/mlir/dialects/PtrOps.td b/mlir/python/mlir/dialects/PtrOps.td
new file mode 100644
index 0000000000000..8bde942c10192
--- /dev/null
+++ b/mlir/python/mlir/dialects/PtrOps.td
@@ -0,0 +1,14 @@
+//===- PTROps.td - Entry point for PTR bindings ------------*- 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 BINDINGS_PYTHON_PTR_OPS
+#define BINDINGS_PYTHON_PTR_OPS
+
+include "mlir/Dialect/Ptr/IR/PtrOps.td"
+
+#endif // BINDINGS_PYTHON_PTR_OPS
diff --git a/mlir/python/mlir/dialects/ptr.py b/mlir/python/mlir/dialects/ptr.py
new file mode 100644
index 0000000000000..a837b5b894dc6
--- /dev/null
+++ b/mlir/python/mlir/dialects/ptr.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 ._ptr_ops_gen import *
+from ._ptr_enum_gen import *
diff --git a/mlir/test/python/dialects/ptr.py b/mlir/test/python/dialects/ptr.py
new file mode 100644
index 0000000000000..ef0f26303afbf
--- /dev/null
+++ b/mlir/test/python/dialects/ptr.py
@@ -0,0 +1,21 @@
+# RUN: %PYTHON %s | FileCheck %s
+
+from mlir.dialects import ptr
+from mlir.ir import Context, Location, Module, InsertionPoint
+
+
+def run(f):
+ print("\nTEST:", f.__name__)
+ with Context(), Location.unknown():
+ module = Module.create()
+ with InsertionPoint(module.body):
+ f(module)
+ print(module)
+ assert module.operation.verify()
+
+
+# CHECK-LABEL: TEST: test_smoke
+@run
+def test_smoke(_module):
+ null = ptr.constant(True)
+ # CHECK: ptr.constant #ptr.null : !ptr.ptr<#ptr.generic_space>
|
7476e22 to
4aa9ab2
Compare
Contributor
|
Just in case, |
4aa9ab2 to
20c44e3
Compare
fabianmcg
approved these changes
Nov 11, 2025
Co-authored-by: Fabian Mora <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR enables basic Python bindings for the
ptrdialect.