MimIR
MimIR is my Intermediate Representation
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
8
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.
13class Clos2SJLJ : public RWPhase {
14public:
17
18private:
19 const Def* rewrite_mut_Lam(Lam*) final;
20
21 /// Restructures the (already rewritten, new-world) @p lam if its body passes exception closures.
22 void convert(Lam* lam);
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(Lam* lam);
33 void get_exn_closures(const Def* def, DefSet& visited);
34 const Def* subst_exn_closures(const Def* def, Def2Def& memo);
35
36 // clang-format off
38 DefMap<Lam*> dom2throw_;
39 DefMap<Lam*> lam2lpad_;
40 LamSet ignore_;
41 // clang-format on
42
43 const Def* cur_rbuf_ = nullptr;
44 const Def* cur_jbuf_ = nullptr;
45};
46
47} // namespace mim::plug::clos::phase
Base class for all Defs.
Definition def.h:261
A function.
Definition lam.h:110
flags_t annex() const
Definition phase.h:81
World & new_world()
Create new Defs into this.
Definition phase.h:368
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition phase.h:316
World & world()=delete
Hides both and forbids direct access.
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition world.h:36
const Def * annex(Sym sym)
Lookup annex by Sym.
Definition world.h:280
const Def * call(const Def *callee, T &&arg, Args &&... args)
Definition world.h:641
const Def * type_i32()
Definition world.h:611
Clos2SJLJ(World &world, flags_t annex)
Definition clos2sjlj.h:15
const Def * rewrite_mut_Lam(Lam *) final
DefMap< const Def * > Def2Def
Definition def.h:77
GIDSet< Lam * > LamSet
Definition lam.h:220
u64 flags_t
Definition types.h:39
GIDMap< const Def *, To > DefMap
Definition def.h:75
GIDMap< Lam *, To > LamMap
Definition lam.h:219
GIDSet< const Def * > DefSet
Definition def.h:76
@ Lam
Definition def.h:109