@@ -366,26 +366,25 @@ doPromotion(Function *F, SmallPtrSetImpl<Argument *> &ArgsToPromote,
366
366
367
367
// Loop over the argument list, transferring uses of the old arguments over to
368
368
// 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)) {
373
372
// If this is an unmodified argument, move the name and users over to the
374
373
// new version.
375
- I-> replaceAllUsesWith (&*I2);
376
- I2->takeName (&*I );
374
+ Arg. replaceAllUsesWith (&*I2);
375
+ I2->takeName (&Arg );
377
376
++I2;
378
377
continue ;
379
378
}
380
379
381
- if (ByValArgsToTransform.count (&*I )) {
380
+ if (ByValArgsToTransform.count (&Arg )) {
382
381
// In the callee, we create an alloca, and store each of the new incoming
383
382
// arguments into the alloca.
384
383
Instruction *InsertPt = &NF->begin ()->front ();
385
384
386
385
// 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 ();
389
388
Value *TheAlloca = new AllocaInst (AgTy, DL.getAllocaAddrSpace (), nullptr ,
390
389
StructAlign, " " , InsertPt);
391
390
StructType *STy = cast<StructType>(AgTy);
@@ -398,41 +397,41 @@ doPromotion(Function *F, SmallPtrSetImpl<Argument *> &ArgsToPromote,
398
397
Value *Idx = GetElementPtrInst::Create (
399
398
AgTy, TheAlloca, Idxs, TheAlloca->getName () + " ." + Twine (i),
400
399
InsertPt);
401
- I2->setName (I-> getName () + " ." + Twine (i));
400
+ I2->setName (Arg. getName () + " ." + Twine (i));
402
401
Align Alignment = commonAlignment (StructAlign, SL->getElementOffset (i));
403
402
new StoreInst (&*I2++, Idx, false , Alignment, InsertPt);
404
403
}
405
404
406
405
// 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 );
409
408
continue ;
410
409
}
411
410
412
411
// There potentially are metadata uses for things like llvm.dbg.value.
413
412
// Replace them with undef, after handling the other regular uses.
414
413
auto RauwUndefMetadata = make_scope_exit (
415
- [&]() { I-> replaceAllUsesWith (UndefValue::get (I-> getType ())); });
414
+ [&]() { Arg. replaceAllUsesWith (UndefValue::get (Arg. getType ())); });
416
415
417
- if (I-> use_empty ())
416
+ if (Arg. use_empty ())
418
417
continue ;
419
418
420
419
// Otherwise, if we promoted this argument, then all users are load
421
420
// instructions (or GEPs with only load users), and all loads should be
422
421
// using the new argument that we added.
423
- ScalarizeTable &ArgIndices = ScalarizedElements[&*I ];
422
+ ScalarizeTable &ArgIndices = ScalarizedElements[&Arg ];
424
423
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 ())) {
427
426
assert (ArgIndices.begin ()->second .empty () &&
428
427
" Load element should sort to front!" );
429
- I2->setName (I-> getName () + " .val" );
428
+ I2->setName (Arg. getName () + " .val" );
430
429
LI->replaceAllUsesWith (&*I2);
431
430
LI->eraseFromParent ();
432
- LLVM_DEBUG (dbgs () << " *** Promoted load of argument '" << I-> getName ()
431
+ LLVM_DEBUG (dbgs () << " *** Promoted load of argument '" << Arg. getName ()
433
432
<< " ' in function '" << F->getName () << " '\n " );
434
433
} else {
435
- GetElementPtrInst *GEP = cast<GetElementPtrInst>(I-> user_back ());
434
+ GetElementPtrInst *GEP = cast<GetElementPtrInst>(Arg. user_back ());
436
435
assert (!GEP->use_empty () &&
437
436
" GEPs without uses should be cleaned up already" );
438
437
IndicesVector Operands;
@@ -450,7 +449,7 @@ doPromotion(Function *F, SmallPtrSetImpl<Argument *> &ArgsToPromote,
450
449
assert (It != ArgIndices.end () && " GEP not handled??" );
451
450
}
452
451
453
- TheArg->setName (formatv (" {0}.{1:$[.]}.val" , I-> getName (),
452
+ TheArg->setName (formatv (" {0}.{1:$[.]}.val" , Arg. getName (),
454
453
make_range (Operands.begin (), Operands.end ())));
455
454
456
455
LLVM_DEBUG (dbgs () << " *** Promoted agg argument '" << TheArg->getName ()
0 commit comments