[llvm] 737a301 - [nfc][InstrFDO] Add Header::getIndexedProfileVersion and use it to decide profile version. (#93613)
via llvm-commits
llvm-commits at lists.llvm.org
Wed May 29 10:15:22 PDT 2024
Author: Mingming Liu
Date: 2024-05-29T10:15:17-07:00
New Revision: 737a3018e826f5452f181a550be90b9135d8eda5
URL: https://github.com/llvm/llvm-project/commit/737a3018e826f5452f181a550be90b9135d8eda5
DIFF: https://github.com/llvm/llvm-project/commit/737a3018e826f5452f181a550be90b9135d8eda5.diff
LOG: [nfc][InstrFDO] Add Header::getIndexedProfileVersion and use it to decide profile version. (#93613)
This is a split of https://github.com/llvm/llvm-project/pull/93346 as
discussed.
Added:
Modified:
llvm/include/llvm/ProfileData/InstrProf.h
llvm/lib/ProfileData/InstrProf.cpp
llvm/lib/ProfileData/InstrProfReader.cpp
Removed:
################################################################################
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 798236c295194..a5ae0c6fa6244 100644
--- a/llvm/lib/ProfileData/InstrProfReader.cpp
+++ b/llvm/lib/ProfileData/InstrProfReader.cpp
@@ -1328,7 +1328,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;
@@ -1336,7 +1336,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 =
@@ -1350,7 +1350,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 =
@@ -1363,7 +1363,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