X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firopt.c;h=dbcbe6c76978ea473197321ecd73a53b14b92092;hb=8399216d8aebc713bbda04b6e3e250a1d52b20bf;hp=6b3e6b4187810cd51166aff5f6eadbea1e9e20f3;hpb=9fe9c20a1570729f1bdd21a6f174ec045d2ff986;p=libfirm diff --git a/ir/ir/iropt.c b/ir/ir/iropt.c index 6b3e6b418..dbcbe6c76 100644 --- a/ir/ir/iropt.c +++ b/ir/ir/iropt.c @@ -42,12 +42,6 @@ /* Make types visible to allow most efficient access */ # include "entity_t.h" -# ifdef DO_HEAPANALYSIS -/* heapanal can't cope with NoMems */ -# else /* if defined DO_HEAPANALYSIS */ -# define USE_NOMEM -# endif /* defined DO_HEAPANALYSIS */ - /** * Trivial INLINEable routine for copy propagation. * Does follow Ids, needed to optimize INLINEd code. @@ -513,6 +507,26 @@ static tarval *computed_value_Proj(ir_node *n) return tarval_bad; } +/** + * calculate the value of a Mux: can be evaluated, if the + * sel and the right input are known + */ +static tarval *computed_value_Mux(ir_node *n) +{ + ir_node *sel = get_Mux_sel(n); + tarval *ts = value_of(sel); + + if (ts == get_tarval_b_true()) { + ir_node *v = get_Mux_true(n); + return value_of(v); + } + else if (ts == get_tarval_b_false()) { + ir_node *v = get_Mux_false(n); + return value_of(v); + } + return tarval_bad; +} + /** * If the parameter n can be computed, return its value, else tarval_bad. * Performs constant folding. @@ -557,6 +571,7 @@ static ir_op *firm_set_default_computed_value(ir_op *op) CASE(Rot); CASE(Conv); CASE(Proj); + CASE(Mux); default: op->computed_value = NULL; } @@ -1062,6 +1077,22 @@ static ir_node *equivalent_node_Id(ir_node *n) return n; } +/** + * optimize a Mux + */ +static ir_node *equivalent_node_Mux(ir_node *n) +{ + ir_node *sel = get_Mux_sel(n); + tarval *ts = value_of(sel); + + if (ts == get_tarval_b_true()) + return get_Mux_true(n); + else if (ts == get_tarval_b_false()) + return get_Mux_false(n); + + return n; +} + /** * equivalent_node() returns a node equivalent to input n. It skips all nodes that * perform no actual computation, as, e.g., the Id nodes. It does not create @@ -1110,6 +1141,7 @@ static ir_op *firm_set_default_equivalent_node(ir_op *op) CASE(Phi); CASE(Proj); CASE(Id); + CASE(Mux); default: op->equivalent_node = NULL; } @@ -1466,9 +1498,7 @@ static ir_node *transform_node_Proj(ir_node *proj) } else { /* the memory Proj can be removed */ ir_node *res = get_Div_mem(n); -# ifdef USE_NOMEM set_Div_mem(n, get_irg_no_mem(current_ir_graph)); -# endif /* defined USE_NOMEM */ if (proj_nr == pn_Div_M) return res; } @@ -1490,9 +1520,7 @@ static ir_node *transform_node_Proj(ir_node *proj) } else { /* the memory Proj can be removed */ ir_node *res = get_Mod_mem(n); -# ifdef USE_NOMEM set_Mod_mem(n, get_irg_no_mem(current_ir_graph)); -# endif /* defined USE_NOMEM */ if (proj_nr == pn_Mod_M) return res; } @@ -1515,9 +1543,7 @@ static ir_node *transform_node_Proj(ir_node *proj) else { /* the memory Proj can be removed */ ir_node *res = get_DivMod_mem(n); -# ifdef USE_NOMEM set_DivMod_mem(n, get_irg_no_mem(current_ir_graph)); -# endif /* defined USE_NOMEM */ if (proj_nr == pn_DivMod_M) return res; }