File: flatten-and-annotate.ll

package info (click to toggle)
llvm-toolchain-20 1%3A20.1.6-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,111,304 kB
  • sloc: cpp: 7,438,677; ansic: 1,393,822; asm: 1,012,926; python: 241,650; f90: 86,635; objc: 75,479; lisp: 42,144; pascal: 17,286; sh: 10,027; ml: 5,082; perl: 4,730; awk: 3,523; makefile: 3,349; javascript: 2,251; xml: 892; fortran: 672
file content (100 lines) | stat: -rw-r--r-- 3,293 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
; REQUIRES: x86_64-linux
;
; RUN: rm -rf %t
; RUN: split-file %s %t
; RUN: llvm-ctxprof-util fromYAML --input=%t/profile.yaml --output=%t/profile.ctxprofdata
; RUN: opt -module-summary -passes='thinlto-pre-link<O2>' -use-ctx-profile=%t/profile.ctxprofdata \
; RUN:   %t/example.ll -S -o %t/prelink.ll
; RUN: FileCheck --input-file %t/prelink.ll %s --check-prefix=PRELINK
; RUN: opt -passes='ctx-prof-flatten' -use-ctx-profile=%t/profile.ctxprofdata %t/prelink.ll -S  | FileCheck %s
;
;
; Check that instrumentation occurs where expected: the "no" block for both foo and
; @an_entrypoint - which explains the subsequent branch weights
;
; PRELINK-LABEL: @foo
; PRELINK-LABEL: yes:
; PRELINK-LABEL: no:
; PRELINK-NEXT:     call void @llvm.instrprof.increment(ptr @foo, i64 [[#]], i32 2, i32 1)

; PRELINK-LABEL: @an_entrypoint
; PRELINK-LABEL: yes:
; PRELINK-NEXT:    call void @llvm.instrprof.increment(ptr @an_entrypoint, i64 [[#]], i32 2, i32 1)
; PRELINK-NOT: "ProfileSummary"

; Check that the output has:
;  - no instrumentation
;  - the 2 functions have an entry count
;  - each conditional branch has profile annotation
;
; CHECK-NOT:   call void @llvm.instrprof
;
; make sure we have function entry counts, branch weights, and a profile summary.
; CHECK-LABEL: @foo
; CHECK-SAME:    !prof ![[FOO_EP:[0-9]+]]
; CHECK:          br i1 %t, label %yes, label %no, !prof ![[FOO_BW:[0-9]+]]
; CHECK-LABEL: @an_entrypoint
; CHECK-SAME:    !prof ![[AN_ENTRYPOINT_EP:[0-9]+]]
; CHECK:          br i1 %t, label %yes, label %common.ret, !prof ![[AN_ENTRYPOINT_BW:[0-9]+]]


; CHECK:      ![[#]] = !{i32 1, !"ProfileSummary", !1}
; CHECK:      ![[#]] = !{!"TotalCount", i64 480}
; CHECK:      ![[#]] = !{!"MaxCount", i64 140}
; CHECK:      ![[#]] = !{!"MaxInternalCount", i64 125}
; CHECK:      ![[#]] = !{!"MaxFunctionCount", i64 140}
; CHECK:      ![[#]] = !{!"NumCounts", i64 6}
; CHECK:      ![[#]] = !{!"NumFunctions", i64 2}
;
; @foo will be called both unconditionally and conditionally, on the "yes" branch
; which has a count of 40. So 140 times.

; CHECK:       ![[FOO_EP]] = !{!"function_entry_count", i64 140} 

; foo's "no" branch is taken 10+5 times (from the 2 contexts belonging to foo).
; Which means its "yes" branch is taken 140 - 15 times.

; CHECK:       ![[FOO_BW]] = !{!"branch_weights", i32 125, i32 15} 
; CHECK:       ![[AN_ENTRYPOINT_EP]] = !{!"function_entry_count", i64 100}
; CHECK:       ![[AN_ENTRYPOINT_BW]] = !{!"branch_weights", i32 40, i32 60} 

;--- profile.yaml
- Guid: 4909520559318251808
  Counters: [100, 40]
  Callsites: -
              - Guid: 11872291593386833696
                Counters: [ 100, 5 ]
             -
              - Guid: 11872291593386833696
                Counters: [ 40, 10 ]
;--- example.ll
declare void @bar()

define void @foo(i32 %a, ptr %fct) #0 !guid !0 {
  %t = icmp sgt i32 %a, 7
  br i1 %t, label %yes, label %no
yes:
  call void %fct(i32 %a)
  br label %exit
no:
  call void @bar()
  br label %exit
exit:
  ret void
}

define void @an_entrypoint(i32 %a) !guid !1 {
  %t = icmp sgt i32 %a, 0
  call void @foo(i32 10, ptr null)
  br i1 %t, label %yes, label %no

yes:
  call void @foo(i32 1, ptr null)
  ret void
no:
  ret void
}

attributes #0 = { noinline }
!0 = !{ i64 11872291593386833696 }
!1 = !{i64 4909520559318251808}