LLVM API Documentation
00001 //===-- DeadArgumentElimination.cpp - Eliminate dead 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 deletes dead arguments from internal functions. Dead argument 00011 // elimination removes arguments which are directly dead, as well as arguments 00012 // only passed into function calls as dead arguments of other functions. This 00013 // pass also deletes dead arguments in a similar way. 00014 // 00015 // This pass is often useful as a cleanup pass to run after aggressive 00016 // interprocedural passes, which add possibly-dead arguments. 00017 // 00018 //===----------------------------------------------------------------------===// 00019 00020 #include "llvm/Transforms/IPO.h" 00021 #include "llvm/Module.h" 00022 #include "llvm/Pass.h" 00023 #include "llvm/DerivedTypes.h" 00024 #include "llvm/Constant.h" 00025 #include "llvm/Instructions.h" 00026 #include "llvm/Support/CallSite.h" 00027 #include "llvm/Support/Debug.h" 00028 #include "llvm/ADT/Statistic.h" 00029 #include "llvm/ADT/iterator" 00030 #include <set> 00031 using namespace llvm; 00032 00033 namespace { 00034 Statistic<> NumArgumentsEliminated("deadargelim", 00035 "Number of unread args removed"); 00036 Statistic<> NumRetValsEliminated("deadargelim", 00037 "Number of unused return values removed"); 00038 00039 /// DAE - The dead argument elimination pass. 00040 /// 00041 class DAE : public ModulePass { 00042 /// Liveness enum - During our initial pass over the program, we determine 00043 /// that things are either definately alive, definately dead, or in need of 00044 /// interprocedural analysis (MaybeLive). 00045 /// 00046 enum Liveness { Live, MaybeLive, Dead }; 00047 00048 /// LiveArguments, MaybeLiveArguments, DeadArguments - These sets contain 00049 /// all of the arguments in the program. The Dead set contains arguments 00050 /// which are completely dead (never used in the function). The MaybeLive 00051 /// set contains arguments which are only passed into other function calls, 00052 /// thus may be live and may be dead. The Live set contains arguments which 00053 /// are known to be alive. 00054 /// 00055 std::set<Argument*> DeadArguments, MaybeLiveArguments, LiveArguments; 00056 00057 /// DeadRetVal, MaybeLiveRetVal, LifeRetVal - These sets contain all of the 00058 /// functions in the program. The Dead set contains functions whose return 00059 /// value is known to be dead. The MaybeLive set contains functions whose 00060 /// return values are only used by return instructions, and the Live set 00061 /// contains functions whose return values are used, functions that are 00062 /// external, and functions that already return void. 00063 /// 00064 std::set<Function*> DeadRetVal, MaybeLiveRetVal, LiveRetVal; 00065 00066 /// InstructionsToInspect - As we mark arguments and return values 00067 /// MaybeLive, we keep track of which instructions could make the values 00068 /// live here. Once the entire program has had the return value and 00069 /// arguments analyzed, this set is scanned to promote the MaybeLive objects 00070 /// to be Live if they really are used. 00071 std::vector<Instruction*> InstructionsToInspect; 00072 00073 /// CallSites - Keep track of the call sites of functions that have 00074 /// MaybeLive arguments or return values. 00075 std::multimap<Function*, CallSite> CallSites; 00076 00077 public: 00078 bool runOnModule(Module &M); 00079 00080 virtual bool ShouldHackArguments() const { return false; } 00081 00082 private: 00083 Liveness getArgumentLiveness(const Argument &A); 00084 bool isMaybeLiveArgumentNowLive(Argument *Arg); 00085 00086 void SurveyFunction(Function &Fn); 00087 00088 void MarkArgumentLive(Argument *Arg); 00089 void MarkRetValLive(Function *F); 00090 void MarkReturnInstArgumentLive(ReturnInst *RI); 00091 00092 void RemoveDeadArgumentsFromFunction(Function *F); 00093 }; 00094 RegisterOpt<DAE> X("deadargelim", "Dead Argument Elimination"); 00095 00096 /// DAH - DeadArgumentHacking pass - Same as dead argument elimination, but 00097 /// deletes arguments to functions which are external. This is only for use 00098 /// by bugpoint. 00099 struct DAH : public DAE { 00100 virtual bool ShouldHackArguments() const { return true; } 00101 }; 00102 RegisterPass<DAH> Y("deadarghaX0r", 00103 "Dead Argument Hacking (BUGPOINT USE ONLY; DO NOT USE)"); 00104 } 00105 00106 /// createDeadArgEliminationPass - This pass removes arguments from functions 00107 /// which are not used by the body of the function. 00108 /// 00109 ModulePass *llvm::createDeadArgEliminationPass() { return new DAE(); } 00110 ModulePass *llvm::createDeadArgHackingPass() { return new DAH(); } 00111 00112 static inline bool CallPassesValueThoughVararg(Instruction *Call, 00113 const Value *Arg) { 00114 CallSite CS = CallSite::get(Call); 00115 const Type *CalledValueTy = CS.getCalledValue()->getType(); 00116 const Type *FTy = cast<PointerType>(CalledValueTy)->getElementType(); 00117 unsigned NumFixedArgs = cast<FunctionType>(FTy)->getNumParams(); 00118 for (CallSite::arg_iterator AI = CS.arg_begin()+NumFixedArgs; 00119 AI != CS.arg_end(); ++AI) 00120 if (AI->get() == Arg) 00121 return true; 00122 return false; 00123 } 00124 00125 // getArgumentLiveness - Inspect an argument, determining if is known Live 00126 // (used in a computation), MaybeLive (only passed as an argument to a call), or 00127 // Dead (not used). 00128 DAE::Liveness DAE::getArgumentLiveness(const Argument &A) { 00129 if (A.use_empty()) return Dead; // First check, directly dead? 00130 00131 // Scan through all of the uses, looking for non-argument passing uses. 00132 for (Value::use_const_iterator I = A.use_begin(), E = A.use_end(); I!=E;++I) { 00133 // Return instructions do not immediately effect liveness. 00134 if (isa<ReturnInst>(*I)) 00135 continue; 00136 00137 CallSite CS = CallSite::get(const_cast<User*>(*I)); 00138 if (!CS.getInstruction()) { 00139 // If its used by something that is not a call or invoke, it's alive! 00140 return Live; 00141 } 00142 // If it's an indirect call, mark it alive... 00143 Function *Callee = CS.getCalledFunction(); 00144 if (!Callee) return Live; 00145 00146 // Check to see if it's passed through a va_arg area: if so, we cannot 00147 // remove it. 00148 if (CallPassesValueThoughVararg(CS.getInstruction(), &A)) 00149 return Live; // If passed through va_arg area, we cannot remove it 00150 } 00151 00152 return MaybeLive; // It must be used, but only as argument to a function 00153 } 00154 00155 00156 // SurveyFunction - This performs the initial survey of the specified function, 00157 // checking out whether or not it uses any of its incoming arguments or whether 00158 // any callers use the return value. This fills in the 00159 // (Dead|MaybeLive|Live)(Arguments|RetVal) sets. 00160 // 00161 // We consider arguments of non-internal functions to be intrinsically alive as 00162 // well as arguments to functions which have their "address taken". 00163 // 00164 void DAE::SurveyFunction(Function &F) { 00165 bool FunctionIntrinsicallyLive = false; 00166 Liveness RetValLiveness = F.getReturnType() == Type::VoidTy ? Live : Dead; 00167 00168 if (!F.hasInternalLinkage() && 00169 (!ShouldHackArguments() || F.getIntrinsicID())) 00170 FunctionIntrinsicallyLive = true; 00171 else 00172 for (Value::use_iterator I = F.use_begin(), E = F.use_end(); I != E; ++I) { 00173 // If this use is anything other than a call site, the function is alive. 00174 CallSite CS = CallSite::get(*I); 00175 Instruction *TheCall = CS.getInstruction(); 00176 if (!TheCall) { // Not a direct call site? 00177 FunctionIntrinsicallyLive = true; 00178 break; 00179 } 00180 00181 // Check to see if the return value is used... 00182 if (RetValLiveness != Live) 00183 for (Value::use_iterator I = TheCall->use_begin(), 00184 E = TheCall->use_end(); I != E; ++I) 00185 if (isa<ReturnInst>(cast<Instruction>(*I))) { 00186 RetValLiveness = MaybeLive; 00187 } else if (isa<CallInst>(cast<Instruction>(*I)) || 00188 isa<InvokeInst>(cast<Instruction>(*I))) { 00189 if (CallPassesValueThoughVararg(cast<Instruction>(*I), TheCall) || 00190 !CallSite::get(cast<Instruction>(*I)).getCalledFunction()) { 00191 RetValLiveness = Live; 00192 break; 00193 } else { 00194 RetValLiveness = MaybeLive; 00195 } 00196 } else { 00197 RetValLiveness = Live; 00198 break; 00199 } 00200 00201 // If the function is PASSED IN as an argument, its address has been taken 00202 for (CallSite::arg_iterator AI = CS.arg_begin(), E = CS.arg_end(); 00203 AI != E; ++AI) 00204 if (AI->get() == &F) { 00205 FunctionIntrinsicallyLive = true; 00206 break; 00207 } 00208 if (FunctionIntrinsicallyLive) break; 00209 } 00210 00211 if (FunctionIntrinsicallyLive) { 00212 DEBUG(std::cerr << " Intrinsically live fn: " << F.getName() << "\n"); 00213 for (Function::aiterator AI = F.abegin(), E = F.aend(); AI != E; ++AI) 00214 LiveArguments.insert(AI); 00215 LiveRetVal.insert(&F); 00216 return; 00217 } 00218 00219 switch (RetValLiveness) { 00220 case Live: LiveRetVal.insert(&F); break; 00221 case MaybeLive: MaybeLiveRetVal.insert(&F); break; 00222 case Dead: DeadRetVal.insert(&F); break; 00223 } 00224 00225 DEBUG(std::cerr << " Inspecting args for fn: " << F.getName() << "\n"); 00226 00227 // If it is not intrinsically alive, we know that all users of the 00228 // function are call sites. Mark all of the arguments live which are 00229 // directly used, and keep track of all of the call sites of this function 00230 // if there are any arguments we assume that are dead. 00231 // 00232 bool AnyMaybeLiveArgs = false; 00233 for (Function::aiterator AI = F.abegin(), E = F.aend(); AI != E; ++AI) 00234 switch (getArgumentLiveness(*AI)) { 00235 case Live: 00236 DEBUG(std::cerr << " Arg live by use: " << AI->getName() << "\n"); 00237 LiveArguments.insert(AI); 00238 break; 00239 case Dead: 00240 DEBUG(std::cerr << " Arg definitely dead: " <<AI->getName()<<"\n"); 00241 DeadArguments.insert(AI); 00242 break; 00243 case MaybeLive: 00244 DEBUG(std::cerr << " Arg only passed to calls: " 00245 << AI->getName() << "\n"); 00246 AnyMaybeLiveArgs = true; 00247 MaybeLiveArguments.insert(AI); 00248 break; 00249 } 00250 00251 // If there are any "MaybeLive" arguments, we need to check callees of 00252 // this function when/if they become alive. Record which functions are 00253 // callees... 00254 if (AnyMaybeLiveArgs || RetValLiveness == MaybeLive) 00255 for (Value::use_iterator I = F.use_begin(), E = F.use_end(); 00256 I != E; ++I) { 00257 if (AnyMaybeLiveArgs) 00258 CallSites.insert(std::make_pair(&F, CallSite::get(*I))); 00259 00260 if (RetValLiveness == MaybeLive) 00261 for (Value::use_iterator UI = I->use_begin(), E = I->use_end(); 00262 UI != E; ++UI) 00263 InstructionsToInspect.push_back(cast<Instruction>(*UI)); 00264 } 00265 } 00266 00267 // isMaybeLiveArgumentNowLive - Check to see if Arg is alive. At this point, we 00268 // know that the only uses of Arg are to be passed in as an argument to a 00269 // function call or return. Check to see if the formal argument passed in is in 00270 // the LiveArguments set. If so, return true. 00271 // 00272 bool DAE::isMaybeLiveArgumentNowLive(Argument *Arg) { 00273 for (Value::use_iterator I = Arg->use_begin(), E = Arg->use_end(); I!=E; ++I){ 00274 if (isa<ReturnInst>(*I)) { 00275 if (LiveRetVal.count(Arg->getParent())) return true; 00276 continue; 00277 } 00278 00279 CallSite CS = CallSite::get(*I); 00280 00281 // We know that this can only be used for direct calls... 00282 Function *Callee = CS.getCalledFunction(); 00283 00284 // Loop over all of the arguments (because Arg may be passed into the call 00285 // multiple times) and check to see if any are now alive... 00286 CallSite::arg_iterator CSAI = CS.arg_begin(); 00287 for (Function::aiterator AI = Callee->abegin(), E = Callee->aend(); 00288 AI != E; ++AI, ++CSAI) 00289 // If this is the argument we are looking for, check to see if it's alive 00290 if (*CSAI == Arg && LiveArguments.count(AI)) 00291 return true; 00292 } 00293 return false; 00294 } 00295 00296 /// MarkArgumentLive - The MaybeLive argument 'Arg' is now known to be alive. 00297 /// Mark it live in the specified sets and recursively mark arguments in callers 00298 /// live that are needed to pass in a value. 00299 /// 00300 void DAE::MarkArgumentLive(Argument *Arg) { 00301 std::set<Argument*>::iterator It = MaybeLiveArguments.lower_bound(Arg); 00302 if (It == MaybeLiveArguments.end() || *It != Arg) return; 00303 00304 DEBUG(std::cerr << " MaybeLive argument now live: " << Arg->getName()<<"\n"); 00305 MaybeLiveArguments.erase(It); 00306 LiveArguments.insert(Arg); 00307 00308 // Loop over all of the call sites of the function, making any arguments 00309 // passed in to provide a value for this argument live as necessary. 00310 // 00311 Function *Fn = Arg->getParent(); 00312 unsigned ArgNo = std::distance(Fn->abegin(), Function::aiterator(Arg)); 00313 00314 std::multimap<Function*, CallSite>::iterator I = CallSites.lower_bound(Fn); 00315 for (; I != CallSites.end() && I->first == Fn; ++I) { 00316 CallSite CS = I->second; 00317 Value *ArgVal = *(CS.arg_begin()+ArgNo); 00318 if (Argument *ActualArg = dyn_cast<Argument>(ArgVal)) { 00319 MarkArgumentLive(ActualArg); 00320 } else { 00321 // If the value passed in at this call site is a return value computed by 00322 // some other call site, make sure to mark the return value at the other 00323 // call site as being needed. 00324 CallSite ArgCS = CallSite::get(ArgVal); 00325 if (ArgCS.getInstruction()) 00326 if (Function *Fn = ArgCS.getCalledFunction()) 00327 MarkRetValLive(Fn); 00328 } 00329 } 00330 } 00331 00332 /// MarkArgumentLive - The MaybeLive return value for the specified function is 00333 /// now known to be alive. Propagate this fact to the return instructions which 00334 /// produce it. 00335 void DAE::MarkRetValLive(Function *F) { 00336 assert(F && "Shame shame, we can't have null pointers here!"); 00337 00338 // Check to see if we already knew it was live 00339 std::set<Function*>::iterator I = MaybeLiveRetVal.lower_bound(F); 00340 if (I == MaybeLiveRetVal.end() || *I != F) return; // It's already alive! 00341 00342 DEBUG(std::cerr << " MaybeLive retval now live: " << F->getName() << "\n"); 00343 00344 MaybeLiveRetVal.erase(I); 00345 LiveRetVal.insert(F); // It is now known to be live! 00346 00347 // Loop over all of the functions, noticing that the return value is now live. 00348 for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) 00349 if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator())) 00350 MarkReturnInstArgumentLive(RI); 00351 } 00352 00353 void DAE::MarkReturnInstArgumentLive(ReturnInst *RI) { 00354 Value *Op = RI->getOperand(0); 00355 if (Argument *A = dyn_cast<Argument>(Op)) { 00356 MarkArgumentLive(A); 00357 } else if (CallInst *CI = dyn_cast<CallInst>(Op)) { 00358 if (Function *F = CI->getCalledFunction()) 00359 MarkRetValLive(F); 00360 } else if (InvokeInst *II = dyn_cast<InvokeInst>(Op)) { 00361 if (Function *F = II->getCalledFunction()) 00362 MarkRetValLive(F); 00363 } 00364 } 00365 00366 // RemoveDeadArgumentsFromFunction - We know that F has dead arguments, as 00367 // specified by the DeadArguments list. Transform the function and all of the 00368 // callees of the function to not have these arguments. 00369 // 00370 void DAE::RemoveDeadArgumentsFromFunction(Function *F) { 00371 // Start by computing a new prototype for the function, which is the same as 00372 // the old function, but has fewer arguments. 00373 const FunctionType *FTy = F->getFunctionType(); 00374 std::vector<const Type*> Params; 00375 00376 for (Function::aiterator I = F->abegin(), E = F->aend(); I != E; ++I) 00377 if (!DeadArguments.count(I)) 00378 Params.push_back(I->getType()); 00379 00380 const Type *RetTy = FTy->getReturnType(); 00381 if (DeadRetVal.count(F)) { 00382 RetTy = Type::VoidTy; 00383 DeadRetVal.erase(F); 00384 } 00385 00386 // Work around LLVM bug PR56: the CWriter cannot emit varargs functions which 00387 // have zero fixed arguments. 00388 // 00389 // FIXME: once this bug is fixed in the CWriter, this hack should be removed. 00390 // 00391 bool ExtraArgHack = false; 00392 if (Params.empty() && FTy->isVarArg()) { 00393 ExtraArgHack = true; 00394 Params.push_back(Type::IntTy); 00395 } 00396 00397 FunctionType *NFTy = FunctionType::get(RetTy, Params, FTy->isVarArg()); 00398 00399 // Create the new function body and insert it into the module... 00400 Function *NF = new Function(NFTy, F->getLinkage(), F->getName()); 00401 F->getParent()->getFunctionList().insert(F, NF); 00402 00403 // Loop over all of the callers of the function, transforming the call sites 00404 // to pass in a smaller number of arguments into the new function. 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, deleting dead ones... 00412 CallSite::arg_iterator AI = CS.arg_begin(); 00413 for (Function::aiterator I = F->abegin(), E = F->aend(); I != E; ++I, ++AI) 00414 if (!DeadArguments.count(I)) // Remove operands for dead arguments 00415 Args.push_back(*AI); 00416 00417 if (ExtraArgHack) 00418 Args.push_back(Constant::getNullValue(Type::IntTy)); 00419 00420 // Push any varargs arguments on the list 00421 for (; AI != CS.arg_end(); ++AI) 00422 Args.push_back(*AI); 00423 00424 Instruction *New; 00425 if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) { 00426 New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(), 00427 Args, "", Call); 00428 } else { 00429 New = new CallInst(NF, Args, "", Call); 00430 } 00431 Args.clear(); 00432 00433 if (!Call->use_empty()) { 00434 if (New->getType() == Type::VoidTy) 00435 Call->replaceAllUsesWith(Constant::getNullValue(Call->getType())); 00436 else { 00437 Call->replaceAllUsesWith(New); 00438 std::string Name = Call->getName(); 00439 Call->setName(""); 00440 New->setName(Name); 00441 } 00442 } 00443 00444 // Finally, remove the old call from the program, reducing the use-count of 00445 // F. 00446 Call->getParent()->getInstList().erase(Call); 00447 } 00448 00449 // Since we have now created the new function, splice the body of the old 00450 // function right into the new function, leaving the old rotting hulk of the 00451 // function empty. 00452 NF->getBasicBlockList().splice(NF->begin(), F->getBasicBlockList()); 00453 00454 // Loop over the argument list, transfering uses of the old arguments over to 00455 // the new arguments, also transfering over the names as well. While we're at 00456 // it, remove the dead arguments from the DeadArguments list. 00457 // 00458 for (Function::aiterator I = F->abegin(), E = F->aend(), I2 = NF->abegin(); 00459 I != E; ++I) 00460 if (!DeadArguments.count(I)) { 00461 // If this is a live argument, move the name and users over to the new 00462 // version. 00463 I->replaceAllUsesWith(I2); 00464 I2->setName(I->getName()); 00465 ++I2; 00466 } else { 00467 // If this argument is dead, replace any uses of it with null constants 00468 // (these are guaranteed to only be operands to call instructions which 00469 // will later be simplified). 00470 I->replaceAllUsesWith(Constant::getNullValue(I->getType())); 00471 DeadArguments.erase(I); 00472 } 00473 00474 // If we change the return value of the function we must rewrite any return 00475 // instructions. Check this now. 00476 if (F->getReturnType() != NF->getReturnType()) 00477 for (Function::iterator BB = NF->begin(), E = NF->end(); BB != E; ++BB) 00478 if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator())) { 00479 new ReturnInst(0, RI); 00480 BB->getInstList().erase(RI); 00481 } 00482 00483 // Now that the old function is dead, delete it. 00484 F->getParent()->getFunctionList().erase(F); 00485 } 00486 00487 bool DAE::runOnModule(Module &M) { 00488 // First phase: loop through the module, determining which arguments are live. 00489 // We assume all arguments are dead unless proven otherwise (allowing us to 00490 // determine that dead arguments passed into recursive functions are dead). 00491 // 00492 DEBUG(std::cerr << "DAE - Determining liveness\n"); 00493 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) 00494 SurveyFunction(*I); 00495 00496 // Loop over the instructions to inspect, propagating liveness among arguments 00497 // and return values which are MaybeLive. 00498 00499 while (!InstructionsToInspect.empty()) { 00500 Instruction *I = InstructionsToInspect.back(); 00501 InstructionsToInspect.pop_back(); 00502 00503 if (ReturnInst *RI = dyn_cast<ReturnInst>(I)) { 00504 // For return instructions, we just have to check to see if the return 00505 // value for the current function is known now to be alive. If so, any 00506 // arguments used by it are now alive, and any call instruction return 00507 // value is alive as well. 00508 if (LiveRetVal.count(RI->getParent()->getParent())) 00509 MarkReturnInstArgumentLive(RI); 00510 00511 } else { 00512 CallSite CS = CallSite::get(I); 00513 assert(CS.getInstruction() && "Unknown instruction for the I2I list!"); 00514 00515 Function *Callee = CS.getCalledFunction(); 00516 00517 // If we found a call or invoke instruction on this list, that means that 00518 // an argument of the function is a call instruction. If the argument is 00519 // live, then the return value of the called instruction is now live. 00520 // 00521 CallSite::arg_iterator AI = CS.arg_begin(); // ActualIterator 00522 for (Function::aiterator FI = Callee->abegin(), E = Callee->aend(); 00523 FI != E; ++AI, ++FI) { 00524 // If this argument is another call... 00525 CallSite ArgCS = CallSite::get(*AI); 00526 if (ArgCS.getInstruction() && LiveArguments.count(FI)) 00527 if (Function *Callee = ArgCS.getCalledFunction()) 00528 MarkRetValLive(Callee); 00529 } 00530 } 00531 } 00532 00533 // Now we loop over all of the MaybeLive arguments, promoting them to be live 00534 // arguments if one of the calls that uses the arguments to the calls they are 00535 // passed into requires them to be live. Of course this could make other 00536 // arguments live, so process callers recursively. 00537 // 00538 // Because elements can be removed from the MaybeLiveArguments set, copy it to 00539 // a temporary vector. 00540 // 00541 std::vector<Argument*> TmpArgList(MaybeLiveArguments.begin(), 00542 MaybeLiveArguments.end()); 00543 for (unsigned i = 0, e = TmpArgList.size(); i != e; ++i) { 00544 Argument *MLA = TmpArgList[i]; 00545 if (MaybeLiveArguments.count(MLA) && 00546 isMaybeLiveArgumentNowLive(MLA)) 00547 MarkArgumentLive(MLA); 00548 } 00549 00550 // Recover memory early... 00551 CallSites.clear(); 00552 00553 // At this point, we know that all arguments in DeadArguments and 00554 // MaybeLiveArguments are dead. If the two sets are empty, there is nothing 00555 // to do. 00556 if (MaybeLiveArguments.empty() && DeadArguments.empty() && 00557 MaybeLiveRetVal.empty() && DeadRetVal.empty()) 00558 return false; 00559 00560 // Otherwise, compact into one set, and start eliminating the arguments from 00561 // the functions. 00562 DeadArguments.insert(MaybeLiveArguments.begin(), MaybeLiveArguments.end()); 00563 MaybeLiveArguments.clear(); 00564 DeadRetVal.insert(MaybeLiveRetVal.begin(), MaybeLiveRetVal.end()); 00565 MaybeLiveRetVal.clear(); 00566 00567 LiveArguments.clear(); 00568 LiveRetVal.clear(); 00569 00570 NumArgumentsEliminated += DeadArguments.size(); 00571 NumRetValsEliminated += DeadRetVal.size(); 00572 while (!DeadArguments.empty()) 00573 RemoveDeadArgumentsFromFunction((*DeadArguments.begin())->getParent()); 00574 00575 while (!DeadRetVal.empty()) 00576 RemoveDeadArgumentsFromFunction(*DeadRetVal.begin()); 00577 return true; 00578 }