.text/.data etc are considered section name prefixes, so suffix added to a prefix is still part of the prefix. <div><br></div><div>David<span></span><br><br>On Monday, February 22, 2016, David Majnemer via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 22, 2016 at 2:14 PM, Dehao Chen via llvm-commits <span dir="ltr"><<a href="javascript:_e(%7B%7D,'cvml','llvm-commits@lists.llvm.org');" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: dehao<br>
Date: Mon Feb 22 16:14:14 2016<br>
New Revision: 261582<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=261582&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=261582&view=rev</a><br>
Log:<br>
Add prefix based function layout when profile is available.<br>
<br>
Summary: If a function is hot, put it in text.hot section.<br>
<br>
Reviewers: davidxl<br>
<br>
Subscribers: eraman, mcrosier, llvm-commits<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D17460" rel="noreferrer" target="_blank">http://reviews.llvm.org/D17460</a><br>
<br>
Added:<br>
    llvm/trunk/test/CodeGen/X86/partition-sections.ll<br>
Modified:<br>
    llvm/trunk/include/llvm/ProfileData/ProfileCommon.h<br>
    llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp<br>
    llvm/trunk/lib/ProfileData/ProfileSummary.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/ProfileData/ProfileCommon.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/ProfileCommon.h?rev=261582&r1=261581&r2=261582&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/ProfileCommon.h?rev=261582&r1=261581&r2=261582&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/ProfileData/ProfileCommon.h (original)<br>
+++ llvm/trunk/include/llvm/ProfileData/ProfileCommon.h Mon Feb 22 16:14:14 2016<br>
@@ -21,6 +21,8 @@<br>
 #define LLVM_PROFILEDATA_PROFILE_COMMON_H<br>
<br>
 namespace llvm {<br>
+class Function;<br>
+class Module;<br>
 namespace IndexedInstrProf {<br>
 struct Summary;<br>
 }<br>
@@ -28,6 +30,8 @@ namespace sampleprof {<br>
 class FunctionSamples;<br>
 }<br>
 struct InstrProfRecord;<br>
+inline const char *getHotSectionPrefix() { return ".hot"; }<br>
+inline const char *getUnlikelySectionPrefix() { return ".unlikely"; }<br></blockquote><div><br></div><div>Shouldn't this be Suffix instead of Prefix?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
 // The profile summary is one or more (Cutoff, MinCount, NumCounts) triplets.<br>
 // The semantics of counts depend on the type of profile. For instrumentation<br>
 // profile, counts are block counts and for sample profile, counts are<br>
@@ -66,6 +70,10 @@ protected:<br>
<br>
 public:<br>
   static const int Scale = 1000000;<br>
+  // \brief Returns true if F is a hot function.<br>
+  static bool isFunctionHot(const Function *F);<br>
+  // \brief Returns true if F is unlikley executed.<br>
+  static bool isFunctionUnlikely(const Function *F);<br>
   inline std::vector<ProfileSummaryEntry> &getDetailedSummary();<br>
   void computeDetailedSummary();<br>
   /// \brief A vector of useful cutoff values for detailed summary.<br>
<br>
Modified: llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp?rev=261582&r1=261581&r2=261582&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp?rev=261582&r1=261581&r2=261582&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp Mon Feb 22 16:14:14 2016<br>
@@ -34,6 +34,7 @@<br>
 #include "llvm/MC/MCSymbolELF.h"<br>
 #include "llvm/MC/MCValue.h"<br>
 #include "llvm/ProfileData/InstrProf.h"<br>
+#include "llvm/ProfileData/ProfileCommon.h"<br>
 #include "llvm/Support/COFF.h"<br>
 #include "llvm/Support/Dwarf.h"<br>
 #include "llvm/Support/ELF.h"<br>
@@ -244,6 +245,11 @@ static StringRef getSectionPrefixForGlob<br>
   return ".<a href="http://data.rel.ro" rel="noreferrer" target="_blank">data.rel.ro</a>";<br>
 }<br>
