|
@@ -4704,6 +4704,55 @@ blocks $B_3$ and $B_4$ to obtain the result $B_5$.
|
|
|
B_5
|
|
|
\]
|
|
|
|
|
|
+Finally, note that the way in which the \code{shrink} pass transforms
|
|
|
+logical operations such as \code{and} and \code{or} can impact the
|
|
|
+quality of code generated by \code{explicate-control}. For example,
|
|
|
+consider the following program.
|
|
|
+\begin{lstlisting}
|
|
|
+(if (and (eq? (read) 0) (eq? (read) 1))
|
|
|
+ 0
|
|
|
+ 42)
|
|
|
+\end{lstlisting}
|
|
|
+The \code{and} operation should transform into something that the
|
|
|
+\code{explicat-pred} function can still analyze and descend through to
|
|
|
+reach the underlying \code{eq?} conditions. Ideally, your
|
|
|
+\code{explicate-control} pass should generate code similar to the
|
|
|
+following for the above program.\footnote{If the trivial blocks 17,
|
|
|
+ 18, and 20 bother you, take a look at the challenge problem in
|
|
|
+ Section~\ref{sec:opt-jumps}.}
|
|
|
+\begin{center}
|
|
|
+\begin{minipage}{0.45\textwidth}
|
|
|
+\begin{lstlisting}
|
|
|
+start:
|
|
|
+ tmp13 = (read);
|
|
|
+ if (eq? tmp13 0)
|
|
|
+ goto block19;
|
|
|
+ else
|
|
|
+ goto block20;
|
|
|
+block19:
|
|
|
+ tmp14 = (read);
|
|
|
+ if (eq? tmp14 1)
|
|
|
+ goto block17;
|
|
|
+ else
|
|
|
+ goto block18;
|
|
|
+\end{lstlisting}
|
|
|
+\end{minipage}
|
|
|
+\begin{minipage}{0.45\textwidth}
|
|
|
+\begin{lstlisting}
|
|
|
+block20:
|
|
|
+ goto block16;
|
|
|
+block17:
|
|
|
+ goto block15;
|
|
|
+block18:
|
|
|
+ goto block16;
|
|
|
+block15:
|
|
|
+ return 0;
|
|
|
+block16:
|
|
|
+ return 42;
|
|
|
+\end{lstlisting}
|
|
|
+\end{minipage}
|
|
|
+\end{center}
|
|
|
+
|
|
|
\begin{exercise}\normalfont
|
|
|
Implement the pass \code{explicate-control} by adding the cases for
|
|
|
\key{if} to the functions for tail and assignment contexts, and
|
|
@@ -7088,7 +7137,7 @@ and changes the top \code{ProgramDefsExp} form to
|
|
|
\end{lstlisting}
|
|
|
where $\itm{mainDef}$ is
|
|
|
\begin{lstlisting}
|
|
|
-(Def main () Integer () |$\Exp'$|)
|
|
|
+(Def 'main '() 'Integer '() |$\Exp'$|)
|
|
|
\end{lstlisting}
|
|
|
|
|
|
|