Skip to content

Commit 5257376

Browse files
committed
Auto hashing of ConstantEdgeFunction + EdgeFunctionComposer
1 parent a4f4cbc commit 5257376

3 files changed

Lines changed: 19 additions & 10 deletions

File tree

include/phasar/DataFlow/IfdsIde/EdgeFunctionUtils.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ operator<<(llvm::raw_ostream &OS, ByConstRef<ConstantEdgeFunction<L>> Id) {
9696
return OS;
9797
}
9898

99+
template <typename L>
100+
requires(is_std_hashable_v<typename NonTopBotValue<L>::type> ||
101+
is_llvm_hashable_v<typename NonTopBotValue<L>::type>)
102+
[[nodiscard]] auto hash_value(const ConstantEdgeFunction<L> &CEF) noexcept {
103+
using value_type = typename ConstantEdgeFunction<L>::value_type;
104+
if constexpr (is_std_hashable_v<value_type>) {
105+
return std::hash<value_type>{}(CEF.Value);
106+
} else {
107+
using llvm::hash_value;
108+
return hash_value(CEF.Value);
109+
}
110+
}
111+
99112
template <typename L> struct AllBottom final {
100113
using l_t = L;
101114
using JLattice = JoinLatticeTraits<L>;
@@ -278,6 +291,11 @@ template <typename L> struct EdgeFunctionComposer {
278291

279292
static_assert(HasDepth<EdgeFunctionComposer<int>>);
280293

294+
template <typename L>
295+
auto hash_value(const EdgeFunctionComposer<L> &EFC) noexcept {
296+
return llvm::hash_combine(EFC.First, EFC.Second);
297+
}
298+
281299
template <typename L, uint8_t N> struct JoinEdgeFunction {
282300
using l_t = L;
283301
using JLattice = JoinLatticeTraits<L>;

lib/DataFlow/IfdsIde/IfdsIde.cppm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ using psr::addSeedsForStartingPoints;
4646
using psr::AllTopFnProvider;
4747
using psr::checkSREquality;
4848
using psr::Compressor;
49-
using psr::ConstantEdgeFunction;
5049
using psr::defaultJoinOrNull;
5150
using psr::DefaultMapKeyCompressor;
5251
using psr::EdgeFunctionCache;

lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDELinearConstantAnalysis.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,9 @@ struct LCAEdgeFunctionComposer : EdgeFunctionComposer<l_t> {
6666
}
6767
};
6868

69-
auto hash_value(const LCAEdgeFunctionComposer &EF) noexcept {
70-
return llvm::hash_combine(EF.First, EF.Second);
71-
}
72-
7369
static_assert(is_llvm_hashable_v<LCAEdgeFunctionComposer>);
7470

75-
struct GenConstant : ConstantEdgeFunction<l_t> {};
76-
77-
llvm::hash_code hash_value(const GenConstant &EF) noexcept {
78-
return llvm::hash_value(EF.Value);
79-
}
71+
using GenConstant = ConstantEdgeFunction<l_t>;
8072

8173
using TTT = decltype(hash_value(std::declval<GenConstant>()));
8274
static_assert(is_llvm_hashable_v<GenConstant>);

0 commit comments

Comments
 (0)