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
69a922ff
Commit
69a922ff
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Debug messages are not concatenated instead of overwritten.
parent
8d6930d4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/copy_propagation.py
+93
-0
93 additions, 0 deletions
src/copy_propagation.py
src/optimize/advanced.py
+2
-2
2 additions, 2 deletions
src/optimize/advanced.py
src/statement.py
+4
-4
4 additions, 4 deletions
src/statement.py
src/writer.py
+1
-1
1 addition, 1 deletion
src/writer.py
with
100 additions
and
7 deletions
src/copy_propagation.py
0 → 100644
+
93
−
0
View file @
69a922ff
from
dataflow
import
pred
from
liveness
import
RESERVED_REGISTERS
def
create_gen_kill
(
block
):
block
.
c_gen
=
set
()
block
.
c_kill
=
set
()
for
s
in
block
:
if
s
.
is_command
(
'
move
'
):
# An occurrence of a copy statement generates this statement
x
,
y
=
s
if
x
not
in
RESERVED_REGISTERS
and
y
not
in
RESERVED_REGISTERS
:
block
.
c_gen
.
add
((
x
,
y
))
else
:
# An assignment to x or y kills the copy statement x = y
block
.
c_kill
|=
set
(
s
.
get_def
())
#for reg in s.get_def():
# block.c_kill.add(reg)
# print 'kill of %s' % reg
def
create_in_out
(
blocks
):
"""
Generate the `in
'
and `out
'
sets of the given blocks using the iterative
algorithm from the lecture slides.
"""
# Create gen/kill sets
for
b
in
blocks
:
create_gen_kill
(
b
)
b
.
copy_in
=
set
()
b
.
copy_out
=
set
()
# in[B1] = {} where B1 is the initial block
blocks
[
0
].
copy_in
=
set
()
#def create_sets(b, first=False):
for
i
,
b
in
enumerate
(
blocks
):
# in[B1] = {} where B1 is the initial block
# in[B] = intersection of out[P] for P in pred(B) for B not initial
if
i
:
b
.
copy_in
=
set
()
for
p
in
pred
(
b
):
b
.
copy_in
&=
p
.
copy_out
# out[B] = c_gen[B] | (in[B] - c_kill[B])
in_minus_kill
=
set
()
for
x
,
y
in
b
.
copy_in
:
if
x
not
in
b
.
c_kill
and
y
not
in
b
.
c_kill
:
print
'
%s, %s not in c_kill
'
%
(
x
,
y
)
in_minus_kill
.
add
((
x
,
y
))
b
.
copy_out
=
b
.
c_gen
|
in_minus_kill
#for successor in b.edges_to:
# create_sets(successor)
#create_sets(blocks[0], True)
def
propagate_copies
(
block
):
changed
=
False
# For each copy statement s: x = y do
for
s
in
block
:
if
s
.
is_command
(
'
move
'
):
x
,
y
=
s
# Determine the uses of x reached by this definition of x
uses
=
filter
(
lambda
suc
:
s
.
sid
in
suc
.
reach_in
,
block
.
edges_to
)
# Determine if for each of those uses this is the only
# definition reaching it -> s in in[B_use]
only_def
=
True
for
b_use
in
uses
:
if
(
x
,
y
)
not
in
b_use
.
copy_in
:
only_def
=
False
# If so, remove s and replace the uses of x by uses of y
if
only_def
:
for
use
in
uses
:
print
'
use:
'
,
use
for
statement
in
use
:
if
statement
.
uses
(
x
):
statement
.
replace_usage
(
x
,
y
)
message
=
'
Replaced %s with %s
'
%
(
x
,
y
)
print
message
statement
.
set_inline_comment
(
message
)
changed
=
True
return
changed
This diff is collapsed.
Click to expand it.
src/optimize/advanced.py
+
2
−
2
View file @
69a922ff
...
...
@@ -446,8 +446,8 @@ def copy_propagation(block):
# Moves to reserved registers will never be removed, so don't
# bother replacing them
#
if x in RESERVED_REGISTERS:
#
continue
if
x
in
RESERVED_REGISTERS
:
continue
# Determine the uses of x reached by this definition of x
for
s2
in
block
[
block
.
pointer
:]:
...
...
This diff is collapsed.
Click to expand it.
src/statement.py
+
4
−
4
View file @
69a922ff
...
...
@@ -40,10 +40,10 @@ class Statement:
%
(
self
.
stype
,
self
.
name
,
self
.
args
)
def
set_message
(
self
,
message
):
if
len
(
self
.
options
.
get
(
'
message
'
,
''
))
:
self
.
options
[
'
message
'
]
+
=
'
|
'
+
message
el
se
:
self
.
options
[
'
message
'
]
=
message
if
'
message
'
not
in
self
.
options
:
self
.
options
[
'
message
'
]
=
[
message
]
el
if
message
not
in
self
.
options
[
'
message
'
]
:
self
.
options
[
'
message
'
]
.
append
(
message
)
def
set_inline_comment
(
self
,
comment
):
self
.
options
[
'
comment
'
]
=
comment
...
...
This diff is collapsed.
Click to expand it.
src/writer.py
+
1
−
1
View file @
69a922ff
...
...
@@ -54,7 +54,7 @@ def write_statements(statements, verbose=0):
if
s
.
has_inline_comment
():
comment
=
s
.
options
[
'
comment
'
]
elif
verbose
:
comment
=
s
.
options
.
get
(
'
message
'
,
''
)
comment
=
'
|
'
.
join
(
s
.
options
.
get
(
'
message
'
,
[])
)
if
len
(
comment
):
start
=
INLINE_COMMENT_LEVEL
*
TABSIZE
...
...
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