Skip to content

Commit 78c4a44

Browse files
committedNov 20, 2015
[PGO] Profile runtime name cleanups
Value profile enumerator change to match LLVM code ProfData new member field name change to match LLVM code ProfData member type change to match LLVM code Do not use lower case for types that are internal to implementation (not exposed to APIs) There is no functional change. This is a preparation patch to enable more code sharing in follow up patches Differential Revision: http://reviews.llvm.org/D14841 llvm-svn: 253700
1 parent d550002 commit 78c4a44

File tree

3 files changed

+48
-44
lines changed

3 files changed

+48
-44
lines changed
 

‎compiler-rt/lib/profile/InstrProfiling.c

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
#include <stdlib.h>
1313
#include <string.h>
1414

15+
typedef struct ValueProfNode {
16+
__llvm_profile_value_data VData;
17+
struct ValueProfNode *Next;
18+
} ValueProfNode;
19+
1520
__attribute__((visibility("hidden"))) uint64_t __llvm_profile_get_magic(void) {
1621
/* Magic number to detect file format and endianness.
1722
*
@@ -54,14 +59,16 @@ __attribute__((visibility("hidden"))) void __llvm_profile_reset_counters(void) {
5459
for (DI = DataBegin; DI != DataEnd; ++DI) {
5560
uint64_t CurrentVSiteCount = 0;
5661
uint32_t VKI, i;
57-
if (!DI->ValueCounters)
62+
if (!DI->Values)
5863
continue;
5964

60-
for (VKI = VK_FIRST; VKI <= VK_LAST; ++VKI)
65+
ValueProfNode **ValueCounters = (ValueProfNode **)DI->Values;
66+
67+
for (VKI = IPVK_First; VKI <= IPVK_Last; ++VKI)
6168
CurrentVSiteCount += DI->NumValueSites[VKI];
6269

6370
for (i = 0; i < CurrentVSiteCount; ++i) {
64-
__llvm_profile_value_node *CurrentVNode = DI->ValueCounters[i];
71+
ValueProfNode *CurrentVNode = ValueCounters[i];
6572

6673
while (CurrentVNode) {
6774
CurrentVNode->VData.NumTaken = 0;
@@ -91,14 +98,14 @@ __llvm_profile_instrument_target(uint64_t TargetValue, void *Data_,
9198
static int allocateValueProfileCounters(__llvm_profile_data *Data) {
9299
uint64_t NumVSites = 0;
93100
uint32_t VKI;
94-
for (VKI = VK_FIRST; VKI <= VK_LAST; ++VKI)
101+
for (VKI = IPVK_First; VKI <= IPVK_Last; ++VKI)
95102
NumVSites += Data->NumValueSites[VKI];
96103

97-
__llvm_profile_value_node **Mem = (__llvm_profile_value_node **)calloc(
98-
NumVSites, sizeof(__llvm_profile_value_node *));
104+
ValueProfNode **Mem =
105+
(ValueProfNode **)calloc(NumVSites, sizeof(ValueProfNode *));
99106
if (!Mem)
100107
return 0;
101-
if (!__sync_bool_compare_and_swap(&Data->ValueCounters, 0, Mem)) {
108+
if (!__sync_bool_compare_and_swap(&Data->Values, 0, Mem)) {
102109
free(Mem);
103110
return 0;
104111
}
@@ -113,20 +120,21 @@ static int allocateValueProfileCounters(__llvm_profile_data *Data) {
113120
}
114121

115122
__attribute__((visibility("hidden"))) void
116-
__llvm_profile_instrument_target(uint64_t TargetValue, void *Data_,
123+
__llvm_profile_instrument_target(uint64_t TargetValue, void *Data,
117124
uint32_t CounterIndex) {
118125

119-
__llvm_profile_data *Data = (__llvm_profile_data *)Data_;
120-
if (!Data)
126+
__llvm_profile_data *VData = (__llvm_profile_data *)Data;
127+
if (!VData)
121128
return;
122129

123-
if (!Data->ValueCounters) {
124-
if (!allocateValueProfileCounters(Data))
130+
if (!VData->Values) {
131+
if (!allocateValueProfileCounters(VData))
125132
return;
126133
}
127134

128-
__llvm_profile_value_node *PrevVNode = NULL;
129-
__llvm_profile_value_node *CurrentVNode = Data->ValueCounters[CounterIndex];
135+
ValueProfNode **ValueCounters = (ValueProfNode **)VData->Values;
136+
ValueProfNode *PrevVNode = NULL;
137+
ValueProfNode *CurrentVNode = ValueCounters[CounterIndex];
130138

131139
uint8_t VDataCount = 0;
132140
while (CurrentVNode) {
@@ -142,27 +150,25 @@ __llvm_profile_instrument_target(uint64_t TargetValue, void *Data_,
142150
if (VDataCount >= UCHAR_MAX)
143151
return;
144152

145-
CurrentVNode =
146-
(__llvm_profile_value_node *)calloc(1, sizeof(__llvm_profile_value_node));
153+
CurrentVNode = (ValueProfNode *)calloc(1, sizeof(ValueProfNode));
147154
if (!CurrentVNode)
148155
return;
149156

150157
CurrentVNode->VData.TargetValue = TargetValue;
151158
CurrentVNode->VData.NumTaken++;
152159

153160
uint32_t Success = 0;
154-
if (!Data->ValueCounters[CounterIndex])
155-
Success = __sync_bool_compare_and_swap(&(Data->ValueCounters[CounterIndex]),
156-
0, CurrentVNode);
161+
if (!ValueCounters[CounterIndex])
162+
Success = __sync_bool_compare_and_swap(&ValueCounters[CounterIndex], 0,
163+
CurrentVNode);
157164
else if (PrevVNode && !PrevVNode->Next)
158165
Success = __sync_bool_compare_and_swap(&(PrevVNode->Next), 0, CurrentVNode);
159166

160167
if (!Success) {
161168
free(CurrentVNode);
162169
return;
163170
}
164-
__sync_fetch_and_add(&TotalValueDataSize,
165-
Success * sizeof(__llvm_profile_value_data));
171+
__sync_fetch_and_add(&TotalValueDataSize, Success * sizeof(ValueProfNode));
166172
}
167173
#endif
168174

@@ -187,10 +193,12 @@ __llvm_profile_gather_value_data(uint8_t **VDataArray) {
187193
uint64_t NumVSites = 0;
188194
uint32_t VKI, i;
189195

190-
if (!I->ValueCounters)
196+
if (!I->Values)
191197
continue;
192198

193-
for (VKI = VK_FIRST; VKI <= VK_LAST; ++VKI)
199+
ValueProfNode **ValueCounters = (ValueProfNode **)I->Values;
200+
201+
for (VKI = IPVK_First; VKI <= IPVK_Last; ++VKI)
194202
NumVSites += I->NumValueSites[VKI];
195203
uint8_t Padding = __llvm_profile_get_num_padding_bytes(NumVSites);
196204

@@ -200,7 +208,7 @@ __llvm_profile_gather_value_data(uint8_t **VDataArray) {
200208

201209
for (i = 0; i < NumVSites; ++i) {
202210

203-
__llvm_profile_value_node *VNode = I->ValueCounters[i];
211+
ValueProfNode *VNode = ValueCounters[i];
204212

205213
uint8_t VDataCount = 0;
206214
while (VNode && ((uint8_t *)(VDataPtr + 1) <= VDataEnd)) {
@@ -213,7 +221,7 @@ __llvm_profile_gather_value_data(uint8_t **VDataArray) {
213221
*PerSiteCountPtr = VDataCount;
214222
++PerSiteCountPtr;
215223
}
216-
I->ValueCounters = (void *)PerSiteCountsHead;
224+
I->Values = (void *)PerSiteCountsHead;
217225
PerSiteCountsHead = (uint8_t *)VDataPtr;
218226
}
219227
return PerSiteCountsHead - *VDataArray;

‎compiler-rt/lib/profile/InstrProfiling.h

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,27 @@ typedef uint32_t uintptr_t;
3535

3636
#endif /* defined(__FreeBSD__) && defined(__i386__) */
3737

38-
typedef enum ValueKind {
39-
VK_IndirectCallTarget = 0,
40-
VK_FIRST = VK_IndirectCallTarget,
41-
VK_LAST = VK_IndirectCallTarget
42-
} __llvm_profile_value_kind;
38+
enum ValueKind {
39+
IPVK_IndirectCallTarget = 0,
40+
IPVK_First = IPVK_IndirectCallTarget,
41+
IPVK_Last = IPVK_IndirectCallTarget
42+
};
4343

4444
typedef struct __llvm_profile_value_data {
4545
uint64_t TargetValue;
4646
uint64_t NumTaken;
4747
} __llvm_profile_value_data;
4848

49-
typedef struct __llvm_profile_value_node {
50-
__llvm_profile_value_data VData;
51-
struct __llvm_profile_value_node *Next;
52-
} __llvm_profile_value_node;
53-
49+
typedef void *IntPtrT;
5450
typedef struct LLVM_ALIGNAS(8) __llvm_profile_data {
5551
const uint32_t NameSize;
5652
const uint32_t NumCounters;
5753
const uint64_t FuncHash;
58-
const char *const NamePtr;
59-
uint64_t *const CounterPtr;
60-
const uint8_t *FunctionPointer;
61-
__llvm_profile_value_node **ValueCounters;
62-
const uint16_t NumValueSites[VK_LAST + 1];
54+
const IntPtrT NamePtr;
55+
const IntPtrT CounterPtr;
56+
const IntPtrT FunctionPointer;
57+
IntPtrT Values;
58+
const uint16_t NumValueSites[IPVK_Last + 1];
6359
} __llvm_profile_data;
6460

6561
typedef struct __llvm_profile_header {
@@ -113,14 +109,14 @@ void __llvm_profile_reset_counters(void);
113109
* Records the target value for the CounterIndex if not seen before. Otherwise,
114110
* increments the counter associated w/ the target value.
115111
*/
116-
void __llvm_profile_instrument_target(uint64_t TargetValue,
117-
void *Data_, uint32_t CounterIndex);
112+
void __llvm_profile_instrument_target(uint64_t TargetValue, void *Data,
113+
uint32_t CounterIndex);
118114

119115
/*!
120116
* \brief Prepares the value profiling data for output.
121117
*
122118
* Prepares a single __llvm_profile_value_data array out of the many
123-
* __llvm_profile_value_node trees (one per instrumented function).
119+
* ValueProfNode trees (one per instrumented function).
124120
*/
125121
uint64_t __llvm_profile_gather_value_data(uint8_t **DataArray);
126122

‎compiler-rt/lib/profile/InstrProfilingWriter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ __attribute__((visibility("hidden"))) int llvmWriteProfDataImpl(
5454
Header.NamesSize = NamesSize;
5555
Header.CountersDelta = (uintptr_t)CountersBegin;
5656
Header.NamesDelta = (uintptr_t)NamesBegin;
57-
Header.ValueKindLast = VK_LAST;
57+
Header.ValueKindLast = IPVK_Last;
5858
Header.ValueDataSize = ValueDataSize;
5959
Header.ValueDataDelta = (uintptr_t)ValueDataBegin;
6060

0 commit comments

Comments
 (0)
Please sign in to comment.