MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
static_arg_opt.h
Go to the documentation of this file.
1#pragma once
2
3#include <fe/bitset.h>
4
5#include "mim/phase.h"
6
7namespace mim {
8
9/// Static Argument Transformation.
10/// A recursive Lam whose self-calls merely forward some of its params is split into a wrapper `wrap`
11/// (same signature) and a `loop` that drops those params;
12/// self-calls forwarding all of them become jumps to `loop`, all others go through `wrap`.
13/// Tail recursion elimination is the special case where the dropped param is the ret var.
14/// @see [Compilation by Transformation in Non-Strict Functional Languages,
15/// ยง7](https://theses.gla.ac.uk/74568/1/10992188.pdf)
16class StaticArgOpt : public RWPhase {
17public:
20
21private:
22 bool analyze() final;
23 void analyze(const Def*);
24 void visit(const App*, Lam*);
25
26 const Def* rewrite_imm_App(const App*) final;
27 const Def* rewrite_mut_Lam(Lam*) final;
28
29 /// Which of @p lam's doms do the self-calls selected for the loop forward unchanged?
30 /// An empty Mask means: leave @p lam alone.
31 fe::Bitset statics(Lam* lam);
32
33 DefSet analyzed_;
34 LamMap<fe::Vector<fe::Bitset>> lam2sites_;
35 LamMap<fe::Bitset> lam2statics_;
36 LamMap<std::pair<Lam*, Lam*>> old2wrap_loop_;
37};
38
39} // namespace mim
Base class for all Defs.
Definition def.h:273
A function.
Definition lam.h:113
flags_t annex() const
Definition phase.h:81
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition phase.h:431
World & world()=delete
Hides both and forbids direct access.
StaticArgOpt(World &world, flags_t annex)
const Def * rewrite_mut_Lam(Lam *) final
bool analyze() final
Runs the optional pre-analysis on Phase::world, typically to a fixed point, before rewriting begins.
const Def * rewrite_imm_App(const App *) final
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition world.h:40
Definition ast.h:16
u64 flags_t
Definition types.h:39
GIDMap< Lam *, To > LamMap
Definition lam.h:219
GIDSet< const Def * > DefSet
Definition def.h:89