mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-17 21:35:07 +00:00
[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@152300 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c10fa6c801
commit
9eddc1cf31
@ -17,6 +17,7 @@
|
|||||||
#define LLVM_ADT_FOLDINGSET_H
|
#define LLVM_ADT_FOLDINGSET_H
|
||||||
|
|
||||||
#include "llvm/Support/DataTypes.h"
|
#include "llvm/Support/DataTypes.h"
|
||||||
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
#include "llvm/ADT/StringRef.h"
|
#include "llvm/ADT/StringRef.h"
|
||||||
|
|
||||||
@ -310,6 +311,7 @@ public:
|
|||||||
void AddInteger(unsigned long long I);
|
void AddInteger(unsigned long long I);
|
||||||
void AddBoolean(bool B) { AddInteger(B ? 1U : 0U); }
|
void AddBoolean(bool B) { AddInteger(B ? 1U : 0U); }
|
||||||
void AddString(StringRef String);
|
void AddString(StringRef String);
|
||||||
|
/// AddNodeID - Adds the Bit data of another ID to *this.
|
||||||
void AddNodeID(const FoldingSetNodeID &ID);
|
void AddNodeID(const FoldingSetNodeID &ID);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -675,6 +677,55 @@ template<typename T> struct FoldingSetTrait<T*> {
|
|||||||
ID.AddPointer(X);
|
ID.AddPointer(X);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// FoldingSetNodeID Inline function definitions
|
||||||
|
|
||||||
|
/// Add* - Add various data types to Bit data.
|
||||||
|
///
|
||||||
|
inline 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.
|
||||||
|
if (sizeof(void*) == sizeof(unsigned))
|
||||||
|
AddInteger((unsigned) (unsigned long long) Ptr);
|
||||||
|
else if (sizeof(void*) == sizeof(unsigned long long)) {
|
||||||
|
AddInteger((unsigned long long) Ptr);
|
||||||
|
} else {
|
||||||
|
llvm_unreachable("unexpected sizeof(void*)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inline void FoldingSetNodeID::AddInteger(signed I) {
|
||||||
|
Bits.push_back(I);
|
||||||
|
}
|
||||||
|
inline void FoldingSetNodeID::AddInteger(unsigned I) {
|
||||||
|
Bits.push_back(I);
|
||||||
|
}
|
||||||
|
inline void FoldingSetNodeID::AddInteger(long I) {
|
||||||
|
AddInteger((unsigned long)I);
|
||||||
|
}
|
||||||
|
inline 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)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inline void FoldingSetNodeID::AddInteger(long long I) {
|
||||||
|
AddInteger((unsigned long long)I);
|
||||||
|
}
|
||||||
|
inline void FoldingSetNodeID::AddInteger(unsigned long long I) {
|
||||||
|
AddInteger(unsigned(I));
|
||||||
|
if ((uint64_t)(unsigned)I != I)
|
||||||
|
Bits.push_back(unsigned(I >> 32));
|
||||||
|
}
|
||||||
|
inline void FoldingSetNodeID::AddNodeID(const FoldingSetNodeID &ID) {
|
||||||
|
Bits.append(ID.Bits.begin(), ID.Bits.end());
|
||||||
|
}
|
||||||
|
|
||||||
} // End of namespace llvm.
|
} // End of namespace llvm.
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -41,43 +41,6 @@ bool FoldingSetNodeIDRef::operator==(FoldingSetNodeIDRef RHS) const {
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// FoldingSetNodeID Implementation
|
// 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) {
|
void FoldingSetNodeID::AddString(StringRef String) {
|
||||||
unsigned Size = String.size();
|
unsigned Size = String.size();
|
||||||
Bits.push_back(Size);
|
Bits.push_back(Size);
|
||||||
@ -129,12 +92,7 @@ void FoldingSetNodeID::AddString(StringRef String) {
|
|||||||
Bits.push_back(V);
|
Bits.push_back(V);
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddNodeID - Adds the Bit data of another ID to *this.
|
/// ComputeHash - Compute a strong hash value for this FoldingSetNodeID, used to
|
||||||
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.
|
/// lookup the node in the FoldingSetImpl.
|
||||||
unsigned FoldingSetNodeID::ComputeHash() const {
|
unsigned FoldingSetNodeID::ComputeHash() const {
|
||||||
return FoldingSetNodeIDRef(Bits.data(), Bits.size()).ComputeHash();
|
return FoldingSetNodeIDRef(Bits.data(), Bits.size()).ComputeHash();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user