19const Def* op_lea_tuple(
const Def* arr,
const Def* tuple) {
20 auto& world = arr->world();
21 world.DLOG(
"op_lea_tuple arr {} : {}", arr, arr->type());
22 auto n = tuple->num_projs();
24 for (
size_t i = 0; i < n; ++i) element =
mem::op_lea(element, tuple->proj(n, i));
28const Def* op_pack_tuple(
u64 n,
const Def* tuple,
const Def* val) {
29 auto& world = val->
world();
32 for (
int i = n - 1; i >= 0; i--) {
33 auto dim = tuple->proj(n, i);
34 element = world.pack(dim, element);
36 world.DLOG(
"op_pack_tuple: {} -> {}", val, element);
37 world.DLOG(
" for tuple: {} : {}", tuple, tuple->type());
41const Def* arr_ty_of_matrix_ty(
const Def* S,
const Def* T) {
42 auto& world =
S->world();
43 auto n =
S->num_projs();
45 for (
int i = n - 1; i >= 0; i--) {
46 auto dim =
S->proj(n, i);
47 arr_ty = world.arr(dim, arr_ty);
57 assert(!
Axm::isa<matrix::prod>(def) &&
"high level operations should have been lowered to for loops by now");
59 assert(!
Axm::isa<matrix::sum>(def) &&
"high level operations should have been lowered to for loops by now");
63 auto [_, S, T] = mat_ax->args<3>();
66 auto arr_ty = arr_ty_of_matrix_ty(S, T);
73 world().DLOG(
"init {} : {}", def, def->
type());
74 auto [_, S, T,
mem] = init_ax->args<4>();
75 world().DLOG(
" S T mem {} {} {}", S, T,
mem);
79 world().DLOG(
" S T mem {} {} {}", S, T,
mem);
80 auto arr_ty = arr_ty_of_matrix_ty(S, T);
83 world().DLOG(
" res {} : {}", res, res->type());
86 auto [
mem, mat, idx] = read_ax->args<3>();
87 world().DLOG(
"read_ax: {}", read_ax);
89 world().DLOG(
" mat: {} : {}", mat, mat->type());
90 world().DLOG(
" idx: {} : {}", idx, idx->type());
94 world().DLOG(
"rewritten read");
96 world().DLOG(
" mat: {} : {}", mat, mat->type());
97 world().DLOG(
" idx: {} : {}", idx, idx->type());
100 auto element_ptr = op_lea_tuple(ptr_mat, idx);
104 auto [
mem, mat, idx, val] = insert_ax->args<4>();
105 world().DLOG(
"insert_ax: {}", insert_ax);
107 world().DLOG(
" mat: {} : {}", mat, mat->type());
108 world().DLOG(
" idx: {} : {}", idx, idx->type());
109 world().DLOG(
" val: {} : {}", val, val->type());
114 world().DLOG(
"rewritten insert");
116 world().DLOG(
" mat: {} : {}", mat, mat->type());
117 world().DLOG(
" idx: {} : {}", idx, idx->type());
118 world().DLOG(
" val: {} : {}", val, val->type());
120 auto element_ptr = op_lea_tuple(ptr_mat, idx);
124 auto [
mem, val] = const_ax->args<2>();
127 auto [n_def, S, T] = const_ax->callee()->as<
App>()->args<3>();
130 auto arr_ty = arr_ty_of_matrix_ty(S, T);
135 auto initial = op_pack_tuple(n, S, val);
143 if (def->isa<
Axm>())
return def;
static auto isa(const Def *def)
World & world() const noexcept
auto projs(F f) const
Splits this Def via Def::projections into an Array (if A == std::dynamic_extent) or std::array (other...
const Def * type() const noexcept
Yields the "raw" type of this Def (maybe nullptr).
virtual const Def * rewrite_imm(const Def *)
virtual const Def * rewrite(const Def *)
const Def * tuple(Defs ops)
const Def * call(Id id, Args &&... args)
Complete curried call of annexes obeying implicits.
const Def * rewrite_imm(const Def *) override
const Def * op_lea(const Def *ptr, const Def *index)
const Def * op_alloc(const Def *type, const Def *mem)
constexpr decltype(auto) get(Span< T, N > span) noexcept