OSDN Git Service

* gensupport.c (collect_insn_data): Record the maximum number
[pf3gnuchains/gcc-fork.git] / gcc / genconfig.c
1 /* Generate from machine description:
2    - some #define configuration flags.
3    Copyright (C) 1987, 1991, 1997, 1998,
4    1999, 2000 Free Software Foundation, Inc.
5
6 This file is part of GNU CC.
7
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING.  If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.  */
22
23
24 #include "hconfig.h"
25 #include "system.h"
26 #include "rtl.h"
27 #include "errors.h"
28 #include "gensupport.h"
29
30
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_peephole_flag;
40 static int have_peephole2_flag;
41
42 /* Maximum number of insns seen in a split.  */
43 static int max_insns_per_split = 1;
44
45 static int clobbers_seen_this_insn;
46 static int dup_operands_seen_this_insn;
47
48 static void walk_insn_part PARAMS ((rtx, int, int));
49 static void gen_insn PARAMS ((rtx));
50 static void gen_expand PARAMS ((rtx));
51 static void gen_split PARAMS ((rtx));
52 static void gen_peephole PARAMS ((rtx));
53
54 /* RECOG_P will be non-zero if this pattern was seen in a context where it will
55    be used to recognize, rather than just generate an insn. 
56
57    NON_PC_SET_SRC will be non-zero if this pattern was seen in a SET_SRC
58    of a SET whose destination is not (pc).  */
59
60 static void
61 walk_insn_part (part, recog_p, non_pc_set_src)
62      rtx part;
63      int recog_p;
64      int non_pc_set_src;
65 {
66   register int i, j;
67   register RTX_CODE code;
68   register const char *format_ptr;
69
70   if (part == 0)
71     return;
72
73   code = GET_CODE (part);
74   switch (code)
75     {
76     case CLOBBER:
77       clobbers_seen_this_insn++;
78       break;
79
80     case MATCH_OPERAND:
81       if (XINT (part, 0) > max_recog_operands)
82         max_recog_operands = XINT (part, 0);
83       return;
84
85     case MATCH_OP_DUP:
86     case MATCH_PAR_DUP:
87       ++dup_operands_seen_this_insn;
88     case MATCH_SCRATCH:
89     case MATCH_PARALLEL:
90     case MATCH_OPERATOR:
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
94          MATCH_PARALLEL.  */
95       break;
96
97     case LABEL_REF:
98       if (GET_CODE (XEXP (part, 0)) == MATCH_OPERAND)
99         break;
100       return;
101
102     case MATCH_DUP:
103       ++dup_operands_seen_this_insn;
104       if (XINT (part, 0) > max_recog_operands)
105         max_recog_operands = XINT (part, 0);
106       return;
107
108     case CC0:
109       if (recog_p)
110         have_cc0_flag = 1;
111       return;
112
113     case LO_SUM:
114       if (recog_p)
115         have_lo_sum_flag = 1;
116       return;
117
118     case SET:
119       walk_insn_part (SET_DEST (part), 0, recog_p);
120       walk_insn_part (SET_SRC (part), recog_p,
121                       GET_CODE (SET_DEST (part)) != PC);
122       return;
123
124     case IF_THEN_ELSE:
125       /* Only consider this machine as having a conditional move if the
126          two arms of the IF_THEN_ELSE are both MATCH_OPERAND.  Otherwise,
127          we have some specific IF_THEN_ELSE construct (like the doz
128          instruction on the RS/6000) that can't be used in the general
129          context we want it for.  */
130
131       if (recog_p && non_pc_set_src
132           && GET_CODE (XEXP (part, 1)) == MATCH_OPERAND
133           && GET_CODE (XEXP (part, 2)) == MATCH_OPERAND)
134         have_cmove_flag = 1;
135       break;
136
137     case COND_EXEC:
138       if (recog_p)
139         have_cond_exec_flag = 1;
140       break;
141
142     case REG: case CONST_INT: case SYMBOL_REF:
143     case PC:
144       return;
145
146     default:
147       break;
148     }
149
150   format_ptr = GET_RTX_FORMAT (GET_CODE (part));
151
152   for (i = 0; i < GET_RTX_LENGTH (GET_CODE (part)); i++)
153     switch (*format_ptr++)
154       {
155       case 'e':
156       case 'u':
157         walk_insn_part (XEXP (part, i), recog_p, non_pc_set_src);
158         break;
159       case 'E':
160         if (XVEC (part, i) != NULL)
161           for (j = 0; j < XVECLEN (part, i); j++)
162             walk_insn_part (XVECEXP (part, i, j), recog_p, non_pc_set_src);
163         break;
164       }
165 }
166
167 static void
168 gen_insn (insn)
169      rtx insn;
170 {
171   int i;
172
173   /* Walk the insn pattern to gather the #define's status.  */
174   clobbers_seen_this_insn = 0;
175   dup_operands_seen_this_insn = 0;
176   if (XVEC (insn, 1) != 0)
177     for (i = 0; i < XVECLEN (insn, 1); i++)
178       walk_insn_part (XVECEXP (insn, 1, i), 1, 0);
179
180   if (clobbers_seen_this_insn > max_clobbers_per_insn)
181     max_clobbers_per_insn = clobbers_seen_this_insn;
182   if (dup_operands_seen_this_insn > max_dup_operands)
183     max_dup_operands = dup_operands_seen_this_insn;
184 }
185
186 /* Similar but scan a define_expand.  */
187
188 static void
189 gen_expand (insn)
190      rtx insn;
191 {
192   int i;
193
194   /* Walk the insn pattern to gather the #define's status.  */
195
196   /* Note that we don't bother recording the number of MATCH_DUPs
197      that occur in a gen_expand, because only reload cares about that.  */
198   if (XVEC (insn, 1) != 0)
199     for (i = 0; i < XVECLEN (insn, 1); i++)
200       {
201         /* Compute the maximum SETs and CLOBBERS
202            in any one of the sub-insns;
203            don't sum across all of them.  */
204         clobbers_seen_this_insn = 0;
205
206         walk_insn_part (XVECEXP (insn, 1, i), 0, 0);
207
208         if (clobbers_seen_this_insn > max_clobbers_per_insn)
209           max_clobbers_per_insn = clobbers_seen_this_insn;
210       }
211 }
212
213 /* Similar but scan a define_split.  */
214
215 static void
216 gen_split (split)
217      rtx split;
218 {
219   int i;
220
221   /* Look through the patterns that are matched
222      to compute the maximum operand number.  */
223   for (i = 0; i < XVECLEN (split, 0); i++)
224     walk_insn_part (XVECEXP (split, 0, i), 1, 0);
225   /* Look at the number of insns this insn could split into.  */
226   if (XVECLEN (split, 2) > max_insns_per_split)
227     max_insns_per_split = XVECLEN (split, 2);
228 }
229
230 static void
231 gen_peephole (peep)
232      rtx peep;
233 {
234   int i;
235
236   /* Look through the patterns that are matched
237      to compute the maximum operand number.  */
238   for (i = 0; i < XVECLEN (peep, 0); i++)
239     walk_insn_part (XVECEXP (peep, 0, i), 1, 0);
240 }
241
242 extern int main PARAMS ((int, char **));
243
244 int
245 main (argc, argv)
246      int argc;
247      char **argv;
248 {
249   rtx desc;
250
251   progname = "genconfig";
252
253   if (argc <= 1)
254     fatal ("No input file name.");
255
256   if (init_md_reader (argv[1]) != SUCCESS_EXIT_CODE)
257     return (FATAL_EXIT_CODE);
258
259   printf ("/* Generated automatically by the program `genconfig'\n\
260 from the machine description file `md'.  */\n\n");
261
262   /* Allow at least 10 operands for the sake of asm constructs.  */
263   max_recog_operands = 9;  /* We will add 1 later.  */
264   max_dup_operands = 1;
265
266   /* Read the machine description.  */
267
268   while (1)
269     {
270       int line_no, insn_code_number = 0;
271
272       desc = read_md_rtx (&line_no, &insn_code_number);
273       if (desc == NULL)
274         break;
275         
276       switch (GET_CODE (desc)) 
277         {
278           case DEFINE_INSN:
279             gen_insn (desc);
280             break;
281           
282           case DEFINE_EXPAND:
283             gen_expand (desc);
284             break;
285
286           case DEFINE_SPLIT:
287             gen_split (desc);
288             break;
289
290           case DEFINE_PEEPHOLE2:
291             have_peephole2_flag = 1;
292             gen_split (desc);
293             break;
294
295           case DEFINE_PEEPHOLE:
296             have_peephole_flag = 1;
297             gen_peephole (desc);
298             break;
299
300           default:
301             break;
302         }
303     }
304
305   printf ("\n#define MAX_RECOG_OPERANDS %d\n", max_recog_operands + 1);
306
307   printf ("\n#define MAX_DUP_OPERANDS %d\n", max_dup_operands);
308
309   /* This is conditionally defined, in case the user writes code which emits
310      more splits than we can readily see (and knows s/he does it).  */
311   printf ("#ifndef MAX_INSNS_PER_SPLIT\n");
312   printf ("#define MAX_INSNS_PER_SPLIT %d\n", max_insns_per_split);
313   printf ("#endif\n");
314
315   if (have_cc0_flag)
316     printf ("#define HAVE_cc0 1\n");
317
318   if (have_cmove_flag)
319     printf ("#define HAVE_conditional_move 1\n");
320
321   if (have_cond_exec_flag)
322     printf ("#define HAVE_conditional_execution 1\n");
323
324   if (have_lo_sum_flag)
325     printf ("#define HAVE_lo_sum 1\n");
326
327   if (have_peephole_flag)
328     printf ("#define HAVE_peephole 1\n");
329
330   if (have_peephole2_flag)
331     printf ("#define HAVE_peephole2 1\n");
332
333   fflush (stdout);
334   return (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
335 }
336
337 /* Define this so we can link with print-rtl.o to get debug_rtx function.  */
338 const char *
339 get_insn_name (code)
340      int code ATTRIBUTE_UNUSED;
341 {
342   return NULL;
343 }