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
770cbc9f
Commit
770cbc9f
authored
Dec 30, 2011
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Plain Diff
Merged conflicts.
parents
fd60f13d
98c43ff0
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
46 additions
and
50 deletions
+46
-50
src/liveness.py
src/liveness.py
+2
-1
src/optimize/__init__.py
src/optimize/__init__.py
+3
-0
src/optimize/advanced.py
src/optimize/advanced.py
+1
-1
src/optimize/redundancies.py
src/optimize/redundancies.py
+6
-11
src/program.py
src/program.py
+2
-1
tests/test_liveness.py
tests/test_liveness.py
+29
-33
tests/test_reaching_definitions.py
tests/test_reaching_definitions.py
+3
-3
No files found.
src/liveness.py
View file @
770cbc9f
...
@@ -29,7 +29,8 @@ def create_use_def(block):
...
@@ -29,7 +29,8 @@ def create_use_def(block):
defined
=
set
()
defined
=
set
()
if
block
.
dummy
:
if
block
.
dummy
:
block
.
use_set
=
set
([
'$4'
,
'$5'
,
'$6'
,
'$7'
])
block
.
use_set
=
set
([
'$4'
,
'$5'
,
'$6'
,
'$7'
,
\
'$f0'
,
'$f3'
,
'$f4'
,
'$f12'
,
'$2'
])
block
.
def_set
=
set
([
'$2'
,
'$3'
])
block
.
def_set
=
set
([
'$2'
,
'$3'
])
return
return
...
...
src/optimize/__init__.py
View file @
770cbc9f
...
@@ -15,11 +15,14 @@ def optimize(program, verbose=0):
...
@@ -15,11 +15,14 @@ def optimize(program, verbose=0):
iterations
=
0
iterations
=
0
while
changed
:
while
changed
:
<<<<<<<
HEAD
iterations
+=
1
iterations
+=
1
if
verbose
>
1
:
if
verbose
>
1
:
print
'main iteration %d'
,
iterations
print
'main iteration %d'
,
iterations
=======
>>>>>>>
98
c43ff02c474a62e42ac89ba9fe20be98f9eccd
changed
=
False
changed
=
False
# Optimize on a global level
# Optimize on a global level
...
...
src/optimize/advanced.py
View file @
770cbc9f
...
@@ -95,7 +95,6 @@ def eliminate_common_subexpressions(block):
...
@@ -95,7 +95,6 @@ def eliminate_common_subexpressions(block):
%
(
s
.
name
,
', '
.
join
(
map
(
str
,
s
)))
%
(
s
.
name
,
', '
.
join
(
map
(
str
,
s
)))
block
.
insert
(
S
(
'command'
,
s
.
name
,
*
([
new_reg
]
+
args
)),
\
block
.
insert
(
S
(
'command'
,
s
.
name
,
*
([
new_reg
]
+
args
)),
\
index
=
occurrences
[
0
],
message
=
message
)
index
=
occurrences
[
0
],
message
=
message
)
changed
=
True
changed
=
True
# Reset pointer to continue from the original statement
# Reset pointer to continue from the original statement
...
@@ -267,6 +266,7 @@ def fold_constants(block):
...
@@ -267,6 +266,7 @@ def fold_constants(block):
else
'Substraction'
,
s
[
1
])
else
'Substraction'
,
s
[
1
])
block
.
replace
(
1
,
[
S
(
'command'
,
'move'
,
rd
,
s
[
1
])],
\
block
.
replace
(
1
,
[
S
(
'command'
,
'move'
,
rd
,
s
[
1
])],
\
message
=
message
)
message
=
message
)
changed
=
True
else
:
else
:
for
reg
in
s
.
get_def
():
for
reg
in
s
.
get_def
():
if
reg
in
register
:
if
reg
in
register
:
...
...
src/optimize/redundancies.py
View file @
770cbc9f
...
@@ -5,12 +5,8 @@ def remove_redundancies(block):
...
@@ -5,12 +5,8 @@ def remove_redundancies(block):
"""Execute all functions that remove redundant statements."""
"""Execute all functions that remove redundant statements."""
callbacks
=
[
move_aa
,
move_inst
,
instr_move_jal
,
move_move
,
sw_ld
,
shift
,
callbacks
=
[
move_aa
,
move_inst
,
instr_move_jal
,
move_move
,
sw_ld
,
shift
,
add_lw
]
add_lw
]
old_len
=
-
1
changed
=
False
changed
=
False
while
old_len
!=
len
(
block
):
old_len
=
len
(
block
)
block
.
reset
()
block
.
reset
()
while
not
block
.
end
():
while
not
block
.
end
():
...
@@ -19,7 +15,6 @@ def remove_redundancies(block):
...
@@ -19,7 +15,6 @@ def remove_redundancies(block):
for
callback
in
callbacks
:
for
callback
in
callbacks
:
if
callback
(
s
,
block
):
if
callback
(
s
,
block
):
changed
=
True
changed
=
True
break
return
changed
return
changed
...
...
src/program.py
View file @
770cbc9f
...
@@ -68,6 +68,7 @@ class Program(Block):
...
@@ -68,6 +68,7 @@ class Program(Block):
return
remove_redundant_jumps
(
self
)
\
return
remove_redundant_jumps
(
self
)
\
|
remove_redundant_branch_jumps
(
self
)
|
remove_redundant_branch_jumps
(
self
)
return
False
def
optimize_blocks
(
self
):
def
optimize_blocks
(
self
):
"""Optimize on block level. Keep executing all optimizations until no
"""Optimize on block level. Keep executing all optimizations until no
...
...
tests/test_liveness.py
View file @
770cbc9f
...
@@ -42,11 +42,11 @@ class TestLiveness(unittest.TestCase):
...
@@ -42,11 +42,11 @@ class TestLiveness(unittest.TestCase):
s34
=
S
(
'command'
,
'mflo'
,
'temp'
)
s34
=
S
(
'command'
,
'mflo'
,
'temp'
)
s35
=
S
(
'command'
,
'addu'
,
'return'
,
'temp'
,
'c'
)
s35
=
S
(
'command'
,
'addu'
,
'return'
,
'temp'
,
'c'
)
b1
,
b2
,
b3
=
find_basic_blocks
([
s11
,
s12
,
s13
,
s14
,
s15
,
s21
,
s22
,
\
b1
,
b2
,
b3
,
b4
=
find_basic_blocks
([
s11
,
s12
,
s13
,
s14
,
s15
,
s21
,
s22
,
\
s31
,
s32
,
s33
,
s34
,
s35
])
s31
,
s32
,
s33
,
s34
,
s35
])
generate_flow_graph
([
b1
,
b2
,
b3
])
generate_flow_graph
([
b1
,
b2
,
b3
,
b4
])
create_in_out
([
b1
,
b2
,
b3
])
create_in_out
([
b1
,
b2
,
b3
,
b4
])
self
.
assertEqual
(
b1
.
use_set
,
set
())
self
.
assertEqual
(
b1
.
use_set
,
set
())
self
.
assertEqual
(
b1
.
def_set
,
set
([
'a'
,
'b'
,
'd'
,
'x'
]))
self
.
assertEqual
(
b1
.
def_set
,
set
([
'a'
,
'b'
,
'd'
,
'x'
]))
...
@@ -57,50 +57,46 @@ class TestLiveness(unittest.TestCase):
...
@@ -57,50 +57,46 @@ class TestLiveness(unittest.TestCase):
self
.
assertEqual
(
b3
.
use_set
,
set
([
'b'
,
'd'
]))
self
.
assertEqual
(
b3
.
use_set
,
set
([
'b'
,
'd'
]))
self
.
assertEqual
(
b3
.
def_set
,
set
([
'c'
,
'temp'
,
'return'
]))
self
.
assertEqual
(
b3
.
def_set
,
set
([
'c'
,
'temp'
,
'return'
]))
self
.
assertEqual
(
b1
.
live_in
,
set
())
self
.
assertEqual
(
b1
.
live_in
,
set
(
[
'$4'
,
'$5'
,
'$6'
,
'$7'
]
))
self
.
assertEqual
(
b1
.
live_out
,
set
([
'a'
,
'b'
,
'd'
]))
self
.
assertEqual
(
b1
.
live_out
,
set
([
'a'
,
'b'
,
'd'
,
'$4'
,
'$5'
,
'$6'
,
'$7'
]))
self
.
assertEqual
(
b2
.
live_in
,
set
([
'a'
,
'b'
]))
self
.
assertEqual
(
b2
.
live_in
,
set
([
'a'
,
'b'
,
'$4'
,
'$5'
,
'$6'
,
'$7'
]))
self
.
assertEqual
(
b2
.
live_out
,
set
([
'b'
,
'd'
]))
self
.
assertEqual
(
b2
.
live_out
,
set
([
'b'
,
'd'
,
'$4'
,
'$5'
,
'$6'
,
'$7'
]))
self
.
assertEqual
(
b3
.
live_in
,
set
([
'b'
,
'd'
]))
self
.
assertEqual
(
b3
.
live_in
,
set
([
'b'
,
'd'
,
'$4'
,
'$5'
,
'$6'
,
'$7'
]))
self
.
assertEqual
(
b3
.
live_out
,
set
())
self
.
assertEqual
(
b3
.
live_out
,
set
(
[
'$4'
,
'$5'
,
'$6'
,
'$7'
]
))
# def test_create_in_out_two(self):
# def test_create_in_out_two(self):
# s11 = S('command', 'subu', 'i', 'm', '0x00000001')
# s11 = S('command', 'subu', 'i', 'm', '0x00000001')
# s12 = S('command', 'move', 'j', 'n')
# s12 = S('command', 'move', 'j', 'n')
# s13 = S('command', 'move', 'a', 'u1')
# s13 = S('command', 'move', 'a', 'u1')
# s14 = S('command', 'subu', 'i', 'm', '0x0000000
1
')
# s14 = S('command', 'subu', 'i', 'm', '0x0000000
5
')
# s15 = S('command', 'j', 'L1')
# s15 = S('command', 'j', 'L1')
# s16 = S('')
#
#
# s21 = S('label', 'L1')
# s21 = S('label', 'L1')
# s22 = S('command', 'addi', 'i', '0x00000001')
# s22 = S('command', 'addi', 'i', '0x00000001')
# s23 = S('command', 'subi', 'j', '0x0000000
1
')
# s23 = S('command', 'subi', 'j', '0x0000000
2
')
# s24 = S('command', 'j', 'L2')
# s24 = S('command', '
bne', 'i', '
j', 'L2')
#
#
# s31 = S('label', 'L2')
# s31 = S('command', 'move', 'a', 'u2')
# s32 = S('command', 'move', 'a', 'u2')
# s32 = S('command', 'j', 'L1')
# s33 = S('command', 'j', 'L1')
# s41 = S('label', 'L
3
')
# s41 = S('label', 'L
2
')
# s42 = S('command', 'move', 'i', 'u3')
# s42 = S('command', 'move', 'i', 'u3')
# s43 = S('command', 'beq', '
g', 'd', 'L4
')
# s43 = S('command', 'beq', '
i', 'j', 'L3
')
#
#
# s51 = S('label', 'L
4
')
# s51 = S('label', 'L
3
')
# s52 = S('command', 'addu', 'b', 'i', 'a')
# s52 = S('command', 'addu', 'b', 'i', 'a')
#
#
# b1, b2, b3, b4 = find_basic_blocks([s11, s12, s13, s14, s15, s21, s22,\
# blocks = find_basic_blocks([s11, s12, s13, s14, s15,
# s31, s32, s33, s41, s42, s43, s51])
# s21, s22, s23, s24, s31, s32, s41, s42, s43, s51, s52])
# generate_flow_graph([b1, b2, b3, b4, b5])
# create_in_out([b1, b2, b3, b4, b5])
#
#
# generate_flow_graph(blocks)
# create_in_out(blocks)
#
#
# for i, block in enumerate(blocks):
#self.assertEqual(b1.)
# print 'block ', i,':\n\t in:', block.live_in
# print '\t out:', block.live_out
#
# #print blocks[-1].live_in
...
...
tests/test_reaching_definitions.py
View file @
770cbc9f
...
@@ -55,11 +55,11 @@ class TestReachingDefinitions(unittest.TestCase):
...
@@ -55,11 +55,11 @@ class TestReachingDefinitions(unittest.TestCase):
s34
=
S
(
'command'
,
'mflo'
,
'temp'
)
s34
=
S
(
'command'
,
'mflo'
,
'temp'
)
s35
=
S
(
'command'
,
'addu'
,
'return'
,
'temp'
,
'c'
)
s35
=
S
(
'command'
,
'addu'
,
'return'
,
'temp'
,
'c'
)
b1
,
b2
,
b3
=
find_basic_blocks
([
s11
,
s12
,
s13
,
s14
,
s15
,
s21
,
s22
,
\
b1
,
b2
,
b3
,
b4
=
find_basic_blocks
([
s11
,
s12
,
s13
,
s14
,
s15
,
s21
,
s22
,
\
s31
,
s32
,
s33
,
s34
,
s35
])
s31
,
s32
,
s33
,
s34
,
s35
])
generate_flow_graph
([
b1
,
b2
,
b3
])
generate_flow_graph
([
b1
,
b2
,
b3
,
b4
])
create_in_out
([
b1
,
b2
,
b3
])
create_in_out
([
b1
,
b2
,
b3
,
b4
])
self
.
assertEqual
(
b1
.
gen_set
,
set
([
s11
.
sid
,
s12
.
sid
,
s13
.
sid
,
self
.
assertEqual
(
b1
.
gen_set
,
set
([
s11
.
sid
,
s12
.
sid
,
s13
.
sid
,
s14
.
sid
]))
s14
.
sid
]))
...
...
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