1 /* Generate from machine description:
2 - some #define configuration flags.
3 Copyright (C) 1987, 1991, 1997, 1998 Free Software Foundation, Inc.
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. */
33 static struct obstack obstack
;
34 struct obstack
*rtl_obstack
= &obstack
;
36 #define obstack_chunk_alloc xmalloc
37 #define obstack_chunk_free free
39 /* Define this so we can link with print-rtl.o to get debug_rtx function. */
40 char **insn_name_ptr
= 0;
42 /* flags to determine output of machine description dependent #define's. */
43 static int max_recog_operands
; /* Largest operand number seen. */
44 static int max_dup_operands
; /* Largest number of match_dup in any insn. */
45 static int max_clobbers_per_insn
;
46 static int register_constraint_flag
;
47 static int have_cc0_flag
;
48 static int have_cmove_flag
;
49 static int have_lo_sum_flag
;
51 /* Maximum number of insns seen in a split. */
52 static int max_insns_per_split
= 1;
54 static int clobbers_seen_this_insn
;
55 static int dup_operands_seen_this_insn
;
57 char *xmalloc
PROTO((unsigned));
58 static void fatal
PVPROTO ((char *, ...)) ATTRIBUTE_PRINTF_1
;
59 void fancy_abort
PROTO((void));
61 static void walk_insn_part
PROTO((rtx
, int, int));
62 static void gen_insn
PROTO((rtx
));
63 static void gen_expand
PROTO((rtx
));
64 static void gen_split
PROTO((rtx
));
65 static void gen_peephole
PROTO((rtx
));
67 /* RECOG_P will be non-zero if this pattern was seen in a context where it will
68 be used to recognize, rather than just generate an insn.
70 NON_PC_SET_SRC will be non-zero if this pattern was seen in a SET_SRC
71 of a SET whose destination is not (pc). */
74 walk_insn_part (part
, recog_p
, non_pc_set_src
)
80 register RTX_CODE code
;
81 register char *format_ptr
;
86 code
= GET_CODE (part
);
90 clobbers_seen_this_insn
++;
94 if (XINT (part
, 0) > max_recog_operands
)
95 max_recog_operands
= XINT (part
, 0);
96 if (XSTR (part
, 2) && *XSTR (part
, 2))
97 register_constraint_flag
= 1;
102 ++dup_operands_seen_this_insn
;
106 if (XINT (part
, 0) > max_recog_operands
)
107 max_recog_operands
= XINT (part
, 0);
108 /* Now scan the rtl's in the vector inside the MATCH_OPERATOR or
113 if (GET_CODE (XEXP (part
, 0)) == MATCH_OPERAND
)
118 ++dup_operands_seen_this_insn
;
119 if (XINT (part
, 0) > max_recog_operands
)
120 max_recog_operands
= XINT (part
, 0);
130 have_lo_sum_flag
= 1;
134 walk_insn_part (SET_DEST (part
), 0, recog_p
);
135 walk_insn_part (SET_SRC (part
), recog_p
,
136 GET_CODE (SET_DEST (part
)) != PC
);
140 /* Only consider this machine as having a conditional move if the
141 two arms of the IF_THEN_ELSE are both MATCH_OPERAND. Otherwise,
142 we have some specific IF_THEN_ELSE construct (like the doz
143 instruction on the RS/6000) that can't be used in the general
144 context we want it for. */
146 if (recog_p
&& non_pc_set_src
147 && GET_CODE (XEXP (part
, 1)) == MATCH_OPERAND
148 && GET_CODE (XEXP (part
, 2)) == MATCH_OPERAND
)
152 case REG
: case CONST_INT
: case SYMBOL_REF
:
160 format_ptr
= GET_RTX_FORMAT (GET_CODE (part
));
162 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (part
)); i
++)
163 switch (*format_ptr
++)
167 walk_insn_part (XEXP (part
, i
), recog_p
, non_pc_set_src
);
170 if (XVEC (part
, i
) != NULL
)
171 for (j
= 0; j
< XVECLEN (part
, i
); j
++)
172 walk_insn_part (XVECEXP (part
, i
, j
), recog_p
, non_pc_set_src
);
183 /* Walk the insn pattern to gather the #define's status. */
184 clobbers_seen_this_insn
= 0;
185 dup_operands_seen_this_insn
= 0;
186 if (XVEC (insn
, 1) != 0)
187 for (i
= 0; i
< XVECLEN (insn
, 1); i
++)
188 walk_insn_part (XVECEXP (insn
, 1, i
), 1, 0);
190 if (clobbers_seen_this_insn
> max_clobbers_per_insn
)
191 max_clobbers_per_insn
= clobbers_seen_this_insn
;
192 if (dup_operands_seen_this_insn
> max_dup_operands
)
193 max_dup_operands
= dup_operands_seen_this_insn
;
196 /* Similar but scan a define_expand. */
204 /* Walk the insn pattern to gather the #define's status. */
206 /* Note that we don't bother recording the number of MATCH_DUPs
207 that occur in a gen_expand, because only reload cares about that. */
208 if (XVEC (insn
, 1) != 0)
209 for (i
= 0; i
< XVECLEN (insn
, 1); i
++)
211 /* Compute the maximum SETs and CLOBBERS
212 in any one of the sub-insns;
213 don't sum across all of them. */
214 clobbers_seen_this_insn
= 0;
216 walk_insn_part (XVECEXP (insn
, 1, i
), 0, 0);
218 if (clobbers_seen_this_insn
> max_clobbers_per_insn
)
219 max_clobbers_per_insn
= clobbers_seen_this_insn
;
223 /* Similar but scan a define_split. */
231 /* Look through the patterns that are matched
232 to compute the maximum operand number. */
233 for (i
= 0; i
< XVECLEN (split
, 0); i
++)
234 walk_insn_part (XVECEXP (split
, 0, i
), 1, 0);
235 /* Look at the number of insns this insn could split into. */
236 if (XVECLEN (split
, 2) > max_insns_per_split
)
237 max_insns_per_split
= XVECLEN (split
, 2);
246 /* Look through the patterns that are matched
247 to compute the maximum operand number. */
248 for (i
= 0; i
< XVECLEN (peep
, 0); i
++)
249 walk_insn_part (XVECEXP (peep
, 0, i
), 1, 0);
256 register char *val
= (char *) malloc (size
);
259 fatal ("virtual memory exhausted");
269 char *result
= (char *) realloc (ptr
, size
);
271 fatal ("virtual memory exhausted");
276 fatal
VPROTO ((char *format
, ...))
283 VA_START (ap
, format
);
286 format
= va_arg (ap
, char *);
289 fprintf (stderr
, "genconfig: ");
290 vfprintf (stderr
, format
, ap
);
292 fprintf (stderr
, "\n");
293 exit (FATAL_EXIT_CODE
);
296 /* More 'friendly' abort that prints the line and file.
297 config.h can #define abort fancy_abort if you like that sort of thing. */
302 fatal ("Internal gcc abort.");
314 obstack_init (rtl_obstack
);
317 fatal ("No input file name.");
319 infile
= fopen (argv
[1], "r");
323 exit (FATAL_EXIT_CODE
);
328 printf ("/* Generated automatically by the program `genconfig'\n\
329 from the machine description file `md'. */\n\n");
331 /* Allow at least 10 operands for the sake of asm constructs. */
332 max_recog_operands
= 9; /* We will add 1 later. */
333 max_dup_operands
= 1;
335 /* Read the machine description. */
339 c
= read_skip_spaces (infile
);
344 desc
= read_rtx (infile
);
345 if (GET_CODE (desc
) == DEFINE_INSN
)
347 if (GET_CODE (desc
) == DEFINE_EXPAND
)
349 if (GET_CODE (desc
) == DEFINE_SPLIT
)
351 if (GET_CODE (desc
) == DEFINE_PEEPHOLE
)
355 printf ("\n#define MAX_RECOG_OPERANDS %d\n", max_recog_operands
+ 1);
357 printf ("\n#define MAX_DUP_OPERANDS %d\n", max_dup_operands
);
359 /* This is conditionally defined, in case the user writes code which emits
360 more splits than we can readily see (and knows s/he does it). */
361 printf ("#ifndef MAX_INSNS_PER_SPLIT\n#define MAX_INSNS_PER_SPLIT %d\n#endif\n",
362 max_insns_per_split
);
364 if (register_constraint_flag
)
365 printf ("#define REGISTER_CONSTRAINTS\n");
368 printf ("#define HAVE_cc0\n");
371 printf ("#define HAVE_conditional_move\n");
373 if (have_lo_sum_flag
)
374 printf ("#define HAVE_lo_sum\n");
377 exit (ferror (stdout
) != 0 ? FATAL_EXIT_CODE
: SUCCESS_EXIT_CODE
);