diff mbox

[RFC:,1/6] New target hook: rtx_branch_cost

Message ID 1464886438-17892-2-git-send-email-james.greenhalgh@arm.com
State New
Headers show

Commit Message

James Greenhalgh June 2, 2016, 4:53 p.m. UTC
Hi,

This patch introduces a new target hook, to be used like BRANCH_COST but
with a guaranteed unit of measurement. We want this to break away from
the current ambiguous uses of BRANCH_COST.

BRANCH_COST is used in ifcvt.c in two types of comparisons. One against
instruction counts - where it is used as the limit on the number of new
instructions we are permitted to generate. The other (after multiplying
by COSTS_N_INSNS (1)) directly against RTX costs.

Of these, a comparison against RTX costs is the more easily understood
metric across the compiler, and the one I've pulled out to the new hook.
To keep things consistent for targets which don't migrate, this new hook
has a default value of BRANCH_COST * COSTS_N_INSNS (1).

OK?

Thanks,
James

---
2016-06-02  James Greenhalgh  <james.greenhalgh@arm.com>

	* target.def (rtx_branch_cost): New.
	* doc/tm.texi.in (TARGET_RTX_BRANCH_COST): Document it.
	* doc/tm.texi: Regenerate.
	* targhooks.h (default_rtx_branch_cost): New.
	* targhooks.c (default_rtx_branch_cost): New.
diff mbox

Patch

diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 8c7f2a1..32efa1f 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -6499,6 +6499,16 @@  should probably only be given to addresses with different numbers of
 registers on machines with lots of registers.
 @end deftypefn
 
+@deftypefn {Target Hook} {unsigned int} TARGET_RTX_BRANCH_COST (bool @var{speed_p}, bool @var{predictable_p})
+This hook should return a cost in the same units as
+  @code{TARGET_RTX_COSTS}, giving the estimated cost of a branch.
+  @code{speed_p} is true if we are compiling for speed.
+  @code{predictable_p} is true if analysis suggests that the branch
+  will be predictable.  The default implementation of this hook
+  multiplies @code{BRANCH_COST} by the cost of a cheap instruction to
+  approximate the cost of a branch in the appropriate units.
+@end deftypefn
+
 @deftypefn {Target Hook} bool TARGET_NO_SPECULATION_IN_DELAY_SLOTS_P (void)
 This predicate controls the use of the eager delay slot filler to disallow
 speculatively executed instructions being placed in delay slots.  Targets
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index f963a58..92461b0 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -4748,6 +4748,8 @@  Define this macro if a non-short-circuit operation produced by
 
 @hook TARGET_ADDRESS_COST
 
+@hook TARGET_RTX_BRANCH_COST
+
 @hook TARGET_NO_SPECULATION_IN_DELAY_SLOTS_P
 
 @node Scheduling
diff --git a/gcc/target.def b/gcc/target.def
index 6392e73..f049a8b 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -3559,6 +3559,20 @@  registers on machines with lots of registers.",
  int, (rtx address, machine_mode mode, addr_space_t as, bool speed),
  default_address_cost)
 
+/* Give a cost, in RTX Costs units, for an edge.  Like BRANCH_COST, but with
+   well defined units.  */
+DEFHOOK
+(rtx_branch_cost,
+ "This hook should return a cost in the same units as\n\
+  @code{TARGET_RTX_COSTS}, giving the estimated cost of a branch.\n\
+  @code{speed_p} is true if we are compiling for speed.\n\
+  @code{predictable_p} is true if analysis suggests that the branch\n\
+  will be predictable.  The default implementation of this hook\n\
+  multiplies @code{BRANCH_COST} by the cost of a cheap instruction to\n\
+  approximate the cost of a branch in the appropriate units.",
+  unsigned int, (bool speed_p, bool predictable_p),
+  default_rtx_branch_cost)
+
 /* Permit speculative instructions in delay slots during delayed-branch 
    scheduling.  */
 DEFHOOK
diff --git a/gcc/targhooks.c b/gcc/targhooks.c
index 6b4601b..dcffeb8 100644
--- a/gcc/targhooks.c
+++ b/gcc/targhooks.c
@@ -74,6 +74,7 @@  along with GCC; see the file COPYING3.  If not see
 #include "intl.h"
 #include "opts.h"
 #include "gimplify.h"
+#include "predict.h"
 
 
 bool
@@ -1965,4 +1966,13 @@  default_optab_supported_p (int, machine_mode, machine_mode, optimization_type)
   return true;
 }
 
+/* Default implementation of TARGET_RTX_BRANCH_COST.  */
+
+unsigned int
+default_rtx_branch_cost (bool speed_p,
+			 bool predictable_p)
+{
+  return BRANCH_COST (speed_p, predictable_p) * COSTS_N_INSNS (1);
+}
+
 #include "gt-targhooks.h"
diff --git a/gcc/targhooks.h b/gcc/targhooks.h
index 7687c39..b7ff94c 100644
--- a/gcc/targhooks.h
+++ b/gcc/targhooks.h
@@ -254,4 +254,6 @@  extern void default_setup_incoming_vararg_bounds (cumulative_args_t ca ATTRIBUTE
 extern bool default_optab_supported_p (int, machine_mode, machine_mode,
 				       optimization_type);
 
+extern unsigned int default_rtx_branch_cost (bool, bool);
+
 #endif /* GCC_TARGHOOKS_H */