<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 12 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
h4
        {mso-style-priority:9;
        mso-style-link:"Heading 4 Char";
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        font-weight:bold;}
h5
        {mso-style-priority:9;
        mso-style-link:"Heading 5 Char";
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:10.0pt;
        font-family:"Times New Roman","serif";
        font-weight:bold;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
tt
        {mso-style-priority:99;
        font-family:"Courier New";}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0in;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:.5in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
span.Heading4Char
        {mso-style-name:"Heading 4 Char";
        mso-style-priority:9;
        mso-style-link:"Heading 4";
        font-family:"Times New Roman","serif";
        font-weight:bold;}
span.Heading5Char
        {mso-style-name:"Heading 5 Char";
        mso-style-priority:9;
        mso-style-link:"Heading 5";
        font-family:"Times New Roman","serif";
        font-weight:bold;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Courier New";}
span.EmailStyle24
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.apple-converted-space
        {mso-style-name:apple-converted-space;}
span.EmailStyle26
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:1400135149;
        mso-list-type:hybrid;
        mso-list-template-ids:854870906 67698689 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l0:level1
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Symbol;}
@list l0:level2
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l0:level3
        {mso-level-tab-stop:1.5in;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level4
        {mso-level-tab-stop:2.0in;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level5
        {mso-level-tab-stop:2.5in;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level6
        {mso-level-tab-stop:3.0in;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level7
        {mso-level-tab-stop:3.5in;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level8
        {mso-level-tab-stop:4.0in;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level9
        {mso-level-tab-stop:4.5in;
        mso-level-number-position:left;
        text-indent:-.25in;}
ol
        {margin-bottom:0in;}
ul
        {margin-bottom:0in;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Villmow, Micah
<br>
<b>Sent:</b> Tuesday, September 11, 2012 12:51 PM<br>
<b>To:</b> llvm-commits@cs.uiuc.edu<br>
<b>Subject:</b> Proposal: New IR instruction for casting between address spaces<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Problem:<o:p></o:p></p>
<p class="MsoNormal">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.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Solution:<o:p></o:p></p>
<p class="MsoNormal">Remove the ability of bitcast to cast between pointers of different address spaces and replace with an instruction that handles this case explicitely.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Proposed changes:<o:p></o:p></p>
<p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l0 level1 lfo2"><![if !supportLists]><span style="font-family:Symbol"><span style="mso-list:Ignore">·<span style="font:7.0pt "Times New Roman"">        
</span></span></span><![endif]>Add restriction to the verifier on the bitcast instruction making bitcasting between address spaces illegal.<o:p></o:p></p>
<p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l0 level1 lfo2"><![if !supportLists]><span style="font-family:Symbol"><span style="mso-list:Ignore">·<span style="font:7.0pt "Times New Roman"">        
</span></span></span><![endif]>Change documentation[3] to state the bitcast to pointers of different address spaces is illegal.<o:p></o:p></p>
<p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l0 level1 lfo2"><![if !supportLists]><span style="font-family:Symbol"><span style="mso-list:Ignore">·<span style="font:7.0pt "Times New Roman"">        
</span></span></span><![endif]>Add in a new IR node, addrspacecast, that allows conversions between address spaces<o:p></o:p></p>
<p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l0 level1 lfo2"><![if !supportLists]><span style="font-family:Symbol"><span style="mso-list:Ignore">·<span style="font:7.0pt "Times New Roman"">        
</span></span></span><![endif]>Updated the reader/writer to handle these cases<o:p></o:p></p>
<p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l0 level1 lfo2"><![if !supportLists]><span style="font-family:Symbol"><span style="mso-list:Ignore">·<span style="font:7.0pt "Times New Roman"">        
</span></span></span><![endif]>Update the documentation to insert the new IR node.<o:p></o:p></p>
<p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l0 level1 lfo2"><![if !supportLists]><span style="font-family:Symbol"><span style="mso-list:Ignore">·<span style="font:7.0pt "Times New Roman"">        
</span></span></span><![endif]>Add the following documentation:<o:p></o:p></p>
<div style="border:none;border-bottom:solid #999999 1.0pt;padding:0in 0in 0in 0in">
<h4 style="mso-margin-top-alt:24.0pt;margin-right:6.0pt;margin-bottom:6.0pt;margin-left:6.0pt">
<a name="i_bitcast"><i><span style="font-size:13.5pt;color:black">'</span></i></a><tt><i><span style="font-size:10.0pt;color:black">addrspacecast .. to</span></i></tt><i><span style="font-size:13.5pt;color:black">' Instruction<o:p></o:p></span></i></h4>
</div>
<h5><span style="color:black">Syntax:<o:p></o:p></span></h5>
<pre><span style="color:black">  <result> = addrspacecast <ty> <value> to <ty2>             <i>; yields ty2</i><o:p></o:p></span></pre>
<h5><span style="color:black">Overview:<o:p></o:p></span></h5>
<p><span style="font-size:13.5pt;color:black">The '</span><span style="color:black"> addrspacecast</span><span style="font-size:13.5pt;color:black"> ' instruction converts<span class="apple-converted-space"> </span></span><tt><span style="font-size:10.0pt;color:black">value</span></tt><span class="apple-converted-space"><span style="font-size:13.5pt;color:black"> </span></span><span style="font-size:13.5pt;color:black">to
 type<span class="apple-converted-space"> </span></span><tt><span style="font-size:10.0pt;color:black">ty2</span></tt><span class="apple-converted-space"><span style="font-size:13.5pt;color:black"> </span></span><span style="font-size:13.5pt;color:black">without
 changing any bits.<o:p></o:p></span></p>
<h5><span style="color:black">Arguments:<o:p></o:p></span></h5>
<p><span style="font-size:13.5pt;color:black">The '</span><span style="color:black"> addrspacecast</span><span style="font-size:13.5pt;color:black"> ' 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<span class="apple-converted-space"> </span></span><tt><span style="font-size:10.0pt;color:black">value</span></tt><span class="apple-converted-space"><span style="font-size:13.5pt;color:black"> </span></span><span style="font-size:13.5pt;color:black">and
 the destination type,<span class="apple-converted-space"> </span></span><tt><span style="font-size:10.0pt;color:black">ty2</span></tt><span style="font-size:13.5pt;color:black">, must be identical, except for the address space.<o:p></o:p></span></p>
<h5><span style="color:black">Semantics:<o:p></o:p></span></h5>
<p><span style="font-size:13.5pt;color:black">The '</span><span style="color:black"> addrspacecast</span><span style="font-size:13.5pt;color:black"> ' instruction converts<span class="apple-converted-space"> </span></span><tt><span style="font-size:10.0pt;color:black">value</span></tt><span class="apple-converted-space"><span style="font-size:13.5pt;color:black"> </span></span><span style="font-size:13.5pt;color:black">to
 type<span class="apple-converted-space"> </span></span><tt><span style="font-size:10.0pt;color:black">ty2</span></tt><span style="font-size:13.5pt;color:black">. 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.
<o:p></o:p></span></p>
<h5><span style="color:black">Example:<o:p></o:p></span></h5>
<pre><span style="color:black">  %X = addrspacecast i8 addrspace(1) 255 to i8* addrspace(2)              <i>; yields i8* addrspace(2) :-1</i><o:p></o:p></span></pre>
<pre><span style="color:black">  %Y = addrspacecast i32* %x to sint* addrspace(31)          <i>; yields sint* addrspace(31):%x<o:p></o:p></i></span></pre>
<pre><i><span style="color:black"><o:p> </o:p></span></i></pre>
<pre><i><span style="color:black">Thanks,<o:p></o:p></span></i></pre>
<pre><i><span style="color:black">Micah</span></i><o:p></o:p></pre>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">[1] <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-September/053166.html">
http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-September/053166.html</a><o:p></o:p></p>
<p class="MsoNormal">[2] <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-August/052639.html">
http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-August/052639.html</a><o:p></o:p></p>
<p class="MsoNormal">[3] <a href="http://llvm.org/docs/LangRef.html#i_bitcast">http://llvm.org/docs/LangRef.html#i_bitcast</a><o:p></o:p></p>
<p class="MsoListParagraph"><o:p> </o:p></p>
</div>
</div>
</body>
</html>