c-captured.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-captured.c %s -o - -emit-llvm -fprofile-instr-generate | FileCheck -check-prefix=PGOGEN -check-prefix=PGOALL %s
  2. // RUN: llvm-profdata merge %S/Inputs/c-captured.proftext -o %t.profdata
  3. // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-captured.c %s -o - -emit-llvm -fprofile-instr-use=%t.profdata | FileCheck -check-prefix=PGOUSE -check-prefix=PGOALL %s
  4. // PGOGEN: @[[DCC:__llvm_profile_counters_debug_captured]] = private global [3 x i64] zeroinitializer
  5. // PGOGEN: @[[CSC:"__llvm_profile_counters_c-captured.c:__captured_stmt"]] = private global [2 x i64] zeroinitializer
  6. // PGOGEN: @[[C1C:"__llvm_profile_counters_c-captured.c:__captured_stmt.1"]] = private global [3 x i64] zeroinitializer
  7. // PGOALL-LABEL: define void @debug_captured()
  8. // PGOGEN: store {{.*}} @[[DCC]], i64 0, i64 0
  9. void debug_captured() {
  10. int x = 10;
  11. // Check both debug_captured counters, so we can do this all in one pass
  12. // PGOGEN: store {{.*}} @[[DCC]], i64 0, i64 1
  13. // PGOUSE: br {{.*}} !prof ![[DC1:[0-9]+]]
  14. // PGOGEN: store {{.*}} @[[DCC]], i64 0, i64 2
  15. // PGOUSE: br {{.*}} !prof ![[DC2:[0-9]+]]
  16. // PGOALL: ret
  17. // PGOALL-LABEL: define internal void @__captured_stmt(
  18. // PGOGEN: store {{.*}} @[[CSC]], i64 0, i64 0
  19. #pragma clang __debug captured
  20. {
  21. // PGOGEN: store {{.*}} @[[CSC]], i64 0, i64 1
  22. // PGOUSE: br {{.*}} !prof ![[CS1:[0-9]+]]
  23. if (x) {}
  24. // PGOALL: ret
  25. }
  26. if (x) {} // This is DC1. Checked above.
  27. // PGOALL-LABEL: define internal void @__captured_stmt.1(
  28. // PGOGEN: store {{.*}} @[[C1C]], i64 0, i64 0
  29. #pragma clang __debug captured
  30. {
  31. // PGOGEN: store {{.*}} @[[C1C]], i64 0, i64 1
  32. // PGOUSE: br {{.*}} !prof ![[C11:[0-9]+]]
  33. for (int i = 0; i < x; ++i) {}
  34. // PGOGEN: store {{.*}} @[[C1C]], i64 0, i64 2
  35. // PGOUSE: br {{.*}} !prof ![[C12:[0-9]+]]
  36. if (x) {}
  37. // PGOALL: ret
  38. }
  39. if (x) {} // This is DC2. Checked above.
  40. }
  41. // PGOUSE-DAG: ![[DC1]] = !{!"branch_weights", i32 2, i32 1}
  42. // PGOUSE-DAG: ![[DC2]] = !{!"branch_weights", i32 2, i32 1}
  43. // PGOUSE-DAG: ![[CS1]] = !{!"branch_weights", i32 2, i32 1}
  44. // PGOUSE-DAG: ![[C11]] = !{!"branch_weights", i32 11, i32 2}
  45. // PGOUSE-DAG: ![[C12]] = !{!"branch_weights", i32 2, i32 1}
  46. int main(int argc, const char *argv[]) {
  47. debug_captured();
  48. return 0;
  49. }