1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-21 18:22:53 +01:00

[Analysis] Use range-based for loops (NFC)

This commit is contained in:
Kazu Hirata 2021-02-06 11:17:09 -08:00
parent 616a63dfa9
commit d03fec5a45
10 changed files with 41 additions and 50 deletions

View File

@ -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);
}
}

View File

@ -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();
}

View File

@ -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);
}
}

View File

@ -62,17 +62,17 @@ public:
: 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();

View File

@ -59,19 +59,17 @@ public:
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";

View File

@ -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)

View File

@ -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;

View File

@ -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: " : " ");

View File

@ -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);
}
}
}

View File

@ -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;
}