[CodeGen][Transforms] Remove unused DenseMapInfo::getEmptyKey (#201994)

After #201281 DenseMapInfo<T>::getEmptyKey() is no longer used by
DenseMap. Remove the unused getEmptyKey definitions and dead sentinel
uses.
This commit is contained in:
Fangrui Song 2026-06-06 13:45:36 -07:00 committed by GitHub
parent 25a492be00
commit e076ae4d0f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
42 changed files with 12 additions and 275 deletions

View file

@ -271,9 +271,6 @@ struct OffsetAndUnitID {
};
template <> struct DenseMapInfo<OffsetAndUnitID> {
static inline OffsetAndUnitID getEmptyKey() {
return OffsetAndUnitID(-1, -1, false);
}
static unsigned getHashValue(const OffsetAndUnitID &Val) {
return (unsigned)llvm::hash_combine(Val.offset(), Val.unitID(), Val.IsTU);
}

View file

@ -85,9 +85,6 @@ template <> struct DenseMapInfo<MBBSectionID> {
using TypeInfo = DenseMapInfo<MBBSectionID::SectionType>;
using NumberInfo = DenseMapInfo<unsigned>;
static inline MBBSectionID getEmptyKey() {
return MBBSectionID(NumberInfo::getEmptyKey());
}
static unsigned getHashValue(const MBBSectionID &SecID) {
return detail::combineHashValue(TypeInfo::getHashValue(SecID.Type),
NumberInfo::getHashValue(SecID.Number));

View file

@ -2125,17 +2125,11 @@ private:
/// instruction rather than by pointer value.
/// The hashing and equality testing functions ignore definitions so this is
/// useful for CSE, etc.
struct MachineInstrExpressionTrait : DenseMapInfo<MachineInstr*> {
static inline MachineInstr *getEmptyKey() {
return nullptr;
}
struct MachineInstrExpressionTrait : DenseMapInfo<MachineInstr *> {
LLVM_ABI static unsigned getHashValue(const MachineInstr *const &MI);
static bool isEqual(const MachineInstr* const &LHS,
const MachineInstr* const &RHS) {
if (RHS == getEmptyKey() || LHS == getEmptyKey())
return LHS == RHS;
static bool isEqual(const MachineInstr *const &LHS,
const MachineInstr *const &RHS) {
return LHS->isIdenticalTo(*RHS, MachineInstr::IgnoreVRegDefs);
}
};

View file

@ -1036,10 +1036,6 @@ private:
};
template <> struct DenseMapInfo<MachineOperand> {
static MachineOperand getEmptyKey() {
return MachineOperand(static_cast<MachineOperand::MachineOperandType>(
MachineOperand::MO_Empty));
}
static unsigned getHashValue(const MachineOperand &MO) {
return hash_value(MO);
}

View file

@ -47,8 +47,6 @@ private:
class PoolEntryDSInfo {
public:
static inline PoolEntry *getEmptyKey() { return nullptr; }
template <typename ValueKeyT>
static unsigned getHashValue(const ValueKeyT &C) {
return hash_value(C);
@ -69,14 +67,10 @@ private:
template <typename ValueKeyT>
static bool isEqual(const ValueKeyT &C, PoolEntry *P) {
if (P == getEmptyKey())
return false;
return isEqual(C, P->getValue());
}
static bool isEqual(PoolEntry *P1, PoolEntry *P2) {
if (P1 == getEmptyKey())
return P1 == P2;
return isEqual(P1->getValue(), P2);
}
};

View file

@ -163,9 +163,6 @@ public:
// Provide DenseMapInfo for Register
template <> struct DenseMapInfo<Register> {
static inline Register getEmptyKey() {
return DenseMapInfo<unsigned>::getEmptyKey();
}
static unsigned getHashValue(const Register &Val) {
return DenseMapInfo<unsigned>::getHashValue(Val.id());
}

View file

@ -238,13 +238,7 @@ public:
inline bool hasOneUse() const;
};
template<> struct DenseMapInfo<SDValue> {
static inline SDValue getEmptyKey() {
SDValue V;
V.ResNo = -1U;
return V;
}
template <> struct DenseMapInfo<SDValue> {
static unsigned getHashValue(const SDValue &Val) {
return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
(unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();

View file

@ -2417,11 +2417,6 @@ template <> struct DenseMapInfo<TargetInstrInfo::RegSubRegPair> {
using RegInfo = DenseMapInfo<Register>;
using SubRegInfo = DenseMapInfo<unsigned>;
static inline TargetInstrInfo::RegSubRegPair getEmptyKey() {
return TargetInstrInfo::RegSubRegPair(RegInfo::getEmptyKey(),
SubRegInfo::getEmptyKey());
}
/// Reuse getHashValue implementation from
/// std::pair<unsigned, unsigned>.
static unsigned getHashValue(const TargetInstrInfo::RegSubRegPair &Val) {

View file

@ -185,8 +185,6 @@ static_assert(std::is_trivially_copyable<GloballyHashedType>::value,
template <> struct DenseMapInfo<codeview::LocallyHashedType> {
LLVM_ABI static codeview::LocallyHashedType Empty;
static codeview::LocallyHashedType getEmptyKey() { return Empty; }
static unsigned getHashValue(codeview::LocallyHashedType Val) {
return Val.Hash;
}
@ -202,8 +200,6 @@ template <> struct DenseMapInfo<codeview::LocallyHashedType> {
template <> struct DenseMapInfo<codeview::GloballyHashedType> {
LLVM_ABI static codeview::GloballyHashedType Empty;
static codeview::GloballyHashedType getEmptyKey() { return Empty; }
static unsigned getHashValue(codeview::GloballyHashedType Val) {
return *reinterpret_cast<const unsigned *>(Val.Hash.data());
}

View file

@ -290,9 +290,6 @@ LLVM_ABI void printTypeIndex(ScopedPrinter &Printer, StringRef FieldName,
}
template <> struct DenseMapInfo<codeview::TypeIndex> {
static inline codeview::TypeIndex getEmptyKey() {
return codeview::TypeIndex{DenseMapInfo<uint32_t>::getEmptyKey()};
}
static unsigned getHashValue(const codeview::TypeIndex &TI) {
return DenseMapInfo<uint32_t>::getHashValue(TI.getIndex());
}

View file

@ -535,7 +535,6 @@ public:
private:
/// DenseMapInfo for struct Abbrev.
struct AbbrevMapInfo {
LLVM_ABI static Abbrev getEmptyKey();
static unsigned getHashValue(uint32_t Code) {
return DenseMapInfo<uint32_t>::getHashValue(Code);
}

View file

@ -52,10 +52,6 @@ struct FileEntry {
} // namespace gsym
template <> struct DenseMapInfo<gsym::FileEntry> {
static inline gsym::FileEntry getEmptyKey() {
gsym::gsym_strp_t key = DenseMapInfo<gsym::gsym_strp_t>::getEmptyKey();
return gsym::FileEntry(key, key);
}
static unsigned getHashValue(const gsym::FileEntry &Val) {
return llvm::hash_combine(
DenseMapInfo<gsym::gsym_strp_t>::getHashValue(Val.Dir),

View file

@ -431,9 +431,6 @@ template <>
struct DenseMapInfo<AA::ValueAndContext>
: public DenseMapInfo<AA::ValueAndContext::Base> {
using Base = DenseMapInfo<AA::ValueAndContext::Base>;
static inline AA::ValueAndContext getEmptyKey() {
return Base::getEmptyKey();
}
static unsigned getHashValue(const AA::ValueAndContext &VAC) {
return Base::getHashValue(VAC);
}
@ -447,9 +444,6 @@ struct DenseMapInfo<AA::ValueAndContext>
template <>
struct DenseMapInfo<AA::ValueScope> : public DenseMapInfo<unsigned char> {
using Base = DenseMapInfo<unsigned char>;
static inline AA::ValueScope getEmptyKey() {
return AA::ValueScope(Base::getEmptyKey());
}
static unsigned getHashValue(const AA::ValueScope &S) {
return Base::getHashValue(S);
}
@ -462,10 +456,6 @@ struct DenseMapInfo<AA::ValueScope> : public DenseMapInfo<unsigned char> {
template <>
struct DenseMapInfo<const AA::InstExclusionSetTy *>
: public DenseMapInfo<void *> {
using super = DenseMapInfo<void *>;
static inline const AA::InstExclusionSetTy *getEmptyKey() {
return static_cast<const AA::InstExclusionSetTy *>(super::getEmptyKey());
}
static unsigned getHashValue(const AA::InstExclusionSetTy *BES) {
unsigned H = 0;
if (BES)
@ -477,8 +467,6 @@ struct DenseMapInfo<const AA::InstExclusionSetTy *>
const AA::InstExclusionSetTy *RHS) {
if (LHS == RHS)
return true;
if (LHS == getEmptyKey() || RHS == getEmptyKey())
return false;
auto SizeLHS = LHS ? LHS->size() : 0;
auto SizeRHS = RHS ? RHS->size() : 0;
if (SizeLHS != SizeRHS)
@ -942,12 +930,6 @@ struct IRPosition {
/// Check if the position has any call base context.
bool hasCallBaseContext() const { return CBContext != nullptr; }
/// Special DenseMap key values.
///
///{
LLVM_ABI static const IRPosition EmptyKey;
///}
/// Conversion into a void * to allow reuse of pointer hashing.
operator void *() const { return Enc.getOpaqueValue(); }
@ -1082,7 +1064,6 @@ private:
/// Helper that allows IRPosition as a key in a DenseMap.
template <> struct DenseMapInfo<IRPosition> {
static inline IRPosition getEmptyKey() { return IRPosition::EmptyKey; }
static unsigned getHashValue(const IRPosition &IRP) {
return (DenseMapInfo<void *>::getHashValue(IRP) << 4) ^
(DenseMapInfo<Value *>::getHashValue(IRP.getCallBaseContext()));

View file

@ -202,12 +202,7 @@ public:
IROutliner(function_ref<TargetTransformInfo &(Function &)> GTTI,
function_ref<IRSimilarityIdentifier &(Module &)> GIRSI,
function_ref<OptimizationRemarkEmitter &(Function &)> GORE)
: getTTI(GTTI), getIRSI(GIRSI), getORE(GORE) {
// Check that the DenseMap implementation has not changed.
static_assert(DenseMapInfo<unsigned>::getEmptyKey() ==
static_cast<unsigned>(-1));
}
: getTTI(GTTI), getIRSI(GIRSI), getORE(GORE) {}
LLVM_ABI bool run(Module &M);
private:

View file

@ -70,14 +70,10 @@ public:
Expression &operator=(const Expression &) = delete;
virtual ~Expression();
static unsigned getEmptyKey() { return ~0U; }
bool operator!=(const Expression &Other) const { return !(*this == Other); }
bool operator==(const Expression &Other) const {
if (getOpcode() != Other.getOpcode())
return false;
if (getOpcode() == getEmptyKey())
return true;
// Compare the expression type for anything but load and store.
// For load and store we set the opcode to zero to make them equal.
if (getExpressionType() != ET_Load && getExpressionType() != ET_Store &&

View file

@ -46,10 +46,6 @@ template <> struct DenseMapInfo<DivRemMapKey> {
Val1.Divisor == Val2.Divisor;
}
static DivRemMapKey getEmptyKey() {
return DivRemMapKey(false, nullptr, nullptr);
}
static unsigned getHashValue(const DivRemMapKey &Val) {
return (unsigned)(reinterpret_cast<uintptr_t>(
static_cast<Value *>(Val.Dividend)) ^

View file

@ -22,9 +22,6 @@
namespace llvm {
/// Traits for DenseMap.
template <> struct DenseMapInfo<SmallVector<sandboxir::Value *>> {
static inline SmallVector<sandboxir::Value *> getEmptyKey() {
return SmallVector<sandboxir::Value *>({(sandboxir::Value *)-1});
}
static unsigned getHashValue(const SmallVector<sandboxir::Value *> &Vec) {
return hash_combine_range(Vec);
}

View file

@ -548,10 +548,6 @@ public:
template <> struct DenseMapInfo<CodeViewDebug::LocalVarDef> {
static inline CodeViewDebug::LocalVarDef getEmptyKey() {
return CodeViewDebug::LocalVarDef::emptyValue();
}
static unsigned getHashValue(const CodeViewDebug::LocalVarDef &DR) {
return DR.hashValue();
}

View file

@ -70,9 +70,6 @@ static cl::opt<cl::boolOrDefault>
// need to create a DenseMapInfo wrapper around the specified underlying type.
template <> struct llvm::DenseMapInfo<VariableID> {
using Wrapped = DenseMapInfo<unsigned>;
static inline VariableID getEmptyKey() {
return static_cast<VariableID>(Wrapped::getEmptyKey());
}
static unsigned getHashValue(const VariableID &Val) {
return Wrapped::getHashValue(static_cast<unsigned>(Val));
}

View file

@ -127,10 +127,6 @@ hash_code hash_value(const ComplexValue &Arg) {
typedef SmallVector<struct ComplexValue, 2> ComplexValues;
template <> struct llvm::DenseMapInfo<ComplexValue> {
static inline ComplexValue getEmptyKey() {
return {DenseMapInfo<Value *>::getEmptyKey(),
DenseMapInfo<Value *>::getEmptyKey()};
}
static unsigned getHashValue(const ComplexValue &Val) {
return hash_combine(DenseMapInfo<Value *>::getHashValue(Val.Real),
DenseMapInfo<Value *>::getHashValue(Val.Imag));

View file

@ -209,16 +209,12 @@ namespace llvm {
using namespace LiveDebugValues;
template <> struct DenseMapInfo<LocIdx> {
static inline LocIdx getEmptyKey() { return LocIdx::MakeIllegalLoc(); }
static unsigned getHashValue(const LocIdx &Loc) { return Loc.asU64(); }
static bool isEqual(const LocIdx &A, const LocIdx &B) { return A == B; }
};
template <> struct DenseMapInfo<ValueIDNum> {
static inline ValueIDNum getEmptyKey() { return ValueIDNum::EmptyValue; }
static unsigned getHashValue(const ValueIDNum &Val) {
return hash_value(Val.asU64());
}

View file

@ -244,9 +244,6 @@ struct InstructionMapper {
if (LegalInstrNumber >= IllegalInstrNumber)
report_fatal_error("Instruction mapping overflow!");
assert(LegalInstrNumber != DenseMapInfo<unsigned>::getEmptyKey() &&
"Tried to assign DenseMap empty key to instruction.");
// Statistics.
++NumLegalInUnsignedVec;
return MINumber;
@ -282,9 +279,6 @@ struct InstructionMapper {
assert(LegalInstrNumber < IllegalInstrNumber &&
"Instruction mapping overflow!");
assert(IllegalInstrNumber != DenseMapInfo<unsigned>::getEmptyKey() &&
"IllegalInstrNumber cannot be DenseMap empty key!");
return MINumber;
}
@ -413,12 +407,7 @@ struct InstructionMapper {
}
}
InstructionMapper(const MachineModuleInfo &MMI_) : MMI(MMI_) {
// Make sure that the implementation of DenseMapInfo<unsigned> hasn't
// changed.
static_assert(DenseMapInfo<unsigned>::getEmptyKey() ==
static_cast<unsigned>(-1));
}
InstructionMapper(const MachineModuleInfo &MMI_) : MMI(MMI_) {}
};
/// An interprocedural pass which finds repeated sequences of

View file

@ -245,8 +245,6 @@ StackMaps::parseOperand(MachineInstr::const_mop_iterator MOI,
// where we have to insert the empty key into a map, and for a
// DenseMap<uint64_t, T> this is (uint64_t)-1. It can be and is
// represented using 32 bit integers.
assert((uint64_t)Imm != DenseMapInfo<uint64_t>::getEmptyKey() &&
"empty key should fit in 32 bits!");
auto Result = ConstPool.insert(std::make_pair(Imm, Imm));
Locs.emplace_back(Location::ConstantIndex, sizeof(int64_t), 0,
Result.first - ConstPool.begin());

View file

@ -512,10 +512,6 @@ static bool isSentinel(const DWARFDebugNames::Abbrev &Abbr) {
return Abbr.Code == 0;
}
DWARFDebugNames::Abbrev DWARFDebugNames::AbbrevMapInfo::getEmptyKey() {
return sentinelAbbrev();
}
Expected<DWARFDebugNames::AttributeEncoding>
DWARFDebugNames::NameIndex::extractAttributeEncoding(uint64_t *Offset) {
if (*Offset >= Offsets.EntriesBase) {

View file

@ -68,10 +68,6 @@ struct llvm::pdb::GSIHashStreamBuilder {
// DenseMapInfo implementation for deduplicating symbol records.
struct llvm::pdb::SymbolDenseMapInfo {
static inline CVSymbol getEmptyKey() {
static CVSymbol Empty;
return Empty;
}
static unsigned getHashValue(const CVSymbol &Val) {
return xxh3_64bits(Val.RecordData);
}

View file

@ -1332,8 +1332,6 @@ ChangeStatus Attributor::manifestAttrs(const IRPosition &IRP,
return updateAttrMap<Attribute>(IRP, Attrs, AddAttrCB);
}
const IRPosition IRPosition::EmptyKey(DenseMapInfo<void *>::getEmptyKey());
SubsumingPositionIterator::SubsumingPositionIterator(const IRPosition &IRP) {
IRPositions.emplace_back(IRP);

View file

@ -745,18 +745,12 @@ struct State;
template <>
struct DenseMapInfo<AAPointerInfo::Access> : DenseMapInfo<Instruction *> {
using Access = AAPointerInfo::Access;
static inline Access getEmptyKey();
static unsigned getHashValue(const Access &A);
static bool isEqual(const Access &LHS, const Access &RHS);
};
/// Helper that allows RangeTy as a key in a DenseMap.
template <> struct DenseMapInfo<AA::RangeTy> {
static inline AA::RangeTy getEmptyKey() {
auto EmptyKey = DenseMapInfo<int64_t>::getEmptyKey();
return AA::RangeTy{EmptyKey, EmptyKey};
}
static unsigned getHashValue(const AA::RangeTy &Range) {
return detail::combineHashValue(
DenseMapInfo<int64_t>::getHashValue(Range.Offset),
@ -773,7 +767,6 @@ template <> struct DenseMapInfo<AA::RangeTy> {
struct AccessAsInstructionInfo : DenseMapInfo<Instruction *> {
using Base = DenseMapInfo<Instruction *>;
using Access = AAPointerInfo::Access;
static inline Access getEmptyKey();
static unsigned getHashValue(const Access &A);
static bool isEqual(const Access &LHS, const Access &RHS);
};
@ -3469,9 +3462,6 @@ template <typename ToTy> struct DenseMapInfo<ReachabilityQueryInfo<ToTy> *> {
using InstSetDMI = DenseMapInfo<const AA::InstExclusionSetTy *>;
using PairDMI = DenseMapInfo<std::pair<const Instruction *, const ToTy *>>;
static ReachabilityQueryInfo<ToTy> EmptyKey;
static inline ReachabilityQueryInfo<ToTy> *getEmptyKey() { return &EmptyKey; }
static unsigned getHashValue(const ReachabilityQueryInfo<ToTy> *RQI) {
return RQI->Hash ? RQI->Hash : RQI->computeHashValue();
}
@ -3483,17 +3473,6 @@ template <typename ToTy> struct DenseMapInfo<ReachabilityQueryInfo<ToTy> *> {
}
};
#define DefineKeys(ToTy) \
template <> \
ReachabilityQueryInfo<ToTy> \
DenseMapInfo<ReachabilityQueryInfo<ToTy> *>::EmptyKey = \
ReachabilityQueryInfo<ToTy>( \
DenseMapInfo<const Instruction *>::getEmptyKey(), \
DenseMapInfo<const ToTy *>::getEmptyKey());
DefineKeys(Instruction) DefineKeys(Function)
#undef DefineKeys
} // namespace llvm
namespace {

View file

@ -633,8 +633,6 @@ void FunctionSpecializer::cleanUpSSA() {
}
template <> struct llvm::DenseMapInfo<SpecSig> {
static inline SpecSig getEmptyKey() { return {~0U, {}}; }
static unsigned getHashValue(const SpecSig &S) {
return static_cast<unsigned>(hash_value(S));
}

View file

@ -383,10 +383,6 @@ struct VTableSlot {
} // end anonymous namespace
template <> struct llvm::DenseMapInfo<VTableSlot> {
static VTableSlot getEmptyKey() {
return {DenseMapInfo<Metadata *>::getEmptyKey(),
DenseMapInfo<uint64_t>::getEmptyKey()};
}
static unsigned getHashValue(const VTableSlot &I) {
return DenseMapInfo<Metadata *>::getHashValue(I.TypeID) ^
DenseMapInfo<uint64_t>::getHashValue(I.ByteOffset);
@ -398,10 +394,6 @@ template <> struct llvm::DenseMapInfo<VTableSlot> {
};
template <> struct llvm::DenseMapInfo<VTableSlotSummary> {
static VTableSlotSummary getEmptyKey() {
return {DenseMapInfo<StringRef>::getEmptyKey(),
DenseMapInfo<uint64_t>::getEmptyKey()};
}
static unsigned getHashValue(const VTableSlotSummary &I) {
return DenseMapInfo<StringRef>::getHashValue(I.TypeID) ^
DenseMapInfo<uint64_t>::getHashValue(I.ByteOffset);

View file

@ -1048,9 +1048,6 @@ struct LoweredPHIRecord {
} // namespace
template <> struct llvm::DenseMapInfo<LoweredPHIRecord> {
static inline LoweredPHIRecord getEmptyKey() {
return LoweredPHIRecord(nullptr, 0);
}
static unsigned getHashValue(const LoweredPHIRecord &Val) {
return DenseMapInfo<PHINode *>::getHashValue(Val.PN) ^ (Val.Shift >> 3) ^
(Val.Width >> 3);

View file

@ -94,11 +94,7 @@ struct SimpleValue {
Instruction *Inst;
SimpleValue(Instruction *I) : Inst(I) {
assert((isSentinel() || canHandle(I)) && "Inst can't be handled!");
}
bool isSentinel() const {
return Inst == DenseMapInfo<Instruction *>::getEmptyKey();
assert(canHandle(I) && "Inst can't be handled!");
}
static bool canHandle(Instruction *Inst) {
@ -154,10 +150,6 @@ struct SimpleValue {
} // end anonymous namespace
template <> struct llvm::DenseMapInfo<SimpleValue> {
static inline SimpleValue getEmptyKey() {
return DenseMapInfo<Instruction *>::getEmptyKey();
}
static unsigned getHashValue(SimpleValue Val);
static bool isEqual(SimpleValue LHS, SimpleValue RHS);
};
@ -345,9 +337,6 @@ unsigned DenseMapInfo<SimpleValue>::getHashValue(SimpleValue Val) {
static bool isEqualImpl(SimpleValue LHS, SimpleValue RHS) {
Instruction *LHSI = LHS.Inst, *RHSI = RHS.Inst;
if (LHS.isSentinel() || RHS.isSentinel())
return LHSI == RHSI;
if (LHSI->getOpcode() != RHSI->getOpcode())
return false;
if (LHSI->isIdenticalToWhenDefined(RHSI, /*IntersectAttrs=*/true)) {
@ -457,8 +446,7 @@ bool DenseMapInfo<SimpleValue>::isEqual(SimpleValue LHS, SimpleValue RHS) {
// These comparisons are nontrivial, so assert that equality implies
// hash equality (DenseMap demands this as an invariant).
bool Result = isEqualImpl(LHS, RHS);
assert(!Result || (LHS.isSentinel() && LHS.Inst == RHS.Inst) ||
getHashValueImpl(LHS) == getHashValueImpl(RHS));
assert(!Result || getHashValueImpl(LHS) == getHashValueImpl(RHS));
return Result;
}
@ -474,11 +462,7 @@ struct CallValue {
Instruction *Inst;
CallValue(Instruction *I) : Inst(I) {
assert((isSentinel() || canHandle(I)) && "Inst can't be handled!");
}
bool isSentinel() const {
return Inst == DenseMapInfo<Instruction *>::getEmptyKey();
assert(canHandle(I) && "Inst can't be handled!");
}
static bool canHandle(Instruction *Inst) {
@ -500,10 +484,6 @@ struct CallValue {
} // end anonymous namespace
template <> struct llvm::DenseMapInfo<CallValue> {
static inline CallValue getEmptyKey() {
return DenseMapInfo<Instruction *>::getEmptyKey();
}
static unsigned getHashValue(CallValue Val);
static bool isEqual(CallValue LHS, CallValue RHS);
};
@ -516,9 +496,6 @@ unsigned DenseMapInfo<CallValue>::getHashValue(CallValue Val) {
}
bool DenseMapInfo<CallValue>::isEqual(CallValue LHS, CallValue RHS) {
if (LHS.isSentinel() || RHS.isSentinel())
return LHS.Inst == RHS.Inst;
CallInst *LHSI = cast<CallInst>(LHS.Inst);
CallInst *RHSI = cast<CallInst>(RHS.Inst);
@ -542,16 +519,12 @@ struct GEPValue {
std::optional<int64_t> ConstantOffset;
GEPValue(Instruction *I) : Inst(I) {
assert((isSentinel() || canHandle(I)) && "Inst can't be handled!");
assert(canHandle(I) && "Inst can't be handled!");
}
GEPValue(Instruction *I, std::optional<int64_t> ConstantOffset)
: Inst(I), ConstantOffset(ConstantOffset) {
assert((isSentinel() || canHandle(I)) && "Inst can't be handled!");
}
bool isSentinel() const {
return Inst == DenseMapInfo<Instruction *>::getEmptyKey();
assert(canHandle(I) && "Inst can't be handled!");
}
static bool canHandle(Instruction *Inst) {
@ -562,10 +535,6 @@ struct GEPValue {
} // namespace
template <> struct llvm::DenseMapInfo<GEPValue> {
static inline GEPValue getEmptyKey() {
return DenseMapInfo<Instruction *>::getEmptyKey();
}
static unsigned getHashValue(const GEPValue &Val);
static bool isEqual(const GEPValue &LHS, const GEPValue &RHS);
};
@ -580,8 +549,6 @@ unsigned DenseMapInfo<GEPValue>::getHashValue(const GEPValue &Val) {
}
bool DenseMapInfo<GEPValue>::isEqual(const GEPValue &LHS, const GEPValue &RHS) {
if (LHS.isSentinel() || RHS.isSentinel())
return LHS.Inst == RHS.Inst;
auto *LGEP = cast<GetElementPtrInst>(LHS.Inst);
auto *RGEP = cast<GetElementPtrInst>(RHS.Inst);
if (LGEP->getPointerOperand() != RGEP->getPointerOperand())

View file

@ -177,8 +177,6 @@ struct llvm::GVNPass::Expression {
};
template <> struct llvm::DenseMapInfo<GVNPass::Expression> {
static inline GVNPass::Expression getEmptyKey() { return ~0U; }
static unsigned getHashValue(const GVNPass::Expression &E) {
using llvm::hash_value;

View file

@ -255,11 +255,6 @@ static raw_ostream &operator<<(raw_ostream &OS,
#endif
template <> struct llvm::DenseMapInfo<ModelledPHI> {
static inline ModelledPHI &getEmptyKey() {
static ModelledPHI Dummy = ModelledPHI::createDummy(0);
return Dummy;
}
static unsigned getHashValue(const ModelledPHI &V) { return V.hash(); }
static bool isEqual(const ModelledPHI &LHS, const ModelledPHI &RHS) {

View file

@ -303,10 +303,6 @@ struct UnrolledInstStateKeyInfo {
using PtrInfo = DenseMapInfo<Instruction *>;
using PairInfo = DenseMapInfo<std::pair<Instruction *, int>>;
static inline UnrolledInstState getEmptyKey() {
return {PtrInfo::getEmptyKey(), 0, 0, 0};
}
static inline unsigned getHashValue(const UnrolledInstState &S) {
return PairInfo::getHashValue({S.I, S.Iteration});
}

View file

@ -442,12 +442,6 @@ struct ExactEqualsExpression {
} // end anonymous namespace
template <> struct llvm::DenseMapInfo<const Expression *> {
static const Expression *getEmptyKey() {
auto Val = static_cast<uintptr_t>(-1);
Val <<= PointerLikeTypeTraits<const Expression *>::NumLowBitsAvailable;
return reinterpret_cast<const Expression *>(Val);
}
static unsigned getHashValue(const Expression *E) {
return E->getComputedHash();
}
@ -457,16 +451,12 @@ template <> struct llvm::DenseMapInfo<const Expression *> {
}
static bool isEqual(const ExactEqualsExpression &LHS, const Expression *RHS) {
if (RHS == getEmptyKey())
return false;
return LHS == *RHS;
}
static bool isEqual(const Expression *LHS, const Expression *RHS) {
if (LHS == RHS)
return true;
if (LHS == getEmptyKey() || RHS == getEmptyKey())
return false;
// Compare hashes before equality. This is *not* what the hashtable does,
// since it is computing it modulo the number of buckets, whereas we are
// using the full hash keyspace. Since the hashes are precomputed, this

View file

@ -102,11 +102,6 @@ struct FrozenIndPHIInfo {
} // namespace
template <> struct llvm::DenseMapInfo<FrozenIndPHIInfo> {
static inline FrozenIndPHIInfo getEmptyKey() {
return FrozenIndPHIInfo(DenseMapInfo<PHINode *>::getEmptyKey(),
DenseMapInfo<BinaryOperator *>::getEmptyKey());
}
static unsigned getHashValue(const FrozenIndPHIInfo &Val) {
return DenseMapInfo<FreezeInst *>::getHashValue(Val.FI);
};

View file

@ -1432,12 +1432,6 @@ EliminateDuplicatePHINodesSetBasedImpl(BasicBlock *BB,
// one having an undef where the other doesn't could be collapsed.
struct PHIDenseMapInfo {
static PHINode *getEmptyKey() {
return DenseMapInfo<PHINode *>::getEmptyKey();
}
static bool isSentinel(PHINode *PN) { return PN == getEmptyKey(); }
// WARNING: this logic must be kept in sync with
// Instruction::isIdenticalToWhenDefined()!
static unsigned getHashValueImpl(PHINode *PN) {
@ -1462,8 +1456,6 @@ EliminateDuplicatePHINodesSetBasedImpl(BasicBlock *BB,
}
static bool isEqualImpl(PHINode *LHS, PHINode *RHS) {
if (isSentinel(LHS) || isSentinel(RHS))
return LHS == RHS;
return LHS->isIdenticalTo(RHS);
}
@ -1471,8 +1463,7 @@ EliminateDuplicatePHINodesSetBasedImpl(BasicBlock *BB,
// These comparisons are nontrivial, so assert that equality implies
// hash equality (DenseMap demands this as an invariant).
bool Result = isEqualImpl(LHS, RHS);
assert(!Result || (isSentinel(LHS) && LHS == RHS) ||
getHashValueImpl(LHS) == getHashValueImpl(RHS));
assert(!Result || getHashValueImpl(LHS) == getHashValueImpl(RHS));
return Result;
}
};
@ -2817,18 +2808,12 @@ static bool markAliveBlocks(Function &F, SmallVectorImpl<bool> &Reachable,
} else if (auto *CatchSwitch = dyn_cast<CatchSwitchInst>(Terminator)) {
// Remove catchpads which cannot be reached.
struct CatchPadDenseMapInfo {
static CatchPadInst *getEmptyKey() {
return DenseMapInfo<CatchPadInst *>::getEmptyKey();
}
static unsigned getHashValue(CatchPadInst *CatchPad) {
return static_cast<unsigned>(hash_combine_range(
CatchPad->value_op_begin(), CatchPad->value_op_end()));
}
static bool isEqual(CatchPadInst *LHS, CatchPadInst *RHS) {
if (LHS == getEmptyKey() || RHS == getEmptyKey())
return LHS == RHS;
return LHS->isIdenticalTo(RHS);
}
};

View file

@ -8056,9 +8056,6 @@ struct EqualBBWrapper {
};
template <> struct llvm::DenseMapInfo<const EqualBBWrapper *> {
static const EqualBBWrapper *getEmptyKey() {
return static_cast<EqualBBWrapper *>(DenseMapInfo<void *>::getEmptyKey());
}
static unsigned getHashValue(const EqualBBWrapper *EBW) {
BasicBlock *BB = EBW->BB;
UncondBrInst *BI = cast<UncondBrInst>(BB->getTerminator());
@ -8078,10 +8075,6 @@ template <> struct llvm::DenseMapInfo<const EqualBBWrapper *> {
return hash_combine(Succ, hash_combine_range(PhiValsForBB));
}
static bool isEqual(const EqualBBWrapper *LHS, const EqualBBWrapper *RHS) {
auto *EKey = DenseMapInfo<EqualBBWrapper *>::getEmptyKey();
if (LHS == EKey || RHS == EKey)
return LHS == RHS;
BasicBlock *A = LHS->BB;
BasicBlock *B = RHS->BB;

View file

@ -1817,15 +1817,11 @@ std::vector<Chain> Vectorizer::gatherChains(ArrayRef<Instruction *> Instrs) {
: std::pair<Instruction *, Chain>(I, {}) {}
};
struct InstrListElemDenseMapInfo {
using PtrInfo = DenseMapInfo<InstrListElem *>;
using IInfo = DenseMapInfo<Instruction *>;
static InstrListElem *getEmptyKey() { return PtrInfo::getEmptyKey(); }
static unsigned getHashValue(const InstrListElem *E) {
return IInfo::getHashValue(E->first);
}
static bool isEqual(const InstrListElem *A, const InstrListElem *B) {
if (A == getEmptyKey() || B == getEmptyKey())
return A == getEmptyKey() && B == getEmptyKey();
return IInfo::isEqual(A->first, B->first);
}
};

View file

@ -2050,10 +2050,6 @@ struct CSEDenseMapInfo {
isa<ShuffleVectorInst>(I) || isa<GetElementPtrInst>(I);
}
static inline Instruction *getEmptyKey() {
return DenseMapInfo<Instruction *>::getEmptyKey();
}
static unsigned getHashValue(const Instruction *I) {
assert(canHandle(I) && "Unknown instruction!");
return hash_combine(I->getOpcode(),
@ -2061,8 +2057,6 @@ struct CSEDenseMapInfo {
}
static bool isEqual(const Instruction *LHS, const Instruction *RHS) {
if (LHS == getEmptyKey() || RHS == getEmptyKey())
return LHS == RHS;
return LHS->isIdenticalTo(RHS);
}
};

View file

@ -6463,12 +6463,6 @@ private:
/// A DenseMapInfo implementation for holding DenseMaps and DenseSets of
/// sorted SmallVectors of unsigned.
struct OrdersTypeDenseMapInfo {
static OrdersType getEmptyKey() {
OrdersType V;
V.push_back(~1U);
return V;
}
static unsigned getHashValue(const OrdersType &V) {
return static_cast<unsigned>(hash_combine_range(V));
}
@ -6523,11 +6517,6 @@ private:
template <> struct llvm::DenseMapInfo<BoUpSLP::EdgeInfo> {
using FirstInfo = DenseMapInfo<BoUpSLP::TreeEntry *>;
using SecondInfo = DenseMapInfo<unsigned>;
static BoUpSLP::EdgeInfo getEmptyKey() {
return BoUpSLP::EdgeInfo(FirstInfo::getEmptyKey(),
SecondInfo::getEmptyKey());
}
static unsigned getHashValue(const BoUpSLP::EdgeInfo &Val) {
return detail::combineHashValue(FirstInfo::getHashValue(Val.UserTE),
SecondInfo::getHashValue(Val.EdgeIdx));

View file

@ -2409,10 +2409,6 @@ void VPlanTransforms::clearReductionWrapFlags(VPlan &Plan) {
namespace {
struct VPCSEDenseMapInfo : public DenseMapInfo<VPSingleDefRecipe *> {
static bool isSentinel(const VPSingleDefRecipe *Def) {
return Def == getEmptyKey();
}
/// If recipe \p R will lower to a GEP with a non-i8 source element type,
/// return that source element type.
static Type *getGEPSourceElementType(const VPSingleDefRecipe *R) {
@ -2465,8 +2461,6 @@ struct VPCSEDenseMapInfo : public DenseMapInfo<VPSingleDefRecipe *> {
/// Check equality of underlying data of \p L and \p R.
static bool isEqual(const VPSingleDefRecipe *L, const VPSingleDefRecipe *R) {
if (isSentinel(L) || isSentinel(R))
return L == R;
if (L->getVPRecipeID() != R->getVPRecipeID() ||
getOpcodeOrIntrinsicID(L) != getOpcodeOrIntrinsicID(R) ||
getGEPSourceElementType(L) != getGEPSourceElementType(R) ||