cvsuser     04/08/05 02:49:49

  Modified:    imcc     imc.h reg_alloc.c
               imcc/t/reg spill.t
  Log:
  fix 2 bugs WRT register spilling; better allocation order
  
  Revision  Changes    Path
  1.69      +0 -7      parrot/imcc/imc.h
  
  Index: imc.h
  ===================================================================
  RCS file: /cvs/public/parrot/imcc/imc.h,v
  retrieving revision 1.68
  retrieving revision 1.69
  diff -u -w -r1.68 -r1.69
  --- imc.h     3 Aug 2004 12:51:06 -0000       1.68
  +++ imc.h     5 Aug 2004 09:49:45 -0000       1.69
  @@ -36,13 +36,6 @@
   #define EXTERN extern
   #endif
   
  -#define SPILL_STRESS 0
  -
  -#if SPILL_STRESS
  -# undef MAX_COLOR
  -# define MAX_COLOR 4
  -#endif
  -
   /* IMCC reserves this character for internally generated labels
    * and identifiers that won't collide with high level compiler generated names.
    */
  
  
  
  1.15      +28 -8     parrot/imcc/reg_alloc.c
  
  Index: reg_alloc.c
  ===================================================================
  RCS file: /cvs/public/parrot/imcc/reg_alloc.c,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -w -r1.14 -r1.15
  --- reg_alloc.c       23 Apr 2004 14:09:33 -0000      1.14
  +++ reg_alloc.c       5 Aug 2004 09:49:45 -0000       1.15
  @@ -29,7 +29,7 @@
   
   #if SPILL_STRESS
   # undef MAX_COLOR
  -# define MAX_COLOR 4
  +# define MAX_COLOR 6
   #endif
   
   static void make_stat(IMC_Unit *, int *sets, int *cols);
  @@ -294,8 +294,11 @@
    */
   
   
  -#define ALLOCATE_HACK
  +/* #define ALLOCATE_HACK */
  +
   #ifdef ALLOCATE_HACK
  +
  +#define SHORT_RANGE 5
   static void
   allocate_non_interfering(Parrot_Interp interpreter, SymReg ** reglist, int n)
   {
  @@ -330,7 +333,7 @@
                   if (r->set != typ || (r->type & VT_REGP) ||
                           r->want_regno >= 0 || r->color >= 0)
                       continue;
  -                if (r->last_ins->index - r->first_ins->index > 10)
  +                if (r->last_ins->index - r->first_ins->index > SHORT_RANGE)
                       continue;
                   if (r->first_ins->bbindex != r->last_ins->bbindex)
                       continue;
  @@ -751,6 +754,9 @@
        min_node = -1;
   
           for (x = 0; x < n_symbols; x++) {
  +            /* if its spilled skip it */
  +            if (unit->reglist[x]->usage & U_SPILL)
  +                continue;
   
               /* for now, our score function only
               takes in account how many times a symbols
  @@ -774,11 +780,20 @@
            }
           }
   
  -     if (min_node == -1) return; /* We are finished */
  +     if (min_node == -1)
  +            break;       /* We are finished */
   
        imcstack_push(nodeStack, min_node);
        unit->reglist[min_node]->simplified = 1;
       }
  +    /*
  +     * now put all spilled regs on top of stack so that they
  +     * get their register first
  +     */
  +    for (x = 0; x < n_symbols; x++) {
  +        if (unit->reglist[x]->usage & U_SPILL)
  +            imcstack_push(nodeStack, x);
  +    }
   }
   
   
  @@ -848,7 +863,7 @@
                free_colors = map_colors(x, graph, colors, typ);
                if (free_colors > 0) {
                    for (color = 0; color < MAX_COLOR; color++) {
  -                        int c = (color + 16) % 32;
  +                        int c = (color + MAX_COLOR/2) % MAX_COLOR;
                        if (!colors[c]) {
                            reglist[x]->color = c;
   
  @@ -863,7 +878,8 @@
                }
   
                if (reglist[x]->color == -1) {
  -                    debug(interpreter, DEBUG_IMC, "# no more colors free = %d\n", 
free_colors);
  +                    debug(interpreter, DEBUG_IMC,
  +                            "# no more colors free = %d\n", free_colors);
   
                    /* It has been impossible to assign a color
                        * to this node, return it so it gets spilled
  @@ -938,8 +954,10 @@
       }
       /* add this sym to reglist, if not there */
       if (add) {
  -        unit->reglist = realloc(unit->reglist, (n_symbols + 1) * sizeof(SymReg *));
  +        unit->reglist = realloc(unit->reglist, (n_symbols + 1) *
  +                sizeof(SymReg *));
           unit->reglist[n_symbols++] = r;
  +        unit->n_symbols = n_symbols;
       }
   
       r->first_ins = r->last_ins = ins;
  @@ -995,7 +1013,7 @@
               }
           }
           free(interference_graph);
  -        interference_graph = new_graph;
  +        unit->interference_graph = interference_graph = new_graph;
       }
       for (x = 0; x < n_symbols; x++) {
           for (y = x + 1; y < n_symbols; y++) {
  @@ -1013,6 +1031,8 @@
           }
       }
       if (IMCC_INFO(interpreter)->debug & DEBUG_IMC) {
  +        fprintf(stderr, "old_sym %s\n", old->name);
  +        fprintf(stderr, "new_sym %s\n", new->name);
           dump_interference_graph(unit);
       }
   }
  
  
  
  1.8       +98 -1     parrot/imcc/t/reg/spill.t
  
  Index: spill.t
  ===================================================================
  RCS file: /cvs/public/parrot/imcc/t/reg/spill.t,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -w -r1.7 -r1.8
  --- spill.t   19 Nov 2003 07:18:05 -0000      1.7
  +++ spill.t   5 Aug 2004 09:49:49 -0000       1.8
  @@ -1,6 +1,6 @@
   #!perl
   use strict;
  -use TestCompiler tests => 3;
  +use TestCompiler tests => 4;
   
   ##############################
   
  @@ -327,3 +327,100 @@
   40
   OUT
   
  +output_is(<<'CODE', <<'OUT', "spill 4");
  +
  +.sub _MAIN
  +     $I0 = 0
  +     $I1 = 1
  +     $I2 = 2
  +     $I3 = 3
  +     $I4 = 4
  +     $I5 = 5
  +     $I6 = 6
  +     $I7 = 7
  +     $I8 = 8
  +     $I9 = 9
  +
  +     $I10 = 10
  +     $I11 = 11
  +     $I12 = 12
  +     $I13 = 13
  +     $I14 = 14
  +     $I15 = 15
  +     $I16 = 16
  +     $I17 = 17
  +     $I18 = 18
  +     $I19 = 19
  +
  +     $I20 = 20
  +     $I21 = 21
  +     $I22 = 22
  +     $I23 = 23
  +     $I24 = 24
  +     $I25 = 25
  +     $I26 = 26
  +     $I27 = 27
  +     $I28 = 28
  +     $I29 = 29
  +
  +     $I30 = 30
  +     $I31 = 31
  +     $I32 = 32
  +     $I33 = 33
  +     $I34 = 34
  +     $I35 = 35
  +     $I36 = 36
  +     $I37 = 37
  +     $I38 = 38
  +     $I39 = 39
  +
  +     if $I0 != 0 goto err
  +     if $I1 != 1 goto err
  +     if $I2 != 2 goto err
  +     if $I3 != 3 goto err
  +     if $I4 != 4 goto err
  +     if $I5 != 5 goto err
  +     if $I6 != 6 goto err
  +     if $I7 != 7 goto err
  +     if $I8 != 8 goto err
  +     if $I9 != 9 goto err
  +     if $I10 != 10 goto err
  +     if $I11 != 11 goto err
  +     if $I12 != 12 goto err
  +     if $I13 != 13 goto err
  +     if $I14 != 14 goto err
  +     if $I15 != 15 goto err
  +     if $I16 != 16 goto err
  +     if $I17 != 17 goto err
  +     if $I18 != 18 goto err
  +     if $I19 != 19 goto err
  +     if $I20 != 20 goto err
  +     if $I21 != 21 goto err
  +     if $I22 != 22 goto err
  +     if $I23 != 23 goto err
  +     if $I24 != 24 goto err
  +     if $I25 != 25 goto err
  +     if $I26 != 26 goto err
  +     if $I27 != 27 goto err
  +     if $I28 != 28 goto err
  +     if $I29 != 29 goto err
  +     if $I30 != 30 goto err
  +     if $I31 != 31 goto err
  +     if $I32 != 32 goto err
  +     if $I33 != 33 goto err
  +     if $I34 != 34 goto err
  +     if $I35 != 35 goto err
  +     if $I36 != 36 goto err
  +     if $I37 != 37 goto err
  +     if $I38 != 38 goto err
  +     if $I39 != 39 goto err
  +
  +     print "ok\n"
  +     end
  +err:
  +     print "nok\n"
  +     end
  +.end
  +CODE
  +ok
  +OUT
  
  
  

Reply via email to