Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions mlir/lib/Bindings/Python/Pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down