[LLVMdev] Finding call points to a function
criswell at cs.uiuc.edu
Thu Sep 10 08:00:55 PDT 2009
Nick Lewycky wrote:
> Rakesh Komuravelli wrote:
>> I am writing an LLVM Pass and I would like to know how would I do the
>> 1. I have a function foo, and I need to get all the call points calling
>> this function in each Function of the Module. The only way I can think
>> of is to iterate over the BasicBlocks of each Function, look for all the
>> Call Instructions and check if the called function is foo. I was
>> wondering if there is any other better way to do this.
> Iterate over @foo's use list.
Note that you can have indirect calls to function foo. If foo is marked
with internal linkage, then the only way it can be used indirectly is if
it has a use that is either:
a) Not a call instruction
b) Is a call instruction, but foo is passed as an argument to the function
If foo is marked with external linkage, then, in theory, external
libraries linked into the program after code generation can call foo.
If you need to deal with indirect function calls, there are some
options. First, I believe the CallGraph analysis pass provides correct
(but very conservative) information on which functions are reachable by
which indirect call instructions. If you need more accurate results,
then you can use the DSA pointer analysis code in the poolalloc project.
>> 2. Is it possible to distinguish a class method from a non class method
>> while analyzing the emitted LLVM code for a C++ program? Because, I need
>> to interpret the calls made to foo differently in a class method and in
>> a non class method.
> No. Methods turn into functions that happen to take the class type
> pointer as first argument.
There might be a hack'ish way to do this. The LLVM function name is (or
is close to) the mangled name of the original C++ function. If you're
unable to demangle the name, you should be able to tell whether the
function is a class method or a regular function.
-- John T.
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
More information about the llvm-dev