use of CallInst()

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

use of CallInst()

Ryan M. Lefever
To create a new CallInst I used to call the following constructor:

CallInst(Value *F, const std::vector<Value*> &Par, const std::string
&Name = "", Instruction *InsertBefore = 0);

However, it seems as though that constructor has been removed.  I assume
that I'm suppossed to use the following constructor, but I can't figure
out what to pass as the Args parameter (the second parameter).

CallInst (Value *F, Value *const *Args, unsigned NumArgs, const
std::string &Name="", Instruction *InsertBefore=0)

Can someone help?

Thanks,
Ryan

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: use of CallInst()

Reid Spencer-2
On Tue, 2007-03-06 at 22:44 -0600, Ryan M. Lefever wrote:

> To create a new CallInst I used to call the following constructor:
>
> CallInst(Value *F, const std::vector<Value*> &Par, const std::string
> &Name = "", Instruction *InsertBefore = 0);
>
> However, it seems as though that constructor has been removed.  I assume
> that I'm suppossed to use the following constructor, but I can't figure
> out what to pass as the Args parameter (the second parameter).
>
> CallInst (Value *F, Value *const *Args, unsigned NumArgs, const
> std::string &Name="", Instruction *InsertBefore=0)
>
> Can someone help?

Ryan, I suggest you familiarize yourself with
http://llvm.org/doxygen/classes.html and look there for help on the new
API. It is regenerated every night so it should be perpetually up to
date with CVS HEAD.

Args needs to be an array of the arguments and NumArgs needs to be the
size of the array. If you have a std::vector then you can just:

new CallInst(F, &ArgVec[0], ArgVec.size(), ...)

Reid.

>
> Thanks,
> Ryan
>
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: use of CallInst()

Ryan M. Lefever
Thanks for the help Reid!  I frequently look at the online doxygen, but
sometimes its difficult to determine the correct replacement when a
method is removed from LLVM.  In this particular case, I knew which new
CallInst constructor to use, I just couldn't figure out the proper syntax.

At any rate, I really appreciate your help!!

Reid Spencer wrote:

> On Tue, 2007-03-06 at 22:44 -0600, Ryan M. Lefever wrote:
>> To create a new CallInst I used to call the following constructor:
>>
>> CallInst(Value *F, const std::vector<Value*> &Par, const std::string
>> &Name = "", Instruction *InsertBefore = 0);
>>
>> However, it seems as though that constructor has been removed.  I assume
>> that I'm suppossed to use the following constructor, but I can't figure
>> out what to pass as the Args parameter (the second parameter).
>>
>> CallInst (Value *F, Value *const *Args, unsigned NumArgs, const
>> std::string &Name="", Instruction *InsertBefore=0)
>>
>> Can someone help?
>
> Ryan, I suggest you familiarize yourself with
> http://llvm.org/doxygen/classes.html and look there for help on the new
> API. It is regenerated every night so it should be perpetually up to
> date with CVS HEAD.
>
> Args needs to be an array of the arguments and NumArgs needs to be the
> size of the array. If you have a std::vector then you can just:
>
> new CallInst(F, &ArgVec[0], ArgVec.size(), ...)
>
> Reid.
>
>> Thanks,
>> Ryan
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> [hidden email]         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

