Add hack to only consider indirect calls indirect if they do more than cast

their source function


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4723 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2002-11-17 22:17:12 +00:00
parent ae5f603665
commit ed806bf9fc

View File

@@ -11,7 +11,7 @@
#include <vector> #include <vector>
namespace { namespace {
Statistic<double> TotalNumCallees("totalcallees", Statistic<> TotalNumCallees("totalcallees",
"Total number of callee functions at all indirect call sites"); "Total number of callee functions at all indirect call sites");
Statistic<> NumIndirectCalls("numindirect", Statistic<> NumIndirectCalls("numindirect",
"Total number of indirect call sites in the program"); "Total number of indirect call sites in the program");
@@ -39,6 +39,14 @@ namespace {
static RegisterAnalysis<DSGraphStats> Z("dsstats", "DS Graph Statistics"); static RegisterAnalysis<DSGraphStats> Z("dsstats", "DS Graph Statistics");
} }
static bool isIndirectCallee(Value *V) {
if (isa<Function>(V)) return false;
if (CastInst *CI = dyn_cast<CastInst>(V))
return isIndirectCallee(CI->getOperand(0));
return true;
}
void DSGraphStats::countCallees(const Function& F, void DSGraphStats::countCallees(const Function& F,
const DSGraph& tdGraph) const DSGraph& tdGraph)
@@ -47,7 +55,7 @@ void DSGraphStats::countCallees(const Function& F,
const std::vector<DSCallSite>& callSites = tdGraph.getFunctionCalls(); const std::vector<DSCallSite>& callSites = tdGraph.getFunctionCalls();
for (unsigned i=0, N = callSites.size(); i < N; ++i) for (unsigned i=0, N = callSites.size(); i < N; ++i)
if (callSites[i].getCallInst().getCalledFunction() == NULL) if (isIndirectCallee(callSites[i].getCallInst().getCalledValue()))
{ // This is an indirect function call { // This is an indirect function call
std::vector<GlobalValue*> Callees = std::vector<GlobalValue*> Callees =
callSites[i].getCallee().getNode()->getGlobals(); callSites[i].getCallee().getNode()->getGlobals();
@@ -66,10 +74,10 @@ void DSGraphStats::countCallees(const Function& F,
TotalNumCallees += totalNumCallees; TotalNumCallees += totalNumCallees;
NumIndirectCalls += numIndirectCalls; NumIndirectCalls += numIndirectCalls;
std::cout << " In function " << F.getName() << " : " if (numIndirectCalls)
<< (double) (numIndirectCalls == 0? 0.0 std::cout << " In function " << F.getName() << ": "
: (totalNumCallees / (double) numIndirectCalls)) << (totalNumCallees / (double) numIndirectCalls)
<< " avg. callees per indirect call\n"; << " average callees per indirect call\n";
} }