Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
peephole
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Taddeüs Kroes
peephole
Commits
6181d33a
Commit
6181d33a
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Fixed copy propagation name conflicts.
parent
24c91ff6
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/copy_propagation.py
+32
-32
32 additions, 32 deletions
src/copy_propagation.py
src/optimize/advanced.py
+3
-3
3 additions, 3 deletions
src/optimize/advanced.py
src/program.py
+5
-5
5 additions, 5 deletions
src/program.py
tests/test_optimize_advanced.py
+11
-11
11 additions, 11 deletions
tests/test_optimize_advanced.py
with
51 additions
and
51 deletions
src/copy_propagation.py
+
32
−
32
View file @
6181d33a
...
...
@@ -59,35 +59,35 @@ def create_in_out(blocks):
#create_sets(blocks[0], True)
def
propagate_copies
(
block
):
changed
=
False
# For each copy statement s: x = y do
for
s
in
block
:
if
s
.
is_command
(
'
move
'
):
x
,
y
=
s
# Determine the uses of x reached by this definition of x
uses
=
filter
(
lambda
suc
:
s
.
sid
in
suc
.
reach_in
,
block
.
edges_to
)
# Determine if for each of those uses this is the only
# definition reaching it -> s in in[B_use]
only_def
=
True
for
b_use
in
uses
:
if
(
x
,
y
)
not
in
b_use
.
copy_in
:
only_def
=
False
# If so, remove s and replace the uses of x by uses of y
if
only_def
:
for
use
in
uses
:
print
'
use:
'
,
use
for
statement
in
use
:
if
statement
.
uses
(
x
):
statement
.
replace_usage
(
x
,
y
)
message
=
'
Replaced %s with %s
'
%
(
x
,
y
)
print
message
statement
.
set_inline_comment
(
message
)
changed
=
True
return
changed
#
def propagate_copies(block):
#
changed = False
#
#
# For each copy statement s: x = y do
#
for s in block:
#
if s.is_command('move'):
#
x, y = s
#
#
# Determine the uses of x reached by this definition of x
#
uses = filter(lambda suc: s.sid in suc.reach_in, block.edges_to)
#
#
# Determine if for each of those uses this is the only
#
# definition reaching it -> s in in[B_use]
#
only_def = True
#
#
for b_use in uses:
#
if (x, y) not in b_use.copy_in:
#
only_def = False
#
#
# If so, remove s and replace the uses of x by uses of y
#
if only_def:
#
for use in uses:
#
print 'use:', use
#
for statement in use:
#
if statement.uses(x):
#
statement.replace_usage(x, y)
#
message = ' Replaced %s with %s' % (x, y)
#
print message
#
statement.set_inline_comment(message)
#
changed = True
#
#
return changed
This diff is collapsed.
Click to expand it.
src/optimize/advanced.py
+
3
−
3
View file @
6181d33a
...
...
@@ -282,7 +282,7 @@ def fold_constants(block):
return
changed
#def
copy_
propagat
ion
(block):
#def propagat
e_copies
(block):
# """
# Unpack a move instruction, by replacing its destination
# address with its source address in the code following the move instruction.
...
...
@@ -343,7 +343,7 @@ def fold_constants(block):
# return changed
#def
copy_
propagat
ion
(block):
#def propagat
e_copies
(block):
# """
# Unpack a move instruction, by replacing its destination
# address with its source address in the code following the move instruction.
...
...
@@ -420,7 +420,7 @@ def fold_constants(block):
# return changed
def
copy_
propagat
ion
(
block
):
def
propagat
e_copies
(
block
):
"""
Unpack a move instruction, by replacing its destination
address with its source address in the code following the move instruction.
...
...
This diff is collapsed.
Click to expand it.
src/program.py
+
5
−
5
View file @
6181d33a
...
...
@@ -4,11 +4,11 @@ from dataflow import find_basic_blocks, generate_flow_graph
from
optimize.redundancies
import
remove_redundant_jumps
,
remove_redundancies
,
\
remove_redundant_branch_jumps
from
optimize.advanced
import
eliminate_common_subexpressions
,
\
fold_constants
,
copy_
propagat
ion
,
eliminate_dead_code
fold_constants
,
propagat
e_copies
,
eliminate_dead_code
import
liveness
import
reaching_definitions
#
import copy_propagation
as copy_propagation_flow
import
copy_propagation
from
writer
import
write_statements
...
...
@@ -95,7 +95,7 @@ class Program(Block):
if
fold_constants
(
block
):
changed
=
True
if
copy_
propagat
ion
(
block
):
if
propagat
e_copies
(
block
):
changed
=
True
if
eliminate_dead_code
(
block
):
...
...
@@ -104,7 +104,7 @@ class Program(Block):
#if remove_redundancies(block) \
# | eliminate_common_subexpressions(block) \
# | fold_constants(block) \
# |
copy_
propagat
ion
(block) \
# | propagat
e_copies
(block) \
# | eliminate_dead_code(block):
# changed = True
...
...
@@ -129,7 +129,7 @@ class Program(Block):
generate_flow_graph
(
self
.
blocks
)
liveness
.
create_in_out
(
self
.
blocks
)
reaching_definitions
.
create_in_out
(
self
.
blocks
)
#
copy_propagation
_flow
.create_in_out(self.blocks)
copy_propagation
.
create_in_out
(
self
.
blocks
)
def
save
(
self
,
filename
):
"""
Save the program in the specified file.
"""
...
...
This diff is collapsed.
Click to expand it.
tests/test_optimize_advanced.py
+
11
−
11
View file @
6181d33a
...
...
@@ -2,7 +2,7 @@ import unittest
from
copy
import
copy
from
src.optimize.advanced
import
eliminate_common_subexpressions
,
\
fold_constants
,
copy_
propagat
ion
fold_constants
,
propagat
e_copies
from
src.statement
import
Statement
as
S
from
src.dataflow
import
BasicBlock
as
B
,
generate_flow_graph
import
src.liveness
as
liveness
...
...
@@ -40,49 +40,49 @@ class TestOptimizeAdvanced(unittest.TestCase):
def
test_fold_constants
(
self
):
pass
#def test_
copy_
propagat
ion
_true(self):
#def test_propagat
e_copies
_true(self):
# block = B([self.foo,
# S('command', 'move', '$1', '$2'),
# self.foo,
# S('command', 'addu', '$3', '$1', '$4'),
# self.bar])
# self.assertTrue(
copy_
propagat
ion
(block))
# self.assertTrue(propagat
e_copies
(block))
# self.assertEqual(block.statements, [self.foo,
# S('command', 'move', '$1', '$2'),
# self.foo,
# S('command', 'addu', '$3', '$2', '$4'),
# self.bar])
def
test_
copy_
propagat
ion
_other_arg
(
self
):
def
test_propagat
e_copies
_other_arg
(
self
):
block
=
B
([
self
.
foo
,
S
(
'
command
'
,
'
move
'
,
'
$1
'
,
'
$2
'
),
self
.
foo
,
S
(
'
command
'
,
'
addu
'
,
'
$3
'
,
'
$4
'
,
'
$1
'
),
self
.
bar
])
self
.
assertTrue
(
copy_
propagat
ion
(
block
))
self
.
assertTrue
(
propagat
e_copies
(
block
))
self
.
assertEqual
(
block
.
statements
,
[
self
.
foo
,
S
(
'
command
'
,
'
move
'
,
'
$1
'
,
'
$2
'
),
self
.
foo
,
S
(
'
command
'
,
'
addu
'
,
'
$3
'
,
'
$4
'
,
'
$2
'
),
self
.
bar
])
#def test_
copy_
propagat
ion
_overwrite(self):
#def test_propagat
e_copies
_overwrite(self):
# block = B([self.foo,
# S('command', 'move', '$1', '$2'),
# S('command', 'move', '$1', '$5'),
# S('command', 'addu', '$3', '$1', '$4'),
# self.bar])
# self.assertTrue(
copy_
propagat
ion
(block))
# self.assertTrue(propagat
e_copies
(block))
# self.assertEqual(block.statements, [self.foo,
# S('command', 'move', '$1', '$2'),
# S('command', 'move', '$1', '$5'),
# S('command', 'addu', '$3', '$5', '$4'),
# self.bar])
def
test_
copy_
propagat
ion
_false
(
self
):
def
test_propagat
e_copies
_false
(
self
):
arguments
=
[
self
.
foo
,
S
(
'
command
'
,
'
move
'
,
'
$1
'
,
'
$2
'
),
S
(
'
command
'
,
'
move
'
,
'
$10
'
,
'
$20
'
),
...
...
@@ -90,10 +90,10 @@ class TestOptimizeAdvanced(unittest.TestCase):
S
(
'
command
'
,
'
addu
'
,
'
$3
'
,
'
$1
'
,
'
$4
'
),
self
.
bar
]
block
=
B
(
arguments
)
self
.
assertFalse
(
copy_
propagat
ion
(
block
))
self
.
assertFalse
(
propagat
e_copies
(
block
))
self
.
assertEqual
(
block
.
statements
,
arguments
)
def
test_
copy_
propagat
ion
_false_severalmoves
(
self
):
def
test_propagat
e_copies
_false_severalmoves
(
self
):
arguments
=
[
self
.
foo
,
S
(
'
command
'
,
'
move
'
,
'
$1
'
,
'
$2
'
),
self
.
foo
,
...
...
@@ -101,7 +101,7 @@ class TestOptimizeAdvanced(unittest.TestCase):
S
(
'
command
'
,
'
addu
'
,
'
$3
'
,
'
$1
'
,
'
$4
'
),
self
.
bar
]
block
=
B
(
arguments
)
self
.
assertFalse
(
copy_
propagat
ion
(
block
))
self
.
assertFalse
(
propagat
e_copies
(
block
))
self
.
assertEqual
(
block
.
statements
,
arguments
)
#def test_algebraic_transforms_add0(self):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment