cast instruction

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

cast instruction

Ryan M. Lefever
I need to create a cast instruction that casts an sbyte* to another
pointer type.  Previously I was using the CastInst::createInferredCast()
function to do that; however, that function has been removed.  Which of
the create() functions from CastInst should I use to do that?  It seems
like the obdvious answer should be createPointerCast().  However, the
documentation for createPointerCast says, "Create a BitCast or a
PtrToInt cast instruction," and I'm not wanting to cast a pointer to an int.

Thanks,
Ryan

--
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: cast instruction

Reid Spencer-2
On Fri, 2007-02-23 at 21:09 -0600, Ryan M. Lefever wrote:
> I need to create a cast instruction that casts an sbyte* to another
> pointer type.  Previously I was using the CastInst::createInferredCast()
> function to do that; however, that function has been removed.  Which of
> the create() functions from CastInst should I use to do that?  It seems
> like the obdvious answer should be createPointerCast().  However, the
> documentation for createPointerCast says, "Create a BitCast or a
> PtrToInt cast instruction," and I'm not wanting to cast a pointer to an int.

Pointer to pointer cast is always a bit cast so just use "new
BitCast(...)"

Reid.

>
> 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: cast instruction

Chris Lattner
In reply to this post by Ryan M. Lefever
On Fri, 23 Feb 2007, Ryan M. Lefever wrote:
> I need to create a cast instruction that casts an sbyte* to another
> pointer type.  Previously I was using the CastInst::createInferredCast()
> function to do that; however, that function has been removed.  Which of
> the create() functions from CastInst should I use to do that?  It seems
> like the obdvious answer should be createPointerCast().  However, the
> documentation for createPointerCast says, "Create a BitCast or a
> PtrToInt cast instruction," and I'm not wanting to cast a pointer to an int.

Pointer to pointer casts use the 'bitcast' instruction, because the
src/dest are required to be the same size.

-Chris

--
http://nondot.org/sabre/
http://llvm.org/
_______________________________________________
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: cast instruction

Nick Lewycky
In reply to this post by Ryan M. Lefever
Ryan M. Lefever wrote:
> I need to create a cast instruction that casts an sbyte* to another
> pointer type.

A pointer to pointer cast is a bitcast.

  Previously I was using the CastInst::createInferredCast()
> function to do that; however, that function has been removed.  Which of
> the create() functions from CastInst should I use to do that?

new BitCastInst(SourcePtr, DestTy, InstToInsertBefore);

  It seems
> like the obdvious answer should be createPointerCast().  However, the
> documentation for createPointerCast says, "Create a BitCast or a
> PtrToInt cast instruction," and I'm not wanting to cast a pointer to an int.

createPointerCast is for cases when the pass doesn't know in advance
(statically) whether the destination type is pointer or int. In your
case, you know that the result is a pointer, so you can use the direct
constructor.

Nick Lewycky
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev