[llvm-dev] Finding callees of a function

mayuyu.io via llvm-dev llvm-dev at lists.llvm.org
Wed Jan 15 02:01:55 PST 2020


You should use getCalledValue()->stripPointerCasts() instead

Zhang

> 在 2020年1月15日,17:58,Tim Northover via llvm-dev <llvm-dev at lists.llvm.org> 写道:
> 
> Hi Marc,
> 
>> On Wed, 15 Jan 2020 at 09:52, Marc via llvm-dev <llvm-dev at lists.llvm.org> wrote:
>>  bool Foo:runOnModule(Module &M) {
>>    LLVMContext &C = M.getContext();
>>    for (auto &F : M) {
>>      // magic here
>> 
>> if I want to know from which function (callee) each function is called -
>> how can I do this?
> 
> To get the direct callers you would iterate through the users of F,
> and check whether it's being used as the callee operand in a CallInst
> or InvokeInst. Fortunately there's a CallSite class that abstracts
> away many of the differences. So something like:
> 
>    for (auto &U : F.getUsers()) {
>      if (auto CS = CallSite(U)) {
>        if (CS->getCalledFunction() == F)
>          doStuff(CS);
>      }
>    }
> 
>> I am aware that this will not work for calls that are made outside of
>> the analyzed module.
> 
> Also indirect calls.
> 
> Cheers.
> 
> Tim.
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev





More information about the llvm-dev mailing list