MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
normalizers.cpp
Go to the documentation of this file.
1#include <mim/world.h>
2
4
5#include "mim/plug/arm/arm.h"
6
7namespace mim::plug::arm {
8
9namespace {
10
11/// Fuses `sel.ne (cmp (cc.<c> f, 0), x, y)` into `sel.<c> (f, x, y)`.
12template<auto id>
13const 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
29const Def* normalize_zero(const Def* type, const Def*, const Def* x) { return mach::fold_ext(type, x, false); }
30const Def* normalize_sext(const Def* type, const Def*, const Def* x) { return mach::fold_ext(type, x, true); }
31const Def* normalize_trunc(const Def* type, const Def*, const Def* x) { return mach::fold_ext(type, x, false); }
32
33template<csel id>
34const Def* normalize_csel(const Def* type, const Def*, const Def* arg) {
35 return fuse_cc<id>(type, arg);
36}
37
38template<fcsel id>
39const Def* normalize_fcsel(const Def* type, const Def*, const Def* arg) {
40 return fuse_cc<id>(type, arg);
41}
42
44
45} // namespace mim::plug::arm
#define MIM_arm_NORMALIZER_IMPL
Definition autogen.h:414
static auto isa(const Def *def)
Definition axm.h:112
Base class for all Defs.
Definition def.h:285
static std::optional< T > isa(const Def *def)
Definition def.h:974
The ARM Plugin
Definition arm.h:11
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
const Def * normalize_zero(const Def *type, const Def *, const Def *x)
const Def * normalize_csel(const Def *type, const Def *, const Def *arg)
const Def * normalize_trunc(const Def *type, const Def *, const Def *x)
const Def * normalize_sext(const Def *type, const Def *, const Def *x)
const Def * normalize_fcsel(const Def *type, const Def *, const Def *arg)
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
fe::View< const Def * > Defs
Definition def.h:94