[LLVMdev] FW: Proposal: New IR instruction for casting between address spaces

Villmow, Micah Micah.Villmow at amd.com
Tue Sep 11 13:03:16 PDT 2012


From: Villmow, Micah
Sent: Tuesday, September 11, 2012 12:51 PM
To: llvm-commits at cs.uiuc.edu
Subject: Proposal: New IR instruction for casting between address spaces

Problem:
Bit casting between pointers of different address spaces only works if all address space pointers are the same size. With changes from email chain [1][2], support for different pointer sizes breaks the bitcast instruction since there is no guarantee that the pointer size for the address space is on the source and destination arguments are of the same size.

Solution:
Remove the ability of bitcast to cast between pointers of different address spaces and replace with an instruction that handles this case explicitely.

Proposed changes:

*         Add restriction to the verifier on the bitcast instruction making bitcasting between address spaces illegal.

*         Change documentation[3] to state the bitcast to pointers of different address spaces is illegal.

*         Add in a new IR node, addrspacecast, that allows conversions between address spaces

*         Updated the reader/writer to handle these cases

*         Update the documentation to insert the new IR node.

*         Add the following documentation:

'addrspacecast .. to' Instruction
Syntax:

  <result> = addrspacecast <ty> <value> to <ty2>             ; yields ty2

Overview:

The ' addrspacecast ' instruction converts value to type ty2 without changing any bits.

Arguments:

The ' addrspacecast ' instruction takes a value to cast, which must be a non-aggregate first class value with a pointer type, and a type to cast it to, which must also be a pointer type. The pointer types of value and the destination type, ty2, must be identical, except for the address space.

Semantics:

The ' addrspacecast ' instruction converts value to type ty2. It converts the type to the type that is implied by the address space of the destination pointer. If the destination pointer is smaller than the source pointer, the upper bits are truncated. If the inverse is true, the upper bits are sign extended, otherwise the operation is a no-op.

Example:

  %X = addrspacecast i8 addrspace(1) 255 to i8* addrspace(2)              ; yields i8* addrspace(2) :-1

  %Y = addrspacecast i32* %x to sint* addrspace(31)          ; yields sint* addrspace(31):%x



Thanks,

Micah


[1] http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-September/053166.html
[2] http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-August/052639.html
[3] http://llvm.org/docs/LangRef.html#i_bitcast


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120911/c437fcbd/attachment.html>


More information about the llvm-dev mailing list