[llvm] r353434 - [HotColdSplit] With PGO add profile entry metadata to split cold function

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 7 09:50:36 PST 2019


Author: tejohnson
Date: Thu Feb  7 09:50:35 2019
New Revision: 353434

URL: http://llvm.org/viewvc/llvm-project?rev=353434&view=rev
Log:
[HotColdSplit] With PGO add profile entry metadata to split cold function

Summary:
When compiling with profile data, ensure the split cold function gets
cold function_entry_count metadata (just use 0 since it should be cold).
Otherwise with function sections it will not be placed in the unlikely
text section with other cold code.

Reviewers: vsk

Subscribers: sebpop, hiraditya, davidxl, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D57900

Added:
    llvm/trunk/test/Transforms/HotColdSplit/coldentrycount.ll
Modified:
    llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp

Modified: llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp?rev=353434&r1=353433&r2=353434&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp Thu Feb  7 09:50:35 2019
@@ -144,8 +144,10 @@ static bool mayExtractBlock(const BasicB
 }
 
 /// Mark \p F cold. Based on this assumption, also optimize it for minimum size.
+/// If \p UpdateEntryCount is true (set when this is a new split function and
+/// module has profile data), set entry count to 0 to ensure treated as cold.
 /// Return true if the function is changed.
-static bool markFunctionCold(Function &F) {
+static bool markFunctionCold(Function &F, bool UpdateEntryCount = false) {
   assert(!F.hasFnAttribute(Attribute::OptimizeNone) && "Can't mark this cold");
   bool Changed = false;
   if (!F.hasFnAttribute(Attribute::Cold)) {
@@ -156,6 +158,13 @@ static bool markFunctionCold(Function &F
     F.addFnAttr(Attribute::MinSize);
     Changed = true;
   }
+  if (UpdateEntryCount) {
+    // Set the entry count to 0 to ensure it is placed in the unlikely text
+    // section when function sections are enabled.
+    F.setEntryCount(0);
+    Changed = true;
+  }
+
   return Changed;
 }
 
@@ -340,7 +349,7 @@ Function *HotColdSplitting::extractColdR
     }
     CI->setIsNoInline();
 
-    markFunctionCold(*OutF);
+    markFunctionCold(*OutF, BFI != nullptr);
 
     LLVM_DEBUG(llvm::dbgs() << "Outlined Region: " << *OutF);
     ORE.emit([&]() {

Added: llvm/trunk/test/Transforms/HotColdSplit/coldentrycount.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/HotColdSplit/coldentrycount.ll?rev=353434&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/HotColdSplit/coldentrycount.ll (added)
+++ llvm/trunk/test/Transforms/HotColdSplit/coldentrycount.ll Thu Feb  7 09:50:35 2019
@@ -0,0 +1,43 @@
+; Test to ensure that split cold function gets 0 entry count profile
+; metadata when compiling with pgo.
+
+; RUN: opt -hotcoldsplit -hotcoldsplit-threshold=0 -S < %s | FileCheck %s
+
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.14.0"
+
+; CHECK-LABEL: @fun
+; CHECK: call void @fun.cold.1
+define void @fun() !prof !14 {
+entry:
+  br i1 undef, label %if.then, label %if.else
+
+if.then:
+  ret void
+
+if.else:
+  call void @sink()
+  ret void
+}
+
+declare void @sink() cold
+
+; CHECK: define {{.*}} @fun.cold.1{{.*}} ![[PROF:[0-9]+]]
+; CHECK: ![[PROF]] = !{!"function_entry_count", i64 0}
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 1, !"ProfileSummary", !1}
+!1 = !{!2, !3, !4, !5, !6, !7, !8, !9}
+!2 = !{!"ProfileFormat", !"InstrProf"}
+!3 = !{!"TotalCount", i64 10000}
+!4 = !{!"MaxCount", i64 10}
+!5 = !{!"MaxInternalCount", i64 1}
+!6 = !{!"MaxFunctionCount", i64 1000}
+!7 = !{!"NumCounts", i64 3}
+!8 = !{!"NumFunctions", i64 3}
+!9 = !{!"DetailedSummary", !10}
+!10 = !{!11, !12, !13}
+!11 = !{i32 10000, i64 100, i32 1}
+!12 = !{i32 999000, i64 100, i32 1}
+!13 = !{i32 999999, i64 1, i32 2}
+!14 = !{!"function_entry_count", i64 100}




More information about the llvm-commits mailing list