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

Data Structures

struct  depth_first_search_dsS

Typedefs

typedef struct
depth_first_search_dsS
depth_first_search_ds

Functions

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, basic_block)
static void flow_dfs_compute_reverse_finish (depth_first_search_ds)
bool mark_dfs_back_edges ()
void find_unreachable_blocks ()
struct edge_listcreate_edge_list ()
void free_edge_list ()
DEBUG_FUNCTION void print_edge_list ()
DEBUG_FUNCTION void verify_edge_list ()
edge find_edge ()
int find_edge_index ()
static void remove_fake_predecessors ()
void remove_fake_edges ()
void remove_fake_exit_edges ()
void add_noreturn_fake_exit_edges ()
void connect_infinite_loops_to_exit ()
int post_order_compute (int *post_order, bool include_entry_exit, bool delete_unreachable)
basic_block dfs_find_deadend ()
int inverted_post_order_compute ()
int pre_and_rev_post_order_compute (int *pre_order, int *rev_post_order, bool include_entry_exit)
static void flow_dfs_compute_reverse_init ()
static void flow_dfs_compute_reverse_add_bb ()
static void flow_dfs_compute_reverse_finish ()
int dfs_enumerate_from (basic_block bb, int reverse, bool(*predicate)(const_basic_block, const void *), basic_block *rslt, int rslt_max, const void *data)
static void compute_dominance_frontiers_1 ()
void compute_dominance_frontiers ()
bitmap compute_idf ()
void bitmap_intersection_of_succs ()
void bitmap_intersection_of_preds ()
void bitmap_union_of_succs ()
void bitmap_union_of_preds ()

Typedef Documentation


Function Documentation

void add_noreturn_fake_exit_edges ( void  )
This function will add a fake edge between any block which has no
   successors, and the exit block. Some data flow equations require these
   edges to exist.   

References make_single_succ_edge(), and basic_block_def::succs.

Referenced by branch_prob(), cleanup_cfg(), one_pre_gcse_pass(), one_store_motion_pass(), rebuild_frequencies(), and tree_estimate_probability().

void bitmap_intersection_of_preds ( )
Set the bitmap DST to the intersection of SRC of predecessors of
   basic block B.   

References bitmap_copy(), bitmap_ones(), simple_bitmap_def::elms, basic_block_def::index, simple_bitmap_def::popcount, basic_block_def::preds, simple_bitmap_def::size, and edge_def::src.

void bitmap_intersection_of_succs ( )
Intersection and union of preds/succs for sbitmap based data flow
   solvers.  All four functions defined below take the same arguments:
   B is the basic block to perform the operation for.  DST is the
   target sbitmap, i.e. the result.  SRC is an sbitmap vector of size
   last_basic_block so that it can be indexed with basic block indices.
   DST may be (but does not have to be) SRC[B->index].   
Set the bitmap DST to the intersection of SRC of successors of
   basic block B.   

References bitmap_copy(), bitmap_ones(), edge_def::dest, simple_bitmap_def::elms, basic_block_def::index, simple_bitmap_def::popcount, simple_bitmap_def::size, and basic_block_def::succs.

void bitmap_union_of_preds ( )
Set the bitmap DST to the union of SRC of predecessors of
   basic block B.   

References bitmap_clear(), bitmap_copy(), simple_bitmap_def::elms, basic_block_def::index, simple_bitmap_def::popcount, basic_block_def::preds, simple_bitmap_def::size, and edge_def::src.

void bitmap_union_of_succs ( )
void compute_dominance_frontiers ( )
static void compute_dominance_frontiers_1 ( )
static
Compute dominance frontiers, ala Harvey, Ferrante, et al.

   This algorithm can be found in Timothy Harvey's PhD thesis, at
   http://www.cs.rice.edu/~harv/dissertation.pdf in the section on iterative
   dominance algorithms.

   First, we identify each join point, j (any node with more than one
   incoming edge is a join point).

   We then examine each predecessor, p, of j and walk up the dominator tree
   starting at p.

   We stop the walk when we reach j's immediate dominator - j is in the
   dominance frontier of each of  the nodes in the walk, except for j's
   immediate dominator. Intuitively, all of the rest of j's dominators are
   shared by j's predecessors as well.
   Since they dominate j, they will not have j in their dominance frontiers.

   The number of nodes touched by this algorithm is equal to the size
   of the dominance frontiers, no more, no less.

References bitmap_set_bit(), CDI_DOMINATORS, get_immediate_dominator(), basic_block_def::index, basic_block_def::preds, and edge_def::src.

