fold voffs/toffs/constants into location case list, plug into converters

This commit is contained in:
Ryan Fleury
2026-04-20 09:57:30 -07:00
parent 4ea7f86d92
commit cff7a786b3
7 changed files with 60 additions and 34 deletions
+5 -5
View File
@@ -114,7 +114,7 @@ RDI_SectionKind_GlobalVariableSymbols = 0x0023,
RDI_SectionKind_ThreadVariableSymbols = 0x0024,
RDI_SectionKind_ConstantSymbols = 0x0025,
RDI_SectionKind_ProcedureSymbols = 0x0026,
RDI_SectionKind_LocalSymbols = 0x0027,
RDI_SectionKind_LocalVariableSymbols = 0x0027,
RDI_SectionKind_LocationsBytecodeData = 0x0028,
RDI_SectionKind_LocationsConstantData = 0x0029,
RDI_SectionKind_LocationsSetElements = 0x002A,
@@ -579,7 +579,7 @@ X(GlobalVariableSymbols, global_variable_symbols, RDI_Symbol)\
X(ThreadVariableSymbols, thread_variable_symbols, RDI_Symbol)\
X(ConstantSymbols, constant_symbols, RDI_Symbol)\
X(ProcedureSymbols, procedure_symbols, RDI_Symbol)\
X(LocalSymbols, local_symbols, RDI_Symbol)\
X(LocalVariableSymbols, local_variable_symbols, RDI_Symbol)\
X(LocationsBytecodeData, locations_bytecode_data, RDI_U8)\
X(LocationsConstantData, locations_constant_data, RDI_U8)\
X(LocationsSetElements, locations_set_elements, RDI_LocationSetElement)\
@@ -1143,7 +1143,7 @@ typedef struct RDI_U32_GlobalVariableSymbols { RDI_U32 v; } RDI_U32_Global
typedef struct RDI_U32_ThreadVariableSymbols { RDI_U32 v; } RDI_U32_ThreadVariableSymbols;
typedef struct RDI_U32_ConstantSymbols { RDI_U32 v; } RDI_U32_ConstantSymbols;
typedef struct RDI_U32_ProcedureSymbols { RDI_U32 v; } RDI_U32_ProcedureSymbols;
typedef struct RDI_U32_LocalSymbols { RDI_U32 v; } RDI_U32_LocalSymbols;
typedef struct RDI_U32_LocalVariableSymbols { RDI_U32 v; } RDI_U32_LocalVariableSymbols;
typedef struct RDI_U32_LocationsBytecodeData { RDI_U32 v; } RDI_U32_LocationsBytecodeData;
typedef struct RDI_U32_LocationsConstantData { RDI_U32 v; } RDI_U32_LocationsConstantData;
typedef struct RDI_U32_LocationsSetElements { RDI_U32 v; } RDI_U32_LocationsSetElements;
@@ -1192,7 +1192,7 @@ typedef RDI_U32_Table RDI_U32_GlobalVariableSymbols;
typedef RDI_U32_Table RDI_U32_ThreadVariableSymbols;
typedef RDI_U32_Table RDI_U32_ConstantSymbols;
typedef RDI_U32_Table RDI_U32_ProcedureSymbols;
typedef RDI_U32_Table RDI_U32_LocalSymbols;
typedef RDI_U32_Table RDI_U32_LocalVariableSymbols;
typedef RDI_U32_Table RDI_U32_LocationsBytecodeData;
typedef RDI_U32_Table RDI_U32_LocationsConstantData;
typedef RDI_U32_Table RDI_U32_LocationsSetElements;
@@ -1638,7 +1638,7 @@ typedef RDI_Symbol RDI_SectionElementType_GlobalVariableSy
typedef RDI_Symbol RDI_SectionElementType_ThreadVariableSymbols;
typedef RDI_Symbol RDI_SectionElementType_ConstantSymbols;
typedef RDI_Symbol RDI_SectionElementType_ProcedureSymbols;
typedef RDI_Symbol RDI_SectionElementType_LocalSymbols;
typedef RDI_Symbol RDI_SectionElementType_LocalVariableSymbols;
typedef RDI_U8 RDI_SectionElementType_LocationsBytecodeData;
typedef RDI_U8 RDI_SectionElementType_LocationsConstantData;
typedef RDI_LocationSetElement RDI_SectionElementType_LocationsSetElements;
+12 -11
View File
@@ -940,14 +940,7 @@ rdim_idx_from_symbol(RDIM_Symbol *symbol)
RDI_PROC void
rdim_symbol_chunk_list_concat_in_place(RDIM_SymbolChunkList *dst, RDIM_SymbolChunkList *to_push)
{
RDIM_IdxedChunkListConcatInPlace(RDIM_SymbolChunkNode, dst, to_push, dst->total_value_data_size += to_push->total_value_data_size);
}
internal void
rdim_symbol_push_value_data(RDIM_Arena *arena, RDIM_SymbolChunkList *list, RDIM_Symbol *symbol, RDIM_String8 data)
{
symbol->value_data = rdim_str8_copy(arena, data);
list->total_value_data_size += data.size;
RDIM_IdxedChunkListConcatInPlace(RDIM_SymbolChunkNode, dst, to_push);
}
////////////////////////////////
@@ -1080,6 +1073,16 @@ rdim_is_bytecode_tls_dependent(RDIM_EvalBytecode bytecode)
return result;
}
RDI_PROC void
rdim_location_case_list_push(RDIM_Arena *arena, RDIM_LocationCaseList *cases, RDIM_Location loc, RDIM_Rng1U64 range)
{
RDIM_LocationCase *n = rdim_push_array(arena, RDIM_LocationCase, 1);
RDIM_SLLQueuePush(cases->first, cases->last, n);
cases->count += 1;
n->location = loc;
n->voff_range = range;
}
////////////////////////////////
//~ rjf: [Building] Scope Info Building
@@ -1102,8 +1105,7 @@ rdim_scope_chunk_list_concat_in_place(RDIM_ScopeChunkList *dst, RDIM_ScopeChunkL
{
RDIM_IdxedChunkListConcatInPlace(RDIM_ScopeChunkNode, dst, to_push,
dst->scope_voff_count += to_push->scope_voff_count,
dst->local_count += to_push->local_count,
dst->location_case_count += to_push->location_case_count);
dst->local_count += to_push->local_count);
}
RDI_PROC void
@@ -1131,7 +1133,6 @@ rdim_push_location_case(RDIM_Arena *arena, RDIM_ScopeChunkList *scopes, RDIM_Loc
list->count += 1;
n->location = *location;
n->voff_range = voff_range;
scopes->location_case_count += 1;
return n;
}
+1 -5
View File
@@ -887,13 +887,11 @@ struct RDIM_Symbol
RDIM_String8 name;
RDIM_String8 link_name;
RDIM_Type *type;
RDI_U64 offset;
struct RDIM_Scope *container_scope;
RDIM_Type *container_type;
RDIM_Namespace *container_namespace;
struct RDIM_Scope *root_scope;
RDIM_LocationCaseList location_cases;
RDIM_String8 value_data;
};
typedef struct RDIM_SymbolChunkNode RDIM_SymbolChunkNode;
@@ -913,7 +911,6 @@ struct RDIM_SymbolChunkList
RDIM_SymbolChunkNode *last;
RDI_U64 chunk_count;
RDI_U64 total_count;
RDI_U64 total_value_data_size;
};
////////////////////////////////
@@ -996,7 +993,6 @@ struct RDIM_ScopeChunkList
RDI_U64 total_count;
RDI_U64 scope_voff_count;
RDI_U64 local_count;
RDI_U64 location_case_count;
};
////////////////////////////////
@@ -1663,7 +1659,6 @@ RDI_PROC RDIM_UDTEnumVal *rdim_udt_push_enum_val(RDIM_Arena *arena, RDIM_UDTChun
RDI_PROC RDIM_Symbol *rdim_symbol_chunk_list_push(RDIM_Arena *arena, RDIM_SymbolChunkList *list, RDI_U64 cap);
RDI_PROC RDI_U64 rdim_idx_from_symbol(RDIM_Symbol *symbol);
RDI_PROC void rdim_symbol_chunk_list_concat_in_place(RDIM_SymbolChunkList *dst, RDIM_SymbolChunkList *to_push);
internal void rdim_symbol_push_value_data(RDIM_Arena *arena, RDIM_SymbolChunkList *list, RDIM_Symbol *symbol, RDIM_String8 data);
////////////////////////////////
//~ rjf: [Building] Inline Site Info Building
@@ -1681,6 +1676,7 @@ RDI_PROC void rdim_bytecode_push_sconst(RDIM_Arena *arena, RDIM_EvalBytecode *by
RDI_PROC void rdim_bytecode_push_convert(RDIM_Arena *arena, RDIM_EvalBytecode *bytecode, RDI_EvalTypeGroup in, RDI_EvalTypeGroup out);
RDI_PROC void rdim_bytecode_concat_in_place(RDIM_EvalBytecode *left_dst, RDIM_EvalBytecode *right_destroyed);
RDI_PROC B32 rdim_is_bytecode_tls_dependent(RDIM_EvalBytecode bytecode);
RDI_PROC void rdim_location_case_list_push(RDIM_Arena *arena, RDIM_LocationCaseList *cases, RDIM_Location loc, RDIM_Rng1U64 range);
////////////////////////////////
//~ rjf: [Building] Scope Info Building
+1 -1
View File
@@ -202,7 +202,7 @@ RDI_SectionTable:
{ThreadVariableSymbols thread_variable_symbols RDI_Symbol 0x0024 U32 ""}
{ConstantSymbols constant_symbols RDI_Symbol 0x0025 U32 ""}
{ProcedureSymbols procedure_symbols RDI_Symbol 0x0026 U32 ""}
{LocalSymbols local_symbols RDI_Symbol 0x0027 U32 ""}
{LocalVariableSymbols local_variable_symbols RDI_Symbol 0x0027 U32 ""}
//- NOTE(rjf): vvv new story for locations
{LocationsBytecodeData locations_bytecode_data RDI_U8 0x0028 U32 ""}
+3 -1
View File
@@ -2521,8 +2521,10 @@ d2r_convert_symbols(Arena *arena,
var->name = name;
var->link_name = dw_string_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_LinkageName);
var->type = type;
var->offset = voff;
var->container_scope = 0;
RDIM_Location loc = {.kind = RDI_LocationKind_ModuleOff, .offset = voff};
RDIM_Rng1U64 range = {0, 0xffffffffffffffffull};
rdim_location_case_list_push(arena, &var->location_cases, loc, range);
}
} break;
case DW_TagKind_FormalParameter: {
+9 -3
View File
@@ -3468,9 +3468,11 @@ p2r_convert(Arena *arena, P2R_ConvertParams *params)
symbol->is_extern = (iter.kind == CV_SymKind_GDATA32);
symbol->name = name;
symbol->type = type;
symbol->offset = voff;
symbol->container_scope = container_scope;
symbol->container_type = container_type;
RDIM_Location loc = {.kind = RDI_LocationKind_ModuleOff, .offset = voff};
RDIM_Rng1U64 range = {0, 0xffffffffffffffffull};
rdim_location_case_list_push(arena, &symbol->location_cases, loc, range);
}
}break;
@@ -3722,9 +3724,11 @@ p2r_convert(Arena *arena, P2R_ConvertParams *params)
tvar->name = name;
tvar->type = type;
tvar->is_extern = (iter.kind == CV_SymKind_GTHREAD32);
tvar->offset = tls_off;
tvar->container_type = container_type;
tvar->container_scope = container_scope;
RDIM_Location loc = {.kind = RDI_LocationKind_TLSOff, .offset = tls_off};
RDIM_Rng1U64 range = {0, 0xffffffffffffffffull};
rdim_location_case_list_push(arena, &tvar->location_cases, loc, range);
}break;
//- rjf: LOCAL
@@ -4132,7 +4136,9 @@ p2r_convert(Arena *arena, P2R_ConvertParams *params)
RDIM_Symbol *cnst = rdim_symbol_chunk_list_push(arena, sym_constants, sym_constants_chunk_cap);
cnst->name = name_qualified;
cnst->type = type;
rdim_symbol_push_value_data(arena, sym_constants, cnst, val_data);
RDIM_Location loc = {.kind = RDI_LocationKind_ConstantDataOff, .value_data = str8_copy(arena, val_data)};
RDIM_Rng1U64 range = {0, 0xffffffffffffffffull};
rdim_location_case_list_push(arena, &cnst->location_cases, loc, range);
}
}break;
}
+29 -8
View File
@@ -423,7 +423,14 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params)
{
U64 slot_idx = lane_idx()*params->global_variables.chunk_count + chunk_idx;
Rng1U64 range = lane_range(n->count);
lane_chunk_range_counts[slot_idx] += dim_1u64(range);
for EachIndex(n_idx, n->count)
{
if(n->v[n_idx].location_cases.count == 1 &&
n->v[n_idx].location_cases.first->location.kind == RDI_LocationKind_ModuleOff)
{
lane_chunk_range_counts[slot_idx] += 1;
}
}
chunk_idx += 1;
}
}
@@ -471,13 +478,17 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params)
Rng1U64 range = lane_range(n->count);
for EachInRange(n_idx, range)
{
RDI_U32 global_idx = (RDI_U32)rdim_idx_from_symbol(&n->v[n_idx]); // TODO(rjf): @u64_to_u32
RDI_U32 global_size = (RDI_U32)(n->v[n_idx].type ? n->v[n_idx].type->byte_size : 1);
RDI_U64 global_voff = n->v[n_idx].offset;
global_vmap_records[off].key.voff = global_voff;
global_vmap_records[off].key.negative_size = -global_size;
global_vmap_records[off].idx = global_idx;
off += 1;
if(n->v[n_idx].location_cases.count == 1 &&
n->v[n_idx].location_cases.first->location.kind == RDI_LocationKind_ModuleOff)
{
RDI_U32 global_idx = (RDI_U32)rdim_idx_from_symbol(&n->v[n_idx]); // TODO(rjf): @u64_to_u32
RDI_U32 global_size = (RDI_U32)(n->v[n_idx].type ? n->v[n_idx].type->byte_size : 1);
RDI_U64 global_voff = n->v[n_idx].location_cases.first->location.offset;
global_vmap_records[off].key.voff = global_voff;
global_vmap_records[off].key.negative_size = -global_size;
global_vmap_records[off].idx = global_idx;
off += 1;
}
}
chunk_idx += 1;
}
@@ -3036,6 +3047,7 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params)
//////////////////////////////////////////////////////////////
//- rjf: @rdim_bake_stage compute layout for constant data
//
#if 0 // TODO(rjf): @locpass
typedef struct ConstantLayout ConstantLayout;
struct ConstantLayout
{
@@ -3088,10 +3100,12 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params)
}
}
lane_sync();
#endif
//////////////////////////////////////////////////////////////
//- rjf: @rdim_bake_stage bake constants
//
#if 0 // TODO(rjf): @locpass
RDIM_ConstantsBakeResult *baked_constants = 0;
ProfScope("bake constants")
{
@@ -3144,6 +3158,7 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params)
}
}
lane_sync();
#endif
//////////////////////////////////////////////////////////////
//- rjf: @rdim_bake_stage bake units, symbols, types, UDTs
@@ -3288,6 +3303,7 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params)
}
//- rjf: bake global variables
#if 0 // TODO(rjf): @locpass
ProfScope("bake global variables")
{
for EachNode(n, RDIM_SymbolChunkNode, params->global_variables.first)
@@ -3317,8 +3333,10 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params)
}
}
}
#endif
//- rjf: bake thread variables
#if 0 // TODO(rjf): @locpass
ProfScope("bake thread variables")
{
for EachNode(n, RDIM_SymbolChunkNode, params->thread_variables.first)
@@ -3348,6 +3366,7 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params)
}
}
}
#endif
//- rjf: bake inline sites
ProfScope("bake inline sites")
@@ -3757,7 +3776,9 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params)
result.global_variables = *baked_global_variables;
result.global_vmap = *baked_global_vmap;
result.thread_variables = *baked_thread_variables;
#if 0 // TODO(rjf): @locpass
result.constants = *baked_constants;
#endif
result.procedures = *baked_procedures;
result.scopes = *baked_scopes;
result.inline_sites = *baked_inline_sites;