[LLVMdev] Walking thru CallGraph bottom up

Simone Atzeni simone.at at gmail.com
Sun Mar 1 23:12:57 PST 2015


Hi Herbie,

thanks for you answer and explanation.

> 
> Also, if any of the functions are external, you are completely stuck (unless you put everything together with lld).


I am indeed having a problem regarding external function.
I my program is just one file everything work and I can access all the functions.
However, if it has multiple files I have a lot of unresolved pointers to external functions.
I am creating separately all the byte code files for each file of my program.
Then I link all of them together with llvm-link, I thought it was enough but actually I can not access the functions that are in other files even if I am link all of them together.

Do you have any idea/suggestion how to solve this problem?

Thanks!
Best,
Simone


> On Feb 28, 2015, at 14:30, Herbie Robinson <HerbieRobinson at verizon.net> wrote:
> 
> On 2/24/15 2:27 PM, Simone Atzeni wrote:
>> Hi all,
>> 
>> I would like to create a Pass that given an IR instruction walks starting from that instruction up to the main function
>> to identify all the functions call that have been made to call that instruction.
>> 
>> Is it possible? What kind of Pass should I create?
>> 
> Technically, that's not a pass, because a pass is an algorithm for going through all the Instructions.
> 
> What you want to do is only possible to do for internal functions if there are no function variables in play.
> 
> The Instruction class has a method to get to the basic block which has a method to get to the Funciton.  In both cases, the method is called getParent().  Once you get the Function, you can find all the internal uses using the use chain from the Function.
> 
> Start looking at the user class here:
> 
> http://llvm.org/doxygen/classllvm_1_1User.html
> 
> When you go through the user chain, you will find all sorts of instructions and possibly other things.  If you find anything other than a call Instruction, you have hit upon a case that's more difficult to handle (related to using function pointer).  If you run whatever analysis you are trying to do after all the optimization passes, value propagation may have covered some of the function pointer cases; so, you want to recurse through PHI nodes, too.
> 
> Also, if any of the functions are external, you are completely stuck (unless you put everything together with lld).





More information about the llvm-dev mailing list