@@ -2773,24 +2773,26 @@ void Py_LeaveRecursiveCall(void)
2773
2773
_PyInterpreterFrame *
2774
2774
_PyUopExecute (_PyExecutorObject * executor , _PyInterpreterFrame * frame , PyObject * * stack_pointer )
2775
2775
{
2776
- #ifdef LLTRACE
2776
+ #ifdef Py_DEBUG
2777
2777
char * uop_debug = Py_GETENV ("PYTHONUOPSDEBUG" );
2778
2778
int lltrace = 0 ;
2779
2779
if (uop_debug != NULL && * uop_debug >= '0' ) {
2780
2780
lltrace = * uop_debug - '0' ; // TODO: Parse an int and all that
2781
2781
}
2782
- if (lltrace >= 2 ) {
2783
- PyCodeObject * code = _PyFrame_GetCode (frame );
2784
- _Py_CODEUNIT * instr = frame -> prev_instr + 1 ;
2785
- fprintf (stderr ,
2786
- "Entering _PyUopExecute for %s (%s:%d) at offset %ld\n" ,
2787
- PyUnicode_AsUTF8 (code -> co_qualname ),
2788
- PyUnicode_AsUTF8 (code -> co_filename ),
2789
- code -> co_firstlineno ,
2790
- (long )(instr - (_Py_CODEUNIT * )code -> co_code_adaptive ));
2791
- }
2782
+ #define DPRINTF (level , ...) \
2783
+ if (lltrace >= (level)) { fprintf(stderr, __VA_ARGS__); }
2784
+ #else
2785
+ #define DPRINTF (level , ...)
2792
2786
#endif
2793
2787
2788
+ DPRINTF (3 ,
2789
+ "Entering _PyUopExecute for %s (%s:%d) at offset %ld\n" ,
2790
+ PyUnicode_AsUTF8 (_PyFrame_GetCode (frame )-> co_qualname ),
2791
+ PyUnicode_AsUTF8 (_PyFrame_GetCode (frame )-> co_filename ),
2792
+ _PyFrame_GetCode (frame )-> co_firstlineno ,
2793
+ (long )(frame -> prev_instr + 1 -
2794
+ (_Py_CODEUNIT * )_PyFrame_GetCode (frame )-> co_code_adaptive ));
2795
+
2794
2796
PyThreadState * tstate = _PyThreadState_GET ();
2795
2797
_PyUOpExecutorObject * self = (_PyUOpExecutorObject * )executor ;
2796
2798
@@ -2803,7 +2805,7 @@ _PyUopExecute(_PyExecutorObject *executor, _PyInterpreterFrame *frame, PyObject
2803
2805
}
2804
2806
2805
2807
OBJECT_STAT_INC (optimization_traces_executed );
2806
- _Py_CODEUNIT * ip_offset = (_Py_CODEUNIT * )_PyFrame_GetCode (frame )-> co_code_adaptive - 1 ;
2808
+ _Py_CODEUNIT * ip_offset = (_Py_CODEUNIT * )_PyFrame_GetCode (frame )-> co_code_adaptive ;
2807
2809
int pc = 0 ;
2808
2810
int opcode ;
2809
2811
uint64_t operand ;
@@ -2812,14 +2814,11 @@ _PyUopExecute(_PyExecutorObject *executor, _PyInterpreterFrame *frame, PyObject
2812
2814
opcode = self -> trace [pc ].opcode ;
2813
2815
operand = self -> trace [pc ].operand ;
2814
2816
oparg = (int )operand ;
2815
- #ifdef LLTRACE
2816
- if (lltrace >= 3 ) {
2817
- const char * opname = opcode < 256 ? _PyOpcode_OpName [opcode ] : _PyOpcode_uop_name [opcode ];
2818
- int stack_level = (int )(stack_pointer - _PyFrame_Stackbase (frame ));
2819
- fprintf (stderr , " uop %s, operand %" PRIu64 ", stack_level %d\n" ,
2820
- opname , operand , stack_level );
2821
- }
2822
- #endif
2817
+ DPRINTF (3 ,
2818
+ " uop %s, operand %" PRIu64 ", stack_level %d\n" ,
2819
+ opcode < 256 ? _PyOpcode_OpName [opcode ] : _PyOpcode_uop_name [opcode ],
2820
+ operand ,
2821
+ (int )(stack_pointer - _PyFrame_Stackbase (frame )));
2823
2822
pc ++ ;
2824
2823
OBJECT_STAT_INC (optimization_uops_executed );
2825
2824
switch (opcode ) {
@@ -2828,14 +2827,15 @@ _PyUopExecute(_PyExecutorObject *executor, _PyInterpreterFrame *frame, PyObject
2828
2827
#define ENABLE_SPECIALIZATION 0
2829
2828
#include "executor_cases.c.h"
2830
2829
2831
- case SET_IP :
2830
+ case SAVE_IP :
2832
2831
{
2833
2832
frame -> prev_instr = ip_offset + oparg ;
2834
2833
break ;
2835
2834
}
2836
2835
2837
2836
case EXIT_TRACE :
2838
2837
{
2838
+ frame -> prev_instr -- ; // Back up to just before destination
2839
2839
_PyFrame_SetStackPointer (frame , stack_pointer );
2840
2840
Py_DECREF (self );
2841
2841
return frame ;
@@ -2850,6 +2850,13 @@ _PyUopExecute(_PyExecutorObject *executor, _PyInterpreterFrame *frame, PyObject
2850
2850
}
2851
2851
}
2852
2852
2853
+ unbound_local_error :
2854
+ format_exc_check_arg (tstate , PyExc_UnboundLocalError ,
2855
+ UNBOUNDLOCAL_ERROR_MSG ,
2856
+ PyTuple_GetItem (_PyFrame_GetCode (frame )-> co_localsplusnames , oparg )
2857
+ );
2858
+ goto error ;
2859
+
2853
2860
pop_4_error :
2854
2861
STACK_SHRINK (1 );
2855
2862
pop_3_error :
@@ -2861,23 +2868,16 @@ _PyUopExecute(_PyExecutorObject *executor, _PyInterpreterFrame *frame, PyObject
2861
2868
error :
2862
2869
// On ERROR_IF we return NULL as the frame.
2863
2870
// The caller recovers the frame from cframe.current_frame.
2864
- #ifdef LLTRACE
2865
- if (lltrace >= 2 ) {
2866
- fprintf (stderr , "Error: [Opcode %d, operand %" PRIu64 "]\n" , opcode , operand );
2867
- }
2868
- #endif
2871
+ DPRINTF (2 , "Error: [Opcode %d, operand %" PRIu64 "]\n" , opcode , operand );
2869
2872
_PyFrame_SetStackPointer (frame , stack_pointer );
2870
2873
Py_DECREF (self );
2871
2874
return NULL ;
2872
2875
2873
2876
deoptimize :
2874
2877
// On DEOPT_IF we just repeat the last instruction.
2875
2878
// This presumes nothing was popped from the stack (nor pushed).
2876
- #ifdef LLTRACE
2877
- if (lltrace >= 2 ) {
2878
- fprintf (stderr , "DEOPT: [Opcode %d, operand %" PRIu64 "]\n" , opcode , operand );
2879
- }
2880
- #endif
2879
+ DPRINTF (2 , "DEOPT: [Opcode %d, operand %" PRIu64 "]\n" , opcode , operand );
2880
+ frame -> prev_instr -- ; // Back up to just before destination
2881
2881
_PyFrame_SetStackPointer (frame , stack_pointer );
2882
2882
Py_DECREF (self );
2883
2883
return frame ;
0 commit comments