Author: leo
Date: Mon Aug 15 04:48:14 2005
New Revision: 8967

Modified:
   branches/leo-ctx5/PLATFORMS
   branches/leo-ctx5/classes/fixedintegerarray.pmc
   branches/leo-ctx5/docs/running.pod
   branches/leo-ctx5/imcc/cfg.c
   branches/leo-ctx5/imcc/cfg.h
   branches/leo-ctx5/imcc/debug.c
   branches/leo-ctx5/imcc/debug.h
   branches/leo-ctx5/imcc/optimizer.c
   branches/leo-ctx5/imcc/optimizer.h
   branches/leo-ctx5/imcc/reg_alloc.c
   branches/leo-ctx5/imcc/unit.h
   branches/leo-ctx5/jit/sun4/jit_emit.h
Log:
merge -r8957:8966 from trunk

Modified: branches/leo-ctx5/PLATFORMS
==============================================================================
--- branches/leo-ctx5/PLATFORMS (original)
+++ branches/leo-ctx5/PLATFORMS Mon Aug 15 04:48:14 2005
@@ -30,6 +30,7 @@ openbsd                      Y    Y/5  Y
 openbsd_beta_3.5-vax                                 Y*4  Y/26
 os2
 solaris8-sparc-cc       B    -    Y/425 -    -   -   Y    Y/15     20050804
+solaris9-sparc-gcc3.3.2 B    -    Y/2  -     Y       Y    Y/2      20050814
 solaris10-sparc-gcc3.4.3 B                           Y*7  Y/1      20050804
 tru64-alpha-gcc          8                   Y       Y    Y
 tru64-alpha-dec_c_v6.5   8                   Y       Y    Y        20040816

Modified: branches/leo-ctx5/classes/fixedintegerarray.pmc
==============================================================================
--- branches/leo-ctx5/classes/fixedintegerarray.pmc     (original)
+++ branches/leo-ctx5/classes/fixedintegerarray.pmc     Mon Aug 15 04:48:14 2005
@@ -65,11 +65,14 @@ which is a string I<"(el0, el1, ...)">.
             SELF = constant_pmc_new(INTERP, type);
         else
             SELF = pmc_new(INTERP, type);
-        if ((l = string_length(INTERP, rep)) <= 2)      /* "()" - no args */
+        l = string_length(INTERP, rep);
+        if (!l)
             return SELF;
         if (rep->encoding != Parrot_fixed_8_encoding_ptr)
             real_exception(INTERP, NULL, E_ValueError,
                     "unhandled string encoding in constructor");
+        if (l <= 2 && ((char*)rep->strstart)[0] == '(')   /* "()" - no args */
+            return SELF;
         /* count commas */
         p = rep->strstart;
         for (i = l, n = 0; i; --i, ++p) {

Modified: branches/leo-ctx5/docs/running.pod
==============================================================================
--- branches/leo-ctx5/docs/running.pod  (original)
+++ branches/leo-ctx5/docs/running.pod  Mon Aug 15 04:48:14 2005
@@ -42,6 +42,10 @@ This document describes parrot's command
 If this environment variable is set, parrot will use this path as runtime
 prefix instead of the compiled in path.
 
+=item PARROT_GC_DEBUG
+
+Turn on the I<--gc-debug> flag.
+
 =back
 
 =head1 OPTIONS

Modified: branches/leo-ctx5/imcc/cfg.c
==============================================================================
--- branches/leo-ctx5/imcc/cfg.c        (original)
+++ branches/leo-ctx5/imcc/cfg.c        Mon Aug 15 04:48:14 2005
@@ -830,6 +830,52 @@ compute_dominators (Parrot_Interp interp
 #endif
 }
 
+/* Algorithm to find dominance frontiers described in paper 
+ * "A Simple, Fast Dominance Algorithm", Cooper et al. (2001)
+ */
+void
+compute_dominance_frontiers (Parrot_Interp interpreter, IMC_Unit * unit)
+{
+    int i, n, b, runner;
+    Edge *edge;
+    Set** dominance_frontiers;
+
+    n = unit->n_basic_blocks;
+    IMCC_info(interpreter, 2, "compute_dominance_frontiers\n");
+    dominance_frontiers = unit->dominance_frontiers = malloc(sizeof(Set*) * n);
+
+    dominance_frontiers[0] = set_make(n);
+    for (i = 1; i < n; i++) {
+        dominance_frontiers[i] = set_make(n);
+    }
+
+    /* for all nodes, b */
+    for (b = 1; b < n; b++) {
+        edge = unit->bb_list[b]->pred_list;
+        /* if the number of predecessors of b >= 2 */
+        if (edge && edge->pred_next) {
+            /* for all predecessors, p, of b */
+            for (; edge; edge = edge->pred_next) {
+                /* runner = p */
+                runner = edge->from->index;
+                /* while runner != idoms[b] */
+                while (runner >= 0 && runner != unit->idoms[b]) {
+                    /* add b to runner's dominance frontier set */
+                    set_add(unit->dominance_frontiers[runner], b);
+                    /* runner = idoms[runner] */
+                    if (runner == 0)
+                        runner = -1;
+                    else
+                        runner = unit->idoms[runner];
+                }
+            }
+        }
+    }
+        
+    if (IMCC_INFO(interpreter)->debug & DEBUG_CFG)
+        dump_dominance_frontiers(unit);
+}
+
 static void
 free_dominators(IMC_Unit * unit)
 {
@@ -845,6 +891,20 @@ free_dominators(IMC_Unit * unit)
     free(unit->idoms);
 }
 
+static void
+free_dominance_frontiers(IMC_Unit * unit)
+{
+    int i;
+
+    if (!unit->dominance_frontiers)
+        return;
+    for (i=0; i < unit->n_basic_blocks; i++) {
+        set_free (unit->dominance_frontiers[i]);
+    }
+    free(unit->dominance_frontiers);
+    unit->dominance_frontiers = 0;
+}
+
 
 static void
 sort_loops(Parrot_Interp interpreter, IMC_Unit * unit)
@@ -1101,6 +1161,7 @@ clear_basic_blocks(IMC_Unit * unit)
     }
     free_edge(unit);
     free_dominators(unit);
