<span style><font face="nsimsun, monospace">Hi LLVMers,</font></span><div><span style><font face="nsimsun, monospace"><br></font></span></div><div><p class="MsoNormal" style><font face="nsimsun, monospace">The attached patch adds a new Intrinsic named "llvm.codegen" to support embedded LLVM IR code generation.  <u></u><span style="background-color:transparent;text-align:left">The '</span><tt style="background-color:transparent;text-align:left">llvm.codegen</tt><span style="background-color:transparent;text-align:left">' intrinsic uses the LLVM back ends to generate code for embedded LLVM IR strings. The code generation target can be same or different to the one of the parent module. </span></font></p>
<p class="MsoNormal" style><font face="nsimsun, monospace"><span style="background-color:transparent;text-align:left"><br></span></font></p><p class="MsoNormal" style><font face="nsimsun, monospace" style="color:rgb(34,34,34)">The original motivation inspiring us to add this intrinsic, is to generate code for heterogeneous platform. A test case in the patch demos this.  In the test case, on a X86 host, we use this intrinsic to transform an embedded  LLVM IR into a string of PTX assembly. We can then employ a PTX  execution engine ( on </font><span style="color:rgb(34,34,34);font-family:nsimsun,monospace">CUDA Supported GPU</span><font face="nsimsun, monospace" style="color:rgb(34,34,34)">) to execute the newly generated assembly and copy back the result later.</font></p>
<p class="MsoNormal" style><font face="nsimsun, monospace"><br></font></p><p class="MsoNormal" style><span style="font-family:nsimsun,monospace">The usage of t</span><font face="nsimsun, monospace">his intrinsic is not limited to code generation for heterogeneous platform. It can also help lots of (run-time) optimization and security problems even when the code generation target is same as the one of the parent module.</font></p>
<p class="MsoNormal" style><font face="nsimsun, monospace"><br></font></p><p class="MsoNormal" style><font face="nsimsun, monospace"><span style="background-color:transparent;text-align:left">Each call to the intrinsic has two arguments. One is the LLVM IR string. The other is the name of the target architecture. When running with tools like llc, lli, etc, this intrinsic transforms the input LLVM IR string  to a new string of assembly code for the target architecture </span></font><span style="background-color:transparent;text-align:left;font-family:nsimsun,monospace">firstly. Then the call to the intrinsic is replaced by a pointer to the newly generated string. After this, we have in our module </span></p>
<p class="MsoNormal" style><u></u> <u></u></p><p class="MsoNormal" style>We would like to get the community’s feedback on this so as to make sure this patch is as universally applicable as possible. </p><p class="MsoNormal" style>
Thanks a lot!</p><p class="MsoNormal" style><br></p><p class="MsoNormal" style>best regards,</p><p class="MsoNormal" style>Yabin Hu</p></div>