/* Allocation for dataflow support routines.
Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
- 2008, 2009, 2010 Free Software Foundation, Inc.
+ 2008, 2009, 2010, 2011 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)
Functions to create, destroy and manipulate an instance of df.
----------------------------------------------------------------------------*/
-struct df *df;
+struct df_d *df;
/* Add PROBLEM (and any dependent problems) to the DF instance. */
rest_of_handle_df_initialize (void)
{
gcc_assert (!df);
- df = XCNEW (struct df);
+ df = XCNEW (struct df_d);
df->changeable_flags = 0;
bitmap_obstack_initialize (&df_bitmap_obstack);
NULL, /* sub */
NULL, /* next */
0, /* static_pass_number */
- TV_NONE, /* tv_id */
+ TV_DF_SCAN, /* tv_id */
0, /* properties_required */
0, /* properties_provided */
0, /* properties_destroyed */
NULL, /* sub */
NULL, /* next */
0, /* static_pass_number */
- TV_NONE, /* tv_id */
+ TV_DF_SCAN, /* tv_id */
0, /* properties_required */
0, /* properties_provided */
0, /* properties_destroyed */
dflow->problem->free_fun ();
}
- if (df->postorder)
- free (df->postorder);
- if (df->postorder_inverted)
- free (df->postorder_inverted);
+ free (df->postorder);
+ free (df->postorder_inverted);
free (df->hard_regs_live_count);
free (df);
df = NULL;
The general data flow analysis engine.
----------------------------------------------------------------------------*/
+/* Return time BB when it was visited for last time. */
+#define BB_LAST_CHANGE_AGE(bb) ((ptrdiff_t)(bb)->aux)
/* Helper function for df_worklist_dataflow.
Propagate the dataflow forward.
Given a BB_INDEX, do the dataflow propagation
and set bits on for successors in PENDING
- if the out set of the dataflow has changed. */
+ if the out set of the dataflow has changed.
+
+ AGE specify time when BB was visited last time.
+ AGE of 0 means we are visiting for first time and need to
+ compute transfer function to initialize datastructures.
+ Otherwise we re-do transfer function only if something change
+ while computing confluence functions.
+ We need to compute confluence only of basic block that are younger
+ then last visit of the BB.
+
+ Return true if BB info has changed. This is always the case
+ in the first visit. */
static bool
df_worklist_propagate_forward (struct dataflow *dataflow,
unsigned *bbindex_to_postorder,
bitmap pending,
sbitmap considered,
- size_t age)
+ ptrdiff_t age)
{
edge e;
edge_iterator ei;
if (EDGE_COUNT (bb->preds) > 0)
FOR_EACH_EDGE (e, ei, bb->preds)
{
- if ((age <= (size_t)e->src->aux)
- && TEST_BIT (considered, e->src->index))
+ if (age <= BB_LAST_CHANGE_AGE (e->src)
+ && TEST_BIT (considered, e->src->index))
changed |= dataflow->problem->con_fun_n (e);
}
else if (dataflow->problem->con_fun_0)
- {
- dataflow->problem->con_fun_0 (bb);
- changed = true;
- }
+ dataflow->problem->con_fun_0 (bb);
if (changed
&& dataflow->problem->trans_fun (bb_index))
unsigned *bbindex_to_postorder,
bitmap pending,
sbitmap considered,
- size_t age)
+ ptrdiff_t age)
{
edge e;
edge_iterator ei;
if (EDGE_COUNT (bb->succs) > 0)
FOR_EACH_EDGE (e, ei, bb->succs)
{
- if ((age <= (size_t)e->dest->aux)
- && TEST_BIT (considered, e->dest->index))
+ if (age <= BB_LAST_CHANGE_AGE (e->dest)
+ && TEST_BIT (considered, e->dest->index))
changed |= dataflow->problem->con_fun_n (e);
}
else if (dataflow->problem->con_fun_0)
- {
- dataflow->problem->con_fun_0 (bb);
- changed = true;
- }
+ dataflow->problem->con_fun_0 (bb);
if (changed
&& dataflow->problem->trans_fun (bb_index))
return false;
}
-DEF_VEC_I(size_t);
-DEF_VEC_ALLOC_I(size_t,heap);
+/* Main dataflow solver loop.
+
+ DATAFLOW is problem we are solving, PENDING is worklist of basic blocks we
+ need to visit.
+ BLOCK_IN_POSTORDER is array of size N_BLOCKS specifying postorder in BBs and
+ BBINDEX_TO_POSTORDER is array mapping back BB->index to postorder possition.
+ PENDING will be freed.
-/* This will free "pending". */
+ The worklists are bitmaps indexed by postorder positions.
+
+ The function implements standard algorithm for dataflow solving with two
+ worklists (we are processing WORKLIST and storing new BBs to visit in
+ PENDING).
+
+ As an optimization we maintain ages when BB was changed (stored in bb->aux)
+ and when it was last visited (stored in last_visit_age). This avoids need
+ to re-do confluence function for edges to basic blocks whose source
+ did not change since destination was visited last time. */
static void
df_worklist_dataflow_doublequeue (struct dataflow *dataflow,
enum df_flow_dir dir = dataflow->problem->dir;
int dcount = 0;
bitmap worklist = BITMAP_ALLOC (&df_bitmap_obstack);
- size_t age = 0;
+ int age = 0;
bool changed;
- VEC(size_t, heap) *last_age = NULL;
- size_t prev_age;
+ VEC(int, heap) *last_visit_age = NULL;
+ int prev_age;
basic_block bb;
int i;
- VEC_safe_grow_cleared (size_t, heap, last_age, n_blocks);
+ VEC_safe_grow_cleared (int, heap, last_visit_age, n_blocks);
/* Double-queueing. Worklist is for the current iteration,
and pending is for the next. */
unsigned bb_index;
dcount++;
+ bitmap_clear_bit (pending, index);
bb_index = blocks_in_postorder[index];
bb = BASIC_BLOCK (bb_index);
- prev_age = VEC_index (size_t, last_age, index);
+ prev_age = VEC_index (int, last_visit_age, index);
if (dir == DF_FORWARD)
changed = df_worklist_propagate_forward (dataflow, bb_index,
bbindex_to_postorder,
bbindex_to_postorder,
pending, considered,
prev_age);
- age++;
+ VEC_replace (int, last_visit_age, index, ++age);
if (changed)
- bb->aux = (void *)age;
- VEC_replace (size_t, last_age, index, age);
- age++;
+ bb->aux = (void *)(ptrdiff_t)age;
}
bitmap_clear (worklist);
}
BITMAP_FREE (worklist);
BITMAP_FREE (pending);
- VEC_free (size_t, heap, last_age);
+ VEC_free (int, heap, last_visit_age);
/* Dump statistics. */
if (dump_file)
bool everything;
int i;
- if (df->postorder)
- free (df->postorder);
- if (df->postorder_inverted)
- free (df->postorder_inverted);
+ free (df->postorder);
+ free (df->postorder_inverted);
df->postorder = XNEWVEC (int, last_basic_block);
df->postorder_inverted = XNEWVEC (int, last_basic_block);
df->n_blocks = post_order_compute (df->postorder, true, true);
bool
df_get_bb_dirty (basic_block bb)
{
- if (df && df_live)
- return bitmap_bit_p (df_live->out_of_date_transfer_functions, bb->index);
- else
- return false;
+ return bitmap_bit_p ((df_live
+ ? df_live : df_lr)->out_of_date_transfer_functions,
+ bb->index);
}
void
df_set_bb_dirty (basic_block bb)
{
+ bb->flags |= BB_MODIFIED;
if (df)
{
int p;
}
-/* Mark BB as needing it's transfer functions as being out of
- date, except for LR problem. Used when analyzing DEBUG_INSNs,
- as LR problem can trigger DCE, and DEBUG_INSNs shouldn't ever
- shorten or enlarge lifetime of regs. */
-
-void
-df_set_bb_dirty_nonlr (basic_block bb)
-{
- if (df)
- {
- int p;
- for (p = 1; p < df->num_problems_defined; p++)
- {
- struct dataflow *dflow = df->problems_in_order[p];
- if (dflow == df_lr)
- continue;
- if (dflow->out_of_date_transfer_functions)
- bitmap_set_bit (dflow->out_of_date_transfer_functions, bb->index);
- dflow->solutions_dirty = true;
- }
- }
-}
-
/* Grow the bb_info array. */
void
static void
df_set_clean_cfg (void)
{
- if (saved_cfg)
- free (saved_cfg);
+ free (saved_cfg);
saved_cfg = df_compute_cfg_image ();
}
debugging dump. */
void
-df_print_byte_regset (FILE *file, bitmap r)
+df_print_word_regset (FILE *file, bitmap r)
{
unsigned int max_reg = max_reg_num ();
- bitmap_iterator bi;
if (r == NULL)
fputs (" (nil)", file);
else
{
unsigned int i;
- for (i = 0; i < max_reg; i++)
+ for (i = FIRST_PSEUDO_REGISTER; i < max_reg; i++)
{
- unsigned int first = df_byte_lr_get_regno_start (i);
- unsigned int len = df_byte_lr_get_regno_len (i);
-
- if (len > 1)
+ bool found = (bitmap_bit_p (r, 2 * i)
+ || bitmap_bit_p (r, 2 * i + 1));
+ if (found)
{
- bool found = false;
- unsigned int j;
-
- EXECUTE_IF_SET_IN_BITMAP (r, first, j, bi)
- {
- found = j < first + len;
- break;
- }
- if (found)
- {
- const char * sep = "";
- fprintf (file, " %d", i);
- if (i < FIRST_PSEUDO_REGISTER)
- fprintf (file, " [%s]", reg_names[i]);
- fprintf (file, "(");
- EXECUTE_IF_SET_IN_BITMAP (r, first, j, bi)
- {
- if (j > first + len - 1)
- break;
- fprintf (file, "%s%d", sep, j-first);
- sep = ", ";
- }
- fprintf (file, ")");
- }
- }
- else
- {
- if (bitmap_bit_p (r, first))
- {
- fprintf (file, " %d", i);
- if (i < FIRST_PSEUDO_REGISTER)
- fprintf (file, " [%s]", reg_names[i]);
- }
+ int word;
+ const char * sep = "";
+ fprintf (file, " %d", i);
+ fprintf (file, "(");
+ for (word = 0; word < 2; word++)
+ if (bitmap_bit_p (r, 2 * i + word))
+ {
+ fprintf (file, "%s%d", sep, word);
+ sep = ", ";
+ }
+ fprintf (file, ")");
}
-
}
}
fprintf (file, "\n");
}
+static void
+df_ref_dump (df_ref ref, FILE *file)
+{
+ fprintf (file, "%c%d(%d)",
+ DF_REF_REG_DEF_P (ref)
+ ? 'd'
+ : (DF_REF_FLAGS (ref) & DF_REF_IN_NOTE) ? 'e' : 'u',
+ DF_REF_ID (ref),
+ DF_REF_REGNO (ref));
+}
+
void
df_refs_chain_dump (df_ref *ref_rec, bool follow_chain, FILE *file)
{
while (*ref_rec)
{
df_ref ref = *ref_rec;
- fprintf (file, "%c%d(%d)",
- DF_REF_REG_DEF_P (ref) ? 'd' : (DF_REF_FLAGS (ref) & DF_REF_IN_NOTE) ? 'e' : 'u',
- DF_REF_ID (ref),
- DF_REF_REGNO (ref));
+ df_ref_dump (ref, file);
if (follow_chain)
df_chain_dump (DF_REF_CHAIN (ref), file);
ref_rec++;
fprintf (file, "{ ");
while (ref)
{
- fprintf (file, "%c%d(%d) ",
- DF_REF_REG_DEF_P (ref) ? 'd' : 'u',
- DF_REF_ID (ref),
- DF_REF_REGNO (ref));
+ df_ref_dump (ref, file);
ref = DF_REF_NEXT_REG (ref);
}
fprintf (file, "}");