[PATCH] convert target_expmed macro accessors into inline functions

2012-07-27 Thread Nathan Froyd
As suggested by rth here:

http://gcc.gnu.org/ml/gcc-patches/2012-07/msg01281.html

this patch converts all the #define accessors in expmed.h to use inline
functions instead.

By itself, doing that conversion is not very exciting.  Followup patches
might:

* Move setters into expmed.c;
* Reduce space of fields by not using NUM_MACHINE_MODES, similar to the
  convert_cost case;
* Possibly moving the getters into expmed.c, assuming that LTO will take
  care of the performance hit.  Doing so enables target_expmed to not be
  exposed everywhere.
* Lazily initialize the costs.

Tested on x86_64-unknown-linux-gnu.  OK to commit?

-Nathan

* expmed.h (alg_hash, alg_hash_used_p, sdiv_pow2_cheap,
smod_pow2_cheap, zero_cost, add_cost, neg_cost, shift_cost)
shiftadd_cost, shiftsub0_cost, shiftsub1_cost, mul_cost,
sdiv_cost, udiv_cost, mul_widen_cost, mul_highpart_cost): Delete
macro definitions and re-purpose as inline functions.
(alg_hash_entry_ptr, set_alg_hash_used_p, sdiv_pow2_cheap_ptr,
set_sdiv_pow2_cheap, smod_pow2_cheap_ptr, set_smod_pow2_cheap,
zero_cost_ptr, set_zero_cost, add_cost_ptr, set_add_cost,
neg_cost_ptr, set_neg_cost, shift_cost_ptr, set_shift_cost,
shiftadd_cost_ptr, set_shiftadd_cost, shiftsub0_cost_ptr,
set_shiftsub0_cost, shiftsub1_cost_ptr, set_shiftsub1_cost,
mul_cost_ptr, set_mul_cost, sdiv_cost_ptr, set_sdiv_cost,
udiv_cost_ptr, set_udiv_cost, mul_widen_cost_ptr,
set_mul_widen_cost, mul_highpart_cost_ptr, set_mul_highpart_cost):
New functions.
(convert_cost_ptr): New function, split out from...
(set_convert_cost, convert_cost): ...here.
* expmed.c, tree-ssa-loop-ivopts.c: Update for new functions.
* gimple-ssa-strength-reduction.c: Likewise.

---
 gcc/expmed.c|  230 ++-
 gcc/expmed.h|  441 +++
 gcc/gimple-ssa-strength-reduction.c |6 +-
 gcc/tree-ssa-loop-ivopts.c  |   24 +-
 4 files changed, 533 insertions(+), 168 deletions(-)

