Skip to content

Commit 7e8d188

Browse files
committed
Set opcode statically to free up a parameter for tailcalling
1 parent c3ae5c9 commit 7e8d188

File tree

11 files changed

+525
-139
lines changed

11 files changed

+525
-139
lines changed

Include/internal/pycore_opcode_metadata.h

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

Include/internal/pycore_uop_ids.h

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

Include/opcode_ids.h

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

Lib/_opcode_metadata.py

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

Python/bytecodes.c

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,12 +2019,10 @@ dummy_func(
20192019
ERROR_IF(err != 0, error);
20202020
}
20212021

2022-
inst(INSTRUMENTED_LOAD_SUPER_ATTR, (unused/1 -- )) {
2023-
// cancel out the decrement that will happen in LOAD_SUPER_ATTR; we
2024-
// don't want to specialize instrumented instructions
2025-
PAUSE_ADAPTIVE_COUNTER(this_instr[1].counter);
2026-
GO_TO_INSTRUCTION(LOAD_SUPER_ATTR);
2027-
}
2022+
macro(INSTRUMENTED_LOAD_SUPER_ATTR) =
2023+
counter/1 +
2024+
_LOAD_SUPER_ATTR +
2025+
_PUSH_NULL_CONDITIONAL;
20282026

20292027
family(LOAD_SUPER_ATTR, INLINE_CACHE_ENTRIES_LOAD_SUPER_ATTR) = {
20302028
LOAD_SUPER_ATTR_ATTR,
@@ -2088,7 +2086,10 @@ dummy_func(
20882086
attr = PyStackRef_FromPyObjectSteal(attr_o);
20892087
}
20902088

2091-
macro(LOAD_SUPER_ATTR) = _SPECIALIZE_LOAD_SUPER_ATTR + _LOAD_SUPER_ATTR + _PUSH_NULL_CONDITIONAL;
2089+
macro(LOAD_SUPER_ATTR) =
2090+
_SPECIALIZE_LOAD_SUPER_ATTR +
2091+
_LOAD_SUPER_ATTR +
2092+
_PUSH_NULL_CONDITIONAL;
20922093

20932094
inst(LOAD_SUPER_ATTR_ATTR, (unused/1, global_super_st, class_st, self_st -- attr_st)) {
20942095
PyObject *global_super = PyStackRef_AsPyObjectBorrow(global_super_st);
@@ -4336,18 +4337,23 @@ dummy_func(
43364337
CALL_KW_NON_PY,
43374338
};
43384339

4339-
inst(INSTRUMENTED_CALL_KW, (counter/1, version/2 -- )) {
4340-
int is_meth = !PyStackRef_IsNull(PEEK(oparg + 2));
4341-
int total_args = oparg + is_meth;
4342-
PyObject *function = PyStackRef_AsPyObjectBorrow(PEEK(oparg + 3));
4343-
PyObject *arg = total_args == 0 ? &_PyInstrumentation_MISSING
4344-
: PyStackRef_AsPyObjectBorrow(PEEK(total_args + 1));
4340+
op(_MONITOR_CALL_KW, (callable[1], self_or_null[1], args[oparg], kwnames -- callable[1], self_or_null[1], args[oparg], kwnames)) {
4341+
int is_meth = !PyStackRef_IsNull(self_or_null[0]);
4342+
PyObject *arg;
4343+
if (is_meth) {
4344+
arg = PyStackRef_AsPyObjectBorrow(self_or_null[0]);
4345+
}
4346+
else if (args) {
4347+
arg = PyStackRef_AsPyObjectBorrow(args[0]);
4348+
}
4349+
else {
4350+
arg = &_PyInstrumentation_MISSING;
4351+
}
4352+
PyObject *function = PyStackRef_AsPyObjectBorrow(callable[0]);
43454353
int err = _Py_call_instrumentation_2args(
43464354
tstate, PY_MONITORING_EVENT_CALL,
43474355
frame, this_instr, function, arg);
43484356
ERROR_IF(err, error);
4349-
PAUSE_ADAPTIVE_COUNTER(this_instr[1].counter);
4350-
GO_TO_INSTRUCTION(CALL_KW);
43514357
}
43524358

43534359
op(_MAYBE_EXPAND_METHOD_KW, (callable[1], self_or_null[1], args[oparg], kwnames_in -- func[1], maybe_self[1], args[oparg], kwnames_out)) {
@@ -4526,6 +4532,13 @@ dummy_func(
45264532
_MAYBE_EXPAND_METHOD_KW +
45274533
_DO_CALL_KW;
45284534

4535+
macro(INSTRUMENTED_CALL_KW) =
4536+
counter/1 +
4537+
unused/2 +
4538+
_MONITOR_CALL_KW +
4539+
_MAYBE_EXPAND_METHOD_KW +
4540+
_DO_CALL_KW;
4541+
45294542
op(_CHECK_IS_NOT_PY_CALLABLE_KW, (callable[1], unused[1], unused[oparg], kwnames -- callable[1], unused[1], unused[oparg], kwnames)) {
45304543
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
45314544
EXIT_IF(PyFunction_Check(callable_o));
@@ -4572,10 +4585,6 @@ dummy_func(
45724585
_CALL_KW_NON_PY +
45734586
_CHECK_PERIODIC;
45744587

4575-
inst(INSTRUMENTED_CALL_FUNCTION_EX, ( -- )) {
4576-
GO_TO_INSTRUCTION(CALL_FUNCTION_EX);
4577-
}
4578-
45794588
op(_MAKE_CALLARGS_A_TUPLE, (func, unused, callargs, kwargs_in -- func, unused, tuple, kwargs_out)) {
45804589
PyObject *callargs_o = PyStackRef_AsPyObjectBorrow(callargs);
45814590
if (PyTuple_CheckExact(callargs_o)) {
@@ -4683,6 +4692,10 @@ dummy_func(
46834692
_DO_CALL_FUNCTION_EX +
46844693
_CHECK_PERIODIC;
46854694

4695+
macro(INSTRUMENTED_CALL_FUNCTION_EX) =
4696+
_MAKE_CALLARGS_A_TUPLE +
4697+
_DO_CALL_FUNCTION_EX +
4698+
_CHECK_PERIODIC;
46864699

46874700
inst(MAKE_FUNCTION, (codeobj_st -- func)) {
46884701
PyObject *codeobj = PyStackRef_AsPyObjectBorrow(codeobj_st);

Python/executor_cases.c.h

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

0 commit comments

Comments
 (0)