Referenced by compute_dominance_frontiers().

bitmap compute_idf ( )
Given a set of blocks with variable definitions (DEF_BLOCKS),
   return a bitmap with all the blocks in the iterated dominance
   frontier of the blocks in DEF_BLOCKS.  DFS contains dominance
   frontier information as returned by compute_dominance_frontiers.

   The resulting set of blocks are the potential sites where PHI nodes
   are needed.  The caller is responsible for freeing the memory
   allocated for the return value.   

References bitmap_set_bit().

void connect_infinite_loops_to_exit ( void  )
This function adds a fake edge between any infinite loops to the
   exit block.  Some optimizations require a path from each node to
   the exit node.

   See also Morgan, Figure 3.10, pp. 82-83.

   The current implementation is ugly, not attempting to minimize the
   number of inserted fake edges.  To reduce the number of fake edges
   to insert, add fake edges from _innermost_ loops containing only
   nodes not reachable from the exit block.   

References dfs_find_deadend(), flow_dfs_compute_reverse_add_bb(), flow_dfs_compute_reverse_execute(), flow_dfs_compute_reverse_finish(), flow_dfs_compute_reverse_init(), and make_edge().

Referenced by execute_sink_code(), init_pre(), one_store_motion_pass(), rebuild_frequencies(), and tree_estimate_probability().

struct edge_list* create_edge_list ( void  )
read
Functions to access an edge list with a vector representation.
   Enough data is kept such that given an index number, the
   pred and succ that edge represents can be determined, or
   given a pred and a succ, its index number can be returned.
   This allows algorithms which consume a lot of memory to
   represent the normally full matrix of edge (pred,succ) with a
   single indexed vector,  edge (EDGE_INDEX (pred, succ)), with no
   wasted space in the client code due to sparse flow graphs.   
This functions initializes the edge list. Basically the entire
   flowgraph is processed, and all edges are assigned a number,
   and the data structure is filled in.   

References edge_list::index_to_edge, edge_list::num_edges, and basic_block_def::succs.

Referenced by branch_prob(), perform_tree_ssa_dce(), pre_edge_lcm(), and pre_edge_rev_lcm().

int dfs_enumerate_from ( basic_block  bb,
int  reverse,
bool(*)(const_basic_block, const void *)  predicate,
basic_block rslt,
int  rslt_max,
const void *  data 
)
Performs dfs search from BB over vertices satisfying PREDICATE;
   if REVERSE, go against direction of edges.  Returns number of blocks
   found and their list in RSLT.  RSLT can contain at most RSLT_MAX items.   

References bitmap_clear(), edge_def::dest, free(), basic_block_def::preds, sbitmap_alloc(), sbitmap_resize(), depth_first_search_dsS::sp, edge_def::src, basic_block_def::succs, and visited.

Referenced by determine_bb_domination_status(), find_path(), get_loop_body_with_size(), new_loop_vec_info(), and thread_through_loop_header().

basic_block dfs_find_deadend ( )
Helper routine for inverted_post_order_compute
   flow_dfs_compute_reverse_execute, and the reverse-CFG
   deapth first search in dominance.c.
   BB has to belong to a region of CFG
   unreachable by inverted traversal from the exit.
   i.e. there's no control flow path from ENTRY to EXIT
   that contains this BB.
   This can happen in two cases - if there's an infinite loop
   or if there's a block that has no successor
   (call to a function with no return).
   Some RTL passes deal with this condition by
   calling connect_infinite_loops_to_exit () and/or
   add_noreturn_fake_exit_edges ().
   However, those methods involve modifying the CFG itself
   which may not be desirable.
   Hence, we deal with the infinite loop/no return cases
   by identifying a unique basic block that can reach all blocks
   in such a region by inverted traversal.
   This function returns a basic block that guarantees
   that all blocks in the region are reachable
   by starting an inverted traversal from the returned block.   

References bitmap_set_bit(), basic_block_def::index, basic_block_def::succs, and visited.

edge find_edge ( )
Given PRED and SUCC blocks, return the edge which connects the blocks.
   If no such edge exists, return NULL.   

References edge_def::dest, basic_block_def::preds, edge_def::src, and basic_block_def::succs.

int find_edge_index ( )
This routine will determine what, if any, edge there is between
   a specified predecessor and successor.   
void find_unreachable_blocks ( void  )
Find unreachable blocks.  An unreachable block will have 0 in
   the reachable bit in block->flags.  A nonzero value indicates the
   block is reachable.   

