Thorin 1.9.0
The Higher ORder INtermediate representation
Loading...
Searching...
No Matches
opt.cpp
Go to the documentation of this file.
2
3#include <string_view>
4
5#include <thorin/driver.h>
6
7#include <thorin/pass/pass.h>
8
11
12using namespace thorin;
13using namespace thorin::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(world, 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
31 && "thorin/plugin_phase: invalid plugin name");
32 world.DLOG("thorin/plugin_phase for: {}", plugin_axiom->sym());
33 world.DLOG("thorin/plugin: {}", plugin);
34 world.DLOG("contained: {}", is_loaded);
35
36 compile::handle_optimization_part(is_loaded ? then_phase : else_phase, world, passes, builder);
37 };
38 },
39 nullptr};
40}
Base class for all Defs.
Definition def.h:222
Sym sym() const
Definition def.h:470
The World represents the whole program and manages creation of Thorin nodes (Defs).
Definition world.h:35
#define THORIN_EXPORT
Definition config.h:16
void handle_optimization_part(const Def *part, World &world, Passes &passes, PipelineBuilder &builder)
Definition compile.h:10
Definition cfg.h:11
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
THORIN_EXPORT thorin::Plugin thorin_get_plugin()
To be implemented and exported by a 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
u64 flags_t
Definition types.h:46
static constexpr flags_t Base
Definition plugin.h:131
static std::array< Sym, 3 > split(World &, Sym)
Definition plugin.cpp:58
Basic info and registration function pointer to be returned from a specific plugin.
Definition plugin.h:29