[PGO] Read VP raw data without depending on the Value field
[oota-llvm.git] / include / llvm / ProfileData / InstrProfReader.h
index 49233366e164dbd1933db8002cc5784c395bf7dc..304606de67914879e45ff8bef277659457e50e62 100644 (file)
@@ -136,7 +136,6 @@ private:
   bool ShouldSwapBytes;
   uint64_t CountersDelta;
   uint64_t NamesDelta;
-  uint64_t ValueDataDelta;
   const RawInstrProf::ProfileData<IntPtrT> *Data;
   const RawInstrProf::ProfileData<IntPtrT> *DataEnd;
   const uint64_t *CountersStart;
@@ -144,6 +143,7 @@ private:
   const uint8_t *ValueDataStart;
   const char *ProfileEnd;
   uint32_t ValueKindLast;
+  uint32_t CurValueDataSize;
 
   // String table for holding a unique copy of all the strings in the profile.
   InstrProfStringTable StringTable;
@@ -162,10 +162,19 @@ public:
 private:
   std::error_code readNextHeader(const char *CurrentPos);
   std::error_code readHeader(const RawInstrProf::Header &Header);
-  template <class IntT>
-  IntT swap(IntT Int) const {
+  template <class IntT> IntT swap(IntT Int) const {
     return ShouldSwapBytes ? sys::getSwappedBytes(Int) : Int;
   }
+  support::endianness getDataEndianness() const {
+    support::endianness HostEndian = getHostEndianness();
+    if (!ShouldSwapBytes)
+      return HostEndian;
+    if (HostEndian == support::little)
+      return support::big;
+    else
+      return support::little;
+  }
+
   inline uint8_t getNumPaddingBytes(uint64_t SizeInBytes) {
     return 7 & (sizeof(uint64_t) - SizeInBytes % sizeof(uint64_t));
   }
@@ -174,7 +183,10 @@ private:
   std::error_code readRawCounts(InstrProfRecord &Record);
   std::error_code readValueProfilingData(InstrProfRecord &Record);
   bool atEnd() const { return Data == DataEnd; }
-  void advanceData() { Data++; }
+  void advanceData() {
+    Data++;
+    ValueDataStart += CurValueDataSize;
+  }
 
   const uint64_t *getCounter(IntPtrT CounterPtr) const {
     ptrdiff_t Offset = (swap(CounterPtr) - CountersDelta) / sizeof(uint64_t);
@@ -184,17 +196,6 @@ 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<const InstrProfValueData *>(ValueDataStart +
-                                                        Offset);
-  }
 };
 
 typedef RawInstrProfReader<uint32_t> RawInstrProfReader32;
@@ -270,6 +271,7 @@ struct InstrProfReaderIndexBase {
   virtual bool atEnd() const = 0;
   virtual void setValueProfDataEndianness(support::endianness Endianness) = 0;
   virtual ~InstrProfReaderIndexBase() {}
+  virtual uint64_t getVersion() const = 0;
 };
 
 typedef OnDiskIterableChainedHashTable<InstrProfLookupTrait>
@@ -303,6 +305,7 @@ public:
     HashTable->getInfoObj().setValueProfDataEndianness(Endianness);
   }
   ~InstrProfReaderIndex() override {}
+  uint64_t getVersion() const override { return FormatVersion; }
 };
 
 /// Reader for the indexed binary instrprof format.
@@ -319,6 +322,7 @@ private:
   IndexedInstrProfReader &operator=(const IndexedInstrProfReader &) = delete;
 
 public:
+  uint64_t getVersion() const { return Index->getVersion(); }
   IndexedInstrProfReader(std::unique_ptr<MemoryBuffer> DataBuffer)
       : DataBuffer(std::move(DataBuffer)), Index(nullptr) {}