gh-111848: Clean up RESERVE() macro (#112274)

Also avoid compiler warnings about unused 'reserved' variable.
This commit is contained in:
Guido van Rossum 2023-11-20 10:45:42 -08:00 committed by GitHub
parent 1995955173
commit c4c63211e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -426,7 +426,6 @@ translate_bytecode_to_trace(
_Py_CODEUNIT *initial_instr = instr;
int trace_length = 0;
int max_length = buffer_size;
int reserved = 0;
struct {
PyCodeObject *code;
_Py_CODEUNIT *instr;
@ -456,8 +455,6 @@ translate_bytecode_to_trace(
(OPARG), \
(uint64_t)(OPERAND)); \
assert(trace_length < max_length); \
assert(reserved > 0); \
reserved--; \
trace[trace_length].opcode = (OPCODE); \
trace[trace_length].oparg = (OPARG); \
trace[trace_length].operand = (OPERAND); \
@ -474,11 +471,10 @@ translate_bytecode_to_trace(
(opname), (n), max_length - trace_length); \
OPT_STAT_INC(trace_too_long); \
goto done; \
} \
reserved = (n); // Keep ADD_TO_TRACE honest
}
// Reserve space for main+stub uops, plus 3 for _SET_IP, _CHECK_VALIDITY and _EXIT_TRACE
#define RESERVE(main, stub) RESERVE_RAW((main) + (stub) + 3, _PyUopName(opcode))
// Reserve space for N uops, plus 3 for _SET_IP, _CHECK_VALIDITY and _EXIT_TRACE
#define RESERVE(needed) RESERVE_RAW((needed) + 3, _PyUopName(opcode))
// Trace stack operations (used by _PUSH_FRAME, _POP_FRAME)
#define TRACE_STACK_PUSH() \
@ -543,7 +539,7 @@ top: // Jump here after _PUSH_FRAME or likely branches
case POP_JUMP_IF_FALSE:
case POP_JUMP_IF_TRUE:
{
RESERVE(1, 0);
RESERVE(1);
int counter = instr[1].cache;
int bitcount = _Py_popcount32(counter);
int jump_likely = bitcount > 8;
@ -566,7 +562,7 @@ top: // Jump here after _PUSH_FRAME or likely branches
case JUMP_BACKWARD:
{
if (instr + 2 - oparg == initial_instr && code == initial_code) {
RESERVE(1, 0);
RESERVE(1);
ADD_TO_TRACE(_JUMP_TO_TOP, 0, 0, 0);
}
else {
@ -578,7 +574,7 @@ top: // Jump here after _PUSH_FRAME or likely branches
case JUMP_FORWARD:
{
RESERVE(0, 0);
RESERVE(0);
// This will emit two _SET_IP instructions; leave it to the optimizer
instr += oparg;
break;
@ -590,7 +586,7 @@ top: // Jump here after _PUSH_FRAME or likely branches
if (expansion->nuops > 0) {
// Reserve space for nuops (+ _SET_IP + _EXIT_TRACE)
int nuops = expansion->nuops;
RESERVE(nuops, 0);
RESERVE(nuops);
if (expansion->uops[nuops-1].uop == _POP_FRAME) {
// Check for trace stack underflow now:
// We can't bail e.g. in the middle of
@ -737,13 +733,12 @@ done:
if (trace_length > 4) {
ADD_TO_TRACE(_EXIT_TRACE, 0, 0, target);
DPRINTF(1,
"Created a trace for %s (%s:%d) at byte offset %d -- length %d+%d\n",
"Created a trace for %s (%s:%d) at byte offset %d -- length %d\n",
PyUnicode_AsUTF8(code->co_qualname),
PyUnicode_AsUTF8(code->co_filename),
code->co_firstlineno,
2 * INSTR_IP(initial_instr, code),
trace_length,
buffer_size - max_length);
trace_length);
OPT_HIST(trace_length + buffer_size - max_length, trace_length_hist);
return 1;
}