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
c53c99a7
Commit
c53c99a7
authored
Dec 30, 2011
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed unit tests without dummy block.
parent
968c47b8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
122 additions
and
122 deletions
+122
-122
tests/test_liveness.py
tests/test_liveness.py
+28
-28
tests/test_optimize_advanced.py
tests/test_optimize_advanced.py
+91
-91
tests/test_reaching_definitions.py
tests/test_reaching_definitions.py
+3
-3
No files found.
tests/test_liveness.py
View file @
c53c99a7
...
...
@@ -41,12 +41,12 @@ class TestLiveness(unittest.TestCase):
s33
=
S
(
'command'
,
'mult'
,
'b'
,
'd'
)
s34
=
S
(
'command'
,
'mflo'
,
'temp'
)
s35
=
S
(
'command'
,
'addu'
,
'return'
,
'temp'
,
'c'
)
b1
,
b2
,
b3
,
b4
=
find_basic_blocks
([
s11
,
s12
,
s13
,
s14
,
s15
,
s21
,
s22
,
\
b1
,
b2
,
b3
=
find_basic_blocks
([
s11
,
s12
,
s13
,
s14
,
s15
,
s21
,
s22
,
s31
,
s32
,
s33
,
s34
,
s35
])
generate_flow_graph
([
b1
,
b2
,
b3
,
b4
])
create_in_out
([
b1
,
b2
,
b3
,
b4
])
generate_flow_graph
([
b1
,
b2
,
b3
])
create_in_out
([
b1
,
b2
,
b3
])
self
.
assertEqual
(
b1
.
use_set
,
set
())
self
.
assertEqual
(
b1
.
def_set
,
set
([
'a'
,
'b'
,
'd'
,
'x'
]))
...
...
@@ -57,51 +57,51 @@ class TestLiveness(unittest.TestCase):
self
.
assertEqual
(
b3
.
use_set
,
set
([
'b'
,
'd'
]))
self
.
assertEqual
(
b3
.
def_set
,
set
([
'c'
,
'temp'
,
'return'
]))
self
.
assertEqual
(
b1
.
live_in
,
set
(
[
'$4'
,
'$5'
,
'$6'
,
'$7'
]
))
self
.
assertEqual
(
b1
.
live_out
,
set
([
'a'
,
'b'
,
'd'
,
'$4'
,
'$5'
,
'$6'
,
'$7'
]))
self
.
assertEqual
(
b2
.
live_in
,
set
([
'a'
,
'b'
,
'$4'
,
'$5'
,
'$6'
,
'$7'
]))
self
.
assertEqual
(
b2
.
live_out
,
set
([
'b'
,
'd'
,
'$4'
,
'$5'
,
'$6'
,
'$7'
]))
self
.
assertEqual
(
b3
.
live_in
,
set
([
'b'
,
'd'
,
'$4'
,
'$5'
,
'$6'
,
'$7'
]))
self
.
assertEqual
(
b3
.
live_out
,
set
(
[
'$4'
,
'$5'
,
'$6'
,
'$7'
]
))
# def test_create_in_out_two(self):
self
.
assertEqual
(
b1
.
live_in
,
set
())
self
.
assertEqual
(
b1
.
live_out
,
set
([
'a'
,
'b'
,
'd'
]))
self
.
assertEqual
(
b2
.
live_in
,
set
([
'a'
,
'b'
]))
self
.
assertEqual
(
b2
.
live_out
,
set
([
'b'
,
'd'
]))
self
.
assertEqual
(
b3
.
live_in
,
set
([
'b'
,
'd'
]))
self
.
assertEqual
(
b3
.
live_out
,
set
())
# def test_create_in_out_two(self):
# s11 = S('command', 'subu', 'i', 'm', '0x00000001')
# s12 = S('command', 'move', 'j', 'n')
# s13 = S('command', 'move', 'a', 'u1')
# s14 = S('command', 'subu', 'i', 'm', '0x00000005')
# s15 = S('command', 'j', 'L1')
#
#
# s21 = S('label', 'L1')
# s22 = S('command', 'addi', 'i', '0x00000001')
# s23 = S('command', 'subi', 'j', '0x00000002')
# s24 = S('command', 'bne', 'i', 'j', 'L2')
#
#
# s31 = S('command', 'move', 'a', 'u2')
# s32 = S('command', 'j', 'L1')
# s32 = S('command', 'j', 'L1')
# s41 = S('label', 'L2')
# s42 = S('command', 'move', 'i', 'u3')
# s43 = S('command', 'beq', 'i', 'j', 'L3')
#
#
# s51 = S('label', 'L3')
# s52 = S('command', 'addu', 'b', 'i', 'a')
#
# blocks = find_basic_blocks([s11, s12, s13, s14, s15,
#
# blocks = find_basic_blocks([s11, s12, s13, s14, s15,
# s21, s22, s23, s24, s31, s32, s41, s42, s43, s51, s52])
#
#
# generate_flow_graph(blocks)
# create_in_out(blocks)
#
#
# for i, block in enumerate(blocks):
# print 'block ', i,':\n\t in:', block.live_in
# print '\t out:', block.live_out
#
#
# #print blocks[-1].live_in
tests/test_optimize_advanced.py
View file @
c53c99a7
...
...
@@ -2,7 +2,7 @@ import unittest
from
copy
import
copy
from
src.optimize.advanced
import
eliminate_common_subexpressions
,
\
fold_constants
,
copy_propagation
,
algebraic_transformations
fold_constants
,
copy_propagation
from
src.statement
import
Statement
as
S
from
src.dataflow
import
BasicBlock
as
B
,
generate_flow_graph
import
src.liveness
as
liveness
...
...
@@ -104,93 +104,93 @@ class TestOptimizeAdvanced(unittest.TestCase):
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
(
algebraic_transformations
(
block
))
self
.
assertEqual
(
block
.
statements
,
[
self
.
foo
,
S
(
'command'
,
'move'
,
'$1'
,
'$2'
),
self
.
bar
])
def
test_algebraic_transforms_add1
(
self
):
arguments
=
[
self
.
foo
,
S
(
'command'
,
'addu'
,
'$1'
,
'$2'
,
1
),
self
.
bar
]
block
=
B
(
arguments
)
self
.
assertFalse
(
algebraic_transformations
(
block
))
self
.
assertEqual
(
block
.
statements
,
arguments
)
def
test_algebraic_transforms_sub0
(
self
):
block
=
B
([
self
.
foo
,
S
(
'command'
,
'subu'
,
'$1'
,
'$2'
,
0
),
self
.
bar
])
self
.
assertTrue
(
algebraic_transformations
(
block
))
self
.
assertEqual
(
block
.
statements
,
[
self
.
foo
,
S
(
'command'
,
'move'
,
'$1'
,
'$2'
),
self
.
bar
])
def
test_algebraic_transforms_sub1
(
self
):
arguments
=
[
self
.
foo
,
S
(
'command'
,
'subu'
,
'$1'
,
'$2'
,
1
),
self
.
bar
]
block
=
B
(
arguments
)
self
.
assertFalse
(
algebraic_transformations
(
block
))
self
.
assertEqual
(
block
.
statements
,
arguments
)
def
test_algebraic_transforms_mult0
(
self
):
block
=
B
([
self
.
foo
,
S
(
'command'
,
'mult'
,
'$2'
,
0
),
S
(
'command'
,
'mflo'
,
'$1'
),
self
.
bar
])
self
.
assertTrue
(
algebraic_transformations
(
block
))
self
.
assertEqual
(
block
.
statements
,
[
self
.
foo
,
S
(
'command'
,
'li'
,
'$1'
,
'0x00000000'
),
self
.
bar
])
def
test_algebraic_transforms_mult1
(
self
):
block
=
B
([
self
.
foo
,
S
(
'command'
,
'mult'
,
'$2'
,
1
),
S
(
'command'
,
'mflo'
,
'$1'
),
self
.
bar
])
self
.
assertTrue
(
algebraic_transformations
(
block
))
self
.
assertEqual
(
block
.
statements
,
[
self
.
foo
,
S
(
'command'
,
'move'
,
'$1'
,
'$2'
),
self
.
bar
])
def
test_algebraic_transforms_mult2
(
self
):
block
=
B
([
self
.
foo
,
S
(
'command'
,
'mult'
,
'$2'
,
2
),
S
(
'command'
,
'mflo'
,
'$1'
),
self
.
bar
])
self
.
assertTrue
(
algebraic_transformations
(
block
))
self
.
assertEqual
(
block
.
statements
,
[
self
.
foo
,
S
(
'command'
,
'sll'
,
'$1'
,
'$2'
,
1
),
self
.
bar
])
def
test_algebraic_transforms_mult16
(
self
):
block
=
B
([
self
.
foo
,
S
(
'command'
,
'mult'
,
'$2'
,
16
),
S
(
'command'
,
'mflo'
,
'$1'
),
self
.
bar
])
self
.
assertTrue
(
algebraic_transformations
(
block
))
self
.
assertEqual
(
block
.
statements
,
[
self
.
foo
,
S
(
'command'
,
'sll'
,
'$1'
,
'$2'
,
4
),
self
.
bar
])
def
test_algebraic_transforms_mult3
(
self
):
arguments
=
[
self
.
foo
,
S
(
'command'
,
'mult'
,
'$2'
,
3
),
S
(
'command'
,
'mflo'
,
'$1'
),
self
.
bar
]
block
=
B
(
arguments
)
self
.
assertFalse
(
algebraic_transformations
(
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(algebraic_transformations(block))
#
self.assertEqual(block.statements, [self.foo,
#
S('command', 'move', '$1', '$2'),
#
self.bar])
#
def test_algebraic_transforms_add1(self):
#
arguments = [self.foo,
#
S('command', 'addu', '$1', '$2', 1),
#
self.bar]
#
block = B(arguments)
#
self.assertFalse(algebraic_transformations(block))
#
self.assertEqual(block.statements, arguments)
#
def test_algebraic_transforms_sub0(self):
#
block = B([self.foo,
#
S('command', 'subu', '$1', '$2', 0),
#
self.bar])
#
self.assertTrue(algebraic_transformations(block))
#
self.assertEqual(block.statements, [self.foo,
#
S('command', 'move', '$1', '$2'),
#
self.bar])
#
def test_algebraic_transforms_sub1(self):
#
arguments = [self.foo,
#
S('command', 'subu', '$1', '$2', 1),
#
self.bar]
#
block = B(arguments)
#
self.assertFalse(algebraic_transformations(block))
#
self.assertEqual(block.statements, arguments)
#
def test_algebraic_transforms_mult0(self):
#
block = B([self.foo,
#
S('command', 'mult', '$2', 0),
#
S('command', 'mflo', '$1'),
#
self.bar])
#
self.assertTrue(algebraic_transformations(block))
#
self.assertEqual(block.statements, [self.foo,
#
S('command', 'li', '$1', '0x00000000'),
#
self.bar])
#
def test_algebraic_transforms_mult1(self):
#
block = B([self.foo,
#
S('command', 'mult', '$2', 1),
#
S('command', 'mflo', '$1'),
#
self.bar])
#
self.assertTrue(algebraic_transformations(block))
#
self.assertEqual(block.statements, [self.foo,
#
S('command', 'move', '$1', '$2'),
#
self.bar])
#
def test_algebraic_transforms_mult2(self):
#
block = B([self.foo,
#
S('command', 'mult', '$2', 2),
#
S('command', 'mflo', '$1'),
#
self.bar])
#
self.assertTrue(algebraic_transformations(block))
#
self.assertEqual(block.statements, [self.foo,
#
S('command', 'sll', '$1', '$2', 1),
#
self.bar])
#
def test_algebraic_transforms_mult16(self):
#
block = B([self.foo,
#
S('command', 'mult', '$2', 16),
#
S('command', 'mflo', '$1'),
#
self.bar])
#
self.assertTrue(algebraic_transformations(block))
#
self.assertEqual(block.statements, [self.foo,
#
S('command', 'sll', '$1', '$2', 4),
#
self.bar])
#
def test_algebraic_transforms_mult3(self):
#
arguments = [self.foo,
#
S('command', 'mult', '$2', 3),
#
S('command', 'mflo', '$1'),
#
self.bar]
#
block = B(arguments)
#
self.assertFalse(algebraic_transformations(block))
#
self.assertEqual(block.statements, arguments)
tests/test_reaching_definitions.py
View file @
c53c99a7
...
...
@@ -55,11 +55,11 @@ class TestReachingDefinitions(unittest.TestCase):
s34
=
S
(
'command'
,
'mflo'
,
'temp'
)
s35
=
S
(
'command'
,
'addu'
,
'return'
,
'temp'
,
'c'
)
b1
,
b2
,
b3
,
b4
=
find_basic_blocks
([
s11
,
s12
,
s13
,
s14
,
s15
,
s21
,
s22
,
\
b1
,
b2
,
b3
=
find_basic_blocks
([
s11
,
s12
,
s13
,
s14
,
s15
,
s21
,
s22
,
\
s31
,
s32
,
s33
,
s34
,
s35
])
generate_flow_graph
([
b1
,
b2
,
b3
,
b4
])
create_in_out
([
b1
,
b2
,
b3
,
b4
])
generate_flow_graph
([
b1
,
b2
,
b3
])
create_in_out
([
b1
,
b2
,
b3
])
self
.
assertEqual
(
b1
.
gen_set
,
set
([
s11
.
sid
,
s12
.
sid
,
s13
.
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