Skip to content

Commit 4403cdb

Browse files
[ProfileData] Refactor BinaryIdsStart and BinaryIdsSize (NFC) (#94922)
BinaryIdsStart and BinaryIdsSize in IndexedInstrProfReader are always used together, so this patch packages them into an ArrayRef<uint8_t>. For now, readBinaryIdsInternal immediately unpacks ArrayRef into its constituents to avoid touching the rest of readBinaryIdsInternal.
1 parent 367d502 commit 4403cdb

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

llvm/include/llvm/ProfileData/InstrProfReader.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -697,10 +697,8 @@ class IndexedInstrProfReader : public InstrProfReader {
697697
/// A compiler that reads indexed profiles could construct symtab from module
698698
/// IR so it doesn't need the decompressed names.
699699
StringRef VTableName;
700-
/// Total size of binary ids.
701-
uint64_t BinaryIdsSize{0};
702-
/// Start address of binary id length and data pairs.
703-
const uint8_t *BinaryIdsStart = nullptr;
700+
/// A memory buffer holding binary ids.
701+
ArrayRef<uint8_t> BinaryIdsBuffer;
704702

705703
// Index to the current record in the record array.
706704
unsigned RecordIndex = 0;

llvm/lib/ProfileData/InstrProfReader.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,14 @@ static Error initializeReader(InstrProfReader &Reader) {
9191
/// associated endian format to read the binary ids correctly.
9292
static Error
9393
readBinaryIdsInternal(const MemoryBuffer &DataBuffer,
94-
const uint64_t BinaryIdsSize,
95-
const uint8_t *BinaryIdsStart,
94+
ArrayRef<uint8_t> BinaryIdsBuffer,
9695
std::vector<llvm::object::BuildID> &BinaryIds,
9796
const llvm::endianness Endian) {
9897
using namespace support;
9998

99+
const uint64_t BinaryIdsSize = BinaryIdsBuffer.size();
100+
const uint8_t *BinaryIdsStart = BinaryIdsBuffer.data();
101+
100102
if (BinaryIdsSize == 0)
101103
return Error::success();
102104

@@ -584,10 +586,10 @@ Error RawInstrProfReader<IntPtrT>::readHeader(
584586
const uint8_t *BufferEnd = (const uint8_t *)DataBuffer->getBufferEnd();
585587
if (BinaryIdSize % sizeof(uint64_t) || BinaryIdEnd > BufferEnd)
586588
return error(instrprof_error::bad_header);
587-
if (BinaryIdSize != 0) {
588-
if (Error Err =
589-
readBinaryIdsInternal(*DataBuffer, BinaryIdSize, BinaryIdStart,
590-
BinaryIds, getDataEndianness()))
589+
ArrayRef<uint8_t> BinaryIdsBuffer(BinaryIdStart, BinaryIdSize);
590+
if (!BinaryIdsBuffer.empty()) {
591+
if (Error Err = readBinaryIdsInternal(*DataBuffer, BinaryIdsBuffer,
592+
BinaryIds, getDataEndianness()))
591593
return Err;
592594
}
593595

@@ -1383,13 +1385,13 @@ Error IndexedInstrProfReader::readHeader() {
13831385
if (Header->getIndexedProfileVersion() >= 9) {
13841386
const unsigned char *Ptr = Start + Header->BinaryIdOffset;
13851387
// Read binary ids size.
1386-
BinaryIdsSize =
1388+
uint64_t BinaryIdsSize =
13871389
support::endian::readNext<uint64_t, llvm::endianness::little>(Ptr);
13881390
if (BinaryIdsSize % sizeof(uint64_t))
13891391
return error(instrprof_error::bad_header);
13901392
// Set the binary ids start.
1391-
BinaryIdsStart = Ptr;
1392-
if (BinaryIdsStart > (const unsigned char *)DataBuffer->getBufferEnd())
1393+
BinaryIdsBuffer = ArrayRef<uint8_t>(Ptr, BinaryIdsSize);
1394+
if (Ptr > (const unsigned char *)DataBuffer->getBufferEnd())
13931395
return make_error<InstrProfError>(instrprof_error::malformed,
13941396
"corrupted binary ids");
13951397
}
@@ -1691,8 +1693,8 @@ Error IndexedInstrProfReader::readNextRecord(NamedInstrProfRecord &Record) {
16911693

16921694
Error IndexedInstrProfReader::readBinaryIds(
16931695
std::vector<llvm::object::BuildID> &BinaryIds) {
1694-
return readBinaryIdsInternal(*DataBuffer, BinaryIdsSize, BinaryIdsStart,
1695-
BinaryIds, llvm::endianness::little);
1696+
return readBinaryIdsInternal(*DataBuffer, BinaryIdsBuffer, BinaryIds,
1697+
llvm::endianness::little);
16961698
}
16971699

16981700
Error IndexedInstrProfReader::printBinaryIds(raw_ostream &OS) {

0 commit comments

Comments
 (0)