[llvm] [nfc][InstrFDO] Add Header::getIndexedProfileVersion and use it to decide profile version. (PR #93613)
Mingming Liu via llvm-commits
llvm-commits at lists.llvm.org
Tue May 28 14:45:18 PDT 2024
https://github.com/minglotus-6 created https://github.com/llvm/llvm-project/pull/93613
This is a split of https://github.com/llvm/llvm-project/pull/93346 as discussed.
>From 0afcdd002236430cbff1b70212df0db7bf3a1698 Mon Sep 17 00:00:00 2001
From: mingmingl <mingmingl at google.com>
Date: Tue, 28 May 2024 11:34:45 -0700
Subject: [PATCH] Introduce Header::getIndexedProfileVersion
---
llvm/include/llvm/ProfileData/InstrProf.h | 4 ++++
llvm/lib/ProfileData/InstrProf.cpp | 11 ++++++++---
llvm/lib/ProfileData/InstrProfReader.cpp | 8 ++++----
3 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/llvm/include/llvm/ProfileData/InstrProf.h b/llvm/include/llvm/ProfileData/InstrProf.h
index 2cee928b210e2..15b9eb688e27e 100644
--- a/llvm/include/llvm/ProfileData/InstrProf.h
+++ b/llvm/include/llvm/ProfileData/InstrProf.h
@@ -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
diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp
index f9cd71b37002f..dcf6aac8b5996 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -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(
@@ -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.
diff --git a/llvm/lib/ProfileData/InstrProfReader.cpp b/llvm/lib/ProfileData/InstrProfReader.cpp
index 836206a4fd86e..ec7117cb91b54 100644
--- a/llvm/lib/ProfileData/InstrProfReader.cpp
+++ b/llvm/lib/ProfileData/InstrProfReader.cpp
@@ -1327,7 +1327,7 @@ 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;
@@ -1335,7 +1335,7 @@ Error IndexedInstrProfReader::readHeader() {
// 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 =
@@ -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 =
@@ -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();
More information about the llvm-commits
mailing list