https://github.com/makslevental created 
https://github.com/llvm/llvm-project/pull/174043

None

>From 71579b1df6a39d45f7c06b8d82ecb4a92df58262 Mon Sep 17 00:00:00 2001
From: makslevental <[email protected]>
Date: Tue, 30 Dec 2025 16:24:24 -0800
Subject: [PATCH] try twolevel_namespace

---
 mlir/cmake/modules/AddMLIRPython.cmake  |  4 ++-
 mlir/lib/Bindings/Python/IRCore.cpp     | 33 +++++++++++++++++++++++++
 mlir/lib/Bindings/Python/MainModule.cpp | 28 ---------------------
 3 files changed, 36 insertions(+), 29 deletions(-)

diff --git a/mlir/cmake/modules/AddMLIRPython.cmake 
b/mlir/cmake/modules/AddMLIRPython.cmake
index 57207ab0e2a18..3914716cb636c 100644
--- a/mlir/cmake/modules/AddMLIRPython.cmake
+++ b/mlir/cmake/modules/AddMLIRPython.cmake
@@ -875,7 +875,6 @@ function(add_mlir_python_extension libname extname 
nb_library_target_name)
   elseif(LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL)
     set(eh_rtti_enable -frtti -fexceptions)
   endif ()
-
   if(ARG__PRIVATE_SUPPORT_LIB)
     add_library(${libname} SHARED ${ARG_SOURCES})
     if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
@@ -908,6 +907,9 @@ function(add_mlir_python_extension libname extname 
nb_library_target_name)
     PRIVATE
     MLIR_BINDINGS_PYTHON_DOMAIN=${ARG_MLIR_BINDINGS_PYTHON_NB_DOMAIN}
   )
+  if(APPLE)
+    target_link_options(${libname} PRIVATE "LINKER:-twolevel_namespace")
+  endif()
 
   if (NOT MLIR_DISABLE_CONFIGURE_PYTHON_DEV_PACKAGES
       AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL))
diff --git a/mlir/lib/Bindings/Python/IRCore.cpp 
b/mlir/lib/Bindings/Python/IRCore.cpp
index a204dd7a4c3b8..16d1e74f72f39 100644
--- a/mlir/lib/Bindings/Python/IRCore.cpp
+++ b/mlir/lib/Bindings/Python/IRCore.cpp
@@ -1993,6 +1993,35 @@ intptr_t PyBlockArgumentList::getRawNumElements() {
   return mlirBlockGetNumArguments(block);
 }
 
+void PyBlockArgument::bindDerived(ClassTy &c) {
+  c.def_prop_ro(
+      "owner",
+      [](PyBlockArgument &self) {
+        return PyBlock(self.getParentOperation(),
+                       mlirBlockArgumentGetOwner(self.get()));
+      },
+      "Returns the block that owns this argument.");
+  c.def_prop_ro(
+      "arg_number",
+      [](PyBlockArgument &self) {
+        return mlirBlockArgumentGetArgNumber(self.get());
+      },
+      "Returns the position of this argument in the block's argument list.");
+  c.def(
+      "set_type",
+      [](PyBlockArgument &self, PyType type) {
+        return mlirBlockArgumentSetType(self.get(), type);
+      },
+      nanobind::arg("type"), "Sets the type of this block argument.");
+  c.def(
+      "set_location",
+      [](PyBlockArgument &self, PyLocation loc) {
+        return mlirBlockArgumentSetLocation(self.get(), loc);
+      },
+      nanobind::arg("loc"), "Sets the location of this block argument.");
+}
+
+
 PyBlockArgument PyBlockArgumentList::getRawElement(intptr_t pos) const {
   MlirValue argument = mlirBlockGetArgument(block, pos);
   return PyBlockArgument(operation, argument);
@@ -2178,3 +2207,7 @@ void PyOpAttributeMap::forEachAttr(
 } // namespace MLIR_BINDINGS_PYTHON_DOMAIN
 } // namespace python
 } // namespace mlir
+
+NB_MODULE(_mlirPythonSupport, m) {
+  m.doc() = "MLIR Python Support Extension";
+}
\ No newline at end of file
diff --git a/mlir/lib/Bindings/Python/MainModule.cpp 
b/mlir/lib/Bindings/Python/MainModule.cpp
index 9790a8feb8d03..b49a9f1e3af24 100644
--- a/mlir/lib/Bindings/Python/MainModule.cpp
+++ b/mlir/lib/Bindings/Python/MainModule.cpp
@@ -303,34 +303,6 @@ void PyOpResultList::bindDerived(ClassTy &c) {
       "Returns the operation that owns this result list.");
 }
 
-void PyBlockArgument::bindDerived(ClassTy &c) {
-  c.def_prop_ro(
-      "owner",
-      [](PyBlockArgument &self) {
-        return PyBlock(self.getParentOperation(),
-                       mlirBlockArgumentGetOwner(self.get()));
-      },
-      "Returns the block that owns this argument.");
-  c.def_prop_ro(
-      "arg_number",
-      [](PyBlockArgument &self) {
-        return mlirBlockArgumentGetArgNumber(self.get());
-      },
-      "Returns the position of this argument in the block's argument list.");
-  c.def(
-      "set_type",
-      [](PyBlockArgument &self, PyType type) {
-        return mlirBlockArgumentSetType(self.get(), type);
-      },
-      nanobind::arg("type"), "Sets the type of this block argument.");
-  c.def(
-      "set_location",
-      [](PyBlockArgument &self, PyLocation loc) {
-        return mlirBlockArgumentSetLocation(self.get(), loc);
-      },
-      nanobind::arg("loc"), "Sets the location of this block argument.");
-}
-
 void PyOpOperandList::bindDerived(ClassTy &c) {
   c.def("__setitem__", &PyOpOperandList::dunderSetItem, nanobind::arg("index"),
         nanobind::arg("value"),

_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to