Get instance of CallGraph of a module in the pass

Hello,

I want an instance of CallGraph in my pass. By looking at -dot-callgraph source, I’ve tried something like this:

CallGraphWrapperPass *CGWP = new CallGraphWrapperPass();

PM.add(CGWP);

CallGraph *CG = &CGWP->getCallGraph();

PM.add(new MyPass(CG));

I get the following error:

/home/riyad/installs/llvm-3.7.0/include/llvm/PassSupport.h:95:38: error: no matching constructor for initialization of

‘MyPass’

Pass *callDefaultCtor() { return new PassName(); }

My guess is pass manager needs pass with default constructor. Is there any easy way to get instance of call graph in my pass?

Thanks in Advance,
Riyad

Hi,

you could require the Call Graph pass:

void MyPass::getAnalysisUsage(AnalysisUsage &AU) const {

AU.addRequired();
}

and then get the result at some point in your pass:

CallGraph &CG = getAnalysis().getCallGraph();

I believe this works for you.

Hi Victor,

Thanks!

One more question, why “llvm.dbg.declare” and “llvm.dbg.value” are also included in the call graph? These functions are compiler intrinsic for back-end binary generation.

Riyad