-static void compute_df_up(ir_node *bl, void *data)
-{
- pmap *df_map = ((dom_front_info_t *) data)->df_map;
- ir_node *y;
-
- for(y = get_Block_dominated_first(bl); y; y = get_Block_dominated_next(y)) {
- ir_node *w;
- pset *df = pmap_get(df_map, y);
-
- for(w = pset_first(df); w; w = pset_next(df))
- if(!block_dominates(bl, w) || bl == w)
- pset_insert_ptr(df, w);
- }
-}
-
-static void compute_df(ir_node *n, pmap *df_map)
-{
- ir_node *y, *c;
- const ir_edge_t *edge;
- pset *df = pset_new_ptr_default();
-
- /* Add local dominance frontiers */
- foreach_block_succ(n, edge) {
- ir_node *y = edge->src;
-
- if(get_idom(y) != n)
- pset_insert_ptr(df, y);
- }
-
- /*
- * Go recursively down the dominance tree and add all blocks
- * int the dominance frontiers of the children, which are not
- * dominated by the given block.
- */
- for(c = get_Block_dominated_first(n); c; c = get_Block_dominated_next(c)) {
- pset *df_c;
- ir_node *w;
-
- compute_df(c, df_map);
- df_c = pmap_get(df_map, c);
-
- for(w = pset_first(df_c); w; w = pset_next(df_c)) {
- if(!block_dominates(n, w))
- pset_insert_ptr(df, w);
- }
- }
-
- pmap_insert(df_map, n, df);
-
-}
-
-dom_front_info_t *be_compute_dominance_frontiers(ir_graph *irg)
-{
- dom_front_info_t *info = malloc(sizeof(*info));
-
- edges_assure(irg);
- info->df_map = pmap_create();
- compute_df(get_irg_start_block(irg), info->df_map);
-
-#if 0
- /*
- * This must be called as a post walker, since the dom front sets
- * of all predecessors must be created when a block is reached.
- */
- dom_tree_walk_irg(irg, NULL, compute_df_local, info);
- dom_tree_walk_irg(irg, NULL, compute_df_up, info);
-#endif
- return info;
-}
-
-void be_free_dominance_frontiers(dom_front_info_t *info)
-{
- pmap_entry *ent;
-
- for(ent = pmap_first(info->df_map); ent; ent = pmap_next(info->df_map))
- del_pset(ent->value);
-
- pmap_destroy(info->df_map);
- free(info);
-}
-
-pset *be_get_dominance_frontier(dom_front_info_t *info, ir_node *block)
-{
- return pmap_get(info->df_map, block);
-}
-
-/**
- * Algorithm to place the Phi-Functions.
- * @see Appel, Modern Compiler Implementation in Java, 2nd ed., p. 399ff
- *
- * This function takes an original node and a set of already placed
- * copies of that node called @p copies. It places phi nodes at the
- * iterated dominance frontiers of these copies and puts these phi nodes
- * in the @p copies set, since they are another form of copies of the
- * original value.
- *
- * The rename phase (see below) is responsible for fixing up the usages
- * of the original node.
- *
- * @param orig The original node.
- * @param copies A set contianing nodes representing a copy of the
- * original node. Each node must be inserted into the block's schedule.
- * @param copy_blocks A set in which the blocks are recorded which
- * contain a copy. This is just for efficiency in later phases (see
- * rename).
- */
-static void place_phi_functions(ir_node *orig, pset *copies,
- pset *copy_blocks, dom_front_info_t *df_info)
-{
- int i;
- ir_node *orig_block = get_nodes_block(orig);
- ir_graph *irg = get_irn_irg(orig);
- ir_mode *mode = get_irn_mode(orig);
- pdeq *worklist = new_pdeq();
- pset *phi_blocks = pset_new_ptr(8);
- ir_node **ins = NULL;
- void *it;
- firm_dbg_module_t *dbg = DBG_MODULE;
-
- /*
- * Allocate an array for all blocks where the copies and the original
- * value were defined.
- */
- int n_orig_blocks = pset_count(copy_blocks);
- ir_node **orig_blocks = malloc(n_orig_blocks * sizeof(orig_blocks[0]));
-
- /*
- * Fill the worklist queue and the rest of the orig blocks array.
- */
- for(it = pset_first(copy_blocks), i = 0; it; it = pset_next(copy_blocks)) {
- ir_node *copy_block = it;
-
- assert(block_dominates(orig_block, copy_block)
- && "The block of the copy must be dominated by the block of the value");
-
- pdeq_putr(worklist, copy_block);
- orig_blocks[i++] = copy_block;
- }
-
- while(!pdeq_empty(worklist)) {
- ir_node *bl = pdeq_getl(worklist);
- ir_node *y;
- pset *df = be_get_dominance_frontier(df_info, bl);
-
- DBG((dbg, LEVEL_3, "dom front of %+F\n", bl));
- for(y = pset_first(df); y; y = pset_next(df))
- DBG((dbg, LEVEL_3, "\t%+F\n", y));
-
- for(y = pset_first(df); y; y = pset_next(df)) {
- int n_preds = get_irn_arity(y);
-
- if(!pset_find_ptr(phi_blocks, y)) {
- ir_node *phi;
- int insert = 1;
-
- /*
- * Set the orig node as the only operand of the
- * phi node.
- */
- ins = realloc(ins, n_preds * sizeof(ins[0]));
- for(i = 0; i < n_preds; ++i)
- ins[i] = orig;
-
- /* Insert phi node */
- phi = new_r_Phi(irg, y, n_preds, ins, mode);
- DBG((dbg, LEVEL_2, " inserting phi %+F with %d args in block %+F\n",
- phi, n_preds, y));
-
- /*
- * The phi node itself is also a copy of the original
- * value. So put it in the copies set also, so that
- * the rename phase can treat them right.
- */
- pset_insert_ptr(copies, phi);
- pset_insert_ptr(copy_blocks, y);
-
- /*
- * Insert the phi node into the schedule if it
- * can occur there (PhiM's are not to put into a schedule.
- */
- if(to_appear_in_schedule(phi))
- sched_add_before(sched_first(y), phi);
-
- /* Insert the phi node in the phi blocks set. */
- pset_insert_ptr(phi_blocks, y);
-
- /*
- * If orig or a copy of it were not defined in y,
- * add y to the worklist.
- */
- for(i = 0; i < n_orig_blocks; ++i)
- if(orig_blocks[i] == y) {
- insert = 0;
- break;
- }
-
- if(insert)
- pdeq_putr(worklist, y);
-
- }
- }
- }
-
- del_pset(phi_blocks);
- del_pdeq(worklist);
-
- free(orig_blocks);
-
- if(ins)
- free(ins);
-}