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/arm/arm.h
"
6
7
namespace
mim::plug::arm
{
8
9
namespace
{
10
11
/// Fuses `sel.ne (cmp (cc.<c> f, 0), x, y)` into `sel.<c> (f, x, y)`.
12
template
<auto
id
>
13
const
Def* fuse_cc(
const
Def* type,
const
Def* arg) {
14
using
Sel =
decltype
(
id
);
15
if
constexpr
(
id
== Sel::ne) {
16
auto
[
f
, x, y] = arg->projs<3>();
17
if
(
auto
c =
Axm::isa<cmp>
(f)) {
18
auto
[
a
,
b
] =
c
->args<2>();
19
if
(
auto
l =
Lit::isa
(b);
l
&& *
l
== 0)
20
if
(
auto
cond =
Axm::isa<cc>
(a))
21
return
type
->world().call(
cc_to<Sel>
(
cond
.id()),
Defs
{cond->arg(), x, y});
22
}
23
}
24
return
nullptr
;
25
}
26
27
}
// namespace
28
29
const
Def
*
normalize_zero
(
const
Def
* type,
const
Def
*,
const
Def
* x) {
return
mach::fold_ext
(type, x,
false
); }
30
const
Def
*
normalize_sext
(
const
Def
* type,
const
Def
*,
const
Def
* x) {
return
mach::fold_ext
(type, x,
true
); }
31
const
Def
*
normalize_trunc
(
const
Def
* type,
const
Def
*,
const
Def
* x) {
return
mach::fold_ext
(type, x,
false
); }
32
33
template
<csel
id
>
34
const
Def
*
normalize_csel
(
const
Def
* type,
const
Def
*,
const
Def
* arg) {
35
return
fuse_cc<id>(type, arg);
36
}
37
38
template
<fcsel
id
>
39
const
Def
*
normalize_fcsel
(
const
Def
* type,
const
Def
*,
const
Def
* arg) {
40
return
fuse_cc<id>(type, arg);
41
}
42
43
MIM_arm_NORMALIZER_IMPL
44
45
}
// namespace mim::plug::arm
MIM_arm_NORMALIZER_IMPL
#define MIM_arm_NORMALIZER_IMPL
Definition
autogen.h:414
arm.h
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::Lit::isa
static std::optional< T > isa(const Def *def)
Definition
def.h:974
mach.h
mim::plug::affine::id
id
Definition
autogen.h:64
mim::plug::arm
The ARM Plugin
Definition
arm.h:11
mim::plug::arm::cc_to
constexpr flags_t cc_to(cc c)
The instance of the select family Sel (csel or fcsel) that selects on c.
Definition
arm.h:52
mim::plug::arm::normalize_zero
const Def * normalize_zero(const Def *type, const Def *, const Def *x)
Definition
normalizers.cpp:29
mim::plug::arm::normalize_csel
const Def * normalize_csel(const Def *type, const Def *, const Def *arg)
Definition
normalizers.cpp:34
mim::plug::arm::normalize_trunc
const Def * normalize_trunc(const Def *type, const Def *, const Def *x)
Definition
normalizers.cpp:31
mim::plug::arm::normalize_sext
const Def * normalize_sext(const Def *type, const Def *, const Def *x)
Definition
normalizers.cpp:30
mim::plug::arm::normalize_fcsel
const Def * normalize_fcsel(const Def *type, const Def *, const Def *arg)
Definition
normalizers.cpp:39
mim::plug::compile::cond
cond
Definition
autogen.h:29
mim::plug::core::ncmp::l
@ l
Definition
autogen.h:56
mim::plug::core::ncmp::f
@ f
Definition
autogen.h:52
mim::plug::core::shr::a
@ a
Definition
autogen.h:139
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::math::round::c
@ c
Definition
autogen.h:297
mim::plug::refly::type
type
Definition
autogen.h:37
mim::plug::x86::cc::b
@ b
Definition
autogen.h:348
mim::Defs
fe::View< const Def * > Defs
Definition
def.h:94
world.h
src
mim
plug
arm
normalizers.cpp
Generated by
1.18.0