Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.3k
gh-132732: Automatically constant evaluate pure operations#132733
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
1ffbb6b
691084d
b89e4dc
0959918
2541683
d5b2208
71ced86
a10d5a1
d22f165
8ae38c7
712a810
dc2d922
f3f2a69
53ce10f
17634a8
4937c2f
ae08b79
c0c6600
6bdd3f9
de8e170
c2f8e22
ac7e343
05b822f
b4c2e93
d229f57
c4aae6c
8552182
703dfc9
b278734
73a8b00
4116a31
548b67c
74a0208
6a5dc12
3896775
507c80a
dc68b45
41a271c
e88b71a
866510f
01be0c6
fce79a6
9bef4a4
1f76e2c
efb9888
029c92b
738d20e
202af76
4c0c52c
e24e9a3
f362866
d54a6f2
2644cb9
634ed26
0e9ce84
f2fc3fc
2408fb0
e40cb06
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -159,6 +159,26 @@ _Py_uop_sym_get_const_as_stackref(JitOptContext *ctx, JitOptSymbol *sym) | ||
return PyStackRef_FromPyObjectImmortalUnchecked(const_val); | ||
} | ||
/* | ||
Indicates whether the constant is safe to constant evaluate | ||
(without side effects). | ||
*/ | ||
bool | ||
_Py_uop_sym_is_safe_const(JitOptContext *ctx, JitOptSymbol *sym) | ||
{ | ||
PyObject *const_val = _Py_uop_sym_get_const(ctx, sym); | ||
if (const_val == NULL) { | ||
return false; | ||
} | ||
PyTypeObject *typ = Py_TYPE(const_val); | ||
return (typ == &PyLong_Type) || | ||
(typ == &PyUnicode_Type) || | ||
(typ == &PyFloat_Type) || | ||
(typ == &PyDict_Type) || | ||
(typ == &PyTuple_Type) || | ||
(typ == &PyList_Type); | ||
Fidget-Spinner marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
} | ||
void | ||
_Py_uop_sym_set_type(JitOptContext *ctx, JitOptSymbol *sym, PyTypeObject *typ) | ||
{ | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -187,8 +187,8 @@ def write_uop_pure_evaluation_region_header( | ||
emitter.emit("if (\n") | ||
assert len(uop.stack.inputs) > 0, "Pure operations must have at least 1 input" | ||
for inp in uop.stack.inputs[:-1]: | ||
Fidget-Spinner marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
emitter.emit(f"sym_is_safe_const(ctx, {inp.name}) &&\n") | ||
emitter.emit(f"sym_is_safe_const(ctx, {uop.stack.inputs[-1].name})\n") | ||
emitter.emit(') {\n') | ||
# Declare variables, before they are shadowed. | ||
for inp in uop.stack.inputs: | ||