LLVM API Documentation

InstrProfIndexed.h
Go to the documentation of this file.
00001 //=-- InstrProfIndexed.h - Indexed profiling format support -------*- C++ -*-=//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // Shared header for the instrumented profile data reader and writer.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_LIB_PROFILEDATA_INSTRPROFINDEXED_H
00015 #define LLVM_LIB_PROFILEDATA_INSTRPROFINDEXED_H
00016 
00017 #include "llvm/Support/ErrorHandling.h"
00018 #include "llvm/Support/MD5.h"
00019 
00020 namespace llvm {
00021 
00022 namespace IndexedInstrProf {
00023 enum class HashT : uint32_t {
00024   MD5,
00025 
00026   Last = MD5
00027 };
00028 
00029 static inline uint64_t MD5Hash(StringRef Str) {
00030   MD5 Hash;
00031   Hash.update(Str);
00032   llvm::MD5::MD5Result Result;
00033   Hash.final(Result);
00034   // Return the least significant 8 bytes. Our MD5 implementation returns the
00035   // result in little endian, so we may need to swap bytes.
00036   using namespace llvm::support;
00037   return endian::read<uint64_t, little, unaligned>(Result);
00038 }
00039 
00040 static inline uint64_t ComputeHash(HashT Type, StringRef K) {
00041   switch (Type) {
00042   case HashT::MD5:
00043     return IndexedInstrProf::MD5Hash(K);
00044   }
00045   llvm_unreachable("Unhandled hash type");
00046 }
00047 
00048 const uint64_t Magic = 0x8169666f72706cff; // "\xfflprofi\x81"
00049 const uint64_t Version = 2;
00050 const HashT HashType = HashT::MD5;
00051 }
00052 
00053 } // end namespace llvm
00054 
00055 #endif