[Mlir-commits] [mlir] [MLIR][Python] enable ptr dialect bindings (PR #167270)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Nov 9 22:15:21 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Maksim Levental (makslevental)

<details>
<summary>Changes</summary>

This PR enables basic Python bindings for the `ptr` dialect. Follow-up PRs will bind types and attributes.

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


4 Files Affected:

- (modified) mlir/python/CMakeLists.txt (+9) 
- (added) mlir/python/mlir/dialects/PtrOps.td (+14) 
- (added) mlir/python/mlir/dialects/ptr.py (+6) 
- (added) mlir/test/python/dialects/ptr.py (+21) 


``````````diff
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
+ at run
+def test_smoke(_module):
+    null = ptr.constant(True)
+    # CHECK: ptr.constant #ptr.null : !ptr.ptr<#ptr.generic_space>

``````````

</details>


https://github.com/llvm/llvm-project/pull/167270


More information about the Mlir-commits mailing list