Skip to content

Commit 79179a3

Browse files
committed
[ArgPromotion] Use range-based for loop (NFC)
1 parent aaa16eb commit 79179a3

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

llvm/lib/Transforms/IPO/ArgumentPromotion.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -366,26 +366,25 @@ doPromotion(Function *F, SmallPtrSetImpl<Argument *> &ArgsToPromote,
366366

367367
// Loop over the argument list, transferring uses of the old arguments over to
368368
// the new arguments, also transferring over the names as well.
369-
for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(),
370-
I2 = NF->arg_begin();
371-
I != E; ++I) {
372-
if (!ArgsToPromote.count(&*I) && !ByValArgsToTransform.count(&*I)) {
369+
Function::arg_iterator I2 = NF->arg_begin();
370+
for (Argument &Arg : F->args()) {
371+
if (!ArgsToPromote.count(&Arg) && !ByValArgsToTransform.count(&Arg)) {
373372
// If this is an unmodified argument, move the name and users over to the
374373
// new version.
375-
I->replaceAllUsesWith(&*I2);
376-
I2->takeName(&*I);
374+
Arg.replaceAllUsesWith(&*I2);
375+
I2->takeName(&Arg);
377376
++I2;
378377
continue;
379378
}
380379

381-
if (ByValArgsToTransform.count(&*I)) {
380+
if (ByValArgsToTransform.count(&Arg)) {
382381
// In the callee, we create an alloca, and store each of the new incoming
383382
// arguments into the alloca.
384383
Instruction *InsertPt = &NF->begin()->front();
385384

386385
// Just add all the struct element types.
387-
Type *AgTy = I->getParamByValType();
388-
Align StructAlign = *I->getParamAlign();
386+
Type *AgTy = Arg.getParamByValType();
387+
Align StructAlign = *Arg.getParamAlign();
389388
Value *TheAlloca = new AllocaInst(AgTy, DL.getAllocaAddrSpace(), nullptr,
390389
StructAlign, "", InsertPt);
391390
StructType *STy = cast<StructType>(AgTy);
@@ -398,41 +397,41 @@ doPromotion(Function *F, SmallPtrSetImpl<Argument *> &ArgsToPromote,
398397
Value *Idx = GetElementPtrInst::Create(
399398
AgTy, TheAlloca, Idxs, TheAlloca->getName() + "." + Twine(i),
400399
InsertPt);
401-
I2->setName(I->getName() + "." + Twine(i));
400+
I2->setName(Arg.getName() + "." + Twine(i));
402401
Align Alignment = commonAlignment(StructAlign, SL->getElementOffset(i));
403402
new StoreInst(&*I2++, Idx, false, Alignment, InsertPt);
404403
}
405404

406405
// Anything that used the arg should now use the alloca.
407-
I->replaceAllUsesWith(TheAlloca);
408-
TheAlloca->takeName(&*I);
406+
Arg.replaceAllUsesWith(TheAlloca);
407+
TheAlloca->takeName(&Arg);
409408
continue;
410409
}
411410

412411
// There potentially are metadata uses for things like llvm.dbg.value.
413412
// Replace them with undef, after handling the other regular uses.
414413
auto RauwUndefMetadata = make_scope_exit(
415-
[&]() { I->replaceAllUsesWith(UndefValue::get(I->getType())); });
414+
[&]() { Arg.replaceAllUsesWith(UndefValue::get(Arg.getType())); });
416415

417-
if (I->use_empty())
416+
if (Arg.use_empty())
418417
continue;
419418

420419
// Otherwise, if we promoted this argument, then all users are load
421420
// instructions (or GEPs with only load users), and all loads should be
422421
// using the new argument that we added.
423-
ScalarizeTable &ArgIndices = ScalarizedElements[&*I];
422+
ScalarizeTable &ArgIndices = ScalarizedElements[&Arg];
424423

425-
while (!I->use_empty()) {
426-
if (LoadInst *LI = dyn_cast<LoadInst>(I->user_back())) {
424+
while (!Arg.use_empty()) {
425+
if (LoadInst *LI = dyn_cast<LoadInst>(Arg.user_back())) {
427426
assert(ArgIndices.begin()->second.empty() &&
428427
"Load element should sort to front!");
429-
I2->setName(I->getName() + ".val");
428+
I2->setName(Arg.getName() + ".val");
430429
LI->replaceAllUsesWith(&*I2);
431430
LI->eraseFromParent();
432-
LLVM_DEBUG(dbgs() << "*** Promoted load of argument '" << I->getName()
431+
LLVM_DEBUG(dbgs() << "*** Promoted load of argument '" << Arg.getName()
433432
<< "' in function '" << F->getName() << "'\n");
434433
} else {
435-
GetElementPtrInst *GEP = cast<GetElementPtrInst>(I->user_back());
434+
GetElementPtrInst *GEP = cast<GetElementPtrInst>(Arg.user_back());
436435
assert(!GEP->use_empty() &&
437436
"GEPs without uses should be cleaned up already");
438437
IndicesVector Operands;
@@ -450,7 +449,7 @@ doPromotion(Function *F, SmallPtrSetImpl<Argument *> &ArgsToPromote,
450449
assert(It != ArgIndices.end() && "GEP not handled??");
451450
}
452451

453-
TheArg->setName(formatv("{0}.{1:$[.]}.val", I->getName(),
452+
TheArg->setName(formatv("{0}.{1:$[.]}.val", Arg.getName(),
454453
make_range(Operands.begin(), Operands.end())));
455454

456455
LLVM_DEBUG(dbgs() << "*** Promoted agg argument '" << TheArg->getName()

0 commit comments

Comments
 (0)