[Python-checkins] gh-106812: Refactor cases_generator to allow uops with array stack effects (#107564)
gvanrossum
webhook-mailer at python.org
Fri Aug 4 12:36:00 EDT 2023
https://github.com/python/cpython/commit/400835ea1626c8c6dcd967c7eabe0dad4a923182
commit: 400835ea1626c8c6dcd967c7eabe0dad4a923182
branch: main
author: Guido van Rossum <guido at python.org>
committer: gvanrossum <gvanrossum at gmail.com>
date: 2023-08-04T09:35:56-07:00
summary:
gh-106812: Refactor cases_generator to allow uops with array stack effects (#107564)
Introducing a new file, stacking.py, that takes over several responsibilities related to symbolic evaluation of push/pop operations, with more generality.
files:
A Tools/cases_generator/stacking.py
M Include/internal/pycore_opcode_metadata.h
M Lib/test/test_generated_cases.py
M Python/executor_cases.c.h
M Python/generated_cases.c.h
M Tools/cases_generator/analysis.py
M Tools/cases_generator/flags.py
M Tools/cases_generator/formatting.py
M Tools/cases_generator/generate_cases.py
M Tools/cases_generator/instructions.py
M Tools/cases_generator/parsing.py
M Tools/cases_generator/plexer.py
diff --git a/Include/internal/pycore_opcode_metadata.h b/Include/internal/pycore_opcode_metadata.h
index 64a084618e13b..1cab6c984f3ac 100644
--- a/Include/internal/pycore_opcode_metadata.h
+++ b/Include/internal/pycore_opcode_metadata.h
@@ -679,9 +679,9 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
case LOAD_GLOBAL:
return ((oparg & 1) ? 1 : 0) + 1;
case LOAD_GLOBAL_MODULE:
- return ((oparg & 1) ? 1 : 0) + 1;
+ return (oparg & 1 ? 1 : 0) + 1;
case LOAD_GLOBAL_BUILTIN:
- return ((oparg & 1) ? 1 : 0) + 1;
+ return (oparg & 1 ? 1 : 0) + 1;
case DELETE_FAST:
return 0;
case MAKE_CELL:
@@ -739,7 +739,7 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
case LOAD_METHOD:
return ((oparg & 1) ? 1 : 0) + 1;
case LOAD_ATTR_INSTANCE_VALUE:
- return ((oparg & 1) ? 1 : 0) + 1;
+ return (oparg & 1 ? 1 : 0) + 1;
case LOAD_ATTR_MODULE:
return ((oparg & 1) ? 1 : 0) + 1;
case LOAD_ATTR_WITH_HINT:
@@ -944,7 +944,18 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
}
#endif
-enum InstructionFormat { INSTR_FMT_IB, INSTR_FMT_IBC, INSTR_FMT_IBC00, INSTR_FMT_IBC000, INSTR_FMT_IBC00000000, INSTR_FMT_IX, INSTR_FMT_IXC, INSTR_FMT_IXC0, INSTR_FMT_IXC00, INSTR_FMT_IXC000 };
+enum InstructionFormat {
+ INSTR_FMT_IB,
+ INSTR_FMT_IBC,
+ INSTR_FMT_IBC00,
+ INSTR_FMT_IBC000,
+ INSTR_FMT_IBC00000000,
+ INSTR_FMT_IX,
+ INSTR_FMT_IXC,
+ INSTR_FMT_IXC0,
+ INSTR_FMT_IXC00,
+ INSTR_FMT_IXC000,
+};
#define IS_VALID_OPCODE(OP) \
(((OP) >= 0) && ((OP) < OPCODE_METADATA_SIZE) && \
diff --git a/Lib/test/test_generated_cases.py b/Lib/test/test_generated_cases.py
index 9c23c2e82058c..54378fced5469 100644
--- a/Lib/test/test_generated_cases.py
+++ b/Lib/test/test_generated_cases.py
@@ -6,9 +6,9 @@
test_tools.skip_if_missing('cases_generator')
with test_tools.imports_under_tool('cases_generator'):
+ import generate_cases
import analysis
import formatting
- import generate_cases
from parsing import StackEffect
@@ -46,28 +46,11 @@ def test_effect_sizes(self):
(2, "(oparg<<1)"),
)
- self.assertEqual(
- formatting.string_effect_size(
- formatting.list_effect_size(input_effects),
- ), "1 + oparg + oparg*2",
- )
- self.assertEqual(
- formatting.string_effect_size(
- formatting.list_effect_size(output_effects),
- ),
- "2 + oparg*4",
- )
- self.assertEqual(
- formatting.string_effect_size(
- formatting.list_effect_size(other_effects),
- ),
- "2 + (oparg<<1)",
- )
-
class TestGeneratedCases(unittest.TestCase):
def setUp(self) -> None:
super().setUp()
+ self.maxDiff = None
self.temp_dir = tempfile.gettempdir()
self.temp_input_filename = os.path.join(self.temp_dir, "input.txt")
@@ -140,7 +123,8 @@ def test_inst_one_pop(self):
"""
output = """
TARGET(OP) {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
+ value = stack_pointer[-1];
spam();
STACK_SHRINK(1);
DISPATCH();
@@ -173,8 +157,9 @@ def test_inst_one_push_one_pop(self):
"""
output = """
TARGET(OP) {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
PyObject *res;
+ value = stack_pointer[-1];
spam();
stack_pointer[-1] = res;
DISPATCH();
@@ -190,9 +175,11 @@ def test_binary_op(self):
"""
output = """
TARGET(OP) {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
PyObject *res;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
spam();
STACK_SHRINK(1);
stack_pointer[-1] = res;
@@ -209,9 +196,11 @@ def test_overlap(self):
"""
output = """
TARGET(OP) {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
PyObject *result;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
spam();
stack_pointer[-1] = result;
DISPATCH();
@@ -235,8 +224,9 @@ def test_predictions_and_eval_breaker(self):
}
TARGET(OP3) {
- PyObject *arg = stack_pointer[-1];
+ PyObject *arg;
PyObject *res;
+ arg = stack_pointer[-1];
DEOPT_IF(xxx, OP1);
stack_pointer[-1] = res;
CHECK_EVAL_BREAKER();
@@ -281,9 +271,11 @@ def test_error_if_pop(self):
"""
output = """
TARGET(OP) {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
PyObject *res;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
if (cond) goto pop_2_label;
STACK_SHRINK(1);
stack_pointer[-1] = res;
@@ -299,7 +291,8 @@ def test_cache_effect(self):
"""
output = """
TARGET(OP) {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
+ value = stack_pointer[-1];
uint16_t counter = read_u16(&next_instr[0].cache);
uint32_t extra = read_u32(&next_instr[1].cache);
STACK_SHRINK(1);
@@ -338,8 +331,10 @@ def test_macro_instruction(self):
"""
output = """
TARGET(OP1) {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
uint16_t counter = read_u16(&next_instr[0].cache);
op1(left, right);
next_instr += 1;
@@ -347,38 +342,38 @@ def test_macro_instruction(self):
}
TARGET(OP) {
- PyObject *_tmp_1 = stack_pointer[-1];
- PyObject *_tmp_2 = stack_pointer[-2];
- PyObject *_tmp_3 = stack_pointer[-3];
+ static_assert(INLINE_CACHE_ENTRIES_OP == 5, "incorrect cache size");
+ PyObject *right;
+ PyObject *left;
+ PyObject *arg2;
+ PyObject *res;
+ // OP1
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
{
- PyObject *right = _tmp_1;
- PyObject *left = _tmp_2;
uint16_t counter = read_u16(&next_instr[0].cache);
op1(left, right);
- _tmp_2 = left;
- _tmp_1 = right;
}
+ // OP2
+ arg2 = stack_pointer[-3];
{
- PyObject *right = _tmp_1;
- PyObject *left = _tmp_2;
- PyObject *arg2 = _tmp_3;
- PyObject *res;
uint32_t extra = read_u32(&next_instr[3].cache);
res = op2(arg2, left, right);
- _tmp_3 = res;
}
- next_instr += 5;
- static_assert(INLINE_CACHE_ENTRIES_OP == 5, "incorrect cache size");
STACK_SHRINK(2);
- stack_pointer[-1] = _tmp_3;
+ stack_pointer[-1] = res;
+ next_instr += 5;
DISPATCH();
}
TARGET(OP3) {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
- PyObject *arg2 = stack_pointer[-3];
+ PyObject *right;
+ PyObject *left;
+ PyObject *arg2;
PyObject *res;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
+ arg2 = stack_pointer[-3];
res = op3(arg2, left, right);
STACK_SHRINK(2);
stack_pointer[-1] = res;
@@ -396,9 +391,12 @@ def test_array_input(self):
"""
output = """
TARGET(OP) {
- PyObject *above = stack_pointer[-1];
- PyObject **values = (stack_pointer - (1 + oparg*2));
- PyObject *below = stack_pointer[-(2 + oparg*2)];
+ PyObject *above;
+ PyObject **values;
+ PyObject *below;
+ above = stack_pointer[-1];
+ values = stack_pointer - 1 - oparg*2;
+ below = stack_pointer[-2 - oparg*2];
spam();
STACK_SHRINK(oparg*2);
STACK_SHRINK(2);
@@ -416,12 +414,13 @@ def test_array_output(self):
output = """
TARGET(OP) {
PyObject *below;
- PyObject **values = stack_pointer - (2) + 1;
+ PyObject **values;
PyObject *above;
+ values = stack_pointer - 1;
spam(values, oparg);
STACK_GROW(oparg*3);
+ stack_pointer[-2 - oparg*3] = below;
stack_pointer[-1] = above;
- stack_pointer[-(2 + oparg*3)] = below;
DISPATCH();
}
"""
@@ -435,8 +434,9 @@ def test_array_input_output(self):
"""
output = """
TARGET(OP) {
- PyObject **values = (stack_pointer - oparg);
+ PyObject **values;
PyObject *above;
+ values = stack_pointer - oparg;
spam(values, oparg);
STACK_GROW(1);
stack_pointer[-1] = above;
@@ -453,8 +453,10 @@ def test_array_error_if(self):
"""
output = """
TARGET(OP) {
- PyObject **values = (stack_pointer - oparg);
- PyObject *extra = stack_pointer[-(1 + oparg)];
+ PyObject **values;
+ PyObject *extra;
+ values = stack_pointer - oparg;
+ extra = stack_pointer[-1 - oparg];
if (oparg == 0) { STACK_SHRINK(oparg); goto pop_1_somewhere; }
STACK_SHRINK(oparg);
STACK_SHRINK(1);
@@ -471,18 +473,21 @@ def test_cond_effect(self):
"""
output = """
TARGET(OP) {
- PyObject *cc = stack_pointer[-1];
- PyObject *input = ((oparg & 1) == 1) ? stack_pointer[-(1 + (((oparg & 1) == 1) ? 1 : 0))] : NULL;
- PyObject *aa = stack_pointer[-(2 + (((oparg & 1) == 1) ? 1 : 0))];
+ PyObject *cc;
+ PyObject *input = NULL;
+ PyObject *aa;
PyObject *xx;
PyObject *output = NULL;
PyObject *zz;
+ cc = stack_pointer[-1];
+ if ((oparg & 1) == 1) { input = stack_pointer[-1 - ((oparg & 1) == 1 ? 1 : 0)]; }
+ aa = stack_pointer[-2 - ((oparg & 1) == 1 ? 1 : 0)];
output = spam(oparg, input);
STACK_SHRINK((((oparg & 1) == 1) ? 1 : 0));
STACK_GROW(((oparg & 2) ? 1 : 0));
+ stack_pointer[-2 - (oparg & 2 ? 1 : 0)] = xx;
+ if (oparg & 2) { stack_pointer[-1 - (oparg & 2 ? 1 : 0)] = output; }
stack_pointer[-1] = zz;
- if (oparg & 2) { stack_pointer[-(1 + ((oparg & 2) ? 1 : 0))] = output; }
- stack_pointer[-(2 + ((oparg & 2) ? 1 : 0))] = xx;
DISPATCH();
}
"""
@@ -500,29 +505,28 @@ def test_macro_cond_effect(self):
"""
output = """
TARGET(M) {
- PyObject *_tmp_1 = stack_pointer[-1];
- PyObject *_tmp_2 = stack_pointer[-2];
- PyObject *_tmp_3 = stack_pointer[-3];
+ PyObject *right;
+ PyObject *middle;
+ PyObject *left;
+ PyObject *deep;
+ PyObject *extra = NULL;
+ PyObject *res;
+ // A
+ right = stack_pointer[-1];
+ middle = stack_pointer[-2];
+ left = stack_pointer[-3];
{
- PyObject *right = _tmp_1;
- PyObject *middle = _tmp_2;
- PyObject *left = _tmp_3;
# Body of A
}
+ // B
{
- PyObject *deep;
- PyObject *extra = NULL;
- PyObject *res;
# Body of B
- _tmp_3 = deep;
- if (oparg) { _tmp_2 = extra; }
- _tmp_1 = res;
}
STACK_SHRINK(1);
STACK_GROW((oparg ? 1 : 0));
- stack_pointer[-1] = _tmp_1;
- if (oparg) { stack_pointer[-2] = _tmp_2; }
- stack_pointer[-3] = _tmp_3;
+ stack_pointer[-2 - (oparg ? 1 : 0)] = deep;
+ if (oparg) { stack_pointer[-1 - (oparg ? 1 : 0)] = extra; }
+ stack_pointer[-1] = res;
DISPATCH();
}
"""
diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h
index ed7cf4c15ec4a..9363b4955087d 100644
--- a/Python/executor_cases.c.h
+++ b/Python/executor_cases.c.h
@@ -47,14 +47,16 @@
}
case STORE_FAST: {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
+ value = stack_pointer[-1];
SETLOCAL(oparg, value);
STACK_SHRINK(1);
break;
}
case POP_TOP: {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
+ value = stack_pointer[-1];
Py_DECREF(value);
STACK_SHRINK(1);
break;
@@ -69,8 +71,10 @@
}
case END_SEND: {
- PyObject *value = stack_pointer[-1];
- PyObject *receiver = stack_pointer[-2];
+ PyObject *value;
+ PyObject *receiver;
+ value = stack_pointer[-1];
+ receiver = stack_pointer[-2];
Py_DECREF(receiver);
STACK_SHRINK(1);
stack_pointer[-1] = value;
@@ -78,8 +82,9 @@
}
case UNARY_NEGATIVE: {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
PyObject *res;
+ value = stack_pointer[-1];
res = PyNumber_Negative(value);
Py_DECREF(value);
if (res == NULL) goto pop_1_error;
@@ -88,8 +93,9 @@
}
case UNARY_NOT: {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
PyObject *res;
+ value = stack_pointer[-1];
assert(PyBool_Check(value));
res = Py_IsFalse(value) ? Py_True : Py_False;
stack_pointer[-1] = res;
@@ -98,8 +104,9 @@
case TO_BOOL: {
static_assert(INLINE_CACHE_ENTRIES_TO_BOOL == 3, "incorrect cache size");
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
PyObject *res;
+ value = stack_pointer[-1];
#if ENABLE_SPECIALIZATION
_PyToBoolCache *cache = (_PyToBoolCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@@ -119,15 +126,17 @@
}
case TO_BOOL_BOOL: {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
+ value = stack_pointer[-1];
DEOPT_IF(!PyBool_Check(value), TO_BOOL);
STAT_INC(TO_BOOL, hit);
break;
}
case TO_BOOL_INT: {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
PyObject *res;
+ value = stack_pointer[-1];
DEOPT_IF(!PyLong_CheckExact(value), TO_BOOL);
STAT_INC(TO_BOOL, hit);
if (_PyLong_IsZero((PyLongObject *)value)) {
@@ -143,8 +152,9 @@
}
case TO_BOOL_LIST: {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
PyObject *res;
+ value = stack_pointer[-1];
DEOPT_IF(!PyList_CheckExact(value), TO_BOOL);
STAT_INC(TO_BOOL, hit);
res = Py_SIZE(value) ? Py_True : Py_False;
@@ -154,8 +164,9 @@
}
case TO_BOOL_NONE: {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
PyObject *res;
+ value = stack_pointer[-1];
// This one is a bit weird, because we expect *some* failures:
DEOPT_IF(!Py_IsNone(value), TO_BOOL);
STAT_INC(TO_BOOL, hit);
@@ -165,8 +176,9 @@
}
case TO_BOOL_STR: {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
PyObject *res;
+ value = stack_pointer[-1];
DEOPT_IF(!PyUnicode_CheckExact(value), TO_BOOL);
STAT_INC(TO_BOOL, hit);
if (value == &_Py_STR(empty)) {
@@ -183,8 +195,9 @@
}
case TO_BOOL_ALWAYS_TRUE: {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
PyObject *res;
+ value = stack_pointer[-1];
uint32_t version = (uint32_t)operand;
// This one is a bit weird, because we expect *some* failures:
assert(version);
@@ -197,8 +210,9 @@
}
case UNARY_INVERT: {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
PyObject *res;
+ value = stack_pointer[-1];
res = PyNumber_Invert(value);
Py_DECREF(value);
if (res == NULL) goto pop_1_error;
@@ -207,17 +221,21 @@
}
case _GUARD_BOTH_INT: {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
DEOPT_IF(!PyLong_CheckExact(left), BINARY_OP);
DEOPT_IF(!PyLong_CheckExact(right), BINARY_OP);
break;
}
case _BINARY_OP_MULTIPLY_INT: {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
PyObject *res;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
STAT_INC(BINARY_OP, hit);
res = _PyLong_Multiply((PyLongObject *)left, (PyLongObject *)right);
_Py_DECREF_SPECIALIZED(right, (destructor)PyObject_Free);
@@ -229,9 +247,11 @@
}
case _BINARY_OP_ADD_INT: {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
PyObject *res;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
STAT_INC(BINARY_OP, hit);
res = _PyLong_Add((PyLongObject *)left, (PyLongObject *)right);
_Py_DECREF_SPECIALIZED(right, (destructor)PyObject_Free);
@@ -243,9 +263,11 @@
}
case _BINARY_OP_SUBTRACT_INT: {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
PyObject *res;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
STAT_INC(BINARY_OP, hit);
res = _PyLong_Subtract((PyLongObject *)left, (PyLongObject *)right);
_Py_DECREF_SPECIALIZED(right, (destructor)PyObject_Free);
@@ -257,17 +279,21 @@
}
case _GUARD_BOTH_FLOAT: {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
DEOPT_IF(!PyFloat_CheckExact(left), BINARY_OP);
DEOPT_IF(!PyFloat_CheckExact(right), BINARY_OP);
break;
}
case _BINARY_OP_MULTIPLY_FLOAT: {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
PyObject *res;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
STAT_INC(BINARY_OP, hit);
double dres =
((PyFloatObject *)left)->ob_fval *
@@ -279,9 +305,11 @@
}
case _BINARY_OP_ADD_FLOAT: {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
PyObject *res;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
STAT_INC(BINARY_OP, hit);
double dres =
((PyFloatObject *)left)->ob_fval +
@@ -293,9 +321,11 @@
}
case _BINARY_OP_SUBTRACT_FLOAT: {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
PyObject *res;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
STAT_INC(BINARY_OP, hit);
double dres =
((PyFloatObject *)left)->ob_fval -
@@ -307,17 +337,21 @@
}
case _GUARD_BOTH_UNICODE: {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
DEOPT_IF(!PyUnicode_CheckExact(left), BINARY_OP);
DEOPT_IF(!PyUnicode_CheckExact(right), BINARY_OP);
break;
}
case _BINARY_OP_ADD_UNICODE: {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
PyObject *res;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
STAT_INC(BINARY_OP, hit);
res = PyUnicode_Concat(left, right);
_Py_DECREF_SPECIALIZED(left, _PyUnicode_ExactDealloc);
@@ -330,9 +364,11 @@
case BINARY_SUBSCR: {
static_assert(INLINE_CACHE_ENTRIES_BINARY_SUBSCR == 1, "incorrect cache size");
- PyObject *sub = stack_pointer[-1];
- PyObject *container = stack_pointer[-2];
+ PyObject *sub;
+ PyObject *container;
PyObject *res;
+ sub = stack_pointer[-1];
+ container = stack_pointer[-2];
#if ENABLE_SPECIALIZATION
_PyBinarySubscrCache *cache = (_PyBinarySubscrCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@@ -353,10 +389,13 @@
}
case BINARY_SLICE: {
- PyObject *stop = stack_pointer[-1];
- PyObject *start = stack_pointer[-2];
- PyObject *container = stack_pointer[-3];
+ PyObject *stop;
+ PyObject *start;
+ PyObject *container;
PyObject *res;
+ stop = stack_pointer[-1];
+ start = stack_pointer[-2];
+ container = stack_pointer[-3];
PyObject *slice = _PyBuildSlice_ConsumeRefs(start, stop);
// Can't use ERROR_IF() here, because we haven't
// DECREF'ed container yet, and we still own slice.
@@ -375,10 +414,14 @@
}
case STORE_SLICE: {
- PyObject *stop = stack_pointer[-1];
- PyObject *start = stack_pointer[-2];
- PyObject *container = stack_pointer[-3];
- PyObject *v = stack_pointer[-4];
+ PyObject *stop;
+ PyObject *start;
+ PyObject *container;
+ PyObject *v;
+ stop = stack_pointer[-1];
+ start = stack_pointer[-2];
+ container = stack_pointer[-3];
+ v = stack_pointer[-4];
PyObject *slice = _PyBuildSlice_ConsumeRefs(start, stop);
int err;
if (slice == NULL) {
@@ -396,9 +439,11 @@
}
case BINARY_SUBSCR_LIST_INT: {
- PyObject *sub = stack_pointer[-1];
- PyObject *list = stack_pointer[-2];
+ PyObject *sub;
+ PyObject *list;
PyObject *res;
+ sub = stack_pointer[-1];
+ list = stack_pointer[-2];
DEOPT_IF(!PyLong_CheckExact(sub), BINARY_SUBSCR);
DEOPT_IF(!PyList_CheckExact(list), BINARY_SUBSCR);
@@ -418,9 +463,11 @@
}
case BINARY_SUBSCR_TUPLE_INT: {
- PyObject *sub = stack_pointer[-1];
- PyObject *tuple = stack_pointer[-2];
+ PyObject *sub;
+ PyObject *tuple;
PyObject *res;
+ sub = stack_pointer[-1];
+ tuple = stack_pointer[-2];
DEOPT_IF(!PyLong_CheckExact(sub), BINARY_SUBSCR);
DEOPT_IF(!PyTuple_CheckExact(tuple), BINARY_SUBSCR);
@@ -440,9 +487,11 @@
}
case BINARY_SUBSCR_DICT: {
- PyObject *sub = stack_pointer[-1];
- PyObject *dict = stack_pointer[-2];
+ PyObject *sub;
+ PyObject *dict;
PyObject *res;
+ sub = stack_pointer[-1];
+ dict = stack_pointer[-2];
DEOPT_IF(!PyDict_CheckExact(dict), BINARY_SUBSCR);
STAT_INC(BINARY_SUBSCR, hit);
res = PyDict_GetItemWithError(dict, sub);
@@ -463,16 +512,20 @@
}
case LIST_APPEND: {
- PyObject *v = stack_pointer[-1];
- PyObject *list = stack_pointer[-(2 + (oparg-1))];
+ PyObject *v;
+ PyObject *list;
+ v = stack_pointer[-1];
+ list = stack_pointer[-2 - (oparg-1)];
if (_PyList_AppendTakeRef((PyListObject *)list, v) < 0) goto pop_1_error;
STACK_SHRINK(1);
break;
}
case SET_ADD: {
- PyObject *v = stack_pointer[-1];
- PyObject *set = stack_pointer[-(2 + (oparg-1))];
+ PyObject *v;
+ PyObject *set;
+ v = stack_pointer[-1];
+ set = stack_pointer[-2 - (oparg-1)];
int err = PySet_Add(set, v);
Py_DECREF(v);
if (err) goto pop_1_error;
@@ -482,9 +535,12 @@
case STORE_SUBSCR: {
static_assert(INLINE_CACHE_ENTRIES_STORE_SUBSCR == 1, "incorrect cache size");
- PyObject *sub = stack_pointer[-1];
- PyObject *container = stack_pointer[-2];
- PyObject *v = stack_pointer[-3];
+ PyObject *sub;
+ PyObject *container;
+ PyObject *v;
+ sub = stack_pointer[-1];
+ container = stack_pointer[-2];
+ v = stack_pointer[-3];
#if ENABLE_SPECIALIZATION
_PyStoreSubscrCache *cache = (_PyStoreSubscrCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@@ -506,9 +562,12 @@
}
case STORE_SUBSCR_LIST_INT: {
- PyObject *sub = stack_pointer[-1];
- PyObject *list = stack_pointer[-2];
- PyObject *value = stack_pointer[-3];
+ PyObject *sub;
+ PyObject *list;
+ PyObject *value;
+ sub = stack_pointer[-1];
+ list = stack_pointer[-2];
+ value = stack_pointer[-3];
DEOPT_IF(!PyLong_CheckExact(sub), STORE_SUBSCR);
DEOPT_IF(!PyList_CheckExact(list), STORE_SUBSCR);
@@ -530,9 +589,12 @@
}
case STORE_SUBSCR_DICT: {
- PyObject *sub = stack_pointer[-1];
- PyObject *dict = stack_pointer[-2];
- PyObject *value = stack_pointer[-3];
+ PyObject *sub;
+ PyObject *dict;
+ PyObject *value;
+ sub = stack_pointer[-1];
+ dict = stack_pointer[-2];
+ value = stack_pointer[-3];
DEOPT_IF(!PyDict_CheckExact(dict), STORE_SUBSCR);
STAT_INC(STORE_SUBSCR, hit);
int err = _PyDict_SetItem_Take2((PyDictObject *)dict, sub, value);
@@ -543,8 +605,10 @@
}
case DELETE_SUBSCR: {
- PyObject *sub = stack_pointer[-1];
- PyObject *container = stack_pointer[-2];
+ PyObject *sub;
+ PyObject *container;
+ sub = stack_pointer[-1];
+ container = stack_pointer[-2];
/* del container[sub] */
int err = PyObject_DelItem(container, sub);
Py_DECREF(container);
@@ -555,8 +619,9 @@
}
case CALL_INTRINSIC_1: {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
PyObject *res;
+ value = stack_pointer[-1];
assert(oparg <= MAX_INTRINSIC_1);
res = _PyIntrinsics_UnaryFunctions[oparg].func(tstate, value);
Py_DECREF(value);
@@ -566,9 +631,11 @@
}
case CALL_INTRINSIC_2: {
- PyObject *value1 = stack_pointer[-1];
- PyObject *value2 = stack_pointer[-2];
+ PyObject *value1;
+ PyObject *value2;
PyObject *res;
+ value1 = stack_pointer[-1];
+ value2 = stack_pointer[-2];
assert(oparg <= MAX_INTRINSIC_2);
res = _PyIntrinsics_BinaryFunctions[oparg].func(tstate, value2, value1);
Py_DECREF(value2);
@@ -580,8 +647,9 @@
}
case GET_AITER: {
- PyObject *obj = stack_pointer[-1];
+ PyObject *obj;
PyObject *iter;
+ obj = stack_pointer[-1];
unaryfunc getter = NULL;
PyTypeObject *type = Py_TYPE(obj);
@@ -617,8 +685,9 @@
}
case GET_ANEXT: {
- PyObject *aiter = stack_pointer[-1];
+ PyObject *aiter;
PyObject *awaitable;
+ aiter = stack_pointer[-1];
unaryfunc getter = NULL;
PyObject *next_iter = NULL;
PyTypeObject *type = Py_TYPE(aiter);
@@ -667,8 +736,9 @@
}
case GET_AWAITABLE: {
- PyObject *iterable = stack_pointer[-1];
+ PyObject *iterable;
PyObject *iter;
+ iterable = stack_pointer[-1];
iter = _PyCoro_GetAwaitableIter(iterable);
if (iter == NULL) {
@@ -697,7 +767,8 @@
}
case POP_EXCEPT: {
- PyObject *exc_value = stack_pointer[-1];
+ PyObject *exc_value;
+ exc_value = stack_pointer[-1];
_PyErr_StackItem *exc_info = tstate->exc_info;
Py_XSETREF(exc_info->exc_value, exc_value);
STACK_SHRINK(1);
@@ -726,7 +797,8 @@
}
case STORE_NAME: {
- PyObject *v = stack_pointer[-1];
+ PyObject *v;
+ v = stack_pointer[-1];
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
PyObject *ns = LOCALS();
int err;
@@ -768,7 +840,8 @@
case UNPACK_SEQUENCE: {
static_assert(INLINE_CACHE_ENTRIES_UNPACK_SEQUENCE == 1, "incorrect cache size");
- PyObject *seq = stack_pointer[-1];
+ PyObject *seq;
+ seq = stack_pointer[-1];
#if ENABLE_SPECIALIZATION
_PyUnpackSequenceCache *cache = (_PyUnpackSequenceCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@@ -789,8 +862,10 @@
}
case UNPACK_SEQUENCE_TWO_TUPLE: {
- PyObject *seq = stack_pointer[-1];
- PyObject **values = stack_pointer - (1);
+ PyObject *seq;
+ PyObject **values;
+ seq = stack_pointer[-1];
+ values = stack_pointer - 1;
DEOPT_IF(!PyTuple_CheckExact(seq), UNPACK_SEQUENCE);
DEOPT_IF(PyTuple_GET_SIZE(seq) != 2, UNPACK_SEQUENCE);
assert(oparg == 2);
@@ -804,8 +879,10 @@
}
case UNPACK_SEQUENCE_TUPLE: {
- PyObject *seq = stack_pointer[-1];
- PyObject **values = stack_pointer - (1);
+ PyObject *seq;
+ PyObject **values;
+ seq = stack_pointer[-1];
+ values = stack_pointer - 1;
DEOPT_IF(!PyTuple_CheckExact(seq), UNPACK_SEQUENCE);
DEOPT_IF(PyTuple_GET_SIZE(seq) != oparg, UNPACK_SEQUENCE);
STAT_INC(UNPACK_SEQUENCE, hit);
@@ -820,8 +897,10 @@
}
case UNPACK_SEQUENCE_LIST: {
- PyObject *seq = stack_pointer[-1];
- PyObject **values = stack_pointer - (1);
+ PyObject *seq;
+ PyObject **values;
+ seq = stack_pointer[-1];
+ values = stack_pointer - 1;
DEOPT_IF(!PyList_CheckExact(seq), UNPACK_SEQUENCE);
DEOPT_IF(PyList_GET_SIZE(seq) != oparg, UNPACK_SEQUENCE);
STAT_INC(UNPACK_SEQUENCE, hit);
@@ -836,7 +915,8 @@
}
case UNPACK_EX: {
- PyObject *seq = stack_pointer[-1];
+ PyObject *seq;
+ seq = stack_pointer[-1];
int totalargs = 1 + (oparg & 0xFF) + (oparg >> 8);
PyObject **top = stack_pointer + totalargs - 1;
int res = _PyEval_UnpackIterable(tstate, seq, oparg & 0xFF, oparg >> 8, top);
@@ -848,8 +928,10 @@
case STORE_ATTR: {
static_assert(INLINE_CACHE_ENTRIES_STORE_ATTR == 4, "incorrect cache size");
- PyObject *owner = stack_pointer[-1];
- PyObject *v = stack_pointer[-2];
+ PyObject *owner;
+ PyObject *v;
+ owner = stack_pointer[-1];
+ v = stack_pointer[-2];
#if ENABLE_SPECIALIZATION
_PyAttrCache *cache = (_PyAttrCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@@ -871,7 +953,8 @@
}
case DELETE_ATTR: {
- PyObject *owner = stack_pointer[-1];
+ PyObject *owner;
+ owner = stack_pointer[-1];
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
int err = PyObject_DelAttr(owner, name);
Py_DECREF(owner);
@@ -881,7 +964,8 @@
}
case STORE_GLOBAL: {
- PyObject *v = stack_pointer[-1];
+ PyObject *v;
+ v = stack_pointer[-1];
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
int err = PyDict_SetItem(GLOBALS(), name, v);
Py_DECREF(v);
@@ -920,8 +1004,9 @@
}
case _LOAD_FROM_DICT_OR_GLOBALS: {
- PyObject *mod_or_class_dict = stack_pointer[-1];
+ PyObject *mod_or_class_dict;
PyObject *v;
+ mod_or_class_dict = stack_pointer[-1];
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
if (PyMapping_GetOptionalItem(mod_or_class_dict, name, &v) < 0) {
Py_DECREF(mod_or_class_dict);
@@ -1004,8 +1089,8 @@
null = NULL;
STACK_GROW(1);
STACK_GROW(((oparg & 1) ? 1 : 0));
+ if (oparg & 1) { stack_pointer[-1 - (oparg & 1 ? 1 : 0)] = null; }
stack_pointer[-1] = v;
- if (oparg & 1) { stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))] = null; }
break;
}
@@ -1040,8 +1125,8 @@
null = NULL;
STACK_GROW(1);
STACK_GROW(((oparg & 1) ? 1 : 0));
+ if (oparg & 1) { stack_pointer[-1 - (oparg & 1 ? 1 : 0)] = null; }
stack_pointer[-1] = res;
- if (oparg & 1) { stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))] = null; }
break;
}
@@ -1058,8 +1143,8 @@
null = NULL;
STACK_GROW(1);
STACK_GROW(((oparg & 1) ? 1 : 0));
+ if (oparg & 1) { stack_pointer[-1 - (oparg & 1 ? 1 : 0)] = null; }
stack_pointer[-1] = res;
- if (oparg & 1) { stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))] = null; }
break;
}
@@ -1085,8 +1170,9 @@
}
case LOAD_FROM_DICT_OR_DEREF: {
- PyObject *class_dict = stack_pointer[-1];
+ PyObject *class_dict;
PyObject *value;
+ class_dict = stack_pointer[-1];
PyObject *name;
assert(class_dict);
assert(oparg >= 0 && oparg < _PyFrame_GetCode(frame)->co_nlocalsplus);
@@ -1124,7 +1210,8 @@
}
case STORE_DEREF: {
- PyObject *v = stack_pointer[-1];
+ PyObject *v;
+ v = stack_pointer[-1];
PyObject *cell = GETLOCAL(oparg);
PyObject *oldobj = PyCell_GET(cell);
PyCell_SET(cell, v);
@@ -1148,8 +1235,9 @@
}
case BUILD_STRING: {
- PyObject **pieces = (stack_pointer - oparg);
+ PyObject **pieces;
PyObject *str;
+ pieces = stack_pointer - oparg;
str = _PyUnicode_JoinArray(&_Py_STR(empty), pieces, oparg);
for (int _i = oparg; --_i >= 0;) {
Py_DECREF(pieces[_i]);
@@ -1162,8 +1250,9 @@
}
case BUILD_TUPLE: {
- PyObject **values = (stack_pointer - oparg);
+ PyObject **values;
PyObject *tup;
+ values = stack_pointer - oparg;
tup = _PyTuple_FromArraySteal(values, oparg);
if (tup == NULL) { STACK_SHRINK(oparg); goto error; }
STACK_SHRINK(oparg);
@@ -1173,8 +1262,9 @@
}
case BUILD_LIST: {
- PyObject **values = (stack_pointer - oparg);
+ PyObject **values;
PyObject *list;
+ values = stack_pointer - oparg;
list = _PyList_FromArraySteal(values, oparg);
if (list == NULL) { STACK_SHRINK(oparg); goto error; }
STACK_SHRINK(oparg);
@@ -1184,8 +1274,10 @@
}
case LIST_EXTEND: {
- PyObject *iterable = stack_pointer[-1];
- PyObject *list = stack_pointer[-(2 + (oparg-1))];
+ PyObject *iterable;
+ PyObject *list;
+ iterable = stack_pointer[-1];
+ list = stack_pointer[-2 - (oparg-1)];
PyObject *none_val = _PyList_Extend((PyListObject *)list, iterable);
if (none_val == NULL) {
if (_PyErr_ExceptionMatches(tstate, PyExc_TypeError) &&
@@ -1206,8 +1298,10 @@
}
case SET_UPDATE: {
- PyObject *iterable = stack_pointer[-1];
- PyObject *set = stack_pointer[-(2 + (oparg-1))];
+ PyObject *iterable;
+ PyObject *set;
+ iterable = stack_pointer[-1];
+ set = stack_pointer[-2 - (oparg-1)];
int err = _PySet_Update(set, iterable);
Py_DECREF(iterable);
if (err < 0) goto pop_1_error;
@@ -1216,8 +1310,9 @@
}
case BUILD_SET: {
- PyObject **values = (stack_pointer - oparg);
+ PyObject **values;
PyObject *set;
+ values = stack_pointer - oparg;
set = PySet_New(NULL);
if (set == NULL)
goto error;
@@ -1239,8 +1334,9 @@
}
case BUILD_MAP: {
- PyObject **values = (stack_pointer - oparg*2);
+ PyObject **values;
PyObject *map;
+ values = stack_pointer - oparg*2;
map = _PyDict_FromItems(
values, 2,
values+1, 2,
@@ -1300,9 +1396,11 @@
}
case BUILD_CONST_KEY_MAP: {
- PyObject *keys = stack_pointer[-1];
- PyObject **values = (stack_pointer - (1 + oparg));
+ PyObject *keys;
+ PyObject **values;
PyObject *map;
+ keys = stack_pointer[-1];
+ values = stack_pointer - 1 - oparg;
if (!PyTuple_CheckExact(keys) ||
PyTuple_GET_SIZE(keys) != (Py_ssize_t)oparg) {
_PyErr_SetString(tstate, PyExc_SystemError,
@@ -1323,7 +1421,8 @@
}
case DICT_UPDATE: {
- PyObject *update = stack_pointer[-1];
+ PyObject *update;
+ update = stack_pointer[-1];
PyObject *dict = PEEK(oparg + 1); // update is still on the stack
if (PyDict_Update(dict, update) < 0) {
if (_PyErr_ExceptionMatches(tstate, PyExc_AttributeError)) {
@@ -1340,7 +1439,8 @@
}
case DICT_MERGE: {
- PyObject *update = stack_pointer[-1];
+ PyObject *update;
+ update = stack_pointer[-1];
PyObject *dict = PEEK(oparg + 1); // update is still on the stack
if (_PyDict_MergeEx(dict, update, 2) < 0) {
@@ -1354,8 +1454,10 @@
}
case MAP_ADD: {
- PyObject *value = stack_pointer[-1];
- PyObject *key = stack_pointer[-2];
+ PyObject *value;
+ PyObject *key;
+ value = stack_pointer[-1];
+ key = stack_pointer[-2];
PyObject *dict = PEEK(oparg + 2); // key, value are still on the stack
assert(PyDict_CheckExact(dict));
/* dict[key] = value */
@@ -1366,11 +1468,14 @@
}
case LOAD_SUPER_ATTR_ATTR: {
- PyObject *self = stack_pointer[-1];
- PyObject *class = stack_pointer[-2];
- PyObject *global_super = stack_pointer[-3];
+ PyObject *self;
+ PyObject *class;
+ PyObject *global_super;
PyObject *res2 = NULL;
PyObject *res;
+ self = stack_pointer[-1];
+ class = stack_pointer[-2];
+ global_super = stack_pointer[-3];
assert(!(oparg & 1));
DEOPT_IF(global_super != (PyObject *)&PySuper_Type, LOAD_SUPER_ATTR);
DEOPT_IF(!PyType_Check(class), LOAD_SUPER_ATTR);
@@ -1383,17 +1488,20 @@
if (res == NULL) goto pop_3_error;
STACK_SHRINK(2);
STACK_GROW(((oparg & 1) ? 1 : 0));
+ if (oparg & 1) { stack_pointer[-1 - (oparg & 1 ? 1 : 0)] = res2; }
stack_pointer[-1] = res;
- if (oparg & 1) { stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))] = res2; }
break;
}
case LOAD_SUPER_ATTR_METHOD: {
- PyObject *self = stack_pointer[-1];
- PyObject *class = stack_pointer[-2];
- PyObject *global_super = stack_pointer[-3];
+ PyObject *self;
+ PyObject *class;
+ PyObject *global_super;
PyObject *res2;
PyObject *res;
+ self = stack_pointer[-1];
+ class = stack_pointer[-2];
+ global_super = stack_pointer[-3];
assert(oparg & 1);
DEOPT_IF(global_super != (PyObject *)&PySuper_Type, LOAD_SUPER_ATTR);
DEOPT_IF(!PyType_Check(class), LOAD_SUPER_ATTR);
@@ -1417,16 +1525,17 @@
res2 = NULL;
}
STACK_SHRINK(1);
- stack_pointer[-1] = res;
stack_pointer[-2] = res2;
+ stack_pointer[-1] = res;
break;
}
case LOAD_ATTR: {
static_assert(INLINE_CACHE_ENTRIES_LOAD_ATTR == 9, "incorrect cache size");
- PyObject *owner = stack_pointer[-1];
+ PyObject *owner;
PyObject *res2 = NULL;
PyObject *res;
+ owner = stack_pointer[-1];
#if ENABLE_SPECIALIZATION
_PyAttrCache *cache = (_PyAttrCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@@ -1473,13 +1582,14 @@
if (res == NULL) goto pop_1_error;
}
STACK_GROW(((oparg & 1) ? 1 : 0));
+ if (oparg & 1) { stack_pointer[-1 - (oparg & 1 ? 1 : 0)] = res2; }
stack_pointer[-1] = res;
- if (oparg & 1) { stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))] = res2; }
break;
}
case _GUARD_TYPE_VERSION: {
- PyObject *owner = stack_pointer[-1];
+ PyObject *owner;
+ owner = stack_pointer[-1];
uint32_t type_version = (uint32_t)operand;
PyTypeObject *tp = Py_TYPE(owner);
assert(type_version != 0);
@@ -1488,7 +1598,8 @@
}
case _CHECK_MANAGED_OBJECT_HAS_VALUES: {
- PyObject *owner = stack_pointer[-1];
+ PyObject *owner;
+ owner = stack_pointer[-1];
assert(Py_TYPE(owner)->tp_dictoffset < 0);
assert(Py_TYPE(owner)->tp_flags & Py_TPFLAGS_MANAGED_DICT);
PyDictOrValues dorv = *_PyObject_DictOrValuesPointer(owner);
@@ -1497,9 +1608,10 @@
}
case _LOAD_ATTR_INSTANCE_VALUE: {
- PyObject *owner = stack_pointer[-1];
+ PyObject *owner;
PyObject *res2 = NULL;
PyObject *res;
+ owner = stack_pointer[-1];
uint16_t index = (uint16_t)operand;
PyDictOrValues dorv = *_PyObject_DictOrValuesPointer(owner);
res = _PyDictOrValues_GetValues(dorv)->values[index];
@@ -1509,16 +1621,18 @@
res2 = NULL;
Py_DECREF(owner);
STACK_GROW(((oparg & 1) ? 1 : 0));
+ if (oparg & 1) { stack_pointer[-1 - (oparg & 1 ? 1 : 0)] = res2; }
stack_pointer[-1] = res;
- if (oparg & 1) { stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))] = res2; }
break;
}
case COMPARE_OP: {
static_assert(INLINE_CACHE_ENTRIES_COMPARE_OP == 1, "incorrect cache size");
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
PyObject *res;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
#if ENABLE_SPECIALIZATION
_PyCompareOpCache *cache = (_PyCompareOpCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@@ -1546,9 +1660,11 @@
}
case COMPARE_OP_FLOAT: {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
PyObject *res;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
DEOPT_IF(!PyFloat_CheckExact(left), COMPARE_OP);
DEOPT_IF(!PyFloat_CheckExact(right), COMPARE_OP);
STAT_INC(COMPARE_OP, hit);
@@ -1566,9 +1682,11 @@
}
case COMPARE_OP_INT: {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
PyObject *res;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
DEOPT_IF(!PyLong_CheckExact(left), COMPARE_OP);
DEOPT_IF(!PyLong_CheckExact(right), COMPARE_OP);
DEOPT_IF(!_PyLong_IsCompact((PyLongObject *)left), COMPARE_OP);
@@ -1590,9 +1708,11 @@
}
case COMPARE_OP_STR: {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
PyObject *res;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
DEOPT_IF(!PyUnicode_CheckExact(left), COMPARE_OP);
DEOPT_IF(!PyUnicode_CheckExact(right), COMPARE_OP);
STAT_INC(COMPARE_OP, hit);
@@ -1611,9 +1731,11 @@
}
case IS_OP: {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
PyObject *b;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
int res = Py_Is(left, right) ^ oparg;
Py_DECREF(left);
Py_DECREF(right);
@@ -1624,9 +1746,11 @@
}
case CONTAINS_OP: {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
PyObject *b;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
int res = PySequence_Contains(right, left);
Py_DECREF(left);
Py_DECREF(right);
@@ -1638,10 +1762,12 @@
}
case CHECK_EG_MATCH: {
- PyObject *match_type = stack_pointer[-1];
- PyObject *exc_value = stack_pointer[-2];
+ PyObject *match_type;
+ PyObject *exc_value;
PyObject *rest;
PyObject *match;
+ match_type = stack_pointer[-1];
+ exc_value = stack_pointer[-2];
if (_PyEval_CheckExceptStarTypeValid(tstate, match_type) < 0) {
Py_DECREF(exc_value);
Py_DECREF(match_type);
@@ -1662,15 +1788,17 @@
if (!Py_IsNone(match)) {
PyErr_SetHandledException(match);
}
- stack_pointer[-1] = match;
stack_pointer[-2] = rest;
+ stack_pointer[-1] = match;
break;
}
case CHECK_EXC_MATCH: {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
PyObject *b;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
assert(PyExceptionInstance_Check(left));
if (_PyEval_CheckExceptTypeValid(tstate, right) < 0) {
Py_DECREF(right);
@@ -1685,8 +1813,9 @@
}
case IS_NONE: {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
PyObject *b;
+ value = stack_pointer[-1];
if (Py_IsNone(value)) {
b = Py_True;
}
@@ -1699,8 +1828,9 @@
}
case GET_LEN: {
- PyObject *obj = stack_pointer[-1];
+ PyObject *obj;
PyObject *len_o;
+ obj = stack_pointer[-1];
// PUSH(len(TOS))
Py_ssize_t len_i = PyObject_Length(obj);
if (len_i < 0) goto error;
@@ -1712,10 +1842,13 @@
}
case MATCH_CLASS: {
- PyObject *names = stack_pointer[-1];
- PyObject *type = stack_pointer[-2];
- PyObject *subject = stack_pointer[-3];
+ PyObject *names;
+ PyObject *type;
+ PyObject *subject;
PyObject *attrs;
+ names = stack_pointer[-1];
+ type = stack_pointer[-2];
+ subject = stack_pointer[-3];
// Pop TOS and TOS1. Set TOS to a tuple of attributes on success, or
// None on failure.
assert(PyTuple_CheckExact(names));
@@ -1736,8 +1869,9 @@
}
case MATCH_MAPPING: {
- PyObject *subject = stack_pointer[-1];
+ PyObject *subject;
PyObject *res;
+ subject = stack_pointer[-1];
int match = Py_TYPE(subject)->tp_flags & Py_TPFLAGS_MAPPING;
res = match ? Py_True : Py_False;
STACK_GROW(1);
@@ -1746,8 +1880,9 @@
}
case MATCH_SEQUENCE: {
- PyObject *subject = stack_pointer[-1];
+ PyObject *subject;
PyObject *res;
+ subject = stack_pointer[-1];
int match = Py_TYPE(subject)->tp_flags & Py_TPFLAGS_SEQUENCE;
res = match ? Py_True : Py_False;
STACK_GROW(1);
@@ -1756,9 +1891,11 @@
}
case MATCH_KEYS: {
- PyObject *keys = stack_pointer[-1];
- PyObject *subject = stack_pointer[-2];
+ PyObject *keys;
+ PyObject *subject;
PyObject *values_or_none;
+ keys = stack_pointer[-1];
+ subject = stack_pointer[-2];
// On successful match, PUSH(values). Otherwise, PUSH(None).
values_or_none = _PyEval_MatchKeys(tstate, subject, keys);
if (values_or_none == NULL) goto error;
@@ -1768,8 +1905,9 @@
}
case GET_ITER: {
- PyObject *iterable = stack_pointer[-1];
+ PyObject *iterable;
PyObject *iter;
+ iterable = stack_pointer[-1];
/* before: [obj]; after [getiter(obj)] */
iter = PyObject_GetIter(iterable);
Py_DECREF(iterable);
@@ -1779,8 +1917,9 @@
}
case GET_YIELD_FROM_ITER: {
- PyObject *iterable = stack_pointer[-1];
+ PyObject *iterable;
PyObject *iter;
+ iterable = stack_pointer[-1];
/* before: [obj]; after [getiter(obj)] */
if (PyCoro_CheckExact(iterable)) {
/* `iterable` is a coroutine */
@@ -1810,14 +1949,16 @@
}
case _ITER_CHECK_LIST: {
- PyObject *iter = stack_pointer[-1];
+ PyObject *iter;
+ iter = stack_pointer[-1];
DEOPT_IF(Py_TYPE(iter) != &PyListIter_Type, FOR_ITER);
break;
}
case _IS_ITER_EXHAUSTED_LIST: {
- PyObject *iter = stack_pointer[-1];
+ PyObject *iter;
PyObject *exhausted;
+ iter = stack_pointer[-1];
_PyListIterObject *it = (_PyListIterObject *)iter;
assert(Py_TYPE(iter) == &PyListIter_Type);
PyListObject *seq = it->it_seq;
@@ -1838,8 +1979,9 @@
}
case _ITER_NEXT_LIST: {
- PyObject *iter = stack_pointer[-1];
+ PyObject *iter;
PyObject *next;
+ iter = stack_pointer[-1];
_PyListIterObject *it = (_PyListIterObject *)iter;
assert(Py_TYPE(iter) == &PyListIter_Type);
PyListObject *seq = it->it_seq;
@@ -1852,14 +1994,16 @@
}
case _ITER_CHECK_TUPLE: {
- PyObject *iter = stack_pointer[-1];
+ PyObject *iter;
+ iter = stack_pointer[-1];
DEOPT_IF(Py_TYPE(iter) != &PyTupleIter_Type, FOR_ITER);
break;
}
case _IS_ITER_EXHAUSTED_TUPLE: {
- PyObject *iter = stack_pointer[-1];
+ PyObject *iter;
PyObject *exhausted;
+ iter = stack_pointer[-1];
_PyTupleIterObject *it = (_PyTupleIterObject *)iter;
assert(Py_TYPE(iter) == &PyTupleIter_Type);
PyTupleObject *seq = it->it_seq;
@@ -1880,8 +2024,9 @@
}
case _ITER_NEXT_TUPLE: {
- PyObject *iter = stack_pointer[-1];
+ PyObject *iter;
PyObject *next;
+ iter = stack_pointer[-1];
_PyTupleIterObject *it = (_PyTupleIterObject *)iter;
assert(Py_TYPE(iter) == &PyTupleIter_Type);
PyTupleObject *seq = it->it_seq;
@@ -1894,15 +2039,17 @@
}
case _ITER_CHECK_RANGE: {
- PyObject *iter = stack_pointer[-1];
+ PyObject *iter;
+ iter = stack_pointer[-1];
_PyRangeIterObject *r = (_PyRangeIterObject *)iter;
DEOPT_IF(Py_TYPE(r) != &PyRangeIter_Type, FOR_ITER);
break;
}
case _IS_ITER_EXHAUSTED_RANGE: {
- PyObject *iter = stack_pointer[-1];
+ PyObject *iter;
PyObject *exhausted;
+ iter = stack_pointer[-1];
_PyRangeIterObject *r = (_PyRangeIterObject *)iter;
assert(Py_TYPE(r) == &PyRangeIter_Type);
exhausted = r->len <= 0 ? Py_True : Py_False;
@@ -1912,8 +2059,9 @@
}
case _ITER_NEXT_RANGE: {
- PyObject *iter = stack_pointer[-1];
+ PyObject *iter;
PyObject *next;
+ iter = stack_pointer[-1];
_PyRangeIterObject *r = (_PyRangeIterObject *)iter;
assert(Py_TYPE(r) == &PyRangeIter_Type);
assert(r->len > 0);
@@ -1928,10 +2076,13 @@
}
case WITH_EXCEPT_START: {
- PyObject *val = stack_pointer[-1];
- PyObject *lasti = stack_pointer[-3];
- PyObject *exit_func = stack_pointer[-4];
+ PyObject *val;
+ PyObject *lasti;
+ PyObject *exit_func;
PyObject *res;
+ val = stack_pointer[-1];
+ lasti = stack_pointer[-3];
+ exit_func = stack_pointer[-4];
/* At the top of the stack are 4 values:
- val: TOP = exc_info()
- unused: SECOND = previous exception
@@ -1963,8 +2114,9 @@
}
case PUSH_EXC_INFO: {
- PyObject *new_exc = stack_pointer[-1];
+ PyObject *new_exc;
PyObject *prev_exc;
+ new_exc = stack_pointer[-1];
_PyErr_StackItem *exc_info = tstate->exc_info;
if (exc_info->exc_value != NULL) {
prev_exc = exc_info->exc_value;
@@ -1975,16 +2127,19 @@
assert(PyExceptionInstance_Check(new_exc));
exc_info->exc_value = Py_NewRef(new_exc);
STACK_GROW(1);
- stack_pointer[-1] = new_exc;
stack_pointer[-2] = prev_exc;
+ stack_pointer[-1] = new_exc;
break;
}
case CALL_NO_KW_TYPE_1: {
- PyObject **args = (stack_pointer - oparg);
- PyObject *callable = stack_pointer[-(1 + oparg)];
- PyObject *null = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *callable;
+ PyObject *null;
PyObject *res;
+ args = stack_pointer - oparg;
+ callable = stack_pointer[-1 - oparg];
+ null = stack_pointer[-2 - oparg];
ASSERT_KWNAMES_IS_NULL();
assert(oparg == 1);
DEOPT_IF(null != NULL, CALL);
@@ -2001,10 +2156,13 @@
}
case CALL_NO_KW_STR_1: {
- PyObject **args = (stack_pointer - oparg);
- PyObject *callable = stack_pointer[-(1 + oparg)];
- PyObject *null = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *callable;
+ PyObject *null;
PyObject *res;
+ args = stack_pointer - oparg;
+ callable = stack_pointer[-1 - oparg];
+ null = stack_pointer[-2 - oparg];
ASSERT_KWNAMES_IS_NULL();
assert(oparg == 1);
DEOPT_IF(null != NULL, CALL);
@@ -2023,10 +2181,13 @@
}
case CALL_NO_KW_TUPLE_1: {
- PyObject **args = (stack_pointer - oparg);
- PyObject *callable = stack_pointer[-(1 + oparg)];
- PyObject *null = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *callable;
+ PyObject *null;
PyObject *res;
+ args = stack_pointer - oparg;
+ callable = stack_pointer[-1 - oparg];
+ null = stack_pointer[-2 - oparg];
ASSERT_KWNAMES_IS_NULL();
assert(oparg == 1);
DEOPT_IF(null != NULL, CALL);
@@ -2045,7 +2206,8 @@
}
case EXIT_INIT_CHECK: {
- PyObject *should_be_none = stack_pointer[-1];
+ PyObject *should_be_none;
+ should_be_none = stack_pointer[-1];
assert(STACK_LEVEL() == 2);
if (should_be_none != Py_None) {
PyErr_Format(PyExc_TypeError,
@@ -2058,10 +2220,13 @@
}
case CALL_NO_KW_BUILTIN_O: {
- PyObject **args = (stack_pointer - oparg);
- PyObject *callable = stack_pointer[-(1 + oparg)];
- PyObject *method = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *callable;
+ PyObject *method;
PyObject *res;
+ args = stack_pointer - oparg;
+ callable = stack_pointer[-1 - oparg];
+ method = stack_pointer[-2 - oparg];
/* Builtin METH_O functions */
ASSERT_KWNAMES_IS_NULL();
int is_meth = method != NULL;
@@ -2097,10 +2262,13 @@
}
case CALL_NO_KW_BUILTIN_FAST: {
- PyObject **args = (stack_pointer - oparg);
- PyObject *callable = stack_pointer[-(1 + oparg)];
- PyObject *method = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *callable;
+ PyObject *method;
PyObject *res;
+ args = stack_pointer - oparg;
+ callable = stack_pointer[-1 - oparg];
+ method = stack_pointer[-2 - oparg];
/* Builtin METH_FASTCALL functions, without keywords */
ASSERT_KWNAMES_IS_NULL();
int is_meth = method != NULL;
@@ -2140,10 +2308,13 @@
}
case CALL_NO_KW_LEN: {
- PyObject **args = (stack_pointer - oparg);
- PyObject *callable = stack_pointer[-(1 + oparg)];
- PyObject *method = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *callable;
+ PyObject *method;
PyObject *res;
+ args = stack_pointer - oparg;
+ callable = stack_pointer[-1 - oparg];
+ method = stack_pointer[-2 - oparg];
ASSERT_KWNAMES_IS_NULL();
/* len(o) */
int is_meth = method != NULL;
@@ -2175,10 +2346,13 @@
}
case CALL_NO_KW_ISINSTANCE: {
- PyObject **args = (stack_pointer - oparg);
- PyObject *callable = stack_pointer[-(1 + oparg)];
- PyObject *method = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *callable;
+ PyObject *method;
PyObject *res;
+ args = stack_pointer - oparg;
+ callable = stack_pointer[-1 - oparg];
+ method = stack_pointer[-2 - oparg];
ASSERT_KWNAMES_IS_NULL();
/* isinstance(o, o2) */
int is_meth = method != NULL;
@@ -2212,9 +2386,11 @@
}
case CALL_NO_KW_METHOD_DESCRIPTOR_O: {
- PyObject **args = (stack_pointer - oparg);
- PyObject *method = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *method;
PyObject *res;
+ args = stack_pointer - oparg;
+ method = stack_pointer[-2 - oparg];
ASSERT_KWNAMES_IS_NULL();
int is_meth = method != NULL;
int total_args = oparg;
@@ -2253,9 +2429,11 @@
}
case CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS: {
- PyObject **args = (stack_pointer - oparg);
- PyObject *method = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *method;
PyObject *res;
+ args = stack_pointer - oparg;
+ method = stack_pointer[-2 - oparg];
ASSERT_KWNAMES_IS_NULL();
assert(oparg == 0 || oparg == 1);
int is_meth = method != NULL;
@@ -2292,9 +2470,11 @@
}
case CALL_NO_KW_METHOD_DESCRIPTOR_FAST: {
- PyObject **args = (stack_pointer - oparg);
- PyObject *method = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *method;
PyObject *res;
+ args = stack_pointer - oparg;
+ method = stack_pointer[-2 - oparg];
ASSERT_KWNAMES_IS_NULL();
int is_meth = method != NULL;
int total_args = oparg;
@@ -2330,8 +2510,9 @@
}
case MAKE_FUNCTION: {
- PyObject *codeobj = stack_pointer[-1];
+ PyObject *codeobj;
PyObject *func;
+ codeobj = stack_pointer[-1];
PyFunctionObject *func_obj = (PyFunctionObject *)
PyFunction_New(codeobj, GLOBALS());
@@ -2348,8 +2529,10 @@
}
case SET_FUNCTION_ATTRIBUTE: {
- PyObject *func = stack_pointer[-1];
- PyObject *attr = stack_pointer[-2];
+ PyObject *func;
+ PyObject *attr;
+ func = stack_pointer[-1];
+ attr = stack_pointer[-2];
assert(PyFunction_Check(func));
PyFunctionObject *func_obj = (PyFunctionObject *)func;
switch(oparg) {
@@ -2380,10 +2563,13 @@
}
case BUILD_SLICE: {
- PyObject *step = (oparg == 3) ? stack_pointer[-(((oparg == 3) ? 1 : 0))] : NULL;
- PyObject *stop = stack_pointer[-(1 + ((oparg == 3) ? 1 : 0))];
- PyObject *start = stack_pointer[-(2 + ((oparg == 3) ? 1 : 0))];
+ PyObject *step = NULL;
+ PyObject *stop;
+ PyObject *start;
PyObject *slice;
+ if (oparg == 3) { step = stack_pointer[-(oparg == 3 ? 1 : 0)]; }
+ stop = stack_pointer[-1 - (oparg == 3 ? 1 : 0)];
+ start = stack_pointer[-2 - (oparg == 3 ? 1 : 0)];
slice = PySlice_New(start, stop, step);
Py_DECREF(start);
Py_DECREF(stop);
@@ -2396,8 +2582,9 @@
}
case CONVERT_VALUE: {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
PyObject *result;
+ value = stack_pointer[-1];
convertion_func_ptr conv_fn;
assert(oparg >= FVC_STR && oparg <= FVC_ASCII);
conv_fn = CONVERSION_FUNCTIONS[oparg];
@@ -2409,8 +2596,9 @@
}
case FORMAT_SIMPLE: {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
PyObject *res;
+ value = stack_pointer[-1];
/* If value is a unicode object, then we know the result
* of format(value) is value itself. */
if (!PyUnicode_CheckExact(value)) {
@@ -2426,9 +2614,11 @@
}
case FORMAT_WITH_SPEC: {
- PyObject *fmt_spec = stack_pointer[-1];
- PyObject *value = stack_pointer[-2];
+ PyObject *fmt_spec;
+ PyObject *value;
PyObject *res;
+ fmt_spec = stack_pointer[-1];
+ value = stack_pointer[-2];
res = PyObject_Format(value, fmt_spec);
Py_DECREF(value);
Py_DECREF(fmt_spec);
@@ -2439,8 +2629,9 @@
}
case COPY: {
- PyObject *bottom = stack_pointer[-(1 + (oparg-1))];
+ PyObject *bottom;
PyObject *top;
+ bottom = stack_pointer[-1 - (oparg-1)];
assert(oparg > 0);
top = Py_NewRef(bottom);
STACK_GROW(1);
@@ -2450,9 +2641,11 @@
case BINARY_OP: {
static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 1, "incorrect cache size");
- PyObject *rhs = stack_pointer[-1];
- PyObject *lhs = stack_pointer[-2];
+ PyObject *rhs;
+ PyObject *lhs;
PyObject *res;
+ rhs = stack_pointer[-1];
+ lhs = stack_pointer[-2];
#if ENABLE_SPECIALIZATION
_PyBinaryOpCache *cache = (_PyBinaryOpCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@@ -2476,16 +2669,19 @@
}
case SWAP: {
- PyObject *top = stack_pointer[-1];
- PyObject *bottom = stack_pointer[-(2 + (oparg-2))];
+ PyObject *top;
+ PyObject *bottom;
+ top = stack_pointer[-1];
+ bottom = stack_pointer[-2 - (oparg-2)];
assert(oparg >= 2);
+ stack_pointer[-2 - (oparg-2)] = top;
stack_pointer[-1] = bottom;
- stack_pointer[-(2 + (oparg-2))] = top;
break;
}
case _POP_JUMP_IF_FALSE: {
- PyObject *flag = stack_pointer[-1];
+ PyObject *flag;
+ flag = stack_pointer[-1];
if (Py_IsFalse(flag)) {
pc = oparg;
}
@@ -2494,7 +2690,8 @@
}
case _POP_JUMP_IF_TRUE: {
- PyObject *flag = stack_pointer[-1];
+ PyObject *flag;
+ flag = stack_pointer[-1];
if (Py_IsTrue(flag)) {
pc = oparg;
}
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index 9fa549a120324..7250240ac2396 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -91,8 +91,8 @@
Py_INCREF(value1);
Py_INCREF(value2);
STACK_GROW(2);
- stack_pointer[-1] = value2;
stack_pointer[-2] = value1;
+ stack_pointer[-1] = value2;
DISPATCH();
}
@@ -106,15 +106,17 @@
}
TARGET(STORE_FAST) {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
+ value = stack_pointer[-1];
SETLOCAL(oparg, value);
STACK_SHRINK(1);
DISPATCH();
}
TARGET(STORE_FAST_LOAD_FAST) {
- PyObject *value1 = stack_pointer[-1];
+ PyObject *value1;
PyObject *value2;
+ value1 = stack_pointer[-1];
uint32_t oparg1 = oparg >> 4;
uint32_t oparg2 = oparg & 15;
SETLOCAL(oparg1, value1);
@@ -125,8 +127,10 @@
}
TARGET(STORE_FAST_STORE_FAST) {
- PyObject *value1 = stack_pointer[-1];
- PyObject *value2 = stack_pointer[-2];
+ PyObject *value1;
+ PyObject *value2;
+ value1 = stack_pointer[-1];
+ value2 = stack_pointer[-2];
uint32_t oparg1 = oparg >> 4;
uint32_t oparg2 = oparg & 15;
SETLOCAL(oparg1, value1);
@@ -136,7 +140,8 @@
}
TARGET(POP_TOP) {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
+ value = stack_pointer[-1];
Py_DECREF(value);
STACK_SHRINK(1);
DISPATCH();
@@ -151,14 +156,15 @@
}
TARGET(END_FOR) {
- PyObject *_tmp_1 = stack_pointer[-1];
- PyObject *_tmp_2 = stack_pointer[-2];
+ PyObject *value;
+ // POP_TOP
+ value = stack_pointer[-1];
{
- PyObject *value = _tmp_1;
Py_DECREF(value);
}
+ // POP_TOP
+ value = stack_pointer[-2];
{
- PyObject *value = _tmp_2;
Py_DECREF(value);
}
STACK_SHRINK(2);
@@ -166,8 +172,10 @@
}
TARGET(INSTRUMENTED_END_FOR) {
- PyObject *value = stack_pointer[-1];
- PyObject *receiver = stack_pointer[-2];
+ PyObject *value;
+ PyObject *receiver;
+ value = stack_pointer[-1];
+ receiver = stack_pointer[-2];
/* Need to create a fake StopIteration error here,
* to conform to PEP 380 */
if (PyGen_Check(receiver)) {
@@ -184,8 +192,10 @@
}
TARGET(END_SEND) {
- PyObject *value = stack_pointer[-1];
- PyObject *receiver = stack_pointer[-2];
+ PyObject *value;
+ PyObject *receiver;
+ value = stack_pointer[-1];
+ receiver = stack_pointer[-2];
Py_DECREF(receiver);
STACK_SHRINK(1);
stack_pointer[-1] = value;
@@ -193,8 +203,10 @@
}
TARGET(INSTRUMENTED_END_SEND) {
- PyObject *value = stack_pointer[-1];
- PyObject *receiver = stack_pointer[-2];
+ PyObject *value;
+ PyObject *receiver;
+ value = stack_pointer[-1];
+ receiver = stack_pointer[-2];
if (PyGen_Check(receiver) || PyCoro_CheckExact(receiver)) {
PyErr_SetObject(PyExc_StopIteration, value);
if (monitor_stop_iteration(tstate, frame, next_instr-1)) {
@@ -209,8 +221,9 @@
}
TARGET(UNARY_NEGATIVE) {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
PyObject *res;
+ value = stack_pointer[-1];
res = PyNumber_Negative(value);
Py_DECREF(value);
if (res == NULL) goto pop_1_error;
@@ -219,8 +232,9 @@
}
TARGET(UNARY_NOT) {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
PyObject *res;
+ value = stack_pointer[-1];
assert(PyBool_Check(value));
res = Py_IsFalse(value) ? Py_True : Py_False;
stack_pointer[-1] = res;
@@ -230,8 +244,9 @@
TARGET(TO_BOOL) {
PREDICTED(TO_BOOL);
static_assert(INLINE_CACHE_ENTRIES_TO_BOOL == 3, "incorrect cache size");
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
PyObject *res;
+ value = stack_pointer[-1];
#if ENABLE_SPECIALIZATION
_PyToBoolCache *cache = (_PyToBoolCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@@ -252,7 +267,8 @@
}
TARGET(TO_BOOL_BOOL) {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
+ value = stack_pointer[-1];
DEOPT_IF(!PyBool_Check(value), TO_BOOL);
STAT_INC(TO_BOOL, hit);
next_instr += 3;
@@ -260,8 +276,9 @@
}
TARGET(TO_BOOL_INT) {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
PyObject *res;
+ value = stack_pointer[-1];
DEOPT_IF(!PyLong_CheckExact(value), TO_BOOL);
STAT_INC(TO_BOOL, hit);
if (_PyLong_IsZero((PyLongObject *)value)) {
@@ -278,8 +295,9 @@
}
TARGET(TO_BOOL_LIST) {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
PyObject *res;
+ value = stack_pointer[-1];
DEOPT_IF(!PyList_CheckExact(value), TO_BOOL);
STAT_INC(TO_BOOL, hit);
res = Py_SIZE(value) ? Py_True : Py_False;
@@ -290,8 +308,9 @@
}
TARGET(TO_BOOL_NONE) {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
PyObject *res;
+ value = stack_pointer[-1];
// This one is a bit weird, because we expect *some* failures:
DEOPT_IF(!Py_IsNone(value), TO_BOOL);
STAT_INC(TO_BOOL, hit);
@@ -302,8 +321,9 @@
}
TARGET(TO_BOOL_STR) {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
PyObject *res;
+ value = stack_pointer[-1];
DEOPT_IF(!PyUnicode_CheckExact(value), TO_BOOL);
STAT_INC(TO_BOOL, hit);
if (value == &_Py_STR(empty)) {
@@ -321,8 +341,9 @@
}
TARGET(TO_BOOL_ALWAYS_TRUE) {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
PyObject *res;
+ value = stack_pointer[-1];
uint32_t version = read_u32(&next_instr[1].cache);
// This one is a bit weird, because we expect *some* failures:
assert(version);
@@ -336,8 +357,9 @@
}
TARGET(UNARY_INVERT) {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
PyObject *res;
+ value = stack_pointer[-1];
res = PyNumber_Invert(value);
Py_DECREF(value);
if (res == NULL) goto pop_1_error;
@@ -346,215 +368,192 @@
}
TARGET(BINARY_OP_MULTIPLY_INT) {
- PyObject *_tmp_1 = stack_pointer[-1];
- PyObject *_tmp_2 = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
+ PyObject *res;
+ // _GUARD_BOTH_INT
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
{
- PyObject *right = _tmp_1;
- PyObject *left = _tmp_2;
DEOPT_IF(!PyLong_CheckExact(left), BINARY_OP);
DEOPT_IF(!PyLong_CheckExact(right), BINARY_OP);
- _tmp_2 = left;
- _tmp_1 = right;
}
+ // _BINARY_OP_MULTIPLY_INT
{
- PyObject *right = _tmp_1;
- PyObject *left = _tmp_2;
- PyObject *res;
STAT_INC(BINARY_OP, hit);
res = _PyLong_Multiply((PyLongObject *)left, (PyLongObject *)right);
_Py_DECREF_SPECIALIZED(right, (destructor)PyObject_Free);
_Py_DECREF_SPECIALIZED(left, (destructor)PyObject_Free);
if (res == NULL) goto pop_2_error;
- _tmp_2 = res;
}
- next_instr += 1;
STACK_SHRINK(1);
- stack_pointer[-1] = _tmp_2;
+ stack_pointer[-1] = res;
+ next_instr += 1;
DISPATCH();
}
TARGET(BINARY_OP_ADD_INT) {
- PyObject *_tmp_1 = stack_pointer[-1];
- PyObject *_tmp_2 = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
+ PyObject *res;
+ // _GUARD_BOTH_INT
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
{
- PyObject *right = _tmp_1;
- PyObject *left = _tmp_2;
DEOPT_IF(!PyLong_CheckExact(left), BINARY_OP);
DEOPT_IF(!PyLong_CheckExact(right), BINARY_OP);
- _tmp_2 = left;
- _tmp_1 = right;
}
+ // _BINARY_OP_ADD_INT
{
- PyObject *right = _tmp_1;
- PyObject *left = _tmp_2;
- PyObject *res;
STAT_INC(BINARY_OP, hit);
res = _PyLong_Add((PyLongObject *)left, (PyLongObject *)right);
_Py_DECREF_SPECIALIZED(right, (destructor)PyObject_Free);
_Py_DECREF_SPECIALIZED(left, (destructor)PyObject_Free);
if (res == NULL) goto pop_2_error;
- _tmp_2 = res;
}
- next_instr += 1;
STACK_SHRINK(1);
- stack_pointer[-1] = _tmp_2;
+ stack_pointer[-1] = res;
+ next_instr += 1;
DISPATCH();
}
TARGET(BINARY_OP_SUBTRACT_INT) {
- PyObject *_tmp_1 = stack_pointer[-1];
- PyObject *_tmp_2 = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
+ PyObject *res;
+ // _GUARD_BOTH_INT
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
{
- PyObject *right = _tmp_1;
- PyObject *left = _tmp_2;
DEOPT_IF(!PyLong_CheckExact(left), BINARY_OP);
DEOPT_IF(!PyLong_CheckExact(right), BINARY_OP);
- _tmp_2 = left;
- _tmp_1 = right;
}
+ // _BINARY_OP_SUBTRACT_INT
{
- PyObject *right = _tmp_1;
- PyObject *left = _tmp_2;
- PyObject *res;
STAT_INC(BINARY_OP, hit);
res = _PyLong_Subtract((PyLongObject *)left, (PyLongObject *)right);
_Py_DECREF_SPECIALIZED(right, (destructor)PyObject_Free);
_Py_DECREF_SPECIALIZED(left, (destructor)PyObject_Free);
if (res == NULL) goto pop_2_error;
- _tmp_2 = res;
}
- next_instr += 1;
STACK_SHRINK(1);
- stack_pointer[-1] = _tmp_2;
+ stack_pointer[-1] = res;
+ next_instr += 1;
DISPATCH();
}
TARGET(BINARY_OP_MULTIPLY_FLOAT) {
- PyObject *_tmp_1 = stack_pointer[-1];
- PyObject *_tmp_2 = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
+ PyObject *res;
+ // _GUARD_BOTH_FLOAT
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
{
- PyObject *right = _tmp_1;
- PyObject *left = _tmp_2;
DEOPT_IF(!PyFloat_CheckExact(left), BINARY_OP);
DEOPT_IF(!PyFloat_CheckExact(right), BINARY_OP);
- _tmp_2 = left;
- _tmp_1 = right;
}
+ // _BINARY_OP_MULTIPLY_FLOAT
{
- PyObject *right = _tmp_1;
- PyObject *left = _tmp_2;
- PyObject *res;
STAT_INC(BINARY_OP, hit);
double dres =
((PyFloatObject *)left)->ob_fval *
((PyFloatObject *)right)->ob_fval;
DECREF_INPUTS_AND_REUSE_FLOAT(left, right, dres, res);
- _tmp_2 = res;
}
- next_instr += 1;
STACK_SHRINK(1);
- stack_pointer[-1] = _tmp_2;
+ stack_pointer[-1] = res;
+ next_instr += 1;
DISPATCH();
}
TARGET(BINARY_OP_ADD_FLOAT) {
- PyObject *_tmp_1 = stack_pointer[-1];
- PyObject *_tmp_2 = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
+ PyObject *res;
+ // _GUARD_BOTH_FLOAT
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
{
- PyObject *right = _tmp_1;
- PyObject *left = _tmp_2;
DEOPT_IF(!PyFloat_CheckExact(left), BINARY_OP);
DEOPT_IF(!PyFloat_CheckExact(right), BINARY_OP);
- _tmp_2 = left;
- _tmp_1 = right;
}
+ // _BINARY_OP_ADD_FLOAT
{
- PyObject *right = _tmp_1;
- PyObject *left = _tmp_2;
- PyObject *res;
STAT_INC(BINARY_OP, hit);
double dres =
((PyFloatObject *)left)->ob_fval +
((PyFloatObject *)right)->ob_fval;
DECREF_INPUTS_AND_REUSE_FLOAT(left, right, dres, res);
- _tmp_2 = res;
}
- next_instr += 1;
STACK_SHRINK(1);
- stack_pointer[-1] = _tmp_2;
+ stack_pointer[-1] = res;
+ next_instr += 1;
DISPATCH();
}
TARGET(BINARY_OP_SUBTRACT_FLOAT) {
- PyObject *_tmp_1 = stack_pointer[-1];
- PyObject *_tmp_2 = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
+ PyObject *res;
+ // _GUARD_BOTH_FLOAT
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
{
- PyObject *right = _tmp_1;
- PyObject *left = _tmp_2;
DEOPT_IF(!PyFloat_CheckExact(left), BINARY_OP);
DEOPT_IF(!PyFloat_CheckExact(right), BINARY_OP);
- _tmp_2 = left;
- _tmp_1 = right;
}
+ // _BINARY_OP_SUBTRACT_FLOAT
{
- PyObject *right = _tmp_1;
- PyObject *left = _tmp_2;
- PyObject *res;
STAT_INC(BINARY_OP, hit);
double dres =
((PyFloatObject *)left)->ob_fval -
((PyFloatObject *)right)->ob_fval;
DECREF_INPUTS_AND_REUSE_FLOAT(left, right, dres, res);
- _tmp_2 = res;
}
- next_instr += 1;
STACK_SHRINK(1);
- stack_pointer[-1] = _tmp_2;
+ stack_pointer[-1] = res;
+ next_instr += 1;
DISPATCH();
}
TARGET(BINARY_OP_ADD_UNICODE) {
- PyObject *_tmp_1 = stack_pointer[-1];
- PyObject *_tmp_2 = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
+ PyObject *res;
+ // _GUARD_BOTH_UNICODE
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
{
- PyObject *right = _tmp_1;
- PyObject *left = _tmp_2;
DEOPT_IF(!PyUnicode_CheckExact(left), BINARY_OP);
DEOPT_IF(!PyUnicode_CheckExact(right), BINARY_OP);
- _tmp_2 = left;
- _tmp_1 = right;
}
+ // _BINARY_OP_ADD_UNICODE
{
- PyObject *right = _tmp_1;
- PyObject *left = _tmp_2;
- PyObject *res;
STAT_INC(BINARY_OP, hit);
res = PyUnicode_Concat(left, right);
_Py_DECREF_SPECIALIZED(left, _PyUnicode_ExactDealloc);
_Py_DECREF_SPECIALIZED(right, _PyUnicode_ExactDealloc);
if (res == NULL) goto pop_2_error;
- _tmp_2 = res;
}
- next_instr += 1;
STACK_SHRINK(1);
- stack_pointer[-1] = _tmp_2;
+ stack_pointer[-1] = res;
+ next_instr += 1;
DISPATCH();
}
TARGET(BINARY_OP_INPLACE_ADD_UNICODE) {
- PyObject *_tmp_1 = stack_pointer[-1];
- PyObject *_tmp_2 = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
+ // _GUARD_BOTH_UNICODE
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
{
- PyObject *right = _tmp_1;
- PyObject *left = _tmp_2;
DEOPT_IF(!PyUnicode_CheckExact(left), BINARY_OP);
DEOPT_IF(!PyUnicode_CheckExact(right), BINARY_OP);
- _tmp_2 = left;
- _tmp_1 = right;
}
+ // _BINARY_OP_INPLACE_ADD_UNICODE
{
- PyObject *right = _tmp_1;
- PyObject *left = _tmp_2;
_Py_CODEUNIT true_next = next_instr[INLINE_CACHE_ENTRIES_BINARY_OP];
assert(true_next.op.code == STORE_FAST);
PyObject **target_local = &GETLOCAL(true_next.op.arg);
@@ -586,9 +585,11 @@
TARGET(BINARY_SUBSCR) {
PREDICTED(BINARY_SUBSCR);
static_assert(INLINE_CACHE_ENTRIES_BINARY_SUBSCR == 1, "incorrect cache size");
- PyObject *sub = stack_pointer[-1];
- PyObject *container = stack_pointer[-2];
+ PyObject *sub;
+ PyObject *container;
PyObject *res;
+ sub = stack_pointer[-1];
+ container = stack_pointer[-2];
#if ENABLE_SPECIALIZATION
_PyBinarySubscrCache *cache = (_PyBinarySubscrCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@@ -610,10 +611,13 @@
}
TARGET(BINARY_SLICE) {
- PyObject *stop = stack_pointer[-1];
- PyObject *start = stack_pointer[-2];
- PyObject *container = stack_pointer[-3];
+ PyObject *stop;
+ PyObject *start;
+ PyObject *container;
PyObject *res;
+ stop = stack_pointer[-1];
+ start = stack_pointer[-2];
+ container = stack_pointer[-3];
PyObject *slice = _PyBuildSlice_ConsumeRefs(start, stop);
// Can't use ERROR_IF() here, because we haven't
// DECREF'ed container yet, and we still own slice.
@@ -632,10 +636,14 @@
}
TARGET(STORE_SLICE) {
- PyObject *stop = stack_pointer[-1];
- PyObject *start = stack_pointer[-2];
- PyObject *container = stack_pointer[-3];
- PyObject *v = stack_pointer[-4];
+ PyObject *stop;
+ PyObject *start;
+ PyObject *container;
+ PyObject *v;
+ stop = stack_pointer[-1];
+ start = stack_pointer[-2];
+ container = stack_pointer[-3];
+ v = stack_pointer[-4];
PyObject *slice = _PyBuildSlice_ConsumeRefs(start, stop);
int err;
if (slice == NULL) {
@@ -653,9 +661,11 @@
}
TARGET(BINARY_SUBSCR_LIST_INT) {
- PyObject *sub = stack_pointer[-1];
- PyObject *list = stack_pointer[-2];
+ PyObject *sub;
+ PyObject *list;
PyObject *res;
+ sub = stack_pointer[-1];
+ list = stack_pointer[-2];
DEOPT_IF(!PyLong_CheckExact(sub), BINARY_SUBSCR);
DEOPT_IF(!PyList_CheckExact(list), BINARY_SUBSCR);
@@ -676,9 +686,11 @@
}
TARGET(BINARY_SUBSCR_TUPLE_INT) {
- PyObject *sub = stack_pointer[-1];
- PyObject *tuple = stack_pointer[-2];
+ PyObject *sub;
+ PyObject *tuple;
PyObject *res;
+ sub = stack_pointer[-1];
+ tuple = stack_pointer[-2];
DEOPT_IF(!PyLong_CheckExact(sub), BINARY_SUBSCR);
DEOPT_IF(!PyTuple_CheckExact(tuple), BINARY_SUBSCR);
@@ -699,9 +711,11 @@
}
TARGET(BINARY_SUBSCR_DICT) {
- PyObject *sub = stack_pointer[-1];
- PyObject *dict = stack_pointer[-2];
+ PyObject *sub;
+ PyObject *dict;
PyObject *res;
+ sub = stack_pointer[-1];
+ dict = stack_pointer[-2];
DEOPT_IF(!PyDict_CheckExact(dict), BINARY_SUBSCR);
STAT_INC(BINARY_SUBSCR, hit);
res = PyDict_GetItemWithError(dict, sub);
@@ -723,8 +737,10 @@
}
TARGET(BINARY_SUBSCR_GETITEM) {
- PyObject *sub = stack_pointer[-1];
- PyObject *container = stack_pointer[-2];
+ PyObject *sub;
+ PyObject *container;
+ sub = stack_pointer[-1];
+ container = stack_pointer[-2];
DEOPT_IF(tstate->interp->eval_frame, BINARY_SUBSCR);
PyTypeObject *tp = Py_TYPE(container);
DEOPT_IF(!PyType_HasFeature(tp, Py_TPFLAGS_HEAPTYPE), BINARY_SUBSCR);
@@ -747,19 +763,24 @@
SKIP_OVER(INLINE_CACHE_ENTRIES_BINARY_SUBSCR);
frame->return_offset = 0;
DISPATCH_INLINED(new_frame);
+ STACK_SHRINK(1);
}
TARGET(LIST_APPEND) {
- PyObject *v = stack_pointer[-1];
- PyObject *list = stack_pointer[-(2 + (oparg-1))];
+ PyObject *v;
+ PyObject *list;
+ v = stack_pointer[-1];
+ list = stack_pointer[-2 - (oparg-1)];
if (_PyList_AppendTakeRef((PyListObject *)list, v) < 0) goto pop_1_error;
STACK_SHRINK(1);
DISPATCH();
}
TARGET(SET_ADD) {
- PyObject *v = stack_pointer[-1];
- PyObject *set = stack_pointer[-(2 + (oparg-1))];
+ PyObject *v;
+ PyObject *set;
+ v = stack_pointer[-1];
+ set = stack_pointer[-2 - (oparg-1)];
int err = PySet_Add(set, v);
Py_DECREF(v);
if (err) goto pop_1_error;
@@ -770,9 +791,12 @@
TARGET(STORE_SUBSCR) {
PREDICTED(STORE_SUBSCR);
static_assert(INLINE_CACHE_ENTRIES_STORE_SUBSCR == 1, "incorrect cache size");
- PyObject *sub = stack_pointer[-1];
- PyObject *container = stack_pointer[-2];
- PyObject *v = stack_pointer[-3];
+ PyObject *sub;
+ PyObject *container;
+ PyObject *v;
+ sub = stack_pointer[-1];
+ container = stack_pointer[-2];
+ v = stack_pointer[-3];
#if ENABLE_SPECIALIZATION
_PyStoreSubscrCache *cache = (_PyStoreSubscrCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@@ -795,9 +819,12 @@
}
TARGET(STORE_SUBSCR_LIST_INT) {
- PyObject *sub = stack_pointer[-1];
- PyObject *list = stack_pointer[-2];
- PyObject *value = stack_pointer[-3];
+ PyObject *sub;
+ PyObject *list;
+ PyObject *value;
+ sub = stack_pointer[-1];
+ list = stack_pointer[-2];
+ value = stack_pointer[-3];
DEOPT_IF(!PyLong_CheckExact(sub), STORE_SUBSCR);
DEOPT_IF(!PyList_CheckExact(list), STORE_SUBSCR);
@@ -820,9 +847,12 @@
}
TARGET(STORE_SUBSCR_DICT) {
- PyObject *sub = stack_pointer[-1];
- PyObject *dict = stack_pointer[-2];
- PyObject *value = stack_pointer[-3];
+ PyObject *sub;
+ PyObject *dict;
+ PyObject *value;
+ sub = stack_pointer[-1];
+ dict = stack_pointer[-2];
+ value = stack_pointer[-3];
DEOPT_IF(!PyDict_CheckExact(dict), STORE_SUBSCR);
STAT_INC(STORE_SUBSCR, hit);
int err = _PyDict_SetItem_Take2((PyDictObject *)dict, sub, value);
@@ -834,8 +864,10 @@
}
TARGET(DELETE_SUBSCR) {
- PyObject *sub = stack_pointer[-1];
- PyObject *container = stack_pointer[-2];
+ PyObject *sub;
+ PyObject *container;
+ sub = stack_pointer[-1];
+ container = stack_pointer[-2];
/* del container[sub] */
int err = PyObject_DelItem(container, sub);
Py_DECREF(container);
@@ -846,8 +878,9 @@
}
TARGET(CALL_INTRINSIC_1) {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
PyObject *res;
+ value = stack_pointer[-1];
assert(oparg <= MAX_INTRINSIC_1);
res = _PyIntrinsics_UnaryFunctions[oparg].func(tstate, value);
Py_DECREF(value);
@@ -857,9 +890,11 @@
}
TARGET(CALL_INTRINSIC_2) {
- PyObject *value1 = stack_pointer[-1];
- PyObject *value2 = stack_pointer[-2];
+ PyObject *value1;
+ PyObject *value2;
PyObject *res;
+ value1 = stack_pointer[-1];
+ value2 = stack_pointer[-2];
assert(oparg <= MAX_INTRINSIC_2);
res = _PyIntrinsics_BinaryFunctions[oparg].func(tstate, value2, value1);
Py_DECREF(value2);
@@ -871,7 +906,8 @@
}
TARGET(RAISE_VARARGS) {
- PyObject **args = (stack_pointer - oparg);
+ PyObject **args;
+ args = stack_pointer - oparg;
PyObject *cause = NULL, *exc = NULL;
switch (oparg) {
case 2:
@@ -893,10 +929,12 @@
break;
}
if (true) { STACK_SHRINK(oparg); goto error; }
+ STACK_SHRINK(oparg);
}
TARGET(INTERPRETER_EXIT) {
- PyObject *retval = stack_pointer[-1];
+ PyObject *retval;
+ retval = stack_pointer[-1];
assert(frame == &entry_frame);
assert(_PyFrame_IsIncomplete(frame));
/* Restore previous cframe and return. */
@@ -905,10 +943,12 @@
assert(!_PyErr_Occurred(tstate));
tstate->c_recursion_remaining += PY_EVAL_C_STACK_UNITS;
return retval;
+ STACK_SHRINK(1);
}
TARGET(RETURN_VALUE) {
- PyObject *retval = stack_pointer[-1];
+ PyObject *retval;
+ retval = stack_pointer[-1];
STACK_SHRINK(1);
assert(EMPTY());
_PyFrame_SetStackPointer(frame, stack_pointer);
@@ -921,10 +961,12 @@
frame->prev_instr += frame->return_offset;
_PyFrame_StackPush(frame, retval);
goto resume_frame;
+ STACK_SHRINK(1);
}
TARGET(INSTRUMENTED_RETURN_VALUE) {
- PyObject *retval = stack_pointer[-1];
+ PyObject *retval;
+ retval = stack_pointer[-1];
int err = _Py_call_instrumentation_arg(
tstate, PY_MONITORING_EVENT_PY_RETURN,
frame, next_instr-1, retval);
@@ -941,6 +983,7 @@
frame->prev_instr += frame->return_offset;
_PyFrame_StackPush(frame, retval);
goto resume_frame;
+ STACK_SHRINK(1);
}
TARGET(RETURN_CONST) {
@@ -980,8 +1023,9 @@
}
TARGET(GET_AITER) {
- PyObject *obj = stack_pointer[-1];
+ PyObject *obj;
PyObject *iter;
+ obj = stack_pointer[-1];
unaryfunc getter = NULL;
PyTypeObject *type = Py_TYPE(obj);
@@ -1017,8 +1061,9 @@
}
TARGET(GET_ANEXT) {
- PyObject *aiter = stack_pointer[-1];
+ PyObject *aiter;
PyObject *awaitable;
+ aiter = stack_pointer[-1];
unaryfunc getter = NULL;
PyObject *next_iter = NULL;
PyTypeObject *type = Py_TYPE(aiter);
@@ -1067,8 +1112,9 @@
}
TARGET(GET_AWAITABLE) {
- PyObject *iterable = stack_pointer[-1];
+ PyObject *iterable;
PyObject *iter;
+ iterable = stack_pointer[-1];
iter = _PyCoro_GetAwaitableIter(iterable);
if (iter == NULL) {
@@ -1099,9 +1145,11 @@
TARGET(SEND) {
PREDICTED(SEND);
static_assert(INLINE_CACHE_ENTRIES_SEND == 1, "incorrect cache size");
- PyObject *v = stack_pointer[-1];
- PyObject *receiver = stack_pointer[-2];
+ PyObject *v;
+ PyObject *receiver;
PyObject *retval;
+ v = stack_pointer[-1];
+ receiver = stack_pointer[-2];
#if ENABLE_SPECIALIZATION
_PySendCache *cache = (_PySendCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@@ -1154,8 +1202,10 @@
}
TARGET(SEND_GEN) {
- PyObject *v = stack_pointer[-1];
- PyObject *receiver = stack_pointer[-2];
+ PyObject *v;
+ PyObject *receiver;
+ v = stack_pointer[-1];
+ receiver = stack_pointer[-2];
DEOPT_IF(tstate->interp->eval_frame, SEND);
PyGenObject *gen = (PyGenObject *)receiver;
DEOPT_IF(Py_TYPE(gen) != &PyGen_Type &&
@@ -1174,7 +1224,8 @@
}
TARGET(INSTRUMENTED_YIELD_VALUE) {
- PyObject *retval = stack_pointer[-1];
+ PyObject *retval;
+ retval = stack_pointer[-1];
assert(frame != &entry_frame);
assert(oparg >= 0); /* make the generator identify this as HAS_ARG */
PyGenObject *gen = _PyFrame_GetGenerator(frame);
@@ -1195,7 +1246,8 @@
}
TARGET(YIELD_VALUE) {
- PyObject *retval = stack_pointer[-1];
+ PyObject *retval;
+ retval = stack_pointer[-1];
// NOTE: It's important that YIELD_VALUE never raises an exception!
// The compiler treats any exception raised here as a failed close()
// or throw() call.
@@ -1215,7 +1267,8 @@
}
TARGET(POP_EXCEPT) {
- PyObject *exc_value = stack_pointer[-1];
+ PyObject *exc_value;
+ exc_value = stack_pointer[-1];
_PyErr_StackItem *exc_info = tstate->exc_info;
Py_XSETREF(exc_info->exc_value, exc_value);
STACK_SHRINK(1);
@@ -1223,8 +1276,10 @@
}
TARGET(RERAISE) {
- PyObject *exc = stack_pointer[-1];
- PyObject **values = (stack_pointer - (1 + oparg));
+ PyObject *exc;
+ PyObject **values;
+ exc = stack_pointer[-1];
+ values = stack_pointer - 1 - oparg;
assert(oparg >= 0 && oparg <= 2);
if (oparg) {
PyObject *lasti = values[0];
@@ -1243,11 +1298,14 @@
_PyErr_SetRaisedException(tstate, exc);
monitor_reraise(tstate, frame, next_instr-1);
goto exception_unwind;
+ STACK_SHRINK(1);
}
TARGET(END_ASYNC_FOR) {
- PyObject *exc = stack_pointer[-1];
- PyObject *awaitable = stack_pointer[-2];
+ PyObject *exc;
+ PyObject *awaitable;
+ exc = stack_pointer[-1];
+ awaitable = stack_pointer[-2];
assert(exc && PyExceptionInstance_Check(exc));
if (PyErr_GivenExceptionMatches(exc, PyExc_StopAsyncIteration)) {
Py_DECREF(awaitable);
@@ -1264,11 +1322,14 @@
}
TARGET(CLEANUP_THROW) {
- PyObject *exc_value = stack_pointer[-1];
- PyObject *last_sent_val = stack_pointer[-2];
- PyObject *sub_iter = stack_pointer[-3];
+ PyObject *exc_value;
+ PyObject *last_sent_val;
+ PyObject *sub_iter;
PyObject *none;
PyObject *value;
+ exc_value = stack_pointer[-1];
+ last_sent_val = stack_pointer[-2];
+ sub_iter = stack_pointer[-3];
assert(throwflag);
assert(exc_value && PyExceptionInstance_Check(exc_value));
if (PyErr_GivenExceptionMatches(exc_value, PyExc_StopIteration)) {
@@ -1284,8 +1345,8 @@
goto exception_unwind;
}
STACK_SHRINK(1);
- stack_pointer[-1] = value;
stack_pointer[-2] = none;
+ stack_pointer[-1] = value;
DISPATCH();
}
@@ -1311,7 +1372,8 @@
}
TARGET(STORE_NAME) {
- PyObject *v = stack_pointer[-1];
+ PyObject *v;
+ v = stack_pointer[-1];
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
PyObject *ns = LOCALS();
int err;
@@ -1354,7 +1416,8 @@
TARGET(UNPACK_SEQUENCE) {
PREDICTED(UNPACK_SEQUENCE);
static_assert(INLINE_CACHE_ENTRIES_UNPACK_SEQUENCE == 1, "incorrect cache size");
- PyObject *seq = stack_pointer[-1];
+ PyObject *seq;
+ seq = stack_pointer[-1];
#if ENABLE_SPECIALIZATION
_PyUnpackSequenceCache *cache = (_PyUnpackSequenceCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@@ -1376,8 +1439,10 @@
}
TARGET(UNPACK_SEQUENCE_TWO_TUPLE) {
- PyObject *seq = stack_pointer[-1];
- PyObject **values = stack_pointer - (1);
+ PyObject *seq;
+ PyObject **values;
+ seq = stack_pointer[-1];
+ values = stack_pointer - 1;
DEOPT_IF(!PyTuple_CheckExact(seq), UNPACK_SEQUENCE);
DEOPT_IF(PyTuple_GET_SIZE(seq) != 2, UNPACK_SEQUENCE);
assert(oparg == 2);
@@ -1392,8 +1457,10 @@
}
TARGET(UNPACK_SEQUENCE_TUPLE) {
- PyObject *seq = stack_pointer[-1];
- PyObject **values = stack_pointer - (1);
+ PyObject *seq;
+ PyObject **values;
+ seq = stack_pointer[-1];
+ values = stack_pointer - 1;
DEOPT_IF(!PyTuple_CheckExact(seq), UNPACK_SEQUENCE);
DEOPT_IF(PyTuple_GET_SIZE(seq) != oparg, UNPACK_SEQUENCE);
STAT_INC(UNPACK_SEQUENCE, hit);
@@ -1409,8 +1476,10 @@
}
TARGET(UNPACK_SEQUENCE_LIST) {
- PyObject *seq = stack_pointer[-1];
- PyObject **values = stack_pointer - (1);
+ PyObject *seq;
+ PyObject **values;
+ seq = stack_pointer[-1];
+ values = stack_pointer - 1;
DEOPT_IF(!PyList_CheckExact(seq), UNPACK_SEQUENCE);
DEOPT_IF(PyList_GET_SIZE(seq) != oparg, UNPACK_SEQUENCE);
STAT_INC(UNPACK_SEQUENCE, hit);
@@ -1426,7 +1495,8 @@
}
TARGET(UNPACK_EX) {
- PyObject *seq = stack_pointer[-1];
+ PyObject *seq;
+ seq = stack_pointer[-1];
int totalargs = 1 + (oparg & 0xFF) + (oparg >> 8);
PyObject **top = stack_pointer + totalargs - 1;
int res = _PyEval_UnpackIterable(tstate, seq, oparg & 0xFF, oparg >> 8, top);
@@ -1439,8 +1509,10 @@
TARGET(STORE_ATTR) {
PREDICTED(STORE_ATTR);
static_assert(INLINE_CACHE_ENTRIES_STORE_ATTR == 4, "incorrect cache size");
- PyObject *owner = stack_pointer[-1];
- PyObject *v = stack_pointer[-2];
+ PyObject *owner;
+ PyObject *v;
+ owner = stack_pointer[-1];
+ v = stack_pointer[-2];
#if ENABLE_SPECIALIZATION
_PyAttrCache *cache = (_PyAttrCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@@ -1463,7 +1535,8 @@
}
TARGET(DELETE_ATTR) {
- PyObject *owner = stack_pointer[-1];
+ PyObject *owner;
+ owner = stack_pointer[-1];
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
int err = PyObject_DelAttr(owner, name);
Py_DECREF(owner);
@@ -1473,7 +1546,8 @@
}
TARGET(STORE_GLOBAL) {
- PyObject *v = stack_pointer[-1];
+ PyObject *v;
+ v = stack_pointer[-1];
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
int err = PyDict_SetItem(GLOBALS(), name, v);
Py_DECREF(v);
@@ -1498,27 +1572,25 @@
}
TARGET(LOAD_LOCALS) {
- PyObject *_tmp_1;
- {
- PyObject *locals;
- locals = LOCALS();
- if (locals == NULL) {
- _PyErr_SetString(tstate, PyExc_SystemError,
- "no locals found");
- if (true) goto error;
- }
- Py_INCREF(locals);
- _tmp_1 = locals;
+ PyObject *locals;
+ locals = LOCALS();
+ if (locals == NULL) {
+ _PyErr_SetString(tstate, PyExc_SystemError,
+ "no locals found");
+ if (true) goto error;
}
+ Py_INCREF(locals);
STACK_GROW(1);
- stack_pointer[-1] = _tmp_1;
+ stack_pointer[-1] = locals;
DISPATCH();
}
TARGET(LOAD_NAME) {
- PyObject *_tmp_1;
+ PyObject *locals;
+ PyObject *mod_or_class_dict;
+ PyObject *v;
+ // _LOAD_LOCALS
{
- PyObject *locals;
locals = LOCALS();
if (locals == NULL) {
_PyErr_SetString(tstate, PyExc_SystemError,
@@ -1526,11 +1598,10 @@
if (true) goto error;
}
Py_INCREF(locals);
- _tmp_1 = locals;
}
+ // _LOAD_FROM_DICT_OR_GLOBALS
+ mod_or_class_dict = locals;
{
- PyObject *mod_or_class_dict = _tmp_1;
- PyObject *v;
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
if (PyMapping_GetOptionalItem(mod_or_class_dict, name, &v) < 0) {
Py_DECREF(mod_or_class_dict);
@@ -1557,47 +1628,43 @@
}
}
}
- _tmp_1 = v;
}
STACK_GROW(1);
- stack_pointer[-1] = _tmp_1;
+ stack_pointer[-1] = v;
DISPATCH();
}
TARGET(LOAD_FROM_DICT_OR_GLOBALS) {
- PyObject *_tmp_1 = stack_pointer[-1];
- {
- PyObject *mod_or_class_dict = _tmp_1;
- PyObject *v;
- PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
- if (PyMapping_GetOptionalItem(mod_or_class_dict, name, &v) < 0) {
- Py_DECREF(mod_or_class_dict);
+ PyObject *mod_or_class_dict;
+ PyObject *v;
+ mod_or_class_dict = stack_pointer[-1];
+ PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
+ if (PyMapping_GetOptionalItem(mod_or_class_dict, name, &v) < 0) {
+ Py_DECREF(mod_or_class_dict);
+ goto error;
+ }
+ Py_DECREF(mod_or_class_dict);
+ if (v == NULL) {
+ v = PyDict_GetItemWithError(GLOBALS(), name);
+ if (v != NULL) {
+ Py_INCREF(v);
+ }
+ else if (_PyErr_Occurred(tstate)) {
goto error;
}
- Py_DECREF(mod_or_class_dict);
- if (v == NULL) {
- v = PyDict_GetItemWithError(GLOBALS(), name);
- if (v != NULL) {
- Py_INCREF(v);
- }
- else if (_PyErr_Occurred(tstate)) {
+ else {
+ if (PyMapping_GetOptionalItem(BUILTINS(), name, &v) < 0) {
goto error;
}
- else {
- if (PyMapping_GetOptionalItem(BUILTINS(), name, &v) < 0) {
- goto error;
- }
- if (v == NULL) {
- _PyEval_FormatExcCheckArg(
- tstate, PyExc_NameError,
- NAME_ERROR_MSG, name);
- goto error;
- }
+ if (v == NULL) {
+ _PyEval_FormatExcCheckArg(
+ tstate, PyExc_NameError,
+ NAME_ERROR_MSG, name);
+ goto error;
}
}
- _tmp_1 = v;
}
- stack_pointer[-1] = _tmp_1;
+ stack_pointer[-1] = v;
DISPATCH();
}
@@ -1654,15 +1721,16 @@
null = NULL;
STACK_GROW(1);
STACK_GROW(((oparg & 1) ? 1 : 0));
+ if (oparg & 1) { stack_pointer[-1 - (oparg & 1 ? 1 : 0)] = null; }
stack_pointer[-1] = v;
- if (oparg & 1) { stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))] = null; }
next_instr += 4;
DISPATCH();
}
TARGET(LOAD_GLOBAL_MODULE) {
- PyObject *_tmp_1;
- PyObject *_tmp_2;
+ PyObject *null = NULL;
+ PyObject *res;
+ // _GUARD_GLOBALS_VERSION
{
uint16_t version = read_u16(&next_instr[1].cache);
PyDictObject *dict = (PyDictObject *)GLOBALS();
@@ -1670,9 +1738,8 @@
DEOPT_IF(dict->ma_keys->dk_version != version, LOAD_GLOBAL);
assert(DK_IS_UNICODE(dict->ma_keys));
}
+ // _LOAD_GLOBAL_MODULE
{
- PyObject *null = NULL;
- PyObject *res;
uint16_t index = read_u16(&next_instr[3].cache);
PyDictObject *dict = (PyDictObject *)GLOBALS();
PyDictUnicodeEntry *entries = DK_UNICODE_ENTRIES(dict->ma_keys);
@@ -1681,20 +1748,19 @@
Py_INCREF(res);
STAT_INC(LOAD_GLOBAL, hit);
null = NULL;
- if (oparg & 1) { _tmp_2 = null; }
- _tmp_1 = res;
}
- next_instr += 4;
STACK_GROW(1);
STACK_GROW(((oparg & 1) ? 1 : 0));
- stack_pointer[-1] = _tmp_1;
- if (oparg & 1) { stack_pointer[-2] = _tmp_2; }
+ if (oparg & 1) { stack_pointer[-1 - (oparg & 1 ? 1 : 0)] = null; }
+ stack_pointer[-1] = res;
+ next_instr += 4;
DISPATCH();
}
TARGET(LOAD_GLOBAL_BUILTIN) {
- PyObject *_tmp_1;
- PyObject *_tmp_2;
+ PyObject *null = NULL;
+ PyObject *res;
+ // _GUARD_GLOBALS_VERSION
{
uint16_t version = read_u16(&next_instr[1].cache);
PyDictObject *dict = (PyDictObject *)GLOBALS();
@@ -1702,6 +1768,7 @@
DEOPT_IF(dict->ma_keys->dk_version != version, LOAD_GLOBAL);
assert(DK_IS_UNICODE(dict->ma_keys));
}
+ // _GUARD_BUILTINS_VERSION
{
uint16_t version = read_u16(&next_instr[2].cache);
PyDictObject *dict = (PyDictObject *)BUILTINS();
@@ -1709,9 +1776,8 @@
DEOPT_IF(dict->ma_keys->dk_version != version, LOAD_GLOBAL);
assert(DK_IS_UNICODE(dict->ma_keys));
}
+ // _LOAD_GLOBAL_BUILTINS
{
- PyObject *null = NULL;
- PyObject *res;
uint16_t index = read_u16(&next_instr[3].cache);
PyDictObject *bdict = (PyDictObject *)BUILTINS();
PyDictUnicodeEntry *entries = DK_UNICODE_ENTRIES(bdict->ma_keys);
@@ -1720,14 +1786,12 @@
Py_INCREF(res);
STAT_INC(LOAD_GLOBAL, hit);
null = NULL;
- if (oparg & 1) { _tmp_2 = null; }
- _tmp_1 = res;
}
- next_instr += 4;
STACK_GROW(1);
STACK_GROW(((oparg & 1) ? 1 : 0));
- stack_pointer[-1] = _tmp_1;
- if (oparg & 1) { stack_pointer[-2] = _tmp_2; }
+ if (oparg & 1) { stack_pointer[-1 - (oparg & 1 ? 1 : 0)] = null; }
+ stack_pointer[-1] = res;
+ next_instr += 4;
DISPATCH();
}
@@ -1765,8 +1829,9 @@
}
TARGET(LOAD_FROM_DICT_OR_DEREF) {
- PyObject *class_dict = stack_pointer[-1];
+ PyObject *class_dict;
PyObject *value;
+ class_dict = stack_pointer[-1];
PyObject *name;
assert(class_dict);
assert(oparg >= 0 && oparg < _PyFrame_GetCode(frame)->co_nlocalsplus);
@@ -1804,7 +1869,8 @@
}
TARGET(STORE_DEREF) {
- PyObject *v = stack_pointer[-1];
+ PyObject *v;
+ v = stack_pointer[-1];
PyObject *cell = GETLOCAL(oparg);
PyObject *oldobj = PyCell_GET(cell);
PyCell_SET(cell, v);
@@ -1828,8 +1894,9 @@
}
TARGET(BUILD_STRING) {
- PyObject **pieces = (stack_pointer - oparg);
+ PyObject **pieces;
PyObject *str;
+ pieces = stack_pointer - oparg;
str = _PyUnicode_JoinArray(&_Py_STR(empty), pieces, oparg);
for (int _i = oparg; --_i >= 0;) {
Py_DECREF(pieces[_i]);
@@ -1842,8 +1909,9 @@
}
TARGET(BUILD_TUPLE) {
- PyObject **values = (stack_pointer - oparg);
+ PyObject **values;
PyObject *tup;
+ values = stack_pointer - oparg;
tup = _PyTuple_FromArraySteal(values, oparg);
if (tup == NULL) { STACK_SHRINK(oparg); goto error; }
STACK_SHRINK(oparg);
@@ -1853,8 +1921,9 @@
}
TARGET(BUILD_LIST) {
- PyObject **values = (stack_pointer - oparg);
+ PyObject **values;
PyObject *list;
+ values = stack_pointer - oparg;
list = _PyList_FromArraySteal(values, oparg);
if (list == NULL) { STACK_SHRINK(oparg); goto error; }
STACK_SHRINK(oparg);
@@ -1864,8 +1933,10 @@
}
TARGET(LIST_EXTEND) {
- PyObject *iterable = stack_pointer[-1];
- PyObject *list = stack_pointer[-(2 + (oparg-1))];
+ PyObject *iterable;
+ PyObject *list;
+ iterable = stack_pointer[-1];
+ list = stack_pointer[-2 - (oparg-1)];
PyObject *none_val = _PyList_Extend((PyListObject *)list, iterable);
if (none_val == NULL) {
if (_PyErr_ExceptionMatches(tstate, PyExc_TypeError) &&
@@ -1886,8 +1957,10 @@
}
TARGET(SET_UPDATE) {
- PyObject *iterable = stack_pointer[-1];
- PyObject *set = stack_pointer[-(2 + (oparg-1))];
+ PyObject *iterable;
+ PyObject *set;
+ iterable = stack_pointer[-1];
+ set = stack_pointer[-2 - (oparg-1)];
int err = _PySet_Update(set, iterable);
Py_DECREF(iterable);
if (err < 0) goto pop_1_error;
@@ -1896,8 +1969,9 @@
}
TARGET(BUILD_SET) {
- PyObject **values = (stack_pointer - oparg);
+ PyObject **values;
PyObject *set;
+ values = stack_pointer - oparg;
set = PySet_New(NULL);
if (set == NULL)
goto error;
@@ -1919,8 +1993,9 @@
}
TARGET(BUILD_MAP) {
- PyObject **values = (stack_pointer - oparg*2);
+ PyObject **values;
PyObject *map;
+ values = stack_pointer - oparg*2;
map = _PyDict_FromItems(
values, 2,
values+1, 2,
@@ -1980,9 +2055,11 @@
}
TARGET(BUILD_CONST_KEY_MAP) {
- PyObject *keys = stack_pointer[-1];
- PyObject **values = (stack_pointer - (1 + oparg));
+ PyObject *keys;
+ PyObject **values;
PyObject *map;
+ keys = stack_pointer[-1];
+ values = stack_pointer - 1 - oparg;
if (!PyTuple_CheckExact(keys) ||
PyTuple_GET_SIZE(keys) != (Py_ssize_t)oparg) {
_PyErr_SetString(tstate, PyExc_SystemError,
@@ -2003,7 +2080,8 @@
}
TARGET(DICT_UPDATE) {
- PyObject *update = stack_pointer[-1];
+ PyObject *update;
+ update = stack_pointer[-1];
PyObject *dict = PEEK(oparg + 1); // update is still on the stack
if (PyDict_Update(dict, update) < 0) {
if (_PyErr_ExceptionMatches(tstate, PyExc_AttributeError)) {
@@ -2020,7 +2098,8 @@
}
TARGET(DICT_MERGE) {
- PyObject *update = stack_pointer[-1];
+ PyObject *update;
+ update = stack_pointer[-1];
PyObject *dict = PEEK(oparg + 1); // update is still on the stack
if (_PyDict_MergeEx(dict, update, 2) < 0) {
@@ -2034,8 +2113,10 @@
}
TARGET(MAP_ADD) {
- PyObject *value = stack_pointer[-1];
- PyObject *key = stack_pointer[-2];
+ PyObject *value;
+ PyObject *key;
+ value = stack_pointer[-1];
+ key = stack_pointer[-2];
PyObject *dict = PEEK(oparg + 2); // key, value are still on the stack
assert(PyDict_CheckExact(dict));
/* dict[key] = value */
@@ -2051,16 +2132,21 @@
// don't want to specialize instrumented instructions
INCREMENT_ADAPTIVE_COUNTER(cache->counter);
GO_TO_INSTRUCTION(LOAD_SUPER_ATTR);
+ STACK_SHRINK(2);
+ STACK_GROW(((oparg & 1) ? 1 : 0));
}
TARGET(LOAD_SUPER_ATTR) {
PREDICTED(LOAD_SUPER_ATTR);
static_assert(INLINE_CACHE_ENTRIES_LOAD_SUPER_ATTR == 1, "incorrect cache size");
- PyObject *self = stack_pointer[-1];
- PyObject *class = stack_pointer[-2];
- PyObject *global_super = stack_pointer[-3];
+ PyObject *self;
+ PyObject *class;
+ PyObject *global_super;
PyObject *res2 = NULL;
PyObject *res;
+ self = stack_pointer[-1];
+ class = stack_pointer[-2];
+ global_super = stack_pointer[-3];
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg >> 2);
int load_method = oparg & 1;
#if ENABLE_SPECIALIZATION
@@ -2111,18 +2197,21 @@
if (res == NULL) goto pop_3_error;
STACK_SHRINK(2);
STACK_GROW(((oparg & 1) ? 1 : 0));
+ if (oparg & 1) { stack_pointer[-1 - (oparg & 1 ? 1 : 0)] = res2; }
stack_pointer[-1] = res;
- if (oparg & 1) { stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))] = res2; }
next_instr += 1;
DISPATCH();
}
TARGET(LOAD_SUPER_ATTR_ATTR) {
- PyObject *self = stack_pointer[-1];
- PyObject *class = stack_pointer[-2];
- PyObject *global_super = stack_pointer[-3];
+ PyObject *self;
+ PyObject *class;
+ PyObject *global_super;
PyObject *res2 = NULL;
PyObject *res;
+ self = stack_pointer[-1];
+ class = stack_pointer[-2];
+ global_super = stack_pointer[-3];
assert(!(oparg & 1));
DEOPT_IF(global_super != (PyObject *)&PySuper_Type, LOAD_SUPER_ATTR);
DEOPT_IF(!PyType_Check(class), LOAD_SUPER_ATTR);
@@ -2135,18 +2224,21 @@
if (res == NULL) goto pop_3_error;
STACK_SHRINK(2);
STACK_GROW(((oparg & 1) ? 1 : 0));
+ if (oparg & 1) { stack_pointer[-1 - (oparg & 1 ? 1 : 0)] = res2; }
stack_pointer[-1] = res;
- if (oparg & 1) { stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))] = res2; }
next_instr += 1;
DISPATCH();
}
TARGET(LOAD_SUPER_ATTR_METHOD) {
- PyObject *self = stack_pointer[-1];
- PyObject *class = stack_pointer[-2];
- PyObject *global_super = stack_pointer[-3];
+ PyObject *self;
+ PyObject *class;
+ PyObject *global_super;
PyObject *res2;
PyObject *res;
+ self = stack_pointer[-1];
+ class = stack_pointer[-2];
+ global_super = stack_pointer[-3];
assert(oparg & 1);
DEOPT_IF(global_super != (PyObject *)&PySuper_Type, LOAD_SUPER_ATTR);
DEOPT_IF(!PyType_Check(class), LOAD_SUPER_ATTR);
@@ -2170,8 +2262,8 @@
res2 = NULL;
}
STACK_SHRINK(1);
- stack_pointer[-1] = res;
stack_pointer[-2] = res2;
+ stack_pointer[-1] = res;
next_instr += 1;
DISPATCH();
}
@@ -2179,9 +2271,10 @@
TARGET(LOAD_ATTR) {
PREDICTED(LOAD_ATTR);
static_assert(INLINE_CACHE_ENTRIES_LOAD_ATTR == 9, "incorrect cache size");
- PyObject *owner = stack_pointer[-1];
+ PyObject *owner;
PyObject *res2 = NULL;
PyObject *res;
+ owner = stack_pointer[-1];
#if ENABLE_SPECIALIZATION
_PyAttrCache *cache = (_PyAttrCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@@ -2228,35 +2321,33 @@
if (res == NULL) goto pop_1_error;
}
STACK_GROW(((oparg & 1) ? 1 : 0));
+ if (oparg & 1) { stack_pointer[-1 - (oparg & 1 ? 1 : 0)] = res2; }
stack_pointer[-1] = res;
- if (oparg & 1) { stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))] = res2; }
next_instr += 9;
DISPATCH();
}
TARGET(LOAD_ATTR_INSTANCE_VALUE) {
- PyObject *_tmp_1;
- PyObject *_tmp_2 = stack_pointer[-1];
+ PyObject *owner;
+ PyObject *res2 = NULL;
+ PyObject *res;
+ // _GUARD_TYPE_VERSION
+ owner = stack_pointer[-1];
{
- PyObject *owner = _tmp_2;
uint32_t type_version = read_u32(&next_instr[1].cache);
PyTypeObject *tp = Py_TYPE(owner);
assert(type_version != 0);
DEOPT_IF(tp->tp_version_tag != type_version, LOAD_ATTR);
- _tmp_2 = owner;
}
+ // _CHECK_MANAGED_OBJECT_HAS_VALUES
{
- PyObject *owner = _tmp_2;
assert(Py_TYPE(owner)->tp_dictoffset < 0);
assert(Py_TYPE(owner)->tp_flags & Py_TPFLAGS_MANAGED_DICT);
PyDictOrValues dorv = *_PyObject_DictOrValuesPointer(owner);
DEOPT_IF(!_PyDictOrValues_IsValues(dorv), LOAD_ATTR);
- _tmp_2 = owner;
}
+ // _LOAD_ATTR_INSTANCE_VALUE
{
- PyObject *owner = _tmp_2;
- PyObject *res2 = NULL;
- PyObject *res;
uint16_t index = read_u16(&next_instr[3].cache);
PyDictOrValues dorv = *_PyObject_DictOrValuesPointer(owner);
res = _PyDictOrValues_GetValues(dorv)->values[index];
@@ -2265,20 +2356,19 @@
Py_INCREF(res);
res2 = NULL;
Py_DECREF(owner);
- if (oparg & 1) { _tmp_2 = res2; }
- _tmp_1 = res;
}
- next_instr += 9;
STACK_GROW(((oparg & 1) ? 1 : 0));
- stack_pointer[-1] = _tmp_1;
- if (oparg & 1) { stack_pointer[-2] = _tmp_2; }
+ if (oparg & 1) { stack_pointer[-1 - (oparg & 1 ? 1 : 0)] = res2; }
+ stack_pointer[-1] = res;
+ next_instr += 9;
DISPATCH();
}
TARGET(LOAD_ATTR_MODULE) {
- PyObject *owner = stack_pointer[-1];
+ PyObject *owner;
PyObject *res2 = NULL;
PyObject *res;
+ owner = stack_pointer[-1];
uint32_t type_version = read_u32(&next_instr[1].cache);
uint16_t index = read_u16(&next_instr[3].cache);
DEOPT_IF(!PyModule_CheckExact(owner), LOAD_ATTR);
@@ -2295,16 +2385,17 @@
res2 = NULL;
Py_DECREF(owner);
STACK_GROW(((oparg & 1) ? 1 : 0));
+ if (oparg & 1) { stack_pointer[-1 - (oparg & 1 ? 1 : 0)] = res2; }
stack_pointer[-1] = res;
- if (oparg & 1) { stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))] = res2; }
next_instr += 9;
DISPATCH();
}
TARGET(LOAD_ATTR_WITH_HINT) {
- PyObject *owner = stack_pointer[-1];
+ PyObject *owner;
PyObject *res2 = NULL;
PyObject *res;
+ owner = stack_pointer[-1];
uint32_t type_version = read_u32(&next_instr[1].cache);
uint16_t index = read_u16(&next_instr[3].cache);
PyTypeObject *tp = Py_TYPE(owner);
@@ -2335,16 +2426,17 @@
res2 = NULL;
Py_DECREF(owner);
STACK_GROW(((oparg & 1) ? 1 : 0));
+ if (oparg & 1) { stack_pointer[-1 - (oparg & 1 ? 1 : 0)] = res2; }
stack_pointer[-1] = res;
- if (oparg & 1) { stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))] = res2; }
next_instr += 9;
DISPATCH();
}
TARGET(LOAD_ATTR_SLOT) {
- PyObject *owner = stack_pointer[-1];
+ PyObject *owner;
PyObject *res2 = NULL;
PyObject *res;
+ owner = stack_pointer[-1];
uint32_t type_version = read_u32(&next_instr[1].cache);
uint16_t index = read_u16(&next_instr[3].cache);
PyTypeObject *tp = Py_TYPE(owner);
@@ -2358,16 +2450,17 @@
res2 = NULL;
Py_DECREF(owner);
STACK_GROW(((oparg & 1) ? 1 : 0));
+ if (oparg & 1) { stack_pointer[-1 - (oparg & 1 ? 1 : 0)] = res2; }
stack_pointer[-1] = res;
- if (oparg & 1) { stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))] = res2; }
next_instr += 9;
DISPATCH();
}
TARGET(LOAD_ATTR_CLASS) {
- PyObject *cls = stack_pointer[-1];
+ PyObject *cls;
PyObject *res2 = NULL;
PyObject *res;
+ cls = stack_pointer[-1];
uint32_t type_version = read_u32(&next_instr[1].cache);
PyObject *descr = read_obj(&next_instr[5].cache);
@@ -2383,14 +2476,15 @@
Py_INCREF(res);
Py_DECREF(cls);
STACK_GROW(((oparg & 1) ? 1 : 0));
+ if (oparg & 1) { stack_pointer[-1 - (oparg & 1 ? 1 : 0)] = res2; }
stack_pointer[-1] = res;
- if (oparg & 1) { stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))] = res2; }
next_instr += 9;
DISPATCH();
}
TARGET(LOAD_ATTR_PROPERTY) {
- PyObject *owner = stack_pointer[-1];
+ PyObject *owner;
+ owner = stack_pointer[-1];
uint32_t type_version = read_u32(&next_instr[1].cache);
uint32_t func_version = read_u32(&next_instr[3].cache);
PyObject *fget = read_obj(&next_instr[5].cache);
@@ -2417,10 +2511,12 @@
SKIP_OVER(INLINE_CACHE_ENTRIES_LOAD_ATTR);
frame->return_offset = 0;
DISPATCH_INLINED(new_frame);
+ STACK_GROW(((oparg & 1) ? 1 : 0));
}
TARGET(LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN) {
- PyObject *owner = stack_pointer[-1];
+ PyObject *owner;
+ owner = stack_pointer[-1];
uint32_t type_version = read_u32(&next_instr[1].cache);
uint32_t func_version = read_u32(&next_instr[3].cache);
PyObject *getattribute = read_obj(&next_instr[5].cache);
@@ -2449,11 +2545,14 @@
SKIP_OVER(INLINE_CACHE_ENTRIES_LOAD_ATTR);
frame->return_offset = 0;
DISPATCH_INLINED(new_frame);
+ STACK_GROW(((oparg & 1) ? 1 : 0));
}
TARGET(STORE_ATTR_INSTANCE_VALUE) {
- PyObject *owner = stack_pointer[-1];
- PyObject *value = stack_pointer[-2];
+ PyObject *owner;
+ PyObject *value;
+ owner = stack_pointer[-1];
+ value = stack_pointer[-2];
uint32_t type_version = read_u32(&next_instr[1].cache);
uint16_t index = read_u16(&next_instr[3].cache);
PyTypeObject *tp = Py_TYPE(owner);
@@ -2479,8 +2578,10 @@
}
TARGET(STORE_ATTR_WITH_HINT) {
- PyObject *owner = stack_pointer[-1];
- PyObject *value = stack_pointer[-2];
+ PyObject *owner;
+ PyObject *value;
+ owner = stack_pointer[-1];
+ value = stack_pointer[-2];
uint32_t type_version = read_u32(&next_instr[1].cache);
uint16_t hint = read_u16(&next_instr[3].cache);
PyTypeObject *tp = Py_TYPE(owner);
@@ -2527,8 +2628,10 @@
}
TARGET(STORE_ATTR_SLOT) {
- PyObject *owner = stack_pointer[-1];
- PyObject *value = stack_pointer[-2];
+ PyObject *owner;
+ PyObject *value;
+ owner = stack_pointer[-1];
+ value = stack_pointer[-2];
uint32_t type_version = read_u32(&next_instr[1].cache);
uint16_t index = read_u16(&next_instr[3].cache);
PyTypeObject *tp = Py_TYPE(owner);
@@ -2548,9 +2651,11 @@
TARGET(COMPARE_OP) {
PREDICTED(COMPARE_OP);
static_assert(INLINE_CACHE_ENTRIES_COMPARE_OP == 1, "incorrect cache size");
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
PyObject *res;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
#if ENABLE_SPECIALIZATION
_PyCompareOpCache *cache = (_PyCompareOpCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@@ -2579,9 +2684,11 @@
}
TARGET(COMPARE_OP_FLOAT) {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
PyObject *res;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
DEOPT_IF(!PyFloat_CheckExact(left), COMPARE_OP);
DEOPT_IF(!PyFloat_CheckExact(right), COMPARE_OP);
STAT_INC(COMPARE_OP, hit);
@@ -2600,9 +2707,11 @@
}
TARGET(COMPARE_OP_INT) {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
PyObject *res;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
DEOPT_IF(!PyLong_CheckExact(left), COMPARE_OP);
DEOPT_IF(!PyLong_CheckExact(right), COMPARE_OP);
DEOPT_IF(!_PyLong_IsCompact((PyLongObject *)left), COMPARE_OP);
@@ -2625,9 +2734,11 @@
}
TARGET(COMPARE_OP_STR) {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
PyObject *res;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
DEOPT_IF(!PyUnicode_CheckExact(left), COMPARE_OP);
DEOPT_IF(!PyUnicode_CheckExact(right), COMPARE_OP);
STAT_INC(COMPARE_OP, hit);
@@ -2647,9 +2758,11 @@
}
TARGET(IS_OP) {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
PyObject *b;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
int res = Py_Is(left, right) ^ oparg;
Py_DECREF(left);
Py_DECREF(right);
@@ -2660,9 +2773,11 @@
}
TARGET(CONTAINS_OP) {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
PyObject *b;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
int res = PySequence_Contains(right, left);
Py_DECREF(left);
Py_DECREF(right);
@@ -2674,10 +2789,12 @@
}
TARGET(CHECK_EG_MATCH) {
- PyObject *match_type = stack_pointer[-1];
- PyObject *exc_value = stack_pointer[-2];
+ PyObject *match_type;
+ PyObject *exc_value;
PyObject *rest;
PyObject *match;
+ match_type = stack_pointer[-1];
+ exc_value = stack_pointer[-2];
if (_PyEval_CheckExceptStarTypeValid(tstate, match_type) < 0) {
Py_DECREF(exc_value);
Py_DECREF(match_type);
@@ -2698,15 +2815,17 @@
if (!Py_IsNone(match)) {
PyErr_SetHandledException(match);
}
- stack_pointer[-1] = match;
stack_pointer[-2] = rest;
+ stack_pointer[-1] = match;
DISPATCH();
}
TARGET(CHECK_EXC_MATCH) {
- PyObject *right = stack_pointer[-1];
- PyObject *left = stack_pointer[-2];
+ PyObject *right;
+ PyObject *left;
PyObject *b;
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
assert(PyExceptionInstance_Check(left));
if (_PyEval_CheckExceptTypeValid(tstate, right) < 0) {
Py_DECREF(right);
@@ -2721,9 +2840,11 @@
}
TARGET(IMPORT_NAME) {
- PyObject *fromlist = stack_pointer[-1];
- PyObject *level = stack_pointer[-2];
+ PyObject *fromlist;
+ PyObject *level;
PyObject *res;
+ fromlist = stack_pointer[-1];
+ level = stack_pointer[-2];
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
res = import_name(tstate, frame, name, fromlist, level);
Py_DECREF(level);
@@ -2735,8 +2856,9 @@
}
TARGET(IMPORT_FROM) {
- PyObject *from = stack_pointer[-1];
+ PyObject *from;
PyObject *res;
+ from = stack_pointer[-1];
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg);
res = import_from(tstate, from, name);
if (res == NULL) goto error;
@@ -2797,7 +2919,8 @@
}
TARGET(POP_JUMP_IF_FALSE) {
- PyObject *cond = stack_pointer[-1];
+ PyObject *cond;
+ cond = stack_pointer[-1];
assert(PyBool_Check(cond));
JUMPBY(oparg * Py_IsFalse(cond));
STACK_SHRINK(1);
@@ -2805,7 +2928,8 @@
}
TARGET(POP_JUMP_IF_TRUE) {
- PyObject *cond = stack_pointer[-1];
+ PyObject *cond;
+ cond = stack_pointer[-1];
assert(PyBool_Check(cond));
JUMPBY(oparg * Py_IsTrue(cond));
STACK_SHRINK(1);
@@ -2813,10 +2937,12 @@
}
TARGET(POP_JUMP_IF_NONE) {
- PyObject *_tmp_1 = stack_pointer[-1];
+ PyObject *value;
+ PyObject *b;
+ PyObject *cond;
+ // IS_NONE
+ value = stack_pointer[-1];
{
- PyObject *value = _tmp_1;
- PyObject *b;
if (Py_IsNone(value)) {
b = Py_True;
}
@@ -2824,10 +2950,10 @@
b = Py_False;
Py_DECREF(value);
}
- _tmp_1 = b;
}
+ // POP_JUMP_IF_TRUE
+ cond = b;
{
- PyObject *cond = _tmp_1;
assert(PyBool_Check(cond));
JUMPBY(oparg * Py_IsTrue(cond));
}
@@ -2836,10 +2962,12 @@
}
TARGET(POP_JUMP_IF_NOT_NONE) {
- PyObject *_tmp_1 = stack_pointer[-1];
+ PyObject *value;
+ PyObject *b;
+ PyObject *cond;
+ // IS_NONE
+ value = stack_pointer[-1];
{
- PyObject *value = _tmp_1;
- PyObject *b;
if (Py_IsNone(value)) {
b = Py_True;
}
@@ -2847,10 +2975,10 @@
b = Py_False;
Py_DECREF(value);
}
- _tmp_1 = b;
}
+ // POP_JUMP_IF_FALSE
+ cond = b;
{
- PyObject *cond = _tmp_1;
assert(PyBool_Check(cond));
JUMPBY(oparg * Py_IsFalse(cond));
}
@@ -2869,8 +2997,9 @@
}
TARGET(GET_LEN) {
- PyObject *obj = stack_pointer[-1];
+ PyObject *obj;
PyObject *len_o;
+ obj = stack_pointer[-1];
// PUSH(len(TOS))
Py_ssize_t len_i = PyObject_Length(obj);
if (len_i < 0) goto error;
@@ -2882,10 +3011,13 @@
}
TARGET(MATCH_CLASS) {
- PyObject *names = stack_pointer[-1];
- PyObject *type = stack_pointer[-2];
- PyObject *subject = stack_pointer[-3];
+ PyObject *names;
+ PyObject *type;
+ PyObject *subject;
PyObject *attrs;
+ names = stack_pointer[-1];
+ type = stack_pointer[-2];
+ subject = stack_pointer[-3];
// Pop TOS and TOS1. Set TOS to a tuple of attributes on success, or
// None on failure.
assert(PyTuple_CheckExact(names));
@@ -2906,8 +3038,9 @@
}
TARGET(MATCH_MAPPING) {
- PyObject *subject = stack_pointer[-1];
+ PyObject *subject;
PyObject *res;
+ subject = stack_pointer[-1];
int match = Py_TYPE(subject)->tp_flags & Py_TPFLAGS_MAPPING;
res = match ? Py_True : Py_False;
STACK_GROW(1);
@@ -2916,8 +3049,9 @@
}
TARGET(MATCH_SEQUENCE) {
- PyObject *subject = stack_pointer[-1];
+ PyObject *subject;
PyObject *res;
+ subject = stack_pointer[-1];
int match = Py_TYPE(subject)->tp_flags & Py_TPFLAGS_SEQUENCE;
res = match ? Py_True : Py_False;
STACK_GROW(1);
@@ -2926,9 +3060,11 @@
}
TARGET(MATCH_KEYS) {
- PyObject *keys = stack_pointer[-1];
- PyObject *subject = stack_pointer[-2];
+ PyObject *keys;
+ PyObject *subject;
PyObject *values_or_none;
+ keys = stack_pointer[-1];
+ subject = stack_pointer[-2];
// On successful match, PUSH(values). Otherwise, PUSH(None).
values_or_none = _PyEval_MatchKeys(tstate, subject, keys);
if (values_or_none == NULL) goto error;
@@ -2938,8 +3074,9 @@
}
TARGET(GET_ITER) {
- PyObject *iterable = stack_pointer[-1];
+ PyObject *iterable;
PyObject *iter;
+ iterable = stack_pointer[-1];
/* before: [obj]; after [getiter(obj)] */
iter = PyObject_GetIter(iterable);
Py_DECREF(iterable);
@@ -2949,8 +3086,9 @@
}
TARGET(GET_YIELD_FROM_ITER) {
- PyObject *iterable = stack_pointer[-1];
+ PyObject *iterable;
PyObject *iter;
+ iterable = stack_pointer[-1];
/* before: [obj]; after [getiter(obj)] */
if (PyCoro_CheckExact(iterable)) {
/* `iterable` is a coroutine */
@@ -2982,8 +3120,9 @@
TARGET(FOR_ITER) {
PREDICTED(FOR_ITER);
static_assert(INLINE_CACHE_ENTRIES_FOR_ITER == 1, "incorrect cache size");
- PyObject *iter = stack_pointer[-1];
+ PyObject *iter;
PyObject *next;
+ iter = stack_pointer[-1];
#if ENABLE_SPECIALIZATION
_PyForIterCache *cache = (_PyForIterCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@@ -3051,15 +3190,15 @@
}
TARGET(FOR_ITER_LIST) {
- PyObject *_tmp_1;
- PyObject *_tmp_2 = stack_pointer[-1];
+ PyObject *iter;
+ PyObject *next;
+ // _ITER_CHECK_LIST
+ iter = stack_pointer[-1];
{
- PyObject *iter = _tmp_2;
DEOPT_IF(Py_TYPE(iter) != &PyListIter_Type, FOR_ITER);
- _tmp_2 = iter;
}
+ // _ITER_JUMP_LIST
{
- PyObject *iter = _tmp_2;
_PyListIterObject *it = (_PyListIterObject *)iter;
assert(Py_TYPE(iter) == &PyListIter_Type);
STAT_INC(FOR_ITER, hit);
@@ -3076,37 +3215,32 @@
JUMPBY(oparg + 1);
DISPATCH();
}
- _tmp_2 = iter;
}
+ // _ITER_NEXT_LIST
{
- PyObject *iter = _tmp_2;
- PyObject *next;
_PyListIterObject *it = (_PyListIterObject *)iter;
assert(Py_TYPE(iter) == &PyListIter_Type);
PyListObject *seq = it->it_seq;
assert(seq);
assert(it->it_index < PyList_GET_SIZE(seq));
next = Py_NewRef(PyList_GET_ITEM(seq, it->it_index++));
- _tmp_2 = iter;
- _tmp_1 = next;
}
- next_instr += 1;
STACK_GROW(1);
- stack_pointer[-1] = _tmp_1;
- stack_pointer[-2] = _tmp_2;
+ stack_pointer[-1] = next;
+ next_instr += 1;
DISPATCH();
}
TARGET(FOR_ITER_TUPLE) {
- PyObject *_tmp_1;
- PyObject *_tmp_2 = stack_pointer[-1];
+ PyObject *iter;
+ PyObject *next;
+ // _ITER_CHECK_TUPLE
+ iter = stack_pointer[-1];
{
- PyObject *iter = _tmp_2;
DEOPT_IF(Py_TYPE(iter) != &PyTupleIter_Type, FOR_ITER);
- _tmp_2 = iter;
}
+ // _ITER_JUMP_TUPLE
{
- PyObject *iter = _tmp_2;
_PyTupleIterObject *it = (_PyTupleIterObject *)iter;
assert(Py_TYPE(iter) == &PyTupleIter_Type);
STAT_INC(FOR_ITER, hit);
@@ -3123,38 +3257,33 @@
JUMPBY(oparg + 1);
DISPATCH();
}
- _tmp_2 = iter;
}
+ // _ITER_NEXT_TUPLE
{
- PyObject *iter = _tmp_2;
- PyObject *next;
_PyTupleIterObject *it = (_PyTupleIterObject *)iter;
assert(Py_TYPE(iter) == &PyTupleIter_Type);
PyTupleObject *seq = it->it_seq;
assert(seq);
assert(it->it_index < PyTuple_GET_SIZE(seq));
next = Py_NewRef(PyTuple_GET_ITEM(seq, it->it_index++));
- _tmp_2 = iter;
- _tmp_1 = next;
}
- next_instr += 1;
STACK_GROW(1);
- stack_pointer[-1] = _tmp_1;
- stack_pointer[-2] = _tmp_2;
+ stack_pointer[-1] = next;
+ next_instr += 1;
DISPATCH();
}
TARGET(FOR_ITER_RANGE) {
- PyObject *_tmp_1;
- PyObject *_tmp_2 = stack_pointer[-1];
+ PyObject *iter;
+ PyObject *next;
+ // _ITER_CHECK_RANGE
+ iter = stack_pointer[-1];
{
- PyObject *iter = _tmp_2;
_PyRangeIterObject *r = (_PyRangeIterObject *)iter;
DEOPT_IF(Py_TYPE(r) != &PyRangeIter_Type, FOR_ITER);
- _tmp_2 = iter;
}
+ // _ITER_JUMP_RANGE
{
- PyObject *iter = _tmp_2;
_PyRangeIterObject *r = (_PyRangeIterObject *)iter;
assert(Py_TYPE(r) == &PyRangeIter_Type);
STAT_INC(FOR_ITER, hit);
@@ -3166,11 +3295,9 @@
JUMPBY(oparg + 1);
DISPATCH();
}
- _tmp_2 = iter;
}
+ // _ITER_NEXT_RANGE
{
- PyObject *iter = _tmp_2;
- PyObject *next;
_PyRangeIterObject *r = (_PyRangeIterObject *)iter;
assert(Py_TYPE(r) == &PyRangeIter_Type);
assert(r->len > 0);
@@ -3179,18 +3306,16 @@
r->len--;
next = PyLong_FromLong(value);
if (next == NULL) goto error;
- _tmp_2 = iter;
- _tmp_1 = next;
}
- next_instr += 1;
STACK_GROW(1);
- stack_pointer[-1] = _tmp_1;
- stack_pointer[-2] = _tmp_2;
+ stack_pointer[-1] = next;
+ next_instr += 1;
DISPATCH();
}
TARGET(FOR_ITER_GEN) {
- PyObject *iter = stack_pointer[-1];
+ PyObject *iter;
+ iter = stack_pointer[-1];
DEOPT_IF(tstate->interp->eval_frame, FOR_ITER);
PyGenObject *gen = (PyGenObject *)iter;
DEOPT_IF(Py_TYPE(gen) != &PyGen_Type, FOR_ITER);
@@ -3206,12 +3331,14 @@
assert(next_instr[oparg].op.code == END_FOR ||
next_instr[oparg].op.code == INSTRUMENTED_END_FOR);
DISPATCH_INLINED(gen_frame);
+ STACK_GROW(1);
}
TARGET(BEFORE_ASYNC_WITH) {
- PyObject *mgr = stack_pointer[-1];
+ PyObject *mgr;
PyObject *exit;
PyObject *res;
+ mgr = stack_pointer[-1];
PyObject *enter = _PyObject_LookupSpecial(mgr, &_Py_ID(__aenter__));
if (enter == NULL) {
if (!_PyErr_Occurred(tstate)) {
@@ -3242,15 +3369,16 @@
if (true) goto pop_1_error;
}
STACK_GROW(1);
- stack_pointer[-1] = res;
stack_pointer[-2] = exit;
+ stack_pointer[-1] = res;
DISPATCH();
}
TARGET(BEFORE_WITH) {
- PyObject *mgr = stack_pointer[-1];
+ PyObject *mgr;
PyObject *exit;
PyObject *res;
+ mgr = stack_pointer[-1];
/* pop the context manager, push its __exit__ and the
* value returned from calling its __enter__
*/
@@ -3284,16 +3412,19 @@
if (true) goto pop_1_error;
}
STACK_GROW(1);
- stack_pointer[-1] = res;
stack_pointer[-2] = exit;
+ stack_pointer[-1] = res;
DISPATCH();
}
TARGET(WITH_EXCEPT_START) {
- PyObject *val = stack_pointer[-1];
- PyObject *lasti = stack_pointer[-3];
- PyObject *exit_func = stack_pointer[-4];
+ PyObject *val;
+ PyObject *lasti;
+ PyObject *exit_func;
PyObject *res;
+ val = stack_pointer[-1];
+ lasti = stack_pointer[-3];
+ exit_func = stack_pointer[-4];
/* At the top of the stack are 4 values:
- val: TOP = exc_info()
- unused: SECOND = previous exception
@@ -3325,8 +3456,9 @@
}
TARGET(PUSH_EXC_INFO) {
- PyObject *new_exc = stack_pointer[-1];
+ PyObject *new_exc;
PyObject *prev_exc;
+ new_exc = stack_pointer[-1];
_PyErr_StackItem *exc_info = tstate->exc_info;
if (exc_info->exc_value != NULL) {
prev_exc = exc_info->exc_value;
@@ -3337,15 +3469,16 @@
assert(PyExceptionInstance_Check(new_exc));
exc_info->exc_value = Py_NewRef(new_exc);
STACK_GROW(1);
- stack_pointer[-1] = new_exc;
stack_pointer[-2] = prev_exc;
+ stack_pointer[-1] = new_exc;
DISPATCH();
}
TARGET(LOAD_ATTR_METHOD_WITH_VALUES) {
- PyObject *self = stack_pointer[-1];
- PyObject *res2 = NULL;
+ PyObject *self;
+ PyObject *res2;
PyObject *res;
+ self = stack_pointer[-1];
uint32_t type_version = read_u32(&next_instr[1].cache);
uint32_t keys_version = read_u32(&next_instr[3].cache);
PyObject *descr = read_obj(&next_instr[5].cache);
@@ -3366,16 +3499,17 @@
assert(_PyType_HasFeature(Py_TYPE(res2), Py_TPFLAGS_METHOD_DESCRIPTOR));
res = self;
STACK_GROW(1);
- stack_pointer[-1] = res;
stack_pointer[-2] = res2;
+ stack_pointer[-1] = res;
next_instr += 9;
DISPATCH();
}
TARGET(LOAD_ATTR_METHOD_NO_DICT) {
- PyObject *self = stack_pointer[-1];
- PyObject *res2 = NULL;
+ PyObject *self;
+ PyObject *res2;
PyObject *res;
+ self = stack_pointer[-1];
uint32_t type_version = read_u32(&next_instr[1].cache);
PyObject *descr = read_obj(&next_instr[5].cache);
assert(oparg & 1);
@@ -3388,15 +3522,16 @@
res2 = Py_NewRef(descr);
res = self;
STACK_GROW(1);
- stack_pointer[-1] = res;
stack_pointer[-2] = res2;
+ stack_pointer[-1] = res;
next_instr += 9;
DISPATCH();
}
TARGET(LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES) {
- PyObject *self = stack_pointer[-1];
+ PyObject *self;
PyObject *res;
+ self = stack_pointer[-1];
uint32_t type_version = read_u32(&next_instr[1].cache);
uint32_t keys_version = read_u32(&next_instr[3].cache);
PyObject *descr = read_obj(&next_instr[5].cache);
@@ -3420,8 +3555,9 @@
}
TARGET(LOAD_ATTR_NONDESCRIPTOR_NO_DICT) {
- PyObject *self = stack_pointer[-1];
+ PyObject *self;
PyObject *res;
+ self = stack_pointer[-1];
uint32_t type_version = read_u32(&next_instr[1].cache);
PyObject *descr = read_obj(&next_instr[5].cache);
assert((oparg & 1) == 0);
@@ -3439,9 +3575,10 @@
}
TARGET(LOAD_ATTR_METHOD_LAZY_DICT) {
- PyObject *self = stack_pointer[-1];
- PyObject *res2 = NULL;
+ PyObject *self;
+ PyObject *res2;
PyObject *res;
+ self = stack_pointer[-1];
uint32_t type_version = read_u32(&next_instr[1].cache);
PyObject *descr = read_obj(&next_instr[5].cache);
assert(oparg & 1);
@@ -3458,8 +3595,8 @@
res2 = Py_NewRef(descr);
res = self;
STACK_GROW(1);
- stack_pointer[-1] = res;
stack_pointer[-2] = res2;
+ stack_pointer[-1] = res;
next_instr += 9;
DISPATCH();
}
@@ -3489,10 +3626,13 @@
TARGET(CALL) {
PREDICTED(CALL);
static_assert(INLINE_CACHE_ENTRIES_CALL == 3, "incorrect cache size");
- PyObject **args = (stack_pointer - oparg);
- PyObject *callable = stack_pointer[-(1 + oparg)];
- PyObject *method = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *callable;
+ PyObject *method;
PyObject *res;
+ args = stack_pointer - oparg;
+ callable = stack_pointer[-1 - oparg];
+ method = stack_pointer[-2 - oparg];
int is_meth = method != NULL;
int total_args = oparg;
if (is_meth) {
@@ -3583,8 +3723,10 @@
}
TARGET(CALL_BOUND_METHOD_EXACT_ARGS) {
- PyObject *callable = stack_pointer[-(1 + oparg)];
- PyObject *method = stack_pointer[-(2 + oparg)];
+ PyObject *callable;
+ PyObject *method;
+ callable = stack_pointer[-1 - oparg];
+ method = stack_pointer[-2 - oparg];
DEOPT_IF(method != NULL, CALL);
DEOPT_IF(Py_TYPE(callable) != &PyMethod_Type, CALL);
STAT_INC(CALL, hit);
@@ -3594,13 +3736,18 @@
PEEK(oparg + 2) = Py_NewRef(meth); // method
Py_DECREF(callable);
GO_TO_INSTRUCTION(CALL_PY_EXACT_ARGS);
+ STACK_SHRINK(oparg);
+ STACK_SHRINK(1);
}
TARGET(CALL_PY_EXACT_ARGS) {
PREDICTED(CALL_PY_EXACT_ARGS);
- PyObject **args = (stack_pointer - oparg);
- PyObject *callable = stack_pointer[-(1 + oparg)];
- PyObject *method = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *callable;
+ PyObject *method;
+ args = stack_pointer - oparg;
+ callable = stack_pointer[-1 - oparg];
+ method = stack_pointer[-2 - oparg];
uint32_t func_version = read_u32(&next_instr[1].cache);
ASSERT_KWNAMES_IS_NULL();
DEOPT_IF(tstate->interp->eval_frame, CALL);
@@ -3627,12 +3774,17 @@
SKIP_OVER(INLINE_CACHE_ENTRIES_CALL);
frame->return_offset = 0;
DISPATCH_INLINED(new_frame);
+ STACK_SHRINK(oparg);
+ STACK_SHRINK(1);
}
TARGET(CALL_PY_WITH_DEFAULTS) {
- PyObject **args = (stack_pointer - oparg);
- PyObject *callable = stack_pointer[-(1 + oparg)];
- PyObject *method = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *callable;
+ PyObject *method;
+ args = stack_pointer - oparg;
+ callable = stack_pointer[-1 - oparg];
+ method = stack_pointer[-2 - oparg];
uint32_t func_version = read_u32(&next_instr[1].cache);
ASSERT_KWNAMES_IS_NULL();
DEOPT_IF(tstate->interp->eval_frame, CALL);
@@ -3669,13 +3821,18 @@
SKIP_OVER(INLINE_CACHE_ENTRIES_CALL);
frame->return_offset = 0;
DISPATCH_INLINED(new_frame);
+ STACK_SHRINK(oparg);
+ STACK_SHRINK(1);
}
TARGET(CALL_NO_KW_TYPE_1) {
- PyObject **args = (stack_pointer - oparg);
- PyObject *callable = stack_pointer[-(1 + oparg)];
- PyObject *null = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *callable;
+ PyObject *null;
PyObject *res;
+ args = stack_pointer - oparg;
+ callable = stack_pointer[-1 - oparg];
+ null = stack_pointer[-2 - oparg];
ASSERT_KWNAMES_IS_NULL();
assert(oparg == 1);
DEOPT_IF(null != NULL, CALL);
@@ -3693,10 +3850,13 @@
}
TARGET(CALL_NO_KW_STR_1) {
- PyObject **args = (stack_pointer - oparg);
- PyObject *callable = stack_pointer[-(1 + oparg)];
- PyObject *null = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *callable;
+ PyObject *null;
PyObject *res;
+ args = stack_pointer - oparg;
+ callable = stack_pointer[-1 - oparg];
+ null = stack_pointer[-2 - oparg];
ASSERT_KWNAMES_IS_NULL();
assert(oparg == 1);
DEOPT_IF(null != NULL, CALL);
@@ -3716,10 +3876,13 @@
}
TARGET(CALL_NO_KW_TUPLE_1) {
- PyObject **args = (stack_pointer - oparg);
- PyObject *callable = stack_pointer[-(1 + oparg)];
- PyObject *null = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *callable;
+ PyObject *null;
PyObject *res;
+ args = stack_pointer - oparg;
+ callable = stack_pointer[-1 - oparg];
+ null = stack_pointer[-2 - oparg];
ASSERT_KWNAMES_IS_NULL();
assert(oparg == 1);
DEOPT_IF(null != NULL, CALL);
@@ -3739,9 +3902,12 @@
}
TARGET(CALL_NO_KW_ALLOC_AND_ENTER_INIT) {
- PyObject **args = (stack_pointer - oparg);
- PyObject *callable = stack_pointer[-(1 + oparg)];
- PyObject *null = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *callable;
+ PyObject *null;
+ args = stack_pointer - oparg;
+ callable = stack_pointer[-1 - oparg];
+ null = stack_pointer[-2 - oparg];
/* This instruction does the following:
* 1. Creates the object (by calling ``object.__new__``)
* 2. Pushes a shim frame to the frame stack (to cleanup after ``__init__``)
@@ -3792,10 +3958,13 @@
* as it will be checked after start_frame */
tstate->py_recursion_remaining--;
goto start_frame;
+ STACK_SHRINK(oparg);
+ STACK_SHRINK(1);
}
TARGET(EXIT_INIT_CHECK) {
- PyObject *should_be_none = stack_pointer[-1];
+ PyObject *should_be_none;
+ should_be_none = stack_pointer[-1];
assert(STACK_LEVEL() == 2);
if (should_be_none != Py_None) {
PyErr_Format(PyExc_TypeError,
@@ -3808,10 +3977,13 @@
}
TARGET(CALL_BUILTIN_CLASS) {
- PyObject **args = (stack_pointer - oparg);
- PyObject *callable = stack_pointer[-(1 + oparg)];
- PyObject *method = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *callable;
+ PyObject *method;
PyObject *res;
+ args = stack_pointer - oparg;
+ callable = stack_pointer[-1 - oparg];
+ method = stack_pointer[-2 - oparg];
int is_meth = method != NULL;
int total_args = oparg;
if (is_meth) {
@@ -3842,10 +4014,13 @@
}
TARGET(CALL_NO_KW_BUILTIN_O) {
- PyObject **args = (stack_pointer - oparg);
- PyObject *callable = stack_pointer[-(1 + oparg)];
- PyObject *method = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *callable;
+ PyObject *method;
PyObject *res;
+ args = stack_pointer - oparg;
+ callable = stack_pointer[-1 - oparg];
+ method = stack_pointer[-2 - oparg];
/* Builtin METH_O functions */
ASSERT_KWNAMES_IS_NULL();
int is_meth = method != NULL;
@@ -3882,10 +4057,13 @@
}
TARGET(CALL_NO_KW_BUILTIN_FAST) {
- PyObject **args = (stack_pointer - oparg);
- PyObject *callable = stack_pointer[-(1 + oparg)];
- PyObject *method = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *callable;
+ PyObject *method;
PyObject *res;
+ args = stack_pointer - oparg;
+ callable = stack_pointer[-1 - oparg];
+ method = stack_pointer[-2 - oparg];
/* Builtin METH_FASTCALL functions, without keywords */
ASSERT_KWNAMES_IS_NULL();
int is_meth = method != NULL;
@@ -3926,10 +4104,13 @@
}
TARGET(CALL_BUILTIN_FAST_WITH_KEYWORDS) {
- PyObject **args = (stack_pointer - oparg);
- PyObject *callable = stack_pointer[-(1 + oparg)];
- PyObject *method = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *callable;
+ PyObject *method;
PyObject *res;
+ args = stack_pointer - oparg;
+ callable = stack_pointer[-1 - oparg];
+ method = stack_pointer[-2 - oparg];
/* Builtin METH_FASTCALL | METH_KEYWORDS functions */
int is_meth = method != NULL;
int total_args = oparg;
@@ -3970,10 +4151,13 @@
}
TARGET(CALL_NO_KW_LEN) {
- PyObject **args = (stack_pointer - oparg);
- PyObject *callable = stack_pointer[-(1 + oparg)];
- PyObject *method = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *callable;
+ PyObject *method;
PyObject *res;
+ args = stack_pointer - oparg;
+ callable = stack_pointer[-1 - oparg];
+ method = stack_pointer[-2 - oparg];
ASSERT_KWNAMES_IS_NULL();
/* len(o) */
int is_meth = method != NULL;
@@ -4006,10 +4190,13 @@
}
TARGET(CALL_NO_KW_ISINSTANCE) {
- PyObject **args = (stack_pointer - oparg);
- PyObject *callable = stack_pointer[-(1 + oparg)];
- PyObject *method = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *callable;
+ PyObject *method;
PyObject *res;
+ args = stack_pointer - oparg;
+ callable = stack_pointer[-1 - oparg];
+ method = stack_pointer[-2 - oparg];
ASSERT_KWNAMES_IS_NULL();
/* isinstance(o, o2) */
int is_meth = method != NULL;
@@ -4044,9 +4231,12 @@
}
TARGET(CALL_NO_KW_LIST_APPEND) {
- PyObject **args = (stack_pointer - oparg);
- PyObject *self = stack_pointer[-(1 + oparg)];
- PyObject *method = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *self;
+ PyObject *method;
+ args = stack_pointer - oparg;
+ self = stack_pointer[-1 - oparg];
+ method = stack_pointer[-2 - oparg];
ASSERT_KWNAMES_IS_NULL();
assert(oparg == 1);
assert(method != NULL);
@@ -4064,12 +4254,16 @@
SKIP_OVER(INLINE_CACHE_ENTRIES_CALL + 1);
assert(next_instr[-1].op.code == POP_TOP);
DISPATCH();
+ STACK_SHRINK(oparg);
+ STACK_SHRINK(1);
}
TARGET(CALL_NO_KW_METHOD_DESCRIPTOR_O) {
- PyObject **args = (stack_pointer - oparg);
- PyObject *method = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *method;
PyObject *res;
+ args = stack_pointer - oparg;
+ method = stack_pointer[-2 - oparg];
ASSERT_KWNAMES_IS_NULL();
int is_meth = method != NULL;
int total_args = oparg;
@@ -4109,9 +4303,11 @@
}
TARGET(CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS) {
- PyObject **args = (stack_pointer - oparg);
- PyObject *method = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *method;
PyObject *res;
+ args = stack_pointer - oparg;
+ method = stack_pointer[-2 - oparg];
int is_meth = method != NULL;
int total_args = oparg;
if (is_meth) {
@@ -4149,9 +4345,11 @@
}
TARGET(CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS) {
- PyObject **args = (stack_pointer - oparg);
- PyObject *method = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *method;
PyObject *res;
+ args = stack_pointer - oparg;
+ method = stack_pointer[-2 - oparg];
ASSERT_KWNAMES_IS_NULL();
assert(oparg == 0 || oparg == 1);
int is_meth = method != NULL;
@@ -4189,9 +4387,11 @@
}
TARGET(CALL_NO_KW_METHOD_DESCRIPTOR_FAST) {
- PyObject **args = (stack_pointer - oparg);
- PyObject *method = stack_pointer[-(2 + oparg)];
+ PyObject **args;
+ PyObject *method;
PyObject *res;
+ args = stack_pointer - oparg;
+ method = stack_pointer[-2 - oparg];
ASSERT_KWNAMES_IS_NULL();
int is_meth = method != NULL;
int total_args = oparg;
@@ -4233,10 +4433,13 @@
TARGET(CALL_FUNCTION_EX) {
PREDICTED(CALL_FUNCTION_EX);
- PyObject *kwargs = (oparg & 1) ? stack_pointer[-(((oparg & 1) ? 1 : 0))] : NULL;
- PyObject *callargs = stack_pointer[-(1 + ((oparg & 1) ? 1 : 0))];
- PyObject *func = stack_pointer[-(2 + ((oparg & 1) ? 1 : 0))];
+ PyObject *kwargs = NULL;
+ PyObject *callargs;
+ PyObject *func;
PyObject *result;
+ if (oparg & 1) { kwargs = stack_pointer[-(oparg & 1 ? 1 : 0)]; }
+ callargs = stack_pointer[-1 - (oparg & 1 ? 1 : 0)];
+ func = stack_pointer[-2 - (oparg & 1 ? 1 : 0)];
// DICT_MERGE is called before this opcode if there are kwargs.
// It converts all dict subtypes in kwargs into regular dicts.
assert(kwargs == NULL || PyDict_CheckExact(kwargs));
@@ -4311,8 +4514,9 @@
}
TARGET(MAKE_FUNCTION) {
- PyObject *codeobj = stack_pointer[-1];
+ PyObject *codeobj;
PyObject *func;
+ codeobj = stack_pointer[-1];
PyFunctionObject *func_obj = (PyFunctionObject *)
PyFunction_New(codeobj, GLOBALS());
@@ -4329,8 +4533,10 @@
}
TARGET(SET_FUNCTION_ATTRIBUTE) {
- PyObject *func = stack_pointer[-1];
- PyObject *attr = stack_pointer[-2];
+ PyObject *func;
+ PyObject *attr;
+ func = stack_pointer[-1];
+ attr = stack_pointer[-2];
assert(PyFunction_Check(func));
PyFunctionObject *func_obj = (PyFunctionObject *)func;
switch(oparg) {
@@ -4384,10 +4590,13 @@
}
TARGET(BUILD_SLICE) {
- PyObject *step = (oparg == 3) ? stack_pointer[-(((oparg == 3) ? 1 : 0))] : NULL;
- PyObject *stop = stack_pointer[-(1 + ((oparg == 3) ? 1 : 0))];
- PyObject *start = stack_pointer[-(2 + ((oparg == 3) ? 1 : 0))];
+ PyObject *step = NULL;
+ PyObject *stop;
+ PyObject *start;
PyObject *slice;
+ if (oparg == 3) { step = stack_pointer[-(oparg == 3 ? 1 : 0)]; }
+ stop = stack_pointer[-1 - (oparg == 3 ? 1 : 0)];
+ start = stack_pointer[-2 - (oparg == 3 ? 1 : 0)];
slice = PySlice_New(start, stop, step);
Py_DECREF(start);
Py_DECREF(stop);
@@ -4400,8 +4609,9 @@
}
TARGET(CONVERT_VALUE) {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
PyObject *result;
+ value = stack_pointer[-1];
convertion_func_ptr conv_fn;
assert(oparg >= FVC_STR && oparg <= FVC_ASCII);
conv_fn = CONVERSION_FUNCTIONS[oparg];
@@ -4413,8 +4623,9 @@
}
TARGET(FORMAT_SIMPLE) {
- PyObject *value = stack_pointer[-1];
+ PyObject *value;
PyObject *res;
+ value = stack_pointer[-1];
/* If value is a unicode object, then we know the result
* of format(value) is value itself. */
if (!PyUnicode_CheckExact(value)) {
@@ -4430,9 +4641,11 @@
}
TARGET(FORMAT_WITH_SPEC) {
- PyObject *fmt_spec = stack_pointer[-1];
- PyObject *value = stack_pointer[-2];
+ PyObject *fmt_spec;
+ PyObject *value;
PyObject *res;
+ fmt_spec = stack_pointer[-1];
+ value = stack_pointer[-2];
res = PyObject_Format(value, fmt_spec);
Py_DECREF(value);
Py_DECREF(fmt_spec);
@@ -4443,8 +4656,9 @@
}
TARGET(COPY) {
- PyObject *bottom = stack_pointer[-(1 + (oparg-1))];
+ PyObject *bottom;
PyObject *top;
+ bottom = stack_pointer[-1 - (oparg-1)];
assert(oparg > 0);
top = Py_NewRef(bottom);
STACK_GROW(1);
@@ -4455,9 +4669,11 @@
TARGET(BINARY_OP) {
PREDICTED(BINARY_OP);
static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 1, "incorrect cache size");
- PyObject *rhs = stack_pointer[-1];
- PyObject *lhs = stack_pointer[-2];
+ PyObject *rhs;
+ PyObject *lhs;
PyObject *res;
+ rhs = stack_pointer[-1];
+ lhs = stack_pointer[-2];
#if ENABLE_SPECIALIZATION
_PyBinaryOpCache *cache = (_PyBinaryOpCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
@@ -4482,11 +4698,13 @@
}
TARGET(SWAP) {
- PyObject *top = stack_pointer[-1];
- PyObject *bottom = stack_pointer[-(2 + (oparg-2))];
+ PyObject *top;
+ PyObject *bottom;
+ top = stack_pointer[-1];
+ bottom = stack_pointer[-2 - (oparg-2)];
assert(oparg >= 2);
+ stack_pointer[-2 - (oparg-2)] = top;
stack_pointer[-1] = bottom;
- stack_pointer[-(2 + (oparg-2))] = top;
DISPATCH();
}
diff --git a/Tools/cases_generator/analysis.py b/Tools/cases_generator/analysis.py
index 53ae7360b8ae1..bd8918a87ffe0 100644
--- a/Tools/cases_generator/analysis.py
+++ b/Tools/cases_generator/analysis.py
@@ -13,7 +13,6 @@
MacroParts,
OverriddenInstructionPlaceHolder,
PseudoInstruction,
- StackEffectMapping,
)
import parsing
from parsing import StackEffect
@@ -34,11 +33,12 @@ class Analyzer:
input_filenames: list[str]
errors: int = 0
+ warnings: int = 0
def __init__(self, input_filenames: list[str]):
self.input_filenames = input_filenames
- def error(self, msg: str, node: parsing.Node) -> None:
+ def message(self, msg: str, node: parsing.Node) -> None:
lineno = 0
filename = "<unknown file>"
if context := node.context:
@@ -49,8 +49,18 @@ def error(self, msg: str, node: parsing.Node) -> None:
if token.kind != "COMMENT":
break
print(f"{filename}:{lineno}: {msg}", file=sys.stderr)
+
+ def error(self, msg: str, node: parsing.Node) -> None:
+ self.message("error: " + msg, node)
self.errors += 1
+ def warning(self, msg: str, node: parsing.Node) -> None:
+ self.message("warning: " + msg, node)
+ self.warnings += 1
+
+ def note(self, msg: str, node: parsing.Node) -> None:
+ self.message("note: " + msg, node)
+
everything: list[
parsing.InstDef
| parsing.Macro
@@ -83,8 +93,15 @@ def parse(self) -> None:
self.parse_file(filename, instrs_idx)
files = " + ".join(self.input_filenames)
+ n_instrs = 0
+ n_ops = 0
+ for instr in self.instrs.values():
+ if instr.kind == "op":
+ n_ops += 1
+ else:
+ n_instrs += 1
print(
- f"Read {len(self.instrs)} instructions/ops, "
+ f"Read {n_instrs} instructions, {n_ops} ops, "
f"{len(self.macros)} macros, {len(self.pseudos)} pseudos, "
f"and {len(self.families)} families from {files}",
file=sys.stderr,
@@ -270,14 +287,70 @@ def analyze_macros_and_pseudos(self) -> None:
self.macro_instrs = {}
self.pseudo_instrs = {}
for name, macro in self.macros.items():
- self.macro_instrs[name] = self.analyze_macro(macro)
+ self.macro_instrs[name] = mac = self.analyze_macro(macro)
+ self.check_macro_consistency(mac)
for name, pseudo in self.pseudos.items():
self.pseudo_instrs[name] = self.analyze_pseudo(pseudo)
+ # TODO: Merge with similar code in stacking.py, write_components()
+ def check_macro_consistency(self, mac: MacroInstruction) -> None:
+ def get_var_names(instr: Instruction) -> dict[str, StackEffect]:
+ vars: dict[str, StackEffect] = {}
+ for eff in instr.input_effects + instr.output_effects:
+ if eff.name in vars:
+ if vars[eff.name] != eff:
+ self.error(
+ f"Instruction {instr.name!r} has "
+ f"inconsistent type/cond/size for variable "
+ f"{eff.name!r}: {vars[eff.name]} vs {eff}",
+ instr.inst,
+ )
+ else:
+ vars[eff.name] = eff
+ return vars
+
+ all_vars: dict[str, StackEffect] = {}
+ # print("Checking", mac.name)
+ prevop: Instruction | None = None
+ for part in mac.parts:
+ if not isinstance(part, Component):
+ continue
+ vars = get_var_names(part.instr)
+ # print(" //", part.instr.name, "//", vars)
+ for name, eff in vars.items():
+ if name in all_vars:
+ if all_vars[name] != eff:
+ self.error(
+ f"Macro {mac.name!r} has "
+ f"inconsistent type/cond/size for variable "
+ f"{name!r}: "
+ f"{all_vars[name]} vs {eff} in {part.instr.name!r}",
+ mac.macro,
+ )
+ else:
+ all_vars[name] = eff
+ if prevop is not None:
+ pushes = list(prevop.output_effects)
+ pops = list(reversed(part.instr.input_effects))
+ copies: list[tuple[StackEffect, StackEffect]] = []
+ while pushes and pops and pushes[-1] == pops[0]:
+ src, dst = pushes.pop(), pops.pop(0)
+ if src.name == dst.name or dst.name is UNUSED:
+ continue
+ copies.append((src, dst))
+ reads = set(copy[0].name for copy in copies)
+ writes = set(copy[1].name for copy in copies)
+ if reads & writes:
+ self.error(
+ f"Macro {mac.name!r} has conflicting copies "
+ f"(source of one copy is destination of another): "
+ f"{reads & writes}",
+ mac.macro,
+ )
+ prevop = part.instr
+
def analyze_macro(self, macro: parsing.Macro) -> MacroInstruction:
components = self.check_macro_components(macro)
- stack, initial_sp = self.stack_analysis(components)
- sp = initial_sp
parts: MacroParts = []
flags = InstructionFlags.newEmpty()
offset = 0
@@ -287,20 +360,15 @@ def analyze_macro(self, macro: parsing.Macro) -> MacroInstruction:
parts.append(ceffect)
offset += ceffect.size
case Instruction() as instr:
- part, sp, offset = self.analyze_instruction(
- instr, stack, sp, offset
- )
+ part, offset = self.analyze_instruction(instr, offset)
parts.append(part)
flags.add(instr.instr_flags)
case _:
typing.assert_never(component)
- final_sp = sp
format = "IB"
if offset:
format += "C" + "0" * (offset - 1)
- return MacroInstruction(
- macro.name, stack, initial_sp, final_sp, format, flags, macro, parts, offset
- )
+ return MacroInstruction(macro.name, format, flags, macro, parts, offset)
def analyze_pseudo(self, pseudo: parsing.Pseudo) -> PseudoInstruction:
targets = [self.instrs[target] for target in pseudo.targets]
@@ -312,24 +380,15 @@ def analyze_pseudo(self, pseudo: parsing.Pseudo) -> PseudoInstruction:
return PseudoInstruction(pseudo.name, targets, fmts[0], targets[0].instr_flags)
def analyze_instruction(
- self, instr: Instruction, stack: list[StackEffect], sp: int, offset: int
- ) -> tuple[Component, int, int]:
- input_mapping: StackEffectMapping = []
- for ieffect in reversed(instr.input_effects):
- sp -= 1
- input_mapping.append((stack[sp], ieffect))
- output_mapping: StackEffectMapping = []
- for oeffect in instr.output_effects:
- output_mapping.append((stack[sp], oeffect))
- sp += 1
+ self, instr: Instruction, offset: int
+ ) -> tuple[Component, int]:
active_effects: list[ActiveCacheEffect] = []
for ceffect in instr.cache_effects:
if ceffect.name != UNUSED:
active_effects.append(ActiveCacheEffect(ceffect, offset))
offset += ceffect.size
return (
- Component(instr, input_mapping, output_mapping, active_effects),
- sp,
+ Component(instr, active_effects),
offset,
)
@@ -348,65 +407,3 @@ def check_macro_components(
case _:
typing.assert_never(uop)
return components
-
- def stack_analysis(
- self, components: typing.Iterable[InstructionOrCacheEffect]
- ) -> tuple[list[StackEffect], int]:
- """Analyze a macro.
-
- Ignore cache effects.
-
- Return the list of variables (as StackEffects) and the initial stack pointer.
- """
- lowest = current = highest = 0
- conditions: dict[int, str] = {} # Indexed by 'current'.
- last_instr: Instruction | None = None
- for thing in components:
- if isinstance(thing, Instruction):
- last_instr = thing
- for thing in components:
- match thing:
- case Instruction() as instr:
- if any(
- eff.size for eff in instr.input_effects + instr.output_effects
- ):
- # TODO: Eventually this will be needed, at least for macros.
- self.error(
- f"Instruction {instr.name!r} has variable-sized stack effect, "
- "which are not supported in macro instructions",
- instr.inst, # TODO: Pass name+location of macro
- )
- if any(eff.cond for eff in instr.input_effects):
- self.error(
- f"Instruction {instr.name!r} has conditional input stack effect, "
- "which are not supported in macro instructions",
- instr.inst, # TODO: Pass name+location of macro
- )
- if (
- any(eff.cond for eff in instr.output_effects)
- and instr is not last_instr
- ):
- self.error(
- f"Instruction {instr.name!r} has conditional output stack effect, "
- "but is not the last instruction in a macro",
- instr.inst, # TODO: Pass name+location of macro
- )
- current -= len(instr.input_effects)
- lowest = min(lowest, current)
- for eff in instr.output_effects:
- if eff.cond:
- conditions[current] = eff.cond
- current += 1
- highest = max(highest, current)
- case parsing.CacheEffect():
- pass
- case _:
- typing.assert_never(thing)
- # At this point, 'current' is the net stack effect,
- # and 'lowest' and 'highest' are the extremes.
- # Note that 'lowest' may be negative.
- stack = [
- StackEffect(f"_tmp_{i}", "", conditions.get(highest - i, ""))
- for i in reversed(range(1, highest - lowest + 1))
- ]
- return stack, -lowest
diff --git a/Tools/cases_generator/flags.py b/Tools/cases_generator/flags.py
index 78acd93b73ac3..f7ebdeb0d6567 100644
--- a/Tools/cases_generator/flags.py
+++ b/Tools/cases_generator/flags.py
@@ -49,9 +49,9 @@ def add(self, other: "InstructionFlags") -> None:
if value:
setattr(self, name, value)
- def names(self, value=None):
+ def names(self, value=None) -> list[str]:
if value is None:
- return dataclasses.asdict(self).keys()
+ return list(dataclasses.asdict(self).keys())
return [n for n, v in dataclasses.asdict(self).items() if v == value]
def bitmap(self) -> int:
diff --git a/Tools/cases_generator/formatting.py b/Tools/cases_generator/formatting.py
index 6b5a375af891b..5894751bd9635 100644
--- a/Tools/cases_generator/formatting.py
+++ b/Tools/cases_generator/formatting.py
@@ -2,7 +2,7 @@
import re
import typing
-from parsing import StackEffect
+from parsing import StackEffect, Family
UNUSED = "unused"
@@ -19,8 +19,11 @@ class Formatter:
nominal_filename: str
def __init__(
- self, stream: typing.TextIO, indent: int,
- emit_line_directives: bool = False, comment: str = "//",
+ self,
+ stream: typing.TextIO,
+ indent: int,
+ emit_line_directives: bool = False,
+ comment: str = "//",
) -> None:
self.stream = stream
self.prefix = " " * indent
@@ -93,8 +96,11 @@ def declare(self, dst: StackEffect, src: StackEffect | None):
typ = f"{dst.type}" if dst.type else "PyObject *"
if src:
cast = self.cast(dst, src)
- init = f" = {cast}{src.name}"
- elif dst.cond:
+ initexpr = f"{cast}{src.name}"
+ if src.cond and src.cond != "1":
+ initexpr = f"{parenthesize_cond(src.cond)} ? {initexpr} : NULL"
+ init = f" = {initexpr}"
+ elif dst.cond and dst.cond != "1":
init = " = NULL"
else:
init = ""
@@ -102,10 +108,7 @@ def declare(self, dst: StackEffect, src: StackEffect | None):
self.emit(f"{typ}{sepa}{dst.name}{init};")
def assign(self, dst: StackEffect, src: StackEffect):
- if src.name == UNUSED:
- return
- if src.size:
- # Don't write sized arrays -- it's up to the user code.
+ if src.name == UNUSED or dst.name == UNUSED:
return
cast = self.cast(dst, src)
if re.match(r"^REG\(oparg(\d+)\)$", dst.name):
@@ -122,6 +125,23 @@ def assign(self, dst: StackEffect, src: StackEffect):
def cast(self, dst: StackEffect, src: StackEffect) -> str:
return f"({dst.type or 'PyObject *'})" if src.type != dst.type else ""
+ def static_assert_family_size(
+ self, name: str, family: Family | None, cache_offset: int
+ ) -> None:
+ """Emit a static_assert for the size of a family, if known.
+
+ This will fail at compile time if the cache size computed from
+ the instruction definition does not match the size of the struct
+ used by specialize.c.
+ """
+ if family and name == family.name:
+ cache_size = family.size
+ if cache_size:
+ self.emit(
+ f"static_assert({cache_size} == {cache_offset}, "
+ f'"incorrect cache size");'
+ )
+
def prettify_filename(filename: str) -> str:
# Make filename more user-friendly and less platform-specific,
@@ -178,11 +198,8 @@ def maybe_parenthesize(sym: str) -> str:
return f"({sym})"
-def string_effect_size(arg: tuple[int, str]) -> str:
- numeric, symbolic = arg
- if numeric and symbolic:
- return f"{numeric} + {symbolic}"
- elif symbolic:
- return symbolic
- else:
- return str(numeric)
+def parenthesize_cond(cond: str) -> str:
+ """Parenthesize a condition, but only if it contains ?: itself."""
+ if "?" in cond:
+ cond = f"({cond})"
+ return cond
diff --git a/Tools/cases_generator/generate_cases.py b/Tools/cases_generator/generate_cases.py
index 967e1e2f5b63b..d35a16a80e8d0 100644
--- a/Tools/cases_generator/generate_cases.py
+++ b/Tools/cases_generator/generate_cases.py
@@ -4,14 +4,14 @@
"""
import argparse
-import contextlib
import os
import posixpath
import sys
import typing
+import stacking # Early import to avoid circular import
from analysis import Analyzer
-from formatting import Formatter, list_effect_size, maybe_parenthesize
+from formatting import Formatter, list_effect_size
from flags import InstructionFlags, variable_used
from instructions import (
AnyInstruction,
@@ -118,41 +118,7 @@ def effect_str(effects: list[StackEffect]) -> str:
pushed = ""
case parsing.Macro():
instr = self.macro_instrs[thing.name]
- parts = [comp for comp in instr.parts if isinstance(comp, Component)]
- # Note: stack_analysis() already verifies that macro components
- # have no variable-sized stack effects.
- low = 0
- sp = 0
- high = 0
- pushed_symbolic: list[str] = []
- for comp in parts:
- for effect in comp.instr.input_effects:
- assert not effect.cond, effect
- assert not effect.size, effect
- sp -= 1
- low = min(low, sp)
- for effect in comp.instr.output_effects:
- assert not effect.size, effect
- if effect.cond:
- if effect.cond in ("0", "1"):
- pushed_symbolic.append(effect.cond)
- else:
- pushed_symbolic.append(
- maybe_parenthesize(
- f"{maybe_parenthesize(effect.cond)} ? 1 : 0"
- )
- )
- sp += 1
- high = max(sp, high)
- if high != max(0, sp):
- # If you get this, intermediate stack growth occurs,
- # and stack size calculations may go awry.
- # E.g. [push, pop]. The fix would be for stack size
- # calculations to use the micro ops.
- self.error("Macro has virtual stack growth", thing)
- popped = str(-low)
- pushed_symbolic.append(str(sp - low - len(pushed_symbolic)))
- pushed = " + ".join(pushed_symbolic)
+ popped, pushed = stacking.get_stack_effect_info_for_macro(instr)
case parsing.Pseudo():
instr = self.pseudo_instrs[thing.name]
popped = pushed = None
@@ -258,7 +224,8 @@ def write_metadata(self, metadata_filename: str, pymetadata_filename: str) -> No
case _:
typing.assert_never(thing)
all_formats.add(format)
- # Turn it into a list of enum definitions.
+
+ # Turn it into a sorted list of enum values.
format_enums = [INSTR_FMT_PREFIX + format for format in sorted(all_formats)]
with open(metadata_filename, "w") as f:
@@ -276,8 +243,10 @@ def write_metadata(self, metadata_filename: str, pymetadata_filename: str) -> No
self.write_stack_effect_functions()
- # Write type definitions
- self.out.emit(f"enum InstructionFormat {{ {', '.join(format_enums)} }};")
+ # Write the enum definition for instruction formats.
+ with self.out.block("enum InstructionFormat", ";"):
+ for enum in format_enums:
+ self.out.emit(enum + ",")
self.out.emit("")
self.out.emit(
@@ -374,7 +343,7 @@ def write_metadata(self, metadata_filename: str, pymetadata_filename: str) -> No
# Since an 'op' is not a bytecode, it has no expansion; but 'inst' is
if instr.kind == "inst" and instr.is_viable_uop():
# Construct a dummy Component -- input/output mappings are not used
- part = Component(instr, [], [], instr.active_caches)
+ part = Component(instr, instr.active_caches)
self.write_macro_expansions(instr.name, [part])
elif instr.kind == "inst" and variable_used(
instr.inst, "oparg1"
@@ -468,7 +437,15 @@ def write_macro_expansions(self, name: str, parts: MacroParts) -> None:
if isinstance(part, Component):
# All component instructions must be viable uops
if not part.instr.is_viable_uop():
- print(f"NOTE: Part {part.instr.name} of {name} is not a viable uop")
+ # This note just reminds us about macros that cannot
+ # be expanded to Tier 2 uops. It is not an error.
+ # It is sometimes emitted for macros that have a
+ # manual translation in translate_bytecode_to_trace()
+ # in Python/optimizer.c.
+ self.note(
+ f"Part {part.instr.name} of {name} is not a viable uop",
+ part.instr.inst,
+ )
return
if not part.active_caches:
size, offset = OPARG_SIZES["OPARG_FULL"], 0
@@ -512,7 +489,7 @@ def write_super_expansions(self, name: str) -> None:
instr2 = self.instrs[name2]
assert not instr1.active_caches, f"{name1} has active caches"
assert not instr2.active_caches, f"{name2} has active caches"
- expansions = [
+ expansions: list[tuple[str, int, int]] = [
(name1, OPARG_SIZES["OPARG_TOP"], 0),
(name2, OPARG_SIZES["OPARG_BOTTOM"], 0),
]
@@ -563,7 +540,6 @@ def write_instructions(
# Write and count instructions of all kinds
n_instrs = 0
n_macros = 0
- n_pseudos = 0
for thing in self.everything:
match thing:
case OverriddenInstructionPlaceHolder():
@@ -574,15 +550,17 @@ def write_instructions(
self.write_instr(self.instrs[thing.name])
case parsing.Macro():
n_macros += 1
- self.write_macro(self.macro_instrs[thing.name])
+ mac = self.macro_instrs[thing.name]
+ stacking.write_macro_instr(mac, self.out, self.families.get(mac.name))
+ # self.write_macro(self.macro_instrs[thing.name])
case parsing.Pseudo():
- n_pseudos += 1
+ pass
case _:
typing.assert_never(thing)
print(
- f"Wrote {n_instrs} instructions, {n_macros} macros, "
- f"and {n_pseudos} pseudos to {output_filename}",
+ f"Wrote {n_instrs} instructions and {n_macros} macros "
+ f"to {output_filename}",
file=sys.stderr,
)
@@ -590,6 +568,8 @@ def write_executor_instructions(
self, executor_filename: str, emit_line_directives: bool
) -> None:
"""Generate cases for the Tier 2 interpreter."""
+ n_instrs = 0
+ n_uops = 0
with open(executor_filename, "w") as f:
self.out = Formatter(f, 8, emit_line_directives)
self.write_provenance_header()
@@ -601,6 +581,10 @@ def write_executor_instructions(
case parsing.InstDef():
instr = self.instrs[thing.name]
if instr.is_viable_uop():
+ if instr.kind == "op":
+ n_uops += 1
+ else:
+ n_instrs += 1
self.out.emit("")
with self.out.block(f"case {thing.name}:"):
instr.write(self.out, tier=TIER_TWO)
@@ -616,7 +600,7 @@ def write_executor_instructions(
case _:
typing.assert_never(thing)
print(
- f"Wrote some stuff to {executor_filename}",
+ f"Wrote {n_instrs} instructions and {n_uops} ops to {executor_filename}",
file=sys.stderr,
)
@@ -642,69 +626,6 @@ def write_instr(self, instr: Instruction) -> None:
self.out.emit("CHECK_EVAL_BREAKER();")
self.out.emit(f"DISPATCH();")
- def write_macro(self, mac: MacroInstruction) -> None:
- """Write code for a macro instruction."""
- last_instr: Instruction | None = None
- with self.wrap_macro(mac):
- cache_adjust = 0
- for part in mac.parts:
- match part:
- case parsing.CacheEffect(size=size):
- cache_adjust += size
- case Component() as comp:
- last_instr = comp.instr
- comp.write_body(self.out)
- cache_adjust += comp.instr.cache_offset
-
- if cache_adjust:
- self.out.emit(f"next_instr += {cache_adjust};")
-
- if (
- (family := self.families.get(mac.name))
- and mac.name == family.name
- and (cache_size := family.size)
- ):
- self.out.emit(
- f"static_assert({cache_size} == "
- f'{cache_adjust}, "incorrect cache size");'
- )
-
- @contextlib.contextmanager
- def wrap_macro(self, mac: MacroInstruction):
- """Boilerplate for macro instructions."""
- # TODO: Somewhere (where?) make it so that if one instruction
- # has an output that is input to another, and the variable names
- # and types match and don't conflict with other instructions,
- # that variable is declared with the right name and type in the
- # outer block, rather than trusting the compiler to optimize it.
- self.out.emit("")
- with self.out.block(f"TARGET({mac.name})"):
- if mac.predicted:
- self.out.emit(f"PREDICTED({mac.name});")
-
- # The input effects should have no conditionals.
- # Only the output effects do (for now).
- ieffects = [
- StackEffect(eff.name, eff.type) if eff.cond else eff
- for eff in mac.stack
- ]
-
- for i, var in reversed(list(enumerate(ieffects))):
- src = None
- if i < mac.initial_sp:
- src = StackEffect(f"stack_pointer[-{mac.initial_sp - i}]", "")
- self.out.declare(var, src)
-
- yield
-
- self.out.stack_adjust(ieffects[: mac.initial_sp], mac.stack[: mac.final_sp])
-
- for i, var in enumerate(reversed(mac.stack[: mac.final_sp]), 1):
- dst = StackEffect(f"stack_pointer[-{i}]", "")
- self.out.assign(dst, var)
-
- self.out.emit(f"DISPATCH();")
-
def main():
"""Parse command line, parse input, analyze, write output."""
diff --git a/Tools/cases_generator/instructions.py b/Tools/cases_generator/instructions.py
index 6f42699d900b4..aa94dbb07ea1c 100644
--- a/Tools/cases_generator/instructions.py
+++ b/Tools/cases_generator/instructions.py
@@ -2,17 +2,16 @@
import re
import typing
-from flags import InstructionFlags, variable_used_unspecialized
+from flags import InstructionFlags, variable_used, variable_used_unspecialized
from formatting import (
Formatter,
UNUSED,
- string_effect_size,
list_effect_size,
- maybe_parenthesize,
)
import lexer as lx
import parsing
from parsing import StackEffect
+import stacking
BITS_PER_CODE_UNIT = 16
@@ -61,6 +60,7 @@ class Instruction:
# Computed by constructor
always_exits: bool
+ has_deopt: bool
cache_offset: int
cache_effects: list[parsing.CacheEffect]
input_effects: list[StackEffect]
@@ -83,6 +83,7 @@ def __init__(self, inst: parsing.InstDef):
self.block
)
self.always_exits = always_exits(self.block_text)
+ self.has_deopt = variable_used(self.inst, "DEOPT_IF")
self.cache_effects = [
effect for effect in inst.inputs if isinstance(effect, parsing.CacheEffect)
]
@@ -93,7 +94,7 @@ def __init__(self, inst: parsing.InstDef):
self.output_effects = inst.outputs # For consistency/completeness
unmoved_names: set[str] = set()
for ieffect, oeffect in zip(self.input_effects, self.output_effects):
- if ieffect.name == oeffect.name:
+ if ieffect == oeffect and ieffect.name == oeffect.name:
unmoved_names.add(ieffect.name)
else:
break
@@ -141,84 +142,17 @@ def is_viable_uop(self) -> bool:
def write(self, out: Formatter, tier: Tiers = TIER_ONE) -> None:
"""Write one instruction, sans prologue and epilogue."""
+
# Write a static assertion that a family's cache size is correct
- if family := self.family:
- if self.name == family.name:
- if cache_size := family.size:
- out.emit(
- f"static_assert({cache_size} == "
- f'{self.cache_offset}, "incorrect cache size");'
- )
+ out.static_assert_family_size(self.name, self.family, self.cache_offset)
# Write input stack effect variable declarations and initializations
- ieffects = list(reversed(self.input_effects))
- for i, ieffect in enumerate(ieffects):
- isize = string_effect_size(
- list_effect_size([ieff for ieff in ieffects[: i + 1]])
- )
- if ieffect.size:
- src = StackEffect(
- f"(stack_pointer - {maybe_parenthesize(isize)})", "PyObject **"
- )
- elif ieffect.cond:
- src = StackEffect(
- f"({ieffect.cond}) ? stack_pointer[-{maybe_parenthesize(isize)}] : NULL",
- "",
- )
- else:
- src = StackEffect(f"stack_pointer[-{maybe_parenthesize(isize)}]", "")
- out.declare(ieffect, src)
-
- # Write output stack effect variable declarations
- isize = string_effect_size(list_effect_size(self.input_effects))
- input_names = {ieffect.name for ieffect in self.input_effects}
- for i, oeffect in enumerate(self.output_effects):
- if oeffect.name not in input_names:
- if oeffect.size:
- osize = string_effect_size(
- list_effect_size([oeff for oeff in self.output_effects[:i]])
- )
- offset = "stack_pointer"
- if isize != osize:
- if isize != "0":
- offset += f" - ({isize})"
- if osize != "0":
- offset += f" + {osize}"
- src = StackEffect(offset, "PyObject **")
- out.declare(oeffect, src)
- else:
- out.declare(oeffect, None)
-
- # out.emit(f"next_instr += OPSIZE({self.inst.name}) - 1;")
-
- self.write_body(out, 0, self.active_caches, tier=tier)
+ stacking.write_single_instr(self, out, tier)
# Skip the rest if the block always exits
if self.always_exits:
return
- # Write net stack growth/shrinkage
- out.stack_adjust(
- [ieff for ieff in self.input_effects],
- [oeff for oeff in self.output_effects],
- )
-
- # Write output stack effect assignments
- oeffects = list(reversed(self.output_effects))
- for i, oeffect in enumerate(oeffects):
- if oeffect.name in self.unmoved_names:
- continue
- osize = string_effect_size(
- list_effect_size([oeff for oeff in oeffects[: i + 1]])
- )
- if oeffect.size:
- dst = StackEffect(
- f"stack_pointer - {maybe_parenthesize(osize)}", "PyObject **"
- )
- else:
- dst = StackEffect(f"stack_pointer[-{maybe_parenthesize(osize)}]", "")
- out.assign(dst, oeffect)
-
# Write cache effect
if tier == TIER_ONE and self.cache_offset:
out.emit(f"next_instr += {self.cache_offset};")
@@ -274,7 +208,12 @@ def write_body(
# These aren't DECREF'ed so they can stay.
ieffs = list(self.input_effects)
oeffs = list(self.output_effects)
- while ieffs and oeffs and ieffs[0] == oeffs[0]:
+ while (
+ ieffs
+ and oeffs
+ and ieffs[0] == oeffs[0]
+ and ieffs[0].name == oeffs[0].name
+ ):
ieffs.pop(0)
oeffs.pop(0)
ninputs, symbolic = list_effect_size(ieffs)
@@ -307,30 +246,13 @@ def write_body(
InstructionOrCacheEffect = Instruction | parsing.CacheEffect
-StackEffectMapping = list[tuple[StackEffect, StackEffect]]
@dataclasses.dataclass
class Component:
instr: Instruction
- input_mapping: StackEffectMapping
- output_mapping: StackEffectMapping
active_caches: list[ActiveCacheEffect]
- def write_body(self, out: Formatter) -> None:
- with out.block(""):
- input_names = {ieffect.name for _, ieffect in self.input_mapping}
- for var, ieffect in self.input_mapping:
- out.declare(ieffect, var)
- for _, oeffect in self.output_mapping:
- if oeffect.name not in input_names:
- out.declare(oeffect, None)
-
- self.instr.write_body(out, -4, self.active_caches)
-
- for var, oeffect in self.output_mapping:
- out.assign(var, oeffect)
-
MacroParts = list[Component | parsing.CacheEffect]
@@ -340,9 +262,6 @@ class MacroInstruction:
"""A macro instruction."""
name: str
- stack: list[StackEffect]
- initial_sp: int
- final_sp: int
instr_fmt: str
instr_flags: InstructionFlags
macro: parsing.Macro
diff --git a/Tools/cases_generator/parsing.py b/Tools/cases_generator/parsing.py
index 290285dc03123..5610ac661a894 100644
--- a/Tools/cases_generator/parsing.py
+++ b/Tools/cases_generator/parsing.py
@@ -69,12 +69,18 @@ class Block(Node):
@dataclass
class StackEffect(Node):
- name: str
+ name: str = field(compare=False) # __eq__ only uses type, cond, size
type: str = "" # Optional `:type`
cond: str = "" # Optional `if (cond)`
size: str = "" # Optional `[size]`
# Note: size cannot be combined with type or cond
+ def __repr__(self):
+ items = [self.name, self.type, self.cond, self.size]
+ while items and items[-1] == "":
+ del items[-1]
+ return f"StackEffect({', '.join(repr(item) for item in items)})"
+
@dataclass
class Expression(Node):
@@ -130,6 +136,7 @@ class Family(Node):
size: str # Variable giving the cache size in code units
members: list[str]
+
@dataclass
class Pseudo(Node):
name: str
@@ -154,7 +161,13 @@ def inst_def(self) -> InstDef | None:
if hdr := self.inst_header():
if block := self.block():
return InstDef(
- hdr.override, hdr.register, hdr.kind, hdr.name, hdr.inputs, hdr.outputs, block
+ hdr.override,
+ hdr.register,
+ hdr.kind,
+ hdr.name,
+ hdr.inputs,
+ hdr.outputs,
+ block,
)
raise self.make_syntax_error("Expected block")
return None
@@ -371,9 +384,7 @@ def pseudo_def(self) -> Pseudo | None:
raise self.make_syntax_error("Expected {")
if members := self.members():
if self.expect(lx.RBRACE) and self.expect(lx.SEMI):
- return Pseudo(
- tkn.text, members
- )
+ return Pseudo(tkn.text, members)
return None
def members(self) -> list[str] | None:
diff --git a/Tools/cases_generator/plexer.py b/Tools/cases_generator/plexer.py
index a73254ed5b1da..cb6c537586649 100644
--- a/Tools/cases_generator/plexer.py
+++ b/Tools/cases_generator/plexer.py
@@ -1,4 +1,5 @@
import lexer as lx
+
Token = lx.Token
@@ -64,7 +65,9 @@ def require(self, kind: str) -> Token:
tkn = self.next()
if tkn is not None and tkn.kind == kind:
return tkn
- raise self.make_syntax_error(f"Expected {kind!r} but got {tkn and tkn.text!r}", tkn)
+ raise self.make_syntax_error(
+ f"Expected {kind!r} but got {tkn and tkn.text!r}", tkn
+ )
def extract_line(self, lineno: int) -> str:
# Return source line `lineno` (1-based)
@@ -73,18 +76,20 @@ def extract_line(self, lineno: int) -> str:
return ""
return lines[lineno - 1]
- def make_syntax_error(self, message: str, tkn: Token|None = None) -> SyntaxError:
+ def make_syntax_error(self, message: str, tkn: Token | None = None) -> SyntaxError:
# Construct a SyntaxError instance from message and token
if tkn is None:
tkn = self.peek()
if tkn is None:
tkn = self.tokens[-1]
- return lx.make_syntax_error(message,
- self.filename, tkn.line, tkn.column, self.extract_line(tkn.line))
+ return lx.make_syntax_error(
+ message, self.filename, tkn.line, tkn.column, self.extract_line(tkn.line)
+ )
if __name__ == "__main__":
import sys
+
if sys.argv[1:]:
filename = sys.argv[1]
if filename == "-c" and sys.argv[2:]:
diff --git a/Tools/cases_generator/stacking.py b/Tools/cases_generator/stacking.py
new file mode 100644
index 0000000000000..23eca3037f896
--- /dev/null
+++ b/Tools/cases_generator/stacking.py
@@ -0,0 +1,400 @@
+import dataclasses
+import typing
+
+from formatting import (
+ Formatter,
+ UNUSED,
+ maybe_parenthesize,
+ parenthesize_cond,
+)
+from instructions import (
+ ActiveCacheEffect,
+ Instruction,
+ MacroInstruction,
+ Component,
+ Tiers,
+ TIER_ONE,
+)
+from parsing import StackEffect, CacheEffect, Family
+
+
+ at dataclasses.dataclass
+class StackOffset:
+ """Represent the stack offset for a PEEK or POKE.
+
+ - At stack_pointer[0], deep and high are both empty.
+ (Note that that is an invalid stack reference.)
+ - Below stack top, only deep is non-empty.
+ - Above stack top, only high is non-empty.
+ - In complex cases, both deep and high may be non-empty.
+
+ All this would be much simpler if all stack entries were the same
+ size, but with conditional and array effects, they aren't.
+ The offsets are each represented by a list of StackEffect objects.
+ The name in the StackEffects is unused.
+ """
+
+ deep: list[StackEffect] = dataclasses.field(default_factory=list)
+ high: list[StackEffect] = dataclasses.field(default_factory=list)
+
+ def clone(self) -> "StackOffset":
+ return StackOffset(list(self.deep), list(self.high))
+
+ def negate(self) -> "StackOffset":
+ return StackOffset(list(self.high), list(self.deep))
+
+ def deeper(self, eff: StackEffect) -> None:
+ if eff in self.high:
+ self.high.remove(eff)
+ else:
+ self.deep.append(eff)
+
+ def higher(self, eff: StackEffect) -> None:
+ if eff in self.deep:
+ self.deep.remove(eff)
+ else:
+ self.high.append(eff)
+
+ def as_terms(self) -> list[tuple[str, str]]:
+ num = 0
+ terms: list[tuple[str, str]] = []
+ for eff in self.deep:
+ if eff.size:
+ terms.append(("-", maybe_parenthesize(eff.size)))
+ elif eff.cond and eff.cond != "1":
+ terms.append(("-", f"({parenthesize_cond(eff.cond)} ? 1 : 0)"))
+ elif eff.cond != "0":
+ num -= 1
+ for eff in self.high:
+ if eff.size:
+ terms.append(("+", maybe_parenthesize(eff.size)))
+ elif eff.cond and eff.cond != "1":
+ terms.append(("+", f"({parenthesize_cond(eff.cond)} ? 1 : 0)"))
+ elif eff.cond != "0":
+ num += 1
+ if num < 0:
+ terms.insert(0, ("-", str(-num)))
+ elif num > 0:
+ terms.append(("+", str(num)))
+ return terms
+
+ def as_index(self) -> str:
+ terms = self.as_terms()
+ return make_index(terms)
+
+
+def make_index(terms: list[tuple[str, str]]) -> str:
+ # Produce an index expression from the terms honoring PEP 8,
+ # surrounding binary ops with spaces but not unary minus
+ index = ""
+ for sign, term in terms:
+ if index:
+ index += f" {sign} {term}"
+ elif sign == "+":
+ index = term
+ else:
+ index = sign + term
+ return index or "0"
+
+
+ at dataclasses.dataclass
+class StackItem:
+ offset: StackOffset
+ effect: StackEffect
+
+ def as_variable(self, lax: bool = False) -> str:
+ """Return e.g. stack_pointer[-1]."""
+ terms = self.offset.as_terms()
+ if self.effect.size:
+ terms.insert(0, ("+", "stack_pointer"))
+ index = make_index(terms)
+ if self.effect.size:
+ res = index
+ else:
+ res = f"stack_pointer[{index}]"
+ if not lax:
+ # Check that we're not reading or writing above stack top.
+ # Skip this for output variable initialization (lax=True).
+ assert (
+ self.effect in self.offset.deep and not self.offset.high
+ ), f"Push or pop above current stack level: {res}"
+ return res
+
+
+ at dataclasses.dataclass
+class CopyEffect:
+ src: StackEffect
+ dst: StackEffect
+
+
+class EffectManager:
+ """Manage stack effects and offsets for an instruction."""
+
+ instr: Instruction
+ active_caches: list[ActiveCacheEffect]
+ peeks: list[StackItem]
+ pokes: list[StackItem]
+ copies: list[CopyEffect] # See merge()
+ # Track offsets from stack pointer
+ min_offset: StackOffset
+ final_offset: StackOffset
+
+ def __init__(
+ self,
+ instr: Instruction,
+ active_caches: list[ActiveCacheEffect],
+ pred: "EffectManager | None" = None,
+ ):
+ self.instr = instr
+ self.active_caches = active_caches
+ self.peeks = []
+ self.pokes = []
+ self.copies = []
+ self.final_offset = pred.final_offset.clone() if pred else StackOffset()
+ for eff in reversed(instr.input_effects):
+ self.final_offset.deeper(eff)
+ self.peeks.append(StackItem(offset=self.final_offset.clone(), effect=eff))
+ self.min_offset = self.final_offset.clone()
+ for eff in instr.output_effects:
+ self.pokes.append(StackItem(offset=self.final_offset.clone(), effect=eff))
+ self.final_offset.higher(eff)
+
+ if pred:
+ # Replace push(x) + pop(y) with copy(x, y).
+ # Check that the sources and destinations are disjoint.
+ sources: set[str] = set()
+ destinations: set[str] = set()
+ while (
+ pred.pokes
+ and self.peeks
+ and pred.pokes[-1].effect == self.peeks[-1].effect
+ ):
+ src = pred.pokes.pop(-1).effect
+ dst = self.peeks.pop(0).effect
+ pred.final_offset.deeper(src)
+ if dst.name != UNUSED:
+ destinations.add(dst.name)
+ if dst.name != src.name:
+ sources.add(src.name)
+ self.copies.append(CopyEffect(src, dst))
+ # TODO: Turn this into an error (pass an Analyzer instance?)
+ assert sources & destinations == set(), (
+ pred.instr.name,
+ self.instr.name,
+ sources,
+ destinations,
+ )
+
+ def adjust_deeper(self, eff: StackEffect) -> None:
+ for peek in self.peeks:
+ peek.offset.deeper(eff)
+ for poke in self.pokes:
+ poke.offset.deeper(eff)
+ self.min_offset.deeper(eff)
+ self.final_offset.deeper(eff)
+
+ def adjust_higher(self, eff: StackEffect) -> None:
+ for peek in self.peeks:
+ peek.offset.higher(eff)
+ for poke in self.pokes:
+ poke.offset.higher(eff)
+ self.min_offset.higher(eff)
+ self.final_offset.higher(eff)
+
+ def adjust(self, offset: StackOffset) -> None:
+ for down in offset.deep:
+ self.adjust_deeper(down)
+ for up in offset.high:
+ self.adjust_higher(up)
+
+ def adjust_inverse(self, offset: StackOffset) -> None:
+ for down in offset.deep:
+ self.adjust_higher(down)
+ for up in offset.high:
+ self.adjust_deeper(up)
+
+ def collect_vars(self) -> dict[str, StackEffect]:
+ """Collect all variables, skipping unused ones."""
+ vars: dict[str, StackEffect] = {}
+
+ def add(eff: StackEffect) -> None:
+ if eff.name != UNUSED:
+ if eff.name in vars:
+ # TODO: Make this an error
+ assert vars[eff.name] == eff, (
+ self.instr.name,
+ eff.name,
+ vars[eff.name],
+ eff,
+ )
+ else:
+ vars[eff.name] = eff
+
+ for copy in self.copies:
+ add(copy.src)
+ add(copy.dst)
+ for peek in self.peeks:
+ add(peek.effect)
+ for poke in self.pokes:
+ add(poke.effect)
+
+ return vars
+
+
+def less_than(a: StackOffset, b: StackOffset) -> bool:
+ # TODO: Handle more cases
+ if a.high != b.high:
+ return False
+ return a.deep[: len(b.deep)] == b.deep
+
+
+def get_managers(parts: list[Component]) -> list[EffectManager]:
+ managers: list[EffectManager] = []
+ pred: EffectManager | None = None
+ for part in parts:
+ mgr = EffectManager(part.instr, part.active_caches, pred)
+ managers.append(mgr)
+ pred = mgr
+ return managers
+
+
+def get_stack_effect_info_for_macro(mac: MacroInstruction) -> tuple[str, str]:
+ """Get the stack effect info for a macro instruction.
+
+ Returns a tuple (popped, pushed) where each is a string giving a
+ symbolic expression for the number of values popped/pushed.
+ """
+ parts = [part for part in mac.parts if isinstance(part, Component)]
+ managers = get_managers(parts)
+ popped = StackOffset()
+ for mgr in managers:
+ if less_than(mgr.min_offset, popped):
+ popped = mgr.min_offset.clone()
+ # Compute pushed = final - popped
+ pushed = managers[-1].final_offset.clone()
+ for effect in popped.deep:
+ pushed.higher(effect)
+ for effect in popped.high:
+ pushed.deeper(effect)
+ return popped.negate().as_index(), pushed.as_index()
+
+
+def write_single_instr(
+ instr: Instruction, out: Formatter, tier: Tiers = TIER_ONE
+) -> None:
+ try:
+ write_components(
+ [Component(instr, instr.active_caches)],
+ out,
+ tier,
+ )
+ except AssertionError as err:
+ raise AssertionError(f"Error writing instruction {instr.name}") from err
+
+
+def write_macro_instr(
+ mac: MacroInstruction, out: Formatter, family: Family | None
+) -> None:
+ parts = [part for part in mac.parts if isinstance(part, Component)]
+
+ cache_adjust = 0
+ for part in mac.parts:
+ match part:
+ case CacheEffect(size=size):
+ cache_adjust += size
+ case Component(instr=instr):
+ cache_adjust += instr.cache_offset
+ case _:
+ typing.assert_never(part)
+
+ out.emit("")
+ with out.block(f"TARGET({mac.name})"):
+ if mac.predicted:
+ out.emit(f"PREDICTED({mac.name});")
+ out.static_assert_family_size(mac.name, family, cache_adjust)
+ try:
+ write_components(parts, out, TIER_ONE)
+ except AssertionError as err:
+ raise AssertionError(f"Error writing macro {mac.name}") from err
+ if cache_adjust:
+ out.emit(f"next_instr += {cache_adjust};")
+ out.emit("DISPATCH();")
+
+
+def write_components(
+ parts: list[Component],
+ out: Formatter,
+ tier: Tiers,
+) -> None:
+ managers = get_managers(parts)
+
+ all_vars: dict[str, StackEffect] = {}
+ for mgr in managers:
+ for name, eff in mgr.collect_vars().items():
+ if name in all_vars:
+ # TODO: Turn this into an error -- variable conflict
+ assert all_vars[name] == eff, (
+ name,
+ mgr.instr.name,
+ all_vars[name],
+ eff,
+ )
+ else:
+ all_vars[name] = eff
+
+ # Declare all variables
+ for name, eff in all_vars.items():
+ out.declare(eff, None)
+
+ for mgr in managers:
+ if len(parts) > 1:
+ out.emit(f"// {mgr.instr.name}")
+
+ for copy in mgr.copies:
+ if copy.src.name != copy.dst.name:
+ out.assign(copy.dst, copy.src)
+ for peek in mgr.peeks:
+ out.assign(
+ peek.effect,
+ StackEffect(
+ peek.as_variable(),
+ peek.effect.type,
+ peek.effect.cond,
+ peek.effect.size,
+ ),
+ )
+ # Initialize array outputs
+ for poke in mgr.pokes:
+ if poke.effect.size and poke.effect.name not in mgr.instr.unmoved_names:
+ out.assign(
+ poke.effect,
+ StackEffect(
+ poke.as_variable(lax=True),
+ poke.effect.type,
+ poke.effect.cond,
+ poke.effect.size,
+ ),
+ )
+
+ if len(parts) == 1:
+ mgr.instr.write_body(out, 0, mgr.active_caches, tier)
+ else:
+ with out.block(""):
+ mgr.instr.write_body(out, -4, mgr.active_caches, tier)
+
+ if mgr is managers[-1]:
+ out.stack_adjust(mgr.final_offset.deep, mgr.final_offset.high)
+ # Use clone() since adjust_inverse() mutates final_offset
+ mgr.adjust_inverse(mgr.final_offset.clone())
+
+ for poke in mgr.pokes:
+ if not poke.effect.size and poke.effect.name not in mgr.instr.unmoved_names:
+ out.assign(
+ StackEffect(
+ poke.as_variable(),
+ poke.effect.type,
+ poke.effect.cond,
+ poke.effect.size,
+ ),
+ poke.effect,
+ )
More information about the Python-checkins
mailing list