Skip to content

Commit b53fc7c

Browse files
authored
GH-144179: Use recorded values to make optimizer more robust (GH-144437)
* Add three new symbol kinds * Do not smuggle code object in _PUSH_FRAME operand * Fix small bug in predicate analysis
1 parent b6d8aa4 commit b53fc7c

16 files changed

+2062
-1507
lines changed

Include/internal/pycore_opcode_metadata.h

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

Include/internal/pycore_optimizer.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ extern JitOptRef _Py_uop_sym_new_compact_int(JitOptContext *ctx);
298298
extern void _Py_uop_sym_set_compact_int(JitOptContext *ctx, JitOptRef sym);
299299
extern JitOptRef _Py_uop_sym_new_predicate(JitOptContext *ctx, JitOptRef lhs_ref, JitOptRef rhs_ref, JitOptPredicateKind kind);
300300
extern void _Py_uop_sym_apply_predicate_narrowing(JitOptContext *ctx, JitOptRef sym, bool branch_is_true);
301+
extern void _Py_uop_sym_set_recorded_value(JitOptContext *ctx, JitOptRef sym, PyObject *value);
302+
extern void _Py_uop_sym_set_recorded_type(JitOptContext *ctx, JitOptRef sym, PyTypeObject *type);
303+
extern void _Py_uop_sym_set_recorded_gen_func(JitOptContext *ctx, JitOptRef ref, PyFunctionObject *value);
304+
extern PyCodeObject *_Py_uop_sym_get_probable_func_code(JitOptRef sym);
305+
extern PyObject *_Py_uop_sym_get_probable_value(JitOptRef sym);
301306

302307
extern void _Py_uop_abstractcontext_init(JitOptContext *ctx);
303308
extern void _Py_uop_abstractcontext_fini(JitOptContext *ctx);
@@ -308,6 +313,14 @@ extern _Py_UOpsAbstractFrame *_Py_uop_frame_new(
308313
int curr_stackentries,
309314
JitOptRef *args,
310315
int arg_len);
316+
317+
extern _Py_UOpsAbstractFrame *_Py_uop_frame_new_from_symbol(
318+
JitOptContext *ctx,
319+
JitOptRef callable,
320+
int curr_stackentries,
321+
JitOptRef *args,
322+
int arg_len);
323+
311324
extern int _Py_uop_frame_pop(JitOptContext *ctx, PyCodeObject *co, int curr_stackentries);
312325

313326
PyAPI_FUNC(PyObject *) _Py_uop_symbols_test(PyObject *self, PyObject *ignored);
@@ -341,6 +354,7 @@ _PyJit_TryInitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame,
341354
int oparg, _PyExecutorObject *current_executor);
342355

343356
PyAPI_FUNC(void) _PyJit_FinalizeTracing(PyThreadState *tstate, int err);
357+
void _PyPrintExecutor(_PyExecutorObject *executor, const _PyUOpInstruction *marker);
344358
void _PyJit_TracerFree(_PyThreadStateImpl *_tstate);
345359

346360
void _PyJit_Tracer_InvalidateDependency(PyThreadState *old_tstate, void *obj);

Include/internal/pycore_optimizer_types.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ typedef enum _JitSymType {
4141
JIT_SYM_TRUTHINESS_TAG = 9,
4242
JIT_SYM_COMPACT_INT = 10,
4343
JIT_SYM_PREDICATE_TAG = 11,
44+
JIT_SYM_RECORDED_VALUE_TAG = 12,
45+
JIT_SYM_RECORDED_TYPE_TAG = 13,
46+
JIT_SYM_RECORDED_GEN_FUNC_TAG = 14,
4447
} JitSymType;
4548

4649
typedef struct _jit_opt_known_class {
@@ -87,6 +90,24 @@ typedef struct {
8790
uint16_t rhs;
8891
} JitOptPredicate;
8992

93+
typedef struct _jit_opt_recorded_value {
94+
uint8_t tag;
95+
bool known_type;
96+
PyObject *value;
97+
} JitOptRecordedValue;
98+
99+
typedef struct _jit_opt_recorded_type {
100+
uint8_t tag;
101+
PyTypeObject *type;
102+
} JitOptRecordedType;
103+
104+
/* Represents a generator, but we record the
105+
* function as the generator is emphemeral */
106+
typedef struct _jit_opt_recorded_gen_func {
107+
uint8_t tag;
108+
PyFunctionObject *func;
109+
} JitOptRecordedGenFunc;
110+
90111
typedef struct {
91112
uint8_t tag;
92113
} JitOptCompactInt;
@@ -100,6 +121,9 @@ typedef union _jit_opt_symbol {
100121
JitOptTruthiness truthiness;
101122
JitOptCompactInt compact;
102123
JitOptPredicate predicate;
124+
JitOptRecordedValue recorded_value;
125+
JitOptRecordedType recorded_type;
126+
JitOptRecordedGenFunc recorded_gen_func;
103127
} JitOptSymbol;
104128

105129
// This mimics the _PyStackRef API

0 commit comments

Comments
 (0)