18using namespace nb::literals;
26 m.doc() =
"MLIR Python Native Extension";
28 nb::class_<PyGlobals>(m,
"_Globals")
29 .def_prop_rw(
"dialect_search_modules",
35 "_check_dialect_module_loaded",
36 [](
PyGlobals &self,
const std::string &dialectNamespace) {
39 "dialect_namespace"_a)
41 "dialect_namespace"_a,
"dialect_class"_a,
42 "Testing hook for directly registering a dialect")
44 "operation_name"_a,
"operation_class"_a, nb::kw_only(),
46 "Testing hook for directly registering an operation")
47 .def(
"loc_tracebacks_enabled",
51 .def(
"set_loc_tracebacks_enabled",
55 .def(
"loc_tracebacks_frame_limit",
59 .def(
"set_loc_tracebacks_frame_limit",
60 [](
PyGlobals &self, std::optional<int> n) {
64 .def(
"register_traceback_file_inclusion",
65 [](
PyGlobals &self,
const std::string &filename) {
68 .def(
"register_traceback_file_exclusion",
69 [](
PyGlobals &self,
const std::string &filename) {
76 m.attr(
"globals") = nb::cast(
new PyGlobals, nb::rv_policy::take_ownership);
81 [](nb::type_object pyClass) {
82 std::string dialectNamespace =
83 nanobind::cast<std::string>(pyClass.attr(
"DIALECT_NAMESPACE"));
88 "Class decorator for registering a custom Dialect wrapper");
91 [](
const nb::type_object &dialectClass,
bool replace) -> nb::object {
92 return nb::cpp_function(
94 replace](nb::type_object opClass) -> nb::type_object {
95 std::string operationName =
96 nanobind::cast<std::string>(opClass.attr(
"OPERATION_NAME"));
100 nb::object opClassName = opClass.attr(
"__name__");
101 dialectClass.attr(opClassName) = opClass;
105 "dialect_class"_a, nb::kw_only(),
"replace"_a =
false,
106 "Produce a class decorator for registering an Operation class as part of "
110 [](MlirTypeID mlirTypeID,
bool replace) -> nb::object {
111 return nb::cpp_function([mlirTypeID, replace](
112 nb::callable typeCaster) -> nb::object {
117 "typeid"_a, nb::kw_only(),
"replace"_a =
false,
118 "Register a type caster for casting MLIR types to custom user types.");
121 [](MlirTypeID mlirTypeID,
bool replace) -> nb::object {
122 return nb::cpp_function(
123 [mlirTypeID, replace](nb::callable valueCaster) -> nb::object {
129 "typeid"_a, nb::kw_only(),
"replace"_a =
false,
130 "Register a value caster for casting MLIR values to custom user values.");
133 auto irModule = m.def_submodule(
"ir",
"MLIR IR Bindings");
140 auto rewriteModule = m.def_submodule(
"rewrite",
"MLIR Rewrite Bindings");
144 auto passManagerModule =
145 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.