Skip to content

Commit 69ae05c

Browse files
committed
remove valuecastercache
1 parent 31792be commit 69ae05c

File tree

2 files changed

+6
-36
lines changed

2 files changed

+6
-36
lines changed

mlir/lib/Bindings/Python/Globals.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,8 @@ class PyGlobals {
120120
llvm::StringMap<pybind11::object> attributeBuilderMap;
121121
/// Map of MlirTypeID to custom type caster.
122122
llvm::DenseMap<MlirTypeID, pybind11::object> typeCasterMap;
123-
124123
/// Map of MlirTypeID to custom value caster.
125124
llvm::DenseMap<MlirTypeID, pybind11::object> valueCasterMap;
126-
/// Cache for map of MlirTypeID to custom value caster.
127-
llvm::DenseMap<MlirTypeID, pybind11::object> valueCasterMapCache;
128-
129125
/// Set of dialect namespaces that we have attempted to import implementation
130126
/// modules for.
131127
llvm::StringSet<> loadedDialectModules;

mlir/lib/Bindings/Python/IRModule.cpp

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,10 @@ void PyGlobals::registerValueCaster(MlirTypeID mlirTypeID,
9292
pybind11::function valueCaster,
9393
bool replace) {
9494
pybind11::object &found = valueCasterMap[mlirTypeID];
95-
if (found && !found.is_none() && !replace)
95+
if (found && !replace)
9696
throw std::runtime_error("Value caster is already registered: " +
9797
py::repr(found).cast<std::string>());
9898
found = std::move(valueCaster);
99-
const auto foundIt = valueCasterMapCache.find(mlirTypeID);
100-
if (foundIt != valueCasterMapCache.end() && !foundIt->second.is_none()) {
101-
valueCasterMapCache[mlirTypeID] = found;
102-
}
10399
}
104100

105101
void PyGlobals::registerDialectImpl(const std::string &dialectNamespace,
@@ -150,35 +146,13 @@ std::optional<py::function> PyGlobals::lookupTypeCaster(MlirTypeID mlirTypeID,
150146

151147
std::optional<py::function> PyGlobals::lookupValueCaster(MlirTypeID mlirTypeID,
152148
MlirDialect dialect) {
153-
{
154-
// Fast match against the value caster map first (common case).
155-
const auto foundIt = valueCasterMapCache.find(mlirTypeID);
156-
if (foundIt != valueCasterMapCache.end()) {
157-
if (foundIt->second.is_none())
158-
return std::nullopt;
159-
assert(foundIt->second && "py::function is defined");
160-
return foundIt->second;
161-
}
162-
}
163-
164-
// Not found. Load the dialect namespace.
165149
loadDialectModule(unwrap(mlirDialectGetNamespace(dialect)));
166-
167-
// Attempt to find from the canonical map and cache.
168-
{
169-
const auto foundIt = valueCasterMap.find(mlirTypeID);
170-
if (foundIt != valueCasterMap.end()) {
171-
if (foundIt->second.is_none())
172-
return std::nullopt;
173-
assert(foundIt->second && "py::object is defined");
174-
// Positive cache.
175-
valueCasterMapCache[mlirTypeID] = foundIt->second;
176-
return foundIt->second;
177-
}
178-
// Negative cache.
179-
valueCasterMap[mlirTypeID] = py::none();
180-
return std::nullopt;
150+
const auto foundIt = valueCasterMap.find(mlirTypeID);
151+
if (foundIt != valueCasterMap.end()) {
152+
assert(foundIt->second && "value caster is defined");
153+
return foundIt->second;
181154
}
155+
return std::nullopt;
182156
}
183157

184158
std::optional<py::object>

0 commit comments

Comments
 (0)