153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)// Tests for instrumentation of templated code. Each instantiation of a template
253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)// should be instrumented separately.
353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)// 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
553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)// RUN: FileCheck --input-file=%tgen -check-prefix=T0GEN -check-prefix=ALL %s
653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)// RUN: FileCheck --input-file=%tgen -check-prefix=T100GEN -check-prefix=ALL %s
753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)// RUN: llvm-profdata merge %S/Inputs/cxx-templates.proftext -o %t.profdata
953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)// 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
1053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)// RUN: FileCheck --input-file=%tuse -check-prefix=T0USE -check-prefix=ALL %s
1153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)// RUN: FileCheck --input-file=%tuse -check-prefix=T100USE -check-prefix=ALL %s
1253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
1353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)// T0GEN: @[[T0C:__llvm_profile_counters__Z4loopILj0EEvv]] = linkonce_odr hidden global [2 x i64] zeroinitializer
1453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)// T100GEN: @[[T100C:__llvm_profile_counters__Z4loopILj100EEvv]] = linkonce_odr hidden global [2 x i64] zeroinitializer
1553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
1653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)// T0GEN-LABEL: define linkonce_odr void @_Z4loopILj0EEvv()
1753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)// T0USE-LABEL: define linkonce_odr void @_Z4loopILj0EEvv()
1853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)// T100GEN-LABEL: define linkonce_odr void @_Z4loopILj100EEvv()
1953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)// T100USE-LABEL: define linkonce_odr void @_Z4loopILj100EEvv()
2053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)template <unsigned N> void loop() {
2153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)  // ALL-NOT: ret
2253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)  // T0GEN: store {{.*}} @[[T0C]], i64 0, i64 0
2353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)  // T100GEN: store {{.*}} @[[T100C]], i64 0, i64 0
2453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
2553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)  // ALL-NOT: ret
2602772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch  // T0GEN: store {{.*}} @[[T0C]], i64 0, i64 1
2753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)  // T0USE: br {{.*}} !prof ![[T01:[0-9]+]]
2853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)  // T100GEN: store {{.*}} @[[T100C]], i64 0, i64 1
2953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)  // T100USE: br {{.*}} !prof ![[T1001:[0-9]+]]
30197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch  for (unsigned I = 0; I < N; ++I) {}
3153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
32197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch  // ALL: ret
33197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch}
34197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
35197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch// T0USE-DAG: ![[T01]] = metadata !{metadata !"branch_weights", i32 1, i32 2}
3653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)// T100USE-DAG: ![[T1001]] = metadata !{metadata !"branch_weights", i32 101, i32 2}
37c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)
3853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)int main(int argc, const char *argv[]) {
39a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)  loop<0>();
4053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)  loop<100>();
4193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)  return 0;
4293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)}
43f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)