Skip to content

[ProfileData] Refactor BinaryIdsStart and BinaryIdsSize (NFC) #94922

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
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
6 changes: 2 additions & 4 deletions llvm/include/llvm/ProfileData/InstrProfReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -697,10 +697,8 @@ class IndexedInstrProfReader : public InstrProfReader {
/// A compiler that reads indexed profiles could construct symtab from module
/// IR so it doesn't need the decompressed names.
StringRef VTableName;
/// Total size of binary ids.
uint64_t BinaryIdsSize{0};
/// Start address of binary id length and data pairs.
const uint8_t *BinaryIdsStart = nullptr;
/// A memory buffer holding binary ids.
ArrayRef<uint8_t> BinaryIdsBuffer;

// Index to the current record in the record array.
unsigned RecordIndex = 0;
Expand Down
24 changes: 13 additions & 11 deletions llvm/lib/ProfileData/InstrProfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,14 @@ static Error initializeReader(InstrProfReader &Reader) {
/// associated endian format to read the binary ids correctly.
static Error
readBinaryIdsInternal(const MemoryBuffer &DataBuffer,
const uint64_t BinaryIdsSize,
const uint8_t *BinaryIdsStart,
ArrayRef<uint8_t> BinaryIdsBuffer,
std::vector<llvm::object::BuildID> &BinaryIds,
const llvm::endianness Endian) {
using namespace support;

const uint64_t BinaryIdsSize = BinaryIdsBuffer.size();
const uint8_t *BinaryIdsStart = BinaryIdsBuffer.data();

if (BinaryIdsSize == 0)
return Error::success();

Expand Down Expand Up @@ -584,10 +586,10 @@ Error RawInstrProfReader<IntPtrT>::readHeader(
const uint8_t *BufferEnd = (const uint8_t *)DataBuffer->getBufferEnd();
if (BinaryIdSize % sizeof(uint64_t) || BinaryIdEnd > BufferEnd)
return error(instrprof_error::bad_header);
if (BinaryIdSize != 0) {
if (Error Err =
readBinaryIdsInternal(*DataBuffer, BinaryIdSize, BinaryIdStart,
BinaryIds, getDataEndianness()))
ArrayRef<uint8_t> BinaryIdsBuffer(BinaryIdStart, BinaryIdSize);
if (!BinaryIdsBuffer.empty()) {
if (Error Err = readBinaryIdsInternal(*DataBuffer, BinaryIdsBuffer,
BinaryIds, getDataEndianness()))
return Err;
}

Expand Down Expand Up @@ -1383,13 +1385,13 @@ Error IndexedInstrProfReader::readHeader() {
if (Header->getIndexedProfileVersion() >= 9) {
const unsigned char *Ptr = Start + Header->BinaryIdOffset;
// Read binary ids size.
BinaryIdsSize =
uint64_t BinaryIdsSize =
support::endian::readNext<uint64_t, llvm::endianness::little>(Ptr);
if (BinaryIdsSize % sizeof(uint64_t))
return error(instrprof_error::bad_header);
// Set the binary ids start.
BinaryIdsStart = Ptr;
if (BinaryIdsStart > (const unsigned char *)DataBuffer->getBufferEnd())
BinaryIdsBuffer = ArrayRef<uint8_t>(Ptr, BinaryIdsSize);
if (Ptr > (const unsigned char *)DataBuffer->getBufferEnd())
return make_error<InstrProfError>(instrprof_error::malformed,
"corrupted binary ids");
}
Expand Down Expand Up @@ -1691,8 +1693,8 @@ Error IndexedInstrProfReader::readNextRecord(NamedInstrProfRecord &Record) {

Error IndexedInstrProfReader::readBinaryIds(
std::vector<llvm::object::BuildID> &BinaryIds) {
return readBinaryIdsInternal(*DataBuffer, BinaryIdsSize, BinaryIdsStart,
BinaryIds, llvm::endianness::little);
return readBinaryIdsInternal(*DataBuffer, BinaryIdsBuffer, BinaryIds,
llvm::endianness::little);
}

Error IndexedInstrProfReader::printBinaryIds(raw_ostream &OS) {
Expand Down
Loading