Skip to content

Commit

Permalink
[Transforms] Use range-based for loops (NFC) (llvm#97195)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazutakahirata authored Jul 2, 2024
1 parent 594bc52 commit 4b28b3f
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 41 deletions.
9 changes: 4 additions & 5 deletions llvm/lib/Transforms/IPO/Attributor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2385,8 +2385,7 @@ void Attributor::identifyDeadInternalFunctions() {
bool FoundLiveInternal = true;
while (FoundLiveInternal) {
FoundLiveInternal = false;
for (unsigned u = 0, e = InternalFns.size(); u < e; ++u) {
Function *F = InternalFns[u];
for (Function *&F : InternalFns) {
if (!F)
continue;

Expand All @@ -2403,13 +2402,13 @@ void Attributor::identifyDeadInternalFunctions() {
}

LiveInternalFns.insert(F);
InternalFns[u] = nullptr;
F = nullptr;
FoundLiveInternal = true;
}
}

for (unsigned u = 0, e = InternalFns.size(); u < e; ++u)
if (Function *F = InternalFns[u])
for (Function *F : InternalFns)
if (F)
ToBeDeletedFunctions.insert(F);
}

Expand Down
4 changes: 1 addition & 3 deletions llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,7 @@ bool DeadArgumentEliminationPass::removeDeadArgumentsFromCallers(Function &F) {
continue;

// Now go through all unused args and replace them with poison.
for (unsigned I = 0, E = UnusedArgs.size(); I != E; ++I) {
unsigned ArgNo = UnusedArgs[I];

for (unsigned ArgNo : UnusedArgs) {
Value *Arg = CB->getArgOperand(ArgNo);
CB->setArgOperand(ArgNo, PoisonValue::get(Arg->getType()));
CB->removeParamAttrs(ArgNo, UBImplyingAttributes);
Expand Down
16 changes: 5 additions & 11 deletions llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5114,8 +5114,7 @@ struct VarArgAMD64Helper : public VarArgHelperBase {

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

Expand Down Expand Up @@ -5224,8 +5223,7 @@ struct VarArgMIPS64Helper : public VarArgHelperBase {

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

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

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

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

// Instrument va_start.
// Copy va_list shadow from the backup copy of the TLS contents.
for (size_t VaStartNo = 0, VaStartNum = VAStartInstrumentationList.size();
VaStartNo < VaStartNum; VaStartNo++) {
CallInst *OrigInst = VAStartInstrumentationList[VaStartNo];
for (CallInst *OrigInst : VAStartInstrumentationList) {
NextNodeIRBuilder IRB(OrigInst);
Value *VAListTag = OrigInst->getArgOperand(0);
copyRegSaveArea(IRB, VAListTag);
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Scalar/Scalarizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,8 @@ void ScalarizerVisitor::transferMetadataAndIRFlags(Instruction *Op,
const ValueVector &CV) {
SmallVector<std::pair<unsigned, MDNode *>, 4> MDs;
Op->getAllMetadataOtherThanDebugLoc(MDs);
for (unsigned I = 0, E = CV.size(); I != E; ++I) {
if (Instruction *New = dyn_cast<Instruction>(CV[I])) {
for (Value *V : CV) {
if (Instruction *New = dyn_cast<Instruction>(V)) {
for (const auto &MD : MDs)
if (canTransferMetadata(MD.first))
New->setMetadata(MD.first, MD.second);
Expand Down
4 changes: 1 addition & 3 deletions llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,7 @@ callBufferedPrintfArgPush(IRBuilder<> &Builder, ArrayRef<Value *> Args,
WhatToStore.push_back(processNonStringArg(Args[i], Builder));
}

for (unsigned I = 0, E = WhatToStore.size(); I != E; ++I) {
Value *toStore = WhatToStore[I];

for (Value *toStore : WhatToStore) {
StoreInst *StBuff = Builder.CreateStore(toStore, PtrToStore);
LLVM_DEBUG(dbgs() << "inserting store to printf buffer:" << *StBuff
<< '\n');
Expand Down
11 changes: 4 additions & 7 deletions llvm/lib/Transforms/Utils/InlineFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2631,8 +2631,7 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
if ((InsertLifetime || Caller->isPresplitCoroutine()) &&
!IFI.StaticAllocas.empty()) {
IRBuilder<> builder(&*FirstNewBlock, FirstNewBlock->begin());
for (unsigned ai = 0, ae = IFI.StaticAllocas.size(); ai != ae; ++ai) {
AllocaInst *AI = IFI.StaticAllocas[ai];
for (AllocaInst *AI : IFI.StaticAllocas) {
// Don't mark swifterror allocas. They can't have bitcast uses.
if (AI->isSwiftError())
continue;
Expand Down Expand Up @@ -2969,8 +2968,7 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
// Loop over all of the return instructions adding entries to the PHI node
// as appropriate.
if (PHI) {
for (unsigned i = 0, e = Returns.size(); i != e; ++i) {
ReturnInst *RI = Returns[i];
for (ReturnInst *RI : Returns) {
assert(RI->getReturnValue()->getType() == PHI->getType() &&
"Ret value not consistent in function!");
PHI->addIncoming(RI->getReturnValue(), RI->getParent());
Expand All @@ -2979,9 +2977,8 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,

// Add a branch to the merge points and remove return instructions.
DebugLoc Loc;
for (unsigned i = 0, e = Returns.size(); i != e; ++i) {
ReturnInst *RI = Returns[i];
BranchInst* BI = BranchInst::Create(AfterCallBB, RI->getIterator());
for (ReturnInst *RI : Returns) {
BranchInst *BI = BranchInst::Create(AfterCallBB, RI->getIterator());
Loc = RI->getDebugLoc();
BI->setDebugLoc(Loc);
RI->eraseFromParent();
Expand Down
4 changes: 1 addition & 3 deletions llvm/lib/Transforms/Utils/Local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1095,11 +1095,9 @@ static void redirectValuesFromPredecessorsToPhi(BasicBlock *BB,
PN->addIncoming(OldValPN->getIncomingValueForBlock(CommonPred), BB);

} else {
for (unsigned i = 0, e = BBPreds.size(); i != e; ++i) {
for (BasicBlock *PredBB : BBPreds) {
// Update existing incoming values in PN for this
// predecessor of BB.
BasicBlock *PredBB = BBPreds[i];

if (PredBB == CommonPred)
continue;

Expand Down
13 changes: 6 additions & 7 deletions llvm/lib/Transforms/Utils/LoopSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ static void placeSplitBlockCarefully(BasicBlock *NewBB,
Loop *L) {
// Check to see if NewBB is already well placed.
Function::iterator BBI = --NewBB->getIterator();
for (unsigned i = 0, e = SplitPreds.size(); i != e; ++i) {
if (&*BBI == SplitPreds[i])
for (BasicBlock *Pred : SplitPreds) {
if (&*BBI == Pred)
return;
}

Expand All @@ -95,10 +95,10 @@ static void placeSplitBlockCarefully(BasicBlock *NewBB,
// Figure out *which* outside block to put this after. Prefer an outside
// block that neighbors a BB actually in the loop.
BasicBlock *FoundBB = nullptr;
for (unsigned i = 0, e = SplitPreds.size(); i != e; ++i) {
Function::iterator BBI = SplitPreds[i]->getIterator();
for (BasicBlock *Pred : SplitPreds) {
Function::iterator BBI = Pred->getIterator();
if (++BBI != NewBB->getParent()->end() && L->contains(&*BBI)) {
FoundBB = SplitPreds[i];
FoundBB = Pred;
break;
}
}
Expand Down Expand Up @@ -630,8 +630,7 @@ static bool simplifyOneLoop(Loop *L, SmallVectorImpl<Loop *> &Worklist,
return true;
};
if (HasUniqueExitBlock()) {
for (unsigned i = 0, e = ExitingBlocks.size(); i != e; ++i) {
BasicBlock *ExitingBlock = ExitingBlocks[i];
for (BasicBlock *ExitingBlock : ExitingBlocks) {
if (!ExitingBlock->getSinglePredecessor()) continue;
BranchInst *BI = dyn_cast<BranchInst>(ExitingBlock->getTerminator());
if (!BI || !BI->isConditional()) continue;
Expand Down

0 comments on commit 4b28b3f

Please sign in to comment.