@@ -9,7 +9,6 @@ import scala.util.Random
99
1010/**
1111 * Brute force greedy register allocation algorithm.
12- * <p>
1312 * To make our life easier, don't consider any special registers that may be used during call.
1413 */
1514final class BruteRegAlloc (emitter : AsmEmitter ) extends RegAlloc (emitter) {
@@ -32,6 +31,7 @@ final class BruteRegAlloc(emitter: AsmEmitter) extends RegAlloc(emitter) {
3231 val used = new mutable.TreeSet [Reg ]
3332 }
3433
34+ /** Bind a temp with a register. */
3535 private def bind (temp : Temp , reg : Reg )(implicit ctx : Context ): Unit = {
3636 ctx.used += reg
3737 ctx.occupied += reg
@@ -40,6 +40,7 @@ final class BruteRegAlloc(emitter: AsmEmitter) extends RegAlloc(emitter) {
4040 ctx.tempOf(reg) = temp
4141 }
4242
43+ /** Unbind a temp with its register. */
4344 private def unbind (temp : Temp )(implicit ctx : Context ): Unit = {
4445 if (ctx.regOf.contains(temp)) {
4546 ctx.occupied.remove(ctx.regOf(temp))
@@ -49,24 +50,21 @@ final class BruteRegAlloc(emitter: AsmEmitter) extends RegAlloc(emitter) {
4950
5051 /**
5152 * Main algorithm of local register allocation à la brute-force. Basic idea:
52- * <ul>
53- * <li>Allocation is preformed block-by-block.</li>
54- * <li>Assume that every allocatable register is unoccupied before entering every basic block.</li>
55- * <li>For every read (src) and written (dst) temp {@code t} in every pseudo instruction, attempt the following
56- * in order:</li>
57- * <li><ol>
58- * <li>{@code t} is already bound to a register: keep on using it.</li>
59- * <li>If there exists an available (unoccupied, or the occupied temp is no longer alive) register,
60- * then bind to it.</li>
61- * <li>Arbitrarily pick a general register, spill its value to stack, and then bind to it.</li>
62- * </ol></li>
63- * </ul>
64- * <p>
65- * The output assembly code is maintained by {@code emitter}.
53+ *
54+ * - Allocation is preformed block-by-block.
55+ * - Assume that every allocatable register is unoccupied before entering every basic block.
56+ * - For every read (src) and written (dst) temp `t` in every pseudo instruction, attempt the following in order:
57+ *
58+ * 1. `t` is already bound to a register: keep on using it.
59+ * 1. If there exists an available (unoccupied, or the occupied temp is no longer alive) register,
60+ * then bind to it.
61+ * 1. Arbitrarily pick a general register, spill its value to stack, and then bind to it.</li>
62+ *
63+ * The output assembly code is maintained by `ctx.emitter`.
6664 *
6765 * @param bb the basic block which the algorithm performs on
6866 * @param ctx context
69- * @see # allocRegFor
67+ * @see [[ allocRegFor ]]
7068 */
7169 private def localAlloc (bb : BasicBlock [PseudoInstr ])(implicit ctx : Context ): Unit = {
7270 ctx.regOf.clear()
0 commit comments