Skip to content

Commit 194456f

Browse files
committed
simplify: re-port GetLength with proper DeoptBase PrimitiveBox
Uses hir_c_create_primitive_box (full DeoptBase version with func+frame_state), not _reg variant which lacks DeoptBase init. Also fixes PrimitiveBoxBool helper to use _bool_reg variant. 14/14 modules, 980/980 tests PASS.
1 parent 02ac609 commit 194456f

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

Python/jit/hir/simplify.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2772,8 +2772,12 @@ Register* simplifyInstr(Env& env, const Instr* instr) {
27722772
return r;
27732773
}
27742774

2775-
case Opcode::kGetLength:
2776-
return simplifyGetLength(env, instr);
2775+
case Opcode::kGetLength: {
2776+
SimplifyEnv cenv = make_c_env();
2777+
auto *r = static_cast<Register*>(simplify_get_length_c(&cenv, instr));
2778+
sync_c_env(cenv);
2779+
return r;
2780+
}
27772781

27782782
case Opcode::kIntConvert: {
27792783
SimplifyEnv cenv = make_c_env();

Python/jit/hir/simplify_c.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,8 @@ void *simplify_env_emit_long_compare(SimplifyEnv *env, int32_t op,
115115

116116
void *simplify_env_emit_primitive_box_bool(SimplifyEnv *env, void *src) {
117117
void *reg = hir_func_alloc_register(env->func);
118-
extern void *hir_c_create_primitive_box(void *dst, void *src, HirType type);
119-
HirType t_cbool = HIR_TYPE_CBOOL;
120-
void *instr = hir_c_create_primitive_box(reg, src, t_cbool);
118+
extern void *hir_c_create_primitive_box_bool_reg(void *dst, void *src);
119+
void *instr = hir_c_create_primitive_box_bool_reg(reg, src);
121120
return simplify_env_emit(env, instr);
122121
}
123122

@@ -199,6 +198,20 @@ void *simplify_env_emit_check_neg(SimplifyEnv *env, void *src, void *frame_state
199198
return simplify_env_emit(env, instr);
200199
}
201200

201+
/* ---- simplifyGetLength ----
202+
* If obj is a collection with known length field, emit LoadField + PrimitiveBox. */
203+
void *simplify_get_length_c(SimplifyEnv *env, const void *instr) {
204+
void *obj = hir_c_get_operand(instr, 0);
205+
void *size = emit_get_length_int64_c(env, obj);
206+
if (size == NULL) return NULL;
207+
208+
void *fs = hir_c_get_frame_state(instr);
209+
HirType t_cint64 = HIR_TYPE_CINT64;
210+
extern void *hir_c_create_primitive_box(void *func, void *src, HirType type, void *fs);
211+
void *box = hir_c_create_primitive_box(env->func, size, t_cint64, fs);
212+
return simplify_env_emit(env, box);
213+
}
214+
202215
/* ---- simplifyStoreSubscr ----
203216
* If target is DictExact, call mp_ass_subscript directly + check_neg. */
204217
void *simplify_store_subscr_c(SimplifyEnv *env, const void *instr) {

Python/jit/hir/simplify_c.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ void *simplify_cint_to_cbool_c(SimplifyEnv *env, const void *instr);
4545
void *simplify_cond_branch_const_c(SimplifyEnv *env, const void *instr);
4646
void *simplify_compare_c(SimplifyEnv *env, const void *instr);
4747
void *simplify_is_neg_and_err_c(SimplifyEnv *env, const void *instr);
48+
void *simplify_get_length_c(SimplifyEnv *env, const void *instr);
4849
void *simplify_store_subscr_c(SimplifyEnv *env, const void *instr);
4950
void *simplify_load_var_object_size_c(SimplifyEnv *env, const void *instr);
5051

0 commit comments

Comments
 (0)