]>
Commit | Line | Data |
---|---|---|
2199e5fa | 1 | /* Process machine description and calculate constant conditions. |
a945c346 | 2 | Copyright (C) 2001-2024 Free Software Foundation, Inc. |
2199e5fa | 3 | |
54a7b573 | 4 | This file is part of GCC. |
2199e5fa | 5 | |
54a7b573 | 6 | GCC is free software; you can redistribute it and/or modify |
2199e5fa | 7 | it under the terms of the GNU General Public License as published by |
9dcd6f09 | 8 | the Free Software Foundation; either version 3, or (at your option) |
2199e5fa ZW |
9 | any later version. |
10 | ||
54a7b573 | 11 | GCC is distributed in the hope that it will be useful, |
2199e5fa ZW |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
9dcd6f09 NC |
17 | along with GCC; see the file COPYING3. If not see |
18 | <http://www.gnu.org/licenses/>. */ | |
2199e5fa ZW |
19 | |
20 | /* In a machine description, all of the insn patterns - define_insn, | |
21 | define_expand, define_split, define_peephole, define_peephole2 - | |
22 | contain an optional C expression which makes the final decision | |
23 | about whether or not this pattern is usable. That expression may | |
24 | turn out to be always false when the compiler is built. If it is, | |
25 | most of the programs that generate code from the machine | |
26 | description can simply ignore the entire pattern. */ | |
27 | ||
4977bab6 | 28 | #include "bconfig.h" |
2199e5fa | 29 | #include "system.h" |
4977bab6 ZW |
30 | #include "coretypes.h" |
31 | #include "tm.h" | |
2199e5fa ZW |
32 | #include "rtl.h" |
33 | #include "errors.h" | |
10692477 | 34 | #include "read-md.h" |
2199e5fa ZW |
35 | #include "gensupport.h" |
36 | ||
e0a21ab9 | 37 | /* so we can include except.h in the generated file. */ |
2199e5fa ZW |
38 | static int saw_eh_return; |
39 | ||
3d7aafde AJ |
40 | static void write_header (void); |
41 | static void write_conditions (void); | |
42 | static int write_one_condition (void **, void *); | |
2199e5fa | 43 | |
2199e5fa ZW |
44 | /* Generate the header for insn-conditions.c. */ |
45 | ||
46 | static void | |
3d7aafde | 47 | write_header (void) |
2199e5fa ZW |
48 | { |
49 | puts ("\ | |
50 | /* Generated automatically by the program `genconditions' from the target\n\ | |
51 | machine description file. */\n\ | |
52 | \n\ | |
8fcc61f8 | 53 | #define IN_TARGET_CODE 1\n\ |
4977bab6 | 54 | #include \"bconfig.h\"\n\ |
01736018 | 55 | #define INCLUDE_STRING\n\ |
89a42ac8 ZW |
56 | #include \"system.h\"\n\ |
57 | \n\ | |
f7c8e4fc ZW |
58 | /* It is necessary, but not entirely safe, to include the headers below\n\ |
59 | in a generator program. As a defensive measure, don't do so when the\n\ | |
60 | table isn't going to have anything in it. */\n\ | |
61 | #if GCC_VERSION >= 3001\n\ | |
62 | \n\ | |
2199e5fa | 63 | /* Do not allow checking to confuse the issue. */\n\ |
7f71272e MM |
64 | #undef CHECKING_P\n\ |
65 | #define CHECKING_P 0\n\ | |
2199e5fa ZW |
66 | #undef ENABLE_TREE_CHECKING\n\ |
67 | #undef ENABLE_RTL_CHECKING\n\ | |
68 | #undef ENABLE_RTL_FLAG_CHECKING\n\ | |
69 | #undef ENABLE_GC_CHECKING\n\ | |
89a42ac8 | 70 | #undef ENABLE_GC_ALWAYS_COLLECT\n\ |
b77d1a17 | 71 | #define USE_ENUM_MODES\n\ |
89a42ac8 | 72 | \n\ |
4977bab6 ZW |
73 | #include \"coretypes.h\"\n\ |
74 | #include \"tm.h\"\n\ | |
f7c8e4fc | 75 | #include \"insn-constants.h\"\n\ |
2199e5fa | 76 | #include \"rtl.h\"\n\ |
4d0cdd0c | 77 | #include \"memmodel.h\"\n\ |
2199e5fa | 78 | #include \"tm_p.h\"\n\ |
83685514 | 79 | #include \"hard-reg-set.h\"\n\ |
89a42ac8 | 80 | #include \"function.h\"\n\ |
2bb8cb58 | 81 | #include \"emit-rtl.h\"\n\ |
89a42ac8 | 82 | \n\ |
2199e5fa ZW |
83 | /* Fake - insn-config.h doesn't exist yet. */\n\ |
84 | #define MAX_RECOG_OPERANDS 10\n\ | |
85 | #define MAX_DUP_OPERANDS 10\n\ | |
89a42ac8 ZW |
86 | #define MAX_INSNS_PER_SPLIT 5\n\ |
87 | \n\ | |
2199e5fa ZW |
88 | #include \"regs.h\"\n\ |
89 | #include \"recog.h\"\n\ | |
2199e5fa ZW |
90 | #include \"output.h\"\n\ |
91 | #include \"flags.h\"\n\ | |
92 | #include \"hard-reg-set.h\"\n\ | |
60393bbc AM |
93 | #include \"predict.h\"\n\ |
94 | #include \"basic-block.h\"\n\ | |
c7131fb2 AM |
95 | #include \"bitmap.h\"\n\ |
96 | #include \"df.h\"\n\ | |
2199e5fa | 97 | #include \"resource.h\"\n\ |
79a3f089 | 98 | #include \"diagnostic-core.h\"\n\ |
f8569394 DE |
99 | #include \"reload.h\"\n\ |
100 | #include \"tm-constrs.h\"\n"); | |
2199e5fa ZW |
101 | |
102 | if (saw_eh_return) | |
103 | puts ("#define HAVE_eh_return 1"); | |
104 | puts ("#include \"except.h\"\n"); | |
105 | ||
106 | puts ("\ | |
107 | /* Dummy external declarations. */\n\ | |
95770ca3 | 108 | extern rtx_insn *insn;\n\ |
2199e5fa | 109 | extern rtx ins1;\n\ |
f7c8e4fc ZW |
110 | extern rtx operands[];\n\ |
111 | \n\ | |
112 | #endif /* gcc >= 3.0.1 */\n"); | |
2199e5fa ZW |
113 | } |
114 | ||
115 | /* Write out one entry in the conditions table, using the data pointed | |
116 | to by SLOT. Each entry looks like this: | |
7445392c RS |
117 | |
118 | { "! optimize_size && ! TARGET_READ_MODIFY_WRITE", | |
119 | __builtin_constant_p (! optimize_size && ! TARGET_READ_MODIFY_WRITE) | |
120 | ? (int) (! optimize_size && ! TARGET_READ_MODIFY_WRITE) | |
121 | : -1) }, */ | |
2199e5fa ZW |
122 | |
123 | static int | |
e18476eb | 124 | write_one_condition (void **slot, void * ARG_UNUSED (dummy)) |
2199e5fa | 125 | { |
69b6cce9 | 126 | const struct c_test *test = *(const struct c_test *const *) slot; |
2199e5fa ZW |
127 | const char *p; |
128 | ||
b78027d1 | 129 | rtx_reader_ptr->print_md_ptr_loc (test->expr); |
2199e5fa ZW |
130 | fputs (" { \"", stdout); |
131 | for (p = test->expr; *p; p++) | |
132 | { | |
f7c8e4fc ZW |
133 | switch (*p) |
134 | { | |
135 | case '\n': fputs ("\\n\\", stdout); break; | |
136 | case '\\': | |
137 | case '\"': putchar ('\\'); break; | |
138 | default: break; | |
139 | } | |
140 | putchar (*p); | |
2199e5fa ZW |
141 | } |
142 | ||
89a42ac8 | 143 | fputs ("\",\n __builtin_constant_p ", stdout); |
b78027d1 | 144 | rtx_reader_ptr->print_c_condition (test->expr); |
89a42ac8 | 145 | fputs ("\n ? (int) ", stdout); |
b78027d1 | 146 | rtx_reader_ptr->print_c_condition (test->expr); |
89a42ac8 | 147 | fputs ("\n : -1 },\n", stdout); |
2199e5fa ZW |
148 | return 1; |
149 | } | |
150 | ||
151 | /* Write out the complete conditions table, its size, and a flag | |
e53b6e56 | 152 | indicating that gensupport.cc can now do insn elision. */ |
2199e5fa | 153 | static void |
3d7aafde | 154 | write_conditions (void) |
2199e5fa | 155 | { |
f7c8e4fc ZW |
156 | puts ("\ |
157 | /* Structure definition duplicated from gensupport.h rather than\n\ | |
158 | drag in that file and its dependencies. */\n\ | |
159 | struct c_test\n\ | |
160 | {\n\ | |
161 | const char *expr;\n\ | |
162 | int value;\n\ | |
89a42ac8 ZW |
163 | };\n\ |
164 | \n\ | |
2199e5fa ZW |
165 | /* This table lists each condition found in the machine description.\n\ |
166 | Each condition is mapped to its truth value (0 or 1), or -1 if that\n\ | |
f7c8e4fc ZW |
167 | cannot be calculated at compile time.\n\ |
168 | If we don't have __builtin_constant_p, or it's not acceptable in array\n\ | |
1c7352cd ZW |
169 | initializers, fall back to assuming that all conditions potentially\n\ |
170 | vary at run time. It works in 3.0.1 and later; 3.0 only when not\n\ | |
171 | optimizing. */\n\ | |
f7c8e4fc | 172 | \n\ |
e45dcf9c EB |
173 | #if GCC_VERSION >= 3001\n\ |
174 | static const struct c_test insn_conditions[] = {\n"); | |
2199e5fa | 175 | |
1c7352cd | 176 | traverse_c_tests (write_one_condition, 0); |
2199e5fa | 177 | |
8afcd148 | 178 | puts (" { nullptr, -1 }\n};\n#endif /* gcc >= 3.0.1 */\n"); |
1c7352cd | 179 | } |
2199e5fa | 180 | |
1c7352cd ZW |
181 | /* Emit code which will convert the C-format table to a |
182 | (define_conditions) form, which the MD reader can understand. | |
183 | The result will be added to the set of files scanned by | |
184 | 'downstream' generators. */ | |
185 | static void | |
186 | write_writer (void) | |
187 | { | |
f7c8e4fc ZW |
188 | puts ("int\n" |
189 | "main(void)\n" | |
190 | "{\n" | |
191 | " unsigned int i;\n" | |
192 | " const char *p;\n" | |
193 | " puts (\"(define_conditions [\");\n" | |
e45dcf9c | 194 | "#if GCC_VERSION >= 3001\n" |
8afcd148 | 195 | " for (i = 0; i < ARRAY_SIZE (insn_conditions) - 1; i++)\n" |
f7c8e4fc ZW |
196 | " {\n" |
197 | " printf (\" (%d \\\"\", insn_conditions[i].value);\n" | |
198 | " for (p = insn_conditions[i].expr; *p; p++)\n" | |
199 | " {\n" | |
200 | " switch (*p)\n" | |
201 | " {\n" | |
202 | " case '\\\\':\n" | |
203 | " case '\\\"': putchar ('\\\\'); break;\n" | |
204 | " default: break;\n" | |
205 | " }\n" | |
206 | " putchar (*p);\n" | |
207 | " }\n" | |
208 | " puts (\"\\\")\");\n" | |
89a42ac8 | 209 | " }\n" |
e45dcf9c | 210 | "#endif /* gcc >= 3.0.1 */\n" |
89a42ac8 | 211 | " puts (\"])\");\n" |
f7c8e4fc ZW |
212 | " fflush (stdout);\n" |
213 | "return ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE;\n" | |
214 | "}"); | |
2199e5fa ZW |
215 | } |
216 | ||
217 | int | |
66b0fe8f | 218 | main (int argc, const char **argv) |
2199e5fa | 219 | { |
2199e5fa ZW |
220 | progname = "genconditions"; |
221 | ||
600ab3fc | 222 | if (!init_rtx_reader_args (argc, argv)) |
2199e5fa ZW |
223 | return (FATAL_EXIT_CODE); |
224 | ||
2199e5fa | 225 | /* Read the machine description. */ |
5d2d3e43 RS |
226 | md_rtx_info info; |
227 | while (read_md_rtx (&info)) | |
2199e5fa | 228 | { |
5d2d3e43 | 229 | rtx def = info.def; |
d1427a17 | 230 | add_c_test (get_c_test (def), -1); |
5d2d3e43 | 231 | switch (GET_CODE (def)) |
2199e5fa | 232 | { |
2199e5fa ZW |
233 | case DEFINE_INSN: |
234 | case DEFINE_EXPAND: | |
2199e5fa ZW |
235 | /* except.h needs to know whether there is an eh_return |
236 | pattern in the machine description. */ | |
5d2d3e43 | 237 | if (!strcmp (XSTR (def, 0), "eh_return")) |
2199e5fa ZW |
238 | saw_eh_return = 1; |
239 | break; | |
240 | ||
5d2d3e43 | 241 | default: |
2199e5fa ZW |
242 | break; |
243 | } | |
244 | } | |
245 | ||
246 | write_header (); | |
247 | write_conditions (); | |
1c7352cd | 248 | write_writer (); |
2199e5fa ZW |
249 | |
250 | fflush (stdout); | |
251 | return (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE); | |
252 | } |