OSDN Git Service

* config/darwin-protos.h, config/c4x/c4x-protos.h,
[pf3gnuchains/gcc-fork.git] / gcc / ssa-dce.c
index db13b9a..6ccc222 100644 (file)
@@ -69,6 +69,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 
 #include "config.h"
 #include "system.h"
+#include "coretypes.h"
+#include "tm.h"
 
 #include "rtl.h"
 #include "hard-reg-set.h"
@@ -98,13 +100,13 @@ static void set_control_dependent_block_to_edge_map_bit
 static void control_dependent_block_to_edge_map_free
   PARAMS ((control_dependent_block_to_edge_map c));
 static void find_all_control_dependences
-  PARAMS ((struct edge_list *el, int *pdom,
+  PARAMS ((struct edge_list *el, dominance_info pdom,
           control_dependent_block_to_edge_map cdbte));
 static void find_control_dependence
-  PARAMS ((struct edge_list *el, int edge_index, int *pdom,
+  PARAMS ((struct edge_list *el, int edge_index, dominance_info pdom,
           control_dependent_block_to_edge_map cdbte));
 static basic_block find_pdom
-  PARAMS ((int *pdom, basic_block block));
+  PARAMS ((dominance_info pdom, basic_block block));
 static int inherently_necessary_register_1
   PARAMS ((rtx *current_rtx, void *data));
 static int inherently_necessary_register
@@ -133,10 +135,12 @@ static void mark_all_insn_unnecessary
   rtx INSN;                                                    \
                                                                \
   for (INSN = get_insns (); INSN != NULL_RTX; INSN = NEXT_INSN (INSN)) \
-    if (INSN_DEAD_CODE_P (INSN)) {                             \
-      CODE;                                                    \
-    }                                                          \
+    if (INSN_P (insn) && INSN_DEAD_CODE_P (INSN))              \
+      {                                                                \
+        CODE;                                                  \
+      }                                                                \
 }
+
 /* Find the label beginning block BB.  */
 static rtx find_block_label
   PARAMS ((basic_block bb));
@@ -218,7 +222,7 @@ control_dependent_block_to_edge_map_free (c)
 static void
 find_all_control_dependences (el, pdom, cdbte)
    struct edge_list *el;
-   int *pdom;
+   dominance_info pdom;
    control_dependent_block_to_edge_map cdbte;
 {
   int i;
@@ -237,7 +241,7 @@ static void
 find_control_dependence (el, edge_index, pdom, cdbte)
    struct edge_list *el;
    int edge_index;
-   int *pdom;
+   dominance_info pdom;
    control_dependent_block_to_edge_map cdbte;
 {
   basic_block current_block;
@@ -266,7 +270,7 @@ find_control_dependence (el, edge_index, pdom, cdbte)
 
 static basic_block
 find_pdom (pdom, block)
-     int *pdom;
+     dominance_info pdom;
      basic_block block;
 {
   if (!block)
@@ -276,10 +280,15 @@ find_pdom (pdom, block)
 
   if (block == ENTRY_BLOCK_PTR)
     return ENTRY_BLOCK_PTR->next_bb;
-  else if (block == EXIT_BLOCK_PTR || pdom[block->index] == EXIT_BLOCK)
+  else if (block == EXIT_BLOCK_PTR)
     return EXIT_BLOCK_PTR;
   else
-    return BASIC_BLOCK (pdom[block->index]);
+    {
+      basic_block bb = get_immediate_dominator (pdom, block);
+      if (!bb)
+       return EXIT_BLOCK_PTR;
+      return bb;
+    }
 }
 
 /* Determine if the given CURRENT_RTX uses a hard register not
@@ -441,8 +450,11 @@ static void
 mark_all_insn_unnecessary ()
 {
   rtx insn;
-  for (insn = get_insns (); insn != NULL_RTX; insn = NEXT_INSN (insn))
-    KILL_INSN (insn);
+  for (insn = get_insns (); insn != NULL_RTX; insn = NEXT_INSN (insn)) {
+    if (INSN_P (insn))
+      KILL_INSN (insn);
+  }
+  
 }
 
 /* Find the label beginning block BB, adding one if necessary.  */
@@ -488,7 +500,6 @@ delete_insn_bb (insn)
 void
 ssa_eliminate_dead_code ()
 {
-  int i;
   rtx insn;
   basic_block bb;
   /* Necessary instructions with operands to explore.  */
@@ -497,7 +508,7 @@ ssa_eliminate_dead_code ()
      edge.  "cdbte" abbreviates control dependent block to edge.  */
   control_dependent_block_to_edge_map cdbte;
  /* Element I is the immediate postdominator of block I.  */
-  int *pdom;
+  dominance_info pdom;
   struct edge_list *el;
 
   /* Initialize the data structures.  */
@@ -508,24 +519,15 @@ ssa_eliminate_dead_code ()
 
   /* Prepare for use of BLOCK_NUM ().  */
   connect_infinite_loops_to_exit ();
-   /* Be careful not to clear the added edges.  */
-  compute_bb_for_insn ();
 
   /* Compute control dependence.  */
-  pdom = (int *) xmalloc (last_basic_block * sizeof (int));
-  for (i = 0; i < last_basic_block; ++i)
-    pdom[i] = INVALID_BLOCK;
-  calculate_dominance_info (pdom, NULL, CDI_POST_DOMINATORS);
-  /* Assume there is a path from each node to the exit block.  */
-  for (i = 0; i < last_basic_block; ++i)
-    if (pdom[i] == INVALID_BLOCK)
-      pdom[i] = EXIT_BLOCK;
+  pdom = calculate_dominance_info (CDI_POST_DOMINATORS);
   el = create_edge_list ();
   find_all_control_dependences (el, pdom, cdbte);
 
   /* Find inherently necessary instructions.  */
   for (insn = get_insns (); insn != NULL_RTX; insn = NEXT_INSN (insn))
-    if (find_inherently_necessary (insn))
+    if (find_inherently_necessary (insn) && INSN_P (insn))
       {
        RESURRECT_INSN (insn);
        VARRAY_PUSH_RTX (unprocessed_instructions, insn);
@@ -728,8 +730,11 @@ ssa_eliminate_dead_code ()
        }
     }
   /* Release allocated memory.  */
-  for (insn = get_insns (); insn != NULL_RTX; insn = NEXT_INSN (insn))
-    RESURRECT_INSN (insn);
+  for (insn = get_insns (); insn != NULL_RTX; insn = NEXT_INSN (insn)) {
+    if (INSN_P (insn))
+      RESURRECT_INSN (insn);
+  }
+  
   if (VARRAY_ACTIVE_SIZE (unprocessed_instructions) != 0)
     abort ();
   control_dependent_block_to_edge_map_free (cdbte);