MimIR
0.6-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
normalizers.cpp
Go to the documentation of this file.
1
#include <
mim/world.h
>
2
3
#include <
mim/plug/mach/mach.h
>
4
5
#include "
mim/plug/x86/imm.h
"
6
#include "
mim/plug/x86/x86.h
"
7
8
namespace
mim::plug::x86
{
9
10
const
Def
*
normalize_movzx
(
const
Def
* type,
const
Def
*,
const
Def
* x) {
return
mach::fold_ext
(type, x,
false
); }
11
const
Def
*
normalize_movsx
(
const
Def
* type,
const
Def
*,
const
Def
* x) {
return
mach::fold_ext
(type, x,
true
); }
12
const
Def
*
normalize_trunc
(
const
Def
* type,
const
Def
*,
const
Def
* x) {
return
mach::fold_ext
(type, x,
false
); }
13
14
const
Def
*
normalize_addr
(
const
Def
* type,
const
Def
*,
const
Def
* arg) {
15
auto
& w = type->world();
16
auto
[disp, base] = arg->
projs
<2>();
17
auto
d =
Lit::isa
(disp);
18
auto
b
=
Lit::isa
(base);
19
if
(!d || !
b
|| *
b
== 0)
return
nullptr
;
20
if
(
auto
sum =
s64
(
s32
(*d)) +
s64
(*
b
);
fits_i32
(sum))
return
w.call<
addr
>(
Defs
{w.lit_i32(u32(sum)), w.lit_i64(0)});
21
return
w.call<
addr
>(
Defs
{disp, w.call<
mov
>(base)});
22
}
23
24
const
Def
*
normalize_lea
(
const
Def
* type,
const
Def
*,
const
Def
* a) {
25
if
(
auto
ad =
Axm::isa<addr>
(a)) {
26
auto
[disp, base] = ad->args<2>();
27
auto
d =
Lit::isa
(disp);
28
auto
b
=
Lit::isa
(base);
29
if
(d && *d == 0)
return
base;
30
if
(d &&
b
&& *
b
== 0)
return
type->world().lit_i64(
u64
(
s64
(
s32
(*d))));
31
}
32
return
nullptr
;
33
}
34
35
template
<cmovcc
id
>
36
const
Def
*
normalize_cmovcc
(
const
Def
* type,
const
Def
*,
const
Def
* arg) {
37
if
constexpr
(
id
==
cmovcc::ne
) {
38
auto
[f, x, y] = arg->
projs
<3>();
39
if
(
auto
t =
Axm::isa<test>
(f)) {
40
auto
[a,
b
] = t->args<2>();
41
if
(
auto
c =
Axm::isa<cc>
(a); c && a ==
b
)
42
return
type->world().call(
static_cast<
cmovcc
>
(
Annex::Base<cmovcc>
| c.sub()),
Defs
{c->arg(), x, y});
43
}
44
}
45
return
nullptr
;
46
}
47
48
MIM_x86_NORMALIZER_IMPL
49
50
}
// namespace mim::plug::x86
mim::Axm::isa
static auto isa(const Def *def)
Definition
axm.h:112
mim::Def
Base class for all Defs.
Definition
def.h:285
mim::Def::projs
auto projs(Projector auto f) const
Splits this Def via Def::projections into an Array (if A == std::dynamic_extent) or std::array (other...
Definition
def.h:453
mim::Lit::isa
static std::optional< T > isa(const Def *def)
Definition
def.h:974
imm.h
mach.h
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::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::normalize_trunc
const Def * normalize_trunc(const Def *type, const Def *, const Def *x)
Definition
normalizers.cpp:12
mim::plug::x86::normalize_addr
const Def * normalize_addr(const Def *type, const Def *, const Def *arg)
Definition
normalizers.cpp:14
mim::plug::x86::normalize_cmovcc
const Def * normalize_cmovcc(const Def *type, const Def *, const Def *arg)
Definition
normalizers.cpp:36
mim::plug::x86::addr
addr
Definition
autogen.h:35
mim::plug::x86::mov
mov
Definition
autogen.h:181
mim::plug::x86::normalize_lea
const Def * normalize_lea(const Def *type, const Def *, const Def *a)
Definition
normalizers.cpp:24
mim::plug::x86::normalize_movzx
const Def * normalize_movzx(const Def *type, const Def *, const Def *x)
Definition
normalizers.cpp:10
mim::plug::x86::cc::b
@ b
Definition
autogen.h:348
mim::plug::x86::cmovcc
cmovcc
Definition
autogen.h:368
mim::plug::x86::cmovcc::ne
@ ne
Definition
autogen.h:374
mim::plug::x86::normalize_movsx
const Def * normalize_movsx(const Def *type, const Def *, const Def *x)
Definition
normalizers.cpp:11
mim::Defs
fe::View< const Def * > Defs
Definition
def.h:94
mim::s32
int32_t s32
Definition
types.h:27
mim::s64
int64_t s64
Definition
types.h:27
mim::u64
uint64_t u64
Definition
types.h:27
mim::Annex::Base
static constexpr flags_t Base
Definition
plugin.h:276
world.h
MIM_x86_NORMALIZER_IMPL
#define MIM_x86_NORMALIZER_IMPL
Definition
autogen.h:536
x86.h
src
mim
plug
x86
normalizers.cpp
Generated by
1.18.0