llvm.org GIT mirror llvm / 8d0d2b6
Apply clang-tidy's modernize-loop-convert to lib/Analysis. Only minor manual fixes. No functionality change intended. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273816 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 4 years ago
19 changed file(s) with 107 addition(s) and 123 deletion(s). Raw diff Collapse all Expand all
6666
6767 /// contains - Find out if a basic block is in this interval
6868 inline bool contains(BasicBlock *BB) const {
69 for (unsigned i = 0; i < Nodes.size(); ++i)
70 if (Nodes[i] == BB) return true;
69 for (BasicBlock *Node : Nodes)
70 if (Node == BB)
71 return true;
7172 return false;
7273 // I don't want the dependency on
7374 //return find(Nodes.begin(), Nodes.end(), BB) != Nodes.end();
7576
7677 /// isSuccessor - find out if a basic block is a successor of this Interval
7778 inline bool isSuccessor(BasicBlock *BB) const {
78 for (unsigned i = 0; i < Successors.size(); ++i)
79 if (Successors[i] == BB) return true;
79 for (BasicBlock *Successor : Successors)
80 if (Successor == BB)
81 return true;
8082 return false;
8183 // I don't want the dependency on
8284 //return find(Successors.begin(), Successors.end(), BB) != Successors.end();
174174
175175 if (EvalAAMD) {
176176 // iterate over all pairs of load, store
177 for (SetVector::iterator I1 = Loads.begin(), E = Loads.end();
178 I1 != E; ++I1) {
179 for (SetVector::iterator I2 = Stores.begin(), E2 = Stores.end();
180 I2 != E2; ++I2) {
181 switch (AA.alias(MemoryLocation::get(cast(*I1)),
182 MemoryLocation::get(cast(*I2)))) {
177 for (Value *Load : Loads) {
178 for (Value *Store : Stores) {
179 switch (AA.alias(MemoryLocation::get(cast(Load)),
180 MemoryLocation::get(cast(Store)))) {
183181 case NoAlias:
184 PrintLoadStoreResults("NoAlias", PrintNoAlias, *I1, *I2,
182 PrintLoadStoreResults("NoAlias", PrintNoAlias, Load, Store,
185183 F.getParent());
186184 ++NoAliasCount;
187185 break;
188186 case MayAlias:
189 PrintLoadStoreResults("MayAlias", PrintMayAlias, *I1, *I2,
187 PrintLoadStoreResults("MayAlias", PrintMayAlias, Load, Store,
190188 F.getParent());
191189 ++MayAliasCount;
192190 break;
193191 case PartialAlias:
194 PrintLoadStoreResults("PartialAlias", PrintPartialAlias, *I1, *I2,
192 PrintLoadStoreResults("PartialAlias", PrintPartialAlias, Load, Store,
195193 F.getParent());
196194 ++PartialAliasCount;
197195 break;
198196 case MustAlias:
199 PrintLoadStoreResults("MustAlias", PrintMustAlias, *I1, *I2,
197 PrintLoadStoreResults("MustAlias", PrintMustAlias, Load, Store,
200198 F.getParent());
201199 ++MustAliasCount;
202200 break;
236234 }
237235
238236 // Mod/ref alias analysis: compare all pairs of calls and values
239 for (auto C = CallSites.begin(), Ce = CallSites.end(); C != Ce; ++C) {
240 Instruction *I = C->getInstruction();
241
242 for (SetVector::iterator V = Pointers.begin(), Ve = Pointers.end();
243 V != Ve; ++V) {
237 for (CallSite C : CallSites) {
238 Instruction *I = C.getInstruction();
239
240 for (auto Pointer : Pointers) {
244241 uint64_t Size = MemoryLocation::UnknownSize;
245 Type *ElTy = cast((*V)->getType())->getElementType();
242 Type *ElTy = cast(Pointer->getType())->getElementType();
246243 if (ElTy->isSized()) Size = DL.getTypeStoreSize(ElTy);
247244
248 switch (AA.getModRefInfo(*C, *V, Size)) {
245 switch (AA.getModRefInfo(C, Pointer, Size)) {
249246 case MRI_NoModRef:
250 PrintModRefResults("NoModRef", PrintNoModRef, I, *V, F.getParent());
247 PrintModRefResults("NoModRef", PrintNoModRef, I, Pointer,
248 F.getParent());
251249 ++NoModRefCount;
252250 break;
253251 case MRI_Mod:
254 PrintModRefResults("Just Mod", PrintMod, I, *V, F.getParent());
252 PrintModRefResults("Just Mod", PrintMod, I, Pointer, F.getParent());
255253 ++ModCount;
256254 break;
257255 case MRI_Ref:
258 PrintModRefResults("Just Ref", PrintRef, I, *V, F.getParent());
256 PrintModRefResults("Just Ref", PrintRef, I, Pointer, F.getParent());
259257 ++RefCount;
260258 break;
261259 case MRI_ModRef:
262 PrintModRefResults("Both ModRef", PrintModRef, I, *V, F.getParent());
260 PrintModRefResults("Both ModRef", PrintModRef, I, Pointer,
261 F.getParent());
263262 ++ModRefCount;
264263 break;
265264 }
233233 /// alias sets.
234234 bool AliasSetTracker::containsPointer(const Value *Ptr, uint64_t Size,
235235 const AAMDNodes &AAInfo) const {
236 for (const_iterator I = begin(), E = end(); I != E; ++I)
237 if (!I->Forward && I->aliasesPointer(Ptr, Size, AAInfo, AA))
236 for (const AliasSet &AS : *this)
237 if (!AS.Forward && AS.aliasesPointer(Ptr, Size, AAInfo, AA))
238238 return true;
239239 return false;
240240 }
241241
242242 bool AliasSetTracker::containsUnknown(const Instruction *Inst) const {
243 for (const_iterator I = begin(), E = end(); I != E; ++I)
244 if (!I->Forward && I->aliasesUnknownInst(Inst, AA))
243 for (const AliasSet &AS : *this)
244 if (!AS.Forward && AS.aliasesUnknownInst(Inst, AA))
245245 return true;
246246 return false;
247247 }
408408 // Loop over all of the alias sets in AST, adding the pointers contained
409409 // therein into the current alias sets. This can cause alias sets to be
410410 // merged together in the current AST.
411 for (const_iterator I = AST.begin(), E = AST.end(); I != E; ++I) {
412 if (I->Forward) continue; // Ignore forwarding alias sets
413
414 AliasSet &AS = const_cast(*I);
411 for (const AliasSet &AS : AST) {
412 if (AS.Forward)
413 continue; // Ignore forwarding alias sets
415414
416415 // If there are any call sites in the alias set, add them to this AST.
417416 for (unsigned i = 0, e = AS.UnknownInsts.size(); i != e; ++i)
647646 void AliasSetTracker::print(raw_ostream &OS) const {
648647 OS << "Alias Set Tracker: " << AliasSets.size() << " alias sets for "
649648 << PointerMap.size() << " pointer values.\n";
650 for (const_iterator I = begin(), E = end(); I != E; ++I)
651 I->print(OS);
649 for (const AliasSet &AS : *this)
650 AS.print(OS);
652651 OS << "\n";
653652 }
654653
7979 Node->addCalledFunction(CallSite(), CallsExternalNode.get());
8080
8181 // Look for calls by this function.
82 for (Function::iterator BB = F->begin(), BBE = F->end(); BB != BBE; ++BB)
83 for (BasicBlock::iterator II = BB->begin(), IE = BB->end(); II != IE;
84 ++II) {
85 CallSite CS(cast(II));
86 if (CS) {
82 for (BasicBlock &BB : *F)
83 for (Instruction &I : BB) {
84 if (auto CS = CallSite(&I)) {
8785 const Function *Callee = CS.getCalledFunction();
8886 if (!Callee || !Intrinsic::isLeaf(Callee->getIntrinsicID()))
8987 // Indirect calls of intrinsics are not allowed so no need to check.
110108 SmallVector Nodes;
111109 Nodes.reserve(FunctionMap.size());
112110
113 for (auto I = begin(), E = end(); I != E; ++I)
114 Nodes.push_back(I->second.get());
111 for (const auto &I : *this)
112 Nodes.push_back(I.second.get());
115113
116114 std::sort(Nodes.begin(), Nodes.end(),
117115 [](CallGraphNode *LHS, CallGraphNode *RHS) {
185183
186184 OS << "<<" << this << ">> #uses=" << getNumReferences() << '\n';
187185
188 for (const_iterator I = begin(), E = end(); I != E; ++I) {
189 OS << " CS<" << I->first << "> calls ";
190 if (Function *FI = I->second->getFunction())
186 for (const auto &I : *this) {
187 OS << " CS<" << I.first << "> calls ";
188 if (Function *FI = I.second->getFunction())
191189 OS << "function '" << FI->getName() <<"'\n";
192190 else
193191 OS << "external node\n";
260260 // Loop over all of the instructions in the function, getting the callsites.
261261 // Keep track of the number of direct/indirect calls added.
262262 unsigned NumDirectAdded = 0, NumIndirectAdded = 0;
263
264 for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
265 for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
266 CallSite CS(cast(I));
263
264 for (BasicBlock &BB : *F)
265 for (Instruction &I : BB) {
266 CallSite CS(&I);
267267 if (!CS) continue;
268268 Function *Callee = CS.getCalledFunction();
269269 if (Callee && Callee->isIntrinsic()) continue;
521521 if (!F)
522522 return;
523523
524 for (Function::iterator B = F->begin(), BE = F->end(); B != BE; ++B) {
525 for (BasicBlock::iterator it = B->begin(), e = B->end(); it != e; ++it) {
526 Instruction *Inst = &*it;
527 unsigned Cost = getInstructionCost(Inst);
524 for (BasicBlock &B : *F) {
525 for (Instruction &Inst : B) {
526 unsigned Cost = getInstructionCost(&Inst);
528527 if (Cost != (unsigned)-1)
529528 OS << "Cost Model: Found an estimated cost of " << Cost;
530529 else
531530 OS << "Cost Model: Unknown cost";
532531
533 OS << " for instruction: "<< *Inst << "\n";
532 OS << " for instruction: " << Inst << "\n";
534533 }
535534 }
536535 }
780780
781781 // Go through each pair and find the widest bit to which we need
782782 // to extend all of them.
783 for (unsigned i = 0; i < Pairs.size(); i++) {
784 const SCEV *Src = Pairs[i]->Src;
785 const SCEV *Dst = Pairs[i]->Dst;
783 for (Subscript *Pair : Pairs) {
784 const SCEV *Src = Pair->Src;
785 const SCEV *Dst = Pair->Dst;
786786 IntegerType *SrcTy = dyn_cast(Src->getType());
787787 IntegerType *DstTy = dyn_cast(Dst->getType());
788788 if (SrcTy == nullptr || DstTy == nullptr) {
805805 assert(widestWidthSeen > 0);
806806
807807 // Now extend each pair to the widest seen.
808 for (unsigned i = 0; i < Pairs.size(); i++) {
809 const SCEV *Src = Pairs[i]->Src;
810 const SCEV *Dst = Pairs[i]->Dst;
808 for (Subscript *Pair : Pairs) {
809 const SCEV *Src = Pair->Src;
810 const SCEV *Dst = Pair->Dst;
811811 IntegerType *SrcTy = dyn_cast(Src->getType());
812812 IntegerType *DstTy = dyn_cast(Dst->getType());
813813 if (SrcTy == nullptr || DstTy == nullptr) {
818818 }
819819 if (SrcTy->getBitWidth() < widestWidthSeen)
820820 // Sign-extend Src to widestType
821 Pairs[i]->Src = SE->getSignExtendExpr(Src, widestType);
821 Pair->Src = SE->getSignExtendExpr(Src, widestType);
822822 if (DstTy->getBitWidth() < widestWidthSeen) {
823823 // Sign-extend Dst to widestType
824 Pairs[i]->Dst = SE->getSignExtendExpr(Dst, widestType);
824 Pair->Dst = SE->getSignExtendExpr(Dst, widestType);
825825 }
826826 }
827827 }
289289 }
290290 OS << ":\n";
291291
292 for (ilist::const_iterator UI = IVUses.begin(),
293 E = IVUses.end(); UI != E; ++UI) {
292 for (const IVStrideUse &IVUse : IVUses) {
294293 OS << " ";
295 UI->getOperandValToReplace()->printAsOperand(OS, false);
296 OS << " = " << *getReplacementExpr(*UI);
297 for (PostIncLoopSet::const_iterator
298 I = UI->PostIncLoops.begin(),
299 E = UI->PostIncLoops.end(); I != E; ++I) {
294 IVUse.getOperandValToReplace()->printAsOperand(OS, false);
295 OS << " = " << *getReplacementExpr(IVUse);
296 for (auto PostIncLoop : IVUse.PostIncLoops) {
300297 OS << " (post-inc with loop ";
301 (*I)->getHeader()->printAsOperand(OS, false);
298 PostIncLoop->getHeader()->printAsOperand(OS, false);
302299 OS << ")";
303300 }
304301 OS << " in ";
305 if (UI->getUser())
306 UI->getUser()->print(OS);
302 if (IVUse.getUser())
303 IVUse.getUser()->print(OS);
307304 else
308305 OS << "Printing User";
309306 OS << '\n';
4141 << "Interval Contents:\n";
4242
4343 // Print out all of the basic blocks in the interval...
44 for (std::vector::const_iterator I = Nodes.begin(),
45 E = Nodes.end(); I != E; ++I)
46 OS << **I << "\n";
44 for (const BasicBlock *Node : Nodes)
45 OS << *Node << "\n";
4746
4847 OS << "Interval Predecessors:\n";
49 for (std::vector::const_iterator I = Predecessors.begin(),
50 E = Predecessors.end(); I != E; ++I)
51 OS << **I << "\n";
48 for (const BasicBlock *Predecessor : Predecessors)
49 OS << *Predecessor << "\n";
5250
5351 OS << "Interval Successors:\n";
54 for (std::vector::const_iterator I = Successors.begin(),
55 E = Successors.end(); I != E; ++I)
56 OS << **I << "\n";
52 for (const BasicBlock *Successor : Successors)
53 OS << *Successor << "\n";
5754 }
5656 //
5757 void IntervalPartition::updatePredecessors(Interval *Int) {
5858 BasicBlock *Header = Int->getHeaderNode();
59 for (Interval::succ_iterator I = Int->Successors.begin(),
60 E = Int->Successors.end(); I != E; ++I)
61 getBlockInterval(*I)->Predecessors.push_back(Header);
59 for (BasicBlock *Successor : Int->Successors)
60 getBlockInterval(Successor)->Predecessors.push_back(Header);
6261 }
6362
6463 // IntervalPartition ctor - Build the first level interval partition for the
562562 if (ODI != OverDefinedCache.end())
563563 OverDefinedCache.erase(ODI);
564564
565 for (auto I = ValueCache.begin(), E = ValueCache.end(); I != E; ++I)
566 I->second.erase(BB);
565 for (auto &I : ValueCache)
566 I.second.erase(BB);
567567 }
568568
569569 void LazyValueInfoCache::solve() {
433433 // Perform a post order CFG traversal of all blocks within this loop,
434434 // propagating the nearest loop from sucessors to predecessors.
435435 LoopBlocksTraversal Traversal(DFS, LI);
436 for (LoopBlocksTraversal::POTIterator POI = Traversal.begin(),
437 POE = Traversal.end(); POI != POE; ++POI) {
438
439 Loop *L = LI->getLoopFor(*POI);
440 Loop *NL = getNearestLoop(*POI, L);
436 for (BasicBlock *POI : Traversal) {
437
438 Loop *L = LI->getLoopFor(POI);
439 Loop *NL = getNearestLoop(POI, L);
441440
442441 if (NL != L) {
443442 // For reducible loops, NL is now an ancestor of Unloop.
444443 assert((NL != &Unloop && (!NL || NL->contains(&Unloop))) &&
445444 "uninitialized successor");
446 LI->changeLoopFor(*POI, NL);
445 LI->changeLoopFor(POI, NL);
447446 }
448447 else {
449448 // Or the current block is part of a subloop, in which case its parent
108108 /// deleteSimpleAnalysisValue - Invoke deleteAnalysisValue hook for all passes.
109109 void LPPassManager::deleteSimpleAnalysisValue(Value *V, Loop *L) {
110110 if (BasicBlock *BB = dyn_cast(V)) {
111 for (BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE;
112 ++BI) {
113 Instruction &I = *BI;
111 for (Instruction &I : *BB) {
114112 deleteSimpleAnalysisValue(&I, L);
115113 }
116114 }
110110 MDA.getNonLocalCallDependency(CS);
111111
112112 DepSet &InstDeps = Deps[Inst];
113 for (MemoryDependenceResults::NonLocalDepInfo::const_iterator
114 I = NLDI.begin(), E = NLDI.end(); I != E; ++I) {
115 const MemDepResult &Res = I->getResult();
116 InstDeps.insert(std::make_pair(getInstTypePair(Res), I->getBB()));
113 for (const NonLocalDepEntry &I : NLDI) {
114 const MemDepResult &Res = I.getResult();
115 InstDeps.insert(std::make_pair(getInstTypePair(Res), I.getBB()));
117116 }
118117 } else {
119118 SmallVector NLDI;
122121 MDA.getNonLocalPointerDependency(Inst, NLDI);
123122
124123 DepSet &InstDeps = Deps[Inst];
125 for (SmallVectorImpl::const_iterator
126 I = NLDI.begin(), E = NLDI.end(); I != E; ++I) {
127 const MemDepResult &Res = I->getResult();
128 InstDeps.insert(std::make_pair(getInstTypePair(Res), I->getBB()));
124 for (const NonLocalDepResult &I : NLDI) {
125 const MemDepResult &Res = I.getResult();
126 InstDeps.insert(std::make_pair(getInstTypePair(Res), I.getBB()));
129127 }
130128 }
131129 }
660660 // erase everything that was computed in this iteration from the cache, so
661661 // that no dangling references are left behind. We could be a bit smarter if
662662 // we kept a dependency graph. It's probably not worth the complexity.
663 for (PtrSetTy::iterator I=SeenVals.begin(), E=SeenVals.end(); I != E; ++I) {
664 CacheMapTy::iterator CacheIt = CacheMap.find(*I);
663 for (const Value *SeenVal : SeenVals) {
664 CacheMapTy::iterator CacheIt = CacheMap.find(SeenVal);
665665 // non-computable results can be safely cached
666666 if (CacheIt != CacheMap.end() && anyKnown(CacheIt->second))
667667 CacheMap.erase(CacheIt);
7575 DenseSet RefEdges;
7676
7777 SmallPtrSet Visited;
78 for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
79 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E;
80 ++I) {
78 for (const BasicBlock &BB : F)
79 for (const Instruction &I : BB) {
8180 if (!isa(I))
8281 ++NumInsts;
8382
84 if (auto CS = ImmutableCallSite(&*I)) {
83 if (auto CS = ImmutableCallSite(&I)) {
8584 auto *CalledFunction = CS.getCalledFunction();
8685 if (CalledFunction && CalledFunction->hasName() &&
8786 !CalledFunction->isIntrinsic()) {
88 auto ScaledCount = BFI ? BFI->getBlockProfileCount(&*BB) : None;
87 auto ScaledCount = BFI ? BFI->getBlockProfileCount(&BB) : None;
8988 auto *CalleeId =
9089 M->getValueSymbolTable().lookup(CalledFunction->getName());
9190 CallGraphEdges[CalleeId] +=
9291 (ScaledCount ? ScaledCount.getValue() : 0);
9392 }
9493 }
95 findRefEdges(&*I, RefEdges, Visited);
94 findRefEdges(&I, RefEdges, Visited);
9695 }
9796
9897 GlobalValueSummary::GVFlags Flags(F);
116116 << ((R.getDepth() * 2 % 12) + 2) << "\n";
117117 }
118118
119 for (Region::const_iterator RI = R.begin(), RE = R.end(); RI != RE; ++RI)
120 printRegionCluster(**RI, GW, depth + 1);
119 for (const auto &RI : R)
120 printRegionCluster(*RI, GW, depth + 1);
121121
122122 const RegionInfo &RI = *static_cast(R.getRegionInfo());
123123
54845484
54855485 // Forget all contained loops too, to avoid dangling entries in the
54865486 // ValuesAtScopes map.
5487 for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I)
5488 forgetLoop(*I);
5487 for (Loop *I : *L)
5488 forgetLoop(I);
54895489
54905490 LoopHasNoAbnormalExits.erase(L);
54915491 }
95339533 static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE,
95349534 const Loop *L) {
95359535 // Print all inner loops first
9536 for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I)
9537 PrintLoopInfo(OS, SE, *I);
9536 for (Loop *I : *L)
9537 PrintLoopInfo(OS, SE, I);
95389538
95399539 OS << "Loop ";
95409540 L->getHeader()->printAsOperand(OS, /*PrintType=*/false);
96759675 OS << "Determining loop execution counts for: ";
96769676 F.printAsOperand(OS, /*PrintType=*/false);
96779677 OS << "\n";
9678 for (LoopInfo::iterator I = LI.begin(), E = LI.end(); I != E; ++I)
9679 PrintLoopInfo(OS, &SE, *I);
9678 for (Loop *I : LI)
9679 PrintLoopInfo(OS, &SE, I);
96809680 }
96819681
96829682 ScalarEvolution::LoopDisposition
1042810428 const PredicatedScalarEvolution &Init)
1042910429 : RewriteMap(Init.RewriteMap), SE(Init.SE), L(Init.L), Preds(Init.Preds),
1043010430 Generation(Init.Generation), BackedgeCount(Init.BackedgeCount) {
10431 for (auto I = Init.FlagsMap.begin(), E = Init.FlagsMap.end(); I != E; ++I)
10432 FlagsMap.insert(*I);
10431 for (const auto &I : Init.FlagsMap)
10432 FlagsMap.insert(I);
1043310433 }
1043410434
1043510435 void PredicatedScalarEvolution::print(raw_ostream &OS, unsigned Depth) const {
319319
320320 // Notify all instructions in this basic block that they are newly
321321 // executable.
322 for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
323 visitInst(*I);
322 for (Instruction &I : *BB)
323 visitInst(I);
324324 }
325325 }
326326 }