24Ref op_lea_tuple(Ref arr, Ref tuple) {
25 auto& world = arr->world();
26 world.DLOG(
"op_lea_tuple arr {} : {}", arr, arr->type());
27 auto n = tuple->num_projs();
29 for (
size_t i = 0; i < n; ++i) element =
mem::op_lea(element, tuple->proj(n, i));
33Ref op_pack_tuple(
u64 n, Ref tuple, Ref val) {
34 auto& world = val->
world();
37 for (
int i = n - 1; i >= 0; i--) {
38 auto dim = tuple->proj(n, i);
39 element = world.pack(dim, element);
41 world.DLOG(
"op_pack_tuple: {} -> {}", val, element);
42 world.DLOG(
" for tuple: {} : {}", tuple, tuple->type());
46Ref arr_ty_of_matrix_ty(Ref S, Ref T) {
47 auto& world =
S->world();
48 auto n =
S->num_projs();
50 for (
int i = n - 1; i >= 0; i--) {
51 auto dim =
S->proj(n, i);
52 arr_ty = world.arr(dim, arr_ty);
61 assert(!
match<matrix::shape>(def) &&
"high level operations should have been lowered to for loops by now");
62 assert(!
match<matrix::prod>(def) &&
"high level operations should have been lowered to for loops by now");
64 assert(!
match<matrix::sum>(def) &&
"high level operations should have been lowered to for loops by now");
68 auto [_, S, T] = mat_ax->args<3>();
71 auto arr_ty = arr_ty_of_matrix_ty(S, T);
78 world().DLOG(
"init {} : {}", def, def->
type());
79 auto [_, S, T,
mem] = init_ax->args<4>();
80 world().DLOG(
" S T mem {} {} {}", S, T,
mem);
84 world().DLOG(
" S T mem {} {} {}", S, T,
mem);
85 auto arr_ty = arr_ty_of_matrix_ty(S, T);
88 world().DLOG(
" res {} : {}", res, res->type());
91 auto [
mem, mat, idx] = read_ax->args<3>();
92 world().DLOG(
"read_ax: {}", read_ax);
94 world().DLOG(
" mat: {} : {}", mat, mat->type());
95 world().DLOG(
" idx: {} : {}", idx, idx->type());
99 world().DLOG(
"rewritten read");
101 world().DLOG(
" mat: {} : {}", mat, mat->type());
102 world().DLOG(
" idx: {} : {}", idx, idx->type());
105 auto element_ptr = op_lea_tuple(ptr_mat, idx);
109 auto [
mem, mat, idx, val] = insert_ax->args<4>();
110 world().DLOG(
"insert_ax: {}", insert_ax);
112 world().DLOG(
" mat: {} : {}", mat, mat->type());
113 world().DLOG(
" idx: {} : {}", idx, idx->type());
114 world().DLOG(
" val: {} : {}", val, val->type());
119 world().DLOG(
"rewritten insert");
121 world().DLOG(
" mat: {} : {}", mat, mat->type());
122 world().DLOG(
" idx: {} : {}", idx, idx->type());
123 world().DLOG(
" val: {} : {}", val, val->type());
125 auto element_ptr = op_lea_tuple(ptr_mat, idx);
129 auto [
mem, val] = const_ax->args<2>();
132 auto [n_def, S, T] = const_ax->callee()->as<
App>()->args<3>();
135 auto arr_ty = arr_ty_of_matrix_ty(S, T);
139 auto n = n_def->as<
Lit>()->get<u64>();
140 auto initial = op_pack_tuple(n, S, val);
148 if (def->isa<
Axiom>())
return 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...
Ref type() const noexcept
Yields the raw type of this Def, i.e. maybe nullptr.
Helper class to retrieve Infer::arg if present.
virtual Ref rewrite_imm(Ref)
This is a thin wrapper for std::span<T, N> with the following additional features:
const Def * call(Id id, Args &&... args)
Complete curried call of annexes obeying implicits.
Ref rewrite_imm(Ref) override
Ref op_alloc(Ref type, Ref mem)
Ref op_lea(Ref ptr, Ref index)