1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 20:23:11 +01:00

[Transforms/Scalar] Use range-based for loops (NFC)

This commit is contained in:
Kazu Hirata 2021-02-04 21:18:05 -08:00
parent f9bdd6d212
commit 9912faec1f
7 changed files with 20 additions and 28 deletions

View File

@ -776,16 +776,16 @@ memoryIsNotModifiedBetween(Instruction *FirstI, Instruction *SecondI, AATy &AA,
if (B != FirstBB) {
assert(B != &FirstBB->getParent()->getEntryBlock() &&
"Should not hit the entry block because SI must be dominated by LI");
for (auto PredI = pred_begin(B), PE = pred_end(B); PredI != PE; ++PredI) {
for (BasicBlock *Pred : predecessors(B)) {
PHITransAddr PredAddr = Addr;
if (PredAddr.NeedsPHITranslationFromBlock(B)) {
if (!PredAddr.IsPotentiallyPHITranslatable())
return false;
if (PredAddr.PHITranslateValue(B, *PredI, DT, false))
if (PredAddr.PHITranslateValue(B, Pred, DT, false))
return false;
}
Value *TranslatedPtr = PredAddr.getAddr();
auto Inserted = Visited.insert(std::make_pair(*PredI, TranslatedPtr));
auto Inserted = Visited.insert(std::make_pair(Pred, TranslatedPtr));
if (!Inserted.second) {
// We already visited this block before. If it was with a different
// address - bail out!
@ -794,7 +794,7 @@ memoryIsNotModifiedBetween(Instruction *FirstI, Instruction *SecondI, AATy &AA,
// ... otherwise just skip it.
continue;
}
WorkList.push_back(std::make_pair(*PredI, PredAddr));
WorkList.push_back(std::make_pair(Pred, PredAddr));
}
}
}
@ -805,8 +805,7 @@ memoryIsNotModifiedBetween(Instruction *FirstI, Instruction *SecondI, AATy &AA,
/// them to F.
static void findUnconditionalPreds(SmallVectorImpl<BasicBlock *> &Blocks,
BasicBlock *BB, DominatorTree *DT) {
for (pred_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I) {
BasicBlock *Pred = *I;
for (BasicBlock *Pred : predecessors(BB)) {
if (Pred == BB) continue;
Instruction *PredTI = Pred->getTerminator();
if (PredTI->getNumSuccessors() != 1)

View File

@ -2795,9 +2795,7 @@ void GVN::addDeadBlock(BasicBlock *BB) {
// For the dead blocks' live successors, update their phi nodes by replacing
// the operands corresponding to dead blocks with UndefVal.
for(SmallSetVector<BasicBlock *, 4>::iterator I = DF.begin(), E = DF.end();
I != E; I++) {
BasicBlock *B = *I;
for (BasicBlock *B : DF) {
if (DeadBlocks.count(B))
continue;

View File

@ -310,9 +310,8 @@ bool LUAnalysisCache::countLoop(const Loop *L, const TargetTransformInfo &TTI,
// consideration code simplification opportunities and code that can
// be shared by the resultant unswitched loops.
CodeMetrics Metrics;
for (Loop::block_iterator I = L->block_begin(), E = L->block_end(); I != E;
++I)
Metrics.analyzeBasicBlock(*I, TTI, EphValues);
for (BasicBlock *BB : L->blocks())
Metrics.analyzeBasicBlock(BB, TTI, EphValues);
Props.SizeEstimation = Metrics.NumInsts;
Props.CanBeUnswitchedCount = MaxSize / (Props.SizeEstimation);
@ -1132,9 +1131,9 @@ static bool isTrivialLoopExitBlockHelper(Loop *L, BasicBlock *BB,
}
// Otherwise, this is an unvisited intra-loop node. Check all successors.
for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI) {
for (BasicBlock *Succ : successors(BB)) {
// Check to see if the successor is a trivial loop exit.
if (!isTrivialLoopExitBlockHelper(L, *SI, ExitBB, Visited))
if (!isTrivialLoopExitBlockHelper(L, Succ, ExitBB, Visited))
return false;
}
@ -1628,9 +1627,7 @@ void LoopUnswitch::unswitchNontrivialCondition(
PHINode *PN = PHINode::Create(LPad->getType(), 0, "",
&*ExitSucc->getFirstInsertionPt());
for (pred_iterator I = pred_begin(ExitSucc), E = pred_end(ExitSucc);
I != E; ++I) {
BasicBlock *BB = *I;
for (BasicBlock *BB : predecessors(ExitSucc)) {
LandingPadInst *LPI = BB->getLandingPadInst();
LPI->replaceAllUsesWith(PN);
PN->addIncoming(LPI, BB);

View File

@ -440,8 +440,7 @@ BCECmpChain::BCECmpChain(const std::vector<BasicBlock *> &Blocks, PHINode &Phi,
// Now look inside blocks to check for BCE comparisons.
std::vector<BCECmpBlock> Comparisons;
BaseIdentifier BaseId;
for (size_t BlockIdx = 0; BlockIdx < Blocks.size(); ++BlockIdx) {
BasicBlock *const Block = Blocks[BlockIdx];
for (BasicBlock *const Block : Blocks) {
assert(Block && "invalid block");
BCECmpBlock Comparison = visitCmpBlock(Phi.getIncomingValueForBlock(Block),
Block, Phi.getParent(), BaseId);

View File

@ -364,8 +364,8 @@ NaryReassociatePass::tryReassociateGEPAtIndex(GetElementPtrInst *GEP,
// Look for GEP's closest dominator that has the same SCEV as GEP except that
// the I-th index is replaced with LHS.
SmallVector<const SCEV *, 4> IndexExprs;
for (auto Index = GEP->idx_begin(); Index != GEP->idx_end(); ++Index)
IndexExprs.push_back(SE->getSCEV(*Index));
for (Use &Index : GEP->indices())
IndexExprs.push_back(SE->getSCEV(Index));
// Replace the I-th index with LHS.
IndexExprs[I] = SE->getSCEV(LHS);
if (isKnownNonNegative(LHS, *DL, 0, AC, GEP, DT) &&

View File

@ -312,8 +312,8 @@ bool StraightLineStrengthReduce::isFoldable(const Candidate &C,
// Returns true if GEP has zero or one non-zero index.
static bool hasOnlyOneNonZeroIndex(GetElementPtrInst *GEP) {
unsigned NumNonZeroIndices = 0;
for (auto I = GEP->idx_begin(); I != GEP->idx_end(); ++I) {
ConstantInt *ConstIdx = dyn_cast<ConstantInt>(*I);
for (Use &Idx : GEP->indices()) {
ConstantInt *ConstIdx = dyn_cast<ConstantInt>(Idx);
if (ConstIdx == nullptr || !ConstIdx->isZero())
++NumNonZeroIndices;
}
@ -533,8 +533,8 @@ void StraightLineStrengthReduce::allocateCandidatesAndFindBasisForGEP(
return;
SmallVector<const SCEV *, 4> IndexExprs;
for (auto I = GEP->idx_begin(); I != GEP->idx_end(); ++I)
IndexExprs.push_back(SE->getSCEV(*I));
for (Use &Idx : GEP->indices())
IndexExprs.push_back(SE->getSCEV(Idx));
gep_type_iterator GTI = gep_type_begin(GEP);
for (unsigned I = 1, E = GEP->getNumOperands(); I != E; ++I, ++GTI) {

View File

@ -677,9 +677,8 @@ void StructurizeCFG::killTerminator(BasicBlock *BB) {
if (!Term)
return;
for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB);
SI != SE; ++SI)
delPhiValues(BB, *SI);
for (BasicBlock *Succ : successors(BB))
delPhiValues(BB, Succ);
if (DA)
DA->removeValue(Term);