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
668a93c9
Commit
668a93c9
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of github.com:taddeus/peephole
parents
bfe97cf8
95cbd4de
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
report/report.tex
+19
-6
19 additions, 6 deletions
report/report.tex
src/optimize/advanced.py
+1
-1
1 addition, 1 deletion
src/optimize/advanced.py
with
20 additions
and
7 deletions
report/report.tex
+
19
−
6
View file @
668a93c9
...
@@ -118,7 +118,21 @@ primary concern, this is not a big problem.
...
@@ -118,7 +118,21 @@ primary concern, this is not a big problem.
\subsubsection
*
{
Constant folding
}
\subsubsection
*
{
Constant folding
}
Another optimization is to do constant folding. Constant folding is replacing
a expensive step like addition with a more simple step like loading a constant.
Of course, this is not always possible. It is possible in cases where you apply
an operation on two constants, or a constant and a variable of which you know
for sure that it always has a certain value at that point. For example:
\begin
{
verbatim
}
li
$
regA, 1 li
$
regA,
1
addu
$
regB,
$
regA,
2
-
> li
$
regB, 3
\end{verbatim}
Of course, if
\texttt
{
\$
regA
}
is not used after this, it can be removed, which
will be done by the dead code elimination.
One problem we encountered with this is that the use of a
\texttt
{
li
}
is that
the program often also stores this in the memory, so we had to check whether
this was necessary here as well.
\subsubsection*
{
Copy propagation
}
\subsubsection*
{
Copy propagation
}
...
@@ -145,12 +159,11 @@ of the move operation.
...
@@ -145,12 +159,11 @@ of the move operation.
An example would be the following:
An example would be the following:
\begin{verbatim}
\begin{verbatim}
move
$
regA,
$
regB move
$
regA,
$
regB
move
$
regA,
$
regB move
$
regA,
$
regB
... ...
... ...
Code not writing
$
regA, -> ...
Code not writing
$
regA,
$
regB -> ...
$
regB ...
... ...
... ...
addu
$
regC,
$
regA, ... addu
$
regC,
$
regB, ...
addu
$
regC,
$
regA, ... addu
$
regC,
$
regB, ...
\end{verbatim}
\end{verbatim}
This code shows that
\texttt
{
\$
regA
}
is replaced with
\texttt
{
\$
regB
}
. This
This code shows that
\texttt
{
\$
regA
}
is replaced with
\texttt
{
\$
regB
}
. This
way, the move instruction might have become useless, and it will then be
way, the move instruction might have become useless, and it will then be
...
...
This diff is collapsed.
Click to expand it.
src/optimize/advanced.py
+
1
−
1
View file @
668a93c9
...
@@ -137,7 +137,7 @@ def fold_constants(block):
...
@@ -137,7 +137,7 @@ def fold_constants(block):
if
reg_from
in
register
:
if
reg_from
in
register
:
# Other value is also known, copy its value
# Other value is also known, copy its value
register
[
reg_to
]
=
register
[
reg_
to
]
register
[
reg_to
]
=
register
[
reg_
from
]
else
:
else
:
# Other value is unknown, delete the value
# Other value is unknown, delete the value
del
register
[
reg_to
]
del
register
[
reg_to
]
...
...
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