Skip to content

Commit cd87f6f

Browse files
gvanrossumaisk
authored andcommitted
A smattering of cleanups in uop debug output and lltrace (python#112980)
* Include destination T1 opcode in Error debug message * Include destination T1 opcode in DEOPT debug message * Remove obsolete comment from remove_unneeded_uops * Change lltrace_instruction() to print caller's opcode/oparg
1 parent 83b7cb5 commit cd87f6f

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

Python/ceval.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ dump_stack(_PyInterpreterFrame *frame, PyObject **stack_pointer)
135135
static void
136136
lltrace_instruction(_PyInterpreterFrame *frame,
137137
PyObject **stack_pointer,
138-
_Py_CODEUNIT *next_instr)
138+
_Py_CODEUNIT *next_instr,
139+
int opcode,
140+
int oparg)
139141
{
140142
if (frame->owner == FRAME_OWNED_BY_CSTACK) {
141143
return;
142144
}
143145
dump_stack(frame, stack_pointer);
144-
int oparg = next_instr->op.arg;
145-
int opcode = next_instr->op.code;
146146
const char *opname = _PyOpcode_OpName[opcode];
147147
assert(opname != NULL);
148148
int offset = (int)(next_instr - _PyCode_CODE(_PyFrame_GetCode(frame)));
@@ -1051,9 +1051,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
10511051
pop_1_error_tier_two:
10521052
STACK_SHRINK(1);
10531053
error_tier_two:
1054-
DPRINTF(2, "Error: [UOp %d (%s), oparg %d, operand %" PRIu64 ", target %d @ %d]\n",
1054+
DPRINTF(2, "Error: [UOp %d (%s), oparg %d, operand %" PRIu64 ", target %d @ %d -> %s]\n",
10551055
uopcode, _PyUOpName(uopcode), next_uop[-1].oparg, next_uop[-1].operand, next_uop[-1].target,
1056-
(int)(next_uop - current_executor->trace - 1));
1056+
(int)(next_uop - current_executor->trace - 1),
1057+
_PyOpcode_OpName[frame->instr_ptr->op.code]);
10571058
OPT_HIST(trace_uop_execution_counter, trace_run_length_hist);
10581059
frame->return_offset = 0; // Don't leave this random
10591060
_PyFrame_SetStackPointer(frame, stack_pointer);
@@ -1064,14 +1065,15 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
10641065
deoptimize:
10651066
// On DEOPT_IF we just repeat the last instruction.
10661067
// This presumes nothing was popped from the stack (nor pushed).
1067-
DPRINTF(2, "DEOPT: [UOp %d (%s), oparg %d, operand %" PRIu64 ", target %d @ %d]\n",
1068+
frame->instr_ptr = next_uop[-1].target + _PyCode_CODE(_PyFrame_GetCode(frame));
1069+
DPRINTF(2, "DEOPT: [UOp %d (%s), oparg %d, operand %" PRIu64 ", target %d @ %d -> %s]\n",
10681070
uopcode, _PyUOpName(uopcode), next_uop[-1].oparg, next_uop[-1].operand, next_uop[-1].target,
1069-
(int)(next_uop - current_executor->trace - 1));
1071+
(int)(next_uop - current_executor->trace - 1),
1072+
_PyOpcode_OpName[frame->instr_ptr->op.code]);
10701073
OPT_HIST(trace_uop_execution_counter, trace_run_length_hist);
10711074
UOP_STAT_INC(uopcode, miss);
10721075
frame->return_offset = 0; // Dispatch to frame->instr_ptr
10731076
_PyFrame_SetStackPointer(frame, stack_pointer);
1074-
frame->instr_ptr = next_uop[-1].target + _PyCode_CODE(_PyFrame_GetCode(frame));
10751077
Py_DECREF(current_executor);
10761078
// Fall through
10771079
// Jump here from ENTER_EXECUTOR

Python/ceval_macros.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
/* PRE_DISPATCH_GOTO() does lltrace if enabled. Normally a no-op */
8282
#ifdef LLTRACE
8383
#define PRE_DISPATCH_GOTO() if (lltrace >= 5) { \
84-
lltrace_instruction(frame, stack_pointer, next_instr); }
84+
lltrace_instruction(frame, stack_pointer, next_instr, opcode, oparg); }
8585
#else
8686
#define PRE_DISPATCH_GOTO() ((void)0)
8787
#endif

Python/optimizer_analysis.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
static void
1616
remove_unneeded_uops(_PyUOpInstruction *buffer, int buffer_size)
1717
{
18-
// Note that we don't enter stubs, those SET_IPs are needed.
1918
int last_set_ip = -1;
2019
bool maybe_invalid = false;
2120
for (int pc = 0; pc < buffer_size; pc++) {

0 commit comments

Comments
 (0)