MimIR
0.6-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
gen.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <optional>
4
#include <string_view>
5
6
#include <
mim/driver.h
>
7
#include <
mim/phase.h
>
8
9
#include "
mim/plug/mach/rule_table.h
"
10
11
namespace
mim::plug::mach
{
12
13
class
Gen
;
14
15
/// Gen::start, compiled once into `libmim_mach`; Gen reaches it via `GET_FUN_PTR`.
16
extern
"C"
MIM_EXPORT
void
mim_mach_gen
(
Gen
&);
17
18
/// Writes the closed rules among the annexes of a backend's isel plugin as the C++ matchers and builders of a
19
/// rules::Table in `mim::plug::<backend>::rules`, to `-X <isel>:o=<file>` or stdout.
20
/// The isel plugin derives from it and states the machine facts of its backend.
21
class
Gen
:
public
Phase
{
22
public
:
23
/// The annexes of the isel plugin that Gen knows; `0` for one it does not have.
24
struct
Annexes
{
25
flags_t
addr
= 0;
///< `addr p`: the address `p` as an address operand, Want::Addr.
26
flags_t
reg_imm
= 0;
///< `reg_imm x`: Want::RegImm.
27
flags_t
reg_sh
= 0;
///< `reg_sh x`: Want::RegSh.
28
flags_t
scaled
= 0;
///< `scaled i`: Want::Scaled.
29
flags_t
zx
= 0;
///< `zx x`: Want::Zx of a meta variable, else the non-terminal Zx of a rhs or conversion.
30
flags_t
imm
= 0;
///< The guard `imm x`: Want::Imm.
31
flags_t
lit
= 0;
///< The guard `lit x`: a literal.
32
flags_t
commutes
;
///< The tuple of the operations whose two operands a rule also matches swapped.
33
flags_t
formats
;
///< The values of a family parameter of type `«2; Nat»`.
34
flags_t
sizes
;
///< The values of a family parameter of type `Nat`.
35
};
36
37
/// @p backend names the plugin whose instructions the rules of the plugin @p isel select.
38
Gen
(
World
&
world
,
39
flags_t
annex
,
40
std::string_view
backend
,
41
plugin_t
backend_id
,
42
std::string_view
isel
,
43
plugin_t
isel_id
,
44
Annexes
annexes
)
45
:
Phase
(
world
,
annex
)
46
, backend_(
backend
)
47
, backend_id_(
backend_id
)
48
, isel_(
isel
)
49
, isel_id_(
isel_id
)
50
, annexes_(
annexes
) {}
51
52
void
start
() final {
driver
().GET_FUN_PTR(
"mach"
,
mim_mach_gen
)(*this); }
53
54
std::string_view
backend
()
const
{
return
backend_; }
55
plugin_t
backend_id
()
const
{
return
backend_id_; }
56
std::string_view
isel
()
const
{
return
isel_; }
57
plugin_t
isel_id
()
const
{
return
isel_id_; }
58
const
Annexes
&
annexes
()
const
{
return
annexes_; }
59
60
/// @name Machine Facts
61
///@{
62
/// The cost of the instruction @p insn of the backend, which a rule's cost sums up.
63
virtual
u32
cost
(
const
App
* insn)
const
= 0;
64
/// The operand whose register the result of the two-address instruction @p insn takes.
65
virtual
std::optional<size_t>
tied
(
const
App
*)
const
{
return
{}; }
66
/// What an operand of the backend's address type @p type is: Want::Base, Want::Index, or Want::Addr.
67
virtual
std::optional<mach::rules::Want>
classify
(
const
Def
*)
const
{
return
{}; }
68
///@}
69
70
private
:
71
std::string_view backend_;
72
plugin_t
backend_id_;
73
std::string_view isel_;
74
plugin_t
isel_id_;
75
Annexes annexes_;
76
};
77
78
}
// namespace mim::plug::mach
mim::App
Definition
lam.h:215
mim::Def
Base class for all Defs.
Definition
def.h:285
mim::Phase::annex
flags_t annex() const
Definition
phase.h:64
mim::Phase::Phase
Phase(World &world, std::string name)
Definition
phase.h:29
mim::Phase::driver
Driver & driver()
Definition
phase.h:61
mim::Phase::world
World & world()
Definition
phase.h:60
mim::World
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition
world.h:43
mim::plug::mach::Gen
Writes the closed rules among the annexes of a backend's isel plugin as the C++ matchers and builders...
Definition
gen.h:21
mim::plug::mach::Gen::classify
virtual std::optional< mach::rules::Want > classify(const Def *) const
What an operand of the backend's address type type is: Want::Base, Want::Index, or Want::Addr.
Definition
gen.h:67
mim::plug::mach::Gen::Annexes::sizes
flags_t sizes
The values of a family parameter of type Nat.
Definition
gen.h:34
mim::plug::mach::Gen::backend
std::string_view backend() const
Definition
gen.h:54
mim::plug::mach::Gen::Annexes::addr
flags_t addr
addr p: the address p as an address operand, Want::Addr.
Definition
gen.h:25
mim::plug::mach::Gen::Annexes::reg_sh
flags_t reg_sh
reg_sh x: Want::RegSh.
Definition
gen.h:27
mim::plug::mach::Gen::Annexes::reg_imm
flags_t reg_imm
reg_imm x: Want::RegImm.
Definition
gen.h:26
mim::plug::mach::Gen::start
void start() final
Actual entry.
Definition
gen.h:52
mim::plug::mach::Gen::Annexes::lit
flags_t lit
The guard lit x: a literal.
Definition
gen.h:31
mim::plug::mach::Gen::isel_id
plugin_t isel_id() const
Definition
gen.h:57
mim::plug::mach::Gen::Annexes::commutes
flags_t commutes
The tuple of the operations whose two operands a rule also matches swapped.
Definition
gen.h:32
mim::plug::mach::Gen::tied
virtual std::optional< size_t > tied(const App *) const
The operand whose register the result of the two-address instruction insn takes.
Definition
gen.h:65
mim::plug::mach::Gen::Annexes::zx
flags_t zx
zx x: Want::Zx of a meta variable, else the non-terminal Zx of a rhs or conversion.
Definition
gen.h:29
mim::plug::mach::Gen::isel
std::string_view isel() const
Definition
gen.h:56
mim::plug::mach::Gen::Gen
Gen(World &world, flags_t annex, std::string_view backend, plugin_t backend_id, std::string_view isel, plugin_t isel_id, Annexes annexes)
backend names the plugin whose instructions the rules of the plugin isel select.
Definition
gen.h:38
mim::plug::mach::Gen::Annexes::scaled
flags_t scaled
scaled i: Want::Scaled.
Definition
gen.h:28
mim::plug::mach::Gen::backend_id
plugin_t backend_id() const
Definition
gen.h:55
mim::plug::mach::Gen::cost
virtual u32 cost(const App *insn) const =0
mim::plug::mach::Gen::Annexes::imm
flags_t imm
The guard imm x: Want::Imm.
Definition
gen.h:30
mim::plug::mach::Gen::Annexes::formats
flags_t formats
The values of a family parameter of type «2; Nat».
Definition
gen.h:33
mim::plug::mach::Gen::annexes
const Annexes & annexes() const
Definition
gen.h:58
mim::plug::mach::Gen::Annexes
The annexes of the isel plugin that Gen knows; 0 for one it does not have.
Definition
gen.h:24
MIM_EXPORT
#define MIM_EXPORT
Definition
config.h:21
driver.h
mim::plug::mach
The mach Plugin
Definition
asm.h:15
mim::plug::mach::mim_mach_gen
void mim_mach_gen(Gen &)
Gen::start, compiled once into libmim_mach; Gen reaches it via GET_FUN_PTR.
Definition
gen.cpp:1006
mim::flags_t
u64 flags_t
Definition
types.h:39
mim::plugin_t
u64 plugin_t
Definition
types.h:40
mim::u32
uint32_t u32
Definition
types.h:27
phase.h
rule_table.h
include
mim
plug
mach
gen.h
Generated by
1.18.0