17 using namespace py::literals;
25 m.doc() =
"MLIR Python Native Extension";
27 py::class_<PyGlobals>(m,
"_Globals", py::module_local())
28 .def_property(
"dialect_search_modules",
29 &PyGlobals::getDialectSearchPrefixes,
30 &PyGlobals::setDialectSearchPrefixes)
32 "append_dialect_search_prefix",
33 [](
PyGlobals &
self, std::string moduleName) {
34 self.getDialectSearchPrefixes().push_back(std::move(moduleName));
38 "_check_dialect_module_loaded",
39 [](
PyGlobals &
self,
const std::string &dialectNamespace) {
40 return self.loadDialectModule(dialectNamespace);
42 "dialect_namespace"_a)
43 .def(
"_register_dialect_impl", &PyGlobals::registerDialectImpl,
44 "dialect_namespace"_a,
"dialect_class"_a,
45 "Testing hook for directly registering a dialect")
46 .def(
"_register_operation_impl", &PyGlobals::registerOperationImpl,
47 "operation_name"_a,
"operation_class"_a, py::kw_only(),
49 "Testing hook for directly registering an operation");
55 py::cast(
new PyGlobals, py::return_value_policy::take_ownership);
60 [](py::object pyClass) {
61 std::string dialectNamespace =
62 pyClass.attr(
"DIALECT_NAMESPACE").cast<std::string>();
67 "Class decorator for registering a custom Dialect wrapper");
70 [](
const py::object &dialectClass,
bool replace) -> py::cpp_function {
71 return py::cpp_function(
72 [dialectClass, replace](py::object opClass) -> py::object {
73 std::string operationName =
74 opClass.attr(
"OPERATION_NAME").cast<std::string>();
79 py::object opClassName = opClass.attr(
"__name__");
80 dialectClass.attr(opClassName) = opClass;
84 "dialect_class"_a, py::kw_only(),
"replace"_a =
false,
85 "Produce a class decorator for registering an Operation class as part of "
89 [](MlirTypeID mlirTypeID,
bool replace) -> py::cpp_function {
90 return py::cpp_function([mlirTypeID,
91 replace](py::object typeCaster) -> py::object {
92 PyGlobals::get().registerTypeCaster(mlirTypeID, typeCaster, replace);
96 "typeid"_a, py::kw_only(),
"replace"_a =
false,
97 "Register a type caster for casting MLIR types to custom user types.");
100 [](MlirTypeID mlirTypeID,
bool replace) -> py::cpp_function {
101 return py::cpp_function(
102 [mlirTypeID, replace](py::object valueCaster) -> py::object {
108 "typeid"_a, py::kw_only(),
"replace"_a =
false,
109 "Register a value caster for casting MLIR values to custom user values.");
112 auto irModule = m.def_submodule(
"ir",
"MLIR IR Bindings");
121 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 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...