MimIR
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:
10
11private:
12 enum Lattice : u8 { Bot, Single, Eta };
13
14 static Lattice join(Lattice l1, Lattice l2) {
15 if (l1 == Bot) return l2;
16 if (l2 == Bot) return l1;
17 return Eta;
18 }
19
20 void join(const Def* def, Lattice l) {
21 if (auto [i, ins] = def2lattice_.emplace(def, l); !ins) i->second = join(i->second, l);
22 }
23
24 Lattice lattice(const Def* def) {
25 if (auto l = fe::lookup(def2lattice_, def)) return *l;
26 return Bot;
27 }
28
29 bool analyze() final;
30 void analyze(const Def*);
31 void visit(const Def*, Lattice = Eta);
32
33 const Def* rewrite(const Def*) final;
34 const Def* rewrite_mut_Lam(Lam*) final;
35 const Def* rewrite_no_eta(const Def* old_def) { return RWPhase::rewrite(old_def); }
36
37 DefSet analyzed_;
38 DefMap<Lattice> def2lattice_;
39 DefMap<const Def*> def2eta_;
40 VarMap<const Def*> var2def_; // vars that contain a ret_var
41 LamSet split_;
42};
43
44} // namespace mim
Base class for all Defs.
Definition def.h:289
A function.
Definition lam.h:91
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition phase.h:334
const Def * rewrite_mut_Lam(Lam *) final
Definition ret_wrap.cpp:60
bool analyze() final
Runs the optional pre-analysis on old_world(), typically to a fixed point, before rewriting begins.
Definition ret_wrap.cpp:5
const Def * rewrite(const Def *) final
Definition ret_wrap.cpp:50
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition phase.h:334
virtual const Def * rewrite(const Def *)
Definition rewrite.cpp:62
Definition ast.h:16
GIDSet< Lam * > LamSet
Definition lam.h:211
GIDMap< const Var *, To > VarMap
Definition def.h:114
GIDMap< const Def *, To > DefMap
Definition def.h:93
GIDSet< const Def * > DefSet
Definition def.h:94
uint8_t u8
Definition types.h:27