Skip to content
Prev Previous commit
Next Next commit
Add type version functions and struct initialization
  • Loading branch information
saulshanabrook committed May 20, 2024
commit 89e3649ef1ac9e47054f8f5edafc6bf5b2b8a0cc
2 changes: 2 additions & 0 deletions Python/optimizer_bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame;
#define sym_new_const _Py_uop_sym_new_const
#define sym_new_null _Py_uop_sym_new_null
#define sym_matches_type _Py_uop_sym_matches_type
#define sym_matches_type_version _Py_uop_sym_matches_type_version
#define sym_get_type _Py_uop_sym_get_type
#define sym_has_type _Py_uop_sym_has_type
#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 frame_new _Py_uop_frame_new
Expand Down
26 changes: 24 additions & 2 deletions Python/optimizer_symbols.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ static inline int get_lltrace(void) {
static _Py_UopsSymbol NO_SPACE_SYMBOL = {
.flags = IS_NULL | NOT_NULL | NO_SPACE,
.typ = NULL,
.const_val = NULL
.const_val = NULL,
.typ_version = 0,
.typ_version_offset = 0,
};

_Py_UopsSymbol *
Expand All @@ -76,7 +78,8 @@ sym_new(_Py_UOpsContext *ctx)
self->flags = 0;
self->typ = NULL;
self->const_val = NULL;
self->typ_version =
self->typ_version = 0;
self->typ_version_offset = 0;

return self;
}
Expand Down Expand Up @@ -153,6 +156,12 @@ _Py_uop_sym_set_type(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym, PyTypeObject *ty
}
}

void
_Py_uop_sym_set_type_version(_Py_UopsContext *ctx, _Py_UopsSymbol *sym, int32_t version)
{
sym->typ_version = version;
}

void
_Py_uop_sym_set_const(_Py_UOpsContext *ctx, _Py_UopsSymbol *sym, PyObject *const_val)
{
Expand Down Expand Up @@ -257,6 +266,12 @@ _Py_uop_sym_get_type(_Py_UopsSymbol *sym)
return sym->typ;
}

int32_t
_Py_uop_sym_get_type_version(_Py_UopsSymbol *sym)
{
return sym->typ_version;
}

bool
_Py_uop_sym_has_type(_Py_UopsSymbol *sym)
{
Expand All @@ -273,6 +288,13 @@ _Py_uop_sym_matches_type(_Py_UopsSymbol *sym, PyTypeObject *typ)
return _Py_uop_sym_get_type(sym) == typ;
}

bool
_Py_uop_sym_matches_type_version(_Py_UopsSymbol *sym, int32_t version)
{
return _Py_uop_sym_get_type_version(sym) == version;
}


int
_Py_uop_sym_truthiness(_Py_UopsSymbol *sym)
{
Expand Down