Commit 6dd8f4bb by Bill Schmidt Committed by William Schmidt

tree-ssa-loop-ivopts.c (mbc_entry_hash): Remove.

2012-07-26  Bill Schmidt  <wschmidt@linux.ibm.com>

	* tree-ssa-loop-ivopts.c (mbc_entry_hash): Remove.
	(mbc_entry_eq): Likewise.
	(mult_costs): Likewise.
	(cost_tables_exist): Likewise.
	(initialize_costs): Likewise.
	(finalize_costs): Likewise.
	(tree_ssa_iv_optimize_init): Remove call to initialize_costs.
	(add_regs_cost): Remove.
	(multiply_regs_cost): Likewise.
	(add_const_cost): Likewise.
	(extend_or_trunc_reg_cost): Likewise.
	(negate_reg_cost): Likewise.
	(struct mbc_entry): Likewise.
	(multiply_by_const_cost): Likewise.
	(get_address_cost): Change add_regs_cost calls to add_cost lookups;
	change multiply_by_const_cost to mult_by_coeff_cost.
	(force_expr_to_var_cost): Likewise.
	(difference_cost): Change multiply_by_const_cost to mult_by_coeff_cost.
	(get_computation_cost_at): Change add_regs_cost calls to add_cost
	lookups; change multiply_by_const_cost to mult_by_coeff_cost.
	(determine_iv_cost): Change add_regs_cost calls to add_cost lookups.
	(tree_ssa_iv_optimize_finalize): Remove call to finalize_costs.
	* tree-ssa-address.c (expmed.h): New #include.
	(most_expensive_mult_to_index): Change multiply_by_const_cost to
	mult_by_coeff_cost.
	* gimple-ssa-strength-reduction.c (expmed.h): New #include.
	(stmt_cost): Change to use mult_by_coeff_cost, mul_cost, add_cost,
	neg_cost, and convert_cost instead of IVOPTS interfaces.
	(execute_strength_reduction): Remove calls to initialize_costs and
	finalize_costs.
	* expmed.c (struct init_expmed_rtl): Add convert rtx_def.
	(init_expmed_one_mode): Initialize convert rtx_def; initialize
	x_convert_cost for related modes.
	(mult_by_coeff_cost): New function.
	* expmed.h (NUM_MODE_INT): New #define.
	(struct target_expmed): Add x_convert_cost matrix.
	(set_convert_cost): New inline function.
	(convert_cost): Likewise.
	(mult_by_coeff_cost): New extern decl.
	* tree-flow.h (initialize_costs): Remove decl.
	(finalize_costs): Likewise.
	(multiply_by_const_cost): Likewise.
	(add_regs_cost): Likewise.
	(multiply_regs_cost): Likewise.
	(add_const_cost): Likewise.
	(extend_or_trunc_reg_cost): Likewise.
	(negate_reg_cost): Likewise.
	* Makefile.in (gimple-ssa-strength-reduction.o): Update dependencies.
	(tree-ssa-address.o): Update dependencies.

