63 lines · c
1// Tests for -fprofile-generate and -fprofile-use flag compatibility. These two2// flags behave similarly to their GCC counterparts:3//4// -fprofile-generate Generates the profile file ./default.profraw5// -fprofile-generate=<dir> Generates the profile file <dir>/default.profraw6// -fprofile-use Uses the profile file ./default.profdata7// -fprofile-use=<dir> Uses the profile file <dir>/default.profdata8// -fprofile-use=<dir>/file Uses the profile file <dir>/file9 10// On AIX, -flto used to be required with -fprofile-generate, so test those11// extra cases.12 13// RUN: %clang %s -c -S -o - -emit-llvm -target powerpc64-unknown-aix -flto -fprofile-generate | FileCheck -check-prefix=PROFILE-GEN %s14// PROFILE-GEN: @__profc_main = {{(private|internal)}} global [2 x i64] zeroinitializer, section15// PROFILE-GEN: @__profd_main =16 17// Check that -fprofile-generate=/path/to generates /path/to/default.profraw18// RxUN: %clang %s -c -S -o - -emit-llvm -target powerpc64-unknown-aix -flto -fprofile-generate=/path/to | FileCheck -check-prefixes=PROFILE-GEN,PROFILE-GEN-EQ %s19// PROFILE-GEN-EQ: constant [{{.*}} x i8] c"/path/to{{/|\\\\}}{{.*}}\00"20 21// Check that -fprofile-use=some/path reads some/path/default.profdata22// This uses Clang FE format profile.23// RUN: rm -rf %t.dir24// RUN: mkdir -p %t.dir/some/path25// RUN: llvm-profdata merge %S/Inputs/gcc-flag-compatibility.proftext -o %t.dir/some/path/default.profdata26// RUN: %clang %s -o - -Xclang -disable-llvm-passes -emit-llvm -S -fprofile-use=%t.dir/some/path | FileCheck -check-prefix=PROFILE-USE %s27 28// Check that -fprofile-use=some/path/file.prof reads some/path/file.prof29// This uses Clang FE format profile.30// RUN: rm -rf %t.dir31// RUN: mkdir -p %t.dir/some/path32// RUN: llvm-profdata merge %S/Inputs/gcc-flag-compatibility.proftext -o %t.dir/some/path/file.prof33// RUN: %clang %s -o - -Xclang -disable-llvm-passes -emit-llvm -S -fprofile-use=%t.dir/some/path/file.prof | FileCheck -check-prefix=PROFILE-USE %s34// PROFILE-USE: = !{!"branch_weights", i32 101, i32 2}35 36// Check that -fprofile-use=some/path reads some/path/default.profdata37// This uses LLVM IR format profile.38// RUN: rm -rf %t.dir39// RUN: mkdir -p %t.dir/some/path40// RUN: llvm-profdata merge %S/Inputs/gcc-flag-compatibility_IR.proftext -o %t.dir/some/path/default.profdata41// RUN: %clang %s -o - -emit-llvm -S -fprofile-use=%t.dir/some/path | FileCheck -check-prefix=PROFILE-USE-IR %s42 43// Check that -fprofile-use=some/path/file.prof reads some/path/file.prof44// This uses LLVM IR format profile.45// RUN: rm -rf %t.dir46// RUN: mkdir -p %t.dir/some/path47// RUN: llvm-profdata merge %S/Inputs/gcc-flag-compatibility_IR.proftext -o %t.dir/some/path/file.prof48// RUN: %clang %s -o - -emit-llvm -S -fprofile-use=%t.dir/some/path/file.prof | FileCheck -check-prefix=PROFILE-USE-IR %s49//50// RUN: llvm-profdata merge %S/Inputs/gcc-flag-compatibility_IR_entry.proftext -o %t.dir/some/path/file.prof51// RUN: %clang %s -o - -emit-llvm -S -fprofile-use=%t.dir/some/path/file.prof | FileCheck -check-prefix=PROFILE-USE-IR %s52 53// PROFILE-USE-IR: = !{!"branch_weights", i32 100, i32 1}54 55int X = 0;56 57int main(void) {58 int i;59 for (i = 0; i < 100; i++)60 X += i;61 return 0;62}63