[llvm] r179935 - SLPVectorizer: Strength reduce SmallVectors to ArrayRefs.

Benjamin Kramer benny.kra at googlemail.com
Sat Apr 20 02:49:11 PDT 2013


Author: d0k
Date: Sat Apr 20 04:49:10 2013
New Revision: 179935

URL: http://llvm.org/viewvc/llvm-project?rev=179935&view=rev
Log:
SLPVectorizer: Strength reduce SmallVectors to ArrayRefs.

Avoids a couple of copies and allows more flexibility in the clients.

Modified:
    llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp
    llvm/trunk/lib/Transforms/Vectorize/VecUtils.cpp
    llvm/trunk/lib/Transforms/Vectorize/VecUtils.h

Modified: llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp?rev=179935&r1=179934&r2=179935&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp Sat Apr 20 04:49:10 2013
@@ -128,7 +128,7 @@ private:
   bool tryToVectorizePair(Value *A, Value *B,  BoUpSLP &R);
 
   /// \brief Try to vectorize a list of operands.
-  bool tryToVectorizeList(BoUpSLP::ValueList &VL, BoUpSLP &R);
+  bool tryToVectorizeList(ArrayRef<Value *> VL, BoUpSLP &R);
 
   /// \brief Try to vectorize a chain that may start at the operands of \V;
   bool tryToVectorize(BinaryOperator *V,  BoUpSLP &R);
