Anomaly with CallGraph construction

Hi all,

I have been trying to build a loop nesting analysis which works interprocedurally. In order
to find the functions called inside a given loop, I am traversing the Instructions into the
BasicBlock’s that conform a Loop, and applying the code that CallGraph construction uses:

------ extract from CallGraph.cpp : 144
// Look for calls by this function.
for (Function::iterator BB = F->begin(), BBE = F->end(); BB != BBE; ++BB)
for (BasicBlock::iterator II = BB->begin(), IE = BB->end();
II != IE; ++II) {
CallSite CS(cast(II));
if (CS && !isa(II)) {
const Function *Callee = CS.getCalledFunction();
if (Callee)
Node->addCalledFunction(CS, getOrInsertFunction(Callee));
Node->addCalledFunction(CS, CallsExternalNode);

Hi Gabriel,


Summarizing, I have two questions: 1) is the CallGraph analysis "working as
intended" here?; and 2) what would be the correct approach
to modifying the proposed analysis in order to detect that randlc() is being
called in that CallInst ?

the reason that the callgraph analysis does not try to understand indirect
calls like this is that other passes are supposed to sort such things out
if they can be sorted out. If they failed then there is no point in having
the callgraph analysis try too. The main place that tries to sort out such
bitcasts is transformConstExprCastCall in InstCombineCalls.cpp. You may want
to rummage around in there to work out why it thinks removing the bitcast is

So the answers to your questions are: (1) yes, and (2) it is not a job for the
analysis - instcombine is the place to take care of this.

Ciao, Duncan.

I see, thanks Duncan. The problem was, I was not running the InstCombiner in the first place.