Skip to content

Commit 4ca2972

Browse files
[Transforms] Use range-based for loops (NFC)
1 parent 4154ada commit 4ca2972

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

llvm/lib/Transforms/IPO/GlobalOpt.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,10 @@ CleanupPointerRootUsers(GlobalVariable *GV,
250250
}
251251
}
252252

253-
for (int i = 0, e = Dead.size(); i != e; ++i) {
254-
if (IsSafeComputationToRemove(Dead[i].first, GetTLI)) {
255-
Dead[i].second->eraseFromParent();
256-
Instruction *I = Dead[i].first;
253+
for (const auto &Pair : Dead) {
254+
if (IsSafeComputationToRemove(Pair.first, GetTLI)) {
255+
Pair.second->eraseFromParent();
256+
Instruction *I = Pair.first;
257257
do {
258258
if (isAllocationFn(I, GetTLI))
259259
break;

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3472,13 +3472,13 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) {
34723472
auto Removable =
34733473
isAllocSiteRemovable(&MI, Users, TLI, KnowInitZero | KnowInitUndef);
34743474
if (Removable) {
3475-
for (unsigned i = 0, e = Users.size(); i != e; ++i) {
3475+
for (WeakTrackingVH &User : Users) {
34763476
// Lowering all @llvm.objectsize and MTI calls first because they may use
34773477
// a bitcast/GEP of the alloca we are removing.
3478-
if (!Users[i])
3479-
continue;
3478+
if (!User)
3479+
continue;
34803480

3481-
Instruction *I = cast<Instruction>(&*Users[i]);
3481+
Instruction *I = cast<Instruction>(&*User);
34823482

34833483
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
34843484
if (II->getIntrinsicID() == Intrinsic::objectsize) {
@@ -3489,7 +3489,7 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) {
34893489
Worklist.add(Inserted);
34903490
replaceInstUsesWith(*I, Result);
34913491
eraseInstFromFunction(*I);
3492-
Users[i] = nullptr; // Skip examining in the next loop.
3492+
User = nullptr; // Skip examining in the next loop.
34933493
continue;
34943494
}
34953495
if (auto *MTI = dyn_cast<MemTransferInst>(I)) {
@@ -3505,11 +3505,11 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) {
35053505
}
35063506
}
35073507
}
3508-
for (unsigned i = 0, e = Users.size(); i != e; ++i) {
3509-
if (!Users[i])
3508+
for (WeakTrackingVH &User : Users) {
3509+
if (!User)
35103510
continue;
35113511

3512-
Instruction *I = cast<Instruction>(&*Users[i]);
3512+
Instruction *I = cast<Instruction>(&*User);
35133513

35143514
if (ICmpInst *C = dyn_cast<ICmpInst>(I)) {
35153515
replaceInstUsesWith(*C,

llvm/lib/Transforms/Scalar/LoopInterchange.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ static bool populateDependencyMatrix(CharMatrix &DepMatrix, unsigned Level,
235235
// matrix by exchanging the two columns.
236236
static void interChangeDependencies(CharMatrix &DepMatrix, unsigned FromIndx,
237237
unsigned ToIndx) {
238-
for (unsigned I = 0, E = DepMatrix.size(); I < E; ++I)
239-
std::swap(DepMatrix[I][ToIndx], DepMatrix[I][FromIndx]);
238+
for (auto &Row : DepMatrix)
239+
std::swap(Row[ToIndx], Row[FromIndx]);
240240
}
241241

242242
// Check if a direction vector is lexicographically positive. Return true if it

llvm/lib/Transforms/Scalar/Reassociate.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ static void PrintOps(Instruction *I, const SmallVectorImpl<ValueEntry> &Ops) {
8383
Module *M = I->getModule();
8484
dbgs() << Instruction::getOpcodeName(I->getOpcode()) << " "
8585
<< *Ops[0].Op->getType() << '\t';
86-
for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
86+
for (const ValueEntry &Op : Ops) {
8787
dbgs() << "[ ";
88-
Ops[i].Op->printAsOperand(dbgs(), false, M);
89-
dbgs() << ", #" << Ops[i].Rank << "] ";
88+
Op.Op->printAsOperand(dbgs(), false, M);
89+
dbgs() << ", #" << Op.Rank << "] ";
9090
}
9191
}
9292
#endif
@@ -1585,9 +1585,9 @@ Value *ReassociatePass::OptimizeAdd(Instruction *I,
15851585
// where they are actually the same multiply.
15861586
unsigned MaxOcc = 0;
15871587
Value *MaxOccVal = nullptr;
1588-
for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
1588+
for (const ValueEntry &Op : Ops) {
15891589
BinaryOperator *BOp =
1590-
isReassociableOp(Ops[i].Op, Instruction::Mul, Instruction::FMul);
1590+
isReassociableOp(Op.Op, Instruction::Mul, Instruction::FMul);
15911591
if (!BOp)
15921592
continue;
15931593

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3082,10 +3082,10 @@ bool VectorCombine::foldSelectShuffle(Instruction &I, bool FromReduction) {
30823082
auto *SSV = cast<ShuffleVectorInst>(SVOp0);
30833083
SVOp0 = SSV->getOperand(0);
30843084
SVOp1 = SSV->getOperand(1);
3085-
for (unsigned I = 0, E = Mask.size(); I != E; I++) {
3086-
if (Mask[I] >= static_cast<int>(SSV->getShuffleMask().size()))
3085+
for (int &Elem : Mask) {
3086+
if (Elem >= static_cast<int>(SSV->getShuffleMask().size()))
30873087
return false;
3088-
Mask[I] = Mask[I] < 0 ? Mask[I] : SSV->getMaskValue(Mask[I]);
3088+
Elem = Elem < 0 ? Elem : SSV->getMaskValue(Elem);
30893089
}
30903090
}
30913091
if (SVOp0 == Op1 && SVOp1 == Op0) {

0 commit comments

Comments
 (0)