[llvm] r323616 - [Support] Move DJB hash to support. NFC

Jonas Devlieghere via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 28 03:05:11 PST 2018


Author: jdevlieghere
Date: Sun Jan 28 03:05:10 2018
New Revision: 323616

URL: http://llvm.org/viewvc/llvm-project?rev=323616&view=rev
Log:
[Support] Move DJB hash to support. NFC

This patch moves the DJB hash to support. This is consistent with other
hashing algorithms living there. The hash is used by the DWARF
accelerator tables. We're doing this now because the hashing function is
needed by dsymutil and we don't want to link against libBinaryFormat.

Differential revision: https://reviews.llvm.org/D42594

Added:
    llvm/trunk/include/llvm/Support/DJB.h
    llvm/trunk/lib/Support/DJB.cpp
Modified:
    llvm/trunk/include/llvm/BinaryFormat/Dwarf.h
    llvm/trunk/lib/BinaryFormat/Dwarf.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.h
    llvm/trunk/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
    llvm/trunk/lib/Support/CMakeLists.txt

Modified: llvm/trunk/include/llvm/BinaryFormat/Dwarf.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/BinaryFormat/Dwarf.h?rev=323616&r1=323615&r2=323616&view=diff
==============================================================================
--- llvm/trunk/include/llvm/BinaryFormat/Dwarf.h (original)
+++ llvm/trunk/include/llvm/BinaryFormat/Dwarf.h Sun Jan 28 03:05:10 2018
@@ -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

Added: llvm/trunk/include/llvm/Support/DJB.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/DJB.h?rev=323616&view=auto
==============================================================================
--- llvm/trunk/include/llvm/Support/DJB.h (added)
+++ llvm/trunk/include/llvm/Support/DJB.h Sun Jan 28 03:05:10 2018
@@ -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

Modified: llvm/trunk/lib/BinaryFormat/Dwarf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/BinaryFormat/Dwarf.cpp?rev=323616&r1=323615&r2=323616&view=diff
==============================================================================
--- llvm/trunk/lib/BinaryFormat/Dwarf.cpp (original)
+++ llvm/trunk/lib/BinaryFormat/Dwarf.cpp Sun Jan 28 03:05:10 2018
@@ -589,9 +589,3 @@ bool llvm::dwarf::isValidFormForVersion(
   }
   return ExtensionsOk;
 }
-
-uint32_t llvm::dwarf::djbHash(StringRef Buffer, uint32_t H) {
-  for (char C : Buffer.bytes())
-    H = ((H << 5) + H) + C;
-  return H;
-}

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.h?rev=323616&r1=323615&r2=323616&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.h Sun Jan 28 03:05:10 2018
@@ -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

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp?rev=323616&r1=323615&r2=323616&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp Sun Jan 28 03:05:10 2018
@@ -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(Strin
     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;

Modified: llvm/trunk/lib/Support/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/CMakeLists.txt?rev=323616&r1=323615&r2=323616&view=diff
==============================================================================
--- llvm/trunk/lib/Support/CMakeLists.txt (original)
+++ llvm/trunk/lib/Support/CMakeLists.txt Sun Jan 28 03:05:10 2018
@@ -59,6 +59,7 @@ add_llvm_library(LLVMSupport
   DebugCounter.cpp
   DeltaAlgorithm.cpp
   DAGDeltaAlgorithm.cpp
+  DJB.cpp
   Error.cpp
   ErrorHandling.cpp
   FileUtilities.cpp

Added: llvm/trunk/lib/Support/DJB.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/DJB.cpp?rev=323616&view=auto
==============================================================================
--- llvm/trunk/lib/Support/DJB.cpp (added)
+++ llvm/trunk/lib/Support/DJB.cpp Sun Jan 28 03:05:10 2018
@@ -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;
+}




More information about the llvm-commits mailing list