References edge_def::dest, basic_block_def::flags, free(), basic_block_def::succs, and worklist.

Referenced by delete_unreachable_blocks(), delete_unreachable_blocks_update_callgraph(), and eliminate_unnecessary_stmts().

static void flow_dfs_compute_reverse_add_bb ( depth_first_search_ds  ,
basic_block   
)
static
static void flow_dfs_compute_reverse_add_bb ( )
static
Add the specified basic block to the top of the dfs data
   structures.  When the search continues, it will start at the
   block.   

References bitmap_set_bit(), basic_block_def::index, depth_first_search_dsS::sp, depth_first_search_dsS::stack, and depth_first_search_dsS::visited_blocks.

static basic_block flow_dfs_compute_reverse_execute ( depth_first_search_ds  data,
basic_block  last_unvisited 
)
static
Continue the depth-first search through the reverse graph starting with the
   block at the stack's top and ending when the stack is empty.  Visited nodes
   are marked.  Returns an unvisited basic block, or NULL if there is none
   available.   

References bitmap_bit_p(), flow_dfs_compute_reverse_add_bb(), basic_block_def::index, basic_block_def::preds, depth_first_search_dsS::sp, edge_def::src, depth_first_search_dsS::stack, and depth_first_search_dsS::visited_blocks.

Referenced by connect_infinite_loops_to_exit().

static void flow_dfs_compute_reverse_finish ( depth_first_search_ds  )
static
static void flow_dfs_compute_reverse_finish ( )
static
Destroy the data structures needed for depth-first search on the
   reverse graph.   

References free(), sbitmap_free(), depth_first_search_dsS::stack, and depth_first_search_dsS::visited_blocks.

static void flow_dfs_compute_reverse_init ( depth_first_search_ds  )
static
static void flow_dfs_compute_reverse_init ( )
static
Compute the depth first search order on the _reverse_ graph and
   store in the array DFS_ORDER, marking the nodes visited in VISITED.
   Returns the number of nodes visited.

   The computation is split into three pieces:

   flow_dfs_compute_reverse_init () creates the necessary data
   structures.

   flow_dfs_compute_reverse_add_bb () adds a basic block to the data
   structures.  The block will start the search.

   flow_dfs_compute_reverse_execute () continues (or starts) the
   search using the block on the top of the stack, stopping when the
   stack is empty.

   flow_dfs_compute_reverse_finish () destroys the necessary data
   structures.

   Thus, the user will probably call ..._init(), call ..._add_bb() to
   add a beginning basic block to the stack, call ..._execute(),
   possibly add another bb to the stack and again call ..._execute(),
   ..., and finally call _finish().   
Initialize the data structures used for depth-first search on the
   reverse graph.  If INITIALIZE_STACK is nonzero, the exit block is
   added to the basic block stack.  DATA is the current depth-first
   search context.  If INITIALIZE_STACK is nonzero, there is an
   element on the stack.   

References bitmap_clear(), sbitmap_alloc(), depth_first_search_dsS::sp, depth_first_search_dsS::stack, and depth_first_search_dsS::visited_blocks.

void free_edge_list ( )
This function free's memory associated with an edge list.   

References free(), and edge_list::index_to_edge.

int inverted_post_order_compute ( )
Compute the reverse top sort order of the inverted CFG
   i.e. starting from the exit block and following the edges backward
   (from successors to predecessors).
   This ordering can be used for forward dataflow problems among others.

   This function assumes that all blocks in the CFG are reachable
   from the ENTRY (but not necessarily from EXIT).

   If there's an infinite loop,
   a simple inverted traversal starting from the blocks
   with no successors can't visit all blocks.
   To solve this problem, we first do inverted traversal
   starting from the blocks with no successor.
   And if there's any block left that's not visited by the regular
   inverted traversal from EXIT,
   those blocks are in such problematic region.
   Among those, we find one block that has
   any visited predecessor (which is an entry into such a region),
   and start looking for a "dead end" from that block
   and do another inverted traversal from that block.   

References bitmap_bit_p(), bitmap_clear(), bitmap_set_bit(), edge_def::dest, dfs_find_deadend(), ei_edge(), ei_next(), ei_one_before_end_p(), free(), basic_block_def::index, basic_block_def::preds, sbitmap_alloc(), sbitmap_free(), depth_first_search_dsS::sp, edge_def::src, stack, basic_block_def::succs, and visited.

