[llvm-dev] How to get the arguments of a function call in LLVM?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[llvm-dev] How to get the arguments of a function call in LLVM?

Chris Lattner via llvm-dev
Hello,

I am using the following to capture the values of the arguments in a call function:

        for (auto &BB : F) {
                for (auto &II : BB) {
                if (CallInst *c = dyn_cast <CallInst> (&II)){
                                if ( Function *func = c->getCalledFunction()){
                                        if ( func->getName() =="__kmpc_for_static_init_4" ||
                                          func->getName() == "__kmpc_for_static_fini" )
                                        {
                                                errs() << func->getName();
                                                errs() << "\n";
                                                for(auto arg = func->arg_begin(); arg != func->arg_end(); ++arg) {
                                                        errs() << *arg << "\n";
                                                if(auto* ci = dyn_cast<ConstantInt>(arg))
                                                        errs() << ci->getValue() << "\n";
                                                        }
                                                }
                                        }
                                }
                        }
                }

I am looking for two specific calls for OMP in the *.ll file. For the following:

call void @__kmpc_for_static_init_4(%struct.ident_t* @0, i32 %17, i32 34, i32* %8, i32* %5, i32* %6, i32* %7, i32 1, i32 1)

I am able to see it and get the following:
__kmpc_for_static_init_4
%struct.ident_t* %0
i32 %1
i32 %2
i32* %3
i32* %4
i32* %5
i32* %6
i32 %7
i32 %8
The three arguments ( third ( schedule) and the last two; loop increment and chunk size are constant). The innermost loop should get them but it seems the test command fails on these three arguments. Also, the argument variable are different from the actual variable from the *.ll file.

Any comments.

Thanks,

--
Abid M. Malik
******************************************************

 

_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] How to get the arguments of a function call in LLVM?

Chris Lattner via llvm-dev
I think you need to get the arguments from the CallInst, not func. func is getting the arguments from the function defintion. If you want the arguments from the call site you want them from CallInst.
~Craig


On Thu, Jan 16, 2020 at 10:12 AM Abid Malik via llvm-dev <[hidden email]> wrote:
Hello,

I am using the following to capture the values of the arguments in a call function:

        for (auto &BB : F) {
                for (auto &II : BB) {
                if (CallInst *c = dyn_cast <CallInst> (&II)){
                                if ( Function *func = c->getCalledFunction()){
                                        if ( func->getName() =="__kmpc_for_static_init_4" ||
                                          func->getName() == "__kmpc_for_static_fini" )
                                        {
                                                errs() << func->getName();
                                                errs() << "\n";
                                                for(auto arg = func->arg_begin(); arg != func->arg_end(); ++arg) {
                                                        errs() << *arg << "\n";
                                                if(auto* ci = dyn_cast<ConstantInt>(arg))
                                                        errs() << ci->getValue() << "\n";
                                                        }
                                                }
                                        }
                                }
                        }
                }

I am looking for two specific calls for OMP in the *.ll file. For the following:

call void @__kmpc_for_static_init_4(%struct.ident_t* @0, i32 %17, i32 34, i32* %8, i32* %5, i32* %6, i32* %7, i32 1, i32 1)

I am able to see it and get the following:
__kmpc_for_static_init_4
%struct.ident_t* %0
i32 %1
i32 %2
i32* %3
i32* %4
i32* %5
i32* %6
i32 %7
i32 %8
The three arguments ( third ( schedule) and the last two; loop increment and chunk size are constant). The innermost loop should get them but it seems the test command fails on these three arguments. Also, the argument variable are different from the actual variable from the *.ll file.

Any comments.

Thanks,

--
Abid M. Malik
******************************************************

 
_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] How to get the arguments of a function call in LLVM?

Chris Lattner via llvm-dev
In reply to this post by Chris Lattner via llvm-dev

  Hi Abid,

  CallInst has a member getArgOperand(No) which returns the values passed
  at the call site. The code below iterates over function arguments
  instead.

  Cheers,
    Johannes




---------------------------------------
Johannes Doerfert
Researcher

Argonne National Laboratory
Lemont, IL 60439, USA

[hidden email]

________________________________________
From: llvm-dev <[hidden email]> on behalf of Abid Malik via llvm-dev <[hidden email]>
Sent: Thursday, January 16, 2020 12:11
To: [hidden email]
Subject: [llvm-dev] How to get the arguments of a function call in LLVM?

Hello,

I am using the following to capture the values of the arguments in a call function:

        for (auto &BB : F) {
                for (auto &II : BB) {
                if (CallInst *c = dyn_cast <CallInst> (&II)){
                                if ( Function *func = c->getCalledFunction()){
                                        if ( func->getName() =="__kmpc_for_static_init_4" ||
                                          func->getName() == "__kmpc_for_static_fini" )
                                        {
                                                errs() << func->getName();
                                                errs() << "\n";
                                                for(auto arg = func->arg_begin(); arg != func->arg_end(); ++arg) {
                                                        errs() << *arg << "\n";
                                                if(auto* ci = dyn_cast<ConstantInt>(arg))
                                                        errs() << ci->getValue() << "\n";
                                                        }
                                                }
                                        }
                                }
                        }
                }

I am looking for two specific calls for OMP in the *.ll file. For the following:

call void @__kmpc_for_static_init_4(%struct.ident_t* @0, i32 %17, i32 34, i32* %8, i32* %5, i32* %6, i32* %7, i32 1, i32 1)

I am able to see it and get the following:
__kmpc_for_static_init_4
%struct.ident_t* %0
i32 %1
i32 %2
i32* %3
i32* %4
i32* %5
i32* %6
i32 %7
i32 %8
The three arguments ( third ( schedule) and the last two; loop increment and chunk size are constant). The innermost loop should get them but it seems the test command fails on these three arguments. Also, the argument variable are different from the actual variable from the *.ll file.

Any comments.

Thanks,

--
Abid M. Malik
******************************************************


_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev