8000 gh-106581: Fix two bugs in the code generator's copy optimization by gvanrossum · Pull Request #108380 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-106581: Fix two bugs in the code generator's copy optimization #108380

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

Merged
merged 5 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Do more clever things with copies
  • Loading branch information
gvanrossum committed Aug 24, 2023
commit 848822f38cfca4356fb8fe0c57a8d06faaab0f99
1 change: 0 additions & 1 deletion Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 19 additions & 6 deletions Tools/cases_generator/stacking.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,12 @@ def __init__(
):
src = pred.pokes.pop(-1)
dst = self.peeks.pop(0)
src_offset = src.offset
dst_offset = dst.offset
assert src.offset.equivalent_to(dst.offset), (src, dst)
pred.final_offset.deeper(src.effect)
if dst.effect.name != UNUSED:
destinations.add(dst.effect.name)
if dst.effect.name != src.effect.name:
if dst.effect.name != src.effect.name:
if dst.effect.name != UNUSED:
destinations.add(dst.effect.name)
if src.effect.name != UNUSED:
sources.add(src.effect.name)
self.copies.append(CopyItem(src, dst))
# TODO: Turn this into an error (pass an Analyzer instance?)
Expand All @@ -226,6 +225,18 @@ def __init__(
else:
pred = None # Break

# Fix up patterns of copies through UNUSED,
# e.g. cp(a, UNUSED) + cp(UNUSED, b) -> cp(a, b).
if any(copy.src.effect.name == UNUSED for copy in self.copies):
pred = self
while pred := pred.pred:
for copy in self.copies:
if copy.src.effect.name == UNUSED:
for pred_copy in pred.copies:
if pred_copy.dst == copy.src:
copy.src = pred_copy.src
break

def adjust_deeper(self, eff: StackEffect) -> None:
for peek in self.peeks:
peek.offset.deeper(eff)
Expand Down Expand Up @@ -399,7 +410,9 @@ def write_components(
if copy_src_effect.name != copy.dst.effect.name:
if copy_src_effect.name == UNUSED:
copy_src_effect = copy.src.as_stack_effect()
out.assign(copy.dst.effect, copy_src_effect)
out.assign(copy.dst.effect, copy_src_effect)
else:
out.assign(copy.dst.effect, copy_sr 47FD c_effect)
for peek in mgr.peeks:
out.assign(
peek.effect,
Expand Down
0