Skip to content

Commit 75b628a

Browse files
authored
GH-128563: Generate opcode = ... in instructions that need opcode (GH-129608)
* Remove support for GO_TO_INSTRUCTION
1 parent 808071b commit 75b628a

12 files changed

+558
-172
lines changed

Include/internal/pycore_opcode_metadata.h

+11-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_ids.h

+35-37
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/opcode_ids.h

+15-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/_opcode_metadata.py

+15-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/bytecodes.c

+32-20
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
#include "ceval_macros.h"
4646

4747
/* Flow control macros */
48-
#define GO_TO_INSTRUCTION(instname) ((void)0)
4948

5049
#define inst(name, ...) case name:
5150
#define op(name, ...) /* NAME is ignored */
@@ -2019,12 +2018,10 @@ dummy_func(
20192018
ERROR_IF(err != 0, error);
20202019
}
20212020

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-
}
2021+
macro(INSTRUMENTED_LOAD_SUPER_ATTR) =
2022+
counter/1 +
2023+
_LOAD_SUPER_ATTR +
2024+
_PUSH_NULL_CONDITIONAL;
20282025

20292026
family(LOAD_SUPER_ATTR, INLINE_CACHE_ENTRIES_LOAD_SUPER_ATTR) = {
20302027
LOAD_SUPER_ATTR_ATTR,
@@ -2088,7 +2085,10 @@ dummy_func(
20882085
attr = PyStackRef_FromPyObjectSteal(attr_o);
20892086
}
20902087

2091-
macro(LOAD_SUPER_ATTR) = _SPECIALIZE_LOAD_SUPER_ATTR + _LOAD_SUPER_ATTR + _PUSH_NULL_CONDITIONAL;
2088+
macro(LOAD_SUPER_ATTR) =
2089+
_SPECIALIZE_LOAD_SUPER_ATTR +
2090+
_LOAD_SUPER_ATTR +
2091+
_PUSH_NULL_CONDITIONAL;
20922092

20932093
inst(LOAD_SUPER_ATTR_ATTR, (unused/1, global_super_st, class_st, self_st -- attr_st)) {
20942094
PyObject *global_super = PyStackRef_AsPyObjectBorrow(global_super_st);
@@ -4331,18 +4331,23 @@ dummy_func(
43314331
CALL_KW_NON_PY,
43324332
};
43334333

4334-
inst(INSTRUMENTED_CALL_KW, (counter/1, version/2 -- )) {
4335-
int is_meth = !PyStackRef_IsNull(PEEK(oparg + 2));
4336-
int total_args = oparg + is_meth;
4337-
PyObject *function = PyStackRef_AsPyObjectBorrow(PEEK(oparg + 3));
4338-
PyObject *arg = total_args == 0 ? &_PyInstrumentation_MISSING
4339-
: PyStackRef_AsPyObjectBorrow(PEEK(total_args + 1));
4334+
op(_MONITOR_CALL_KW, (callable[1], self_or_null[1], args[oparg], kwnames -- callable[1], self_or_null[1], args[oparg], kwnames)) {
4335+
int is_meth = !PyStackRef_IsNull(self_or_null[0]);
4336+
PyObject *arg;
4337+
if (is_meth) {
4338+
arg = PyStackRef_AsPyObjectBorrow(self_or_null[0]);
4339+
}
4340+
else if (args) {
4341+
arg = PyStackRef_AsPyObjectBorrow(args[0]);
4342+
}
4343+
else {
4344+
arg = &_PyInstrumentation_MISSING;
4345+
}
4346+
PyObject *function = PyStackRef_AsPyObjectBorrow(callable[0]);
43404347
int err = _Py_call_instrumentation_2args(
43414348
tstate, PY_MONITORING_EVENT_CALL,
43424349
frame, this_instr, function, arg);
43434350
ERROR_IF(err, error);
4344-
PAUSE_ADAPTIVE_COUNTER(this_instr[1].counter);
4345-
GO_TO_INSTRUCTION(CALL_KW);
43464351
}
43474352

43484353
op(_MAYBE_EXPAND_METHOD_KW, (callable[1], self_or_null[1], args[oparg], kwnames_in -- func[1], maybe_self[1], args[oparg], kwnames_out)) {
@@ -4520,6 +4525,13 @@ dummy_func(
45204525
_MAYBE_EXPAND_METHOD_KW +
45214526
_DO_CALL_KW;
45224527

4528+
macro(INSTRUMENTED_CALL_KW) =
4529+
counter/1 +
4530+
unused/2 +
4531+
_MONITOR_CALL_KW +
4532+
_MAYBE_EXPAND_METHOD_KW +
4533+
_DO_CALL_KW;
4534+
45234535
op(_CHECK_IS_NOT_PY_CALLABLE_KW, (callable[1], unused[1], unused[oparg], kwnames -- callable[1], unused[1], unused[oparg], kwnames)) {
45244536
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
45254537
EXIT_IF(PyFunction_Check(callable_o));
@@ -4566,10 +4578,6 @@ dummy_func(
45664578
_CALL_KW_NON_PY +
45674579
_CHECK_PERIODIC;
45684580

4569-
inst(INSTRUMENTED_CALL_FUNCTION_EX, ( -- )) {
4570-
GO_TO_INSTRUCTION(CALL_FUNCTION_EX);
4571-
}
4572-
45734581
op(_MAKE_CALLARGS_A_TUPLE, (func, unused, callargs, kwargs_in -- func, unused, tuple, kwargs_out)) {
45744582
PyObject *callargs_o = PyStackRef_AsPyObjectBorrow(callargs);
45754583
if (PyTuple_CheckExact(callargs_o)) {
@@ -4678,6 +4686,10 @@ dummy_func(
46784686
_DO_CALL_FUNCTION_EX +
46794687
_CHECK_PERIODIC;
46804688

4689+
macro(INSTRUMENTED_CALL_FUNCTION_EX) =
4690+
_MAKE_CALLARGS_A_TUPLE +
4691+
_DO_CALL_FUNCTION_EX +
4692+
_CHECK_PERIODIC;
46814693

46824694
inst(MAKE_FUNCTION, (codeobj_st -- func)) {
46834695
PyObject *codeobj = PyStackRef_AsPyObjectBorrow(codeobj_st);

0 commit comments

Comments
 (0)