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:
15 using RWPhase::RWPhase;
16
17private:
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
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
Base class for all Defs.
Definition def.h:289
A function.
Definition lam.h:91
World & new_world()
Create new Defs into this.
Definition phase.h:379
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition phase.h:334
const Def * call(const Def *callee, auto &&arg, Args &&... args)
Definition world.h:674
const Def * annex(Sym sym)
Lookup annex by Sym.
Definition world.cpp:160
const Def * type_i32()
Definition world.h:637
Lowers basicblock closures that are passed as arguments (i.e.
Definition clos2sjlj.h:13
const Def * rewrite(const Def *) final
const Def * rewrite_mut_Lam(Lam *) final
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition phase.h:334
GIDSet< Lam * > LamSet
Definition lam.h:211
GIDMap< const Def *, To > DefMap
Definition def.h:93
GIDMap< Lam *, To > LamMap
Definition lam.h:210
GIDSet< const Def * > DefSet
Definition def.h:94