1 // This file tests the -Rpass family of flags (-Rpass, -Rpass-missed
2 // and -Rpass-analysis) with the inliner. The test is designed to
3 // always trigger the inliner, so it should be independent of the
4 // optimization level (under the legacy PM). The inliner is not added to the new
5 // PM pipeline unless optimizations are present.
6
7 // The inliner for the new PM does not seem to be enabled at O0, but we still
8 // get the same remarks with at least O1. The remarks are also slightly
9 // different and located in another test file.
10 // RUN: %clang_cc1 %s -Rpass=inline -Rpass-analysis=inline -Rpass-missed=inline -O0 -fno-experimental-new-pass-manager -emit-llvm-only -verify -mllvm -mandatory-inlining-first=0
11 // RUN: %clang_cc1 %s -Rpass=inline -Rpass-analysis=inline -Rpass-missed=inline -O0 -fno-experimental-new-pass-manager -emit-llvm-only -debug-info-kind=line-tables-only -verify -mllvm -mandatory-inlining-first=0
12 // RUN: %clang_cc1 %s -Rpass=inline -emit-llvm -o - -mllvm -mandatory-inlining-first=0 2>/dev/null | FileCheck %s
13 //
14 // Check that we can override -Rpass= with -Rno-pass.
15 // RUN: %clang_cc1 %s -Rpass=inline -fno-experimental-new-pass-manager -emit-llvm -o - -mllvm -mandatory-inlining-first=0 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS
16 // RUN: %clang_cc1 %s -Rpass=inline -Rno-pass -emit-llvm -o - -mllvm -mandatory-inlining-first=0 2>&1 | FileCheck %s --check-prefix=CHECK-NO-REMARKS
17 // RUN: %clang_cc1 %s -Rpass=inline -Rno-everything -emit-llvm -o - -mllvm -mandatory-inlining-first=0 2>&1 | FileCheck %s --check-prefix=CHECK-NO-REMARKS
18 // RUN: %clang_cc1 %s -Rpass=inline -fno-experimental-new-pass-manager -Rno-everything -Reverything -emit-llvm -o - -mllvm -mandatory-inlining-first=0 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS
19 //
20 // The inliner for the new PM does not seem to be enabled at O0, but we still
21 // get the same remarks with at least O1.
22 // RUN: %clang_cc1 %s -Rpass=inline -fexperimental-new-pass-manager -O1 -emit-llvm -o - -mllvm -mandatory-inlining-first=0 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS
23 // RUN: %clang_cc1 %s -Rpass=inline -fexperimental-new-pass-manager -O1 -Rno-everything -Reverything -emit-llvm -o - -mllvm -mandatory-inlining-first=0 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS
24 //
25 // Check that -w doesn't disable remarks.
26 // RUN: %clang_cc1 %s -Rpass=inline -fno-experimental-new-pass-manager -w -emit-llvm -o - -mllvm -mandatory-inlining-first=0 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS
27 // RUN: %clang_cc1 %s -Rpass=inline -fexperimental-new-pass-manager -O1 -w -emit-llvm -o - -mllvm -mandatory-inlining-first=0 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS
28 //
29 // FIXME: -Reverything should imply -Rpass=.*.
30 // RUN: %clang_cc1 %s -Reverything -emit-llvm -o - -mllvm -mandatory-inlining-first=0 2>/dev/null | FileCheck %s --check-prefix=CHECK-NO-REMARKS
31 //
32 // FIXME: -Rpass should either imply -Rpass=.* or should be rejected.
33 // RUN: %clang_cc1 %s -Rpass -emit-llvm -o - -mllvm -mandatory-inlining-first=0 2>/dev/null | FileCheck %s --check-prefix=CHECK-NO-REMARKS
34
35 // CHECK-REMARKS: remark:
36 // CHECK-NO-REMARKS-NOT: remark:
37
38 // -Rpass should produce source location annotations, exclusively (just
39 // like -gmlt).
40 // CHECK: , !dbg !
41 // CHECK-NOT: DW_TAG_base_type
42
43 // The CU should be marked NoDebug (to prevent writing debug info to
44 // the final output).
45 // CHECK: !llvm.dbg.cu = !{![[CU:.*]]}
46 // CHECK: ![[CU]] = distinct !DICompileUnit({{.*}}emissionKind: NoDebug
47
48 int foo(int x, int y) __attribute__((always_inline));
foo(int x,int y)49 int foo(int x, int y) { return x + y; }
50
51 float foz(int x, int y) __attribute__((noinline));
foz(int x,int y)52 float foz(int x, int y) { return x * y; }
53
54 // The negative diagnostics are emitted twice because the inliner runs
55 // twice.
56 //
bar(int j)57 int bar(int j) {
58 // expected-remark@+3 {{foz not inlined into bar because it should never be inlined (cost=never)}}
59 // expected-remark@+2 {{foz not inlined into bar because it should never be inlined (cost=never)}}
60 // expected-remark@+1 {{foo inlined into bar}}
61 return foo(j, j - 2) * foz(j - 2, j);
62 }
63