MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
compile.cpp
Go to the documentation of this file.
2
3#include <memory>
4
5#include <mim/config.h>
6#include <mim/driver.h>
7#include <mim/phase.h>
8
11#include <mim/phase/eta_conv.h>
12#include <mim/phase/lam_spec.h>
13#include <mim/phase/ret_wrap.h>
14#include <mim/phase/scalarize.h>
16#include <mim/phase/unload.h>
17
19
20using namespace mim;
21using namespace mim::plug;
22
23/// Phase hook for `compile.named`.
24/// Reads the fully-qualified annex name (e.g. `"clos.clos_conv"`) from the driving App at phase-build time,
25/// looks up the matching annex `Def` in the current `World`, and *redirects* Phase::create to that annex's own
26/// Phase. If the plugin part of the name is not loaded or the annex is missing, it elides (resolves to nothing),
27/// so the enclosing `compile.phases` simply skips it.
28class Named : public Phase {
29public:
31 : Phase(w, a) {}
32
33 void start() final { fe::unreachable(); } // a Named always redirects and never runs itself
34
35 void apply(const App* app) final {
36 if (!app) return;
37 auto str = tuple2str(app->arg());
38 if (str.empty()) return;
39
40 auto dot = str.find('.');
41 if (dot == std::string::npos) return;
42 if (!driver().is_loaded(std::string_view(str).substr(0, dot))) return;
43
44 if (auto def = world().annex(driver().sym(str))) resolved_ = Phase::create(driver().phases(), def);
45 }
46
47 bool redirects() const override { return true; }
48 std::unique_ptr<Phase> take_resolved() override { return std::move(resolved_); }
49
50private:
51 std::unique_ptr<Phase> resolved_;
52};
53
70
71// clang-format off
72static constexpr PluginArg known_args[] = {
73 {"aggr", "Forces `compile.aggr` to `tt`, switching fixed-point iteration of the `opt` pipeline's `optimize` stage on (off by default)."},
74 {"no-aggr", "Forces `compile.aggr` to `ff`, switching that fixed-point iteration off."},
75};
76// clang-format on
77
80 {}, {}};
81}
void reg_phases(Flags2Phases &phases)
Definition affine.cpp:12
void apply(const App *app) final
Invoked if your Phase has additional args.
Definition compile.cpp:35
std::unique_ptr< Phase > take_resolved() override
The Phase to use instead; nullptr means elide.
Definition compile.cpp:48
void start() final
Actual entry.
Definition compile.cpp:33
bool redirects() const override
If true, Phase::create uses take_resolved().
Definition compile.cpp:47
Named(World &w, flags_t a)
Definition compile.cpp:30
static void hook(Flags2Phases &phases)
Definition phase.h:70
flags_t annex() const
Definition phase.h:81
Phase(World &world, std::string name)
Definition phase.h:29
static std::unique_ptr< Phase > create(const Flags2Phases &phases, const Def *def)
Definition phase.h:50
Driver & driver()
Definition phase.h:78
World & world()
Definition phase.h:77
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition world.h:40
static constexpr PluginArg known_args[]
Definition compile.cpp:72
#define MIM_EXPORT
Definition config.h:21
void register_normalizers(Normalizers &normalizers)
Definition ast.h:16
u64 flags_t
Definition types.h:39
absl::flat_hash_map< flags_t, std::function< std::unique_ptr< Phase >(World &)> > Flags2Phases
Maps an axiom of a Phase to a function that creates one.
Definition plugin.h:30
std::string tuple2str(const Def *)
Definition tuple.cpp:48
mim::Plugin mim_get_plugin()
One -X <plugin>:<arg> a Plugin understands; see Arguments.
Definition plugin.h:34
#define MIM_VERSION
Definition plugin.h:149
static consteval flags_t base()
Definition plugin.h:250
Basic info and registration function pointer to be returned from a specific plugin.
Definition plugin.h:154