2828#include " analysis/lattices/inverted.h"
2929#include " analysis/lattices/lift.h"
3030#include " analysis/lattices/stack.h"
31+ #include " analysis/lattices/vector.h"
3132#include " analysis/liveness-transfer-function.h"
3233#include " analysis/reaching-definitions-transfer-function.h"
3334#include " analysis/transfer-function.h"
@@ -151,33 +152,38 @@ static_assert(Lattice<RandomLattice>);
151152using ArrayFullLattice = analysis::Array<RandomFullLattice, 2 >;
152153using ArrayLattice = analysis::Array<RandomLattice, 2 >;
153154
154- struct RandomFullLattice ::L
155- : std::variant<Bool, UInt32, Inverted<RandomFullLattice>, ArrayFullLattice> {
156- };
155+ struct RandomFullLattice ::L : std::variant<Bool,
156+ UInt32,
157+ Inverted<RandomFullLattice>,
158+ ArrayFullLattice,
159+ Vector<RandomFullLattice>> {};
157160
158161struct RandomFullLattice ::ElementImpl
159162 : std::variant<typename Bool::Element,
160163 typename UInt32::Element,
161164 typename Inverted<RandomFullLattice>::Element,
162- typename ArrayFullLattice::Element> {};
165+ typename ArrayFullLattice::Element,
166+ typename Vector<RandomFullLattice>::Element> {};
163167
164168struct RandomLattice ::L : std::variant<RandomFullLattice,
165169 Flat<uint32_t >,
166170 Lift<RandomLattice>,
167- ArrayLattice> {};
171+ ArrayLattice,
172+ Vector<RandomLattice>> {};
168173
169174struct RandomLattice ::ElementImpl
170175 : std::variant<typename RandomFullLattice::Element,
171176 typename Flat<uint32_t >::Element,
172177 typename Lift<RandomLattice>::Element,
173- typename ArrayLattice::Element> {};
178+ typename ArrayLattice::Element,
179+ typename Vector<RandomLattice>::Element> {};
174180
175181RandomFullLattice::RandomFullLattice (Random& rand,
176182 size_t depth,
177183 std::optional<uint32_t > maybePick)
178184 : rand(rand) {
179185 // TODO: Limit the depth once we get lattices with more fan-out.
180- uint32_t pick = maybePick ? *maybePick : rand.upTo (4 );
186+ uint32_t pick = maybePick ? *maybePick : rand.upTo (5 );
181187 switch (pick) {
182188 case 0 :
183189 lattice = std::make_unique<L>(L{Bool{}});
@@ -193,30 +199,39 @@ RandomFullLattice::RandomFullLattice(Random& rand,
193199 lattice = std::make_unique<L>(
194200 L{ArrayFullLattice{RandomFullLattice{rand, depth + 1 }}});
195201 return ;
202+ case 4 :
203+ lattice = std::make_unique<L>(
204+ L{Vector{RandomFullLattice{rand, depth + 1 }, rand.upTo (4 )}});
205+ return ;
196206 }
197207 WASM_UNREACHABLE (" unexpected pick" );
198208}
199209
200210RandomLattice::RandomLattice (Random& rand, size_t depth) : rand(rand) {
201211 // TODO: Limit the depth once we get lattices with more fan-out.
202- uint32_t pick = rand.upTo (7 );
212+ uint32_t pick = rand.upTo (9 );
203213 switch (pick) {
204214 case 0 :
205215 case 1 :
206216 case 2 :
207217 case 3 :
218+ case 4 :
208219 lattice = std::make_unique<L>(L{RandomFullLattice{rand, depth, pick}});
209220 return ;
210- case 4 :
221+ case 5 :
211222 lattice = std::make_unique<L>(L{Flat<uint32_t >{}});
212223 return ;
213- case 5 :
224+ case 6 :
214225 lattice = std::make_unique<L>(L{Lift{RandomLattice{rand, depth + 1 }}});
215226 return ;
216- case 6 :
227+ case 7 :
217228 lattice =
218229 std::make_unique<L>(L{ArrayLattice{RandomLattice{rand, depth + 1 }}});
219230 return ;
231+ case 8 :
232+ lattice = std::make_unique<L>(
233+ L{Vector{RandomLattice{rand, depth + 1 }, rand.upTo (4 )}});
234+ return ;
220235 }
221236 WASM_UNREACHABLE (" unexpected pick" );
222237}
@@ -235,6 +250,14 @@ RandomFullLattice::Element RandomFullLattice::makeElement() const noexcept {
235250 return ElementImpl{typename ArrayFullLattice::Element{
236251 l->lattice .makeElement (), l->lattice .makeElement ()}};
237252 }
253+ if (const auto * l = std::get_if<Vector<RandomFullLattice>>(lattice.get ())) {
254+ std::vector<typename RandomFullLattice::Element> elem;
255+ elem.reserve (l->size );
256+ for (size_t i = 0 ; i < l->size ; ++i) {
257+ elem.push_back (l->lattice .makeElement ());
258+ }
259+ return ElementImpl{std::move (elem)};
260+ }
238261 WASM_UNREACHABLE (" unexpected lattice" );
239262}
240263
@@ -261,6 +284,14 @@ RandomLattice::Element RandomLattice::makeElement() const noexcept {
261284 return ElementImpl{typename ArrayLattice::Element{
262285 l->lattice .makeElement (), l->lattice .makeElement ()}};
263286 }
287+ if (const auto * l = std::get_if<Vector<RandomLattice>>(lattice.get ())) {
288+ std::vector<typename RandomLattice::Element> elem;
289+ elem.reserve (l->size );
290+ for (size_t i = 0 ; i < l->size ; ++i) {
291+ elem.push_back (l->lattice .makeElement ());
292+ }
293+ return ElementImpl{std::move (elem)};
294+ }
264295 WASM_UNREACHABLE (" unexpected lattice" );
265296}
266297
@@ -293,6 +324,17 @@ void printFullElement(std::ostream& os,
293324 printFullElement (os, e->back (), depth + 1 );
294325 indent (os, depth);
295326 os << " ]\n " ;
327+ } else if (const auto * vec =
328+ std::get_if<typename Vector<RandomFullLattice>::Element>(
329+ &*elem)) {
330+ os << " Vector[\n " ;
331+ for (const auto & e : *vec) {
332+ printFullElement (os, e, depth + 1 );
333+ }
334+ indent (os, depth);
335+ os << " ]\n " ;
336+ } else {
337+ WASM_UNREACHABLE (" unexpected element" );
296338 }
297339}
298340
@@ -332,6 +374,16 @@ void printElement(std::ostream& os,
332374 printElement (os, e->back (), depth + 1 );
333375 indent (os, depth);
334376 os << " )\n " ;
377+ } else if (const auto * vec =
378+ std::get_if<typename Vector<RandomLattice>::Element>(&*elem)) {
379+ os << " Vector[\n " ;
380+ for (const auto & e : *vec) {
381+ printElement (os, e, depth + 1 );
382+ }
383+ indent (os, depth);
384+ os << " ]\n " ;
385+ } else {
386+ WASM_UNREACHABLE (" unexpected element" );
335387 }
336388}
337389
0 commit comments