mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-09 00:58:16 +00:00
Temporary patch for lb_gen_map_header
This commit is contained in:
+22
-8
@@ -500,17 +500,11 @@ 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;
|
||||
@@ -550,10 +544,30 @@ lbValue lb_gen_map_header(lbProcedure *p, lbValue map_val_ptr, Type *map_type) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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));
|
||||
|
||||
|
||||
// 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();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user