public:
static const ComparableFunction EmptyKey;
static const ComparableFunction TombstoneKey;
+ static TargetData * const LookupOnly;
ComparableFunction(Function *Func, TargetData *TD)
: Func(Func), Hash(profileFunction(Func)), TD(TD) {}
const ComparableFunction ComparableFunction::EmptyKey = ComparableFunction(0);
const ComparableFunction ComparableFunction::TombstoneKey =
ComparableFunction(1);
+TargetData * const ComparableFunction::LookupOnly = (TargetData*)(-1);
}
return true;
if (!LHS.getFunc() || !RHS.getFunc())
return false;
+
+ // One of these is a special "underlying pointer comparison only" object.
+ if (LHS.getTD() == ComparableFunction::LookupOnly ||
+ RHS.getTD() == ComparableFunction::LookupOnly)
+ return false;
+
assert(LHS.getTD() == RHS.getTD() &&
"Comparing functions for different targets");
// that was already inserted.
bool MergeFunctions::insert(ComparableFunction &NewF) {
std::pair<FnSetType::iterator, bool> Result = FnSet.insert(NewF);
- if (Result.second)
+ if (Result.second) {
+ DEBUG(dbgs() << "Inserting as unique: " << NewF.getFunc()->getName() << '\n');
return false;
+ }
const ComparableFunction &OldF = *Result.first;
// Remove a function from FnSet. If it was already in FnSet, add it to Deferred
// so that we'll look at it in the next round.
void MergeFunctions::remove(Function *F) {
- ComparableFunction CF = ComparableFunction(F, TD);
+ // We need to make sure we remove F, not a function "equal" to F per the
+ // function equality comparator.
+ //
+ // The special "lookup only" ComparableFunction bypasses the expensive
+ // function comparison in favour of a pointer comparison on the underlying
+ // Function*'s.
+ ComparableFunction CF = ComparableFunction(F, ComparableFunction::LookupOnly);
if (FnSet.erase(CF)) {
+ DEBUG(dbgs() << "Removed " << F->getName() << " from set and deferred it.\n");
Deferred.push_back(F);
}
}