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
39bfc57a
Commit
39bfc57a
authored
Dec 28, 2011
by
Jayke Meijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added copy propagation to report and changed its docstring.
parent
8c9efd40
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
4 deletions
+47
-4
report/report.tex
report/report.tex
+44
-0
src/optimize/advanced.py
src/optimize/advanced.py
+3
-4
No files found.
report/report.tex
View file @
39bfc57a
...
@@ -116,6 +116,50 @@ This is a less efficient method then the dag, but because the basic blocks are
...
@@ -116,6 +116,50 @@ This is a less efficient method then the dag, but because the basic blocks are
in general not very large and the execution time of the optimizer is not a
in general not very large and the execution time of the optimizer is not a
primary concern, this is not a big problem.
primary concern, this is not a big problem.
\subsubsection
*
{
Fold constants
}
\subsubsection
*
{
Copy propagation
}
Copy propagation `unpacks' a move instruction, by replacing its destination
address with its source address in the code following the move instruction.
This is not a direct optimization, but this does allow for a more effective
dead code elimination.
The code of the block is checked linearly. When a move operation is
encountered, the source and destination address of this move are stored. When
a normal operation with a source and a destination address are found, a number
of checks are performed.
The first check is whether the destination address is stored as a destination
address of a move instruction. If so, this move instruction is no longer valid,
so the optimizations can not be done. Otherwise, continue with the second
check.
In the second check, the source address is compared to the destination
addresses of all still valid move operations. If these are the same, in the
current operation the found source address is replaced with the source address
of the move operation.
An example would be the following:
\begin
{
verbatim
}
move
$
regA,
$
regB move
$
regA,
$
regB
... ...
Code not writing
$
regA, -> ...
$
regB ...
... ...
addu
$
regC,
$
regA, ... addu
$
regC,
$
regB, ...
\end
{
verbatim
}
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
removed by the dead code elimination.
\subsubsection
*
{
Algebraic transformations
}
\section
{
Implementation
}
\section
{
Implementation
}
We decided to implement the optimization in Python. We chose this programming
We decided to implement the optimization in Python. We chose this programming
...
...
src/optimize/advanced.py
View file @
39bfc57a
...
@@ -162,10 +162,9 @@ def fold_constants(block):
...
@@ -162,10 +162,9 @@ def fold_constants(block):
def
copy_propagation
(
block
):
def
copy_propagation
(
block
):
"""
"""
Replace a variable with its original variable after a move if possible, by
Unpack a move instruction, by replacing its destination
walking through the code, storing move operations and checking whether it
address with its source address in the code following the move instruction.
changes or whether a variable can be replaced. This way, the move statement
This way, the move statement might be a target for dead code elimination.
might be a target for dead code elimination.
move $regA, $regB move $regA, $regB
move $regA, $regB move $regA, $regB
... ...
... ...
...
...
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