gb_internal LLVM backend

This commit is contained in:
gingerBill
2022-12-18 22:32:05 +00:00
parent 66ce990e0b
commit 6cdec65ca1
12 changed files with 627 additions and 628 deletions
+77 -77
View File
@@ -18,21 +18,21 @@ struct lbArgType {
}; };
i64 lb_sizeof(LLVMTypeRef type); gb_internal i64 lb_sizeof(LLVMTypeRef type);
i64 lb_alignof(LLVMTypeRef type); gb_internal i64 lb_alignof(LLVMTypeRef type);
lbArgType lb_arg_type_direct(LLVMTypeRef type, LLVMTypeRef cast_type, LLVMTypeRef pad_type, LLVMAttributeRef attr) { gb_internal lbArgType lb_arg_type_direct(LLVMTypeRef type, LLVMTypeRef cast_type, LLVMTypeRef pad_type, LLVMAttributeRef attr) {
return lbArgType{lbArg_Direct, type, cast_type, pad_type, attr, nullptr, 0, false}; return lbArgType{lbArg_Direct, type, cast_type, pad_type, attr, nullptr, 0, false};
} }
lbArgType lb_arg_type_direct(LLVMTypeRef type) { gb_internal lbArgType lb_arg_type_direct(LLVMTypeRef type) {
return lb_arg_type_direct(type, nullptr, nullptr, nullptr); return lb_arg_type_direct(type, nullptr, nullptr, nullptr);
} }
lbArgType lb_arg_type_indirect(LLVMTypeRef type, LLVMAttributeRef attr) { gb_internal lbArgType lb_arg_type_indirect(LLVMTypeRef type, LLVMAttributeRef attr) {
return lbArgType{lbArg_Indirect, type, nullptr, nullptr, attr, nullptr, 0, false}; return lbArgType{lbArg_Indirect, type, nullptr, nullptr, attr, nullptr, 0, false};
} }
lbArgType lb_arg_type_indirect_byval(LLVMContextRef c, LLVMTypeRef type) { gb_internal lbArgType lb_arg_type_indirect_byval(LLVMContextRef c, LLVMTypeRef type) {
i64 alignment = lb_alignof(type); i64 alignment = lb_alignof(type);
alignment = gb_max(alignment, 8); alignment = gb_max(alignment, 8);
@@ -41,7 +41,7 @@ lbArgType lb_arg_type_indirect_byval(LLVMContextRef c, LLVMTypeRef type) {
return lbArgType{lbArg_Indirect, type, nullptr, nullptr, byval_attr, align_attr, alignment, true}; return lbArgType{lbArg_Indirect, type, nullptr, nullptr, byval_attr, align_attr, alignment, true};
} }
lbArgType lb_arg_type_ignore(LLVMTypeRef type) { gb_internal lbArgType lb_arg_type_ignore(LLVMTypeRef type) {
return lbArgType{lbArg_Ignore, type, nullptr, nullptr, nullptr, nullptr, 0, false}; return lbArgType{lbArg_Ignore, type, nullptr, nullptr, nullptr, nullptr, 0, false};
} }
@@ -55,24 +55,24 @@ struct lbFunctionType {
isize original_arg_count; isize original_arg_count;
}; };
gbAllocator lb_function_type_args_allocator(void) { gb_internal gbAllocator lb_function_type_args_allocator(void) {
return heap_allocator(); return heap_allocator();
} }
i64 llvm_align_formula(i64 off, i64 a) { gb_internal gb_inline i64 llvm_align_formula(i64 off, i64 a) {
return (off + a - 1) / a * a; return (off + a - 1) / a * a;
} }
bool lb_is_type_kind(LLVMTypeRef type, LLVMTypeKind kind) { gb_internal bool lb_is_type_kind(LLVMTypeRef type, LLVMTypeKind kind) {
if (type == nullptr) { if (type == nullptr) {
return false; return false;
} }
return LLVMGetTypeKind(type) == kind; return LLVMGetTypeKind(type) == kind;
} }
LLVMTypeRef lb_function_type_to_llvm_raw(lbFunctionType *ft, bool is_var_arg) { gb_internal LLVMTypeRef lb_function_type_to_llvm_raw(lbFunctionType *ft, bool is_var_arg) {
unsigned arg_count = cast(unsigned)ft->args.count; unsigned arg_count = cast(unsigned)ft->args.count;
unsigned offset = 0; unsigned offset = 0;
@@ -130,7 +130,7 @@ LLVMTypeRef lb_function_type_to_llvm_raw(lbFunctionType *ft, bool is_var_arg) {
// } // }
void lb_add_function_type_attributes(LLVMValueRef fn, lbFunctionType *ft, ProcCallingConvention calling_convention) { gb_internal void lb_add_function_type_attributes(LLVMValueRef fn, lbFunctionType *ft, ProcCallingConvention calling_convention) {
if (ft == nullptr) { if (ft == nullptr) {
return; return;
} }
@@ -201,7 +201,7 @@ void lb_add_function_type_attributes(LLVMValueRef fn, lbFunctionType *ft, ProcCa
} }
i64 lb_sizeof(LLVMTypeRef type) { gb_internal i64 lb_sizeof(LLVMTypeRef type) {
LLVMTypeKind kind = LLVMGetTypeKind(type); LLVMTypeKind kind = LLVMGetTypeKind(type);
switch (kind) { switch (kind) {
case LLVMVoidTypeKind: case LLVMVoidTypeKind:
@@ -267,7 +267,7 @@ i64 lb_sizeof(LLVMTypeRef type) {
return 0; return 0;
} }
i64 lb_alignof(LLVMTypeRef type) { gb_internal i64 lb_alignof(LLVMTypeRef type) {
LLVMTypeKind kind = LLVMGetTypeKind(type); LLVMTypeKind kind = LLVMGetTypeKind(type);
switch (kind) { switch (kind) {
case LLVMVoidTypeKind: case LLVMVoidTypeKind:
@@ -333,7 +333,7 @@ typedef LB_ABI_INFO(lbAbiInfoType);
typedef LB_ABI_COMPUTE_RETURN_TYPE(lbAbiComputeReturnType); typedef LB_ABI_COMPUTE_RETURN_TYPE(lbAbiComputeReturnType);
lbArgType lb_abi_modify_return_is_tuple(lbFunctionType *ft, LLVMContextRef c, LLVMTypeRef return_type, lbAbiComputeReturnType *compute_return_type) { gb_internal lbArgType lb_abi_modify_return_is_tuple(lbFunctionType *ft, LLVMContextRef c, LLVMTypeRef return_type, lbAbiComputeReturnType *compute_return_type) {
GB_ASSERT(return_type != nullptr); GB_ASSERT(return_type != nullptr);
GB_ASSERT(compute_return_type != nullptr); GB_ASSERT(compute_return_type != nullptr);
@@ -370,10 +370,10 @@ lbArgType lb_abi_modify_return_is_tuple(lbFunctionType *ft, LLVMContextRef c, LL
// NOTE(bill): I hate `namespace` in C++ but this is just because I don't want to prefix everything // NOTE(bill): I hate `namespace` in C++ but this is just because I don't want to prefix everything
namespace lbAbi386 { namespace lbAbi386 {
Array<lbArgType> compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count); gb_internal Array<lbArgType> compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count);
LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type); gb_internal LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type);
LB_ABI_INFO(abi_info) { gb_internal LB_ABI_INFO(abi_info) {
lbFunctionType *ft = gb_alloc_item(permanent_allocator(), lbFunctionType); lbFunctionType *ft = gb_alloc_item(permanent_allocator(), lbFunctionType);
ft->ctx = c; ft->ctx = c;
ft->args = compute_arg_types(c, arg_types, arg_count); ft->args = compute_arg_types(c, arg_types, arg_count);
@@ -382,7 +382,7 @@ namespace lbAbi386 {
return ft; return ft;
} }
lbArgType non_struct(LLVMContextRef c, LLVMTypeRef type, bool is_return) { gb_internal lbArgType non_struct(LLVMContextRef c, LLVMTypeRef type, bool is_return) {
if (!is_return && lb_sizeof(type) > 8) { if (!is_return && lb_sizeof(type) > 8) {
return lb_arg_type_indirect(type, nullptr); return lb_arg_type_indirect(type, nullptr);
} }
@@ -409,7 +409,7 @@ namespace lbAbi386 {
return lb_arg_type_direct(type, nullptr, nullptr, attr); return lb_arg_type_direct(type, nullptr, nullptr, attr);
} }
Array<lbArgType> compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count) { gb_internal Array<lbArgType> compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count) {
auto args = array_make<lbArgType>(lb_function_type_args_allocator(), arg_count); auto args = array_make<lbArgType>(lb_function_type_args_allocator(), arg_count);
for (unsigned i = 0; i < arg_count; i++) { for (unsigned i = 0; i < arg_count; i++) {
@@ -429,7 +429,7 @@ namespace lbAbi386 {
return args; return args;
} }
LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type) { gb_internal LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type) {
if (!return_is_defined) { if (!return_is_defined) {
return lb_arg_type_direct(LLVMVoidTypeInContext(c)); return lb_arg_type_direct(LLVMVoidTypeInContext(c));
} else if (lb_is_type_kind(return_type, LLVMStructTypeKind) || lb_is_type_kind(return_type, LLVMArrayTypeKind)) { } else if (lb_is_type_kind(return_type, LLVMStructTypeKind) || lb_is_type_kind(return_type, LLVMArrayTypeKind)) {
@@ -451,10 +451,10 @@ namespace lbAbi386 {
}; };
namespace lbAbiAmd64Win64 { namespace lbAbiAmd64Win64 {
Array<lbArgType> compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count); gb_internal Array<lbArgType> compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count);
LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type); gb_internal LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type);
LB_ABI_INFO(abi_info) { gb_internal LB_ABI_INFO(abi_info) {
lbFunctionType *ft = gb_alloc_item(permanent_allocator(), lbFunctionType); lbFunctionType *ft = gb_alloc_item(permanent_allocator(), lbFunctionType);
ft->ctx = c; ft->ctx = c;
ft->args = compute_arg_types(c, arg_types, arg_count); ft->args = compute_arg_types(c, arg_types, arg_count);
@@ -463,7 +463,7 @@ namespace lbAbiAmd64Win64 {
return ft; return ft;
} }
Array<lbArgType> compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count) { gb_internal Array<lbArgType> compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count) {
auto args = array_make<lbArgType>(lb_function_type_args_allocator(), arg_count); auto args = array_make<lbArgType>(lb_function_type_args_allocator(), arg_count);
for (unsigned i = 0; i < arg_count; i++) { for (unsigned i = 0; i < arg_count; i++) {
@@ -489,7 +489,7 @@ namespace lbAbiAmd64Win64 {
return args; return args;
} }
LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type) { gb_internal LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type) {
if (!return_is_defined) { if (!return_is_defined) {
return lb_arg_type_direct(LLVMVoidTypeInContext(c)); return lb_arg_type_direct(LLVMVoidTypeInContext(c));
} else if (lb_is_type_kind(return_type, LLVMStructTypeKind) || lb_is_type_kind(return_type, LLVMArrayTypeKind)) { } else if (lb_is_type_kind(return_type, LLVMStructTypeKind) || lb_is_type_kind(return_type, LLVMArrayTypeKind)) {
@@ -530,7 +530,7 @@ namespace lbAbiAmd64SysV {
RegClass_Memory, RegClass_Memory,
}; };
bool is_sse(RegClass reg_class) { gb_internal bool is_sse(RegClass reg_class) {
switch (reg_class) { switch (reg_class) {
case RegClass_SSEFs: case RegClass_SSEFs:
case RegClass_SSEFv: case RegClass_SSEFv:
@@ -546,7 +546,7 @@ namespace lbAbiAmd64SysV {
return false; return false;
} }
void all_mem(Array<RegClass> *cs) { gb_internal void all_mem(Array<RegClass> *cs) {
for_array(i, *cs) { for_array(i, *cs) {
(*cs)[i] = RegClass_Memory; (*cs)[i] = RegClass_Memory;
} }
@@ -558,14 +558,14 @@ namespace lbAbiAmd64SysV {
Amd64TypeAttribute_StructRect, Amd64TypeAttribute_StructRect,
}; };
LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type); gb_internal LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type);
void classify_with(LLVMTypeRef t, Array<RegClass> *cls, i64 ix, i64 off); gb_internal void classify_with(LLVMTypeRef t, Array<RegClass> *cls, i64 ix, i64 off);
void fixup(LLVMTypeRef t, Array<RegClass> *cls); gb_internal void fixup(LLVMTypeRef t, Array<RegClass> *cls);
lbArgType amd64_type(LLVMContextRef c, LLVMTypeRef type, Amd64TypeAttributeKind attribute_kind, ProcCallingConvention calling_convention); gb_internal lbArgType amd64_type(LLVMContextRef c, LLVMTypeRef type, Amd64TypeAttributeKind attribute_kind, ProcCallingConvention calling_convention);
Array<RegClass> classify(LLVMTypeRef t); gb_internal Array<RegClass> classify(LLVMTypeRef t);
LLVMTypeRef llreg(LLVMContextRef c, Array<RegClass> const &reg_classes); gb_internal LLVMTypeRef llreg(LLVMContextRef c, Array<RegClass> const &reg_classes);
LB_ABI_INFO(abi_info) { gb_internal LB_ABI_INFO(abi_info) {
lbFunctionType *ft = gb_alloc_item(permanent_allocator(), lbFunctionType); lbFunctionType *ft = gb_alloc_item(permanent_allocator(), lbFunctionType);
ft->ctx = c; ft->ctx = c;
ft->calling_convention = calling_convention; ft->calling_convention = calling_convention;
@@ -584,7 +584,7 @@ namespace lbAbiAmd64SysV {
return ft; return ft;
} }
bool is_mem_cls(Array<RegClass> const &cls, Amd64TypeAttributeKind attribute_kind) { gb_internal bool is_mem_cls(Array<RegClass> const &cls, Amd64TypeAttributeKind attribute_kind) {
if (attribute_kind == Amd64TypeAttribute_ByVal) { if (attribute_kind == Amd64TypeAttribute_ByVal) {
if (cls.count == 0) { if (cls.count == 0) {
return false; return false;
@@ -600,7 +600,7 @@ namespace lbAbiAmd64SysV {
return false; return false;
} }
bool is_register(LLVMTypeRef type) { gb_internal bool is_register(LLVMTypeRef type) {
LLVMTypeKind kind = LLVMGetTypeKind(type); LLVMTypeKind kind = LLVMGetTypeKind(type);
i64 sz = lb_sizeof(type); i64 sz = lb_sizeof(type);
if (sz == 0) { if (sz == 0) {
@@ -617,7 +617,7 @@ namespace lbAbiAmd64SysV {
return false; return false;
} }
bool is_llvm_type_slice_like(LLVMTypeRef type) { gb_internal bool is_llvm_type_slice_like(LLVMTypeRef type) {
if (!lb_is_type_kind(type, LLVMStructTypeKind)) { if (!lb_is_type_kind(type, LLVMStructTypeKind)) {
return false; return false;
} }
@@ -633,7 +633,7 @@ namespace lbAbiAmd64SysV {
} }
lbArgType amd64_type(LLVMContextRef c, LLVMTypeRef type, Amd64TypeAttributeKind attribute_kind, ProcCallingConvention calling_convention) { gb_internal lbArgType amd64_type(LLVMContextRef c, LLVMTypeRef type, Amd64TypeAttributeKind attribute_kind, ProcCallingConvention calling_convention) {
if (is_register(type)) { if (is_register(type)) {
LLVMAttributeRef attribute = nullptr; LLVMAttributeRef attribute = nullptr;
if (type == LLVMInt1TypeInContext(c)) { if (type == LLVMInt1TypeInContext(c)) {
@@ -668,7 +668,7 @@ namespace lbAbiAmd64SysV {
} }
} }
lbArgType non_struct(LLVMContextRef c, LLVMTypeRef type) { gb_internal lbArgType non_struct(LLVMContextRef c, LLVMTypeRef type) {
LLVMAttributeRef attr = nullptr; LLVMAttributeRef attr = nullptr;
LLVMTypeRef i1 = LLVMInt1TypeInContext(c); LLVMTypeRef i1 = LLVMInt1TypeInContext(c);
if (type == i1) { if (type == i1) {
@@ -677,7 +677,7 @@ namespace lbAbiAmd64SysV {
return lb_arg_type_direct(type, nullptr, nullptr, attr); return lb_arg_type_direct(type, nullptr, nullptr, attr);
} }
Array<RegClass> classify(LLVMTypeRef t) { gb_internal Array<RegClass> classify(LLVMTypeRef t) {
i64 sz = lb_sizeof(t); i64 sz = lb_sizeof(t);
i64 words = (sz + 7)/8; i64 words = (sz + 7)/8;
auto reg_classes = array_make<RegClass>(heap_allocator(), cast(isize)words); auto reg_classes = array_make<RegClass>(heap_allocator(), cast(isize)words);
@@ -690,7 +690,7 @@ namespace lbAbiAmd64SysV {
return reg_classes; return reg_classes;
} }
void unify(Array<RegClass> *cls, i64 i, RegClass const newv) { gb_internal void unify(Array<RegClass> *cls, i64 i, RegClass const newv) {
RegClass const oldv = (*cls)[cast(isize)i]; RegClass const oldv = (*cls)[cast(isize)i];
if (oldv == newv) { if (oldv == newv) {
return; return;
@@ -726,7 +726,7 @@ namespace lbAbiAmd64SysV {
(*cls)[cast(isize)i] = to_write; (*cls)[cast(isize)i] = to_write;
} }
void fixup(LLVMTypeRef t, Array<RegClass> *cls) { gb_internal void fixup(LLVMTypeRef t, Array<RegClass> *cls) {
i64 i = 0; i64 i = 0;
i64 e = cls->count; i64 e = cls->count;
if (e > 2 && (lb_is_type_kind(t, LLVMStructTypeKind) || if (e > 2 && (lb_is_type_kind(t, LLVMStructTypeKind) ||
@@ -773,7 +773,7 @@ namespace lbAbiAmd64SysV {
} }
} }
unsigned llvec_len(Array<RegClass> const &reg_classes, isize offset) { gb_internal unsigned llvec_len(Array<RegClass> const &reg_classes, isize offset) {
unsigned len = 1; unsigned len = 1;
for (isize i = offset; i < reg_classes.count; i++) { for (isize i = offset; i < reg_classes.count; i++) {
if (reg_classes[i] != RegClass_SSEUp) { if (reg_classes[i] != RegClass_SSEUp) {
@@ -785,7 +785,7 @@ namespace lbAbiAmd64SysV {
} }
LLVMTypeRef llreg(LLVMContextRef c, Array<RegClass> const &reg_classes) { gb_internal LLVMTypeRef llreg(LLVMContextRef c, Array<RegClass> const &reg_classes) {
auto types = array_make<LLVMTypeRef>(heap_allocator(), 0, reg_classes.count); auto types = array_make<LLVMTypeRef>(heap_allocator(), 0, reg_classes.count);
for (isize i = 0; i < reg_classes.count; /**/) { for (isize i = 0; i < reg_classes.count; /**/) {
RegClass reg_class = reg_classes[i]; RegClass reg_class = reg_classes[i];
@@ -854,7 +854,7 @@ namespace lbAbiAmd64SysV {
return LLVMStructTypeInContext(c, types.data, cast(unsigned)types.count, false); return LLVMStructTypeInContext(c, types.data, cast(unsigned)types.count, false);
} }
void classify_with(LLVMTypeRef t, Array<RegClass> *cls, i64 ix, i64 off) { gb_internal void classify_with(LLVMTypeRef t, Array<RegClass> *cls, i64 ix, i64 off) {
i64 t_align = lb_alignof(t); i64 t_align = lb_alignof(t);
i64 t_size = lb_sizeof(t); i64 t_size = lb_sizeof(t);
@@ -955,7 +955,7 @@ namespace lbAbiAmd64SysV {
} }
} }
LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type) { gb_internal LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type) {
if (!return_is_defined) { if (!return_is_defined) {
return lb_arg_type_direct(LLVMVoidTypeInContext(c)); return lb_arg_type_direct(LLVMVoidTypeInContext(c));
} else if (lb_is_type_kind(return_type, LLVMStructTypeKind)) { } else if (lb_is_type_kind(return_type, LLVMStructTypeKind)) {
@@ -980,11 +980,11 @@ namespace lbAbiAmd64SysV {
namespace lbAbiArm64 { namespace lbAbiArm64 {
Array<lbArgType> compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count); gb_internal Array<lbArgType> compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count);
LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type); gb_internal LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type);
bool is_homogenous_aggregate(LLVMContextRef c, LLVMTypeRef type, LLVMTypeRef *base_type_, unsigned *member_count_); gb_internal bool is_homogenous_aggregate(LLVMContextRef c, LLVMTypeRef type, LLVMTypeRef *base_type_, unsigned *member_count_);
LB_ABI_INFO(abi_info) { gb_internal LB_ABI_INFO(abi_info) {
lbFunctionType *ft = gb_alloc_item(permanent_allocator(), lbFunctionType); lbFunctionType *ft = gb_alloc_item(permanent_allocator(), lbFunctionType);
ft->ctx = c; ft->ctx = c;
ft->ret = compute_return_type(ft, c, return_type, return_is_defined, return_is_tuple); ft->ret = compute_return_type(ft, c, return_type, return_is_defined, return_is_tuple);
@@ -993,7 +993,7 @@ namespace lbAbiArm64 {
return ft; return ft;
} }
bool is_register(LLVMTypeRef type) { gb_internal bool is_register(LLVMTypeRef type) {
LLVMTypeKind kind = LLVMGetTypeKind(type); LLVMTypeKind kind = LLVMGetTypeKind(type);
switch (kind) { switch (kind) {
case LLVMIntegerTypeKind: case LLVMIntegerTypeKind:
@@ -1006,7 +1006,7 @@ namespace lbAbiArm64 {
return false; return false;
} }
lbArgType non_struct(LLVMContextRef c, LLVMTypeRef type) { gb_internal lbArgType non_struct(LLVMContextRef c, LLVMTypeRef type) {
LLVMAttributeRef attr = nullptr; LLVMAttributeRef attr = nullptr;
LLVMTypeRef i1 = LLVMInt1TypeInContext(c); LLVMTypeRef i1 = LLVMInt1TypeInContext(c);
if (type == i1) { if (type == i1) {
@@ -1015,7 +1015,7 @@ namespace lbAbiArm64 {
return lb_arg_type_direct(type, nullptr, nullptr, attr); return lb_arg_type_direct(type, nullptr, nullptr, attr);
} }
bool is_homogenous_array(LLVMContextRef c, LLVMTypeRef type, LLVMTypeRef *base_type_, unsigned *member_count_) { gb_internal bool is_homogenous_array(LLVMContextRef c, LLVMTypeRef type, LLVMTypeRef *base_type_, unsigned *member_count_) {
GB_ASSERT(lb_is_type_kind(type, LLVMArrayTypeKind)); GB_ASSERT(lb_is_type_kind(type, LLVMArrayTypeKind));
unsigned len = LLVMGetArrayLength(type); unsigned len = LLVMGetArrayLength(type);
if (len == 0) { if (len == 0) {
@@ -1032,7 +1032,7 @@ namespace lbAbiArm64 {
} }
return false; return false;
} }
bool is_homogenous_struct(LLVMContextRef c, LLVMTypeRef type, LLVMTypeRef *base_type_, unsigned *member_count_) { gb_internal bool is_homogenous_struct(LLVMContextRef c, LLVMTypeRef type, LLVMTypeRef *base_type_, unsigned *member_count_) {
GB_ASSERT(lb_is_type_kind(type, LLVMStructTypeKind)); GB_ASSERT(lb_is_type_kind(type, LLVMStructTypeKind));
unsigned elem_count = LLVMCountStructElementTypes(type); unsigned elem_count = LLVMCountStructElementTypes(type);
if (elem_count == 0) { if (elem_count == 0) {
@@ -1075,7 +1075,7 @@ namespace lbAbiArm64 {
} }
bool is_homogenous_aggregate(LLVMContextRef c, LLVMTypeRef type, LLVMTypeRef *base_type_, unsigned *member_count_) { gb_internal bool is_homogenous_aggregate(LLVMContextRef c, LLVMTypeRef type, LLVMTypeRef *base_type_, unsigned *member_count_) {
LLVMTypeKind kind = LLVMGetTypeKind(type); LLVMTypeKind kind = LLVMGetTypeKind(type);
switch (kind) { switch (kind) {
case LLVMFloatTypeKind: case LLVMFloatTypeKind:
@@ -1091,11 +1091,11 @@ namespace lbAbiArm64 {
return false; return false;
} }
unsigned is_homogenous_aggregate_small_enough(LLVMTypeRef base_type, unsigned member_count) { gb_internal unsigned is_homogenous_aggregate_small_enough(LLVMTypeRef base_type, unsigned member_count) {
return (member_count <= 4); return (member_count <= 4);
} }
LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type) { gb_internal LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type) {
LLVMTypeRef homo_base_type = nullptr; LLVMTypeRef homo_base_type = nullptr;
unsigned homo_member_count = 0; unsigned homo_member_count = 0;
@@ -1142,7 +1142,7 @@ namespace lbAbiArm64 {
} }
} }
Array<lbArgType> compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count) { gb_internal Array<lbArgType> compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count) {
auto args = array_make<lbArgType>(lb_function_type_args_allocator(), arg_count); auto args = array_make<lbArgType>(lb_function_type_args_allocator(), arg_count);
for (unsigned i = 0; i < arg_count; i++) { for (unsigned i = 0; i < arg_count; i++) {
@@ -1188,12 +1188,12 @@ namespace lbAbiWasm {
The approach taken optimizes for passing things in multiple The approach taken optimizes for passing things in multiple
registers/arguments if possible rather than by pointer. registers/arguments if possible rather than by pointer.
*/ */
Array<lbArgType> compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count); gb_internal Array<lbArgType> compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count);
LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type); gb_internal LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type);
enum {MAX_DIRECT_STRUCT_SIZE = 32}; enum {MAX_DIRECT_STRUCT_SIZE = 32};
LB_ABI_INFO(abi_info) { gb_internal LB_ABI_INFO(abi_info) {
lbFunctionType *ft = gb_alloc_item(permanent_allocator(), lbFunctionType); lbFunctionType *ft = gb_alloc_item(permanent_allocator(), lbFunctionType);
ft->ctx = c; ft->ctx = c;
ft->args = compute_arg_types(c, arg_types, arg_count); ft->args = compute_arg_types(c, arg_types, arg_count);
@@ -1202,7 +1202,7 @@ namespace lbAbiWasm {
return ft; return ft;
} }
lbArgType non_struct(LLVMContextRef c, LLVMTypeRef type, bool is_return) { gb_internal lbArgType non_struct(LLVMContextRef c, LLVMTypeRef type, bool is_return) {
if (!is_return && type == LLVMIntTypeInContext(c, 128)) { if (!is_return && type == LLVMIntTypeInContext(c, 128)) {
LLVMTypeRef cast_type = LLVMVectorType(LLVMInt64TypeInContext(c), 2); LLVMTypeRef cast_type = LLVMVectorType(LLVMInt64TypeInContext(c), 2);
return lb_arg_type_direct(type, cast_type, nullptr, nullptr); return lb_arg_type_direct(type, cast_type, nullptr, nullptr);
@@ -1220,7 +1220,7 @@ namespace lbAbiWasm {
return lb_arg_type_direct(type, nullptr, nullptr, attr); return lb_arg_type_direct(type, nullptr, nullptr, attr);
} }
bool is_basic_register_type(LLVMTypeRef type) { gb_internal bool is_basic_register_type(LLVMTypeRef type) {
switch (LLVMGetTypeKind(type)) { switch (LLVMGetTypeKind(type)) {
case LLVMHalfTypeKind: case LLVMHalfTypeKind:
case LLVMFloatTypeKind: case LLVMFloatTypeKind:
@@ -1233,7 +1233,7 @@ namespace lbAbiWasm {
return false; return false;
} }
bool type_can_be_direct(LLVMTypeRef type) { gb_internal bool type_can_be_direct(LLVMTypeRef type) {
LLVMTypeKind kind = LLVMGetTypeKind(type); LLVMTypeKind kind = LLVMGetTypeKind(type);
i64 sz = lb_sizeof(type); i64 sz = lb_sizeof(type);
if (sz == 0) { if (sz == 0) {
@@ -1259,7 +1259,7 @@ namespace lbAbiWasm {
return false; return false;
} }
lbArgType is_struct(LLVMContextRef c, LLVMTypeRef type) { gb_internal lbArgType is_struct(LLVMContextRef c, LLVMTypeRef type) {
LLVMTypeKind kind = LLVMGetTypeKind(type); LLVMTypeKind kind = LLVMGetTypeKind(type);
GB_ASSERT(kind == LLVMArrayTypeKind || kind == LLVMStructTypeKind); GB_ASSERT(kind == LLVMArrayTypeKind || kind == LLVMStructTypeKind);
@@ -1274,7 +1274,7 @@ namespace lbAbiWasm {
} }
Array<lbArgType> compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count) { gb_internal Array<lbArgType> compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count) {
auto args = array_make<lbArgType>(lb_function_type_args_allocator(), arg_count); auto args = array_make<lbArgType>(lb_function_type_args_allocator(), arg_count);
for (unsigned i = 0; i < arg_count; i++) { for (unsigned i = 0; i < arg_count; i++) {
@@ -1289,7 +1289,7 @@ namespace lbAbiWasm {
return args; return args;
} }
LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type) { gb_internal LB_ABI_COMPUTE_RETURN_TYPE(compute_return_type) {
if (!return_is_defined) { if (!return_is_defined) {
return lb_arg_type_direct(LLVMVoidTypeInContext(c)); return lb_arg_type_direct(LLVMVoidTypeInContext(c));
} else if (lb_is_type_kind(return_type, LLVMStructTypeKind) || lb_is_type_kind(return_type, LLVMArrayTypeKind)) { } else if (lb_is_type_kind(return_type, LLVMStructTypeKind) || lb_is_type_kind(return_type, LLVMArrayTypeKind)) {
@@ -1315,10 +1315,10 @@ namespace lbAbiWasm {
} }
namespace lbAbiArm32 { namespace lbAbiArm32 {
Array<lbArgType> compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count, ProcCallingConvention calling_convention); gb_internal Array<lbArgType> compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count, ProcCallingConvention calling_convention);
lbArgType compute_return_type(LLVMContextRef c, LLVMTypeRef return_type, bool return_is_defined); gb_internal lbArgType compute_return_type(LLVMContextRef c, LLVMTypeRef return_type, bool return_is_defined);
LB_ABI_INFO(abi_info) { gb_internal LB_ABI_INFO(abi_info) {
lbFunctionType *ft = gb_alloc_item(permanent_allocator(), lbFunctionType); lbFunctionType *ft = gb_alloc_item(permanent_allocator(), lbFunctionType);
ft->ctx = c; ft->ctx = c;
ft->args = compute_arg_types(c, arg_types, arg_count, calling_convention); ft->args = compute_arg_types(c, arg_types, arg_count, calling_convention);
@@ -1327,7 +1327,7 @@ namespace lbAbiArm32 {
return ft; return ft;
} }
bool is_register(LLVMTypeRef type, bool is_return) { gb_internal bool is_register(LLVMTypeRef type, bool is_return) {
LLVMTypeKind kind = LLVMGetTypeKind(type); LLVMTypeKind kind = LLVMGetTypeKind(type);
switch (kind) { switch (kind) {
case LLVMHalfTypeKind: case LLVMHalfTypeKind:
@@ -1346,7 +1346,7 @@ namespace lbAbiArm32 {
return false; return false;
} }
lbArgType non_struct(LLVMContextRef c, LLVMTypeRef type, bool is_return) { gb_internal lbArgType non_struct(LLVMContextRef c, LLVMTypeRef type, bool is_return) {
LLVMAttributeRef attr = nullptr; LLVMAttributeRef attr = nullptr;
LLVMTypeRef i1 = LLVMInt1TypeInContext(c); LLVMTypeRef i1 = LLVMInt1TypeInContext(c);
if (type == i1) { if (type == i1) {
@@ -1355,7 +1355,7 @@ namespace lbAbiArm32 {
return lb_arg_type_direct(type, nullptr, nullptr, attr); return lb_arg_type_direct(type, nullptr, nullptr, attr);
} }
Array<lbArgType> compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count, ProcCallingConvention calling_convention) { gb_internal Array<lbArgType> compute_arg_types(LLVMContextRef c, LLVMTypeRef *arg_types, unsigned arg_count, ProcCallingConvention calling_convention) {
auto args = array_make<lbArgType>(lb_function_type_args_allocator(), arg_count); auto args = array_make<lbArgType>(lb_function_type_args_allocator(), arg_count);
for (unsigned i = 0; i < arg_count; i++) { for (unsigned i = 0; i < arg_count; i++) {
@@ -1380,7 +1380,7 @@ namespace lbAbiArm32 {
return args; return args;
} }
lbArgType compute_return_type(LLVMContextRef c, LLVMTypeRef return_type, bool return_is_defined) { gb_internal lbArgType compute_return_type(LLVMContextRef c, LLVMTypeRef return_type, bool return_is_defined) {
if (!return_is_defined) { if (!return_is_defined) {
return lb_arg_type_direct(LLVMVoidTypeInContext(c)); return lb_arg_type_direct(LLVMVoidTypeInContext(c));
} else if (!is_register(return_type, true)) { } else if (!is_register(return_type, true)) {
@@ -1397,7 +1397,7 @@ namespace lbAbiArm32 {
}; };
LB_ABI_INFO(lb_get_abi_info_internal) { gb_internal LB_ABI_INFO(lb_get_abi_info_internal) {
switch (calling_convention) { switch (calling_convention) {
case ProcCC_None: case ProcCC_None:
case ProcCC_InlineAsm: case ProcCC_InlineAsm:
@@ -1451,7 +1451,7 @@ LB_ABI_INFO(lb_get_abi_info_internal) {
} }
LB_ABI_INFO(lb_get_abi_info) { gb_internal LB_ABI_INFO(lb_get_abi_info) {
lbFunctionType *ft = lb_get_abi_info_internal( lbFunctionType *ft = lb_get_abi_info_internal(
c, c,
arg_types, arg_count, arg_types, arg_count,
+35 -35
View File
@@ -22,7 +22,7 @@
#include "llvm_backend_proc.cpp" #include "llvm_backend_proc.cpp"
void lb_add_foreign_library_path(lbModule *m, Entity *e) { gb_internal void lb_add_foreign_library_path(lbModule *m, Entity *e) {
if (e == nullptr) { if (e == nullptr) {
return; return;
} }
@@ -36,7 +36,7 @@ void lb_add_foreign_library_path(lbModule *m, Entity *e) {
mutex_unlock(&m->gen->foreign_mutex); mutex_unlock(&m->gen->foreign_mutex);
} }
GB_COMPARE_PROC(foreign_library_cmp) { gb_internal GB_COMPARE_PROC(foreign_library_cmp) {
int cmp = 0; int cmp = 0;
Entity *x = *(Entity **)a; Entity *x = *(Entity **)a;
Entity *y = *(Entity **)b; Entity *y = *(Entity **)b;
@@ -78,7 +78,7 @@ GB_COMPARE_PROC(foreign_library_cmp) {
return i32_cmp(x->token.pos.offset, y->token.pos.offset); return i32_cmp(x->token.pos.offset, y->token.pos.offset);
} }
void lb_set_entity_from_other_modules_linkage_correctly(lbModule *other_module, Entity *e, String const &name) { gb_internal void lb_set_entity_from_other_modules_linkage_correctly(lbModule *other_module, Entity *e, String const &name) {
if (other_module == nullptr) { if (other_module == nullptr) {
return; return;
} }
@@ -95,7 +95,7 @@ void lb_set_entity_from_other_modules_linkage_correctly(lbModule *other_module,
} }
} }
void lb_emit_init_context(lbProcedure *p, lbAddr addr) { gb_internal void lb_emit_init_context(lbProcedure *p, lbAddr addr) {
GB_ASSERT(addr.kind == lbAddr_Context); GB_ASSERT(addr.kind == lbAddr_Context);
GB_ASSERT(addr.ctx.sel.index.count == 0); GB_ASSERT(addr.ctx.sel.index.count == 0);
@@ -104,7 +104,7 @@ void lb_emit_init_context(lbProcedure *p, lbAddr addr) {
lb_emit_runtime_call(p, "__init_context", args); lb_emit_runtime_call(p, "__init_context", args);
} }
lbContextData *lb_push_context_onto_stack_from_implicit_parameter(lbProcedure *p) { gb_internal lbContextData *lb_push_context_onto_stack_from_implicit_parameter(lbProcedure *p) {
Type *pt = base_type(p->type); Type *pt = base_type(p->type);
GB_ASSERT(pt->kind == Type_Proc); GB_ASSERT(pt->kind == Type_Proc);
GB_ASSERT(pt->Proc.calling_convention == ProcCC_Odin); GB_ASSERT(pt->Proc.calling_convention == ProcCC_Odin);
@@ -131,7 +131,7 @@ lbContextData *lb_push_context_onto_stack_from_implicit_parameter(lbProcedure *p
return cd; return cd;
} }
lbContextData *lb_push_context_onto_stack(lbProcedure *p, lbAddr ctx) { gb_internal lbContextData *lb_push_context_onto_stack(lbProcedure *p, lbAddr ctx) {
ctx.kind = lbAddr_Context; ctx.kind = lbAddr_Context;
lbContextData *cd = array_add_and_get(&p->context_stack); lbContextData *cd = array_add_and_get(&p->context_stack);
cd->ctx = ctx; cd->ctx = ctx;
@@ -140,7 +140,7 @@ lbContextData *lb_push_context_onto_stack(lbProcedure *p, lbAddr ctx) {
} }
lbValue lb_equal_proc_for_type(lbModule *m, Type *type) { gb_internal lbValue lb_equal_proc_for_type(lbModule *m, Type *type) {
type = base_type(type); type = base_type(type);
GB_ASSERT(is_type_comparable(type)); GB_ASSERT(is_type_comparable(type));
@@ -279,7 +279,7 @@ lbValue lb_equal_proc_for_type(lbModule *m, Type *type) {
return {compare_proc->value, compare_proc->type}; return {compare_proc->value, compare_proc->type};
} }
lbValue lb_simple_compare_hash(lbProcedure *p, Type *type, lbValue data, lbValue seed) { gb_internal lbValue lb_simple_compare_hash(lbProcedure *p, Type *type, lbValue data, lbValue seed) {
GB_ASSERT_MSG(is_type_simple_compare(type), "%s", type_to_string(type)); GB_ASSERT_MSG(is_type_simple_compare(type), "%s", type_to_string(type));
auto args = array_make<lbValue>(permanent_allocator(), 3); auto args = array_make<lbValue>(permanent_allocator(), 3);
@@ -289,11 +289,11 @@ lbValue lb_simple_compare_hash(lbProcedure *p, Type *type, lbValue data, lbValue
return lb_emit_runtime_call(p, "default_hasher", args); return lb_emit_runtime_call(p, "default_hasher", args);
} }
void lb_add_callsite_force_inline(lbProcedure *p, lbValue ret_value) { gb_internal void lb_add_callsite_force_inline(lbProcedure *p, lbValue ret_value) {
LLVMAddCallSiteAttribute(ret_value.value, LLVMAttributeIndex_FunctionIndex, lb_create_enum_attribute(p->module->ctx, "alwaysinline")); LLVMAddCallSiteAttribute(ret_value.value, LLVMAttributeIndex_FunctionIndex, lb_create_enum_attribute(p->module->ctx, "alwaysinline"));
} }
lbValue lb_hasher_proc_for_type(lbModule *m, Type *type) { gb_internal lbValue lb_hasher_proc_for_type(lbModule *m, Type *type) {
type = core_type(type); type = core_type(type);
GB_ASSERT_MSG(is_type_valid_for_keys(type), "%s", type_to_string(type)); GB_ASSERT_MSG(is_type_valid_for_keys(type), "%s", type_to_string(type));
@@ -458,7 +458,7 @@ lbValue lb_hasher_proc_for_type(lbModule *m, Type *type) {
} }
lbValue lb_map_get_proc_for_type(lbModule *m, Type *type) { gb_internal lbValue lb_map_get_proc_for_type(lbModule *m, Type *type) {
GB_ASSERT(build_context.use_static_map_calls); GB_ASSERT(build_context.use_static_map_calls);
type = base_type(type); type = base_type(type);
GB_ASSERT(type->kind == Type_Map); GB_ASSERT(type->kind == Type_Map);
@@ -605,13 +605,13 @@ lbValue lb_map_get_proc_for_type(lbModule *m, Type *type) {
return {p->value, p->type}; return {p->value, p->type};
} }
void lb_debug_print(lbProcedure *p, String const &str) { gb_internal void lb_debug_print(lbProcedure *p, String const &str) {
auto args = array_make<lbValue>(heap_allocator(), 1); auto args = array_make<lbValue>(heap_allocator(), 1);
args[0] = lb_const_string(p->module, str); args[0] = lb_const_string(p->module, str);
lb_emit_runtime_call(p, "print_string", args); lb_emit_runtime_call(p, "print_string", args);
} }
lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) { gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) {
GB_ASSERT(build_context.use_static_map_calls); GB_ASSERT(build_context.use_static_map_calls);
type = base_type(type); type = base_type(type);
GB_ASSERT(type->kind == Type_Map); GB_ASSERT(type->kind == Type_Map);
@@ -731,7 +731,7 @@ lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) {
} }
lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &prefix_name, Ast *expr, lbProcedure *parent) { gb_internal lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &prefix_name, Ast *expr, lbProcedure *parent) {
lbProcedure **found = map_get(&m->gen->anonymous_proc_lits, expr); lbProcedure **found = map_get(&m->gen->anonymous_proc_lits, expr);
if (found) { if (found) {
return lb_find_procedure_value_from_entity(m, (*found)->entity); return lb_find_procedure_value_from_entity(m, (*found)->entity);
@@ -778,7 +778,7 @@ lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &prefix_name, A
} }
lbValue lb_gen_map_cell_info_ptr(lbModule *m, Type *type) { gb_internal lbValue lb_gen_map_cell_info_ptr(lbModule *m, Type *type) {
lbAddr *found = map_get(&m->map_cell_info_map, type); lbAddr *found = map_get(&m->map_cell_info_map, type);
if (found) { if (found) {
return found->addr; return found->addr;
@@ -802,7 +802,7 @@ lbValue lb_gen_map_cell_info_ptr(lbModule *m, Type *type) {
return addr.addr; return addr.addr;
} }
lbValue lb_gen_map_info_ptr(lbModule *m, Type *map_type) { gb_internal lbValue lb_gen_map_info_ptr(lbModule *m, Type *map_type) {
map_type = base_type(map_type); map_type = base_type(map_type);
GB_ASSERT(map_type->kind == Type_Map); GB_ASSERT(map_type->kind == Type_Map);
@@ -833,7 +833,7 @@ lbValue lb_gen_map_info_ptr(lbModule *m, Type *map_type) {
return addr.addr; return addr.addr;
} }
lbValue lb_const_hash(lbModule *m, lbValue key, Type *key_type) { gb_internal lbValue lb_const_hash(lbModule *m, lbValue key, Type *key_type) {
if (true) { if (true) {
return {}; return {};
} }
@@ -880,7 +880,7 @@ lbValue lb_const_hash(lbModule *m, lbValue key, Type *key_type) {
return hashed_key; return hashed_key;
} }
lbValue lb_gen_map_key_hash(lbProcedure *p, lbValue key, Type *key_type, lbValue *key_ptr_) { gb_internal lbValue lb_gen_map_key_hash(lbProcedure *p, lbValue key, Type *key_type, lbValue *key_ptr_) {
lbValue key_ptr = lb_address_from_load_or_generate_local(p, key); lbValue key_ptr = lb_address_from_load_or_generate_local(p, key);
key_ptr = lb_emit_conv(p, key_ptr, t_rawptr); key_ptr = lb_emit_conv(p, key_ptr, t_rawptr);
@@ -899,7 +899,7 @@ lbValue lb_gen_map_key_hash(lbProcedure *p, lbValue key, Type *key_type, lbValue
return hashed_key; return hashed_key;
} }
lbValue lb_internal_dynamic_map_get_ptr(lbProcedure *p, lbValue const &map_ptr, lbValue const &key) { gb_internal lbValue lb_internal_dynamic_map_get_ptr(lbProcedure *p, lbValue const &map_ptr, lbValue const &key) {
Type *map_type = base_type(type_deref(map_ptr.type)); Type *map_type = base_type(type_deref(map_ptr.type));
GB_ASSERT(map_type->kind == Type_Map); GB_ASSERT(map_type->kind == Type_Map);
@@ -928,8 +928,8 @@ lbValue lb_internal_dynamic_map_get_ptr(lbProcedure *p, lbValue const &map_ptr,
return lb_emit_conv(p, ptr, alloc_type_pointer(map_type->Map.value)); return lb_emit_conv(p, ptr, alloc_type_pointer(map_type->Map.value));
} }
void lb_internal_dynamic_map_set(lbProcedure *p, lbValue const &map_ptr, Type *map_type, gb_internal void lb_internal_dynamic_map_set(lbProcedure *p, lbValue const &map_ptr, Type *map_type,
lbValue const &map_key, lbValue const &map_value, Ast *node) { lbValue const &map_key, lbValue const &map_value, Ast *node) {
map_type = base_type(map_type); map_type = base_type(map_type);
GB_ASSERT(map_type->kind == Type_Map); GB_ASSERT(map_type->kind == Type_Map);
@@ -962,7 +962,7 @@ void lb_internal_dynamic_map_set(lbProcedure *p, lbValue const &map_ptr, Type *m
} }
} }
lbValue lb_dynamic_map_reserve(lbProcedure *p, lbValue const &map_ptr, isize const capacity, TokenPos const &pos) { gb_internal lbValue lb_dynamic_map_reserve(lbProcedure *p, lbValue const &map_ptr, isize const capacity, TokenPos const &pos) {
GB_ASSERT(!build_context.no_dynamic_literals); GB_ASSERT(!build_context.no_dynamic_literals);
String proc_name = {}; String proc_name = {};
@@ -986,7 +986,7 @@ struct lbGlobalVariable {
bool is_initialized; bool is_initialized;
}; };
lbProcedure *lb_create_startup_type_info(lbModule *m) { gb_internal lbProcedure *lb_create_startup_type_info(lbModule *m) {
if (build_context.disallow_rtti) { if (build_context.disallow_rtti) {
return nullptr; return nullptr;
} }
@@ -1020,7 +1020,7 @@ lbProcedure *lb_create_startup_type_info(lbModule *m) {
return p; return p;
} }
lbProcedure *lb_create_objc_names(lbModule *main_module) { gb_internal lbProcedure *lb_create_objc_names(lbModule *main_module) {
if (build_context.metrics.os != TargetOs_darwin) { if (build_context.metrics.os != TargetOs_darwin) {
return nullptr; return nullptr;
} }
@@ -1031,7 +1031,7 @@ lbProcedure *lb_create_objc_names(lbModule *main_module) {
return p; return p;
} }
void lb_finalize_objc_names(lbProcedure *p) { gb_internal void lb_finalize_objc_names(lbProcedure *p) {
if (p == nullptr) { if (p == nullptr) {
return; return;
} }
@@ -1066,7 +1066,7 @@ void lb_finalize_objc_names(lbProcedure *p) {
} }
lbProcedure *lb_create_startup_runtime(lbModule *main_module, lbProcedure *startup_type_info, lbProcedure *objc_names, Array<lbGlobalVariable> &global_variables) { // Startup Runtime gb_internal lbProcedure *lb_create_startup_runtime(lbModule *main_module, lbProcedure *startup_type_info, lbProcedure *objc_names, Array<lbGlobalVariable> &global_variables) { // Startup Runtime
LLVMPassManagerRef default_function_pass_manager = LLVMCreateFunctionPassManagerForModule(main_module->mod); LLVMPassManagerRef default_function_pass_manager = LLVMCreateFunctionPassManagerForModule(main_module->mod);
lb_populate_function_pass_manager(main_module, default_function_pass_manager, false, build_context.optimization_level); lb_populate_function_pass_manager(main_module, default_function_pass_manager, false, build_context.optimization_level);
LLVMFinalizeFunctionPassManager(default_function_pass_manager); LLVMFinalizeFunctionPassManager(default_function_pass_manager);
@@ -1181,7 +1181,7 @@ lbProcedure *lb_create_startup_runtime(lbModule *main_module, lbProcedure *start
} }
lbProcedure *lb_create_main_procedure(lbModule *m, lbProcedure *startup_runtime) { gb_internal lbProcedure *lb_create_main_procedure(lbModule *m, lbProcedure *startup_runtime) {
LLVMPassManagerRef default_function_pass_manager = LLVMCreateFunctionPassManagerForModule(m->mod); LLVMPassManagerRef default_function_pass_manager = LLVMCreateFunctionPassManagerForModule(m->mod);
lb_populate_function_pass_manager(m, default_function_pass_manager, false, build_context.optimization_level); lb_populate_function_pass_manager(m, default_function_pass_manager, false, build_context.optimization_level);
LLVMFinalizeFunctionPassManager(default_function_pass_manager); LLVMFinalizeFunctionPassManager(default_function_pass_manager);
@@ -1331,7 +1331,7 @@ lbProcedure *lb_create_main_procedure(lbModule *m, lbProcedure *startup_runtime)
return p; return p;
} }
String lb_filepath_ll_for_module(lbModule *m) { gb_internal String lb_filepath_ll_for_module(lbModule *m) {
String path = concatenate3_strings(permanent_allocator(), String path = concatenate3_strings(permanent_allocator(),
build_context.build_paths[BuildPath_Output].basename, build_context.build_paths[BuildPath_Output].basename,
STR_LIT("/"), STR_LIT("/"),
@@ -1347,7 +1347,7 @@ String lb_filepath_ll_for_module(lbModule *m) {
return path; return path;
} }
String lb_filepath_obj_for_module(lbModule *m) { gb_internal String lb_filepath_obj_for_module(lbModule *m) {
String path = concatenate3_strings(permanent_allocator(), String path = concatenate3_strings(permanent_allocator(),
build_context.build_paths[BuildPath_Output].basename, build_context.build_paths[BuildPath_Output].basename,
STR_LIT("/"), STR_LIT("/"),
@@ -1397,7 +1397,7 @@ String lb_filepath_obj_for_module(lbModule *m) {
} }
bool lb_is_module_empty(lbModule *m) { gb_internal bool lb_is_module_empty(lbModule *m) {
if (LLVMGetFirstFunction(m->mod) == nullptr && if (LLVMGetFirstFunction(m->mod) == nullptr &&
LLVMGetFirstGlobal(m->mod) == nullptr) { LLVMGetFirstGlobal(m->mod) == nullptr) {
return true; return true;
@@ -1426,7 +1426,7 @@ struct lbLLVMEmitWorker {
lbModule *m; lbModule *m;
}; };
WORKER_TASK_PROC(lb_llvm_emit_worker_proc) { gb_internal WORKER_TASK_PROC(lb_llvm_emit_worker_proc) {
GB_ASSERT(MULTITHREAD_OBJECT_GENERATION); GB_ASSERT(MULTITHREAD_OBJECT_GENERATION);
char *llvm_error = nullptr; char *llvm_error = nullptr;
@@ -1441,7 +1441,7 @@ WORKER_TASK_PROC(lb_llvm_emit_worker_proc) {
return 0; return 0;
} }
WORKER_TASK_PROC(lb_llvm_function_pass_worker_proc) { gb_internal WORKER_TASK_PROC(lb_llvm_function_pass_worker_proc) {
GB_ASSERT(MULTITHREAD_OBJECT_GENERATION); GB_ASSERT(MULTITHREAD_OBJECT_GENERATION);
auto m = cast(lbModule *)data; auto m = cast(lbModule *)data;
@@ -1526,7 +1526,7 @@ struct lbLLVMModulePassWorkerData {
LLVMTargetMachineRef target_machine; LLVMTargetMachineRef target_machine;
}; };
WORKER_TASK_PROC(lb_llvm_module_pass_worker_proc) { gb_internal WORKER_TASK_PROC(lb_llvm_module_pass_worker_proc) {
auto wd = cast(lbLLVMModulePassWorkerData *)data; auto wd = cast(lbLLVMModulePassWorkerData *)data;
LLVMPassManagerRef module_pass_manager = LLVMCreatePassManager(); LLVMPassManagerRef module_pass_manager = LLVMCreatePassManager();
lb_populate_module_pass_manager(wd->target_machine, module_pass_manager, build_context.optimization_level); lb_populate_module_pass_manager(wd->target_machine, module_pass_manager, build_context.optimization_level);
@@ -1535,7 +1535,7 @@ WORKER_TASK_PROC(lb_llvm_module_pass_worker_proc) {
} }
void lb_generate_procedure(lbModule *m, lbProcedure *p) { gb_internal void lb_generate_procedure(lbModule *m, lbProcedure *p) {
if (p->is_done) { if (p->is_done) {
return; return;
} }
@@ -1575,7 +1575,7 @@ void lb_generate_procedure(lbModule *m, lbProcedure *p) {
} }
void lb_generate_code(lbGenerator *gen) { gb_internal void lb_generate_code(lbGenerator *gen) {
TIME_SECTION("LLVM Initializtion"); TIME_SECTION("LLVM Initializtion");
isize thread_count = gb_max(build_context.thread_count, 1); isize thread_count = gb_max(build_context.thread_count, 1);
+137 -137
View File
@@ -322,197 +322,197 @@ struct lbProcedure {
#define LLVMBuildPtrDiff2(Builder__, Ty__, LHS__, RHS__, Name__) LLVMBuildPtrDiff(Builder__, LHS__, RHS__, Name__) #define LLVMBuildPtrDiff2(Builder__, Ty__, LHS__, RHS__, Name__) LLVMBuildPtrDiff(Builder__, LHS__, RHS__, Name__)
#endif #endif
bool lb_init_generator(lbGenerator *gen, Checker *c); gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c);
String lb_mangle_name(lbModule *m, Entity *e); gb_internal String lb_mangle_name(lbModule *m, Entity *e);
String lb_get_entity_name(lbModule *m, Entity *e, String name = {}); gb_internal String lb_get_entity_name(lbModule *m, Entity *e, String name = {});
LLVMAttributeRef lb_create_enum_attribute(LLVMContextRef ctx, char const *name, u64 value=0); gb_internal LLVMAttributeRef lb_create_enum_attribute(LLVMContextRef ctx, char const *name, u64 value=0);
LLVMAttributeRef lb_create_enum_attribute_with_type(LLVMContextRef ctx, char const *name, LLVMTypeRef type); gb_internal LLVMAttributeRef lb_create_enum_attribute_with_type(LLVMContextRef ctx, char const *name, LLVMTypeRef type);
void lb_add_proc_attribute_at_index(lbProcedure *p, isize index, char const *name, u64 value); gb_internal void lb_add_proc_attribute_at_index(lbProcedure *p, isize index, char const *name, u64 value);
void lb_add_proc_attribute_at_index(lbProcedure *p, isize index, char const *name); gb_internal void lb_add_proc_attribute_at_index(lbProcedure *p, isize index, char const *name);
lbProcedure *lb_create_procedure(lbModule *module, Entity *entity, bool ignore_body=false); gb_internal lbProcedure *lb_create_procedure(lbModule *module, Entity *entity, bool ignore_body=false);
void lb_end_procedure(lbProcedure *p); gb_internal void lb_end_procedure(lbProcedure *p);
LLVMTypeRef lb_type(lbModule *m, Type *type); gb_internal LLVMTypeRef lb_type(lbModule *m, Type *type);
LLVMTypeRef llvm_get_element_type(LLVMTypeRef type); gb_internal LLVMTypeRef llvm_get_element_type(LLVMTypeRef type);
lbBlock *lb_create_block(lbProcedure *p, char const *name, bool append=false); gb_internal lbBlock *lb_create_block(lbProcedure *p, char const *name, bool append=false);
lbValue lb_const_nil(lbModule *m, Type *type); gb_internal lbValue lb_const_nil(lbModule *m, Type *type);
lbValue lb_const_undef(lbModule *m, Type *type); gb_internal lbValue lb_const_undef(lbModule *m, Type *type);
lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_local=true); gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_local=true);
lbValue lb_const_bool(lbModule *m, Type *type, bool value); gb_internal lbValue lb_const_bool(lbModule *m, Type *type, bool value);
lbValue lb_const_int(lbModule *m, Type *type, u64 value); gb_internal lbValue lb_const_int(lbModule *m, Type *type, u64 value);
lbAddr lb_addr(lbValue addr); gb_internal lbAddr lb_addr(lbValue addr);
Type *lb_addr_type(lbAddr const &addr); gb_internal Type *lb_addr_type(lbAddr const &addr);
LLVMTypeRef llvm_addr_type(lbModule *module, lbValue addr_val); gb_internal LLVMTypeRef llvm_addr_type(lbModule *module, lbValue addr_val);
void lb_addr_store(lbProcedure *p, lbAddr addr, lbValue value); gb_internal void lb_addr_store(lbProcedure *p, lbAddr addr, lbValue value);
lbValue lb_addr_load(lbProcedure *p, lbAddr const &addr); gb_internal lbValue lb_addr_load(lbProcedure *p, lbAddr const &addr);
lbValue lb_emit_load(lbProcedure *p, lbValue v); gb_internal lbValue lb_emit_load(lbProcedure *p, lbValue v);
void lb_emit_store(lbProcedure *p, lbValue ptr, lbValue value); gb_internal void lb_emit_store(lbProcedure *p, lbValue ptr, lbValue value);
void lb_build_stmt(lbProcedure *p, Ast *stmt); gb_internal void lb_build_stmt(lbProcedure *p, Ast *stmt);
lbValue lb_build_expr(lbProcedure *p, Ast *expr); gb_internal lbValue lb_build_expr(lbProcedure *p, Ast *expr);
lbAddr lb_build_addr(lbProcedure *p, Ast *expr); gb_internal lbAddr lb_build_addr(lbProcedure *p, Ast *expr);
void lb_build_stmt_list(lbProcedure *p, Array<Ast *> const &stmts); gb_internal void lb_build_stmt_list(lbProcedure *p, Array<Ast *> const &stmts);
lbValue lb_emit_epi(lbProcedure *p, lbValue const &value, isize index); gb_internal lbValue lb_emit_epi(lbProcedure *p, lbValue const &value, isize index);
lbValue lb_emit_epi(lbModule *m, lbValue const &value, isize index); gb_internal lbValue lb_emit_epi(lbModule *m, lbValue const &value, isize index);
lbValue lb_emit_array_epi(lbModule *m, lbValue s, isize index); gb_internal lbValue lb_emit_array_epi(lbModule *m, lbValue s, isize index);
lbValue lb_emit_struct_ep(lbProcedure *p, lbValue s, i32 index); gb_internal lbValue lb_emit_struct_ep(lbProcedure *p, lbValue s, i32 index);
lbValue lb_emit_struct_ev(lbProcedure *p, lbValue s, i32 index); gb_internal lbValue lb_emit_struct_ev(lbProcedure *p, lbValue s, i32 index);
lbValue lb_emit_tuple_ev(lbProcedure *p, lbValue value, i32 index); gb_internal lbValue lb_emit_tuple_ev(lbProcedure *p, lbValue value, i32 index);
lbValue lb_emit_array_epi(lbProcedure *p, lbValue value, isize index); gb_internal lbValue lb_emit_array_epi(lbProcedure *p, lbValue value, isize index);
lbValue lb_emit_array_ep(lbProcedure *p, lbValue s, lbValue index); gb_internal lbValue lb_emit_array_ep(lbProcedure *p, lbValue s, lbValue index);
lbValue lb_emit_deep_field_gep(lbProcedure *p, lbValue e, Selection sel); gb_internal lbValue lb_emit_deep_field_gep(lbProcedure *p, lbValue e, Selection sel);
lbValue lb_emit_deep_field_ev(lbProcedure *p, lbValue e, Selection sel); gb_internal lbValue lb_emit_deep_field_ev(lbProcedure *p, lbValue e, Selection sel);
lbValue lb_emit_matrix_ep(lbProcedure *p, lbValue s, lbValue row, lbValue column); gb_internal lbValue lb_emit_matrix_ep(lbProcedure *p, lbValue s, lbValue row, lbValue column);
lbValue lb_emit_matrix_epi(lbProcedure *p, lbValue s, isize row, isize column); gb_internal lbValue lb_emit_matrix_epi(lbProcedure *p, lbValue s, isize row, isize column);
lbValue lb_emit_matrix_ev(lbProcedure *p, lbValue s, isize row, isize column); gb_internal lbValue lb_emit_matrix_ev(lbProcedure *p, lbValue s, isize row, isize column);
lbValue lb_emit_arith(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type); gb_internal lbValue lb_emit_arith(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type);
lbValue lb_emit_byte_swap(lbProcedure *p, lbValue value, Type *end_type); gb_internal lbValue lb_emit_byte_swap(lbProcedure *p, lbValue value, Type *end_type);
void lb_emit_defer_stmts(lbProcedure *p, lbDeferExitKind kind, lbBlock *block); gb_internal void lb_emit_defer_stmts(lbProcedure *p, lbDeferExitKind kind, lbBlock *block);
lbValue lb_emit_transmute(lbProcedure *p, lbValue value, Type *t); gb_internal lbValue lb_emit_transmute(lbProcedure *p, lbValue value, Type *t);
lbValue lb_emit_comp(lbProcedure *p, TokenKind op_kind, lbValue left, lbValue right); gb_internal lbValue lb_emit_comp(lbProcedure *p, TokenKind op_kind, lbValue left, lbValue right);
lbValue lb_emit_call(lbProcedure *p, lbValue value, Array<lbValue> const &args, ProcInlining inlining = ProcInlining_none); gb_internal lbValue lb_emit_call(lbProcedure *p, lbValue value, Array<lbValue> const &args, ProcInlining inlining = ProcInlining_none);
lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t); gb_internal lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t);
lbValue lb_emit_comp_against_nil(lbProcedure *p, TokenKind op_kind, lbValue x); gb_internal lbValue lb_emit_comp_against_nil(lbProcedure *p, TokenKind op_kind, lbValue x);
void lb_emit_jump(lbProcedure *p, lbBlock *target_block); gb_internal void lb_emit_jump(lbProcedure *p, lbBlock *target_block);
void lb_emit_if(lbProcedure *p, lbValue cond, lbBlock *true_block, lbBlock *false_block); gb_internal void lb_emit_if(lbProcedure *p, lbValue cond, lbBlock *true_block, lbBlock *false_block);
void lb_start_block(lbProcedure *p, lbBlock *b); gb_internal void lb_start_block(lbProcedure *p, lbBlock *b);
lbValue lb_build_call_expr(lbProcedure *p, Ast *expr); gb_internal lbValue lb_build_call_expr(lbProcedure *p, Ast *expr);
lbAddr lb_find_or_generate_context_ptr(lbProcedure *p); gb_internal lbAddr lb_find_or_generate_context_ptr(lbProcedure *p);
lbContextData *lb_push_context_onto_stack(lbProcedure *p, lbAddr ctx); gb_internal lbContextData *lb_push_context_onto_stack(lbProcedure *p, lbAddr ctx);
lbContextData *lb_push_context_onto_stack_from_implicit_parameter(lbProcedure *p); gb_internal lbContextData *lb_push_context_onto_stack_from_implicit_parameter(lbProcedure *p);
lbAddr lb_add_global_generated(lbModule *m, Type *type, lbValue value={}, Entity **entity_=nullptr); gb_internal lbAddr lb_add_global_generated(lbModule *m, Type *type, lbValue value={}, Entity **entity_=nullptr);
lbAddr lb_add_local(lbProcedure *p, Type *type, Entity *e=nullptr, bool zero_init=true, bool force_no_init=false); gb_internal lbAddr lb_add_local(lbProcedure *p, Type *type, Entity *e=nullptr, bool zero_init=true, bool force_no_init=false);
void lb_add_foreign_library_path(lbModule *m, Entity *e); gb_internal void lb_add_foreign_library_path(lbModule *m, Entity *e);
lbValue lb_typeid(lbModule *m, Type *type); gb_internal lbValue lb_typeid(lbModule *m, Type *type);
lbValue lb_address_from_load_or_generate_local(lbProcedure *p, lbValue value); gb_internal lbValue lb_address_from_load_or_generate_local(lbProcedure *p, lbValue value);
lbValue lb_address_from_load(lbProcedure *p, lbValue value); gb_internal lbValue lb_address_from_load(lbProcedure *p, lbValue value);
void lb_add_defer_node(lbProcedure *p, isize scope_index, Ast *stmt); gb_internal void lb_add_defer_node(lbProcedure *p, isize scope_index, Ast *stmt);
lbAddr lb_add_local_generated(lbProcedure *p, Type *type, bool zero_init); gb_internal lbAddr lb_add_local_generated(lbProcedure *p, Type *type, bool zero_init);
lbValue lb_emit_runtime_call(lbProcedure *p, char const *c_name, Array<lbValue> const &args); gb_internal lbValue lb_emit_runtime_call(lbProcedure *p, char const *c_name, Array<lbValue> const &args);
lbValue lb_emit_ptr_offset(lbProcedure *p, lbValue ptr, lbValue index); gb_internal lbValue lb_emit_ptr_offset(lbProcedure *p, lbValue ptr, lbValue index);
lbValue lb_string_elem(lbProcedure *p, lbValue string); gb_internal lbValue lb_string_elem(lbProcedure *p, lbValue string);
lbValue lb_string_len(lbProcedure *p, lbValue string); gb_internal lbValue lb_string_len(lbProcedure *p, lbValue string);
lbValue lb_cstring_len(lbProcedure *p, lbValue value); gb_internal lbValue lb_cstring_len(lbProcedure *p, lbValue value);
lbValue lb_array_elem(lbProcedure *p, lbValue array_ptr); gb_internal lbValue lb_array_elem(lbProcedure *p, lbValue array_ptr);
lbValue lb_slice_elem(lbProcedure *p, lbValue slice); gb_internal lbValue lb_slice_elem(lbProcedure *p, lbValue slice);
lbValue lb_slice_len(lbProcedure *p, lbValue slice); gb_internal lbValue lb_slice_len(lbProcedure *p, lbValue slice);
lbValue lb_dynamic_array_elem(lbProcedure *p, lbValue da); gb_internal lbValue lb_dynamic_array_elem(lbProcedure *p, lbValue da);
lbValue lb_dynamic_array_len(lbProcedure *p, lbValue da); gb_internal lbValue lb_dynamic_array_len(lbProcedure *p, lbValue da);
lbValue lb_dynamic_array_cap(lbProcedure *p, lbValue da); gb_internal lbValue lb_dynamic_array_cap(lbProcedure *p, lbValue da);
lbValue lb_dynamic_array_allocator(lbProcedure *p, lbValue da); gb_internal lbValue lb_dynamic_array_allocator(lbProcedure *p, lbValue da);
lbValue lb_map_len(lbProcedure *p, lbValue value); gb_internal lbValue lb_map_len(lbProcedure *p, lbValue value);
lbValue lb_map_cap(lbProcedure *p, lbValue value); gb_internal lbValue lb_map_cap(lbProcedure *p, lbValue value);
lbValue lb_soa_struct_len(lbProcedure *p, lbValue value); gb_internal lbValue lb_soa_struct_len(lbProcedure *p, lbValue value);
void lb_emit_increment(lbProcedure *p, lbValue addr); gb_internal void lb_emit_increment(lbProcedure *p, lbValue addr);
lbValue lb_emit_select(lbProcedure *p, lbValue cond, lbValue x, lbValue y); gb_internal lbValue lb_emit_select(lbProcedure *p, lbValue cond, lbValue x, lbValue y);
lbValue lb_emit_mul_add(lbProcedure *p, lbValue a, lbValue b, lbValue c, Type *t); gb_internal lbValue lb_emit_mul_add(lbProcedure *p, lbValue a, lbValue b, lbValue c, Type *t);
void lb_fill_slice(lbProcedure *p, lbAddr const &slice, lbValue base_elem, lbValue len); gb_internal void lb_fill_slice(lbProcedure *p, lbAddr const &slice, lbValue base_elem, lbValue len);
lbValue lb_type_info(lbModule *m, Type *type); gb_internal lbValue lb_type_info(lbModule *m, Type *type);
lbValue lb_find_or_add_entity_string(lbModule *m, String const &str); gb_internal lbValue lb_find_or_add_entity_string(lbModule *m, String const &str);
lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &prefix_name, Ast *expr, lbProcedure *parent = nullptr); gb_internal lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &prefix_name, Ast *expr, lbProcedure *parent = nullptr);
bool lb_is_const(lbValue value); gb_internal bool lb_is_const(lbValue value);
bool lb_is_const_or_global(lbValue value); gb_internal bool lb_is_const_or_global(lbValue value);
bool lb_is_const_nil(lbValue value); gb_internal bool lb_is_const_nil(lbValue value);
String lb_get_const_string(lbModule *m, lbValue value); gb_internal String lb_get_const_string(lbModule *m, lbValue value);
lbValue lb_generate_local_array(lbProcedure *p, Type *elem_type, i64 count, bool zero_init=true); gb_internal lbValue lb_generate_local_array(lbProcedure *p, Type *elem_type, i64 count, bool zero_init=true);
lbValue lb_generate_global_array(lbModule *m, Type *elem_type, i64 count, String prefix, i64 id); gb_internal lbValue lb_generate_global_array(lbModule *m, Type *elem_type, i64 count, String prefix, i64 id);
lbValue lb_gen_map_key_hash(lbProcedure *p, lbValue key, Type *key_type, lbValue *key_ptr_); gb_internal lbValue lb_gen_map_key_hash(lbProcedure *p, lbValue key, Type *key_type, lbValue *key_ptr_);
lbValue lb_gen_map_cell_info_ptr(lbModule *m, Type *type); gb_internal lbValue lb_gen_map_cell_info_ptr(lbModule *m, Type *type);
lbValue lb_gen_map_info_ptr(lbModule *m, Type *map_type); gb_internal lbValue lb_gen_map_info_ptr(lbModule *m, Type *map_type);
lbValue lb_internal_dynamic_map_get_ptr(lbProcedure *p, lbValue const &map_ptr, lbValue const &key); gb_internal lbValue lb_internal_dynamic_map_get_ptr(lbProcedure *p, lbValue const &map_ptr, lbValue const &key);
void lb_internal_dynamic_map_set(lbProcedure *p, lbValue const &map_ptr, Type *map_type, lbValue const &map_key, lbValue const &map_value, Ast *node); gb_internal void lb_internal_dynamic_map_set(lbProcedure *p, lbValue const &map_ptr, Type *map_type, lbValue const &map_key, lbValue const &map_value, Ast *node);
lbValue lb_dynamic_map_reserve(lbProcedure *p, lbValue const &map_ptr, isize const capacity, TokenPos const &pos); gb_internal lbValue lb_dynamic_map_reserve(lbProcedure *p, lbValue const &map_ptr, isize const capacity, TokenPos const &pos);
lbValue lb_find_procedure_value_from_entity(lbModule *m, Entity *e); gb_internal lbValue lb_find_procedure_value_from_entity(lbModule *m, Entity *e);
lbValue lb_find_value_from_entity(lbModule *m, Entity *e); gb_internal lbValue lb_find_value_from_entity(lbModule *m, Entity *e);
void lb_store_type_case_implicit(lbProcedure *p, Ast *clause, lbValue value); gb_internal void lb_store_type_case_implicit(lbProcedure *p, Ast *clause, lbValue value);
lbAddr lb_store_range_stmt_val(lbProcedure *p, Ast *stmt_val, lbValue value); gb_internal lbAddr lb_store_range_stmt_val(lbProcedure *p, Ast *stmt_val, lbValue value);
lbValue lb_emit_source_code_location_const(lbProcedure *p, String const &procedure, TokenPos const &pos); gb_internal lbValue lb_emit_source_code_location_const(lbProcedure *p, String const &procedure, TokenPos const &pos);
lbValue lb_handle_param_value(lbProcedure *p, Type *parameter_type, ParameterValue const &param_value, TokenPos const &pos); gb_internal lbValue lb_handle_param_value(lbProcedure *p, Type *parameter_type, ParameterValue const &param_value, TokenPos const &pos);
lbValue lb_equal_proc_for_type(lbModule *m, Type *type); gb_internal lbValue lb_equal_proc_for_type(lbModule *m, Type *type);
lbValue lb_hasher_proc_for_type(lbModule *m, Type *type); gb_internal lbValue lb_hasher_proc_for_type(lbModule *m, Type *type);
lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t); gb_internal lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t);
LLVMMetadataRef lb_debug_type(lbModule *m, Type *type); gb_internal LLVMMetadataRef lb_debug_type(lbModule *m, Type *type);
lbValue lb_emit_count_ones(lbProcedure *p, lbValue x, Type *type); gb_internal lbValue lb_emit_count_ones(lbProcedure *p, lbValue x, Type *type);
lbValue lb_emit_count_zeros(lbProcedure *p, lbValue x, Type *type); gb_internal lbValue lb_emit_count_zeros(lbProcedure *p, lbValue x, Type *type);
lbValue lb_emit_count_trailing_zeros(lbProcedure *p, lbValue x, Type *type); gb_internal lbValue lb_emit_count_trailing_zeros(lbProcedure *p, lbValue x, Type *type);
lbValue lb_emit_count_leading_zeros(lbProcedure *p, lbValue x, Type *type); gb_internal lbValue lb_emit_count_leading_zeros(lbProcedure *p, lbValue x, Type *type);
lbValue lb_emit_reverse_bits(lbProcedure *p, lbValue x, Type *type); gb_internal lbValue lb_emit_reverse_bits(lbProcedure *p, lbValue x, Type *type);
lbValue lb_emit_bit_set_card(lbProcedure *p, lbValue x); gb_internal lbValue lb_emit_bit_set_card(lbProcedure *p, lbValue x);
void lb_mem_zero_addr(lbProcedure *p, LLVMValueRef ptr, Type *type); gb_internal void lb_mem_zero_addr(lbProcedure *p, LLVMValueRef ptr, Type *type);
void lb_build_nested_proc(lbProcedure *p, AstProcLit *pd, Entity *e); gb_internal void lb_build_nested_proc(lbProcedure *p, AstProcLit *pd, Entity *e);
lbValue lb_emit_logical_binary_expr(lbProcedure *p, TokenKind op, Ast *left, Ast *right, Type *type); gb_internal lbValue lb_emit_logical_binary_expr(lbProcedure *p, TokenKind op, Ast *left, Ast *right, Type *type);
lbValue lb_build_cond(lbProcedure *p, Ast *cond, lbBlock *true_block, lbBlock *false_block); gb_internal lbValue lb_build_cond(lbProcedure *p, Ast *cond, lbBlock *true_block, lbBlock *false_block);
LLVMValueRef llvm_const_named_struct(lbModule *m, Type *t, LLVMValueRef *values, isize value_count_); gb_internal LLVMValueRef llvm_const_named_struct(lbModule *m, Type *t, LLVMValueRef *values, isize value_count_);
LLVMValueRef llvm_const_named_struct_internal(LLVMTypeRef t, LLVMValueRef *values, isize value_count_); gb_internal LLVMValueRef llvm_const_named_struct_internal(LLVMTypeRef t, LLVMValueRef *values, isize value_count_);
void lb_set_entity_from_other_modules_linkage_correctly(lbModule *other_module, Entity *e, String const &name); gb_internal void lb_set_entity_from_other_modules_linkage_correctly(lbModule *other_module, Entity *e, String const &name);
lbValue lb_expr_untyped_const_to_typed(lbModule *m, Ast *expr, Type *t); gb_internal lbValue lb_expr_untyped_const_to_typed(lbModule *m, Ast *expr, Type *t);
bool lb_is_expr_untyped_const(Ast *expr); gb_internal bool lb_is_expr_untyped_const(Ast *expr);
LLVMValueRef llvm_alloca(lbProcedure *p, LLVMTypeRef llvm_type, isize alignment, char const *name = ""); gb_internal LLVMValueRef llvm_alloca(lbProcedure *p, LLVMTypeRef llvm_type, isize alignment, char const *name = "");
void lb_mem_zero_ptr(lbProcedure *p, LLVMValueRef ptr, Type *type, unsigned alignment); gb_internal void lb_mem_zero_ptr(lbProcedure *p, LLVMValueRef ptr, Type *type, unsigned alignment);
void lb_emit_init_context(lbProcedure *p, lbAddr addr); gb_internal void lb_emit_init_context(lbProcedure *p, lbAddr addr);
lbStructFieldRemapping lb_get_struct_remapping(lbModule *m, Type *t); gb_internal lbStructFieldRemapping lb_get_struct_remapping(lbModule *m, Type *t);
LLVMTypeRef lb_type_padding_filler(lbModule *m, i64 padding, i64 padding_align); gb_internal LLVMTypeRef lb_type_padding_filler(lbModule *m, i64 padding, i64 padding_align);
LLVMValueRef llvm_basic_shuffle(lbProcedure *p, LLVMValueRef vector, LLVMValueRef mask); gb_internal LLVMValueRef llvm_basic_shuffle(lbProcedure *p, LLVMValueRef vector, LLVMValueRef mask);
LLVMValueRef lb_call_intrinsic(lbProcedure *p, const char *name, LLVMValueRef* args, unsigned arg_count, LLVMTypeRef* types, unsigned type_count); gb_internal LLVMValueRef lb_call_intrinsic(lbProcedure *p, const char *name, LLVMValueRef* args, unsigned arg_count, LLVMTypeRef* types, unsigned type_count);
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);
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);
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);
i64 lb_max_zero_init_size(void) { gb_internal gb_inline i64 lb_max_zero_init_size(void) {
return cast(i64)(4*build_context.word_size); return cast(i64)(4*build_context.word_size);
} }
LLVMTypeRef OdinLLVMGetArrayElementType(LLVMTypeRef type); gb_internal LLVMTypeRef OdinLLVMGetArrayElementType(LLVMTypeRef type);
LLVMTypeRef OdinLLVMGetVectorElementType(LLVMTypeRef type); gb_internal LLVMTypeRef OdinLLVMGetVectorElementType(LLVMTypeRef type);
#define LB_STARTUP_RUNTIME_PROC_NAME "__$startup_runtime" #define LB_STARTUP_RUNTIME_PROC_NAME "__$startup_runtime"
#define LB_STARTUP_TYPE_INFO_PROC_NAME "__$startup_type_info" #define LB_STARTUP_TYPE_INFO_PROC_NAME "__$startup_type_info"
@@ -632,7 +632,7 @@ enum : LLVMAttributeIndex {
}; };
char const *llvm_linkage_strings[] = { gb_global char const *llvm_linkage_strings[] = {
"external linkage", "external linkage",
"available externally linkage", "available externally linkage",
"link once any linkage", "link once any linkage",
+30 -30
View File
@@ -1,4 +1,4 @@
bool lb_is_const(lbValue value) { gb_internal bool lb_is_const(lbValue value) {
LLVMValueRef v = value.value; LLVMValueRef v = value.value;
if (is_type_untyped_nil(value.type) || is_type_untyped_undef(value.type)) { if (is_type_untyped_nil(value.type) || is_type_untyped_undef(value.type)) {
// TODO(bill): Is this correct behaviour? // TODO(bill): Is this correct behaviour?
@@ -10,7 +10,7 @@ bool lb_is_const(lbValue value) {
return false; return false;
} }
bool lb_is_const_or_global(lbValue value) { gb_internal bool lb_is_const_or_global(lbValue value) {
if (lb_is_const(value)) { if (lb_is_const(value)) {
return true; return true;
} }
@@ -29,7 +29,7 @@ bool lb_is_const_or_global(lbValue value) {
} }
bool lb_is_elem_const(Ast *elem, Type *elem_type) { gb_internal bool lb_is_elem_const(Ast *elem, Type *elem_type) {
if (!elem_type_can_be_constant(elem_type)) { if (!elem_type_can_be_constant(elem_type)) {
return false; return false;
} }
@@ -42,7 +42,7 @@ bool lb_is_elem_const(Ast *elem, Type *elem_type) {
} }
bool lb_is_const_nil(lbValue value) { gb_internal bool lb_is_const_nil(lbValue value) {
LLVMValueRef v = value.value; LLVMValueRef v = value.value;
if (LLVMIsConstant(v)) { if (LLVMIsConstant(v)) {
if (LLVMIsAConstantAggregateZero(v)) { if (LLVMIsAConstantAggregateZero(v)) {
@@ -55,7 +55,7 @@ bool lb_is_const_nil(lbValue value) {
} }
bool lb_is_expr_constant_zero(Ast *expr) { gb_internal bool lb_is_expr_constant_zero(Ast *expr) {
GB_ASSERT(expr != nullptr); GB_ASSERT(expr != nullptr);
auto v = exact_value_to_integer(expr->tav.value); auto v = exact_value_to_integer(expr->tav.value);
if (v.kind == ExactValue_Integer) { if (v.kind == ExactValue_Integer) {
@@ -64,7 +64,7 @@ bool lb_is_expr_constant_zero(Ast *expr) {
return false; return false;
} }
String lb_get_const_string(lbModule *m, lbValue value) { gb_internal String lb_get_const_string(lbModule *m, lbValue value) {
GB_ASSERT(lb_is_const(value)); GB_ASSERT(lb_is_const(value));
GB_ASSERT(LLVMIsConstant(value.value)); GB_ASSERT(LLVMIsConstant(value.value));
@@ -92,7 +92,7 @@ String lb_get_const_string(lbModule *m, lbValue value) {
} }
LLVMValueRef llvm_const_cast(LLVMValueRef val, LLVMTypeRef dst) { gb_internal LLVMValueRef llvm_const_cast(LLVMValueRef val, LLVMTypeRef dst) {
LLVMTypeRef src = LLVMTypeOf(val); LLVMTypeRef src = LLVMTypeOf(val);
if (src == dst) { if (src == dst) {
return val; return val;
@@ -116,7 +116,7 @@ LLVMValueRef llvm_const_cast(LLVMValueRef val, LLVMTypeRef dst) {
} }
lbValue lb_const_ptr_cast(lbModule *m, lbValue value, Type *t) { gb_internal lbValue lb_const_ptr_cast(lbModule *m, lbValue value, Type *t) {
GB_ASSERT(is_type_internally_pointer_like(value.type)); GB_ASSERT(is_type_internally_pointer_like(value.type));
GB_ASSERT(is_type_internally_pointer_like(t)); GB_ASSERT(is_type_internally_pointer_like(t));
GB_ASSERT(lb_is_const(value)); GB_ASSERT(lb_is_const(value));
@@ -127,7 +127,7 @@ lbValue lb_const_ptr_cast(lbModule *m, lbValue value, Type *t) {
return res; return res;
} }
LLVMValueRef llvm_const_named_struct(lbModule *m, Type *t, LLVMValueRef *values, isize value_count_) { gb_internal LLVMValueRef llvm_const_named_struct(lbModule *m, Type *t, LLVMValueRef *values, isize value_count_) {
LLVMTypeRef struct_type = lb_type(m, t); LLVMTypeRef struct_type = lb_type(m, t);
GB_ASSERT(LLVMGetTypeKind(struct_type) == LLVMStructTypeKind); GB_ASSERT(LLVMGetTypeKind(struct_type) == LLVMStructTypeKind);
@@ -157,7 +157,7 @@ LLVMValueRef llvm_const_named_struct(lbModule *m, Type *t, LLVMValueRef *values,
return llvm_const_named_struct_internal(struct_type, values_with_padding, values_with_padding_count); return llvm_const_named_struct_internal(struct_type, values_with_padding, values_with_padding_count);
} }
LLVMValueRef llvm_const_named_struct_internal(LLVMTypeRef t, LLVMValueRef *values, isize value_count_) { gb_internal LLVMValueRef llvm_const_named_struct_internal(LLVMTypeRef t, LLVMValueRef *values, isize value_count_) {
unsigned value_count = cast(unsigned)value_count_; unsigned value_count = cast(unsigned)value_count_;
unsigned elem_count = LLVMCountStructElementTypes(t); unsigned elem_count = LLVMCountStructElementTypes(t);
GB_ASSERT_MSG(value_count == elem_count, "%s %u %u", LLVMPrintTypeToString(t), value_count, elem_count); GB_ASSERT_MSG(value_count == elem_count, "%s %u %u", LLVMPrintTypeToString(t), value_count, elem_count);
@@ -168,7 +168,7 @@ LLVMValueRef llvm_const_named_struct_internal(LLVMTypeRef t, LLVMValueRef *value
return LLVMConstNamedStruct(t, values, value_count); return LLVMConstNamedStruct(t, values, value_count);
} }
LLVMValueRef llvm_const_array(LLVMTypeRef elem_type, LLVMValueRef *values, isize value_count_) { gb_internal LLVMValueRef llvm_const_array(LLVMTypeRef elem_type, LLVMValueRef *values, isize value_count_) {
unsigned value_count = cast(unsigned)value_count_; unsigned value_count = cast(unsigned)value_count_;
for (unsigned i = 0; i < value_count; i++) { for (unsigned i = 0; i < value_count; i++) {
values[i] = llvm_const_cast(values[i], elem_type); values[i] = llvm_const_cast(values[i], elem_type);
@@ -176,7 +176,7 @@ LLVMValueRef llvm_const_array(LLVMTypeRef elem_type, LLVMValueRef *values, isize
return LLVMConstArray(elem_type, values, value_count); return LLVMConstArray(elem_type, values, value_count);
} }
LLVMValueRef llvm_const_slice(lbModule *m, lbValue data, lbValue len) { gb_internal LLVMValueRef llvm_const_slice(lbModule *m, lbValue data, lbValue len) {
GB_ASSERT(is_type_pointer(data.type) || is_type_multi_pointer(data.type)); GB_ASSERT(is_type_pointer(data.type) || is_type_multi_pointer(data.type));
GB_ASSERT(are_types_identical(len.type, t_int)); GB_ASSERT(are_types_identical(len.type, t_int));
LLVMValueRef vals[2] = { LLVMValueRef vals[2] = {
@@ -187,38 +187,38 @@ LLVMValueRef llvm_const_slice(lbModule *m, lbValue data, lbValue len) {
} }
lbValue lb_const_nil(lbModule *m, Type *type) { gb_internal lbValue lb_const_nil(lbModule *m, Type *type) {
LLVMValueRef v = LLVMConstNull(lb_type(m, type)); LLVMValueRef v = LLVMConstNull(lb_type(m, type));
return lbValue{v, type}; return lbValue{v, type};
} }
lbValue lb_const_undef(lbModule *m, Type *type) { gb_internal lbValue lb_const_undef(lbModule *m, Type *type) {
LLVMValueRef v = LLVMGetUndef(lb_type(m, type)); LLVMValueRef v = LLVMGetUndef(lb_type(m, type));
return lbValue{v, type}; return lbValue{v, type};
} }
lbValue lb_const_int(lbModule *m, Type *type, u64 value) { gb_internal lbValue lb_const_int(lbModule *m, Type *type, u64 value) {
lbValue res = {}; lbValue res = {};
res.value = LLVMConstInt(lb_type(m, type), cast(unsigned long long)value, !is_type_unsigned(type)); res.value = LLVMConstInt(lb_type(m, type), cast(unsigned long long)value, !is_type_unsigned(type));
res.type = type; res.type = type;
return res; return res;
} }
lbValue lb_const_string(lbModule *m, String const &value) { gb_internal lbValue lb_const_string(lbModule *m, String const &value) {
return lb_const_value(m, t_string, exact_value_string(value)); return lb_const_value(m, t_string, exact_value_string(value));
} }
lbValue lb_const_bool(lbModule *m, Type *type, bool value) { gb_internal lbValue lb_const_bool(lbModule *m, Type *type, bool value) {
lbValue res = {}; lbValue res = {};
res.value = LLVMConstInt(lb_type(m, type), value, false); res.value = LLVMConstInt(lb_type(m, type), value, false);
res.type = type; res.type = type;
return res; return res;
} }
LLVMValueRef lb_const_f16(lbModule *m, f32 f, Type *type=t_f16) { gb_internal LLVMValueRef lb_const_f16(lbModule *m, f32 f, Type *type=t_f16) {
GB_ASSERT(type_size_of(type) == 2); GB_ASSERT(type_size_of(type) == 2);
u16 u = f32_to_f16(f); u16 u = f32_to_f16(f);
@@ -229,7 +229,7 @@ LLVMValueRef lb_const_f16(lbModule *m, f32 f, Type *type=t_f16) {
return LLVMConstBitCast(i, lb_type(m, type)); return LLVMConstBitCast(i, lb_type(m, type));
} }
LLVMValueRef lb_const_f32(lbModule *m, f32 f, Type *type=t_f32) { gb_internal LLVMValueRef lb_const_f32(lbModule *m, f32 f, Type *type=t_f32) {
GB_ASSERT(type_size_of(type) == 4); GB_ASSERT(type_size_of(type) == 4);
u32 u = bit_cast<u32>(f); u32 u = bit_cast<u32>(f);
if (is_type_different_to_arch_endianness(type)) { if (is_type_different_to_arch_endianness(type)) {
@@ -241,7 +241,7 @@ LLVMValueRef lb_const_f32(lbModule *m, f32 f, Type *type=t_f32) {
bool lb_is_expr_untyped_const(Ast *expr) { gb_internal bool lb_is_expr_untyped_const(Ast *expr) {
auto const &tv = type_and_value_of_expr(expr); auto const &tv = type_and_value_of_expr(expr);
if (is_type_untyped(tv.type)) { if (is_type_untyped(tv.type)) {
return tv.value.kind != ExactValue_Invalid; return tv.value.kind != ExactValue_Invalid;
@@ -250,13 +250,13 @@ bool lb_is_expr_untyped_const(Ast *expr) {
} }
lbValue lb_expr_untyped_const_to_typed(lbModule *m, Ast *expr, Type *t) { gb_internal lbValue lb_expr_untyped_const_to_typed(lbModule *m, Ast *expr, Type *t) {
GB_ASSERT(is_type_typed(t)); GB_ASSERT(is_type_typed(t));
auto const &tv = type_and_value_of_expr(expr); auto const &tv = type_and_value_of_expr(expr);
return lb_const_value(m, t, tv.value); return lb_const_value(m, t, tv.value);
} }
lbValue lb_emit_source_code_location_const(lbProcedure *p, String const &procedure, TokenPos const &pos) { gb_internal lbValue lb_emit_source_code_location_const(lbProcedure *p, String const &procedure, TokenPos const &pos) {
lbModule *m = p->module; lbModule *m = p->module;
LLVMValueRef fields[4] = {}; LLVMValueRef fields[4] = {};
@@ -271,7 +271,7 @@ lbValue lb_emit_source_code_location_const(lbProcedure *p, String const &procedu
return res; return res;
} }
lbValue lb_emit_source_code_location_const(lbProcedure *p, Ast *node) { gb_internal lbValue lb_emit_source_code_location_const(lbProcedure *p, Ast *node) {
String proc_name = {}; String proc_name = {};
if (p->entity) { if (p->entity) {
proc_name = p->entity->token.string; proc_name = p->entity->token.string;
@@ -284,7 +284,7 @@ lbValue lb_emit_source_code_location_const(lbProcedure *p, Ast *node) {
} }
lbValue lb_emit_source_code_location_as_global_ptr(lbProcedure *p, String const &procedure, TokenPos const &pos) { gb_internal lbValue lb_emit_source_code_location_as_global_ptr(lbProcedure *p, String const &procedure, TokenPos const &pos) {
lbValue loc = lb_emit_source_code_location_const(p, procedure, pos); lbValue loc = lb_emit_source_code_location_const(p, procedure, pos);
lbAddr addr = lb_add_global_generated(p->module, loc.type, loc, nullptr); lbAddr addr = lb_add_global_generated(p->module, loc.type, loc, nullptr);
lb_make_global_private_const(addr); lb_make_global_private_const(addr);
@@ -292,24 +292,24 @@ lbValue lb_emit_source_code_location_as_global_ptr(lbProcedure *p, String const
} }
lbValue lb_emit_source_code_location_as_global_ptr(lbProcedure *p, Ast *node) { gb_internal lbValue lb_emit_source_code_location_as_global_ptr(lbProcedure *p, Ast *node) {
lbValue loc = lb_emit_source_code_location_const(p, node); lbValue loc = lb_emit_source_code_location_const(p, node);
lbAddr addr = lb_add_global_generated(p->module, loc.type, loc, nullptr); lbAddr addr = lb_add_global_generated(p->module, loc.type, loc, nullptr);
lb_make_global_private_const(addr); lb_make_global_private_const(addr);
return addr.addr; return addr.addr;
} }
lbValue lb_emit_source_code_location_as_global(lbProcedure *p, String const &procedure, TokenPos const &pos) { gb_internal lbValue lb_emit_source_code_location_as_global(lbProcedure *p, String const &procedure, TokenPos const &pos) {
return lb_emit_load(p, lb_emit_source_code_location_as_global_ptr(p, procedure, pos)); return lb_emit_load(p, lb_emit_source_code_location_as_global_ptr(p, procedure, pos));
} }
lbValue lb_emit_source_code_location_as_global(lbProcedure *p, Ast *node) { gb_internal lbValue lb_emit_source_code_location_as_global(lbProcedure *p, Ast *node) {
return lb_emit_load(p, lb_emit_source_code_location_as_global_ptr(p, node)); return lb_emit_load(p, lb_emit_source_code_location_as_global_ptr(p, node));
} }
LLVMValueRef lb_build_constant_array_values(lbModule *m, Type *type, Type *elem_type, isize count, LLVMValueRef *values, bool allow_local) { gb_internal LLVMValueRef lb_build_constant_array_values(lbModule *m, Type *type, Type *elem_type, isize count, LLVMValueRef *values, bool allow_local) {
bool is_local = allow_local && m->curr_procedure != nullptr; bool is_local = allow_local && m->curr_procedure != nullptr;
bool is_const = true; bool is_const = true;
if (is_local) { if (is_local) {
@@ -341,7 +341,7 @@ LLVMValueRef lb_build_constant_array_values(lbModule *m, Type *type, Type *elem_
return llvm_const_array(lb_type(m, elem_type), values, cast(unsigned int)count); return llvm_const_array(lb_type(m, elem_type), values, cast(unsigned int)count);
} }
LLVMValueRef lb_big_int_to_llvm(lbModule *m, Type *original_type, BigInt const *a) { gb_internal LLVMValueRef lb_big_int_to_llvm(lbModule *m, Type *original_type, BigInt const *a) {
if (big_int_is_zero(a)) { if (big_int_is_zero(a)) {
return LLVMConstNull(lb_type(m, original_type)); return LLVMConstNull(lb_type(m, original_type));
} }
@@ -387,7 +387,7 @@ LLVMValueRef lb_big_int_to_llvm(lbModule *m, Type *original_type, BigInt const *
} }
lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_local) { gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bool allow_local) {
LLVMContextRef ctx = m->ctx; LLVMContextRef ctx = m->ctx;
type = default_type(type); type = default_type(type);
+22 -22
View File
@@ -1,4 +1,4 @@
LLVMMetadataRef lb_get_llvm_metadata(lbModule *m, void *key) { gb_internal LLVMMetadataRef lb_get_llvm_metadata(lbModule *m, void *key) {
if (key == nullptr) { if (key == nullptr) {
return nullptr; return nullptr;
} }
@@ -8,20 +8,20 @@ LLVMMetadataRef lb_get_llvm_metadata(lbModule *m, void *key) {
} }
return nullptr; return nullptr;
} }
void lb_set_llvm_metadata(lbModule *m, void *key, LLVMMetadataRef value) { gb_internal void lb_set_llvm_metadata(lbModule *m, void *key, LLVMMetadataRef value) {
if (key != nullptr) { if (key != nullptr) {
map_set(&m->debug_values, key, value); map_set(&m->debug_values, key, value);
} }
} }
LLVMMetadataRef lb_get_llvm_file_metadata_from_node(lbModule *m, Ast *node) { gb_internal LLVMMetadataRef lb_get_llvm_file_metadata_from_node(lbModule *m, Ast *node) {
if (node == nullptr) { if (node == nullptr) {
return nullptr; return nullptr;
} }
return lb_get_llvm_metadata(m, node->file()); return lb_get_llvm_metadata(m, node->file());
} }
LLVMMetadataRef lb_get_current_debug_scope(lbProcedure *p) { gb_internal LLVMMetadataRef lb_get_current_debug_scope(lbProcedure *p) {
GB_ASSERT_MSG(p->debug_info != nullptr, "missing debug information for %.*s", LIT(p->name)); GB_ASSERT_MSG(p->debug_info != nullptr, "missing debug information for %.*s", LIT(p->name));
for (isize i = p->scope_stack.count-1; i >= 0; i--) { for (isize i = p->scope_stack.count-1; i >= 0; i--) {
@@ -34,21 +34,21 @@ LLVMMetadataRef lb_get_current_debug_scope(lbProcedure *p) {
return p->debug_info; return p->debug_info;
} }
LLVMMetadataRef lb_debug_location_from_token_pos(lbProcedure *p, TokenPos pos) { gb_internal LLVMMetadataRef lb_debug_location_from_token_pos(lbProcedure *p, TokenPos pos) {
LLVMMetadataRef scope = lb_get_current_debug_scope(p); LLVMMetadataRef scope = lb_get_current_debug_scope(p);
GB_ASSERT_MSG(scope != nullptr, "%.*s", LIT(p->name)); GB_ASSERT_MSG(scope != nullptr, "%.*s", LIT(p->name));
return LLVMDIBuilderCreateDebugLocation(p->module->ctx, cast(unsigned)pos.line, cast(unsigned)pos.column, scope, nullptr); return LLVMDIBuilderCreateDebugLocation(p->module->ctx, cast(unsigned)pos.line, cast(unsigned)pos.column, scope, nullptr);
} }
LLVMMetadataRef lb_debug_location_from_ast(lbProcedure *p, Ast *node) { gb_internal LLVMMetadataRef lb_debug_location_from_ast(lbProcedure *p, Ast *node) {
GB_ASSERT(node != nullptr); GB_ASSERT(node != nullptr);
return lb_debug_location_from_token_pos(p, ast_token(node).pos); return lb_debug_location_from_token_pos(p, ast_token(node).pos);
} }
LLVMMetadataRef lb_debug_end_location_from_ast(lbProcedure *p, Ast *node) { gb_internal LLVMMetadataRef lb_debug_end_location_from_ast(lbProcedure *p, Ast *node) {
GB_ASSERT(node != nullptr); GB_ASSERT(node != nullptr);
return lb_debug_location_from_token_pos(p, ast_end_token(node).pos); return lb_debug_location_from_token_pos(p, ast_end_token(node).pos);
} }
LLVMMetadataRef lb_debug_type_internal_proc(lbModule *m, Type *type) { gb_internal LLVMMetadataRef lb_debug_type_internal_proc(lbModule *m, Type *type) {
i64 size = type_size_of(type); // Check size i64 size = type_size_of(type); // Check size
gb_unused(size); gb_unused(size);
@@ -93,7 +93,7 @@ LLVMMetadataRef lb_debug_type_internal_proc(lbModule *m, Type *type) {
return LLVMDIBuilderCreateSubroutineType(m->debug_builder, file, parameters, parameter_count, flags); return LLVMDIBuilderCreateSubroutineType(m->debug_builder, file, parameters, parameter_count, flags);
} }
LLVMMetadataRef lb_debug_struct_field(lbModule *m, String const &name, Type *type, u64 offset_in_bits) { gb_internal LLVMMetadataRef lb_debug_struct_field(lbModule *m, String const &name, Type *type, u64 offset_in_bits) {
unsigned field_line = 1; unsigned field_line = 1;
LLVMDIFlags field_flags = LLVMDIFlagZero; LLVMDIFlags field_flags = LLVMDIFlagZero;
@@ -107,7 +107,7 @@ LLVMMetadataRef lb_debug_struct_field(lbModule *m, String const &name, Type *typ
field_flags, lb_debug_type(m, type) field_flags, lb_debug_type(m, type)
); );
} }
LLVMMetadataRef lb_debug_basic_struct(lbModule *m, String const &name, u64 size_in_bits, u32 align_in_bits, LLVMMetadataRef *elements, unsigned element_count) { gb_internal LLVMMetadataRef lb_debug_basic_struct(lbModule *m, String const &name, u64 size_in_bits, u32 align_in_bits, LLVMMetadataRef *elements, unsigned element_count) {
AstPackage *pkg = m->info->runtime_package; AstPackage *pkg = m->info->runtime_package;
GB_ASSERT(pkg->files.count != 0); GB_ASSERT(pkg->files.count != 0);
LLVMMetadataRef file = lb_get_llvm_metadata(m, pkg->files[0]); LLVMMetadataRef file = lb_get_llvm_metadata(m, pkg->files[0]);
@@ -117,7 +117,7 @@ LLVMMetadataRef lb_debug_basic_struct(lbModule *m, String const &name, u64 size_
} }
LLVMMetadataRef lb_debug_type_basic_type(lbModule *m, String const &name, u64 size_in_bits, LLVMDWARFTypeEncoding encoding, LLVMDIFlags flags = LLVMDIFlagZero) { gb_internal LLVMMetadataRef lb_debug_type_basic_type(lbModule *m, String const &name, u64 size_in_bits, LLVMDWARFTypeEncoding encoding, LLVMDIFlags flags = LLVMDIFlagZero) {
LLVMMetadataRef basic_type = LLVMDIBuilderCreateBasicType(m->debug_builder, cast(char const *)name.text, name.len, size_in_bits, encoding, flags); LLVMMetadataRef basic_type = LLVMDIBuilderCreateBasicType(m->debug_builder, cast(char const *)name.text, name.len, size_in_bits, encoding, flags);
#if 1 #if 1
LLVMMetadataRef final_decl = LLVMDIBuilderCreateTypedef(m->debug_builder, basic_type, cast(char const *)name.text, name.len, nullptr, 0, nullptr, cast(u32)size_in_bits); LLVMMetadataRef final_decl = LLVMDIBuilderCreateTypedef(m->debug_builder, basic_type, cast(char const *)name.text, name.len, nullptr, 0, nullptr, cast(u32)size_in_bits);
@@ -127,7 +127,7 @@ LLVMMetadataRef lb_debug_type_basic_type(lbModule *m, String const &name, u64 si
#endif #endif
} }
LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) { gb_internal LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) {
i64 size = type_size_of(type); // Check size i64 size = type_size_of(type); // Check size
gb_unused(size); gb_unused(size);
@@ -474,7 +474,7 @@ LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) {
return nullptr; return nullptr;
} }
LLVMMetadataRef lb_get_base_scope_metadata(lbModule *m, Scope *scope) { gb_internal LLVMMetadataRef lb_get_base_scope_metadata(lbModule *m, Scope *scope) {
LLVMMetadataRef found = nullptr; LLVMMetadataRef found = nullptr;
for (;;) { for (;;) {
if (scope == nullptr) { if (scope == nullptr) {
@@ -496,7 +496,7 @@ LLVMMetadataRef lb_get_base_scope_metadata(lbModule *m, Scope *scope) {
} }
} }
LLVMMetadataRef lb_debug_type(lbModule *m, Type *type) { gb_internal LLVMMetadataRef lb_debug_type(lbModule *m, Type *type) {
GB_ASSERT(type != nullptr); GB_ASSERT(type != nullptr);
LLVMMetadataRef found = lb_get_llvm_metadata(m, type); LLVMMetadataRef found = lb_get_llvm_metadata(m, type);
if (found != nullptr) { if (found != nullptr) {
@@ -615,7 +615,7 @@ LLVMMetadataRef lb_debug_type(lbModule *m, Type *type) {
return dt; return dt;
} }
void lb_debug_complete_types(lbModule *m) { gb_internal void lb_debug_complete_types(lbModule *m) {
/* unsigned const word_size = cast(unsigned)build_context.word_size; */ /* unsigned const word_size = cast(unsigned)build_context.word_size; */
unsigned const word_bits = cast(unsigned)(8*build_context.word_size); unsigned const word_bits = cast(unsigned)(8*build_context.word_size);
@@ -962,7 +962,7 @@ void lb_debug_complete_types(lbModule *m) {
void lb_add_debug_local_variable(lbProcedure *p, LLVMValueRef ptr, Type *type, Token const &token) { gb_internal void lb_add_debug_local_variable(lbProcedure *p, LLVMValueRef ptr, Type *type, Token const &token) {
if (p->debug_info == nullptr) { if (p->debug_info == nullptr) {
return; return;
} }
@@ -1024,7 +1024,7 @@ void lb_add_debug_local_variable(lbProcedure *p, LLVMValueRef ptr, Type *type, T
LLVMDIBuilderInsertDeclareAtEnd(m->debug_builder, storage, var_info, llvm_expr, llvm_debug_loc, block); LLVMDIBuilderInsertDeclareAtEnd(m->debug_builder, storage, var_info, llvm_expr, llvm_debug_loc, block);
} }
void lb_add_debug_param_variable(lbProcedure *p, LLVMValueRef ptr, Type *type, Token const &token, unsigned arg_number, lbBlock *block, lbArgKind arg_kind) { gb_internal void lb_add_debug_param_variable(lbProcedure *p, LLVMValueRef ptr, Type *type, Token const &token, unsigned arg_number, lbBlock *block, lbArgKind arg_kind) {
if (p->debug_info == nullptr) { if (p->debug_info == nullptr) {
return; return;
} }
@@ -1097,7 +1097,7 @@ void lb_add_debug_param_variable(lbProcedure *p, LLVMValueRef ptr, Type *type, T
} }
void lb_add_debug_context_variable(lbProcedure *p, lbAddr const &ctx) { gb_internal void lb_add_debug_context_variable(lbProcedure *p, lbAddr const &ctx) {
if (!p->debug_info || !p->body) { if (!p->debug_info || !p->body) {
return; return;
} }
@@ -1125,7 +1125,7 @@ void lb_add_debug_context_variable(lbProcedure *p, lbAddr const &ctx) {
} }
String debug_info_mangle_constant_name(Entity *e, bool *did_allocate_) { gb_internal String debug_info_mangle_constant_name(Entity *e, bool *did_allocate_) {
String name = e->token.string; String name = e->token.string;
if (e->pkg && e->pkg->name.len > 0) { if (e->pkg && e->pkg->name.len > 0) {
// NOTE(bill): C++ NONSENSE FOR DEBUG SHITE! // NOTE(bill): C++ NONSENSE FOR DEBUG SHITE!
@@ -1135,7 +1135,7 @@ String debug_info_mangle_constant_name(Entity *e, bool *did_allocate_) {
return name; return name;
} }
void add_debug_info_global_variable_expr(lbModule *m, String const &name, LLVMMetadataRef dtype, LLVMMetadataRef expr) { gb_internal void add_debug_info_global_variable_expr(lbModule *m, String const &name, LLVMMetadataRef dtype, LLVMMetadataRef expr) {
LLVMMetadataRef scope = nullptr; LLVMMetadataRef scope = nullptr;
LLVMMetadataRef file = nullptr; LLVMMetadataRef file = nullptr;
unsigned line = 0; unsigned line = 0;
@@ -1151,7 +1151,7 @@ void add_debug_info_global_variable_expr(lbModule *m, String const &name, LLVMMe
expr, decl, 8/*AlignInBits*/); expr, decl, 8/*AlignInBits*/);
} }
void add_debug_info_for_global_constant_internal_i64(lbModule *m, Entity *e, LLVMMetadataRef dtype, i64 v) { gb_internal void add_debug_info_for_global_constant_internal_i64(lbModule *m, Entity *e, LLVMMetadataRef dtype, i64 v) {
LLVMMetadataRef expr = LLVMDIBuilderCreateConstantValueExpression(m->debug_builder, v); LLVMMetadataRef expr = LLVMDIBuilderCreateConstantValueExpression(m->debug_builder, v);
bool did_allocate = false; bool did_allocate = false;
@@ -1167,7 +1167,7 @@ void add_debug_info_for_global_constant_internal_i64(lbModule *m, Entity *e, LLV
} }
} }
void add_debug_info_for_global_constant_from_entity(lbGenerator *gen, Entity *e) { gb_internal void add_debug_info_for_global_constant_from_entity(lbGenerator *gen, Entity *e) {
if (e == nullptr || e->kind != Entity_Constant) { if (e == nullptr || e->kind != Entity_Constant) {
return; return;
} }
+40 -40
View File
@@ -1,6 +1,6 @@
lbValue lb_emit_arith_matrix(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type, bool component_wise); gb_internal lbValue lb_emit_arith_matrix(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type, bool component_wise);
lbValue lb_emit_logical_binary_expr(lbProcedure *p, TokenKind op, Ast *left, Ast *right, Type *type) { gb_internal lbValue lb_emit_logical_binary_expr(lbProcedure *p, TokenKind op, Ast *left, Ast *right, Type *type) {
lbModule *m = p->module; lbModule *m = p->module;
lbBlock *rhs = lb_create_block(p, "logical.cmp.rhs"); lbBlock *rhs = lb_create_block(p, "logical.cmp.rhs");
@@ -113,7 +113,7 @@ lbValue lb_emit_logical_binary_expr(lbProcedure *p, TokenKind op, Ast *left, Ast
} }
lbValue lb_emit_unary_arith(lbProcedure *p, TokenKind op, lbValue x, Type *type) { gb_internal lbValue lb_emit_unary_arith(lbProcedure *p, TokenKind op, lbValue x, Type *type) {
switch (op) { switch (op) {
case Token_Add: case Token_Add:
return x; return x;
@@ -283,7 +283,7 @@ lbValue lb_emit_unary_arith(lbProcedure *p, TokenKind op, lbValue x, Type *type)
return res; return res;
} }
bool lb_try_direct_vector_arith(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type, lbValue *res_) { gb_internal bool lb_try_direct_vector_arith(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type, lbValue *res_) {
GB_ASSERT(is_type_array_like(type)); GB_ASSERT(is_type_array_like(type));
Type *elem_type = base_array_type(type); Type *elem_type = base_array_type(type);
@@ -418,7 +418,7 @@ bool lb_try_direct_vector_arith(lbProcedure *p, TokenKind op, lbValue lhs, lbVal
} }
lbValue lb_emit_arith_array(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type) { gb_internal lbValue lb_emit_arith_array(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type) {
GB_ASSERT(is_type_array_like(lhs.type) || is_type_array_like(rhs.type)); GB_ASSERT(is_type_array_like(lhs.type) || is_type_array_like(rhs.type));
lhs = lb_emit_conv(p, lhs, type); lhs = lb_emit_conv(p, lhs, type);
@@ -490,7 +490,7 @@ lbValue lb_emit_arith_array(lbProcedure *p, TokenKind op, lbValue lhs, lbValue r
} }
} }
bool lb_is_matrix_simdable(Type *t) { gb_internal bool lb_is_matrix_simdable(Type *t) {
Type *mt = base_type(t); Type *mt = base_type(t);
GB_ASSERT(mt->kind == Type_Matrix); GB_ASSERT(mt->kind == Type_Matrix);
@@ -534,7 +534,7 @@ bool lb_is_matrix_simdable(Type *t) {
} }
LLVMValueRef lb_matrix_to_vector(lbProcedure *p, lbValue matrix) { gb_internal LLVMValueRef lb_matrix_to_vector(lbProcedure *p, lbValue matrix) {
Type *mt = base_type(matrix.type); Type *mt = base_type(matrix.type);
GB_ASSERT(mt->kind == Type_Matrix); GB_ASSERT(mt->kind == Type_Matrix);
LLVMTypeRef elem_type = lb_type(p->module, mt->Matrix.elem); LLVMTypeRef elem_type = lb_type(p->module, mt->Matrix.elem);
@@ -554,7 +554,7 @@ LLVMValueRef lb_matrix_to_vector(lbProcedure *p, lbValue matrix) {
#endif #endif
} }
LLVMValueRef lb_matrix_trimmed_vector_mask(lbProcedure *p, Type *mt) { gb_internal LLVMValueRef lb_matrix_trimmed_vector_mask(lbProcedure *p, Type *mt) {
mt = base_type(mt); mt = base_type(mt);
GB_ASSERT(mt->kind == Type_Matrix); GB_ASSERT(mt->kind == Type_Matrix);
@@ -574,7 +574,7 @@ LLVMValueRef lb_matrix_trimmed_vector_mask(lbProcedure *p, Type *mt) {
return mask; return mask;
} }
LLVMValueRef lb_matrix_to_trimmed_vector(lbProcedure *p, lbValue m) { gb_internal LLVMValueRef lb_matrix_to_trimmed_vector(lbProcedure *p, lbValue m) {
LLVMValueRef vector = lb_matrix_to_vector(p, m); LLVMValueRef vector = lb_matrix_to_vector(p, m);
Type *mt = base_type(m.type); Type *mt = base_type(m.type);
@@ -592,7 +592,7 @@ LLVMValueRef lb_matrix_to_trimmed_vector(lbProcedure *p, lbValue m) {
} }
lbValue lb_emit_matrix_tranpose(lbProcedure *p, lbValue m, Type *type) { gb_internal lbValue lb_emit_matrix_tranpose(lbProcedure *p, lbValue m, Type *type) {
if (is_type_array(m.type)) { if (is_type_array(m.type)) {
i32 rank = type_math_rank(m.type); i32 rank = type_math_rank(m.type);
if (rank == 2) { if (rank == 2) {
@@ -669,7 +669,7 @@ lbValue lb_emit_matrix_tranpose(lbProcedure *p, lbValue m, Type *type) {
return lb_addr_load(p, res); return lb_addr_load(p, res);
} }
lbValue lb_matrix_cast_vector_to_type(lbProcedure *p, LLVMValueRef vector, Type *type) { gb_internal lbValue lb_matrix_cast_vector_to_type(lbProcedure *p, LLVMValueRef vector, Type *type) {
lbAddr res = lb_add_local_generated(p, type, true); lbAddr res = lb_add_local_generated(p, type, true);
LLVMValueRef res_ptr = res.addr.value; LLVMValueRef res_ptr = res.addr.value;
unsigned alignment = cast(unsigned)gb_max(type_align_of(type), lb_alignof(LLVMTypeOf(vector))); unsigned alignment = cast(unsigned)gb_max(type_align_of(type), lb_alignof(LLVMTypeOf(vector)));
@@ -681,7 +681,7 @@ lbValue lb_matrix_cast_vector_to_type(lbProcedure *p, LLVMValueRef vector, Type
return lb_addr_load(p, res); return lb_addr_load(p, res);
} }
lbValue lb_emit_matrix_flatten(lbProcedure *p, lbValue m, Type *type) { gb_internal lbValue lb_emit_matrix_flatten(lbProcedure *p, lbValue m, Type *type) {
if (is_type_array(m.type)) { if (is_type_array(m.type)) {
// no-op // no-op
m.type = type; m.type = type;
@@ -710,7 +710,7 @@ lbValue lb_emit_matrix_flatten(lbProcedure *p, lbValue m, Type *type) {
} }
lbValue lb_emit_outer_product(lbProcedure *p, lbValue a, lbValue b, Type *type) { gb_internal lbValue lb_emit_outer_product(lbProcedure *p, lbValue a, lbValue b, Type *type) {
Type *mt = base_type(type); Type *mt = base_type(type);
Type *at = base_type(a.type); Type *at = base_type(a.type);
Type *bt = base_type(b.type); Type *bt = base_type(b.type);
@@ -741,7 +741,7 @@ lbValue lb_emit_outer_product(lbProcedure *p, lbValue a, lbValue b, Type *type)
} }
lbValue lb_emit_matrix_mul(lbProcedure *p, lbValue lhs, lbValue rhs, Type *type) { gb_internal lbValue lb_emit_matrix_mul(lbProcedure *p, lbValue lhs, lbValue rhs, Type *type) {
// TODO(bill): Handle edge case for f16 types on x86(-64) platforms // TODO(bill): Handle edge case for f16 types on x86(-64) platforms
Type *xt = base_type(lhs.type); Type *xt = base_type(lhs.type);
@@ -828,7 +828,7 @@ lbValue lb_emit_matrix_mul(lbProcedure *p, lbValue lhs, lbValue rhs, Type *type)
} }
} }
lbValue lb_emit_matrix_mul_vector(lbProcedure *p, lbValue lhs, lbValue rhs, Type *type) { gb_internal lbValue lb_emit_matrix_mul_vector(lbProcedure *p, lbValue lhs, lbValue rhs, Type *type) {
// TODO(bill): Handle edge case for f16 types on x86(-64) platforms // TODO(bill): Handle edge case for f16 types on x86(-64) platforms
Type *mt = base_type(lhs.type); Type *mt = base_type(lhs.type);
@@ -897,7 +897,7 @@ lbValue lb_emit_matrix_mul_vector(lbProcedure *p, lbValue lhs, lbValue rhs, Type
return lb_addr_load(p, res); return lb_addr_load(p, res);
} }
lbValue lb_emit_vector_mul_matrix(lbProcedure *p, lbValue lhs, lbValue rhs, Type *type) { gb_internal lbValue lb_emit_vector_mul_matrix(lbProcedure *p, lbValue lhs, lbValue rhs, Type *type) {
// TODO(bill): Handle edge case for f16 types on x86(-64) platforms // TODO(bill): Handle edge case for f16 types on x86(-64) platforms
Type *mt = base_type(rhs.type); Type *mt = base_type(rhs.type);
@@ -984,7 +984,7 @@ lbValue lb_emit_vector_mul_matrix(lbProcedure *p, lbValue lhs, lbValue rhs, Type
lbValue lb_emit_arith_matrix(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type, bool component_wise) { gb_internal lbValue lb_emit_arith_matrix(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type, bool component_wise) {
GB_ASSERT(is_type_matrix(lhs.type) || is_type_matrix(rhs.type)); GB_ASSERT(is_type_matrix(lhs.type) || is_type_matrix(rhs.type));
if (op == Token_Mul && !component_wise) { if (op == Token_Mul && !component_wise) {
@@ -1056,7 +1056,7 @@ lbValue lb_emit_arith_matrix(lbProcedure *p, TokenKind op, lbValue lhs, lbValue
lbValue lb_emit_arith(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type) { gb_internal lbValue lb_emit_arith(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type) {
if (is_type_array_like(lhs.type) || is_type_array_like(rhs.type)) { if (is_type_array_like(lhs.type) || is_type_array_like(rhs.type)) {
return lb_emit_arith_array(p, op, lhs, rhs, type); return lb_emit_arith_array(p, op, lhs, rhs, type);
} else if (is_type_matrix(lhs.type) || is_type_matrix(rhs.type)) { } else if (is_type_matrix(lhs.type) || is_type_matrix(rhs.type)) {
@@ -1325,7 +1325,7 @@ handle_op:
return {}; return {};
} }
lbValue lb_build_binary_expr(lbProcedure *p, Ast *expr) { gb_internal lbValue lb_build_binary_expr(lbProcedure *p, Ast *expr) {
ast_node(be, BinaryExpr, expr); ast_node(be, BinaryExpr, expr);
TypeAndValue tv = type_and_value_of_expr(expr); TypeAndValue tv = type_and_value_of_expr(expr);
@@ -1472,7 +1472,7 @@ lbValue lb_build_binary_expr(lbProcedure *p, Ast *expr) {
return {}; return {};
} }
lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t) { gb_internal lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t) {
lbModule *m = p->module; lbModule *m = p->module;
t = reduce_tuple_to_single_type(t); t = reduce_tuple_to_single_type(t);
@@ -2202,7 +2202,7 @@ lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t) {
return {}; return {};
} }
lbValue lb_compare_records(lbProcedure *p, TokenKind op_kind, lbValue left, lbValue right, Type *type) { gb_internal lbValue lb_compare_records(lbProcedure *p, TokenKind op_kind, lbValue left, lbValue right, Type *type) {
GB_ASSERT((is_type_struct(type) || is_type_union(type)) && is_type_comparable(type)); GB_ASSERT((is_type_struct(type) || is_type_union(type)) && is_type_comparable(type));
lbValue left_ptr = lb_address_from_load_or_generate_local(p, left); lbValue left_ptr = lb_address_from_load_or_generate_local(p, left);
lbValue right_ptr = lb_address_from_load_or_generate_local(p, right); lbValue right_ptr = lb_address_from_load_or_generate_local(p, right);
@@ -2230,7 +2230,7 @@ lbValue lb_compare_records(lbProcedure *p, TokenKind op_kind, lbValue left, lbVa
lbValue lb_emit_comp(lbProcedure *p, TokenKind op_kind, lbValue left, lbValue right) { gb_internal lbValue lb_emit_comp(lbProcedure *p, TokenKind op_kind, lbValue left, lbValue right) {
Type *a = core_type(left.type); Type *a = core_type(left.type);
Type *b = core_type(right.type); Type *b = core_type(right.type);
@@ -2642,7 +2642,7 @@ lbValue lb_emit_comp(lbProcedure *p, TokenKind op_kind, lbValue left, lbValue ri
lbValue lb_emit_comp_against_nil(lbProcedure *p, TokenKind op_kind, lbValue x) { gb_internal lbValue lb_emit_comp_against_nil(lbProcedure *p, TokenKind op_kind, lbValue x) {
lbValue res = {}; lbValue res = {};
res.type = t_llvm_bool; res.type = t_llvm_bool;
Type *t = x.type; Type *t = x.type;
@@ -2803,7 +2803,7 @@ lbValue lb_emit_comp_against_nil(lbProcedure *p, TokenKind op_kind, lbValue x) {
return {}; return {};
} }
lbValue lb_make_soa_pointer(lbProcedure *p, Type *type, lbValue const &addr, lbValue const &index) { gb_internal lbValue lb_make_soa_pointer(lbProcedure *p, Type *type, lbValue const &addr, lbValue const &index) {
lbAddr v = lb_add_local_generated(p, type, false); lbAddr v = lb_add_local_generated(p, type, false);
lbValue ptr = lb_emit_struct_ep(p, v.addr, 0); lbValue ptr = lb_emit_struct_ep(p, v.addr, 0);
lbValue idx = lb_emit_struct_ep(p, v.addr, 1); lbValue idx = lb_emit_struct_ep(p, v.addr, 1);
@@ -2813,7 +2813,7 @@ lbValue lb_make_soa_pointer(lbProcedure *p, Type *type, lbValue const &addr, lbV
return lb_addr_load(p, v); return lb_addr_load(p, v);
} }
lbValue lb_build_unary_and(lbProcedure *p, Ast *expr) { gb_internal lbValue lb_build_unary_and(lbProcedure *p, Ast *expr) {
ast_node(ue, UnaryExpr, expr); ast_node(ue, UnaryExpr, expr);
auto tv = type_and_value_of_expr(expr); auto tv = type_and_value_of_expr(expr);
@@ -3023,8 +3023,8 @@ lbValue lb_build_unary_and(lbProcedure *p, Ast *expr) {
return lb_build_addr_ptr(p, ue->expr); return lb_build_addr_ptr(p, ue->expr);
} }
lbValue lb_build_expr_internal(lbProcedure *p, Ast *expr); gb_internal lbValue lb_build_expr_internal(lbProcedure *p, Ast *expr);
lbValue lb_build_expr(lbProcedure *p, Ast *expr) { gb_internal lbValue lb_build_expr(lbProcedure *p, Ast *expr) {
u16 prev_state_flags = p->state_flags; u16 prev_state_flags = p->state_flags;
defer (p->state_flags = prev_state_flags); defer (p->state_flags = prev_state_flags);
@@ -3080,7 +3080,7 @@ lbValue lb_build_expr(lbProcedure *p, Ast *expr) {
return res; return res;
} }
lbValue lb_build_expr_internal(lbProcedure *p, Ast *expr) { gb_internal lbValue lb_build_expr_internal(lbProcedure *p, Ast *expr) {
lbModule *m = p->module; lbModule *m = p->module;
expr = unparen_expr(expr); expr = unparen_expr(expr);
@@ -3355,10 +3355,10 @@ lbValue lb_build_expr_internal(lbProcedure *p, Ast *expr) {
return {}; return {};
} }
lbAddr lb_get_soa_variable_addr(lbProcedure *p, Entity *e) { gb_internal lbAddr lb_get_soa_variable_addr(lbProcedure *p, Entity *e) {
return map_must_get(&p->module->soa_values, e); return map_must_get(&p->module->soa_values, e);
} }
lbValue lb_get_using_variable(lbProcedure *p, Entity *e) { gb_internal lbValue lb_get_using_variable(lbProcedure *p, Entity *e) {
GB_ASSERT(e->kind == Entity_Variable && e->flags & EntityFlag_Using); GB_ASSERT(e->kind == Entity_Variable && e->flags & EntityFlag_Using);
String name = e->token.string; String name = e->token.string;
Entity *parent = e->using_parent; Entity *parent = e->using_parent;
@@ -3393,7 +3393,7 @@ lbValue lb_get_using_variable(lbProcedure *p, Entity *e) {
lbAddr lb_build_addr_from_entity(lbProcedure *p, Entity *e, Ast *expr) { gb_internal lbAddr lb_build_addr_from_entity(lbProcedure *p, Entity *e, Ast *expr) {
GB_ASSERT(e != nullptr); GB_ASSERT(e != nullptr);
if (e->kind == Entity_Constant) { if (e->kind == Entity_Constant) {
Type *t = default_type(type_of_expr(expr)); Type *t = default_type(type_of_expr(expr));
@@ -3427,7 +3427,7 @@ lbAddr lb_build_addr_from_entity(lbProcedure *p, Entity *e, Ast *expr) {
return lb_addr(v); return lb_addr(v);
} }
lbAddr lb_build_array_swizzle_addr(lbProcedure *p, AstCallExpr *ce, TypeAndValue const &tv) { gb_internal lbAddr lb_build_array_swizzle_addr(lbProcedure *p, AstCallExpr *ce, TypeAndValue const &tv) {
isize index_count = ce->args.count-1; isize index_count = ce->args.count-1;
lbAddr addr = lb_build_addr(p, ce->args[0]); lbAddr addr = lb_build_addr(p, ce->args[0]);
if (index_count == 0) { if (index_count == 0) {
@@ -3463,8 +3463,8 @@ lbAddr lb_build_array_swizzle_addr(lbProcedure *p, AstCallExpr *ce, TypeAndValue
} }
lbAddr lb_build_addr_internal(lbProcedure *p, Ast *expr); gb_internal lbAddr lb_build_addr_internal(lbProcedure *p, Ast *expr);
lbAddr lb_build_addr(lbProcedure *p, Ast *expr) { gb_internal lbAddr lb_build_addr(lbProcedure *p, Ast *expr) {
expr = unparen_expr(expr); expr = unparen_expr(expr);
// IMPORTANT NOTE(bill): // IMPORTANT NOTE(bill):
@@ -3489,7 +3489,7 @@ lbAddr lb_build_addr(lbProcedure *p, Ast *expr) {
return addr; return addr;
} }
void lb_build_addr_compound_lit_populate(lbProcedure *p, Slice<Ast *> const &elems, Array<lbCompoundLitElemTempData> *temp_data, Type *compound_type) { gb_internal void lb_build_addr_compound_lit_populate(lbProcedure *p, Slice<Ast *> const &elems, Array<lbCompoundLitElemTempData> *temp_data, Type *compound_type) {
Type *bt = base_type(compound_type); Type *bt = base_type(compound_type);
Type *et = nullptr; Type *et = nullptr;
switch (bt->kind) { switch (bt->kind) {
@@ -3595,7 +3595,7 @@ void lb_build_addr_compound_lit_populate(lbProcedure *p, Slice<Ast *> const &ele
} }
} }
} }
void lb_build_addr_compound_lit_assign_array(lbProcedure *p, Array<lbCompoundLitElemTempData> const &temp_data) { gb_internal void lb_build_addr_compound_lit_assign_array(lbProcedure *p, Array<lbCompoundLitElemTempData> const &temp_data) {
for_array(i, temp_data) { for_array(i, temp_data) {
auto td = temp_data[i]; auto td = temp_data[i];
if (td.value.value != nullptr) { if (td.value.value != nullptr) {
@@ -3614,7 +3614,7 @@ void lb_build_addr_compound_lit_assign_array(lbProcedure *p, Array<lbCompoundLit
} }
} }
lbAddr lb_build_addr_index_expr(lbProcedure *p, Ast *expr) { gb_internal lbAddr lb_build_addr_index_expr(lbProcedure *p, Ast *expr) {
ast_node(ie, IndexExpr, expr); ast_node(ie, IndexExpr, expr);
Type *t = base_type(type_of_expr(ie->expr)); Type *t = base_type(type_of_expr(ie->expr));
@@ -3833,7 +3833,7 @@ lbAddr lb_build_addr_index_expr(lbProcedure *p, Ast *expr) {
} }
lbAddr lb_build_addr_slice_expr(lbProcedure *p, Ast *expr) { gb_internal lbAddr lb_build_addr_slice_expr(lbProcedure *p, Ast *expr) {
ast_node(se, SliceExpr, expr); ast_node(se, SliceExpr, expr);
lbValue low = lb_const_int(p->module, t_int, 0); lbValue low = lb_const_int(p->module, t_int, 0);
@@ -4031,7 +4031,7 @@ lbAddr lb_build_addr_slice_expr(lbProcedure *p, Ast *expr) {
} }
lbAddr lb_build_addr_compound_lit(lbProcedure *p, Ast *expr) { gb_internal lbAddr lb_build_addr_compound_lit(lbProcedure *p, Ast *expr) {
ast_node(cl, CompoundLit, expr); ast_node(cl, CompoundLit, expr);
Type *type = type_of_expr(expr); Type *type = type_of_expr(expr);
@@ -4383,7 +4383,7 @@ lbAddr lb_build_addr_compound_lit(lbProcedure *p, Ast *expr) {
} }
lbAddr lb_build_addr_internal(lbProcedure *p, Ast *expr) { gb_internal lbAddr lb_build_addr_internal(lbProcedure *p, Ast *expr) {
switch (expr->kind) { switch (expr->kind) {
case_ast_node(i, Implicit, expr); case_ast_node(i, Implicit, expr);
lbAddr v = {}; lbAddr v = {};
+91 -91
View File
@@ -1,4 +1,4 @@
void lb_add_debug_local_variable(lbProcedure *p, LLVMValueRef ptr, Type *type, Token const &token); gb_internal void lb_add_debug_local_variable(lbProcedure *p, LLVMValueRef ptr, Type *type, Token const &token);
gb_global Entity *lb_global_type_info_data_entity = {}; gb_global Entity *lb_global_type_info_data_entity = {};
gb_global lbAddr lb_global_type_info_member_types = {}; gb_global lbAddr lb_global_type_info_member_types = {};
@@ -15,7 +15,7 @@ gb_global isize lb_global_type_info_member_usings_index = 0;
gb_global isize lb_global_type_info_member_tags_index = 0; gb_global isize lb_global_type_info_member_tags_index = 0;
void lb_init_module(lbModule *m, Checker *c) { gb_internal void lb_init_module(lbModule *m, Checker *c) {
m->info = &c->info; m->info = &c->info;
gbString module_name = gb_string_make(heap_allocator(), "odin_package"); gbString module_name = gb_string_make(heap_allocator(), "odin_package");
@@ -82,7 +82,7 @@ void lb_init_module(lbModule *m, Checker *c) {
} }
bool lb_init_generator(lbGenerator *gen, Checker *c) { gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c) {
if (global_error_collector.count != 0) { if (global_error_collector.count != 0) {
return false; return false;
} }
@@ -164,7 +164,7 @@ bool lb_init_generator(lbGenerator *gen, Checker *c) {
lbValue lb_global_type_info_data_ptr(lbModule *m) { gb_internal lbValue lb_global_type_info_data_ptr(lbModule *m) {
lbValue v = lb_find_value_from_entity(m, lb_global_type_info_data_entity); lbValue v = lb_find_value_from_entity(m, lb_global_type_info_data_entity);
return v; return v;
} }
@@ -187,7 +187,7 @@ struct lbCompoundLitElemTempData {
}; };
lbLoopData lb_loop_start(lbProcedure *p, isize count, Type *index_type=t_i32) { gb_internal lbLoopData lb_loop_start(lbProcedure *p, isize count, Type *index_type=t_i32) {
lbLoopData data = {}; lbLoopData data = {};
lbValue max = lb_const_int(p->module, t_int, count); lbValue max = lb_const_int(p->module, t_int, count);
@@ -210,7 +210,7 @@ lbLoopData lb_loop_start(lbProcedure *p, isize count, Type *index_type=t_i32) {
return data; return data;
} }
void lb_loop_end(lbProcedure *p, lbLoopData const &data) { gb_internal void lb_loop_end(lbProcedure *p, lbLoopData const &data) {
if (data.idx_addr.addr.value != nullptr) { if (data.idx_addr.addr.value != nullptr) {
lb_emit_increment(p, data.idx_addr.addr); lb_emit_increment(p, data.idx_addr.addr);
lb_emit_jump(p, data.loop); lb_emit_jump(p, data.loop);
@@ -219,19 +219,19 @@ void lb_loop_end(lbProcedure *p, lbLoopData const &data) {
} }
void lb_make_global_private_const(LLVMValueRef global_data) { gb_internal void lb_make_global_private_const(LLVMValueRef global_data) {
LLVMSetLinkage(global_data, LLVMPrivateLinkage); LLVMSetLinkage(global_data, LLVMPrivateLinkage);
LLVMSetUnnamedAddress(global_data, LLVMGlobalUnnamedAddr); LLVMSetUnnamedAddress(global_data, LLVMGlobalUnnamedAddr);
LLVMSetGlobalConstant(global_data, true); LLVMSetGlobalConstant(global_data, true);
} }
void lb_make_global_private_const(lbAddr const &addr) { gb_internal void lb_make_global_private_const(lbAddr const &addr) {
lb_make_global_private_const(addr.addr.value); lb_make_global_private_const(addr.addr.value);
} }
// This emits a GEP at 0, index // This emits a GEP at 0, index
lbValue lb_emit_epi(lbProcedure *p, lbValue const &value, isize index) { gb_internal lbValue lb_emit_epi(lbProcedure *p, lbValue const &value, isize index) {
GB_ASSERT(is_type_pointer(value.type)); GB_ASSERT(is_type_pointer(value.type));
Type *type = type_deref(value.type); Type *type = type_deref(value.type);
@@ -251,7 +251,7 @@ lbValue lb_emit_epi(lbProcedure *p, lbValue const &value, isize index) {
return res; return res;
} }
// This emits a GEP at 0, index // This emits a GEP at 0, index
lbValue lb_emit_epi(lbModule *m, lbValue const &value, isize index) { gb_internal lbValue lb_emit_epi(lbModule *m, lbValue const &value, isize index) {
GB_ASSERT(is_type_pointer(value.type)); GB_ASSERT(is_type_pointer(value.type));
GB_ASSERT(LLVMIsConstant(value.value)); GB_ASSERT(LLVMIsConstant(value.value));
Type *type = type_deref(value.type); Type *type = type_deref(value.type);
@@ -269,17 +269,17 @@ lbValue lb_emit_epi(lbModule *m, lbValue const &value, isize index) {
LLVMValueRef llvm_zero(lbModule *m) { gb_internal LLVMValueRef llvm_zero(lbModule *m) {
return LLVMConstInt(lb_type(m, t_int), 0, false); return LLVMConstInt(lb_type(m, t_int), 0, false);
} }
LLVMValueRef llvm_zero32(lbModule *m) { gb_internal LLVMValueRef llvm_zero32(lbModule *m) {
return LLVMConstInt(lb_type(m, t_i32), 0, false); return LLVMConstInt(lb_type(m, t_i32), 0, false);
} }
LLVMValueRef llvm_one(lbModule *m) { gb_internal LLVMValueRef llvm_one(lbModule *m) {
return LLVMConstInt(lb_type(m, t_i32), 1, false); return LLVMConstInt(lb_type(m, t_i32), 1, false);
} }
LLVMValueRef llvm_alloca(lbProcedure *p, LLVMTypeRef llvm_type, isize alignment, char const *name) { gb_internal LLVMValueRef llvm_alloca(lbProcedure *p, LLVMTypeRef llvm_type, isize alignment, char const *name) {
LLVMPositionBuilderAtEnd(p->builder, p->decl_block->block); LLVMPositionBuilderAtEnd(p->builder, p->decl_block->block);
LLVMValueRef val = LLVMBuildAlloca(p->builder, llvm_type, name); LLVMValueRef val = LLVMBuildAlloca(p->builder, llvm_type, name);
@@ -290,20 +290,20 @@ LLVMValueRef llvm_alloca(lbProcedure *p, LLVMTypeRef llvm_type, isize alignment,
return val; return val;
} }
lbValue lb_zero(lbModule *m, Type *t) { gb_internal lbValue lb_zero(lbModule *m, Type *t) {
lbValue v = {}; lbValue v = {};
v.value = LLVMConstInt(lb_type(m, t), 0, false); v.value = LLVMConstInt(lb_type(m, t), 0, false);
v.type = t; v.type = t;
return v; return v;
} }
LLVMValueRef llvm_cstring(lbModule *m, String const &str) { gb_internal LLVMValueRef llvm_cstring(lbModule *m, String const &str) {
lbValue v = lb_find_or_add_entity_string(m, str); lbValue v = lb_find_or_add_entity_string(m, str);
unsigned indices[1] = {0}; unsigned indices[1] = {0};
return LLVMConstExtractValue(v.value, indices, gb_count_of(indices)); return LLVMConstExtractValue(v.value, indices, gb_count_of(indices));
} }
bool lb_is_instr_terminating(LLVMValueRef instr) { gb_internal bool lb_is_instr_terminating(LLVMValueRef instr) {
if (instr != nullptr) { if (instr != nullptr) {
LLVMOpcode op = LLVMGetInstructionOpcode(instr); LLVMOpcode op = LLVMGetInstructionOpcode(instr);
switch (op) { switch (op) {
@@ -322,7 +322,7 @@ bool lb_is_instr_terminating(LLVMValueRef instr) {
lbModule *lb_pkg_module(lbGenerator *gen, AstPackage *pkg) { gb_internal lbModule *lb_pkg_module(lbGenerator *gen, AstPackage *pkg) {
auto *found = map_get(&gen->modules, pkg); auto *found = map_get(&gen->modules, pkg);
if (found) { if (found) {
return *found; return *found;
@@ -331,7 +331,7 @@ lbModule *lb_pkg_module(lbGenerator *gen, AstPackage *pkg) {
} }
lbAddr lb_addr(lbValue addr) { gb_internal lbAddr lb_addr(lbValue addr) {
lbAddr v = {lbAddr_Default, addr}; lbAddr v = {lbAddr_Default, addr};
if (addr.type != nullptr && is_type_relative_pointer(type_deref(addr.type))) { if (addr.type != nullptr && is_type_relative_pointer(type_deref(addr.type))) {
GB_ASSERT(is_type_pointer(addr.type)); GB_ASSERT(is_type_pointer(addr.type));
@@ -344,7 +344,7 @@ lbAddr lb_addr(lbValue addr) {
} }
lbAddr lb_addr_map(lbValue addr, lbValue map_key, Type *map_type, Type *map_result) { gb_internal lbAddr lb_addr_map(lbValue addr, lbValue map_key, Type *map_type, Type *map_result) {
GB_ASSERT(is_type_pointer(addr.type)); GB_ASSERT(is_type_pointer(addr.type));
Type *mt = type_deref(addr.type); Type *mt = type_deref(addr.type);
GB_ASSERT(is_type_map(mt)); GB_ASSERT(is_type_map(mt));
@@ -357,14 +357,14 @@ lbAddr lb_addr_map(lbValue addr, lbValue map_key, Type *map_type, Type *map_resu
} }
lbAddr lb_addr_soa_variable(lbValue addr, lbValue index, Ast *index_expr) { gb_internal lbAddr lb_addr_soa_variable(lbValue addr, lbValue index, Ast *index_expr) {
lbAddr v = {lbAddr_SoaVariable, addr}; lbAddr v = {lbAddr_SoaVariable, addr};
v.soa.index = index; v.soa.index = index;
v.soa.index_expr = index_expr; v.soa.index_expr = index_expr;
return v; return v;
} }
lbAddr lb_addr_swizzle(lbValue addr, Type *array_type, u8 swizzle_count, u8 swizzle_indices[4]) { gb_internal lbAddr lb_addr_swizzle(lbValue addr, Type *array_type, u8 swizzle_count, u8 swizzle_indices[4]) {
GB_ASSERT(is_type_array(array_type)); GB_ASSERT(is_type_array(array_type));
GB_ASSERT(1 < swizzle_count && swizzle_count <= 4); GB_ASSERT(1 < swizzle_count && swizzle_count <= 4);
lbAddr v = {lbAddr_Swizzle, addr}; lbAddr v = {lbAddr_Swizzle, addr};
@@ -374,7 +374,7 @@ lbAddr lb_addr_swizzle(lbValue addr, Type *array_type, u8 swizzle_count, u8 swiz
return v; return v;
} }
lbAddr lb_addr_swizzle_large(lbValue addr, Type *array_type, Slice<i32> const &swizzle_indices) { gb_internal lbAddr lb_addr_swizzle_large(lbValue addr, Type *array_type, Slice<i32> const &swizzle_indices) {
GB_ASSERT_MSG(is_type_array(array_type), "%s", type_to_string(array_type)); GB_ASSERT_MSG(is_type_array(array_type), "%s", type_to_string(array_type));
lbAddr v = {lbAddr_SwizzleLarge, addr}; lbAddr v = {lbAddr_SwizzleLarge, addr};
v.swizzle_large.type = array_type; v.swizzle_large.type = array_type;
@@ -382,7 +382,7 @@ lbAddr lb_addr_swizzle_large(lbValue addr, Type *array_type, Slice<i32> const &s
return v; return v;
} }
Type *lb_addr_type(lbAddr const &addr) { gb_internal Type *lb_addr_type(lbAddr const &addr) {
if (addr.addr.value == nullptr) { if (addr.addr.value == nullptr) {
return nullptr; return nullptr;
} }
@@ -411,7 +411,7 @@ Type *lb_addr_type(lbAddr const &addr) {
return type_deref(addr.addr.type); return type_deref(addr.addr.type);
} }
lbValue lb_addr_get_ptr(lbProcedure *p, lbAddr const &addr) { gb_internal lbValue lb_addr_get_ptr(lbProcedure *p, lbAddr const &addr) {
if (addr.addr.value == nullptr) { if (addr.addr.value == nullptr) {
GB_PANIC("Illegal addr -> nullptr"); GB_PANIC("Illegal addr -> nullptr");
return {}; return {};
@@ -462,12 +462,12 @@ lbValue lb_addr_get_ptr(lbProcedure *p, lbAddr const &addr) {
} }
lbValue lb_build_addr_ptr(lbProcedure *p, Ast *expr) { gb_internal lbValue lb_build_addr_ptr(lbProcedure *p, Ast *expr) {
lbAddr addr = lb_build_addr(p, expr); lbAddr addr = lb_build_addr(p, expr);
return lb_addr_get_ptr(p, addr); return lb_addr_get_ptr(p, addr);
} }
void lb_emit_bounds_check(lbProcedure *p, Token token, lbValue index, lbValue len) { gb_internal void lb_emit_bounds_check(lbProcedure *p, Token token, lbValue index, lbValue len) {
if (build_context.no_bounds_check) { if (build_context.no_bounds_check) {
return; return;
} }
@@ -492,7 +492,7 @@ void lb_emit_bounds_check(lbProcedure *p, Token token, lbValue index, lbValue le
lb_emit_runtime_call(p, "bounds_check_error", args); lb_emit_runtime_call(p, "bounds_check_error", args);
} }
void lb_emit_matrix_bounds_check(lbProcedure *p, Token token, lbValue row_index, lbValue column_index, lbValue row_count, lbValue column_count) { gb_internal void lb_emit_matrix_bounds_check(lbProcedure *p, Token token, lbValue row_index, lbValue column_index, lbValue row_count, lbValue column_count) {
if (build_context.no_bounds_check) { if (build_context.no_bounds_check) {
return; return;
} }
@@ -522,7 +522,7 @@ void lb_emit_matrix_bounds_check(lbProcedure *p, Token token, lbValue row_index,
} }
void lb_emit_multi_pointer_slice_bounds_check(lbProcedure *p, Token token, lbValue low, lbValue high) { gb_internal void lb_emit_multi_pointer_slice_bounds_check(lbProcedure *p, Token token, lbValue low, lbValue high) {
if (build_context.no_bounds_check) { if (build_context.no_bounds_check) {
return; return;
} }
@@ -547,7 +547,7 @@ void lb_emit_multi_pointer_slice_bounds_check(lbProcedure *p, Token token, lbVal
lb_emit_runtime_call(p, "multi_pointer_slice_expr_error", args); lb_emit_runtime_call(p, "multi_pointer_slice_expr_error", args);
} }
void lb_emit_slice_bounds_check(lbProcedure *p, Token token, lbValue low, lbValue high, lbValue len, bool lower_value_used) { gb_internal void lb_emit_slice_bounds_check(lbProcedure *p, Token token, lbValue low, lbValue high, lbValue len, bool lower_value_used) {
if (build_context.no_bounds_check) { if (build_context.no_bounds_check) {
return; return;
} }
@@ -585,14 +585,14 @@ void lb_emit_slice_bounds_check(lbProcedure *p, Token token, lbValue low, lbValu
} }
} }
unsigned lb_try_get_alignment(LLVMValueRef addr_ptr, unsigned default_alignment) { gb_internal unsigned lb_try_get_alignment(LLVMValueRef addr_ptr, unsigned default_alignment) {
if (LLVMIsAGlobalValue(addr_ptr) || LLVMIsAAllocaInst(addr_ptr) || LLVMIsALoadInst(addr_ptr)) { if (LLVMIsAGlobalValue(addr_ptr) || LLVMIsAAllocaInst(addr_ptr) || LLVMIsALoadInst(addr_ptr)) {
return LLVMGetAlignment(addr_ptr); return LLVMGetAlignment(addr_ptr);
} }
return default_alignment; return default_alignment;
} }
bool lb_try_update_alignment(LLVMValueRef addr_ptr, unsigned alignment) { gb_internal bool lb_try_update_alignment(LLVMValueRef addr_ptr, unsigned alignment) {
if (LLVMIsAGlobalValue(addr_ptr) || LLVMIsAAllocaInst(addr_ptr) || LLVMIsALoadInst(addr_ptr)) { if (LLVMIsAGlobalValue(addr_ptr) || LLVMIsAAllocaInst(addr_ptr) || LLVMIsALoadInst(addr_ptr)) {
if (LLVMGetAlignment(addr_ptr) < alignment) { if (LLVMGetAlignment(addr_ptr) < alignment) {
if (LLVMIsAAllocaInst(addr_ptr) || LLVMIsAGlobalValue(addr_ptr)) { if (LLVMIsAAllocaInst(addr_ptr) || LLVMIsAGlobalValue(addr_ptr)) {
@@ -604,15 +604,15 @@ bool lb_try_update_alignment(LLVMValueRef addr_ptr, unsigned alignment) {
return false; return false;
} }
bool lb_try_update_alignment(lbValue ptr, unsigned alignment) { gb_internal bool lb_try_update_alignment(lbValue ptr, unsigned alignment) {
return lb_try_update_alignment(ptr.value, alignment); return lb_try_update_alignment(ptr.value, alignment);
} }
bool lb_can_try_to_inline_array_arith(Type *t) { gb_internal bool lb_can_try_to_inline_array_arith(Type *t) {
return type_size_of(t) <= build_context.max_simd_align; return type_size_of(t) <= build_context.max_simd_align;
} }
bool lb_try_vector_cast(lbModule *m, lbValue ptr, LLVMTypeRef *vector_type_) { gb_internal bool lb_try_vector_cast(lbModule *m, lbValue ptr, LLVMTypeRef *vector_type_) {
Type *array_type = base_type(type_deref(ptr.type)); Type *array_type = base_type(type_deref(ptr.type));
GB_ASSERT(is_type_array_like(array_type)); GB_ASSERT(is_type_array_like(array_type));
i64 count = get_array_type_count(array_type); i64 count = get_array_type_count(array_type);
@@ -647,7 +647,7 @@ bool lb_try_vector_cast(lbModule *m, lbValue ptr, LLVMTypeRef *vector_type_) {
return false; return false;
} }
void lb_addr_store(lbProcedure *p, lbAddr addr, lbValue value) { gb_internal void lb_addr_store(lbProcedure *p, lbAddr addr, lbValue value) {
if (addr.addr.value == nullptr) { if (addr.addr.value == nullptr) {
return; return;
} }
@@ -874,7 +874,7 @@ void lb_addr_store(lbProcedure *p, lbAddr addr, lbValue value) {
lb_emit_store(p, addr.addr, value); lb_emit_store(p, addr.addr, value);
} }
void lb_const_store(lbValue ptr, lbValue value) { gb_internal void lb_const_store(lbValue ptr, lbValue value) {
GB_ASSERT(lb_is_const(ptr)); GB_ASSERT(lb_is_const(ptr));
GB_ASSERT(lb_is_const(value)); GB_ASSERT(lb_is_const(value));
GB_ASSERT(is_type_pointer(ptr.type)); GB_ASSERT(is_type_pointer(ptr.type));
@@ -882,7 +882,7 @@ void lb_const_store(lbValue ptr, lbValue value) {
} }
bool lb_is_type_proc_recursive(Type *t) { gb_internal bool lb_is_type_proc_recursive(Type *t) {
for (;;) { for (;;) {
if (t == nullptr) { if (t == nullptr) {
return false; return false;
@@ -902,7 +902,7 @@ bool lb_is_type_proc_recursive(Type *t) {
} }
} }
void lb_emit_store(lbProcedure *p, lbValue ptr, lbValue value) { gb_internal void lb_emit_store(lbProcedure *p, lbValue ptr, lbValue value) {
GB_ASSERT(value.value != nullptr); GB_ASSERT(value.value != nullptr);
Type *a = type_deref(ptr.type); Type *a = type_deref(ptr.type);
@@ -978,11 +978,11 @@ void lb_emit_store(lbProcedure *p, lbValue ptr, lbValue value) {
} }
} }
LLVMTypeRef llvm_addr_type(lbModule *module, lbValue addr_val) { gb_internal LLVMTypeRef llvm_addr_type(lbModule *module, lbValue addr_val) {
return lb_type(module, type_deref(addr_val.type)); return lb_type(module, type_deref(addr_val.type));
} }
lbValue lb_emit_load(lbProcedure *p, lbValue value) { gb_internal lbValue lb_emit_load(lbProcedure *p, lbValue value) {
GB_ASSERT(value.value != nullptr); GB_ASSERT(value.value != nullptr);
if (is_type_multi_pointer(value.type)) { if (is_type_multi_pointer(value.type)) {
Type *vt = base_type(value.type); Type *vt = base_type(value.type);
@@ -1003,7 +1003,7 @@ lbValue lb_emit_load(lbProcedure *p, lbValue value) {
return lbValue{v, t}; return lbValue{v, t};
} }
lbValue lb_addr_load(lbProcedure *p, lbAddr const &addr) { gb_internal lbValue lb_addr_load(lbProcedure *p, lbAddr const &addr) {
GB_ASSERT(addr.addr.value != nullptr); GB_ASSERT(addr.addr.value != nullptr);
@@ -1243,11 +1243,11 @@ lbValue lb_addr_load(lbProcedure *p, lbAddr const &addr) {
return lb_emit_load(p, addr.addr); return lb_emit_load(p, addr.addr);
} }
lbValue lb_const_union_tag(lbModule *m, Type *u, Type *v) { gb_internal lbValue lb_const_union_tag(lbModule *m, Type *u, Type *v) {
return lb_const_value(m, union_tag_type(u), exact_value_i64(union_variant_index(u, v))); return lb_const_value(m, union_tag_type(u), exact_value_i64(union_variant_index(u, v)));
} }
lbValue lb_emit_union_tag_ptr(lbProcedure *p, lbValue u) { gb_internal lbValue lb_emit_union_tag_ptr(lbProcedure *p, lbValue u) {
Type *t = u.type; Type *t = u.type;
GB_ASSERT_MSG(is_type_pointer(t) && GB_ASSERT_MSG(is_type_pointer(t) &&
is_type_union(type_deref(t)), "%s", type_to_string(t)); is_type_union(type_deref(t)), "%s", type_to_string(t));
@@ -1269,14 +1269,14 @@ lbValue lb_emit_union_tag_ptr(lbProcedure *p, lbValue u) {
return tag_ptr; return tag_ptr;
} }
lbValue lb_emit_union_tag_value(lbProcedure *p, lbValue u) { gb_internal lbValue lb_emit_union_tag_value(lbProcedure *p, lbValue u) {
lbValue ptr = lb_address_from_load_or_generate_local(p, u); lbValue ptr = lb_address_from_load_or_generate_local(p, u);
lbValue tag_ptr = lb_emit_union_tag_ptr(p, ptr); lbValue tag_ptr = lb_emit_union_tag_ptr(p, ptr);
return lb_emit_load(p, tag_ptr); return lb_emit_load(p, tag_ptr);
} }
void lb_emit_store_union_variant_tag(lbProcedure *p, lbValue parent, Type *variant_type) { gb_internal void lb_emit_store_union_variant_tag(lbProcedure *p, lbValue parent, Type *variant_type) {
Type *t = type_deref(parent.type); Type *t = type_deref(parent.type);
if (is_type_union_maybe_pointer(t) || type_size_of(t) == 0) { if (is_type_union_maybe_pointer(t) || type_size_of(t) == 0) {
@@ -1287,7 +1287,7 @@ void lb_emit_store_union_variant_tag(lbProcedure *p, lbValue parent, Type *varia
} }
} }
void lb_emit_store_union_variant(lbProcedure *p, lbValue parent, lbValue variant, Type *variant_type) { gb_internal void lb_emit_store_union_variant(lbProcedure *p, lbValue parent, lbValue variant, Type *variant_type) {
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) {
@@ -1320,14 +1320,14 @@ void lb_emit_store_union_variant(lbProcedure *p, lbValue parent, lbValue variant
} }
void lb_clone_struct_type(LLVMTypeRef dst, LLVMTypeRef src) { gb_internal void lb_clone_struct_type(LLVMTypeRef dst, LLVMTypeRef src) {
unsigned field_count = LLVMCountStructElementTypes(src); unsigned field_count = LLVMCountStructElementTypes(src);
LLVMTypeRef *fields = gb_alloc_array(temporary_allocator(), LLVMTypeRef, field_count); LLVMTypeRef *fields = gb_alloc_array(temporary_allocator(), LLVMTypeRef, field_count);
LLVMGetStructElementTypes(src, fields); LLVMGetStructElementTypes(src, fields);
LLVMStructSetBody(dst, fields, field_count, LLVMIsPackedStruct(src)); LLVMStructSetBody(dst, fields, field_count, LLVMIsPackedStruct(src));
} }
LLVMTypeRef lb_alignment_prefix_type_hack(lbModule *m, i64 alignment) { gb_internal LLVMTypeRef lb_alignment_prefix_type_hack(lbModule *m, i64 alignment) {
switch (alignment) { switch (alignment) {
case 1: case 1:
return LLVMArrayType(lb_type(m, t_u8), 0); return LLVMArrayType(lb_type(m, t_u8), 0);
@@ -1342,7 +1342,7 @@ LLVMTypeRef lb_alignment_prefix_type_hack(lbModule *m, i64 alignment) {
} }
} }
String lb_mangle_name(lbModule *m, Entity *e) { gb_internal String lb_mangle_name(lbModule *m, Entity *e) {
String name = e->token.string; String name = e->token.string;
AstPackage *pkg = e->pkg; AstPackage *pkg = e->pkg;
@@ -1384,7 +1384,7 @@ String lb_mangle_name(lbModule *m, Entity *e) {
return mangled_name; return mangled_name;
} }
String lb_set_nested_type_name_ir_mangled_name(Entity *e, lbProcedure *p) { gb_internal String lb_set_nested_type_name_ir_mangled_name(Entity *e, lbProcedure *p) {
// NOTE(bill, 2020-03-08): A polymorphic procedure may take a nested type declaration // NOTE(bill, 2020-03-08): A polymorphic procedure may take a nested type declaration
// and as a result, the declaration does not have time to determine what it should be // and as a result, the declaration does not have time to determine what it should be
@@ -1440,7 +1440,7 @@ String lb_set_nested_type_name_ir_mangled_name(Entity *e, lbProcedure *p) {
} }
} }
String lb_get_entity_name(lbModule *m, Entity *e, String default_name) { gb_internal String lb_get_entity_name(lbModule *m, Entity *e, String default_name) {
if (e != nullptr && e->kind == Entity_TypeName && e->TypeName.ir_mangled_name.len != 0) { if (e != nullptr && e->kind == Entity_TypeName && e->TypeName.ir_mangled_name.len != 0) {
return e->TypeName.ir_mangled_name; return e->TypeName.ir_mangled_name;
} }
@@ -1488,7 +1488,7 @@ String lb_get_entity_name(lbModule *m, Entity *e, String default_name) {
} }
LLVMTypeRef lb_type_internal_for_procedures_raw(lbModule *m, Type *type) { gb_internal LLVMTypeRef lb_type_internal_for_procedures_raw(lbModule *m, Type *type) {
Type *original_type = type; Type *original_type = type;
type = base_type(original_type); type = base_type(original_type);
GB_ASSERT(type->kind == Type_Proc); GB_ASSERT(type->kind == Type_Proc);
@@ -1607,7 +1607,7 @@ LLVMTypeRef lb_type_internal_for_procedures_raw(lbModule *m, Type *type) {
return new_abi_fn_type; return new_abi_fn_type;
} }
LLVMTypeRef lb_type_internal(lbModule *m, Type *type) { gb_internal LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
LLVMContextRef ctx = m->ctx; LLVMContextRef ctx = m->ctx;
i64 size = type_size_of(type); // Check size i64 size = type_size_of(type); // Check size
gb_unused(size); gb_unused(size);
@@ -2145,7 +2145,7 @@ LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
return LLVMInt32TypeInContext(ctx); return LLVMInt32TypeInContext(ctx);
} }
LLVMTypeRef lb_type(lbModule *m, Type *type) { gb_internal LLVMTypeRef lb_type(lbModule *m, Type *type) {
type = default_type(type); type = default_type(type);
LLVMTypeRef *found = map_get(&m->types, type); LLVMTypeRef *found = map_get(&m->types, type);
@@ -2164,7 +2164,7 @@ LLVMTypeRef lb_type(lbModule *m, Type *type) {
return llvm_type; return llvm_type;
} }
lbFunctionType *lb_get_function_type(lbModule *m, Type *pt) { gb_internal lbFunctionType *lb_get_function_type(lbModule *m, Type *pt) {
lbFunctionType **ft_found = nullptr; lbFunctionType **ft_found = nullptr;
ft_found = map_get(&m->function_type_map, pt); ft_found = map_get(&m->function_type_map, pt);
if (!ft_found) { if (!ft_found) {
@@ -2177,7 +2177,7 @@ lbFunctionType *lb_get_function_type(lbModule *m, Type *pt) {
return *ft_found; return *ft_found;
} }
void lb_ensure_abi_function_type(lbModule *m, lbProcedure *p) { gb_internal void lb_ensure_abi_function_type(lbModule *m, lbProcedure *p) {
if (p->abi_function_type != nullptr) { if (p->abi_function_type != nullptr) {
return; return;
} }
@@ -2192,20 +2192,20 @@ void lb_ensure_abi_function_type(lbModule *m, lbProcedure *p) {
GB_ASSERT(p->abi_function_type != nullptr); GB_ASSERT(p->abi_function_type != nullptr);
} }
void lb_add_entity(lbModule *m, Entity *e, lbValue val) { gb_internal void lb_add_entity(lbModule *m, Entity *e, lbValue val) {
if (e != nullptr) { if (e != nullptr) {
map_set(&m->values, e, val); map_set(&m->values, e, val);
} }
} }
void lb_add_member(lbModule *m, String const &name, lbValue val) { gb_internal void lb_add_member(lbModule *m, String const &name, lbValue val) {
if (name.len > 0) { if (name.len > 0) {
string_map_set(&m->members, name, val); string_map_set(&m->members, name, val);
} }
} }
void lb_add_member(lbModule *m, StringHashKey const &key, lbValue val) { gb_internal void lb_add_member(lbModule *m, StringHashKey const &key, lbValue val) {
string_map_set(&m->members, key, val); string_map_set(&m->members, key, val);
} }
void lb_add_procedure_value(lbModule *m, lbProcedure *p) { gb_internal void lb_add_procedure_value(lbModule *m, lbProcedure *p) {
if (p->entity != nullptr) { if (p->entity != nullptr) {
map_set(&m->procedure_values, p->value, p->entity); map_set(&m->procedure_values, p->value, p->entity);
} }
@@ -2214,7 +2214,7 @@ void lb_add_procedure_value(lbModule *m, lbProcedure *p) {
LLVMAttributeRef lb_create_enum_attribute_with_type(LLVMContextRef ctx, char const *name, LLVMTypeRef type) { gb_internal LLVMAttributeRef lb_create_enum_attribute_with_type(LLVMContextRef ctx, char const *name, LLVMTypeRef type) {
unsigned kind = 0; unsigned kind = 0;
String s = make_string_c(name); String s = make_string_c(name);
@@ -2243,7 +2243,7 @@ LLVMAttributeRef lb_create_enum_attribute_with_type(LLVMContextRef ctx, char con
#endif #endif
} }
LLVMAttributeRef lb_create_enum_attribute(LLVMContextRef ctx, char const *name, u64 value) { gb_internal LLVMAttributeRef lb_create_enum_attribute(LLVMContextRef ctx, char const *name, u64 value) {
String s = make_string_c(name); String s = make_string_c(name);
// NOTE(2021-02-25, bill); All this attributes require a type associated with them // NOTE(2021-02-25, bill); All this attributes require a type associated with them
@@ -2264,23 +2264,23 @@ LLVMAttributeRef lb_create_enum_attribute(LLVMContextRef ctx, char const *name,
return LLVMCreateEnumAttribute(ctx, kind, value); return LLVMCreateEnumAttribute(ctx, kind, value);
} }
void lb_add_proc_attribute_at_index(lbProcedure *p, isize index, char const *name, u64 value) { gb_internal void lb_add_proc_attribute_at_index(lbProcedure *p, isize index, char const *name, u64 value) {
LLVMAttributeRef attr = lb_create_enum_attribute(p->module->ctx, name, value); LLVMAttributeRef attr = lb_create_enum_attribute(p->module->ctx, name, value);
GB_ASSERT(attr != nullptr); GB_ASSERT(attr != nullptr);
LLVMAddAttributeAtIndex(p->value, cast(unsigned)index, attr); LLVMAddAttributeAtIndex(p->value, cast(unsigned)index, attr);
} }
void lb_add_proc_attribute_at_index(lbProcedure *p, isize index, char const *name) { gb_internal void lb_add_proc_attribute_at_index(lbProcedure *p, isize index, char const *name) {
lb_add_proc_attribute_at_index(p, index, name, 0); lb_add_proc_attribute_at_index(p, index, name, 0);
} }
void lb_add_attribute_to_proc(lbModule *m, LLVMValueRef proc_value, char const *name, u64 value=0) { gb_internal void lb_add_attribute_to_proc(lbModule *m, LLVMValueRef proc_value, char const *name, u64 value=0) {
LLVMAddAttributeAtIndex(proc_value, LLVMAttributeIndex_FunctionIndex, lb_create_enum_attribute(m->ctx, name, value)); LLVMAddAttributeAtIndex(proc_value, LLVMAttributeIndex_FunctionIndex, lb_create_enum_attribute(m->ctx, name, value));
} }
void lb_add_edge(lbBlock *from, lbBlock *to) { gb_internal void lb_add_edge(lbBlock *from, lbBlock *to) {
LLVMValueRef instr = LLVMGetLastInstruction(from->block); LLVMValueRef instr = LLVMGetLastInstruction(from->block);
if (instr == nullptr || !LLVMIsATerminatorInst(instr)) { if (instr == nullptr || !LLVMIsATerminatorInst(instr)) {
array_add(&from->succs, to); array_add(&from->succs, to);
@@ -2289,7 +2289,7 @@ void lb_add_edge(lbBlock *from, lbBlock *to) {
} }
lbBlock *lb_create_block(lbProcedure *p, char const *name, bool append) { gb_internal lbBlock *lb_create_block(lbProcedure *p, char const *name, bool append) {
lbBlock *b = gb_alloc_item(permanent_allocator(), lbBlock); lbBlock *b = gb_alloc_item(permanent_allocator(), lbBlock);
b->block = LLVMCreateBasicBlockInContext(p->module->ctx, name); b->block = LLVMCreateBasicBlockInContext(p->module->ctx, name);
b->appended = false; b->appended = false;
@@ -2309,7 +2309,7 @@ lbBlock *lb_create_block(lbProcedure *p, char const *name, bool append) {
return b; return b;
} }
void lb_emit_jump(lbProcedure *p, lbBlock *target_block) { gb_internal void lb_emit_jump(lbProcedure *p, lbBlock *target_block) {
if (p->curr_block == nullptr) { if (p->curr_block == nullptr) {
return; return;
} }
@@ -2323,7 +2323,7 @@ void lb_emit_jump(lbProcedure *p, lbBlock *target_block) {
p->curr_block = nullptr; p->curr_block = nullptr;
} }
void lb_emit_if(lbProcedure *p, lbValue cond, lbBlock *true_block, lbBlock *false_block) { gb_internal void lb_emit_if(lbProcedure *p, lbValue cond, lbBlock *true_block, lbBlock *false_block) {
lbBlock *b = p->curr_block; lbBlock *b = p->curr_block;
if (b == nullptr) { if (b == nullptr) {
return; return;
@@ -2342,20 +2342,20 @@ void lb_emit_if(lbProcedure *p, lbValue cond, lbBlock *true_block, lbBlock *fals
} }
gb_inline LLVMTypeRef OdinLLVMGetInternalElementType(LLVMTypeRef type) { gb_internal gb_inline LLVMTypeRef OdinLLVMGetInternalElementType(LLVMTypeRef type) {
return LLVMGetElementType(type); return LLVMGetElementType(type);
} }
LLVMTypeRef OdinLLVMGetArrayElementType(LLVMTypeRef type) { gb_internal LLVMTypeRef OdinLLVMGetArrayElementType(LLVMTypeRef type) {
GB_ASSERT(lb_is_type_kind(type, LLVMArrayTypeKind)); GB_ASSERT(lb_is_type_kind(type, LLVMArrayTypeKind));
return OdinLLVMGetInternalElementType(type); return OdinLLVMGetInternalElementType(type);
} }
LLVMTypeRef OdinLLVMGetVectorElementType(LLVMTypeRef type) { gb_internal LLVMTypeRef OdinLLVMGetVectorElementType(LLVMTypeRef type) {
GB_ASSERT(lb_is_type_kind(type, LLVMVectorTypeKind)); GB_ASSERT(lb_is_type_kind(type, LLVMVectorTypeKind));
return OdinLLVMGetInternalElementType(type); return OdinLLVMGetInternalElementType(type);
} }
LLVMValueRef OdinLLVMBuildTransmute(lbProcedure *p, LLVMValueRef val, LLVMTypeRef dst_type) { gb_internal LLVMValueRef OdinLLVMBuildTransmute(lbProcedure *p, LLVMValueRef val, LLVMTypeRef dst_type) {
LLVMContextRef ctx = p->module->ctx; LLVMContextRef ctx = p->module->ctx;
LLVMTypeRef src_type = LLVMTypeOf(val); LLVMTypeRef src_type = LLVMTypeOf(val);
@@ -2445,7 +2445,7 @@ general_end:;
LLVMValueRef lb_find_or_add_entity_string_ptr(lbModule *m, String const &str) { gb_internal LLVMValueRef lb_find_or_add_entity_string_ptr(lbModule *m, String const &str) {
StringHashKey key = string_hash_string(str); StringHashKey key = string_hash_string(str);
LLVMValueRef *found = string_map_get(&m->const_strings, key); LLVMValueRef *found = string_map_get(&m->const_strings, key);
if (found != nullptr) { if (found != nullptr) {
@@ -2477,7 +2477,7 @@ LLVMValueRef lb_find_or_add_entity_string_ptr(lbModule *m, String const &str) {
} }
} }
lbValue lb_find_or_add_entity_string(lbModule *m, String const &str) { gb_internal lbValue lb_find_or_add_entity_string(lbModule *m, String const &str) {
LLVMValueRef ptr = nullptr; LLVMValueRef ptr = nullptr;
if (str.len != 0) { if (str.len != 0) {
ptr = lb_find_or_add_entity_string_ptr(m, str); ptr = lb_find_or_add_entity_string_ptr(m, str);
@@ -2493,7 +2493,7 @@ lbValue lb_find_or_add_entity_string(lbModule *m, String const &str) {
return res; return res;
} }
lbValue lb_find_or_add_entity_string_byte_slice(lbModule *m, String const &str) { gb_internal lbValue lb_find_or_add_entity_string_byte_slice(lbModule *m, String const &str) {
LLVMValueRef indices[2] = {llvm_zero(m), llvm_zero(m)}; LLVMValueRef indices[2] = {llvm_zero(m), llvm_zero(m)};
LLVMValueRef data = LLVMConstStringInContext(m->ctx, LLVMValueRef data = LLVMConstStringInContext(m->ctx,
cast(char const *)str.text, cast(char const *)str.text,
@@ -2529,7 +2529,7 @@ lbValue lb_find_or_add_entity_string_byte_slice(lbModule *m, String const &str)
res.type = t_u8_slice; res.type = t_u8_slice;
return res; return res;
} }
lbValue lb_find_or_add_entity_string_byte_slice_with_type(lbModule *m, String const &str, Type *slice_type) { gb_internal lbValue lb_find_or_add_entity_string_byte_slice_with_type(lbModule *m, String const &str, Type *slice_type) {
GB_ASSERT(is_type_slice(slice_type)); GB_ASSERT(is_type_slice(slice_type));
LLVMValueRef indices[2] = {llvm_zero(m), llvm_zero(m)}; LLVMValueRef indices[2] = {llvm_zero(m), llvm_zero(m)};
LLVMValueRef data = LLVMConstStringInContext(m->ctx, LLVMValueRef data = LLVMConstStringInContext(m->ctx,
@@ -2579,7 +2579,7 @@ lbValue lb_find_or_add_entity_string_byte_slice_with_type(lbModule *m, String co
lbValue lb_find_ident(lbProcedure *p, lbModule *m, Entity *e, Ast *expr) { gb_internal lbValue lb_find_ident(lbProcedure *p, lbModule *m, Entity *e, Ast *expr) {
if (e->flags & EntityFlag_Param) { if (e->flags & EntityFlag_Param) {
// NOTE(bill): Bypass the stack copied variable for // NOTE(bill): Bypass the stack copied variable for
// direct parameters as there is no need for the direct load // direct parameters as there is no need for the direct load
@@ -2633,7 +2633,7 @@ lbValue lb_find_ident(lbProcedure *p, lbModule *m, Entity *e, Ast *expr) {
} }
lbValue lb_find_procedure_value_from_entity(lbModule *m, Entity *e) { gb_internal lbValue lb_find_procedure_value_from_entity(lbModule *m, Entity *e) {
GB_ASSERT(is_type_proc(e->type)); GB_ASSERT(is_type_proc(e->type));
e = strip_entity_wrapping(e); e = strip_entity_wrapping(e);
GB_ASSERT(e != nullptr); GB_ASSERT(e != nullptr);
@@ -2668,7 +2668,7 @@ lbValue lb_find_procedure_value_from_entity(lbModule *m, Entity *e) {
} }
lbAddr lb_add_global_generated(lbModule *m, Type *type, lbValue value, Entity **entity_) { gb_internal lbAddr lb_add_global_generated(lbModule *m, Type *type, lbValue value, Entity **entity_) {
GB_ASSERT(type != nullptr); GB_ASSERT(type != nullptr);
type = default_type(type); type = default_type(type);
@@ -2700,23 +2700,23 @@ lbAddr lb_add_global_generated(lbModule *m, Type *type, lbValue value, Entity **
return lb_addr(g); return lb_addr(g);
} }
lbValue lb_find_runtime_value(lbModule *m, String const &name) { gb_internal lbValue lb_find_runtime_value(lbModule *m, String const &name) {
AstPackage *p = m->info->runtime_package; AstPackage *p = m->info->runtime_package;
Entity *e = scope_lookup_current(p->scope, name); Entity *e = scope_lookup_current(p->scope, name);
return lb_find_value_from_entity(m, e); return lb_find_value_from_entity(m, e);
} }
lbValue lb_find_package_value(lbModule *m, String const &pkg, String const &name) { gb_internal lbValue lb_find_package_value(lbModule *m, String const &pkg, String const &name) {
Entity *e = find_entity_in_pkg(m->info, pkg, name); Entity *e = find_entity_in_pkg(m->info, pkg, name);
return lb_find_value_from_entity(m, e); return lb_find_value_from_entity(m, e);
} }
lbValue lb_generate_local_array(lbProcedure *p, Type *elem_type, i64 count, bool zero_init) { gb_internal lbValue lb_generate_local_array(lbProcedure *p, Type *elem_type, i64 count, bool zero_init) {
lbAddr addr = lb_add_local_generated(p, alloc_type_array(elem_type, count), zero_init); lbAddr addr = lb_add_local_generated(p, alloc_type_array(elem_type, count), zero_init);
return lb_addr_get_ptr(p, addr); return lb_addr_get_ptr(p, addr);
} }
lbValue lb_find_value_from_entity(lbModule *m, Entity *e) { gb_internal lbValue lb_find_value_from_entity(lbModule *m, Entity *e) {
e = strip_entity_wrapping(e); e = strip_entity_wrapping(e);
GB_ASSERT(e != nullptr); GB_ASSERT(e != nullptr);
@@ -2788,7 +2788,7 @@ lbValue lb_find_value_from_entity(lbModule *m, Entity *e) {
return {}; return {};
} }
lbValue lb_generate_global_array(lbModule *m, Type *elem_type, i64 count, String prefix, i64 id) { gb_internal lbValue lb_generate_global_array(lbModule *m, Type *elem_type, i64 count, String prefix, i64 id) {
Token token = {Token_Ident}; Token token = {Token_Ident};
isize name_len = prefix.len + 1 + 20; isize name_len = prefix.len + 1 + 20;
@@ -2813,7 +2813,7 @@ lbValue lb_generate_global_array(lbModule *m, Type *elem_type, i64 count, String
lbValue lb_build_cond(lbProcedure *p, Ast *cond, lbBlock *true_block, lbBlock *false_block) { gb_internal lbValue lb_build_cond(lbProcedure *p, Ast *cond, lbBlock *true_block, lbBlock *false_block) {
GB_ASSERT(cond != nullptr); GB_ASSERT(cond != nullptr);
GB_ASSERT(true_block != nullptr); GB_ASSERT(true_block != nullptr);
GB_ASSERT(false_block != nullptr); GB_ASSERT(false_block != nullptr);
@@ -2868,7 +2868,7 @@ lbValue lb_build_cond(lbProcedure *p, Ast *cond, lbBlock *true_block, lbBlock *f
} }
lbAddr lb_add_local(lbProcedure *p, Type *type, Entity *e, bool zero_init, bool force_no_init) { gb_internal lbAddr lb_add_local(lbProcedure *p, Type *type, Entity *e, bool zero_init, bool force_no_init) {
GB_ASSERT(p->decl_block != p->curr_block); GB_ASSERT(p->decl_block != p->curr_block);
LLVMPositionBuilderAtEnd(p->builder, p->decl_block->block); LLVMPositionBuilderAtEnd(p->builder, p->decl_block->block);
@@ -2917,18 +2917,18 @@ lbAddr lb_add_local(lbProcedure *p, Type *type, Entity *e, bool zero_init, bool
return lb_addr(val); return lb_addr(val);
} }
lbAddr lb_add_local_generated(lbProcedure *p, Type *type, bool zero_init) { gb_internal lbAddr lb_add_local_generated(lbProcedure *p, Type *type, bool zero_init) {
return lb_add_local(p, type, nullptr, zero_init); return lb_add_local(p, type, nullptr, zero_init);
} }
lbAddr lb_add_local_generated_temp(lbProcedure *p, Type *type, i64 min_alignment) { gb_internal lbAddr lb_add_local_generated_temp(lbProcedure *p, Type *type, i64 min_alignment) {
lbAddr res = lb_add_local(p, type, nullptr, false, true); lbAddr res = lb_add_local(p, type, nullptr, false, true);
lb_try_update_alignment(res.addr, cast(unsigned)min_alignment); lb_try_update_alignment(res.addr, cast(unsigned)min_alignment);
return res; return res;
} }
void lb_set_linkage_from_entity_flags(lbModule *m, LLVMValueRef value, u64 flags) { gb_internal void lb_set_linkage_from_entity_flags(lbModule *m, LLVMValueRef value, u64 flags) {
if (flags & EntityFlag_CustomLinkage_Internal) { if (flags & EntityFlag_CustomLinkage_Internal) {
LLVMSetLinkage(value, LLVMInternalLinkage); LLVMSetLinkage(value, LLVMInternalLinkage);
} else if (flags & EntityFlag_CustomLinkage_Strong) { } else if (flags & EntityFlag_CustomLinkage_Strong) {
+16 -16
View File
@@ -32,12 +32,12 @@
**************************************************************************/ **************************************************************************/
void lb_populate_function_pass_manager(lbModule *m, LLVMPassManagerRef fpm, bool ignore_memcpy_pass, i32 optimization_level); gb_internal void lb_populate_function_pass_manager(lbModule *m, LLVMPassManagerRef fpm, bool ignore_memcpy_pass, i32 optimization_level);
void lb_add_function_simplifcation_passes(LLVMPassManagerRef mpm, i32 optimization_level); gb_internal void lb_add_function_simplifcation_passes(LLVMPassManagerRef mpm, i32 optimization_level);
void lb_populate_module_pass_manager(LLVMTargetMachineRef target_machine, LLVMPassManagerRef mpm, i32 optimization_level); gb_internal void lb_populate_module_pass_manager(LLVMTargetMachineRef target_machine, LLVMPassManagerRef mpm, i32 optimization_level);
void lb_populate_function_pass_manager_specific(lbModule *m, LLVMPassManagerRef fpm, i32 optimization_level); gb_internal void lb_populate_function_pass_manager_specific(lbModule *m, LLVMPassManagerRef fpm, i32 optimization_level);
LLVMBool lb_must_preserve_predicate_callback(LLVMValueRef value, void *user_data) { gb_internal LLVMBool lb_must_preserve_predicate_callback(LLVMValueRef value, void *user_data) {
lbModule *m = cast(lbModule *)user_data; lbModule *m = cast(lbModule *)user_data;
if (m == nullptr) { if (m == nullptr) {
return false; return false;
@@ -55,7 +55,7 @@ LLVMBool lb_must_preserve_predicate_callback(LLVMValueRef value, void *user_data
#define LLVM_ADD_CONSTANT_VALUE_PASS(fpm) #define LLVM_ADD_CONSTANT_VALUE_PASS(fpm)
#endif #endif
void lb_basic_populate_function_pass_manager(LLVMPassManagerRef fpm, i32 optimization_level) { gb_internal void lb_basic_populate_function_pass_manager(LLVMPassManagerRef fpm, i32 optimization_level) {
if (false && optimization_level == 0 && build_context.ODIN_DEBUG) { if (false && optimization_level == 0 && build_context.ODIN_DEBUG) {
LLVMAddMergedLoadStoreMotionPass(fpm); LLVMAddMergedLoadStoreMotionPass(fpm);
} else { } else {
@@ -68,7 +68,7 @@ void lb_basic_populate_function_pass_manager(LLVMPassManagerRef fpm, i32 optimiz
} }
} }
void lb_populate_function_pass_manager(lbModule *m, LLVMPassManagerRef fpm, bool ignore_memcpy_pass, i32 optimization_level) { gb_internal void lb_populate_function_pass_manager(lbModule *m, LLVMPassManagerRef fpm, bool ignore_memcpy_pass, i32 optimization_level) {
// NOTE(bill): Treat -opt:3 as if it was -opt:2 // NOTE(bill): Treat -opt:3 as if it was -opt:2
// TODO(bill): Determine which opt definitions should exist in the first place // TODO(bill): Determine which opt definitions should exist in the first place
optimization_level = gb_clamp(optimization_level, 0, 2); optimization_level = gb_clamp(optimization_level, 0, 2);
@@ -102,7 +102,7 @@ void lb_populate_function_pass_manager(lbModule *m, LLVMPassManagerRef fpm, bool
#endif #endif
} }
void lb_populate_function_pass_manager_specific(lbModule *m, LLVMPassManagerRef fpm, i32 optimization_level) { gb_internal void lb_populate_function_pass_manager_specific(lbModule *m, LLVMPassManagerRef fpm, i32 optimization_level) {
// NOTE(bill): Treat -opt:3 as if it was -opt:2 // NOTE(bill): Treat -opt:3 as if it was -opt:2
// TODO(bill): Determine which opt definitions should exist in the first place // TODO(bill): Determine which opt definitions should exist in the first place
optimization_level = gb_clamp(optimization_level, 0, 2); optimization_level = gb_clamp(optimization_level, 0, 2);
@@ -141,7 +141,7 @@ void lb_populate_function_pass_manager_specific(lbModule *m, LLVMPassManagerRef
#endif #endif
} }
void lb_add_function_simplifcation_passes(LLVMPassManagerRef mpm, i32 optimization_level) { gb_internal void lb_add_function_simplifcation_passes(LLVMPassManagerRef mpm, i32 optimization_level) {
LLVMAddCFGSimplificationPass(mpm); LLVMAddCFGSimplificationPass(mpm);
LLVMAddJumpThreadingPass(mpm); LLVMAddJumpThreadingPass(mpm);
@@ -177,7 +177,7 @@ void lb_add_function_simplifcation_passes(LLVMPassManagerRef mpm, i32 optimizati
} }
void lb_populate_module_pass_manager(LLVMTargetMachineRef target_machine, LLVMPassManagerRef mpm, i32 optimization_level) { gb_internal void lb_populate_module_pass_manager(LLVMTargetMachineRef target_machine, LLVMPassManagerRef mpm, i32 optimization_level) {
// NOTE(bill): Treat -opt:3 as if it was -opt:2 // NOTE(bill): Treat -opt:3 as if it was -opt:2
// TODO(bill): Determine which opt definitions should exist in the first place // TODO(bill): Determine which opt definitions should exist in the first place
@@ -266,7 +266,7 @@ void lb_populate_module_pass_manager(LLVMTargetMachineRef target_machine, LLVMPa
optimization of Odin programs optimization of Odin programs
**************************************************************************/ **************************************************************************/
void lb_run_remove_dead_instruction_pass(lbProcedure *p) { gb_internal void lb_run_remove_dead_instruction_pass(lbProcedure *p) {
isize removal_count = 0; isize removal_count = 0;
isize pass_count = 0; isize pass_count = 0;
isize const max_pass_count = 10; isize const max_pass_count = 10;
@@ -358,7 +358,7 @@ void lb_run_remove_dead_instruction_pass(lbProcedure *p) {
} }
void lb_run_function_pass_manager(LLVMPassManagerRef fpm, lbProcedure *p) { gb_internal void lb_run_function_pass_manager(LLVMPassManagerRef fpm, lbProcedure *p) {
LLVMRunFunctionPassManager(fpm, p->value); LLVMRunFunctionPassManager(fpm, p->value);
// NOTE(bill): LLVMAddDCEPass doesn't seem to be exported in the official DLL's for LLVM // NOTE(bill): LLVMAddDCEPass doesn't seem to be exported in the official DLL's for LLVM
// which means we cannot rely upon it // which means we cannot rely upon it
@@ -367,7 +367,7 @@ void lb_run_function_pass_manager(LLVMPassManagerRef fpm, lbProcedure *p) {
lb_run_remove_dead_instruction_pass(p); lb_run_remove_dead_instruction_pass(p);
} }
void llvm_delete_function(LLVMValueRef func) { gb_internal void llvm_delete_function(LLVMValueRef func) {
// for (LLVMBasicBlockRef block = LLVMGetFirstBasicBlock(func); block != nullptr; /**/) { // for (LLVMBasicBlockRef block = LLVMGetFirstBasicBlock(func); block != nullptr; /**/) {
// LLVMBasicBlockRef curr_block = block; // LLVMBasicBlockRef curr_block = block;
// block = LLVMGetNextBasicBlock(block); // block = LLVMGetNextBasicBlock(block);
@@ -382,7 +382,7 @@ void llvm_delete_function(LLVMValueRef func) {
LLVMDeleteFunction(func); LLVMDeleteFunction(func);
} }
void lb_append_to_compiler_used(lbModule *m, LLVMValueRef func) { gb_internal void lb_append_to_compiler_used(lbModule *m, LLVMValueRef func) {
LLVMValueRef global = LLVMGetNamedGlobal(m->mod, "llvm.compiler.used"); LLVMValueRef global = LLVMGetNamedGlobal(m->mod, "llvm.compiler.used");
LLVMValueRef *constants; LLVMValueRef *constants;
@@ -419,7 +419,7 @@ void lb_append_to_compiler_used(lbModule *m, LLVMValueRef func) {
LLVMSetInitializer(global, initializer); LLVMSetInitializer(global, initializer);
} }
void lb_run_remove_unused_function_pass(lbModule *m) { gb_internal void lb_run_remove_unused_function_pass(lbModule *m) {
isize removal_count = 0; isize removal_count = 0;
isize pass_count = 0; isize pass_count = 0;
isize const max_pass_count = 10; isize const max_pass_count = 10;
@@ -470,7 +470,7 @@ void lb_run_remove_unused_function_pass(lbModule *m) {
} }
void lb_run_remove_unused_globals_pass(lbModule *m) { gb_internal void lb_run_remove_unused_globals_pass(lbModule *m) {
isize removal_count = 0; isize removal_count = 0;
isize pass_count = 0; isize pass_count = 0;
isize const max_pass_count = 10; isize const max_pass_count = 10;
+27 -28
View File
@@ -1,5 +1,4 @@
LLVMValueRef lb_call_intrinsic(lbProcedure *p, const char *name, LLVMValueRef* args, unsigned arg_count, LLVMTypeRef* types, unsigned type_count) gb_internal LLVMValueRef lb_call_intrinsic(lbProcedure *p, const char *name, LLVMValueRef* args, unsigned arg_count, LLVMTypeRef* types, unsigned type_count) {
{
unsigned id = LLVMLookupIntrinsicID(name, gb_strlen(name)); unsigned id = LLVMLookupIntrinsicID(name, gb_strlen(name));
GB_ASSERT_MSG(id != 0, "Unable to find %s", name); GB_ASSERT_MSG(id != 0, "Unable to find %s", name);
LLVMValueRef ip = LLVMGetIntrinsicDeclaration(p->module->mod, id, types, type_count); LLVMValueRef ip = LLVMGetIntrinsicDeclaration(p->module->mod, id, types, type_count);
@@ -7,7 +6,7 @@ LLVMValueRef lb_call_intrinsic(lbProcedure *p, const char *name, LLVMValueRef* a
return LLVMBuildCall2(p->builder, call_type, ip, args, arg_count, ""); return LLVMBuildCall2(p->builder, call_type, ip, args, arg_count, "");
} }
void lb_mem_copy_overlapping(lbProcedure *p, lbValue dst, lbValue src, lbValue len, bool is_volatile) { gb_internal void lb_mem_copy_overlapping(lbProcedure *p, lbValue dst, lbValue src, lbValue len, bool is_volatile) {
dst = lb_emit_conv(p, dst, t_rawptr); dst = lb_emit_conv(p, dst, t_rawptr);
src = lb_emit_conv(p, src, t_rawptr); src = lb_emit_conv(p, src, t_rawptr);
len = lb_emit_conv(p, len, t_int); len = lb_emit_conv(p, len, t_int);
@@ -36,7 +35,7 @@ void lb_mem_copy_overlapping(lbProcedure *p, lbValue dst, lbValue src, lbValue l
void lb_mem_copy_non_overlapping(lbProcedure *p, lbValue dst, lbValue src, lbValue len, bool is_volatile) { gb_internal void lb_mem_copy_non_overlapping(lbProcedure *p, lbValue dst, lbValue src, lbValue len, bool is_volatile) {
dst = lb_emit_conv(p, dst, t_rawptr); dst = lb_emit_conv(p, dst, t_rawptr);
src = lb_emit_conv(p, src, t_rawptr); src = lb_emit_conv(p, src, t_rawptr);
len = lb_emit_conv(p, len, t_int); len = lb_emit_conv(p, len, t_int);
@@ -65,7 +64,7 @@ void lb_mem_copy_non_overlapping(lbProcedure *p, lbValue dst, lbValue src, lbVal
} }
lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool ignore_body) { gb_internal lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool ignore_body) {
GB_ASSERT(entity != nullptr); GB_ASSERT(entity != nullptr);
GB_ASSERT(entity->kind == Entity_Procedure); GB_ASSERT(entity->kind == Entity_Procedure);
if (!entity->Procedure.is_foreign) { if (!entity->Procedure.is_foreign) {
@@ -320,7 +319,7 @@ lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool ignore_body)
return p; return p;
} }
lbProcedure *lb_create_dummy_procedure(lbModule *m, String link_name, Type *type) { gb_internal lbProcedure *lb_create_dummy_procedure(lbModule *m, String link_name, Type *type) {
{ {
lbValue *found = string_map_get(&m->members, link_name); lbValue *found = string_map_get(&m->members, link_name);
GB_ASSERT_MSG(found == nullptr, "failed to create dummy procedure for: %.*s", LIT(link_name)); GB_ASSERT_MSG(found == nullptr, "failed to create dummy procedure for: %.*s", LIT(link_name));
@@ -384,7 +383,7 @@ lbProcedure *lb_create_dummy_procedure(lbModule *m, String link_name, Type *type
} }
lbValue lb_value_param(lbProcedure *p, Entity *e, Type *abi_type, i32 index, lbParamPasskind *kind_) { gb_internal lbValue lb_value_param(lbProcedure *p, Entity *e, Type *abi_type, i32 index, lbParamPasskind *kind_) {
lbParamPasskind kind = lbParamPass_Value; lbParamPasskind kind = lbParamPass_Value;
if (e != nullptr && !are_types_identical(abi_type, e->type)) { if (e != nullptr && !are_types_identical(abi_type, e->type)) {
@@ -427,7 +426,7 @@ lbValue lb_value_param(lbProcedure *p, Entity *e, Type *abi_type, i32 index, lbP
void lb_start_block(lbProcedure *p, lbBlock *b) { gb_internal void lb_start_block(lbProcedure *p, lbBlock *b) {
GB_ASSERT(b != nullptr); GB_ASSERT(b != nullptr);
if (!b->appended) { if (!b->appended) {
b->appended = true; b->appended = true;
@@ -437,7 +436,7 @@ void lb_start_block(lbProcedure *p, lbBlock *b) {
p->curr_block = b; p->curr_block = b;
} }
void lb_set_debug_position_to_procedure_begin(lbProcedure *p) { gb_internal void lb_set_debug_position_to_procedure_begin(lbProcedure *p) {
if (p->debug_info == nullptr) { if (p->debug_info == nullptr) {
return; return;
} }
@@ -454,7 +453,7 @@ void lb_set_debug_position_to_procedure_begin(lbProcedure *p) {
} }
} }
void lb_set_debug_position_to_procedure_end(lbProcedure *p) { gb_internal void lb_set_debug_position_to_procedure_end(lbProcedure *p) {
if (p->debug_info == nullptr) { if (p->debug_info == nullptr) {
return; return;
} }
@@ -471,7 +470,7 @@ void lb_set_debug_position_to_procedure_end(lbProcedure *p) {
} }
} }
void lb_begin_procedure_body(lbProcedure *p) { gb_internal void lb_begin_procedure_body(lbProcedure *p) {
DeclInfo *decl = decl_info_of_entity(p->entity); DeclInfo *decl = decl_info_of_entity(p->entity);
if (decl != nullptr) { if (decl != nullptr) {
for_array(i, decl->labels) { for_array(i, decl->labels) {
@@ -686,7 +685,7 @@ void lb_begin_procedure_body(lbProcedure *p) {
lb_start_block(p, p->entry_block); lb_start_block(p, p->entry_block);
} }
void lb_end_procedure_body(lbProcedure *p) { gb_internal void lb_end_procedure_body(lbProcedure *p) {
lb_set_debug_position_to_procedure_begin(p); lb_set_debug_position_to_procedure_begin(p);
LLVMPositionBuilderAtEnd(p->builder, p->decl_block->block); LLVMPositionBuilderAtEnd(p->builder, p->decl_block->block);
@@ -720,11 +719,11 @@ void lb_end_procedure_body(lbProcedure *p) {
p->curr_block = nullptr; p->curr_block = nullptr;
p->state_flags = 0; p->state_flags = 0;
} }
void lb_end_procedure(lbProcedure *p) { gb_internal void lb_end_procedure(lbProcedure *p) {
LLVMDisposeBuilder(p->builder); LLVMDisposeBuilder(p->builder);
} }
void lb_build_nested_proc(lbProcedure *p, AstProcLit *pd, Entity *e) { gb_internal void lb_build_nested_proc(lbProcedure *p, AstProcLit *pd, Entity *e) {
GB_ASSERT(pd->body != nullptr); GB_ASSERT(pd->body != nullptr);
lbModule *m = p->module; lbModule *m = p->module;
auto *min_dep_set = &m->info->minimum_dependency_set; auto *min_dep_set = &m->info->minimum_dependency_set;
@@ -766,7 +765,7 @@ void lb_build_nested_proc(lbProcedure *p, AstProcLit *pd, Entity *e) {
Array<lbValue> lb_value_to_array(lbProcedure *p, lbValue value) { gb_internal Array<lbValue> lb_value_to_array(lbProcedure *p, lbValue value) {
Array<lbValue> array = {}; Array<lbValue> array = {};
Type *t = base_type(value.type); Type *t = base_type(value.type);
if (t == nullptr) { if (t == nullptr) {
@@ -783,7 +782,7 @@ Array<lbValue> lb_value_to_array(lbProcedure *p, lbValue value) {
lbValue lb_emit_call_internal(lbProcedure *p, lbValue value, lbValue return_ptr, Array<lbValue> const &processed_args, Type *abi_rt, lbAddr context_ptr, ProcInlining inlining) { gb_internal lbValue lb_emit_call_internal(lbProcedure *p, lbValue value, lbValue return_ptr, Array<lbValue> const &processed_args, Type *abi_rt, lbAddr context_ptr, ProcInlining inlining) {
GB_ASSERT(p->module->ctx == LLVMGetTypeContext(LLVMTypeOf(value.value))); GB_ASSERT(p->module->ctx == LLVMGetTypeContext(LLVMTypeOf(value.value)));
unsigned arg_count = cast(unsigned)processed_args.count; unsigned arg_count = cast(unsigned)processed_args.count;
@@ -892,20 +891,20 @@ lbValue lb_emit_call_internal(lbProcedure *p, lbValue value, lbValue return_ptr,
} }
lbValue lb_lookup_runtime_procedure(lbModule *m, String const &name) { gb_internal lbValue lb_lookup_runtime_procedure(lbModule *m, String const &name) {
AstPackage *pkg = m->info->runtime_package; AstPackage *pkg = m->info->runtime_package;
Entity *e = scope_lookup_current(pkg->scope, name); Entity *e = scope_lookup_current(pkg->scope, name);
return lb_find_procedure_value_from_entity(m, e); return lb_find_procedure_value_from_entity(m, e);
} }
lbValue lb_emit_runtime_call(lbProcedure *p, char const *c_name, Array<lbValue> const &args) { gb_internal lbValue lb_emit_runtime_call(lbProcedure *p, char const *c_name, Array<lbValue> const &args) {
String name = make_string_c(c_name); String name = make_string_c(c_name);
lbValue proc = lb_lookup_runtime_procedure(p->module, name); lbValue proc = lb_lookup_runtime_procedure(p->module, name);
return lb_emit_call(p, proc, args); return lb_emit_call(p, proc, args);
} }
lbValue lb_emit_conjugate(lbProcedure *p, lbValue val, Type *type) { gb_internal lbValue lb_emit_conjugate(lbProcedure *p, lbValue val, Type *type) {
lbValue res = {}; lbValue res = {};
Type *t = val.type; Type *t = val.type;
if (is_type_complex(t)) { if (is_type_complex(t)) {
@@ -956,7 +955,7 @@ lbValue lb_emit_conjugate(lbProcedure *p, lbValue val, Type *type) {
return lb_emit_load(p, res); return lb_emit_load(p, res);
} }
lbValue lb_emit_call(lbProcedure *p, lbValue value, Array<lbValue> const &args, ProcInlining inlining) { gb_internal lbValue lb_emit_call(lbProcedure *p, lbValue value, Array<lbValue> const &args, ProcInlining inlining) {
lbModule *m = p->module; lbModule *m = p->module;
Type *pt = base_type(value.type); Type *pt = base_type(value.type);
@@ -1166,7 +1165,7 @@ lbValue lb_emit_call(lbProcedure *p, lbValue value, Array<lbValue> const &args,
return result; return result;
} }
LLVMValueRef llvm_splat_float(i64 count, LLVMTypeRef type, f64 value) { gb_internal LLVMValueRef llvm_splat_float(i64 count, LLVMTypeRef type, f64 value) {
LLVMValueRef v = LLVMConstReal(type, value); LLVMValueRef v = LLVMConstReal(type, value);
LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, count); LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, count);
for (i64 i = 0; i < count; i++) { for (i64 i = 0; i < count; i++) {
@@ -1174,7 +1173,7 @@ LLVMValueRef llvm_splat_float(i64 count, LLVMTypeRef type, f64 value) {
} }
return LLVMConstVector(values, cast(unsigned)count); return LLVMConstVector(values, cast(unsigned)count);
} }
LLVMValueRef llvm_splat_int(i64 count, LLVMTypeRef type, i64 value, bool is_signed=false) { gb_internal LLVMValueRef llvm_splat_int(i64 count, LLVMTypeRef type, i64 value, bool is_signed=false) {
LLVMValueRef v = LLVMConstInt(type, value, is_signed); LLVMValueRef v = LLVMConstInt(type, value, is_signed);
LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, count); LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, count);
for (i64 i = 0; i < count; i++) { for (i64 i = 0; i < count; i++) {
@@ -1184,7 +1183,7 @@ LLVMValueRef llvm_splat_int(i64 count, LLVMTypeRef type, i64 value, bool is_sign
} }
lbValue lb_build_builtin_simd_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv, BuiltinProcId builtin_id) { gb_internal lbValue lb_build_builtin_simd_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv, BuiltinProcId builtin_id) {
ast_node(ce, CallExpr, expr); ast_node(ce, CallExpr, expr);
lbModule *m = p->module; lbModule *m = p->module;
@@ -1600,7 +1599,7 @@ lbValue lb_build_builtin_simd_proc(lbProcedure *p, Ast *expr, TypeAndValue const
} }
lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv, BuiltinProcId id) { gb_internal lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv, BuiltinProcId id) {
ast_node(ce, CallExpr, expr); ast_node(ce, CallExpr, expr);
if (BuiltinProc__simd_begin < id && id < BuiltinProc__simd_end) { if (BuiltinProc__simd_begin < id && id < BuiltinProc__simd_end) {
@@ -2980,7 +2979,7 @@ lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv,
} }
lbValue lb_handle_param_value(lbProcedure *p, Type *parameter_type, ParameterValue const &param_value, TokenPos const &pos) { gb_internal lbValue lb_handle_param_value(lbProcedure *p, Type *parameter_type, ParameterValue const &param_value, TokenPos const &pos) {
switch (param_value.kind) { switch (param_value.kind) {
case ParameterValue_Constant: case ParameterValue_Constant:
if (is_type_constant_type(parameter_type)) { if (is_type_constant_type(parameter_type)) {
@@ -3015,9 +3014,9 @@ lbValue lb_handle_param_value(lbProcedure *p, Type *parameter_type, ParameterVal
} }
lbValue lb_build_call_expr_internal(lbProcedure *p, Ast *expr); gb_internal lbValue lb_build_call_expr_internal(lbProcedure *p, Ast *expr);
lbValue lb_build_call_expr(lbProcedure *p, Ast *expr) { gb_internal lbValue lb_build_call_expr(lbProcedure *p, Ast *expr) {
expr = unparen_expr(expr); expr = unparen_expr(expr);
ast_node(ce, CallExpr, expr); ast_node(ce, CallExpr, expr);
@@ -3030,7 +3029,7 @@ lbValue lb_build_call_expr(lbProcedure *p, Ast *expr) {
} }
return res; return res;
} }
lbValue lb_build_call_expr_internal(lbProcedure *p, Ast *expr) { gb_internal lbValue lb_build_call_expr_internal(lbProcedure *p, Ast *expr) {
lbModule *m = p->module; lbModule *m = p->module;
TypeAndValue tv = type_and_value_of_expr(expr); TypeAndValue tv = type_and_value_of_expr(expr);
+45 -45
View File
@@ -1,4 +1,4 @@
void lb_build_constant_value_decl(lbProcedure *p, AstValueDecl *vd) { gb_internal void lb_build_constant_value_decl(lbProcedure *p, AstValueDecl *vd) {
if (vd == nullptr || vd->is_mutable) { if (vd == nullptr || vd->is_mutable) {
return; return;
} }
@@ -105,7 +105,7 @@ void lb_build_constant_value_decl(lbProcedure *p, AstValueDecl *vd) {
} }
void lb_build_stmt_list(lbProcedure *p, Slice<Ast *> const &stmts) { gb_internal void lb_build_stmt_list(lbProcedure *p, Slice<Ast *> const &stmts) {
for_array(i, stmts) { for_array(i, stmts) {
Ast *stmt = stmts[i]; Ast *stmt = stmts[i];
switch (stmt->kind) { switch (stmt->kind) {
@@ -125,7 +125,7 @@ void lb_build_stmt_list(lbProcedure *p, Slice<Ast *> const &stmts) {
lbBranchBlocks lb_lookup_branch_blocks(lbProcedure *p, Ast *ident) { gb_internal lbBranchBlocks lb_lookup_branch_blocks(lbProcedure *p, Ast *ident) {
GB_ASSERT(ident->kind == Ast_Ident); GB_ASSERT(ident->kind == Ast_Ident);
Entity *e = entity_of_node(ident); Entity *e = entity_of_node(ident);
GB_ASSERT(e->kind == Entity_Label); GB_ASSERT(e->kind == Entity_Label);
@@ -142,7 +142,7 @@ lbBranchBlocks lb_lookup_branch_blocks(lbProcedure *p, Ast *ident) {
} }
lbTargetList *lb_push_target_list(lbProcedure *p, Ast *label, lbBlock *break_, lbBlock *continue_, lbBlock *fallthrough_) { gb_internal lbTargetList *lb_push_target_list(lbProcedure *p, Ast *label, lbBlock *break_, lbBlock *continue_, lbBlock *fallthrough_) {
lbTargetList *tl = gb_alloc_item(permanent_allocator(), lbTargetList); lbTargetList *tl = gb_alloc_item(permanent_allocator(), lbTargetList);
tl->prev = p->target_list; tl->prev = p->target_list;
tl->break_ = break_; tl->break_ = break_;
@@ -170,11 +170,11 @@ lbTargetList *lb_push_target_list(lbProcedure *p, Ast *label, lbBlock *break_, l
return tl; return tl;
} }
void lb_pop_target_list(lbProcedure *p) { gb_internal void lb_pop_target_list(lbProcedure *p) {
p->target_list = p->target_list->prev; p->target_list = p->target_list->prev;
} }
void lb_open_scope(lbProcedure *p, Scope *s) { gb_internal void lb_open_scope(lbProcedure *p, Scope *s) {
lbModule *m = p->module; lbModule *m = p->module;
if (m->debug_builder) { if (m->debug_builder) {
LLVMMetadataRef curr_metadata = lb_get_llvm_metadata(m, s); LLVMMetadataRef curr_metadata = lb_get_llvm_metadata(m, s);
@@ -211,7 +211,7 @@ void lb_open_scope(lbProcedure *p, Scope *s) {
} }
void lb_close_scope(lbProcedure *p, lbDeferExitKind kind, lbBlock *block, bool pop_stack=true) { gb_internal void lb_close_scope(lbProcedure *p, lbDeferExitKind kind, lbBlock *block, bool pop_stack=true) {
lb_emit_defer_stmts(p, kind, block); lb_emit_defer_stmts(p, kind, block);
GB_ASSERT(p->scope_index > 0); GB_ASSERT(p->scope_index > 0);
@@ -230,7 +230,7 @@ void lb_close_scope(lbProcedure *p, lbDeferExitKind kind, lbBlock *block, bool p
array_pop(&p->scope_stack); array_pop(&p->scope_stack);
} }
void lb_build_when_stmt(lbProcedure *p, AstWhenStmt *ws) { gb_internal void lb_build_when_stmt(lbProcedure *p, AstWhenStmt *ws) {
TypeAndValue tv = type_and_value_of_expr(ws->cond); TypeAndValue tv = type_and_value_of_expr(ws->cond);
GB_ASSERT(is_type_boolean(tv.type)); GB_ASSERT(is_type_boolean(tv.type));
GB_ASSERT(tv.value.kind == ExactValue_Bool); GB_ASSERT(tv.value.kind == ExactValue_Bool);
@@ -253,8 +253,8 @@ void lb_build_when_stmt(lbProcedure *p, AstWhenStmt *ws) {
void lb_build_range_indexed(lbProcedure *p, lbValue expr, Type *val_type, lbValue count_ptr, gb_internal void lb_build_range_indexed(lbProcedure *p, lbValue expr, Type *val_type, lbValue count_ptr,
lbValue *val_, lbValue *idx_, lbBlock **loop_, lbBlock **done_) { lbValue *val_, lbValue *idx_, lbBlock **loop_, lbBlock **done_) {
lbModule *m = p->module; lbModule *m = p->module;
lbValue count = {}; lbValue count = {};
@@ -342,7 +342,7 @@ void lb_build_range_indexed(lbProcedure *p, lbValue expr, Type *val_type, lbValu
if (done_) *done_ = done; if (done_) *done_ = done;
} }
lbValue lb_map_cell_index_static(lbProcedure *p, Type *type, lbValue cells_ptr, lbValue index) { gb_internal lbValue lb_map_cell_index_static(lbProcedure *p, Type *type, lbValue cells_ptr, lbValue index) {
i64 size, len; i64 size, len;
i64 elem_sz = type_size_of(type); i64 elem_sz = type_size_of(type);
map_cell_size_and_len(type, &size, &len); map_cell_size_and_len(type, &size, &len);
@@ -378,7 +378,7 @@ lbValue lb_map_cell_index_static(lbProcedure *p, Type *type, lbValue cells_ptr,
return lb_emit_ptr_offset(p, elems_ptr, data_index); return lb_emit_ptr_offset(p, elems_ptr, data_index);
} }
void lb_map_kvh_data_static(lbProcedure *p, lbValue map_value, lbValue *ks_, lbValue *vs_, lbValue *hs_) { gb_internal void lb_map_kvh_data_static(lbProcedure *p, lbValue map_value, lbValue *ks_, lbValue *vs_, lbValue *hs_) {
lbValue capacity = lb_map_cap(p, map_value); lbValue capacity = lb_map_cap(p, map_value);
lbValue ks = lb_map_data_uintptr(p, map_value); lbValue ks = lb_map_data_uintptr(p, map_value);
lbValue vs = {}; lbValue vs = {};
@@ -388,7 +388,7 @@ void lb_map_kvh_data_static(lbProcedure *p, lbValue map_value, lbValue *ks_, lbV
if (hs_) *hs_ = hs; if (hs_) *hs_ = hs;
} }
lbValue lb_map_hash_is_valid(lbProcedure *p, lbValue hash) { gb_internal lbValue lb_map_hash_is_valid(lbProcedure *p, lbValue hash) {
// N :: size_of(uintptr)*8 - 1 // N :: size_of(uintptr)*8 - 1
// (hash != 0) & (hash>>N == 0) // (hash != 0) & (hash>>N == 0)
@@ -404,8 +404,8 @@ lbValue lb_map_hash_is_valid(lbProcedure *p, lbValue hash) {
return lb_emit_arith(p, Token_And, not_deleted, not_empty, t_uintptr); return lb_emit_arith(p, Token_And, not_deleted, not_empty, t_uintptr);
} }
void lb_build_range_map(lbProcedure *p, lbValue expr, Type *val_type, gb_internal void lb_build_range_map(lbProcedure *p, lbValue expr, Type *val_type,
lbValue *val_, lbValue *key_, lbBlock **loop_, lbBlock **done_) { lbValue *val_, lbValue *key_, lbBlock **loop_, lbBlock **done_) {
lbModule *m = p->module; lbModule *m = p->module;
Type *type = base_type(type_deref(expr.type)); Type *type = base_type(type_deref(expr.type));
@@ -466,8 +466,8 @@ void lb_build_range_map(lbProcedure *p, lbValue expr, Type *val_type,
void lb_build_range_string(lbProcedure *p, lbValue expr, Type *val_type, gb_internal void lb_build_range_string(lbProcedure *p, lbValue expr, Type *val_type,
lbValue *val_, lbValue *idx_, lbBlock **loop_, lbBlock **done_) { lbValue *val_, lbValue *idx_, lbBlock **loop_, lbBlock **done_) {
lbModule *m = p->module; lbModule *m = p->module;
lbValue count = lb_const_int(m, t_int, 0); lbValue count = lb_const_int(m, t_int, 0);
Type *expr_type = base_type(expr.type); Type *expr_type = base_type(expr.type);
@@ -526,8 +526,8 @@ void lb_build_range_string(lbProcedure *p, lbValue expr, Type *val_type,
} }
void lb_build_range_interval(lbProcedure *p, AstBinaryExpr *node, gb_internal void lb_build_range_interval(lbProcedure *p, AstBinaryExpr *node,
AstRangeStmt *rs, Scope *scope) { AstRangeStmt *rs, Scope *scope) {
bool ADD_EXTRA_WRAPPING_CHECK = true; bool ADD_EXTRA_WRAPPING_CHECK = true;
lbModule *m = p->module; lbModule *m = p->module;
@@ -630,7 +630,7 @@ void lb_build_range_interval(lbProcedure *p, AstBinaryExpr *node,
lb_start_block(p, done); lb_start_block(p, done);
} }
void lb_build_range_enum(lbProcedure *p, Type *enum_type, Type *val_type, lbValue *val_, lbValue *idx_, lbBlock **loop_, lbBlock **done_) { gb_internal void lb_build_range_enum(lbProcedure *p, Type *enum_type, Type *val_type, lbValue *val_, lbValue *idx_, lbBlock **loop_, lbBlock **done_) {
lbModule *m = p->module; lbModule *m = p->module;
Type *t = enum_type; Type *t = enum_type;
@@ -683,8 +683,8 @@ void lb_build_range_enum(lbProcedure *p, Type *enum_type, Type *val_type, lbValu
if (done_) *done_ = done; if (done_) *done_ = done;
} }
void lb_build_range_tuple(lbProcedure *p, Ast *expr, Type *val0_type, Type *val1_type, gb_internal void lb_build_range_tuple(lbProcedure *p, Ast *expr, Type *val0_type, Type *val1_type,
lbValue *val0_, lbValue *val1_, lbBlock **loop_, lbBlock **done_) { lbValue *val0_, lbValue *val1_, lbBlock **loop_, lbBlock **done_) {
lbBlock *loop = lb_create_block(p, "for.tuple.loop"); lbBlock *loop = lb_create_block(p, "for.tuple.loop");
lb_emit_jump(p, loop); lb_emit_jump(p, loop);
lb_start_block(p, loop); lb_start_block(p, loop);
@@ -709,7 +709,7 @@ void lb_build_range_tuple(lbProcedure *p, Ast *expr, Type *val0_type, Type *val1
if (done_) *done_ = done; if (done_) *done_ = done;
} }
void lb_build_range_stmt_struct_soa(lbProcedure *p, AstRangeStmt *rs, Scope *scope) { gb_internal void lb_build_range_stmt_struct_soa(lbProcedure *p, AstRangeStmt *rs, Scope *scope) {
Ast *expr = unparen_expr(rs->expr); Ast *expr = unparen_expr(rs->expr);
TypeAndValue tav = type_and_value_of_expr(expr); TypeAndValue tav = type_and_value_of_expr(expr);
@@ -778,7 +778,7 @@ void lb_build_range_stmt_struct_soa(lbProcedure *p, AstRangeStmt *rs, Scope *sco
} }
void lb_build_range_stmt(lbProcedure *p, AstRangeStmt *rs, Scope *scope) { gb_internal void lb_build_range_stmt(lbProcedure *p, AstRangeStmt *rs, Scope *scope) {
Ast *expr = unparen_expr(rs->expr); Ast *expr = unparen_expr(rs->expr);
if (is_ast_range(expr)) { if (is_ast_range(expr)) {
@@ -923,7 +923,7 @@ void lb_build_range_stmt(lbProcedure *p, AstRangeStmt *rs, Scope *scope) {
lb_start_block(p, done); lb_start_block(p, done);
} }
void lb_build_unroll_range_stmt(lbProcedure *p, AstUnrollRangeStmt *rs, Scope *scope) { gb_internal void lb_build_unroll_range_stmt(lbProcedure *p, AstUnrollRangeStmt *rs, Scope *scope) {
lbModule *m = p->module; lbModule *m = p->module;
lb_open_scope(p, scope); // Open scope here lb_open_scope(p, scope); // Open scope here
@@ -1089,7 +1089,7 @@ void lb_build_unroll_range_stmt(lbProcedure *p, AstUnrollRangeStmt *rs, Scope *s
lb_close_scope(p, lbDeferExit_Default, nullptr); lb_close_scope(p, lbDeferExit_Default, nullptr);
} }
bool lb_switch_stmt_can_be_trivial_jump_table(AstSwitchStmt *ss, bool *default_found_) { gb_internal bool lb_switch_stmt_can_be_trivial_jump_table(AstSwitchStmt *ss, bool *default_found_) {
if (ss->tag == nullptr) { if (ss->tag == nullptr) {
return false; return false;
} }
@@ -1138,7 +1138,7 @@ bool lb_switch_stmt_can_be_trivial_jump_table(AstSwitchStmt *ss, bool *default_f
} }
void lb_build_switch_stmt(lbProcedure *p, AstSwitchStmt *ss, Scope *scope) { gb_internal void lb_build_switch_stmt(lbProcedure *p, AstSwitchStmt *ss, Scope *scope) {
lb_open_scope(p, scope); lb_open_scope(p, scope);
if (ss->init != nullptr) { if (ss->init != nullptr) {
@@ -1300,7 +1300,7 @@ void lb_build_switch_stmt(lbProcedure *p, AstSwitchStmt *ss, Scope *scope) {
lb_close_scope(p, lbDeferExit_Default, done); lb_close_scope(p, lbDeferExit_Default, done);
} }
void lb_store_type_case_implicit(lbProcedure *p, Ast *clause, lbValue value) { gb_internal void lb_store_type_case_implicit(lbProcedure *p, Ast *clause, lbValue value) {
Entity *e = implicit_entity_of_node(clause); Entity *e = implicit_entity_of_node(clause);
GB_ASSERT(e != nullptr); GB_ASSERT(e != nullptr);
if (e->flags & EntityFlag_Value) { if (e->flags & EntityFlag_Value) {
@@ -1315,7 +1315,7 @@ void lb_store_type_case_implicit(lbProcedure *p, Ast *clause, lbValue value) {
} }
} }
lbAddr lb_store_range_stmt_val(lbProcedure *p, Ast *stmt_val, lbValue value) { gb_internal lbAddr lb_store_range_stmt_val(lbProcedure *p, Ast *stmt_val, lbValue value) {
Entity *e = entity_of_node(stmt_val); Entity *e = entity_of_node(stmt_val);
if (e == nullptr) { if (e == nullptr) {
return {}; return {};
@@ -1335,7 +1335,7 @@ lbAddr lb_store_range_stmt_val(lbProcedure *p, Ast *stmt_val, lbValue value) {
return addr; return addr;
} }
void lb_type_case_body(lbProcedure *p, Ast *label, Ast *clause, lbBlock *body, lbBlock *done) { gb_internal void lb_type_case_body(lbProcedure *p, Ast *label, Ast *clause, lbBlock *body, lbBlock *done) {
ast_node(cc, CaseClause, clause); ast_node(cc, CaseClause, clause);
lb_push_target_list(p, label, done, nullptr, nullptr); lb_push_target_list(p, label, done, nullptr, nullptr);
@@ -1346,7 +1346,7 @@ void lb_type_case_body(lbProcedure *p, Ast *label, Ast *clause, lbBlock *body, l
lb_emit_jump(p, done); lb_emit_jump(p, done);
} }
void lb_build_type_switch_stmt(lbProcedure *p, AstTypeSwitchStmt *ss) { gb_internal void lb_build_type_switch_stmt(lbProcedure *p, AstTypeSwitchStmt *ss) {
lbModule *m = p->module; lbModule *m = p->module;
lb_open_scope(p, ss->scope); lb_open_scope(p, ss->scope);
@@ -1480,7 +1480,7 @@ void lb_build_type_switch_stmt(lbProcedure *p, AstTypeSwitchStmt *ss) {
} }
void lb_build_static_variables(lbProcedure *p, AstValueDecl *vd) { gb_internal void lb_build_static_variables(lbProcedure *p, AstValueDecl *vd) {
for_array(i, vd->names) { for_array(i, vd->names) {
lbValue value = {}; lbValue value = {};
if (vd->values.count > 0) { if (vd->values.count > 0) {
@@ -1543,7 +1543,7 @@ void lb_build_static_variables(lbProcedure *p, AstValueDecl *vd) {
lb_add_member(p->module, mangled_name, global_val); lb_add_member(p->module, mangled_name, global_val);
} }
} }
void lb_append_tuple_values(lbProcedure *p, Array<lbValue> *dst_values, lbValue src_value) { gb_internal void lb_append_tuple_values(lbProcedure *p, Array<lbValue> *dst_values, lbValue src_value) {
Type *t = src_value.type; Type *t = src_value.type;
if (t->kind == Type_Tuple) { if (t->kind == Type_Tuple) {
lbTupleFix *tf = map_get(&p->tuple_fix_map, src_value.value); lbTupleFix *tf = map_get(&p->tuple_fix_map, src_value.value);
@@ -1563,7 +1563,7 @@ void lb_append_tuple_values(lbProcedure *p, Array<lbValue> *dst_values, lbValue
} }
void lb_build_assignment(lbProcedure *p, Array<lbAddr> &lvals, Slice<Ast *> const &values) { gb_internal void lb_build_assignment(lbProcedure *p, Array<lbAddr> &lvals, Slice<Ast *> const &values) {
if (values.count == 0) { if (values.count == 0) {
return; return;
} }
@@ -1584,7 +1584,7 @@ void lb_build_assignment(lbProcedure *p, Array<lbAddr> &lvals, Slice<Ast *> cons
} }
} }
void lb_build_return_stmt_internal(lbProcedure *p, lbValue res) { gb_internal void lb_build_return_stmt_internal(lbProcedure *p, lbValue res) {
lbFunctionType *ft = lb_get_function_type(p->module, p->type); lbFunctionType *ft = lb_get_function_type(p->module, p->type);
bool return_by_pointer = ft->ret.kind == lbArg_Indirect; bool return_by_pointer = ft->ret.kind == lbArg_Indirect;
bool split_returns = ft->multiple_return_original_type != nullptr; bool split_returns = ft->multiple_return_original_type != nullptr;
@@ -1621,7 +1621,7 @@ void lb_build_return_stmt_internal(lbProcedure *p, lbValue res) {
LLVMBuildRet(p->builder, ret_val); LLVMBuildRet(p->builder, ret_val);
} }
} }
void lb_build_return_stmt(lbProcedure *p, Slice<Ast *> const &return_results) { gb_internal void lb_build_return_stmt(lbProcedure *p, Slice<Ast *> const &return_results) {
lb_ensure_abi_function_type(p->module, p); lb_ensure_abi_function_type(p->module, p);
lbValue res = {}; lbValue res = {};
@@ -1765,7 +1765,7 @@ void lb_build_return_stmt(lbProcedure *p, Slice<Ast *> const &return_results) {
lb_build_return_stmt_internal(p, res); lb_build_return_stmt_internal(p, res);
} }
void lb_build_if_stmt(lbProcedure *p, Ast *node) { gb_internal void lb_build_if_stmt(lbProcedure *p, Ast *node) {
ast_node(is, IfStmt, node); ast_node(is, IfStmt, node);
lb_open_scope(p, is->scope); // Scope #1 lb_open_scope(p, is->scope); // Scope #1
defer (lb_close_scope(p, lbDeferExit_Default, nullptr)); defer (lb_close_scope(p, lbDeferExit_Default, nullptr));
@@ -1852,7 +1852,7 @@ void lb_build_if_stmt(lbProcedure *p, Ast *node) {
lb_start_block(p, done); lb_start_block(p, done);
} }
void lb_build_for_stmt(lbProcedure *p, Ast *node) { gb_internal void lb_build_for_stmt(lbProcedure *p, Ast *node) {
ast_node(fs, ForStmt, node); ast_node(fs, ForStmt, node);
lb_open_scope(p, fs->scope); // Open Scope here lb_open_scope(p, fs->scope); // Open Scope here
@@ -1912,7 +1912,7 @@ void lb_build_for_stmt(lbProcedure *p, Ast *node) {
lb_close_scope(p, lbDeferExit_Default, nullptr); lb_close_scope(p, lbDeferExit_Default, nullptr);
} }
void lb_build_assign_stmt_array(lbProcedure *p, TokenKind op, lbAddr const &lhs, lbValue const &value) { gb_internal void lb_build_assign_stmt_array(lbProcedure *p, TokenKind op, lbAddr const &lhs, lbValue const &value) {
GB_ASSERT(op != Token_Eq); GB_ASSERT(op != Token_Eq);
Type *lhs_type = lb_addr_type(lhs); Type *lhs_type = lb_addr_type(lhs);
@@ -2055,7 +2055,7 @@ void lb_build_assign_stmt_array(lbProcedure *p, TokenKind op, lbAddr const &lhs,
lb_loop_end(p, loop_data); lb_loop_end(p, loop_data);
} }
} }
void lb_build_assign_stmt(lbProcedure *p, AstAssignStmt *as) { gb_internal void lb_build_assign_stmt(lbProcedure *p, AstAssignStmt *as) {
if (as->op.kind == Token_Eq) { if (as->op.kind == Token_Eq) {
auto lvals = array_make<lbAddr>(permanent_allocator(), 0, as->lhs.count); auto lvals = array_make<lbAddr>(permanent_allocator(), 0, as->lhs.count);
@@ -2113,7 +2113,7 @@ void lb_build_assign_stmt(lbProcedure *p, AstAssignStmt *as) {
} }
void lb_build_stmt(lbProcedure *p, Ast *node) { gb_internal void lb_build_stmt(lbProcedure *p, Ast *node) {
Ast *prev_stmt = p->curr_stmt; Ast *prev_stmt = p->curr_stmt;
defer (p->curr_stmt = prev_stmt); defer (p->curr_stmt = prev_stmt);
p->curr_stmt = node; p->curr_stmt = node;
@@ -2308,7 +2308,7 @@ void lb_build_stmt(lbProcedure *p, Ast *node) {
void lb_build_defer_stmt(lbProcedure *p, lbDefer const &d) { gb_internal void lb_build_defer_stmt(lbProcedure *p, lbDefer const &d) {
if (p->curr_block == nullptr) { if (p->curr_block == nullptr) {
return; return;
} }
@@ -2337,7 +2337,7 @@ void lb_build_defer_stmt(lbProcedure *p, lbDefer const &d) {
} }
} }
void lb_emit_defer_stmts(lbProcedure *p, lbDeferExitKind kind, lbBlock *block) { gb_internal void lb_emit_defer_stmts(lbProcedure *p, lbDeferExitKind kind, lbBlock *block) {
isize count = p->defer_stmts.count; isize count = p->defer_stmts.count;
isize i = count; isize i = count;
while (i --> 0) { while (i --> 0) {
@@ -2364,7 +2364,7 @@ void lb_emit_defer_stmts(lbProcedure *p, lbDeferExitKind kind, lbBlock *block) {
} }
} }
void lb_add_defer_node(lbProcedure *p, isize scope_index, Ast *stmt) { gb_internal void lb_add_defer_node(lbProcedure *p, isize scope_index, Ast *stmt) {
Type *pt = base_type(p->type); Type *pt = base_type(p->type);
GB_ASSERT(pt->kind == Type_Proc); GB_ASSERT(pt->kind == Type_Proc);
if (pt->Proc.calling_convention == ProcCC_Odin) { if (pt->Proc.calling_convention == ProcCC_Odin) {
@@ -2379,7 +2379,7 @@ void lb_add_defer_node(lbProcedure *p, isize scope_index, Ast *stmt) {
d->stmt = stmt; d->stmt = stmt;
} }
void lb_add_defer_proc(lbProcedure *p, isize scope_index, lbValue deferred, Array<lbValue> const &result_as_args) { gb_internal void lb_add_defer_proc(lbProcedure *p, isize scope_index, lbValue deferred, Array<lbValue> const &result_as_args) {
Type *pt = base_type(p->type); Type *pt = base_type(p->type);
GB_ASSERT(pt->kind == Type_Proc); GB_ASSERT(pt->kind == Type_Proc);
if (pt->Proc.calling_convention == ProcCC_Odin) { if (pt->Proc.calling_convention == ProcCC_Odin) {
+10 -10
View File
@@ -1,4 +1,4 @@
isize lb_type_info_index(CheckerInfo *info, Type *type, bool err_on_not_found=true) { gb_internal isize lb_type_info_index(CheckerInfo *info, Type *type, bool err_on_not_found=true) {
auto *set = &info->minimum_dependency_type_info_set; auto *set = &info->minimum_dependency_type_info_set;
isize index = type_info_index(info, type, err_on_not_found); isize index = type_info_index(info, type, err_on_not_found);
if (index >= 0) { if (index >= 0) {
@@ -13,7 +13,7 @@ isize lb_type_info_index(CheckerInfo *info, Type *type, bool err_on_not_found=tr
return -1; return -1;
} }
lbValue lb_typeid(lbModule *m, Type *type) { gb_internal lbValue lb_typeid(lbModule *m, Type *type) {
GB_ASSERT(!build_context.disallow_rtti); GB_ASSERT(!build_context.disallow_rtti);
type = default_type(type); type = default_type(type);
@@ -90,7 +90,7 @@ lbValue lb_typeid(lbModule *m, Type *type) {
return res; return res;
} }
lbValue lb_type_info(lbModule *m, Type *type) { gb_internal lbValue lb_type_info(lbModule *m, Type *type) {
GB_ASSERT(!build_context.disallow_rtti); GB_ASSERT(!build_context.disallow_rtti);
type = default_type(type); type = default_type(type);
@@ -102,36 +102,36 @@ lbValue lb_type_info(lbModule *m, Type *type) {
return lb_emit_array_epi(m, data, index); return lb_emit_array_epi(m, data, index);
} }
LLVMTypeRef lb_get_procedure_raw_type(lbModule *m, Type *type) { gb_internal LLVMTypeRef lb_get_procedure_raw_type(lbModule *m, Type *type) {
return lb_type_internal_for_procedures_raw(m, type); return lb_type_internal_for_procedures_raw(m, type);
} }
lbValue lb_type_info_member_types_offset(lbProcedure *p, isize count) { gb_internal lbValue lb_type_info_member_types_offset(lbProcedure *p, isize count) {
GB_ASSERT(p->module == &p->module->gen->default_module); GB_ASSERT(p->module == &p->module->gen->default_module);
lbValue offset = lb_emit_array_epi(p, lb_global_type_info_member_types.addr, lb_global_type_info_member_types_index); lbValue offset = lb_emit_array_epi(p, lb_global_type_info_member_types.addr, lb_global_type_info_member_types_index);
lb_global_type_info_member_types_index += cast(i32)count; lb_global_type_info_member_types_index += cast(i32)count;
return offset; return offset;
} }
lbValue lb_type_info_member_names_offset(lbProcedure *p, isize count) { gb_internal lbValue lb_type_info_member_names_offset(lbProcedure *p, isize count) {
GB_ASSERT(p->module == &p->module->gen->default_module); GB_ASSERT(p->module == &p->module->gen->default_module);
lbValue offset = lb_emit_array_epi(p, lb_global_type_info_member_names.addr, lb_global_type_info_member_names_index); lbValue offset = lb_emit_array_epi(p, lb_global_type_info_member_names.addr, lb_global_type_info_member_names_index);
lb_global_type_info_member_names_index += cast(i32)count; lb_global_type_info_member_names_index += cast(i32)count;
return offset; return offset;
} }
lbValue lb_type_info_member_offsets_offset(lbProcedure *p, isize count) { gb_internal lbValue lb_type_info_member_offsets_offset(lbProcedure *p, isize count) {
GB_ASSERT(p->module == &p->module->gen->default_module); GB_ASSERT(p->module == &p->module->gen->default_module);
lbValue offset = lb_emit_array_epi(p, lb_global_type_info_member_offsets.addr, lb_global_type_info_member_offsets_index); lbValue offset = lb_emit_array_epi(p, lb_global_type_info_member_offsets.addr, lb_global_type_info_member_offsets_index);
lb_global_type_info_member_offsets_index += cast(i32)count; lb_global_type_info_member_offsets_index += cast(i32)count;
return offset; return offset;
} }
lbValue lb_type_info_member_usings_offset(lbProcedure *p, isize count) { gb_internal lbValue lb_type_info_member_usings_offset(lbProcedure *p, isize count) {
GB_ASSERT(p->module == &p->module->gen->default_module); GB_ASSERT(p->module == &p->module->gen->default_module);
lbValue offset = lb_emit_array_epi(p, lb_global_type_info_member_usings.addr, lb_global_type_info_member_usings_index); lbValue offset = lb_emit_array_epi(p, lb_global_type_info_member_usings.addr, lb_global_type_info_member_usings_index);
lb_global_type_info_member_usings_index += cast(i32)count; lb_global_type_info_member_usings_index += cast(i32)count;
return offset; return offset;
} }
lbValue lb_type_info_member_tags_offset(lbProcedure *p, isize count) { gb_internal lbValue lb_type_info_member_tags_offset(lbProcedure *p, isize count) {
GB_ASSERT(p->module == &p->module->gen->default_module); GB_ASSERT(p->module == &p->module->gen->default_module);
lbValue offset = lb_emit_array_epi(p, lb_global_type_info_member_tags.addr, lb_global_type_info_member_tags_index); lbValue offset = lb_emit_array_epi(p, lb_global_type_info_member_tags.addr, lb_global_type_info_member_tags_index);
lb_global_type_info_member_tags_index += cast(i32)count; lb_global_type_info_member_tags_index += cast(i32)count;
@@ -139,7 +139,7 @@ lbValue lb_type_info_member_tags_offset(lbProcedure *p, isize count) {
} }
void lb_setup_type_info_data(lbProcedure *p) { // NOTE(bill): Setup type_info data gb_internal void lb_setup_type_info_data(lbProcedure *p) { // NOTE(bill): Setup type_info data
if (build_context.disallow_rtti) { if (build_context.disallow_rtti) {
return; return;
} }
+97 -97
View File
@@ -1,6 +1,6 @@
lbValue lb_lookup_runtime_procedure(lbModule *m, String const &name); gb_internal lbValue lb_lookup_runtime_procedure(lbModule *m, String const &name);
bool lb_is_type_aggregate(Type *t) { gb_internal bool lb_is_type_aggregate(Type *t) {
t = base_type(t); t = base_type(t);
switch (t->kind) { switch (t->kind) {
case Type_Basic: case Type_Basic:
@@ -39,7 +39,7 @@ bool lb_is_type_aggregate(Type *t) {
return false; return false;
} }
void lb_emit_unreachable(lbProcedure *p) { gb_internal void lb_emit_unreachable(lbProcedure *p) {
LLVMValueRef instr = LLVMGetLastInstruction(p->curr_block->block); LLVMValueRef instr = LLVMGetLastInstruction(p->curr_block->block);
if (instr == nullptr || !lb_is_instr_terminating(instr)) { if (instr == nullptr || !lb_is_instr_terminating(instr)) {
lb_call_intrinsic(p, "llvm.trap", nullptr, 0, nullptr, 0); lb_call_intrinsic(p, "llvm.trap", nullptr, 0, nullptr, 0);
@@ -47,7 +47,7 @@ void lb_emit_unreachable(lbProcedure *p) {
} }
} }
lbValue lb_correct_endianness(lbProcedure *p, lbValue value) { gb_internal lbValue lb_correct_endianness(lbProcedure *p, lbValue value) {
Type *src = core_type(value.type); Type *src = core_type(value.type);
GB_ASSERT(is_type_integer(src) || is_type_float(src)); GB_ASSERT(is_type_integer(src) || is_type_float(src));
if (is_type_different_to_arch_endianness(src)) { if (is_type_different_to_arch_endianness(src)) {
@@ -57,7 +57,7 @@ lbValue lb_correct_endianness(lbProcedure *p, lbValue value) {
return value; return value;
} }
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;
i64 const_len = 0; i64 const_len = 0;
@@ -103,7 +103,7 @@ LLVMValueRef lb_mem_zero_ptr_internal(lbProcedure *p, LLVMValueRef ptr, LLVMValu
} }
void lb_mem_zero_ptr(lbProcedure *p, LLVMValueRef ptr, Type *type, unsigned alignment) { gb_internal void lb_mem_zero_ptr(lbProcedure *p, LLVMValueRef ptr, Type *type, unsigned alignment) {
LLVMTypeRef llvm_type = lb_type(p->module, type); LLVMTypeRef llvm_type = lb_type(p->module, type);
LLVMTypeKind kind = LLVMGetTypeKind(llvm_type); LLVMTypeKind kind = LLVMGetTypeKind(llvm_type);
@@ -123,7 +123,7 @@ void lb_mem_zero_ptr(lbProcedure *p, LLVMValueRef ptr, Type *type, unsigned alig
} }
} }
lbValue lb_emit_select(lbProcedure *p, lbValue cond, lbValue x, lbValue y) { gb_internal lbValue lb_emit_select(lbProcedure *p, lbValue cond, lbValue x, lbValue y) {
cond = lb_emit_conv(p, cond, t_llvm_bool); cond = lb_emit_conv(p, cond, t_llvm_bool);
lbValue res = {}; lbValue res = {};
res.value = LLVMBuildSelect(p->builder, cond.value, x.value, y.value, ""); res.value = LLVMBuildSelect(p->builder, cond.value, x.value, y.value, "");
@@ -131,19 +131,19 @@ lbValue lb_emit_select(lbProcedure *p, lbValue cond, lbValue x, lbValue y) {
return res; return res;
} }
lbValue lb_emit_min(lbProcedure *p, Type *t, lbValue x, lbValue y) { gb_internal lbValue lb_emit_min(lbProcedure *p, Type *t, lbValue x, lbValue y) {
x = lb_emit_conv(p, x, t); x = lb_emit_conv(p, x, t);
y = lb_emit_conv(p, y, t); y = lb_emit_conv(p, y, t);
return lb_emit_select(p, lb_emit_comp(p, Token_Lt, x, y), x, y); return lb_emit_select(p, lb_emit_comp(p, Token_Lt, x, y), x, y);
} }
lbValue lb_emit_max(lbProcedure *p, Type *t, lbValue x, lbValue y) { gb_internal lbValue lb_emit_max(lbProcedure *p, Type *t, lbValue x, lbValue y) {
x = lb_emit_conv(p, x, t); x = lb_emit_conv(p, x, t);
y = lb_emit_conv(p, y, t); y = lb_emit_conv(p, y, t);
return lb_emit_select(p, lb_emit_comp(p, Token_Gt, x, y), x, y); return lb_emit_select(p, lb_emit_comp(p, Token_Gt, x, y), x, y);
} }
lbValue lb_emit_clamp(lbProcedure *p, Type *t, lbValue x, lbValue min, lbValue max) { gb_internal lbValue lb_emit_clamp(lbProcedure *p, Type *t, lbValue x, lbValue min, lbValue max) {
lbValue z = {}; lbValue z = {};
z = lb_emit_max(p, t, x, min); z = lb_emit_max(p, t, x, min);
z = lb_emit_min(p, t, z, max); z = lb_emit_min(p, t, z, max);
@@ -152,7 +152,7 @@ lbValue lb_emit_clamp(lbProcedure *p, Type *t, lbValue x, lbValue min, lbValue m
lbValue lb_emit_string(lbProcedure *p, lbValue str_elem, lbValue str_len) { gb_internal lbValue lb_emit_string(lbProcedure *p, lbValue str_elem, lbValue str_len) {
if (false && lb_is_const(str_elem) && lb_is_const(str_len)) { if (false && lb_is_const(str_elem) && lb_is_const(str_len)) {
LLVMValueRef values[2] = { LLVMValueRef values[2] = {
str_elem.value, str_elem.value,
@@ -171,7 +171,7 @@ lbValue lb_emit_string(lbProcedure *p, lbValue str_elem, lbValue str_len) {
} }
lbValue lb_emit_transmute(lbProcedure *p, lbValue value, Type *t) { gb_internal lbValue lb_emit_transmute(lbProcedure *p, lbValue value, Type *t) {
Type *src_type = value.type; Type *src_type = value.type;
if (are_types_identical(t, src_type)) { if (are_types_identical(t, src_type)) {
return value; return value;
@@ -259,7 +259,7 @@ lbValue lb_emit_transmute(lbProcedure *p, lbValue value, Type *t) {
return res; return res;
} }
lbValue lb_copy_value_to_ptr(lbProcedure *p, lbValue val, Type *new_type, i64 alignment) { gb_internal lbValue lb_copy_value_to_ptr(lbProcedure *p, lbValue val, Type *new_type, i64 alignment) {
i64 type_alignment = type_align_of(new_type); i64 type_alignment = type_align_of(new_type);
if (alignment < type_alignment) { if (alignment < type_alignment) {
alignment = type_alignment; alignment = type_alignment;
@@ -274,7 +274,7 @@ lbValue lb_copy_value_to_ptr(lbProcedure *p, lbValue val, Type *new_type, i64 al
} }
lbValue lb_soa_zip(lbProcedure *p, AstCallExpr *ce, TypeAndValue const &tv) { gb_internal lbValue lb_soa_zip(lbProcedure *p, AstCallExpr *ce, TypeAndValue const &tv) {
GB_ASSERT(ce->args.count > 0); GB_ASSERT(ce->args.count > 0);
auto slices = slice_make<lbValue>(temporary_allocator(), ce->args.count); auto slices = slice_make<lbValue>(temporary_allocator(), ce->args.count);
@@ -305,7 +305,7 @@ lbValue lb_soa_zip(lbProcedure *p, AstCallExpr *ce, TypeAndValue const &tv) {
return lb_addr_load(p, res); return lb_addr_load(p, res);
} }
lbValue lb_soa_unzip(lbProcedure *p, AstCallExpr *ce, TypeAndValue const &tv) { gb_internal lbValue lb_soa_unzip(lbProcedure *p, AstCallExpr *ce, TypeAndValue const &tv) {
GB_ASSERT(ce->args.count == 1); GB_ASSERT(ce->args.count == 1);
lbValue arg = lb_build_expr(p, ce->args[0]); lbValue arg = lb_build_expr(p, ce->args[0]);
@@ -331,7 +331,7 @@ lbValue lb_soa_unzip(lbProcedure *p, AstCallExpr *ce, TypeAndValue const &tv) {
return lb_addr_load(p, res); return lb_addr_load(p, res);
} }
void lb_emit_try_lhs_rhs(lbProcedure *p, Ast *arg, TypeAndValue const &tv, lbValue *lhs_, lbValue *rhs_) { gb_internal void lb_emit_try_lhs_rhs(lbProcedure *p, Ast *arg, TypeAndValue const &tv, lbValue *lhs_, lbValue *rhs_) {
lbValue lhs = {}; lbValue lhs = {};
lbValue rhs = {}; lbValue rhs = {};
@@ -360,7 +360,7 @@ void lb_emit_try_lhs_rhs(lbProcedure *p, Ast *arg, TypeAndValue const &tv, lbVal
} }
lbValue lb_emit_try_has_value(lbProcedure *p, lbValue rhs) { gb_internal lbValue lb_emit_try_has_value(lbProcedure *p, lbValue rhs) {
lbValue has_value = {}; lbValue has_value = {};
if (is_type_boolean(rhs.type)) { if (is_type_boolean(rhs.type)) {
has_value = rhs; has_value = rhs;
@@ -373,7 +373,7 @@ lbValue lb_emit_try_has_value(lbProcedure *p, lbValue rhs) {
} }
lbValue lb_emit_or_else(lbProcedure *p, Ast *arg, Ast *else_expr, TypeAndValue const &tv) { gb_internal lbValue lb_emit_or_else(lbProcedure *p, Ast *arg, Ast *else_expr, TypeAndValue const &tv) {
if (arg->state_flags & StateFlag_DirectiveWasFalse) { if (arg->state_flags & StateFlag_DirectiveWasFalse) {
return lb_build_expr(p, else_expr); return lb_build_expr(p, else_expr);
} }
@@ -435,10 +435,10 @@ lbValue lb_emit_or_else(lbProcedure *p, Ast *arg, Ast *else_expr, TypeAndValue c
} }
} }
void lb_build_return_stmt(lbProcedure *p, Slice<Ast *> const &return_results); gb_internal void lb_build_return_stmt(lbProcedure *p, Slice<Ast *> const &return_results);
void lb_build_return_stmt_internal(lbProcedure *p, lbValue res); gb_internal void lb_build_return_stmt_internal(lbProcedure *p, lbValue res);
lbValue lb_emit_or_return(lbProcedure *p, Ast *arg, TypeAndValue const &tv) { gb_internal lbValue lb_emit_or_return(lbProcedure *p, Ast *arg, TypeAndValue const &tv) {
lbValue lhs = {}; lbValue lhs = {};
lbValue rhs = {}; lbValue rhs = {};
lb_emit_try_lhs_rhs(p, arg, tv, &lhs, &rhs); lb_emit_try_lhs_rhs(p, arg, tv, &lhs, &rhs);
@@ -479,7 +479,7 @@ lbValue lb_emit_or_return(lbProcedure *p, Ast *arg, TypeAndValue const &tv) {
} }
void lb_emit_increment(lbProcedure *p, lbValue addr) { gb_internal void lb_emit_increment(lbProcedure *p, lbValue addr) {
GB_ASSERT(is_type_pointer(addr.type)); GB_ASSERT(is_type_pointer(addr.type));
Type *type = type_deref(addr.type); Type *type = type_deref(addr.type);
lbValue v_one = lb_const_value(p->module, type, exact_value_i64(1)); lbValue v_one = lb_const_value(p->module, type, exact_value_i64(1));
@@ -487,7 +487,7 @@ void lb_emit_increment(lbProcedure *p, lbValue addr) {
} }
lbValue lb_emit_byte_swap(lbProcedure *p, lbValue value, Type *end_type) { gb_internal lbValue lb_emit_byte_swap(lbProcedure *p, lbValue value, Type *end_type) {
GB_ASSERT(type_size_of(value.type) == type_size_of(end_type)); GB_ASSERT(type_size_of(value.type) == type_size_of(end_type));
if (type_size_of(value.type) < 2) { if (type_size_of(value.type) < 2) {
@@ -526,7 +526,7 @@ lbValue lb_emit_byte_swap(lbProcedure *p, lbValue value, Type *end_type) {
lbValue lb_emit_count_ones(lbProcedure *p, lbValue x, Type *type) { gb_internal lbValue lb_emit_count_ones(lbProcedure *p, lbValue x, Type *type) {
x = lb_emit_conv(p, x, type); x = lb_emit_conv(p, x, type);
char const *name = "llvm.ctpop"; char const *name = "llvm.ctpop";
@@ -539,7 +539,7 @@ lbValue lb_emit_count_ones(lbProcedure *p, lbValue x, Type *type) {
return res; return res;
} }
lbValue lb_emit_count_zeros(lbProcedure *p, lbValue x, Type *type) { gb_internal lbValue lb_emit_count_zeros(lbProcedure *p, lbValue x, Type *type) {
Type *elem = base_array_type(type); Type *elem = base_array_type(type);
i64 sz = 8*type_size_of(elem); i64 sz = 8*type_size_of(elem);
lbValue size = lb_const_int(p->module, elem, cast(u64)sz); lbValue size = lb_const_int(p->module, elem, cast(u64)sz);
@@ -550,7 +550,7 @@ lbValue lb_emit_count_zeros(lbProcedure *p, lbValue x, Type *type) {
lbValue lb_emit_count_trailing_zeros(lbProcedure *p, lbValue x, Type *type) { gb_internal lbValue lb_emit_count_trailing_zeros(lbProcedure *p, lbValue x, Type *type) {
x = lb_emit_conv(p, x, type); x = lb_emit_conv(p, x, type);
char const *name = "llvm.cttz"; char const *name = "llvm.cttz";
@@ -566,7 +566,7 @@ lbValue lb_emit_count_trailing_zeros(lbProcedure *p, lbValue x, Type *type) {
return res; return res;
} }
lbValue lb_emit_count_leading_zeros(lbProcedure *p, lbValue x, Type *type) { gb_internal lbValue lb_emit_count_leading_zeros(lbProcedure *p, lbValue x, Type *type) {
x = lb_emit_conv(p, x, type); x = lb_emit_conv(p, x, type);
char const *name = "llvm.ctlz"; char const *name = "llvm.ctlz";
@@ -584,7 +584,7 @@ lbValue lb_emit_count_leading_zeros(lbProcedure *p, lbValue x, Type *type) {
lbValue lb_emit_reverse_bits(lbProcedure *p, lbValue x, Type *type) { gb_internal lbValue lb_emit_reverse_bits(lbProcedure *p, lbValue x, Type *type) {
x = lb_emit_conv(p, x, type); x = lb_emit_conv(p, x, type);
char const *name = "llvm.bitreverse"; char const *name = "llvm.bitreverse";
@@ -599,7 +599,7 @@ lbValue lb_emit_reverse_bits(lbProcedure *p, lbValue x, Type *type) {
} }
lbValue lb_emit_bit_set_card(lbProcedure *p, lbValue x) { gb_internal lbValue lb_emit_bit_set_card(lbProcedure *p, lbValue x) {
GB_ASSERT(is_type_bit_set(x.type)); GB_ASSERT(is_type_bit_set(x.type));
Type *underlying = bit_set_to_int(x.type); Type *underlying = bit_set_to_int(x.type);
lbValue card = lb_emit_count_ones(p, x, underlying); lbValue card = lb_emit_count_ones(p, x, underlying);
@@ -607,7 +607,7 @@ lbValue lb_emit_bit_set_card(lbProcedure *p, lbValue x) {
} }
lbValue lb_emit_union_cast_only_ok_check(lbProcedure *p, lbValue value, Type *type, TokenPos pos) { gb_internal lbValue lb_emit_union_cast_only_ok_check(lbProcedure *p, lbValue value, Type *type, TokenPos pos) {
GB_ASSERT(is_type_tuple(type)); GB_ASSERT(is_type_tuple(type));
lbModule *m = p->module; lbModule *m = p->module;
@@ -654,7 +654,7 @@ lbValue lb_emit_union_cast_only_ok_check(lbProcedure *p, lbValue value, Type *ty
return lb_addr_load(p, v); return lb_addr_load(p, v);
} }
lbValue lb_emit_union_cast(lbProcedure *p, lbValue value, Type *type, TokenPos pos) { gb_internal lbValue lb_emit_union_cast(lbProcedure *p, lbValue value, Type *type, TokenPos pos) {
lbModule *m = p->module; lbModule *m = p->module;
Type *src_type = value.type; Type *src_type = value.type;
@@ -753,7 +753,7 @@ lbValue lb_emit_union_cast(lbProcedure *p, lbValue value, Type *type, TokenPos p
return lb_addr_load(p, v); return lb_addr_load(p, v);
} }
lbAddr lb_emit_any_cast_addr(lbProcedure *p, lbValue value, Type *type, TokenPos pos) { gb_internal lbAddr lb_emit_any_cast_addr(lbProcedure *p, lbValue value, Type *type, TokenPos pos) {
lbModule *m = p->module; lbModule *m = p->module;
Type *src_type = value.type; Type *src_type = value.type;
@@ -826,13 +826,13 @@ lbAddr lb_emit_any_cast_addr(lbProcedure *p, lbValue value, Type *type, TokenPos
} }
return v; return v;
} }
lbValue lb_emit_any_cast(lbProcedure *p, lbValue value, Type *type, TokenPos pos) { gb_internal lbValue lb_emit_any_cast(lbProcedure *p, lbValue value, Type *type, TokenPos pos) {
return lb_addr_load(p, lb_emit_any_cast_addr(p, value, type, pos)); return lb_addr_load(p, lb_emit_any_cast_addr(p, value, type, pos));
} }
lbAddr lb_find_or_generate_context_ptr(lbProcedure *p) { gb_internal lbAddr lb_find_or_generate_context_ptr(lbProcedure *p) {
if (p->context_stack.count > 0) { if (p->context_stack.count > 0) {
return p->context_stack[p->context_stack.count-1].ctx; return p->context_stack[p->context_stack.count-1].ctx;
} }
@@ -850,7 +850,7 @@ lbAddr lb_find_or_generate_context_ptr(lbProcedure *p) {
return c; return c;
} }
lbValue lb_address_from_load_or_generate_local(lbProcedure *p, lbValue value) { gb_internal lbValue lb_address_from_load_or_generate_local(lbProcedure *p, lbValue value) {
if (LLVMIsALoadInst(value.value)) { if (LLVMIsALoadInst(value.value)) {
lbValue res = {}; lbValue res = {};
res.value = LLVMGetOperand(value.value, 0); res.value = LLVMGetOperand(value.value, 0);
@@ -864,7 +864,7 @@ lbValue lb_address_from_load_or_generate_local(lbProcedure *p, lbValue value) {
lb_addr_store(p, res, value); lb_addr_store(p, res, value);
return res.addr; return res.addr;
} }
lbValue lb_address_from_load(lbProcedure *p, lbValue value) { gb_internal lbValue lb_address_from_load(lbProcedure *p, lbValue value) {
if (LLVMIsALoadInst(value.value)) { if (LLVMIsALoadInst(value.value)) {
lbValue res = {}; lbValue res = {};
res.value = LLVMGetOperand(value.value, 0); res.value = LLVMGetOperand(value.value, 0);
@@ -877,7 +877,7 @@ lbValue lb_address_from_load(lbProcedure *p, lbValue value) {
} }
lbStructFieldRemapping lb_get_struct_remapping(lbModule *m, Type *t) { gb_internal lbStructFieldRemapping lb_get_struct_remapping(lbModule *m, Type *t) {
t = base_type(t); t = base_type(t);
LLVMTypeRef struct_type = lb_type(m, t); LLVMTypeRef struct_type = lb_type(m, t);
auto *field_remapping = map_get(&m->struct_field_remapping, cast(void *)struct_type); auto *field_remapping = map_get(&m->struct_field_remapping, cast(void *)struct_type);
@@ -888,7 +888,7 @@ lbStructFieldRemapping lb_get_struct_remapping(lbModule *m, Type *t) {
return *field_remapping; return *field_remapping;
} }
i32 lb_convert_struct_index(lbModule *m, Type *t, i32 index) { gb_internal i32 lb_convert_struct_index(lbModule *m, Type *t, i32 index) {
if (t->kind == Type_Struct) { if (t->kind == Type_Struct) {
auto field_remapping = lb_get_struct_remapping(m, t); auto field_remapping = lb_get_struct_remapping(m, t);
index = field_remapping[index]; index = field_remapping[index];
@@ -896,7 +896,7 @@ i32 lb_convert_struct_index(lbModule *m, Type *t, i32 index) {
return index; return index;
} }
LLVMTypeRef lb_type_padding_filler(lbModule *m, i64 padding, i64 padding_align) { gb_internal LLVMTypeRef lb_type_padding_filler(lbModule *m, i64 padding, i64 padding_align) {
// NOTE(bill): limit to `[N x u64]` to prevent ABI issues // NOTE(bill): limit to `[N x u64]` to prevent ABI issues
padding_align = gb_clamp(padding_align, 1, 8); padding_align = gb_clamp(padding_align, 1, 8);
if (padding % padding_align == 0) { if (padding % padding_align == 0) {
@@ -921,7 +921,7 @@ LLVMTypeRef lb_type_padding_filler(lbModule *m, i64 padding, i64 padding_align)
} }
char const *llvm_type_kinds[] = { gb_global char const *llvm_type_kinds[] = {
"LLVMVoidTypeKind", "LLVMVoidTypeKind",
"LLVMHalfTypeKind", "LLVMHalfTypeKind",
"LLVMFloatTypeKind", "LLVMFloatTypeKind",
@@ -973,7 +973,7 @@ gb_internal lbValue lb_emit_struct_ep_internal(lbProcedure *p, lbValue s, i32 in
} }
} }
lbValue lb_emit_tuple_ep(lbProcedure *p, lbValue ptr, i32 index) { gb_internal lbValue lb_emit_tuple_ep(lbProcedure *p, lbValue ptr, i32 index) {
Type *t = type_deref(ptr.type); Type *t = type_deref(ptr.type);
GB_ASSERT(is_type_tuple(t)); GB_ASSERT(is_type_tuple(t));
Type *result_type = t->Tuple.variables[index]->type; Type *result_type = t->Tuple.variables[index]->type;
@@ -991,7 +991,7 @@ lbValue lb_emit_tuple_ep(lbProcedure *p, lbValue ptr, i32 index) {
} }
lbValue lb_emit_struct_ep(lbProcedure *p, lbValue s, i32 index) { gb_internal lbValue lb_emit_struct_ep(lbProcedure *p, lbValue s, i32 index) {
GB_ASSERT(is_type_pointer(s.type)); GB_ASSERT(is_type_pointer(s.type));
Type *t = base_type(type_deref(s.type)); Type *t = base_type(type_deref(s.type));
Type *result_type = nullptr; Type *result_type = nullptr;
@@ -1074,7 +1074,7 @@ lbValue lb_emit_struct_ep(lbProcedure *p, lbValue s, i32 index) {
return lb_emit_struct_ep_internal(p, s, index, result_type); return lb_emit_struct_ep_internal(p, s, index, result_type);
} }
lbValue lb_emit_tuple_ev(lbProcedure *p, lbValue value, i32 index) { gb_internal lbValue lb_emit_tuple_ev(lbProcedure *p, lbValue value, i32 index) {
Type *t = value.type; Type *t = value.type;
GB_ASSERT(is_type_tuple(t)); GB_ASSERT(is_type_tuple(t));
Type *result_type = t->Tuple.variables[index]->type; Type *result_type = t->Tuple.variables[index]->type;
@@ -1104,7 +1104,7 @@ lbValue lb_emit_tuple_ev(lbProcedure *p, lbValue value, i32 index) {
return res; return res;
} }
lbValue lb_emit_struct_ev(lbProcedure *p, lbValue s, i32 index) { gb_internal lbValue lb_emit_struct_ev(lbProcedure *p, lbValue s, i32 index) {
Type *t = base_type(s.type); Type *t = base_type(s.type);
if (is_type_tuple(t)) { if (is_type_tuple(t)) {
return lb_emit_tuple_ev(p, s, index); return lb_emit_tuple_ev(p, s, index);
@@ -1223,7 +1223,7 @@ lbValue lb_emit_struct_ev(lbProcedure *p, lbValue s, i32 index) {
return res; return res;
} }
lbValue lb_emit_deep_field_gep(lbProcedure *p, lbValue e, Selection sel) { gb_internal lbValue lb_emit_deep_field_gep(lbProcedure *p, lbValue e, Selection sel) {
GB_ASSERT(sel.index.count > 0); GB_ASSERT(sel.index.count > 0);
Type *type = type_deref(e.type); Type *type = type_deref(e.type);
@@ -1311,14 +1311,14 @@ lbValue lb_emit_deep_field_gep(lbProcedure *p, lbValue e, Selection sel) {
} }
lbValue lb_emit_deep_field_ev(lbProcedure *p, lbValue e, Selection sel) { gb_internal lbValue lb_emit_deep_field_ev(lbProcedure *p, lbValue e, Selection sel) {
lbValue ptr = lb_address_from_load_or_generate_local(p, e); lbValue ptr = lb_address_from_load_or_generate_local(p, e);
lbValue res = lb_emit_deep_field_gep(p, ptr, sel); lbValue res = lb_emit_deep_field_gep(p, ptr, sel);
return lb_emit_load(p, res); return lb_emit_load(p, res);
} }
lbValue lb_emit_array_ep(lbProcedure *p, lbValue s, lbValue index) { gb_internal lbValue lb_emit_array_ep(lbProcedure *p, lbValue s, lbValue index) {
Type *t = s.type; Type *t = s.type;
GB_ASSERT_MSG(is_type_pointer(t), "%s", type_to_string(t)); GB_ASSERT_MSG(is_type_pointer(t), "%s", type_to_string(t));
Type *st = base_type(type_deref(t)); Type *st = base_type(type_deref(t));
@@ -1341,7 +1341,7 @@ lbValue lb_emit_array_ep(lbProcedure *p, lbValue s, lbValue index) {
return res; return res;
} }
lbValue lb_emit_array_epi(lbProcedure *p, lbValue s, isize index) { gb_internal lbValue lb_emit_array_epi(lbProcedure *p, lbValue s, isize index) {
Type *t = s.type; Type *t = s.type;
GB_ASSERT(is_type_pointer(t)); GB_ASSERT(is_type_pointer(t));
Type *st = base_type(type_deref(t)); Type *st = base_type(type_deref(t));
@@ -1349,7 +1349,7 @@ lbValue lb_emit_array_epi(lbProcedure *p, lbValue s, isize index) {
GB_ASSERT(0 <= index); GB_ASSERT(0 <= index);
return lb_emit_epi(p, s, index); return lb_emit_epi(p, s, index);
} }
lbValue lb_emit_array_epi(lbModule *m, lbValue s, isize index) { gb_internal lbValue lb_emit_array_epi(lbModule *m, lbValue s, isize index) {
Type *t = s.type; Type *t = s.type;
GB_ASSERT(is_type_pointer(t)); GB_ASSERT(is_type_pointer(t));
Type *st = base_type(type_deref(t)); Type *st = base_type(type_deref(t));
@@ -1358,7 +1358,7 @@ lbValue lb_emit_array_epi(lbModule *m, lbValue s, isize index) {
return lb_emit_epi(m, s, index); return lb_emit_epi(m, s, index);
} }
lbValue lb_emit_ptr_offset(lbProcedure *p, lbValue ptr, lbValue index) { gb_internal lbValue lb_emit_ptr_offset(lbProcedure *p, lbValue ptr, lbValue index) {
index = lb_emit_conv(p, index, t_int); index = lb_emit_conv(p, index, t_int);
LLVMValueRef indices[1] = {index.value}; LLVMValueRef indices[1] = {index.value};
lbValue res = {}; lbValue res = {};
@@ -1373,7 +1373,7 @@ lbValue lb_emit_ptr_offset(lbProcedure *p, lbValue ptr, lbValue index) {
return res; return res;
} }
lbValue lb_emit_matrix_epi(lbProcedure *p, lbValue s, isize row, isize column) { gb_internal lbValue lb_emit_matrix_epi(lbProcedure *p, lbValue s, isize row, isize column) {
Type *t = s.type; Type *t = s.type;
GB_ASSERT(is_type_pointer(t)); GB_ASSERT(is_type_pointer(t));
Type *mt = base_type(type_deref(t)); Type *mt = base_type(type_deref(t));
@@ -1391,7 +1391,7 @@ lbValue lb_emit_matrix_epi(lbProcedure *p, lbValue s, isize row, isize column) {
return lb_emit_epi(p, s, offset); return lb_emit_epi(p, s, offset);
} }
lbValue lb_emit_matrix_ep(lbProcedure *p, lbValue s, lbValue row, lbValue column) { gb_internal lbValue lb_emit_matrix_ep(lbProcedure *p, lbValue s, lbValue row, lbValue column) {
Type *t = s.type; Type *t = s.type;
GB_ASSERT(is_type_pointer(t)); GB_ASSERT(is_type_pointer(t));
Type *mt = base_type(type_deref(t)); Type *mt = base_type(type_deref(t));
@@ -1423,7 +1423,7 @@ lbValue lb_emit_matrix_ep(lbProcedure *p, lbValue s, lbValue row, lbValue column
} }
lbValue lb_emit_matrix_ev(lbProcedure *p, lbValue s, isize row, isize column) { gb_internal lbValue lb_emit_matrix_ev(lbProcedure *p, lbValue s, isize row, isize column) {
Type *st = base_type(s.type); Type *st = base_type(s.type);
GB_ASSERT_MSG(is_type_matrix(st), "%s", type_to_string(st)); GB_ASSERT_MSG(is_type_matrix(st), "%s", type_to_string(st));
@@ -1433,14 +1433,14 @@ lbValue lb_emit_matrix_ev(lbProcedure *p, lbValue s, isize row, isize column) {
} }
void lb_fill_slice(lbProcedure *p, lbAddr const &slice, lbValue base_elem, lbValue len) { gb_internal void lb_fill_slice(lbProcedure *p, lbAddr const &slice, lbValue base_elem, lbValue len) {
Type *t = lb_addr_type(slice); Type *t = lb_addr_type(slice);
GB_ASSERT(is_type_slice(t)); GB_ASSERT(is_type_slice(t));
lbValue ptr = lb_addr_get_ptr(p, slice); lbValue ptr = lb_addr_get_ptr(p, slice);
lb_emit_store(p, lb_emit_struct_ep(p, ptr, 0), base_elem); lb_emit_store(p, lb_emit_struct_ep(p, ptr, 0), base_elem);
lb_emit_store(p, lb_emit_struct_ep(p, ptr, 1), len); lb_emit_store(p, lb_emit_struct_ep(p, ptr, 1), len);
} }
void lb_fill_string(lbProcedure *p, lbAddr const &string, lbValue base_elem, lbValue len) { gb_internal void lb_fill_string(lbProcedure *p, lbAddr const &string, lbValue base_elem, lbValue len) {
Type *t = lb_addr_type(string); Type *t = lb_addr_type(string);
GB_ASSERT(is_type_string(t)); GB_ASSERT(is_type_string(t));
lbValue ptr = lb_addr_get_ptr(p, string); lbValue ptr = lb_addr_get_ptr(p, string);
@@ -1448,18 +1448,18 @@ void lb_fill_string(lbProcedure *p, lbAddr const &string, lbValue base_elem, lbV
lb_emit_store(p, lb_emit_struct_ep(p, ptr, 1), len); lb_emit_store(p, lb_emit_struct_ep(p, ptr, 1), len);
} }
lbValue lb_string_elem(lbProcedure *p, lbValue string) { gb_internal lbValue lb_string_elem(lbProcedure *p, lbValue string) {
Type *t = base_type(string.type); Type *t = base_type(string.type);
GB_ASSERT(t->kind == Type_Basic && t->Basic.kind == Basic_string); GB_ASSERT(t->kind == Type_Basic && t->Basic.kind == Basic_string);
return lb_emit_struct_ev(p, string, 0); return lb_emit_struct_ev(p, string, 0);
} }
lbValue lb_string_len(lbProcedure *p, lbValue string) { gb_internal lbValue lb_string_len(lbProcedure *p, lbValue string) {
Type *t = base_type(string.type); Type *t = base_type(string.type);
GB_ASSERT_MSG(t->kind == Type_Basic && t->Basic.kind == Basic_string, "%s", type_to_string(t)); GB_ASSERT_MSG(t->kind == Type_Basic && t->Basic.kind == Basic_string, "%s", type_to_string(t));
return lb_emit_struct_ev(p, string, 1); return lb_emit_struct_ev(p, string, 1);
} }
lbValue lb_cstring_len(lbProcedure *p, lbValue value) { gb_internal lbValue lb_cstring_len(lbProcedure *p, lbValue value) {
GB_ASSERT(is_type_cstring(value.type)); GB_ASSERT(is_type_cstring(value.type));
auto args = array_make<lbValue>(permanent_allocator(), 1); auto args = array_make<lbValue>(permanent_allocator(), 1);
args[0] = lb_emit_conv(p, value, t_cstring); args[0] = lb_emit_conv(p, value, t_cstring);
@@ -1467,43 +1467,43 @@ lbValue lb_cstring_len(lbProcedure *p, lbValue value) {
} }
lbValue lb_array_elem(lbProcedure *p, lbValue array_ptr) { gb_internal lbValue lb_array_elem(lbProcedure *p, lbValue array_ptr) {
Type *t = type_deref(array_ptr.type); Type *t = type_deref(array_ptr.type);
GB_ASSERT(is_type_array(t)); GB_ASSERT(is_type_array(t));
return lb_emit_struct_ep(p, array_ptr, 0); return lb_emit_struct_ep(p, array_ptr, 0);
} }
lbValue lb_slice_elem(lbProcedure *p, lbValue slice) { gb_internal lbValue lb_slice_elem(lbProcedure *p, lbValue slice) {
GB_ASSERT(is_type_slice(slice.type)); GB_ASSERT(is_type_slice(slice.type));
return lb_emit_struct_ev(p, slice, 0); return lb_emit_struct_ev(p, slice, 0);
} }
lbValue lb_slice_len(lbProcedure *p, lbValue slice) { gb_internal lbValue lb_slice_len(lbProcedure *p, lbValue slice) {
GB_ASSERT(is_type_slice(slice.type) || is_type_relative_slice(slice.type)); GB_ASSERT(is_type_slice(slice.type) || is_type_relative_slice(slice.type));
return lb_emit_struct_ev(p, slice, 1); return lb_emit_struct_ev(p, slice, 1);
} }
lbValue lb_dynamic_array_elem(lbProcedure *p, lbValue da) { gb_internal lbValue lb_dynamic_array_elem(lbProcedure *p, lbValue da) {
GB_ASSERT(is_type_dynamic_array(da.type)); GB_ASSERT(is_type_dynamic_array(da.type));
return lb_emit_struct_ev(p, da, 0); return lb_emit_struct_ev(p, da, 0);
} }
lbValue lb_dynamic_array_len(lbProcedure *p, lbValue da) { gb_internal lbValue lb_dynamic_array_len(lbProcedure *p, lbValue da) {
GB_ASSERT(is_type_dynamic_array(da.type)); GB_ASSERT(is_type_dynamic_array(da.type));
return lb_emit_struct_ev(p, da, 1); return lb_emit_struct_ev(p, da, 1);
} }
lbValue lb_dynamic_array_cap(lbProcedure *p, lbValue da) { gb_internal lbValue lb_dynamic_array_cap(lbProcedure *p, lbValue da) {
GB_ASSERT(is_type_dynamic_array(da.type)); GB_ASSERT(is_type_dynamic_array(da.type));
return lb_emit_struct_ev(p, da, 2); return lb_emit_struct_ev(p, da, 2);
} }
lbValue lb_dynamic_array_allocator(lbProcedure *p, lbValue da) { gb_internal lbValue lb_dynamic_array_allocator(lbProcedure *p, lbValue da) {
GB_ASSERT(is_type_dynamic_array(da.type)); GB_ASSERT(is_type_dynamic_array(da.type));
return lb_emit_struct_ev(p, da, 3); return lb_emit_struct_ev(p, da, 3);
} }
lbValue lb_map_len(lbProcedure *p, lbValue value) { gb_internal lbValue lb_map_len(lbProcedure *p, lbValue value) {
GB_ASSERT_MSG(is_type_map(value.type) || are_types_identical(value.type, t_raw_map), "%s", type_to_string(value.type)); GB_ASSERT_MSG(is_type_map(value.type) || are_types_identical(value.type, t_raw_map), "%s", type_to_string(value.type));
lbValue len = lb_emit_struct_ev(p, value, 1); lbValue len = lb_emit_struct_ev(p, value, 1);
return lb_emit_conv(p, len, t_int); return lb_emit_conv(p, len, t_int);
} }
lbValue lb_map_len_ptr(lbProcedure *p, lbValue map_ptr) { gb_internal lbValue lb_map_len_ptr(lbProcedure *p, lbValue map_ptr) {
Type *type = map_ptr.type; Type *type = map_ptr.type;
GB_ASSERT(is_type_pointer(type)); GB_ASSERT(is_type_pointer(type));
type = type_deref(type); type = type_deref(type);
@@ -1511,7 +1511,7 @@ lbValue lb_map_len_ptr(lbProcedure *p, lbValue map_ptr) {
return lb_emit_struct_ep(p, map_ptr, 1); return lb_emit_struct_ep(p, map_ptr, 1);
} }
lbValue lb_map_cap(lbProcedure *p, lbValue value) { gb_internal lbValue lb_map_cap(lbProcedure *p, lbValue value) {
GB_ASSERT_MSG(is_type_map(value.type) || are_types_identical(value.type, t_raw_map), "%s", type_to_string(value.type)); GB_ASSERT_MSG(is_type_map(value.type) || are_types_identical(value.type, t_raw_map), "%s", type_to_string(value.type));
lbValue zero = lb_const_int(p->module, t_uintptr, 0); lbValue zero = lb_const_int(p->module, t_uintptr, 0);
lbValue one = lb_const_int(p->module, t_uintptr, 1); lbValue one = lb_const_int(p->module, t_uintptr, 1);
@@ -1525,7 +1525,7 @@ lbValue lb_map_cap(lbProcedure *p, lbValue value) {
return lb_emit_conv(p, lb_emit_select(p, cmp, zero, cap), t_int); return lb_emit_conv(p, lb_emit_select(p, cmp, zero, cap), t_int);
} }
lbValue lb_map_data_uintptr(lbProcedure *p, lbValue value) { gb_internal lbValue lb_map_data_uintptr(lbProcedure *p, lbValue value) {
GB_ASSERT(is_type_map(value.type) || are_types_identical(value.type, t_raw_map)); GB_ASSERT(is_type_map(value.type) || are_types_identical(value.type, t_raw_map));
lbValue data = lb_emit_struct_ev(p, value, 0); lbValue data = lb_emit_struct_ev(p, value, 0);
u64 mask_value = 0; u64 mask_value = 0;
@@ -1539,7 +1539,7 @@ lbValue lb_map_data_uintptr(lbProcedure *p, lbValue value) {
} }
lbValue lb_soa_struct_len(lbProcedure *p, lbValue value) { gb_internal lbValue lb_soa_struct_len(lbProcedure *p, lbValue value) {
Type *t = base_type(value.type); Type *t = base_type(value.type);
bool is_ptr = false; bool is_ptr = false;
if (is_type_pointer(t)) { if (is_type_pointer(t)) {
@@ -1572,7 +1572,7 @@ lbValue lb_soa_struct_len(lbProcedure *p, lbValue value) {
return lb_emit_struct_ev(p, value, cast(i32)n); return lb_emit_struct_ev(p, value, cast(i32)n);
} }
lbValue lb_soa_struct_cap(lbProcedure *p, lbValue value) { gb_internal lbValue lb_soa_struct_cap(lbProcedure *p, lbValue value) {
Type *t = base_type(value.type); Type *t = base_type(value.type);
bool is_ptr = false; bool is_ptr = false;
@@ -1604,7 +1604,7 @@ lbValue lb_soa_struct_cap(lbProcedure *p, lbValue value) {
return lb_emit_struct_ev(p, value, cast(i32)n); return lb_emit_struct_ev(p, value, cast(i32)n);
} }
lbValue lb_emit_mul_add(lbProcedure *p, lbValue a, lbValue b, lbValue c, Type *t) { gb_internal lbValue lb_emit_mul_add(lbProcedure *p, lbValue a, lbValue b, lbValue c, Type *t) {
lbModule *m = p->module; lbModule *m = p->module;
a = lb_emit_conv(p, a, t); a = lb_emit_conv(p, a, t);
@@ -1647,7 +1647,7 @@ lbValue lb_emit_mul_add(lbProcedure *p, lbValue a, lbValue b, lbValue c, Type *t
} }
} }
LLVMValueRef llvm_mask_iota(lbModule *m, unsigned start, unsigned count) { gb_internal LLVMValueRef llvm_mask_iota(lbModule *m, unsigned start, unsigned count) {
auto iota = slice_make<LLVMValueRef>(temporary_allocator(), count); auto iota = slice_make<LLVMValueRef>(temporary_allocator(), count);
for (unsigned i = 0; i < count; i++) { for (unsigned i = 0; i < count; i++) {
iota[i] = lb_const_int(m, t_u32, start+i).value; iota[i] = lb_const_int(m, t_u32, start+i).value;
@@ -1655,7 +1655,7 @@ LLVMValueRef llvm_mask_iota(lbModule *m, unsigned start, unsigned count) {
return LLVMConstVector(iota.data, count); return LLVMConstVector(iota.data, count);
} }
LLVMValueRef llvm_mask_zero(lbModule *m, unsigned count) { gb_internal LLVMValueRef llvm_mask_zero(lbModule *m, unsigned count) {
return LLVMConstNull(LLVMVectorType(lb_type(m, t_u32), count)); return LLVMConstNull(LLVMVectorType(lb_type(m, t_u32), count));
} }
@@ -1663,16 +1663,16 @@ LLVMValueRef llvm_mask_zero(lbModule *m, unsigned count) {
// #define LLVM_VECTOR_DUMMY_VALUE(type) LLVMConstNull((type)) // #define LLVM_VECTOR_DUMMY_VALUE(type) LLVMConstNull((type))
LLVMValueRef llvm_basic_shuffle(lbProcedure *p, LLVMValueRef vector, LLVMValueRef mask) { gb_internal LLVMValueRef llvm_basic_shuffle(lbProcedure *p, LLVMValueRef vector, LLVMValueRef mask) {
return LLVMBuildShuffleVector(p->builder, vector, LLVM_VECTOR_DUMMY_VALUE(LLVMTypeOf(vector)), mask, ""); return LLVMBuildShuffleVector(p->builder, vector, LLVM_VECTOR_DUMMY_VALUE(LLVMTypeOf(vector)), mask, "");
} }
LLVMValueRef llvm_basic_const_shuffle(LLVMValueRef vector, LLVMValueRef mask) { gb_internal LLVMValueRef llvm_basic_const_shuffle(LLVMValueRef vector, LLVMValueRef mask) {
return LLVMConstShuffleVector(vector, LLVM_VECTOR_DUMMY_VALUE(LLVMTypeOf(vector)), mask); return LLVMConstShuffleVector(vector, LLVM_VECTOR_DUMMY_VALUE(LLVMTypeOf(vector)), mask);
} }
LLVMValueRef llvm_vector_broadcast(lbProcedure *p, LLVMValueRef value, unsigned count) { gb_internal LLVMValueRef llvm_vector_broadcast(lbProcedure *p, LLVMValueRef value, unsigned count) {
GB_ASSERT(count > 0); GB_ASSERT(count > 0);
if (LLVMIsConstant(value)) { if (LLVMIsConstant(value)) {
LLVMValueRef single = LLVMConstVector(&value, 1); LLVMValueRef single = LLVMConstVector(&value, 1);
@@ -1692,7 +1692,7 @@ LLVMValueRef llvm_vector_broadcast(lbProcedure *p, LLVMValueRef value, unsigned
return llvm_basic_shuffle(p, single, mask); return llvm_basic_shuffle(p, single, mask);
} }
LLVMValueRef llvm_vector_shuffle_reduction(lbProcedure *p, LLVMValueRef value, LLVMOpcode op_code) { gb_internal LLVMValueRef llvm_vector_shuffle_reduction(lbProcedure *p, LLVMValueRef value, LLVMOpcode op_code) {
LLVMTypeRef original_vector_type = LLVMTypeOf(value); LLVMTypeRef original_vector_type = LLVMTypeOf(value);
GB_ASSERT(LLVMGetTypeKind(original_vector_type) == LLVMVectorTypeKind); GB_ASSERT(LLVMGetTypeKind(original_vector_type) == LLVMVectorTypeKind);
@@ -1719,7 +1719,7 @@ LLVMValueRef llvm_vector_shuffle_reduction(lbProcedure *p, LLVMValueRef value, L
return LLVMBuildExtractElement(p->builder, value, v_zero32, ""); return LLVMBuildExtractElement(p->builder, value, v_zero32, "");
} }
LLVMValueRef llvm_vector_expand_to_power_of_two(lbProcedure *p, LLVMValueRef value) { gb_internal LLVMValueRef llvm_vector_expand_to_power_of_two(lbProcedure *p, LLVMValueRef value) {
LLVMTypeRef vector_type = LLVMTypeOf(value); LLVMTypeRef vector_type = LLVMTypeOf(value);
unsigned len = LLVMGetVectorSize(vector_type); unsigned len = LLVMGetVectorSize(vector_type);
if (len == 1) { if (len == 1) {
@@ -1734,7 +1734,7 @@ LLVMValueRef llvm_vector_expand_to_power_of_two(lbProcedure *p, LLVMValueRef val
return LLVMBuildShuffleVector(p->builder, value, LLVMConstNull(vector_type), mask, ""); return LLVMBuildShuffleVector(p->builder, value, LLVMConstNull(vector_type), mask, "");
} }
LLVMValueRef llvm_vector_reduce_add(lbProcedure *p, LLVMValueRef value) { gb_internal LLVMValueRef llvm_vector_reduce_add(lbProcedure *p, LLVMValueRef value) {
LLVMTypeRef type = LLVMTypeOf(value); LLVMTypeRef type = LLVMTypeOf(value);
GB_ASSERT(LLVMGetTypeKind(type) == LLVMVectorTypeKind); GB_ASSERT(LLVMGetTypeKind(type) == LLVMVectorTypeKind);
LLVMTypeRef elem = OdinLLVMGetVectorElementType(type); LLVMTypeRef elem = OdinLLVMGetVectorElementType(type);
@@ -1810,7 +1810,7 @@ LLVMValueRef llvm_vector_reduce_add(lbProcedure *p, LLVMValueRef value) {
#endif #endif
} }
LLVMValueRef llvm_vector_add(lbProcedure *p, LLVMValueRef a, LLVMValueRef b) { gb_internal LLVMValueRef llvm_vector_add(lbProcedure *p, LLVMValueRef a, LLVMValueRef b) {
GB_ASSERT(LLVMTypeOf(a) == LLVMTypeOf(b)); GB_ASSERT(LLVMTypeOf(a) == LLVMTypeOf(b));
LLVMTypeRef elem = OdinLLVMGetVectorElementType(LLVMTypeOf(a)); LLVMTypeRef elem = OdinLLVMGetVectorElementType(LLVMTypeOf(a));
@@ -1821,7 +1821,7 @@ LLVMValueRef llvm_vector_add(lbProcedure *p, LLVMValueRef a, LLVMValueRef b) {
return LLVMBuildFAdd(p->builder, a, b, ""); return LLVMBuildFAdd(p->builder, a, b, "");
} }
LLVMValueRef llvm_vector_mul(lbProcedure *p, LLVMValueRef a, LLVMValueRef b) { gb_internal LLVMValueRef llvm_vector_mul(lbProcedure *p, LLVMValueRef a, LLVMValueRef b) {
GB_ASSERT(LLVMTypeOf(a) == LLVMTypeOf(b)); GB_ASSERT(LLVMTypeOf(a) == LLVMTypeOf(b));
LLVMTypeRef elem = OdinLLVMGetVectorElementType(LLVMTypeOf(a)); LLVMTypeRef elem = OdinLLVMGetVectorElementType(LLVMTypeOf(a));
@@ -1833,11 +1833,11 @@ LLVMValueRef llvm_vector_mul(lbProcedure *p, LLVMValueRef a, LLVMValueRef b) {
} }
LLVMValueRef llvm_vector_dot(lbProcedure *p, LLVMValueRef a, LLVMValueRef b) { gb_internal LLVMValueRef llvm_vector_dot(lbProcedure *p, LLVMValueRef a, LLVMValueRef b) {
return llvm_vector_reduce_add(p, llvm_vector_mul(p, a, b)); return llvm_vector_reduce_add(p, llvm_vector_mul(p, a, b));
} }
LLVMValueRef llvm_vector_mul_add(lbProcedure *p, LLVMValueRef a, LLVMValueRef b, LLVMValueRef c) { gb_internal LLVMValueRef llvm_vector_mul_add(lbProcedure *p, LLVMValueRef a, LLVMValueRef b, LLVMValueRef c) {
LLVMTypeRef t = LLVMTypeOf(a); LLVMTypeRef t = LLVMTypeOf(a);
GB_ASSERT(t == LLVMTypeOf(b)); GB_ASSERT(t == LLVMTypeOf(b));
@@ -1871,7 +1871,7 @@ LLVMValueRef llvm_vector_mul_add(lbProcedure *p, LLVMValueRef a, LLVMValueRef b,
} }
} }
LLVMValueRef llvm_get_inline_asm(LLVMTypeRef func_type, String const &str, String const &clobbers, bool has_side_effects=true, bool is_align_stack=false, LLVMInlineAsmDialect dialect=LLVMInlineAsmDialectATT) { gb_internal LLVMValueRef llvm_get_inline_asm(LLVMTypeRef func_type, String const &str, String const &clobbers, bool has_side_effects=true, bool is_align_stack=false, LLVMInlineAsmDialect dialect=LLVMInlineAsmDialectATT) {
return LLVMGetInlineAsm(func_type, return LLVMGetInlineAsm(func_type,
cast(char *)str.text, cast(size_t)str.len, cast(char *)str.text, cast(size_t)str.len,
cast(char *)clobbers.text, cast(size_t)clobbers.len, cast(char *)clobbers.text, cast(size_t)clobbers.len,
@@ -1884,7 +1884,7 @@ LLVMValueRef llvm_get_inline_asm(LLVMTypeRef func_type, String const &str, Strin
} }
void lb_set_wasm_import_attributes(LLVMValueRef value, Entity *entity, String import_name) { gb_internal void lb_set_wasm_import_attributes(LLVMValueRef value, Entity *entity, String import_name) {
if (!is_arch_wasm()) { if (!is_arch_wasm()) {
return; return;
} }
@@ -1906,7 +1906,7 @@ void lb_set_wasm_import_attributes(LLVMValueRef value, Entity *entity, String im
} }
void lb_set_wasm_export_attributes(LLVMValueRef value, String export_name) { gb_internal void lb_set_wasm_export_attributes(LLVMValueRef value, String export_name) {
if (!is_arch_wasm()) { if (!is_arch_wasm()) {
return; return;
} }
@@ -1918,7 +1918,7 @@ void lb_set_wasm_export_attributes(LLVMValueRef value, String export_name) {
lbAddr lb_handle_objc_find_or_register_selector(lbProcedure *p, String const &name) { gb_internal lbAddr lb_handle_objc_find_or_register_selector(lbProcedure *p, String const &name) {
lbAddr *found = string_map_get(&p->module->objc_selectors, name); lbAddr *found = string_map_get(&p->module->objc_selectors, name);
if (found) { if (found) {
return *found; return *found;
@@ -1938,7 +1938,7 @@ lbAddr lb_handle_objc_find_or_register_selector(lbProcedure *p, String const &na
} }
} }
lbValue lb_handle_objc_find_selector(lbProcedure *p, Ast *expr) { gb_internal lbValue lb_handle_objc_find_selector(lbProcedure *p, Ast *expr) {
ast_node(ce, CallExpr, expr); ast_node(ce, CallExpr, expr);
auto tav = ce->args[0]->tav; auto tav = ce->args[0]->tav;
@@ -1947,7 +1947,7 @@ lbValue lb_handle_objc_find_selector(lbProcedure *p, Ast *expr) {
return lb_addr_load(p, lb_handle_objc_find_or_register_selector(p, name)); return lb_addr_load(p, lb_handle_objc_find_or_register_selector(p, name));
} }
lbValue lb_handle_objc_register_selector(lbProcedure *p, Ast *expr) { gb_internal lbValue lb_handle_objc_register_selector(lbProcedure *p, Ast *expr) {
ast_node(ce, CallExpr, expr); ast_node(ce, CallExpr, expr);
lbModule *m = p->module; lbModule *m = p->module;
@@ -1964,7 +1964,7 @@ lbValue lb_handle_objc_register_selector(lbProcedure *p, Ast *expr) {
return lb_addr_load(p, dst); return lb_addr_load(p, dst);
} }
lbAddr lb_handle_objc_find_or_register_class(lbProcedure *p, String const &name) { gb_internal lbAddr lb_handle_objc_find_or_register_class(lbProcedure *p, String const &name) {
lbAddr *found = string_map_get(&p->module->objc_classes, name); lbAddr *found = string_map_get(&p->module->objc_classes, name);
if (found) { if (found) {
return *found; return *found;
@@ -1984,7 +1984,7 @@ lbAddr lb_handle_objc_find_or_register_class(lbProcedure *p, String const &name)
} }
} }
lbValue lb_handle_objc_find_class(lbProcedure *p, Ast *expr) { gb_internal lbValue lb_handle_objc_find_class(lbProcedure *p, Ast *expr) {
ast_node(ce, CallExpr, expr); ast_node(ce, CallExpr, expr);
auto tav = ce->args[0]->tav; auto tav = ce->args[0]->tav;
@@ -1993,7 +1993,7 @@ lbValue lb_handle_objc_find_class(lbProcedure *p, Ast *expr) {
return lb_addr_load(p, lb_handle_objc_find_or_register_class(p, name)); return lb_addr_load(p, lb_handle_objc_find_or_register_class(p, name));
} }
lbValue lb_handle_objc_register_class(lbProcedure *p, Ast *expr) { gb_internal lbValue lb_handle_objc_register_class(lbProcedure *p, Ast *expr) {
ast_node(ce, CallExpr, expr); ast_node(ce, CallExpr, expr);
lbModule *m = p->module; lbModule *m = p->module;
@@ -2013,7 +2013,7 @@ lbValue lb_handle_objc_register_class(lbProcedure *p, Ast *expr) {
} }
lbValue lb_handle_objc_id(lbProcedure *p, Ast *expr) { gb_internal lbValue lb_handle_objc_id(lbProcedure *p, Ast *expr) {
TypeAndValue const &tav = type_and_value_of_expr(expr); TypeAndValue const &tav = type_and_value_of_expr(expr);
if (tav.mode == Addressing_Type) { if (tav.mode == Addressing_Type) {
Type *type = tav.type; Type *type = tav.type;
@@ -2044,7 +2044,7 @@ lbValue lb_handle_objc_id(lbProcedure *p, Ast *expr) {
return lb_build_expr(p, expr); return lb_build_expr(p, expr);
} }
lbValue lb_handle_objc_send(lbProcedure *p, Ast *expr) { gb_internal lbValue lb_handle_objc_send(lbProcedure *p, Ast *expr) {
ast_node(ce, CallExpr, expr); ast_node(ce, CallExpr, expr);
lbModule *m = p->module; lbModule *m = p->module;
@@ -2087,7 +2087,7 @@ lbValue lb_handle_objc_send(lbProcedure *p, Ast *expr) {
LLVMAtomicOrdering llvm_atomic_ordering_from_odin(ExactValue const &value) { gb_internal LLVMAtomicOrdering llvm_atomic_ordering_from_odin(ExactValue const &value) {
GB_ASSERT(value.kind == ExactValue_Integer); GB_ASSERT(value.kind == ExactValue_Integer);
i64 v = exact_value_to_i64(value); i64 v = exact_value_to_i64(value);
switch (v) { switch (v) {
@@ -2103,7 +2103,7 @@ LLVMAtomicOrdering llvm_atomic_ordering_from_odin(ExactValue const &value) {
} }
LLVMAtomicOrdering llvm_atomic_ordering_from_odin(Ast *expr) { gb_internal LLVMAtomicOrdering llvm_atomic_ordering_from_odin(Ast *expr) {
ExactValue value = type_and_value_of_expr(expr).value; ExactValue value = type_and_value_of_expr(expr).value;
return llvm_atomic_ordering_from_odin(value); return llvm_atomic_ordering_from_odin(value);
} }