Skip to content

Commit 8508af7

Browse files
committed
add INVALID tag for abstract frame
1 parent 09fe5ae commit 8508af7

5 files changed

Lines changed: 39 additions & 27 deletions

File tree

Include/internal/pycore_optimizer.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ static inline uint16_t uop_get_error_target(const _PyUOpInstruction *inst)
115115

116116

117117
#define REF_IS_BORROWED 1
118+
#define REF_IS_INVALID 2
119+
#define REF_TAG_BITS 3
118120

119-
#define JIT_BITS_TO_PTR_MASKED(REF) ((JitOptSymbol *)(((REF).bits) & (~REF_IS_BORROWED)))
121+
#define JIT_BITS_TO_PTR_MASKED(REF) ((JitOptSymbol *)(((REF).bits) & (~REF_TAG_BITS)))
120122

121123
static inline JitOptSymbol *
122124
PyJitRef_Unwrap(JitOptRef ref)
@@ -133,6 +135,18 @@ PyJitRef_Wrap(JitOptSymbol *sym)
133135
return (JitOptRef){.bits=(uintptr_t)sym};
134136
}
135137

138+
static inline JitOptRef
139+
PyJitRef_WrapInvalid(void *ptr)
140+
{
141+
return (JitOptRef){.bits=(uintptr_t)ptr | REF_IS_INVALID};
142+
}
143+
144+
static inline bool
145+
PyJitRef_IsInvalid(JitOptRef ref)
146+
{
147+
return (ref.bits & REF_IS_INVALID) == REF_IS_INVALID;
148+
}
149+
136150
static inline JitOptRef
137151
PyJitRef_StripReferenceInfo(JitOptRef ref)
138152
{

Include/internal/pycore_optimizer_types.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ typedef enum _JitSymType {
4040
JIT_SYM_TUPLE_TAG = 8,
4141
JIT_SYM_TRUTHINESS_TAG = 9,
4242
JIT_SYM_COMPACT_INT = 10,
43-
JIT_SYM_INVALID_TAG = 255, // for non-symbol values on abstract stack
4443
} JitSymType;
4544

4645
typedef struct _jit_opt_known_class {
@@ -93,7 +92,6 @@ typedef union {
9392
} JitOptRef;
9493

9594
typedef struct _Py_UOpsAbstractFrame {
96-
uint8_t tag;
9795
bool globals_watched;
9896
// The version number of the globals dicts, once checked. 0 if unchecked.
9997
uint32_t globals_checked_version;

Python/optimizer_bytecodes.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ dummy_func(void) {
340340
}
341341
f->locals[0] = container;
342342
f->locals[1] = sub;
343-
new_frame = PyJitRef_Wrap((JitOptSymbol *)f);
343+
new_frame = PyJitRef_WrapInvalid(f);
344344
}
345345

346346
op(_BINARY_OP_SUBSCR_STR_INT, (str_st, sub_st -- res, s, i)) {
@@ -784,7 +784,7 @@ dummy_func(void) {
784784
break;
785785
}
786786
f->locals[0] = owner;
787-
new_frame = PyJitRef_Wrap((JitOptSymbol *)f);
787+
new_frame = PyJitRef_WrapInvalid(f);
788788
}
789789

790790
op(_INIT_CALL_BOUND_METHOD_EXACT_ARGS, (callable, self_or_null, unused[oparg] -- callable, self_or_null, unused[oparg])) {
@@ -848,9 +848,9 @@ dummy_func(void) {
848848
}
849849

850850
if (sym_is_null(self_or_null) || sym_is_not_null(self_or_null)) {
851-
new_frame = PyJitRef_Wrap((JitOptSymbol *)frame_new(ctx, co, 0, args, argcount));
851+
new_frame = PyJitRef_WrapInvalid(frame_new(ctx, co, 0, args, argcount));
852852
} else {
853-
new_frame = PyJitRef_Wrap((JitOptSymbol *)frame_new(ctx, co, 0, NULL, 0));
853+
new_frame = PyJitRef_WrapInvalid(frame_new(ctx, co, 0, NULL, 0));
854854
}
855855
}
856856

@@ -868,7 +868,7 @@ dummy_func(void) {
868868
break;
869869
}
870870

871-
new_frame = PyJitRef_Wrap((JitOptSymbol *)frame_new(ctx, co, 0, NULL, 0));
871+
new_frame = PyJitRef_WrapInvalid(frame_new(ctx, co, 0, NULL, 0));
872872
}
873873

874874
op(_PY_FRAME_KW, (callable, self_or_null, args[oparg], kwnames -- new_frame)) {
@@ -879,7 +879,7 @@ dummy_func(void) {
879879
break;
880880
}
881881

882-
new_frame = PyJitRef_Wrap((JitOptSymbol *)frame_new(ctx, co, 0, NULL, 0));
882+
new_frame = PyJitRef_WrapInvalid(frame_new(ctx, co, 0, NULL, 0));
883883
}
884884

885885
op(_PY_FRAME_EX, (func_st, null, callargs_st, kwargs_st -- ex_frame)) {
@@ -890,7 +890,7 @@ dummy_func(void) {
890890
break;
891891
}
892892

893-
ex_frame = PyJitRef_Wrap((JitOptSymbol *)frame_new(ctx, co, 0, NULL, 0));
893+
ex_frame = PyJitRef_WrapInvalid(frame_new(ctx, co, 0, NULL, 0));
894894
}
895895

896896
op(_CHECK_AND_ALLOCATE_OBJECT, (type_version/2, callable, self_or_null, args[oparg] -- callable, self_or_null, args[oparg])) {
@@ -914,7 +914,7 @@ dummy_func(void) {
914914
ctx->curr_frame_depth++;
915915
assert((this_instr + 1)->opcode == _PUSH_FRAME);
916916
PyCodeObject *co = get_code_with_logging((this_instr + 1));
917-
init_frame = PyJitRef_Wrap((JitOptSymbol *)frame_new(ctx, co, 0, args-1, oparg+1));
917+
init_frame = PyJitRef_WrapInvalid(frame_new(ctx, co, 0, args-1, oparg+1));
918918
}
919919

920920
op(_RETURN_VALUE, (retval -- res)) {
@@ -1007,7 +1007,7 @@ dummy_func(void) {
10071007
break;
10081008
}
10091009
new_frame->stack[0] = sym_new_const(ctx, Py_None);
1010-
gen_frame = PyJitRef_Wrap((JitOptSymbol *)new_frame);
1010+
gen_frame = PyJitRef_WrapInvalid(new_frame);
10111011
}
10121012

10131013
op(_SEND_GEN_FRAME, (unused, v -- unused, gen_frame)) {
@@ -1023,7 +1023,7 @@ dummy_func(void) {
10231023
break;
10241024
}
10251025
new_frame->stack[0] = PyJitRef_StripReferenceInfo(v);
1026-
gen_frame = PyJitRef_Wrap((JitOptSymbol *)new_frame);
1026+
gen_frame = PyJitRef_WrapInvalid(new_frame);
10271027
}
10281028

10291029
op(_CHECK_STACK_SPACE, (unused, unused, unused[oparg] -- unused, unused, unused[oparg])) {

Python/optimizer_cases.c.h

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer_symbols.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ _PyUOpSymPrint(JitOptRef ref)
7676
printf("<JitRef NULL>");
7777
return;
7878
}
79+
if (PyJitRef_IsInvalid(ref)) {
80+
printf("<INVALID frame at %p>", (void *)PyJitRef_Unwrap(ref));
81+
return;
82+
}
7983
JitOptSymbol *sym = PyJitRef_Unwrap(ref);
8084
switch (sym->tag) {
8185
case JIT_SYM_UNKNOWN_TAG:
@@ -109,9 +113,6 @@ _PyUOpSymPrint(JitOptRef ref)
109113
case JIT_SYM_COMPACT_INT:
110114
printf("<compact_int at %p>", (void *)sym);
111115
break;
112-
case JIT_SYM_INVALID_TAG:
113-
printf("<INVALID frame at %p>", (void *)sym);
114-
break;
115116
default:
116117
printf("<tag=%d at %p>", sym->tag, (void *)sym);
117118
break;
@@ -874,7 +875,6 @@ _Py_uop_frame_new(
874875
return NULL;
875876
}
876877
_Py_UOpsAbstractFrame *frame = &ctx->frames[ctx->curr_frame_depth];
877-
frame->tag = JIT_SYM_INVALID_TAG;
878878
frame->code = co;
879879
frame->stack_len = co->co_stacksize;
880880
frame->locals_len = co->co_nlocalsplus;

0 commit comments

Comments
 (0)