1 /* Generate code from to output assembler insns as recognized from rtl.
2 Copyright (C) 1987, 1988, 1992, 1994, 1995, 1997, 1998, 1999, 2000, 2002,
3 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011, 2012
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 /* This program reads the machine description for the compiler target machine
24 and produces a file containing these things:
26 1. An array of `struct insn_data_d', which is indexed by insn code number,
29 a. `name' is the name for that pattern. Nameless patterns are
32 b. `output' hold either the output template, an array of output
33 templates, or an output function.
35 c. `genfun' is the function to generate a body for that pattern,
36 given operands as arguments.
38 d. `n_operands' is the number of distinct operands in the pattern
41 e. `n_dups' is the number of match_dup's that appear in the insn's
42 pattern. This says how many elements of `recog_data.dup_loc' are
43 significant after an insn has been recognized.
45 f. `n_alternatives' is the number of alternatives in the constraints
48 g. `output_format' tells what type of thing `output' is.
50 h. `operand' is the base of an array of operand data for the insn.
52 2. An array of `struct insn_operand data', used by `operand' above.
54 a. `predicate', an int-valued function, is the match_operand predicate
57 b. `constraint' is the constraint for this operand.
59 c. `address_p' indicates that the operand appears within ADDRESS
62 d. `mode' is the machine mode that that operand is supposed to have.
64 e. `strict_low', is nonzero for operands contained in a STRICT_LOW_PART.
66 f. `eliminable', is nonzero for operands that are matched normally by
67 MATCH_OPERAND; it is zero for operands that should not be changed during
68 register elimination such as MATCH_OPERATORs.
70 g. `allows_mem', is true for operands that accept MEM rtxes.
72 The code number of an insn is simply its position in the machine
73 description; code numbers are assigned sequentially to entries in
74 the description, starting with code number 0.
76 Thus, the following entry in the machine description
79 [(set (match_operand:DF 0 "general_operand" "")
84 assuming it is the 25th entry present, would cause
85 insn_data[24].template to be "clrd %0", and
86 insn_data[24].n_operands to be 1. */
90 #include "coretypes.h"
95 #include "gensupport.h"
97 /* No instruction can have more operands than this. Sorry for this
98 arbitrary limit, but what machine will have an instruction with
99 this many operands? */
101 #define MAX_MAX_OPERANDS 40
103 static int n_occurrences (int, const char *);
104 static const char *strip_whitespace (const char *);
106 /* insns in the machine description are assigned sequential code numbers
107 that are used by insn-recog.c (produced by genrecog) to communicate
108 to insn-output.c (produced by this program). */
110 static int next_code_number
;
112 /* This counts all definitions in the md file,
113 for the sake of error messages. */
115 static int next_index_number
;
117 /* This counts all operands used in the md file. The first is null. */
119 static int next_operand_number
= 1;
121 /* Record in this chain all information about the operands we will output. */
125 struct operand_data
*next
;
127 const char *predicate
;
128 const char *constraint
;
129 enum machine_mode mode
;
130 unsigned char n_alternatives
;
137 /* Begin with a null operand at index 0. */
139 static struct operand_data null_operand
=
141 0, 0, "", "", VOIDmode
, 0, 0, 0, 0, 0
144 static struct operand_data
*odata
= &null_operand
;
145 static struct operand_data
**odata_end
= &null_operand
.next
;
147 /* Must match the constants in recog.h. */
149 #define INSN_OUTPUT_FORMAT_NONE 0 /* abort */
150 #define INSN_OUTPUT_FORMAT_SINGLE 1 /* const char * */
151 #define INSN_OUTPUT_FORMAT_MULTI 2 /* const char * const * */
152 #define INSN_OUTPUT_FORMAT_FUNCTION 3 /* const char * (*)(...) */
154 /* Record in this chain all information that we will output,
155 associated with the code number of the insn. */
161 const char *template_code
;
164 const char *filename
;
166 int n_generator_args
; /* Number of arguments passed to generator */
167 int n_operands
; /* Number of operands this insn recognizes */
168 int n_dups
; /* Number times match_dup appears in pattern */
169 int n_alternatives
; /* Number of alternatives in each constraint */
170 int operand_number
; /* Operand index in the big array. */
171 int output_format
; /* INSN_OUTPUT_FORMAT_*. */
172 struct operand_data operand
[MAX_MAX_OPERANDS
];
175 /* A dummy insn, for CODE_FOR_nothing. */
176 static struct data nothing
;
178 /* This variable points to the first link in the insn chain. */
179 static struct data
*idata
= ¬hing
;
181 /* This variable points to the end of the insn chain. This is where
182 everything relevant from the machien description is appended to. */
183 static struct data
**idata_end
= ¬hing
.next
;
186 static void output_prologue (void);
187 static void output_operand_data (void);
188 static void output_insn_data (void);
189 static void output_get_insn_name (void);
190 static void scan_operands (struct data
*, rtx
, int, int);
191 static int compare_operands (struct operand_data
*,
192 struct operand_data
*);
193 static void place_operands (struct data
*);
194 static void process_template (struct data
*, const char *);
195 static void validate_insn_alternatives (struct data
*);
196 static void validate_insn_operands (struct data
*);
197 static void gen_insn (rtx
, int);
198 static void gen_peephole (rtx
, int);
199 static void gen_expand (rtx
, int);
200 static void gen_split (rtx
, int);
202 #ifdef USE_MD_CONSTRAINTS
204 struct constraint_data
206 struct constraint_data
*next_this_letter
;
208 unsigned int namelen
;
212 /* This is a complete list (unlike the one in genpreds.c) of constraint
213 letters and modifiers with machine-independent meaning. The only
214 omission is digits, as these are handled specially. */
215 static const char indep_constraints
[] = ",=+%*?!#&<>EFVXgimnoprs";
217 static struct constraint_data
*
218 constraints_by_letter_table
[1 << CHAR_BIT
];
220 static int mdep_constraint_len (const char *, int, int);
221 static void note_constraint (rtx
, int);
223 #else /* !USE_MD_CONSTRAINTS */
225 static void check_constraint_len (void);
226 static int constraint_len (const char *, int);
228 #endif /* !USE_MD_CONSTRAINTS */
232 output_prologue (void)
234 printf ("/* Generated automatically by the program `genoutput'\n\
235 from the machine description file `md'. */\n\n");
237 printf ("#include \"config.h\"\n");
238 printf ("#include \"system.h\"\n");
239 printf ("#include \"coretypes.h\"\n");
240 printf ("#include \"tm.h\"\n");
241 printf ("#include \"flags.h\"\n");
242 printf ("#include \"ggc.h\"\n");
243 printf ("#include \"rtl.h\"\n");
244 printf ("#include \"expr.h\"\n");
245 printf ("#include \"insn-codes.h\"\n");
246 printf ("#include \"tm_p.h\"\n");
247 printf ("#include \"function.h\"\n");
248 printf ("#include \"regs.h\"\n");
249 printf ("#include \"hard-reg-set.h\"\n");
250 printf ("#include \"insn-config.h\"\n\n");
251 printf ("#include \"conditions.h\"\n");
252 printf ("#include \"insn-attr.h\"\n\n");
253 printf ("#include \"recog.h\"\n\n");
254 printf ("#include \"diagnostic-core.h\"\n");
255 printf ("#include \"output.h\"\n");
256 printf ("#include \"target.h\"\n");
257 printf ("#include \"tm-constrs.h\"\n");
261 output_operand_data (void)
263 struct operand_data
*d
;
265 printf ("\nstatic const struct insn_operand_data operand_data[] = \n{\n");
267 for (d
= odata
; d
; d
= d
->next
)
269 struct pred_data
*pred
;
274 d
->predicate
&& d
->predicate
[0] ? d
->predicate
: "0");
276 printf (" \"%s\",\n", d
->constraint
? d
->constraint
: "");
278 printf (" %smode,\n", GET_MODE_NAME (d
->mode
));
280 printf (" %d,\n", d
->strict_low
);
282 printf (" %d,\n", d
->constraint
== NULL
? 1 : 0);
284 printf (" %d,\n", d
->eliminable
);
288 pred
= lookup_predicate (d
->predicate
);
289 printf (" %d\n", pred
&& pred
->codes
[MEM
]);
297 output_insn_data (void)
301 int next_name_offset
;
302 const char * last_name
= 0;
303 const char * next_name
= 0;
306 for (n
= idata
, next_name_offset
= 1; n
; n
= n
->next
, next_name_offset
++)
313 printf ("#if GCC_VERSION >= 2007\n__extension__\n#endif\n");
314 printf ("\nconst struct insn_data_d insn_data[] = \n{\n");
316 for (d
= idata
; d
; d
= d
->next
)
318 printf (" /* %s:%d */\n", d
->filename
, d
->lineno
);
323 printf (" \"%s\",\n", d
->name
);
327 for (n
= d
->next
, next_name_offset
= 1; n
;
328 n
= n
->next
, next_name_offset
++)
340 if (next_name
&& (last_name
== 0
341 || name_offset
> next_name_offset
/ 2))
342 printf (" \"%s-%d\",\n", next_name
,
343 next_name_offset
- name_offset
);
345 printf (" \"%s+%d\",\n", last_name
, name_offset
);
348 switch (d
->output_format
)
350 case INSN_OUTPUT_FORMAT_NONE
:
351 printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n");
352 printf (" { 0 },\n");
354 printf (" { 0, 0, 0 },\n");
357 case INSN_OUTPUT_FORMAT_SINGLE
:
359 const char *p
= d
->template_code
;
362 printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n");
363 printf (" { .single =\n");
370 if (IS_VSPACE (*p
) && prev
!= '\\')
372 /* Preserve two consecutive \n's or \r's, but treat \r\n
373 as a single newline. */
374 if (*p
== '\n' && prev
!= '\r')
383 printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n");
386 printf (" 0, 0 },\n");
390 case INSN_OUTPUT_FORMAT_MULTI
:
391 printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n");
392 printf (" { .multi = output_%d },\n", d
->code_number
);
394 printf (" { 0, output_%d, 0 },\n", d
->code_number
);
397 case INSN_OUTPUT_FORMAT_FUNCTION
:
398 printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n");
399 printf (" { .function = output_%d },\n", d
->code_number
);
401 printf (" { 0, 0, output_%d },\n", d
->code_number
);
408 if (d
->name
&& d
->name
[0] != '*')
409 printf (" (insn_gen_fn) gen_%s,\n", d
->name
);
413 printf (" &operand_data[%d],\n", d
->operand_number
);
414 printf (" %d,\n", d
->n_generator_args
);
415 printf (" %d,\n", d
->n_operands
);
416 printf (" %d,\n", d
->n_dups
);
417 printf (" %d,\n", d
->n_alternatives
);
418 printf (" %d\n", d
->output_format
);
426 output_get_insn_name (void)
428 printf ("const char *\n");
429 printf ("get_insn_name (int code)\n");
431 printf (" if (code == NOOP_MOVE_INSN_CODE)\n");
432 printf (" return \"NOOP_MOVE\";\n");
434 printf (" return insn_data[code].name;\n");
439 /* Stores the operand data into `d->operand[i]'.
441 THIS_ADDRESS_P is nonzero if the containing rtx was an ADDRESS.
442 THIS_STRICT_LOW is nonzero if the containing rtx was a STRICT_LOW_PART. */
445 scan_operands (struct data
*d
, rtx part
, int this_address_p
,
449 const char *format_ptr
;
455 switch (GET_CODE (part
))
458 opno
= XINT (part
, 0);
459 if (opno
>= MAX_MAX_OPERANDS
)
461 error_with_line (d
->lineno
, "maximum number of operands exceeded");
464 if (d
->operand
[opno
].seen
)
465 error_with_line (d
->lineno
, "repeated operand number %d\n", opno
);
467 d
->operand
[opno
].seen
= 1;
468 d
->operand
[opno
].mode
= GET_MODE (part
);
469 d
->operand
[opno
].strict_low
= this_strict_low
;
470 d
->operand
[opno
].predicate
= XSTR (part
, 1);
471 d
->operand
[opno
].constraint
= strip_whitespace (XSTR (part
, 2));
472 d
->operand
[opno
].n_alternatives
473 = n_occurrences (',', d
->operand
[opno
].constraint
) + 1;
474 d
->operand
[opno
].address_p
= this_address_p
;
475 d
->operand
[opno
].eliminable
= 1;
479 opno
= XINT (part
, 0);
480 if (opno
>= MAX_MAX_OPERANDS
)
482 error_with_line (d
->lineno
, "maximum number of operands exceeded");
485 if (d
->operand
[opno
].seen
)
486 error_with_line (d
->lineno
, "repeated operand number %d\n", opno
);
488 d
->operand
[opno
].seen
= 1;
489 d
->operand
[opno
].mode
= GET_MODE (part
);
490 d
->operand
[opno
].strict_low
= 0;
491 d
->operand
[opno
].predicate
= "scratch_operand";
492 d
->operand
[opno
].constraint
= strip_whitespace (XSTR (part
, 1));
493 d
->operand
[opno
].n_alternatives
494 = n_occurrences (',', d
->operand
[opno
].constraint
) + 1;
495 d
->operand
[opno
].address_p
= 0;
496 d
->operand
[opno
].eliminable
= 0;
501 opno
= XINT (part
, 0);
502 if (opno
>= MAX_MAX_OPERANDS
)
504 error_with_line (d
->lineno
, "maximum number of operands exceeded");
507 if (d
->operand
[opno
].seen
)
508 error_with_line (d
->lineno
, "repeated operand number %d\n", opno
);
510 d
->operand
[opno
].seen
= 1;
511 d
->operand
[opno
].mode
= GET_MODE (part
);
512 d
->operand
[opno
].strict_low
= 0;
513 d
->operand
[opno
].predicate
= XSTR (part
, 1);
514 d
->operand
[opno
].constraint
= 0;
515 d
->operand
[opno
].address_p
= 0;
516 d
->operand
[opno
].eliminable
= 0;
517 for (i
= 0; i
< XVECLEN (part
, 2); i
++)
518 scan_operands (d
, XVECEXP (part
, 2, i
), 0, 0);
521 case STRICT_LOW_PART
:
522 scan_operands (d
, XEXP (part
, 0), 0, 1);
529 format_ptr
= GET_RTX_FORMAT (GET_CODE (part
));
531 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (part
)); i
++)
532 switch (*format_ptr
++)
536 scan_operands (d
, XEXP (part
, i
), 0, 0);
539 if (XVEC (part
, i
) != NULL
)
540 for (j
= 0; j
< XVECLEN (part
, i
); j
++)
541 scan_operands (d
, XVECEXP (part
, i
, j
), 0, 0);
546 /* Compare two operands for content equality. */
549 compare_operands (struct operand_data
*d0
, struct operand_data
*d1
)
559 if (strcmp (p0
, p1
) != 0)
568 if (strcmp (p0
, p1
) != 0)
571 if (d0
->mode
!= d1
->mode
)
574 if (d0
->strict_low
!= d1
->strict_low
)
577 if (d0
->eliminable
!= d1
->eliminable
)
583 /* Scan the list of operands we've already committed to output and either
584 find a subsequence that is the same, or allocate a new one at the end. */
587 place_operands (struct data
*d
)
589 struct operand_data
*od
, *od2
;
592 if (d
->n_operands
== 0)
594 d
->operand_number
= 0;
598 /* Brute force substring search. */
599 for (od
= odata
, i
= 0; od
; od
= od
->next
, i
= 0)
600 if (compare_operands (od
, &d
->operand
[0]))
606 if (i
== d
->n_operands
)
610 if (! compare_operands (od2
, &d
->operand
[i
]))
612 ++i
, od2
= od2
->next
;
616 /* Either partial match at the end of the list, or no match. In either
617 case, we tack on what operands are remaining to the end of the list. */
619 d
->operand_number
= next_operand_number
- i
;
620 for (; i
< d
->n_operands
; ++i
)
622 od2
= &d
->operand
[i
];
624 odata_end
= &od2
->next
;
625 od2
->index
= next_operand_number
++;
631 d
->operand_number
= od
->index
;
636 /* Process an assembler template from a define_insn or a define_peephole.
637 It is either the assembler code template, a list of assembler code
638 templates, or C code to generate the assembler code template. */
641 process_template (struct data
*d
, const char *template_code
)
646 /* Templates starting with * contain straight code to be run. */
647 if (template_code
[0] == '*')
649 d
->template_code
= 0;
650 d
->output_format
= INSN_OUTPUT_FORMAT_FUNCTION
;
652 puts ("\nstatic const char *");
653 printf ("output_%d (rtx *operands ATTRIBUTE_UNUSED, rtx insn ATTRIBUTE_UNUSED)\n",
656 print_md_ptr_loc (template_code
);
657 puts (template_code
+ 1);
661 /* If the assembler code template starts with a @ it is a newline-separated
662 list of assembler code templates, one for each alternative. */
663 else if (template_code
[0] == '@')
667 for (cp
= &template_code
[1]; *cp
; )
669 while (ISSPACE (*cp
))
673 while (!IS_VSPACE (*cp
) && *cp
!= '\0')
676 d
->template_code
= 0;
679 d
->output_format
= INSN_OUTPUT_FORMAT_FUNCTION
;
680 puts ("\nstatic const char *");
681 printf ("output_%d (rtx *operands ATTRIBUTE_UNUSED, "
682 "rtx insn ATTRIBUTE_UNUSED)\n", d
->code_number
);
684 puts (" switch (which_alternative)\n {");
688 d
->output_format
= INSN_OUTPUT_FORMAT_MULTI
;
689 printf ("\nstatic const char * const output_%d[] = {\n",
693 for (i
= 0, cp
= &template_code
[1]; *cp
; )
695 const char *ep
, *sp
, *bp
;
697 while (ISSPACE (*cp
))
703 printf (" case %d:", i
);
710 printf (" return \"");
715 for (ep
= sp
= cp
; !IS_VSPACE (*ep
) && *ep
!= '\0'; ++ep
)
720 message_with_line (d
->lineno
,
721 "trailing whitespace in output template");
735 /* The usual action will end with a return.
736 If there is neither break or return at the end, this is
737 assumed to be intentional; this allows to have multiple
738 consecutive alternatives share some code. */
744 message_with_line (d
->lineno
,
745 "'@' is redundant for output template with single alternative");
746 if (i
!= d
->n_alternatives
)
747 error_with_line (d
->lineno
,
748 "wrong number of alternatives in the output template");
751 puts (" default: gcc_unreachable ();\n }\n}");
757 d
->template_code
= template_code
;
758 d
->output_format
= INSN_OUTPUT_FORMAT_SINGLE
;
762 /* Check insn D for consistency in number of constraint alternatives. */
765 validate_insn_alternatives (struct data
*d
)
769 /* Make sure all the operands have the same number of alternatives
770 in their constraints. Let N be that number. */
771 for (start
= 0; start
< d
->n_operands
; start
++)
772 if (d
->operand
[start
].n_alternatives
> 0)
777 int which_alternative
= 0;
778 int alternative_count_unsure
= 0;
780 for (p
= d
->operand
[start
].constraint
; (c
= *p
); p
+= len
)
782 #ifdef USE_MD_CONSTRAINTS
783 if (ISSPACE (c
) || strchr (indep_constraints
, c
))
785 else if (ISDIGIT (c
))
790 while (ISDIGIT (*q
));
794 len
= mdep_constraint_len (p
, d
->lineno
, start
);
796 len
= CONSTRAINT_LEN (c
, p
);
798 if (len
< 1 || (len
> 1 && strchr (",#*+=&%!0123456789", c
)))
800 error_with_line (d
->lineno
,
801 "invalid length %d for char '%c' in"
802 " alternative %d of operand %d",
803 len
, c
, which_alternative
, start
);
814 for (i
= 1; i
< len
; i
++)
817 error_with_line (d
->lineno
,
818 "NUL in alternative %d of operand %d",
819 which_alternative
, start
);
820 alternative_count_unsure
= 1;
823 else if (strchr (",#*", p
[i
]))
825 error_with_line (d
->lineno
,
826 "'%c' in alternative %d of operand %d",
827 p
[i
], which_alternative
, start
);
828 alternative_count_unsure
= 1;
831 if (!alternative_count_unsure
)
834 n
= d
->operand
[start
].n_alternatives
;
835 else if (n
!= d
->operand
[start
].n_alternatives
)
836 error_with_line (d
->lineno
,
837 "wrong number of alternatives in operand %d",
842 /* Record the insn's overall number of alternatives. */
843 d
->n_alternatives
= n
;
846 /* Verify that there are no gaps in operand numbers for INSNs. */
849 validate_insn_operands (struct data
*d
)
853 for (i
= 0; i
< d
->n_operands
; ++i
)
854 if (d
->operand
[i
].seen
== 0)
855 error_with_line (d
->lineno
, "missing operand %d", i
);
859 validate_optab_operands (struct data
*d
)
861 if (!d
->name
|| d
->name
[0] == '\0' || d
->name
[0] == '*')
864 /* Miscellaneous tests. */
865 if (strncmp (d
->name
, "cstore", 6) == 0
866 && d
->name
[strlen (d
->name
) - 1] == '4'
867 && d
->operand
[0].mode
== VOIDmode
)
869 message_with_line (d
->lineno
, "missing mode for operand 0 of cstore");
874 /* Look at a define_insn just read. Assign its code number. Record
875 on idata the template and the number of arguments. If the insn has
876 a hairy output action, output a function for now. */
879 gen_insn (rtx insn
, int lineno
)
881 struct pattern_stats stats
;
882 struct data
*d
= XNEW (struct data
);
885 d
->code_number
= next_code_number
;
886 d
->index_number
= next_index_number
;
887 d
->filename
= read_md_filename
;
889 if (XSTR (insn
, 0)[0])
890 d
->name
= XSTR (insn
, 0);
894 /* Build up the list in the same order as the insns are seen
895 in the machine description. */
898 idata_end
= &d
->next
;
900 memset (d
->operand
, 0, sizeof (d
->operand
));
902 for (i
= 0; i
< XVECLEN (insn
, 1); i
++)
903 scan_operands (d
, XVECEXP (insn
, 1, i
), 0, 0);
905 get_pattern_stats (&stats
, XVEC (insn
, 1));
906 d
->n_generator_args
= stats
.num_generator_args
;
907 d
->n_operands
= stats
.num_insn_operands
;
908 d
->n_dups
= stats
.num_dups
;
910 #ifndef USE_MD_CONSTRAINTS
911 check_constraint_len ();
913 validate_insn_operands (d
);
914 validate_insn_alternatives (d
);
915 validate_optab_operands (d
);
917 process_template (d
, XTMPL (insn
, 3));
920 /* Look at a define_peephole just read. Assign its code number.
921 Record on idata the template and the number of arguments.
922 If the insn has a hairy output action, output it now. */
925 gen_peephole (rtx peep
, int lineno
)
927 struct pattern_stats stats
;
928 struct data
*d
= XNEW (struct data
);
931 d
->code_number
= next_code_number
;
932 d
->index_number
= next_index_number
;
933 d
->filename
= read_md_filename
;
937 /* Build up the list in the same order as the insns are seen
938 in the machine description. */
941 idata_end
= &d
->next
;
943 memset (d
->operand
, 0, sizeof (d
->operand
));
945 /* Get the number of operands by scanning all the patterns of the
946 peephole optimizer. But ignore all the rest of the information
948 for (i
= 0; i
< XVECLEN (peep
, 0); i
++)
949 scan_operands (d
, XVECEXP (peep
, 0, i
), 0, 0);
951 get_pattern_stats (&stats
, XVEC (peep
, 0));
952 d
->n_generator_args
= 0;
953 d
->n_operands
= stats
.num_insn_operands
;
956 validate_insn_alternatives (d
);
958 process_template (d
, XTMPL (peep
, 2));
961 /* Process a define_expand just read. Assign its code number,
962 only for the purposes of `insn_gen_function'. */
965 gen_expand (rtx insn
, int lineno
)
967 struct pattern_stats stats
;
968 struct data
*d
= XNEW (struct data
);
971 d
->code_number
= next_code_number
;
972 d
->index_number
= next_index_number
;
973 d
->filename
= read_md_filename
;
975 if (XSTR (insn
, 0)[0])
976 d
->name
= XSTR (insn
, 0);
980 /* Build up the list in the same order as the insns are seen
981 in the machine description. */
984 idata_end
= &d
->next
;
986 memset (d
->operand
, 0, sizeof (d
->operand
));
988 /* Scan the operands to get the specified predicates and modes,
989 since expand_binop needs to know them. */
992 for (i
= 0; i
< XVECLEN (insn
, 1); i
++)
993 scan_operands (d
, XVECEXP (insn
, 1, i
), 0, 0);
995 get_pattern_stats (&stats
, XVEC (insn
, 1));
996 d
->n_generator_args
= stats
.num_generator_args
;
997 d
->n_operands
= stats
.num_insn_operands
;
998 d
->n_dups
= stats
.num_dups
;
999 d
->template_code
= 0;
1000 d
->output_format
= INSN_OUTPUT_FORMAT_NONE
;
1002 validate_insn_alternatives (d
);
1003 validate_optab_operands (d
);
1007 /* Process a define_split just read. Assign its code number,
1008 only for reasons of consistency and to simplify genrecog. */
1011 gen_split (rtx split
, int lineno
)
1013 struct pattern_stats stats
;
1014 struct data
*d
= XNEW (struct data
);
1017 d
->code_number
= next_code_number
;
1018 d
->index_number
= next_index_number
;
1019 d
->filename
= read_md_filename
;
1023 /* Build up the list in the same order as the insns are seen
1024 in the machine description. */
1027 idata_end
= &d
->next
;
1029 memset (d
->operand
, 0, sizeof (d
->operand
));
1031 /* Get the number of operands by scanning all the patterns of the
1032 split patterns. But ignore all the rest of the information thus
1034 for (i
= 0; i
< XVECLEN (split
, 0); i
++)
1035 scan_operands (d
, XVECEXP (split
, 0, i
), 0, 0);
1037 get_pattern_stats (&stats
, XVEC (split
, 0));
1038 d
->n_generator_args
= 0;
1039 d
->n_operands
= stats
.num_insn_operands
;
1041 d
->n_alternatives
= 0;
1042 d
->template_code
= 0;
1043 d
->output_format
= INSN_OUTPUT_FORMAT_NONE
;
1049 init_insn_for_nothing (void)
1051 memset (¬hing
, 0, sizeof (nothing
));
1052 nothing
.name
= "*placeholder_for_nothing";
1053 nothing
.filename
= "<internal>";
1056 extern int main (int, char **);
1059 main (int argc
, char **argv
)
1063 progname
= "genoutput";
1065 init_insn_for_nothing ();
1067 if (!init_rtx_reader_args (argc
, argv
))
1068 return (FATAL_EXIT_CODE
);
1071 next_index_number
= 0;
1073 /* Read the machine description. */
1079 desc
= read_md_rtx (&line_no
, &next_code_number
);
1083 switch (GET_CODE (desc
))
1086 gen_insn (desc
, line_no
);
1089 case DEFINE_PEEPHOLE
:
1090 gen_peephole (desc
, line_no
);
1094 gen_expand (desc
, line_no
);
1098 case DEFINE_PEEPHOLE2
:
1099 gen_split (desc
, line_no
);
1102 #ifdef USE_MD_CONSTRAINTS
1103 case DEFINE_CONSTRAINT
:
1104 case DEFINE_REGISTER_CONSTRAINT
:
1105 case DEFINE_ADDRESS_CONSTRAINT
:
1106 case DEFINE_MEMORY_CONSTRAINT
:
1107 note_constraint (desc
, line_no
);
1114 next_index_number
++;
1118 output_operand_data ();
1119 output_insn_data ();
1120 output_get_insn_name ();
1123 return (ferror (stdout
) != 0 || have_error
1124 ? FATAL_EXIT_CODE
: SUCCESS_EXIT_CODE
);
1127 /* Return the number of occurrences of character C in string S or
1128 -1 if S is the null string. */
1131 n_occurrences (int c
, const char *s
)
1135 if (s
== 0 || *s
== '\0')
1144 /* Remove whitespace in `s' by moving up characters until the end.
1145 Return a new string. */
1148 strip_whitespace (const char *s
)
1156 p
= q
= XNEWVEC (char, strlen (s
) + 1);
1157 while ((ch
= *s
++) != '\0')
1165 #ifdef USE_MD_CONSTRAINTS
1167 /* Record just enough information about a constraint to allow checking
1168 of operand constraint strings above, in validate_insn_alternatives.
1169 Does not validate most properties of the constraint itself; does
1170 enforce no duplicate names, no overlap with MI constraints, and no
1171 prefixes. EXP is the define_*constraint form, LINENO the line number
1172 reported by the reader. */
1174 note_constraint (rtx exp
, int lineno
)
1176 const char *name
= XSTR (exp
, 0);
1177 unsigned int namelen
= strlen (name
);
1178 struct constraint_data
**iter
, **slot
, *new_cdata
;
1180 /* The 'm' constraint is special here since that constraint letter
1181 can be overridden by the back end by defining the
1182 TARGET_MEM_CONSTRAINT macro. */
1183 if (strchr (indep_constraints
, name
[0]) && name
[0] != 'm')
1185 if (name
[1] == '\0')
1186 error_with_line (lineno
, "constraint letter '%s' cannot be "
1187 "redefined by the machine description", name
);
1189 error_with_line (lineno
, "constraint name '%s' cannot be defined by "
1190 "the machine description, as it begins with '%c'",
1195 slot
= &constraints_by_letter_table
[(unsigned int)name
[0]];
1196 for (iter
= slot
; *iter
; iter
= &(*iter
)->next_this_letter
)
1198 /* This causes slot to end up pointing to the
1199 next_this_letter field of the last constraint with a name
1200 of equal or greater length than the new constraint; hence
1201 the new constraint will be inserted after all previous
1202 constraints with names of the same length. */
1203 if ((*iter
)->namelen
>= namelen
)
1206 if (!strcmp ((*iter
)->name
, name
))
1208 error_with_line (lineno
, "redefinition of constraint '%s'", name
);
1209 message_with_line ((*iter
)->lineno
, "previous definition is here");
1212 else if (!strncmp ((*iter
)->name
, name
, (*iter
)->namelen
))
1214 error_with_line (lineno
, "defining constraint '%s' here", name
);
1215 message_with_line ((*iter
)->lineno
, "renders constraint '%s' "
1216 "(defined here) a prefix", (*iter
)->name
);
1219 else if (!strncmp ((*iter
)->name
, name
, namelen
))
1221 error_with_line (lineno
, "constraint '%s' is a prefix", name
);
1222 message_with_line ((*iter
)->lineno
, "of constraint '%s' "
1223 "(defined here)", (*iter
)->name
);
1227 new_cdata
= XNEWVAR (struct constraint_data
, sizeof (struct constraint_data
) + namelen
);
1228 strcpy (CONST_CAST(char *, new_cdata
->name
), name
);
1229 new_cdata
->namelen
= namelen
;
1230 new_cdata
->lineno
= lineno
;
1231 new_cdata
->next_this_letter
= *slot
;
1235 /* Return the length of the constraint name beginning at position S
1236 of an operand constraint string, or issue an error message if there
1237 is no such constraint. Does not expect to be called for generic
1240 mdep_constraint_len (const char *s
, int lineno
, int opno
)
1242 struct constraint_data
*p
;
1244 p
= constraints_by_letter_table
[(unsigned int)s
[0]];
1247 for (; p
; p
= p
->next_this_letter
)
1248 if (!strncmp (s
, p
->name
, p
->namelen
))
1251 error_with_line (lineno
,
1252 "error: undefined machine-specific constraint "
1253 "at this point: \"%s\"", s
);
1254 message_with_line (lineno
, "note: in operand %d", opno
);
1255 return 1; /* safe */
1259 /* Verify that DEFAULT_CONSTRAINT_LEN is used properly and not
1260 tampered with. This isn't bullet-proof, but it should catch
1261 most genuine mistakes. */
1263 check_constraint_len (void)
1268 for (p
= ",#*+=&%!1234567890"; *p
; p
++)
1269 for (d
= -9; d
< 9; d
++)
1270 gcc_assert (constraint_len (p
, d
) == d
);
1274 constraint_len (const char *p
, int genoutput_default_constraint_len
)
1276 /* Check that we still match defaults.h . First we do a generation-time
1277 check that fails if the value is not the expected one... */
1278 gcc_assert (DEFAULT_CONSTRAINT_LEN (*p
, p
) == 1);
1279 /* And now a compile-time check that should give a diagnostic if the
1280 definition doesn't exactly match. */
1281 #define DEFAULT_CONSTRAINT_LEN(C,STR) 1
1282 /* Now re-define DEFAULT_CONSTRAINT_LEN so that we can verify it is
1284 #undef DEFAULT_CONSTRAINT_LEN
1285 #define DEFAULT_CONSTRAINT_LEN(C,STR) \
1286 ((C) != *p || STR != p ? -1 : genoutput_default_constraint_len)
1287 return CONSTRAINT_LEN (*p
, p
);
1288 /* And set it back. */
1289 #undef DEFAULT_CONSTRAINT_LEN
1290 #define DEFAULT_CONSTRAINT_LEN(C,STR) 1