Use new tail-calling mechanism on ARM.
[official-gcc.git] / gcc / genattr.c
blob36a37b1a40884f844d22592165233e354196b434
1 /* Generate attribute information (insn-attr.h) from machine description.
2 Copyright (C) 1991, 1994, 1996, 1998, 1999, 2000 Free Software Foundation, Inc.
3 Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU CC is distributed in the hope that it will be useful,
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.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 #include "hconfig.h"
24 #include "system.h"
25 #include "rtl.h"
26 #include "obstack.h"
27 #include "errors.h"
28 #include "gensupport.h"
30 static struct obstack obstack;
31 struct obstack *rtl_obstack = &obstack;
33 #define obstack_chunk_alloc xmalloc
34 #define obstack_chunk_free free
36 /* A range of values. */
38 struct range
40 int min;
41 int max;
44 /* Record information about each function unit mentioned in a
45 DEFINE_FUNCTION_UNIT. */
47 struct function_unit
49 char *name; /* Function unit name. */
50 struct function_unit *next; /* Next function unit. */
51 int multiplicity; /* Number of units of this type. */
52 int simultaneity; /* Maximum number of simultaneous insns
53 on this function unit or 0 if unlimited. */
54 struct range ready_cost; /* Range of ready cost values. */
55 struct range issue_delay; /* Range of issue delay values. */
58 static void extend_range PARAMS ((struct range *, int, int));
59 static void init_range PARAMS ((struct range *));
60 static void write_upcase PARAMS ((const char *));
61 static void gen_attr PARAMS ((rtx));
62 static void write_units PARAMS ((int, struct range *, struct range *,
63 struct range *, struct range *,
64 struct range *));
65 static void
66 extend_range (range, min, max)
67 struct range *range;
68 int min;
69 int max;
71 if (range->min > min) range->min = min;
72 if (range->max < max) range->max = max;
75 static void
76 init_range (range)
77 struct range *range;
79 range->min = 100000;
80 range->max = -1;
83 static void
84 write_upcase (str)
85 const char *str;
87 for (; *str; str++)
88 putchar (TOUPPER(*str));
91 static void
92 gen_attr (attr)
93 rtx attr;
95 const char *p;
96 int is_const = GET_CODE (XEXP (attr, 2)) == CONST;
98 printf ("#define HAVE_ATTR_%s\n", XSTR (attr, 0));
100 /* If numeric attribute, don't need to write an enum. */
101 if (*XSTR (attr, 1) == '\0')
102 printf ("extern int get_attr_%s PARAMS ((%s));\n", XSTR (attr, 0),
103 (is_const ? "void" : "rtx"));
104 else
106 printf ("enum attr_%s {", XSTR (attr, 0));
107 write_upcase (XSTR (attr, 0));
108 printf ("_");
110 for (p = XSTR (attr, 1); *p != '\0'; p++)
112 if (*p == ',')
114 printf (", ");
115 write_upcase (XSTR (attr, 0));
116 printf ("_");
118 else
119 putchar (TOUPPER(*p));
122 printf ("};\n");
123 printf ("extern enum attr_%s get_attr_%s PARAMS ((%s));\n\n",
124 XSTR (attr, 0), XSTR (attr, 0), (is_const ? "void" : "rtx"));
127 /* If `length' attribute, write additional function definitions and define
128 variables used by `insn_current_length'. */
129 if (! strcmp (XSTR (attr, 0), "length"))
131 printf ("extern void shorten_branches PARAMS ((rtx));\n");
132 printf ("extern int insn_default_length PARAMS ((rtx));\n");
133 printf ("extern int insn_variable_length_p PARAMS ((rtx));\n");
134 printf ("extern int insn_current_length PARAMS ((rtx));\n\n");
135 printf ("extern int *insn_addresses;\n");
136 printf ("extern int insn_current_address;\n\n");
140 static void
141 write_units (num_units, multiplicity, simultaneity,
142 ready_cost, issue_delay, blockage)
143 int num_units;
144 struct range *multiplicity;
145 struct range *simultaneity;
146 struct range *ready_cost;
147 struct range *issue_delay;
148 struct range *blockage;
150 int i, q_size;
152 printf ("#define INSN_SCHEDULING\n\n");
153 printf ("extern int result_ready_cost PARAMS ((rtx));\n");
154 printf ("extern int function_units_used PARAMS ((rtx));\n\n");
155 printf ("extern struct function_unit_desc\n");
156 printf ("{\n");
157 printf (" const char *name;\n");
158 printf (" int bitmask;\n");
159 printf (" int multiplicity;\n");
160 printf (" int simultaneity;\n");
161 printf (" int default_cost;\n");
162 printf (" int max_issue_delay;\n");
163 printf (" int (*ready_cost_function) PARAMS ((rtx));\n");
164 printf (" int (*conflict_cost_function) PARAMS ((rtx, rtx));\n");
165 printf (" int max_blockage;\n");
166 printf (" unsigned int (*blockage_range_function) PARAMS ((rtx));\n");
167 printf (" int (*blockage_function) PARAMS ((rtx, rtx));\n");
168 printf ("} function_units[];\n\n");
169 printf ("#define FUNCTION_UNITS_SIZE %d\n", num_units);
170 printf ("#define MIN_MULTIPLICITY %d\n", multiplicity->min);
171 printf ("#define MAX_MULTIPLICITY %d\n", multiplicity->max);
172 printf ("#define MIN_SIMULTANEITY %d\n", simultaneity->min);
173 printf ("#define MAX_SIMULTANEITY %d\n", simultaneity->max);
174 printf ("#define MIN_READY_COST %d\n", ready_cost->min);
175 printf ("#define MAX_READY_COST %d\n", ready_cost->max);
176 printf ("#define MIN_ISSUE_DELAY %d\n", issue_delay->min);
177 printf ("#define MAX_ISSUE_DELAY %d\n", issue_delay->max);
178 printf ("#define MIN_BLOCKAGE %d\n", blockage->min);
179 printf ("#define MAX_BLOCKAGE %d\n", blockage->max);
180 for (i = 0; (1 << i) < blockage->max; i++)
182 printf ("#define BLOCKAGE_BITS %d\n", i + 1);
184 /* INSN_QUEUE_SIZE is a power of two larger than MAX_BLOCKAGE and
185 MAX_READY_COST. This is the longest time an isnsn may be queued. */
186 i = MAX (blockage->max, ready_cost->max);
187 for (q_size = 1; q_size <= i; q_size <<= 1)
189 printf ("#define INSN_QUEUE_SIZE %d\n", q_size);
193 xmalloc (size)
194 size_t size;
196 register PTR val = (PTR) malloc (size);
198 if (val == 0)
199 fatal ("virtual memory exhausted");
200 return val;
204 xrealloc (old, size)
205 PTR old;
206 size_t size;
208 register PTR ptr;
209 if (old)
210 ptr = (PTR) realloc (old, size);
211 else
212 ptr = (PTR) malloc (size);
213 if (!ptr)
214 fatal ("virtual memory exhausted");
215 return ptr;
218 extern int main PARAMS ((int, char **));
221 main (argc, argv)
222 int argc;
223 char **argv;
225 rtx desc;
226 int have_delay = 0;
227 int have_annul_true = 0;
228 int have_annul_false = 0;
229 int num_units = 0;
230 struct range all_simultaneity, all_multiplicity;
231 struct range all_ready_cost, all_issue_delay, all_blockage;
232 struct function_unit *units = 0, *unit;
233 int i;
235 init_range (&all_multiplicity);
236 init_range (&all_simultaneity);
237 init_range (&all_ready_cost);
238 init_range (&all_issue_delay);
239 init_range (&all_blockage);
241 progname = "genattr";
242 obstack_init (rtl_obstack);
244 if (argc <= 1)
245 fatal ("No input file name.");
247 if (init_md_reader (argv[1]) != SUCCESS_EXIT_CODE)
248 return (FATAL_EXIT_CODE);
250 printf ("/* Generated automatically by the program `genattr'\n\
251 from the machine description file `md'. */\n\n");
253 /* For compatibility, define the attribute `alternative', which is just
254 a reference to the variable `which_alternative'. */
256 printf ("#define HAVE_ATTR_alternative\n");
257 printf ("#define get_attr_alternative(insn) which_alternative\n");
259 /* Read the machine description. */
261 while (1)
263 int line_no, insn_code_number;
265 desc = read_md_rtx (&line_no, &insn_code_number);
266 if (desc == NULL)
267 break;
269 if (GET_CODE (desc) == DEFINE_ATTR)
270 gen_attr (desc);
272 else if (GET_CODE (desc) == DEFINE_DELAY)
274 if (! have_delay)
276 printf ("#define DELAY_SLOTS\n");
277 printf ("extern int num_delay_slots PARAMS ((rtx));\n");
278 printf ("extern int eligible_for_delay PARAMS ((rtx, int, rtx, int));\n\n");
279 printf ("extern int const_num_delay_slots PARAMS ((rtx));\n\n");
280 have_delay = 1;
283 for (i = 0; i < XVECLEN (desc, 1); i += 3)
285 if (XVECEXP (desc, 1, i + 1) && ! have_annul_true)
287 printf ("#define ANNUL_IFTRUE_SLOTS\n");
288 printf ("extern int eligible_for_annul_true PARAMS ((rtx, int, rtx, int));\n");
289 have_annul_true = 1;
292 if (XVECEXP (desc, 1, i + 2) && ! have_annul_false)
294 printf ("#define ANNUL_IFFALSE_SLOTS\n");
295 printf ("extern int eligible_for_annul_false PARAMS ((rtx, int, rtx, int));\n");
296 have_annul_false = 1;
301 else if (GET_CODE (desc) == DEFINE_FUNCTION_UNIT)
303 const char *name = XSTR (desc, 0);
304 int multiplicity = XINT (desc, 1);
305 int simultaneity = XINT (desc, 2);
306 int ready_cost = MAX (XINT (desc, 4), 1);
307 int issue_delay = MAX (XINT (desc, 5), 1);
308 int issueexp_p = (XVEC (desc, 6) != 0);
310 for (unit = units; unit; unit = unit->next)
311 if (strcmp (unit->name, name) == 0)
312 break;
314 if (unit == 0)
316 int len = strlen (name) + 1;
317 unit = (struct function_unit *)
318 alloca (sizeof (struct function_unit));
319 unit->name = (char *) alloca (len);
320 bcopy (name, unit->name, len);
321 unit->multiplicity = multiplicity;
322 unit->simultaneity = simultaneity;
323 unit->ready_cost.min = unit->ready_cost.max = ready_cost;
324 unit->issue_delay.min = unit->issue_delay.max = issue_delay;
325 unit->next = units;
326 units = unit;
327 num_units++;
329 extend_range (&all_multiplicity, multiplicity, multiplicity);
330 extend_range (&all_simultaneity, simultaneity, simultaneity);
332 else if (unit->multiplicity != multiplicity
333 || unit->simultaneity != simultaneity)
334 fatal ("Differing specifications given for `%s' function unit.",
335 unit->name);
337 extend_range (&unit->ready_cost, ready_cost, ready_cost);
338 extend_range (&unit->issue_delay,
339 issueexp_p ? 1 : issue_delay, issue_delay);
340 extend_range (&all_ready_cost,
341 unit->ready_cost.min, unit->ready_cost.max);
342 extend_range (&all_issue_delay,
343 unit->issue_delay.min, unit->issue_delay.max);
347 if (num_units > 0)
349 /* Compute the range of blockage cost values. See genattrtab.c
350 for the derivation. BLOCKAGE (E,C) when SIMULTANEITY is zero is
352 MAX (ISSUE-DELAY (E,C),
353 READY-COST (E) - (READY-COST (C) - 1))
355 and otherwise
357 MAX (ISSUE-DELAY (E,C),
358 READY-COST (E) - (READY-COST (C) - 1),
359 READY-COST (E) - FILL-TIME) */
361 for (unit = units; unit; unit = unit->next)
363 struct range blockage;
365 blockage = unit->issue_delay;
366 blockage.max = MAX (unit->ready_cost.max
367 - (unit->ready_cost.min - 1),
368 blockage.max);
369 blockage.min = MAX (1, blockage.min);
371 if (unit->simultaneity != 0)
373 int fill_time = ((unit->simultaneity - 1)
374 * unit->issue_delay.min);
375 blockage.min = MAX (unit->ready_cost.min - fill_time,
376 blockage.min);
377 blockage.max = MAX (unit->ready_cost.max - fill_time,
378 blockage.max);
380 extend_range (&all_blockage, blockage.min, blockage.max);
383 write_units (num_units, &all_multiplicity, &all_simultaneity,
384 &all_ready_cost, &all_issue_delay, &all_blockage);
387 /* Output flag masks for use by reorg.
389 Flags are used to hold branch direction and prediction information
390 for use by eligible_for_... */
391 printf("\n#define ATTR_FLAG_forward\t0x1\n");
392 printf("#define ATTR_FLAG_backward\t0x2\n");
393 printf("#define ATTR_FLAG_likely\t0x4\n");
394 printf("#define ATTR_FLAG_very_likely\t0x8\n");
395 printf("#define ATTR_FLAG_unlikely\t0x10\n");
396 printf("#define ATTR_FLAG_very_unlikely\t0x20\n");
398 fflush (stdout);
399 return (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
402 /* Define this so we can link with print-rtl.o to get debug_rtx function. */
403 const char *
404 get_insn_name (code)
405 int code ATTRIBUTE_UNUSED;
407 return NULL;