Make iostream #inclusion explicit
[oota-llvm.git] / lib / Transforms / IPO / DeadArgumentElimination.cpp
1 //===-- DeadArgumentElimination.cpp - Eliminate dead 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 deletes dead arguments from internal functions.  Dead argument
11 // elimination removes arguments which are directly dead, as well as arguments
12 // only passed into function calls as dead arguments of other functions.  This
13 // pass also deletes dead arguments in a similar way.
14 //
15 // This pass is often useful as a cleanup pass to run after aggressive
16 // interprocedural passes, which add possibly-dead arguments.
17 //
18 //===----------------------------------------------------------------------===//
19
20 #define DEBUG_TYPE "deadargelim"
21 #include "llvm/Transforms/IPO.h"
22 #include "llvm/Module.h"
23 #include "llvm/Pass.h"
24 #include "llvm/DerivedTypes.h"
25 #include "llvm/Constant.h"
26 #include "llvm/Instructions.h"
27 #include "llvm/Support/CallSite.h"
28 #include "llvm/Support/Debug.h"
29 #include "llvm/ADT/Statistic.h"
30 #include "llvm/ADT/iterator"
31 #include <iostream>
32 #include <set>
33 using namespace llvm;
34
35 namespace {
36   Statistic<> NumArgumentsEliminated("deadargelim",
37                                      "Number of unread args removed");
38   Statistic<> NumRetValsEliminated("deadargelim",
39                                    "Number of unused return values removed");
40
41   /// DAE - The dead argument elimination pass.
42   ///
43   class DAE : public ModulePass {
44     /// Liveness enum - During our initial pass over the program, we determine
45     /// that things are either definately alive, definately dead, or in need of
46     /// interprocedural analysis (MaybeLive).
47     ///
48     enum Liveness { Live, MaybeLive, Dead };
49
50     /// LiveArguments, MaybeLiveArguments, DeadArguments - These sets contain
51     /// all of the arguments in the program.  The Dead set contains arguments
52     /// which are completely dead (never used in the function).  The MaybeLive
53     /// set contains arguments which are only passed into other function calls,
54     /// thus may be live and may be dead.  The Live set contains arguments which
55     /// are known to be alive.
56     ///
57     std::set<Argument*> DeadArguments, MaybeLiveArguments, LiveArguments;
58
59     /// DeadRetVal, MaybeLiveRetVal, LifeRetVal - These sets contain all of the
60     /// functions in the program.  The Dead set contains functions whose return
61     /// value is known to be dead.  The MaybeLive set contains functions whose
62     /// return values are only used by return instructions, and the Live set
63     /// contains functions whose return values are used, functions that are
64     /// external, and functions that already return void.
65     ///
66     std::set<Function*> DeadRetVal, MaybeLiveRetVal, LiveRetVal;
67
68     /// InstructionsToInspect - As we mark arguments and return values
69     /// MaybeLive, we keep track of which instructions could make the values
70     /// live here.  Once the entire program has had the return value and
71     /// arguments analyzed, this set is scanned to promote the MaybeLive objects
72     /// to be Live if they really are used.
73     std::vector<Instruction*> InstructionsToInspect;
74
75     /// CallSites - Keep track of the call sites of functions that have
76     /// MaybeLive arguments or return values.
77     std::multimap<Function*, CallSite> CallSites;
78
79   public:
80     bool runOnModule(Module &M);
81
82     virtual bool ShouldHackArguments() const { return false; }
83
84   private:
85     Liveness getArgumentLiveness(const Argument &A);
86     bool isMaybeLiveArgumentNowLive(Argument *Arg);
87
88     void SurveyFunction(Function &Fn);
89
90     void MarkArgumentLive(Argument *Arg);
91     void MarkRetValLive(Function *F);
92     void MarkReturnInstArgumentLive(ReturnInst *RI);
93
94     void RemoveDeadArgumentsFromFunction(Function *F);
95   };
96   RegisterOpt<DAE> X("deadargelim", "Dead Argument Elimination");
97
98   /// DAH - DeadArgumentHacking pass - Same as dead argument elimination, but
99   /// deletes arguments to functions which are external.  This is only for use
100   /// by bugpoint.
101   struct DAH : public DAE {
102     virtual bool ShouldHackArguments() const { return true; }
103   };
104   RegisterPass<DAH> Y("deadarghaX0r",
105                       "Dead Argument Hacking (BUGPOINT USE ONLY; DO NOT USE)");
106 }
107
108 /// createDeadArgEliminationPass - This pass removes arguments from functions
109 /// which are not used by the body of the function.
110 ///
111 ModulePass *llvm::createDeadArgEliminationPass() { return new DAE(); }
112 ModulePass *llvm::createDeadArgHackingPass() { return new DAH(); }
113
114 static inline bool CallPassesValueThoughVararg(Instruction *Call,
115                                                const Value *Arg) {
116   CallSite CS = CallSite::get(Call);
117   const Type *CalledValueTy = CS.getCalledValue()->getType();
118   const Type *FTy = cast<PointerType>(CalledValueTy)->getElementType();
119   unsigned NumFixedArgs = cast<FunctionType>(FTy)->getNumParams();
120   for (CallSite::arg_iterator AI = CS.arg_begin()+NumFixedArgs;
121        AI != CS.arg_end(); ++AI)
122     if (AI->get() == Arg)
123       return true;
124   return false;
125 }
126
127 // getArgumentLiveness - Inspect an argument, determining if is known Live
128 // (used in a computation), MaybeLive (only passed as an argument to a call), or
129 // Dead (not used).
130 DAE::Liveness DAE::getArgumentLiveness(const Argument &A) {
131   if (A.use_empty()) return Dead;  // First check, directly dead?
132
133   // Scan through all of the uses, looking for non-argument passing uses.
134   for (Value::use_const_iterator I = A.use_begin(), E = A.use_end(); I!=E;++I) {
135     // Return instructions do not immediately effect liveness.
136     if (isa<ReturnInst>(*I))
137       continue;
138
139     CallSite CS = CallSite::get(const_cast<User*>(*I));
140     if (!CS.getInstruction()) {
141       // If its used by something that is not a call or invoke, it's alive!
142       return Live;
143     }
144     // If it's an indirect call, mark it alive...
145     Function *Callee = CS.getCalledFunction();
146     if (!Callee) return Live;
147
148     // Check to see if it's passed through a va_arg area: if so, we cannot
149     // remove it.
150     if (CallPassesValueThoughVararg(CS.getInstruction(), &A))
151       return Live;   // If passed through va_arg area, we cannot remove it
152   }
153
154   return MaybeLive;  // It must be used, but only as argument to a function
155 }
156
157
158 // SurveyFunction - This performs the initial survey of the specified function,
159 // checking out whether or not it uses any of its incoming arguments or whether
160 // any callers use the return value.  This fills in the
161 // (Dead|MaybeLive|Live)(Arguments|RetVal) sets.
162 //
163 // We consider arguments of non-internal functions to be intrinsically alive as
164 // well as arguments to functions which have their "address taken".
165 //
166 void DAE::SurveyFunction(Function &F) {
167   bool FunctionIntrinsicallyLive = false;
168   Liveness RetValLiveness = F.getReturnType() == Type::VoidTy ? Live : Dead;
169
170   if (!F.hasInternalLinkage() &&
171       (!ShouldHackArguments() || F.getIntrinsicID()))
172     FunctionIntrinsicallyLive = true;
173   else
174     for (Value::use_iterator I = F.use_begin(), E = F.use_end(); I != E; ++I) {
175       // If this use is anything other than a call site, the function is alive.
176       CallSite CS = CallSite::get(*I);
177       Instruction *TheCall = CS.getInstruction();
178       if (!TheCall) {   // Not a direct call site?
179         FunctionIntrinsicallyLive = true;
180         break;
181       }
182
183       // Check to see if the return value is used...
184       if (RetValLiveness != Live)
185         for (Value::use_iterator I = TheCall->use_begin(),
186                E = TheCall->use_end(); I != E; ++I)
187           if (isa<ReturnInst>(cast<Instruction>(*I))) {
188             RetValLiveness = MaybeLive;
189           } else if (isa<CallInst>(cast<Instruction>(*I)) ||
190                      isa<InvokeInst>(cast<Instruction>(*I))) {
191             if (CallPassesValueThoughVararg(cast<Instruction>(*I), TheCall) ||
192                 !CallSite::get(cast<Instruction>(*I)).getCalledFunction()) {
193               RetValLiveness = Live;
194               break;
195             } else {
196               RetValLiveness = MaybeLive;
197             }
198           } else {
199             RetValLiveness = Live;
200             break;
201           }
202
203       // If the function is PASSED IN as an argument, its address has been taken
204       for (CallSite::arg_iterator AI = CS.arg_begin(), E = CS.arg_end();
205            AI != E; ++AI)
206         if (AI->get() == &F) {
207           FunctionIntrinsicallyLive = true;
208           break;
209         }
210       if (FunctionIntrinsicallyLive) break;
211     }
212
213   if (FunctionIntrinsicallyLive) {
214     DEBUG(std::cerr << "  Intrinsically live fn: " << F.getName() << "\n");
215     for (Function::arg_iterator AI = F.arg_begin(), E = F.arg_end();
216          AI != E; ++AI)
217       LiveArguments.insert(AI);
218     LiveRetVal.insert(&F);
219     return;
220   }
221
222   switch (RetValLiveness) {
223   case Live:      LiveRetVal.insert(&F); break;
224   case MaybeLive: MaybeLiveRetVal.insert(&F); break;
225   case Dead:      DeadRetVal.insert(&F); break;
226   }
227
228   DEBUG(std::cerr << "  Inspecting args for fn: " << F.getName() << "\n");
229
230   // If it is not intrinsically alive, we know that all users of the
231   // function are call sites.  Mark all of the arguments live which are
232   // directly used, and keep track of all of the call sites of this function
233   // if there are any arguments we assume that are dead.
234   //
235   bool AnyMaybeLiveArgs = false;
236   for (Function::arg_iterator AI = F.arg_begin(), E = F.arg_end();
237        AI != E; ++AI)
238     switch (getArgumentLiveness(*AI)) {
239     case Live:
240       DEBUG(std::cerr << "    Arg live by use: " << AI->getName() << "\n");
241       LiveArguments.insert(AI);
242       break;
243     case Dead:
244       DEBUG(std::cerr << "    Arg definitely dead: " <<AI->getName()<<"\n");
245       DeadArguments.insert(AI);
246       break;
247     case MaybeLive:
248       DEBUG(std::cerr << "    Arg only passed to calls: "
249             << AI->getName() << "\n");
250       AnyMaybeLiveArgs = true;
251       MaybeLiveArguments.insert(AI);
252       break;
253     }
254
255   // If there are any "MaybeLive" arguments, we need to check callees of
256   // this function when/if they become alive.  Record which functions are
257   // callees...
258   if (AnyMaybeLiveArgs || RetValLiveness == MaybeLive)
259     for (Value::use_iterator I = F.use_begin(), E = F.use_end();
260          I != E; ++I) {
261       if (AnyMaybeLiveArgs)
262         CallSites.insert(std::make_pair(&F, CallSite::get(*I)));
263
264       if (RetValLiveness == MaybeLive)
265         for (Value::use_iterator UI = I->use_begin(), E = I->use_end();
266              UI != E; ++UI)
267           InstructionsToInspect.push_back(cast<Instruction>(*UI));
268     }
269 }
270
271 // isMaybeLiveArgumentNowLive - Check to see if Arg is alive.  At this point, we
272 // know that the only uses of Arg are to be passed in as an argument to a
273 // function call or return.  Check to see if the formal argument passed in is in
274 // the LiveArguments set.  If so, return true.
275 //
276 bool DAE::isMaybeLiveArgumentNowLive(Argument *Arg) {
277   for (Value::use_iterator I = Arg->use_begin(), E = Arg->use_end(); I!=E; ++I){
278     if (isa<ReturnInst>(*I)) {
279       if (LiveRetVal.count(Arg->getParent())) return true;
280       continue;
281     }
282
283     CallSite CS = CallSite::get(*I);
284
285     // We know that this can only be used for direct calls...
286     Function *Callee = CS.getCalledFunction();
287
288     // Loop over all of the arguments (because Arg may be passed into the call
289     // multiple times) and check to see if any are now alive...
290     CallSite::arg_iterator CSAI = CS.arg_begin();
291     for (Function::arg_iterator AI = Callee->arg_begin(), E = Callee->arg_end();
292          AI != E; ++AI, ++CSAI)
293       // If this is the argument we are looking for, check to see if it's alive
294       if (*CSAI == Arg && LiveArguments.count(AI))
295         return true;
296   }
297   return false;
298 }
299
300 /// MarkArgumentLive - The MaybeLive argument 'Arg' is now known to be alive.
301 /// Mark it live in the specified sets and recursively mark arguments in callers
302 /// live that are needed to pass in a value.
303 ///
304 void DAE::MarkArgumentLive(Argument *Arg) {
305   std::set<Argument*>::iterator It = MaybeLiveArguments.lower_bound(Arg);
306   if (It == MaybeLiveArguments.end() || *It != Arg) return;
307
308   DEBUG(std::cerr << "  MaybeLive argument now live: " << Arg->getName()<<"\n");
309   MaybeLiveArguments.erase(It);
310   LiveArguments.insert(Arg);
311
312   // Loop over all of the call sites of the function, making any arguments
313   // passed in to provide a value for this argument live as necessary.
314   //
315   Function *Fn = Arg->getParent();
316   unsigned ArgNo = std::distance(Fn->arg_begin(), Function::arg_iterator(Arg));
317
318   std::multimap<Function*, CallSite>::iterator I = CallSites.lower_bound(Fn);
319   for (; I != CallSites.end() && I->first == Fn; ++I) {
320     CallSite CS = I->second;
321     Value *ArgVal = *(CS.arg_begin()+ArgNo);
322     if (Argument *ActualArg = dyn_cast<Argument>(ArgVal)) {
323       MarkArgumentLive(ActualArg);
324     } else {
325       // If the value passed in at this call site is a return value computed by
326       // some other call site, make sure to mark the return value at the other
327       // call site as being needed.
328       CallSite ArgCS = CallSite::get(ArgVal);
329       if (ArgCS.getInstruction())
330         if (Function *Fn = ArgCS.getCalledFunction())
331           MarkRetValLive(Fn);
332     }
333   }
334 }
335
336 /// MarkArgumentLive - The MaybeLive return value for the specified function is
337 /// now known to be alive.  Propagate this fact to the return instructions which
338 /// produce it.
339 void DAE::MarkRetValLive(Function *F) {
340   assert(F && "Shame shame, we can't have null pointers here!");
341
342   // Check to see if we already knew it was live
343   std::set<Function*>::iterator I = MaybeLiveRetVal.lower_bound(F);
344   if (I == MaybeLiveRetVal.end() || *I != F) return;  // It's already alive!
345
346   DEBUG(std::cerr << "  MaybeLive retval now live: " << F->getName() << "\n");
347
348   MaybeLiveRetVal.erase(I);
349   LiveRetVal.insert(F);        // It is now known to be live!
350
351   // Loop over all of the functions, noticing that the return value is now live.
352   for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
353     if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator()))
354       MarkReturnInstArgumentLive(RI);
355 }
356
357 void DAE::MarkReturnInstArgumentLive(ReturnInst *RI) {
358   Value *Op = RI->getOperand(0);
359   if (Argument *A = dyn_cast<Argument>(Op)) {
360     MarkArgumentLive(A);
361   } else if (CallInst *CI = dyn_cast<CallInst>(Op)) {
362     if (Function *F = CI->getCalledFunction())
363       MarkRetValLive(F);
364   } else if (InvokeInst *II = dyn_cast<InvokeInst>(Op)) {
365     if (Function *F = II->getCalledFunction())
366       MarkRetValLive(F);
367   }
368 }
369
370 // RemoveDeadArgumentsFromFunction - We know that F has dead arguments, as
371 // specified by the DeadArguments list.  Transform the function and all of the
372 // callees of the function to not have these arguments.
373 //
374 void DAE::RemoveDeadArgumentsFromFunction(Function *F) {
375   // Start by computing a new prototype for the function, which is the same as
376   // the old function, but has fewer arguments.
377   const FunctionType *FTy = F->getFunctionType();
378   std::vector<const Type*> Params;
379
380   for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; ++I)
381     if (!DeadArguments.count(I))
382       Params.push_back(I->getType());
383
384   const Type *RetTy = FTy->getReturnType();
385   if (DeadRetVal.count(F)) {
386     RetTy = Type::VoidTy;
387     DeadRetVal.erase(F);
388   }
389
390   // Work around LLVM bug PR56: the CWriter cannot emit varargs functions which
391   // have zero fixed arguments.
392   //
393   // FIXME: once this bug is fixed in the CWriter, this hack should be removed.
394   //
395   bool ExtraArgHack = false;
396   if (Params.empty() && FTy->isVarArg()) {
397     ExtraArgHack = true;
398     Params.push_back(Type::IntTy);
399   }
400
401   FunctionType *NFTy = FunctionType::get(RetTy, Params, FTy->isVarArg());
402
403   // Create the new function body and insert it into the module...
404   Function *NF = new Function(NFTy, F->getLinkage(), F->getName());
405   NF->setCallingConv(F->getCallingConv());
406   F->getParent()->getFunctionList().insert(F, NF);
407
408   // Loop over all of the callers of the function, transforming the call sites
409   // to pass in a smaller number of arguments into the new function.
410   //
411   std::vector<Value*> Args;
412   while (!F->use_empty()) {
413     CallSite CS = CallSite::get(F->use_back());
414     Instruction *Call = CS.getInstruction();
415
416     // Loop over the operands, deleting dead ones...
417     CallSite::arg_iterator AI = CS.arg_begin();
418     for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end();
419          I != E; ++I, ++AI)
420       if (!DeadArguments.count(I))      // Remove operands for dead arguments
421         Args.push_back(*AI);
422
423     if (ExtraArgHack)
424       Args.push_back(Constant::getNullValue(Type::IntTy));
425
426     // Push any varargs arguments on the list
427     for (; AI != CS.arg_end(); ++AI)
428       Args.push_back(*AI);
429
430     Instruction *New;
431     if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) {
432       New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(),
433                            Args, "", Call);
434       cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv());
435     } else {
436       New = new CallInst(NF, Args, "", Call);
437       cast<CallInst>(New)->setCallingConv(CS.getCallingConv());
438       if (cast<CallInst>(Call)->isTailCall())
439         cast<CallInst>(New)->setTailCall();
440     }
441     Args.clear();
442
443     if (!Call->use_empty()) {
444       if (New->getType() == Type::VoidTy)
445         Call->replaceAllUsesWith(Constant::getNullValue(Call->getType()));
446       else {
447         Call->replaceAllUsesWith(New);
448         std::string Name = Call->getName();
449         Call->setName("");
450         New->setName(Name);
451       }
452     }
453
454     // Finally, remove the old call from the program, reducing the use-count of
455     // F.
456     Call->getParent()->getInstList().erase(Call);
457   }
458
459   // Since we have now created the new function, splice the body of the old
460   // function right into the new function, leaving the old rotting hulk of the
461   // function empty.
462   NF->getBasicBlockList().splice(NF->begin(), F->getBasicBlockList());
463
464   // Loop over the argument list, transfering uses of the old arguments over to
465   // the new arguments, also transfering over the names as well.  While we're at
466   // it, remove the dead arguments from the DeadArguments list.
467   //
468   for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(),
469          I2 = NF->arg_begin();
470        I != E; ++I)
471     if (!DeadArguments.count(I)) {
472       // If this is a live argument, move the name and users over to the new
473       // version.
474       I->replaceAllUsesWith(I2);
475       I2->setName(I->getName());
476       ++I2;
477     } else {
478       // If this argument is dead, replace any uses of it with null constants
479       // (these are guaranteed to only be operands to call instructions which
480       // will later be simplified).
481       I->replaceAllUsesWith(Constant::getNullValue(I->getType()));
482       DeadArguments.erase(I);
483     }
484
485   // If we change the return value of the function we must rewrite any return
486   // instructions.  Check this now.
487   if (F->getReturnType() != NF->getReturnType())
488     for (Function::iterator BB = NF->begin(), E = NF->end(); BB != E; ++BB)
489       if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator())) {
490         new ReturnInst(0, RI);
491         BB->getInstList().erase(RI);
492       }
493
494   // Now that the old function is dead, delete it.
495   F->getParent()->getFunctionList().erase(F);
496 }
497
498 bool DAE::runOnModule(Module &M) {
499   // First phase: loop through the module, determining which arguments are live.
500   // We assume all arguments are dead unless proven otherwise (allowing us to
501   // determine that dead arguments passed into recursive functions are dead).
502   //
503   DEBUG(std::cerr << "DAE - Determining liveness\n");
504   for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
505     SurveyFunction(*I);
506
507   // Loop over the instructions to inspect, propagating liveness among arguments
508   // and return values which are MaybeLive.
509
510   while (!InstructionsToInspect.empty()) {
511     Instruction *I = InstructionsToInspect.back();
512     InstructionsToInspect.pop_back();
513
514     if (ReturnInst *RI = dyn_cast<ReturnInst>(I)) {
515       // For return instructions, we just have to check to see if the return
516       // value for the current function is known now to be alive.  If so, any
517       // arguments used by it are now alive, and any call instruction return
518       // value is alive as well.
519       if (LiveRetVal.count(RI->getParent()->getParent()))
520         MarkReturnInstArgumentLive(RI);
521
522     } else {
523       CallSite CS = CallSite::get(I);
524       assert(CS.getInstruction() && "Unknown instruction for the I2I list!");
525
526       Function *Callee = CS.getCalledFunction();
527
528       // If we found a call or invoke instruction on this list, that means that
529       // an argument of the function is a call instruction.  If the argument is
530       // live, then the return value of the called instruction is now live.
531       //
532       CallSite::arg_iterator AI = CS.arg_begin();  // ActualIterator
533       for (Function::arg_iterator FI = Callee->arg_begin(),
534              E = Callee->arg_end(); FI != E; ++AI, ++FI) {
535         // If this argument is another call...
536         CallSite ArgCS = CallSite::get(*AI);
537         if (ArgCS.getInstruction() && LiveArguments.count(FI))
538           if (Function *Callee = ArgCS.getCalledFunction())
539             MarkRetValLive(Callee);
540       }
541     }
542   }
543
544   // Now we loop over all of the MaybeLive arguments, promoting them to be live
545   // arguments if one of the calls that uses the arguments to the calls they are
546   // passed into requires them to be live.  Of course this could make other
547   // arguments live, so process callers recursively.
548   //
549   // Because elements can be removed from the MaybeLiveArguments set, copy it to
550   // a temporary vector.
551   //
552   std::vector<Argument*> TmpArgList(MaybeLiveArguments.begin(),
553                                     MaybeLiveArguments.end());
554   for (unsigned i = 0, e = TmpArgList.size(); i != e; ++i) {
555     Argument *MLA = TmpArgList[i];
556     if (MaybeLiveArguments.count(MLA) &&
557         isMaybeLiveArgumentNowLive(MLA))
558       MarkArgumentLive(MLA);
559   }
560
561   // Recover memory early...
562   CallSites.clear();
563
564   // At this point, we know that all arguments in DeadArguments and
565   // MaybeLiveArguments are dead.  If the two sets are empty, there is nothing
566   // to do.
567   if (MaybeLiveArguments.empty() && DeadArguments.empty() &&
568       MaybeLiveRetVal.empty() && DeadRetVal.empty())
569     return false;
570
571   // Otherwise, compact into one set, and start eliminating the arguments from
572   // the functions.
573   DeadArguments.insert(MaybeLiveArguments.begin(), MaybeLiveArguments.end());
574   MaybeLiveArguments.clear();
575   DeadRetVal.insert(MaybeLiveRetVal.begin(), MaybeLiveRetVal.end());
576   MaybeLiveRetVal.clear();
577
578   LiveArguments.clear();
579   LiveRetVal.clear();
580
581   NumArgumentsEliminated += DeadArguments.size();
582   NumRetValsEliminated   += DeadRetVal.size();
583   while (!DeadArguments.empty())
584     RemoveDeadArgumentsFromFunction((*DeadArguments.begin())->getParent());
585
586   while (!DeadRetVal.empty())
587     RemoveDeadArgumentsFromFunction(*DeadRetVal.begin());
588   return true;
589 }