@@ -404,9 +404,9 @@ Function *ArgPromotion::DoPromotion(Function *F,
404
404
ParamAttrsVector ParamAttrsVec;
405
405
const ParamAttrsList *PAL = F->getParamAttrs ();
406
406
407
- unsigned index = 1 ;
407
+ unsigned ArgIndex = 1 ;
408
408
for (Function::arg_iterator I = F->arg_begin (), E = F->arg_end (); I != E;
409
- ++I, ++index ) {
409
+ ++I, ++ArgIndex ) {
410
410
if (ByValArgsToTransform.count (I)) {
411
411
// Just add all the struct element types.
412
412
const Type *AgTy = cast<PointerType>(I->getType ())->getElementType ();
@@ -416,7 +416,7 @@ Function *ArgPromotion::DoPromotion(Function *F,
416
416
++NumByValArgsPromoted;
417
417
} else if (!ArgsToPromote.count (I)) {
418
418
Params.push_back (I->getType ());
419
- if (unsigned attrs = PAL ? PAL->getParamAttrs (index ) : 0 )
419
+ if (unsigned attrs = PAL ? PAL->getParamAttrs (ArgIndex ) : 0 )
420
420
ParamAttrsVec.push_back (ParamAttrsWithIndex::get (Params.size (), attrs));
421
421
} else if (I->use_empty ()) {
422
422
++NumArgumentsDead;
@@ -454,10 +454,6 @@ Function *ArgPromotion::DoPromotion(Function *F,
454
454
455
455
const Type *RetTy = FTy->getReturnType ();
456
456
457
- // Recompute the parameter attributes list based on the new arguments for
458
- // the function.
459
- PAL = ParamAttrsList::get (ParamAttrsVec);
460
-
461
457
// Work around LLVM bug PR56: the CWriter cannot emit varargs functions which
462
458
// have zero fixed arguments.
463
459
bool ExtraArgHack = false ;
@@ -472,7 +468,12 @@ Function *ArgPromotion::DoPromotion(Function *F,
472
468
// Create the new function body and insert it into the module...
473
469
Function *NF = new Function (NFTy, F->getLinkage (), F->getName ());
474
470
NF->setCallingConv (F->getCallingConv ());
475
- NF->setParamAttrs (PAL);
471
+
472
+ // Recompute the parameter attributes list based on the new arguments for
473
+ // the function.
474
+ NF->setParamAttrs (ParamAttrsList::get (ParamAttrsVec));
475
+ ParamAttrsVec.clear (); PAL = 0 ;
476
+
476
477
if (F->hasCollector ())
477
478
NF->setCollector (F->getCollector ());
478
479
F->getParent ()->getFunctionList ().insert (F, NF);
@@ -484,18 +485,24 @@ Function *ArgPromotion::DoPromotion(Function *F,
484
485
// Loop over all of the callers of the function, transforming the call sites
485
486
// to pass in the loaded pointers.
486
487
//
487
- std::vector <Value*> Args;
488
+ SmallVector <Value*, 16 > Args;
488
489
while (!F->use_empty ()) {
489
490
CallSite CS = CallSite::get (F->use_back ());
490
491
Instruction *Call = CS.getInstruction ();
491
-
492
+ PAL = CS.getParamAttrs ();
493
+
492
494
// Loop over the operands, inserting GEP and loads in the caller as
493
495
// appropriate.
494
496
CallSite::arg_iterator AI = CS.arg_begin ();
497
+ ArgIndex = 1 ;
495
498
for (Function::arg_iterator I = F->arg_begin (), E = F->arg_end ();
496
- I != E; ++I, ++AI)
499
+ I != E; ++I, ++AI, ++ArgIndex )
497
500
if (!ArgsToPromote.count (I) && !ByValArgsToTransform.count (I)) {
498
501
Args.push_back (*AI); // Unmodified argument
502
+
503
+ if (unsigned Attrs = PAL ? PAL->getParamAttrs (ArgIndex) : 0 )
504
+ ParamAttrsVec.push_back (ParamAttrsWithIndex::get (Args.size (), Attrs));
505
+
499
506
} else if (ByValArgsToTransform.count (I)) {
500
507
// Emit a GEP and load for each element of the struct.
501
508
const Type *AgTy = cast<PointerType>(I->getType ())->getElementType ();
@@ -530,23 +537,27 @@ Function *ArgPromotion::DoPromotion(Function *F,
530
537
Args.push_back (Constant::getNullValue (Type::Int32Ty));
531
538
532
539
// Push any varargs arguments on the list
533
- for (; AI != CS.arg_end (); ++AI)
540
+ for (; AI != CS.arg_end (); ++AI, ++ArgIndex) {
534
541
Args.push_back (*AI);
542
+ if (unsigned Attrs = PAL ? PAL->getParamAttrs (ArgIndex) : 0 )
543
+ ParamAttrsVec.push_back (ParamAttrsWithIndex::get (Args.size (), Attrs));
544
+ }
535
545
536
546
Instruction *New;
537
547
if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) {
538
548
New = new InvokeInst (NF, II->getNormalDest (), II->getUnwindDest (),
539
549
Args.begin (), Args.end (), " " , Call);
540
550
cast<InvokeInst>(New)->setCallingConv (CS.getCallingConv ());
541
- cast<InvokeInst>(New)->setParamAttrs (PAL );
551
+ cast<InvokeInst>(New)->setParamAttrs (ParamAttrsList::get (ParamAttrsVec) );
542
552
} else {
543
553
New = new CallInst (NF, Args.begin (), Args.end (), " " , Call);
544
554
cast<CallInst>(New)->setCallingConv (CS.getCallingConv ());
545
- cast<CallInst>(New)->setParamAttrs (PAL );
555
+ cast<CallInst>(New)->setParamAttrs (ParamAttrsList::get (ParamAttrsVec) );
546
556
if (cast<CallInst>(Call)->isTailCall ())
547
557
cast<CallInst>(New)->setTailCall ();
548
558
}
549
559
Args.clear ();
560
+ ParamAttrsVec.clear ();
550
561
551
562
// Update the alias analysis implementation to know that we are replacing
552
563
// the old call with a new one.
0 commit comments