Justin Bogner | b7aa263 | 2014-04-18 21:48:40 +0000 | [diff] [blame] | 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 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 14 | #ifndef LLVM_LIB_PROFILEDATA_INSTRPROFINDEXED_H |
| 15 | #define LLVM_LIB_PROFILEDATA_INSTRPROFINDEXED_H |
Justin Bogner | b7aa263 | 2014-04-18 21:48:40 +0000 | [diff] [blame] | 16 | |
Benjamin Kramer | d59664f | 2014-04-29 23:26:49 +0000 | [diff] [blame] | 17 | #include "llvm/Support/ErrorHandling.h" |
Justin Bogner | b7aa263 | 2014-04-18 21:48:40 +0000 | [diff] [blame] | 18 | #include "llvm/Support/MD5.h" |
| 19 | |
| 20 | namespace llvm { |
| 21 | |
| 22 | namespace IndexedInstrProf { |
| 23 | enum class HashT : uint32_t { |
| 24 | MD5, |
| 25 | |
| 26 | Last = MD5 |
| 27 | }; |
| 28 | |
| 29 | static inline uint64_t MD5Hash(StringRef Str) { |
| 30 | MD5 Hash; |
| 31 | Hash.update(Str); |
| 32 | llvm::MD5::MD5Result Result; |
| 33 | Hash.final(Result); |
| 34 | // Return the least significant 8 bytes. Our MD5 implementation returns the |
| 35 | // result in little endian, so we may need to swap bytes. |
| 36 | using namespace llvm::support; |
| 37 | return endian::read<uint64_t, little, unaligned>(Result); |
| 38 | } |
| 39 | |
Justin Bogner | b5d368e | 2014-04-18 22:00:22 +0000 | [diff] [blame] | 40 | static inline uint64_t ComputeHash(HashT Type, StringRef K) { |
Justin Bogner | b7aa263 | 2014-04-18 21:48:40 +0000 | [diff] [blame] | 41 | switch (Type) { |
| 42 | case HashT::MD5: |
| 43 | return IndexedInstrProf::MD5Hash(K); |
| 44 | } |
| 45 | llvm_unreachable("Unhandled hash type"); |
| 46 | } |
| 47 | |
| 48 | const uint64_t Magic = 0x8169666f72706cff; // "\xfflprofi\x81" |
Justin Bogner | 821d747 | 2014-08-01 22:50:07 +0000 | [diff] [blame] | 49 | const uint64_t Version = 2; |
Justin Bogner | b7aa263 | 2014-04-18 21:48:40 +0000 | [diff] [blame] | 50 | const HashT HashType = HashT::MD5; |
| 51 | } |
| 52 | |
| 53 | } // end namespace llvm |
| 54 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 55 | #endif |