1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[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

llvm-svn: 323616
This commit is contained in:
Jonas Devlieghere 2018-01-28 11:05:10 +00:00
parent b0e1b77ff1
commit 924e1d99fc
7 changed files with 50 additions and 11 deletions

View File

@ -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

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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;

View File

@ -59,6 +59,7 @@ add_llvm_library(LLVMSupport
DebugCounter.cpp
DeltaAlgorithm.cpp
DAGDeltaAlgorithm.cpp
DJB.cpp
Error.cpp
ErrorHandling.cpp
FileUtilities.cpp

20
lib/Support/DJB.cpp Normal file
View File

@ -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;
}