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
030e9754
Commit
030e9754
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Extended docstrings.
parent
870d25ee
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/optimize/advanced.py
+15
-6
15 additions, 6 deletions
src/optimize/advanced.py
with
15 additions
and
6 deletions
src/optimize/advanced.py
+
15
−
6
View file @
030e9754
...
@@ -8,6 +8,11 @@ def create_variable():
...
@@ -8,6 +8,11 @@ def create_variable():
def
eliminate_common_subexpressions
(
block
):
def
eliminate_common_subexpressions
(
block
):
"""
"""
Common subexpression elimination:
Common subexpression elimination:
x = a + b -> u = a + b
y = a + b x = u
y = u
The algorithm used is as follows:
- Traverse through the statements in reverse order.
- Traverse through the statements in reverse order.
- If the statement can be possibly be eliminated, walk further collecting
- If the statement can be possibly be eliminated, walk further collecting
all other occurrences of the expression until one of the arguments is
all other occurrences of the expression until one of the arguments is
...
@@ -65,7 +70,11 @@ def to_hex(value):
...
@@ -65,7 +70,11 @@ def to_hex(value):
def
fold_constants
(
block
):
def
fold_constants
(
block
):
"""
"""
Constant folding:
Constant folding:
- An immidiate load defines a register value:
x = 3 + 5 -> x = 8
y = x * 2 y = 16
To keep track of constant values, the following assumptions are made:
- An immediate load defines a register value:
li $reg, XX -> register[$reg] = XX
li $reg, XX -> register[$reg] = XX
- Integer variable definition is of the following form:
- Integer variable definition is of the following form:
li $reg, XX -> constants[VAR] = XX
li $reg, XX -> constants[VAR] = XX
...
@@ -161,12 +170,12 @@ def copy_propagation(block):
...
@@ -161,12 +170,12 @@ def copy_propagation(block):
while
not
block
.
end
():
while
not
block
.
end
():
s
=
block
.
read
()
s
=
block
.
read
()
if
len
(
s
)
==
3
:
if
len
(
s
)
==
3
:
print
"
s[0] =
"
,
s
[
0
]
print
"
s[0] =
"
,
s
[
0
]
print
"
s[1] =
"
,
s
[
1
]
print
"
s[1] =
"
,
s
[
1
]
print
"
s[2] =
"
,
s
[
2
]
print
"
s[2] =
"
,
s
[
2
]
if
moves_from
:
if
moves_from
:
print
"
fr:
"
,
moves_from
print
"
fr:
"
,
moves_from
print
"
to:
"
,
moves_to
print
"
to:
"
,
moves_to
...
@@ -193,10 +202,10 @@ def copy_propagation(block):
...
@@ -193,10 +202,10 @@ def copy_propagation(block):
if
s
[
1
]
==
moves_to
[
i
]:
if
s
[
1
]
==
moves_to
[
i
]:
s
[
1
]
=
moves_from
[
i
]
s
[
1
]
=
moves_from
[
i
]
print
"
Propagated
"
print
"
Propagated
"
if
s
[
2
]
==
moves_to
[
i
]:
if
s
[
2
]
==
moves_to
[
i
]:
s
[
2
]
=
moves_from
[
i
]
s
[
2
]
=
moves_from
[
i
]
print
"
Propagated
"
print
"
Propagated
"
print
""
print
""
return
False
return
False
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