[ProfileData] Add unit test infrastructure for sample profile reader/writer
[oota-llvm.git] / include / llvm / ProfileData / SampleProfReader.h
index 8a54ea0b3152ed989511da81968fd48c4241487c..9762813264f491f861e7098e385328a315486a23 100644 (file)
 //        A NUL-separated list of SIZE strings.
 //
 // FUNCTION BODY (one for each uninlined function body present in the profile)
+//    HEAD_SAMPLES (uint64_t) [only for top-level functions]
+//        Total number of samples collected at the head (prologue) of the
+//        function.
+//        NOTE: This field should only be present for top-level functions
+//              (i.e., not inlined into any caller). Inlined function calls
+//              have no prologue, so they don't need this.
 //    NAME_IDX (uint32_t)
 //        Index into the name table indicating the function name.
-//    SAMPLES (uint32_t)
+//    SAMPLES (uint64_t)
 //        Total number of samples collected in this function.
-//        FIXME(dnovillo) this should be a uint64_t value.
-//    HEAD_SAMPLES (uint32_t)
-//        Total number of samples collected at the head of the function.
 //    NRECS (uint32_t)
 //        Total number of sampling records this function's profile.
 //    BODY RECORDS
@@ -264,6 +267,10 @@ public:
   static ErrorOr<std::unique_ptr<SampleProfileReader>>
   create(StringRef Filename, LLVMContext &C);
 
+  /// \brief Create a sample profile reader from the supplied memory buffer.
+  static ErrorOr<std::unique_ptr<SampleProfileReader>>
+  create(std::unique_ptr<MemoryBuffer> &B, LLVMContext &C);
+
 protected:
   /// \brief Map every function to its associated profile.
   ///
@@ -289,6 +296,9 @@ public:
 
   /// \brief Read sample profiles from the associated file.
   std::error_code read() override;
+
+  /// \brief Return true if \p Buffer is in the format supported by this class.
+  static bool hasFormat(const MemoryBuffer &Buffer);
 };
 
 class SampleProfileReaderBinary : public SampleProfileReader {