forked from llvm-mirror/llvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SamplePGO - Add initial support for inliner annotations.
This adds two thresholds to the sample profiler to affect inlining decisions: the concept of global hotness and coldness. Functions that have accumulated more than a certain fraction of samples at runtime, are annotated with the InlineHint attribute. Conversely, functions that accumulate less than a certain fraction of samples, are annotated with the Cold attribute. This is very similar to the hints emitted by Clang when using instrumentation profiles. Notice that this is a very blunt instrument. A function may have globally collected a significant fraction of samples, but that does not necessarily mean that every callsite for that function is hot. Ideally, we would annotate each callsite with the samples collected at that callsite. This way, the inliner can incorporate all these weights into its cost model. Once the inliner offers this functionality, we can change the hints emitted here to a more precise per-callsite annotation. For now, this is providing some measure of speedups with our internal benchmarks. I've observed speedups of up to 23% (though the geo mean is about 3%). I expect these numbers to improve as the inliner gets better annotations. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254212 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
Showing
3 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
_Z6hot_fnRxi:700:0 | ||
_Z7cold_fnRxi:1:0 | ||
other:299:0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
; RUN: opt %s -sample-profile -sample-profile-file=%S/Inputs/inline-hint.prof -pass-remarks=sample-profile -o /dev/null 2>&1 | FileCheck %s | ||
; | ||
; CHECK: Applied cold hint to globally cold function '_Z7cold_fnRxi' with 0.1 | ||
define void @_Z7cold_fnRxi() !dbg !4 { | ||
entry: | ||
ret void, !dbg !29 | ||
} | ||
|
||
; CHECK: Applied inline hint to globally hot function '_Z6hot_fnRxi' with 70.0 | ||
define void @_Z6hot_fnRxi() #0 !dbg !10 { | ||
entry: | ||
ret void, !dbg !38 | ||
} | ||
|
||
!llvm.module.flags = !{!17, !18} | ||
!llvm.ident = !{!19} | ||
|
||
!1 = !DIFile(filename: "inline-hint.cc", directory: ".") | ||
!2 = !{} | ||
!3 = !{!4, !10, !11, !14} | ||
!4 = distinct !DISubprogram(name: "cold_fn", linkageName: "_Z7cold_fnRxi", scope: !1, file: !1, line: 3, type: !5, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: false, variables: !2) | ||
!5 = !DISubroutineType(types: !6) | ||
!6 = !{null, !7, !9} | ||
!7 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !8, size: 64, align: 64) | ||
!8 = !DIBasicType(name: "long long int", size: 64, align: 64, encoding: DW_ATE_signed) | ||
!9 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) | ||
!10 = distinct !DISubprogram(name: "hot_fn", linkageName: "_Z6hot_fnRxi", scope: !1, file: !1, line: 7, type: !5, isLocal: false, isDefinition: true, scopeLine: 7, flags: DIFlagPrototyped, isOptimized: false, variables: !2) | ||
!11 = distinct !DISubprogram(name: "compute", linkageName: "_Z7computex", scope: !1, file: !1, line: 11, type: !12, isLocal: false, isDefinition: true, scopeLine: 11, flags: DIFlagPrototyped, isOptimized: false, variables: !2) | ||
!12 = !DISubroutineType(types: !13) | ||
!13 = !{!8, !8} | ||
!14 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 21, type: !15, isLocal: false, isDefinition: true, scopeLine: 21, flags: DIFlagPrototyped, isOptimized: false, variables: !2) | ||
!15 = !DISubroutineType(types: !16) | ||
!16 = !{!9} | ||
!17 = !{i32 2, !"Dwarf Version", i32 4} | ||
!18 = !{i32 2, !"Debug Info Version", i32 3} | ||
!19 = !{!"clang version 3.8.0 (trunk 254067) (llvm/trunk 254079)"} | ||
!29 = !DILocation(line: 5, column: 1, scope: !4) | ||
!38 = !DILocation(line: 9, column: 1, scope: !10) |