1 // Tests for -fprofile-generate and -fprofile-use flag compatibility. These two
2 // flags behave similarly to their GCC counterparts:
3 //
4 // -fprofile-generate         Generates the profile file ./default.profraw
5 // -fprofile-generate=<dir>   Generates the profile file <dir>/default.profraw
6 // -fprofile-use              Uses the profile file ./default.profdata
7 // -fprofile-use=<dir>        Uses the profile file <dir>/default.profdata
8 // -fprofile-use=<dir>/file   Uses the profile file <dir>/file
9 
10 // Check that -fprofile-generate uses the runtime default profile file.
11 // RUN: %clang %s -c -S -o - -emit-llvm -fprofile-generate | FileCheck -check-prefix=PROFILE-GEN %s
12 // PROFILE-GEN-NOT: call void @__llvm_profile_override_default_filename
13 // PROFILE-GEN-NOT: declare void @__llvm_profile_override_default_filename(i8*)
14 
15 // Check that -fprofile-generate=/path/to generates /path/to/default.profraw
16 // RUN: %clang %s -c -S -o - -emit-llvm -fprofile-generate=/path/to | FileCheck -check-prefix=PROFILE-GEN-EQ %s
17 // PROFILE-GEN-EQ: private constant [25 x i8] c"/path/to{{/|\\5C}}default.profraw\00"
18 // PROFILE-GEN-EQ: call void @__llvm_profile_override_default_filename(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @0, i32 0, i32 0))
19 // PROFILE-GEN-EQ: declare void @__llvm_profile_override_default_filename(i8*)
20 
21 // Check that -fprofile-use=some/path reads some/path/default.profdata
22 // RUN: rm -rf %t.dir
23 // RUN: mkdir -p %t.dir/some/path
24 // RUN: llvm-profdata merge %S/Inputs/gcc-flag-compatibility.proftext -o %t.dir/some/path/default.profdata
25 // RUN: %clang %s -o - -mllvm -disable-llvm-optzns -emit-llvm -S -fprofile-use=%t.dir/some/path | FileCheck -check-prefix=PROFILE-USE-2 %s
26 // PROFILE-USE-2: = !{!"branch_weights", i32 101, i32 2}
27 
28 // Check that -fprofile-use=some/path/file.prof reads some/path/file.prof
29 // RUN: rm -rf %t.dir
30 // RUN: mkdir -p %t.dir/some/path
31 // RUN: llvm-profdata merge %S/Inputs/gcc-flag-compatibility.proftext -o %t.dir/some/path/file.prof
32 // RUN: %clang %s -o - -mllvm -disable-llvm-optzns -emit-llvm -S -fprofile-use=%t.dir/some/path/file.prof | FileCheck -check-prefix=PROFILE-USE-3 %s
33 // PROFILE-USE-3: = !{!"branch_weights", i32 101, i32 2}
34 
35 int X = 0;
36 
main()37 int main() {
38   int i;
39   for (i = 0; i < 100; i++)
40     X += i;
41   return 0;
42 }
43