[PGO] Simplify computehash interface (NFC)
[oota-llvm.git] / include / llvm / ProfileData / InstrProf.h
index dca36a4b63b57bb1fecd9af623c5c59f461567fd..365656bb9d2ca1eb32b47beba6cb36a8f2577076 100644 (file)
@@ -199,6 +199,37 @@ enum InstrProfValueKind : uint32_t {
 #include "llvm/ProfileData/InstrProfData.inc"
 };
 
+namespace object {
+class SectionRef;
+}
+/// A symbol table used for function PGO name look-up with keys
+/// (such as pointers, md5hash values) to the function. A function's
+/// PGO name or name's md5hash are used in retrieving the profile
+/// data of the function. See \c getPGOFuncName() method for details
+/// on how PGO name is formed.
+class InstrProfSymtab {
+private:
+  StringRef Data;
+  uint64_t Address;
+
+public:
+  InstrProfSymtab() : Data(), Address(0) {}
+
+  /// Create InstrProfSymtab from a object file section which
+  /// contains function PGO names that are uncompressed.
+  std::error_code create(object::SectionRef &Section);
+  std::error_code create(StringRef D, uint64_t BaseAddr) {
+    Data = D;
+    Address = BaseAddr;
+    return std::error_code();
+  }
+
+  /// Return function's PGO name from the function name's symabol
+  /// address in the object file. If an error occurs, Return
+  /// an empty string.
+  StringRef getFuncName(uint64_t FuncNameAddress, size_t NameSize);
+};
+
 struct InstrProfStringTable {
   // Set of string values in profiling data.
   StringSet<> StringValueSet;
@@ -544,6 +575,10 @@ const uint64_t Magic = 0x8169666f72706cff; // "\xfflprofi\x81"
 const uint64_t Version = INSTR_PROF_INDEX_VERSION;
 const HashT HashType = HashT::MD5;
 
+static inline uint64_t ComputeHash(StringRef K) {
+  return ComputeHash(HashType, K);
+}
+
 // This structure defines the file header of the LLVM profile
 // data file in indexed-format.
 struct Header {