[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Frontend / optimization-remark-with-hotness-new-pm.c
blob173b43ba41bfedea0c2c53d30edcf0e5297ae76b
1 // This test is similar to Frontend/optimization-remark-with-hotness.c but
2 // testing the output under the new pass manager. The inliner is not added to
3 // the default new PM pipeline at O0, so we compile with optimizations here. As
4 // a result, some of the remarks will be different since we turn on inlining,
5 // but the test is meant to show that remarks get dumped. The remarks are also
6 // slightly different in text.
8 // Generate instrumentation and sampling profile data.
9 // RUN: llvm-profdata merge \
10 // RUN: %S/Inputs/optimization-remark-with-hotness.proftext \
11 // RUN: -o %t.profdata
12 // RUN: llvm-profdata merge -sample \
13 // RUN: %S/Inputs/optimization-remark-with-hotness-sample.proftext \
14 // RUN: -o %t-sample.profdata
16 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
17 // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \
18 // RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \
19 // RUN: -O1 \
20 // RUN: -Rpass-analysis=inline -Rpass-missed=inline \
21 // RUN: -fdiagnostics-show-hotness -verify
22 // The clang version of the previous test.
23 // RUN: %clang -target x86_64-apple-macosx10.9 %s -c -emit-llvm -o /dev/null \
24 // RUN: -fprofile-instr-use=%t.profdata -Rpass=inline \
25 // RUN: -O1 \
26 // RUN: -Rpass-analysis=inline -Rpass-missed=inline \
27 // RUN: -fdiagnostics-show-hotness -Xclang -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-sample-use=%t-sample.profdata -Rpass=inline \
31 // RUN: -O1 \
32 // RUN: -Rpass-analysis=inline -Rpass-missed=inline \
33 // RUN: -fdiagnostics-show-hotness -fdiagnostics-hotness-threshold=10 \
34 // RUN: -verify
35 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
36 // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \
37 // RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \
38 // RUN: -O1 \
39 // RUN: -Rpass-analysis=inline -Rpass-missed=inline \
40 // RUN: -fdiagnostics-show-hotness -fdiagnostics-hotness-threshold=10 -verify
41 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
42 // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \
43 // RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \
44 // RUN: -O1 \
45 // RUN: -Rpass-analysis=inline 2>&1 | FileCheck -check-prefix=HOTNESS_OFF %s
46 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
47 // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \
48 // RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \
49 // RUN: -O1 \
50 // RUN: -Rpass-analysis=inline -Rno-pass-with-hotness 2>&1 | FileCheck \
51 // RUN: -check-prefix=HOTNESS_OFF %s
52 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
53 // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \
54 // RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \
55 // RUN: -Rpass-analysis=inline -fdiagnostics-show-hotness \
56 // RUN: -fdiagnostics-hotness-threshold=100 2>&1 \
57 // RUN: | FileCheck -allow-empty -check-prefix=THRESHOLD %s
58 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
59 // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \
60 // RUN: -Rpass=inline -Rpass-analysis=inline \
61 // RUN: -fdiagnostics-show-hotness -fdiagnostics-hotness-threshold=10 2>&1 \
62 // RUN: | FileCheck -check-prefix=NO_PGO %s
64 int foo(int x, int y) __attribute__((always_inline));
65 int foo(int x, int y) { return x + y; }
67 int sum = 0;
69 void bar(int x) {
70 // HOTNESS_OFF: 'foo' inlined into 'bar'
71 // HOTNESS_OFF-NOT: hotness:
72 // THRESHOLD-NOT: inlined
73 // THRESHOLD-NOT: hotness
74 // NO_PGO: '-fdiagnostics-show-hotness' requires profile-guided optimization information
75 // NO_PGO: '-fdiagnostics-hotness-threshold=' requires profile-guided optimization information
76 // expected-remark@+1 {{'foo' inlined into 'bar' with (cost=always): always inline attribute at callsite bar:8:10; (hotness:}}
77 sum += foo(x, x - 2);
80 int main(int argc, const char *argv[]) {
81 for (int i = 0; i < 30; i++)
82 // expected-remark@+1 {{'bar' inlined into 'main' with}}
83 bar(argc);
84 return sum;