blob: ce5651a250065584f354b216d603f47c018fc19e [file] [log] [blame]
Justin Bognerb1966292014-04-12 00:54:06 +00001// Tests for instrumentation of templated code. Each instantiation of a template
2// should be instrumented separately.
3
4// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-templates.cpp -std=c++11 -o - -emit-llvm -fprofile-instr-generate > %tgen
5// RUN: FileCheck --input-file=%tgen -check-prefix=T0GEN -check-prefix=ALL %s
6// RUN: FileCheck --input-file=%tgen -check-prefix=T100GEN -check-prefix=ALL %s
7
Justin Bogner534f14a2014-04-17 22:49:06 +00008// RUN: llvm-profdata merge %S/Inputs/cxx-templates.proftext -o %t.profdata
9// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-templates.cpp -std=c++11 -o - -emit-llvm -fprofile-instr-use=%t.profdata > %tuse
Justin Bognerb1966292014-04-12 00:54:06 +000010// RUN: FileCheck --input-file=%tuse -check-prefix=T0USE -check-prefix=ALL %s
11// RUN: FileCheck --input-file=%tuse -check-prefix=T100USE -check-prefix=ALL %s
12
Duncan P. N. Exon Smith91212202014-05-16 01:24:00 +000013// T0GEN: @[[T0C:__llvm_profile_counters__Z4loopILj0EEvv]] = linkonce_odr hidden global [2 x i64] zeroinitializer
14// T100GEN: @[[T100C:__llvm_profile_counters__Z4loopILj100EEvv]] = linkonce_odr hidden global [2 x i64] zeroinitializer
Justin Bognerb1966292014-04-12 00:54:06 +000015
16// T0GEN-LABEL: define linkonce_odr void @_Z4loopILj0EEvv()
17// T0USE-LABEL: define linkonce_odr void @_Z4loopILj0EEvv()
18// T100GEN-LABEL: define linkonce_odr void @_Z4loopILj100EEvv()
19// T100USE-LABEL: define linkonce_odr void @_Z4loopILj100EEvv()
20template <unsigned N> void loop() {
21 // ALL-NOT: ret
22 // T0GEN: store {{.*}} @[[T0C]], i64 0, i64 0
23 // T100GEN: store {{.*}} @[[T100C]], i64 0, i64 0
24
25 // ALL-NOT: ret
26 // T0GEN: store {{.*}} @[[T0C]], i64 0, i64 1
27 // T0USE: br {{.*}} !prof ![[T01:[0-9]+]]
28 // T100GEN: store {{.*}} @[[T100C]], i64 0, i64 1
29 // T100USE: br {{.*}} !prof ![[T1001:[0-9]+]]
30 for (unsigned I = 0; I < N; ++I) {}
31
32 // ALL: ret
33}
34
Duncan P. N. Exon Smithb3a66692014-12-15 19:10:08 +000035// T0USE-DAG: ![[T01]] = !{!"branch_weights", i32 1, i32 2}
36// T100USE-DAG: ![[T1001]] = !{!"branch_weights", i32 101, i32 2}
Justin Bognerb1966292014-04-12 00:54:06 +000037
38int main(int argc, const char *argv[]) {
39 loop<0>();
40 loop<100>();
41 return 0;
42}