<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p>This really sounds like it should be an analysis pass. 
      Summarizing the results into the IR using the existing
      entry_county attributes sounds like a workaround for an
      invalidation problem more than anything else.  <br>
    </p>
    <p>You acknowledge this in your alternatives discussion, but I don't
      follow why BFI invalidation at the function level has to
      invalidate the inter procedural result.  You'd certainly need to
      use BFI when *running* your analysis, but once computed the
      results should be stable across updates within the function.  You
      might need update logic for inlining, outlining, and mergefunc,
      but that should be it in terms of current LLVM transforms?</p>
    <p>Philip<br>
    </p>
    <br>
    <div class="moz-cite-prefix">On 12/12/2017 05:02 PM, Easwaran Raman
      via llvm-dev wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAPK5YPa0fuWVx-k4vi_3_fP3kifT-iYQdGAROh8bCcRXpoTM-w@mail.gmail.com">
      <div dir="ltr"><span
          id="gmail-docs-internal-guid-54633d65-4d61-93c5-4945-401b16f25f9a">
          <p dir="ltr"
            style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">Functions in LLVM IR have a function_entry_count metadata that is attached in PGO compilation. By using the entry count together with the block frequency info, the compiler computes the profile count of call instructions based on which the hotness/coldness of callsites can be determined. Experiments have shown that using a higher threshold for hot callsites results in improved runtime performance of the generated code without significant code size increases. We propose to generate synthetic function counts for non-PGO compilation and use the counts for boosting hot callsites during inlining. </span></p>
          <br>
          <p dir="ltr"
            style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">Synthetic function entry counts of functions are initialized based on properties of the function such as whether it is visible outside the module, whether it has an inline keyword and so on. Then, the callgraph SCC is traversed in reverse post-order. Counts of callsites are determined based on the entry count and the block frequency of the callsite. The callsite count gets added to the entry count of the callee. For targets of indirect calls, we will use the !callees metadata to find the possible targets and distribute the count equally among them. For functions in a non-trivial SCC, the algorithm has to ensure that the counts are stable and deterministic.</span></p>
          <br>
          <p dir="ltr"
            style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap"> In ThinLTO mode, the function summary contains the list of call edges from the function. We propose to add the relative block frequency on these edges. During the thinlink phase, we propagate the function counts on the entire call graph and update the function summary with the synthetic counts. Additionally, we plan to use the computed counts to drive the importing decisions. </span></p>
          <br>
          <p dir="ltr"
            style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">Alternative approach </span></p>
          <p dir="ltr"
            style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">-----------------------------</span></p>
          <p dir="ltr"
            style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">
</span></p>
          <p dir="ltr"
            style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">An alternative to generating synthetic counts is to make block frequency info an inter-procedural analysis. Such an analysis would allow comparing BFI of callsites in two different functions. This has several downsides:</span></p>
          <ul style="margin-top:0pt;margin-bottom:0pt">
            <li dir="ltr" style="list-style-type:disc;font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-space:pre"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;background-color:transparent;vertical-align:baseline;white-space:pre-wrap">The inter-procedural BFI computation is likely to be more expensive in terms of compile-time. </span></p></li>
            <li dir="ltr" style="list-style-type:disc;font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-space:pre"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;background-color:transparent;vertical-align:baseline;white-space:pre-wrap">Many function passes invalidate the BFI. This will require selective invalidation of function BFIs.</span></p></li>
            <li dir="ltr" style="list-style-type:disc;font-size:11pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-space:pre"><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:11pt;background-color:transparent;vertical-align:baseline;white-space:pre-wrap">Inliner correctly updates function counts of a callee after a callsite is inlined. We can piggyback on this mechanism by using synthetic counts. </span></p></li>
          </ul>
        </span></div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>