1 // Generate instrumentation and sampling profile data.
2 // RUN: llvm-profdata merge \
3 // RUN: %S/Inputs/optimization-remark-with-hotness.proftext \
4 // RUN: -o %t.profdata
5 // RUN: llvm-profdata merge -sample \
6 // RUN: %S/Inputs/optimization-remark-with-hotness-sample.proftext \
7 // RUN: -o %t-sample.profdata
8 //
9 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
10 // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \
11 // RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \
12 // RUN: -fno-experimental-new-pass-manager \
13 // RUN: -Rpass-analysis=inline -Rpass-missed=inline \
14 // RUN: -fdiagnostics-show-hotness -verify
15 // The clang version of the previous test.
16 // RUN: %clang -target x86_64-apple-macosx10.9 %s -c -emit-llvm -o /dev/null \
17 // RUN: -fprofile-instr-use=%t.profdata -Rpass=inline \
18 // RUN: -fno-experimental-new-pass-manager \
19 // RUN: -Rpass-analysis=inline -Rpass-missed=inline \
20 // RUN: -fdiagnostics-show-hotness -Xclang -verify
21 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
22 // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \
23 // RUN: -fprofile-sample-use=%t-sample.profdata -Rpass=inline \
24 // RUN: -fno-experimental-new-pass-manager \
25 // RUN: -Rpass-analysis=inline -Rpass-missed=inline \
26 // RUN: -fdiagnostics-show-hotness -fdiagnostics-hotness-threshold=10 \
27 // RUN: -verify
28 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
29 // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \
30 // RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \
31 // RUN: -fno-experimental-new-pass-manager \
32 // RUN: -Rpass-analysis=inline -Rpass-missed=inline \
33 // RUN: -fdiagnostics-show-hotness -fdiagnostics-hotness-threshold=10 -verify
34 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
35 // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \
36 // RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \
37 // RUN: -fno-experimental-new-pass-manager \
38 // RUN: -Rpass-analysis=inline 2>&1 | FileCheck -check-prefix=HOTNESS_OFF %s
39 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
40 // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \
41 // RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \
42 // RUN: -fno-experimental-new-pass-manager \
43 // RUN: -Rpass-analysis=inline -Rno-pass-with-hotness 2>&1 | FileCheck \
44 // RUN: -check-prefix=HOTNESS_OFF %s
45 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
46 // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \
47 // RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \
48 // RUN: -Rpass-analysis=inline -fdiagnostics-show-hotness \
49 // RUN: -fdiagnostics-hotness-threshold=100 2>&1 \
50 // RUN: | FileCheck -allow-empty -check-prefix=THRESHOLD %s
51 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
52 // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \
53 // RUN: -Rpass=inline -Rpass-analysis=inline \
54 // RUN: -fdiagnostics-show-hotness -fdiagnostics-hotness-threshold=10 2>&1 \
55 // RUN: | FileCheck -check-prefix=NO_PGO %s
56
57 int foo(int x, int y) __attribute__((always_inline));
foo(int x,int y)58 int foo(int x, int y) { return x + y; }
59
60 int sum = 0;
61
bar(int x)62 void bar(int x) {
63 // HOTNESS_OFF: foo inlined into bar
64 // HOTNESS_OFF-NOT: hotness:
65 // THRESHOLD-NOT: inlined
66 // THRESHOLD-NOT: hotness
67 // NO_PGO: '-fdiagnostics-show-hotness' requires profile-guided optimization information
68 // NO_PGO: '-fdiagnostics-hotness-threshold=' requires profile-guided optimization information
69 // expected-remark@+1 {{foo inlined into bar with (cost=always): always inliner at callsite bar:8:10; (hotness:}}
70 sum += foo(x, x - 2);
71 }
72
main(int argc,const char * argv[])73 int main(int argc, const char *argv[]) {
74 for (int i = 0; i < 30; i++)
75 // expected-remark@+1 {{bar not inlined into main because it should never be inlined (cost=never): no alwaysinline attribute (hotness:}}
76 bar(argc);
77 return sum;
78 }
79