GCC Middle and Back End API Reference
dominance.c File Reference

Data Structures

struct  dom_info

Typedefs

typedef unsigned int TBB

Functions

static void init_dom_info (struct dom_info *, enum cdi_direction)
static void free_dom_info (struct dom_info *)
static void calc_dfs_tree_nonrec (struct dom_info *, basic_block, bool)
static void calc_dfs_tree (struct dom_info *, bool)
static void compress (struct dom_info *, TBB)
static TBB eval (struct dom_info *, TBB)
static void link_roots (struct dom_info *, TBB, TBB)
static void calc_idoms (struct dom_info *, bool)
void debug_dominance_info (enum cdi_direction)
void debug_dominance_tree (enum cdi_direction, basic_block)
static void init_dom_info ()
static unsigned int dom_convert_dir_to_idx ()
static void free_dom_info ()
static void calc_dfs_tree_nonrec ()
static void calc_dfs_tree ()
static void compress ()
static TBB eval ()
static void link_roots ()
static void calc_idoms ()
static void assign_dfs_numbers ()
static void compute_dom_fast_query ()
void calculate_dominance_info ()
void free_dominance_info ()
basic_block get_immediate_dominator ()
void set_immediate_dominator (enum cdi_direction dir, basic_block bb, basic_block dominated_by)
vec< basic_blockget_dominated_by ()
vec< basic_blockget_dominated_by_region (enum cdi_direction dir, basic_block *region, unsigned n_region)
vec< basic_blockget_dominated_to_depth ()
vec< basic_blockget_all_dominated_blocks ()
void redirect_immediate_dominators (enum cdi_direction dir, basic_block bb, basic_block to)
basic_block nearest_common_dominator ()
basic_block nearest_common_dominator_for_set ()
bool dominated_by_p ()
unsigned bb_dom_dfs_in ()
unsigned bb_dom_dfs_out ()
DEBUG_FUNCTION void verify_dominators ()
basic_block recompute_dominator ()
static void prune_bbs_to_update_dominators (vec< basic_block > bbs, bool conservative)
static basic_block root_of_dom_tree ()
static void determine_dominators_for_sons (struct graph *g, vec< basic_block > bbs, int y, int *son, int *brother)
void iterate_fix_dominators (enum cdi_direction dir, vec< basic_block > bbs, bool conservative)
void add_to_dominance_info ()
void delete_from_dominance_info ()
basic_block first_dom_son ()
basic_block next_dom_son ()
enum dom_state dom_info_state ()
void set_dom_info_availability ()
bool dom_info_available_p ()
DEBUG_FUNCTION void debug_dominance_info ()
static void debug_dominance_tree_1 (enum cdi_direction dir, basic_block root, unsigned indent, bool indent_first)
DEBUG_FUNCTION void debug_dominance_tree ()

Typedef Documentation

typedef unsigned int TBB
Calculate (post)dominators in slightly super-linear time.
   Copyright (C) 2000-2013 Free Software Foundation, Inc.
   Contributed by Michael Matz (matz@ifh.de).

   This file is part of GCC.

   GCC is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   GCC is distributed in the hope that it will be useful, but WITHOUT
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
   License for more details.

   You should have received a copy of the GNU General Public License
   along with GCC; see the file COPYING3.  If not see
   <http://www.gnu.org/licenses/>.   
This file implements the well known algorithm from Lengauer and Tarjan
   to compute the dominators in a control flow graph.  A basic block D is said
   to dominate another block X, when all paths from the entry node of the CFG
   to X go also over D.  The dominance relation is a transitive reflexive
   relation and its minimal transitive reduction is a tree, called the
   dominator tree.  So for each block X besides the entry block exists a
   block I(X), called the immediate dominator of X, which is the parent of X
   in the dominator tree.

   The algorithm computes this dominator tree implicitly by computing for
   each block its immediate dominator.  We use tree balancing and path
   compression, so it's the O(e*a(e,v)) variant, where a(e,v) is the very
   slowly growing functional inverse of the Ackerman function.   
