mirror of
https://github.com/odin-lang/Odin.git
synced 2026-01-05 20:48:04 +00:00
Merge branch 'odin-lang:master' into haiku
This commit is contained in:
@@ -1053,41 +1053,6 @@ struct lbGlobalVariable {
|
||||
bool is_initialized;
|
||||
};
|
||||
|
||||
gb_internal lbProcedure *lb_create_startup_type_info(lbModule *m) {
|
||||
if (build_context.no_rtti) {
|
||||
return nullptr;
|
||||
}
|
||||
Type *proc_type = alloc_type_proc(nullptr, nullptr, 0, nullptr, 0, false, ProcCC_CDecl);
|
||||
|
||||
lbProcedure *p = lb_create_dummy_procedure(m, str_lit(LB_STARTUP_TYPE_INFO_PROC_NAME), proc_type);
|
||||
p->is_startup = true;
|
||||
LLVMSetLinkage(p->value, LLVMInternalLinkage);
|
||||
|
||||
lb_add_attribute_to_proc(m, p->value, "nounwind");
|
||||
// lb_add_attribute_to_proc(p->module, p->value, "mustprogress");
|
||||
// lb_add_attribute_to_proc(p->module, p->value, "nofree");
|
||||
// lb_add_attribute_to_proc(p->module, p->value, "norecurse");
|
||||
// lb_add_attribute_to_proc(p->module, p->value, "nosync");
|
||||
// lb_add_attribute_to_proc(p->module, p->value, "willreturn");
|
||||
if (!LB_USE_GIANT_PACKED_STRUCT) {
|
||||
lb_add_attribute_to_proc(m, p->value, "optnone");
|
||||
lb_add_attribute_to_proc(m, p->value, "noinline");
|
||||
}
|
||||
|
||||
lb_begin_procedure_body(p);
|
||||
|
||||
lb_setup_type_info_data(p);
|
||||
|
||||
lb_end_procedure_body(p);
|
||||
|
||||
if (!m->debug_builder && LLVMVerifyFunction(p->value, LLVMReturnStatusAction)) {
|
||||
gb_printf_err("LLVM CODE GEN FAILED FOR PROCEDURE: %s\n", "main");
|
||||
LLVMDumpValue(p->value);
|
||||
gb_printf_err("\n\n\n\n");
|
||||
LLVMVerifyFunction(p->value, LLVMAbortProcessAction);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
gb_internal lbProcedure *lb_create_objc_names(lbModule *main_module) {
|
||||
if (build_context.metrics.os != TargetOs_darwin) {
|
||||
@@ -1129,7 +1094,7 @@ gb_internal void lb_finalize_objc_names(lbProcedure *p) {
|
||||
lb_end_procedure_body(p);
|
||||
}
|
||||
|
||||
gb_internal 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 *objc_names, Array<lbGlobalVariable> &global_variables) { // Startup Runtime
|
||||
Type *proc_type = alloc_type_proc(nullptr, nullptr, 0, nullptr, 0, false, ProcCC_Odin);
|
||||
|
||||
lbProcedure *p = lb_create_dummy_procedure(main_module, str_lit(LB_STARTUP_RUNTIME_PROC_NAME), proc_type);
|
||||
@@ -1139,9 +1104,7 @@ gb_internal lbProcedure *lb_create_startup_runtime(lbModule *main_module, lbProc
|
||||
|
||||
lb_begin_procedure_body(p);
|
||||
|
||||
if (startup_type_info) {
|
||||
LLVMBuildCall2(p->builder, lb_type_internal_for_procedures_raw(main_module, startup_type_info->type), startup_type_info->value, nullptr, 0, "");
|
||||
}
|
||||
lb_setup_type_info_data(main_module);
|
||||
|
||||
if (objc_names) {
|
||||
LLVMBuildCall2(p->builder, lb_type_internal_for_procedures_raw(main_module, objc_names->type), objc_names->value, nullptr, 0, "");
|
||||
@@ -1201,7 +1164,7 @@ gb_internal lbProcedure *lb_create_startup_runtime(lbModule *main_module, lbProc
|
||||
lbValue data = lb_emit_struct_ep(p, var.var, 0);
|
||||
lbValue ti = lb_emit_struct_ep(p, var.var, 1);
|
||||
lb_emit_store(p, data, lb_emit_conv(p, gp, t_rawptr));
|
||||
lb_emit_store(p, ti, lb_type_info(main_module, var_type));
|
||||
lb_emit_store(p, ti, lb_type_info(p, var_type));
|
||||
} else {
|
||||
LLVMTypeRef vt = llvm_addr_type(p->module, var.var);
|
||||
lbValue src0 = lb_emit_conv(p, var.init, t);
|
||||
@@ -1426,7 +1389,6 @@ gb_internal WORKER_TASK_PROC(lb_llvm_function_pass_per_module) {
|
||||
}
|
||||
|
||||
if (m == &m->gen->default_module) {
|
||||
lb_llvm_function_pass_per_function_internal(m, m->gen->startup_type_info);
|
||||
lb_llvm_function_pass_per_function_internal(m, m->gen->startup_runtime);
|
||||
lb_llvm_function_pass_per_function_internal(m, m->gen->cleanup_runtime);
|
||||
lb_llvm_function_pass_per_function_internal(m, m->gen->objc_names);
|
||||
@@ -2691,17 +2653,19 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
|
||||
|
||||
{ // Add type info data
|
||||
isize max_type_info_count = info->minimum_dependency_type_info_set.count+1;
|
||||
Type *t = alloc_type_array(t_type_info, max_type_info_count);
|
||||
Type *t = alloc_type_array(t_type_info_ptr, max_type_info_count);
|
||||
|
||||
// IMPORTANT NOTE(bill): As LLVM does not have a union type, an array of unions cannot be initialized
|
||||
// at compile time without cheating in some way. This means to emulate an array of unions is to use
|
||||
// a giant packed struct of "corrected" data types.
|
||||
|
||||
LLVMTypeRef internal_llvm_type = lb_setup_type_info_data_internal_type(m, max_type_info_count);
|
||||
LLVMTypeRef internal_llvm_type = lb_type(m, t);
|
||||
|
||||
LLVMValueRef g = LLVMAddGlobal(m->mod, internal_llvm_type, LB_TYPE_INFO_DATA_NAME);
|
||||
LLVMSetInitializer(g, LLVMConstNull(internal_llvm_type));
|
||||
LLVMSetLinkage(g, USE_SEPARATE_MODULES ? LLVMExternalLinkage : LLVMInternalLinkage);
|
||||
LLVMSetUnnamedAddress(g, LLVMGlobalUnnamedAddr);
|
||||
LLVMSetGlobalConstant(g, /*true*/false);
|
||||
|
||||
lbValue value = {};
|
||||
value.value = g;
|
||||
@@ -2710,11 +2674,6 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
|
||||
lb_global_type_info_data_entity = alloc_entity_variable(nullptr, make_token_ident(LB_TYPE_INFO_DATA_NAME), t, EntityState_Resolved);
|
||||
lb_add_entity(m, lb_global_type_info_data_entity, value);
|
||||
|
||||
if (LB_USE_GIANT_PACKED_STRUCT) {
|
||||
LLVMSetLinkage(g, LLVMPrivateLinkage);
|
||||
LLVMSetUnnamedAddress(g, LLVMGlobalUnnamedAddr);
|
||||
LLVMSetGlobalConstant(g, /*true*/false);
|
||||
}
|
||||
}
|
||||
{ // Type info member buffer
|
||||
// NOTE(bill): Removes need for heap allocation by making it global memory
|
||||
@@ -2750,9 +2709,7 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
|
||||
LLVMValueRef g = LLVMAddGlobal(m->mod, lb_type(m, t), name);
|
||||
LLVMSetInitializer(g, LLVMConstNull(lb_type(m, t)));
|
||||
LLVMSetLinkage(g, LLVMInternalLinkage);
|
||||
if (LB_USE_GIANT_PACKED_STRUCT) {
|
||||
lb_make_global_private_const(g);
|
||||
}
|
||||
lb_make_global_private_const(g);
|
||||
return lb_addr({g, alloc_type_pointer(t)});
|
||||
};
|
||||
|
||||
@@ -2921,12 +2878,11 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
|
||||
}
|
||||
}
|
||||
|
||||
TIME_SECTION("LLVM Runtime Type Information Creation");
|
||||
gen->startup_type_info = lb_create_startup_type_info(default_module);
|
||||
TIME_SECTION("LLVM Runtime Objective-C Names Creation");
|
||||
gen->objc_names = lb_create_objc_names(default_module);
|
||||
|
||||
TIME_SECTION("LLVM Runtime Startup Creation (Global Variables & @(init))");
|
||||
gen->startup_runtime = lb_create_startup_runtime(default_module, gen->startup_type_info, gen->objc_names, global_variables);
|
||||
gen->startup_runtime = lb_create_startup_runtime(default_module, gen->objc_names, global_variables);
|
||||
|
||||
TIME_SECTION("LLVM Runtime Cleanup Creation & @(fini)");
|
||||
gen->cleanup_runtime = lb_create_cleanup_runtime(default_module);
|
||||
|
||||
@@ -225,7 +225,6 @@ struct lbGenerator : LinkerData {
|
||||
std::atomic<u32> global_array_index;
|
||||
std::atomic<u32> global_generated_index;
|
||||
|
||||
lbProcedure *startup_type_info;
|
||||
lbProcedure *startup_runtime;
|
||||
lbProcedure *cleanup_runtime;
|
||||
lbProcedure *objc_names;
|
||||
@@ -486,7 +485,7 @@ gb_internal lbValue lb_emit_mul_add(lbProcedure *p, lbValue a, lbValue b, lbValu
|
||||
|
||||
gb_internal void lb_fill_slice(lbProcedure *p, lbAddr const &slice, lbValue base_elem, lbValue len);
|
||||
|
||||
gb_internal lbValue lb_type_info(lbModule *m, Type *type);
|
||||
gb_internal lbValue lb_type_info(lbProcedure *p, Type *type);
|
||||
|
||||
gb_internal lbValue lb_find_or_add_entity_string(lbModule *m, String const &str);
|
||||
gb_internal lbValue lb_generate_anonymous_proc_lit(lbModule *m, String const &prefix_name, Ast *expr, lbProcedure *parent = nullptr);
|
||||
@@ -587,7 +586,6 @@ gb_internal LLVMTypeRef llvm_array_type(LLVMTypeRef ElementType, uint64_t Elemen
|
||||
|
||||
#define LB_STARTUP_RUNTIME_PROC_NAME "__$startup_runtime"
|
||||
#define LB_CLEANUP_RUNTIME_PROC_NAME "__$cleanup_runtime"
|
||||
#define LB_STARTUP_TYPE_INFO_PROC_NAME "__$startup_type_info"
|
||||
#define LB_TYPE_INFO_DATA_NAME "__$type_info_data"
|
||||
#define LB_TYPE_INFO_TYPES_NAME "__$type_info_types_data"
|
||||
#define LB_TYPE_INFO_NAMES_NAME "__$type_info_names_data"
|
||||
|
||||
@@ -1755,7 +1755,7 @@ gb_internal lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValu
|
||||
TypeAndValue tav = type_and_value_of_expr(arg);
|
||||
if (tav.mode == Addressing_Type) {
|
||||
Type *t = default_type(type_of_expr(arg));
|
||||
return lb_type_info(p->module, t);
|
||||
return lb_type_info(p, t);
|
||||
}
|
||||
GB_ASSERT(is_type_typeid(tav.type));
|
||||
|
||||
@@ -3361,9 +3361,9 @@ gb_internal lbValue lb_build_call_expr_internal(lbProcedure *p, Ast *expr) {
|
||||
for (Ast *var_arg : variadic) {
|
||||
lbValue arg = lb_build_expr(p, var_arg);
|
||||
if (is_type_any(elem_type)) {
|
||||
array_add(&args, lb_emit_conv(p, arg, default_type(arg.type)));
|
||||
array_add(&args, lb_emit_conv(p, arg, c_vararg_promote_type(default_type(arg.type))));
|
||||
} else {
|
||||
array_add(&args, lb_emit_conv(p, arg, elem_type));
|
||||
array_add(&args, lb_emit_conv(p, arg, c_vararg_promote_type(elem_type)));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -748,7 +748,7 @@ gb_internal void lb_build_range_enum(lbProcedure *p, Type *enum_type, Type *val_
|
||||
i64 enum_count = t->Enum.fields.count;
|
||||
lbValue max_count = lb_const_int(m, t_int, enum_count);
|
||||
|
||||
lbValue ti = lb_type_info(m, t);
|
||||
lbValue ti = lb_type_info(p, t);
|
||||
lbValue variant = lb_emit_struct_ep(p, ti, 4);
|
||||
lbValue eti_ptr = lb_emit_conv(p, variant, t_type_info_enum_ptr);
|
||||
lbValue values = lb_emit_load(p, lb_emit_struct_ep(p, eti_ptr, 2));
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -365,6 +365,9 @@ enum Typeid_Kind : u8 {
|
||||
Typeid_Matrix,
|
||||
Typeid_SoaPointer,
|
||||
Typeid_Bit_Field,
|
||||
|
||||
Typeid__COUNT
|
||||
|
||||
};
|
||||
|
||||
// IMPORTANT NOTE(bill): This must match the same as the in core.odin
|
||||
@@ -562,6 +565,14 @@ gb_global Type *t_f16 = &basic_types[Basic_f16];
|
||||
gb_global Type *t_f32 = &basic_types[Basic_f32];
|
||||
gb_global Type *t_f64 = &basic_types[Basic_f64];
|
||||
|
||||
gb_global Type *t_f16be = &basic_types[Basic_f16be];
|
||||
gb_global Type *t_f32be = &basic_types[Basic_f32be];
|
||||
gb_global Type *t_f64be = &basic_types[Basic_f64be];
|
||||
|
||||
gb_global Type *t_f16le = &basic_types[Basic_f16le];
|
||||
gb_global Type *t_f32le = &basic_types[Basic_f32le];
|
||||
gb_global Type *t_f64le = &basic_types[Basic_f64le];
|
||||
|
||||
gb_global Type *t_complex32 = &basic_types[Basic_complex32];
|
||||
gb_global Type *t_complex64 = &basic_types[Basic_complex64];
|
||||
gb_global Type *t_complex128 = &basic_types[Basic_complex128];
|
||||
@@ -2819,6 +2830,49 @@ gb_internal Type *default_type(Type *type) {
|
||||
return type;
|
||||
}
|
||||
|
||||
// See https://en.cppreference.com/w/c/language/conversion#Default_argument_promotions
|
||||
gb_internal Type *c_vararg_promote_type(Type *type) {
|
||||
GB_ASSERT(type != nullptr);
|
||||
|
||||
Type *core = core_type(type);
|
||||
|
||||
if (core->kind == Type_BitSet) {
|
||||
core = core_type(bit_set_to_int(core));
|
||||
}
|
||||
|
||||
if (core->kind == Type_Basic) {
|
||||
switch (core->Basic.kind) {
|
||||
case Basic_f32:
|
||||
case Basic_UntypedFloat:
|
||||
return t_f64;
|
||||
case Basic_f32le:
|
||||
return t_f64le;
|
||||
case Basic_f32be:
|
||||
return t_f64be;
|
||||
|
||||
case Basic_UntypedBool:
|
||||
case Basic_bool:
|
||||
case Basic_b8:
|
||||
case Basic_b16:
|
||||
case Basic_i8:
|
||||
case Basic_i16:
|
||||
case Basic_u8:
|
||||
case Basic_u16:
|
||||
return t_i32;
|
||||
|
||||
case Basic_i16le:
|
||||
case Basic_u16le:
|
||||
return t_i32le;
|
||||
|
||||
case Basic_i16be:
|
||||
case Basic_u16be:
|
||||
return t_i32be;
|
||||
}
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
gb_internal bool union_variant_index_types_equal(Type *v, Type *vt) {
|
||||
if (are_types_identical(v, vt)) {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user