8000 GH-131498: Another refactoring of the code generator by markshannon · Pull Request #131827 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-131498: Another refactoring of the code generator #131827

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Convert in_memory from boolean to stack offset
  • Loading branch information
markshannon committed Mar 25, 2025
commit 6e2a1891a22f801e78302c267a05198887a261c5
29 changes: 28 additions & 1 deletion Lib/test/test_generated_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,11 @@ def test_overlap(self):
def test_predictions(self):
input = """
inst(OP1, (arg -- res)) {
DEAD(arg);
res = Py_None;
}
inst(OP3, (arg -- res)) {
DEAD(arg);
DEOPT_IF(xxx);
res = Py_None;
}
Expand All @@ -303,7 +305,9 @@ def test_predictions(self):
next_instr += 1;
INSTRUCTION_STATS(OP1);
PREDICTED_OP1:;
_PyStackRef arg;
_PyStackRef res;
arg = stack_pointer[-1];
res = Py_None;
stack_pointer[-1] = res;
DISPATCH();
Expand All < 8000 /td> @@ -320,7 +324,9 @@ def test_predictions(self):
next_instr += 1;
INSTRUCTION_STATS(OP3);
static_assert(INLINE_CACHE_ENTRIES_OP1 == 0, "incorrect cache size");
_PyStackRef arg;
_PyStackRef res;
arg = stack_pointer[-1];
if (xxx) {
UPDATE_MISS_STATS(OP1);
assert(_PyOpcode_Deopt[opcode] == (OP1));
Expand All @@ -336,11 +342,13 @@ def test_predictions(self):
def test_sync_sp(self):
input = """
inst(A, (arg -- res)) {
DEAD(arg);
SYNC_SP();
escaping_call();
res = Py_None;
}
inst(B, (arg -- res)) {
DEAD(arg);
res = Py_None;
SYNC_SP();
escaping_call();
Expand All @@ -355,7 +363,9 @@ def test_sync_sp(self):
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(A);
_PyStackRef arg;
_PyStackRef res;
arg = stack_pointer[-1];
stack_pointer += -1;
assert(WITHIN_STACK_BOUNDS());
_PyFrame_SetStackPointer(frame, stack_pointer);
Expand All @@ -376,7 +386,9 @@ def test_sync_sp(self):
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(B);
_PyStackRef arg;
_PyStackRef res;
arg = stack_pointer[-1];
res = Py_None;
stack_pointer[-1] = res;
_PyFrame_SetStackPointer(frame, stack_pointer);
Expand Down Expand Up @@ -522,6 +534,7 @@ def test_error_if_pop_with_result(self):
def test_cache_effect(self):
input = """
inst(OP, (counter/1, extra/2, value --)) {
DEAD(value);
}
"""
output = """
Expand All @@ -535,6 +548,8 @@ def test_cache_effect(self):
frame->instr_ptr = next_instr;
next_instr += 4;
INSTRUCTION_STATS(OP);
_PyStackRef value;
value = stack_pointer[-1];
uint16_t counter = read_u16(&this_instr[1].cache);
(void)counter;
uint32_t extra = read_u32(&this_instr[2].cache);
Expand Down Expand Up @@ -793,7 +808,9 @@ def test_array_input(self):
input = """
inst(OP, (below, values[oparg*2], above --)) {
SPAM(values, oparg);
DEAD(below);
DEAD(values);
DEAD(above);
}
"""
output = """
Expand All @@ -805,8 +822,12 @@ def test_array_input(self):
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP);
_PyStackRef below;
_PyStackRef *values;
_PyStackRef above;
above = stack_pointer[-1];
values = &stack_pointer[-1 - oparg*2];
below = stack_pointer[-2 - oparg*2];
SPAM(values, oparg);
stack_pointer += -2 - oparg*2;
assert(WITHIN_STACK_BOUNDS());
Expand Down Expand Up @@ -880,6 +901,8 @@ def test_array_input_output(self):
def test_array_error_if(self):
input = """
inst(OP, (extra, values[oparg] --)) {
DEAD(extra);
DEAD(values);
ERROR_IF(oparg == 0, somewhere);
}
"""
Expand All @@ -892,6 +915,10 @@ def test_array_error_if(self):
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP);
_PyStackRef extra;
_PyStackRef *values;
values = &stack_pointer[-oparg];
extra = stack_pointer[-1 - oparg];
if (oparg == 0) {
stack_pointer += -1 - oparg;
assert(WITHIN_STACK_BOUNDS());
Expand Down Expand Up @@ -1223,7 +1250,7 @@ def test_unused_used_used(self):
}
// THIRD
{
y = x;
y = stack_pointer[-1];
USE(y);
}
DISPATCH();
Expand Down
8 changes: 4 additions & 4 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3986,10 +3986,10 @@ dummy_func(
assert(_PyFrame_GetBytecode(shim)[1].op.code == RETURN_VALUE);
/* Push self onto stack of shim */
shim->localsplus[0] = PyStackRef_DUP(self[0]);
DEAD(init);
DEAD(self);
_PyInterpreterFrame *temp = _PyEvalFramePushAndInit(
tstate, init[0], NULL, args-1, oparg+1, NULL, shim);
DEAD(init);
DEAD(self);
DEAD(args);
SYNC_SP();
if (temp == NULL) {
Expand Down Expand Up @@ -4192,9 +4192,9 @@ dummy_func(
res = PyStackRef_FromPyObjectSteal(res_o);
}

inst(CALL_ISINSTANCE, (unused/1, unused/2, callable[1], self_or_null[1], args[oparg] -- res)) {
inst(CALL_ISINSTANCE, (unused/1, unused/2, callable, self_or_null[1], args[oparg] -- res)) {
/* isinstance(o, o2) */
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable[0]);
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable);

int total_args = oparg;
_PyStackRef *arguments = args;
Expand Down
56 changes: 22 additions & 34 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
0