MimIR
MimIR is my Intermediate Representation
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
10
11namespace 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.
14template<class Reg>
15constexpr 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.
20inline 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`.
31inline 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
const Axm * axm() const
Definition lam.h:257
Base class for all Defs.
Definition def.h:285
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
Definition def.h:1116
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
static constexpr nat_t size2bitwidth(nat_t n)
Definition def.h:1038
static std::optional< nat_t > isa_lit(const Def *def)
Definition def.cpp:689
static std::optional< T > isa(const Def *def)
Definition def.h:974
The mach Plugin
Definition asm.h:15
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
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
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
static constexpr sub_t flags2sub(flags_t f)
Yields the sub part of the name as integer.
Definition plugin.h:262
A physical register of a register class.
Definition emit.h:25