static inline bool nodeContainsExternalFunction(const DSNode *N) {
const std::vector<GlobalValue*> &Globals = N->getGlobals();
for (unsigned i = 0, e = Globals.size(); i != e; ++i)
- if (Globals[i]->isExternal())
+ if (Globals[i]->isExternal() && isa<Function>(Globals[i]))
return true;
return false;
}
Function *LastCalleeFunc = 0;
unsigned NumDuplicateCalls = 0;
bool LastCalleeContainsExternalFunction = false;
+
+ std::vector<unsigned> CallsToDelete;
+
for (unsigned i = 0; i != Calls.size(); ++i) {
DSCallSite &CS = Calls[i];
#ifndef NDEBUG
std::cerr << "WARNING: Useless call site found.\n";
#endif
- CS.swap(Calls.back());
- Calls.pop_back();
- --i;
+ CallsToDelete.push_back(i);
} else {
// If the return value or any arguments point to a void node with no
// information at all in it, and the call node is the only node to point
DSCallSite &OCS = Calls[i-1];
OCS.mergeWith(CS);
- // The node will now be eliminated as a duplicate!
- if (CS.getNumPtrArgs() < OCS.getNumPtrArgs())
- CS = OCS;
- else if (CS.getNumPtrArgs() > OCS.getNumPtrArgs())
- OCS = CS;
+ // No need to keep this call anymore.
+ CallsToDelete.push_back(i);
}
#endif
} else {
}
}
#endif
+
+ unsigned NumDeleted = 0;
+ for (unsigned i = 0, e = CallsToDelete.size(); i != e; ++i)
+ Calls.erase(Calls.begin()+CallsToDelete[i]-NumDeleted++);
+
Calls.erase(std::unique(Calls.begin(), Calls.end()), Calls.end());
// Track the number of call nodes merged away...