We name our nodes with integers, beginning with 1.  Zero is reserved for
   'undefined' or 'end of list'.  The name of each node is given by the dfs
   number of the corresponding basic block.  Please note, that we include the
   artificial ENTRY_BLOCK (or EXIT_BLOCK in the post-dom case) in our lists to
   support multiple entry points.  Its dfs number is of course 1.   
Type of Basic Block aka. TBB  

Function Documentation

void add_to_dominance_info ( )
static void assign_dfs_numbers ( )
static
Assign dfs numbers starting from NUM to NODE and its sons.   

References et_node::dfs_num_in, et_node::dfs_num_out, et_node::right, and et_node::son.

Referenced by compute_dom_fast_query().

unsigned bb_dom_dfs_in ( )
Returns the entry dfs number for basic block BB, in the direction DIR.   

References et_node::dfs_num_in, basic_block_def::dom, dom_convert_dir_to_idx(), and DOM_OK.

unsigned bb_dom_dfs_out ( )
Returns the exit dfs number for basic block BB, in the direction DIR.   

References et_node::dfs_num_out, basic_block_def::dom, dom_convert_dir_to_idx(), and DOM_OK.

static void calc_dfs_tree ( struct dom_info ,
bool   
)
static
static void calc_dfs_tree ( )
static
The main entry for calculating the DFS tree or forest.  DI is our working
   structure and REVERSE is true, if we are interested in the reverse flow
   graph.  In that case the result is not necessarily a tree but a forest,
   because there may be nodes from which the EXIT_BLOCK is unreachable.   

References bitmap_set_bit(), calc_dfs_tree_nonrec(), dfs_find_deadend(), dom_info::dfs_order, dom_info::dfs_parent, dom_info::dfs_to_bb, dom_info::dfsnum, dom_info::fake_exit_edge, basic_block_def::index, dom_info::nodes, and basic_block_def::succs.

static void calc_dfs_tree_nonrec ( struct dom_info ,
basic_block  ,
bool   
)
static

Referenced by calc_dfs_tree().

static void calc_dfs_tree_nonrec ( )
static
The nonrecursive variant of creating a DFS tree.  DI is our working
   structure, BB the starting basic block for this tree and REVERSE
   is true, if predecessors should be visited instead of successors of a
   node.  After this is done all nodes reachable from BB were visited, have
   assigned their dfs number and are linked together to form a tree.   

References edge_def::dest, dom_info::dfs_order, dom_info::dfs_parent, dom_info::dfs_to_bb, dom_info::dfsnum, ei_edge(), ei_end_p(), ei_next(), free(), basic_block_def::index, basic_block_def::preds, edge_def::src, stack, and basic_block_def::succs.

static void calc_idoms ( struct dom_info ,
bool   
)
static
static void calc_idoms ( )
static
This calculates the immediate dominators (or post-dominators if REVERSE is
   true).  DI is our working structure and should hold the DFS forest.
   On return the immediate dominator to node V is in di->dom[V].   

References bitmap_bit_p(), dom_info::bucket, edge_def::dest, dom_info::dfs_order, dom_info::dfs_parent, dom_info::dfs_to_bb, dom_info::dom, ei_edge(), ei_end_p(), ei_next(), eval(), dom_info::fake_exit_edge, basic_block_def::index, edge_iterator::index, dom_info::key, link_roots(), dom_info::next_bucket, dom_info::nodes, basic_block_def::preds, edge_def::src, and basic_block_def::succs.

void calculate_dominance_info ( )
static void compress ( struct dom_info ,
TBB   
)
static

Referenced by compress(), and eval().

static void compress ( )
static
Compress the path from V to the root of its set and update path_min at the
   same time.  After compress(di, V) set_chain[V] is the root of the set V is
   in and path_min[V] is the node with the smallest key[] value on the path
   from V to that root.   

References compress(), dom_info::key, dom_info::path_min, and dom_info::set_chain.

