MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
compile.h
Go to the documentation of this file.
1#pragma once
2
3#include <mim/world.h>
4
7
9inline void handle_optimization_part(const Def* part, World& world, Passes& passes, PipelineBuilder& builder) {
10 if (auto app = part->isa<App>()) {
11 if (auto lam = app->callee()->isa<Lam>()) {
12 part = lam->reduce(app->arg())[1];
13 world.DLOG("reduce pass/phase lambda {} to {} : {}", lam, part, part->type());
14 }
15 }
16
17 auto [phase_def, phase_args] = collect_args(part);
18 world.DLOG("pass/phase: {}", phase_def);
19 if (auto phase_ax = phase_def->isa<Axiom>()) {
20 auto flag = phase_ax->flags();
21 if (passes.contains(flag)) {
22 auto phase_fun = passes[flag];
23 phase_fun(world, builder, part);
24 } else {
25 world.WLOG("pass/phase '{}' not found", phase_ax->sym());
26 assert(passes.contains(flag) && "pass/phase not found");
27 }
28 } else if (phase_def->isa<Lam>()) {
29 assert(0 && "curried lambas are not supported");
30 } else {
31 world.WLOG("pass/phase '{}' is not an axiom", phase_def);
32 assert(phase_def->isa<Axiom>() && "pass/phase is not an axiom");
33 }
34}
35} // namespace mim::plug::compile
Base class for all Defs.
Definition def.h:223
DefVec reduce(const Def *arg) const
Rewrites Def::ops by substituting this mutable's Var with arg.
Definition def.cpp:206
const Def * type() const
Definition def.h:248
A function.
Definition lam.h:103
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition world.h:33
The compile Plugin
Definition compile.h:8
void handle_optimization_part(const Def *part, World &world, Passes &passes, PipelineBuilder &builder)
Definition compile.h:9
absl::flat_hash_map< flags_t, std::function< void(World &, PipelineBuilder &, const Def *)> > Passes
axiom ↦ (pipeline part) × (axiom application) → () The function should inspect Application to const...
Definition plugin.h:22
std::pair< const Def *, std::vector< const Def * > > collect_args(const Def *def)
Helper function to cope with the fact that normalizers take all arguments and not only its axiom argu...
Definition lam.cpp:86