Skip to content

Commit 739b928

Browse files
kazutakahiratalravenclaw
authored andcommitted
[Transforms] Use range-based for loops (NFC) (llvm#97195)
1 parent 0b928fb commit 739b928

File tree

8 files changed

+24
-41
lines changed

8 files changed

+24
-41
lines changed

llvm/lib/Transforms/IPO/Attributor.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,8 +2385,7 @@ void Attributor::identifyDeadInternalFunctions() {
23852385
bool FoundLiveInternal = true;
23862386
while (FoundLiveInternal) {
23872387
FoundLiveInternal = false;
2388-
for (unsigned u = 0, e = InternalFns.size(); u < e; ++u) {
2389-
Function *F = InternalFns[u];
2388+
for (Function *&F : InternalFns) {
23902389
if (!F)
23912390
continue;
23922391

@@ -2403,13 +2402,13 @@ void Attributor::identifyDeadInternalFunctions() {
24032402
}
24042403

24052404
LiveInternalFns.insert(F);
2406-
InternalFns[u] = nullptr;
2405+
F = nullptr;
24072406
FoundLiveInternal = true;
24082407
}
24092408
}
24102409

2411-
for (unsigned u = 0, e = InternalFns.size(); u < e; ++u)
2412-
if (Function *F = InternalFns[u])
2410+
for (Function *F : InternalFns)
2411+
if (F)
24132412
ToBeDeletedFunctions.insert(F);
24142413
}
24152414

llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,7 @@ bool DeadArgumentEliminationPass::removeDeadArgumentsFromCallers(Function &F) {
319319
continue;
320320

321321
// Now go through all unused args and replace them with poison.
322-
for (unsigned I = 0, E = UnusedArgs.size(); I != E; ++I) {
323-
unsigned ArgNo = UnusedArgs[I];
324-
322+
for (unsigned ArgNo : UnusedArgs) {
325323
Value *Arg = CB->getArgOperand(ArgNo);
326324
CB->setArgOperand(ArgNo, PoisonValue::get(Arg->getType()));
327325
CB->removeParamAttrs(ArgNo, UBImplyingAttributes);

llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5114,8 +5114,7 @@ struct VarArgAMD64Helper : public VarArgHelperBase {
51145114

51155115
// Instrument va_start.
51165116
// Copy va_list shadow from the backup copy of the TLS contents.
5117-
for (size_t i = 0, n = VAStartInstrumentationList.size(); i < n; i++) {
5118-
CallInst *OrigInst = VAStartInstrumentationList[i];
5117+
for (CallInst *OrigInst : VAStartInstrumentationList) {
51195118
NextNodeIRBuilder IRB(OrigInst);
51205119
Value *VAListTag = OrigInst->getArgOperand(0);
51215120

@@ -5224,8 +5223,7 @@ struct VarArgMIPS64Helper : public VarArgHelperBase {
52245223

52255224
// Instrument va_start.
52265225
// Copy va_list shadow from the backup copy of the TLS contents.
5227-
for (size_t i = 0, n = VAStartInstrumentationList.size(); i < n; i++) {
5228-
CallInst *OrigInst = VAStartInstrumentationList[i];
5226+
for (CallInst *OrigInst : VAStartInstrumentationList) {
52295227
NextNodeIRBuilder IRB(OrigInst);
52305228
Value *VAListTag = OrigInst->getArgOperand(0);
52315229
Type *RegSaveAreaPtrTy = PointerType::getUnqual(*MS.C); // i64*
@@ -5399,8 +5397,7 @@ struct VarArgAArch64Helper : public VarArgHelperBase {
53995397

54005398
// Instrument va_start, copy va_list shadow from the backup copy of
54015399
// the TLS contents.
5402-
for (size_t i = 0, n = VAStartInstrumentationList.size(); i < n; i++) {
5403-
CallInst *OrigInst = VAStartInstrumentationList[i];
5400+
for (CallInst *OrigInst : VAStartInstrumentationList) {
54045401
NextNodeIRBuilder IRB(OrigInst);
54055402

54065403
Value *VAListTag = OrigInst->getArgOperand(0);
@@ -5610,8 +5607,7 @@ struct VarArgPowerPC64Helper : public VarArgHelperBase {
56105607

56115608
// Instrument va_start.
56125609
// Copy va_list shadow from the backup copy of the TLS contents.
5613-
for (size_t i = 0, n = VAStartInstrumentationList.size(); i < n; i++) {
5614-
CallInst *OrigInst = VAStartInstrumentationList[i];
5610+
for (CallInst *OrigInst : VAStartInstrumentationList) {
56155611
NextNodeIRBuilder IRB(OrigInst);
56165612
Value *VAListTag = OrigInst->getArgOperand(0);
56175613
Type *RegSaveAreaPtrTy = PointerType::getUnqual(*MS.C); // i64*
@@ -5907,9 +5903,7 @@ struct VarArgSystemZHelper : public VarArgHelperBase {
59075903

59085904
// Instrument va_start.
59095905
// Copy va_list shadow from the backup copy of the TLS contents.
5910-
for (size_t VaStartNo = 0, VaStartNum = VAStartInstrumentationList.size();
5911-
VaStartNo < VaStartNum; VaStartNo++) {
5912-
CallInst *OrigInst = VAStartInstrumentationList[VaStartNo];
5906+
for (CallInst *OrigInst : VAStartInstrumentationList) {
59135907
NextNodeIRBuilder IRB(OrigInst);
59145908
Value *VAListTag = OrigInst->getArgOperand(0);
59155909
copyRegSaveArea(IRB, VAListTag);

llvm/lib/Transforms/Scalar/Scalarizer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,8 @@ void ScalarizerVisitor::transferMetadataAndIRFlags(Instruction *Op,
523523
const ValueVector &CV) {
524524
SmallVector<std::pair<unsigned, MDNode *>, 4> MDs;
525525
Op->getAllMetadataOtherThanDebugLoc(MDs);
526-
for (unsigned I = 0, E = CV.size(); I != E; ++I) {
527-
if (Instruction *New = dyn_cast<Instruction>(CV[I])) {
526+
for (Value *V : CV) {
527+
if (Instruction *New = dyn_cast<Instruction>(V)) {
528528
for (const auto &MD : MDs)
529529
if (canTransferMetadata(MD.first))
530530
New->setMetadata(MD.first, MD.second);

llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,7 @@ callBufferedPrintfArgPush(IRBuilder<> &Builder, ArrayRef<Value *> Args,
409409
WhatToStore.push_back(processNonStringArg(Args[i], Builder));
410410
}
411411

412-
for (unsigned I = 0, E = WhatToStore.size(); I != E; ++I) {
413-
Value *toStore = WhatToStore[I];
414-
412+
for (Value *toStore : WhatToStore) {
415413
StoreInst *StBuff = Builder.CreateStore(toStore, PtrToStore);
416414
LLVM_DEBUG(dbgs() << "inserting store to printf buffer:" << *StBuff
417415
<< '\n');

llvm/lib/Transforms/Utils/InlineFunction.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2631,8 +2631,7 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
26312631
if ((InsertLifetime || Caller->isPresplitCoroutine()) &&
26322632
!IFI.StaticAllocas.empty()) {
26332633
IRBuilder<> builder(&*FirstNewBlock, FirstNewBlock->begin());
2634-
for (unsigned ai = 0, ae = IFI.StaticAllocas.size(); ai != ae; ++ai) {
2635-
AllocaInst *AI = IFI.StaticAllocas[ai];
2634+
for (AllocaInst *AI : IFI.StaticAllocas) {
26362635
// Don't mark swifterror allocas. They can't have bitcast uses.
26372636
if (AI->isSwiftError())
26382637
continue;
@@ -2969,8 +2968,7 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
29692968
// Loop over all of the return instructions adding entries to the PHI node
29702969
// as appropriate.
29712970
if (PHI) {
2972-
for (unsigned i = 0, e = Returns.size(); i != e; ++i) {
2973-
ReturnInst *RI = Returns[i];
2971+
for (ReturnInst *RI : Returns) {
29742972
assert(RI->getReturnValue()->getType() == PHI->getType() &&
29752973
"Ret value not consistent in function!");
29762974
PHI->addIncoming(RI->getReturnValue(), RI->getParent());
@@ -2979,9 +2977,8 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
29792977

29802978
// Add a branch to the merge points and remove return instructions.
29812979
DebugLoc Loc;
2982-
for (unsigned i = 0, e = Returns.size(); i != e; ++i) {
2983-
ReturnInst *RI = Returns[i];
2984-
BranchInst* BI = BranchInst::Create(AfterCallBB, RI->getIterator());
2980+
for (ReturnInst *RI : Returns) {
2981+
BranchInst *BI = BranchInst::Create(AfterCallBB, RI->getIterator());
29852982
Loc = RI->getDebugLoc();
29862983
BI->setDebugLoc(Loc);
29872984
RI->eraseFromParent();

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,11 +1095,9 @@ static void redirectValuesFromPredecessorsToPhi(BasicBlock *BB,
10951095
PN->addIncoming(OldValPN->getIncomingValueForBlock(CommonPred), BB);
10961096

10971097
} else {
1098-
for (unsigned i = 0, e = BBPreds.size(); i != e; ++i) {
1098+
for (BasicBlock *PredBB : BBPreds) {
10991099
// Update existing incoming values in PN for this
11001100
// predecessor of BB.
1101-
BasicBlock *PredBB = BBPreds[i];
1102-
11031101
if (PredBB == CommonPred)
11041102
continue;
11051103

llvm/lib/Transforms/Utils/LoopSimplify.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ static void placeSplitBlockCarefully(BasicBlock *NewBB,
8383
Loop *L) {
8484
// Check to see if NewBB is already well placed.
8585
Function::iterator BBI = --NewBB->getIterator();
86-
for (unsigned i = 0, e = SplitPreds.size(); i != e; ++i) {
87-
if (&*BBI == SplitPreds[i])
86+
for (BasicBlock *Pred : SplitPreds) {
87+
if (&*BBI == Pred)
8888
return;
8989
}
9090

@@ -95,10 +95,10 @@ static void placeSplitBlockCarefully(BasicBlock *NewBB,
9595
// Figure out *which* outside block to put this after. Prefer an outside
9696
// block that neighbors a BB actually in the loop.
9797
BasicBlock *FoundBB = nullptr;
98-
for (unsigned i = 0, e = SplitPreds.size(); i != e; ++i) {
99-
Function::iterator BBI = SplitPreds[i]->getIterator();
98+
for (BasicBlock *Pred : SplitPreds) {
99+
Function::iterator BBI = Pred->getIterator();
100100
if (++BBI != NewBB->getParent()->end() && L->contains(&*BBI)) {
101-
FoundBB = SplitPreds[i];
101+
FoundBB = Pred;
102102
break;
103103
}
104104
}
@@ -630,8 +630,7 @@ static bool simplifyOneLoop(Loop *L, SmallVectorImpl<Loop *> &Worklist,
630630
return true;
631631
};
632632
if (HasUniqueExitBlock()) {
633-
for (unsigned i = 0, e = ExitingBlocks.size(); i != e; ++i) {
634-
BasicBlock *ExitingBlock = ExitingBlocks[i];
633+
for (BasicBlock *ExitingBlock : ExitingBlocks) {
635634
if (!ExitingBlock->getSinglePredecessor()) continue;
636635
BranchInst *BI = dyn_cast<BranchInst>(ExitingBlock->getTerminator());
637636
if (!BI || !BI->isConditional()) continue;

0 commit comments

Comments
 (0)