Skip to content

Commit 3c34245

Browse files
authored
[Profile] Use upper 32 bits of profile version for profile variants. (#67695)
Currently all upper 8 bits are reserved for different profile variants. We need more bits for new mods in the future. Context: https://discourse.llvm.org/t/how-to-add-a-new-mode-to-llvm-raw-profile-version/73688
1 parent a2ef046 commit 3c34245

File tree

5 files changed

+13
-15
lines changed

5 files changed

+13
-15
lines changed

compiler-rt/include/profile/InstrProfData.inc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -644,17 +644,16 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
644644
(uint64_t)'p' << 40 | (uint64_t)'r' << 32 | (uint64_t)'o' << 24 | \
645645
(uint64_t)'f' << 16 | (uint64_t)'R' << 8 | (uint64_t)129
646646

647-
/* FIXME: Please remedy the fixme in the header before bumping the version. */
648647
/* Raw profile format version (start from 1). */
649648
#define INSTR_PROF_RAW_VERSION 8
650649
/* Indexed profile format version (start from 1). */
651650
#define INSTR_PROF_INDEX_VERSION 10
652651
/* Coverage mapping format version (start from 0). */
653652
#define INSTR_PROF_COVMAP_VERSION 5
654653

655-
/* Profile version is always of type uint64_t. Reserve the upper 8 bits in the
656-
* version for other variants of profile. We set the lowest bit of the upper 8
657-
* bits (i.e. bit 56) to 1 to indicate if this is an IR-level instrumentation
654+
/* Profile version is always of type uint64_t. Reserve the upper 32 bits in the
655+
* version for other variants of profile. We set the 8th most significant bit
656+
* (i.e. bit 56) to 1 to indicate if this is an IR-level instrumentation
658657
* generated profile, and 0 if this is a Clang FE generated profile.
659658
* 1 in bit 57 indicates there are context-sensitive records in the profile.
660659
* The 59th bit indicates whether to use debug info to correlate profiles.
@@ -663,7 +662,7 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
663662
* The 62nd bit indicates whether memory profile information is present.
664663
* The 63rd bit indicates if this is a temporal profile.
665664
*/
666-
#define VARIANT_MASKS_ALL 0xff00000000000000ULL
665+
#define VARIANT_MASKS_ALL 0xffffffff00000000ULL
667666
#define GET_VERSION(V) ((V) & ~VARIANT_MASKS_ALL)
668667
#define VARIANT_MASK_IR_PROF (0x1ULL << 56)
669668
#define VARIANT_MASK_CSIR_PROF (0x1ULL << 57)

llvm/include/llvm/ProfileData/InstrProfData.inc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -644,17 +644,16 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
644644
(uint64_t)'p' << 40 | (uint64_t)'r' << 32 | (uint64_t)'o' << 24 | \
645645
(uint64_t)'f' << 16 | (uint64_t)'R' << 8 | (uint64_t)129
646646

647-
/* FIXME: Please remedy the fixme in the header before bumping the version. */
648647
/* Raw profile format version (start from 1). */
649648
#define INSTR_PROF_RAW_VERSION 8
650649
/* Indexed profile format version (start from 1). */
651650
#define INSTR_PROF_INDEX_VERSION 10
652651
/* Coverage mapping format version (start from 0). */
653652
#define INSTR_PROF_COVMAP_VERSION 5
654653

655-
/* Profile version is always of type uint64_t. Reserve the upper 8 bits in the
656-
* version for other variants of profile. We set the lowest bit of the upper 8
657-
* bits (i.e. bit 56) to 1 to indicate if this is an IR-level instrumentation
654+
/* Profile version is always of type uint64_t. Reserve the upper 32 bits in the
655+
* version for other variants of profile. We set the 8th most significant bit
656+
* (i.e. bit 56) to 1 to indicate if this is an IR-level instrumentation
658657
* generated profile, and 0 if this is a Clang FE generated profile.
659658
* 1 in bit 57 indicates there are context-sensitive records in the profile.
660659
* The 59th bit indicates whether to use debug info to correlate profiles.
@@ -663,7 +662,7 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
663662
* The 62nd bit indicates whether memory profile information is present.
664663
* The 63rd bit indicates if this is a temporal profile.
665664
*/
666-
#define VARIANT_MASKS_ALL 0xff00000000000000ULL
665+
#define VARIANT_MASKS_ALL 0xffffffff00000000ULL
667666
#define GET_VERSION(V) ((V) & ~VARIANT_MASKS_ALL)
668667
#define VARIANT_MASK_IR_PROF (0x1ULL << 56)
669668
#define VARIANT_MASK_CSIR_PROF (0x1ULL << 57)

llvm/include/llvm/ProfileData/InstrProfReader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ class RawInstrProfReader : public InstrProfReader {
318318
/// A list of timestamps paired with a function name reference.
319319
std::vector<std::pair<uint64_t, uint64_t>> TemporalProfTimestamps;
320320
bool ShouldSwapBytes;
321-
// The value of the version field of the raw profile data header. The lower 56
322-
// bits specifies the format version and the most significant 8 bits specify
321+
// The value of the version field of the raw profile data header. The lower 32
322+
// bits specifies the format version and the most significant 32 bits specify
323323
// the variant types of the profile.
324324
uint64_t Version;
325325
uint64_t CountersDelta;

llvm/lib/ProfileData/InstrProfReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
using namespace llvm;
4040

41-
// Extracts the variant information from the top 8 bits in the version and
41+
// Extracts the variant information from the top 32 bits in the version and
4242
// returns an enum specifying the variants present.
4343
static InstrProfKind getProfileKindFromVersion(uint64_t Version) {
4444
InstrProfKind ProfileKind = InstrProfKind::Unknown;

llvm/test/tools/llvm-profdata/mismatched-raw-profile-header.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Magic
22
RUN: printf '\377lprofr\201' > %t
33
// Version
4-
RUN: printf '\0\01\0\0\0\0\0\10' >> %t
4+
RUN: printf '\0\0\0\0\10\0\0\10' >> %t
55
// The rest of the header needs to be there to prevent a broken header error.
66
RUN: printf '\0\0\0\0\0\0\0\0' >> %t
77
RUN: printf '\0\0\0\0\0\0\0\2' >> %t
@@ -15,5 +15,5 @@ RUN: printf '\0\0\0\0\0\0\0\0' >> %t
1515

1616
RUN: not llvm-profdata show %t -o /dev/null 2>&1 | FileCheck %s
1717

18-
CHECK: raw profile version mismatch: Profile uses raw profile format version = 281474976710664; expected version = {{[0-9]+}}
18+
CHECK: raw profile version mismatch: Profile uses raw profile format version = 134217736; expected version = {{[0-9]+}}
1919
CHECK-NEXT: PLEASE update this tool to version in the raw profile, or regenerate raw profile with expected version.

0 commit comments

Comments
 (0)