Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9466417
Skip refcounting where possible for common float ops
Fidget-Spinner May 23, 2025
ad03b1e
Add for common list ops
Fidget-Spinner May 23, 2025
7f90d0c
Fix test, rename
Fidget-Spinner May 23, 2025
a42b434
Remove list optimizations to minimize PR
Fidget-Spinner May 23, 2025
f456740
📜🤖 Added by blurb_it.
blurb-it[bot] May 23, 2025
16f9dee
Merge remote-tracking branch 'upstream/main' into decref_elimination_…
Fidget-Spinner May 27, 2025
5c429b6
Rename things to make things clearer
Fidget-Spinner May 27, 2025
1535133
Revert "Rename things to make things clearer"
Fidget-Spinner May 27, 2025
8f62067
Massive refactor from JitOptSymbol to JitRef
Fidget-Spinner May 28, 2025
a158835
refactor more
Fidget-Spinner May 28, 2025
e77f842
fix debug build
Fidget-Spinner May 28, 2025
01004c2
lint
Fidget-Spinner May 28, 2025
24f98d5
Merge remote-tracking branch 'upstream/main' into decref_elimination_…
Fidget-Spinner May 28, 2025
0189413
fix upstream
Fidget-Spinner May 28, 2025
4a386bf
reduce diff
Fidget-Spinner May 28, 2025
ac034a0
fix for FT
Fidget-Spinner May 28, 2025
b6e467e
fix failing tests
Fidget-Spinner May 28, 2025
3a3fa9d
Fix for disabled GIL
Fidget-Spinner May 29, 2025
ab1ad9c
fix on FT again
Fidget-Spinner May 29, 2025
5d82489
Try fix windows
Fidget-Spinner May 29, 2025
4d9a68e
Apply code review suggestions from Tomas
Fidget-Spinner Jun 4, 2025
2bbd47a
call the functions sym instead of ref
Fidget-Spinner Jun 4, 2025
2d779c4
rename jitref functions
Fidget-Spinner Jun 4, 2025
b74e160
Address review
Fidget-Spinner Jun 4, 2025
3ebcc20
Update comment
Fidget-Spinner Jun 4, 2025
673d5c8
Merge remote-tracking branch 'upstream/main' into decref_elimination_…
Fidget-Spinner Jun 17, 2025
914f1ff
Fix changes from upstream (no more casts)
Fidget-Spinner Jun 17, 2025
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
Prev Previous commit
Next Next commit
Massive refactor from JitOptSymbol to JitRef
  • Loading branch information
Fidget-Spinner committed May 28, 2025
commit 8f6206795863595a440c2647db77f09aec72fab2
130 changes: 82 additions & 48 deletions Include/internal/pycore_optimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "pycore_typedefs.h" // _PyInterpreterFrame
#include "pycore_uop_ids.h"
#include "pycore_stackref.h"
#include <stdbool.h>


Expand Down Expand Up @@ -180,13 +181,10 @@
JIT_SYM_TRUTHINESS_TAG = 9,
} JitSymType;

#define DONT_SKIP_REFCOUNT 0
#define SKIP_REFCOUNT 1

