GeezerVison is showing github.com — GH-144179: Use recorded values to make optimizer more robust (GH-144437) · thunder-coding/cpython@d377d8c
File treeExpand file treeCollapse file tree Open diff view settings Modules/_testinternalcapi
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Include/internal/pycore_opcode_metadata.h +11-11Lines changed: 11 additions & 11 deletions Collapse file Copy file name to clipboardExpand all lines: Include/internal/pycore_optimizer.h +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -298,6 +298,11 @@ extern JitOptRef _Py_uop_sym_new_compact_int(JitOptContext *ctx); | 298 | 298 | extern void _Py_uop_sym_set_compact_int(JitOptContext *ctx, JitOptRef sym); | 299 | 299 | extern JitOptRef _Py_uop_sym_new_predicate(JitOptContext *ctx, JitOptRef lhs_ref, JitOptRef rhs_ref, JitOptPredicateKind kind); | 300 | 300 | 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); | 301 | 306 |
| 302 | 307 | extern void _Py_uop_abstractcontext_init(JitOptContext *ctx); | 303 | 308 | extern void _Py_uop_abstractcontext_fini(JitOptContext *ctx); | @@ -308,6 +313,14 @@ extern _Py_UOpsAbstractFrame *_Py_uop_frame_new( | 308 | 313 | int curr_stackentries, | 309 | 314 | JitOptRef *args, | 310 | 315 | 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 | + | 311 | 324 | extern int _Py_uop_frame_pop(JitOptContext *ctx, PyCodeObject *co, int curr_stackentries); | 312 | 325 |
| 313 | 326 | PyAPI_FUNC(PyObject *) _Py_uop_symbols_test(PyObject *self, PyObject *ignored); | @@ -341,6 +354,7 @@ _PyJit_TryInitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame, | 341 | 354 | int oparg, _PyExecutorObject *current_executor); | 342 | 355 |
| 343 | 356 | PyAPI_FUNC(void) _PyJit_FinalizeTracing(PyThreadState *tstate, int err); | | 357 | +void _PyPrintExecutor(_PyExecutorObject *executor, const _PyUOpInstruction *marker); | 344 | 358 | void _PyJit_TracerFree(_PyThreadStateImpl *_tstate); | 345 | 359 |
| 346 | 360 | void _PyJit_Tracer_InvalidateDependency(PyThreadState *old_tstate, void *obj); | |
Collapse file Copy file name to clipboardExpand all lines: Include/internal/pycore_optimizer_types.h +24Lines changed: 24 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -41,6 +41,9 @@ typedef enum _JitSymType { | 41 | 41 | JIT_SYM_TRUTHINESS_TAG = 9, | 42 | 42 | JIT_SYM_COMPACT_INT = 10, | 43 | 43 | 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, | 44 | 47 | } JitSymType; | 45 | 48 |
| 46 | 49 | typedef struct _jit_opt_known_class { | @@ -87,6 +90,24 @@ typedef struct { | 87 | 90 | uint16_t rhs; | 88 | 91 | } JitOptPredicate; | 89 | 92 |
| | 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 | + | 90 | 111 | typedef struct { | 91 | 112 | uint8_t tag; | 92 | 113 | } JitOptCompactInt; | @@ -100,6 +121,9 @@ typedef union _jit_opt_symbol { | 100 | 121 | JitOptTruthiness truthiness; | 101 | 122 | JitOptCompactInt compact; | 102 | 123 | JitOptPredicate predicate; | | 124 | + JitOptRecordedValue recorded_value; | | 125 | + JitOptRecordedType recorded_type; | | 126 | + JitOptRecordedGenFunc recorded_gen_func; | 103 | 127 | } JitOptSymbol; | 104 | 128 |
| 105 | 129 | // This mimics the _PyStackRef API | |
|