<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:times new roman,serif">Thanks for the proposal and the performance improvement over existing AutoFDO is impressive.   </div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Aug 7, 2020 at 11:28 AM Wenlei He <<a href="mailto:wenlei@fb.com" target="_blank">wenlei@fb.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div lang="EN-US">
<div>
<p class="MsoNormal" style="margin-bottom:12pt"><span style="font-size:11pt;color:black">Hi All,</span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">Our team at Facebook is building a new context-sensitive Sample PGO as an alternative to the existing AutoFDO. We’d like to share our motivation, propose a new design,
 and reveal preliminary results on benchmarks. We will refer to the proposed design as CSSPGO in this RFC.</span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">The new CSSPGO leverages simultaneous LBR and stack sampling to construct a full context-sensitive profile. It doesn’t rely on previous inlining like today’s AutoFDO
 to get context-sensitive profile, and it also doesn’t need a separate post-inline context-sensitive profile like CSPGO. In addition, we introduced pseudo-instrumentation for more accurate mapping from binary samples back to IR, similar to instrumentation PGO,
 but without any measure-able runtime overhead that is usually associated with instrumentation.</span> </p></div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="EN-US"><div><p class="MsoNormal"> </p></div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="EN-US"><div><p class="MsoNormal"><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">We have a functioning implementation for the new CSSPGO now. Initial results on SPEC2006 shows ~2% geomean performance win on top of AutoFDO (with MonoLTO and NewPM)
 and ~4% .text size reduction at the same time.</span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black"> <u></u><u></u></span></p>
<p class="MsoNormal" style="margin-bottom:4pt"><b><span style="font-size:17pt;font-family:Arial,sans-serif;color:black">Motivation</span></b><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(28,30,33)">AutoFDO is a big success as it lowers the entry barrier for PGO significantly while still delivering substantial performance boost. However, there’s still a gap
 between AutoFDO and its instrumentation counterpart. From several failed internal attempts to improve AutoFDO, we realized that the bottleneck of AutoFDO lies in its profile quality. With the current level of profile quality, it’s difficult to reap more performance
 win because good heuristics are often limited by inferior profile. That prompted a systemic effort to investigate and improve AutoFDO framework. Specifically, we’re trying to handle the two biggest sources of profile quality issues:</span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<ol style="margin-top:0in" start="1" type="1">
<li class="MsoNormal" style="color:black;margin-top:12pt;vertical-align:baseline">
<span style="font-size:11pt;font-family:Arial,sans-serif">AutoFDO relies on a limited context-sensitive profile collected based on previous inlining. Therefore it can only replay or prune the previous inlining. With the main CGSCC inliner, post-inline counts
 are not accurate due to scaling of context-less profile, which affects the effectiveness of later passes such as profile-guided code layout.</span><u></u><u></u></li><li class="MsoNormal" style="color:black;margin-bottom:12pt;vertical-align:baseline">
<span style="font-size:11pt;font-family:Arial,sans-serif">Dwarf line and discriminator info aren’t always well-maintained throughout the compilation, thus using them as anchors to map binary samples back to the IR can sometimes be inaccurate, which leads
 to inferior profile quality and limits PGO performance.</span></li></ol></div></div></blockquote><div><div class="gmail_default" style="font-family:"times new roman",serif">Acknowledge to issues. We also found an issue that current AFDO profile doesn't keep edge information and that leads to nonoptimal profile in some cases. Since profile format is needed to be redesigned for component 1, I am thinking whether it is possible to extend the profile format in a way so it can incorporate edge information as well.</div></div><div class="gmail_default" style="font-family:"times new roman",serif"><br></div><div class="gmail_default" style="font-family:"times new roman",serif">About pseudo probe, seemly you doesn't mention in this proposal but does it still provides the ability to solve the source drift issue you mentioned before? If it does, how it is achieved?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="EN-US"><div><ol style="margin-top:0in" start="1" type="1"><li class="MsoNormal" style="color:black;margin-bottom:12pt;vertical-align:baseline"><u></u><u></u></li></ol>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">To lift the above limitations, we’d like to propose an alternative design that consists of two components: 1) Context-sensitive sample PGO, 2) Sample to IR mapping
 using pseudo probes. The goal is to further improve sample PGO performance while maintaining usability and keeping training runtime overhead at zero. In addition, we hope the CSSPGO framework can also open up opportunities for new optimizations with more stringent
 requirements on profile quality.  </span></p></div></div></blockquote><div><br></div><div><div class="gmail_default" style="font-family:"times new roman",serif">I like both ideas, and those two components can be orthogonal? For the first component, I hope the existing debug information based AutoFDO can be benefited from it as well, with some extension to the current profile format. </div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="EN-US"><div><p class="MsoNormal"><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="margin-bottom:4pt"><b><span style="font-size:17pt;font-family:Arial,sans-serif;color:black">Context-sensitive Sample PGO</span></b><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">The effectiveness of BOLT, Propeller and CSPGO all demonstrated the importance of context-sensitive profile for PGO. However there are two limitations with the existing
 approaches.</span><span style="color:black"><u></u><u></u></span></p>