From-SVN: r189890
parent 0263463d
2012-07-26 Bill Schmidt <wschmidt@linux.ibm.com>
* tree-ssa-loop-ivopts.c (mbc_entry_hash): Remove.
(mbc_entry_eq): Likewise.
(mult_costs): Likewise.
(cost_tables_exist): Likewise.
(initialize_costs): Likewise.
(finalize_costs): Likewise.
(tree_ssa_iv_optimize_init): Remove call to initialize_costs.
(add_regs_cost): Remove.
(multiply_regs_cost): Likewise.
(add_const_cost): Likewise.
(extend_or_trunc_reg_cost): Likewise.
(negate_reg_cost): Likewise.
(struct mbc_entry): Likewise.
(multiply_by_const_cost): Likewise.
(get_address_cost): Change add_regs_cost calls to add_cost lookups;
change multiply_by_const_cost to mult_by_coeff_cost.
(force_expr_to_var_cost): Likewise.
(difference_cost): Change multiply_by_const_cost to mult_by_coeff_cost.
(get_computation_cost_at): Change add_regs_cost calls to add_cost
lookups; change multiply_by_const_cost to mult_by_coeff_cost.
(determine_iv_cost): Change add_regs_cost calls to add_cost lookups.
(tree_ssa_iv_optimize_finalize): Remove call to finalize_costs.
* tree-ssa-address.c (expmed.h): New #include.
(most_expensive_mult_to_index): Change multiply_by_const_cost to
mult_by_coeff_cost.
* gimple-ssa-strength-reduction.c (expmed.h): New #include.
(stmt_cost): Change to use mult_by_coeff_cost, mul_cost, add_cost,
neg_cost, and convert_cost instead of IVOPTS interfaces.
(execute_strength_reduction): Remove calls to initialize_costs and
finalize_costs.
* expmed.c (struct init_expmed_rtl): Add convert rtx_def.
(init_expmed_one_mode): Initialize convert rtx_def; initialize
x_convert_cost for related modes.
(mult_by_coeff_cost): New function.
* expmed.h (NUM_MODE_INT): New #define.
(struct target_expmed): Add x_convert_cost matrix.
(set_convert_cost): New inline function.
(convert_cost): Likewise.
(mult_by_coeff_cost): New extern decl.
* tree-flow.h (initialize_costs): Remove decl.
(finalize_costs): Likewise.
(multiply_by_const_cost): Likewise.
(add_regs_cost): Likewise.
(multiply_regs_cost): Likewise.
(add_const_cost): Likewise.
(extend_or_trunc_reg_cost): Likewise.
(negate_reg_cost): Likewise.
* Makefile.in (gimple-ssa-strength-reduction.o): Update dependencies.
(tree-ssa-address.o): Update dependencies.
2012-07-26 Steven Bosscher <steven@gcc.gnu.org> 2012-07-26 Steven Bosscher <steven@gcc.gnu.org>
* bitmap.h: Add explanation of sparse set as linked-list bitmap. * bitmap.h: Add explanation of sparse set as linked-list bitmap.
......
...@@ -2355,7 +2355,7 @@ gimple-ssa-strength-reduction.o : gimple-ssa-strength-reduction.c $(CONFIG_H) \ ...@@ -2355,7 +2355,7 @@ gimple-ssa-strength-reduction.o : gimple-ssa-strength-reduction.c $(CONFIG_H) \
$(SYSTEM_H) coretypes.h $(TREE_H) $(GIMPLE_H) $(BASIC_BLOCK_H) \ $(SYSTEM_H) coretypes.h $(TREE_H) $(GIMPLE_H) $(BASIC_BLOCK_H) \
$(TREE_PASS_H) $(CFGLOOP_H) $(TREE_PRETTY_PRINT_H) \ $(TREE_PASS_H) $(CFGLOOP_H) $(TREE_PRETTY_PRINT_H) \
$(GIMPLE_PRETTY_PRINT_H) alloc-pool.h $(TREE_FLOW_H) domwalk.h \ $(GIMPLE_PRETTY_PRINT_H) alloc-pool.h $(TREE_FLOW_H) domwalk.h \
pointer-set.h pointer-set.h expmed.h
tree-vrp.o : tree-vrp.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \ tree-vrp.o : tree-vrp.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
$(TREE_FLOW_H) $(TREE_PASS_H) $(DIAGNOSTIC_CORE_H) $(GGC_H) \ $(TREE_FLOW_H) $(TREE_PASS_H) $(DIAGNOSTIC_CORE_H) $(GGC_H) \
$(BASIC_BLOCK_H) tree-ssa-propagate.h $(FLAGS_H) $(TREE_DUMP_H) \ $(BASIC_BLOCK_H) tree-ssa-propagate.h $(FLAGS_H) $(TREE_DUMP_H) \
...@@ -2423,7 +2423,7 @@ tree-ssa-address.o : tree-ssa-address.c $(TREE_FLOW_H) $(CONFIG_H) \ ...@@ -2423,7 +2423,7 @@ tree-ssa-address.o : tree-ssa-address.c $(TREE_FLOW_H) $(CONFIG_H) \
$(DIAGNOSTIC_H) $(TM_H) coretypes.h dumpfile.h \ $(DIAGNOSTIC_H) $(TM_H) coretypes.h dumpfile.h \
$(FLAGS_H) $(TREE_INLINE_H) $(RECOG_H) insn-config.h \ $(FLAGS_H) $(TREE_INLINE_H) $(RECOG_H) insn-config.h \
$(EXPR_H) gt-tree-ssa-address.h $(GGC_H) tree-affine.h $(TARGET_H) \ $(EXPR_H) gt-tree-ssa-address.h $(GGC_H) tree-affine.h $(TARGET_H) \
$(TREE_PRETTY_PRINT_H) $(TREE_PRETTY_PRINT_H) expmed.h
tree-ssa-loop-niter.o : tree-ssa-loop-niter.c $(TREE_FLOW_H) $(CONFIG_H) \ tree-ssa-loop-niter.o : tree-ssa-loop-niter.c $(TREE_FLOW_H) $(CONFIG_H) \
$(SYSTEM_H) $(TREE_H) $(TM_P_H) $(CFGLOOP_H) $(PARAMS_H) \ $(SYSTEM_H) $(TREE_H) $(TM_P_H) $(CFGLOOP_H) $(PARAMS_H) \
$(TREE_INLINE_H) $(DIAGNOSTIC_H) $(TM_H) coretypes.h dumpfile.h \ $(TREE_INLINE_H) $(DIAGNOSTIC_H) $(TM_H) coretypes.h dumpfile.h \
......
...@@ -112,6 +112,7 @@ struct init_expmed_rtl ...@@ -112,6 +112,7 @@ struct init_expmed_rtl
struct rtx_def shift_add; rtunion shift_add_fld1; struct rtx_def shift_add; rtunion shift_add_fld1;
struct rtx_def shift_sub0; rtunion shift_sub0_fld1; struct rtx_def shift_sub0; rtunion shift_sub0_fld1;
struct rtx_def shift_sub1; rtunion shift_sub1_fld1; struct rtx_def shift_sub1; rtunion shift_sub1_fld1;
struct rtx_def convert;
rtx pow2[MAX_BITS_PER_WORD]; rtx pow2[MAX_BITS_PER_WORD];
rtx cint[MAX_BITS_PER_WORD]; rtx cint[MAX_BITS_PER_WORD];
...@@ -122,6 +123,7 @@ init_expmed_one_mode (struct init_expmed_rtl *all, ...@@ -122,6 +123,7 @@ init_expmed_one_mode (struct init_expmed_rtl *all,
enum machine_mode mode, int speed) enum machine_mode mode, int speed)
{ {
int m, n, mode_bitsize; int m, n, mode_bitsize;
enum machine_mode mode_from;
mode_bitsize = GET_MODE_UNIT_BITSIZE (mode); mode_bitsize = GET_MODE_UNIT_BITSIZE (mode);
...@@ -139,6 +141,7 @@ init_expmed_one_mode (struct init_expmed_rtl *all, ...@@ -139,6 +141,7 @@ init_expmed_one_mode (struct init_expmed_rtl *all,
PUT_MODE (&all->shift_add, mode); PUT_MODE (&all->shift_add, mode);
PUT_MODE (&all->shift_sub0, mode); PUT_MODE (&all->shift_sub0, mode);
PUT_MODE (&all->shift_sub1, mode); PUT_MODE (&all->shift_sub1, mode);
PUT_MODE (&all->convert, mode);
add_cost[speed][mode] = set_src_cost (&all->plus, speed); add_cost[speed][mode] = set_src_cost (&all->plus, speed);
neg_cost[speed][mode] = set_src_cost (&all->neg, speed); neg_cost[speed][mode] = set_src_cost (&all->neg, speed);
...@@ -183,6 +186,30 @@ init_expmed_one_mode (struct init_expmed_rtl *all, ...@@ -183,6 +186,30 @@ init_expmed_one_mode (struct init_expmed_rtl *all,
mul_highpart_cost[speed][mode] mul_highpart_cost[speed][mode]
= set_src_cost (&all->wide_trunc, speed); = set_src_cost (&all->wide_trunc, speed);
} }
for (mode_from = GET_CLASS_NARROWEST_MODE (MODE_INT);
mode_from != VOIDmode;
mode_from = GET_MODE_WIDER_MODE (mode_from))
if (mode != mode_from)
{
unsigned short size_to = GET_MODE_SIZE (mode);
unsigned short size_from = GET_MODE_SIZE (mode_from);
if (size_to < size_from)
{
PUT_CODE (&all->convert, TRUNCATE);
PUT_MODE (&all->reg, mode_from);
set_convert_cost (mode, mode_from, speed,
set_src_cost (&all->convert, speed));
}
else if (size_from < size_to)
{
/* Assume cost of zero-extend and sign-extend is the same. */
PUT_CODE (&all->convert, ZERO_EXTEND);
PUT_MODE (&all->reg, mode_from);
set_convert_cost (mode, mode_from, speed,
set_src_cost (&all->convert, speed));
}
}
} }
} }
...@@ -262,6 +289,9 @@ init_expmed (void) ...@@ -262,6 +289,9 @@ init_expmed (void)
XEXP (&all.shift_sub1, 0) = &all.reg; XEXP (&all.shift_sub1, 0) = &all.reg;
XEXP (&all.shift_sub1, 1) = &all.shift_mult; XEXP (&all.shift_sub1, 1) = &all.shift_mult;
PUT_CODE (&all.convert, TRUNCATE);
XEXP (&all.convert, 0) = &all.reg;
for (speed = 0; speed < 2; speed++) for (speed = 0; speed < 2; speed++)
{ {
crtl->maybe_hot_insn_p = speed; crtl->maybe_hot_insn_p = speed;
...@@ -3262,6 +3292,24 @@ expand_mult (enum machine_mode mode, rtx op0, rtx op1, rtx target, ...@@ -3262,6 +3292,24 @@ expand_mult (enum machine_mode mode, rtx op0, rtx op1, rtx target,
return op0; return op0;
} }
/* Return a cost estimate for multiplying a register by the given
COEFFicient in the given MODE and SPEED. */
int
mult_by_coeff_cost (HOST_WIDE_INT coeff, enum machine_mode mode, bool speed)
{
int max_cost;
struct algorithm algorithm;
enum mult_variant variant;
rtx fake_reg = gen_raw_REG (mode, LAST_VIRTUAL_REGISTER + 1);
max_cost = set_src_cost (gen_rtx_MULT (mode, fake_reg, fake_reg), speed);
if (choose_mult_variant (mode, coeff, &algorithm, &variant, max_cost))
return algorithm.cost.cost;
else
return max_cost;
}
/* Perform a widening multiplication and return an rtx for the result. /* Perform a widening multiplication and return an rtx for the result.
MODE is mode of value; OP0 and OP1 are what to multiply (rtx's); MODE is mode of value; OP0 and OP1 are what to multiply (rtx's);
TARGET is a suggestion for where to store the result (an rtx). TARGET is a suggestion for where to store the result (an rtx).
......
...@@ -124,6 +124,8 @@ struct alg_hash_entry { ...@@ -124,6 +124,8 @@ struct alg_hash_entry {
#define NUM_ALG_HASH_ENTRIES 307 #define NUM_ALG_HASH_ENTRIES 307
#endif #endif
#define NUM_MODE_INT (MAX_MODE_INT - MIN_MODE_INT + 1)
/* Target-dependent globals. */ /* Target-dependent globals. */
struct target_expmed { struct target_expmed {
/* Each entry of ALG_HASH caches alg_code for some integer. This is /* Each entry of ALG_HASH caches alg_code for some integer. This is
...@@ -155,6 +157,11 @@ struct target_expmed { ...@@ -155,6 +157,11 @@ struct target_expmed {
int x_udiv_cost[2][NUM_MACHINE_MODES]; int x_udiv_cost[2][NUM_MACHINE_MODES];
int x_mul_widen_cost[2][NUM_MACHINE_MODES]; int x_mul_widen_cost[2][NUM_MACHINE_MODES];
int x_mul_highpart_cost[2][NUM_MACHINE_MODES]; int x_mul_highpart_cost[2][NUM_MACHINE_MODES];
/* Conversion costs are only defined between two scalar integer modes
of different sizes. The first machine mode is the destination mode,
and the second is the source mode. */
int x_convert_cost[2][NUM_MODE_INT][NUM_MODE_INT];
}; };
extern struct target_expmed default_target_expmed; extern struct target_expmed default_target_expmed;
...@@ -197,4 +204,43 @@ extern struct target_expmed *this_target_expmed; ...@@ -197,4 +204,43 @@ extern struct target_expmed *this_target_expmed;
#define mul_highpart_cost \ #define mul_highpart_cost \
(this_target_expmed->x_mul_highpart_cost) (this_target_expmed->x_mul_highpart_cost)
/* Set the COST for converting from FROM_MODE to TO_MODE when optimizing
for SPEED. */
static inline void
set_convert_cost (enum machine_mode to_mode, enum machine_mode from_mode,
bool speed, int cost)
{
int to_idx, from_idx;
gcc_assert (to_mode >= MIN_MODE_INT
&& to_mode <= MAX_MODE_INT
&& from_mode >= MIN_MODE_INT
&& from_mode <= MAX_MODE_INT);
to_idx = to_mode - MIN_MODE_INT;
from_idx = from_mode - MIN_MODE_INT;
this_target_expmed->x_convert_cost[speed][to_idx][from_idx] = cost;
}
/* Return the cost for converting from FROM_MODE to TO_MODE when optimizing
for SPEED. */
static inline int
convert_cost (enum machine_mode to_mode, enum machine_mode from_mode,
bool speed)
{
int to_idx, from_idx;
gcc_assert (to_mode >= MIN_MODE_INT
&& to_mode <= MAX_MODE_INT
&& from_mode >= MIN_MODE_INT
&& from_mode <= MAX_MODE_INT);
to_idx = to_mode - MIN_MODE_INT;
from_idx = from_mode - MIN_MODE_INT;
return this_target_expmed->x_convert_cost[speed][to_idx][from_idx];
}
extern int mult_by_coeff_cost (HOST_WIDE_INT, enum machine_mode, bool);
#endif #endif
...@@ -54,6 +54,7 @@ along with GCC; see the file COPYING3. If not see ...@@ -54,6 +54,7 @@ along with GCC; see the file COPYING3. If not see
#include "tree-flow.h" #include "tree-flow.h"
#include "domwalk.h" #include "domwalk.h"
#include "pointer-set.h" #include "pointer-set.h"
#include "expmed.h"
/* Information about a strength reduction candidate. Each statement /* Information about a strength reduction candidate. Each statement
in the candidate table represents an expression of one of the in the candidate table represents an expression of one of the
...@@ -340,29 +341,22 @@ stmt_cost (gimple gs, bool speed) ...@@ -340,29 +341,22 @@ stmt_cost (gimple gs, bool speed)
rhs2 = gimple_assign_rhs2 (gs); rhs2 = gimple_assign_rhs2 (gs);
if (host_integerp (rhs2, 0)) if (host_integerp (rhs2, 0))
return multiply_by_const_cost (TREE_INT_CST_LOW (rhs2), lhs_mode, return mult_by_coeff_cost (TREE_INT_CST_LOW (rhs2), lhs_mode, speed);
speed);
gcc_assert (TREE_CODE (rhs1) != INTEGER_CST); gcc_assert (TREE_CODE (rhs1) != INTEGER_CST);
return multiply_regs_cost (TYPE_MODE (TREE_TYPE (lhs)), speed); return mul_cost[speed][lhs_mode];
case PLUS_EXPR: case PLUS_EXPR:
case POINTER_PLUS_EXPR: case POINTER_PLUS_EXPR:
case MINUS_EXPR: case MINUS_EXPR:
rhs2 = gimple_assign_rhs2 (gs); rhs2 = gimple_assign_rhs2 (gs);
return add_cost[speed][lhs_mode];
if (host_integerp (rhs2, 0))
return add_const_cost (TYPE_MODE (TREE_TYPE (rhs1)), speed);
gcc_assert (TREE_CODE (rhs1) != INTEGER_CST);
return add_regs_cost (lhs_mode, speed);
case NEGATE_EXPR: case NEGATE_EXPR:
return negate_reg_cost (lhs_mode, speed); return neg_cost[speed][lhs_mode];
case NOP_EXPR: case NOP_EXPR:
return extend_or_trunc_reg_cost (TREE_TYPE (lhs), TREE_TYPE (rhs1), return convert_cost (lhs_mode, TYPE_MODE (TREE_TYPE (rhs1)), speed);
speed);
/* Note that we don't assign costs to copies that in most cases /* Note that we don't assign costs to copies that in most cases
will go away. */ will go away. */
...@@ -1460,9 +1454,6 @@ execute_strength_reduction (void) ...@@ -1460,9 +1454,6 @@ execute_strength_reduction (void)
back edges, and this gives us dominator information as well. */ back edges, and this gives us dominator information as well. */
loop_optimizer_init (AVOID_CFG_MODIFICATIONS); loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
/* Initialize costs tables in IVOPTS. */
initialize_costs ();
/* Set up callbacks for the generic dominator tree walker. */ /* Set up callbacks for the generic dominator tree walker. */
walk_data.dom_direction = CDI_DOMINATORS; walk_data.dom_direction = CDI_DOMINATORS;
walk_data.initialize_block_local_data = NULL; walk_data.initialize_block_local_data = NULL;
...@@ -1493,7 +1484,6 @@ execute_strength_reduction (void) ...@@ -1493,7 +1484,6 @@ execute_strength_reduction (void)
pointer_map_destroy (stmt_cand_map); pointer_map_destroy (stmt_cand_map);
VEC_free (slsr_cand_t, heap, cand_vec); VEC_free (slsr_cand_t, heap, cand_vec);
obstack_free (&cand_obstack, NULL); obstack_free (&cand_obstack, NULL);
finalize_costs ();
return 0; return 0;
} }
......
...@@ -806,14 +806,6 @@ bool expr_invariant_in_loop_p (struct loop *, tree); ...@@ -806,14 +806,6 @@ bool expr_invariant_in_loop_p (struct loop *, tree);
bool stmt_invariant_in_loop_p (struct loop *, gimple); bool stmt_invariant_in_loop_p (struct loop *, gimple);
bool multiplier_allowed_in_address_p (HOST_WIDE_INT, enum machine_mode, bool multiplier_allowed_in_address_p (HOST_WIDE_INT, enum machine_mode,
addr_space_t); addr_space_t);
void initialize_costs (void);
void finalize_costs (void);
unsigned multiply_by_const_cost (HOST_WIDE_INT, enum machine_mode, bool);
unsigned add_regs_cost (enum machine_mode, bool);
unsigned multiply_regs_cost (enum machine_mode, bool);
unsigned add_const_cost (enum machine_mode, bool);
unsigned extend_or_trunc_reg_cost (tree, tree, bool);
unsigned negate_reg_cost (enum machine_mode, bool);
bool may_be_nonaddressable_p (tree expr); bool may_be_nonaddressable_p (tree expr);
/* In tree-ssa-threadupdate.c. */ /* In tree-ssa-threadupdate.c. */
......
...@@ -42,6 +42,7 @@ along with GCC; see the file COPYING3. If not see ...@@ -42,6 +42,7 @@ along with GCC; see the file COPYING3. If not see
#include "expr.h" #include "expr.h"
#include "ggc.h" #include "ggc.h"
#include "target.h" #include "target.h"
#include "expmed.h"
/* TODO -- handling of symbols (according to Richard Hendersons /* TODO -- handling of symbols (according to Richard Hendersons
comments, http://gcc.gnu.org/ml/gcc-patches/2005-04/msg00949.html): comments, http://gcc.gnu.org/ml/gcc-patches/2005-04/msg00949.html):
...@@ -554,7 +555,7 @@ most_expensive_mult_to_index (tree type, struct mem_address *parts, ...@@ -554,7 +555,7 @@ most_expensive_mult_to_index (tree type, struct mem_address *parts,
|| !multiplier_allowed_in_address_p (coef, TYPE_MODE (type), as)) || !multiplier_allowed_in_address_p (coef, TYPE_MODE (type), as))
continue; continue;
acost = multiply_by_const_cost (coef, address_mode, speed); acost = mult_by_coeff_cost (coef, address_mode, speed);
if (acost > best_mult_cost) if (acost > best_mult_cost)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment