MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
tail_rec_elim.h
Go to the documentation of this file.
1#pragma once
2
3#include "mim/phase.h"
4
5namespace mim {
6
7/// Eliminates tail recursion:
8/// A returning Lam `f` that calls itself with its own ret var as continuation is split into
9/// a wrapper `rec` (same signature) and a `loop` basic block (signature without the ret var);
10/// the recursive call becomes a jump to `loop`.
11class TailRecElim : public RWPhase {
12public:
15
16private:
17 const Def* rewrite_imm_App(const App*) final;
18 const Def* rewrite_mut_Lam(Lam*) final;
19
20 /// Does @p lam call itself in tail position (with its own ret var as continuation)?
21 bool is_tail_rec(Lam* lam);
22
23 LamMap<bool> tail_rec_;
24 LamMap<std::pair<Lam*, Lam*>> old2rec_loop_;
25};
26
27} // namespace mim
Base class for all Defs.
Definition def.h:261
A function.
Definition lam.h:110
flags_t annex() const
Definition phase.h:81
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition phase.h:316
World & world()=delete
Hides both and forbids direct access.
const Def * rewrite_mut_Lam(Lam *) final
const Def * rewrite_imm_App(const App *) final
TailRecElim(World &world, flags_t annex)
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition world.h:36
Definition ast.h:14
u64 flags_t
Definition types.h:39
GIDMap< Lam *, To > LamMap
Definition lam.h:219