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
0de7d78b
Commit
0de7d78b
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Updated result print format.
parent
ca2d8e22
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/optimize/__init__.py
+22
-12
22 additions, 12 deletions
src/optimize/__init__.py
with
22 additions
and
12 deletions
src/optimize/__init__.py
+
22
−
12
View file @
0de7d78b
...
...
@@ -17,6 +17,8 @@ def remove_redundancies(block):
while
old_len
!=
len
(
block
):
old_len
=
len
(
block
)
block
.
reset
()
while
not
block
.
end
():
s
=
block
.
read
()
...
...
@@ -30,20 +32,34 @@ def remove_redundancies(block):
def
optimize_block
(
block
):
"""
Optimize a basic block.
"""
#changed = True
#while changed:
# changed = False
# if remove_redundancies(block): changed = True
# if eliminate_common_subexpressions(block): changed = True
# if fold_constants(block): changed = True
# if copy_propagation(block): changed = True
# if eliminate_dead_code(block): changed = True
# print 'iteration'
while
remove_redundancies
(
block
)
\
|
eliminate_common_subexpressions
(
block
)
\
|
fold_constants
(
block
)
\
|
copy_propagation
(
block
)
\
|
eliminate_dead_code
(
block
):
#| algebraic_transformations(block) \
#print 'iteration'
pass
from
copy
import
deepcopy
def
optimize
(
statements
,
verbose
=
0
):
"""
Optimization wrapper function, calls global and basic-block level
optimization functions.
"""
# Optimize on a global level
# TODO: only count instructions (no directives)
statements
=
deepcopy
(
statements
)
o
=
len
(
statements
)
remove_redundant_jumps
(
statements
)
g
=
len
(
statements
)
...
...
@@ -64,18 +80,12 @@ def optimize(statements, verbose=0):
opt_blocks
=
reduce
(
lambda
a
,
b
:
a
+
b
,
block_statements
)
b
=
len
(
opt_blocks
)
# - Common subexpression elimination
# - Constant folding
# - Copy propagation
# - Dead-code elimination
# - Temporary variable renaming
# - Interchange of independent statements
# Print results
if
verbose
:
print
'
Original statements:
%d
'
%
o
print
'
After global optimization:
%d
'
%
g
print
'
After basic block
s
optimization: %d
'
%
b
print
'
Optimization:
%d (%d%%)
'
\
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
))
return
opt_blocks
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