MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
compile.cpp
Go to the documentation of this file.
2
3#include <mim/config.h>
4
5#include <mim/pass/beta_red.h>
6#include <mim/pass/eta_exp.h>
7#include <mim/pass/eta_red.h>
8#include <mim/pass/lam_spec.h>
9#include <mim/pass/pass.h>
11#include <mim/pass/ret_wrap.h>
12#include <mim/pass/scalarize.h>
14
17
18using namespace mim;
19using namespace mim::plug;
20
21void add_phases(Defs phases, World& world, Passes& passes, PipelineBuilder& builder) {
22 for (auto phase : phases) compile::handle_optimization_part(phase, world, passes, builder);
23}
24
25void add_passes(World& world, PipelineBuilder& builder, Passes& passes, DefVec& pass_list) {
26 // Concept: We create a convention that passes register in the pipeline using append_**in**_last.
27 // This pass then calls the registered passes in the order they were registered in the last phase.
28
29 // We create a new dummy phase in which the passes should be inserted.
30 // builder.append_phase_end([](Pipeline&) {});
31 builder.begin_pass_phase();
32 for (auto pass : pass_list) compile::handle_optimization_part(pass, world, passes, builder);
33 builder.end_pass_phase();
34}
35
37 return {"compile", [](Normalizers& normalizers) { compile::register_normalizers(normalizers); },
38 [](Passes& passes) {
40 assert_emplace(passes, debug_phase_flag, [](World& world, PipelineBuilder& builder, const Def* app) {
41 world.DLOG("Generate debug_phase: {}", app);
42 int level = (int)(app->as<App>()->arg(0)->as<Lit>()->get<u64>());
43 world.DLOG(" Level: {}", level);
44 builder.add_phase<compile::DebugPrint>(level);
45 });
46
48 [&](World& world, PipelineBuilder& builder, const Def* app) {
49 auto pass_array = app->as<App>()->arg()->projs();
50 DefVec pass_list;
51 for (auto pass : pass_array) pass_list.push_back(pass);
52 add_passes(world, builder, passes, pass_list);
53 });
54
56 [&](World& world, PipelineBuilder& builder, const Def* app) {
57 auto phase_array = app->as<App>()->arg()->projs();
58 DefVec phase_list;
59 for (auto phase : phase_array) phase_list.push_back(phase);
60 add_phases(phase_list, world, passes, builder);
61 });
62
64 [&](World& world, PipelineBuilder& builder, const Def* app) {
65 auto [ax, phases] = collect_args(app);
66 add_phases(phases, world, passes, builder);
67 });
70 [](World&, PipelineBuilder& builder, const Def* def) { builder.def2pass(def, nullptr); });
71
74
78
82 },
83 nullptr};
84}
const Def * arg() const
Definition lam.h:227
Base class for all Defs.
Definition def.h:223
auto projs(F f) const
Splits this Def via Def::projections into an Array (if A == -1_n) or std::array (otherwise).
Definition def.h:367
T get() const
Definition def.h:751
void def2pass(const Def *, Pass *p)
void add_phase(Args &&... args)
This is a thin wrapper for std::span<T, N> with the following additional features:
Definition span.h:28
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition world.h:33
void add_phases(Defs phases, World &world, Passes &passes, PipelineBuilder &builder)
Definition compile.cpp:21
void add_passes(World &world, PipelineBuilder &builder, Passes &passes, DefVec &pass_list)
Definition compile.cpp:25
#define MIM_EXPORT
Definition config.h:16
void register_normalizers(Normalizers &normalizers)
void handle_optimization_part(const Def *part, World &world, Passes &passes, PipelineBuilder &builder)
Definition compile.h:9
Definition cfg.h:11
auto assert_emplace(C &container, Args &&... args)
Invokes emplace on container, asserts that insertion actually happened, and returns the iterator.
Definition util.h:102
u64 flags_t
Definition types.h:45
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
void register_pass(Passes &passes, CArgs &&... args)
void register_pass_with_arg(Passes &passes)
MIM_EXPORT mim::Plugin mim_get_plugin()
absl::flat_hash_map< flags_t, NormalizeFn > Normalizers
Definition plugin.h:19
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
uint64_t u64
Definition types.h:34
static constexpr flags_t Base
Definition plugin.h:118
Basic info and registration function pointer to be returned from a specific plugin.
Definition plugin.h:29