1 /* Generate code from to output assembler insns as recognized from rtl.
2 Copyright (C) 1987-2018 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
21 /* This program reads the machine description for the compiler target machine
22 and produces a file containing these things:
24 1. An array of `struct insn_data_d', which is indexed by insn code number,
27 a. `name' is the name for that pattern. Nameless patterns are
30 b. `output' hold either the output template, an array of output
31 templates, or an output function.
33 c. `genfun' is the function to generate a body for that pattern,
34 given operands as arguments.
36 d. `n_operands' is the number of distinct operands in the pattern
39 e. `n_dups' is the number of match_dup's that appear in the insn's
40 pattern. This says how many elements of `recog_data.dup_loc' are
41 significant after an insn has been recognized.
43 f. `n_alternatives' is the number of alternatives in the constraints
46 g. `output_format' tells what type of thing `output' is.
48 h. `operand' is the base of an array of operand data for the insn.
50 2. An array of `struct insn_operand data', used by `operand' above.
52 a. `predicate', an int-valued function, is the match_operand predicate
55 b. `constraint' is the constraint for this operand.
57 c. `address_p' indicates that the operand appears within ADDRESS
60 d. `mode' is the machine mode that that operand is supposed to have.
62 e. `strict_low', is nonzero for operands contained in a STRICT_LOW_PART.
64 f. `eliminable', is nonzero for operands that are matched normally by
65 MATCH_OPERAND; it is zero for operands that should not be changed during
66 register elimination such as MATCH_OPERATORs.
68 g. `allows_mem', is true for operands that accept MEM rtxes.
70 The code number of an insn is simply its position in the machine
71 description; code numbers are assigned sequentially to entries in
72 the description, starting with code number 0.
74 Thus, the following entry in the machine description
77 [(set (match_operand:DF 0 "general_operand" "")
82 assuming it is the 25th entry present, would cause
83 insn_data[24].template to be "clrd %0", and
84 insn_data[24].n_operands to be 1. */
88 #include "coretypes.h"
93 #include "gensupport.h"
95 /* No instruction can have more operands than this. Sorry for this
96 arbitrary limit, but what machine will have an instruction with
97 this many operands? */
99 #define MAX_MAX_OPERANDS 40
101 static char general_mem
[] = { TARGET_MEM_CONSTRAINT
, 0 };
103 static int n_occurrences (int, const char *);
104 static const char *strip_whitespace (const char *);
106 /* This counts all operands used in the md file. The first is null. */
108 static int next_operand_number
= 1;
110 /* Record in this chain all information about the operands we will output. */
114 struct operand_data
*next
;
116 const char *predicate
;
117 const char *constraint
;
119 unsigned char n_alternatives
;
126 /* Begin with a null operand at index 0. */
128 static struct operand_data null_operand
=
130 0, 0, "", "", E_VOIDmode
, 0, 0, 0, 0, 0
133 static struct operand_data
*odata
= &null_operand
;
134 static struct operand_data
**odata_end
= &null_operand
.next
;
136 /* Must match the constants in recog.h. */
138 #define INSN_OUTPUT_FORMAT_NONE 0 /* abort */
139 #define INSN_OUTPUT_FORMAT_SINGLE 1 /* const char * */
140 #define INSN_OUTPUT_FORMAT_MULTI 2 /* const char * const * */
141 #define INSN_OUTPUT_FORMAT_FUNCTION 3 /* const char * (*)(...) */
143 /* Record in this chain all information that we will output,
144 associated with the code number of the insn. */
150 const char *template_code
;
153 int n_generator_args
; /* Number of arguments passed to generator */
154 int n_operands
; /* Number of operands this insn recognizes */
155 int n_dups
; /* Number times match_dup appears in pattern */
156 int n_alternatives
; /* Number of alternatives in each constraint */
157 int operand_number
; /* Operand index in the big array. */
158 int output_format
; /* INSN_OUTPUT_FORMAT_*. */
159 struct operand_data operand
[MAX_MAX_OPERANDS
];
162 /* This variable points to the first link in the insn chain. */
163 static struct data
*idata
;
165 /* This variable points to the end of the insn chain. This is where
166 everything relevant from the machien description is appended to. */
167 static struct data
**idata_end
;
170 static void output_prologue (void);
171 static void output_operand_data (void);
172 static void output_insn_data (void);
173 static void output_get_insn_name (void);
174 static void scan_operands (struct data
*, rtx
, int, int);
175 static int compare_operands (struct operand_data
*,
176 struct operand_data
*);
177 static void place_operands (struct data
*);
178 static void process_template (struct data
*, const char *);
179 static void validate_insn_alternatives (struct data
*);
180 static void validate_insn_operands (struct data
*);
182 struct constraint_data
184 struct constraint_data
*next_this_letter
;
186 unsigned int namelen
;
190 /* All machine-independent constraint characters (except digits) that
191 are handled outside the define*_constraint mechanism. */
192 static const char indep_constraints
[] = ",=+%*?!^$#&g";
194 static struct constraint_data
*
195 constraints_by_letter_table
[1 << CHAR_BIT
];
197 static int mdep_constraint_len (const char *, file_location
, int);
198 static void note_constraint (md_rtx_info
*);
201 output_prologue (void)
203 printf ("/* Generated automatically by the program `genoutput'\n\
204 from the machine description file `md'. */\n\n");
206 printf ("#define IN_TARGET_CODE 1\n");
207 printf ("#include \"config.h\"\n");
208 printf ("#include \"system.h\"\n");
209 printf ("#include \"coretypes.h\"\n");
210 printf ("#include \"backend.h\"\n");
211 printf ("#include \"predict.h\"\n");
212 printf ("#include \"tree.h\"\n");
213 printf ("#include \"rtl.h\"\n");
214 printf ("#include \"flags.h\"\n");
215 printf ("#include \"alias.h\"\n");
216 printf ("#include \"varasm.h\"\n");
217 printf ("#include \"stor-layout.h\"\n");
218 printf ("#include \"calls.h\"\n");
219 printf ("#include \"insn-config.h\"\n");
220 printf ("#include \"expmed.h\"\n");
221 printf ("#include \"dojump.h\"\n");
222 printf ("#include \"explow.h\"\n");
223 printf ("#include \"memmodel.h\"\n");
224 printf ("#include \"emit-rtl.h\"\n");
225 printf ("#include \"stmt.h\"\n");
226 printf ("#include \"expr.h\"\n");
227 printf ("#include \"insn-codes.h\"\n");
228 printf ("#include \"tm_p.h\"\n");
229 printf ("#include \"regs.h\"\n");
230 printf ("#include \"conditions.h\"\n");
231 printf ("#include \"insn-attr.h\"\n\n");
232 printf ("#include \"recog.h\"\n\n");
233 printf ("#include \"diagnostic-core.h\"\n");
234 printf ("#include \"output.h\"\n");
235 printf ("#include \"target.h\"\n");
236 printf ("#include \"tm-constrs.h\"\n");
240 output_operand_data (void)
242 struct operand_data
*d
;
244 printf ("\nstatic const struct insn_operand_data operand_data[] = \n{\n");
246 for (d
= odata
; d
; d
= d
->next
)
248 struct pred_data
*pred
;
253 d
->predicate
&& d
->predicate
[0] ? d
->predicate
: "0");
255 printf (" \"%s\",\n", d
->constraint
? d
->constraint
: "");
257 printf (" E_%smode,\n", GET_MODE_NAME (d
->mode
));
259 printf (" %d,\n", d
->strict_low
);
261 printf (" %d,\n", d
->constraint
== NULL
? 1 : 0);
263 printf (" %d,\n", d
->eliminable
);
267 pred
= lookup_predicate (d
->predicate
);
268 printf (" %d\n", pred
&& pred
->codes
[MEM
]);
276 output_insn_data (void)
280 int next_name_offset
;
281 const char * last_name
= 0;
282 const char * next_name
= 0;
285 for (n
= idata
, next_name_offset
= 1; n
; n
= n
->next
, next_name_offset
++)
292 printf ("#if GCC_VERSION >= 2007\n__extension__\n#endif\n");
293 printf ("\nconst struct insn_data_d insn_data[] = \n{\n");
295 for (d
= idata
; d
; d
= d
->next
)
297 printf (" /* %s:%d */\n", d
->loc
.filename
, d
->loc
.lineno
);
302 printf (" \"%s\",\n", d
->name
);
306 for (n
= d
->next
, next_name_offset
= 1; n
;
307 n
= n
->next
, next_name_offset
++)
319 if (next_name
&& (last_name
== 0
320 || name_offset
> next_name_offset
/ 2))
321 printf (" \"%s-%d\",\n", next_name
,
322 next_name_offset
- name_offset
);
324 printf (" \"%s+%d\",\n", last_name
, name_offset
);
327 switch (d
->output_format
)
329 case INSN_OUTPUT_FORMAT_NONE
:
330 printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n");
331 printf (" { 0 },\n");
333 printf (" { 0, 0, 0 },\n");
336 case INSN_OUTPUT_FORMAT_SINGLE
:
338 const char *p
= d
->template_code
;
341 printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n");
342 printf (" { .single =\n");
349 if (IS_VSPACE (*p
) && prev
!= '\\')
351 /* Preserve two consecutive \n's or \r's, but treat \r\n
352 as a single newline. */
353 if (*p
== '\n' && prev
!= '\r')
362 printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n");
365 printf (" 0, 0 },\n");
369 case INSN_OUTPUT_FORMAT_MULTI
:
370 printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n");
371 printf (" { .multi = output_%d },\n", d
->code_number
);
373 printf (" { 0, output_%d, 0 },\n", d
->code_number
);
376 case INSN_OUTPUT_FORMAT_FUNCTION
:
377 printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n");
378 printf (" { .function = output_%d },\n", d
->code_number
);
380 printf (" { 0, 0, output_%d },\n", d
->code_number
);
387 if (d
->name
&& d
->name
[0] != '*')
388 printf (" { (insn_gen_fn::stored_funcptr) gen_%s },\n", d
->name
);
390 printf (" { 0 },\n");
392 printf (" &operand_data[%d],\n", d
->operand_number
);
393 printf (" %d,\n", d
->n_generator_args
);
394 printf (" %d,\n", d
->n_operands
);
395 printf (" %d,\n", d
->n_dups
);
396 printf (" %d,\n", d
->n_alternatives
);
397 printf (" %d\n", d
->output_format
);
405 output_get_insn_name (void)
407 printf ("const char *\n");
408 printf ("get_insn_name (int code)\n");
410 printf (" if (code == NOOP_MOVE_INSN_CODE)\n");
411 printf (" return \"NOOP_MOVE\";\n");
413 printf (" return insn_data[code].name;\n");
418 /* Stores the operand data into `d->operand[i]'.
420 THIS_ADDRESS_P is nonzero if the containing rtx was an ADDRESS.
421 THIS_STRICT_LOW is nonzero if the containing rtx was a STRICT_LOW_PART. */
424 scan_operands (struct data
*d
, rtx part
, int this_address_p
,
428 const char *format_ptr
;
434 switch (GET_CODE (part
))
437 opno
= XINT (part
, 0);
438 if (opno
>= MAX_MAX_OPERANDS
)
440 error_at (d
->loc
, "maximum number of operands exceeded");
443 if (d
->operand
[opno
].seen
)
444 error_at (d
->loc
, "repeated operand number %d\n", opno
);
446 d
->operand
[opno
].seen
= 1;
447 d
->operand
[opno
].mode
= GET_MODE (part
);
448 d
->operand
[opno
].strict_low
= this_strict_low
;
449 d
->operand
[opno
].predicate
= XSTR (part
, 1);
450 d
->operand
[opno
].constraint
= strip_whitespace (XSTR (part
, 2));
451 d
->operand
[opno
].n_alternatives
452 = n_occurrences (',', d
->operand
[opno
].constraint
) + 1;
453 d
->operand
[opno
].address_p
= this_address_p
;
454 d
->operand
[opno
].eliminable
= 1;
458 opno
= XINT (part
, 0);
459 if (opno
>= MAX_MAX_OPERANDS
)
461 error_at (d
->loc
, "maximum number of operands exceeded");
464 if (d
->operand
[opno
].seen
)
465 error_at (d
->loc
, "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
= 0;
470 d
->operand
[opno
].predicate
= "scratch_operand";
471 d
->operand
[opno
].constraint
= strip_whitespace (XSTR (part
, 1));
472 d
->operand
[opno
].n_alternatives
473 = n_occurrences (',', d
->operand
[opno
].constraint
) + 1;
474 d
->operand
[opno
].address_p
= 0;
475 d
->operand
[opno
].eliminable
= 0;
480 opno
= XINT (part
, 0);
481 if (opno
>= MAX_MAX_OPERANDS
)
483 error_at (d
->loc
, "maximum number of operands exceeded");
486 if (d
->operand
[opno
].seen
)
487 error_at (d
->loc
, "repeated operand number %d\n", opno
);
489 d
->operand
[opno
].seen
= 1;
490 d
->operand
[opno
].mode
= GET_MODE (part
);
491 d
->operand
[opno
].strict_low
= 0;
492 d
->operand
[opno
].predicate
= XSTR (part
, 1);
493 d
->operand
[opno
].constraint
= 0;
494 d
->operand
[opno
].address_p
= 0;
495 d
->operand
[opno
].eliminable
= 0;
496 for (i
= 0; i
< XVECLEN (part
, 2); i
++)
497 scan_operands (d
, XVECEXP (part
, 2, i
), 0, 0);
500 case STRICT_LOW_PART
:
501 scan_operands (d
, XEXP (part
, 0), 0, 1);
508 format_ptr
= GET_RTX_FORMAT (GET_CODE (part
));
510 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (part
)); i
++)
511 switch (*format_ptr
++)
515 scan_operands (d
, XEXP (part
, i
), 0, 0);
518 if (XVEC (part
, i
) != NULL
)
519 for (j
= 0; j
< XVECLEN (part
, i
); j
++)
520 scan_operands (d
, XVECEXP (part
, i
, j
), 0, 0);
525 /* Compare two operands for content equality. */
528 compare_operands (struct operand_data
*d0
, struct operand_data
*d1
)
538 if (strcmp (p0
, p1
) != 0)
547 if (strcmp (p0
, p1
) != 0)
550 if (d0
->mode
!= d1
->mode
)
553 if (d0
->strict_low
!= d1
->strict_low
)
556 if (d0
->eliminable
!= d1
->eliminable
)
562 /* Scan the list of operands we've already committed to output and either
563 find a subsequence that is the same, or allocate a new one at the end. */
566 place_operands (struct data
*d
)
568 struct operand_data
*od
, *od2
;
571 if (d
->n_operands
== 0)
573 d
->operand_number
= 0;
577 /* Brute force substring search. */
578 for (od
= odata
, i
= 0; od
; od
= od
->next
, i
= 0)
579 if (compare_operands (od
, &d
->operand
[0]))
585 if (i
== d
->n_operands
)
589 if (! compare_operands (od2
, &d
->operand
[i
]))
591 ++i
, od2
= od2
->next
;
595 /* Either partial match at the end of the list, or no match. In either
596 case, we tack on what operands are remaining to the end of the list. */
598 d
->operand_number
= next_operand_number
- i
;
599 for (; i
< d
->n_operands
; ++i
)
601 od2
= &d
->operand
[i
];
603 odata_end
= &od2
->next
;
604 od2
->index
= next_operand_number
++;
610 d
->operand_number
= od
->index
;
615 /* Process an assembler template from a define_insn or a define_peephole.
616 It is either the assembler code template, a list of assembler code
617 templates, or C code to generate the assembler code template. */
620 process_template (struct data
*d
, const char *template_code
)
625 /* Templates starting with * contain straight code to be run. */
626 if (template_code
[0] == '*')
628 d
->template_code
= 0;
629 d
->output_format
= INSN_OUTPUT_FORMAT_FUNCTION
;
631 puts ("\nstatic const char *");
632 printf ("output_%d (rtx *operands ATTRIBUTE_UNUSED, rtx_insn *insn ATTRIBUTE_UNUSED)\n",
635 rtx_reader_ptr
->print_md_ptr_loc (template_code
);
636 puts (template_code
+ 1);
640 /* If the assembler code template starts with a @ it is a newline-separated
641 list of assembler code templates, one for each alternative. */
642 else if (template_code
[0] == '@')
646 for (cp
= &template_code
[1]; *cp
; )
648 while (ISSPACE (*cp
))
652 while (!IS_VSPACE (*cp
) && *cp
!= '\0')
655 d
->template_code
= 0;
658 d
->output_format
= INSN_OUTPUT_FORMAT_FUNCTION
;
659 puts ("\nstatic const char *");
660 printf ("output_%d (rtx *operands ATTRIBUTE_UNUSED, "
661 "rtx_insn *insn ATTRIBUTE_UNUSED)\n", d
->code_number
);
663 puts (" switch (which_alternative)\n {");
667 d
->output_format
= INSN_OUTPUT_FORMAT_MULTI
;
668 printf ("\nstatic const char * const output_%d[] = {\n",
672 for (i
= 0, cp
= &template_code
[1]; *cp
; )
674 const char *ep
, *sp
, *bp
;
676 while (ISSPACE (*cp
))
682 printf (" case %d:", i
);
689 printf (" return \"");
694 for (ep
= sp
= cp
; !IS_VSPACE (*ep
) && *ep
!= '\0'; ++ep
)
699 message_at (d
->loc
, "trailing whitespace in output template");
713 /* The usual action will end with a return.
714 If there is neither break or return at the end, this is
715 assumed to be intentional; this allows to have multiple
716 consecutive alternatives share some code. */
722 message_at (d
->loc
, "'@' is redundant for output template with"
723 " single alternative");
724 if (i
!= d
->n_alternatives
)
725 error_at (d
->loc
, "wrong number of alternatives in the output"
729 puts (" default: gcc_unreachable ();\n }\n}");
735 d
->template_code
= template_code
;
736 d
->output_format
= INSN_OUTPUT_FORMAT_SINGLE
;
740 /* Check insn D for consistency in number of constraint alternatives. */
743 validate_insn_alternatives (struct data
*d
)
747 /* Make sure all the operands have the same number of alternatives
748 in their constraints. Let N be that number. */
749 for (start
= 0; start
< d
->n_operands
; start
++)
750 if (d
->operand
[start
].n_alternatives
> 0)
755 int which_alternative
= 0;
756 int alternative_count_unsure
= 0;
757 bool seen_write
= false;
759 for (p
= d
->operand
[start
].constraint
; (c
= *p
); p
+= len
)
761 if ((c
== '%' || c
== '=' || c
== '+')
762 && p
!= d
->operand
[start
].constraint
)
763 error_at (d
->loc
, "character '%c' can only be used at the"
764 " beginning of a constraint string", c
);
766 if (c
== '=' || c
== '+')
769 /* Earlyclobber operands must always be marked write-only
771 if (!seen_write
&& c
== '&')
772 error_at (d
->loc
, "earlyclobber operands may not be"
773 " read-only in alternative %d", which_alternative
);
775 if (ISSPACE (c
) || strchr (indep_constraints
, c
))
777 else if (ISDIGIT (c
))
782 while (ISDIGIT (*q
));
786 len
= mdep_constraint_len (p
, d
->loc
, start
);
794 for (i
= 1; i
< len
; i
++)
797 error_at (d
->loc
, "NUL in alternative %d of operand %d",
798 which_alternative
, start
);
799 alternative_count_unsure
= 1;
802 else if (strchr (",#*", p
[i
]))
804 error_at (d
->loc
, "'%c' in alternative %d of operand %d",
805 p
[i
], which_alternative
, start
);
806 alternative_count_unsure
= 1;
809 if (!alternative_count_unsure
)
812 n
= d
->operand
[start
].n_alternatives
;
813 else if (n
!= d
->operand
[start
].n_alternatives
)
814 error_at (d
->loc
, "wrong number of alternatives in operand %d",
819 /* Record the insn's overall number of alternatives. */
820 d
->n_alternatives
= n
;
823 /* Verify that there are no gaps in operand numbers for INSNs. */
826 validate_insn_operands (struct data
*d
)
830 for (i
= 0; i
< d
->n_operands
; ++i
)
831 if (d
->operand
[i
].seen
== 0)
832 error_at (d
->loc
, "missing operand %d", i
);
836 validate_optab_operands (struct data
*d
)
838 if (!d
->name
|| d
->name
[0] == '\0' || d
->name
[0] == '*')
841 /* Miscellaneous tests. */
842 if (strncmp (d
->name
, "cstore", 6) == 0
843 && d
->name
[strlen (d
->name
) - 1] == '4'
844 && d
->operand
[0].mode
== VOIDmode
)
846 message_at (d
->loc
, "missing mode for operand 0 of cstore");
851 /* Look at a define_insn just read. Assign its code number. Record
852 on idata the template and the number of arguments. If the insn has
853 a hairy output action, output a function for now. */
856 gen_insn (md_rtx_info
*info
)
858 struct pattern_stats stats
;
859 rtx insn
= info
->def
;
863 d
->code_number
= info
->index
;
865 if (XSTR (insn
, 0)[0])
866 d
->name
= XSTR (insn
, 0);
870 /* Build up the list in the same order as the insns are seen
871 in the machine description. */
874 idata_end
= &d
->next
;
876 memset (d
->operand
, 0, sizeof (d
->operand
));
878 for (i
= 0; i
< XVECLEN (insn
, 1); i
++)
879 scan_operands (d
, XVECEXP (insn
, 1, i
), 0, 0);
881 get_pattern_stats (&stats
, XVEC (insn
, 1));
882 d
->n_generator_args
= stats
.num_generator_args
;
883 d
->n_operands
= stats
.num_insn_operands
;
884 d
->n_dups
= stats
.num_dups
;
886 validate_insn_operands (d
);
887 validate_insn_alternatives (d
);
888 validate_optab_operands (d
);
890 process_template (d
, XTMPL (insn
, 3));
893 /* Look at a define_peephole just read. Assign its code number.
894 Record on idata the template and the number of arguments.
895 If the insn has a hairy output action, output it now. */
898 gen_peephole (md_rtx_info
*info
)
900 struct pattern_stats stats
;
904 d
->code_number
= info
->index
;
908 /* Build up the list in the same order as the insns are seen
909 in the machine description. */
912 idata_end
= &d
->next
;
914 memset (d
->operand
, 0, sizeof (d
->operand
));
916 /* Get the number of operands by scanning all the patterns of the
917 peephole optimizer. But ignore all the rest of the information
919 rtx peep
= info
->def
;
920 for (i
= 0; i
< XVECLEN (peep
, 0); i
++)
921 scan_operands (d
, XVECEXP (peep
, 0, i
), 0, 0);
923 get_pattern_stats (&stats
, XVEC (peep
, 0));
924 d
->n_generator_args
= 0;
925 d
->n_operands
= stats
.num_insn_operands
;
928 validate_insn_alternatives (d
);
930 process_template (d
, XTMPL (peep
, 2));
933 /* Process a define_expand just read. Assign its code number,
934 only for the purposes of `insn_gen_function'. */
937 gen_expand (md_rtx_info
*info
)
939 struct pattern_stats stats
;
940 rtx insn
= info
->def
;
944 d
->code_number
= info
->index
;
946 if (XSTR (insn
, 0)[0])
947 d
->name
= XSTR (insn
, 0);
951 /* Build up the list in the same order as the insns are seen
952 in the machine description. */
955 idata_end
= &d
->next
;
957 memset (d
->operand
, 0, sizeof (d
->operand
));
959 /* Scan the operands to get the specified predicates and modes,
960 since expand_binop needs to know them. */
963 for (i
= 0; i
< XVECLEN (insn
, 1); i
++)
964 scan_operands (d
, XVECEXP (insn
, 1, i
), 0, 0);
966 get_pattern_stats (&stats
, XVEC (insn
, 1));
967 d
->n_generator_args
= stats
.num_generator_args
;
968 d
->n_operands
= stats
.num_insn_operands
;
969 d
->n_dups
= stats
.num_dups
;
970 d
->template_code
= 0;
971 d
->output_format
= INSN_OUTPUT_FORMAT_NONE
;
973 validate_insn_alternatives (d
);
974 validate_optab_operands (d
);
979 init_insn_for_nothing (void)
981 idata
= XCNEW (struct data
);
983 idata
->name
= "*placeholder_for_nothing";
984 idata
->loc
= file_location ("<internal>", 0, 0);
985 idata_end
= &idata
->next
;
988 extern int main (int, const char **);
991 main (int argc
, const char **argv
)
993 progname
= "genoutput";
995 init_insn_for_nothing ();
997 if (!init_rtx_reader_args (argc
, argv
))
998 return (FATAL_EXIT_CODE
);
1002 /* Read the machine description. */
1005 while (read_md_rtx (&info
))
1006 switch (GET_CODE (info
.def
))
1012 case DEFINE_PEEPHOLE
:
1013 gen_peephole (&info
);
1020 case DEFINE_CONSTRAINT
:
1021 case DEFINE_REGISTER_CONSTRAINT
:
1022 case DEFINE_ADDRESS_CONSTRAINT
:
1023 case DEFINE_MEMORY_CONSTRAINT
:
1024 case DEFINE_SPECIAL_MEMORY_CONSTRAINT
:
1025 note_constraint (&info
);
1033 output_operand_data ();
1034 output_insn_data ();
1035 output_get_insn_name ();
1038 return (ferror (stdout
) != 0 || have_error
1039 ? FATAL_EXIT_CODE
: SUCCESS_EXIT_CODE
);
1042 /* Return the number of occurrences of character C in string S or
1043 -1 if S is the null string. */
1046 n_occurrences (int c
, const char *s
)
1050 if (s
== 0 || *s
== '\0')
1059 /* Remove whitespace in `s' by moving up characters until the end.
1060 Return a new string. */
1063 strip_whitespace (const char *s
)
1071 p
= q
= XNEWVEC (char, strlen (s
) + 1);
1072 while ((ch
= *s
++) != '\0')
1080 /* Record just enough information about the constraint in *INFO to allow
1081 checking of operand constraint strings above, in validate_insn_alternatives.
1082 Does not validate most properties of the constraint itself; does enforce
1083 no duplicate names, no overlap with MI constraints, and no prefixes. */
1085 note_constraint (md_rtx_info
*info
)
1087 rtx exp
= info
->def
;
1088 const char *name
= XSTR (exp
, 0);
1089 struct constraint_data
**iter
, **slot
, *new_cdata
;
1091 if (strcmp (name
, "TARGET_MEM_CONSTRAINT") == 0)
1093 unsigned int namelen
= strlen (name
);
1095 if (strchr (indep_constraints
, name
[0]))
1097 if (name
[1] == '\0')
1098 error_at (info
->loc
, "constraint letter '%s' cannot be "
1099 "redefined by the machine description", name
);
1101 error_at (info
->loc
, "constraint name '%s' cannot be defined by "
1102 "the machine description, as it begins with '%c'",
1107 slot
= &constraints_by_letter_table
[(unsigned int)name
[0]];
1108 for (iter
= slot
; *iter
; iter
= &(*iter
)->next_this_letter
)
1110 /* This causes slot to end up pointing to the
1111 next_this_letter field of the last constraint with a name
1112 of equal or greater length than the new constraint; hence
1113 the new constraint will be inserted after all previous
1114 constraints with names of the same length. */
1115 if ((*iter
)->namelen
>= namelen
)
1118 if (!strcmp ((*iter
)->name
, name
))
1120 error_at (info
->loc
, "redefinition of constraint '%s'", name
);
1121 message_at ((*iter
)->loc
, "previous definition is here");
1124 else if (!strncmp ((*iter
)->name
, name
, (*iter
)->namelen
))
1126 error_at (info
->loc
, "defining constraint '%s' here", name
);
1127 message_at ((*iter
)->loc
, "renders constraint '%s' "
1128 "(defined here) a prefix", (*iter
)->name
);
1131 else if (!strncmp ((*iter
)->name
, name
, namelen
))
1133 error_at (info
->loc
, "constraint '%s' is a prefix", name
);
1134 message_at ((*iter
)->loc
, "of constraint '%s' "
1135 "(defined here)", (*iter
)->name
);
1139 new_cdata
= XNEWVAR (struct constraint_data
,
1140 sizeof (struct constraint_data
) + namelen
);
1141 new (new_cdata
) constraint_data ();
1142 strcpy (CONST_CAST (char *, new_cdata
->name
), name
);
1143 new_cdata
->namelen
= namelen
;
1144 new_cdata
->loc
= info
->loc
;
1145 new_cdata
->next_this_letter
= *slot
;
1149 /* Return the length of the constraint name beginning at position S
1150 of an operand constraint string, or issue an error message if there
1151 is no such constraint. Does not expect to be called for generic
1154 mdep_constraint_len (const char *s
, file_location loc
, int opno
)
1156 struct constraint_data
*p
;
1158 p
= constraints_by_letter_table
[(unsigned int)s
[0]];
1161 for (; p
; p
= p
->next_this_letter
)
1162 if (!strncmp (s
, p
->name
, p
->namelen
))
1165 error_at (loc
, "error: undefined machine-specific constraint "
1166 "at this point: \"%s\"", s
);
1167 message_at (loc
, "note: in operand %d", opno
);
1168 return 1; /* safe */