Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions Include/internal/pycore_uop_ids.h

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

2 changes: 2 additions & 0 deletions Include/internal/pycore_uop_metadata.h

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

4 changes: 4 additions & 0 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -4042,6 +4042,10 @@ dummy_func(
tier2 pure op(_LOAD_CONST_INLINE_BORROW, (ptr/4 -- value)) {
value = ptr;
}
tier2 pure op (_POP_TOP_LOAD_CONST_INLINE_BORROW, (ptr/4, pop -- value)) {
Py_DECREF(pop);
value = ptr;
}

tier2 pure op(_LOAD_CONST_INLINE_WITH_NULL, (ptr/4 -- value, null)) {
value = Py_NewRef(ptr);
Expand Down
11 changes: 11 additions & 0 deletions Python/executor_cases.c.h

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

59 changes: 56 additions & 3 deletions Python/optimizer_bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ dummy_func(void) {
if (temp == NULL) {
goto error;
}
res = sym_new_const(ctx, temp);
OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
Comment thread
Fidget-Spinner marked this conversation as resolved.
Outdated
// TODO gh-115506:
// replace opcode with constant propagated one and update tests!
}
Expand All @@ -189,7 +189,7 @@ dummy_func(void) {
if (temp == NULL) {
goto error;
}
res = sym_new_const(ctx, temp);
OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
// TODO gh-115506:
// replace opcode with constant propagated one and update tests!
}
Expand All @@ -208,7 +208,7 @@ dummy_func(void) {
if (temp == NULL) {
goto error;
}
res = sym_new_const(ctx, temp);
OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
// TODO gh-115506:
// replace opcode with constant propagated one and update tests!
}
Expand All @@ -217,6 +217,59 @@ dummy_func(void) {
}
}

op(_TO_BOOL, (value -- res)) {
(void)value;
res = sym_new_type(ctx, &PyBool_Type);
OUT_OF_SPACE_IF_NULL(res);
}

op(_TO_BOOL_BOOL, (value -- value)) {
if (sym_matches_type(value, &PyBool_Type)) {
REPLACE_OP(this_instr, _NOP, 0, 0);
}
else {
sym_set_type(value, &PyBool_Type);
Comment thread
Fidget-Spinner marked this conversation as resolved.
Outdated
}
}

op(_TO_BOOL_INT, (value -- res)) {
if (sym_is_const(value) && sym_matches_type(value, &PyLong_Type)) {
PyObject *load = _PyLong_IsZero((PyLongObject *)sym_get_const(value))
? Py_False : Py_True;
REPLACE_OP(this_instr, _POP_TOP_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)load);
OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, load));
}
else {
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
}
sym_set_type(value, &PyLong_Type);
}

op(_TO_BOOL_LIST, (value -- res)) {
sym_set_type(value, &PyList_Type);
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
}

op(_TO_BOOL_NONE, (value -- res)) {
if (sym_get_const(value) == Py_None) {
REPLACE_OP(this_instr, _POP_TOP_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)Py_False);
}
sym_set_const(value, Py_None);
OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, Py_False));
}

op(_TO_BOOL_STR, (value -- res)) {
if (sym_is_const(value) && sym_matches_type(value, &PyUnicode_Type)) {
PyObject *load = sym_get_const(value) == &_Py_STR(empty) ? Py_False : Py_True;
REPLACE_OP(this_instr, _POP_TOP_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)load);
OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, load));
}
else {
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
}
sym_set_type(value, &PyUnicode_Type);
}

op(_LOAD_CONST, (-- value)) {
// There should be no LOAD_CONST. It should be all
// replaced by peephole_opt.
Expand Down
71 changes: 58 additions & 13 deletions Python/optimizer_cases.c.h

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