xref: /aosp_15_r20/external/clang/test/Frontend/optimization-remark.c (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // This file tests the -Rpass family of flags (-Rpass, -Rpass-missed
2*67e74705SXin Li // and -Rpass-analysis) with the inliner. The test is designed to
3*67e74705SXin Li // always trigger the inliner, so it should be independent of the
4*67e74705SXin Li // optimization level.
5*67e74705SXin Li 
6*67e74705SXin Li // RUN: %clang_cc1 %s -Rpass=inline -Rpass-analysis=inline -Rpass-missed=inline -O0 -emit-llvm-only -verify
7*67e74705SXin Li // RUN: %clang_cc1 %s -Rpass=inline -Rpass-analysis=inline -Rpass-missed=inline -O0 -emit-llvm-only -debug-info-kind=line-tables-only -verify
8*67e74705SXin Li // RUN: %clang_cc1 %s -Rpass=inline -emit-llvm -o - 2>/dev/null | FileCheck %s
9*67e74705SXin Li //
10*67e74705SXin Li // Check that we can override -Rpass= with -Rno-pass.
11*67e74705SXin Li // RUN: %clang_cc1 %s -Rpass=inline -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS
12*67e74705SXin Li // RUN: %clang_cc1 %s -Rpass=inline -Rno-pass -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-NO-REMARKS
13*67e74705SXin Li // RUN: %clang_cc1 %s -Rpass=inline -Rno-everything -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-NO-REMARKS
14*67e74705SXin Li // RUN: %clang_cc1 %s -Rpass=inline -Rno-everything -Reverything -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=CHECK-REMARKS
15*67e74705SXin Li //
16*67e74705SXin Li // FIXME: -Reverything should imply -Rpass=.*.
17*67e74705SXin Li // RUN: %clang_cc1 %s -Reverything -emit-llvm -o - 2>/dev/null | FileCheck %s --check-prefix=CHECK-NO-REMARKS
18*67e74705SXin Li //
19*67e74705SXin Li // FIXME: -Rpass should either imply -Rpass=.* or should be rejected.
20*67e74705SXin Li // RUN: %clang_cc1 %s -Rpass -emit-llvm -o - 2>/dev/null | FileCheck %s --check-prefix=CHECK-NO-REMARKS
21*67e74705SXin Li 
22*67e74705SXin Li // CHECK-REMARKS: remark:
23*67e74705SXin Li // CHECK-NO-REMARKS-NOT: remark:
24*67e74705SXin Li 
25*67e74705SXin Li // -Rpass should produce source location annotations, exclusively (just
26*67e74705SXin Li // like -gmlt).
27*67e74705SXin Li // CHECK: , !dbg !
28*67e74705SXin Li // CHECK-NOT: DW_TAG_base_type
29*67e74705SXin Li 
30*67e74705SXin Li // The CU should be marked NoDebug (to prevent writing debug info to
31*67e74705SXin Li // the final output).
32*67e74705SXin Li // CHECK: !llvm.dbg.cu = !{![[CU:.*]]}
33*67e74705SXin Li // CHECK: ![[CU]] = distinct !DICompileUnit({{.*}}emissionKind: NoDebug
34*67e74705SXin Li 
35*67e74705SXin Li int foo(int x, int y) __attribute__((always_inline));
foo(int x,int y)36*67e74705SXin Li int foo(int x, int y) { return x + y; }
37*67e74705SXin Li 
38*67e74705SXin Li float foz(int x, int y) __attribute__((noinline));
foz(int x,int y)39*67e74705SXin Li float foz(int x, int y) { return x * y; }
40*67e74705SXin Li 
41*67e74705SXin Li // The negative diagnostics are emitted twice because the inliner runs
42*67e74705SXin Li // twice.
43*67e74705SXin Li //
bar(int j)44*67e74705SXin Li int bar(int j) {
45*67e74705SXin Li // expected-remark@+6 {{foz should never be inlined (cost=never)}}
46*67e74705SXin Li // expected-remark@+5 {{foz will not be inlined into bar}}
47*67e74705SXin Li // expected-remark@+4 {{foz should never be inlined}}
48*67e74705SXin Li // expected-remark@+3 {{foz will not be inlined into bar}}
49*67e74705SXin Li // expected-remark@+2 {{foo should always be inlined}}
50*67e74705SXin Li // expected-remark@+1 {{foo inlined into bar}}
51*67e74705SXin Li   return foo(j, j - 2) * foz(j - 2, j);
52*67e74705SXin Li }
53