Skip to content

Commit 917c6f0

Browse files
committed
Update
1 parent a6fd711 commit 917c6f0

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

Python/optimizer.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,8 @@ translate_bytecode_to_trace(
550550
_Py_CODEUNIT *instr,
551551
_PyUOpInstruction *trace,
552552
int buffer_size,
553-
_PyBloomFilter *dependencies, bool progress_needed)
553+
_PyBloomFilter *dependencies, bool progress_needed,
554+
bool is_noopt)
554555
{
555556
bool first = true;
556557
PyCodeObject *code = _PyFrame_GetCode(frame);
@@ -591,7 +592,12 @@ translate_bytecode_to_trace(
591592

592593
for (;;) {
593594
target = INSTR_IP(instr, code);
594-
595+
if (is_noopt) {
596+
max_length-=2;
597+
}
598+
else {
599+
max_length--;
600+
}
595601
uint32_t opcode = instr->op.code;
596602
uint32_t oparg = instr->op.arg;
597603

@@ -629,8 +635,6 @@ translate_bytecode_to_trace(
629635
assert(opcode != ENTER_EXECUTOR && opcode != EXTENDED_ARG);
630636
RESERVE_RAW(2, "_CHECK_VALIDITY");
631637
ADD_TO_TRACE(_CHECK_VALIDITY, 0, 0, target);
632-
// Need to reserve 1 stub in case the _CHECK_VALIDITY results in a _DEOPT_IF
633-
max_length--;
634638
if (!OPCODE_HAS_NO_SAVE_IP(opcode)) {
635639
RESERVE_RAW(2, "_SET_IP");
636640
ADD_TO_TRACE(_SET_IP, 0, (uintptr_t)instr, target);
@@ -657,10 +661,6 @@ translate_bytecode_to_trace(
657661
RESERVE_RAW(2, "_ERROR_POP_N");
658662
max_length--;
659663
}
660-
if (OPCODE_HAS_DEOPT(opcode)) {
661-
RESERVE_RAW(2, "_DEOPT");
662-
max_length--;
663-
}
664664
switch (opcode) {
665665
case POP_JUMP_IF_NONE:
666666
case POP_JUMP_IF_NOT_NONE:
@@ -1287,15 +1287,19 @@ uop_optimize(
12871287
_Py_BloomFilter_Init(&dependencies);
12881288
_PyUOpInstruction buffer[UOP_MAX_TRACE_LENGTH];
12891289
OPT_STAT_INC(attempts);
1290-
int length = translate_bytecode_to_trace(frame, instr, buffer, UOP_MAX_TRACE_LENGTH, &dependencies, progress_needed);
1290+
char *env_var = Py_GETENV("PYTHON_UOPS_OPTIMIZE");
1291+
bool is_noopt = true;
1292+
if (env_var == NULL || *env_var == '\0' || *env_var > '0') {
1293+
is_noopt = false;
1294+
}
1295+
int length = translate_bytecode_to_trace(frame, instr, buffer, UOP_MAX_TRACE_LENGTH, &dependencies, progress_needed, is_noopt);
12911296
if (length <= 0) {
12921297
// Error or nothing translated
12931298
return length;
12941299
}
12951300
assert(length < UOP_MAX_TRACE_LENGTH);
12961301
OPT_STAT_INC(traces_created);
1297-
char *env_var = Py_GETENV("PYTHON_UOPS_OPTIMIZE");
1298-
if (env_var == NULL || *env_var == '\0' || *env_var > '0') {
1302+
if (!is_noopt) {
12991303
length = _Py_uop_analyze_and_optimize(frame, buffer,
13001304
length,
13011305
curr_stackentries, &dependencies);

0 commit comments

Comments
 (0)