static void compute_dom_fast_query ( )
static
Compute the data necessary for fast resolving of dominator queries in a
   static dominator tree.   

References assign_dfs_numbers(), basic_block_def::dom, dom_convert_dir_to_idx(), dom_info_available_p(), DOM_OK, and et_node::father.

Referenced by calculate_dominance_info().

void debug_dominance_info ( enum  cdi_direction)
DEBUG_FUNCTION void debug_dominance_info ( )
void debug_dominance_tree ( enum  cdi_direction,
basic_block   
)
DEBUG_FUNCTION void debug_dominance_tree ( )
Prints to stderr representation of the dominance tree (for direction DIR)
   rooted in ROOT.   

References debug_dominance_tree_1().

static void debug_dominance_tree_1 ( enum cdi_direction  dir,
basic_block  root,
unsigned  indent,
bool  indent_first 
)
static
Prints to stderr representation of the dominance tree (for direction DIR)
   rooted in ROOT, indented by INDENT tabulators.  If INDENT_FIRST is false,
   the first line of the output is not indented.   

References first, first_dom_son(), indent, basic_block_def::index, next_dom_son(), and et_node::son.

Referenced by debug_dominance_tree().

void delete_from_dominance_info ( )
static void determine_dominators_for_sons ( struct graph g,
vec< basic_block bbs,
int  y,
int *  son,
int *  brother 
)
static
See the comment in iterate_fix_dominators.  Finds the immediate dominators
   for the sons of Y, found using the SON and BROTHER arrays representing
   the dominance tree of graph G.  BBS maps the vertices of G to the basic
   blocks.   

References bitmap_set_bit(), CDI_DOMINATORS, vertex::component, dom, free(), graphds_scc(), identify_vertices(), nearest_common_dominator(), basic_block_def::preds, recompute_dominator(), root_of_dom_tree(), set_immediate_dominator(), si, edge_def::src, and graph::vertices.

Referenced by iterate_fix_dominators().

static unsigned int dom_convert_dir_to_idx ( )
static
bool dom_info_available_p ( )
Returns true if dominance information for direction DIR is available.   

References dom_convert_dir_to_idx(), and DOM_NONE.

enum dom_state dom_info_state ( )
Return dominance availability for dominance info DIR.   

References dom_convert_dir_to_idx().

bool dominated_by_p ( )
Given a dominator tree, we can determine whether one thing
    dominates another in constant time by using two DFS numbers:

    1. The number for when we visit a node on the way down the tree
    2. The number for when we visit a node on the way back up the tree

    You can view these as bounds for the range of dfs numbers the
    nodes in the subtree of the dominator tree rooted at that node
    will contain.

    The dominator tree is always a simple acyclic tree, so there are
    only three possible relations two nodes in the dominator tree have
    to each other:

    1. Node A is above Node B (and thus, Node A dominates node B)

     A
     |
     C
    / \
   B   D


   In the above case, DFS_Number_In of A will be <= DFS_Number_In of
   B, and DFS_Number_Out of A will be >= DFS_Number_Out of B.  This is
   because we must hit A in the dominator tree *before* B on the walk
   down, and we will hit A *after* B on the walk back up

   2. Node A is below node B (and thus, node B dominates node A)


     B
     |
     A
    / \
   C   D

   In the above case, DFS_Number_In of A will be >= DFS_Number_In of
   B, and DFS_Number_Out of A will be <= DFS_Number_Out of B.

   This is because we must hit A in the dominator tree *after* B on
   the walk down, and we will hit A *before* B on the walk back up

   3. Node A and B are siblings (and thus, neither dominates the other)

     C
     |
     D
    / \
   A   B

   In the above case, DFS_Number_In of A will *always* be <=
   DFS_Number_In of B, and DFS_Number_Out of A will *always* be <=
   DFS_Number_Out of B.  This is because we will always finish the dfs
   walk of one of the subtrees before the other, and thus, the dfs
   numbers for one subtree can't intersect with the range of dfs
   numbers for the other subtree.  If you swap A and B's position in
   the dominator tree, the comparison changes direction, but the point
   is that both comparisons will always go the same way if there is no
   dominance relationship.

   Thus, it is sufficient to write

   A_Dominates_B (node A, node B)
   {
     return DFS_Number_In(A) <= DFS_Number_In(B)
            && DFS_Number_Out (A) >= DFS_Number_Out(B);
   }

   A_Dominated_by_B (node A, node B)
   {
     return DFS_Number_In(A) >= DFS_Number_In(A)
            && DFS_Number_Out (A) <= DFS_Number_Out(B);
   }   
