1 /* Generate code from to output assembler insns as recognized from rtl.
2 Copyright (C) 1987-2014 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 int n_occurrences (int, const char *);
102 static const char *strip_whitespace (const char *);
104 /* insns in the machine description are assigned sequential code numbers
105 that are used by insn-recog.c (produced by genrecog) to communicate
106 to insn-output.c (produced by this program). */
108 static int next_code_number
;
110 /* This counts all definitions in the md file,
111 for the sake of error messages. */
113 static int next_index_number
;
115 /* This counts all operands used in the md file. The first is null. */
117 static int next_operand_number
= 1;
119 /* Record in this chain all information about the operands we will output. */
123 struct operand_data
*next
;
125 const char *predicate
;
126 const char *constraint
;
127 enum machine_mode mode
;
128 unsigned char n_alternatives
;
135 /* Begin with a null operand at index 0. */
137 static struct operand_data null_operand
=
139 0, 0, "", "", VOIDmode
, 0, 0, 0, 0, 0
142 static struct operand_data
*odata
= &null_operand
;
143 static struct operand_data
**odata_end
= &null_operand
.next
;
145 /* Must match the constants in recog.h. */
147 #define INSN_OUTPUT_FORMAT_NONE 0 /* abort */
148 #define INSN_OUTPUT_FORMAT_SINGLE 1 /* const char * */
149 #define INSN_OUTPUT_FORMAT_MULTI 2 /* const char * const * */
150 #define INSN_OUTPUT_FORMAT_FUNCTION 3 /* const char * (*)(...) */
152 /* Record in this chain all information that we will output,
153 associated with the code number of the insn. */
159 const char *template_code
;
162 const char *filename
;
164 int n_generator_args
; /* Number of arguments passed to generator */
165 int n_operands
; /* Number of operands this insn recognizes */
166 int n_dups
; /* Number times match_dup appears in pattern */
167 int n_alternatives
; /* Number of alternatives in each constraint */
168 int operand_number
; /* Operand index in the big array. */
169 int output_format
; /* INSN_OUTPUT_FORMAT_*. */
170 struct operand_data operand
[MAX_MAX_OPERANDS
];
173 /* A dummy insn, for CODE_FOR_nothing. */
174 static struct data nothing
;
176 /* This variable points to the first link in the insn chain. */
177 static struct data
*idata
= ¬hing
;
179 /* This variable points to the end of the insn chain. This is where
180 everything relevant from the machien description is appended to. */
181 static struct data
**idata_end
= ¬hing
.next
;
184 static void output_prologue (void);
185 static void output_operand_data (void);
186 static void output_insn_data (void);
187 static void output_get_insn_name (void);
188 static void scan_operands (struct data
*, rtx
, int, int);
189 static int compare_operands (struct operand_data
*,
190 struct operand_data
*);
191 static void place_operands (struct data
*);
192 static void process_template (struct data
*, const char *);
193 static void validate_insn_alternatives (struct data
*);
194 static void validate_insn_operands (struct data
*);
195 static void gen_insn (rtx
, int);
196 static void gen_peephole (rtx
, int);
197 static void gen_expand (rtx
, int);
198 static void gen_split (rtx
, int);
200 #ifdef USE_MD_CONSTRAINTS
202 struct constraint_data
204 struct constraint_data
*next_this_letter
;
206 unsigned int namelen
;
210 /* This is a complete list (unlike the one in genpreds.c) of constraint
211 letters and modifiers with machine-independent meaning. The only
212 omission is digits, as these are handled specially. */
213 static const char indep_constraints
[] = ",=+%*?!#&<>EFVXgimnoprs";
215 static struct constraint_data
*
216 constraints_by_letter_table
[1 << CHAR_BIT
];
218 static int mdep_constraint_len (const char *, int, int);
219 static void note_constraint (rtx
, int);
221 #else /* !USE_MD_CONSTRAINTS */
223 static void check_constraint_len (void);
224 static int constraint_len (const char *, int);
226 #endif /* !USE_MD_CONSTRAINTS */
230 output_prologue (void)
232 printf ("/* Generated automatically by the program `genoutput'\n\
233 from the machine description file `md'. */\n\n");
235 printf ("#include \"config.h\"\n");
236 printf ("#include \"system.h\"\n");
237 printf ("#include \"coretypes.h\"\n");
238 printf ("#include \"tm.h\"\n");
239 printf ("#include \"flags.h\"\n");
240 printf ("#include \"ggc.h\"\n");
241 printf ("#include \"tree.h\"\n");
242 printf ("#include \"varasm.h\"\n");
243 printf ("#include \"stor-layout.h\"\n");
244 printf ("#include \"calls.h\"\n");
245 printf ("#include \"rtl.h\"\n");
246 printf ("#include \"expr.h\"\n");
247 printf ("#include \"insn-codes.h\"\n");
248 printf ("#include \"tm_p.h\"\n");
249 printf ("#include \"function.h\"\n");
250 printf ("#include \"regs.h\"\n");
251 printf ("#include \"hard-reg-set.h\"\n");
252 printf ("#include \"insn-config.h\"\n\n");
253 printf ("#include \"conditions.h\"\n");
254 printf ("#include \"insn-attr.h\"\n\n");
255 printf ("#include \"recog.h\"\n\n");
256 printf ("#include \"diagnostic-core.h\"\n");
257 printf ("#include \"output.h\"\n");
258 printf ("#include \"target.h\"\n");
259 printf ("#include \"tm-constrs.h\"\n");
263 output_operand_data (void)
265 struct operand_data
*d
;
267 printf ("\nstatic const struct insn_operand_data operand_data[] = \n{\n");
269 for (d
= odata
; d
; d
= d
->next
)
271 struct pred_data
*pred
;
276 d
->predicate
&& d
->predicate
[0] ? d
->predicate
: "0");
278 printf (" \"%s\",\n", d
->constraint
? d
->constraint
: "");
280 printf (" %smode,\n", GET_MODE_NAME (d
->mode
));
282 printf (" %d,\n", d
->strict_low
);
284 printf (" %d,\n", d
->constraint
== NULL
? 1 : 0);
286 printf (" %d,\n", d
->eliminable
);
290 pred
= lookup_predicate (d
->predicate
);
291 printf (" %d\n", pred
&& pred
->codes
[MEM
]);
299 output_insn_data (void)
303 int next_name_offset
;
304 const char * last_name
= 0;
305 const char * next_name
= 0;
308 for (n
= idata
, next_name_offset
= 1; n
; n
= n
->next
, next_name_offset
++)
315 printf ("#if GCC_VERSION >= 2007\n__extension__\n#endif\n");
316 printf ("\nconst struct insn_data_d insn_data[] = \n{\n");
318 for (d
= idata
; d
; d
= d
->next
)
320 printf (" /* %s:%d */\n", d
->filename
, d
->lineno
);
325 printf (" \"%s\",\n", d
->name
);
329 for (n
= d
->next
, next_name_offset
= 1; n
;
330 n
= n
->next
, next_name_offset
++)
342 if (next_name
&& (last_name
== 0
343 || name_offset
> next_name_offset
/ 2))
344 printf (" \"%s-%d\",\n", next_name
,
345 next_name_offset
- name_offset
);
347 printf (" \"%s+%d\",\n", last_name
, name_offset
);
350 switch (d
->output_format
)
352 case INSN_OUTPUT_FORMAT_NONE
:
353 printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n");
354 printf (" { 0 },\n");
356 printf (" { 0, 0, 0 },\n");
359 case INSN_OUTPUT_FORMAT_SINGLE
:
361 const char *p
= d
->template_code
;
364 printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n");
365 printf (" { .single =\n");
372 if (IS_VSPACE (*p
) && prev
!= '\\')
374 /* Preserve two consecutive \n's or \r's, but treat \r\n
375 as a single newline. */
376 if (*p
== '\n' && prev
!= '\r')
385 printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n");
388 printf (" 0, 0 },\n");
392 case INSN_OUTPUT_FORMAT_MULTI
:
393 printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n");
394 printf (" { .multi = output_%d },\n", d
->code_number
);
396 printf (" { 0, output_%d, 0 },\n", d
->code_number
);
399 case INSN_OUTPUT_FORMAT_FUNCTION
:
400 printf ("#if HAVE_DESIGNATED_UNION_INITIALIZERS\n");
401 printf (" { .function = output_%d },\n", d
->code_number
);
403 printf (" { 0, 0, output_%d },\n", d
->code_number
);
410 if (d
->name
&& d
->name
[0] != '*')
411 printf (" { (insn_gen_fn::stored_funcptr) gen_%s },\n", d
->name
);
413 printf (" { 0 },\n");
415 printf (" &operand_data[%d],\n", d
->operand_number
);
416 printf (" %d,\n", d
->n_generator_args
);
417 printf (" %d,\n", d
->n_operands
);
418 printf (" %d,\n", d
->n_dups
);
419 printf (" %d,\n", d
->n_alternatives
);
420 printf (" %d\n", d
->output_format
);
428 output_get_insn_name (void)
430 printf ("const char *\n");
431 printf ("get_insn_name (int code)\n");
433 printf (" if (code == NOOP_MOVE_INSN_CODE)\n");
434 printf (" return \"NOOP_MOVE\";\n");
436 printf (" return insn_data[code].name;\n");
441 /* Stores the operand data into `d->operand[i]'.
443 THIS_ADDRESS_P is nonzero if the containing rtx was an ADDRESS.
444 THIS_STRICT_LOW is nonzero if the containing rtx was a STRICT_LOW_PART. */
447 scan_operands (struct data
*d
, rtx part
, int this_address_p
,
451 const char *format_ptr
;
457 switch (GET_CODE (part
))
460 opno
= XINT (part
, 0);
461 if (opno
>= MAX_MAX_OPERANDS
)
463 error_with_line (d
->lineno
, "maximum number of operands exceeded");
466 if (d
->operand
[opno
].seen
)
467 error_with_line (d
->lineno
, "repeated operand number %d\n", opno
);
469 d
->operand
[opno
].seen
= 1;
470 d
->operand
[opno
].mode
= GET_MODE (part
);
471 d
->operand
[opno
].strict_low
= this_strict_low
;
472 d
->operand
[opno
].predicate
= XSTR (part
, 1);
473 d
->operand
[opno
].constraint
= strip_whitespace (XSTR (part
, 2));
474 d
->operand
[opno
].n_alternatives
475 = n_occurrences (',', d
->operand
[opno
].constraint
) + 1;
476 d
->operand
[opno
].address_p
= this_address_p
;
477 d
->operand
[opno
].eliminable
= 1;
481 opno
= XINT (part
, 0);
482 if (opno
>= MAX_MAX_OPERANDS
)
484 error_with_line (d
->lineno
, "maximum number of operands exceeded");
487 if (d
->operand
[opno
].seen
)
488 error_with_line (d
->lineno
, "repeated operand number %d\n", opno
);
490 d
->operand
[opno
].seen
= 1;
491 d
->operand
[opno
].mode
= GET_MODE (part
);
492 d
->operand
[opno
].strict_low
= 0;
493 d
->operand
[opno
].predicate
= "scratch_operand";
494 d
->operand
[opno
].constraint
= strip_whitespace (XSTR (part
, 1));
495 d
->operand
[opno
].n_alternatives
496 = n_occurrences (',', d
->operand
[opno
].constraint
) + 1;
497 d
->operand
[opno
].address_p
= 0;
498 d
->operand
[opno
].eliminable
= 0;
503 opno
= XINT (part
, 0);
504 if (opno
>= MAX_MAX_OPERANDS
)
506 error_with_line (d
->lineno
, "maximum number of operands exceeded");
509 if (d
->operand
[opno
].seen
)
510 error_with_line (d
->lineno
, "repeated operand number %d\n", opno
);
512 d
->operand
[opno
].seen
= 1;
513 d
->operand
[opno
].mode
= GET_MODE (part
);
514 d
->operand
[opno
].strict_low
= 0;
515 d
->operand
[opno
].predicate
= XSTR (part
, 1);
516 d
->operand
[opno
].constraint
= 0;
517 d
->operand
[opno
].address_p
= 0;
518 d
->operand
[opno
].eliminable
= 0;
519 for (i
= 0; i
< XVECLEN (part
, 2); i
++)
520 scan_operands (d
, XVECEXP (part
, 2, i
), 0, 0);
523 case STRICT_LOW_PART
:
524 scan_operands (d
, XEXP (part
, 0), 0, 1);
531 format_ptr
= GET_RTX_FORMAT (GET_CODE (part
));
533 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (part
)); i
++)
534 switch (*format_ptr
++)
538 scan_operands (d
, XEXP (part
, i
), 0, 0);
541 if (XVEC (part
, i
) != NULL
)
542 for (j
= 0; j
< XVECLEN (part
, i
); j
++)
543 scan_operands (d
, XVECEXP (part
, i
, j
), 0, 0);
548 /* Compare two operands for content equality. */
551 compare_operands (struct operand_data
*d0
, struct operand_data
*d1
)
561 if (strcmp (p0
, p1
) != 0)
570 if (strcmp (p0
, p1
) != 0)
573 if (d0
->mode
!= d1
->mode
)
576 if (d0
->strict_low
!= d1
->strict_low
)
579 if (d0
->eliminable
!= d1
->eliminable
)
585 /* Scan the list of operands we've already committed to output and either
586 find a subsequence that is the same, or allocate a new one at the end. */
589 place_operands (struct data
*d
)
591 struct operand_data
*od
, *od2
;
594 if (d
->n_operands
== 0)
596 d
->operand_number
= 0;
600 /* Brute force substring search. */
601 for (od
= odata
, i
= 0; od
; od
= od
->next
, i
= 0)
602 if (compare_operands (od
, &d
->operand
[0]))
608 if (i
== d
->n_operands
)
612 if (! compare_operands (od2
, &d
->operand
[i
]))
614 ++i
, od2
= od2
->next
;
618 /* Either partial match at the end of the list, or no match. In either
619 case, we tack on what operands are remaining to the end of the list. */
621 d
->operand_number
= next_operand_number
- i
;
622 for (; i
< d
->n_operands
; ++i
)
624 od2
= &d
->operand
[i
];
626 odata_end
= &od2
->next
;
627 od2
->index
= next_operand_number
++;
633 d
->operand_number
= od
->index
;
638 /* Process an assembler template from a define_insn or a define_peephole.
639 It is either the assembler code template, a list of assembler code
640 templates, or C code to generate the assembler code template. */
643 process_template (struct data
*d
, const char *template_code
)
648 /* Templates starting with * contain straight code to be run. */
649 if (template_code
[0] == '*')
651 d
->template_code
= 0;
652 d
->output_format
= INSN_OUTPUT_FORMAT_FUNCTION
;
654 puts ("\nstatic const char *");
655 printf ("output_%d (rtx *operands ATTRIBUTE_UNUSED, rtx insn ATTRIBUTE_UNUSED)\n",
658 print_md_ptr_loc (template_code
);
659 puts (template_code
+ 1);
663 /* If the assembler code template starts with a @ it is a newline-separated
664 list of assembler code templates, one for each alternative. */
665 else if (template_code
[0] == '@')
669 for (cp
= &template_code
[1]; *cp
; )
671 while (ISSPACE (*cp
))
675 while (!IS_VSPACE (*cp
) && *cp
!= '\0')
678 d
->template_code
= 0;
681 d
->output_format
= INSN_OUTPUT_FORMAT_FUNCTION
;
682 puts ("\nstatic const char *");
683 printf ("output_%d (rtx *operands ATTRIBUTE_UNUSED, "
684 "rtx insn ATTRIBUTE_UNUSED)\n", d
->code_number
);
686 puts (" switch (which_alternative)\n {");
690 d
->output_format
= INSN_OUTPUT_FORMAT_MULTI
;
691 printf ("\nstatic const char * const output_%d[] = {\n",
695 for (i
= 0, cp
= &template_code
[1]; *cp
; )
697 const char *ep
, *sp
, *bp
;
699 while (ISSPACE (*cp
))
705 printf (" case %d:", i
);
712 printf (" return \"");
717 for (ep
= sp
= cp
; !IS_VSPACE (*ep
) && *ep
!= '\0'; ++ep
)
722 message_with_line (d
->lineno
,
723 "trailing whitespace in output template");
737 /* The usual action will end with a return.
738 If there is neither break or return at the end, this is
739 assumed to be intentional; this allows to have multiple
740 consecutive alternatives share some code. */
746 message_with_line (d
->lineno
,
747 "'@' is redundant for output template with single alternative");
748 if (i
!= d
->n_alternatives
)
749 error_with_line (d
->lineno
,
750 "wrong number of alternatives in the output template");
753 puts (" default: gcc_unreachable ();\n }\n}");
759 d
->template_code
= template_code
;
760 d
->output_format
= INSN_OUTPUT_FORMAT_SINGLE
;
764 /* Check insn D for consistency in number of constraint alternatives. */
767 validate_insn_alternatives (struct data
*d
)
771 /* Make sure all the operands have the same number of alternatives
772 in their constraints. Let N be that number. */
773 for (start
= 0; start
< d
->n_operands
; start
++)
774 if (d
->operand
[start
].n_alternatives
> 0)
779 int which_alternative
= 0;
780 int alternative_count_unsure
= 0;
782 for (p
= d
->operand
[start
].constraint
; (c
= *p
); p
+= len
)
784 if ((c
== '%' || c
== '=' || c
== '+')
785 && p
!= d
->operand
[start
].constraint
)
786 error_with_line (d
->lineno
,
787 "character '%c' can only be used at the"
788 " beginning of a constraint string", c
);
789 #ifdef USE_MD_CONSTRAINTS
790 if (ISSPACE (c
) || strchr (indep_constraints
, c
))
792 else if (ISDIGIT (c
))
797 while (ISDIGIT (*q
));
801 len
= mdep_constraint_len (p
, d
->lineno
, start
);
803 len
= CONSTRAINT_LEN (c
, p
);
805 if (len
< 1 || (len
> 1 && strchr (",#*+=&%!0123456789", c
)))
807 error_with_line (d
->lineno
,
808 "invalid length %d for char '%c' in"
809 " alternative %d of operand %d",
810 len
, c
, which_alternative
, start
);
821 for (i
= 1; i
< len
; i
++)
824 error_with_line (d
->lineno
,
825 "NUL in alternative %d of operand %d",
826 which_alternative
, start
);
827 alternative_count_unsure
= 1;
830 else if (strchr (",#*", p
[i
]))
832 error_with_line (d
->lineno
,
833 "'%c' in alternative %d of operand %d",
834 p
[i
], which_alternative
, start
);
835 alternative_count_unsure
= 1;
838 if (!alternative_count_unsure
)
841 n
= d
->operand
[start
].n_alternatives
;
842 else if (n
!= d
->operand
[start
].n_alternatives
)
843 error_with_line (d
->lineno
,
844 "wrong number of alternatives in operand %d",
849 /* Record the insn's overall number of alternatives. */
850 d
->n_alternatives
= n
;
853 /* Verify that there are no gaps in operand numbers for INSNs. */
856 validate_insn_operands (struct data
*d
)
860 for (i
= 0; i
< d
->n_operands
; ++i
)
861 if (d
->operand
[i
].seen
== 0)
862 error_with_line (d
->lineno
, "missing operand %d", i
);
866 validate_optab_operands (struct data
*d
)
868 if (!d
->name
|| d
->name
[0] == '\0' || d
->name
[0] == '*')
871 /* Miscellaneous tests. */
872 if (strncmp (d
->name
, "cstore", 6) == 0
873 && d
->name
[strlen (d
->name
) - 1] == '4'
874 && d
->operand
[0].mode
== VOIDmode
)
876 message_with_line (d
->lineno
, "missing mode for operand 0 of cstore");
881 /* Look at a define_insn just read. Assign its code number. Record
882 on idata the template and the number of arguments. If the insn has
883 a hairy output action, output a function for now. */
886 gen_insn (rtx insn
, int lineno
)
888 struct pattern_stats stats
;
889 struct data
*d
= XNEW (struct data
);
892 d
->code_number
= next_code_number
;
893 d
->index_number
= next_index_number
;
894 d
->filename
= read_md_filename
;
896 if (XSTR (insn
, 0)[0])
897 d
->name
= XSTR (insn
, 0);
901 /* Build up the list in the same order as the insns are seen
902 in the machine description. */
905 idata_end
= &d
->next
;
907 memset (d
->operand
, 0, sizeof (d
->operand
));
909 for (i
= 0; i
< XVECLEN (insn
, 1); i
++)
910 scan_operands (d
, XVECEXP (insn
, 1, i
), 0, 0);
912 get_pattern_stats (&stats
, XVEC (insn
, 1));
913 d
->n_generator_args
= stats
.num_generator_args
;
914 d
->n_operands
= stats
.num_insn_operands
;
915 d
->n_dups
= stats
.num_dups
;
917 #ifndef USE_MD_CONSTRAINTS
918 check_constraint_len ();
920 validate_insn_operands (d
);
921 validate_insn_alternatives (d
);
922 validate_optab_operands (d
);
924 process_template (d
, XTMPL (insn
, 3));
927 /* Look at a define_peephole just read. Assign its code number.
928 Record on idata the template and the number of arguments.
929 If the insn has a hairy output action, output it now. */
932 gen_peephole (rtx peep
, int lineno
)
934 struct pattern_stats stats
;
935 struct data
*d
= XNEW (struct data
);
938 d
->code_number
= next_code_number
;
939 d
->index_number
= next_index_number
;
940 d
->filename
= read_md_filename
;
944 /* Build up the list in the same order as the insns are seen
945 in the machine description. */
948 idata_end
= &d
->next
;
950 memset (d
->operand
, 0, sizeof (d
->operand
));
952 /* Get the number of operands by scanning all the patterns of the
953 peephole optimizer. But ignore all the rest of the information
955 for (i
= 0; i
< XVECLEN (peep
, 0); i
++)
956 scan_operands (d
, XVECEXP (peep
, 0, i
), 0, 0);
958 get_pattern_stats (&stats
, XVEC (peep
, 0));
959 d
->n_generator_args
= 0;
960 d
->n_operands
= stats
.num_insn_operands
;
963 validate_insn_alternatives (d
);
965 process_template (d
, XTMPL (peep
, 2));
968 /* Process a define_expand just read. Assign its code number,
969 only for the purposes of `insn_gen_function'. */
972 gen_expand (rtx insn
, int lineno
)
974 struct pattern_stats stats
;
975 struct data
*d
= XNEW (struct data
);
978 d
->code_number
= next_code_number
;
979 d
->index_number
= next_index_number
;
980 d
->filename
= read_md_filename
;
982 if (XSTR (insn
, 0)[0])
983 d
->name
= XSTR (insn
, 0);
987 /* Build up the list in the same order as the insns are seen
988 in the machine description. */
991 idata_end
= &d
->next
;
993 memset (d
->operand
, 0, sizeof (d
->operand
));
995 /* Scan the operands to get the specified predicates and modes,
996 since expand_binop needs to know them. */
999 for (i
= 0; i
< XVECLEN (insn
, 1); i
++)
1000 scan_operands (d
, XVECEXP (insn
, 1, i
), 0, 0);
1002 get_pattern_stats (&stats
, XVEC (insn
, 1));
1003 d
->n_generator_args
= stats
.num_generator_args
;
1004 d
->n_operands
= stats
.num_insn_operands
;
1005 d
->n_dups
= stats
.num_dups
;
1006 d
->template_code
= 0;
1007 d
->output_format
= INSN_OUTPUT_FORMAT_NONE
;
1009 validate_insn_alternatives (d
);
1010 validate_optab_operands (d
);
1014 /* Process a define_split just read. Assign its code number,
1015 only for reasons of consistency and to simplify genrecog. */
1018 gen_split (rtx split
, int lineno
)
1020 struct pattern_stats stats
;
1021 struct data
*d
= XNEW (struct data
);
1024 d
->code_number
= next_code_number
;
1025 d
->index_number
= next_index_number
;
1026 d
->filename
= read_md_filename
;
1030 /* Build up the list in the same order as the insns are seen
1031 in the machine description. */
1034 idata_end
= &d
->next
;
1036 memset (d
->operand
, 0, sizeof (d
->operand
));
1038 /* Get the number of operands by scanning all the patterns of the
1039 split patterns. But ignore all the rest of the information thus
1041 for (i
= 0; i
< XVECLEN (split
, 0); i
++)
1042 scan_operands (d
, XVECEXP (split
, 0, i
), 0, 0);
1044 get_pattern_stats (&stats
, XVEC (split
, 0));
1045 d
->n_generator_args
= 0;
1046 d
->n_operands
= stats
.num_insn_operands
;
1048 d
->n_alternatives
= 0;
1049 d
->template_code
= 0;
1050 d
->output_format
= INSN_OUTPUT_FORMAT_NONE
;
1056 init_insn_for_nothing (void)
1058 memset (¬hing
, 0, sizeof (nothing
));
1059 nothing
.name
= "*placeholder_for_nothing";
1060 nothing
.filename
= "<internal>";
1063 extern int main (int, char **);
1066 main (int argc
, char **argv
)
1070 progname
= "genoutput";
1072 init_insn_for_nothing ();
1074 if (!init_rtx_reader_args (argc
, argv
))
1075 return (FATAL_EXIT_CODE
);
1078 next_index_number
= 0;
1080 /* Read the machine description. */
1086 desc
= read_md_rtx (&line_no
, &next_code_number
);
1090 switch (GET_CODE (desc
))
1093 gen_insn (desc
, line_no
);
1096 case DEFINE_PEEPHOLE
:
1097 gen_peephole (desc
, line_no
);
1101 gen_expand (desc
, line_no
);
1105 case DEFINE_PEEPHOLE2
:
1106 gen_split (desc
, line_no
);
1109 #ifdef USE_MD_CONSTRAINTS
1110 case DEFINE_CONSTRAINT
:
1111 case DEFINE_REGISTER_CONSTRAINT
:
1112 case DEFINE_ADDRESS_CONSTRAINT
:
1113 case DEFINE_MEMORY_CONSTRAINT
:
1114 note_constraint (desc
, line_no
);
1121 next_index_number
++;
1125 output_operand_data ();
1126 output_insn_data ();
1127 output_get_insn_name ();
1130 return (ferror (stdout
) != 0 || have_error
1131 ? FATAL_EXIT_CODE
: SUCCESS_EXIT_CODE
);
1134 /* Return the number of occurrences of character C in string S or
1135 -1 if S is the null string. */
1138 n_occurrences (int c
, const char *s
)
1142 if (s
== 0 || *s
== '\0')
1151 /* Remove whitespace in `s' by moving up characters until the end.
1152 Return a new string. */
1155 strip_whitespace (const char *s
)
1163 p
= q
= XNEWVEC (char, strlen (s
) + 1);
1164 while ((ch
= *s
++) != '\0')
1172 #ifdef USE_MD_CONSTRAINTS
1174 /* Record just enough information about a constraint to allow checking
1175 of operand constraint strings above, in validate_insn_alternatives.
1176 Does not validate most properties of the constraint itself; does
1177 enforce no duplicate names, no overlap with MI constraints, and no
1178 prefixes. EXP is the define_*constraint form, LINENO the line number
1179 reported by the reader. */
1181 note_constraint (rtx exp
, int lineno
)
1183 const char *name
= XSTR (exp
, 0);
1184 unsigned int namelen
= strlen (name
);
1185 struct constraint_data
**iter
, **slot
, *new_cdata
;
1187 /* The 'm' constraint is special here since that constraint letter
1188 can be overridden by the back end by defining the
1189 TARGET_MEM_CONSTRAINT macro. */
1190 if (strchr (indep_constraints
, name
[0]) && name
[0] != 'm')
1192 if (name
[1] == '\0')
1193 error_with_line (lineno
, "constraint letter '%s' cannot be "
1194 "redefined by the machine description", name
);
1196 error_with_line (lineno
, "constraint name '%s' cannot be defined by "
1197 "the machine description, as it begins with '%c'",
1202 slot
= &constraints_by_letter_table
[(unsigned int)name
[0]];
1203 for (iter
= slot
; *iter
; iter
= &(*iter
)->next_this_letter
)
1205 /* This causes slot to end up pointing to the
1206 next_this_letter field of the last constraint with a name
1207 of equal or greater length than the new constraint; hence
1208 the new constraint will be inserted after all previous
1209 constraints with names of the same length. */
1210 if ((*iter
)->namelen
>= namelen
)
1213 if (!strcmp ((*iter
)->name
, name
))
1215 error_with_line (lineno
, "redefinition of constraint '%s'", name
);
1216 message_with_line ((*iter
)->lineno
, "previous definition is here");
1219 else if (!strncmp ((*iter
)->name
, name
, (*iter
)->namelen
))
1221 error_with_line (lineno
, "defining constraint '%s' here", name
);
1222 message_with_line ((*iter
)->lineno
, "renders constraint '%s' "
1223 "(defined here) a prefix", (*iter
)->name
);
1226 else if (!strncmp ((*iter
)->name
, name
, namelen
))
1228 error_with_line (lineno
, "constraint '%s' is a prefix", name
);
1229 message_with_line ((*iter
)->lineno
, "of constraint '%s' "
1230 "(defined here)", (*iter
)->name
);
1234 new_cdata
= XNEWVAR (struct constraint_data
, sizeof (struct constraint_data
) + namelen
);
1235 strcpy (CONST_CAST (char *, new_cdata
->name
), name
);
1236 new_cdata
->namelen
= namelen
;
1237 new_cdata
->lineno
= lineno
;
1238 new_cdata
->next_this_letter
= *slot
;
1242 /* Return the length of the constraint name beginning at position S
1243 of an operand constraint string, or issue an error message if there
1244 is no such constraint. Does not expect to be called for generic
1247 mdep_constraint_len (const char *s
, int lineno
, int opno
)
1249 struct constraint_data
*p
;
1251 p
= constraints_by_letter_table
[(unsigned int)s
[0]];
1254 for (; p
; p
= p
->next_this_letter
)
1255 if (!strncmp (s
, p
->name
, p
->namelen
))
1258 error_with_line (lineno
,
1259 "error: undefined machine-specific constraint "
1260 "at this point: \"%s\"", s
);
1261 message_with_line (lineno
, "note: in operand %d", opno
);
1262 return 1; /* safe */
1266 /* Verify that DEFAULT_CONSTRAINT_LEN is used properly and not
1267 tampered with. This isn't bullet-proof, but it should catch
1268 most genuine mistakes. */
1270 check_constraint_len (void)
1275 for (p
= ",#*+=&%!1234567890"; *p
; p
++)
1276 for (d
= -9; d
< 9; d
++)
1277 gcc_assert (constraint_len (p
, d
) == d
);
1281 constraint_len (const char *p
, int genoutput_default_constraint_len
)
1283 /* Check that we still match defaults.h . First we do a generation-time
1284 check that fails if the value is not the expected one... */
1285 gcc_assert (DEFAULT_CONSTRAINT_LEN (*p
, p
) == 1);
1286 /* And now a compile-time check that should give a diagnostic if the
1287 definition doesn't exactly match. */
1288 #define DEFAULT_CONSTRAINT_LEN(C,STR) 1
1289 /* Now re-define DEFAULT_CONSTRAINT_LEN so that we can verify it is
1291 #undef DEFAULT_CONSTRAINT_LEN
1292 #define DEFAULT_CONSTRAINT_LEN(C,STR) \
1293 ((C) != *p || STR != p ? -1 : genoutput_default_constraint_len)
1294 return CONSTRAINT_LEN (*p
, p
);
1295 /* And set it back. */
1296 #undef DEFAULT_CONSTRAINT_LEN
1297 #define DEFAULT_CONSTRAINT_LEN(C,STR) 1