MimIR
0.5-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
using
RWPhase::RWPhase
;
16
17
private
:
18
const
Def
*
rewrite
(
const
Def
*)
final
;
19
const
Def
*
rewrite_mut_Lam
(
Lam
*)
final
;
20
21
/// Restructures the rewritten @p filter and @p body of @p lam if @p body passes exception closures.
22
std::pair<const Def*, const Def*> convert(
Lam
* lam,
const
Def
* filter,
const
Def
* body);
23
24
const
Def
* void_ptr() {
return
new_world
().
annex
<
clos::BufPtr
>(); }
25
const
Def
* jb_type() {
return
void_ptr(); }
26
const
Def
* rb_type() {
return
new_world
().
call
<
mem::Ptr0
>(void_ptr()); }
27
const
Def
* tag_type() {
return
new_world
().
type_i32
(); }
28
29
Lam
* get_throw(
const
Def
* res_type);
30
Lam
* get_lpad(
Lam
* lam,
const
Def
* rb);
31
32
void
get_exn_closures(
const
Def
* body);
33
void
get_exn_closures(
const
Def
* def,
DefSet
& visited);
34
35
/// Substitutes closure literals of tagged exception Lam%s by throw closures; does not descend into mutables.
36
const
Def
* subst_exn_closures(
const
Def
* def);
37
38
// clang-format off
39
LamMap<std::pair<int, const Def*>
> lam2tag_;
40
DefMap<Lam*>
dom2throw_;
41
DefMap<Lam*>
lam2lpad_;
42
LamSet
ignore_;
43
// clang-format on
44
45
const
Def
* cur_rbuf_ =
nullptr
;
46
const
Def
* cur_jbuf_ =
nullptr
;
47
};
48
49
}
// namespace mim::plug::clos::phase
mim::Def
Base class for all Defs.
Definition
def.h:289
mim::Lam
A function.
Definition
lam.h:91
mim::RWPhase::new_world
World & new_world()
Create new Defs into this.
Definition
phase.h:379
mim::RWPhase::RWPhase
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition
phase.h:334
mim::World::call
const Def * call(const Def *callee, auto &&arg, Args &&... args)
Definition
world.h:674
mim::World::annex
const Def * annex(Sym sym)
Lookup annex by Sym.
Definition
world.cpp:160
mim::World::type_i32
const Def * type_i32()
Definition
world.h:637
mim::plug::clos::phase::Clos2SJLJ
Lowers basicblock closures that are passed as arguments (i.e.
Definition
clos2sjlj.h:13
mim::plug::clos::phase::Clos2SJLJ::rewrite
const Def * rewrite(const Def *) final
Definition
clos2sjlj.cpp:179
mim::plug::clos::phase::Clos2SJLJ::rewrite_mut_Lam
const Def * rewrite_mut_Lam(Lam *) final
Definition
clos2sjlj.cpp:196
mim::plug::clos::phase::Clos2SJLJ::RWPhase
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition
phase.h:334
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:19
mim::LamSet
GIDSet< Lam * > LamSet
Definition
lam.h:211
mim::DefMap
GIDMap< const Def *, To > DefMap
Definition
def.h:93
mim::LamMap
GIDMap< Lam *, To > LamMap
Definition
lam.h:210
mim::DefSet
GIDSet< const Def * > DefSet
Definition
def.h:94
phase.h
include
mim
plug
clos
phase
clos2sjlj.h
Generated by
1.18.0