18 using namespace py::literals;
26 m.doc() =
"MLIR Python Native Extension";
28 py::class_<PyGlobals>(m,
"_Globals", py::module_local())
29 .def_property(
"dialect_search_modules",
30 &PyGlobals::getDialectSearchPrefixes,
31 &PyGlobals::setDialectSearchPrefixes)
33 "append_dialect_search_prefix",
34 [](
PyGlobals &
self, std::string moduleName) {
35 self.getDialectSearchPrefixes().push_back(std::move(moduleName));
39 "_check_dialect_module_loaded",
40 [](
PyGlobals &
self,
const std::string &dialectNamespace) {
41 return self.loadDialectModule(dialectNamespace);
43 "dialect_namespace"_a)
44 .def(
"_register_dialect_impl", &PyGlobals::registerDialectImpl,
45 "dialect_namespace"_a,
"dialect_class"_a,
46 "Testing hook for directly registering a dialect")
47 .def(
"_register_operation_impl", &PyGlobals::registerOperationImpl,
48 "operation_name"_a,
"operation_class"_a, py::kw_only(),
50 "Testing hook for directly registering an operation");
56 py::cast(
new PyGlobals, py::return_value_policy::take_ownership);
61 [](py::type pyClass) {
62 std::string dialectNamespace =
63 pyClass.attr(
"DIALECT_NAMESPACE").cast<std::string>();
68 "Class decorator for registering a custom Dialect wrapper");
71 [](
const py::type &dialectClass,
bool replace) -> py::cpp_function {
72 return py::cpp_function(
73 [dialectClass, replace](py::type opClass) -> py::type {
74 std::string operationName =
75 opClass.attr(
"OPERATION_NAME").cast<std::string>();
80 py::object opClassName = opClass.attr(
"__name__");
81 dialectClass.attr(opClassName) = opClass;
85 "dialect_class"_a, py::kw_only(),
"replace"_a =
false,
86 "Produce a class decorator for registering an Operation class as part of "
90 [](MlirTypeID mlirTypeID,
bool replace) -> py::cpp_function {
91 return py::cpp_function([mlirTypeID,
92 replace](py::object typeCaster) -> py::object {
93 PyGlobals::get().registerTypeCaster(mlirTypeID, typeCaster, replace);
97 "typeid"_a, py::kw_only(),
"replace"_a =
false,
98 "Register a type caster for casting MLIR types to custom user types.");
101 [](MlirTypeID mlirTypeID,
bool replace) -> py::cpp_function {
102 return py::cpp_function(
103 [mlirTypeID, replace](py::object valueCaster) -> py::object {
109 "typeid"_a, py::kw_only(),
"replace"_a =
false,
110 "Register a value caster for casting MLIR values to custom user values.");
113 auto irModule = m.def_submodule(
"ir",
"MLIR IR Bindings");
120 auto rewriteModule = m.def_submodule(
"rewrite",
"MLIR Rewrite Bindings");
125 m.def_submodule(
"passmanager",
"MLIR Pass Management Bindings");
#define MLIR_PYTHON_CAPI_VALUE_CASTER_REGISTER_ATTR
Attribute on main C extension module (_mlir) that corresponds to the value caster registration bindin...
#define MLIR_PYTHON_CAPI_TYPE_CASTER_REGISTER_ATTR
Attribute on main C extension module (_mlir) that corresponds to the type caster registration binding...
PYBIND11_MODULE(_mlir, m)
Globals that are always accessible once the extension has been initialized.
void populateIRAttributes(pybind11::module &m)
void populateIRTypes(pybind11::module &m)
void populatePassManagerSubmodule(pybind11::module &m)
void populateIRAffine(pybind11::module &m)
void populateIRCore(pybind11::module &m)
void populateRewriteSubmodule(pybind11::module &m)
void populateIRInterfaces(py::module &m)
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...