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