From be73c7b903647221fbcaae302d31e90f53583040 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Sat, 5 Jan 2013 10:16:02 +0000 Subject: [PATCH] Switch the loop vectorizer from VTTI to just use TTI directly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171620 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Vectorize/LoopVectorize.cpp | 94 +++++++++++----------- lib/Transforms/Vectorize/LoopVectorize.h | 18 ++--- 2 files changed, 54 insertions(+), 58 deletions(-) diff --git a/lib/Transforms/Vectorize/LoopVectorize.cpp b/lib/Transforms/Vectorize/LoopVectorize.cpp index af2e8464d01..1f46b91eb5d 100644 --- a/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -90,12 +90,8 @@ struct LoopVectorize : public LoopPass { return false; } - // Select the preffered vectorization factor. - const VectorTargetTransformInfo *VTTI = 0; - if (TTI) - VTTI = TTI->getVectorTargetTransformInfo(); // Use the cost model. - LoopVectorizationCostModel CM(L, SE, LI, &LVL, VTTI); + LoopVectorizationCostModel CM(L, SE, LI, &LVL, TTI); // Check the function attribues to find out if this function should be // optimized for size. @@ -2134,7 +2130,7 @@ LoopVectorizationCostModel::selectVectorizationFactor(bool OptForSize, return UserVF; } - if (!VTTI) { + if (!TTI) { DEBUG(dbgs() << "LV: No vector target information. Not vectorizing. \n"); return 1; } @@ -2170,7 +2166,7 @@ LoopVectorizationCostModel::selectUnrollFactor(bool OptForSize, if (OptForSize) return 1; - unsigned TargetVectorRegisters = VTTI->getNumberOfRegisters(true); + unsigned TargetVectorRegisters = TTI->getNumberOfRegisters(true); DEBUG(dbgs() << "LV: The target has " << TargetVectorRegisters << " vector registers\n"); @@ -2345,7 +2341,7 @@ unsigned LoopVectorizationCostModel::expectedCost(unsigned VF) { unsigned LoopVectorizationCostModel::getInstructionCost(Instruction *I, unsigned VF) { - assert(VTTI && "Invalid vector target transformation info"); + assert(TTI && "Invalid vector target transformation info"); // If we know that this instruction will remain uniform, check the cost of // the scalar version. @@ -2363,7 +2359,7 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, unsigned VF) { // generate vector geps. return 0; case Instruction::Br: { - return VTTI->getCFInstrCost(I->getOpcode()); + return TTI->getCFInstrCost(I->getOpcode()); } case Instruction::PHI: //TODO: IF-converted IFs become selects. @@ -2386,7 +2382,7 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, unsigned VF) { case Instruction::And: case Instruction::Or: case Instruction::Xor: - return VTTI->getArithmeticInstrCost(I->getOpcode(), VectorTy); + return TTI->getArithmeticInstrCost(I->getOpcode(), VectorTy); case Instruction::Select: { SelectInst *SI = cast(I); const SCEV *CondSCEV = SE->getSCEV(SI->getCondition()); @@ -2395,13 +2391,13 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, unsigned VF) { if (ScalarCond) CondTy = VectorType::get(CondTy, VF); - return VTTI->getCmpSelInstrCost(I->getOpcode(), VectorTy, CondTy); + return TTI->getCmpSelInstrCost(I->getOpcode(), VectorTy, CondTy); } case Instruction::ICmp: case Instruction::FCmp: { Type *ValTy = I->getOperand(0)->getType(); VectorTy = ToVectorTy(ValTy, VF); - return VTTI->getCmpSelInstrCost(I->getOpcode(), VectorTy); + return TTI->getCmpSelInstrCost(I->getOpcode(), VectorTy); } case Instruction::Store: { StoreInst *SI = cast(I); @@ -2409,7 +2405,7 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, unsigned VF) { VectorTy = ToVectorTy(ValTy, VF); if (VF == 1) - return VTTI->getMemoryOpCost(I->getOpcode(), VectorTy, + return TTI->getMemoryOpCost(I->getOpcode(), VectorTy, SI->getAlignment(), SI->getPointerAddressSpace()); @@ -2422,36 +2418,36 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, unsigned VF) { // The cost of extracting from the value vector and pointer vector. Type *PtrTy = ToVectorTy(I->getOperand(0)->getType(), VF); for (unsigned i = 0; i < VF; ++i) { - Cost += VTTI->getVectorInstrCost(Instruction::ExtractElement, - VectorTy, i); - Cost += VTTI->getVectorInstrCost(Instruction::ExtractElement, - PtrTy, i); + Cost += TTI->getVectorInstrCost(Instruction::ExtractElement, + VectorTy, i); + Cost += TTI->getVectorInstrCost(Instruction::ExtractElement, + PtrTy, i); } // The cost of the scalar stores. - Cost += VF * VTTI->getMemoryOpCost(I->getOpcode(), - ValTy->getScalarType(), + Cost += VF * TTI->getMemoryOpCost(I->getOpcode(), + ValTy->getScalarType(), SI->getAlignment(), SI->getPointerAddressSpace()); return Cost; } // Wide stores. - unsigned Cost = VTTI->getMemoryOpCost(I->getOpcode(), VectorTy, - SI->getAlignment(), - SI->getPointerAddressSpace()); + unsigned Cost = TTI->getMemoryOpCost(I->getOpcode(), VectorTy, + SI->getAlignment(), + SI->getPointerAddressSpace()); if (Reverse) - Cost += VTTI->getShuffleCost(VectorTargetTransformInfo::Reverse, - VectorTy, 0); + Cost += TTI->getShuffleCost(TargetTransformInfo::Reverse, + VectorTy, 0); return Cost; } case Instruction::Load: { LoadInst *LI = cast(I); if (VF == 1) - return VTTI->getMemoryOpCost(I->getOpcode(), VectorTy, - LI->getAlignment(), - LI->getPointerAddressSpace()); + return TTI->getMemoryOpCost(I->getOpcode(), VectorTy, + LI->getAlignment(), + LI->getPointerAddressSpace()); // Scalarized loads. int Stride = Legal->isConsecutivePtr(LI->getPointerOperand()); @@ -2462,29 +2458,29 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, unsigned VF) { // The cost of extracting from the pointer vector. for (unsigned i = 0; i < VF; ++i) - Cost += VTTI->getVectorInstrCost(Instruction::ExtractElement, - PtrTy, i); + Cost += TTI->getVectorInstrCost(Instruction::ExtractElement, + PtrTy, i); // The cost of inserting data to the result vector. for (unsigned i = 0; i < VF; ++i) - Cost += VTTI->getVectorInstrCost(Instruction::InsertElement, - VectorTy, i); + Cost += TTI->getVectorInstrCost(Instruction::InsertElement, + VectorTy, i); // The cost of the scalar stores. - Cost += VF * VTTI->getMemoryOpCost(I->getOpcode(), - RetTy->getScalarType(), - LI->getAlignment(), - LI->getPointerAddressSpace()); + Cost += VF * TTI->getMemoryOpCost(I->getOpcode(), + RetTy->getScalarType(), + LI->getAlignment(), + LI->getPointerAddressSpace()); return Cost; } // Wide loads. - unsigned Cost = VTTI->getMemoryOpCost(I->getOpcode(), VectorTy, - LI->getAlignment(), - LI->getPointerAddressSpace()); + unsigned Cost = TTI->getMemoryOpCost(I->getOpcode(), VectorTy, + LI->getAlignment(), + LI->getPointerAddressSpace()); if (Reverse) - Cost += VTTI->getShuffleCost(VectorTargetTransformInfo::Reverse, - VectorTy, 0); + Cost += TTI->getShuffleCost(TargetTransformInfo::Reverse, + VectorTy, 0); return Cost; } case Instruction::ZExt: @@ -2503,11 +2499,11 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, unsigned VF) { // The cost of these is the same as the scalar operation. if (I->getOpcode() == Instruction::Trunc && Legal->isInductionVariable(I->getOperand(0))) - return VTTI->getCastInstrCost(I->getOpcode(), I->getType(), - I->getOperand(0)->getType()); + return TTI->getCastInstrCost(I->getOpcode(), I->getType(), + I->getOperand(0)->getType()); Type *SrcVecTy = ToVectorTy(I->getOperand(0)->getType(), VF); - return VTTI->getCastInstrCost(I->getOpcode(), VectorTy, SrcVecTy); + return TTI->getCastInstrCost(I->getOpcode(), VectorTy, SrcVecTy); } case Instruction::Call: { assert(isTriviallyVectorizableIntrinsic(I)); @@ -2516,7 +2512,7 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, unsigned VF) { SmallVector Tys; for (unsigned i = 0, ie = II->getNumArgOperands(); i != ie; ++i) Tys.push_back(ToVectorTy(II->getArgOperand(i)->getType(), VF)); - return VTTI->getIntrinsicInstrCost(II->getIntrinsicID(), RetTy, Tys); + return TTI->getIntrinsicInstrCost(II->getIntrinsicID(), RetTy, Tys); } default: { // We are scalarizing the instruction. Return the cost of the scalar @@ -2525,10 +2521,10 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, unsigned VF) { unsigned Cost = 0; if (!RetTy->isVoidTy() && VF != 1) { - unsigned InsCost = VTTI->getVectorInstrCost(Instruction::InsertElement, - VectorTy); - unsigned ExtCost = VTTI->getVectorInstrCost(Instruction::ExtractElement, - VectorTy); + unsigned InsCost = TTI->getVectorInstrCost(Instruction::InsertElement, + VectorTy); + unsigned ExtCost = TTI->getVectorInstrCost(Instruction::ExtractElement, + VectorTy); // The cost of inserting the results plus extracting each one of the // operands. @@ -2537,7 +2533,7 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, unsigned VF) { // The cost of executing VF copies of the scalar instruction. This opcode // is unknown. Assume that it is the same as 'mul'. - Cost += VF * VTTI->getArithmeticInstrCost(Instruction::Mul, VectorTy); + Cost += VF * TTI->getArithmeticInstrCost(Instruction::Mul, VectorTy); return Cost; } }// end of switch. diff --git a/lib/Transforms/Vectorize/LoopVectorize.h b/lib/Transforms/Vectorize/LoopVectorize.h index 2333b2bcf94..324d4253020 100644 --- a/lib/Transforms/Vectorize/LoopVectorize.h +++ b/lib/Transforms/Vectorize/LoopVectorize.h @@ -76,7 +76,7 @@ namespace llvm { // Forward declarations. class LoopVectorizationLegality; class LoopVectorizationCostModel; -class VectorTargetTransformInfo; +class TargetTransformInfo; /// InnerLoopVectorizer vectorizes loops which contain only one basic /// block to a specified vectorization factor (VF). @@ -468,18 +468,18 @@ private: /// LoopVectorizationCostModel - estimates the expected speedups due to /// vectorization. -/// In many cases vectorization is not profitable. This can happen because -/// of a number of reasons. In this class we mainly attempt to predict -/// the expected speedup/slowdowns due to the supported instruction set. -/// We use the VectorTargetTransformInfo to query the different backends -/// for the cost of different operations. +/// In many cases vectorization is not profitable. This can happen because of +/// a number of reasons. In this class we mainly attempt to predict the +/// expected speedup/slowdowns due to the supported instruction set. We use the +/// TargetTransformInfo to query the different backends for the cost of +/// different operations. class LoopVectorizationCostModel { public: /// C'tor. LoopVectorizationCostModel(Loop *Lp, ScalarEvolution *Se, LoopInfo *Li, LoopVectorizationLegality *Leg, - const VectorTargetTransformInfo *Vtti): - TheLoop(Lp), SE(Se), LI(Li), Legal(Leg), VTTI(Vtti) { } + const TargetTransformInfo *Tti): + TheLoop(Lp), SE(Se), LI(Li), Legal(Leg), TTI(Tti) { } /// \return The most profitable vectorization factor. /// This method checks every power of two up to VF. If UserVF is not ZERO @@ -532,7 +532,7 @@ private: /// Vectorization legality. LoopVectorizationLegality *Legal; /// Vector target information. - const VectorTargetTransformInfo *VTTI; + const TargetTransformInfo *TTI; }; }// namespace llvm