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
e6324624
Commit
e6324624
authored
Dec 30, 2011
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added global optimization and dataflow anaysis to optimization loop.
parent
ae2cc948
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
11 deletions
+18
-11
src/optimize/__init__.py
src/optimize/__init__.py
+14
-10
src/program.py
src/program.py
+4
-1
No files found.
src/optimize/__init__.py
View file @
e6324624
...
...
@@ -11,23 +11,27 @@ def optimize(program, verbose=0):
# Remember original number of statements
o
=
program
.
count_instructions
()
# Optimize on a global level
program
.
optimize_global
()
g
=
program
.
count_instructions
()
changed
=
True
# Perform dataflow analysis
program
.
perform_dataflow_analysis
()
while
changed
:
changed
=
False
# Optimize basic blocks
program
.
optimize_blocks
()
# Optimize on a global level
if
program
.
optimize_global
():
changed
=
True
# Concatenate optimized blocks to obtain
# Perform dataflow analysis on new blocks
program
.
perform_dataflow_analysis
()
# Optimize basic blocks
if
program
.
optimize_blocks
():
changed
=
True
# Count number of instructions after optimization
b
=
program
.
count_instructions
()
# Print results
if
verbose
:
print
'Original statements: %d'
%
o
print
'After global optimization: %d (%d removed)'
%
(
g
,
o
-
g
)
print
'After basic block optimization: %d (%d removed)'
%
(
b
,
g
-
b
)
print
'Statements removed: %d (%d%%)'
\
%
(
o
-
b
,
int
((
o
-
b
)
/
float
(
b
)
*
100
))
src/program.py
View file @
e6324624
...
...
@@ -62,7 +62,10 @@ class Program(Block):
def
optimize_global
(
self
):
"""Optimize on a global level."""
remove_redundant_jumps
(
self
)
if
not
hasattr
(
self
,
'statements'
):
self
.
statements
=
self
.
get_statements
()
return
remove_redundant_jumps
(
self
)
def
optimize_blocks
(
self
):
"""Optimize on block level. Keep executing all optimizations until no
...
...
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