@@ -41,8 +41,8 @@ COMPILER_RT_VISIBILITY
41
41
uint64_t __llvm_profile_get_size_for_buffer (void ) {
42
42
const __llvm_profile_data * DataBegin = __llvm_profile_begin_data ();
43
43
const __llvm_profile_data * DataEnd = __llvm_profile_end_data ();
44
- const uint64_t * CountersBegin = __llvm_profile_begin_counters ();
45
- const uint64_t * CountersEnd = __llvm_profile_end_counters ();
44
+ const char * CountersBegin = __llvm_profile_begin_counters ();
45
+ const char * CountersEnd = __llvm_profile_end_counters ();
46
46
const char * NamesBegin = __llvm_profile_begin_names ();
47
47
const char * NamesEnd = __llvm_profile_end_names ();
48
48
@@ -51,13 +51,36 @@ uint64_t __llvm_profile_get_size_for_buffer(void) {
51
51
}
52
52
53
53
COMPILER_RT_VISIBILITY
54
- uint64_t __llvm_profile_get_data_size (const __llvm_profile_data * Begin ,
55
- const __llvm_profile_data * End ) {
54
+ uint64_t __llvm_profile_get_num_data (const __llvm_profile_data * Begin ,
55
+ const __llvm_profile_data * End ) {
56
56
intptr_t BeginI = (intptr_t )Begin , EndI = (intptr_t )End ;
57
57
return ((EndI + sizeof (__llvm_profile_data ) - 1 ) - BeginI ) /
58
58
sizeof (__llvm_profile_data );
59
59
}
60
60
61
+ COMPILER_RT_VISIBILITY
62
+ uint64_t __llvm_profile_get_data_size (const __llvm_profile_data * Begin ,
63
+ const __llvm_profile_data * End ) {
64
+ return __llvm_profile_get_num_data (Begin , End ) * sizeof (__llvm_profile_data );
65
+ }
66
+
67
+ COMPILER_RT_VISIBILITY size_t __llvm_profile_counter_entry_size (void ) {
68
+ return sizeof (uint64_t );
69
+ }
70
+
71
+ COMPILER_RT_VISIBILITY
72
+ uint64_t __llvm_profile_get_num_counters (const char * Begin , const char * End ) {
73
+ intptr_t BeginI = (intptr_t )Begin , EndI = (intptr_t )End ;
74
+ return ((EndI + __llvm_profile_counter_entry_size () - 1 ) - BeginI ) /
75
+ __llvm_profile_counter_entry_size ();
76
+ }
77
+
78
+ COMPILER_RT_VISIBILITY
79
+ uint64_t __llvm_profile_get_counters_size (const char * Begin , const char * End ) {
80
+ return __llvm_profile_get_num_counters (Begin , End ) *
81
+ __llvm_profile_counter_entry_size ();
82
+ }
83
+
61
84
/// Calculate the number of padding bytes needed to add to \p Offset in order
62
85
/// for (\p Offset + Padding) to be page-aligned.
63
86
static uint64_t calculateBytesNeededToPageAlign (uint64_t Offset ) {
@@ -89,24 +112,22 @@ void __llvm_profile_get_padding_sizes_for_counters(
89
112
90
113
// In continuous mode, the file offsets for headers and for the start of
91
114
// counter sections need to be page-aligned.
92
- uint64_t DataSizeInBytes = DataSize * sizeof (__llvm_profile_data );
93
- uint64_t CountersSizeInBytes = CountersSize * sizeof (uint64_t );
94
- * PaddingBytesBeforeCounters = calculateBytesNeededToPageAlign (
95
- sizeof (__llvm_profile_header ) + DataSizeInBytes );
96
- * PaddingBytesAfterCounters =
97
- calculateBytesNeededToPageAlign (CountersSizeInBytes );
115
+ * PaddingBytesBeforeCounters =
116
+ calculateBytesNeededToPageAlign (sizeof (__llvm_profile_header ) + DataSize );
117
+ * PaddingBytesAfterCounters = calculateBytesNeededToPageAlign (CountersSize );
98
118
* PaddingBytesAfterNames = calculateBytesNeededToPageAlign (NamesSize );
99
119
}
100
120
101
121
COMPILER_RT_VISIBILITY
102
122
uint64_t __llvm_profile_get_size_for_buffer_internal (
103
123
const __llvm_profile_data * DataBegin , const __llvm_profile_data * DataEnd ,
104
- const uint64_t * CountersBegin , const uint64_t * CountersEnd ,
105
- const char * NamesBegin , const char * NamesEnd ) {
124
+ const char * CountersBegin , const char * CountersEnd , const char * NamesBegin ,
125
+ const char * NamesEnd ) {
106
126
/* Match logic in __llvm_profile_write_buffer(). */
107
127
const uint64_t NamesSize = (NamesEnd - NamesBegin ) * sizeof (char );
108
128
uint64_t DataSize = __llvm_profile_get_data_size (DataBegin , DataEnd );
109
- uint64_t CountersSize = CountersEnd - CountersBegin ;
129
+ uint64_t CountersSize =
130
+ __llvm_profile_get_counters_size (CountersBegin , CountersEnd );
110
131
111
132
/* Determine how much padding is needed before/after the counters and after
112
133
* the names. */
@@ -117,9 +138,8 @@ uint64_t __llvm_profile_get_size_for_buffer_internal(
117
138
& PaddingBytesAfterCounters , & PaddingBytesAfterNames );
118
139
119
140
return sizeof (__llvm_profile_header ) + __llvm_write_binary_ids (NULL ) +
120
- (DataSize * sizeof (__llvm_profile_data )) + PaddingBytesBeforeCounters +
121
- (CountersSize * sizeof (uint64_t )) + PaddingBytesAfterCounters +
122
- NamesSize + PaddingBytesAfterNames ;
141
+ DataSize + PaddingBytesBeforeCounters + CountersSize +
142
+ PaddingBytesAfterCounters + NamesSize + PaddingBytesAfterNames ;
123
143
}
124
144
125
145
COMPILER_RT_VISIBILITY
@@ -136,8 +156,8 @@ COMPILER_RT_VISIBILITY int __llvm_profile_write_buffer(char *Buffer) {
136
156
137
157
COMPILER_RT_VISIBILITY int __llvm_profile_write_buffer_internal (
138
158
char * Buffer , const __llvm_profile_data * DataBegin ,
139
- const __llvm_profile_data * DataEnd , const uint64_t * CountersBegin ,
140
- const uint64_t * CountersEnd , const char * NamesBegin , const char * NamesEnd ) {
159
+ const __llvm_profile_data * DataEnd , const char * CountersBegin ,
160
+ const char * CountersEnd , const char * NamesBegin , const char * NamesEnd ) {
141
161
ProfDataWriter BufferWriter ;
142
162
initBufferWriter (& BufferWriter , Buffer );
143
163
return lprofWriteDataImpl (& BufferWriter , DataBegin , DataEnd , CountersBegin ,
0 commit comments