MimIR
0.6-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
imm.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <climits>
4
5
#include <algorithm>
6
#include <bit>
7
#include <optional>
8
9
#include <
mim/def.h
>
10
11
namespace
mim::plug::x86
{
12
13
/// Width of the register holding an `Idx size`.
14
inline
nat_t
reg_width
(
nat_t
size) {
return
std::bit_ceil(std::max<nat_t>(
Idx::size2bitwidth
(size), 8)); }
15
16
inline
bool
fits_i32
(
s64
x) {
return
INT32_MIN <= x && x <= INT32_MAX; }
17
18
/// Does the literal @p val fit a sign-extended 32-bit immediate, if it is an `Idx size`?
19
inline
bool
fits_imm
(std::optional<nat_t> size,
nat_t
val) {
20
return
(size &&
reg_width
(*size) < 64) ||
fits_i32
(
s64
(val));
21
}
22
23
/// Does the literal @p lit fit a sign-extended 32-bit immediate?
24
inline
bool
fits_imm
(
const
Def
* lit) {
return
fits_imm
(
Idx::isa_lit
(lit->type()), *
Lit::isa
(lit)); }
25
26
}
// namespace mim::plug::x86
mim::Def
Base class for all Defs.
Definition
def.h:285
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
def.h
mim::plug::x86
The x86 Plugin
Definition
emit.h:9
mim::plug::x86::fits_i32
bool fits_i32(s64 x)
Definition
imm.h:16
mim::plug::x86::reg_width
nat_t reg_width(nat_t size)
Width of the register holding an Idx size.
Definition
imm.h:14
mim::plug::x86::fits_imm
bool fits_imm(std::optional< nat_t > size, nat_t val)
Does the literal val fit a sign-extended 32-bit immediate, if it is an Idx size?
Definition
imm.h:19
mim::nat_t
u64 nat_t
Definition
types.h:37
mim::s64
int64_t s64
Definition
types.h:27
include
mim
plug
x86
imm.h
Generated by
1.18.0