<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)"><!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><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";}
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.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
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.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:66537048;
        mso-list-type:hybrid;
        mso-list-template-ids:-2031463344 67698703 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l0:level1
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level2
        {mso-level-tab-stop:1.0in;
        mso-level-number-position:left;
        text-indent:-.25in;}
@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;}
@list l1
        {mso-list-id:1656762443;
        mso-list-type:hybrid;
        mso-list-template-ids:815066882 67698703 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l1:level1
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l1:level2
        {mso-level-tab-stop:1.0in;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l1:level3
        {mso-level-tab-stop:1.5in;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l1:level4
        {mso-level-tab-stop:2.0in;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l1:level5
        {mso-level-tab-stop:2.5in;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l1:level6
        {mso-level-tab-stop:3.0in;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l1:level7
        {mso-level-tab-stop:3.5in;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l1:level8
        {mso-level-tab-stop:4.0in;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l1: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="2050" />
</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>Hello,<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>We would like to propose including support for the OpenCL as_typen built-ins to Clang. If the direction presented in this email is accepted, we are ready to submit a patch with tests.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>The as_typen built-ins are described in section 6.2.4.2 of the OpenCL 1.1 spec. Implementing them requires several steps:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoListParagraph style='text-indent:-.25in;mso-list:l1 level1 lfo1'><![if !supportLists]><span style='mso-list:Ignore'>1.<span style='font:7.0pt "Times New Roman"'>       </span></span><![endif]><span dir=LTR></span>Defining the built-ins in Builtins.def to make Clang aware of them. Since these built-ins are overloaded, they will be declared returning "void" and the actual return type will be patched by Sema when the type of the actual argument is known (similarly to what's currently done for __sync_and_and_fetch and its kin).<o:p></o:p></p><p class=MsoListParagraph style='text-indent:-.25in;mso-list:l1 level1 lfo1'><![if !supportLists]><span style='mso-list:Ignore'>2.<span style='font:7.0pt "Times New Roman"'>       </span></span><![endif]><span dir=LTR></span>A new handler in Sema will check that the invocation of the built-in is valid and will patch its return type<o:p></o:p></p><p class=MsoListParagraph style='text-indent:-.25in;mso-list:l1 level1 lfo1'><![if !supportLists]><span style='mso-list:Ignore'>3.<span style='font:7.0pt "Times New Roman"'>       </span></span><![endif]><span dir=LTR></span>Section 6.2.4.2 states that "The usual type promotion for function arguments shall not be performed" for the as_typen built-ins. Support in Sema will be added to not perform such promotions in this case.<o:p></o:p></p><p class=MsoListParagraph style='text-indent:-.25in;mso-list:l1 level1 lfo1'><![if !supportLists]><span style='mso-list:Ignore'>4.<span style='font:7.0pt "Times New Roman"'>       </span></span><![endif]><span dir=LTR></span>A new function in CodeGen/CGBuiltin.cpp will be added to generate a LLVM bitcast from the built-in call, which is its semantics<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>We have a doubt regarding the best implementation method for (1). There are almost 60 as_typen built-ins [6 vector sizes (1 – scalar, 2, 3, 4, 8, 16) times 9 types (char, uchar, short, ushort, int, uint, long, ulong, float), plus some scalar types not valid as vectors]. Two approaches come to mind:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoListParagraph style='text-indent:-.25in;mso-list:l0 level1 lfo2'><![if !supportLists]><span style='mso-list:Ignore'>1.<span style='font:7.0pt "Times New Roman"'>       </span></span><![endif]><span dir=LTR></span>Add all these built-ins to Builtins.def (__builtin_as_float4, __builtin_as_int8, etc.). Then, in Sema (for checking and overload return type patching) and CodeGen, use a lookup table keyed by Builtin::ID enumerations to fetch the type information and size for each built-in.<o:p></o:p></p><p class=MsoListParagraph style='text-indent:-.25in;mso-list:l0 level1 lfo2'><![if !supportLists]><span style='mso-list:Ignore'>2.<span style='font:7.0pt "Times New Roman"'>       </span></span><![endif]><span dir=LTR></span>Add a single __builtin_as_typen built-in to Builtins.def, accepting 3 arguments: numeric encoding of type, vector size and the original argument. Use macros in the OpenCL-specific hidden include file (that's implicitly included into OpenCL kernels) to map specific built-ins like __builtin_as_float4 to invocations of the generic built-in (__builtin_as_typen(3, 4, X) for 3 meaning "float", for example). In Sema and CodeGen use these passed arguments instead of a lookup table. <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>We prefer the first approach since it's cleaner, but it does "pollute" Builtins.def with a large number of OpenCL-only built-ins, which may be seen as a negative. Any additional suggestions will be more than welcome.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>On a related note of Builtins.def "pollution", Basic/Builtins.h&cpp have infrastructure for language-specific built-ins (LanguageID enumeration). However, this is currently only exposed to the LIBBUILTIN macro in Builtins.def, and used for some Objective-C specific library built-ins (OBJC_LANG). Therefore, it comes to mind that a related macro can be defined, named for example LANGBUILTIN, for allowing to add built-ins for specific languages, without specifying a header file (and to keep all code using current BUILTIN untouched). This can then be used to define OpenCL-specific built-ins in a clean manner, allowing uniform checking that some built-in is invoked from a language not supporting it. Perhaps in this case OpenCL built-ins can be split to a separate .def file (similarly to what's currently done with target-specific built-ins like BuiltinsX86.def) and thus not overwhelm Builtins.def with language-specific definitions. <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>What are your thoughts on these issues?<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Thanks in advance,<o:p></o:p></p><p class=MsoNormal>      Guy Benyei<o:p></o:p></p><p class=MsoNormal>      Intel<o:p></o:p></p><p class=MsoNormal>      SSG – MGP OpenCL Development Center<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><img width=490 height=135 id="Picture_x0020_1" src="cid:image001.png@01CBCD32.DF27AF90" alt="new_email_signature_guy2"><o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p></div><font face="monospace">---------------------------------------------------------------------<br>
Intel Israel (74) Limited<br>
<br>
This e-mail and any attachments may contain confidential material for<br>
the sole use of the intended recipient(s). Any review or distribution<br>
by others is strictly prohibited. If you are not the intended<br>
recipient, please contact the sender and delete all copies.</font></body></html>