X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTransforms%2FScalar%2FLoopRerollPass.cpp;h=b6fbb16166dd3de309bfd6399d4fed6894f9d581;hb=73118c41286084de76c9375e7ac40eb46cf40747;hp=144aa7e5c584ae4188514d733a2fe2a588971448;hpb=7f2eff792a2e18758a25956abdac2440ee18dd7f;p=oota-llvm.git diff --git a/lib/Transforms/Scalar/LoopRerollPass.cpp b/lib/Transforms/Scalar/LoopRerollPass.cpp index 144aa7e5c58..b6fbb16166d 100644 --- a/lib/Transforms/Scalar/LoopRerollPass.cpp +++ b/lib/Transforms/Scalar/LoopRerollPass.cpp @@ -11,7 +11,6 @@ // //===----------------------------------------------------------------------===// -#define DEBUG_TYPE "loop-reroll" #include "llvm/Transforms/Scalar.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallSet.h" @@ -36,6 +35,8 @@ using namespace llvm; +#define DEBUG_TYPE "loop-reroll" + STATISTIC(NumRerolledLoops, "Number of rerolled loops"); static cl::opt @@ -125,9 +126,9 @@ namespace { initializeLoopRerollPass(*PassRegistry::getPassRegistry()); } - bool runOnLoop(Loop *L, LPPassManager &LPM); + bool runOnLoop(Loop *L, LPPassManager &LPM) override; - virtual void getAnalysisUsage(AnalysisUsage &AU) const { + void getAnalysisUsage(AnalysisUsage &AU) const override { AU.addRequired(); AU.addRequired(); AU.addPreserved(); @@ -141,7 +142,7 @@ protected: AliasAnalysis *AA; LoopInfo *LI; ScalarEvolution *SE; - DataLayout *DL; + const DataLayout *DL; TargetLibraryInfo *TLI; DominatorTree *DT; @@ -190,12 +191,12 @@ protected: iterator begin() { assert(Valid && "Using invalid reduction"); - return llvm::next(Instructions.begin()); + return std::next(Instructions.begin()); } const_iterator begin() const { assert(Valid && "Using invalid reduction"); - return llvm::next(Instructions.begin()); + return std::next(Instructions.begin()); } iterator end() { return Instructions.end(); } @@ -354,12 +355,9 @@ Pass *llvm::createLoopRerollPass() { // This operates like Instruction::isUsedOutsideOfBlock, but considers PHIs in // non-loop blocks to be outside the loop. static bool hasUsesOutsideLoop(Instruction *I, Loop *L) { - for (Value::use_iterator UI = I->use_begin(), - UIE = I->use_end(); UI != UIE; ++UI) { - Instruction *User = cast(*UI); - if (!L->contains(User)) + for (User *U : I->users()) + if (!L->contains(cast(U))) return true; - } return false; } @@ -409,7 +407,7 @@ void LoopReroll::SimpleLoopReduction::add(Loop *L) { Instruction *C = Instructions.front(); do { - C = cast(*C->use_begin()); + C = cast(*C->user_begin()); if (C->hasOneUse()) { if (!C->isBinaryOp()) return; @@ -424,17 +422,15 @@ void LoopReroll::SimpleLoopReduction::add(Loop *L) { if (Instructions.size() < 2 || !C->isSameOperationAs(Instructions.back()) || - C->use_begin() == C->use_end()) + C->use_empty()) return; // C is now the (potential) last instruction in the reduction chain. - for (Value::use_iterator UI = C->use_begin(), UIE = C->use_end(); - UI != UIE; ++UI) { + for (User *U : C->users()) // The only in-loop user can be the initial PHI. - if (L->contains(cast(*UI))) - if (cast(*UI ) != Instructions.front()) + if (L->contains(cast(U))) + if (cast(U) != Instructions.front()) return; - } Instructions.push_back(C); Valid = true; @@ -484,12 +480,11 @@ void LoopReroll::collectInLoopUserSet(Loop *L, continue; if (!Final.count(I)) - for (Value::use_iterator UI = I->use_begin(), - UIE = I->use_end(); UI != UIE; ++UI) { - Instruction *User = cast(*UI); + for (Use &U : I->uses()) { + Instruction *User = cast(U.getUser()); if (PHINode *PN = dyn_cast(User)) { // Ignore "wrap-around" uses to PHIs of this loop's header. - if (PN->getIncomingBlock(UI) == L->getHeader()) + if (PN->getIncomingBlock(U) == L->getHeader()) continue; } @@ -560,8 +555,8 @@ bool LoopReroll::findScaleFromMul(Instruction *RealIV, uint64_t &Scale, if (RealIV->getNumUses() != 2) return false; const SCEVAddRecExpr *RealIVSCEV = cast(SE->getSCEV(RealIV)); - Instruction *User1 = cast(*RealIV->use_begin()), - *User2 = cast(*llvm::next(RealIV->use_begin())); + Instruction *User1 = cast(*RealIV->user_begin()), + *User2 = cast(*std::next(RealIV->user_begin())); if (!SE->isSCEVable(User1->getType()) || !SE->isSCEVable(User2->getType())) return false; const SCEVAddRecExpr *User1SCEV = @@ -617,26 +612,25 @@ bool LoopReroll::collectAllRoots(Loop *L, uint64_t Inc, uint64_t Scale, SmallVector &Roots, SmallInstructionSet &AllRoots, SmallInstructionVector &LoopIncs) { - for (Value::use_iterator UI = IV->use_begin(), - UIE = IV->use_end(); UI != UIE; ++UI) { - Instruction *User = cast(*UI); - if (!SE->isSCEVable(User->getType())) + for (User *U : IV->users()) { + Instruction *UI = cast(U); + if (!SE->isSCEVable(UI->getType())) continue; - if (User->getType() != IV->getType()) + if (UI->getType() != IV->getType()) continue; - if (!L->contains(User)) + if (!L->contains(UI)) continue; - if (hasUsesOutsideLoop(User, L)) + if (hasUsesOutsideLoop(UI, L)) continue; if (const SCEVConstant *Diff = dyn_cast(SE->getMinusSCEV( - SE->getSCEV(User), SE->getSCEV(IV)))) { + SE->getSCEV(UI), SE->getSCEV(IV)))) { uint64_t Idx = Diff->getValue()->getValue().getZExtValue(); if (Idx > 0 && Idx < Scale) { - Roots[Idx-1].push_back(User); - AllRoots.insert(User); + Roots[Idx-1].push_back(UI); + AllRoots.insert(UI); } else if (Idx == Scale && Inc > 1) { - LoopIncs.push_back(User); + LoopIncs.push_back(UI); } } } @@ -720,10 +714,8 @@ void LoopReroll::ReductionTracker::replaceSelected() { // Replace users with the new end-of-chain value. SmallInstructionVector Users; - for (Value::use_iterator UI = - PossibleReds[i].getReducedValue()->use_begin(), - UIE = PossibleReds[i].getReducedValue()->use_end(); UI != UIE; ++UI) - Users.push_back(cast(*UI)); + for (User *U : PossibleReds[i].getReducedValue()->users()) + Users.push_back(cast(U)); for (SmallInstructionVector::iterator J = Users.begin(), JE = Users.end(); J != JE; ++J) @@ -932,8 +924,10 @@ bool LoopReroll::reroll(Instruction *IV, Loop *L, BasicBlock *Header, // them, and this matching fails. As an exception, we allow the alias // set tracker to handle regular (simple) load/store dependencies. if (FutureSideEffects && - ((!isSimpleLoadStore(J1) && !isSafeToSpeculativelyExecute(J1)) || - (!isSimpleLoadStore(J2) && !isSafeToSpeculativelyExecute(J2)))) { + ((!isSimpleLoadStore(J1) && + !isSafeToSpeculativelyExecute(J1, DL)) || + (!isSimpleLoadStore(J2) && + !isSafeToSpeculativelyExecute(J2, DL)))) { DEBUG(dbgs() << "LRR: iteration root match failed at " << *J1 << " vs. " << *J2 << " (side effects prevent reordering)\n"); @@ -954,7 +948,7 @@ bool LoopReroll::reroll(Instruction *IV, Loop *L, BasicBlock *Header, bool InReduction = Reductions.isPairInSame(J1, J2); if (!(InReduction && J1->isAssociative())) { - bool Swapped = false, SomeOpMatched = false;; + bool Swapped = false, SomeOpMatched = false; for (unsigned j = 0; j < J1->getNumOperands() && !MatchFailed; ++j) { Value *Op2 = J2->getOperand(j); @@ -1134,11 +1128,15 @@ bool LoopReroll::reroll(Instruction *IV, Loop *L, BasicBlock *Header, } bool LoopReroll::runOnLoop(Loop *L, LPPassManager &LPM) { + if (skipOptnoneFunction(L)) + return false; + AA = &getAnalysis(); LI = &getAnalysis(); SE = &getAnalysis(); TLI = &getAnalysis(); - DL = getAnalysisIfAvailable(); + DataLayoutPass *DLP = getAnalysisIfAvailable(); + DL = DLP ? &DLP->getDataLayout() : nullptr; DT = &getAnalysis().getDomTree(); BasicBlock *Header = L->getHeader();