MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
eta_exp_phase.h
Go to the documentation of this file.
1#pragma once
2
3#include "mim/phase/phase.h"
4#include "mim/util/util.h"
5
6namespace mim {
7
8/// Inlines in post-order all Lam%s that occur exactly *once* in the program.
9class EtaExpPhase : public FPPhase {
10public:
12
13private:
14 enum Lattice : u8 {
15 None = 0,
16 Known = 1 << 0,
17 Unknown = 1 << 1,
18 Both = Known | Unknown,
19 };
20
21 static void join(Lattice& l1, Lattice l2) { l1 = (Lattice)((u8)l1 | (u8)l2); }
22
23 void join(const Lam* lam, Lattice l) {
24 if (auto [i, ins] = lam2lattice_.emplace(lam, l); !ins) join(i->second, l);
25 }
26
27 Lattice lattice(const Lam* lam) {
28 if (auto i = lam2lattice_.find(lam); i != lam2lattice_.end()) return i->second;
29 return None;
30 }
31
32 void reset() final;
33
34 bool analyze() final;
35 void analyze(const Def*);
36
37 void rewrite_external(Def*) final;
38 const Def* rewrite_no_eta(const Def*);
39 const Def* rewrite(const Def*);
40 const Def* rewrite_imm_App(const App*) final;
41 const Def* rewrite_imm_Var(const Var*) final;
42
43 DefSet analyzed_;
44 GIDMap<const Lam*, Lattice> lam2lattice_;
46};
47
48} // namespace mim
Base class for all Defs.
Definition def.h:251
const Def * rewrite_imm_Var(const Var *) final
const Def * rewrite_imm_App(const App *) final
void reset() final
void rewrite_external(Def *) final
bool analyze() final
FPPhase(World &world, std::string name)
Definition phase.h:121
A function.
Definition lam.h:109
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition world.h:36
Definition ast.h:14
absl::flat_hash_map< K, V, GIDHash< K > > GIDMap
Definition util.h:187
GIDSet< const Def * > DefSet
Definition def.h:74
uint8_t u8
Definition types.h:34