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
158030a2
Commit
158030a2
authored
Dec 30, 2011
by
Jayke Meijer
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:taddeus/peephole
parents
91236cf5
4099c995
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
10 deletions
+51
-10
src/liveness.py
src/liveness.py
+23
-0
src/optimize/advanced.py
src/optimize/advanced.py
+28
-10
No files found.
src/liveness.py
View file @
158030a2
from
copy
import
copy
from
copy
import
copy
RESERVED_REGISTERS
=
[
'$fp'
,
'$sp'
]
def
is_reg_dead_after
(
reg
,
block
,
index
):
"""Check if a register is dead after a certain point in a basic block."""
if
reg
in
RESERVED_REGISTERS
:
return
False
if
index
<
len
(
block
)
-
1
:
for
s
in
block
[
index
+
1
:]:
# If used, the previous definition is live
if
s
.
uses
(
reg
):
return
False
# If redefined, the previous definition is dead
if
s
.
defines
(
reg
):
return
True
# If dead within the same block, check if the register is in the block's
# live_out set
return
reg
not
in
block
.
live_out
def
create_use_def
(
block
):
def
create_use_def
(
block
):
used
=
set
()
used
=
set
()
defined
=
set
()
defined
=
set
()
...
...
src/optimize/advanced.py
View file @
158030a2
from
src.statement
import
Statement
as
S
from
math
import
log
from
math
import
log
from
src.statement
import
Statement
as
S
from
src.liveness
import
is_reg_dead_after
def
reg_can_be_used_in
(
reg
,
block
,
start
,
end
):
def
reg_can_be_used_in
(
reg
,
block
,
start
,
end
):
"""Check if a register addres safely be used in a block section using local
"""Check if a register addres safely be used in a block section using local
...
@@ -393,25 +395,41 @@ def eliminate_dead_code(block):
...
@@ -393,25 +395,41 @@ def eliminate_dead_code(block):
is not used in the rest of the block, and is not in the `out' set of the
is not used in the rest of the block, and is not in the `out' set of the
block.
block.
"""
"""
# TODO: Finish
changed
=
False
changed
=
False
unused
=
set
()
for
s
in
reversed
(
block
):
for
n
,
s
in
enumerate
(
block
):
for
reg
in
s
.
get_def
():
for
reg
in
s
.
get_def
():
if
reg
in
unused
:
if
is_reg_dead_after
(
reg
,
block
,
n
)
:
# Statement is redefined later, so this statement is useless
# Statement is redefined later, so this statement is useless
if
block
.
debug
:
if
block
.
debug
:
s
.
stype
=
'comment'
s
.
stype
=
'comment'
s
.
options
[
'block'
]
=
False
s
.
options
[
'block'
]
=
False
s
.
name
=
' Dead
code: %s
%s'
\
s
.
name
=
' Dead
:
\
t
%s
\
t
%s'
\
%
(
s
.
name
,
',
'
.
join
(
map
(
str
,
s
)))
%
(
s
.
name
,
','
.
join
(
map
(
str
,
s
)))
else
:
else
:
s
.
remove
=
True
s
.
remove
=
True
else
:
unused
.
add
(
reg
)
unused
-=
set
(
s
.
get_use
())
changed
=
True
#unused = set()
#for s in reversed(block):
# for reg in s.get_def():
# if reg in unused:
# # Statement is redefined later, so this statement is useless
# if block.debug:
# s.stype = 'comment'
# s.options['block'] = False
# s.name = ' Dead:\t%s\t%s' \
# % (s.name, ','.join(map(str, s)))
# else:
# s.remove = True
# changed = True
# else:
# unused.add(reg)
# unused -= set(s.get_use())
if
not
block
.
debug
:
if
not
block
.
debug
:
block
.
apply_filter
(
lambda
s
:
not
hasattr
(
s
,
'remove'
))
block
.
apply_filter
(
lambda
s
:
not
hasattr
(
s
,
'remove'
))
...
...
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