diff mbox

Start adding target-specific selftests

Message ID 1477071924-32878-1-git-send-email-dmalcolm@redhat.com
State New
Headers show

Commit Message

David Malcolm Oct. 21, 2016, 5:45 p.m. UTC
On Fri, 2016-10-21 at 12:04 +0200, Bernd Schmidt wrote:
> On 10/21/2016 02:36 AM, David Malcolm wrote:
> > +  /* Test dumping of hard regs.  This is inherently target
> > -specific due
> > +     to the name.  */
> > +#ifdef I386_OPTS_H
> > +  ASSERT_RTL_DUMP_EQ ("(reg:SI ax)", gen_raw_REG (SImode, 0));
> > +#endif
> 
> Generally putting in target dependencies like this isn't something we
> like to do. The patch is OK without this part, and we can revisit
> this,
> but maybe there wants to be a target hook for running target-specific
> selftests.

Thanks.  I removed the above target-specific part, and committed it
as r241405 (having reverified bootstrap&regrtest on x86_64-pc-linux-gnu).

The following patch implements a target hook for running target-specific
selftests.

It implements the above test for dumping of hard regs, putting it
within i386.c.

It's rather trivial, but I have followups that add further
target-specific tests, so hopefully this foundation is OK.

Successfully bootstrapped&regrtested on x86_64-pc-linux-gnu.

OK for trunk?
 
> > +  ASSERT_RTL_DUMP_EQ ("(cjump_insn (set (pc)\n"
> > +		      "        (label_ref 0))\n"
> > +		      "     (nil))\n",
> > +		      jump_insn);
> >  }
> 
> I do wonder about the (nil)s and whether we can eliminate them.

I hope to.

gcc/ChangeLog:
	* config/i386/i386.c: Include "selftest.h" and "selftest-rtl.h".
	(selftest::ix86_test_dumping_hard_regs): New function.
	(selftest::ix86_run_selftests): New function.
	(TARGET_RUN_TARGET_SELFTESTS): When CHECKING_P, wire this up to
	selftest::ix86_run_selftests.
	* doc/tm.texi.in (TARGET_RUN_TARGET_SELFTESTS): New.
	* doc/tm.texi: Regenerate
	* rtl-tests.c: Include "selftest-rtl.h".
	(selftest::assert_rtl_dump_eq): Make non-static.
	(ASSERT_RTL_DUMP_EQ): Move to selftest-rtl.h.
	(selftest::test_dumping_regs): Update comment.
	* selftest-rtl.h: New file.
	* selftest-run-tests.c: Include "target.h".
	(selftest::run_tests): If non-NULL, call
	targetm.run_target_selftests.
	* target.def (run_target_selftests): New hook.
---
 gcc/config/i386/i386.c   | 34 ++++++++++++++++++++++++++++++++++
 gcc/doc/tm.texi          |  4 ++++
 gcc/doc/tm.texi.in       |  2 ++
 gcc/rtl-tests.c          | 10 +++-------
 gcc/selftest-rtl.h       | 45 +++++++++++++++++++++++++++++++++++++++++++++
 gcc/selftest-run-tests.c |  5 +++++
 gcc/target.def           |  6 ++++++
 7 files changed, 99 insertions(+), 7 deletions(-)
 create mode 100644 gcc/selftest-rtl.h

Comments

David Malcolm Nov. 4, 2016, 2:52 p.m. UTC | #1
(ping)

https://gcc.gnu.org/ml/gcc-patches/2016-10/msg01785.html 

