From: Segher Boessenkool <segher@kernel.crashing.org>
To: gcc-patches@gcc.gnu.org
Cc: law@redhat.com, Segher Boessenkool <segher@kernel.crashing.org>
Subject: [PATCH 3/3] Add targetm.insn_cost hook
Date: Mon, 09 Oct 2017 19:48:00 -0000 [thread overview]
Message-ID: <b043f49b7c81c4d92f4e36807f28c49781fe63f3.1507574244.git.segher@kernel.crashing.org> (raw)
In-Reply-To: <cafebcc0ecc2bac6cbfbb989369a437cfff768b2.1507574244.git.segher@kernel.crashing.org>
In-Reply-To: <cafebcc0ecc2bac6cbfbb989369a437cfff768b2.1507574244.git.segher@kernel.crashing.org>
This adds a new hook that the insn_cost function uses if a target has
implemented it (it uses the old pattern_cost nee insn_rtx_cost if not).
I'll commit this now; it was okayed by Jeff at
https://gcc.gnu.org/ml/gcc-patches/2017-08/msg00204.html .
Segher
2017-10-09 Segher Boessenkool <segher@kernel.crashing.org>
* target.def (insn_cost): New hook.
* doc/tm.texi.in (TARGET_INSN_COST): New hook.
* doc/tm.texi: Regenerate.
* rtlanal.c (insn_cost): Use the new hook.
---
gcc/doc/tm.texi | 12 ++++++++++++
gcc/doc/tm.texi.in | 2 ++
gcc/rtlanal.c | 3 +++
gcc/target.def | 14 ++++++++++++++
4 files changed, 31 insertions(+)
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 8f503e1..0377217 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -6652,6 +6652,18 @@ should probably only be given to addresses with different numbers of
registers on machines with lots of registers.
@end deftypefn
+@deftypefn {Target Hook} int TARGET_INSN_COST (rtx_insn *@var{insn}, bool @var{speed})
+This target hook describes the relative costs of RTL instructions.
+
+In implementing this hook, you can use the construct
+@code{COSTS_N_INSNS (@var{n})} to specify a cost equal to @var{n} fast
+instructions.
+
+When optimizing for code size, i.e.@: when @code{speed} is
+false, this target hook should be used to estimate the relative
+size cost of an expression, again relative to @code{COSTS_N_INSNS}.
+@end deftypefn
+
@deftypefn {Target Hook} {unsigned int} TARGET_MAX_NOCE_IFCVT_SEQ_COST (edge @var{e})
This hook returns a value in the same units as @code{TARGET_RTX_COSTS},
giving the maximum acceptable cost for a sequence generated by the RTL
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index 15b3f1f..d2cf68f 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -4600,6 +4600,8 @@ Define this macro if a non-short-circuit operation produced by
@hook TARGET_ADDRESS_COST
+@hook TARGET_INSN_COST
+
@hook TARGET_MAX_NOCE_IFCVT_SEQ_COST
@hook TARGET_NOCE_CONVERSION_PROFITABLE_P
diff --git a/gcc/rtlanal.c b/gcc/rtlanal.c
index f01eab5..eadf691 100644
--- a/gcc/rtlanal.c
+++ b/gcc/rtlanal.c
@@ -5329,6 +5329,9 @@ pattern_cost (rtx pat, bool speed)
int
insn_cost (rtx_insn *insn, bool speed)
{
+ if (targetm.insn_cost)
+ return targetm.insn_cost (insn, speed);
+
return pattern_cost (PATTERN (insn), speed);
}
diff --git a/gcc/target.def b/gcc/target.def
index 80ef746..aac5d27 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -3715,6 +3715,20 @@ registers on machines with lots of registers.",
int, (rtx address, machine_mode mode, addr_space_t as, bool speed),
default_address_cost)
+/* Compute a cost for INSN. */
+DEFHOOK
+(insn_cost,
+ "This target hook describes the relative costs of RTL instructions.\n\
+\n\
+In implementing this hook, you can use the construct\n\
+@code{COSTS_N_INSNS (@var{n})} to specify a cost equal to @var{n} fast\n\
+instructions.\n\
+\n\
+When optimizing for code size, i.e.@: when @code{speed} is\n\
+false, this target hook should be used to estimate the relative\n\
+size cost of an expression, again relative to @code{COSTS_N_INSNS}.",
+ int, (rtx_insn *insn, bool speed), NULL)
+
/* Give a cost, in RTX Costs units, for an edge. Like BRANCH_COST, but with
well defined units. */
DEFHOOK
--
1.8.3.1
next prev parent reply other threads:[~2017-10-09 19:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-09 19:35 [PATCH 1/3] Replace insn_rtx_cost with insn_cost and pattern_cost Segher Boessenkool
2017-10-09 19:35 ` [PATCH 2/3] combine: Use insn_cost instead of pattern_cost everywhere Segher Boessenkool
2017-10-09 19:48 ` Segher Boessenkool [this message]
2017-10-11 23:48 ` [PATCH 3/3] Add targetm.insn_cost hook Sandra Loosemore
2017-10-12 2:21 ` Segher Boessenkool
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b043f49b7c81c4d92f4e36807f28c49781fe63f3.1507574244.git.segher@kernel.crashing.org \
--to=segher@kernel.crashing.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=law@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).