diff --git a/gcc/expmed.c b/gcc/expmed.c
index e660a3f..9743fc0 100644
--- a/gcc/expmed.c
+++ b/gcc/expmed.c
@@ -143,20 +143,24 @@ init_expmed_one_mode (struct init_expmed_rtl *all,
   PUT_MODE (all-shift_sub1, mode);
   PUT_MODE (all-convert, mode);
 
-  add_cost[speed][mode] = set_src_cost (all-plus, speed);
-  neg_cost[speed][mode] = set_src_cost (all-neg, speed);
-  mul_cost[speed][mode] = set_src_cost (all-mult, speed);
-  sdiv_cost[speed][mode] = set_src_cost (all-sdiv, speed);
-  udiv_cost[speed][mode] = set_src_cost (all-udiv, speed);
-
-  sdiv_pow2_cheap[speed][mode] = (set_src_cost (all-sdiv_32, speed)
- = 2 * add_cost[speed][mode]);
-  smod_pow2_cheap[speed][mode] = (set_src_cost (all-smod_32, speed)
- = 4 * add_cost[speed][mode]);
-
-  shift_cost[speed][mode][0] = 0;
-  shiftadd_cost[speed][mode][0] = shiftsub0_cost[speed][mode][0]
-= shiftsub1_cost[speed][mode][0] = add_cost[speed][mode];
+  set_add_cost (speed, mode, set_src_cost (all-plus, speed));
+  set_neg_cost (speed, mode, set_src_cost (all-neg, speed));
+  set_mul_cost (speed, mode, set_src_cost (all-mult, speed));
+  set_sdiv_cost (speed, mode, set_src_cost (all-sdiv, speed));
+  set_udiv_cost (speed, mode, set_src_cost (all-udiv, speed));
+
+  set_sdiv_pow2_cheap (speed, mode, (set_src_cost (all-sdiv_32, speed)
+= 2 * add_cost (speed, mode)));
+  set_smod_pow2_cheap (speed, mode, (set_src_cost (all-smod_32, speed)
+= 4 * add_cost (speed, mode)));
+
+  set_shift_cost (speed, mode, 0, 0);
+  {
+int cost = add_cost (speed, mode);
+set_shiftadd_cost (speed, mode, 0, cost);
+set_shiftsub0_cost (speed, mode, 0, cost);
+set_shiftsub1_cost (speed, mode, 0, cost);
+  }
 
   n = MIN (MAX_BITS_PER_WORD, mode_bitsize);
   for (m = 1; m  n; m++)
@@ -164,10 +168,10 @@ init_expmed_one_mode (struct init_expmed_rtl *all,
   XEXP (all-shift, 1) = all-cint[m];
   XEXP (all-shift_mult, 1) = all-pow2[m];
 
-  shift_cost[speed][mode][m] = set_src_cost (all-shift, speed);
-  shiftadd_cost[speed][mode][m] = set_src_cost (all-shift_add, speed);
-  shiftsub0_cost[speed][mode][m] = set_src_cost (all-shift_sub0, speed);
-  shiftsub1_cost[speed][mode][m] = set_src_cost (all-shift_sub1, speed);
+  set_shift_cost (speed, mode, m, set_src_cost (all-shift, speed));
+  set_shiftadd_cost (speed, mode, m, set_src_cost (all-shift_add, 
speed));
+  set_shiftsub0_cost (speed, mode, m, set_src_cost (all-shift_sub0, 
speed));
+  set_shiftsub1_cost (speed, mode, m, set_src_cost (all-shift_sub1, 
speed));
 }
 
   if (SCALAR_INT_MODE_P (mode))
@@ -181,10 +185,8 @@ init_expmed_one_mode (struct init_expmed_rtl *all,
  PUT_MODE (all-wide_lshr, wider_mode);
  XEXP 

Re: [PATCH] convert target_expmed macro accessors into inline functions

2012-07-27 Thread Richard Henderson
On 07/27/2012 04:41 AM, Nathan Froyd wrote:
 Tested on x86_64-unknown-linux-gnu.  OK to commit?
 
 -Nathan
 
   * expmed.h (alg_hash, alg_hash_used_p, sdiv_pow2_cheap,
   smod_pow2_cheap, zero_cost, add_cost, neg_cost, shift_cost)
   shiftadd_cost, shiftsub0_cost, shiftsub1_cost, mul_cost,
   sdiv_cost, udiv_cost, mul_widen_cost, mul_highpart_cost): Delete
   macro definitions and re-purpose as inline functions.
   (alg_hash_entry_ptr, set_alg_hash_used_p, sdiv_pow2_cheap_ptr,
   set_sdiv_pow2_cheap, smod_pow2_cheap_ptr, set_smod_pow2_cheap,
   zero_cost_ptr, set_zero_cost, add_cost_ptr, set_add_cost,
   neg_cost_ptr, set_neg_cost, shift_cost_ptr, set_shift_cost,
   shiftadd_cost_ptr, set_shiftadd_cost, shiftsub0_cost_ptr,
   set_shiftsub0_cost, shiftsub1_cost_ptr, set_shiftsub1_cost,
   mul_cost_ptr, set_mul_cost, sdiv_cost_ptr, set_sdiv_cost,
   udiv_cost_ptr, set_udiv_cost, mul_widen_cost_ptr,
   set_mul_widen_cost, mul_highpart_cost_ptr, set_mul_highpart_cost):
   New functions.
   (convert_cost_ptr): New function, split out from...
   (set_convert_cost, convert_cost): ...here.
   * expmed.c, tree-ssa-loop-ivopts.c: Update for new functions.
   * gimple-ssa-strength-reduction.c: Likewise.

Ok.  And thanks!


r~