<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0in;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:.5in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
span.EmailStyle19
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.EmailStyle20
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
span.EmailStyle21
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#993366;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:216749709;
        mso-list-type:hybrid;
        mso-list-template-ids:998155014 67698689 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l0:level1
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Symbol;}
@list l0:level2
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l0:level3
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Wingdings;}
@list l0:level4
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Symbol;}
@list l0:level5
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l0:level6
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Wingdings;}
@list l0:level7
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Symbol;}
@list l0:level8
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l0:level9
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Wingdings;}
@list l1
        {mso-list-id:1254705737;
        mso-list-type:hybrid;
        mso-list-template-ids:1168912722 67698689 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l1:level1
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Symbol;}
@list l1:level2
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l1:level3
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Wingdings;}
@list l1:level4
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Symbol;}
@list l1:level5
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l1:level6
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Wingdings;}
@list l1:level7
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Symbol;}
@list l1:level8
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l1:level9
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Wingdings;}
@list l2
        {mso-list-id:1813862020;
        mso-list-type:hybrid;
        mso-list-template-ids:-1905212240 67698689 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l2:level1
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:1.0in;
        text-indent:-.25in;
        font-family:Symbol;}
@list l2:level2
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:1.5in;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l2:level3
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:2.0in;
        text-indent:-.25in;
        font-family:Wingdings;}
@list l2:level4
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:2.5in;
        text-indent:-.25in;
        font-family:Symbol;}
@list l2:level5
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:3.0in;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l2:level6
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:3.5in;
        text-indent:-.25in;
        font-family:Wingdings;}
@list l2:level7
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:4.0in;
        text-indent:-.25in;
        font-family:Symbol;}
@list l2:level8
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:4.5in;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l2:level9
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:5.0in;
        text-indent:-.25in;
        font-family:Wingdings;}
@list l3
        {mso-list-id:1974557234;
        mso-list-type:hybrid;
        mso-list-template-ids:-729905576 67698689 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l3:level1
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Symbol;}
@list l3:level2
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l3:level3
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Wingdings;}
@list l3:level4
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Symbol;}
@list l3:level5
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l3:level6
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Wingdings;}
@list l3:level7
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Symbol;}
@list l3:level8
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l3:level9
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Wingdings;}
ol
        {margin-bottom:0in;}
