-
-
Notifications
You must be signed in to change notification settings - Fork 32.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 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 1 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
10000
summary>
Filter by extension
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,7 +146,6 @@ class OptimizerEmitter(Emitter): | |
def __init__(self, out: CWriter, labels: dict[str, Label], original_uop: Uop, stack: Stack): | ||
super().__init__(out, labels) | ||
self._replacers["REPLACE_OPCODE_IF_EVALUATES_PURE"] = self.replace_opcode_if_evaluates_pure | ||
self.is_abstract = True | ||
self.original_uop = original_uop | ||
self.stack = stack | ||
|
||
|
@@ -169,6 +168,12 @@ def replace_opcode_if_evaluates_pure( | |
inst: Instruction | None, | ||
) -> bool: | ||
skip_to(tkn_iter, "SEMI") | ||
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. If you're just going to throw away the arguments, why have them? |
||
|
||
if self.original_uop.properties.escapes: | ||
raise analysis_error( | ||
f"REPLACE_OPCODE_IF_EVALUATES_PURE cannot be used with an escaping uop {self.original_uop.properties.escaping_calls}", | ||
self.original_uop.body.open | ||
) | ||
emitter = OptimizerConstantEmitter(self.out, {}, self.original_uop, copy.deepcopy(self.stack)) | ||
emitter.emit("if (\n") | ||
input_identifiers = replace_opcode_if_evaluates_pure_identifiers(uop) | ||
|
@@ -256,11 +261,12 @@ def write_uop( | |
override: Uop | None, | ||
uop: Uop, | ||
out: CWriter, | ||
stack: Stack, | ||
debug: bool, | ||
skip_inputs: bool, | ||
) -> None: | ||
locals: dict[str, Local] = {} | ||
prototype = override if override else uop | ||
stack = Stack() | ||
try: | ||
out.start_line() | ||
if override: | ||
|
@@ -285,8 +291,8 @@ def write_uop( | |
# No reference management of inputs needed. | ||
for var in storage.inputs: # type: ignore[possibly-undefined] | ||
var.in_local = False | ||
_, storage = emitter.emit_tokens(override, storage, None, False) | ||
out.start_line() | ||
_, storage = emitter.emit_tokens(override, storage, inst=None, emit_braces=False) | ||
storage.flush(out) | ||
out.start_line() | ||
else: | ||
|
@@ -335,7 +341,8 @@ def generate_abstract_interpreter( | |
declare_variables(override, out, skip_inputs=False) | ||
else: | ||
declare_variables(uop, out, skip_inputs=True) | ||
write_uop(override, uop, out, debug) | ||
stack = Stack() | ||
write_uop(override, uop, out, stack, debug, skip_inputs=(override is None)) | ||
out.start_line() | ||
out.emit("break;\n") | ||
out.emit("}") | ||
|
Uh oh!
There was an error while loading. Please reload this page.