X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firopt.c;h=bd60eb809148a6abc6f8fec192e15ca23f6a2ddd;hb=8711df01fa5919e55a10ac1e8a594bde1a2b6e46;hp=ffafca6ed5cdc72f219aa8d1573358aa368226dc;hpb=236c08e56b840c915b71f039948a12ee9b23cc75;p=libfirm diff --git a/ir/ir/iropt.c b/ir/ir/iropt.c index ffafca6ed..bd60eb809 100644 --- a/ir/ir/iropt.c +++ b/ir/ir/iropt.c @@ -43,7 +43,6 @@ #include "irhooks.h" #include "irarch.h" #include "hashptr.h" -#include "opt_polymorphy.h" #include "irtools.h" #include "irhooks.h" #include "array_t.h" @@ -52,7 +51,6 @@ #include "bitfiddle.h" #include "be.h" -/* Make types visible to allow most efficient access */ #include "entity_t.h" static bool is_Or_Eor_Add(const ir_node *node) @@ -84,7 +82,6 @@ static ir_tarval *default_value_of(const ir_node *n) value_of_func value_of_ptr = default_value_of; -/* * Set a new value_of function. */ void set_value_of_func(value_of_func func) { if (func != NULL) @@ -617,6 +614,17 @@ static ir_tarval *compute_cmp(const ir_node *cmp) return computed_value_Cmp_Confirm(cmp, left, right, relation); } +/** + * some people want to call compute_cmp directly, in this case we have to + * test the constant folding flag again + */ +static ir_tarval *compute_cmp_ext(const ir_node *cmp) +{ + if (!get_opt_constant_folding()) + return tarval_bad; + return compute_cmp(cmp); +} + /** * Return the value of a Cmp. * @@ -1474,7 +1482,7 @@ static ir_node *equivalent_node_Mux(ir_node *n) if (ts == tarval_bad && is_Cmp(sel)) { /* try again with a direct call to compute_cmp, as we don't care * about the MODEB_LOWERED flag here */ - ts = compute_cmp(sel); + ts = compute_cmp_ext(sel); } /* Mux(true, f, t) == t */ @@ -3542,7 +3550,7 @@ static ir_node *transform_node_Cond(ir_node *n) if (ta == tarval_bad && is_Cmp(a)) { /* try again with a direct call to compute_cmp, as we don't care * about the MODEB_LOWERED flag here */ - ta = compute_cmp(a); + ta = compute_cmp_ext(a); } if (ta != tarval_bad && get_irn_mode(a) == mode_b) { @@ -4066,27 +4074,25 @@ static ir_node *transform_node_Minus(ir_node *n) */ static ir_node *transform_node_Proj_Load(ir_node *proj) { - if (get_opt_ldst_only_null_ptr_exceptions()) { - if (get_irn_mode(proj) == mode_X) { - ir_node *load = get_Proj_pred(proj); + if (get_irn_mode(proj) == mode_X) { + ir_node *load = get_Proj_pred(proj); - /* get the Load address */ - const ir_node *addr = get_Load_ptr(load); - const ir_node *confirm; + /* get the Load address */ + const ir_node *addr = get_Load_ptr(load); + const ir_node *confirm; - if (value_not_null(addr, &confirm)) { - if (confirm == NULL) { - /* this node may float if it did not depend on a Confirm */ - set_irn_pinned(load, op_pin_state_floats); - } - if (get_Proj_proj(proj) == pn_Load_X_except) { - ir_graph *irg = get_irn_irg(proj); - DBG_OPT_EXC_REM(proj); - return new_r_Bad(irg, mode_X); - } else { - ir_node *blk = get_nodes_block(load); - return new_r_Jmp(blk); - } + if (value_not_null(addr, &confirm)) { + if (confirm == NULL) { + /* this node may float if it did not depend on a Confirm */ + set_irn_pinned(load, op_pin_state_floats); + } + if (get_Proj_proj(proj) == pn_Load_X_except) { + ir_graph *irg = get_irn_irg(proj); + DBG_OPT_EXC_REM(proj); + return new_r_Bad(irg, mode_X); + } else { + ir_node *blk = get_nodes_block(load); + return new_r_Jmp(blk); } } } @@ -4098,27 +4104,25 @@ static ir_node *transform_node_Proj_Load(ir_node *proj) */ static ir_node *transform_node_Proj_Store(ir_node *proj) { - if (get_opt_ldst_only_null_ptr_exceptions()) { - if (get_irn_mode(proj) == mode_X) { - ir_node *store = get_Proj_pred(proj); + if (get_irn_mode(proj) == mode_X) { + ir_node *store = get_Proj_pred(proj); - /* get the load/store address */ - const ir_node *addr = get_Store_ptr(store); - const ir_node *confirm; + /* get the load/store address */ + const ir_node *addr = get_Store_ptr(store); + const ir_node *confirm; - if (value_not_null(addr, &confirm)) { - if (confirm == NULL) { - /* this node may float if it did not depend on a Confirm */ - set_irn_pinned(store, op_pin_state_floats); - } - if (get_Proj_proj(proj) == pn_Store_X_except) { - ir_graph *irg = get_irn_irg(proj); - DBG_OPT_EXC_REM(proj); - return new_r_Bad(irg, mode_X); - } else { - ir_node *blk = get_nodes_block(store); - return new_r_Jmp(blk); - } + if (value_not_null(addr, &confirm)) { + if (confirm == NULL) { + /* this node may float if it did not depend on a Confirm */ + set_irn_pinned(store, op_pin_state_floats); + } + if (get_Proj_proj(proj) == pn_Store_X_except) { + ir_graph *irg = get_irn_irg(proj); + DBG_OPT_EXC_REM(proj); + return new_r_Bad(irg, mode_X); + } else { + ir_node *blk = get_nodes_block(store); + return new_r_Jmp(blk); } } } @@ -6372,7 +6376,6 @@ void firm_set_default_transform_node(ir_opcode code, ir_op_ops *ops) CASE(Phi); CASE(Proj); CASE(Rotl); - CASE(Sel); CASE(Shl); CASE(Shr); CASE(Shrs); @@ -6524,11 +6527,11 @@ static int node_cmp_attr_Sel(const ir_node *a, const ir_node *b) /** Compares the attributes of two Phi nodes. */ static int node_cmp_attr_Phi(const ir_node *a, const ir_node *b) { - /* we can only enter this function if both nodes have the same number of inputs, - hence it is enough to check if one of them is a Phi0 */ - if (is_Phi0(a)) { - /* check the Phi0 pos attribute */ - return a->attr.phi.u.pos != b->attr.phi.u.pos; + (void) b; + /* do not CSE Phi-nodes without any inputs when building new graphs */ + if (get_irn_arity(a) == 0 && + get_irg_phase_state(get_irn_irg(a)) == phase_building) { + return 1; } return 0; } @@ -6735,10 +6738,6 @@ void firm_set_default_node_cmp_attr(ir_opcode code, ir_op_ops *ops) #undef CASE } -/* - * Compare function for two nodes in the value table. Gets two - * nodes as parameters. Returns 0 if the nodes are a Common Sub Expression. - */ int identities_cmp(const void *elt, const void *key) { ir_node *a = (ir_node *)elt; @@ -6803,17 +6802,11 @@ int identities_cmp(const void *elt, const void *key) return 0; } -/* - * Calculate a hash value of a node. - * - * @param node The IR-node - */ unsigned ir_node_hash(const ir_node *node) { return node->op->ops.hash(node); } - void new_identities(ir_graph *irg) { if (irg->value_table != NULL) @@ -6827,8 +6820,6 @@ void del_identities(ir_graph *irg) del_pset(irg->value_table); } -/* Normalize a node by putting constants (and operands with larger - * node index) on the right (operator side). */ void ir_normalize_node(ir_node *n) { if (is_op_commutative(get_irn_op(n))) { @@ -6847,16 +6838,6 @@ void ir_normalize_node(ir_node *n) } } -/* - * Return the canonical node computing the same value as n. - * Looks up the node in a hash table, enters it in the table - * if it isn't there yet. - * - * @param n the node to look up - * - * @return a node that computes the same value as n or n if no such - * node could be found - */ ir_node *identify_remember(ir_node *n) { ir_graph *irg = get_irn_irg(n); @@ -6897,7 +6878,6 @@ static inline ir_node *identify_cons(ir_node *n) return n; } -/* Add a node to the identities value table. */ void add_identities(ir_node *node) { if (!get_opt_cse()) @@ -6908,7 +6888,6 @@ void add_identities(ir_node *node) identify_remember(node); } -/* Visit each node in the value table of a graph. */ void visit_all_identities(ir_graph *irg, irg_walk_func visit, void *env) { ir_node *node; @@ -6921,13 +6900,6 @@ void visit_all_identities(ir_graph *irg, irg_walk_func visit, void *env) current_ir_graph = rem; } -/** - * These optimizations deallocate nodes from the obstack. - * It can only be called if it is guaranteed that no other nodes - * reference this one, i.e., right after construction of a node. - * - * @param n The node to optimize - */ ir_node *optimize_node(ir_node *n) { ir_node *oldn = n; @@ -7020,12 +6992,6 @@ ir_node *optimize_node(ir_node *n) return n; } - -/** - * These optimizations never deallocate nodes (in place). This can cause dead - * nodes lying on the obstack. Remove these by a dead node elimination, - * i.e., a copying garbage collection. - */ ir_node *optimize_in_place_2(ir_node *n) { if (!get_opt_optimize() && !is_Phi(n)) return n; @@ -7071,9 +7037,6 @@ ir_node *optimize_in_place_2(ir_node *n) return n; } -/** - * Wrapper for external use, set proper status bits after optimization. - */ ir_node *optimize_in_place(ir_node *n) { ir_graph *irg = get_irn_irg(n); @@ -7097,7 +7060,7 @@ static unsigned hash_Const(const ir_node *node) unsigned h; /* special value for const, as they only differ in their tarval. */ - h = HASH_PTR(node->attr.con.tarval); + h = hash_ptr(node->attr.con.tarval); return h; } @@ -7110,7 +7073,7 @@ static unsigned hash_SymConst(const ir_node *node) unsigned h; /* all others are pointers */ - h = HASH_PTR(node->attr.symc.sym.type_p); + h = hash_ptr(node->attr.symc.sym.type_p); return h; }