--
Ryan M. Lefever  [http://www.ews.uiuc.edu/~lefever]

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: use of CallInst()

Ryan M. Lefever
In reply to this post by Reid Spencer-2
> Args needs to be an array of the arguments and NumArgs needs to be the
> size of the array. If you have a std::vector then you can just:
>
> new CallInst(F, &ArgVec[0], ArgVec.size(), ...)

Doesn't the code above make an assumption about how std::vector is
implemented?  If ArgVec is defined as

std::vector<Value*> ArgVec;

then &ArgVec[0] returns a Value**.  Let us define

Value** Params = &ArgVec[0];

The constructor for CallInst accesses Params using the [] operator in a
for loop.  That should only work if the std::vector<Value*> is
implemented using an array of Value*s.  I looked at the documentation
for STL and did not see anything about vector being guaranteed to be
implemented as an array.

Am I missing something?  If not, why was direct support for a
std:vector<Value*> removed from the CallInst constructor?

I apologize if I am misinterpreting things.
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: use of CallInst()

Patrick Meredith
In reply to this post by Ryan M. Lefever

On Mar 6, 2007, at 11:30 PM, Ryan M. Lefever wrote:

> Thanks for the help Reid!  I frequently look at the online doxygen,  
> but

Something else that really helps when you are unsure as how to use a  
new method is to look at passes in lib, *especially* InstCombine.  
InstCombine is always up-to-date and uses a good amount of the API.

> sometimes its difficult to determine the correct replacement when a
> method is removed from LLVM.  In this particular case, I knew which  
> new
> CallInst constructor to use, I just couldn't figure out the proper  
> syntax.
>
> At any rate, I really appreciate your help!!
>
> Reid Spencer wrote:
>> On Tue, 2007-03-06 at 22:44 -0600, Ryan M. Lefever wrote:
>>> To create a new CallInst I used to call the following constructor:
>>>
>>> CallInst(Value *F, const std::vector<Value*> &Par, const std::string
>>> &Name = "", Instruction *InsertBefore = 0);
>>>
>>> However, it seems as though that constructor has been removed.  I  
>>> assume
>>> that I'm suppossed to use the following constructor, but I can't  
>>> figure
>>> out what to pass as the Args parameter (the second parameter).
>>>
>>> CallInst (Value *F, Value *const *Args, unsigned NumArgs, const
>>> std::string &Name="", Instruction *InsertBefore=0)
>>>
>>> Can someone help?
>>
>> Ryan, I suggest you familiarize yourself with
>> http://llvm.org/doxygen/classes.html and look there for help on  
>> the new
>> API. It is regenerated every night so it should be perpetually up to
>> date with CVS HEAD.
>>
>> Args needs to be an array of the arguments and NumArgs needs to be  
>> the
>> size of the array. If you have a std::vector then you can just:
>>
>> new CallInst(F, &ArgVec[0], ArgVec.size(), ...)
>>
>> Reid.
>>
>>> Thanks,
>>> Ryan
>>>
>>> _______________________________________________
>>> LLVM Developers mailing list
>>> [hidden email]         http://llvm.cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> [hidden email]         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
> --
> Ryan M. Lefever  [http://www.ews.uiuc.edu/~lefever]
>
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: use of CallInst()

Gordon Henriksen-3
In reply to this post by Ryan M. Lefever
On 2007-03-07, at 06:18, Ryan M. Lefever wrote:

>> Args needs to be an array of the arguments and NumArgs needs to be  
>> the size of the array. If you have a std::vector then you can just:
>>
>> new CallInst(F, &ArgVec[0], ArgVec.size(), ...)
>
> Doesn't the code above make an assumption about how std::vector is  
> implemented? That should only work if the std::vector<Value*> is  
> implemented using an array of Value*s.  I looked at the  
> documentation for STL and did not see anything about vector being  
> guaranteed to be implemented as an array.

All pertinent implementations of the STL do in fact make this guarantee.

> why was direct support for a std:vector<Value*> removed from the  
> CallInst constructor?

To allow the use of SmallVector instead of std::vector, which avoids  
a temporary heap allocation for a significant speedup.

— Gordon


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: use of CallInst()

me22
In reply to this post by Ryan M. Lefever
On 3/7/07, Ryan M. Lefever <[hidden email]> wrote:

> Doesn't the code above make an assumption about how std::vector is
> implemented?  If ArgVec is defined as
>
> std::vector<Value*> ArgVec;
>
> then &ArgVec[0] returns a Value**.  Let us define
>
> Value** Params = &ArgVec[0];
>
> The constructor for CallInst accesses Params using the [] operator in a
> for loop.  That should only work if the std::vector<Value*> is
> implemented using an array of Value*s.  I looked at the documentation
> for STL and did not see anything about vector being guaranteed to be
> implemented as an array.
>
As of the 2003 revision of the standard, std::vector is guaranteed to
use contiguous storage: &vec[0] + i == &vec[i] for all i in
[0,vec.size()). (See 23.2.4.1)

That said, with the complexity requirements, it'd be difficult to
implement it any other way.  And as Gordon said, there are no common
implementations that ever did it differently--and likely never were
any at all.
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev