@@ -136,7 +136,7 @@ _PyOptimizer_Optimize(
136136 chain_depth %= MAX_CHAIN_DEPTH ;
137137 bool progress_needed = chain_depth == 0 ;
138138 PyCodeObject * code = (PyCodeObject * )tstate -> interp -> jit_state .initial_code ;
139- _Py_CODEUNIT * start = tstate -> interp -> jit_state .insert_exec_instr ;
139+ _Py_CODEUNIT * start = tstate -> interp -> jit_state .start_instr ;
140140 if (progress_needed && !has_space_for_executor (code , start )) {
141141 interp -> compiling = false;
142142 return 0 ;
@@ -608,10 +608,6 @@ _PyJit_translate_single_bytecode_to_trace(
608608 // Strange control-flow
609609 bool has_dynamic_jump_taken = OPCODE_HAS_UNPREDICTABLE_JUMP (opcode ) &&
610610 (next_instr != this_instr + 1 + _PyOpcode_Caches [_PyOpcode_Deopt [opcode ]]);
611- if (has_dynamic_jump_taken ) {
612- DPRINTF (2 , "Unsupported: dynamic jump taken\n" );
613- goto unsupported ;
614- }
615611
616612 /* Special case the first instruction,
617613 * so that we can guarantee forward progress */
@@ -624,6 +620,10 @@ _PyJit_translate_single_bytecode_to_trace(
624620 }
625621
626622 bool needs_guard_ip = _PyOpcode_NeedsGuardIp [opcode ];
623+ if (has_dynamic_jump_taken && !needs_guard_ip ) {
624+ DPRINTF (2 , "Unsupported: dynamic jump taken\n" );
625+ goto unsupported ;
626+ }
627627 DPRINTF (2 , "%p %d: %s(%d) %d %d\n" , old_code , target , _PyOpcode_OpName [opcode ], oparg , needs_guard_ip , old_stack_level );
628628
629629#ifdef Py_DEBUG
@@ -749,7 +749,7 @@ _PyJit_translate_single_bytecode_to_trace(
749749 case JUMP_BACKWARD_NO_INTERRUPT :
750750 {
751751 if ((next_instr != tstate -> interp -> jit_state .close_loop_instr ) &&
752- (next_instr != tstate -> interp -> jit_state .insert_exec_instr ) &&
752+ (next_instr != tstate -> interp -> jit_state .start_instr ) &&
753753 tstate -> interp -> jit_state .code_curr_size > 5 &&
754754 // These are coroutines, and we want to unroll those usually.
755755 opcode != JUMP_BACKWARD_NO_INTERRUPT ) {
@@ -760,7 +760,7 @@ _PyJit_translate_single_bytecode_to_trace(
760760 OPT_STAT_INC (inner_loop );
761761 ADD_TO_TRACE (_EXIT_TRACE , 0 , 0 , target );
762762 trace [trace_length - 1 ].operand1 = true; // is_control_flow
763- DPRINTF (2 , "JUMP_BACKWARD not to top ends trace %p %p %p\n" , next_instr , tstate -> interp -> jit_state .close_loop_instr , tstate -> interp -> jit_state .insert_exec_instr );
763+ DPRINTF (2 , "JUMP_BACKWARD not to top ends trace %p %p %p\n" , next_instr , tstate -> interp -> jit_state .close_loop_instr , tstate -> interp -> jit_state .start_instr );
764764 goto done ;
765765 }
766766 break ;
@@ -772,7 +772,9 @@ _PyJit_translate_single_bytecode_to_trace(
772772 * start with RESUME_CHECK */
773773 ADD_TO_TRACE (_TIER2_RESUME_CHECK , 0 , 0 , target );
774774 break ;
775-
775+ case INTERPRETER_EXIT :
776+ ADD_TO_TRACE (_DEOPT , 0 , 0 , target );
777+ goto done ;;
776778 default :
777779 {
778780 const struct opcode_macro_expansion * expansion = & _PyOpcode_macro_expansion [opcode ];
@@ -862,18 +864,18 @@ _PyJit_translate_single_bytecode_to_trace(
862864 PyCodeObject * new_code = (PyCodeObject * )PyStackRef_AsPyObjectBorrow (frame -> f_executable );
863865 PyFunctionObject * new_func = (PyFunctionObject * )PyStackRef_AsPyObjectBorrow (frame -> f_funcobj );
864866
865- if ( new_func != NULL ) {
866- operand = ( uintptr_t ) new_func ;
867- DPRINTF ( 2 , "Adding %p func to op\n" , ( void * ) operand );
868- _Py_BloomFilter_Add ( dependencies , new_func ) ;
869- }
870- else if ( new_code != NULL && ! Py_IsNone (( PyObject * ) new_code )) {
871- operand = ( uintptr_t ) new_code | 1 ;
872- DPRINTF ( 2 , "Adding %p code to op\n" , ( void * ) operand );
873- _Py_BloomFilter_Add ( dependencies , new_code ) ;
874- }
875- else {
876- operand = 0 ;
867+ operand = 0 ;
868+ if ( frame -> owner < FRAME_OWNED_BY_INTERPRETER ) {
869+ if ( new_func != NULL ) {
870+ operand = ( uintptr_t ) new_func ;
871+ DPRINTF ( 2 , "Adding %p func to op\n" , ( void * ) operand );
872+ _Py_BloomFilter_Add ( dependencies , new_func );
873+ }
874+ else if ( new_code != NULL && ! Py_IsNone (( PyObject * ) new_code )) {
875+ operand = ( uintptr_t ) new_code | 1 ;
876+ DPRINTF ( 2 , "Adding %p code to op\n" , ( void * ) operand );
877+ _Py_BloomFilter_Add ( dependencies , new_code );
878+ }
877879 }
878880 ADD_TO_TRACE (uop , oparg , operand , target );
879881 trace [trace_length - 1 ].operand1 = PyStackRef_IsNone (frame -> f_executable ) ? 2 : ((int )(frame -> stackpointer - _PyFrame_Stackbase (frame )));
@@ -913,8 +915,11 @@ _PyJit_translate_single_bytecode_to_trace(
913915 }
914916 }
915917 // Loop back to the start
916- int is_first_instr = tstate -> interp -> jit_state .close_loop_instr == next_instr || tstate -> interp -> jit_state .insert_exec_instr == next_instr ;
918+ int is_first_instr = tstate -> interp -> jit_state .close_loop_instr == next_instr || tstate -> interp -> jit_state .start_instr == next_instr ;
917919 if (is_first_instr && tstate -> interp -> jit_state .code_curr_size > 5 ) {
920+ if (needs_guard_ip ) {
921+ ADD_TO_TRACE (_SET_IP , 0 , (uintptr_t )next_instr , 0 );
922+ }
918923 ADD_TO_TRACE (_JUMP_TO_TOP , 0 , 0 , 0 );
919924 goto done ;
920925 }
@@ -945,7 +950,10 @@ _PyJit_translate_single_bytecode_to_trace(
945950
946951// Returns 0 for do not enter tracing, 1 on enter tracing.
947952int
948- _PyJit_TryInitializeTracing (PyThreadState * tstate , _PyInterpreterFrame * frame , _Py_CODEUNIT * curr_instr , _Py_CODEUNIT * insert_exec_instr , _Py_CODEUNIT * close_loop_instr , int curr_stackdepth , int chain_depth , _PyExitData * exit , _PyExecutorObject * prev_exec , int oparg )
953+ _PyJit_TryInitializeTracing (
954+ PyThreadState * tstate , _PyInterpreterFrame * frame , _Py_CODEUNIT * curr_instr ,
955+ _Py_CODEUNIT * start_instr , _Py_CODEUNIT * close_loop_instr , int curr_stackdepth , int chain_depth ,
956+ _PyExitData * exit , int oparg )
949957{
950958 // A recursive trace.
951959 // Don't trace into the inner call because it will stomp on the previous trace, causing endless retraces.
@@ -972,12 +980,12 @@ _PyJit_TryInitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame, _
972980 chain_depth );
973981#endif
974982
975- add_to_trace (tstate -> interp -> jit_state .code_buffer , 0 , _START_EXECUTOR , 0 , (uintptr_t )insert_exec_instr , INSTR_IP (insert_exec_instr , code ));
983+ add_to_trace (tstate -> interp -> jit_state .code_buffer , 0 , _START_EXECUTOR , 0 , (uintptr_t )start_instr , INSTR_IP (start_instr , code ));
976984 add_to_trace (tstate -> interp -> jit_state .code_buffer , 1 , _MAKE_WARM , 0 , 0 , 0 );
977985 tstate -> interp -> jit_state .code_curr_size = 2 ;
978986
979987 tstate -> interp -> jit_state .code_max_size = UOP_MAX_TRACE_LENGTH ;
980- tstate -> interp -> jit_state .insert_exec_instr = insert_exec_instr ;
988+ tstate -> interp -> jit_state .start_instr = start_instr ;
981989 tstate -> interp -> jit_state .close_loop_instr = close_loop_instr ;
982990 tstate -> interp -> jit_state .initial_code = (PyCodeObject * )Py_NewRef (code );
983991 tstate -> interp -> jit_state .initial_func = (PyFunctionObject * )Py_XNewRef (PyStackRef_AsPyObjectBorrow (frame -> f_funcobj ));
@@ -993,9 +1001,9 @@ _PyJit_TryInitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame, _
9931001 tstate -> interp -> jit_state .prev_instr_oparg = oparg ;
9941002 tstate -> interp -> jit_state .prev_instr_stacklevel = curr_stackdepth ;
9951003 tstate -> interp -> jit_state .prev_instr_is_super = false;
996- assert (curr_instr -> op .code == JUMP_BACKWARD_JIT || (prev_exec != NULL && exit != NULL ));
1004+ assert (curr_instr -> op .code == JUMP_BACKWARD_JIT || (exit != NULL ));
9971005 tstate -> interp -> jit_state .jump_backward_instr = curr_instr ;
998- tstate -> interp -> jit_state . prev_executor = ( _PyExecutorObject * ) Py_XNewRef ( prev_exec );
1006+ assert ( curr_instr -> op . code == JUMP_BACKWARD_JIT || ( exit != NULL ) );
9991007 _Py_BloomFilter_Init (& tstate -> interp -> jit_state .dependencies );
10001008 return 1 ;
10011009}
@@ -1006,7 +1014,6 @@ _PyJit_FinalizeTracing(PyThreadState *tstate)
10061014 Py_CLEAR (tstate -> interp -> jit_state .initial_code );
10071015 Py_CLEAR (tstate -> interp -> jit_state .initial_func );
10081016 Py_CLEAR (tstate -> interp -> jit_state .prev_instr_code );
1009- Py_CLEAR (tstate -> interp -> jit_state .prev_executor );
10101017 tstate -> interp -> jit_state .code_curr_size = 2 ;
10111018 tstate -> interp -> jit_state .code_max_size = UOP_MAX_TRACE_LENGTH - 1 ;
10121019}
@@ -1077,9 +1084,6 @@ prepare_for_execution(_PyUOpInstruction *buffer, int length)
10771084 for (int i = 0 ; i < length ; i ++ ) {
10781085 _PyUOpInstruction * inst = & buffer [i ];
10791086 int opcode = inst -> opcode ;
1080- if (inst -> format != UOP_FORMAT_TARGET ) {
1081- fprintf (stdout , "I: %d\n" , i );
1082- }
10831087 int32_t target = (int32_t )uop_get_target (inst );
10841088 uint16_t exit_flags = _PyUop_Flags [opcode ] & (HAS_EXIT_FLAG | HAS_DEOPT_FLAG | HAS_PERIODIC_FLAG );
10851089 if (exit_flags ) {
0 commit comments