Skip to content

inline ConstGlobalRefs into ZigValue #3817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/all_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,6 @@ struct RuntimeHintSlice {
uint64_t len;
};

struct ConstGlobalRefs {
LLVMValueRef llvm_value;
LLVMValueRef llvm_global;
uint32_t align;
};

enum LazyValueId {
LazyValueIdInvalid,
LazyValueIdAlignOf,
Expand Down Expand Up @@ -409,8 +403,10 @@ struct LazyValueErrUnionType {
struct ZigValue {
ZigType *type;
ConstValSpecial special;
uint32_t llvm_align;
ConstParent parent;
ConstGlobalRefs *global_refs;
LLVMValueRef llvm_value;
LLVMValueRef llvm_global;

union {
// populated if special == ConstValSpecialStatic
Expand Down
29 changes: 6 additions & 23 deletions src/analyze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5909,12 +5909,7 @@ ZigValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_


ZigValue *create_const_vals(size_t count) {
ConstGlobalRefs *global_refs = allocate<ConstGlobalRefs>(count, "ConstGlobalRefs");
ZigValue *vals = allocate<ZigValue>(count, "ZigValue");
for (size_t i = 0; i < count; i += 1) {
vals[i].global_refs = &global_refs[i];
}
return vals;
return allocate<ZigValue>(count, "ZigValue");
}

ZigValue **alloc_const_vals_ptrs(size_t count) {
Expand Down Expand Up @@ -6492,48 +6487,36 @@ bool const_values_equal_ptr(ZigValue *a, ZigValue *b) {
return false;
return true;
case ConstPtrSpecialBaseArray:
if (a->data.x_ptr.data.base_array.array_val != b->data.x_ptr.data.base_array.array_val &&
a->data.x_ptr.data.base_array.array_val->global_refs !=
b->data.x_ptr.data.base_array.array_val->global_refs)
{
if (a->data.x_ptr.data.base_array.array_val != b->data.x_ptr.data.base_array.array_val) {
return false;
}
if (a->data.x_ptr.data.base_array.elem_index != b->data.x_ptr.data.base_array.elem_index)
return false;
return true;
case ConstPtrSpecialBaseStruct:
if (a->data.x_ptr.data.base_struct.struct_val != b->data.x_ptr.data.base_struct.struct_val &&
a->data.x_ptr.data.base_struct.struct_val->global_refs !=
b->data.x_ptr.data.base_struct.struct_val->global_refs)
{
if (a->data.x_ptr.data.base_struct.struct_val != b->data.x_ptr.data.base_struct.struct_val) {
return false;
}
if (a->data.x_ptr.data.base_struct.field_index != b->data.x_ptr.data.base_struct.field_index)
return false;
return true;
case ConstPtrSpecialBaseErrorUnionCode:
if (a->data.x_ptr.data.base_err_union_code.err_union_val !=
b->data.x_ptr.data.base_err_union_code.err_union_val &&
a->data.x_ptr.data.base_err_union_code.err_union_val->global_refs !=
b->data.x_ptr.data.base_err_union_code.err_union_val->global_refs)
b->data.x_ptr.data.base_err_union_code.err_union_val)
{
return false;
}
return true;
case ConstPtrSpecialBaseErrorUnionPayload:
if (a->data.x_ptr.data.base_err_union_payload.err_union_val !=
b->data.x_ptr.data.base_err_union_payload.err_union_val &&
a->data.x_ptr.data.base_err_union_payload.err_union_val->global_refs !=
b->data.x_ptr.data.base_err_union_payload.err_union_val->global_refs)
b->data.x_ptr.data.base_err_union_payload.err_union_val)
{
return false;
}
return true;
case ConstPtrSpecialBaseOptionalPayload:
if (a->data.x_ptr.data.base_optional_payload.optional_val !=
b->data.x_ptr.data.base_optional_payload.optional_val &&
a->data.x_ptr.data.base_optional_payload.optional_val->global_refs !=
b->data.x_ptr.data.base_optional_payload.optional_val->global_refs)
b->data.x_ptr.data.base_optional_payload.optional_val)
{
return false;
}
Expand Down
Loading