OSDN Git Service

2009-07-31 Andrew Haley <aph@redhat.com>
[pf3gnuchains/gcc-fork.git] / gcc / df-core.c
index 1ad7ab1..8057b54 100644 (file)
@@ -1,6 +1,6 @@
 /* Allocation for dataflow support routines.
    Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
-   2008 Free Software Foundation, Inc.
+   2008, 2009 Free Software Foundation, Inc.
    Originally contributed by Michael P. Hayes 
              (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
    Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
@@ -170,11 +170,6 @@ There are four ways of doing the incremental scanning:
    d) If the pass modifies all of the insns, as does register
       allocation, it is simply better to rescan the entire function.
 
-   e) If the pass uses either non-standard or ancient techniques to
-      modify insns, automatic detection of the insns that need to be
-      rescanned may be impractical.  Cse and regrename fall into this
-      category.
-
 2) Deferred rescanning - Calls to df_insn_rescan, df_notes_rescan, and
    df_insn_delete do not immediately change the insn but instead make
    a note that the insn needs to be rescanned.  The next call to
@@ -182,27 +177,25 @@ There are four ways of doing the incremental scanning:
    cause all of the pending rescans to be processed.
 
    This is the technique of choice if either 1a, 1b, or 1c are issues
-   in the pass.  In the case of 1a or 1b, a call to df_remove_problem
-   (df_chain) should be made before the next call to df_analyze or
-   df_process_deferred_rescans.
+   in the pass.  In the case of 1a or 1b, a call to df_finish_pass
+   (either manually or via TODO_df_finish) should be made before the
+   next call to df_analyze or df_process_deferred_rescans.
+
+   This mode is also used by a few passes that still rely on note_uses,
+   note_stores and for_each_rtx instead of using the DF data.  This
+   can be said to fall under case 1c.
 
    To enable this mode, call df_set_flags (DF_DEFER_INSN_RESCAN).
    (This mode can be cleared by calling df_clear_flags
    (DF_DEFER_INSN_RESCAN) but this does not cause the deferred insns to
    be rescanned.
 
-   3) Total rescanning - In this mode the rescanning is disabled.
-   However, the df information associated with deleted insn is delete
-   at the time the insn is deleted.  At the end of the pass, a call
-   must be made to df_insn_rescan_all.  This method is used by the
-   register allocator since it generally changes each insn multiple
-   times (once for each ref) and does not need to make use of the
-   updated scanning information.
-
-   It is also currently used by two older passes (cse, and regrename)
-   which change insns in hard to track ways.  It is hoped that this
-   will be fixed soon since this it is expensive to rescan all of the
-   insns when only a small number of them have really changed.
+3) Total rescanning - In this mode the rescanning is disabled.
+   Only when insns are deleted is the df information associated with
+   it also deleted.  At the end of the pass, a call must be made to
+   df_insn_rescan_all.  This method is used by the register allocator
+   since it generally changes each insn multiple times (once for each ref)
+   and does not need to make use of the updated scanning information.
 
 4) Do it yourself - In this mechanism, the pass updates the insns
    itself using the low level df primitives.  Currently no pass does
@@ -474,10 +467,10 @@ df_add_problem (struct df_problem *problem)
 /* Set the MASK flags in the DFLOW problem.  The old flags are
    returned.  If a flag is not allowed to be changed this will fail if
    checking is enabled.  */
-enum df_changeable_flags
-df_set_flags (enum df_changeable_flags changeable_flags)
+int
+df_set_flags (int changeable_flags)
 {
-  enum df_changeable_flags old_flags = df->changeable_flags;
+  int old_flags = df->changeable_flags;
   df->changeable_flags |= changeable_flags;
   return old_flags;
 }
@@ -486,10 +479,10 @@ df_set_flags (enum df_changeable_flags changeable_flags)
 /* Clear the MASK flags in the DFLOW problem.  The old flags are
    returned.  If a flag is not allowed to be changed this will fail if
    checking is enabled.  */
-enum df_changeable_flags
-df_clear_flags (enum df_changeable_flags changeable_flags)
+int
+df_clear_flags (int changeable_flags)
 {
-  enum df_changeable_flags old_flags = df->changeable_flags;
+  int old_flags = df->changeable_flags;
   df->changeable_flags &= ~changeable_flags;
   return old_flags;
 }
@@ -766,7 +759,7 @@ struct rtl_opt_pass pass_df_initialize_opt =
   NULL,                                 /* sub */
   NULL,                                 /* next */
   0,                                    /* static_pass_number */
-  0,                                    /* tv_id */
+  TV_NONE,                              /* tv_id */
   0,                                    /* properties_required */
   0,                                    /* properties_provided */
   0,                                    /* properties_destroyed */
@@ -793,7 +786,7 @@ struct rtl_opt_pass pass_df_initialize_no_opt =
   NULL,                                 /* sub */
   NULL,                                 /* next */
   0,                                    /* static_pass_number */
-  0,                                    /* tv_id */
+  TV_NONE,                              /* tv_id */
   0,                                    /* properties_required */
   0,                                    /* properties_provided */
   0,                                    /* properties_destroyed */
@@ -842,7 +835,7 @@ struct rtl_opt_pass pass_df_finish =
   NULL,                                 /* sub */
   NULL,                                 /* next */
   0,                                    /* static_pass_number */
