MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
copy_prop.h
Go to the documentation of this file.
1#pragma once
2
3#include <mim/pass.h>
4
5namespace mim {
6
7class BetaRed;
8class EtaExp;
9
10namespace plug::mem::pass {
11
12/// This FPPass is similar to sparse conditional constant propagation (SCCP).
13/// However, this optmization also works on all Lam%s alike and does not only consider basic blocks as opposed to
14/// traditional SCCP. What is more, this optimization will also propagate arbitrary Def%s and not only constants.
15/// Finally, it will also remove dead Var%s.
16class CopyProp : public FPPass<CopyProp, Lam> {
17public:
20
21 void apply(bool bb_only);
22 void apply(const App* app) final { apply(Lit::as<bool>(app->arg())); }
23 void apply(Stage& s) final { apply(static_cast<CopyProp&>(s).bb_only()); }
24 void init(PassMan*) final;
25
26 bool bb_only() const { return bb_only_; }
27
29
30private:
31 /// Lattice used for this Pass:
32 /// ```
33 /// Keep <-- We cannot do anything here.
34 /// |
35 /// Prop <-- Var is live but the same Def everywhere.
36 /// |
37 /// Dead <-- Var is dead.
38 /// ```
39 enum Lattice : u8 { Dead, Prop, Keep };
40 enum : u32 { Varxy, Appxy };
41 using Lattices = Vector<Lattice>;
42
43 /// @name PassMan hooks
44 ///@{
45 const Def* rewrite(const Def*) override;
46 undo_t analyze(const Proxy*) override;
47 ///@}
48
49 BetaRed* beta_red_;
50 EtaExp* eta_exp_;
52 bool bb_only_;
53};
54
55} // namespace plug::mem::pass
56} // namespace mim
Optimistically performs β-reduction (aka inlining).
Definition beta_red.h:9
Base class for all Defs.
Definition def.h:251
Performs η-expansion: f -> λx.f x, if f is a Lam with more than one user and does not appear in calle...
Definition eta_exp.h:13
FPPass(World &world, std::string name)
Definition pass.h:323
static T as(const Def *def)
Definition def.h:828
An optimizer that combines several optimizations in an optimal way.
Definition pass.h:172
World & world()
Definition pass.h:64
Stage(World &world, std::string name)
Definition pass.h:30
flags_t annex() const
Definition pass.h:68
This is a thin wrapper for absl::InlinedVector<T, N, A> which is a drop-in replacement for std::vecto...
Definition vector.h:18
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition world.h:36
undo_t analyze(const Proxy *) override
CopyProp(World &world, flags_t annex)
Definition copy_prop.h:18
const Def * rewrite(const Def *) override
Definition copy_prop.cpp:21
void init(PassMan *) final
Definition copy_prop.cpp:15
void apply(Stage &s) final
Dito, but invoked by Stage::recreate.
Definition copy_prop.h:23
void apply(const App *app) final
Invoked if your Stage has additional args.
Definition copy_prop.h:22
Definition ast.h:14
u64 flags_t
Definition types.h:45
GIDMap< Lam *, To > LamMap
Definition lam.h:220
size_t undo_t
Definition pass.h:21
uint32_t u32
Definition types.h:34
uint8_t u8
Definition types.h:34