xref: /openbsd-src/gnu/gcc/gcc/genemit.c (revision 404b540a9034ac75a6199ad1a32d1bbc7a0d4210)
1*404b540aSrobert /* Generate code from machine description to emit insns as rtl.
2*404b540aSrobert    Copyright (C) 1987, 1988, 1991, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
3*404b540aSrobert    2003, 2004, 2005 Free Software Foundation, Inc.
4*404b540aSrobert 
5*404b540aSrobert This file is part of GCC.
6*404b540aSrobert 
7*404b540aSrobert GCC is free software; you can redistribute it and/or modify it under
8*404b540aSrobert the terms of the GNU General Public License as published by the Free
9*404b540aSrobert Software Foundation; either version 2, or (at your option) any later
10*404b540aSrobert version.
11*404b540aSrobert 
12*404b540aSrobert GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13*404b540aSrobert WARRANTY; without even the implied warranty of MERCHANTABILITY or
14*404b540aSrobert FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15*404b540aSrobert for more details.
16*404b540aSrobert 
17*404b540aSrobert You should have received a copy of the GNU General Public License
18*404b540aSrobert along with GCC; see the file COPYING.  If not, write to the Free
19*404b540aSrobert Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
20*404b540aSrobert 02110-1301, USA.  */
21*404b540aSrobert 
22*404b540aSrobert 
23*404b540aSrobert #include "bconfig.h"
24*404b540aSrobert #include "system.h"
25*404b540aSrobert #include "coretypes.h"
26*404b540aSrobert #include "tm.h"
27*404b540aSrobert #include "rtl.h"
28*404b540aSrobert #include "errors.h"
29*404b540aSrobert #include "gensupport.h"
30*404b540aSrobert 
31*404b540aSrobert 
32*404b540aSrobert static int max_opno;
33*404b540aSrobert static int max_dup_opno;
34*404b540aSrobert static int max_scratch_opno;
35*404b540aSrobert static int insn_code_number;
36*404b540aSrobert static int insn_index_number;
37*404b540aSrobert 
38*404b540aSrobert /* Data structure for recording the patterns of insns that have CLOBBERs.
39*404b540aSrobert    We use this to output a function that adds these CLOBBERs to a
40*404b540aSrobert    previously-allocated PARALLEL expression.  */
41*404b540aSrobert 
42*404b540aSrobert struct clobber_pat
43*404b540aSrobert {
44*404b540aSrobert   struct clobber_ent *insns;
45*404b540aSrobert   rtx pattern;
46*404b540aSrobert   int first_clobber;
47*404b540aSrobert   struct clobber_pat *next;
48*404b540aSrobert   int has_hard_reg;
49*404b540aSrobert } *clobber_list;
50*404b540aSrobert 
51*404b540aSrobert /* Records one insn that uses the clobber list.  */
52*404b540aSrobert 
53*404b540aSrobert struct clobber_ent
54*404b540aSrobert {
55*404b540aSrobert   int code_number;		/* Counts only insns.  */
56*404b540aSrobert   struct clobber_ent *next;
57*404b540aSrobert };
58*404b540aSrobert 
59*404b540aSrobert static void max_operand_1		(rtx);
60*404b540aSrobert static int max_operand_vec		(rtx, int);
61*404b540aSrobert static void print_code			(RTX_CODE);
62*404b540aSrobert static void gen_exp			(rtx, enum rtx_code, char *);
63*404b540aSrobert static void gen_insn			(rtx, int);
64*404b540aSrobert static void gen_expand			(rtx);
65*404b540aSrobert static void gen_split			(rtx);
66*404b540aSrobert static void output_add_clobbers		(void);
67*404b540aSrobert static void output_added_clobbers_hard_reg_p (void);
68*404b540aSrobert static void gen_rtx_scratch		(rtx, enum rtx_code);
69*404b540aSrobert static void output_peephole2_scratches	(rtx);
70*404b540aSrobert 
71*404b540aSrobert 
72*404b540aSrobert static void
max_operand_1(rtx x)73*404b540aSrobert max_operand_1 (rtx x)
74*404b540aSrobert {
75*404b540aSrobert   RTX_CODE code;
76*404b540aSrobert   int i;
77*404b540aSrobert   int len;
78*404b540aSrobert   const char *fmt;
79*404b540aSrobert 
80*404b540aSrobert   if (x == 0)
81*404b540aSrobert     return;
82*404b540aSrobert 
83*404b540aSrobert   code = GET_CODE (x);
84*404b540aSrobert 
85*404b540aSrobert   if (code == MATCH_OPERAND || code == MATCH_OPERATOR
86*404b540aSrobert       || code == MATCH_PARALLEL)
87*404b540aSrobert     max_opno = MAX (max_opno, XINT (x, 0));
88*404b540aSrobert   if (code == MATCH_DUP || code == MATCH_OP_DUP || code == MATCH_PAR_DUP)
89*404b540aSrobert     max_dup_opno = MAX (max_dup_opno, XINT (x, 0));
90*404b540aSrobert   if (code == MATCH_SCRATCH)
91*404b540aSrobert     max_scratch_opno = MAX (max_scratch_opno, XINT (x, 0));
92*404b540aSrobert 
93*404b540aSrobert   fmt = GET_RTX_FORMAT (code);
94*404b540aSrobert   len = GET_RTX_LENGTH (code);
95*404b540aSrobert   for (i = 0; i < len; i++)
96*404b540aSrobert     {
97*404b540aSrobert       if (fmt[i] == 'e' || fmt[i] == 'u')
98*404b540aSrobert 	max_operand_1 (XEXP (x, i));
99*404b540aSrobert       else if (fmt[i] == 'E')
100*404b540aSrobert 	{
101*404b540aSrobert 	  int j;
102*404b540aSrobert 	  for (j = 0; j < XVECLEN (x, i); j++)
103*404b540aSrobert 	    max_operand_1 (XVECEXP (x, i, j));
104*404b540aSrobert 	}
105*404b540aSrobert     }
106*404b540aSrobert }
107*404b540aSrobert 
108*404b540aSrobert static int
max_operand_vec(rtx insn,int arg)109*404b540aSrobert max_operand_vec (rtx insn, int arg)
110*404b540aSrobert {
111*404b540aSrobert   int len = XVECLEN (insn, arg);
112*404b540aSrobert   int i;
113*404b540aSrobert 
114*404b540aSrobert   max_opno = -1;
115*404b540aSrobert   max_dup_opno = -1;
116*404b540aSrobert   max_scratch_opno = -1;
117*404b540aSrobert 
118*404b540aSrobert   for (i = 0; i < len; i++)
119*404b540aSrobert     max_operand_1 (XVECEXP (insn, arg, i));
120*404b540aSrobert 
121*404b540aSrobert   return max_opno + 1;
122*404b540aSrobert }
123*404b540aSrobert 
124*404b540aSrobert static void
print_code(RTX_CODE code)125*404b540aSrobert print_code (RTX_CODE code)
126*404b540aSrobert {
127*404b540aSrobert   const char *p1;
128*404b540aSrobert   for (p1 = GET_RTX_NAME (code); *p1; p1++)
129*404b540aSrobert     putchar (TOUPPER(*p1));
130*404b540aSrobert }
131*404b540aSrobert 
132*404b540aSrobert static void
gen_rtx_scratch(rtx x,enum rtx_code subroutine_type)133*404b540aSrobert gen_rtx_scratch (rtx x, enum rtx_code subroutine_type)
134*404b540aSrobert {
135*404b540aSrobert   if (subroutine_type == DEFINE_PEEPHOLE2)
136*404b540aSrobert     {
137*404b540aSrobert       printf ("operand%d", XINT (x, 0));
138*404b540aSrobert     }
139*404b540aSrobert   else
140*404b540aSrobert     {
141*404b540aSrobert       printf ("gen_rtx_SCRATCH (%smode)", GET_MODE_NAME (GET_MODE (x)));
142*404b540aSrobert     }
143*404b540aSrobert }
144*404b540aSrobert 
145*404b540aSrobert /* Print a C expression to construct an RTX just like X,
146*404b540aSrobert    substituting any operand references appearing within.  */
147*404b540aSrobert 
148*404b540aSrobert static void
gen_exp(rtx x,enum rtx_code subroutine_type,char * used)149*404b540aSrobert gen_exp (rtx x, enum rtx_code subroutine_type, char *used)
150*404b540aSrobert {
151*404b540aSrobert   RTX_CODE code;
152*404b540aSrobert   int i;
153*404b540aSrobert   int len;
154*404b540aSrobert   const char *fmt;
155*404b540aSrobert 
156*404b540aSrobert   if (x == 0)
157*404b540aSrobert     {
158*404b540aSrobert       printf ("NULL_RTX");
159*404b540aSrobert       return;
160*404b540aSrobert     }
161*404b540aSrobert 
162*404b540aSrobert   code = GET_CODE (x);
163*404b540aSrobert 
164*404b540aSrobert   switch (code)
165*404b540aSrobert     {
166*404b540aSrobert     case MATCH_OPERAND:
167*404b540aSrobert     case MATCH_DUP:
168*404b540aSrobert       if (used)
169*404b540aSrobert 	{
170*404b540aSrobert 	  if (used[XINT (x, 0)])
171*404b540aSrobert 	    {
172*404b540aSrobert 	      printf ("copy_rtx (operand%d)", XINT (x, 0));
173*404b540aSrobert 	      return;
174*404b540aSrobert 	    }
175*404b540aSrobert 	  used[XINT (x, 0)] = 1;
176*404b540aSrobert 	}
177*404b540aSrobert       printf ("operand%d", XINT (x, 0));
178*404b540aSrobert       return;
179*404b540aSrobert 
180*404b540aSrobert     case MATCH_OP_DUP:
181*404b540aSrobert       printf ("gen_rtx_fmt_");
182*404b540aSrobert       for (i = 0; i < XVECLEN (x, 1); i++)
183*404b540aSrobert 	printf ("e");
184*404b540aSrobert       printf (" (GET_CODE (operand%d), ", XINT (x, 0));
185*404b540aSrobert       if (GET_MODE (x) == VOIDmode)
186*404b540aSrobert 	printf ("GET_MODE (operand%d)", XINT (x, 0));
187*404b540aSrobert       else
188*404b540aSrobert 	printf ("%smode", GET_MODE_NAME (GET_MODE (x)));
189*404b540aSrobert       for (i = 0; i < XVECLEN (x, 1); i++)
190*404b540aSrobert 	{
191*404b540aSrobert 	  printf (",\n\t\t");
192*404b540aSrobert 	  gen_exp (XVECEXP (x, 1, i), subroutine_type, used);
193*404b540aSrobert 	}
194*404b540aSrobert       printf (")");
195*404b540aSrobert       return;
196*404b540aSrobert 
197*404b540aSrobert     case MATCH_OPERATOR:
198*404b540aSrobert       printf ("gen_rtx_fmt_");
199*404b540aSrobert       for (i = 0; i < XVECLEN (x, 2); i++)
200*404b540aSrobert 	printf ("e");
201*404b540aSrobert       printf (" (GET_CODE (operand%d)", XINT (x, 0));
202*404b540aSrobert       printf (", %smode", GET_MODE_NAME (GET_MODE (x)));
203*404b540aSrobert       for (i = 0; i < XVECLEN (x, 2); i++)
204*404b540aSrobert 	{
205*404b540aSrobert 	  printf (",\n\t\t");
206*404b540aSrobert 	  gen_exp (XVECEXP (x, 2, i), subroutine_type, used);
207*404b540aSrobert 	}
208*404b540aSrobert       printf (")");
209*404b540aSrobert       return;
210*404b540aSrobert 
211*404b540aSrobert     case MATCH_PARALLEL:
212*404b540aSrobert     case MATCH_PAR_DUP:
213*404b540aSrobert       printf ("operand%d", XINT (x, 0));
214*404b540aSrobert       return;
215*404b540aSrobert 
216*404b540aSrobert     case MATCH_SCRATCH:
217*404b540aSrobert       gen_rtx_scratch (x, subroutine_type);
218*404b540aSrobert       return;
219*404b540aSrobert 
220*404b540aSrobert     case ADDRESS:
221*404b540aSrobert       fatal ("ADDRESS expression code used in named instruction pattern");
222*404b540aSrobert 
223*404b540aSrobert     case PC:
224*404b540aSrobert       printf ("pc_rtx");
225*404b540aSrobert       return;
226*404b540aSrobert     case CLOBBER:
227*404b540aSrobert       if (REG_P (XEXP (x, 0)))
228*404b540aSrobert 	{
229*404b540aSrobert 	  printf ("gen_hard_reg_clobber (%smode, %i)", GET_MODE_NAME (GET_MODE (XEXP (x, 0))),
230*404b540aSrobert 			  			     REGNO (XEXP (x, 0)));
231*404b540aSrobert 	  return;
232*404b540aSrobert 	}
233*404b540aSrobert       break;
234*404b540aSrobert 
235*404b540aSrobert     case CC0:
236*404b540aSrobert       printf ("cc0_rtx");
237*404b540aSrobert       return;
238*404b540aSrobert 
239*404b540aSrobert     case CONST_INT:
240*404b540aSrobert       if (INTVAL (x) == 0)
241*404b540aSrobert 	printf ("const0_rtx");
242*404b540aSrobert       else if (INTVAL (x) == 1)
243*404b540aSrobert 	printf ("const1_rtx");
244*404b540aSrobert       else if (INTVAL (x) == -1)
245*404b540aSrobert 	printf ("constm1_rtx");
246*404b540aSrobert       else if (-MAX_SAVED_CONST_INT <= INTVAL (x)
247*404b540aSrobert 	  && INTVAL (x) <= MAX_SAVED_CONST_INT)
248*404b540aSrobert 	printf ("const_int_rtx[MAX_SAVED_CONST_INT + (%d)]",
249*404b540aSrobert 		(int) INTVAL (x));
250*404b540aSrobert       else if (INTVAL (x) == STORE_FLAG_VALUE)
251*404b540aSrobert 	printf ("const_true_rtx");
252*404b540aSrobert       else
253*404b540aSrobert 	{
254*404b540aSrobert 	  printf ("GEN_INT (");
255*404b540aSrobert 	  printf (HOST_WIDE_INT_PRINT_DEC_C, INTVAL (x));
256*404b540aSrobert 	  printf (")");
257*404b540aSrobert 	}
258*404b540aSrobert       return;
259*404b540aSrobert 
260*404b540aSrobert     case CONST_DOUBLE:
261*404b540aSrobert       /* These shouldn't be written in MD files.  Instead, the appropriate
262*404b540aSrobert 	 routines in varasm.c should be called.  */
263*404b540aSrobert       gcc_unreachable ();
264*404b540aSrobert 
265*404b540aSrobert     default:
266*404b540aSrobert       break;
267*404b540aSrobert     }
268*404b540aSrobert 
269*404b540aSrobert   printf ("gen_rtx_");
270*404b540aSrobert   print_code (code);
271*404b540aSrobert   printf (" (%smode", GET_MODE_NAME (GET_MODE (x)));
272*404b540aSrobert 
273*404b540aSrobert   fmt = GET_RTX_FORMAT (code);
274*404b540aSrobert   len = GET_RTX_LENGTH (code);
275*404b540aSrobert   for (i = 0; i < len; i++)
276*404b540aSrobert     {
277*404b540aSrobert       if (fmt[i] == '0')
278*404b540aSrobert 	break;
279*404b540aSrobert       printf (",\n\t");
280*404b540aSrobert       switch (fmt[i])
281*404b540aSrobert 	{
282*404b540aSrobert 	case 'e': case 'u':
283*404b540aSrobert 	  gen_exp (XEXP (x, i), subroutine_type, used);
284*404b540aSrobert 	  break;
285*404b540aSrobert 
286*404b540aSrobert 	case 'i':
287*404b540aSrobert 	  printf ("%u", XINT (x, i));
288*404b540aSrobert 	  break;
289*404b540aSrobert 
290*404b540aSrobert 	case 's':
291*404b540aSrobert 	  printf ("\"%s\"", XSTR (x, i));
292*404b540aSrobert 	  break;
293*404b540aSrobert 
294*404b540aSrobert 	case 'E':
295*404b540aSrobert 	  {
296*404b540aSrobert 	    int j;
297*404b540aSrobert 	    printf ("gen_rtvec (%d", XVECLEN (x, i));
298*404b540aSrobert 	    for (j = 0; j < XVECLEN (x, i); j++)
299*404b540aSrobert 	      {
300*404b540aSrobert 		printf (",\n\t\t");
301*404b540aSrobert 		gen_exp (XVECEXP (x, i, j), subroutine_type, used);
302*404b540aSrobert 	      }
303*404b540aSrobert 	    printf (")");
304*404b540aSrobert 	    break;
305*404b540aSrobert 	  }
306*404b540aSrobert 
307*404b540aSrobert 	default:
308*404b540aSrobert 	  gcc_unreachable ();
309*404b540aSrobert 	}
310*404b540aSrobert     }
311*404b540aSrobert   printf (")");
312*404b540aSrobert }
313*404b540aSrobert 
314*404b540aSrobert /* Generate the `gen_...' function for a DEFINE_INSN.  */
315*404b540aSrobert 
316*404b540aSrobert static void
gen_insn(rtx insn,int lineno)317*404b540aSrobert gen_insn (rtx insn, int lineno)
318*404b540aSrobert {
319*404b540aSrobert   int operands;
320*404b540aSrobert   int i;
321*404b540aSrobert 
322*404b540aSrobert   /* See if the pattern for this insn ends with a group of CLOBBERs of (hard)
323*404b540aSrobert      registers or MATCH_SCRATCHes.  If so, store away the information for
324*404b540aSrobert      later.  */
325*404b540aSrobert 
326*404b540aSrobert   if (XVEC (insn, 1))
327*404b540aSrobert     {
328*404b540aSrobert       int has_hard_reg = 0;
329*404b540aSrobert 
330*404b540aSrobert       for (i = XVECLEN (insn, 1) - 1; i > 0; i--)
331*404b540aSrobert 	{
332*404b540aSrobert 	  if (GET_CODE (XVECEXP (insn, 1, i)) != CLOBBER)
333*404b540aSrobert 	    break;
334*404b540aSrobert 
335*404b540aSrobert 	  if (REG_P (XEXP (XVECEXP (insn, 1, i), 0)))
336*404b540aSrobert 	    has_hard_reg = 1;
337*404b540aSrobert 	  else if (GET_CODE (XEXP (XVECEXP (insn, 1, i), 0)) != MATCH_SCRATCH)
338*404b540aSrobert 	    break;
339*404b540aSrobert 	}
340*404b540aSrobert 
341*404b540aSrobert       if (i != XVECLEN (insn, 1) - 1)
342*404b540aSrobert 	{
343*404b540aSrobert 	  struct clobber_pat *p;
344*404b540aSrobert 	  struct clobber_ent *link = XNEW (struct clobber_ent);
345*404b540aSrobert 	  int j;
346*404b540aSrobert 
347*404b540aSrobert 	  link->code_number = insn_code_number;
348*404b540aSrobert 
349*404b540aSrobert 	  /* See if any previous CLOBBER_LIST entry is the same as this
350*404b540aSrobert 	     one.  */
351*404b540aSrobert 
352*404b540aSrobert 	  for (p = clobber_list; p; p = p->next)
353*404b540aSrobert 	    {
354*404b540aSrobert 	      if (p->first_clobber != i + 1
355*404b540aSrobert 		  || XVECLEN (p->pattern, 1) != XVECLEN (insn, 1))
356*404b540aSrobert 		continue;
357*404b540aSrobert 
358*404b540aSrobert 	      for (j = i + 1; j < XVECLEN (insn, 1); j++)
359*404b540aSrobert 		{
360*404b540aSrobert 		  rtx old = XEXP (XVECEXP (p->pattern, 1, j), 0);
361*404b540aSrobert 		  rtx new = XEXP (XVECEXP (insn, 1, j), 0);
362*404b540aSrobert 
363*404b540aSrobert 		  /* OLD and NEW are the same if both are to be a SCRATCH
364*404b540aSrobert 		     of the same mode,
365*404b540aSrobert 		     or if both are registers of the same mode and number.  */
366*404b540aSrobert 		  if (! (GET_MODE (old) == GET_MODE (new)
367*404b540aSrobert 			 && ((GET_CODE (old) == MATCH_SCRATCH
368*404b540aSrobert 			      && GET_CODE (new) == MATCH_SCRATCH)
369*404b540aSrobert 			     || (REG_P (old) && REG_P (new)
370*404b540aSrobert 				 && REGNO (old) == REGNO (new)))))
371*404b540aSrobert 		    break;
372*404b540aSrobert 		}
373*404b540aSrobert 
374*404b540aSrobert 	      if (j == XVECLEN (insn, 1))
375*404b540aSrobert 		break;
376*404b540aSrobert 	    }
377*404b540aSrobert 
378*404b540aSrobert 	  if (p == 0)
379*404b540aSrobert 	    {
380*404b540aSrobert 	      p = XNEW (struct clobber_pat);
381*404b540aSrobert 
382*404b540aSrobert 	      p->insns = 0;
383*404b540aSrobert 	      p->pattern = insn;
384*404b540aSrobert 	      p->first_clobber = i + 1;
385*404b540aSrobert 	      p->next = clobber_list;
386*404b540aSrobert 	      p->has_hard_reg = has_hard_reg;
387*404b540aSrobert 	      clobber_list = p;
388*404b540aSrobert 	    }
389*404b540aSrobert 
390*404b540aSrobert 	  link->next = p->insns;
391*404b540aSrobert 	  p->insns = link;
392*404b540aSrobert 	}
393*404b540aSrobert     }
394*404b540aSrobert 
395*404b540aSrobert   /* Don't mention instructions whose names are the null string
396*404b540aSrobert      or begin with '*'.  They are in the machine description just
397*404b540aSrobert      to be recognized.  */
398*404b540aSrobert   if (XSTR (insn, 0)[0] == 0 || XSTR (insn, 0)[0] == '*')
399*404b540aSrobert     return;
400*404b540aSrobert 
401*404b540aSrobert   printf ("/* %s:%d */\n", read_rtx_filename, lineno);
402*404b540aSrobert 
403*404b540aSrobert   /* Find out how many operands this function has.  */
404*404b540aSrobert   operands = max_operand_vec (insn, 1);
405*404b540aSrobert   if (max_dup_opno >= operands)
406*404b540aSrobert     fatal ("match_dup operand number has no match_operand");
407*404b540aSrobert 
408*404b540aSrobert   /* Output the function name and argument declarations.  */
409*404b540aSrobert   printf ("rtx\ngen_%s (", XSTR (insn, 0));
410*404b540aSrobert   if (operands)
411*404b540aSrobert     for (i = 0; i < operands; i++)
412*404b540aSrobert       if (i)
413*404b540aSrobert 	printf (",\n\trtx operand%d ATTRIBUTE_UNUSED", i);
414*404b540aSrobert       else
415*404b540aSrobert 	printf ("rtx operand%d ATTRIBUTE_UNUSED", i);
416*404b540aSrobert   else
417*404b540aSrobert     printf ("void");
418*404b540aSrobert   printf (")\n");
419*404b540aSrobert   printf ("{\n");
420*404b540aSrobert 
421*404b540aSrobert   /* Output code to construct and return the rtl for the instruction body.  */
422*404b540aSrobert 
423*404b540aSrobert   if (XVECLEN (insn, 1) == 1)
424*404b540aSrobert     {
425*404b540aSrobert       printf ("  return ");
426*404b540aSrobert       gen_exp (XVECEXP (insn, 1, 0), DEFINE_INSN, NULL);
427*404b540aSrobert       printf (";\n}\n\n");
428*404b540aSrobert     }
429*404b540aSrobert   else
430*404b540aSrobert     {
431*404b540aSrobert       printf ("  return gen_rtx_PARALLEL (VOIDmode, gen_rtvec (%d",
432*404b540aSrobert 	      XVECLEN (insn, 1));
433*404b540aSrobert 
434*404b540aSrobert       for (i = 0; i < XVECLEN (insn, 1); i++)
435*404b540aSrobert 	{
436*404b540aSrobert 	  printf (",\n\t\t");
437*404b540aSrobert 	  gen_exp (XVECEXP (insn, 1, i), DEFINE_INSN, NULL);
438*404b540aSrobert 	}
439*404b540aSrobert       printf ("));\n}\n\n");
440*404b540aSrobert     }
441*404b540aSrobert }
442*404b540aSrobert 
443*404b540aSrobert /* Generate the `gen_...' function for a DEFINE_EXPAND.  */
444*404b540aSrobert 
445*404b540aSrobert static void
gen_expand(rtx expand)446*404b540aSrobert gen_expand (rtx expand)
447*404b540aSrobert {
448*404b540aSrobert   int operands;
449*404b540aSrobert   int i;
450*404b540aSrobert 
451*404b540aSrobert   if (strlen (XSTR (expand, 0)) == 0)
452*404b540aSrobert     fatal ("define_expand lacks a name");
453*404b540aSrobert   if (XVEC (expand, 1) == 0)
454*404b540aSrobert     fatal ("define_expand for %s lacks a pattern", XSTR (expand, 0));
455*404b540aSrobert 
456*404b540aSrobert   /* Find out how many operands this function has.  */
457*404b540aSrobert   operands = max_operand_vec (expand, 1);
458*404b540aSrobert 
459*404b540aSrobert   /* Output the function name and argument declarations.  */
460*404b540aSrobert   printf ("rtx\ngen_%s (", XSTR (expand, 0));
461*404b540aSrobert   if (operands)
462*404b540aSrobert     for (i = 0; i < operands; i++)
463*404b540aSrobert       if (i)
464*404b540aSrobert 	printf (",\n\trtx operand%d", i);
465*404b540aSrobert       else
466*404b540aSrobert 	printf ("rtx operand%d", i);
467*404b540aSrobert   else
468*404b540aSrobert     printf ("void");
469*404b540aSrobert   printf (")\n");
470*404b540aSrobert   printf ("{\n");
471*404b540aSrobert 
472*404b540aSrobert   /* If we don't have any C code to write, only one insn is being written,
473*404b540aSrobert      and no MATCH_DUPs are present, we can just return the desired insn
474*404b540aSrobert      like we do for a DEFINE_INSN.  This saves memory.  */
475*404b540aSrobert   if ((XSTR (expand, 3) == 0 || *XSTR (expand, 3) == '\0')
476*404b540aSrobert       && operands > max_dup_opno
477*404b540aSrobert       && XVECLEN (expand, 1) == 1)
478*404b540aSrobert     {
479*404b540aSrobert       printf ("  return ");
480*404b540aSrobert       gen_exp (XVECEXP (expand, 1, 0), DEFINE_EXPAND, NULL);
481*404b540aSrobert       printf (";\n}\n\n");
482*404b540aSrobert       return;
483*404b540aSrobert     }
484*404b540aSrobert 
485*404b540aSrobert   /* For each operand referred to only with MATCH_DUPs,
486*404b540aSrobert      make a local variable.  */
487*404b540aSrobert   for (i = operands; i <= max_dup_opno; i++)
488*404b540aSrobert     printf ("  rtx operand%d;\n", i);
489*404b540aSrobert   for (; i <= max_scratch_opno; i++)
490*404b540aSrobert     printf ("  rtx operand%d ATTRIBUTE_UNUSED;\n", i);
491*404b540aSrobert   printf ("  rtx _val = 0;\n");
492*404b540aSrobert   printf ("  start_sequence ();\n");
493*404b540aSrobert 
494*404b540aSrobert   /* The fourth operand of DEFINE_EXPAND is some code to be executed
495*404b540aSrobert      before the actual construction.
496*404b540aSrobert      This code expects to refer to `operands'
497*404b540aSrobert      just as the output-code in a DEFINE_INSN does,
498*404b540aSrobert      but here `operands' is an automatic array.
499*404b540aSrobert      So copy the operand values there before executing it.  */
500*404b540aSrobert   if (XSTR (expand, 3) && *XSTR (expand, 3))
501*404b540aSrobert     {
502*404b540aSrobert       printf ("  {\n");
503*404b540aSrobert       if (operands > 0 || max_dup_opno >= 0 || max_scratch_opno >= 0)
504*404b540aSrobert 	printf ("    rtx operands[%d];\n",
505*404b540aSrobert 	    MAX (operands, MAX (max_scratch_opno, max_dup_opno) + 1));
506*404b540aSrobert       /* Output code to copy the arguments into `operands'.  */
507*404b540aSrobert       for (i = 0; i < operands; i++)
508*404b540aSrobert 	printf ("    operands[%d] = operand%d;\n", i, i);
509*404b540aSrobert 
510*404b540aSrobert       /* Output the special code to be executed before the sequence
511*404b540aSrobert 	 is generated.  */
512*404b540aSrobert       print_rtx_ptr_loc (XSTR (expand, 3));
513*404b540aSrobert       printf ("%s\n", XSTR (expand, 3));
514*404b540aSrobert 
515*404b540aSrobert       /* Output code to copy the arguments back out of `operands'
516*404b540aSrobert 	 (unless we aren't going to use them at all).  */
517*404b540aSrobert       if (XVEC (expand, 1) != 0)
518*404b540aSrobert 	{
519*404b540aSrobert 	  for (i = 0; i < operands; i++)
520*404b540aSrobert 	    printf ("    operand%d = operands[%d];\n", i, i);
521*404b540aSrobert 	  for (; i <= max_dup_opno; i++)
522*404b540aSrobert 	    printf ("    operand%d = operands[%d];\n", i, i);
523*404b540aSrobert 	  for (; i <= max_scratch_opno; i++)
524*404b540aSrobert 	    printf ("    operand%d = operands[%d];\n", i, i);
525*404b540aSrobert 	}
526*404b540aSrobert       printf ("  }\n");
527*404b540aSrobert     }
528*404b540aSrobert 
529*404b540aSrobert   /* Output code to construct the rtl for the instruction bodies.
530*404b540aSrobert      Use emit_insn to add them to the sequence being accumulated.
531*404b540aSrobert      But don't do this if the user's code has set `no_more' nonzero.  */
532*404b540aSrobert 
533*404b540aSrobert   for (i = 0; i < XVECLEN (expand, 1); i++)
534*404b540aSrobert     {
535*404b540aSrobert       rtx next = XVECEXP (expand, 1, i);
536*404b540aSrobert       if ((GET_CODE (next) == SET && GET_CODE (SET_DEST (next)) == PC)
537*404b540aSrobert 	  || (GET_CODE (next) == PARALLEL
538*404b540aSrobert 	      && ((GET_CODE (XVECEXP (next, 0, 0)) == SET
539*404b540aSrobert 		   && GET_CODE (SET_DEST (XVECEXP (next, 0, 0))) == PC)
540*404b540aSrobert 		  || GET_CODE (XVECEXP (next, 0, 0)) == RETURN))
541*404b540aSrobert 	  || GET_CODE (next) == RETURN)
542*404b540aSrobert 	printf ("  emit_jump_insn (");
543*404b540aSrobert       else if ((GET_CODE (next) == SET && GET_CODE (SET_SRC (next)) == CALL)
544*404b540aSrobert 	       || GET_CODE (next) == CALL
545*404b540aSrobert 	       || (GET_CODE (next) == PARALLEL
546*404b540aSrobert 		   && GET_CODE (XVECEXP (next, 0, 0)) == SET
547*404b540aSrobert 		   && GET_CODE (SET_SRC (XVECEXP (next, 0, 0))) == CALL)
548*404b540aSrobert 	       || (GET_CODE (next) == PARALLEL
549*404b540aSrobert 		   && GET_CODE (XVECEXP (next, 0, 0)) == CALL))
550*404b540aSrobert 	printf ("  emit_call_insn (");
551*404b540aSrobert       else if (LABEL_P (next))
552*404b540aSrobert 	printf ("  emit_label (");
553*404b540aSrobert       else if (GET_CODE (next) == MATCH_OPERAND
554*404b540aSrobert 	       || GET_CODE (next) == MATCH_DUP
555*404b540aSrobert 	       || GET_CODE (next) == MATCH_OPERATOR
556*404b540aSrobert 	       || GET_CODE (next) == MATCH_OP_DUP
557*404b540aSrobert 	       || GET_CODE (next) == MATCH_PARALLEL
558*404b540aSrobert 	       || GET_CODE (next) == MATCH_PAR_DUP
559*404b540aSrobert 	       || GET_CODE (next) == PARALLEL)
560*404b540aSrobert 	printf ("  emit (");
561*404b540aSrobert       else
562*404b540aSrobert 	printf ("  emit_insn (");
563*404b540aSrobert       gen_exp (next, DEFINE_EXPAND, NULL);
564*404b540aSrobert       printf (");\n");
565*404b540aSrobert       if (GET_CODE (next) == SET && GET_CODE (SET_DEST (next)) == PC
566*404b540aSrobert 	  && GET_CODE (SET_SRC (next)) == LABEL_REF)
567*404b540aSrobert 	printf ("  emit_barrier ();");
568*404b540aSrobert     }
569*404b540aSrobert 
570*404b540aSrobert   /* Call `get_insns' to extract the list of all the
571*404b540aSrobert      insns emitted within this gen_... function.  */
572*404b540aSrobert 
573*404b540aSrobert   printf ("  _val = get_insns ();\n");
574*404b540aSrobert   printf ("  end_sequence ();\n");
575*404b540aSrobert   printf ("  return _val;\n}\n\n");
576*404b540aSrobert }
577*404b540aSrobert 
578*404b540aSrobert /* Like gen_expand, but generates insns resulting from splitting SPLIT.  */
579*404b540aSrobert 
580*404b540aSrobert static void
gen_split(rtx split)581*404b540aSrobert gen_split (rtx split)
582*404b540aSrobert {
583*404b540aSrobert   int i;
584*404b540aSrobert   int operands;
585*404b540aSrobert   const char *const name =
586*404b540aSrobert     ((GET_CODE (split) == DEFINE_PEEPHOLE2) ? "peephole2" : "split");
587*404b540aSrobert   const char *unused;
588*404b540aSrobert   char *used;
589*404b540aSrobert 
590*404b540aSrobert   if (XVEC (split, 0) == 0)
591*404b540aSrobert     fatal ("define_%s (definition %d) lacks a pattern", name,
592*404b540aSrobert 	   insn_index_number);
593*404b540aSrobert   else if (XVEC (split, 2) == 0)
594*404b540aSrobert     fatal ("define_%s (definition %d) lacks a replacement pattern", name,
595*404b540aSrobert 	   insn_index_number);
596*404b540aSrobert 
597*404b540aSrobert   /* Find out how many operands this function has.  */
598*404b540aSrobert 
599*404b540aSrobert   max_operand_vec (split, 2);
600*404b540aSrobert   operands = MAX (max_opno, MAX (max_dup_opno, max_scratch_opno)) + 1;
601*404b540aSrobert   unused = (operands == 0 ? " ATTRIBUTE_UNUSED" : "");
602*404b540aSrobert   used = XCNEWVEC (char, operands);
603*404b540aSrobert 
604*404b540aSrobert   /* Output the prototype, function name and argument declarations.  */
605*404b540aSrobert   if (GET_CODE (split) == DEFINE_PEEPHOLE2)
606*404b540aSrobert     {
607*404b540aSrobert       printf ("extern rtx gen_%s_%d (rtx, rtx *);\n",
608*404b540aSrobert 	      name, insn_code_number);
609*404b540aSrobert       printf ("rtx\ngen_%s_%d (rtx curr_insn ATTRIBUTE_UNUSED, rtx *operands%s)\n",
610*404b540aSrobert 	      name, insn_code_number, unused);
611*404b540aSrobert     }
612*404b540aSrobert   else
613*404b540aSrobert     {
614*404b540aSrobert       printf ("extern rtx gen_split_%d (rtx, rtx *);\n", insn_code_number);
615*404b540aSrobert       printf ("rtx\ngen_split_%d (rtx curr_insn ATTRIBUTE_UNUSED, rtx *operands%s)\n",
616*404b540aSrobert 	      insn_code_number, unused);
617*404b540aSrobert     }
618*404b540aSrobert   printf ("{\n");
619*404b540aSrobert 
620*404b540aSrobert   /* Declare all local variables.  */
621*404b540aSrobert   for (i = 0; i < operands; i++)
622*404b540aSrobert     printf ("  rtx operand%d;\n", i);
623*404b540aSrobert   printf ("  rtx _val = 0;\n");
624*404b540aSrobert 
625*404b540aSrobert   if (GET_CODE (split) == DEFINE_PEEPHOLE2)
626*404b540aSrobert     output_peephole2_scratches (split);
627*404b540aSrobert 
628*404b540aSrobert   printf ("  start_sequence ();\n");
629*404b540aSrobert 
630*404b540aSrobert   /* The fourth operand of DEFINE_SPLIT is some code to be executed
631*404b540aSrobert      before the actual construction.  */
632*404b540aSrobert 
633*404b540aSrobert   if (XSTR (split, 3))
634*404b540aSrobert     {
635*404b540aSrobert       print_rtx_ptr_loc (XSTR (split, 3));
636*404b540aSrobert       printf ("%s\n", XSTR (split, 3));
637*404b540aSrobert     }
638*404b540aSrobert 
639*404b540aSrobert   /* Output code to copy the arguments back out of `operands'  */
640*404b540aSrobert   for (i = 0; i < operands; i++)
641*404b540aSrobert     printf ("  operand%d = operands[%d];\n", i, i);
642*404b540aSrobert 
643*404b540aSrobert   /* Output code to construct the rtl for the instruction bodies.
644*404b540aSrobert      Use emit_insn to add them to the sequence being accumulated.
645*404b540aSrobert      But don't do this if the user's code has set `no_more' nonzero.  */
646*404b540aSrobert 
647*404b540aSrobert   for (i = 0; i < XVECLEN (split, 2); i++)
648*404b540aSrobert     {
649*404b540aSrobert       rtx next = XVECEXP (split, 2, i);
650*404b540aSrobert       if ((GET_CODE (next) == SET && GET_CODE (SET_DEST (next)) == PC)
651*404b540aSrobert 	  || (GET_CODE (next) == PARALLEL
652*404b540aSrobert 	      && GET_CODE (XVECEXP (next, 0, 0)) == SET
653*404b540aSrobert 	      && GET_CODE (SET_DEST (XVECEXP (next, 0, 0))) == PC)
654*404b540aSrobert 	  || GET_CODE (next) == RETURN)
655*404b540aSrobert 	printf ("  emit_jump_insn (");
656*404b540aSrobert       else if ((GET_CODE (next) == SET && GET_CODE (SET_SRC (next)) == CALL)
657*404b540aSrobert 	       || GET_CODE (next) == CALL
658*404b540aSrobert 	       || (GET_CODE (next) == PARALLEL
659*404b540aSrobert 		   && GET_CODE (XVECEXP (next, 0, 0)) == SET
660*404b540aSrobert 		   && GET_CODE (SET_SRC (XVECEXP (next, 0, 0))) == CALL)
661*404b540aSrobert 	       || (GET_CODE (next) == PARALLEL
662*404b540aSrobert 		   && GET_CODE (XVECEXP (next, 0, 0)) == CALL))
663*404b540aSrobert 	printf ("  emit_call_insn (");
664*404b540aSrobert       else if (LABEL_P (next))
665*404b540aSrobert 	printf ("  emit_label (");
666*404b540aSrobert       else if (GET_CODE (next) == MATCH_OPERAND
667*404b540aSrobert 	       || GET_CODE (next) == MATCH_OPERATOR
668*404b540aSrobert 	       || GET_CODE (next) == MATCH_PARALLEL
669*404b540aSrobert 	       || GET_CODE (next) == MATCH_OP_DUP
670*404b540aSrobert 	       || GET_CODE (next) == MATCH_DUP
671*404b540aSrobert 	       || GET_CODE (next) == PARALLEL)
672*404b540aSrobert 	printf ("  emit (");
673*404b540aSrobert       else
674*404b540aSrobert 	printf ("  emit_insn (");
675*404b540aSrobert       gen_exp (next, GET_CODE (split), used);
676*404b540aSrobert       printf (");\n");
677*404b540aSrobert       if (GET_CODE (next) == SET && GET_CODE (SET_DEST (next)) == PC
678*404b540aSrobert 	  && GET_CODE (SET_SRC (next)) == LABEL_REF)
679*404b540aSrobert 	printf ("  emit_barrier ();");
680*404b540aSrobert     }
681*404b540aSrobert 
682*404b540aSrobert   /* Call `get_insns' to make a list of all the
683*404b540aSrobert      insns emitted within this gen_... function.  */
684*404b540aSrobert 
685*404b540aSrobert   printf ("  _val = get_insns ();\n");
686*404b540aSrobert   printf ("  end_sequence ();\n");
687*404b540aSrobert   printf ("  return _val;\n}\n\n");
688*404b540aSrobert 
689*404b540aSrobert   free (used);
690*404b540aSrobert }
691*404b540aSrobert 
692*404b540aSrobert /* Write a function, `add_clobbers', that is given a PARALLEL of sufficient
693*404b540aSrobert    size for the insn and an INSN_CODE, and inserts the required CLOBBERs at
694*404b540aSrobert    the end of the vector.  */
695*404b540aSrobert 
696*404b540aSrobert static void
output_add_clobbers(void)697*404b540aSrobert output_add_clobbers (void)
698*404b540aSrobert {
699*404b540aSrobert   struct clobber_pat *clobber;
700*404b540aSrobert   struct clobber_ent *ent;
701*404b540aSrobert   int i;
702*404b540aSrobert 
703*404b540aSrobert   printf ("\n\nvoid\nadd_clobbers (rtx pattern ATTRIBUTE_UNUSED, int insn_code_number)\n");
704*404b540aSrobert   printf ("{\n");
705*404b540aSrobert   printf ("  switch (insn_code_number)\n");
706*404b540aSrobert   printf ("    {\n");
707*404b540aSrobert 
708*404b540aSrobert   for (clobber = clobber_list; clobber; clobber = clobber->next)
709*404b540aSrobert     {
710*404b540aSrobert       for (ent = clobber->insns; ent; ent = ent->next)
711*404b540aSrobert 	printf ("    case %d:\n", ent->code_number);
712*404b540aSrobert 
713*404b540aSrobert       for (i = clobber->first_clobber; i < XVECLEN (clobber->pattern, 1); i++)
714*404b540aSrobert 	{
715*404b540aSrobert 	  printf ("      XVECEXP (pattern, 0, %d) = ", i);
716*404b540aSrobert 	  gen_exp (XVECEXP (clobber->pattern, 1, i),
717*404b540aSrobert 		   GET_CODE (clobber->pattern), NULL);
718*404b540aSrobert 	  printf (";\n");
719*404b540aSrobert 	}
720*404b540aSrobert 
721*404b540aSrobert       printf ("      break;\n\n");
722*404b540aSrobert     }
723*404b540aSrobert 
724*404b540aSrobert   printf ("    default:\n");
725*404b540aSrobert   printf ("      gcc_unreachable ();\n");
726*404b540aSrobert   printf ("    }\n");
727*404b540aSrobert   printf ("}\n");
728*404b540aSrobert }
729*404b540aSrobert 
730*404b540aSrobert /* Write a function, `added_clobbers_hard_reg_p' that is given an insn_code
731*404b540aSrobert    number that will have clobbers added (as indicated by `recog') and returns
732*404b540aSrobert    1 if those include a clobber of a hard reg or 0 if all of them just clobber
733*404b540aSrobert    SCRATCH.  */
734*404b540aSrobert 
735*404b540aSrobert static void
output_added_clobbers_hard_reg_p(void)736*404b540aSrobert output_added_clobbers_hard_reg_p (void)
737*404b540aSrobert {
738*404b540aSrobert   struct clobber_pat *clobber;
739*404b540aSrobert   struct clobber_ent *ent;
740*404b540aSrobert   int clobber_p, used;
741*404b540aSrobert 
742*404b540aSrobert   printf ("\n\nint\nadded_clobbers_hard_reg_p (int insn_code_number)\n");
743*404b540aSrobert   printf ("{\n");
744*404b540aSrobert   printf ("  switch (insn_code_number)\n");
745*404b540aSrobert   printf ("    {\n");
746*404b540aSrobert 
747*404b540aSrobert   for (clobber_p = 0; clobber_p <= 1; clobber_p++)
748*404b540aSrobert     {
749*404b540aSrobert       used = 0;
750*404b540aSrobert       for (clobber = clobber_list; clobber; clobber = clobber->next)
751*404b540aSrobert 	if (clobber->has_hard_reg == clobber_p)
752*404b540aSrobert 	  for (ent = clobber->insns; ent; ent = ent->next)
753*404b540aSrobert 	    {
754*404b540aSrobert 	      printf ("    case %d:\n", ent->code_number);
755*404b540aSrobert 	      used++;
756*404b540aSrobert 	    }
757*404b540aSrobert 
758*404b540aSrobert       if (used)
759*404b540aSrobert 	printf ("      return %d;\n\n", clobber_p);
760*404b540aSrobert     }
761*404b540aSrobert 
762*404b540aSrobert   printf ("    default:\n");
763*404b540aSrobert   printf ("      gcc_unreachable ();\n");
764*404b540aSrobert   printf ("    }\n");
765*404b540aSrobert   printf ("}\n");
766*404b540aSrobert }
767*404b540aSrobert 
768*404b540aSrobert /* Generate code to invoke find_free_register () as needed for the
769*404b540aSrobert    scratch registers used by the peephole2 pattern in SPLIT.  */
770*404b540aSrobert 
771*404b540aSrobert static void
output_peephole2_scratches(rtx split)772*404b540aSrobert output_peephole2_scratches (rtx split)
773*404b540aSrobert {
774*404b540aSrobert   int i;
775*404b540aSrobert   int insn_nr = 0;
776*404b540aSrobert 
777*404b540aSrobert   printf ("  HARD_REG_SET _regs_allocated;\n");
778*404b540aSrobert   printf ("  CLEAR_HARD_REG_SET (_regs_allocated);\n");
779*404b540aSrobert 
780*404b540aSrobert   for (i = 0; i < XVECLEN (split, 0); i++)
781*404b540aSrobert     {
782*404b540aSrobert       rtx elt = XVECEXP (split, 0, i);
783*404b540aSrobert       if (GET_CODE (elt) == MATCH_SCRATCH)
784*404b540aSrobert 	{
785*404b540aSrobert 	  int last_insn_nr = insn_nr;
786*404b540aSrobert 	  int cur_insn_nr = insn_nr;
787*404b540aSrobert 	  int j;
788*404b540aSrobert 	  for (j = i + 1; j < XVECLEN (split, 0); j++)
789*404b540aSrobert 	    if (GET_CODE (XVECEXP (split, 0, j)) == MATCH_DUP)
790*404b540aSrobert 	      {
791*404b540aSrobert 		if (XINT (XVECEXP (split, 0, j), 0) == XINT (elt, 0))
792*404b540aSrobert 		  last_insn_nr = cur_insn_nr;
793*404b540aSrobert 	      }
794*404b540aSrobert 	    else if (GET_CODE (XVECEXP (split, 0, j)) != MATCH_SCRATCH)
795*404b540aSrobert 	      cur_insn_nr++;
796*404b540aSrobert 
797*404b540aSrobert 	  printf ("  if ((operands[%d] = peep2_find_free_register (%d, %d, \"%s\", %smode, &_regs_allocated)) == NULL_RTX)\n\
798*404b540aSrobert     return NULL;\n",
799*404b540aSrobert 		  XINT (elt, 0),
800*404b540aSrobert 		  insn_nr, last_insn_nr,
801*404b540aSrobert 		  XSTR (elt, 1),
802*404b540aSrobert 		  GET_MODE_NAME (GET_MODE (elt)));
803*404b540aSrobert 
804*404b540aSrobert 	}
805*404b540aSrobert       else if (GET_CODE (elt) != MATCH_DUP)
806*404b540aSrobert 	insn_nr++;
807*404b540aSrobert     }
808*404b540aSrobert }
809*404b540aSrobert 
810*404b540aSrobert int
main(int argc,char ** argv)811*404b540aSrobert main (int argc, char **argv)
812*404b540aSrobert {
813*404b540aSrobert   rtx desc;
814*404b540aSrobert 
815*404b540aSrobert   progname = "genemit";
816*404b540aSrobert 
817*404b540aSrobert   if (init_md_reader_args (argc, argv) != SUCCESS_EXIT_CODE)
818*404b540aSrobert     return (FATAL_EXIT_CODE);
819*404b540aSrobert 
820*404b540aSrobert   /* Assign sequential codes to all entries in the machine description
821*404b540aSrobert      in parallel with the tables in insn-output.c.  */
822*404b540aSrobert 
823*404b540aSrobert   insn_code_number = 0;
824*404b540aSrobert   insn_index_number = 0;
825*404b540aSrobert 
826*404b540aSrobert   printf ("/* Generated automatically by the program `genemit'\n\
827*404b540aSrobert from the machine description file `md'.  */\n\n");
828*404b540aSrobert 
829*404b540aSrobert   printf ("#include \"config.h\"\n");
830*404b540aSrobert   printf ("#include \"system.h\"\n");
831*404b540aSrobert   printf ("#include \"coretypes.h\"\n");
832*404b540aSrobert   printf ("#include \"tm.h\"\n");
833*404b540aSrobert   printf ("#include \"rtl.h\"\n");
834*404b540aSrobert   printf ("#include \"tm_p.h\"\n");
835*404b540aSrobert   printf ("#include \"function.h\"\n");
836*404b540aSrobert   printf ("#include \"expr.h\"\n");
837*404b540aSrobert   printf ("#include \"optabs.h\"\n");
838*404b540aSrobert   printf ("#include \"real.h\"\n");
839*404b540aSrobert   printf ("#include \"flags.h\"\n");
840*404b540aSrobert   printf ("#include \"output.h\"\n");
841*404b540aSrobert   printf ("#include \"insn-config.h\"\n");
842*404b540aSrobert   printf ("#include \"hard-reg-set.h\"\n");
843*404b540aSrobert   printf ("#include \"recog.h\"\n");
844*404b540aSrobert   printf ("#include \"resource.h\"\n");
845*404b540aSrobert   printf ("#include \"reload.h\"\n");
846*404b540aSrobert   printf ("#include \"toplev.h\"\n");
847*404b540aSrobert   printf ("#include \"tm-constrs.h\"\n");
848*404b540aSrobert   printf ("#include \"ggc.h\"\n\n");
849*404b540aSrobert   printf ("#include \"basic-block.h\"\n\n");
850*404b540aSrobert   printf ("#define FAIL return (end_sequence (), _val)\n");
851*404b540aSrobert   printf ("#define DONE return (_val = get_insns (), end_sequence (), _val)\n\n");
852*404b540aSrobert 
853*404b540aSrobert   /* Read the machine description.  */
854*404b540aSrobert 
855*404b540aSrobert   while (1)
856*404b540aSrobert     {
857*404b540aSrobert       int line_no;
858*404b540aSrobert 
859*404b540aSrobert       desc = read_md_rtx (&line_no, &insn_code_number);
860*404b540aSrobert       if (desc == NULL)
861*404b540aSrobert 	break;
862*404b540aSrobert 
863*404b540aSrobert       switch (GET_CODE (desc))
864*404b540aSrobert 	{
865*404b540aSrobert 	case DEFINE_INSN:
866*404b540aSrobert 	  gen_insn (desc, line_no);
867*404b540aSrobert 	  break;
868*404b540aSrobert 
869*404b540aSrobert 	case DEFINE_EXPAND:
870*404b540aSrobert 	  printf ("/* %s:%d */\n", read_rtx_filename, line_no);
871*404b540aSrobert 	  gen_expand (desc);
872*404b540aSrobert 	  break;
873*404b540aSrobert 
874*404b540aSrobert 	case DEFINE_SPLIT:
875*404b540aSrobert 	  printf ("/* %s:%d */\n", read_rtx_filename, line_no);
876*404b540aSrobert 	  gen_split (desc);
877*404b540aSrobert 	  break;
878*404b540aSrobert 
879*404b540aSrobert 	case DEFINE_PEEPHOLE2:
880*404b540aSrobert 	  printf ("/* %s:%d */\n", read_rtx_filename, line_no);
881*404b540aSrobert 	  gen_split (desc);
882*404b540aSrobert 	  break;
883*404b540aSrobert 
884*404b540aSrobert 	default:
885*404b540aSrobert 	  break;
886*404b540aSrobert 	}
887*404b540aSrobert       ++insn_index_number;
888*404b540aSrobert     }
889*404b540aSrobert 
890*404b540aSrobert   /* Write out the routines to add CLOBBERs to a pattern and say whether they
891*404b540aSrobert      clobber a hard reg.  */
892*404b540aSrobert   output_add_clobbers ();
893*404b540aSrobert   output_added_clobbers_hard_reg_p ();
894*404b540aSrobert 
895*404b540aSrobert   fflush (stdout);
896*404b540aSrobert   return (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
897*404b540aSrobert }
898