summaryrefslogtreecommitdiff
path: root/src/analysis/lattices/int.h
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2023-10-25 21:30:31 +0200
committerGitHub <noreply@github.com>2023-10-25 21:30:31 +0200
commit6ba0f3d282714fa60be2634fbdf48a8ab5a3997d (patch)
tree45d873c2a38a9e50641254628a59b15d068f49ba /src/analysis/lattices/int.h
parenta09ea699d69ed54741d95b9b5fa2247bdcf28152 (diff)
downloadbinaryen-6ba0f3d282714fa60be2634fbdf48a8ab5a3997d.tar.gz
binaryen-6ba0f3d282714fa60be2634fbdf48a8ab5a3997d.tar.bz2
binaryen-6ba0f3d282714fa60be2634fbdf48a8ab5a3997d.zip
[analysis] Add a FullLattice concept and Inverted lattice (#6038)
The FullLattice concept extends the base Lattice with `getTop` and `meet` operations. The `Inverted` lattice uses these operations to reverse the order of an arbitrary full lattice, for example to create a lattice of integers ordered by `>` rather than by `<`.
Diffstat (limited to 'src/analysis/lattices/int.h')
-rw-r--r--src/analysis/lattices/int.h16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/analysis/lattices/int.h b/src/analysis/lattices/int.h
index a2cd37c1e..682ac1063 100644
--- a/src/analysis/lattices/int.h
+++ b/src/analysis/lattices/int.h
@@ -34,6 +34,7 @@ template<typename T>
struct Integer {
using Element = T;
Element getBottom() const noexcept { return std::numeric_limits<T>::min(); }
+ Element getTop() const noexcept { return std::numeric_limits<T>::max(); }
LatticeComparison compare(Element a, Element b) const noexcept {
return a > b ? GREATER : a == b ? EQUAL : LESS;
}
@@ -44,6 +45,13 @@ struct Integer {
}
return false;
}
+ bool meet(Element& self, Element other) const noexcept {
+ if (self > other) {
+ self = other;
+ return true;
+ }
+ return false;
+ }
};
using Int32 = Integer<int32_t>;
@@ -52,10 +60,10 @@ using Int64 = Integer<int64_t>;
using UInt64 = Integer<uint64_t>;
#if __cplusplus >= 202002L
-static_assert(Lattice<Int32>);
-static_assert(Lattice<Int64>);
-static_assert(Lattice<UInt32>);
-static_assert(Lattice<UInt64>);
+static_assert(FullLattice<Int32>);
+static_assert(FullLattice<Int64>);
+static_assert(FullLattice<UInt32>);
+static_assert(FullLattice<UInt64>);
#endif // __cplusplus >= 202002L
} // namespace wasm::analysis