Justin Bogner | 81c22c2 | 2014-01-23 02:54:27 +0000 | [diff] [blame^] | 1 | // Test that instrumentation based profiling feeds branch prediction |
| 2 | // correctly. This tests both generation of profile data and use of the same, |
| 3 | // and the input file for the -fprofile-instr-use case is expected to be result |
| 4 | // of running the program generated by the -fprofile-instr-generate case |
| 5 | // (excepting no_usable_data). As such, main() should call every function in |
| 6 | // this test. |
| 7 | |
| 8 | // RUN: %clang %s -o - -emit-llvm -S -fprofile-instr-generate -fno-exceptions -target %itanium_abi_triple > %tgen |
| 9 | // RUN: FileCheck --input-file=%tgen -check-prefix=CTRGEN %s |
| 10 | // RUN: FileCheck --input-file=%tgen -check-prefix=DTRGEN %s |
| 11 | // RUN: FileCheck --input-file=%tgen -check-prefix=MTHGEN %s |
| 12 | // RUN: FileCheck --input-file=%tgen -check-prefix=WRPGEN %s |
| 13 | |
| 14 | // RUN: %clang %s -o - -emit-llvm -S -fprofile-instr-use=%S/Inputs/instr-profile-class.pgodata -fno-exceptions -target %itanium_abi_triple > %tuse |
| 15 | // RUN: FileCheck --input-file=%tuse -check-prefix=CTRUSE %s |
| 16 | // RUN: FileCheck --input-file=%tuse -check-prefix=DTRUSE %s |
| 17 | // RUN: FileCheck --input-file=%tuse -check-prefix=MTHUSE %s |
| 18 | // RUN: FileCheck --input-file=%tuse -check-prefix=WRPUSE %s |
| 19 | |
| 20 | class Simple { |
| 21 | int Member; |
| 22 | public: |
| 23 | // CTRGEN-LABEL: define {{.*}} @_ZN6SimpleC2Ei( |
| 24 | // CTRUSE-LABEL: define {{.*}} @_ZN6SimpleC2Ei( |
| 25 | // CTRGEN: store {{.*}} @[[SCC:__llvm_pgo_ctr[0-9]*]], i64 0, i64 0 |
| 26 | explicit Simple(int Member) : Member(Member) { |
| 27 | // CTRGEN: store {{.*}} @[[SCC]], i64 0, i64 1 |
| 28 | // CTRUSE: br {{.*}} !prof ![[SC1:[0-9]+]] |
| 29 | if (Member) {} |
| 30 | // CTRGEN-NOT: store {{.*}} @[[SCC]], |
| 31 | // CTRUSE-NOT: br {{.*}} !prof ![0-9]+ |
| 32 | // CTRUSE: ret void |
| 33 | } |
| 34 | // CTRUSE: ![[SC1]] = metadata !{metadata !"branch_weights", i32 100, i32 2} |
| 35 | |
| 36 | // DTRGEN-LABEL: define {{.*}} @_ZN6SimpleD2Ev( |
| 37 | // DTRUSE-LABEL: define {{.*}} @_ZN6SimpleD2Ev( |
| 38 | // DTRGEN: store {{.*}} @[[SDC:__llvm_pgo_ctr[0-9]*]], i64 0, i64 0 |
| 39 | ~Simple() { |
| 40 | // DTRGEN: store {{.*}} @[[SDC]], i64 0, i64 1 |
| 41 | // DTRUSE: br {{.*}} !prof ![[SD1:[0-9]+]] |
| 42 | if (Member) {} |
| 43 | // DTRGEN-NOT: store {{.*}} @[[SDC]], |
| 44 | // DTRUSE-NOT: br {{.*}} !prof ![0-9]+ |
| 45 | // DTRUSE: ret void |
| 46 | } |
| 47 | // DTRUSE: ![[SD1]] = metadata !{metadata !"branch_weights", i32 100, i32 2} |
| 48 | |
| 49 | // MTHGEN-LABEL: define {{.*}} @_ZN6Simple6methodEv( |
| 50 | // MTHUSE-LABEL: define {{.*}} @_ZN6Simple6methodEv( |
| 51 | // MTHGEN: store {{.*}} @[[SMC:__llvm_pgo_ctr[0-9]*]], i64 0, i64 0 |
| 52 | void method() { |
| 53 | // MTHGEN: store {{.*}} @[[SMC]], i64 0, i64 1 |
| 54 | // MTHUSE: br {{.*}} !prof ![[SM1:[0-9]+]] |
| 55 | if (Member) {} |
| 56 | // MTHGEN-NOT: store {{.*}} @[[SMC]], |
| 57 | // MTHUSE-NOT: br {{.*}} !prof ![0-9]+ |
| 58 | // MTHUSE: ret void |
| 59 | } |
| 60 | // MTHUSE: ![[SM1]] = metadata !{metadata !"branch_weights", i32 100, i32 2} |
| 61 | }; |
| 62 | |
| 63 | // WRPGEN-LABEL: define {{.*}} @_Z14simple_wrapperv( |
| 64 | // WRPUSE-LABEL: define {{.*}} @_Z14simple_wrapperv( |
| 65 | // WRPGEN: store {{.*}} @[[SWC:__llvm_pgo_ctr[0-9]*]], i64 0, i64 0 |
| 66 | void simple_wrapper() { |
| 67 | // WRPGEN: store {{.*}} @[[SWC]], i64 0, i64 1 |
| 68 | // WRPUSE: br {{.*}} !prof ![[SW1:[0-9]+]] |
| 69 | for (int I = 0; I < 100; ++I) { |
| 70 | Simple S(I); |
| 71 | S.method(); |
| 72 | } |
| 73 | // WRPGEN-NOT: store {{.*}} @[[SWC]], |
| 74 | // WRPUSE-NOT: br {{.*}} !prof ![0-9]+ |
| 75 | // WRPUSE: ret void |
| 76 | } |
| 77 | // WRPUSE: ![[SW1]] = metadata !{metadata !"branch_weights", i32 100, i32 2} |
| 78 | |
| 79 | int main(int argc, const char *argv[]) { |
| 80 | simple_wrapper(); |
| 81 | return 0; |
| 82 | } |