annotate gcc/selftest-rtl.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Selftest support for RTL.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 2016-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of GCC.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
7 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
8 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
9 version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
14 for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 #include "config.h"
kono
parents:
diff changeset
21 #include "system.h"
kono
parents:
diff changeset
22 #include "coretypes.h"
kono
parents:
diff changeset
23 #include "selftest.h"
kono
parents:
diff changeset
24 #include "backend.h"
kono
parents:
diff changeset
25 #include "target.h"
kono
parents:
diff changeset
26 #include "rtl.h"
kono
parents:
diff changeset
27 #include "read-rtl-function.h"
kono
parents:
diff changeset
28 #include "read-md.h"
kono
parents:
diff changeset
29 #include "tree-core.h"
kono
parents:
diff changeset
30 #include "memmodel.h"
kono
parents:
diff changeset
31 #include "emit-rtl.h"
kono
parents:
diff changeset
32 #include "selftest-rtl.h"
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 #if CHECKING_P
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 namespace selftest {
kono
parents:
diff changeset
37
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
38 /* Compare rtx EXPECTED and ACTUAL using rtx_equal_p, calling
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
39 ::selftest::pass if they are equal, aborting if they are non-equal.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
40 LOC is the effective location of the assertion, MSG describes it. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
41
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
42 void
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
43 assert_rtx_eq_at (const location &loc, const char *msg,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
44 rtx expected, rtx actual)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
45 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
46 if (rtx_equal_p (expected, actual))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
47 ::selftest::pass (loc, msg);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
48 else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
49 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
50 fprintf (stderr, "%s:%i: %s: FAIL: %s\n", loc.m_file, loc.m_line,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
51 loc.m_function, msg);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
52 fprintf (stderr, " expected: ");
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
53 print_rtl (stderr, expected);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
54 fprintf (stderr, "\n actual: ");
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
55 print_rtl (stderr, actual);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
56 fprintf (stderr, "\n");
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
57 abort ();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
58 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
59 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
60
111
kono
parents:
diff changeset
61 /* Compare rtx EXPECTED and ACTUAL by pointer equality, calling
kono
parents:
diff changeset
62 ::selftest::pass if they are equal, aborting if they are non-equal.
kono
parents:
diff changeset
63 LOC is the effective location of the assertion, MSG describes it. */
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 void
kono
parents:
diff changeset
66 assert_rtx_ptr_eq_at (const location &loc, const char *msg,
kono
parents:
diff changeset
67 rtx expected, rtx actual)
kono
parents:
diff changeset
68 {
kono
parents:
diff changeset
69 if (expected == actual)
kono
parents:
diff changeset
70 ::selftest::pass (loc, msg);
kono
parents:
diff changeset
71 else
kono
parents:
diff changeset
72 {
kono
parents:
diff changeset
73 fprintf (stderr, "%s:%i: %s: FAIL: %s\n", loc.m_file, loc.m_line,
kono
parents:
diff changeset
74 loc.m_function, msg);
kono
parents:
diff changeset
75 fprintf (stderr, " expected (at %p): ", (void *)expected);
kono
parents:
diff changeset
76 print_rtl (stderr, expected);
kono
parents:
diff changeset
77 fprintf (stderr, "\n actual (at %p): ", (void *)actual);
kono
parents:
diff changeset
78 print_rtl (stderr, actual);
kono
parents:
diff changeset
79 fprintf (stderr, "\n");
kono
parents:
diff changeset
80 abort ();
kono
parents:
diff changeset
81 }
kono
parents:
diff changeset
82 }
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 /* Constructor for selftest::rtl_dump_test.
kono
parents:
diff changeset
85 Read a dumped RTL function from PATH.
kono
parents:
diff changeset
86 Takes ownership of PATH, freeing in dtor.
kono
parents:
diff changeset
87 Use LOC as the effective location when reporting failures. */
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 rtl_dump_test::rtl_dump_test (const location &loc, char *path)
kono
parents:
diff changeset
90 : m_path (path)
kono
parents:
diff changeset
91 {
kono
parents:
diff changeset
92 bool read_ok = read_rtl_function_body (path);
kono
parents:
diff changeset
93 ASSERT_TRUE_AT (loc, read_ok);
kono
parents:
diff changeset
94 }
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 /* Destructor for selftest::rtl_dump_test.
kono
parents:
diff changeset
97 Cleanup global state relating to the function, and free the path. */
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 selftest::rtl_dump_test::~rtl_dump_test ()
kono
parents:
diff changeset
100 {
kono
parents:
diff changeset
101 /* Cleanups. */
kono
parents:
diff changeset
102 current_function_decl = NULL;
kono
parents:
diff changeset
103 free_after_compilation (cfun);
kono
parents:
diff changeset
104 set_cfun (NULL);
kono
parents:
diff changeset
105 free (m_path);
kono
parents:
diff changeset
106 }
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 /* Get the insn with the given uid, or NULL if not found. */
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 rtx_insn *
kono
parents:
diff changeset
111 get_insn_by_uid (int uid)
kono
parents:
diff changeset
112 {
kono
parents:
diff changeset
113 for (rtx_insn *insn = get_insns (); insn; insn = NEXT_INSN (insn))
kono
parents:
diff changeset
114 if (INSN_UID (insn) == uid)
kono
parents:
diff changeset
115 return insn;
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 /* Not found. */
kono
parents:
diff changeset
118 return NULL;
kono
parents:
diff changeset
119 }
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 } // namespace selftest
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 #endif /* #if CHECKING_P */