Noeud « Next »: , Noeud « Previous »: T9 Goals, Noeud « Up »: T9



4.11.2 T9 Samples

This section will not demonstrate the output of the option -S, --asm-display, since it includes the Tiger runtime, which is quite long. We simply use -I, --instr-display which has the same effect once the registers allocated, i.e., once -s, --asm-compute executed. In short: we use -sI instead of -S to save place.

Allocating registers in the main function, when there is no register pressure is easy, as, in particular, there are no spills. A direct consequence is that many move are now useless, and have disappeared. Voir Example 118, for instance:

     $ tc -sI seven.tig
     # == Final assembler ouput. == #
     # Routine: Main
     t_main:
             sw      $fp, ($sp)
             move    $fp, $sp
             sub     $sp, $sp, 8
             sw      $ra, -4 ($fp)
     l0:
             li      $t0, 2
             mul     $t1, $t0, 3
             li      $t0, 1
             add     $t0, $t0, $t1
     l1:

             lw      $ra, -4 ($fp)
             move    $sp, $fp
             lw      $fp, ($fp)
             jr      $ra
     Example 143: tc -sI seven.tig
     $ tc -S seven.tig >seven.s
     Example 144: tc -S seven.tig >seven.s
     $ mipsy --execute seven.s
     Example 145: mipsy --execute seven.s

Another means to display the result of register allocation consists in reporting the mapping from temps to actual registers:

     $ tc -s --tempmap-display seven.tig
     /* Temporary map. */
     t1 -> $t0
     t2 -> $t1
     t3 -> $t0
     t4 -> $t0
     t5 -> $s0
     t6 -> $s1
     t7 -> $s2
     t8 -> $s3
     t9 -> $s4
     t10 -> $s5
     t11 -> $s6
     t12 -> $s7

     Example 146: tc -s --tempmap-display seven.tig

Of course it is much better to see what is going on:

     (print_int (1 + 2 * 3); print ("\n"))
     File 147: print-seven.tig
     $ tc -sI print-seven.tig
     # == Final assembler ouput. == #
     .data
     l0:
             .word 1
             .asciiz "\n"
     .text

     # Routine: Main
     t_main:
             sw      $fp, ($sp)
             move    $fp, $sp
             sub     $sp, $sp, 8
             sw      $ra, -4 ($fp)
     l1:
             li      $t0, 2
             mul     $t1, $t0, 3
             li      $t0, 1
             add     $a0, $t0, $t1
             jal     print_int
             la      $a0, l0
             jal     print
     l2:

             lw      $ra, -4 ($fp)
             move    $sp, $fp
             lw      $fp, ($fp)
             jr      $ra
     Example 148: tc -sI print-seven.tig
     $ tc -S print-seven.tig >print-seven.s
     Example 149: tc -S print-seven.tig >print-seven.s
     $ mipsy --execute print-seven.s
     7
     Example 150: mipsy --execute print-seven.s