+    free_dominance_frontiers(unit);
     free_loops(unit);
 }
 

Modified: branches/leo-ctx5/imcc/cfg.h
==============================================================================
--- branches/leo-ctx5/imcc/cfg.h        (original)
+++ branches/leo-ctx5/imcc/cfg.h        Mon Aug 15 04:48:14 2005
@@ -47,7 +47,8 @@ struct _IMC_Unit;
 void find_basic_blocks (Parrot_Interp, struct _IMC_Unit *, int first);
 void build_cfg(Parrot_Interp, struct _IMC_Unit *);
 
-void compute_dominators(Parrot_Interp interpreter, struct _IMC_Unit *);
+void compute_dominators(Parrot_Interp, struct _IMC_Unit *);
+void compute_dominance_frontiers(Parrot_Interp, struct _IMC_Unit *);
 int natural_preheader (struct _IMC_Unit *, Loop_info*);
 void find_loops(Parrot_Interp, struct _IMC_Unit *);
 void search_predecessors_not_in(Basic_block*, Set*);

Modified: branches/leo-ctx5/imcc/debug.c
==============================================================================
--- branches/leo-ctx5/imcc/debug.c      (original)
+++ branches/leo-ctx5/imcc/debug.c      Mon Aug 15 04:48:14 2005
@@ -321,6 +321,28 @@ dump_dominators(IMC_Unit * unit)
     fprintf(stderr, "\n");
 }
 
+void
+dump_dominance_frontiers(IMC_Unit * unit)
+{
+    int i, j;
+
+    fprintf(stderr, "\nDumping the Dominance Frontiers:"
+            "\n-------------------------------\n");
+    for (i = 0; i < unit->n_basic_blocks; i++) {
+       fprintf (stderr, "%2d <-", i);
+
+       for(j = 0; j < unit->n_basic_blocks; j++) {
+            if (set_contains(unit->dominance_frontiers[i], j)) {
+               fprintf(stderr, " %2d", j);
+           }
+       }
+
+       fprintf(stderr, "\n");
+    }
+
+    fprintf(stderr, "\n");
+}
+
 /*
  * Local variables:
  * c-indentation-style: bsd

Modified: branches/leo-ctx5/imcc/debug.h
==============================================================================
--- branches/leo-ctx5/imcc/debug.h      (original)
+++ branches/leo-ctx5/imcc/debug.h      Mon Aug 15 04:48:14 2005
@@ -32,6 +32,7 @@ void dump_labels(IMC_Unit *);
 void dump_symreg(IMC_Unit *);
 void dump_interference_graph(IMC_Unit *);
 void dump_dominators(IMC_Unit *);
+void dump_dominance_frontiers(IMC_Unit *);
 void dump_liveness_status(IMC_Unit *);
 void dump_liveness_status_var(IMC_Unit *, SymReg*);
 

Modified: branches/leo-ctx5/imcc/optimizer.c
==============================================================================
--- branches/leo-ctx5/imcc/optimizer.c  (original)
+++ branches/leo-ctx5/imcc/optimizer.c  Mon Aug 15 04:48:14 2005
@@ -63,7 +63,7 @@
 /* buggy - turned off */
 #define  DO_LOOP_OPTIMIZATION 0
 
