MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
buffer.h
Go to the documentation of this file.
1#pragma once
2
3#include <mim/axm.h>
4#include <mim/world.h>
5
7
9
10/// The buffer type `buffer.Buf (r, s, T)`.
11inline const Def* type_buf(const Def* r, const Def* s, const Def* T) {
12 auto& w = r->world();
13 return w.app(w.annex<Buf>(), {r, s, T});
14}
15
16/// `buffer.alloc (r, s, T) mem` ↦ `[mem.M 0, buffer.Buf (r, s, T)]`.
17inline const Def* op_alloc(const Def* r, const Def* s, const Def* T, const Def* mem) {
18 auto& w = mem->world();
19 return w.app(w.app(w.annex<alloc>(), {r, s, T}), mem);
20}
21
22/// `buffer.read (r, s, T) (mem, buf, idx)` ↦ `[mem.M 0, T]`.
23inline const Def* op_read(const Def* r, const Def* s, const Def* T, const Def* mem, const Def* buf, const Def* idx) {
24 auto& w = mem->world();
25 return w.app(w.app(w.annex<read>(), {r, s, T}), {mem, buf, idx});
26}
27
28/// `buffer.write (r, s, T) (mem, buf, idx, val)` ↦ `[mem.M 0, buffer.Buf (r, s, T)]`.
29inline const Def*
30op_write(const Def* r, const Def* s, const Def* T, const Def* mem, const Def* buf, const Def* idx, const Def* val) {
31 auto& w = mem->world();
32 return w.app(w.app(w.annex<write>(), {r, s, T}), {mem, buf, idx, val});
33}
34
35/// `buffer.copy (r, s, T) (mem, dst, src)` ↦ `mem.M 0` (copies the whole buffer `src` into `dst`).
36inline const Def* op_copy(const Def* r, const Def* s, const Def* T, const Def* mem, const Def* dst, const Def* src) {
37 auto& w = mem->world();
38 return w.app(w.app(w.annex<copy>(), {r, s, T}), {mem, dst, src});
39}
40
41/// op_read with `(r, s, T)` read off the type of @p buf.
42inline const Def* op_read(const Def* mem, const Def* buf, const Def* idx) {
43 auto [r, s, T] = Axm::isa<Buf>(buf->type())->args<3>();
44 return op_read(r, s, T, mem, buf, idx);
45}
46
47/// op_write with `(r, s, T)` read off the type of @p buf.
48inline const Def* op_write(const Def* mem, const Def* buf, const Def* idx, const Def* val) {
49 auto [r, s, T] = Axm::isa<Buf>(buf->type())->args<3>();
50 return op_write(r, s, T, mem, buf, idx, val);
51}
52
53/// op_copy with `(r, s, T)` read off the type of @p dst.
54inline const Def* op_copy(const Def* mem, const Def* dst, const Def* src) {
55 auto [r, s, T] = Axm::isa<Buf>(dst->type())->args<3>();
56 return op_copy(r, s, T, mem, dst, src);
57}
58
59/// `buffer.free (r, s, T) (mem, buf)` ↦ `mem.M 0`.
60inline const Def* op_free(const Def* r, const Def* s, const Def* T, const Def* mem, const Def* buf) {
61 auto& w = mem->world();
62 return w.app(w.app(w.annex<free>(), {r, s, T}), {mem, buf});
63}
64
65/// `buffer.init (r, s, T) (mem, val)` ↦ `[mem.M 0, buffer.Buf (r, s, T)]` (initialised with the array value `val`).
66inline const Def* op_init(const Def* r, const Def* s, const Def* T, const Def* mem, const Def* val) {
67 auto& w = mem->world();
68 return w.app(w.app(w.annex<init>(), {r, s, T}), {mem, val});
69}
70
71/// `buffer.lit (r, s, T) (mem, val)` ↦ `[mem.M 0, buffer.Buf (r, s, T)]` (every element initialised to `val`).
72inline const Def* op_lit(const Def* r, const Def* s, const Def* T, const Def* mem, const Def* val) {
73 auto& w = mem->world();
74 return w.app(w.app(w.annex<lit>(), {r, s, T}), {mem, val});
75}
76
77} // namespace mim::plug::buffer
static auto isa(const Def *def)
Definition axm.h:112
Base class for all Defs.
Definition def.h:289
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
Definition def.h:1119
The buffer Plugin
Definition buffer.h:8
const Def * type_buf(const Def *r, const Def *s, const Def *T)
The buffer type buffer.Buf (r, s, T).
Definition buffer.h:11
const Def * op_free(const Def *r, const Def *s, const Def *T, const Def *mem, const Def *buf)
buffer.free (r, s, T) (mem, buf) ↦ mem.M 0.
Definition buffer.h:60
const Def * op_write(const Def *r, const Def *s, const Def *T, const Def *mem, const Def *buf, const Def *idx, const Def *val)
buffer.write (r, s, T) (mem, buf, idx, val) ↦ [mem.M 0, buffer.Buf (r, s, T)].
Definition buffer.h:30
const Def * op_lit(const Def *r, const Def *s, const Def *T, const Def *mem, const Def *val)
buffer.lit (r, s, T) (mem, val) ↦ [mem.M 0, buffer.Buf (r, s, T)] (every element initialised to val).
Definition buffer.h:72
const Def * op_read(const Def *r, const Def *s, const Def *T, const Def *mem, const Def *buf, const Def *idx)
buffer.read (r, s, T) (mem, buf, idx) ↦ [mem.M 0, T].
Definition buffer.h:23
const Def * op_init(const Def *r, const Def *s, const Def *T, const Def *mem, const Def *val)
buffer.init (r, s, T) (mem, val) ↦ [mem.M 0, buffer.Buf (r, s, T)] (initialised with the array value ...
Definition buffer.h:66
const Def * op_alloc(const Def *r, const Def *s, const Def *T, const Def *mem)
buffer.alloc (r, s, T) mem ↦ [mem.M 0, buffer.Buf (r, s, T)].
Definition buffer.h:17
const Def * op_copy(const Def *r, const Def *s, const Def *T, const Def *mem, const Def *dst, const Def *src)
buffer.copy (r, s, T) (mem, dst, src) ↦ mem.M 0 (copies the whole buffer src into dst).
Definition buffer.h:36
The mem Plugin