1 /* Generate attribute information (insn-attr.h) from machine description.
2 Copyright (C) 1991, 1994, 1996, 1998 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. */
28 static struct obstack obstack
;
29 struct obstack
*rtl_obstack
= &obstack
;
31 #define obstack_chunk_alloc xmalloc
32 #define obstack_chunk_free free
34 static void fatal
PVPROTO ((const char *, ...))
35 ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN
;
36 void fancy_abort
PROTO((void)) ATTRIBUTE_NORETURN
;
38 /* Define this so we can link with print-rtl.o to get debug_rtx function. */
39 char **insn_name_ptr
= 0;
41 /* A range of values. */
49 /* Record information about each function unit mentioned in a
50 DEFINE_FUNCTION_UNIT. */
54 char *name
; /* Function unit name. */
55 struct function_unit
*next
; /* Next function unit. */
56 int multiplicity
; /* Number of units of this type. */
57 int simultaneity
; /* Maximum number of simultaneous insns
58 on this function unit or 0 if unlimited. */
59 struct range ready_cost
; /* Range of ready cost values. */
60 struct range issue_delay
; /* Range of issue delay values. */
63 static void extend_range
PROTO((struct range
*, int, int));
64 static void init_range
PROTO((struct range
*));
65 static void write_upcase
PROTO((char *));
66 static void gen_attr
PROTO((rtx
));
67 static void write_units
PROTO((int, struct range
*, struct range
*,
68 struct range
*, struct range
*,
71 extend_range (range
, min
, max
)
76 if (range
->min
> min
) range
->min
= min
;
77 if (range
->max
< max
) range
->max
= max
;
93 if (*str
>= 'a' && *str
<= 'z')
94 printf ("%c", *str
- 'a' + 'A');
105 printf ("#define HAVE_ATTR_%s\n", XSTR (attr
, 0));
107 /* If numeric attribute, don't need to write an enum. */
108 if (*XSTR (attr
, 1) == '\0')
109 printf ("extern int get_attr_%s ();\n", XSTR (attr
, 0));
112 printf ("enum attr_%s {", XSTR (attr
, 0));
113 write_upcase (XSTR (attr
, 0));
116 for (p
= XSTR (attr
, 1); *p
!= '\0'; p
++)
121 write_upcase (XSTR (attr
, 0));
124 else if (*p
>= 'a' && *p
<= 'z')
125 printf ("%c", *p
- 'a' + 'A');
131 printf ("extern enum attr_%s get_attr_%s ();\n\n",
132 XSTR (attr
, 0), XSTR (attr
, 0));
135 /* If `length' attribute, write additional function definitions and define
136 variables used by `insn_current_length'. */
137 if (! strcmp (XSTR (attr
, 0), "length"))
139 printf ("extern void init_lengths ();\n");
140 printf ("extern void shorten_branches PROTO((rtx));\n");
141 printf ("extern int insn_default_length PROTO((rtx));\n");
142 printf ("extern int insn_variable_length_p PROTO((rtx));\n");
143 printf ("extern int insn_current_length PROTO((rtx));\n\n");
144 printf ("extern int *insn_addresses;\n");
145 printf ("extern int insn_current_address;\n\n");
150 write_units (num_units
, multiplicity
, simultaneity
,
151 ready_cost
, issue_delay
, blockage
)
153 struct range
*multiplicity
;
154 struct range
*simultaneity
;
155 struct range
*ready_cost
;
156 struct range
*issue_delay
;
157 struct range
*blockage
;
161 printf ("#define INSN_SCHEDULING\n\n");
162 printf ("extern int result_ready_cost PROTO((rtx));\n");
163 printf ("extern int function_units_used PROTO((rtx));\n\n");
164 printf ("extern struct function_unit_desc\n");
166 printf (" char *name;\n");
167 printf (" int bitmask;\n");
168 printf (" int multiplicity;\n");
169 printf (" int simultaneity;\n");
170 printf (" int default_cost;\n");
171 printf (" int max_issue_delay;\n");
172 printf (" int (*ready_cost_function) ();\n");
173 printf (" int (*conflict_cost_function) ();\n");
174 printf (" int max_blockage;\n");
175 printf (" unsigned int (*blockage_range_function) ();\n");
176 printf (" int (*blockage_function) ();\n");
177 printf ("} function_units[];\n\n");
178 printf ("#define FUNCTION_UNITS_SIZE %d\n", num_units
);
179 printf ("#define MIN_MULTIPLICITY %d\n", multiplicity
->min
);
180 printf ("#define MAX_MULTIPLICITY %d\n", multiplicity
->max
);
181 printf ("#define MIN_SIMULTANEITY %d\n", simultaneity
->min
);
182 printf ("#define MAX_SIMULTANEITY %d\n", simultaneity
->max
);
183 printf ("#define MIN_READY_COST %d\n", ready_cost
->min
);
184 printf ("#define MAX_READY_COST %d\n", ready_cost
->max
);
185 printf ("#define MIN_ISSUE_DELAY %d\n", issue_delay
->min
);
186 printf ("#define MAX_ISSUE_DELAY %d\n", issue_delay
->max
);
187 printf ("#define MIN_BLOCKAGE %d\n", blockage
->min
);
188 printf ("#define MAX_BLOCKAGE %d\n", blockage
->max
);
189 for (i
= 0; (1 << i
) < blockage
->max
; i
++)
191 printf ("#define BLOCKAGE_BITS %d\n", i
+ 1);
193 /* INSN_QUEUE_SIZE is a power of two larger than MAX_BLOCKAGE and
194 MAX_READY_COST. This is the longest time an isnsn may be queued. */
195 i
= MAX (blockage
->max
, ready_cost
->max
);
196 for (q_size
= 1; q_size
<= i
; q_size
<<= 1)
198 printf ("#define INSN_QUEUE_SIZE %d\n", q_size
);
205 register PTR val
= (PTR
) malloc (size
);
208 fatal ("virtual memory exhausted");
217 register PTR result
= (PTR
) realloc (ptr
, size
);
219 fatal ("virtual memory exhausted");
224 fatal
VPROTO ((const char *format
, ...))
226 #ifndef ANSI_PROTOTYPES
231 VA_START (ap
, format
);
233 #ifndef ANSI_PROTOTYPES
234 format
= va_arg (ap
, const char *);
237 fprintf (stderr
, "genattr: ");
238 vfprintf (stderr
, format
, ap
);
240 fprintf (stderr
, "\n");
241 exit (FATAL_EXIT_CODE
);
244 /* More 'friendly' abort that prints the line and file.
245 config.h can #define abort fancy_abort if you like that sort of thing. */
250 fatal ("Internal gcc abort.");
262 int have_annul_true
= 0;
263 int have_annul_false
= 0;
265 struct range all_simultaneity
, all_multiplicity
;
266 struct range all_ready_cost
, all_issue_delay
, all_blockage
;
267 struct function_unit
*units
= 0, *unit
;
270 init_range (&all_multiplicity
);
271 init_range (&all_simultaneity
);
272 init_range (&all_ready_cost
);
273 init_range (&all_issue_delay
);
274 init_range (&all_blockage
);
276 obstack_init (rtl_obstack
);
279 fatal ("No input file name.");
281 infile
= fopen (argv
[1], "r");
285 exit (FATAL_EXIT_CODE
);
290 printf ("/* Generated automatically by the program `genattr'\n\
291 from the machine description file `md'. */\n\n");
293 /* For compatibility, define the attribute `alternative', which is just
294 a reference to the variable `which_alternative'. */
296 printf ("#define HAVE_ATTR_alternative\n");
297 printf ("#define get_attr_alternative(insn) which_alternative\n");
299 /* Read the machine description. */
303 c
= read_skip_spaces (infile
);
308 desc
= read_rtx (infile
);
309 if (GET_CODE (desc
) == DEFINE_ATTR
)
312 else if (GET_CODE (desc
) == DEFINE_DELAY
)
316 printf ("#define DELAY_SLOTS\n");
317 printf ("extern int num_delay_slots PROTO((rtx));\n");
318 printf ("extern int eligible_for_delay PROTO((rtx, int, rtx, int));\n\n");
319 printf ("extern int const_num_delay_slots PROTO((rtx));\n\n");
323 for (i
= 0; i
< XVECLEN (desc
, 1); i
+= 3)
325 if (XVECEXP (desc
, 1, i
+ 1) && ! have_annul_true
)
327 printf ("#define ANNUL_IFTRUE_SLOTS\n");
328 printf ("extern int eligible_for_annul_true ();\n");
332 if (XVECEXP (desc
, 1, i
+ 2) && ! have_annul_false
)
334 printf ("#define ANNUL_IFFALSE_SLOTS\n");
335 printf ("extern int eligible_for_annul_false ();\n");
336 have_annul_false
= 1;
341 else if (GET_CODE (desc
) == DEFINE_FUNCTION_UNIT
)
343 char *name
= XSTR (desc
, 0);
344 int multiplicity
= XINT (desc
, 1);
345 int simultaneity
= XINT (desc
, 2);
346 int ready_cost
= MAX (XINT (desc
, 4), 1);
347 int issue_delay
= MAX (XINT (desc
, 5), 1);
348 int issueexp_p
= (XVEC (desc
, 6) != 0);
350 for (unit
= units
; unit
; unit
= unit
->next
)
351 if (strcmp (unit
->name
, name
) == 0)
356 int len
= strlen (name
) + 1;
357 unit
= (struct function_unit
*)
358 alloca (sizeof (struct function_unit
));
359 unit
->name
= (char *) alloca (len
);
360 bcopy (name
, unit
->name
, len
);
361 unit
->multiplicity
= multiplicity
;
362 unit
->simultaneity
= simultaneity
;
363 unit
->ready_cost
.min
= unit
->ready_cost
.max
= ready_cost
;
364 unit
->issue_delay
.min
= unit
->issue_delay
.max
= issue_delay
;
369 extend_range (&all_multiplicity
, multiplicity
, multiplicity
);
370 extend_range (&all_simultaneity
, simultaneity
, simultaneity
);
372 else if (unit
->multiplicity
!= multiplicity
373 || unit
->simultaneity
!= simultaneity
)
374 fatal ("Differing specifications given for `%s' function unit.",
377 extend_range (&unit
->ready_cost
, ready_cost
, ready_cost
);
378 extend_range (&unit
->issue_delay
,
379 issueexp_p
? 1 : issue_delay
, issue_delay
);
380 extend_range (&all_ready_cost
,
381 unit
->ready_cost
.min
, unit
->ready_cost
.max
);
382 extend_range (&all_issue_delay
,
383 unit
->issue_delay
.min
, unit
->issue_delay
.max
);
389 /* Compute the range of blockage cost values. See genattrtab.c
390 for the derivation. BLOCKAGE (E,C) when SIMULTANEITY is zero is
392 MAX (ISSUE-DELAY (E,C),
393 READY-COST (E) - (READY-COST (C) - 1))
397 MAX (ISSUE-DELAY (E,C),
398 READY-COST (E) - (READY-COST (C) - 1),
399 READY-COST (E) - FILL-TIME) */
401 for (unit
= units
; unit
; unit
= unit
->next
)
403 struct range blockage
;
405 blockage
= unit
->issue_delay
;
406 blockage
.max
= MAX (unit
->ready_cost
.max
407 - (unit
->ready_cost
.min
- 1),
409 blockage
.min
= MAX (1, blockage
.min
);
411 if (unit
->simultaneity
!= 0)
413 int fill_time
= ((unit
->simultaneity
- 1)
414 * unit
->issue_delay
.min
);
415 blockage
.min
= MAX (unit
->ready_cost
.min
- fill_time
,
417 blockage
.max
= MAX (unit
->ready_cost
.max
- fill_time
,
420 extend_range (&all_blockage
, blockage
.min
, blockage
.max
);
423 write_units (num_units
, &all_multiplicity
, &all_simultaneity
,
424 &all_ready_cost
, &all_issue_delay
, &all_blockage
);
427 /* Output flag masks for use by reorg.
429 Flags are used to hold branch direction and prediction information
430 for use by eligible_for_... */
431 printf("\n#define ATTR_FLAG_forward\t0x1\n");
432 printf("#define ATTR_FLAG_backward\t0x2\n");
433 printf("#define ATTR_FLAG_likely\t0x4\n");
434 printf("#define ATTR_FLAG_very_likely\t0x8\n");
435 printf("#define ATTR_FLAG_unlikely\t0x10\n");
436 printf("#define ATTR_FLAG_very_unlikely\t0x20\n");
439 exit (ferror (stdout
) != 0 ? FATAL_EXIT_CODE
: SUCCESS_EXIT_CODE
);