<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:times new roman,serif">Artur, I have renamed the flag in llvm-profdata: <a href="https://github.com/llvm/llvm-project/commit/56926ae0faa67ac4c3b75609bfeea2eb324c0851" style="font-family:Arial,Helvetica,sans-serif">https://github.com/llvm/llvm-project/commit/56926ae0faa67ac4c3b75609bfeea2eb324c0851</a></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">Thanks,</div><div class="gmail_default" style="font-family:times new roman,serif">Wei.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 12, 2020 at 10:31 AM Wei Mi <<a href="mailto:wmi@google.com">wmi@google.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 dir="ltr"><div dir="ltr"><div style="font-family:"times new roman",serif">Thanks Artur for letting me know the problem. I will prepare a patch to fix it. </div><div style="font-family:"times new roman",serif"><br></div><div style="font-family:"times new roman",serif">Wei.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 12, 2020 at 9:50 AM Artur Pilipenko <<a href="mailto:apilipenko@azul.com" target="_blank">apilipenko@azul.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">Hi Wei, <br>
<br>
This change introduces a cl::opt partial-profile which conflicts with partial-profile option in llvm-profdata tool. The conflict happens in builds with LLVM_LINK_LLVM_DYLIB enabled. In this case the tools are linked with libLLVM and we end up with two definitions for the same cl::opt.<br>
<br>
Can we rename one of the options to avoid this?<br>
<br>
Artur<br>
<br>
> On 8 May 2020, at 11:30, Wei Mi via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br>
> <br>
> <br>
> Author: Wei Mi<br>
> Date: 2020-05-08T11:18:09-07:00<br>
> New Revision: aa2ddfc73d6e4a3369b7992aecaf107987c505b6<br>
> <br>
> URL: <a href="https://github.com/llvm/llvm-project/commit/aa2ddfc73d6e4a3369b7992aecaf107987c505b6" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/aa2ddfc73d6e4a3369b7992aecaf107987c505b6</a><br>
> DIFF: <a href="https://github.com/llvm/llvm-project/commit/aa2ddfc73d6e4a3369b7992aecaf107987c505b6.diff" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/aa2ddfc73d6e4a3369b7992aecaf107987c505b6.diff</a><br>
> <br>
> LOG: [SampleFDO] For functions without profiles, provide an option to put<br>
> them in a special text section.<br>
> <br>
> For sampleFDO, because the optimized build uses profile generated from<br>
> previous release, previously we couldn't tell a function without profile<br>
> was truely cold or just newly created so we had to treat them conservatively<br>
> and put them in .text section instead of .text.unlikely. The result was when<br>
> we persuing the best performance by locking .text.hot and .text in memory,<br>
> we wasted a lot of memory to keep cold functions inside.<br>
> <br>
> In <a href="https://reviews.llvm.org/D66374" rel="noreferrer" target="_blank">https://reviews.llvm.org/D66374</a>, we introduced profile symbol list to<br>
> discriminate functions being cold versus functions being newly added.<br>
> This mechanism works quite well for regular use cases in AutoFDO. However,<br>
> in some case, we can only have a partial profile when optimizing a target.<br>
> The partial profile may be an aggregated profile collected from many targets.<br>
> The profile symbol list method used for regular sampleFDO profile is not<br>
> applicable to partial profile use case because it may be too large and<br>
> introduce many false positives.<br>
> <br>
> To solve the problem for partial profile use case, we provide an option called<br>
> --profile-unknown-in-special-section. For functions without profile, we will<br>
> still treat them conservatively in compiler optimizations -- for example,<br>
> treat them as warm instead of cold in inliner. When we use profile info to<br>
> add section prefix for functions, we will discriminate functions known to be<br>
> not cold versus functions without profile (being unknown), and we will put<br>
> functions being unknown in a special text section called .text.unknown.<br>
> Runtime system will have the flexibility to decide where to put the special<br>
> section in order to achieve a balance between performance and memory saving.<br>
> <br>
> Differential Revision: <a href="https://reviews.llvm.org/D62540" rel="noreferrer" target="_blank">https://reviews.llvm.org/D62540</a><br>
> <br>
> Added: <br>
> <br>
> <br>
> Modified: <br>
>    llvm/include/llvm/Analysis/ProfileSummaryInfo.h<br>
>    llvm/lib/Analysis/ProfileSummaryInfo.cpp<br>
>    llvm/lib/CodeGen/CodeGenPrepare.cpp<br>
>    llvm/test/Transforms/SampleProfile/section-accurate-samplepgo.ll<br>
> <br>
> Removed: <br>
> <br>
> <br>
> <br>
> ################################################################################<br>
> diff  --git a/llvm/include/llvm/Analysis/ProfileSummaryInfo.h b/llvm/include/llvm/Analysis/ProfileSummaryInfo.h<br>
> index e293d069f1f1..8fbc9e8990b2 100644<br>
> --- a/llvm/include/llvm/Analysis/ProfileSummaryInfo.h<br>
> +++ b/llvm/include/llvm/Analysis/ProfileSummaryInfo.h<br>
> @@ -72,13 +72,6 @@ class ProfileSummaryInfo {<br>
>            Summary->getKind() == ProfileSummary::PSK_Sample;<br>
>   }<br>
> <br>
> -  /// Returns true if module \c M has partial-profile sample profile.<br>
> -  bool hasPartialSampleProfile() {<br>
> -    return hasProfileSummary() &&<br>
> -           Summary->getKind() == ProfileSummary::PSK_Sample &&<br>
> -           Summary->isPartialProfile();<br>
> -  }<br>
> -<br>
>   /// Returns true if module \c M has instrumentation profile.<br>
>   bool hasInstrumentationProfile() {<br>
>     return hasProfileSummary() &&<br>
> @@ -106,6 +99,8 @@ class ProfileSummaryInfo {<br>
>   Optional<uint64_t> getProfileCount(const CallBase &CallInst,<br>
>                                      BlockFrequencyInfo *BFI,<br>
>                                      bool AllowSynthetic = false);<br>
> +  /// Returns true if module \c M has partial-profile sample profile.<br>
> +  bool hasPartialSampleProfile();<br>
>   /// Returns true if the working set size of the code is considered huge.<br>
>   bool hasHugeWorkingSetSize();<br>
>   /// Returns true if the working set size of the code is considered large.<br>
> @@ -118,6 +113,8 @@ class ProfileSummaryInfo {<br>
>   bool isFunctionEntryCold(const Function *F);<br>
>   /// Returns true if \p F contains only cold code.<br>
>   bool isFunctionColdInCallGraph(const Function *F, BlockFrequencyInfo &BFI);<br>
> +  /// Returns true if the hotness of \p F is unknown.<br>
> +  bool isFunctionHotnessUnknown(const Function &F);<br>
>   /// Returns true if \p F contains hot code with regard to a given hot<br>
>   /// percentile cutoff value.<br>
>   bool isFunctionHotInCallGraphNthPercentile(int PercentileCutoff,<br>
> <br>
> diff  --git a/llvm/lib/Analysis/ProfileSummaryInfo.cpp b/llvm/lib/Analysis/ProfileSummaryInfo.cpp<br>
> index dd53aa78f40f..ef33b9b1de5a 100644<br>
> --- a/llvm/lib/Analysis/ProfileSummaryInfo.cpp<br>
> +++ b/llvm/lib/Analysis/ProfileSummaryInfo.cpp<br>
> @@ -66,6 +66,10 @@ static cl::opt<int> ProfileSummaryColdCount(<br>
>     cl::desc("A fixed cold count that overrides the count derived from"<br>
>              " profile-summary-cutoff-cold"));<br>
> <br>
> +static cl::opt<bool> PartialProfile(<br>
> +    "partial-profile", cl::Hidden, cl::init(false),<br>
> +    cl::desc("Specify the current profile is used as a partial profile."));<br>
> +<br>
> // Find the summary entry for a desired percentile of counts.<br>
> static const ProfileSummaryEntry &getEntryForPercentile(SummaryEntryVector &DS,<br>
>                                                         uint64_t Percentile) {<br>
> @@ -192,6 +196,11 @@ bool ProfileSummaryInfo::isFunctionColdInCallGraph(const Function *F,<br>
>   return true;<br>
> }<br>
> <br>
> +bool ProfileSummaryInfo::isFunctionHotnessUnknown(const Function &F) {<br>
> +  assert(hasPartialSampleProfile() && "Expect partial sample profile");<br>
> +  return !F.getEntryCount().hasValue();<br>
> +}<br>
> +<br>
> template<bool isHot><br>
> bool ProfileSummaryInfo::isFunctionHotOrColdInCallGraphNthPercentile(<br>
>     int PercentileCutoff, const Function *F, BlockFrequencyInfo &BFI) {<br>
> @@ -399,6 +408,12 @@ bool ProfileSummaryInfo::isColdCallSite(const CallBase &CB,<br>
>   return hasSampleProfile() && CB.getCaller()->hasProfileData();<br>
> }<br>
> <br>
> +bool ProfileSummaryInfo::hasPartialSampleProfile() {<br>
> +  return hasProfileSummary() &&<br>
> +         Summary->getKind() == ProfileSummary::PSK_Sample &&<br>
> +         (PartialProfile || Summary->isPartialProfile());<br>
> +}<br>
> +<br>
> INITIALIZE_PASS(ProfileSummaryInfoWrapperPass, "profile-summary-info",<br>
>                 "Profile summary info", false, true)<br>
> <br>
> <br>
> diff  --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp<br>
> index 359618d6669a..eceee30c532f 100644<br>
> --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp<br>
> +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp<br>
> @@ -177,6 +177,17 @@ static cl::opt<bool> ProfileGuidedSectionPrefix(<br>
>     "profile-guided-section-prefix", cl::Hidden, cl::init(true), cl::ZeroOrMore,<br>
>     cl::desc("Use profile info to add section prefix for hot/cold functions"));<br>
> <br>
> +static cl::opt<bool> ProfileUnknownInSpecialSection(<br>
> +    "profile-unknown-in-special-section", cl::Hidden, cl::init(false),<br>
> +    cl::ZeroOrMore,<br>
> +    cl::desc("In profiling mode like sampleFDO, if a function doesn't have "<br>
> +             "profile, we cannot tell the function is cold for sure because "<br>
> +             "it may be a function newly added without ever being sampled. "<br>
> +             "With the flag enabled, compiler can put such profile unknown "<br>
> +             "functions into a special section, so runtime system can choose "<br>
> +             "to handle it in a <br>
> diff erent way than .text section, to save "<br>
> +             "RAM for example. "));<br>
> +<br>
> static cl::opt<unsigned> FreqRatioToSkipMerge(<br>
>     "cgp-freq-ratio-to-skip-merge", cl::Hidden, cl::init(2),<br>
>     cl::desc("Skip merging empty blocks if (frequency of empty block) / "<br>
> @@ -452,6 +463,9 @@ bool CodeGenPrepare::runOnFunction(Function &F) {<br>
>       F.setSectionPrefix(".hot");<br>
>     else if (PSI->isFunctionColdInCallGraph(&F, *BFI))<br>
>       F.setSectionPrefix(".unlikely");<br>
> +    else if (ProfileUnknownInSpecialSection && PSI->hasPartialSampleProfile() &&<br>
> +             PSI->isFunctionHotnessUnknown(F))<br>
> +      F.setSectionPrefix(".unknown");<br>
>   }<br>
> <br>
>   /// This optimization identifies DIV instructions that can be<br>
> <br>
> diff  --git a/llvm/test/Transforms/SampleProfile/section-accurate-samplepgo.ll b/llvm/test/Transforms/SampleProfile/section-accurate-samplepgo.ll<br>
> index 82c407ebb9d2..6ac39a167689 100644<br>
> --- a/llvm/test/Transforms/SampleProfile/section-accurate-samplepgo.ll<br>
> +++ b/llvm/test/Transforms/SampleProfile/section-accurate-samplepgo.ll<br>
> @@ -1,5 +1,6 @@<br>
> ; REQUIRES: x86-registered-target<br>
> ; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/inline.prof -codegenprepare -S | FileCheck %s<br>
> +; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/inline.prof -codegenprepare -profile-unknown-in-special-section -partial-profile -S | FileCheck %s --check-prefix UNKNOWN<br>
> ; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/inline.prof -codegenprepare -profile-sample-accurate -S | FileCheck %s --check-prefix ACCURATE<br>
> <br>
> target triple = "x86_64-pc-linux-gnu"<br>
> @@ -11,7 +12,8 @@ target triple = "x86_64-pc-linux-gnu"<br>
> declare void @hot_func()<br>
> <br>
> ; CHECK-NOT: foo_not_in_profile{{.*}}!section_prefix<br>
> -; CHECK: foo_not_in_profile{{.*}}!prof ![[UNKNOWN_ID:[0-9]+]]<br>
> +; CHECK: foo_not_in_profile{{.*}}!prof ![[NOPROFILE_ID:[0-9]+]]<br>
> +; UNKNOWN: foo_not_in_profile{{.*}}!prof ![[NOPROFILE_ID:[0-9]+]] !section_prefix ![[UNKNOWN_ID:[0-9]+]]<br>
> ; ACCURATE: foo_not_in_profile{{.*}}!prof ![[ZERO_ID:[0-9]+]] !section_prefix ![[COLD_ID:[0-9]+]]<br>
> ; The function not appearing in profile is cold when -profile-sample-accurate<br>
> ; is on.<br>
> @@ -31,9 +33,11 @@ define void @bar_not_in_profile() #0 {<br>
> <br>
> attributes #0 = { "profile-sample-accurate" }<br>
> <br>
> -; CHECK: ![[UNKNOWN_ID]] = !{!"function_entry_count", i64 -1}<br>
> +; CHECK: ![[NOPROFILE_ID]] = !{!"function_entry_count", i64 -1}<br>
> ; CHECK: ![[ZERO_ID]] = !{!"function_entry_count", i64 0}<br>
> ; CHECK: ![[COLD_ID]] = !{!"function_section_prefix", !".unlikely"}<br>
> +; UNKNOWN: ![[NOPROFILE_ID]] = !{!"function_entry_count", i64 -1}<br>
> +; UNKNOWN: ![[UNKNOWN_ID]] = !{!"function_section_prefix", !".unknown"}<br>
> ; ACCURATE: ![[ZERO_ID]] = !{!"function_entry_count", i64 0}<br>
> ; ACCURATE: ![[COLD_ID]] = !{!"function_section_prefix", !".unlikely"}<br>
> !llvm.module.flags = !{!1}<br>
> <br>
> <br>
> <br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
<br>
</blockquote></div></div>
</blockquote></div></div>