Summary: This pass synthesizes function entry counts by traversing the callgraph and using the relative block frequencies of the callsites. The intended use of these counts is in inlining to determine hot/cold callsites in the absence of profile information. The pass is split into two files with the code that propagates the counts in a callgraph in a Utils file. I plan to add support for propagation in the thinlto link phase and the propagation code will be shared and hence this split. I did not add support to the old PM since hot callsite determination in inlining is not possible in old PM (although we could use hot callee heuristic with synthetic counts in the old PM it is not worth the effort tuning it) Reviewers: davidxl, silvas Subscribers: mgorny, mehdi_amini, llvm-commits Differential Revision: https://reviews.llvm.org/D41604 llvm-svn: 322110
51 lines
1.3 KiB
LLVM
51 lines
1.3 KiB
LLVM
; RUN: opt -passes=synthetic-counts-propagation -S < %s | FileCheck %s
|
|
|
|
; CHECK-LABEL: define void @level1a(i32 %n)
|
|
; CHECK: !prof ![[COUNT1:[0-9]+]]
|
|
define void @level1a(i32 %n) {
|
|
entry:
|
|
%cmp = icmp sgt i32 %n, 10
|
|
br i1 %cmp, label %exit, label %loop
|
|
loop:
|
|
%i = phi i32 [%n, %entry], [%i1, %loop]
|
|
call void @level2a(i32 %n)
|
|
%i1 = sub i32 %i, 1
|
|
%cmp2 = icmp eq i32 %i1, 0
|
|
br i1 %cmp2, label %exit, label %loop, !prof !1
|
|
exit:
|
|
ret void
|
|
}
|
|
|
|
; CHECK-LABEL: define void @level2a(i32 %n)
|
|
; CHECK: !prof ![[COUNT2:[0-9]+]]
|
|
define void @level2a(i32 %n) {
|
|
call void @level2b(i32 %n)
|
|
ret void
|
|
}
|
|
|
|
; CHECK-LABEL: define void @level2b(i32 %n)
|
|
; CHECK: !prof ![[COUNT2]]
|
|
define void @level2b(i32 %n) {
|
|
entry:
|
|
call void @level2a(i32 %n)
|
|
%cmp = icmp eq i32 %n, 0
|
|
br i1 %cmp, label %then, label %else, !prof !2
|
|
then:
|
|
call void @level3a(i32 %n)
|
|
br label %else
|
|
else:
|
|
ret void
|
|
}
|
|
|
|
; CHECK-LABEL: define internal void @level3a(i32 %n)
|
|
; CHECK: !prof ![[COUNT3:[0-9]+]]
|
|
define internal void @level3a(i32 %n) {
|
|
ret void
|
|
}
|
|
|
|
!1 = !{!"branch_weights", i32 1, i32 99}
|
|
!2 = !{!"branch_weights", i32 1, i32 1}
|
|
; CHECK: ![[COUNT1]] = !{!"synthetic_function_entry_count", i64 10}
|
|
; CHECK: ![[COUNT2]] = !{!"synthetic_function_entry_count", i64 520}
|
|
; CHECK: ![[COUNT3]] = !{!"synthetic_function_entry_count", i64 260}
|