summaryrefslogtreecommitdiff
path: root/llvm/lib/ProfileData/InstrProfReader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/ProfileData/InstrProfReader.cpp')
-rw-r--r--llvm/lib/ProfileData/InstrProfReader.cpp40
1 files changed, 21 insertions, 19 deletions
diff --git a/llvm/lib/ProfileData/InstrProfReader.cpp b/llvm/lib/ProfileData/InstrProfReader.cpp
index 54a2a61c3187..e18ce5d373d1 100644
--- a/llvm/lib/ProfileData/InstrProfReader.cpp
+++ b/llvm/lib/ProfileData/InstrProfReader.cpp
@@ -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();
@@ -138,9 +140,8 @@ readBinaryIdsInternal(const MemoryBuffer &DataBuffer,
return Error::success();
}
-static void
-printBinaryIdsInternal(raw_ostream &OS,
- const std::vector<llvm::object::BuildID> &BinaryIds) {
+static void printBinaryIdsInternal(raw_ostream &OS,
+ ArrayRef<llvm::object::BuildID> BinaryIds) {
OS << "Binary IDs: \n";
for (const auto &BI : BinaryIds) {
for (auto I : BI)
@@ -585,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;
}
@@ -1384,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");
}
@@ -1398,14 +1399,16 @@ Error IndexedInstrProfReader::readHeader() {
if (Header->getIndexedProfileVersion() >= 12) {
const unsigned char *Ptr = Start + Header->VTableNamesOffset;
- CompressedVTableNamesLen =
+ uint64_t CompressedVTableNamesLen =
support::endian::readNext<uint64_t, llvm::endianness::little>(Ptr);
// Writer first writes the length of compressed string, and then the actual
// content.
- VTableNamePtr = (const char *)Ptr;
+ const char *VTableNamePtr = (const char *)Ptr;
if (VTableNamePtr > (const char *)DataBuffer->getBufferEnd())
return make_error<InstrProfError>(instrprof_error::truncated);
+
+ VTableName = StringRef(VTableNamePtr, CompressedVTableNamesLen);
}
if (Header->getIndexedProfileVersion() >= 10 &&
@@ -1461,8 +1464,7 @@ InstrProfSymtab &IndexedInstrProfReader::getSymtab() {
auto NewSymtab = std::make_unique<InstrProfSymtab>();
- if (Error E = NewSymtab->initVTableNamesFromCompressedStrings(
- StringRef(VTableNamePtr, CompressedVTableNamesLen))) {
+ if (Error E = NewSymtab->initVTableNamesFromCompressedStrings(VTableName)) {
auto [ErrCode, Msg] = InstrProfError::take(std::move(E));
consumeError(error(ErrCode, Msg));
}
@@ -1502,7 +1504,7 @@ Expected<InstrProfRecord> IndexedInstrProfReader::getInstrProfRecord(
// A flag to indicate if the records are from the same type
// of profile (i.e cs vs nocs).
bool CSBitMatch = false;
- auto getFuncSum = [](const std::vector<uint64_t> &Counts) {
+ auto getFuncSum = [](ArrayRef<uint64_t> Counts) {
uint64_t ValueSum = 0;
for (uint64_t CountValue : Counts) {
if (CountValue == (uint64_t)-1)
@@ -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) {