Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[mypyc] Provide an easier way to define IR-to-IR transforms#16998

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

Merged
JukkaL merged 17 commits intomasterfrommypyc-ir-transform
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
17 commits
Select commitHold shift + click to select a range
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
PrevPrevious commit
NextNext commit
Fix chains of assignments
  • Loading branch information
@JukkaL
JukkaL committedMar 2, 2024
commit5095948e873b8d68f57aca8acacc12ef0fb11454
11 changes: 11 additions & 0 deletionsmypyc/test-data/opt-copy-propagation.test
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,6 +11,17 @@ def f(x):
L0:
return x

[case testCopyPropagationChain]
def f(x: int) -> int:
y = x
z = y
return z
[out]
def f(x):
x :: int
L0:
return x

[case testCopyPropagationTooComplex]
def f(b: bool, x: int) -> int:
if b:
Expand Down
13 changes: 12 additions & 1 deletionmypyc/transform/copy_propagation.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,11 @@

def do_copy_propagation(fn: FuncIR, options: CompilerOptions) -> None:
"""Perform copy propagation optimization for fn."""

# Anything with an assignment count >1 will not be optimized
# here, as it would be require data flow analysis and we want to
# keep this simple & fast, at least until we've made data flow
# analysis much faster.
counts = {}
replacements: dict[Value, Value] = {}
for arg in fn.arg_regs:
Expand All@@ -39,10 +44,16 @@ def do_copy_propagation(fn: FuncIR, options: CompilerOptions) -> None:
elif c == 1:
del replacements[op.dest]
elif isinstance(op, AssignMulti):
# Copy propagation not supported
# Copy propagation not supported for AssignMulti destinations
counts[op.dest] = 2
replacements.pop(op.dest, 0)

# Follow chains of propagation with multiple assignments.
for src, dst in list(replacements.items()):
while dst in replacements:
dst = replacements[dst]
replacements[src] = dst

b = LowLevelIRBuilder(None, options)
t = CopyPropagationTransform(b, replacements)
t.transform_blocks(fn.blocks)
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp