Skip to content

Commit 737a301

Browse files
[nfc][InstrFDO] Add Header::getIndexedProfileVersion and use it to decide profile version. (#93613)
This is a split of #93346 as discussed.
1 parent 2665b2a commit 737a301

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

llvm/include/llvm/ProfileData/InstrProf.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,10 @@ struct Header {
12111211
// Returns the size of the header in bytes for all valid fields based on the
12121212
// version. I.e a older version header will return a smaller size.
12131213
size_t size() const;
1214+
1215+
// Return the indexed profile version, i.e., the least significant 32 bits
1216+
// in Header.Version.
1217+
uint64_t getIndexedProfileVersion() const;
12141218
};
12151219

12161220
// Profile summary data recorded in the profile data file in indexed

llvm/lib/ProfileData/InstrProf.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,10 +1656,11 @@ Expected<Header> Header::readFromBuffer(const unsigned char *Buffer) {
16561656

16571657
// Read the version.
16581658
H.Version = read(Buffer, offsetOf(&Header::Version));
1659-
if (GET_VERSION(H.Version) > IndexedInstrProf::ProfVersion::CurrentVersion)
1659+
if (H.getIndexedProfileVersion() >
1660+
IndexedInstrProf::ProfVersion::CurrentVersion)
16601661
return make_error<InstrProfError>(instrprof_error::unsupported_version);
16611662

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

1693+
uint64_t Header::getIndexedProfileVersion() const {
1694+
return GET_VERSION(Version);
1695+
}
1696+
16921697
size_t Header::size() const {
1693-
switch (GET_VERSION(Version)) {
1698+
switch (getIndexedProfileVersion()) {
16941699
// When a new field is added to the header add a case statement here to
16951700
// compute the size as offset of the new field + size of the new field. This
16961701
// relies on the field being added to the end of the list.

llvm/lib/ProfileData/InstrProfReader.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,15 +1328,15 @@ Error IndexedInstrProfReader::readHeader() {
13281328

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

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

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

13561356
CompressedVTableNamesLen =
@@ -1363,7 +1363,7 @@ Error IndexedInstrProfReader::readHeader() {
13631363
return make_error<InstrProfError>(instrprof_error::truncated);
13641364
}
13651365

1366-
if (GET_VERSION(Header->Version) >= 10 &&
1366+
if (Header->getIndexedProfileVersion() >= 10 &&
13671367
Header->Version & VARIANT_MASK_TEMPORAL_PROF) {
13681368
const unsigned char *Ptr = Start + Header->TemporalProfTracesOffset;
13691369
const auto *PtrEnd = (const unsigned char *)DataBuffer->getBufferEnd();

0 commit comments

Comments
 (0)