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:
18 using RWPhase::RWPhase;
19
20private:
21 bool analyze() final;
22 void analyze(const Def*);
23 void visit(const App*, Lam*);
24
25 const Def* rewrite_imm_App(const App*) final;
26 const Def* rewrite_mut_Lam(Lam*) final;
27
28 /// Which of @p lam's doms does the loop keep - those the selected self-calls do *not* forward unchanged?
29 /// A Sieve that keeps *all* of them means: leave @p lam alone.
30 Sieve sieve(Lam* lam);
31
32 DefSet analyzed_;
34 LamMap<Sieve> lam2sieve_;
35 Lam2Lam old2loop_;
36};
37
38} // namespace mim
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
Filters the components of an aggregate and keeps track of where the survivors end up.
Definition tuple.h:116
Static Argument Transformation.
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition phase.h:334
const Def * rewrite_mut_Lam(Lam *) final
bool analyze() final
Runs the optional pre-analysis on old_world(), typically to a fixed point, before rewriting begins.
const Def * rewrite_imm_App(const App *) final
Definition ast.h:16
LamMap< Lam * > Lam2Lam
Definition lam.h:212
GIDMap< Lam *, To > LamMap
Definition lam.h:210
GIDSet< const Def * > DefSet
Definition def.h:94