<ol style="margin-top:0in" start="1" type="1">
<li class="MsoNormal" style="color:black;margin-top:12pt;vertical-align:baseline">
<span style="font-size:11pt;font-family:Arial,sans-serif">The current solutions focus on leveraging a context-sensitive profile to attain an accurate post-inline profile that helps achieve a better code layout, but do not use the context-sensitive profile
 to drive better inlining.</span><u></u><u></u></li><li class="MsoNormal" style="color:black;margin-bottom:12pt;vertical-align:baseline">
<span style="font-size:11pt;font-family:Arial,sans-serif">The current solutions involve multiple training processes and profiles (e.g. a post-inline profile for CSPGO, or a post-link profile for BOLT and Propeller), which incurs higher operational cost
 and complicates the build and release workflow.</span><u></u><u></u></li></ol>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">We propose a full context-sensitive sample profiling infrastructure that utilizes both LBR and call stack samples at the same time to synthesize a profile with a
 full context sensitivity. The key advantage is that rather than relying on previous inlining or a separate profile, the profile collected with the new approach will have full calling contexts recovered from both inlined and not inlined call sites. To achieve
 an accurate post-inline profile, a separate profile is no longer needed. Instead, the post-inline profile can be directly derived from adjusting the input profile based on all inline decisions. The richer context-sensitive profile also enables better inline
 decisions. The infrastructure has two key components listed below.</span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black"> <u></u><u></u></span></p>
<p class="MsoNormal" style="margin-bottom:4pt"><b><span style="font-size:13pt;font-family:Arial,sans-serif;color:black">Synthesizing context-sensitive LBR with a virtual unwinder</span></b><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">To make sample PGO’s input profile context aware, we need to know the call stack of each LBR fall through path. That is done by sampling LBR and call stack simultaneously.
 With that, each sample will contain a call stack in addition to LBR entries. We use level 2 PEBS to control sampling skid so that the leaf frame from stack sample aligns with leaf frame from LBR. The raw call stack sample describes the calling context for
 the leaf LBR entry. In addition, by unwinding “call” and “return” (including implicit ones from inlinee) from LBR entries backwards on top of raw stack samples, we can recover the calling context for each of the LBR entries from the sample, thus synthesizing
 context-sensitive LBR profile.</span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;color:black"> </span></p></div></div></blockquote><div><br></div><div><div class="gmail_default" style="font-family:"times new roman",serif">What if the stack unwinding is not intact? For example, tail call optimization may cause unwinding issue currently in perf. framepointer or call frame information may not be properly maintained.  </div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="EN-US"><div><p class="MsoNormal"><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">We can then generate context-sensitive sample PGO profile using the context-sensitive LBR profile. In the new profile, a function’s profile becomes a collection of
 profiles, each representing a profile for a given calling context.</span></p></div></div></blockquote><div><br></div><div><div class="gmail_default" style="font-family:"times new roman",serif">Will the profile size be significantly larger?</div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="EN-US"><div><p class="MsoNormal"><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black"> <u></u><u></u></span></p>
<p class="MsoNormal" style="margin-bottom:4pt"><b><span style="font-size:13pt;font-family:Arial,sans-serif;color:black">Context-sensitive FDO/PGO framework in LLVM</span></b><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">In order to leverage context-sensitive profile for inlining, and to maintain accurate post-inline counts, we introduced </span><span style="font-size:11pt;font-family:"Courier New";color:black">SampleContextTracker</span><span style="font-size:11pt;font-family:Arial,sans-serif;color:black"> which
 is a layer sitting in between input profile and the profile used to annotate CFG for optimizations. We also introduced the notion of base profile which </span><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(28,30,33)">is the merged profile
 for function’s profiles from any outstanding (not inlined) context, </span><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">and context profile which is a function's profile for a given calling context. The framework includes four
 simple APIs for updating and query profiles:</span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">Query API:</span><span style="color:black"><u></u><u></u></span></p>
