1 /* Support routines for the various generation passes.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "coretypes.h"
30 #include "gensupport.h"
33 /* In case some macros used by files we include need it, define this here. */
40 /* This callback will be invoked whenever an rtl include directive is
41 processed. To be used for creation of the dependency file. */
42 void (*include_callback
) (const char *);
44 static struct obstack obstack
;
45 struct obstack
*rtl_obstack
= &obstack
;
47 static int sequence_num
;
50 static int predicable_default
;
51 static const char *predicable_true
;
52 static const char *predicable_false
;
54 static htab_t condition_table
;
56 static char *base_dir
= NULL
;
58 /* We initially queue all patterns, process the define_insn and
59 define_cond_exec patterns, then return them one at a time. */
66 struct queue_elem
*next
;
67 /* In a DEFINE_INSN that came from a DEFINE_INSN_AND_SPLIT, SPLIT
68 points to the generated DEFINE_SPLIT. */
69 struct queue_elem
*split
;
72 static struct queue_elem
*define_attr_queue
;
73 static struct queue_elem
**define_attr_tail
= &define_attr_queue
;
74 static struct queue_elem
*define_pred_queue
;
75 static struct queue_elem
**define_pred_tail
= &define_pred_queue
;
76 static struct queue_elem
*define_insn_queue
;
77 static struct queue_elem
**define_insn_tail
= &define_insn_queue
;
78 static struct queue_elem
*define_cond_exec_queue
;
79 static struct queue_elem
**define_cond_exec_tail
= &define_cond_exec_queue
;
80 static struct queue_elem
*other_queue
;
81 static struct queue_elem
**other_tail
= &other_queue
;
83 static struct queue_elem
*queue_pattern (rtx
, struct queue_elem
***,
86 /* Current maximum length of directory names in the search path
87 for include files. (Altered as we get more of them.) */
89 size_t max_include_len
;
93 struct file_name_list
*next
;
97 struct file_name_list
*first_dir_md_include
= 0; /* First dir to search */
98 /* First dir to search for <file> */
99 struct file_name_list
*first_bracket_include
= 0;
100 struct file_name_list
*last_dir_md_include
= 0; /* Last in chain */
102 static void remove_constraints (rtx
);
103 static void process_rtx (rtx
, int);
105 static int is_predicable (struct queue_elem
*);
106 static void identify_predicable_attribute (void);
107 static int n_alternatives (const char *);
108 static void collect_insn_data (rtx
, int *, int *);
109 static rtx
alter_predicate_for_insn (rtx
, int, int, int);
110 static const char *alter_test_for_insn (struct queue_elem
*,
111 struct queue_elem
*);
112 static char *shift_output_template (char *, const char *, int);
113 static const char *alter_output_for_insn (struct queue_elem
*,
116 static void process_one_cond_exec (struct queue_elem
*);
117 static void process_define_cond_exec (void);
118 static void process_include (rtx
, int);
119 static char *save_string (const char *, int);
120 static void init_predicate_table (void);
123 message_with_line (int lineno
, const char *msg
, ...)
129 fprintf (stderr
, "%s:%d: ", read_rtx_filename
, lineno
);
130 vfprintf (stderr
, msg
, ap
);
131 fputc ('\n', stderr
);
136 /* Make a version of gen_rtx_CONST_INT so that GEN_INT can be used in
137 the gensupport programs. */
140 gen_rtx_CONST_INT (enum machine_mode
ARG_UNUSED (mode
),
143 rtx rt
= rtx_alloc (CONST_INT
);
149 /* Queue PATTERN on LIST_TAIL. Return the address of the new queue
152 static struct queue_elem
*
153 queue_pattern (rtx pattern
, struct queue_elem
***list_tail
,
154 const char *filename
, int lineno
)
156 struct queue_elem
*e
= XNEW(struct queue_elem
);
158 e
->filename
= filename
;
163 *list_tail
= &e
->next
;
167 /* Recursively remove constraints from an rtx. */
170 remove_constraints (rtx part
)
173 const char *format_ptr
;
178 if (GET_CODE (part
) == MATCH_OPERAND
)
180 else if (GET_CODE (part
) == MATCH_SCRATCH
)
183 format_ptr
= GET_RTX_FORMAT (GET_CODE (part
));
185 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (part
)); i
++)
186 switch (*format_ptr
++)
190 remove_constraints (XEXP (part
, i
));
193 if (XVEC (part
, i
) != NULL
)
194 for (j
= 0; j
< XVECLEN (part
, i
); j
++)
195 remove_constraints (XVECEXP (part
, i
, j
));
200 /* Process an include file assuming that it lives in gcc/config/{target}/
201 if the include looks like (include "file"). */
204 process_include (rtx desc
, int lineno
)
206 const char *filename
= XSTR (desc
, 0);
207 const char *old_filename
;
212 /* If specified file name is absolute, skip the include stack. */
213 if (! IS_ABSOLUTE_PATH (filename
))
215 struct file_name_list
*stackp
;
217 /* Search directory path, trying to open the file. */
218 for (stackp
= first_dir_md_include
; stackp
; stackp
= stackp
->next
)
220 static const char sep
[2] = { DIR_SEPARATOR
, '\0' };
222 pathname
= concat (stackp
->fname
, sep
, filename
, NULL
);
223 input_file
= fopen (pathname
, "r");
224 if (input_file
!= NULL
)
231 pathname
= concat (base_dir
, filename
, NULL
);
233 pathname
= xstrdup (filename
);
234 input_file
= fopen (pathname
, "r");
235 if (input_file
== NULL
)
238 message_with_line (lineno
, "include file `%s' not found", filename
);
244 /* Save old cursor; setup new for the new file. Note that "lineno" the
245 argument to this function is the beginning of the include statement,
246 while read_rtx_lineno has already been advanced. */
247 old_filename
= read_rtx_filename
;
248 old_lineno
= read_rtx_lineno
;
249 read_rtx_filename
= pathname
;
252 if (include_callback
)
253 include_callback (pathname
);
255 /* Read the entire file. */
256 while (read_rtx (input_file
, &desc
, &lineno
))
257 process_rtx (desc
, lineno
);
259 /* Do not free pathname. It is attached to the various rtx queue
262 read_rtx_filename
= old_filename
;
263 read_rtx_lineno
= old_lineno
;
268 /* Process a top level rtx in some way, queuing as appropriate. */
271 process_rtx (rtx desc
, int lineno
)
273 switch (GET_CODE (desc
))
276 queue_pattern (desc
, &define_insn_tail
, read_rtx_filename
, lineno
);
279 case DEFINE_COND_EXEC
:
280 queue_pattern (desc
, &define_cond_exec_tail
, read_rtx_filename
, lineno
);
284 queue_pattern (desc
, &define_attr_tail
, read_rtx_filename
, lineno
);
287 case DEFINE_PREDICATE
:
288 case DEFINE_SPECIAL_PREDICATE
:
289 queue_pattern (desc
, &define_pred_tail
, read_rtx_filename
, lineno
);
293 process_include (desc
, lineno
);
296 case DEFINE_INSN_AND_SPLIT
:
298 const char *split_cond
;
302 struct queue_elem
*insn_elem
;
303 struct queue_elem
*split_elem
;
305 /* Create a split with values from the insn_and_split. */
306 split
= rtx_alloc (DEFINE_SPLIT
);
308 i
= XVECLEN (desc
, 1);
309 XVEC (split
, 0) = rtvec_alloc (i
);
312 XVECEXP (split
, 0, i
) = copy_rtx (XVECEXP (desc
, 1, i
));
313 remove_constraints (XVECEXP (split
, 0, i
));
316 /* If the split condition starts with "&&", append it to the
317 insn condition to create the new split condition. */
318 split_cond
= XSTR (desc
, 4);
319 if (split_cond
[0] == '&' && split_cond
[1] == '&')
320 split_cond
= concat (XSTR (desc
, 2), split_cond
, NULL
);
321 XSTR (split
, 1) = split_cond
;
322 XVEC (split
, 2) = XVEC (desc
, 5);
323 XSTR (split
, 3) = XSTR (desc
, 6);
325 /* Fix up the DEFINE_INSN. */
326 attr
= XVEC (desc
, 7);
327 PUT_CODE (desc
, DEFINE_INSN
);
328 XVEC (desc
, 4) = attr
;
332 = queue_pattern (desc
, &define_insn_tail
, read_rtx_filename
,
335 = queue_pattern (split
, &other_tail
, read_rtx_filename
, lineno
);
336 insn_elem
->split
= split_elem
;
341 queue_pattern (desc
, &other_tail
, read_rtx_filename
, lineno
);
346 /* Return true if attribute PREDICABLE is true for ELEM, which holds
350 is_predicable (struct queue_elem
*elem
)
352 rtvec vec
= XVEC (elem
->data
, 4);
357 return predicable_default
;
359 for (i
= GET_NUM_ELEM (vec
) - 1; i
>= 0; --i
)
361 rtx sub
= RTVEC_ELT (vec
, i
);
362 switch (GET_CODE (sub
))
365 if (strcmp (XSTR (sub
, 0), "predicable") == 0)
367 value
= XSTR (sub
, 1);
372 case SET_ATTR_ALTERNATIVE
:
373 if (strcmp (XSTR (sub
, 0), "predicable") == 0)
375 message_with_line (elem
->lineno
,
376 "multiple alternatives for `predicable'");
383 if (GET_CODE (SET_DEST (sub
)) != ATTR
384 || strcmp (XSTR (SET_DEST (sub
), 0), "predicable") != 0)
387 if (GET_CODE (sub
) == CONST_STRING
)
389 value
= XSTR (sub
, 0);
393 /* ??? It would be possible to handle this if we really tried.
394 It's not easy though, and I'm not going to bother until it
395 really proves necessary. */
396 message_with_line (elem
->lineno
,
397 "non-constant value for `predicable'");
406 return predicable_default
;
409 /* Verify that predicability does not vary on the alternative. */
410 /* ??? It should be possible to handle this by simply eliminating
411 the non-predicable alternatives from the insn. FRV would like
412 to do this. Delay this until we've got the basics solid. */
413 if (strchr (value
, ',') != NULL
)
415 message_with_line (elem
->lineno
,
416 "multiple alternatives for `predicable'");
421 /* Find out which value we're looking at. */
422 if (strcmp (value
, predicable_true
) == 0)
424 if (strcmp (value
, predicable_false
) == 0)
427 message_with_line (elem
->lineno
,
428 "unknown value `%s' for `predicable' attribute",
434 /* Examine the attribute "predicable"; discover its boolean values
438 identify_predicable_attribute (void)
440 struct queue_elem
*elem
;
441 char *p_true
, *p_false
;
444 /* Look for the DEFINE_ATTR for `predicable', which must exist. */
445 for (elem
= define_attr_queue
; elem
; elem
= elem
->next
)
446 if (strcmp (XSTR (elem
->data
, 0), "predicable") == 0)
449 message_with_line (define_cond_exec_queue
->lineno
,
450 "attribute `predicable' not defined");
455 value
= XSTR (elem
->data
, 1);
456 p_false
= xstrdup (value
);
457 p_true
= strchr (p_false
, ',');
458 if (p_true
== NULL
|| strchr (++p_true
, ',') != NULL
)
460 message_with_line (elem
->lineno
,
461 "attribute `predicable' is not a boolean");
467 predicable_true
= p_true
;
468 predicable_false
= p_false
;
470 switch (GET_CODE (XEXP (elem
->data
, 2)))
473 value
= XSTR (XEXP (elem
->data
, 2), 0);
477 message_with_line (elem
->lineno
,
478 "attribute `predicable' cannot be const");
483 message_with_line (elem
->lineno
,
484 "attribute `predicable' must have a constant default");
489 if (strcmp (value
, p_true
) == 0)
490 predicable_default
= 1;
491 else if (strcmp (value
, p_false
) == 0)
492 predicable_default
= 0;
495 message_with_line (elem
->lineno
,
496 "unknown value `%s' for `predicable' attribute",
502 /* Return the number of alternatives in constraint S. */
505 n_alternatives (const char *s
)
516 /* Determine how many alternatives there are in INSN, and how many
520 collect_insn_data (rtx pattern
, int *palt
, int *pmax
)
526 code
= GET_CODE (pattern
);
530 i
= n_alternatives (XSTR (pattern
, 2));
531 *palt
= (i
> *palt
? i
: *palt
);
537 i
= XINT (pattern
, 0);
546 fmt
= GET_RTX_FORMAT (code
);
547 len
= GET_RTX_LENGTH (code
);
548 for (i
= 0; i
< len
; i
++)
553 collect_insn_data (XEXP (pattern
, i
), palt
, pmax
);
557 if (XVEC (pattern
, i
) == NULL
)
561 for (j
= XVECLEN (pattern
, i
) - 1; j
>= 0; --j
)
562 collect_insn_data (XVECEXP (pattern
, i
, j
), palt
, pmax
);
565 case 'i': case 'w': case '0': case 's': case 'S': case 'T':
575 alter_predicate_for_insn (rtx pattern
, int alt
, int max_op
, int lineno
)
581 code
= GET_CODE (pattern
);
586 const char *c
= XSTR (pattern
, 2);
588 if (n_alternatives (c
) != 1)
590 message_with_line (lineno
,
591 "too many alternatives for operand %d",
597 /* Replicate C as needed to fill out ALT alternatives. */
598 if (c
&& *c
&& alt
> 1)
600 size_t c_len
= strlen (c
);
601 size_t len
= alt
* (c_len
+ 1);
602 char *new_c
= XNEWVEC(char, len
);
604 memcpy (new_c
, c
, c_len
);
605 for (i
= 1; i
< alt
; ++i
)
607 new_c
[i
* (c_len
+ 1) - 1] = ',';
608 memcpy (&new_c
[i
* (c_len
+ 1)], c
, c_len
);
610 new_c
[len
- 1] = '\0';
611 XSTR (pattern
, 2) = new_c
;
619 XINT (pattern
, 0) += max_op
;
626 fmt
= GET_RTX_FORMAT (code
);
627 len
= GET_RTX_LENGTH (code
);
628 for (i
= 0; i
< len
; i
++)
635 r
= alter_predicate_for_insn (XEXP (pattern
, i
), alt
,
642 for (j
= XVECLEN (pattern
, i
) - 1; j
>= 0; --j
)
644 r
= alter_predicate_for_insn (XVECEXP (pattern
, i
, j
),
645 alt
, max_op
, lineno
);
651 case 'i': case 'w': case '0': case 's':
663 alter_test_for_insn (struct queue_elem
*ce_elem
,
664 struct queue_elem
*insn_elem
)
666 const char *ce_test
, *insn_test
;
668 ce_test
= XSTR (ce_elem
->data
, 1);
669 insn_test
= XSTR (insn_elem
->data
, 2);
670 if (!ce_test
|| *ce_test
== '\0')
672 if (!insn_test
|| *insn_test
== '\0')
675 return concat ("(", ce_test
, ") && (", insn_test
, ")", NULL
);
678 /* Adjust all of the operand numbers in SRC to match the shift they'll
679 get from an operand displacement of DISP. Return a pointer after the
683 shift_output_template (char *dest
, const char *src
, int disp
)
692 if (ISDIGIT ((unsigned char) c
))
694 else if (ISALPHA (c
))
707 alter_output_for_insn (struct queue_elem
*ce_elem
,
708 struct queue_elem
*insn_elem
,
711 const char *ce_out
, *insn_out
;
713 size_t len
, ce_len
, insn_len
;
715 /* ??? Could coordinate with genoutput to not duplicate code here. */
717 ce_out
= XSTR (ce_elem
->data
, 2);
718 insn_out
= XTMPL (insn_elem
->data
, 3);
719 if (!ce_out
|| *ce_out
== '\0')
722 ce_len
= strlen (ce_out
);
723 insn_len
= strlen (insn_out
);
725 if (*insn_out
== '*')
726 /* You must take care of the predicate yourself. */
729 if (*insn_out
== '@')
731 len
= (ce_len
+ 1) * alt
+ insn_len
+ 1;
732 p
= result
= XNEWVEC(char, len
);
738 while (ISSPACE ((unsigned char) *insn_out
));
740 if (*insn_out
!= '#')
742 p
= shift_output_template (p
, ce_out
, max_op
);
748 while (*insn_out
&& *insn_out
!= '\n');
755 len
= ce_len
+ 1 + insn_len
+ 1;
756 result
= XNEWVEC (char, len
);
758 p
= shift_output_template (result
, ce_out
, max_op
);
760 memcpy (p
, insn_out
, insn_len
+ 1);
766 /* Replicate insns as appropriate for the given DEFINE_COND_EXEC. */
769 process_one_cond_exec (struct queue_elem
*ce_elem
)
771 struct queue_elem
*insn_elem
;
772 for (insn_elem
= define_insn_queue
; insn_elem
; insn_elem
= insn_elem
->next
)
774 int alternatives
, max_operand
;
775 rtx pred
, insn
, pattern
, split
;
778 if (! is_predicable (insn_elem
))
783 collect_insn_data (insn_elem
->data
, &alternatives
, &max_operand
);
786 if (XVECLEN (ce_elem
->data
, 0) != 1)
788 message_with_line (ce_elem
->lineno
,
789 "too many patterns in predicate");
794 pred
= copy_rtx (XVECEXP (ce_elem
->data
, 0, 0));
795 pred
= alter_predicate_for_insn (pred
, alternatives
, max_operand
,
800 /* Construct a new pattern for the new insn. */
801 insn
= copy_rtx (insn_elem
->data
);
803 pattern
= rtx_alloc (COND_EXEC
);
804 XEXP (pattern
, 0) = pred
;
805 if (XVECLEN (insn
, 1) == 1)
807 XEXP (pattern
, 1) = XVECEXP (insn
, 1, 0);
808 XVECEXP (insn
, 1, 0) = pattern
;
809 PUT_NUM_ELEM (XVEC (insn
, 1), 1);
813 XEXP (pattern
, 1) = rtx_alloc (PARALLEL
);
814 XVEC (XEXP (pattern
, 1), 0) = XVEC (insn
, 1);
815 XVEC (insn
, 1) = rtvec_alloc (1);
816 XVECEXP (insn
, 1, 0) = pattern
;
819 XSTR (insn
, 2) = alter_test_for_insn (ce_elem
, insn_elem
);
820 XTMPL (insn
, 3) = alter_output_for_insn (ce_elem
, insn_elem
,
821 alternatives
, max_operand
);
823 /* ??? Set `predicable' to false. Not crucial since it's really
824 only used here, and we won't reprocess this new pattern. */
826 /* Put the new pattern on the `other' list so that it
827 (a) is not reprocessed by other define_cond_exec patterns
828 (b) appears after all normal define_insn patterns.
830 ??? B is debatable. If one has normal insns that match
831 cond_exec patterns, they will be preferred over these
832 generated patterns. Whether this matters in practice, or if
833 it's a good thing, or whether we should thread these new
834 patterns into the define_insn chain just after their generator
835 is something we'll have to experiment with. */
837 queue_pattern (insn
, &other_tail
, insn_elem
->filename
,
840 if (!insn_elem
->split
)
843 /* If the original insn came from a define_insn_and_split,
844 generate a new split to handle the predicated insn. */
845 split
= copy_rtx (insn_elem
->split
->data
);
846 /* Predicate the pattern matched by the split. */
847 pattern
= rtx_alloc (COND_EXEC
);
848 XEXP (pattern
, 0) = pred
;
849 if (XVECLEN (split
, 0) == 1)
851 XEXP (pattern
, 1) = XVECEXP (split
, 0, 0);
852 XVECEXP (split
, 0, 0) = pattern
;
853 PUT_NUM_ELEM (XVEC (split
, 0), 1);
857 XEXP (pattern
, 1) = rtx_alloc (PARALLEL
);
858 XVEC (XEXP (pattern
, 1), 0) = XVEC (split
, 0);
859 XVEC (split
, 0) = rtvec_alloc (1);
860 XVECEXP (split
, 0, 0) = pattern
;
862 /* Predicate all of the insns generated by the split. */
863 for (i
= 0; i
< XVECLEN (split
, 2); i
++)
865 pattern
= rtx_alloc (COND_EXEC
);
866 XEXP (pattern
, 0) = pred
;
867 XEXP (pattern
, 1) = XVECEXP (split
, 2, i
);
868 XVECEXP (split
, 2, i
) = pattern
;
870 /* Add the new split to the queue. */
871 queue_pattern (split
, &other_tail
, read_rtx_filename
,
872 insn_elem
->split
->lineno
);
876 /* If we have any DEFINE_COND_EXEC patterns, expand the DEFINE_INSN
877 patterns appropriately. */
880 process_define_cond_exec (void)
882 struct queue_elem
*elem
;
884 identify_predicable_attribute ();
888 for (elem
= define_cond_exec_queue
; elem
; elem
= elem
->next
)
889 process_one_cond_exec (elem
);
893 save_string (const char *s
, int len
)
895 char *result
= XNEWVEC (char, len
+ 1);
897 memcpy (result
, s
, len
);
903 /* The entry point for initializing the reader. */
906 init_md_reader_args_cb (int argc
, char **argv
, bool (*parse_opt
)(const char *))
914 for (i
= 1; i
< argc
; i
++)
916 if (argv
[i
][0] != '-')
919 fatal ("too many input files");
928 case 'I': /* Add directory to path for includes. */
930 struct file_name_list
*dirtmp
;
932 dirtmp
= XNEW (struct file_name_list
);
933 dirtmp
->next
= 0; /* New one goes on the end */
934 if (first_dir_md_include
== 0)
935 first_dir_md_include
= dirtmp
;
937 last_dir_md_include
->next
= dirtmp
;
938 last_dir_md_include
= dirtmp
; /* Tail follows the last one */
939 if (argv
[i
][1] == 'I' && argv
[i
][2] != 0)
940 dirtmp
->fname
= argv
[i
] + 2;
941 else if (i
+ 1 == argc
)
942 fatal ("directory name missing after -I option");
944 dirtmp
->fname
= argv
[++i
];
945 if (strlen (dirtmp
->fname
) > max_include_len
)
946 max_include_len
= strlen (dirtmp
->fname
);
950 /* The program may have provided a callback so it can
951 accept its own options. */
952 if (parse_opt
&& parse_opt (argv
[i
]))
955 fatal ("invalid option `%s'", argv
[i
]);
961 fatal ("no input file name");
963 lastsl
= strrchr (in_fname
, '/');
965 base_dir
= save_string (in_fname
, lastsl
- in_fname
+ 1 );
967 read_rtx_filename
= in_fname
;
968 input_file
= fopen (in_fname
, "r");
972 return FATAL_EXIT_CODE
;
975 /* Initialize the table of insn conditions. */
976 condition_table
= htab_create (n_insn_conditions
,
977 hash_c_test
, cmp_c_test
, NULL
);
979 for (ix
= 0; ix
< n_insn_conditions
; ix
++)
980 *(htab_find_slot (condition_table
, &insn_conditions
[ix
], INSERT
))
981 = (void *) &insn_conditions
[ix
];
983 init_predicate_table ();
985 obstack_init (rtl_obstack
);
989 /* Read the entire file. */
990 while (read_rtx (input_file
, &desc
, &lineno
))
991 process_rtx (desc
, lineno
);
994 /* Process define_cond_exec patterns. */
995 if (define_cond_exec_queue
!= NULL
)
996 process_define_cond_exec ();
998 return errors
? FATAL_EXIT_CODE
: SUCCESS_EXIT_CODE
;
1001 /* Programs that don't have their own options can use this entry point
1004 init_md_reader_args (int argc
, char **argv
)
1006 return init_md_reader_args_cb (argc
, argv
, 0);
1009 /* The entry point for reading a single rtx from an md file. */
1012 read_md_rtx (int *lineno
, int *seqnr
)
1014 struct queue_elem
**queue
, *elem
;
1019 /* Read all patterns from a given queue before moving on to the next. */
1020 if (define_attr_queue
!= NULL
)
1021 queue
= &define_attr_queue
;
1022 else if (define_pred_queue
!= NULL
)
1023 queue
= &define_pred_queue
;
1024 else if (define_insn_queue
!= NULL
)
1025 queue
= &define_insn_queue
;
1026 else if (other_queue
!= NULL
)
1027 queue
= &other_queue
;
1032 *queue
= elem
->next
;
1034 read_rtx_filename
= elem
->filename
;
1035 *lineno
= elem
->lineno
;
1036 *seqnr
= sequence_num
;
1040 /* Discard insn patterns which we know can never match (because
1041 their C test is provably always false). If insn_elision is
1042 false, our caller needs to see all the patterns. Note that the
1043 elided patterns are never counted by the sequence numbering; it
1044 it is the caller's responsibility, when insn_elision is false, not
1045 to use elided pattern numbers for anything. */
1046 switch (GET_CODE (desc
))
1050 if (maybe_eval_c_test (XSTR (desc
, 2)) != 0)
1052 else if (insn_elision
)
1057 case DEFINE_PEEPHOLE
:
1058 case DEFINE_PEEPHOLE2
:
1059 if (maybe_eval_c_test (XSTR (desc
, 1)) != 0)
1061 else if (insn_elision
)
1072 /* Helper functions for insn elision. */
1074 /* Compute a hash function of a c_test structure, which is keyed
1075 by its ->expr field. */
1077 hash_c_test (const void *x
)
1079 const struct c_test
*a
= (const struct c_test
*) x
;
1080 const unsigned char *base
, *s
= (const unsigned char *) a
->expr
;
1088 while ((c
= *s
++) != '\0')
1090 hash
+= c
+ (c
<< 17);
1095 hash
+= len
+ (len
<< 17);
1101 /* Compare two c_test expression structures. */
1103 cmp_c_test (const void *x
, const void *y
)
1105 const struct c_test
*a
= (const struct c_test
*) x
;
1106 const struct c_test
*b
= (const struct c_test
*) y
;
1108 return !strcmp (a
->expr
, b
->expr
);
1111 /* Given a string representing a C test expression, look it up in the
1112 condition_table and report whether or not its value is known
1113 at compile time. Returns a tristate: 1 for known true, 0 for
1114 known false, -1 for unknown. */
1116 maybe_eval_c_test (const char *expr
)
1118 const struct c_test
*test
;
1119 struct c_test dummy
;
1124 if (insn_elision_unavailable
)
1128 test
= (const struct c_test
*)htab_find (condition_table
, &dummy
);
1134 /* Given a string, return the number of comma-separated elements in it.
1135 Return 0 for the null string. */
1137 n_comma_elts (const char *s
)
1144 for (n
= 1; *s
; s
++)
1151 /* Given a pointer to a (char *), return a pointer to the beginning of the
1152 next comma-separated element in the string. Advance the pointer given
1153 to the end of that element. Return NULL if at end of string. Caller
1154 is responsible for copying the string if necessary. White space between
1155 a comma and an element is ignored. */
1158 scan_comma_elt (const char **pstr
)
1161 const char *p
= *pstr
;
1173 while (*p
!= ',' && *p
!= '\0')
1180 /* Helper functions for define_predicate and define_special_predicate
1181 processing. Shared between genrecog.c and genpreds.c. */
1183 static htab_t predicate_table
;
1184 struct pred_data
*first_predicate
;
1185 static struct pred_data
**last_predicate
= &first_predicate
;
1188 hash_struct_pred_data (const void *ptr
)
1190 return htab_hash_string (((const struct pred_data
*)ptr
)->name
);
1194 eq_struct_pred_data (const void *a
, const void *b
)
1196 return !strcmp (((const struct pred_data
*)a
)->name
,
1197 ((const struct pred_data
*)b
)->name
);
1201 lookup_predicate (const char *name
)
1203 struct pred_data key
;
1205 return htab_find (predicate_table
, &key
);
1209 add_predicate (struct pred_data
*pred
)
1211 void **slot
= htab_find_slot (predicate_table
, pred
, INSERT
);
1214 error ("duplicate predicate definition for '%s'", pred
->name
);
1218 *last_predicate
= pred
;
1219 last_predicate
= &pred
->next
;
1222 /* This array gives the initial content of the predicate table. It
1223 has entries for all predicates defined in recog.c. The back end
1224 can define PREDICATE_CODES to give additional entries for the
1225 table; this is considered an obsolete mechanism (use
1226 define_predicate instead). */
1228 struct old_pred_table
1231 RTX_CODE codes
[NUM_RTX_CODE
];
1234 static const struct old_pred_table old_preds
[] = {
1235 {"general_operand", {CONST_INT
, CONST_DOUBLE
, CONST
, SYMBOL_REF
,
1236 LABEL_REF
, SUBREG
, REG
, MEM
}},
1237 {"address_operand", {CONST_INT
, CONST_DOUBLE
, CONST
, SYMBOL_REF
,
1238 LABEL_REF
, SUBREG
, REG
, MEM
,
1239 PLUS
, MINUS
, MULT
}},
1240 {"register_operand", {SUBREG
, REG
}},
1241 {"pmode_register_operand", {SUBREG
, REG
}},
1242 {"scratch_operand", {SCRATCH
, REG
}},
1243 {"immediate_operand", {CONST_INT
, CONST_DOUBLE
, CONST
, SYMBOL_REF
,
1245 {"const_int_operand", {CONST_INT
}},
1246 {"const_double_operand", {CONST_INT
, CONST_DOUBLE
}},
1247 {"nonimmediate_operand", {SUBREG
, REG
, MEM
}},
1248 {"nonmemory_operand", {CONST_INT
, CONST_DOUBLE
, CONST
, SYMBOL_REF
,
1249 LABEL_REF
, SUBREG
, REG
}},
1250 {"push_operand", {MEM
}},
1251 {"pop_operand", {MEM
}},
1252 {"memory_operand", {SUBREG
, MEM
}},
1253 {"indirect_operand", {SUBREG
, MEM
}},
1254 {"comparison_operator", {EQ
, NE
, LE
, LT
, GE
, GT
, LEU
, LTU
, GEU
, GTU
,
1255 UNORDERED
, ORDERED
, UNEQ
, UNGE
, UNGT
, UNLE
,
1257 #ifdef PREDICATE_CODES
1261 #define NUM_KNOWN_OLD_PREDS ARRAY_SIZE (old_preds)
1263 /* This table gives the initial set of special predicates. It has
1264 entries for all special predicates defined in recog.c. The back
1265 end can define SPECIAL_MODE_PREDICATES to give additional entries
1266 for the table; this is considered an obsolete mechanism (use
1267 define_special_predicate instead). */
1268 static const char *const old_special_pred_table
[] = {
1270 "pmode_register_operand",
1271 #ifdef SPECIAL_MODE_PREDICATES
1272 SPECIAL_MODE_PREDICATES
1276 #define NUM_OLD_SPECIAL_MODE_PREDS ARRAY_SIZE (old_special_pred_table)
1278 /* Initialize the table of predicate definitions, starting with
1279 the information we have on generic predicates, and the old-style
1280 PREDICATE_CODES definitions. */
1283 init_predicate_table (void)
1286 struct pred_data
*pred
;
1288 predicate_table
= htab_create_alloc (37, hash_struct_pred_data
,
1289 eq_struct_pred_data
, 0,
1292 for (i
= 0; i
< NUM_KNOWN_OLD_PREDS
; i
++)
1294 pred
= xcalloc (sizeof (struct pred_data
), 1);
1295 pred
->name
= old_preds
[i
].name
;
1297 for (j
= 0; old_preds
[i
].codes
[j
] != 0; j
++)
1299 enum rtx_code code
= old_preds
[i
].codes
[j
];
1301 pred
->codes
[code
] = true;
1302 if (GET_RTX_CLASS (code
) != RTX_CONST_OBJ
)
1303 pred
->allows_non_const
= true;
1309 && code
!= STRICT_LOW_PART
)
1310 pred
->allows_non_lvalue
= true;
1313 pred
->singleton
= old_preds
[i
].codes
[0];
1315 add_predicate (pred
);
1318 for (i
= 0; i
< NUM_OLD_SPECIAL_MODE_PREDS
; i
++)
1320 pred
= lookup_predicate (old_special_pred_table
[i
]);
1323 error ("old-style special predicate list refers "
1324 "to unknown predicate '%s'", old_special_pred_table
[i
]);
1327 pred
->special
= true;