Skip to content

Commit af93c07

Browse files
committed
W27c python#4: emitSend → C body + delegation stub
SEND (mainline) opcode handler. Per W27c Step A scope. C body: hir_builder_emit_send_c (~25 lines). Pops value_out, peeks iter, allocates value_in (stack temp) + is_done (non-stack via hir_func_alloc_register per AllocateNonStack convention), emits Send + GetSecondOutput<TCInt64>, pushes value_in, then cond-branch on is_done to done_block (jump target) or continue_block (next instr). ZERO new bridges. Uses existing primitives + existing hir_builder_get_block_at_off bridge. C primitives used: hir_c_create_send_reg + hir_c_create_get_second_output_reg + hir_c_create_cond_branch + hir_func_alloc_register + hir_builder_temps_alloc_stack + hir_builder_get_block_at_off (all existing). C++ HIRBuilder::emitSend → 5-line delegation stub (passes current_func_ + jump_target/next_instr offset values from bc_instr). Verification: cmake --build target jit/phoenix_jit clean (BUILD_EXIT=0). Sole-path coverage: SEND is mainline-tested per theologian L2521 observation.
1 parent dddb393 commit af93c07

2 files changed

Lines changed: 40 additions & 11 deletions

File tree

‎Python/jit/hir/builder.cpp‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4961,20 +4961,17 @@ void HIRBuilder::emitDictMerge(
49614961
static_cast<void*>(&tc), static_cast<void*>(current_func_), bc_instr.oparg());
49624962
}
49634963

4964+
extern "C" void hir_builder_emit_send_c(
4965+
void *tc, void *func, void *builder,
4966+
int jump_target_off, int next_instr_off);
4967+
49644968
void HIRBuilder::emitSend(
49654969
TranslationContext& tc,
49664970
const BytecodeInstruction& bc_instr) {
4967-
PhxPtrArray& stack = tc.frame.stack;
4968-
Register* value_out = static_cast<Register*>(phx_ptr_arr_pop(&stack));
4969-
Register* iter = static_cast<Register*>(stack.data[stack.count - 1]);
4970-
Register* value_in = temps_.AllocateStack();
4971-
tc.emitSend(iter, value_out, value_in, tc.frame);
4972-
Register* is_done = temps_.AllocateNonStack();
4973-
tc.emitGetSecondOutput(is_done, TCInt64, value_in);
4974-
phx_ptr_arr_push(&stack, value_in);
4975-
BasicBlock* done_block = getBlockAtOff(bc_instr.getJumpTarget());
4976-
BasicBlock* continue_block = getBlockAtOff(bc_instr.nextInstrOffset());
4977-
tc.emitCondBranch(is_done, done_block, continue_block);
4971+
hir_builder_emit_send_c(
4972+
&tc, current_func_, this,
4973+
bc_instr.getJumpTarget().value(),
4974+
bc_instr.nextInstrOffset().value());
49784975
}
49794976

49804977
extern "C" void hir_builder_emit_build_interpolation_c(void *tc, void *func, int oparg);

‎Python/jit/hir/builder_emit_c.c‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4166,4 +4166,36 @@ void hir_builder_emit_before_with_c(
41664166
phx_ptr_arr_push(&tc->frame.stack, enter_result);
41674167
}
41684168

4169+
/* W27c #4: emitSend (SEND opcode, mainline). Mirrors C++
4170+
* HIRBuilder::emitSend @ builder.cpp:4964.
4171+
*
4172+
* Pops value_out, peeks iter (stays on stack), allocs value_in + is_done,
4173+
* emits Send + GetSecondOutput<TCInt64>, pushes value_in, then cond-branch
4174+
* on is_done to (jump_target_block, next_instr_block) — both resolved by
4175+
* C++ stub via getBlockAtOff. */
4176+
extern void *hir_builder_get_block_at_off(void *builder, int byte_offset);
4177+
4178+
void hir_builder_emit_send_c(
4179+
PhxTranslationContext *tc,
4180+
void *func,
4181+
void *builder,
4182+
int jump_target_off,
4183+
int next_instr_off) {
4184+
void *value_out = phx_ptr_arr_pop(&tc->frame.stack);
4185+
void *iter = tc->frame.stack.data[tc->frame.stack.count - 1]; /* peek */
4186+
void *value_in = hir_builder_temps_alloc_stack(builder);
4187+
phx_tc_emit(tc, hir_c_create_send_reg(iter, value_out, value_in, &tc->frame));
4188+
/* AllocateNonStack equivalent: hir_func_alloc_register per
4189+
* builder_emit_c.c:929 convention. Avoids stack-temp tracking. */
4190+
void *is_done = hir_func_alloc_register(func);
4191+
HirType t_cint64 = HIR_TYPE_CINT64;
4192+
phx_tc_emit(tc, hir_c_create_get_second_output_reg(
4193+
is_done, t_cint64, value_in));
4194+
phx_ptr_arr_push(&tc->frame.stack, value_in);
4195+
4196+
void *done_block = hir_builder_get_block_at_off(builder, jump_target_off);
4197+
void *continue_block = hir_builder_get_block_at_off(builder, next_instr_off);
4198+
phx_tc_emit(tc, hir_c_create_cond_branch(is_done, done_block, continue_block));
4199+
}
4200+
41694201

0 commit comments

Comments
 (0)