optimization-remark.c 3.5 KB

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