-#define MAX_DEPTH 20
-
-/*
- * Mux optimization routines.
- */
-
-#if 0
-static ir_node *local_optimize_mux(ir_node *mux)
-{
- int i, n;
- ir_node *res = mux;
- ir_node *sel = get_Mux_sel(mux);
- ir_node *cmp = skip_Proj(sel);
-
- /* Optimize the children */
- for(i = 1, n = get_irn_arity(mux); i < n; ++i) {
- ir_node *operand = get_irn_n(mux, i);
- if(get_irn_op(operand) == op_Mux)
- optimize_mux(operand);
- }
-
- /* If we have no cmp above the mux, get out. */
- if(is_Proj(sel) && get_irn_mode(sel) == mode_b && get_irn_opcode(cmp) == iro_Cmp) {
-
- pn_Cmp cc = get_Proj_proj(sel);
- ir_mode *mode = get_irn_mode(mux);
- ir_node *block = get_nodes_block(n);
- ir_node *cmp_left = get_Cmp_left(cmp);
- ir_node *cmp_right = get_Cmp_right(cmp);
- ir_node *mux_true = get_Mux_true(mux);
- ir_node *mux_false = get_Mux_false(mux);
-
- /*
- * Check for comparisons with signed integers.
- */
- if(mode_is_int(mode) /* We need an integral mode */
- && mode_is_signed(mode) /* which is signed */
- && cc == Lt) { /* and have to compare for < */
-
- /*
- * Mux(x:T < 0, -1, 0) -> Shrs(x, sizeof_bits(T) - 1)
- * Conditions:
- * T must be signed.
- */
- if(classify_Const(cmp_right) == CNST_NULL
- && classify_Const(mux_true) == CNST_ALL_ONE
- && classify_Const(mux_false) == CNST_NULL) {
-
- ir_mode *u_mode = find_unsigned_mode(mode);
-
- res = new_r_Shrs(current_ir_graph, block, cmp_left,
- new_r_Const_long(current_ir_graph, block, u_mode,
- get_mode_size_bits(mode) - 1),
- mode);
- }
-
- /*
- * Mux(0 < x:T, 1, 0) -> Shr(-x, sizeof_bits(T) - 1)
- * Conditions:
- * T must be signed.
- */
- else if(classify_Const(cmp_left) == CNST_NULL
- && classify_Const(mux_true) == CNST_ONE
- && classify_Const(mux_false) == CNST_NULL) {
-
- ir_mode *u_mode = find_unsigned_mode(mode);
-
- res = new_r_Shr(current_ir_graph, block,
-
- /* -x goes to 0 - x in Firm (cmp_left is 0, see the if) */
- new_r_Sub(current_ir_graph, block, cmp_left, cmp_right, mode),
-
- /* This is sizeof_bits(T) - 1 */
- new_r_Const_long(current_ir_graph, block, u_mode,
- get_mode_size_bits(mode) - 1),
- mode);
- }
- }
- }
-
- return res;
-}
-#endif
- int i;
- ir_node *res;
- ir_node *ops[2];
- ir_mode *mode = get_irn_mode(mux);
- tarval *null;
- tarval *minus_one;
-
- /*
- * If we have no mux, or its mode is not integer, we
- * can return.
- */
- if(get_irn_op(mux) != op_Mux || !mode_is_int(mode))
- return mux;
-
- res = mux;
- null = get_tarval_null(mode);
- minus_one = tarval_sub(null, get_tarval_one(mode));
-
- ops[0] = get_Mux_false(mux);
- ops[1] = get_Mux_true(mux);
-
- for(i = 0; i < 2; ++i) {
- ir_node *a, *b, *d;
- tarval *tva, *tvb, *tvd;
- ir_node *child_mux;
-
- /*
- * A mux operand at the first position can be factored
- * out, if the operands fulfill several conditions:
- *
- * mux(c1, mux(c2, a, b), d)
- *
- * This can be made into:
- * 1) mux(c1, 0, d) | mux(c2, a, b)
- * if a | d == d and b | d == d
- *
- * 2) mux(c1, -1, d) & mux(c2, a, b)
- * if a & d == d and a & b == b
- */
- if(get_irn_op(ops[i]) == op_Mux) {
-
- child_mux = ops[i];
- a = get_Mux_false(child_mux);
- b = get_Mux_true(child_mux);
- d = ops[1 - i];
-
- /* Try the or stuff */
- tva = get_value_or(a, minus_one);
- tvb = get_value_or(b, minus_one);
- tvd = get_value_or(d, null);
-
- if(tarval_cmp(tarval_or(tva, tvd), tvd) == pn_Cmp_Eq
- && tarval_cmp(tarval_or(tvb, tvd), tvd) == pn_Cmp_Eq) {
-
- ops[i] = new_Const(mode, null);
- res = new_r_Or(current_ir_graph, get_nodes_block(mux),
- mux, child_mux, mode);
- break;
- }
-
- /* If the or didn't go, try the and stuff */
- tva = get_value_or(a, null);
- tvb = get_value_or(b, null);
- tvd = get_value_or(d, minus_one);
-
- if(tarval_cmp(tarval_and(tva, tvd), tvd) == pn_Cmp_Eq
- && tarval_cmp(tarval_and(tvb, tvd), tvd) == pn_Cmp_Eq) {
-
- ops[i] = new_Const(mode, minus_one);
- res = new_r_And(current_ir_graph, get_nodes_block(mux),
- mux, child_mux, mode);
- break;
- }
- }
- }
-
- /* recursively optimize nested muxes. */
- set_irn_n(mux, 1, optimize_mux_chain(ops[0]));
- set_irn_n(mux, 2, optimize_mux_chain(ops[1]));
-
- return res;
+ int i;
+ ir_node *res;
+ ir_node *ops[2];
+ ir_mode *mode = get_irn_mode(mux);
+ tarval *null;
+ tarval *minus_one;
+
+ /*
+ * If we have no mux, or its mode is not integer, we
+ * can return.
+ */
+ if(get_irn_op(mux) != op_Mux || !mode_is_int(mode))
+ return mux;
+
+ res = mux;
+ null = get_tarval_null(mode);
+ minus_one = tarval_sub(null, get_tarval_one(mode));
+
+ ops[0] = get_Mux_false(mux);
+ ops[1] = get_Mux_true(mux);
+
+ for(i = 0; i < 2; ++i) {
+ ir_node *a, *b, *d;
+ tarval *tva, *tvb, *tvd;
+ ir_node *child_mux;
+
+ /*
+ * A mux operand at the first position can be factored
+ * out, if the operands fulfill several conditions:
+ *
+ * mux(c1, mux(c2, a, b), d)
+ *
+ * This can be made into:
+ * 1) mux(c1, 0, d) | mux(c2, a, b)
+ * if a | d == d and b | d == d
+ *
+ * 2) mux(c1, -1, d) & mux(c2, a, b)
+ * if a & d == d and a & b == b
+ */
+ if(get_irn_op(ops[i]) == op_Mux) {
+
+ child_mux = ops[i];
+ a = get_Mux_false(child_mux);
+ b = get_Mux_true(child_mux);
+ d = ops[1 - i];
+
+ /* Try the or stuff */
+ tva = get_value_or(a, minus_one);
+ tvb = get_value_or(b, minus_one);
+ tvd = get_value_or(d, null);
+
+ if(tarval_cmp(tarval_or(tva, tvd), tvd) == pn_Cmp_Eq
+ && tarval_cmp(tarval_or(tvb, tvd), tvd) == pn_Cmp_Eq) {
+
+ ops[i] = new_Const(mode, null);
+ res = new_r_Or(current_ir_graph, get_nodes_block(mux),
+ mux, child_mux, mode);
+ break;
+ }
+
+ /* If the or didn't go, try the and stuff */
+ tva = get_value_or(a, null);
+ tvb = get_value_or(b, null);
+ tvd = get_value_or(d, minus_one);
+
+ if(tarval_cmp(tarval_and(tva, tvd), tvd) == pn_Cmp_Eq
+ && tarval_cmp(tarval_and(tvb, tvd), tvd) == pn_Cmp_Eq) {
+
+ ops[i] = new_Const(mode, minus_one);
+ res = new_r_And(current_ir_graph, get_nodes_block(mux),
+ mux, child_mux, mode);
+ break;
+ }
+ }
+ }
+
+ /* recursively optimize nested muxes. */
+ set_irn_n(mux, 1, optimize_mux_chain(ops[0]));
+ set_irn_n(mux, 2, optimize_mux_chain(ops[1]));
+
+ return res;
- int i, n;
- int res = SUCCESS;
- ir_node *expr_block = get_nodes_block(expr);
-
- /*
- * If we are forced to look too deep into the expression,
- * treat it like it could not be moved.
- */
- if(depth >= max_depth) {
- res = TO_DEEP;
- goto end;
- }
-
- /*
- * If the block of the expression dominates the specified
- * destination block, it does not matter if the expression
- * has side effects or anything else. It is executed on each
- * path the destination block is reached.
- */
- if (block_dominates(expr_block, dest_block))
- goto end;
-
- /*
- * We cannot move phis!
- */
- if (is_Phi(expr)) {
- res = PHI_FOUND;
- goto end;
- }
-
- /*
- * This should be superfluous and could be converted into a assertion.
- * The destination block _must_ dominate the block of the expression,
- * else the expression could be used without its definition.
- */
- if (! block_dominates(dest_block, expr_block)) {
- res = IF_RESULT_SIDE_EFFECT;
- goto end;
- }
-
- /*
- * Surely, if the expression does not have a data mode, it is not
- * movable. Perhaps one should also test the floating property of
- * the opcode/node.
- */
- if (has_side_effects(expr)) {
- res = IF_RESULT_SIDE_EFFECT;
- goto end;
- }
-
- /*
- * If the node looks alright so far, look at its operands and
- * check them out. If one of them cannot be moved, this one
- * cannot be moved either.
- */
- for (i = 0, n = get_irn_arity(expr); i < n; ++i) {
- ir_node *op = get_irn_n(expr, i);
- int new_depth = is_Proj(op) ? depth : depth + 1;
-
- res = _can_move_to(op, dest_block, new_depth, max_depth);
+ int i, n;
+ int res = SUCCESS;
+ ir_node *expr_block = get_nodes_block(expr);
+
+ /*
+ * If we are forced to look too deep into the expression,
+ * treat it like it could not be moved.
+ */
+ if(depth >= info->max_depth) {
+ res = TO_DEEP;
+ goto end;
+ }
+
+ /*
+ * If the block of the expression dominates the specified
+ * destination block, it does not matter if the expression
+ * has side effects or anything else. It is executed on each
+ * path the destination block is reached.
+ */
+ if (block_dominates(expr_block, dest_block))
+ goto end;
+
+ /*
+ * We cannot move phis!
+ */
+ if (is_Phi(expr)) {
+ res = PHI_FOUND;
+ goto end;
+ }
+
+ /*
+ * This should be superfluous and could be converted into a assertion.
+ * The destination block _must_ dominate the block of the expression,
+ * else the expression could be used without its definition.
+ */
+ if (! block_dominates(dest_block, expr_block)) {
+ res = IF_RESULT_SIDE_EFFECT;
+ goto end;
+ }
+
+ /*
+ * Surely, if the expression does not have a data mode, it is not
+ * movable. Perhaps one should also test the floating property of
+ * the opcode/node.
+ */
+ if (has_side_effects(expr)) {
+ res = IF_RESULT_SIDE_EFFECT;
+ goto end;
+ }
+
+ /*
+ * If the node looks alright so far, look at its operands and
+ * check them out. If one of them cannot be moved, this one
+ * cannot be moved either.
+ */
+ for (i = 0, n = get_irn_arity(expr); i < n; ++i) {
+ ir_node *op = get_irn_n(expr, i);
+ int new_depth = is_Proj(op) ? depth : depth + 1;
+
+ res = _can_move_to(op, dest_block, new_depth, info);
- ir_node *cond; /**< The cond node. */
- struct list_head list; /**< List head which is used for queuing this cond
- into the cond bunch it belongs to. */
- unsigned is_new : 1;
- unsigned totally_covers : 1;
- struct _cond_t *link;
- long visited_nr;
-
- /**
- * Information about the both 'branches'
- * (true and false), the cond creates.
- */
- struct {
- int pos; /**< Number of the predecessor of the
- phi block by which this branch is
- reached. It is -1, if this branch is
- only reached through another cond. */
-
- struct _cond_t *masked_by; /**< If this cond's branch is only reached
- through another cond, we store this
- cond ir_node here. */
- } cases[2];
+ ir_node *cond; /**< The cond node. */
+ struct list_head list; /**< List head which is used for queuing this cond
+ into the cond bunch it belongs to. */
+ unsigned is_new : 1;
+ unsigned totally_covers : 1;
+ struct _cond_t *link;
+ long visited_nr;
+
+ /**
+ * Information about the both 'branches'
+ * (true and false), the cond creates.
+ */
+ struct {
+ int pos; /**< Number of the predecessor of the
+ phi block by which this branch is
+ reached. It is -1, if this branch is
+ only reached through another cond. */
+
+ struct _cond_t *masked_by; /**< If this cond's branch is only reached
+ through another cond, we store this
+ cond ir_node here. */
+ } cases[2];
- ir_node *block;
- int saw_select_cond = 0;
-
- block = get_nodes_block(irn);
-
- /*
- * Only check this block if it is dominated by the specified
- * dominator or it has not been visited yet.
- */
- if (block_dominates(dominator, block) && get_Block_block_visited(block) < visited_nr) {
- cond_t *res = masked_by;
- int i, n;
-
- /* check, if we're on a ProjX
- *
- * Further, the ProjX/Cond block must dominate the base block
- * (the block with the phi in it), otherwise, the Cond
- * is not affecting the phi so that a mux can be inserted.
- */
- if(is_Proj(irn) && get_irn_mode(irn) == mode_X) {
-
- int proj = get_Proj_proj(irn);
- ir_node *cond = get_Proj_pred(irn);
-
- /* true, if the mode is a mode_b cond _NO_ switch cond */
- int is_modeb_cond = get_irn_opcode(cond) == iro_Cond
- && get_irn_mode(get_Cond_selector(cond)) == mode_b;
+ ir_node *block;
+ int saw_select_cond = 0;
+
+ block = get_nodes_block(irn);
+
+ /*
+ * Only check this block if it is dominated by the specified
+ * dominator or it has not been visited yet.
+ */
+ if (block_dominates(dominator, block) && get_Block_block_visited(block) < visited_nr) {
+ cond_t *res = masked_by;
+ int i, n;
+
+ /* check, if we're on a ProjX
+ *
+ * Further, the ProjX/Cond block must dominate the base block
+ * (the block with the phi in it), otherwise, the Cond
+ * is not affecting the phi so that a mux can be inserted.
+ */
+ if(is_Proj(irn) && get_irn_mode(irn) == mode_X) {
+
+ int proj = get_Proj_proj(irn);
+ ir_node *cond = get_Proj_pred(irn);
+
+ /* true, if the mode is a mode_b cond _NO_ switch cond */
+ int is_modeb_cond = get_irn_opcode(cond) == iro_Cond
+ && get_irn_mode(get_Cond_selector(cond)) == mode_b;
- /* Check, if the pred of the proj is a Cond
- * with a Projb as selector.
- */
- if(is_modeb_cond) {
- cond_t c;
-
- memset(&c, 0, sizeof(c));
- c.cond = cond;
- c.is_new = 1;
- c.cases[0].pos = -1;
- c.cases[1].pos = -1;
-
- /* get or insert the cond info into the set. */
- res = set_insert(ci->cond_set, &c, sizeof(c), HASH_PTR(cond));
-
- /*
- * If this cond is already masked by the masked_by cond
- * return immediately, since we don't have anything to add.
- */
- if(masked_by && res->cases[proj].masked_by == masked_by)
- return;
-
- if(res->is_new) {
- res->is_new = 0;
- list_add(&res->list, &ci->roots);
- }
-
- /*
- * Set masked by (either NULL or another cond node.
- * If this cond is truly masked by another one, set
- * the position of the actually investigated branch
- * to -1. Since the cond is masked by another one,
- * there could be more ways from the start block
- * to this branch, so we choose -1.
- */
- res->cases[proj].masked_by = masked_by;
-
- if(!masked_by)
- res->cases[proj].pos = pos;
-
- /*
- * Since the masked_by nodes masks a cond, remove it from the
- * root list of the conf trees.
- */
- else {
- assert(res->cases[proj].pos < 0);
- list_del_init(&masked_by->list);
- }
-
- DBG((dbg, LEVEL_2, "%D%n (%s branch) "
- "for pos %d in block %n reached by %n\n",
- depth, cond, proj ? "true" : "false", pos,
- block, masked_by ? masked_by->cond : NULL));
- }
- }
-
- if(get_Block_block_visited(block) < visited_nr && !saw_select_cond) {
-
- set_Block_block_visited(block, visited_nr);
-
- /* Search recursively from this cond. */
- for(i = 0, n = get_irn_arity(block); i < n; ++i) {
- ir_node *pred = get_irn_n(block, i);
-
- /*
- * If the depth is 0 (the first recursion), we set the pos to
- * the current viewed predecessor, else we adopt the position
- * as given by the caller. We also increase the depth for the
- * recursively called functions.
- */
- _find_conds(pred, visited_nr, dominator, res, pos, depth + (res != masked_by), ci);
- }
- }
- }
+ /* Check, if the pred of the proj is a Cond
+ * with a Projb as selector.
+ */
+ if(is_modeb_cond) {
+ cond_t c;
+
+ memset(&c, 0, sizeof(c));
+ c.cond = cond;
+ c.is_new = 1;
+ c.cases[0].pos = -1;
+ c.cases[1].pos = -1;
+
+ /* get or insert the cond info into the set. */
+ res = set_insert(ci->cond_set, &c, sizeof(c), HASH_PTR(cond));
+
+ /*
+ * If this cond is already masked by the masked_by cond
+ * return immediately, since we don't have anything to add.
+ */
+ if(masked_by && res->cases[proj].masked_by == masked_by)
+ return;
+
+ if(res->is_new) {
+ res->is_new = 0;
+ list_add(&res->list, &ci->roots);
+ }
+
+ /*
+ * Set masked by (either NULL or another cond node.
+ * If this cond is truly masked by another one, set
+ * the position of the actually investigated branch
+ * to -1. Since the cond is masked by another one,
+ * there could be more ways from the start block
+ * to this branch, so we choose -1.
+ */
+ res->cases[proj].masked_by = masked_by;
+
+ if(!masked_by)
+ res->cases[proj].pos = pos;
+
+ /*
+ * Since the masked_by nodes masks a cond, remove it from the
+ * root list of the conf trees.
+ */
+ else {
+ assert(res->cases[proj].pos < 0);
+ list_del_init(&masked_by->list);
+ }
+
+ DBG((dbg, LEVEL_2, "%D%n (%s branch) "
+ "for pos %d in block %n reached by %n\n",
+ depth, cond, proj ? "true" : "false", pos,
+ block, masked_by ? masked_by->cond : NULL));
+ }
+ }
+
+ if(get_Block_block_visited(block) < visited_nr && !saw_select_cond) {
+
+ set_Block_block_visited(block, visited_nr);
+
+ /* Search recursively from this cond. */
+ for(i = 0, n = get_irn_arity(block); i < n; ++i) {
+ ir_node *pred = get_irn_n(block, i);
+
+ /*
+ * If the depth is 0 (the first recursion), we set the pos to
+ * the current viewed predecessor, else we adopt the position
+ * as given by the caller. We also increase the depth for the
+ * recursively called functions.
+ */
+ _find_conds(pred, visited_nr, dominator, res, pos, depth + (res != masked_by), ci);
+ }
+ }
+ }
- int i, can_move[2];
- ir_node *projb = get_Cond_selector(cond->cond);
- ir_node *bl = get_nodes_block(cond->cond);
- ir_node *operands[2];
- int set[2];
-
- cond->visited_nr = visited_nr;
- DBG((dbg, LEVEL_2, "%n\n", cond->cond));
- for(i = 0; i < 2; ++i) {
- cond_t *masked_by = cond->cases[i].masked_by;
- int pos = cond->cases[i].pos;
-
- operands[i] = NULL;
- set[i] = -1;
-
- /*
- * If this Cond branch is masked by another cond, make the mux
- * for that Cond first, since the Mux for this cond takes
- * it as an operand.
- */
- if(masked_by) {
- assert(pos < 0);
- DBG((dbg, LEVEL_2, "\tmasked by: %n\n", masked_by->cond));
- if(masked_by->visited_nr < visited_nr)
- operands[i] = make_mux_on_demand(phi, dom, masked_by, max_depth, mux, positions, muxes_made, visited_nr);
- }
-
- /*
- * If this cond branch is not masked by another cond, take
- * the corresponding phi operand as an operand to the mux.
- */
- else if(pos >= 0) {
- operands[i] = get_irn_n(phi, pos);
- set[i] = pos;
- }
- }
-
- /*
- * Move the operands to the dominator block if the cond
- * made sense. Some Conds found are not suitable for making a mux
- * out of them, since one of their branches cannot be reached from
- * the phi block. In that case we do not make a mux and return NULL.
- */
+ int i, can_move[2];
+ ir_node *projb = get_Cond_selector(cond->cond);
+ ir_node *bl = get_nodes_block(cond->cond);
+ ir_node *operands[2];
+ int set[2];
+
+ cond->visited_nr = visited_nr;
+ DBG((dbg, LEVEL_2, "%n\n", cond->cond));
+ for(i = 0; i < 2; ++i) {
+ cond_t *masked_by = cond->cases[i].masked_by;
+ int pos = cond->cases[i].pos;
+
+ operands[i] = NULL;
+ set[i] = -1;
+
+ /*
+ * If this Cond branch is masked by another cond, make the mux
+ * for that Cond first, since the Mux for this cond takes
+ * it as an operand.
+ */
+ if(masked_by) {
+ assert(pos < 0);
+ DBG((dbg, LEVEL_2, "\tmasked by: %n\n", masked_by->cond));
+ if(masked_by->visited_nr < visited_nr)
+ operands[i] = make_mux_on_demand(phi, dom, masked_by, info, mux, positions, muxes_made, visited_nr);
+ }
+
+ /*
+ * If this cond branch is not masked by another cond, take
+ * the corresponding phi operand as an operand to the mux.
+ */
+ else if(pos >= 0) {
+ operands[i] = get_irn_n(phi, pos);
+ set[i] = pos;
+ }
+ }
+
+ /*
+ * Move the operands to the dominator block if the cond
+ * made sense. Some Conds found are not suitable for making a mux
+ * out of them, since one of their branches cannot be reached from
+ * the phi block. In that case we do not make a mux and return NULL.
+ */
- move_to(operands[0], bl);
- move_to(operands[1], bl);
-
- /* Make the mux. */
- *mux = new_r_Mux(current_ir_graph, bl, projb,
- operands[0], operands[1], get_irn_mode(operands[0]));
-
- *muxes_made += 1;
-
- DBG((dbg, LEVEL_2, "\t%n(%n, %n, %n)[%d, %d]\n",
- *mux, projb, operands[0], operands[1], set[0], set[1]));
-
- for(i = 0; i < 2; ++i)
- if(set[i] >= 0) {
- bitset_set(positions, set[i]);
-
- /* we have done one */
- hook_if_conversion(current_ir_graph, phi, set[i], *mux, IF_RESULT_SUCCESS);
- }
+ if (info->allow_mux(projb, operands[0], operands[1])) {
+ move_to(operands[0], bl);
+ move_to(operands[1], bl);
+
+ /* Make the mux. */
+ *mux = new_r_Mux(current_ir_graph, bl, projb,
+ operands[0], operands[1], get_irn_mode(operands[0]));
+
+ *muxes_made += 1;
+
+ DBG((dbg, LEVEL_2, "\t%n(%n, %n, %n)[%d, %d]\n",
+ *mux, projb, operands[0], operands[1], set[0], set[1]));
+
+ for(i = 0; i < 2; ++i)
+ if(set[i] >= 0) {
+ bitset_set(positions, set[i]);
+
+ /* we have done one */
+ hook_if_conversion(current_ir_graph, phi, set[i], *mux, IF_RESULT_SUCCESS);
+ }
+ }
+ else {
+ hook_if_conversion(current_ir_graph, phi, set[i], *mux, IF_RESULT_DENIED);
+ }
- int max_depth = info->max_depth;
- 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, max_depth, &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;
+ 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;
- 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 free 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);
- }
-
- }
+ 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 free 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);
+ }
+
+ }
- 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");
- }
+ 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");
+ }