<br>
+static cl::opt<bool> GroupFunctionsByHotness(<br>
+    "group-functions-by-hotness",<br>
+    llvm::cl::desc("Partition hot/cold functions by sections prefix"),<br>
+    cl::init(false));<br>
+<br>
 static MCSectionELF *<br>
 selectELFSectionForGlobal(MCContext &Ctx, const GlobalValue *GV,<br>
                           SectionKind Kind, Mangler &Mang,<br>
@@ -294,6 +300,16 @@ selectELFSectionForGlobal(MCContext &Ctx<br>
     Name = getSectionPrefixForGlobal(Kind);<br>
   }<br>
<br>
+  if (GroupFunctionsByHotness) {<br>
+    if (const Function *F = dyn_cast<Function>(GV)) {<br>
+      if (ProfileSummary::isFunctionHot(F)) {<br>
+        Name += getHotSectionPrefix();<br>
+      } else if (ProfileSummary::isFunctionUnlikely(F)) {<br>
+        Name += getUnlikelySectionPrefix();<br>
+      }<br>
+    }<br>
+  }<br>
+<br>
   if (EmitUniqueSection && UniqueSectionNames) {<br>
     Name.push_back('.');<br>
     TM.getNameWithPrefix(Name, GV, Mang, true);<br>
<br>
Modified: llvm/trunk/lib/ProfileData/ProfileSummary.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/ProfileSummary.cpp?rev=261582&r1=261581&r2=261582&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/ProfileSummary.cpp?rev=261582&r1=261581&r2=261582&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/ProfileData/ProfileSummary.cpp (original)<br>
+++ llvm/trunk/lib/ProfileData/ProfileSummary.cpp Mon Feb 22 16:14:14 2016<br>
@@ -11,6 +11,9 @@<br>
 //<br>
 //===----------------------------------------------------------------------===//<br>
<br>
+#include "llvm/IR/Attributes.h"<br>
+#include "llvm/IR/Function.h"<br>
+#include "llvm/IR/Module.h"<br>
 #include "llvm/ProfileData/InstrProf.h"<br>
 #include "llvm/ProfileData/ProfileCommon.h"<br>
 #include "llvm/ProfileData/SampleProf.h"<br>
@@ -75,6 +78,24 @@ void ProfileSummary::computeDetailedSumm<br>
   }<br>
 }<br>
<br>
+// Returns true if the function is a hot function.<br>
+bool ProfileSummary::isFunctionHot(const Function *F) {<br>
+  // FIXME: update when summary data is stored in module's metadata.<br>
+  return false;<br>
+}<br>
+<br>
+// Returns true if the function is a cold function.<br>
+bool ProfileSummary::isFunctionUnlikely(const Function *F) {<br>
+  if (F->hasFnAttribute(Attribute::Cold)) {<br>
+    return true;<br>
+  }<br>
+  if (!F->getEntryCount()) {<br>
+    return false;<br>
+  }<br>
+  // FIXME: update when summary data is stored in module's metadata.<br>
+  return (*F->getEntryCount()) == 0;<br>
+}<br>
+<br>
 InstrProfSummary::InstrProfSummary(const IndexedInstrProf::Summary &S)<br>
     : ProfileSummary(), MaxInternalBlockCount(S.get(<br>
                             IndexedInstrProf::Summary::MaxInternalBlockCount)),<br>
<br>
Added: llvm/trunk/test/CodeGen/X86/partition-sections.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/partition-sections.ll?rev=261582&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/partition-sections.ll?rev=261582&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/CodeGen/X86/partition-sections.ll (added)<br>
+++ llvm/trunk/test/CodeGen/X86/partition-sections.ll Mon Feb 22 16:14:14 2016<br>
@@ -0,0 +1,31 @@<br>
+; RUN: llc < %s -group-functions-by-hotness=true | FileCheck %s -check-prefix=PARTITION<br>
+; RUN: llc < %s -function-sections -group-functions-by-hotness=false | FileCheck %s -check-prefix=NO-PARTITION-FUNCTION-SECTION<br>
+; RUN: llc < %s -function-sections -group-functions-by-hotness=true | FileCheck %s -check-prefix=PARTITION-FUNCTION-SECTION<br>
+<br>
+; PARTITION: .text.unlikely<br>
+; PARTITION: .globl  _Z3foov<br>
+; NO-PARTITION-FUNCTION-SECTION: .text._Z3foov<br>
+; PARTITION-FUNCTION-SECTION: .text.unlikely._Z3foov<br>
+define i32 @_Z3foov() #0 {<br>
+  ret i32 0<br>
+}<br>
+<br>
+; PARTITION: .globl  _Z3barv<br>
+; NO-PARTITION-FUNCTION-SECTION: .text._Z3barv<br>
+; PARTITION-FUNCTION-SECTION: .text.unlikely._Z3barv<br>
+define i32 @_Z3barv() #1 !prof !0 {<br>
+  ret i32 1<br>
+}<br>
+<br>
+; PARTITION: .text<br>
+; PARTITION: .globl  _Z3bazv<br>
+; NO-PARTITION-FUNCTION-SECTION: .text._Z3bazv<br>
+; PARTITION-FUNCTION-SECTION: .text._Z3bazv<br>
+define i32 @_Z3bazv() #1 {<br>
+  ret i32 2<br>
+}<br>
+<br>
+attributes #0 = { nounwind uwtable cold }<br>
+attributes #1 = { nounwind uwtable }<br>
+<br>
+!0 = !{!"function_entry_count", i64 0}<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="javascript:_e(%7B%7D,'cvml','llvm-commits@lists.llvm.org');" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>
</blockquote></div>