@@ -290,13 +290,11 @@ namespace {
290
290
raw_ostream &operator << (raw_ostream &OS,
291
291
const NodeToUsesMap &M) LLVM_ATTRIBUTE_UNUSED;
292
292
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 ();
300
298
if (R->hasName ())
301
299
OS << ' ' << R->getName ();
302
300
else
@@ -420,33 +418,27 @@ void HexagonCommonGEP::collect() {
420
418
// instruction that uses another GEP instruction as the base pointer, the
421
419
// gep node for the base pointer should already exist.
422
420
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);
432
427
}
433
428
434
429
LLVM_DEBUG (dbgs () << " Gep nodes after initial collection:\n " << Nodes);
435
430
}
436
431
437
432
static void invert_find_roots (const NodeVect &Nodes, NodeChildrenMap &NCM,
438
433
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 ;
449
438
}
439
+ GepNode *PN = N->Parent ;
440
+ NCM[PN].push_back (N);
441
+ }
450
442
}
451
443
452
444
static void nodes_for_root (GepNode *Root, NodeChildrenMap &NCM,
@@ -546,8 +538,7 @@ void HexagonCommonGEP::common() {
546
538
using NodeSetMap = std::map<unsigned , NodeSet>;
547
539
NodeSetMap MaybeEq;
548
540
549
- for (NodeVect::iterator I = Nodes.begin (), E = Nodes.end (); I != E; ++I) {
550
- GepNode *N = *I;
541
+ for (GepNode *N : Nodes) {
551
542
unsigned H = node_hash (N);
552
543
MaybeEq[H].insert (N);
553
544
}
@@ -556,9 +547,8 @@ void HexagonCommonGEP::common() {
556
547
// one for equality and the other for non-equality.
557
548
NodeSymRel EqRel; // Equality relation (as set of equivalence classes).
558
549
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 ;
562
552
for (NodeSet::iterator NI = S.begin (), NE = S.end (); NI != NE; ++NI) {
563
553
GepNode *N = *NI;
564
554
// If node already has a class, then the class must have been created
@@ -612,8 +602,7 @@ void HexagonCommonGEP::common() {
612
602
// Update the min element's flags, and user list.
613
603
uint32_t Flags = 0 ;
614
604
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) {
617
606
uint32_t NF = N->Flags ;
618
607
// If N is used, append all original values of N to the list of
619
608
// original values of Min.
@@ -633,8 +622,7 @@ void HexagonCommonGEP::common() {
633
622
// selected (minimum) node from the corresponding equivalence class.
634
623
// If a given parent does not have an equivalence class, leave it
635
624
// 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) {
638
626
if (N->Flags & GepNode::Root)
639
627
continue ;
640
628
const NodeSet *PC = node_class (N->Parent , EqRel);
@@ -652,8 +640,7 @@ void HexagonCommonGEP::common() {
652
640
653
641
// Finally, erase the nodes that are no longer used.
654
642
NodeSet Erase;
655
- for (NodeVect::iterator I = Nodes.begin (), E = Nodes.end (); I != E; ++I) {
656
- GepNode *N = *I;
643
+ for (GepNode *N : Nodes) {
657
644
const NodeSet *PC = node_class (N, EqRel);
658
645
if (!PC)
659
646
continue ;
@@ -663,7 +650,7 @@ void HexagonCommonGEP::common() {
663
650
if (N == F->second )
664
651
continue ;
665
652
// Node for removal.
666
- Erase.insert (*I );
653
+ Erase.insert (N );
667
654
}
668
655
erase_if (Nodes, in_set (Erase));
669
656
@@ -775,8 +762,7 @@ BasicBlock *HexagonCommonGEP::recalculatePlacement(GepNode *Node,
775
762
NodeToUsesMap::iterator UF = Uses.find (Node);
776
763
assert (UF != Uses.end () && " Used node with no use information" );
777
764
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) {
780
766
User *R = U->getUser ();
781
767
if (!isa<Instruction>(R))
782
768
continue ;
@@ -790,8 +776,7 @@ BasicBlock *HexagonCommonGEP::recalculatePlacement(GepNode *Node,
790
776
NodeChildrenMap::iterator CF = NCM.find (Node);
791
777
if (CF != NCM.end ()) {
792
778
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) {
795
780
NodeToValueMap::iterator LF = Loc.find (CN);
796
781
// If the child is only used in GEP instructions (i.e. is not used in
797
782
// non-GEP instructions), the nearest dominator computed for it may
@@ -831,8 +816,8 @@ BasicBlock *HexagonCommonGEP::recalculatePlacementRec(GepNode *Node,
831
816
NodeChildrenMap::iterator CF = NCM.find (Node);
832
817
if (CF != NCM.end ()) {
833
818
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);
836
821
}
837
822
BasicBlock *LB = recalculatePlacement (Node, NCM, Loc);
838
823
LLVM_DEBUG (dbgs () << " LocRec end for node:" << Node << ' \n ' );
@@ -921,8 +906,8 @@ BasicBlock *HexagonCommonGEP::adjustForInvariance(GepNode *Node,
921
906
NodeChildrenMap::iterator CF = NCM.find (Node);
922
907
if (CF != NCM.end ()) {
923
908
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);
926
911
}
927
912
return LocB;
928
913
}
@@ -938,10 +923,9 @@ namespace {
938
923
raw_ostream &operator << (raw_ostream &OS,
939
924
const LocationAsBlock &Loc) LLVM_ATTRIBUTE_UNUSED ;
940
925
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 ))
945
929
OS << B->getName () << ' (' << B << ' )' ;
946
930
else
947
931
OS << " <null-block>" ;
@@ -1016,17 +1000,15 @@ void HexagonCommonGEP::separateConstantChains(GepNode *Node,
1016
1000
// Collect all used nodes together with the uses from loads and stores,
1017
1001
// where the GEP node could be folded into the load/store instruction.
1018
1002
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) {
1021
1004
if (!(N->Flags & GepNode::Used))
1022
1005
continue ;
1023
1006
NodeToUsesMap::iterator UF = Uses.find (N);
1024
1007
assert (UF != Uses.end ());
1025
1008
UseSet &Us = UF->second ;
1026
1009
// Loads/stores that use the node N.
1027
1010
UseSet LSs;
1028
- for (UseSet::iterator J = Us.begin (), F = Us.end (); J != F; ++J) {
1029
- Use *U = *J;
1011
+ for (Use *U : Us) {
1030
1012
User *R = U->getUser ();
1031
1013
// We're interested in uses that provide the address. It can happen
1032
1014
// that the value may also be provided via GEP, but we won't handle
@@ -1051,11 +1033,11 @@ void HexagonCommonGEP::separateConstantChains(GepNode *Node,
1051
1033
1052
1034
LLVM_DEBUG (dbgs () << " Nodes with foldable users:\n " << FNs);
1053
1035
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);
1059
1041
}
1060
1042
}
1061
1043
@@ -1068,21 +1050,21 @@ void HexagonCommonGEP::computeNodePlacement(NodeToValueMap &Loc) {
1068
1050
1069
1051
// Compute the initial placement determined by the users' locations, and
1070
1052
// 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);
1073
1055
1074
1056
LLVM_DEBUG (dbgs () << " Initial node placement:\n " << LocationAsBlock (Loc));
1075
1057
1076
1058
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);
1079
1061
1080
1062
LLVM_DEBUG (dbgs () << " Node placement after adjustment for invariance:\n "
1081
1063
<< LocationAsBlock (Loc));
1082
1064
}
1083
1065
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);
1086
1068
}
1087
1069
LLVM_DEBUG (dbgs () << " Node use information:\n " << Uses);
1088
1070
@@ -1153,8 +1135,8 @@ void HexagonCommonGEP::getAllUsersForNode(GepNode *Node, ValueVect &Values,
1153
1135
NodeToUsesMap::iterator UF = Uses.find (N);
1154
1136
assert (UF != Uses.end () && " No use information for used node" );
1155
1137
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 ());
1158
1140
}
1159
1141
NodeChildrenMap::iterator CF = NCM.find (N);
1160
1142
if (CF != NCM.end ()) {
@@ -1223,8 +1205,7 @@ void HexagonCommonGEP::materialize(NodeToValueMap &Loc) {
1223
1205
// to the Roots list.
1224
1206
if (LastCN > 0 ) {
1225
1207
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) {
1228
1209
CN->Flags &= ~GepNode::Internal;
1229
1210
CN->Flags |= GepNode::Root;
1230
1211
CN->BaseVal = NewInst;
@@ -1238,10 +1219,8 @@ void HexagonCommonGEP::materialize(NodeToValueMap &Loc) {
1238
1219
NodeToUsesMap::iterator UF = Uses.find (Last);
1239
1220
assert (UF != Uses.end () && " No use information found" );
1240
1221
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)
1243
1223
U->set (NewInst);
1244
- }
1245
1224
}
1246
1225
}
1247
1226
}
@@ -1261,8 +1240,8 @@ void HexagonCommonGEP::removeDeadCode() {
1261
1240
ValueVect Ins;
1262
1241
for (Instruction &I : llvm::reverse (*B))
1263
1242
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);
1266
1245
if (isInstructionTriviallyDead (In))
1267
1246
In->eraseFromParent ();
1268
1247
}
0 commit comments