Thorin 1.9.0
The Higher ORder INtermediate representation
Loading...
Searching...
No Matches
eta_red.h
Go to the documentation of this file.
1#pragma once
2
3#include "thorin/pass/pass.h"
4
5namespace thorin {
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:
11 EtaRed(PassMan& man, bool callee_only = false)
12 : FPPass(man, "eta_red")
13 , callee_only_(callee_only) {}
14
15 enum Lattice {
16 Bot, ///< Never seen.
17 Reduce, ///< η-reduction performed.
18 Irreducible, ///< η-reduction not possible as we stumbled upon a Var.
19 };
20
22 void mark_irreducible(Lam* lam) { irreducible_.emplace(lam); }
23
24private:
25 const bool callee_only_;
26 Ref rewrite(Ref) override;
27 undo_t analyze(const Var*) override;
28
29 LamSet irreducible_;
30};
31
32} // namespace thorin
Performs η-reduction.
Definition eta_red.h:9
undo_t analyze(const Var *) override
Definition eta_red.cpp:37
@ Reduce
η-reduction performed.
Definition eta_red.h:17
@ Bot
Never seen.
Definition eta_red.h:16
@ Irreducible
η-reduction not possible as we stumbled upon a Var.
Definition eta_red.h:18
LamMap< Lattice > Data
Definition eta_red.h:21
Ref rewrite(Ref) override
Definition eta_red.cpp:21
void mark_irreducible(Lam *lam)
Definition eta_red.h:22
EtaRed(PassMan &man, bool callee_only=false)
Definition eta_red.h:11
Inherit from this class using CRTP, if you do need a Pass with a state and a fixed-point.
Definition pass.h:242
A function.
Definition lam.h:97
An optimizer that combines several optimizations in an optimal way.
Definition pass.h:107
PassMan & man()
Definition pass.h:30
Helper class to retrieve Infer::arg if present.
Definition def.h:87
Definition cfg.h:11
size_t undo_t
Definition pass.h:14
GIDMap< Lam *, To > LamMap
Definition lam.h:189
GIDSet< Lam * > LamSet
Definition lam.h:190