1 /* Generate from machine description:
2 - some #define configuration flags.
3 Copyright (C) 1987-2018 Free Software Foundation, Inc.
5 This file is part of GCC.
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
9 Software Foundation; either version 3, or (at your option) any later
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
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
28 #include "gensupport.h"
31 /* flags to determine output of machine description dependent #define's. */
32 static int max_recog_operands
; /* Largest operand number seen. */
33 static int max_dup_operands
; /* Largest number of match_dup in any insn. */
34 static int max_clobbers_per_insn
;
35 static int have_cc0_flag
;
36 static int have_cmove_flag
;
37 static int have_cond_exec_flag
;
38 static int have_lo_sum_flag
;
39 static int have_rotate_flag
;
40 static int have_rotatert_flag
;
41 static int have_peephole_flag
;
42 static int have_peephole2_flag
;
44 /* Maximum number of insns seen in a split. */
45 static int max_insns_per_split
= 1;
47 /* Maximum number of input insns for peephole2. */
48 static int max_insns_per_peep2
;
50 static int clobbers_seen_this_insn
;
51 static int dup_operands_seen_this_insn
;
53 static void walk_insn_part (rtx
, int, int);
55 /* RECOG_P will be nonzero if this pattern was seen in a context where it will
56 be used to recognize, rather than just generate an insn.
58 NON_PC_SET_SRC will be nonzero if this pattern was seen in a SET_SRC
59 of a SET whose destination is not (pc). */
62 walk_insn_part (rtx part
, int recog_p
, int non_pc_set_src
)
66 const char *format_ptr
;
71 code
= GET_CODE (part
);
76 clobbers_seen_this_insn
++;
80 if (XINT (part
, 0) > max_recog_operands
)
81 max_recog_operands
= XINT (part
, 0);
86 ++dup_operands_seen_this_insn
;
91 if (XINT (part
, 0) > max_recog_operands
)
92 max_recog_operands
= XINT (part
, 0);
93 /* Now scan the rtl's in the vector inside the MATCH_OPERATOR or
98 if (GET_CODE (XEXP (part
, 0)) == MATCH_OPERAND
99 || GET_CODE (XEXP (part
, 0)) == MATCH_DUP
)
104 ++dup_operands_seen_this_insn
;
105 if (XINT (part
, 0) > max_recog_operands
)
106 max_recog_operands
= XINT (part
, 0);
116 have_lo_sum_flag
= 1;
121 have_rotate_flag
= 1;
126 have_rotatert_flag
= 1;
130 walk_insn_part (SET_DEST (part
), 0, recog_p
);
131 walk_insn_part (SET_SRC (part
), recog_p
,
132 GET_CODE (SET_DEST (part
)) != PC
);
136 /* Only consider this machine as having a conditional move if the
137 two arms of the IF_THEN_ELSE are both MATCH_OPERAND. Otherwise,
138 we have some specific IF_THEN_ELSE construct (like the doz
139 instruction on the RS/6000) that can't be used in the general
140 context we want it for. */
142 if (recog_p
&& non_pc_set_src
143 && GET_CODE (XEXP (part
, 1)) == MATCH_OPERAND
144 && GET_CODE (XEXP (part
, 2)) == MATCH_OPERAND
)
150 have_cond_exec_flag
= 1;
153 case REG
: case CONST_INT
: case SYMBOL_REF
:
161 format_ptr
= GET_RTX_FORMAT (GET_CODE (part
));
163 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (part
)); i
++)
164 switch (*format_ptr
++)
168 walk_insn_part (XEXP (part
, i
), recog_p
, non_pc_set_src
);
171 if (XVEC (part
, i
) != NULL
)
172 for (j
= 0; j
< XVECLEN (part
, i
); j
++)
173 walk_insn_part (XVECEXP (part
, i
, j
), recog_p
, non_pc_set_src
);
179 gen_insn (md_rtx_info
*info
)
183 /* Walk the insn pattern to gather the #define's status. */
184 rtx insn
= info
->def
;
185 clobbers_seen_this_insn
= 0;
186 dup_operands_seen_this_insn
= 0;
187 if (XVEC (insn
, 1) != 0)
188 for (i
= 0; i
< XVECLEN (insn
, 1); i
++)
189 walk_insn_part (XVECEXP (insn
, 1, i
), 1, 0);
191 if (clobbers_seen_this_insn
> max_clobbers_per_insn
)
192 max_clobbers_per_insn
= clobbers_seen_this_insn
;
193 if (dup_operands_seen_this_insn
> max_dup_operands
)
194 max_dup_operands
= dup_operands_seen_this_insn
;
197 /* Similar but scan a define_expand. */
200 gen_expand (md_rtx_info
*info
)
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 rtx insn
= info
->def
;
209 if (XVEC (insn
, 1) != 0)
210 for (i
= 0; i
< XVECLEN (insn
, 1); i
++)
212 /* Compute the maximum SETs and CLOBBERS
213 in any one of the sub-insns;
214 don't sum across all of them. */
215 clobbers_seen_this_insn
= 0;
217 walk_insn_part (XVECEXP (insn
, 1, i
), 0, 0);
219 if (clobbers_seen_this_insn
> max_clobbers_per_insn
)
220 max_clobbers_per_insn
= clobbers_seen_this_insn
;
224 /* Similar but scan a define_split. */
227 gen_split (md_rtx_info
*info
)
231 /* Look through the patterns that are matched
232 to compute the maximum operand number. */
233 rtx split
= info
->def
;
234 for (i
= 0; i
< XVECLEN (split
, 0); i
++)
235 walk_insn_part (XVECEXP (split
, 0, i
), 1, 0);
236 /* Look at the number of insns this insn could split into. */
237 if (XVECLEN (split
, 2) > max_insns_per_split
)
238 max_insns_per_split
= XVECLEN (split
, 2);
242 gen_peephole (md_rtx_info
*info
)
246 /* Look through the patterns that are matched
247 to compute the maximum operand number. */
248 rtx peep
= info
->def
;
249 for (i
= 0; i
< XVECLEN (peep
, 0); i
++)
250 walk_insn_part (XVECEXP (peep
, 0, i
), 1, 0);
254 gen_peephole2 (md_rtx_info
*info
)
258 /* Look through the patterns that are matched
259 to compute the maximum operand number. */
260 rtx peep
= info
->def
;
261 for (i
= XVECLEN (peep
, 0) - 1; i
>= 0; --i
)
262 walk_insn_part (XVECEXP (peep
, 0, i
), 1, 0);
264 /* Look at the number of insns this insn can be matched from. */
265 for (i
= XVECLEN (peep
, 0) - 1, n
= 0; i
>= 0; --i
)
266 if (GET_CODE (XVECEXP (peep
, 0, i
)) != MATCH_DUP
267 && GET_CODE (XVECEXP (peep
, 0, i
)) != MATCH_SCRATCH
)
269 if (n
> max_insns_per_peep2
)
270 max_insns_per_peep2
= n
;
274 main (int argc
, const char **argv
)
276 progname
= "genconfig";
278 if (!init_rtx_reader_args (argc
, argv
))
279 return (FATAL_EXIT_CODE
);
281 puts ("/* Generated automatically by the program `genconfig'");
282 puts (" from the machine description file `md'. */\n");
283 puts ("#ifndef GCC_INSN_CONFIG_H");
284 puts ("#define GCC_INSN_CONFIG_H\n");
286 /* Allow at least 30 operands for the sake of asm constructs. */
287 /* ??? We *really* ought to reorganize things such that there
288 is no fixed upper bound. */
289 max_recog_operands
= 29; /* We will add 1 later. */
290 max_dup_operands
= 1;
292 /* Read the machine description. */
295 while (read_md_rtx (&info
))
296 switch (GET_CODE (info
.def
))
310 case DEFINE_PEEPHOLE2
:
311 have_peephole2_flag
= 1;
312 gen_peephole2 (&info
);
315 case DEFINE_PEEPHOLE
:
316 have_peephole_flag
= 1;
317 gen_peephole (&info
);
324 printf ("#define MAX_RECOG_OPERANDS %d\n", max_recog_operands
+ 1);
325 printf ("#define MAX_DUP_OPERANDS %d\n", max_dup_operands
);
327 /* This is conditionally defined, in case the user writes code which emits
328 more splits than we can readily see (and knows s/he does it). */
329 printf ("#ifndef MAX_INSNS_PER_SPLIT\n");
330 printf ("#define MAX_INSNS_PER_SPLIT %d\n", max_insns_per_split
);
335 printf ("#define HAVE_cc0 1\n");
336 printf ("#define CC0_P(X) ((X) == cc0_rtx)\n");
340 /* We output CC0_P this way to make sure that X is declared
342 printf ("#define HAVE_cc0 0\n");
343 printf ("#define CC0_P(X) ((X) ? 0 : 0)\n");
347 printf ("#define HAVE_conditional_move 1\n");
349 printf ("#define HAVE_conditional_move 0\n");
351 if (have_cond_exec_flag
)
352 printf ("#define HAVE_conditional_execution 1\n");
354 printf ("#define HAVE_conditional_execution 0\n");
356 if (have_lo_sum_flag
)
357 printf ("#define HAVE_lo_sum 1\n");
359 printf ("#define HAVE_lo_sum 0\n");
361 if (have_rotate_flag
)
362 printf ("#define HAVE_rotate 1\n");
364 if (have_rotatert_flag
)
365 printf ("#define HAVE_rotatert 1\n");
367 if (have_peephole_flag
)
368 printf ("#define HAVE_peephole 1\n");
370 printf ("#define HAVE_peephole 0\n");
372 if (have_peephole2_flag
)
374 printf ("#define HAVE_peephole2 1\n");
375 printf ("#define MAX_INSNS_PER_PEEP2 %d\n", max_insns_per_peep2
);
379 printf ("#define HAVE_peephole2 0\n");
380 printf ("#define MAX_INSNS_PER_PEEP2 0\n");
383 puts ("\n#endif /* GCC_INSN_CONFIG_H */");
385 if (ferror (stdout
) || fflush (stdout
) || fclose (stdout
))
386 return FATAL_EXIT_CODE
;
388 return SUCCESS_EXIT_CODE
;