<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jul 14, 2016 at 4:01 PM, zan jyu Wong <span dir="ltr"><<a href="mailto:zyfwong@gmail.com" target="_blank">zyfwong@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"><div style="font-family:monospace,monospace;font-size:large">Vivek,<br><br>First of all, I'd like to thank you for you hard work. Your work really helps me a lot.<br></div></div></blockquote><div> </div><div>Thanks Zan Jyu Wong I am glad that this helped, but I would like to share credits with my mentors and llvm community who have helped me for this.</div><div><br></div><div>I am adding llvm dev list here because if my reasons are wrong then some can help both of us understanding it correctly.</div><div><br></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 style="font-family:monospace,monospace;font-size:large">But I have a question about regmask collector.<br>In lib/CodeGen/RegUsageInfoCollector.cpp, there's a for-loop to iterator over all registers to check <br>if they are modified:<br>  for (unsigned PReg = 1, PRegE = TRI->getNumRegs(); PReg < PRegE; ++PReg)<br>    if (MRI->isPhysRegModified(PReg, true))<br>      markRegClobbered(TRI, &RegMask[0], PReg);<br><br>void RegUsageInfoCollector::markRegClobbered(const TargetRegisterInfo *TRI,<br>                                             uint32_t *RegMask, unsigned PReg) {<br>  // If PReg is clobbered then all of its alias are also clobbered.<br>  for (MCRegAliasIterator AI(PReg, TRI, true); AI.isValid(); ++AI) {<br>    DEBUG(dbgs() << "mark: " << TRI->getName(*AI) << "\n");<br>    RegMask[*AI / 32] &= ~(1u << (*AI % 32));<br>  }<br>}<br><br>Suppose that r0, r1 is sub-regs of d0. And function use only r0. Then both r0, d0 will return true<br>when call with MRI->isPhysRegModified. When call `markRegClobbered' using d0, r1 will mark as clobbered, too.<br>But I don't think that r1 should marked as clobbered.<br><br>I'm wondering that if this is expcted behavior? Thanks again.<br></div></div></blockquote><div>No I don't think that r1 will be clobbered here. My reasons are as follow with slightly different example :</div><div>Consider AL | AH | AX | EAX | RAX   and the way LLVM models this register so that AL is aliased to AX, EAX and RAX similar for AH. This can be verified from lib/Target/X86/X86RegisterInfo.td file consider following comments from the file :</div><div><div><font face="monospace, monospace">// In the register alias definitions below, we define which registers alias</font></div><div><font face="monospace, monospace">// which others.  We only specify which registers the small registers alias,</font></div><div><font face="monospace, monospace">// because the register file generator is smart enough to figure out that</font></div><div><font face="monospace, monospace">// AL aliases AX if we tell it that AX aliased AL (for example).</font></div></div><div><br></div><div>see definitions of registers like</div><div><div>def AL : X86Reg<"al", 0>;</div></div><div>def AH : X86Reg<"ah", 4>;<br></div><div>def AX : X86Reg<"ax", 0, [AL,AH]>;<br></div><div>...</div><div>So if we mark AX as used/modified than obviously we can't use AL or AH but yes if only AL is clobbered than AH can still be used.</div><div>I hope this helps, and llvm devs please correct me if necessary.</div><div><br></div><div>-Vivek</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 style="font-family:monospace,monospace;font-size:large"></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Thu, Jul 14, 2016 at 12:50 PM, vivek pandya via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br></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><div class="h5"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span>On Thu, Jul 14, 2016 at 1:10 AM, Mehdi Amini <span dir="ltr"><<a href="mailto:mehdi.amini@apple.com" target="_blank">mehdi.amini@apple.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 style="word-wrap:break-word"><br><div><span><blockquote type="cite"><div>On Jul 13, 2016, at 12:26 PM, Lawrence, Peter <<a href="mailto:c_plawre@qca.qualcomm.com" target="_blank">c_plawre@qca.qualcomm.com</a>> wrote:</div><br><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Vivek,<u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">             I apologize if you took my original email as a request for implementation,<u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">I meant to be asking what is already available, I think the answer to that<u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">is the ‘preserves_most’ and ‘preserves_all’ attributes, but I will also<u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Use ‘regmask’ if those prove to be too sub-optimal.</span></div></div></div></blockquote></span></div></div></blockquote></span><div>Peter there is no need to apologize as we want to get most benefits out of this work ( this is our aim for  GSoC project ). </div><div>Yes 'regmask' can be useful when you can't exactly describe register usage with preserve_most/ preserve_all.  I just ask before sending because to have this feature in truck will take some time (review process).</div><div><br></div><div>As far as LLC is concerned what Mehdi has suggested should be enough. Also I have mentioned already even you want to compile multiple source file and get benefits with LLC I believe you can use llvm-link to combine all .bc files to create one module and use resulting .bc file with LLC to get most benefits of IPRA.</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 style="word-wrap:break-word"><div><span><blockquote type="cite"><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">I am still interested in figuring out the necessary and sufficient conditions<u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">For LLC to do optimal IPRA when given a “whole program”<u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">(as per my previous definition of “whole program”),<u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">As opposed to how to accomplish this with LTO,<u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"></span></div></div></div></blockquote><div><br></div></span><div>Easy: mark *all* of your function “static” (or “internal” in LLVM denomination). <span style="color:rgb(31,73,125);font-family:Calibri,sans-serif;font-size:11pt"> </span></div><span><blockquote type="cite"><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"></div></div></blockquote><br><blockquote type="cite"><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">If you are open to having such discussions, even though your focus<u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">IIUC is supposed to be LTO, then great.   I think Mehdi is stuck trying<u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">To convince me to use LTO, but given all the changes I’ve had to make<u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">To CodeGen (IE outside of my Target sub-dir) for having separate Data and Address<u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">register sets, I think using LTO is a long term solution that I can’t take<u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">On just now (IE the svn branch merge problem)</span></div></div></div></blockquote><blockquote type="cite"><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">As one of my old math professors used to say “don’t use a sledge hammer<u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">To crush a pea”,  to wit  I am only compiling a single source file as an entire whole<u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Program and I don’t do any linking, why should I have to use a linker.</span></div></div></div></blockquote><div><br></div></span><div>Just semantic issue: you need to tell the optimizer what it can and can’t do. In general we can’t assume that the code being optimized or generated won’t be dlopen/dlsym for instance.</div><div>Unfortunately I’d prefer everything to be hidden/private by default and the user having to explicitly export symbols, but that’s not the current model.</div><div><br></div><div>The LTO API is here to circumvent this issue: by delaying the optimizations/codegen to the link time, we have more information about what function can / can’t be called from another module. </div><div>One of the key point of LTO is the linker telling us “I don’t need to export this symbol” and we turn it into an “internal” one.</div><div><br></div><div>— </div><span><font color="#888888"><div>Mehdi</div></font></span><span><div><br></div><div><br></div><br><blockquote type="cite"><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">--Peter Lawrence<u></u><u></u></span></div><div style="border-style:none none solid;border-bottom-color:windowtext;border-bottom-width:1pt;padding:0in 0in 1pt"><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif;border:none;padding:0in"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></div></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></div><p class="MsoNormal" style="margin:0in 0in 12pt;font-size:12pt;font-family:'Times New Roman',serif">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><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">Perhaps using some form of __attribute__ ?<br>Maybe __attribute__ ((registermask = ....))  ?<br><br><br>--Peter Lawrence.<u></u><u></u></div><div style="border-style:none none solid;border-bottom-color:windowtext;border-bottom-width:1pt;padding:0in 0in 1pt"><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif;border:none;padding:0in"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></div></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><b><span style="font-size:11pt;font-family:Calibri,sans-serif">From:</span></b><span style="font-size:11pt;font-family:Calibri,sans-serif"><span> </span>vivek pandya [<a href="mailto:vivekvpandya@gmail.com" target="_blank">mailto:vivekvpandya@gmail.com</a>]<span> </span><br><b>Sent:</b><span> </span>Wednesday, July 13, 2016 11:47 AM<br><b>To:</b><span> </span>Lawrence, Peter <<a href="mailto:c_plawre@qca.qualcomm.com" target="_blank">c_plawre@qca.qualcomm.com</a>><br><b>Cc:</b><span> </span><a href="mailto:mehdi.amini@apple.com" target="_blank">mehdi.amini@apple.com</a>; 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>; Hal Finkel <<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>><br><b>Subject:</b><span> </span>Re: [llvm-dev] IPRA, interprocedural register allocation, question<u></u><u></u></span></div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">Hello Peter,<u></u><u></u></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">Are you still interested in __attribute__(regmask) ? <u></u><u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">I have done some hack ( both clang+IPRA)  to get it working if you want to play around it I can send a patch by tomorrow.<u></u><u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">Sincerely,<u></u><u></u></div></div><div><div style="margin:0in 0in 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">Vivek</div></div></div></div></div></blockquote></span></div><br></div></blockquote></div></div></div><br></div></div>
<br></div></div>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div></div>