-
-/// SurveyUse - This looks at a single use of an argument or return value
-/// and determines if it should be alive or not. Adds this use to MaybeLiveUses
-/// if it causes the used value to become MaybeAlive.
-///
-/// RetValNum is the return value number to use when this use is used in a
-/// return instruction. This is used in the recursion, you should always leave
-/// it at 0.
-DAE::Liveness DAE::SurveyUse(Value::use_iterator U, UseVector &MaybeLiveUses,
- unsigned RetValNum) {
- Value *V = *U;
- if (ReturnInst *RI = dyn_cast<ReturnInst>(V)) {
- // The value is returned from another function. It's only live when the
- // caller's return value is live
- RetOrArg Use = CreateRet(RI->getParent()->getParent(), RetValNum);
- // We might be live, depending on the liveness of Use
- return IsMaybeLive(Use, MaybeLiveUses);
- }
- if (InsertValueInst *IV = dyn_cast<InsertValueInst>(V)) {
- if (U.getOperandNo() != InsertValueInst::getAggregateOperandIndex()
- && IV->hasIndices())
- // The use we are examining is inserted into an aggregate. Our liveness
- // depends on all uses of that aggregate, but if it is used as a return
- // value, only index at which we were inserted counts.
- RetValNum = *IV->idx_begin();
-
- // Note that if we are used as the aggregate operand to the insertvalue,
- // we don't change RetValNum, but do survey all our uses.
-
- Liveness Result = Dead;
- for (Value::use_iterator I = IV->use_begin(),
- E = V->use_end(); I != E; ++I) {
- Result = SurveyUse(I, MaybeLiveUses, RetValNum);
- if (Result == Live)
- break;
- }
- return Result;
- }
- CallSite CS = CallSite::get(V);
- if (CS.getInstruction()) {
- Function *F = CS.getCalledFunction();
- if (F) {
- // Used in a direct call
-
- // Check for vararg. Do - 1 to skip the first operand to call (the
- // function itself).
- if (U.getOperandNo() - 1 >= F->getFunctionType()->getNumParams())
- // The value is passed in through a vararg! Must be live.
- return Live;
-
- // Value passed to a normal call. It's only live when the corresponding
- // argument (operand number - 1 to skip the function pointer operand) to
- // the called function turns out live
- RetOrArg Use = CreateArg(F, U.getOperandNo() - 1);
- return IsMaybeLive(Use, MaybeLiveUses);
- } else {
- // Used in any other way? Value must be live.
- return Live;
- }
- }
- // Used in any other way? Value must be live.
+// getArgumentLiveness - Inspect an argument, determining if is known Live
+// (used in a computation), MaybeLive (only passed as an argument to a call), or
+// Dead (not used).
+DAE::Liveness DAE::getArgumentLiveness(const Argument &A) {
+ const Function *F = A.getParent();
+
+ // If this is the return value of a struct function, it's not really dead.
+ if (F->hasStructRetAttr() && &*(F->arg_begin()) == &A)