[Mlir-commits] [mlir] [mlir][python] UB dialect python bindings (PR #157127)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Sep 5 08:37:46 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-ub
Author: Ivan Butygin (Hardcode84)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/157127.diff
5 Files Affected:
- (modified) mlir/include/mlir/Dialect/UB/IR/UBOps.td (+1-1)
- (modified) mlir/python/CMakeLists.txt (+8-1)
- (added) mlir/python/mlir/dialects/UBOps.td (+14)
- (added) mlir/python/mlir/dialects/ub.py (+5)
- (added) mlir/test/python/dialects/ub.py (+27)
``````````diff
diff --git a/mlir/include/mlir/Dialect/UB/IR/UBOps.td b/mlir/include/mlir/Dialect/UB/IR/UBOps.td
index f3d5a26ef6f9b..c400a2ef2cc7a 100644
--- a/mlir/include/mlir/Dialect/UB/IR/UBOps.td
+++ b/mlir/include/mlir/Dialect/UB/IR/UBOps.td
@@ -12,7 +12,7 @@
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/IR/AttrTypeBase.td"
-include "UBOpsInterfaces.td"
+include "mlir/Dialect/UB/IR/UBOpsInterfaces.td"
def UB_Dialect : Dialect {
let name = "ub";
diff --git a/mlir/python/CMakeLists.txt b/mlir/python/CMakeLists.txt
index 7a0c95ebb8200..c983914722ce1 100644
--- a/mlir/python/CMakeLists.txt
+++ b/mlir/python/CMakeLists.txt
@@ -453,6 +453,14 @@ declare_mlir_dialect_python_bindings(
DIALECT_NAME tosa
)
+declare_mlir_dialect_python_bindings(
+ ADD_TO_PARENT MLIRPythonSources.Dialects
+ ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
+ TD_FILE dialects/UBOps.td
+ SOURCES dialects/ub.py
+ DIALECT_NAME ub
+)
+
declare_mlir_dialect_python_bindings(
ADD_TO_PARENT MLIRPythonSources.Dialects
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
@@ -847,4 +855,3 @@ add_mlir_python_modules(MLIRPythonModules
COMMON_CAPI_LINK_LIBS
MLIRPythonCAPI
)
-
diff --git a/mlir/python/mlir/dialects/UBOps.td b/mlir/python/mlir/dialects/UBOps.td
new file mode 100644
index 0000000000000..b84e7f15fa78f
--- /dev/null
+++ b/mlir/python/mlir/dialects/UBOps.td
@@ -0,0 +1,14 @@
+//===-- UBOps.td - Entry point for UB 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 PYTHON_BINDINGS_UB_OPS
+#define PYTHON_BINDINGS_UB_OPS
+
+include "mlir/Dialect/UB/IR/UBOps.td"
+
+#endif // PYTHON_BINDINGS_UB_OPS
diff --git a/mlir/python/mlir/dialects/ub.py b/mlir/python/mlir/dialects/ub.py
new file mode 100644
index 0000000000000..32e8706745302
--- /dev/null
+++ b/mlir/python/mlir/dialects/ub.py
@@ -0,0 +1,5 @@
+# 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 ._ub_ops_gen import *
diff --git a/mlir/test/python/dialects/ub.py b/mlir/test/python/dialects/ub.py
new file mode 100644
index 0000000000000..0d88da82c5e7b
--- /dev/null
+++ b/mlir/test/python/dialects/ub.py
@@ -0,0 +1,27 @@
+# RUN: %PYTHON %s | FileCheck %s
+# This is just a smoke test that the dialect is functional.
+from array import array
+
+from mlir.ir import *
+from mlir.dialects import ub
+from mlir.extras import types as T
+
+
+def constructAndPrintInModule(f):
+ print("\nTEST:", f.__name__)
+ with Context(), Location.unknown():
+ module = Module.create()
+ with InsertionPoint(module.body):
+ f()
+ print(module)
+ return f
+
+
+# CHECK-LABEL: testSmoke
+ at constructAndPrintInModule
+def testSmoke():
+ # CHECK: Value(%{{.*}} = ub.poison : f32
+ f32 = F32Type.get()
+ poison = ub.poison(f32)
+ print(poison)
+ assert isinstance(poison, Value)
``````````
</details>
https://github.com/llvm/llvm-project/pull/157127
More information about the Mlir-commits
mailing list