MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
eta_red.h
Go to the documentation of this file.
1#pragma once
2
3#include "mim/pass.h"
4
5namespace mim {
6
7/// Performs η-reduction.
8/// Rewrites `λx.e x` to `e`, whenever `x` does (optimistically) not appear free in `e`.
9class EtaRed : public FPPass<EtaRed, Def> {
10public:
13
14 void apply(bool callee_only);
15 void apply(const App* app) final { apply(Lit::as<bool>(app->arg())); }
16 void apply(Stage& s) final { apply(static_cast<EtaRed&>(s).callee_only()); }
17
18 bool callee_only() const { return callee_only_; }
19
20 enum Lattice {
21 Bot, ///< Never seen.
22 Reduce, ///< η-reduction performed.
23 Irreducible, ///< η-reduction not possible as we stumbled upon a Var.
24 };
25
27 void mark_irreducible(Lam* lam) { irreducible_.emplace(lam); }
28
29private:
30 const Def* rewrite(const Def*) override;
31 undo_t analyze(const Var*) override;
32
33 LamSet irreducible_;
34 bool callee_only_;
35};
36
37} // namespace mim
Base class for all Defs.
Definition def.h:251
void apply(Stage &s) final
Dito, but invoked by Stage::recreate.
Definition eta_red.h:16
LamMap< Lattice > Data
Definition eta_red.h:26
@ Irreducible
η-reduction not possible as we stumbled upon a Var.
Definition eta_red.h:23
@ Reduce
η-reduction performed.
Definition eta_red.h:22
@ Bot
Never seen.
Definition eta_red.h:21
void apply(const App *app) final
Invoked if your Stage has additional args.
Definition eta_red.h:15
void mark_irreducible(Lam *lam)
Definition eta_red.h:27
bool callee_only() const
Definition eta_red.h:18
void apply(bool callee_only)
Definition eta_red.cpp:12
const Def * rewrite(const Def *) override
Definition eta_red.cpp:17
EtaRed(World &world, flags_t annex)
Definition eta_red.h:11
undo_t analyze(const Var *) override
Definition eta_red.cpp:33
FPPass(World &world, std::string name)
Definition pass.h:323
A function.
Definition lam.h:111
static T as(const Def *def)
Definition def.h:830
Common base for Phase and Pass.
Definition pass.h:26
World & world()
Definition pass.h:64
flags_t annex() const
Definition pass.h:68
A variable introduced by a binder (mutable).
Definition def.h:700
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition world.h:32
Definition ast.h:14
GIDSet< Lam * > LamSet
Definition lam.h:221
u64 flags_t
Definition types.h:45
GIDMap< Lam *, To > LamMap
Definition lam.h:220
size_t undo_t
Definition pass.h:21