Skip to content

Commit

Permalink
Subselect which ones to do slow insertion
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses committed Feb 21, 2024
1 parent 6918ab0 commit 385f121
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions enzyme/Enzyme/TypeAnalysis/TypeTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -1240,35 +1240,36 @@ class TypeTree : public std::enable_shared_from_this<TypeTree> {
/// equivalent If this is an illegal operation, `LegalOr` will be set to false
bool checkedOrIn(const TypeTree &RHS, bool PointerIntSame, bool &LegalOr) {
// Add fast path where nothing could change because all potentially inserted
// value are already in the map
{
bool newval = false;
for (const auto &pair : RHS.mapping) {
auto found = mapping.find(pair.first);
if (found == mapping.end()) {
newval = true;
break;
}
bool SubLegalOr = true;
auto cur = found->second;
bool SubChanged =
cur.checkedOrIn(pair.second, PointerIntSame, SubLegalOr);
if (!SubLegalOr) {
LegalOr = false;
return false;
}
if (!SubChanged) {
newval = true;
break;
}
// value are already in the map. Save all other ones that may need slow
// insertion
std::vector<std::pair<const std::vector<int>, ConcreteType>> todo;

for (const auto &pair : RHS.mapping) {
auto found = mapping.find(pair.first);
if (found == mapping.end()) {
todo.emplace_back(pair);
continue;
}
if (!newval)
bool SubLegalOr = true;
auto cur = found->second;
bool SubChanged =
cur.checkedOrIn(pair.second, PointerIntSame, SubLegalOr);
if (!SubLegalOr) {
LegalOr = false;
return false;
}
if (!SubChanged) {
todo.emplace_back(pair);
continue;
}
}

if (todo.size() == 0)
return false;

// TODO detect recursive merge and simplify
bool changed = false;
for (auto &pair : RHS.mapping) {
for (auto &pair : todo) {
changed |= checkedOrIn(pair.first, pair.second, PointerIntSame, LegalOr);
}
return changed;
Expand Down

0 comments on commit 385f121

Please sign in to comment.