@@ -174,13 +174,11 @@ unsigned SLPVectorizer::collectStores(Ba
 
 bool SLPVectorizer::tryToVectorizePair(Value *A, Value *B,  BoUpSLP &R) {
   if (!A || !B) return false;
-  BoUpSLP::ValueList VL;
-  VL.push_back(A);
-  VL.push_back(B);
+  Value *VL[] = { A, B };
   return tryToVectorizeList(VL, R);
 }
 
-bool SLPVectorizer::tryToVectorizeList(BoUpSLP::ValueList &VL,  BoUpSLP &R) {
+bool SLPVectorizer::tryToVectorizeList(ArrayRef<Value *> VL, BoUpSLP &R) {
   DEBUG(dbgs()<<"SLP: Vectorizing a list of length = " << VL.size() << ".\n");
   int Cost = R.getTreeCost(VL);
   int ExtrCost = R.getScalarizationCost(VL);

Modified: llvm/trunk/lib/Transforms/Vectorize/VecUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/VecUtils.cpp?rev=179935&r1=179934&r2=179935&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Vectorize/VecUtils.cpp (original)
+++ llvm/trunk/lib/Transforms/Vectorize/VecUtils.cpp Sat Apr 20 04:49:10 2013
@@ -103,7 +103,7 @@ bool BoUpSLP::isConsecutiveAccess(Value
   return ((-Offset) == Sz);
 }
 
-bool BoUpSLP::vectorizeStoreChain(ValueList &Chain, int CostThreshold) {
+bool BoUpSLP::vectorizeStoreChain(ArrayRef<Value *> Chain, int CostThreshold) {
   Type *StoreTy = cast<StoreInst>(Chain[0])->getValueOperand()->getType();
   unsigned Sz = DL->getTypeSizeInBits(StoreTy);
   unsigned VF = MinVecRegSize / Sz;
@@ -115,7 +115,7 @@ bool BoUpSLP::vectorizeStoreChain(ValueL
   for (unsigned i = 0, e = Chain.size(); i < e; ++i) {
     if (i + VF > e) return Changed;
     DEBUG(dbgs()<<"SLP: Analyzing " << VF << " stores at offset "<< i << "\n");
-    ValueList Operands(&Chain[i], &Chain[i] + VF);
+    ArrayRef<Value *> Operands = Chain.slice(i, VF);
 
     int Cost = getTreeCost(Operands);
     DEBUG(dbgs() << "SLP: Found cost=" << Cost << " for VF=" << VF << "\n");
@@ -130,7 +130,7 @@ bool BoUpSLP::vectorizeStoreChain(ValueL
   return Changed;
 }
 
-bool BoUpSLP::vectorizeStores(StoreList &Stores, int costThreshold) {
+bool BoUpSLP::vectorizeStores(ArrayRef<StoreInst *> Stores, int costThreshold) {
   ValueSet Heads, Tails;
   SmallDenseMap<Value*, Value*> ConsecutiveChain;
 
@@ -178,7 +178,7 @@ bool BoUpSLP::vectorizeStores(StoreList
   return Changed;
 }
 
-int BoUpSLP::getScalarizationCost(ValueList &VL) {
+int BoUpSLP::getScalarizationCost(ArrayRef<Value *> VL) {
   // Find the type of the operands in VL.
   Type *ScalarTy = VL[0]->getType();
   if (StoreInst *SI = dyn_cast<StoreInst>(VL[0]))
@@ -223,7 +223,7 @@ Value *BoUpSLP::isUnsafeToSink(Instructi
   return 0;
 }
 
-void BoUpSLP::vectorizeArith(ValueList &Operands) {
+void BoUpSLP::vectorizeArith(ArrayRef<Value *> Operands) {
   Value *Vec = vectorizeTree(Operands, Operands.size());
   BasicBlock::iterator Loc = cast<Instruction>(Vec);
   IRBuilder<> Builder(++Loc);
@@ -236,7 +236,7 @@ void BoUpSLP::vectorizeArith(ValueList &
   }
 }
 
-int BoUpSLP::getTreeCost(ValueList &VL) {
+int BoUpSLP::getTreeCost(ArrayRef<Value *> VL) {
   // Get rid of the list of stores that were removed, and from the
   // lists of instructions with multiple users.
   MemBarrierIgnoreList.clear();
@@ -278,7 +278,7 @@ int BoUpSLP::getTreeCost(ValueList &VL)
   return getTreeCost_rec(VL, 0);
 }
 
-void BoUpSLP::getTreeUses_rec(ValueList &VL, unsigned Depth) {
+void BoUpSLP::getTreeUses_rec(ArrayRef<Value *> VL, unsigned Depth) {
   if (Depth == RecursionMaxDepth) return;
 
   // Don't handle vectors.
@@ -367,7 +367,7 @@ void BoUpSLP::getTreeUses_rec(ValueList
   }
 }
 
-int BoUpSLP::getTreeCost_rec(ValueList &VL, unsigned Depth) {
+int BoUpSLP::getTreeCost_rec(ArrayRef<Value *> VL, unsigned Depth) {
   Type *ScalarTy = VL[0]->getType();
 
   if (StoreInst *SI = dyn_cast<StoreInst>(VL[0]))
@@ -516,14 +516,14 @@ int BoUpSLP::getTreeCost_rec(ValueList &
   }
 }
 
-Instruction *BoUpSLP::GetLastInstr(ValueList &VL, unsigned VF) {
+Instruction *BoUpSLP::GetLastInstr(ArrayRef<Value *> VL, unsigned VF) {
   int MaxIdx = InstrIdx[BB->getFirstNonPHI()];
   for (unsigned i = 0; i < VF; ++i )
     MaxIdx = std::max(MaxIdx, InstrIdx[VL[i]]);
   return InstrVec[MaxIdx + 1];
 }
 
-Value *BoUpSLP::Scalarize(ValueList &VL, VectorType *Ty) {
+Value *BoUpSLP::Scalarize(ArrayRef<Value *> VL, VectorType *Ty) {
   IRBuilder<> Builder(GetLastInstr(VL, Ty->getNumElements()));
   Value *Vec = UndefValue::get(Ty);
   for (unsigned i=0; i < Ty->getNumElements(); ++i) {
@@ -538,7 +538,7 @@ Value *BoUpSLP::Scalarize(ValueList &VL,
   return Vec;
 }
 
-Value *BoUpSLP::vectorizeTree(ValueList &VL, int VF) {
+Value *BoUpSLP::vectorizeTree(ArrayRef<Value *> VL, int VF) {
   Value *V = vectorizeTree_rec(VL, VF);
   // We moved some instructions around. We have to number them again
   // before we can do any analysis.
@@ -547,7 +547,7 @@ Value *BoUpSLP::vectorizeTree(ValueList
   return V;
 }
 
-Value *BoUpSLP::vectorizeTree_rec(ValueList &VL, int VF) {
+Value *BoUpSLP::vectorizeTree_rec(ArrayRef<Value *> VL, int VF) {
   Type *ScalarTy = VL[0]->getType();
   if (StoreInst *SI = dyn_cast<StoreInst>(VL[0]))
     ScalarTy = SI->getValueOperand()->getType();

Modified: llvm/trunk/lib/Transforms/Vectorize/VecUtils.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/VecUtils.h?rev=179935&r1=179934&r2=179935&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Vectorize/VecUtils.h (original)
+++ llvm/trunk/lib/Transforms/Vectorize/VecUtils.h Sat Apr 20 04:49:10 2013
@@ -53,24 +53,24 @@ struct BoUpSLP  {
 
   /// \brief Vectorize the tree that starts with the elements in \p VL.
   /// \returns the vectorized value.
-  Value *vectorizeTree(ValueList &VL, int VF);
+  Value *vectorizeTree(ArrayRef<Value *> VL, int VF);
 
   /// \returns the vectorization cost of the subtree that starts at \p VL.
   /// A negative number means that this is profitable.
-  int getTreeCost(ValueList &VL);
+  int getTreeCost(ArrayRef<Value *> VL);
 
-  /// \returns the scalarization cost for this ValueList. Assuming that this
-  /// subtree gets vectorized, we may need to extract the values from the
+  /// \returns the scalarization cost for this list of values. Assuming that
+  /// this subtree gets vectorized, we may need to extract the values from the
   /// roots. This method calculates the cost of extracting the values.
-  int getScalarizationCost(ValueList &VL);
+  int getScalarizationCost(ArrayRef<Value *> VL);
 
   /// \brief Attempts to order and vectorize a sequence of stores. This
   /// function does a quadratic scan of the given stores.
   /// \returns true if the basic block was modified.
-  bool vectorizeStores(StoreList &Stores, int costThreshold);
+  bool vectorizeStores(ArrayRef<StoreInst *> Stores, int costThreshold);
 
   /// \brief Vectorize a group of scalars into a vector tree.
-  void vectorizeArith(ValueList &Operands);
+  void vectorizeArith(ArrayRef<Value *> Operands);
 
   /// \returns the list of new instructions that were added in order to collect
   /// scalars into vectors. This list can be used to further optimize the gather
@@ -79,21 +79,21 @@ struct BoUpSLP  {
 
 private:
   /// \brief This method contains the recursive part of getTreeCost.
-  int getTreeCost_rec(ValueList &VL, unsigned Depth);
+  int getTreeCost_rec(ArrayRef<Value *> VL, unsigned Depth);
 
   /// \brief This recursive method looks for vectorization hazards such as
   /// values that are used by multiple users and checks that values are used
   /// by only one vector lane. It updates the variables LaneMap, MultiUserVals.
-  void getTreeUses_rec(ValueList &VL, unsigned Depth);
+  void getTreeUses_rec(ArrayRef<Value *> VL, unsigned Depth);
 
   /// \brief This method contains the recursive part of vectorizeTree.
-  Value *vectorizeTree_rec(ValueList &VL, int VF);
+  Value *vectorizeTree_rec(ArrayRef<Value *> VL, int VF);
 
   /// \brief Number all of the instructions in the block.
   void numberInstructions();
 
   ///  \brief Vectorize a sorted sequence of stores.
-  bool vectorizeStoreChain(ValueList &Chain, int CostThreshold);
+  bool vectorizeStoreChain(ArrayRef<Value *> Chain, int CostThreshold);
 
   /// \returns the scalarization cost for this type. Scalarization in this
   /// context means the creation of vectors from a group of scalars.
@@ -109,10 +109,10 @@ private:
 
   /// \returns the instruction that appears last in the BB from \p VL.
   /// Only consider the first \p VF elements.
-  Instruction *GetLastInstr(ValueList &VL, unsigned VF);
+  Instruction *GetLastInstr(ArrayRef<Value *> VL, unsigned VF);
 
   /// \returns a vector from a collection of scalars in \p VL.
-  Value *Scalarize(ValueList &VL, VectorType *Ty);
+  Value *Scalarize(ArrayRef<Value *> VL, VectorType *Ty);
 
 private:
   /// Maps instructions to numbers and back.





More information about the llvm-commits mailing list