Skip to content

Commit c736d63

Browse files
markshannonadorilson
authored andcommitted
pythonGH-116468: Use constants instead of oparg in stack effects when oparg is known to be a constant. (pythonGH-116469)
1 parent 493b403 commit c736d63

File tree

5 files changed

+98
-108
lines changed

5 files changed

+98
-108
lines changed

Include/internal/pycore_opcode_metadata.h

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

Python/bytecodes.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ dummy_func(
129129
PyObject *top;
130130
PyObject *type;
131131
PyObject *typevars;
132+
PyObject *val0;
133+
PyObject *val1;
132134
int values_or_none;
133135

134136
switch (opcode) {
@@ -1223,13 +1225,13 @@ dummy_func(
12231225

12241226
macro(UNPACK_SEQUENCE) = _SPECIALIZE_UNPACK_SEQUENCE + _UNPACK_SEQUENCE;
12251227

1226-
inst(UNPACK_SEQUENCE_TWO_TUPLE, (unused/1, seq -- values[oparg])) {
1228+
inst(UNPACK_SEQUENCE_TWO_TUPLE, (unused/1, seq -- val1, val0)) {
1229+
assert(oparg == 2);
12271230
DEOPT_IF(!PyTuple_CheckExact(seq));
12281231
DEOPT_IF(PyTuple_GET_SIZE(seq) != 2);
1229-
assert(oparg == 2);
12301232
STAT_INC(UNPACK_SEQUENCE, hit);
1231-
values[0] = Py_NewRef(PyTuple_GET_ITEM(seq, 1));
1232-
values[1] = Py_NewRef(PyTuple_GET_ITEM(seq, 0));
1233+
val0 = Py_NewRef(PyTuple_GET_ITEM(seq, 0));
1234+
val1 = Py_NewRef(PyTuple_GET_ITEM(seq, 1));
12331235
DECREF_INPUTS();
12341236
}
12351237

@@ -3236,39 +3238,33 @@ dummy_func(
32363238
DISPATCH_INLINED(new_frame);
32373239
}
32383240

3239-
inst(CALL_TYPE_1, (unused/1, unused/2, callable, null, args[oparg] -- res)) {
3241+
inst(CALL_TYPE_1, (unused/1, unused/2, callable, null, arg -- res)) {
32403242
assert(oparg == 1);
32413243
DEOPT_IF(null != NULL);
3242-
PyObject *obj = args[0];
32433244
DEOPT_IF(callable != (PyObject *)&PyType_Type);
32443245
STAT_INC(CALL, hit);
3245-
res = Py_NewRef(Py_TYPE(obj));
3246-
Py_DECREF(obj);
3247-
Py_DECREF(&PyType_Type); // I.e., callable
3246+
res = Py_NewRef(Py_TYPE(arg));
3247+
Py_DECREF(arg);
32483248
}
32493249

3250-
inst(CALL_STR_1, (unused/1, unused/2, callable, null, args[oparg] -- res)) {
3250+
inst(CALL_STR_1, (unused/1, unused/2, callable, null, arg -- res)) {
32513251
assert(oparg == 1);
32523252
DEOPT_IF(null != NULL);
32533253
DEOPT_IF(callable != (PyObject *)&PyUnicode_Type);
32543254
STAT_INC(CALL, hit);
3255-
PyObject *arg = args[0];
32563255
res = PyObject_Str(arg);
32573256
Py_DECREF(arg);
3258-
Py_DECREF(&PyUnicode_Type); // I.e., callable
32593257
ERROR_IF(res == NULL, error);
32603258
CHECK_EVAL_BREAKER();
32613259
}
32623260

3263-
inst(CALL_TUPLE_1, (unused/1, unused/2, callable, null, args[oparg] -- res)) {
3261+
inst(CALL_TUPLE_1, (unused/1, unused/2, callable, null, arg -- res)) {
32643262
assert(oparg == 1);
32653263
DEOPT_IF(null != NULL);
32663264
DEOPT_IF(callable != (PyObject *)&PyTuple_Type);
32673265
STAT_INC(CALL, hit);
3268-
PyObject *arg = args[0];
32693266
res = PySequence_Tuple(arg);
32703267
Py_DECREF(arg);
3271-
Py_DECREF(&PyTuple_Type); // I.e., tuple
32723268
ERROR_IF(res == NULL, error);
32733269
CHECK_EVAL_BREAKER();
32743270
}
@@ -3490,14 +3486,14 @@ dummy_func(
34903486
}
34913487

34923488
// This is secretly a super-instruction
3493-
tier1 inst(CALL_LIST_APPEND, (unused/1, unused/2, callable, self, args[oparg] -- unused)) {
3489+
tier1 inst(CALL_LIST_APPEND, (unused/1, unused/2, callable, self, arg -- unused)) {
34943490
assert(oparg == 1);
34953491
PyInterpreterState *interp = tstate->interp;
34963492
DEOPT_IF(callable != interp->callable_cache.list_append);
34973493
assert(self != NULL);
34983494
DEOPT_IF(!PyList_Check(self));
34993495
STAT_INC(CALL, hit);
3500-
if (_PyList_AppendTakeRef((PyListObject *)self, args[0]) < 0) {
3496+
if (_PyList_AppendTakeRef((PyListObject *)self, arg) < 0) {
35013497
goto pop_1_error; // Since arg is DECREF'ed already
35023498
}
35033499
Py_DECREF(self);

Python/executor_cases.c.h

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

Python/generated_cases.c.h

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

0 commit comments

Comments
 (0)