-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[TypeProf][InstrPGO] Introduce raw and instr profile format change for type profiling. #81691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
0dd267b
a4ec017
9c833bd
d56bb34
206415c
84570cd
0c9ed57
67bbafb
c30a699
393d166
744b87f
4786174
36541d9
c74bde7
d0757f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,16 +51,29 @@ uint64_t __llvm_profile_get_size_for_buffer(void) { | |
const char *BitmapEnd = __llvm_profile_end_bitmap(); | ||
const char *NamesBegin = __llvm_profile_begin_names(); | ||
const char *NamesEnd = __llvm_profile_end_names(); | ||
const VTableProfData *VTableBegin = __llvm_profile_begin_vtables(); | ||
const VTableProfData *VTableEnd = __llvm_profile_end_vtables(); | ||
const char *VNamesBegin = __llvm_profile_begin_vtabnames(); | ||
const char *VNamesEnd = __llvm_profile_end_vtabnames(); | ||
|
||
return __llvm_profile_get_size_for_buffer_internal( | ||
DataBegin, DataEnd, CountersBegin, CountersEnd, BitmapBegin, BitmapEnd, | ||
NamesBegin, NamesEnd); | ||
NamesBegin, NamesEnd, VTableBegin, VTableEnd, VNamesBegin, VNamesEnd); | ||
} | ||
|
||
COMPILER_RT_VISIBILITY | ||
uint64_t __llvm_profile_get_num_data(const __llvm_profile_data *Begin, | ||
const __llvm_profile_data *End) { | ||
intptr_t BeginI = (intptr_t)Begin, EndI = (intptr_t)End; | ||
// `sizeof(__llvm_profile_data) - 1` is required in the numerator when | ||
// [Begin, End] represents an inclusive range. | ||
// For ELF, [Begin, End) represents the address of linker-inserted | ||
// symbols `__start__<elf-section>` and `__stop_<elf-section>`. | ||
// Thereby, `End` is one byte past the inclusive range, and | ||
// `sizeof(__llvm_profile_data) - 1` is not necessary in the numerator to get | ||
// the correct number of profile data. | ||
// FIXME: Consider removing `sizeof(__llvm_profile_data) - 1` if this is true | ||
// across platforms. | ||
return ((EndI + sizeof(__llvm_profile_data) - 1) - BeginI) / | ||
sizeof(__llvm_profile_data); | ||
} | ||
|
@@ -71,6 +84,26 @@ uint64_t __llvm_profile_get_data_size(const __llvm_profile_data *Begin, | |
return __llvm_profile_get_num_data(Begin, End) * sizeof(__llvm_profile_data); | ||
} | ||
|
||
// Counts the number of `VTableProfData` elements within the range of [Begin, | ||
// End). Caller should guarantee that End points to one byte past the inclusive | ||
// range. | ||
// FIXME: Add a compiler-rt test to make sure the number of vtables in the | ||
// raw profile is the same as the number of vtable elements in the instrumented | ||
// binary. | ||
COMPILER_RT_VISIBILITY | ||
uint64_t __llvm_profile_get_num_vtable(const VTableProfData *Begin, | ||
const VTableProfData *End) { | ||
// Convert pointers to intptr_t to use integer arithmetic. | ||
intptr_t EndI = (intptr_t)End, BeginI = (intptr_t)Begin; | ||
return (EndI - BeginI) / sizeof(VTableProfData); | ||
} | ||
|
||
COMPILER_RT_VISIBILITY | ||
uint64_t __llvm_profile_get_vtable_section_size(const VTableProfData *Begin, | ||
const VTableProfData *End) { | ||
return __llvm_profile_get_num_vtable(Begin, End) * sizeof(VTableProfData); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this just be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated both https://gcc.godbolt.org/z/MWaG6cEPn shows the generated codes before and after are equivalent (as long as |
||
} | ||
|
||
COMPILER_RT_VISIBILITY size_t __llvm_profile_counter_entry_size(void) { | ||
if (__llvm_profile_get_version() & VARIANT_MASK_BYTE_COVERAGE) | ||
return sizeof(uint8_t); | ||
|
@@ -119,21 +152,33 @@ static int needsCounterPadding(void) { | |
} | ||
|
||
COMPILER_RT_VISIBILITY | ||
void __llvm_profile_get_padding_sizes_for_counters( | ||
int __llvm_profile_get_padding_sizes_for_counters( | ||
uint64_t DataSize, uint64_t CountersSize, uint64_t NumBitmapBytes, | ||
uint64_t NamesSize, uint64_t *PaddingBytesBeforeCounters, | ||
uint64_t *PaddingBytesAfterCounters, uint64_t *PaddingBytesAfterBitmapBytes, | ||
uint64_t *PaddingBytesAfterNames) { | ||
uint64_t NamesSize, uint64_t VTableSize, uint64_t VNameSize, | ||
uint64_t *PaddingBytesBeforeCounters, uint64_t *PaddingBytesAfterCounters, | ||
uint64_t *PaddingBytesAfterBitmapBytes, uint64_t *PaddingBytesAfterNames, | ||
uint64_t *PaddingBytesAfterVTable, uint64_t *PaddingBytesAfterVName) { | ||
// Counter padding is needed only if continuous mode is enabled. | ||
if (!needsCounterPadding()) { | ||
*PaddingBytesBeforeCounters = 0; | ||
*PaddingBytesAfterCounters = | ||
__llvm_profile_get_num_padding_bytes(CountersSize); | ||
*PaddingBytesAfterBitmapBytes = | ||
__llvm_profile_get_num_padding_bytes(NumBitmapBytes); | ||
*PaddingBytesAfterNames = __llvm_profile_get_num_padding_bytes(NamesSize); | ||
return; | ||
if (PaddingBytesAfterVTable != NULL) | ||
*PaddingBytesAfterVTable = | ||
__llvm_profile_get_num_padding_bytes(VTableSize); | ||
if (PaddingBytesAfterVName != NULL) | ||
*PaddingBytesAfterVName = __llvm_profile_get_num_padding_bytes(VNameSize); | ||
return 0; | ||
} | ||
|
||
// Value profiling not supported in continuous mode at profile-write time. | ||
// Return -1 to alert the incompatibility. | ||
if (VTableSize != 0 || VNameSize != 0) | ||
return -1; | ||
|
||
// In continuous mode, the file offsets for headers and for the start of | ||
// counter sections need to be page-aligned. | ||
*PaddingBytesBeforeCounters = | ||
|
@@ -142,34 +187,52 @@ void __llvm_profile_get_padding_sizes_for_counters( | |
*PaddingBytesAfterBitmapBytes = | ||
calculateBytesNeededToPageAlign(NumBitmapBytes); | ||
*PaddingBytesAfterNames = calculateBytesNeededToPageAlign(NamesSize); | ||
// Set these two variables to zero to avoid uninitialized variables | ||
// even if VTableSize and VNameSize are known to be zero. | ||
if (PaddingBytesAfterVTable != NULL) | ||
*PaddingBytesAfterVTable = 0; | ||
if (PaddingBytesAfterVName != NULL) | ||
*PaddingBytesAfterVName = 0; | ||
return 0; | ||
} | ||
|
||
COMPILER_RT_VISIBILITY | ||
uint64_t __llvm_profile_get_size_for_buffer_internal( | ||
const __llvm_profile_data *DataBegin, const __llvm_profile_data *DataEnd, | ||
const char *CountersBegin, const char *CountersEnd, const char *BitmapBegin, | ||
const char *BitmapEnd, const char *NamesBegin, const char *NamesEnd) { | ||
const char *BitmapEnd, const char *NamesBegin, const char *NamesEnd, | ||
const VTableProfData *VTableBegin, const VTableProfData *VTableEnd, | ||
const char *VNamesBegin, const char *VNamesEnd) { | ||
/* Match logic in __llvm_profile_write_buffer(). */ | ||
const uint64_t NamesSize = (NamesEnd - NamesBegin) * sizeof(char); | ||
uint64_t DataSize = __llvm_profile_get_data_size(DataBegin, DataEnd); | ||
uint64_t CountersSize = | ||
__llvm_profile_get_counters_size(CountersBegin, CountersEnd); | ||
const uint64_t NumBitmapBytes = | ||
__llvm_profile_get_num_bitmap_bytes(BitmapBegin, BitmapEnd); | ||
const uint64_t VTableSize = | ||
__llvm_profile_get_vtable_section_size(VTableBegin, VTableEnd); | ||
const uint64_t VNameSize = | ||
__llvm_profile_get_name_size(VNamesBegin, VNamesEnd); | ||
|
||
/* Determine how much padding is needed before/after the counters and after | ||
* the names. */ | ||
uint64_t PaddingBytesBeforeCounters, PaddingBytesAfterCounters, | ||
PaddingBytesAfterNames, PaddingBytesAfterBitmapBytes; | ||
PaddingBytesAfterNames, PaddingBytesAfterBitmapBytes, | ||
PaddingBytesAfterVTable, PaddingBytesAfterVNames; | ||
__llvm_profile_get_padding_sizes_for_counters( | ||
DataSize, CountersSize, NumBitmapBytes, NamesSize, | ||
&PaddingBytesBeforeCounters, &PaddingBytesAfterCounters, | ||
&PaddingBytesAfterBitmapBytes, &PaddingBytesAfterNames); | ||
DataSize, CountersSize, NumBitmapBytes, NamesSize, 0 /* VTableSize */, | ||
0 /* VNameSize */, &PaddingBytesBeforeCounters, | ||
&PaddingBytesAfterCounters, &PaddingBytesAfterBitmapBytes, | ||
&PaddingBytesAfterNames, &PaddingBytesAfterVTable, | ||
&PaddingBytesAfterVNames); | ||
|
||
return sizeof(__llvm_profile_header) + __llvm_write_binary_ids(NULL) + | ||
DataSize + PaddingBytesBeforeCounters + CountersSize + | ||
PaddingBytesAfterCounters + NumBitmapBytes + | ||
PaddingBytesAfterBitmapBytes + NamesSize + PaddingBytesAfterNames; | ||
PaddingBytesAfterBitmapBytes + NamesSize + PaddingBytesAfterNames + | ||
VTableSize + PaddingBytesAfterVTable + VNameSize + | ||
PaddingBytesAfterVNames; | ||
} | ||
|
||
COMPILER_RT_VISIBILITY | ||
|
@@ -191,7 +254,10 @@ COMPILER_RT_VISIBILITY int __llvm_profile_write_buffer_internal( | |
const char *NamesBegin, const char *NamesEnd) { | ||
ProfDataWriter BufferWriter; | ||
initBufferWriter(&BufferWriter, Buffer); | ||
return lprofWriteDataImpl(&BufferWriter, DataBegin, DataEnd, CountersBegin, | ||
CountersEnd, BitmapBegin, BitmapEnd, 0, NamesBegin, | ||
NamesEnd, 0); | ||
// Set virtual table arguments to NULL since they are not supported yet. | ||
return lprofWriteDataImpl( | ||
&BufferWriter, DataBegin, DataEnd, CountersBegin, CountersEnd, | ||
BitmapBegin, BitmapEnd, /*VPDataReader=*/0, NamesBegin, NamesEnd, | ||
/*VTableBegin=*/NULL, /*VTableEnd=*/NULL, /*VNamesBegin=*/NULL, | ||
/*VNamesEnd=*/NULL, /*SkipNameDataWrite=*/0); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.