1 /* Support routines for the various generation passes.
2 Copyright (C) 2000-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GCC is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
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/>. */
22 #include "coretypes.h"
28 #include "gensupport.h"
31 #define MAX_OPERANDS 40
33 static rtx operand_data
[MAX_OPERANDS
];
34 static rtx match_operand_entries_in_pattern
[MAX_OPERANDS
];
35 static char used_operands_numbers
[MAX_OPERANDS
];
38 /* In case some macros used by files we include need it, define this here. */
43 static struct obstack obstack
;
44 struct obstack
*rtl_obstack
= &obstack
;
46 /* Counter for patterns that generate code: define_insn, define_expand,
47 define_split, define_peephole, and define_peephole2. See read_md_rtx().
48 Any define_insn_and_splits are already in separate queues so that the
49 insn and the splitter get a unique number also. */
50 static int sequence_num
;
52 static int predicable_default
;
53 static const char *predicable_true
;
54 static const char *predicable_false
;
56 static const char *subst_true
= "yes";
57 static const char *subst_false
= "no";
59 static htab_t condition_table
;
61 /* We initially queue all patterns, process the define_insn,
62 define_cond_exec and define_subst patterns, then return
63 them one at a time. */
69 struct queue_elem
*next
;
70 /* In a DEFINE_INSN that came from a DEFINE_INSN_AND_SPLIT, SPLIT
71 points to the generated DEFINE_SPLIT. */
72 struct queue_elem
*split
;
75 #define MNEMONIC_ATTR_NAME "mnemonic"
76 #define MNEMONIC_HTAB_SIZE 1024
78 static struct queue_elem
*define_attr_queue
;
79 static struct queue_elem
**define_attr_tail
= &define_attr_queue
;
80 static struct queue_elem
*define_pred_queue
;
81 static struct queue_elem
**define_pred_tail
= &define_pred_queue
;
82 static struct queue_elem
*define_insn_queue
;
83 static struct queue_elem
**define_insn_tail
= &define_insn_queue
;
84 static struct queue_elem
*define_cond_exec_queue
;
85 static struct queue_elem
**define_cond_exec_tail
= &define_cond_exec_queue
;
86 static struct queue_elem
*define_subst_queue
;
87 static struct queue_elem
**define_subst_tail
= &define_subst_queue
;
88 static struct queue_elem
*other_queue
;
89 static struct queue_elem
**other_tail
= &other_queue
;
90 static struct queue_elem
*define_subst_attr_queue
;
91 static struct queue_elem
**define_subst_attr_tail
= &define_subst_attr_queue
;
93 static void remove_constraints (rtx
);
95 static int is_predicable (struct queue_elem
*);
96 static void identify_predicable_attribute (void);
97 static int n_alternatives (const char *);
98 static void collect_insn_data (rtx
, int *, int *);
99 static const char *alter_test_for_insn (struct queue_elem
*,
100 struct queue_elem
*);
101 static char *shift_output_template (char *, const char *, int);
102 static const char *alter_output_for_insn (struct queue_elem
*,
105 static void process_one_cond_exec (struct queue_elem
*);
106 static void process_define_cond_exec (void);
107 static void init_predicate_table (void);
108 static void record_insn_name (int, const char *);
110 static bool has_subst_attribute (struct queue_elem
*, struct queue_elem
*);
111 static const char * alter_output_for_subst_insn (rtx
, int);
112 static void alter_attrs_for_subst_insn (struct queue_elem
*, int);
113 static void process_substs_on_one_elem (struct queue_elem
*,
114 struct queue_elem
*);
115 static rtx
subst_dup (rtx
, int, int);
116 static void process_define_subst (void);
118 static const char * duplicate_alternatives (const char *, int);
119 static const char * duplicate_each_alternative (const char * str
, int n_dup
);
121 typedef const char * (*constraints_handler_t
) (const char *, int);
122 static rtx
alter_constraints (rtx
, int, constraints_handler_t
);
123 static rtx
adjust_operands_numbers (rtx
);
124 static rtx
replace_duplicating_operands_in_pattern (rtx
);
126 /* Make a version of gen_rtx_CONST_INT so that GEN_INT can be used in
127 the gensupport programs. */
130 gen_rtx_CONST_INT (machine_mode
ARG_UNUSED (mode
),
133 rtx rt
= rtx_alloc (CONST_INT
);
139 /* Return the rtx pattern specified by the list of rtxes in a
140 define_insn or define_split. */
143 add_implicit_parallel (rtvec vec
)
145 if (GET_NUM_ELEM (vec
) == 1)
146 return RTVEC_ELT (vec
, 0);
149 rtx pattern
= rtx_alloc (PARALLEL
);
150 XVEC (pattern
, 0) = vec
;
155 /* Predicate handling.
157 We construct from the machine description a table mapping each
158 predicate to a list of the rtl codes it can possibly match. The
159 function 'maybe_both_true' uses it to deduce that there are no
160 expressions that can be matches by certain pairs of tree nodes.
161 Also, if a predicate can match only one code, we can hardwire that
162 code into the node testing the predicate.
164 Some predicates are flagged as special. validate_pattern will not
165 warn about modeless match_operand expressions if they have a
166 special predicate. Predicates that allow only constants are also
167 treated as special, for this purpose.
169 validate_pattern will warn about predicates that allow non-lvalues
170 when they appear in destination operands.
172 Calculating the set of rtx codes that can possibly be accepted by a
173 predicate expression EXP requires a three-state logic: any given
174 subexpression may definitively accept a code C (Y), definitively
175 reject a code C (N), or may have an indeterminate effect (I). N
176 and I is N; Y or I is Y; Y and I, N or I are both I. Here are full
187 We represent Y with 1, N with 0, I with 2. If any code is left in
188 an I state by the complete expression, we must assume that that
189 code can be accepted. */
195 #define TRISTATE_AND(a,b) \
196 ((a) == I ? ((b) == N ? N : I) : \
197 (b) == I ? ((a) == N ? N : I) : \
200 #define TRISTATE_OR(a,b) \
201 ((a) == I ? ((b) == Y ? Y : I) : \
202 (b) == I ? ((a) == Y ? Y : I) : \
205 #define TRISTATE_NOT(a) \
206 ((a) == I ? I : !(a))
208 /* 0 means no warning about that code yet, 1 means warned. */
209 static char did_you_mean_codes
[NUM_RTX_CODE
];
211 /* Recursively calculate the set of rtx codes accepted by the
212 predicate expression EXP, writing the result to CODES. LOC is
213 the .md file location of the directive containing EXP. */
216 compute_test_codes (rtx exp
, file_location loc
, char *codes
)
218 char op0_codes
[NUM_RTX_CODE
];
219 char op1_codes
[NUM_RTX_CODE
];
220 char op2_codes
[NUM_RTX_CODE
];
223 switch (GET_CODE (exp
))
226 compute_test_codes (XEXP (exp
, 0), loc
, op0_codes
);
227 compute_test_codes (XEXP (exp
, 1), loc
, op1_codes
);
228 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
229 codes
[i
] = TRISTATE_AND (op0_codes
[i
], op1_codes
[i
]);
233 compute_test_codes (XEXP (exp
, 0), loc
, op0_codes
);
234 compute_test_codes (XEXP (exp
, 1), loc
, op1_codes
);
235 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
236 codes
[i
] = TRISTATE_OR (op0_codes
[i
], op1_codes
[i
]);
239 compute_test_codes (XEXP (exp
, 0), loc
, op0_codes
);
240 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
241 codes
[i
] = TRISTATE_NOT (op0_codes
[i
]);
245 /* a ? b : c accepts the same codes as (a & b) | (!a & c). */
246 compute_test_codes (XEXP (exp
, 0), loc
, op0_codes
);
247 compute_test_codes (XEXP (exp
, 1), loc
, op1_codes
);
248 compute_test_codes (XEXP (exp
, 2), loc
, op2_codes
);
249 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
250 codes
[i
] = TRISTATE_OR (TRISTATE_AND (op0_codes
[i
], op1_codes
[i
]),
251 TRISTATE_AND (TRISTATE_NOT (op0_codes
[i
]),
256 /* MATCH_CODE allows a specified list of codes. However, if it
257 does not apply to the top level of the expression, it does not
258 constrain the set of codes for the top level. */
259 if (XSTR (exp
, 1)[0] != '\0')
261 memset (codes
, Y
, NUM_RTX_CODE
);
265 memset (codes
, N
, NUM_RTX_CODE
);
267 const char *next_code
= XSTR (exp
, 0);
270 if (*next_code
== '\0')
272 error_at (loc
, "empty match_code expression");
276 while ((code
= scan_comma_elt (&next_code
)) != 0)
278 size_t n
= next_code
- code
;
281 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
282 if (!strncmp (code
, GET_RTX_NAME (i
), n
)
283 && GET_RTX_NAME (i
)[n
] == '\0')
291 error_at (loc
, "match_code \"%.*s\" matches nothing",
293 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
294 if (!strncasecmp (code
, GET_RTX_NAME (i
), n
)
295 && GET_RTX_NAME (i
)[n
] == '\0'
296 && !did_you_mean_codes
[i
])
298 did_you_mean_codes
[i
] = 1;
299 message_at (loc
, "(did you mean \"%s\"?)",
308 /* MATCH_OPERAND disallows the set of codes that the named predicate
309 disallows, and is indeterminate for the codes that it does allow. */
311 struct pred_data
*p
= lookup_predicate (XSTR (exp
, 1));
314 error_at (loc
, "reference to unknown predicate '%s'",
318 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
319 codes
[i
] = p
->codes
[i
] ? I
: N
;
325 /* (match_test WHATEVER) is completely indeterminate. */
326 memset (codes
, I
, NUM_RTX_CODE
);
330 error_at (loc
, "'%s' cannot be used in predicates or constraints",
331 GET_RTX_NAME (GET_CODE (exp
)));
332 memset (codes
, I
, NUM_RTX_CODE
);
341 /* Return true if NAME is a valid predicate name. */
344 valid_predicate_name_p (const char *name
)
348 if (!ISALPHA (name
[0]) && name
[0] != '_')
350 for (p
= name
+ 1; *p
; p
++)
351 if (!ISALNUM (*p
) && *p
!= '_')
356 /* Process define_predicate directive DESC, which appears at location LOC.
357 Compute the set of codes that can be matched, and record this as a known
361 process_define_predicate (rtx desc
, file_location loc
)
363 struct pred_data
*pred
;
364 char codes
[NUM_RTX_CODE
];
367 if (!valid_predicate_name_p (XSTR (desc
, 0)))
369 error_at (loc
, "%s: predicate name must be a valid C function name",
374 pred
= XCNEW (struct pred_data
);
375 pred
->name
= XSTR (desc
, 0);
376 pred
->exp
= XEXP (desc
, 1);
377 pred
->c_block
= XSTR (desc
, 2);
378 if (GET_CODE (desc
) == DEFINE_SPECIAL_PREDICATE
)
379 pred
->special
= true;
381 compute_test_codes (XEXP (desc
, 1), loc
, codes
);
383 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
385 add_predicate_code (pred
, (enum rtx_code
) i
);
387 add_predicate (pred
);
393 /* Queue PATTERN on LIST_TAIL. Return the address of the new queue
396 static struct queue_elem
*
397 queue_pattern (rtx pattern
, struct queue_elem
***list_tail
,
400 struct queue_elem
*e
= XNEW (struct queue_elem
);
406 *list_tail
= &e
->next
;
410 /* Remove element ELEM from QUEUE. */
412 remove_from_queue (struct queue_elem
*elem
, struct queue_elem
**queue
)
414 struct queue_elem
*prev
, *e
;
416 for (e
= *queue
; e
; e
= e
->next
)
426 prev
->next
= elem
->next
;
431 /* Build a define_attr for an binary attribute with name NAME and
432 possible values "yes" and "no", and queue it. */
434 add_define_attr (const char *name
)
436 struct queue_elem
*e
= XNEW (struct queue_elem
);
437 rtx t1
= rtx_alloc (DEFINE_ATTR
);
439 XSTR (t1
, 1) = "no,yes";
440 XEXP (t1
, 2) = rtx_alloc (CONST_STRING
);
441 XSTR (XEXP (t1
, 2), 0) = "yes";
443 e
->loc
= file_location ("built-in", -1);
444 e
->next
= define_attr_queue
;
445 define_attr_queue
= e
;
449 /* Recursively remove constraints from an rtx. */
452 remove_constraints (rtx part
)
455 const char *format_ptr
;
460 if (GET_CODE (part
) == MATCH_OPERAND
)
462 else if (GET_CODE (part
) == MATCH_SCRATCH
)
465 format_ptr
= GET_RTX_FORMAT (GET_CODE (part
));
467 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (part
)); i
++)
468 switch (*format_ptr
++)
472 remove_constraints (XEXP (part
, i
));
475 if (XVEC (part
, i
) != NULL
)
476 for (j
= 0; j
< XVECLEN (part
, i
); j
++)
477 remove_constraints (XVECEXP (part
, i
, j
));
482 /* Process a top level rtx in some way, queuing as appropriate. */
485 process_rtx (rtx desc
, file_location loc
)
487 switch (GET_CODE (desc
))
490 queue_pattern (desc
, &define_insn_tail
, loc
);
493 case DEFINE_COND_EXEC
:
494 queue_pattern (desc
, &define_cond_exec_tail
, loc
);
498 queue_pattern (desc
, &define_subst_tail
, loc
);
501 case DEFINE_SUBST_ATTR
:
502 queue_pattern (desc
, &define_subst_attr_tail
, loc
);
506 case DEFINE_ENUM_ATTR
:
507 queue_pattern (desc
, &define_attr_tail
, loc
);
510 case DEFINE_PREDICATE
:
511 case DEFINE_SPECIAL_PREDICATE
:
512 process_define_predicate (desc
, loc
);
515 case DEFINE_CONSTRAINT
:
516 case DEFINE_REGISTER_CONSTRAINT
:
517 case DEFINE_MEMORY_CONSTRAINT
:
518 case DEFINE_ADDRESS_CONSTRAINT
:
519 queue_pattern (desc
, &define_pred_tail
, loc
);
522 case DEFINE_INSN_AND_SPLIT
:
524 const char *split_cond
;
528 struct queue_elem
*insn_elem
;
529 struct queue_elem
*split_elem
;
531 /* Create a split with values from the insn_and_split. */
532 split
= rtx_alloc (DEFINE_SPLIT
);
534 i
= XVECLEN (desc
, 1);
535 XVEC (split
, 0) = rtvec_alloc (i
);
538 XVECEXP (split
, 0, i
) = copy_rtx (XVECEXP (desc
, 1, i
));
539 remove_constraints (XVECEXP (split
, 0, i
));
542 /* If the split condition starts with "&&", append it to the
543 insn condition to create the new split condition. */
544 split_cond
= XSTR (desc
, 4);
545 if (split_cond
[0] == '&' && split_cond
[1] == '&')
547 copy_md_ptr_loc (split_cond
+ 2, split_cond
);
548 split_cond
= join_c_conditions (XSTR (desc
, 2), split_cond
+ 2);
550 XSTR (split
, 1) = split_cond
;
551 XVEC (split
, 2) = XVEC (desc
, 5);
552 XSTR (split
, 3) = XSTR (desc
, 6);
554 /* Fix up the DEFINE_INSN. */
555 attr
= XVEC (desc
, 7);
556 PUT_CODE (desc
, DEFINE_INSN
);
557 XVEC (desc
, 4) = attr
;
560 insn_elem
= queue_pattern (desc
, &define_insn_tail
, loc
);
561 split_elem
= queue_pattern (split
, &other_tail
, loc
);
562 insn_elem
->split
= split_elem
;
567 queue_pattern (desc
, &other_tail
, loc
);
572 /* Return true if attribute PREDICABLE is true for ELEM, which holds
576 is_predicable (struct queue_elem
*elem
)
578 rtvec vec
= XVEC (elem
->data
, 4);
583 return predicable_default
;
585 for (i
= GET_NUM_ELEM (vec
) - 1; i
>= 0; --i
)
587 rtx sub
= RTVEC_ELT (vec
, i
);
588 switch (GET_CODE (sub
))
591 if (strcmp (XSTR (sub
, 0), "predicable") == 0)
593 value
= XSTR (sub
, 1);
598 case SET_ATTR_ALTERNATIVE
:
599 if (strcmp (XSTR (sub
, 0), "predicable") == 0)
601 error_at (elem
->loc
, "multiple alternatives for `predicable'");
607 if (GET_CODE (SET_DEST (sub
)) != ATTR
608 || strcmp (XSTR (SET_DEST (sub
), 0), "predicable") != 0)
611 if (GET_CODE (sub
) == CONST_STRING
)
613 value
= XSTR (sub
, 0);
617 /* ??? It would be possible to handle this if we really tried.
618 It's not easy though, and I'm not going to bother until it
619 really proves necessary. */
620 error_at (elem
->loc
, "non-constant value for `predicable'");
628 return predicable_default
;
631 /* Find out which value we're looking at. Multiple alternatives means at
632 least one is predicable. */
633 if (strchr (value
, ',') != NULL
)
635 if (strcmp (value
, predicable_true
) == 0)
637 if (strcmp (value
, predicable_false
) == 0)
640 error_at (elem
->loc
, "unknown value `%s' for `predicable' attribute", value
);
644 /* Find attribute SUBST in ELEM and assign NEW_VALUE to it. */
646 change_subst_attribute (struct queue_elem
*elem
,
647 struct queue_elem
*subst_elem
,
648 const char *new_value
)
650 rtvec attrs_vec
= XVEC (elem
->data
, 4);
651 const char *subst_name
= XSTR (subst_elem
->data
, 0);
657 for (i
= GET_NUM_ELEM (attrs_vec
) - 1; i
>= 0; --i
)
659 rtx cur_attr
= RTVEC_ELT (attrs_vec
, i
);
660 if (GET_CODE (cur_attr
) != SET_ATTR
)
662 if (strcmp (XSTR (cur_attr
, 0), subst_name
) == 0)
664 XSTR (cur_attr
, 1) = new_value
;
670 /* Return true if ELEM has the attribute with the name of DEFINE_SUBST
671 represented by SUBST_ELEM and this attribute has value SUBST_TRUE.
672 DEFINE_SUBST isn't applied to patterns without such attribute. In other
673 words, we suppose the default value of the attribute to be 'no' since it is
674 always generated automaticaly in read-rtl.c. */
676 has_subst_attribute (struct queue_elem
*elem
, struct queue_elem
*subst_elem
)
678 rtvec attrs_vec
= XVEC (elem
->data
, 4);
679 const char *value
, *subst_name
= XSTR (subst_elem
->data
, 0);
685 for (i
= GET_NUM_ELEM (attrs_vec
) - 1; i
>= 0; --i
)
687 rtx cur_attr
= RTVEC_ELT (attrs_vec
, i
);
688 switch (GET_CODE (cur_attr
))
691 if (strcmp (XSTR (cur_attr
, 0), subst_name
) == 0)
693 value
= XSTR (cur_attr
, 1);
699 if (GET_CODE (SET_DEST (cur_attr
)) != ATTR
700 || strcmp (XSTR (SET_DEST (cur_attr
), 0), subst_name
) != 0)
702 cur_attr
= SET_SRC (cur_attr
);
703 if (GET_CODE (cur_attr
) == CONST_STRING
)
705 value
= XSTR (cur_attr
, 0);
709 /* Only (set_attr "subst" "yes/no") and
710 (set (attr "subst" (const_string "yes/no")))
711 are currently allowed. */
712 error_at (elem
->loc
, "unsupported value for `%s'", subst_name
);
715 case SET_ATTR_ALTERNATIVE
:
717 "%s: `set_attr_alternative' is unsupported by "
718 "`define_subst'", XSTR (elem
->data
, 0));
730 if (strcmp (value
, subst_true
) == 0)
732 if (strcmp (value
, subst_false
) == 0)
735 error_at (elem
->loc
, "unknown value `%s' for `%s' attribute",
740 /* Compare RTL-template of original define_insn X to input RTL-template of
741 define_subst PT. Return 1 if the templates match, 0 otherwise.
742 During the comparison, the routine also fills global_array OPERAND_DATA. */
744 subst_pattern_match (rtx x
, rtx pt
, file_location loc
)
746 RTX_CODE code
, code_pt
;
748 const char *fmt
, *pred_name
;
751 code_pt
= GET_CODE (pt
);
753 if (code_pt
== MATCH_OPERAND
)
755 /* MATCH_DUP, and MATCH_OP_DUP don't have a specified mode, so we
756 always accept them. */
757 if (GET_MODE (pt
) != VOIDmode
&& GET_MODE (x
) != GET_MODE (pt
)
758 && (code
!= MATCH_DUP
&& code
!= MATCH_OP_DUP
))
759 return false; /* Modes don't match. */
761 if (code
== MATCH_OPERAND
)
763 pred_name
= XSTR (pt
, 1);
764 if (pred_name
[0] != 0)
766 const struct pred_data
*pred_pt
= lookup_predicate (pred_name
);
767 if (!pred_pt
|| pred_pt
!= lookup_predicate (XSTR (x
, 1)))
768 return false; /* Predicates don't match. */
772 gcc_assert (XINT (pt
, 0) >= 0 && XINT (pt
, 0) < MAX_OPERANDS
);
773 operand_data
[XINT (pt
, 0)] = x
;
777 if (code_pt
== MATCH_OPERATOR
)
779 int x_vecexp_pos
= -1;
782 if (GET_MODE (pt
) != VOIDmode
&& GET_MODE (x
) != GET_MODE (pt
))
785 /* In case X is also match_operator, compare predicates. */
786 if (code
== MATCH_OPERATOR
)
788 pred_name
= XSTR (pt
, 1);
789 if (pred_name
[0] != 0)
791 const struct pred_data
*pred_pt
= lookup_predicate (pred_name
);
792 if (!pred_pt
|| pred_pt
!= lookup_predicate (XSTR (x
, 1)))
798 MATCH_OPERATOR in input template could match in original template
799 either 1) MATCH_OPERAND, 2) UNSPEC, 3) ordinary operation (like PLUS).
800 In the first case operands are at (XVECEXP (x, 2, j)), in the second
801 - at (XVECEXP (x, 0, j)), in the last one - (XEXP (x, j)).
802 X_VECEXP_POS variable shows, where to look for these operands. */
804 || code
== UNSPEC_VOLATILE
)
806 else if (code
== MATCH_OPERATOR
)
811 /* MATCH_OPERATOR or UNSPEC case. */
812 if (x_vecexp_pos
>= 0)
814 /* Compare operands number in X and PT. */
815 if (XVECLEN (x
, x_vecexp_pos
) != XVECLEN (pt
, 2))
817 for (j
= 0; j
< XVECLEN (pt
, 2); j
++)
818 if (!subst_pattern_match (XVECEXP (x
, x_vecexp_pos
, j
),
819 XVECEXP (pt
, 2, j
), loc
))
823 /* Ordinary operator. */
826 /* Compare operands number in X and PT.
827 We count operands differently for X and PT since we compare
828 an operator (with operands directly in RTX) and MATCH_OPERATOR
829 (that has a vector with operands). */
830 if (GET_RTX_LENGTH (code
) != XVECLEN (pt
, 2))
832 for (j
= 0; j
< XVECLEN (pt
, 2); j
++)
833 if (!subst_pattern_match (XEXP (x
, j
), XVECEXP (pt
, 2, j
), loc
))
837 /* Store the operand to OPERAND_DATA array. */
838 gcc_assert (XINT (pt
, 0) >= 0 && XINT (pt
, 0) < MAX_OPERANDS
);
839 operand_data
[XINT (pt
, 0)] = x
;
843 if (code_pt
== MATCH_PAR_DUP
844 || code_pt
== MATCH_DUP
845 || code_pt
== MATCH_OP_DUP
846 || code_pt
== MATCH_SCRATCH
847 || code_pt
== MATCH_PARALLEL
)
849 /* Currently interface for these constructions isn't defined -
850 probably they aren't needed in input template of define_subst at all.
851 So, for now their usage in define_subst is forbidden. */
852 error_at (loc
, "%s cannot be used in define_subst",
853 GET_RTX_NAME (code_pt
));
856 gcc_assert (code
!= MATCH_PAR_DUP
857 && code_pt
!= MATCH_DUP
858 && code_pt
!= MATCH_OP_DUP
859 && code_pt
!= MATCH_SCRATCH
860 && code_pt
!= MATCH_PARALLEL
861 && code_pt
!= MATCH_OPERAND
862 && code_pt
!= MATCH_OPERATOR
);
863 /* If PT is none of the handled above, then we match only expressions with
864 the same code in X. */
868 fmt
= GET_RTX_FORMAT (code_pt
);
869 len
= GET_RTX_LENGTH (code_pt
);
871 for (i
= 0; i
< len
; i
++)
878 case 'i': case 'r': case 'w': case 's':
882 if (!subst_pattern_match (XEXP (x
, i
), XEXP (pt
, i
), loc
))
887 if (XVECLEN (x
, i
) != XVECLEN (pt
, i
))
889 for (j
= 0; j
< XVECLEN (pt
, i
); j
++)
890 if (!subst_pattern_match (XVECEXP (x
, i
, j
),
891 XVECEXP (pt
, i
, j
), loc
))
903 /* Examine the attribute "predicable"; discover its boolean values
907 identify_predicable_attribute (void)
909 struct queue_elem
*elem
;
910 char *p_true
, *p_false
;
913 /* Look for the DEFINE_ATTR for `predicable', which must exist. */
914 for (elem
= define_attr_queue
; elem
; elem
= elem
->next
)
915 if (strcmp (XSTR (elem
->data
, 0), "predicable") == 0)
918 error_at (define_cond_exec_queue
->loc
,
919 "attribute `predicable' not defined");
923 value
= XSTR (elem
->data
, 1);
924 p_false
= xstrdup (value
);
925 p_true
= strchr (p_false
, ',');
926 if (p_true
== NULL
|| strchr (++p_true
, ',') != NULL
)
928 error_at (elem
->loc
, "attribute `predicable' is not a boolean");
934 predicable_true
= p_true
;
935 predicable_false
= p_false
;
937 switch (GET_CODE (XEXP (elem
->data
, 2)))
940 value
= XSTR (XEXP (elem
->data
, 2), 0);
944 error_at (elem
->loc
, "attribute `predicable' cannot be const");
950 "attribute `predicable' must have a constant default");
955 if (strcmp (value
, p_true
) == 0)
956 predicable_default
= 1;
957 else if (strcmp (value
, p_false
) == 0)
958 predicable_default
= 0;
961 error_at (elem
->loc
, "unknown value `%s' for `predicable' attribute",
967 /* Return the number of alternatives in constraint S. */
970 n_alternatives (const char *s
)
981 /* The routine scans rtl PATTERN, find match_operand in it and counts
982 number of alternatives. If PATTERN contains several match_operands
983 with different number of alternatives, error is emitted, and the
984 routine returns 0. If all match_operands in PATTERN have the same
985 number of alternatives, it's stored in N_ALT, and the routine returns 1.
986 LOC is the location of PATTERN, for error reporting. */
988 get_alternatives_number (rtx pattern
, int *n_alt
, file_location loc
)
997 code
= GET_CODE (pattern
);
1001 i
= n_alternatives (XSTR (pattern
, 2));
1002 /* n_alternatives returns 1 if constraint string is empty -
1003 here we fix it up. */
1004 if (!*(XSTR (pattern
, 2)))
1009 else if (i
&& i
!= *n_alt
)
1011 error_at (loc
, "wrong number of alternatives in operand %d",
1020 fmt
= GET_RTX_FORMAT (code
);
1021 len
= GET_RTX_LENGTH (code
);
1022 for (i
= 0; i
< len
; i
++)
1027 if (!get_alternatives_number (XEXP (pattern
, i
), n_alt
, loc
))
1032 if (XVEC (pattern
, i
) == NULL
)
1036 for (j
= XVECLEN (pattern
, i
) - 1; j
>= 0; --j
)
1037 if (!get_alternatives_number (XVECEXP (pattern
, i
, j
), n_alt
, loc
))
1041 case 'i': case 'r': case 'w': case '0': case 's': case 'S': case 'T':
1051 /* Determine how many alternatives there are in INSN, and how many
1055 collect_insn_data (rtx pattern
, int *palt
, int *pmax
)
1061 code
= GET_CODE (pattern
);
1065 i
= n_alternatives (XSTR (pattern
, 2));
1066 *palt
= (i
> *palt
? i
: *palt
);
1069 case MATCH_OPERATOR
:
1071 case MATCH_PARALLEL
:
1072 i
= XINT (pattern
, 0);
1081 fmt
= GET_RTX_FORMAT (code
);
1082 len
= GET_RTX_LENGTH (code
);
1083 for (i
= 0; i
< len
; i
++)
1088 collect_insn_data (XEXP (pattern
, i
), palt
, pmax
);
1092 if (XVEC (pattern
, i
) == NULL
)
1096 for (j
= XVECLEN (pattern
, i
) - 1; j
>= 0; --j
)
1097 collect_insn_data (XVECEXP (pattern
, i
, j
), palt
, pmax
);
1100 case 'i': case 'r': case 'w': case '0': case 's': case 'S': case 'T':
1110 alter_predicate_for_insn (rtx pattern
, int alt
, int max_op
,
1117 code
= GET_CODE (pattern
);
1122 const char *c
= XSTR (pattern
, 2);
1124 if (n_alternatives (c
) != 1)
1126 error_at (loc
, "too many alternatives for operand %d",
1131 /* Replicate C as needed to fill out ALT alternatives. */
1132 if (c
&& *c
&& alt
> 1)
1134 size_t c_len
= strlen (c
);
1135 size_t len
= alt
* (c_len
+ 1);
1136 char *new_c
= XNEWVEC (char, len
);
1138 memcpy (new_c
, c
, c_len
);
1139 for (i
= 1; i
< alt
; ++i
)
1141 new_c
[i
* (c_len
+ 1) - 1] = ',';
1142 memcpy (&new_c
[i
* (c_len
+ 1)], c
, c_len
);
1144 new_c
[len
- 1] = '\0';
1145 XSTR (pattern
, 2) = new_c
;
1150 case MATCH_OPERATOR
:
1152 case MATCH_PARALLEL
:
1153 XINT (pattern
, 0) += max_op
;
1160 fmt
= GET_RTX_FORMAT (code
);
1161 len
= GET_RTX_LENGTH (code
);
1162 for (i
= 0; i
< len
; i
++)
1169 r
= alter_predicate_for_insn (XEXP (pattern
, i
), alt
, max_op
, loc
);
1175 for (j
= XVECLEN (pattern
, i
) - 1; j
>= 0; --j
)
1177 r
= alter_predicate_for_insn (XVECEXP (pattern
, i
, j
),
1184 case 'i': case 'r': case 'w': case '0': case 's':
1195 /* Duplicate constraints in PATTERN. If pattern is from original
1196 rtl-template, we need to duplicate each alternative - for that we
1197 need to use duplicate_each_alternative () as a functor ALTER.
1198 If pattern is from output-pattern of define_subst, we need to
1199 duplicate constraints in another way - with duplicate_alternatives ().
1200 N_DUP is multiplication factor. */
1202 alter_constraints (rtx pattern
, int n_dup
, constraints_handler_t alter
)
1208 code
= GET_CODE (pattern
);
1212 XSTR (pattern
, 2) = alter (XSTR (pattern
, 2), n_dup
);
1219 fmt
= GET_RTX_FORMAT (code
);
1220 len
= GET_RTX_LENGTH (code
);
1221 for (i
= 0; i
< len
; i
++)
1228 r
= alter_constraints (XEXP (pattern
, i
), n_dup
, alter
);
1234 for (j
= XVECLEN (pattern
, i
) - 1; j
>= 0; --j
)
1236 r
= alter_constraints (XVECEXP (pattern
, i
, j
), n_dup
, alter
);
1242 case 'i': case 'r': case 'w': case '0': case 's':
1254 alter_test_for_insn (struct queue_elem
*ce_elem
,
1255 struct queue_elem
*insn_elem
)
1257 return join_c_conditions (XSTR (ce_elem
->data
, 1),
1258 XSTR (insn_elem
->data
, 2));
1261 /* Modify VAL, which is an attribute expression for the "enabled" attribute,
1262 to take "ce_enabled" into account. Return the new expression. */
1264 modify_attr_enabled_ce (rtx val
)
1268 eq_attr
= rtx_alloc (EQ_ATTR
);
1269 ite
= rtx_alloc (IF_THEN_ELSE
);
1270 str
= rtx_alloc (CONST_STRING
);
1272 XSTR (eq_attr
, 0) = "ce_enabled";
1273 XSTR (eq_attr
, 1) = "yes";
1274 XSTR (str
, 0) = "no";
1275 XEXP (ite
, 0) = eq_attr
;
1276 XEXP (ite
, 1) = val
;
1277 XEXP (ite
, 2) = str
;
1282 /* Alter the attribute vector of INSN, which is a COND_EXEC variant created
1283 from a define_insn pattern. We must modify the "predicable" attribute
1284 to be named "ce_enabled", and also change any "enabled" attribute that's
1285 present so that it takes ce_enabled into account.
1286 We rely on the fact that INSN was created with copy_rtx, and modify data
1290 alter_attrs_for_insn (rtx insn
)
1292 static bool global_changes_made
= false;
1293 rtvec vec
= XVEC (insn
, 4);
1297 int predicable_idx
= -1;
1298 int enabled_idx
= -1;
1304 num_elem
= GET_NUM_ELEM (vec
);
1305 for (i
= num_elem
- 1; i
>= 0; --i
)
1307 rtx sub
= RTVEC_ELT (vec
, i
);
1308 switch (GET_CODE (sub
))
1311 if (strcmp (XSTR (sub
, 0), "predicable") == 0)
1314 XSTR (sub
, 0) = "ce_enabled";
1316 else if (strcmp (XSTR (sub
, 0), "enabled") == 0)
1319 XSTR (sub
, 0) = "nonce_enabled";
1323 case SET_ATTR_ALTERNATIVE
:
1324 if (strcmp (XSTR (sub
, 0), "predicable") == 0)
1325 /* We already give an error elsewhere. */
1327 else if (strcmp (XSTR (sub
, 0), "enabled") == 0)
1330 XSTR (sub
, 0) = "nonce_enabled";
1335 if (GET_CODE (SET_DEST (sub
)) != ATTR
)
1337 if (strcmp (XSTR (SET_DEST (sub
), 0), "predicable") == 0)
1339 sub
= SET_SRC (sub
);
1340 if (GET_CODE (sub
) == CONST_STRING
)
1343 XSTR (sub
, 0) = "ce_enabled";
1346 /* We already give an error elsewhere. */
1350 if (strcmp (XSTR (SET_DEST (sub
), 0), "enabled") == 0)
1353 XSTR (SET_DEST (sub
), 0) = "nonce_enabled";
1361 if (predicable_idx
== -1)
1364 if (!global_changes_made
)
1366 struct queue_elem
*elem
;
1368 global_changes_made
= true;
1369 add_define_attr ("ce_enabled");
1370 add_define_attr ("nonce_enabled");
1372 for (elem
= define_attr_queue
; elem
; elem
= elem
->next
)
1373 if (strcmp (XSTR (elem
->data
, 0), "enabled") == 0)
1375 XEXP (elem
->data
, 2)
1376 = modify_attr_enabled_ce (XEXP (elem
->data
, 2));
1379 if (enabled_idx
== -1)
1382 new_vec
= rtvec_alloc (num_elem
+ 1);
1383 for (i
= 0; i
< num_elem
; i
++)
1384 RTVEC_ELT (new_vec
, i
) = RTVEC_ELT (vec
, i
);
1385 val
= rtx_alloc (IF_THEN_ELSE
);
1386 XEXP (val
, 0) = rtx_alloc (EQ_ATTR
);
1387 XEXP (val
, 1) = rtx_alloc (CONST_STRING
);
1388 XEXP (val
, 2) = rtx_alloc (CONST_STRING
);
1389 XSTR (XEXP (val
, 0), 0) = "nonce_enabled";
1390 XSTR (XEXP (val
, 0), 1) = "yes";
1391 XSTR (XEXP (val
, 1), 0) = "yes";
1392 XSTR (XEXP (val
, 2), 0) = "no";
1393 set
= rtx_alloc (SET
);
1394 SET_DEST (set
) = rtx_alloc (ATTR
);
1395 XSTR (SET_DEST (set
), 0) = "enabled";
1396 SET_SRC (set
) = modify_attr_enabled_ce (val
);
1397 RTVEC_ELT (new_vec
, i
) = set
;
1398 XVEC (insn
, 4) = new_vec
;
1401 /* As number of constraints is changed after define_subst, we need to
1402 process attributes as well - we need to duplicate them the same way
1403 that we duplicated constraints in original pattern
1404 ELEM is a queue element, containing our rtl-template,
1405 N_DUP - multiplication factor. */
1407 alter_attrs_for_subst_insn (struct queue_elem
* elem
, int n_dup
)
1409 rtvec vec
= XVEC (elem
->data
, 4);
1413 if (n_dup
< 2 || ! vec
)
1416 num_elem
= GET_NUM_ELEM (vec
);
1417 for (i
= num_elem
- 1; i
>= 0; --i
)
1419 rtx sub
= RTVEC_ELT (vec
, i
);
1420 switch (GET_CODE (sub
))
1423 if (strchr (XSTR (sub
, 1), ',') != NULL
)
1424 XSTR (sub
, 1) = duplicate_alternatives (XSTR (sub
, 1), n_dup
);
1427 case SET_ATTR_ALTERNATIVE
:
1429 error_at (elem
->loc
,
1430 "%s: `define_subst' does not support attributes "
1431 "assigned by `set' and `set_attr_alternative'",
1432 XSTR (elem
->data
, 0));
1441 /* Adjust all of the operand numbers in SRC to match the shift they'll
1442 get from an operand displacement of DISP. Return a pointer after the
1446 shift_output_template (char *dest
, const char *src
, int disp
)
1455 if (ISDIGIT ((unsigned char) c
))
1457 else if (ISALPHA (c
))
1470 alter_output_for_insn (struct queue_elem
*ce_elem
,
1471 struct queue_elem
*insn_elem
,
1472 int alt
, int max_op
)
1474 const char *ce_out
, *insn_out
;
1476 size_t len
, ce_len
, insn_len
;
1478 /* ??? Could coordinate with genoutput to not duplicate code here. */
1480 ce_out
= XSTR (ce_elem
->data
, 2);
1481 insn_out
= XTMPL (insn_elem
->data
, 3);
1482 if (!ce_out
|| *ce_out
== '\0')
1485 ce_len
= strlen (ce_out
);
1486 insn_len
= strlen (insn_out
);
1488 if (*insn_out
== '*')
1489 /* You must take care of the predicate yourself. */
1492 if (*insn_out
== '@')
1494 len
= (ce_len
+ 1) * alt
+ insn_len
+ 1;
1495 p
= result
= XNEWVEC (char, len
);
1501 while (ISSPACE ((unsigned char) *insn_out
));
1503 if (*insn_out
!= '#')
1505 p
= shift_output_template (p
, ce_out
, max_op
);
1511 while (*insn_out
&& *insn_out
!= '\n');
1518 len
= ce_len
+ 1 + insn_len
+ 1;
1519 result
= XNEWVEC (char, len
);
1521 p
= shift_output_template (result
, ce_out
, max_op
);
1523 memcpy (p
, insn_out
, insn_len
+ 1);
1529 /* From string STR "a,b,c" produce "a,b,c,a,b,c,a,b,c", i.e. original
1530 string, duplicated N_DUP times. */
1533 duplicate_alternatives (const char * str
, int n_dup
)
1535 int i
, len
, new_len
;
1542 while (ISSPACE (*str
))
1550 new_len
= (len
+ 1) * n_dup
;
1552 sp
= result
= XNEWVEC (char, new_len
);
1554 /* Global modifier characters mustn't be duplicated: skip if found. */
1555 if (*cp
== '=' || *cp
== '+' || *cp
== '%')
1561 /* Copy original constraints N_DUP times. */
1562 for (i
= 0; i
< n_dup
; i
++, sp
+= len
+1)
1564 memcpy (sp
, cp
, len
);
1565 *(sp
+len
) = (i
== n_dup
- 1) ? '\0' : ',';
1571 /* From string STR "a,b,c" produce "a,a,a,b,b,b,c,c,c", i.e. string where
1572 each alternative from the original string is duplicated N_DUP times. */
1574 duplicate_each_alternative (const char * str
, int n_dup
)
1576 int i
, len
, new_len
;
1577 char *result
, *sp
, *ep
, *cp
;
1582 while (ISSPACE (*str
))
1590 new_len
= (strlen (cp
) + 1) * n_dup
;
1592 sp
= result
= XNEWVEC (char, new_len
);
1594 /* Global modifier characters mustn't be duplicated: skip if found. */
1595 if (*cp
== '=' || *cp
== '+' || *cp
== '%')
1600 if ((ep
= strchr (cp
, ',')) != NULL
)
1604 /* Copy a constraint N_DUP times. */
1605 for (i
= 0; i
< n_dup
; i
++, sp
+= len
+ 1)
1607 memcpy (sp
, cp
, len
);
1608 *(sp
+len
) = (ep
== NULL
&& i
== n_dup
- 1) ? '\0' : ',';
1618 /* Alter the output of INSN whose pattern was modified by
1619 DEFINE_SUBST. We must replicate output strings according
1620 to the new number of alternatives ALT in substituted pattern.
1621 If ALT equals 1, output has one alternative or defined by C
1622 code, then output is returned without any changes. */
1625 alter_output_for_subst_insn (rtx insn
, int alt
)
1627 const char *insn_out
, *sp
;
1628 char *old_out
, *new_out
, *cp
;
1631 insn_out
= XTMPL (insn
, 3);
1633 if (alt
< 2 || *insn_out
== '*' || *insn_out
!= '@')
1636 old_out
= XNEWVEC (char, strlen (insn_out
)),
1639 while (ISSPACE (*sp
) || *sp
== '@')
1643 old_out
[i
++] = *sp
++;
1645 new_len
= alt
* (i
+ 1) + 1;
1647 new_out
= XNEWVEC (char, new_len
);
1650 for (j
= 0, cp
= new_out
+ 1; j
< alt
; j
++, cp
+= i
+ 1)
1652 memcpy (cp
, old_out
, i
);
1653 *(cp
+i
) = (j
== alt
- 1) ? '\0' : '\n';
1659 /* Replicate insns as appropriate for the given DEFINE_COND_EXEC. */
1662 process_one_cond_exec (struct queue_elem
*ce_elem
)
1664 struct queue_elem
*insn_elem
;
1665 for (insn_elem
= define_insn_queue
; insn_elem
; insn_elem
= insn_elem
->next
)
1667 int alternatives
, max_operand
;
1668 rtx pred
, insn
, pattern
, split
;
1672 if (! is_predicable (insn_elem
))
1677 collect_insn_data (insn_elem
->data
, &alternatives
, &max_operand
);
1680 if (XVECLEN (ce_elem
->data
, 0) != 1)
1682 error_at (ce_elem
->loc
, "too many patterns in predicate");
1686 pred
= copy_rtx (XVECEXP (ce_elem
->data
, 0, 0));
1687 pred
= alter_predicate_for_insn (pred
, alternatives
, max_operand
,
1692 /* Construct a new pattern for the new insn. */
1693 insn
= copy_rtx (insn_elem
->data
);
1694 new_name
= XNEWVAR (char, strlen
XSTR (insn_elem
->data
, 0) + 4);
1695 sprintf (new_name
, "*p %s", XSTR (insn_elem
->data
, 0));
1696 XSTR (insn
, 0) = new_name
;
1697 pattern
= rtx_alloc (COND_EXEC
);
1698 XEXP (pattern
, 0) = pred
;
1699 XEXP (pattern
, 1) = add_implicit_parallel (XVEC (insn
, 1));
1700 XVEC (insn
, 1) = rtvec_alloc (1);
1701 XVECEXP (insn
, 1, 0) = pattern
;
1703 if (XVEC (ce_elem
->data
, 3) != NULL
)
1705 rtvec attributes
= rtvec_alloc (XVECLEN (insn
, 4)
1706 + XVECLEN (ce_elem
->data
, 3));
1709 for (i
= 0; i
< XVECLEN (insn
, 4); i
++)
1710 RTVEC_ELT (attributes
, i
) = XVECEXP (insn
, 4, i
);
1712 for (j
= 0; j
< XVECLEN (ce_elem
->data
, 3); j
++, i
++)
1713 RTVEC_ELT (attributes
, i
) = XVECEXP (ce_elem
->data
, 3, j
);
1715 XVEC (insn
, 4) = attributes
;
1718 XSTR (insn
, 2) = alter_test_for_insn (ce_elem
, insn_elem
);
1719 XTMPL (insn
, 3) = alter_output_for_insn (ce_elem
, insn_elem
,
1720 alternatives
, max_operand
);
1721 alter_attrs_for_insn (insn
);
1723 /* Put the new pattern on the `other' list so that it
1724 (a) is not reprocessed by other define_cond_exec patterns
1725 (b) appears after all normal define_insn patterns.
1727 ??? B is debatable. If one has normal insns that match
1728 cond_exec patterns, they will be preferred over these
1729 generated patterns. Whether this matters in practice, or if
1730 it's a good thing, or whether we should thread these new
1731 patterns into the define_insn chain just after their generator
1732 is something we'll have to experiment with. */
1734 queue_pattern (insn
, &other_tail
, insn_elem
->loc
);
1736 if (!insn_elem
->split
)
1739 /* If the original insn came from a define_insn_and_split,
1740 generate a new split to handle the predicated insn. */
1741 split
= copy_rtx (insn_elem
->split
->data
);
1742 /* Predicate the pattern matched by the split. */
1743 pattern
= rtx_alloc (COND_EXEC
);
1744 XEXP (pattern
, 0) = pred
;
1745 XEXP (pattern
, 1) = add_implicit_parallel (XVEC (split
, 0));
1746 XVEC (split
, 0) = rtvec_alloc (1);
1747 XVECEXP (split
, 0, 0) = pattern
;
1749 /* Predicate all of the insns generated by the split. */
1750 for (i
= 0; i
< XVECLEN (split
, 2); i
++)
1752 pattern
= rtx_alloc (COND_EXEC
);
1753 XEXP (pattern
, 0) = pred
;
1754 XEXP (pattern
, 1) = XVECEXP (split
, 2, i
);
1755 XVECEXP (split
, 2, i
) = pattern
;
1757 /* Add the new split to the queue. */
1758 queue_pattern (split
, &other_tail
, insn_elem
->split
->loc
);
1762 /* Try to apply define_substs to the given ELEM.
1763 Only define_substs, specified via attributes would be applied.
1764 If attribute, requiring define_subst, is set, but no define_subst
1765 was applied, ELEM would be deleted. */
1768 process_substs_on_one_elem (struct queue_elem
*elem
,
1769 struct queue_elem
*queue
)
1771 struct queue_elem
*subst_elem
;
1772 int i
, j
, patterns_match
;
1774 for (subst_elem
= define_subst_queue
;
1775 subst_elem
; subst_elem
= subst_elem
->next
)
1777 int alternatives
, alternatives_subst
;
1779 rtvec subst_pattern_vec
;
1781 if (!has_subst_attribute (elem
, subst_elem
))
1784 /* Compare original rtl-pattern from define_insn with input
1785 pattern from define_subst.
1786 Also, check if numbers of alternatives are the same in all
1788 if (XVECLEN (elem
->data
, 1) != XVECLEN (subst_elem
->data
, 1))
1792 alternatives_subst
= -1;
1793 for (j
= 0; j
< XVECLEN (elem
->data
, 1); j
++)
1795 if (!subst_pattern_match (XVECEXP (elem
->data
, 1, j
),
1796 XVECEXP (subst_elem
->data
, 1, j
),
1803 if (!get_alternatives_number (XVECEXP (elem
->data
, 1, j
),
1804 &alternatives
, subst_elem
->loc
))
1811 /* Check if numbers of alternatives are the same in all
1812 match_operands in output template of define_subst. */
1813 for (j
= 0; j
< XVECLEN (subst_elem
->data
, 3); j
++)
1815 if (!get_alternatives_number (XVECEXP (subst_elem
->data
, 3, j
),
1816 &alternatives_subst
,
1824 if (!patterns_match
)
1827 /* Clear array in which we save occupied indexes of operands. */
1828 memset (used_operands_numbers
, 0, sizeof (used_operands_numbers
));
1830 /* Create a pattern, based on the output one from define_subst. */
1831 subst_pattern_vec
= rtvec_alloc (XVECLEN (subst_elem
->data
, 3));
1832 for (j
= 0; j
< XVECLEN (subst_elem
->data
, 3); j
++)
1834 subst_pattern
= copy_rtx (XVECEXP (subst_elem
->data
, 3, j
));
1836 /* Duplicate constraints in substitute-pattern. */
1837 subst_pattern
= alter_constraints (subst_pattern
, alternatives
,
1838 duplicate_each_alternative
);
1840 subst_pattern
= adjust_operands_numbers (subst_pattern
);
1842 /* Substitute match_dup and match_op_dup in the new pattern and
1843 duplicate constraints. */
1844 subst_pattern
= subst_dup (subst_pattern
, alternatives
,
1845 alternatives_subst
);
1847 replace_duplicating_operands_in_pattern (subst_pattern
);
1849 /* We don't need any constraints in DEFINE_EXPAND. */
1850 if (GET_CODE (elem
->data
) == DEFINE_EXPAND
)
1851 remove_constraints (subst_pattern
);
1853 RTVEC_ELT (subst_pattern_vec
, j
) = subst_pattern
;
1855 XVEC (elem
->data
, 1) = subst_pattern_vec
;
1857 for (i
= 0; i
< MAX_OPERANDS
; i
++)
1858 match_operand_entries_in_pattern
[i
] = NULL
;
1860 if (GET_CODE (elem
->data
) == DEFINE_INSN
)
1862 XTMPL (elem
->data
, 3) =
1863 alter_output_for_subst_insn (elem
->data
, alternatives_subst
);
1864 alter_attrs_for_subst_insn (elem
, alternatives_subst
);
1867 /* Recalculate condition, joining conditions from original and
1868 DEFINE_SUBST input patterns. */
1869 XSTR (elem
->data
, 2) = join_c_conditions (XSTR (subst_elem
->data
, 2),
1870 XSTR (elem
->data
, 2));
1871 /* Mark that subst was applied by changing attribute from "yes"
1873 change_subst_attribute (elem
, subst_elem
, subst_false
);
1876 /* If ELEM contains a subst attribute with value "yes", then we
1877 expected that a subst would be applied, but it wasn't - so,
1878 we need to remove that elementto avoid duplicating. */
1879 for (subst_elem
= define_subst_queue
;
1880 subst_elem
; subst_elem
= subst_elem
->next
)
1882 if (has_subst_attribute (elem
, subst_elem
))
1884 remove_from_queue (elem
, &queue
);
1890 /* This is a subroutine of mark_operands_used_in_match_dup.
1891 This routine is marks all MATCH_OPERANDs inside PATTERN as occupied. */
1893 mark_operands_from_match_dup (rtx pattern
)
1896 int i
, j
, len
, opno
;
1898 if (GET_CODE (pattern
) == MATCH_OPERAND
1899 || GET_CODE (pattern
) == MATCH_OPERATOR
1900 || GET_CODE (pattern
) == MATCH_PARALLEL
)
1902 opno
= XINT (pattern
, 0);
1903 gcc_assert (opno
>= 0 && opno
< MAX_OPERANDS
);
1904 used_operands_numbers
[opno
] = 1;
1906 fmt
= GET_RTX_FORMAT (GET_CODE (pattern
));
1907 len
= GET_RTX_LENGTH (GET_CODE (pattern
));
1908 for (i
= 0; i
< len
; i
++)
1913 mark_operands_from_match_dup (XEXP (pattern
, i
));
1916 for (j
= XVECLEN (pattern
, i
) - 1; j
>= 0; --j
)
1917 mark_operands_from_match_dup (XVECEXP (pattern
, i
, j
));
1923 /* This is a subroutine of adjust_operands_numbers.
1924 It goes through all expressions in PATTERN and when MATCH_DUP is
1925 met, all MATCH_OPERANDs inside it is marked as occupied. The
1926 process of marking is done by routin mark_operands_from_match_dup. */
1928 mark_operands_used_in_match_dup (rtx pattern
)
1931 int i
, j
, len
, opno
;
1933 if (GET_CODE (pattern
) == MATCH_DUP
)
1935 opno
= XINT (pattern
, 0);
1936 gcc_assert (opno
>= 0 && opno
< MAX_OPERANDS
);
1937 mark_operands_from_match_dup (operand_data
[opno
]);
1940 fmt
= GET_RTX_FORMAT (GET_CODE (pattern
));
1941 len
= GET_RTX_LENGTH (GET_CODE (pattern
));
1942 for (i
= 0; i
< len
; i
++)
1947 mark_operands_used_in_match_dup (XEXP (pattern
, i
));
1950 for (j
= XVECLEN (pattern
, i
) - 1; j
>= 0; --j
)
1951 mark_operands_used_in_match_dup (XVECEXP (pattern
, i
, j
));
1957 /* This is subroutine of renumerate_operands_in_pattern.
1958 It finds first not-occupied operand-index. */
1960 find_first_unused_number_of_operand ()
1963 for (i
= 0; i
< MAX_OPERANDS
; i
++)
1964 if (!used_operands_numbers
[i
])
1966 return MAX_OPERANDS
;
1969 /* This is subroutine of adjust_operands_numbers.
1970 It visits all expressions in PATTERN and assigns not-occupied
1971 operand indexes to MATCH_OPERANDs and MATCH_OPERATORs of this
1974 renumerate_operands_in_pattern (rtx pattern
)
1978 int i
, j
, len
, new_opno
;
1979 code
= GET_CODE (pattern
);
1981 if (code
== MATCH_OPERAND
1982 || code
== MATCH_OPERATOR
)
1984 new_opno
= find_first_unused_number_of_operand ();
1985 gcc_assert (new_opno
>= 0 && new_opno
< MAX_OPERANDS
);
1986 XINT (pattern
, 0) = new_opno
;
1987 used_operands_numbers
[new_opno
] = 1;
1990 fmt
= GET_RTX_FORMAT (GET_CODE (pattern
));
1991 len
= GET_RTX_LENGTH (GET_CODE (pattern
));
1992 for (i
= 0; i
< len
; i
++)
1997 renumerate_operands_in_pattern (XEXP (pattern
, i
));
2000 for (j
= XVECLEN (pattern
, i
) - 1; j
>= 0; --j
)
2001 renumerate_operands_in_pattern (XVECEXP (pattern
, i
, j
));
2007 /* If output pattern of define_subst contains MATCH_DUP, then this
2008 expression would be replaced with the pattern, matched with
2009 MATCH_OPERAND from input pattern. This pattern could contain any
2010 number of MATCH_OPERANDs, MATCH_OPERATORs etc., so it's possible
2011 that a MATCH_OPERAND from output_pattern (if any) would have the
2012 same number, as MATCH_OPERAND from copied pattern. To avoid such
2013 indexes overlapping, we assign new indexes to MATCH_OPERANDs,
2014 laying in the output pattern outside of MATCH_DUPs. */
2016 adjust_operands_numbers (rtx pattern
)
2018 mark_operands_used_in_match_dup (pattern
);
2020 renumerate_operands_in_pattern (pattern
);
2025 /* Generate RTL expression
2029 generate_match_dup (int opno
)
2031 rtx return_rtx
= rtx_alloc (MATCH_DUP
);
2032 PUT_CODE (return_rtx
, MATCH_DUP
);
2033 XINT (return_rtx
, 0) = opno
;
2037 /* This routine checks all match_operands in PATTERN and if some of
2038 have the same index, it replaces all of them except the first one to
2040 Usually, match_operands with the same indexes are forbidden, but
2041 after define_subst copy an RTL-expression from original template,
2042 indexes of existed and just-copied match_operands could coincide.
2043 To fix it, we replace one of them with match_dup. */
2045 replace_duplicating_operands_in_pattern (rtx pattern
)
2048 int i
, j
, len
, opno
;
2051 if (GET_CODE (pattern
) == MATCH_OPERAND
)
2053 opno
= XINT (pattern
, 0);
2054 gcc_assert (opno
>= 0 && opno
< MAX_OPERANDS
);
2055 if (match_operand_entries_in_pattern
[opno
] == NULL
)
2057 match_operand_entries_in_pattern
[opno
] = pattern
;
2062 /* Compare predicates before replacing with match_dup. */
2063 if (strcmp (XSTR (pattern
, 1),
2064 XSTR (match_operand_entries_in_pattern
[opno
], 1)))
2066 error ("duplicated match_operands with different predicates were"
2070 return generate_match_dup (opno
);
2073 fmt
= GET_RTX_FORMAT (GET_CODE (pattern
));
2074 len
= GET_RTX_LENGTH (GET_CODE (pattern
));
2075 for (i
= 0; i
< len
; i
++)
2080 mdup
= replace_duplicating_operands_in_pattern (XEXP (pattern
, i
));
2082 XEXP (pattern
, i
) = mdup
;
2085 for (j
= XVECLEN (pattern
, i
) - 1; j
>= 0; --j
)
2088 replace_duplicating_operands_in_pattern (XVECEXP
2091 XVECEXP (pattern
, i
, j
) = mdup
;
2099 /* The routine modifies given input PATTERN of define_subst, replacing
2100 MATCH_DUP and MATCH_OP_DUP with operands from define_insn original
2101 pattern, whose operands are stored in OPERAND_DATA array.
2102 It also duplicates constraints in operands - constraints from
2103 define_insn operands are duplicated N_SUBST_ALT times, constraints
2104 from define_subst operands are duplicated N_ALT times.
2105 After the duplication, returned output rtl-pattern contains every
2106 combination of input constraints Vs constraints from define_subst
2109 subst_dup (rtx pattern
, int n_alt
, int n_subst_alt
)
2113 int i
, j
, len
, opno
;
2115 code
= GET_CODE (pattern
);
2120 opno
= XINT (pattern
, 0);
2122 gcc_assert (opno
>= 0 && opno
< MAX_OPERANDS
);
2124 if (operand_data
[opno
])
2126 pattern
= copy_rtx (operand_data
[opno
]);
2128 /* Duplicate constraints. */
2129 pattern
= alter_constraints (pattern
, n_subst_alt
,
2130 duplicate_alternatives
);
2138 fmt
= GET_RTX_FORMAT (GET_CODE (pattern
));
2139 len
= GET_RTX_LENGTH (GET_CODE (pattern
));
2140 for (i
= 0; i
< len
; i
++)
2145 if (code
!= MATCH_DUP
&& code
!= MATCH_OP_DUP
)
2146 XEXP (pattern
, i
) = subst_dup (XEXP (pattern
, i
),
2147 n_alt
, n_subst_alt
);
2150 if (XVEC (pattern
, i
) == NULL
)
2153 if (code
!= MATCH_DUP
&& code
!= MATCH_OP_DUP
)
2154 for (j
= XVECLEN (pattern
, i
) - 1; j
>= 0; --j
)
2155 XVECEXP (pattern
, i
, j
) = subst_dup (XVECEXP (pattern
, i
, j
),
2156 n_alt
, n_subst_alt
);
2159 case 'i': case 'r': case 'w': case '0': case 's': case 'S': case 'T':
2169 /* If we have any DEFINE_COND_EXEC patterns, expand the DEFINE_INSN
2170 patterns appropriately. */
2173 process_define_cond_exec (void)
2175 struct queue_elem
*elem
;
2177 identify_predicable_attribute ();
2181 for (elem
= define_cond_exec_queue
; elem
; elem
= elem
->next
)
2182 process_one_cond_exec (elem
);
2185 /* If we have any DEFINE_SUBST patterns, expand DEFINE_INSN and
2186 DEFINE_EXPAND patterns appropriately. */
2189 process_define_subst (void)
2191 struct queue_elem
*elem
, *elem_attr
;
2193 /* Check if each define_subst has corresponding define_subst_attr. */
2194 for (elem
= define_subst_queue
; elem
; elem
= elem
->next
)
2196 for (elem_attr
= define_subst_attr_queue
;
2198 elem_attr
= elem_attr
->next
)
2199 if (strcmp (XSTR (elem
->data
, 0), XSTR (elem_attr
->data
, 1)) == 0)
2202 error_at (elem
->loc
,
2203 "%s: `define_subst' must have at least one "
2204 "corresponding `define_subst_attr'",
2205 XSTR (elem
->data
, 0));
2212 for (elem
= define_insn_queue
; elem
; elem
= elem
->next
)
2213 process_substs_on_one_elem (elem
, define_insn_queue
);
2214 for (elem
= other_queue
; elem
; elem
= elem
->next
)
2216 if (GET_CODE (elem
->data
) != DEFINE_EXPAND
)
2218 process_substs_on_one_elem (elem
, other_queue
);
2222 /* A read_md_files callback for reading an rtx. */
2225 rtx_handle_directive (file_location loc
, const char *rtx_name
)
2227 auto_vec
<rtx
, 32> subrtxs
;
2228 if (!read_rtx (rtx_name
, &subrtxs
))
2233 FOR_EACH_VEC_ELT (subrtxs
, i
, x
)
2234 process_rtx (x
, loc
);
2237 /* Comparison function for the mnemonic hash table. */
2240 htab_eq_string (const void *s1
, const void *s2
)
2242 return strcmp ((const char*)s1
, (const char*)s2
) == 0;
2245 /* Add mnemonic STR with length LEN to the mnemonic hash table
2246 MNEMONIC_HTAB. A trailing zero end character is appendend to STR
2247 and a permanent heap copy of STR is created. */
2250 add_mnemonic_string (htab_t mnemonic_htab
, const char *str
, int len
)
2254 char *str_zero
= (char*)alloca (len
+ 1);
2256 memcpy (str_zero
, str
, len
);
2257 str_zero
[len
] = '\0';
2259 slot
= htab_find_slot (mnemonic_htab
, str_zero
, INSERT
);
2264 /* Not found; create a permanent copy and add it to the hash table. */
2265 new_str
= XNEWVAR (char, len
+ 1);
2266 memcpy (new_str
, str_zero
, len
+ 1);
2270 /* Scan INSN for mnemonic strings and add them to the mnemonic hash
2271 table in MNEMONIC_HTAB.
2273 The mnemonics cannot be found if they are emitted using C code.
2275 If a mnemonic string contains ';' or a newline the string assumed
2276 to consist of more than a single instruction. The attribute value
2277 will then be set to the user defined default value. */
2280 gen_mnemonic_setattr (htab_t mnemonic_htab
, rtx insn
)
2282 const char *template_code
, *cp
;
2289 template_code
= XTMPL (insn
, 3);
2291 /* Skip patterns which use C code to emit the template. */
2292 if (template_code
[0] == '*')
2295 if (template_code
[0] == '@')
2296 cp
= &template_code
[1];
2298 cp
= &template_code
[0];
2302 const char *ep
, *sp
;
2305 while (ISSPACE (*cp
))
2308 for (ep
= sp
= cp
; !IS_VSPACE (*ep
) && *ep
!= '\0'; ++ep
)
2313 obstack_1grow (&string_obstack
, ',');
2315 while (cp
< sp
&& ((*cp
>= '0' && *cp
<= '9')
2316 || (*cp
>= 'a' && *cp
<= 'z')))
2319 obstack_1grow (&string_obstack
, *cp
);
2326 if (*cp
== ';' || (*cp
== '\\' && cp
[1] == 'n'))
2328 /* Don't set a value if there are more than one
2329 instruction in the string. */
2330 obstack_next_free (&string_obstack
) =
2331 obstack_next_free (&string_obstack
) - size
;
2340 obstack_1grow (&string_obstack
, '*');
2342 add_mnemonic_string (mnemonic_htab
,
2343 obstack_next_free (&string_obstack
) - size
,
2348 /* An insn definition might emit an empty string. */
2349 if (obstack_object_size (&string_obstack
) == 0)
2352 obstack_1grow (&string_obstack
, '\0');
2354 set_attr
= rtx_alloc (SET_ATTR
);
2355 XSTR (set_attr
, 1) = XOBFINISH (&string_obstack
, char *);
2356 attr_name
= XNEWVAR (char, strlen (MNEMONIC_ATTR_NAME
) + 1);
2357 strcpy (attr_name
, MNEMONIC_ATTR_NAME
);
2358 XSTR (set_attr
, 0) = attr_name
;
2360 if (!XVEC (insn
, 4))
2363 vec_len
= XVECLEN (insn
, 4);
2365 new_vec
= rtvec_alloc (vec_len
+ 1);
2366 for (i
= 0; i
< vec_len
; i
++)
2367 RTVEC_ELT (new_vec
, i
) = XVECEXP (insn
, 4, i
);
2368 RTVEC_ELT (new_vec
, vec_len
) = set_attr
;
2369 XVEC (insn
, 4) = new_vec
;
2372 /* This function is called for the elements in the mnemonic hashtable
2373 and generates a comma separated list of the mnemonics. */
2376 mnemonic_htab_callback (void **slot
, void *info ATTRIBUTE_UNUSED
)
2378 obstack_grow (&string_obstack
, (char*)*slot
, strlen ((char*)*slot
));
2379 obstack_1grow (&string_obstack
, ',');
2383 /* Generate (set_attr "mnemonic" "..") RTXs and append them to every
2384 insn definition in case the back end requests it by defining the
2385 mnemonic attribute. The values for the attribute will be extracted
2386 from the output patterns of the insn definitions as far as
2390 gen_mnemonic_attr (void)
2392 struct queue_elem
*elem
;
2393 rtx mnemonic_attr
= NULL
;
2394 htab_t mnemonic_htab
;
2395 const char *str
, *p
;
2401 /* Look for the DEFINE_ATTR for `mnemonic'. */
2402 for (elem
= define_attr_queue
; elem
!= *define_attr_tail
; elem
= elem
->next
)
2403 if (GET_CODE (elem
->data
) == DEFINE_ATTR
2404 && strcmp (XSTR (elem
->data
, 0), MNEMONIC_ATTR_NAME
) == 0)
2406 mnemonic_attr
= elem
->data
;
2410 /* A (define_attr "mnemonic" "...") indicates that the back-end
2411 wants a mnemonic attribute to be generated. */
2415 mnemonic_htab
= htab_create_alloc (MNEMONIC_HTAB_SIZE
, htab_hash_string
,
2416 htab_eq_string
, 0, xcalloc
, free
);
2418 for (elem
= define_insn_queue
; elem
; elem
= elem
->next
)
2420 rtx insn
= elem
->data
;
2423 /* Check if the insn definition already has
2424 (set_attr "mnemonic" ...) or (set (attr "mnemonic") ...). */
2426 for (i
= 0; i
< XVECLEN (insn
, 4); i
++)
2428 rtx set_attr
= XVECEXP (insn
, 4, i
);
2430 switch (GET_CODE (set_attr
))
2433 case SET_ATTR_ALTERNATIVE
:
2434 if (strcmp (XSTR (set_attr
, 0), MNEMONIC_ATTR_NAME
) == 0)
2438 if (GET_CODE (SET_DEST (set_attr
)) == ATTR
2439 && strcmp (XSTR (SET_DEST (set_attr
), 0),
2440 MNEMONIC_ATTR_NAME
) == 0)
2449 gen_mnemonic_setattr (mnemonic_htab
, insn
);
2452 /* Add the user defined values to the hash table. */
2453 str
= XSTR (mnemonic_attr
, 1);
2454 while ((p
= scan_comma_elt (&str
)) != NULL
)
2455 add_mnemonic_string (mnemonic_htab
, p
, str
- p
);
2457 htab_traverse (mnemonic_htab
, mnemonic_htab_callback
, NULL
);
2459 /* Replace the last ',' with the zero end character. */
2460 *((char *)obstack_next_free (&string_obstack
) - 1) = '\0';
2461 XSTR (mnemonic_attr
, 1) = XOBFINISH (&string_obstack
, char *);
2464 /* Check if there are DEFINE_ATTRs with the same name. */
2466 check_define_attr_duplicates ()
2468 struct queue_elem
*elem
;
2473 attr_htab
= htab_create (500, htab_hash_string
, htab_eq_string
, NULL
);
2475 for (elem
= define_attr_queue
; elem
; elem
= elem
->next
)
2477 attr_name
= xstrdup (XSTR (elem
->data
, 0));
2479 slot
= htab_find_slot (attr_htab
, attr_name
, INSERT
);
2484 error_at (elem
->loc
, "redefinition of attribute '%s'", attr_name
);
2485 htab_delete (attr_htab
);
2492 htab_delete (attr_htab
);
2495 /* The entry point for initializing the reader. */
2498 init_rtx_reader_args_cb (int argc
, char **argv
,
2499 bool (*parse_opt
) (const char *))
2501 /* Prepare to read input. */
2502 condition_table
= htab_create (500, hash_c_test
, cmp_c_test
, NULL
);
2503 init_predicate_table ();
2504 obstack_init (rtl_obstack
);
2506 /* Start at 1, to make 0 available for CODE_FOR_nothing. */
2509 read_md_files (argc
, argv
, parse_opt
, rtx_handle_directive
);
2511 if (define_attr_queue
!= NULL
)
2512 check_define_attr_duplicates ();
2514 /* Process define_cond_exec patterns. */
2515 if (define_cond_exec_queue
!= NULL
)
2516 process_define_cond_exec ();
2518 /* Process define_subst patterns. */
2519 if (define_subst_queue
!= NULL
)
2520 process_define_subst ();
2522 if (define_attr_queue
!= NULL
)
2523 gen_mnemonic_attr ();
2528 /* Programs that don't have their own options can use this entry point
2531 init_rtx_reader_args (int argc
, char **argv
)
2533 return init_rtx_reader_args_cb (argc
, argv
, 0);
2536 /* Try to read a single rtx from the file. Return true on success,
2537 describing it in *INFO. */
2540 read_md_rtx (md_rtx_info
*info
)
2542 struct queue_elem
**queue
, *elem
;
2547 /* Read all patterns from a given queue before moving on to the next. */
2548 if (define_attr_queue
!= NULL
)
2549 queue
= &define_attr_queue
;
2550 else if (define_pred_queue
!= NULL
)
2551 queue
= &define_pred_queue
;
2552 else if (define_insn_queue
!= NULL
)
2553 queue
= &define_insn_queue
;
2554 else if (other_queue
!= NULL
)
2555 queue
= &other_queue
;
2560 *queue
= elem
->next
;
2561 info
->def
= elem
->data
;
2562 info
->loc
= elem
->loc
;
2563 info
->index
= sequence_num
;
2567 /* Discard insn patterns which we know can never match (because
2568 their C test is provably always false). If insn_elision is
2569 false, our caller needs to see all the patterns. Note that the
2570 elided patterns are never counted by the sequence numbering; it
2571 is the caller's responsibility, when insn_elision is false, not
2572 to use elided pattern numbers for anything. */
2574 switch (GET_CODE (desc
))
2579 if (maybe_eval_c_test (XSTR (desc
, 2)) != 0)
2581 else if (insn_elision
)
2584 /* info->index is used here so the name table will match caller's
2585 idea of insn numbering, whether or not elision is active. */
2586 record_insn_name (info
->index
, XSTR (desc
, 0));
2590 case DEFINE_PEEPHOLE
:
2591 case DEFINE_PEEPHOLE2
:
2592 if (maybe_eval_c_test (XSTR (desc
, 1)) != 0)
2594 else if (insn_elision
)
2605 /* Helper functions for insn elision. */
2607 /* Compute a hash function of a c_test structure, which is keyed
2608 by its ->expr field. */
2610 hash_c_test (const void *x
)
2612 const struct c_test
*a
= (const struct c_test
*) x
;
2613 const unsigned char *base
, *s
= (const unsigned char *) a
->expr
;
2621 while ((c
= *s
++) != '\0')
2623 hash
+= c
+ (c
<< 17);
2628 hash
+= len
+ (len
<< 17);
2634 /* Compare two c_test expression structures. */
2636 cmp_c_test (const void *x
, const void *y
)
2638 const struct c_test
*a
= (const struct c_test
*) x
;
2639 const struct c_test
*b
= (const struct c_test
*) y
;
2641 return !strcmp (a
->expr
, b
->expr
);
2644 /* Given a string representing a C test expression, look it up in the
2645 condition_table and report whether or not its value is known
2646 at compile time. Returns a tristate: 1 for known true, 0 for
2647 known false, -1 for unknown. */
2649 maybe_eval_c_test (const char *expr
)
2651 const struct c_test
*test
;
2652 struct c_test dummy
;
2658 test
= (const struct c_test
*)htab_find (condition_table
, &dummy
);
2664 /* Record the C test expression EXPR in the condition_table, with
2665 value VAL. Duplicates clobber previous entries. */
2668 add_c_test (const char *expr
, int value
)
2670 struct c_test
*test
;
2675 test
= XNEW (struct c_test
);
2677 test
->value
= value
;
2679 *(htab_find_slot (condition_table
, test
, INSERT
)) = test
;
2682 /* For every C test, call CALLBACK with two arguments: a pointer to
2683 the condition structure and INFO. Stops when CALLBACK returns zero. */
2685 traverse_c_tests (htab_trav callback
, void *info
)
2687 if (condition_table
)
2688 htab_traverse (condition_table
, callback
, info
);
2691 /* Helper functions for define_predicate and define_special_predicate
2692 processing. Shared between genrecog.c and genpreds.c. */
2694 static htab_t predicate_table
;
2695 struct pred_data
*first_predicate
;
2696 static struct pred_data
**last_predicate
= &first_predicate
;
2699 hash_struct_pred_data (const void *ptr
)
2701 return htab_hash_string (((const struct pred_data
*)ptr
)->name
);
2705 eq_struct_pred_data (const void *a
, const void *b
)
2707 return !strcmp (((const struct pred_data
*)a
)->name
,
2708 ((const struct pred_data
*)b
)->name
);
2712 lookup_predicate (const char *name
)
2714 struct pred_data key
;
2716 return (struct pred_data
*) htab_find (predicate_table
, &key
);
2719 /* Record that predicate PRED can accept CODE. */
2722 add_predicate_code (struct pred_data
*pred
, enum rtx_code code
)
2724 if (!pred
->codes
[code
])
2727 pred
->codes
[code
] = true;
2729 if (GET_RTX_CLASS (code
) != RTX_CONST_OBJ
)
2730 pred
->allows_non_const
= true;
2737 && code
!= STRICT_LOW_PART
2739 pred
->allows_non_lvalue
= true;
2741 if (pred
->num_codes
== 1)
2742 pred
->singleton
= code
;
2743 else if (pred
->num_codes
== 2)
2744 pred
->singleton
= UNKNOWN
;
2749 add_predicate (struct pred_data
*pred
)
2751 void **slot
= htab_find_slot (predicate_table
, pred
, INSERT
);
2754 error ("duplicate predicate definition for '%s'", pred
->name
);
2758 *last_predicate
= pred
;
2759 last_predicate
= &pred
->next
;
2762 /* This array gives the initial content of the predicate table. It
2763 has entries for all predicates defined in recog.c. */
2765 struct std_pred_table
2769 bool allows_const_p
;
2770 RTX_CODE codes
[NUM_RTX_CODE
];
2773 static const struct std_pred_table std_preds
[] = {
2774 {"general_operand", false, true, {SUBREG
, REG
, MEM
}},
2775 {"address_operand", true, true, {SUBREG
, REG
, MEM
, PLUS
, MINUS
, MULT
,
2776 ZERO_EXTEND
, SIGN_EXTEND
, AND
}},
2777 {"register_operand", false, false, {SUBREG
, REG
}},
2778 {"pmode_register_operand", true, false, {SUBREG
, REG
}},
2779 {"scratch_operand", false, false, {SCRATCH
, REG
}},
2780 {"immediate_operand", false, true, {UNKNOWN
}},
2781 {"const_int_operand", false, false, {CONST_INT
}},
2782 #if TARGET_SUPPORTS_WIDE_INT
2783 {"const_scalar_int_operand", false, false, {CONST_INT
, CONST_WIDE_INT
}},
2784 {"const_double_operand", false, false, {CONST_DOUBLE
}},
2786 {"const_double_operand", false, false, {CONST_INT
, CONST_DOUBLE
}},
2788 {"nonimmediate_operand", false, false, {SUBREG
, REG
, MEM
}},
2789 {"nonmemory_operand", false, true, {SUBREG
, REG
}},
2790 {"push_operand", false, false, {MEM
}},
2791 {"pop_operand", false, false, {MEM
}},
2792 {"memory_operand", false, false, {SUBREG
, MEM
}},
2793 {"indirect_operand", false, false, {SUBREG
, MEM
}},
2794 {"ordered_comparison_operator", false, false, {EQ
, NE
,
2796 LEU
, LTU
, GEU
, GTU
}},
2797 {"comparison_operator", false, false, {EQ
, NE
,
2804 #define NUM_KNOWN_STD_PREDS ARRAY_SIZE (std_preds)
2806 /* Initialize the table of predicate definitions, starting with
2807 the information we have on generic predicates. */
2810 init_predicate_table (void)
2813 struct pred_data
*pred
;
2815 predicate_table
= htab_create_alloc (37, hash_struct_pred_data
,
2816 eq_struct_pred_data
, 0,
2819 for (i
= 0; i
< NUM_KNOWN_STD_PREDS
; i
++)
2821 pred
= XCNEW (struct pred_data
);
2822 pred
->name
= std_preds
[i
].name
;
2823 pred
->special
= std_preds
[i
].special
;
2825 for (j
= 0; std_preds
[i
].codes
[j
] != 0; j
++)
2826 add_predicate_code (pred
, std_preds
[i
].codes
[j
]);
2828 if (std_preds
[i
].allows_const_p
)
2829 for (j
= 0; j
< NUM_RTX_CODE
; j
++)
2830 if (GET_RTX_CLASS (j
) == RTX_CONST_OBJ
)
2831 add_predicate_code (pred
, (enum rtx_code
) j
);
2833 add_predicate (pred
);
2837 /* These functions allow linkage with print-rtl.c. Also, some generators
2838 like to annotate their output with insn names. */
2840 /* Holds an array of names indexed by insn_code_number. */
2841 static char **insn_name_ptr
= 0;
2842 static int insn_name_ptr_size
= 0;
2845 get_insn_name (int code
)
2847 if (code
< insn_name_ptr_size
)
2848 return insn_name_ptr
[code
];
2854 record_insn_name (int code
, const char *name
)
2856 static const char *last_real_name
= "insn";
2857 static int last_real_code
= 0;
2860 if (insn_name_ptr_size
<= code
)
2863 new_size
= (insn_name_ptr_size
? insn_name_ptr_size
* 2 : 512);
2864 insn_name_ptr
= XRESIZEVEC (char *, insn_name_ptr
, new_size
);
2865 memset (insn_name_ptr
+ insn_name_ptr_size
, 0,
2866 sizeof (char *) * (new_size
- insn_name_ptr_size
));
2867 insn_name_ptr_size
= new_size
;
2870 if (!name
|| name
[0] == '\0')
2872 new_name
= XNEWVAR (char, strlen (last_real_name
) + 10);
2873 sprintf (new_name
, "%s+%d", last_real_name
, code
- last_real_code
);
2877 last_real_name
= new_name
= xstrdup (name
);
2878 last_real_code
= code
;
2881 insn_name_ptr
[code
] = new_name
;
2884 /* Make STATS describe the operands that appear in rtx X. */
2887 get_pattern_stats_1 (struct pattern_stats
*stats
, rtx x
)
2897 code
= GET_CODE (x
);
2901 case MATCH_OPERATOR
:
2902 case MATCH_PARALLEL
:
2903 stats
->max_opno
= MAX (stats
->max_opno
, XINT (x
, 0));
2910 stats
->max_dup_opno
= MAX (stats
->max_dup_opno
, XINT (x
, 0));
2914 stats
->max_scratch_opno
= MAX (stats
->max_scratch_opno
, XINT (x
, 0));
2921 fmt
= GET_RTX_FORMAT (code
);
2922 len
= GET_RTX_LENGTH (code
);
2923 for (i
= 0; i
< len
; i
++)
2925 if (fmt
[i
] == 'e' || fmt
[i
] == 'u')
2926 get_pattern_stats_1 (stats
, XEXP (x
, i
));
2927 else if (fmt
[i
] == 'E')
2930 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2931 get_pattern_stats_1 (stats
, XVECEXP (x
, i
, j
));
2936 /* Make STATS describe the operands that appear in instruction pattern
2940 get_pattern_stats (struct pattern_stats
*stats
, rtvec pattern
)
2944 stats
->max_opno
= -1;
2945 stats
->max_dup_opno
= -1;
2946 stats
->max_scratch_opno
= -1;
2947 stats
->num_dups
= 0;
2949 len
= GET_NUM_ELEM (pattern
);
2950 for (i
= 0; i
< len
; i
++)
2951 get_pattern_stats_1 (stats
, RTVEC_ELT (pattern
, i
));
2953 stats
->num_generator_args
= stats
->max_opno
+ 1;
2954 stats
->num_insn_operands
= MAX (stats
->max_opno
,
2955 stats
->max_scratch_opno
) + 1;
2956 stats
->num_operand_vars
= MAX (stats
->max_opno
,
2957 MAX (stats
->max_dup_opno
,
2958 stats
->max_scratch_opno
)) + 1;
2961 /* Return the emit_* function that should be used for pattern X, or NULL
2962 if we can't pick a particular type at compile time and should instead
2963 fall back to "emit". */
2966 get_emit_function (rtx x
)
2968 switch (classify_insn (x
))
2974 return "emit_call_insn";
2977 return "emit_jump_insn";
2987 /* Return true if we must emit a barrier after pattern X. */
2990 needs_barrier_p (rtx x
)
2992 return (GET_CODE (x
) == SET
2993 && GET_CODE (SET_DEST (x
)) == PC
2994 && GET_CODE (SET_SRC (x
)) == LABEL_REF
);