cvsuser     03/02/08 09:16:26

  Modified:    config/gen/makefiles imcc.in
               languages/imcc ChangeLog imc.c instructions.c optimizer.c
                        optimizer.h
               languages/imcc/t/imcpasm opt1.t opt2.t
               languages/imcc/t/syn bsr.t
  Log:
  imcc-opt1 - remove dead code, branch_branch, tests - s. ChangeLog
  
  Revision  Changes    Path
  1.12      +2 -2      parrot/config/gen/makefiles/imcc.in
  
  Index: imcc.in
  ===================================================================
  RCS file: /cvs/public/parrot/config/gen/makefiles/imcc.in,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -w -r1.11 -r1.12
  --- imcc.in   6 Feb 2003 15:18:29 -0000       1.11
  +++ imcc.in   8 Feb 2003 17:16:13 -0000       1.12
  @@ -45,11 +45,11 @@
   ../../$(PARROTLIB): ../../parrot$(EXE)
        cd ../.. && $(MAKE) $(PARROTLIB)
   
  -imcparser.c : imcc.y $(H_FILES)
  +imcparser.c : imcc.y
        $(YACC) -d -o imcparser.c imcc.y
   
   imcparser.h : imcc.y
  -imclexer.c : imcc.l $(H_FILES)
  +imclexer.c : imcc.l
        $(LEX) imcc.l
   
   .c$(O):
  
  
  
  1.11      +14 -0     parrot/languages/imcc/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/ChangeLog,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -w -r1.10 -r1.11
  --- ChangeLog 8 Feb 2003 14:41:28 -0000       1.10
  +++ ChangeLog 8 Feb 2003 17:16:16 -0000       1.11
  @@ -1,4 +1,18 @@
   - 2003-02-08         leo
  +        * changed branch_branch to optimize a sequence of absolute
  +       branches to branch to the final target
  +     * dead blocks removal
  +     * unreachable lines removal
  +
  +       *****************************************************
  +       make the long announced rule fix:
  +       o global labels MUST start with an underscore
  +       o labels of bsr calls are global
  +       o labels of set_addr op are global
  +       o local labels SHOULD NOT start with an underscore
  +       *****************************************************
  +
  +- 2003-02-08         leo
        * version 0.0.9.13
        * pass -Ox on to tests
        * remove dead code
  
  
  
  1.32      +6 -1      parrot/languages/imcc/imc.c
  
  Index: imc.c
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/imc.c,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -w -r1.31 -r1.32
  --- imc.c     8 Feb 2003 14:41:28 -0000       1.31
  +++ imc.c     8 Feb 2003 17:16:16 -0000       1.32
  @@ -45,13 +45,18 @@
   
       todo = 1;
       while (todo) {
  -        build_reglist();
           find_basic_blocks();
           build_cfg();
   
  +        if (!dont_optimize && dead_code_remove()) {
  +            pre_optimize(interpreter);
  +            continue;
  +        }
  +
           compute_dominators();
           find_loops();
   
  +        build_reglist();
           life_analysis();
           /* optimize, as long as there is something to do -
            * but not, if we found a set_addr, which means
  
  
  
  1.23      +2 -1      parrot/languages/imcc/instructions.c
  
  Index: instructions.c
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/instructions.c,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -w -r1.22 -r1.23
  --- instructions.c    8 Feb 2003 14:41:28 -0000       1.22
  +++ instructions.c    8 Feb 2003 17:16:16 -0000       1.23
  @@ -213,6 +213,7 @@
       next = ins->next;
       prev = ins->prev;
       prev->next = next;
  +    if (next)
       next->prev = prev;
       if (needs_freeing)
           free_ins(ins);
  
  
  
  1.13      +80 -16    parrot/languages/imcc/optimizer.c
  
  Index: optimizer.c
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/optimizer.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -w -r1.12 -r1.13
  --- optimizer.c       8 Feb 2003 14:41:28 -0000       1.12
  +++ optimizer.c       8 Feb 2003 17:16:16 -0000       1.13
  @@ -156,31 +156,40 @@
   }
   
   /*
  - * branch L1
  - * branch L2  <- not reached
  + * branch L1  => branch L2
  + * ...
  + * L1:
  + * branch L2
  + *
    */
   static void branch_branch()
   {
  -    Instruction *ins, *last;
  +    Instruction *ins1, *ins2, *next;
   
       /* reset statistic globals */
       ostat.branch_branch = 0;
  -
  -    last = instructions;
  -    if (!last->next)
  -        return;
  -    for (ins = last->next; ins; ) {
  -        if ((last->type & IF_goto) &&           /* branch Lx */
  -                (ins->type & IF_goto)) {        /* branch Ly*/
  -            ostat.deleted_ins++;
  -            ins = delete_ins(ins, 1);
  +    for (ins1 = 0, ins1 = instructions; ins1; ins1 = ins1->next) {
  +        if ((ins1->type & IF_goto) && !strcmp(ins1->op, "branch")) {
  +            for (ins2 = 0, ins2 = instructions; ins2; ins2 = ins2->next) {
  +                if ((ins2->type & ITLABEL) &&
  +                        !strcmp(ins1->r[0]->name, ins2->r[0]->name)) {
  +                    next = ins2->next;
  +                    if (!next)
  +                        break;
  +                    if ((next->type & IF_goto) &&
  +                            !strcmp(next->op, "branch")) {
  +                        debug(DEBUG_OPT1, "found branch to branch '%s' %s\n",
  +                                ins2->r[0]->name, ins_string(next));
               ostat.branch_branch++;
  +                        ins1->r[0] = next->r[0];
  +                    }
  +                }
           }
  -        last = ins;
  -        ins = ins->next;
       }
   }
   
  +}
  +
   static void unused_label()
   {
       Instruction *ins, *ins2, *last;
  @@ -220,6 +229,61 @@
       }
   }
   
  +/* optimizations with CFG built */
  +int dead_code_remove(void)
  +{
  +    Basic_block *bb;
  +    int i;
  +    int changed = 0;
  +    Instruction *ins, *last;
  +
  +    if (*optimizer_opt == '0')       /* XXX */
  +        return 0;
  +    for (i=1; bb_list[i]; i++) {
  +     bb = bb_list[i];
  +        if ((bb->start->type & ITLABEL) && *bb->start->r[0]->name == '_')
  +            continue;
  +        /* this block isn't entered from anywhere */
  +        if (!bb->pred_list) {
  +            debug(DEBUG_OPT1, "found dead block %d\n", bb->index);
  +            for (ins = bb->start; ins; ) {
  +                ins = delete_ins(ins, 1);
  +                ostat.deleted_ins++;
  +                changed++;
  +                if (!ins || ins == bb->end->next)
  +                    break;
  +            }
  +        }
  +    }
  +    if (changed)
  +        return changed;
  +    for (last = instructions, ins=last->next; last && ins; ins = ins->next) {
  +        if ((last->type & IF_goto) && !(ins->type & ITLABEL)) {
  +            debug(DEBUG_CFG, "unreachable ins deleted %s\n",
  +                    ins_string(ins));
  +            ins = delete_ins(ins, 1);
  +            ostat.deleted_ins++;
  +            changed++;
  +        }
  +        /*
  +         *   branch L1     => --
  +         * L1: ...            L1:
  +         */
  +        if ((last->type & IF_goto) && (ins->type & ITLABEL) &&
  +                !strcmp(last->op, "branch") &&
  +                !strcmp(last->r[0]->name, ins->r[0]->name)) {
  +            debug(DEBUG_CFG, "dead branch deleted %s\n",
  +                    ins_string(ins));
  +            ins = delete_ins(last, 1);
  +            ostat.deleted_ins++;
  +            changed++;
  +        }
  +        last = ins;
  +    }
  +    return changed;
  +}
  +
  +/* optimizations with CFG & life info built */
   static int used_once()
   {
       Instruction *ins;
  @@ -481,7 +545,7 @@
                   changed |= loop_one(interp, bb);
               }
           /* currently e.g. mandel.p6 breaks, if not only the most
  -         * inner loop is changed, but outer loops to */
  +         * inner loop is changed, but outer loops too */
           if (changed) {
               prev_depth = l-1;
               debug(DEBUG_OPT2,"after loop_opt\n");
  
  
  
  1.5       +1 -0      parrot/languages/imcc/optimizer.h
  
  Index: optimizer.h
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/optimizer.h,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -w -r1.4 -r1.5
  --- optimizer.h       31 Jan 2003 10:54:08 -0000      1.4
  +++ optimizer.h       8 Feb 2003 17:16:16 -0000       1.5
  @@ -1,6 +1,7 @@
   #ifndef __OPTIMIZER_H
   #define __OPTIMIZER_H
   void pre_optimize(struct Parrot_Interp *);
  +int dead_code_remove(void);
   int optimize(struct Parrot_Interp *);
   void post_optimize(struct Parrot_Interp *);
   
  
  
  
  1.3       +27 -1     parrot/languages/imcc/t/imcpasm/opt1.t
  
  Index: opt1.t
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/t/imcpasm/opt1.t,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -w -r1.2 -r1.3
  --- opt1.t    8 Feb 2003 11:50:58 -0000       1.2
  +++ opt1.t    8 Feb 2003 17:16:21 -0000       1.3
  @@ -1,8 +1,11 @@
   #!perl
   use strict;
  -use TestCompiler tests => 5;
  +use TestCompiler tests => 6;
   use Test::More qw(skip);
   
  +# these tests are run with -O1 by TestCompiler and show
  +# generated PASM code for various optimizations at level 1
  +
   ##############################
   output_is(<<'CODE', <<'OUT', "branch opt if");
   .sub _main
  @@ -72,3 +75,26 @@
   _L2:
        end
   OUT
  +
  +##############################
  +output_is(<<'CODE', <<'OUT', "branch_branch and dead code");
  +.sub _test
  +   goto l1
  +l2:
  +   noop
  +   print "ok\n"
  +   end
  +l1:
  +   goto l3
  +l4:
  +   eq I1, 0, l2
  +l3:
  +   goto l2
  +.end
  +CODE
  +_test:
  +   noop
  +   print "ok\n"
  +   end
  +OUT
  +
  
  
  
  1.2       +25 -1     parrot/languages/imcc/t/imcpasm/opt2.t
  
  Index: opt2.t
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/t/imcpasm/opt2.t,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- opt2.t    10 Dec 2002 08:55:12 -0000      1.1
  +++ opt2.t    8 Feb 2003 17:16:21 -0000       1.2
  @@ -1,8 +1,11 @@
   #!perl
   use strict;
  -use TestCompiler tests => 1;
  +use TestCompiler tests => 2;
   use Test::More qw(skip);
   
  +# these tests are run with -O2 by TestCompiler and show
  +# generated PASM code for various optimizations at level 2
  +
   ##############################
   output_is(<<'CODE', <<'OUT', "used once lhs");
   .sub _main
  @@ -18,3 +21,24 @@
        end
   OUT
   
  +##############################
  +output_is(<<'CODE', <<'OUT', "move invariant out of loop");
  +.sub _main
  +       set I0, 5
  +loop:
  +       set I1, 2
  +       add I0, I1
  +       lt I0, 20, loop
  +       print I0
  +       end
  +.end
  +CODE
  +_main:
  +  set I0, 5
  +  set I1, 2
  +loop:
  +  add I0, I1
  +  lt I0, 20, loop
  +  print I0
  +  end
  +OUT
  
  
  
  1.2       +3 -3      parrot/languages/imcc/t/syn/bsr.t
  
  Index: bsr.t
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/t/syn/bsr.t,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- bsr.t     7 Feb 2003 17:04:20 -0000       1.1
  +++ bsr.t     8 Feb 2003 17:16:26 -0000       1.2
  @@ -31,11 +31,11 @@
   .sub _test
      $I0 = 5
      $I1 = $I0
  -   bsr fact
  +   bsr _fact
      print $I1
      print "\n"
      end
  -fact:
  +_fact:
      save $I0
      save $I1
      saveall
  @@ -44,7 +44,7 @@
      if $I0 <= 1 goto fin
      dec $I0
      $I1 = $I1 * $I0
  -   bsr fact
  +   bsr _fact
   fin:
      save $I1
      restoreall
  
  
  


Reply via email to