Skip to content

Commit 0358825

Browse files
authored
[Profile] Remove __llvm_profile_has_correlation() (#71996)
As discussed in #70856 (comment) and #70856 (comment), it's better not to do runtime check for VARIANT_MASK_DBG_CORRELATE bit in __llvm_profile_raw_version when deciding if profile data/name sections should be dropped or not.
1 parent 0177c1c commit 0358825

File tree

5 files changed

+8
-24
lines changed

5 files changed

+8
-24
lines changed

compiler-rt/lib/profile/InstrProfiling.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,3 @@ COMPILER_RT_VISIBILITY void __llvm_profile_reset_counters(void) {
8989
}
9090
lprofSetProfileDumped(0);
9191
}
92-
93-
COMPILER_RT_VISIBILITY int __llvm_profile_has_correlation() {
94-
return (__llvm_profile_get_version() & VARIANT_MASK_DBG_CORRELATE) != 0ULL;
95-
}

compiler-rt/lib/profile/InstrProfiling.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,6 @@ uint64_t __llvm_profile_get_magic(void);
261261
/*! \brief Get the version of the file format. */
262262
uint64_t __llvm_profile_get_version(void);
263263

264-
/*! \brief If the binary is compiled with profile correlation. */
265-
int __llvm_profile_has_correlation();
266-
267264
/*! \brief Get the number of entries in the profile data section. */
268265
uint64_t __llvm_profile_get_num_data(const __llvm_profile_data *Begin,
269266
const __llvm_profile_data *End);

compiler-rt/lib/profile/InstrProfilingBuffer.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ uint64_t __llvm_profile_get_size_for_buffer(void) {
5656
COMPILER_RT_VISIBILITY
5757
uint64_t __llvm_profile_get_num_data(const __llvm_profile_data *Begin,
5858
const __llvm_profile_data *End) {
59-
if (__llvm_profile_has_correlation())
60-
return 0;
6159
intptr_t BeginI = (intptr_t)Begin, EndI = (intptr_t)End;
6260
return ((EndI + sizeof(__llvm_profile_data) - 1) - BeginI) /
6361
sizeof(__llvm_profile_data);
@@ -66,8 +64,6 @@ uint64_t __llvm_profile_get_num_data(const __llvm_profile_data *Begin,
6664
COMPILER_RT_VISIBILITY
6765
uint64_t __llvm_profile_get_data_size(const __llvm_profile_data *Begin,
6866
const __llvm_profile_data *End) {
69-
if (__llvm_profile_has_correlation())
70-
return 0;
7167
return __llvm_profile_get_num_data(Begin, End) * sizeof(__llvm_profile_data);
7268
}
7369

@@ -98,8 +94,6 @@ uint64_t __llvm_profile_get_num_bitmap_bytes(const char *Begin,
9894

9995
COMPILER_RT_VISIBILITY
10096
uint64_t __llvm_profile_get_name_size(const char *Begin, const char *End) {
101-
if (__llvm_profile_has_correlation())
102-
return 0;
10397
return End - Begin;
10498
}
10599

compiler-rt/lib/profile/InstrProfilingMerge.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ int __llvm_profile_merge_from_buffer(const char *ProfileData,
139139
if (SrcNameStart < SrcCountersStart || SrcNameStart < SrcBitmapStart)
140140
return 1;
141141

142-
// Merge counters by iterating the entire counter section when correlation is
143-
// enabled.
144-
if (__llvm_profile_has_correlation()) {
142+
// Merge counters by iterating the entire counter section when data section is
143+
// empty due to correlation.
144+
if (Header->NumData == 0) {
145145
for (SrcCounter = SrcCountersStart,
146146
DstCounter = __llvm_profile_begin_counters();
147147
SrcCounter < SrcCountersEnd;) {

compiler-rt/lib/profile/InstrProfilingWriter.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,6 @@ lprofWriteDataImpl(ProfDataWriter *Writer, const __llvm_profile_data *DataBegin,
262262
const char *BitmapBegin, const char *BitmapEnd,
263263
VPDataReaderType *VPDataReader, const char *NamesBegin,
264264
const char *NamesEnd, int SkipNameDataWrite) {
265-
int ProfileCorrelation = __llvm_profile_has_correlation();
266-
267265
/* Calculate size of sections. */
268266
const uint64_t DataSectionSize =
269267
__llvm_profile_get_data_size(DataBegin, DataEnd);
@@ -302,7 +300,7 @@ lprofWriteDataImpl(ProfDataWriter *Writer, const __llvm_profile_data *DataBegin,
302300
#endif
303301

304302
/* The data and names sections are omitted in lightweight mode. */
305-
if (ProfileCorrelation) {
303+
if (NumData == 0 && NamesSize == 0) {
306304
Header.CountersDelta = 0;
307305
Header.NamesDelta = 0;
308306
}
@@ -318,22 +316,21 @@ lprofWriteDataImpl(ProfDataWriter *Writer, const __llvm_profile_data *DataBegin,
318316

319317
/* Write the profile data. */
320318
ProfDataIOVec IOVecData[] = {
321-
{ProfileCorrelation ? NULL : DataBegin, sizeof(uint8_t), DataSectionSize,
322-
0},
319+
{DataBegin, sizeof(uint8_t), DataSectionSize, 0},
323320
{NULL, sizeof(uint8_t), PaddingBytesBeforeCounters, 1},
324321
{CountersBegin, sizeof(uint8_t), CountersSectionSize, 0},
325322
{NULL, sizeof(uint8_t), PaddingBytesAfterCounters, 1},
326323
{BitmapBegin, sizeof(uint8_t), NumBitmapBytes, 0},
327324
{NULL, sizeof(uint8_t), PaddingBytesAfterBitmapBytes, 1},
328-
{(SkipNameDataWrite || ProfileCorrelation) ? NULL : NamesBegin,
329-
sizeof(uint8_t), NamesSize, 0},
325+
{SkipNameDataWrite ? NULL : NamesBegin, sizeof(uint8_t), NamesSize, 0},
330326
{NULL, sizeof(uint8_t), PaddingBytesAfterNames, 1}};
331327
if (Writer->Write(Writer, IOVecData, sizeof(IOVecData) / sizeof(*IOVecData)))
332328
return -1;
333329

334330
/* Value profiling is not yet supported in continuous mode and profile
335331
* correlation mode. */
336-
if (__llvm_profile_is_continuous_mode_enabled() || ProfileCorrelation)
332+
if (__llvm_profile_is_continuous_mode_enabled() ||
333+
(NumData == 0 && NamesSize == 0))
337334
return 0;
338335

339336
return writeValueProfData(Writer, VPDataReader, DataBegin, DataEnd);

0 commit comments

Comments
 (0)