1 /* Support routines for the various generation passes.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
3 2010, 2012 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 3, 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 COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
30 #include "gensupport.h"
32 #define MAX_OPERANDS 40
34 static rtx operand_data
[MAX_OPERANDS
];
35 static rtx match_operand_entries_in_pattern
[MAX_OPERANDS
];
36 static char used_operands_numbers
[MAX_OPERANDS
];
39 /* In case some macros used by files we include need it, define this here. */
44 static struct obstack obstack
;
45 struct obstack
*rtl_obstack
= &obstack
;
47 /* Counter for patterns that generate code: define_insn, define_expand,
48 define_split, define_peephole, and define_peephole2. See read_md_rtx().
49 Any define_insn_and_splits are already in separate queues so that the
50 insn and the splitter get a unique number also. */
51 static int sequence_num
;
53 static int predicable_default
;
54 static const char *predicable_true
;
55 static const char *predicable_false
;
57 static const char *subst_true
= "yes";
58 static const char *subst_false
= "no";
60 static htab_t condition_table
;
62 /* We initially queue all patterns, process the define_insn,
63 define_cond_exec and define_subst patterns, then return
64 them one at a time. */
71 struct queue_elem
*next
;
72 /* In a DEFINE_INSN that came from a DEFINE_INSN_AND_SPLIT, SPLIT
73 points to the generated DEFINE_SPLIT. */
74 struct queue_elem
*split
;
77 #define MNEMONIC_ATTR_NAME "mnemonic"
78 #define MNEMONIC_HTAB_SIZE 1024
80 static struct queue_elem
*define_attr_queue
;
81 static struct queue_elem
**define_attr_tail
= &define_attr_queue
;
82 static struct queue_elem
*define_pred_queue
;
83 static struct queue_elem
**define_pred_tail
= &define_pred_queue
;
84 static struct queue_elem
*define_insn_queue
;
85 static struct queue_elem
**define_insn_tail
= &define_insn_queue
;
86 static struct queue_elem
*define_cond_exec_queue
;
87 static struct queue_elem
**define_cond_exec_tail
= &define_cond_exec_queue
;
88 static struct queue_elem
*define_subst_queue
;
89 static struct queue_elem
**define_subst_tail
= &define_subst_queue
;
90 static struct queue_elem
*other_queue
;
91 static struct queue_elem
**other_tail
= &other_queue
;
92 static struct queue_elem
*define_subst_attr_queue
;
93 static struct queue_elem
**define_subst_attr_tail
= &define_subst_attr_queue
;
95 static struct queue_elem
*queue_pattern (rtx
, struct queue_elem
***,
98 static void remove_constraints (rtx
);
99 static void process_rtx (rtx
, int);
101 static int is_predicable (struct queue_elem
*);
102 static void identify_predicable_attribute (void);
103 static int n_alternatives (const char *);
104 static void collect_insn_data (rtx
, int *, int *);
105 static rtx
alter_predicate_for_insn (rtx
, int, int, int);
106 static const char *alter_test_for_insn (struct queue_elem
*,
107 struct queue_elem
*);
108 static char *shift_output_template (char *, const char *, int);
109 static const char *alter_output_for_insn (struct queue_elem
*,
112 static void process_one_cond_exec (struct queue_elem
*);
113 static void process_define_cond_exec (void);
114 static void init_predicate_table (void);
115 static void record_insn_name (int, const char *);
117 static bool has_subst_attribute (struct queue_elem
*, struct queue_elem
*);
118 static bool subst_pattern_match (rtx
, rtx
, int);
119 static int get_alternatives_number (rtx
, int *, int);
120 static const char * alter_output_for_subst_insn (rtx
, int);
121 static void alter_attrs_for_subst_insn (struct queue_elem
*, int);
122 static void process_substs_on_one_elem (struct queue_elem
*,
123 struct queue_elem
*);
124 static rtx
subst_dup (rtx
, int, int);
125 static void process_define_subst (void);
127 static const char * duplicate_alternatives (const char *, int);
128 static const char * duplicate_each_alternative (const char * str
, int n_dup
);
130 typedef const char * (*constraints_handler_t
) (const char *, int);
131 static rtx
alter_constraints (rtx
, int, constraints_handler_t
);
132 static rtx
adjust_operands_numbers (rtx
);
133 static rtx
replace_duplicating_operands_in_pattern (rtx
);
135 /* Make a version of gen_rtx_CONST_INT so that GEN_INT can be used in
136 the gensupport programs. */
139 gen_rtx_CONST_INT (enum machine_mode
ARG_UNUSED (mode
),
142 rtx rt
= rtx_alloc (CONST_INT
);
148 /* Predicate handling.
150 We construct from the machine description a table mapping each
151 predicate to a list of the rtl codes it can possibly match. The
152 function 'maybe_both_true' uses it to deduce that there are no
153 expressions that can be matches by certain pairs of tree nodes.
154 Also, if a predicate can match only one code, we can hardwire that
155 code into the node testing the predicate.
157 Some predicates are flagged as special. validate_pattern will not
158 warn about modeless match_operand expressions if they have a
159 special predicate. Predicates that allow only constants are also
160 treated as special, for this purpose.
162 validate_pattern will warn about predicates that allow non-lvalues
163 when they appear in destination operands.
165 Calculating the set of rtx codes that can possibly be accepted by a
166 predicate expression EXP requires a three-state logic: any given
167 subexpression may definitively accept a code C (Y), definitively
168 reject a code C (N), or may have an indeterminate effect (I). N
169 and I is N; Y or I is Y; Y and I, N or I are both I. Here are full
180 We represent Y with 1, N with 0, I with 2. If any code is left in
181 an I state by the complete expression, we must assume that that
182 code can be accepted. */
188 #define TRISTATE_AND(a,b) \
189 ((a) == I ? ((b) == N ? N : I) : \
190 (b) == I ? ((a) == N ? N : I) : \
193 #define TRISTATE_OR(a,b) \
194 ((a) == I ? ((b) == Y ? Y : I) : \
195 (b) == I ? ((a) == Y ? Y : I) : \
198 #define TRISTATE_NOT(a) \
199 ((a) == I ? I : !(a))
201 /* 0 means no warning about that code yet, 1 means warned. */
202 static char did_you_mean_codes
[NUM_RTX_CODE
];
204 /* Recursively calculate the set of rtx codes accepted by the
205 predicate expression EXP, writing the result to CODES. LINENO is
206 the line number on which the directive containing EXP appeared. */
209 compute_predicate_codes (rtx exp
, int lineno
, char codes
[NUM_RTX_CODE
])
211 char op0_codes
[NUM_RTX_CODE
];
212 char op1_codes
[NUM_RTX_CODE
];
213 char op2_codes
[NUM_RTX_CODE
];
216 switch (GET_CODE (exp
))
219 compute_predicate_codes (XEXP (exp
, 0), lineno
, op0_codes
);
220 compute_predicate_codes (XEXP (exp
, 1), lineno
, op1_codes
);
221 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
222 codes
[i
] = TRISTATE_AND (op0_codes
[i
], op1_codes
[i
]);
226 compute_predicate_codes (XEXP (exp
, 0), lineno
, op0_codes
);
227 compute_predicate_codes (XEXP (exp
, 1), lineno
, op1_codes
);
228 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
229 codes
[i
] = TRISTATE_OR (op0_codes
[i
], op1_codes
[i
]);
232 compute_predicate_codes (XEXP (exp
, 0), lineno
, op0_codes
);
233 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
234 codes
[i
] = TRISTATE_NOT (op0_codes
[i
]);
238 /* a ? b : c accepts the same codes as (a & b) | (!a & c). */
239 compute_predicate_codes (XEXP (exp
, 0), lineno
, op0_codes
);
240 compute_predicate_codes (XEXP (exp
, 1), lineno
, op1_codes
);
241 compute_predicate_codes (XEXP (exp
, 2), lineno
, op2_codes
);
242 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
243 codes
[i
] = TRISTATE_OR (TRISTATE_AND (op0_codes
[i
], op1_codes
[i
]),
244 TRISTATE_AND (TRISTATE_NOT (op0_codes
[i
]),
249 /* MATCH_CODE allows a specified list of codes. However, if it
250 does not apply to the top level of the expression, it does not
251 constrain the set of codes for the top level. */
252 if (XSTR (exp
, 1)[0] != '\0')
254 memset (codes
, Y
, NUM_RTX_CODE
);
258 memset (codes
, N
, NUM_RTX_CODE
);
260 const char *next_code
= XSTR (exp
, 0);
263 if (*next_code
== '\0')
265 error_with_line (lineno
, "empty match_code expression");
269 while ((code
= scan_comma_elt (&next_code
)) != 0)
271 size_t n
= next_code
- code
;
274 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
275 if (!strncmp (code
, GET_RTX_NAME (i
), n
)
276 && GET_RTX_NAME (i
)[n
] == '\0')
284 error_with_line (lineno
,
285 "match_code \"%.*s\" matches nothing",
287 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
288 if (!strncasecmp (code
, GET_RTX_NAME (i
), n
)
289 && GET_RTX_NAME (i
)[n
] == '\0'
290 && !did_you_mean_codes
[i
])
292 did_you_mean_codes
[i
] = 1;
293 message_with_line (lineno
, "(did you mean \"%s\"?)",
302 /* MATCH_OPERAND disallows the set of codes that the named predicate
303 disallows, and is indeterminate for the codes that it does allow. */
305 struct pred_data
*p
= lookup_predicate (XSTR (exp
, 1));
308 error_with_line (lineno
, "reference to unknown predicate '%s'",
312 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
313 codes
[i
] = p
->codes
[i
] ? I
: N
;
319 /* (match_test WHATEVER) is completely indeterminate. */
320 memset (codes
, I
, NUM_RTX_CODE
);
324 error_with_line (lineno
,
325 "'%s' cannot be used in a define_predicate expression",
326 GET_RTX_NAME (GET_CODE (exp
)));
327 memset (codes
, I
, NUM_RTX_CODE
);
336 /* Return true if NAME is a valid predicate name. */
339 valid_predicate_name_p (const char *name
)
343 if (!ISALPHA (name
[0]) && name
[0] != '_')
345 for (p
= name
+ 1; *p
; p
++)
346 if (!ISALNUM (*p
) && *p
!= '_')
351 /* Process define_predicate directive DESC, which appears on line number
352 LINENO. Compute the set of codes that can be matched, and record this
353 as a known predicate. */
356 process_define_predicate (rtx desc
, int lineno
)
358 struct pred_data
*pred
;
359 char codes
[NUM_RTX_CODE
];
362 if (!valid_predicate_name_p (XSTR (desc
, 0)))
364 error_with_line (lineno
,
365 "%s: predicate name must be a valid C function name",
370 pred
= XCNEW (struct pred_data
);
371 pred
->name
= XSTR (desc
, 0);
372 pred
->exp
= XEXP (desc
, 1);
373 pred
->c_block
= XSTR (desc
, 2);
374 if (GET_CODE (desc
) == DEFINE_SPECIAL_PREDICATE
)
375 pred
->special
= true;
377 compute_predicate_codes (XEXP (desc
, 1), lineno
, codes
);
379 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
381 add_predicate_code (pred
, (enum rtx_code
) i
);
383 add_predicate (pred
);
389 /* Queue PATTERN on LIST_TAIL. Return the address of the new queue
392 static struct queue_elem
*
393 queue_pattern (rtx pattern
, struct queue_elem
***list_tail
,
394 const char *filename
, int lineno
)
396 struct queue_elem
*e
= XNEW(struct queue_elem
);
398 e
->filename
= filename
;
403 *list_tail
= &e
->next
;
407 /* Remove element ELEM from QUEUE. */
409 remove_from_queue (struct queue_elem
*elem
, struct queue_elem
**queue
)
411 struct queue_elem
*prev
, *e
;
413 for (e
= *queue
; e
; e
= e
->next
)
423 prev
->next
= elem
->next
;
428 /* Build a define_attr for an binary attribute with name NAME and
429 possible values "yes" and "no", and queue it. */
431 add_define_attr (const char *name
)
433 struct queue_elem
*e
= XNEW(struct queue_elem
);
434 rtx t1
= rtx_alloc (DEFINE_ATTR
);
436 XSTR (t1
, 1) = "no,yes";
437 XEXP (t1
, 2) = rtx_alloc (CONST_STRING
);
438 XSTR (XEXP (t1
, 2), 0) = "yes";
440 e
->filename
= "built-in";
442 e
->next
= define_attr_queue
;
443 define_attr_queue
= e
;
447 /* Recursively remove constraints from an rtx. */
450 remove_constraints (rtx part
)
453 const char *format_ptr
;
458 if (GET_CODE (part
) == MATCH_OPERAND
)
460 else if (GET_CODE (part
) == MATCH_SCRATCH
)
463 format_ptr
= GET_RTX_FORMAT (GET_CODE (part
));
465 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (part
)); i
++)
466 switch (*format_ptr
++)
470 remove_constraints (XEXP (part
, i
));
473 if (XVEC (part
, i
) != NULL
)
474 for (j
= 0; j
< XVECLEN (part
, i
); j
++)
475 remove_constraints (XVECEXP (part
, i
, j
));
480 /* Process a top level rtx in some way, queuing as appropriate. */
483 process_rtx (rtx desc
, int lineno
)
485 switch (GET_CODE (desc
))
488 queue_pattern (desc
, &define_insn_tail
, read_md_filename
, lineno
);
491 case DEFINE_COND_EXEC
:
492 queue_pattern (desc
, &define_cond_exec_tail
, read_md_filename
, lineno
);
496 queue_pattern (desc
, &define_subst_tail
, read_md_filename
, lineno
);
499 case DEFINE_SUBST_ATTR
:
500 queue_pattern (desc
, &define_subst_attr_tail
, read_md_filename
, lineno
);
504 case DEFINE_ENUM_ATTR
:
505 queue_pattern (desc
, &define_attr_tail
, read_md_filename
, lineno
);
508 case DEFINE_PREDICATE
:
509 case DEFINE_SPECIAL_PREDICATE
:
510 process_define_predicate (desc
, lineno
);
513 case DEFINE_CONSTRAINT
:
514 case DEFINE_REGISTER_CONSTRAINT
:
515 case DEFINE_MEMORY_CONSTRAINT
:
516 case DEFINE_ADDRESS_CONSTRAINT
:
517 queue_pattern (desc
, &define_pred_tail
, read_md_filename
, lineno
);
520 case DEFINE_INSN_AND_SPLIT
:
522 const char *split_cond
;
526 struct queue_elem
*insn_elem
;
527 struct queue_elem
*split_elem
;
529 /* Create a split with values from the insn_and_split. */
530 split
= rtx_alloc (DEFINE_SPLIT
);
532 i
= XVECLEN (desc
, 1);
533 XVEC (split
, 0) = rtvec_alloc (i
);
536 XVECEXP (split
, 0, i
) = copy_rtx (XVECEXP (desc
, 1, i
));
537 remove_constraints (XVECEXP (split
, 0, i
));
540 /* If the split condition starts with "&&", append it to the
541 insn condition to create the new split condition. */
542 split_cond
= XSTR (desc
, 4);
543 if (split_cond
[0] == '&' && split_cond
[1] == '&')
545 copy_md_ptr_loc (split_cond
+ 2, split_cond
);
546 split_cond
= join_c_conditions (XSTR (desc
, 2), split_cond
+ 2);
548 XSTR (split
, 1) = split_cond
;
549 XVEC (split
, 2) = XVEC (desc
, 5);
550 XSTR (split
, 3) = XSTR (desc
, 6);
552 /* Fix up the DEFINE_INSN. */
553 attr
= XVEC (desc
, 7);
554 PUT_CODE (desc
, DEFINE_INSN
);
555 XVEC (desc
, 4) = attr
;
559 = queue_pattern (desc
, &define_insn_tail
, read_md_filename
,
562 = queue_pattern (split
, &other_tail
, read_md_filename
, lineno
);
563 insn_elem
->split
= split_elem
;
568 queue_pattern (desc
, &other_tail
, read_md_filename
, lineno
);
573 /* Return true if attribute PREDICABLE is true for ELEM, which holds
577 is_predicable (struct queue_elem
*elem
)
579 rtvec vec
= XVEC (elem
->data
, 4);
584 return predicable_default
;
586 for (i
= GET_NUM_ELEM (vec
) - 1; i
>= 0; --i
)
588 rtx sub
= RTVEC_ELT (vec
, i
);
589 switch (GET_CODE (sub
))
592 if (strcmp (XSTR (sub
, 0), "predicable") == 0)
594 value
= XSTR (sub
, 1);
599 case SET_ATTR_ALTERNATIVE
:
600 if (strcmp (XSTR (sub
, 0), "predicable") == 0)
602 error_with_line (elem
->lineno
,
603 "multiple alternatives for `predicable'");
609 if (GET_CODE (SET_DEST (sub
)) != ATTR
610 || strcmp (XSTR (SET_DEST (sub
), 0), "predicable") != 0)
613 if (GET_CODE (sub
) == CONST_STRING
)
615 value
= XSTR (sub
, 0);
619 /* ??? It would be possible to handle this if we really tried.
620 It's not easy though, and I'm not going to bother until it
621 really proves necessary. */
622 error_with_line (elem
->lineno
,
623 "non-constant value for `predicable'");
631 return predicable_default
;
634 /* Find out which value we're looking at. Multiple alternatives means at
635 least one is predicable. */
636 if (strchr (value
, ',') != NULL
)
638 if (strcmp (value
, predicable_true
) == 0)
640 if (strcmp (value
, predicable_false
) == 0)
643 error_with_line (elem
->lineno
,
644 "unknown value `%s' for `predicable' attribute", value
);
648 /* Find attribute SUBST in ELEM and assign NEW_VALUE to it. */
650 change_subst_attribute (struct queue_elem
*elem
,
651 struct queue_elem
*subst_elem
,
652 const char *new_value
)
654 rtvec attrs_vec
= XVEC (elem
->data
, 4);
655 const char *subst_name
= XSTR (subst_elem
->data
, 0);
661 for (i
= GET_NUM_ELEM (attrs_vec
) - 1; i
>= 0; --i
)
663 rtx cur_attr
= RTVEC_ELT (attrs_vec
, i
);
664 if (GET_CODE (cur_attr
) != SET_ATTR
)
666 if (strcmp (XSTR (cur_attr
, 0), subst_name
) == 0)
668 XSTR (cur_attr
, 1) = new_value
;
674 /* Return true if ELEM has the attribute with the name of DEFINE_SUBST
675 represented by SUBST_ELEM and this attribute has value SUBST_TRUE.
676 DEFINE_SUBST isn't applied to patterns without such attribute. In other
677 words, we suppose the default value of the attribute to be 'no' since it is
678 always generated automaticaly in read-rtl.c. */
680 has_subst_attribute (struct queue_elem
*elem
, struct queue_elem
*subst_elem
)
682 rtvec attrs_vec
= XVEC (elem
->data
, 4);
683 const char *value
, *subst_name
= XSTR (subst_elem
->data
, 0);
689 for (i
= GET_NUM_ELEM (attrs_vec
) - 1; i
>= 0; --i
)
691 rtx cur_attr
= RTVEC_ELT (attrs_vec
, i
);
692 switch (GET_CODE (cur_attr
))
695 if (strcmp (XSTR (cur_attr
, 0), subst_name
) == 0)
697 value
= XSTR (cur_attr
, 1);
703 if (GET_CODE (SET_DEST (cur_attr
)) != ATTR
704 || strcmp (XSTR (SET_DEST (cur_attr
), 0), subst_name
) != 0)
706 cur_attr
= SET_SRC (cur_attr
);
707 if (GET_CODE (cur_attr
) == CONST_STRING
)
709 value
= XSTR (cur_attr
, 0);
713 /* Only (set_attr "subst" "yes/no") and
714 (set (attr "subst" (const_string "yes/no")))
715 are currently allowed. */
716 error_with_line (elem
->lineno
,
717 "unsupported value for `%s'", subst_name
);
720 case SET_ATTR_ALTERNATIVE
:
721 error_with_line (elem
->lineno
,
722 "%s: `set_attr_alternative' is unsupported by "
724 XSTR (elem
->data
, 0));
736 if (strcmp (value
, subst_true
) == 0)
738 if (strcmp (value
, subst_false
) == 0)
741 error_with_line (elem
->lineno
,
742 "unknown value `%s' for `%s' attribute", value
, subst_name
);
746 /* Compare RTL-template of original define_insn X to input RTL-template of
747 define_subst PT. Return 1 if the templates match, 0 otherwise.
748 During the comparison, the routine also fills global_array OPERAND_DATA. */
750 subst_pattern_match (rtx x
, rtx pt
, int lineno
)
752 RTX_CODE code
, code_pt
;
754 const char *fmt
, *pred_name
;
757 code_pt
= GET_CODE (pt
);
759 if (code_pt
== MATCH_OPERAND
)
761 /* MATCH_DUP, and MATCH_OP_DUP don't have a specified mode, so we
762 always accept them. */
763 if (GET_MODE (pt
) != VOIDmode
&& GET_MODE (x
) != GET_MODE (pt
)
764 && (code
!= MATCH_DUP
&& code
!= MATCH_OP_DUP
))
765 return false; /* Modes don't match. */
767 if (code
== MATCH_OPERAND
)
769 pred_name
= XSTR (pt
, 1);
770 if (pred_name
[0] != 0)
772 const struct pred_data
*pred_pt
= lookup_predicate (pred_name
);
773 if (!pred_pt
|| pred_pt
!= lookup_predicate (XSTR (x
, 1)))
774 return false; /* Predicates don't match. */
778 gcc_assert (XINT (pt
, 0) >= 0 && XINT (pt
, 0) < MAX_OPERANDS
);
779 operand_data
[XINT (pt
, 0)] = x
;
783 if (code_pt
== MATCH_OPERATOR
)
785 int x_vecexp_pos
= -1;
788 if (GET_MODE (pt
) != VOIDmode
&& GET_MODE (x
) != GET_MODE (pt
))
791 /* In case X is also match_operator, compare predicates. */
792 if (code
== MATCH_OPERATOR
)
794 pred_name
= XSTR (pt
, 1);
795 if (pred_name
[0] != 0)
797 const struct pred_data
*pred_pt
= lookup_predicate (pred_name
);
798 if (!pred_pt
|| pred_pt
!= lookup_predicate (XSTR (x
, 1)))
804 MATCH_OPERATOR in input template could match in original template
805 either 1) MATCH_OPERAND, 2) UNSPEC, 3) ordinary operation (like PLUS).
806 In the first case operands are at (XVECEXP (x, 2, j)), in the second
807 - at (XVECEXP (x, 0, j)), in the last one - (XEXP (x, j)).
808 X_VECEXP_POS variable shows, where to look for these operands. */
810 || code
== UNSPEC_VOLATILE
)
812 else if (code
== MATCH_OPERATOR
)
817 /* MATCH_OPERATOR or UNSPEC case. */
818 if (x_vecexp_pos
>= 0)
820 /* Compare operands number in X and PT. */
821 if (XVECLEN (x
, x_vecexp_pos
) != XVECLEN (pt
, 2))
823 for (j
= 0; j
< XVECLEN (pt
, 2); j
++)
824 if (!subst_pattern_match (XVECEXP (x
, x_vecexp_pos
, j
),
825 XVECEXP (pt
, 2, j
), lineno
))
829 /* Ordinary operator. */
832 /* Compare operands number in X and PT.
833 We count operands differently for X and PT since we compare
834 an operator (with operands directly in RTX) and MATCH_OPERATOR
835 (that has a vector with operands). */
836 if (GET_RTX_LENGTH (code
) != XVECLEN (pt
, 2))
838 for (j
= 0; j
< XVECLEN (pt
, 2); j
++)
839 if (!subst_pattern_match (XEXP (x
, j
), XVECEXP (pt
, 2, j
), lineno
))
843 /* Store the operand to OPERAND_DATA array. */
844 gcc_assert (XINT (pt
, 0) >= 0 && XINT (pt
, 0) < MAX_OPERANDS
);
845 operand_data
[XINT (pt
, 0)] = x
;
849 if (code_pt
== MATCH_PAR_DUP
850 || code_pt
== MATCH_DUP
851 || code_pt
== MATCH_OP_DUP
852 || code_pt
== MATCH_SCRATCH
853 || code_pt
== MATCH_PARALLEL
)
855 /* Currently interface for these constructions isn't defined -
856 probably they aren't needed in input template of define_subst at all.
857 So, for now their usage in define_subst is forbidden. */
858 error_with_line (lineno
, "%s cannot be used in define_subst",
859 GET_RTX_NAME (code_pt
));
862 gcc_assert (code
!= MATCH_PAR_DUP
863 && code_pt
!= MATCH_DUP
864 && code_pt
!= MATCH_OP_DUP
865 && code_pt
!= MATCH_SCRATCH
866 && code_pt
!= MATCH_PARALLEL
867 && code_pt
!= MATCH_OPERAND
868 && code_pt
!= MATCH_OPERATOR
);
869 /* If PT is none of the handled above, then we match only expressions with
870 the same code in X. */
874 fmt
= GET_RTX_FORMAT (code_pt
);
875 len
= GET_RTX_LENGTH (code_pt
);
877 for (i
= 0; i
< len
; i
++)
884 case 'i': case 'w': case 's':
888 if (!subst_pattern_match (XEXP (x
, i
), XEXP (pt
, i
), lineno
))
893 if (XVECLEN (x
, i
) != XVECLEN (pt
, i
))
895 for (j
= 0; j
< XVECLEN (pt
, i
); j
++)
896 if (!subst_pattern_match (XVECEXP (x
, i
, j
), XVECEXP (pt
, i
, j
),
909 /* Examine the attribute "predicable"; discover its boolean values
913 identify_predicable_attribute (void)
915 struct queue_elem
*elem
;
916 char *p_true
, *p_false
;
919 /* Look for the DEFINE_ATTR for `predicable', which must exist. */
920 for (elem
= define_attr_queue
; elem
; elem
= elem
->next
)
921 if (strcmp (XSTR (elem
->data
, 0), "predicable") == 0)
924 error_with_line (define_cond_exec_queue
->lineno
,
925 "attribute `predicable' not defined");
929 value
= XSTR (elem
->data
, 1);
930 p_false
= xstrdup (value
);
931 p_true
= strchr (p_false
, ',');
932 if (p_true
== NULL
|| strchr (++p_true
, ',') != NULL
)
934 error_with_line (elem
->lineno
, "attribute `predicable' is not a boolean");
940 predicable_true
= p_true
;
941 predicable_false
= p_false
;
943 switch (GET_CODE (XEXP (elem
->data
, 2)))
946 value
= XSTR (XEXP (elem
->data
, 2), 0);
950 error_with_line (elem
->lineno
, "attribute `predicable' cannot be const");
955 error_with_line (elem
->lineno
,
956 "attribute `predicable' must have a constant default");
961 if (strcmp (value
, p_true
) == 0)
962 predicable_default
= 1;
963 else if (strcmp (value
, p_false
) == 0)
964 predicable_default
= 0;
967 error_with_line (elem
->lineno
,
968 "unknown value `%s' for `predicable' attribute", value
);
973 /* Return the number of alternatives in constraint S. */
976 n_alternatives (const char *s
)
987 /* The routine scans rtl PATTERN, find match_operand in it and counts
988 number of alternatives. If PATTERN contains several match_operands
989 with different number of alternatives, error is emitted, and the
990 routine returns 0. If all match_operands in PATTERN have the same
991 number of alternatives, it's stored in N_ALT, and the routine returns 1.
992 Argument LINENO is used in when the error is emitted. */
994 get_alternatives_number (rtx pattern
, int *n_alt
, int lineno
)
1003 code
= GET_CODE (pattern
);
1007 i
= n_alternatives (XSTR (pattern
, 2));
1008 /* n_alternatives returns 1 if constraint string is empty -
1009 here we fix it up. */
1010 if (!*(XSTR (pattern
, 2)))
1015 else if (i
&& i
!= *n_alt
)
1017 error_with_line (lineno
,
1018 "wrong number of alternatives in operand %d",
1027 fmt
= GET_RTX_FORMAT (code
);
1028 len
= GET_RTX_LENGTH (code
);
1029 for (i
= 0; i
< len
; i
++)
1034 if (!get_alternatives_number (XEXP (pattern
, i
), n_alt
, lineno
))
1039 if (XVEC (pattern
, i
) == NULL
)
1043 for (j
= XVECLEN (pattern
, i
) - 1; j
>= 0; --j
)
1044 if (!get_alternatives_number (XVECEXP (pattern
, i
, j
),
1049 case 'i': case 'w': case '0': case 's': case 'S': case 'T':
1059 /* Determine how many alternatives there are in INSN, and how many
1063 collect_insn_data (rtx pattern
, int *palt
, int *pmax
)
1069 code
= GET_CODE (pattern
);
1073 i
= n_alternatives (XSTR (pattern
, 2));
1074 *palt
= (i
> *palt
? i
: *palt
);
1077 case MATCH_OPERATOR
:
1079 case MATCH_PARALLEL
:
1080 i
= XINT (pattern
, 0);
1089 fmt
= GET_RTX_FORMAT (code
);
1090 len
= GET_RTX_LENGTH (code
);
1091 for (i
= 0; i
< len
; i
++)
1096 collect_insn_data (XEXP (pattern
, i
), palt
, pmax
);
1100 if (XVEC (pattern
, i
) == NULL
)
1104 for (j
= XVECLEN (pattern
, i
) - 1; j
>= 0; --j
)
1105 collect_insn_data (XVECEXP (pattern
, i
, j
), palt
, pmax
);
1108 case 'i': case 'w': case '0': case 's': case 'S': case 'T':
1118 alter_predicate_for_insn (rtx pattern
, int alt
, int max_op
, int lineno
)
1124 code
= GET_CODE (pattern
);
1129 const char *c
= XSTR (pattern
, 2);
1131 if (n_alternatives (c
) != 1)
1133 error_with_line (lineno
, "too many alternatives for operand %d",
1138 /* Replicate C as needed to fill out ALT alternatives. */
1139 if (c
&& *c
&& alt
> 1)
1141 size_t c_len
= strlen (c
);
1142 size_t len
= alt
* (c_len
+ 1);
1143 char *new_c
= XNEWVEC (char, len
);
1145 memcpy (new_c
, c
, c_len
);
1146 for (i
= 1; i
< alt
; ++i
)
1148 new_c
[i
* (c_len
+ 1) - 1] = ',';
1149 memcpy (&new_c
[i
* (c_len
+ 1)], c
, c_len
);
1151 new_c
[len
- 1] = '\0';
1152 XSTR (pattern
, 2) = new_c
;
1157 case MATCH_OPERATOR
:
1159 case MATCH_PARALLEL
:
1160 XINT (pattern
, 0) += max_op
;
1167 fmt
= GET_RTX_FORMAT (code
);
1168 len
= GET_RTX_LENGTH (code
);
1169 for (i
= 0; i
< len
; i
++)
1176 r
= alter_predicate_for_insn (XEXP (pattern
, i
), alt
,
1183 for (j
= XVECLEN (pattern
, i
) - 1; j
>= 0; --j
)
1185 r
= alter_predicate_for_insn (XVECEXP (pattern
, i
, j
),
1186 alt
, max_op
, lineno
);
1192 case 'i': case 'w': case '0': case 's':
1203 /* Duplicate constraints in PATTERN. If pattern is from original
1204 rtl-template, we need to duplicate each alternative - for that we
1205 need to use duplicate_each_alternative () as a functor ALTER.
1206 If pattern is from output-pattern of define_subst, we need to
1207 duplicate constraints in another way - with duplicate_alternatives ().
1208 N_DUP is multiplication factor. */
1210 alter_constraints (rtx pattern
, int n_dup
, constraints_handler_t alter
)
1216 code
= GET_CODE (pattern
);
1220 XSTR (pattern
, 2) = alter (XSTR (pattern
, 2), n_dup
);
1227 fmt
= GET_RTX_FORMAT (code
);
1228 len
= GET_RTX_LENGTH (code
);
1229 for (i
= 0; i
< len
; i
++)
1236 r
= alter_constraints (XEXP (pattern
, i
), n_dup
, alter
);
1242 for (j
= XVECLEN (pattern
, i
) - 1; j
>= 0; --j
)
1244 r
= alter_constraints (XVECEXP (pattern
, i
, j
), n_dup
, alter
);
1250 case 'i': case 'w': case '0': case 's':
1262 alter_test_for_insn (struct queue_elem
*ce_elem
,
1263 struct queue_elem
*insn_elem
)
1265 return join_c_conditions (XSTR (ce_elem
->data
, 1),
1266 XSTR (insn_elem
->data
, 2));
1269 /* Modify VAL, which is an attribute expression for the "enabled" attribute,
1270 to take "ce_enabled" into account. Return the new expression. */
1272 modify_attr_enabled_ce (rtx val
)
1276 eq_attr
= rtx_alloc (EQ_ATTR
);
1277 ite
= rtx_alloc (IF_THEN_ELSE
);
1278 str
= rtx_alloc (CONST_STRING
);
1280 XSTR (eq_attr
, 0) = "ce_enabled";
1281 XSTR (eq_attr
, 1) = "yes";
1282 XSTR (str
, 0) = "no";
1283 XEXP (ite
, 0) = eq_attr
;
1284 XEXP (ite
, 1) = val
;
1285 XEXP (ite
, 2) = str
;
1290 /* Alter the attribute vector of INSN, which is a COND_EXEC variant created
1291 from a define_insn pattern. We must modify the "predicable" attribute
1292 to be named "ce_enabled", and also change any "enabled" attribute that's
1293 present so that it takes ce_enabled into account.
1294 We rely on the fact that INSN was created with copy_rtx, and modify data
1298 alter_attrs_for_insn (rtx insn
)
1300 static bool global_changes_made
= false;
1301 rtvec vec
= XVEC (insn
, 4);
1305 int predicable_idx
= -1;
1306 int enabled_idx
= -1;
1312 num_elem
= GET_NUM_ELEM (vec
);
1313 for (i
= num_elem
- 1; i
>= 0; --i
)
1315 rtx sub
= RTVEC_ELT (vec
, i
);
1316 switch (GET_CODE (sub
))
1319 if (strcmp (XSTR (sub
, 0), "predicable") == 0)
1322 XSTR (sub
, 0) = "ce_enabled";
1324 else if (strcmp (XSTR (sub
, 0), "enabled") == 0)
1327 XSTR (sub
, 0) = "nonce_enabled";
1331 case SET_ATTR_ALTERNATIVE
:
1332 if (strcmp (XSTR (sub
, 0), "predicable") == 0)
1333 /* We already give an error elsewhere. */
1335 else if (strcmp (XSTR (sub
, 0), "enabled") == 0)
1338 XSTR (sub
, 0) = "nonce_enabled";
1343 if (GET_CODE (SET_DEST (sub
)) != ATTR
)
1345 if (strcmp (XSTR (SET_DEST (sub
), 0), "predicable") == 0)
1347 sub
= SET_SRC (sub
);
1348 if (GET_CODE (sub
) == CONST_STRING
)
1351 XSTR (sub
, 0) = "ce_enabled";
1354 /* We already give an error elsewhere. */
1358 if (strcmp (XSTR (SET_DEST (sub
), 0), "enabled") == 0)
1361 XSTR (SET_DEST (sub
), 0) = "nonce_enabled";
1369 if (predicable_idx
== -1)
1372 if (!global_changes_made
)
1374 struct queue_elem
*elem
;
1376 global_changes_made
= true;
1377 add_define_attr ("ce_enabled");
1378 add_define_attr ("nonce_enabled");
1380 for (elem
= define_attr_queue
; elem
; elem
= elem
->next
)
1381 if (strcmp (XSTR (elem
->data
, 0), "enabled") == 0)
1383 XEXP (elem
->data
, 2)
1384 = modify_attr_enabled_ce (XEXP (elem
->data
, 2));
1387 if (enabled_idx
== -1)
1390 new_vec
= rtvec_alloc (num_elem
+ 1);
1391 for (i
= 0; i
< num_elem
; i
++)
1392 RTVEC_ELT (new_vec
, i
) = RTVEC_ELT (vec
, i
);
1393 val
= rtx_alloc (IF_THEN_ELSE
);
1394 XEXP (val
, 0) = rtx_alloc (EQ_ATTR
);
1395 XEXP (val
, 1) = rtx_alloc (CONST_STRING
);
1396 XEXP (val
, 2) = rtx_alloc (CONST_STRING
);
1397 XSTR (XEXP (val
, 0), 0) = "nonce_enabled";
1398 XSTR (XEXP (val
, 0), 1) = "yes";
1399 XSTR (XEXP (val
, 1), 0) = "yes";
1400 XSTR (XEXP (val
, 2), 0) = "no";
1401 set
= rtx_alloc (SET
);
1402 SET_DEST (set
) = rtx_alloc (ATTR
);
1403 XSTR (SET_DEST (set
), 0) = "enabled";
1404 SET_SRC (set
) = modify_attr_enabled_ce (val
);
1405 RTVEC_ELT (new_vec
, i
) = set
;
1406 XVEC (insn
, 4) = new_vec
;
1409 /* As number of constraints is changed after define_subst, we need to
1410 process attributes as well - we need to duplicate them the same way
1411 that we duplicated constraints in original pattern
1412 ELEM is a queue element, containing our rtl-template,
1413 N_DUP - multiplication factor. */
1415 alter_attrs_for_subst_insn (struct queue_elem
* elem
, int n_dup
)
1417 rtvec vec
= XVEC (elem
->data
, 4);
1421 if (n_dup
< 2 || ! vec
)
1424 num_elem
= GET_NUM_ELEM (vec
);
1425 for (i
= num_elem
- 1; i
>= 0; --i
)
1427 rtx sub
= RTVEC_ELT (vec
, i
);
1428 switch (GET_CODE (sub
))
1431 if (strchr (XSTR (sub
, 1), ',') != NULL
)
1432 XSTR (sub
, 1) = duplicate_alternatives (XSTR (sub
, 1), n_dup
);
1435 case SET_ATTR_ALTERNATIVE
:
1437 error_with_line (elem
->lineno
,
1438 "%s: `define_subst' does not support attributes "
1439 "assigned by `set' and `set_attr_alternative'",
1440 XSTR (elem
->data
, 0));
1449 /* Adjust all of the operand numbers in SRC to match the shift they'll
1450 get from an operand displacement of DISP. Return a pointer after the
1454 shift_output_template (char *dest
, const char *src
, int disp
)
1463 if (ISDIGIT ((unsigned char) c
))
1465 else if (ISALPHA (c
))
1478 alter_output_for_insn (struct queue_elem
*ce_elem
,
1479 struct queue_elem
*insn_elem
,
1480 int alt
, int max_op
)
1482 const char *ce_out
, *insn_out
;
1484 size_t len
, ce_len
, insn_len
;
1486 /* ??? Could coordinate with genoutput to not duplicate code here. */
1488 ce_out
= XSTR (ce_elem
->data
, 2);
1489 insn_out
= XTMPL (insn_elem
->data
, 3);
1490 if (!ce_out
|| *ce_out
== '\0')
1493 ce_len
= strlen (ce_out
);
1494 insn_len
= strlen (insn_out
);
1496 if (*insn_out
== '*')
1497 /* You must take care of the predicate yourself. */
1500 if (*insn_out
== '@')
1502 len
= (ce_len
+ 1) * alt
+ insn_len
+ 1;
1503 p
= result
= XNEWVEC (char, len
);
1509 while (ISSPACE ((unsigned char) *insn_out
));
1511 if (*insn_out
!= '#')
1513 p
= shift_output_template (p
, ce_out
, max_op
);
1519 while (*insn_out
&& *insn_out
!= '\n');
1526 len
= ce_len
+ 1 + insn_len
+ 1;
1527 result
= XNEWVEC (char, len
);
1529 p
= shift_output_template (result
, ce_out
, max_op
);
1531 memcpy (p
, insn_out
, insn_len
+ 1);
1537 /* From string STR "a,b,c" produce "a,b,c,a,b,c,a,b,c", i.e. original
1538 string, duplicated N_DUP times. */
1541 duplicate_alternatives (const char * str
, int n_dup
)
1543 int i
, len
, new_len
;
1550 while (ISSPACE (*str
))
1558 new_len
= (len
+ 1) * n_dup
;
1560 sp
= result
= XNEWVEC (char, new_len
);
1562 /* Global modifier characters mustn't be duplicated: skip if found. */
1563 if (*cp
== '=' || *cp
== '+' || *cp
== '%')
1569 /* Copy original constraints N_DUP times. */
1570 for (i
= 0; i
< n_dup
; i
++, sp
+= len
+1)
1572 memcpy (sp
, cp
, len
);
1573 *(sp
+len
) = (i
== n_dup
- 1) ? '\0' : ',';
1579 /* From string STR "a,b,c" produce "a,a,a,b,b,b,c,c,c", i.e. string where
1580 each alternative from the original string is duplicated N_DUP times. */
1582 duplicate_each_alternative (const char * str
, int n_dup
)
1584 int i
, len
, new_len
;
1585 char *result
, *sp
, *ep
, *cp
;
1590 while (ISSPACE (*str
))
1598 new_len
= (strlen (cp
) + 1) * n_dup
;
1600 sp
= result
= XNEWVEC (char, new_len
);
1602 /* Global modifier characters mustn't be duplicated: skip if found. */
1603 if (*cp
== '=' || *cp
== '+' || *cp
== '%')
1608 if ((ep
= strchr (cp
, ',')) != NULL
)
1612 /* Copy a constraint N_DUP times. */
1613 for (i
= 0; i
< n_dup
; i
++, sp
+= len
+ 1)
1615 memcpy (sp
, cp
, len
);
1616 *(sp
+len
) = (ep
== NULL
&& i
== n_dup
- 1) ? '\0' : ',';
1626 /* Alter the output of INSN whose pattern was modified by
1627 DEFINE_SUBST. We must replicate output strings according
1628 to the new number of alternatives ALT in substituted pattern.
1629 If ALT equals 1, output has one alternative or defined by C
1630 code, then output is returned without any changes. */
1633 alter_output_for_subst_insn (rtx insn
, int alt
)
1635 const char *insn_out
, *sp
;
1636 char *old_out
, *new_out
, *cp
;
1639 insn_out
= XTMPL (insn
, 3);
1641 if (alt
< 2 || *insn_out
== '*' || *insn_out
!= '@')
1644 old_out
= XNEWVEC (char, strlen (insn_out
)),
1647 while (ISSPACE (*sp
) || *sp
== '@')
1651 old_out
[i
++] = *sp
++;
1653 new_len
= alt
* (i
+ 1) + 1;
1655 new_out
= XNEWVEC (char, new_len
);
1658 for (j
= 0, cp
= new_out
+ 1; j
< alt
; j
++, cp
+= i
+ 1)
1660 memcpy (cp
, old_out
, i
);
1661 *(cp
+i
) = (j
== alt
- 1) ? '\0' : '\n';
1667 /* Replicate insns as appropriate for the given DEFINE_COND_EXEC. */
1670 process_one_cond_exec (struct queue_elem
*ce_elem
)
1672 struct queue_elem
*insn_elem
;
1673 for (insn_elem
= define_insn_queue
; insn_elem
; insn_elem
= insn_elem
->next
)
1675 int alternatives
, max_operand
;
1676 rtx pred
, insn
, pattern
, split
;
1680 if (! is_predicable (insn_elem
))
1685 collect_insn_data (insn_elem
->data
, &alternatives
, &max_operand
);
1688 if (XVECLEN (ce_elem
->data
, 0) != 1)
1690 error_with_line (ce_elem
->lineno
, "too many patterns in predicate");
1694 pred
= copy_rtx (XVECEXP (ce_elem
->data
, 0, 0));
1695 pred
= alter_predicate_for_insn (pred
, alternatives
, max_operand
,
1700 /* Construct a new pattern for the new insn. */
1701 insn
= copy_rtx (insn_elem
->data
);
1702 new_name
= XNEWVAR (char, strlen
XSTR (insn_elem
->data
, 0) + 4);
1703 sprintf (new_name
, "*p %s", XSTR (insn_elem
->data
, 0));
1704 XSTR (insn
, 0) = new_name
;
1705 pattern
= rtx_alloc (COND_EXEC
);
1706 XEXP (pattern
, 0) = pred
;
1707 if (XVECLEN (insn
, 1) == 1)
1709 XEXP (pattern
, 1) = XVECEXP (insn
, 1, 0);
1710 XVECEXP (insn
, 1, 0) = pattern
;
1711 PUT_NUM_ELEM (XVEC (insn
, 1), 1);
1715 XEXP (pattern
, 1) = rtx_alloc (PARALLEL
);
1716 XVEC (XEXP (pattern
, 1), 0) = XVEC (insn
, 1);
1717 XVEC (insn
, 1) = rtvec_alloc (1);
1718 XVECEXP (insn
, 1, 0) = pattern
;
1721 XSTR (insn
, 2) = alter_test_for_insn (ce_elem
, insn_elem
);
1722 XTMPL (insn
, 3) = alter_output_for_insn (ce_elem
, insn_elem
,
1723 alternatives
, max_operand
);
1724 alter_attrs_for_insn (insn
);
1726 /* Put the new pattern on the `other' list so that it
1727 (a) is not reprocessed by other define_cond_exec patterns
1728 (b) appears after all normal define_insn patterns.
1730 ??? B is debatable. If one has normal insns that match
1731 cond_exec patterns, they will be preferred over these
1732 generated patterns. Whether this matters in practice, or if
1733 it's a good thing, or whether we should thread these new
1734 patterns into the define_insn chain just after their generator
1735 is something we'll have to experiment with. */
1737 queue_pattern (insn
, &other_tail
, insn_elem
->filename
,
1740 if (!insn_elem
->split
)
1743 /* If the original insn came from a define_insn_and_split,
1744 generate a new split to handle the predicated insn. */
1745 split
= copy_rtx (insn_elem
->split
->data
);
1746 /* Predicate the pattern matched by the split. */
1747 pattern
= rtx_alloc (COND_EXEC
);
1748 XEXP (pattern
, 0) = pred
;
1749 if (XVECLEN (split
, 0) == 1)
1751 XEXP (pattern
, 1) = XVECEXP (split
, 0, 0);
1752 XVECEXP (split
, 0, 0) = pattern
;
1753 PUT_NUM_ELEM (XVEC (split
, 0), 1);
1757 XEXP (pattern
, 1) = rtx_alloc (PARALLEL
);
1758 XVEC (XEXP (pattern
, 1), 0) = XVEC (split
, 0);
1759 XVEC (split
, 0) = rtvec_alloc (1);
1760 XVECEXP (split
, 0, 0) = pattern
;
1762 /* Predicate all of the insns generated by the split. */
1763 for (i
= 0; i
< XVECLEN (split
, 2); i
++)
1765 pattern
= rtx_alloc (COND_EXEC
);
1766 XEXP (pattern
, 0) = pred
;
1767 XEXP (pattern
, 1) = XVECEXP (split
, 2, i
);
1768 XVECEXP (split
, 2, i
) = pattern
;
1770 /* Add the new split to the queue. */
1771 queue_pattern (split
, &other_tail
, read_md_filename
,
1772 insn_elem
->split
->lineno
);
1776 /* Try to apply define_substs to the given ELEM.
1777 Only define_substs, specified via attributes would be applied.
1778 If attribute, requiring define_subst, is set, but no define_subst
1779 was applied, ELEM would be deleted. */
1782 process_substs_on_one_elem (struct queue_elem
*elem
,
1783 struct queue_elem
*queue
)
1785 struct queue_elem
*subst_elem
;
1786 int i
, j
, patterns_match
;
1788 for (subst_elem
= define_subst_queue
;
1789 subst_elem
; subst_elem
= subst_elem
->next
)
1791 int alternatives
, alternatives_subst
;
1793 rtvec subst_pattern_vec
;
1795 if (!has_subst_attribute (elem
, subst_elem
))
1798 /* Compare original rtl-pattern from define_insn with input
1799 pattern from define_subst.
1800 Also, check if numbers of alternatives are the same in all
1802 if (XVECLEN (elem
->data
, 1) != XVECLEN (subst_elem
->data
, 1))
1806 alternatives_subst
= -1;
1807 for (j
= 0; j
< XVECLEN (elem
->data
, 1); j
++)
1809 if (!subst_pattern_match (XVECEXP (elem
->data
, 1, j
),
1810 XVECEXP (subst_elem
->data
, 1, j
),
1811 subst_elem
->lineno
))
1817 if (!get_alternatives_number (XVECEXP (elem
->data
, 1, j
),
1818 &alternatives
, subst_elem
->lineno
))
1825 /* Check if numbers of alternatives are the same in all
1826 match_operands in output template of define_subst. */
1827 for (j
= 0; j
< XVECLEN (subst_elem
->data
, 3); j
++)
1829 if (!get_alternatives_number (XVECEXP (subst_elem
->data
, 3, j
),
1830 &alternatives_subst
,
1831 subst_elem
->lineno
))
1838 if (!patterns_match
)
1841 /* Clear array in which we save occupied indexes of operands. */
1842 memset (used_operands_numbers
, 0, sizeof (used_operands_numbers
));
1844 /* Create a pattern, based on the output one from define_subst. */
1845 subst_pattern_vec
= rtvec_alloc (XVECLEN (subst_elem
->data
, 3));
1846 for (j
= 0; j
< XVECLEN (subst_elem
->data
, 3); j
++)
1848 subst_pattern
= copy_rtx (XVECEXP (subst_elem
->data
, 3, j
));
1850 /* Duplicate constraints in substitute-pattern. */
1851 subst_pattern
= alter_constraints (subst_pattern
, alternatives
,
1852 duplicate_each_alternative
);
1854 subst_pattern
= adjust_operands_numbers (subst_pattern
);
1856 /* Substitute match_dup and match_op_dup in the new pattern and
1857 duplicate constraints. */
1858 subst_pattern
= subst_dup (subst_pattern
, alternatives
,
1859 alternatives_subst
);
1861 replace_duplicating_operands_in_pattern (subst_pattern
);
1863 /* We don't need any constraints in DEFINE_EXPAND. */
1864 if (GET_CODE (elem
->data
) == DEFINE_EXPAND
)
1865 remove_constraints (subst_pattern
);
1867 RTVEC_ELT (subst_pattern_vec
, j
) = subst_pattern
;
1869 XVEC (elem
->data
, 1) = subst_pattern_vec
;
1871 for (i
= 0; i
< MAX_OPERANDS
; i
++)
1872 match_operand_entries_in_pattern
[i
] = NULL
;
1874 if (GET_CODE (elem
->data
) == DEFINE_INSN
)
1876 XTMPL (elem
->data
, 3) =
1877 alter_output_for_subst_insn (elem
->data
, alternatives_subst
);
1878 alter_attrs_for_subst_insn (elem
, alternatives_subst
);
1881 /* Recalculate condition, joining conditions from original and
1882 DEFINE_SUBST input patterns. */
1883 XSTR (elem
->data
, 2) = join_c_conditions (XSTR (subst_elem
->data
, 2),
1884 XSTR (elem
->data
, 2));
1885 /* Mark that subst was applied by changing attribute from "yes"
1887 change_subst_attribute (elem
, subst_elem
, subst_false
);
1890 /* If ELEM contains a subst attribute with value "yes", then we
1891 expected that a subst would be applied, but it wasn't - so,
1892 we need to remove that elementto avoid duplicating. */
1893 for (subst_elem
= define_subst_queue
;
1894 subst_elem
; subst_elem
= subst_elem
->next
)
1896 if (has_subst_attribute (elem
, subst_elem
))
1898 remove_from_queue (elem
, &queue
);
1904 /* This is a subroutine of mark_operands_used_in_match_dup.
1905 This routine is marks all MATCH_OPERANDs inside PATTERN as occupied. */
1907 mark_operands_from_match_dup (rtx pattern
)
1910 int i
, j
, len
, opno
;
1912 if (GET_CODE (pattern
) == MATCH_OPERAND
1913 || GET_CODE (pattern
) == MATCH_OPERATOR
1914 || GET_CODE (pattern
) == MATCH_PARALLEL
)
1916 opno
= XINT (pattern
, 0);
1917 gcc_assert (opno
>= 0 && opno
< MAX_OPERANDS
);
1918 used_operands_numbers
[opno
] = 1;
1920 fmt
= GET_RTX_FORMAT (GET_CODE (pattern
));
1921 len
= GET_RTX_LENGTH (GET_CODE (pattern
));
1922 for (i
= 0; i
< len
; i
++)
1927 mark_operands_from_match_dup (XEXP (pattern
, i
));
1930 for (j
= XVECLEN (pattern
, i
) - 1; j
>= 0; --j
)
1931 mark_operands_from_match_dup (XVECEXP (pattern
, i
, j
));
1937 /* This is a subroutine of adjust_operands_numbers.
1938 It goes through all expressions in PATTERN and when MATCH_DUP is
1939 met, all MATCH_OPERANDs inside it is marked as occupied. The
1940 process of marking is done by routin mark_operands_from_match_dup. */
1942 mark_operands_used_in_match_dup (rtx pattern
)
1945 int i
, j
, len
, opno
;
1947 if (GET_CODE (pattern
) == MATCH_DUP
)
1949 opno
= XINT (pattern
, 0);
1950 gcc_assert (opno
>= 0 && opno
< MAX_OPERANDS
);
1951 mark_operands_from_match_dup (operand_data
[opno
]);
1954 fmt
= GET_RTX_FORMAT (GET_CODE (pattern
));
1955 len
= GET_RTX_LENGTH (GET_CODE (pattern
));
1956 for (i
= 0; i
< len
; i
++)
1961 mark_operands_used_in_match_dup (XEXP (pattern
, i
));
1964 for (j
= XVECLEN (pattern
, i
) - 1; j
>= 0; --j
)
1965 mark_operands_used_in_match_dup (XVECEXP (pattern
, i
, j
));
1971 /* This is subroutine of renumerate_operands_in_pattern.
1972 It finds first not-occupied operand-index. */
1974 find_first_unused_number_of_operand ()
1977 for (i
= 0; i
< MAX_OPERANDS
; i
++)
1978 if (!used_operands_numbers
[i
])
1980 return MAX_OPERANDS
;
1983 /* This is subroutine of adjust_operands_numbers.
1984 It visits all expressions in PATTERN and assigns not-occupied
1985 operand indexes to MATCH_OPERANDs and MATCH_OPERATORs of this
1988 renumerate_operands_in_pattern (rtx pattern
)
1992 int i
, j
, len
, new_opno
;
1993 code
= GET_CODE (pattern
);
1995 if (code
== MATCH_OPERAND
1996 || code
== MATCH_OPERATOR
)
1998 new_opno
= find_first_unused_number_of_operand ();
1999 gcc_assert (new_opno
>= 0 && new_opno
< MAX_OPERANDS
);
2000 XINT (pattern
, 0) = new_opno
;
2001 used_operands_numbers
[new_opno
] = 1;
2004 fmt
= GET_RTX_FORMAT (GET_CODE (pattern
));
2005 len
= GET_RTX_LENGTH (GET_CODE (pattern
));
2006 for (i
= 0; i
< len
; i
++)
2011 renumerate_operands_in_pattern (XEXP (pattern
, i
));
2014 for (j
= XVECLEN (pattern
, i
) - 1; j
>= 0; --j
)
2015 renumerate_operands_in_pattern (XVECEXP (pattern
, i
, j
));
2021 /* If output pattern of define_subst contains MATCH_DUP, then this
2022 expression would be replaced with the pattern, matched with
2023 MATCH_OPERAND from input pattern. This pattern could contain any
2024 number of MATCH_OPERANDs, MATCH_OPERATORs etc., so it's possible
2025 that a MATCH_OPERAND from output_pattern (if any) would have the
2026 same number, as MATCH_OPERAND from copied pattern. To avoid such
2027 indexes overlapping, we assign new indexes to MATCH_OPERANDs,
2028 laying in the output pattern outside of MATCH_DUPs. */
2030 adjust_operands_numbers (rtx pattern
)
2032 mark_operands_used_in_match_dup (pattern
);
2034 renumerate_operands_in_pattern (pattern
);
2039 /* Generate RTL expression
2043 generate_match_dup (int opno
)
2045 rtx return_rtx
= rtx_alloc (MATCH_DUP
);
2046 PUT_CODE (return_rtx
, MATCH_DUP
);
2047 XINT (return_rtx
, 0) = opno
;
2051 /* This routine checks all match_operands in PATTERN and if some of
2052 have the same index, it replaces all of them except the first one to
2054 Usually, match_operands with the same indexes are forbidden, but
2055 after define_subst copy an RTL-expression from original template,
2056 indexes of existed and just-copied match_operands could coincide.
2057 To fix it, we replace one of them with match_dup. */
2059 replace_duplicating_operands_in_pattern (rtx pattern
)
2062 int i
, j
, len
, opno
;
2065 if (GET_CODE (pattern
) == MATCH_OPERAND
)
2067 opno
= XINT (pattern
, 0);
2068 gcc_assert (opno
>= 0 && opno
< MAX_OPERANDS
);
2069 if (match_operand_entries_in_pattern
[opno
] == NULL
)
2071 match_operand_entries_in_pattern
[opno
] = pattern
;
2076 /* Compare predicates before replacing with match_dup. */
2077 if (strcmp (XSTR (pattern
, 1),
2078 XSTR (match_operand_entries_in_pattern
[opno
], 1)))
2080 error ("duplicated match_operands with different predicates were"
2084 return generate_match_dup (opno
);
2087 fmt
= GET_RTX_FORMAT (GET_CODE (pattern
));
2088 len
= GET_RTX_LENGTH (GET_CODE (pattern
));
2089 for (i
= 0; i
< len
; i
++)
2094 mdup
= replace_duplicating_operands_in_pattern (XEXP (pattern
, i
));
2096 XEXP (pattern
, i
) = mdup
;
2099 for (j
= XVECLEN (pattern
, i
) - 1; j
>= 0; --j
)
2102 replace_duplicating_operands_in_pattern (XVECEXP
2105 XVECEXP (pattern
, i
, j
) = mdup
;
2113 /* The routine modifies given input PATTERN of define_subst, replacing
2114 MATCH_DUP and MATCH_OP_DUP with operands from define_insn original
2115 pattern, whose operands are stored in OPERAND_DATA array.
2116 It also duplicates constraints in operands - constraints from
2117 define_insn operands are duplicated N_SUBST_ALT times, constraints
2118 from define_subst operands are duplicated N_ALT times.
2119 After the duplication, returned output rtl-pattern contains every
2120 combination of input constraints Vs constraints from define_subst
2123 subst_dup (rtx pattern
, int n_alt
, int n_subst_alt
)
2127 int i
, j
, len
, opno
;
2129 code
= GET_CODE (pattern
);
2134 opno
= XINT (pattern
, 0);
2136 gcc_assert (opno
>= 0 && opno
< MAX_OPERANDS
);
2138 if (operand_data
[opno
])
2140 pattern
= copy_rtx (operand_data
[opno
]);
2142 /* Duplicate constraints. */
2143 pattern
= alter_constraints (pattern
, n_subst_alt
,
2144 duplicate_alternatives
);
2152 fmt
= GET_RTX_FORMAT (GET_CODE (pattern
));
2153 len
= GET_RTX_LENGTH (GET_CODE (pattern
));
2154 for (i
= 0; i
< len
; i
++)
2159 if (code
!= MATCH_DUP
&& code
!= MATCH_OP_DUP
)
2160 XEXP (pattern
, i
) = subst_dup (XEXP (pattern
, i
),
2161 n_alt
, n_subst_alt
);
2164 if (XVEC (pattern
, i
) == NULL
)
2167 for (j
= XVECLEN (pattern
, i
) - 1; j
>= 0; --j
)
2168 if (code
!= MATCH_DUP
&& code
!= MATCH_OP_DUP
)
2169 XVECEXP (pattern
, i
, j
) = subst_dup (XVECEXP (pattern
, i
, j
),
2170 n_alt
, n_subst_alt
);
2173 case 'i': case 'w': case '0': case 's': case 'S': case 'T':
2183 /* If we have any DEFINE_COND_EXEC patterns, expand the DEFINE_INSN
2184 patterns appropriately. */
2187 process_define_cond_exec (void)
2189 struct queue_elem
*elem
;
2191 identify_predicable_attribute ();
2195 for (elem
= define_cond_exec_queue
; elem
; elem
= elem
->next
)
2196 process_one_cond_exec (elem
);
2199 /* If we have any DEFINE_SUBST patterns, expand DEFINE_INSN and
2200 DEFINE_EXPAND patterns appropriately. */
2203 process_define_subst (void)
2205 struct queue_elem
*elem
, *elem_attr
;
2207 /* Check if each define_subst has corresponding define_subst_attr. */
2208 for (elem
= define_subst_queue
; elem
; elem
= elem
->next
)
2210 for (elem_attr
= define_subst_attr_queue
;
2212 elem_attr
= elem_attr
->next
)
2213 if (strcmp (XSTR (elem
->data
, 0), XSTR (elem_attr
->data
, 1)) == 0)
2216 error_with_line (elem
->lineno
,
2217 "%s: `define_subst' must have at least one "
2218 "corresponding `define_subst_attr'",
2219 XSTR (elem
->data
, 0));
2225 for (elem
= define_insn_queue
; elem
; elem
= elem
->next
)
2226 process_substs_on_one_elem (elem
, define_insn_queue
);
2227 for (elem
= other_queue
; elem
; elem
= elem
->next
)
2229 if (GET_CODE (elem
->data
) != DEFINE_EXPAND
)
2231 process_substs_on_one_elem (elem
, other_queue
);
2235 /* A read_md_files callback for reading an rtx. */
2238 rtx_handle_directive (int lineno
, const char *rtx_name
)
2242 if (read_rtx (rtx_name
, &queue
))
2243 for (x
= queue
; x
; x
= XEXP (x
, 1))
2244 process_rtx (XEXP (x
, 0), lineno
);
2247 /* Comparison function for the mnemonic hash table. */
2250 htab_eq_string (const void *s1
, const void *s2
)
2252 return strcmp ((const char*)s1
, (const char*)s2
) == 0;
2255 /* Add mnemonic STR with length LEN to the mnemonic hash table
2256 MNEMONIC_HTAB. A trailing zero end character is appendend to STR
2257 and a permanent heap copy of STR is created. */
2260 add_mnemonic_string (htab_t mnemonic_htab
, const char *str
, int len
)
2264 char *str_zero
= (char*)alloca (len
+ 1);
2266 memcpy (str_zero
, str
, len
);
2267 str_zero
[len
] = '\0';
2269 slot
= htab_find_slot (mnemonic_htab
, str_zero
, INSERT
);
2274 /* Not found; create a permanent copy and add it to the hash table. */
2275 new_str
= XNEWVAR (char, len
+ 1);
2276 memcpy (new_str
, str_zero
, len
+ 1);
2280 /* Scan INSN for mnemonic strings and add them to the mnemonic hash
2281 table in MNEMONIC_HTAB.
2283 The mnemonics cannot be found if they are emitted using C code.
2285 If a mnemonic string contains ';' or a newline the string assumed
2286 to consist of more than a single instruction. The attribute value
2287 will then be set to the user defined default value. */
2290 gen_mnemonic_setattr (htab_t mnemonic_htab
, rtx insn
)
2292 const char *template_code
, *cp
;
2299 template_code
= XTMPL (insn
, 3);
2301 /* Skip patterns which use C code to emit the template. */
2302 if (template_code
[0] == '*')
2305 if (template_code
[0] == '@')
2306 cp
= &template_code
[1];
2308 cp
= &template_code
[0];
2312 const char *ep
, *sp
;
2315 while (ISSPACE (*cp
))
2318 for (ep
= sp
= cp
; !IS_VSPACE (*ep
) && *ep
!= '\0'; ++ep
)
2323 obstack_1grow (&string_obstack
, ',');
2325 while (cp
< sp
&& ((*cp
>= '0' && *cp
<= '9')
2326 || (*cp
>= 'a' && *cp
<= 'z')))
2329 obstack_1grow (&string_obstack
, *cp
);
2336 if (*cp
== ';' || (*cp
== '\\' && cp
[1] == 'n'))
2338 /* Don't set a value if there are more than one
2339 instruction in the string. */
2340 obstack_next_free (&string_obstack
) =
2341 obstack_next_free (&string_obstack
) - size
;
2350 obstack_1grow (&string_obstack
, '*');
2352 add_mnemonic_string (mnemonic_htab
,
2353 obstack_next_free (&string_obstack
) - size
,
2358 /* An insn definition might emit an empty string. */
2359 if (obstack_object_size (&string_obstack
) == 0)
2362 obstack_1grow (&string_obstack
, '\0');
2364 set_attr
= rtx_alloc (SET_ATTR
);
2365 XSTR (set_attr
, 1) = XOBFINISH (&string_obstack
, char *);
2366 attr_name
= XNEWVAR (char, strlen (MNEMONIC_ATTR_NAME
) + 1);
2367 strcpy (attr_name
, MNEMONIC_ATTR_NAME
);
2368 XSTR (set_attr
, 0) = attr_name
;
2370 if (!XVEC (insn
, 4))
2373 vec_len
= XVECLEN (insn
, 4);
2375 new_vec
= rtvec_alloc (vec_len
+ 1);
2376 for (i
= 0; i
< vec_len
; i
++)
2377 RTVEC_ELT (new_vec
, i
) = XVECEXP (insn
, 4, i
);
2378 RTVEC_ELT (new_vec
, vec_len
) = set_attr
;
2379 XVEC (insn
, 4) = new_vec
;
2382 /* This function is called for the elements in the mnemonic hashtable
2383 and generates a comma separated list of the mnemonics. */
2386 mnemonic_htab_callback (void **slot
, void *info ATTRIBUTE_UNUSED
)
2388 obstack_grow (&string_obstack
, (char*)*slot
, strlen ((char*)*slot
));
2389 obstack_1grow (&string_obstack
, ',');
2393 /* Generate (set_attr "mnemonic" "..") RTXs and append them to every
2394 insn definition in case the back end requests it by defining the
2395 mnemonic attribute. The values for the attribute will be extracted
2396 from the output patterns of the insn definitions as far as
2400 gen_mnemonic_attr (void)
2402 struct queue_elem
*elem
;
2403 rtx mnemonic_attr
= NULL
;
2404 htab_t mnemonic_htab
;
2405 const char *str
, *p
;
2411 /* Look for the DEFINE_ATTR for `mnemonic'. */
2412 for (elem
= define_attr_queue
; elem
!= *define_attr_tail
; elem
= elem
->next
)
2413 if (GET_CODE (elem
->data
) == DEFINE_ATTR
2414 && strcmp (XSTR (elem
->data
, 0), MNEMONIC_ATTR_NAME
) == 0)
2416 mnemonic_attr
= elem
->data
;
2420 /* A (define_attr "mnemonic" "...") indicates that the back-end
2421 wants a mnemonic attribute to be generated. */
2425 mnemonic_htab
= htab_create_alloc (MNEMONIC_HTAB_SIZE
, htab_hash_string
,
2426 htab_eq_string
, 0, xcalloc
, free
);
2428 for (elem
= define_insn_queue
; elem
; elem
= elem
->next
)
2430 rtx insn
= elem
->data
;
2433 /* Check if the insn definition already has
2434 (set_attr "mnemonic" ...). */
2436 for (i
= 0; i
< XVECLEN (insn
, 4); i
++)
2437 if (strcmp (XSTR (XVECEXP (insn
, 4, i
), 0), MNEMONIC_ATTR_NAME
) == 0)
2444 gen_mnemonic_setattr (mnemonic_htab
, insn
);
2447 /* Add the user defined values to the hash table. */
2448 str
= XSTR (mnemonic_attr
, 1);
2449 while ((p
= scan_comma_elt (&str
)) != NULL
)
2450 add_mnemonic_string (mnemonic_htab
, p
, str
- p
);
2452 htab_traverse (mnemonic_htab
, mnemonic_htab_callback
, NULL
);
2454 /* Replace the last ',' with the zero end character. */
2455 *((char *)obstack_next_free (&string_obstack
) - 1) = '\0';
2456 XSTR (mnemonic_attr
, 1) = XOBFINISH (&string_obstack
, char *);
2459 /* Check if there are DEFINE_ATTRs with the same name. */
2461 check_define_attr_duplicates ()
2463 struct queue_elem
*elem
;
2468 attr_htab
= htab_create (500, htab_hash_string
, htab_eq_string
, NULL
);
2470 for (elem
= define_attr_queue
; elem
; elem
= elem
->next
)
2472 attr_name
= xstrdup (XSTR (elem
->data
, 0));
2474 slot
= htab_find_slot (attr_htab
, attr_name
, INSERT
);
2479 error_with_line (elem
->lineno
, "redefinition of attribute '%s'",
2481 htab_delete (attr_htab
);
2488 htab_delete (attr_htab
);
2491 /* The entry point for initializing the reader. */
2494 init_rtx_reader_args_cb (int argc
, char **argv
,
2495 bool (*parse_opt
) (const char *))
2497 /* Prepare to read input. */
2498 condition_table
= htab_create (500, hash_c_test
, cmp_c_test
, NULL
);
2499 init_predicate_table ();
2500 obstack_init (rtl_obstack
);
2502 /* Start at 1, to make 0 available for CODE_FOR_nothing. */
2505 read_md_files (argc
, argv
, parse_opt
, rtx_handle_directive
);
2507 if (define_attr_queue
!= NULL
)
2508 check_define_attr_duplicates ();
2510 /* Process define_cond_exec patterns. */
2511 if (define_cond_exec_queue
!= NULL
)
2512 process_define_cond_exec ();
2514 /* Process define_subst patterns. */
2515 if (define_subst_queue
!= NULL
)
2516 process_define_subst ();
2518 if (define_attr_queue
!= NULL
)
2519 gen_mnemonic_attr ();
2524 /* Programs that don't have their own options can use this entry point
2527 init_rtx_reader_args (int argc
, char **argv
)
2529 return init_rtx_reader_args_cb (argc
, argv
, 0);
2532 /* The entry point for reading a single rtx from an md file. Return
2533 the rtx, or NULL if the md file has been fully processed.
2534 Return the line where the rtx was found in LINENO.
2535 Return the number of code generating rtx'en read since the start
2536 of the md file in SEQNR. */
2539 read_md_rtx (int *lineno
, int *seqnr
)
2541 struct queue_elem
**queue
, *elem
;
2546 /* Read all patterns from a given queue before moving on to the next. */
2547 if (define_attr_queue
!= NULL
)
2548 queue
= &define_attr_queue
;
2549 else if (define_pred_queue
!= NULL
)
2550 queue
= &define_pred_queue
;
2551 else if (define_insn_queue
!= NULL
)
2552 queue
= &define_insn_queue
;
2553 else if (other_queue
!= NULL
)
2554 queue
= &other_queue
;
2559 *queue
= elem
->next
;
2561 read_md_filename
= elem
->filename
;
2562 *lineno
= elem
->lineno
;
2563 *seqnr
= 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. */
2573 switch (GET_CODE (desc
))
2578 if (maybe_eval_c_test (XSTR (desc
, 2)) != 0)
2580 else if (insn_elision
)
2583 /* *seqnr is used here so the name table will match caller's
2584 idea of insn numbering, whether or not elision is active. */
2585 record_insn_name (*seqnr
, XSTR (desc
, 0));
2589 case DEFINE_PEEPHOLE
:
2590 case DEFINE_PEEPHOLE2
:
2591 if (maybe_eval_c_test (XSTR (desc
, 1)) != 0)
2593 else if (insn_elision
)
2604 /* Helper functions for insn elision. */
2606 /* Compute a hash function of a c_test structure, which is keyed
2607 by its ->expr field. */
2609 hash_c_test (const void *x
)
2611 const struct c_test
*a
= (const struct c_test
*) x
;
2612 const unsigned char *base
, *s
= (const unsigned char *) a
->expr
;
2620 while ((c
= *s
++) != '\0')
2622 hash
+= c
+ (c
<< 17);
2627 hash
+= len
+ (len
<< 17);
2633 /* Compare two c_test expression structures. */
2635 cmp_c_test (const void *x
, const void *y
)
2637 const struct c_test
*a
= (const struct c_test
*) x
;
2638 const struct c_test
*b
= (const struct c_test
*) y
;
2640 return !strcmp (a
->expr
, b
->expr
);
2643 /* Given a string representing a C test expression, look it up in the
2644 condition_table and report whether or not its value is known
2645 at compile time. Returns a tristate: 1 for known true, 0 for
2646 known false, -1 for unknown. */
2648 maybe_eval_c_test (const char *expr
)
2650 const struct c_test
*test
;
2651 struct c_test dummy
;
2657 test
= (const struct c_test
*)htab_find (condition_table
, &dummy
);
2663 /* Record the C test expression EXPR in the condition_table, with
2664 value VAL. Duplicates clobber previous entries. */
2667 add_c_test (const char *expr
, int value
)
2669 struct c_test
*test
;
2674 test
= XNEW (struct c_test
);
2676 test
->value
= value
;
2678 *(htab_find_slot (condition_table
, test
, INSERT
)) = test
;
2681 /* For every C test, call CALLBACK with two arguments: a pointer to
2682 the condition structure and INFO. Stops when CALLBACK returns zero. */
2684 traverse_c_tests (htab_trav callback
, void *info
)
2686 if (condition_table
)
2687 htab_traverse (condition_table
, callback
, info
);
2690 /* Helper functions for define_predicate and define_special_predicate
2691 processing. Shared between genrecog.c and genpreds.c. */
2693 static htab_t predicate_table
;
2694 struct pred_data
*first_predicate
;
2695 static struct pred_data
**last_predicate
= &first_predicate
;
2698 hash_struct_pred_data (const void *ptr
)
2700 return htab_hash_string (((const struct pred_data
*)ptr
)->name
);
2704 eq_struct_pred_data (const void *a
, const void *b
)
2706 return !strcmp (((const struct pred_data
*)a
)->name
,
2707 ((const struct pred_data
*)b
)->name
);
2711 lookup_predicate (const char *name
)
2713 struct pred_data key
;
2715 return (struct pred_data
*) htab_find (predicate_table
, &key
);
2718 /* Record that predicate PRED can accept CODE. */
2721 add_predicate_code (struct pred_data
*pred
, enum rtx_code code
)
2723 if (!pred
->codes
[code
])
2726 pred
->codes
[code
] = true;
2728 if (GET_RTX_CLASS (code
) != RTX_CONST_OBJ
)
2729 pred
->allows_non_const
= true;
2736 && code
!= STRICT_LOW_PART
)
2737 pred
->allows_non_lvalue
= true;
2739 if (pred
->num_codes
== 1)
2740 pred
->singleton
= code
;
2741 else if (pred
->num_codes
== 2)
2742 pred
->singleton
= UNKNOWN
;
2747 add_predicate (struct pred_data
*pred
)
2749 void **slot
= htab_find_slot (predicate_table
, pred
, INSERT
);
2752 error ("duplicate predicate definition for '%s'", pred
->name
);
2756 *last_predicate
= pred
;
2757 last_predicate
= &pred
->next
;
2760 /* This array gives the initial content of the predicate table. It
2761 has entries for all predicates defined in recog.c. */
2763 struct std_pred_table
2767 bool allows_const_p
;
2768 RTX_CODE codes
[NUM_RTX_CODE
];
2771 static const struct std_pred_table std_preds
[] = {
2772 {"general_operand", false, true, {SUBREG
, REG
, MEM
}},
2773 {"address_operand", true, true, {SUBREG
, REG
, MEM
, PLUS
, MINUS
, MULT
}},
2774 {"register_operand", false, false, {SUBREG
, REG
}},
2775 {"pmode_register_operand", true, false, {SUBREG
, REG
}},
2776 {"scratch_operand", false, false, {SCRATCH
, REG
}},
2777 {"immediate_operand", false, true, {UNKNOWN
}},
2778 {"const_int_operand", false, false, {CONST_INT
}},
2779 {"const_double_operand", false, false, {CONST_INT
, CONST_DOUBLE
}},
2780 {"nonimmediate_operand", false, false, {SUBREG
, REG
, MEM
}},
2781 {"nonmemory_operand", false, true, {SUBREG
, REG
}},
2782 {"push_operand", false, false, {MEM
}},
2783 {"pop_operand", false, false, {MEM
}},
2784 {"memory_operand", false, false, {SUBREG
, MEM
}},
2785 {"indirect_operand", false, false, {SUBREG
, MEM
}},
2786 {"ordered_comparison_operator", false, false, {EQ
, NE
,
2788 LEU
, LTU
, GEU
, GTU
}},
2789 {"comparison_operator", false, false, {EQ
, NE
,
2796 #define NUM_KNOWN_STD_PREDS ARRAY_SIZE (std_preds)
2798 /* Initialize the table of predicate definitions, starting with
2799 the information we have on generic predicates. */
2802 init_predicate_table (void)
2805 struct pred_data
*pred
;
2807 predicate_table
= htab_create_alloc (37, hash_struct_pred_data
,
2808 eq_struct_pred_data
, 0,
2811 for (i
= 0; i
< NUM_KNOWN_STD_PREDS
; i
++)
2813 pred
= XCNEW (struct pred_data
);
2814 pred
->name
= std_preds
[i
].name
;
2815 pred
->special
= std_preds
[i
].special
;
2817 for (j
= 0; std_preds
[i
].codes
[j
] != 0; j
++)
2818 add_predicate_code (pred
, std_preds
[i
].codes
[j
]);
2820 if (std_preds
[i
].allows_const_p
)
2821 for (j
= 0; j
< NUM_RTX_CODE
; j
++)
2822 if (GET_RTX_CLASS (j
) == RTX_CONST_OBJ
)
2823 add_predicate_code (pred
, (enum rtx_code
) j
);
2825 add_predicate (pred
);
2829 /* These functions allow linkage with print-rtl.c. Also, some generators
2830 like to annotate their output with insn names. */
2832 /* Holds an array of names indexed by insn_code_number. */
2833 static char **insn_name_ptr
= 0;
2834 static int insn_name_ptr_size
= 0;
2837 get_insn_name (int code
)
2839 if (code
< insn_name_ptr_size
)
2840 return insn_name_ptr
[code
];
2846 record_insn_name (int code
, const char *name
)
2848 static const char *last_real_name
= "insn";
2849 static int last_real_code
= 0;
2852 if (insn_name_ptr_size
<= code
)
2855 new_size
= (insn_name_ptr_size
? insn_name_ptr_size
* 2 : 512);
2856 insn_name_ptr
= XRESIZEVEC (char *, insn_name_ptr
, new_size
);
2857 memset (insn_name_ptr
+ insn_name_ptr_size
, 0,
2858 sizeof(char *) * (new_size
- insn_name_ptr_size
));
2859 insn_name_ptr_size
= new_size
;
2862 if (!name
|| name
[0] == '\0')
2864 new_name
= XNEWVAR (char, strlen (last_real_name
) + 10);
2865 sprintf (new_name
, "%s+%d", last_real_name
, code
- last_real_code
);
2869 last_real_name
= new_name
= xstrdup (name
);
2870 last_real_code
= code
;
2873 insn_name_ptr
[code
] = new_name
;
2876 /* Make STATS describe the operands that appear in rtx X. */
2879 get_pattern_stats_1 (struct pattern_stats
*stats
, rtx x
)
2889 code
= GET_CODE (x
);
2893 case MATCH_OPERATOR
:
2894 case MATCH_PARALLEL
:
2895 stats
->max_opno
= MAX (stats
->max_opno
, XINT (x
, 0));
2902 stats
->max_dup_opno
= MAX (stats
->max_dup_opno
, XINT (x
, 0));
2906 stats
->max_scratch_opno
= MAX (stats
->max_scratch_opno
, XINT (x
, 0));
2913 fmt
= GET_RTX_FORMAT (code
);
2914 len
= GET_RTX_LENGTH (code
);
2915 for (i
= 0; i
< len
; i
++)
2917 if (fmt
[i
] == 'e' || fmt
[i
] == 'u')
2918 get_pattern_stats_1 (stats
, XEXP (x
, i
));
2919 else if (fmt
[i
] == 'E')
2922 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2923 get_pattern_stats_1 (stats
, XVECEXP (x
, i
, j
));
2928 /* Make STATS describe the operands that appear in instruction pattern
2932 get_pattern_stats (struct pattern_stats
*stats
, rtvec pattern
)
2936 stats
->max_opno
= -1;
2937 stats
->max_dup_opno
= -1;
2938 stats
->max_scratch_opno
= -1;
2939 stats
->num_dups
= 0;
2941 len
= GET_NUM_ELEM (pattern
);
2942 for (i
= 0; i
< len
; i
++)
2943 get_pattern_stats_1 (stats
, RTVEC_ELT (pattern
, i
));
2945 stats
->num_generator_args
= stats
->max_opno
+ 1;
2946 stats
->num_insn_operands
= MAX (stats
->max_opno
,
2947 stats
->max_scratch_opno
) + 1;
2948 stats
->num_operand_vars
= MAX (stats
->max_opno
,
2949 MAX (stats
->max_dup_opno
,
2950 stats
->max_scratch_opno
)) + 1;