typedef struct _jit_opt_known_class {
struct {
uint8_t tag;
uint8_t skip_refcount;
};
uint32_t version;
PyTypeObject *type;
Expand All @@ -195,15 +193,13 @@
typedef struct _jit_opt_known_version {
struct {
uint8_t tag;
uint8_t skip_refcount;
};
uint32_t version;
} JitOptKnownVersion;

typedef struct _jit_opt_known_value {
struct {
uint8_t tag;
uint8_t skip_refcount;
};
PyObject *value;
} JitOptKnownValue;
Expand All @@ -213,7 +209,6 @@
typedef struct _jit_opt_tuple {
struct {
uint8_t tag;
uint8_t skip_refcount;
};
uint8_t length;
uint16_t items[MAX_SYMBOLIC_TUPLE_SIZE];
Expand All @@ -222,7 +217,6 @@
typedef struct {
struct {
uint8_t tag;
uint8_t skip_refcount;
};
bool invert;
uint16_t value;
Expand All @@ -231,11 +225,6 @@
typedef union _jit_opt_symbol {
struct {
uint8_t tag;
// Whether this object skips refcount on the stack
// (using the _PyStackRef API), or not.
// 0 - normal refcounting
// 1 - skip refcounting
int8_t skip_refcount;
};
JitOptKnownClass cls;
JitOptKnownValue value;
Expand All @@ -245,15 +234,65 @@
} JitOptSymbol;


// This mimics the _PyStackRef API
typedef union {
uintptr_t bits;
} JitOptRef;

#define JIT_BITS_TO_PTR(REF) ((JitOptSymbol *)((REF).bits))
#define JIT_BITS_TO_PTR_MASKED(REF) ((JitOptSymbol *)(((REF).bits) & (~Py_TAG_REFCNT)))

static inline JitOptSymbol *
PyJitRef_AsSymbolBorrow(JitOptRef ref)
{
return JIT_BITS_TO_PTR_MASKED(ref);
}

bool _Py_uop_sym_is_immortal(JitOptSymbol *sym);

static inline JitOptRef
PyJitRef_FromSymbolSteal(JitOptSymbol *sym)
{
if (sym == NULL || _Py_uop_sym_is_immortal(sym)) {
return (JitOptRef){.bits=(uintptr_t)sym | Py_TAG_REFCNT};
}
return (JitOptRef){.bits=(uintptr_t)sym};
}

static inline JitOptRef
PyJitRef_FromSymbolBorrow(JitOptSymbol *sym)
{
return (JitOptRef){.bits=(uintptr_t)sym | Py_TAG_REFCNT};
}

static inline JitOptRef
PyJitRef_Borrow(JitOptRef ref)
{
return (JitOptRef){ .bits = ref.bits | Py_TAG_REFCNT };
}

static const JitOptRef PyJitRef_NULL = { .bits = PyStackRef_NULL_BITS };

Check failure on line 274 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (x64)

'PyStackRef_NULL_BITS': undeclared identifier [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 274 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (x64)

initializer is not a constant [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 274 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (x64)

'PyStackRef_NULL_BITS': undeclared identifier [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 274 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (x64)

initializer is not a constant [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 274 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (x64)

'PyStackRef_NULL_BITS': undeclared identifier [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 274 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (x64)

initializer is not a constant [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 274 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (x64)

'PyStackRef_NULL_BITS': undeclared identifier [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 274 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (arm64)

'PyStackRef_NULL_BITS': undeclared identifier [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 274 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (arm64)

initializer is not a constant [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 274 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (arm64)

'PyStackRef_NULL_BITS': undeclared identifier [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 274 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (arm64)

initializer is not a constant [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 274 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (arm64)

'PyStackRef_NULL_BITS': undeclared identifier [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 274 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (arm64)

initializer is not a constant [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 274 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (arm64)

'PyStackRef_NULL_BITS': undeclared identifier [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 274 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04)

‘PyStackRef_NULL_BITS’ undeclared here (not in a function); did you mean ‘PyStackRef_NULL’?

Check failure on line 274 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04)

‘PyStackRef_NULL_BITS’ undeclared here (not in a function); did you mean ‘PyStackRef_NULL’?

Check failure on line 274 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04)

‘PyStackRef_NULL_BITS’ undeclared here (not in a function); did you mean ‘PyStackRef_NULL’?

Check failure on line 274 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04)

‘PyStackRef_NULL_BITS’ undeclared here (not in a function); did you mean ‘PyStackRef_NULL’?

Check failure on line 274 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04)

‘PyStackRef_NULL_BITS’ undeclared here (not in a function); did you mean ‘PyStackRef_NULL’?

Check failure on line 274 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04)

‘PyStackRef_NULL_BITS’ undeclared here (not in a function); did you mean ‘PyStackRef_NULL’?

Check failure on line 274 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04)

‘PyStackRef_NULL_BITS’ undeclared here (not in a function); did you mean ‘PyStackRef_NULL’?

Check failure on line 274 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04)

‘PyStackRef_NULL_BITS’ undeclared here (not in a function); did you mean ‘PyStackRef_NULL’?

Check failure on line 274 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04)

‘PyStackRef_NULL_BITS’ undeclared here (not in a function); did you mean ‘PyStackRef_NULL’?

Check failure on line 274 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04)

‘PyStackRef_NULL_BITS’ undeclared here (not in a function); did you mean ‘PyStackRef_NULL’?

static inline bool
PyJitRef_IsNull(JitOptRef ref)
{
return ref.bits == PyStackRef_NULL_BITS;

Check failure on line 279 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (x64)

'PyStackRef_NULL_BITS': undeclared identifier [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 279 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (x64)

'PyStackRef_NULL_BITS': undeclared identifier [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 279 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (x64)

'PyStackRef_NULL_BITS': undeclared identifier [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 279 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (arm64)

'PyStackRef_NULL_BITS': undeclared identifier [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 279 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (arm64)

'PyStackRef_NULL_BITS': undeclared identifier [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 279 in Include/internal/pycore_optimizer.h

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (arm64)

'PyStackRef_NULL_BITS': undeclared identifier [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]
}

static inline int
PyJitRef_IsBorrowed(JitOptRef ref)
{
return (ref.bits & Py_TAG_REFCNT) == Py_TAG_REFCNT;
}

struct _Py_UOpsAbstractFrame {
// Max stacklen
int stack_len;
int locals_len;

JitOptSymbol **stack_pointer;
JitOptSymbol **stack;
JitOptSymbol **locals;
JitOptRef *stack_pointer;
JitOptRef *stack;
JitOptRef *locals;
};

typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame;
Expand All @@ -276,41 +315,36 @@
// Arena for the symbolic types.
ty_arena t_arena;

JitOptSymbol **n_consumed;
JitOptSymbol **limit;
JitOptSymbol *locals_and_stack[MAX_ABSTRACT_INTERP_SIZE];
JitOptRef *n_consumed;
JitOptRef *limit;
JitOptRef locals_and_stack[MAX_ABSTRACT_INTERP_SIZE];
} JitOptContext;

extern bool _Py_uop_sym_is_null(JitOptSymbol *sym);
extern bool _Py_uop_sym_is_not_null(JitOptSymbol *sym);
extern bool _Py_uop_sym_is_const(JitOptContext *ctx, JitOptSymbol *sym);
extern PyObject *_Py_uop_sym_get_const(JitOptContext *ctx, JitOptSymbol *sym);
extern JitOptSymbol *_Py_uop_sym_new_unknown(JitOptContext *ctx);
extern JitOptSymbol *_Py_uop_sym_new_not_null(JitOptContext *ctx);
extern JitOptSymbol *_Py_uop_sym_new_type(
extern bool _Py_uop_ref_is_null(JitOptRef sym);
extern bool _Py_uop_ref_is_not_null(JitOptRef sym);
extern bool _Py_uop_ref_is_const(JitOptContext *ctx, JitOptRef sym);
extern PyObject *_Py_uop_ref_get_const(JitOptContext *ctx, JitOptRef sym);
extern JitOptRef _Py_uop_ref_new_unknown(JitOptContext *ctx);
extern JitOptRef _Py_uop_ref_new_not_null(JitOptContext *ctx);
extern JitOptRef _Py_uop_ref_new_type(
JitOptContext *ctx, PyTypeObject *typ);
extern JitOptSymbol *_Py_uop_sym_new_const(JitOptContext *ctx, PyObject *const_val);
extern JitOptSymbol *_Py_uop_sym_new_null(JitOptContext *ctx);
extern bool _Py_uop_sym_has_type(JitOptSymbol *sym);
extern bool _Py_uop_sym_matches_type(JitOptSymbol *sym, PyTypeObject *typ);
extern bool _Py_uop_sym_matches_type_version(JitOptSymbol *sym, unsigned int version);
extern void _Py_uop_sym_set_null(JitOptContext *ctx, JitOptSymbol *sym);
extern void _Py_uop_sym_set_non_null(JitOptContext *ctx, JitOptSymbol *sym);
extern void _Py_uop_sym_set_type(JitOptContext *ctx, JitOptSymbol *sym, PyTypeObject *typ);
extern bool _Py_uop_sym_set_type_version(JitOptContext *ctx, JitOptSymbol *sym, unsigned int version);
extern void _Py_uop_sym_set_const(JitOptContext *ctx, JitOptSymbol *sym, PyObject *const_val);
extern bool _Py_uop_sym_is_bottom(JitOptSymbol *sym);
extern int _Py_uop_sym_truthiness(JitOptContext *ctx, JitOptSymbol *sym);
extern PyTypeObject *_Py_uop_sym_get_type(JitOptSymbol *sym);
extern bool _Py_uop_sym_is_immortal(JitOptSymbol *sym);
extern JitOptSymbol *_Py_uop_sym_new_tuple(JitOptContext *ctx, int size, JitOptSymbol **args);
extern JitOptSymbol *_Py_uop_sym_tuple_getitem(JitOptContext *ctx, JitOptSymbol *sym, int item);
extern int _Py_uop_sym_tuple_length(JitOptSymbol *sym);
extern JitOptSymbol *_Py_uop_sym_new_truthiness(JitOptContext *ctx, JitOptSymbol *value, bool truthy);

extern void _Py_uop_sym_set_dont_skip_refcount(JitOptContext *ctx, JitOptSymbol *sym);
extern bool _Py_uop_sym_is_skip_refcount(JitOptContext *ctx, JitOptSymbol *sym);
extern void _Py_uop_sym_set_skip_refcount(JitOptContext *ctx, JitOptSymbol *sym);
extern JitOptRef _Py_uop_ref_new_const(JitOptContext *ctx, PyObject *const_val);
extern JitOptRef _Py_uop_ref_new_null(JitOptContext *ctx);
extern bool _Py_uop_ref_has_type(JitOptRef sym);
extern bool _Py_uop_ref_matches_type(JitOptRef sym, PyTypeObject *typ);
extern bool _Py_uop_ref_matches_type_version(JitOptRef sym, unsigned int version);
extern void _Py_uop_ref_set_null(JitOptContext *ctx, JitOptRef sym);
extern void _Py_uop_ref_set_non_null(JitOptContext *ctx, JitOptRef sym);
extern void _Py_uop_ref_set_type(JitOptContext *ctx, JitOptRef sym, PyTypeObject *typ);
extern bool _Py_uop_ref_set_type_version(JitOptContext *ctx, JitOptRef sym, unsigned int version);
extern void _Py_uop_ref_set_const(JitOptContext *ctx, JitOptRef sym, PyObject *const_val);
extern bool _Py_uop_ref_is_bottom(JitOptRef sym);
extern int _Py_uop_ref_truthiness(JitOptContext *ctx, JitOptRef sym);
extern PyTypeObject *_Py_uop_ref_get_type(JitOptRef sym);
extern JitOptRef _Py_uop_ref_new_tuple(JitOptContext *ctx, int size, JitOptRef *args);
extern JitOptRef _Py_uop_ref_tuple_getitem(JitOptContext *ctx, JitOptRef sym, int item);
extern int _Py_uop_ref_tuple_length(JitOptRef sym);
extern JitOptRef _Py_uop_ref_new_truthiness(JitOptContext *ctx, JitOptRef value, bool truthy);

extern void _Py_uop_abstractcontext_init(JitOptContext *ctx);
extern void _Py_uop_abstractcontext_fini(JitOptContext *ctx);
Expand All @@ -319,7 +353,7 @@
JitOptContext *ctx,
PyCodeObject *co,
int curr_stackentries,
JitOptSymbol **args,
JitOptRef *args,
int arg_len);
extern int _Py_uop_frame_pop(JitOptContext *ctx);

Expand Down
71 changes: 34 additions & 37 deletions Python/optimizer_analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,54 +315,51 @@ remove_globals(_PyInterpreterFrame *frame, _PyUOpInstruction *buffer,
INST->operand0 = OPERAND;

/* 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_has_type _Py_uop_sym_has_type
#define sym_get_type _Py_uop_sym_get_type
#define sym_matches_type _Py_uop_sym_matches_type
#define sym_matches_type_version _Py_uop_sym_matches_type_version
#define sym_set_null(SYM) _Py_uop_sym_set_null(ctx, SYM)
#define sym_set_non_null(SYM) _Py_uop_sym_set_non_null(ctx, SYM)
#define sym_set_type(SYM, TYPE) _Py_uop_sym_set_type(ctx, SYM, TYPE)
#define sym_set_type_version(SYM, VERSION) _Py_uop_sym_set_type_version(ctx, SYM, VERSION)
#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_truthiness _Py_uop_sym_truthiness
#define ref_is_not_null _Py_uop_ref_is_not_null
#define ref_is_const _Py_uop_ref_is_const
#define ref_get_const _Py_uop_ref_get_const
#define ref_new_unknown _Py_uop_ref_new_unknown
#define ref_new_not_null _Py_uop_ref_new_not_null
#define ref_new_type _Py_uop_ref_new_type
#define ref_is_null _Py_uop_ref_is_null
#define ref_new_const _Py_uop_ref_new_const
#define ref_new_null _Py_uop_ref_new_null
#define ref_has_type _Py_uop_ref_has_type
#define ref_get_type _Py_uop_ref_get_type
#define ref_matches_type _Py_uop_ref_matches_type
#define ref_matches_type_version _Py_uop_ref_matches_type_version
#define ref_set_null(SYM) _Py_uop_ref_set_null(ctx, SYM)
#define ref_set_non_null(SYM) _Py_uop_ref_set_non_null(ctx, SYM)
#define ref_set_type(SYM, TYPE) _Py_uop_ref_set_type(ctx, SYM, TYPE)
#define ref_set_type_version(SYM, VERSION) _Py_uop_ref_set_type_version(ctx, SYM, VERSION)
#define ref_set_const(SYM, CNST) _Py_uop_ref_set_const(ctx, SYM, CNST)
#define ref_is_bottom _Py_uop_ref_is_bottom
#define ref_truthiness _Py_uop_ref_truthiness
#define frame_new _Py_uop_frame_new
#define frame_pop _Py_uop_frame_pop
#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_new_truthiness _Py_uop_sym_new_truthiness
#define sym_set_skip_refcount _Py_uop_sym_set_skip_refcount
#define sym_set_dont_skip_refcount _Py_uop_sym_set_dont_skip_refcount
#define sym_is_skip_refcount _Py_uop_sym_is_skip_refcount
#define ref_new_tuple _Py_uop_ref_new_tuple
#define ref_tuple_getitem _Py_uop_ref_tuple_getitem
#define ref_tuple_length _Py_uop_ref_tuple_length
#define ref_is_immortal _Py_uop_ref_is_immortal
#define ref_new_truthiness _Py_uop_ref_new_truthiness

static int
optimize_to_bool(
_PyUOpInstruction *this_instr,
JitOptContext *ctx,
JitOptSymbol *value,
JitOptSymbol **result_ptr)
JitOptRef value,
JitOptRef *result_ptr)
{
if (sym_matches_type(value, &PyBool_Type)) {
if (ref_matches_type(value, &PyBool_Type)) {
REPLACE_OP(this_instr, _NOP, 0, 0);
*result_ptr = value;
return 1;
}
int truthiness = sym_truthiness(ctx, value);
int truthiness = ref_truthiness(ctx, value);
if (truthiness >= 0) {
PyObject *load = truthiness ? Py_True : Py_False;
REPLACE_OP(this_instr, _POP_TOP_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)load);
*result_ptr = sym_new_const(ctx, load);
*result_ptr = ref_new_const(ctx, load);
return 1;
}
return 0;
Expand All @@ -378,7 +375,7 @@ eliminate_pop_guard(_PyUOpInstruction *this_instr, bool exit)
}
}

static JitOptSymbol *
static JitOptRef
lookup_attr(JitOptContext *ctx, _PyUOpInstruction *this_instr,
PyTypeObject *type, PyObject *name, uint16_t immortal,
uint16_t mortal)
Expand All @@ -389,10 +386,10 @@ lookup_attr(JitOptContext *ctx, _PyUOpInstruction *this_instr,
if (lookup) {
int opcode = _Py_IsImmortal(lookup) ? immortal : mortal;
REPLACE_OP(this_instr, opcode, 0, (uintptr_t)lookup);
return sym_new_const(ctx, lookup);
return ref_new_const(ctx, lookup);
}
}
return sym_new_not_null(ctx);
return ref_new_not_null(ctx);
}

/* _PUSH_FRAME/_RETURN_VALUE's operand can be 0, a PyFunctionObject *, or a
Expand Down Expand Up @@ -487,7 +484,7 @@ optimize_uops(

int oparg = this_instr->oparg;
opcode = this_instr->opcode;
JitOptSymbol **stack_pointer = ctx->frame->stack_pointer;
JitOptRef *stack_pointer = ctx->frame->stack_pointer;

#ifdef Py_DEBUG
if (get_lltrace() >= 3) {
Expand Down
Loading
Loading