[llvm] r344233 - [LV] Use SmallVector instead of DenseMap in calculateRegisterUsage (NFC).

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 11 02:46:25 PDT 2018


Author: fhahn
Date: Thu Oct 11 02:46:25 2018
New Revision: 344233

URL: http://llvm.org/viewvc/llvm-project?rev=344233&view=rev
Log:
[LV] Use SmallVector instead of DenseMap in calculateRegisterUsage (NFC).

We assign indices sequentially for seen instructions, so we can just use
a vector and push back the seen instructions. No need for using a
DenseMap.

Reviewers: hsaito, rengolin, nadav, dcaballe

Reviewed By: rengolin

Differential Revision: https://reviews.llvm.org/D53089

Modified:
    llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp

Modified: llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp?rev=344233&r1=344232&r2=344233&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp (original)
+++ llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp Thu Oct 11 02:46:25 2018
@@ -4882,7 +4882,7 @@ LoopVectorizationCostModel::calculateReg
   using IntervalMap = DenseMap<Instruction *, unsigned>;
 
   // Maps instruction to its index.
-  DenseMap<unsigned, Instruction *> IdxToInstr;
+  SmallVector<Instruction *, 64> IdxToInstr;
   // Marks the end of each interval.
   IntervalMap EndPoint;
   // Saves the list of instruction indices that are used in the loop.
@@ -4891,10 +4891,9 @@ LoopVectorizationCostModel::calculateReg
   // defined outside the loop, such as arguments and constants.
   SmallPtrSet<Value *, 8> LoopInvariants;
 
-  unsigned Index = 0;
   for (BasicBlock *BB : make_range(DFS.beginRPO(), DFS.endRPO())) {
     for (Instruction &I : BB->instructionsWithoutDebug()) {
-      IdxToInstr[Index++] = &I;
+      IdxToInstr.push_back(&I);
 
       // Save the end location of each USE.
       for (Value *U : I.operands()) {
@@ -4911,7 +4910,7 @@ LoopVectorizationCostModel::calculateReg
         }
 
         // Overwrite previous end points.
-        EndPoint[Instr] = Index;
+        EndPoint[Instr] = IdxToInstr.size();
         Ends.insert(Instr);
       }
     }
@@ -4948,7 +4947,7 @@ LoopVectorizationCostModel::calculateReg
     return std::max<unsigned>(1, VF * TypeSize / WidestRegister);
   };
 
-  for (unsigned int i = 0; i < Index; ++i) {
+  for (unsigned int i = 0, s = IdxToInstr.size(); i < s; ++i) {
     Instruction *I = IdxToInstr[i];
 
     // Remove all of the instructions that end at this location.




More information about the llvm-commits mailing list