[llvm-dev] Need help in understanding CallSite

410 views
Skip to first unread message

Nagaraju Mekala via llvm-dev

unread,
Feb 21, 2021, 6:07:41 AM2/21/21
to LLVM Developers Mailing List
Hi All,

I have a custom Pass which will identify a few functions in the .cpp
code and process them.
It was working fine for almost all the functions except for a function
which has class objects as its arguments.

Details:
For a particular function the CallSite CS(*iUse); CS is zero. When I
debugged the code the CallSite was expecting the *iUse to be InstTy
but this particular function is having the type UnaryConstantExpr. Due
to this the CS is zero.

I want to understand why this specific function has the UnaryConstantExpr type?
Any reference to documents or links will be a great help.

CallSite.h:
static CallSiteBase get(ValTy *V) {
if (InstrTy *II = dyn_cast<InstrTy>(V)) {

CustomPass:
//aFuncs has the custom functions list from .cpp
for(AFuncList::iterator iFunc=aFuncs.begin(); iFunc!=aFuncs.end(); iFunc++){
Function *f = *iFunc;
for(Value::user_iterator iUse = f->user_begin(); iUse !=
f->user_end(); iUse++){
CallSite CS(*iUse);
if ( CS ){
BasicBlock *bb = CS.getInstruction()->getParent();
-----
---

Please let me know if more details are needed.

Thanks in Advance,
Nagaraju
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

Mircea Trofin via llvm-dev

unread,
Feb 21, 2021, 11:40:35 AM2/21/21
to Nagaraju Mekala, LLVM Developers Mailing List
CallSite and CallSiteBase were removed in fdbf493a705c. I'm assuming you're working on a branch before that. To future-proof the code, it'd be probably best to not use CallSite, and instead use CallBase (an Instruction, base class to CallInst, CallBrInst or InvokeInst) and get the information from it, e.g. getCalledOperand.

For your case, could it be that the use of the function is not a call, but, for example, an expression taking the address of the function? When debugging, I find it useful to call dump() on the various objects of interest, it very quickly reveals what's happening.

Nagaraju Mekala via llvm-dev

unread,
Feb 22, 2021, 8:49:58 AM2/22/21
to Mircea Trofin, LLVM Developers Mailing List
Hi Mircea,

Thanks for the reply.

On Sun, Feb 21, 2021 at 10:10 PM Mircea Trofin <mtr...@google.com> wrote:
>
> CallSite and CallSiteBase were removed in fdbf493a705c. I'm assuming you're working on a branch before that. To future-proof the code, it'd be probably best to not use CallSite, and instead use CallBase (an Instruction, base class to CallInst, CallBrInst or InvokeInst) and get the information from it, e.g. getCalledOperand.
>

Sorry I forgot to mention the version. I am using the LLVM 3.9 and
have some tool dependencies with the version so had to stay on this
older release.

> For your case, could it be that the use of the function is not a call, but, for example, an expression taking the address of the function? When debugging, I find it useful to call dump() on the various objects of interest, it very quickly reveals what's happening.
>

This is definitely a function call, after using the dump() and
analyzing the IR I found that <bitcast> is being used. Due to
<bitcast> the f->user_begin() is not getting the proper InstTy.

Thanks,
Nagaraju

Reply all
Reply to author
Forward
0 new messages