<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 8, 2016 at 1:42 PM, vivek pandya <span dir="ltr"><<a href="mailto:vivekvpandya@gmail.com" target="_blank">vivekvpandya@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Fri, Jul 8, 2016 at 9:47 AM, Lawrence, Peter <span dir="ltr"><<a href="mailto:c_plawre@qca.qualcomm.com" target="_blank">c_plawre@qca.qualcomm.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">





<div lang="EN-US" link="blue" vlink="purple">
<div>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Vivek,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">             I am looking into these function attributes in the clang docs<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">                Preserve_most<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">                Preserve_all<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">They are not available in the 3.6.2 that I am currently using, but I hope they exist in 3.8<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">These should provide enough info to solve my problem,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">at the MC level calls to functions with these attributes<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">with be code-gen’ed  through different “calling conventions”,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">and CALL instructions to them should have different register USE and DEF info,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> </span></p></div></div></blockquote></span><div>Yes I believe that preserve_most or preserve_all should help you even with out IPRA. But just to note IPRA can even help further for example on X86 preserve_most cc will not preserve R11 (this can be verified from X86CallingConv.td and X86RegisterInfo.cpp) how ever IPAR calculates regmask based on the actual register usage and if procedure with preserve_most cc does not use R11 and none callsite inside of function body then IPRA will mark R11 as preserved. Also IPRA produces RegMask which is super set of RegMask due to calling convention.</div></div></div></div></blockquote><div><br></div><div>I believe that __attribute__ ((registermask = ....))  can provide more flexibility compare to preserve_all or preserve_most CC in some case. So believe that we should try it out.</div><div><br></div><div>-Vivek</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">This CALL instruction register USE and DEF info should already be useful<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">to the intra-procedural register allocator (allowing values live across these<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">calls to be in what are otherwise caller-save registers),<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">at least that’s how I read the MC dumps, every call instruction seems to have<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">every caller-save register flagged as “imp-def”, IE implicitly-defined by the instruction,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">and hopefully what is considered a caller-save register at a call-site is defined by the callee.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">And this should be the information that IPRA takes advantage of in its bottom-up analysis.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> </span></p></div></div></blockquote></span><div>Yes that is expected help from IPRA. </div><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Which leads me to this question, when compiling an entire whole program at one time,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">so there is no linking and no LTO, will there ever be IPRA that works within LLC for this scenario,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">and is this an objective of your project, or are you focusing only on LTO ?<u></u><u></u></span></p>
<p class="MsoNormal"></p></div></blockquote></span><div>The current IPRA infrastructure works at compile time so it's scope of optimization is restricted to a compilation unit. So IPRA can only construct correct register usage information if the procedure's code is generated by same compiler instance that means we can't optimize library calls or procedure defined in other module. This is because we can't keep register usage information data across two different compiler instance. </div><div><br></div><div>Now if we consider LTO, it eliminates above limitation by making a large IR module from smaller modules before generating code and thus we can have register usage information (at lest) for procedure which was previously defined in other module, because now with LTO every thing is in one module. So that also clarifies that IPRA does not do anything at link time.</div><div><br></div><div>Now coming to LLC, it can use IPRA and optimize for functions defined in current module. So yes while compiling whole program ( a single huge .bc file) IPRA can be used with LLC. Also just note that if a software is written in separate files per module (which is very common) and still you want to maximize benefits of IPRA, then we can use llvm-link tool to combine several .bc files to produce a huge .bc file and use that with LLC to get maximum benefits. </div><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><p class="MsoNormal"> </p></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">I know this is not the typical “linux” scenario (dynamic linking of not only standard libraries,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">but also sometimes even application libraries, and lots of static linking because of program<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">size), but it is a typical “embedded” scenario, which is where I am currently.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> </span></p></div></div></blockquote></span><div>I don't understand this use case but we can have further improvement in IPRA for example if you have several libraries which has already compiled and codegen, but you are able to provide information of register usage for the functions of that libraries than we can think about an approach were we can store register usage information into a file (which will obviously increase compile time) and use that information across different compiler instances so that we can provide register usage information with out having actual code while compiling.</div><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Other thoughts or comments ?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> </span></p></div></div></blockquote></span><div>I am looking for some ideas that can improve current IPRA. So if you feel anything relevant please let me know we can discuss and implement feasible ideas.</div><div><br></div><div>Thanks,</div><div>Vivek  </div><div><div class="h5"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">--Peter Lawrence.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><b><span style="font-size:11pt;font-family:Calibri,sans-serif">From:</span></b><span style="font-size:11pt;font-family:Calibri,sans-serif"> vivek pandya [mailto:<a href="mailto:vivekvpandya@gmail.com" target="_blank">vivekvpandya@gmail.com</a>]
<br>
<b>Sent:</b> Wednesday, July 06, 2016 2:09 PM<br>
<b>To:</b> llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>>; <a href="mailto:llvm-dev-request@lists.llvm.org" target="_blank">llvm-dev-request@lists.llvm.org</a>; Lawrence, Peter <<a href="mailto:c_plawre@qca.qualcomm.com" target="_blank">c_plawre@qca.qualcomm.com</a>><br>
<b>Subject:</b> Re:[llvm-dev] IPRA, interprocedural register allocation, question<u></u><u></u></span></p><div><div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">Hello Peter,<u></u><u></u></p>
<div>
<div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Thanks to pointing out this interesting case. <u></u><u></u></p>
</div>
<blockquote style="border-style:none none none solid;border-left-color:rgb(204,204,204);border-left-width:1pt;padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal" style="margin-bottom:12pt">Vivek,<br>
          I have an application where many of the leaf functions are<br>
Hand-coded assembly language,  because they use special IO instructions<br>
That only the assembler knows about.  These functions typically don't<br>
Use any registers besides the incoming argument registers, IE they don't<br>
Need to use any additional callee-save nor caller-save registers.<u></u><u></u></p>
</blockquote>
<div>
<p class="MsoNormal">If inline asm template has specified clobbered list properly than IPRA is able to use that information and it propagates correct register mask (and that also means that skipping clobbers list while IPRA enabled may broke executable)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">For example in following code:<u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">int gcd( int a, int b ) {<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">    int result ;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">    /* Compute Greatest Common Divisor using Euclid's Algorithm */<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">    __asm__ __volatile__ ( "movl %1, %%r15d;"<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">                          "movl %2, %%ecx;"<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">                          "CONTD: cmpl $0, %%ecx;"<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">                          "je DONE;"<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">                          "xorl %%r13d, %%r13d;"<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">                          "idivl %%ecx;"<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">                          "movl %%ecx, %%r15d;"<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">                          "movl %%r13d, %%ecx;"<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">                          "jmp CONTD;"<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">                          "DONE: movl %%r15d, %0;" : "=g" (result) : "g" (a), "g" (b) : "ecx" ,"r13", "r15"<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">    );<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">    return result ;<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">}<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal">IPRA calculates and propagates correct regmask in which it marks CH, CL, ECX .. clobbered and R13, R15 is not marked clobbered as it is callee saved and LLVM code generators also insert spill/restores code for them.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<blockquote style="border-style:none none none solid;border-left-color:rgb(204,204,204);border-left-width:1pt;padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">Is there any way in your IPRA interprocedural register allocation project that<br>
The user can supply this information for external functions ?<u></u><u></u></p>
</blockquote>
<div>
<p class="MsoNormal">By external word do you here mean function defined in other module than being used?  In that case as IPRA can operate on only one module at time register usage propagation is not possible. But there is a work around for this problem. You
 can use IPRA with link time optimization enabled because the way LLVM LTO works it creates a big IR modules out of source files and them optimize and codegen it so in that case IPRA can have actual register usage info (if function will be compiled in current
 module). <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">In case you want to experiment with IPRA please apply <a href="http://reviews.llvm.org/D21395" target="_blank">http://reviews.llvm.org/D21395</a> this patch before you begin.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">-Vivek<u></u><u></u></p>
</div>
<blockquote style="border-style:none none none solid;border-left-color:rgb(204,204,204);border-left-width:1pt;padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal"> <u></u><u></u></p>
</blockquote>
<blockquote style="border-style:none none none solid;border-left-color:rgb(204,204,204);border-left-width:1pt;padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">Perhaps using some form of __attribute__ ?<br>
Maybe __attribute__ ((registermask = ....))  ?<br>
<br>
<br>
--Peter Lawrence.<u></u><u></u></p>
</blockquote>
</div>
</div>
</div>
</div></div></div>
</div>

</blockquote></div></div></div><br></div></div>
</blockquote></div><br></div></div>