Author: leo
Date: Thu Aug 11 06:26:29 2005
New Revision: 8915

Modified:
   branches/leo-ctx5/imcc/cfg.c
   branches/leo-ctx5/imcc/main.c
Log:
merge -r8912:8914 from trunk; resolved imcc/cfg.c

Modified: branches/leo-ctx5/imcc/cfg.c
==============================================================================
--- branches/leo-ctx5/imcc/cfg.c        (original)
+++ branches/leo-ctx5/imcc/cfg.c        Thu Aug 11 06:26:29 2005
@@ -22,6 +22,7 @@ static void init_basic_blocks(IMC_Unit *
 static void analyse_life_symbol(Parrot_Interp, IMC_Unit *, SymReg*);
 static void analyse_life_block(Parrot_Interp, Basic_block*, SymReg*);
 static void bb_add_edge(IMC_Unit *, Basic_block*, Basic_block*);
+static void bb_remove_edge(IMC_Unit *, Edge*);
 static Basic_block* make_basic_block(Interp *, IMC_Unit *, Instruction*);
 
 /* Code: */
@@ -215,13 +216,13 @@ bb_check_newsub(Parrot_Interp interprete
             }
     }
 }
+
 /* Once the basic blocks have been computed, build_cfg computes
    the dependencies between them. */
-
 void
 build_cfg(Parrot_Interp interpreter, IMC_Unit * unit)
 {
-    int i, j;
+    int i, j, changes;
     SymReg * addr;
     Basic_block *last = NULL, *bb;
     Edge *pred;
@@ -320,6 +321,25 @@ invok:
         last = bb;
     }
 
+    /* Decouple unreachable blocks (not the first block, with no predecessors)
+     * from the CFG
+     */
+    do {
+        changes = 0;
+        for (i = 1; i < unit->n_basic_blocks; i++) {
+            bb = unit->bb_list[i];
+            if (!bb->pred_list) {
+                /* Remove all successor edges of block bb */
+                while (bb->succ_list) {
+                    bb_remove_edge(unit, bb->succ_list);
+                    IMCC_debug(interpreter, DEBUG_CFG,
+                            "remove edge from bb: %d\n", bb->index);
+                    changes = 1;
+                }
+            }
+        }
+    } while (changes);
+
     if (IMCC_INFO(interpreter)->debug & DEBUG_CFG)
         dump_cfg(unit);
 }
@@ -400,6 +420,44 @@ bb_add_edge(IMC_Unit * unit, Basic_block
 }
 
 static void
+bb_remove_edge(IMC_Unit * unit, Edge * edge)
+{
+    Edge *prev;
+
+    if (edge->from->succ_list == edge) {
+        edge->from->succ_list = edge->succ_next;
+    } else {
+        for (prev = edge->from->succ_list; prev; prev = prev->succ_next) {
+            if (prev->succ_next == edge) {
+                prev->succ_next = edge->succ_next;
+            }
+        }
+    }
+
+    if (edge->to->pred_list == edge) {
+        edge->to->pred_list = edge->pred_next;
+    } else {
+        for (prev = edge->to->pred_list; prev; prev = prev->pred_next) {
+            if (prev->pred_next == edge) {
+                prev->pred_next = edge->pred_next;
+            }
+        }
+    }
+
+    if (unit->edge_list == edge) {
+        unit->edge_list = edge->next;
+       free(edge);
+    } else {
+        for (prev = unit->edge_list; prev; prev = prev->next) {
+            if (prev->next == edge) {
+                prev->next = edge->next;
+               free(edge);
+            }
+        }
+    }
+}
+
+static void
 free_edge(IMC_Unit * unit)
 {
     Edge *e, *next;
@@ -685,7 +743,12 @@ compute_dominators (Parrot_Interp interp
     dominators[0] = set_make(n);
     set_add(dominators[0], 0);
     for (i = 1; i < n; i++) {
-        dominators[i] = set_make_full(n);
+        if (unit->bb_list[i]->pred_list) {
+            dominators[i] = set_make_full(n);
+        } else {
+            dominators[i] = set_make(n);
+            set_add(dominators[i], i);
+        }
     }
 
 #if USE_BFS
@@ -748,14 +811,14 @@ compute_dominators (Parrot_Interp interp
                         if (set_contains(dominators[runner], i)) {
                             wrong = 1;
                             break;
-                        } 
+                        }
                     }
                 }
-                if (!wrong) { 
+                if (!wrong) {
                     unit->idoms[b] = unit->bb_list[i]->index;
                     break;
                 }
-            }       
+            }
        }
    }
 

Modified: branches/leo-ctx5/imcc/main.c
==============================================================================
--- branches/leo-ctx5/imcc/main.c       (original)
+++ branches/leo-ctx5/imcc/main.c       Thu Aug 11 06:26:29 2005
@@ -369,6 +369,7 @@ do_pre_process(Parrot_Interp interp)
     int c;
     YYSTYPE val;
 
+    IMCC_push_parser_state(interp);
     while ( (c = yylex(&val, interp)) ) {
         switch (c) {
             case EMIT:          printf(".emit\n"); break;

Reply via email to