[Mlir-commits] [mlir] [MLIR][Python] Remove partial LLVM APIs in python bindings (4/n) (PR #180256)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Feb 6 11:52:37 PST 2026


https://github.com/RattataKing updated https://github.com/llvm/llvm-project/pull/180256

>From f7a5d994b8df1b476414a8327b3844ef47f5cff9 Mon Sep 17 00:00:00 2001
From: Amily Wu <amilywu2 at amd.com>
Date: Fri, 6 Feb 2026 00:23:12 +0000
Subject: [PATCH 01/10] Replace twine with detail::join

---
 mlir/lib/Bindings/Python/Globals.cpp      | 27 +++++++--------
 mlir/lib/Bindings/Python/IRAffine.cpp     | 24 ++++++-------
 mlir/lib/Bindings/Python/IRInterfaces.cpp | 42 ++++++++++-------------
 mlir/lib/Bindings/Python/IRTypes.cpp      | 10 ++----
 4 files changed, 46 insertions(+), 57 deletions(-)

diff --git a/mlir/lib/Bindings/Python/Globals.cpp b/mlir/lib/Bindings/Python/Globals.cpp
index 1fcd83c15c6ce..6a22573ab6bd0 100644
--- a/mlir/lib/Bindings/Python/Globals.cpp
+++ b/mlir/lib/Bindings/Python/Globals.cpp
@@ -86,11 +86,11 @@ void PyGlobals::registerAttributeBuilder(const std::string &attributeKind,
   nb::ft_lock_guard lock(mutex);
   nb::object &found = attributeBuilderMap[attributeKind];
   if (found && !replace) {
-    throw std::runtime_error((llvm::Twine("Attribute builder for '") +
-                              attributeKind +
-                              "' is already registered with func: " +
-                              nb::cast<std::string>(nb::str(found)))
-                                 .str());
+    throw std::runtime_error(nanobind::detail::join(
+        "Attribute builder for '", attributeKind,
+        "' is already registered with func: ",
+        nb::cast<std::string>(nb::str(found)))
+                                 .c_str());
   }
   found = std::move(pyFunc);
 }
@@ -120,9 +120,9 @@ void PyGlobals::registerDialectImpl(const std::string &dialectNamespace,
   nb::ft_lock_guard lock(mutex);
   nb::object &found = dialectClassMap[dialectNamespace];
   if (found) {
-    throw std::runtime_error((llvm::Twine("Dialect namespace '") +
-                              dialectNamespace + "' is already registered.")
-                                 .str());
+    throw std::runtime_error(nanobind::detail::join(
+        "Dialect namespace '", dialectNamespace,
+        "' is already registered.").c_str());
   }
   found = std::move(pyClass);
 }
@@ -132,9 +132,8 @@ void PyGlobals::registerOperationImpl(const std::string &operationName,
   nb::ft_lock_guard lock(mutex);
   nb::object &found = operationClassMap[operationName];
   if (found && !replace) {
-    throw std::runtime_error((llvm::Twine("Operation '") + operationName +
-                              "' is already registered.")
-                                 .str());
+    throw std::runtime_error(nanobind::detail::join(
+        "Operation '", operationName, "' is already registered.").c_str());
   }
   found = std::move(pyClass);
 }
@@ -144,9 +143,9 @@ void PyGlobals::registerOpAdaptorImpl(const std::string &operationName,
   nb::ft_lock_guard lock(mutex);
   nb::object &found = opAdaptorClassMap[operationName];
   if (found && !replace) {
-    throw std::runtime_error((llvm::Twine("Operation adaptor of '") +
-                              operationName + "' is already registered.")
-                                 .str());
+    throw std::runtime_error(nanobind::detail::join(
+        "Operation adaptor of '", operationName,
+        "' is already registered.").c_str());
   }
   found = std::move(pyClass);
 }
diff --git a/mlir/lib/Bindings/Python/IRAffine.cpp b/mlir/lib/Bindings/Python/IRAffine.cpp
index 2e760e6e6f830..eb472582d9c2c 100644
--- a/mlir/lib/Bindings/Python/IRAffine.cpp
+++ b/mlir/lib/Bindings/Python/IRAffine.cpp
@@ -26,7 +26,6 @@
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/Twine.h"
 
 namespace nb = nanobind;
 using namespace mlir;
@@ -34,7 +33,6 @@ using namespace mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN;
 
 using llvm::SmallVector;
 using llvm::StringRef;
-using llvm::Twine;
 
 static const char kDumpDocstring[] =
     R"(Dumps a debug representation of the object to stderr.)";
@@ -52,14 +50,16 @@ static void pyListToVector(const nb::list &list,
     try {
       result.push_back(nb::cast<PyType>(item));
     } catch (nb::cast_error &err) {
-      std::string msg = (llvm::Twine("Invalid expression when ") + action +
-                         " (" + err.what() + ")")
-                            .str();
+      std::string msg = nanobind::detail::join(
+                             "Invalid expression when ", action.str(), " (",
+                             err.what(), ")")
+                             .c_str();
       throw std::runtime_error(msg.c_str());
     } catch (std::runtime_error &err) {
-      std::string msg = (llvm::Twine("Invalid expression (None?) when ") +
-                         action + " (" + err.what() + ")")
-                            .str();
+      std::string msg = nanobind::detail::join(
+                             "Invalid expression (None?) when ", action.str(),
+                             " (", err.what(), ")")
+                             .c_str();
       throw std::runtime_error(msg.c_str());
     }
   }
@@ -106,11 +106,9 @@ class PyConcreteAffineExpr : public BaseTy {
   static MlirAffineExpr castFrom(PyAffineExpr &orig) {
     if (!DerivedTy::isaFunction(orig)) {
       auto origRepr = nb::cast<std::string>(nb::repr(nb::cast(orig)));
-      throw nb::value_error((Twine("Cannot cast affine expression to ") +
-                             DerivedTy::pyClassName + " (from " + origRepr +
-                             ")")
-                                .str()
-                                .c_str());
+      throw nb::value_error(nanobind::detail::join(
+          "Cannot cast affine expression to ", DerivedTy::pyClassName,
+          " (from ", origRepr, ")").c_str());
     }
     return orig;
   }
diff --git a/mlir/lib/Bindings/Python/IRInterfaces.cpp b/mlir/lib/Bindings/Python/IRInterfaces.cpp
index 09112d4989ae4..743d1a5d09228 100644
--- a/mlir/lib/Bindings/Python/IRInterfaces.cpp
+++ b/mlir/lib/Bindings/Python/IRInterfaces.cpp
@@ -19,7 +19,6 @@
 #include "mlir/Bindings/Python/IRCore.h"
 #include "mlir/Bindings/Python/Nanobind.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SmallVector.h"
 
 namespace nb = nanobind;
 
@@ -48,10 +47,10 @@ its return shaped type components. Raises ValueError on failure.)";
 
 namespace {
 
-/// Takes in an optional ist of operands and converts them into a SmallVector
-/// of MlirVlaues. Returns an empty SmallVector if the list is empty.
-llvm::SmallVector<MlirValue> wrapOperands(std::optional<nb::list> operandList) {
-  llvm::SmallVector<MlirValue> mlirOperands;
+/// Takes in an optional ist of operands and converts them into a std::vector
+/// of MlirVlaues. Returns an empty std::vector if the list is empty.
+std::vector<MlirValue> wrapOperands(std::optional<nb::list> operandList) {
+  std::vector<MlirValue> mlirOperands;
 
   if (!operandList || operandList->size() == 0) {
     return mlirOperands;
@@ -84,20 +83,17 @@ llvm::SmallVector<MlirValue> wrapOperands(std::optional<nb::list> operandList) {
             throw nb::cast_error();
           mlirOperands.push_back(val->get());
         } catch (nb::cast_error &err) {
-          throw nb::value_error(
-              (llvm::Twine("Operand ") + llvm::Twine(it.index()) +
-               " must be a Value or Sequence of Values (" + err.what() + ")")
-                  .str()
-                  .c_str());
+          throw nb::value_error(nanobind::detail::join(
+              "Operand ", it.index(),
+              " must be a Value or Sequence of Values (", err.what(), ")")
+                                    .c_str());
         }
       }
       continue;
     } catch (nb::cast_error &err) {
-      throw nb::value_error((llvm::Twine("Operand ") + llvm::Twine(it.index()) +
-                             " must be a Value or Sequence of Values (" +
-                             err.what() + ")")
-                                .str()
-                                .c_str());
+      throw nb::value_error(nanobind::detail::join(
+          "Operand ", it.index(), " must be a Value or Sequence of Values (",
+          err.what(), ")").c_str());
     }
 
     throw nb::cast_error();
@@ -106,11 +102,11 @@ llvm::SmallVector<MlirValue> wrapOperands(std::optional<nb::list> operandList) {
   return mlirOperands;
 }
 
-/// Takes in an optional vector of PyRegions and returns a SmallVector of
-/// MlirRegion. Returns an empty SmallVector if the list is empty.
-llvm::SmallVector<MlirRegion>
+/// Takes in an optional vector of PyRegions and returns a std::vector of
+/// MlirRegion. Returns an empty std::vector if the list is empty.
+std::vector<MlirRegion>
 wrapRegions(std::optional<std::vector<PyRegion>> regions) {
-  llvm::SmallVector<MlirRegion> mlirRegions;
+  std::vector<MlirRegion> mlirRegions;
 
   if (regions) {
     mlirRegions.reserve(regions->size());
@@ -273,9 +269,9 @@ class PyInferTypeOpInterface
                    std::optional<std::vector<PyRegion>> regions,
                    DefaultingPyMlirContext context,
                    DefaultingPyLocation location) {
-    llvm::SmallVector<MlirValue> mlirOperands =
+    std::vector<MlirValue> mlirOperands =
         wrapOperands(std::move(operandList));
-    llvm::SmallVector<MlirRegion> mlirRegions = wrapRegions(std::move(regions));
+    std::vector<MlirRegion> mlirRegions = wrapRegions(std::move(regions));
 
     std::vector<PyType> inferredTypes;
     PyMlirContext &pyContext = context.resolve();
@@ -430,9 +426,9 @@ class PyInferShapedTypeOpInterface
       std::optional<PyAttribute> attributes, void *properties,
       std::optional<std::vector<PyRegion>> regions,
       DefaultingPyMlirContext context, DefaultingPyLocation location) {
-    llvm::SmallVector<MlirValue> mlirOperands =
+    std::vector<MlirValue> mlirOperands =
         wrapOperands(std::move(operandList));
-    llvm::SmallVector<MlirRegion> mlirRegions = wrapRegions(std::move(regions));
+    std::vector<MlirRegion> mlirRegions = wrapRegions(std::move(regions));
 
     std::vector<PyShapedTypeComponents> inferredShapedTypeComponents;
     PyMlirContext &pyContext = context.resolve();
diff --git a/mlir/lib/Bindings/Python/IRTypes.cpp b/mlir/lib/Bindings/Python/IRTypes.cpp
index 94327f67e050e..965b98994e02b 100644
--- a/mlir/lib/Bindings/Python/IRTypes.cpp
+++ b/mlir/lib/Bindings/Python/IRTypes.cpp
@@ -24,7 +24,6 @@ using namespace mlir;
 using namespace mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN;
 
 using llvm::SmallVector;
-using llvm::Twine;
 
 namespace mlir {
 namespace python {
@@ -310,12 +309,9 @@ void PyComplexType::bindDerived(ClassTy &c) {
           MlirType t = mlirComplexTypeGet(elementType);
           return PyComplexType(elementType.getContext(), t);
         }
-        throw nb::value_error(
-            (Twine("invalid '") +
-             nb::cast<std::string>(nb::repr(nb::cast(elementType))) +
-             "' and expected floating point or integer type.")
-                .str()
-                .c_str());
+        throw nb::value_error(nanobind::detail::join(
+            "invalid '", nb::cast<std::string>(nb::repr(nb::cast(elementType))),
+            "' and expected floating point or integer type.").c_str());
       },
       "Create a complex type");
   c.def_prop_ro(

>From ca8ea14211c0435b2950be630cfa4a6ec6f9e8e8 Mon Sep 17 00:00:00 2001
From: Amily Wu <amilywu2 at amd.com>
Date: Fri, 6 Feb 2026 16:37:46 +0000
Subject: [PATCH 02/10] Replace enum

---
 mlir/lib/Bindings/Python/IRInterfaces.cpp | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/mlir/lib/Bindings/Python/IRInterfaces.cpp b/mlir/lib/Bindings/Python/IRInterfaces.cpp
index 743d1a5d09228..474e4efa1602b 100644
--- a/mlir/lib/Bindings/Python/IRInterfaces.cpp
+++ b/mlir/lib/Bindings/Python/IRInterfaces.cpp
@@ -18,7 +18,6 @@
 #include "mlir-c/Support.h"
 #include "mlir/Bindings/Python/IRCore.h"
 #include "mlir/Bindings/Python/Nanobind.h"
-#include "llvm/ADT/STLExtras.h"
 
 namespace nb = nanobind;
 
@@ -58,13 +57,15 @@ std::vector<MlirValue> wrapOperands(std::optional<nb::list> operandList) {
 
   // Note: as the list may contain other lists this may not be final size.
   mlirOperands.reserve(operandList->size());
-  for (const auto &&it : llvm::enumerate(*operandList)) {
-    if (it.value().is_none())
+  for (size_t i = 0, e = operandList->size(); i < e; ++i) {
+    nb::handle operand = (*operandList)[i];
+    intptr_t index = static_cast<intptr_t>(i);
+    if (operand.is_none())
       continue;
 
     PyValue *val;
     try {
-      val = nb::cast<PyValue *>(it.value());
+      val = nb::cast<PyValue *>(operand);
       if (!val)
         throw nb::cast_error();
       mlirOperands.push_back(val->get());
@@ -75,7 +76,7 @@ std::vector<MlirValue> wrapOperands(std::optional<nb::list> operandList) {
     }
 
     try {
-      auto vals = nb::cast<nb::sequence>(it.value());
+      auto vals = nb::cast<nb::sequence>(operand);
       for (nb::handle v : vals) {
         try {
           val = nb::cast<PyValue *>(v);
@@ -84,7 +85,7 @@ std::vector<MlirValue> wrapOperands(std::optional<nb::list> operandList) {
           mlirOperands.push_back(val->get());
         } catch (nb::cast_error &err) {
           throw nb::value_error(nanobind::detail::join(
-              "Operand ", it.index(),
+              "Operand ", index,
               " must be a Value or Sequence of Values (", err.what(), ")")
                                     .c_str());
         }
@@ -92,7 +93,7 @@ std::vector<MlirValue> wrapOperands(std::optional<nb::list> operandList) {
       continue;
     } catch (nb::cast_error &err) {
       throw nb::value_error(nanobind::detail::join(
-          "Operand ", it.index(), " must be a Value or Sequence of Values (",
+          "Operand ", index, " must be a Value or Sequence of Values (",
           err.what(), ")").c_str());
     }
 

>From 993494e4b5dee3bca3fdf80faa77245c6141a8ab Mon Sep 17 00:00:00 2001
From: Amily Wu <amilywu2 at amd.com>
Date: Fri, 6 Feb 2026 17:02:46 +0000
Subject: [PATCH 03/10] Replace stringRef with string_view

---
 mlir/include/mlir/Bindings/Python/Globals.h |  3 +-
 mlir/lib/Bindings/Python/Globals.cpp        | 36 ++++++++++++---------
 mlir/lib/Bindings/Python/IRAffine.cpp       | 11 +++----
 3 files changed, 26 insertions(+), 24 deletions(-)

diff --git a/mlir/include/mlir/Bindings/Python/Globals.h b/mlir/include/mlir/Bindings/Python/Globals.h
index bdcabea76cd3c..23cccdd36279a 100644
--- a/mlir/include/mlir/Bindings/Python/Globals.h
+++ b/mlir/include/mlir/Bindings/Python/Globals.h
@@ -23,7 +23,6 @@
 #include "mlir/CAPI/Support.h"
 
 #include "llvm/ADT/StringExtras.h"
-#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Regex.h"
 
 namespace mlir {
@@ -127,7 +126,7 @@ class MLIR_PYTHON_API_EXPORTED PyGlobals {
   /// name. Note that this may trigger a load of the dialect, which can
   /// arbitrarily re-enter.
   std::optional<nanobind::object>
-  lookupOpAdaptorClass(llvm::StringRef operationName);
+  lookupOpAdaptorClass(std::string_view operationName);
 
   class MLIR_PYTHON_API_EXPORTED TracebackLoc {
   public:
diff --git a/mlir/lib/Bindings/Python/Globals.cpp b/mlir/lib/Bindings/Python/Globals.cpp
index 6a22573ab6bd0..b3b7619ad34e6 100644
--- a/mlir/lib/Bindings/Python/Globals.cpp
+++ b/mlir/lib/Bindings/Python/Globals.cpp
@@ -86,11 +86,11 @@ void PyGlobals::registerAttributeBuilder(const std::string &attributeKind,
   nb::ft_lock_guard lock(mutex);
   nb::object &found = attributeBuilderMap[attributeKind];
   if (found && !replace) {
-    throw std::runtime_error(nanobind::detail::join(
-        "Attribute builder for '", attributeKind,
-        "' is already registered with func: ",
-        nb::cast<std::string>(nb::str(found)))
-                                 .c_str());
+    throw std::runtime_error(
+        nanobind::detail::join("Attribute builder for '", attributeKind,
+                               "' is already registered with func: ",
+                               nb::cast<std::string>(nb::str(found)))
+            .c_str());
   }
   found = std::move(pyFunc);
 }
@@ -120,9 +120,10 @@ void PyGlobals::registerDialectImpl(const std::string &dialectNamespace,
   nb::ft_lock_guard lock(mutex);
   nb::object &found = dialectClassMap[dialectNamespace];
   if (found) {
-    throw std::runtime_error(nanobind::detail::join(
-        "Dialect namespace '", dialectNamespace,
-        "' is already registered.").c_str());
+    throw std::runtime_error(nanobind::detail::join("Dialect namespace '",
+                                                    dialectNamespace,
+                                                    "' is already registered.")
+                                 .c_str());
   }
   found = std::move(pyClass);
 }
@@ -132,8 +133,10 @@ void PyGlobals::registerOperationImpl(const std::string &operationName,
   nb::ft_lock_guard lock(mutex);
   nb::object &found = operationClassMap[operationName];
   if (found && !replace) {
-    throw std::runtime_error(nanobind::detail::join(
-        "Operation '", operationName, "' is already registered.").c_str());
+    throw std::runtime_error(nanobind::detail::join("Operation '",
+                                                    operationName,
+                                                    "' is already registered.")
+                                 .c_str());
   }
   found = std::move(pyClass);
 }
@@ -143,9 +146,10 @@ void PyGlobals::registerOpAdaptorImpl(const std::string &operationName,
   nb::ft_lock_guard lock(mutex);
   nb::object &found = opAdaptorClassMap[operationName];
   if (found && !replace) {
-    throw std::runtime_error(nanobind::detail::join(
-        "Operation adaptor of '", operationName,
-        "' is already registered.").c_str());
+    throw std::runtime_error(nanobind::detail::join("Operation adaptor of '",
+                                                    operationName,
+                                                    "' is already registered.")
+                                 .c_str());
   }
   found = std::move(pyClass);
 }
@@ -221,10 +225,10 @@ PyGlobals::lookupOperationClass(std::string_view operationName) {
 }
 
 std::optional<nb::object>
-PyGlobals::lookupOpAdaptorClass(llvm::StringRef operationName) {
+PyGlobals::lookupOpAdaptorClass(std::string_view operationName) {
   // Make sure dialect module is loaded.
-  auto split = operationName.split('.');
-  llvm::StringRef dialectNamespace = split.first;
+  std::string_view dialectNamespace =
+      operationName.substr(0, operationName.find('.'));
   (void)loadDialectModule(dialectNamespace);
 
   nb::ft_lock_guard lock(mutex);
diff --git a/mlir/lib/Bindings/Python/IRAffine.cpp b/mlir/lib/Bindings/Python/IRAffine.cpp
index eb472582d9c2c..c0674567dcccd 100644
--- a/mlir/lib/Bindings/Python/IRAffine.cpp
+++ b/mlir/lib/Bindings/Python/IRAffine.cpp
@@ -10,6 +10,7 @@
 #include <cstdint>
 #include <stdexcept>
 #include <string>
+#include <string_view>
 #include <utility>
 #include <vector>
 
@@ -25,14 +26,12 @@
 #include "mlir/Support/LLVM.h"
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/StringRef.h"
 
 namespace nb = nanobind;
 using namespace mlir;
 using namespace mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN;
 
 using llvm::SmallVector;
-using llvm::StringRef;
 
 static const char kDumpDocstring[] =
     R"(Dumps a debug representation of the object to stderr.)";
@@ -44,21 +43,21 @@ static const char kDumpDocstring[] =
 template <typename PyType, typename CType>
 static void pyListToVector(const nb::list &list,
                            llvm::SmallVectorImpl<CType> &result,
-                           StringRef action) {
+                           std::string_view action) {
   result.reserve(nb::len(list));
   for (nb::handle item : list) {
     try {
       result.push_back(nb::cast<PyType>(item));
     } catch (nb::cast_error &err) {
       std::string msg = nanobind::detail::join(
-                             "Invalid expression when ", action.str(), " (",
+                             "Invalid expression when ", action, " (",
                              err.what(), ")")
                              .c_str();
       throw std::runtime_error(msg.c_str());
     } catch (std::runtime_error &err) {
       std::string msg = nanobind::detail::join(
-                             "Invalid expression (None?) when ", action.str(),
-                             " (", err.what(), ")")
+                             "Invalid expression (None?) when ", action, " (",
+                             err.what(), ")")
                              .c_str();
       throw std::runtime_error(msg.c_str());
     }

>From 46e8204b9728987de2549111502ea6188a1b79fe Mon Sep 17 00:00:00 2001
From: Amily Wu <amilywu2 at amd.com>
Date: Fri, 6 Feb 2026 17:54:22 +0000
Subject: [PATCH 04/10] Clean some SmallVector

---
 .../mlir/Bindings/Python/IRAttributes.h       | 11 ++--
 .../Bindings/Python/ExecutionEngineModule.cpp |  5 +-
 mlir/lib/Bindings/Python/IRAffine.cpp         | 52 +++++++++----------
 mlir/lib/Bindings/Python/IRAttributes.cpp     | 21 ++++----
 mlir/lib/Bindings/Python/IRInterfaces.cpp     | 23 ++++----
 mlir/lib/Bindings/Python/IRTypes.cpp          |  9 ++--
 6 files changed, 64 insertions(+), 57 deletions(-)

diff --git a/mlir/include/mlir/Bindings/Python/IRAttributes.h b/mlir/include/mlir/Bindings/Python/IRAttributes.h
index 5ff9afd0875f1..d5d5548602114 100644
--- a/mlir/include/mlir/Bindings/Python/IRAttributes.h
+++ b/mlir/include/mlir/Bindings/Python/IRAttributes.h
@@ -13,6 +13,7 @@
 #include <string>
 #include <string_view>
 #include <utility>
+#include <vector>
 
 #include "mlir-c/BuiltinAttributes.h"
 #include "mlir-c/BuiltinTypes.h"
@@ -31,13 +32,13 @@ struct nb_buffer_info {
   ssize_t size = 0;
   const char *format = nullptr;
   ssize_t ndim = 0;
-  SmallVector<ssize_t, 4> shape;
-  SmallVector<ssize_t, 4> strides;
+  std::vector<ssize_t> shape;
+  std::vector<ssize_t> strides;
   bool readonly = false;
 
   nb_buffer_info(
       void *ptr, ssize_t itemsize, const char *format, ssize_t ndim,
-      SmallVector<ssize_t, 4> shape_in, SmallVector<ssize_t, 4> strides_in,
+      std::vector<ssize_t> shape_in, std::vector<ssize_t> strides_in,
       bool readonly = false,
       std::unique_ptr<Py_buffer, void (*)(Py_buffer *)> owned_view_in =
           std::unique_ptr<Py_buffer, void (*)(Py_buffer *)>(nullptr, nullptr));
@@ -462,11 +463,11 @@ class MLIR_PYTHON_API_EXPORTED PyDenseElementsAttribute
     Type *data = static_cast<Type *>(
         const_cast<void *>(mlirDenseElementsAttrGetRawData(*this)));
     // Prepare the shape for the buffer_info.
-    SmallVector<intptr_t, 4> shape;
+    std::vector<ssize_t> shape;
     for (intptr_t i = 0; i < rank; ++i)
       shape.push_back(mlirShapedTypeGetDimSize(shapedType, i));
     // Prepare the strides for the buffer_info.
-    SmallVector<intptr_t, 4> strides;
+    std::vector<ssize_t> strides;
     if (mlirDenseElementsAttrIsSplat(*this)) {
       // Splats are special, only the single value is stored.
       strides.assign(rank, 0);
diff --git a/mlir/lib/Bindings/Python/ExecutionEngineModule.cpp b/mlir/lib/Bindings/Python/ExecutionEngineModule.cpp
index 01b7930deffd2..76dbd54ef0467 100644
--- a/mlir/lib/Bindings/Python/ExecutionEngineModule.cpp
+++ b/mlir/lib/Bindings/Python/ExecutionEngineModule.cpp
@@ -6,6 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include <vector>
+
 #include "mlir-c/ExecutionEngine.h"
 #include "mlir/Bindings/Python/IRCore.h"
 #include "mlir/Bindings/Python/Nanobind.h"
@@ -83,7 +85,8 @@ NB_MODULE(_mlirExecutionEngine, m) {
           [](PyExecutionEngine &self, PyModule &module, int optLevel,
              const std::vector<std::string> &sharedLibPaths,
              bool enableObjectDump, bool enablePIC) {
-            llvm::SmallVector<MlirStringRef, 4> libPaths;
+            std::vector<MlirStringRef> libPaths;
+            libPaths.reserve(sharedLibPaths.size());
             for (const std::string &path : sharedLibPaths)
               libPaths.push_back({path.c_str(), path.length()});
             MlirExecutionEngine executionEngine = mlirExecutionEngineCreate(
diff --git a/mlir/lib/Bindings/Python/IRAffine.cpp b/mlir/lib/Bindings/Python/IRAffine.cpp
index c0674567dcccd..2c86e31e29625 100644
--- a/mlir/lib/Bindings/Python/IRAffine.cpp
+++ b/mlir/lib/Bindings/Python/IRAffine.cpp
@@ -8,6 +8,7 @@
 
 #include <cstddef>
 #include <cstdint>
+#include <memory>
 #include <stdexcept>
 #include <string>
 #include <string_view>
@@ -25,14 +26,11 @@
 #include "mlir/Bindings/Python/Nanobind.h"
 #include "mlir/Support/LLVM.h"
 #include "llvm/ADT/Hashing.h"
-#include "llvm/ADT/SmallVector.h"
 
 namespace nb = nanobind;
 using namespace mlir;
 using namespace mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN;
 
-using llvm::SmallVector;
-
 static const char kDumpDocstring[] =
     R"(Dumps a debug representation of the object to stderr.)";
 
@@ -41,24 +39,22 @@ static const char kDumpDocstring[] =
 /// Throws errors in case of failure, using "action" to describe what the caller
 /// was attempting to do.
 template <typename PyType, typename CType>
-static void pyListToVector(const nb::list &list,
-                           llvm::SmallVectorImpl<CType> &result,
+static void pyListToVector(const nb::list &list, std::vector<CType> &result,
                            std::string_view action) {
   result.reserve(nb::len(list));
   for (nb::handle item : list) {
     try {
       result.push_back(nb::cast<PyType>(item));
     } catch (nb::cast_error &err) {
-      std::string msg = nanobind::detail::join(
-                             "Invalid expression when ", action, " (",
-                             err.what(), ")")
-                             .c_str();
+      std::string msg = nanobind::detail::join("Invalid expression when ",
+                                               action, " (", err.what(), ")")
+                            .c_str();
       throw std::runtime_error(msg.c_str());
     } catch (std::runtime_error &err) {
-      std::string msg = nanobind::detail::join(
-                             "Invalid expression (None?) when ", action, " (",
-                             err.what(), ")")
-                             .c_str();
+      std::string msg =
+          nanobind::detail::join("Invalid expression (None?) when ", action,
+                                 " (", err.what(), ")")
+              .c_str();
       throw std::runtime_error(msg.c_str());
     }
   }
@@ -66,7 +62,7 @@ static void pyListToVector(const nb::list &list,
 
 template <typename PermutationTy>
 static bool isPermutation(const std::vector<PermutationTy> &permutation) {
-  llvm::SmallVector<bool, 8> seen(permutation.size(), false);
+  std::vector<bool> seen(permutation.size(), false);
   for (auto val : permutation) {
     if (val < permutation.size()) {
       if (seen[val])
@@ -105,9 +101,11 @@ class PyConcreteAffineExpr : public BaseTy {
   static MlirAffineExpr castFrom(PyAffineExpr &orig) {
     if (!DerivedTy::isaFunction(orig)) {
       auto origRepr = nb::cast<std::string>(nb::repr(nb::cast(orig)));
-      throw nb::value_error(nanobind::detail::join(
-          "Cannot cast affine expression to ", DerivedTy::pyClassName,
-          " (from ", origRepr, ")").c_str());
+      throw nb::value_error(
+          nanobind::detail::join("Cannot cast affine expression to ",
+                                 DerivedTy::pyClassName, " (from ", origRepr,
+                                 ")")
+              .c_str());
     }
     return orig;
   }
@@ -741,7 +739,7 @@ void populateIRAffine(nb::module_ &m) {
       .def_static(
           "compress_unused_symbols",
           [](const nb::list &affineMaps, DefaultingPyMlirContext context) {
-            SmallVector<MlirAffineMap> maps;
+            std::vector<MlirAffineMap> maps;
             pyListToVector<PyAffineMap, MlirAffineMap>(
                 affineMaps, maps, "attempting to create an AffineMap");
             std::vector<MlirAffineMap> compressed(affineMaps.size());
@@ -769,7 +767,7 @@ void populateIRAffine(nb::module_ &m) {
           "get",
           [](intptr_t dimCount, intptr_t symbolCount, const nb::list &exprs,
              DefaultingPyMlirContext context) {
-            SmallVector<MlirAffineExpr> affineExprs;
+            std::vector<MlirAffineExpr> affineExprs;
             pyListToVector<PyAffineExpr, MlirAffineExpr>(
                 exprs, affineExprs, "attempting to create an AffineMap");
             MlirAffineMap map =
@@ -943,17 +941,18 @@ void populateIRAffine(nb::module_ &m) {
             if (exprs.size() == 0)
               throw nb::value_error("Expected non-empty list of constraints");
 
-            // Copy over to a SmallVector because std::vector has a
-            // specialization for booleans that packs data and does not
-            // expose a `bool *`.
-            SmallVector<bool, 8> flags(eqFlags.begin(), eqFlags.end());
+            // std::vector<bool> does not expose a bool* data pointer.
+            std::unique_ptr<bool[]> flags =
+                std::make_unique<bool[]>(eqFlags.size());
+            for (size_t i = 0, e = eqFlags.size(); i < e; ++i)
+              flags[i] = eqFlags[i];
 
-            SmallVector<MlirAffineExpr> affineExprs;
+            std::vector<MlirAffineExpr> affineExprs;
             pyListToVector<PyAffineExpr>(exprs, affineExprs,
                                          "attempting to create an IntegerSet");
             MlirIntegerSet set = mlirIntegerSetGet(
                 context->get(), numDims, numSymbols, exprs.size(),
-                affineExprs.data(), flags.data());
+                affineExprs.data(), flags.get());
             return PyIntegerSet(context->getRef(), set);
           },
           nb::arg("num_dims"), nb::arg("num_symbols"), nb::arg("exprs"),
@@ -984,7 +983,8 @@ void populateIRAffine(nb::module_ &m) {
                   "Expected the number of symbol replacement expressions "
                   "to match that of symbols");
 
-            SmallVector<MlirAffineExpr> dimAffineExprs, symbolAffineExprs;
+            std::vector<MlirAffineExpr> dimAffineExprs;
+            std::vector<MlirAffineExpr> symbolAffineExprs;
             pyListToVector<PyAffineExpr>(
                 dimExprs, dimAffineExprs,
                 "attempting to create an IntegerSet by replacing dimensions");
diff --git a/mlir/lib/Bindings/Python/IRAttributes.cpp b/mlir/lib/Bindings/Python/IRAttributes.cpp
index 05c0c5e825df3..7be613b571569 100644
--- a/mlir/lib/Bindings/Python/IRAttributes.cpp
+++ b/mlir/lib/Bindings/Python/IRAttributes.cpp
@@ -12,6 +12,7 @@
 #include <string>
 #include <string_view>
 #include <utility>
+#include <vector>
 
 #include "mlir-c/BuiltinAttributes.h"
 #include "mlir-c/BuiltinTypes.h"
@@ -28,8 +29,6 @@ using namespace nanobind::literals;
 using namespace mlir;
 using namespace mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN;
 
-using llvm::SmallVector;
-
 //------------------------------------------------------------------------------
 // Docstrings (trivial, non-duplicated docstrings are included inline).
 //------------------------------------------------------------------------------
@@ -129,7 +128,7 @@ namespace MLIR_BINDINGS_PYTHON_DOMAIN {
 
 nb_buffer_info::nb_buffer_info(
     void *ptr, ssize_t itemsize, const char *format, ssize_t ndim,
-    SmallVector<ssize_t, 4> shape_in, SmallVector<ssize_t, 4> strides_in,
+    std::vector<ssize_t> shape_in, std::vector<ssize_t> strides_in,
     bool readonly,
     std::unique_ptr<Py_buffer, void (*)(Py_buffer *)> owned_view_in)
     : ptr(ptr), itemsize(itemsize), format(format), ndim(ndim),
@@ -255,7 +254,7 @@ void PyArrayAttribute::bindDerived(ClassTy &c) {
   c.def_static(
       "get",
       [](const nb::list &attributes, DefaultingPyMlirContext context) {
-        SmallVector<MlirAttribute> mlirAttributes;
+        std::vector<MlirAttribute> mlirAttributes;
         mlirAttributes.reserve(nb::len(attributes));
         for (auto attribute : attributes) {
           mlirAttributes.push_back(pyTryCast<PyAttribute>(attribute));
@@ -465,7 +464,7 @@ PySymbolRefAttribute::fromList(const std::vector<std::string> &symbols,
     throw std::runtime_error("SymbolRefAttr must be composed of at least "
                              "one symbol.");
   MlirStringRef rootSymbol = toMlirStringRef(symbols[0]);
-  SmallVector<MlirAttribute, 3> referenceAttrs;
+  std::vector<MlirAttribute> referenceAttrs;
   for (size_t i = 1; i < symbols.size(); ++i) {
     referenceAttrs.push_back(
         mlirFlatSymbolRefAttrGet(context.get(), toMlirStringRef(symbols[i])));
@@ -574,14 +573,14 @@ PyDenseElementsAttribute::getFromList(const nb::list &attributes,
     }
     shapedType = *explicitType;
   } else {
-    SmallVector<int64_t> shape = {static_cast<int64_t>(numAttributes)};
+    std::vector<int64_t> shape = {static_cast<int64_t>(numAttributes)};
     shapedType = mlirRankedTensorTypeGet(
         shape.size(), shape.data(),
         mlirAttributeGetType(pyTryCast<PyAttribute>(attributes[0])),
         mlirAttributeGetNull());
   }
 
-  SmallVector<MlirAttribute> mlirAttributes;
+  std::vector<MlirAttribute> mlirAttributes;
   mlirAttributes.reserve(numAttributes);
   for (const nb::handle &attribute : attributes) {
     MlirAttribute mlirAttribute = pyTryCast<PyAttribute>(attribute);
@@ -810,11 +809,11 @@ bool PyDenseElementsAttribute::isSignedIntegerFormat(std::string_view format) {
 MlirType PyDenseElementsAttribute::getShapedType(
     std::optional<MlirType> bulkLoadElementType,
     std::optional<std::vector<int64_t>> explicitShape, Py_buffer &view) {
-  SmallVector<int64_t> shape;
+  std::vector<int64_t> shape;
   if (explicitShape) {
-    shape.append(explicitShape->begin(), explicitShape->end());
+    shape.insert(shape.end(), explicitShape->begin(), explicitShape->end());
   } else {
-    shape.append(view.shape, view.shape + view.ndim);
+    shape.insert(shape.end(), view.shape, view.shape + view.ndim);
   }
 
   if (mlirTypeIsAShaped(*bulkLoadElementType)) {
@@ -1199,7 +1198,7 @@ void PyDictAttribute::bindDerived(ClassTy &c) {
   c.def_static(
       "get",
       [](const nb::dict &attributes, DefaultingPyMlirContext context) {
-        SmallVector<MlirNamedAttribute> mlirNamedAttributes;
+        std::vector<MlirNamedAttribute> mlirNamedAttributes;
         mlirNamedAttributes.reserve(attributes.size());
         for (std::pair<nb::handle, nb::handle> it : attributes) {
           auto &mlirAttr = nb::cast<PyAttribute &>(it.second);
diff --git a/mlir/lib/Bindings/Python/IRInterfaces.cpp b/mlir/lib/Bindings/Python/IRInterfaces.cpp
index 474e4efa1602b..be60426473e0d 100644
--- a/mlir/lib/Bindings/Python/IRInterfaces.cpp
+++ b/mlir/lib/Bindings/Python/IRInterfaces.cpp
@@ -84,17 +84,20 @@ std::vector<MlirValue> wrapOperands(std::optional<nb::list> operandList) {
             throw nb::cast_error();
           mlirOperands.push_back(val->get());
         } catch (nb::cast_error &err) {
-          throw nb::value_error(nanobind::detail::join(
-              "Operand ", index,
-              " must be a Value or Sequence of Values (", err.what(), ")")
-                                    .c_str());
+          throw nb::value_error(
+              nanobind::detail::join("Operand ", index,
+                                     " must be a Value or Sequence of Values (",
+                                     err.what(), ")")
+                  .c_str());
         }
       }
       continue;
     } catch (nb::cast_error &err) {
-      throw nb::value_error(nanobind::detail::join(
-          "Operand ", index, " must be a Value or Sequence of Values (",
-          err.what(), ")").c_str());
+      throw nb::value_error(
+          nanobind::detail::join("Operand ", index,
+                                 " must be a Value or Sequence of Values (",
+                                 err.what(), ")")
+              .c_str());
     }
 
     throw nb::cast_error();
@@ -270,8 +273,7 @@ class PyInferTypeOpInterface
                    std::optional<std::vector<PyRegion>> regions,
                    DefaultingPyMlirContext context,
                    DefaultingPyLocation location) {
-    std::vector<MlirValue> mlirOperands =
-        wrapOperands(std::move(operandList));
+    std::vector<MlirValue> mlirOperands = wrapOperands(std::move(operandList));
     std::vector<MlirRegion> mlirRegions = wrapRegions(std::move(regions));
 
     std::vector<PyType> inferredTypes;
@@ -427,8 +429,7 @@ class PyInferShapedTypeOpInterface
       std::optional<PyAttribute> attributes, void *properties,
       std::optional<std::vector<PyRegion>> regions,
       DefaultingPyMlirContext context, DefaultingPyLocation location) {
-    std::vector<MlirValue> mlirOperands =
-        wrapOperands(std::move(operandList));
+    std::vector<MlirValue> mlirOperands = wrapOperands(std::move(operandList));
     std::vector<MlirRegion> mlirRegions = wrapRegions(std::move(regions));
 
     std::vector<PyShapedTypeComponents> inferredShapedTypeComponents;
diff --git a/mlir/lib/Bindings/Python/IRTypes.cpp b/mlir/lib/Bindings/Python/IRTypes.cpp
index 965b98994e02b..a8e60f099ef67 100644
--- a/mlir/lib/Bindings/Python/IRTypes.cpp
+++ b/mlir/lib/Bindings/Python/IRTypes.cpp
@@ -309,9 +309,12 @@ void PyComplexType::bindDerived(ClassTy &c) {
           MlirType t = mlirComplexTypeGet(elementType);
           return PyComplexType(elementType.getContext(), t);
         }
-        throw nb::value_error(nanobind::detail::join(
-            "invalid '", nb::cast<std::string>(nb::repr(nb::cast(elementType))),
-            "' and expected floating point or integer type.").c_str());
+        throw nb::value_error(
+            nanobind::detail::join(
+                "invalid '",
+                nb::cast<std::string>(nb::repr(nb::cast(elementType))),
+                "' and expected floating point or integer type.")
+                .c_str());
       },
       "Create a complex type");
   c.def_prop_ro(

>From 0678eddcd11894d0902a1bf36740c30a265052c3 Mon Sep 17 00:00:00 2001
From: Amily Wu <amilywu2 at amd.com>
Date: Fri, 6 Feb 2026 18:11:37 +0000
Subject: [PATCH 05/10] Replace raw_string_ostream with detail::join

---
 mlir/lib/Bindings/Python/IRAttributes.cpp | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/mlir/lib/Bindings/Python/IRAttributes.cpp b/mlir/lib/Bindings/Python/IRAttributes.cpp
index 7be613b571569..e2abb14e7bd87 100644
--- a/mlir/lib/Bindings/Python/IRAttributes.cpp
+++ b/mlir/lib/Bindings/Python/IRAttributes.cpp
@@ -22,7 +22,6 @@
 #include "mlir/Bindings/Python/NanobindAdaptors.h"
 #include "mlir/Bindings/Python/NanobindUtils.h"
 #include "llvm/ADT/ScopeExit.h"
-#include "llvm/Support/raw_ostream.h"
 
 namespace nb = nanobind;
 using namespace nanobind::literals;
@@ -565,10 +564,9 @@ PyDenseElementsAttribute::getFromList(const nb::list &attributes,
     if ((!mlirTypeIsAShaped(*explicitType) ||
          !mlirShapedTypeHasStaticShape(*explicitType))) {
 
-      std::string message;
-      llvm::raw_string_ostream os(message);
-      os << "Expected a static ShapedType for the shaped_type parameter: "
-         << nb::cast<std::string>(nb::repr(nb::cast(*explicitType)));
+      std::string message = nanobind::detail::join(
+          "Expected a static ShapedType for the shaped_type parameter: ",
+          nb::cast<std::string>(nb::repr(nb::cast(*explicitType))));
       throw nb::value_error(message.c_str());
     }
     shapedType = *explicitType;
@@ -588,12 +586,11 @@ PyDenseElementsAttribute::getFromList(const nb::list &attributes,
     mlirAttributes.push_back(mlirAttribute);
 
     if (!mlirTypeEqual(mlirShapedTypeGetElementType(shapedType), attrType)) {
-      std::string message;
-      llvm::raw_string_ostream os(message);
-      os << "All attributes must be of the same type and match "
-         << "the type parameter: expected="
-         << nb::cast<std::string>(nb::repr(nb::cast(shapedType)))
-         << ", but got=" << nb::cast<std::string>(nb::repr(nb::cast(attrType)));
+      std::string message = nanobind::detail::join(
+          "All attributes must be of the same type and match the type "
+          "parameter: expected=",
+          nb::cast<std::string>(nb::repr(nb::cast(shapedType))),
+          ", but got=", nb::cast<std::string>(nb::repr(nb::cast(attrType))));
       throw nb::value_error(message.c_str());
     }
   }

>From 37c93af49a28171fc8134c219b60b72798d17226 Mon Sep 17 00:00:00 2001
From: Amily Wu <amilywu2 at amd.com>
Date: Fri, 6 Feb 2026 18:17:37 +0000
Subject: [PATCH 06/10] Clean hash

---
 mlir/lib/Bindings/Python/IRAffine.cpp | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/mlir/lib/Bindings/Python/IRAffine.cpp b/mlir/lib/Bindings/Python/IRAffine.cpp
index 2c86e31e29625..9fb2cfde2d340 100644
--- a/mlir/lib/Bindings/Python/IRAffine.cpp
+++ b/mlir/lib/Bindings/Python/IRAffine.cpp
@@ -25,7 +25,6 @@
 #include "mlir-c/IntegerSet.h"
 #include "mlir/Bindings/Python/Nanobind.h"
 #include "mlir/Support/LLVM.h"
-#include "llvm/ADT/Hashing.h"
 
 namespace nb = nanobind;
 using namespace mlir;
@@ -597,7 +596,7 @@ void populateIRAffine(nb::module_ &m) {
            })
       .def("__hash__",
            [](PyAffineExpr &self) {
-             return static_cast<size_t>(llvm::hash_value(self.get().ptr));
+             return std::hash<const void *>{}(self.get().ptr);
            })
       .def_prop_ro(
           "context",
@@ -734,7 +733,7 @@ void populateIRAffine(nb::module_ &m) {
            })
       .def("__hash__",
            [](PyAffineMap &self) {
-             return static_cast<size_t>(llvm::hash_value(self.get().ptr));
+             return std::hash<const void *>{}(self.get().ptr);
            })
       .def_static(
           "compress_unused_symbols",
@@ -920,7 +919,7 @@ void populateIRAffine(nb::module_ &m) {
            })
       .def("__hash__",
            [](PyIntegerSet &self) {
-             return static_cast<size_t>(llvm::hash_value(self.get().ptr));
+             return std::hash<const void *>{}(self.get().ptr);
            })
       .def_prop_ro(
           "context",

>From c644951313d5cca8b4d805566412b1a3038f0c44 Mon Sep 17 00:00:00 2001
From: Amily Wu <amilywu2 at amd.com>
Date: Fri, 6 Feb 2026 18:19:28 +0000
Subject: [PATCH 07/10] Clean fill

---
 mlir/lib/Bindings/Python/IRAttributes.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mlir/lib/Bindings/Python/IRAttributes.cpp b/mlir/lib/Bindings/Python/IRAttributes.cpp
index e2abb14e7bd87..c271497fcc9f8 100644
--- a/mlir/lib/Bindings/Python/IRAttributes.cpp
+++ b/mlir/lib/Bindings/Python/IRAttributes.cpp
@@ -6,6 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include <algorithm>
 #include <cmath>
 #include <cstdint>
 #include <optional>
@@ -1299,7 +1300,7 @@ void PyStridedLayoutAttribute::bindDerived(ClassTy &c) {
       [](int64_t rank, DefaultingPyMlirContext ctx) {
         auto dynamic = mlirShapedTypeGetDynamicStrideOrOffset();
         std::vector<int64_t> strides(rank);
-        llvm::fill(strides, dynamic);
+        std::fill(strides.begin(), strides.end(), dynamic);
         MlirAttribute attr = mlirStridedLayoutAttrGet(
             ctx->get(), dynamic, strides.size(), strides.data());
         return PyStridedLayoutAttribute(ctx->getRef(), attr);

>From d48af75bce9cd7c9d21f55f16300298eaa78be18 Mon Sep 17 00:00:00 2001
From: Amily Wu <amilywu2 at amd.com>
Date: Fri, 6 Feb 2026 18:21:41 +0000
Subject: [PATCH 08/10] Remove unused lib import

---
 mlir/include/mlir/Bindings/Python/NanobindUtils.h | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/mlir/include/mlir/Bindings/Python/NanobindUtils.h b/mlir/include/mlir/Bindings/Python/NanobindUtils.h
index b72ed31a4a4e5..69b0c6f0f51ad 100644
--- a/mlir/include/mlir/Bindings/Python/NanobindUtils.h
+++ b/mlir/include/mlir/Bindings/Python/NanobindUtils.h
@@ -12,10 +12,6 @@
 
 #include "mlir-c/Support.h"
 #include "mlir/Bindings/Python/Nanobind.h"
-#include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/Twine.h"
-#include "llvm/Support/DataTypes.h"
 
 #include <fstream>
 #include <sstream>

>From 303c4e795d9fdc0e7b45ae913909216d62f78f7b Mon Sep 17 00:00:00 2001
From: Amily Wu <amilywu2 at amd.com>
Date: Fri, 6 Feb 2026 19:25:14 +0000
Subject: [PATCH 09/10] Change ssize_t to Py_ssize_t to fix win err

---
 mlir/include/mlir/Bindings/Python/NanobindUtils.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/include/mlir/Bindings/Python/NanobindUtils.h b/mlir/include/mlir/Bindings/Python/NanobindUtils.h
index 69b0c6f0f51ad..2bd1025c49c36 100644
--- a/mlir/include/mlir/Bindings/Python/NanobindUtils.h
+++ b/mlir/include/mlir/Bindings/Python/NanobindUtils.h
@@ -336,7 +336,7 @@ class Sliceable {
   /// Returns a new instance of the pseudo-container restricted to the given
   /// slice. Returns a nullptr object on failure.
   nanobind::object getItemSlice(PyObject *slice) {
-    ssize_t start, stop, extraStep, sliceLength;
+    Py_ssize_t start, stop, extraStep, sliceLength;
     if (PySlice_GetIndicesEx(slice, length, &start, &stop, &extraStep,
                              &sliceLength) != 0) {
       PyErr_SetString(PyExc_IndexError, "index out of range");

>From 600848b494de168a7aaef8259432c7ba72b3e17c Mon Sep 17 00:00:00 2001
From: Amily Wu <amilywu2 at amd.com>
Date: Fri, 6 Feb 2026 19:52:18 +0000
Subject: [PATCH 10/10] Change to cast char to bool

---
 mlir/lib/Bindings/Python/IRAffine.cpp | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/mlir/lib/Bindings/Python/IRAffine.cpp b/mlir/lib/Bindings/Python/IRAffine.cpp
index 9fb2cfde2d340..9ad6dd80b4af9 100644
--- a/mlir/lib/Bindings/Python/IRAffine.cpp
+++ b/mlir/lib/Bindings/Python/IRAffine.cpp
@@ -941,17 +941,13 @@ void populateIRAffine(nb::module_ &m) {
               throw nb::value_error("Expected non-empty list of constraints");
 
             // std::vector<bool> does not expose a bool* data pointer.
-            std::unique_ptr<bool[]> flags =
-                std::make_unique<bool[]>(eqFlags.size());
-            for (size_t i = 0, e = eqFlags.size(); i < e; ++i)
-              flags[i] = eqFlags[i];
-
+            std::vector<char> flags(eqFlags.begin(), eqFlags.end());
             std::vector<MlirAffineExpr> affineExprs;
             pyListToVector<PyAffineExpr>(exprs, affineExprs,
                                          "attempting to create an IntegerSet");
             MlirIntegerSet set = mlirIntegerSetGet(
                 context->get(), numDims, numSymbols, exprs.size(),
-                affineExprs.data(), flags.get());
+                affineExprs.data(), reinterpret_cast<bool *>(flags.data()));
             return PyIntegerSet(context->getRef(), set);
           },
           nb::arg("num_dims"), nb::arg("num_symbols"), nb::arg("exprs"),



More information about the Mlir-commits mailing list