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
e3796724
Commit
e3796724
authored
Dec 22, 2011
by
Jayke Meijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added unittests and fixed problems that arose from that.
parent
bb1f3ba0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
6 deletions
+65
-6
src/optimize.py
src/optimize.py
+6
-3
src/statement.py
src/statement.py
+1
-0
tests/test_optimize.py
tests/test_optimize.py
+58
-3
No files found.
src/optimize.py
View file @
e3796724
import
re
from
dataflow
import
find_basic_blocks
...
...
@@ -36,9 +38,10 @@ def optimize_global(statements):
mov
,
jal
=
following
if
mov
.
is_command
(
'move'
)
and
mov
[
1
]
==
s
[
0
]
\
and
re
.
match
(
'^
\
$[
4
-7]$'
,
mov
[
0
])
\
and
jal
.
is_command
(
'jal'
):
s
[
0
]
=
mov
[
0
]
statements
.
replace
(
1
,
[],
start
=
statements
.
pointer
+
1
)
statements
.
replace
(
2
,
[
s
]
)
continue
# sw $regA, XX -> sw $regA, XX
...
...
@@ -46,8 +49,8 @@ def optimize_global(statements):
if
s
.
is_command
(
'sw'
):
ld
=
statements
.
peek
()
if
ld
.
is_command
(
'ld'
)
and
ld
.
args
==
s
.
args
:
statements
.
replace
(
2
,
[
ld
])
if
ld
.
is_command
(
'ld'
)
and
ld
[
0
]
==
s
[
0
]
:
statements
.
replace
(
2
,
[
s
])
continue
# shift $regA, $regA, 0 -> --- remove it
...
...
src/statement.py
View file @
e3796724
...
...
@@ -120,6 +120,7 @@ class Block:
replacement."""
if self.pointer == 0:
raise Exception('
No
statement
have
been
read
yet
.
')
if start == None:
start = self.pointer - 1
...
...
tests/test_optimize.py
View file @
e3796724
...
...
@@ -44,13 +44,68 @@ class TestOptimize(unittest.TestCase):
def
test_optimize_global_movinst_false
(
self
):
foo
=
S
(
'command'
,
'foo'
)
bar
=
S
(
'command'
,
'bar'
)
statements
=
[
foo
,
\
S
(
'command'
,
'move'
,
'$regA'
,
'$regB'
),
\
S
(
'command'
,
'addu'
,
'$regA'
,
'$regC'
,
2
),
\
bar
]
block
=
B
(
statements
)
optimize_global
(
block
)
self
.
assertEquals
(
block
.
statements
,
statements
)
def
test_optimize_global_instr_mov_jal_true
(
self
):
foo
=
S
(
'command'
,
'foo'
)
bar
=
S
(
'command'
,
'bar'
)
block
=
B
([
foo
,
S
(
'command'
,
'move'
,
'$regA'
,
'$regB'
),
S
(
'command'
,
'addu'
,
'$regA'
,
'$regC'
,
2
),
S
(
'command'
,
'move'
,
'$4'
,
'$regA'
),
S
(
'command'
,
'jal'
,
'L1'
),
bar
])
optimize_global
(
block
)
self
.
assertEquals
(
block
.
statements
,
[
foo
,
S
(
'command'
,
'move'
,
'$regA'
,
'$regB'
),
S
(
'command'
,
'addu'
,
'$regA'
,
'$regC'
,
2
),
S
(
'command'
,
'addu'
,
'$4'
,
'$regC'
,
2
),
S
(
'command'
,
'jal'
,
'L1'
),
bar
])
def
test_optimize_global_instr_mov_jal_false
(
self
):
foo
=
S
(
'command'
,
'foo'
)
bar
=
S
(
'command'
,
'bar'
)
arguments
=
[
foo
,
\
S
(
'command'
,
'addu'
,
'$regA'
,
'$regC'
,
2
),
\
S
(
'command'
,
'move'
,
'$3'
,
'$regA'
),
\
S
(
'command'
,
'jal'
,
'L1'
),
\
bar
]
block
=
B
(
arguments
)
optimize_global
(
block
)
self
.
assertEquals
(
block
.
statements
,
arguments
)
def
test_optimize_global_sw_ld_true
(
self
):
foo
=
S
(
'command'
,
'foo'
)
bar
=
S
(
'command'
,
'bar'
)
block
=
B
([
foo
,
S
(
'command'
,
'sw'
,
'$regA'
,
'$regB'
),
S
(
'command'
,
'ld'
,
'$regA'
,
'$regC'
),
bar
])
optimize_global
(
block
)
self
.
assertEquals
(
block
.
statements
,
[
foo
,
S
(
'command'
,
'sw'
,
'$regA'
,
'$regB'
),
bar
])
def
test_optimize_global_sw_ld_false
(
self
):
foo
=
S
(
'command'
,
'foo'
)
bar
=
S
(
'command'
,
'bar'
)
arguments
=
[
foo
,
\
S
(
'command'
,
'sw'
,
'$regA'
,
'$regB'
),
\
S
(
'command'
,
'ld'
,
'$regD'
,
'$regC'
),
\
bar
]
block
=
B
(
arguments
)
optimize_global
(
block
)
self
.
assertEquals
(
block
.
statements
,
arguments
)
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