LLVM API Documentation

ArgumentPromotion.cpp

Go to the documentation of this file.
00001 //===-- ArgumentPromotion.cpp - Promote by-reference arguments ------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This pass promotes "by reference" arguments to be "by value" arguments.  In
00011 // practice, this means looking for internal functions that have pointer
00012 // arguments.  If we can prove, through the use of alias analysis, that an
00013 // argument is *only* loaded, then we can pass the value into the function
00014 // instead of the address of the value.  This can cause recursive simplification
00015 // of code and lead to the elimination of allocas (especially in C++ template
00016 // code like the STL).
00017 //
00018 // This pass also handles aggregate arguments that are passed into a function,
00019 // scalarizing them if the elements of the aggregate are only loaded.  Note that
00020 // we refuse to scalarize aggregates which would require passing in more than
00021 // three operands to the function, because we don't want to pass thousands of
00022 // operands for a large array or structure!
00023 //
00024 // Note that this transformation could also be done for arguments that are only
00025 // stored to (returning the value instead), but we do not currently handle that
00026 // case.  This case would be best handled when and if we start supporting
00027 // multiple return values from functions.
00028 //
00029 //===----------------------------------------------------------------------===//
00030 
00031 #define DEBUG_TYPE "argpromotion"
00032 #include "llvm/Transforms/IPO.h"
00033 #include "llvm/Constants.h"
00034 #include "llvm/DerivedTypes.h"
00035 #include "llvm/Module.h"
00036 #include "llvm/CallGraphSCCPass.h"
00037 #include "llvm/Instructions.h"
00038 #include "llvm/Analysis/AliasAnalysis.h"
00039 #include "llvm/Analysis/CallGraph.h"
00040 #include "llvm/Target/TargetData.h"
00041 #include "llvm/Support/CallSite.h"
00042 #include "llvm/Support/CFG.h"
00043 #include "llvm/Support/Debug.h"
00044 #include "llvm/ADT/DepthFirstIterator.h"
00045 #include "llvm/ADT/Statistic.h"
00046 #include "llvm/ADT/StringExtras.h"
00047 #include <iostream>
00048 #include <set>
00049 using namespace llvm;
00050 
00051 namespace {
00052   Statistic<> NumArgumentsPromoted("argpromotion",
00053                                    "Number of pointer arguments promoted");
00054   Statistic<> NumAggregatesPromoted("argpromotion",
00055                                     "Number of aggregate arguments promoted");
00056   Statistic<> NumArgumentsDead("argpromotion",
00057                                "Number of dead pointer args eliminated");
00058 
00059   /// ArgPromotion - The 'by reference' to 'by value' argument promotion pass.
00060   ///
00061   struct ArgPromotion : public CallGraphSCCPass {
00062     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
00063       AU.addRequired<AliasAnalysis>();
00064       AU.addRequired<TargetData>();
00065       CallGraphSCCPass::getAnalysisUsage(AU);
00066     }
00067 
00068     virtual bool runOnSCC(const std::vector<CallGraphNode *> &SCC);
00069   private:
00070     bool PromoteArguments(CallGraphNode *CGN);
00071     bool isSafeToPromoteArgument(Argument *Arg) const;
00072     Function *DoPromotion(Function *F, std::vector<Argument*> &ArgsToPromote);
00073   };
00074 
00075   RegisterOpt<ArgPromotion> X("argpromotion",
00076                               "Promote 'by reference' arguments to scalars");
00077 }
00078 
00079 ModulePass *llvm::createArgumentPromotionPass() {
00080   return new ArgPromotion();
00081 }
00082 
00083 bool ArgPromotion::runOnSCC(const std::vector<CallGraphNode *> &SCC) {
00084   bool Changed = false, LocalChange;
00085 
00086   do {  // Iterate until we stop promoting from this SCC.
00087     LocalChange = false;
00088     // Attempt to promote arguments from all functions in this SCC.
00089     for (unsigned i = 0, e = SCC.size(); i != e; ++i)
00090       LocalChange |= PromoteArguments(SCC[i]);
00091     Changed |= LocalChange;               // Remember that we changed something.
00092   } while (LocalChange);
00093 
00094   return Changed;
00095 }
00096 
00097 /// PromoteArguments - This method checks the specified function to see if there
00098 /// are any promotable arguments and if it is safe to promote the function (for
00099 /// example, all callers are direct).  If safe to promote some arguments, it
00100 /// calls the DoPromotion method.
00101 ///
00102 bool ArgPromotion::PromoteArguments(CallGraphNode *CGN) {
00103   Function *F = CGN->getFunction();
00104 
00105   // Make sure that it is local to this module.
00106   if (!F || !F->hasInternalLinkage()) return false;
00107 
00108   // First check: see if there are any pointer arguments!  If not, quick exit.
00109   std::vector<Argument*> PointerArgs;
00110   for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; ++I)
00111     if (isa<PointerType>(I->getType()))
00112       PointerArgs.push_back(I);
00113   if (PointerArgs.empty()) return false;
00114 
00115   // Second check: make sure that all callers are direct callers.  We can't
00116   // transform functions that have indirect callers.
00117   for (Value::use_iterator UI = F->use_begin(), E = F->use_end();
00118        UI != E; ++UI) {
00119     CallSite CS = CallSite::get(*UI);
00120     if (!CS.getInstruction())       // "Taking the address" of the function
00121       return false;
00122 
00123     // Ensure that this call site is CALLING the function, not passing it as
00124     // an argument.
00125     for (CallSite::arg_iterator AI = CS.arg_begin(), E = CS.arg_end();
00126          AI != E; ++AI)
00127       if (*AI == F) return false;   // Passing the function address in!
00128   }
00129 
00130   // Check to see which arguments are promotable.  If an argument is not
00131   // promotable, remove it from the PointerArgs vector.
00132   for (unsigned i = 0; i != PointerArgs.size(); ++i)
00133     if (!isSafeToPromoteArgument(PointerArgs[i])) {
00134       std::swap(PointerArgs[i--], PointerArgs.back());
00135       PointerArgs.pop_back();
00136     }
00137 
00138   // No promotable pointer arguments.
00139   if (PointerArgs.empty()) return false;
00140 
00141   // Okay, promote all of the arguments are rewrite the callees!
00142   Function *NewF = DoPromotion(F, PointerArgs);
00143 
00144   // Update the call graph to know that the old function is gone.
00145   getAnalysis<CallGraph>().changeFunction(F, NewF);
00146   return true;
00147 }
00148 
00149 /// IsAlwaysValidPointer - Return true if the specified pointer is always legal
00150 /// to load.
00151 static bool IsAlwaysValidPointer(Value *V) {
00152   if (isa<AllocaInst>(V) || isa<GlobalVariable>(V)) return true;
00153   if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(V))
00154     return IsAlwaysValidPointer(GEP->getOperand(0));
00155   if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
00156     if (CE->getOpcode() == Instruction::GetElementPtr)
00157       return IsAlwaysValidPointer(CE->getOperand(0));
00158 
00159   return false;
00160 }
00161 
00162 /// AllCalleesPassInValidPointerForArgument - Return true if we can prove that
00163 /// all callees pass in a valid pointer for the specified function argument.
00164 static bool AllCalleesPassInValidPointerForArgument(Argument *Arg) {
00165   Function *Callee = Arg->getParent();
00166 
00167   unsigned ArgNo = std::distance(Callee->arg_begin(), Function::arg_iterator(Arg));
00168 
00169   // Look at all call sites of the function.  At this pointer we know we only
00170   // have direct callees.
00171   for (Value::use_iterator UI = Callee->use_begin(), E = Callee->use_end();
00172        UI != E; ++UI) {
00173     CallSite CS = CallSite::get(*UI);
00174     assert(CS.getInstruction() && "Should only have direct calls!");
00175 
00176     if (!IsAlwaysValidPointer(CS.getArgument(ArgNo)))
00177       return false;
00178   }
00179   return true;
00180 }
00181 
00182 
00183 /// isSafeToPromoteArgument - As you might guess from the name of this method,
00184 /// it checks to see if it is both safe and useful to promote the argument.
00185 /// This method limits promotion of aggregates to only promote up to three
00186 /// elements of the aggregate in order to avoid exploding the number of
00187 /// arguments passed in.
00188 bool ArgPromotion::isSafeToPromoteArgument(Argument *Arg) const {
00189   // We can only promote this argument if all of the uses are loads, or are GEP
00190   // instructions (with constant indices) that are subsequently loaded.
00191   bool HasLoadInEntryBlock = false;
00192   BasicBlock *EntryBlock = Arg->getParent()->begin();
00193   std::vector<LoadInst*> Loads;
00194   std::vector<std::vector<ConstantInt*> > GEPIndices;
00195   for (Value::use_iterator UI = Arg->use_begin(), E = Arg->use_end();
00196        UI != E; ++UI)
00197     if (LoadInst *LI = dyn_cast<LoadInst>(*UI)) {
00198       if (LI->isVolatile()) return false;  // Don't hack volatile loads
00199       Loads.push_back(LI);
00200       HasLoadInEntryBlock |= LI->getParent() == EntryBlock;
00201     } else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(*UI)) {
00202       if (GEP->use_empty()) {
00203         // Dead GEP's cause trouble later.  Just remove them if we run into
00204         // them.
00205         getAnalysis<AliasAnalysis>().deleteValue(GEP);
00206         GEP->getParent()->getInstList().erase(GEP);
00207         return isSafeToPromoteArgument(Arg);
00208       }
00209       // Ensure that all of the indices are constants.
00210       std::vector<ConstantInt*> Operands;
00211       for (unsigned i = 1, e = GEP->getNumOperands(); i != e; ++i)
00212         if (ConstantInt *C = dyn_cast<ConstantInt>(GEP->getOperand(i)))
00213           Operands.push_back(C);
00214         else
00215           return false;  // Not a constant operand GEP!
00216 
00217       // Ensure that the only users of the GEP are load instructions.
00218       for (Value::use_iterator UI = GEP->use_begin(), E = GEP->use_end();
00219            UI != E; ++UI)
00220         if (LoadInst *LI = dyn_cast<LoadInst>(*UI)) {
00221           if (LI->isVolatile()) return false;  // Don't hack volatile loads
00222           Loads.push_back(LI);
00223           HasLoadInEntryBlock |= LI->getParent() == EntryBlock;
00224         } else {
00225           return false;
00226         }
00227 
00228       // See if there is already a GEP with these indices.  If not, check to
00229       // make sure that we aren't promoting too many elements.  If so, nothing
00230       // to do.
00231       if (std::find(GEPIndices.begin(), GEPIndices.end(), Operands) ==
00232           GEPIndices.end()) {
00233         if (GEPIndices.size() == 3) {
00234           DEBUG(std::cerr << "argpromotion disable promoting argument '"
00235                 << Arg->getName() << "' because it would require adding more "
00236                 << "than 3 arguments to the function.\n");
00237           // We limit aggregate promotion to only promoting up to three elements
00238           // of the aggregate.
00239           return false;
00240         }
00241         GEPIndices.push_back(Operands);
00242       }
00243     } else {
00244       return false;  // Not a load or a GEP.
00245     }
00246 
00247   if (Loads.empty()) return true;  // No users, this is a dead argument.
00248 
00249   // If we decide that we want to promote this argument, the value is going to
00250   // be unconditionally loaded in all callees.  This is only safe to do if the
00251   // pointer was going to be unconditionally loaded anyway (i.e. there is a load
00252   // of the pointer in the entry block of the function) or if we can prove that
00253   // all pointers passed in are always to legal locations (for example, no null
00254   // pointers are passed in, no pointers to free'd memory, etc).
00255   if (!HasLoadInEntryBlock && !AllCalleesPassInValidPointerForArgument(Arg))
00256     return false;   // Cannot prove that this is safe!!
00257 
00258   // Okay, now we know that the argument is only used by load instructions and
00259   // it is safe to unconditionally load the pointer.  Use alias analysis to
00260   // check to see if the pointer is guaranteed to not be modified from entry of
00261   // the function to each of the load instructions.
00262   Function &F = *Arg->getParent();
00263 
00264   // Because there could be several/many load instructions, remember which
00265   // blocks we know to be transparent to the load.
00266   std::set<BasicBlock*> TranspBlocks;
00267 
00268   AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
00269   TargetData &TD = getAnalysis<TargetData>();
00270 
00271   for (unsigned i = 0, e = Loads.size(); i != e; ++i) {
00272     // Check to see if the load is invalidated from the start of the block to
00273     // the load itself.
00274     LoadInst *Load = Loads[i];
00275     BasicBlock *BB = Load->getParent();
00276 
00277     const PointerType *LoadTy =
00278       cast<PointerType>(Load->getOperand(0)->getType());
00279     unsigned LoadSize = (unsigned)TD.getTypeSize(LoadTy->getElementType());
00280 
00281     if (AA.canInstructionRangeModify(BB->front(), *Load, Arg, LoadSize))
00282       return false;  // Pointer is invalidated!
00283 
00284     // Now check every path from the entry block to the load for transparency.
00285     // To do this, we perform a depth first search on the inverse CFG from the
00286     // loading block.
00287     for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
00288       for (idf_ext_iterator<BasicBlock*> I = idf_ext_begin(*PI, TranspBlocks),
00289              E = idf_ext_end(*PI, TranspBlocks); I != E; ++I)
00290         if (AA.canBasicBlockModify(**I, Arg, LoadSize))
00291           return false;
00292   }
00293 
00294   // If the path from the entry of the function to each load is free of
00295   // instructions that potentially invalidate the load, we can make the
00296   // transformation!
00297   return true;
00298 }
00299 
00300 namespace {
00301   /// GEPIdxComparator - Provide a strong ordering for GEP indices.  All Value*
00302   /// elements are instances of ConstantInt.
00303   ///
00304   struct GEPIdxComparator {
00305     bool operator()(const std::vector<Value*> &LHS,
00306                     const std::vector<Value*> &RHS) const {
00307       unsigned idx = 0;
00308       for (; idx < LHS.size() && idx < RHS.size(); ++idx) {
00309         if (LHS[idx] != RHS[idx]) {
00310           return cast<ConstantInt>(LHS[idx])->getRawValue() <
00311                  cast<ConstantInt>(RHS[idx])->getRawValue();
00312         }
00313       }
00314 
00315       // Return less than if we ran out of stuff in LHS and we didn't run out of
00316       // stuff in RHS.
00317       return idx == LHS.size() && idx != RHS.size();
00318     }
00319   };
00320 }
00321 
00322 
00323 /// DoPromotion - This method actually performs the promotion of the specified
00324 /// arguments, and returns the new function.  At this point, we know that it's
00325 /// safe to do so.
00326 Function *ArgPromotion::DoPromotion(Function *F,
00327                                     std::vector<Argument*> &Args2Prom) {
00328   std::set<Argument*> ArgsToPromote(Args2Prom.begin(), Args2Prom.end());
00329 
00330   // Start by computing a new prototype for the function, which is the same as
00331   // the old function, but has modified arguments.
00332   const FunctionType *FTy = F->getFunctionType();
00333   std::vector<const Type*> Params;
00334 
00335   typedef std::set<std::vector<Value*>, GEPIdxComparator> ScalarizeTable;
00336 
00337   // ScalarizedElements - If we are promoting a pointer that has elements
00338   // accessed out of it, keep track of which elements are accessed so that we
00339   // can add one argument for each.
00340   //
00341   // Arguments that are directly loaded will have a zero element value here, to
00342   // handle cases where there are both a direct load and GEP accesses.
00343   //
00344   std::map<Argument*, ScalarizeTable> ScalarizedElements;
00345 
00346   // OriginalLoads - Keep track of a representative load instruction from the
00347   // original function so that we can tell the alias analysis implementation
00348   // what the new GEP/Load instructions we are inserting look like.
00349   std::map<std::vector<Value*>, LoadInst*> OriginalLoads;
00350 
00351   for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; ++I)
00352     if (!ArgsToPromote.count(I)) {
00353       Params.push_back(I->getType());
00354     } else if (I->use_empty()) {
00355       ++NumArgumentsDead;
00356     } else {
00357       // Okay, this is being promoted.  Check to see if there are any GEP uses
00358       // of the argument.
00359       ScalarizeTable &ArgIndices = ScalarizedElements[I];
00360       for (Value::use_iterator UI = I->use_begin(), E = I->use_end(); UI != E;
00361            ++UI) {
00362         Instruction *User = cast<Instruction>(*UI);
00363         assert(isa<LoadInst>(User) || isa<GetElementPtrInst>(User));
00364         std::vector<Value*> Indices(User->op_begin()+1, User->op_end());
00365         ArgIndices.insert(Indices);
00366         LoadInst *OrigLoad;
00367         if (LoadInst *L = dyn_cast<LoadInst>(User))
00368           OrigLoad = L;
00369         else
00370           OrigLoad = cast<LoadInst>(User->use_back());
00371         OriginalLoads[Indices] = OrigLoad;
00372       }
00373 
00374       // Add a parameter to the function for each element passed in.
00375       for (ScalarizeTable::iterator SI = ArgIndices.begin(),
00376              E = ArgIndices.end(); SI != E; ++SI)
00377         Params.push_back(GetElementPtrInst::getIndexedType(I->getType(), *SI));
00378 
00379       if (ArgIndices.size() == 1 && ArgIndices.begin()->empty())
00380         ++NumArgumentsPromoted;
00381       else
00382         ++NumAggregatesPromoted;
00383     }
00384 
00385   const Type *RetTy = FTy->getReturnType();
00386 
00387   // Work around LLVM bug PR56: the CWriter cannot emit varargs functions which
00388   // have zero fixed arguments.
00389   bool ExtraArgHack = false;
00390   if (Params.empty() && FTy->isVarArg()) {
00391     ExtraArgHack = true;
00392     Params.push_back(Type::IntTy);
00393   }
00394   FunctionType *NFTy = FunctionType::get(RetTy, Params, FTy->isVarArg());
00395 
00396    // Create the new function body and insert it into the module...
00397   Function *NF = new Function(NFTy, F->getLinkage(), F->getName());
00398   NF->setCallingConv(F->getCallingConv());
00399   F->getParent()->getFunctionList().insert(F, NF);
00400 
00401   // Get the alias analysis information that we need to update to reflect our
00402   // changes.
00403   AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
00404 
00405   // Loop over all of the callers of the function, transforming the call sites
00406   // to pass in the loaded pointers.
00407   //
00408   std::vector<Value*> Args;
00409   while (!F->use_empty()) {
00410     CallSite CS = CallSite::get(F->use_back());
00411     Instruction *Call = CS.getInstruction();
00412 
00413     // Loop over the operands, inserting GEP and loads in the caller as
00414     // appropriate.
00415     CallSite::arg_iterator AI = CS.arg_begin();
00416     for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end();
00417          I != E; ++I, ++AI)
00418       if (!ArgsToPromote.count(I))
00419         Args.push_back(*AI);          // Unmodified argument
00420       else if (!I->use_empty()) {
00421         // Non-dead argument: insert GEPs and loads as appropriate.
00422         ScalarizeTable &ArgIndices = ScalarizedElements[I];
00423         for (ScalarizeTable::iterator SI = ArgIndices.begin(),
00424                E = ArgIndices.end(); SI != E; ++SI) {
00425           Value *V = *AI;
00426           LoadInst *OrigLoad = OriginalLoads[*SI];
00427           if (!SI->empty()) {
00428             V = new GetElementPtrInst(V, *SI, V->getName()+".idx", Call);
00429             AA.copyValue(OrigLoad->getOperand(0), V);
00430           }
00431           Args.push_back(new LoadInst(V, V->getName()+".val", Call));
00432           AA.copyValue(OrigLoad, Args.back());
00433         }
00434       }
00435 
00436     if (ExtraArgHack)
00437       Args.push_back(Constant::getNullValue(Type::IntTy));
00438 
00439     // Push any varargs arguments on the list
00440     for (; AI != CS.arg_end(); ++AI)
00441       Args.push_back(*AI);
00442 
00443     Instruction *New;
00444     if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) {
00445       New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(),
00446                            Args, "", Call);
00447       cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv());
00448     } else {
00449       New = new CallInst(NF, Args, "", Call);
00450       cast<CallInst>(New)->setCallingConv(CS.getCallingConv());
00451       if (cast<CallInst>(Call)->isTailCall())
00452         cast<CallInst>(New)->setTailCall();
00453     }
00454     Args.clear();
00455 
00456     // Update the alias analysis implementation to know that we are replacing
00457     // the old call with a new one.
00458     AA.replaceWithNewValue(Call, New);
00459 
00460     if (!Call->use_empty()) {
00461       Call->replaceAllUsesWith(New);
00462       std::string Name = Call->getName();
00463       Call->setName("");
00464       New->setName(Name);
00465     }
00466 
00467     // Finally, remove the old call from the program, reducing the use-count of
00468     // F.
00469     Call->getParent()->getInstList().erase(Call);
00470   }
00471 
00472   // Since we have now created the new function, splice the body of the old
00473   // function right into the new function, leaving the old rotting hulk of the
00474   // function empty.
00475   NF->getBasicBlockList().splice(NF->begin(), F->getBasicBlockList());
00476 
00477   // Loop over the argument list, transfering uses of the old arguments over to
00478   // the new arguments, also transfering over the names as well.
00479   //
00480   for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(), I2 = NF->arg_begin();
00481        I != E; ++I)
00482     if (!ArgsToPromote.count(I)) {
00483       // If this is an unmodified argument, move the name and users over to the
00484       // new version.
00485       I->replaceAllUsesWith(I2);
00486       I2->setName(I->getName());
00487       AA.replaceWithNewValue(I, I2);
00488       ++I2;
00489     } else if (I->use_empty()) {
00490       AA.deleteValue(I);
00491     } else {
00492       // Otherwise, if we promoted this argument, then all users are load
00493       // instructions, and all loads should be using the new argument that we
00494       // added.
00495       ScalarizeTable &ArgIndices = ScalarizedElements[I];
00496 
00497       while (!I->use_empty()) {
00498         if (LoadInst *LI = dyn_cast<LoadInst>(I->use_back())) {
00499           assert(ArgIndices.begin()->empty() &&
00500                  "Load element should sort to front!");
00501           I2->setName(I->getName()+".val");
00502           LI->replaceAllUsesWith(I2);
00503           AA.replaceWithNewValue(LI, I2);
00504           LI->getParent()->getInstList().erase(LI);
00505           DEBUG(std::cerr << "*** Promoted load of argument '" << I->getName()
00506                           << "' in function '" << F->getName() << "'\n");
00507         } else {
00508           GetElementPtrInst *GEP = cast<GetElementPtrInst>(I->use_back());
00509           std::vector<Value*> Operands(GEP->op_begin()+1, GEP->op_end());
00510 
00511           unsigned ArgNo = 0;
00512           Function::arg_iterator TheArg = I2;
00513           for (ScalarizeTable::iterator It = ArgIndices.begin();
00514                *It != Operands; ++It, ++TheArg) {
00515             assert(It != ArgIndices.end() && "GEP not handled??");
00516           }
00517 
00518           std::string NewName = I->getName();
00519           for (unsigned i = 0, e = Operands.size(); i != e; ++i)
00520             if (ConstantInt *CI = dyn_cast<ConstantInt>(Operands[i]))
00521               NewName += "."+itostr((int64_t)CI->getRawValue());
00522             else
00523               NewName += ".x";
00524           TheArg->setName(NewName+".val");
00525 
00526           DEBUG(std::cerr << "*** Promoted agg argument '" << TheArg->getName()
00527                           << "' of function '" << F->getName() << "'\n");
00528 
00529           // All of the uses must be load instructions.  Replace them all with
00530           // the argument specified by ArgNo.
00531           while (!GEP->use_empty()) {
00532             LoadInst *L = cast<LoadInst>(GEP->use_back());
00533             L->replaceAllUsesWith(TheArg);
00534             AA.replaceWithNewValue(L, TheArg);
00535             L->getParent()->getInstList().erase(L);
00536           }
00537           AA.deleteValue(GEP);
00538           GEP->getParent()->getInstList().erase(GEP);
00539         }
00540       }
00541 
00542       // Increment I2 past all of the arguments added for this promoted pointer.
00543       for (unsigned i = 0, e = ArgIndices.size(); i != e; ++i)
00544         ++I2;
00545     }
00546 
00547   // Notify the alias analysis implementation that we inserted a new argument.
00548   if (ExtraArgHack)
00549     AA.copyValue(Constant::getNullValue(Type::IntTy), NF->arg_begin());
00550 
00551 
00552   // Tell the alias analysis that the old function is about to disappear.
00553   AA.replaceWithNewValue(F, NF);
00554 
00555   // Now that the old function is dead, delete it.
00556   F->getParent()->getFunctionList().erase(F);
00557   return NF;
00558 }