Thorin
1.9.0
The Higher ORder INtermediate representation
Loading...
Searching...
No Matches
normalizers.cpp
Go to the documentation of this file.
1
#include "
thorin/world.h
"
2
3
#include "
thorin/plug/mem/mem.h
"
4
5
namespace
thorin::plug::mem
{
6
7
Ref
normalize_lea
(
Ref
type,
Ref
callee,
Ref
arg) {
8
auto
& world = type->
world
();
9
auto
[ptr, index] = arg->
projs
<2>();
10
auto
[pointee, addr_space] = force<Ptr>(ptr->type())->args<2>();
11
12
if
(
auto
a =
Lit::isa
(pointee->arity()); a && *a == 1)
return
ptr;
13
// TODO
14
15
return
world.raw_app(type, callee, {ptr, index});
16
}
17
18
Ref
normalize_load
(
Ref
type,
Ref
callee,
Ref
arg) {
19
auto
& world = type->
world
();
20
auto
[
mem
, ptr] = arg->
projs
<2>();
21
auto
[pointee, addr_space] = force<Ptr>(ptr->type())->args<2>();
22
23
if
(ptr->isa<
Bot
>())
return
world.tuple({
mem
, world.bot(type->as<
Sigma
>()->
op
(1))});
24
25
// loading an empty tuple can only result in an empty tuple
26
if
(
auto
sigma = pointee->isa<
Sigma
>(); sigma && sigma->
num_ops
() == 0)
27
return
world.tuple({
mem
, world.tuple(sigma->type(), {})});
28
29
return
world.raw_app(type, callee, {
mem
, ptr});
30
}
31
32
Ref
normalize_remem
(
Ref
type,
Ref
callee,
Ref
mem
) {
33
auto
& world = type->
world
();
34
35
// if (auto m = match<remem>(mem)) mem = m;
36
return
world.
raw_app
(type, callee,
mem
);
37
}
38
39
Ref
normalize_store
(
Ref
type,
Ref
callee,
Ref
arg) {
40
auto
& world = type->
world
();
41
auto
[
mem
, ptr, val] = arg->
projs
<3>();
42
43
if
(ptr->isa<
Bot
>() || val->isa<
Bot
>())
return
mem
;
44
if
(
auto
pack = val->isa<
Pack
>(); pack && pack->
body
()->isa<
Bot
>())
return
mem
;
45
if
(
auto
tuple = val->isa<
Tuple
>()) {
46
if
(std::ranges::all_of(tuple->ops(), [](
Ref
op) {
return
op->isa<
Bot
>(); }))
return
mem
;
47
}
48
49
return
world.raw_app(type, callee, {
mem
, ptr, val});
50
}
51
52
THORIN_mem_NORMALIZER_IMPL
53
54
}
// namespace thorin::plug::mem
thorin::Def::projs
auto projs(F f) const
Splits this Def via Def::projections into an Array (if A == -1_n) or std::array (otherwise).
Definition
def.h:369
thorin::Def::op
const Def * op(size_t i) const
Definition
def.h:269
thorin::Def::num_ops
size_t num_ops() const
Definition
def.h:270
thorin::Def::world
World & world() const
Definition
def.cpp:421
thorin::Lit::isa
static std::optional< T > isa(Ref def)
Definition
def.h:726
thorin::Pack
A (possibly paramterized) Tuple.
Definition
tuple.h:87
thorin::Pack::body
const Def * body() const
Definition
tuple.h:97
thorin::Ref
Helper class to retrieve Infer::arg if present.
Definition
def.h:87
thorin::Sigma
A dependent tuple type.
Definition
tuple.h:9
thorin::TExt
Extremum. Either Top (Up) or Bottom.
Definition
lattice.h:130
thorin::Tuple
Data constructor for a Sigma.
Definition
tuple.h:39
thorin::World::raw_app
Ref raw_app(Ref type, Ref callee, Ref arg)
Definition
world.cpp:205
THORIN_mem_NORMALIZER_IMPL
#define THORIN_mem_NORMALIZER_IMPL
Definition
autogen.h:282
mem.h
thorin::plug::mem
The mem Plugin
Definition
mem.h:11
thorin::plug::mem::normalize_load
Ref normalize_load(Ref type, Ref callee, Ref arg)
Definition
normalizers.cpp:18
thorin::plug::mem::normalize_store
Ref normalize_store(Ref type, Ref callee, Ref arg)
Definition
normalizers.cpp:39
thorin::plug::mem::normalize_lea
Ref normalize_lea(Ref type, Ref callee, Ref arg)
Definition
normalizers.cpp:7
thorin::plug::mem::normalize_remem
Ref normalize_remem(Ref type, Ref callee, Ref mem)
Definition
normalizers.cpp:32
world.h
src
thorin
plug
mem
normalizers.cpp
Generated by
1.9.8