[llvm] r207312 - [LCG] Rather than removing nodes from the SCC entry set when we process

Chandler Carruth chandlerc at gmail.com
Sat Apr 26 02:45:55 PDT 2014


Author: chandlerc
Date: Sat Apr 26 04:45:55 2014
New Revision: 207312

URL: http://llvm.org/viewvc/llvm-project?rev=207312&view=rev
Log:
[LCG] Rather than removing nodes from the SCC entry set when we process
them, just skip over any DFS-numbered nodes when finding the next root
of a DFS. This allows the entry set to just be a vector as we populate
it from a uniqued source. It also removes the possibility for a linear
scan of the entry set to actually do the removal which can make things
go quadratic if we get unlucky.

Modified:
    llvm/trunk/include/llvm/Analysis/LazyCallGraph.h
    llvm/trunk/lib/Analysis/LazyCallGraph.cpp

Modified: llvm/trunk/include/llvm/Analysis/LazyCallGraph.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LazyCallGraph.h?rev=207312&r1=207311&r2=207312&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/LazyCallGraph.h (original)
+++ llvm/trunk/include/llvm/Analysis/LazyCallGraph.h Sat Apr 26 04:45:55 2014
@@ -384,7 +384,7 @@ private:
   SmallVector<std::pair<Node *, iterator>, 4> DFSStack;
 
   /// \brief Set of entry nodes not-yet-processed into SCCs.
-  SmallSetVector<Function *, 4> SCCEntryNodes;
+  SmallVector<Function *, 4> SCCEntryNodes;
 
   /// \brief Stack of nodes the DFS has walked but not yet put into a SCC.
   SmallVector<Node *, 4> PendingSCCStack;

Modified: llvm/trunk/lib/Analysis/LazyCallGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LazyCallGraph.cpp?rev=207312&r1=207311&r2=207312&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LazyCallGraph.cpp (original)
+++ llvm/trunk/lib/Analysis/LazyCallGraph.cpp Sat Apr 26 04:45:55 2014
@@ -100,9 +100,9 @@ LazyCallGraph::LazyCallGraph(Module &M)
 
   for (auto &Entry : EntryNodes)
     if (Function *F = Entry.dyn_cast<Function *>())
-      SCCEntryNodes.insert(F);
+      SCCEntryNodes.push_back(F);
     else
-      SCCEntryNodes.insert(&Entry.get<Node *>()->getFunction());
+      SCCEntryNodes.push_back(&Entry.get<Node *>()->getFunction());
 }
 
 LazyCallGraph::LazyCallGraph(LazyCallGraph &&G)
@@ -437,10 +437,12 @@ LazyCallGraph::SCC *LazyCallGraph::getNe
     DFSStack.pop_back();
   } else {
     // If we've handled all candidate entry nodes to the SCC forest, we're done.
-    if (SCCEntryNodes.empty())
-      return nullptr;
+    do {
+      if (SCCEntryNodes.empty())
+        return nullptr;
 
-    N = &get(*SCCEntryNodes.pop_back_val());
+      N = &get(*SCCEntryNodes.pop_back_val());
+    } while (N->DFSNumber != 0);
     I = N->begin();
     N->LowLink = N->DFSNumber = 1;
     NextDFSNumber = 2;
@@ -463,7 +465,6 @@ LazyCallGraph::SCC *LazyCallGraph::getNe
         assert(!SCCMap.count(&ChildN) &&
                "Found a node with 0 DFS number but already in an SCC!");
         ChildN.LowLink = ChildN.DFSNumber = NextDFSNumber++;
-        SCCEntryNodes.remove(&ChildN.getFunction());
         N = &ChildN;
         I = ChildN.begin();
         E = ChildN.end();





More information about the llvm-commits mailing list