37 static Lattice join(Lattice l1, Lattice l2) {
38 if (l1 == Unknown_1 && l2 == Unknown_1)
return Unknown_N;
39 if (l1 == l2)
return l1;
40 if (l1 == None)
return l2;
41 if (l2 == None)
return l1;
42 if (l1 == Both || l2 == Both)
return Both;
43 if (l1 == Known && (l2 == Unknown_1 || l2 == Unknown_N))
return Both;
44 if (l2 == Known && (l1 == Unknown_1 || l1 == Unknown_N))
return Both;
45 if (l1 == Unknown_1 && l2 == Unknown_N)
return Unknown_N;
46 if (l2 == Unknown_1 && l1 == Unknown_N)
return Unknown_N;
50 Lattice lattice(
const Lam* lam) {
51 if (
auto i = lam2lattice_.find(lam); i != lam2lattice_.end())
return i->second;
55 static bool eta_expand(Lattice l) {
return l != Known &&
l != Unknown_1 &&
l != None; }
56 bool eta_expand(
const Lam* lam) {
return eta_expand(lattice(lam)); }
59 bool keep_wrapper(
const Def* f) {
60 auto lam =
f->isa<
Lam>();
61 return lam && eta_expand(lattice(lam));
64 void join(
const Lam* lam, Lattice l) {
65 if (
auto [i, ins] = lam2lattice_.emplace(lam, l); !ins) i->second = join(i->second, l);
70 void visit(const Def*, Lattice);
74 const Def*
rewrite(const Def*) final;
79 const Def* rewrite_no_exp(const Def* old_def);
80 const Def* rewrite_no_eta(const Def* old_def) {
return RWPhase::rewrite(old_def); }