MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
ret_wrap.h
Go to the documentation of this file.
1#pragma once
2
3#include "mim/phase.h"
4
5namespace mim {
6
7class RetWrap : public RWPhase {
8public:
11
12private:
13 enum Lattice : u8 { Bot, Single, Eta };
14
15 static Lattice join(Lattice l1, Lattice l2) {
16 if (l1 == Bot) return l2;
17 if (l2 == Bot) return l1;
18 return Eta;
19 }
20
21 void join(const Def* def, Lattice l) {
22 if (auto [i, ins] = def2lattice_.emplace(def, l); !ins) i->second = join(i->second, l);
23 }
24
25 Lattice lattice(const Def* def) {
26 if (auto i = def2lattice_.find(def); i != def2lattice_.end()) return i->second;
27 return Bot;
28 }
29
30 bool analyze() final;
31 void analyze(const Def*);
32 void visit(const Def*, Lattice = Eta);
33
34 const Def* rewrite(const Def*) final;
35 const Def* rewrite_mut_Lam(Lam*) final;
36 const Def* rewrite_no_eta(const Def* old_def) { return Rewriter::rewrite(old_def); }
37
38 DefSet analyzed_;
39 DefMap<Lattice> def2lattice_;
40 DefMap<const Def*> def2eta_;
41 VarMap<const Def*> var2def_; // vars that contain a ret_var
42 LamSet split_;
43};
44
45} // namespace mim
RWPhase(World &world, std::string name)
Definition phase.h:71
World & world()=delete
Hides both and forbids direct access.
const Def * rewrite_mut_Lam(Lam *) final
Definition ret_wrap.cpp:60
bool analyze() final
You can do an optional fixed-point loop on the RWPhase::old_world before rewriting.
Definition ret_wrap.cpp:5
const Def * rewrite(const Def *) final
Definition ret_wrap.cpp:50
RetWrap(World &world, flags_t annex)
Definition ret_wrap.h:9
virtual const Def * rewrite(const Def *)
Definition rewrite.cpp:14
flags_t annex() const
Definition pass.h:68
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition world.h:36
Definition ast.h:14
GIDSet< Lam * > LamSet
Definition lam.h:221
u64 flags_t
Definition types.h:45
GIDMap< const Var *, To > VarMap
Definition def.h:94
GIDSet< const Def * > DefSet
Definition def.h:74
TExt< false > Bot
Definition lattice.h:171
uint8_t u8
Definition types.h:34
@ Lam
Definition def.h:114