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

[ADT] Move DenseMapInfo for APInt into APInt.h (PR50527)

As suggested in https://bugs.llvm.org/show_bug.cgi?id=50527, this
moves the DenseMapInfo for APInt and APSInt into the respective
headers, removing the need to include APInt.h and APSInt.h from
DenseMapInfo.h.

We could probably do the same from StringRef and ArrayRef as well.

Differential Revision: https://reviews.llvm.org/D103422
This commit is contained in:
Nikita Popov 2021-05-31 18:49:34 +02:00
parent ec4f4175eb
commit 0d55b59b6a
5 changed files with 46 additions and 45 deletions

View File

@ -2298,6 +2298,27 @@ void StoreIntToMemory(const APInt &IntVal, uint8_t *Dst, unsigned StoreBytes);
/// from Src into IntVal, which is assumed to be wide enough and to hold zero.
void LoadIntFromMemory(APInt &IntVal, const uint8_t *Src, unsigned LoadBytes);
/// Provide DenseMapInfo for APInt.
template <> struct DenseMapInfo<APInt> {
static inline APInt getEmptyKey() {
APInt V(nullptr, 0);
V.U.VAL = 0;
return V;
}
static inline APInt getTombstoneKey() {
APInt V(nullptr, 0);
V.U.VAL = 1;
return V;
}
static unsigned getHashValue(const APInt &Key);
static bool isEqual(const APInt &LHS, const APInt &RHS) {
return LHS.getBitWidth() == RHS.getBitWidth() && LHS == RHS;
}
};
} // namespace llvm
#endif

View File

@ -348,6 +348,26 @@ inline raw_ostream &operator<<(raw_ostream &OS, const APSInt &I) {
return OS;
}
/// Provide DenseMapInfo for APSInt, using the DenseMapInfo for APInt.
template <> struct DenseMapInfo<APSInt> {
static inline APSInt getEmptyKey() {
return APSInt(DenseMapInfo<APInt>::getEmptyKey());
}
static inline APSInt getTombstoneKey() {
return APSInt(DenseMapInfo<APInt>::getTombstoneKey());
}
static unsigned getHashValue(const APSInt &Key) {
return DenseMapInfo<APInt>::getHashValue(Key);
}
static bool isEqual(const APSInt &LHS, const APSInt &RHS) {
return LHS.getBitWidth() == RHS.getBitWidth() &&
LHS.isUnsigned() == RHS.isUnsigned() && LHS == RHS;
}
};
} // end namespace llvm
#endif

View File

@ -13,8 +13,6 @@
#ifndef LLVM_ADT_DENSEMAPINFO_H
#define LLVM_ADT_DENSEMAPINFO_H
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/StringRef.h"
@ -349,49 +347,6 @@ template <> struct DenseMapInfo<hash_code> {
static bool isEqual(hash_code LHS, hash_code RHS) { return LHS == RHS; }
};
/// Provide DenseMapInfo for APInt.
template <> struct DenseMapInfo<APInt> {
static inline APInt getEmptyKey() {
APInt V(nullptr, 0);
V.U.VAL = 0;
return V;
}
static inline APInt getTombstoneKey() {
APInt V(nullptr, 0);
V.U.VAL = 1;
return V;
}
static unsigned getHashValue(const APInt &Key) {
return static_cast<unsigned>(hash_value(Key));
}
static bool isEqual(const APInt &LHS, const APInt &RHS) {
return LHS.getBitWidth() == RHS.getBitWidth() && LHS == RHS;
}
};
/// Provide DenseMapInfo for APSInt, using the DenseMapInfo for APInt.
template <> struct DenseMapInfo<APSInt> {
static inline APSInt getEmptyKey() {
return APSInt(DenseMapInfo<APInt>::getEmptyKey());
}
static inline APSInt getTombstoneKey() {
return APSInt(DenseMapInfo<APInt>::getTombstoneKey());
}
static unsigned getHashValue(const APSInt &Key) {
return static_cast<unsigned>(hash_value(Key));
}
static bool isEqual(const APSInt &LHS, const APSInt &RHS) {
return LHS.getBitWidth() == RHS.getBitWidth() &&
LHS.isUnsigned() == RHS.isUnsigned() && LHS == RHS;
}
};
} // end namespace llvm
#endif // LLVM_ADT_DENSEMAPINFO_H

View File

@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/ObjectYAML/ELFYAML.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/ELF.h"

View File

@ -550,6 +550,10 @@ hash_code llvm::hash_value(const APInt &Arg) {
hash_combine_range(Arg.U.pVal, Arg.U.pVal + Arg.getNumWords()));
}
unsigned DenseMapInfo<APInt>::getHashValue(const APInt &Key) {
return static_cast<unsigned>(hash_value(Key));
}
bool APInt::isSplat(unsigned SplatSizeInBits) const {
assert(getBitWidth() % SplatSizeInBits == 0 &&
"SplatSizeInBits must divide width!");