Skip to content

[nfc][InstrFDO] Add Header::getIndexedProfileVersion and use it to decide profile version. #93613

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

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/include/llvm/ProfileData/InstrProf.h
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,10 @@ struct Header {
// Returns the size of the header in bytes for all valid fields based on the
// version. I.e a older version header will return a smaller size.
size_t size() const;

// Return the indexed profile version, i.e., the least significant 32 bits
// in Header.Version.
uint64_t getIndexedProfileVersion() const;
};

// Profile summary data recorded in the profile data file in indexed
Expand Down
11 changes: 8 additions & 3 deletions llvm/lib/ProfileData/InstrProf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1656,10 +1656,11 @@ Expected<Header> Header::readFromBuffer(const unsigned char *Buffer) {

// Read the version.
H.Version = read(Buffer, offsetOf(&Header::Version));
if (GET_VERSION(H.Version) > IndexedInstrProf::ProfVersion::CurrentVersion)
if (H.getIndexedProfileVersion() >
IndexedInstrProf::ProfVersion::CurrentVersion)
return make_error<InstrProfError>(instrprof_error::unsupported_version);

switch (GET_VERSION(H.Version)) {
switch (H.getIndexedProfileVersion()) {
// When a new field is added in the header add a case statement here to
// populate it.
static_assert(
Expand Down Expand Up @@ -1689,8 +1690,12 @@ Expected<Header> Header::readFromBuffer(const unsigned char *Buffer) {
return H;
}

uint64_t Header::getIndexedProfileVersion() const {
return GET_VERSION(Version);
}

size_t Header::size() const {
switch (GET_VERSION(Version)) {
switch (getIndexedProfileVersion()) {
// When a new field is added to the header add a case statement here to
// compute the size as offset of the new field + size of the new field. This
// relies on the field being added to the end of the list.
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/ProfileData/InstrProfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1327,15 +1327,15 @@ Error IndexedInstrProfReader::readHeader() {

// The MemProfOffset field in the header is only valid when the format
// version is higher than 8 (when it was introduced).
if (GET_VERSION(Header->Version) >= 8 &&
if (Header->getIndexedProfileVersion() >= 8 &&
Header->Version & VARIANT_MASK_MEMPROF) {
if (Error E = MemProfReader.deserialize(Start, Header->MemProfOffset))
return E;
}

// BinaryIdOffset field in the header is only valid when the format version
// is higher than 9 (when it was introduced).
if (GET_VERSION(Header->Version) >= 9) {
if (Header->getIndexedProfileVersion() >= 9) {
const unsigned char *Ptr = Start + Header->BinaryIdOffset;
// Read binary ids size.
BinaryIdsSize =
Expand All @@ -1349,7 +1349,7 @@ Error IndexedInstrProfReader::readHeader() {
"corrupted binary ids");
}

if (GET_VERSION(Header->Version) >= 12) {
if (Header->getIndexedProfileVersion() >= 12) {
const unsigned char *Ptr = Start + Header->VTableNamesOffset;

CompressedVTableNamesLen =
Expand All @@ -1362,7 +1362,7 @@ Error IndexedInstrProfReader::readHeader() {
return make_error<InstrProfError>(instrprof_error::truncated);
}

if (GET_VERSION(Header->Version) >= 10 &&
if (Header->getIndexedProfileVersion() >= 10 &&
Header->Version & VARIANT_MASK_TEMPORAL_PROF) {
const unsigned char *Ptr = Start + Header->TemporalProfTracesOffset;
const auto *PtrEnd = (const unsigned char *)DataBuffer->getBufferEnd();
Expand Down
Loading