9 #ifndef MLIR_BINDINGS_PYTHON_GLOBALS_H
10 #define MLIR_BINDINGS_PYTHON_GLOBALS_H
19 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/ADT/StringSet.h"
34 assert(instance &&
"PyGlobals is null");
41 return dialectSearchPrefixes;
44 dialectSearchPrefixes.swap(newValues);
59 nanobind::callable pyFunc,
60 bool replace =
false);
66 bool replace =
false);
72 nanobind::callable valueCaster,
73 bool replace =
false);
79 nanobind::object pyClass);
85 nanobind::object pyClass,
bool replace =
false);
88 std::optional<nanobind::callable>
101 std::optional<nanobind::object>
107 std::optional<nanobind::object>
113 std::vector<std::string> dialectSearchPrefixes;
115 llvm::StringMap<nanobind::object> dialectClassMap;
117 llvm::StringMap<nanobind::object> operationClassMap;
119 llvm::StringMap<nanobind::callable> attributeBuilderMap;
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.
void registerOperationImpl(const std::string &operationName, nanobind::object pyClass, bool replace=false)
Adds a concrete implementation operation class.
void registerAttributeBuilder(const std::string &attributeKind, nanobind::callable pyFunc, bool replace=false)
Adds a user-friendly Attribute builder.
void registerValueCaster(MlirTypeID mlirTypeID, nanobind::callable valueCaster, bool replace=false)
Adds a user-friendly value caster.
std::optional< nanobind::callable > lookupValueCaster(MlirTypeID mlirTypeID, MlirDialect dialect)
Returns the custom value caster for MlirTypeID mlirTypeID.
void setDialectSearchPrefixes(std::vector< std::string > newValues)
std::optional< nanobind::object > lookupDialectClass(const std::string &dialectNamespace)
Looks up a registered dialect class by namespace.
std::vector< std::string > & getDialectSearchPrefixes()
Get and set the list of parent modules to search for dialect implementation classes.
std::optional< nanobind::object > lookupOperationClass(llvm::StringRef operationName)
Looks up a registered operation class (deriving from OpView) by operation name.
static PyGlobals & get()
Most code should get the globals via this static accessor.
std::optional< nanobind::callable > lookupAttributeBuilder(const std::string &attributeKind)
Returns the custom Attribute builder for Attribute kind.
void registerDialectImpl(const std::string &dialectNamespace, nanobind::object pyClass)
Adds a concrete implementation dialect class.
std::optional< nanobind::callable > lookupTypeCaster(MlirTypeID mlirTypeID, MlirDialect dialect)
Returns the custom type caster for MlirTypeID mlirTypeID.
Include the generated interface declarations.