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