Return TRUE in case BB1 is dominated by BB2.   

References et_node::dfs_num_in, et_node::dfs_num_out, basic_block_def::dom, dom_convert_dir_to_idx(), DOM_OK, and et_below().

static TBB eval ( struct dom_info ,
TBB   
)
static

Referenced by calc_idoms(), and gimplify_expr().

static TBB eval ( )
inlinestatic
Compress the path from V to the set root of V if needed (when the root has
   changed since the last call).  Returns the node with the smallest key[]
   value on the path from V to the root.   

References compress(), dom_info::key, dom_info::path_min, and dom_info::set_chain.

basic_block first_dom_son ( )
Returns the first son of BB in the dominator or postdominator tree
   as determined by DIR.   

References et_node::data, basic_block_def::dom, dom_convert_dir_to_idx(), and et_node::son.

static void free_dom_info ( struct dom_info )
static
void free_dominance_info ( )
Free dominance information for direction DIR.   

References basic_block_def::dom, dom_convert_dir_to_idx(), dom_info_available_p(), DOM_NONE, et_free_pools(), and et_free_tree_force().

vec<basic_block> get_all_dominated_blocks ( )
Returns the list of basic blocks including BB dominated by BB, in the
   direction DIR.  The vector will be sorted in preorder.   

References get_dominated_to_depth().

vec<basic_block> get_dominated_by ( )
Returns the list of basic blocks immediately dominated by BB, in the
   direction DIR.   

References et_node::data, basic_block_def::dom, dom_convert_dir_to_idx(), et_node::right, et_node::son, and vNULL.

vec<basic_block> get_dominated_by_region ( enum cdi_direction  dir,
basic_block region,
unsigned  n_region 
)
Returns the list of basic blocks that are immediately dominated (in
   direction DIR) by some block between N_REGION ones stored in REGION,
   except for blocks in the REGION itself.   

References dom, first_dom_son(), basic_block_def::flags, next_dom_son(), and vNULL.

Referenced by gimple_duplicate_sese_region(), gimple_duplicate_sese_tail(), and move_sese_region_to_fn().

vec<basic_block> get_dominated_to_depth ( )
Returns the list of basic blocks including BB dominated by BB, in the
   direction DIR up to DEPTH in the dominator tree.  The DEPTH of zero will
   produce a vector containing all dominated blocks.  The vector will be sorted
   in preorder.   

References first_dom_son(), next_dom_son(), et_node::son, and vNULL.

basic_block get_immediate_dominator ( )
Return the immediate dominator of basic block BB.   

References et_node::data, basic_block_def::dom, dom_convert_dir_to_idx(), and et_node::father.

static void init_dom_info ( struct dom_info ,
enum  cdi_direction 
)
static
static void init_dom_info ( )
static
void iterate_fix_dominators ( enum cdi_direction  dir,
vec< basic_block bbs,
bool  conservative 
)
Recompute dominance information for basic blocks in the set BBS.  The
   function assumes that the immediate dominators of all the other blocks
   in CFG are correct, and that there are no unreachable blocks.

   If CONSERVATIVE is true, we additionally assume that all the ancestors of
   a block of BBS in the current dominance tree dominate it.   