On Fri, 2016-10-21 at 13:45 -0400, David Malcolm wrote:
> On Fri, 2016-10-21 at 12:04 +0200, Bernd Schmidt wrote:
> > On 10/21/2016 02:36 AM, David Malcolm wrote:
> > > +  /* Test dumping of hard regs.  This is inherently target
> > > -specific due
> > > +     to the name.  */
> > > +#ifdef I386_OPTS_H
> > > +  ASSERT_RTL_DUMP_EQ ("(reg:SI ax)", gen_raw_REG (SImode, 0));
> > > +#endif
> > 
> > Generally putting in target dependencies like this isn't something
> > we
> > like to do. The patch is OK without this part, and we can revisit
> > this,
> > but maybe there wants to be a target hook for running target
> > -specific
> > selftests.
> 
> Thanks.  I removed the above target-specific part, and committed it
> as r241405 (having reverified bootstrap&regrtest on x86_64-pc-linux
> -gnu).
> 
> The following patch implements a target hook for running target
> -specific
> selftests.
> 
> It implements the above test for dumping of hard regs, putting it
> within i386.c.
> 
> It's rather trivial, but I have followups that add further
> target-specific tests, so hopefully this foundation is OK.
> 
> Successfully bootstrapped&regrtested on x86_64-pc-linux-gnu.
> 
> OK for trunk?
>  
> > > +  ASSERT_RTL_DUMP_EQ ("(cjump_insn (set (pc)\n"
> > > +		      "        (label_ref 0))\n"
> > > +		      "     (nil))\n",
> > > +		      jump_insn);
> > >  }
> > 
> > I do wonder about the (nil)s and whether we can eliminate them.
> 
> I hope to.
> 
> gcc/ChangeLog:
> 	* config/i386/i386.c: Include "selftest.h" and "selftest
> -rtl.h".
> 	(selftest::ix86_test_dumping_hard_regs): New function.
> 	(selftest::ix86_run_selftests): New function.
> 	(TARGET_RUN_TARGET_SELFTESTS): When CHECKING_P, wire this up to
> 	selftest::ix86_run_selftests.
> 	* doc/tm.texi.in (TARGET_RUN_TARGET_SELFTESTS): New.
> 	* doc/tm.texi: Regenerate
> 	* rtl-tests.c: Include "selftest-rtl.h".
> 	(selftest::assert_rtl_dump_eq): Make non-static.
> 	(ASSERT_RTL_DUMP_EQ): Move to selftest-rtl.h.
> 	(selftest::test_dumping_regs): Update comment.
> 	* selftest-rtl.h: New file.
> 	* selftest-run-tests.c: Include "target.h".
> 	(selftest::run_tests): If non-NULL, call
> 	targetm.run_target_selftests.
> 	* target.def (run_target_selftests): New hook.
> ---
>  gcc/config/i386/i386.c   | 34 ++++++++++++++++++++++++++++++++++
>  gcc/doc/tm.texi          |  4 ++++
>  gcc/doc/tm.texi.in       |  2 ++
>  gcc/rtl-tests.c          | 10 +++-------
>  gcc/selftest-rtl.h       | 45
> +++++++++++++++++++++++++++++++++++++++++++++
>  gcc/selftest-run-tests.c |  5 +++++
>  gcc/target.def           |  6 ++++++
>  7 files changed, 99 insertions(+), 7 deletions(-)
>  create mode 100644 gcc/selftest-rtl.h
> 
> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
> index 3e6f8fd..8f6ceb4 100644
> --- a/gcc/config/i386/i386.c
> +++ b/gcc/config/i386/i386.c
> @@ -77,6 +77,8 @@ along with GCC; see the file COPYING3.  If not see
>  #include "case-cfn-macros.h"
>  #include "regrename.h"
>  #include "dojump.h"
> +#include "selftest.h"
> +#include "selftest-rtl.h"
>  
>  /* This file should be included last.  */
>  #include "target-def.h"
> @@ -50365,6 +50367,33 @@ ix86_addr_space_zero_address_valid
> (addr_space_t as)
>  #undef TARGET_ADDR_SPACE_ZERO_ADDRESS_VALID
>  #define TARGET_ADDR_SPACE_ZERO_ADDRESS_VALID
> ix86_addr_space_zero_address_valid
>  
> +/* Target-specific selftests.  */
> +
> +#if CHECKING_P
> +
> +namespace selftest {
> +
> +/* Verify that hard regs are dumped as expected (in compact mode). 
>  */
> +
> +static void
> +ix86_test_dumping_hard_regs ()
> +{
> +  ASSERT_RTL_DUMP_EQ ("(reg:SI ax)", gen_raw_REG (SImode, 0));
> +  ASSERT_RTL_DUMP_EQ ("(reg:SI dx)", gen_raw_REG (SImode, 1));
> +}
> +
> +/* Run all target-specific selftests.  */
> +
> +static void
> +ix86_run_selftests (void)
> +{
> +  ix86_test_dumping_hard_regs ();
> +}
> +
> +} // namespace selftest
> +
> +#endif /* CHECKING_P */
> +
>  /* Initialize the GCC target structure.  */
>  #undef TARGET_RETURN_IN_MEMORY
>  #define TARGET_RETURN_IN_MEMORY ix86_return_in_memory
> @@ -50840,6 +50869,11 @@ ix86_addr_space_zero_address_valid
> (addr_space_t as)
>  #undef TARGET_CUSTOM_FUNCTION_DESCRIPTORS
>  #define TARGET_CUSTOM_FUNCTION_DESCRIPTORS 1
>  
> +#if CHECKING_P
> +#undef TARGET_RUN_TARGET_SELFTESTS
> +#define TARGET_RUN_TARGET_SELFTESTS selftest::ix86_run_selftests
> +#endif /* #if CHECKING_P */
> +
>  struct gcc_target targetm = TARGET_INITIALIZER;
>  
>  #include "gt-i386.h"
> diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
> index 29dc73b..7efcf57 100644
> --- a/gcc/doc/tm.texi
> +++ b/gcc/doc/tm.texi
> @@ -11821,3 +11821,7 @@ All and all it does not take long to convert
> ports that the
>  maintainer is familiar with.
>  
>  @end defmac
> +
> +@deftypefn {Target Hook} void TARGET_RUN_TARGET_SELFTESTS (void)
> +If selftests are enabled, run any selftests for this target.
> +@end deftypefn
> diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
> index efcd741..fb94dd8 100644
> --- a/gcc/doc/tm.texi.in
> +++ b/gcc/doc/tm.texi.in
> @@ -8307,3 +8307,5 @@ All and all it does not take long to convert
> ports that the
>  maintainer is familiar with.
>  
>  @end defmac
> +
> +@hook TARGET_RUN_TARGET_SELFTESTS
> diff --git a/gcc/rtl-tests.c b/gcc/rtl-tests.c
> index b723560..10c0ddc 100644
> --- a/gcc/rtl-tests.c
> +++ b/gcc/rtl-tests.c
> @@ -38,6 +38,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "cfgbuild.h"
>  #include "print-rtl.h"
>  #include "selftest.h"
> +#include "selftest-rtl.h"
>  #include "function.h"
>  #include "memmodel.h"
>  #include "emit-rtl.h"
> @@ -60,7 +61,7 @@ verify_print_pattern (const char *expected, rtx
> pat)
>  /* Verify that X is dumped as EXPECTED_DUMP, using compact mode.
>     Use LOC as the effective location when reporting errors.  */
>  
> -static void
> +void
>  assert_rtl_dump_eq (const location &loc, const char *expected_dump,
> rtx x)
>  {
>    named_temp_file tmp_out (".rtl");
> @@ -75,18 +76,13 @@ assert_rtl_dump_eq (const location &loc, const
> char *expected_dump, rtx x)
>    free (dump);
>  }
>  
> -/* Verify that RTX is dumped as EXPECTED_DUMP, using compact mode. 
>  */
> -
> -#define ASSERT_RTL_DUMP_EQ(EXPECTED_DUMP, RTX) \
> -  assert_rtl_dump_eq (SELFTEST_LOCATION, (EXPECTED_DUMP), (RTX))
> -
>  /* Verify that regs are dumped as expected (in compact mode).  */
>  
>  static void
>  test_dumping_regs ()
>  {
>    /* Dumps of hard regs contain a target-specific name, so we don't
> test
> -     it here.  */
> +     it here; this can be tested in target-specific selftests.  */
>  
>    /* Test dumping of virtual regs.  The various virtual regs are
> inited as
>       Pmode, so this is target-specific.  The tests below assume
> DImode, so
> diff --git a/gcc/selftest-rtl.h b/gcc/selftest-rtl.h
> new file mode 100644
> index 0000000..0f0e167
> --- /dev/null
> +++ b/gcc/selftest-rtl.h
> @@ -0,0 +1,45 @@
> +/* A self-testing framework, for use by -fself-test.
> +   Copyright (C) 2016 Free Software Foundation, Inc.
> +
> +This file is part of GCC.
> +
> +GCC is free software; you can redistribute it and/or modify it under
> +the terms of the GNU General Public License as published by the Free
> +Software Foundation; either version 3, or (at your option) any later
> +version.
> +
> +GCC is distributed in the hope that it will be useful, but WITHOUT
> ANY
> +WARRANTY; without even the implied warranty of MERCHANTABILITY or
> +FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
> License
> +for more details.
> +
> +You should have received a copy of the GNU General Public License
> +along with GCC; see the file COPYING3.  If not see
> +<http://www.gnu.org/licenses/>.  */
> +
> +#ifndef GCC_SELFTEST_RTL_H
> +#define GCC_SELFTEST_RTL_H
> +
> +/* The selftest code should entirely disappear in a production
> +   configuration, hence we guard all of it with #if CHECKING_P.  */
> +
> +#if CHECKING_P
> +
> +namespace selftest {
> +
> +/* Verify that X is dumped as EXPECTED_DUMP, using compact mode.
> +   Use LOC as the effective location when reporting errors.  */
> +
> +extern void
> +assert_rtl_dump_eq (const location &loc, const char *expected_dump,
> rtx x);
> +
> +/* Verify that RTX is dumped as EXPECTED_DUMP, using compact mode. 
>  */
> +
> +#define ASSERT_RTL_DUMP_EQ(EXPECTED_DUMP, RTX) \
> +  assert_rtl_dump_eq (SELFTEST_LOCATION, (EXPECTED_DUMP), (RTX))
> +
> +} /* end of namespace selftest.  */
> +
> +#endif /* #if CHECKING_P */
> +
> +#endif /* GCC_SELFTEST_RTL_H */
> diff --git a/gcc/selftest-run-tests.c b/gcc/selftest-run-tests.c
> index d9d3ea1..68930ae 100644
> --- a/gcc/selftest-run-tests.c
> +++ b/gcc/selftest-run-tests.c
> @@ -22,6 +22,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "coretypes.h"
>  #include "selftest.h"
>  #include "tree.h"
> +#include "target.h"
>  #include "langhooks.h"
>  
>  /* This function needed to be split out from selftest.c as it
> references
> @@ -77,6 +78,10 @@ selftest::run_tests ()
>    /* This one relies on most of the above.  */
>    function_tests_c_tests ();
>  
> +  /* Run any target-specific selftests.  */
> +  if (targetm.run_target_selftests)
> +    targetm.run_target_selftests ();
> +
>    /* Run any lang-specific selftests.  */
>    lang_hooks.run_lang_selftests ();
>  
> diff --git a/gcc/target.def b/gcc/target.def
> index 29d1f81..61c5397 100644
> --- a/gcc/target.def
> +++ b/gcc/target.def
> @@ -6136,6 +6136,12 @@ HOOK_VECTOR_END (mode_switching)
>  #include "target-insns.def"
>  #undef DEF_TARGET_INSN
>  
> +DEFHOOK
> +(run_target_selftests,
> + "If selftests are enabled, run any selftests for this target.",
> + void, (void),
> + NULL)
> +
>  /* Close the 'struct gcc_target' definition.  */
>  HOOK_VECTOR_END (C90_EMPTY_HACK)
>
Bernd Schmidt Nov. 4, 2016, 3:01 p.m. UTC | #2
On 10/21/2016 07:45 PM, David Malcolm wrote:
>
> gcc/ChangeLog:
> 	* config/i386/i386.c: Include "selftest.h" and "selftest-rtl.h".
> 	(selftest::ix86_test_dumping_hard_regs): New function.
> 	(selftest::ix86_run_selftests): New function.
> 	(TARGET_RUN_TARGET_SELFTESTS): When CHECKING_P, wire this up to
> 	selftest::ix86_run_selftests.
> 	* doc/tm.texi.in (TARGET_RUN_TARGET_SELFTESTS): New.
> 	* doc/tm.texi: Regenerate
> 	* rtl-tests.c: Include "selftest-rtl.h".
> 	(selftest::assert_rtl_dump_eq): Make non-static.
> 	(ASSERT_RTL_DUMP_EQ): Move to selftest-rtl.h.
> 	(selftest::test_dumping_regs): Update comment.
> 	* selftest-rtl.h: New file.
> 	* selftest-run-tests.c: Include "target.h".
> 	(selftest::run_tests): If non-NULL, call
> 	targetm.run_target_selftests.
> 	* target.def (run_target_selftests): New hook.

Ok.


Bernd
diff mbox

Patch

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 3e6f8fd..8f6ceb4 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -77,6 +77,8 @@  along with GCC; see the file COPYING3.  If not see
 #include "case-cfn-macros.h"
 #include "regrename.h"
 #include "dojump.h"
+#include "selftest.h"
+#include "selftest-rtl.h"
 
 /* This file should be included last.  */
 #include "target-def.h"
@@ -50365,6 +50367,33 @@  ix86_addr_space_zero_address_valid (addr_space_t as)
 #undef TARGET_ADDR_SPACE_ZERO_ADDRESS_VALID
 #define TARGET_ADDR_SPACE_ZERO_ADDRESS_VALID ix86_addr_space_zero_address_valid
 
+/* Target-specific selftests.  */
+
+#if CHECKING_P
+
+namespace selftest {
+
+/* Verify that hard regs are dumped as expected (in compact mode).  */
+
+static void
+ix86_test_dumping_hard_regs ()
+{
+  ASSERT_RTL_DUMP_EQ ("(reg:SI ax)", gen_raw_REG (SImode, 0));
+  ASSERT_RTL_DUMP_EQ ("(reg:SI dx)", gen_raw_REG (SImode, 1));
+}
+
+/* Run all target-specific selftests.  */
+
+static void
+ix86_run_selftests (void)
+{
+  ix86_test_dumping_hard_regs ();
+}
+
+} // namespace selftest
+
+#endif /* CHECKING_P */
+
 /* Initialize the GCC target structure.  */
 #undef TARGET_RETURN_IN_MEMORY
 #define TARGET_RETURN_IN_MEMORY ix86_return_in_memory
@@ -50840,6 +50869,11 @@  ix86_addr_space_zero_address_valid (addr_space_t as)
 #undef TARGET_CUSTOM_FUNCTION_DESCRIPTORS
 #define TARGET_CUSTOM_FUNCTION_DESCRIPTORS 1
 
+#if CHECKING_P
+#undef TARGET_RUN_TARGET_SELFTESTS
+#define TARGET_RUN_TARGET_SELFTESTS selftest::ix86_run_selftests
+#endif /* #if CHECKING_P */
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 #include "gt-i386.h"
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 29dc73b..7efcf57 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -11821,3 +11821,7 @@  All and all it does not take long to convert ports that the
 maintainer is familiar with.
 
 @end defmac
+
+@deftypefn {Target Hook} void TARGET_RUN_TARGET_SELFTESTS (void)
+If selftests are enabled, run any selftests for this target.
+@end deftypefn
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index efcd741..fb94dd8 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -8307,3 +8307,5 @@  All and all it does not take long to convert ports that the
 maintainer is familiar with.
 
 @end defmac
+
+@hook TARGET_RUN_TARGET_SELFTESTS
diff --git a/gcc/rtl-tests.c b/gcc/rtl-tests.c
index b723560..10c0ddc 100644
--- a/gcc/rtl-tests.c
+++ b/gcc/rtl-tests.c
@@ -38,6 +38,7 @@  along with GCC; see the file COPYING3.  If not see
 #include "cfgbuild.h"
 #include "print-rtl.h"
 #include "selftest.h"
+#include "selftest-rtl.h"
 #include "function.h"
 #include "memmodel.h"
 #include "emit-rtl.h"
@@ -60,7 +61,7 @@  verify_print_pattern (const char *expected, rtx pat)
 /* Verify that X is dumped as EXPECTED_DUMP, using compact mode.
    Use LOC as the effective location when reporting errors.  */
 
-static void
+void
 assert_rtl_dump_eq (const location &loc, const char *expected_dump, rtx x)
 {
   named_temp_file tmp_out (".rtl");
@@ -75,18 +76,13 @@  assert_rtl_dump_eq (const location &loc, const char *expected_dump, rtx x)
   free (dump);
 }
 
-/* Verify that RTX is dumped as EXPECTED_DUMP, using compact mode.  */
-
-#define ASSERT_RTL_DUMP_EQ(EXPECTED_DUMP, RTX) \
-  assert_rtl_dump_eq (SELFTEST_LOCATION, (EXPECTED_DUMP), (RTX))
-
 /* Verify that regs are dumped as expected (in compact mode).  */
 
 static void
 test_dumping_regs ()
 {
   /* Dumps of hard regs contain a target-specific name, so we don't test
-     it here.  */
+     it here; this can be tested in target-specific selftests.  */
 
   /* Test dumping of virtual regs.  The various virtual regs are inited as
      Pmode, so this is target-specific.  The tests below assume DImode, so
diff --git a/gcc/selftest-rtl.h b/gcc/selftest-rtl.h
new file mode 100644
index 0000000..0f0e167
--- /dev/null
+++ b/gcc/selftest-rtl.h
@@ -0,0 +1,45 @@ 
+/* A self-testing framework, for use by -fself-test.
+   Copyright (C) 2016 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+#ifndef GCC_SELFTEST_RTL_H
+#define GCC_SELFTEST_RTL_H
+
+/* The selftest code should entirely disappear in a production
+   configuration, hence we guard all of it with #if CHECKING_P.  */
+
+#if CHECKING_P
+
+namespace selftest {
+
+/* Verify that X is dumped as EXPECTED_DUMP, using compact mode.
+   Use LOC as the effective location when reporting errors.  */
+
+extern void
+assert_rtl_dump_eq (const location &loc, const char *expected_dump, rtx x);
+
+/* Verify that RTX is dumped as EXPECTED_DUMP, using compact mode.  */
+
+#define ASSERT_RTL_DUMP_EQ(EXPECTED_DUMP, RTX) \
+  assert_rtl_dump_eq (SELFTEST_LOCATION, (EXPECTED_DUMP), (RTX))
+
+} /* end of namespace selftest.  */
+
+#endif /* #if CHECKING_P */
+
+#endif /* GCC_SELFTEST_RTL_H */
diff --git a/gcc/selftest-run-tests.c b/gcc/selftest-run-tests.c
index d9d3ea1..68930ae 100644
--- a/gcc/selftest-run-tests.c
+++ b/gcc/selftest-run-tests.c
@@ -22,6 +22,7 @@  along with GCC; see the file COPYING3.  If not see
 #include "coretypes.h"
 #include "selftest.h"
 #include "tree.h"
+#include "target.h"
 #include "langhooks.h"
 
 /* This function needed to be split out from selftest.c as it references
@@ -77,6 +78,10 @@  selftest::run_tests ()
   /* This one relies on most of the above.  */
   function_tests_c_tests ();
 
+  /* Run any target-specific selftests.  */
+  if (targetm.run_target_selftests)
+    targetm.run_target_selftests ();
+
   /* Run any lang-specific selftests.  */
   lang_hooks.run_lang_selftests ();
 
diff --git a/gcc/target.def b/gcc/target.def
index 29d1f81..61c5397 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -6136,6 +6136,12 @@  HOOK_VECTOR_END (mode_switching)
 #include "target-insns.def"
 #undef DEF_TARGET_INSN
 
+DEFHOOK
+(run_target_selftests,
+ "If selftests are enabled, run any selftests for this target.",
+ void, (void),
+ NULL)
+
 /* Close the 'struct gcc_target' definition.  */
 HOOK_VECTOR_END (C90_EMPTY_HACK)