Skip to content

Conversation

Hardcode84
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Sep 5, 2025

@llvm/pr-subscribers-mlir

Author: Ivan Butygin (Hardcode84)

Changes

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 --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
+@constructAndPrintInModule
+def testSmoke():
+    # CHECK: Value(%{{.*}} = ub.poison : f32
+    f32 = F32Type.get()
+    poison = ub.poison(f32)
+    print(poison)
+    assert isinstance(poison, Value)

@llvmbot
Copy link
Member

llvmbot commented Sep 5, 2025

@llvm/pr-subscribers-mlir-ub

Author: Ivan Butygin (Hardcode84)

Changes

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 --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
+@constructAndPrintInModule
+def testSmoke():
+    # CHECK: Value(%{{.*}} = ub.poison : f32
+    f32 = F32Type.get()
+    poison = ub.poison(f32)
+    print(poison)
+    assert isinstance(poison, Value)

Copy link
Contributor

@makslevental makslevental left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Hardcode84 Hardcode84 merged commit dc85d0c into llvm:main Sep 5, 2025
13 checks passed
@Hardcode84 Hardcode84 deleted the ub-python branch September 5, 2025 15:52
rupprecht added a commit to rupprecht/llvm-project that referenced this pull request Sep 8, 2025
rupprecht added a commit that referenced this pull request Sep 8, 2025
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:ub mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants