InstrProfIndexed.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. #ifndef LLVM_LIB_PROFILEDATA_INSTRPROFINDEXED_H
  14. #define LLVM_LIB_PROFILEDATA_INSTRPROFINDEXED_H
  15. #include "llvm/Support/Endian.h"
  16. #include "llvm/Support/ErrorHandling.h"
  17. #include "llvm/Support/MD5.h"
  18. namespace llvm {
  19. namespace IndexedInstrProf {
  20. enum class HashT : uint32_t {
  21. MD5,
  22. Last = MD5
  23. };
  24. static inline uint64_t MD5Hash(StringRef Str) {
  25. MD5 Hash;
  26. Hash.update(Str);
  27. llvm::MD5::MD5Result Result;
  28. Hash.final(Result);
  29. // Return the least significant 8 bytes. Our MD5 implementation returns the
  30. // result in little endian, so we may need to swap bytes.
  31. using namespace llvm::support;
  32. return endian::read<uint64_t, little, unaligned>(Result);
  33. }
  34. static inline uint64_t ComputeHash(HashT Type, StringRef K) {
  35. switch (Type) {
  36. case HashT::MD5:
  37. return IndexedInstrProf::MD5Hash(K);
  38. }
  39. llvm_unreachable("Unhandled hash type");
  40. }
  41. const uint64_t Magic = 0x8169666f72706cff; // "\xfflprofi\x81"
  42. const uint64_t Version = 2;
  43. const HashT HashType = HashT::MD5;
  44. }
  45. } // end namespace llvm
  46. #endif