-static void if_branch(Interp *, IMC_Unit *);
+static int if_branch(Interp *, IMC_Unit *);
 
 static int branch_branch(Interp *interpreter, IMC_Unit *);
 static int unused_label(Interp *interpreter, IMC_Unit *);
@@ -81,16 +81,19 @@ static int clone_remove(Interp *, IMC_Un
 /*
  * Handles optimizations occuring before the construction of the CFG.
  */
-void
+int
 pre_optimize(Interp *interpreter, IMC_Unit * unit)
 {
+    int changed = 0;
+    
     if (IMCC_INFO(interpreter)->optimizer_level & OPT_PRE) {
         IMCC_info(interpreter, 2, "pre_optimize\n");
         /* TODO integrate all in one pass */
-        strength_reduce(interpreter, unit);
+        changed += strength_reduce(interpreter, unit);
         if (!IMCC_INFO(interpreter)->dont_optimize)
-            if_branch(interpreter, unit);
+            changed += if_branch(interpreter, unit);
     }
+    return changed;
 }
 
 /*
@@ -174,15 +177,15 @@ get_neg_op(char *op, int *n)
  *   unless cond L2
  *
  */
-static void
+static int
 if_branch(Interp *interpreter, IMC_Unit * unit)
 {
     Instruction *ins, *last;
-    int reg;
+    int reg, changed = 0;
 
     last = unit->instructions;
     if (!last->next)
-        return;
+        return changed;
     IMCC_info(interpreter, 2, "\tif_branch\n");
     for (ins = last->next; ins; ) {
         if ((last->type & ITBRANCH) &&          /* if ...L1 */
@@ -214,12 +217,14 @@ if_branch(Interp *interpreter, IMC_Unit 
                     ostat.deleted_ins++;
                     ins = delete_ins(unit, ins, 1);
                     ostat.if_branch++;
+                    changed = 1;
                 }
             } /* label found */
         } /* branch detected */
         last = ins;
         ins = ins->next;
     }
+    return changed;
 }
 
 /*

Modified: branches/leo-ctx5/imcc/optimizer.h
==============================================================================
--- branches/leo-ctx5/imcc/optimizer.h  (original)
+++ branches/leo-ctx5/imcc/optimizer.h  Mon Aug 15 04:48:14 2005
@@ -1,6 +1,6 @@
 #if !defined(PARROT_IMCC_OPTIMIZER_H_GUARD)
 #define PARROT_IMCC_OPTIMIZER_H_GUARD
-void pre_optimize(Interp *, IMC_Unit *);
+int pre_optimize(Interp *, IMC_Unit *);
 int cfg_optimize(Interp *, IMC_Unit *);
 int optimize(Interp *, IMC_Unit *);
 void post_optimize(Interp *, IMC_Unit *);

Modified: branches/leo-ctx5/imcc/reg_alloc.c
==============================================================================
--- branches/leo-ctx5/imcc/reg_alloc.c  (original)
+++ branches/leo-ctx5/imcc/reg_alloc.c  Mon Aug 15 04:48:14 2005
@@ -105,8 +105,7 @@ static unsigned int* ig_allocate(int N)
 void
 imc_reg_alloc(Interp *interpreter, IMC_Unit * unit)
 {
-    int todo, first;
-    int loop_counter;
+    int first;
     char *function;
 
     if (!unit)
@@ -136,48 +135,32 @@ imc_reg_alloc(Interp *interpreter, IMC_U
             (IMCC_INFO(interpreter)->debug & DEBUG_IMC))
         imc_stat_init(unit);
 
-    /* consecutive labels, if_branch, unused_labels ... */
-    pre_optimize(interpreter, unit);
-    if (IMCC_INFO(interpreter)->optimizer_level == OPT_PRE && unit->pasm_file)
+    if (IMCC_INFO(interpreter)->optimizer_level == OPT_PRE && unit->pasm_file) 
{
+        while (pre_optimize(interpreter, unit));
         return;
+    }
 
     nodeStack = imcstack_new();
     unit->n_spilled = 0;
 
