summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>2016-11-04 17:05:38 +0000
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>2016-11-04 17:05:38 +0000
commitb07ada29a6ba9cf1478b2f874a54ca46bdc37eb8 (patch)
treef0c2a3dd53e078735d3c7fce70972ff6c1f0ac97
parenta740a7ef7623e64ae0d418659303855866b44e62 (diff)
downloadgcc-b07ada29a6ba9cf1478b2f874a54ca46bdc37eb8.tar.gz
Start adding target-specific selftests
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 * selftest-rtl.h: New file. * 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-run-tests.c: Include "target.h". (selftest::run_tests): If non-NULL, call targetm.run_target_selftests. * target.def (run_target_selftests): New hook. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@241851 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog19
-rw-r--r--gcc/config/i386/i386.c34
-rw-r--r--gcc/doc/tm.texi4
-rw-r--r--gcc/doc/tm.texi.in2
-rw-r--r--gcc/rtl-tests.c10
-rw-r--r--gcc/selftest-rtl.h45
-rw-r--r--gcc/selftest-run-tests.c5
-rw-r--r--gcc/target.def6
8 files changed, 118 insertions, 7 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index ae886a456fe..ae6910c4267 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,22 @@
+2016-11-04 David Malcolm <dmalcolm@redhat.com>
+
+ * 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
+ * selftest-rtl.h: New file.
+ * 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-run-tests.c: Include "target.h".
+ (selftest::run_tests): If non-NULL, call
+ targetm.run_target_selftests.
+ * target.def (run_target_selftests): New hook.
+
2016-11-04 Thomas Preud'homme <thomas.preudhomme@arm.com>
* config/arm/arm-arches.def (armv8-m.main+dsp): Set Cortex-M33 as
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index b42ecd34cac..bffba803eee 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -80,6 +80,8 @@ along with GCC; see the file COPYING3. If not see
#include "fold-const-call.h"
#include "tree-vrp.h"
#include "tree-ssanames.h"
+#include "selftest.h"
+#include "selftest-rtl.h"
/* This file should be included last. */
#include "target-def.h"
@@ -50610,6 +50612,33 @@ ix86_expand_divmod_libfunc (rtx libfunc, machine_mode mode,
*rem_p = rem;
}
+/* 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
@@ -51092,6 +51121,11 @@ ix86_expand_divmod_libfunc (rtx libfunc, machine_mode mode,
#undef TARGET_EXPAND_DIVMOD_LIBFUNC
#define TARGET_EXPAND_DIVMOD_LIBFUNC ix86_expand_divmod_libfunc
+#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 b4eb18cc89a..e2d5e5fe346 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -11839,3 +11839,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 9e5b45661a9..102ad71ac01 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -8309,3 +8309,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 4e534b2316f..cf5239f92f9 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");
@@ -74,18 +75,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 00000000000..0f0e1673ab3
--- /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 54a9b0f6c7e..76532afca66 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 3d5c179fd15..c9fdfa7b493 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -6156,6 +6156,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)