MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
opt.cpp
Go to the documentation of this file.
1#include "mim/plug/opt/opt.h"
2
3#include <string_view>
4
5#include <mim/driver.h>
6
7#include <mim/pass/pass.h>
8
11
12using namespace mim;
13using namespace mim::plug;
14
16 return {"opt", nullptr,
17 [](Passes& passes) {
19 const Def* app) {
20 auto& driver = builder.world().driver();
21 auto [ax, args] = collect_args(app);
22 auto plugin_axiom = args[1]->as<Axiom>();
23 auto then_phase = args[2];
24 auto else_phase = args[3];
25 auto name = plugin_axiom->sym(); // name has the form %opt.tag
26 auto [_, tag, __] = Annex::split(driver, name); // where tag = [plugin]_plugin
27 auto plugin = tag.view().substr(0, tag.view().find('_')); // we want to extract the plugin
28 bool is_loaded = driver.is_loaded(driver.sym(plugin));
29
30 assert(tag.view().find('_') != std::string_view::npos && "mim/plugin_phase: invalid plugin name");
31 world.DLOG("mim/plugin_phase for: {}", plugin_axiom->sym());
32 world.DLOG("mim/plugin: {}", plugin);
33 world.DLOG("contained: {}", is_loaded);
34
35 compile::handle_optimization_part(is_loaded ? then_phase : else_phase, world, passes, builder);
36 };
37 },
38 nullptr};
39}
Base class for all Defs.
Definition def.h:220
Sym sym() const
Definition def.h:465
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition world.h:33
#define MIM_EXPORT
Definition config.h:16
void handle_optimization_part(const Def *part, World &world, Passes &passes, PipelineBuilder &builder)
Definition compile.h:9
Definition cfg.h:11
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
MIM_EXPORT mim::Plugin mim_get_plugin()
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
static std::tuple< Sym, Sym, Sym > split(Driver &, Sym)
Definition plugin.cpp:58
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