<ul style="margin-top:0in" type="disc">
<li class="MsoNormal" style="color:black;margin-top:12pt;vertical-align:baseline">
<span style="font-size:11pt;font-family:"Courier New"">getBaseSamplesFor</span><span style="font-size:11pt;font-family:Arial,sans-serif">: Query base profile by function name.</span><u></u><u></u></li><li class="MsoNormal" style="color:black;margin-bottom:12pt;vertical-align:baseline">
<span style="font-size:11pt;font-family:"Courier New"">getContextSamplesFor</span><span style="font-size:11pt;font-family:Arial,sans-serif">: Query context profile by calling context and function name.</span><u></u><u></u></li></ul>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">Update API:</span><span style="color:black"><u></u><u></u></span></p>
<ul style="margin-top:0in" type="disc">
<li class="MsoNormal" style="color:black;margin-top:12pt;vertical-align:baseline">
<span style="font-size:11pt;font-family:"Courier New"">MarkContextSamplesInlined</span><span style="font-size:11pt;font-family:Arial,sans-serif">: When a function is inlined for a given calling context, we need to mark the context profile for that context
 as inlined. This is to make sure we don't include inlined context profile when synthesizing the base profile.</span><u></u><u></u></li><li class="MsoNormal" style="color:black;margin-bottom:12pt;vertical-align:baseline">
<span style="font-size:11pt;font-family:"Courier New"">PromoteMergeContextSamplesTree</span><span style="font-size:11pt;font-family:Arial,sans-serif">: When a function is not inlined for a given calling context, we need to promote the context profile
 tree to be top-level context. This preserves the child context under that function so later inline decisions for calls originating from that not inlined function will still be driven by an accurate context profile.</span><u></u><u></u></li></ul>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">These APIs are used by </span><span style="font-size:11pt;font-family:"Courier New";color:black">SampleProfileLoader</span><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">’s
 inlining, for better inline decisions and better post-inline counts. For optimal results, the new infrastructure needs to work with a top-down FDO inliner. We added top-down FDO inlining under a switch, and the switch is turned on by default in upstream recently.
 There’re a few other improvements for the FDO inliner that we plan to upstream soon.</span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black"> <u></u><u></u></span></p>
<p class="MsoNormal" style="margin-bottom:4pt"><b><span style="font-size:17pt;font-family:Arial,sans-serif;color:black">Pseudo-instrumentation for sample to IR mapping</span></b><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">Being able to profile production binaries is a key advantage of AutoFDO over Instrumentation PGO, but it also comes with a big challenge. While using line number
 and discriminator as anchor for profile mapping incurs zero run time overhead for AutoFDO, it’s not as accurate as instrumented probes. This is because the instrumented probes are part of the IR, rather than metadata attached to the IR like </span><span style="font-size:11pt;font-family:"Courier New";color:black">!dbg</span><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">.
 That has two implications: 1) it’s easier to maintain IR than metadata for optimization passes; 2) probe blocks some CFG transformations that can mess up profile correlation.</span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">With the proposed pseudo instrumentation, we can achieve most of the benefit of instrumentation PGO in little runtime overhead. We instrument each basic block with
 a pseudo probe associated with the block Id. Unlike in PGO instrumentation where a counter is implemented as a persisting operation such as atomic read/write or runtime helper call, a pseudo probe is implemented as a dedicated intrinsic call with </span><span style="font-size:11pt;font-family:"Courier New";color:black">IntrInaccessibleMemOnly</span><span style="font-size:11pt;font-family:Arial,sans-serif;color:black"> flag.
 The intrinsic comes with </span><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(28,30,33)">most of the semantics of a PGO </span><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">counter</span><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(28,30,33)"> but
 is much less optimization-</span><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">intrusive. </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">The pseudo probe intrinsic calls are on the IR throughout the optimization and code generation pipeline and are materialized as a piece of binary data stored in a
 separate </span><span style="font-size:11pt;font-family:"Courier New";color:black">.pseudo_probe</span><span style="font-size:11pt;font-family:Arial,sans-serif;color:black"> data section. The section is then used to map binary samples back to blocks
 of CFG during profile generation. There are also no real machine instructions generated for a pseudo probe and the</span><span style="font-size:11pt;font-family:"Courier New";color:black">.pseudo_probe</span><span style="font-size:11pt;font-family:Arial,sans-serif;color:black"> section
 won’t be loaded into memory at runtime, therefore they should incur very little runtime overhead. As a fact, we see no measure-able performance impact from pseudo-instrumentation itself on SPEC2006 or big internal workload.</span></p></div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="EN-US"><div><p class="MsoNormal"><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black"> <u></u><u></u></span></p>
