// performance boost we can expect if the specified value is constant.
unsigned CodeMetrics::CountBonusForConstant(Value *V) {
unsigned Bonus = 0;
+ bool indirectCallBonus = false;
for (Value::use_iterator UI = V->use_begin(), E = V->use_end(); UI != E;++UI){
User *U = *UI;
if (CallInst *CI = dyn_cast<CallInst>(U)) {
// Turning an indirect call into a direct call is a BIG win
if (CI->getCalledValue() == V)
- Bonus += InlineConstants::IndirectCallBonus;
+ indirectCallBonus = true;
}
else if (InvokeInst *II = dyn_cast<InvokeInst>(U)) {
// Turning an indirect call into a direct call is a BIG win
if (II->getCalledValue() == V)
- Bonus += InlineConstants::IndirectCallBonus;
+ indirectCallBonus = true;
}
// FIXME: Eliminating conditional branches and switches should
// also yield a per-call performance boost.
Bonus += CountBonusForConstant(&Inst);
}
}
+
+ if (indirectCallBonus) Bonus += InlineConstants::IndirectCallBonus;
+
return Bonus;
}