MimIR
0.4-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
clos2sjlj.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <
mim/phase.h
>
4
5
#include <
mim/plug/mem/mem.h
>
6
7
#include "
mim/plug/clos/clos.h
"
8
9
namespace
mim::plug::clos::phase
{
10
11
/// Lowers basicblock closures that are passed as arguments (i.e. exception continuations)
12
/// to setjmp/longjmp: the caller setjmps and dispatches on the tag, the closures become longjmps.
13
class
Clos2SJLJ
:
public
RWPhase
{
14
public
:
15
Clos2SJLJ
(
World
&
world
,
flags_t
annex
)
16
:
RWPhase
(
world
,
annex
) {}
17
18
private
:
19
const
Def
*
rewrite
(
const
Def
*)
final
;
20
const
Def
*
rewrite_mut_Lam
(
Lam
*)
final
;
21
22
/// Restructures the (already rewritten, new-world) @p lam if its body passes exception closures.
23
void
convert(
Lam
* lam);
24
25
const
Def
* void_ptr() {
return
new_world
().
annex
<
clos::BufPtr
>(); }
26
const
Def
* jb_type() {
return
void_ptr(); }
27
const
Def
* rb_type() {
return
new_world
().
call
<
mem::Ptr0
>(void_ptr()); }
28
const
Def
* tag_type() {
return
new_world
().
type_i32
(); }
29
30
Lam* get_throw(
const
Def* res_type);
31
Lam* get_lpad(Lam* lam,
const
Def* rb);
32
33
void
get_exn_closures(Lam* lam);
34
void
get_exn_closures(
const
Def* def,
DefSet
& visited);
35
36
/// Substitutes closure literals of tagged exception Lam%s by throw closures; does not descend into mutables.
37
const
Def* subst_exn_closures(
const
Def* def);
38
39
// clang-format off
40
LamMap<std::pair<int, const Def*>
> lam2tag_;
41
DefMap<Lam*>
dom2throw_;
42
DefMap<Lam*>
lam2lpad_;
43
LamSet
ignore_;
44
// clang-format on
45
46
const
Def* cur_rbuf_ =
nullptr
;
47
const
Def* cur_jbuf_ =
nullptr
;
48
};
49
50
}
// namespace mim::plug::clos::phase
mim::Def
Base class for all Defs.
Definition
def.h:273
mim::Lam
A function.
Definition
lam.h:113
mim::Phase::annex
flags_t annex() const
Definition
phase.h:81
mim::RWPhase::new_world
World & new_world()
Create new Defs into this.
Definition
phase.h:452
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::World
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition
world.h:40
mim::World::annex
const Def * annex(Sym sym)
Lookup annex by Sym.
Definition
world.h:294
mim::World::call
const Def * call(const Def *callee, T &&arg, Args &&... args)
Definition
world.h:662
mim::World::type_i32
const Def * type_i32()
Definition
world.h:633
mim::plug::clos::phase::Clos2SJLJ::rewrite
const Def * rewrite(const Def *) final
Definition
clos2sjlj.cpp:178
mim::plug::clos::phase::Clos2SJLJ::Clos2SJLJ
Clos2SJLJ(World &world, flags_t annex)
Definition
clos2sjlj.h:15
mim::plug::clos::phase::Clos2SJLJ::rewrite_mut_Lam
const Def * rewrite_mut_Lam(Lam *) final
Definition
clos2sjlj.cpp:195
clos.h
mem.h
mim::plug::clos::phase
Definition
branch_clos_elim.h:5
mim::plug::clos::BufPtr
BufPtr
Definition
autogen.h:14
mim::plug::mem::Ptr0
Ptr0
Definition
autogen.h:28
mim::LamSet
GIDSet< Lam * > LamSet
Definition
lam.h:220
mim::flags_t
u64 flags_t
Definition
types.h:39
mim::DefMap
GIDMap< const Def *, To > DefMap
Definition
def.h:88
mim::LamMap
GIDMap< Lam *, To > LamMap
Definition
lam.h:219
mim::DefSet
GIDSet< const Def * > DefSet
Definition
def.h:89
phase.h
include
mim
plug
clos
phase
clos2sjlj.h
Generated by
1.18.0