brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 93c3c46 Raw
63 lines · c
1/*2RUN: rm -fr %t.profdir3RUN: %clang_profgen=%t.profdir/default_%m.profraw -o %t -O2 %s4RUN: %run %t  2>&1 | FileCheck %s --check-prefix=NO_EXIT_WRITE5RUN: llvm-profdata merge -o %t.profdata %t.profdir6RUN: %clang_profuse=%t.profdata -o - -S -emit-llvm %s | FileCheck %s  --check-prefix=PROF7 8NO_EXIT_WRITE: Profile data not written to file: already written9*/10 11int __llvm_profile_dump(void);12void __llvm_profile_reset_counters(void);13int foo(int);14int bar(int);15int skip(int);16 17int main(int argc, const char *argv[]) {18  int Ret = foo(0); /* region 1 */19  __llvm_profile_dump();20 21  /* not profiled -- cleared later. */22  skip(0);   /* skipped region */23  24  __llvm_profile_reset_counters();25  Ret += bar(0);  /* region 2 */26  __llvm_profile_dump();27 28  skip(1);29 30  __llvm_profile_reset_counters();31  /* foo's profile will be merged.  */32  foo(1);  /* region 3 */33  __llvm_profile_dump();34 35  return Ret;36}37 38__attribute__((noinline)) int foo(int X) {39  /* PROF: define {{.*}} @foo({{.*}}!prof ![[ENT:[0-9]+]]40     PROF: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD1:[0-9]+]]41  */42  return X <= 0 ? -X : X;43}44 45__attribute__((noinline)) int skip(int X) {46  /* PROF: define {{.*}} @skip(47     PROF: br i1 %{{.*}}, label %{{.*}}, label %{{[^,]+$}}48  */49  return X <= 0 ? -X : X;50}51 52__attribute__((noinline)) int bar(int X) {53  /* PROF-LABEL: define {{.*}} @bar(54     PROF: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof ![[PD2:[0-9]+]]55  */56  return X <= 0 ? -X : X;57}58 59/*60PROF: ![[ENT]] = !{!"function_entry_count", i64 2}  61PROF: ![[PD1]] = !{!"branch_weights", i32 2, i32 2}62*/63