cxx-templates.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Tests for instrumentation of templated code. Each instantiation of a template
  2. // should be instrumented separately.
  3. // 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
  4. // RUN: FileCheck --input-file=%tgen -check-prefix=T0GEN -check-prefix=ALL %s
  5. // RUN: FileCheck --input-file=%tgen -check-prefix=T100GEN -check-prefix=ALL %s
  6. // RUN: llvm-profdata merge %S/Inputs/cxx-templates.proftext -o %t.profdata
  7. // 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
  8. // RUN: FileCheck --input-file=%tuse -check-prefix=T0USE -check-prefix=ALL %s
  9. // RUN: FileCheck --input-file=%tuse -check-prefix=T100USE -check-prefix=ALL %s
  10. // T0GEN: @[[T0C:__llvm_profile_counters__Z4loopILj0EEvv]] = linkonce_odr hidden global [2 x i64] zeroinitializer
  11. // T100GEN: @[[T100C:__llvm_profile_counters__Z4loopILj100EEvv]] = linkonce_odr hidden global [2 x i64] zeroinitializer
  12. // T0GEN-LABEL: define linkonce_odr {{.*}}void @_Z4loopILj0EEvv()
  13. // T0USE-LABEL: define linkonce_odr {{.*}}void @_Z4loopILj0EEvv()
  14. // T100GEN-LABEL: define linkonce_odr {{.*}}void @_Z4loopILj100EEvv()
  15. // T100USE-LABEL: define linkonce_odr {{.*}}void @_Z4loopILj100EEvv()
  16. template <unsigned N> void loop() {
  17. // ALL-NOT: ret
  18. // T0GEN: store {{.*}} @[[T0C]], i64 0, i64 0
  19. // T100GEN: store {{.*}} @[[T100C]], i64 0, i64 0
  20. // ALL-NOT: ret
  21. // T0GEN: store {{.*}} @[[T0C]], i64 0, i64 1
  22. // T0USE: br {{.*}} !prof ![[T01:[0-9]+]]
  23. // T100GEN: store {{.*}} @[[T100C]], i64 0, i64 1
  24. // T100USE: br {{.*}} !prof ![[T1001:[0-9]+]]
  25. for (unsigned I = 0; I < N; ++I) {}
  26. // ALL: ret
  27. }
  28. // T0USE-DAG: ![[T01]] = !{!"branch_weights", i32 1, i32 2}
  29. // T100USE-DAG: ![[T1001]] = !{!"branch_weights", i32 101, i32 2}
  30. int main(int argc, const char *argv[]) {
  31. loop<0>();
  32. loop<100>();
  33. return 0;
  34. }