diff --git a/mlir/lib/Bindings/Python/ExecutionEngineModule.cpp b/mlir/lib/Bindings/Python/ExecutionEngineModule.cpp --- a/mlir/lib/Bindings/Python/ExecutionEngineModule.cpp +++ b/mlir/lib/Bindings/Python/ExecutionEngineModule.cpp @@ -58,7 +58,7 @@ //---------------------------------------------------------------------------- // Mapping of the top-level PassManager //---------------------------------------------------------------------------- - py::class_(m, "ExecutionEngine") + py::class_(m, "ExecutionEngine", py::module_local()) .def(py::init<>([](MlirModule module, int optLevel, const std::vector &sharedLibPaths) { llvm::SmallVector libPaths; diff --git a/mlir/lib/Bindings/Python/IRAffine.cpp b/mlir/lib/Bindings/Python/IRAffine.cpp --- a/mlir/lib/Bindings/Python/IRAffine.cpp +++ b/mlir/lib/Bindings/Python/IRAffine.cpp @@ -97,7 +97,7 @@ } static void bind(py::module &m) { - auto cls = ClassTy(m, DerivedTy::pyClassName); + auto cls = ClassTy(m, DerivedTy::pyClassName, py::module_local()); cls.def(py::init()); DerivedTy::bindDerived(cls); } @@ -367,7 +367,8 @@ bool isEq() { return mlirIntegerSetIsConstraintEq(set, pos); } static void bind(py::module &m) { - py::class_(m, "IntegerSetConstraint") + py::class_(m, "IntegerSetConstraint", + py::module_local()) .def_property_readonly("expr", &PyIntegerSetConstraint::getExpr) .def_property_readonly("is_eq", &PyIntegerSetConstraint::isEq); } @@ -427,7 +428,7 @@ //---------------------------------------------------------------------------- // Mapping of PyAffineExpr and derived classes. //---------------------------------------------------------------------------- - py::class_(m, "AffineExpr") + py::class_(m, "AffineExpr", py::module_local()) .def_property_readonly(MLIR_PYTHON_CAPI_PTR_ATTR, &PyAffineExpr::getCapsule) .def(MLIR_PYTHON_CAPI_FACTORY_ATTR, &PyAffineExpr::createFromCapsule) @@ -515,7 +516,7 @@ //---------------------------------------------------------------------------- // Mapping of PyAffineMap. //---------------------------------------------------------------------------- - py::class_(m, "AffineMap") + py::class_(m, "AffineMap", py::module_local()) .def_property_readonly(MLIR_PYTHON_CAPI_PTR_ATTR, &PyAffineMap::getCapsule) .def(MLIR_PYTHON_CAPI_FACTORY_ATTR, &PyAffineMap::createFromCapsule) @@ -686,7 +687,7 @@ //---------------------------------------------------------------------------- // Mapping of PyIntegerSet. //---------------------------------------------------------------------------- - py::class_(m, "IntegerSet") + py::class_(m, "IntegerSet", py::module_local()) .def_property_readonly(MLIR_PYTHON_CAPI_PTR_ATTR, &PyIntegerSet::getCapsule) .def(MLIR_PYTHON_CAPI_FACTORY_ATTR, &PyIntegerSet::createFromCapsule) diff --git a/mlir/lib/Bindings/Python/IRAttributes.cpp b/mlir/lib/Bindings/Python/IRAttributes.cpp --- a/mlir/lib/Bindings/Python/IRAttributes.cpp +++ b/mlir/lib/Bindings/Python/IRAttributes.cpp @@ -65,7 +65,8 @@ } static void bind(py::module &m) { - py::class_(m, "ArrayAttributeIterator") + py::class_(m, "ArrayAttributeIterator", + py::module_local()) .def("__iter__", &PyArrayAttributeIterator::dunderIter) .def("__next__", &PyArrayAttributeIterator::dunderNext); } diff --git a/mlir/lib/Bindings/Python/IRCore.cpp b/mlir/lib/Bindings/Python/IRCore.cpp --- a/mlir/lib/Bindings/Python/IRCore.cpp +++ b/mlir/lib/Bindings/Python/IRCore.cpp @@ -163,7 +163,7 @@ static void bind(py::module &m) { // Debug flags. - py::class_(m, "_GlobalDebug") + py::class_(m, "_GlobalDebug", py::module_local()) .def_property_static("flag", &PyGlobalDebugFlag::get, &PyGlobalDebugFlag::set, "LLVM-wide debug flag"); } @@ -192,7 +192,7 @@ } static void bind(py::module &m) { - py::class_(m, "RegionIterator") + py::class_(m, "RegionIterator", py::module_local()) .def("__iter__", &PyRegionIterator::dunderIter) .def("__next__", &PyRegionIterator::dunderNext); } @@ -224,7 +224,7 @@ } static void bind(py::module &m) { - py::class_(m, "RegionSequence") + py::class_(m, "RegionSequence", py::module_local()) .def("__len__", &PyRegionList::dunderLen) .def("__getitem__", &PyRegionList::dunderGetItem); } @@ -252,7 +252,7 @@ } static void bind(py::module &m) { - py::class_(m, "BlockIterator") + py::class_(m, "BlockIterator", py::module_local()) .def("__iter__", &PyBlockIterator::dunderIter) .def("__next__", &PyBlockIterator::dunderNext); } @@ -317,7 +317,7 @@ } static void bind(py::module &m) { - py::class_(m, "BlockList") + py::class_(m, "BlockList", py::module_local()) .def("__getitem__", &PyBlockList::dunderGetItem) .def("__iter__", &PyBlockList::dunderIter) .def("__len__", &PyBlockList::dunderLen) @@ -349,7 +349,7 @@ } static void bind(py::module &m) { - py::class_(m, "OperationIterator") + py::class_(m, "OperationIterator", py::module_local()) .def("__iter__", &PyOperationIterator::dunderIter) .def("__next__", &PyOperationIterator::dunderNext); } @@ -405,7 +405,7 @@ } static void bind(py::module &m) { - py::class_(m, "OperationList") + py::class_(m, "OperationList", py::module_local()) .def("__getitem__", &PyOperationList::dunderGetItem) .def("__iter__", &PyOperationList::dunderIter) .def("__len__", &PyOperationList::dunderLen); @@ -1540,7 +1540,7 @@ /// Binds the Python module objects to functions of this class. static void bind(py::module &m) { - auto cls = ClassTy(m, DerivedTy::pyClassName); + auto cls = ClassTy(m, DerivedTy::pyClassName, py::module_local()); cls.def(py::init(), py::keep_alive<0, 1>()); DerivedTy::bindDerived(cls); } @@ -1618,7 +1618,7 @@ /// Defines a Python class in the bindings. static void bind(py::module &m) { - py::class_(m, "BlockArgumentList") + py::class_(m, "BlockArgumentList", py::module_local()) .def("__len__", &PyBlockArgumentList::dunderLen) .def("__getitem__", &PyBlockArgumentList::dunderGetItem); } @@ -1765,7 +1765,7 @@ } static void bind(py::module &m) { - py::class_(m, "OpAttributeMap") + py::class_(m, "OpAttributeMap", py::module_local()) .def("__contains__", &PyOpAttributeMap::dunderContains) .def("__len__", &PyOpAttributeMap::dunderLen) .def("__getitem__", &PyOpAttributeMap::dunderGetItemNamed) @@ -1788,7 +1788,7 @@ //---------------------------------------------------------------------------- // Mapping of MlirContext. //---------------------------------------------------------------------------- - py::class_(m, "Context") + py::class_(m, "Context", py::module_local()) .def(py::init<>(&PyMlirContext::createNewContextForInit)) .def_static("_get_live_count", &PyMlirContext::getLiveCount) .def("_get_context_again", @@ -1852,7 +1852,7 @@ //---------------------------------------------------------------------------- // Mapping of PyDialectDescriptor //---------------------------------------------------------------------------- - py::class_(m, "DialectDescriptor") + py::class_(m, "DialectDescriptor", py::module_local()) .def_property_readonly("namespace", [](PyDialectDescriptor &self) { MlirStringRef ns = @@ -1870,7 +1870,7 @@ //---------------------------------------------------------------------------- // Mapping of PyDialects //---------------------------------------------------------------------------- - py::class_(m, "Dialects") + py::class_(m, "Dialects", py::module_local()) .def("__getitem__", [=](PyDialects &self, std::string keyName) { MlirDialect dialect = @@ -1890,7 +1890,7 @@ //---------------------------------------------------------------------------- // Mapping of PyDialect //---------------------------------------------------------------------------- - py::class_(m, "Dialect") + py::class_(m, "Dialect", py::module_local()) .def(py::init(), "descriptor") .def_property_readonly( "descriptor", [](PyDialect &self) { return self.getDescriptor(); }) @@ -1905,7 +1905,7 @@ //---------------------------------------------------------------------------- // Mapping of Location //---------------------------------------------------------------------------- - py::class_(m, "Location") + py::class_(m, "Location", py::module_local()) .def_property_readonly(MLIR_PYTHON_CAPI_PTR_ATTR, &PyLocation::getCapsule) .def(MLIR_PYTHON_CAPI_FACTORY_ATTR, &PyLocation::createFromCapsule) .def("__enter__", &PyLocation::contextEnter) @@ -1957,7 +1957,7 @@ //---------------------------------------------------------------------------- // Mapping of Module //---------------------------------------------------------------------------- - py::class_(m, "Module") + py::class_(m, "Module", py::module_local()) .def_property_readonly(MLIR_PYTHON_CAPI_PTR_ATTR, &PyModule::getCapsule) .def(MLIR_PYTHON_CAPI_FACTORY_ATTR, &PyModule::createFromCapsule) .def_static( @@ -2026,7 +2026,7 @@ //---------------------------------------------------------------------------- // Mapping of Operation. //---------------------------------------------------------------------------- - py::class_(m, "_OperationBase") + py::class_(m, "_OperationBase", py::module_local()) .def("__eq__", [](PyOperationBase &self, PyOperationBase &other) { return &self.getOperation() == &other.getOperation(); @@ -2113,7 +2113,7 @@ "Verify the operation and return true if it passes, false if it " "fails."); - py::class_(m, "Operation") + py::class_(m, "Operation", py::module_local()) .def_static("create", &PyOperation::create, py::arg("name"), py::arg("results") = py::none(), py::arg("operands") = py::none(), @@ -2150,7 +2150,7 @@ .def_property_readonly("opview", &PyOperation::createOpView); auto opViewClass = - py::class_(m, "OpView") + py::class_(m, "OpView", py::module_local()) .def(py::init()) .def_property_readonly("operation", &PyOpView::getOperationObject) .def_property_readonly( @@ -2175,7 +2175,7 @@ //---------------------------------------------------------------------------- // Mapping of PyRegion. //---------------------------------------------------------------------------- - py::class_(m, "Region") + py::class_(m, "Region", py::module_local()) .def_property_readonly( "blocks", [](PyRegion &self) { @@ -2199,7 +2199,7 @@ //---------------------------------------------------------------------------- // Mapping of PyBlock. //---------------------------------------------------------------------------- - py::class_(m, "Block") + py::class_(m, "Block", py::module_local()) .def_property_readonly( "owner", [](PyBlock &self) { @@ -2248,7 +2248,7 @@ // Mapping of PyInsertionPoint. //---------------------------------------------------------------------------- - py::class_(m, "InsertionPoint") + py::class_(m, "InsertionPoint", py::module_local()) .def(py::init(), py::arg("block"), "Inserts after the last operation but still inside the block.") .def("__enter__", &PyInsertionPoint::contextEnter) @@ -2275,7 +2275,7 @@ //---------------------------------------------------------------------------- // Mapping of PyAttribute. //---------------------------------------------------------------------------- - py::class_(m, "Attribute") + py::class_(m, "Attribute", py::module_local()) // Delegate to the PyAttribute copy constructor, which will also lifetime // extend the backing context which owns the MlirAttribute. .def(py::init(), py::arg("cast_from_type"), @@ -2346,7 +2346,7 @@ //---------------------------------------------------------------------------- // Mapping of PyNamedAttribute //---------------------------------------------------------------------------- - py::class_(m, "NamedAttribute") + py::class_(m, "NamedAttribute", py::module_local()) .def("__repr__", [](PyNamedAttribute &self) { PyPrintAccumulator printAccum; @@ -2382,7 +2382,7 @@ //---------------------------------------------------------------------------- // Mapping of PyType. //---------------------------------------------------------------------------- - py::class_(m, "Type") + py::class_(m, "Type", py::module_local()) // Delegate to the PyType copy constructor, which will also lifetime // extend the backing context which owns the MlirType. .def(py::init(), py::arg("cast_from_type"), @@ -2436,7 +2436,7 @@ //---------------------------------------------------------------------------- // Mapping of Value. //---------------------------------------------------------------------------- - py::class_(m, "Value") + py::class_(m, "Value", py::module_local()) .def_property_readonly(MLIR_PYTHON_CAPI_PTR_ATTR, &PyValue::getCapsule) .def(MLIR_PYTHON_CAPI_FACTORY_ATTR, &PyValue::createFromCapsule) .def_property_readonly( diff --git a/mlir/lib/Bindings/Python/MainModule.cpp b/mlir/lib/Bindings/Python/MainModule.cpp --- a/mlir/lib/Bindings/Python/MainModule.cpp +++ b/mlir/lib/Bindings/Python/MainModule.cpp @@ -26,7 +26,7 @@ PYBIND11_MODULE(_mlir, m) { m.doc() = "MLIR Python Native Extension"; - py::class_(m, "_Globals") + py::class_(m, "_Globals", py::module_local()) .def_property("dialect_search_modules", &PyGlobals::getDialectSearchPrefixes, &PyGlobals::setDialectSearchPrefixes) diff --git a/mlir/lib/Bindings/Python/Pass.cpp b/mlir/lib/Bindings/Python/Pass.cpp --- a/mlir/lib/Bindings/Python/Pass.cpp +++ b/mlir/lib/Bindings/Python/Pass.cpp @@ -55,7 +55,7 @@ //---------------------------------------------------------------------------- // Mapping of the top-level PassManager //---------------------------------------------------------------------------- - py::class_(m, "PassManager") + py::class_(m, "PassManager", py::module_local()) .def(py::init<>([](DefaultingPyMlirContext context) { MlirPassManager passManager = mlirPassManagerCreate(context->get());