MimIR
0.6-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
mach.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <utility>
4
5
#include <
mim/axm.h
>
6
#include <
mim/lam.h
>
7
#include <
mim/world.h
>
8
9
#include "
mim/plug/mach/autogen.h
"
10
11
namespace
mim::plug::mach
{
12
13
/// The hardware encoding of the register @p r of a backend's module `reg`, whose subtags are in encoding order.
14
template
<
class
Reg>
15
constexpr
size_t
encoding
(
Reg
r) {
16
return
Annex::flags2sub
(std::to_underlying(r));
17
}
18
19
/// @p x of `Idx s` as a literal of @p type, sign-extended if @p sign.
20
inline
const
Def
*
fold_ext
(
const
Def
* type,
const
Def
* x,
bool
sign) {
21
auto
l =
Lit::isa
(x);
22
auto
s =
Idx::isa_lit
(x->
type
());
23
auto
d =
Idx::isa_lit
(type);
24
if
(!l || !s || !d)
return
nullptr
;
25
auto
v = *l;
26
if
(
auto
bits =
Idx::size2bitwidth
(*s); sign && bits < 64 && (v >> (bits - 1)) & 1) v |= ~0_n << bits;
27
return
type->world().lit_idx_mod(*d, v);
28
}
29
30
/// Bails unless the address space @p a of the `mem` operation @p app is `0`.
31
inline
void
check_addr_space
(
const
App
* app,
const
Def
* a) {
32
if
(
auto
l =
Lit::isa
(a); !l || *l != 0)
33
app->
blame
(
"native backend: address space `{}` of `{}` is not 0"
, a, app->
axm
()).bail();
34
}
35
36
}
// namespace mim::plug::mach
axm.h
mim::App
Definition
lam.h:215
mim::App::axm
const Axm * axm() const
Definition
lam.h:257
mim::Def
Base class for all Defs.
Definition
def.h:285
mim::Def::type
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
Definition
def.h:1116
mim::Def::blame
fe::Error & blame(fe::cite_string< Args... > s, Args &&... args) const
Reports an error that blames this; chain Error::n for Notes and Error::bail to throw.
Definition
def.h:329
mim::Idx::size2bitwidth
static constexpr nat_t size2bitwidth(nat_t n)
Definition
def.h:1038
mim::Idx::isa_lit
static std::optional< nat_t > isa_lit(const Def *def)
Definition
def.cpp:689
mim::Lit::isa
static std::optional< T > isa(const Def *def)
Definition
def.h:974
lam.h
autogen.h
mim::plug::mach
The mach Plugin
Definition
asm.h:15
mim::plug::mach::check_addr_space
void check_addr_space(const App *app, const Def *a)
Bails unless the address space a of the mem operation app is 0.
Definition
mach.h:31
mim::plug::mach::encoding
constexpr size_t encoding(Reg r)
The hardware encoding of the register r of a backend's module reg, whose subtags are in encoding orde...
Definition
mach.h:15
mim::plug::mach::fold_ext
const Def * fold_ext(const Def *type, const Def *x, bool sign)
x of Idx s as a literal of type, sign-extended if sign.
Definition
mach.h:20
mim::Annex::flags2sub
static constexpr sub_t flags2sub(flags_t f)
Yields the sub part of the name as integer.
Definition
plugin.h:262
mim::plug::mach::Reg
A physical register of a register class.
Definition
emit.h:25
world.h
include
mim
plug
mach
mach.h
Generated by
1.18.0