8000 gh-105481: add flags to each instr in the opcode metadata table, to replace opcode.hasarg/hasname/hasconst by iritkatriel · Pull Request #105482 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-105481: add flags to each instr in the opcode metadata table, to replace opcode.hasarg/hasname/hasconst #105482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 13, 2023
Prev Previous commit
Next Next commit
add macros CO_CONSTS, CO_NAMES
  • Loading branch information
iritkatriel committed Jun 8, 2023
commit fdce9f41afd9dc8be614980bcd057d558ede8252
50 changes: 25 additions & 25 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ dummy_func(
}

inst(LOAD_CONST, (-- value)) {
value = GETITEM(frame->f_code->co_consts, oparg);
value = GETITEM(CO_CONSTS, oparg);
Py_INCREF(value);
}

Expand Down Expand Up @@ -713,7 +713,7 @@ dummy_func(
}

inst(RETURN_CONST, (--)) {
PyObject *retval = GETITEM(frame->f_code->co_consts, oparg);
PyObject *retval = GETITEM(CO_CONSTS, oparg);
Py_INCREF(retval);
assert(EMPTY());
_PyFrame_SetStackPointer(frame, stack_pointer);
Expand All @@ -729,7 +729,7 @@ dummy_func(
}

inst(INSTRUMENTED_RETURN_CONST, (--)) {
PyObject *retval = GETITEM(frame->f_code->co_consts, oparg);
PyObject *retval = GETITEM(CO_CONSTS, oparg);
int err = _Py_call_instrumentation_arg(
tstate, PY_MONITORING_EVENT_PY_RETURN,
frame, next_instr-1, retval);
Expand Down Expand Up @@ -1048,7 +1048,7 @@ dummy_func(


inst(STORE_NAME, (v -- )) {
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
PyObject *name = GETITEM(CO_NAMES, oparg);
PyObject *ns = LOCALS();
int err;
if (ns == NULL) {
Expand All @@ -1066,7 +1066,7 @@ dummy_func(
}

inst(DELETE_NAME, (--)) {
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
PyObject *name = GETITEM(CO_NAMES, oparg);
PyObject *ns = LOCALS();
int err;
if (ns == NULL) {
Expand Down Expand Up @@ -1158,7 +1158,7 @@ dummy_func(
inst(STORE_ATTR, (counter/1, unused/3, v, owner --)) {
#if ENABLE_SPECIALIZATION
if (ADAPTIVE_COUNTER_IS_ZERO(counter)) {
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
PyObject *name = GETITEM(CO_NAMES, oparg);
next_instr--;
_Py_Specialize_StoreAttr(owner, next_instr, name);
DISPATCH_SAME_OPARG();
Expand All @@ -1169,28 +1169,28 @@ dummy_func(
#else
(void)counter; // Unused.
#endif /* ENABLE_SPECIALIZATION */
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
PyObject *name = GETITEM(CO_NAMES, oparg);
int err = PyObject_SetAttr(owner, name, v);
DECREF_INPUTS();
ERROR_IF(err, error);
}

inst(DELETE_ATTR, (owner --)) {
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
PyObject *name = GETITEM(CO_NAMES, oparg);
int err = PyObject_SetAttr(owner, name, (PyObject *)NULL);
DECREF_INPUTS();
ERROR_IF(err, error);
}

inst(STORE_GLOBAL, (v --)) {
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
PyObject *name = GETITEM(CO_NAMES, oparg);
int err = PyDict_SetItem(GLOBALS(), name, v);
DECREF_INPUTS();
ERROR_IF(err, error);
}

inst(DELETE_GLOBAL, (--)) {
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
PyObject *name = GETITEM(CO_NAMES, oparg);
int err;
err = PyDict_DelItem(GLOBALS(), name);
// Can't use ERROR_IF here.
Expand All @@ -1216,7 +1216,7 @@ dummy_func(
macro(LOAD_LOCALS) = _LOAD_LOCALS;

op(_LOAD_FROM_DICT_OR_GLOBALS, (mod_or_class_dict -- v)) {
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
PyObject *name = GETITEM(CO_NAMES, oparg);
if (PyDict_CheckExact(mod_or_class_dict)) {
v = PyDict_GetItemWithError(mod_or_class_dict, name);
if (v != NULL) {
Expand Down Expand Up @@ -1288,15 +1288,15 @@ dummy_func(
#if ENABLE_SPECIALIZATION
_PyLoadGlobalCache *cache = (_PyLoadGlobalCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
PyObject *name = GETITEM(frame->f_code->co_names, oparg>>1);
PyObject *name = GETITEM(CO_NAMES, oparg>>1);
next_instr--;
_Py_Specialize_LoadGlobal(GLOBALS(), BUILTINS(), next_instr, name);
DISPATCH_SAME_OPARG();
}
STAT_INC(LOAD_GLOBAL, deferred);
DECREMENT_ADAPTIVE_COUNTER(cache->counter);
#endif /* ENABLE_SPECIALIZATION */
PyObject *name = GETITEM(frame->f_code->co_names, oparg>>1);
PyObject *name = GETITEM(CO_NAMES, oparg>>1);
if (PyDict_CheckExact(GLOBALS())
&& PyDict_CheckExact(BUILTINS()))
{
Expand Down Expand Up @@ -1640,7 +1640,7 @@ dummy_func(
};

inst(LOAD_SUPER_ATTR, (unused/1, global_sup 10000 er, class, self -- res2 if (oparg & 1), res)) {
PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 2);
PyObject *name = GETITEM(CO_NAMES, oparg >> 2);
int load_method = oparg & 1;
#if ENABLE_SPECIALIZATION
_PySuperAttrCache *cache = (_PySuperAttrCache *)next_instr;
Expand Down Expand Up @@ -1693,7 +1693,7 @@ dummy_func(
DEOPT_IF(global_super != (PyObject *)&PySuper_Type, LOAD_SUPER_ATTR);
DEOPT_IF(!PyType_Check(class), LOAD_SUPER_ATTR);
STAT_INC(LOAD_SUPER_ATTR, hit);
PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 2);
PyObject *name = GETITEM(CO_NAMES, oparg >> 2);
res = _PySuper_Lookup((PyTypeObject *)class, self, name, NULL);
DECREF_INPUTS();
ERROR_IF(res == NULL, error);
Expand All @@ -1704,7 +1704,7 @@ dummy_func(
DEOPT_IF(global_super != (PyObject *)&PySuper_Type, LOAD_SUPER_ATTR);
DEOPT_IF(!PyType_Check(class), LOAD_SUPER_ATTR);
STAT_INC(LOAD_SUPER_ATTR, hit);
PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 2);
PyObject *name = GETITEM(CO_NAMES, oparg >> 2);
PyTypeObject *cls = (PyTypeObject *)class;
int method_found = 0;
res2 = _PySuper_Lookup(cls, self, name,
Expand Down Expand Up @@ -1742,15 +1742,15 @@ dummy_func(
#if ENABLE_SPECIALIZATION
_PyAttrCache *cache = (_PyAttrCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
PyObject *name = GETITEM(frame->f_code->co_names, oparg>>1);
PyObject *name = GETITEM(CO_NAMES, oparg>>1);
next_instr--;
_Py_Specialize_LoadAttr(owner, next_instr, name);
DISPATCH_SAME_OPARG();
}
STAT_INC(LOAD_ATTR, deferred);
DECREMENT_ADAPTIVE_COUNTER(cache->counter);
#endif /* ENABLE_SPECIALIZATION */
PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 1);
PyObject *name = GETITEM(CO_NAMES, oparg >> 1);
if (oparg & 1) {
/* Designed to work in tandem with CALL, pushes two values. */
PyObject* meth = NULL;
Expand Down Expand Up @@ -1828,7 +1828,7 @@ dummy_func(
PyDictObject *dict = (PyDictObject *)_PyDictOrValues_GetDict(dorv);
DEOPT_IF(dict == NULL, LOAD_ATTR);
assert(PyDict_CheckExact((PyObject *)dict));
PyObject *name = GETITEM(frame->f_code->co_names, oparg>>1);
PyObject *name = GETITEM(CO_NAMES, oparg>>1);
uint16_t hint = index;
DEOPT_IF(hint >= (size_t)dict->ma_keys->dk_nentries, LOAD_ATTR);
if (DK_IS_UNICODE(dict->ma_keys)) {
Expand Down Expand Up @@ -1916,7 +1916,7 @@ dummy_func(
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), LOAD_ATTR);
STAT_INC(LOAD_ATTR, hit);

PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 1);
PyObject *name = GETITEM(CO_NAMES, oparg >> 1);
Py_INCREF(f);
_PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, f, 2);
// Manipulate stack directly because we exit with DISPATCH_INLINED().
Expand Down Expand Up @@ -1960,7 +1960,7 @@ dummy_func(
PyDictObject *dict = (PyDictObject *)_PyDictOrValues_GetDict(dorv);
DEOPT_IF(dict == NULL, STORE_ATTR);
assert(PyDict_CheckExact((PyObject *)dict));
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
PyObject *name = GETITEM(CO_NAMES, oparg);
DEOPT_IF(hint >= (size_t)dict->ma_keys->dk_nentries, STORE_ATTR);
PyObject *old_value;
uint64_t new_version;
Expand Down 57AE Expand Up @@ -2120,14 +2120,14 @@ dummy_func(
}

inst(IMPORT_NAME, (level, fromlist -- res)) {
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
PyObject *name = GETITEM(CO_NAMES, oparg);
res = import_name(tstate, frame, name, fromlist, level);
DECREF_INPUTS();
ERROR_IF(res == NULL, error);
}

inst(IMPORT_FROM, (from -- from, res)) {
PyObject *name = GETITEM(frame->f_code->co_names, oparg);
PyObject *name = GETITEM(CO_NAMES, oparg);
res = import_from(tstate, from, name);
ERROR_IF(res == NULL, error);
}
Expand Down Expand Up @@ -2609,8 +2609,8 @@ dummy_func(

inst(KW_NAMES, (--)) {
assert(kwnames == NULL);
assert(oparg < PyTuple_GET_SIZE(frame->f_code->co_consts));
kwnames = GETITEM(frame->f_code->co_consts, oparg);
assert(oparg < PyTuple_GET_SIZE(CO_CONSTS));
kwnames = GETITEM(CO_CONSTS, oparg);
}

inst(INSTRUMENTED_CALL, ( -- )) {
Expand Down
5 changes: 5 additions & 0 deletions Python/ceval_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ GETITEM(PyObject *v, Py_ssize_t i) {
#define STACK_SHRINK(n) BASIC_STACKADJ(-(n))
#endif


/* Data access macros */
#define CO_CONSTS (frame->f_code->co_consts)
#define CO_NAMES (frame->f_code->co_names)

/* Local variable macros */

#define GETLOCAL(i) (frame->localsplus[i])
Expand Down
Loading
0