[Mlir-commits] [mlir] [MLIR][Python] enable ptr dialect bindings (PR #167270)
Maksim Levental
llvmlistbot at llvm.org
Sun Nov 9 22:14:49 PST 2025
https://github.com/makslevental created https://github.com/llvm/llvm-project/pull/167270
This PR enables Python bindings for the `ptr` dialect. Follow-up PRs will bind types and attributes.
>From 7476e220501f9f8d3215c4f1ad3fbeb6d1b8632f Mon Sep 17 00:00:00 2001
From: makslevental <maksim.levental at gmail.com>
Date: Sun, 9 Nov 2025 22:14:12 -0800
Subject: [PATCH] [MLIR][Python] enable ptr dialect bindings
---
mlir/python/CMakeLists.txt | 9 +++++++++
mlir/python/mlir/dialects/PtrOps.td | 14 ++++++++++++++
mlir/python/mlir/dialects/ptr.py | 6 ++++++
mlir/test/python/dialects/ptr.py | 21 +++++++++++++++++++++
4 files changed, 50 insertions(+)
create mode 100644 mlir/python/mlir/dialects/PtrOps.td
create mode 100644 mlir/python/mlir/dialects/ptr.py
create mode 100644 mlir/test/python/dialects/ptr.py
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>
More information about the Mlir-commits
mailing list