X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fia32%2Fia32_address_mode.c;h=2b4ff29b45c146bda2191c3de60771067cd4d9a6;hb=f9e10681f491baabe1e401a429f7f68c76b38062;hp=6bdc1721698190ca15e59bce3a8d3200759e9757;hpb=ce6161a7e42a48f7422b7babcc64d8ace18e2687;p=libfirm diff --git a/ir/be/ia32/ia32_address_mode.c b/ir/be/ia32/ia32_address_mode.c index 6bdc17216..2b4ff29b4 100644 --- a/ir/be/ia32/ia32_address_mode.c +++ b/ir/be/ia32/ia32_address_mode.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2010 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -55,7 +55,7 @@ static bitset_t *non_address_mode_nodes; * * @return non-zero if the DAG represents an immediate, 0 else */ -static int do_is_immediate(const ir_node *node, int *symconsts, int negate) +static bool do_is_immediate(const ir_node *node, int *symconsts, bool negate) { ir_node *left; ir_node *right; @@ -69,63 +69,46 @@ static int do_is_immediate(const ir_node *node, int *symconsts, int negate) "Optimisation warning tarval of %+F(%+F) is not a long.\n", node, current_ir_graph); #endif - return 0; + return false; } - return 1; + return true; case iro_SymConst: /* the first SymConst of a DAG can be fold into an immediate */ #ifndef SUPPORT_NEGATIVE_SYMCONSTS /* unfortunately the assembler/linker doesn't support -symconst */ if (negate) - return 0; + return false; #endif - if (get_SymConst_kind(node) != symconst_addr_ent) - return 0; - (*symconsts)++; - if (*symconsts > 1) - return 0; + return false; + if (++*symconsts > 1) + return false; - return 1; + return true; case iro_Unknown: /* we can use '0' for Unknowns */ - return 1; + return true; case iro_Add: case iro_Sub: /* Add's and Sub's are typically supported as long as both operands are * immediates */ if (ia32_is_non_address_mode_node(node)) - return 0; + return false; - left = get_binop_left(node); - right = get_binop_right(node); + left = get_binop_left(node); if (!do_is_immediate(left, symconsts, negate)) - return 0; + return false; + right = get_binop_right(node); if (!do_is_immediate(right, symconsts, is_Sub(node) ? !negate : negate)) - return 0; + return false; - return 1; + return true; default: /* all other nodes are NO immediates */ - return 0; + return false; } } -/** - * Checks if a DAG with a single root node can be represented as a simple immediate. - * - * @param node the node - * - * @return non-zero if the DAG represents an immediate, 0 else - */ -#if 0 -static int is_immediate_simple(const ir_node *node) -{ - int symconsts = 0; - return do_is_immediate(node, &symconsts, 0); -} -#endif - /** * Check if a DAG starting with root node can be folded into an address mode * as an immediate. @@ -134,7 +117,7 @@ static int is_immediate_simple(const ir_node *node) * @param node the node * @param negate if set, the immediate must be negated */ -static int is_immediate(ia32_address_t *addr, const ir_node *node, int negate) +static int is_immediate(ia32_address_t *addr, const ir_node *node, bool negate) { int symconsts = (addr->symconst_ent != NULL); return do_is_immediate(node, &symconsts, negate); @@ -147,7 +130,7 @@ static int is_immediate(ia32_address_t *addr, const ir_node *node, int negate) * @param node the node * @param negate if set, the immediate must be negated */ -static void eat_immediate(ia32_address_t *addr, ir_node *node, int negate) +static void eat_immediate(ia32_address_t *addr, ir_node *node, bool negate) { ir_tarval *tv; ir_node *left; @@ -171,6 +154,8 @@ static void eat_immediate(ia32_address_t *addr, ir_node *node, int negate) panic("Internal error: more than 1 symconst in address calculation"); } addr->symconst_ent = get_SymConst_entity(node); + if (get_entity_owner(addr->symconst_ent) == get_tls_type()) + addr->tls_segment = true; #ifndef SUPPORT_NEGATIVE_SYMCONSTS assert(!negate); #endif @@ -181,15 +166,15 @@ static void eat_immediate(ia32_address_t *addr, ir_node *node, int negate) case iro_Add: assert(!ia32_is_non_address_mode_node(node)); left = get_Add_left(node); - right = get_Add_right(node); eat_immediate(addr, left, negate); + right = get_Add_right(node); eat_immediate(addr, right, negate); break; case iro_Sub: assert(!ia32_is_non_address_mode_node(node)); left = get_Sub_left(node); - right = get_Sub_right(node); eat_immediate(addr, left, negate); + right = get_Sub_right(node); eat_immediate(addr, right, !negate); break; default: @@ -432,6 +417,10 @@ int ia32_is_non_address_mode_node(ir_node const *node) return bitset_is_set(non_address_mode_nodes, get_irn_idx(node)); } +/** + * Check if a given value is last used (i.e. die after) the block of some + * other node. + */ static int value_last_used_here(be_lv_t *lv, ir_node *here, ir_node *value) { ir_node *block = get_nodes_block(here); @@ -453,6 +442,12 @@ static int value_last_used_here(be_lv_t *lv, ir_node *here, ir_node *value) return 1; } +static bool simple_is_immediate(const ir_node *node) +{ + int symconsts = 0; + return do_is_immediate(node, &symconsts, false); +} + /** * Walker: mark those nodes that cannot be part of an address mode because * their value must be accessed through a register @@ -498,12 +493,17 @@ static void mark_non_address_nodes(ir_node *node, void *env) left = get_binop_left(node); right = get_binop_right(node); - /* Fold AM if any of the two operands does not die here. This duplicates + /* if any of the operands is an immediate then this will not + * increase register pressure */ + if (simple_is_immediate(left) || simple_is_immediate(right)) + return; + + /* Fold AM if any of the two operands does not die here. This duplicates * an addition and has the same register pressure for the case that only * one operand dies, but is faster (on Pentium 4). * && instead of || only folds AM if both operands do not die here */ if (!value_last_used_here(lv, node, left) || - !value_last_used_here(lv, node, right)) { + !value_last_used_here(lv, node, right)) { return; }