Skip to content

Commit 28d3132

Browse files
[Analysis] Use range-based for loops (NFC)
1 parent 3289759 commit 28d3132

10 files changed

+41
-50
lines changed

llvm/lib/Analysis/AliasAnalysisEvaluator.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,13 @@ void AAEvaluator::runInternal(Function &F, AAResults &AA) {
105105
if (I.getType()->isPointerTy()) // Add all pointer arguments.
106106
Pointers.insert(&I);
107107

108-
for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
109-
if (I->getType()->isPointerTy()) // Add all pointer instructions.
110-
Pointers.insert(&*I);
111-
if (EvalAAMD && isa<LoadInst>(&*I))
112-
Loads.insert(&*I);
113-
if (EvalAAMD && isa<StoreInst>(&*I))
114-
Stores.insert(&*I);
115-
Instruction &Inst = *I;
108+
for (Instruction &Inst : instructions(F)) {
109+
if (Inst.getType()->isPointerTy()) // Add all pointer instructions.
110+
Pointers.insert(&Inst);
111+
if (EvalAAMD && isa<LoadInst>(&Inst))
112+
Loads.insert(&Inst);
113+
if (EvalAAMD && isa<StoreInst>(&Inst))
114+
Stores.insert(&Inst);
116115
if (auto *Call = dyn_cast<CallBase>(&Inst)) {
117116
Value *Callee = Call->getCalledOperand();
118117
// Skip actual functions for direct function calls.
@@ -125,10 +124,9 @@ void AAEvaluator::runInternal(Function &F, AAResults &AA) {
125124
Calls.insert(Call);
126125
} else {
127126
// Consider all operands.
128-
for (Instruction::op_iterator OI = Inst.op_begin(), OE = Inst.op_end();
129-
OI != OE; ++OI)
130-
if (isInterestingPointer(*OI))
131-
Pointers.insert(*OI);
127+
for (Use &Op : Inst.operands())
128+
if (isInterestingPointer(Op))
129+
Pointers.insert(Op);
132130
}
133131
}
134132

llvm/lib/Analysis/AliasSetTracker.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,8 @@ AliasSet &AliasSetTracker::mergeAllAliasSets() {
608608
// without worrying about iterator invalidation.
609609
std::vector<AliasSet *> ASVector;
610610
ASVector.reserve(SaturationThreshold);
611-
for (iterator I = begin(), E = end(); I != E; I++)
612-
ASVector.push_back(&*I);
611+
for (AliasSet &AS : *this)
612+
ASVector.push_back(&AS);
613613

614614
// Copy all instructions and pointers into a new set, and forward all other
615615
// sets to it.
@@ -755,8 +755,8 @@ namespace {
755755
auto &AAWP = getAnalysis<AAResultsWrapperPass>();
756756
AliasSetTracker Tracker(AAWP.getAAResults());
757757
errs() << "Alias sets for function '" << F.getName() << "':\n";
758-
for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
759-
Tracker.add(&*I);
758+
for (Instruction &I : instructions(F))
759+
Tracker.add(&I);
760760
Tracker.print(errs());
761761
return false;
762762
}
@@ -779,8 +779,8 @@ PreservedAnalyses AliasSetsPrinterPass::run(Function &F,
779779
auto &AA = AM.getResult<AAManager>(F);
780780
AliasSetTracker Tracker(AA);
781781
OS << "Alias sets for function '" << F.getName() << "':\n";
782-
for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
783-
Tracker.add(&*I);
782+
for (Instruction &I : instructions(F))
783+
Tracker.add(&I);
784784
Tracker.print(OS);
785785
return PreservedAnalyses::all();
786786
}

llvm/lib/Analysis/BranchProbabilityInfo.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -840,8 +840,7 @@ bool BranchProbabilityInfo::calcEstimatedHeuristics(const BasicBlock *BB) {
840840
SmallVector<uint32_t, 4> SuccWeights;
841841
uint64_t TotalWeight = 0;
842842
// Go over all successors of BB and put their weights into SuccWeights.
843-
for (const_succ_iterator I = succ_begin(BB), E = succ_end(BB); I != E; ++I) {
844-
const BasicBlock *SuccBB = *I;
843+
for (const BasicBlock *SuccBB : successors(BB)) {
845844
Optional<uint32_t> Weight;
846845
const LoopBlock SuccLoopBB = getLoopBlock(SuccBB);
847846
const LoopEdge Edge{LoopBB, SuccLoopBB};
@@ -1094,10 +1093,8 @@ void BranchProbabilityInfo::print(raw_ostream &OS) const {
10941093
// or the function it is currently running over.
10951094
assert(LastF && "Cannot print prior to running over a function");
10961095
for (const auto &BI : *LastF) {
1097-
for (const_succ_iterator SI = succ_begin(&BI), SE = succ_end(&BI); SI != SE;
1098-
++SI) {
1099-
printEdgeProbability(OS << " ", &BI, *SI);
1100-
}
1096+
for (const BasicBlock *Succ : successors(&BI))
1097+
printEdgeProbability(OS << " ", &BI, Succ);
11011098
}
11021099
}
11031100

llvm/lib/Analysis/CallPrinter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@ class CallGraphDOTInfo {
6262
: M(M), CG(CG), LookupBFI(LookupBFI) {
6363
MaxFreq = 0;
6464

65-
for (auto F = M->getFunctionList().begin(); F != M->getFunctionList().end(); ++F) {
65+
for (Function &F : M->getFunctionList()) {
6666
uint64_t localSumFreq = 0;
6767
SmallSet<Function *, 16> Callers;
68-
for (User *U : (*F).users())
68+
for (User *U : F.users())
6969
if (isa<CallInst>(U))
7070
Callers.insert(cast<Instruction>(U)->getFunction());
71-
for (auto iter = Callers.begin() ; iter != Callers.end() ; ++iter)
72-
localSumFreq += getNumOfCalls((**iter), *F);
71+
for (Function *Caller : Callers)
72+
localSumFreq += getNumOfCalls(*Caller, F);
7373
if (localSumFreq >= MaxFreq)
7474
MaxFreq = localSumFreq;
75-
Freq[&*F] = localSumFreq;
75+
Freq[&F] = localSumFreq;
7676
}
7777
if (!CallMultiGraph)
7878
removeParallelEdges();

llvm/lib/Analysis/Delinearization.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,17 @@ class Delinearization : public FunctionPass {
5959
void printDelinearization(raw_ostream &O, Function *F, LoopInfo *LI,
6060
ScalarEvolution *SE) {
6161
O << "Delinearization on function " << F->getName() << ":\n";
62-
for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
63-
Instruction *Inst = &(*I);
64-
62+
for (Instruction &Inst : instructions(F)) {
6563
// Only analyze loads and stores.
66-
if (!isa<StoreInst>(Inst) && !isa<LoadInst>(Inst) &&
67-
!isa<GetElementPtrInst>(Inst))
64+
if (!isa<StoreInst>(&Inst) && !isa<LoadInst>(&Inst) &&
65+
!isa<GetElementPtrInst>(&Inst))
6866
continue;
6967

70-
const BasicBlock *BB = Inst->getParent();
68+
const BasicBlock *BB = Inst.getParent();
7169
// Delinearize the memory access as analyzed in all the surrounding loops.
7270
// Do not analyze memory accesses outside loops.
7371
for (Loop *L = LI->getLoopFor(BB); L != nullptr; L = L->getParentLoop()) {
74-
const SCEV *AccessFn = SE->getSCEVAtScope(getPointerOperand(Inst), L);
72+
const SCEV *AccessFn = SE->getSCEVAtScope(getPointerOperand(&Inst), L);
7573

7674
const SCEVUnknown *BasePointer =
7775
dyn_cast<SCEVUnknown>(SE->getPointerBase(AccessFn));
@@ -81,12 +79,12 @@ void printDelinearization(raw_ostream &O, Function *F, LoopInfo *LI,
8179
AccessFn = SE->getMinusSCEV(AccessFn, BasePointer);
8280

8381
O << "\n";
84-
O << "Inst:" << *Inst << "\n";
82+
O << "Inst:" << Inst << "\n";
8583
O << "In Loop with Header: " << L->getHeader()->getName() << "\n";
8684
O << "AccessFunction: " << *AccessFn << "\n";
8785

8886
SmallVector<const SCEV *, 3> Subscripts, Sizes;
89-
SE->delinearize(AccessFn, Subscripts, Sizes, SE->getElementSize(Inst));
87+
SE->delinearize(AccessFn, Subscripts, Sizes, SE->getElementSize(&Inst));
9088
if (Subscripts.size() == 0 || Sizes.size() == 0 ||
9189
Subscripts.size() != Sizes.size()) {
9290
O << "failed to delinearize\n";

llvm/lib/Analysis/IRSimilarityIdentifier.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,8 +835,8 @@ void IRSimilarityIdentifier::findCandidates(
835835
// Iterate over the subsequences found by the Suffix Tree to create
836836
// IRSimilarityCandidates for each repeated subsequence and determine which
837837
// instances are structurally similar to one another.
838-
for (auto It = ST.begin(), Et = ST.end(); It != Et; ++It) {
839-
createCandidatesFromSuffixTree(Mapper, InstrList, IntegerMapping, *It,
838+
for (SuffixTree::RepeatedSubstring &RS : ST) {
839+
createCandidatesFromSuffixTree(Mapper, InstrList, IntegerMapping, RS,
840840
CandsForRepSubstring);
841841

842842
if (CandsForRepSubstring.size() < 2)

llvm/lib/Analysis/LazyValueInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,8 @@ Optional<ValueLatticeElement> LazyValueInfoImpl::solveBlockValueNonLocal(
687687
// find a path to function entry. TODO: We should consider explicitly
688688
// canonicalizing to make this true rather than relying on this happy
689689
// accident.
690-
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
691-
Optional<ValueLatticeElement> EdgeResult = getEdgeValue(Val, *PI, BB);
690+
for (BasicBlock *Pred : predecessors(BB)) {
691+
Optional<ValueLatticeElement> EdgeResult = getEdgeValue(Val, Pred, BB);
692692
if (!EdgeResult)
693693
// Explore that input, then return here
694694
return None;

llvm/lib/Analysis/LegacyDivergenceAnalysis.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,7 @@ void LegacyDivergenceAnalysis::print(raw_ostream &OS, const Module *) const {
396396
OS << Arg << "\n";
397397
}
398398
// Iterate instructions using instructions() to ensure a deterministic order.
399-
for (auto BI = F->begin(), BE = F->end(); BI != BE; ++BI) {
400-
auto &BB = *BI;
399+
for (const BasicBlock &BB : *F) {
401400
OS << "\n " << BB.getName() << ":\n";
402401
for (auto &I : BB.instructionsWithoutDebug()) {
403402
OS << (isDivergent(&I) ? "DIVERGENT: " : " ");

llvm/lib/Analysis/LoopInfo.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -765,9 +765,8 @@ void UnloopUpdater::updateBlockParents() {
765765
void UnloopUpdater::removeBlocksFromAncestors() {
766766
// Remove all unloop's blocks (including those in nested subloops) from
767767
// ancestors below the new parent loop.
768-
for (Loop::block_iterator BI = Unloop.block_begin(), BE = Unloop.block_end();
769-
BI != BE; ++BI) {
770-
Loop *OuterParent = LI->getLoopFor(*BI);
768+
for (BasicBlock *BB : Unloop.blocks()) {
769+
Loop *OuterParent = LI->getLoopFor(BB);
771770
if (Unloop.contains(OuterParent)) {
772771
while (OuterParent->getParentLoop() != &Unloop)
773772
OuterParent = OuterParent->getParentLoop();
@@ -778,7 +777,7 @@ void UnloopUpdater::removeBlocksFromAncestors() {
778777
for (Loop *OldParent = Unloop.getParentLoop(); OldParent != OuterParent;
779778
OldParent = OldParent->getParentLoop()) {
780779
assert(OldParent && "new loop is not an ancestor of the original");
781-
OldParent->removeBlockFromLoop(*BI);
780+
OldParent->removeBlockFromLoop(BB);
782781
}
783782
}
784783
}

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5053,8 +5053,8 @@ bool llvm::isGuaranteedToTransferExecutionToSuccessor(const Instruction *I) {
50535053
bool llvm::isGuaranteedToTransferExecutionToSuccessor(const BasicBlock *BB) {
50545054
// TODO: This is slightly conservative for invoke instruction since exiting
50555055
// via an exception *is* normal control for them.
5056-
for (auto I = BB->begin(), E = BB->end(); I != E; ++I)
5057-
if (!isGuaranteedToTransferExecutionToSuccessor(&*I))
5056+
for (const Instruction &I : *BB)
5057+
if (!isGuaranteedToTransferExecutionToSuccessor(&I))
50585058
return false;
50595059
return true;
50605060
}

0 commit comments

Comments
 (0)