[llvm] r237265 - Add function entry counts from sample profiles.

Diego Novillo dnovillo at google.com
Wed May 13 10:04:29 PDT 2015


Author: dnovillo
Date: Wed May 13 12:04:29 2015
New Revision: 237265

URL: http://llvm.org/viewvc/llvm-project?rev=237265&view=rev
Log:
Add function entry counts from sample profiles.

This patch uses the new function profile metadata "function_entry_count"
to annotate entry counts from sample profiles.

In a sampling profile, the total samples collected at the function entry
are an approximation for the number of times that function was invoked.

Added:
    llvm/trunk/test/Transforms/SampleProfile/Inputs/entry_counts.prof
    llvm/trunk/test/Transforms/SampleProfile/entry_counts.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp?rev=237265&r1=237264&r2=237265&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SampleProfile.cpp Wed May 13 12:04:29 2015
@@ -580,6 +580,10 @@ void SampleProfileLoader::propagateWeigh
   bool Changed = true;
   unsigned i = 0;
 
+  // Add an entry count to the function using the samples gathered
+  // at the function entry.
+  F.setEntryCount(Samples->getHeadSamples());
+
   // Before propagation starts, build, for each block, a list of
   // unique predecessors and successors. This is necessary to handle
   // identical edges in multiway branches. Since we visit all blocks and all

Added: llvm/trunk/test/Transforms/SampleProfile/Inputs/entry_counts.prof
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SampleProfile/Inputs/entry_counts.prof?rev=237265&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/SampleProfile/Inputs/entry_counts.prof (added)
+++ llvm/trunk/test/Transforms/SampleProfile/Inputs/entry_counts.prof Wed May 13 12:04:29 2015
@@ -0,0 +1,3 @@
+empty:100:13293
+0: 0
+1: 100

Added: llvm/trunk/test/Transforms/SampleProfile/entry_counts.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SampleProfile/entry_counts.ll?rev=237265&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/SampleProfile/entry_counts.ll (added)
+++ llvm/trunk/test/Transforms/SampleProfile/entry_counts.ll Wed May 13 12:04:29 2015
@@ -0,0 +1,24 @@
+; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/entry_counts.prof -S | FileCheck %s
+
+; According to the profile, function empty() was called 13,293 times.
+; CHECK: {{.*}} = !{!"function_entry_count", i64 13293}
+
+define void @empty() {
+entry:
+  ret void, !dbg !9
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!6, !7}
+!llvm.ident = !{!8}
+
+!0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.7.0 (trunk 237249) (llvm/trunk 237261)", isOptimized: false, runtimeVersion: 0, emissionKind: 2, enums: !2, retainedTypes: !2, subprograms: !3, globals: !2, imports: !2)
+!1 = !DIFile(filename: "entry_counts.c", directory: "/usr/local/google/home/dnovillo/llvm/test/pgo")
+!2 = !{}
+!3 = !{!4}
+!4 = !DISubprogram(name: "empty", scope: !1, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: false, function: void ()* @empty, variables: !2)
+!5 = !DISubroutineType(types: !2)
+!6 = !{i32 2, !"Dwarf Version", i32 4}
+!7 = !{i32 2, !"Debug Info Version", i32 3}
+!8 = !{!"clang version 3.7.0 (trunk 237249) (llvm/trunk 237261)"}
+!9 = !DILocation(line: 1, column: 15, scope: !4)





More information about the llvm-commits mailing list