<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi Graham,<div class=""><br class=""></div><div class="">Have you looked at using the existing outliner framework to implement partial inlining? In the past, people have combined outlining + inlining to get partial inlining “for free” (see "Function outlining and partial inlining” by Zhao and Amaral).</div><div class=""><br class=""></div><div class="">There is the MachineOutliner. River Riddle has been working on an IR-level outliner as well. The MachineOutliner doesn’t currently consider the heat of a block, but might be worth experimenting with. It might be good to experiment with River’s work and the existing outlining pass to see if this functionality can effectively fall out of what we have already.</div><div class=""><br class=""></div><div class="">Here’s the recent IR-level outlining thread for reference wrt River’s work: <a href="http://lists.llvm.org/pipermail/llvm-dev/2017-July/115666.html" class="">http://lists.llvm.org/pipermail/llvm-dev/2017-July/115666.html</a></div><div class=""><br class=""></div><div class="">- Jessica</div><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Aug 15, 2017, at 11:22 AM, Graham Yiu via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><p class=""><font size="2" face="Arial" class="">Hello,</font><br class=""><br class=""><font size="2" face="Arial" class="">My team and I are looking to do some enhancements in the partial inliner in opt. Would appreciate any feedback that folks might have.</font><br class=""><br class=""><font size="2" face="Arial" class=""># Partial Inlining in LLVM opt</font><font size="2" face="Arial" class=""><br class=""></font><font size="2" face="Arial" class=""><br class="">## Summary</font><font size="2" face="Arial" class=""><br class=""></font><font size="2" face="Arial" class=""><br class="">### Background</font><font size="2" face="Arial" class=""><br class=""></font><font size="2" face="Arial" class=""><br class="">Currently, the partial inliner searches the first few blocks of the callee and looks for a branch to the return block (ie. early return). If found, it attempts to outline the rest of the slow (or heavy) code so the inliner will be able to inline the fast (or light) code. If no early returns are found, the partial inliner will give up. As far as I can tell, BlockFrequency and BranchProbability information is only used when attempting to inline the early return code, and not used to determine whether to outline the slow code.<br class=""><br class="">### Proposed changes</font><font size="2" face="Arial" class=""><br class=""></font><font size="2" face="Arial" class=""><br class="">In addition to looking for early returns, we should utilize profile information to outline blocks that are considered cold. If we can sufficiently reduce the size of the original function via this type of outlining, inlining should be able to inline the rest of the hot code. </font><font size="2" face="Arial" class=""><br class=""></font><font size="2" face="Arial" class=""><br class="">## Details</font><font size="2" face="Arial" class=""><br class=""></font><font size="2" face="Arial" class=""><br class="">With the presence of profile information, we have a view of what code is infrequently executed and make better decisions on what to outline. Early return blocks that are infrequently executed should still be included as candidates for outlining, but will be treated just like any other cold blocks. Without profiling information, however, we should remain conservative and only partial inline in the presence of an early return in the first few blocks of a function (ie. peel the early return out of the function).</font><font size="2" face="Arial" class=""><br class=""></font><font size="2" face="Arial" class=""><br class="">To find cold regions to outline, we will traverse the CFG to find edges deemed 'cold' and look at the blocks dominated by the successor node. If, for some reason, that block has more than one predecessor, then we will skip this candidate as there should be a node that dominates this successor that has a single entry point. The last node in the dominance vector should also have a single successor. If it does not, then further investigation of the CFG is necessary to see when/how this situation occurs.</font><font size="2" face="Arial" class=""><br class=""></font><font size="2" face="Arial" class=""><br class="">We will need several heuristics to make sure we only outline in cases where we are confident it will result in a performance gain. Things such as threshold on when a branch is considered cold, the minimum number of times the predecessor node has to be executed in order for an edge to be considered (confidence factor), and the minimum size of the region to be outlined (can use inlining cost analysis like we currently do) will require some level of tuning.</font><font size="2" face="Arial" class=""><br class=""></font><font size="2" face="Arial" class=""><br class="">Similar to the current implementation, we will attempt to inline the leftover (hot) parts of the code, and if for some reason we cannot then we discard the modified function and its outlined code.</font><font size="2" face="Arial" class=""><br class=""></font><font size="2" face="Arial" class=""><br class="">### Code changes</font><font size="2" face="Arial" class=""><br class=""></font><font size="2" face="Arial" class=""><br class="">The current Partial Inlining code first clones the function of interest and looks for a single set of blocks to outline. It then creates a function with the set the blocks, and saves the outlined function and outline callsite information as part of the function cloning container. In order to outline multiple regions of the function, we will need to change these containers to keep track of a list of regions to outline. We will also need to update the cost analysis to take into account multiple outlined functions. </font><font size="2" face="Arial" class=""><br class=""></font><font size="2" face="Arial" class=""><br class="">When a ProfileSummary is available, then we should skip the code that looks for early returns and go into new code that looks for cold regions to outline. When ProfileSummary is not available, then we can fall back to the existing code and look for early returns only.<br class=""><br class="">### Tuning</font><font size="2" face="Arial" class=""><br class=""></font><font size="2" face="Arial" class=""><br class="">- The outlining heuristics will need to determine if a set of cold blocks is large enough to warrant the overhead of a function call. We also don't want the inliner to attempt to inline the outlined code later.<br class="">- The threshold for determining whether a block is cold will also need to be tuned. In the case that profiling information is not accurate, we will pay the price of the additional call overhead for executing cold code.<br class="">- The confidence factor, which can be viewed as the minimum number of times the predecessor has to be executed in order for an edge to be considered cold, should also be taken into account to avoid outlining code paths we have little information on.</font><br class=""><br class=""><font size="2" class="">Graham Yiu<br class="">LLVM Compiler Development<br class="">IBM Toronto Software Lab<br class="">Office: (905) 413-4077 C2-407/8200/Markham<br class=""><a href="mailto:gyiu@ca.ibm.com" class="">Email: gyiu@ca.ibm.com</a></font><br class="">
</p></div>
_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class=""></div></blockquote></div><br class=""></div></body></html>