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
ff70b648
Commit
ff70b648
authored
13 years ago
by
Jayke Meijer
Browse files
Options
Downloads
Patches
Plain Diff
Added j-label optimization.
parent
2eed7245
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/redundancies.py
+18
-1
18 additions, 1 deletion
src/optimize/redundancies.py
tests/test_optimize.py
+52
-29
52 additions, 29 deletions
tests/test_optimize.py
with
70 additions
and
30 deletions
src/optimize/redundancies.py
+
18
−
1
View file @
ff70b648
...
@@ -123,8 +123,25 @@ def add_lw(add, statements):
...
@@ -123,8 +123,25 @@ def add_lw(add, statements):
return
True
return
True
def
remove_redundant_jumps
(
statements
):
def
remove_redundant_jumps
(
statements
):
"""
Remove jump if label follows immediatly.
"""
old_len
=
-
1
while
old_len
!=
len
(
statements
):
old_len
=
len
(
statements
)
while
not
statements
.
end
():
s
=
statements
.
read
()
# j $Lx -> $Lx:
# $Lx:
if
s
.
is_command
(
'
j
'
):
following
=
statements
.
peek
(
2
)
if
following
.
is_label
(
s
[
0
]):
statements
.
replace
(
1
,
[])
def
remove_redundant_branch_jumps
(
statements
):
"""
Optimize statement sequences on a global level.
"""
"""
Optimize statement sequences on a global level.
"""
old_len
=
-
1
old_len
=
-
1
...
...
This diff is collapsed.
Click to expand it.
tests/test_optimize.py
+
52
−
29
View file @
ff70b648
...
@@ -172,72 +172,95 @@ class TestOptimize(unittest.TestCase):
...
@@ -172,72 +172,95 @@ class TestOptimize(unittest.TestCase):
self
.
assertEquals
(
block
.
statements
,
arguments
)
self
.
assertEquals
(
block
.
statements
,
arguments
)
self
.
assertEquals
(
block2
.
statements
,
arguments2
)
self
.
assertEquals
(
block2
.
statements
,
arguments2
)
self
.
assertEquals
(
block3
.
statements
,
arguments3
)
self
.
assertEquals
(
block3
.
statements
,
arguments3
)
def
test_optimize_block_move_move_true
(
self
):
block
=
B
([
self
.
foo
,
S
(
'
command
'
,
'
move
'
,
'
$regA
'
,
'
$regB
'
),
S
(
'
command
'
,
'
move
'
,
'
$regB
'
,
'
$regA
'
),
self
.
bar
])
remove_redundancies
(
block
)
self
.
assertEquals
(
block
.
statements
,
[
self
.
foo
,
S
(
'
command
'
,
'
move
'
,
'
$regA
'
,
'
$regB
'
),
self
.
bar
])
def
test_optimize_block_mov_mov_false
(
self
):
arguments
=
[
self
.
foo
,
\
S
(
'
command
'
,
'
move
'
,
'
$regA
'
,
'
$regB
'
),
\
S
(
'
command
'
,
'
move
'
,
'
$regB
'
,
'
$regC
'
),
\
self
.
bar
]
block
=
B
(
arguments
)
remove_redundancies
(
block
)
def
test_remove_redundant_jumps_beq_j_true
(
self
):
self
.
assertEquals
(
block
.
statements
,
arguments
)
def
test_remove_redundant_jumps_true
(
self
):
block
=
B
([
self
.
foo
,
S
(
'
command
'
,
'
j
'
,
'
$L1
'
),
S
(
'
label
'
,
'
$L1
'
),
self
.
bar
])
remove_redundancies
(
block
)
self
.
assertEqual
(
block
.
statements
,
B
([
self
.
foo
,
S
(
'
command
'
,
'
j
'
,
'
$L1
'
),
self
.
bar
]))
def
test_remove_redundant_jumps_false
(
self
):
arguments
=
[
self
.
foo
,
S
(
'
command
'
,
'
j
'
,
'
$L1
'
),
S
(
'
label
'
,
'
$L2
'
),
self
.
bar
]
block
=
B
(
arguments
)
remove_redundancies
(
block
)
self
.
assertEqual
(
block
.
statements
,
arguments
)
def
test_remove_redundant_branch_jumps_beq_j_true
(
self
):
block
=
B
([
self
.
foo
,
block
=
B
([
self
.
foo
,
S
(
'
command
'
,
'
beq
'
,
'
$regA
'
,
'
$regB
'
,
'
$Lx
'
),
S
(
'
command
'
,
'
beq
'
,
'
$regA
'
,
'
$regB
'
,
'
$Lx
'
),
S
(
'
command
'
,
'
j
'
,
'
$Ly
'
),
S
(
'
command
'
,
'
j
'
,
'
$Ly
'
),
S
(
'
label
'
,
'
$Lx
'
),
S
(
'
label
'
,
'
$Lx
'
),
self
.
bar
])
self
.
bar
])
remove_redundant_jumps
(
block
)
remove_redundant_
branch_
jumps
(
block
)
self
.
assertEquals
(
block
.
statements
,
[
self
.
foo
,
self
.
assertEquals
(
block
.
statements
,
[
self
.
foo
,
S
(
'
command
'
,
'
bne
'
,
'
$regA
'
,
'
$regB
'
,
'
$Ly
'
),
S
(
'
command
'
,
'
bne
'
,
'
$regA
'
,
'
$regB
'
,
'
$Ly
'
),
S
(
'
label
'
,
'
$Lx
'
),
S
(
'
label
'
,
'
$Lx
'
),
self
.
bar
])
self
.
bar
])
def
test_remove_redundant_jumps_beq_j_false
(
self
):
def
test_remove_redundant_
branch_
jumps_beq_j_false
(
self
):
arguments
=
[
self
.
foo
,
\
arguments
=
[
self
.
foo
,
\
S
(
'
command
'
,
'
beq
'
,
'
$regA
'
,
'
$regB
'
,
'
$Lz
'
),
\
S
(
'
command
'
,
'
beq
'
,
'
$regA
'
,
'
$regB
'
,
'
$Lz
'
),
\
S
(
'
command
'
,
'
j
'
,
'
$Ly
'
),
\
S
(
'
command
'
,
'
j
'
,
'
$Ly
'
),
\
S
(
'
label
'
,
'
$Lx
'
),
\
S
(
'
label
'
,
'
$Lx
'
),
\
self
.
bar
]
self
.
bar
]
block
=
B
(
arguments
)
block
=
B
(
arguments
)
remove_redundant_jumps
(
block
)
remove_redundant_
branch_
jumps
(
block
)
self
.
assertEquals
(
block
.
statements
,
arguments
)
self
.
assertEquals
(
block
.
statements
,
arguments
)
def
test_remove_redundant_jumps_bne_j_true
(
self
):
def
test_remove_redundant_
branch_
jumps_bne_j_true
(
self
):
block
=
B
([
self
.
foo
,
block
=
B
([
self
.
foo
,
S
(
'
command
'
,
'
bne
'
,
'
$regA
'
,
'
$regB
'
,
'
$Lx
'
),
S
(
'
command
'
,
'
bne
'
,
'
$regA
'
,
'
$regB
'
,
'
$Lx
'
),
S
(
'
command
'
,
'
j
'
,
'
$Ly
'
),
S
(
'
command
'
,
'
j
'
,
'
$Ly
'
),
S
(
'
label
'
,
'
$Lx
'
),
S
(
'
label
'
,
'
$Lx
'
),
self
.
bar
])
self
.
bar
])
remove_redundant_jumps
(
block
)
remove_redundant_
branch_
jumps
(
block
)
self
.
assertEquals
(
block
.
statements
,
[
self
.
foo
,
self
.
assertEquals
(
block
.
statements
,
[
self
.
foo
,
S
(
'
command
'
,
'
beq
'
,
'
$regA
'
,
'
$regB
'
,
'
$Ly
'
),
S
(
'
command
'
,
'
beq
'
,
'
$regA
'
,
'
$regB
'
,
'
$Ly
'
),
S
(
'
label
'
,
'
$Lx
'
),
S
(
'
label
'
,
'
$Lx
'
),
self
.
bar
])
self
.
bar
])
def
test_remove_redundant_jumps_bne_j_false
(
self
):
def
test_remove_redundant_
branch_
jumps_bne_j_false
(
self
):
arguments
=
[
self
.
foo
,
\
arguments
=
[
self
.
foo
,
\
S
(
'
command
'
,
'
bne
'
,
'
$regA
'
,
'
$regB
'
,
'
$Lz
'
),
\
S
(
'
command
'
,
'
bne
'
,
'
$regA
'
,
'
$regB
'
,
'
$Lz
'
),
\
S
(
'
command
'
,
'
j
'
,
'
$Ly
'
),
\
S
(
'
command
'
,
'
j
'
,
'
$Ly
'
),
\
S
(
'
label
'
,
'
$Lx
'
),
\
S
(
'
label
'
,
'
$Lx
'
),
\
self
.
bar
]
self
.
bar
]
block
=
B
(
arguments
)
block
=
B
(
arguments
)
remove_redundant_jumps
(
block
)
remove_redundant_branch_jumps
(
block
)
self
.
assertEquals
(
block
.
statements
,
arguments
)
def
test_optimize_block_move_move_true
(
self
):
block
=
B
([
self
.
foo
,
S
(
'
command
'
,
'
move
'
,
'
$regA
'
,
'
$regB
'
),
S
(
'
command
'
,
'
move
'
,
'
$regB
'
,
'
$regA
'
),
self
.
bar
])
remove_redundancies
(
block
)
self
.
assertEquals
(
block
.
statements
,
[
self
.
foo
,
S
(
'
command
'
,
'
move
'
,
'
$regA
'
,
'
$regB
'
),
self
.
bar
])
def
test_optimize_block_mov_mov_false
(
self
):
arguments
=
[
self
.
foo
,
\
S
(
'
command
'
,
'
move
'
,
'
$regA
'
,
'
$regB
'
),
\
S
(
'
command
'
,
'
move
'
,
'
$regB
'
,
'
$regC
'
),
\
self
.
bar
]
block
=
B
(
arguments
)
remove_redundancies
(
block
)
self
.
assertEquals
(
block
.
statements
,
arguments
)
self
.
assertEquals
(
block
.
statements
,
arguments
)
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