+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
#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"
*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
#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;
\f
#include "gt-i386.h"
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
maintainer is familiar with.
@end defmac
+
+@hook TARGET_RUN_TARGET_SELFTESTS
#include "cfgbuild.h"
#include "print-rtl.h"
#include "selftest.h"
+#include "selftest-rtl.h"
#include "function.h"
#include "memmodel.h"
#include "emit-rtl.h"
/* 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");
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
--- /dev/null
+/* 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 */
#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
/* 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 ();
#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)