// instructions will be constant folded if the specified value is constant.
//
unsigned InlineCostAnalyzer::FunctionInfo::
- CountCodeReductionForConstant(Value *V) {
+CountCodeReductionForConstant(Value *V) {
unsigned Reduction = 0;
for (Value::use_iterator UI = V->use_begin(), E = V->use_end(); UI != E; ++UI)
if (isa<BranchInst>(*UI) || isa<SwitchInst>(*UI)) {
const unsigned NumSucc = TI.getNumSuccessors();
unsigned Instrs = 0;
for (unsigned I = 0; I != NumSucc; ++I)
- Instrs += TI.getSuccessor(I)->size();
+ Instrs += Metrics.NumBBInsts[TI.getSuccessor(I)];
// We don't know which blocks will be eliminated, so use the average size.
Reduction += InlineConstants::InstrCost*Instrs*(NumSucc-1)/NumSucc;
} else if (CallInst *CI = dyn_cast<CallInst>(*UI)) {
/// from the specified block.
void CodeMetrics::analyzeBasicBlock(const BasicBlock *BB) {
++NumBlocks;
-
+ unsigned NumInstsInThisBB = 0;
for (BasicBlock::const_iterator II = BB->begin(), E = BB->end();
II != E; ++II) {
if (isa<PHINode>(II)) continue; // PHI nodes don't count.
}
++NumInsts;
+ ++NumInstsInThisBB;
}
if (isa<ReturnInst>(BB->getTerminator()))
// function which is extremely undefined behavior.
if (isa<IndirectBrInst>(BB->getTerminator()))
NeverInline = true;
+
+ // Remember NumInsts for this BB.
+ NumBBInsts[BB] = NumInstsInThisBB;
}
/// analyzeFunction - Fill in the current structure with information gleaned
FunctionInfo &CallerFI = CachedFunctionInfo[Caller];
// For small functions we prefer to recalculate the cost for better accuracy.
- if (!CallerFI.Metrics.NumBlocks || CallerFI.Metrics.NumInsts < 100) {
+ if (CallerFI.Metrics.NumBlocks < 10 || CallerFI.Metrics.NumInsts < 1000) {
resetCachedCostInfo(Caller);
return;
}
CallerFI.Metrics.NumCalls += CalleeFI.Metrics.NumCalls;
CallerFI.Metrics.NumVectorInsts += CalleeFI.Metrics.NumVectorInsts;
CallerFI.Metrics.NumRets += CalleeFI.Metrics.NumRets;
+
+ // analyzeBasicBlock counts each function argument as an inst.
+ if (CallerFI.Metrics.NumInsts >= Callee->arg_size())
+ CallerFI.Metrics.NumInsts -= Callee->arg_size();
+ else
+ CallerFI.Metrics.NumInsts = 0;
}
// We are not updating the argumentweights. We have already determined that
// Caller is a fairly large function, so we accept the loss of precision.