diff options
Diffstat (limited to 'lib/Transforms/Scalar/SCCP.cpp')
-rw-r--r-- | lib/Transforms/Scalar/SCCP.cpp | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index 91e625b7aac..d4c156e994c 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -1277,11 +1277,11 @@ void SCCPSolver::Solve() { /// conservatively, as "(zext i8 X -> i32) & 0xFF00" must always return zero, /// even if X isn't defined. bool SCCPSolver::ResolvedUndefsIn(Function &F) { - for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { - if (!BBExecutable.count(&*BB)) + for (BasicBlock &BB : F) { + if (!BBExecutable.count(&BB)) continue; - for (Instruction &I : *BB) { + for (Instruction &I : BB) { // Look for instructions which produce undef values. if (I.getType()->isVoidTy()) continue; @@ -1505,7 +1505,7 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) { // Check to see if we have a branch or switch on an undefined value. If so // we force the branch to go one way or the other to make the successor // values live. It doesn't really matter which way we force it. - TerminatorInst *TI = BB->getTerminator(); + TerminatorInst *TI = BB.getTerminator(); if (BranchInst *BI = dyn_cast<BranchInst>(TI)) { if (!BI->isConditional()) continue; if (!getValueState(BI->getCondition()).isUndefined()) @@ -1515,7 +1515,7 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) { // false. if (isa<UndefValue>(BI->getCondition())) { BI->setCondition(ConstantInt::getFalse(BI->getContext())); - markEdgeExecutable(&*BB, TI->getSuccessor(1)); + markEdgeExecutable(&BB, TI->getSuccessor(1)); return true; } @@ -1537,7 +1537,7 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) { // the first constant. if (isa<UndefValue>(SI->getCondition())) { SI->setCondition(SI->case_begin().getCaseValue()); - markEdgeExecutable(&*BB, SI->case_begin().getCaseSuccessor()); + markEdgeExecutable(&BB, SI->case_begin().getCaseSuccessor()); return true; } @@ -1578,12 +1578,12 @@ static bool runSCCP(Function &F, const DataLayout &DL, // delete their contents now. Note that we cannot actually delete the blocks, // as we cannot modify the CFG of the function. - for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { - if (!Solver.isBlockExecutable(&*BB)) { - DEBUG(dbgs() << " BasicBlock Dead:" << *BB); + for (BasicBlock &BB : F) { + if (!Solver.isBlockExecutable(&BB)) { + DEBUG(dbgs() << " BasicBlock Dead:" << BB); ++NumDeadBlocks; - NumInstRemoved += removeAllNonTerminatorAndEHPadInstructions(&*BB); + NumInstRemoved += removeAllNonTerminatorAndEHPadInstructions(&BB); MadeChanges = true; continue; @@ -1592,7 +1592,7 @@ static bool runSCCP(Function &F, const DataLayout &DL, // Iterate over all of the instructions in a function, replacing them with // constants if we have found them to be of constant values. // - for (BasicBlock::iterator BI = BB->begin(), E = BB->end(); BI != E; ) { + for (BasicBlock::iterator BI = BB.begin(), E = BB.end(); BI != E;) { Instruction *Inst = &*BI++; if (Inst->getType()->isVoidTy() || isa<TerminatorInst>(Inst)) continue; @@ -1760,8 +1760,8 @@ static bool runIPSCCP(Module &M, const DataLayout &DL, DEBUG(dbgs() << "RESOLVING UNDEFS\n"); ResolvedUndefs = false; - for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) - ResolvedUndefs |= Solver.ResolvedUndefsIn(*F); + for (Function &F : M) + ResolvedUndefs |= Solver.ResolvedUndefsIn(F); } bool MadeChanges = false; @@ -1771,13 +1771,13 @@ static bool runIPSCCP(Module &M, const DataLayout &DL, // SmallVector<BasicBlock*, 512> BlocksToErase; - for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) { - if (F->isDeclaration()) + for (Function &F : M) { + if (F.isDeclaration()) continue; - if (Solver.isBlockExecutable(&F->front())) { - for (Function::arg_iterator AI = F->arg_begin(), E = F->arg_end(); - AI != E; ++AI) { + if (Solver.isBlockExecutable(&F.front())) { + for (Function::arg_iterator AI = F.arg_begin(), E = F.arg_end(); AI != E; + ++AI) { if (AI->use_empty() || AI->getType()->isStructTy()) continue; // TODO: Could use getStructLatticeValueFor to find out if the entire @@ -1797,7 +1797,7 @@ static bool runIPSCCP(Module &M, const DataLayout &DL, } } - for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) { + for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { if (!Solver.isBlockExecutable(&*BB)) { DEBUG(dbgs() << " BasicBlock Dead:" << *BB); @@ -1807,7 +1807,7 @@ static bool runIPSCCP(Module &M, const DataLayout &DL, MadeChanges = true; - if (&*BB != &F->front()) + if (&*BB != &F.front()) BlocksToErase.push_back(&*BB); continue; } @@ -1889,7 +1889,7 @@ static bool runIPSCCP(Module &M, const DataLayout &DL, } // Finally, delete the basic block. - F->getBasicBlockList().erase(DeadBB); + F.getBasicBlockList().erase(DeadBB); } BlocksToErase.clear(); } @@ -1908,18 +1908,17 @@ static bool runIPSCCP(Module &M, const DataLayout &DL, // TODO: Process multiple value ret instructions also. const DenseMap<Function*, LatticeVal> &RV = Solver.getTrackedRetVals(); - for (DenseMap<Function*, LatticeVal>::const_iterator I = RV.begin(), - E = RV.end(); I != E; ++I) { - Function *F = I->first; - if (I->second.isOverdefined() || F->getReturnType()->isVoidTy()) + for (const auto &I : RV) { + Function *F = I.first; + if (I.second.isOverdefined() || F->getReturnType()->isVoidTy()) continue; // We can only do this if we know that nothing else can call the function. if (!F->hasLocalLinkage() || AddressTakenFunctions.count(F)) continue; - for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) - if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator())) + for (BasicBlock &BB : *F) + if (ReturnInst *RI = dyn_cast<ReturnInst>(BB.getTerminator())) if (!isa<UndefValue>(RI->getOperand(0))) ReturnsToZap.push_back(RI); } |