blob: ede5368ca2c2ffa1ead9207eddf2d7afae451ee9 [file] [log] [blame]
Justin Bognerb7aa2632014-04-18 21:48:40 +00001//=-- InstrProfIndexed.h - Indexed profiling format support -------*- C++ -*-=//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Shared header for the instrumented profile data reader and writer.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_PROFILEDATA_INSTRPROF_INDEXED_H_
15#define LLVM_PROFILEDATA_INSTRPROF_INDEXED_H_
16
17#include "llvm/Support/MD5.h"
18
19namespace llvm {
20
21namespace IndexedInstrProf {
22enum class HashT : uint32_t {
23 MD5,
24
25 Last = MD5
26};
27
28static inline uint64_t MD5Hash(StringRef Str) {
29 MD5 Hash;
30 Hash.update(Str);
31 llvm::MD5::MD5Result Result;
32 Hash.final(Result);
33 // Return the least significant 8 bytes. Our MD5 implementation returns the
34 // result in little endian, so we may need to swap bytes.
35 using namespace llvm::support;
36 return endian::read<uint64_t, little, unaligned>(Result);
37}
38
Justin Bognerb5d368e2014-04-18 22:00:22 +000039static inline uint64_t ComputeHash(HashT Type, StringRef K) {
Justin Bognerb7aa2632014-04-18 21:48:40 +000040 switch (Type) {
41 case HashT::MD5:
42 return IndexedInstrProf::MD5Hash(K);
43 }
44 llvm_unreachable("Unhandled hash type");
45}
46
47const uint64_t Magic = 0x8169666f72706cff; // "\xfflprofi\x81"
48const uint64_t Version = 1;
49const HashT HashType = HashT::MD5;
50}
51
52} // end namespace llvm
53
54#endif // LLVM_PROFILEDATA_INSTRPROF_INDEXED_H_