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
eea69c60
Commit
eea69c60
authored
13 years ago
by
Richard Torenvliet
Browse files
Options
Downloads
Patches
Plain Diff
Made progress with liveness analyses in dataflow.py
parent
13966882
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/dataflow.py
+31
-6
31 additions, 6 deletions
src/dataflow.py
src/optimize.py
+3
-0
3 additions, 0 deletions
src/optimize.py
tests/test_dataflow.py
+29
-0
29 additions, 0 deletions
tests/test_dataflow.py
with
63 additions
and
6 deletions
src/dataflow.py
+
31
−
6
View file @
eea69c60
...
...
@@ -11,6 +11,10 @@ class BasicBlock(Block):
self
.
dominates
=
[]
self
.
dominated_by
=
[]
self
.
in_set
=
set
([])
self
.
out_set
=
set
([])
self
.
gen_set
=
set
([])
self
.
kill_set
=
set
([])
def
add_edge_to
(
self
,
block
):
if
block
not
in
self
.
edges_to
:
...
...
@@ -23,17 +27,38 @@ class BasicBlock(Block):
block
.
dominated_by
.
append
(
self
)
def
get_gen
(
self
):
pass
for
s
in
self
.
statements
:
if
s
.
is_arith
():
self
.
gen_set
.
add
(
s
[
0
])
print
'
added:
'
,
s
[
0
]
return
self
.
gen_set
def
get_kill
(
self
):
pass
# if self.edges_from != []:
for
backw
in
self
.
edges_from
:
self
.
kill_set
=
self
.
kill_set
|
backw
.
get_kill
()
self
.
kill_set
=
self
.
kill_set
-
self
.
get_gen
()
print
'
get_kill_set
'
,
self
.
kill_set
return
self
.
kill_set
def
get_in
(
self
):
pass
for
backw
in
self
.
edges_from
:
self
.
in_set
=
self
.
in_set
|
backw
.
get_out
()
print
'
in_set
'
,
self
.
in_set
return
self
.
in_set
def
get_out
(
self
):
pass
print
'
gen_set
'
,
self
.
gen_set
print
'
get_in
'
,
self
.
get_in
()
print
'
get_kill
'
,
self
.
get_kill
()
self
.
out_set
=
self
.
gen_set
|
(
self
.
get_in
()
-
self
.
get_kill
())
def
reaching_definition
(
blocks
):
generate_flow_graph
(
blocks
)
def
find_leaders
(
statements
):
"""
Determine the leaders, which are:
...
...
This diff is collapsed.
Click to expand it.
src/optimize.py
+
3
−
0
View file @
eea69c60
...
...
@@ -101,6 +101,9 @@ def optimize_blocks(blocks):
blocks
=
optimized
return
reduce
(
lambda
a
,
b
:
a
+
b
,
blocks
,
[])
...
...
This diff is collapsed.
Click to expand it.
tests/test_dataflow.py
+
29
−
0
View file @
eea69c60
...
...
@@ -23,6 +23,35 @@ class TestDataflow(unittest.TestCase):
self
.
assertEqual
(
map
(
lambda
b
:
b
.
statements
,
find_basic_blocks
(
s
)),
\
[
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]
#
# for block in blocks:
# block.out_set = block.get_gen()
# print 'block.out_set', block.out_set
# generate_flow_graph(blocks)
# print b1.get_gen()
# print b2.get_gen()
# print b2.get_out()
def
test_generate_flow_graph_simple
(
self
):
b1
=
B
([
S
(
'
command
'
,
'
foo
'
),
S
(
'
command
'
,
'
j
'
,
'
b2
'
)])
...
...
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