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(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
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
Base class for all Defs.
Definition def.h:273
A function.
Definition lam.h:113
flags_t annex() const
Definition phase.h:81
World & new_world()
Create new Defs into this.
Definition phase.h:452
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition phase.h:431
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:40
const Def * annex(Sym sym)
Lookup annex by Sym.
Definition world.h:294
const Def * call(const Def *callee, T &&arg, Args &&... args)
Definition world.h:662
const Def * type_i32()
Definition world.h:633
const Def * rewrite(const Def *) final
Clos2SJLJ(World &world, flags_t annex)
Definition clos2sjlj.h:15
const Def * rewrite_mut_Lam(Lam *) final
GIDSet< Lam * > LamSet
Definition lam.h:220
u64 flags_t
Definition types.h:39
GIDMap< const Def *, To > DefMap
Definition def.h:88
GIDMap< Lam *, To > LamMap
Definition lam.h:219
GIDSet< const Def * > DefSet
Definition def.h:89