<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 24, 2016, at 11:35 AM, vivek pandya <<a href="mailto:vivekvpandya@gmail.com" class="">vivekvpandya@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br class="Apple-interchange-newline"><br 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-stroke-width: 0px;" class=""><div class="gmail_quote" 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-stroke-width: 0px;">On Tue, Jun 21, 2016 at 12:31 AM, Matthias Braun<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:matze@braunis.de" target="_blank" class="">matze@braunis.de</a>></span><span class="Apple-converted-space"> </span>wrote:<br 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 style="word-wrap: break-word;" class=""><div class="">I just discussed this with vivek on IRC (and I think we agreed on this):</div><div class=""><br class=""></div><div class="">Let me first state the motivation clearly to ease later discussions:</div><div class="">As far as the motivation for this change goes: Changing the calling convention allows us to choose whether a register is saved by the callee or the caller. Usually it is best to have a mix of both as too many caller saved registers leads to unnecessary save/restores when the called function turns out to only touch a fraction of the registers (as is typically for smaller leaf-functions of the call graph). While too many callee saved registers may lead to unnecessary saves/restores of registers even though the calling function didn't have a live value in the register anyway. With IPRA the first problem is mitigated since we propagate the actually clobbered set of registers up the callgraph instead of relying on conventions, so it is best to aim for more caller saved registers (though we should check for code size increases and store/restore code being potentially less good than the tuned sequences generated during FrameLowering).</div><div class=""><br class=""></div><div class="">To the disucssion at hand:</div><div class="">- Introducing a new calling convention at the IR level is the wrong approach: The calling convention is mostly a contract when calling and being called across translation unit boundaries. The details about how this contract is fulfilled are part of CodeGen IMO but do not need to be visible at the IR level.</div><div class="">- The only thing we want to influence here is which registers are saved by the callee. Changing TargetFrameLowering::determineCalleeSaves() is a good place to achieve this without affecting unrelated things like parameter and return value handling which would be part of the calling convention.</div></div></blockquote><div class="">Hello Matthias,</div><div class=""><br class=""></div><div class="">As per our discussion, the above trick will make sure that there is no callee saved registers and also we have thought that RegUsageInfoCalculator.cpp is having regmask that will make caller to save restore registers if both callee and caller is using any common register but this would require following change in RegUsageInfoCalculator.cpp :</div><div class=""><br class=""></div><div class=""><div class=""><font face="monospace, monospace" class="">if (!F->hasLocalLinkage() || F->hasAddressTaken()) {</font></div><div class=""><font face="monospace, monospace" class=""> const uint32_t *CallPreservedMask =</font></div><div class=""><font face="monospace, monospace" class=""> TRI->getCallPreservedMask(MF, MF.getFunction()->getCallingConv());</font></div><div class=""><font face="monospace, monospace" class=""> // Set callee saved register as preserved.</font></div><div class=""><font face="monospace, monospace" class=""> for (unsigned i = 0; i < RegMaskSize; ++i)</font></div><div class=""><font face="monospace, monospace" class=""> RegMask[i] = RegMask[i] | CallPreservedMask[i];</font></div><div class=""><font face="monospace, monospace" class=""> <span class="Apple-converted-space"> </span>}</font></div></div><div class=""><br class=""></div><div class="">because RegUsageInfoCalculator.cpp marks register as preserved if MF's CC preserves it. But While optimizing for callee saved register we need to skip above code so that register save/restore code is adder around call site.</div></div></div></blockquote><div>Indeed some adjustment there should improve your results. I would however recommend to use something like this to determine which registers got saved:</div><div><br class=""></div><div>const MachineFrameInfo &MFI = *MF.getFrameInfo();</div><div>assert(MFI.isCalleeSavedInfoValid());</div><div>for (const CalleeSavedInfo &Info : MFI.getCalleeSavedInfo()) {</div><div> // Mark Info.getReg() and all its subregisters as preserved here!</div><div>}</div><div><br class=""></div><div>- Matthias</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div class="gmail_quote" 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-stroke-width: 0px;"><div class=""><br class=""></div><div class="">Apart from that my hunch is that IPO inlining of static function also creates problem for this ( I have this feeling because some test case from test-suite fails when using -O > 0 ). I am still working on this. </div><div class=""><br class=""></div><div class="">Please share your thoughts on this.</div><div class=""><br class=""></div><div class="">Sincerely,</div><div class="">- Vivek</div><div class=""> <br class=""></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;" class=""><div class="">- We could experiment with dynamically changing the number of caller saved registers in the future. I could imagine heuristics like functions called from many places using some callee saved registers in order to avoid code size increases because of extra spills/restores at all the call sites. We can hardly create new calling conventions for these combinations of marking registers as callee/caller saved.</div><span class=""><font color="#888888" class=""><div class=""><br class=""></div><div class="">- Matthias</div><div class=""><br class=""></div></font></span><div class=""><blockquote type="cite" class=""><div class=""><div class="h5"><div class="">On Jun 20, 2016, at 7:39 AM, vivek pandya via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class=""></div></div><div class=""><div class=""><div class="h5"><div dir="ltr" class="">Dear Community,<div class=""><br class=""></div><div class="">To improve current interprocedural register allocation (IPRA) , we have planned to set callee saved registers to none for local functions, currently I am doing it in following way:</div><div class=""><br class=""></div><div class=""><font face="monospace, monospace" class="">if (F->hasLocalLinkage() <span style="font-size: 12.499999046325684px;" class=""> </span><span style="font-size: 12.499999046325684px;" class="">&& !F->hasAddressTaken()</span>) {</font></div><div class=""><font face="monospace, monospace" class=""> <span class="Apple-converted-space"> </span>DEBUG(dbgs() << "Function has LocalLinkage \n");</font></div><div class=""><font face="monospace, monospace" class="">F->setCallingConv(CallingConv::GHC); </font></div><div class=""><font face="monospace, monospace" class=""> }</font></div><div class=""><br class=""></div><div class="">but we think threre should be clean and properway to do this perhaps like:</div><div class=""><br class=""></div><div class=""><div class=""><div style="font-size: 12.499999046325684px;" class=""><font face="monospace, monospace" class="">if (F->hasLocalLinkage() && !F->hasAddressTaken()) {</font></div><span style="font-size: 12.499999046325684px;" class=""><font face="monospace, monospace" class=""> <span class="Apple-converted-space"> </span>DEBUG(dbgs() << "Function has LocalLinkage \n");</font></span><div style="font-size: 12.499999046325684px;" class=""><font face="monospace, monospace" class=""> <span class="Apple-converted-space"> </span>F->setCallingConv(CallingConv::NO_Callee_Saved);</font></div><div style="font-size: 12.499999046325684px;" class=""><font face="monospace, monospace" class=""> <span class="Apple-converted-space"> </span>}</font></div><div style="font-size: 12.499999046325684px;" class=""><font face="monospace, monospace" class=""><br class=""></font></div><div class=""><font face="arial, helvetica, sans-serif" class=""><span style="font-size: 12.499999046325684px;" class="">So I would like to know any better suggestions and if it is better to add a new CC for this purpose then what aspects should be considered while defining a new CC. Actually in this case the new CC does not really required to define how parameters should be passed or any special rule for return value etc , it just required to set callee saved registers to be none. So what are the minimal things required to define such a CC?</span></font></div></div></div><div class=""><font face="arial, helvetica, sans-serif" class=""><span style="font-size: 12.499999046325684px;" class=""><br class=""></span></font></div><div class=""><font face="arial, helvetica, sans-serif" class=""><span style="font-size: 12.499999046325684px;" class="">Other alternative that I have thought was to add new attribute for function and use it like following in TargetFrameLowering::determineCalleeSaves()</span></font></div><div class=""><font face="arial, helvetica, sans-serif" class=""><span style="font-size: 12.499999046325684px;" class=""><br class=""></span></font></div><div class=""><div style="font-size: 12.499999046325684px;" class=""> <font face="monospace, monospace" class="">// In Naked functions we aren't going to save any registers.</font></div><div style="font-size: 12.499999046325684px;" class=""><font face="monospace, monospace" class=""> <span class="Apple-converted-space"> </span>if (MF.getFunction()->hasFnAttribute(Attribute::Naked))</font></div><div style="font-size: 12.499999046325684px;" class=""><font face="monospace, monospace" class=""> <span class="Apple-converted-space"> </span>return;</font></div></div><div style="font-size: 12.499999046325684px;" class=""><font face="monospace, monospace" class=""><br class=""></font></div><div style="font-size: 12.499999046325684px;" class=""><font face="arial, helvetica, sans-serif" class="">Any suggestions / thoughts are welcomed !</font></div><div style="font-size: 12.499999046325684px;" class=""><font face="arial, helvetica, sans-serif" class=""><br class=""></font></div><div style="font-size: 12.499999046325684px;" class=""><font face="arial, helvetica, sans-serif" class="">Sincerely,</font></div><div style="font-size: 12.499999046325684px;" class=""><font face="arial, helvetica, sans-serif" class="">Vivek</font></div></div></div></div><span 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" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a></span></div></blockquote></div></div></blockquote></div></div></blockquote></div><br class=""></body></html>