mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
GH-115816: Assorted naming and formatting changes to improve maintainability. (GH-115987)
* Rename _Py_UOpsAbstractInterpContext to _Py_UOpsContext and _Py_UOpsSymType to _Py_UopsSymbol. * #define shortened form of _Py_uop_... names for improved readability.
This commit is contained in:
parent
10fbcd6c5d
commit
6ecfcfe894
8 changed files with 495 additions and 473 deletions
|
@ -28,7 +28,7 @@ extern PyTypeObject _PyUOpOptimizer_Type;
|
||||||
|
|
||||||
/* Symbols */
|
/* Symbols */
|
||||||
|
|
||||||
struct _Py_UOpsSymType {
|
struct _Py_UopsSymbol {
|
||||||
int flags;
|
int flags;
|
||||||
PyTypeObject *typ;
|
PyTypeObject *typ;
|
||||||
// constant propagated value (might be NULL)
|
// constant propagated value (might be NULL)
|
||||||
|
@ -38,23 +38,21 @@ struct _Py_UOpsSymType {
|
||||||
// Holds locals, stack, locals, stack ... co_consts (in that order)
|
// Holds locals, stack, locals, stack ... co_consts (in that order)
|
||||||
#define MAX_ABSTRACT_INTERP_SIZE 4096
|
#define MAX_ABSTRACT_INTERP_SIZE 4096
|
||||||
|
|
||||||
#define OVERALLOCATE_FACTOR 5
|
#define TY_ARENA_SIZE (UOP_MAX_TRACE_LENGTH * 5)
|
||||||
|
|
||||||
#define TY_ARENA_SIZE (UOP_MAX_TRACE_LENGTH * OVERALLOCATE_FACTOR)
|
|
||||||
|
|
||||||
// Need extras for root frame and for overflow frame (see TRACE_STACK_PUSH())
|
// Need extras for root frame and for overflow frame (see TRACE_STACK_PUSH())
|
||||||
#define MAX_ABSTRACT_FRAME_DEPTH (TRACE_STACK_SIZE + 2)
|
#define MAX_ABSTRACT_FRAME_DEPTH (TRACE_STACK_SIZE + 2)
|
||||||
|
|
||||||
typedef struct _Py_UOpsSymType _Py_UOpsSymType;
|
typedef struct _Py_UopsSymbol _Py_UopsSymbol;
|
||||||
|
|
||||||
struct _Py_UOpsAbstractFrame {
|
struct _Py_UOpsAbstractFrame {
|
||||||
// Max stacklen
|
// Max stacklen
|
||||||
int stack_len;
|
int stack_len;
|
||||||
int locals_len;
|
int locals_len;
|
||||||
|
|
||||||
_Py_UOpsSymType **stack_pointer;
|
_Py_UopsSymbol **stack_pointer;
|
||||||
_Py_UOpsSymType **stack;
|
_Py_UopsSymbol **stack;
|
||||||
_Py_UOpsSymType **locals;
|
_Py_UopsSymbol **locals;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame;
|
typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame;
|
||||||
|
@ -62,10 +60,10 @@ typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame;
|
||||||
typedef struct ty_arena {
|
typedef struct ty_arena {
|
||||||
int ty_curr_number;
|
int ty_curr_number;
|
||||||
int ty_max_number;
|
int ty_max_number;
|
||||||
_Py_UOpsSymType arena[TY_ARENA_SIZE];
|
_Py_UopsSymbol arena[TY_ARENA_SIZE];
|
||||||
} ty_arena;
|
} ty_arena;
|
||||||
|
|
||||||
struct _Py_UOpsAbstractInterpContext {
|
struct _Py_UOpsContext {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
// The current "executing" frame.
|
// The current "executing" frame.
|
||||||
_Py_UOpsAbstractFrame *frame;
|
_Py_UOpsAbstractFrame *frame;
|
||||||
|
@ -75,40 +73,39 @@ struct _Py_UOpsAbstractInterpContext {
|
||||||
// Arena for the symbolic types.
|
// Arena for the symbolic types.
|
||||||
ty_arena t_arena;
|
ty_arena t_arena;
|
||||||
|
|
||||||
_Py_UOpsSymType **n_consumed;
|
_Py_UopsSymbol **n_consumed;
|
||||||
_Py_UOpsSymType **limit;
|
_Py_UopsSymbol **limit;
|
||||||
_Py_UOpsSymType *locals_and_stack[MAX_ABSTRACT_INTERP_SIZE];
|
_Py_UopsSymbol *locals_and_stack[MAX_ABSTRACT_INTERP_SIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _Py_UOpsAbstractInterpContext _Py_UOpsAbstractInterpContext;
|
typedef struct _Py_UOpsContext _Py_UOpsContext;
|
||||||
|
|
||||||
extern bool _Py_uop_sym_is_null(_Py_UOpsSymType *sym);
|
extern bool _Py_uop_sym_is_null(_Py_UopsSymbol *sym);
|
||||||
extern bool _Py_uop_sym_is_not_null(_Py_UOpsSymType *sym);
|
extern bool _Py_uop_sym_is_not_null(_Py_UopsSymbol *sym);
|
||||||
extern bool _Py_uop_sym_is_const(_Py_UOpsSymType *sym);
|
extern bool _Py_uop_sym_is_const(_Py_UopsSymbol *sym);
|
||||||
extern PyObject *_Py_uop_sym_get_const(_Py_UOpsSymType *sym);
|
extern PyObject *_Py_uop_sym_get_const(_Py_UopsSymbol *sym);
|
||||||
extern _Py_UOpsSymType *_Py_uop_sym_new_unknown(_Py_UOpsAbstractInterpContext *ctx);
|
extern _Py_UopsSymbol *_Py_uop_sym_new_unknown(_Py_UOpsContext *ctx);
|
||||||
extern _Py_UOpsSymType *_Py_uop_sym_new_not_null(_Py_UOpsAbstractInterpContext *ctx);
|
extern _Py_UopsSymbol *_Py_uop_sym_new_not_null(_Py_UOpsContext *ctx);
|
||||||
extern _Py_UOpsSymType *_Py_uop_sym_new_type(
|
extern _Py_UopsSymbol *_Py_uop_sym_new_type(
|
||||||
_Py_UOpsAbstractInterpContext *ctx, PyTypeObject *typ);
|
_Py_UOpsContext *ctx, PyTypeObject *typ);
|
||||||
extern _Py_UOpsSymType *_Py_uop_sym_new_const(_Py_UOpsAbstractInterpContext *ctx, PyObject *const_val);
|
extern _Py_UopsSymbol *_Py_uop_sym_new_const(_Py_UOpsContext *ctx, PyObject *const_val);
|
||||||
extern _Py_UOpsSymType *_Py_uop_sym_new_null(_Py_UOpsAbstractInterpContext *ctx);
|
extern _Py_UopsSymbol *_Py_uop_sym_new_null(_Py_UOpsContext *ctx);
|
||||||
extern bool _Py_uop_sym_matches_type(_Py_UOpsSymType *sym, PyTypeObject *typ);
|
extern bool _Py_uop_sym_matches_type(_Py_UopsSymbol *sym, PyTypeObject *typ);
|
||||||
extern void _Py_uop_sym_set_null(_Py_UOpsSymType *sym);
|
extern void _Py_uop_sym_set_null(_Py_UopsSymbol *sym);
|
||||||
extern void _Py_uop_sym_set_type(_Py_UOpsSymType *sym, PyTypeObject *tp);
|
extern void _Py_uop_sym_set_type(_Py_UopsSymbol *sym, PyTypeObject *tp);
|
||||||
|
|
||||||
extern int _Py_uop_abstractcontext_init(_Py_UOpsAbstractInterpContext *ctx);
|
extern int _Py_uop_abstractcontext_init(_Py_UOpsContext *ctx);
|
||||||
extern void _Py_uop_abstractcontext_fini(_Py_UOpsAbstractInterpContext *ctx);
|
extern void _Py_uop_abstractcontext_fini(_Py_UOpsContext *ctx);
|
||||||
|
|
||||||
extern _Py_UOpsAbstractFrame *_Py_uop_ctx_frame_new(
|
extern _Py_UOpsAbstractFrame *_Py_uop_frame_new(
|
||||||
_Py_UOpsAbstractInterpContext *ctx,
|
_Py_UOpsContext *ctx,
|
||||||
PyCodeObject *co,
|
PyCodeObject *co,
|
||||||
_Py_UOpsSymType **localsplus_start,
|
_Py_UopsSymbol **localsplus_start,
|
||||||
int n_locals_already_filled,
|
int n_locals_already_filled,
|
||||||
int curr_stackentries);
|
int curr_stackentries);
|
||||||
extern int _Py_uop_ctx_frame_pop(_Py_UOpsAbstractInterpContext *ctx);
|
extern int _Py_uop_frame_pop(_Py_UOpsContext *ctx);
|
||||||
|
|
||||||
PyAPI_FUNC(PyObject *)
|
PyAPI_FUNC(PyObject *) _Py_uop_symbols_test(PyObject *self, PyObject *ignored);
|
||||||
_Py_uop_symbols_test(PyObject *self, PyObject *ignored);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -890,8 +890,8 @@ class TestGeneratedAbstractCases(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
output = """
|
output = """
|
||||||
case OP: {
|
case OP: {
|
||||||
_Py_UOpsSymType *arg1;
|
_Py_UopsSymbol *arg1;
|
||||||
_Py_UOpsSymType *out;
|
_Py_UopsSymbol *out;
|
||||||
arg1 = stack_pointer[-1];
|
arg1 = stack_pointer[-1];
|
||||||
eggs();
|
eggs();
|
||||||
stack_pointer[-1] = out;
|
stack_pointer[-1] = out;
|
||||||
|
@ -899,7 +899,7 @@ class TestGeneratedAbstractCases(unittest.TestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
case OP2: {
|
case OP2: {
|
||||||
_Py_UOpsSymType *out;
|
_Py_UopsSymbol *out;
|
||||||
out = _Py_uop_sym_new_unknown(ctx);
|
out = _Py_uop_sym_new_unknown(ctx);
|
||||||
if (out == NULL) goto out_of_space;
|
if (out == NULL) goto out_of_space;
|
||||||
stack_pointer[-1] = out;
|
stack_pointer[-1] = out;
|
||||||
|
@ -924,7 +924,7 @@ class TestGeneratedAbstractCases(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
output = """
|
output = """
|
||||||
case OP: {
|
case OP: {
|
||||||
_Py_UOpsSymType *out;
|
_Py_UopsSymbol *out;
|
||||||
out = _Py_uop_sym_new_unknown(ctx);
|
out = _Py_uop_sym_new_unknown(ctx);
|
||||||
if (out == NULL) goto out_of_space;
|
if (out == NULL) goto out_of_space;
|
||||||
stack_pointer[-1] = out;
|
stack_pointer[-1] = out;
|
||||||
|
@ -932,8 +932,8 @@ class TestGeneratedAbstractCases(unittest.TestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
case OP2: {
|
case OP2: {
|
||||||
_Py_UOpsSymType *arg1;
|
_Py_UopsSymbol *arg1;
|
||||||
_Py_UOpsSymType *out;
|
_Py_UopsSymbol *out;
|
||||||
arg1 = stack_pointer[-1];
|
arg1 = stack_pointer[-1];
|
||||||
stack_pointer[-1] = out;
|
stack_pointer[-1] = out;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include "pycore_interp.h" // _PyInterpreterState_GetConfigCopy()
|
#include "pycore_interp.h" // _PyInterpreterState_GetConfigCopy()
|
||||||
#include "pycore_long.h" // _PyLong_Sign()
|
#include "pycore_long.h" // _PyLong_Sign()
|
||||||
#include "pycore_object.h" // _PyObject_IsFreed()
|
#include "pycore_object.h" // _PyObject_IsFreed()
|
||||||
#include "pycore_optimizer.h" // _Py_UOpsSymType, etc.
|
#include "pycore_optimizer.h" // _Py_UopsSymbol, etc.
|
||||||
#include "pycore_pathconfig.h" // _PyPathConfig_ClearGlobal()
|
#include "pycore_pathconfig.h" // _PyPathConfig_ClearGlobal()
|
||||||
#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
|
#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
|
||||||
#include "pycore_pystate.h" // _PyThreadState_GET()
|
#include "pycore_pystate.h" // _PyThreadState_GET()
|
||||||
|
|
|
@ -282,6 +282,23 @@ remove_globals(_PyInterpreterFrame *frame, _PyUOpInstruction *buffer,
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
|
|
||||||
|
/* Shortened forms for convenience, used in optimizer_bytecodes.c */
|
||||||
|
#define sym_is_not_null _Py_uop_sym_is_not_null
|
||||||
|
#define sym_is_const _Py_uop_sym_is_const
|
||||||
|
#define sym_get_const _Py_uop_sym_get_const
|
||||||
|
#define sym_new_unknown _Py_uop_sym_new_unknown
|
||||||
|
#define sym_new_not_null _Py_uop_sym_new_not_null
|
||||||
|
#define sym_new_type _Py_uop_sym_new_type
|
||||||
|
#define sym_is_null _Py_uop_sym_is_null
|
||||||
|
#define sym_new_const _Py_uop_sym_new_const
|
||||||
|
#define sym_new_null _Py_uop_sym_new_null
|
||||||
|
#define sym_matches_type _Py_uop_sym_matches_type
|
||||||
|
#define sym_set_null _Py_uop_sym_set_null
|
||||||
|
#define sym_set_type _Py_uop_sym_set_type
|
||||||
|
#define frame_new _Py_uop_frame_new
|
||||||
|
#define frame_pop _Py_uop_frame_pop
|
||||||
|
|
||||||
|
|
||||||
/* 1 for success, 0 for not ready, cannot error at the moment. */
|
/* 1 for success, 0 for not ready, cannot error at the moment. */
|
||||||
static int
|
static int
|
||||||
optimize_uops(
|
optimize_uops(
|
||||||
|
@ -293,13 +310,13 @@ optimize_uops(
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|
||||||
_Py_UOpsAbstractInterpContext context;
|
_Py_UOpsContext context;
|
||||||
_Py_UOpsAbstractInterpContext *ctx = &context;
|
_Py_UOpsContext *ctx = &context;
|
||||||
|
|
||||||
if (_Py_uop_abstractcontext_init(ctx) < 0) {
|
if (_Py_uop_abstractcontext_init(ctx) < 0) {
|
||||||
goto out_of_space;
|
goto out_of_space;
|
||||||
}
|
}
|
||||||
_Py_UOpsAbstractFrame *frame = _Py_uop_ctx_frame_new(ctx, co, ctx->n_consumed, 0, curr_stacklen);
|
_Py_UOpsAbstractFrame *frame = _Py_uop_frame_new(ctx, co, ctx->n_consumed, 0, curr_stacklen);
|
||||||
if (frame == NULL) {
|
if (frame == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -313,7 +330,7 @@ optimize_uops(
|
||||||
int oparg = this_instr->oparg;
|
int oparg = this_instr->oparg;
|
||||||
uint32_t opcode = this_instr->opcode;
|
uint32_t opcode = this_instr->opcode;
|
||||||
|
|
||||||
_Py_UOpsSymType **stack_pointer = ctx->frame->stack_pointer;
|
_Py_UopsSymbol **stack_pointer = ctx->frame->stack_pointer;
|
||||||
|
|
||||||
DPRINTF(3, "Abstract interpreting %s:%d ",
|
DPRINTF(3, "Abstract interpreting %s:%d ",
|
||||||
_PyUOpName(opcode),
|
_PyUOpName(opcode),
|
||||||
|
|
|
@ -1,29 +1,46 @@
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
|
#include "pycore_optimizer.h"
|
||||||
#include "pycore_uops.h"
|
#include "pycore_uops.h"
|
||||||
#include "pycore_uop_ids.h"
|
#include "pycore_uop_ids.h"
|
||||||
#include "internal/pycore_moduleobject.h"
|
#include "internal/pycore_moduleobject.h"
|
||||||
|
|
||||||
#define op(name, ...) /* NAME is ignored */
|
#define op(name, ...) /* NAME is ignored */
|
||||||
|
|
||||||
typedef struct _Py_UOpsSymType _Py_UOpsSymType;
|
typedef struct _Py_UopsSymbol _Py_UopsSymbol;
|
||||||
typedef struct _Py_UOpsAbstractInterpContext _Py_UOpsAbstractInterpContext;
|
typedef struct _Py_UOpsContext _Py_UOpsContext;
|
||||||
typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame;
|
typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame;
|
||||||
|
|
||||||
|
/* Shortened forms for convenience */
|
||||||
|
#define sym_is_not_null _Py_uop_sym_is_not_null
|
||||||
|
#define sym_is_const _Py_uop_sym_is_const
|
||||||
|
#define sym_get_const _Py_uop_sym_get_const
|
||||||
|
#define sym_new_unknown _Py_uop_sym_new_unknown
|
||||||
|
#define sym_new_not_null _Py_uop_sym_new_not_null
|
||||||
|
#define sym_new_type _Py_uop_sym_new_type
|
||||||
|
#define sym_is_null _Py_uop_sym_is_null
|
||||||
|
#define sym_new_const _Py_uop_sym_new_const
|
||||||
|
#define sym_new_null _Py_uop_sym_new_null
|
||||||
|
#define sym_matches_type _Py_uop_sym_matches_type
|
||||||
|
#define sym_set_null _Py_uop_sym_set_null
|
||||||
|
#define sym_set_type _Py_uop_sym_set_type
|
||||||
|
#define frame_new _Py_uop_frame_new
|
||||||
|
#define frame_pop _Py_uop_frame_pop
|
||||||
|
|
||||||
static int
|
static int
|
||||||
dummy_func(void) {
|
dummy_func(void) {
|
||||||
|
|
||||||
PyCodeObject *code;
|
PyCodeObject *code;
|
||||||
int oparg;
|
int oparg;
|
||||||
_Py_UOpsSymType *flag;
|
_Py_UopsSymbol *flag;
|
||||||
_Py_UOpsSymType *left;
|
_Py_UopsSymbol *left;
|
||||||
_Py_UOpsSymType *right;
|
_Py_UopsSymbol *right;
|
||||||
_Py_UOpsSymType *value;
|
_Py_UopsSymbol *value;
|
||||||
_Py_UOpsSymType *res;
|
_Py_UopsSymbol *res;
|
||||||
_Py_UOpsSymType *iter;
|
_Py_UopsSymbol *iter;
|
||||||
_Py_UOpsSymType *top;
|
_Py_UopsSymbol *top;
|
||||||
_Py_UOpsSymType *bottom;
|
_Py_UopsSymbol *bottom;
|
||||||
_Py_UOpsAbstractFrame *frame;
|
_Py_UOpsAbstractFrame *frame;
|
||||||
_Py_UOpsAbstractInterpContext *ctx;
|
_Py_UOpsContext *ctx;
|
||||||
_PyUOpInstruction *this_instr;
|
_PyUOpInstruction *this_instr;
|
||||||
_PyBloomFilter *dependencies;
|
_PyBloomFilter *dependencies;
|
||||||
int modified;
|
int modified;
|
||||||
|
@ -33,7 +50,7 @@ dummy_func(void) {
|
||||||
op(_LOAD_FAST_CHECK, (-- value)) {
|
op(_LOAD_FAST_CHECK, (-- value)) {
|
||||||
value = GETLOCAL(oparg);
|
value = GETLOCAL(oparg);
|
||||||
// We guarantee this will error - just bail and don't optimize it.
|
// We guarantee this will error - just bail and don't optimize it.
|
||||||
if (_Py_uop_sym_is_null(value)) {
|
if (sym_is_null(value)) {
|
||||||
goto out_of_space;
|
goto out_of_space;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,8 +61,8 @@ dummy_func(void) {
|
||||||
|
|
||||||
op(_LOAD_FAST_AND_CLEAR, (-- value)) {
|
op(_LOAD_FAST_AND_CLEAR, (-- value)) {
|
||||||
value = GETLOCAL(oparg);
|
value = GETLOCAL(oparg);
|
||||||
_Py_UOpsSymType *temp;
|
_Py_UopsSymbol *temp;
|
||||||
OUT_OF_SPACE_IF_NULL(temp = _Py_uop_sym_new_null(ctx));
|
OUT_OF_SPACE_IF_NULL(temp = sym_new_null(ctx));
|
||||||
GETLOCAL(oparg) = temp;
|
GETLOCAL(oparg) = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,147 +71,147 @@ dummy_func(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_PUSH_NULL, (-- res)) {
|
op(_PUSH_NULL, (-- res)) {
|
||||||
res = _Py_uop_sym_new_null(ctx);
|
res = sym_new_null(ctx);
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
goto out_of_space;
|
goto out_of_space;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_GUARD_BOTH_INT, (left, right -- left, right)) {
|
op(_GUARD_BOTH_INT, (left, right -- left, right)) {
|
||||||
if (_Py_uop_sym_matches_type(left, &PyLong_Type) &&
|
if (sym_matches_type(left, &PyLong_Type) &&
|
||||||
_Py_uop_sym_matches_type(right, &PyLong_Type)) {
|
sym_matches_type(right, &PyLong_Type)) {
|
||||||
REPLACE_OP(this_instr, _NOP, 0, 0);
|
REPLACE_OP(this_instr, _NOP, 0, 0);
|
||||||
}
|
}
|
||||||
_Py_uop_sym_set_type(left, &PyLong_Type);
|
sym_set_type(left, &PyLong_Type);
|
||||||
_Py_uop_sym_set_type(right, &PyLong_Type);
|
sym_set_type(right, &PyLong_Type);
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_GUARD_BOTH_FLOAT, (left, right -- left, right)) {
|
op(_GUARD_BOTH_FLOAT, (left, right -- left, right)) {
|
||||||
if (_Py_uop_sym_matches_type(left, &PyFloat_Type) &&
|
if (sym_matches_type(left, &PyFloat_Type) &&
|
||||||
_Py_uop_sym_matches_type(right, &PyFloat_Type)) {
|
sym_matches_type(right, &PyFloat_Type)) {
|
||||||
REPLACE_OP(this_instr, _NOP, 0 ,0);
|
REPLACE_OP(this_instr, _NOP, 0 ,0);
|
||||||
}
|
}
|
||||||
_Py_uop_sym_set_type(left, &PyFloat_Type);
|
sym_set_type(left, &PyFloat_Type);
|
||||||
_Py_uop_sym_set_type(right, &PyFloat_Type);
|
sym_set_type(right, &PyFloat_Type);
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_GUARD_BOTH_UNICODE, (left, right -- left, right)) {
|
op(_GUARD_BOTH_UNICODE, (left, right -- left, right)) {
|
||||||
if (_Py_uop_sym_matches_type(left, &PyUnicode_Type) &&
|
if (sym_matches_type(left, &PyUnicode_Type) &&
|
||||||
_Py_uop_sym_matches_type(right, &PyUnicode_Type)) {
|
sym_matches_type(right, &PyUnicode_Type)) {
|
||||||
REPLACE_OP(this_instr, _NOP, 0 ,0);
|
REPLACE_OP(this_instr, _NOP, 0 ,0);
|
||||||
}
|
}
|
||||||
_Py_uop_sym_set_type(left, &PyUnicode_Type);
|
sym_set_type(left, &PyUnicode_Type);
|
||||||
_Py_uop_sym_set_type(right, &PyUnicode_Type);
|
sym_set_type(right, &PyUnicode_Type);
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_BINARY_OP_ADD_INT, (left, right -- res)) {
|
op(_BINARY_OP_ADD_INT, (left, right -- res)) {
|
||||||
if (_Py_uop_sym_is_const(left) && _Py_uop_sym_is_const(right)) {
|
if (sym_is_const(left) && sym_is_const(right)) {
|
||||||
assert(PyLong_CheckExact(_Py_uop_sym_get_const(left)));
|
assert(PyLong_CheckExact(sym_get_const(left)));
|
||||||
assert(PyLong_CheckExact(_Py_uop_sym_get_const(right)));
|
assert(PyLong_CheckExact(sym_get_const(right)));
|
||||||
PyObject *temp = _PyLong_Add((PyLongObject *)_Py_uop_sym_get_const(left),
|
PyObject *temp = _PyLong_Add((PyLongObject *)sym_get_const(left),
|
||||||
(PyLongObject *)_Py_uop_sym_get_const(right));
|
(PyLongObject *)sym_get_const(right));
|
||||||
if (temp == NULL) {
|
if (temp == NULL) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
OUT_OF_SPACE_IF_NULL(res = _Py_uop_sym_new_const(ctx, temp));
|
OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
|
||||||
// TODO gh-115506:
|
// TODO gh-115506:
|
||||||
// replace opcode with constant propagated one and add tests!
|
// replace opcode with constant propagated one and add tests!
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
OUT_OF_SPACE_IF_NULL(res = _Py_uop_sym_new_type(ctx, &PyLong_Type));
|
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyLong_Type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_BINARY_OP_SUBTRACT_INT, (left, right -- res)) {
|
op(_BINARY_OP_SUBTRACT_INT, (left, right -- res)) {
|
||||||
if (_Py_uop_sym_is_const(left) && _Py_uop_sym_is_const(right)) {
|
if (sym_is_const(left) && sym_is_const(right)) {
|
||||||
assert(PyLong_CheckExact(_Py_uop_sym_get_const(left)));
|
assert(PyLong_CheckExact(sym_get_const(left)));
|
||||||
assert(PyLong_CheckExact(_Py_uop_sym_get_const(right)));
|
assert(PyLong_CheckExact(sym_get_const(right)));
|
||||||
PyObject *temp = _PyLong_Subtract((PyLongObject *)_Py_uop_sym_get_const(left),
|
PyObject *temp = _PyLong_Subtract((PyLongObject *)sym_get_const(left),
|
||||||
(PyLongObject *)_Py_uop_sym_get_const(right));
|
(PyLongObject *)sym_get_const(right));
|
||||||
if (temp == NULL) {
|
if (temp == NULL) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
OUT_OF_SPACE_IF_NULL(res = _Py_uop_sym_new_const(ctx, temp));
|
OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
|
||||||
// TODO gh-115506:
|
// TODO gh-115506:
|
||||||
// replace opcode with constant propagated one and add tests!
|
// replace opcode with constant propagated one and add tests!
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
OUT_OF_SPACE_IF_NULL(res = _Py_uop_sym_new_type(ctx, &PyLong_Type));
|
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyLong_Type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_BINARY_OP_MULTIPLY_INT, (left, right -- res)) {
|
op(_BINARY_OP_MULTIPLY_INT, (left, right -- res)) {
|
||||||
if (_Py_uop_sym_is_const(left) && _Py_uop_sym_is_const(right)) {
|
if (sym_is_const(left) && sym_is_const(right)) {
|
||||||
assert(PyLong_CheckExact(_Py_uop_sym_get_const(left)));
|
assert(PyLong_CheckExact(sym_get_const(left)));
|
||||||
assert(PyLong_CheckExact(_Py_uop_sym_get_const(right)));
|
assert(PyLong_CheckExact(sym_get_const(right)));
|
||||||
PyObject *temp = _PyLong_Multiply((PyLongObject *)_Py_uop_sym_get_const(left),
|
PyObject *temp = _PyLong_Multiply((PyLongObject *)sym_get_const(left),
|
||||||
(PyLongObject *)_Py_uop_sym_get_const(right));
|
(PyLongObject *)sym_get_const(right));
|
||||||
if (temp == NULL) {
|
if (temp == NULL) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
OUT_OF_SPACE_IF_NULL(res = _Py_uop_sym_new_const(ctx, temp));
|
OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
|
||||||
// TODO gh-115506:
|
// TODO gh-115506:
|
||||||
// replace opcode with constant propagated one and add tests!
|
// replace opcode with constant propagated one and add tests!
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
OUT_OF_SPACE_IF_NULL(res = _Py_uop_sym_new_type(ctx, &PyLong_Type));
|
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyLong_Type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_BINARY_OP_ADD_FLOAT, (left, right -- res)) {
|
op(_BINARY_OP_ADD_FLOAT, (left, right -- res)) {
|
||||||
if (_Py_uop_sym_is_const(left) && _Py_uop_sym_is_const(right)) {
|
if (sym_is_const(left) && sym_is_const(right)) {
|
||||||
assert(PyFloat_CheckExact(_Py_uop_sym_get_const(left)));
|
assert(PyFloat_CheckExact(sym_get_const(left)));
|
||||||
assert(PyFloat_CheckExact(_Py_uop_sym_get_const(right)));
|
assert(PyFloat_CheckExact(sym_get_const(right)));
|
||||||
PyObject *temp = PyFloat_FromDouble(
|
PyObject *temp = PyFloat_FromDouble(
|
||||||
PyFloat_AS_DOUBLE(_Py_uop_sym_get_const(left)) +
|
PyFloat_AS_DOUBLE(sym_get_const(left)) +
|
||||||
PyFloat_AS_DOUBLE(_Py_uop_sym_get_const(right)));
|
PyFloat_AS_DOUBLE(sym_get_const(right)));
|
||||||
if (temp == NULL) {
|
if (temp == NULL) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
res = _Py_uop_sym_new_const(ctx, temp);
|
res = sym_new_const(ctx, temp);
|
||||||
// TODO gh-115506:
|
// TODO gh-115506:
|
||||||
// replace opcode with constant propagated one and update tests!
|
// replace opcode with constant propagated one and update tests!
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
OUT_OF_SPACE_IF_NULL(res = _Py_uop_sym_new_type(ctx, &PyFloat_Type));
|
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyFloat_Type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_BINARY_OP_SUBTRACT_FLOAT, (left, right -- res)) {
|
op(_BINARY_OP_SUBTRACT_FLOAT, (left, right -- res)) {
|
||||||
if (_Py_uop_sym_is_const(left) && _Py_uop_sym_is_const(right)) {
|
if (sym_is_const(left) && sym_is_const(right)) {
|
||||||
assert(PyFloat_CheckExact(_Py_uop_sym_get_const(left)));
|
assert(PyFloat_CheckExact(sym_get_const(left)));
|
||||||
assert(PyFloat_CheckExact(_Py_uop_sym_get_const(right)));
|
assert(PyFloat_CheckExact(sym_get_const(right)));
|
||||||
PyObject *temp = PyFloat_FromDouble(
|
PyObject *temp = PyFloat_FromDouble(
|
||||||
PyFloat_AS_DOUBLE(_Py_uop_sym_get_const(left)) -
|
PyFloat_AS_DOUBLE(sym_get_const(left)) -
|
||||||
PyFloat_AS_DOUBLE(_Py_uop_sym_get_const(right)));
|
PyFloat_AS_DOUBLE(sym_get_const(right)));
|
||||||
if (temp == NULL) {
|
if (temp == NULL) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
res = _Py_uop_sym_new_const(ctx, temp);
|
res = sym_new_const(ctx, temp);
|
||||||
// TODO gh-115506:
|
// TODO gh-115506:
|
||||||
// replace opcode with constant propagated one and update tests!
|
// replace opcode with constant propagated one and update tests!
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
OUT_OF_SPACE_IF_NULL(res = _Py_uop_sym_new_type(ctx, &PyFloat_Type));
|
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyFloat_Type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_BINARY_OP_MULTIPLY_FLOAT, (left, right -- res)) {
|
op(_BINARY_OP_MULTIPLY_FLOAT, (left, right -- res)) {
|
||||||
if (_Py_uop_sym_is_const(left) && _Py_uop_sym_is_const(right)) {
|
if (sym_is_const(left) && sym_is_const(right)) {
|
||||||
assert(PyFloat_CheckExact(_Py_uop_sym_get_const(left)));
|
assert(PyFloat_CheckExact(sym_get_const(left)));
|
||||||
assert(PyFloat_CheckExact(_Py_uop_sym_get_const(right)));
|
assert(PyFloat_CheckExact(sym_get_const(right)));
|
||||||
PyObject *temp = PyFloat_FromDouble(
|
PyObject *temp = PyFloat_FromDouble(
|
||||||
PyFloat_AS_DOUBLE(_Py_uop_sym_get_const(left)) *
|
PyFloat_AS_DOUBLE(sym_get_const(left)) *
|
||||||
PyFloat_AS_DOUBLE(_Py_uop_sym_get_const(right)));
|
PyFloat_AS_DOUBLE(sym_get_const(right)));
|
||||||
if (temp == NULL) {
|
if (temp == NULL) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
res = _Py_uop_sym_new_const(ctx, temp);
|
res = sym_new_const(ctx, temp);
|
||||||
// TODO gh-115506:
|
// TODO gh-115506:
|
||||||
// replace opcode with constant propagated one and update tests!
|
// replace opcode with constant propagated one and update tests!
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
OUT_OF_SPACE_IF_NULL(res = _Py_uop_sym_new_type(ctx, &PyFloat_Type));
|
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyFloat_Type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,21 +222,21 @@ dummy_func(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_LOAD_CONST_INLINE, (ptr/4 -- value)) {
|
op(_LOAD_CONST_INLINE, (ptr/4 -- value)) {
|
||||||
OUT_OF_SPACE_IF_NULL(value = _Py_uop_sym_new_const(ctx, ptr));
|
OUT_OF_SPACE_IF_NULL(value = sym_new_const(ctx, ptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_LOAD_CONST_INLINE_BORROW, (ptr/4 -- value)) {
|
op(_LOAD_CONST_INLINE_BORROW, (ptr/4 -- value)) {
|
||||||
OUT_OF_SPACE_IF_NULL(value = _Py_uop_sym_new_const(ctx, ptr));
|
OUT_OF_SPACE_IF_NULL(value = sym_new_const(ctx, ptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_LOAD_CONST_INLINE_WITH_NULL, (ptr/4 -- value, null)) {
|
op(_LOAD_CONST_INLINE_WITH_NULL, (ptr/4 -- value, null)) {
|
||||||
OUT_OF_SPACE_IF_NULL(value = _Py_uop_sym_new_const(ctx, ptr));
|
OUT_OF_SPACE_IF_NULL(value = sym_new_const(ctx, ptr));
|
||||||
OUT_OF_SPACE_IF_NULL(null = _Py_uop_sym_new_null(ctx));
|
OUT_OF_SPACE_IF_NULL(null = sym_new_null(ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_LOAD_CONST_INLINE_BORROW_WITH_NULL, (ptr/4 -- value, null)) {
|
op(_LOAD_CONST_INLINE_BORROW_WITH_NULL, (ptr/4 -- value, null)) {
|
||||||
OUT_OF_SPACE_IF_NULL(value = _Py_uop_sym_new_const(ctx, ptr));
|
OUT_OF_SPACE_IF_NULL(value = sym_new_const(ctx, ptr));
|
||||||
OUT_OF_SPACE_IF_NULL(null = _Py_uop_sym_new_null(ctx));
|
OUT_OF_SPACE_IF_NULL(null = sym_new_null(ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -240,8 +257,8 @@ dummy_func(void) {
|
||||||
|
|
||||||
op(_CHECK_ATTR_MODULE, (dict_version/2, owner -- owner)) {
|
op(_CHECK_ATTR_MODULE, (dict_version/2, owner -- owner)) {
|
||||||
(void)dict_version;
|
(void)dict_version;
|
||||||
if (_Py_uop_sym_is_const(owner)) {
|
if (sym_is_const(owner)) {
|
||||||
PyObject *cnst = _Py_uop_sym_get_const(owner);
|
PyObject *cnst = sym_get_const(owner);
|
||||||
if (PyModule_CheckExact(cnst)) {
|
if (PyModule_CheckExact(cnst)) {
|
||||||
PyModuleObject *mod = (PyModuleObject *)cnst;
|
PyModuleObject *mod = (PyModuleObject *)cnst;
|
||||||
PyObject *dict = mod->md_dict;
|
PyObject *dict = mod->md_dict;
|
||||||
|
@ -257,23 +274,23 @@ dummy_func(void) {
|
||||||
|
|
||||||
op(_LOAD_ATTR_MODULE, (index/1, owner -- attr, null if (oparg & 1))) {
|
op(_LOAD_ATTR_MODULE, (index/1, owner -- attr, null if (oparg & 1))) {
|
||||||
(void)index;
|
(void)index;
|
||||||
OUT_OF_SPACE_IF_NULL(null = _Py_uop_sym_new_null(ctx));
|
OUT_OF_SPACE_IF_NULL(null = sym_new_null(ctx));
|
||||||
attr = NULL;
|
attr = NULL;
|
||||||
if (this_instr[-1].opcode == _NOP) {
|
if (this_instr[-1].opcode == _NOP) {
|
||||||
// Preceding _CHECK_ATTR_MODULE was removed: mod is const and dict is watched.
|
// Preceding _CHECK_ATTR_MODULE was removed: mod is const and dict is watched.
|
||||||
assert(_Py_uop_sym_is_const(owner));
|
assert(sym_is_const(owner));
|
||||||
PyModuleObject *mod = (PyModuleObject *)_Py_uop_sym_get_const(owner);
|
PyModuleObject *mod = (PyModuleObject *)sym_get_const(owner);
|
||||||
assert(PyModule_CheckExact(mod));
|
assert(PyModule_CheckExact(mod));
|
||||||
PyObject *dict = mod->md_dict;
|
PyObject *dict = mod->md_dict;
|
||||||
PyObject *res = convert_global_to_const(this_instr, dict);
|
PyObject *res = convert_global_to_const(this_instr, dict);
|
||||||
if (res != NULL) {
|
if (res != NULL) {
|
||||||
this_instr[-1].opcode = _POP_TOP;
|
this_instr[-1].opcode = _POP_TOP;
|
||||||
OUT_OF_SPACE_IF_NULL(attr = _Py_uop_sym_new_const(ctx, res));
|
OUT_OF_SPACE_IF_NULL(attr = sym_new_const(ctx, res));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (attr == NULL) {
|
if (attr == NULL) {
|
||||||
/* No conversion made. We don't know what `attr` is. */
|
/* No conversion made. We don't know what `attr` is. */
|
||||||
OUT_OF_SPACE_IF_NULL(attr = _Py_uop_sym_new_not_null(ctx));
|
OUT_OF_SPACE_IF_NULL(attr = sym_new_not_null(ctx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,38 +314,38 @@ dummy_func(void) {
|
||||||
|
|
||||||
op(_LOAD_ATTR_METHOD_WITH_VALUES, (descr/4, owner -- attr, self if (1))) {
|
op(_LOAD_ATTR_METHOD_WITH_VALUES, (descr/4, owner -- attr, self if (1))) {
|
||||||
(void)descr;
|
(void)descr;
|
||||||
OUT_OF_SPACE_IF_NULL(attr = _Py_uop_sym_new_not_null(ctx));
|
OUT_OF_SPACE_IF_NULL(attr = sym_new_not_null(ctx));
|
||||||
self = owner;
|
self = owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_LOAD_ATTR_METHOD_NO_DICT, (descr/4, owner -- attr, self if (1))) {
|
op(_LOAD_ATTR_METHOD_NO_DICT, (descr/4, owner -- attr, self if (1))) {
|
||||||
(void)descr;
|
(void)descr;
|
||||||
OUT_OF_SPACE_IF_NULL(attr = _Py_uop_sym_new_not_null(ctx));
|
OUT_OF_SPACE_IF_NULL(attr = sym_new_not_null(ctx));
|
||||||
self = owner;
|
self = owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_LOAD_ATTR_METHOD_LAZY_DICT, (descr/4, owner -- attr, self if (1))) {
|
op(_LOAD_ATTR_METHOD_LAZY_DICT, (descr/4, owner -- attr, self if (1))) {
|
||||||
(void)descr;
|
(void)descr;
|
||||||
OUT_OF_SPACE_IF_NULL(attr = _Py_uop_sym_new_not_null(ctx));
|
OUT_OF_SPACE_IF_NULL(attr = sym_new_not_null(ctx));
|
||||||
self = owner;
|
self = owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_INIT_CALL_BOUND_METHOD_EXACT_ARGS, (callable, unused, unused[oparg] -- func, self, unused[oparg])) {
|
op(_INIT_CALL_BOUND_METHOD_EXACT_ARGS, (callable, unused, unused[oparg] -- func, self, unused[oparg])) {
|
||||||
(void)callable;
|
(void)callable;
|
||||||
OUT_OF_SPACE_IF_NULL(func = _Py_uop_sym_new_not_null(ctx));
|
OUT_OF_SPACE_IF_NULL(func = sym_new_not_null(ctx));
|
||||||
OUT_OF_SPACE_IF_NULL(self = _Py_uop_sym_new_not_null(ctx));
|
OUT_OF_SPACE_IF_NULL(self = sym_new_not_null(ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
op(_CHECK_FUNCTION_EXACT_ARGS, (func_version/2, callable, self_or_null, unused[oparg] -- callable, self_or_null, unused[oparg])) {
|
op(_CHECK_FUNCTION_EXACT_ARGS, (func_version/2, callable, self_or_null, unused[oparg] -- callable, self_or_null, unused[oparg])) {
|
||||||
_Py_uop_sym_set_type(callable, &PyFunction_Type);
|
sym_set_type(callable, &PyFunction_Type);
|
||||||
(void)self_or_null;
|
(void)self_or_null;
|
||||||
(void)func_version;
|
(void)func_version;
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_CHECK_CALL_BOUND_METHOD_EXACT_ARGS, (callable, null, unused[oparg] -- callable, null, unused[oparg])) {
|
op(_CHECK_CALL_BOUND_METHOD_EXACT_ARGS, (callable, null, unused[oparg] -- callable, null, unused[oparg])) {
|
||||||
_Py_uop_sym_set_null(null);
|
sym_set_null(null);
|
||||||
_Py_uop_sym_set_type(callable, &PyMethod_Type);
|
sym_set_type(callable, &PyMethod_Type);
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_INIT_CALL_PY_EXACT_ARGS, (callable, self_or_null, args[oparg] -- new_frame: _Py_UOpsAbstractFrame *)) {
|
op(_INIT_CALL_PY_EXACT_ARGS, (callable, self_or_null, args[oparg] -- new_frame: _Py_UOpsAbstractFrame *)) {
|
||||||
|
@ -344,29 +361,29 @@ dummy_func(void) {
|
||||||
|
|
||||||
assert(self_or_null != NULL);
|
assert(self_or_null != NULL);
|
||||||
assert(args != NULL);
|
assert(args != NULL);
|
||||||
if (_Py_uop_sym_is_not_null(self_or_null)) {
|
if (sym_is_not_null(self_or_null)) {
|
||||||
// Bound method fiddling, same as _INIT_CALL_PY_EXACT_ARGS in VM
|
// Bound method fiddling, same as _INIT_CALL_PY_EXACT_ARGS in VM
|
||||||
args--;
|
args--;
|
||||||
argcount++;
|
argcount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
_Py_UOpsSymType **localsplus_start = ctx->n_consumed;
|
_Py_UopsSymbol **localsplus_start = ctx->n_consumed;
|
||||||
int n_locals_already_filled = 0;
|
int n_locals_already_filled = 0;
|
||||||
// Can determine statically, so we interleave the new locals
|
// Can determine statically, so we interleave the new locals
|
||||||
// and make the current stack the new locals.
|
// and make the current stack the new locals.
|
||||||
// This also sets up for true call inlining.
|
// This also sets up for true call inlining.
|
||||||
if (_Py_uop_sym_is_null(self_or_null) || _Py_uop_sym_is_not_null(self_or_null)) {
|
if (sym_is_null(self_or_null) || sym_is_not_null(self_or_null)) {
|
||||||
localsplus_start = args;
|
localsplus_start = args;
|
||||||
n_locals_already_filled = argcount;
|
n_locals_already_filled = argcount;
|
||||||
}
|
}
|
||||||
OUT_OF_SPACE_IF_NULL(new_frame =
|
OUT_OF_SPACE_IF_NULL(new_frame =
|
||||||
_Py_uop_ctx_frame_new(ctx, co, localsplus_start, n_locals_already_filled, 0));
|
frame_new(ctx, co, localsplus_start, n_locals_already_filled, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_POP_FRAME, (retval -- res)) {
|
op(_POP_FRAME, (retval -- res)) {
|
||||||
SYNC_SP();
|
SYNC_SP();
|
||||||
ctx->frame->stack_pointer = stack_pointer;
|
ctx->frame->stack_pointer = stack_pointer;
|
||||||
_Py_uop_ctx_frame_pop(ctx);
|
frame_pop(ctx);
|
||||||
stack_pointer = ctx->frame->stack_pointer;
|
stack_pointer = ctx->frame->stack_pointer;
|
||||||
res = retval;
|
res = retval;
|
||||||
}
|
}
|
||||||
|
@ -383,7 +400,7 @@ dummy_func(void) {
|
||||||
/* This has to be done manually */
|
/* This has to be done manually */
|
||||||
(void)seq;
|
(void)seq;
|
||||||
for (int i = 0; i < oparg; i++) {
|
for (int i = 0; i < oparg; i++) {
|
||||||
OUT_OF_SPACE_IF_NULL(values[i] = _Py_uop_sym_new_unknown(ctx));
|
OUT_OF_SPACE_IF_NULL(values[i] = sym_new_unknown(ctx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,12 +409,12 @@ dummy_func(void) {
|
||||||
(void)seq;
|
(void)seq;
|
||||||
int totalargs = (oparg & 0xFF) + (oparg >> 8) + 1;
|
int totalargs = (oparg & 0xFF) + (oparg >> 8) + 1;
|
||||||
for (int i = 0; i < totalargs; i++) {
|
for (int i = 0; i < totalargs; i++) {
|
||||||
OUT_OF_SPACE_IF_NULL(values[i] = _Py_uop_sym_new_unknown(ctx));
|
OUT_OF_SPACE_IF_NULL(values[i] = sym_new_unknown(ctx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_ITER_NEXT_RANGE, (iter -- iter, next)) {
|
op(_ITER_NEXT_RANGE, (iter -- iter, next)) {
|
||||||
OUT_OF_SPACE_IF_NULL(next = _Py_uop_sym_new_type(ctx, &PyLong_Type));
|
OUT_OF_SPACE_IF_NULL(next = sym_new_type(ctx, &PyLong_Type));
|
||||||
(void)iter;
|
(void)iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
538
Python/optimizer_cases.c.h
generated
538
Python/optimizer_cases.c.h
generated
File diff suppressed because it is too large
Load diff
|
@ -32,10 +32,10 @@ static inline int get_lltrace(void) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Takes a borrowed reference to const_val, turns that into a strong reference.
|
// Takes a borrowed reference to const_val, turns that into a strong reference.
|
||||||
static _Py_UOpsSymType*
|
static _Py_UopsSymbol *
|
||||||
sym_new(_Py_UOpsAbstractInterpContext *ctx, PyObject *const_val)
|
sym_new(_Py_UOpsContext *ctx, PyObject *const_val)
|
||||||
{
|
{
|
||||||
_Py_UOpsSymType *self = &ctx->t_arena.arena[ctx->t_arena.ty_curr_number];
|
_Py_UopsSymbol *self = &ctx->t_arena.arena[ctx->t_arena.ty_curr_number];
|
||||||
if (ctx->t_arena.ty_curr_number >= ctx->t_arena.ty_max_number) {
|
if (ctx->t_arena.ty_curr_number >= ctx->t_arena.ty_max_number) {
|
||||||
OPT_STAT_INC(optimizer_failure_reason_no_memory);
|
OPT_STAT_INC(optimizer_failure_reason_no_memory);
|
||||||
DPRINTF(1, "out of space for symbolic expression type\n");
|
DPRINTF(1, "out of space for symbolic expression type\n");
|
||||||
|
@ -54,37 +54,37 @@ sym_new(_Py_UOpsAbstractInterpContext *ctx, PyObject *const_val)
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
sym_set_flag(_Py_UOpsSymType *sym, int flag)
|
sym_set_flag(_Py_UopsSymbol *sym, int flag)
|
||||||
{
|
{
|
||||||
sym->flags |= flag;
|
sym->flags |= flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
sym_has_flag(_Py_UOpsSymType *sym, int flag)
|
sym_has_flag(_Py_UopsSymbol *sym, int flag)
|
||||||
{
|
{
|
||||||
return (sym->flags & flag) != 0;
|
return (sym->flags & flag) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
_Py_uop_sym_is_not_null(_Py_UOpsSymType *sym)
|
_Py_uop_sym_is_not_null(_Py_UopsSymbol *sym)
|
||||||
{
|
{
|
||||||
return (sym->flags & (IS_NULL | NOT_NULL)) == NOT_NULL;
|
return (sym->flags & (IS_NULL | NOT_NULL)) == NOT_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
_Py_uop_sym_is_null(_Py_UOpsSymType *sym)
|
_Py_uop_sym_is_null(_Py_UopsSymbol *sym)
|
||||||
{
|
{
|
||||||
return (sym->flags & (IS_NULL | NOT_NULL)) == IS_NULL;
|
return (sym->flags & (IS_NULL | NOT_NULL)) == IS_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
_Py_uop_sym_is_const(_Py_UOpsSymType *sym)
|
_Py_uop_sym_is_const(_Py_UopsSymbol *sym)
|
||||||
{
|
{
|
||||||
return (sym->flags & TRUE_CONST) != 0;
|
return (sym->flags & TRUE_CONST) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
_Py_uop_sym_get_const(_Py_UOpsSymType *sym)
|
_Py_uop_sym_get_const(_Py_UopsSymbol *sym)
|
||||||
{
|
{
|
||||||
assert(_Py_uop_sym_is_const(sym));
|
assert(_Py_uop_sym_is_const(sym));
|
||||||
assert(sym->const_val);
|
assert(sym->const_val);
|
||||||
|
@ -92,7 +92,7 @@ _Py_uop_sym_get_const(_Py_UOpsSymType *sym)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_Py_uop_sym_set_type(_Py_UOpsSymType *sym, PyTypeObject *tp)
|
_Py_uop_sym_set_type(_Py_UopsSymbol *sym, PyTypeObject *tp)
|
||||||
{
|
{
|
||||||
assert(PyType_Check(tp));
|
assert(PyType_Check(tp));
|
||||||
sym->typ = tp;
|
sym->typ = tp;
|
||||||
|
@ -101,23 +101,23 @@ _Py_uop_sym_set_type(_Py_UOpsSymType *sym, PyTypeObject *tp)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_Py_uop_sym_set_null(_Py_UOpsSymType *sym)
|
_Py_uop_sym_set_null(_Py_UopsSymbol *sym)
|
||||||
{
|
{
|
||||||
sym_set_flag(sym, IS_NULL);
|
sym_set_flag(sym, IS_NULL);
|
||||||
sym_set_flag(sym, KNOWN);
|
sym_set_flag(sym, KNOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_Py_UOpsSymType *
|
_Py_UopsSymbol *
|
||||||
_Py_uop_sym_new_unknown(_Py_UOpsAbstractInterpContext *ctx)
|
_Py_uop_sym_new_unknown(_Py_UOpsContext *ctx)
|
||||||
{
|
{
|
||||||
return sym_new(ctx,NULL);
|
return sym_new(ctx, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
_Py_UOpsSymType *
|
_Py_UopsSymbol *
|
||||||
_Py_uop_sym_new_not_null(_Py_UOpsAbstractInterpContext *ctx)
|
_Py_uop_sym_new_not_null(_Py_UOpsContext *ctx)
|
||||||
{
|
{
|
||||||
_Py_UOpsSymType *res = _Py_uop_sym_new_unknown(ctx);
|
_Py_UopsSymbol *res = _Py_uop_sym_new_unknown(ctx);
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -126,11 +126,11 @@ _Py_uop_sym_new_not_null(_Py_UOpsAbstractInterpContext *ctx)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
_Py_UOpsSymType *
|
_Py_UopsSymbol *
|
||||||
_Py_uop_sym_new_type(_Py_UOpsAbstractInterpContext *ctx,
|
_Py_uop_sym_new_type(_Py_UOpsContext *ctx,
|
||||||
PyTypeObject *typ)
|
PyTypeObject *typ)
|
||||||
{
|
{
|
||||||
_Py_UOpsSymType *res = sym_new(ctx,NULL);
|
_Py_UopsSymbol *res = sym_new(ctx,NULL);
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -139,14 +139,11 @@ _Py_uop_sym_new_type(_Py_UOpsAbstractInterpContext *ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes a borrowed reference to const_val.
|
// Takes a borrowed reference to const_val.
|
||||||
_Py_UOpsSymType*
|
_Py_UopsSymbol *
|
||||||
_Py_uop_sym_new_const(_Py_UOpsAbstractInterpContext *ctx, PyObject *const_val)
|
_Py_uop_sym_new_const(_Py_UOpsContext *ctx, PyObject *const_val)
|
||||||
{
|
{
|
||||||
assert(const_val != NULL);
|
assert(const_val != NULL);
|
||||||
_Py_UOpsSymType *temp = sym_new(
|
_Py_UopsSymbol *temp = sym_new(ctx, const_val);
|
||||||
ctx,
|
|
||||||
const_val
|
|
||||||
);
|
|
||||||
if (temp == NULL) {
|
if (temp == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -157,10 +154,10 @@ _Py_uop_sym_new_const(_Py_UOpsAbstractInterpContext *ctx, PyObject *const_val)
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
_Py_UOpsSymType*
|
_Py_UopsSymbol *
|
||||||
_Py_uop_sym_new_null(_Py_UOpsAbstractInterpContext *ctx)
|
_Py_uop_sym_new_null(_Py_UOpsContext *ctx)
|
||||||
{
|
{
|
||||||
_Py_UOpsSymType *null_sym = _Py_uop_sym_new_unknown(ctx);
|
_Py_UopsSymbol *null_sym = _Py_uop_sym_new_unknown(ctx);
|
||||||
if (null_sym == NULL) {
|
if (null_sym == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -169,7 +166,7 @@ _Py_uop_sym_new_null(_Py_UOpsAbstractInterpContext *ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
_Py_uop_sym_matches_type(_Py_UOpsSymType *sym, PyTypeObject *typ)
|
_Py_uop_sym_matches_type(_Py_UopsSymbol *sym, PyTypeObject *typ)
|
||||||
{
|
{
|
||||||
assert(typ == NULL || PyType_Check(typ));
|
assert(typ == NULL || PyType_Check(typ));
|
||||||
if (!sym_has_flag(sym, KNOWN)) {
|
if (!sym_has_flag(sym, KNOWN)) {
|
||||||
|
@ -180,13 +177,12 @@ _Py_uop_sym_matches_type(_Py_UOpsSymType *sym, PyTypeObject *typ)
|
||||||
|
|
||||||
// 0 on success, -1 on error.
|
// 0 on success, -1 on error.
|
||||||
_Py_UOpsAbstractFrame *
|
_Py_UOpsAbstractFrame *
|
||||||
_Py_uop_ctx_frame_new(
|
_Py_uop_frame_new(
|
||||||
_Py_UOpsAbstractInterpContext *ctx,
|
_Py_UOpsContext *ctx,
|
||||||
PyCodeObject *co,
|
PyCodeObject *co,
|
||||||
_Py_UOpsSymType **localsplus_start,
|
_Py_UopsSymbol **localsplus_start,
|
||||||
int n_locals_already_filled,
|
int n_locals_already_filled,
|
||||||
int curr_stackentries
|
int curr_stackentries)
|
||||||
)
|
|
||||||
{
|
{
|
||||||
assert(ctx->curr_frame_depth < MAX_ABSTRACT_FRAME_DEPTH);
|
assert(ctx->curr_frame_depth < MAX_ABSTRACT_FRAME_DEPTH);
|
||||||
_Py_UOpsAbstractFrame *frame = &ctx->frames[ctx->curr_frame_depth];
|
_Py_UOpsAbstractFrame *frame = &ctx->frames[ctx->curr_frame_depth];
|
||||||
|
@ -205,7 +201,7 @@ _Py_uop_ctx_frame_new(
|
||||||
|
|
||||||
// Initialize with the initial state of all local variables
|
// Initialize with the initial state of all local variables
|
||||||
for (int i = n_locals_already_filled; i < co->co_nlocalsplus; i++) {
|
for (int i = n_locals_already_filled; i < co->co_nlocalsplus; i++) {
|
||||||
_Py_UOpsSymType *local = _Py_uop_sym_new_unknown(ctx);
|
_Py_UopsSymbol *local = _Py_uop_sym_new_unknown(ctx);
|
||||||
if (local == NULL) {
|
if (local == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -215,7 +211,7 @@ _Py_uop_ctx_frame_new(
|
||||||
|
|
||||||
// Initialize the stack as well
|
// Initialize the stack as well
|
||||||
for (int i = 0; i < curr_stackentries; i++) {
|
for (int i = 0; i < curr_stackentries; i++) {
|
||||||
_Py_UOpsSymType *stackvar = _Py_uop_sym_new_unknown(ctx);
|
_Py_UopsSymbol *stackvar = _Py_uop_sym_new_unknown(ctx);
|
||||||
if (stackvar == NULL) {
|
if (stackvar == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -226,7 +222,7 @@ _Py_uop_ctx_frame_new(
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_Py_uop_abstractcontext_fini(_Py_UOpsAbstractInterpContext *ctx)
|
_Py_uop_abstractcontext_fini(_Py_UOpsContext *ctx)
|
||||||
{
|
{
|
||||||
if (ctx == NULL) {
|
if (ctx == NULL) {
|
||||||
return;
|
return;
|
||||||
|
@ -239,9 +235,7 @@ _Py_uop_abstractcontext_fini(_Py_UOpsAbstractInterpContext *ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
_Py_uop_abstractcontext_init(
|
_Py_uop_abstractcontext_init(_Py_UOpsContext *ctx)
|
||||||
_Py_UOpsAbstractInterpContext *ctx
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
ctx->limit = ctx->locals_and_stack + MAX_ABSTRACT_INTERP_SIZE;
|
ctx->limit = ctx->locals_and_stack + MAX_ABSTRACT_INTERP_SIZE;
|
||||||
ctx->n_consumed = ctx->locals_and_stack;
|
ctx->n_consumed = ctx->locals_and_stack;
|
||||||
|
@ -262,12 +256,9 @@ _Py_uop_abstractcontext_init(
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
_Py_uop_ctx_frame_pop(
|
_Py_uop_frame_pop(_Py_UOpsContext *ctx)
|
||||||
_Py_UOpsAbstractInterpContext *ctx
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
_Py_UOpsAbstractFrame *frame = ctx->frame;
|
_Py_UOpsAbstractFrame *frame = ctx->frame;
|
||||||
|
|
||||||
ctx->n_consumed = frame->locals;
|
ctx->n_consumed = frame->locals;
|
||||||
ctx->curr_frame_depth--;
|
ctx->curr_frame_depth--;
|
||||||
assert(ctx->curr_frame_depth >= 1);
|
assert(ctx->curr_frame_depth >= 1);
|
||||||
|
@ -287,10 +278,10 @@ do { \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
static _Py_UOpsSymType *
|
static _Py_UopsSymbol *
|
||||||
make_bottom(_Py_UOpsAbstractInterpContext *ctx)
|
make_contradiction(_Py_UOpsContext *ctx)
|
||||||
{
|
{
|
||||||
_Py_UOpsSymType *sym = _Py_uop_sym_new_unknown(ctx);
|
_Py_UopsSymbol *sym = _Py_uop_sym_new_unknown(ctx);
|
||||||
_Py_uop_sym_set_null(sym);
|
_Py_uop_sym_set_null(sym);
|
||||||
_Py_uop_sym_set_type(sym, &PyLong_Type);
|
_Py_uop_sym_set_type(sym, &PyLong_Type);
|
||||||
return sym;
|
return sym;
|
||||||
|
@ -299,11 +290,11 @@ make_bottom(_Py_UOpsAbstractInterpContext *ctx)
|
||||||
PyObject *
|
PyObject *
|
||||||
_Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored))
|
_Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored))
|
||||||
{
|
{
|
||||||
_Py_UOpsAbstractInterpContext context;
|
_Py_UOpsContext context;
|
||||||
_Py_UOpsAbstractInterpContext *ctx = &context;
|
_Py_UOpsContext *ctx = &context;
|
||||||
_Py_uop_abstractcontext_init(ctx);
|
_Py_uop_abstractcontext_init(ctx);
|
||||||
|
|
||||||
_Py_UOpsSymType *top = _Py_uop_sym_new_unknown(ctx);
|
_Py_UopsSymbol *top = _Py_uop_sym_new_unknown(ctx);
|
||||||
if (top == NULL) {
|
if (top == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -312,17 +303,17 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored))
|
||||||
TEST_PREDICATE(!_Py_uop_sym_is_const(top), "unknown is a constant");
|
TEST_PREDICATE(!_Py_uop_sym_is_const(top), "unknown is a constant");
|
||||||
// TEST_PREDICATE(_Py_uop_sym_get_const(top) == NULL, "unknown as constant is not NULL");
|
// TEST_PREDICATE(_Py_uop_sym_get_const(top) == NULL, "unknown as constant is not NULL");
|
||||||
|
|
||||||
// _Py_UOpsSymType *bottom = make_bottom(ctx);
|
// _Py_UopsSymbol *contradiction = make_contradiction(ctx);
|
||||||
// TEST_PREDICATE(_Py_uop_sym_is_null(bottom), "bottom is NULL is not true");
|
// TEST_PREDICATE(_Py_uop_sym_is_null(contradiction), "contradiction is NULL is not true");
|
||||||
// TEST_PREDICATE(_Py_uop_sym_is_not_null(bottom), "bottom is not NULL is not true");
|
// TEST_PREDICATE(_Py_uop_sym_is_not_null(contradiction), "contradiction is not NULL is not true");
|
||||||
// TEST_PREDICATE(_Py_uop_sym_is_const(bottom), "bottom is a constant is not true");
|
// TEST_PREDICATE(_Py_uop_sym_is_const(contradiction), "contradiction is a constant is not true");
|
||||||
|
|
||||||
_Py_UOpsSymType *int_type = _Py_uop_sym_new_type(ctx, &PyLong_Type);
|
_Py_UopsSymbol *int_type = _Py_uop_sym_new_type(ctx, &PyLong_Type);
|
||||||
TEST_PREDICATE(_Py_uop_sym_matches_type(int_type, &PyLong_Type), "inconsistent type");
|
TEST_PREDICATE(_Py_uop_sym_matches_type(int_type, &PyLong_Type), "inconsistent type");
|
||||||
_Py_uop_sym_set_type(int_type, &PyLong_Type);
|
_Py_uop_sym_set_type(int_type, &PyLong_Type);
|
||||||
TEST_PREDICATE(_Py_uop_sym_matches_type(int_type, &PyLong_Type), "inconsistent type");
|
TEST_PREDICATE(_Py_uop_sym_matches_type(int_type, &PyLong_Type), "inconsistent type");
|
||||||
_Py_uop_sym_set_type(int_type, &PyFloat_Type);
|
_Py_uop_sym_set_type(int_type, &PyFloat_Type);
|
||||||
// TEST_PREDICATE(_Py_uop_sym_matches_type(int_type, &PyLong_Type), "bottom doesn't match int");
|
// TEST_PREDICATE(_Py_uop_sym_matches_type(int_type, &PyLong_Type), "(int and float) doesn't match int");
|
||||||
|
|
||||||
_Py_uop_abstractcontext_fini(ctx);
|
_Py_uop_abstractcontext_fini(ctx);
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
|
|
|
@ -41,10 +41,10 @@ def validate_uop(override: Uop, uop: Uop) -> None:
|
||||||
|
|
||||||
def type_name(var: StackItem) -> str:
|
def type_name(var: StackItem) -> str:
|
||||||
if var.is_array():
|
if var.is_array():
|
||||||
return f"_Py_UOpsSymType **"
|
return f"_Py_UopsSymbol **"
|
||||||
if var.type:
|
if var.type:
|
||||||
return var.type
|
return var.type
|
||||||
return f"_Py_UOpsSymType *"
|
return f"_Py_UopsSymbol *"
|
||||||
|
|
||||||
|
|
||||||
def declare_variables(uop: Uop, out: CWriter, skip_inputs: bool) -> None:
|
def declare_variables(uop: Uop, out: CWriter, skip_inputs: bool) -> None:
|
||||||
|
@ -148,7 +148,7 @@ def write_uop(
|
||||||
if not var.peek or is_override:
|
if not var.peek or is_override:
|
||||||
out.emit(stack.push(var))
|
out.emit(stack.push(var))
|
||||||
out.start_line()
|
out.start_line()
|
||||||
stack.flush(out, cast_type="_Py_UOpsSymType *")
|
stack.flush(out, cast_type="_Py_UopsSymbol *")
|
||||||
except SizeMismatch as ex:
|
except SizeMismatch as ex:
|
||||||
raise analysis_error(ex.args[0], uop.body[0])
|
raise analysis_error(ex.args[0], uop.body[0])
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue