MimIR
0.4-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/axm.h
>
2
#include <
mim/tuple.h
>
3
#include <
mim/world.h
>
4
5
#include "
mim/plug/buffer/buffer.h
"
6
7
namespace
mim::plug::buffer
{
8
9
/// `Buf (r, s, T)` with literal size-1 axes in `s` ↦ `Buf (r', s', T)` with those axes dropped.
10
/// This mirrors the folding of the corresponding array types (`«3, 1; T»` ≡ `«3; T»`), so buffer types
11
/// derived from logical shapes agree with the (folded) boundary types by construction.
12
const
Def
*
normalize_Buf
(
const
Def
*,
const
Def
* callee,
const
Def
* arg) {
13
auto
& world = arg->
world
();
14
auto
[r, s, T] = arg->
projs
<3>();
15
auto
r_l =
Lit::isa<u64>
(r);
16
if
(!r_l)
return
{};
17
18
DefVec
dims;
19
dims.reserve(*r_l);
20
for
(
u64
i = 0; i < *r_l; ++i) {
21
auto
d = s->proj(*r_l, i);
22
if
(
auto
l =
Lit::isa<u64>
(d); l && *l == 1)
continue
;
23
dims.push_back(d);
24
}
25
if
(dims.size() == *r_l)
return
{};
26
return
world.app(callee, world.tuple({world.lit_nat(dims.size()), world.tuple(dims), T}));
27
}
28
29
/// `read (constant v) idx` ↦ `v`.
30
const
Def
*
normalize_read
(
const
Def
* type,
const
Def
*,
const
Def
* arg) {
31
auto
& world = type->world();
32
auto
[
mem
, buf, index] = arg->
projs
<3>();
33
if
(
auto
ex = buf->isa<
Extract
>())
34
if
(
auto
l =
Axm::isa<lit>
(ex->tuple())) {
35
auto
[cmem, v] = l->arg()->projs<2>();
36
return
world.tuple({
mem
, v});
37
}
38
return
{};
39
}
40
41
const
Def
*
normalize_write
(
const
Def
*,
const
Def
*,
const
Def
*) {
return
{}; }
42
43
/// `shape buf i` ↦ the `i`-th size, read off the buffer's type.
44
const
Def
*
normalize_shape
(
const
Def
* type,
const
Def
*,
const
Def
* arg) {
45
auto
& world = type->world();
46
auto
[buf, index] = arg->
projs
<2>();
47
auto
[r, s, T] =
Axm::isa<Buf, false>
(buf->type())->args<3>();
48
return
world.extract(s, index);
49
}
50
51
MIM_buffer_NORMALIZER_IMPL
52
53
}
// namespace mim::plug::buffer
axm.h
MIM_buffer_NORMALIZER_IMPL
#define MIM_buffer_NORMALIZER_IMPL
Definition
autogen.h:81
buffer.h
mim::Axm::isa
static auto isa(const Def *def)
Definition
axm.h:112
mim::Def
Base class for all Defs.
Definition
def.h:273
mim::Def::world
World & world() const noexcept
Definition
def.h:1097
mim::Def::projs
auto projs(F f) const
Splits this Def via Def::projections into an Array (if A == std::dynamic_extent) or std::array (other...
Definition
def.h:440
mim::Extract
Extracts from a Sigma or Array-typed Extract::tuple the element at position Extract::index.
Definition
tuple.h:161
mim::Lit::isa
static std::optional< T > isa(const Def *def)
Definition
def.h:937
mim::plug::buffer
The buffer Plugin
Definition
buffer.h:7
mim::plug::buffer::normalize_write
const Def * normalize_write(const Def *, const Def *, const Def *)
Definition
normalizers.cpp:41
mim::plug::buffer::normalize_shape
const Def * normalize_shape(const Def *type, const Def *, const Def *arg)
shape buf i ↦ the i-th size, read off the buffer's type.
Definition
normalizers.cpp:44
mim::plug::buffer::normalize_read
const Def * normalize_read(const Def *type, const Def *, const Def *arg)
read (constant v) idx ↦ v.
Definition
normalizers.cpp:30
mim::plug::buffer::normalize_Buf
const Def * normalize_Buf(const Def *, const Def *callee, const Def *arg)
Buf (r, s, T) with literal size-1 axes in s ↦ Buf (r', s', T) with those axes dropped.
Definition
normalizers.cpp:12
mim::plug::mem
The mem Plugin
Definition
mem.h:11
mim::DefVec
fe::Vector< const Def * > DefVec
Definition
def.h:93
mim::u64
uint64_t u64
Definition
types.h:27
tuple.h
world.h
src
mim
plug
buffer
normalizers.cpp
Generated by
1.18.0