Skip to content

Commit 8414321

Browse files
[Hexagon] Use range-based for loops (NFC)
1 parent 7e14e88 commit 8414321

File tree

1 file changed

+53
-74
lines changed

1 file changed

+53
-74
lines changed

llvm/lib/Target/Hexagon/HexagonCommonGEP.cpp

Lines changed: 53 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,11 @@ namespace {
290290
raw_ostream &operator<< (raw_ostream &OS,
291291
const NodeToUsesMap &M) LLVM_ATTRIBUTE_UNUSED;
292292
raw_ostream &operator<< (raw_ostream &OS, const NodeToUsesMap &M){
293-
using const_iterator = NodeToUsesMap::const_iterator;
294-
295-
for (const_iterator I = M.begin(), E = M.end(); I != E; ++I) {
296-
const UseSet &Us = I->second;
297-
OS << I->first << " -> #" << Us.size() << '{';
298-
for (UseSet::const_iterator J = Us.begin(), F = Us.end(); J != F; ++J) {
299-
User *R = (*J)->getUser();
293+
for (const auto &I : M) {
294+
const UseSet &Us = I.second;
295+
OS << I.first << " -> #" << Us.size() << '{';
296+
for (const Use *U : Us) {
297+
User *R = U->getUser();
300298
if (R->hasName())
301299
OS << ' ' << R->getName();
302300
else
@@ -420,33 +418,27 @@ void HexagonCommonGEP::collect() {
420418
// instruction that uses another GEP instruction as the base pointer, the
421419
// gep node for the base pointer should already exist.
422420
ValueToNodeMap NM;
423-
for (ValueVect::iterator I = BO.begin(), E = BO.end(); I != E; ++I) {
424-
BasicBlock *B = cast<BasicBlock>(*I);
425-
for (BasicBlock::iterator J = B->begin(), F = B->end(); J != F; ++J) {
426-
if (!isa<GetElementPtrInst>(J))
427-
continue;
428-
GetElementPtrInst *GepI = cast<GetElementPtrInst>(J);
429-
if (isHandledGepForm(GepI))
430-
processGepInst(GepI, NM);
431-
}
421+
for (Value *I : BO) {
422+
BasicBlock *B = cast<BasicBlock>(I);
423+
for (Instruction &J : *B)
424+
if (auto *GepI = dyn_cast<GetElementPtrInst>(&J))
425+
if (isHandledGepForm(GepI))
426+
processGepInst(GepI, NM);
432427
}
433428

434429
LLVM_DEBUG(dbgs() << "Gep nodes after initial collection:\n" << Nodes);
435430
}
436431

437432
static void invert_find_roots(const NodeVect &Nodes, NodeChildrenMap &NCM,
438433
NodeVect &Roots) {
439-
using const_iterator = NodeVect::const_iterator;
440-
441-
for (const_iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) {
442-
GepNode *N = *I;
443-
if (N->Flags & GepNode::Root) {
444-
Roots.push_back(N);
445-
continue;
446-
}
447-
GepNode *PN = N->Parent;
448-
NCM[PN].push_back(N);
434+
for (GepNode *N : Nodes) {
435+
if (N->Flags & GepNode::Root) {
436+
Roots.push_back(N);
437+
continue;
449438
}
439+
GepNode *PN = N->Parent;
440+
NCM[PN].push_back(N);
441+
}
450442
}
451443

452444
static void nodes_for_root(GepNode *Root, NodeChildrenMap &NCM,
@@ -546,8 +538,7 @@ void HexagonCommonGEP::common() {
546538
using NodeSetMap = std::map<unsigned, NodeSet>;
547539
NodeSetMap MaybeEq;
548540

549-
for (NodeVect::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) {
550-
GepNode *N = *I;
541+
for (GepNode *N : Nodes) {
551542
unsigned H = node_hash(N);
552543
MaybeEq[H].insert(N);
553544
}
@@ -556,9 +547,8 @@ void HexagonCommonGEP::common() {
556547
// one for equality and the other for non-equality.
557548
NodeSymRel EqRel; // Equality relation (as set of equivalence classes).
558549
NodePairSet Eq, Ne; // Caches.
559-
for (NodeSetMap::iterator I = MaybeEq.begin(), E = MaybeEq.end();
560-
I != E; ++I) {
561-
NodeSet &S = I->second;
550+
for (auto &I : MaybeEq) {
551+
NodeSet &S = I.second;
562552
for (NodeSet::iterator NI = S.begin(), NE = S.end(); NI != NE; ++NI) {
563553
GepNode *N = *NI;
564554
// If node already has a class, then the class must have been created
@@ -612,8 +602,7 @@ void HexagonCommonGEP::common() {
612602
// Update the min element's flags, and user list.
613603
uint32_t Flags = 0;
614604
UseSet &MinUs = Uses[Min];
615-
for (NodeSet::iterator J = S.begin(), F = S.end(); J != F; ++J) {
616-
GepNode *N = *J;
605+
for (GepNode *N : S) {
617606
uint32_t NF = N->Flags;
618607
// If N is used, append all original values of N to the list of
619608
// original values of Min.
@@ -633,8 +622,7 @@ void HexagonCommonGEP::common() {
633622
// selected (minimum) node from the corresponding equivalence class.
634623
// If a given parent does not have an equivalence class, leave it
635624
// unchanged (it means that it's the only element in its class).
636-
for (NodeVect::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) {
637-
GepNode *N = *I;
625+
for (GepNode *N : Nodes) {
638626
if (N->Flags & GepNode::Root)
639627
continue;
640628
const NodeSet *PC = node_class(N->Parent, EqRel);
@@ -652,8 +640,7 @@ void HexagonCommonGEP::common() {
652640

653641
// Finally, erase the nodes that are no longer used.
654642
NodeSet Erase;
655-
for (NodeVect::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) {
656-
GepNode *N = *I;
643+
for (GepNode *N : Nodes) {
657644
const NodeSet *PC = node_class(N, EqRel);
658645
if (!PC)
659646
continue;
@@ -663,7 +650,7 @@ void HexagonCommonGEP::common() {
663650
if (N == F->second)
664651
continue;
665652
// Node for removal.
666-
Erase.insert(*I);
653+
Erase.insert(N);
667654
}
668655
erase_if(Nodes, in_set(Erase));
669656

@@ -775,8 +762,7 @@ BasicBlock *HexagonCommonGEP::recalculatePlacement(GepNode *Node,
775762
NodeToUsesMap::iterator UF = Uses.find(Node);
776763
assert(UF != Uses.end() && "Used node with no use information");
777764
UseSet &Us = UF->second;
778-
for (UseSet::iterator I = Us.begin(), E = Us.end(); I != E; ++I) {
779-
Use *U = *I;
765+
for (Use *U : Us) {
780766
User *R = U->getUser();
781767
if (!isa<Instruction>(R))
782768
continue;
@@ -790,8 +776,7 @@ BasicBlock *HexagonCommonGEP::recalculatePlacement(GepNode *Node,
790776
NodeChildrenMap::iterator CF = NCM.find(Node);
791777
if (CF != NCM.end()) {
792778
NodeVect &Cs = CF->second;
793-
for (NodeVect::iterator I = Cs.begin(), E = Cs.end(); I != E; ++I) {
794-
GepNode *CN = *I;
779+
for (GepNode *CN : Cs) {
795780
NodeToValueMap::iterator LF = Loc.find(CN);
796781
// If the child is only used in GEP instructions (i.e. is not used in
797782
// non-GEP instructions), the nearest dominator computed for it may
@@ -831,8 +816,8 @@ BasicBlock *HexagonCommonGEP::recalculatePlacementRec(GepNode *Node,
831816
NodeChildrenMap::iterator CF = NCM.find(Node);
832817
if (CF != NCM.end()) {
833818
NodeVect &Cs = CF->second;
834-
for (NodeVect::iterator I = Cs.begin(), E = Cs.end(); I != E; ++I)
835-
recalculatePlacementRec(*I, NCM, Loc);
819+
for (GepNode *C : Cs)
820+
recalculatePlacementRec(C, NCM, Loc);
836821
}
837822
BasicBlock *LB = recalculatePlacement(Node, NCM, Loc);
838823
LLVM_DEBUG(dbgs() << "LocRec end for node:" << Node << '\n');
@@ -921,8 +906,8 @@ BasicBlock *HexagonCommonGEP::adjustForInvariance(GepNode *Node,
921906
NodeChildrenMap::iterator CF = NCM.find(Node);
922907
if (CF != NCM.end()) {
923908
NodeVect &Cs = CF->second;
924-
for (NodeVect::iterator I = Cs.begin(), E = Cs.end(); I != E; ++I)
925-
adjustForInvariance(*I, NCM, Loc);
909+
for (GepNode *C : Cs)
910+
adjustForInvariance(C, NCM, Loc);
926911
}
927912
return LocB;
928913
}
@@ -938,10 +923,9 @@ namespace {
938923
raw_ostream &operator<< (raw_ostream &OS,
939924
const LocationAsBlock &Loc) LLVM_ATTRIBUTE_UNUSED ;
940925
raw_ostream &operator<< (raw_ostream &OS, const LocationAsBlock &Loc) {
941-
for (NodeToValueMap::const_iterator I = Loc.Map.begin(), E = Loc.Map.end();
942-
I != E; ++I) {
943-
OS << I->first << " -> ";
944-
if (BasicBlock *B = cast_or_null<BasicBlock>(I->second))
926+
for (const auto &I : Loc.Map) {
927+
OS << I.first << " -> ";
928+
if (BasicBlock *B = cast_or_null<BasicBlock>(I.second))
945929
OS << B->getName() << '(' << B << ')';
946930
else
947931
OS << "<null-block>";
@@ -1016,17 +1000,15 @@ void HexagonCommonGEP::separateConstantChains(GepNode *Node,
10161000
// Collect all used nodes together with the uses from loads and stores,
10171001
// where the GEP node could be folded into the load/store instruction.
10181002
NodeToUsesMap FNs; // Foldable nodes.
1019-
for (NodeSet::iterator I = Ns.begin(), E = Ns.end(); I != E; ++I) {
1020-
GepNode *N = *I;
1003+
for (GepNode *N : Ns) {
10211004
if (!(N->Flags & GepNode::Used))
10221005
continue;
10231006
NodeToUsesMap::iterator UF = Uses.find(N);
10241007
assert(UF != Uses.end());
10251008
UseSet &Us = UF->second;
10261009
// Loads/stores that use the node N.
10271010
UseSet LSs;
1028-
for (UseSet::iterator J = Us.begin(), F = Us.end(); J != F; ++J) {
1029-
Use *U = *J;
1011+
for (Use *U : Us) {
10301012
User *R = U->getUser();
10311013
// We're interested in uses that provide the address. It can happen
10321014
// that the value may also be provided via GEP, but we won't handle
@@ -1051,11 +1033,11 @@ void HexagonCommonGEP::separateConstantChains(GepNode *Node,
10511033

10521034
LLVM_DEBUG(dbgs() << "Nodes with foldable users:\n" << FNs);
10531035

1054-
for (NodeToUsesMap::iterator I = FNs.begin(), E = FNs.end(); I != E; ++I) {
1055-
GepNode *N = I->first;
1056-
UseSet &Us = I->second;
1057-
for (UseSet::iterator J = Us.begin(), F = Us.end(); J != F; ++J)
1058-
separateChainForNode(N, *J, Loc);
1036+
for (auto &FN : FNs) {
1037+
GepNode *N = FN.first;
1038+
UseSet &Us = FN.second;
1039+
for (Use *U : Us)
1040+
separateChainForNode(N, U, Loc);
10591041
}
10601042
}
10611043

@@ -1068,21 +1050,21 @@ void HexagonCommonGEP::computeNodePlacement(NodeToValueMap &Loc) {
10681050

10691051
// Compute the initial placement determined by the users' locations, and
10701052
// the locations of the child nodes.
1071-
for (NodeVect::iterator I = Roots.begin(), E = Roots.end(); I != E; ++I)
1072-
recalculatePlacementRec(*I, NCM, Loc);
1053+
for (GepNode *Root : Roots)
1054+
recalculatePlacementRec(Root, NCM, Loc);
10731055

10741056
LLVM_DEBUG(dbgs() << "Initial node placement:\n" << LocationAsBlock(Loc));
10751057

10761058
if (OptEnableInv) {
1077-
for (NodeVect::iterator I = Roots.begin(), E = Roots.end(); I != E; ++I)
1078-
adjustForInvariance(*I, NCM, Loc);
1059+
for (GepNode *Root : Roots)
1060+
adjustForInvariance(Root, NCM, Loc);
10791061

10801062
LLVM_DEBUG(dbgs() << "Node placement after adjustment for invariance:\n"
10811063
<< LocationAsBlock(Loc));
10821064
}
10831065
if (OptEnableConst) {
1084-
for (NodeVect::iterator I = Roots.begin(), E = Roots.end(); I != E; ++I)
1085-
separateConstantChains(*I, NCM, Loc);
1066+
for (GepNode *Root : Roots)
1067+
separateConstantChains(Root, NCM, Loc);
10861068
}
10871069
LLVM_DEBUG(dbgs() << "Node use information:\n" << Uses);
10881070

@@ -1153,8 +1135,8 @@ void HexagonCommonGEP::getAllUsersForNode(GepNode *Node, ValueVect &Values,
11531135
NodeToUsesMap::iterator UF = Uses.find(N);
11541136
assert(UF != Uses.end() && "No use information for used node");
11551137
UseSet &Us = UF->second;
1156-
for (UseSet::iterator I = Us.begin(), E = Us.end(); I != E; ++I)
1157-
Values.push_back((*I)->getUser());
1138+
for (const auto &U : Us)
1139+
Values.push_back(U->getUser());
11581140
}
11591141
NodeChildrenMap::iterator CF = NCM.find(N);
11601142
if (CF != NCM.end()) {
@@ -1223,8 +1205,7 @@ void HexagonCommonGEP::materialize(NodeToValueMap &Loc) {
12231205
// to the Roots list.
12241206
if (LastCN > 0) {
12251207
NodeVect &Cs = NCM[Last];
1226-
for (NodeVect::iterator I = Cs.begin(), E = Cs.end(); I != E; ++I) {
1227-
GepNode *CN = *I;
1208+
for (GepNode *CN : Cs) {
12281209
CN->Flags &= ~GepNode::Internal;
12291210
CN->Flags |= GepNode::Root;
12301211
CN->BaseVal = NewInst;
@@ -1238,10 +1219,8 @@ void HexagonCommonGEP::materialize(NodeToValueMap &Loc) {
12381219
NodeToUsesMap::iterator UF = Uses.find(Last);
12391220
assert(UF != Uses.end() && "No use information found");
12401221
UseSet &Us = UF->second;
1241-
for (UseSet::iterator I = Us.begin(), E = Us.end(); I != E; ++I) {
1242-
Use *U = *I;
1222+
for (Use *U : Us)
12431223
U->set(NewInst);
1244-
}
12451224
}
12461225
}
12471226
}
@@ -1261,8 +1240,8 @@ void HexagonCommonGEP::removeDeadCode() {
12611240
ValueVect Ins;
12621241
for (Instruction &I : llvm::reverse(*B))
12631242
Ins.push_back(&I);
1264-
for (ValueVect::iterator I = Ins.begin(), E = Ins.end(); I != E; ++I) {
1265-
Instruction *In = cast<Instruction>(*I);
1243+
for (Value *I : Ins) {
1244+
Instruction *In = cast<Instruction>(I);
12661245
if (isInstructionTriviallyDead(In))
12671246
In->eraseFromParent();
12681247
}

0 commit comments

Comments
 (0)