File tree Expand file tree Collapse file tree 2 files changed +22
-18
lines changed
Expand file tree Collapse file tree 2 files changed +22
-18
lines changed Original file line number Diff line number Diff line change @@ -151,6 +151,25 @@ class PyGlobals {
151151
152152 TracebackLoc &getTracebackLoc () { return tracebackLoc; }
153153
154+ class TypeIDAllocator {
155+ public:
156+ TypeIDAllocator () : allocator(mlirTypeIDAllocatorCreate()) {}
157+ ~TypeIDAllocator () {
158+ if (!allocator.ptr )
159+ mlirTypeIDAllocatorDestroy (allocator);
160+ }
161+
162+ MlirTypeIDAllocator get () { return allocator; }
163+ MlirTypeID allocate () {
164+ return mlirTypeIDAllocatorAllocateTypeID (allocator);
165+ }
166+
167+ private:
168+ MlirTypeIDAllocator allocator;
169+ };
170+
171+ MlirTypeID allocateTypeID () { return typeIDAllocator.allocate (); }
172+
154173private:
155174 static PyGlobals *instance;
156175
@@ -173,6 +192,7 @@ class PyGlobals {
173192 llvm::StringSet<> loadedDialectModules;
174193
175194 TracebackLoc tracebackLoc;
195+ TypeIDAllocator typeIDAllocator;
176196};
177197
178198} // namespace python
Original file line number Diff line number Diff line change 88
99#include " Pass.h"
1010
11+ #include " Globals.h"
1112#include " IRModule.h"
1213#include " mlir-c/Pass.h"
1314// clang-format off
@@ -52,23 +53,6 @@ class PyPassManager {
5253 MlirPassManager passManager;
5354};
5455
55- class PyTypeIDAllocator {
56- public:
57- PyTypeIDAllocator () : allocator(mlirTypeIDAllocatorCreate()) {}
58- ~PyTypeIDAllocator () {
59- if (!allocator.ptr )
60- mlirTypeIDAllocatorDestroy (allocator);
61- }
62-
63- MlirTypeIDAllocator get () { return allocator; }
64- MlirTypeID allocate () { return mlirTypeIDAllocatorAllocateTypeID (allocator); }
65-
66- private:
67- MlirTypeIDAllocator allocator;
68- };
69-
70- PyTypeIDAllocator globalTypeIDAllocator;
71-
7256} // namespace
7357
7458// / Create the `mlir.passmanager` here.
@@ -198,7 +182,7 @@ void mlir::python::populatePassManagerSubmodule(nb::module_ &m) {
198182 name = nb::cast<std::string>(
199183 nb::borrow<nb::str>(run.attr (" __name__" )));
200184 }
201- MlirTypeID passID = globalTypeIDAllocator. allocate ();
185+ MlirTypeID passID = PyGlobals::get (). allocateTypeID ();
202186 MlirExternalPassCallbacks callbacks;
203187 callbacks.construct = [](void *obj) {
204188 (void )nb::handle (static_cast <PyObject *>(obj)).inc_ref ();
You can’t perform that action at this time.
0 commit comments