instrprof-value-prof-2.c
5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// RUN: %clang_profgen -O2 -o %t %s
// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
// RUN: llvm-profdata merge -o %t.profdata %t.profraw
// RUN: llvm-profdata show --all-functions -ic-targets %t.profdata > %t.out
// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-1 < %t.out
// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-2 < %t.out
// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-3 < %t.out
// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-4 < %t.out
// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-5 < %t.out
// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-6 < %t.out
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct __llvm_profile_data __llvm_profile_data;
const __llvm_profile_data *__llvm_profile_begin_data(void);
const __llvm_profile_data *__llvm_profile_end_data(void);
void __llvm_profile_set_num_value_sites(__llvm_profile_data *Data,
uint32_t ValueKind,
uint16_t NumValueSites);
__llvm_profile_data *
__llvm_profile_iterate_data(const __llvm_profile_data *Data);
void *__llvm_get_function_addr(const __llvm_profile_data *Data);
void __llvm_profile_instrument_target(uint64_t TargetValue, void *Data,
uint32_t CounterIndex);
void callee1() {}
void callee2() {}
void caller_without_value_site1() {}
void caller_with_value_site_never_called1() {}
void caller_with_vp1() {}
void caller_with_value_site_never_called2() {}
void caller_without_value_site2() {}
void caller_with_vp2() {}
void (*callee1Ptr)();
void (*callee2Ptr)();
void __attribute__ ((noinline)) setFunctionPointers () {
callee1Ptr = callee1;
callee2Ptr = callee2;
}
int main(int argc, const char *argv[]) {
unsigned S, NS = 10, V;
const __llvm_profile_data *Data, *DataEnd;
setFunctionPointers();
Data = __llvm_profile_begin_data();
DataEnd = __llvm_profile_end_data();
for (; Data < DataEnd; Data = __llvm_profile_iterate_data(Data)) {
void *func = __llvm_get_function_addr(Data);
if (func == caller_without_value_site1 ||
func == caller_without_value_site2 ||
func == callee1 || func == callee2 || func == main)
continue;
__llvm_profile_set_num_value_sites((__llvm_profile_data *)Data,
0 /*IPVK_IndirectCallTarget */, 10);
if (func == caller_with_value_site_never_called1 ||
func == caller_with_value_site_never_called2)
continue;
for (S = 0; S < NS; S++) {
unsigned C;
for (C = 0; C < S + 1; C++) {
__llvm_profile_instrument_target((uint64_t)callee1Ptr, (void *)Data, S);
if (C % 2 == 0)
__llvm_profile_instrument_target((uint64_t)callee2Ptr, (void *)Data, S);
}
}
}
}
// CHECK-1-LABEL: caller_with_value_site_never_called2:
// CHECK-1-NEXT: Hash: 0x0000000000000000
// CHECK-1-NEXT: Counters:
// CHECK-1-NEXT: Function count
// CHECK-1-NEXT: Indirect Call Site Count: 10
// CHECK-1-NEXT: Indirect Target Results:
// CHECK-2-LABEL: caller_with_vp2:
// CHECK-2-NEXT: Hash: 0x0000000000000000
// CHECK-2-NEXT: Counters:
// CHECK-2-NEXT: Function count:
// CHECK-2-NEXT: Indirect Call Site Count: 10
// CHECK-2-NEXT: Indirect Target Results:
// CHECK-2-NEXT: [ 0, callee1, 1 ]
// CHECK-2-NEXT: [ 0, callee2, 1 ]
// CHECK-2-NEXT: [ 1, callee1, 2 ]
// CHECK-2-NEXT: [ 1, callee2, 1 ]
// CHECK-2-NEXT: [ 2, callee1, 3 ]
// CHECK-2-NEXT: [ 2, callee2, 2 ]
// CHECK-2-NEXT: [ 3, callee1, 4 ]
// CHECK-2-NEXT: [ 3, callee2, 2 ]
// CHECK-2-NEXT: [ 4, callee1, 5 ]
// CHECK-2-NEXT: [ 4, callee2, 3 ]
// CHECK-2-NEXT: [ 5, callee1, 6 ]
// CHECK-2-NEXT: [ 5, callee2, 3 ]
// CHECK-2-NEXT: [ 6, callee1, 7 ]
// CHECK-2-NEXT: [ 6, callee2, 4 ]
// CHECK-2-NEXT: [ 7, callee1, 8 ]
// CHECK-2-NEXT: [ 7, callee2, 4 ]
// CHECK-2-NEXT: [ 8, callee1, 9 ]
// CHECK-2-NEXT: [ 8, callee2, 5 ]
// CHECK-2-NEXT: [ 9, callee1, 10 ]
// CHECK-2-NEXT: [ 9, callee2, 5 ]
// CHECK-3-LABEL: caller_with_vp1:
// CHECK-3-NEXT: Hash: 0x0000000000000000
// CHECK-3-NEXT: Counters:
// CHECK-3-NEXT: Function count
// CHECK-3-NEXT: Indirect Call Site Count: 10
// CHECK-3-NEXT: Indirect Target Results:
// CHECK-3-NEXT: [ 0, callee1, 1 ]
// CHECK-3-NEXT: [ 0, callee2, 1 ]
// CHECK-3-NEXT: [ 1, callee1, 2 ]
// CHECK-3-NEXT: [ 1, callee2, 1 ]
// CHECK-3-NEXT: [ 2, callee1, 3 ]
// CHECK-3-NEXT: [ 2, callee2, 2 ]
// CHECK-3-NEXT: [ 3, callee1, 4 ]
// CHECK-3-NEXT: [ 3, callee2, 2 ]
// CHECK-3-NEXT: [ 4, callee1, 5 ]
// CHECK-3-NEXT: [ 4, callee2, 3 ]
// CHECK-3-NEXT: [ 5, callee1, 6 ]
// CHECK-3-NEXT: [ 5, callee2, 3 ]
// CHECK-3-NEXT: [ 6, callee1, 7 ]
// CHECK-3-NEXT: [ 6, callee2, 4 ]
// CHECK-3-NEXT: [ 7, callee1, 8 ]
// CHECK-3-NEXT: [ 7, callee2, 4 ]
// CHECK-3-NEXT: [ 8, callee1, 9 ]
// CHECK-3-NEXT: [ 8, callee2, 5 ]
// CHECK-3-NEXT: [ 9, callee1, 10 ]
// CHECK-3-NEXT: [ 9, callee2, 5 ]
// CHECK-4-LABEL: caller_with_value_site_never_called1:
// CHECK-4-NEXT: Hash: 0x0000000000000000
// CHECK-4-NEXT: Counters:
// CHECK-4-NEXT: Function count:
// CHECK-4-NEXT: Indirect Call Site Count: 10
// CHECK-4-NEXT: Indirect Target Results:
// CHECK-5-LABEL: caller_without_value_site2:
// CHECK-5-NEXT: Hash: 0x0000000000000000
// CHECK-5-NEXT: Counters:
// CHECK-5-NEXT: Function count:
// CHECK-5-NEXT: Indirect Call Site Count: 0
// CHECK-5-NEXT: Indirect Target Results:
// CHECK-6-LABEL: caller_without_value_site1:
// CHECK-6-NEXT: Hash: 0x0000000000000000
// CHECK-6-NEXT: Counters:
// CHECK-6-NEXT: Function count:
// CHECK-6-NEXT: Indirect Call Site Count: 0
// CHECK-6-NEXT: Indirect Target Results: