MimIR
0.6-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
legalize.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <
mim/phase.h
>
4
5
namespace
mim::plug::mach
{
6
7
/// Turns every `Nat` value and every pointer into an `I64`, so that instruction selection only sees register types.
8
/// `Nat` literals stay `Nat` as type-level arguments and become `I64` only as values.
9
/// `mem.lea` becomes a `core.wrap.add` of the byte offset by the layout of `core.trait`, `mem.load`/`mem.store` become
10
/// `mach.load`/`mach.store`, `mem.mslot` becomes `mach.slot`, and the `Nat` operations become their `I64` counterparts.
11
class
Legalize
:
public
RWPhase
{
12
public
:
13
using
RWPhase::RWPhase
;
14
15
private
:
16
/// Are the rewritten @p args no type-level `Nat`s, such as a size bound by a Pi?
17
bool
is_value(
const
Def
*
args
);
18
/// The rewritten @p def with a `Nat` literal as `I64`.
19
const
Def
* val(
const
Def
* def);
20
/// The rewritten array index @p i at register size.
21
const
Def
* index(
const
Def
* i);
22
23
/// Short-circuits a branch on `a ∨ b` or `a ∧ b` into branches on `a` and `b`, so isel branches on their flags.
24
const
Def
* split(
const
Def
* cond,
const
Def
* ff,
const
Def
* tt,
const
Def
* arg);
25
26
std::array<const Def*, 2>
rewrite_filter_body
(
Lam
*,
Lam
*)
final
;
27
const
Def
*
rewrite_imm_Nat
(
const
Nat
*)
final
{
return
new_world
().
type_i64
(); }
28
const
Def
*
rewrite_imm_Lit
(
const
Lit
*)
final
;
29
const
Def
*
rewrite_imm_App
(
const
App
*)
final
;
30
const
Def
*
rewrite_imm_Extract
(
const
Extract
*)
final
;
31
const
Def
*
coerce_leaf
(
const
Def
*,
const
Def
*)
final
;
32
};
33
34
}
// namespace mim::plug::mach
mim::App
Definition
lam.h:215
mim::Def
Base class for all Defs.
Definition
def.h:285
mim::Extract
Extracts from a Sigma or Array-typed Extract::tuple the element at position Extract::index.
Definition
tuple.h:360
mim::Lam
A function.
Definition
lam.h:91
mim::Lit
Definition
def.h:946
mim::Nat
Definition
def.h:998
mim::Phase::args
const fe::Vector< std::string > & args()
Command-line arguments passed to this Phase's plugin via -X <plugin>:<arg>.
Definition
phase.cpp:23
mim::RWPhase::new_world
World & new_world()
Create new Defs into this.
Definition
phase.h:418
mim::RWPhase::RWPhase
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition
phase.h:360
mim::World::type_i64
const Def * type_i64()
Definition
world.h:657
mim::plug::mach::Legalize
Turns every Nat value and every pointer into an I64, so that instruction selection only sees register...
Definition
legalize.h:11
mim::plug::mach::Legalize::rewrite_filter_body
std::array< const Def *, 2 > rewrite_filter_body(Lam *, Lam *) final
The rewritten filter and body of old_lam for its stub new_lam, before the body is coerce()d.
Definition
legalize.cpp:62
mim::plug::mach::Legalize::rewrite_imm_Nat
const Def * rewrite_imm_Nat(const Nat *) final
Definition
legalize.h:27
mim::plug::mach::Legalize::rewrite_imm_Lit
const Def * rewrite_imm_Lit(const Lit *) final
Definition
legalize.cpp:90
mim::plug::mach::Legalize::rewrite_imm_Extract
const Def * rewrite_imm_Extract(const Extract *) final
Definition
legalize.cpp:101
mim::plug::mach::Legalize::rewrite_imm_App
const Def * rewrite_imm_App(const App *) final
Definition
legalize.cpp:110
mim::plug::mach::Legalize::RWPhase
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition
phase.h:360
mim::plug::mach::Legalize::coerce_leaf
const Def * coerce_leaf(const Def *, const Def *) final
Converts the new leaf new_val into the new new_type, whose representation this phase changed.
Definition
legalize.cpp:95
mim::plug::mach
The mach Plugin
Definition
asm.h:15
phase.h
include
mim
plug
mach
legalize.h
Generated by
1.18.0