Make ArgumentPromotion handle recursive functions that pass pointers in their recursi...
[oota-llvm.git] / lib / Transforms / IPO / ArgumentPromotion.cpp
1 //===-- ArgumentPromotion.cpp - Promote by-reference arguments ------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This pass promotes "by reference" arguments to be "by value" arguments.  In
11 // practice, this means looking for internal functions that have pointer
12 // arguments.  If we can prove, through the use of alias analysis, that an
13 // argument is *only* loaded, then we can pass the value into the function
14 // instead of the address of the value.  This can cause recursive simplification
15 // of code and lead to the elimination of allocas (especially in C++ template
16 // code like the STL).
17 //
18 // This pass also handles aggregate arguments that are passed into a function,
19 // scalarizing them if the elements of the aggregate are only loaded.  Note that
20 // we refuse to scalarize aggregates which would require passing in more than
21 // three operands to the function, because we don't want to pass thousands of
22 // operands for a large array or structure!
23 //
24 // Note that this transformation could also be done for arguments that are only
25 // stored to (returning the value instead), but we do not currently handle that
26 // case.  This case would be best handled when and if we start supporting
27 // multiple return values from functions.
28 //
29 //===----------------------------------------------------------------------===//
30
31 #define DEBUG_TYPE "argpromotion"
32 #include "llvm/Transforms/IPO.h"
33 #include "llvm/Constants.h"
34 #include "llvm/DerivedTypes.h"
35 #include "llvm/Module.h"
36 #include "llvm/CallGraphSCCPass.h"
37 #include "llvm/Instructions.h"
38 #include "llvm/Analysis/AliasAnalysis.h"
39 #include "llvm/Analysis/CallGraph.h"
40 #include "llvm/Target/TargetData.h"
41 #include "llvm/Support/CallSite.h"
42 #include "llvm/Support/CFG.h"
43 #include "llvm/Support/Debug.h"
44 #include "llvm/ADT/DepthFirstIterator.h"
45 #include "llvm/ADT/Statistic.h"
46 #include "llvm/ADT/StringExtras.h"
47 #include <iostream>
48 #include <set>
49 using namespace llvm;
50
51 namespace {
52   Statistic<> NumArgumentsPromoted("argpromotion",
53                                    "Number of pointer arguments promoted");
54   Statistic<> NumAggregatesPromoted("argpromotion",
55                                     "Number of aggregate arguments promoted");
56   Statistic<> NumArgumentsDead("argpromotion",
57                                "Number of dead pointer args eliminated");
58
59   /// ArgPromotion - The 'by reference' to 'by value' argument promotion pass.
60   ///
61   struct ArgPromotion : public CallGraphSCCPass {
62     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
63       AU.addRequired<AliasAnalysis>();
64       AU.addRequired<TargetData>();
65       CallGraphSCCPass::getAnalysisUsage(AU);
66     }
67
68     virtual bool runOnSCC(const std::vector<CallGraphNode *> &SCC);
69   private:
70     bool PromoteArguments(CallGraphNode *CGN);
71     bool isSafeToPromoteArgument(Argument *Arg) const;
72     Function *DoPromotion(Function *F, std::vector<Argument*> &ArgsToPromote);
73   };
74
75   RegisterPass<ArgPromotion> X("argpromotion",
76                                "Promote 'by reference' arguments to scalars");
77 }
78
79 ModulePass *llvm::createArgumentPromotionPass() {
80   return new ArgPromotion();
81 }
82
83 bool ArgPromotion::runOnSCC(const std::vector<CallGraphNode *> &SCC) {
84   bool Changed = false, LocalChange;
85
86   do {  // Iterate until we stop promoting from this SCC.
87     LocalChange = false;
88     // Attempt to promote arguments from all functions in this SCC.
89     for (unsigned i = 0, e = SCC.size(); i != e; ++i)
90       LocalChange |= PromoteArguments(SCC[i]);
91     Changed |= LocalChange;               // Remember that we changed something.
92   } while (LocalChange);
93
94   return Changed;
95 }
96
97 /// PromoteArguments - This method checks the specified function to see if there
98 /// are any promotable arguments and if it is safe to promote the function (for
99 /// example, all callers are direct).  If safe to promote some arguments, it
100 /// calls the DoPromotion method.
101 ///
102 bool ArgPromotion::PromoteArguments(CallGraphNode *CGN) {
103   Function *F = CGN->getFunction();
104
105   // Make sure that it is local to this module.
106   if (!F || !F->hasInternalLinkage()) return false;
107
108   // First check: see if there are any pointer arguments!  If not, quick exit.
109   std::vector<Argument*> PointerArgs;
110   for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; ++I)
111     if (isa<PointerType>(I->getType()))
112       PointerArgs.push_back(I);
113   if (PointerArgs.empty()) return false;
114
115   // Second check: make sure that all callers are direct callers.  We can't
116   // transform functions that have indirect callers.
117   for (Value::use_iterator UI = F->use_begin(), E = F->use_end();
118        UI != E; ++UI) {
119     CallSite CS = CallSite::get(*UI);
120     if (!CS.getInstruction())       // "Taking the address" of the function
121       return false;
122
123     // Ensure that this call site is CALLING the function, not passing it as
124     // an argument.
125     for (CallSite::arg_iterator AI = CS.arg_begin(), E = CS.arg_end();
126          AI != E; ++AI)
127       if (*AI == F) return false;   // Passing the function address in!
128   }
129
130   // Check to see which arguments are promotable.  If an argument is not
131   // promotable, remove it from the PointerArgs vector.
132   for (unsigned i = 0; i != PointerArgs.size(); ++i)
133     if (!isSafeToPromoteArgument(PointerArgs[i])) {
134       std::swap(PointerArgs[i--], PointerArgs.back());
135       PointerArgs.pop_back();
136     }
137
138   // No promotable pointer arguments.
139   if (PointerArgs.empty()) return false;
140
141   // Okay, promote all of the arguments are rewrite the callees!
142   Function *NewF = DoPromotion(F, PointerArgs);
143
144   // Update the call graph to know that the old function is gone.
145   getAnalysis<CallGraph>().changeFunction(F, NewF);
146   return true;
147 }
148
149 /// IsAlwaysValidPointer - Return true if the specified pointer is always legal
150 /// to load.
151 static bool IsAlwaysValidPointer(Value *V) {
152   if (isa<AllocaInst>(V) || isa<GlobalVariable>(V)) return true;
153   if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(V))
154     return IsAlwaysValidPointer(GEP->getOperand(0));
155   if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
156     if (CE->getOpcode() == Instruction::GetElementPtr)
157       return IsAlwaysValidPointer(CE->getOperand(0));
158
159   return false;
160 }
161
162 /// AllCalleesPassInValidPointerForArgument - Return true if we can prove that
163 /// all callees pass in a valid pointer for the specified function argument.
164 static bool AllCalleesPassInValidPointerForArgument(Argument *Arg) {
165   Function *Callee = Arg->getParent();
166
167   unsigned ArgNo = std::distance(Callee->arg_begin(), Function::arg_iterator(Arg));
168
169   // Look at all call sites of the function.  At this pointer we know we only
170   // have direct callees.
171   for (Value::use_iterator UI = Callee->use_begin(), E = Callee->use_end();
172        UI != E; ++UI) {
173     CallSite CS = CallSite::get(*UI);
174     assert(CS.getInstruction() && "Should only have direct calls!");
175
176     if (!IsAlwaysValidPointer(CS.getArgument(ArgNo)))
177       return false;
178   }
179   return true;
180 }
181
182
183 /// isSafeToPromoteArgument - As you might guess from the name of this method,
184 /// it checks to see if it is both safe and useful to promote the argument.
185 /// This method limits promotion of aggregates to only promote up to three
186 /// elements of the aggregate in order to avoid exploding the number of
187 /// arguments passed in.
188 bool ArgPromotion::isSafeToPromoteArgument(Argument *Arg) const {
189   AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
190
191   // We can only promote this argument if all of the uses are loads, or are GEP
192   // instructions (with constant indices) that are subsequently loaded.
193   bool HasLoadInEntryBlock = false;
194   BasicBlock *EntryBlock = Arg->getParent()->begin();
195   std::vector<LoadInst*> Loads;
196   std::vector<std::vector<ConstantInt*> > GEPIndices;
197   for (Value::use_iterator UI = Arg->use_begin(), E = Arg->use_end();
198        UI != E; ++UI)
199     if (LoadInst *LI = dyn_cast<LoadInst>(*UI)) {
200       if (LI->isVolatile()) return false;  // Don't hack volatile loads
201       Loads.push_back(LI);
202       HasLoadInEntryBlock |= LI->getParent() == EntryBlock;
203     } else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(*UI)) {
204       if (GEP->use_empty()) {
205         // Dead GEP's cause trouble later.  Just remove them if we run into
206         // them.
207         getAnalysis<AliasAnalysis>().deleteValue(GEP);
208         GEP->getParent()->getInstList().erase(GEP);
209         return isSafeToPromoteArgument(Arg);
210       }
211       // Ensure that all of the indices are constants.
212       std::vector<ConstantInt*> Operands;
213       for (unsigned i = 1, e = GEP->getNumOperands(); i != e; ++i)
214         if (ConstantInt *C = dyn_cast<ConstantInt>(GEP->getOperand(i)))
215           Operands.push_back(C);
216         else
217           return false;  // Not a constant operand GEP!
218
219       // Ensure that the only users of the GEP are load instructions.
220       for (Value::use_iterator UI = GEP->use_begin(), E = GEP->use_end();
221            UI != E; ++UI)
222         if (LoadInst *LI = dyn_cast<LoadInst>(*UI)) {
223           if (LI->isVolatile()) return false;  // Don't hack volatile loads
224           Loads.push_back(LI);
225           HasLoadInEntryBlock |= LI->getParent() == EntryBlock;
226         } else {
227           return false;
228         }
229
230       // See if there is already a GEP with these indices.  If not, check to
231       // make sure that we aren't promoting too many elements.  If so, nothing
232       // to do.
233       if (std::find(GEPIndices.begin(), GEPIndices.end(), Operands) ==
234           GEPIndices.end()) {
235         if (GEPIndices.size() == 3) {
236           DEBUG(std::cerr << "argpromotion disable promoting argument '"
237                 << Arg->getName() << "' because it would require adding more "
238                 << "than 3 arguments to the function.\n");
239           // We limit aggregate promotion to only promoting up to three elements
240           // of the aggregate.
241           return false;
242         }
243         GEPIndices.push_back(Operands);
244       }
245     } else if (CallInst* CI = dyn_cast<CallInst>(*UI)) {
246       // Is this a recursive call?
247       if (CI->getCalledFunction() != Arg->getParent())
248         return false;
249       
250       // Find out what position argument we're dealing with.
251       unsigned Position = 0;
252       Function::arg_iterator ArgPos = Arg->getParent()->arg_begin();
253       while (Arg != ArgPos) {
254         assert(ArgPos != Arg->getParent()->arg_end() &&
255                "Arg not in parent's arg list?");
256         Position++;
257         ArgPos++;
258       }
259       
260       // We only know that the call is safe if it's passing the argument in
261       // the same position that it came in at.
262       if (UI.getOperandNo() != Position+1)
263         return false;
264     } else {
265       return false;  // Not a load or a GEP.
266     }
267
268   if (Loads.empty()) return true;  // No users, this is a dead argument.
269
270   // If we decide that we want to promote this argument, the value is going to
271   // be unconditionally loaded in all callees.  This is only safe to do if the
272   // pointer was going to be unconditionally loaded anyway (i.e. there is a load
273   // of the pointer in the entry block of the function) or if we can prove that
274   // all pointers passed in are always to legal locations (for example, no null
275   // pointers are passed in, no pointers to free'd memory, etc).
276   if (!HasLoadInEntryBlock && !AllCalleesPassInValidPointerForArgument(Arg))
277     return false;   // Cannot prove that this is safe!!
278
279   // Okay, now we know that the argument is only used by load instructions and
280   // it is safe to unconditionally load the pointer.  Use alias analysis to
281   // check to see if the pointer is guaranteed to not be modified from entry of
282   // the function to each of the load instructions.
283   Function &F = *Arg->getParent();
284
285   // Because there could be several/many load instructions, remember which
286   // blocks we know to be transparent to the load.
287   std::set<BasicBlock*> TranspBlocks;
288   
289   TargetData &TD = getAnalysis<TargetData>();
290
291   for (unsigned i = 0, e = Loads.size(); i != e; ++i) {
292     // Check to see if the load is invalidated from the start of the block to
293     // the load itself.
294     LoadInst *Load = Loads[i];
295     BasicBlock *BB = Load->getParent();
296
297     const PointerType *LoadTy =
298       cast<PointerType>(Load->getOperand(0)->getType());
299     unsigned LoadSize = (unsigned)TD.getTypeSize(LoadTy->getElementType());
300
301     if (AA.canInstructionRangeModify(BB->front(), *Load, Arg, LoadSize))
302       return false;  // Pointer is invalidated!
303
304     // Now check every path from the entry block to the load for transparency.
305     // To do this, we perform a depth first search on the inverse CFG from the
306     // loading block.
307     for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
308       for (idf_ext_iterator<BasicBlock*> I = idf_ext_begin(*PI, TranspBlocks),
309              E = idf_ext_end(*PI, TranspBlocks); I != E; ++I)
310         if (AA.canBasicBlockModify(**I, Arg, LoadSize))
311           return false;
312   }
313
314   // If the path from the entry of the function to each load is free of
315   // instructions that potentially invalidate the load, we can make the
316   // transformation!
317   return true;
318 }
319
320 namespace {
321   /// GEPIdxComparator - Provide a strong ordering for GEP indices.  All Value*
322   /// elements are instances of ConstantInt.
323   ///
324   struct GEPIdxComparator {
325     bool operator()(const std::vector<Value*> &LHS,
326                     const std::vector<Value*> &RHS) const {
327       unsigned idx = 0;
328       for (; idx < LHS.size() && idx < RHS.size(); ++idx) {
329         if (LHS[idx] != RHS[idx]) {
330           return cast<ConstantInt>(LHS[idx])->getRawValue() <
331                  cast<ConstantInt>(RHS[idx])->getRawValue();
332         }
333       }
334
335       // Return less than if we ran out of stuff in LHS and we didn't run out of
336       // stuff in RHS.
337       return idx == LHS.size() && idx != RHS.size();
338     }
339   };
340 }
341
342
343 /// DoPromotion - This method actually performs the promotion of the specified
344 /// arguments, and returns the new function.  At this point, we know that it's
345 /// safe to do so.
346 Function *ArgPromotion::DoPromotion(Function *F,
347                                     std::vector<Argument*> &Args2Prom) {
348   std::set<Argument*> ArgsToPromote(Args2Prom.begin(), Args2Prom.end());
349
350   // Start by computing a new prototype for the function, which is the same as
351   // the old function, but has modified arguments.
352   const FunctionType *FTy = F->getFunctionType();
353   std::vector<const Type*> Params;
354
355   typedef std::set<std::vector<Value*>, GEPIdxComparator> ScalarizeTable;
356
357   // ScalarizedElements - If we are promoting a pointer that has elements
358   // accessed out of it, keep track of which elements are accessed so that we
359   // can add one argument for each.
360   //
361   // Arguments that are directly loaded will have a zero element value here, to
362   // handle cases where there are both a direct load and GEP accesses.
363   //
364   std::map<Argument*, ScalarizeTable> ScalarizedElements;
365
366   // OriginalLoads - Keep track of a representative load instruction from the
367   // original function so that we can tell the alias analysis implementation
368   // what the new GEP/Load instructions we are inserting look like.
369   std::map<std::vector<Value*>, LoadInst*> OriginalLoads;
370
371   for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; ++I)
372     if (!ArgsToPromote.count(I)) {
373       Params.push_back(I->getType());
374     } else if (I->use_empty()) {
375       ++NumArgumentsDead;
376     } else {
377       // Okay, this is being promoted.  Check to see if there are any GEP uses
378       // of the argument.
379       ScalarizeTable &ArgIndices = ScalarizedElements[I];
380       for (Value::use_iterator UI = I->use_begin(), E = I->use_end(); UI != E;
381            ++UI) {
382         Instruction *User = cast<Instruction>(*UI);
383         if (!isa<CallInst>(User)) {
384           assert(isa<LoadInst>(User) || isa<GetElementPtrInst>(User));
385           std::vector<Value*> Indices(User->op_begin()+1, User->op_end());
386           ArgIndices.insert(Indices);
387           LoadInst *OrigLoad;
388           if (LoadInst *L = dyn_cast<LoadInst>(User))
389             OrigLoad = L;
390           else
391             OrigLoad = cast<LoadInst>(User->use_back());
392           OriginalLoads[Indices] = OrigLoad;
393         }
394       }
395
396       // Add a parameter to the function for each element passed in.
397       for (ScalarizeTable::iterator SI = ArgIndices.begin(),
398              E = ArgIndices.end(); SI != E; ++SI)
399         Params.push_back(GetElementPtrInst::getIndexedType(I->getType(), *SI));
400
401       if (ArgIndices.size() == 1 && ArgIndices.begin()->empty())
402         ++NumArgumentsPromoted;
403       else
404         ++NumAggregatesPromoted;
405     }
406
407   const Type *RetTy = FTy->getReturnType();
408
409   // Work around LLVM bug PR56: the CWriter cannot emit varargs functions which
410   // have zero fixed arguments.
411   bool ExtraArgHack = false;
412   if (Params.empty() && FTy->isVarArg()) {
413     ExtraArgHack = true;
414     Params.push_back(Type::IntTy);
415   }
416   FunctionType *NFTy = FunctionType::get(RetTy, Params, FTy->isVarArg());
417
418    // Create the new function body and insert it into the module...
419   Function *NF = new Function(NFTy, F->getLinkage(), F->getName());
420   NF->setCallingConv(F->getCallingConv());
421   F->getParent()->getFunctionList().insert(F, NF);
422
423   // Get the alias analysis information that we need to update to reflect our
424   // changes.
425   AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
426
427   // Loop over all of the callers of the function, transforming the call sites
428   // to pass in the loaded pointers.
429   //
430   std::vector<Value*> Args;
431   while (!F->use_empty()) {
432     CallSite CS = CallSite::get(F->use_back());
433     Instruction *Call = CS.getInstruction();
434
435     // Loop over the operands, inserting GEP and loads in the caller as
436     // appropriate.
437     CallSite::arg_iterator AI = CS.arg_begin();
438     for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end();
439          I != E; ++I, ++AI)
440       if (!ArgsToPromote.count(I))
441         Args.push_back(*AI);          // Unmodified argument
442       else if (!I->use_empty()) {
443         // Non-dead argument: insert GEPs and loads as appropriate.
444         ScalarizeTable &ArgIndices = ScalarizedElements[I];
445         for (ScalarizeTable::iterator SI = ArgIndices.begin(),
446                E = ArgIndices.end(); SI != E; ++SI) {
447           Value *V = *AI;
448           LoadInst *OrigLoad = OriginalLoads[*SI];
449           if (!SI->empty()) {
450             V = new GetElementPtrInst(V, *SI, V->getName()+".idx", Call);
451             AA.copyValue(OrigLoad->getOperand(0), V);
452           }
453           Args.push_back(new LoadInst(V, V->getName()+".val", Call));
454           AA.copyValue(OrigLoad, Args.back());
455         }
456       }
457
458     if (ExtraArgHack)
459       Args.push_back(Constant::getNullValue(Type::IntTy));
460
461     // Push any varargs arguments on the list
462     for (; AI != CS.arg_end(); ++AI)
463       Args.push_back(*AI);
464
465     Instruction *New;
466     if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) {
467       New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(),
468                            Args, "", Call);
469       cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv());
470     } else {
471       New = new CallInst(NF, Args, "", Call);
472       cast<CallInst>(New)->setCallingConv(CS.getCallingConv());
473       if (cast<CallInst>(Call)->isTailCall())
474         cast<CallInst>(New)->setTailCall();
475     }
476     Args.clear();
477
478     // Update the alias analysis implementation to know that we are replacing
479     // the old call with a new one.
480     AA.replaceWithNewValue(Call, New);
481
482     if (!Call->use_empty()) {
483       Call->replaceAllUsesWith(New);
484       std::string Name = Call->getName();
485       Call->setName("");
486       New->setName(Name);
487     }
488
489     // Finally, remove the old call from the program, reducing the use-count of
490     // F.
491     Call->getParent()->getInstList().erase(Call);
492   }
493
494   // Since we have now created the new function, splice the body of the old
495   // function right into the new function, leaving the old rotting hulk of the
496   // function empty.
497   NF->getBasicBlockList().splice(NF->begin(), F->getBasicBlockList());
498
499   // Loop over the argument list, transfering uses of the old arguments over to
500   // the new arguments, also transfering over the names as well.
501   //
502   for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(), I2 = NF->arg_begin();
503        I != E; ++I)
504     if (!ArgsToPromote.count(I)) {
505       // If this is an unmodified argument, move the name and users over to the
506       // new version.
507       I->replaceAllUsesWith(I2);
508       I2->setName(I->getName());
509       AA.replaceWithNewValue(I, I2);
510       ++I2;
511     } else if (I->use_empty()) {
512       AA.deleteValue(I);
513     } else {
514       // Otherwise, if we promoted this argument, then all users are load
515       // instructions, and all loads should be using the new argument that we
516       // added.
517       ScalarizeTable &ArgIndices = ScalarizedElements[I];
518
519       while (!I->use_empty()) {
520         if (LoadInst *LI = dyn_cast<LoadInst>(I->use_back())) {
521           assert(ArgIndices.begin()->empty() &&
522                  "Load element should sort to front!");
523           I2->setName(I->getName()+".val");
524           LI->replaceAllUsesWith(I2);
525           AA.replaceWithNewValue(LI, I2);
526           LI->getParent()->getInstList().erase(LI);
527           DEBUG(std::cerr << "*** Promoted load of argument '" << I->getName()
528                           << "' in function '" << F->getName() << "'\n");
529         } else {
530           GetElementPtrInst *GEP = cast<GetElementPtrInst>(I->use_back());
531           std::vector<Value*> Operands(GEP->op_begin()+1, GEP->op_end());
532
533           unsigned ArgNo = 0;
534           Function::arg_iterator TheArg = I2;
535           for (ScalarizeTable::iterator It = ArgIndices.begin();
536                *It != Operands; ++It, ++TheArg) {
537             assert(It != ArgIndices.end() && "GEP not handled??");
538           }
539
540           std::string NewName = I->getName();
541           for (unsigned i = 0, e = Operands.size(); i != e; ++i)
542             if (ConstantInt *CI = dyn_cast<ConstantInt>(Operands[i]))
543               NewName += "."+itostr((int64_t)CI->getRawValue());
544             else
545               NewName += ".x";
546           TheArg->setName(NewName+".val");
547
548           DEBUG(std::cerr << "*** Promoted agg argument '" << TheArg->getName()
549                           << "' of function '" << F->getName() << "'\n");
550
551           // All of the uses must be load instructions.  Replace them all with
552           // the argument specified by ArgNo.
553           while (!GEP->use_empty()) {
554             LoadInst *L = cast<LoadInst>(GEP->use_back());
555             L->replaceAllUsesWith(TheArg);
556             AA.replaceWithNewValue(L, TheArg);
557             L->getParent()->getInstList().erase(L);
558           }
559           AA.deleteValue(GEP);
560           GEP->getParent()->getInstList().erase(GEP);
561         }
562       }
563
564       // Increment I2 past all of the arguments added for this promoted pointer.
565       for (unsigned i = 0, e = ArgIndices.size(); i != e; ++i)
566         ++I2;
567     }
568
569   // Notify the alias analysis implementation that we inserted a new argument.
570   if (ExtraArgHack)
571     AA.copyValue(Constant::getNullValue(Type::IntTy), NF->arg_begin());
572
573
574   // Tell the alias analysis that the old function is about to disappear.
575   AA.replaceWithNewValue(F, NF);
576
577   // Now that the old function is dead, delete it.
578   F->getParent()->getFunctionList().erase(F);
579   return NF;
580 }