gh-144540: Add _MAKE_HEAP_SAFE uop to eliminate unnecessary refcount operations in RETURN_VALUE and YIELD_VALUE (GH-144414)

This commit is contained in:
Hai Zhu 2026-03-12 04:24:19 +08:00 committed by GitHub
parent 77d6d5d8fc
commit f062014d38
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 1288 additions and 1072 deletions

View file

@ -88,6 +88,14 @@ dummy_func(void) {
// BEGIN BYTECODES //
op(_MAKE_HEAP_SAFE, (value -- value)) {
// eliminate _MAKE_HEAP_SAFE when we *know* the value is immortal
if (sym_is_immortal(PyJitRef_Unwrap(value))) {
ADD_OP(_NOP, 0, 0);
}
value = PyJitRef_StripReferenceInfo(value);
}
op(_LOAD_FAST_CHECK, (-- value)) {
value = GETLOCAL(oparg);
// We guarantee this will error - just bail and don't optimize it.
@ -944,8 +952,7 @@ dummy_func(void) {
}
op(_RETURN_VALUE, (retval -- res)) {
// Mimics PyStackRef_MakeHeapSafe in the interpreter.
JitOptRef temp = PyJitRef_StripReferenceInfo(retval);
JitOptRef temp = retval;
DEAD(retval);
SAVE_STACK();
ctx->frame->stack_pointer = stack_pointer;
@ -983,8 +990,7 @@ dummy_func(void) {
}
op(_YIELD_VALUE, (retval -- value)) {
// Mimics PyStackRef_MakeHeapSafe in the interpreter.
JitOptRef temp = PyJitRef_StripReferenceInfo(retval);
JitOptRef temp = retval;
DEAD(retval);
SAVE_STACK();
ctx->frame->stack_pointer = stack_pointer;