<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Sep 12, 2018, at 2:54 PM, Richard Smith via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><div class="gmail_quote"><div dir="ltr" class="">On Tue, 11 Sep 2018 at 19:40, Tom Stellard via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;">On 09/11/2018 12:50 PM, Richard Smith via llvm-dev wrote:<br class="">> On Mon, 10 Sep 2018 at 18:47, Nicholas Wilson via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a><span class="Apple-converted-space"> </span><mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>>> wrote:<br class="">><span class="Apple-converted-space"> </span><br class="">> I was going to wait until Neil Trevett got back to me about becoming a SPIR-V TSG advisor but this seems like just as good an opportunity. Please see the previous discussion [1] if you have not already, there were many relevant points made.<br class="">><span class="Apple-converted-space"> </span><br class="">> First, I’d like to note that while clang may be the primary motivator for many of the readers here it is not the only frontend that would like to make use of proper SPIR-V support in LLVM. In particular, the current implementation of builtins as Itanium with extensions mangled C++ is much more difficult to use (even if those frontends have a C++ mangler, the extensions make it unusable), compared to intrinsics which is _the_ way backends for LLVM expose builtins. This is an absolute requirement for me for SPIR-V support in upstream LLVM.<br class="">><span class="Apple-converted-space"> </span><br class="">> I’d much rather have this as a target than as an external library, but if it means I get intrinsics faster then I’m all for it.<br class="">><span class="Apple-converted-space"> </span><br class="">><span class="Apple-converted-space"> </span><br class="">> +1. What would be the justification for using an external binary for this rather than treating it like any other LLVM backend?<br class="">><span class="Apple-converted-space"> </span><br class=""><br class="">This has been discussed in the past, but I don't think SPIR-V<br class="">is a good fit for an LLVM backend. It is very similar to LLVM<br class="">IR and it seems like overkill to write a whole backend just to<br class="">do a simple translation.</blockquote><div class=""><br class=""></div><div class=""><div class="">I don't see how SPIR-V is any different from WebAssembly or PTXAS in this regard. I also don't see why a "whole backend" is a different amount of work from a separate program that implements a whole backend.</div></div></div></div></div></blockquote><div>Using lib/CodeGen and going to MIR makes sense if you have to solve instruction selection, legalization, scheduling, register/resource allocation problems, manage a callstack etc. if you don't need any (or most) of that then I think it makes sense to just build a custom IR pass rather than invoking the whole codegen machinery.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><div class="gmail_quote"><div class=""><div class=""> <br class=""></div></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;">Not to mention the fact that I don't<br class="">see how it's possible with the current backend infrastructure<br class="">to preserve type information for complex types like structs all<br class="">the way through the codegen pipeline.<br class=""></blockquote><div class=""><br class=""></div><div class="">The nice thing about code is that it's malleable. If there's a limitation that prevents SPIR-V being written as an LLVM target, we should just fix that.</div></div></div></div></blockquote><div>Indeed we should still be able to implement the TargetMachine interface and get the thing into the TargetMachine registry.</div><div><br class=""></div><div>- Matthias</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><div class="gmail_quote"><div class=""><br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;">-Tom<br class=""><br class=""><br class="">><span class="Apple-converted-space"> </span><br class="">> Could you please link the thread mentioned?<br class="">><span class="Apple-converted-space"> </span><br class="">> Thanks,<br class="">> Nic<br class="">><span class="Apple-converted-space"> </span><br class="">> P.S. Feel free to use the tablegen descriptions of the SPIR-V format from [2]<br class="">><span class="Apple-converted-space"> </span><br class="">> [1]:<span class="Apple-converted-space"> </span><a href="http://lists.llvm.org/pipermail/llvm-dev/2017-May/112538.html" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/pipermail/llvm-dev/2017-May/112538.html</a><br class="">> [2]:<span class="Apple-converted-space"> </span><a href="https://github.com/thewilsonator/llvm-target-spirv" rel="noreferrer" target="_blank" class="">https://github.com/thewilsonator/llvm-target-spirv</a><span class="Apple-converted-space"> </span><br class="">><span class="Apple-converted-space"> </span><br class="">>> On 10 Sep 2018, at 11:10 pm, Anastasia Stulova via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a><span class="Apple-converted-space"> </span><mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>>> wrote:<br class="">>><br class="">>> Hello,<br class="">>><br class="">>> Since 2015 Khronos has switched to the new portable intermediate format SPIR-V, which has replaced the original SPIR. The advantage is that it offers higher portability across different toolchains. There was a talk about it at a Dev Meeting:<br class="">>> <a href="http://llvm.org/devmtg/2017-03//2017/02/20/accepted-sessions.html#17" rel="noreferrer" target="_blank" class="">http://llvm.org/devmtg/2017-03//2017/02/20/accepted-sessions.html#17</a><br class="">>><br class="">>> LLVM currently only supports SPIR format for OpenCL in Clang. Several Khronos vendors (ARM, AMD, Intel, Xilinx, Codeplay and others) are interested in adding support for SPIR-V, which should gradually replace the old SPIR once products are no longer shipped with the old format. Here is the detailed description:<br class="">>> <a href="https://github.com/KhronosGroup/SPIRV-LLVM-Translator/wiki/SPIRV-Toolchain-for-Clang" rel="noreferrer" target="_blank" class="">https://github.com/KhronosGroup/SPIRV-LLVM-Translator/wiki/SPIRV-Toolchain-for-Clang</a><br class="">>><br class="">>> To summarize, the idea is to add a SPIR-V target triple to Clang that can be used to generate a SPIR-V binary for OpenCL code. There was a separate thread regarding generation of SPIR-V binary and the community suggested that a translator from LLVM IR to SPIR-V can be used as an external tool, called llvm-spirv. This can be invoked similar to such tools as ptxas and fatbinary for the CUDA toolchain:<br class="">>> <a href="http://lists.llvm.org/pipermail/llvm-dev/2018-February/121440.html" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/pipermail/llvm-dev/2018-February/121440.html</a><br class="">>><br class="">>> An example of how Clang can be used to target SPIR-V:<br class="">>><br class="">>> clang -c<span class="Apple-converted-space"> </span><a href="http://test.cl/" rel="noreferrer" target="_blank" class="">test.cl</a><span class="Apple-converted-space"> </span><<a href="http://test.cl/" rel="noreferrer" target="_blank" class="">http://test.cl</a>> -target spirv[32|64]-unknown-unknown -o test.spv<br class="">>><br class="">>> This will result in the following Clang actions:<br class="">>><br class="">>> (1) clang -cc1 -triple spirv[32|64]-unknown-unknown<span class="Apple-converted-space"> </span><a href="http://test.cl/" rel="noreferrer" target="_blank" class="">test.cl</a><span class="Apple-converted-space"> </span><<a href="http://test.cl/" rel="noreferrer" target="_blank" class="">http://test.cl</a>> -emit-llvm-bc -o test.bc<br class="">>><br class="">>> (2) llvm-spirv test.bc -o test.spv<br class="">>><br class="">>> SPIR-V generation is essential for completion of OpenCL C++ support in Clang, as newer OpenCL standards require frontend invocation to be performed offline, producing the SPIR-V binary that can be then loaded at application execution time. Besides that, it will also allow Clang to be used as a complete standalone tool to generate portable binaries that can then be consumed by different proprietary toolchains. In addition, this will open a path to the LLVM backends for various languages and frontends that already generate SPIR-V.<br class="">>><br class="">>> A more detailed explanation of the complete design proposal is given in this Wiki page:<br class="">>> <a href="https://github.com/KhronosGroup/SPIRV-LLVM-Translator/wiki/SPIRV-Toolchain-for-Clang" rel="noreferrer" target="_blank" class="">https://github.com/KhronosGroup/SPIRV-LLVM-Translator/wiki/SPIRV-Toolchain-for-Clang</a><br class="">>><br class="">>> Looking forward to any feedback about the proposal or possible collaborations,<br class="">>><br class="">>> Thanks!<br class="">>><br class="">>> Anastasia<br class="">>> _______________________________________________<br class="">>> LLVM Developers mailing list<br class="">>> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a><span class="Apple-converted-space"> </span><mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>><br class="">>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class="">><span class="Apple-converted-space"> </span><br class="">> _______________________________________________<br class="">> LLVM Developers mailing list<br class="">> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a><span class="Apple-converted-space"> </span><mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>><br class="">> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class="">><span class="Apple-converted-space"> </span><br class="">><span class="Apple-converted-space"> </span><br class="">><span class="Apple-converted-space"> </span><br class="">> _______________________________________________<br class="">> LLVM Developers mailing list<br class="">><span class="Apple-converted-space"> </span><a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a><br class="">><span class="Apple-converted-space"> </span><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class="">><span class="Apple-converted-space"> </span><br class=""><br class="">_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a><br class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class=""></blockquote></div></div><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">_______________________________________________</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">LLVM Developers mailing list</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><a href="mailto:llvm-dev@lists.llvm.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">llvm-dev@lists.llvm.org</a><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a></div></blockquote></div><br class=""></body></html>