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
45947974
Commit
45947974
authored
13 years ago
by
Jayke Meijer
Browse files
Options
Downloads
Patches
Plain Diff
Added algebraic conversions and first unittest for those.
parent
a2133db3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/optimize/advanced.py
+27
-0
27 additions, 0 deletions
src/optimize/advanced.py
tests/test_optimize_advanced.py
+11
-1
11 additions, 1 deletion
tests/test_optimize_advanced.py
with
38 additions
and
1 deletion
src/optimize/advanced.py
+
27
−
0
View file @
45947974
...
...
@@ -208,3 +208,30 @@ def copy_propagation(block):
changed
=
True
return
changed
def
algebraic_transformations
(
block
):
"""
Change ineffective or useless algebraic transformations. Handled are:
- x = x + 0 -> remove
- x = x - 0 -> remove
- x = x * 1 -> remove
- x = x * 2 -> x = x << 1
"""
changed
=
False
while
not
block
.
end
():
changed
=
True
s
=
block
.
read
()
if
(
s
.
is_command
(
'
addu
'
)
or
s
.
is_command
(
'
subu
'
))
and
s
[
2
]
==
0
:
block
.
replace
(
1
,
[])
elif
s
.
is_command
(
'
mult
'
)
and
s
[
2
]
==
1
:
block
.
replace
(
1
,
[])
elif
s
.
is_command
(
'
mult
'
)
and
s
[
2
]
==
2
:
new_command
=
S
([
'
command
'
,
'
sll
'
,
s
[
0
],
s
[
1
],
1
])
block
.
replace
(
1
,
[
new_command
])
else
:
changed
=
False
return
changed
This diff is collapsed.
Click to expand it.
tests/test_optimize_advanced.py
+
11
−
1
View file @
45947974
import
unittest
from
src.optimize.advanced
import
eliminate_common_subexpressions
,
\
fold_constants
,
copy_propagation
fold_constants
,
copy_propagation
,
algebraic_transformations
from
src.statement
import
Statement
as
S
,
Block
as
B
...
...
@@ -63,3 +63,13 @@ class TestOptimizeAdvanced(unittest.TestCase):
block
=
B
(
arguments
)
self
.
assertFalse
(
copy_propagation
(
block
))
self
.
assertEqual
(
block
.
statements
,
arguments
)
def
test_algebraic_transforms_add0
(
self
):
block
=
B
([
self
.
foo
,
S
(
'
command
'
,
'
addu
'
,
'
$1
'
,
'
$2
'
,
0
),
self
.
bar
])
# self.assertTrue(copy_propagation(block))
algebraic_transformations
(
block
)
self
.
assertEqual
(
block
.
statements
,
[
self
.
foo
,
self
.
bar
])
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