18using namespace nb::literals;
26 m.doc() =
"MLIR Python Native Extension";
27 m.attr(
"T") = nb::type_var(
"T");
28 m.attr(
"U") = nb::type_var(
"U");
30 nb::class_<PyGlobals>(m,
"_Globals")
31 .def_prop_rw(
"dialect_search_modules",
37 "_check_dialect_module_loaded",
38 [](
PyGlobals &self,
const std::string &dialectNamespace) {
41 "dialect_namespace"_a)
43 "dialect_namespace"_a,
"dialect_class"_a,
44 "Testing hook for directly registering a dialect")
46 "operation_name"_a,
"operation_class"_a, nb::kw_only(),
48 "Testing hook for directly registering an operation")
49 .def(
"loc_tracebacks_enabled",
53 .def(
"set_loc_tracebacks_enabled",
57 .def(
"loc_tracebacks_frame_limit",
61 .def(
"set_loc_tracebacks_frame_limit",
62 [](
PyGlobals &self, std::optional<int> n) {
66 .def(
"register_traceback_file_inclusion",
67 [](
PyGlobals &self,
const std::string &filename) {
70 .def(
"register_traceback_file_exclusion",
71 [](
PyGlobals &self,
const std::string &filename) {
78 m.attr(
"globals") = nb::cast(
new PyGlobals, nb::rv_policy::take_ownership);
83 [](nb::type_object pyClass) {
84 std::string dialectNamespace =
85 nanobind::cast<std::string>(pyClass.attr(
"DIALECT_NAMESPACE"));
90 "Class decorator for registering a custom Dialect wrapper");
93 [](
const nb::type_object &dialectClass,
bool replace) -> nb::object {
94 return nb::cpp_function(
96 replace](nb::type_object opClass) -> nb::type_object {
97 std::string operationName =
98 nanobind::cast<std::string>(opClass.attr(
"OPERATION_NAME"));
102 nb::object opClassName = opClass.attr(
"__name__");
103 dialectClass.attr(opClassName) = opClass;
108 nb::sig(
"def register_operation(dialect_class: type, *, replace: bool = False) "
109 "-> typing.Callable[[type[T]], type[T]]"),
111 "dialect_class"_a, nb::kw_only(),
"replace"_a =
false,
112 "Produce a class decorator for registering an Operation class as part of "
116 [](MlirTypeID mlirTypeID,
bool replace) -> nb::object {
117 return nb::cpp_function([mlirTypeID, replace](
118 nb::callable typeCaster) -> nb::object {
124 nb::sig(
"def register_type_caster(typeid: _mlir.ir.TypeID, *, replace: bool = False) "
125 "-> typing.Callable[[typing.Callable[[T], U]], typing.Callable[[T], U]]"),
127 "typeid"_a, nb::kw_only(),
"replace"_a =
false,
128 "Register a type caster for casting MLIR types to custom user types.");
131 [](MlirTypeID mlirTypeID,
bool replace) -> nb::object {
132 return nb::cpp_function(
133 [mlirTypeID, replace](nb::callable valueCaster) -> nb::object {
140 nb::sig(
"def register_value_caster(typeid: _mlir.ir.TypeID, *, replace: bool = False) "
141 "-> typing.Callable[[typing.Callable[[T], U]], typing.Callable[[T], U]]"),
143 "typeid"_a, nb::kw_only(),
"replace"_a =
false,
144 "Register a value caster for casting MLIR values to custom user values.");
147 auto irModule = m.def_submodule(
"ir",
"MLIR IR Bindings");
154 auto rewriteModule = m.def_submodule(
"rewrite",
"MLIR Rewrite Bindings");
158 auto passManagerModule =
159 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...
void registerTracebackFileExclusion(const std::string &file)
static constexpr size_t kMaxFrames
size_t locTracebackFramesLimit()
void setLocTracebacksEnabled(bool value)
bool locTracebacksEnabled()
void setLocTracebackFramesLimit(size_t value)
void registerTracebackFileInclusion(const std::string &file)
Globals that are always accessible once the extension has been initialized.
bool loadDialectModule(llvm::StringRef dialectNamespace)
Loads a python module corresponding to the given dialect namespace.
void registerTypeCaster(MlirTypeID mlirTypeID, nanobind::callable typeCaster, bool replace=false)
Adds a user-friendly type caster.
std::vector< std::string > getDialectSearchPrefixes()
Get and set the list of parent modules to search for dialect implementation classes.
void addDialectSearchPrefix(std::string value)
void registerOperationImpl(const std::string &operationName, nanobind::object pyClass, bool replace=false)
Adds a concrete implementation operation class.
TracebackLoc & getTracebackLoc()
static PyGlobals & get()
Most code should get the globals via this static accessor.
void registerValueCaster(MlirTypeID mlirTypeID, nanobind::callable valueCaster, bool replace=false)
Adds a user-friendly value caster.
void setDialectSearchPrefixes(std::vector< std::string > newValues)
void registerDialectImpl(const std::string &dialectNamespace, nanobind::object pyClass)
Adds a concrete implementation dialect class.
void populateIRAttributes(nanobind::module_ &m)
void populateIRInterfaces(nb::module_ &m)
void populatePassManagerSubmodule(nanobind::module_ &m)
void populateIRAffine(nanobind::module_ &m)
void populateRewriteSubmodule(nanobind::module_ &m)
void populateIRTypes(nanobind::module_ &m)
void populateIRCore(nanobind::module_ &m)
Include the generated interface declarations.