- // Loop over the instructions to inspect, propagating liveness among arguments
- // and return values which are MaybeLive.
- while (!InstructionsToInspect.empty()) {
- Instruction *I = InstructionsToInspect.back();
- InstructionsToInspect.pop_back();
-
- if (ReturnInst *RI = dyn_cast<ReturnInst>(I)) {
- // For return instructions, we just have to check to see if the return
- // value for the current function is known now to be alive. If so, any
- // arguments used by it are now alive, and any call instruction return
- // value is alive as well.
- if (LiveRetVal.count(RI->getParent()->getParent()))
- MarkReturnInstArgumentLive(RI);
-
- } else {
- CallSite CS = CallSite::get(I);
- assert(CS.getInstruction() && "Unknown instruction for the I2I list!");
-
- Function *Callee = CS.getCalledFunction();
-
- // If we found a call or invoke instruction on this list, that means that
- // an argument of the function is a call instruction. If the argument is
- // live, then the return value of the called instruction is now live.
- //
- CallSite::arg_iterator AI = CS.arg_begin(); // ActualIterator
- for (Function::arg_iterator FI = Callee->arg_begin(),
- E = Callee->arg_end(); FI != E; ++AI, ++FI) {
- // If this argument is another call...
- CallSite ArgCS = CallSite::get(*AI);
- if (ArgCS.getInstruction() && LiveArguments.count(FI))
- if (Function *Callee = ArgCS.getCalledFunction())
- MarkRetValLive(Callee);
- }
- }
- }
-
- // Now we loop over all of the MaybeLive arguments, promoting them to be live
- // arguments if one of the calls that uses the arguments to the calls they are
- // passed into requires them to be live. Of course this could make other
- // arguments live, so process callers recursively.
- //
- // Because elements can be removed from the MaybeLiveArguments set, copy it to
- // a temporary vector.
- //
- std::vector<Argument*> TmpArgList(MaybeLiveArguments.begin(),
- MaybeLiveArguments.end());
- for (unsigned i = 0, e = TmpArgList.size(); i != e; ++i) {
- Argument *MLA = TmpArgList[i];
- if (MaybeLiveArguments.count(MLA) &&
- isMaybeLiveArgumentNowLive(MLA))
- MarkArgumentLive(MLA);