================ @@ -13804,3 +13807,78 @@ StringRef ASTContext::getCUIDHash() const { CUIDHash = llvm::utohexstr(llvm::MD5Hash(LangOpts.CUID), /*LowerCase=*/true); return CUIDHash; } + +using FunctionEffectSpan = llvm::ArrayRef<FunctionEffect>; + +llvm::hash_code hash_value(const FunctionEffect &Effect) { + return llvm::hash_value(Effect.opaqueRepr()); +} + +namespace llvm { +template <> struct DenseMapInfo<FunctionEffectSpan> { + static FunctionEffectSpan getEmptyKey() { + return {static_cast<const FunctionEffect *>(nullptr), size_t(0)}; + } + static FunctionEffectSpan getTombstoneKey() { + return {reinterpret_cast<const FunctionEffect *>(intptr_t(-1)), size_t(0)}; + } + static unsigned getHashValue(const FunctionEffectSpan &Val) { + hash_code hash1 = hash_value(Val.size()); + // Treat the FunctionEffects as a span of integers + const FunctionEffect *Begin = Val.begin(); + const FunctionEffect *End = Val.end(); + hash_code hash2 = + hash_combine_range(reinterpret_cast<const uint32_t *>(Begin), + reinterpret_cast<const uint32_t *>(End)); + return hash_combine(hash1, hash2); + } + static bool isEqual(const FunctionEffectSpan &LHS, + const FunctionEffectSpan &RHS) { + if (LHS.size() != RHS.size()) { + return false; + } + // distinguish empty from tombstone + if (LHS.size() == 0) { + return LHS.data() == RHS.data(); + } + return std::equal(LHS.begin(), LHS.end(), RHS.begin()); + } +}; +} // namespace llvm + +FunctionEffectSet +ASTContext::getUniquedFunctionEffectSet(llvm::ArrayRef<uint32_t> FX) { + static_assert(sizeof(FunctionEffect) == sizeof(uint32_t)); + const auto *ptr = reinterpret_cast<const FunctionEffect *>(FX.data()); + return UniquedFunctionEffectSet.getUniqued({ptr, FX.size()}); ---------------- Sirraide wrote:
I think this is technically *fine* assuming that the pointer in the `ArrayRef` started out as a `FunctionEffect*`, but it’s still quite the hack imo. https://github.com/llvm/llvm-project/pull/84983 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits