File: inline.ll

package info (click to toggle)
llvm-toolchain-21 1%3A21.1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,245,028 kB
  • sloc: cpp: 7,619,726; ansic: 1,434,018; asm: 1,058,748; python: 252,740; f90: 94,671; objc: 70,685; lisp: 42,813; pascal: 18,401; sh: 8,601; ml: 5,111; perl: 4,720; makefile: 3,675; awk: 3,523; javascript: 2,409; xml: 892; fortran: 770
file content (131 lines) | stat: -rw-r--r-- 5,232 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
; 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 -passes='module-inline,print<ctx-prof-analysis>' -ctx-profile-printer-level=everything %t/1000.ll -S \
; RUN:   -use-ctx-profile=%t/profile.ctxprofdata -ctx-profile-printer-level=yaml \
; RUN:   -o - 2> %t/profile-final.yaml | FileCheck %s
; RUN: diff %t/profile-final.yaml %t/expected.yaml

; There are 2 calls to @a from @entrypoint. We only inline the one callsite
; marked as alwaysinline, the rest are blocked (marked noinline). After the inline,
; the updated contextual profile should still have the same tree for the non-inlined case.
; For the inlined case, we should observe, for the @entrypoint context:
;  - an empty callsite where the inlined one was (first one, i.e. 0)
;  - more counters appended to the old counter list (because we ingested the
;    ones from @a). The values are copied.
;  - a new callsite to @b
; CHECK-LABEL: @entrypoint
; CHECK-LABEL: yes:
; CHECK:         call void @llvm.instrprof.increment(ptr @entrypoint, i64 0, i32 3, i32 1)
; CHECK-NEXT:    br label %loop.i
; CHECK-LABEL:  loop.i:
; CHECK-NEXT:    %indvar.i = phi i32 [ %indvar.next.i, %loop.i ], [ 0, %yes ]
; CHECK-NEXT:    call void @llvm.instrprof.increment(ptr @entrypoint, i64 0, i32 2, i32 3)
; CHECK-NEXT:    %b.i = add i32 %x, %indvar.i
; CHECK-NEXT:    call void @llvm.instrprof.callsite(ptr @entrypoint, i64 0, i32 1, i32 2, ptr @b)
; CHECK-NEXT:    %call3.i = call i32 @b() #1
; CHECK-LABEL: no:
; CHECK-NEXT:    call void @llvm.instrprof.increment(ptr @entrypoint, i64 0, i32 3, i32 2)
; CHECK-NEXT:    call void @llvm.instrprof.callsite(ptr @entrypoint, i64 0, i32 2, i32 1, ptr @a)
; CHECK-NEXT:    %call2 = call i32 @a(i32 %x) #1
; CHECK-NEXT:    br label %exit

; Make sure the postlink thinlto pipeline is aware of ctxprof
; RUN: opt -passes='thinlto<O2>' -use-ctx-profile=%t/profile.ctxprofdata \
; RUN:   %t/1000.ll -S -o - | FileCheck %s --check-prefix=PIPELINE

; PIPELINE-LABEL: define i32 @entrypoint
; PIPELINE-SAME: !prof ![[ENTRYPOINT_COUNT:[0-9]+]]
; PIPELINE-LABEL: loop.i:
; PIPELINE:         br i1 %cond.i, label %loop.i, label %exit, !prof ![[LOOP_BW_INL:[0-9]+]]
; PIPELINE-LABEL: define i32 @a
; PIPELINE-LABEL: loop:
; PIPELINE:         br i1 %cond, label %loop, label %exit, !prof ![[LOOP_BW_ORIG:[0-9]+]]

; *Note* that all values are multiplied by the TotalRootEntryCount, which is 24
;
; PIPELINE: ![[ENTRYPOINT_COUNT]] = !{!"function_entry_count", i64 240}
; These are the weights of the inlined @a, where the counters were 2, 100 (2 for entry, 100 for loop)
; PIPELINE: ![[LOOP_BW_INL]] = !{!"branch_weights", i32 2352, i32 48}
; These are the weights of the un-inlined @a, where the counters were 8, 500 (8 for entry, 500 for loop)
; PIPELINE: ![[LOOP_BW_ORIG]] = !{!"branch_weights", i32 11808, i32 192}

;--- 1000.ll
define i32 @entrypoint(i32 %x) !guid !0 {
  call void @llvm.instrprof.increment(ptr @entrypoint, i64 0, i32 3, i32 0)
  %t = icmp eq i32 %x, 0
  br i1 %t, label %yes, label %no
yes:
  call void @llvm.instrprof.increment(ptr @entrypoint, i64 0, i32 3, i32 1)
  call void @llvm.instrprof.callsite(ptr @entrypoint, i64 0, i32 2, i32 0, ptr @a)
  %call1 = call i32 @a(i32 %x) alwaysinline
  br label %exit
no:
  call void @llvm.instrprof.increment(ptr @entrypoint, i64 0, i32 3, i32 2)
  call void @llvm.instrprof.callsite(ptr @entrypoint, i64 0, i32 2, i32 1, ptr @a)
  %call2 = call i32 @a(i32 %x) noinline
  br label %exit
exit:
  %ret = phi i32 [%call1, %yes], [%call2, %no]
  ret i32 %ret
}

define i32 @a(i32 %x) !guid !1 {
entry:
  call void @llvm.instrprof.increment(ptr @a, i64 0, i32 2, i32 0)
  br label %loop
loop:
  %indvar = phi i32 [%indvar.next, %loop], [0, %entry]
  call void @llvm.instrprof.increment(ptr @a, i64 0, i32 2, i32 1)
  %b = add i32 %x, %indvar
  call void @llvm.instrprof.callsite(ptr @a, i64 0, i32 1, i32 0, ptr @b)
  %call3 = call i32 @b() noinline
  %indvar.next = add i32 %indvar, %call3
  %cond = icmp slt i32 %indvar.next, %x
  br i1 %cond, label %loop, label %exit
exit:
  ret i32 8
}

define i32 @b() !guid !2 {
  call void @llvm.instrprof.increment(ptr @b, i64 0, i32 1, i32 0)
  ret i32 1
}

!0 = !{i64 1000}
!1 = !{i64 1001}
!2 = !{i64 1002}
;--- profile.yaml
Contexts:
  - Guid: 1000
    TotalRootEntryCount: 24
    Counters: [10, 2, 8]
    Callsites:  -
                  - Guid: 1001
                    Counters: [2, 100]
                    Callsites:  -
                                  - Guid: 1002
                                    Counters: [100]
                -
                  - Guid: 1001
                    Counters: [8, 500]
                    Callsites:  -
                                  - Guid: 1002
                                    Counters: [500]
;--- expected.yaml

Contexts:
  - Guid:            1000
    TotalRootEntryCount: 24
    Counters:        [ 10, 2, 8, 100 ]
    Callsites:
      - [  ]
      - - Guid:            1001
          Counters:        [ 8, 500 ]
          Callsites:
            - - Guid:            1002
                Counters:        [ 500 ]
      - - Guid:            1002
          Counters:        [ 100 ]