c-attributes.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Test that instrumentation based profiling sets function attributes correctly.
  2. // RUN: llvm-profdata merge %S/Inputs/c-attributes.proftext -o %t.profdata
  3. // RUN: %clang %s -o - -mllvm -disable-llvm-optzns -emit-llvm -S -fprofile-instr-use=%t.profdata | FileCheck %s
  4. extern int atoi(const char *);
  5. // CHECK: hot_100_percent(i32{{.*}}%i) [[HOT:#[0-9]+]]
  6. void hot_100_percent(int i) {
  7. while (i > 0)
  8. i--;
  9. }
  10. // CHECK: hot_40_percent(i32{{.*}}%i) [[HOT]]
  11. void hot_40_percent(int i) {
  12. while (i > 0)
  13. i--;
  14. }
  15. // CHECK: normal_func(i32{{.*}}%i) [[NORMAL:#[0-9]+]]
  16. void normal_func(int i) {
  17. while (i > 0)
  18. i--;
  19. }
  20. // CHECK: cold_func(i32{{.*}}%i) [[COLD:#[0-9]+]]
  21. void cold_func(int i) {
  22. while (i > 0)
  23. i--;
  24. }
  25. // CHECK: attributes [[HOT]] = { inlinehint nounwind {{.*}} }
  26. // CHECK: attributes [[NORMAL]] = { nounwind {{.*}} }
  27. // CHECK: attributes [[COLD]] = { cold nounwind {{.*}} }
  28. int main(int argc, const char *argv[]) {
  29. int max = atoi(argv[1]);
  30. int i;
  31. for (i = 0; i < max; i++)
  32. hot_100_percent(i);
  33. for (i = 0; i < max * 4 / 10; i++)
  34. hot_40_percent(i);
  35. for (i = 0; i < max * 2 / 10; i++)
  36. normal_func(i);
  37. for (i = 0; i < max / 200; i++)
  38. cold_func(i);
  39. return 0;
  40. }