/* Calculate (post)dominators in slightly super-linear time.
- Copyright (C) 2000, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
- Free Software Foundation, Inc.
+ Copyright (C) 2000-2015 Free Software Foundation, Inc.
Contributed by Michael Matz (matz@ifh.de).
This file is part of GCC.
#include "rtl.h"
#include "hard-reg-set.h"
#include "obstack.h"
+#include "predict.h"
+#include "function.h"
+#include "dominance.h"
+#include "cfg.h"
+#include "cfganal.h"
#include "basic-block.h"
#include "diagnostic-core.h"
+#include "alloc-pool.h"
#include "et-forest.h"
#include "timevar.h"
-#include "pointer-set.h"
#include "graphds.h"
#include "bitmap.h"
init_dom_info (struct dom_info *di, enum cdi_direction dir)
{
/* We need memory for n_basic_blocks nodes. */
- unsigned int num = n_basic_blocks;
+ unsigned int num = n_basic_blocks_for_fn (cfun);
init_ar (di->dfs_parent, TBB, num, 0);
init_ar (di->path_min, TBB, num, i);
init_ar (di->key, TBB, num, i);
init_ar (di->set_size, unsigned int, num, 1);
init_ar (di->set_child, TBB, num, 0);
- init_ar (di->dfs_order, TBB, (unsigned int) last_basic_block + 1, 0);
+ init_ar (di->dfs_order, TBB,
+ (unsigned int) last_basic_block_for_fn (cfun) + 1, 0);
init_ar (di->dfs_to_bb, basic_block, num, 0);
di->dfsnum = 1;
edge_iterator *stack;
edge_iterator ei, einext;
int sp;
- /* Start block (ENTRY_BLOCK_PTR for forward problem, EXIT_BLOCK for backward
+ /* Start block (the entry block for forward problem, exit block for backward
problem). */
basic_block en_block;
/* Ending block. */
basic_block ex_block;
- stack = XNEWVEC (edge_iterator, n_basic_blocks + 1);
+ stack = XNEWVEC (edge_iterator, n_basic_blocks_for_fn (cfun) + 1);
sp = 0;
/* Initialize our border blocks, and the first edge. */
if (reverse)
{
ei = ei_start (bb->preds);
- en_block = EXIT_BLOCK_PTR;
- ex_block = ENTRY_BLOCK_PTR;
+ en_block = EXIT_BLOCK_PTR_FOR_FN (cfun);
+ ex_block = ENTRY_BLOCK_PTR_FOR_FN (cfun);
}
else
{
ei = ei_start (bb->succs);
- en_block = ENTRY_BLOCK_PTR;
- ex_block = EXIT_BLOCK_PTR;
+ en_block = ENTRY_BLOCK_PTR_FOR_FN (cfun);
+ ex_block = EXIT_BLOCK_PTR_FOR_FN (cfun);
}
/* When the stack is empty we break out of this loop. */
if (bb != en_block)
my_i = di->dfs_order[bb->index];
else
- my_i = di->dfs_order[last_basic_block];
+ my_i = di->dfs_order[last_basic_block_for_fn (cfun)];
child_i = di->dfs_order[bn->index] = di->dfsnum++;
di->dfs_to_bb[child_i] = bn;
di->dfs_parent[child_i] = my_i;
calc_dfs_tree (struct dom_info *di, bool reverse)
{
/* The first block is the ENTRY_BLOCK (or EXIT_BLOCK if REVERSE). */
- basic_block begin = reverse ? EXIT_BLOCK_PTR : ENTRY_BLOCK_PTR;
- di->dfs_order[last_basic_block] = di->dfsnum;
+ basic_block begin = (reverse
+ ? EXIT_BLOCK_PTR_FOR_FN (cfun) : ENTRY_BLOCK_PTR_FOR_FN (cfun));
+ di->dfs_order[last_basic_block_for_fn (cfun)] = di->dfsnum;
di->dfs_to_bb[di->dfsnum] = begin;
di->dfsnum++;
basic_block b;
bool saw_unconnected = false;
- FOR_EACH_BB_REVERSE (b)
+ FOR_EACH_BB_REVERSE_FN (b, cfun)
{
if (EDGE_COUNT (b->succs) > 0)
{
bitmap_set_bit (di->fake_exit_edge, b->index);
di->dfs_order[b->index] = di->dfsnum;
di->dfs_to_bb[di->dfsnum] = b;
- di->dfs_parent[di->dfsnum] = di->dfs_order[last_basic_block];
+ di->dfs_parent[di->dfsnum] =
+ di->dfs_order[last_basic_block_for_fn (cfun)];
di->dfsnum++;
calc_dfs_tree_nonrec (di, b, reverse);
}
if (saw_unconnected)
{
- FOR_EACH_BB_REVERSE (b)
+ FOR_EACH_BB_REVERSE_FN (b, cfun)
{
basic_block b2;
if (di->dfs_order[b->index])
bitmap_set_bit (di->fake_exit_edge, b2->index);
di->dfs_order[b2->index] = di->dfsnum;
di->dfs_to_bb[di->dfsnum] = b2;
- di->dfs_parent[di->dfsnum] = di->dfs_order[last_basic_block];
+ di->dfs_parent[di->dfsnum] =
+ di->dfs_order[last_basic_block_for_fn (cfun)];
di->dfsnum++;
calc_dfs_tree_nonrec (di, b2, reverse);
gcc_checking_assert (di->dfs_order[b->index]);
di->nodes = di->dfsnum - 1;
/* This aborts e.g. when there is _no_ path from ENTRY to EXIT at all. */
- gcc_assert (di->nodes == (unsigned int) n_basic_blocks - 1);
+ gcc_assert (di->nodes == (unsigned int) n_basic_blocks_for_fn (cfun) - 1);
}
/* Compress the path from V to the root of its set and update path_min at the
di->path_min[s] = di->path_min[w];
di->set_size[v] += di->set_size[w];
if (di->set_size[v] < 2 * di->set_size[w])
- {
- TBB tmp = s;
- s = di->set_child[v];
- di->set_child[v] = tmp;
- }
+ std::swap (di->set_child[v], s);
/* Merge all subtrees. */
while (s)
edge_iterator ei, einext;
if (reverse)
- en_block = EXIT_BLOCK_PTR;
+ en_block = EXIT_BLOCK_PTR_FOR_FN (cfun);
else
- en_block = ENTRY_BLOCK_PTR;
+ en_block = ENTRY_BLOCK_PTR_FOR_FN (cfun);
/* Go backwards in DFS order, to first look at the leafs. */
v = di->nodes;
if (b == en_block)
{
do_fake_exit_edge:
- k1 = di->dfs_order[last_basic_block];
+ k1 = di->dfs_order[last_basic_block_for_fn (cfun)];
}
else
k1 = di->dfs_order[b->index];
if (dom_computed[dir_index] == DOM_OK)
return;
- FOR_ALL_BB (bb)
+ FOR_ALL_BB_FN (bb, cfun)
{
if (!bb->dom[dir_index]->father)
assign_dfs_numbers (bb->dom[dir_index], &num);
bool reverse = (dir == CDI_POST_DOMINATORS) ? true : false;
if (dom_computed[dir_index] == DOM_OK)
- return;
+ {
+#if ENABLE_CHECKING
+ verify_dominators (dir);
+#endif
+ return;
+ }
timevar_push (TV_DOMINANCE);
if (!dom_info_available_p (dir))
{
gcc_assert (!n_bbs_in_dom_tree[dir_index]);
- FOR_ALL_BB (b)
+ FOR_ALL_BB_FN (b, cfun)
{
b->dom[dir_index] = et_new_tree (b);
}
- n_bbs_in_dom_tree[dir_index] = n_basic_blocks;
+ n_bbs_in_dom_tree[dir_index] = n_basic_blocks_for_fn (cfun);
init_dom_info (&di, dir);
calc_dfs_tree (&di, reverse);
calc_idoms (&di, reverse);
- FOR_EACH_BB (b)
+ FOR_EACH_BB_FN (b, cfun)
{
TBB d = di.dom[di.dfs_order[b->index]];
free_dom_info (&di);
dom_computed[dir_index] = DOM_NO_FAST_QUERY;
}
+ else
+ {
+#if ENABLE_CHECKING
+ verify_dominators (dir);
+#endif
+ }
compute_dom_fast_query (dir);
/* Free dominance information for direction DIR. */
void
-free_dominance_info (enum cdi_direction dir)
+free_dominance_info (function *fn, enum cdi_direction dir)
{
basic_block bb;
unsigned int dir_index = dom_convert_dir_to_idx (dir);
- if (!dom_info_available_p (dir))
+ if (!dom_info_available_p (fn, dir))
return;
- FOR_ALL_BB (bb)
+ FOR_ALL_BB_FN (bb, fn)
{
et_free_tree_force (bb->dom[dir_index]);
bb->dom[dir_index] = NULL;
}
et_free_pools ();
- n_bbs_in_dom_tree[dir_index] = 0;
+ fn->cfg->x_n_bbs_in_dom_tree[dir_index] = 0;
- dom_computed[dir_index] = DOM_NONE;
+ fn->cfg->x_dom_computed[dir_index] = DOM_NONE;
+}
+
+void
+free_dominance_info (enum cdi_direction dir)
+{
+ free_dominance_info (cfun, dir);
}
/* Return the immediate dominator of basic block BB. */
{
unsigned int dir_index = dom_convert_dir_to_idx (dir);
struct et_node *node = bb->dom[dir_index], *son = node->son, *ason;
- vec<basic_block> bbs = vec<basic_block>();
+ vec<basic_block> bbs = vNULL;
gcc_checking_assert (dom_computed[dir_index]);
if (!son)
- return vec<basic_block>();
+ return vNULL;
bbs.safe_push ((basic_block) son->data);
for (ason = son->right; ason != son; ason = ason->right)
{
unsigned i;
basic_block dom;
- vec<basic_block> doms = vec<basic_block>();
+ vec<basic_block> doms = vNULL;
for (i = 0; i < n_region; i++)
region[i]->flags |= BB_DUPLICATED;
vec<basic_block>
get_dominated_to_depth (enum cdi_direction dir, basic_block bb, int depth)
{
- vec<basic_block> bbs = vec<basic_block>();
+ vec<basic_block> bbs = vNULL;
unsigned i;
unsigned next_level_start;
basic_block dom;
first = bitmap_first_set_bit (blocks);
- dom = BASIC_BLOCK (first);
+ dom = BASIC_BLOCK_FOR_FN (cfun, first);
EXECUTE_IF_SET_IN_BITMAP (blocks, 0, i, bi)
- if (dom != BASIC_BLOCK (i))
- dom = nearest_common_dominator (dir, dom, BASIC_BLOCK (i));
+ if (dom != BASIC_BLOCK_FOR_FN (cfun, i))
+ dom = nearest_common_dominator (dir, dom, BASIC_BLOCK_FOR_FN (cfun, i));
return dom;
}
A_Dominated_by_B (node A, node B)
{
- return DFS_Number_In(A) >= DFS_Number_In(A)
+ return DFS_Number_In(A) >= DFS_Number_In(B)
&& DFS_Number_Out (A) <= DFS_Number_Out(B);
} */
calc_dfs_tree (&di, reverse);
calc_idoms (&di, reverse);
- FOR_EACH_BB (bb)
+ FOR_EACH_BB_FN (bb, cfun)
{
imm_bb = get_immediate_dominator (dir, bb);
if (!imm_bb)
for (i = 0; bbs.iterate (i, &bb);)
{
- if (bb == ENTRY_BLOCK_PTR)
+ if (bb == ENTRY_BLOCK_PTR_FOR_FN (cfun))
goto succeed;
if (single_pred_p (bb))
if (son[y] == -1)
return;
if (y == (int) bbs.length ())
- ybb = ENTRY_BLOCK_PTR;
+ ybb = ENTRY_BLOCK_PTR_FOR_FN (cfun);
else
ybb = bbs[y];
size_t dom_i;
edge e;
edge_iterator ei;
- struct pointer_map_t *map;
int *parent, *son, *brother;
unsigned int dir_index = dom_convert_dir_to_idx (dir);
}
/* Construct the graph G. */
- map = pointer_map_create ();
+ hash_map<basic_block, int> map (251);
FOR_EACH_VEC_ELT (bbs, i, bb)
{
/* If the dominance tree is conservatively correct, split it now. */
if (conservative)
set_immediate_dominator (CDI_DOMINATORS, bb, NULL);
- *pointer_map_insert (map, bb) = (void *) (size_t) i;
+ map.put (bb, i);
}
- *pointer_map_insert (map, ENTRY_BLOCK_PTR) = (void *) (size_t) n;
+ map.put (ENTRY_BLOCK_PTR_FOR_FN (cfun), n);
g = new_graph (n + 1);
for (y = 0; y < g->n_vertices; y++)
if (dom == bb)
continue;
- dom_i = (size_t) *pointer_map_contains (map, dom);
+ dom_i = *map.get (dom);
/* Do not include parallel edges to G. */
if (!bitmap_set_bit ((bitmap) g->vertices[dom_i].data, i))
}
for (y = 0; y < g->n_vertices; y++)
BITMAP_FREE (g->vertices[y].data);
- pointer_map_destroy (map);
/* Find the dominator tree of G. */
son = XNEWVEC (int, n + 1);
/* Return dominance availability for dominance info DIR. */
enum dom_state
-dom_info_state (enum cdi_direction dir)
+dom_info_state (function *fn, enum cdi_direction dir)
{
+ if (!fn->cfg)
+ return DOM_NONE;
+
unsigned int dir_index = dom_convert_dir_to_idx (dir);
+ return fn->cfg->x_dom_computed[dir_index];
+}
- return dom_computed[dir_index];
+enum dom_state
+dom_info_state (enum cdi_direction dir)
+{
+ return dom_info_state (cfun, dir);
}
/* Set the dominance availability for dominance info DIR to NEW_STATE. */
/* Returns true if dominance information for direction DIR is available. */
bool
-dom_info_available_p (enum cdi_direction dir)
+dom_info_available_p (function *fn, enum cdi_direction dir)
{
- unsigned int dir_index = dom_convert_dir_to_idx (dir);
+ return dom_info_state (fn, dir) != DOM_NONE;
+}
- return dom_computed[dir_index] != DOM_NONE;
+bool
+dom_info_available_p (enum cdi_direction dir)
+{
+ return dom_info_available_p (cfun, dir);
}
DEBUG_FUNCTION void
debug_dominance_info (enum cdi_direction dir)
{
basic_block bb, bb2;
- FOR_EACH_BB (bb)
+ FOR_EACH_BB_FN (bb, cfun)
if ((bb2 = get_immediate_dominator (dir, bb)))
fprintf (stderr, "%i %i\n", bb->index, bb2->index);
}