]>
Commit | Line | Data |
---|---|---|
f12b8918 | 1 | /* Generate attribute information (insn-attr.h) from machine description. |
23a5b65a | 2 | Copyright (C) 1991-2014 Free Software Foundation, Inc. |
c9309570 | 3 | Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu) |
41299f41 | 4 | |
1322177d | 5 | This file is part of GCC. |
41299f41 | 6 | |
1322177d LB |
7 | GCC is free software; you can redistribute it and/or modify it under |
8 | the terms of the GNU General Public License as published by the Free | |
9dcd6f09 | 9 | Software Foundation; either version 3, or (at your option) any later |
1322177d | 10 | version. |
41299f41 | 11 | |
1322177d LB |
12 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | for more details. | |
41299f41 TW |
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/>. */ | |
41299f41 TW |
20 | |
21 | ||
4977bab6 | 22 | #include "bconfig.h" |
0b93b64e | 23 | #include "system.h" |
4977bab6 ZW |
24 | #include "coretypes.h" |
25 | #include "tm.h" | |
41299f41 | 26 | #include "rtl.h" |
f8b6598e | 27 | #include "errors.h" |
10692477 | 28 | #include "read-md.h" |
c88c0d42 | 29 | #include "gensupport.h" |
41299f41 | 30 | |
41299f41 | 31 | |
3d7aafde | 32 | static void gen_attr (rtx); |
ef3fad04 | 33 | |
9771b263 | 34 | static vec<rtx> const_attrs, reservations; |
2b21299c JJ |
35 | |
36 | ||
4beba5da | 37 | static void |
3d7aafde | 38 | gen_attr (rtx attr) |
4beba5da | 39 | { |
c344a866 | 40 | const char *p; |
3d7aafde | 41 | int is_const = GET_CODE (XEXP (attr, 2)) == CONST; |
41299f41 | 42 | |
2b21299c | 43 | if (is_const) |
9771b263 | 44 | const_attrs.safe_push (attr); |
2b21299c | 45 | |
d327457f | 46 | printf ("#define HAVE_ATTR_%s 1\n", XSTR (attr, 0)); |
41299f41 | 47 | |
f12b8918 | 48 | /* If numeric attribute, don't need to write an enum. */ |
8f4fe86c RS |
49 | if (GET_CODE (attr) == DEFINE_ENUM_ATTR) |
50 | printf ("extern enum %s get_attr_%s (%s);\n\n", | |
84034c69 DM |
51 | XSTR (attr, 1), XSTR (attr, 0), |
52 | (is_const ? "void" : "rtx_insn *")); | |
41299f41 TW |
53 | else |
54 | { | |
8f4fe86c RS |
55 | p = XSTR (attr, 1); |
56 | if (*p == '\0') | |
57 | printf ("extern int get_attr_%s (%s);\n", XSTR (attr, 0), | |
84034c69 | 58 | (is_const ? "void" : "rtx_insn *")); |
8f4fe86c | 59 | else |
c344a866 | 60 | printf ("extern enum attr_%s get_attr_%s (%s);\n\n", |
84034c69 DM |
61 | XSTR (attr, 0), XSTR (attr, 0), |
62 | (is_const ? "void" : "rtx_insn *")); | |
41299f41 TW |
63 | } |
64 | ||
f12b8918 TM |
65 | /* If `length' attribute, write additional function definitions and define |
66 | variables used by `insn_current_length'. */ | |
67 | if (! strcmp (XSTR (attr, 0), "length")) | |
41299f41 | 68 | { |
9a5834ae | 69 | puts ("\ |
49922db8 | 70 | extern void shorten_branches (rtx_insn *);\n\ |
84034c69 DM |
71 | extern int insn_default_length (rtx_insn *);\n\ |
72 | extern int insn_min_length (rtx_insn *);\n\ | |
73 | extern int insn_variable_length_p (rtx_insn *);\n\ | |
74 | extern int insn_current_length (rtx_insn *);\n\n\ | |
9a5834ae | 75 | #include \"insn-addr.h\"\n"); |
41299f41 TW |
76 | } |
77 | } | |
78 | ||
2b21299c JJ |
79 | /* Check that attribute NAME is used in define_insn_reservation condition |
80 | EXP. Return true if it is. */ | |
81 | static bool | |
82 | check_tune_attr (const char *name, rtx exp) | |
83 | { | |
84 | switch (GET_CODE (exp)) | |
85 | { | |
86 | case AND: | |
87 | if (check_tune_attr (name, XEXP (exp, 0))) | |
88 | return true; | |
89 | return check_tune_attr (name, XEXP (exp, 1)); | |
90 | ||
91 | case IOR: | |
92 | return (check_tune_attr (name, XEXP (exp, 0)) | |
93 | && check_tune_attr (name, XEXP (exp, 1))); | |
94 | ||
95 | case EQ_ATTR: | |
96 | return strcmp (XSTR (exp, 0), name) == 0; | |
97 | ||
98 | default: | |
99 | return false; | |
100 | } | |
101 | } | |
102 | ||
103 | /* Try to find a const attribute (usually cpu or tune) that is used | |
104 | in all define_insn_reservation conditions. */ | |
105 | static bool | |
106 | find_tune_attr (rtx exp) | |
107 | { | |
108 | unsigned int i; | |
109 | rtx attr; | |
110 | ||
111 | switch (GET_CODE (exp)) | |
112 | { | |
113 | case AND: | |
114 | case IOR: | |
115 | if (find_tune_attr (XEXP (exp, 0))) | |
116 | return true; | |
117 | return find_tune_attr (XEXP (exp, 1)); | |
118 | ||
119 | case EQ_ATTR: | |
120 | if (strcmp (XSTR (exp, 0), "alternative") == 0) | |
121 | return false; | |
122 | ||
9771b263 | 123 | FOR_EACH_VEC_ELT (const_attrs, i, attr) |
2b21299c JJ |
124 | if (strcmp (XSTR (attr, 0), XSTR (exp, 0)) == 0) |
125 | { | |
126 | unsigned int j; | |
127 | rtx resv; | |
128 | ||
9771b263 | 129 | FOR_EACH_VEC_ELT (reservations, j, resv) |
2b21299c JJ |
130 | if (! check_tune_attr (XSTR (attr, 0), XEXP (resv, 2))) |
131 | return false; | |
132 | return true; | |
133 | } | |
134 | return false; | |
135 | ||
136 | default: | |
137 | return false; | |
138 | } | |
139 | } | |
140 | ||
41299f41 | 141 | int |
3d7aafde | 142 | main (int argc, char **argv) |
41299f41 TW |
143 | { |
144 | rtx desc; | |
f12b8918 TM |
145 | int have_delay = 0; |
146 | int have_annul_true = 0; | |
147 | int have_annul_false = 0; | |
fae15c93 | 148 | int num_insn_reservations = 0; |
41299f41 TW |
149 | int i; |
150 | ||
f8b6598e | 151 | progname = "genattr"; |
41299f41 | 152 | |
600ab3fc | 153 | if (!init_rtx_reader_args (argc, argv)) |
c88c0d42 | 154 | return (FATAL_EXIT_CODE); |
41299f41 | 155 | |
0313e85b ZW |
156 | puts ("/* Generated automatically by the program `genattr'"); |
157 | puts (" from the machine description file `md'. */\n"); | |
158 | puts ("#ifndef GCC_INSN_ATTR_H"); | |
159 | puts ("#define GCC_INSN_ATTR_H\n"); | |
41299f41 | 160 | |
88a00ef7 JM |
161 | puts ("#include \"insn-attr-common.h\"\n"); |
162 | ||
41299f41 TW |
163 | /* Read the machine description. */ |
164 | ||
165 | while (1) | |
166 | { | |
c88c0d42 CP |
167 | int line_no, insn_code_number; |
168 | ||
169 | desc = read_md_rtx (&line_no, &insn_code_number); | |
170 | if (desc == NULL) | |
41299f41 | 171 | break; |
41299f41 | 172 | |
8f4fe86c RS |
173 | if (GET_CODE (desc) == DEFINE_ATTR |
174 | || GET_CODE (desc) == DEFINE_ENUM_ATTR) | |
f12b8918 | 175 | gen_attr (desc); |
41299f41 | 176 | |
f12b8918 TM |
177 | else if (GET_CODE (desc) == DEFINE_DELAY) |
178 | { | |
179 | if (! have_delay) | |
180 | { | |
84034c69 | 181 | printf ("extern int num_delay_slots (rtx_insn *);\n"); |
b32d5189 | 182 | printf ("extern int eligible_for_delay (rtx_insn *, int, rtx_insn *, int);\n\n"); |
647d790d | 183 | printf ("extern int const_num_delay_slots (rtx_insn *);\n\n"); |
f12b8918 TM |
184 | have_delay = 1; |
185 | } | |
41299f41 | 186 | |
f12b8918 TM |
187 | for (i = 0; i < XVECLEN (desc, 1); i += 3) |
188 | { | |
189 | if (XVECEXP (desc, 1, i + 1) && ! have_annul_true) | |
190 | { | |
191 | printf ("#define ANNUL_IFTRUE_SLOTS\n"); | |
b32d5189 | 192 | printf ("extern int eligible_for_annul_true (rtx_insn *, int, rtx_insn *, int);\n"); |
f12b8918 TM |
193 | have_annul_true = 1; |
194 | } | |
ef3fad04 | 195 | |
f12b8918 TM |
196 | if (XVECEXP (desc, 1, i + 2) && ! have_annul_false) |
197 | { | |
198 | printf ("#define ANNUL_IFFALSE_SLOTS\n"); | |
b32d5189 | 199 | printf ("extern int eligible_for_annul_false (rtx_insn *, int, rtx_insn *, int);\n"); |
f12b8918 TM |
200 | have_annul_false = 1; |
201 | } | |
202 | } | |
203 | } | |
ef3fad04 | 204 | |
fae15c93 | 205 | else if (GET_CODE (desc) == DEFINE_INSN_RESERVATION) |
2b21299c JJ |
206 | { |
207 | num_insn_reservations++; | |
9771b263 | 208 | reservations.safe_push (desc); |
2b21299c | 209 | } |
f12b8918 | 210 | } |
ef3fad04 | 211 | |
fa0aee89 | 212 | if (num_insn_reservations > 0) |
f12b8918 | 213 | { |
2b21299c | 214 | bool has_tune_attr |
9771b263 | 215 | = find_tune_attr (XEXP (reservations[0], 2)); |
fae15c93 VM |
216 | /* Output interface for pipeline hazards recognition based on |
217 | DFA (deterministic finite state automata. */ | |
218 | printf ("\n/* DFA based pipeline interface. */"); | |
d530b07f VM |
219 | printf ("\n#ifndef AUTOMATON_ALTS\n"); |
220 | printf ("#define AUTOMATON_ALTS 0\n"); | |
221 | printf ("#endif\n\n"); | |
fae15c93 VM |
222 | printf ("\n#ifndef AUTOMATON_STATE_ALTS\n"); |
223 | printf ("#define AUTOMATON_STATE_ALTS 0\n"); | |
224 | printf ("#endif\n\n"); | |
225 | printf ("#ifndef CPU_UNITS_QUERY\n"); | |
226 | printf ("#define CPU_UNITS_QUERY 0\n"); | |
227 | printf ("#endif\n\n"); | |
228 | /* Interface itself: */ | |
2b21299c JJ |
229 | if (has_tune_attr) |
230 | { | |
231 | printf ("/* Initialize fn pointers for internal_dfa_insn_code\n"); | |
232 | printf (" and insn_default_latency. */\n"); | |
233 | printf ("extern void init_sched_attrs (void);\n\n"); | |
234 | printf ("/* Internal insn code number used by automata. */\n"); | |
84034c69 | 235 | printf ("extern int (*internal_dfa_insn_code) (rtx_insn *);\n\n"); |
2b21299c | 236 | printf ("/* Insn latency time defined in define_insn_reservation. */\n"); |
84034c69 | 237 | printf ("extern int (*insn_default_latency) (rtx_insn *);\n\n"); |
2b21299c JJ |
238 | } |
239 | else | |
240 | { | |
241 | printf ("#define init_sched_attrs() do { } while (0)\n\n"); | |
242 | printf ("/* Internal insn code number used by automata. */\n"); | |
84034c69 | 243 | printf ("extern int internal_dfa_insn_code (rtx_insn *);\n\n"); |
2b21299c | 244 | printf ("/* Insn latency time defined in define_insn_reservation. */\n"); |
84034c69 | 245 | printf ("extern int insn_default_latency (rtx_insn *);\n\n"); |
2b21299c | 246 | } |
fae15c93 VM |
247 | printf ("/* Return nonzero if there is a bypass for given insn\n"); |
248 | printf (" which is a data producer. */\n"); | |
84034c69 | 249 | printf ("extern int bypass_p (rtx_insn *);\n\n"); |
fae15c93 VM |
250 | printf ("/* Insn latency time on data consumed by the 2nd insn.\n"); |
251 | printf (" Use the function if bypass_p returns nonzero for\n"); | |
252 | printf (" the 1st insn. */\n"); | |
84034c69 | 253 | printf ("extern int insn_latency (rtx, rtx);\n\n"); |
e855c69d AB |
254 | printf ("/* Maximal insn latency time possible of all bypasses for this insn.\n"); |
255 | printf (" Use the function if bypass_p returns nonzero for\n"); | |
256 | printf (" the 1st insn. */\n"); | |
257 | printf ("extern int maximal_insn_latency (rtx);\n\n"); | |
d530b07f | 258 | printf ("\n#if AUTOMATON_ALTS\n"); |
fae15c93 VM |
259 | printf ("/* The following function returns number of alternative\n"); |
260 | printf (" reservations of given insn. It may be used for better\n"); | |
261 | printf (" insns scheduling heuristics. */\n"); | |
3d7aafde | 262 | printf ("extern int insn_alts (rtx);\n\n"); |
d530b07f | 263 | printf ("#endif\n\n"); |
fae15c93 VM |
264 | printf ("/* Maximal possible number of insns waiting results being\n"); |
265 | printf (" produced by insns whose execution is not finished. */\n"); | |
5f2f0edd | 266 | printf ("extern const int max_insn_queue_index;\n\n"); |
fae15c93 VM |
267 | printf ("/* Pointer to data describing current state of DFA. */\n"); |
268 | printf ("typedef void *state_t;\n\n"); | |
269 | printf ("/* Size of the data in bytes. */\n"); | |
3d7aafde | 270 | printf ("extern int state_size (void);\n\n"); |
fae15c93 VM |
271 | printf ("/* Initiate given DFA state, i.e. Set up the state\n"); |
272 | printf (" as all functional units were not reserved. */\n"); | |
3d7aafde | 273 | printf ("extern void state_reset (state_t);\n"); |
fae15c93 VM |
274 | printf ("/* The following function returns negative value if given\n"); |
275 | printf (" insn can be issued in processor state described by given\n"); | |
276 | printf (" DFA state. In this case, the DFA state is changed to\n"); | |
277 | printf (" reflect the current and future reservations by given\n"); | |
278 | printf (" insn. Otherwise the function returns minimal time\n"); | |
279 | printf (" delay to issue the insn. This delay may be zero\n"); | |
280 | printf (" for superscalar or VLIW processors. If the second\n"); | |
281 | printf (" parameter is NULL the function changes given DFA state\n"); | |
282 | printf (" as new processor cycle started. */\n"); | |
3d7aafde | 283 | printf ("extern int state_transition (state_t, rtx);\n"); |
fae15c93 VM |
284 | printf ("\n#if AUTOMATON_STATE_ALTS\n"); |
285 | printf ("/* The following function returns number of possible\n"); | |
286 | printf (" alternative reservations of given insn in given\n"); | |
287 | printf (" DFA state. It may be used for better insns scheduling\n"); | |
288 | printf (" heuristics. By default the function is defined if\n"); | |
289 | printf (" macro AUTOMATON_STATE_ALTS is defined because its\n"); | |
290 | printf (" implementation may require much memory. */\n"); | |
3d7aafde | 291 | printf ("extern int state_alts (state_t, rtx);\n"); |
fae15c93 | 292 | printf ("#endif\n\n"); |
84034c69 | 293 | printf ("extern int min_issue_delay (state_t, rtx_insn *);\n"); |
fae15c93 VM |
294 | printf ("/* The following function returns nonzero if no one insn\n"); |
295 | printf (" can be issued in current DFA state. */\n"); | |
3d7aafde | 296 | printf ("extern int state_dead_lock_p (state_t);\n"); |
fae15c93 VM |
297 | printf ("/* The function returns minimal delay of issue of the 2nd\n"); |
298 | printf (" insn after issuing the 1st insn in given DFA state.\n"); | |
299 | printf (" The 1st insn should be issued in given state (i.e.\n"); | |
300 | printf (" state_transition should return negative value for\n"); | |
301 | printf (" the insn and the state). Data dependencies between\n"); | |
302 | printf (" the insns are ignored by the function. */\n"); | |
303 | printf | |
3d7aafde | 304 | ("extern int min_insn_conflict_delay (state_t, rtx, rtx);\n"); |
fae15c93 VM |
305 | printf ("/* The following function outputs reservations for given\n"); |
306 | printf (" insn as they are described in the corresponding\n"); | |
307 | printf (" define_insn_reservation. */\n"); | |
84034c69 | 308 | printf ("extern void print_reservation (FILE *, rtx_insn *);\n"); |
fae15c93 VM |
309 | printf ("\n#if CPU_UNITS_QUERY\n"); |
310 | printf ("/* The following function returns code of functional unit\n"); | |
311 | printf (" with given name (see define_cpu_unit). */\n"); | |
3d7aafde | 312 | printf ("extern int get_cpu_unit_code (const char *);\n"); |
fae15c93 VM |
313 | printf ("/* The following function returns nonzero if functional\n"); |
314 | printf (" unit with given code is currently reserved in given\n"); | |
315 | printf (" DFA state. */\n"); | |
3d7aafde | 316 | printf ("extern int cpu_unit_reservation_p (state_t, int);\n"); |
dd1b7476 | 317 | printf ("#endif\n\n"); |
1c3d0d93 MK |
318 | printf ("/* The following function returns true if insn\n"); |
319 | printf (" has a dfa reservation. */\n"); | |
84034c69 | 320 | printf ("extern bool insn_has_dfa_reservation_p (rtx_insn *);\n\n"); |
30028c85 VM |
321 | printf ("/* Clean insn code cache. It should be called if there\n"); |
322 | printf (" is a chance that condition value in a\n"); | |
323 | printf (" define_insn_reservation will be changed after\n"); | |
324 | printf (" last call of dfa_start. */\n"); | |
3d7aafde | 325 | printf ("extern void dfa_clean_insn_cache (void);\n\n"); |
cbba639c | 326 | printf ("extern void dfa_clear_single_insn_cache (rtx_insn *);\n\n"); |
fae15c93 VM |
327 | printf ("/* Initiate and finish work with DFA. They should be\n"); |
328 | printf (" called as the first and the last interface\n"); | |
329 | printf (" functions. */\n"); | |
3d7aafde AJ |
330 | printf ("extern void dfa_start (void);\n"); |
331 | printf ("extern void dfa_finish (void);\n"); | |
fae15c93 VM |
332 | } |
333 | else | |
334 | { | |
335 | /* Otherwise we do no scheduling, but we need these typedefs | |
336 | in order to avoid uglifying other code with more ifdefs. */ | |
337 | printf ("typedef void *state_t;\n\n"); | |
a224278b | 338 | } |
b29d5f75 | 339 | |
688010ba | 340 | /* Special-purpose attributes should be tested with if, not #ifdef. */ |
9840b2fa RS |
341 | const char * const special_attrs[] = { "length", "enabled", |
342 | "preferred_for_size", | |
343 | "preferred_for_speed", 0 }; | |
d327457f JR |
344 | for (const char * const *p = special_attrs; *p; p++) |
345 | { | |
346 | printf ("#ifndef HAVE_ATTR_%s\n" | |
347 | "#define HAVE_ATTR_%s 0\n" | |
348 | "#endif\n", *p, *p); | |
349 | } | |
350 | /* We make an exception here to provide stub definitions for | |
351 | insn_*_length* / get_attr_enabled functions. */ | |
352 | puts ("#if !HAVE_ATTR_length\n" | |
84034c69 DM |
353 | "extern int hook_int_rtx_insn_unreachable (rtx_insn *);\n" |
354 | "#define insn_default_length hook_int_rtx_insn_unreachable\n" | |
355 | "#define insn_min_length hook_int_rtx_insn_unreachable\n" | |
356 | "#define insn_variable_length_p hook_int_rtx_insn_unreachable\n" | |
357 | "#define insn_current_length hook_int_rtx_insn_unreachable\n" | |
d327457f JR |
358 | "#include \"insn-addr.h\"\n" |
359 | "#endif\n" | |
d327457f | 360 | "extern int hook_int_rtx_1 (rtx);\n" |
9840b2fa | 361 | "#if !HAVE_ATTR_enabled\n" |
d327457f | 362 | "#define get_attr_enabled hook_int_rtx_1\n" |
9840b2fa RS |
363 | "#endif\n" |
364 | "#if !HAVE_ATTR_preferred_for_size\n" | |
365 | "#define get_attr_preferred_for_size hook_int_rtx_1\n" | |
366 | "#endif\n" | |
367 | "#if !HAVE_ATTR_preferred_for_speed\n" | |
368 | "#define get_attr_preferred_for_speed hook_int_rtx_1\n" | |
d327457f JR |
369 | "#endif\n"); |
370 | ||
3d7aafde | 371 | /* Output flag masks for use by reorg. |
eaa48dab | 372 | |
593dbe11 | 373 | Flags are used to hold branch direction for use by eligible_for_... */ |
c3284718 RS |
374 | printf ("\n#define ATTR_FLAG_forward\t0x1\n"); |
375 | printf ("#define ATTR_FLAG_backward\t0x2\n"); | |
eaa48dab | 376 | |
c3284718 | 377 | puts ("\n#endif /* GCC_INSN_ATTR_H */"); |
0313e85b ZW |
378 | |
379 | if (ferror (stdout) || fflush (stdout) || fclose (stdout)) | |
380 | return FATAL_EXIT_CODE; | |
381 | ||
382 | return SUCCESS_EXIT_CODE; | |
41299f41 | 383 | } |