Index: llvm/trunk/include/llvm/BinaryFormat/Dwarf.h =================================================================== --- llvm/trunk/include/llvm/BinaryFormat/Dwarf.h +++ llvm/trunk/include/llvm/BinaryFormat/Dwarf.h @@ -528,9 +528,6 @@ /// 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 Index: llvm/trunk/include/llvm/Support/DJB.h =================================================================== --- llvm/trunk/include/llvm/Support/DJB.h +++ llvm/trunk/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 Index: llvm/trunk/lib/BinaryFormat/Dwarf.cpp =================================================================== --- llvm/trunk/lib/BinaryFormat/Dwarf.cpp +++ llvm/trunk/lib/BinaryFormat/Dwarf.cpp @@ -589,9 +589,3 @@ } return ExtensionsOk; } - -uint32_t llvm::dwarf::djbHash(StringRef Buffer, uint32_t H) { - for (char C : Buffer.bytes()) - H = ((H << 5) + H) + C; - return H; -} Index: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.h =================================================================== --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfAccelTable.h +++ llvm/trunk/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 @@ HashData(StringRef S, DwarfAccelTable::DataArray &Data) : Str(S), Data(Data) { - HashValue = dwarf::djbHash(S); + HashValue = djbHash(S); } #ifndef NDEBUG Index: llvm/trunk/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp =================================================================== --- llvm/trunk/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp +++ llvm/trunk/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 @@ -236,7 +237,7 @@ 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; Index: llvm/trunk/lib/Support/CMakeLists.txt =================================================================== --- llvm/trunk/lib/Support/CMakeLists.txt +++ llvm/trunk/lib/Support/CMakeLists.txt @@ -59,6 +59,7 @@ DebugCounter.cpp DeltaAlgorithm.cpp DAGDeltaAlgorithm.cpp + DJB.cpp Error.cpp ErrorHandling.cpp FileUtilities.cpp Index: llvm/trunk/lib/Support/DJB.cpp =================================================================== --- llvm/trunk/lib/Support/DJB.cpp +++ llvm/trunk/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; +}