X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FProfileData%2FInstrProfReader.h;h=f58000c3057703ab949bdea8ac2d9d4bc45b133c;hb=77b5e3816106051a5c83ffcf482bff19a17cb852;hp=69e899d806ea4005fe44a15987046913e36a30bf;hpb=61c7e68339b15eb0b9d4f3cfe2e48ebd23e60c40;p=oota-llvm.git diff --git a/include/llvm/ProfileData/InstrProfReader.h b/include/llvm/ProfileData/InstrProfReader.h index 69e899d806e..f58000c3057 100644 --- a/include/llvm/ProfileData/InstrProfReader.h +++ b/include/llvm/ProfileData/InstrProfReader.h @@ -23,6 +23,7 @@ #include "llvm/Support/LineIterator.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/OnDiskHashTable.h" +#include "llvm/Support/raw_ostream.h" #include namespace llvm { @@ -111,6 +112,9 @@ public: TextInstrProfReader(std::unique_ptr DataBuffer_) : DataBuffer(std::move(DataBuffer_)), Line(*DataBuffer, true, '#') {} + /// Return true if the given buffer is in text instrprof format. + static bool hasFormat(const MemoryBuffer &Buffer); + /// Read the header. std::error_code readHeader() override { return success(); } /// Read a single record. @@ -129,15 +133,21 @@ class RawInstrProfReader : public InstrProfReader { private: /// The profile data file contents. std::unique_ptr DataBuffer; - bool ShouldSwapBytes; uint64_t CountersDelta; uint64_t NamesDelta; + uint64_t ValueDataDelta; const RawInstrProf::ProfileData *Data; const RawInstrProf::ProfileData *DataEnd; const uint64_t *CountersStart; const char *NamesStart; + const uint8_t *ValueDataStart; const char *ProfileEnd; + uint32_t ValueKindLast; + + // String table for holding a unique copy of all the strings in the profile. + InstrProfStringTable StringTable; + InstrProfRecord::ValueMapType FunctionPtrToNameMap; RawInstrProfReader(const RawInstrProfReader &) = delete; RawInstrProfReader &operator=(const RawInstrProfReader &) = delete; @@ -156,10 +166,13 @@ private: IntT swap(IntT Int) const { return ShouldSwapBytes ? sys::getSwappedBytes(Int) : Int; } - + inline uint8_t getNumPaddingBytes(uint64_t SizeInBytes) { + return 7 & (sizeof(uint64_t) - SizeInBytes % sizeof(uint64_t)); + } std::error_code readName(InstrProfRecord &Record); std::error_code readFuncHash(InstrProfRecord &Record); std::error_code readRawCounts(InstrProfRecord &Record); + std::error_code readValueData(InstrProfRecord &Record); bool atEnd() const { return Data == DataEnd; } void advanceData() { Data++; } @@ -171,6 +184,17 @@ private: ptrdiff_t Offset = (swap(NamePtr) - NamesDelta) / sizeof(char); return NamesStart + Offset; } + const uint8_t *getValueDataCounts(IntPtrT ValueCountsPtr) const { + ptrdiff_t Offset = + (swap(ValueCountsPtr) - ValueDataDelta) / sizeof(uint8_t); + return ValueDataStart + Offset; + } + // This accepts an already byte-swapped ValueDataPtr argument. + const InstrProfValueData *getValueData(IntPtrT ValueDataPtr) const { + ptrdiff_t Offset = (ValueDataPtr - ValueDataDelta) / sizeof(uint8_t); + return reinterpret_cast(ValueDataStart + + Offset); + } }; typedef RawInstrProfReader RawInstrProfReader32; @@ -186,11 +210,16 @@ class InstrProfLookupTrait { std::vector DataBuffer; IndexedInstrProf::HashT HashType; unsigned FormatVersion; + // Endianness of the input value profile data. + // It should be LE by default, but can be changed + // for testing purpose. + support::endianness ValueProfDataEndianness; std::vector> HashKeys; public: InstrProfLookupTrait(IndexedInstrProf::HashT HashType, unsigned FormatVersion) - : HashType(HashType), FormatVersion(FormatVersion) {} + : HashType(HashType), FormatVersion(FormatVersion), + ValueProfDataEndianness(support::little) {} typedef ArrayRef data_type; @@ -223,6 +252,11 @@ public: bool ReadValueProfilingData(const unsigned char *&D, const unsigned char *const End); data_type ReadData(StringRef K, const unsigned char *D, offset_type N); + + // Used for testing purpose only. + void setValueProfDataEndianness(support::endianness Endianness) { + ValueProfDataEndianness = Endianness; + } }; class InstrProfReaderIndex { @@ -251,6 +285,10 @@ class InstrProfReaderIndex { void advanceToNextKey() { RecordIterator++; } bool atEnd() const { return RecordIterator == Index->data_end(); } + // Used for testing purpose only. + void setValueProfDataEndianness(support::endianness Endianness) { + Index->getInfoObj().setValueProfDataEndianness(Endianness); + } }; /// Reader for the indexed binary instrprof format. @@ -286,6 +324,7 @@ private: /// Fill Counts with the profile data for the given function name. std::error_code getFunctionCounts(StringRef FuncName, uint64_t FuncHash, std::vector &Counts); + /// Return the maximum of all known function counts. uint64_t getMaximumFunctionCount() { return MaxFunctionCount; } @@ -295,6 +334,11 @@ private: static ErrorOr> create(std::unique_ptr Buffer); + + // Used for testing purpose only. + void setValueProfDataEndianness(support::endianness Endianness) { + Index.setValueProfDataEndianness(Endianness); + } }; } // end namespace llvm