-static int check_out_phi(phi_info_t *phi_info, const opt_if_conv_info_t *info)
-{
- ir_node *irn = phi_info->irn;
- ir_node *block, *nw;
- cond_info_t *cond_info = phi_info->cond_info;
- cond_t *cond;
- int i, arity;
- int muxes_made = 0;
- bitset_t *positions;
-
- block = get_nodes_block(irn);
- arity = get_irn_arity(irn);
- positions = bitset_alloca(arity);
-
- assert(is_Phi(irn));
- assert(get_irn_arity(irn) == get_irn_arity(block));
- assert(arity > 0);
-
- DBG((dbg, LEVEL_2, "phi candidate: %n\n", irn));
-
- list_for_each_entry(cond_t, cond, &cond_info->roots, list) {
- ir_node *cidom = block;
- ir_node *mux = NULL;
- cond_t *p, *head = NULL;
- long pos;
-
- bitset_clear_all(positions);
-
- DBG((dbg, LEVEL_2, "\tcond root: %n\n", cond->cond));
- /*
- * Link all conds which are in the subtree of
- * the current cond in the list together.
- */
- walk_conds(cond, link_conds, NULL, &head);
-
- cidom = block;
- for(p = head; p; p = p->link) {
- for(i = 0; i < 2; ++i) {
- int pos = p->cases[i].pos;
- if(pos != -1)
- cidom = common_idom(cidom, get_nodes_block(get_irn_n(block, pos)));
- }
- }
-
- DBG((dbg, LEVEL_2, "\tcommon idom: %n\n", cidom));
- make_mux_on_demand(irn, cidom, cond, info, &mux, positions, &muxes_made, ++cond_visited_nr);
-
- if(mux) {
- bitset_foreach(positions, pos)
- set_irn_n(irn, (int) pos, mux);
- }
- }
-
- /*
- * optimize the phi away. This can anable further runs of this
- * function. Look at _can_move. phis cannot be moved there.
- */
- nw = optimize_in_place_2(irn);
- if(nw != irn)
- exchange(irn, nw);
-
- return muxes_made;
-}
-
-typedef struct _cond_walk_info_t {
- struct obstack *obst;
- struct list_head cond_info_head;
- struct list_head phi_head;
-} cond_walk_info_t;
-
-
-static void annotate_cond_info_pre(ir_node *irn, void *data)
-{
- set_irn_link(irn, NULL);
-}
-
-static void annotate_cond_info_post(ir_node *irn, void *data)
-{
- cond_walk_info_t *cwi = data;
-
- /*
- * Check, if the node is a phi
- * we then compute a set of conds which are reachable from this
- * phi's block up to its dominator.
- * The set is attached to the blocks link field.
- */
- if(is_Phi(irn) && mode_is_datab(get_irn_mode(irn))) {
- ir_node *block = get_nodes_block(irn);
-
- cond_info_t *ci = get_irn_link(block);
-
- /* If the set is not yet computed, do it now. */
- if(!ci) {
- ci = obstack_alloc(cwi->obst, sizeof(*ci));
- ci->cond_set = new_set(cond_cmp, log2_ceil(get_irn_arity(block)));
- ci->first_phi = irn;
-
- INIT_LIST_HEAD(&ci->roots);
- INIT_LIST_HEAD(&ci->list);
-
- /*
- * Add this cond info to the list of all cond infos
- * in this graph. This is just done to xfree the
- * set easier afterwards (we save an irg_walk_graph).
- */
- list_add(&cwi->cond_info_head, &ci->list);
-
- DBG((dbg, LEVEL_2, "searching conds at %n\n", irn));
-
- /*
- * Fill the set with conds we find on the way from
- * the block to its dominator.
- */
- find_conds(irn, ci);
-
- /*
- * If there where no suitable conds, delete the set
- * immediately and reset the set pointer to NULL
- */
- if(set_count(ci->cond_set) == 0) {
- del_set(ci->cond_set);
- list_del(&ci->list);
- obstack_free(cwi->obst, ci);
- ci = NULL;
- }
- }
-
- else
- DBG((dbg, LEVEL_2, "conds already computed for %n (look at %n)\n", irn, ci->first_phi));
-
- set_irn_link(block, ci);
-
- if(ci) {
- phi_info_t *pi = obstack_alloc(cwi->obst, sizeof(*pi));
- pi->irn = irn;
- pi->cond_info = ci;
- INIT_LIST_HEAD(&pi->list);
- list_add(&pi->list, &cwi->phi_head);
- }
-
- }
-}
-
-static void dump_conds(cond_t *cond, void *env)
-{
- int i;
- FILE *f = env;
-
- ir_fprintf(f, "node:{title:\"n%p\" label:\"%n(%d, %d)\n%n\"}\n",
- cond, cond->cond, cond->cases[0].pos, cond->cases[1].pos,
- get_nodes_block(cond->cond));
-
- for(i = 0; i < 2; ++i)
- if(cond->cases[i].masked_by)
- ir_fprintf(f, "edge:{sourcename:\"n%p\" targetname:\"n%p\" label:\"%d\"}\n",
- cond, cond->cases[i].masked_by, i);
-}
-
-static void vcg_dump_conds(ir_graph *irg, cond_walk_info_t *cwi)
-{
- char buf[512];
- FILE *f;
-
- snprintf(buf, sizeof(buf), "%s-conds.vcg", get_entity_name(get_irg_entity(irg)));
-
- if((f = fopen(buf, "wt")) != NULL) {
- cond_info_t *ci;
- phi_info_t *phi;
- cond_t *cond;
-
- ir_fprintf(f, "graph:{\ndisplay_edge_labels:yes\n");
- list_for_each_entry(cond_info_t, ci, &cwi->cond_info_head, list) {
- ir_fprintf(f, "node:{title:\"n%p\" label:\"cond info\"}\n", ci);
- list_for_each_entry(cond_t, cond, &ci->roots, list) {
- walk_conds(cond, NULL, dump_conds, f);
- ir_fprintf(f, "edge:{sourcename:\"n%p\" targetname:\"n%p\"}\n", ci, cond);
- }
- }
-
- list_for_each_entry(phi_info_t, phi, &cwi->phi_head, list) {
- ir_fprintf(f, "node:{title:\"n%p\" label:\"%n\n%n\"}\n",
- phi->irn, phi->irn, get_nodes_block(phi->irn));
- ir_fprintf(f, "edge:{sourcename:\"n%p\" targetname:\"n%p\"}\n", phi->irn, phi->cond_info);
- }
- fprintf(f, "}\n");
- }
-}