xref: /dragonfly/contrib/gcc-8.0/gcc/genconfig.c (revision 38fd1498)
1*38fd1498Szrj /* Generate from machine description:
2*38fd1498Szrj    - some #define configuration flags.
3*38fd1498Szrj    Copyright (C) 1987-2018 Free Software Foundation, Inc.
4*38fd1498Szrj 
5*38fd1498Szrj This file is part of GCC.
6*38fd1498Szrj 
7*38fd1498Szrj GCC is free software; you can redistribute it and/or modify it under
8*38fd1498Szrj the terms of the GNU General Public License as published by the Free
9*38fd1498Szrj Software Foundation; either version 3, or (at your option) any later
10*38fd1498Szrj version.
11*38fd1498Szrj 
12*38fd1498Szrj GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13*38fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or
14*38fd1498Szrj FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15*38fd1498Szrj for more details.
16*38fd1498Szrj 
17*38fd1498Szrj You should have received a copy of the GNU General Public License
18*38fd1498Szrj along with GCC; see the file COPYING3.  If not see
19*38fd1498Szrj <http://www.gnu.org/licenses/>.  */
20*38fd1498Szrj 
21*38fd1498Szrj 
22*38fd1498Szrj #include "bconfig.h"
23*38fd1498Szrj #include "system.h"
24*38fd1498Szrj #include "coretypes.h"
25*38fd1498Szrj #include "tm.h"
26*38fd1498Szrj #include "rtl.h"
27*38fd1498Szrj #include "errors.h"
28*38fd1498Szrj #include "gensupport.h"
29*38fd1498Szrj 
30*38fd1498Szrj 
31*38fd1498Szrj /* flags to determine output of machine description dependent #define's.  */
32*38fd1498Szrj static int max_recog_operands;  /* Largest operand number seen.  */
33*38fd1498Szrj static int max_dup_operands;    /* Largest number of match_dup in any insn.  */
34*38fd1498Szrj static int max_clobbers_per_insn;
35*38fd1498Szrj static int have_cc0_flag;
36*38fd1498Szrj static int have_cmove_flag;
37*38fd1498Szrj static int have_cond_exec_flag;
38*38fd1498Szrj static int have_lo_sum_flag;
39*38fd1498Szrj static int have_rotate_flag;
40*38fd1498Szrj static int have_rotatert_flag;
41*38fd1498Szrj static int have_peephole_flag;
42*38fd1498Szrj static int have_peephole2_flag;
43*38fd1498Szrj 
44*38fd1498Szrj /* Maximum number of insns seen in a split.  */
45*38fd1498Szrj static int max_insns_per_split = 1;
46*38fd1498Szrj 
47*38fd1498Szrj /* Maximum number of input insns for peephole2.  */
48*38fd1498Szrj static int max_insns_per_peep2;
49*38fd1498Szrj 
50*38fd1498Szrj static int clobbers_seen_this_insn;
51*38fd1498Szrj static int dup_operands_seen_this_insn;
52*38fd1498Szrj 
53*38fd1498Szrj static void walk_insn_part (rtx, int, int);
54*38fd1498Szrj 
55*38fd1498Szrj /* RECOG_P will be nonzero if this pattern was seen in a context where it will
56*38fd1498Szrj    be used to recognize, rather than just generate an insn.
57*38fd1498Szrj 
58*38fd1498Szrj    NON_PC_SET_SRC will be nonzero if this pattern was seen in a SET_SRC
59*38fd1498Szrj    of a SET whose destination is not (pc).  */
60*38fd1498Szrj 
61*38fd1498Szrj static void
walk_insn_part(rtx part,int recog_p,int non_pc_set_src)62*38fd1498Szrj walk_insn_part (rtx part, int recog_p, int non_pc_set_src)
63*38fd1498Szrj {
64*38fd1498Szrj   int i, j;
65*38fd1498Szrj   RTX_CODE code;
66*38fd1498Szrj   const char *format_ptr;
67*38fd1498Szrj 
68*38fd1498Szrj   if (part == 0)
69*38fd1498Szrj     return;
70*38fd1498Szrj 
71*38fd1498Szrj   code = GET_CODE (part);
72*38fd1498Szrj   switch (code)
73*38fd1498Szrj     {
74*38fd1498Szrj     case CLOBBER:
75*38fd1498Szrj       clobbers_seen_this_insn++;
76*38fd1498Szrj       break;
77*38fd1498Szrj 
78*38fd1498Szrj     case MATCH_OPERAND:
79*38fd1498Szrj       if (XINT (part, 0) > max_recog_operands)
80*38fd1498Szrj 	max_recog_operands = XINT (part, 0);
81*38fd1498Szrj       return;
82*38fd1498Szrj 
83*38fd1498Szrj     case MATCH_OP_DUP:
84*38fd1498Szrj     case MATCH_PAR_DUP:
85*38fd1498Szrj       ++dup_operands_seen_this_insn;
86*38fd1498Szrj       /* FALLTHRU */
87*38fd1498Szrj     case MATCH_SCRATCH:
88*38fd1498Szrj     case MATCH_PARALLEL:
89*38fd1498Szrj     case MATCH_OPERATOR:
90*38fd1498Szrj       if (XINT (part, 0) > max_recog_operands)
91*38fd1498Szrj 	max_recog_operands = XINT (part, 0);
92*38fd1498Szrj       /* Now scan the rtl's in the vector inside the MATCH_OPERATOR or
93*38fd1498Szrj 	 MATCH_PARALLEL.  */
94*38fd1498Szrj       break;
95*38fd1498Szrj 
96*38fd1498Szrj     case LABEL_REF:
97*38fd1498Szrj       if (GET_CODE (XEXP (part, 0)) == MATCH_OPERAND
98*38fd1498Szrj 	  || GET_CODE (XEXP (part, 0)) == MATCH_DUP)
99*38fd1498Szrj 	break;
100*38fd1498Szrj       return;
101*38fd1498Szrj 
102*38fd1498Szrj     case MATCH_DUP:
103*38fd1498Szrj       ++dup_operands_seen_this_insn;
104*38fd1498Szrj       if (XINT (part, 0) > max_recog_operands)
105*38fd1498Szrj 	max_recog_operands = XINT (part, 0);
106*38fd1498Szrj       return;
107*38fd1498Szrj 
108*38fd1498Szrj     case CC0:
109*38fd1498Szrj       if (recog_p)
110*38fd1498Szrj 	have_cc0_flag = 1;
111*38fd1498Szrj       return;
112*38fd1498Szrj 
113*38fd1498Szrj     case LO_SUM:
114*38fd1498Szrj       if (recog_p)
115*38fd1498Szrj 	have_lo_sum_flag = 1;
116*38fd1498Szrj       return;
117*38fd1498Szrj 
118*38fd1498Szrj     case ROTATE:
119*38fd1498Szrj       if (recog_p)
120*38fd1498Szrj 	have_rotate_flag = 1;
121*38fd1498Szrj       return;
122*38fd1498Szrj 
123*38fd1498Szrj     case ROTATERT:
124*38fd1498Szrj       if (recog_p)
125*38fd1498Szrj 	have_rotatert_flag = 1;
126*38fd1498Szrj       return;
127*38fd1498Szrj 
128*38fd1498Szrj     case SET:
129*38fd1498Szrj       walk_insn_part (SET_DEST (part), 0, recog_p);
130*38fd1498Szrj       walk_insn_part (SET_SRC (part), recog_p,
131*38fd1498Szrj 		      GET_CODE (SET_DEST (part)) != PC);
132*38fd1498Szrj       return;
133*38fd1498Szrj 
134*38fd1498Szrj     case IF_THEN_ELSE:
135*38fd1498Szrj       /* Only consider this machine as having a conditional move if the
136*38fd1498Szrj 	 two arms of the IF_THEN_ELSE are both MATCH_OPERAND.  Otherwise,
137*38fd1498Szrj 	 we have some specific IF_THEN_ELSE construct (like the doz
138*38fd1498Szrj 	 instruction on the RS/6000) that can't be used in the general
139*38fd1498Szrj 	 context we want it for.  */
140*38fd1498Szrj 
141*38fd1498Szrj       if (recog_p && non_pc_set_src
142*38fd1498Szrj 	  && GET_CODE (XEXP (part, 1)) == MATCH_OPERAND
143*38fd1498Szrj 	  && GET_CODE (XEXP (part, 2)) == MATCH_OPERAND)
144*38fd1498Szrj 	have_cmove_flag = 1;
145*38fd1498Szrj       break;
146*38fd1498Szrj 
147*38fd1498Szrj     case COND_EXEC:
148*38fd1498Szrj       if (recog_p)
149*38fd1498Szrj 	have_cond_exec_flag = 1;
150*38fd1498Szrj       break;
151*38fd1498Szrj 
152*38fd1498Szrj     case REG: case CONST_INT: case SYMBOL_REF:
153*38fd1498Szrj     case PC:
154*38fd1498Szrj       return;
155*38fd1498Szrj 
156*38fd1498Szrj     default:
157*38fd1498Szrj       break;
158*38fd1498Szrj     }
159*38fd1498Szrj 
160*38fd1498Szrj   format_ptr = GET_RTX_FORMAT (GET_CODE (part));
161*38fd1498Szrj 
162*38fd1498Szrj   for (i = 0; i < GET_RTX_LENGTH (GET_CODE (part)); i++)
163*38fd1498Szrj     switch (*format_ptr++)
164*38fd1498Szrj       {
165*38fd1498Szrj       case 'e':
166*38fd1498Szrj       case 'u':
167*38fd1498Szrj 	walk_insn_part (XEXP (part, i), recog_p, non_pc_set_src);
168*38fd1498Szrj 	break;
169*38fd1498Szrj       case 'E':
170*38fd1498Szrj 	if (XVEC (part, i) != NULL)
171*38fd1498Szrj 	  for (j = 0; j < XVECLEN (part, i); j++)
172*38fd1498Szrj 	    walk_insn_part (XVECEXP (part, i, j), recog_p, non_pc_set_src);
173*38fd1498Szrj 	break;
174*38fd1498Szrj       }
175*38fd1498Szrj }
176*38fd1498Szrj 
177*38fd1498Szrj static void
gen_insn(md_rtx_info * info)178*38fd1498Szrj gen_insn (md_rtx_info *info)
179*38fd1498Szrj {
180*38fd1498Szrj   int i;
181*38fd1498Szrj 
182*38fd1498Szrj   /* Walk the insn pattern to gather the #define's status.  */
183*38fd1498Szrj   rtx insn = info->def;
184*38fd1498Szrj   clobbers_seen_this_insn = 0;
185*38fd1498Szrj   dup_operands_seen_this_insn = 0;
186*38fd1498Szrj   if (XVEC (insn, 1) != 0)
187*38fd1498Szrj     for (i = 0; i < XVECLEN (insn, 1); i++)
188*38fd1498Szrj       walk_insn_part (XVECEXP (insn, 1, i), 1, 0);
189*38fd1498Szrj 
190*38fd1498Szrj   if (clobbers_seen_this_insn > max_clobbers_per_insn)
191*38fd1498Szrj     max_clobbers_per_insn = clobbers_seen_this_insn;
192*38fd1498Szrj   if (dup_operands_seen_this_insn > max_dup_operands)
193*38fd1498Szrj     max_dup_operands = dup_operands_seen_this_insn;
194*38fd1498Szrj }
195*38fd1498Szrj 
196*38fd1498Szrj /* Similar but scan a define_expand.  */
197*38fd1498Szrj 
198*38fd1498Szrj static void
gen_expand(md_rtx_info * info)199*38fd1498Szrj gen_expand (md_rtx_info *info)
200*38fd1498Szrj {
201*38fd1498Szrj   int i;
202*38fd1498Szrj 
203*38fd1498Szrj   /* Walk the insn pattern to gather the #define's status.  */
204*38fd1498Szrj 
205*38fd1498Szrj   /* Note that we don't bother recording the number of MATCH_DUPs
206*38fd1498Szrj      that occur in a gen_expand, because only reload cares about that.  */
207*38fd1498Szrj   rtx insn = info->def;
208*38fd1498Szrj   if (XVEC (insn, 1) != 0)
209*38fd1498Szrj     for (i = 0; i < XVECLEN (insn, 1); i++)
210*38fd1498Szrj       {
211*38fd1498Szrj 	/* Compute the maximum SETs and CLOBBERS
212*38fd1498Szrj 	   in any one of the sub-insns;
213*38fd1498Szrj 	   don't sum across all of them.  */
214*38fd1498Szrj 	clobbers_seen_this_insn = 0;
215*38fd1498Szrj 
216*38fd1498Szrj 	walk_insn_part (XVECEXP (insn, 1, i), 0, 0);
217*38fd1498Szrj 
218*38fd1498Szrj 	if (clobbers_seen_this_insn > max_clobbers_per_insn)
219*38fd1498Szrj 	  max_clobbers_per_insn = clobbers_seen_this_insn;
220*38fd1498Szrj       }
221*38fd1498Szrj }
222*38fd1498Szrj 
223*38fd1498Szrj /* Similar but scan a define_split.  */
224*38fd1498Szrj 
225*38fd1498Szrj static void
gen_split(md_rtx_info * info)226*38fd1498Szrj gen_split (md_rtx_info *info)
227*38fd1498Szrj {
228*38fd1498Szrj   int i;
229*38fd1498Szrj 
230*38fd1498Szrj   /* Look through the patterns that are matched
231*38fd1498Szrj      to compute the maximum operand number.  */
232*38fd1498Szrj   rtx split = info->def;
233*38fd1498Szrj   for (i = 0; i < XVECLEN (split, 0); i++)
234*38fd1498Szrj     walk_insn_part (XVECEXP (split, 0, i), 1, 0);
235*38fd1498Szrj   /* Look at the number of insns this insn could split into.  */
236*38fd1498Szrj   if (XVECLEN (split, 2) > max_insns_per_split)
237*38fd1498Szrj     max_insns_per_split = XVECLEN (split, 2);
238*38fd1498Szrj }
239*38fd1498Szrj 
240*38fd1498Szrj static void
gen_peephole(md_rtx_info * info)241*38fd1498Szrj gen_peephole (md_rtx_info *info)
242*38fd1498Szrj {
243*38fd1498Szrj   int i;
244*38fd1498Szrj 
245*38fd1498Szrj   /* Look through the patterns that are matched
246*38fd1498Szrj      to compute the maximum operand number.  */
247*38fd1498Szrj   rtx peep = info->def;
248*38fd1498Szrj   for (i = 0; i < XVECLEN (peep, 0); i++)
249*38fd1498Szrj     walk_insn_part (XVECEXP (peep, 0, i), 1, 0);
250*38fd1498Szrj }
251*38fd1498Szrj 
252*38fd1498Szrj static void
gen_peephole2(md_rtx_info * info)253*38fd1498Szrj gen_peephole2 (md_rtx_info *info)
254*38fd1498Szrj {
255*38fd1498Szrj   int i, n;
256*38fd1498Szrj 
257*38fd1498Szrj   /* Look through the patterns that are matched
258*38fd1498Szrj      to compute the maximum operand number.  */
259*38fd1498Szrj   rtx peep = info->def;
260*38fd1498Szrj   for (i = XVECLEN (peep, 0) - 1; i >= 0; --i)
261*38fd1498Szrj     walk_insn_part (XVECEXP (peep, 0, i), 1, 0);
262*38fd1498Szrj 
263*38fd1498Szrj   /* Look at the number of insns this insn can be matched from.  */
264*38fd1498Szrj   for (i = XVECLEN (peep, 0) - 1, n = 0; i >= 0; --i)
265*38fd1498Szrj     if (GET_CODE (XVECEXP (peep, 0, i)) != MATCH_DUP
266*38fd1498Szrj 	&& GET_CODE (XVECEXP (peep, 0, i)) != MATCH_SCRATCH)
267*38fd1498Szrj       n++;
268*38fd1498Szrj   if (n > max_insns_per_peep2)
269*38fd1498Szrj     max_insns_per_peep2 = n;
270*38fd1498Szrj }
271*38fd1498Szrj 
272*38fd1498Szrj int
main(int argc,const char ** argv)273*38fd1498Szrj main (int argc, const char **argv)
274*38fd1498Szrj {
275*38fd1498Szrj   progname = "genconfig";
276*38fd1498Szrj 
277*38fd1498Szrj   if (!init_rtx_reader_args (argc, argv))
278*38fd1498Szrj     return (FATAL_EXIT_CODE);
279*38fd1498Szrj 
280*38fd1498Szrj   puts ("/* Generated automatically by the program `genconfig'");
281*38fd1498Szrj   puts ("   from the machine description file `md'.  */\n");
282*38fd1498Szrj   puts ("#ifndef GCC_INSN_CONFIG_H");
283*38fd1498Szrj   puts ("#define GCC_INSN_CONFIG_H\n");
284*38fd1498Szrj 
285*38fd1498Szrj   /* Allow at least 30 operands for the sake of asm constructs.  */
286*38fd1498Szrj   /* ??? We *really* ought to reorganize things such that there
287*38fd1498Szrj      is no fixed upper bound.  */
288*38fd1498Szrj   max_recog_operands = 29;  /* We will add 1 later.  */
289*38fd1498Szrj   max_dup_operands = 1;
290*38fd1498Szrj 
291*38fd1498Szrj   /* Read the machine description.  */
292*38fd1498Szrj 
293*38fd1498Szrj   md_rtx_info info;
294*38fd1498Szrj   while (read_md_rtx (&info))
295*38fd1498Szrj     switch (GET_CODE (info.def))
296*38fd1498Szrj       {
297*38fd1498Szrj       case DEFINE_INSN:
298*38fd1498Szrj 	gen_insn (&info);
299*38fd1498Szrj 	break;
300*38fd1498Szrj 
301*38fd1498Szrj       case DEFINE_EXPAND:
302*38fd1498Szrj 	gen_expand (&info);
303*38fd1498Szrj 	break;
304*38fd1498Szrj 
305*38fd1498Szrj       case DEFINE_SPLIT:
306*38fd1498Szrj 	gen_split (&info);
307*38fd1498Szrj 	break;
308*38fd1498Szrj 
309*38fd1498Szrj       case DEFINE_PEEPHOLE2:
310*38fd1498Szrj 	have_peephole2_flag = 1;
311*38fd1498Szrj 	gen_peephole2 (&info);
312*38fd1498Szrj 	break;
313*38fd1498Szrj 
314*38fd1498Szrj       case DEFINE_PEEPHOLE:
315*38fd1498Szrj 	have_peephole_flag = 1;
316*38fd1498Szrj 	gen_peephole (&info);
317*38fd1498Szrj 	break;
318*38fd1498Szrj 
319*38fd1498Szrj       default:
320*38fd1498Szrj 	break;
321*38fd1498Szrj       }
322*38fd1498Szrj 
323*38fd1498Szrj   printf ("#define MAX_RECOG_OPERANDS %d\n", max_recog_operands + 1);
324*38fd1498Szrj   printf ("#define MAX_DUP_OPERANDS %d\n", max_dup_operands);
325*38fd1498Szrj 
326*38fd1498Szrj   /* This is conditionally defined, in case the user writes code which emits
327*38fd1498Szrj      more splits than we can readily see (and knows s/he does it).  */
328*38fd1498Szrj   printf ("#ifndef MAX_INSNS_PER_SPLIT\n");
329*38fd1498Szrj   printf ("#define MAX_INSNS_PER_SPLIT %d\n", max_insns_per_split);
330*38fd1498Szrj   printf ("#endif\n");
331*38fd1498Szrj 
332*38fd1498Szrj   if (have_cc0_flag)
333*38fd1498Szrj     {
334*38fd1498Szrj       printf ("#define HAVE_cc0 1\n");
335*38fd1498Szrj       printf ("#define CC0_P(X) ((X) == cc0_rtx)\n");
336*38fd1498Szrj     }
337*38fd1498Szrj   else
338*38fd1498Szrj     {
339*38fd1498Szrj       /* We output CC0_P this way to make sure that X is declared
340*38fd1498Szrj 	 somewhere.  */
341*38fd1498Szrj       printf ("#define HAVE_cc0 0\n");
342*38fd1498Szrj       printf ("#define CC0_P(X) ((X) ? 0 : 0)\n");
343*38fd1498Szrj     }
344*38fd1498Szrj 
345*38fd1498Szrj   if (have_cmove_flag)
346*38fd1498Szrj     printf ("#define HAVE_conditional_move 1\n");
347*38fd1498Szrj   else
348*38fd1498Szrj     printf ("#define HAVE_conditional_move 0\n");
349*38fd1498Szrj 
350*38fd1498Szrj   if (have_cond_exec_flag)
351*38fd1498Szrj     printf ("#define HAVE_conditional_execution 1\n");
352*38fd1498Szrj   else
353*38fd1498Szrj     printf ("#define HAVE_conditional_execution 0\n");
354*38fd1498Szrj 
355*38fd1498Szrj   if (have_lo_sum_flag)
356*38fd1498Szrj     printf ("#define HAVE_lo_sum 1\n");
357*38fd1498Szrj   else
358*38fd1498Szrj     printf ("#define HAVE_lo_sum 0\n");
359*38fd1498Szrj 
360*38fd1498Szrj   if (have_rotate_flag)
361*38fd1498Szrj     printf ("#define HAVE_rotate 1\n");
362*38fd1498Szrj 
363*38fd1498Szrj   if (have_rotatert_flag)
364*38fd1498Szrj     printf ("#define HAVE_rotatert 1\n");
365*38fd1498Szrj 
366*38fd1498Szrj   if (have_peephole_flag)
367*38fd1498Szrj     printf ("#define HAVE_peephole 1\n");
368*38fd1498Szrj   else
369*38fd1498Szrj     printf ("#define HAVE_peephole 0\n");
370*38fd1498Szrj 
371*38fd1498Szrj   if (have_peephole2_flag)
372*38fd1498Szrj     {
373*38fd1498Szrj       printf ("#define HAVE_peephole2 1\n");
374*38fd1498Szrj       printf ("#define MAX_INSNS_PER_PEEP2 %d\n", max_insns_per_peep2);
375*38fd1498Szrj     }
376*38fd1498Szrj   else
377*38fd1498Szrj     {
378*38fd1498Szrj       printf ("#define HAVE_peephole2 0\n");
379*38fd1498Szrj       printf ("#define MAX_INSNS_PER_PEEP2 0\n");
380*38fd1498Szrj     }
381*38fd1498Szrj 
382*38fd1498Szrj   puts ("\n#endif /* GCC_INSN_CONFIG_H */");
383*38fd1498Szrj 
384*38fd1498Szrj   if (ferror (stdout) || fflush (stdout) || fclose (stdout))
385*38fd1498Szrj     return FATAL_EXIT_CODE;
386*38fd1498Szrj 
387*38fd1498Szrj   return SUCCESS_EXIT_CODE;
388*38fd1498Szrj }
389