Using a deque to manage the stack of nodes is faster here.
authorLenny Maiorani <lenny@colorado.edu>
Sat, 20 Sep 2014 13:29:20 +0000 (13:29 +0000)
committerLenny Maiorani <lenny@colorado.edu>
Sat, 20 Sep 2014 13:29:20 +0000 (13:29 +0000)
  Vector is slow due to many reallocations as the size regularly changes in
  unpredictable ways. See the investigation provided on the mailing list for
  more information:

http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20120116/135228.html

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

lib/Transforms/Scalar/EarlyCSE.cpp

index 21ef34772d732464270b59d50e329cba7bb52475..131a8cb3dcbbb4d1a334a7e045a155de63930cc9 100644 (file)
@@ -26,7 +26,7 @@
 #include "llvm/Support/RecyclingAllocator.h"
 #include "llvm/Target/TargetLibraryInfo.h"
 #include "llvm/Transforms/Utils/Local.h"
-#include <vector>
+#include <deque>
 using namespace llvm;
 
 #define DEBUG_TYPE "early-cse"
@@ -560,7 +560,11 @@ bool EarlyCSE::runOnFunction(Function &F) {
   if (skipOptnoneFunction(F))
     return false;
 
-  std::vector<StackNode *> nodesToProcess;
+  // Note, deque is being used here because there is significant performance gains
+  // over vector when the container becomes very large due to the specific access
+  // patterns. For more information see the mailing list discussion on this:
+  // http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20120116/135228.html
+  std::deque<StackNode *> nodesToProcess;
 
   DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>();
   DL = DLP ? &DLP->getDataLayout() : nullptr;