Call Graph Analysis

Hi,

I have been working on implementing new analysis for a LLVM module. For that, I need that Call Graph of the module. Inside the CallGraph file, the constructor has been declared “protected” hence I can’t define its instance and thus use the CallGraph for further analysis.

So, what are the ways of building and using Call Graph of a module. Do I need to make my new analysis as another PASS?

Thanks

–Kapil

Yes, you should make it a pass, and then say that that pass requires
call graph information like this:

  AU.addRequired<CallGraph>();

The pass manager's responsible for providing that analysis information
for you. See how it's used in other passes for examples.

-bw

Hi,

I have made my optimization as an extension of ModulePass as suggested in last mail. I included “addRequired” in getAnalysisUsage function.
The application compiles fine but while linking, I get following errors:
“undefined reference to llvm::CallGraphLinkVar”
"undefined reference to llvm::CallGraph::ID

The above error is at point where I refer to individual instruction. I followed the conventions used in GlobalModRefPass, which is also an extension of ModulePass. Is there any other convention which needs to be followed?

Thanks

–Kapil

I would think that that is enough. Where are you adding this module? Is it part of the libLLVMipa.a library? Or is it another library? Make sure that when you link your application, you're analysis is either part of libLLVMipa.a or has that library on the link line.

-bw

Hi,

I am not making this application part of LLVM library although I do link the libLLVMipa library ( actually I am using llvm-config --libs all option in the Makefile which links all the libraries).

Is it necessary to make it part of LLVM library?

Thanks for you responses.

–Kapil

Hi,

I am not making this application part of LLVM library although I do link the libLLVMipa library ( actually I am using llvm-config --libs all option in the Makefile which links all the libraries).

Is it necessary to make it part of LLVM library?

It's probably not necessary, but keep in mind that linkers will throw away symbols that it doesn't think are used. Make sure that you're doing the linking correctly. I'm not very familiar with the "llvm-config" tool, so I can't really say what's going on here. Just use "nm" and other tools to see where these symbols are used/defined and make sure that you're doing the "right thing".

-bw