1 /* Generate code from machine description to recognize rtl as insns.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GCC is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 /* This program is used to produce insn-recog.c, which contains a
24 function called `recog' plus its subroutines. These functions
25 contain a decision tree that recognizes whether an rtx, the
26 argument given to recog, is a valid instruction.
28 recog returns -1 if the rtx is not valid. If the rtx is valid,
29 recog returns a nonnegative number which is the insn code number
30 for the pattern that matched. This is the same as the order in the
31 machine description of the entry that matched. This number can be
32 used as an index into various insn_* tables, such as insn_template,
33 insn_outfun, and insn_n_operands (found in insn-output.c).
35 The third argument to recog is an optional pointer to an int. If
36 present, recog will accept a pattern if it matches except for
37 missing CLOBBER expressions at the end. In that case, the value
38 pointed to by the optional pointer will be set to the number of
39 CLOBBERs that need to be added (it should be initialized to zero by
40 the caller). If it is set nonzero, the caller should allocate a
41 PARALLEL of the appropriate size, copy the initial entries, and
42 call add_clobbers (found in insn-emit.c) to fill in the CLOBBERs.
44 This program also generates the function `split_insns', which
45 returns 0 if the rtl could not be split, or it returns the split
48 This program also generates the function `peephole2_insns', which
49 returns 0 if the rtl could not be matched. If there was a match,
50 the new rtl is returned in an INSN list, and LAST_INSN will point
51 to the last recognized insn in the old sequence. */
55 #include "coretypes.h"
60 #include "gensupport.h"
62 #define OUTPUT_LABEL(INDENT_STRING, LABEL_NUMBER) \
63 printf("%sL%d: ATTRIBUTE_UNUSED_LABEL\n", (INDENT_STRING), (LABEL_NUMBER))
65 /* A listhead of decision trees. The alternatives to a node are kept
66 in a doubly-linked list so we can easily add nodes to the proper
67 place when merging. */
71 struct decision
*first
;
72 struct decision
*last
;
75 /* These types are roughly in the order in which we'd like to test them. */
79 DT_mode
, DT_code
, DT_veclen
,
80 DT_elt_zero_int
, DT_elt_one_int
, DT_elt_zero_wide
, DT_elt_zero_wide_safe
,
82 DT_veclen_ge
, DT_dup
, DT_pred
, DT_c_test
,
83 DT_accept_op
, DT_accept_insn
86 /* A single test. The two accept types aren't tests per-se, but
87 their equality (or lack thereof) does affect tree merging so
88 it is convenient to keep them here. */
92 /* A linked list through the tests attached to a node. */
93 struct decision_test
*next
;
95 enum decision_type type
;
99 int num_insns
; /* Number if insn in a define_peephole2. */
100 enum machine_mode mode
; /* Machine mode of node. */
101 RTX_CODE code
; /* Code to test. */
105 const char *name
; /* Predicate to call. */
106 const struct pred_data
*data
;
107 /* Optimization hints for this predicate. */
108 enum machine_mode mode
; /* Machine mode for node. */
111 const char *c_test
; /* Additional test to perform. */
112 int veclen
; /* Length of vector. */
113 int dup
; /* Number of operand to compare against. */
114 HOST_WIDE_INT intval
; /* Value for XINT for XWINT. */
115 int opno
; /* Operand number matched. */
118 int code_number
; /* Insn number matched. */
119 int lineno
; /* Line number of the insn. */
120 int num_clobbers_to_add
; /* Number of CLOBBERs to be added. */
125 /* Data structure for decision tree for recognizing legitimate insns. */
129 struct decision_head success
; /* Nodes to test on success. */
130 struct decision
*next
; /* Node to test on failure. */
131 struct decision
*prev
; /* Node whose failure tests us. */
132 struct decision
*afterward
; /* Node to test on success,
133 but failure of successor nodes. */
135 const char *position
; /* String denoting position in pattern. */
137 struct decision_test
*tests
; /* The tests for this node. */
139 int number
; /* Node number, used for labels */
140 int subroutine_number
; /* Number of subroutine this node starts */
141 int need_label
; /* Label needs to be output. */
144 #define SUBROUTINE_THRESHOLD 100
146 static int next_subroutine_number
;
148 /* We can write three types of subroutines: One for insn recognition,
149 one to split insns, and one for peephole-type optimizations. This
150 defines which type is being written. */
153 RECOG
, SPLIT
, PEEPHOLE2
156 #define IS_SPLIT(X) ((X) != RECOG)
158 /* Next available node number for tree nodes. */
160 static int next_number
;
162 /* Next number to use as an insn_code. */
164 static int next_insn_code
;
166 /* Record the highest depth we ever have so we know how many variables to
167 allocate in each subroutine we make. */
169 static int max_depth
;
171 /* The line number of the start of the pattern currently being processed. */
172 static int pattern_lineno
;
174 /* Predicate handling.
176 We construct from the machine description a table mapping each
177 predicate to a list of the rtl codes it can possibly match. The
178 function 'maybe_both_true' uses it to deduce that there are no
179 expressions that can be matches by certain pairs of tree nodes.
180 Also, if a predicate can match only one code, we can hardwire that
181 code into the node testing the predicate.
183 Some predicates are flagged as special. validate_pattern will not
184 warn about modeless match_operand expressions if they have a
185 special predicate. Predicates that allow only constants are also
186 treated as special, for this purpose.
188 validate_pattern will warn about predicates that allow non-lvalues
189 when they appear in destination operands.
191 Calculating the set of rtx codes that can possibly be accepted by a
192 predicate expression EXP requires a three-state logic: any given
193 subexpression may definitively accept a code C (Y), definitively
194 reject a code C (N), or may have an indeterminate effect (I). N
195 and I is N; Y or I is Y; Y and I, N or I are both I. Here are full
206 We represent Y with 1, N with 0, I with 2. If any code is left in
207 an I state by the complete expression, we must assume that that
208 code can be accepted. */
214 #define TRISTATE_AND(a,b) \
215 ((a) == I ? ((b) == N ? N : I) : \
216 (b) == I ? ((a) == N ? N : I) : \
219 #define TRISTATE_OR(a,b) \
220 ((a) == I ? ((b) == Y ? Y : I) : \
221 (b) == I ? ((a) == Y ? Y : I) : \
224 #define TRISTATE_NOT(a) \
225 ((a) == I ? I : !(a))
227 /* 0 means no warning about that code yet, 1 means warned. */
228 static char did_you_mean_codes
[NUM_RTX_CODE
];
230 /* Recursively calculate the set of rtx codes accepted by the
231 predicate expression EXP, writing the result to CODES. */
233 compute_predicate_codes (rtx exp
, char codes
[NUM_RTX_CODE
])
235 char op0_codes
[NUM_RTX_CODE
];
236 char op1_codes
[NUM_RTX_CODE
];
237 char op2_codes
[NUM_RTX_CODE
];
240 switch (GET_CODE (exp
))
243 compute_predicate_codes (XEXP (exp
, 0), op0_codes
);
244 compute_predicate_codes (XEXP (exp
, 1), op1_codes
);
245 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
246 codes
[i
] = TRISTATE_AND (op0_codes
[i
], op1_codes
[i
]);
250 compute_predicate_codes (XEXP (exp
, 0), op0_codes
);
251 compute_predicate_codes (XEXP (exp
, 1), op1_codes
);
252 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
253 codes
[i
] = TRISTATE_OR (op0_codes
[i
], op1_codes
[i
]);
256 compute_predicate_codes (XEXP (exp
, 0), op0_codes
);
257 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
258 codes
[i
] = TRISTATE_NOT (op0_codes
[i
]);
262 /* a ? b : c accepts the same codes as (a & b) | (!a & c). */
263 compute_predicate_codes (XEXP (exp
, 0), op0_codes
);
264 compute_predicate_codes (XEXP (exp
, 1), op1_codes
);
265 compute_predicate_codes (XEXP (exp
, 2), op2_codes
);
266 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
267 codes
[i
] = TRISTATE_OR (TRISTATE_AND (op0_codes
[i
], op1_codes
[i
]),
268 TRISTATE_AND (TRISTATE_NOT (op0_codes
[i
]),
273 /* MATCH_CODE allows a specified list of codes. However, if it
274 does not apply to the top level of the expression, it does not
275 constrain the set of codes for the top level. */
276 if (XSTR (exp
, 1)[0] != '\0')
278 memset (codes
, Y
, NUM_RTX_CODE
);
282 memset (codes
, N
, NUM_RTX_CODE
);
284 const char *next_code
= XSTR (exp
, 0);
287 if (*next_code
== '\0')
289 error_with_line (pattern_lineno
, "empty match_code expression");
293 while ((code
= scan_comma_elt (&next_code
)) != 0)
295 size_t n
= next_code
- code
;
298 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
299 if (!strncmp (code
, GET_RTX_NAME (i
), n
)
300 && GET_RTX_NAME (i
)[n
] == '\0')
308 error_with_line (pattern_lineno
,
309 "match_code \"%.*s\" matches nothing",
311 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
312 if (!strncasecmp (code
, GET_RTX_NAME (i
), n
)
313 && GET_RTX_NAME (i
)[n
] == '\0'
314 && !did_you_mean_codes
[i
])
316 did_you_mean_codes
[i
] = 1;
317 message_with_line (pattern_lineno
, "(did you mean \"%s\"?)", GET_RTX_NAME (i
));
326 /* MATCH_OPERAND disallows the set of codes that the named predicate
327 disallows, and is indeterminate for the codes that it does allow. */
329 struct pred_data
*p
= lookup_predicate (XSTR (exp
, 1));
332 error_with_line (pattern_lineno
,
333 "reference to unknown predicate '%s'",
337 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
338 codes
[i
] = p
->codes
[i
] ? I
: N
;
344 /* (match_test WHATEVER) is completely indeterminate. */
345 memset (codes
, I
, NUM_RTX_CODE
);
349 error_with_line (pattern_lineno
,
350 "'%s' cannot be used in a define_predicate expression",
351 GET_RTX_NAME (GET_CODE (exp
)));
352 memset (codes
, I
, NUM_RTX_CODE
);
361 /* Process a define_predicate expression: compute the set of predicates
362 that can be matched, and record this as a known predicate. */
364 process_define_predicate (rtx desc
)
366 struct pred_data
*pred
= XCNEW (struct pred_data
);
367 char codes
[NUM_RTX_CODE
];
370 pred
->name
= XSTR (desc
, 0);
371 if (GET_CODE (desc
) == DEFINE_SPECIAL_PREDICATE
)
374 compute_predicate_codes (XEXP (desc
, 1), codes
);
376 for (i
= 0; i
< NUM_RTX_CODE
; i
++)
378 add_predicate_code (pred
, (enum rtx_code
) i
);
380 add_predicate (pred
);
387 static struct decision
*new_decision
388 (const char *, struct decision_head
*);
389 static struct decision_test
*new_decision_test
390 (enum decision_type
, struct decision_test
***);
391 static rtx find_operand
393 static rtx find_matching_operand
395 static void validate_pattern
396 (rtx
, rtx
, rtx
, int);
397 static struct decision
*add_to_sequence
398 (rtx
, struct decision_head
*, const char *, enum routine_type
, int);
400 static int maybe_both_true_2
401 (struct decision_test
*, struct decision_test
*);
402 static int maybe_both_true_1
403 (struct decision_test
*, struct decision_test
*);
404 static int maybe_both_true
405 (struct decision
*, struct decision
*, int);
407 static int nodes_identical_1
408 (struct decision_test
*, struct decision_test
*);
409 static int nodes_identical
410 (struct decision
*, struct decision
*);
411 static void merge_accept_insn
412 (struct decision
*, struct decision
*);
413 static void merge_trees
414 (struct decision_head
*, struct decision_head
*);
416 static void factor_tests
417 (struct decision_head
*);
418 static void simplify_tests
419 (struct decision_head
*);
420 static int break_out_subroutines
421 (struct decision_head
*, int);
422 static void find_afterward
423 (struct decision_head
*, struct decision
*);
425 static void change_state
426 (const char *, const char *, const char *);
427 static void print_code
429 static void write_afterward
430 (struct decision
*, struct decision
*, const char *);
431 static struct decision
*write_switch
432 (struct decision
*, int);
433 static void write_cond
434 (struct decision_test
*, int, enum routine_type
);
435 static void write_action
436 (struct decision
*, struct decision_test
*, int, int,
437 struct decision
*, enum routine_type
);
438 static int is_unconditional
439 (struct decision_test
*, enum routine_type
);
440 static int write_node
441 (struct decision
*, int, enum routine_type
);
442 static void write_tree_1
443 (struct decision_head
*, int, enum routine_type
);
444 static void write_tree
445 (struct decision_head
*, const char *, enum routine_type
, int);
446 static void write_subroutine
447 (struct decision_head
*, enum routine_type
);
448 static void write_subroutines
449 (struct decision_head
*, enum routine_type
);
450 static void write_header
453 static struct decision_head make_insn_sequence
454 (rtx
, enum routine_type
);
455 static void process_tree
456 (struct decision_head
*, enum routine_type
);
458 static void debug_decision_0
459 (struct decision
*, int, int);
460 static void debug_decision_1
461 (struct decision
*, int);
462 static void debug_decision_2
463 (struct decision_test
*);
464 extern void debug_decision
466 extern void debug_decision_list
469 /* Create a new node in sequence after LAST. */
471 static struct decision
*
472 new_decision (const char *position
, struct decision_head
*last
)
474 struct decision
*new_decision
= XCNEW (struct decision
);
476 new_decision
->success
= *last
;
477 new_decision
->position
= xstrdup (position
);
478 new_decision
->number
= next_number
++;
480 last
->first
= last
->last
= new_decision
;
484 /* Create a new test and link it in at PLACE. */
486 static struct decision_test
*
487 new_decision_test (enum decision_type type
, struct decision_test
***pplace
)
489 struct decision_test
**place
= *pplace
;
490 struct decision_test
*test
;
492 test
= XNEW (struct decision_test
);
503 /* Search for and return operand N, stop when reaching node STOP. */
506 find_operand (rtx pattern
, int n
, rtx stop
)
516 code
= GET_CODE (pattern
);
517 if ((code
== MATCH_SCRATCH
518 || code
== MATCH_OPERAND
519 || code
== MATCH_OPERATOR
520 || code
== MATCH_PARALLEL
)
521 && XINT (pattern
, 0) == n
)
524 fmt
= GET_RTX_FORMAT (code
);
525 len
= GET_RTX_LENGTH (code
);
526 for (i
= 0; i
< len
; i
++)
531 if ((r
= find_operand (XEXP (pattern
, i
), n
, stop
)) != NULL_RTX
)
536 if (! XVEC (pattern
, i
))
541 for (j
= 0; j
< XVECLEN (pattern
, i
); j
++)
542 if ((r
= find_operand (XVECEXP (pattern
, i
, j
), n
, stop
))
547 case 'i': case 'w': case '0': case 's':
558 /* Search for and return operand M, such that it has a matching
559 constraint for operand N. */
562 find_matching_operand (rtx pattern
, int n
)
569 code
= GET_CODE (pattern
);
570 if (code
== MATCH_OPERAND
571 && (XSTR (pattern
, 2)[0] == '0' + n
572 || (XSTR (pattern
, 2)[0] == '%'
573 && XSTR (pattern
, 2)[1] == '0' + n
)))
576 fmt
= GET_RTX_FORMAT (code
);
577 len
= GET_RTX_LENGTH (code
);
578 for (i
= 0; i
< len
; i
++)
583 if ((r
= find_matching_operand (XEXP (pattern
, i
), n
)))
588 if (! XVEC (pattern
, i
))
593 for (j
= 0; j
< XVECLEN (pattern
, i
); j
++)
594 if ((r
= find_matching_operand (XVECEXP (pattern
, i
, j
), n
)))
598 case 'i': case 'w': case '0': case 's':
610 /* Check for various errors in patterns. SET is nonnull for a destination,
611 and is the complete set pattern. SET_CODE is '=' for normal sets, and
612 '+' within a context that requires in-out constraints. */
615 validate_pattern (rtx pattern
, rtx insn
, rtx set
, int set_code
)
622 code
= GET_CODE (pattern
);
630 if (find_operand (insn
, XINT (pattern
, 0), pattern
) == pattern
)
631 error_with_line (pattern_lineno
,
632 "operand %i duplicated before defined",
638 const char *pred_name
= XSTR (pattern
, 1);
639 const struct pred_data
*pred
;
642 if (GET_CODE (insn
) == DEFINE_INSN
)
643 c_test
= XSTR (insn
, 2);
645 c_test
= XSTR (insn
, 1);
647 if (pred_name
[0] != 0)
649 pred
= lookup_predicate (pred_name
);
651 message_with_line (pattern_lineno
,
652 "warning: unknown predicate '%s'",
658 if (code
== MATCH_OPERAND
)
660 const char constraints0
= XSTR (pattern
, 2)[0];
662 /* In DEFINE_EXPAND, DEFINE_SPLIT, and DEFINE_PEEPHOLE2, we
663 don't use the MATCH_OPERAND constraint, only the predicate.
664 This is confusing to folks doing new ports, so help them
665 not make the mistake. */
666 if (GET_CODE (insn
) == DEFINE_EXPAND
667 || GET_CODE (insn
) == DEFINE_SPLIT
668 || GET_CODE (insn
) == DEFINE_PEEPHOLE2
)
671 message_with_line (pattern_lineno
,
672 "warning: constraints not supported in %s",
673 rtx_name
[GET_CODE (insn
)]);
676 /* A MATCH_OPERAND that is a SET should have an output reload. */
677 else if (set
&& constraints0
)
681 if (constraints0
== '+')
683 /* If we've only got an output reload for this operand,
684 we'd better have a matching input operand. */
685 else if (constraints0
== '='
686 && find_matching_operand (insn
, XINT (pattern
, 0)))
689 error_with_line (pattern_lineno
,
690 "operand %d missing in-out reload",
693 else if (constraints0
!= '=' && constraints0
!= '+')
694 error_with_line (pattern_lineno
,
695 "operand %d missing output reload",
700 /* Allowing non-lvalues in destinations -- particularly CONST_INT --
701 while not likely to occur at runtime, results in less efficient
702 code from insn-recog.c. */
703 if (set
&& pred
&& pred
->allows_non_lvalue
)
704 message_with_line (pattern_lineno
,
705 "warning: destination operand %d "
709 /* A modeless MATCH_OPERAND can be handy when we can check for
710 multiple modes in the c_test. In most other cases, it is a
711 mistake. Only DEFINE_INSN is eligible, since SPLIT and
712 PEEP2 can FAIL within the output pattern. Exclude special
713 predicates, which check the mode themselves. Also exclude
714 predicates that allow only constants. Exclude the SET_DEST
715 of a call instruction, as that is a common idiom. */
717 if (GET_MODE (pattern
) == VOIDmode
718 && code
== MATCH_OPERAND
719 && GET_CODE (insn
) == DEFINE_INSN
722 && pred
->allows_non_const
723 && strstr (c_test
, "operands") == NULL
725 && GET_CODE (set
) == SET
726 && GET_CODE (SET_SRC (set
)) == CALL
))
727 message_with_line (pattern_lineno
,
728 "warning: operand %d missing mode?",
735 enum machine_mode dmode
, smode
;
738 dest
= SET_DEST (pattern
);
739 src
= SET_SRC (pattern
);
741 /* STRICT_LOW_PART is a wrapper. Its argument is the real
742 destination, and it's mode should match the source. */
743 if (GET_CODE (dest
) == STRICT_LOW_PART
)
744 dest
= XEXP (dest
, 0);
746 /* Find the referent for a DUP. */
748 if (GET_CODE (dest
) == MATCH_DUP
749 || GET_CODE (dest
) == MATCH_OP_DUP
750 || GET_CODE (dest
) == MATCH_PAR_DUP
)
751 dest
= find_operand (insn
, XINT (dest
, 0), NULL
);
753 if (GET_CODE (src
) == MATCH_DUP
754 || GET_CODE (src
) == MATCH_OP_DUP
755 || GET_CODE (src
) == MATCH_PAR_DUP
)
756 src
= find_operand (insn
, XINT (src
, 0), NULL
);
758 dmode
= GET_MODE (dest
);
759 smode
= GET_MODE (src
);
761 /* The mode of an ADDRESS_OPERAND is the mode of the memory
762 reference, not the mode of the address. */
763 if (GET_CODE (src
) == MATCH_OPERAND
764 && ! strcmp (XSTR (src
, 1), "address_operand"))
767 /* The operands of a SET must have the same mode unless one
769 else if (dmode
!= VOIDmode
&& smode
!= VOIDmode
&& dmode
!= smode
)
770 error_with_line (pattern_lineno
,
771 "mode mismatch in set: %smode vs %smode",
772 GET_MODE_NAME (dmode
), GET_MODE_NAME (smode
));
774 /* If only one of the operands is VOIDmode, and PC or CC0 is
775 not involved, it's probably a mistake. */
776 else if (dmode
!= smode
777 && GET_CODE (dest
) != PC
778 && GET_CODE (dest
) != CC0
779 && GET_CODE (src
) != PC
780 && GET_CODE (src
) != CC0
781 && !CONST_INT_P (src
)
782 && GET_CODE (src
) != CALL
)
785 which
= (dmode
== VOIDmode
? "destination" : "source");
786 message_with_line (pattern_lineno
,
787 "warning: %s missing a mode?", which
);
790 if (dest
!= SET_DEST (pattern
))
791 validate_pattern (dest
, insn
, pattern
, '=');
792 validate_pattern (SET_DEST (pattern
), insn
, pattern
, '=');
793 validate_pattern (SET_SRC (pattern
), insn
, NULL_RTX
, 0);
798 validate_pattern (SET_DEST (pattern
), insn
, pattern
, '=');
802 validate_pattern (XEXP (pattern
, 0), insn
, set
, set
? '+' : 0);
803 validate_pattern (XEXP (pattern
, 1), insn
, NULL_RTX
, 0);
804 validate_pattern (XEXP (pattern
, 2), insn
, NULL_RTX
, 0);
807 case STRICT_LOW_PART
:
808 validate_pattern (XEXP (pattern
, 0), insn
, set
, set
? '+' : 0);
812 if (GET_MODE (XEXP (pattern
, 0)) != VOIDmode
)
813 error_with_line (pattern_lineno
,
814 "operand to label_ref %smode not VOIDmode",
815 GET_MODE_NAME (GET_MODE (XEXP (pattern
, 0))));
822 fmt
= GET_RTX_FORMAT (code
);
823 len
= GET_RTX_LENGTH (code
);
824 for (i
= 0; i
< len
; i
++)
829 validate_pattern (XEXP (pattern
, i
), insn
, NULL_RTX
, 0);
833 for (j
= 0; j
< XVECLEN (pattern
, i
); j
++)
834 validate_pattern (XVECEXP (pattern
, i
, j
), insn
, NULL_RTX
, 0);
837 case 'i': case 'w': case '0': case 's':
846 /* Create a chain of nodes to verify that an rtl expression matches
849 LAST is a pointer to the listhead in the previous node in the chain (or
850 in the calling function, for the first node).
852 POSITION is the string representing the current position in the insn.
854 INSN_TYPE is the type of insn for which we are emitting code.
856 A pointer to the final node in the chain is returned. */
858 static struct decision
*
859 add_to_sequence (rtx pattern
, struct decision_head
*last
, const char *position
,
860 enum routine_type insn_type
, int top
)
863 struct decision
*this_decision
, *sub
;
864 struct decision_test
*test
;
865 struct decision_test
**place
;
869 int depth
= strlen (position
);
871 enum machine_mode mode
;
873 if (depth
> max_depth
)
876 subpos
= XNEWVAR (char, depth
+ 2);
877 strcpy (subpos
, position
);
878 subpos
[depth
+ 1] = 0;
880 sub
= this_decision
= new_decision (position
, last
);
881 place
= &this_decision
->tests
;
884 mode
= GET_MODE (pattern
);
885 code
= GET_CODE (pattern
);
890 /* Toplevel peephole pattern. */
891 if (insn_type
== PEEPHOLE2
&& top
)
895 /* Check we have sufficient insns. This avoids complications
896 because we then know peep2_next_insn never fails. */
897 num_insns
= XVECLEN (pattern
, 0);
900 test
= new_decision_test (DT_num_insns
, &place
);
901 test
->u
.num_insns
= num_insns
;
902 last
= &sub
->success
;
906 /* We don't need the node we just created -- unlink it. */
907 last
->first
= last
->last
= NULL
;
910 for (i
= 0; i
< (size_t) XVECLEN (pattern
, 0); i
++)
912 /* Which insn we're looking at is represented by A-Z. We don't
913 ever use 'A', however; it is always implied. */
915 subpos
[depth
] = (i
> 0 ? 'A' + i
: 0);
916 sub
= add_to_sequence (XVECEXP (pattern
, 0, i
),
917 last
, subpos
, insn_type
, 0);
918 last
= &sub
->success
;
923 /* Else nothing special. */
927 /* The explicit patterns within a match_parallel enforce a minimum
928 length on the vector. The match_parallel predicate may allow
929 for more elements. We do need to check for this minimum here
930 or the code generated to match the internals may reference data
931 beyond the end of the vector. */
932 test
= new_decision_test (DT_veclen_ge
, &place
);
933 test
->u
.veclen
= XVECLEN (pattern
, 2);
940 RTX_CODE was_code
= code
;
941 const char *pred_name
;
942 bool allows_const_int
= true;
944 if (code
== MATCH_SCRATCH
)
946 pred_name
= "scratch_operand";
951 pred_name
= XSTR (pattern
, 1);
952 if (code
== MATCH_PARALLEL
)
958 if (pred_name
[0] != 0)
960 const struct pred_data
*pred
;
962 test
= new_decision_test (DT_pred
, &place
);
963 test
->u
.pred
.name
= pred_name
;
964 test
->u
.pred
.mode
= mode
;
966 /* See if we know about this predicate.
967 If we do, remember it for use below.
969 We can optimize the generated code a little if either
970 (a) the predicate only accepts one code, or (b) the
971 predicate does not allow CONST_INT, in which case it
972 can match only if the modes match. */
973 pred
= lookup_predicate (pred_name
);
976 test
->u
.pred
.data
= pred
;
977 allows_const_int
= pred
->codes
[CONST_INT
];
978 if (was_code
== MATCH_PARALLEL
979 && pred
->singleton
!= PARALLEL
)
980 message_with_line (pattern_lineno
,
981 "predicate '%s' used in match_parallel "
982 "does not allow only PARALLEL", pred
->name
);
984 code
= pred
->singleton
;
987 message_with_line (pattern_lineno
,
988 "warning: unknown predicate '%s' in '%s' expression",
989 pred_name
, GET_RTX_NAME (was_code
));
992 /* Can't enforce a mode if we allow const_int. */
993 if (allows_const_int
)
996 /* Accept the operand, i.e. record it in `operands'. */
997 test
= new_decision_test (DT_accept_op
, &place
);
998 test
->u
.opno
= XINT (pattern
, 0);
1000 if (was_code
== MATCH_OPERATOR
|| was_code
== MATCH_PARALLEL
)
1002 char base
= (was_code
== MATCH_OPERATOR
? '0' : 'a');
1003 for (i
= 0; i
< (size_t) XVECLEN (pattern
, 2); i
++)
1005 subpos
[depth
] = i
+ base
;
1006 sub
= add_to_sequence (XVECEXP (pattern
, 2, i
),
1007 &sub
->success
, subpos
, insn_type
, 0);
1016 test
= new_decision_test (DT_dup
, &place
);
1017 test
->u
.dup
= XINT (pattern
, 0);
1019 test
= new_decision_test (DT_accept_op
, &place
);
1020 test
->u
.opno
= XINT (pattern
, 0);
1022 for (i
= 0; i
< (size_t) XVECLEN (pattern
, 1); i
++)
1024 subpos
[depth
] = i
+ '0';
1025 sub
= add_to_sequence (XVECEXP (pattern
, 1, i
),
1026 &sub
->success
, subpos
, insn_type
, 0);
1034 test
= new_decision_test (DT_dup
, &place
);
1035 test
->u
.dup
= XINT (pattern
, 0);
1039 pattern
= XEXP (pattern
, 0);
1046 fmt
= GET_RTX_FORMAT (code
);
1047 len
= GET_RTX_LENGTH (code
);
1049 /* Do tests against the current node first. */
1050 for (i
= 0; i
< (size_t) len
; i
++)
1058 test
= new_decision_test (DT_elt_zero_int
, &place
);
1059 test
->u
.intval
= XINT (pattern
, i
);
1063 test
= new_decision_test (DT_elt_one_int
, &place
);
1064 test
->u
.intval
= XINT (pattern
, i
);
1067 else if (fmt
[i
] == 'w')
1069 /* If this value actually fits in an int, we can use a switch
1070 statement here, so indicate that. */
1071 enum decision_type type
1072 = ((int) XWINT (pattern
, i
) == XWINT (pattern
, i
))
1073 ? DT_elt_zero_wide_safe
: DT_elt_zero_wide
;
1077 test
= new_decision_test (type
, &place
);
1078 test
->u
.intval
= XWINT (pattern
, i
);
1080 else if (fmt
[i
] == 'E')
1084 test
= new_decision_test (DT_veclen
, &place
);
1085 test
->u
.veclen
= XVECLEN (pattern
, i
);
1089 /* Now test our sub-patterns. */
1090 for (i
= 0; i
< (size_t) len
; i
++)
1095 subpos
[depth
] = '0' + i
;
1096 sub
= add_to_sequence (XEXP (pattern
, i
), &sub
->success
,
1097 subpos
, insn_type
, 0);
1103 for (j
= 0; j
< XVECLEN (pattern
, i
); j
++)
1105 subpos
[depth
] = 'a' + j
;
1106 sub
= add_to_sequence (XVECEXP (pattern
, i
, j
),
1107 &sub
->success
, subpos
, insn_type
, 0);
1113 /* Handled above. */
1124 /* Insert nodes testing mode and code, if they're still relevant,
1125 before any of the nodes we may have added above. */
1126 if (code
!= UNKNOWN
)
1128 place
= &this_decision
->tests
;
1129 test
= new_decision_test (DT_code
, &place
);
1130 test
->u
.code
= code
;
1133 if (mode
!= VOIDmode
)
1135 place
= &this_decision
->tests
;
1136 test
= new_decision_test (DT_mode
, &place
);
1137 test
->u
.mode
= mode
;
1140 /* If we didn't insert any tests or accept nodes, hork. */
1141 gcc_assert (this_decision
->tests
);
1148 /* A subroutine of maybe_both_true; examines only one test.
1149 Returns > 0 for "definitely both true" and < 0 for "maybe both true". */
1152 maybe_both_true_2 (struct decision_test
*d1
, struct decision_test
*d2
)
1154 if (d1
->type
== d2
->type
)
1159 if (d1
->u
.num_insns
== d2
->u
.num_insns
)
1165 return d1
->u
.mode
== d2
->u
.mode
;
1168 return d1
->u
.code
== d2
->u
.code
;
1171 return d1
->u
.veclen
== d2
->u
.veclen
;
1173 case DT_elt_zero_int
:
1174 case DT_elt_one_int
:
1175 case DT_elt_zero_wide
:
1176 case DT_elt_zero_wide_safe
:
1177 return d1
->u
.intval
== d2
->u
.intval
;
1184 /* If either has a predicate that we know something about, set
1185 things up so that D1 is the one that always has a known
1186 predicate. Then see if they have any codes in common. */
1188 if (d1
->type
== DT_pred
|| d2
->type
== DT_pred
)
1190 if (d2
->type
== DT_pred
)
1192 struct decision_test
*tmp
;
1193 tmp
= d1
, d1
= d2
, d2
= tmp
;
1196 /* If D2 tests a mode, see if it matches D1. */
1197 if (d1
->u
.pred
.mode
!= VOIDmode
)
1199 if (d2
->type
== DT_mode
)
1201 if (d1
->u
.pred
.mode
!= d2
->u
.mode
1202 /* The mode of an address_operand predicate is the
1203 mode of the memory, not the operand. It can only
1204 be used for testing the predicate, so we must
1206 && strcmp (d1
->u
.pred
.name
, "address_operand") != 0)
1209 /* Don't check two predicate modes here, because if both predicates
1210 accept CONST_INT, then both can still be true even if the modes
1211 are different. If they don't accept CONST_INT, there will be a
1212 separate DT_mode that will make maybe_both_true_1 return 0. */
1215 if (d1
->u
.pred
.data
)
1217 /* If D2 tests a code, see if it is in the list of valid
1218 codes for D1's predicate. */
1219 if (d2
->type
== DT_code
)
1221 if (!d1
->u
.pred
.data
->codes
[d2
->u
.code
])
1225 /* Otherwise see if the predicates have any codes in common. */
1226 else if (d2
->type
== DT_pred
&& d2
->u
.pred
.data
)
1228 bool common
= false;
1231 for (c
= 0; c
< NUM_RTX_CODE
; c
++)
1232 if (d1
->u
.pred
.data
->codes
[c
] && d2
->u
.pred
.data
->codes
[c
])
1244 /* Tests vs veclen may be known when strict equality is involved. */
1245 if (d1
->type
== DT_veclen
&& d2
->type
== DT_veclen_ge
)
1246 return d1
->u
.veclen
>= d2
->u
.veclen
;
1247 if (d1
->type
== DT_veclen_ge
&& d2
->type
== DT_veclen
)
1248 return d2
->u
.veclen
>= d1
->u
.veclen
;
1253 /* A subroutine of maybe_both_true; examines all the tests for a given node.
1254 Returns > 0 for "definitely both true" and < 0 for "maybe both true". */
1257 maybe_both_true_1 (struct decision_test
*d1
, struct decision_test
*d2
)
1259 struct decision_test
*t1
, *t2
;
1261 /* A match_operand with no predicate can match anything. Recognize
1262 this by the existence of a lone DT_accept_op test. */
1263 if (d1
->type
== DT_accept_op
|| d2
->type
== DT_accept_op
)
1266 /* Eliminate pairs of tests while they can exactly match. */
1267 while (d1
&& d2
&& d1
->type
== d2
->type
)
1269 if (maybe_both_true_2 (d1
, d2
) == 0)
1271 d1
= d1
->next
, d2
= d2
->next
;
1274 /* After that, consider all pairs. */
1275 for (t1
= d1
; t1
; t1
= t1
->next
)
1276 for (t2
= d2
; t2
; t2
= t2
->next
)
1277 if (maybe_both_true_2 (t1
, t2
) == 0)
1283 /* Return 0 if we can prove that there is no RTL that can match both
1284 D1 and D2. Otherwise, return 1 (it may be that there is an RTL that
1285 can match both or just that we couldn't prove there wasn't such an RTL).
1287 TOPLEVEL is nonzero if we are to only look at the top level and not
1288 recursively descend. */
1291 maybe_both_true (struct decision
*d1
, struct decision
*d2
,
1294 struct decision
*p1
, *p2
;
1297 /* Don't compare strings on the different positions in insn. Doing so
1298 is incorrect and results in false matches from constructs like
1300 [(set (subreg:HI (match_operand:SI "register_operand" "r") 0)
1301 (subreg:HI (match_operand:SI "register_operand" "r") 0))]
1303 [(set (match_operand:HI "register_operand" "r")
1304 (match_operand:HI "register_operand" "r"))]
1306 If we are presented with such, we are recursing through the remainder
1307 of a node's success nodes (from the loop at the end of this function).
1308 Skip forward until we come to a position that matches.
1310 Due to the way position strings are constructed, we know that iterating
1311 forward from the lexically lower position (e.g. "00") will run into
1312 the lexically higher position (e.g. "1") and not the other way around.
1313 This saves a bit of effort. */
1315 cmp
= strcmp (d1
->position
, d2
->position
);
1318 gcc_assert (!toplevel
);
1320 /* If the d2->position was lexically lower, swap. */
1322 p1
= d1
, d1
= d2
, d2
= p1
;
1324 if (d1
->success
.first
== 0)
1326 for (p1
= d1
->success
.first
; p1
; p1
= p1
->next
)
1327 if (maybe_both_true (p1
, d2
, 0))
1333 /* Test the current level. */
1334 cmp
= maybe_both_true_1 (d1
->tests
, d2
->tests
);
1338 /* We can't prove that D1 and D2 cannot both be true. If we are only
1339 to check the top level, return 1. Otherwise, see if we can prove
1340 that all choices in both successors are mutually exclusive. If
1341 either does not have any successors, we can't prove they can't both
1344 if (toplevel
|| d1
->success
.first
== 0 || d2
->success
.first
== 0)
1347 for (p1
= d1
->success
.first
; p1
; p1
= p1
->next
)
1348 for (p2
= d2
->success
.first
; p2
; p2
= p2
->next
)
1349 if (maybe_both_true (p1
, p2
, 0))
1355 /* A subroutine of nodes_identical. Examine two tests for equivalence. */
1358 nodes_identical_1 (struct decision_test
*d1
, struct decision_test
*d2
)
1363 return d1
->u
.num_insns
== d2
->u
.num_insns
;
1366 return d1
->u
.mode
== d2
->u
.mode
;
1369 return d1
->u
.code
== d2
->u
.code
;
1372 return (d1
->u
.pred
.mode
== d2
->u
.pred
.mode
1373 && strcmp (d1
->u
.pred
.name
, d2
->u
.pred
.name
) == 0);
1376 return strcmp (d1
->u
.c_test
, d2
->u
.c_test
) == 0;
1380 return d1
->u
.veclen
== d2
->u
.veclen
;
1383 return d1
->u
.dup
== d2
->u
.dup
;
1385 case DT_elt_zero_int
:
1386 case DT_elt_one_int
:
1387 case DT_elt_zero_wide
:
1388 case DT_elt_zero_wide_safe
:
1389 return d1
->u
.intval
== d2
->u
.intval
;
1392 return d1
->u
.opno
== d2
->u
.opno
;
1394 case DT_accept_insn
:
1395 /* Differences will be handled in merge_accept_insn. */
1403 /* True iff the two nodes are identical (on one level only). Due
1404 to the way these lists are constructed, we shouldn't have to
1405 consider different orderings on the tests. */
1408 nodes_identical (struct decision
*d1
, struct decision
*d2
)
1410 struct decision_test
*t1
, *t2
;
1412 for (t1
= d1
->tests
, t2
= d2
->tests
; t1
&& t2
; t1
= t1
->next
, t2
= t2
->next
)
1414 if (t1
->type
!= t2
->type
)
1416 if (! nodes_identical_1 (t1
, t2
))
1420 /* For success, they should now both be null. */
1424 /* Check that their subnodes are at the same position, as any one set
1425 of sibling decisions must be at the same position. Allowing this
1426 requires complications to find_afterward and when change_state is
1428 if (d1
->success
.first
1429 && d2
->success
.first
1430 && strcmp (d1
->success
.first
->position
, d2
->success
.first
->position
))
1436 /* A subroutine of merge_trees; given two nodes that have been declared
1437 identical, cope with two insn accept states. If they differ in the
1438 number of clobbers, then the conflict was created by make_insn_sequence
1439 and we can drop the with-clobbers version on the floor. If both
1440 nodes have no additional clobbers, we have found an ambiguity in the
1441 source machine description. */
1444 merge_accept_insn (struct decision
*oldd
, struct decision
*addd
)
1446 struct decision_test
*old
, *add
;
1448 for (old
= oldd
->tests
; old
; old
= old
->next
)
1449 if (old
->type
== DT_accept_insn
)
1454 for (add
= addd
->tests
; add
; add
= add
->next
)
1455 if (add
->type
== DT_accept_insn
)
1460 /* If one node is for a normal insn and the second is for the base
1461 insn with clobbers stripped off, the second node should be ignored. */
1463 if (old
->u
.insn
.num_clobbers_to_add
== 0
1464 && add
->u
.insn
.num_clobbers_to_add
> 0)
1466 /* Nothing to do here. */
1468 else if (old
->u
.insn
.num_clobbers_to_add
> 0
1469 && add
->u
.insn
.num_clobbers_to_add
== 0)
1471 /* In this case, replace OLD with ADD. */
1472 old
->u
.insn
= add
->u
.insn
;
1476 error_with_line (add
->u
.insn
.lineno
, "`%s' matches `%s'",
1477 get_insn_name (add
->u
.insn
.code_number
),
1478 get_insn_name (old
->u
.insn
.code_number
));
1479 message_with_line (old
->u
.insn
.lineno
, "previous definition of `%s'",
1480 get_insn_name (old
->u
.insn
.code_number
));
1484 /* Merge two decision trees OLDH and ADDH, modifying OLDH destructively. */
1487 merge_trees (struct decision_head
*oldh
, struct decision_head
*addh
)
1489 struct decision
*next
, *add
;
1491 if (addh
->first
== 0)
1493 if (oldh
->first
== 0)
1499 /* Trying to merge bits at different positions isn't possible. */
1500 gcc_assert (!strcmp (oldh
->first
->position
, addh
->first
->position
));
1502 for (add
= addh
->first
; add
; add
= next
)
1504 struct decision
*old
, *insert_before
= NULL
;
1508 /* The semantics of pattern matching state that the tests are
1509 done in the order given in the MD file so that if an insn
1510 matches two patterns, the first one will be used. However,
1511 in practice, most, if not all, patterns are unambiguous so
1512 that their order is independent. In that case, we can merge
1513 identical tests and group all similar modes and codes together.
1515 Scan starting from the end of OLDH until we reach a point
1516 where we reach the head of the list or where we pass a
1517 pattern that could also be true if NEW is true. If we find
1518 an identical pattern, we can merge them. Also, record the
1519 last node that tests the same code and mode and the last one
1520 that tests just the same mode.
1522 If we have no match, place NEW after the closest match we found. */
1524 for (old
= oldh
->last
; old
; old
= old
->prev
)
1526 if (nodes_identical (old
, add
))
1528 merge_accept_insn (old
, add
);
1529 merge_trees (&old
->success
, &add
->success
);
1533 if (maybe_both_true (old
, add
, 0))
1536 /* Insert the nodes in DT test type order, which is roughly
1537 how expensive/important the test is. Given that the tests
1538 are also ordered within the list, examining the first is
1540 if ((int) add
->tests
->type
< (int) old
->tests
->type
)
1541 insert_before
= old
;
1544 if (insert_before
== NULL
)
1547 add
->prev
= oldh
->last
;
1548 oldh
->last
->next
= add
;
1553 if ((add
->prev
= insert_before
->prev
) != NULL
)
1554 add
->prev
->next
= add
;
1557 add
->next
= insert_before
;
1558 insert_before
->prev
= add
;
1565 /* Walk the tree looking for sub-nodes that perform common tests.
1566 Factor out the common test into a new node. This enables us
1567 (depending on the test type) to emit switch statements later. */
1570 factor_tests (struct decision_head
*head
)
1572 struct decision
*first
, *next
;
1574 for (first
= head
->first
; first
&& first
->next
; first
= next
)
1576 enum decision_type type
;
1577 struct decision
*new_dec
, *old_last
;
1579 type
= first
->tests
->type
;
1582 /* Want at least two compatible sequential nodes. */
1583 if (next
->tests
->type
!= type
)
1586 /* Don't want all node types, just those we can turn into
1587 switch statements. */
1590 && type
!= DT_veclen
1591 && type
!= DT_elt_zero_int
1592 && type
!= DT_elt_one_int
1593 && type
!= DT_elt_zero_wide_safe
)
1596 /* If we'd been performing more than one test, create a new node
1597 below our first test. */
1598 if (first
->tests
->next
!= NULL
)
1600 new_dec
= new_decision (first
->position
, &first
->success
);
1601 new_dec
->tests
= first
->tests
->next
;
1602 first
->tests
->next
= NULL
;
1605 /* Crop the node tree off after our first test. */
1607 old_last
= head
->last
;
1610 /* For each compatible test, adjust to perform only one test in
1611 the top level node, then merge the node back into the tree. */
1614 struct decision_head h
;
1616 if (next
->tests
->next
!= NULL
)
1618 new_dec
= new_decision (next
->position
, &next
->success
);
1619 new_dec
->tests
= next
->tests
->next
;
1620 next
->tests
->next
= NULL
;
1624 new_dec
->next
= NULL
;
1625 h
.first
= h
.last
= new_dec
;
1627 merge_trees (head
, &h
);
1629 while (next
&& next
->tests
->type
== type
);
1631 /* After we run out of compatible tests, graft the remaining nodes
1632 back onto the tree. */
1635 next
->prev
= head
->last
;
1636 head
->last
->next
= next
;
1637 head
->last
= old_last
;
1642 for (first
= head
->first
; first
; first
= first
->next
)
1643 factor_tests (&first
->success
);
1646 /* After factoring, try to simplify the tests on any one node.
1647 Tests that are useful for switch statements are recognizable
1648 by having only a single test on a node -- we'll be manipulating
1649 nodes with multiple tests:
1651 If we have mode tests or code tests that are redundant with
1652 predicates, remove them. */
1655 simplify_tests (struct decision_head
*head
)
1657 struct decision
*tree
;
1659 for (tree
= head
->first
; tree
; tree
= tree
->next
)
1661 struct decision_test
*a
, *b
;
1668 /* Find a predicate node. */
1669 while (b
&& b
->type
!= DT_pred
)
1673 /* Due to how these tests are constructed, we don't even need
1674 to check that the mode and code are compatible -- they were
1675 generated from the predicate in the first place. */
1676 while (a
->type
== DT_mode
|| a
->type
== DT_code
)
1683 for (tree
= head
->first
; tree
; tree
= tree
->next
)
1684 simplify_tests (&tree
->success
);
1687 /* Count the number of subnodes of HEAD. If the number is high enough,
1688 make the first node in HEAD start a separate subroutine in the C code
1689 that is generated. */
1692 break_out_subroutines (struct decision_head
*head
, int initial
)
1695 struct decision
*sub
;
1697 for (sub
= head
->first
; sub
; sub
= sub
->next
)
1698 size
+= 1 + break_out_subroutines (&sub
->success
, 0);
1700 if (size
> SUBROUTINE_THRESHOLD
&& ! initial
)
1702 head
->first
->subroutine_number
= ++next_subroutine_number
;
1708 /* For each node p, find the next alternative that might be true
1712 find_afterward (struct decision_head
*head
, struct decision
*real_afterward
)
1714 struct decision
*p
, *q
, *afterward
;
1716 /* We can't propagate alternatives across subroutine boundaries.
1717 This is not incorrect, merely a minor optimization loss. */
1720 afterward
= (p
->subroutine_number
> 0 ? NULL
: real_afterward
);
1722 for ( ; p
; p
= p
->next
)
1724 /* Find the next node that might be true if this one fails. */
1725 for (q
= p
->next
; q
; q
= q
->next
)
1726 if (maybe_both_true (p
, q
, 1))
1729 /* If we reached the end of the list without finding one,
1730 use the incoming afterward position. */
1739 for (p
= head
->first
; p
; p
= p
->next
)
1740 if (p
->success
.first
)
1741 find_afterward (&p
->success
, p
->afterward
);
1743 /* When we are generating a subroutine, record the real afterward
1744 position in the first node where write_tree can find it, and we
1745 can do the right thing at the subroutine call site. */
1747 if (p
->subroutine_number
> 0)
1748 p
->afterward
= real_afterward
;
1751 /* Assuming that the state of argument is denoted by OLDPOS, take whatever
1752 actions are necessary to move to NEWPOS. If we fail to move to the
1753 new state, branch to node AFTERWARD if nonzero, otherwise return.
1755 Failure to move to the new state can only occur if we are trying to
1756 match multiple insns and we try to step past the end of the stream. */
1759 change_state (const char *oldpos
, const char *newpos
, const char *indent
)
1761 int odepth
= strlen (oldpos
);
1762 int ndepth
= strlen (newpos
);
1765 /* Pop up as many levels as necessary. */
1766 for (depth
= odepth
; strncmp (oldpos
, newpos
, depth
) != 0; --depth
)
1769 /* Go down to desired level. */
1770 while (depth
< ndepth
)
1772 /* It's a different insn from the first one. */
1773 if (ISUPPER (newpos
[depth
]))
1775 printf ("%stem = peep2_next_insn (%d);\n",
1776 indent
, newpos
[depth
] - 'A');
1777 printf ("%sx%d = PATTERN (tem);\n", indent
, depth
+ 1);
1779 else if (ISLOWER (newpos
[depth
]))
1780 printf ("%sx%d = XVECEXP (x%d, 0, %d);\n",
1781 indent
, depth
+ 1, depth
, newpos
[depth
] - 'a');
1783 printf ("%sx%d = XEXP (x%d, %c);\n",
1784 indent
, depth
+ 1, depth
, newpos
[depth
]);
1789 /* Print the enumerator constant for CODE -- the upcase version of
1793 print_code (enum rtx_code code
)
1796 for (p
= GET_RTX_NAME (code
); *p
; p
++)
1797 putchar (TOUPPER (*p
));
1800 /* Emit code to cross an afterward link -- change state and branch. */
1803 write_afterward (struct decision
*start
, struct decision
*afterward
,
1806 if (!afterward
|| start
->subroutine_number
> 0)
1807 printf("%sgoto ret0;\n", indent
);
1810 change_state (start
->position
, afterward
->position
, indent
);
1811 printf ("%sgoto L%d;\n", indent
, afterward
->number
);
1815 /* Emit a HOST_WIDE_INT as an integer constant expression. We need to take
1816 special care to avoid "decimal constant is so large that it is unsigned"
1817 warnings in the resulting code. */
1820 print_host_wide_int (HOST_WIDE_INT val
)
1822 HOST_WIDE_INT min
= (unsigned HOST_WIDE_INT
)1 << (HOST_BITS_PER_WIDE_INT
-1);
1824 printf ("(" HOST_WIDE_INT_PRINT_DEC_C
"-1)", val
+ 1);
1826 printf (HOST_WIDE_INT_PRINT_DEC_C
, val
);
1829 /* Emit a switch statement, if possible, for an initial sequence of
1830 nodes at START. Return the first node yet untested. */
1832 static struct decision
*
1833 write_switch (struct decision
*start
, int depth
)
1835 struct decision
*p
= start
;
1836 enum decision_type type
= p
->tests
->type
;
1837 struct decision
*needs_label
= NULL
;
1839 /* If we have two or more nodes in sequence that test the same one
1840 thing, we may be able to use a switch statement. */
1844 || p
->next
->tests
->type
!= type
1845 || p
->next
->tests
->next
1846 || nodes_identical_1 (p
->tests
, p
->next
->tests
))
1849 /* DT_code is special in that we can do interesting things with
1850 known predicates at the same time. */
1851 if (type
== DT_code
)
1853 char codemap
[NUM_RTX_CODE
];
1854 struct decision
*ret
;
1857 memset (codemap
, 0, sizeof(codemap
));
1859 printf (" switch (GET_CODE (x%d))\n {\n", depth
);
1860 code
= p
->tests
->u
.code
;
1863 if (p
!= start
&& p
->need_label
&& needs_label
== NULL
)
1868 printf (":\n goto L%d;\n", p
->success
.first
->number
);
1869 p
->success
.first
->need_label
= 1;
1876 && p
->tests
->type
== DT_code
1877 && ! codemap
[code
= p
->tests
->u
.code
]);
1879 /* If P is testing a predicate that we know about and we haven't
1880 seen any of the codes that are valid for the predicate, we can
1881 write a series of "case" statement, one for each possible code.
1882 Since we are already in a switch, these redundant tests are very
1883 cheap and will reduce the number of predicates called. */
1885 /* Note that while we write out cases for these predicates here,
1886 we don't actually write the test here, as it gets kinda messy.
1887 It is trivial to leave this to later by telling our caller that
1888 we only processed the CODE tests. */
1889 if (needs_label
!= NULL
)
1894 while (p
&& p
->tests
->type
== DT_pred
&& p
->tests
->u
.pred
.data
)
1896 const struct pred_data
*data
= p
->tests
->u
.pred
.data
;
1899 for (c
= 0; c
< NUM_RTX_CODE
; c
++)
1900 if (codemap
[c
] && data
->codes
[c
])
1903 for (c
= 0; c
< NUM_RTX_CODE
; c
++)
1906 fputs (" case ", stdout
);
1907 print_code ((enum rtx_code
) c
);
1908 fputs (":\n", stdout
);
1912 printf (" goto L%d;\n", p
->number
);
1918 /* Make the default case skip the predicates we managed to match. */
1920 printf (" default:\n");
1925 printf (" goto L%d;\n", p
->number
);
1929 write_afterward (start
, start
->afterward
, " ");
1932 printf (" break;\n");
1937 else if (type
== DT_mode
1938 || type
== DT_veclen
1939 || type
== DT_elt_zero_int
1940 || type
== DT_elt_one_int
1941 || type
== DT_elt_zero_wide_safe
)
1943 const char *indent
= "";
1945 /* We cast switch parameter to integer, so we must ensure that the value
1947 if (type
== DT_elt_zero_wide_safe
)
1950 printf(" if ((int) XWINT (x%d, 0) == XWINT (x%d, 0))\n", depth
, depth
);
1952 printf ("%s switch (", indent
);
1956 printf ("GET_MODE (x%d)", depth
);
1959 printf ("XVECLEN (x%d, 0)", depth
);
1961 case DT_elt_zero_int
:
1962 printf ("XINT (x%d, 0)", depth
);
1964 case DT_elt_one_int
:
1965 printf ("XINT (x%d, 1)", depth
);
1967 case DT_elt_zero_wide_safe
:
1968 /* Convert result of XWINT to int for portability since some C
1969 compilers won't do it and some will. */
1970 printf ("(int) XWINT (x%d, 0)", depth
);
1975 printf (")\n%s {\n", indent
);
1979 /* Merge trees will not unify identical nodes if their
1980 sub-nodes are at different levels. Thus we must check
1981 for duplicate cases. */
1983 for (q
= start
; q
!= p
; q
= q
->next
)
1984 if (nodes_identical_1 (p
->tests
, q
->tests
))
1987 if (p
!= start
&& p
->need_label
&& needs_label
== NULL
)
1990 printf ("%s case ", indent
);
1994 printf ("%smode", GET_MODE_NAME (p
->tests
->u
.mode
));
1997 printf ("%d", p
->tests
->u
.veclen
);
1999 case DT_elt_zero_int
:
2000 case DT_elt_one_int
:
2001 case DT_elt_zero_wide
:
2002 case DT_elt_zero_wide_safe
:
2003 print_host_wide_int (p
->tests
->u
.intval
);
2008 printf (":\n%s goto L%d;\n", indent
, p
->success
.first
->number
);
2009 p
->success
.first
->need_label
= 1;
2013 while (p
&& p
->tests
->type
== type
&& !p
->tests
->next
);
2016 printf ("%s default:\n%s break;\n%s }\n",
2017 indent
, indent
, indent
);
2019 return needs_label
!= NULL
? needs_label
: p
;
2023 /* None of the other tests are amenable. */
2028 /* Emit code for one test. */
2031 write_cond (struct decision_test
*p
, int depth
,
2032 enum routine_type subroutine_type
)
2037 printf ("peep2_current_count >= %d", p
->u
.num_insns
);
2041 printf ("GET_MODE (x%d) == %smode", depth
, GET_MODE_NAME (p
->u
.mode
));
2045 printf ("GET_CODE (x%d) == ", depth
);
2046 print_code (p
->u
.code
);
2050 printf ("XVECLEN (x%d, 0) == %d", depth
, p
->u
.veclen
);
2053 case DT_elt_zero_int
:
2054 printf ("XINT (x%d, 0) == %d", depth
, (int) p
->u
.intval
);
2057 case DT_elt_one_int
:
2058 printf ("XINT (x%d, 1) == %d", depth
, (int) p
->u
.intval
);
2061 case DT_elt_zero_wide
:
2062 case DT_elt_zero_wide_safe
:
2063 printf ("XWINT (x%d, 0) == ", depth
);
2064 print_host_wide_int (p
->u
.intval
);
2068 printf ("x%d == const_int_rtx[MAX_SAVED_CONST_INT + (%d)]",
2069 depth
, (int) p
->u
.intval
);
2073 printf ("XVECLEN (x%d, 0) >= %d", depth
, p
->u
.veclen
);
2077 printf ("rtx_equal_p (x%d, operands[%d])", depth
, p
->u
.dup
);
2081 printf ("%s (x%d, %smode)", p
->u
.pred
.name
, depth
,
2082 GET_MODE_NAME (p
->u
.pred
.mode
));
2086 print_c_condition (p
->u
.c_test
);
2089 case DT_accept_insn
:
2090 gcc_assert (subroutine_type
== RECOG
);
2091 gcc_assert (p
->u
.insn
.num_clobbers_to_add
);
2092 printf ("pnum_clobbers != NULL");
2100 /* Emit code for one action. The previous tests have succeeded;
2101 TEST is the last of the chain. In the normal case we simply
2102 perform a state change. For the `accept' tests we must do more work. */
2105 write_action (struct decision
*p
, struct decision_test
*test
,
2106 int depth
, int uncond
, struct decision
*success
,
2107 enum routine_type subroutine_type
)
2114 else if (test
->type
== DT_accept_op
|| test
->type
== DT_accept_insn
)
2116 fputs (" {\n", stdout
);
2123 if (test
->type
== DT_accept_op
)
2125 printf("%soperands[%d] = x%d;\n", indent
, test
->u
.opno
, depth
);
2127 /* Only allow DT_accept_insn to follow. */
2131 gcc_assert (test
->type
== DT_accept_insn
);
2135 /* Sanity check that we're now at the end of the list of tests. */
2136 gcc_assert (!test
->next
);
2138 if (test
->type
== DT_accept_insn
)
2140 switch (subroutine_type
)
2143 if (test
->u
.insn
.num_clobbers_to_add
!= 0)
2144 printf ("%s*pnum_clobbers = %d;\n",
2145 indent
, test
->u
.insn
.num_clobbers_to_add
);
2146 printf ("%sreturn %d; /* %s */\n", indent
,
2147 test
->u
.insn
.code_number
,
2148 get_insn_name (test
->u
.insn
.code_number
));
2152 printf ("%sreturn gen_split_%d (insn, operands);\n",
2153 indent
, test
->u
.insn
.code_number
);
2158 int match_len
= 0, i
;
2160 for (i
= strlen (p
->position
) - 1; i
>= 0; --i
)
2161 if (ISUPPER (p
->position
[i
]))
2163 match_len
= p
->position
[i
] - 'A';
2166 printf ("%s*_pmatch_len = %d;\n", indent
, match_len
);
2167 printf ("%stem = gen_peephole2_%d (insn, operands);\n",
2168 indent
, test
->u
.insn
.code_number
);
2169 printf ("%sif (tem != 0)\n%s return tem;\n", indent
, indent
);
2179 printf("%sgoto L%d;\n", indent
, success
->number
);
2180 success
->need_label
= 1;
2184 fputs (" }\n", stdout
);
2187 /* Return 1 if the test is always true and has no fallthru path. Return -1
2188 if the test does have a fallthru path, but requires that the condition be
2189 terminated. Otherwise return 0 for a normal test. */
2190 /* ??? is_unconditional is a stupid name for a tri-state function. */
2193 is_unconditional (struct decision_test
*t
, enum routine_type subroutine_type
)
2195 if (t
->type
== DT_accept_op
)
2198 if (t
->type
== DT_accept_insn
)
2200 switch (subroutine_type
)
2203 return (t
->u
.insn
.num_clobbers_to_add
== 0);
2216 /* Emit code for one node -- the conditional and the accompanying action.
2217 Return true if there is no fallthru path. */
2220 write_node (struct decision
*p
, int depth
,
2221 enum routine_type subroutine_type
)
2223 struct decision_test
*test
, *last_test
;
2226 /* Scan the tests and simplify comparisons against small
2228 for (test
= p
->tests
; test
; test
= test
->next
)
2230 if (test
->type
== DT_code
2231 && test
->u
.code
== CONST_INT
2233 && test
->next
->type
== DT_elt_zero_wide_safe
2234 && -MAX_SAVED_CONST_INT
<= test
->next
->u
.intval
2235 && test
->next
->u
.intval
<= MAX_SAVED_CONST_INT
)
2237 test
->type
= DT_const_int
;
2238 test
->u
.intval
= test
->next
->u
.intval
;
2239 test
->next
= test
->next
->next
;
2243 last_test
= test
= p
->tests
;
2244 uncond
= is_unconditional (test
, subroutine_type
);
2248 write_cond (test
, depth
, subroutine_type
);
2250 while ((test
= test
->next
) != NULL
)
2253 if (is_unconditional (test
, subroutine_type
))
2257 write_cond (test
, depth
, subroutine_type
);
2263 write_action (p
, last_test
, depth
, uncond
, p
->success
.first
, subroutine_type
);
2268 /* Emit code for all of the sibling nodes of HEAD. */
2271 write_tree_1 (struct decision_head
*head
, int depth
,
2272 enum routine_type subroutine_type
)
2274 struct decision
*p
, *next
;
2277 for (p
= head
->first
; p
; p
= next
)
2279 /* The label for the first element was printed in write_tree. */
2280 if (p
!= head
->first
&& p
->need_label
)
2281 OUTPUT_LABEL (" ", p
->number
);
2283 /* Attempt to write a switch statement for a whole sequence. */
2284 next
= write_switch (p
, depth
);
2289 /* Failed -- fall back and write one node. */
2290 uncond
= write_node (p
, depth
, subroutine_type
);
2295 /* Finished with this chain. Close a fallthru path by branching
2296 to the afterward node. */
2298 write_afterward (head
->last
, head
->last
->afterward
, " ");
2301 /* Write out the decision tree starting at HEAD. PREVPOS is the
2302 position at the node that branched to this node. */
2305 write_tree (struct decision_head
*head
, const char *prevpos
,
2306 enum routine_type type
, int initial
)
2308 struct decision
*p
= head
->first
;
2312 OUTPUT_LABEL (" ", p
->number
);
2314 if (! initial
&& p
->subroutine_number
> 0)
2316 static const char * const name_prefix
[] = {
2317 "recog", "split", "peephole2"
2320 static const char * const call_suffix
[] = {
2321 ", pnum_clobbers", "", ", _pmatch_len"
2324 /* This node has been broken out into a separate subroutine.
2325 Call it, test the result, and branch accordingly. */
2329 printf (" tem = %s_%d (x0, insn%s);\n",
2330 name_prefix
[type
], p
->subroutine_number
, call_suffix
[type
]);
2331 if (IS_SPLIT (type
))
2332 printf (" if (tem != 0)\n return tem;\n");
2334 printf (" if (tem >= 0)\n return tem;\n");
2336 change_state (p
->position
, p
->afterward
->position
, " ");
2337 printf (" goto L%d;\n", p
->afterward
->number
);
2341 printf (" return %s_%d (x0, insn%s);\n",
2342 name_prefix
[type
], p
->subroutine_number
, call_suffix
[type
]);
2347 int depth
= strlen (p
->position
);
2349 change_state (prevpos
, p
->position
, " ");
2350 write_tree_1 (head
, depth
, type
);
2352 for (p
= head
->first
; p
; p
= p
->next
)
2353 if (p
->success
.first
)
2354 write_tree (&p
->success
, p
->position
, type
, 0);
2358 /* Write out a subroutine of type TYPE to do comparisons starting at
2362 write_subroutine (struct decision_head
*head
, enum routine_type type
)
2364 int subfunction
= head
->first
? head
->first
->subroutine_number
: 0;
2369 s_or_e
= subfunction
? "static " : "";
2372 sprintf (extension
, "_%d", subfunction
);
2373 else if (type
== RECOG
)
2374 extension
[0] = '\0';
2376 strcpy (extension
, "_insns");
2382 recog%s (rtx x0 ATTRIBUTE_UNUSED,\n\trtx insn ATTRIBUTE_UNUSED,\n\tint *pnum_clobbers ATTRIBUTE_UNUSED)\n", s_or_e
, extension
);
2386 split%s (rtx x0 ATTRIBUTE_UNUSED, rtx insn ATTRIBUTE_UNUSED)\n",
2391 peephole2%s (rtx x0 ATTRIBUTE_UNUSED,\n\trtx insn ATTRIBUTE_UNUSED,\n\tint *_pmatch_len ATTRIBUTE_UNUSED)\n",
2396 printf ("{\n rtx * const operands ATTRIBUTE_UNUSED = &recog_data.operand[0];\n");
2397 for (i
= 1; i
<= max_depth
; i
++)
2398 printf (" rtx x%d ATTRIBUTE_UNUSED;\n", i
);
2400 printf (" %s tem ATTRIBUTE_UNUSED;\n", IS_SPLIT (type
) ? "rtx" : "int");
2403 printf (" recog_data.insn = NULL_RTX;\n");
2406 write_tree (head
, "", type
, 1);
2408 printf (" goto ret0;\n");
2410 printf (" ret0:\n return %d;\n}\n\n", IS_SPLIT (type
) ? 0 : -1);
2413 /* In break_out_subroutines, we discovered the boundaries for the
2414 subroutines, but did not write them out. Do so now. */
2417 write_subroutines (struct decision_head
*head
, enum routine_type type
)
2421 for (p
= head
->first
; p
; p
= p
->next
)
2422 if (p
->success
.first
)
2423 write_subroutines (&p
->success
, type
);
2425 if (head
->first
->subroutine_number
> 0)
2426 write_subroutine (head
, type
);
2429 /* Begin the output file. */
2435 /* Generated automatically by the program `genrecog' from the target\n\
2436 machine description file. */\n\
2438 #include \"config.h\"\n\
2439 #include \"system.h\"\n\
2440 #include \"coretypes.h\"\n\
2441 #include \"tm.h\"\n\
2442 #include \"rtl.h\"\n\
2443 #include \"tm_p.h\"\n\
2444 #include \"function.h\"\n\
2445 #include \"insn-config.h\"\n\
2446 #include \"recog.h\"\n\
2447 #include \"output.h\"\n\
2448 #include \"flags.h\"\n\
2449 #include \"hard-reg-set.h\"\n\
2450 #include \"resource.h\"\n\
2451 #include \"diagnostic-core.h\"\n\
2452 #include \"reload.h\"\n\
2453 #include \"regs.h\"\n\
2454 #include \"tm-constrs.h\"\n\
2458 /* `recog' contains a decision tree that recognizes whether the rtx\n\
2459 X0 is a valid instruction.\n\
2461 recog returns -1 if the rtx is not valid. If the rtx is valid, recog\n\
2462 returns a nonnegative number which is the insn code number for the\n\
2463 pattern that matched. This is the same as the order in the machine\n\
2464 description of the entry that matched. This number can be used as an\n\
2465 index into `insn_data' and other tables.\n");
2467 The third argument to recog is an optional pointer to an int. If\n\
2468 present, recog will accept a pattern if it matches except for missing\n\
2469 CLOBBER expressions at the end. In that case, the value pointed to by\n\
2470 the optional pointer will be set to the number of CLOBBERs that need\n\
2471 to be added (it should be initialized to zero by the caller). If it");
2473 is set nonzero, the caller should allocate a PARALLEL of the\n\
2474 appropriate size, copy the initial entries, and call add_clobbers\n\
2475 (found in insn-emit.c) to fill in the CLOBBERs.\n\
2479 The function split_insns returns 0 if the rtl could not\n\
2480 be split or the split rtl as an INSN list if it can be.\n\
2482 The function peephole2_insns returns 0 if the rtl could not\n\
2483 be matched. If there was a match, the new rtl is returned in an INSN list,\n\
2484 and LAST_INSN will point to the last recognized insn in the old sequence.\n\
2489 /* Construct and return a sequence of decisions
2490 that will recognize INSN.
2492 TYPE says what type of routine we are recognizing (RECOG or SPLIT). */
2494 static struct decision_head
2495 make_insn_sequence (rtx insn
, enum routine_type type
)
2498 const char *c_test
= XSTR (insn
, type
== RECOG
? 2 : 1);
2499 int truth
= maybe_eval_c_test (c_test
);
2500 struct decision
*last
;
2501 struct decision_test
*test
, **place
;
2502 struct decision_head head
;
2505 /* We should never see an insn whose C test is false at compile time. */
2508 c_test_pos
[0] = '\0';
2509 if (type
== PEEPHOLE2
)
2513 /* peephole2 gets special treatment:
2514 - X always gets an outer parallel even if it's only one entry
2515 - we remove all traces of outer-level match_scratch and match_dup
2516 expressions here. */
2517 x
= rtx_alloc (PARALLEL
);
2518 PUT_MODE (x
, VOIDmode
);
2519 XVEC (x
, 0) = rtvec_alloc (XVECLEN (insn
, 0));
2520 for (i
= j
= 0; i
< XVECLEN (insn
, 0); i
++)
2522 rtx tmp
= XVECEXP (insn
, 0, i
);
2523 if (GET_CODE (tmp
) != MATCH_SCRATCH
&& GET_CODE (tmp
) != MATCH_DUP
)
2525 XVECEXP (x
, 0, j
) = tmp
;
2531 c_test_pos
[0] = 'A' + j
- 1;
2532 c_test_pos
[1] = '\0';
2534 else if (XVECLEN (insn
, type
== RECOG
) == 1)
2535 x
= XVECEXP (insn
, type
== RECOG
, 0);
2538 x
= rtx_alloc (PARALLEL
);
2539 XVEC (x
, 0) = XVEC (insn
, type
== RECOG
);
2540 PUT_MODE (x
, VOIDmode
);
2543 validate_pattern (x
, insn
, NULL_RTX
, 0);
2545 memset(&head
, 0, sizeof(head
));
2546 last
= add_to_sequence (x
, &head
, "", type
, 1);
2548 /* Find the end of the test chain on the last node. */
2549 for (test
= last
->tests
; test
->next
; test
= test
->next
)
2551 place
= &test
->next
;
2553 /* Skip the C test if it's known to be true at compile time. */
2556 /* Need a new node if we have another test to add. */
2557 if (test
->type
== DT_accept_op
)
2559 last
= new_decision (c_test_pos
, &last
->success
);
2560 place
= &last
->tests
;
2562 test
= new_decision_test (DT_c_test
, &place
);
2563 test
->u
.c_test
= c_test
;
2566 test
= new_decision_test (DT_accept_insn
, &place
);
2567 test
->u
.insn
.code_number
= next_insn_code
;
2568 test
->u
.insn
.lineno
= pattern_lineno
;
2569 test
->u
.insn
.num_clobbers_to_add
= 0;
2574 /* If this is a DEFINE_INSN and X is a PARALLEL, see if it ends
2575 with a group of CLOBBERs of (hard) registers or MATCH_SCRATCHes.
2576 If so, set up to recognize the pattern without these CLOBBERs. */
2578 if (GET_CODE (x
) == PARALLEL
)
2582 /* Find the last non-clobber in the parallel. */
2583 for (i
= XVECLEN (x
, 0); i
> 0; i
--)
2585 rtx y
= XVECEXP (x
, 0, i
- 1);
2586 if (GET_CODE (y
) != CLOBBER
2587 || (!REG_P (XEXP (y
, 0))
2588 && GET_CODE (XEXP (y
, 0)) != MATCH_SCRATCH
))
2592 if (i
!= XVECLEN (x
, 0))
2595 struct decision_head clobber_head
;
2597 /* Build a similar insn without the clobbers. */
2599 new_rtx
= XVECEXP (x
, 0, 0);
2604 new_rtx
= rtx_alloc (PARALLEL
);
2605 XVEC (new_rtx
, 0) = rtvec_alloc (i
);
2606 for (j
= i
- 1; j
>= 0; j
--)
2607 XVECEXP (new_rtx
, 0, j
) = XVECEXP (x
, 0, j
);
2611 memset (&clobber_head
, 0, sizeof(clobber_head
));
2612 last
= add_to_sequence (new_rtx
, &clobber_head
, "", type
, 1);
2614 /* Find the end of the test chain on the last node. */
2615 for (test
= last
->tests
; test
->next
; test
= test
->next
)
2618 /* We definitely have a new test to add -- create a new
2620 place
= &test
->next
;
2621 if (test
->type
== DT_accept_op
)
2623 last
= new_decision ("", &last
->success
);
2624 place
= &last
->tests
;
2627 /* Skip the C test if it's known to be true at compile
2631 test
= new_decision_test (DT_c_test
, &place
);
2632 test
->u
.c_test
= c_test
;
2635 test
= new_decision_test (DT_accept_insn
, &place
);
2636 test
->u
.insn
.code_number
= next_insn_code
;
2637 test
->u
.insn
.lineno
= pattern_lineno
;
2638 test
->u
.insn
.num_clobbers_to_add
= XVECLEN (x
, 0) - i
;
2640 merge_trees (&head
, &clobber_head
);
2646 /* Define the subroutine we will call below and emit in genemit. */
2647 printf ("extern rtx gen_split_%d (rtx, rtx *);\n", next_insn_code
);
2651 /* Define the subroutine we will call below and emit in genemit. */
2652 printf ("extern rtx gen_peephole2_%d (rtx, rtx *);\n",
2661 process_tree (struct decision_head
*head
, enum routine_type subroutine_type
)
2663 if (head
->first
== NULL
)
2665 /* We can elide peephole2_insns, but not recog or split_insns. */
2666 if (subroutine_type
== PEEPHOLE2
)
2671 factor_tests (head
);
2673 next_subroutine_number
= 0;
2674 break_out_subroutines (head
, 1);
2675 find_afterward (head
, NULL
);
2677 /* We run this after find_afterward, because find_afterward needs
2678 the redundant DT_mode tests on predicates to determine whether
2679 two tests can both be true or not. */
2680 simplify_tests(head
);
2682 write_subroutines (head
, subroutine_type
);
2685 write_subroutine (head
, subroutine_type
);
2688 extern int main (int, char **);
2691 main (int argc
, char **argv
)
2694 struct decision_head recog_tree
, split_tree
, peephole2_tree
, h
;
2696 progname
= "genrecog";
2698 memset (&recog_tree
, 0, sizeof recog_tree
);
2699 memset (&split_tree
, 0, sizeof split_tree
);
2700 memset (&peephole2_tree
, 0, sizeof peephole2_tree
);
2702 if (!init_rtx_reader_args (argc
, argv
))
2703 return (FATAL_EXIT_CODE
);
2709 /* Read the machine description. */
2713 desc
= read_md_rtx (&pattern_lineno
, &next_insn_code
);
2717 switch (GET_CODE (desc
))
2719 case DEFINE_PREDICATE
:
2720 case DEFINE_SPECIAL_PREDICATE
:
2721 process_define_predicate (desc
);
2725 h
= make_insn_sequence (desc
, RECOG
);
2726 merge_trees (&recog_tree
, &h
);
2730 h
= make_insn_sequence (desc
, SPLIT
);
2731 merge_trees (&split_tree
, &h
);
2734 case DEFINE_PEEPHOLE2
:
2735 h
= make_insn_sequence (desc
, PEEPHOLE2
);
2736 merge_trees (&peephole2_tree
, &h
);
2744 return FATAL_EXIT_CODE
;
2748 process_tree (&recog_tree
, RECOG
);
2749 process_tree (&split_tree
, SPLIT
);
2750 process_tree (&peephole2_tree
, PEEPHOLE2
);
2753 return (ferror (stdout
) != 0 ? FATAL_EXIT_CODE
: SUCCESS_EXIT_CODE
);
2757 debug_decision_2 (struct decision_test
*test
)
2762 fprintf (stderr
, "num_insns=%d", test
->u
.num_insns
);
2765 fprintf (stderr
, "mode=%s", GET_MODE_NAME (test
->u
.mode
));
2768 fprintf (stderr
, "code=%s", GET_RTX_NAME (test
->u
.code
));
2771 fprintf (stderr
, "veclen=%d", test
->u
.veclen
);
2773 case DT_elt_zero_int
:
2774 fprintf (stderr
, "elt0_i=%d", (int) test
->u
.intval
);
2776 case DT_elt_one_int
:
2777 fprintf (stderr
, "elt1_i=%d", (int) test
->u
.intval
);
2779 case DT_elt_zero_wide
:
2780 fprintf (stderr
, "elt0_w=" HOST_WIDE_INT_PRINT_DEC
, test
->u
.intval
);
2782 case DT_elt_zero_wide_safe
:
2783 fprintf (stderr
, "elt0_ws=" HOST_WIDE_INT_PRINT_DEC
, test
->u
.intval
);
2786 fprintf (stderr
, "veclen>=%d", test
->u
.veclen
);
2789 fprintf (stderr
, "dup=%d", test
->u
.dup
);
2792 fprintf (stderr
, "pred=(%s,%s)",
2793 test
->u
.pred
.name
, GET_MODE_NAME(test
->u
.pred
.mode
));
2798 strncpy (sub
, test
->u
.c_test
, sizeof(sub
));
2799 memcpy (sub
+16, "...", 4);
2800 fprintf (stderr
, "c_test=\"%s\"", sub
);
2804 fprintf (stderr
, "A_op=%d", test
->u
.opno
);
2806 case DT_accept_insn
:
2807 fprintf (stderr
, "A_insn=(%d,%d)",
2808 test
->u
.insn
.code_number
, test
->u
.insn
.num_clobbers_to_add
);
2817 debug_decision_1 (struct decision
*d
, int indent
)
2820 struct decision_test
*test
;
2824 for (i
= 0; i
< indent
; ++i
)
2826 fputs ("(nil)\n", stderr
);
2830 for (i
= 0; i
< indent
; ++i
)
2837 debug_decision_2 (test
);
2838 while ((test
= test
->next
) != NULL
)
2840 fputs (" + ", stderr
);
2841 debug_decision_2 (test
);
2844 fprintf (stderr
, "} %d n %d a %d\n", d
->number
,
2845 (d
->next
? d
->next
->number
: -1),
2846 (d
->afterward
? d
->afterward
->number
: -1));
2850 debug_decision_0 (struct decision
*d
, int indent
, int maxdepth
)
2859 for (i
= 0; i
< indent
; ++i
)
2861 fputs ("(nil)\n", stderr
);
2865 debug_decision_1 (d
, indent
);
2866 for (n
= d
->success
.first
; n
; n
= n
->next
)
2867 debug_decision_0 (n
, indent
+ 2, maxdepth
- 1);
2871 debug_decision (struct decision
*d
)
2873 debug_decision_0 (d
, 0, 1000000);
2877 debug_decision_list (struct decision
*d
)
2881 debug_decision_0 (d
, 0, 0);