MimIR
0.4-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
ret_wrap.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
mim/phase.h
"
4
5
namespace
mim
{
6
7
class
RetWrap
:
public
RWPhase
{
8
public
:
9
RetWrap
(
World
&
world
,
flags_t
annex
)
10
:
RWPhase
(
world
,
annex
) {}
11
12
private
:
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
RWPhase::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
mim::Phase::annex
flags_t annex() const
Definition
phase.h:81
mim::RWPhase::RWPhase
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition
phase.h:431
mim::RWPhase::world
World & world()=delete
Hides both and forbids direct access.
mim::RetWrap::rewrite_mut_Lam
const Def * rewrite_mut_Lam(Lam *) final
Definition
ret_wrap.cpp:60
mim::RetWrap::analyze
bool analyze() final
Runs the optional pre-analysis on Phase::world, typically to a fixed point, before rewriting begins.
Definition
ret_wrap.cpp:5
mim::RetWrap::rewrite
const Def * rewrite(const Def *) final
Definition
ret_wrap.cpp:50
mim::RetWrap::RetWrap
RetWrap(World &world, flags_t annex)
Definition
ret_wrap.h:9
mim::Rewriter::rewrite
virtual const Def * rewrite(const Def *)
Definition
rewrite.cpp:55
mim::World
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition
world.h:40
mim
Definition
ast.h:16
mim::LamSet
GIDSet< Lam * > LamSet
Definition
lam.h:220
mim::flags_t
u64 flags_t
Definition
types.h:39
mim::VarMap
GIDMap< const Var *, To > VarMap
Definition
def.h:110
mim::DefSet
GIDSet< const Def * > DefSet
Definition
def.h:89
mim::Bot
TExt< false > Bot
Definition
lattice.h:164
mim::u8
uint8_t u8
Definition
types.h:27
phase.h
include
mim
phase
ret_wrap.h
Generated by
1.18.0