[Mlir-commits] [mlir] 75eecd2 - [MLIR][Python] Remove partial LLVM APIs in python bindings (6/6) (#180986)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Feb 12 05:28:23 PST 2026
Author: RattataKing
Date: 2026-02-12T08:28:18-05:00
New Revision: 75eecd27eb432ef8085c2f7733d067de80afa894
URL: https://github.com/llvm/llvm-project/commit/75eecd27eb432ef8085c2f7733d067de80afa894
DIFF: https://github.com/llvm/llvm-project/commit/75eecd27eb432ef8085c2f7733d067de80afa894.diff
LOG: [MLIR][Python] Remove partial LLVM APIs in python bindings (6/6) (#180986)
This PR completed work from
https://github.com/llvm/llvm-project/pull/178290.
Switched the last few python bindings that still relied on LLVM over to
the C API, and dropped `LLVMsupport` dependency from MLIR cmake.
Added:
Modified:
mlir/cmake/modules/AddMLIRPython.cmake
mlir/include/mlir-c/Support.h
mlir/include/mlir/Bindings/Python/Globals.h
mlir/include/mlir/Bindings/Python/IRCore.h
mlir/lib/Bindings/Python/IRCore.cpp
mlir/lib/CAPI/IR/Support.cpp
Removed:
################################################################################
diff --git a/mlir/cmake/modules/AddMLIRPython.cmake b/mlir/cmake/modules/AddMLIRPython.cmake
index 97873d0c07ab8..54c59f41404b7 100644
--- a/mlir/cmake/modules/AddMLIRPython.cmake
+++ b/mlir/cmake/modules/AddMLIRPython.cmake
@@ -474,7 +474,10 @@ function(add_mlir_python_modules name)
MLIR_BINDINGS_PYTHON_NB_DOMAIN ${ARG_MLIR_BINDINGS_PYTHON_NB_DOMAIN}
_PRIVATE_SUPPORT_LIB
LINK_LIBS PRIVATE
- LLVMSupport
+ # LLVMSupport is intentionally removed to avoid introducing an LLVM dependency
+ # for the mlir-python bindings. Do not add new dependencies on the C++ LLVM/MLIR
+ # libraries; use the C++ standard library instead, or wrap LLVM functionality in
+ # the C API first.
${sources_target}
${ARG_COMMON_CAPI_LINK_LIBS}
)
diff --git a/mlir/include/mlir-c/Support.h b/mlir/include/mlir-c/Support.h
index 26da8eee022c5..50cb65e0ac7f5 100644
--- a/mlir/include/mlir-c/Support.h
+++ b/mlir/include/mlir-c/Support.h
@@ -156,6 +156,10 @@ MLIR_CAPI_EXPORTED MlirLlvmThreadPool mlirLlvmThreadPoolCreate(void);
/// Destroy an LLVM thread pool.
MLIR_CAPI_EXPORTED void mlirLlvmThreadPoolDestroy(MlirLlvmThreadPool pool);
+/// Returns the maximum number of threads in the thread pool.
+MLIR_CAPI_EXPORTED int
+mlirLlvmThreadPoolGetMaxConcurrency(MlirLlvmThreadPool pool);
+
//===----------------------------------------------------------------------===//
// MlirLlvmRawFdOStream.
//===----------------------------------------------------------------------===//
diff --git a/mlir/include/mlir/Bindings/Python/Globals.h b/mlir/include/mlir/Bindings/Python/Globals.h
index 23cccdd36279a..33e1130e6979d 100644
--- a/mlir/include/mlir/Bindings/Python/Globals.h
+++ b/mlir/include/mlir/Bindings/Python/Globals.h
@@ -22,9 +22,6 @@
#include "mlir/Bindings/Python/NanobindUtils.h"
#include "mlir/CAPI/Support.h"
-#include "llvm/ADT/StringExtras.h"
-#include "llvm/Support/Regex.h"
-
namespace mlir {
namespace python {
namespace MLIR_BINDINGS_PYTHON_DOMAIN {
diff --git a/mlir/include/mlir/Bindings/Python/IRCore.h b/mlir/include/mlir/Bindings/Python/IRCore.h
index e551a49bb34a8..0c7431875a5b4 100644
--- a/mlir/include/mlir/Bindings/Python/IRCore.h
+++ b/mlir/include/mlir/Bindings/Python/IRCore.h
@@ -31,8 +31,6 @@
#include "mlir/Bindings/Python/Nanobind.h"
#include "mlir/Bindings/Python/NanobindAdaptors.h"
-#include "llvm/Support/ThreadPool.h"
-
namespace mlir {
namespace python {
namespace MLIR_BINDINGS_PYTHON_DOMAIN {
@@ -183,16 +181,17 @@ class MLIR_PYTHON_API_EXPORTED PyThreadContextEntry {
class MLIR_PYTHON_API_EXPORTED PyThreadPool {
public:
PyThreadPool();
+ ~PyThreadPool();
PyThreadPool(const PyThreadPool &) = delete;
PyThreadPool(PyThreadPool &&) = delete;
- int getMaxConcurrency() const { return ownedThreadPool->getMaxConcurrency(); }
- MlirLlvmThreadPool get() { return wrap(ownedThreadPool.get()); }
+ int getMaxConcurrency() const;
+ MlirLlvmThreadPool get() { return threadPool; }
std::string _mlir_thread_pool_ptr() const;
private:
- std::unique_ptr<llvm::ThreadPoolInterface> ownedThreadPool;
+ MlirLlvmThreadPool threadPool;
};
/// Wrapper around MlirContext.
diff --git a/mlir/lib/Bindings/Python/IRCore.cpp b/mlir/lib/Bindings/Python/IRCore.cpp
index bffe5da45f6dc..f61180cdbc34d 100644
--- a/mlir/lib/Bindings/Python/IRCore.cpp
+++ b/mlir/lib/Bindings/Python/IRCore.cpp
@@ -20,6 +20,7 @@
#include "mlir-c/IR.h"
#include "mlir-c/Support.h"
+#include <array>
#include <functional>
#include <optional>
#include <string>
@@ -440,13 +441,20 @@ void PyOpOperandIterator::bind(nb::module_ &m) {
// PyThreadPool
//------------------------------------------------------------------------------
-PyThreadPool::PyThreadPool() {
- ownedThreadPool = std::make_unique<llvm::DefaultThreadPool>();
+PyThreadPool::PyThreadPool() { threadPool = mlirLlvmThreadPoolCreate(); }
+
+PyThreadPool::~PyThreadPool() {
+ if (threadPool.ptr)
+ mlirLlvmThreadPoolDestroy(threadPool);
+}
+
+int PyThreadPool::getMaxConcurrency() const {
+ return mlirLlvmThreadPoolGetMaxConcurrency(threadPool);
}
std::string PyThreadPool::_mlir_thread_pool_ptr() const {
std::stringstream ss;
- ss << ownedThreadPool.get();
+ ss << threadPool.ptr;
return ss.str();
}
diff --git a/mlir/lib/CAPI/IR/Support.cpp b/mlir/lib/CAPI/IR/Support.cpp
index 3a41fb2a00a85..343f718ce7e7e 100644
--- a/mlir/lib/CAPI/IR/Support.cpp
+++ b/mlir/lib/CAPI/IR/Support.cpp
@@ -35,6 +35,10 @@ void mlirLlvmThreadPoolDestroy(MlirLlvmThreadPool threadPool) {
delete unwrap(threadPool);
}
+int mlirLlvmThreadPoolGetMaxConcurrency(MlirLlvmThreadPool threadPool) {
+ return unwrap(threadPool)->getMaxConcurrency();
+}
+
//===----------------------------------------------------------------------===//
// LLVM raw_fd_ostream API.
//===----------------------------------------------------------------------===//
More information about the Mlir-commits
mailing list