-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-134584: Specialize POP_TOP by reference and type in JIT #135761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4b415f5
0031dfe
ca6e42c
4100934
c4121f5
134ad1f
23197eb
9443007
a3b82a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Specialize :opcode:`POP_TOP` in the JIT compiler by specializing for reference lifetime and type. This will also enable easier top of stack caching in the JIT compiler. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame; | |
#define sym_new_tuple _Py_uop_sym_new_tuple | ||
#define sym_tuple_getitem _Py_uop_sym_tuple_getitem | ||
#define sym_tuple_length _Py_uop_sym_tuple_length | ||
#define sym_is_immortal _Py_uop_sym_is_immortal | ||
#define sym_is_immortal _Py_uop_symbol_is_immortal | ||
#define sym_new_compact_int _Py_uop_sym_new_compact_int | ||
#define sym_is_compact_int _Py_uop_sym_is_compact_int | ||
#define sym_new_truthiness _Py_uop_sym_new_truthiness | ||
|
@@ -534,15 +534,15 @@ dummy_func(void) { | |
} | ||
|
||
op(_LOAD_CONST_INLINE, (ptr/4 -- value)) { | ||
value = PyJitRef_Borrow(sym_new_const(ctx, ptr)); | ||
value = sym_new_const(ctx, ptr); | ||
} | ||
|
||
op(_LOAD_CONST_INLINE_BORROW, (ptr/4 -- value)) { | ||
value = PyJitRef_Borrow(sym_new_const(ctx, ptr)); | ||
} | ||
|
||
op(_POP_TOP_LOAD_CONST_INLINE, (ptr/4, pop -- value)) { | ||
value = PyJitRef_Borrow(sym_new_const(ctx, ptr)); | ||
value = sym_new_const(ctx, ptr); | ||
} | ||
|
||
op(_POP_TOP_LOAD_CONST_INLINE_BORROW, (ptr/4, pop -- value)) { | ||
|
@@ -561,6 +561,24 @@ dummy_func(void) { | |
value = PyJitRef_Borrow(sym_new_const(ctx, ptr)); | ||
} | ||
|
||
op(_POP_TOP, (value -- )) { | ||
PyTypeObject *typ = sym_get_type(value); | ||
if (PyJitRef_IsBorrowed(value) || | ||
sym_is_immortal(PyJitRef_Unwrap(value)) || | ||
sym_is_null(value)) { | ||
REPLACE_OP(this_instr, _POP_TOP_NOP, 0, 0); | ||
} | ||
else if (typ == &PyLong_Type) { | ||
REPLACE_OP(this_instr, _POP_TOP_INT, 0, 0); | ||
} | ||
else if (typ == &PyFloat_Type) { | ||
REPLACE_OP(this_instr, _POP_TOP_FLOAT, 0, 0); | ||
} | ||
else if (typ == &PyUnicode_Type) { | ||
REPLACE_OP(this_instr, _POP_TOP_UNICODE, 0, 0); | ||
} | ||
} | ||
|
||
op(_COPY, (bottom, unused[oparg-1] -- bottom, unused[oparg-1], top)) { | ||
assert(oparg > 0); | ||
top = bottom; | ||
|
@@ -803,7 +821,9 @@ dummy_func(void) { | |
} | ||
|
||
op(_RETURN_VALUE, (retval -- res)) { | ||
JitOptRef temp = retval; | ||
// We wrap and unwrap the value to mimic PyStackRef_MakeHeapSafe | ||
// in bytecodes.c | ||
JitOptRef temp = PyJitRef_Wrap(PyJitRef_Unwrap(retval)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a bug in the previous implementation. This was only exposed in this PR. |
||
DEAD(retval); | ||
SAVE_STACK(); | ||
ctx->frame->stack_pointer = stack_pointer; | ||
|
Uh oh!
There was an error while loading. Please reload this page.