-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[MLIR][Python] Make the TypeID allocator globally defined in PassManager.add
#162594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-mlir Author: Twice (PragmaTwice) ChangesPreviously, each time we called Full diff: https://github.com/llvm/llvm-project/pull/162594.diff 1 Files Affected:
diff --git a/mlir/lib/Bindings/Python/Pass.cpp b/mlir/lib/Bindings/Python/Pass.cpp
index e489585fd5f50..e371a8cf76a9d 100644
--- a/mlir/lib/Bindings/Python/Pass.cpp
+++ b/mlir/lib/Bindings/Python/Pass.cpp
@@ -52,6 +52,23 @@ class PyPassManager {
MlirPassManager passManager;
};
+class PyTypeIDAllocator {
+public:
+ PyTypeIDAllocator() : allocator(mlirTypeIDAllocatorCreate()) {}
+ ~PyTypeIDAllocator() {
+ if (!allocator.ptr)
+ mlirTypeIDAllocatorDestroy(allocator);
+ }
+
+ MlirTypeIDAllocator get() { return allocator; }
+ MlirTypeID allocate() { return mlirTypeIDAllocatorAllocateTypeID(allocator); }
+
+private:
+ MlirTypeIDAllocator allocator;
+};
+
+PyTypeIDAllocator globalTypeIDAllocator;
+
} // namespace
/// Create the `mlir.passmanager` here.
@@ -181,9 +198,7 @@ void mlir::python::populatePassManagerSubmodule(nb::module_ &m) {
name = nb::cast<std::string>(
nb::borrow<nb::str>(run.attr("__name__")));
}
- MlirTypeIDAllocator typeIDAllocator = mlirTypeIDAllocatorCreate();
- MlirTypeID passID =
- mlirTypeIDAllocatorAllocateTypeID(typeIDAllocator);
+ MlirTypeID passID = globalTypeIDAllocator.allocate();
MlirExternalPassCallbacks callbacks;
callbacks.construct = [](void *obj) {
(void)nb::handle(static_cast<PyObject *>(obj)).inc_ref();
|
PassManager.add
PassManager.add
Thank you all! I'll merge it soon. |
…ager.add` (#162594) Previously, each time we called `PassManager.add(python_pass_callable)`, a new `TypeID` allocator was created and never released afterward. This approach could potentially lead to some issues. In this PR, we introduce a global `TypeIDAllocator` that is shared across all `add` calls to allocate IDs.
…ager.add` (llvm#162594) Previously, each time we called `PassManager.add(python_pass_callable)`, a new `TypeID` allocator was created and never released afterward. This approach could potentially lead to some issues. In this PR, we introduce a global `TypeIDAllocator` that is shared across all `add` calls to allocate IDs.
Previously, each time we called
PassManager.add(python_pass_callable)
, a newTypeID
allocator was created and never released afterward. This approach could potentially lead to some issues. In this PR, we introduce a globalTypeIDAllocator
that is shared across alladd
calls to allocate IDs.