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