ul
        {margin-bottom:0in;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="color:#002060">I’ve worked on something like this in the past, which I found very useful.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#002060"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#002060">The user facing aspect is nice, but I found the real value was creating a human-editable, machine-readable report. I then updated the inliner so it could read in the report as a “replay script”. This enabled
 a bunch of new capabilities:<o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l1 level1 lfo4"><![if !supportLists]><span style="font-family:Symbol;color:#002060"><span style="mso-list:Ignore">·<span style="font:7.0pt "Times New Roman"">        
</span></span></span><![endif]><span style="color:#002060">By editing the script via tools, we could bisect bugs based on inlines, super-useful for whittling down huge inline trees found when doing aggressive inlining.<o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l1 level1 lfo4"><![if !supportLists]><span style="font-family:Symbol;color:#002060"><span style="mso-list:Ignore">·<span style="font:7.0pt "Times New Roman"">        
</span></span></span><![endif]><span style="color:#002060">By collating across failure instances, producing failure reason histograms, useful for prioritizing work on removing limitations.<o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l1 level1 lfo4"><![if !supportLists]><span style="font-family:Symbol;color:#002060"><span style="mso-list:Ignore">·<span style="font:7.0pt "Times New Roman"">        
</span></span></span><![endif]><span style="color:#002060">By cross-referencing decisions vs runtime data (say, dynamic call frequency), various views of effectiveness of inlining.<o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l1 level1 lfo4"><![if !supportLists]><span style="font-family:Symbol;color:#002060"><span style="mso-list:Ignore">·<span style="font:7.0pt "Times New Roman"">        
</span></span></span><![endif]><span style="color:#002060">By editing by hand or tool, easy what-if experiments in changing inlining strategy.<o:p></o:p></span></p>
<p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l1 level1 lfo4"><![if !supportLists]><span style="font-family:Symbol;color:#002060"><span style="mso-list:Ignore">·<span style="font:7.0pt "Times New Roman"">        
</span></span></span><![endif]><span style="color:#002060">By hacking other compilers to emit scripts, I could see what would happen if my compiler could emulate the other compiler’s inlining strategy.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#002060"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#002060">There are tricky aspects to the replay, but in my experience, something like this is very worthwhile.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#002060"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#002060">FWIW I am considering implementing something similar for LLILC....</span><span style="color:#993366"><o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="color:#993366"><o:p> </o:p></span></a></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> llvm-dev [mailto:llvm-dev-bounces@lists.llvm.org]
<b>On Behalf Of </b>Cox, Robert via llvm-dev<br>
<b>Sent:</b> Thursday, October 22, 2015 11:25 AM<br>
<b>To:</b> llvm-dev@lists.llvm.org<br>
<b>Subject:</b> [llvm-dev] RFC: Inlining report<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b>RFC: Inlining Report <o:p></o:p></b></p>
<p class="MsoNormal"><b><span style="color:#1F497D"><o:p> </o:p></span></b></p>
<p class="MsoNormal"><b>Motivation <o:p></o:p></b></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:black">Making good inlining choices while optimizing an application is often key to achieving optimal performance.  While the compiler’s default inlining heuristics sometimes provide great out-of-box results, optimal
 performance is sometimes achieved only after varying the settings of certain compiler options related to inlining or adding “always_inline” or “noinline” attributes to certain functions.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:black">Before we can determine how we need change the compiler’s inlining choices to get better performance for an application, we need to have a clear picture of the compiler’s inlining choices and what motivated them. 
 Many compilers like LLVM and GCC provide <b>informational notes </b>when a function is inlined, but  these notes provide only a “blow by blow” description of what the compiler did, rather than a high level illustration of the result. This high level picture
 can be provided by an <b>inlining report. <o:p></o:p></b></span></p>
<p class="MsoNormal"><span style="color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:black">Over the years, I’ve worked with several compilers that provide inlining reports, and I can attest that the customers using those compilers have found them to be invaluable tool in investigating and improving their
 applications’ performance.  In addition,  the inlining report can be used by compiler developers to visualize and improve the compiler’s default heuristics and option values.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:black">For these reasons, I’d like to contribute code to LLVM to generate an inlining report as part of the inliner.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><b>Description <o:p></o:p></b></p>
<p class="MsoNormal"><span style="color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:black">The inlining report I am proposing contains the following information:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"><o:p> </o:p></span></p>
<p class="MsoListParagraph" style="margin-left:.75in;text-indent:-.25in"><span style="color:black">(1)</span><span style="font-size:7.0pt;font-family:"Times New Roman",serif;color:black">   
</span><span style="color:black">The values of the principle threshold options which affect how much inlining is done under various circumstances<o:p></o:p></span></p>
<p class="MsoListParagraph" style="margin-left:.75in;text-indent:-.25in"><span style="color:black">(2)</span><span style="font-size:7.0pt;font-family:"Times New Roman",serif;color:black">   
</span><span style="color:black">Whether each function is compiled or has been eliminated by dead static function elimination.<o:p></o:p></span></p>
<p class="MsoListParagraph" style="margin-left:.75in;text-indent:-.25in"><span style="color:black">(3)</span><span style="font-size:7.0pt;font-family:"Times New Roman",serif;color:black">   
</span><span style="color:black">For each function, the call sites that were and were not inlined.  Since inlining a call site can expose other call sites for inlining, the inlining report also reports on whether these exposed call sites have been inlined or
 not.  This information is presented in hierarchical manner.<o:p></o:p></span></p>
<p class="MsoListParagraph" style="margin-left:.75in;text-indent:-.25in"><span style="color:black">(4)</span><span style="font-size:7.0pt;font-family:"Times New Roman",serif;color:black">   
</span><span style="color:black">For each call site, we include the principle reason the call site was or was not inlined, together with any cost vs . threshold computation that was done.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><b>High Level Design <o:p></o:p></b></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal">The inline report is created if the option –inline-report=X is passed on command line with a positive integer value of X.  If X is 0, or this option is not specified, the Inliner does not create or perform any operations on the inline report,
 and there is no compile time overhead. <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Three main classes are used to implement the inline report:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b><i>class InlineReportCallSite <o:p></o:p></i></b></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This class contains the inlining report information specific to a particular CallSite CS, including:
<o:p></o:p></p>
<p class="MsoListParagraph" style="margin-left:.75in;text-indent:-.25in">(1)<span style="font-size:7.0pt;font-family:"Times New Roman",serif">   
</span>A bool indicating whether or not the CallSite was or was not inlined <o:p>
</o:p></p>
<p class="MsoListParagraph" style="margin-left:.75in;text-indent:-.25in">(2)<span style="font-size:7.0pt;font-family:"Times New Roman",serif">   
</span>An inlining reason  indicating why the CallSite was or was not inlined <o:p>
</o:p></p>
<p class="MsoListParagraph" style="margin-left:.75in;text-indent:-.25in">(3)<span style="font-size:7.0pt;font-family:"Times New Roman",serif">   
</span>The inlining cost, outer inlining cost, and threshold values used in calculating the profitability of inlining
<o:p></o:p></p>
<p class="MsoListParagraph" style="margin-left:.75in;text-indent:-.25in">(4)<span style="font-size:7.0pt;font-family:"Times New Roman",serif">   
</span>A vector of InlineReportCallSite*, each of which points to an InlineReportCallSite for a CallSite exposed when CS was inlined.  <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b><i>class InlineReportFunction <o:p></o:p></i></b></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This class contains the inlining report information specific to a particular Function F in the call graph, including:
<o:p></o:p></p>
<p class="MsoListParagraph" style="margin-left:.75in;text-indent:-.25in">(1)<span style="font-size:7.0pt;font-family:"Times New Roman",serif">   
</span>A bool indicating whether the function has been dead static eliminated. <o:p>
</o:p></p>
<p class="MsoListParagraph" style="margin-left:.75in;text-indent:-.25in">(2)<span style="font-size:7.0pt;font-family:"Times New Roman",serif">   
</span>A vector of call InlineReportCallSite*, each of which points to an InlineReportCallSite for a CallSite that appeared in F before any inlining was applied.
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b><i>class InlineReport <o:p></o:p></i></b></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The main class which summarizes the high level information in the inline report, including:
<o:p></o:p></p>
<p class="MsoListParagraph" style="margin-left:.75in;text-indent:-.25in">(1)<span style="font-size:7.0pt;font-family:"Times New Roman",serif">   
</span>The values of the inlining threshold options<o:p></o:p></p>
<p class="MsoListParagraph" style="margin-left:.75in;text-indent:-.25in">(2)<span style="font-size:7.0pt;font-family:"Times New Roman",serif">   
</span>The “level” of the inlining report, which is a bit vector of feature options.  For example, whether to print external functions and intrinsics, whether to print the inlining reasons, etc.
<o:p></o:p></p>
<p class="MsoListParagraph" style="margin-left:.75in;text-indent:-.25in">(3)<span style="font-size:7.0pt;font-family:"Times New Roman",serif">   
</span>A map MF from each Function* to InlineReportFunction* <o:p></o:p></p>
<p class="MsoListParagraph" style="margin-left:.75in;text-indent:-.25in">(4)<span style="font-size:7.0pt;font-family:"Times New Roman",serif">   
</span>A map MCS from each CallSite* to InlineReportCallSite* <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">In addition, the class InlineCost (from InlineCost.h) is augmented to include the primary reason a call site was inlined.  
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The class Inliner has been augmented with an InlineReport, which is created when an Inliner is constructed. The InlineReport is updated using calls to the member functions of these three classes in Inliner::runOnSCC() and the functions
 called by it.  <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Before any inlining is done in a particular call to runOnSCC(), the map MF is updated so that each Function (caller or callee) that will be examined for inlining has a corresponding InlineReportFunction in the map.  (The map MCS is also
 updated in a similar way, but only when a Function is actually inlined.) <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The Inliner determines if a CallSite should be inlined by first calling Inliner::ShouldInline().   This calls getInlineCost() which returns an InlineCost, which now includes the reason the call site should or should not be inlined.  This
 reason, as well and costs and threshold from the InlineCost are stored in the InlineReportCallSite for the CallSite. 
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Then Inliner calls the static function InlineCallPossible(). If the inlining was not performed, the reason for not inlining is recorded in the InlineReportCallSite corresponding to the CallSite.  If the inlining was performed, the corresponding
 InlineReportCallSite is marked as inlined, and it is populated with the InlineReportCallSites corresponding to the newly exposed CallSites that were created during the inlining. 
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The InlineReport is printed during the call to Inliner::doFinalization().
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Since the compiler can run any number of optimizations between two successive calls to runOnSCC(), the Instructions corresponding to CallSites can be deleted by the optimizations.  Callbacks are used to mark the corresponding InlineReportCallSites
 as deleted when this happens. <o:p></o:p></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="color:black">Example <o:p></o:p></span></b></p>
<p class="MsoNormal"><span style="color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:black">Here is an example of abbreviated inlining report that is generated in my locally modified copy of the LLVM sources.  I generated this by compiling the file bzip2.c from the spec 2006 benchmark 401.bzip.  (For
 the sake of brevity, I didn’t include all of the report</span>.  Omitted parts are indicated by …. in the report.)
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b>---- Begin Inlining Report ----<o:p></o:p></b></p>
<p class="MsoNormal"><b><o:p> </o:p></b></p>
<p class="MsoNormal"><b>Option Values:<o:p></o:p></b></p>
<p class="MsoNormal"><b>  inline-threshold: 225<o:p></o:p></b></p>
<p class="MsoNormal"><b>  inlinehint-threshold: 325<o:p></o:p></b></p>
<p class="MsoNormal"><b>  inlinecold-threshold: 225<o:p></o:p></b></p>
<p class="MsoNormal"><b>  inlineoptsize-threshold: 15<o:p></o:p></b></p>
<p class="MsoNormal"><b><o:p> </o:p></b></p>
<p class="MsoNormal"><b>COMPILE FUNC: fopen_output_safely<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: open<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: fdopen<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: close<o:p></o:p></b></p>
<p class="MsoNormal"><b><o:p> </o:p></b></p>
<p class="MsoNormal"><b>DEAD STATIC FUNC: setExit<o:p></o:p></b></p>
<p class="MsoNormal"><b><o:p> </o:p></b></p>
<p class="MsoNormal"><b>DEAD STATIC FUNC: copyFileName<o:p></o:p></b></p>
<p class="MsoNormal"><b><o:p> </o:p></b></p>
<p class="MsoNormal"><b>DEAD STATIC FUNC: showFileNames<o:p></o:p></b></p>
<p class="MsoNormal"><b><o:p> </o:p></b></p>
<p class="MsoNormal"><b>DEAD STATIC FUNC: stat<o:p></o:p></b></p>
<p class="MsoNormal"><b><o:p> </o:p></b></p>
<p class="MsoNormal"><b>….<o:p></o:p></b></p>
<p class="MsoNormal"><b><o:p> </o:p></b></p>
<p class="MsoNormal"><b>COMPILE FUNC: cleanUpAndFail<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> llvm.lifetime.start<o:p></o:p></b></p>
<p class="MsoNormal"><b>      [[Callee is intrinsic]]<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> INLINE: stat (35<=487)<o:p></o:p></b></p>
<p class="MsoNormal"><b>      <<Callee is single basic block>><o:p></o:p></b></p>
<p class="MsoNormal"><b>      -> EXTERN: __xstat<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: fprintf<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: fclose<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: remove<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: fprintf<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: fprintf<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: fprintf<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: fprintf<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: fprintf<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: fprintf<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> INLINE: setExit (15<=225)<o:p></o:p></b></p>
<p class="MsoNormal"><b>      <<Inlining is profitable>><o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: exit<o:p></o:p></b></p>
<p class="MsoNormal"><b><o:p> </o:p></b></p>
<p class="MsoNormal"><b>….<o:p></o:p></b></p>
<p class="MsoNormal"><b><o:p> </o:p></b></p>
<p class="MsoNormal"><b>COMPILE FUNC: outOfMemory<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: fprintf<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> INLINE: showFileNames (70<=225)<o:p></o:p></b></p>
<p class="MsoNormal"><b>      <<Inlining is profitable>><o:p></o:p></b></p>
<p class="MsoNormal"><b>      -> EXTERN: fprintf<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> cleanUpAndFail<o:p></o:p></b></p>
<p class="MsoNormal"><b>      [[Callee is noreturn]]<o:p></o:p></b></p>
<p class="MsoNormal"><b><o:p> </o:p></b></p>
<p class="MsoNormal"><b>….<o:p></o:p></b></p>
<p class="MsoNormal"><b><o:p> </o:p></b></p>
<p class="MsoNormal"><b>COMPILE FUNC: snocString<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> INLINE: mkCell (-14920<=225)<o:p></o:p></b></p>
<p class="MsoNormal"><b>      <<Callee has single callsite and local linkage>><o:p></o:p></b></p>
<p class="MsoNormal"><b>      -> INLINE: myMalloc (70<=225)<o:p></o:p></b></p>
<p class="MsoNormal"><b>         <<Inlining is profitable>><o:p></o:p></b></p>
<p class="MsoNormal"><b>         -> EXTERN: malloc<o:p></o:p></b></p>
<p class="MsoNormal"><b>         -> outOfMemory<o:p></o:p></b></p>
<p class="MsoNormal"><b>            [[Callee is noreturn]]<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: strlen<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> INLINE: myMalloc (-14925<=225)<o:p></o:p></b></p>
<p class="MsoNormal"><b>      <<Callee has single callsite and local linkage>><o:p></o:p></b></p>
<p class="MsoNormal"><b>      -> EXTERN: malloc<o:p></o:p></b></p>
<p class="MsoNormal"><b>      -> outOfMemory<o:p></o:p></b></p>
<p class="MsoNormal"><b>         [[Callee is noreturn]]<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: strcpy<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> snocString<o:p></o:p></b></p>
<p class="MsoNormal"><b>      [[Callee is never inline]]<o:p></o:p></b></p>
<p class="MsoNormal"><b><o:p> </o:p></b></p>
<p class="MsoNormal"><b>…..<o:p></o:p></b></p>
<p class="MsoNormal"><b><o:p> </o:p></b></p>
<p class="MsoNormal"><b>---- End Inlining Report ------<o:p></o:p></b></p>
<p class="MsoNormal"><b><o:p> </o:p></b></p>
<p class="MsoNormal">Here is an explanation of some of the features:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoListParagraph" style="text-indent:-.25in">(1)<span style="font-size:7.0pt;font-family:"Times New Roman",serif">   
</span>Option values<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b><span style="background:yellow;mso-highlight:yellow">Option Values:<o:p></o:p></span></b></p>
<p class="MsoNormal"><b><span style="background:yellow;mso-highlight:yellow">  inline-threshold: 225<o:p></o:p></span></b></p>
<p class="MsoNormal"><b><span style="background:yellow;mso-highlight:yellow">  inlinehint-threshold: 325<o:p></o:p></span></b></p>
<p class="MsoNormal"><b><span style="background:yellow;mso-highlight:yellow">  inlinecold-threshold: 225<o:p></o:p></span></b></p>
<p class="MsoNormal"><b><span style="background:yellow;mso-highlight:yellow">  inlineoptsize-threshold: 15</span><o:p></o:p></b></p>
<p class="MsoNormal"><b><o:p> </o:p></b></p>
<p class="MsoNormal">The report begins with a list of the most relevant option values to inlining.
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoListParagraph" style="text-indent:-.25in">(2)<span style="font-size:7.0pt;font-family:"Times New Roman",serif">   
</span>Compiled and dead functions<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b><span style="background:yellow;mso-highlight:yellow">COMPILE FUNC: fopen_output_safely</span><o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: open<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: fdopen<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: close<o:p></o:p></b></p>
<p class="MsoNormal"><b><o:p> </o:p></b></p>
<p class="MsoNormal"><b><span style="background:yellow;mso-highlight:yellow">DEAD STATIC FUNC: setExit</span><o:p></o:p></b></p>
<p class="MsoNormal"><b><o:p> </o:p></b></p>
<p class="MsoNormal">Functions in the file are identified as either being compiled or eliminated by dead static function elimination.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoListParagraph" style="text-indent:-.25in">(3)<span style="font-size:7.0pt;font-family:"Times New Roman",serif">   
</span>External function calls <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b>COMPILE FUNC: fopen_output_safely<o:p></o:p></b></p>
<p class="MsoNormal"><b>   <span style="background:yellow;mso-highlight:yellow">-> EXTERN: open<o:p></o:p></span></b></p>
<p class="MsoNormal"><b><span style="background:yellow;mso-highlight:yellow">   -> EXTERN: fdopen<o:p></o:p></span></b></p>
<p class="MsoNormal"><b><span style="background:yellow;mso-highlight:yellow">   -> EXTERN: close</span><o:p></o:p></b></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Calls to externally defined functions are indicated by the word EXTERN.  These lines can optionally be omitted.
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoListParagraph" style="text-indent:-.25in">(4)<span style="font-size:7.0pt;font-family:"Times New Roman",serif">   
</span>Inlining and nesting  <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b>COMPILE FUNC: snocString<o:p></o:p></b></p>
<p class="MsoNormal"><b>   <span style="background:yellow;mso-highlight:yellow">-> INLINE: mkCell (-14920<=225)</span><o:p></o:p></b></p>
<p class="MsoNormal"><b>      <<Callee has single callsite and local linkage>><o:p></o:p></b></p>
<p class="MsoNormal"><b>      <span style="background:yellow;mso-highlight:yellow">
-> INLINE: myMalloc (70<=225)</span><o:p></o:p></b></p>
<p class="MsoNormal"><b>         <<Inlining is profitable>><o:p></o:p></b></p>
<p class="MsoNormal"><b>         -> EXTERN: malloc<o:p></o:p></b></p>
<p class="MsoNormal"><b><o:p> </o:p></b></p>
<p class="MsoNormal">Inlined functions are marked INLINE. The inlining of a function within other inlined functions is shown clearly in the report using indentation.
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoListParagraph" style="text-indent:-.25in">(5)<span style="font-size:7.0pt;font-family:"Times New Roman",serif">   
</span>Reasons functions were and were not inlined<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b>COMPILE FUNC: cleanUpAndFail<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> llvm.lifetime.start<o:p></o:p></b></p>
<p class="MsoNormal"><b>      <span style="background:yellow;mso-highlight:yellow">
[[Callee is intrinsic]]</span><o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> INLINE: stat <span style="background:yellow;mso-highlight:yellow">
(35<=487)</span><o:p></o:p></b></p>
<p class="MsoNormal"><b>      <span style="background:yellow;mso-highlight:yellow">
<<Callee is single basic block>></span><o:p></o:p></b></p>
<p class="MsoNormal"><b>      -> EXTERN: __xstat<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: fprintf<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: fclose<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: remove<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: fprintf<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: fprintf<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: fprintf<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: fprintf<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: fprintf<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: fprintf<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> INLINE: setExit <span style="background:yellow;mso-highlight:yellow">
(15<=225)</span><o:p></o:p></b></p>
<p class="MsoNormal"><b>      <span style="background:yellow;mso-highlight:yellow">
<<Inlining is profitable>></span><o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: exit<o:p></o:p></b></p>
<p class="MsoNormal"><b><o:p> </o:p></b></p>
<p class="MsoNormal">….<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b>COMPILE FUNC: outOfMemory<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: fprintf<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> INLINE: showFileNames <span style="background:yellow;mso-highlight:yellow">
(70<=225)</span><o:p></o:p></b></p>
<p class="MsoNormal"><b>      <span style="background:yellow;mso-highlight:yellow">
<<Inlining is profitable>></span><o:p></o:p></b></p>
<p class="MsoNormal"><b>      -> EXTERN: fprintf<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> cleanUpAndFail<o:p></o:p></b></p>
<p class="MsoNormal"><b>      <span style="background:yellow;mso-highlight:yellow">
[[Callee is noreturn]]</span><o:p></o:p></b></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The principal reason a function was or was not inlined can be optionally displayed in the report.  The reason a function was inlined is indicated in double angle brackets << >>.  The reason a function was not inlined is indicated in double
 square brackets [[ ]].   When a comparison of the cost and threshold was used to determine if the function should be inlined, the comparison done is given.   (Since intrinsics are never inlined, information about them can be suppressed in the report.) The
 reasons for or for not inlining can optionally be displayed on the same line as the function considered for inlining for easy analysis using grep, awk, etc.
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoListParagraph" style="text-indent:-.25in">(6)<span style="font-size:7.0pt;font-family:"Times New Roman",serif">   
</span>Line and column info <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b>COMPILE FUNC: outOfMemory<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> EXTERN: fprintf   <span style="background:yellow;mso-highlight:yellow">bzip2.c(1016,4)</span><o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> showFileNames   <span style="background:yellow;mso-highlight:yellow">bzip2.c(1019,4)</span> [[Callee is never inline]]<o:p></o:p></b></p>
<p class="MsoNormal"><b>   -> cleanUpAndFail   <span style="background:yellow;mso-highlight:yellow">bzip2.c(1020,4)</span> [[Callee is never inline]]<o:p></o:p></b></p>
<p class="MsoNormal"><b><o:p> </o:p></b></p>
<p class="MsoNormal">Optionally, file, line, and column info can be provided for call sites if source position information is present (using –g or
<o:p></o:p></p>
<p class="MsoNormal">–gline-tables-only). <o:p></o:p></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal">I would appreciate any comments you have on whether you support the inclusion of an inline report in LLVM, the form and features I have outlined above, and your thoughts on the high level design.
<o:p></o:p></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal">Thank you in advance for your comments,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Robert Cox<o:p></o:p></p>
<p class="MsoNormal"><a href="mailto:robert.cox@intel.com"><span style="color:windowtext;text-decoration:none">robert.cox@intel.com</span></a>
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>