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
2bc283ea
Commit
2bc283ea
authored
Dec 29, 2011
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added reaching definitions to optimizer, and cleaned up some code.
parent
bca9684d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
9 deletions
+11
-9
src/optimize/__init__.py
src/optimize/__init__.py
+9
-2
src/optimize/advanced.py
src/optimize/advanced.py
+2
-7
No files found.
src/optimize/__init__.py
View file @
2bc283ea
from
src.dataflow
import
find_basic_blocks
from
src.dataflow
import
find_basic_blocks
,
reaching_definitions
from
redundancies
import
remove_redundant_jumps
,
move_1
,
move_2
,
move_3
,
\
move_4
,
load
,
shift
,
add
...
...
@@ -45,9 +45,16 @@ def optimize(statements, verbose=0):
remove_redundant_jumps
(
statements
)
g
=
len
(
statements
)
#
Optimize
basic blocks
#
Divide into
basic blocks
blocks
=
find_basic_blocks
(
statements
)
# Find reaching definitions
reaching_definitions
(
blocks
)
# Optimize basic blocks
map
(
optimize_block
,
blocks
)
# Concatenate optimized blocks to obtain
block_statements
=
map
(
lambda
b
:
b
.
statements
,
blocks
)
opt_blocks
=
reduce
(
lambda
a
,
b
:
a
+
b
,
block_statements
)
b
=
len
(
opt_blocks
)
...
...
src/optimize/advanced.py
View file @
2bc283ea
...
...
@@ -18,7 +18,7 @@ def reg_can_be_used_in(reg, block, start, end):
elif
s
.
defines
(
reg
):
return
True
return
True
return
reg
not
in
block
.
out_set
def
find_free_reg
(
block
,
start
,
end
):
...
...
@@ -348,13 +348,9 @@ def eliminate_dead_code(block):
"""
# TODO: Finish
changed
=
False
block
.
reverse_statements
()
unused
=
set
()
while
not
block
.
end
():
s
=
block
.
read
()
for
s
in
reversed
(
block
):
for
reg
in
s
.
get_def
():
if
reg
in
unused
:
# Statement is redefined later, so this statement is useless
...
...
@@ -367,6 +363,5 @@ def eliminate_dead_code(block):
unused
-=
set
(
s
.
get_use
())
block
.
apply_filter
(
lambda
s
:
not
hasattr
(
s
,
'remove'
))
block
.
reverse_statements
()
return
changed
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