GH-131498: Remove conditional stack effects (GH-131499)

* Adds some missing #includes
This commit is contained in:
Mark Shannon 2025-03-20 15:39:38 +00:00 committed by GitHub
parent 443c0cd17c
commit 7ebd71ee14
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 129 additions and 272 deletions

View file

@ -59,7 +59,6 @@
#define guard
#define override
#define specializing
#define split
#define replicate(TIMES)
#define tier1
#define no_save_ip
@ -1686,8 +1685,10 @@ dummy_func(
ERROR_IF(PyStackRef_IsNull(*res), error);
}
op(_PUSH_NULL_CONDITIONAL, ( -- null if (oparg & 1))) {
null = PyStackRef_NULL;
op(_PUSH_NULL_CONDITIONAL, ( -- null[oparg & 1])) {
if (oparg & 1) {
null[0] = PyStackRef_NULL;
}
}
macro(LOAD_GLOBAL) =

View file

@ -2285,10 +2285,12 @@
}
case _PUSH_NULL_CONDITIONAL: {
_PyStackRef null = PyStackRef_NULL;
_PyStackRef *null;
oparg = CURRENT_OPARG();
null = PyStackRef_NULL;
if (oparg & 1) stack_pointer[0] = null;
null = &stack_pointer[0];
if (oparg & 1) {
null[0] = PyStackRef_NULL;
}
stack_pointer += (oparg & 1);
assert(WITHIN_STACK_BOUNDS());
break;

View file

@ -6982,7 +6982,7 @@
_PyStackRef class_st;
_PyStackRef self_st;
_PyStackRef attr;
_PyStackRef null = PyStackRef_NULL;
_PyStackRef *null;
/* Skip 1 cache entry */
// _LOAD_SUPER_ATTR
{
@ -7078,10 +7078,12 @@
}
// _PUSH_NULL_CONDITIONAL
{
null = PyStackRef_NULL;
null = &stack_pointer[1];
if (oparg & 1) {
null[0] = PyStackRef_NULL;
}
}
stack_pointer[0] = attr;
if (oparg & 1) stack_pointer[1] = null;
stack_pointer += 1 + (oparg & 1);
assert(WITHIN_STACK_BOUNDS());
DISPATCH();
@ -7840,7 +7842,7 @@
static_assert(INLINE_CACHE_ENTRIES_LOAD_ATTR == 9, "incorrect cache size");
_PyStackRef owner;
_PyStackRef attr;
_PyStackRef null = PyStackRef_NULL;
_PyStackRef *null;
/* Skip 1 cache entry */
// _CHECK_ATTR_CLASS
{
@ -7876,9 +7878,11 @@
}
// _PUSH_NULL_CONDITIONAL
{
null = PyStackRef_NULL;
null = &stack_pointer[0];
if (oparg & 1) {
null[0] = PyStackRef_NULL;
}
}
if (oparg & 1) stack_pointer[0] = null;
stack_pointer += (oparg & 1);
assert(WITHIN_STACK_BOUNDS());
DISPATCH();
@ -7897,7 +7901,7 @@
static_assert(INLINE_CACHE_ENTRIES_LOAD_ATTR == 9, "incorrect cache size");
_PyStackRef owner;
_PyStackRef attr;
_PyStackRef null = PyStackRef_NULL;
_PyStackRef *null;
/* Skip 1 cache entry */
// _CHECK_ATTR_CLASS
{
@ -7943,9 +7947,11 @@
}
// _PUSH_NULL_CONDITIONAL
{
null = PyStackRef_NULL;
null = &stack_pointer[0];
if (oparg & 1) {
null[0] = PyStackRef_NULL;
}
}
if (oparg & 1) stack_pointer[0] = null;
stack_pointer += (oparg & 1);
assert(WITHIN_STACK_BOUNDS());
DISPATCH();
@ -8022,7 +8028,7 @@
static_assert(INLINE_CACHE_ENTRIES_LOAD_ATTR == 9, "incorrect cache size");
_PyStackRef owner;
_PyStackRef attr;
_PyStackRef null = PyStackRef_NULL;
_PyStackRef *null;
/* Skip 1 cache entry */
// _GUARD_TYPE_VERSION
{
@ -8078,9 +8084,11 @@
/* Skip 5 cache entries */
// _PUSH_NULL_CONDITIONAL
{
null = PyStackRef_NULL;
null = &stack_pointer[0];
if (oparg & 1) {
null[0] = PyStackRef_NULL;
}
}
if (oparg & 1) stack_pointer[0] = null;
stack_pointer += (oparg & 1);
assert(WITHIN_STACK_BOUNDS());
DISPATCH();
@ -8270,7 +8278,7 @@
static_assert(INLINE_CACHE_ENTRIES_LOAD_ATTR == 9, "incorrect cache size");
_PyStackRef owner;
_PyStackRef attr;
_PyStackRef null = PyStackRef_NULL;
_PyStackRef *null;
/* Skip 1 cache entry */
// _LOAD_ATTR_MODULE
{
@ -8321,9 +8329,11 @@
/* Skip 5 cache entries */
// _PUSH_NULL_CONDITIONAL
{
null = PyStackRef_NULL;
null = &stack_pointer[0];
if (oparg & 1) {
null[0] = PyStackRef_NULL;
}
}
if (oparg & 1) stack_pointer[0] = null;
stack_pointer += (oparg & 1);
assert(WITHIN_STACK_BOUNDS());
DISPATCH();
@ -8552,7 +8562,7 @@
static_assert(INLINE_CACHE_ENTRIES_LOAD_ATTR == 9, "incorrect cache size");
_PyStackRef owner;
_PyStackRef attr;
_PyStackRef null = PyStackRef_NULL;
_PyStackRef *null;
/* Skip 1 cache entry */
// _GUARD_TYPE_VERSION
{
@ -8599,9 +8609,11 @@
/* Skip 5 cache entries */
// _PUSH_NULL_CONDITIONAL
{
null = PyStackRef_NULL;
null = &stack_pointer[0];
if (oparg & 1) {
null[0] = PyStackRef_NULL;
}
}
if (oparg & 1) stack_pointer[0] = null;
stack_pointer += (oparg & 1);
assert(WITHIN_STACK_BOUNDS());
DISPATCH();
@ -8620,7 +8632,7 @@
static_assert(INLINE_CACHE_ENTRIES_LOAD_ATTR == 9, "incorrect cache size");
_PyStackRef owner;
_PyStackRef attr;
_PyStackRef null = PyStackRef_NULL;
_PyStackRef *null;
/* Skip 1 cache entry */
// _GUARD_TYPE_VERSION
{
@ -8700,9 +8712,11 @@
/* Skip 5 cache entries */
// _PUSH_NULL_CONDITIONAL
{
null = PyStackRef_NULL;
null = &stack_pointer[0];
if (oparg & 1) {
null[0] = PyStackRef_NULL;
}
}
if (oparg & 1) stack_pointer[0] = null;
stack_pointer += (oparg & 1);
assert(WITHIN_STACK_BOUNDS());
DISPATCH();
@ -9080,7 +9094,7 @@
_Py_CODEUNIT* const this_instr = next_instr - 5;
(void)this_instr;
_PyStackRef *res;
_PyStackRef null = PyStackRef_NULL;
_PyStackRef *null;
// _SPECIALIZE_LOAD_GLOBAL
{
uint16_t counter = read_u16(&this_instr[1].cache);
@ -9114,9 +9128,11 @@
}
// _PUSH_NULL_CONDITIONAL
{
null = PyStackRef_NULL;
null = &stack_pointer[1];
if (oparg & 1) {
null[0] = PyStackRef_NULL;
}
}
if (oparg & 1) stack_pointer[1] = null;
stack_pointer += 1 + (oparg & 1);
assert(WITHIN_STACK_BOUNDS());
DISPATCH();
@ -9134,7 +9150,7 @@
INSTRUCTION_STATS(LOAD_GLOBAL_BUILTIN);
static_assert(INLINE_CACHE_ENTRIES_LOAD_GLOBAL == 4, "incorrect cache size");
_PyStackRef res;
_PyStackRef null = PyStackRef_NULL;
_PyStackRef *null;
/* Skip 1 cache entry */
// _GUARD_GLOBALS_VERSION
{
@ -9191,10 +9207,12 @@
}
// _PUSH_NULL_CONDITIONAL
{
null = PyStackRef_NULL;
null = &stack_pointer[1];
if (oparg & 1) {
null[0] = PyStackRef_NULL;
}
}
stack_pointer[0] = res;
if (oparg & 1) stack_pointer[1] = null;
stack_pointer += 1 + (oparg & 1);
assert(WITHIN_STACK_BOUNDS());
DISPATCH();
@ -9212,7 +9230,7 @@
INSTRUCTION_STATS(LOAD_GLOBAL_MODULE);
static_assert(INLINE_CACHE_ENTRIES_LOAD_GLOBAL == 4, "incorrect cache size");
_PyStackRef res;
_PyStackRef null = PyStackRef_NULL;
_PyStackRef *null;
/* Skip 1 cache entry */
// _NOP
{
@ -9256,10 +9274,12 @@
}
// _PUSH_NULL_CONDITIONAL
{
null = PyStackRef_NULL;
null = &stack_pointer[1];
if (oparg & 1) {
null[0] = PyStackRef_NULL;
}
}
stack_pointer[0] = res;
if (oparg & 1) stack_pointer[1] = null;
stack_pointer += 1 + (oparg & 1);
assert(WITHIN_STACK_BOUNDS());
DISPATCH();
@ -9387,7 +9407,7 @@
_PyStackRef class_st;
_PyStackRef self_st;
_PyStackRef attr;
_PyStackRef null = PyStackRef_NULL;
_PyStackRef *null;
// _SPECIALIZE_LOAD_SUPER_ATTR
{
class_st = stack_pointer[-2];
@ -9499,10 +9519,12 @@
}
// _PUSH_NULL_CONDITIONAL
{
null = PyStackRef_NULL;
null = &stack_pointer[1];
if (oparg & 1) {
null[0] = PyStackRef_NULL;
}
}
stack_pointer[0] = attr;
if (oparg & 1) stack_pointer[1] = null;
stack_pointer += 1 + (oparg & 1);
assert(WITHIN_STACK_BOUNDS());
DISPATCH();

View file

@ -8,7 +8,11 @@
#include "pycore_ceval.h"
#include "pycore_critical_section.h"
#include "pycore_dict.h"
#include "pycore_floatobject.h"
#include "pycore_frame.h"
#include "pycore_interpframe.h"
#include "pycore_intrinsics.h"
#include "pycore_list.h"
#include "pycore_long.h"
#include "pycore_opcode_metadata.h"
#include "pycore_opcode_utils.h"
@ -16,6 +20,9 @@
#include "pycore_pyerrors.h"
#include "pycore_setobject.h"
#include "pycore_sliceobject.h"
#include "pycore_tuple.h"
#include "pycore_unicodeobject.h"
#include "pycore_jit.h"
// Memory management stuff: ////////////////////////////////////////////////////

View file

@ -6,11 +6,15 @@
#include "pycore_interp.h"
#include "pycore_backoff.h"
#include "pycore_bitutils.h" // _Py_popcount32()
#include "pycore_code.h" // _Py_GetBaseCodeUnit
#include "pycore_interpframe.h"
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
#include "pycore_opcode_metadata.h" // _PyOpcode_OpName[]
#include "pycore_opcode_utils.h" // MAX_REAL_OPCODE
#include "pycore_optimizer.h" // _Py_uop_analyze_and_optimize()
#include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_tuple.h" // _PyTuple_FromArraySteal
#include "pycore_unicodeobject.h" // _PyUnicode_FromASCII
#include "pycore_uop_ids.h"
#include "pycore_jit.h"
#include <stdbool.h>
@ -1226,11 +1230,7 @@ uop_optimize(
for (int pc = 0; pc < length; pc++) {
int opcode = buffer[pc].opcode;
int oparg = buffer[pc].oparg;
if (_PyUop_Flags[opcode] & HAS_OPARG_AND_1_FLAG) {
buffer[pc].opcode = opcode + 1 + (oparg & 1);
assert(strncmp(_PyOpcode_uop_name[buffer[pc].opcode], _PyOpcode_uop_name[opcode], strlen(_PyOpcode_uop_name[opcode])) == 0);
}
else if (oparg < _PyUop_Replication[opcode]) {
if (oparg < _PyUop_Replication[opcode]) {
buffer[pc].opcode = opcode + oparg + 1;
assert(strncmp(_PyOpcode_uop_name[buffer[pc].opcode], _PyOpcode_uop_name[opcode], strlen(_PyOpcode_uop_name[opcode])) == 0);
}

View file

@ -21,6 +21,7 @@
#include "pycore_uop_metadata.h"
#include "pycore_dict.h"
#include "pycore_long.h"
#include "pycore_interpframe.h" // _PyFrame_GetCode
#include "pycore_optimizer.h"
#include "pycore_object.h"
#include "pycore_dict.h"

View file

@ -546,10 +546,14 @@ dummy_func(void) {
}
}
op (_PUSH_NULL_CONDITIONAL, ( -- null if (oparg & 1))) {
int opcode = (oparg & 1) ? _PUSH_NULL : _NOP;
REPLACE_OP(this_instr, opcode, 0, 0);
null = sym_new_null(ctx);
op (_PUSH_NULL_CONDITIONAL, ( -- null[oparg & 1])) {
if (oparg & 1) {
REPLACE_OP(this_instr, _PUSH_NULL, 0, 0);
null[0] = sym_new_null(ctx);
}
else {
REPLACE_OP(this_instr, _NOP, 0, 0);
}
}
op(_LOAD_ATTR, (owner -- attr, self_or_null[oparg&1])) {
@ -765,7 +769,7 @@ dummy_func(void) {
Py_UNREACHABLE();
}
op(_PUSH_FRAME, (new_frame: _Py_UOpsAbstractFrame * -- unused if (0))) {
op(_PUSH_FRAME, (new_frame: _Py_UOpsAbstractFrame * -- )) {
SYNC_SP();
ctx->frame->stack_pointer = stack_pointer;
ctx->frame = new_frame;

View file

@ -921,11 +921,15 @@
}
case _PUSH_NULL_CONDITIONAL: {
JitOptSymbol *null = NULL;
int opcode = (oparg & 1) ? _PUSH_NULL : _NOP;
REPLACE_OP(this_instr, opcode, 0, 0);
null = sym_new_null(ctx);
if (oparg & 1) stack_pointer[0] = null;
JitOptSymbol **null;
null = &stack_pointer[0];
if (oparg & 1) {
REPLACE_OP(this_instr, _PUSH_NULL, 0, 0);
null[0] = sym_new_null(ctx);
}
else {
REPLACE_OP(this_instr, _NOP, 0, 0);
}
stack_pointer += (oparg & 1);
assert(WITHIN_STACK_BOUNDS());
break;

View file

@ -6,6 +6,7 @@
#include "pycore_frame.h"
#include "pycore_long.h"
#include "pycore_optimizer.h"
#include "pycore_stats.h"
#include "pycore_tuple.h" // _PyTuple_FromArray()
#include <stdbool.h>

View file

@ -18,6 +18,7 @@
#include "pycore_long.h" // _PyLong_InitTypes()
#include "pycore_object.h" // _PyDebug_PrintTotalRefs()
#include "pycore_obmalloc.h" // _PyMem_init_obmalloc()
#include "pycore_optimizer.h" // _Py_Executors_InvalidateAll
#include "pycore_pathconfig.h" // _PyPathConfig_UpdateGlobal()
#include "pycore_pyerrors.h" // _PyErr_Occurred()
#include "pycore_pylifecycle.h" // _PyErr_Print()