/* Control flow graph analysis code for GNU compiler.
- Copyright (C) 1987-2015 Free Software Foundation, Inc.
+ Copyright (C) 1987-2016 Free Software Foundation, Inc.
This file is part of GCC.
#include "config.h"
#include "system.h"
#include "coretypes.h"
-#include "predict.h"
-#include "tm.h"
-#include "hard-reg-set.h"
-#include "input.h"
-#include "function.h"
-#include "dominance.h"
-#include "cfg.h"
-#include "cfganal.h"
-#include "basic-block.h"
-#include "bitmap.h"
-#include "sbitmap.h"
+#include "backend.h"
+#include "cfghooks.h"
#include "timevar.h"
+#include "cfganal.h"
/* Store the data structures necessary for depth-first search. */
-struct depth_first_search_dsS {
+struct depth_first_search_ds {
/* stack for backtracking during the algorithm */
basic_block *stack;
/* record of basic blocks already seen by depth-first search */
sbitmap visited_blocks;
};
-typedef struct depth_first_search_dsS *depth_first_search_ds;
-static void flow_dfs_compute_reverse_init (depth_first_search_ds);
-static void flow_dfs_compute_reverse_add_bb (depth_first_search_ds,
+static void flow_dfs_compute_reverse_init (depth_first_search_ds *);
+static void flow_dfs_compute_reverse_add_bb (depth_first_search_ds *,
basic_block);
-static basic_block flow_dfs_compute_reverse_execute (depth_first_search_ds,
+static basic_block flow_dfs_compute_reverse_execute (depth_first_search_ds *,
basic_block);
-static void flow_dfs_compute_reverse_finish (depth_first_search_ds);
+static void flow_dfs_compute_reverse_finish (depth_first_search_ds *);
\f
/* Mark the back edges in DFS traversal.
Return nonzero if a loop (natural or otherwise) is present.
free (worklist);
}
+
+/* Verify that there are no unreachable blocks in the current function. */
+
+void
+verify_no_unreachable_blocks (void)
+{
+ find_unreachable_blocks ();
+
+ basic_block bb;
+ FOR_EACH_BB_FN (bb, cfun)
+ gcc_assert ((bb->flags & BB_REACHABLE) != 0);
+}
+
\f
/* Functions to access an edge list with a vector representation.
Enough data is kept such that given an index number, the
{
basic_block unvisited_block = EXIT_BLOCK_PTR_FOR_FN (cfun);
basic_block deadend_block;
- struct depth_first_search_dsS dfs_ds;
+ depth_first_search_ds dfs_ds;
/* Perform depth-first search in the reverse graph to find nodes
reachable from the exit block. */
(from successors to predecessors).
This ordering can be used for forward dataflow problems among others.
+ Optionally if START_POINTS is specified, start from exit block and all
+ basic blocks in START_POINTS. This is used by CD-DCE.
+
This function assumes that all blocks in the CFG are reachable
from the ENTRY (but not necessarily from EXIT).
and do another inverted traversal from that block. */
int
-inverted_post_order_compute (int *post_order)
+inverted_post_order_compute (int *post_order,
+ sbitmap *start_points)
{
basic_block bb;
edge_iterator *stack;
int post_order_num = 0;
sbitmap visited;
+ if (flag_checking)
+ verify_no_unreachable_blocks ();
+
/* Allocate stack for back-tracking up CFG. */
stack = XNEWVEC (edge_iterator, n_basic_blocks_for_fn (cfun) + 1);
sp = 0;
/* None of the nodes in the CFG have been visited yet. */
bitmap_clear (visited);
+ if (start_points)
+ {
+ FOR_ALL_BB_FN (bb, cfun)
+ if (bitmap_bit_p (*start_points, bb->index)
+ && EDGE_COUNT (bb->preds) > 0)
+ {
+ stack[sp++] = ei_start (bb->preds);
+ bitmap_set_bit (visited, bb->index);
+ }
+ if (EDGE_COUNT (EXIT_BLOCK_PTR_FOR_FN (cfun)->preds))
+ {
+ stack[sp++] = ei_start (EXIT_BLOCK_PTR_FOR_FN (cfun)->preds);
+ bitmap_set_bit (visited, EXIT_BLOCK_PTR_FOR_FN (cfun)->index);
+ }
+ }
+ else
/* Put all blocks that have no successor into the initial work list. */
FOR_ALL_BB_FN (bb, cfun)
if (EDGE_COUNT (bb->succs) == 0)
pre_order[pre_order_num] = ENTRY_BLOCK;
pre_order_num++;
if (rev_post_order)
- rev_post_order[rev_post_order_num--] = ENTRY_BLOCK;
+ rev_post_order[rev_post_order_num--] = EXIT_BLOCK;
}
else
rev_post_order_num -= NUM_FIXED_BLOCKS;
pre_order[pre_order_num] = EXIT_BLOCK;
pre_order_num++;
if (rev_post_order)
- rev_post_order[rev_post_order_num--] = EXIT_BLOCK;
+ rev_post_order[rev_post_order_num--] = ENTRY_BLOCK;
}
return pre_order_num;
element on the stack. */
static void
-flow_dfs_compute_reverse_init (depth_first_search_ds data)
+flow_dfs_compute_reverse_init (depth_first_search_ds *data)
{
/* Allocate stack for back-tracking up CFG. */
data->stack = XNEWVEC (basic_block, n_basic_blocks_for_fn (cfun));
block. */
static void
-flow_dfs_compute_reverse_add_bb (depth_first_search_ds data, basic_block bb)
+flow_dfs_compute_reverse_add_bb (depth_first_search_ds *data, basic_block bb)
{
data->stack[data->sp++] = bb;
bitmap_set_bit (data->visited_blocks, bb->index);
available. */
static basic_block
-flow_dfs_compute_reverse_execute (depth_first_search_ds data,
+flow_dfs_compute_reverse_execute (depth_first_search_ds *data,
basic_block last_unvisited)
{
basic_block bb;
reverse graph. */
static void
-flow_dfs_compute_reverse_finish (depth_first_search_ds data)
+flow_dfs_compute_reverse_finish (depth_first_search_ds *data)
{
free (data->stack);
sbitmap_free (data->visited_blocks);