Skip to content

Commit b6ae6da

Browse files
authored
GH-116596: Better determination of escaping uops. (GH-116597)
1 parent 6c4fc20 commit b6ae6da

File tree

5 files changed

+47
-30
lines changed

5 files changed

+47
-30
lines changed

Include/internal/pycore_opcode_metadata.h

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_metadata.h

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,7 @@ uop_optimize(
10331033
break;
10341034
}
10351035
assert(_PyOpcode_uop_name[buffer[pc].opcode]);
1036+
assert(strncmp(_PyOpcode_uop_name[buffer[pc].opcode], _PyOpcode_uop_name[opcode], strlen(_PyOpcode_uop_name[opcode])) == 0);
10361037
}
10371038
_PyExecutorObject *executor = make_executor_from_uops(buffer, &dependencies);
10381039
if (executor == NULL) {

Python/optimizer_analysis.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,15 +430,15 @@ remove_unneeded_uops(_PyUOpInstruction *buffer, int buffer_size)
430430
int opcode = buffer[pc].opcode;
431431
switch (opcode) {
432432
case _SET_IP:
433-
buffer[pc].opcode = NOP;
433+
buffer[pc].opcode = _NOP;
434434
last_set_ip = pc;
435435
break;
436436
case _CHECK_VALIDITY:
437437
if (may_have_escaped) {
438438
may_have_escaped = false;
439439
}
440440
else {
441-
buffer[pc].opcode = NOP;
441+
buffer[pc].opcode = _NOP;
442442
}
443443
break;
444444
case _CHECK_VALIDITY_AND_SET_IP:
@@ -447,7 +447,7 @@ remove_unneeded_uops(_PyUOpInstruction *buffer, int buffer_size)
447447
buffer[pc].opcode = _CHECK_VALIDITY;
448448
}
449449
else {
450-
buffer[pc].opcode = NOP;
450+
buffer[pc].opcode = _NOP;
451451
}
452452
last_set_ip = pc;
453453
break;
@@ -463,7 +463,7 @@ remove_unneeded_uops(_PyUOpInstruction *buffer, int buffer_size)
463463
last->opcode == _COPY
464464
) {
465465
last->opcode = _NOP;
466-
buffer[pc].opcode = NOP;
466+
buffer[pc].opcode = _NOP;
467467
}
468468
if (last->opcode == _REPLACE_WITH_TRUE) {
469469
last->opcode = _NOP;

Tools/cases_generator/analyzer.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ def is_infallible(op: parser.InstDef) -> bool:
335335
"_PyDictOrValues_IsValues",
336336
"_PyObject_DictOrValuesPointer",
337337
"_PyDictOrValues_GetValues",
338+
"_PyDictValues_AddToInsertionOrder",
338339
"_PyObject_MakeInstanceAttributesFromDict",
339340
"Py_DECREF",
340341
"_Py_DECREF_SPECIALIZED",
@@ -355,8 +356,10 @@ def is_infallible(op: parser.InstDef) -> bool:
355356
"_PyLong_IsCompact",
356357
"_PyLong_IsNonNegativeCompact",
357358
"_PyLong_CompactValue",
359+
"_PyLong_DigitCount",
358360
"_Py_NewRef",
359361
"_Py_IsImmortal",
362+
"PyLong_FromLong",
360363
"_Py_STR",
361364
"_PyLong_Add",
362365
"_PyLong_Multiply",
@@ -368,6 +371,17 @@ def is_infallible(op: parser.InstDef) -> bool:
368371
"_Py_atomic_load_uintptr_relaxed",
369372
"_PyFrame_GetCode",
370373
"_PyThreadState_HasStackSpace",
374+
"_PyUnicode_Equal",
375+
"_PyFrame_SetStackPointer",
376+
"_PyType_HasFeature",
377+
"PyUnicode_Concat",
378+
"_PyList_FromArraySteal",
379+
"_PyTuple_FromArraySteal",
380+
"PySlice_New",
381+
"_Py_LeaveRecursiveCallPy",
382+
"CALL_STAT_INC",
383+
"maybe_lltrace_resume_frame",
384+
"_PyUnicode_JoinArray",
371385
)
372386

373387
ESCAPING_FUNCTIONS = (
@@ -379,6 +393,8 @@ def is_infallible(op: parser.InstDef) -> bool:
379393
def makes_escaping_api_call(instr: parser.InstDef) -> bool:
380394
if "CALL_INTRINSIC" in instr.name:
381395
return True
396+
if instr.name == "_BINARY_OP":
397+
return True
382398
tkns = iter(instr.tokens)
383399
for tkn in tkns:
384400
if tkn.kind != lexer.IDENTIFIER:

0 commit comments

Comments
 (0)