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
6
8
10inline void handle_optimization_part(const Def* part, World& world, Passes& passes, PipelineBuilder& builder) {
11 if (auto app = part->isa<App>()) {
12 if (auto lam = app->callee()->isa<Lam>()) {
13 part = lam->reduce_body(app->arg());
14 world.DLOG("reduce pass/phase lambda {} to {} : {}", lam, part, part->type());
15 }
16 }
17
18 auto [phase_def, phase_args] = collect_args(part);
19 world.DLOG("pass/phase: {}", phase_def);
20 if (auto phase_ax = phase_def->isa<Axm>()) {
21 auto flag = phase_ax->flags();
22 if (passes.contains(flag)) {
23 auto phase_fun = passes[flag];
24 phase_fun(world, builder, part);
25 } else {
26 world.WLOG("pass/phase '{}' not found", phase_ax->sym());
27 assert(passes.contains(flag) && "pass/phase not found");
28 }
29 } else if (phase_def->isa<Lam>()) {
30 assert(0 && "curried lambas are not supported");
31 } else {
32 world.WLOG("pass/phase '{}' is not an axm", phase_def);
33 assert(phase_def->isa<Axm>() && "pass/phase is not an axm");
34 }
35}
36} // namespace mim::plug::compile
Definition axm.h:9
Base class for all Defs.
Definition def.h:197
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
Definition def.h:241
A function.
Definition lam.h:106
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition world.h:33
The compile Plugin
Definition compile.h:9
void handle_optimization_part(const Def *part, World &world, Passes &passes, PipelineBuilder &builder)
Definition compile.h:10
std::pair< const Def *, DefVec > collect_args(const Def *def)
Helper function to cope with the fact that normalizers take all arguments and not only its axm argume...
Definition lam.cpp:82
absl::flat_hash_map< flags_t, std::function< void(World &, PipelineBuilder &, const Def *)> > Passes
axm ↦ (pipeline part) × (axm application) → () The function should inspect Application to construct...
Definition plugin.h:22