+
+void
+debug_bb (basic_block bb)
+{
+ dump_bb (bb, stderr, 0);
+}
+
+basic_block
+debug_bb_n (int n)
+{
+ basic_block bb = BASIC_BLOCK (n);
+ dump_bb (bb, stderr, 0);
+ return bb;
+}
+
+/* Dumps cfg related information about basic block BB to FILE. */
+
+static void
+dump_cfg_bb_info (FILE *file, basic_block bb)
+{
+ unsigned i;
+ edge_iterator ei;
+ bool first = true;
+ static const char * const bb_bitnames[] =
+ {
+ "dirty", "new", "reachable", "visited", "irreducible_loop", "superblock"
+ };
+ const unsigned n_bitnames = sizeof (bb_bitnames) / sizeof (char *);
+ edge e;
+
+ fprintf (file, "Basic block %d", bb->index);
+ for (i = 0; i < n_bitnames; i++)
+ if (bb->flags & (1 << i))
+ {
+ if (first)
+ fprintf (file, " (");
+ else
+ fprintf (file, ", ");
+ first = false;
+ fprintf (file, bb_bitnames[i]);
+ }
+ if (!first)
+ fprintf (file, ")");
+ fprintf (file, "\n");
+
+ fprintf (file, "Predecessors: ");
+ FOR_EACH_EDGE (e, ei, bb->preds)
+ dump_edge_info (file, e, 0);
+
+ fprintf (file, "\nSuccessors: ");
+ FOR_EACH_EDGE (e, ei, bb->succs)
+ dump_edge_info (file, e, 1);
+ fprintf (file, "\n\n");
+}
+
+/* Dumps a brief description of cfg to FILE. */
+
+void
+brief_dump_cfg (FILE *file)
+{
+ basic_block bb;
+
+ FOR_EACH_BB (bb)
+ {
+ dump_cfg_bb_info (file, bb);
+ }
+}
+
+/* An edge originally destinating BB of FREQUENCY and COUNT has been proved to
+ leave the block by TAKEN_EDGE. Update profile of BB such that edge E can be
+ redirected to destination of TAKEN_EDGE.
+
+ This function may leave the profile inconsistent in the case TAKEN_EDGE
+ frequency or count is believed to be lower than FREQUENCY or COUNT
+ respectively. */
+void
+update_bb_profile_for_threading (basic_block bb, int edge_frequency,
+ gcov_type count, edge taken_edge)
+{
+ edge c;
+ int prob;
+ edge_iterator ei;
+
+ bb->count -= count;
+ if (bb->count < 0)
+ bb->count = 0;
+
+ /* Compute the probability of TAKEN_EDGE being reached via threaded edge.
+ Watch for overflows. */
+ if (bb->frequency)
+ prob = edge_frequency * REG_BR_PROB_BASE / bb->frequency;
+ else
+ prob = 0;
+ if (prob > taken_edge->probability)
+ {
+ if (dump_file)
+ fprintf (dump_file, "Jump threading proved probability of edge "
+ "%i->%i too small (it is %i, should be %i).\n",
+ taken_edge->src->index, taken_edge->dest->index,
+ taken_edge->probability, prob);
+ prob = taken_edge->probability;
+ }
+
+ /* Now rescale the probabilities. */
+ taken_edge->probability -= prob;
+ prob = REG_BR_PROB_BASE - prob;
+ bb->frequency -= edge_frequency;
+ if (bb->frequency < 0)
+ bb->frequency = 0;
+ if (prob <= 0)
+ {
+ if (dump_file)
+ fprintf (dump_file, "Edge frequencies of bb %i has been reset, "
+ "frequency of block should end up being 0, it is %i\n",
+ bb->index, bb->frequency);
+ EDGE_SUCC (bb, 0)->probability = REG_BR_PROB_BASE;
+ ei = ei_start (bb->succs);
+ ei_next (&ei);
+ for (; (c = ei_safe_edge (ei)); ei_next (&ei))
+ c->probability = 0;
+ }
+ else
+ FOR_EACH_EDGE (c, ei, bb->succs)
+ c->probability = ((c->probability * REG_BR_PROB_BASE) / (double) prob);
+
+ if (bb != taken_edge->src)
+ abort ();
+ taken_edge->count -= count;
+ if (taken_edge->count < 0)
+ taken_edge->count = 0;
+}