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
b7e2f719
Commit
b7e2f719
authored
Dec 29, 2011
by
Jayke Meijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added base for unittest reaching definitions.
parent
d6c51e39
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
80 deletions
+41
-80
src/dataflow.py
src/dataflow.py
+3
-5
tests/test_dataflow.py
tests/test_dataflow.py
+38
-75
No files found.
src/dataflow.py
View file @
b7e2f719
from
copy
import
copy
from
statement
import
Block
...
...
@@ -86,10 +84,10 @@ def reaching_definitions(blocks):
for
pred
in
b
.
edges_from
:
b
.
in_set
|=
pred
.
out_set
oldout
=
copy
(
p
.
out_set
)
p
.
out_set
=
b
.
gen_set
|
(
b
.
in_set
-
b
.
kill_set
)
new_out
=
b
.
gen_set
|
(
b
.
in_set
-
b
.
kill_set
)
if
b
.
out_set
!=
oldout
:
if
new_out
!=
b
.
out_set
:
b
.
out_set
=
new_out
change
=
True
...
...
tests/test_dataflow.py
View file @
b7e2f719
...
...
@@ -24,41 +24,44 @@ class TestDataflow(unittest.TestCase):
[
B
(
s
[:
2
]).
statements
,
B
(
s
[
2
:
4
]).
statements
,
\
B
(
s
[
4
:]).
statements
])
# def test_get_gen(self):
# b1 = B([S('command', 'add', '$1', '$2', '$3'), \
# S('command', 'add', '$2', '$3', '$4'), \
# S('command', 'add', '$1', '$4', '$5')])
#
# self.assertEqual(b1.get_gen(), ['$1', '$2'])
# def test_get_out(self):
# b1 = B([S('command', 'add', '$1', '$2', '$3'), \
# S('command', 'add', '$2', '$3', '$4'), \
# S('command', 'add', '$1', '$4', '$5'), \
# S('command', 'j', 'b2')])
#
# b2 = B([S('command', 'add', '$3', '$5', '$6'), \
# S('command', 'add', '$1', '$2', '$3'), \
# S('command', 'add', '$6', '$4', '$5')])
#
# blocks = [b1, b2]
#
# # initialize out[B] = gen[B] for every block
# for block in blocks:
# block.out_set = block.get_gen()
# print 'block.out_set', block.out_set
#
# generate_flow_graph(blocks)
# change = True
# while change:
# for i, block in enumerate(blocks):
# block.get_in()
# oldout = block.out_set
# newout = block.get_out()
# if (block.out_set == block.get_out()):
# change = False
def
test_defs
(
self
):
s1
=
S
(
'command'
,
'add'
,
'$3'
,
'$1'
,
'$2'
)
s2
=
S
(
'command'
,
'move'
,
'$1'
,
'$3'
)
s3
=
S
(
'command'
,
'move'
,
'$3'
,
'$2'
)
s4
=
S
(
'command'
,
'li'
,
'$4'
,
'0x00000001'
)
block
=
B
([
s1
,
s2
,
s3
,
s4
])
self
.
assertEqual
(
defs
([
block
]),
{
'$3'
:
set
([
s1
.
sid
,
s3
.
sid
]),
'$1'
:
set
([
s2
.
sid
]),
'$4'
:
set
([
s4
.
sid
])
})
def
test_create_gen_kill
(
self
):
s1
=
S
(
'command'
,
'addu'
,
'$3'
,
'$1'
,
'$2'
)
s2
=
S
(
'command'
,
'addu'
,
'$1'
,
'$3'
,
10
)
s3
=
S
(
'command'
,
'subu'
,
'$3'
,
'$1'
,
5
)
s4
=
S
(
'command'
,
'li'
,
'$4'
,
'0x00000001'
)
block
=
B
([
s1
,
s2
,
s3
,
s4
])
block
.
create_gen_kill
(
defs
([
block
]))
self
.
assertEqual
(
block
.
gen_set
,
set
([
s2
.
sid
,
s3
.
sid
,
s4
.
sid
]))
self
.
assertEqual
(
block
.
kill_set
,
set
([
s1
.
sid
]))
def
test_reaching_definitions
(
self
):
s11
=
S
(
'command'
,
'li'
,
'a'
,
3
)
s12
=
S
(
'command'
,
'li'
,
'b'
,
5
)
s13
=
S
(
'command'
,
'li'
,
'd'
,
4
)
s14
=
S
(
'command'
,
'li'
,
'x'
,
100
)
s15
=
S
(
'command'
,
'blt'
,
'a'
,
'b'
,
'L1'
)
block1
=
B
([
s11
,
s12
,
s13
,
s14
,
s15
])
s21
=
S
(
'command'
,
'addu'
,
'c'
,
'a'
,
'b'
)
s22
=
S
(
'command'
,
'li'
,
'd'
,
2
)
block2
=
B
([
s21
,
s22
])
s31
=
S
(
'label'
,
'L1'
)
s32
=
S
(
'command'
,
'li'
,
'c'
,
4
)
s33
=
S
(
'command'
,
'mult'
,
'b'
,
'd'
)
s34
=
S
(
'command'
,
'mflo'
,
'temp'
)
s35
=
S
(
'command'
,
'addu'
,
'return'
,
'temp'
,
'c'
)
block3
=
B
([
s31
,
s32
,
s33
,
s34
,
s35
])
def
test_generate_flow_graph_simple
(
self
):
b1
=
B
([
S
(
'command'
,
'foo'
),
S
(
'command'
,
'j'
,
'b2'
)])
...
...
@@ -112,46 +115,6 @@ class TestDataflow(unittest.TestCase):
#
# self.assertEqualDag(dag, expect)
def
test_defs
(
self
):
s1
=
S
(
'command'
,
'addu'
,
'$3'
,
'$1'
,
'$2'
)
s2
=
S
(
'command'
,
'addu'
,
'$1'
,
'$3'
,
10
)
s3
=
S
(
'command'
,
'subu'
,
'$3'
,
'$1'
,
5
)
s4
=
S
(
'command'
,
'li'
,
'$4'
,
'0x00000001'
)
block
=
B
([
s1
,
s2
,
s3
,
s4
])
self
.
assertEqual
(
defs
([
block
]),
{
'$3'
:
set
([
s1
.
sid
,
s3
.
sid
]),
'$1'
:
set
([
s2
.
sid
]),
'$4'
:
set
([
s4
.
sid
])
})
def
test_defs
(
self
):
s1
=
S
(
'command'
,
'add'
,
'$3'
,
'$1'
,
'$2'
)
s2
=
S
(
'command'
,
'move'
,
'$1'
,
'$3'
)
s3
=
S
(
'command'
,
'move'
,
'$3'
,
'$2'
)
s4
=
S
(
'command'
,
'li'
,
'$4'
,
'0x00000001'
)
block
=
B
([
s1
,
s2
,
s3
,
s4
])
self
.
assertEqual
(
defs
([
block
]),
{
'$3'
:
set
([
s1
.
sid
,
s3
.
sid
]),
'$1'
:
set
([
s2
.
sid
]),
'$4'
:
set
([
s4
.
sid
])
})
def
test_create_gen_kill_gen
(
self
):
s1
=
S
(
'command'
,
'addu'
,
'$3'
,
'$1'
,
'$2'
)
s2
=
S
(
'command'
,
'addu'
,
'$1'
,
'$3'
,
10
)
s3
=
S
(
'command'
,
'subu'
,
'$3'
,
'$1'
,
5
)
s4
=
S
(
'command'
,
'li'
,
'$4'
,
'0x00000001'
)
block
=
B
([
s1
,
s2
,
s3
,
s4
])
block
.
create_gen_kill
(
defs
([
block
]))
self
.
assertEqual
(
block
.
gen_set
,
set
([
s2
.
sid
,
s3
.
sid
,
s4
.
sid
]))
#def test_get_kill_used(self):
# block = B([S('command', 'move', '$1', '$3'),
# S('command', 'add', '$3', '$1', '$2'),
# S('command', 'move', '$1', '$3'),
# S('command', 'move', '$2', '$3')])
# self.assertEqual(block.get_kill(), set())
def
assertEqualDag
(
self
,
dag1
,
dag2
):
self
.
assertEqual
(
len
(
dag1
.
nodes
),
len
(
dag2
.
nodes
))
...
...
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