OSDN Git Service

a18f896a5b995cb55f90de6a559553d6b1a47c71
[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 \f
242 PTR
243 xmalloc (size)
244   size_t size;
245 {
246   register PTR val = (PTR) malloc (size);
247
248   if (val == 0)
249     fatal ("virtual memory exhausted");
250
251   return val;
252 }
253
254 PTR
255 xrealloc (old, size)
256   PTR old;
257   size_t size;
258 {
259   register PTR ptr;
260   if (old)
261     ptr = (PTR) realloc (old, size);
262   else
263     ptr = (PTR) malloc (size);
264   if (!ptr)
265     fatal ("virtual memory exhausted");
266   return ptr;
267 }
268
269 extern int main PARAMS ((int, char **));
270
271 int
272 main (argc, argv)
273      int argc;
274      char **argv;
275 {
276   rtx desc;
277
278   progname = "genconfig";
279
280   if (argc <= 1)
281     fatal ("No input file name.");
282
283   if (init_md_reader (argv[1]) != SUCCESS_EXIT_CODE)
284     return (FATAL_EXIT_CODE);
285
286   printf ("/* Generated automatically by the program `genconfig'\n\
287 from the machine description file `md'.  */\n\n");
288
289   /* Allow at least 10 operands for the sake of asm constructs.  */
290   max_recog_operands = 9;  /* We will add 1 later.  */
291   max_dup_operands = 1;
292
293   /* Read the machine description.  */
294
295   while (1)
296     {
297       int line_no, insn_code_number = 0;
298
299       desc = read_md_rtx (&line_no, &insn_code_number);
300       if (desc == NULL)
301         break;
302         
303       switch (GET_CODE (desc)) 
304         {
305           case DEFINE_INSN:
306             gen_insn (desc);
307             break;
308           
309           case DEFINE_EXPAND:
310             gen_expand (desc);
311             break;
312
313           case DEFINE_SPLIT:
314             gen_split (desc);
315             break;
316
317           case DEFINE_PEEPHOLE2:
318             have_peephole2_flag = 1;
319             gen_split (desc);
320             break;
321
322           case DEFINE_PEEPHOLE:
323             have_peephole_flag = 1;
324             gen_peephole (desc);
325             break;
326
327           default:
328             break;
329         }
330     }
331
332   printf ("\n#define MAX_RECOG_OPERANDS %d\n", max_recog_operands + 1);
333
334   printf ("\n#define MAX_DUP_OPERANDS %d\n", max_dup_operands);
335
336   /* This is conditionally defined, in case the user writes code which emits
337      more splits than we can readily see (and knows s/he does it).  */
338   printf ("#ifndef MAX_INSNS_PER_SPLIT\n");
339   printf ("#define MAX_INSNS_PER_SPLIT %d\n", max_insns_per_split);
340   printf ("#endif\n");
341
342   if (have_cc0_flag)
343     printf ("#define HAVE_cc0 1\n");
344
345   if (have_cmove_flag)
346     printf ("#define HAVE_conditional_move 1\n");
347
348   if (have_cond_exec_flag)
349     printf ("#define HAVE_conditional_execution 1\n");
350
351   if (have_lo_sum_flag)
352     printf ("#define HAVE_lo_sum 1\n");
353
354   if (have_peephole_flag)
355     printf ("#define HAVE_peephole 1\n");
356
357   if (have_peephole2_flag)
358     printf ("#define HAVE_peephole2 1\n");
359
360   fflush (stdout);
361   return (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
362 }
363
364 /* Define this so we can link with print-rtl.o to get debug_rtx function.  */
365 const char *
366 get_insn_name (code)
367      int code ATTRIBUTE_UNUSED;
368 {
369   return NULL;
370 }