2014-04-12 08:54:06 +08:00
|
|
|
// Tests for instrumentation of templated code. Each instantiation of a template
|
|
|
|
// should be instrumented separately.
|
|
|
|
|
2022-04-07 18:03:55 +08:00
|
|
|
// RUN: %clang_cc1 -no-opaque-pointers -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-templates.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument=clang > %tgen
|
2014-04-12 08:54:06 +08:00
|
|
|
// RUN: FileCheck --input-file=%tgen -check-prefix=T0GEN -check-prefix=ALL %s
|
|
|
|
// RUN: FileCheck --input-file=%tgen -check-prefix=T100GEN -check-prefix=ALL %s
|
|
|
|
|
2014-04-18 06:49:06 +08:00
|
|
|
// RUN: llvm-profdata merge %S/Inputs/cxx-templates.proftext -o %t.profdata
|
2022-04-07 18:03:55 +08:00
|
|
|
// RUN: %clang_cc1 -no-opaque-pointers -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-templates.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata > %tuse
|
2014-04-12 08:54:06 +08:00
|
|
|
// RUN: FileCheck --input-file=%tuse -check-prefix=T0USE -check-prefix=ALL %s
|
|
|
|
// RUN: FileCheck --input-file=%tuse -check-prefix=T100USE -check-prefix=ALL %s
|
|
|
|
|
[AIX] Change the linkage of profiling counter/data to be private
We generate symbols like `profc`/`profd` for each function, and put them into csects.
When there are weak functions, we generate weak symbols for the functions as well,
with ELF (and some others), linker (binder) will discard and only keep one copy of the weak symbols.
However, on AIX, the current binder can NOT discard the weak symbols if we put all of them into the same csect,
as binder can NOT discard a subset of a csect.
This creates a unique challenge for using those symbols to calculate some relative offsets.
This patch changed the linkage of `profc`/`profd` symbols to be private, so that all the profc/profd for each weak symbol will be *local* to objects, and all kept in the csect, so we won't have problem. Although only one of the counters will be used, all the pointer in the profd is correct.
The downside is that we won't be able to discard the duplicated counters and profile data,
but those can not be discarded even if we keep the weak linkage,
due to the binder limitation of not discarding a subsect of the csect either .
Reviewed By: Whitney, MaskRay
Differential Revision: https://reviews.llvm.org/D110422
2021-09-29 06:28:13 +08:00
|
|
|
// The linkage can be target dependent, so accept all linkage here,
|
|
|
|
// the linkage tests for different target are in llvm/test/Instrumentation/InstrProfiling/profiling.ll
|
|
|
|
// T0GEN: @[[T0C:__profc__Z4loopILj0EEvv]] = {{.*}} global [2 x i64] zeroinitializer
|
|
|
|
// T100GEN: @[[T100C:__profc__Z4loopILj100EEvv]] = {{.*}} global [2 x i64] zeroinitializer
|
2014-04-12 08:54:06 +08:00
|
|
|
|
2015-06-30 01:29:50 +08:00
|
|
|
// T0GEN-LABEL: define linkonce_odr {{.*}}void @_Z4loopILj0EEvv()
|
|
|
|
// T0USE-LABEL: define linkonce_odr {{.*}}void @_Z4loopILj0EEvv()
|
|
|
|
// T100GEN-LABEL: define linkonce_odr {{.*}}void @_Z4loopILj100EEvv()
|
|
|
|
// T100USE-LABEL: define linkonce_odr {{.*}}void @_Z4loopILj100EEvv()
|
2014-04-12 08:54:06 +08:00
|
|
|
template <unsigned N> void loop() {
|
|
|
|
// ALL-NOT: ret
|
2021-11-20 07:44:48 +08:00
|
|
|
// T0GEN: store {{.*}} @[[T0C]], i32 0, i32 0
|
|
|
|
// T100GEN: store {{.*}} @[[T100C]], i32 0, i32 0
|
2014-04-12 08:54:06 +08:00
|
|
|
|
|
|
|
// ALL-NOT: ret
|
2021-11-20 07:44:48 +08:00
|
|
|
// T0GEN: store {{.*}} @[[T0C]], i32 0, i32 1
|
2014-04-12 08:54:06 +08:00
|
|
|
// T0USE: br {{.*}} !prof ![[T01:[0-9]+]]
|
2021-11-20 07:44:48 +08:00
|
|
|
// T100GEN: store {{.*}} @[[T100C]], i32 0, i32 1
|
2014-04-12 08:54:06 +08:00
|
|
|
// T100USE: br {{.*}} !prof ![[T1001:[0-9]+]]
|
|
|
|
for (unsigned I = 0; I < N; ++I) {}
|
|
|
|
|
|
|
|
// ALL: ret
|
|
|
|
}
|
|
|
|
|
2020-10-31 15:15:46 +08:00
|
|
|
// T0USE-DAG: ![[T01]] = !{!"branch_weights", i32 1, i32 2}
|
|
|
|
// T100USE-DAG: ![[T1001]] = !{!"branch_weights", i32 101, i32 2}
|
2014-04-12 08:54:06 +08:00
|
|
|
|
|
|
|
int main(int argc, const char *argv[]) {
|
|
|
|
loop<0>();
|
|
|
|
loop<100>();
|
|
|
|
return 0;
|
|
|
|
}
|