// Insert a ComparableFunction into the FnSet, or merge it away if equal to one // that was already inserted. bool MergeFunctions::insert(ComparableFunction &NewF) { std::pair<FnSetType::iterator, bool> Result = FnSet.insert(NewF); if (Result.second) { DEBUG(dbgs() << "Inserting as unique: " << NewF.getFunc()->getName() << '\n'); return false; } const ComparableFunction &OldF = *Result.first; // Don't merge tiny functions, since it can just end up making the function // larger. // FIXME: Should still merge them if they are unnamed_addr and produce an // alias. if (NewF.getFunc()->size() == 1) { if (NewF.getFunc()->front().size() <= 2) { DEBUG(dbgs() << NewF.getFunc()->getName() << " is to small to bother merging\n"); return false; } } // Never thunk a strong function to a weak function. assert(!OldF.getFunc()->mayBeOverridden() || NewF.getFunc()->mayBeOverridden()); DEBUG(dbgs() << " " << OldF.getFunc()->getName() << " == " << NewF.getFunc()->getName() << '\n'); Function *DeleteF = NewF.getFunc(); NewF.release(); mergeTwoFunctions(OldF.getFunc(), DeleteF); return true; }
// Insert - Insert a ComparableFunction into the FnSet, or merge it away if // equal to one that's already inserted. bool MergeFunctions::Insert(FnSetType &FnSet, ComparableFunction &NewF) { std::pair<FnSetType::iterator, bool> Result = FnSet.insert(NewF); if (Result.second) return false; const ComparableFunction &OldF = *Result.first; // Never thunk a strong function to a weak function. assert(!OldF.getFunc()->mayBeOverridden() || NewF.getFunc()->mayBeOverridden()); DEBUG(dbgs() << " " << OldF.getFunc()->getName() << " == " << NewF.getFunc()->getName() << '\n'); Function *DeleteF = NewF.getFunc(); NewF.release(); MergeTwoFunctions(OldF.getFunc(), DeleteF); return true; }