Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
peephole
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
peephole
Commits
8c9efd40
Commit
8c9efd40
authored
Dec 28, 2011
by
Jayke Meijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed algebraic transformations to more generic form.
parent
5aba6a1e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
10 deletions
+13
-10
src/optimize/advanced.py
src/optimize/advanced.py
+7
-7
tests/test_optimize_advanced.py
tests/test_optimize_advanced.py
+6
-3
No files found.
src/optimize/advanced.py
View file @
8c9efd40
...
@@ -220,11 +220,11 @@ def copy_propagation(block):
...
@@ -220,11 +220,11 @@ def copy_propagation(block):
def
algebraic_transformations
(
block
):
def
algebraic_transformations
(
block
):
"""
"""
Change ineffective or useless algebraic transformations. Handled are:
Change ineffective or useless algebraic transformations. Handled are:
- x =
x + 0 -> remove
- x =
y + 0 -> x = y
- x =
x - 0 -> remove
- x =
y - 0 -> x = y
- x =
x * 1 -> remove
- x =
y * 1 -> x = y
- x =
x
* 0 -> x = 0
- x =
y
* 0 -> x = 0
- x =
x
* 2 -> x = x << 1
- x =
y
* 2 -> x = x << 1
"""
"""
changed
=
False
changed
=
False
...
@@ -232,10 +232,10 @@ def algebraic_transformations(block):
...
@@ -232,10 +232,10 @@ def algebraic_transformations(block):
s
=
block
.
read
()
s
=
block
.
read
()
if
(
s
.
is_command
(
'addu'
)
or
s
.
is_command
(
'subu'
))
and
s
[
2
]
==
0
:
if
(
s
.
is_command
(
'addu'
)
or
s
.
is_command
(
'subu'
))
and
s
[
2
]
==
0
:
block
.
replace
(
1
,
[])
block
.
replace
(
1
,
[
S
(
'command'
,
'move'
,
s
[
0
],
s
[
1
])
])
changed
=
True
changed
=
True
elif
s
.
is_command
(
'mult'
)
and
s
[
2
]
==
1
:
elif
s
.
is_command
(
'mult'
)
and
s
[
2
]
==
1
:
block
.
replace
(
1
,
[])
block
.
replace
(
1
,
[
S
(
'command'
,
'move'
,
s
[
0
],
s
[
1
])
])
changed
=
True
changed
=
True
elif
s
.
is_command
(
'mult'
)
and
s
[
2
]
==
0
:
elif
s
.
is_command
(
'mult'
)
and
s
[
2
]
==
0
:
block
.
replace
(
1
,
[
S
(
'command'
,
'li'
,
'$1'
,
to_hex
(
0
))])
block
.
replace
(
1
,
[
S
(
'command'
,
'li'
,
'$1'
,
to_hex
(
0
))])
...
...
tests/test_optimize_advanced.py
View file @
8c9efd40
...
@@ -78,7 +78,8 @@ class TestOptimizeAdvanced(unittest.TestCase):
...
@@ -78,7 +78,8 @@ class TestOptimizeAdvanced(unittest.TestCase):
self
.
assertTrue
(
algebraic_transformations
(
block
))
self
.
assertTrue
(
algebraic_transformations
(
block
))
self
.
assertEqual
(
block
.
statements
,
[
self
.
foo
,
self
.
assertEqual
(
block
.
statements
,
[
self
.
foo
,
self
.
bar
])
S
(
'command'
,
'move'
,
'$1'
,
'$2'
),
self
.
bar
])
def
test_algebraic_transforms_add1
(
self
):
def
test_algebraic_transforms_add1
(
self
):
arguments
=
[
self
.
foo
,
arguments
=
[
self
.
foo
,
...
@@ -96,7 +97,8 @@ class TestOptimizeAdvanced(unittest.TestCase):
...
@@ -96,7 +97,8 @@ class TestOptimizeAdvanced(unittest.TestCase):
self
.
assertTrue
(
algebraic_transformations
(
block
))
self
.
assertTrue
(
algebraic_transformations
(
block
))
self
.
assertEqual
(
block
.
statements
,
[
self
.
foo
,
self
.
assertEqual
(
block
.
statements
,
[
self
.
foo
,
self
.
bar
])
S
(
'command'
,
'move'
,
'$1'
,
'$2'
),
self
.
bar
])
def
test_algebraic_transforms_sub1
(
self
):
def
test_algebraic_transforms_sub1
(
self
):
arguments
=
[
self
.
foo
,
arguments
=
[
self
.
foo
,
...
@@ -124,7 +126,8 @@ class TestOptimizeAdvanced(unittest.TestCase):
...
@@ -124,7 +126,8 @@ class TestOptimizeAdvanced(unittest.TestCase):
self
.
assertTrue
(
algebraic_transformations
(
block
))
self
.
assertTrue
(
algebraic_transformations
(
block
))
self
.
assertEqual
(
block
.
statements
,
[
self
.
foo
,
self
.
assertEqual
(
block
.
statements
,
[
self
.
foo
,
self
.
bar
])
S
(
'command'
,
'move'
,
'$1'
,
'$2'
),
self
.
bar
])
def
test_algebraic_transforms_mult2
(
self
):
def
test_algebraic_transforms_mult2
(
self
):
block
=
B
([
self
.
foo
,
block
=
B
([
self
.
foo
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment