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.cpp49
1 files changed, 41 insertions, 8 deletions
diff --git a/llvm/lib/ProfileData/InstrProfReader.cpp b/llvm/lib/ProfileData/InstrProfReader.cpp
index 9581e5b486a6..8a4470ae207d 100644
--- a/llvm/lib/ProfileData/InstrProfReader.cpp
+++ b/llvm/lib/ProfileData/InstrProfReader.cpp
@@ -24,8 +24,8 @@
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/SymbolRemappingReader.h"
#include "llvm/Support/SwapByteOrder.h"
+#include "llvm/Support/SymbolRemappingReader.h"
#include <algorithm>
#include <cctype>
#include <cstddef>
@@ -41,7 +41,7 @@ using namespace llvm;
static Expected<std::unique_ptr<MemoryBuffer>>
setupMemoryBuffer(const Twine &Path) {
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
- MemoryBuffer::getFileOrSTDIN(Path);
+ MemoryBuffer::getFileOrSTDIN(Path, /*IsText=*/true);
if (std::error_code EC = BufferOrErr.getError())
return errorCodeToError(EC);
return std::move(BufferOrErr.get());
@@ -159,16 +159,16 @@ Error TextInstrProfReader::readHeader() {
while (Line->startswith(":")) {
StringRef Str = Line->substr(1);
- if (Str.equals_lower("ir"))
+ if (Str.equals_insensitive("ir"))
IsIRInstr = true;
- else if (Str.equals_lower("fe"))
+ else if (Str.equals_insensitive("fe"))
IsIRInstr = false;
- else if (Str.equals_lower("csir")) {
+ else if (Str.equals_insensitive("csir")) {
IsIRInstr = true;
IsCS = true;
- } else if (Str.equals_lower("entry_first"))
+ } else if (Str.equals_insensitive("entry_first"))
IsEntryFirst = true;
- else if (Str.equals_lower("not_entry_first"))
+ else if (Str.equals_insensitive("not_entry_first"))
IsEntryFirst = false;
else
return error(instrprof_error::bad_header);
@@ -374,11 +374,13 @@ Error RawInstrProfReader<IntPtrT>::readHeader(
auto PaddingBytesAfterCounters = swap(Header.PaddingBytesAfterCounters);
NamesSize = swap(Header.NamesSize);
ValueKindLast = swap(Header.ValueKindLast);
+ BinaryIdsSize = swap(Header.BinaryIdsSize);
auto DataSizeInBytes = DataSize * sizeof(RawInstrProf::ProfileData<IntPtrT>);
auto PaddingSize = getNumPaddingBytes(NamesSize);
- ptrdiff_t DataOffset = sizeof(RawInstrProf::Header);
+ // Profile data starts after profile header and binary ids if exist.
+ ptrdiff_t DataOffset = sizeof(RawInstrProf::Header) + BinaryIdsSize;
ptrdiff_t CountersOffset =
DataOffset + DataSizeInBytes + PaddingBytesBeforeCounters;
ptrdiff_t NamesOffset = CountersOffset + (sizeof(uint64_t) * CountersSize) +
@@ -392,6 +394,10 @@ Error RawInstrProfReader<IntPtrT>::readHeader(
Data = reinterpret_cast<const RawInstrProf::ProfileData<IntPtrT> *>(
Start + DataOffset);
DataEnd = Data + DataSize;
+
+ // Binary ids start just after the header.
+ BinaryIdsStart =
+ reinterpret_cast<const uint8_t *>(&Header) + sizeof(RawInstrProf::Header);
CountersStart = reinterpret_cast<const uint64_t *>(Start + CountersOffset);
NamesStart = Start + NamesOffset;
ValueDataStart = reinterpret_cast<const uint8_t *>(Start + ValueDataOffset);
@@ -506,6 +512,33 @@ Error RawInstrProfReader<IntPtrT>::readNextRecord(NamedInstrProfRecord &Record)
return success();
}
+template <class IntPtrT>
+Error RawInstrProfReader<IntPtrT>::printBinaryIds(raw_ostream &OS) {
+ if (BinaryIdsSize == 0)
+ return success();
+
+ OS << "Binary IDs: \n";
+ const uint8_t *BI = BinaryIdsStart;
+ while (BI < BinaryIdsStart + BinaryIdsSize) {
+ uint64_t BinaryIdLen = swap(*reinterpret_cast<const uint64_t *>(BI));
+ // Increment by binary id length data type size.
+ BI += sizeof(BinaryIdLen);
+ if (BI > (const uint8_t *)DataBuffer->getBufferEnd())
+ return make_error<InstrProfError>(instrprof_error::malformed);
+
+ for (uint64_t I = 0; I < BinaryIdLen; I++)
+ OS << format("%02x", BI[I]);
+ OS << "\n";
+
+ // Increment by binary id data length.
+ BI += BinaryIdLen;
+ if (BI > (const uint8_t *)DataBuffer->getBufferEnd())
+ return make_error<InstrProfError>(instrprof_error::malformed);
+ }
+
+ return success();
+}
+
namespace llvm {
template class RawInstrProfReader<uint32_t>;