From 0b827993ed98b20425c33fecaa06b7b1a32a40c4 Mon Sep 17 00:00:00 2001 From: Nadav Rotem Date: Thu, 20 Jun 2013 17:54:36 +0000 Subject: Clang-format the SLP vectorizer. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184446 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Vectorize/SLPVectorizer.cpp | 96 +++++++++++++++++------------- 1 file changed, 53 insertions(+), 43 deletions(-) (limited to 'lib/Transforms/Vectorize/SLPVectorizer.cpp') diff --git a/lib/Transforms/Vectorize/SLPVectorizer.cpp b/lib/Transforms/Vectorize/SLPVectorizer.cpp index 91c0463..c3cb037 100644 --- a/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -41,14 +41,14 @@ using namespace llvm; static cl::opt -SLPCostThreshold("slp-threshold", cl::init(0), cl::Hidden, - cl::desc("Only vectorize trees if the gain is above this " - "number. (gain = -cost of vectorization)")); + SLPCostThreshold("slp-threshold", cl::init(0), cl::Hidden, + cl::desc("Only vectorize trees if the gain is above this " + "number. (gain = -cost of vectorization)")); namespace { /// The SLPVectorizer Pass. struct SLPVectorizer : public FunctionPass { - typedef MapVector StoreListMap; + typedef MapVector StoreListMap; /// Pass identification, replacement for typeid static char ID; @@ -78,7 +78,7 @@ struct SLPVectorizer : public FunctionPass { if (!DL) return false; - DEBUG(dbgs()<<"SLP: Analyzing blocks in " << F.getName() << ".\n"); + DEBUG(dbgs() << "SLP: Analyzing blocks in " << F.getName() << ".\n"); for (Function::iterator it = F.begin(), e = F.end(); it != e; ++it) { BasicBlock *BB = it; @@ -94,7 +94,7 @@ struct SLPVectorizer : public FunctionPass { // Vectorize trees that end at stores. if (unsigned count = collectStores(BB, R)) { (void)count; - DEBUG(dbgs()<<"SLP: Found " << count << " stores to vectorize.\n"); + DEBUG(dbgs() << "SLP: Found " << count << " stores to vectorize.\n"); BBChanged |= vectorizeStoreChains(R); } @@ -108,7 +108,7 @@ struct SLPVectorizer : public FunctionPass { } if (Changed) { - DEBUG(dbgs()<<"SLP: vectorized \""< VL, BoUpSLP &R, bool NeedExtracts); /// \brief Try to vectorize a chain that may start at the operands of \V; - bool tryToVectorize(BinaryOperator *V, BoUpSLP &R); + bool tryToVectorize(BinaryOperator *V, BoUpSLP &R); /// \brief Vectorize the stores that were collected in StoreRefs. bool vectorizeStoreChains(BoUpSLP &R); @@ -188,8 +188,9 @@ unsigned SLPVectorizer::collectStores(BasicBlock *BB, BoUpSLP &R) { return count; } -bool SLPVectorizer::tryToVectorizePair(Value *A, Value *B, BoUpSLP &R) { - if (!A || !B) return false; +bool SLPVectorizer::tryToVectorizePair(Value *A, Value *B, BoUpSLP &R) { + if (!A || !B) + return false; Value *VL[] = { A, B }; return tryToVectorizeList(VL, R, true); } @@ -199,11 +200,12 @@ bool SLPVectorizer::tryToVectorizeList(ArrayRef VL, BoUpSLP &R, if (VL.size() < 2) return false; - DEBUG(dbgs()<<"SLP: Vectorizing a list of length = " << VL.size() << ".\n"); + DEBUG(dbgs() << "SLP: Vectorizing a list of length = " << VL.size() << ".\n"); // Check that all of the parts are scalar instructions of the same type. Instruction *I0 = dyn_cast(VL[0]); - if (!I0) return 0; + if (!I0) + return 0; unsigned Opcode0 = I0->getOpcode(); @@ -217,17 +219,20 @@ bool SLPVectorizer::tryToVectorizeList(ArrayRef VL, BoUpSLP &R, } int Cost = R.getTreeCost(VL); - int ExtrCost = NeedExtracts ? R.getScalarizationCost(VL) : 0; - DEBUG(dbgs()<<"SLP: Cost of pair:" << Cost << - " Cost of extract:" << ExtrCost << ".\n"); - if ((Cost+ExtrCost) >= -SLPCostThreshold) return false; - DEBUG(dbgs()<<"SLP: Vectorizing pair.\n"); + int ExtrCost = NeedExtracts ? R.getScalarizationCost(VL) : 0; + DEBUG(dbgs() << "SLP: Cost of pair:" << Cost + << " Cost of extract:" << ExtrCost << ".\n"); + if ((Cost + ExtrCost) >= -SLPCostThreshold) + return false; + DEBUG(dbgs() << "SLP: Vectorizing pair.\n"); R.vectorizeArith(VL); return true; } -bool SLPVectorizer::tryToVectorize(BinaryOperator *V, BoUpSLP &R) { - if (!V) return false; +bool SLPVectorizer::tryToVectorize(BinaryOperator *V, BoUpSLP &R) { + if (!V) + return false; + // Try to vectorize V. if (tryToVectorizePair(V->getOperand(0), V->getOperand(1), R)) return true; @@ -267,22 +272,27 @@ bool SLPVectorizer::tryToVectorize(BinaryOperator *V, BoUpSLP &R) { bool SLPVectorizer::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) { bool Changed = false; for (BasicBlock::iterator it = BB->begin(), e = BB->end(); it != e; ++it) { - if (isa(it)) continue; + if (isa(it)) + continue; // Try to vectorize reductions that use PHINodes. if (PHINode *P = dyn_cast(it)) { // Check that the PHI is a reduction PHI. - if (P->getNumIncomingValues() != 2) return Changed; - Value *Rdx = (P->getIncomingBlock(0) == BB ? P->getIncomingValue(0) : - (P->getIncomingBlock(1) == BB ? P->getIncomingValue(1) : - 0)); + if (P->getNumIncomingValues() != 2) + return Changed; + Value *Rdx = + (P->getIncomingBlock(0) == BB + ? (P->getIncomingValue(0)) + : (P->getIncomingBlock(1) == BB ? P->getIncomingValue(1) : 0)); // Check if this is a Binary Operator. BinaryOperator *BI = dyn_cast_or_null(Rdx); if (!BI) continue; Value *Inst = BI->getOperand(0); - if (Inst == P) Inst = BI->getOperand(1); + if (Inst == P) + Inst = BI->getOperand(1); + Changed |= tryToVectorize(dyn_cast(Inst), R); continue; } @@ -295,7 +305,8 @@ bool SLPVectorizer::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) { } for (int i = 0; i < 2; ++i) if (BinaryOperator *BI = dyn_cast(CI->getOperand(i))) - Changed |= tryToVectorizePair(BI->getOperand(0), BI->getOperand(1), R); + Changed |= + tryToVectorizePair(BI->getOperand(0), BI->getOperand(1), R); continue; } } @@ -303,7 +314,7 @@ bool SLPVectorizer::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) { // Scan the PHINodes in our successors in search for pairing hints. for (succ_iterator it = succ_begin(BB), e = succ_end(BB); it != e; ++it) { BasicBlock *Succ = *it; - SmallVector Incoming; + SmallVector Incoming; // Collect the incoming values from the PHIs. for (BasicBlock::iterator instr = Succ->begin(), ie = Succ->end(); @@ -322,7 +333,7 @@ bool SLPVectorizer::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) { if (Incoming.size() > 1) Changed |= tryToVectorizeList(Incoming, R, true); } - + return Changed; } @@ -334,8 +345,8 @@ bool SLPVectorizer::vectorizeStoreChains(BoUpSLP &R) { if (it->second.size() < 2) continue; - DEBUG(dbgs()<<"SLP: Analyzing a store chain of length " << - it->second.size() << ".\n"); + DEBUG(dbgs() << "SLP: Analyzing a store chain of length " + << it->second.size() << ".\n"); Changed |= R.vectorizeStores(it->second, -SLPCostThreshold); } @@ -343,7 +354,7 @@ bool SLPVectorizer::vectorizeStoreChains(BoUpSLP &R) { } bool SLPVectorizer::vectorizeUsingGatherHints(BoUpSLP::InstrList &Gathers) { - SmallVector Seq; + SmallVector Seq; bool Changed = false; for (int i = 0, e = Gathers.size(); i < e; ++i) { InsertElementInst *IEI = dyn_cast_or_null(Gathers[i]); @@ -359,13 +370,13 @@ bool SLPVectorizer::vectorizeUsingGatherHints(BoUpSLP::InstrList &Gathers) { Instruction *I = cast(Seq[0]); BasicBlock *BB = I->getParent(); - DEBUG(dbgs()<<"SLP: Inspecting a gather list of size " << Seq.size() << - " in " << BB->getName() << ".\n"); + DEBUG(dbgs() << "SLP: Inspecting a gather list of size " << Seq.size() + << " in " << BB->getName() << ".\n"); // Check if the gathered values have multiple uses. If they only have one // user then we know that the insert/extract pair will go away. bool HasMultipleUsers = false; - for (int i=0; e = Seq.size(), i < e; ++i) { + for (int i = 0; e = Seq.size(), i < e; ++i) { if (!Seq[i]->hasOneUse()) { HasMultipleUsers = true; break; @@ -375,8 +386,8 @@ bool SLPVectorizer::vectorizeUsingGatherHints(BoUpSLP::InstrList &Gathers) { BoUpSLP BO(BB, SE, DL, TTI, AA, LI->getLoopFor(BB)); if (tryToVectorizeList(Seq, BO, HasMultipleUsers)) { - DEBUG(dbgs()<<"SLP: Vectorized a gather list of len " << Seq.size() << - " in " << BB->getName() << ".\n"); + DEBUG(dbgs() << "SLP: Vectorized a gather list of len " << Seq.size() + << " in " << BB->getName() << ".\n"); Changed = true; } @@ -418,8 +429,10 @@ void SLPVectorizer::hoistGatherSequence(LoopInfo *LI, BasicBlock *BB, // hoist this instruction. Instruction *CurrVec = dyn_cast(Insert->getOperand(0)); Instruction *NewElem = dyn_cast(Insert->getOperand(1)); - if (CurrVec && L->contains(CurrVec)) continue; - if (NewElem && L->contains(NewElem)) continue; + if (CurrVec && L->contains(CurrVec)) + continue; + if (NewElem && L->contains(NewElem)) + continue; // We can hoist this instruction. Move it to the pre-header. Insert->moveBefore(Location); @@ -438,8 +451,5 @@ INITIALIZE_PASS_DEPENDENCY(LoopSimplify) INITIALIZE_PASS_END(SLPVectorizer, SV_NAME, lv_name, false, false) namespace llvm { - Pass *createSLPVectorizerPass() { - return new SLPVectorizer(); - } +Pass *createSLPVectorizerPass() { return new SLPVectorizer(); } } - -- cgit v1.1