Get the call graph SCCs from a function pass

Hello,

I'm writing a Function Pass. This function pass needs access to the
CallGraph and CallGraph SCCs. Is there any way I can get CallGraph
information without changing my pass to a CallGraphSCCPass ?

Thanks,

Does getAnalysis<CallGraph>() work?

But I'm not sure if using a FunctionPass to access Callgraph data is a
good idea, transformations can
change it (for example dead code elimination can remove edges).

Best regards,
--Edwin

> Hello,
>
> I'm writing a Function Pass. This function pass needs access to the
> CallGraph and CallGraph SCCs. Is there any way I can get CallGraph
> information without changing my pass to a CallGraphSCCPass ?

Does getAnalysis<CallGraph>() work?

AFAIK, it's not a pass.

But I'm not sure if using a FunctionPass to access Callgraph data is a
good idea, transformations can
change it (for example dead code elimination can remove edges).

I'm just using it to interpret profiling information correctly; in
that respect, it doesn't matter if transformations change the IR, so
long as the CallGraph data reflects the IR against which profiling was
done.

Nick

  

> Hello,
>
> I'm writing a Function Pass. This function pass needs access to the
> CallGraph and CallGraph SCCs. Is there any way I can get CallGraph
> information without changing my pass to a CallGraphSCCPass ?

Does getAnalysis<CallGraph>() work?

AFAIK, it's not a pass.

It is, see lib/Analysis/IPA/CallGraph.cpp:

static RegisterAnalysisGroup<CallGraph> X("Call Graph");
static RegisterPass<BasicCallGraph>
Y("basiccg", "Basic CallGraph Construction", false, true);
static RegisterAnalysisGroup<CallGraph, true> Z(Y);

I know that using getAnalysis<CallGraph> works in a ModulePass, but
never tried it in a FunctionPass.

But I'm not sure if using a FunctionPass to access Callgraph data is a
good idea, transformations can
change it (for example dead code elimination can remove edges).

I'm just using it to interpret profiling information correctly; in
that respect, it doesn't matter if transformations change the IR, so
long as the CallGraph data reflects the IR against which profiling was
done.
  
Ok.

Best regards,
--Edwin

Does getAnalysis<CallGraph>() work?

Thanks Edwin, that works!

What about the CallGraphSCC ? It looks like one can declare a
CallGraphSCCPass, but I don't see any other way to get the SCCs of the
call graph.

You can use scc_iterator from ADT/SCCIterator.h, that gives you a
std::vector of functions that are part of the same SCC, on each iteration.

Have a look at tools/opt/PrintSCC.cpp for an example, or at the
implementation of CallGraphSCCPass in lib/Analysis/IPA/

Best regards,
--Edwin