9 #ifndef MLIR_BINDINGS_PYTHON_GLOBALS_H
10 #define MLIR_BINDINGS_PYTHON_GLOBALS_H
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/ADT/StringSet.h"
35 assert(instance &&
"PyGlobals is null");
42 return dialectSearchPrefixes;
45 dialectSearchPrefixes.swap(newValues);
60 pybind11::function pyFunc,
61 bool replace =
false);
67 bool replace =
false);
73 pybind11::function valueCaster,
74 bool replace =
false);
80 pybind11::object pyClass);
86 pybind11::object pyClass,
bool replace =
false);
89 std::optional<pybind11::function>
102 std::optional<pybind11::object>
108 std::optional<pybind11::object>
114 std::vector<std::string> dialectSearchPrefixes;
116 llvm::StringMap<pybind11::object> dialectClassMap;
118 llvm::StringMap<pybind11::object> operationClassMap;
120 llvm::StringMap<pybind11::object> 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.
std::optional< pybind11::function > lookupAttributeBuilder(const std::string &attributeKind)
Returns the custom Attribute builder for Attribute kind.
std::optional< pybind11::function > lookupTypeCaster(MlirTypeID mlirTypeID, MlirDialect dialect)
Returns the custom type caster for MlirTypeID mlirTypeID.
void registerAttributeBuilder(const std::string &attributeKind, pybind11::function pyFunc, bool replace=false)
Adds a user-friendly Attribute builder.
std::optional< pybind11::object > lookupDialectClass(const std::string &dialectNamespace)
Looks up a registered dialect class by namespace.
void registerTypeCaster(MlirTypeID mlirTypeID, pybind11::function typeCaster, bool replace=false)
Adds a user-friendly type caster.
void setDialectSearchPrefixes(std::vector< std::string > newValues)
std::vector< std::string > & getDialectSearchPrefixes()
Get and set the list of parent modules to search for dialect implementation classes.
static PyGlobals & get()
Most code should get the globals via this static accessor.
void registerValueCaster(MlirTypeID mlirTypeID, pybind11::function valueCaster, bool replace=false)
Adds a user-friendly value caster.
void registerOperationImpl(const std::string &operationName, pybind11::object pyClass, bool replace=false)
Adds a concrete implementation operation class.
void registerDialectImpl(const std::string &dialectNamespace, pybind11::object pyClass)
Adds a concrete implementation dialect class.
std::optional< pybind11::object > lookupOperationClass(llvm::StringRef operationName)
Looks up a registered operation class (deriving from OpView) by operation name.
std::optional< pybind11::function > lookupValueCaster(MlirTypeID mlirTypeID, MlirDialect dialect)
Returns the custom value caster for MlirTypeID mlirTypeID.
Include the generated interface declarations.