cvsuser     03/02/20 00:04:34

  Modified:    languages/imcc ChangeLog README TestCompiler.pm cfg.c imc.c
                        imc.h instructions.c main.c optimizer.c pbc.c
               languages/imcc/docs running.pod
               languages/imcc/t/imcpasm cfg.t
  Log:
  div-imcc: docu update; optimizer_level; bug fixes
  
  Revision  Changes    Path
  1.12      +10 -0     parrot/languages/imcc/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/ChangeLog,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -w -r1.11 -r1.12
  --- ChangeLog 8 Feb 2003 17:16:16 -0000       1.11
  +++ ChangeLog 20 Feb 2003 08:04:12 -0000      1.12
  @@ -1,3 +1,13 @@
  +- 2003-02-20 leo / Juergen Boemmel
  +
  +     * version 0.0.9.14
  +     * macro preprocessor - thanks Juergen Boemmels
  +       s. docs/macros.pod
  +
  +     * lot of constants optimizations, like add I0, 10, 20
  +     * reorganized optimization levels
  +     * run allocate for PASM code too, if optimizing
  +
   - 2003-02-08         leo
           * changed branch_branch to optimize a sequence of absolute
          branches to branch to the final target
  
  
  
  1.14      +1 -1      parrot/languages/imcc/README
  
  Index: README
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/README,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -w -r1.13 -r1.14
  --- README    10 Dec 2002 08:55:14 -0000      1.13
  +++ README    20 Feb 2003 08:04:13 -0000      1.14
  @@ -224,5 +224,5 @@
   Leopold Toetsch <[EMAIL PROTECTED]>  ... numerous bugfixes/cleanup/rewrite
                                        optimizer.c
                                     run parrot code inside imcc
  -
  +Juergen Boemmels <[EMAIL PROTECTED]> Macro preprocessor
   
  
  
  
  1.5       +1 -0      parrot/languages/imcc/TestCompiler.pm
  
  Index: TestCompiler.pm
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/TestCompiler.pm,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -w -r1.4 -r1.5
  --- TestCompiler.pm   8 Feb 2003 14:41:28 -0000       1.4
  +++ TestCompiler.pm   20 Feb 2003 08:04:13 -0000      1.5
  @@ -61,6 +61,7 @@
        $gen_pasm = 1 if ($by_f =~ m!/imcpasm/!);
        my $opt = '';
        $opt = "-O$1" if ($by_f =~ m!/imcpasm/opt(.)!);
  +     $opt = "-O1" if ($by_f =~ m!/imcpasm/cfg!);
   
        $output =~ s/\cM\cJ/\n/g;
        if ($gen_pasm) {
  
  
  
  1.15      +3 -2      parrot/languages/imcc/cfg.c
  
  Index: cfg.c
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/cfg.c,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -w -r1.14 -r1.15
  --- cfg.c     8 Feb 2003 14:41:28 -0000       1.14
  +++ cfg.c     20 Feb 2003 08:04:13 -0000      1.15
  @@ -47,8 +47,9 @@
                * when we have the target here
                * and it doesn't saveall - like P6C recursive bsr's
                */
  -            if (!strcmp(ins->op, "bsr")) {
  -                char *name = ins->r[0]->name;
  +            if (!strcmp(ins->op, "bsr") || !strcmp(ins->op, "set_addr")) {
  +                char *name =
  +                    *ins->op == 'b' ? ins->r[0]->name : ins->r[1]->name;
                   found = 0;
                   for (lab = instructions; lab; lab = lab->next) {
                       if ((lab->type & ITLABEL) &&
  
  
  
  1.34      +25 -3     parrot/languages/imcc/imc.c
  
  Index: imc.c
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/imc.c,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -w -r1.33 -r1.34
  --- imc.c     17 Feb 2003 13:56:36 -0000      1.33
  +++ imc.c     20 Feb 2003 08:04:13 -0000      1.34
  @@ -19,6 +19,7 @@
   static void imc_stat_init(void);
   static void print_stat(void);
   
  +extern int pasm_file;
   /* Globals: */
   
   static IMCStack nodeStack;
  @@ -41,6 +42,8 @@
   
       if (!instructions)
           return;
  +    if (!optimizer_level && pasm_file)
  +        return;
   
       debug(DEBUG_IMC, "\n------------------------\n");
       debug(DEBUG_IMC, "processing sub %s\n", function);
  @@ -48,26 +51,36 @@
       if (IMCC_VERBOSE > 1 || (IMCC_DEBUG & DEBUG_IMC))
           imc_stat_init();
   
  +    info(2, "pre_optimize\n");
       /* consecutive labels, if_branch, unused_labels ... */
       pre_optimize(interpreter);
  +    if (optimizer_level == OPT_PRE && pasm_file)
  +        return;
   
       nodeStack = imcstack_new();
       dont_optimize = n_spilled = 0;
   
       todo = 1;
       while (todo) {
  +        info(2, "find_basic_blocks\n");
           find_basic_blocks();
  +        info(2, "build_cfg\n");
           build_cfg();
   
           if (!dont_optimize && dead_code_remove()) {
  +            info(2, "pre_optimize\n");
               pre_optimize(interpreter);
               continue;
           }
   
  +        info(2, "compute_dominators\n");
           compute_dominators();
  +        info(2, "find_loops\n");
           find_loops();
   
  +        info(2, "build_reglist\n");
           build_reglist();
  +        info(2, "life_analysis\n");
           life_analysis();
           /* optimize, as long as there is something to do -
            * but not, if we found a set_addr, which means
  @@ -76,15 +89,17 @@
               dump_symreg();
           if (dont_optimize)
               todo = 0;
  -        else
  +        else {
  +            info(2, "optimize\n");
               todo = optimize(interpreter);
       }
  +    }
       todo = 1;
       while (todo) {
           build_interference_graph();
           compute_spilling_costs();
           /* simplify until no changes can be made */
  -        while (simplify()) {}
  +        /* while (simplify()) {} */
           order_spilling();          /* puts the remaing item on stack */
   
           to_spill = try_allocate();
  @@ -99,6 +114,8 @@
               todo = 0;
           }
       }
  +    if (IMCC_DEBUG & DEBUG_IMC)
  +        dump_instructions();
       if (IMCC_VERBOSE > 1 || (IMCC_DEBUG & DEBUG_IMC))
           print_stat();
       free_reglist();
  @@ -222,6 +239,11 @@
                       reglist[count++] = r->reg;
                   else
                       reglist[count++] = r;
  +                /* rearange I registers */
  +                if ((optimizer_level & OPT_PASM) && pasm_file &&
  +                        (reglist[count-1]->set == 'I' ||
  +                        reglist[count-1]->set == 'N'))
  +                    reglist[count-1]->color = -1;
               }
           }
       }
  @@ -538,7 +560,7 @@
        for(t = 0; t < 4; t++) {
            int typ = "INSP"[t];
            memset(colors, 0, sizeof(colors));
  -         if (reglist[x]->set == typ) {
  +         if (reglist[x]->set == typ && reglist[x]->color == -1) {
                free_colors = map_colors(x, graph, colors, typ);
                if (free_colors > 0) {
                    for(color = 0; color < MAX_COLOR - (typ=='P'); color++) {
  
  
  
  1.27      +9 -1      parrot/languages/imcc/imc.h
  
  Index: imc.h
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/imc.h,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -w -r1.26 -r1.27
  --- imc.h     17 Feb 2003 13:56:36 -0000      1.26
  +++ imc.h     20 Feb 2003 08:04:13 -0000      1.27
  @@ -77,8 +77,16 @@
   EXTERN char * sourcefile;    /* current file */
   EXTERN char * function;      /* current function */
   EXTERN int        line;      /* and line */
  -EXTERN char optimizer_opt[20];
  +EXTERN int optimizer_level;
   EXTERN int dont_optimize;
  +
  +enum {
  +     OPT_NONE,
  +     OPT_PRE,
  +     OPT_CFG =       0x002,
  +     OPT_PASM =      0x100,
  +     OPT_J =         0x200
  +} enum_opt;
   
   struct imcc_ostat {
        int deleted_labels;
  
  
  
  1.26      +0 -23     parrot/languages/imcc/instructions.c
  
  Index: instructions.c
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/instructions.c,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -w -r1.25 -r1.26
  --- instructions.c    17 Feb 2003 13:56:36 -0000      1.25
  +++ instructions.c    20 Feb 2003 08:04:13 -0000      1.26
  @@ -270,34 +270,11 @@
   /* Emits the instructions buffered in 'instructions' */
   Instruction * emitb(Instruction * i) {
   
  -    Instruction *prev;
  -
       if (!i)
        return 0;
       if(!instructions)
           last_ins = instructions = i;
       else {
  -        if ((last_ins->type & IF_goto) && !(i->type & ITLABEL)) {
  -            debug(DEBUG_CFG, "unreachable ins dropped line %d op %s\n",
  -                    line - 1, i->op);
  -            return i;
  -        }
  -        if ((last_ins->type & IF_goto) && (i->type & ITLABEL) &&
  -                !strcmp(last_ins->op, "branch") &&
  -                !strcmp(last_ins->r[0]->name, i->r[0]->name)) {
  -            debug(DEBUG_CFG, "dead branch dropped line %d op %s\n",
  -                    line - 1, i->op);
  -            prev = last_ins->prev;
  -            if (!prev)
  -                instructions = i;
  -            else
  -                prev->next = i;
  -            i->prev = prev;
  -            free_ins(last_ins);
  -            last_ins = i;
  -            i->line = line - 1;
  -            return i;
  -        }
        last_ins->next = i;
           i->prev = last_ins;
        last_ins = i;
  
  
  
  1.17      +21 -6     parrot/languages/imcc/main.c
  
  Index: main.c
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/main.c,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -w -r1.16 -r1.17
  --- main.c    17 Feb 2003 13:56:36 -0000      1.16
  +++ main.c    20 Feb 2003 08:04:13 -0000      1.17
  @@ -19,9 +19,10 @@
   #include "pbc.h"
   #include "parser.h"
   
  -#define IMCC_VERSION "0.0.9.13"
  +#define IMCC_VERSION "0.0.9.14"
   
   static int run_pbc, write_pbc;
  +static char optimizer_opt[20];
   extern FILE *yyin;
   
   static void usage(FILE *fp)
  @@ -198,9 +199,22 @@
       /* register PASM and PIR compilers to parrot core */
       register_compilers(interpreter);
   
  -    /* default optimizations, s. optimizer.c */
  -    if (!*optimizer_opt)
  +    /* default optimizations, s. optimizer.c, imc.h */
  +    if (!*optimizer_opt) {
           strcpy(optimizer_opt, "0");
  +        optimizer_level = 0;
  +    }
  +    else {
  +        if (strchr(optimizer_opt, '1'))
  +            optimizer_level |= OPT_PRE;
  +        if (strchr(optimizer_opt, '2'))
  +            optimizer_level |= (OPT_CFG | OPT_PRE);
  +        if (strchr(optimizer_opt, 'j'))
  +            optimizer_level |= OPT_J;
  +        if (strchr(optimizer_opt, 'p'))
  +            optimizer_level |= OPT_PASM;
  +    }
  +
   
       if (!sourcefile || !*sourcefile) {
           fatal(EX_NOINPUT, "main", "No source file specified.\n" );
  @@ -217,8 +231,6 @@
           ext = strrchr(sourcefile, '.');
           if (ext && strcmp (ext, ".pasm") == 0) {
               pasm_file = 1;
  -            if (output)
  -                write_pbc = 1;
           }
           else if (ext && strcmp (ext, ".pbc") == 0) {
               run_pbc = 2;
  @@ -232,6 +244,8 @@
           if (ext && strcmp (ext, ".pbc") == 0) {
               write_pbc = 1;
           }
  +        if (!strcmp(sourcefile, output))
  +            fatal(1, "main", "outputfile is sourcefile\n");
       }
   
       if (IMCC_VERBOSE) {
  @@ -253,7 +267,8 @@
       }
       else {
           int per_pbc = write_pbc | run_pbc;
  -        info(1, "using optimization '%s'\n", optimizer_opt);
  +        info(1, "using optimization '%s' (%x) \n", optimizer_opt,
  +                optimizer_level);
           pf = PackFile_new(0);
           Parrot_loadbc(interpreter, pf);
   
  
  
  
  1.17      +16 -9     parrot/languages/imcc/optimizer.c
  
  Index: optimizer.c
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/optimizer.c,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -w -r1.16 -r1.17
  --- optimizer.c       17 Feb 2003 15:10:52 -0000      1.16
  +++ optimizer.c       20 Feb 2003 08:04:13 -0000      1.17
  @@ -59,7 +59,7 @@
   static int clone_remove(void);
   
   void pre_optimize(struct Parrot_Interp *interp) {
  -    if (*optimizer_opt != '0') {      /* XXX */
  +    if (optimizer_level & OPT_PRE) {      /* XXX */
           subst_constants_mix(interp);
           subst_constants_umix(interp);
           subst_constants(interp);
  @@ -75,7 +75,7 @@
   
   int optimize(struct Parrot_Interp *interp) {
   
  -    if (*optimizer_opt > '1') {      /* XXX */
  +    if (optimizer_level & OPT_CFG) {
           /* constant_propagation(); N/Y */
           if (clone_remove())
               return 1;
  @@ -258,6 +258,7 @@
           for (i = 0; i < 4; i++) {
               if (ins->opsize == 4 &&
                       ins->r[0] == ins->r[1] &&
  +                    (ins->r[0]->set == 'I' || ins->r[0]->set == 'N') &&
                       !strcmp(ins->op, ops[i])) {
                   debug(DEBUG_OPT1, "opt1 %s => ", ins_string(ins));
                   ins->r[1] = ins->r[2];
  @@ -386,7 +387,7 @@
   {
       Instruction *ins, *tmp;
       const char *ops[] = {
  -        "add", "div", "mul", "sub", "set"
  +        "add", "div", "mul", "sub"
       };
       size_t i;
       char b[128];
  @@ -767,7 +768,8 @@
       int changed = 0;
       Instruction *ins, *last;
   
  -    if (*optimizer_opt == '0')       /* XXX */
  +    /* this could be a separate level, now it's done with -O1 */
  +    if (!(optimizer_level & OPT_PRE))
           return 0;
       for (i=1; bb_list[i]; i++) {
        bb = bb_list[i];
  @@ -775,8 +777,11 @@
               continue;
           /* this block isn't entered from anywhere */
           if (!bb->pred_list) {
  +            int bbi = bb->index;
               debug(DEBUG_OPT1, "found dead block %d\n", bb->index);
  -            for (ins = bb->start; ins; ) {
  +            for (ins = bb->start; ins && ins->index == bbi; ) {
  +                debug(DEBUG_OPT1, "unreachable ins deleted %s\n",
  +                    ins_string(ins));
                   ins = delete_ins(ins, 1);
                   ostat.deleted_ins++;
                   changed++;
  @@ -789,7 +794,7 @@
           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",
  +            debug(DEBUG_OPT1, "unreachable ins deleted %s\n",
                       ins_string(ins));
               ins = delete_ins(ins, 1);
               ostat.deleted_ins++;
  @@ -799,16 +804,18 @@
            *   branch L1     => --
            * L1: ...            L1:
            */
  -        if ((last->type & IF_goto) && (ins->type & ITLABEL) &&
  +        if (ins && last && (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",
  +            debug(DEBUG_OPT1, "dead branch deleted %s\n",
                       ins_string(ins));
               ins = delete_ins(last, 1);
               ostat.deleted_ins++;
               changed++;
           }
           last = ins;
  +        if (!ins)
  +            break;
       }
       return changed;
   }
  @@ -1013,7 +1020,7 @@
       debug(DEBUG_OPT2, "inserting it in blk %d after %s\n", pred->index,
               ins_string(out));
       *ins = move_ins(*ins, out);
  -    if (DEBUG_OPT2 & IMCC_DEBUG) {
  +    if (0 && (DEBUG_OPT2 & IMCC_DEBUG)) {
           char buf[256];
           SymReg * regs[IMCC_MAX_REGS];
           Instruction * tmp;
  
  
  
  1.27      +7 -5      parrot/languages/imcc/pbc.c
  
  Index: pbc.c
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/pbc.c,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -w -r1.26 -r1.27
  --- pbc.c     17 Feb 2003 13:56:36 -0000      1.26
  +++ pbc.c     20 Feb 2003 08:04:13 -0000      1.27
  @@ -259,12 +259,14 @@
               store_label(ins->r[0], pc);
               ins->r[0]->color = pc;
           }
  -        else if (!strcmp(ins->op, "bsr")) {
  +        else if (ins->type & ITBRANCH) {
  +            if (!strcmp(ins->op, "bsr")) {
               if (!(ins->r[0]->type & VTREGISTER))
                   store_bsr(ins->r[0], pc, 1);
           }
           else if (!strcmp(ins->op, "set_addr"))
               store_bsr(ins->r[1], pc, 2);
  +        }
           else if (!strcmp(ins->op, "compile"))
               ++has_compile;
           pc += ins->opsize;
  
  
  
  1.7       +7 -2      parrot/languages/imcc/docs/running.pod
  
  Index: running.pod
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/docs/running.pod,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -w -r1.6 -r1.7
  --- running.pod       7 Feb 2003 14:05:57 -0000       1.6
  +++ running.pod       20 Feb 2003 08:04:20 -0000      1.7
  @@ -60,7 +60,10 @@
   
   =item -o outputfile
   
  -Act like assembler. Don't run code, except B<-r> is given too.
  +Act like assembler. Don't run code, except B<-r> is given too. If the
  +outputfile ends with B<.pbc> a PBC file is written. If it ends with
  +B<.pasm> a PASM output is generated, even from PASM input. This canbe
  +handy to check various optimizations including B<-Op>.
   
   =item -r, --run-pbc
   
  @@ -79,9 +82,10 @@
   
   Optimize
   
  - -O0 no opimization
  + -O0 no opimization (default)
    -O1 optimizations w/o life info (e.g. branches)
    -O2 optimizations with life info
  + -Op rewrite I and N PASM registers most used first
   
   This will probably change.
   
  @@ -120,6 +124,7 @@
    imcc x.pasm         run
    imcc x.pbc          run
    -o x.pasm x.imc     ass             x.pasm
  + -o x.pasm y.pasm    ass             x.pasm
    -o x.pbc  x.imc     ass             x.pbc
    -o x.pbc  x.pasm    ass             x.pbc
    -o x.pbc -r x.pasm  ass/run         x.pbc
  
  
  
  1.2       +0 -1      parrot/languages/imcc/t/imcpasm/cfg.t
  
  Index: cfg.t
  ===================================================================
  RCS file: /cvs/public/parrot/languages/imcc/t/imcpasm/cfg.t,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- cfg.t     8 Feb 2003 11:50:58 -0000       1.1
  +++ cfg.t     20 Feb 2003 08:04:33 -0000      1.2
  @@ -48,6 +48,5 @@
   .end
   CODE
   _test:
  -L:
     end
   OUT
  
  
  


Reply via email to