References add_edge(), bitmap_set_bit(), CDI_DOMINATORS, pointer_map< T >::contains(), vertex::data, determine_dominators_for_sons(), dom, dom_convert_dir_to_idx(), free(), free_graph(), g, graphds_domtree(), pointer_map< T >::insert(), map, graph::n_vertices, new_graph(), basic_block_def::preds, prune_bbs_to_update_dominators(), recompute_dominator(), root_of_dom_tree(), set_immediate_dominator(), edge_def::src, and graph::vertices.

Referenced by emit_case_bit_tests(), gen_inbound_check(), gimple_duplicate_sese_region(), gimple_duplicate_sese_tail(), make_forwarder_block(), remove_edge_and_dominated_blocks(), remove_path(), unroll_loop_runtime_iterations(), and update_dominators_in_loop().

static void link_roots ( struct dom_info ,
TBB  ,
TBB   
)
static

Referenced by calc_idoms().

static void link_roots ( )
static
This essentially merges the two sets of V and W, giving a single set with
   the new root V.  The internal representation of these disjoint sets is a
   balanced tree.  Currently link(V,W) is only used with V being the parent
   of W.   

References dom_info::key, dom_info::path_min, dom_info::set_chain, dom_info::set_child, and dom_info::set_size.

basic_block nearest_common_dominator ( )
Find first basic block in the tree dominating both BB1 and BB2.   

References et_node::data, basic_block_def::dom, dom_convert_dir_to_idx(), and et_nca().

basic_block nearest_common_dominator_for_set ( )
Find the nearest common dominator for the basic blocks in BLOCKS,
   using dominance direction DIR.   

References bitmap_first_set_bit(), dom, first, and nearest_common_dominator().

basic_block next_dom_son ( )
Returns the next dominance son after BB in the dominator or postdominator
   tree as determined by DIR, or NULL if it was the last one.   

References et_node::data, basic_block_def::dom, dom_convert_dir_to_idx(), et_node::father, et_node::right, and et_node::son.

static void prune_bbs_to_update_dominators ( vec< basic_block bbs,
bool  conservative 
)
static
Use simple heuristics (see iterate_fix_dominators) to determine dominators
   of BBS.  We assume that all the immediate dominators except for those of the
   blocks in BBS are correct.  If CONSERVATIVE is true, we also assume that the
   currently recorded immediate dominators of blocks in BBS really dominate the
   blocks.  The basic blocks for that we determine the dominator are removed
   from BBS.   

References CDI_DOMINATORS, dom, dominated_by_p(), find_edge(), nearest_common_dominator(), basic_block_def::preds, set_immediate_dominator(), single, single_pred(), single_pred_p(), and edge_def::src.

Referenced by iterate_fix_dominators().

basic_block recompute_dominator ( )
Determine immediate dominator (or postdominator, according to DIR) of BB,
   assuming that dominators of other blocks are correct.  We also use it to
   recompute the dominators in a restricted area, by iterating it until it
   reaches a fixed point.   

References CDI_DOMINATORS, edge_def::dest, dom_convert_dir_to_idx(), dominated_by_p(), nearest_common_dominator(), basic_block_def::preds, edge_def::src, and basic_block_def::succs.

void redirect_immediate_dominators ( enum cdi_direction  dir,
basic_block  bb,
basic_block  to 
)
Redirect all edges pointing to BB to TO.   

References basic_block_def::dom, dom_convert_dir_to_idx(), DOM_NO_FAST_QUERY, DOM_OK, et_set_father(), et_split(), and et_node::son.

Referenced by merge_blocks(), and split_block().

static basic_block root_of_dom_tree ( )
static
Returns root of the dominance tree in the direction DIR that contains
   BB.   

References et_node::data, basic_block_def::dom, dom_convert_dir_to_idx(), and et_root().

Referenced by determine_dominators_for_sons(), and iterate_fix_dominators().

void set_dom_info_availability ( )
Set the dominance availability for dominance info DIR to NEW_STATE.   

References dom_convert_dir_to_idx().

void set_immediate_dominator ( enum cdi_direction  dir,
basic_block  bb,
basic_block  dominated_by 
)