8000 gh-111848: Clean up RESERVE() macro (#112274) · Glyphack/cpython@2384007 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2384007

Browse files
gvanrossumGlyphack
authored andcommitted
pythongh-111848: Clean up RESERVE() macro (python#112274)
Also avoid compiler warnings about unused 'reserved' variable.
1 parent e235eb1 commit 2384007

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

Python/optimizer.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,6 @@ translate_bytecode_to_trace(
426426
_Py_CODEUNIT *initial_instr = instr;
427427
int trace_length = 0;
428428
int max_length = buffer_size;
429-
int reserved = 0;
430429
struct {
431430
PyCodeObject *code;
432431
_Py_CODEUNIT *instr;
@@ -456,8 +455,6 @@ translate_bytecode_to_trace(
456455
(OPARG), \
457456
(uint64_t)(OPERAND)); \
458457
assert(trace_length < max_length); \
459-
assert(reserved > 0); \
460-
reserved--; \
461458
trace[trace_length].opcode = (OPCODE); \
462459
trace[trace_length].oparg = (OPARG); \
463460
trace[trace_length].operand = (OPERAND); \
@@ -474,11 +471,10 @@ translate_bytecode_to_trace(
474471
(opname), (n), max_length - trace_length); \
475472
OPT_STAT_INC(trace_too_long); \
476473
goto done; \
477-
} \
478-
reserved = (n); // Keep ADD_TO_TRACE honest
474+
}
479475

480-
// Reserve space for main+stub uops, plus 3 for _SET_IP, _CHECK_VALIDITY and _EXIT_TRACE
481-
#define RESERVE(main, stub) RESERVE_RAW((main) + (stub) + 3, _PyUopName(opcode))
476+
// Reserve space for N uops, plus 3 for _SET_IP, _CHECK_VALIDITY and _EXIT_TRACE
477+
#define RESERVE(needed) RESERVE_RAW((needed) + 3, _PyUopName(opcode))
482478

483479
// Trace stack operations (used by _PUSH_FRAME, _POP_FRAME)
484480
#define TRACE_STACK_PUSH() \
@@ -543,7 +539,7 @@ translate_bytecode_to_trace(
543539
case POP_JUMP_IF_FALSE:
544540
case POP_JUMP_IF_TRUE:
545541
{
546-
RESERVE(1, 0);
542+
RESERVE(1);
547543
int counter = instr[1].cache;
548544
int bitcount = _Py_popcount32(counter);
549545
int jump_likely = bitcount > 8;
@@ -566,7 +562,7 @@ translate_bytecode_to_trace(
566562
case JUMP_BACKWARD:
567563
{
568564
if (instr + 2 - oparg == initial_instr && code == initial_code) {
569-
RESERVE(1, 0);
565+
RESERVE(1);
570566
ADD_TO_TRACE(_JUMP_TO_TOP, 0, 0, 0);
571567
}
572568
else {
@@ -578,7 +574,7 @@ translate_bytecode_to_trace(
578574

579575
case JUMP_FORWARD:
580576
{
581-
RESERVE(0, 0);
577+
RESERVE(0);
582578
// This will emit two _SET_IP instructions; leave it to the optimizer
583579
instr += oparg;
584580
break;
@@ -590,7 +586,7 @@ translate_bytecode_to_trace(
590586
if (expansion->nuops > 0) {
591587
// Reserve space for nuops (+ _SET_IP + _EXIT_TRACE)
592588
int nuops = expansion->nuops;
593-
RESERVE(nuops, 0);
589+
RESERVE(nuops);
594590
if (expansion->uops[nuops-1].uop == _POP_FRAME) {
595591
// Check for trace stack underflow now:
596592
// We can't bail e.g. in the middle of
@@ -737,13 +733,12 @@ translate_bytecode_to_trace(
737733
if (trace_length > 4) {
738734
ADD_TO_TRACE(_EXIT_TRACE, 0, 0, target);
739735
DPRINTF(1,
740-
"Created a trace for %s (%s:%d) at byte offset %d -- length %d+%d\n",
736+
"Created a trace for %s (%s:%d) at byte offset %d -- length %d\n",
741737
PyUnicode_AsUTF8(code->co_qualname),
742738
PyUnicode_AsUTF8(code->co_filename),
743739
code->co_firstlineno,
744740
2 * INSTR_IP(initial_instr, code),
745-
trace_length,
746-
buffer_size - max_length);
741+
trace_length);
747742
OPT_HIST(trace_length + buffer_size - max_length, trace_length_hist);
748743
return 1;
749744
}

0 commit comments

Comments
 (0)
0