<p class="MsoNormal" style="margin-bottom:4pt"><b><span style="font-size:13pt;font-family:Arial,sans-serif;color:black">Pseudo-instrumentation integration and Pass Ordering</span></b><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">One implication from pseudo-probe instrumentation is that the profile is now sensitive to CFG changes. We now defect stale profiles for sample PGO via CFG checksum,
 instead of just using it. However, the potential downside is that CFG may change between different versions of the compiler even if the source code is unchanged. To solve that problem, we perform the pseudo instrumentation very early in the pre-LTO pipeline,
 before any CFG transformation. This ensures that the CFG instrumented and annotated is stable. We added </span><span style="font-size:11pt;font-family:"Courier New";color:black">SampleProfileProber</span><span style="font-size:11pt;font-family:Arial,sans-serif;color:black"> that
 performs the pseudo instrumentation and runs independent of profile annotation.</span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">A new switch </span><span style="font-size:11pt;font-family:"Courier New";color:black">-fpseudo-probe-for-profiling</span><span style="font-size:11pt;font-family:Arial,sans-serif;color:black"> is
 added to enable sample PGO with pseudo instrumentation, similar to </span><span style="font-size:11pt;font-family:"Courier New";color:black">-fdebug-info-for-profiling</span><span style="font-size:11pt;font-family:Arial,sans-serif;color:black"> for AutoFDO.
 Input profile is still provided through the same switch used by today’s AutoFDO, namely </span><span style="font-size:11pt;font-family:"Courier New";color:black">-fprofile-sample-use</span><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">,
 and the profile loader will automatically decide how to load and annotate profile depending on whether input profile is dwarf-based or pseudo-probe based.</span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="margin-bottom:4pt"><b><span style="font-size:17pt;font-family:Arial,sans-serif;color:black">New profile format and profile generation</span></b><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">We extend current profile format in order to be able to represent a full context-sensitive profile and also encode pseudo-probe info. This is done without drastically
 diverging from today’s AutoFDO profile format so that existing tools and libraries can be reused with minor changes (e.g. </span><span style="font-size:11pt;font-family:"Courier New";color:black">llvm-profdata</span><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">,
 profiler reader and writer).</span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">For a context-sensitive profile, we extend the profile format by changing the function profile header line to include calling context in addition to function name.
 With today’s AutoFDO, we have a single profile header for each function to represent its accumulative profile. E.g. This is the profile header for </span><span style="font-size:11pt;font-family:"Courier New";color:black">foo</span><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">,
 with 1290 total samples, and 74 header samples.</span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:"Courier New";color:black">foo:1290:74</span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">For CSSPGO, we will have multiple profile headers for a single function’s profile, each representing profile for a specific calling context as shown below. CSSPGO
 profile header is bracketed to differentiate from today’s AutoFDO.</span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:"Courier New";color:black">[main:12 @ bar:3 @ foo]:279:54</span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:"Courier New";color:black">[main:19 @ zoo:7 @ foo]:1011:20</span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">With calling context encoded in the function header, we no longer need a nested function profile for inlinees. Instead, a context profile will be represented uniformly
 using context strings in the function profile header, regardless of whether the calls in the context are inlined or not. The flat structure makes sure that context profile is easily indexable. The change is mostly transparent to tools like </span><span style="font-size:11pt;font-family:"Courier New";color:black">llvm-profdata</span><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">.
 Support for binary profile format has not been added yet, but should be easy to do.</span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">For pseudo-probe, we repurposed the line to count map of AutoFDO profile to be block Id to count map. This only changes the interpretation of profile content rather
 than the representation, hence all reader/writer helpers can be reused.</span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">There's a new profile generation tool, </span><span style="font-size:11pt;font-family:"Courier New";color:black">llvm-profgen</span><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">,
 with the virtual winder implemented for context-sensitive profiling, and uses the </span><span style="font-size:11pt;font-family:"Courier New";color:black">.pseudo_probe</span><span style="font-size:11pt;font-family:Arial,sans-serif;color:black"> section
 to map binary profile to pre-opt CFG profile. Since profile generation is a critical piece of the workflow, we’d like to propose to include the tool as part of LLVM, alongside with </span><span style="font-size:11pt;font-family:"Courier New";color:black">llvm-profdata</span><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">.</span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="margin-bottom:4pt"><b><span style="font-size:17pt;font-family:Arial,sans-serif;color:black">Preliminary Results</span></b><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">To quantitatively assess profile quality improvement brought by pseudo-instrumentation, we introduce a profile quality metric. We measure the metric by first annotating
 an optimized binary with the MIR block execution counts derived from a profile. The binary is then sampled and the counts are compared against the annotation. The weighted relative delta is used as an indicator for profile quality (lower is better). </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">Table below shows the profile quality metric for SPEC2006. We can see from the numbers that the profile quality of pseudo-instrumentation sample PGO is much better
 than AutoFDO and close to instrumentation PGO.</span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal" style="margin-bottom:12pt"><span style="font-size:11pt;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<table border="0" cellspacing="0" cellpadding="0" width="624" style="width:6.5in;border-collapse:collapse">