bool mark_dfs_back_edges ( void  )
Mark the back edges in DFS traversal.
   Return nonzero if a loop (natural or otherwise) is present.
   Inspired by Depth_First_Search_PP described in:

     Advanced Compiler Design and Implementation
     Steven Muchnick
     Morgan Kaufmann, 1997

   and heavily borrowed from pre_and_rev_post_order_compute.   

References bitmap_bit_p(), bitmap_clear(), bitmap_set_bit(), edge_def::dest, ei_edge(), ei_next(), ei_one_before_end_p(), edge_def::flags, free(), basic_block_def::index, sbitmap_alloc(), sbitmap_free(), depth_first_search_dsS::sp, edge_def::src, stack, basic_block_def::succs, and visited.

Referenced by analyze_function(), bypass_conditional_jumps(), compute_antic(), draw_cfg_edges(), estimate_bb_frequencies(), execute_split_functions(), execute_vrp(), identify_jump_threads(), insert_backedge_copies(), perform_tree_ssa_dce(), reg_to_stack(), reorder_basic_blocks(), tracer(), tree_ssa_dominator_optimize(), and variable_tracking_main_1().

int post_order_compute ( int *  post_order,
bool  include_entry_exit,
bool  delete_unreachable 
)
Compute reverse top sort order.  This is computing a post order
   numbering of the graph.  If INCLUDE_ENTRY_EXIT is true, then
   ENTRY_BLOCK and EXIT_BLOCK are included.  If DELETE_UNREACHABLE is
   true, unreachable blocks are deleted.   

References bitmap_bit_p(), bitmap_clear(), bitmap_set_bit(), count, delete_basic_block(), edge_def::dest, ei_edge(), ei_next(), ei_one_before_end_p(), free(), basic_block_def::index, basic_block_def::next_bb, sbitmap_alloc(), sbitmap_free(), depth_first_search_dsS::sp, edge_def::src, stack, basic_block_def::succs, tidy_fallthru_edges(), and visited.

Referenced by df_analyze(), extend_rgns(), and rest_of_handle_df_initialize().

int pre_and_rev_post_order_compute ( int *  pre_order,
int *  rev_post_order,
bool  include_entry_exit 
)
Compute the depth first search order and store in the array
  PRE_ORDER if nonzero, marking the nodes visited in VISITED.  If
  REV_POST_ORDER is nonzero, return the reverse completion number for each
  node.  Returns the number of nodes visited.  A depth first search
  tries to get as far away from the starting point as quickly as
  possible.

  pre_order is a really a preorder numbering of the graph.
  rev_post_order is really a reverse postorder numbering of the graph.

References bitmap_bit_p(), bitmap_clear(), bitmap_set_bit(), edge_def::dest, ei_edge(), ei_next(), ei_one_before_end_p(), free(), basic_block_def::index, sbitmap_alloc(), sbitmap_free(), depth_first_search_dsS::sp, edge_def::src, stack, basic_block_def::succs, and visited.

Referenced by add_scope_conflicts(), cse_main(), draw_cfg_nodes_no_loops(), estimate_function_body_sizes(), find_assert_locations(), flow_loops_find(), init_alias_analysis(), init_reassoc(), init_scc_vn(), regrename_analyze(), and vt_find_locations().

DEBUG_FUNCTION void print_edge_list ( )
This function provides debug output showing an edge list.   

References edge_list::num_edges.

void remove_fake_edges ( void  )
This routine will remove all fake edges from the flow graph.  If
   we remove all fake successors, it will automatically remove all
   fake predecessors.   

References basic_block_def::next_bb, and remove_fake_predecessors().

Referenced by branch_prob().

void remove_fake_exit_edges ( void  )
This routine will remove all fake edges to the EXIT_BLOCK.   

References remove_fake_predecessors().

Referenced by cleanup_cfg(), do_pre(), execute_sink_code(), one_pre_gcse_pass(), one_store_motion_pass(), rebuild_frequencies(), and tree_estimate_probability().

static void remove_fake_predecessors ( )
static
This routine will remove any fake predecessor edges for a basic block.
   When the edge is removed, it is also removed from whatever successor
   list it is in.   

References ei_next(), ei_safe_edge(), edge_def::flags, basic_block_def::preds, and remove_edge().

Referenced by remove_fake_edges(), and remove_fake_exit_edges().

DEBUG_FUNCTION void verify_edge_list ( )
This function provides an internal consistency check of an edge list,
   verifying that all edges are present, and that there are no
   extra edges.   

References edge_def::dest, basic_block_def::index, basic_block_def::next_bb, basic_block_def::preds, edge_def::src, and basic_block_def::succs.