summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/BinaryFormat/Dwarf.h3
-rw-r--r--llvm/include/llvm/Support/DJB.h25
-rw-r--r--llvm/lib/BinaryFormat/Dwarf.cpp6
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfAccelTable.h3
-rw-r--r--llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp3
-rw-r--r--llvm/lib/Support/CMakeLists.txt1
-rw-r--r--llvm/lib/Support/DJB.cpp20
7 files changed, 50 insertions, 11 deletions
diff --git a/llvm/include/llvm/BinaryFormat/Dwarf.h b/llvm/include/llvm/BinaryFormat/Dwarf.h
index e355b442e35..29df99b5de7 100644
--- a/llvm/include/llvm/BinaryFormat/Dwarf.h
+++ b/llvm/include/llvm/BinaryFormat/Dwarf.h
@@ -528,9 +528,6 @@ private:
/// Constants that define the DWARF format as 32 or 64 bit.
enum DwarfFormat : uint8_t { DWARF32, DWARF64 };
-/// The Bernstein hash function used by the accelerator tables.
-uint32_t djbHash(StringRef Buffer, uint32_t H = 5381);
-
} // End of namespace dwarf
} // End of namespace llvm
diff --git a/llvm/include/llvm/Support/DJB.h b/llvm/include/llvm/Support/DJB.h
new file mode 100644
index 00000000000..02e2ce07557
--- /dev/null
+++ b/llvm/include/llvm/Support/DJB.h
@@ -0,0 +1,25 @@
+//===-- llvm/Support/DJB.h ---DJB Hash --------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains support for the DJ Bernstein hash function.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_DJB_H
+#define LLVM_SUPPORT_DJB_H
+
+#include "llvm/ADT/StringRef.h"
+
+namespace llvm {
+
+/// The Bernstein hash function used by the DWARF accelerator tables.
+uint32_t djbHash(StringRef Buffer, uint32_t H = 5381);
+} // namespace llvm
+
+#endif // LLVM_SUPPORT_DJB_H
diff --git a/llvm/lib/BinaryFormat/Dwarf.cpp b/llvm/lib/BinaryFormat/Dwarf.cpp
index 0ec57870f65..169e50e8d14 100644
--- a/llvm/lib/BinaryFormat/Dwarf.cpp
+++ b/llvm/lib/BinaryFormat/Dwarf.cpp
@@ -589,9 +589,3 @@ bool llvm::dwarf::isValidFormForVersion(Form F, unsigned Version,
}
return ExtensionsOk;
}
-
-uint32_t llvm::dwarf::djbHash(StringRef Buffer, uint32_t H) {
- for (char C : Buffer.bytes())
- H = ((H << 5) + H) + C;
- return H;
-}
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfAccelTable.h b/llvm/lib/CodeGen/AsmPrinter/DwarfAccelTable.h
index f56199dc8e7..36373076096 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfAccelTable.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfAccelTable.h
@@ -23,6 +23,7 @@
#include "llvm/CodeGen/DwarfStringPoolEntry.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/Support/Allocator.h"
+#include "llvm/Support/DJB.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
@@ -192,7 +193,7 @@ private:
HashData(StringRef S, DwarfAccelTable::DataArray &Data)
: Str(S), Data(Data) {
- HashValue = dwarf::djbHash(S);
+ HashValue = djbHash(S);
}
#ifndef NDEBUG
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp b/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
index ac30f74f346..8bb14876f15 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
@@ -13,6 +13,7 @@
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
#include "llvm/Support/Compiler.h"
+#include "llvm/Support/DJB.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
#include <cstddef>
@@ -236,7 +237,7 @@ AppleAcceleratorTable::equal_range(StringRef Key) const {
return make_range(ValueIterator(), ValueIterator());
// Find the bucket.
- unsigned HashValue = dwarf::djbHash(Key);
+ unsigned HashValue = djbHash(Key);
unsigned Bucket = HashValue % Hdr.NumBuckets;
unsigned BucketBase = sizeof(Hdr) + Hdr.HeaderDataLength;
unsigned HashesBase = BucketBase + Hdr.NumBuckets * 4;
diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt
index 5723f8fcf5b..d7020336cc9 100644
--- a/llvm/lib/Support/CMakeLists.txt
+++ b/llvm/lib/Support/CMakeLists.txt
@@ -59,6 +59,7 @@ add_llvm_library(LLVMSupport
DebugCounter.cpp
DeltaAlgorithm.cpp
DAGDeltaAlgorithm.cpp
+ DJB.cpp
Error.cpp
ErrorHandling.cpp
FileUtilities.cpp
diff --git a/llvm/lib/Support/DJB.cpp b/llvm/lib/Support/DJB.cpp
new file mode 100644
index 00000000000..c696f1e6a0b
--- /dev/null
+++ b/llvm/lib/Support/DJB.cpp
@@ -0,0 +1,20 @@
+//===-- Support/DJB.cpp ---DJB Hash -----------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains support for the DJ Bernstein hash function.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/DJB.h"
+
+uint32_t llvm::djbHash(StringRef Buffer, uint32_t H) {
+ for (char C : Buffer.bytes())
+ H = ((H << 5) + H) + C;
+ return H;
+}
OpenPOWER on IntegriCloud