45 lines · cpp
1// Tests for instrumentation of templated code. Each instantiation of a template2// 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-instrument=clang > %tgen5// RUN: FileCheck --input-file=%tgen -check-prefix=T0GEN -check-prefix=ALL %s6// RUN: FileCheck --input-file=%tgen -check-prefix=T100GEN -check-prefix=ALL %s7 8// RUN: llvm-profdata merge %S/Inputs/cxx-templates.proftext -o %t.profdata9// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-templates.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument-use=clang -fprofile-instrument-use-path=%t.profdata > %tuse10// RUN: FileCheck --input-file=%tuse -check-prefix=T0USE -check-prefix=ALL %s11// RUN: FileCheck --input-file=%tuse -check-prefix=T100USE -check-prefix=ALL %s12 13// The linkage can be target dependent, so accept all linkage here,14// the linkage tests for different target are in llvm/test/Instrumentation/InstrProfiling/profiling.ll15// T0GEN: @[[T0C:__profc__Z4loopILj0EEvv]] = {{.*}} global [2 x i64] zeroinitializer16// T100GEN: @[[T100C:__profc__Z4loopILj100EEvv]] = {{.*}} global [2 x i64] zeroinitializer17 18// T0GEN-LABEL: define linkonce_odr {{.*}}void @_Z4loopILj0EEvv()19// T0USE-LABEL: define linkonce_odr {{.*}}void @_Z4loopILj0EEvv()20// T100GEN-LABEL: define linkonce_odr {{.*}}void @_Z4loopILj100EEvv()21// T100USE-LABEL: define linkonce_odr {{.*}}void @_Z4loopILj100EEvv()22template <unsigned N> void loop() {23 // ALL-NOT: ret24 // T0GEN: store {{.*}} @[[T0C]]25 // T100GEN: store {{.*}} @[[T100C]]26 27 // ALL-NOT: ret28 // T0GEN: store {{.*}} @[[T0C]], i32 0, i32 129 // T0USE: br {{.*}} !prof ![[T01:[0-9]+]]30 // T100GEN: store {{.*}} @[[T100C]], i32 0, i32 131 // T100USE: br {{.*}} !prof ![[T1001:[0-9]+]]32 for (unsigned I = 0; I < N; ++I) {}33 34 // ALL: ret35}36 37// T0USE-DAG: ![[T01]] = !{!"branch_weights", i32 1, i32 2}38// T100USE-DAG: ![[T1001]] = !{!"branch_weights", i32 101, i32 2}39 40int main(int argc, const char *argv[]) {41 loop<0>();42 loop<100>();43 return 0;44}45