]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/genattr.c
f9501eda39ebcec1fdcdf509b518db49271c9355
1 /* Generate attribute information (insn-attr.h) from machine description.
2 Copyright (C) 1991, 1994, 1996, 1998, 1999 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)
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. */
29 static struct obstack obstack
;
30 struct obstack
*rtl_obstack
= &obstack
;
32 #define obstack_chunk_alloc xmalloc
33 #define obstack_chunk_free free
35 /* Define this so we can link with print-rtl.o to get debug_rtx function. */
36 char **insn_name_ptr
= 0;
38 /* A range of values. */
46 /* Record information about each function unit mentioned in a
47 DEFINE_FUNCTION_UNIT. */
51 char *name
; /* Function unit name. */
52 struct function_unit
*next
; /* Next function unit. */
53 int multiplicity
; /* Number of units of this type. */
54 int simultaneity
; /* Maximum number of simultaneous insns
55 on this function unit or 0 if unlimited. */
56 struct range ready_cost
; /* Range of ready cost values. */
57 struct range issue_delay
; /* Range of issue delay values. */
60 static void extend_range
PROTO((struct range
*, int, int));
61 static void init_range
PROTO((struct range
*));
62 static void write_upcase
PROTO((char *));
63 static void gen_attr
PROTO((rtx
));
64 static void write_units
PROTO((int, struct range
*, struct range
*,
65 struct range
*, struct range
*,
68 extend_range (range
, min
, max
)
73 if (range
->min
> min
) range
->min
= min
;
74 if (range
->max
< max
) range
->max
= max
;
91 printf ("%c", toupper(*str
));
101 int is_const
= GET_CODE (XEXP (attr
, 2)) == CONST
;
103 printf ("#define HAVE_ATTR_%s\n", XSTR (attr
, 0));
105 /* If numeric attribute, don't need to write an enum. */
106 if (*XSTR (attr
, 1) == '\0')
107 printf ("extern int get_attr_%s PROTO((%s));\n", XSTR (attr
, 0),
108 (is_const
? "void" : "rtx"));
111 printf ("enum attr_%s {", XSTR (attr
, 0));
112 write_upcase (XSTR (attr
, 0));
115 for (p
= XSTR (attr
, 1); *p
!= '\0'; p
++)
120 write_upcase (XSTR (attr
, 0));
123 else if (ISLOWER(*p
))
124 printf ("%c", toupper(*p
));
130 printf ("extern enum attr_%s get_attr_%s PROTO((%s));\n\n",
131 XSTR (attr
, 0), XSTR (attr
, 0), (is_const
? "void" : "rtx"));
134 /* If `length' attribute, write additional function definitions and define
135 variables used by `insn_current_length'. */
136 if (! strcmp (XSTR (attr
, 0), "length"))
138 printf ("extern void shorten_branches PROTO((rtx));\n");
139 printf ("extern int insn_default_length PROTO((rtx));\n");
140 printf ("extern int insn_variable_length_p PROTO((rtx));\n");
141 printf ("extern int insn_current_length PROTO((rtx));\n\n");
142 printf ("extern int *insn_addresses;\n");
143 printf ("extern int insn_current_address;\n\n");
148 write_units (num_units
, multiplicity
, simultaneity
,
149 ready_cost
, issue_delay
, blockage
)
151 struct range
*multiplicity
;
152 struct range
*simultaneity
;
153 struct range
*ready_cost
;
154 struct range
*issue_delay
;
155 struct range
*blockage
;
159 printf ("#define INSN_SCHEDULING\n\n");
160 printf ("extern int result_ready_cost PROTO((rtx));\n");
161 printf ("extern int function_units_used PROTO((rtx));\n\n");
162 printf ("extern struct function_unit_desc\n");
164 printf (" const char *name;\n");
165 printf (" int bitmask;\n");
166 printf (" int multiplicity;\n");
167 printf (" int simultaneity;\n");
168 printf (" int default_cost;\n");
169 printf (" int max_issue_delay;\n");
170 printf (" int (*ready_cost_function) PROTO ((rtx));\n");
171 printf (" int (*conflict_cost_function) PROTO ((rtx, rtx));\n");
172 printf (" int max_blockage;\n");
173 printf (" unsigned int (*blockage_range_function) PROTO ((rtx));\n");
174 printf (" int (*blockage_function) PROTO ((rtx, rtx));\n");
175 printf ("} function_units[];\n\n");
176 printf ("#define FUNCTION_UNITS_SIZE %d\n", num_units
);
177 printf ("#define MIN_MULTIPLICITY %d\n", multiplicity
->min
);
178 printf ("#define MAX_MULTIPLICITY %d\n", multiplicity
->max
);
179 printf ("#define MIN_SIMULTANEITY %d\n", simultaneity
->min
);
180 printf ("#define MAX_SIMULTANEITY %d\n", simultaneity
->max
);
181 printf ("#define MIN_READY_COST %d\n", ready_cost
->min
);
182 printf ("#define MAX_READY_COST %d\n", ready_cost
->max
);
183 printf ("#define MIN_ISSUE_DELAY %d\n", issue_delay
->min
);
184 printf ("#define MAX_ISSUE_DELAY %d\n", issue_delay
->max
);
185 printf ("#define MIN_BLOCKAGE %d\n", blockage
->min
);
186 printf ("#define MAX_BLOCKAGE %d\n", blockage
->max
);
187 for (i
= 0; (1 << i
) < blockage
->max
; i
++)
189 printf ("#define BLOCKAGE_BITS %d\n", i
+ 1);
191 /* INSN_QUEUE_SIZE is a power of two larger than MAX_BLOCKAGE and
192 MAX_READY_COST. This is the longest time an isnsn may be queued. */
193 i
= MAX (blockage
->max
, ready_cost
->max
);
194 for (q_size
= 1; q_size
<= i
; q_size
<<= 1)
196 printf ("#define INSN_QUEUE_SIZE %d\n", q_size
);
203 register PTR val
= (PTR
) malloc (size
);
206 fatal ("virtual memory exhausted");
217 ptr
= (PTR
) realloc (old
, size
);
219 ptr
= (PTR
) malloc (size
);
221 fatal ("virtual memory exhausted");
234 int have_annul_true
= 0;
235 int have_annul_false
= 0;
237 struct range all_simultaneity
, all_multiplicity
;
238 struct range all_ready_cost
, all_issue_delay
, all_blockage
;
239 struct function_unit
*units
= 0, *unit
;
242 init_range (&all_multiplicity
);
243 init_range (&all_simultaneity
);
244 init_range (&all_ready_cost
);
245 init_range (&all_issue_delay
);
246 init_range (&all_blockage
);
248 progname
= "genattr";
249 obstack_init (rtl_obstack
);
252 fatal ("No input file name.");
254 infile
= fopen (argv
[1], "r");
258 exit (FATAL_EXIT_CODE
);
261 printf ("/* Generated automatically by the program `genattr'\n\
262 from the machine description file `md'. */\n\n");
264 /* For compatibility, define the attribute `alternative', which is just
265 a reference to the variable `which_alternative'. */
267 printf ("#define HAVE_ATTR_alternative\n");
268 printf ("#define get_attr_alternative(insn) which_alternative\n");
270 /* Read the machine description. */
274 c
= read_skip_spaces (infile
);
279 desc
= read_rtx (infile
);
280 if (GET_CODE (desc
) == DEFINE_ATTR
)
283 else if (GET_CODE (desc
) == DEFINE_DELAY
)
287 printf ("#define DELAY_SLOTS\n");
288 printf ("extern int num_delay_slots PROTO((rtx));\n");
289 printf ("extern int eligible_for_delay PROTO((rtx, int, rtx, int));\n\n");
290 printf ("extern int const_num_delay_slots PROTO((rtx));\n\n");
294 for (i
= 0; i
< XVECLEN (desc
, 1); i
+= 3)
296 if (XVECEXP (desc
, 1, i
+ 1) && ! have_annul_true
)
298 printf ("#define ANNUL_IFTRUE_SLOTS\n");
299 printf ("extern int eligible_for_annul_true PROTO ((rtx, int, rtx, int));\n");
303 if (XVECEXP (desc
, 1, i
+ 2) && ! have_annul_false
)
305 printf ("#define ANNUL_IFFALSE_SLOTS\n");
306 printf ("extern int eligible_for_annul_false PROTO ((rtx, int, rtx, int));\n");
307 have_annul_false
= 1;
312 else if (GET_CODE (desc
) == DEFINE_FUNCTION_UNIT
)
314 char *name
= XSTR (desc
, 0);
315 int multiplicity
= XINT (desc
, 1);
316 int simultaneity
= XINT (desc
, 2);
317 int ready_cost
= MAX (XINT (desc
, 4), 1);
318 int issue_delay
= MAX (XINT (desc
, 5), 1);
319 int issueexp_p
= (XVEC (desc
, 6) != 0);
321 for (unit
= units
; unit
; unit
= unit
->next
)
322 if (strcmp (unit
->name
, name
) == 0)
327 int len
= strlen (name
) + 1;
328 unit
= (struct function_unit
*)
329 alloca (sizeof (struct function_unit
));
330 unit
->name
= (char *) alloca (len
);
331 bcopy (name
, unit
->name
, len
);
332 unit
->multiplicity
= multiplicity
;
333 unit
->simultaneity
= simultaneity
;
334 unit
->ready_cost
.min
= unit
->ready_cost
.max
= ready_cost
;
335 unit
->issue_delay
.min
= unit
->issue_delay
.max
= issue_delay
;
340 extend_range (&all_multiplicity
, multiplicity
, multiplicity
);
341 extend_range (&all_simultaneity
, simultaneity
, simultaneity
);
343 else if (unit
->multiplicity
!= multiplicity
344 || unit
->simultaneity
!= simultaneity
)
345 fatal ("Differing specifications given for `%s' function unit.",
348 extend_range (&unit
->ready_cost
, ready_cost
, ready_cost
);
349 extend_range (&unit
->issue_delay
,
350 issueexp_p
? 1 : issue_delay
, issue_delay
);
351 extend_range (&all_ready_cost
,
352 unit
->ready_cost
.min
, unit
->ready_cost
.max
);
353 extend_range (&all_issue_delay
,
354 unit
->issue_delay
.min
, unit
->issue_delay
.max
);
360 /* Compute the range of blockage cost values. See genattrtab.c
361 for the derivation. BLOCKAGE (E,C) when SIMULTANEITY is zero is
363 MAX (ISSUE-DELAY (E,C),
364 READY-COST (E) - (READY-COST (C) - 1))
368 MAX (ISSUE-DELAY (E,C),
369 READY-COST (E) - (READY-COST (C) - 1),
370 READY-COST (E) - FILL-TIME) */
372 for (unit
= units
; unit
; unit
= unit
->next
)
374 struct range blockage
;
376 blockage
= unit
->issue_delay
;
377 blockage
.max
= MAX (unit
->ready_cost
.max
378 - (unit
->ready_cost
.min
- 1),
380 blockage
.min
= MAX (1, blockage
.min
);
382 if (unit
->simultaneity
!= 0)
384 int fill_time
= ((unit
->simultaneity
- 1)
385 * unit
->issue_delay
.min
);
386 blockage
.min
= MAX (unit
->ready_cost
.min
- fill_time
,
388 blockage
.max
= MAX (unit
->ready_cost
.max
- fill_time
,
391 extend_range (&all_blockage
, blockage
.min
, blockage
.max
);
394 write_units (num_units
, &all_multiplicity
, &all_simultaneity
,
395 &all_ready_cost
, &all_issue_delay
, &all_blockage
);
398 /* Output flag masks for use by reorg.
400 Flags are used to hold branch direction and prediction information
401 for use by eligible_for_... */
402 printf("\n#define ATTR_FLAG_forward\t0x1\n");
403 printf("#define ATTR_FLAG_backward\t0x2\n");
404 printf("#define ATTR_FLAG_likely\t0x4\n");
405 printf("#define ATTR_FLAG_very_likely\t0x8\n");
406 printf("#define ATTR_FLAG_unlikely\t0x10\n");
407 printf("#define ATTR_FLAG_very_unlikely\t0x20\n");
410 exit (ferror (stdout
) != 0 ? FATAL_EXIT_CODE
: SUCCESS_EXIT_CODE
);