mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
mem zero rather than store to a union where the variant is of size zero
This commit is contained in:
@@ -550,6 +550,7 @@ gb_internal LLVMValueRef lb_call_intrinsic(lbProcedure *p, const char *name, LLV
|
|||||||
gb_internal void lb_mem_copy_overlapping(lbProcedure *p, lbValue dst, lbValue src, lbValue len, bool is_volatile=false);
|
gb_internal void lb_mem_copy_overlapping(lbProcedure *p, lbValue dst, lbValue src, lbValue len, bool is_volatile=false);
|
||||||
gb_internal void lb_mem_copy_non_overlapping(lbProcedure *p, lbValue dst, lbValue src, lbValue len, bool is_volatile=false);
|
gb_internal void lb_mem_copy_non_overlapping(lbProcedure *p, lbValue dst, lbValue src, lbValue len, bool is_volatile=false);
|
||||||
gb_internal LLVMValueRef lb_mem_zero_ptr_internal(lbProcedure *p, LLVMValueRef ptr, LLVMValueRef len, unsigned alignment, bool is_volatile);
|
gb_internal LLVMValueRef lb_mem_zero_ptr_internal(lbProcedure *p, LLVMValueRef ptr, LLVMValueRef len, unsigned alignment, bool is_volatile);
|
||||||
|
gb_internal LLVMValueRef lb_mem_zero_ptr_internal(lbProcedure *p, LLVMValueRef ptr, usize len, unsigned alignment, bool is_volatile);
|
||||||
|
|
||||||
gb_internal gb_inline i64 lb_max_zero_init_size(void) {
|
gb_internal gb_inline i64 lb_max_zero_init_size(void) {
|
||||||
return cast(i64)(4*build_context.int_size);
|
return cast(i64)(4*build_context.int_size);
|
||||||
|
|||||||
@@ -1332,6 +1332,8 @@ gb_internal void lb_emit_store_union_variant(lbProcedure *p, lbValue parent, lbV
|
|||||||
Type *pt = base_type(type_deref(parent.type));
|
Type *pt = base_type(type_deref(parent.type));
|
||||||
GB_ASSERT(pt->kind == Type_Union);
|
GB_ASSERT(pt->kind == Type_Union);
|
||||||
if (pt->Union.kind == UnionType_shared_nil) {
|
if (pt->Union.kind == UnionType_shared_nil) {
|
||||||
|
GB_ASSERT(type_size_of(variant_type));
|
||||||
|
|
||||||
lbBlock *if_nil = lb_create_block(p, "shared_nil.if_nil");
|
lbBlock *if_nil = lb_create_block(p, "shared_nil.if_nil");
|
||||||
lbBlock *if_not_nil = lb_create_block(p, "shared_nil.if_not_nil");
|
lbBlock *if_not_nil = lb_create_block(p, "shared_nil.if_not_nil");
|
||||||
lbBlock *done = lb_create_block(p, "shared_nil.done");
|
lbBlock *done = lb_create_block(p, "shared_nil.done");
|
||||||
@@ -1353,9 +1355,13 @@ gb_internal void lb_emit_store_union_variant(lbProcedure *p, lbValue parent, lbV
|
|||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
lbValue underlying = lb_emit_conv(p, parent, alloc_type_pointer(variant_type));
|
if (type_size_of(variant_type) == 0) {
|
||||||
|
unsigned alignment = 1;
|
||||||
lb_emit_store(p, underlying, variant);
|
lb_mem_zero_ptr_internal(p, parent.value, pt->Union.variant_block_size, alignment, false);
|
||||||
|
} else {
|
||||||
|
lbValue underlying = lb_emit_conv(p, parent, alloc_type_pointer(variant_type));
|
||||||
|
lb_emit_store(p, underlying, variant);
|
||||||
|
}
|
||||||
lb_emit_store_union_variant_tag(p, parent, variant_type);
|
lb_emit_store_union_variant_tag(p, parent, variant_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,10 @@ gb_internal lbValue lb_correct_endianness(lbProcedure *p, lbValue value) {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gb_internal LLVMValueRef lb_mem_zero_ptr_internal(lbProcedure *p, LLVMValueRef ptr, usize len, unsigned alignment, bool is_volatile) {
|
||||||
|
return lb_mem_zero_ptr_internal(p, ptr, LLVMConstInt(lb_type(p->module, t_uint), len, false), alignment, is_volatile);
|
||||||
|
}
|
||||||
|
|
||||||
gb_internal LLVMValueRef lb_mem_zero_ptr_internal(lbProcedure *p, LLVMValueRef ptr, LLVMValueRef len, unsigned alignment, bool is_volatile) {
|
gb_internal LLVMValueRef lb_mem_zero_ptr_internal(lbProcedure *p, LLVMValueRef ptr, LLVMValueRef len, unsigned alignment, bool is_volatile) {
|
||||||
bool is_inlinable = false;
|
bool is_inlinable = false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user