<tbody>
<tr>
<td valign="top" style="border:1pt solid black;padding:5pt">
<p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">Profile quality metric</span><u></u><u></u></p>
</td>
<td valign="top" style="border-top:1pt solid black;border-right:1pt solid black;border-bottom:1pt solid black;border-left:none;padding:5pt">
<p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">Baseline AutoFDO</span><u></u><u></u></p>
</td>
<td valign="top" style="border-top:1pt solid black;border-right:1pt solid black;border-bottom:1pt solid black;border-left:none;padding:5pt">
<p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">Instrumentation PGO</span><u></u><u></u></p>
</td>
<td valign="top" style="border-top:1pt solid black;border-right:1pt solid black;border-bottom:1pt solid black;border-left:none;padding:5pt">
<p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:9pt;font-family:Arial,sans-serif;color:black">Sample PGO w/ Pseudo Instrumentation</span><u></u><u></u></p>
</td>
</tr>
<tr>
<td valign="top" style="border-right:1pt solid black;border-bottom:1pt solid black;border-left:1pt solid black;border-top:none;padding:5pt">
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">SPEC2006</span><u></u><u></u></p>
</td>
<td valign="top" style="border-top:none;border-left:none;border-bottom:1pt solid black;border-right:1pt solid black;padding:5pt">
<p class="MsoNormal" align="right" style="text-align:right"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">24.58%</span><u></u><u></u></p>
</td>
<td valign="top" style="border-top:none;border-left:none;border-bottom:1pt solid black;border-right:1pt solid black;padding:5pt">
<p class="MsoNormal" align="right" style="text-align:right"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">15.70%</span><u></u><u></u></p>
</td>
<td valign="top" style="border-top:none;border-left:none;border-bottom:1pt solid black;border-right:1pt solid black;padding:5pt">
<p class="MsoNormal" align="right" style="text-align:right"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">16.21%</span><u></u><u></u></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin-bottom:12pt"><span style="font-size:11pt;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">We also measured performance and code size on SPEC2006 with CSSPGO. The measurement was done with MonoLTO and new pass manager, with tuning for FDO inliner to accommodate
 context-sensitive profile, and used training dataset for both pass1 and pass2. The result shows ~2% performance win on top of today’s AutoFDO, with ~4% .text reduction, see table below. </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<table border="0" cellspacing="0" cellpadding="0" width="624" style="width:6.5in;border-collapse:collapse">
