MimIR
0.5-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/mem/mem.h
"
4
5
namespace
mim::plug::mem
{
6
7
const
Def
*
normalize_lea
(
const
Def
*,
const
Def
*,
const
Def
* arg) {
8
auto
[ptr, index] = arg->
projs
<2>();
9
if
(
auto
a =
Lit::isa
(
pointee
(ptr)->arity()); a && *a == 1)
return
ptr;
10
11
return
{};
12
}
13
14
const
Def
*
normalize_load
(
const
Def
* type,
const
Def
*,
const
Def
* arg) {
15
auto
& world = type->world();
16
auto
[
mem
, ptr] = arg->
projs
<2>();
17
18
if
(ptr->isa<
Bot
>())
return
world.tuple({
mem
, world.bot(type->as<
Sigma
>()->
op
(1))});
19
20
// loading an empty tuple can only result in an empty tuple
21
// TODO use common singleton magic here
22
if
(
auto
sigma =
pointee
(ptr)->isa<Sigma>(); sigma && sigma->
num_ops
() == 0)
23
return
world.tuple({
mem
, world.tuple(sigma->type(), {})});
24
25
return
{};
26
}
27
28
const
Def
*
normalize_store
(
const
Def
*,
const
Def
*,
const
Def
* arg) {
29
auto
[
mem
, ptr, val] = arg->
projs
<3>();
30
31
if
(ptr->isa<
Bot
>() || val->isa<
Bot
>())
return
mem
;
32
if
(
auto
pack = val->isa<
Pack
>(); pack && pack->
body
()->isa<
Bot
>())
return
mem
;
33
if
(
auto
tuple
= val->isa<
Tuple
>()) {
34
if
(std::ranges::all_of(
tuple
->ops(), [](
const
Def
* op) { return op->isa<Bot>(); }))
return
mem
;
35
}
36
37
return
{};
38
}
39
40
MIM_mem_NORMALIZER_IMPL
41
42
}
// namespace mim::plug::mem
mim::Def
Base class for all Defs.
Definition
def.h:289
mim::Def::op
const Def * op(size_t i) const noexcept
Definition
def.h:377
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:457
mim::Def::num_ops
constexpr size_t num_ops() const noexcept
Definition
def.h:378
mim::Lit::isa
static std::optional< T > isa(const Def *def)
Definition
def.h:976
mim::Pack
A (possibly paramterized) Tuple.
Definition
tuple.h:332
mim::Seq::body
const Def * body() const
Definition
tuple.h:280
mim::Sigma
A dependent tuple type.
Definition
tuple.h:39
mim::Tuple
Data constructor for a Sigma.
Definition
tuple.h:84
MIM_mem_NORMALIZER_IMPL
#define MIM_mem_NORMALIZER_IMPL
Definition
autogen.h:162
mem.h
mim::plug::mem
The mem Plugin
Definition
escape_analysis.h:9
mim::plug::mem::normalize_lea
const Def * normalize_lea(const Def *, const Def *, const Def *arg)
Definition
normalizers.cpp:7
mim::plug::mem::normalize_store
const Def * normalize_store(const Def *, const Def *, const Def *arg)
Definition
normalizers.cpp:28
mim::plug::mem::normalize_load
const Def * normalize_load(const Def *type, const Def *, const Def *arg)
Definition
normalizers.cpp:14
mim::plug::mem::pointee
const Def * pointee(const Def *ptr)
Definition
mem.h:81
mim::plug::tuple
The tuple Plugin
Definition
normalizers.cpp:6
mim::Bot
TExt< false > Bot
Definition
union.h:39
world.h
src
mim
plug
mem
normalizers.cpp
Generated by
1.18.0