Start adding selftests for print_rtx
gcc/ChangeLog: * print-rtl-function.c (flag_compact): Move extern decl to... * print-rtl.h (flag_compact): ...here. * rtl-tests.c (selftests::assert_rtl_dump_eq): New function. (ASSERT_RTL_DUMP_EQ): New macro. (selftest::test_dumping_regs): New function. (selftest::test_dumping_insns): New function. (selftest::test_uncond_jump): Add uses of ASSERT_RTL_DUMP_EQ on the insns. (selftest::rtl_tests_c_tests): Call the new test functions. From-SVN: r241405
This commit is contained in:
parent
6652a944dc
commit
e2ce9e83f7
@ -1,3 +1,15 @@
|
||||
2016-10-21 David Malcolm <dmalcolm@redhat.com>
|
||||
|
||||
* print-rtl-function.c (flag_compact): Move extern decl to...
|
||||
* print-rtl.h (flag_compact): ...here.
|
||||
* rtl-tests.c (selftests::assert_rtl_dump_eq): New function.
|
||||
(ASSERT_RTL_DUMP_EQ): New macro.
|
||||
(selftest::test_dumping_regs): New function.
|
||||
(selftest::test_dumping_insns): New function.
|
||||
(selftest::test_uncond_jump): Add uses of ASSERT_RTL_DUMP_EQ on
|
||||
the insns.
|
||||
(selftest::rtl_tests_c_tests): Call the new test functions.
|
||||
|
||||
2016-10-21 Trevor Saunders <tbsaunde+gcc@tbsaunde.org>
|
||||
|
||||
* cfgcleanup.c (merge_blocks_move_successor_nojumps): Adjust.
|
||||
|
@ -34,8 +34,6 @@ along with GCC; see the file COPYING3. If not see
|
||||
#include "memmodel.h"
|
||||
#include "emit-rtl.h"
|
||||
|
||||
extern bool flag_compact;
|
||||
|
||||
/* Print an "(edge-from)" or "(edge-to)" directive describing E
|
||||
to OUTFILE. */
|
||||
|
||||
|
@ -20,6 +20,8 @@ along with GCC; see the file COPYING3. If not see
|
||||
#ifndef GCC_PRINT_RTL_H
|
||||
#define GCC_PRINT_RTL_H
|
||||
|
||||
extern bool flag_compact;
|
||||
|
||||
#ifdef BUFSIZ
|
||||
extern void print_rtl (FILE *, const_rtx);
|
||||
#endif
|
||||
|
@ -57,6 +57,82 @@ verify_print_pattern (const char *expected, rtx pat)
|
||||
ASSERT_STREQ (expected, pp_formatted_text (&pp));
|
||||
}
|
||||
|
||||
/* Verify that X is dumped as EXPECTED_DUMP, using compact mode.
|
||||
Use LOC as the effective location when reporting errors. */
|
||||
|
||||
static void
|
||||
assert_rtl_dump_eq (const location &loc, const char *expected_dump, rtx x)
|
||||
{
|
||||
named_temp_file tmp_out (".rtl");
|
||||
FILE *outfile = fopen (tmp_out.get_filename (), "w");
|
||||
flag_compact = true;
|
||||
print_rtl (outfile, x);
|
||||
flag_compact = false;
|
||||
fclose (outfile);
|
||||
|
||||
char *dump = read_file (SELFTEST_LOCATION, tmp_out.get_filename ());
|
||||
ASSERT_STREQ_AT (loc, expected_dump, dump);
|
||||
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. */
|
||||
|
||||
/* Test dumping of virtual regs. The various virtual regs are inited as
|
||||
Pmode, so this is target-specific. The tests below assume DImode, so
|
||||
only run the tests for targets where Pmode is DImode. */
|
||||
if (Pmode == DImode)
|
||||
{
|
||||
ASSERT_RTL_DUMP_EQ ("(reg:DI virtual-incoming-args)",
|
||||
virtual_incoming_args_rtx);
|
||||
ASSERT_RTL_DUMP_EQ ("(reg:DI virtual-stack-vars)",
|
||||
virtual_stack_vars_rtx);
|
||||
ASSERT_RTL_DUMP_EQ ("(reg:DI virtual-stack-dynamic)",
|
||||
virtual_stack_dynamic_rtx);
|
||||
ASSERT_RTL_DUMP_EQ ("(reg:DI virtual-outgoing-args)",
|
||||
virtual_outgoing_args_rtx);
|
||||
ASSERT_RTL_DUMP_EQ ("(reg:DI virtual-cfa)",
|
||||
virtual_cfa_rtx);
|
||||
ASSERT_RTL_DUMP_EQ ("(reg:DI virtual-preferred-stack-boundary)",
|
||||
virtual_preferred_stack_boundary_rtx);
|
||||
}
|
||||
|
||||
/* Test dumping of non-virtual pseudos. */
|
||||
ASSERT_RTL_DUMP_EQ ("(reg:SI %0)",
|
||||
gen_raw_REG (SImode, LAST_VIRTUAL_REGISTER + 1));
|
||||
ASSERT_RTL_DUMP_EQ ("(reg:SI %1)",
|
||||
gen_raw_REG (SImode, LAST_VIRTUAL_REGISTER + 2));
|
||||
}
|
||||
|
||||
/* Verify that insns are dumped as expected (in compact mode). */
|
||||
|
||||
static void
|
||||
test_dumping_insns ()
|
||||
{
|
||||
/* Barriers. */
|
||||
rtx_barrier *barrier = as_a <rtx_barrier *> (rtx_alloc (BARRIER));
|
||||
SET_NEXT_INSN (barrier) = NULL;
|
||||
ASSERT_RTL_DUMP_EQ ("(cbarrier)\n", barrier);
|
||||
|
||||
/* Labels. */
|
||||
rtx_insn *label = gen_label_rtx ();
|
||||
CODE_LABEL_NUMBER (label) = 42;
|
||||
ASSERT_RTL_DUMP_EQ ("(clabel 0 42 \"\")\n", label);
|
||||
|
||||
LABEL_NAME (label)= "some_label";
|
||||
ASSERT_RTL_DUMP_EQ ("(clabel 0 42 (\"some_label\"))\n", label);
|
||||
}
|
||||
|
||||
/* Unit testing of "single_set". */
|
||||
|
||||
static void
|
||||
@ -92,6 +168,10 @@ test_uncond_jump ()
|
||||
|
||||
verify_print_pattern ("pc=L0", jump_pat);
|
||||
|
||||
ASSERT_RTL_DUMP_EQ ("(set (pc)\n"
|
||||
" (label_ref 0))",
|
||||
jump_pat);
|
||||
|
||||
rtx_insn *jump_insn = emit_jump_insn (jump_pat);
|
||||
ASSERT_FALSE (any_condjump_p (jump_insn));
|
||||
ASSERT_TRUE (any_uncondjump_p (jump_insn));
|
||||
@ -99,6 +179,11 @@ test_uncond_jump ()
|
||||
ASSERT_TRUE (simplejump_p (jump_insn));
|
||||
ASSERT_TRUE (onlyjump_p (jump_insn));
|
||||
ASSERT_TRUE (control_flow_insn_p (jump_insn));
|
||||
|
||||
ASSERT_RTL_DUMP_EQ ("(cjump_insn (set (pc)\n"
|
||||
" (label_ref 0))\n"
|
||||
" (nil))\n",
|
||||
jump_insn);
|
||||
}
|
||||
|
||||
/* Run all of the selftests within this file. */
|
||||
@ -106,6 +191,8 @@ test_uncond_jump ()
|
||||
void
|
||||
rtl_tests_c_tests ()
|
||||
{
|
||||
test_dumping_regs ();
|
||||
test_dumping_insns ();
|
||||
test_single_set ();
|
||||
test_uncond_jump ();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user