MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
clos_conv_prep.h
Go to the documentation of this file.
1#pragma once
2
3#include <mim/phase.h>
4
6
8
9/// Wraps operands with the `clos.anno` annotations (returning, free_bb, fstclass_bb, ...) and eta-expands
10/// branches and continuations so that ClosConv sees a canonical program.
11class ClosConvPrep : public RWPhase {
12public:
13 using RWPhase::RWPhase;
14
15private:
16 /// Fills lam2fscope_: assigns each basicblock Lam to its enclosing returning Lam.
17 bool analyze() final;
18 const Def* rewrite_imm_App(const App*) final;
19
20 const Def* rewrite_arg(const App* app, const Def* old_op, size_t i, size_t n);
21 const Def* rewrite_callee_op(const Def* old_op);
22
23 Lam* scope(Lam* lam) { return lam2fscope_[lam]; }
24
25 bool from_outer_scope(Lam* lam) {
26 auto mut = curr_mut() ? curr_mut()->isa_mut<Lam>() : nullptr;
27 return mut && scope(lam) && scope(lam) != scope(mut);
28 }
29
30 const Def* eta_wrap(const Def* old_op, anno a);
31
32 DefMap<Lam*> old2wrapper_;
33 Lam2Lam lam2fscope_;
34 bool analyzed_ = false;
35};
36
37} // namespace mim::plug::clos::phase
Base class for all Defs.
Definition def.h:289
A function.
Definition lam.h:91
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition phase.h:334
D * curr_mut() const
Definition rewrite.h:98
Wraps operands with the clos.anno annotations (returning, free_bb, fstclass_bb, .....
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition phase.h:334
const Def * rewrite_imm_App(const App *) final
bool analyze() final
Fills lam2fscope_: assigns each basicblock Lam to its enclosing returning Lam.
GIDMap< const Def *, To > DefMap
Definition def.h:93
LamMap< Lam * > Lam2Lam
Definition lam.h:212