optimization-remark-with-hotness.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. int foo(int x, int y) __attribute__((always_inline));
  57. int foo(int x, int y) { return x + y; }
  58. int sum = 0;
  59. void bar(int x) {
  60. // HOTNESS_OFF: foo inlined into bar
  61. // HOTNESS_OFF-NOT: hotness:
  62. // THRESHOLD-NOT: inlined
  63. // THRESHOLD-NOT: hotness
  64. // NO_PGO: '-fdiagnostics-show-hotness' requires profile-guided optimization information
  65. // NO_PGO: '-fdiagnostics-hotness-threshold=' requires profile-guided optimization information
  66. // expected-remark@+1 {{foo inlined into bar with (cost=always): always inliner (hotness:}}
  67. sum += foo(x, x - 2);
  68. }
  69. int main(int argc, const char *argv[]) {
  70. for (int i = 0; i < 30; i++)
  71. // expected-remark@+1 {{bar not inlined into main because it should never be inlined (cost=never): no alwaysinline attribute (hotness:}}
  72. bar(argc);
  73. return sum;
  74. }