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