To torture your compiler, you ought to use many temporaries. To be honest, ours is quite slow, it spends way too much time in register allocation.
     let
       var a00 := 00      var a55 := 55
       var a11 := 11      var a66 := 66
       var a22 := 22      var a77 := 77
       var a33 := 33      var a88 := 88
       var a44 := 44      var a99 := 99
     in
       print_int (0
                  +  a00 + a00 + a55 + a55
                  +  a11 + a11 + a66 + a66
                  +  a22 + a22 + a77 + a77
                  +  a33 + a33 + a88 + a88
                  +  a44 + a44 + a99 + a99);
       print ("\n")
     end
     File 151: print-many.tig
     $ tc -eIs --tempmap-display -I --time-report print-many.tig
     error-->Execution times (seconds)
     error--> 8: liveness analysis    : 0.01   (   25%)   0      (    0%)   0.02   (   50%)
     error--> 8: liveness edges       : 0.01   (   25%)   0      (    0%)   0      (    0%)
     error--> 9: coalesce             : 0.01   (   25%)   0      (    0%)   0.01   (   25%)
     error--> 9: register allocation  : 0      (    0%)   0      (    0%)   0.01   (   25%)
     error-->Cumulated times (seconds)
     error--> 7: inst-display         : 0.04   (  100%)   0      (    0%)   0.04   (  100%)
     error--> 8: liveness analysis    : 0.01   (   25%)   0      (    0%)   0.02   (   50%)
     error--> 9: asm-compute          : 0.04   (  100%)   0      (    0%)   0.04   (  100%)
     error--> 9: coalesce             : 0.01   (   25%)   0      (    0%)   0.01   (   25%)
     error--> 9: register allocation  : 0.04   (  100%)   0      (    0%)   0.04   (  100%)
     error--> rest                    : 0.04   (  100%)   0      (    0%)   0.04   (  100%)
     error--> TOTAL (seconds)         : 0.04   user,      0      system,    0.04   wall
     # == Final assembler ouput. == #
     .data
     l0:
             .word 1
             .asciiz "\n"
     .text

     # Routine: Main
     t_main:
             move    t33, $s0
             move    t34, $s1
             move    t35, $s2
             move    t36, $s3
             move    t37, $s4
             move    t38, $s5
             move    t39, $s6
             move    t40, $s7
     l1:
             li      t0, 0
             li      t1, 55
             li      t2, 11
             li      t3, 66
             li      t4, 22
             li      t5, 77
             li      t6, 33
             li      t7, 88
             li      t8, 44
             li      t9, 99
             li      t31, 0
             add     t30, t31, t0
             add     t29, t30, t0
             add     t28, t29, t1
             add     t27, t28, t1
             add     t26, t27, t2
             add     t25, t26, t2
             add     t24, t25, t3
             add     t23, t24, t3
             add     t22, t23, t4
             add     t21, t22, t4
             add     t20, t21, t5
             add     t19, t20, t5
             add     t18, t19, t6
             add     t17, t18, t6
             add     t16, t17, t7
             add     t15, t16, t7
             add     t14, t15, t8
             add     t13, t14, t8
             add     t12, t13, t9
             add     t11, t12, t9
             move    $a0, t11
             jal     print_int
             la      t32, l0
             move    $a0, t32
             jal     print
     l2:
             move    $s0, t33
             move    $s1, t34
             move    $s2, t35
             move    $s3, t36
             move    $s4, t37
             move    $s5, t38
             move    $s6, t39
             move    $s7, t40

     /* Temporary map. */
     t0 -> $a0
     t1 -> $t9
     t2 -> $t8
     t3 -> $t7
     t4 -> $t6
     t5 -> $t5
     t6 -> $t4
     t7 -> $t3
     t8 -> $t2
     t9 -> $t1
     t11 -> $a0
     t12 -> $t0
     t13 -> $t0
     t14 -> $t0
     t15 -> $t0
     t16 -> $t0
     t17 -> $t0
     t18 -> $t0
     t19 -> $t0
     t20 -> $t0
     t21 -> $t0
     t22 -> $t0
     t23 -> $t0
     t24 -> $t0
     t25 -> $t0
     t26 -> $t0
     t27 -> $t0
     t28 -> $t0
     t29 -> $t0
     t30 -> $t0
     t31 -> $t0
     t32 -> $a0
     t33 -> $s0
     t34 -> $s1
     t35 -> $s2
     t36 -> $s3
     t37 -> $s4
     t38 -> $s5
     t39 -> $s6
     t40 -> $s7

     # == Final assembler ouput. == #
     .data
     l0:
             .word 1
             .asciiz "\n"
     .text

     # Routine: Main
     t_main:
             sw      $fp, ($sp)
             move    $fp, $sp
             sub     $sp, $sp, 8
             sw      $ra, -4 ($fp)
     l1:
             li      $a0, 0
             li      $t9, 55
             li      $t8, 11
             li      $t7, 66
             li      $t6, 22
             li      $t5, 77
             li      $t4, 33
             li      $t3, 88
             li      $t2, 44
             li      $t1, 99
             li      $t0, 0
             add     $t0, $t0, $a0
             add     $t0, $t0, $a0
             add     $t0, $t0, $t9
             add     $t0, $t0, $t9
             add     $t0, $t0, $t8
             add     $t0, $t0, $t8
             add     $t0, $t0, $t7
             add     $t0, $t0, $t7
             add     $t0, $t0, $t6
             add     $t0, $t0, $t6
             add     $t0, $t0, $t5
             add     $t0, $t0, $t5
             add     $t0, $t0, $t4
             add     $t0, $t0, $t4
             add     $t0, $t0, $t3
             add     $t0, $t0, $t3
             add     $t0, $t0, $t2
             add     $t0, $t0, $t2
             add     $t0, $t0, $t1
             add     $a0, $t0, $t1
             jal     print_int
             la      $a0, l0
             jal     print
     l2:

             lw      $ra, -4 ($fp)
             move    $sp, $fp
             lw      $fp, ($fp)
             jr      $ra
     Example 152: tc -eIs --tempmap-display -I --time-report print-many.tig