summaryrefslogtreecommitdiff
path: root/include/llvm/Support/MD5.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/Support/MD5.h')
-rw-r--r--include/llvm/Support/MD5.h15
1 files changed, 14 insertions, 1 deletions
diff --git a/include/llvm/Support/MD5.h b/include/llvm/Support/MD5.h
index f6e1e92c9fa82..42d8ca8a1ebb1 100644
--- a/include/llvm/Support/MD5.h
+++ b/include/llvm/Support/MD5.h
@@ -28,11 +28,12 @@
#ifndef LLVM_SUPPORT_MD5_H
#define LLVM_SUPPORT_MD5_H
-#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/DataTypes.h"
+#include "llvm/Support/Endian.h"
namespace llvm {
+template <typename T> class ArrayRef;
class MD5 {
// Any 32-bit or wider unsigned integer data type will do.
@@ -65,6 +66,18 @@ private:
const uint8_t *body(ArrayRef<uint8_t> Data);
};
+/// Helper to compute and return lower 64 bits of the given string's MD5 hash.
+inline uint64_t MD5Hash(StringRef Str) {
+ MD5 Hash;
+ Hash.update(Str);
+ llvm::MD5::MD5Result Result;
+ Hash.final(Result);
+ // Return the least significant 8 bytes. Our MD5 implementation returns the
+ // result in little endian, so we may need to swap bytes.
+ using namespace llvm::support;
+ return endian::read<uint64_t, little, unaligned>(Result);
+}
+
}
#endif