Skip to content

Commit

Permalink
TypeTree add fast path for checkedOrIn
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses committed Feb 21, 2024
1 parent 638ac37 commit 5072cca
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion enzyme/Enzyme/TypeAnalysis/TypeTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -1239,8 +1239,26 @@ class TypeTree : public std::enable_shared_from_this<TypeTree> {
/// changed Setting `PointerIntSame` considers pointers and integers as
/// equivalent If this is an illegal operation, `LegalOr` will be set to false
bool checkedOrIn(const TypeTree &RHS, bool PointerIntSame, bool &LegalOr) {
// TODO detect recursive merge and simplify
// Add fast path where nothing could change because all potentially inserted
// value are already in the map
{
bool newval = false;
for (const auto &pair : mapping) {
auto found = mapping.find(pair.first);
if (found == mapping.end()) {
newval = true;
break;
}
if (found->second != pair.second) {
newval = true;
break;
}
}
if (!newval)
return false;
}

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

0 comments on commit 5072cca

Please sign in to comment.