- for (Value::use_iterator I = F.use_begin(), E = F.use_end(); I != E; ++I)
- if (!isa<Instruction>(*I))
- return false; // Used by a non-instruction, do not transform
- else {
- CallSite CS = CallSite::get(cast<Instruction>(*I));
- if (CS.getInstruction() == 0 ||
- CS.getCalledFunction() != &F)
- return false; // Not a direct call site?
-
- // Check out all of the potentially constant arguments
- CallSite::arg_iterator AI = CS.arg_begin();
- Function::arg_iterator Arg = F.arg_begin();
- for (unsigned i = 0, e = ArgumentConstants.size(); i != e;
- ++i, ++AI, ++Arg) {
- if (*AI == &F) return false; // Passes the function into itself
-
- if (!ArgumentConstants[i].second) {
- if (Constant *C = dyn_cast<Constant>(*AI)) {
- if (!ArgumentConstants[i].first)
- ArgumentConstants[i].first = C;
- else if (ArgumentConstants[i].first != C) {
- // Became non-constant
- ArgumentConstants[i].second = true;
- ++NumNonconstant;
- if (NumNonconstant == ArgumentConstants.size()) return false;
- }
- } else if (*AI != &*Arg) { // Ignore recursive calls with same arg
- // This is not a constant argument. Mark the argument as
- // non-constant.
- ArgumentConstants[i].second = true;
- ++NumNonconstant;
- if (NumNonconstant == ArgumentConstants.size()) return false;
- }
- }
+ // Check out all of the potentially constant arguments. Note that we don't
+ // inspect varargs here.
+ CallSite::arg_iterator AI = CS.arg_begin();
+ Function::arg_iterator Arg = F.arg_begin();
+ for (unsigned i = 0, e = ArgumentConstants.size(); i != e;
+ ++i, ++AI, ++Arg) {
+
+ // If this argument is known non-constant, ignore it.
+ if (ArgumentConstants[i].second)
+ continue;
+
+ Constant *C = dyn_cast<Constant>(*AI);
+ if (C && ArgumentConstants[i].first == 0) {
+ ArgumentConstants[i].first = C; // First constant seen.
+ } else if (C && ArgumentConstants[i].first == C) {
+ // Still the constant value we think it is.
+ } else if (*AI == &*Arg) {
+ // Ignore recursive calls passing argument down.
+ } else {
+ // Argument became non-constant. If all arguments are non-constant now,
+ // give up on this function.
+ if (++NumNonconstant == ArgumentConstants.size())
+ return false;
+ ArgumentConstants[i].second = true;