sema: align C function names with Sema.zig for CPU profile cross-referencing
Rename static functions to use sema prefix + Zig method name pattern, so perf profiles show corresponding names (e.g. semaAddExtra ↔ Sema.addExtra). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
222
stage0/sema.c
222
stage0/sema.c
@@ -188,11 +188,11 @@ static AirInstRef resolveInst(Sema* sema, ZirInstRef zir_ref) {
|
||||
return AIR_REF_FROM_IP(zir_ref);
|
||||
}
|
||||
|
||||
// --- addAirInst ---
|
||||
// --- semaAddInstAsIndex ---
|
||||
// Appends an AIR instruction to sema's output arrays.
|
||||
// Returns the instruction index (not the ref).
|
||||
|
||||
static uint32_t addAirInst(Sema* sema, AirInstTag inst_tag, AirInstData data) {
|
||||
static uint32_t semaAddInstAsIndex(Sema* sema, AirInstTag inst_tag, AirInstData data) {
|
||||
if (sema->air_inst_len >= sema->air_inst_cap) {
|
||||
uint32_t new_cap = sema->air_inst_cap * 2;
|
||||
uint8_t* new_tags
|
||||
@@ -235,10 +235,10 @@ static void semaBlockDeinit(SemaBlock* block) {
|
||||
}
|
||||
|
||||
// Add an AIR instruction to the block's instruction list.
|
||||
static AirInstRef blockAddInst(
|
||||
static AirInstRef semaAddInst(
|
||||
SemaBlock* block, AirInstTag inst_tag, AirInstData data) {
|
||||
Sema* sema = block->sema;
|
||||
uint32_t idx = addAirInst(sema, inst_tag, data);
|
||||
uint32_t idx = semaAddInstAsIndex(sema, inst_tag, data);
|
||||
|
||||
// Append to block's instruction list.
|
||||
if (block->instructions_len >= block->instructions_cap) {
|
||||
@@ -257,7 +257,7 @@ static AirInstRef blockAddInst(
|
||||
|
||||
// --- Air extra helpers ---
|
||||
// Append a u32 to the AIR extra array, growing if needed.
|
||||
static uint32_t addAirExtra(Sema* sema, uint32_t value) {
|
||||
static uint32_t semaAddExtra(Sema* sema, uint32_t value) {
|
||||
if (sema->air_extra_len >= sema->air_extra_cap) {
|
||||
uint32_t new_cap = sema->air_extra_cap * 2;
|
||||
uint32_t* new_extra
|
||||
@@ -304,11 +304,11 @@ static void zirDbgStmt(Sema* sema, SemaBlock* block, uint32_t inst) {
|
||||
memset(&data, 0, sizeof(data));
|
||||
data.dbg_stmt.line = line;
|
||||
data.dbg_stmt.column = column;
|
||||
(void)blockAddInst(block, AIR_INST_DBG_STMT, data);
|
||||
(void)semaAddInst(block, AIR_INST_DBG_STMT, data);
|
||||
}
|
||||
|
||||
// semaAppendAirString: store a NullTerminatedString in the AIR extra array.
|
||||
// Ported from src/Sema.zig appendAirString.
|
||||
// Ported from src/Sema.zig semaAppendAirString.
|
||||
// The string (including NUL) is packed into u32 words in the extra array.
|
||||
// Returns the extra array index where the string starts.
|
||||
static uint32_t semaAppendAirString(Sema* sema, const char* str) {
|
||||
@@ -370,7 +370,7 @@ static void zirDbgVar(
|
||||
memset(&data, 0, sizeof(data));
|
||||
data.pl_op.operand = operand;
|
||||
data.pl_op.payload = name_nts;
|
||||
(void)blockAddInst(block, air_tag, data);
|
||||
(void)semaAddInst(block, air_tag, data);
|
||||
}
|
||||
|
||||
// --- Declaration.Flags.Id helpers ---
|
||||
@@ -491,11 +491,11 @@ static void getParamBody(Sema* sema, uint32_t param_block_inst,
|
||||
*body_len_out = 0;
|
||||
}
|
||||
|
||||
// coerceIntRef: coerce an integer AIR ref to a target type.
|
||||
// semaCoerceIntRef: coerce an integer AIR ref to a target type.
|
||||
// If the ref points to a comptime_int IP entry and the target type
|
||||
// is a concrete integer type, creates a new IP entry with that type.
|
||||
// Ported from InternPool.getCoercedInts (src/InternPool.zig:10947).
|
||||
static AirInstRef coerceIntRef(
|
||||
static AirInstRef semaCoerceIntRef(
|
||||
Sema* sema, AirInstRef air_ref, TypeIndex target_ty) {
|
||||
// Extract IP index from the AIR ref.
|
||||
uint32_t ip_idx = air_ref; // AIR_REF_FROM_IP is identity
|
||||
@@ -517,7 +517,7 @@ static AirInstRef coerceIntRef(
|
||||
}
|
||||
|
||||
// semaTypeOf: resolve the type of an AIR ref.
|
||||
// Ported from src/Air.zig typeOf / typeOfIndex.
|
||||
// Ported from src/Air.zig semaTypeOf / semaTypeOfIndex.
|
||||
static TypeIndex semaTypeOf(Sema* sema, AirInstRef ref) {
|
||||
if (AIR_REF_IS_IP(ref)) {
|
||||
return ipTypeOf(sema->ip, AIR_REF_TO_IP(ref));
|
||||
@@ -586,9 +586,9 @@ static TypeIndex semaTypeOf(Sema* sema, AirInstRef ref) {
|
||||
}
|
||||
}
|
||||
|
||||
// resolvePeerType: determine the common type of two AIR refs.
|
||||
// Ported from src/Sema.zig resolvePeerTypes (simplified).
|
||||
static TypeIndex resolvePeerType(Sema* sema, AirInstRef lhs, AirInstRef rhs) {
|
||||
// semaResolvePeerTypes: determine the common type of two AIR refs.
|
||||
// Ported from src/Sema.zig semaResolvePeerTypess (simplified).
|
||||
static TypeIndex semaResolvePeerTypes(Sema* sema, AirInstRef lhs, AirInstRef rhs) {
|
||||
TypeIndex lhs_ty = semaTypeOf(sema, lhs);
|
||||
TypeIndex rhs_ty = semaTypeOf(sema, rhs);
|
||||
if (lhs_ty == rhs_ty)
|
||||
@@ -600,7 +600,7 @@ static TypeIndex resolvePeerType(Sema* sema, AirInstRef lhs, AirInstRef rhs) {
|
||||
// When both types are concrete int types and one operand is
|
||||
// comptime-known, use the other (runtime) type. The comptime value
|
||||
// can be coerced to the runtime type during semaCoerce.
|
||||
// Ported from src/Sema.zig resolvePeerTypes peer_resolve_int_int.
|
||||
// Ported from src/Sema.zig semaResolvePeerTypess peer_resolve_int_int.
|
||||
if (sema->ip->items[lhs_ty].tag == IP_KEY_INT_TYPE
|
||||
&& sema->ip->items[rhs_ty].tag == IP_KEY_INT_TYPE) {
|
||||
if (AIR_REF_IS_IP(lhs))
|
||||
@@ -613,7 +613,7 @@ static TypeIndex resolvePeerType(Sema* sema, AirInstRef lhs, AirInstRef rhs) {
|
||||
return lhs_ty;
|
||||
}
|
||||
|
||||
// coerce: coerce an AIR ref to a target type.
|
||||
// semaCoerce: coerce an AIR ref to a target type.
|
||||
// Ported from src/Sema.zig coerce (simplified).
|
||||
static AirInstRef semaCoerce(
|
||||
Sema* sema, SemaBlock* block, TypeIndex target_ty, AirInstRef ref) {
|
||||
@@ -621,11 +621,11 @@ static AirInstRef semaCoerce(
|
||||
if (src_ty == target_ty)
|
||||
return ref;
|
||||
if (src_ty == IP_INDEX_COMPTIME_INT_TYPE)
|
||||
return coerceIntRef(sema, ref, target_ty);
|
||||
return semaCoerceIntRef(sema, ref, target_ty);
|
||||
// Comptime int→int coercion: re-intern with target type.
|
||||
if (AIR_REF_IS_IP(ref) && sema->ip->items[src_ty].tag == IP_KEY_INT_TYPE
|
||||
&& sema->ip->items[target_ty].tag == IP_KEY_INT_TYPE) {
|
||||
return coerceIntRef(sema, ref, target_ty);
|
||||
return semaCoerceIntRef(sema, ref, target_ty);
|
||||
}
|
||||
// Runtime int→int coercion: emit intcast.
|
||||
if (AIR_REF_IS_INST(ref) && sema->ip->items[src_ty].tag == IP_KEY_INT_TYPE
|
||||
@@ -634,7 +634,7 @@ static AirInstRef semaCoerce(
|
||||
memset(&data, 0, sizeof(data));
|
||||
data.ty_op.ty_ref = AIR_REF_FROM_IP(target_ty);
|
||||
data.ty_op.operand = ref;
|
||||
return blockAddInst(block, AIR_INST_INTCAST, data);
|
||||
return semaAddInst(block, AIR_INST_INTCAST, data);
|
||||
}
|
||||
// For unsupported type combinations (e.g. type→void during comptime
|
||||
// analysis of generic functions), return the operand unchanged.
|
||||
@@ -664,7 +664,7 @@ static void zirStoreNode(Sema* sema, SemaBlock* block, uint32_t inst) {
|
||||
memset(&data, 0, sizeof(data));
|
||||
data.bin_op.lhs = ptr;
|
||||
data.bin_op.rhs = val;
|
||||
(void)blockAddInst(block, AIR_INST_STORE, data);
|
||||
(void)semaAddInst(block, AIR_INST_STORE, data);
|
||||
}
|
||||
|
||||
// zirLoad: handle load ZIR instruction (pointer dereference).
|
||||
@@ -678,7 +678,7 @@ static AirInstRef zirLoad(Sema* sema, SemaBlock* block, uint32_t inst) {
|
||||
memset(&data, 0, sizeof(data));
|
||||
data.ty_op.ty_ref = AIR_REF_FROM_IP(elem_ty);
|
||||
data.ty_op.operand = ptr;
|
||||
return blockAddInst(block, AIR_INST_LOAD, data);
|
||||
return semaAddInst(block, AIR_INST_LOAD, data);
|
||||
}
|
||||
|
||||
// zirNegate: handle negate ZIR instruction (unary -).
|
||||
@@ -700,7 +700,7 @@ static AirInstRef zirNegate(Sema* sema, SemaBlock* block, uint32_t inst) {
|
||||
memset(&data, 0, sizeof(data));
|
||||
data.bin_op.lhs = zero;
|
||||
data.bin_op.rhs = operand;
|
||||
return blockAddInst(block, AIR_INST_SUB, data);
|
||||
return semaAddInst(block, AIR_INST_SUB, data);
|
||||
}
|
||||
|
||||
// zirNegateWrap: handle negate_wrap ZIR instruction (wrapping unary -).
|
||||
@@ -721,7 +721,7 @@ static AirInstRef zirNegateWrap(Sema* sema, SemaBlock* block, uint32_t inst) {
|
||||
memset(&data, 0, sizeof(data));
|
||||
data.bin_op.lhs = zero;
|
||||
data.bin_op.rhs = operand;
|
||||
return blockAddInst(block, AIR_INST_SUB_WRAP, data);
|
||||
return semaAddInst(block, AIR_INST_SUB_WRAP, data);
|
||||
}
|
||||
|
||||
// zirBitNot: handle bit_not ZIR instruction (bitwise ~).
|
||||
@@ -734,7 +734,7 @@ static AirInstRef zirBitNot(Sema* sema, SemaBlock* block, uint32_t inst) {
|
||||
memset(&data, 0, sizeof(data));
|
||||
data.ty_op.ty_ref = AIR_REF_FROM_IP(ty);
|
||||
data.ty_op.operand = operand;
|
||||
return blockAddInst(block, AIR_INST_NOT, data);
|
||||
return semaAddInst(block, AIR_INST_NOT, data);
|
||||
}
|
||||
|
||||
// zirBoolNot: handle bool_not ZIR instruction.
|
||||
@@ -747,7 +747,7 @@ static AirInstRef zirBoolNot(Sema* sema, SemaBlock* block, uint32_t inst) {
|
||||
memset(&data, 0, sizeof(data));
|
||||
data.ty_op.ty_ref = AIR_REF_FROM_IP(IP_INDEX_BOOL_TYPE);
|
||||
data.ty_op.operand = operand;
|
||||
return blockAddInst(block, AIR_INST_NOT, data);
|
||||
return semaAddInst(block, AIR_INST_NOT, data);
|
||||
}
|
||||
|
||||
// zirIntFromBool: handle int_from_bool ZIR instruction (@intFromBool).
|
||||
@@ -760,7 +760,7 @@ static AirInstRef zirIntFromBool(Sema* sema, SemaBlock* block, uint32_t inst) {
|
||||
memset(&data, 0, sizeof(data));
|
||||
data.ty_op.ty_ref = AIR_REF_FROM_IP(IP_INDEX_U1_TYPE);
|
||||
data.ty_op.operand = operand;
|
||||
return blockAddInst(block, AIR_INST_BITCAST, data);
|
||||
return semaAddInst(block, AIR_INST_BITCAST, data);
|
||||
}
|
||||
|
||||
// isComptimeInt: check if an AIR ref is a comptime integer value.
|
||||
@@ -872,7 +872,7 @@ static AirInstRef zirBitCount(
|
||||
memset(&data, 0, sizeof(data));
|
||||
data.ty_op.ty_ref = AIR_REF_FROM_IP(result_ty);
|
||||
data.ty_op.operand = operand;
|
||||
return blockAddInst(block, air_tag, data);
|
||||
return semaAddInst(block, air_tag, data);
|
||||
}
|
||||
|
||||
// zirByteSwap: handle byte_swap ZIR instruction (@byteSwap).
|
||||
@@ -885,7 +885,7 @@ static AirInstRef zirByteSwap(Sema* sema, SemaBlock* block, uint32_t inst) {
|
||||
memset(&data, 0, sizeof(data));
|
||||
data.ty_op.ty_ref = AIR_REF_FROM_IP(operand_ty);
|
||||
data.ty_op.operand = operand;
|
||||
return blockAddInst(block, AIR_INST_BYTE_SWAP, data);
|
||||
return semaAddInst(block, AIR_INST_BYTE_SWAP, data);
|
||||
}
|
||||
|
||||
// zirArithmetic: handle add/sub ZIR instructions.
|
||||
@@ -947,14 +947,14 @@ static AirInstRef zirArithmetic(
|
||||
}
|
||||
|
||||
emit_runtime:;
|
||||
TypeIndex peer_ty = resolvePeerType(sema, lhs, rhs);
|
||||
TypeIndex peer_ty = semaResolvePeerTypes(sema, lhs, rhs);
|
||||
lhs = semaCoerce(sema, block, peer_ty, lhs);
|
||||
rhs = semaCoerce(sema, block, peer_ty, rhs);
|
||||
AirInstData data;
|
||||
memset(&data, 0, sizeof(data));
|
||||
data.bin_op.lhs = lhs;
|
||||
data.bin_op.rhs = rhs;
|
||||
return blockAddInst(block, air_tag, data);
|
||||
return semaAddInst(block, air_tag, data);
|
||||
}
|
||||
|
||||
// zirBitwise: handle bitwise operation ZIR instructions.
|
||||
@@ -995,14 +995,14 @@ static AirInstRef zirBitwise(
|
||||
}
|
||||
|
||||
emit_bitwise_runtime:;
|
||||
TypeIndex peer_ty = resolvePeerType(sema, lhs, rhs);
|
||||
TypeIndex peer_ty = semaResolvePeerTypes(sema, lhs, rhs);
|
||||
lhs = semaCoerce(sema, block, peer_ty, lhs);
|
||||
rhs = semaCoerce(sema, block, peer_ty, rhs);
|
||||
AirInstData data;
|
||||
memset(&data, 0, sizeof(data));
|
||||
data.bin_op.lhs = lhs;
|
||||
data.bin_op.rhs = rhs;
|
||||
return blockAddInst(block, air_tag, data);
|
||||
return semaAddInst(block, air_tag, data);
|
||||
}
|
||||
|
||||
// zirBitcast: handle @bitCast ZIR instruction.
|
||||
@@ -1032,7 +1032,7 @@ static AirInstRef zirBitcast(Sema* sema, SemaBlock* block, uint32_t inst) {
|
||||
memset(&data, 0, sizeof(data));
|
||||
data.ty_op.ty_ref = AIR_REF_FROM_IP(dest_ty);
|
||||
data.ty_op.operand = operand;
|
||||
return blockAddInst(block, AIR_INST_BITCAST, data);
|
||||
return semaAddInst(block, AIR_INST_BITCAST, data);
|
||||
}
|
||||
|
||||
// zirTyOpCast: generic handler for type-changing cast ZIR instructions
|
||||
@@ -1054,7 +1054,7 @@ static AirInstRef zirTyOpCast(
|
||||
memset(&data, 0, sizeof(data));
|
||||
data.ty_op.ty_ref = AIR_REF_FROM_IP(dest_ty);
|
||||
data.ty_op.operand = operand;
|
||||
return blockAddInst(block, air_tag, data);
|
||||
return semaAddInst(block, air_tag, data);
|
||||
}
|
||||
|
||||
// floatBits: get the bit width of a float type from its IP index.
|
||||
@@ -1101,7 +1101,7 @@ static AirInstRef zirFloatCast(Sema* sema, SemaBlock* block, uint32_t inst) {
|
||||
memset(&data, 0, sizeof(data));
|
||||
data.ty_op.ty_ref = AIR_REF_FROM_IP(dest_ty);
|
||||
data.ty_op.operand = operand;
|
||||
return blockAddInst(block, air_tag, data);
|
||||
return semaAddInst(block, air_tag, data);
|
||||
}
|
||||
|
||||
// zirTypeofLog2IntType: compute the log2 integer type for shift amounts.
|
||||
@@ -1190,7 +1190,7 @@ static AirInstRef zirShl(
|
||||
memset(&data, 0, sizeof(data));
|
||||
data.bin_op.lhs = lhs;
|
||||
data.bin_op.rhs = rhs;
|
||||
return blockAddInst(block, air_tag, data);
|
||||
return semaAddInst(block, air_tag, data);
|
||||
}
|
||||
|
||||
// zirAsNode: handle @as ZIR instruction.
|
||||
@@ -2403,7 +2403,7 @@ static AirInstRef zirCall(
|
||||
// need_debug_scope is always false → BLOCK tag.
|
||||
AirInstData rt_dead;
|
||||
memset(&rt_dead, 0, sizeof(rt_dead));
|
||||
addAirInst(sema, AIR_INST_BLOCK, rt_dead);
|
||||
semaAddInstAsIndex(sema, AIR_INST_BLOCK, rt_dead);
|
||||
uint8_t signedness = 0; // 0 = unsigned, 1 = signed
|
||||
uint16_t bits_val = 0;
|
||||
|
||||
@@ -2521,7 +2521,7 @@ static AirInstRef zirCall(
|
||||
AirInstData dummy;
|
||||
memset(&dummy, 0, sizeof(dummy));
|
||||
dummy.ty.ty_ref = AIR_REF_FROM_IP(arg_ty);
|
||||
addAirInst(sema, AIR_INST_ALLOC, dummy);
|
||||
semaAddInstAsIndex(sema, AIR_INST_ALLOC, dummy);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2557,16 +2557,16 @@ static AirInstRef zirCall(
|
||||
InternPoolIndex func_val_ip = ipIntern(sema->ip, fv_key);
|
||||
|
||||
// Emit CALL extra: {args_len, arg_refs[0..args_len]}.
|
||||
uint32_t call_extra = addAirExtra(sema, runtime_args_count);
|
||||
uint32_t call_extra = semaAddExtra(sema, runtime_args_count);
|
||||
for (uint32_t a = 0; a < runtime_args_count; a++)
|
||||
addAirExtra(sema, runtime_arg_refs[a]);
|
||||
semaAddExtra(sema, runtime_arg_refs[a]);
|
||||
|
||||
// Emit CALL instruction.
|
||||
AirInstData call_data;
|
||||
memset(&call_data, 0, sizeof(call_data));
|
||||
call_data.pl_op.operand = AIR_REF_FROM_IP(func_val_ip);
|
||||
call_data.pl_op.payload = call_extra;
|
||||
AirInstRef call_ref = blockAddInst(block, AIR_INST_CALL, call_data);
|
||||
AirInstRef call_ref = semaAddInst(block, AIR_INST_CALL, call_data);
|
||||
|
||||
// Register CALL return type for semaTypeOf.
|
||||
if (sema->num_calls < 16) {
|
||||
@@ -2628,7 +2628,7 @@ static AirInstRef zirCall(
|
||||
= need_debug_scope ? AIR_INST_DBG_INLINE_BLOCK : AIR_INST_BLOCK;
|
||||
|
||||
// Reserve the block instruction (data filled later).
|
||||
uint32_t block_inst_idx = addAirInst(sema, block_tag,
|
||||
uint32_t block_inst_idx = semaAddInstAsIndex(sema, block_tag,
|
||||
(AirInstData) { .ty_pl = { .ty_ref = 0, .payload = 0 } });
|
||||
|
||||
// Set up child block for inlining.
|
||||
@@ -2699,7 +2699,7 @@ static AirInstRef zirCall(
|
||||
memset(&data, 0, sizeof(data));
|
||||
data.pl_op.operand = arg_refs[param_idx];
|
||||
data.pl_op.payload = name_nts;
|
||||
(void)blockAddInst(
|
||||
(void)semaAddInst(
|
||||
&child_block, AIR_INST_DBG_ARG_INLINE, data);
|
||||
}
|
||||
param_idx++;
|
||||
@@ -2809,10 +2809,10 @@ static AirInstRef zirCall(
|
||||
child_block.instructions[child_block.instructions_len - 1]);
|
||||
} else {
|
||||
// dbg_inline_block: create block with noreturn type.
|
||||
uint32_t es = addAirExtra(sema, inlining.func);
|
||||
addAirExtra(sema, child_block.instructions_len);
|
||||
uint32_t es = semaAddExtra(sema, inlining.func);
|
||||
semaAddExtra(sema, child_block.instructions_len);
|
||||
for (uint32_t i = 0; i < child_block.instructions_len; i++)
|
||||
addAirExtra(sema, child_block.instructions[i]);
|
||||
semaAddExtra(sema, child_block.instructions[i]);
|
||||
sema->air_inst_datas[block_inst_idx].ty_pl.ty_ref
|
||||
= AIR_REF_FROM_IP(IP_INDEX_NORETURN_TYPE);
|
||||
sema->air_inst_datas[block_inst_idx].ty_pl.payload = es;
|
||||
@@ -2855,13 +2855,13 @@ static AirInstRef zirCall(
|
||||
// Ported from resolveAnalyzedBlock lines 6031-6062.
|
||||
uint32_t es;
|
||||
if (need_debug_scope) {
|
||||
es = addAirExtra(sema, inlining.func);
|
||||
addAirExtra(sema, child_block.instructions_len);
|
||||
es = semaAddExtra(sema, inlining.func);
|
||||
semaAddExtra(sema, child_block.instructions_len);
|
||||
} else {
|
||||
es = addAirExtra(sema, child_block.instructions_len);
|
||||
es = semaAddExtra(sema, child_block.instructions_len);
|
||||
}
|
||||
for (uint32_t i = 0; i < child_block.instructions_len; i++)
|
||||
addAirExtra(sema, child_block.instructions[i]);
|
||||
semaAddExtra(sema, child_block.instructions[i]);
|
||||
sema->air_inst_datas[block_inst_idx].ty_pl.ty_ref
|
||||
= AIR_REF_FROM_IP(IP_INDEX_VOID_TYPE);
|
||||
sema->air_inst_datas[block_inst_idx].ty_pl.payload = es;
|
||||
@@ -2884,13 +2884,13 @@ static AirInstRef zirCall(
|
||||
TypeIndex rty = semaTypeOf(sema, result_ref);
|
||||
uint32_t es;
|
||||
if (need_debug_scope) {
|
||||
es = addAirExtra(sema, inlining.func);
|
||||
addAirExtra(sema, child_block.instructions_len);
|
||||
es = semaAddExtra(sema, inlining.func);
|
||||
semaAddExtra(sema, child_block.instructions_len);
|
||||
} else {
|
||||
es = addAirExtra(sema, child_block.instructions_len);
|
||||
es = semaAddExtra(sema, child_block.instructions_len);
|
||||
}
|
||||
for (uint32_t i = 0; i < child_block.instructions_len; i++)
|
||||
addAirExtra(sema, child_block.instructions[i]);
|
||||
semaAddExtra(sema, child_block.instructions[i]);
|
||||
sema->air_inst_datas[block_inst_idx].ty_pl.ty_ref
|
||||
= AIR_REF_FROM_IP(rty);
|
||||
sema->air_inst_datas[block_inst_idx].ty_pl.payload = es;
|
||||
@@ -2910,13 +2910,13 @@ static AirInstRef zirCall(
|
||||
TypeIndex rty = semaTypeOf(sema, result_ref);
|
||||
uint32_t es;
|
||||
if (need_debug_scope) {
|
||||
es = addAirExtra(sema, inlining.func);
|
||||
addAirExtra(sema, child_block.instructions_len);
|
||||
es = semaAddExtra(sema, inlining.func);
|
||||
semaAddExtra(sema, child_block.instructions_len);
|
||||
} else {
|
||||
es = addAirExtra(sema, child_block.instructions_len);
|
||||
es = semaAddExtra(sema, child_block.instructions_len);
|
||||
}
|
||||
for (uint32_t i = 0; i < child_block.instructions_len; i++)
|
||||
addAirExtra(sema, child_block.instructions[i]);
|
||||
semaAddExtra(sema, child_block.instructions[i]);
|
||||
sema->air_inst_datas[block_inst_idx].ty_pl.ty_ref
|
||||
= AIR_REF_FROM_IP(rty);
|
||||
sema->air_inst_datas[block_inst_idx].ty_pl.payload = es;
|
||||
@@ -3057,7 +3057,7 @@ static void zirFunc(Sema* sema, SemaBlock* block, uint32_t inst) {
|
||||
sema->num_calls = 0;
|
||||
|
||||
// Reserve extra[0] for main_block index (Air.ExtraIndex.main_block).
|
||||
addAirExtra(sema, 0);
|
||||
semaAddExtra(sema, 0);
|
||||
|
||||
// Resolve the function return type.
|
||||
// Ported from src/Sema.zig zirFunc (lines 8869-8885).
|
||||
@@ -3196,7 +3196,7 @@ static void zirFunc(Sema* sema, SemaBlock* block, uint32_t inst) {
|
||||
memset(&arg_data, 0, sizeof(arg_data));
|
||||
arg_data.arg.ty_ref = AIR_REF_FROM_IP(param_ty);
|
||||
arg_data.arg.zir_param_index = runtime_param_index;
|
||||
AirInstRef arg_ref = blockAddInst(&fn_block, AIR_INST_ARG, arg_data);
|
||||
AirInstRef arg_ref = semaAddInst(&fn_block, AIR_INST_ARG, arg_data);
|
||||
|
||||
// Map param ZIR inst → arg AIR ref.
|
||||
instMapPut(&sema->inst_map, param_inst, arg_ref);
|
||||
@@ -3209,9 +3209,9 @@ static void zirFunc(Sema* sema, SemaBlock* block, uint32_t inst) {
|
||||
|
||||
// --- Write main block to extra ---
|
||||
// Layout: AirBlock{body_len}, then body_len instruction indices.
|
||||
uint32_t main_block_extra = addAirExtra(sema, fn_block.instructions_len);
|
||||
uint32_t main_block_extra = semaAddExtra(sema, fn_block.instructions_len);
|
||||
for (uint32_t i = 0; i < fn_block.instructions_len; i++) {
|
||||
addAirExtra(sema, fn_block.instructions[i]);
|
||||
semaAddExtra(sema, fn_block.instructions[i]);
|
||||
}
|
||||
// Patch extra[0] = main_block index.
|
||||
sema->air_extra[0] = main_block_extra;
|
||||
@@ -3431,12 +3431,12 @@ static AirInstRef zirTypeof(Sema* sema, uint32_t inst) {
|
||||
return AIR_REF_FROM_IP(ty);
|
||||
}
|
||||
|
||||
// zirSwitchBlockComptime: handle switch_block on a comptime-known value.
|
||||
// Ported from src/Sema.zig resolveSwitchComptime (simplified).
|
||||
// semaResolveSwitchComptime: handle switch_block on a comptime-known value.
|
||||
// Ported from src/Sema.zig semaResolveSwitchComptime (simplified).
|
||||
// Parses the SwitchBlock extra data, finds the matching scalar case or
|
||||
// falls back to the else prong, then analyzes the matching body.
|
||||
// Returns the result value from the matched break instruction.
|
||||
static AirInstRef zirSwitchBlockComptime(
|
||||
static AirInstRef semaResolveSwitchComptime(
|
||||
Sema* sema, SemaBlock* block, uint32_t inst) {
|
||||
uint32_t payload_index = sema->code.inst_datas[inst].pl_node.payload_index;
|
||||
ZirInstRef operand_ref = sema->code.extra[payload_index];
|
||||
@@ -3540,7 +3540,7 @@ static AirInstRef zirSwitchBlockComptime(
|
||||
// debug undefined pattern.
|
||||
AirInstData block_data;
|
||||
memset(&block_data, 0xaa, sizeof(block_data));
|
||||
uint32_t block_inst = addAirInst(sema, AIR_INST_BLOCK, block_data);
|
||||
uint32_t block_inst = semaAddInstAsIndex(sema, AIR_INST_BLOCK, block_data);
|
||||
|
||||
// Set up a label so break can find this block.
|
||||
SemaBlockLabel label;
|
||||
@@ -3594,7 +3594,7 @@ static AirInstRef zirSwitchBlockComptime(
|
||||
// Reserve BLOCK instruction (same as scalar case above).
|
||||
AirInstData block_data;
|
||||
memset(&block_data, 0xaa, sizeof(block_data));
|
||||
uint32_t block_inst = addAirInst(sema, AIR_INST_BLOCK, block_data);
|
||||
uint32_t block_inst = semaAddInstAsIndex(sema, AIR_INST_BLOCK, block_data);
|
||||
|
||||
SemaBlockLabel label;
|
||||
memset(&label, 0, sizeof(label));
|
||||
@@ -4022,7 +4022,7 @@ static bool analyzeBodyInner(
|
||||
AirInstData ret_data;
|
||||
memset(&ret_data, 0, sizeof(ret_data));
|
||||
ret_data.un_op.operand = AIR_REF_FROM_IP(IP_INDEX_VOID_VALUE);
|
||||
(void)blockAddInst(block, AIR_INST_RET, ret_data);
|
||||
(void)semaAddInst(block, AIR_INST_RET, ret_data);
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -4050,7 +4050,7 @@ static bool analyzeBodyInner(
|
||||
memset(&br_data, 0, sizeof(br_data));
|
||||
br_data.br.block_inst = inl->merges.block_inst;
|
||||
br_data.br.operand = operand;
|
||||
AirInstRef br_ref = blockAddInst(block, AIR_INST_BR, br_data);
|
||||
AirInstRef br_ref = semaAddInst(block, AIR_INST_BR, br_data);
|
||||
// Record merge result and br instruction.
|
||||
if (inl->merges.results_len >= inl->merges.results_cap) {
|
||||
uint32_t new_cap = (inl->merges.results_cap == 0)
|
||||
@@ -4075,7 +4075,7 @@ static bool analyzeBodyInner(
|
||||
memset(&ret_data, 0, sizeof(ret_data));
|
||||
ret_data.un_op.operand = operand;
|
||||
// ReleaseFast: use ret, not ret_safe (no safety checks).
|
||||
(void)blockAddInst(block, AIR_INST_RET, ret_data);
|
||||
(void)semaAddInst(block, AIR_INST_RET, ret_data);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -4223,7 +4223,7 @@ static bool analyzeBodyInner(
|
||||
= block->instructions_len - block_index;
|
||||
|
||||
// Reserve an AIR block instruction.
|
||||
uint32_t blk_inst = addAirInst(sema, AIR_INST_BLOCK,
|
||||
uint32_t blk_inst = semaAddInstAsIndex(sema, AIR_INST_BLOCK,
|
||||
(AirInstData) { .ty_pl = { .ty_ref = 0, .payload = 0 } });
|
||||
|
||||
// Add a BR to exit the block with void_value.
|
||||
@@ -4231,16 +4231,16 @@ static bool analyzeBodyInner(
|
||||
memset(&br_data, 0, sizeof(br_data));
|
||||
br_data.br.block_inst = blk_inst;
|
||||
br_data.br.operand = AIR_REF_FROM_IP(IP_INDEX_VOID_VALUE);
|
||||
uint32_t br_inst = addAirInst(sema, AIR_INST_BR, br_data);
|
||||
uint32_t br_inst = semaAddInstAsIndex(sema, AIR_INST_BR, br_data);
|
||||
|
||||
// Write block extra: body_len2, then body insts.
|
||||
uint32_t body_len2 = new_insts_count + 1; // +1 for BR
|
||||
uint32_t extra_start = addAirExtra(sema, body_len2);
|
||||
uint32_t extra_start = semaAddExtra(sema, body_len2);
|
||||
for (uint32_t ci = block_index; ci < block->instructions_len;
|
||||
ci++) {
|
||||
addAirExtra(sema, block->instructions[ci]);
|
||||
semaAddExtra(sema, block->instructions[ci]);
|
||||
}
|
||||
addAirExtra(sema, br_inst);
|
||||
semaAddExtra(sema, br_inst);
|
||||
|
||||
// Patch the BLOCK instruction data.
|
||||
sema->air_inst_datas[blk_inst].ty_pl.ty_ref
|
||||
@@ -4567,7 +4567,7 @@ static bool analyzeBodyInner(
|
||||
AirInstData d;
|
||||
memset(&d, 0, sizeof(d));
|
||||
d.ty.ty_ref = AIR_REF_FROM_IP(ptr_ty);
|
||||
AirInstRef ref = blockAddInst(block, AIR_INST_ALLOC, d);
|
||||
AirInstRef ref = semaAddInst(block, AIR_INST_ALLOC, d);
|
||||
instMapPut(&sema->inst_map, inst, ref);
|
||||
i++;
|
||||
continue;
|
||||
@@ -4711,7 +4711,7 @@ static bool analyzeBodyInner(
|
||||
// switch_block: comptime switch on a known value.
|
||||
case ZIR_INST_SWITCH_BLOCK:
|
||||
instMapPut(&sema->inst_map, inst,
|
||||
zirSwitchBlockComptime(sema, block, inst));
|
||||
semaResolveSwitchComptime(sema, block, inst));
|
||||
i++;
|
||||
continue;
|
||||
|
||||
@@ -4776,7 +4776,7 @@ static bool analyzeBodyInner(
|
||||
memset(&data, 0, sizeof(data));
|
||||
data.ty.ty_ref = AIR_REF_FROM_IP(ptr_ty);
|
||||
instMapPut(&sema->inst_map, inst,
|
||||
blockAddInst(block, AIR_INST_ALLOC, data));
|
||||
semaAddInst(block, AIR_INST_ALLOC, data));
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
@@ -4792,7 +4792,7 @@ static bool analyzeBodyInner(
|
||||
memset(&data, 0, sizeof(data));
|
||||
// data: alignment=none (0), is_const=false (0)
|
||||
AirInstRef air_ref
|
||||
= blockAddInst(block, AIR_INST_INFERRED_ALLOC, data);
|
||||
= semaAddInst(block, AIR_INST_INFERRED_ALLOC, data);
|
||||
instMapPut(&sema->inst_map, inst, air_ref);
|
||||
// Track for resolve_inferred_alloc.
|
||||
assert(sema->num_ia < 16);
|
||||
@@ -4819,7 +4819,7 @@ static bool analyzeBodyInner(
|
||||
memset(&data, 0, sizeof(data));
|
||||
data.bin_op.lhs = ptr;
|
||||
data.bin_op.rhs = val;
|
||||
AirInstRef store_ref = blockAddInst(block, AIR_INST_STORE, data);
|
||||
AirInstRef store_ref = semaAddInst(block, AIR_INST_STORE, data);
|
||||
// Track the store for the inferred alloc.
|
||||
uint32_t ptr_inst = AIR_REF_TO_INST(ptr);
|
||||
for (uint32_t k = 0; k < sema->num_ia; k++) {
|
||||
@@ -4891,7 +4891,7 @@ static bool analyzeBodyInner(
|
||||
store_data.bin_op.lhs = store_lhs;
|
||||
store_data.bin_op.rhs = coerced;
|
||||
uint32_t new_store_idx
|
||||
= addAirInst(sema, AIR_INST_STORE, store_data);
|
||||
= semaAddInstAsIndex(sema, AIR_INST_STORE, store_data);
|
||||
// Patch the placeholder store with the replacement.
|
||||
sema->air_inst_tags[store_inst]
|
||||
= sema->air_inst_tags[new_store_idx];
|
||||
@@ -4976,7 +4976,7 @@ static bool analyzeBodyInner(
|
||||
|
||||
// Runtime block: reserve an AIR block instruction
|
||||
// (data filled later).
|
||||
uint32_t block_inst_idx = addAirInst(sema, AIR_INST_BLOCK,
|
||||
uint32_t block_inst_idx = semaAddInstAsIndex(sema, AIR_INST_BLOCK,
|
||||
(AirInstData) { .ty_pl = { .ty_ref = 0, .payload = 0 } });
|
||||
|
||||
// Set up label so break instructions can find this block.
|
||||
@@ -5077,10 +5077,10 @@ static bool analyzeBodyInner(
|
||||
= block_inst_idx;
|
||||
|
||||
uint32_t extra_start
|
||||
= addAirExtra(sema, child_block.instructions_len);
|
||||
= semaAddExtra(sema, child_block.instructions_len);
|
||||
for (uint32_t ci = 0; ci < child_block.instructions_len;
|
||||
ci++) {
|
||||
addAirExtra(sema, child_block.instructions[ci]);
|
||||
semaAddExtra(sema, child_block.instructions[ci]);
|
||||
}
|
||||
sema->air_inst_datas[block_inst_idx].ty_pl.ty_ref
|
||||
= AIR_REF_FROM_IP(IP_INDEX_VOID_TYPE);
|
||||
@@ -5107,14 +5107,14 @@ static bool analyzeBodyInner(
|
||||
block->instructions[block->instructions_len++]
|
||||
= block_inst_idx;
|
||||
|
||||
TypeIndex resolved_ty = resolvePeerType(
|
||||
TypeIndex resolved_ty = semaResolvePeerTypes(
|
||||
sema, label.merges.results[0], label.merges.results[1]);
|
||||
|
||||
uint32_t extra_start
|
||||
= addAirExtra(sema, child_block.instructions_len);
|
||||
= semaAddExtra(sema, child_block.instructions_len);
|
||||
for (uint32_t ci = 0; ci < child_block.instructions_len;
|
||||
ci++) {
|
||||
addAirExtra(sema, child_block.instructions[ci]);
|
||||
semaAddExtra(sema, child_block.instructions[ci]);
|
||||
}
|
||||
sema->air_inst_datas[block_inst_idx].ty_pl.ty_ref
|
||||
= AIR_REF_FROM_IP(resolved_ty);
|
||||
@@ -5153,16 +5153,16 @@ static bool analyzeBodyInner(
|
||||
- 1]
|
||||
== AIR_REF_TO_INST(coerced));
|
||||
uint32_t sub_bl = coerce_block.instructions_len + 1;
|
||||
uint32_t sub_br_idx = addAirInst(sema, AIR_INST_BR,
|
||||
uint32_t sub_br_idx = semaAddInstAsIndex(sema, AIR_INST_BR,
|
||||
(AirInstData) {
|
||||
.br = { .block_inst = label.merges.block_inst,
|
||||
.operand = coerced } });
|
||||
uint32_t sub_extra = addAirExtra(sema, sub_bl);
|
||||
uint32_t sub_extra = semaAddExtra(sema, sub_bl);
|
||||
for (uint32_t si = 0;
|
||||
si < coerce_block.instructions_len; si++) {
|
||||
addAirExtra(sema, coerce_block.instructions[si]);
|
||||
semaAddExtra(sema, coerce_block.instructions[si]);
|
||||
}
|
||||
addAirExtra(sema, sub_br_idx);
|
||||
semaAddExtra(sema, sub_br_idx);
|
||||
sema->air_inst_tags[br] = AIR_INST_BLOCK;
|
||||
sema->air_inst_datas[br].ty_pl.ty_ref
|
||||
= AIR_REF_FROM_IP(resolved_ty);
|
||||
@@ -5231,7 +5231,7 @@ static bool analyzeBodyInner(
|
||||
}
|
||||
|
||||
// Runtime: emit BLOCK(bool) + COND_BR with then/else bodies.
|
||||
uint32_t block_inst_idx = addAirInst(sema, AIR_INST_BLOCK,
|
||||
uint32_t block_inst_idx = semaAddInstAsIndex(sema, AIR_INST_BLOCK,
|
||||
(AirInstData) {
|
||||
.ty_pl = { .ty_ref = AIR_REF_FROM_IP(IP_INDEX_BOOL_TYPE),
|
||||
.payload = 0 } });
|
||||
@@ -5282,7 +5282,7 @@ static bool analyzeBodyInner(
|
||||
br_data.br.block_inst = block_inst_idx;
|
||||
br_data.br.operand = lhs_result;
|
||||
AirInstRef br_ref
|
||||
= blockAddInst(lhs_block, AIR_INST_BR, br_data);
|
||||
= semaAddInst(lhs_block, AIR_INST_BR, br_data);
|
||||
mergesAppend(
|
||||
&label.merges, lhs_result, AIR_REF_TO_INST(br_ref));
|
||||
}
|
||||
@@ -5313,7 +5313,7 @@ static bool analyzeBodyInner(
|
||||
br_data.br.block_inst = block_inst_idx;
|
||||
br_data.br.operand = rhs_result;
|
||||
AirInstRef br_ref
|
||||
= blockAddInst(rhs_block, AIR_INST_BR, br_data);
|
||||
= semaAddInst(rhs_block, AIR_INST_BR, br_data);
|
||||
mergesAppend(
|
||||
&label.merges, rhs_result, AIR_REF_TO_INST(br_ref));
|
||||
}
|
||||
@@ -5324,8 +5324,8 @@ static bool analyzeBodyInner(
|
||||
|
||||
// Emit COND_BR in child_block.
|
||||
uint32_t extra_start
|
||||
= addAirExtra(sema, then_block.instructions_len);
|
||||
addAirExtra(sema, else_block.instructions_len);
|
||||
= semaAddExtra(sema, then_block.instructions_len);
|
||||
semaAddExtra(sema, else_block.instructions_len);
|
||||
// Branch hints.
|
||||
uint32_t branch_hints_packed = 0;
|
||||
if (is_bool_or) {
|
||||
@@ -5337,20 +5337,20 @@ static bool analyzeBodyInner(
|
||||
}
|
||||
branch_hints_packed |= (1u << 6); // then_cov = poi
|
||||
branch_hints_packed |= (1u << 7); // else_cov = poi
|
||||
addAirExtra(sema, branch_hints_packed);
|
||||
semaAddExtra(sema, branch_hints_packed);
|
||||
|
||||
for (uint32_t ti = 0; ti < then_block.instructions_len; ti++) {
|
||||
addAirExtra(sema, then_block.instructions[ti]);
|
||||
semaAddExtra(sema, then_block.instructions[ti]);
|
||||
}
|
||||
for (uint32_t ei = 0; ei < else_block.instructions_len; ei++) {
|
||||
addAirExtra(sema, else_block.instructions[ei]);
|
||||
semaAddExtra(sema, else_block.instructions[ei]);
|
||||
}
|
||||
|
||||
AirInstData cond_data;
|
||||
memset(&cond_data, 0, sizeof(cond_data));
|
||||
cond_data.pl_op.operand = lhs;
|
||||
cond_data.pl_op.payload = extra_start;
|
||||
(void)blockAddInst(&child_block, AIR_INST_COND_BR, cond_data);
|
||||
(void)semaAddInst(&child_block, AIR_INST_COND_BR, cond_data);
|
||||
|
||||
// Resolve the block (same as zirBlock resolveAnalyzedBlock).
|
||||
// bool_br always has 2 merges (lhs + rhs BR).
|
||||
@@ -5365,9 +5365,9 @@ static bool analyzeBodyInner(
|
||||
block->instructions[block->instructions_len++] = block_inst_idx;
|
||||
|
||||
uint32_t blk_extra_start
|
||||
= addAirExtra(sema, child_block.instructions_len);
|
||||
= semaAddExtra(sema, child_block.instructions_len);
|
||||
for (uint32_t ci = 0; ci < child_block.instructions_len; ci++) {
|
||||
addAirExtra(sema, child_block.instructions[ci]);
|
||||
semaAddExtra(sema, child_block.instructions[ci]);
|
||||
}
|
||||
sema->air_inst_datas[block_inst_idx].ty_pl.payload
|
||||
= blk_extra_start;
|
||||
@@ -5437,8 +5437,8 @@ static bool analyzeBodyInner(
|
||||
// Extra data: {then_body_len, else_body_len, branch_hints,
|
||||
// then_body[...], else_body[...]}
|
||||
uint32_t extra_start
|
||||
= addAirExtra(sema, then_block.instructions_len);
|
||||
addAirExtra(sema, else_block.instructions_len);
|
||||
= semaAddExtra(sema, then_block.instructions_len);
|
||||
semaAddExtra(sema, else_block.instructions_len);
|
||||
// BranchHints packed struct (u32):
|
||||
// bits [0..2] = true hint (BranchHint, 3 bits)
|
||||
// bits [3..5] = false hint (BranchHint, 3 bits)
|
||||
@@ -5450,20 +5450,20 @@ static bool analyzeBodyInner(
|
||||
branch_hints_packed |= (uint32_t)(false_hint & 0x7) << 3;
|
||||
branch_hints_packed |= (1u << 6); // then_cov = poi
|
||||
branch_hints_packed |= (1u << 7); // else_cov = poi
|
||||
addAirExtra(sema, branch_hints_packed);
|
||||
semaAddExtra(sema, branch_hints_packed);
|
||||
|
||||
for (uint32_t ti = 0; ti < then_block.instructions_len; ti++) {
|
||||
addAirExtra(sema, then_block.instructions[ti]);
|
||||
semaAddExtra(sema, then_block.instructions[ti]);
|
||||
}
|
||||
for (uint32_t ei = 0; ei < else_block.instructions_len; ei++) {
|
||||
addAirExtra(sema, else_block.instructions[ei]);
|
||||
semaAddExtra(sema, else_block.instructions[ei]);
|
||||
}
|
||||
|
||||
AirInstData cond_data;
|
||||
memset(&cond_data, 0, sizeof(cond_data));
|
||||
cond_data.pl_op.operand = cond;
|
||||
cond_data.pl_op.payload = extra_start;
|
||||
(void)blockAddInst(block, AIR_INST_COND_BR, cond_data);
|
||||
(void)semaAddInst(block, AIR_INST_COND_BR, cond_data);
|
||||
|
||||
semaBlockDeinit(&then_block);
|
||||
semaBlockDeinit(&else_block);
|
||||
@@ -5505,7 +5505,7 @@ static bool analyzeBodyInner(
|
||||
memset(&br_data, 0, sizeof(br_data));
|
||||
br_data.br.block_inst = label->merges.block_inst;
|
||||
br_data.br.operand = operand;
|
||||
AirInstRef br_ref = blockAddInst(block, AIR_INST_BR, br_data);
|
||||
AirInstRef br_ref = semaAddInst(block, AIR_INST_BR, br_data);
|
||||
|
||||
// Record merge result.
|
||||
mergesAppend(&label->merges, operand, AIR_REF_TO_INST(br_ref));
|
||||
@@ -5535,7 +5535,7 @@ static bool analyzeBodyInner(
|
||||
// (no unreach — trap is already noreturn).
|
||||
AirInstData trap_data;
|
||||
memset(&trap_data, 0, sizeof(trap_data));
|
||||
(void)blockAddInst(block, AIR_INST_TRAP, trap_data);
|
||||
(void)semaAddInst(block, AIR_INST_TRAP, trap_data);
|
||||
return false; // panic is terminal
|
||||
}
|
||||
|
||||
@@ -5549,7 +5549,7 @@ static bool analyzeBodyInner(
|
||||
}
|
||||
AirInstData data;
|
||||
memset(&data, 0, sizeof(data));
|
||||
(void)blockAddInst(block, AIR_INST_UNREACH, data);
|
||||
(void)semaAddInst(block, AIR_INST_UNREACH, data);
|
||||
return false; // unreachable is terminal
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user