1 | // Tests for instrumentation of C++11 lambdas |
2 | |
3 | // RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-lambda.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument=clang > %tgen |
4 | // RUN: FileCheck -allow-deprecated-dag-overlap --input-file=%tgen -check-prefix=PGOGEN %s |
5 | // RUN: FileCheck -allow-deprecated-dag-overlap --input-file=%tgen -check-prefix=LMBGEN %s |
6 | |
7 | // RUN: llvm-profdata merge %S/Inputs/cxx-lambda.proftext -o %t.profdata |
8 | // RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-lambda.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata > %tuse |
9 | // RUN: FileCheck -allow-deprecated-dag-overlap --input-file=%tuse -check-prefix=PGOUSE %s |
10 | // RUN: FileCheck -allow-deprecated-dag-overlap --input-file=%tuse -check-prefix=LMBUSE %s |
11 | |
12 | // PGOGEN: @[[LWC:__profc__Z7lambdasv]] = {{(private|internal)}} global [4 x i64] zeroinitializer |
13 | // PGOGEN: @[[MAC:__profc_main]] = {{(private|internal)}} global [1 x i64] zeroinitializer |
14 | // LMBGEN: @[[LFC:"__profc_cxx_lambda.cpp__ZZ7lambdasvENK3\$_0clEi"]] = {{(private|internal)}} global [3 x i64] zeroinitializer |
15 | |
16 | // PGOGEN-LABEL: define {{.*}}void @_Z7lambdasv() |
17 | // PGOUSE-LABEL: define {{.*}}void @_Z7lambdasv() |
18 | // PGOGEN: store {{.*}} @[[LWC]], i64 0, i64 0 |
19 | void lambdas() { |
20 | int i = 1; |
21 | |
22 | // LMBGEN-LABEL: define internal{{( [0-9_a-z]*cc)?( zeroext)?}} i1 @"_ZZ7lambdasvENK3$_0clEi"( |
23 | // LMBUSE-LABEL: define internal{{( [0-9_a-z]*cc)?( zeroext)?}} i1 @"_ZZ7lambdasvENK3$_0clEi"( |
24 | // LMBGEN: store {{.*}} @[[LFC]], i64 0, i64 0 |
25 | auto f = [&i](int k) { |
26 | // LMBGEN: store {{.*}} @[[LFC]], i64 0, i64 1 |
27 | // LMBUSE: br {{.*}} !prof ![[LF1:[0-9]+]] |
28 | if (i > 0) {} |
29 | // LMBGEN: store {{.*}} @[[LFC]], i64 0, i64 2 |
30 | // LMBUSE: br {{.*}} !prof ![[LF2:[0-9]+]] |
31 | return k && i; |
32 | }; |
33 | |
34 | // PGOGEN: store {{.*}} @[[LWC]], i64 0, i64 1 |
35 | // PGOUSE: br {{.*}} !prof ![[LW1:[0-9]+]] |
36 | if (i) {} |
37 | |
38 | // PGOGEN: store {{.*}} @[[LWC]], i64 0, i64 2 |
39 | // PGOUSE: br {{.*}} !prof ![[LW2:[0-9]+]] |
40 | for (i = 0; i < 10; ++i) |
41 | f(9 - i); |
42 | |
43 | // PGOGEN: store {{.*}} @[[LWC]], i64 0, i64 3 |
44 | // PGOUSE: br {{.*}} !prof ![[LW3:[0-9]+]] |
45 | if (i) {} |
46 | } |
47 | |
48 | // PGOUSE-DAG: ![[LW1]] = !{!"branch_weights", i32 2, i32 1} |
49 | // PGOUSE-DAG: ![[LW2]] = !{!"branch_weights", i32 11, i32 2} |
50 | // PGOUSE-DAG: ![[LW3]] = !{!"branch_weights", i32 2, i32 1} |
51 | |
52 | // LMBUSE-DAG: ![[LF1]] = !{!"branch_weights", i32 10, i32 2} |
53 | // LMBUSE-DAG: ![[LF2]] = !{!"branch_weights", i32 10, i32 2} |
54 | |
55 | int main(int argc, const char *argv[]) { |
56 | lambdas(); |
57 | return 0; |
58 | } |
59 | |