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
158030a2
Commit
158030a2
authored
13 years ago
by
Jayke Meijer
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of github.com:taddeus/peephole
parents
91236cf5
4099c995
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/liveness.py
+23
-0
23 additions, 0 deletions
src/liveness.py
src/optimize/advanced.py
+28
-10
28 additions, 10 deletions
src/optimize/advanced.py
with
51 additions
and
10 deletions
src/liveness.py
+
23
−
0
View file @
158030a2
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
):
used
=
set
()
defined
=
set
()
...
...
This diff is collapsed.
Click to expand it.
src/optimize/advanced.py
+
28
−
10
View file @
158030a2
from
src.statement
import
Statement
as
S
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
):
"""
Check if a register addres safely be used in a block section using local
...
...
@@ -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
block.
"""
# TODO: Finish
changed
=
False
unused
=
set
()
for
s
in
reversed
(
block
):
for
n
,
s
in
enumerate
(
block
):
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
if
block
.
debug
:
s
.
stype
=
'
comment
'
s
.
options
[
'
block
'
]
=
False
s
.
name
=
'
Dead
code: %s
%s
'
\
%
(
s
.
name
,
'
,
'
.
join
(
map
(
str
,
s
)))
s
.
name
=
'
Dead
:
\t
%s
\t
%s
'
\
%
(
s
.
name
,
'
,
'
.
join
(
map
(
str
,
s
)))
else
:
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
:
block
.
apply_filter
(
lambda
s
:
not
hasattr
(
s
,
'
remove
'
))
...
...
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