mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
GH-118910: Less boilerplate in the tier 2 optimizer (#118913)
This commit is contained in:
parent
941eea0a27
commit
f5c6b9977a
7 changed files with 275 additions and 473 deletions
|
@ -93,7 +93,9 @@ typedef struct ty_arena {
|
||||||
} ty_arena;
|
} ty_arena;
|
||||||
|
|
||||||
struct _Py_UOpsContext {
|
struct _Py_UOpsContext {
|
||||||
PyObject_HEAD
|
char done;
|
||||||
|
char out_of_space;
|
||||||
|
bool contradiction;
|
||||||
// The current "executing" frame.
|
// The current "executing" frame.
|
||||||
_Py_UOpsAbstractFrame *frame;
|
_Py_UOpsAbstractFrame *frame;
|
||||||
_Py_UOpsAbstractFrame frames[MAX_ABSTRACT_FRAME_DEPTH];
|
_Py_UOpsAbstractFrame frames[MAX_ABSTRACT_FRAME_DEPTH];
|
||||||
|
@ -121,16 +123,16 @@ extern _Py_UopsSymbol *_Py_uop_sym_new_const(_Py_UOpsContext *ctx, PyObject *con
|
||||||
extern _Py_UopsSymbol *_Py_uop_sym_new_null(_Py_UOpsContext *ctx);
|
extern _Py_UopsSymbol *_Py_uop_sym_new_null(_Py_UOpsContext *ctx);
|
||||||
extern bool _Py_uop_sym_has_type(_Py_UopsSymbol *sym);
|
extern bool _Py_uop_sym_has_type(_Py_UopsSymbol *sym);
|
||||||
extern bool _Py_uop_sym_matches_type(_Py_UopsSymbol *sym, PyTypeObject *typ);
|
extern bool _Py_uop_sym_matches_type(_Py_UopsSymbol *sym, PyTypeObject *typ);
|
||||||
extern bool _Py_uop_sym_set_null(_Py_UopsSymbol *sym);
|
extern void _Py_uop_sym_set_null(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym);
|
||||||
extern bool _Py_uop_sym_set_non_null(_Py_UopsSymbol *sym);
|
extern void _Py_uop_sym_set_non_null(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym);
|
||||||
extern bool _Py_uop_sym_set_type(_Py_UopsSymbol *sym, PyTypeObject *typ);
|
extern void _Py_uop_sym_set_type(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym, PyTypeObject *typ);
|
||||||
extern bool _Py_uop_sym_set_const(_Py_UopsSymbol *sym, PyObject *const_val);
|
extern void _Py_uop_sym_set_const(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym, PyObject *const_val);
|
||||||
extern bool _Py_uop_sym_is_bottom(_Py_UopsSymbol *sym);
|
extern bool _Py_uop_sym_is_bottom(_Py_UopsSymbol *sym);
|
||||||
extern int _Py_uop_sym_truthiness(_Py_UopsSymbol *sym);
|
extern int _Py_uop_sym_truthiness(_Py_UopsSymbol *sym);
|
||||||
extern PyTypeObject *_Py_uop_sym_get_type(_Py_UopsSymbol *sym);
|
extern PyTypeObject *_Py_uop_sym_get_type(_Py_UopsSymbol *sym);
|
||||||
|
|
||||||
|
|
||||||
extern int _Py_uop_abstractcontext_init(_Py_UOpsContext *ctx);
|
extern void _Py_uop_abstractcontext_init(_Py_UOpsContext *ctx);
|
||||||
extern void _Py_uop_abstractcontext_fini(_Py_UOpsContext *ctx);
|
extern void _Py_uop_abstractcontext_fini(_Py_UOpsContext *ctx);
|
||||||
|
|
||||||
extern _Py_UOpsAbstractFrame *_Py_uop_frame_new(
|
extern _Py_UOpsAbstractFrame *_Py_uop_frame_new(
|
||||||
|
|
|
@ -909,7 +909,6 @@ class TestGeneratedAbstractCases(unittest.TestCase):
|
||||||
case OP2: {
|
case OP2: {
|
||||||
_Py_UopsSymbol *out;
|
_Py_UopsSymbol *out;
|
||||||
out = sym_new_not_null(ctx);
|
out = sym_new_not_null(ctx);
|
||||||
if (out == NULL) goto out_of_space;
|
|
||||||
stack_pointer[-1] = out;
|
stack_pointer[-1] = out;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -934,7 +933,6 @@ class TestGeneratedAbstractCases(unittest.TestCase):
|
||||||
case OP: {
|
case OP: {
|
||||||
_Py_UopsSymbol *out;
|
_Py_UopsSymbol *out;
|
||||||
out = sym_new_not_null(ctx);
|
out = sym_new_not_null(ctx);
|
||||||
if (out == NULL) goto out_of_space;
|
|
||||||
stack_pointer[-1] = out;
|
stack_pointer[-1] = out;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -297,20 +297,6 @@ remove_globals(_PyInterpreterFrame *frame, _PyUOpInstruction *buffer,
|
||||||
INST->oparg = ARG; \
|
INST->oparg = ARG; \
|
||||||
INST->operand = OPERAND;
|
INST->operand = OPERAND;
|
||||||
|
|
||||||
#define OUT_OF_SPACE_IF_NULL(EXPR) \
|
|
||||||
do { \
|
|
||||||
if ((EXPR) == NULL) { \
|
|
||||||
goto out_of_space; \
|
|
||||||
} \
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
#define _LOAD_ATTR_NOT_NULL \
|
|
||||||
do { \
|
|
||||||
OUT_OF_SPACE_IF_NULL(attr = _Py_uop_sym_new_not_null(ctx)); \
|
|
||||||
OUT_OF_SPACE_IF_NULL(null = _Py_uop_sym_new_null(ctx)); \
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
|
|
||||||
/* Shortened forms for convenience, used in optimizer_bytecodes.c */
|
/* Shortened forms for convenience, used in optimizer_bytecodes.c */
|
||||||
#define sym_is_not_null _Py_uop_sym_is_not_null
|
#define sym_is_not_null _Py_uop_sym_is_not_null
|
||||||
#define sym_is_const _Py_uop_sym_is_const
|
#define sym_is_const _Py_uop_sym_is_const
|
||||||
|
@ -324,10 +310,10 @@ remove_globals(_PyInterpreterFrame *frame, _PyUOpInstruction *buffer,
|
||||||
#define sym_has_type _Py_uop_sym_has_type
|
#define sym_has_type _Py_uop_sym_has_type
|
||||||
#define sym_get_type _Py_uop_sym_get_type
|
#define sym_get_type _Py_uop_sym_get_type
|
||||||
#define sym_matches_type _Py_uop_sym_matches_type
|
#define sym_matches_type _Py_uop_sym_matches_type
|
||||||
#define sym_set_null _Py_uop_sym_set_null
|
#define sym_set_null(SYM) _Py_uop_sym_set_null(ctx, SYM)
|
||||||
#define sym_set_non_null _Py_uop_sym_set_non_null
|
#define sym_set_non_null(SYM) _Py_uop_sym_set_non_null(ctx, SYM)
|
||||||
#define sym_set_type _Py_uop_sym_set_type
|
#define sym_set_type(SYM, TYPE) _Py_uop_sym_set_type(ctx, SYM, TYPE)
|
||||||
#define sym_set_const _Py_uop_sym_set_const
|
#define sym_set_const(SYM, CNST) _Py_uop_sym_set_const(ctx, SYM, CNST)
|
||||||
#define sym_is_bottom _Py_uop_sym_is_bottom
|
#define sym_is_bottom _Py_uop_sym_is_bottom
|
||||||
#define sym_truthiness _Py_uop_sym_truthiness
|
#define sym_truthiness _Py_uop_sym_truthiness
|
||||||
#define frame_new _Py_uop_frame_new
|
#define frame_new _Py_uop_frame_new
|
||||||
|
@ -408,18 +394,20 @@ optimize_uops(
|
||||||
_PyUOpInstruction *first_valid_check_stack = NULL;
|
_PyUOpInstruction *first_valid_check_stack = NULL;
|
||||||
_PyUOpInstruction *corresponding_check_stack = NULL;
|
_PyUOpInstruction *corresponding_check_stack = NULL;
|
||||||
|
|
||||||
if (_Py_uop_abstractcontext_init(ctx) < 0) {
|
_Py_uop_abstractcontext_init(ctx);
|
||||||
goto out_of_space;
|
|
||||||
}
|
|
||||||
_Py_UOpsAbstractFrame *frame = _Py_uop_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;
|
||||||
}
|
}
|
||||||
ctx->curr_frame_depth++;
|
ctx->curr_frame_depth++;
|
||||||
ctx->frame = frame;
|
ctx->frame = frame;
|
||||||
|
ctx->done = false;
|
||||||
|
ctx->out_of_space = false;
|
||||||
|
ctx->contradiction = false;
|
||||||
|
|
||||||
_PyUOpInstruction *this_instr = NULL;
|
_PyUOpInstruction *this_instr = NULL;
|
||||||
for (int i = 0; i < trace_len; i++) {
|
for (int i = 0; !ctx->done; i++) {
|
||||||
|
assert(i < trace_len);
|
||||||
this_instr = &trace[i];
|
this_instr = &trace[i];
|
||||||
|
|
||||||
int oparg = this_instr->oparg;
|
int oparg = this_instr->oparg;
|
||||||
|
@ -447,32 +435,22 @@ optimize_uops(
|
||||||
ctx->frame->stack_pointer = stack_pointer;
|
ctx->frame->stack_pointer = stack_pointer;
|
||||||
assert(STACK_LEVEL() >= 0);
|
assert(STACK_LEVEL() >= 0);
|
||||||
}
|
}
|
||||||
Py_UNREACHABLE();
|
if (ctx->out_of_space) {
|
||||||
|
DPRINTF(3, "\n");
|
||||||
out_of_space:
|
DPRINTF(1, "Out of space in abstract interpreter\n");
|
||||||
DPRINTF(3, "\n");
|
}
|
||||||
DPRINTF(1, "Out of space in abstract interpreter\n");
|
if (ctx->contradiction) {
|
||||||
goto done;
|
// Attempted to push a "bottom" (contradiction) symbol onto the stack.
|
||||||
error:
|
// This means that the abstract interpreter has hit unreachable code.
|
||||||
DPRINTF(3, "\n");
|
// We *could* generate an _EXIT_TRACE or _FATAL_ERROR here, but hitting
|
||||||
DPRINTF(1, "Encountered error in abstract interpreter\n");
|
// bottom indicates type instability, so we are probably better off
|
||||||
if (opcode <= MAX_UOP_ID) {
|
// retrying later.
|
||||||
OPT_ERROR_IN_OPCODE(opcode);
|
DPRINTF(3, "\n");
|
||||||
|
DPRINTF(1, "Hit bottom in abstract interpreter\n");
|
||||||
|
_Py_uop_abstractcontext_fini(ctx);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
_Py_uop_abstractcontext_fini(ctx);
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
hit_bottom:
|
|
||||||
// Attempted to push a "bottom" (contradition) symbol onto the stack.
|
|
||||||
// This means that the abstract interpreter has hit unreachable code.
|
|
||||||
// We *could* generate an _EXIT_TRACE or _FATAL_ERROR here, but hitting
|
|
||||||
// bottom indicates type instability, so we are probably better off
|
|
||||||
// retrying later.
|
|
||||||
DPRINTF(3, "\n");
|
|
||||||
DPRINTF(1, "Hit bottom in abstract interpreter\n");
|
|
||||||
_Py_uop_abstractcontext_fini(ctx);
|
|
||||||
return 0;
|
|
||||||
done:
|
|
||||||
/* Either reached the end or cannot optimize further, but there
|
/* Either reached the end or cannot optimize further, but there
|
||||||
* would be no benefit in retrying later */
|
* would be no benefit in retrying later */
|
||||||
_Py_uop_abstractcontext_fini(ctx);
|
_Py_uop_abstractcontext_fini(ctx);
|
||||||
|
@ -485,6 +463,16 @@ done:
|
||||||
first_valid_check_stack->operand = max_space;
|
first_valid_check_stack->operand = max_space;
|
||||||
}
|
}
|
||||||
return trace_len;
|
return trace_len;
|
||||||
|
|
||||||
|
error:
|
||||||
|
DPRINTF(3, "\n");
|
||||||
|
DPRINTF(1, "Encountered error in abstract interpreter\n");
|
||||||
|
if (opcode <= MAX_UOP_ID) {
|
||||||
|
OPT_ERROR_IN_OPCODE(opcode);
|
||||||
|
}
|
||||||
|
_Py_uop_abstractcontext_fini(ctx);
|
||||||
|
return -1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,10 +23,10 @@ typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame;
|
||||||
#define sym_matches_type _Py_uop_sym_matches_type
|
#define sym_matches_type _Py_uop_sym_matches_type
|
||||||
#define sym_get_type _Py_uop_sym_get_type
|
#define sym_get_type _Py_uop_sym_get_type
|
||||||
#define sym_has_type _Py_uop_sym_has_type
|
#define sym_has_type _Py_uop_sym_has_type
|
||||||
#define sym_set_null _Py_uop_sym_set_null
|
#define sym_set_null(SYM) _Py_uop_sym_set_null(ctx, SYM)
|
||||||
#define sym_set_non_null _Py_uop_sym_set_non_null
|
#define sym_set_non_null(SYM) _Py_uop_sym_set_non_null(ctx, SYM)
|
||||||
#define sym_set_type _Py_uop_sym_set_type
|
#define sym_set_type(SYM, TYPE) _Py_uop_sym_set_type(ctx, SYM, TYPE)
|
||||||
#define sym_set_const _Py_uop_sym_set_const
|
#define sym_set_const(SYM, CNST) _Py_uop_sym_set_const(ctx, SYM, CNST)
|
||||||
#define sym_is_bottom _Py_uop_sym_is_bottom
|
#define sym_is_bottom _Py_uop_sym_is_bottom
|
||||||
#define frame_new _Py_uop_frame_new
|
#define frame_new _Py_uop_frame_new
|
||||||
#define frame_pop _Py_uop_frame_pop
|
#define frame_pop _Py_uop_frame_pop
|
||||||
|
@ -73,7 +73,7 @@ dummy_func(void) {
|
||||||
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 (sym_is_null(value)) {
|
if (sym_is_null(value)) {
|
||||||
goto out_of_space;
|
ctx->done = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,8 +83,7 @@ dummy_func(void) {
|
||||||
|
|
||||||
op(_LOAD_FAST_AND_CLEAR, (-- value)) {
|
op(_LOAD_FAST_AND_CLEAR, (-- value)) {
|
||||||
value = GETLOCAL(oparg);
|
value = GETLOCAL(oparg);
|
||||||
_Py_UopsSymbol *temp;
|
_Py_UopsSymbol *temp = sym_new_null(ctx);
|
||||||
OUT_OF_SPACE_IF_NULL(temp = sym_new_null(ctx));
|
|
||||||
GETLOCAL(oparg) = temp;
|
GETLOCAL(oparg) = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,9 +93,6 @@ dummy_func(void) {
|
||||||
|
|
||||||
op(_PUSH_NULL, (-- res)) {
|
op(_PUSH_NULL, (-- res)) {
|
||||||
res = sym_new_null(ctx);
|
res = sym_new_null(ctx);
|
||||||
if (res == NULL) {
|
|
||||||
goto out_of_space;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_GUARD_BOTH_INT, (left, right -- left, right)) {
|
op(_GUARD_BOTH_INT, (left, right -- left, right)) {
|
||||||
|
@ -113,12 +109,8 @@ dummy_func(void) {
|
||||||
REPLACE_OP(this_instr, _GUARD_NOS_INT, 0, 0);
|
REPLACE_OP(this_instr, _GUARD_NOS_INT, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!sym_set_type(left, &PyLong_Type)) {
|
sym_set_type(left, &PyLong_Type);
|
||||||
goto hit_bottom;
|
sym_set_type(right, &PyLong_Type);
|
||||||
}
|
|
||||||
if (!sym_set_type(right, &PyLong_Type)) {
|
|
||||||
goto hit_bottom;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_GUARD_BOTH_FLOAT, (left, right -- left, right)) {
|
op(_GUARD_BOTH_FLOAT, (left, right -- left, right)) {
|
||||||
|
@ -135,12 +127,9 @@ dummy_func(void) {
|
||||||
REPLACE_OP(this_instr, _GUARD_NOS_FLOAT, 0, 0);
|
REPLACE_OP(this_instr, _GUARD_NOS_FLOAT, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!sym_set_type(left, &PyFloat_Type)) {
|
|
||||||
goto hit_bottom;
|
sym_set_type(left, &PyFloat_Type);
|
||||||
}
|
sym_set_type(right, &PyFloat_Type);
|
||||||
if (!sym_set_type(right, &PyFloat_Type)) {
|
|
||||||
goto hit_bottom;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_GUARD_BOTH_UNICODE, (left, right -- left, right)) {
|
op(_GUARD_BOTH_UNICODE, (left, right -- left, right)) {
|
||||||
|
@ -148,12 +137,8 @@ dummy_func(void) {
|
||||||
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);
|
||||||
}
|
}
|
||||||
if (!sym_set_type(left, &PyUnicode_Type)) {
|
sym_set_type(left, &PyUnicode_Type);
|
||||||
goto hit_bottom;
|
sym_set_type(left, &PyUnicode_Type);
|
||||||
}
|
|
||||||
if (!sym_set_type(right, &PyUnicode_Type)) {
|
|
||||||
goto hit_bottom;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_BINARY_OP, (left, right -- res)) {
|
op(_BINARY_OP, (left, right -- res)) {
|
||||||
|
@ -165,14 +150,14 @@ dummy_func(void) {
|
||||||
if (oparg != NB_TRUE_DIVIDE && oparg != NB_INPLACE_TRUE_DIVIDE &&
|
if (oparg != NB_TRUE_DIVIDE && oparg != NB_INPLACE_TRUE_DIVIDE &&
|
||||||
ltype == &PyLong_Type && rtype == &PyLong_Type) {
|
ltype == &PyLong_Type && rtype == &PyLong_Type) {
|
||||||
/* If both inputs are ints and the op is not division the result is an int */
|
/* If both inputs are ints and the op is not division the result is an int */
|
||||||
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyLong_Type));
|
res = sym_new_type(ctx, &PyLong_Type);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* For any other op combining ints/floats the result is a float */
|
/* For any other op combining ints/floats the result is a float */
|
||||||
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyFloat_Type));
|
res = sym_new_type(ctx, &PyFloat_Type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OUT_OF_SPACE_IF_NULL(res = sym_new_unknown(ctx));
|
res = sym_new_unknown(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_BINARY_OP_ADD_INT, (left, right -- res)) {
|
op(_BINARY_OP_ADD_INT, (left, right -- res)) {
|
||||||
|
@ -188,12 +173,11 @@ dummy_func(void) {
|
||||||
}
|
}
|
||||||
res = sym_new_const(ctx, temp);
|
res = sym_new_const(ctx, temp);
|
||||||
Py_DECREF(temp);
|
Py_DECREF(temp);
|
||||||
OUT_OF_SPACE_IF_NULL(res);
|
|
||||||
// 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 = sym_new_type(ctx, &PyLong_Type));
|
res = sym_new_type(ctx, &PyLong_Type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,12 +194,11 @@ dummy_func(void) {
|
||||||
}
|
}
|
||||||
res = sym_new_const(ctx, temp);
|
res = sym_new_const(ctx, temp);
|
||||||
Py_DECREF(temp);
|
Py_DECREF(temp);
|
||||||
OUT_OF_SPACE_IF_NULL(res);
|
|
||||||
// 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 = sym_new_type(ctx, &PyLong_Type));
|
res = sym_new_type(ctx, &PyLong_Type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,12 +215,11 @@ dummy_func(void) {
|
||||||
}
|
}
|
||||||
res = sym_new_const(ctx, temp);
|
res = sym_new_const(ctx, temp);
|
||||||
Py_DECREF(temp);
|
Py_DECREF(temp);
|
||||||
OUT_OF_SPACE_IF_NULL(res);
|
|
||||||
// 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 = sym_new_type(ctx, &PyLong_Type));
|
res = sym_new_type(ctx, &PyLong_Type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,12 +237,11 @@ dummy_func(void) {
|
||||||
}
|
}
|
||||||
res = sym_new_const(ctx, temp);
|
res = sym_new_const(ctx, temp);
|
||||||
Py_DECREF(temp);
|
Py_DECREF(temp);
|
||||||
OUT_OF_SPACE_IF_NULL(res);
|
|
||||||
// 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 = sym_new_type(ctx, &PyFloat_Type));
|
res = sym_new_type(ctx, &PyFloat_Type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,12 +259,11 @@ dummy_func(void) {
|
||||||
}
|
}
|
||||||
res = sym_new_const(ctx, temp);
|
res = sym_new_const(ctx, temp);
|
||||||
Py_DECREF(temp);
|
Py_DECREF(temp);
|
||||||
OUT_OF_SPACE_IF_NULL(res);
|
|
||||||
// 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 = sym_new_type(ctx, &PyFloat_Type));
|
res = sym_new_type(ctx, &PyFloat_Type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,12 +281,11 @@ dummy_func(void) {
|
||||||
}
|
}
|
||||||
res = sym_new_const(ctx, temp);
|
res = sym_new_const(ctx, temp);
|
||||||
Py_DECREF(temp);
|
Py_DECREF(temp);
|
||||||
OUT_OF_SPACE_IF_NULL(res);
|
|
||||||
// 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 = sym_new_type(ctx, &PyFloat_Type));
|
res = sym_new_type(ctx, &PyFloat_Type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,80 +298,50 @@ dummy_func(void) {
|
||||||
}
|
}
|
||||||
res = sym_new_const(ctx, temp);
|
res = sym_new_const(ctx, temp);
|
||||||
Py_DECREF(temp);
|
Py_DECREF(temp);
|
||||||
OUT_OF_SPACE_IF_NULL(res);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyUnicode_Type));
|
res = sym_new_type(ctx, &PyUnicode_Type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_TO_BOOL, (value -- res)) {
|
op(_TO_BOOL, (value -- res)) {
|
||||||
if (optimize_to_bool(this_instr, ctx, value, &res)) {
|
if (!optimize_to_bool(this_instr, ctx, value, &res)) {
|
||||||
OUT_OF_SPACE_IF_NULL(res);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
res = sym_new_type(ctx, &PyBool_Type);
|
res = sym_new_type(ctx, &PyBool_Type);
|
||||||
OUT_OF_SPACE_IF_NULL(res);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_TO_BOOL_BOOL, (value -- res)) {
|
op(_TO_BOOL_BOOL, (value -- res)) {
|
||||||
if (optimize_to_bool(this_instr, ctx, value, &res)) {
|
if (!optimize_to_bool(this_instr, ctx, value, &res)) {
|
||||||
OUT_OF_SPACE_IF_NULL(res);
|
sym_set_type(value, &PyBool_Type);
|
||||||
}
|
|
||||||
else {
|
|
||||||
if(!sym_set_type(value, &PyBool_Type)) {
|
|
||||||
goto hit_bottom;
|
|
||||||
}
|
|
||||||
res = value;
|
res = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_TO_BOOL_INT, (value -- res)) {
|
op(_TO_BOOL_INT, (value -- res)) {
|
||||||
if (optimize_to_bool(this_instr, ctx, value, &res)) {
|
if (!optimize_to_bool(this_instr, ctx, value, &res)) {
|
||||||
OUT_OF_SPACE_IF_NULL(res);
|
sym_set_type(value, &PyLong_Type);
|
||||||
}
|
res = sym_new_type(ctx, &PyBool_Type);
|
||||||
else {
|
|
||||||
if(!sym_set_type(value, &PyLong_Type)) {
|
|
||||||
goto hit_bottom;
|
|
||||||
}
|
|
||||||
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_TO_BOOL_LIST, (value -- res)) {
|
op(_TO_BOOL_LIST, (value -- res)) {
|
||||||
if (optimize_to_bool(this_instr, ctx, value, &res)) {
|
if (!optimize_to_bool(this_instr, ctx, value, &res)) {
|
||||||
OUT_OF_SPACE_IF_NULL(res);
|
sym_set_type(value, &PyList_Type);
|
||||||
}
|
res = sym_new_type(ctx, &PyBool_Type);
|
||||||
else {
|
|
||||||
if(!sym_set_type(value, &PyList_Type)) {
|
|
||||||
goto hit_bottom;
|
|
||||||
}
|
|
||||||
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_TO_BOOL_NONE, (value -- res)) {
|
op(_TO_BOOL_NONE, (value -- res)) {
|
||||||
if (optimize_to_bool(this_instr, ctx, value, &res)) {
|
if (!optimize_to_bool(this_instr, ctx, value, &res)) {
|
||||||
OUT_OF_SPACE_IF_NULL(res);
|
sym_set_const(value, Py_None);
|
||||||
}
|
res = sym_new_const(ctx, Py_False);
|
||||||
else {
|
|
||||||
if (!sym_set_const(value, Py_None)) {
|
|
||||||
goto hit_bottom;
|
|
||||||
}
|
|
||||||
OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, Py_False));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_TO_BOOL_STR, (value -- res)) {
|
op(_TO_BOOL_STR, (value -- res)) {
|
||||||
if (optimize_to_bool(this_instr, ctx, value, &res)) {
|
if (!optimize_to_bool(this_instr, ctx, value, &res)) {
|
||||||
OUT_OF_SPACE_IF_NULL(res);
|
res = sym_new_type(ctx, &PyBool_Type);
|
||||||
}
|
sym_set_type(value, &PyUnicode_Type);
|
||||||
else {
|
|
||||||
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
|
|
||||||
if(!sym_set_type(value, &PyUnicode_Type)) {
|
|
||||||
goto hit_bottom;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,66 +349,66 @@ dummy_func(void) {
|
||||||
(void)left;
|
(void)left;
|
||||||
(void)right;
|
(void)right;
|
||||||
if (oparg & 16) {
|
if (oparg & 16) {
|
||||||
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
|
res = sym_new_type(ctx, &PyBool_Type);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
OUT_OF_SPACE_IF_NULL(res = _Py_uop_sym_new_not_null(ctx));
|
res = _Py_uop_sym_new_not_null(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_COMPARE_OP_INT, (left, right -- res)) {
|
op(_COMPARE_OP_INT, (left, right -- res)) {
|
||||||
(void)left;
|
(void)left;
|
||||||
(void)right;
|
(void)right;
|
||||||
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
|
res = sym_new_type(ctx, &PyBool_Type);
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_COMPARE_OP_FLOAT, (left, right -- res)) {
|
op(_COMPARE_OP_FLOAT, (left, right -- res)) {
|
||||||
(void)left;
|
(void)left;
|
||||||
(void)right;
|
(void)right;
|
||||||
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
|
res = sym_new_type(ctx, &PyBool_Type);
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_COMPARE_OP_STR, (left, right -- res)) {
|
op(_COMPARE_OP_STR, (left, right -- res)) {
|
||||||
(void)left;
|
(void)left;
|
||||||
(void)right;
|
(void)right;
|
||||||
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
|
res = sym_new_type(ctx, &PyBool_Type);
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_IS_OP, (left, right -- res)) {
|
op(_IS_OP, (left, right -- res)) {
|
||||||
(void)left;
|
(void)left;
|
||||||
(void)right;
|
(void)right;
|
||||||
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
|
res = sym_new_type(ctx, &PyBool_Type);
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_CONTAINS_OP, (left, right -- res)) {
|
op(_CONTAINS_OP, (left, right -- res)) {
|
||||||
(void)left;
|
(void)left;
|
||||||
(void)right;
|
(void)right;
|
||||||
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
|
res = sym_new_type(ctx, &PyBool_Type);
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_LOAD_CONST, (-- value)) {
|
op(_LOAD_CONST, (-- value)) {
|
||||||
PyObject *val = PyTuple_GET_ITEM(co->co_consts, this_instr->oparg);
|
PyObject *val = PyTuple_GET_ITEM(co->co_consts, this_instr->oparg);
|
||||||
int opcode = _Py_IsImmortal(val) ? _LOAD_CONST_INLINE_BORROW : _LOAD_CONST_INLINE;
|
int opcode = _Py_IsImmortal(val) ? _LOAD_CONST_INLINE_BORROW : _LOAD_CONST_INLINE;
|
||||||
REPLACE_OP(this_instr, opcode, 0, (uintptr_t)val);
|
REPLACE_OP(this_instr, opcode, 0, (uintptr_t)val);
|
||||||
OUT_OF_SPACE_IF_NULL(value = sym_new_const(ctx, val));
|
value = sym_new_const(ctx, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_LOAD_CONST_INLINE, (ptr/4 -- value)) {
|
op(_LOAD_CONST_INLINE, (ptr/4 -- value)) {
|
||||||
OUT_OF_SPACE_IF_NULL(value = sym_new_const(ctx, ptr));
|
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 = sym_new_const(ctx, ptr));
|
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 = sym_new_const(ctx, ptr));
|
value = sym_new_const(ctx, ptr);
|
||||||
OUT_OF_SPACE_IF_NULL(null = sym_new_null(ctx));
|
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 = sym_new_const(ctx, ptr));
|
value = sym_new_const(ctx, ptr);
|
||||||
OUT_OF_SPACE_IF_NULL(null = sym_new_null(ctx));
|
null = sym_new_null(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_COPY, (bottom, unused[oparg-1] -- bottom, unused[oparg-1], top)) {
|
op(_COPY, (bottom, unused[oparg-1] -- bottom, unused[oparg-1], top)) {
|
||||||
|
@ -472,7 +421,8 @@ dummy_func(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_LOAD_ATTR_INSTANCE_VALUE, (index/1, owner -- attr, null if (oparg & 1))) {
|
op(_LOAD_ATTR_INSTANCE_VALUE, (index/1, owner -- attr, null if (oparg & 1))) {
|
||||||
_LOAD_ATTR_NOT_NULL
|
attr = sym_new_not_null(ctx);
|
||||||
|
null = sym_new_null(ctx);
|
||||||
(void)index;
|
(void)index;
|
||||||
(void)owner;
|
(void)owner;
|
||||||
}
|
}
|
||||||
|
@ -496,15 +446,15 @@ dummy_func(void) {
|
||||||
|
|
||||||
op(_LOAD_ATTR, (owner -- attr, self_or_null if (oparg & 1))) {
|
op(_LOAD_ATTR, (owner -- attr, self_or_null if (oparg & 1))) {
|
||||||
(void)owner;
|
(void)owner;
|
||||||
OUT_OF_SPACE_IF_NULL(attr = sym_new_not_null(ctx));
|
attr = sym_new_not_null(ctx);
|
||||||
if (oparg & 1) {
|
if (oparg & 1) {
|
||||||
OUT_OF_SPACE_IF_NULL(self_or_null = sym_new_unknown(ctx));
|
self_or_null = sym_new_unknown(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = sym_new_null(ctx));
|
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.
|
||||||
|
@ -515,72 +465,69 @@ dummy_func(void) {
|
||||||
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 = sym_new_const(ctx, res));
|
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 = sym_new_not_null(ctx));
|
attr = sym_new_not_null(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_LOAD_ATTR_WITH_HINT, (hint/1, owner -- attr, null if (oparg & 1))) {
|
op(_LOAD_ATTR_WITH_HINT, (hint/1, owner -- attr, null if (oparg & 1))) {
|
||||||
_LOAD_ATTR_NOT_NULL
|
attr = sym_new_not_null(ctx);
|
||||||
|
null = sym_new_null(ctx);
|
||||||
(void)hint;
|
(void)hint;
|
||||||
(void)owner;
|
(void)owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_LOAD_ATTR_SLOT, (index/1, owner -- attr, null if (oparg & 1))) {
|
op(_LOAD_ATTR_SLOT, (index/1, owner -- attr, null if (oparg & 1))) {
|
||||||
_LOAD_ATTR_NOT_NULL
|
attr = sym_new_not_null(ctx);
|
||||||
|
null = sym_new_null(ctx);
|
||||||
(void)index;
|
(void)index;
|
||||||
(void)owner;
|
(void)owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_LOAD_ATTR_CLASS, (descr/4, owner -- attr, null if (oparg & 1))) {
|
op(_LOAD_ATTR_CLASS, (descr/4, owner -- attr, null if (oparg & 1))) {
|
||||||
_LOAD_ATTR_NOT_NULL
|
attr = sym_new_not_null(ctx);
|
||||||
|
null = sym_new_null(ctx);
|
||||||
(void)descr;
|
(void)descr;
|
||||||
(void)owner;
|
(void)owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = sym_new_not_null(ctx));
|
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 = sym_new_not_null(ctx));
|
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 = sym_new_not_null(ctx));
|
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 = sym_new_not_null(ctx));
|
func = sym_new_not_null(ctx);
|
||||||
OUT_OF_SPACE_IF_NULL(self = sym_new_not_null(ctx));
|
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])) {
|
||||||
if (!sym_set_type(callable, &PyFunction_Type)) {
|
sym_set_type(callable, &PyFunction_Type);
|
||||||
goto hit_bottom;
|
|
||||||
}
|
|
||||||
(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])) {
|
||||||
if (!sym_set_null(null)) {
|
sym_set_null(null);
|
||||||
goto hit_bottom;
|
sym_set_type(callable, &PyMethod_Type);
|
||||||
}
|
|
||||||
if (!sym_set_type(callable, &PyMethod_Type)) {
|
|
||||||
goto hit_bottom;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 *)) {
|
||||||
|
@ -602,7 +549,8 @@ dummy_func(void) {
|
||||||
if (func == NULL) {
|
if (func == NULL) {
|
||||||
DPRINTF(3, "\n");
|
DPRINTF(3, "\n");
|
||||||
DPRINTF(1, "Missing function\n");
|
DPRINTF(1, "Missing function\n");
|
||||||
goto done;
|
ctx->done = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
co = (PyCodeObject *)func->func_code;
|
co = (PyCodeObject *)func->func_code;
|
||||||
DPRINTF(3, "code=%p ", co);
|
DPRINTF(3, "code=%p ", co);
|
||||||
|
@ -625,8 +573,7 @@ dummy_func(void) {
|
||||||
localsplus_start = args;
|
localsplus_start = args;
|
||||||
n_locals_already_filled = argcount;
|
n_locals_already_filled = argcount;
|
||||||
}
|
}
|
||||||
OUT_OF_SPACE_IF_NULL(new_frame =
|
new_frame = frame_new(ctx, co, localsplus_start, n_locals_already_filled, 0);
|
||||||
frame_new(ctx, co, localsplus_start, n_locals_already_filled, 0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_PY_FRAME_GENERAL, (callable, self_or_null, args[oparg] -- new_frame: _Py_UOpsAbstractFrame *)) {
|
op(_PY_FRAME_GENERAL, (callable, self_or_null, args[oparg] -- new_frame: _Py_UOpsAbstractFrame *)) {
|
||||||
|
@ -635,7 +582,8 @@ dummy_func(void) {
|
||||||
(void)self_or_null;
|
(void)self_or_null;
|
||||||
(void)args;
|
(void)args;
|
||||||
first_valid_check_stack = NULL;
|
first_valid_check_stack = NULL;
|
||||||
goto done;
|
new_frame = NULL;
|
||||||
|
ctx->done = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_POP_FRAME, (retval -- res)) {
|
op(_POP_FRAME, (retval -- res)) {
|
||||||
|
@ -656,7 +604,7 @@ dummy_func(void) {
|
||||||
co = get_code(this_instr);
|
co = get_code(this_instr);
|
||||||
if (co == NULL) {
|
if (co == NULL) {
|
||||||
// might be impossible, but bailing is still safe
|
// might be impossible, but bailing is still safe
|
||||||
goto done;
|
ctx->done = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -665,7 +613,7 @@ dummy_func(void) {
|
||||||
ctx->frame->stack_pointer = stack_pointer;
|
ctx->frame->stack_pointer = stack_pointer;
|
||||||
frame_pop(ctx);
|
frame_pop(ctx);
|
||||||
stack_pointer = ctx->frame->stack_pointer;
|
stack_pointer = ctx->frame->stack_pointer;
|
||||||
OUT_OF_SPACE_IF_NULL(res = sym_new_unknown(ctx));
|
res = sym_new_unknown(ctx);
|
||||||
|
|
||||||
/* Stack space handling */
|
/* Stack space handling */
|
||||||
assert(corresponding_check_stack == NULL);
|
assert(corresponding_check_stack == NULL);
|
||||||
|
@ -678,17 +626,17 @@ dummy_func(void) {
|
||||||
co = get_code(this_instr);
|
co = get_code(this_instr);
|
||||||
if (co == NULL) {
|
if (co == NULL) {
|
||||||
// might be impossible, but bailing is still safe
|
// might be impossible, but bailing is still safe
|
||||||
goto done;
|
ctx->done = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_YIELD_VALUE, (unused -- res)) {
|
op(_YIELD_VALUE, (unused -- res)) {
|
||||||
OUT_OF_SPACE_IF_NULL(res = sym_new_unknown(ctx));
|
res = sym_new_unknown(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_FOR_ITER_GEN_FRAME, ( -- )) {
|
op(_FOR_ITER_GEN_FRAME, ( -- )) {
|
||||||
/* We are about to hit the end of the trace */
|
/* We are about to hit the end of the trace */
|
||||||
goto done;
|
ctx->done = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_CHECK_STACK_SPACE, ( --)) {
|
op(_CHECK_STACK_SPACE, ( --)) {
|
||||||
|
@ -712,7 +660,8 @@ dummy_func(void) {
|
||||||
co = get_code(this_instr);
|
co = get_code(this_instr);
|
||||||
if (co == NULL) {
|
if (co == NULL) {
|
||||||
// should be about to _EXIT_TRACE anyway
|
// should be about to _EXIT_TRACE anyway
|
||||||
goto done;
|
ctx->done = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stack space handling */
|
/* Stack space handling */
|
||||||
|
@ -721,7 +670,8 @@ dummy_func(void) {
|
||||||
curr_space += framesize;
|
curr_space += framesize;
|
||||||
if (curr_space < 0 || curr_space > INT32_MAX) {
|
if (curr_space < 0 || curr_space > INT32_MAX) {
|
||||||
// won't fit in signed 32-bit int
|
// won't fit in signed 32-bit int
|
||||||
goto done;
|
ctx->done = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
max_space = curr_space > max_space ? curr_space : max_space;
|
max_space = curr_space > max_space ? curr_space : max_space;
|
||||||
if (first_valid_check_stack == NULL) {
|
if (first_valid_check_stack == NULL) {
|
||||||
|
@ -738,7 +688,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] = sym_new_unknown(ctx));
|
values[i] = sym_new_unknown(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -747,12 +697,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] = sym_new_unknown(ctx));
|
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 = sym_new_type(ctx, &PyLong_Type));
|
next = sym_new_type(ctx, &PyLong_Type);
|
||||||
(void)iter;
|
(void)iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -805,11 +755,11 @@ dummy_func(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_JUMP_TO_TOP, (--)) {
|
op(_JUMP_TO_TOP, (--)) {
|
||||||
goto done;
|
ctx->done = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
op(_EXIT_TRACE, (--)) {
|
op(_EXIT_TRACE, (--)) {
|
||||||
goto done;
|
ctx->done = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
309
Python/optimizer_cases.c.h
generated
309
Python/optimizer_cases.c.h
generated
File diff suppressed because it is too large
Load diff
|
@ -32,6 +32,7 @@
|
||||||
// Flags for below.
|
// Flags for below.
|
||||||
#define IS_NULL 1 << 0
|
#define IS_NULL 1 << 0
|
||||||
#define NOT_NULL 1 << 1
|
#define NOT_NULL 1 << 1
|
||||||
|
#define NO_SPACE 1 << 2
|
||||||
|
|
||||||
#ifdef Py_DEBUG
|
#ifdef Py_DEBUG
|
||||||
static inline int get_lltrace(void) {
|
static inline int get_lltrace(void) {
|
||||||
|
@ -48,6 +49,20 @@ static inline int get_lltrace(void) {
|
||||||
#define DPRINTF(level, ...)
|
#define DPRINTF(level, ...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static _Py_UopsSymbol NO_SPACE_SYMBOL = {
|
||||||
|
.flags = IS_NULL | NOT_NULL | NO_SPACE,
|
||||||
|
.typ = NULL,
|
||||||
|
.const_val = NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
_Py_UopsSymbol *
|
||||||
|
out_of_space(_Py_UOpsContext *ctx)
|
||||||
|
{
|
||||||
|
ctx->done = true;
|
||||||
|
ctx->out_of_space = true;
|
||||||
|
return &NO_SPACE_SYMBOL;
|
||||||
|
}
|
||||||
|
|
||||||
static _Py_UopsSymbol *
|
static _Py_UopsSymbol *
|
||||||
sym_new(_Py_UOpsContext *ctx)
|
sym_new(_Py_UOpsContext *ctx)
|
||||||
{
|
{
|
||||||
|
@ -72,11 +87,13 @@ sym_set_flag(_Py_UopsSymbol *sym, int flag)
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
sym_set_bottom(_Py_UopsSymbol *sym)
|
sym_set_bottom(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym)
|
||||||
{
|
{
|
||||||
sym_set_flag(sym, IS_NULL | NOT_NULL);
|
sym_set_flag(sym, IS_NULL | NOT_NULL);
|
||||||
sym->typ = NULL;
|
sym->typ = NULL;
|
||||||
Py_CLEAR(sym->const_val);
|
Py_CLEAR(sym->const_val);
|
||||||
|
ctx->done = true;
|
||||||
|
ctx->contradiction = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -115,45 +132,41 @@ _Py_uop_sym_get_const(_Py_UopsSymbol *sym)
|
||||||
return sym->const_val;
|
return sym->const_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
void
|
||||||
_Py_uop_sym_set_type(_Py_UopsSymbol *sym, PyTypeObject *typ)
|
_Py_uop_sym_set_type(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym, PyTypeObject *typ)
|
||||||
{
|
{
|
||||||
assert(typ != NULL && PyType_Check(typ));
|
assert(typ != NULL && PyType_Check(typ));
|
||||||
if (sym->flags & IS_NULL) {
|
if (sym->flags & IS_NULL) {
|
||||||
sym_set_bottom(sym);
|
sym_set_bottom(ctx, sym);
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
if (sym->typ != NULL) {
|
if (sym->typ != NULL) {
|
||||||
if (sym->typ != typ) {
|
if (sym->typ != typ) {
|
||||||
sym_set_bottom(sym);
|
sym_set_bottom(ctx, sym);
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sym_set_flag(sym, NOT_NULL);
|
sym_set_flag(sym, NOT_NULL);
|
||||||
sym->typ = typ;
|
sym->typ = typ;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
void
|
||||||
_Py_uop_sym_set_const(_Py_UopsSymbol *sym, PyObject *const_val)
|
_Py_uop_sym_set_const(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym, PyObject *const_val)
|
||||||
{
|
{
|
||||||
assert(const_val != NULL);
|
assert(const_val != NULL);
|
||||||
if (sym->flags & IS_NULL) {
|
if (sym->flags & IS_NULL) {
|
||||||
sym_set_bottom(sym);
|
sym_set_bottom(ctx, sym);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
PyTypeObject *typ = Py_TYPE(const_val);
|
PyTypeObject *typ = Py_TYPE(const_val);
|
||||||
if (sym->typ != NULL && sym->typ != typ) {
|
if (sym->typ != NULL && sym->typ != typ) {
|
||||||
sym_set_bottom(sym);
|
sym_set_bottom(ctx, sym);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
if (sym->const_val != NULL) {
|
if (sym->const_val != NULL) {
|
||||||
if (sym->const_val != const_val) {
|
if (sym->const_val != const_val) {
|
||||||
// TODO: What if they're equal?
|
// TODO: What if they're equal?
|
||||||
sym_set_bottom(sym);
|
sym_set_bottom(ctx, sym);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -161,29 +174,24 @@ _Py_uop_sym_set_const(_Py_UopsSymbol *sym, PyObject *const_val)
|
||||||
sym->typ = typ;
|
sym->typ = typ;
|
||||||
sym->const_val = Py_NewRef(const_val);
|
sym->const_val = Py_NewRef(const_val);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
void
|
||||||
_Py_uop_sym_set_null(_Py_UopsSymbol *sym)
|
_Py_uop_sym_set_null(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym)
|
||||||
{
|
{
|
||||||
if (_Py_uop_sym_is_not_null(sym)) {
|
if (_Py_uop_sym_is_not_null(sym)) {
|
||||||
sym_set_bottom(sym);
|
sym_set_bottom(ctx, sym);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
sym_set_flag(sym, IS_NULL);
|
sym_set_flag(sym, IS_NULL);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
void
|
||||||
_Py_uop_sym_set_non_null(_Py_UopsSymbol *sym)
|
_Py_uop_sym_set_non_null(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym)
|
||||||
{
|
{
|
||||||
if (_Py_uop_sym_is_null(sym)) {
|
if (_Py_uop_sym_is_null(sym)) {
|
||||||
sym_set_bottom(sym);
|
sym_set_bottom(ctx, sym);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
sym_set_flag(sym, NOT_NULL);
|
sym_set_flag(sym, NOT_NULL);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -198,7 +206,7 @@ _Py_uop_sym_new_not_null(_Py_UOpsContext *ctx)
|
||||||
{
|
{
|
||||||
_Py_UopsSymbol *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 out_of_space(ctx);
|
||||||
}
|
}
|
||||||
sym_set_flag(res, NOT_NULL);
|
sym_set_flag(res, NOT_NULL);
|
||||||
return res;
|
return res;
|
||||||
|
@ -209,9 +217,9 @@ _Py_uop_sym_new_type(_Py_UOpsContext *ctx, PyTypeObject *typ)
|
||||||
{
|
{
|
||||||
_Py_UopsSymbol *res = sym_new(ctx);
|
_Py_UopsSymbol *res = sym_new(ctx);
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
return NULL;
|
return out_of_space(ctx);
|
||||||
}
|
}
|
||||||
_Py_uop_sym_set_type(res, typ);
|
_Py_uop_sym_set_type(ctx, res, typ);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,9 +230,9 @@ _Py_uop_sym_new_const(_Py_UOpsContext *ctx, PyObject *const_val)
|
||||||
assert(const_val != NULL);
|
assert(const_val != NULL);
|
||||||
_Py_UopsSymbol *res = sym_new(ctx);
|
_Py_UopsSymbol *res = sym_new(ctx);
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
return NULL;
|
return out_of_space(ctx);
|
||||||
}
|
}
|
||||||
_Py_uop_sym_set_const(res, const_val);
|
_Py_uop_sym_set_const(ctx, res, const_val);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,9 +241,9 @@ _Py_uop_sym_new_null(_Py_UOpsContext *ctx)
|
||||||
{
|
{
|
||||||
_Py_UopsSymbol *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 out_of_space(ctx);
|
||||||
}
|
}
|
||||||
_Py_uop_sym_set_null(null_sym);
|
_Py_uop_sym_set_null(ctx, null_sym);
|
||||||
return null_sym;
|
return null_sym;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,6 +326,8 @@ _Py_uop_frame_new(
|
||||||
frame->stack_pointer = frame->stack + curr_stackentries;
|
frame->stack_pointer = frame->stack + curr_stackentries;
|
||||||
ctx->n_consumed = localsplus_start + (co->co_nlocalsplus + co->co_stacksize);
|
ctx->n_consumed = localsplus_start + (co->co_nlocalsplus + co->co_stacksize);
|
||||||
if (ctx->n_consumed >= ctx->limit) {
|
if (ctx->n_consumed >= ctx->limit) {
|
||||||
|
ctx->done = true;
|
||||||
|
ctx->out_of_space = true;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,9 +335,6 @@ _Py_uop_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_UopsSymbol *local = _Py_uop_sym_new_unknown(ctx);
|
_Py_UopsSymbol *local = _Py_uop_sym_new_unknown(ctx);
|
||||||
if (local == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
frame->locals[i] = local;
|
frame->locals[i] = local;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,9 +342,6 @@ _Py_uop_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_UopsSymbol *stackvar = _Py_uop_sym_new_unknown(ctx);
|
_Py_UopsSymbol *stackvar = _Py_uop_sym_new_unknown(ctx);
|
||||||
if (stackvar == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
frame->stack[i] = stackvar;
|
frame->stack[i] = stackvar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,7 +361,7 @@ _Py_uop_abstractcontext_fini(_Py_UOpsContext *ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
void
|
||||||
_Py_uop_abstractcontext_init(_Py_UOpsContext *ctx)
|
_Py_uop_abstractcontext_init(_Py_UOpsContext *ctx)
|
||||||
{
|
{
|
||||||
ctx->limit = ctx->locals_and_stack + MAX_ABSTRACT_INTERP_SIZE;
|
ctx->limit = ctx->locals_and_stack + MAX_ABSTRACT_INTERP_SIZE;
|
||||||
|
@ -374,8 +378,6 @@ _Py_uop_abstractcontext_init(_Py_UOpsContext *ctx)
|
||||||
|
|
||||||
// Frame setup
|
// Frame setup
|
||||||
ctx->curr_frame_depth = 0;
|
ctx->curr_frame_depth = 0;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -404,8 +406,8 @@ static _Py_UopsSymbol *
|
||||||
make_bottom(_Py_UOpsContext *ctx)
|
make_bottom(_Py_UOpsContext *ctx)
|
||||||
{
|
{
|
||||||
_Py_UopsSymbol *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(ctx, sym);
|
||||||
_Py_uop_sym_set_non_null(sym);
|
_Py_uop_sym_set_non_null(ctx, sym);
|
||||||
return sym;
|
return sym;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -452,10 +454,10 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored))
|
||||||
TEST_PREDICATE(!_Py_uop_sym_is_const(sym), "int is a constant");
|
TEST_PREDICATE(!_Py_uop_sym_is_const(sym), "int is a constant");
|
||||||
TEST_PREDICATE(_Py_uop_sym_get_const(sym) == NULL, "int as constant is not NULL");
|
TEST_PREDICATE(_Py_uop_sym_get_const(sym) == NULL, "int as constant is not NULL");
|
||||||
|
|
||||||
_Py_uop_sym_set_type(sym, &PyLong_Type); // Should be a no-op
|
_Py_uop_sym_set_type(ctx, sym, &PyLong_Type); // Should be a no-op
|
||||||
TEST_PREDICATE(_Py_uop_sym_matches_type(sym, &PyLong_Type), "(int and int) isn't int");
|
TEST_PREDICATE(_Py_uop_sym_matches_type(sym, &PyLong_Type), "(int and int) isn't int");
|
||||||
|
|
||||||
_Py_uop_sym_set_type(sym, &PyFloat_Type); // Should make it bottom
|
_Py_uop_sym_set_type(ctx, sym, &PyFloat_Type); // Should make it bottom
|
||||||
TEST_PREDICATE(_Py_uop_sym_is_bottom(sym), "(int and float) isn't bottom");
|
TEST_PREDICATE(_Py_uop_sym_is_bottom(sym), "(int and float) isn't bottom");
|
||||||
|
|
||||||
val_42 = PyLong_FromLong(42);
|
val_42 = PyLong_FromLong(42);
|
||||||
|
@ -470,7 +472,7 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored))
|
||||||
if (sym == NULL) {
|
if (sym == NULL) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
_Py_uop_sym_set_const(sym, val_42);
|
_Py_uop_sym_set_const(ctx, sym, val_42);
|
||||||
TEST_PREDICATE(_Py_uop_sym_truthiness(sym) == 1, "bool(42) is not True");
|
TEST_PREDICATE(_Py_uop_sym_truthiness(sym) == 1, "bool(42) is not True");
|
||||||
TEST_PREDICATE(!_Py_uop_sym_is_null(sym), "42 is NULL");
|
TEST_PREDICATE(!_Py_uop_sym_is_null(sym), "42 is NULL");
|
||||||
TEST_PREDICATE(_Py_uop_sym_is_not_null(sym), "42 isn't not NULL");
|
TEST_PREDICATE(_Py_uop_sym_is_not_null(sym), "42 isn't not NULL");
|
||||||
|
@ -480,19 +482,19 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored))
|
||||||
TEST_PREDICATE(_Py_uop_sym_get_const(sym) != NULL, "42 as constant is NULL");
|
TEST_PREDICATE(_Py_uop_sym_get_const(sym) != NULL, "42 as constant is NULL");
|
||||||
TEST_PREDICATE(_Py_uop_sym_get_const(sym) == val_42, "42 as constant isn't 42");
|
TEST_PREDICATE(_Py_uop_sym_get_const(sym) == val_42, "42 as constant isn't 42");
|
||||||
|
|
||||||
_Py_uop_sym_set_type(sym, &PyLong_Type); // Should be a no-op
|
_Py_uop_sym_set_type(ctx, sym, &PyLong_Type); // Should be a no-op
|
||||||
TEST_PREDICATE(_Py_uop_sym_matches_type(sym, &PyLong_Type), "(42 and 42) isn't an int");
|
TEST_PREDICATE(_Py_uop_sym_matches_type(sym, &PyLong_Type), "(42 and 42) isn't an int");
|
||||||
TEST_PREDICATE(_Py_uop_sym_get_const(sym) == val_42, "(42 and 42) as constant isn't 42");
|
TEST_PREDICATE(_Py_uop_sym_get_const(sym) == val_42, "(42 and 42) as constant isn't 42");
|
||||||
|
|
||||||
_Py_uop_sym_set_type(sym, &PyFloat_Type); // Should make it bottom
|
_Py_uop_sym_set_type(ctx, sym, &PyFloat_Type); // Should make it bottom
|
||||||
TEST_PREDICATE(_Py_uop_sym_is_bottom(sym), "(42 and float) isn't bottom");
|
TEST_PREDICATE(_Py_uop_sym_is_bottom(sym), "(42 and float) isn't bottom");
|
||||||
|
|
||||||
sym = _Py_uop_sym_new_type(ctx, &PyLong_Type);
|
sym = _Py_uop_sym_new_type(ctx, &PyLong_Type);
|
||||||
if (sym == NULL) {
|
if (sym == NULL) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
_Py_uop_sym_set_const(sym, val_42);
|
_Py_uop_sym_set_const(ctx, sym, val_42);
|
||||||
_Py_uop_sym_set_const(sym, val_43); // Should make it bottom
|
_Py_uop_sym_set_const(ctx, sym, val_43); // Should make it bottom
|
||||||
TEST_PREDICATE(_Py_uop_sym_is_bottom(sym), "(42 and 43) isn't bottom");
|
TEST_PREDICATE(_Py_uop_sym_is_bottom(sym), "(42 and 43) isn't bottom");
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -84,14 +84,11 @@ def emit_default(out: CWriter, uop: Uop) -> None:
|
||||||
if var.is_array():
|
if var.is_array():
|
||||||
out.emit(f"for (int _i = {var.size}; --_i >= 0;) {{\n")
|
out.emit(f"for (int _i = {var.size}; --_i >= 0;) {{\n")
|
||||||
out.emit(f"{var.name}[_i] = sym_new_not_null(ctx);\n")
|
out.emit(f"{var.name}[_i] = sym_new_not_null(ctx);\n")
|
||||||
out.emit(f"if ({var.name}[_i] == NULL) goto out_of_space;\n")
|
|
||||||
out.emit("}\n")
|
out.emit("}\n")
|
||||||
elif var.name == "null":
|
elif var.name == "null":
|
||||||
out.emit(f"{var.name} = sym_new_null(ctx);\n")
|
out.emit(f"{var.name} = sym_new_null(ctx);\n")
|
||||||
out.emit(f"if ({var.name} == NULL) goto out_of_space;\n")
|
|
||||||
else:
|
else:
|
||||||
out.emit(f"{var.name} = sym_new_not_null(ctx);\n")
|
out.emit(f"{var.name} = sym_new_not_null(ctx);\n")
|
||||||
out.emit(f"if ({var.name} == NULL) goto out_of_space;\n")
|
|
||||||
|
|
||||||
|
|
||||||
def write_uop(
|
def write_uop(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue