Skip to content

Conversation

@makslevental
Copy link
Contributor

@makslevental makslevental commented Nov 10, 2025

This PR enables basic Python bindings for the ptr dialect.

@llvmbot
Copy link
Member

llvmbot commented Nov 10, 2025

@llvm/pr-subscribers-mlir

Author: Maksim Levental (makslevental)

Changes

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 --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> 
@makslevental makslevental force-pushed the users/makslevental/ptr-dialectpython branch from 7476e22 to 4aa9ab2 Compare November 10, 2025 06:40
@makslevental makslevental marked this pull request as draft November 10, 2025 06:40
@fabianmcg
Copy link
Contributor

Just in case, ptr uses properties in most cases, thus with the current state of props in python, I don't know how useful the bindings will be.

@makslevental makslevental force-pushed the users/makslevental/ptr-dialectpython branch from 4aa9ab2 to 20c44e3 Compare November 11, 2025 07:51
@makslevental makslevental marked this pull request as ready for review November 11, 2025 17:11
Co-authored-by: Fabian Mora <fmora.dev@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mlir:python MLIR Python bindings mlir

4 participants