summaryrefslogtreecommitdiff
path: root/lib/Support/FoldingSet.cpp
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2012-03-08 09:32:21 +0000
committerDuncan Sands <baldrick@free.fr>2012-03-08 09:32:21 +0000
commited5edea96d72440679311d7d31d39804967f3220 (patch)
tree9ed28f36819890514e02a1a4853176d347fd5f24 /lib/Support/FoldingSet.cpp
parentfac259814923d091942b230e7bd002a8d1130bc3 (diff)
downloadllvm-ed5edea96d72440679311d7d31d39804967f3220.tar.gz
llvm-ed5edea96d72440679311d7d31d39804967f3220.tar.bz2
llvm-ed5edea96d72440679311d7d31d39804967f3220.tar.xz
Revert commit 152300 (ddunbar) since it still seems to be breaking
buildbots. Original commit message: [ADT] Change the trivial FoldingSetNodeID::Add* methods to be inline, reapplied with a fix for the longstanding over-read of 32-bit pointer values. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@152304 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/FoldingSet.cpp')
-rw-r--r--lib/Support/FoldingSet.cpp44
1 files changed, 43 insertions, 1 deletions
diff --git a/lib/Support/FoldingSet.cpp b/lib/Support/FoldingSet.cpp
index d182d48035..e029970b58 100644
--- a/lib/Support/FoldingSet.cpp
+++ b/lib/Support/FoldingSet.cpp
@@ -41,6 +41,43 @@ bool FoldingSetNodeIDRef::operator==(FoldingSetNodeIDRef RHS) const {
//===----------------------------------------------------------------------===//
// FoldingSetNodeID Implementation
+/// Add* - Add various data types to Bit data.
+///
+void FoldingSetNodeID::AddPointer(const void *Ptr) {
+ // Note: this adds pointers to the hash using sizes and endianness that
+ // depend on the host. It doesn't matter however, because hashing on
+ // pointer values in inherently unstable. Nothing should depend on the
+ // ordering of nodes in the folding set.
+ Bits.append(reinterpret_cast<unsigned *>(&Ptr),
+ reinterpret_cast<unsigned *>(&Ptr+1));
+}
+void FoldingSetNodeID::AddInteger(signed I) {
+ Bits.push_back(I);
+}
+void FoldingSetNodeID::AddInteger(unsigned I) {
+ Bits.push_back(I);
+}
+void FoldingSetNodeID::AddInteger(long I) {
+ AddInteger((unsigned long)I);
+}
+void FoldingSetNodeID::AddInteger(unsigned long I) {
+ if (sizeof(long) == sizeof(int))
+ AddInteger(unsigned(I));
+ else if (sizeof(long) == sizeof(long long)) {
+ AddInteger((unsigned long long)I);
+ } else {
+ llvm_unreachable("unexpected sizeof(long)");
+ }
+}
+void FoldingSetNodeID::AddInteger(long long I) {
+ AddInteger((unsigned long long)I);
+}
+void FoldingSetNodeID::AddInteger(unsigned long long I) {
+ AddInteger(unsigned(I));
+ if ((uint64_t)(unsigned)I != I)
+ Bits.push_back(unsigned(I >> 32));
+}
+
void FoldingSetNodeID::AddString(StringRef String) {
unsigned Size = String.size();
Bits.push_back(Size);
@@ -92,7 +129,12 @@ void FoldingSetNodeID::AddString(StringRef String) {
Bits.push_back(V);
}
-/// ComputeHash - Compute a strong hash value for this FoldingSetNodeID, used to
+// AddNodeID - Adds the Bit data of another ID to *this.
+void FoldingSetNodeID::AddNodeID(const FoldingSetNodeID &ID) {
+ Bits.append(ID.Bits.begin(), ID.Bits.end());
+}
+
+/// ComputeHash - Compute a strong hash value for this FoldingSetNodeID, used to
/// lookup the node in the FoldingSetImpl.
unsigned FoldingSetNodeID::ComputeHash() const {
return FoldingSetNodeIDRef(Bits.data(), Bits.size()).ComputeHash();