#include "llvm/CallGraphSCCPass.h"
#include "llvm/Instructions.h"
#include "llvm/Analysis/CallGraph.h"
+#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/InstIterator.h"
bool AddReadAttrs::runOnSCC(const std::vector<CallGraphNode *> &SCC) {
+ SmallPtrSet<CallGraphNode *, 8> SCCNodes;
CallGraph &CG = getAnalysis<CallGraph>();
+ // Fill SCCNodes with the elements of the SCC. Used for quickly
+ // looking up whether a given CallGraphNode is in this SCC.
+ for (unsigned i = 0, e = SCC.size(); i != e; ++i)
+ SCCNodes.insert(SCC[i]);
+
// Check if any of the functions in the SCC read or write memory. If they
// write memory then they can't be marked readnone or readonly.
bool ReadsMemory = false;
CallSite CS = CallSite::get(&*II);
// Ignore calls to functions in the same SCC.
- if (CS.getInstruction() &&
- std::find(SCC.begin(), SCC.end(), CG[CS.getCalledFunction()]) !=
- SCC.end())
+ if (CS.getInstruction() && SCCNodes.count(CG[CS.getCalledFunction()]))
continue;
if (II->mayWriteToMemory())
#include "llvm/Function.h"
#include "llvm/Instructions.h"
#include "llvm/Analysis/CallGraph.h"
+#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Support/CFG.h"
bool PruneEH::runOnSCC(const std::vector<CallGraphNode *> &SCC) {
+ SmallPtrSet<CallGraphNode *, 8> SCCNodes;
CallGraph &CG = getAnalysis<CallGraph>();
bool MadeChange = false;
+ // Fill SCCNodes with the elements of the SCC. Used for quickly
+ // looking up whether a given CallGraphNode is in this SCC.
+ for (unsigned i = 0, e = SCC.size(); i != e; ++i)
+ SCCNodes.insert(SCC[i]);
+
// First pass, scan all of the functions in the SCC, simplifying them
// according to what we know.
for (unsigned i = 0, e = SCC.size(); i != e; ++i)
CallGraphNode *CalleeNode = CG[Callee];
// If the callee is outside our current SCC then we may
// throw because it might.
- if (std::find(SCC.begin(), SCC.end(), CalleeNode) == SCC.end()){
+ if (!SCCNodes.count(CalleeNode)) {
SCCMightUnwind = true;
break;
}