-/* See the comment at the top of the Reaching Uses problem for how the
- uses are represented in the kill sets. The same games are played
- here for the defs. */
-
-/* Private data used to compute the solution for this problem. These
- data structures are not accessible outside of this module. */
-struct df_rd_problem_data
-{
- /* The set of defs to regs invalidated by call. */
- bitmap sparse_invalidated_by_call;
- /* The set of defs to regs invalidate by call for rd. */
- bitmap dense_invalidated_by_call;
- /* An obstack for the bitmaps we need for this problem. */
- bitmap_obstack rd_bitmaps;
-};
-
-/* Set basic block info. */
-
-static void
-df_rd_set_bb_info (unsigned int index,
- struct df_rd_bb_info *bb_info)
-{
- gcc_assert (df_rd);
- gcc_assert (index < df_rd->block_info_size);
- df_rd->block_info[index] = bb_info;
-}
-
-
-/* Free basic block info. */
-
-static void
-df_rd_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
- void *vbb_info)
-{
- struct df_rd_bb_info *bb_info = (struct df_rd_bb_info *) vbb_info;
- if (bb_info)
- {
- BITMAP_FREE (bb_info->kill);
- BITMAP_FREE (bb_info->sparse_kill);
- BITMAP_FREE (bb_info->gen);
- BITMAP_FREE (bb_info->in);
- BITMAP_FREE (bb_info->out);
- pool_free (df_rd->block_pool, bb_info);
- }
-}
-
-
-/* Allocate or reset bitmaps for DF_RD blocks. The solution bits are
- not touched unless the block is new. */
-
-static void
-df_rd_alloc (bitmap all_blocks)
-{
- unsigned int bb_index;
- bitmap_iterator bi;
- struct df_rd_problem_data *problem_data;
-
- if (!df_rd->block_pool)
- df_rd->block_pool = create_alloc_pool ("df_rd_block pool",
- sizeof (struct df_rd_bb_info), 50);
-
- if (df_rd->problem_data)
- {
- problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
- bitmap_clear (problem_data->sparse_invalidated_by_call);
- bitmap_clear (problem_data->dense_invalidated_by_call);
- }
- else
- {
- problem_data = XNEW (struct df_rd_problem_data);
- df_rd->problem_data = problem_data;
-
- bitmap_obstack_initialize (&problem_data->rd_bitmaps);
- problem_data->sparse_invalidated_by_call
- = BITMAP_ALLOC (&problem_data->rd_bitmaps);
- problem_data->dense_invalidated_by_call
- = BITMAP_ALLOC (&problem_data->rd_bitmaps);
- }
-
- df_grow_bb_info (df_rd);
-
- /* Because of the clustering of all use sites for the same pseudo,
- we have to process all of the blocks before doing the
- analysis. */
-
- EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
- {
- struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
- if (bb_info)
- {
- bitmap_clear (bb_info->kill);
- bitmap_clear (bb_info->sparse_kill);
- bitmap_clear (bb_info->gen);
- }
- else
- {
- bb_info = (struct df_rd_bb_info *) pool_alloc (df_rd->block_pool);
- df_rd_set_bb_info (bb_index, bb_info);
- bb_info->kill = BITMAP_ALLOC (&problem_data->rd_bitmaps);
- bb_info->sparse_kill = BITMAP_ALLOC (&problem_data->rd_bitmaps);
- bb_info->gen = BITMAP_ALLOC (&problem_data->rd_bitmaps);
- bb_info->in = BITMAP_ALLOC (&problem_data->rd_bitmaps);
- bb_info->out = BITMAP_ALLOC (&problem_data->rd_bitmaps);
- }
- }
- df_rd->optional_p = true;
-}
-
-
-/* Process a list of DEFs for df_rd_bb_local_compute. */
-
-static void
-df_rd_bb_local_compute_process_def (struct df_rd_bb_info *bb_info,
- struct df_ref **def_rec,
- enum df_ref_flags top_flag)
-{
- while (*def_rec)
- {
- struct df_ref *def = *def_rec;
- if (top_flag == (DF_REF_FLAGS (def) & DF_REF_AT_TOP))
- {
- unsigned int regno = DF_REF_REGNO (def);
- unsigned int begin = DF_DEFS_BEGIN (regno);
- unsigned int n_defs = DF_DEFS_COUNT (regno);
-
- if ((!(df->changeable_flags & DF_NO_HARD_REGS))
- || (regno >= FIRST_PSEUDO_REGISTER))
- {
- /* Only the last def(s) for a regno in the block has any
- effect. */
- if (!bitmap_bit_p (seen_in_block, regno))
- {
- /* The first def for regno in insn gets to knock out the
- defs from other instructions. */
- if ((!bitmap_bit_p (seen_in_insn, regno))
- /* If the def is to only part of the reg, it does
- not kill the other defs that reach here. */
- && (!(DF_REF_FLAGS (def) &
- (DF_REF_PARTIAL | DF_REF_CONDITIONAL | DF_REF_MAY_CLOBBER))))
- {
- if (n_defs > DF_SPARSE_THRESHOLD)
- {
- bitmap_set_bit (bb_info->sparse_kill, regno);
- bitmap_clear_range(bb_info->gen, begin, n_defs);
- }
- else
- {
- bitmap_set_range (bb_info->kill, begin, n_defs);
- bitmap_clear_range (bb_info->gen, begin, n_defs);
- }
- }
-
- bitmap_set_bit (seen_in_insn, regno);
- /* All defs for regno in the instruction may be put into
- the gen set. */
- if (!(DF_REF_FLAGS (def)
- & (DF_REF_MUST_CLOBBER | DF_REF_MAY_CLOBBER)))
- bitmap_set_bit (bb_info->gen, DF_REF_ID (def));
- }
- }
- }
- def_rec++;
- }
-}
-
-/* Compute local reaching def info for basic block BB. */
-
-static void
-df_rd_bb_local_compute (unsigned int bb_index)
-{
- basic_block bb = BASIC_BLOCK (bb_index);
- struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
- rtx insn;
-
- bitmap_clear (seen_in_block);
- bitmap_clear (seen_in_insn);
-
- /* Artificials are only hard regs. */
- if (!(df->changeable_flags & DF_NO_HARD_REGS))
- df_rd_bb_local_compute_process_def (bb_info,
- df_get_artificial_defs (bb_index),
- 0);
-
- FOR_BB_INSNS_REVERSE (bb, insn)
- {
- unsigned int uid = INSN_UID (insn);
-
- if (!INSN_P (insn))
- continue;
-
- df_rd_bb_local_compute_process_def (bb_info,
- DF_INSN_UID_DEFS (uid), 0);
-
- /* This complex dance with the two bitmaps is required because
- instructions can assign twice to the same pseudo. This
- generally happens with calls that will have one def for the
- result and another def for the clobber. If only one vector
- is used and the clobber goes first, the result will be
- lost. */
- bitmap_ior_into (seen_in_block, seen_in_insn);
- bitmap_clear (seen_in_insn);
- }
-
- /* Process the artificial defs at the top of the block last since we
- are going backwards through the block and these are logically at
- the start. */
- if (!(df->changeable_flags & DF_NO_HARD_REGS))
- df_rd_bb_local_compute_process_def (bb_info,
- df_get_artificial_defs (bb_index),
- DF_REF_AT_TOP);
-}
-
-
-/* Compute local reaching def info for each basic block within BLOCKS. */
-
-static void
-df_rd_local_compute (bitmap all_blocks)
-{
- unsigned int bb_index;
- bitmap_iterator bi;
- unsigned int regno;
- struct df_rd_problem_data *problem_data
- = (struct df_rd_problem_data *) df_rd->problem_data;
- bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
- bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
-
- df_set_seen ();
-
- df_maybe_reorganize_def_refs (DF_REF_ORDER_BY_REG);
-
- EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
- {
- df_rd_bb_local_compute (bb_index);
- }
-
- /* Set up the knockout bit vectors to be applied across EH_EDGES. */
- EXECUTE_IF_SET_IN_BITMAP (df_invalidated_by_call, 0, regno, bi)
- {
- if (DF_DEFS_COUNT (regno) > DF_SPARSE_THRESHOLD)
- bitmap_set_bit (sparse_invalidated, regno);
- else
- bitmap_set_range (dense_invalidated,
- DF_DEFS_BEGIN (regno),
- DF_DEFS_COUNT (regno));
- }
- df_unset_seen ();
-}
-
-
-/* Initialize the solution bit vectors for problem. */
-
-static void
-df_rd_init_solution (bitmap all_blocks)
-{
- unsigned int bb_index;
- bitmap_iterator bi;
-
- EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
- {
- struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
-
- bitmap_copy (bb_info->out, bb_info->gen);
- bitmap_clear (bb_info->in);
- }
-}
-
-/* In of target gets or of out of source. */
-
-static void
-df_rd_confluence_n (edge e)
-{
- bitmap op1 = df_rd_get_bb_info (e->dest->index)->in;
- bitmap op2 = df_rd_get_bb_info (e->src->index)->out;
-
- if (e->flags & EDGE_EH)
- {
- struct df_rd_problem_data *problem_data
- = (struct df_rd_problem_data *) df_rd->problem_data;
- bitmap sparse_invalidated = problem_data->sparse_invalidated_by_call;
- bitmap dense_invalidated = problem_data->dense_invalidated_by_call;
- bitmap_iterator bi;
- unsigned int regno;
- bitmap tmp = BITMAP_ALLOC (&df_bitmap_obstack);
-
- bitmap_copy (tmp, op2);
- bitmap_and_compl_into (tmp, dense_invalidated);
-
- EXECUTE_IF_SET_IN_BITMAP (sparse_invalidated, 0, regno, bi)
- {
- bitmap_clear_range (tmp,
- DF_DEFS_BEGIN (regno),
- DF_DEFS_COUNT (regno));
- }
- bitmap_ior_into (op1, tmp);
- BITMAP_FREE (tmp);
- }
- else
- bitmap_ior_into (op1, op2);
-}
-
-
-/* Transfer function. */
-
-static bool
-df_rd_transfer_function (int bb_index)
-{
- struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
- unsigned int regno;
- bitmap_iterator bi;
- bitmap in = bb_info->in;
- bitmap out = bb_info->out;
- bitmap gen = bb_info->gen;
- bitmap kill = bb_info->kill;
- bitmap sparse_kill = bb_info->sparse_kill;
-
- if (bitmap_empty_p (sparse_kill))
- return bitmap_ior_and_compl (out, gen, in, kill);
- else
- {
- struct df_rd_problem_data *problem_data;
- bool changed = false;
- bitmap tmp;
-
- /* Note that TMP is _not_ a temporary bitmap if we end up replacing
- OUT with TMP. Therefore, allocate TMP in the RD bitmaps obstack. */
- problem_data = (struct df_rd_problem_data *) df_rd->problem_data;
- tmp = BITMAP_ALLOC (&problem_data->rd_bitmaps);
-
- bitmap_copy (tmp, in);
- EXECUTE_IF_SET_IN_BITMAP (sparse_kill, 0, regno, bi)
- {
- bitmap_clear_range (tmp,
- DF_DEFS_BEGIN (regno),
- DF_DEFS_COUNT (regno));
- }
- bitmap_and_compl_into (tmp, kill);
- bitmap_ior_into (tmp, gen);
- changed = !bitmap_equal_p (tmp, out);
- if (changed)
- {
- BITMAP_FREE (out);
- bb_info->out = tmp;
- }
- else
- BITMAP_FREE (tmp);
- return changed;
- }
-}
-
-
-/* Free all storage associated with the problem. */
-
-static void
-df_rd_free (void)
-{
- unsigned int i;
- struct df_rd_problem_data *problem_data
- = (struct df_rd_problem_data *) df_rd->problem_data;
-
- if (problem_data)
- {
- for (i = 0; i < df_rd->block_info_size; i++)
- {
- struct df_rd_bb_info *bb_info = df_rd_get_bb_info (i);
- if (bb_info)
- {
- BITMAP_FREE (bb_info->kill);
- BITMAP_FREE (bb_info->sparse_kill);
- BITMAP_FREE (bb_info->gen);
- BITMAP_FREE (bb_info->in);
- BITMAP_FREE (bb_info->out);
- }
- }
-
- free_alloc_pool (df_rd->block_pool);
- BITMAP_FREE (problem_data->sparse_invalidated_by_call);
- BITMAP_FREE (problem_data->dense_invalidated_by_call);
- bitmap_obstack_release (&problem_data->rd_bitmaps);
-
- df_rd->block_info_size = 0;
- free (df_rd->block_info);
- free (df_rd->problem_data);
- }
- free (df_rd);
-}
-
-
-/* Debugging info. */
-
-static void
-df_rd_start_dump (FILE *file)
-{
- struct df_rd_problem_data *problem_data
- = (struct df_rd_problem_data *) df_rd->problem_data;
- unsigned int m = DF_REG_SIZE(df);
- unsigned int regno;
-
- if (!df_rd->block_info)
- return;
-
- fprintf (file, ";; Reaching defs:\n\n");
-
- fprintf (file, " sparse invalidated \t");
- dump_bitmap (file, problem_data->sparse_invalidated_by_call);
- fprintf (file, " dense invalidated \t");
- dump_bitmap (file, problem_data->dense_invalidated_by_call);
-
- for (regno = 0; regno < m; regno++)
- if (DF_DEFS_COUNT (regno))
- fprintf (file, "%d[%d,%d] ", regno,
- DF_DEFS_BEGIN (regno),
- DF_DEFS_COUNT (regno));
- fprintf (file, "\n");
-
-}
-
-
-/* Debugging info at top of bb. */
-
-static void
-df_rd_top_dump (basic_block bb, FILE *file)
-{
- struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
- if (!bb_info || !bb_info->in)
- return;
-
- fprintf (file, ";; rd in \t(%d)\n", (int) bitmap_count_bits (bb_info->in));
- dump_bitmap (file, bb_info->in);
- fprintf (file, ";; rd gen \t(%d)\n", (int) bitmap_count_bits (bb_info->gen));
- dump_bitmap (file, bb_info->gen);
- fprintf (file, ";; rd kill\t(%d)\n", (int) bitmap_count_bits (bb_info->kill));
- dump_bitmap (file, bb_info->kill);
-}
-
-
-/* Debugging info at top of bb. */
-
-static void
-df_rd_bottom_dump (basic_block bb, FILE *file)
-{
- struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb->index);
- if (!bb_info || !bb_info->out)
- return;
-
- fprintf (file, ";; rd out \t(%d)\n", (int) bitmap_count_bits (bb_info->out));
- dump_bitmap (file, bb_info->out);
-}
-
-/* All of the information associated with every instance of the problem. */
-
-static struct df_problem problem_RD =
-{
- DF_RD, /* Problem id. */
- DF_FORWARD, /* Direction. */
- df_rd_alloc, /* Allocate the problem specific data. */
- NULL, /* Reset global information. */
- df_rd_free_bb_info, /* Free basic block info. */
- df_rd_local_compute, /* Local compute function. */
- df_rd_init_solution, /* Init the solution specific data. */
- df_worklist_dataflow, /* Worklist solver. */
- NULL, /* Confluence operator 0. */
- df_rd_confluence_n, /* Confluence operator n. */
- df_rd_transfer_function, /* Transfer function. */
- NULL, /* Finalize function. */
- df_rd_free, /* Free all of the problem information. */
- df_rd_free, /* Remove this problem from the stack of dataflow problems. */
- df_rd_start_dump, /* Debugging. */
- df_rd_top_dump, /* Debugging start block. */
- df_rd_bottom_dump, /* Debugging end block. */
- NULL, /* Incremental solution verify start. */
- NULL, /* Incremental solution verfiy end. */
- NULL, /* Dependent problem. */
- TV_DF_RD, /* Timing variable. */
- true /* Reset blocks on dropping out of blocks_to_analyze. */
-};
-
-
-
-/* Create a new DATAFLOW instance and add it to an existing instance
- of DF. The returned structure is what is used to get at the
- solution. */
-
-void
-df_rd_add_problem (void)
-{
- df_add_problem (&problem_RD);
-}
-
-
-\f
-/*----------------------------------------------------------------------------
- LIVE REGISTERS
-
- Find the locations in the function where any use of a pseudo can
- reach in the backwards direction. In and out bitvectors are built
- for each basic block. The regnum is used to index into these sets.
- See df.h for details.
- ----------------------------------------------------------------------------*/
-
-/* Private data used to verify the solution for this problem. */
-struct df_lr_problem_data
-{
- bitmap *in;
- bitmap *out;
-};
-
-
-/* Set basic block info. */
-
-static void
-df_lr_set_bb_info (unsigned int index,
- struct df_lr_bb_info *bb_info)
-{
- gcc_assert (df_lr);
- gcc_assert (index < df_lr->block_info_size);
- df_lr->block_info[index] = bb_info;
-}
-
-
-/* Free basic block info. */
-
-static void
-df_lr_free_bb_info (basic_block bb ATTRIBUTE_UNUSED,
- void *vbb_info)
-{
- struct df_lr_bb_info *bb_info = (struct df_lr_bb_info *) vbb_info;
- if (bb_info)
- {
- BITMAP_FREE (bb_info->use);
- BITMAP_FREE (bb_info->def);
- if (bb_info->in == bb_info->top)
- bb_info->top = NULL;
- else
- {
- BITMAP_FREE (bb_info->top);
- BITMAP_FREE (bb_info->ause);
- BITMAP_FREE (bb_info->adef);
- }
- BITMAP_FREE (bb_info->in);
- BITMAP_FREE (bb_info->out);
- pool_free (df_lr->block_pool, bb_info);
- }
-}
-
-
-/* Allocate or reset bitmaps for DF_LR blocks. The solution bits are
- not touched unless the block is new. */
-
-static void
-df_lr_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
-{
- unsigned int bb_index;
- bitmap_iterator bi;
-
- if (!df_lr->block_pool)
- df_lr->block_pool = create_alloc_pool ("df_lr_block pool",
- sizeof (struct df_lr_bb_info), 50);
-
- df_grow_bb_info (df_lr);
-
- EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
- {
- struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
- if (bb_info)
- {
- bitmap_clear (bb_info->def);
- bitmap_clear (bb_info->use);
- if (bb_info->adef)
- {
- bitmap_clear (bb_info->adef);
- bitmap_clear (bb_info->ause);
- }
- }
- else
- {
- bb_info = (struct df_lr_bb_info *) pool_alloc (df_lr->block_pool);
- df_lr_set_bb_info (bb_index, bb_info);
- bb_info->use = BITMAP_ALLOC (NULL);
- bb_info->def = BITMAP_ALLOC (NULL);
- bb_info->in = BITMAP_ALLOC (NULL);
- bb_info->out = BITMAP_ALLOC (NULL);
- bb_info->top = bb_info->in;
- bb_info->adef = NULL;
- bb_info->ause = NULL;
- }
- }
-
- df_lr->optional_p = false;
-}
-
-
-/* Reset the global solution for recalculation. */
-
-static void
-df_lr_reset (bitmap all_blocks)
-{
- unsigned int bb_index;
- bitmap_iterator bi;
-
- EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
- {
- struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
- gcc_assert (bb_info);
- bitmap_clear (bb_info->in);
- bitmap_clear (bb_info->out);
- bitmap_clear (bb_info->top);
- }
-}
-
-
-/* Compute local live register info for basic block BB. */
-
-static void
-df_lr_bb_local_compute (unsigned int bb_index)
-{
- basic_block bb = BASIC_BLOCK (bb_index);
- struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
- rtx insn;
- struct df_ref **def_rec;
- struct df_ref **use_rec;
-
- /* Process the registers set in an exception handler. */
- for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
- {
- struct df_ref *def = *def_rec;
- if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP) == 0)
- {
- unsigned int dregno = DF_REF_REGNO (def);
- bitmap_set_bit (bb_info->def, dregno);
- bitmap_clear_bit (bb_info->use, dregno);
- }
- }
-
- /* Process the hardware registers that are always live. */
- for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
- {
- struct df_ref *use = *use_rec;
- /* Add use to set of uses in this BB. */
- if ((DF_REF_FLAGS (use) & DF_REF_AT_TOP) == 0)
- bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
- }
-
- FOR_BB_INSNS_REVERSE (bb, insn)
- {
- unsigned int uid = INSN_UID (insn);
-
- if (!INSN_P (insn))
- continue;
-
- if (CALL_P (insn))
- {
- for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
- {
- struct df_ref *def = *def_rec;
- unsigned int dregno = DF_REF_REGNO (def);
-
- if (DF_REF_FLAGS (def) & DF_REF_MUST_CLOBBER)
- {
- if (dregno >= FIRST_PSEUDO_REGISTER
- || !(SIBLING_CALL_P (insn)
- && bitmap_bit_p (df->exit_block_uses, dregno)
- && !refers_to_regno_p (dregno, dregno+1,
- current_function_return_rtx,
- (rtx *)0)))
- {
- /* If the def is to only part of the reg, it does
- not kill the other defs that reach here. */
- if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
- {
- bitmap_set_bit (bb_info->def, dregno);
- bitmap_clear_bit (bb_info->use, dregno);
- }
- }
- }
- else
- /* This is the return value. */
- if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
- {
- bitmap_set_bit (bb_info->def, dregno);
- bitmap_clear_bit (bb_info->use, dregno);
- }
- }
- }
- else
- {
- for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
- {
- struct df_ref *def = *def_rec;
- /* If the def is to only part of the reg, it does
- not kill the other defs that reach here. */
- if (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)))
- {
- unsigned int dregno = DF_REF_REGNO (def);
- bitmap_set_bit (bb_info->def, dregno);
- bitmap_clear_bit (bb_info->use, dregno);
- }
- }
- }
-
- for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
- {
- struct df_ref *use = *use_rec;
- /* Add use to set of uses in this BB. */
- bitmap_set_bit (bb_info->use, DF_REF_REGNO (use));
- }
- }
- /* Process the registers set in an exception handler. */
- for (def_rec = df_get_artificial_defs (bb_index); *def_rec; def_rec++)
- {
- struct df_ref *def = *def_rec;
- if ((DF_REF_FLAGS (def) & DF_REF_AT_TOP)
- && (!(DF_REF_FLAGS (def) & (DF_REF_PARTIAL | DF_REF_CONDITIONAL))))
- {
- unsigned int dregno = DF_REF_REGNO (def);
- if (bb_info->adef == NULL)
- {
- gcc_assert (bb_info->ause == NULL);
- gcc_assert (bb_info->top == bb_info->in);
- bb_info->adef = BITMAP_ALLOC (NULL);
- bb_info->ause = BITMAP_ALLOC (NULL);
- bb_info->top = BITMAP_ALLOC (NULL);
- }
- bitmap_set_bit (bb_info->adef, dregno);
- }
- }
-
-#ifdef EH_USES
- /* Process the uses that are live into an exception handler. */
- for (use_rec = df_get_artificial_uses (bb_index); *use_rec; use_rec++)
- {
- struct df_ref *use = *use_rec;
- /* Add use to set of uses in this BB. */
- if (DF_REF_FLAGS (use) & DF_REF_AT_TOP)
- {
- if (bb_info->adef == NULL)
- {
- gcc_assert (bb_info->ause == NULL);
- gcc_assert (bb_info->top == bb_info->in);
- bb_info->adef = BITMAP_ALLOC (NULL);
- bb_info->ause = BITMAP_ALLOC (NULL);
- bb_info->top = BITMAP_ALLOC (NULL);
- }
- bitmap_set_bit (bb_info->ause, DF_REF_REGNO (use));
- }
- }
-#endif
-
- /* If the df_live problem is not defined, such as at -O0 and -O1, we
- still need to keep the luids up to date. This is normally done
- in the df_live problem since this problem has a forwards
- scan. */
- if (!df_live)
- df_recompute_luids (bb);
-}
-
-
-/* Compute local live register info for each basic block within BLOCKS. */
-
-static void
-df_lr_local_compute (bitmap all_blocks ATTRIBUTE_UNUSED)
-{
- unsigned int bb_index;
- bitmap_iterator bi;
-
- bitmap_clear (df->hardware_regs_used);
-
- /* The all-important stack pointer must always be live. */
- bitmap_set_bit (df->hardware_regs_used, STACK_POINTER_REGNUM);
-
- /* Before reload, there are a few registers that must be forced
- live everywhere -- which might not already be the case for
- blocks within infinite loops. */
- if (!reload_completed)
- {
- /* Any reference to any pseudo before reload is a potential
- reference of the frame pointer. */
- bitmap_set_bit (df->hardware_regs_used, FRAME_POINTER_REGNUM);
-
-#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
- /* Pseudos with argument area equivalences may require
- reloading via the argument pointer. */
- if (fixed_regs[ARG_POINTER_REGNUM])
- bitmap_set_bit (df->hardware_regs_used, ARG_POINTER_REGNUM);
-#endif
-
- /* Any constant, or pseudo with constant equivalences, may
- require reloading from memory using the pic register. */
- if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
- && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
- bitmap_set_bit (df->hardware_regs_used, PIC_OFFSET_TABLE_REGNUM);
- }
-
- EXECUTE_IF_SET_IN_BITMAP (df_lr->out_of_date_transfer_functions, 0, bb_index, bi)
- {
- if (bb_index == EXIT_BLOCK)
- {
- /* The exit block is special for this problem and its bits are
- computed from thin air. */
- struct df_lr_bb_info *bb_info = df_lr_get_bb_info (EXIT_BLOCK);
- bitmap_copy (bb_info->use, df->exit_block_uses);
- }
- else
- df_lr_bb_local_compute (bb_index);
- }
-
- bitmap_clear (df_lr->out_of_date_transfer_functions);
-}
-
-
-/* Initialize the solution vectors. */
-
-static void
-df_lr_init (bitmap all_blocks)
-{
- unsigned int bb_index;
- bitmap_iterator bi;
-
- EXECUTE_IF_SET_IN_BITMAP (all_blocks, 0, bb_index, bi)
- {
- struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
- bitmap_copy (bb_info->in, bb_info->use);
- bitmap_clear (bb_info->out);
- }
-}
-
-
-/* Confluence function that processes infinite loops. This might be a
- noreturn function that throws. And even if it isn't, getting the
- unwind info right helps debugging. */
-static void
-df_lr_confluence_0 (basic_block bb)
-{
- bitmap op1 = df_lr_get_bb_info (bb->index)->out;
- if (bb != EXIT_BLOCK_PTR)
- bitmap_copy (op1, df->hardware_regs_used);
-}
-
-
-/* Confluence function that ignores fake edges. */
-
-static void
-df_lr_confluence_n (edge e)
-{
- bitmap op1 = df_lr_get_bb_info (e->src->index)->out;
- bitmap op2 = df_lr_get_bb_info (e->dest->index)->in;
-
- /* Call-clobbered registers die across exception and call edges. */
- /* ??? Abnormal call edges ignored for the moment, as this gets
- confused by sibling call edges, which crashes reg-stack. */
- if (e->flags & EDGE_EH)
- bitmap_ior_and_compl_into (op1, op2, df_invalidated_by_call);
- else
- bitmap_ior_into (op1, op2);
-
- bitmap_ior_into (op1, df->hardware_regs_used);
-}
-
-
-/* Transfer function. */
-
-static bool
-df_lr_transfer_function (int bb_index)
-{
- struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
- bitmap in = bb_info->in;
- bitmap out = bb_info->out;
- bitmap use = bb_info->use;
- bitmap def = bb_info->def;
- bitmap top = bb_info->top;
- bitmap ause = bb_info->ause;
- bitmap adef = bb_info->adef;
- bool changed;
-
- changed = bitmap_ior_and_compl (top, use, out, def);
- if (in != top)
- {
- gcc_assert (ause && adef);
- changed |= bitmap_ior_and_compl (in, ause, top, adef);
- }
-
- return changed;
-}
-
-
-/* Run the fast dce as a side effect of building LR. */
-
-static void
-df_lr_local_finalize (bitmap all_blocks ATTRIBUTE_UNUSED)
-{
- if (df->changeable_flags & DF_LR_RUN_DCE)
- {
- run_fast_df_dce ();
- if (df_lr->problem_data && df_lr->solutions_dirty)
- {
- /* If we are here, then it is because we are both verifying
- the solution and the dce changed the function. In that case
- the verification info built will be wrong. So we leave the
- dirty flag true so that the verifier will skip the checking
- part and just clean up.*/
- df_lr->solutions_dirty = true;
- }
- else
- df_lr->solutions_dirty = false;
- }
- else
- df_lr->solutions_dirty = false;
-}
-
-
-/* Free all storage associated with the problem. */
-
-static void
-df_lr_free (void)
-{
- if (df_lr->block_info)
- {
- unsigned int i;
- for (i = 0; i < df_lr->block_info_size; i++)
- {
- struct df_lr_bb_info *bb_info = df_lr_get_bb_info (i);
- if (bb_info)
- {
- BITMAP_FREE (bb_info->use);
- BITMAP_FREE (bb_info->def);
- if (bb_info->in == bb_info->top)
- bb_info->top = NULL;
- else
- {
- BITMAP_FREE (bb_info->top);
- BITMAP_FREE (bb_info->ause);
- BITMAP_FREE (bb_info->adef);
- }
- BITMAP_FREE (bb_info->in);
- BITMAP_FREE (bb_info->out);
- }
- }
- free_alloc_pool (df_lr->block_pool);
-
- df_lr->block_info_size = 0;
- free (df_lr->block_info);
- }
-
- BITMAP_FREE (df_lr->out_of_date_transfer_functions);
- free (df_lr);
-}
-
-
-/* Debugging info at top of bb. */
-
-static void
-df_lr_top_dump (basic_block bb, FILE *file)
-{
- struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
- struct df_lr_problem_data *problem_data;
- if (!bb_info || !bb_info->in)
- return;
-
- fprintf (file, ";; lr in \t");
- df_print_regset (file, bb_info->in);
- if (df_lr->problem_data)
- {
- problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
- fprintf (file, ";; old in \t");
- df_print_regset (file, problem_data->in[bb->index]);
- }
- fprintf (file, ";; lr use \t");
- df_print_regset (file, bb_info->use);
- fprintf (file, ";; lr def \t");
- df_print_regset (file, bb_info->def);
-}
-
-
-/* Debugging info at bottom of bb. */
-
-static void
-df_lr_bottom_dump (basic_block bb, FILE *file)
-{
- struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
- struct df_lr_problem_data *problem_data;
- if (!bb_info || !bb_info->out)
- return;
-
- fprintf (file, ";; lr out \t");
- df_print_regset (file, bb_info->out);
- if (df_lr->problem_data)
- {
- problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
- fprintf (file, ";; old out \t");
- df_print_regset (file, problem_data->out[bb->index]);
- }
-}
-
-
-/* Build the datastructure to verify that the solution to the dataflow
- equations is not dirty. */
-
-static void
-df_lr_verify_solution_start (void)
-{
- basic_block bb;
- struct df_lr_problem_data *problem_data;
- if (df_lr->solutions_dirty)
- {
- df_lr->problem_data = NULL;
- return;
- }
-
- /* Set it true so that the solution is recomputed. */
- df_lr->solutions_dirty = true;
-
- problem_data = XNEW (struct df_lr_problem_data);
- df_lr->problem_data = problem_data;
- problem_data->in = XNEWVEC (bitmap, last_basic_block);
- problem_data->out = XNEWVEC (bitmap, last_basic_block);
-
- FOR_ALL_BB (bb)
- {
- problem_data->in[bb->index] = BITMAP_ALLOC (NULL);
- problem_data->out[bb->index] = BITMAP_ALLOC (NULL);
- bitmap_copy (problem_data->in[bb->index], DF_LR_IN (bb));
- bitmap_copy (problem_data->out[bb->index], DF_LR_OUT (bb));
- }
-}
-
-
-/* Compare the saved datastructure and the new solution to the dataflow
- equations. */
-
-static void
-df_lr_verify_solution_end (void)
-{
- struct df_lr_problem_data *problem_data;
- basic_block bb;
-
- if (df_lr->problem_data == NULL)
- return;
-
- problem_data = (struct df_lr_problem_data *)df_lr->problem_data;
-
- if (df_lr->solutions_dirty)
- /* Do not check if the solution is still dirty. See the comment
- in df_lr_local_finalize for details. */
- df_lr->solutions_dirty = false;
- else
- FOR_ALL_BB (bb)
- {
- if ((!bitmap_equal_p (problem_data->in[bb->index], DF_LR_IN (bb)))
- || (!bitmap_equal_p (problem_data->out[bb->index], DF_LR_OUT (bb))))
- {
- /*df_dump (stderr);*/
- gcc_unreachable ();
- }
- }
-
- /* Cannot delete them immediately because you may want to dump them
- if the comparison fails. */
- FOR_ALL_BB (bb)
- {
- BITMAP_FREE (problem_data->in[bb->index]);
- BITMAP_FREE (problem_data->out[bb->index]);
- }
-
- free (problem_data->in);
- free (problem_data->out);
- free (problem_data);
- df_lr->problem_data = NULL;
-}
-
-
-/* All of the information associated with every instance of the problem. */
-
-static struct df_problem problem_LR =
-{
- DF_LR, /* Problem id. */
- DF_BACKWARD, /* Direction. */
- df_lr_alloc, /* Allocate the problem specific data. */
- df_lr_reset, /* Reset global information. */
- df_lr_free_bb_info, /* Free basic block info. */
- df_lr_local_compute, /* Local compute function. */
- df_lr_init, /* Init the solution specific data. */
- df_worklist_dataflow, /* Worklist solver. */
- df_lr_confluence_0, /* Confluence operator 0. */
- df_lr_confluence_n, /* Confluence operator n. */
- df_lr_transfer_function, /* Transfer function. */
- df_lr_local_finalize, /* Finalize function. */
- df_lr_free, /* Free all of the problem information. */
- NULL, /* Remove this problem from the stack of dataflow problems. */
- NULL, /* Debugging. */
- df_lr_top_dump, /* Debugging start block. */
- df_lr_bottom_dump, /* Debugging end block. */
- df_lr_verify_solution_start,/* Incremental solution verify start. */
- df_lr_verify_solution_end, /* Incremental solution verify end. */
- NULL, /* Dependent problem. */
- TV_DF_LR, /* Timing variable. */
- false /* Reset blocks on dropping out of blocks_to_analyze. */
-};
-
-
-/* Create a new DATAFLOW instance and add it to an existing instance
- of DF. The returned structure is what is used to get at the
- solution. */
-
-void
-df_lr_add_problem (void)
-{
- df_add_problem (&problem_LR);
- /* These will be initialized when df_scan_blocks processes each
- block. */
- df_lr->out_of_date_transfer_functions = BITMAP_ALLOC (NULL);
-}
-
-
-/* Verify that all of the lr related info is consistent and
- correct. */
-
-void
-df_lr_verify_transfer_functions (void)
-{
- basic_block bb;
- bitmap saved_def;
- bitmap saved_use;
- bitmap saved_adef;
- bitmap saved_ause;
- bitmap all_blocks;
- bool need_as;
-
- if (!df)
- return;
-
- saved_def = BITMAP_ALLOC (NULL);
- saved_use = BITMAP_ALLOC (NULL);
- saved_adef = BITMAP_ALLOC (NULL);
- saved_ause = BITMAP_ALLOC (NULL);
- all_blocks = BITMAP_ALLOC (NULL);
-
- FOR_ALL_BB (bb)
- {
- struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb->index);
- bitmap_set_bit (all_blocks, bb->index);
-
- if (bb_info)
- {
- /* Make a copy of the transfer functions and then compute
- new ones to see if the transfer functions have
- changed. */
- if (!bitmap_bit_p (df_lr->out_of_date_transfer_functions,
- bb->index))
- {
- bitmap_copy (saved_def, bb_info->def);
- bitmap_copy (saved_use, bb_info->use);
- bitmap_clear (bb_info->def);
- bitmap_clear (bb_info->use);
-
- if (bb_info->adef)
- {
- need_as = true;
- bitmap_copy (saved_adef, bb_info->adef);
- bitmap_copy (saved_ause, bb_info->ause);
- bitmap_clear (bb_info->adef);
- bitmap_clear (bb_info->ause);
- }
- else
- need_as = false;
-
- df_lr_bb_local_compute (bb->index);
- gcc_assert (bitmap_equal_p (saved_def, bb_info->def));
- gcc_assert (bitmap_equal_p (saved_use, bb_info->use));
-
- if (need_as)
- {
- gcc_assert (bb_info->adef);
- gcc_assert (bb_info->ause);
- gcc_assert (bitmap_equal_p (saved_adef, bb_info->adef));
- gcc_assert (bitmap_equal_p (saved_ause, bb_info->ause));
- }
- else
- {
- gcc_assert (!bb_info->adef);
- gcc_assert (!bb_info->ause);
- }
- }
- }
- else
- {
- /* If we do not have basic block info, the block must be in
- the list of dirty blocks or else some one has added a
- block behind our backs. */
- gcc_assert (bitmap_bit_p (df_lr->out_of_date_transfer_functions,
- bb->index));
- }
- /* Make sure no one created a block without following
- procedures. */
- gcc_assert (df_scan_get_bb_info (bb->index));
- }
-
- /* Make sure there are no dirty bits in blocks that have been deleted. */
- gcc_assert (!bitmap_intersect_compl_p (df_lr->out_of_date_transfer_functions,
- all_blocks));
-
- BITMAP_FREE (saved_def);
- BITMAP_FREE (saved_use);
- BITMAP_FREE (saved_adef);
- BITMAP_FREE (saved_ause);
- BITMAP_FREE (all_blocks);
-}
-
-
-\f
-/*----------------------------------------------------------------------------
- COMBINED LIVE REGISTERS AND UNINITIALIZED REGISTERS.
-
- First find the set of uses for registers that are reachable from
- the entry block without passing thru a definition. In and out
- bitvectors are built for each basic block. The regnum is used to
- index into these sets. See df.h for details.
-
- Then the in and out sets here are the anded results of the in and
- out sets from the lr and ur
- problems.
-----------------------------------------------------------------------------*/
-