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
8fa5681c
Commit
8fa5681c
authored
Dec 22, 2011
by
Jayke Meijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Global optimalizations are now.
parent
01466521
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
110 additions
and
2 deletions
+110
-2
src/optimize.py
src/optimize.py
+3
-2
tests/test_optimize.py
tests/test_optimize.py
+107
-0
No files found.
src/optimize.py
View file @
8fa5681c
...
...
@@ -64,7 +64,7 @@ def optimize_global(statements):
lw
=
statements
.
peek
()
if
lw
.
is_command
(
'lw'
)
and
lw
[
-
1
]
==
'0(%s)'
%
s
[
0
]:
lw
[
-
1
]
=
s
[
2
]
+
lw
[
1
:]
lw
[
-
1
]
=
s
tr
(
s
[
2
])
+
lw
[
-
1
]
[
1
:]
statements
.
replace
(
2
,
[
lw
])
continue
...
...
@@ -78,7 +78,8 @@ def optimize_global(statements):
j
,
label
=
following
if
j
.
is_command
(
'j'
)
and
label
.
is_label
(
s
[
2
]):
s
[
2
]
=
label
.
name
s
.
name
=
'bne'
s
[
2
]
=
j
[
0
]
statements
.
replace
(
3
,
[
s
,
label
])
...
...
tests/test_optimize.py
View file @
8fa5681c
...
...
@@ -109,3 +109,110 @@ class TestOptimize(unittest.TestCase):
optimize_global
(
block
)
self
.
assertEquals
(
block
.
statements
,
arguments
)
def
test_optimize_global_shift_true
(
self
):
foo
=
S
(
'command'
,
'foo'
)
bar
=
S
(
'command'
,
'bar'
)
block
=
B
([
foo
,
S
(
'command'
,
'sll'
,
'$regA'
,
'$regA'
,
0
),
bar
])
optimize_global
(
block
)
self
.
assertEquals
(
block
.
statements
,
[
foo
,
bar
])
def
test_optimize_global_shift_false
(
self
):
foo
=
S
(
'command'
,
'foo'
)
bar
=
S
(
'command'
,
'bar'
)
arguments
=
[
foo
,
\
S
(
'command'
,
'sll'
,
'$regA'
,
'$regB'
,
0
),
\
bar
]
block
=
B
(
arguments
)
optimize_global
(
block
)
self
.
assertEquals
(
block
.
statements
,
arguments
)
arguments2
=
[
foo
,
\
S
(
'command'
,
'sll'
,
'$regA'
,
'$regA'
,
1
),
\
bar
]
block2
=
B
(
arguments2
)
optimize_global
(
block2
)
self
.
assertEquals
(
block2
.
statements
,
arguments2
)
def
test_optimize_global_add_lw_true
(
self
):
foo
=
S
(
'command'
,
'foo'
)
bar
=
S
(
'command'
,
'bar'
)
block
=
B
([
foo
,
S
(
'command'
,
'add'
,
'$regA'
,
'$regA'
,
10
),
S
(
'command'
,
'lw'
,
'$regB'
,
'0($regA)'
),
bar
])
optimize_global
(
block
)
self
.
assertEquals
(
block
.
statements
,
[
foo
,
S
(
'command'
,
'lw'
,
'$regB'
,
'10($regA)'
),
bar
])
def
test_optimize_global_add_lw_false
(
self
):
foo
=
S
(
'command'
,
'foo'
)
bar
=
S
(
'command'
,
'bar'
)
arguments
=
[
foo
,
\
S
(
'command'
,
'add'
,
'$regA'
,
'$regA'
,
10
),
\
S
(
'command'
,
'lw'
,
'$regB'
,
'0($regC)'
),
\
bar
]
block
=
B
(
arguments
)
optimize_global
(
block
)
arguments2
=
[
foo
,
\
S
(
'command'
,
'add'
,
'$regA'
,
'$regB'
,
10
),
\
S
(
'command'
,
'lw'
,
'$regB'
,
'0($regA)'
),
\
bar
]
block2
=
B
(
arguments2
)
arguments3
=
[
foo
,
\
S
(
'command'
,
'add'
,
'$regA'
,
'$regA'
,
10
),
\
S
(
'command'
,
'lw'
,
'$regB'
,
'1($regA)'
),
\
bar
]
block3
=
B
(
arguments3
)
optimize_global
(
block3
)
self
.
assertEquals
(
block
.
statements
,
arguments
)
self
.
assertEquals
(
block2
.
statements
,
arguments2
)
self
.
assertEquals
(
block3
.
statements
,
arguments3
)
# beq ..., $Lx -> bne ..., $Ly
# j $Ly $Lx:
# $Lx:
def
test_optimize_global_beq_j_true
(
self
):
foo
=
S
(
'command'
,
'foo'
)
bar
=
S
(
'command'
,
'bar'
)
block
=
B
([
foo
,
S
(
'command'
,
'beq'
,
'$regA'
,
'$regB'
,
'$Lx'
),
S
(
'command'
,
'j'
,
'$Ly'
),
S
(
'label'
,
'$Lx'
),
bar
])
optimize_global
(
block
)
self
.
assertEquals
(
block
.
statements
,
[
foo
,
S
(
'command'
,
'bne'
,
'$regA'
,
'$regB'
,
'$Ly'
),
S
(
'label'
,
'$Lx'
),
bar
])
def
test_optimize_global_beq_j_false
(
self
):
foo
=
S
(
'command'
,
'foo'
)
bar
=
S
(
'command'
,
'bar'
)
arguments
=
[
foo
,
\
S
(
'command'
,
'beq'
,
'$regA'
,
'$regB'
,
'$Lz'
),
\
S
(
'command'
,
'j'
,
'$Ly'
),
\
S
(
'label'
,
'$Lx'
),
\
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