diff options
author | Bruce He <44327446+zm2he@users.noreply.github.com> | 2023-08-03 17:45:27 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-03 13:45:27 -0400 |
commit | bcdfa72afe41746ac13d27e6d02866c7d11e7fb5 (patch) | |
tree | 0df76ff435ce39e291bd93914eb9afdaccba6a38 /src/analysis/lattice.h | |
parent | 8bd418cc44705f1c272bbbe1ad65186dcd5b0fa9 (diff) | |
download | binaryen-bcdfa72afe41746ac13d27e6d02866c7d11e7fb5.tar.gz binaryen-bcdfa72afe41746ac13d27e6d02866c7d11e7fb5.tar.bz2 binaryen-bcdfa72afe41746ac13d27e6d02866c7d11e7fb5.zip |
Lattice to model Stack (#5849)
This change introduces StackLattice, a lattice to model stack-related
behavior. It is templated on a separate lattice whose elements model
some property of individual values on the stack. The StackLattice
allows users to access the top of the stack, push abstract values, and
pop them. Comparisons and least upper bound operations are done on a
value by value basis starting from the top of the stack and moving
toward the bottom. This is because it allows stacks from different
scopes to be joined easily.
An application of StackLattice is to model the wasm value stack. The goal
is to organize lattice elements representing individual stack values in a
natural way which mirrors the wasm value stack. Transfer functions operate
on each stack value individually. The stack lattice is an intermediate
structure which is not intended to be directly operated on. Rather, it
simulates the push and pop behavior of instructions.
Diffstat (limited to 'src/analysis/lattice.h')
-rw-r--r-- | src/analysis/lattice.h | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/analysis/lattice.h b/src/analysis/lattice.h index cd634c09c..1f2669c89 100644 --- a/src/analysis/lattice.h +++ b/src/analysis/lattice.h @@ -43,10 +43,10 @@ constexpr bool has_makeLeastUpperBound = const Element&>::value; template<typename Element> constexpr bool has_isTop = - std::is_invocable_r<bool, decltype(&Element::isTop), Element>::value; + std::is_invocable_r<bool, decltype(&Element::isTop), const Element>::value; template<typename Element> constexpr bool has_isBottom = - std::is_invocable_r<bool, decltype(&Element::isBottom), Element>::value; + std::is_invocable_r<bool, decltype(&Element::isBottom), const Element>::value; template<typename Lattice> constexpr bool is_lattice = has_getBottom<Lattice>&& has_compare<Lattice>&& @@ -82,7 +82,7 @@ public: public: Element(Element&& source) = default; - Element(Element& source) = default; + Element(const Element& source) = default; Element& operator=(Element&& source) = default; Element& operator=(const Element& source) = default; @@ -90,13 +90,13 @@ public: // Counts the number of members present the element itself. For instance, if // we had {true, false, true}, the count would be 2. O(N) operation which // iterates through the bitvector. - size_t count(); + size_t count() const; bool get(size_t index) { return bitvector[index]; } void set(size_t index, bool value) { bitvector[index] = value; } - bool isTop() { return count() == bitvector.size(); } - bool isBottom() { return count() == 0; } + bool isTop() const { return count() == bitvector.size(); } + bool isBottom() const { return count() == 0; } // Calculates the LUB of this element with some other element and sets // this element to the LUB in place. Returns true if this element before |