-  0,                                    /* tv_id */
+  TV_NONE,                              /* tv_id */
   0,                                    /* properties_required */
   0,                                    /* properties_provided */
   0,                                    /* properties_destroyed */
@@ -943,47 +936,6 @@ df_worklist_propagate_backward (struct dataflow *dataflow,
 
 
 /* This will free "pending". */
-static void 
-df_worklist_dataflow_overeager (struct dataflow *dataflow,
-                               bitmap pending,
-                                sbitmap considered,
-                                int *blocks_in_postorder,
-                               unsigned *bbindex_to_postorder)
-{
-  enum df_flow_dir dir = dataflow->problem->dir;
-  int count = 0;
-
-  while (!bitmap_empty_p (pending))
-    {
-      unsigned bb_index;
-      int index;
-      count++;
-
-      index = bitmap_first_set_bit (pending);
-      bitmap_clear_bit (pending, index);
-
-      bb_index = blocks_in_postorder[index];
-
-      if (dir == DF_FORWARD)
-       df_worklist_propagate_forward (dataflow, bb_index,
-                                      bbindex_to_postorder,
-                                      pending, considered);
-      else 
-       df_worklist_propagate_backward (dataflow, bb_index,
-                                       bbindex_to_postorder,
-                                       pending, considered);
-    }
-
-  BITMAP_FREE (pending);
-
-  /* Dump statistics. */
-  if (dump_file)
-    fprintf (dump_file, "df_worklist_dataflow_overeager:"
-            "n_basic_blocks %d n_edges %d"
-            " count %d (%5.2g)\n",
-            n_basic_blocks, n_edges,
-            count, count / (float)n_basic_blocks);
-}
 
 static void 
 df_worklist_dataflow_doublequeue (struct dataflow *dataflow,
@@ -1042,23 +994,10 @@ df_worklist_dataflow_doublequeue (struct dataflow *dataflow,
 
 /* Worklist-based dataflow solver. It uses sbitmap as a worklist,
    with "n"-th bit representing the n-th block in the reverse-postorder order. 
-   This is so-called over-eager algorithm where it propagates
-   changes on demand. This algorithm may visit blocks more than
-   iterative method if there are deeply nested loops. 
-   Worklist algorithm works better than iterative algorithm
-   for CFGs with no nested loops.
-   In practice, the measurement shows worklist algorithm beats 
-   iterative algorithm by some margin overall.  
-   Note that this is slightly different from the traditional textbook worklist solver,
-   in that the worklist is effectively sorted by the reverse postorder.
-   For CFGs with no nested loops, this is optimal. 
-   
-   The overeager algorithm while works well for typical inputs,
-   it could degenerate into excessive iterations given CFGs with high loop nests
-   and unstructured loops. To cap the excessive iteration on such case,
-   we switch to double-queueing when the original algorithm seems to 
-   get into such.
-   */
+   The solver is a double-queue algorithm similar to the "double stack" solver
+   from Cooper, Harvey and Kennedy, "Iterative data-flow analysis, Revisited".
+   The only significant difference is that the worklist in this implementation
+   is always sorted in RPO of the CFG visiting direction.  */
 
 void 
 df_worklist_dataflow (struct dataflow *dataflow,
@@ -1103,26 +1042,10 @@ df_worklist_dataflow (struct dataflow *dataflow,
   if (dataflow->problem->init_fun)
     dataflow->problem->init_fun (blocks_to_consider);
 
-  /* Solve it. Determine the solving algorithm
-     based on a simple heuristic. */
-  if (n_edges > PARAM_VALUE (PARAM_DF_DOUBLE_QUEUE_THRESHOLD_FACTOR)
-      * n_basic_blocks)
-    {
-      /* High average connectivity, meaning dense graph
-         with more likely deep nested loops
-        or unstructured loops. */
-      df_worklist_dataflow_doublequeue (dataflow, pending, considered,
-                                       blocks_in_postorder,
-                                       bbindex_to_postorder);
-    }
-  else 
-    {
-      /* Most inputs fall into this case
-        with relatively flat or structured CFG. */
-      df_worklist_dataflow_overeager (dataflow, pending, considered,
-                                     blocks_in_postorder,
-                                     bbindex_to_postorder);
-    }
+  /* Solve it.  */
+  df_worklist_dataflow_doublequeue (dataflow, pending, considered,
+                                   blocks_in_postorder,
+                                   bbindex_to_postorder);
 
   sbitmap_free (considered);
   free (bbindex_to_postorder);
@@ -2197,7 +2120,13 @@ df_ref_debug (df_ref ref, FILE *file)
           DF_REF_FLAGS (ref),
           DF_REF_TYPE (ref));
   if (DF_REF_LOC (ref))
-    fprintf (file, "loc %p(%p) chain ", (void *)DF_REF_LOC (ref), (void *)*DF_REF_LOC (ref));
+    {
+      if (flag_dump_noaddr)
+       fprintf (file, "loc #(#) chain ");
+      else
+       fprintf (file, "loc %p(%p) chain ", (void *)DF_REF_LOC (ref),
+                (void *)*DF_REF_LOC (ref));
+    }
   else
     fprintf (file, "chain ");
   df_chain_dump (DF_REF_CHAIN (ref), file);