Commit 941ce4df authored by Jayke Meijer's avatar Jayke Meijer

Filled list of optimizations.

parent 134aea82
...@@ -45,10 +45,11 @@ will be discussed seperatly ...@@ -45,10 +45,11 @@ will be discussed seperatly
We only perform one global optimization, which is optimizing branch-jump We only perform one global optimization, which is optimizing branch-jump
statements. The unoptimized Assembly code contains sequences of code of the statements. The unoptimized Assembly code contains sequences of code of the
following structure: following structure:
\begin{lstlisting} \begin{verbatim}
beq ...,$Lx beq ...,$Lx
j $Ly j $Ly
$Lx: ...\end{lstlisting} $Lx: ...
\end{verbatim}
This is inefficient, since there is a jump to a label that follows this code. This is inefficient, since there is a jump to a label that follows this code.
It would be more efficient to replace the branch statement with a \texttt{bne} It would be more efficient to replace the branch statement with a \texttt{bne}
(the opposite case) to the label used in the jump statement. This way the jump (the opposite case) to the label used in the jump statement. This way the jump
...@@ -79,14 +80,14 @@ will describe the types of optimizations here in stead of each optimization. ...@@ -79,14 +80,14 @@ will describe the types of optimizations here in stead of each optimization.
These are optimizations that simply look for a certain statement or pattern of These are optimizations that simply look for a certain statement or pattern of
statements, and optimize these. For example, statements, and optimize these. For example,
\begin{lstlisting} \begin{verbatim}
mov $regA,$regB mov $regA,$regB
instr $regA, $regA,... instr $regA, $regA,...
\end{lstlisting} \end{verbatim}
can be optimized into can be optimized into
\begin{lstlisting} \begin{verbatim}
instr $regA, $regB,... instr $regA, $regB,...
\end{lstlisting} \end{verbatim}
since the register \texttt{\$regA} gets overwritten by the second instruction since the register \texttt{\$regA} gets overwritten by the second instruction
anyway, and the instruction can easily use \texttt{\$regB} in stead of anyway, and the instruction can easily use \texttt{\$regB} in stead of
\texttt{\$regA}. There are a few more of these cases, which are the same as \texttt{\$regA}. There are a few more of these cases, which are the same as
...@@ -163,36 +164,48 @@ this IR and writing the IR back to Assembly. ...@@ -163,36 +164,48 @@ this IR and writing the IR back to Assembly.
\textbf{Global optimizations} \textbf{Global optimizations}
\begin{tabular}{| c c c |} \begin{verbatim}
\hline beq ...,$Lx bne ...,$Ly
\begin{lstlisting} j $Ly -> $Lx: ...
beq ...,$Lx $Lx: ...
j $Ly
$Lx: ...\end{lstlisting} & $\Rightarrow$ & \begin{lstlisting}
bne ...,$Ly bne ...,$Lx beq ...,$Ly
$Lx: ...\end{lstlisting}\\ j $Ly -> $Lx: ...
\hline $Lx: ...
\begin{lstlisting} \end{verbatim}
bne ...,$Lx
j $Ly
$Lx: ...\end{lstlisting} & $\Rightarrow$ & \begin{lstlisting}
beq ...,$Ly
$Lx: ...\end{lstlisting}\\
\hline
\end{tabular}\\
\\
\textbf{Simple basic block optimizations} \textbf{Simple basic block optimizations}
\begin{tabular}{|c c c|} \begin{verbatim}
\hline mov $regA,$regA -> --- // remove it
\begin{lstlisting}
beq ...,$Lx
j $Ly mov $regA,$regB -> instr $regA, $regB,...
$Lx: ...\end{lstlisting} & $\Rightarrow$ & \begin{lstlisting} instr $regA, $regA,...
bne ...,$Ly
$Lx: ...\end{lstlisting}\\
\hline instr $regA,... instr $4,...
\end{tabular}\\ mov [$4-$7], $regA -> jal XXX
\\ jal XXX
sw $regA,XXX -> sw $regA, XXX
ld $regA,XXX
shift $regA,$regA,0 -> --- // remove it
add $regA,$regA,X -> lw ...,X($regA)
lw ...,0($regA)
\end{verbatim}
\textbf{Advanced basic block optimizations} \textbf{Advanced basic block optimizations}
\begin{verbatim}
addu $regA, $regB, 4 addu $regD, $regB, 4
... move $regA, $regD
Code not writing $regB -> ...
... ...
addu $regC, $regB, 4 move $regC, $regD
\end{verbatim}
\end{document} \end{document}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment