9 #ifndef MLIR_BINDINGS_PYTHON_GLOBALS_H
10 #define MLIR_BINDINGS_PYTHON_GLOBALS_H
15 #include <unordered_set>
22 #include "llvm/ADT/DenseMap.h"
23 #include "llvm/ADT/StringExtras.h"
24 #include "llvm/ADT/StringRef.h"
25 #include "llvm/ADT/StringSet.h"
26 #include "llvm/Support/Regex.h"
40 assert(instance &&
"PyGlobals is null");
47 nanobind::ft_lock_guard lock(mutex);
48 return dialectSearchPrefixes;
51 nanobind::ft_lock_guard lock(mutex);
52 dialectSearchPrefixes.swap(newValues);
55 nanobind::ft_lock_guard lock(mutex);
56 dialectSearchPrefixes.push_back(std::move(value));
71 nanobind::callable pyFunc,
72 bool replace =
false);
78 bool replace =
false);
84 nanobind::callable valueCaster,
85 bool replace =
false);
91 nanobind::object pyClass);
97 nanobind::object pyClass,
bool replace =
false);
100 std::optional<nanobind::callable>
105 MlirDialect dialect);
109 MlirDialect dialect);
113 std::optional<nanobind::object>
119 std::optional<nanobind::object>
141 nanobind::ft_mutex mutex;
142 bool locTracebackEnabled_ =
false;
143 size_t locTracebackFramesLimit_ = 10;
144 std::unordered_set<std::string> userTracebackIncludeFiles;
145 std::unordered_set<std::string> userTracebackExcludeFiles;
146 std::regex userTracebackIncludeRegex;
147 bool rebuildUserTracebackIncludeRegex =
false;
148 std::regex userTracebackExcludeRegex;
149 bool rebuildUserTracebackExcludeRegex =
false;
150 llvm::StringMap<bool> isUserTracebackFilenameCache;
164 other.allocator.ptr =
nullptr;
167 MlirTypeIDAllocator
get() {
return allocator; }
173 MlirTypeIDAllocator allocator;
181 nanobind::ft_mutex mutex;
184 std::vector<std::string> dialectSearchPrefixes;
186 llvm::StringMap<nanobind::object> dialectClassMap;
188 llvm::StringMap<nanobind::object> operationClassMap;
190 llvm::StringMap<nanobind::callable> attributeBuilderMap;
199 TracebackLoc tracebackLoc;
This class provides a way to define new TypeIDs at runtime.
void registerTracebackFileExclusion(const std::string &file)
static constexpr size_t kMaxFrames
bool isUserTracebackFilename(llvm::StringRef file)
size_t locTracebackFramesLimit()
void setLocTracebacksEnabled(bool value)
bool locTracebacksEnabled()
void setLocTracebackFramesLimit(size_t value)
void registerTracebackFileInclusion(const std::string &file)
TypeIDAllocator(const TypeIDAllocator &)=delete
MlirTypeIDAllocator get()
TypeIDAllocator(TypeIDAllocator &&other)
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.
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)
MlirTypeID allocateTypeID()
TracebackLoc & getTracebackLoc()
std::optional< nanobind::object > lookupDialectClass(const std::string &dialectNamespace)
Looks up a registered dialect class by namespace.
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.
MLIR_CAPI_EXPORTED void mlirTypeIDAllocatorDestroy(MlirTypeIDAllocator allocator)
Deallocates the allocator and all allocated type ids.
MLIR_CAPI_EXPORTED MlirTypeID mlirTypeIDAllocatorAllocateTypeID(MlirTypeIDAllocator allocator)
Allocates a type id that is valid for the lifetime of the allocator.
MLIR_CAPI_EXPORTED MlirTypeIDAllocator mlirTypeIDAllocatorCreate(void)
Creates a type id allocator for dynamic type id creation.
Include the generated interface declarations.