|
9 | 9 | #ifndef MLIR_BINDINGS_PYTHON_GLOBALS_H |
10 | 10 | #define MLIR_BINDINGS_PYTHON_GLOBALS_H |
11 | 11 |
|
12 | | -#include "PybindUtils.h" |
| 12 | +#include <optional> |
| 13 | +#include <string> |
| 14 | +#include <vector> |
13 | 15 |
|
| 16 | +#include "NanobindUtils.h" |
14 | 17 | #include "mlir-c/IR.h" |
15 | 18 | #include "mlir/CAPI/Support.h" |
16 | 19 | #include "llvm/ADT/DenseMap.h" |
17 | 20 | #include "llvm/ADT/StringRef.h" |
18 | 21 | #include "llvm/ADT/StringSet.h" |
19 | 22 |
|
20 | | -#include <optional> |
21 | | -#include <string> |
22 | | -#include <vector> |
23 | | - |
24 | 23 | namespace mlir { |
25 | 24 | namespace python { |
26 | 25 |
|
@@ -57,71 +56,71 @@ class PyGlobals { |
57 | 56 | /// Raises an exception if the mapping already exists and replace == false. |
58 | 57 | /// This is intended to be called by implementation code. |
59 | 58 | void registerAttributeBuilder(const std::string &attributeKind, |
60 | | - pybind11::function pyFunc, |
| 59 | + nanobind::callable pyFunc, |
61 | 60 | bool replace = false); |
62 | 61 |
|
63 | 62 | /// Adds a user-friendly type caster. Raises an exception if the mapping |
64 | 63 | /// already exists and replace == false. This is intended to be called by |
65 | 64 | /// implementation code. |
66 | | - void registerTypeCaster(MlirTypeID mlirTypeID, pybind11::function typeCaster, |
| 65 | + void registerTypeCaster(MlirTypeID mlirTypeID, nanobind::callable typeCaster, |
67 | 66 | bool replace = false); |
68 | 67 |
|
69 | 68 | /// Adds a user-friendly value caster. Raises an exception if the mapping |
70 | 69 | /// already exists and replace == false. This is intended to be called by |
71 | 70 | /// implementation code. |
72 | 71 | void registerValueCaster(MlirTypeID mlirTypeID, |
73 | | - pybind11::function valueCaster, |
| 72 | + nanobind::callable valueCaster, |
74 | 73 | bool replace = false); |
75 | 74 |
|
76 | 75 | /// Adds a concrete implementation dialect class. |
77 | 76 | /// Raises an exception if the mapping already exists. |
78 | 77 | /// This is intended to be called by implementation code. |
79 | 78 | void registerDialectImpl(const std::string &dialectNamespace, |
80 | | - pybind11::object pyClass); |
| 79 | + nanobind::object pyClass); |
81 | 80 |
|
82 | 81 | /// Adds a concrete implementation operation class. |
83 | 82 | /// Raises an exception if the mapping already exists and replace == false. |
84 | 83 | /// This is intended to be called by implementation code. |
85 | 84 | void registerOperationImpl(const std::string &operationName, |
86 | | - pybind11::object pyClass, bool replace = false); |
| 85 | + nanobind::object pyClass, bool replace = false); |
87 | 86 |
|
88 | 87 | /// Returns the custom Attribute builder for Attribute kind. |
89 | | - std::optional<pybind11::function> |
| 88 | + std::optional<nanobind::callable> |
90 | 89 | lookupAttributeBuilder(const std::string &attributeKind); |
91 | 90 |
|
92 | 91 | /// Returns the custom type caster for MlirTypeID mlirTypeID. |
93 | | - std::optional<pybind11::function> lookupTypeCaster(MlirTypeID mlirTypeID, |
| 92 | + std::optional<nanobind::callable> lookupTypeCaster(MlirTypeID mlirTypeID, |
94 | 93 | MlirDialect dialect); |
95 | 94 |
|
96 | 95 | /// Returns the custom value caster for MlirTypeID mlirTypeID. |
97 | | - std::optional<pybind11::function> lookupValueCaster(MlirTypeID mlirTypeID, |
| 96 | + std::optional<nanobind::callable> lookupValueCaster(MlirTypeID mlirTypeID, |
98 | 97 | MlirDialect dialect); |
99 | 98 |
|
100 | 99 | /// Looks up a registered dialect class by namespace. Note that this may |
101 | 100 | /// trigger loading of the defining module and can arbitrarily re-enter. |
102 | | - std::optional<pybind11::object> |
| 101 | + std::optional<nanobind::object> |
103 | 102 | lookupDialectClass(const std::string &dialectNamespace); |
104 | 103 |
|
105 | 104 | /// Looks up a registered operation class (deriving from OpView) by operation |
106 | 105 | /// name. Note that this may trigger a load of the dialect, which can |
107 | 106 | /// arbitrarily re-enter. |
108 | | - std::optional<pybind11::object> |
| 107 | + std::optional<nanobind::object> |
109 | 108 | lookupOperationClass(llvm::StringRef operationName); |
110 | 109 |
|
111 | 110 | private: |
112 | 111 | static PyGlobals *instance; |
113 | 112 | /// Module name prefixes to search under for dialect implementation modules. |
114 | 113 | std::vector<std::string> dialectSearchPrefixes; |
115 | 114 | /// Map of dialect namespace to external dialect class object. |
116 | | - llvm::StringMap<pybind11::object> dialectClassMap; |
| 115 | + llvm::StringMap<nanobind::object> dialectClassMap; |
117 | 116 | /// Map of full operation name to external operation class object. |
118 | | - llvm::StringMap<pybind11::object> operationClassMap; |
| 117 | + llvm::StringMap<nanobind::object> operationClassMap; |
119 | 118 | /// Map of attribute ODS name to custom builder. |
120 | | - llvm::StringMap<pybind11::object> attributeBuilderMap; |
| 119 | + llvm::StringMap<nanobind::callable> attributeBuilderMap; |
121 | 120 | /// Map of MlirTypeID to custom type caster. |
122 | | - llvm::DenseMap<MlirTypeID, pybind11::object> typeCasterMap; |
| 121 | + llvm::DenseMap<MlirTypeID, nanobind::callable> typeCasterMap; |
123 | 122 | /// Map of MlirTypeID to custom value caster. |
124 | | - llvm::DenseMap<MlirTypeID, pybind11::object> valueCasterMap; |
| 123 | + llvm::DenseMap<MlirTypeID, nanobind::callable> valueCasterMap; |
125 | 124 | /// Set of dialect namespaces that we have attempted to import implementation |
126 | 125 | /// modules for. |
127 | 126 | llvm::StringSet<> loadedDialectModules; |
|
0 commit comments