-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-119477: Analyze through BUILD_TUPLE and BINARY_SUBSCR_TUPLE_INT #119478
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
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,8 @@ struct _Py_UopsSymbol { | |
| int flags; // 0 bits: Top; 2 or more bits: Bottom | ||
| PyTypeObject *typ; // Borrowed reference | ||
| PyObject *const_val; // Owned reference (!) | ||
| int tuple_count; | ||
| struct _Py_UopsSymbol **tuple_val; | ||
|
Member
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. Can you use indexes, rather than pointers? We can fit 6 10-bit indexes into a 64 bit int. Would it be possible to use a union, and overlap this field with |
||
| }; | ||
|
|
||
| #define UOP_FORMAT_TARGET 0 | ||
|
|
@@ -92,6 +94,12 @@ typedef struct ty_arena { | |
| _Py_UopsSymbol arena[TY_ARENA_SIZE]; | ||
| } ty_arena; | ||
|
|
||
| typedef struct tup_arena { | ||
|
Member
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 shouldn't be necessary, if we use indexes into the arena, instead of pointers. |
||
| int tup_curr_number; | ||
| int tup_max_number; | ||
| _Py_UopsSymbol *arena[TY_ARENA_SIZE]; | ||
| } tup_arena; | ||
|
|
||
| struct _Py_UOpsContext { | ||
| char done; | ||
| char out_of_space; | ||
|
|
@@ -104,6 +112,9 @@ struct _Py_UOpsContext { | |
| // Arena for the symbolic types. | ||
| ty_arena t_arena; | ||
|
|
||
| // Arena for the symbolic tuple objects. | ||
| tup_arena tup_arena; | ||
|
|
||
| _Py_UopsSymbol **n_consumed; | ||
| _Py_UopsSymbol **limit; | ||
| _Py_UopsSymbol *locals_and_stack[MAX_ABSTRACT_INTERP_SIZE]; | ||
|
|
@@ -119,6 +130,8 @@ extern _Py_UopsSymbol *_Py_uop_sym_new_unknown(_Py_UOpsContext *ctx); | |
| extern _Py_UopsSymbol *_Py_uop_sym_new_not_null(_Py_UOpsContext *ctx); | ||
| extern _Py_UopsSymbol *_Py_uop_sym_new_type( | ||
| _Py_UOpsContext *ctx, PyTypeObject *typ); | ||
| extern _Py_UopsSymbol *_Py_uop_sym_new_tuple(_Py_UOpsContext *ctx, int count); | ||
| extern _Py_UopsSymbol *_Py_uop_sym_tuple_at(_Py_UopsSymbol *sym, int idx); | ||
|
Member
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. Can you use |
||
| extern _Py_UopsSymbol *_Py_uop_sym_new_const(_Py_UOpsContext *ctx, PyObject *const_val); | ||
| extern _Py_UopsSymbol *_Py_uop_sym_new_null(_Py_UOpsContext *ctx); | ||
| extern bool _Py_uop_sym_has_type(_Py_UopsSymbol *sym); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,8 @@ typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame; | |
| #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_new_tuple _Py_uop_sym_new_tuple | ||
| #define sym_tuple_at _Py_uop_sym_tuple_at | ||
| #define sym_matches_type _Py_uop_sym_matches_type | ||
| #define sym_get_type _Py_uop_sym_get_type | ||
| #define sym_has_type _Py_uop_sym_has_type | ||
|
|
@@ -762,6 +764,25 @@ dummy_func(void) { | |
| ctx->done = true; | ||
| } | ||
|
|
||
| op(_BUILD_TUPLE, (values[oparg] -- tup)) { | ||
| tup = sym_new_tuple(ctx, oparg); | ||
| assert(tup != NULL); | ||
| assert(!ctx->out_of_space); | ||
| for (int i = 0; i < oparg; i++) { | ||
| tup->tuple_val[i] = values[i]; | ||
|
Member
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. Use |
||
| } | ||
| } | ||
|
|
||
| op(_BINARY_SUBSCR_TUPLE_INT, (tuple, sub -- res)) { | ||
|
Member
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 optimization applies to all |
||
| if (sym_has_type(tuple) && sym_matches_type(tuple, &PyTuple_Type) && sym_is_const(sub) ) { | ||
| PyObject* value = sym_get_const(sub); | ||
| Py_ssize_t index = ((PyLongObject*)value)->long_value.ob_digit[0]; | ||
|
Member
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. There is no guarantee that value is an |
||
| res = sym_tuple_at(tuple, index); | ||
| } else { | ||
| res = sym_new_unknown(ctx); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| // END BYTECODES // | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this after the
flags, and it doesn't need 32 bits.