MimIR
0.5-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
compile.cpp
Go to the documentation of this file.
1
#include "
mim/plug/compile/compile.h
"
2
3
#include <memory>
4
5
#include <
mim/config.h
>
6
#include <
mim/driver.h
>
7
#include <
mim/phase.h
>
8
9
#include <
mim/phase/adce.h
>
10
#include <
mim/phase/beta_red.h
>
11
#include <
mim/phase/dispatch_normalize.h
>
12
#include <
mim/phase/eta_conv.h
>
13
#include <
mim/phase/lam_spec.h
>
14
#include <
mim/phase/nom_erasure.h
>
15
#include <
mim/phase/ret_wrap.h
>
16
#include <
mim/phase/scalarize.h
>
17
#include <
mim/phase/sccp.h
>
18
#include <
mim/phase/single_erasure.h
>
19
#include <
mim/phase/static_arg_opt.h
>
20
21
#include "
mim/plug/compile/autogen.h
"
22
23
using namespace
mim
;
24
using namespace
mim::plug
;
25
26
/// Phase hook for `compile.named`.
27
/// Reads the fully-qualified annex name (e.g. `"clos.clos_conv"`) from the driving App at phase-build time,
28
/// looks up the matching annex `Def` in the current `World`, and *redirects* Phase::create to that annex's own
29
/// Phase. If the plugin part of the name is not loaded or the annex is missing, it elides (resolves to nothing),
30
/// so the enclosing `compile.phases` simply skips it.
31
class
Named
:
public
Phase
{
32
public
:
33
Named
(
World
& w,
flags_t
a)
34
:
Phase
(w, a) {}
35
36
void
start
() final { std::unreachable(); }
// a Named always redirects and never runs itself
37
38
void
apply
(
const
App
* app)
final
{
39
if
(!app)
return
;
40
auto
str =
tuple2str
(app->arg());
41
if
(str.empty())
return
;
42
43
auto
dot = str.find(
'.'
);
44
if
(dot == std::string::npos)
return
;
45
if
(!
driver
().is_loaded(std::string_view(str).substr(0, dot)))
return
;
46
47
if
(
auto
def =
world
().
annex
(
driver
().sym(str))) resolved_ =
Phase::create
(
driver
().phases(), def);
48
}
49
50
bool
redirects
()
const override
{
return
true
; }
51
std::unique_ptr<Phase>
take_resolved
()
override
{
return
std::move(resolved_); }
52
53
private
:
54
std::unique_ptr<Phase> resolved_;
55
};
56
57
static
void
reg_phases
(
Flags2Phases
& phases) {
58
// clang-format off
59
fe::assert_emplace(phases,
Annex::base<compile::null>
(), [](
World
&) {
return
std::unique_ptr<Phase>{}; });
60
Phase::hook<compile::adce, ADCE >
(phases);
61
Phase::hook<compile::beta_red, BetaRed >
(phases);
62
Phase::hook<compile::cleanup, Cleanup >
(phases);
63
Phase::hook<compile::dispatch_normalize, DispatchNormalize>
(phases);
64
Phase::hook<compile::eta_conv, EtaConv >
(phases);
65
Phase::hook<compile::lam_spec, LamSpec >
(phases);
66
Phase::hook<compile::named, Named >
(phases);
67
Phase::hook<compile::nom_erasure, NomErasure >
(phases);
68
Phase::hook<compile::phases, PhaseMan >
(phases);
69
Phase::hook<compile::ret_wrap, RetWrap >
(phases);
70
Phase::hook<compile::scalarize, Scalarize >
(phases);
71
Phase::hook<compile::sccp, SCCP >
(phases);
72
Phase::hook<compile::single_erasure, SingleErasure >
(phases);
73
Phase::hook<compile::static_arg_opt, StaticArgOpt >
(phases);
74
// clang-format on
75
}
76
77
// clang-format off
78
static
constexpr
PluginArg
known_args
[] = {
79
{
"aggr"
,
"Forces `compile.aggr` to `tt`, switching fixed-point iteration of the `opt` pipeline's `optimize` stage on (off by default)."
},
80
{
"no-aggr"
,
"Forces `compile.aggr` to `ff`, switching that fixed-point iteration off."
},
81
};
82
// clang-format on
83
84
MIM_PLUGIN_ENTRY
(
compile
) {
85
plugin.register_normalizers =
compile::register_normalizers
;
86
plugin.register_phases =
reg_phases
;
87
plugin.args =
known_args
;
88
plugin.num_args = std::size(
known_args
);
89
}
adce.h
beta_red.h
Named::apply
void apply(const App *app) final
Invoked if your Phase has additional args.
Definition
compile.cpp:38
Named::take_resolved
std::unique_ptr< Phase > take_resolved() override
The Phase to use instead; nullptr means elide.
Definition
compile.cpp:51
Named::start
void start() final
Actual entry.
Definition
compile.cpp:36
Named::redirects
bool redirects() const override
If true, Phase::create uses take_resolved().
Definition
compile.cpp:50
Named::Named
Named(World &w, flags_t a)
Definition
compile.cpp:33
mim::App
Definition
lam.h:215
mim::Phase::hook
static void hook(Flags2Phases &phases)
Definition
phase.h:51
mim::Phase::annex
flags_t annex() const
Definition
phase.h:62
mim::Phase::Phase
Phase(World &world, std::string name)
Definition
phase.h:27
mim::Phase::driver
Driver & driver()
Definition
phase.h:59
mim::Phase::create
static std::unique_ptr< Phase > create(const Flags2Phases &phases, const Def *def)
Definition
phase.cpp:25
mim::Phase::world
World & world()
Definition
phase.h:58
mim::World
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition
world.h:43
autogen.h
reg_phases
static void reg_phases(Flags2Phases &phases)
Definition
compile.cpp:57
known_args
static constexpr PluginArg known_args[]
Definition
compile.cpp:78
compile.h
config.h
dispatch_normalize.h
driver.h
eta_conv.h
lam_spec.h
mim::plug::compile
The compile Plugin
Definition
normalizers.cpp:7
mim::plug::compile::register_normalizers
void register_normalizers(Normalizers &normalizers)
mim::plug
Definition
affine.h:10
mim
Definition
ast.h:16
mim::flags_t
u64 flags_t
Definition
types.h:39
mim::tuple2str
std::string tuple2str(const Def *)
Definition
tuple.cpp:115
mim::Flags2Phases
ankerl::unordered_dense::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
mim::PluginArg
One -X <plugin>:<arg> a Plugin understands; see Arguments.
Definition
plugin.h:34
nom_erasure.h
phase.h
MIM_PLUGIN_ENTRY
#define MIM_PLUGIN_ENTRY(p)
Defines a Plugin's entry point; the body fills in the plugin handed to it, as in MIM_PLUGIN_ENTRY(dem...
Definition
plugin.h:196
ret_wrap.h
scalarize.h
sccp.h
single_erasure.h
static_arg_opt.h
mim::Annex::base
static consteval flags_t base()
Definition
plugin.h:276
src
mim
plug
compile
compile.cpp
Generated by
1.18.0