minor renaming, documentation and cleanups.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169175 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nadav Rotem 2012-12-03 22:57:09 +00:00
parent 25752e7be7
commit b8f842dce4
2 changed files with 22 additions and 26 deletions

View File

@ -111,7 +111,7 @@ createBBVectorizePass(const VectorizeConfig &C = VectorizeConfig());
// //
// LoopVectorize - Create a loop vectorization pass. // LoopVectorize - Create a loop vectorization pass.
// //
Pass * createLoopVectorizePass(); Pass *createLoopVectorizePass();
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
/// @brief Vectorize the BasicBlock. /// @brief Vectorize the BasicBlock.

View File

@ -118,8 +118,7 @@ class InnerLoopVectorizer {
public: public:
/// Ctor. /// Ctor.
InnerLoopVectorizer(Loop *Orig, ScalarEvolution *Se, LoopInfo *Li, InnerLoopVectorizer(Loop *Orig, ScalarEvolution *Se, LoopInfo *Li,
DominatorTree *Dt, DataLayout *Dl, DominatorTree *Dt, DataLayout *Dl, unsigned VecWidth):
unsigned VecWidth):
OrigLoop(Orig), SE(Se), LI(Li), DT(Dt), DL(Dl), VF(VecWidth), OrigLoop(Orig), SE(Se), LI(Li), DT(Dt), DL(Dl), VF(VecWidth),
Builder(Se->getContext()), Induction(0), OldInduction(0) { } Builder(Se->getContext()), Induction(0), OldInduction(0) { }
@ -343,12 +342,12 @@ private:
/// Check if a single basic block loop is vectorizable. /// Check if a single basic block loop is vectorizable.
/// At this point we know that this is a loop with a constant trip count /// At this point we know that this is a loop with a constant trip count
/// and we only need to check individual instructions. /// and we only need to check individual instructions.
bool canVectorizeInstrs(BasicBlock &BB); bool canVectorizeInstrs();
/// When we vectorize loops we may change the order in which /// When we vectorize loops we may change the order in which
/// we read and write from memory. This method checks if it is /// we read and write from memory. This method checks if it is
/// legal to vectorize the code, considering only memory constrains. /// legal to vectorize the code, considering only memory constrains.
/// Returns true if BB is vectorizable /// Returns true if the loop is vectorizable
bool canVectorizeMemory(); bool canVectorizeMemory();
/// Return true if we can vectorize this loop using the IF-conversion /// Return true if we can vectorize this loop using the IF-conversion
@ -358,7 +357,7 @@ private:
/// Collect the variables that need to stay uniform after vectorization. /// Collect the variables that need to stay uniform after vectorization.
void collectLoopUniforms(); void collectLoopUniforms();
/// return true if all of the instructions in the block can be speculatively /// Return true if all of the instructions in the block can be speculatively
/// executed. /// executed.
bool blockCanBePredicated(BasicBlock *BB); bool blockCanBePredicated(BasicBlock *BB);
@ -1463,7 +1462,7 @@ bool LoopVectorizationLegality::canVectorizeWithIfConvert() {
if (Preds > 2) if (Preds > 2)
return false; return false;
// We must be able to predicate all blocks that needs to be predicated. // We must be able to predicate all blocks that need to be predicated.
if (blockNeedsPredication(BB) && !blockCanBePredicated(BB)) if (blockNeedsPredication(BB) && !blockCanBePredicated(BB))
return false; return false;
} }
@ -1516,7 +1515,7 @@ bool LoopVectorizationLegality::canVectorize() {
} }
// Check if we can vectorize the instructions and CFG in this loop. // Check if we can vectorize the instructions and CFG in this loop.
if (!canVectorizeInstrs(*Header)) { if (!canVectorizeInstrs()) {
DEBUG(dbgs() << "LV: Can't vectorize the instructions or CFG\n"); DEBUG(dbgs() << "LV: Can't vectorize the instructions or CFG\n");
return false; return false;
} }
@ -1527,7 +1526,7 @@ bool LoopVectorizationLegality::canVectorize() {
return false; return false;
} }
// Collect all of the variables that remain uniform after vectorization. // Collect all of the variables that remain uniform after vectorization.
collectLoopUniforms(); collectLoopUniforms();
DEBUG(dbgs() << "LV: We can vectorize this loop" << DEBUG(dbgs() << "LV: We can vectorize this loop" <<
@ -1540,19 +1539,19 @@ bool LoopVectorizationLegality::canVectorize() {
return true; return true;
} }
bool LoopVectorizationLegality::canVectorizeInstrs(BasicBlock &BB) { bool LoopVectorizationLegality::canVectorizeInstrs() {
BasicBlock *PreHeader = TheLoop->getLoopPreheader(); BasicBlock *PreHeader = TheLoop->getLoopPreheader();
BasicBlock *Header = TheLoop->getHeader(); BasicBlock *Header = TheLoop->getHeader();
// For each block in the loop // For each block in the loop.
for (Loop::block_iterator bb = TheLoop->block_begin(), for (Loop::block_iterator bb = TheLoop->block_begin(),
be = TheLoop->block_end(); bb != be; ++bb) { be = TheLoop->block_end(); bb != be; ++bb) {
// Scan the instructions in the block and look for hazards. // Scan the instructions in the block and look for hazards.
for (BasicBlock::iterator it = BB.begin(), e = BB.end(); it != e; ++it) { for (BasicBlock::iterator it = (*bb)->begin(), e = (*bb)->end(); it != e;
Instruction *I = it; ++it) {
if (PHINode *Phi = dyn_cast<PHINode>(I)) { if (PHINode *Phi = dyn_cast<PHINode>(it)) {
// This should not happen because the loop should be normalized. // This should not happen because the loop should be normalized.
if (Phi->getNumIncomingValues() != 2) { if (Phi->getNumIncomingValues() != 2) {
DEBUG(dbgs() << "LV: Found an invalid PHI.\n"); DEBUG(dbgs() << "LV: Found an invalid PHI.\n");
@ -1561,9 +1560,8 @@ bool LoopVectorizationLegality::canVectorizeInstrs(BasicBlock &BB) {
// If this PHINode is not in the header block, then we know that we // If this PHINode is not in the header block, then we know that we
// can convert it to select during if-conversion. // can convert it to select during if-conversion.
if (*bb != Header) { if (*bb != Header)
continue; continue;
}
// This is the value coming from the preheader. // This is the value coming from the preheader.
Value *StartValue = Phi->getIncomingValueForBlock(PreHeader); Value *StartValue = Phi->getIncomingValueForBlock(PreHeader);
@ -1615,26 +1613,26 @@ bool LoopVectorizationLegality::canVectorizeInstrs(BasicBlock &BB) {
}// end of PHI handling }// end of PHI handling
// We still don't handle functions. // We still don't handle functions.
CallInst *CI = dyn_cast<CallInst>(I); CallInst *CI = dyn_cast<CallInst>(it);
if (CI) { if (CI) {
DEBUG(dbgs() << "LV: Found a call site.\n"); DEBUG(dbgs() << "LV: Found a call site.\n");
return false; return false;
} }
// We do not re-vectorize vectors. // We do not re-vectorize vectors.
if (!VectorType::isValidElementType(I->getType()) && if (!VectorType::isValidElementType(it->getType()) &&
!I->getType()->isVoidTy()) { !it->getType()->isVoidTy()) {
DEBUG(dbgs() << "LV: Found unvectorizable type." << "\n"); DEBUG(dbgs() << "LV: Found unvectorizable type." << "\n");
return false; return false;
} }
// Reduction instructions are allowed to have exit users. // Reduction instructions are allowed to have exit users.
// All other instructions must not have external users. // All other instructions must not have external users.
if (!AllowedExit.count(I)) if (!AllowedExit.count(it))
//Check that all of the users of the loop are inside the BB. //Check that all of the users of the loop are inside the BB.
for (Value::use_iterator it = I->use_begin(), e = I->use_end(); for (Value::use_iterator I = it->use_begin(), E = it->use_end();
it != e; ++it) { I != E; ++I) {
Instruction *U = cast<Instruction>(*it); Instruction *U = cast<Instruction>(*I);
// This user may be a reduction exit value. // This user may be a reduction exit value.
if (!TheLoop->contains(U)) { if (!TheLoop->contains(U)) {
DEBUG(dbgs() << "LV: Found an outside user for : "<< *U << "\n"); DEBUG(dbgs() << "LV: Found an outside user for : "<< *U << "\n");
@ -1657,7 +1655,6 @@ void LoopVectorizationLegality::collectLoopUniforms() {
// We now know that the loop is vectorizable! // We now know that the loop is vectorizable!
// Collect variables that will remain uniform after vectorization. // Collect variables that will remain uniform after vectorization.
std::vector<Value*> Worklist; std::vector<Value*> Worklist;
BasicBlock *Latch = TheLoop->getLoopLatch(); BasicBlock *Latch = TheLoop->getLoopLatch();
// Start with the conditional branch and walk up the block. // Start with the conditional branch and walk up the block.
@ -1669,8 +1666,7 @@ void LoopVectorizationLegality::collectLoopUniforms() {
// Look at instructions inside this loop. // Look at instructions inside this loop.
// Stop when reaching PHI nodes. // Stop when reaching PHI nodes.
// TODO: we need to prevent loops but we do need to follow PHIs inside this // TODO: we need to follow values all over the loop, not only in this block.
// loop.
if (!I || !TheLoop->contains(I) || isa<PHINode>(I)) if (!I || !TheLoop->contains(I) || isa<PHINode>(I))
continue; continue;