Make static map calls the default; add -dynamic-map-calls

This commit is contained in:
gingerBill
2023-02-03 12:16:58 +00:00
parent fcc920ed39
commit eb457d688d
4 changed files with 37 additions and 32 deletions
+1 -1
View File
@@ -306,7 +306,7 @@ struct BuildContext {
bool disallow_rtti; bool disallow_rtti;
bool use_static_map_calls; bool dynamic_map_calls;
RelocMode reloc_mode; RelocMode reloc_mode;
bool disable_red_zone; bool disable_red_zone;
+6 -6
View File
@@ -281,11 +281,11 @@ gb_internal void error_operand_no_value(Operand *o) {
} }
gb_internal void add_map_get_dependencies(CheckerContext *c) { gb_internal void add_map_get_dependencies(CheckerContext *c) {
if (build_context.use_static_map_calls) { if (build_context.dynamic_map_calls) {
add_package_dependency(c, "runtime", "__dynamic_map_get");
} else {
add_package_dependency(c, "runtime", "map_desired_position"); add_package_dependency(c, "runtime", "map_desired_position");
add_package_dependency(c, "runtime", "map_probe_distance"); add_package_dependency(c, "runtime", "map_probe_distance");
} else {
add_package_dependency(c, "runtime", "__dynamic_map_get");
} }
} }
@@ -297,11 +297,11 @@ gb_internal void add_map_set_dependencies(CheckerContext *c) {
t_map_set_proc = alloc_type_proc_from_types(map_set_args, gb_count_of(map_set_args), t_rawptr, false, ProcCC_Odin); t_map_set_proc = alloc_type_proc_from_types(map_set_args, gb_count_of(map_set_args), t_rawptr, false, ProcCC_Odin);
} }
if (build_context.use_static_map_calls) { if (build_context.dynamic_map_calls) {
add_package_dependency(c, "runtime", "__dynamic_map_set");
} else {
add_package_dependency(c, "runtime", "__dynamic_map_check_grow"); add_package_dependency(c, "runtime", "__dynamic_map_check_grow");
add_package_dependency(c, "runtime", "map_insert_hash_dynamic"); add_package_dependency(c, "runtime", "map_insert_hash_dynamic");
} else {
add_package_dependency(c, "runtime", "__dynamic_map_set");
} }
} }
+21 -21
View File
@@ -457,7 +457,7 @@ gb_internal lbValue lb_hasher_proc_for_type(lbModule *m, Type *type) {
gb_internal 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.dynamic_map_calls);
type = base_type(type); type = base_type(type);
GB_ASSERT(type->kind == Type_Map); GB_ASSERT(type->kind == Type_Map);
@@ -610,7 +610,7 @@ gb_internal lbValue lb_map_get_proc_for_type(lbModule *m, Type *type) {
// } // }
gb_internal 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.dynamic_map_calls);
type = base_type(type); type = base_type(type);
GB_ASSERT(type->kind == Type_Map); GB_ASSERT(type->kind == Type_Map);
@@ -907,7 +907,15 @@ gb_internal lbValue lb_internal_dynamic_map_get_ptr(lbProcedure *p, lbValue cons
lbValue key_ptr = {}; lbValue key_ptr = {};
lbValue hash = lb_gen_map_key_hash(p, key, map_type->Map.key, &key_ptr); lbValue hash = lb_gen_map_key_hash(p, key, map_type->Map.key, &key_ptr);
if (build_context.use_static_map_calls) { if (build_context.dynamic_map_calls) {
auto args = array_make<lbValue>(permanent_allocator(), 4);
args[0] = lb_emit_transmute(p, map_ptr, t_raw_map_ptr);
args[1] = lb_gen_map_info_ptr(p->module, map_type);
args[2] = hash;
args[3] = key_ptr;
ptr = lb_emit_runtime_call(p, "__dynamic_map_get", args);
} else {
lbValue map_get_proc = lb_map_get_proc_for_type(p->module, map_type); lbValue map_get_proc = lb_map_get_proc_for_type(p->module, map_type);
auto args = array_make<lbValue>(permanent_allocator(), 3); auto args = array_make<lbValue>(permanent_allocator(), 3);
@@ -916,14 +924,6 @@ gb_internal lbValue lb_internal_dynamic_map_get_ptr(lbProcedure *p, lbValue cons
args[2] = key_ptr; args[2] = key_ptr;
ptr = lb_emit_call(p, map_get_proc, args); ptr = lb_emit_call(p, map_get_proc, args);
} else {
auto args = array_make<lbValue>(permanent_allocator(), 4);
args[0] = lb_emit_transmute(p, map_ptr, t_raw_map_ptr);
args[1] = lb_gen_map_info_ptr(p->module, map_type);
args[2] = hash;
args[3] = key_ptr;
ptr = lb_emit_runtime_call(p, "__dynamic_map_get", args);
} }
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));
} }
@@ -939,7 +939,16 @@ gb_internal void lb_internal_dynamic_map_set(lbProcedure *p, lbValue const &map_
lbValue v = lb_emit_conv(p, map_value, map_type->Map.value); lbValue v = lb_emit_conv(p, map_value, map_type->Map.value);
lbValue value_ptr = lb_address_from_load_or_generate_local(p, v); lbValue value_ptr = lb_address_from_load_or_generate_local(p, v);
if (build_context.use_static_map_calls) { if (build_context.dynamic_map_calls) {
auto args = array_make<lbValue>(permanent_allocator(), 6);
args[0] = lb_emit_conv(p, map_ptr, t_raw_map_ptr);
args[1] = lb_gen_map_info_ptr(p->module, map_type);
args[2] = hash;
args[3] = lb_emit_conv(p, key_ptr, t_rawptr);
args[4] = lb_emit_conv(p, value_ptr, t_rawptr);
args[5] = lb_emit_source_code_location_as_global(p, node);
lb_emit_runtime_call(p, "__dynamic_map_set", args);
} else {
lbValue map_set_proc = lb_map_set_proc_for_type(p->module, map_type); lbValue map_set_proc = lb_map_set_proc_for_type(p->module, map_type);
auto args = array_make<lbValue>(permanent_allocator(), 5); auto args = array_make<lbValue>(permanent_allocator(), 5);
@@ -950,15 +959,6 @@ gb_internal void lb_internal_dynamic_map_set(lbProcedure *p, lbValue const &map_
args[4] = lb_emit_source_code_location_as_global(p, node); args[4] = lb_emit_source_code_location_as_global(p, node);
lb_emit_call(p, map_set_proc, args); lb_emit_call(p, map_set_proc, args);
} else {
auto args = array_make<lbValue>(permanent_allocator(), 6);
args[0] = lb_emit_conv(p, map_ptr, t_raw_map_ptr);
args[1] = lb_gen_map_info_ptr(p->module, map_type);
args[2] = hash;
args[3] = lb_emit_conv(p, key_ptr, t_rawptr);
args[4] = lb_emit_conv(p, value_ptr, t_rawptr);
args[5] = lb_emit_source_code_location_as_global(p, node);
lb_emit_runtime_call(p, "__dynamic_map_set", args);
} }
} }
+9 -4
View File
@@ -647,7 +647,7 @@ enum BuildFlagKind {
BuildFlag_StrictStyleInitOnly, BuildFlag_StrictStyleInitOnly,
BuildFlag_ForeignErrorProcedures, BuildFlag_ForeignErrorProcedures,
BuildFlag_DisallowRTTI, BuildFlag_DisallowRTTI,
BuildFlag_UseStaticMapCalls, BuildFlag_DynamicMapCalls,
BuildFlag_Compact, BuildFlag_Compact,
BuildFlag_GlobalDefinitions, BuildFlag_GlobalDefinitions,
@@ -824,7 +824,7 @@ gb_internal bool parse_build_flags(Array<String> args) {
add_flag(&build_flags, BuildFlag_DisallowRTTI, str_lit("disallow-rtti"), BuildFlagParam_None, Command__does_check); add_flag(&build_flags, BuildFlag_DisallowRTTI, str_lit("disallow-rtti"), BuildFlagParam_None, Command__does_check);
add_flag(&build_flags, BuildFlag_UseStaticMapCalls, str_lit("use-static-map-calls"), BuildFlagParam_None, Command__does_check); add_flag(&build_flags, BuildFlag_DynamicMapCalls, str_lit("dynamic-map-calls"), BuildFlagParam_None, Command__does_check);
add_flag(&build_flags, BuildFlag_Short, str_lit("short"), BuildFlagParam_None, Command_doc); add_flag(&build_flags, BuildFlag_Short, str_lit("short"), BuildFlagParam_None, Command_doc);
add_flag(&build_flags, BuildFlag_AllPackages, str_lit("all-packages"), BuildFlagParam_None, Command_doc); add_flag(&build_flags, BuildFlag_AllPackages, str_lit("all-packages"), BuildFlagParam_None, Command_doc);
@@ -1407,8 +1407,8 @@ gb_internal bool parse_build_flags(Array<String> args) {
case BuildFlag_DisallowRTTI: case BuildFlag_DisallowRTTI:
build_context.disallow_rtti = true; build_context.disallow_rtti = true;
break; break;
case BuildFlag_UseStaticMapCalls: case BuildFlag_DynamicMapCalls:
build_context.use_static_map_calls = true; build_context.dynamic_map_calls = true;
break; break;
case BuildFlag_DefaultToNilAllocator: case BuildFlag_DefaultToNilAllocator:
build_context.ODIN_DEFAULT_TO_NIL_ALLOCATOR = true; build_context.ODIN_DEFAULT_TO_NIL_ALLOCATOR = true;
@@ -2130,6 +2130,11 @@ gb_internal void print_show_help(String const arg0, String const &command) {
print_usage_line(1, "-disable-red-zone"); print_usage_line(1, "-disable-red-zone");
print_usage_line(2, "Disable red zone on a supported freestanding target"); print_usage_line(2, "Disable red zone on a supported freestanding target");
print_usage_line(0, "");
print_usage_line(1, "-dynamic-map-calls");
print_usage_line(2, "Use dynamic map calls to minimize code generation at the cost of runtime execution");
print_usage_line(0, "");
} }
if (check) { if (check) {