LLVM  3.7.0
InstrProfIndexed.h
Go to the documentation of this file.
1 //=-- 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_LIB_PROFILEDATA_INSTRPROFINDEXED_H
15 #define LLVM_LIB_PROFILEDATA_INSTRPROFINDEXED_H
16 
17 #include "llvm/Support/Endian.h"
19 #include "llvm/Support/MD5.h"
20 
21 namespace llvm {
22 
23 namespace IndexedInstrProf {
24 enum class HashT : uint32_t {
25  MD5,
26 
27  Last = MD5
28 };
29 
30 static inline uint64_t MD5Hash(StringRef Str) {
31  MD5 Hash;
32  Hash.update(Str);
33  llvm::MD5::MD5Result Result;
34  Hash.final(Result);
35  // Return the least significant 8 bytes. Our MD5 implementation returns the
36  // result in little endian, so we may need to swap bytes.
37  using namespace llvm::support;
38  return endian::read<uint64_t, little, unaligned>(Result);
39 }
40 
41 static inline uint64_t ComputeHash(HashT Type, StringRef K) {
42  switch (Type) {
43  case HashT::MD5:
44  return IndexedInstrProf::MD5Hash(K);
45  }
46  llvm_unreachable("Unhandled hash type");
47 }
48 
49 const uint64_t Magic = 0x8169666f72706cff; // "\xfflprofi\x81"
50 const uint64_t Version = 2;
52 }
53 
54 } // end namespace llvm
55 
56 #endif
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:98
void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
Definition: MD5.cpp:187
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
uint8_t MD5Result[16]
Definition: MD5.h:47
void final(MD5Result &Result)
Finishes off the hash and puts the result in result.
Definition: MD5.cpp:232
static uint64_t MD5Hash(StringRef Str)
static uint64_t ComputeHash(HashT Type, StringRef K)
Definition: MD5.h:37
std::string Hash(const Unit &U)
Definition: FuzzerUtil.cpp:39
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40