-    todo = first = 1;
-    loop_counter = 0;
-    while (todo) {
-        loop_counter++;
-        find_basic_blocks(interpreter, unit, first);
-        build_cfg(interpreter, unit);
+    /* build CFG and life info, and optimize iteratively */
+    do {
+        first = 1;
+        do {
+            while (pre_optimize(interpreter, unit));
 
-        first = 0;
-        todo = cfg_optimize(interpreter, unit);
-    }
-    todo = first = 1;
-    loop_counter = 0;
-    while (todo) {
-        loop_counter++;
-        if (!first) {
-            find_basic_blocks(interpreter, unit, 0);
+            find_basic_blocks(interpreter, unit, first);
             build_cfg(interpreter, unit);
-        }
-        first = 0;
+            first = 0;
+        } while (cfg_optimize(interpreter, unit));
 
         compute_dominators(interpreter, unit);
+        compute_dominance_frontiers(interpreter, unit);
         find_loops(interpreter, unit);
 
         build_reglist(interpreter, unit, 1);
         life_analysis(interpreter, unit);
-        /* optimize, as long as there is something to do */
-        if (IMCC_INFO(interpreter)->dont_optimize)
-            todo = 0;
-        else {
-            todo = optimize(interpreter, unit);
-            if (todo)
-                pre_optimize(interpreter, unit);
-        }
-    }
+    } while (!IMCC_INFO(interpreter)->dont_optimize && optimize(interpreter, 
unit));
 
     graph_coloring_reg_alloc(interpreter, unit);
 

Modified: branches/leo-ctx5/imcc/unit.h
==============================================================================
--- branches/leo-ctx5/imcc/unit.h       (original)
+++ branches/leo-ctx5/imcc/unit.h       Mon Aug 15 04:48:14 2005
@@ -27,6 +27,7 @@ typedef struct _IMC_Unit {
     Basic_block **bb_list;
     Set** dominators;
     int* idoms;
+    Set** dominance_frontiers;
     int n_loops;
     Loop_info ** loop_info;
     Edge * edge_list;

Modified: branches/leo-ctx5/jit/sun4/jit_emit.h
==============================================================================
--- branches/leo-ctx5/jit/sun4/jit_emit.h       (original)
+++ branches/leo-ctx5/jit/sun4/jit_emit.h       Mon Aug 15 04:48:14 2005
@@ -371,13 +371,21 @@ Parrot_jit_bytejump(Parrot_jit_info_t *j
 {
 
     /* fixup where we have the Parrot registers - context switches */
-    emitm_ld_i(jit_info->native_ptr, emitm_i(0), offsetof(Interp, ctx.bp), 
Parrot_jit_regbase);
+    emitm_ld_i(jit_info->native_ptr, emitm_i(0), offsetof(Interp, ctx.bp),
+        Parrot_jit_regbase);
+
+    /* fix opmap address */
+    emitm_ld_i(jit_info->native_ptr, emitm_i(0), offsetof(Interp, code), XSR1);
+    emitm_ld_i(jit_info->native_ptr, XSR1,
+        offsetof(struct PackFile_ByteCode, jit_info), XSR1);
+    emitm_ld_i(jit_info->native_ptr, XSR1,
+      (offsetof(Parrot_jit_arena_t, op_map) + offsetof(Parrot_jit_info_t,  
arena)),
+      Parrot_jit_opmap);
 
     /* Construct the starting address of the byte code */
-    emitm_sethi(jit_info->native_ptr, emitm_hi22(interpreter->code->base.data),
-        XSR1);
-    emitm_or_i(jit_info->native_ptr, XSR1,
-        emitm_lo10(interpreter->code->base.data), XSR1);
+    emitm_ld_i(jit_info->native_ptr, emitm_i(0), offsetof(Interp, code), XSR1);
+    emitm_ld_i(jit_info->native_ptr, XSR1, offsetof(struct PackFile_Segment, 
data),
+               XSR1);
 
     /* Calculates the offset into op_map shadow array
      * assuming sizeof(opcode_t) == sizeof(opmap array entry) */

Reply via email to