bool loopIsFiniteByAssumption(const Loop *L);
class FoldID {
- SmallVector<unsigned, 5> Bits;
+ const SCEV *Op = nullptr;
+ const Type *Ty = nullptr;
+ unsigned short C;
public:
- void 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)");
+ FoldID(SCEVTypes C, const SCEV *Op, const Type *Ty) : Op(Op), Ty(Ty), C(C) {
+ assert(Op);
+ assert(Ty);
}
- void addInteger(unsigned I) { Bits.push_back(I); }
- void addInteger(int I) { Bits.push_back(I); }
- void addInteger(unsigned long long I) {
- addInteger(unsigned(I));
- addInteger(unsigned(I >> 32));
- }
-
- void 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 is inherently unstable. Nothing should depend on the
- // ordering of nodes in the folding set.
- static_assert(sizeof(uintptr_t) <= sizeof(unsigned long long),
- "unexpected pointer size");
- addInteger(reinterpret_cast<uintptr_t>(Ptr));
- }
+ FoldID(unsigned short C) : C(C) {}
unsigned computeHash() const {
- unsigned Hash = Bits.size();
- for (unsigned I = 0; I != Bits.size(); ++I)
- Hash = detail::combineHashValue(Hash, Bits[I]);
- return Hash;
+ return detail::combineHashValue(
+ C, detail::combineHashValue(reinterpret_cast<uintptr_t>(Op),
+ reinterpret_cast<uintptr_t>(Ty)));
}
+
bool operator==(const FoldID &RHS) const {
- if (Bits.size() != RHS.Bits.size())
- return false;
- for (unsigned I = 0; I != Bits.size(); ++I)
- if (Bits[I] != RHS.Bits[I])
- return false;
- return true;
+ return std::tie(Op, Ty, C) == std::tie(RHS.Op, RHS.Ty, RHS.C);
}
};
template <> struct DenseMapInfo<ScalarEvolution::FoldID> {
static inline ScalarEvolution::FoldID getEmptyKey() {
- ScalarEvolution::FoldID ID;
- ID.addInteger(~0ULL);
+ ScalarEvolution::FoldID ID(0);
return ID;
}
static inline ScalarEvolution::FoldID getTombstoneKey() {
- ScalarEvolution::FoldID ID;
- ID.addInteger(~0ULL - 1ULL);
+ ScalarEvolution::FoldID ID(1);
return ID;
}
assert(!Op->getType()->isPointerTy() && "Can't extend pointer!");
Ty = getEffectiveSCEVType(Ty);
- FoldID ID;
- ID.addInteger(scZeroExtend);
- ID.addPointer(Op);
- ID.addPointer(Ty);
+ FoldID ID(scZeroExtend, Op, Ty);
auto Iter = FoldCache.find(ID);
if (Iter != FoldCache.end())
return Iter->second;
assert(!Op->getType()->isPointerTy() && "Can't extend pointer!");
Ty = getEffectiveSCEVType(Ty);
- FoldID ID;
- ID.addInteger(scSignExtend);
- ID.addPointer(Op);
- ID.addPointer(Ty);
+ FoldID ID(scSignExtend, Op, Ty);
auto Iter = FoldCache.find(ID);
if (Iter != FoldCache.end())
return Iter->second;