From e281528d570c0e7bbeb1d7bb79e1a3ad30a7042b Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Thu, 16 Apr 2026 11:50:02 -0700 Subject: [PATCH] rdi pass checkpoint: rdi baking; scope-organized locals gathering / sorting / organizing; plug into serialization path --- build.bat | 2 +- project.4coder | 2 +- src/rdi/rdi_local.c | 18 +++-------- src/rdi/rdi_local.h | 1 + src/rdi_make/rdi_make_local.c | 58 ++++++++++++++++++++++++----------- 5 files changed, 47 insertions(+), 34 deletions(-) diff --git a/build.bat b/build.bat index 36d142ae..052085c8 100644 --- a/build.bat +++ b/build.bat @@ -146,7 +146,7 @@ if "%convertperf%"=="1" set didbuild=1 && %compile% ..\src\scratc if "%debugstringperf%"=="1" set didbuild=1 && %compile% ..\src\scratch\debugstringperf.c %compile_link% %out%debugstringperf.exe || exit /b 1 if "%parse_inline_sites%"=="1" set didbuild=1 && %compile% ..\src\scratch\parse_inline_sites.c %compile_link% %out%parse_inline_sites.exe || exit /b 1 if "%strip_lib_debug%"=="1" set didbuild=1 && %compile% ..\src\strip_lib_debug\strip_lib_debug.c %compile_link% %out%strip_lib_debug.exe || exit /b 1 -if "%mule_main%"=="1" set didbuild=1 && del vc*.pdb mule*.pdb && %compile_release% %only_compile% ..\src\mule\mule_inline.cpp %out%mule_inline.obj && %compile_release% %only_compile% ..\src\mule\mule_o2.cpp %out%mule_o2.obj && %compile_debug% %EHsc% ..\src\mule\mule_main.cpp ..\src\mule\mule_c.c mule_inline.obj mule_o2.obj %compile_link% %no_aslr% %out%mule_main.exe || exit /b 1 +if "%mule_main%"=="1" set didbuild=1 && del vc*.pdb mule*.pdb && %compile_release% %only_compile% ..\src\mule\mule_inline.cpp && %compile_release% %only_compile% ..\src\mule\mule_o2.cpp && %compile_debug% %EHsc% ..\src\mule\mule_main.cpp ..\src\mule\mule_c.c mule_inline.obj mule_o2.obj %compile_link% %no_aslr% %out%mule_main.exe || exit /b 1 if "%mule_module%"=="1" set didbuild=1 && %compile% ..\src\mule\mule_module.cpp %link_dll% %out%mule_module.dll || exit /b 1 if "%mule_hotload%"=="1" set didbuild=1 && %compile% ..\src\mule\mule_hotload_main.c %compile_link% %out%mule_hotload.exe & %compile% ..\src\mule\mule_hotload_module_main.c %compile_link% %link_dll% %out%mule_hotload_module.dll || exit /b 1 if "%torture%"=="1" set didbuild=1 && %compile% ..\src\torture\torture_main.c %compile_link% %out%torture.exe || exit /b1 diff --git a/project.4coder b/project.4coder index 0d66816b..a3fc4681 100644 --- a/project.4coder +++ b/project.4coder @@ -48,7 +48,7 @@ commands = //- rjf: [raddbg] // .f1 = { .win = "raddbg_stable --ipc kill_all && build raddbg meta telemetry", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, // .f1 = { .win = "raddbg_stable --ipc kill_all && build raddbg debug telemetry", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, - .f1 = { .win = "raddbg_stable --ipc kill_all && build raddbg debug", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, + .f1 = { .win = "raddbg_stable --ipc kill_all && build radbin", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, //- rjf: [raddbg wsl] // .f1 = { .win = "wsl ./build.sh raddbg", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, diff --git a/src/rdi/rdi_local.c b/src/rdi/rdi_local.c index e86ff47f..191ac4de 100644 --- a/src/rdi/rdi_local.c +++ b/src/rdi/rdi_local.c @@ -1117,6 +1117,7 @@ lane_sync(); if(flags & (1ull<<(kind))) ProfScope(rdi_name_title_from_dump_subse {RDI_DumpSubset_Procedures, RDI_SectionKind_ProcedureSymbols}, {RDI_DumpSubset_GlobalVariables, RDI_SectionKind_GlobalVariableSymbols}, {RDI_DumpSubset_ThreadVariables, RDI_SectionKind_ThreadVariableSymbols}, + {RDI_DumpSubset_LocalVariables, RDI_SectionKind_LocalVariableSymbols}, {RDI_DumpSubset_Constants, RDI_SectionKind_ConstantSymbols}, }; for EachElement(symbol_table_idx, symbol_tables) @@ -1137,6 +1138,7 @@ lane_sync(); if(flags & (1ull<<(kind))) ProfScope(rdi_name_title_from_dump_subse dumpf(" type_idx: %u\n", symbol->type_idx); dumpf(" root_scope_idx: %u\n", symbol->root_scope_idx); dumpf(" container_idx: %u\n", symbol->container_idx); + // TODO(rjf): location info dumpf(" }\n"); scratch_end(scratch); } @@ -1153,7 +1155,7 @@ lane_sync(); if(flags & (1ull<<(kind))) ProfScope(rdi_name_title_from_dump_subse U64 scope_voffs_count = 0; U64 *scope_voffs = rdi_table_from_name(rdi, ScopeVOffData, &scope_voffs_count); U64 locals_count = 0; - RDI_Local *locals = rdi_table_from_name(rdi, Locals, &locals_count); + RDI_Symbol *locals = rdi_table_from_name(rdi, LocalVariableSymbols, &locals_count); U64 count = 0; RDI_Scope *v = rdi_table_from_name(rdi, Scopes, &count); RDI_Scope *nil = &v[0]; @@ -1217,22 +1219,10 @@ lane_sync(); if(flags & (1ull<<(kind))) ProfScope(rdi_name_title_from_dump_subse for(U32 local_idx = local_lo; local_idx < local_hi; local_idx += 1) { Temp scratch = scratch_begin(&arena, 1); - RDI_Local *local_ptr = &locals[local_idx]; + RDI_Symbol *local_ptr = &locals[local_idx]; dumpf("%.*s '%S': // local[%u]\n", depth*2, indent.str, str8_from_rdi_string_idx(rdi, local_ptr->name_string_idx), local_idx); dumpf("%.*s {\n", depth*2, indent.str); - dumpf("%.*s kind: %S\n", depth*2, indent.str, rdi_string_from_local_kind(scratch.arena, local_ptr->kind)); dumpf("%.*s type_idx: %u\n", depth*2, indent.str, local_ptr->type_idx); - dumpf("%.*s locations:\n", depth*2, indent.str); - dumpf("%.*s {\n", depth*2, indent.str); - if(local_ptr->location_first < local_ptr->location_opl) - { - String8List locations_strings = rdi_strings_from_locations(arena, rdi, tli->arch, r1u64(local_ptr->location_first, local_ptr->location_opl)); - for(String8Node *n = locations_strings.first; n != 0; n = n->next) - { - dumpf("%.*s %S\n", depth*2, indent.str, n->string); - } - } - dumpf("%.*s }\n", depth*2, indent.str); dumpf("%.*s }\n", depth*2, indent.str); scratch_end(scratch); } diff --git a/src/rdi/rdi_local.h b/src/rdi/rdi_local.h index 96b8d0e5..98dd57bc 100644 --- a/src/rdi/rdi_local.h +++ b/src/rdi/rdi_local.h @@ -25,6 +25,7 @@ X(UserDefinedTypes, user_defined_types, "USER DEFINED TYPES")\ X(GlobalVariables, global_variables, "GLOBAL VARIABLES")\ X(GlobalVariablesVMap, global_variables_vmap, "GLOBAL VARIABLE VMAP")\ X(ThreadVariables, thread_variables, "THREAD VARIABLES")\ +X(LocalVariables, local_variables, "LOCAL VARIABLES")\ X(Constants, constants, "CONSTANTS")\ X(Procedures, procedures, "PROCEDURES")\ X(Scopes, scopes, "SCOPES")\ diff --git a/src/rdi_make/rdi_make_local.c b/src/rdi_make/rdi_make_local.c index 948b08ac..f72597fc 100644 --- a/src/rdi_make/rdi_make_local.c +++ b/src/rdi_make/rdi_make_local.c @@ -2973,6 +2973,7 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params) RDI_U64 *scope_local_chunk_lane_offs; // [lane_count * scope_chunk_count] RDI_U64 *scope_voff_chunk_lane_counts; // [lane_count * scope_chunk_count] RDI_U64 *scope_voff_chunk_lane_offs; // [lane_count * scope_chunk_count] + U64 total_local_count; }; ScopeLayout *scope_layout = 0; ProfScope("compute layout for scope sub-lists (locals / voffs)") @@ -3026,6 +3027,7 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params) } chunk_idx += 1; } + scope_layout->total_local_count = local_layout_off; } lane_sync(); } @@ -3041,7 +3043,7 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params) RDI_U64 scopes_count; RDI_U64 *scope_voffs; RDI_U64 scope_voffs_count; - RDIM_SymbolChunkList arranged_locals; + RDIM_SymbolChunkNode arranged_locals_chunk; }; BakedScopes *baked_scopes = 0; ProfScope("bake scopes") @@ -3062,6 +3064,13 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params) baked_scopes->scope_voffs_count = all_scopes->scope_voff_count+1; baked_scopes->scope_voffs = push_array(arena, RDI_U64, baked_scopes->scope_voffs_count); } + if(lane_idx() == lane_from_task_idx(2)) + { + baked_scopes->arranged_locals_chunk.count = scope_layout->total_local_count; + baked_scopes->arranged_locals_chunk.cap = baked_scopes->arranged_locals_chunk.count; + baked_scopes->arranged_locals_chunk.base_idx = 0; + baked_scopes->arranged_locals_chunk.v = push_array(scratch.arena, RDIM_Symbol, baked_scopes->arranged_locals_chunk.count); + } lane_sync(); //- rjf: wide fill @@ -3096,18 +3105,18 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params) for EachIndex(src_local_idx, src_local_n->count) { RDIM_Symbol *src_local = &src_local_n->v[src_local_idx]; -#if 0 - RDI_Symbol *dst_local = &baked_scopes->locals[chunk_local_off]; - dst_local->kind = src_local->kind; - dst_local->name_string_idx = rdim_bake_idx_from_string(bake_strings, src_local->name); - dst_local->type_idx = (RDI_U32)rdim_idx_from_type(src_local->type); // TODO(rjf): @u64_to_u32 - if(src_local->location_cases.count != 0) - { - dst_local->location_first = chunk_location_block_off; - dst_local->location_opl = chunk_location_block_off + src_local->location_cases.count; - chunk_location_block_off += src_local->location_cases.count; - } -#endif + RDIM_Symbol *dst_local = &baked_scopes->arranged_locals_chunk.v[chunk_local_off]; + dst_local->chunk = &baked_scopes->arranged_locals_chunk; + dst_local->is_extern = src_local->is_extern; + dst_local->is_param = src_local->is_param; + dst_local->name = src_local->name; + dst_local->link_name = src_local->link_name; + dst_local->type = src_local->type; + dst_local->container_scope = src_local->container_scope; + dst_local->container_type = src_local->container_type; + dst_local->container_namespace = src_local->container_namespace; + dst_local->root_scope = src_local->root_scope; + dst_local->location_cases = src_local->location_cases; chunk_local_off += 1; } } @@ -3130,6 +3139,19 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params) } lane_sync(); + ////////////////////////////////////////////////////////////// + //- rjf: @rdim_bake_stage form local chunk list for all arranged locals + // + RDIM_SymbolChunkList *all_locals = 0; + if(lane_idx() == 0) + { + all_locals = push_array(scratch.arena, RDIM_SymbolChunkList, 1); + all_locals[0].first = all_locals[0].last = &baked_scopes->arranged_locals_chunk; + all_locals[0].chunk_count = 1; + all_locals[0].total_count = baked_scopes->arranged_locals_chunk.count; + } + lane_sync_u64(&all_locals, 0); + ////////////////////////////////////////////////////////////// //- rjf: @rdim_bake_stage bake procedures // @@ -3550,11 +3572,11 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params) } symbol_table_lists[] = { - {all_global_variables, &baked_global_variables, &baked_global_variables_count}, - {all_thread_variables, &baked_thread_variables, &baked_thread_variables_count}, - {all_procedures, &baked_procedures, &baked_procedures_count}, - {all_constants, &baked_constants, &baked_constants_count}, - {&baked_scopes->arranged_locals, &baked_locals, &baked_locals_count}, + {all_global_variables, &baked_global_variables, &baked_global_variables_count}, + {all_thread_variables, &baked_thread_variables, &baked_thread_variables_count}, + {all_procedures, &baked_procedures, &baked_procedures_count}, + {all_constants, &baked_constants, &baked_constants_count}, + {all_locals, &baked_locals, &baked_locals_count}, }; //////////////////////////////////////////////////////////////