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