|
@@ -5493,6 +5493,8 @@ locations before instruction $I_k$. \racket{We recommend representing
|
|
|
\end{figure}
|
|
|
\fi}
|
|
|
|
|
|
+% TODO: add a python version of the reference box for sets. -Jeremy
|
|
|
+
|
|
|
The locations that are live after an instruction are its
|
|
|
\emph{live-after}\index{subject}{live-after} set, and the locations
|
|
|
that are live before an instruction are its
|
|
@@ -5905,7 +5907,7 @@ registers in the interference graph.
|
|
|
\fi}
|
|
|
{\if\edition\pythonEd\pythonColor
|
|
|
\[
|
|
|
-\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
+\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.9]
|
|
|
\node (t0) at (0,2) {$\ttm{tmp\_0}$};
|
|
|
\node (t1) at (0,0) {$\ttm{tmp\_1}$};
|
|
|
\node (z) at (3,2) {$\ttm{z}$};
|
|
@@ -6103,7 +6105,7 @@ register, obtaining the following annotated graph. For example, the
|
|
|
saturation for \code{t} is $\{-1,-2\}$ because it interferes with both
|
|
|
\code{rax} and \code{rsp}.
|
|
|
\[
|
|
|
-\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
+\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.9]
|
|
|
\node (rax) at (0,0) {$\ttm{rax}:-1,\{-2\}$};
|
|
|
\node (rsp) at (10,2) {$\ttm{rsp}:-2,\{-1\}$};
|
|
|
\node (t1) at (0,2) {$\ttm{t}:-,\{-1,-2\}$};
|
|
@@ -6135,7 +6137,7 @@ $\ttm{t}$ and color it with the first available integer, which is
|
|
|
$0$. We mark $0$ as no longer available for $\ttm{z}$, $\ttm{rax}$,
|
|
|
and \ttm{rsp} because they interfere with $\ttm{t}$.
|
|
|
\[
|
|
|
-\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
+\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.9]
|
|
|
\node (rax) at (0,0) {$\ttm{rax}:-1,\{0,-2\}$};
|
|
|
\node (rsp) at (10,2) {$\ttm{rsp}:-2,\{-1,0\}$};
|
|
|
\node (t1) at (0,2) {$\ttm{t}:0,\{-1,-2\}$};
|
|
@@ -6167,7 +6169,7 @@ choosing \code{z}, and coloring it with the first available number, which
|
|
|
is $1$. We add $1$ to the saturation for the neighboring vertices
|
|
|
\code{t}, \code{y}, \code{w}, and \code{rsp}.
|
|
|
\[
|
|
|
-\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
+\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.9]
|
|
|
\node (rax) at (0,0) {$\ttm{rax}:-1,\{0,-2\}$};
|
|
|
\node (rsp) at (10,2) {$\ttm{rsp}:-2,\{-1,0,1\}$};
|
|
|
\node (t1) at (0,2) {$\ttm{t}:0,\{-1,1,-2\}$};
|
|
@@ -6197,7 +6199,7 @@ is $1$. We add $1$ to the saturation for the neighboring vertices
|
|
|
The most saturated vertices are now \code{w} and \code{y}. We color
|
|
|
\code{w} with the first available color, which is $0$.
|
|
|
\[
|
|
|
-\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
+\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.9]
|
|
|
\node (rax) at (0,0) {$\ttm{rax}:-1,\{0,-2\}$};
|
|
|
\node (rsp) at (10,2) {$\ttm{rsp}:-2,\{-1,0,1\}$};
|
|
|
\node (t1) at (0,2) {$\ttm{t}:0,\{-1,1,-2\}$};
|
|
@@ -6229,7 +6231,7 @@ with $2$. We cannot choose $0$ or $1$ because those numbers are in
|
|
|
\code{y}'s saturation set. Indeed, \code{y} interferes with \code{w}
|
|
|
and \code{z}, whose colors are $0$ and $1$ respectively.
|
|
|
\[
|
|
|
-\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
+\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.9]
|
|
|
\node (rax) at (0,0) {$\ttm{rax}:-1,\{0,-2\}$};
|
|
|
\node (rsp) at (10,2) {$\ttm{rsp}:-2,\{-1,0,1,2\}$};
|
|
|
\node (t1) at (0,2) {$\ttm{t}:0,\{-1,1,-2\}$};
|
|
@@ -6258,7 +6260,7 @@ and \code{z}, whose colors are $0$ and $1$ respectively.
|
|
|
\]
|
|
|
Now \code{x} and \code{v} are the most saturated, so we color \code{v} with $1$.
|
|
|
\[
|
|
|
-\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
+\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.9]
|
|
|
\node (rax) at (0,0) {$\ttm{rax}:-1,\{0,-2\}$};
|
|
|
\node (rsp) at (10,2) {$\ttm{rsp}:-2,\{-1,0,1,2\}$};
|
|
|
\node (t1) at (0,2) {$\ttm{t}:0,\{-1,1,-2\}$};
|
|
@@ -6287,7 +6289,7 @@ Now \code{x} and \code{v} are the most saturated, so we color \code{v} with $1$.
|
|
|
\]
|
|
|
In the last step of the algorithm, we color \code{x} with $1$.
|
|
|
\[
|
|
|
-\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
+\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.9]
|
|
|
\node (rax) at (0,0) {$\ttm{rax}:-1,\{0,-2\}$};
|
|
|
\node (rsp) at (10,2) {$\ttm{rsp}:-2,\{-1,0,1,2\}$};
|
|
|
\node (t1) at (0,2) {$\ttm{t}:0,\{-1,1,-2\}$};
|
|
@@ -6333,19 +6335,15 @@ So, we obtain the following coloring:
|
|
|
%
|
|
|
With the DSATUR algorithm in hand, let us return to the running
|
|
|
example and consider how to color the interference graph shown in
|
|
|
-figure~\ref{fig:interfere}, again mapping 1 to blank, 2 to white, and
|
|
|
-3 to gray. We annotate each variable node with a dash to indicate that
|
|
|
-it has not yet been assigned a color. Each register node (not shown)
|
|
|
-should be assigned the number that the register corresponds to, for
|
|
|
-example, color \code{rcx} with the number \code{0} and \code{rdx} with
|
|
|
-\code{1}. The saturation sets are also shown for each node; all of
|
|
|
-them start as the empty set. We do not show the register nodes in the
|
|
|
-following graph because there were no interference edges involving
|
|
|
-registers in this program; however, in general there can be inference
|
|
|
-edges that involve registers.
|
|
|
+figure~\ref{fig:interfere}. We annotate each variable node with a dash
|
|
|
+to indicate that it has not yet been assigned a color. Each register
|
|
|
+node (not shown) should be assigned the number that the register
|
|
|
+corresponds to, for example, color \code{rcx} with the number \code{0}
|
|
|
+and \code{rdx} with \code{1}. The saturation sets are also shown for
|
|
|
+each node; all of them start as the empty set.
|
|
|
%
|
|
|
\[
|
|
|
-\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
+\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.9]
|
|
|
\node (t0) at (0,2) {$\ttm{tmp\_0}: -, \{\}$};
|
|
|
\node (t1) at (0,0) {$\ttm{tmp\_1}: -, \{\}$};
|
|
|
\node (z) at (3,2) {$\ttm{z}: -, \{\}$};
|
|
@@ -6369,7 +6367,7 @@ and then we color it with the first available integer, which is $0$. We mark
|
|
|
$0$ as no longer available for $\ttm{tmp\_1}$ and $\ttm{z}$ because
|
|
|
they interfere with $\ttm{tmp\_0}$.
|
|
|
\[
|
|
|
-\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
+\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.9]
|
|
|
\node (t0) at (0,2) {$\ttm{tmp\_0}: 0, \{\}$};
|
|
|
\node (t1) at (0,0) {$\ttm{tmp\_1}: -, \{0\}$};
|
|
|
\node (z) at (3,2) {$\ttm{z}: -, \{0\}$};
|
|
@@ -6392,7 +6390,7 @@ We repeat the process. The most saturated vertices are \code{z} and
|
|
|
available number, which is $1$. We add $1$ to the saturation for the
|
|
|
neighboring vertices \code{tmp\_0}, \code{y}, and \code{w}.
|
|
|
\[
|
|
|
-\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
+\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.9]
|
|
|
\node (t0) at (0,2) {$\ttm{tmp\_0}: 0, \{1\}$};
|
|
|
\node (t1) at (0,0) {$\ttm{tmp\_1}: -, \{0\}$};
|
|
|
\node (z) at (3,2) {$\ttm{z}: 1, \{0\}$};
|
|
@@ -6414,7 +6412,7 @@ The most saturated vertices are now \code{tmp\_1}, \code{w}, and
|
|
|
\code{y}. We color \code{w} with the first available color, which
|
|
|
is $0$.
|
|
|
\[
|
|
|
-\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
+\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.9]
|
|
|
\node (t0) at (0,2) {$\ttm{tmp\_0}: 0, \{1\}$};
|
|
|
\node (t1) at (0,0) {$\ttm{tmp\_1}: -, \{0\}$};
|
|
|
\node (z) at (3,2) {$\ttm{z}: 1, \{0\}$};
|
|
@@ -6434,7 +6432,7 @@ is $0$.
|
|
|
\]
|
|
|
Now \code{y} is the most saturated, so we color it with $2$.
|
|
|
\[
|
|
|
-\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
+\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.9]
|
|
|
\node (t0) at (0,2) {$\ttm{tmp\_0}: 0, \{1\}$};
|
|
|
\node (t1) at (0,0) {$\ttm{tmp\_1}: -, \{0\}$};
|
|
|
\node (z) at (3,2) {$\ttm{z}: 1, \{0,2\}$};
|
|
@@ -6455,7 +6453,7 @@ Now \code{y} is the most saturated, so we color it with $2$.
|
|
|
The most saturated vertices are \code{tmp\_1}, \code{x}, and \code{v}.
|
|
|
We choose to color \code{v} with $1$.
|
|
|
\[
|
|
|
-\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
+\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.9]
|
|
|
\node (t0) at (0,2) {$\ttm{tmp\_0}: 0, \{1\}$};
|
|
|
\node (t1) at (0,0) {$\ttm{tmp\_1}: -, \{0\}$};
|
|
|
\node (z) at (3,2) {$\ttm{z}: 1, \{0,2\}$};
|
|
@@ -6475,7 +6473,7 @@ We choose to color \code{v} with $1$.
|
|
|
\]
|
|
|
We color the remaining two variables, \code{tmp\_1} and \code{x}, with $1$.
|
|
|
\[
|
|
|
-\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
+\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.9]
|
|
|
\node (t0) at (0,2) {$\ttm{tmp\_0}: 0, \{1\}$};
|
|
|
\node (t1) at (0,0) {$\ttm{tmp\_1}: 1, \{0\}$};
|
|
|
\node (z) at (3,2) {$\ttm{z}: 1, \{0,2\}$};
|
|
@@ -6556,8 +6554,7 @@ With the coloring complete, we finalize the assignment of variables to
|
|
|
registers and stack locations. We map the first $k$ colors to the $k$
|
|
|
registers and the rest of the colors to stack locations. Suppose for
|
|
|
the moment that we have just one register to use for register
|
|
|
-allocation, \key{rcx}. Then we have the following map from colors to
|
|
|
-locations.
|
|
|
+allocation, \key{rcx}. Then we have the following assignment.
|
|
|
\[
|
|
|
\{ 0 \mapsto \key{\%rcx}, \; 1 \mapsto \key{-8(\%rbp)}, \; 2 \mapsto \key{-16(\%rbp)} \}
|
|
|
\]
|
|
@@ -6589,7 +6586,6 @@ Adapt the code from the \code{assign\_homes} pass
|
|
|
(section~\ref{sec:assign-Lvar}) to replace the variables with their
|
|
|
assigned location. Applying this assignment to our running
|
|
|
example shown next, on the left, yields the program on the right.
|
|
|
-% why frame size of 32? -JGS
|
|
|
\begin{center}
|
|
|
{\if\edition\racketEd
|
|
|
\begin{minipage}{0.35\textwidth}
|
|
@@ -6834,7 +6830,7 @@ and \code{pushq} subtracts $8$ from the \code{rsp}.
|
|
|
{\if\edition\racketEd
|
|
|
\begin{figure}[tbp]
|
|
|
\begin{tcolorbox}[colback=white]
|
|
|
-\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
+\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.9]
|
|
|
\node (Lvar) at (0,2) {\large \LangVar{}};
|
|
|
\node (Lvar-2) at (3,2) {\large \LangVar{}};
|
|
|
\node (Lvar-3) at (7,2) {\large \LangVarANF{}};
|
|
@@ -7077,10 +7073,10 @@ two stack locations.
|
|
|
|
|
|
We recommend representing the move relationships in a graph, similarly
|
|
|
to how we represented interference. The following is the \emph{move
|
|
|
- graph} for our running example.
|
|
|
+ graph} for our example.
|
|
|
{\if\edition\racketEd
|
|
|
\[
|
|
|
-\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
+\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.9]
|
|
|
\node (rax) at (0,0) {$\ttm{rax}$};
|
|
|
\node (rsp) at (9,2) {$\ttm{rsp}$};
|
|
|
\node (t) at (0,2) {$\ttm{t}$};
|
|
@@ -7100,7 +7096,7 @@ to how we represented interference. The following is the \emph{move
|
|
|
%
|
|
|
{\if\edition\pythonEd\pythonColor
|
|
|
\[
|
|
|
-\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
+\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.9]
|
|
|
\node (t0) at (0,2) {$\ttm{tmp\_0}$};
|
|
|
\node (t1) at (0,0) {$\ttm{tmp\_1}$};
|
|
|
\node (z) at (3,2) {$\ttm{z}$};
|
|
@@ -7123,7 +7119,7 @@ Now we replay the graph coloring, pausing to see the coloring of
|
|
|
\code{y}. Recall the following configuration. The most saturated vertices
|
|
|
were \code{w} and \code{y}.
|
|
|
\[
|
|
|
-\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
+\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.9]
|
|
|
\node (rax) at (0,0) {$\ttm{rax}:-1,\{0,-2\}$};
|
|
|
\node (rsp) at (9,2) {$\ttm{rsp}:-2,\{-1,0,1,2\}$};
|
|
|
\node (t1) at (0,2) {$\ttm{t}:0,\{1,-2\}$};
|
|
@@ -7156,7 +7152,7 @@ that \code{w} is not move-related to any vertex, but \code{y} is
|
|
|
move-related to \code{t}. So we choose to color \code{y} with $0$,
|
|
|
the same color as \code{t}.
|
|
|
\[
|
|
|
-\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
+\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.9]
|
|
|
\node (rax) at (0,0) {$\ttm{rax}:-1,\{0,-2\}$};
|
|
|
\node (rsp) at (9,2) {$\ttm{rsp}:-2,\{-1,0,1,2\}$};
|
|
|
\node (t1) at (0,2) {$\ttm{t}:0,\{1,-2\}$};
|
|
@@ -7185,7 +7181,7 @@ the same color as \code{t}.
|
|
|
\]
|
|
|
Now \code{w} is the most saturated, so we color it $2$.
|
|
|
\[
|
|
|
-\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
+\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.9]
|
|
|
\node (rax) at (0,0) {$\ttm{rax}:-1,\{0,-2\}$};
|
|
|
\node (rsp) at (9,2) {$\ttm{rsp}:-2,\{-1,0,1,2\}$};
|
|
|
\node (t1) at (0,2) {$\ttm{t}:0,\{1,-2\}$};
|
|
@@ -7216,7 +7212,7 @@ At this point, vertices \code{x} and \code{v} are most saturated, but
|
|
|
\code{x} is move related to \code{y} and \code{z}, so we color
|
|
|
\code{x} to $0$ to match \code{y}. Finally, we color \code{v} to $0$.
|
|
|
\[
|
|
|
-\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
+\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.9]
|
|
|
\node (rax) at (0,0) {$\ttm{rax}:-1,\{0,-2\}$};
|
|
|
\node (rsp) at (9,2) {$\ttm{rsp}:-2,\{-1,0,1,2\}$};
|
|
|
\node (t) at (0,2) {$\ttm{t}:0,\{1,-2\}$};
|
|
@@ -7250,7 +7246,7 @@ Now we replay the graph coloring, pausing before the coloring of
|
|
|
\code{w}. Recall the following configuration. The most saturated vertices
|
|
|
were \code{tmp\_1}, \code{w}, and \code{y}.
|
|
|
\[
|
|
|
-\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
+\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.9]
|
|
|
\node (t0) at (0,2) {$\ttm{tmp\_0}: 0, \{1\}$};
|
|
|
\node (t1) at (0,0) {$\ttm{tmp\_1}: -, \{0\}$};
|
|
|
\node (z) at (3,2) {$\ttm{z}: 1, \{0\}$};
|
|
@@ -7274,7 +7270,7 @@ variables, whereas \code{y} and \code{tmp\_1} are move related to
|
|
|
\code{tmp\_0} and \code{z}, respectively. If we instead choose
|
|
|
\code{y} and color it $0$, we can delete another move instruction.
|
|
|
\[
|
|
|
-\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
+\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.9]
|
|
|
\node (t0) at (0,2) {$\ttm{tmp\_0}: 0, \{1\}$};
|
|
|
\node (t1) at (0,0) {$\ttm{tmp\_1}: -, \{0\}$};
|
|
|
\node (z) at (3,2) {$\ttm{z}: 1, \{0\}$};
|
|
@@ -7294,7 +7290,7 @@ variables, whereas \code{y} and \code{tmp\_1} are move related to
|
|
|
\]
|
|
|
Now \code{w} is the most saturated, so we color it $2$.
|
|
|
\[
|
|
|
-\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
+\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.9]
|
|
|
\node (t0) at (0,2) {$\ttm{tmp\_0}: 0, \{1\}$};
|
|
|
\node (t1) at (0,0) {$\ttm{tmp\_1}: -, \{0\}$};
|
|
|
\node (z) at (3,2) {$\ttm{z}: 1, \{0\}$};
|
|
@@ -7315,7 +7311,7 @@ Now \code{w} is the most saturated, so we color it $2$.
|
|
|
To finish the coloring, \code{x} and \code{v} get $0$ and
|
|
|
\code{tmp\_1} gets $1$.
|
|
|
\[
|
|
|
-\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
+\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.9]
|
|
|
\node (t0) at (0,2) {$\ttm{tmp\_0}: 0, \{1\}$};
|
|
|
\node (t1) at (0,0) {$\ttm{tmp\_1}: 1, \{0\}$};
|
|
|
\node (z) at (3,2) {$\ttm{z}: 1, \{0\}$};
|