[Mlir-commits] [mlir] dc85d0c - [mlir][python] UB dialect python bindings (#157127)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Sep 5 08:52:04 PDT 2025


Author: Ivan Butygin
Date: 2025-09-05T18:52:01+03:00
New Revision: dc85d0c4fa9e9a1258806facf20f928d846a3040

URL: https://github.com/llvm/llvm-project/commit/dc85d0c4fa9e9a1258806facf20f928d846a3040
DIFF: https://github.com/llvm/llvm-project/commit/dc85d0c4fa9e9a1258806facf20f928d846a3040.diff

LOG: [mlir][python] UB dialect python bindings (#157127)

Added: 
    mlir/python/mlir/dialects/UBOps.td
    mlir/python/mlir/dialects/ub.py
    mlir/test/python/dialects/ub.py

Modified: 
    mlir/include/mlir/Dialect/UB/IR/UBOps.td
    mlir/python/CMakeLists.txt

Removed: 
    


################################################################################
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)


        


More information about the Mlir-commits mailing list