Micah,<div><br></div><div>You're saying it works for you, but Clang doesn't currently anywhere near the range of horrible constantexpr constructs it is possible to create. You can "get by" at the moment with just handling ConstantGEPs, because of the way Clang works.</div>
<div><br></div><div>But SPIR isn't restricted to Clang, and the problem is that it is *possible* (although not probable, or nice, but that is irrelevant for corner conditions) to get valid SPIR that it is *very* difficult to get into a shape that you can code generate for CPUs.</div>
<div><br></div><div>Even the SAFECode snippet that Pekka noted doesn't even handle the case of ConstantShuffleVectors, for example.</div><div><br></div><div>You can easily simplify this problem with a restriction in SPIR: disallow ConstantExpr casts - no ptrtoint constant expression. Because GlobalVariables have pointer type, if you disallow converting their type to non-pointer type in a constantexpr, the number of constantexpr subclasses you have to deal with is drastically reduced (to essentially just BitCast and GEP).</div>
<div><br></div><div>That would be a simple, reasonable restriction that would stop potentially maliciously horrible test cases causing all CPU SPIR clients to write upwards of a hundred lines of conversion code.</div><div>
<br></div><div>Cheers,</div><div><br></div><div>James<br><br><div class="gmail_quote">On 28 September 2012 16:48, Villmow, Micah <span dir="ltr"><<a href="mailto:Micah.Villmow@amd.com" target="_blank">Micah.Villmow@amd.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Carlos,<br>
 AMD's OpenCL implementation(both CPU and GPU) has worked for years with the way SPIR represents locals. If there is problems with the representation then it is an implementation issue. One of the issues with using extra kernel arguments is that it requires extra validation and complexity at the runtime level that is not needed if it is handled internally by the compiler. That being said, both ways of doing it are equally valid, but the choice of which way to do it is a implementation decision. I don't think it would be that difficult to lower global variables to function arguments given SPIR representation.<br>

<span class="HOEnZb"><font color="#888888"><br>
Micah<br>
</font></span><div class="im HOEnZb"><br>
> -----Original Message-----<br>
> From: Carlos Sánchez de La Lama [mailto:<a href="mailto:csanchezdll@gmail.com">csanchezdll@gmail.com</a>]<br>
> Sent: Friday, September 28, 2012 12:34 AM<br>
> To: James Molloy<br>
> Cc: Pekka Jääskeläinen; Ouriel, Boaz; <a href="mailto:pocl-devel@lists.sourceforge.net">pocl-devel@lists.sourceforge.net</a>;<br>
> Villmow, Micah; <a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a>; <a href="mailto:llvmdev@cs.uiuc.edu">llvmdev@cs.uiuc.edu</a><br>
> Subject: Re: [pocl-devel] [cfe-dev] [LLVMdev] SPIR provisional<br>
> specification is now available in the Khronos website<br>
><br>
</div><div class="HOEnZb"><div class="h5">> Hi guys,<br>
><br>
> > So it is valid SPIR, as the specification stands, to manipulate<br>
> > __local variables as Constants in a way that is extremely difficult to<br>
> > undo. That is, in order to transform SPIR to code that can run on a<br>
> > CPU, the GlobalVariable (which is a subclass of Constant) must be<br>
> > replaced with a dynamically calculated Value (which is not a subclass<br>
> of constant).<br>
><br>
> What about translating automatic locals to function scope pointers?<br>
> This will make handling of automatic locals and local pointer arguments<br>
> similar, which is desirable as they are just a way to describe the same<br>
> thing (I understand automatic locals as just a simpler way to use local<br>
> buffers than local arguments).<br>
><br>
> In fact, pocl converts automatic locals to implicit "extra" kernel<br>
> arguments and manages both cases the same way.<br>
><br>
> Carlos<br>
<br>
<br>
</div></div></blockquote></div><br></div>