| 1 |
\section{Span Dependency Resolution} \label{sec:span-dep} |
| 2 |
|
| 3 |
The span dependency resolution phase is used to resolve the values of |
| 4 |
client defined \href{constants.html}{constants} and \href{labels.html}{labels} |
| 5 |
in a program. An instruction whose immediate operand field contains a |
| 6 |
constant or \href{labexp.html}{label expression} which |
| 7 |
is too large is rewritten into a sequence of instructions to compute |
| 8 |
the same result. Similarly, short branches referencing labels that are |
| 9 |
too far are rewritten into the long form. For architectures |
| 10 |
that require the filling of delay slots, this is performed at the same |
| 11 |
time as span depedency resolution, to ensure maximum benefit results. |
| 12 |
|
| 13 |
\subsubsection{The Interface} |
| 14 |
|
| 15 |
The signature \sml{SDI_JUMPS} describes |
| 16 |
architectural information about span dependence resolution. |
| 17 |
|
| 18 |
\begin{SML} |
| 19 |
signature \mlrischref{backpatch/sdi-jumps.sig}{SDI_JUMPS} = sig |
| 20 |
structure I : \href{instructions.html}{INSTRUCTIONS} |
| 21 |
structure C : \href{cells.html}{CELLS} |
| 22 |
sharing I.C = C |
| 23 |
|
| 24 |
val branchDelayedArch : bool |
| 25 |
val isSdi : I.instruction -> bool |
| 26 |
val minSize : I.instruction -> int |
| 27 |
val maxSize : I.instruction -> int |
| 28 |
val sdiSize : I.instruction * (C.cell -> C.cell) |
| 29 |
* (Label.label -> int) * int -> int |
| 30 |
val expand : I.instruction * int * int -> I.instruction list |
| 31 |
end |
| 32 |
\end{SML} |
| 33 |
|
| 34 |
The components in this interface are: |
| 35 |
\begin{description} |
| 36 |
\item[branchDelayedArch] A flag indicating whether the architecture |
| 37 |
contains delay slots. For example, this would be true on the MIPS, |
| 38 |
Sparc, PA RISC; but would be false on the x86 and on the Alpha. |
| 39 |
\item[isSdi] This function returns true if the instruction is |
| 40 |
\newdef{span dependent}, i.e.~its size depends either on some unresolved |
| 41 |
constants, or on its position in the code stream. |
| 42 |
\item[sdiSize] This function takes a span dependent instruction, |
| 43 |
a \href{regmap.html}{regmap}, |
| 44 |
a mapping from labels to code stream position, and |
| 45 |
its current code stream position and returns the size of its |
| 46 |
expansion in bytes. |
| 47 |
\item[expand] This function takes a span dependent instruction, |
| 48 |
its size, and its location and return its expansion. |
| 49 |
\end{description} |
| 50 |
|
| 51 |
The signature \sml{BBSCHED} is the signature of the phase that performs |
| 52 |
span depedennce resolution and code generation. |
| 53 |
\begin{SML} |
| 54 |
signature \mlrischref{backpatch/bbsched.sig}{BBSCHED} = sig |
| 55 |
structure F : \href{cluster.html}{FLOWGRAPH} |
| 56 |
|
| 57 |
val bbsched : F.cluster -> unit |
| 58 |
val finish : unit -> unit |
| 59 |
val cleanUp : unit -> unit |
| 60 |
end |
| 61 |
\end{SML} |
| 62 |
|
| 63 |
\subsubsection{The Modules} |
| 64 |
|
| 65 |
Three different functors are present in the \MLRISC{} system for |
| 66 |
performing span dependence resolution and code generator. |
| 67 |
Functor \sml{BBSched2} is the simplest one, which does not perform |
| 68 |
delay slot filling. |
| 69 |
\begin{SML} |
| 70 |
functor BBSched2 |
| 71 |
(structure Flowgraph : \mlrischref{cluster/flowgraph.sig}{FLOWGRAPH} |
| 72 |
structure Jumps : \mlrischref{backpatch/sdi-jumps.sig}{SDI_JUMPS} |
| 73 |
structure Emitter : \href{mc.html}{INSTRUCTION_EMITTER} |
| 74 |
sharing Emitter.P = Flowgraph.P |
| 75 |
sharing Flowgraph.I = Jumps.I = Emitter.I |
| 76 |
): BBSCHED |
| 77 |
\end{SML} |
| 78 |
|
| 79 |
Functor \sml{SpanDependencyResolution} performs both span dependence |
| 80 |
resolution and delay slot filling at the same time. |
| 81 |
\begin{SML} |
| 82 |
functor SpanDependencyResolution |
| 83 |
(structure Flowgraph : \mlrischref{cluster/flowgraph.sig}{FLOWGRAPH} |
| 84 |
structure Emitter : \href{mc.html}{INSTRUCTION_EMITTER} |
| 85 |
structure Jumps : \mlrischref{backpatch/sdi-jumps.sig}{SDI_JUMPS} |
| 86 |
structure DelaySlot : \href{delayslots.html}{DELAY_SLOT_PROPERTIES} |
| 87 |
structure Props : \mlrischref{instructions/insnProps.sig}{INSN_PROPERTIES} |
| 88 |
sharing Flowgraph.P = Emitter.P |
| 89 |
sharing Flowgraph.I = Jumps.I = DelaySlot.I = Props.I = Emitter.I |
| 90 |
) : BBSCHED |
| 91 |
\end{SML} |
| 92 |
|
| 93 |
Finally, functor \sml{BackPatch} is a span dependency resolution |
| 94 |
module specially written for the \href{x86.html}{x86} architecture. |
| 95 |
\begin{SML} |
| 96 |
functor BackPatch |
| 97 |
(structure CodeString : \mlrischref{emit/code-string.sig}{CODE_STRING} |
| 98 |
structure Jumps: \mlrischref{backpatch/sdi-jumps.sig}{SDI_JUMPS} |
| 99 |
structure Props : \mlrischref{instructions/insnProps.sig}{INSN_PROPERTIES} |
| 100 |
structure Emitter : \mlrischref{backpatch/vlBatchPatch.sig}{MC_EMIT} |
| 101 |
structure Flowgraph : \href{cluster.html}{FLOWGRAPH} |
| 102 |
structure Asm : \href{asm.html}{INSTRUCTION_EMITTER} |
| 103 |
sharing Emitter.I = Jumps.I = Flowgraph.I = Props.I = Asm.I) : BBSCHED |
| 104 |
\end{SML} |
| 105 |
|
| 106 |
|