Speed up these passes when the callgraph has
authorDuncan Sands <baldrick@free.fr>
Mon, 29 Sep 2008 14:59:04 +0000 (14:59 +0000)
committerDuncan Sands <baldrick@free.fr>
Mon, 29 Sep 2008 14:59:04 +0000 (14:59 +0000)
huge simply connected components.  Suggested
by Chris.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56787 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/AddReadAttrs.cpp
lib/Transforms/IPO/PruneEH.cpp

index b70bdaf763a4aaa3febf417ae0905e857aaa37f8..4c6158c65e8fc9dec5bae64fe877d1ab8ec80148 100644 (file)
@@ -19,6 +19,7 @@
 #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"
@@ -45,8 +46,14 @@ Pass *llvm::createAddReadAttrsPass() { return new AddReadAttrs(); }
 
 
 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;
@@ -77,9 +84,7 @@ bool AddReadAttrs::runOnSCC(const std::vector<CallGraphNode *> &SCC) {
       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())
index adaa9c1680956933749d1d4cdbd762d5ef086985..c7a4b9766a58eddcebf1c27b8ed28a6eddc63264 100644 (file)
@@ -21,6 +21,7 @@
 #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"
@@ -53,9 +54,15 @@ Pass *llvm::createPruneEHPass() { return new PruneEH(); }
 
 
 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)
@@ -107,7 +114,7 @@ bool PruneEH::runOnSCC(const std::vector<CallGraphNode *> &SCC) {
                 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;
                 }