|
@@ -2814,20 +2814,33 @@ shown in Figure~\ref{fig:reg-alloc-passes}.
|
|
\end{figure}
|
|
\end{figure}
|
|
|
|
|
|
\begin{exercise}\normalfont
|
|
\begin{exercise}\normalfont
|
|
-Implement the pass \code{allocate-registers} and test it by creating
|
|
|
|
-new example programs that exercise all of the register allocation
|
|
|
|
-algorithm, such as forcing variables to be spilled to the stack.
|
|
|
|
-
|
|
|
|
-We recommend that you create a helper function named
|
|
|
|
-\code{color-graph} that takes an interference graph and a list of all
|
|
|
|
-the variables in the program. This function should return a mapping of
|
|
|
|
-variables to their colors. By creating this helper function, we will
|
|
|
|
-be able to reuse it in Chapter~\ref{ch:functions} when we add support
|
|
|
|
-for functions. Once you have obtained the coloring from
|
|
|
|
-\code{color-graph}, you can assign the variables to registers or stack
|
|
|
|
-locations based on their color and then use the \code{assign-homes}
|
|
|
|
-function from Section~\ref{sec:assign-s0} to replace the variables
|
|
|
|
-with their assigned location.
|
|
|
|
|
|
+ Implement the pass \code{allocate-registers}, which should come
|
|
|
|
+ after the \code{build-interference} pass. The three new passes,
|
|
|
|
+ \code{uncover-live}, \code{build-interference}, and
|
|
|
|
+ \code{allocate-registers} replace the \code{assign-homes} pass of
|
|
|
|
+ Section~\ref{sec:assign-s0}. Just like \code{assign-homes}, the
|
|
|
|
+ output of \code{allocate-registers} should be in the form
|
|
|
|
+ \[
|
|
|
|
+ (\key{program}\;\Int\;\Instr^{+})
|
|
|
|
+ \]
|
|
|
|
+
|
|
|
|
+ We recommend that you create a helper function named
|
|
|
|
+ \code{color-graph} that takes an interference graph and a list of
|
|
|
|
+ all the variables in the program. This function should return a
|
|
|
|
+ mapping of variables to their colors (represented as natural
|
|
|
|
+ numbers). By creating this helper function, you will be able to
|
|
|
|
+ reuse it in Chapter~\ref{ch:functions} when you add support for
|
|
|
|
+ functions.
|
|
|
|
+
|
|
|
|
+ Once you have obtained the coloring from \code{color-graph}, you can
|
|
|
|
+ assign the variables to registers or stack locations and then reuse
|
|
|
|
+ code from the \code{assign-homes} pass from
|
|
|
|
+ Section~\ref{sec:assign-s0} to replace the variables with their
|
|
|
|
+ assigned location.
|
|
|
|
+
|
|
|
|
+ Test your updated compiler by creating new example programs that
|
|
|
|
+ exercise all of the register allocation algorithm, such as forcing
|
|
|
|
+ variables to be spilled to the stack.
|
|
\end{exercise}
|
|
\end{exercise}
|
|
|
|
|
|
|
|
|