aboutsummaryrefslogtreecommitdiff
path: root/src/llvm_backend_stmt.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2022-11-08 14:58:05 +0000
committergingerBill <bill@gingerbill.org>2022-11-08 14:58:05 +0000
commita71daee545f5425aae971c0e00d7064fe53d64c7 (patch)
tree0509041a757de626760408684e2db4c1b22678b3 /src/llvm_backend_stmt.cpp
parent046dd5503211c617a88d7de7d089dd5b74e63500 (diff)
Allow for `-use-static-map-calls` which generates a get procedure per `map`; add `runtime.map_get`
Diffstat (limited to 'src/llvm_backend_stmt.cpp')
-rw-r--r--src/llvm_backend_stmt.cpp26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/llvm_backend_stmt.cpp b/src/llvm_backend_stmt.cpp
index 3e4846f02..6b83068ce 100644
--- a/src/llvm_backend_stmt.cpp
+++ b/src/llvm_backend_stmt.cpp
@@ -371,24 +371,30 @@ void lb_build_range_indexed(lbProcedure *p, lbValue expr, Type *val_type, lbValu
}
lbValue lb_map_cell_index_static(lbProcedure *p, Type *type, lbValue cells_ptr, lbValue index) {
- i64 size, N;
- i64 sz = type_size_of(type);
- map_cell_size_and_len(type, &size, &N);
+ i64 size, len;
+ i64 elem_sz = type_size_of(type);
+ map_cell_size_and_len(type, &size, &len);
- index = lb_emit_conv(p, index, t_uint);
+ index = lb_emit_conv(p, index, t_uintptr);
- if (size == N*sz) {
+ if (size == len*elem_sz) {
lbValue elems_ptr = lb_emit_conv(p, cells_ptr, alloc_type_pointer(type));
return lb_emit_ptr_offset(p, elems_ptr, index);
}
// TOOD(bill): N power of two optimization to use >> and &
- lbValue N_const = lb_const_int(p->module, index.type, N);
- lbValue cell_index = lb_emit_arith(p, Token_Quo, index, N_const, index.type);
- lbValue data_index = lb_emit_arith(p, Token_Mod, index, N_const, index.type);
- lbValue cell = lb_emit_ptr_offset(p, cells_ptr, cell_index);
- lbValue elems_ptr = lb_emit_conv(p, cell, alloc_type_pointer(type));
+ lbValue size_const = lb_const_int(p->module, t_uintptr, size);
+ lbValue len_const = lb_const_int(p->module, t_uintptr, len);
+ lbValue cell_index = lb_emit_arith(p, Token_Quo, index, len_const, t_uintptr);
+ lbValue data_index = lb_emit_arith(p, Token_Mod, index, len_const, t_uintptr);
+
+ lbValue elems_ptr = lb_emit_conv(p, cells_ptr, t_uintptr);
+ lbValue cell_offset = lb_emit_arith(p, Token_Mul, size_const, cell_index, t_uintptr);
+ elems_ptr = lb_emit_arith(p, Token_Add, elems_ptr, cell_offset, t_uintptr);
+
+ elems_ptr = lb_emit_conv(p, elems_ptr, alloc_type_pointer(type));
+
return lb_emit_ptr_offset(p, elems_ptr, data_index);
}