Skip to content

Commit 2ea6b0a

Browse files
committed
infra: add hir_type_from_cint/cuint to hir_type_c.h
Move hir_type_from_cuint from simplify_c.c to hir_type_c.h (shared). Add hir_type_from_cint. Both construct HirType with HIR_SPEC_INT specialization and embedded integer constant value. Needed for LoadAttr specialization conversion (dict_version, slot_offset).
1 parent 8382896 commit 2ea6b0a

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

Python/jit/hir/hir_type_c.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,22 @@ static inline HirType hir_type_from_cdouble(double d) {
305305
return t;
306306
}
307307

308+
static inline HirType hir_type_from_cint(int64_t val, HirType base) {
309+
HirType t = base;
310+
t.bits_and_flags = (t.bits_and_flags & ~HIR_TYPE_SPEC_MASK) |
311+
((uint64_t)HIR_SPEC_INT << HIR_TYPE_SPEC_SHIFT);
312+
t.int_val = (intptr_t)val;
313+
return t;
314+
}
315+
316+
static inline HirType hir_type_from_cuint(uint64_t val, HirType base) {
317+
HirType t = base;
318+
t.bits_and_flags = (t.bits_and_flags & ~HIR_TYPE_SPEC_MASK) |
319+
((uint64_t)HIR_SPEC_INT << HIR_TYPE_SPEC_SHIFT);
320+
t.int_val = (intptr_t)val;
321+
return t;
322+
}
323+
308324
/* Return the type with specialization stripped (spec_kind=Top, spec_val=0).
309325
* C equivalent of Type::unspecialized(). */
310326
static inline HirType hir_type_unspecialized(const HirType *t) {

Python/jit/hir/simplify_c.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,13 +1646,7 @@ static void *type_attr_slow_path(SimplifyEnv *env, void *ctx) {
16461646
* returns NULL to fall through to C++ simplifyLoadAttrInstanceReceiver.
16471647
* Returns: register or NULL. Sets env->optimized if handled. */
16481648
/* ==== Type construction helpers ==== */
1649-
static inline HirType hir_type_from_cuint(uint64_t val, HirType base) {
1650-
HirType t = base;
1651-
t.bits_and_flags = (t.bits_and_flags & ~HIR_TYPE_SPEC_MASK) |
1652-
((uint64_t)HIR_SPEC_INT << HIR_TYPE_SPEC_SHIFT);
1653-
t.int_val = (intptr_t)val;
1654-
return t;
1655-
}
1649+
/* hir_type_from_cuint moved to hir_type_c.h */
16561650

16571651
static inline HirType hir_type_from_cptr(void *ptr) {
16581652
HirType t = HIR_TYPE_CPTR;

0 commit comments

Comments
 (0)