How to dynamically profile LLVM IR, i.e., doing things along the program execution?

Hi, all

I am wondering if it is possible to dynamically profile LLVM IR? For example, if I have a

void foo(){
A a;; //invoke a virtual function of class A

Assume we don’t know which “goo()" of class “A” will be executed at run time. We may want to print the body of goo() as well as the bodies of the function called by goo() and etc., or do something along the execution trace.

How can we do this kind of dynamic profiling? I recently learned some LLVM basics. It seems to me that the purpose of LLVM passes is static profiling, right?

Thanks for your ideas.


The DSA CallTargets pass can get you a list of possible targets for an indirect function call. I don’t know of a pass that does this. However, it is trivial to write an LLVM pass that adds code before every indirect function call and prints out the address of the function that will be called. Using that information, you can build a dynamic call graph. Regards, John Criswell