<div dir="ltr">On 2 October 2013 12:34, Stanislav Manilov <span dir="ltr"><<a href="mailto:stanislav.manilov@gmail.com" target="_blank">stanislav.manilov@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Again, the tool you describe is exactly what I ultimately want to create. The translation to AltiVec would be a step towards understanding how to manipulate the intrinsics, but it is not a goal on its own.<br>
<div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>Do you have any ideas where in the whole LLVM structure would it fit (should it be implemented as a separate optional pass)?</div></div></div></div></blockquote>
<div></div></div><br></div><div class="gmail_extra">I think there are two separate things:</div><div class="gmail_extra"><br></div><div class="gmail_extra">1. A conversion tool, that will read specific SIMD-1 C files and produce SIMD-2 C files. This will need the C back-end to be working well, or implement its own SIMD-specific C backend, which is in itself, quite a big task. This tool would have to use a function pass that would scan for SIMD-1 intrinsics, and convert them to SIMD-2 in the IR level, so your tool would read the SIMD-1 file as if it were targeting arch-2, and the pass would convert automatically, using the function pass below.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">2. A function pass, to do the conversion between SIMD-1 intrinsics to SIMD-2, based on their original namespace inside LLVM (AVX, NEON, etc) and the target parameter (for SIMD-2 output). This FP should be off by default, of course, but could be turned on (say -convert-simd-intrinsics) when compiling legacy code.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">I'd start with just cataloguing all NEON and AltiVec intrinsics, and trying to map them. You'll probably hit cases where NEON A == AltiVec A + op1 + op2, so you'll have to take head and tail operations around the intrinsics as possible part of an interchangeable SIMD operation. </div>
<div class="gmail_extra"><br></div><div class="gmail_extra">As a first example, you could write a function pass to get only the ones that map nicely 1-to-1 and see if the concept works, and if people are happy with your changes. It should be able to read a (very simple) NEON C file and produce compatible PowerPC AltiVec assembly code. After the infrastructure is in place, you can continue incrementing it by adding support for more intrinsics, more SIMD ISAs, and more complex patterns (involving surrounding instructions, etc). In parallel, you could try to create the tool that would do the source-to-source transformation, using the pass that you have written.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">Of course, adding tests for all known supported conversions to/from would be critical to the success of your project.</div><div class="gmail_extra"><br></div><div class="gmail_extra">
cheers,</div><div class="gmail_extra">--renato</div></div>