Skip to content

Commit b9e7da0

Browse files
committed
[compiler-rt][InstrProf] unify the calculation of section bytes and entry counts
1 parent cac5d0e commit b9e7da0

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

compiler-rt/lib/profile/InstrProfilingBuffer.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,13 @@ COMPILER_RT_VISIBILITY
6767
uint64_t __llvm_profile_get_num_data(const __llvm_profile_data *Begin,
6868
const __llvm_profile_data *End) {
6969
intptr_t BeginI = (intptr_t)Begin, EndI = (intptr_t)End;
70-
return ((EndI + sizeof(__llvm_profile_data) - 1) - BeginI) /
71-
sizeof(__llvm_profile_data);
70+
return (EndI - BeginI) / sizeof(__llvm_profile_data);
7271
}
7372

7473
COMPILER_RT_VISIBILITY
7574
uint64_t __llvm_profile_get_data_size(const __llvm_profile_data *Begin,
7675
const __llvm_profile_data *End) {
77-
return __llvm_profile_get_num_data(Begin, End) * sizeof(__llvm_profile_data);
76+
return (intptr_t)(End) - (intptr_t)(Begin);
7877
}
7978

8079
// Counts the number of `VTableProfData` elements within the range of [Begin,
@@ -106,25 +105,23 @@ COMPILER_RT_VISIBILITY size_t __llvm_profile_counter_entry_size(void) {
106105
COMPILER_RT_VISIBILITY
107106
uint64_t __llvm_profile_get_num_counters(const char *Begin, const char *End) {
108107
intptr_t BeginI = (intptr_t)Begin, EndI = (intptr_t)End;
109-
return ((EndI + __llvm_profile_counter_entry_size() - 1) - BeginI) /
110-
__llvm_profile_counter_entry_size();
108+
return (EndI - BeginI) / __llvm_profile_counter_entry_size();
111109
}
112110

113111
COMPILER_RT_VISIBILITY
114112
uint64_t __llvm_profile_get_counters_size(const char *Begin, const char *End) {
115-
return __llvm_profile_get_num_counters(Begin, End) *
116-
__llvm_profile_counter_entry_size();
113+
return (intptr_t)(End) - (intptr_t)(Begin);
117114
}
118115

119116
COMPILER_RT_VISIBILITY
120117
uint64_t __llvm_profile_get_num_bitmap_bytes(const char *Begin,
121118
const char *End) {
122-
return (End - Begin);
119+
return (intptr_t)(End) - (intptr_t)(Begin);
123120
}
124121

125122
COMPILER_RT_VISIBILITY
126123
uint64_t __llvm_profile_get_name_size(const char *Begin, const char *End) {
127-
return End - Begin;
124+
return (intptr_t)(End) - (intptr_t)(Begin);
128125
}
129126

130127
/// Calculate the number of padding bytes needed to add to \p Offset in order

0 commit comments

Comments
 (0)