[llvm] 28d3132 - [Analysis] Use range-based for loops (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 6 11:17:36 PST 2021
Author: Kazu Hirata
Date: 2021-02-06T11:17:10-08:00
New Revision: 28d31320894cc5c1c2ce358c5beeb9fe99abab09
URL: https://github.com/llvm/llvm-project/commit/28d31320894cc5c1c2ce358c5beeb9fe99abab09
DIFF: https://github.com/llvm/llvm-project/commit/28d31320894cc5c1c2ce358c5beeb9fe99abab09.diff
LOG: [Analysis] Use range-based for loops (NFC)
Added:
Modified:
llvm/lib/Analysis/AliasAnalysisEvaluator.cpp
llvm/lib/Analysis/AliasSetTracker.cpp
llvm/lib/Analysis/BranchProbabilityInfo.cpp
llvm/lib/Analysis/CallPrinter.cpp
llvm/lib/Analysis/Delinearization.cpp
llvm/lib/Analysis/IRSimilarityIdentifier.cpp
llvm/lib/Analysis/LazyValueInfo.cpp
llvm/lib/Analysis/LegacyDivergenceAnalysis.cpp
llvm/lib/Analysis/LoopInfo.cpp
llvm/lib/Analysis/ValueTracking.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/AliasAnalysisEvaluator.cpp b/llvm/lib/Analysis/AliasAnalysisEvaluator.cpp
index bbfa82bcca6a..94cfada5357e 100644
--- a/llvm/lib/Analysis/AliasAnalysisEvaluator.cpp
+++ b/llvm/lib/Analysis/AliasAnalysisEvaluator.cpp
@@ -105,14 +105,13 @@ void AAEvaluator::runInternal(Function &F, AAResults &AA) {
if (I.getType()->isPointerTy()) // Add all pointer arguments.
Pointers.insert(&I);
- for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
- if (I->getType()->isPointerTy()) // Add all pointer instructions.
- Pointers.insert(&*I);
- if (EvalAAMD && isa<LoadInst>(&*I))
- Loads.insert(&*I);
- if (EvalAAMD && isa<StoreInst>(&*I))
- Stores.insert(&*I);
- Instruction &Inst = *I;
+ for (Instruction &Inst : instructions(F)) {
+ if (Inst.getType()->isPointerTy()) // Add all pointer instructions.
+ Pointers.insert(&Inst);
+ if (EvalAAMD && isa<LoadInst>(&Inst))
+ Loads.insert(&Inst);
+ if (EvalAAMD && isa<StoreInst>(&Inst))
+ Stores.insert(&Inst);
if (auto *Call = dyn_cast<CallBase>(&Inst)) {
Value *Callee = Call->getCalledOperand();
// Skip actual functions for direct function calls.
@@ -125,10 +124,9 @@ void AAEvaluator::runInternal(Function &F, AAResults &AA) {
Calls.insert(Call);
} else {
// Consider all operands.
- for (Instruction::op_iterator OI = Inst.op_begin(), OE = Inst.op_end();
- OI != OE; ++OI)
- if (isInterestingPointer(*OI))
- Pointers.insert(*OI);
+ for (Use &Op : Inst.operands())
+ if (isInterestingPointer(Op))
+ Pointers.insert(Op);
}
}
diff --git a/llvm/lib/Analysis/AliasSetTracker.cpp b/llvm/lib/Analysis/AliasSetTracker.cpp
index 486b4d99dfae..c71b86385be9 100644
--- a/llvm/lib/Analysis/AliasSetTracker.cpp
+++ b/llvm/lib/Analysis/AliasSetTracker.cpp
@@ -608,8 +608,8 @@ AliasSet &AliasSetTracker::mergeAllAliasSets() {
// without worrying about iterator invalidation.
std::vector<AliasSet *> ASVector;
ASVector.reserve(SaturationThreshold);
- for (iterator I = begin(), E = end(); I != E; I++)
- ASVector.push_back(&*I);
+ for (AliasSet &AS : *this)
+ ASVector.push_back(&AS);
// Copy all instructions and pointers into a new set, and forward all other
// sets to it.
@@ -755,8 +755,8 @@ namespace {
auto &AAWP = getAnalysis<AAResultsWrapperPass>();
AliasSetTracker Tracker(AAWP.getAAResults());
errs() << "Alias sets for function '" << F.getName() << "':\n";
- for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
- Tracker.add(&*I);
+ for (Instruction &I : instructions(F))
+ Tracker.add(&I);
Tracker.print(errs());
return false;
}
@@ -779,8 +779,8 @@ PreservedAnalyses AliasSetsPrinterPass::run(Function &F,
auto &AA = AM.getResult<AAManager>(F);
AliasSetTracker Tracker(AA);
OS << "Alias sets for function '" << F.getName() << "':\n";
- for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
- Tracker.add(&*I);
+ for (Instruction &I : instructions(F))
+ Tracker.add(&I);
Tracker.print(OS);
return PreservedAnalyses::all();
}
diff --git a/llvm/lib/Analysis/BranchProbabilityInfo.cpp b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
index 4cb17b81b467..2bbf4219d761 100644
--- a/llvm/lib/Analysis/BranchProbabilityInfo.cpp
+++ b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
@@ -840,8 +840,7 @@ bool BranchProbabilityInfo::calcEstimatedHeuristics(const BasicBlock *BB) {
SmallVector<uint32_t, 4> SuccWeights;
uint64_t TotalWeight = 0;
// Go over all successors of BB and put their weights into SuccWeights.
- for (const_succ_iterator I = succ_begin(BB), E = succ_end(BB); I != E; ++I) {
- const BasicBlock *SuccBB = *I;
+ for (const BasicBlock *SuccBB : successors(BB)) {
Optional<uint32_t> Weight;
const LoopBlock SuccLoopBB = getLoopBlock(SuccBB);
const LoopEdge Edge{LoopBB, SuccLoopBB};
@@ -1094,10 +1093,8 @@ void BranchProbabilityInfo::print(raw_ostream &OS) const {
// or the function it is currently running over.
assert(LastF && "Cannot print prior to running over a function");
for (const auto &BI : *LastF) {
- for (const_succ_iterator SI = succ_begin(&BI), SE = succ_end(&BI); SI != SE;
- ++SI) {
- printEdgeProbability(OS << " ", &BI, *SI);
- }
+ for (const BasicBlock *Succ : successors(&BI))
+ printEdgeProbability(OS << " ", &BI, Succ);
}
}
diff --git a/llvm/lib/Analysis/CallPrinter.cpp b/llvm/lib/Analysis/CallPrinter.cpp
index 872a91ad7cbf..bbbcbf8dd1cc 100644
--- a/llvm/lib/Analysis/CallPrinter.cpp
+++ b/llvm/lib/Analysis/CallPrinter.cpp
@@ -62,17 +62,17 @@ class CallGraphDOTInfo {
: M(M), CG(CG), LookupBFI(LookupBFI) {
MaxFreq = 0;
- for (auto F = M->getFunctionList().begin(); F != M->getFunctionList().end(); ++F) {
+ for (Function &F : M->getFunctionList()) {
uint64_t localSumFreq = 0;
SmallSet<Function *, 16> Callers;
- for (User *U : (*F).users())
+ for (User *U : F.users())
if (isa<CallInst>(U))
Callers.insert(cast<Instruction>(U)->getFunction());
- for (auto iter = Callers.begin() ; iter != Callers.end() ; ++iter)
- localSumFreq += getNumOfCalls((**iter), *F);
+ for (Function *Caller : Callers)
+ localSumFreq += getNumOfCalls(*Caller, F);
if (localSumFreq >= MaxFreq)
MaxFreq = localSumFreq;
- Freq[&*F] = localSumFreq;
+ Freq[&F] = localSumFreq;
}
if (!CallMultiGraph)
removeParallelEdges();
diff --git a/llvm/lib/Analysis/Delinearization.cpp b/llvm/lib/Analysis/Delinearization.cpp
index 87a41bbf16a5..448e970e9bcc 100644
--- a/llvm/lib/Analysis/Delinearization.cpp
+++ b/llvm/lib/Analysis/Delinearization.cpp
@@ -59,19 +59,17 @@ class Delinearization : public FunctionPass {
void printDelinearization(raw_ostream &O, Function *F, LoopInfo *LI,
ScalarEvolution *SE) {
O << "Delinearization on function " << F->getName() << ":\n";
- for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
- Instruction *Inst = &(*I);
-
+ for (Instruction &Inst : instructions(F)) {
// Only analyze loads and stores.
- if (!isa<StoreInst>(Inst) && !isa<LoadInst>(Inst) &&
- !isa<GetElementPtrInst>(Inst))
+ if (!isa<StoreInst>(&Inst) && !isa<LoadInst>(&Inst) &&
+ !isa<GetElementPtrInst>(&Inst))
continue;
- const BasicBlock *BB = Inst->getParent();
+ const BasicBlock *BB = Inst.getParent();
// Delinearize the memory access as analyzed in all the surrounding loops.
// Do not analyze memory accesses outside loops.
for (Loop *L = LI->getLoopFor(BB); L != nullptr; L = L->getParentLoop()) {
- const SCEV *AccessFn = SE->getSCEVAtScope(getPointerOperand(Inst), L);
+ const SCEV *AccessFn = SE->getSCEVAtScope(getPointerOperand(&Inst), L);
const SCEVUnknown *BasePointer =
dyn_cast<SCEVUnknown>(SE->getPointerBase(AccessFn));
@@ -81,12 +79,12 @@ void printDelinearization(raw_ostream &O, Function *F, LoopInfo *LI,
AccessFn = SE->getMinusSCEV(AccessFn, BasePointer);
O << "\n";
- O << "Inst:" << *Inst << "\n";
+ O << "Inst:" << Inst << "\n";
O << "In Loop with Header: " << L->getHeader()->getName() << "\n";
O << "AccessFunction: " << *AccessFn << "\n";
SmallVector<const SCEV *, 3> Subscripts, Sizes;
- SE->delinearize(AccessFn, Subscripts, Sizes, SE->getElementSize(Inst));
+ SE->delinearize(AccessFn, Subscripts, Sizes, SE->getElementSize(&Inst));
if (Subscripts.size() == 0 || Sizes.size() == 0 ||
Subscripts.size() != Sizes.size()) {
O << "failed to delinearize\n";
diff --git a/llvm/lib/Analysis/IRSimilarityIdentifier.cpp b/llvm/lib/Analysis/IRSimilarityIdentifier.cpp
index 25443a667908..d6ade21fcbb7 100644
--- a/llvm/lib/Analysis/IRSimilarityIdentifier.cpp
+++ b/llvm/lib/Analysis/IRSimilarityIdentifier.cpp
@@ -835,8 +835,8 @@ void IRSimilarityIdentifier::findCandidates(
// Iterate over the subsequences found by the Suffix Tree to create
// IRSimilarityCandidates for each repeated subsequence and determine which
// instances are structurally similar to one another.
- for (auto It = ST.begin(), Et = ST.end(); It != Et; ++It) {
- createCandidatesFromSuffixTree(Mapper, InstrList, IntegerMapping, *It,
+ for (SuffixTree::RepeatedSubstring &RS : ST) {
+ createCandidatesFromSuffixTree(Mapper, InstrList, IntegerMapping, RS,
CandsForRepSubstring);
if (CandsForRepSubstring.size() < 2)
diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp
index ba2b6fe94c18..7e1c13518c45 100644
--- a/llvm/lib/Analysis/LazyValueInfo.cpp
+++ b/llvm/lib/Analysis/LazyValueInfo.cpp
@@ -687,8 +687,8 @@ Optional<ValueLatticeElement> LazyValueInfoImpl::solveBlockValueNonLocal(
// find a path to function entry. TODO: We should consider explicitly
// canonicalizing to make this true rather than relying on this happy
// accident.
- for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
- Optional<ValueLatticeElement> EdgeResult = getEdgeValue(Val, *PI, BB);
+ for (BasicBlock *Pred : predecessors(BB)) {
+ Optional<ValueLatticeElement> EdgeResult = getEdgeValue(Val, Pred, BB);
if (!EdgeResult)
// Explore that input, then return here
return None;
diff --git a/llvm/lib/Analysis/LegacyDivergenceAnalysis.cpp b/llvm/lib/Analysis/LegacyDivergenceAnalysis.cpp
index 30eec5a611f7..be8a18a21f23 100644
--- a/llvm/lib/Analysis/LegacyDivergenceAnalysis.cpp
+++ b/llvm/lib/Analysis/LegacyDivergenceAnalysis.cpp
@@ -396,8 +396,7 @@ void LegacyDivergenceAnalysis::print(raw_ostream &OS, const Module *) const {
OS << Arg << "\n";
}
// Iterate instructions using instructions() to ensure a deterministic order.
- for (auto BI = F->begin(), BE = F->end(); BI != BE; ++BI) {
- auto &BB = *BI;
+ for (const BasicBlock &BB : *F) {
OS << "\n " << BB.getName() << ":\n";
for (auto &I : BB.instructionsWithoutDebug()) {
OS << (isDivergent(&I) ? "DIVERGENT: " : " ");
diff --git a/llvm/lib/Analysis/LoopInfo.cpp b/llvm/lib/Analysis/LoopInfo.cpp
index a85869b16333..da894ef45bb2 100644
--- a/llvm/lib/Analysis/LoopInfo.cpp
+++ b/llvm/lib/Analysis/LoopInfo.cpp
@@ -765,9 +765,8 @@ void UnloopUpdater::updateBlockParents() {
void UnloopUpdater::removeBlocksFromAncestors() {
// Remove all unloop's blocks (including those in nested subloops) from
// ancestors below the new parent loop.
- for (Loop::block_iterator BI = Unloop.block_begin(), BE = Unloop.block_end();
- BI != BE; ++BI) {
- Loop *OuterParent = LI->getLoopFor(*BI);
+ for (BasicBlock *BB : Unloop.blocks()) {
+ Loop *OuterParent = LI->getLoopFor(BB);
if (Unloop.contains(OuterParent)) {
while (OuterParent->getParentLoop() != &Unloop)
OuterParent = OuterParent->getParentLoop();
@@ -778,7 +777,7 @@ void UnloopUpdater::removeBlocksFromAncestors() {
for (Loop *OldParent = Unloop.getParentLoop(); OldParent != OuterParent;
OldParent = OldParent->getParentLoop()) {
assert(OldParent && "new loop is not an ancestor of the original");
- OldParent->removeBlockFromLoop(*BI);
+ OldParent->removeBlockFromLoop(BB);
}
}
}
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 5600a3b33750..6bb629285edc 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -5053,8 +5053,8 @@ bool llvm::isGuaranteedToTransferExecutionToSuccessor(const Instruction *I) {
bool llvm::isGuaranteedToTransferExecutionToSuccessor(const BasicBlock *BB) {
// TODO: This is slightly conservative for invoke instruction since exiting
// via an exception *is* normal control for them.
- for (auto I = BB->begin(), E = BB->end(); I != E; ++I)
- if (!isGuaranteedToTransferExecutionToSuccessor(&*I))
+ for (const Instruction &I : *BB)
+ if (!isGuaranteedToTransferExecutionToSuccessor(&I))
return false;
return true;
}
More information about the llvm-commits
mailing list