X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Flower%2Flower_mode_b.c;h=ea50c29ba59f525cdef3f2d043c1c3b6d9beb9f3;hb=58145b34ccd4c05fc1975cf8ba712e4b05cffa12;hp=00e6e1d83317ab6b79c6a3120c34946170a56c20;hpb=9d3c8631459f431c313160dab5778e8a7b88dd92;p=libfirm diff --git a/ir/lower/lower_mode_b.c b/ir/lower/lower_mode_b.c index 00e6e1d83..ea50c29ba 100644 --- a/ir/lower/lower_mode_b.c +++ b/ir/lower/lower_mode_b.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -32,7 +32,7 @@ * - The only nodes producing mode_b are: Proj(Cmp) and ConvB(X) (where X * is some mode that can be converted to the lowered mode). * ConvB will usually be implemented by a comparison with 0 producing some - * flags in the backends. It's debatable wether ConvB(X) is a goode idea. + * flags in the backends. It's debatable whether ConvB(X) is a good idea. * Maybe we should rather introduce a Test node. * All other former uses should be converted to manipulations with an integer * mode that was specified in the pass configuration. @@ -149,9 +149,6 @@ ir_node *ir_create_cond_set(ir_node *cond_value, ir_mode *dest_mode) set_irn_in(lower_block, ARRAY_SIZE(lower_in), lower_in); phi = new_r_Phi(lower_block, ARRAY_SIZE(phi_in), phi_in, dest_mode); - assert(get_Block_phis(lower_block) == NULL); - set_Block_phis(lower_block, phi); - set_Phi_next(phi, NULL); /* make sure we do visit the cond_value later... */ ARR_APP1(ir_node*, check_later, cond_value); @@ -161,9 +158,9 @@ ir_node *ir_create_cond_set(ir_node *cond_value, ir_mode *dest_mode) static void adjust_method_type(ir_type *method_type) { - int i; - int n_params; - int n_res; + size_t i; + size_t n_params; + size_t n_res; n_params = get_method_n_params(method_type); for (i = 0; i < n_params; ++i) { @@ -187,10 +184,9 @@ static ir_node *lower_node(ir_node *node) dbg_info *dbgi = get_irn_dbg_info(node); ir_node *block = get_nodes_block(node); ir_mode *mode = config->lowered_mode; + ir_node *res = (ir_node*)get_irn_link(node); ir_graph *irg; - ir_node *res; - res = get_irn_link(node); if (res != NULL) return res; @@ -276,73 +272,75 @@ static ir_node *lower_node(ir_node *node) ir_tarval *tv_zeroc = get_mode_null(mode); ir_node *zero_cmp = new_rd_Const(dbgi, irg, tv_zeroc); - ir_node *cmp = new_rd_Cmp(dbgi, block, pred, zero_cmp); - ir_node *proj = new_rd_Proj(dbgi, cmp, mode_b, pn_Cmp_Lg); - res = config->create_set(proj); + ir_node *cmp = new_rd_Cmp(dbgi, block, pred, zero_cmp, ir_relation_less_greater); + res = config->create_set(cmp); break; } - case iro_Proj: { - ir_node *pred = get_Proj_pred(node); - - if (is_Cmp(pred)) { - ir_node *left = get_Cmp_left(pred); - ir_node *right = get_Cmp_right(pred); - ir_mode *cmp_mode = get_irn_mode(left); - - if ((mode_is_int(cmp_mode) || mode_is_reference(cmp_mode)) && - (get_mode_size_bits(cmp_mode) < get_mode_size_bits(mode) || - (mode_is_signed(cmp_mode) && is_Const(right) && is_Const_null(right)))) { - int pnc = get_Proj_proj(node); - int need_not = 0; - ir_node *a = NULL; - ir_node *b = NULL; - int bits; - ir_tarval *tv; - ir_node *shift_cnt; - - if (pnc == pn_Cmp_Lt) { - /* a < b -> (a - b) >> 31 */ - a = left; - b = right; - } else if (pnc == pn_Cmp_Le) { - /* a <= b -> ~(a - b) >> 31 */ - a = right; - b = left; - need_not = 1; - } else if (pnc == pn_Cmp_Gt) { - /* a > b -> (b - a) >> 31 */ - a = right; - b = left; - } else if (pnc == pn_Cmp_Ge) { - /* a >= b -> ~(a - b) >> 31 */ - a = left; - b = right; - need_not = 1; - } else { - goto synth_zero_one; - } + case iro_Cmp: { + ir_node *left = get_Cmp_left(node); + ir_node *right = get_Cmp_right(node); + ir_mode *cmp_mode = get_irn_mode(left); + + if ((mode_is_int(cmp_mode) || mode_is_reference(cmp_mode)) && + (get_mode_size_bits(cmp_mode) < get_mode_size_bits(mode) || + (mode_is_signed(cmp_mode) && is_Const(right) && is_Const_null(right)))) { + ir_relation relation = get_Cmp_relation(node); + int need_not = 0; + ir_node *a = NULL; + ir_node *b = NULL; + int bits; + ir_tarval *tv; + ir_node *shift_cnt; + + if (relation == ir_relation_less) { + /* a < b -> (a - b) >> 31 */ + a = left; + b = right; + } else if (relation == ir_relation_less_equal) { + /* a <= b -> ~(a - b) >> 31 */ + a = right; + b = left; + need_not = 1; + } else if (relation == ir_relation_greater) { + /* a > b -> (b - a) >> 31 */ + a = right; + b = left; + } else if (relation == ir_relation_greater_equal) { + /* a >= b -> ~(a - b) >> 31 */ + a = left; + b = right; + need_not = 1; + } else { + goto synth_zero_one; + } - bits = get_mode_size_bits(mode); - tv = new_tarval_from_long(bits-1, mode_Iu); - shift_cnt = new_rd_Const(dbgi, irg, tv); + bits = get_mode_size_bits(mode); + tv = new_tarval_from_long(bits-1, mode_Iu); + shift_cnt = new_rd_Const(dbgi, irg, tv); - if (cmp_mode != mode) { - a = new_rd_Conv(dbgi, block, a, mode); - b = new_rd_Conv(dbgi, block, b, mode); - } + if (cmp_mode != mode) { + a = new_rd_Conv(dbgi, block, a, mode); + b = new_rd_Conv(dbgi, block, b, mode); + } - res = new_rd_Sub(dbgi, block, a, b, mode); - if (need_not) { - res = new_rd_Not(dbgi, block, res, mode); - } - res = new_rd_Shr(dbgi, block, res, shift_cnt, mode); - } else { - /* synthesize the 0/1 value */ -synth_zero_one: - res = config->create_set(node); + res = new_rd_Sub(dbgi, block, a, b, mode); + if (need_not) { + res = new_rd_Not(dbgi, block, res, mode); } - } else if (is_Proj(pred) && is_Call(get_Proj_pred(pred))) { + res = new_rd_Shr(dbgi, block, res, shift_cnt, mode); + } else { + /* synthesize the 0/1 value */ +synth_zero_one: + res = config->create_set(node); + } + break; + } + + case iro_Proj: { + ir_node *pred = get_Proj_pred(node); + + if (is_Proj(pred) && is_Call(get_Proj_pred(pred))) { ir_type *type = get_Call_type(get_Proj_pred(pred)); adjust_method_type(type); set_irn_mode(node, mode); @@ -403,15 +401,13 @@ static void lower_mode_b_walker(ir_node *node, void *env) continue; if (! config->lower_direct_cmp) { - /* Proj(Cmp) as input for Cond and Mux nodes needs no changes. + /* Cmp as input for Cond and Mux nodes needs no changes. (Mux with mode_b is an exception as it gets replaced by and/or anyway so we still lower the inputs then) */ if (is_Cond(node) || (is_Mux(node) && get_irn_mode(node) != mode_b)) { - if (is_Proj(in)) { - ir_node *pred = get_Proj_pred(in); - if (is_Cmp(pred)) - continue; + if (is_Cmp(in)) { + continue; } } } @@ -428,7 +424,7 @@ static void lower_mode_b_walker(ir_node *node, void *env) changed = true; } if (changed) { - bool *global_changed = env; + bool *global_changed = (bool*)env; *global_changed = true; add_identities(node); } @@ -439,8 +435,8 @@ void ir_lower_mode_b(ir_graph *irg, const lower_mode_b_config_t *nconfig) ir_entity *entity = get_irg_entity(irg); ir_type *type = get_entity_type(entity); bool changed = false; - int i; - int n; + size_t i; + size_t n; config = nconfig; lowered_nodes = NEW_ARR_F(ir_node*, 0); @@ -459,13 +455,12 @@ void ir_lower_mode_b(ir_graph *irg, const lower_mode_b_config_t *nconfig) irg_walk_graph(irg, firm_clear_link, NULL, NULL); irg_walk_graph(irg, lower_mode_b_walker, NULL, &changed); - for (i = 0; i < ARR_LEN(check_later); ++i) { + for (i = 0, n = ARR_LEN(check_later); i < n; ++i) { ir_node *node = check_later[i]; irg_walk_core(node, lower_mode_b_walker, NULL, &changed); } - n = ARR_LEN(lowered_nodes); - for (i = 0; i < n; ++i) { + for (i = 0, n = ARR_LEN(lowered_nodes); i < n; ++i) { ir_node *node = lowered_nodes[i]; maybe_kill_node(node); }