aboutsummaryrefslogtreecommitdiff
path: root/src/llvm_backend.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2022-09-21 11:36:14 +0100
committergingerBill <bill@gingerbill.org>2022-09-21 11:36:14 +0100
commit5337413c5605655847767105f609d74a357984da (patch)
tree7723f6f6c9ba819db2585c6a660e49de676f8c69 /src/llvm_backend.cpp
parent380905618af96ab784f23b2fcd6a3c3c3b8310fd (diff)
Temporary patch for `lb_gen_map_header`
Diffstat (limited to 'src/llvm_backend.cpp')
-rw-r--r--src/llvm_backend.cpp92
1 files changed, 53 insertions, 39 deletions
diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp
index 142ecc348..9594e9d86 100644
--- a/src/llvm_backend.cpp
+++ b/src/llvm_backend.cpp
@@ -500,59 +500,73 @@ lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &prefix_name, A
return value;
}
-lbValue lb_gen_map_header(lbProcedure *p, lbValue map_val_ptr, Type *map_type) {
- GB_ASSERT_MSG(is_type_pointer(map_val_ptr.type), "%s", type_to_string(map_val_ptr.type));
+lbAddr lb_gen_map_header_internal(lbProcedure *p, lbValue map_val_ptr, Type *map_type) {
map_type = base_type(map_type);
GB_ASSERT(map_type->kind == Type_Map);
- lbAddr h = {};
- lbAddr *found = map_get(&p->map_header_cache, map_val_ptr.value);
- if (found != nullptr) {
- h = *found;
- } else {
- h = lb_add_local_generated(p, t_map_header, false); // all the values will be initialzed later
+ lbAddr h = lb_add_local_generated(p, t_map_header, true); // all the values will be initialzed later
+
+ Type *key_type = map_type->Map.key;
+ Type *val_type = map_type->Map.value;
+ gb_unused(val_type);
+
+ GB_ASSERT(map_type->Map.entry_type->kind == Type_Struct);
+ map_type->Map.entry_type->cached_size = -1;
+ map_type->Map.entry_type->Struct.are_offsets_set = false;
+
+ i64 entry_size = type_size_of (map_type->Map.entry_type);
+ i64 entry_align = type_align_of (map_type->Map.entry_type);
- Type *key_type = map_type->Map.key;
- Type *val_type = map_type->Map.value;
- gb_unused(val_type);
+ i64 key_offset = type_offset_of(map_type->Map.entry_type, 2);
+ i64 key_size = type_size_of (map_type->Map.key);
- GB_ASSERT(map_type->Map.entry_type->kind == Type_Struct);
- map_type->Map.entry_type->cached_size = -1;
- map_type->Map.entry_type->Struct.are_offsets_set = false;
+ i64 value_offset = type_offset_of(map_type->Map.entry_type, 3);
+ i64 value_size = type_size_of (map_type->Map.value);
- i64 entry_size = type_size_of (map_type->Map.entry_type);
- i64 entry_align = type_align_of (map_type->Map.entry_type);
- i64 key_offset = type_offset_of(map_type->Map.entry_type, 2);
- i64 key_size = type_size_of (map_type->Map.key);
+ Type *map_header_base = base_type(t_map_header);
+ GB_ASSERT(map_header_base->Struct.fields.count == 8);
+ Type *raw_map_ptr_type = map_header_base->Struct.fields[0]->type;
+ LLVMValueRef const_values[8] = {};
+ const_values[0] = LLVMConstNull(lb_type(p->module, raw_map_ptr_type));
+ const_values[1] = lb_get_equal_proc_for_type(p->module, key_type) .value;
+ const_values[2] = lb_const_int(p->module, t_int, entry_size) .value;
+ const_values[3] = lb_const_int(p->module, t_int, entry_align) .value;
+ const_values[4] = lb_const_int(p->module, t_uintptr, key_offset) .value;
+ const_values[5] = lb_const_int(p->module, t_int, key_size) .value;
+ const_values[6] = lb_const_int(p->module, t_uintptr, value_offset).value;
+ const_values[7] = lb_const_int(p->module, t_int, value_size) .value;
- i64 value_offset = type_offset_of(map_type->Map.entry_type, 3);
- i64 value_size = type_size_of (map_type->Map.value);
+ LLVMValueRef const_value = llvm_const_named_struct(p->module, t_map_header, const_values, gb_count_of(const_values));
+ LLVMBuildStore(p->builder, const_value, h.addr.value);
+ // NOTE(bill): Removes unnecessary allocation if split gep
+ lbValue gep0 = lb_emit_struct_ep(p, h.addr, 0);
+ lbValue m = lb_emit_conv(p, map_val_ptr, type_deref(gep0.type));
+ lb_emit_store(p, gep0, m);
+ return h;
+}
- Type *map_header_base = base_type(t_map_header);
- GB_ASSERT(map_header_base->Struct.fields.count == 8);
- Type *raw_map_ptr_type = map_header_base->Struct.fields[0]->type;
- LLVMValueRef const_values[8] = {};
- const_values[0] = LLVMConstNull(lb_type(p->module, raw_map_ptr_type));
- const_values[1] = lb_get_equal_proc_for_type(p->module, key_type) .value;
- const_values[2] = lb_const_int(p->module, t_int, entry_size) .value;
- const_values[3] = lb_const_int(p->module, t_int, entry_align) .value;
- const_values[4] = lb_const_int(p->module, t_uintptr, key_offset) .value;
- const_values[5] = lb_const_int(p->module, t_int, key_size) .value;
- const_values[6] = lb_const_int(p->module, t_uintptr, value_offset).value;
- const_values[7] = lb_const_int(p->module, t_int, value_size) .value;
- LLVMValueRef const_value = llvm_const_named_struct(p->module, t_map_header, const_values, gb_count_of(const_values));
- LLVMBuildStore(p->builder, const_value, h.addr.value);
+lbValue lb_gen_map_header(lbProcedure *p, lbValue map_val_ptr, Type *map_type) {
+ GB_ASSERT_MSG(is_type_pointer(map_val_ptr.type), "%s", type_to_string(map_val_ptr.type));
+ GB_ASSERT(is_type_map(map_type));
- // NOTE(bill): Removes unnecessary allocation if split gep
- lbValue gep0 = lb_emit_struct_ep(p, h.addr, 0);
- lbValue m = lb_emit_conv(p, map_val_ptr, type_deref(gep0.type));
- lb_emit_store(p, gep0, m);
+ // TODO(bill): this is a temporary fix since this caching is not working other platforms
+ bool allow_caching = build_context.metrics.os == TargetOs_windows || is_arch_wasm();
- map_set(&p->map_header_cache, map_val_ptr.value, h);
+ lbAddr h = {};
+ if (!allow_caching) {
+ h = lb_gen_map_header_internal(p, map_val_ptr, map_type);
+ } else {
+ lbAddr *found = map_get(&p->map_header_cache, map_val_ptr.value);
+ if (found != nullptr) {
+ h = *found;
+ } else {
+ h = lb_gen_map_header_internal(p, map_val_ptr, map_type);
+ map_set(&p->map_header_cache, map_val_ptr.value, h);
+ }
}
return lb_addr_load(p, h);