<tbody>
<tr style="height:21pt">
<td rowspan="2" valign="top" style="border:1pt solid black;padding:5pt;height:21pt">
<p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">SPEC2006</span><u></u><u></u></p>
</td>
<td colspan="3" valign="top" style="border-top:1pt solid black;border-right:1pt solid black;border-bottom:1pt solid black;border-left:none;padding:5pt;height:21pt">
<p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">Performance</span><u></u><u></u></p>
</td>
<td colspan="3" valign="top" style="border-top:1pt solid black;border-right:1pt solid black;border-bottom:1pt solid black;border-left:none;padding:5pt;height:21pt">
<p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">Code Size</span><u></u><u></u></p>
</td>
</tr>
<tr style="height:21pt">
<td valign="top" style="border-top:none;border-left:none;border-bottom:1pt solid black;border-right:1pt solid black;padding:5pt;height:21pt">
<p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:10pt;font-family:Arial,sans-serif;color:black">AutoFDO over LTO</span><u></u><u></u></p>
</td>
<td width="79" valign="top" style="width:59pt;border-top:none;border-left:none;border-bottom:1pt solid black;border-right:1pt solid black;padding:5pt;height:21pt">
<p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:10pt;font-family:Arial,sans-serif;color:black">CSSPGO</span><u></u><u></u></p>
<p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:10pt;font-family:Arial,sans-serif;color:black">Over LTO</span><u></u><u></u></p>
</td>
<td width="89" valign="top" style="width:66.55pt;border-top:none;border-left:none;border-bottom:1pt solid black;border-right:1pt solid black;padding:5pt;height:21pt">
<p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:9pt;font-family:Arial,sans-serif;color:black">CSSPGO over AutoFDO</span><u></u><u></u></p>
</td>
<td valign="top" style="border-top:none;border-left:none;border-bottom:1pt solid black;border-right:1pt solid black;padding:5pt;height:21pt">
<p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:10pt;font-family:Arial,sans-serif;color:black">AutoFDO over LTO</span><u></u><u></u></p>
</td>
<td valign="top" style="border-top:none;border-left:none;border-bottom:1pt solid black;border-right:1pt solid black;padding:5pt;height:21pt">
<p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:10pt;font-family:Arial,sans-serif;color:black">CSSPGO</span><u></u><u></u></p>
<p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:10pt;font-family:Arial,sans-serif;color:black">Over LTO</span><u></u><u></u></p>
</td>
<td valign="top" style="border-top:none;border-left:none;border-bottom:1pt solid black;border-right:1pt solid black;padding:5pt;height:21pt">
<p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:9pt;font-family:Arial,sans-serif;color:black">CSSPGO over AutoFDO</span><u></u><u></u></p>
</td>
</tr>
<tr>
<td valign="top" style="border-right:1pt solid black;border-bottom:1pt solid black;border-left:1pt solid black;border-top:none;padding:5pt">
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">Geomean Delta %</span><u></u><u></u></p>
</td>
<td valign="top" style="border-top:none;border-left:none;border-bottom:1pt solid black;border-right:1pt solid black;padding:5pt">
<p class="MsoNormal" align="right" style="text-align:right"><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(106,168,79)">6.80%</span><u></u><u></u></p>
</td>
<td width="79" valign="top" style="width:59pt;border-top:none;border-left:none;border-bottom:1pt solid black;border-right:1pt solid black;padding:5pt">
<p class="MsoNormal" align="right" style="text-align:right"><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(106,168,79)">8.70%</span><u></u><u></u></p>
</td>
<td width="89" valign="top" style="width:66.55pt;border-top:none;border-left:none;border-bottom:1pt solid black;border-right:1pt solid black;padding:5pt">
<p class="MsoNormal" align="right" style="text-align:right"><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(106,168,79)">2.04%</span><u></u><u></u></p>
</td>
<td valign="top" style="border-top:none;border-left:none;border-bottom:1pt solid black;border-right:1pt solid black;padding:5pt">
<p class="MsoNormal" align="right" style="text-align:right"><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(204,0,0)">11.17%</span><u></u><u></u></p>
</td>
<td valign="top" style="border-top:none;border-left:none;border-bottom:1pt solid black;border-right:1pt solid black;padding:5pt">
<p class="MsoNormal" align="right" style="text-align:right"><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(204,0,0)">6.66%</span><u></u><u></u></p>
</td>
<td valign="top" style="border-top:none;border-left:none;border-bottom:1pt solid black;border-right:1pt solid black;padding:5pt">
<p class="MsoNormal" align="right" style="text-align:right"><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(204,0,0)">4.06%</span><u></u><u></u></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><span style="font-size:11pt;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">While the SPEC2006 benchmark suite is different from large workloads, we think the results demonstrated the potential of CSSPGO and served its purpose for proof of
 concept. We plan to continue tuning and start to evaluate larger internal workloads soon, and we’d like to upstream our work. Feedbacks are welcomed!</span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">Thanks,</span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Arial,sans-serif;color:black">Wenlei & Hongtao</span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;color:black"> </span><span style="color:black"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:black"><u></u> <u></u></span></p>
</div>
</div>

</blockquote></div></div>