source: trunk/src/gcc/gcc/recog.c@ 2

Last change on this file since 2 was 2, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 87.4 KB
Line 
1/* Subroutines used by or related to instruction recognition.
2 Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998
3 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 2, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING. If not, write to the Free
19Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2002111-1307, USA. */
21
22
23#include "config.h"
24#include "system.h"
25#include "rtl.h"
26#include "tm_p.h"
27#include "insn-config.h"
28#include "insn-attr.h"
29#include "hard-reg-set.h"
30#include "recog.h"
31#include "regs.h"
32#include "expr.h"
33#include "function.h"
34#include "flags.h"
35#include "real.h"
36#include "toplev.h"
37#include "basic-block.h"
38#include "output.h"
39#include "reload.h"
40
41#ifndef STACK_PUSH_CODE
42#ifdef STACK_GROWS_DOWNWARD
43#define STACK_PUSH_CODE PRE_DEC
44#else
45#define STACK_PUSH_CODE PRE_INC
46#endif
47#endif
48
49#ifndef STACK_POP_CODE
50#ifdef STACK_GROWS_DOWNWARD
51#define STACK_POP_CODE POST_INC
52#else
53#define STACK_POP_CODE POST_DEC
54#endif
55#endif
56
57static void validate_replace_rtx_1 PARAMS ((rtx *, rtx, rtx, rtx));
58static rtx *find_single_use_1 PARAMS ((rtx, rtx *));
59static void validate_replace_src_1 PARAMS ((rtx *, void *));
60static rtx split_insn PARAMS ((rtx));
61
62/* Nonzero means allow operands to be volatile.
63 This should be 0 if you are generating rtl, such as if you are calling
64 the functions in optabs.c and expmed.c (most of the time).
65 This should be 1 if all valid insns need to be recognized,
66 such as in regclass.c and final.c and reload.c.
67
68 init_recog and init_recog_no_volatile are responsible for setting this. */
69
70int volatile_ok;
71
72struct recog_data recog_data;
73
74/* Contains a vector of operand_alternative structures for every operand.
75 Set up by preprocess_constraints. */
76struct operand_alternative recog_op_alt[MAX_RECOG_OPERANDS][MAX_RECOG_ALTERNATIVES];
77
78/* On return from `constrain_operands', indicate which alternative
79 was satisfied. */
80
81int which_alternative;
82
83/* Nonzero after end of reload pass.
84 Set to 1 or 0 by toplev.c.
85 Controls the significance of (SUBREG (MEM)). */
86
87int reload_completed;
88
89/* Initialize data used by the function `recog'.
90 This must be called once in the compilation of a function
91 before any insn recognition may be done in the function. */
92
93void
94init_recog_no_volatile ()
95{
96 volatile_ok = 0;
97}
98
99void
100init_recog ()
101{
102 volatile_ok = 1;
103}
104
105/* Try recognizing the instruction INSN,
106 and return the code number that results.
107 Remember the code so that repeated calls do not
108 need to spend the time for actual rerecognition.
109
110 This function is the normal interface to instruction recognition.
111 The automatically-generated function `recog' is normally called
112 through this one. (The only exception is in combine.c.) */
113
114int
115recog_memoized_1 (insn)
116 rtx insn;
117{
118 if (INSN_CODE (insn) < 0)
119 INSN_CODE (insn) = recog (PATTERN (insn), insn, 0);
120 return INSN_CODE (insn);
121}
122
123
124/* Check that X is an insn-body for an `asm' with operands
125 and that the operands mentioned in it are legitimate. */
126
127int
128check_asm_operands (x)
129 rtx x;
130{
131 int noperands;
132 rtx *operands;
133 const char **constraints;
134 int i;
135
136 /* Post-reload, be more strict with things. */
137 if (reload_completed)
138 {
139 /* ??? Doh! We've not got the wrapping insn. Cook one up. */
140 extract_insn (make_insn_raw (x));
141 constrain_operands (1);
142 return which_alternative >= 0;
143 }
144
145 noperands = asm_noperands (x);
146 if (noperands < 0)
147 return 0;
148 if (noperands == 0)
149 return 1;
150
151 operands = (rtx *) alloca (noperands * sizeof (rtx));
152 constraints = (const char **) alloca (noperands * sizeof (char *));
153
154 decode_asm_operands (x, operands, NULL, constraints, NULL);
155
156 for (i = 0; i < noperands; i++)
157 {
158 const char *c = constraints[i];
159 if (c[0] == '%')
160 c++;
161 if (ISDIGIT ((unsigned char) c[0]) && c[1] == '\0')
162 c = constraints[c[0] - '0'];
163
164 if (! asm_operand_ok (operands[i], c))
165 return 0;
166 }
167
168 return 1;
169}
170
171
172/* Static data for the next two routines. */
173
174typedef struct change_t
175{
176 rtx object;
177 int old_code;
178 rtx *loc;
179 rtx old;
180} change_t;
181
182static change_t *changes;
183static int changes_allocated;
184
185static int num_changes = 0;
186
187/* Validate a proposed change to OBJECT. LOC is the location in the rtl
188 at which NEW will be placed. If OBJECT is zero, no validation is done,
189 the change is simply made.
190
191 Two types of objects are supported: If OBJECT is a MEM, memory_address_p
192 will be called with the address and mode as parameters. If OBJECT is
193 an INSN, CALL_INSN, or JUMP_INSN, the insn will be re-recognized with
194 the change in place.
195
196 IN_GROUP is non-zero if this is part of a group of changes that must be
197 performed as a group. In that case, the changes will be stored. The
198 function `apply_change_group' will validate and apply the changes.
199
200 If IN_GROUP is zero, this is a single change. Try to recognize the insn
201 or validate the memory reference with the change applied. If the result
202 is not valid for the machine, suppress the change and return zero.
203 Otherwise, perform the change and return 1. */
204
205int
206validate_change (object, loc, new, in_group)
207 rtx object;
208 rtx *loc;
209 rtx new;
210 int in_group;
211{
212 rtx old = *loc;
213
214 if (old == new || rtx_equal_p (old, new))
215 return 1;
216
217 if (in_group == 0 && num_changes != 0)
218 abort ();
219
220 *loc = new;
221
222 /* Save the information describing this change. */
223 if (num_changes >= changes_allocated)
224 {
225 if (changes_allocated == 0)
226 /* This value allows for repeated substitutions inside complex
227 indexed addresses, or changes in up to 5 insns. */
228 changes_allocated = MAX_RECOG_OPERANDS * 5;
229 else
230 changes_allocated *= 2;
231
232 changes =
233 (change_t*) xrealloc (changes,
234 sizeof (change_t) * changes_allocated);
235 }
236
237 changes[num_changes].object = object;
238 changes[num_changes].loc = loc;
239 changes[num_changes].old = old;
240
241 if (object && GET_CODE (object) != MEM)
242 {
243 /* Set INSN_CODE to force rerecognition of insn. Save old code in
244 case invalid. */
245 changes[num_changes].old_code = INSN_CODE (object);
246 INSN_CODE (object) = -1;
247 }
248
249 num_changes++;
250
251 /* If we are making a group of changes, return 1. Otherwise, validate the
252 change group we made. */
253
254 if (in_group)
255 return 1;
256 else
257 return apply_change_group ();
258}
259
260/* This subroutine of apply_change_group verifies whether the changes to INSN
261 were valid; i.e. whether INSN can still be recognized. */
262
263int
264insn_invalid_p (insn)
265 rtx insn;
266{
267 rtx pat = PATTERN (insn);
268 int num_clobbers = 0;
269 /* If we are before reload and the pattern is a SET, see if we can add
270 clobbers. */
271 int icode = recog (pat, insn,
272 (GET_CODE (pat) == SET
273 && ! reload_completed && ! reload_in_progress)
274 ? &num_clobbers : 0);
275 int is_asm = icode < 0 && asm_noperands (PATTERN (insn)) >= 0;
276
277
278 /* If this is an asm and the operand aren't legal, then fail. Likewise if
279 this is not an asm and the insn wasn't recognized. */
280 if ((is_asm && ! check_asm_operands (PATTERN (insn)))
281 || (!is_asm && icode < 0))
282 return 1;
283
284 /* If we have to add CLOBBERs, fail if we have to add ones that reference
285 hard registers since our callers can't know if they are live or not.
286 Otherwise, add them. */
287 if (num_clobbers > 0)
288 {
289 rtx newpat;
290
291 if (added_clobbers_hard_reg_p (icode))
292 return 1;
293
294 newpat = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (num_clobbers + 1));
295 XVECEXP (newpat, 0, 0) = pat;
296 add_clobbers (newpat, icode);
297 PATTERN (insn) = pat = newpat;
298 }
299
300 /* After reload, verify that all constraints are satisfied. */
301 if (reload_completed)
302 {
303 extract_insn (insn);
304
305 if (! constrain_operands (1))
306 return 1;
307 }
308
309 INSN_CODE (insn) = icode;
310 return 0;
311}
312
313/* Apply a group of changes previously issued with `validate_change'.
314 Return 1 if all changes are valid, zero otherwise. */
315
316int
317apply_change_group ()
318{
319 int i;
320 rtx last_validated = NULL_RTX;
321
322 /* The changes have been applied and all INSN_CODEs have been reset to force
323 rerecognition.
324
325 The changes are valid if we aren't given an object, or if we are
326 given a MEM and it still is a valid address, or if this is in insn
327 and it is recognized. In the latter case, if reload has completed,
328 we also require that the operands meet the constraints for
329 the insn. */
330
331 for (i = 0; i < num_changes; i++)
332 {
333 rtx object = changes[i].object;
334
335 /* if there is no object to test or if it is the same as the one we
336 already tested, ignore it. */
337 if (object == 0 || object == last_validated)
338 continue;
339
340 if (GET_CODE (object) == MEM)
341 {
342 if (! memory_address_p (GET_MODE (object), XEXP (object, 0)))
343 break;
344 }
345 else if (insn_invalid_p (object))
346 {
347 rtx pat = PATTERN (object);
348
349 /* Perhaps we couldn't recognize the insn because there were
350 extra CLOBBERs at the end. If so, try to re-recognize
351 without the last CLOBBER (later iterations will cause each of
352 them to be eliminated, in turn). But don't do this if we
353 have an ASM_OPERAND. */
354 if (GET_CODE (pat) == PARALLEL
355 && GET_CODE (XVECEXP (pat, 0, XVECLEN (pat, 0) - 1)) == CLOBBER
356 && asm_noperands (PATTERN (object)) < 0)
357 {
358 rtx newpat;
359
360 if (XVECLEN (pat, 0) == 2)
361 newpat = XVECEXP (pat, 0, 0);
362 else
363 {
364 int j;
365
366 newpat
367 = gen_rtx_PARALLEL (VOIDmode,
368 rtvec_alloc (XVECLEN (pat, 0) - 1));
369 for (j = 0; j < XVECLEN (newpat, 0); j++)
370 XVECEXP (newpat, 0, j) = XVECEXP (pat, 0, j);
371 }
372
373 /* Add a new change to this group to replace the pattern
374 with this new pattern. Then consider this change
375 as having succeeded. The change we added will
376 cause the entire call to fail if things remain invalid.
377
378 Note that this can lose if a later change than the one
379 we are processing specified &XVECEXP (PATTERN (object), 0, X)
380 but this shouldn't occur. */
381
382 validate_change (object, &PATTERN (object), newpat, 1);
383 continue;
384 }
385 else if (GET_CODE (pat) == USE || GET_CODE (pat) == CLOBBER)
386 /* If this insn is a CLOBBER or USE, it is always valid, but is
387 never recognized. */
388 continue;
389 else
390 break;
391 }
392 last_validated = object;
393 }
394
395 if (i == num_changes)
396 {
397 num_changes = 0;
398 return 1;
399 }
400 else
401 {
402 cancel_changes (0);
403 return 0;
404 }
405}
406
407/* Return the number of changes so far in the current group. */
408
409int
410num_validated_changes ()
411{
412 return num_changes;
413}
414
415/* Retract the changes numbered NUM and up. */
416
417void
418cancel_changes (num)
419 int num;
420{
421 int i;
422
423 /* Back out all the changes. Do this in the opposite order in which
424 they were made. */
425 for (i = num_changes - 1; i >= num; i--)
426 {
427 *changes[i].loc = changes[i].old;
428 if (changes[i].object && GET_CODE (changes[i].object) != MEM)
429 INSN_CODE (changes[i].object) = changes[i].old_code;
430 }
431 num_changes = num;
432}
433
434/* Replace every occurrence of FROM in X with TO. Mark each change with
435 validate_change passing OBJECT. */
436
437static void
438validate_replace_rtx_1 (loc, from, to, object)
439 rtx *loc;
440 rtx from, to, object;
441{
442 int i, j;
443 const char *fmt;
444 rtx x = *loc;
445 enum rtx_code code;
446 enum machine_mode op0_mode = VOIDmode;
447 int prev_changes = num_changes;
448 rtx new;
449
450 if (!x)
451 return;
452
453 code = GET_CODE (x);
454 fmt = GET_RTX_FORMAT (code);
455 if (fmt[0] == 'e')
456 op0_mode = GET_MODE (XEXP (x, 0));
457
458 /* X matches FROM if it is the same rtx or they are both referring to the
459 same register in the same mode. Avoid calling rtx_equal_p unless the
460 operands look similar. */
461
462 if (x == from
463 || (GET_CODE (x) == REG && GET_CODE (from) == REG
464 && GET_MODE (x) == GET_MODE (from)
465 && REGNO (x) == REGNO (from))
466 || (GET_CODE (x) == GET_CODE (from) && GET_MODE (x) == GET_MODE (from)
467 && rtx_equal_p (x, from)))
468 {
469 validate_change (object, loc, to, 1);
470 return;
471 }
472
473 /* Call ourself recursively to perform the replacements. */
474
475 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
476 {
477 if (fmt[i] == 'e')
478 validate_replace_rtx_1 (&XEXP (x, i), from, to, object);
479 else if (fmt[i] == 'E')
480 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
481 validate_replace_rtx_1 (&XVECEXP (x, i, j), from, to, object);
482 }
483
484 /* If we didn't substitute, there is nothing more to do. */
485 if (num_changes == prev_changes)
486 return;
487
488 /* Allow substituted expression to have different mode. This is used by
489 regmove to change mode of pseudo register. */
490 if (fmt[0] == 'e' && GET_MODE (XEXP (x, 0)) != VOIDmode)
491 op0_mode = GET_MODE (XEXP (x, 0));
492
493 /* Do changes needed to keep rtx consistent. Don't do any other
494 simplifications, as it is not our job. */
495
496 if ((GET_RTX_CLASS (code) == '<' || GET_RTX_CLASS (code) == 'c')
497 && swap_commutative_operands_p (XEXP (x, 0), XEXP (x, 1)))
498 {
499 validate_change (object, loc,
500 gen_rtx_fmt_ee (GET_RTX_CLASS (code) == 'c' ? code
501 : swap_condition (code),
502 GET_MODE (x), XEXP (x, 1),
503 XEXP (x, 0)), 1);
504 x = *loc;
505 code = GET_CODE (x);
506 }
507
508 switch (code)
509 {
510 case PLUS:
511 /* If we have a PLUS whose second operand is now a CONST_INT, use
512 simplify_gen_binary to try to simplify it.
513 ??? We may want later to remove this, once simplification is
514 separated from this function. */
515 if (GET_CODE (XEXP (x, 1)) == CONST_INT && XEXP (x, 1) == to)
516 validate_change (object, loc,
517 simplify_gen_binary
518 (PLUS, GET_MODE (x), XEXP (x, 0), XEXP (x, 1)), 1);
519 break;
520 case MINUS:
521 if (GET_CODE (XEXP (x, 1)) == CONST_INT
522 || GET_CODE (XEXP (x, 1)) == CONST_DOUBLE)
523 validate_change (object, loc,
524 simplify_gen_binary
525 (PLUS, GET_MODE (x), XEXP (x, 0),
526 simplify_gen_unary (NEG,
527 GET_MODE (x), XEXP (x, 1),
528 GET_MODE (x))), 1);
529 break;
530 case ZERO_EXTEND:
531 case SIGN_EXTEND:
532 if (GET_MODE (XEXP (x, 0)) == VOIDmode)
533 {
534 new = simplify_gen_unary (code, GET_MODE (x), XEXP (x, 0),
535 op0_mode);
536 /* If any of the above failed, substitute in something that
537 we know won't be recognized. */
538 if (!new)
539 new = gen_rtx_CLOBBER (GET_MODE (x), const0_rtx);
540 validate_change (object, loc, new, 1);
541 }
542 break;
543 case SUBREG:
544 /* All subregs possible to simplify should be simplified. */
545 new = simplify_subreg (GET_MODE (x), SUBREG_REG (x), op0_mode,
546 SUBREG_BYTE (x));
547
548 /* Subregs of VOIDmode operands are incorrect. */
549 if (!new && GET_MODE (SUBREG_REG (x)) == VOIDmode)
550 new = gen_rtx_CLOBBER (GET_MODE (x), const0_rtx);
551 if (new)
552 validate_change (object, loc, new, 1);
553 break;
554 case ZERO_EXTRACT:
555 case SIGN_EXTRACT:
556 /* If we are replacing a register with memory, try to change the memory
557 to be the mode required for memory in extract operations (this isn't
558 likely to be an insertion operation; if it was, nothing bad will
559 happen, we might just fail in some cases). */
560
561 if (GET_CODE (XEXP (x, 0)) == MEM
562 && GET_CODE (XEXP (x, 1)) == CONST_INT
563 && GET_CODE (XEXP (x, 2)) == CONST_INT
564 && !mode_dependent_address_p (XEXP (XEXP (x, 0), 0))
565 && !MEM_VOLATILE_P (XEXP (x, 0)))
566 {
567 enum machine_mode wanted_mode = VOIDmode;
568 enum machine_mode is_mode = GET_MODE (XEXP (x, 0));
569 int pos = INTVAL (XEXP (x, 2));
570
571 if (GET_CODE (x) == ZERO_EXTRACT)
572 {
573 enum machine_mode new_mode
574 = mode_for_extraction (EP_extzv, 1);
575 if (new_mode != MAX_MACHINE_MODE)
576 wanted_mode = new_mode;
577 }
578 else if (GET_CODE (x) == SIGN_EXTRACT)
579 {
580 enum machine_mode new_mode
581 = mode_for_extraction (EP_extv, 1);
582 if (new_mode != MAX_MACHINE_MODE)
583 wanted_mode = new_mode;
584 }
585
586 /* If we have a narrower mode, we can do something. */
587 if (wanted_mode != VOIDmode
588 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
589 {
590 int offset = pos / BITS_PER_UNIT;
591 rtx newmem;
592
593 /* If the bytes and bits are counted differently, we
594 must adjust the offset. */
595 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
596 offset =
597 (GET_MODE_SIZE (is_mode) - GET_MODE_SIZE (wanted_mode) -
598 offset);
599
600 pos %= GET_MODE_BITSIZE (wanted_mode);
601
602 newmem = adjust_address_nv (XEXP (x, 0), wanted_mode, offset);
603
604 validate_change (object, &XEXP (x, 2), GEN_INT (pos), 1);
605 validate_change (object, &XEXP (x, 0), newmem, 1);
606 }
607 }
608
609 break;
610
611 default:
612 break;
613 }
614}
615
616/* Try replacing every occurrence of FROM in subexpression LOC of INSN
617 with TO. After all changes have been made, validate by seeing
618 if INSN is still valid. */
619
620int
621validate_replace_rtx_subexp (from, to, insn, loc)
622 rtx from, to, insn, *loc;
623{
624 validate_replace_rtx_1 (loc, from, to, insn);
625 return apply_change_group ();
626}
627
628/* Try replacing every occurrence of FROM in INSN with TO. After all
629 changes have been made, validate by seeing if INSN is still valid. */
630
631int
632validate_replace_rtx (from, to, insn)
633 rtx from, to, insn;
634{
635 validate_replace_rtx_1 (&PATTERN (insn), from, to, insn);
636 return apply_change_group ();
637}
638
639/* Try replacing every occurrence of FROM in INSN with TO. */
640
641void
642validate_replace_rtx_group (from, to, insn)
643 rtx from, to, insn;
644{
645 validate_replace_rtx_1 (&PATTERN (insn), from, to, insn);
646}
647
648/* Function called by note_uses to replace used subexpressions. */
649struct validate_replace_src_data
650{
651 rtx from; /* Old RTX */
652 rtx to; /* New RTX */
653 rtx insn; /* Insn in which substitution is occurring. */
654};
655
656static void
657validate_replace_src_1 (x, data)
658 rtx *x;
659 void *data;
660{
661 struct validate_replace_src_data *d
662 = (struct validate_replace_src_data *) data;
663
664 validate_replace_rtx_1 (x, d->from, d->to, d->insn);
665}
666
667/* Try replacing every occurrence of FROM in INSN with TO, avoiding
668 SET_DESTs. After all changes have been made, validate by seeing if
669 INSN is still valid. */
670
671int
672validate_replace_src (from, to, insn)
673 rtx from, to, insn;
674{
675 struct validate_replace_src_data d;
676
677 d.from = from;
678 d.to = to;
679 d.insn = insn;
680 note_uses (&PATTERN (insn), validate_replace_src_1, &d);
681 return apply_change_group ();
682}
683
684
685#ifdef HAVE_cc0
686/* Return 1 if the insn using CC0 set by INSN does not contain
687 any ordered tests applied to the condition codes.
688 EQ and NE tests do not count. */
689
690int
691next_insn_tests_no_inequality (insn)
692 rtx insn;
693{
694 rtx next = next_cc0_user (insn);
695
696 /* If there is no next insn, we have to take the conservative choice. */
697 if (next == 0)
698 return 0;
699
700 return ((GET_CODE (next) == JUMP_INSN
701 || GET_CODE (next) == INSN
702 || GET_CODE (next) == CALL_INSN)
703 && ! inequality_comparisons_p (PATTERN (next)));
704}
705
706#if 0 /* This is useless since the insn that sets the cc's
707 must be followed immediately by the use of them. */
708/* Return 1 if the CC value set up by INSN is not used. */
709
710int
711next_insns_test_no_inequality (insn)
712 rtx insn;
713{
714 rtx next = NEXT_INSN (insn);
715
716 for (; next != 0; next = NEXT_INSN (next))
717 {
718 if (GET_CODE (next) == CODE_LABEL
719 || GET_CODE (next) == BARRIER)
720 return 1;
721 if (GET_CODE (next) == NOTE)
722 continue;
723 if (inequality_comparisons_p (PATTERN (next)))
724 return 0;
725 if (sets_cc0_p (PATTERN (next)) == 1)
726 return 1;
727 if (! reg_mentioned_p (cc0_rtx, PATTERN (next)))
728 return 1;
729 }
730 return 1;
731}
732#endif
733#endif
734
735
736/* This is used by find_single_use to locate an rtx that contains exactly one
737 use of DEST, which is typically either a REG or CC0. It returns a
738 pointer to the innermost rtx expression containing DEST. Appearances of
739 DEST that are being used to totally replace it are not counted. */
740
741static rtx *
742find_single_use_1 (dest, loc)
743 rtx dest;
744 rtx *loc;
745{
746 rtx x = *loc;
747 enum rtx_code code = GET_CODE (x);
748 rtx *result = 0;
749 rtx *this_result;
750 int i;
751 const char *fmt;
752
753 switch (code)
754 {
755 case CONST_INT:
756 case CONST:
757 case LABEL_REF:
758 case SYMBOL_REF:
759 case CONST_DOUBLE:
760 case CONST_VECTOR:
761 case CLOBBER:
762 return 0;
763
764 case SET:
765 /* If the destination is anything other than CC0, PC, a REG or a SUBREG
766 of a REG that occupies all of the REG, the insn uses DEST if
767 it is mentioned in the destination or the source. Otherwise, we
768 need just check the source. */
769 if (GET_CODE (SET_DEST (x)) != CC0
770 && GET_CODE (SET_DEST (x)) != PC
771 && GET_CODE (SET_DEST (x)) != REG
772 && ! (GET_CODE (SET_DEST (x)) == SUBREG
773 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG
774 && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (x))))
775 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
776 == ((GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
777 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD))))
778 break;
779
780 return find_single_use_1 (dest, &SET_SRC (x));
781
782 case MEM:
783 case SUBREG:
784 return find_single_use_1 (dest, &XEXP (x, 0));
785
786 default:
787 break;
788 }
789
790 /* If it wasn't one of the common cases above, check each expression and
791 vector of this code. Look for a unique usage of DEST. */
792
793 fmt = GET_RTX_FORMAT (code);
794 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
795 {
796 if (fmt[i] == 'e')
797 {
798 if (dest == XEXP (x, i)
799 || (GET_CODE (dest) == REG && GET_CODE (XEXP (x, i)) == REG
800 && REGNO (dest) == REGNO (XEXP (x, i))))
801 this_result = loc;
802 else
803 this_result = find_single_use_1 (dest, &XEXP (x, i));
804
805 if (result == 0)
806 result = this_result;
807 else if (this_result)
808 /* Duplicate usage. */
809 return 0;
810 }
811 else if (fmt[i] == 'E')
812 {
813 int j;
814
815 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
816 {
817 if (XVECEXP (x, i, j) == dest
818 || (GET_CODE (dest) == REG
819 && GET_CODE (XVECEXP (x, i, j)) == REG
820 && REGNO (XVECEXP (x, i, j)) == REGNO (dest)))
821 this_result = loc;
822 else
823 this_result = find_single_use_1 (dest, &XVECEXP (x, i, j));
824
825 if (result == 0)
826 result = this_result;
827 else if (this_result)
828 return 0;
829 }
830 }
831 }
832
833 return result;
834}
835
836
837/* See if DEST, produced in INSN, is used only a single time in the
838 sequel. If so, return a pointer to the innermost rtx expression in which
839 it is used.
840
841 If PLOC is non-zero, *PLOC is set to the insn containing the single use.
842
843 This routine will return usually zero either before flow is called (because
844 there will be no LOG_LINKS notes) or after reload (because the REG_DEAD
845 note can't be trusted).
846
847 If DEST is cc0_rtx, we look only at the next insn. In that case, we don't
848 care about REG_DEAD notes or LOG_LINKS.
849
850 Otherwise, we find the single use by finding an insn that has a
851 LOG_LINKS pointing at INSN and has a REG_DEAD note for DEST. If DEST is
852 only referenced once in that insn, we know that it must be the first
853 and last insn referencing DEST. */
854
855rtx *
856find_single_use (dest, insn, ploc)
857 rtx dest;
858 rtx insn;
859 rtx *ploc;
860{
861 rtx next;
862 rtx *result;
863 rtx link;
864
865#ifdef HAVE_cc0
866 if (dest == cc0_rtx)
867 {
868 next = NEXT_INSN (insn);
869 if (next == 0
870 || (GET_CODE (next) != INSN && GET_CODE (next) != JUMP_INSN))
871 return 0;
872
873 result = find_single_use_1 (dest, &PATTERN (next));
874 if (result && ploc)
875 *ploc = next;
876 return result;
877 }
878#endif
879
880 if (reload_completed || reload_in_progress || GET_CODE (dest) != REG)
881 return 0;
882
883 for (next = next_nonnote_insn (insn);
884 next != 0 && GET_CODE (next) != CODE_LABEL;
885 next = next_nonnote_insn (next))
886 if (INSN_P (next) && dead_or_set_p (next, dest))
887 {
888 for (link = LOG_LINKS (next); link; link = XEXP (link, 1))
889 if (XEXP (link, 0) == insn)
890 break;
891
892 if (link)
893 {
894 result = find_single_use_1 (dest, &PATTERN (next));
895 if (ploc)
896 *ploc = next;
897 return result;
898 }
899 }
900
901 return 0;
902}
903
904
905/* Return 1 if OP is a valid general operand for machine mode MODE.
906 This is either a register reference, a memory reference,
907 or a constant. In the case of a memory reference, the address
908 is checked for general validity for the target machine.
909
910 Register and memory references must have mode MODE in order to be valid,
911 but some constants have no machine mode and are valid for any mode.
912
913 If MODE is VOIDmode, OP is checked for validity for whatever mode
914 it has.
915
916 The main use of this function is as a predicate in match_operand
917 expressions in the machine description.
918
919 For an explanation of this function's behavior for registers of
920 class NO_REGS, see the comment for `register_operand'. */
921
922int
923general_operand (op, mode)
924 rtx op;
925 enum machine_mode mode;
926{
927 enum rtx_code code = GET_CODE (op);
928
929 if (mode == VOIDmode)
930 mode = GET_MODE (op);
931
932 /* Don't accept CONST_INT or anything similar
933 if the caller wants something floating. */
934 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
935 && GET_MODE_CLASS (mode) != MODE_INT
936 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
937 return 0;
938
939 if (GET_CODE (op) == CONST_INT
940 && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
941 return 0;
942
943 if (CONSTANT_P (op))
944 return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode
945 || mode == VOIDmode)
946#ifdef LEGITIMATE_PIC_OPERAND_P
947 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
948#endif
949 && LEGITIMATE_CONSTANT_P (op));
950
951 /* Except for certain constants with VOIDmode, already checked for,
952 OP's mode must match MODE if MODE specifies a mode. */
953
954 if (GET_MODE (op) != mode)
955 return 0;
956
957 if (code == SUBREG)
958 {
959 rtx sub = SUBREG_REG (op);
960
961#ifdef INSN_SCHEDULING
962 /* On machines that have insn scheduling, we want all memory
963 reference to be explicit, so outlaw paradoxical SUBREGs. */
964 if (GET_CODE (sub) == MEM
965 && GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (sub)))
966 return 0;
967#endif
968 /* Avoid memories with nonzero SUBREG_BYTE, as offsetting the memory
969 may result in incorrect reference. We should simplify all valid
970 subregs of MEM anyway. But allow this after reload because we
971 might be called from cleanup_subreg_operands.
972
973 ??? This is a kludge. */
974 if (!reload_completed && SUBREG_BYTE (op) != 0
975 && GET_CODE (sub) == MEM)
976 return 0;
977
978 /* FLOAT_MODE subregs can't be paradoxical. Combine will occasionally
979 create such rtl, and we must reject it. */
980 if (GET_MODE_CLASS (GET_MODE (op)) == MODE_FLOAT
981 && GET_MODE_SIZE (GET_MODE (op)) > GET_MODE_SIZE (GET_MODE (sub)))
982 return 0;
983
984 op = sub;
985 code = GET_CODE (op);
986 }
987
988 if (code == REG)
989 /* A register whose class is NO_REGS is not a general operand. */
990 return (REGNO (op) >= FIRST_PSEUDO_REGISTER
991 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS);
992
993 if (code == MEM)
994 {
995 rtx y = XEXP (op, 0);
996
997 if (! volatile_ok && MEM_VOLATILE_P (op))
998 return 0;
999
1000 if (GET_CODE (y) == ADDRESSOF)
1001 return 1;
1002
1003 /* Use the mem's mode, since it will be reloaded thus. */
1004 mode = GET_MODE (op);
1005 GO_IF_LEGITIMATE_ADDRESS (mode, y, win);
1006 }
1007
1008 /* Pretend this is an operand for now; we'll run force_operand
1009 on its replacement in fixup_var_refs_1. */
1010 if (code == ADDRESSOF)
1011 return 1;
1012
1013 return 0;
1014
1015 win:
1016 return 1;
1017}
1018
1019
1020/* Return 1 if OP is a valid memory address for a memory reference
1021 of mode MODE.
1022
1023 The main use of this function is as a predicate in match_operand
1024 expressions in the machine description. */
1025
1026int
1027address_operand (op, mode)
1028 rtx op;
1029 enum machine_mode mode;
1030{
1031 return memory_address_p (mode, op);
1032}
1033
1034/* Return 1 if OP is a register reference of mode MODE.
1035 If MODE is VOIDmode, accept a register in any mode.
1036
1037 The main use of this function is as a predicate in match_operand
1038 expressions in the machine description.
1039
1040 As a special exception, registers whose class is NO_REGS are
1041 not accepted by `register_operand'. The reason for this change
1042 is to allow the representation of special architecture artifacts
1043 (such as a condition code register) without extending the rtl
1044 definitions. Since registers of class NO_REGS cannot be used
1045 as registers in any case where register classes are examined,
1046 it is most consistent to keep this function from accepting them. */
1047
1048int
1049register_operand (op, mode)
1050 rtx op;
1051 enum machine_mode mode;
1052{
1053 if (GET_MODE (op) != mode && mode != VOIDmode)
1054 return 0;
1055
1056 if (GET_CODE (op) == SUBREG)
1057 {
1058 rtx sub = SUBREG_REG (op);
1059
1060 /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
1061 because it is guaranteed to be reloaded into one.
1062 Just make sure the MEM is valid in itself.
1063 (Ideally, (SUBREG (MEM)...) should not exist after reload,
1064 but currently it does result from (SUBREG (REG)...) where the
1065 reg went on the stack.) */
1066 if (! reload_completed && GET_CODE (sub) == MEM)
1067 return general_operand (op, mode);
1068
1069#ifdef CLASS_CANNOT_CHANGE_MODE
1070 if (GET_CODE (sub) == REG
1071 && REGNO (sub) < FIRST_PSEUDO_REGISTER
1072 && (TEST_HARD_REG_BIT
1073 (reg_class_contents[(int) CLASS_CANNOT_CHANGE_MODE],
1074 REGNO (sub)))
1075 && CLASS_CANNOT_CHANGE_MODE_P (mode, GET_MODE (sub))
1076 && GET_MODE_CLASS (GET_MODE (sub)) != MODE_COMPLEX_INT
1077 && GET_MODE_CLASS (GET_MODE (sub)) != MODE_COMPLEX_FLOAT)
1078 return 0;
1079#endif
1080
1081 /* FLOAT_MODE subregs can't be paradoxical. Combine will occasionally
1082 create such rtl, and we must reject it. */
1083 if (GET_MODE_CLASS (GET_MODE (op)) == MODE_FLOAT
1084 && GET_MODE_SIZE (GET_MODE (op)) > GET_MODE_SIZE (GET_MODE (sub)))
1085 return 0;
1086
1087 op = sub;
1088 }
1089
1090 /* If we have an ADDRESSOF, consider it valid since it will be
1091 converted into something that will not be a MEM. */
1092 if (GET_CODE (op) == ADDRESSOF)
1093 return 1;
1094
1095 /* We don't consider registers whose class is NO_REGS
1096 to be a register operand. */
1097 return (GET_CODE (op) == REG
1098 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
1099 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
1100}
1101
1102/* Return 1 for a register in Pmode; ignore the tested mode. */
1103
1104int
1105pmode_register_operand (op, mode)
1106 rtx op;
1107 enum machine_mode mode ATTRIBUTE_UNUSED;
1108{
1109 return register_operand (op, Pmode);
1110}
1111
1112/* Return 1 if OP should match a MATCH_SCRATCH, i.e., if it is a SCRATCH
1113 or a hard register. */
1114
1115int
1116scratch_operand (op, mode)
1117 rtx op;
1118 enum machine_mode mode;
1119{
1120 if (GET_MODE (op) != mode && mode != VOIDmode)
1121 return 0;
1122
1123 return (GET_CODE (op) == SCRATCH
1124 || (GET_CODE (op) == REG
1125 && REGNO (op) < FIRST_PSEUDO_REGISTER));
1126}
1127
1128/* Return 1 if OP is a valid immediate operand for mode MODE.
1129
1130 The main use of this function is as a predicate in match_operand
1131 expressions in the machine description. */
1132
1133int
1134immediate_operand (op, mode)
1135 rtx op;
1136 enum machine_mode mode;
1137{
1138 /* Don't accept CONST_INT or anything similar
1139 if the caller wants something floating. */
1140 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
1141 && GET_MODE_CLASS (mode) != MODE_INT
1142 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
1143 return 0;
1144
1145 if (GET_CODE (op) == CONST_INT
1146 && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1147 return 0;
1148
1149 /* Accept CONSTANT_P_RTX, since it will be gone by CSE1 and
1150 result in 0/1. It seems a safe assumption that this is
1151 in range for everyone. */
1152 if (GET_CODE (op) == CONSTANT_P_RTX)
1153 return 1;
1154
1155 return (CONSTANT_P (op)
1156 && (GET_MODE (op) == mode || mode == VOIDmode
1157 || GET_MODE (op) == VOIDmode)
1158#ifdef LEGITIMATE_PIC_OPERAND_P
1159 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
1160#endif
1161 && LEGITIMATE_CONSTANT_P (op));
1162}
1163
1164/* Returns 1 if OP is an operand that is a CONST_INT. */
1165
1166int
1167const_int_operand (op, mode)
1168 rtx op;
1169 enum machine_mode mode;
1170{
1171 if (GET_CODE (op) != CONST_INT)
1172 return 0;
1173
1174 if (mode != VOIDmode
1175 && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1176 return 0;
1177
1178 return 1;
1179}
1180
1181/* Returns 1 if OP is an operand that is a constant integer or constant
1182 floating-point number. */
1183
1184int
1185const_double_operand (op, mode)
1186 rtx op;
1187 enum machine_mode mode;
1188{
1189 /* Don't accept CONST_INT or anything similar
1190 if the caller wants something floating. */
1191 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
1192 && GET_MODE_CLASS (mode) != MODE_INT
1193 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
1194 return 0;
1195
1196 return ((GET_CODE (op) == CONST_DOUBLE || GET_CODE (op) == CONST_INT)
1197 && (mode == VOIDmode || GET_MODE (op) == mode
1198 || GET_MODE (op) == VOIDmode));
1199}
1200
1201/* Return 1 if OP is a general operand that is not an immediate operand. */
1202
1203int
1204nonimmediate_operand (op, mode)
1205 rtx op;
1206 enum machine_mode mode;
1207{
1208 return (general_operand (op, mode) && ! CONSTANT_P (op));
1209}
1210
1211/* Return 1 if OP is a register reference or immediate value of mode MODE. */
1212
1213int
1214nonmemory_operand (op, mode)
1215 rtx op;
1216 enum machine_mode mode;
1217{
1218 if (CONSTANT_P (op))
1219 {
1220 /* Don't accept CONST_INT or anything similar
1221 if the caller wants something floating. */
1222 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
1223 && GET_MODE_CLASS (mode) != MODE_INT
1224 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
1225 return 0;
1226
1227 if (GET_CODE (op) == CONST_INT
1228 && trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
1229 return 0;
1230
1231 return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode
1232 || mode == VOIDmode)
1233#ifdef LEGITIMATE_PIC_OPERAND_P
1234 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
1235#endif
1236 && LEGITIMATE_CONSTANT_P (op));
1237 }
1238
1239 if (GET_MODE (op) != mode && mode != VOIDmode)
1240 return 0;
1241
1242 if (GET_CODE (op) == SUBREG)
1243 {
1244 /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
1245 because it is guaranteed to be reloaded into one.
1246 Just make sure the MEM is valid in itself.
1247 (Ideally, (SUBREG (MEM)...) should not exist after reload,
1248 but currently it does result from (SUBREG (REG)...) where the
1249 reg went on the stack.) */
1250 if (! reload_completed && GET_CODE (SUBREG_REG (op)) == MEM)
1251 return general_operand (op, mode);
1252 op = SUBREG_REG (op);
1253 }
1254
1255 /* We don't consider registers whose class is NO_REGS
1256 to be a register operand. */
1257 return (GET_CODE (op) == REG
1258 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
1259 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
1260}
1261
1262/* Return 1 if OP is a valid operand that stands for pushing a
1263 value of mode MODE onto the stack.
1264
1265 The main use of this function is as a predicate in match_operand
1266 expressions in the machine description. */
1267
1268int
1269push_operand (op, mode)
1270 rtx op;
1271 enum machine_mode mode;
1272{
1273 unsigned int rounded_size = GET_MODE_SIZE (mode);
1274
1275#ifdef PUSH_ROUNDING
1276 rounded_size = PUSH_ROUNDING (rounded_size);
1277#endif
1278
1279 if (GET_CODE (op) != MEM)
1280 return 0;
1281
1282 if (mode != VOIDmode && GET_MODE (op) != mode)
1283 return 0;
1284
1285 op = XEXP (op, 0);
1286
1287 if (rounded_size == GET_MODE_SIZE (mode))
1288 {
1289 if (GET_CODE (op) != STACK_PUSH_CODE)
1290 return 0;
1291 }
1292 else
1293 {
1294 if (GET_CODE (op) != PRE_MODIFY
1295 || GET_CODE (XEXP (op, 1)) != PLUS
1296 || XEXP (XEXP (op, 1), 0) != XEXP (op, 0)
1297 || GET_CODE (XEXP (XEXP (op, 1), 1)) != CONST_INT
1298#ifdef STACK_GROWS_DOWNWARD
1299 || INTVAL (XEXP (XEXP (op, 1), 1)) != - (int) rounded_size
1300#else
1301 || INTVAL (XEXP (XEXP (op, 1), 1)) != rounded_size
1302#endif
1303 )
1304 return 0;
1305 }
1306
1307 return XEXP (op, 0) == stack_pointer_rtx;
1308}
1309
1310/* Return 1 if OP is a valid operand that stands for popping a
1311 value of mode MODE off the stack.
1312
1313 The main use of this function is as a predicate in match_operand
1314 expressions in the machine description. */
1315
1316int
1317pop_operand (op, mode)
1318 rtx op;
1319 enum machine_mode mode;
1320{
1321 if (GET_CODE (op) != MEM)
1322 return 0;
1323
1324 if (mode != VOIDmode && GET_MODE (op) != mode)
1325 return 0;
1326
1327 op = XEXP (op, 0);
1328
1329 if (GET_CODE (op) != STACK_POP_CODE)
1330 return 0;
1331
1332 return XEXP (op, 0) == stack_pointer_rtx;
1333}
1334
1335/* Return 1 if ADDR is a valid memory address for mode MODE. */
1336
1337int
1338memory_address_p (mode, addr)
1339 enum machine_mode mode ATTRIBUTE_UNUSED;
1340 rtx addr;
1341{
1342 if (GET_CODE (addr) == ADDRESSOF)
1343 return 1;
1344
1345 GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
1346 return 0;
1347
1348 win:
1349 return 1;
1350}
1351
1352/* Return 1 if OP is a valid memory reference with mode MODE,
1353 including a valid address.
1354
1355 The main use of this function is as a predicate in match_operand
1356 expressions in the machine description. */
1357
1358int
1359memory_operand (op, mode)
1360 rtx op;
1361 enum machine_mode mode;
1362{
1363 rtx inner;
1364
1365 if (! reload_completed)
1366 /* Note that no SUBREG is a memory operand before end of reload pass,
1367 because (SUBREG (MEM...)) forces reloading into a register. */
1368 return GET_CODE (op) == MEM && general_operand (op, mode);
1369
1370 if (mode != VOIDmode && GET_MODE (op) != mode)
1371 return 0;
1372
1373 inner = op;
1374 if (GET_CODE (inner) == SUBREG)
1375 inner = SUBREG_REG (inner);
1376
1377 return (GET_CODE (inner) == MEM && general_operand (op, mode));
1378}
1379
1380/* Return 1 if OP is a valid indirect memory reference with mode MODE;
1381 that is, a memory reference whose address is a general_operand. */
1382
1383int
1384indirect_operand (op, mode)
1385 rtx op;
1386 enum machine_mode mode;
1387{
1388 /* Before reload, a SUBREG isn't in memory (see memory_operand, above). */
1389 if (! reload_completed
1390 && GET_CODE (op) == SUBREG && GET_CODE (SUBREG_REG (op)) == MEM)
1391 {
1392 int offset = SUBREG_BYTE (op);
1393 rtx inner = SUBREG_REG (op);
1394
1395 if (mode != VOIDmode && GET_MODE (op) != mode)
1396 return 0;
1397
1398 /* The only way that we can have a general_operand as the resulting
1399 address is if OFFSET is zero and the address already is an operand
1400 or if the address is (plus Y (const_int -OFFSET)) and Y is an
1401 operand. */
1402
1403 return ((offset == 0 && general_operand (XEXP (inner, 0), Pmode))
1404 || (GET_CODE (XEXP (inner, 0)) == PLUS
1405 && GET_CODE (XEXP (XEXP (inner, 0), 1)) == CONST_INT
1406 && INTVAL (XEXP (XEXP (inner, 0), 1)) == -offset
1407 && general_operand (XEXP (XEXP (inner, 0), 0), Pmode)));
1408 }
1409
1410 return (GET_CODE (op) == MEM
1411 && memory_operand (op, mode)
1412 && general_operand (XEXP (op, 0), Pmode));
1413}
1414
1415/* Return 1 if this is a comparison operator. This allows the use of
1416 MATCH_OPERATOR to recognize all the branch insns. */
1417
1418int
1419comparison_operator (op, mode)
1420 rtx op;
1421 enum machine_mode mode;
1422{
1423 return ((mode == VOIDmode || GET_MODE (op) == mode)
1424 && GET_RTX_CLASS (GET_CODE (op)) == '<');
1425}
1426
1427
1428/* If BODY is an insn body that uses ASM_OPERANDS,
1429 return the number of operands (both input and output) in the insn.
1430 Otherwise return -1. */
1431
1432int
1433asm_noperands (body)
1434 rtx body;
1435{
1436 switch (GET_CODE (body))
1437 {
1438 case ASM_OPERANDS:
1439 /* No output operands: return number of input operands. */
1440 return ASM_OPERANDS_INPUT_LENGTH (body);
1441 case SET:
1442 if (GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1443 /* Single output operand: BODY is (set OUTPUT (asm_operands ...)). */
1444 return ASM_OPERANDS_INPUT_LENGTH (SET_SRC (body)) + 1;
1445 else
1446 return -1;
1447 case PARALLEL:
1448 if (GET_CODE (XVECEXP (body, 0, 0)) == SET
1449 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
1450 {
1451 /* Multiple output operands, or 1 output plus some clobbers:
1452 body is [(set OUTPUT (asm_operands ...))... (clobber (reg ...))...]. */
1453 int i;
1454 int n_sets;
1455
1456 /* Count backwards through CLOBBERs to determine number of SETs. */
1457 for (i = XVECLEN (body, 0); i > 0; i--)
1458 {
1459 if (GET_CODE (XVECEXP (body, 0, i - 1)) == SET)
1460 break;
1461 if (GET_CODE (XVECEXP (body, 0, i - 1)) != CLOBBER)
1462 return -1;
1463 }
1464
1465 /* N_SETS is now number of output operands. */
1466 n_sets = i;
1467
1468 /* Verify that all the SETs we have
1469 came from a single original asm_operands insn
1470 (so that invalid combinations are blocked). */
1471 for (i = 0; i < n_sets; i++)
1472 {
1473 rtx elt = XVECEXP (body, 0, i);
1474 if (GET_CODE (elt) != SET)
1475 return -1;
1476 if (GET_CODE (SET_SRC (elt)) != ASM_OPERANDS)
1477 return -1;
1478 /* If these ASM_OPERANDS rtx's came from different original insns
1479 then they aren't allowed together. */
1480 if (ASM_OPERANDS_INPUT_VEC (SET_SRC (elt))
1481 != ASM_OPERANDS_INPUT_VEC (SET_SRC (XVECEXP (body, 0, 0))))
1482 return -1;
1483 }
1484 return (ASM_OPERANDS_INPUT_LENGTH (SET_SRC (XVECEXP (body, 0, 0)))
1485 + n_sets);
1486 }
1487 else if (GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1488 {
1489 /* 0 outputs, but some clobbers:
1490 body is [(asm_operands ...) (clobber (reg ...))...]. */
1491 int i;
1492
1493 /* Make sure all the other parallel things really are clobbers. */
1494 for (i = XVECLEN (body, 0) - 1; i > 0; i--)
1495 if (GET_CODE (XVECEXP (body, 0, i)) != CLOBBER)
1496 return -1;
1497
1498 return ASM_OPERANDS_INPUT_LENGTH (XVECEXP (body, 0, 0));
1499 }
1500 else
1501 return -1;
1502 default:
1503 return -1;
1504 }
1505}
1506
1507/* Assuming BODY is an insn body that uses ASM_OPERANDS,
1508 copy its operands (both input and output) into the vector OPERANDS,
1509 the locations of the operands within the insn into the vector OPERAND_LOCS,
1510 and the constraints for the operands into CONSTRAINTS.
1511 Write the modes of the operands into MODES.
1512 Return the assembler-template.
1513
1514 If MODES, OPERAND_LOCS, CONSTRAINTS or OPERANDS is 0,
1515 we don't store that info. */
1516
1517const char *
1518decode_asm_operands (body, operands, operand_locs, constraints, modes)
1519 rtx body;
1520 rtx *operands;
1521 rtx **operand_locs;
1522 const char **constraints;
1523 enum machine_mode *modes;
1524{
1525 int i;
1526 int noperands;
1527 const char *template = 0;
1528
1529 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1530 {
1531 rtx asmop = SET_SRC (body);
1532 /* Single output operand: BODY is (set OUTPUT (asm_operands ....)). */
1533
1534 noperands = ASM_OPERANDS_INPUT_LENGTH (asmop) + 1;
1535
1536 for (i = 1; i < noperands; i++)
1537 {
1538 if (operand_locs)
1539 operand_locs[i] = &ASM_OPERANDS_INPUT (asmop, i - 1);
1540 if (operands)
1541 operands[i] = ASM_OPERANDS_INPUT (asmop, i - 1);
1542 if (constraints)
1543 constraints[i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i - 1);
1544 if (modes)
1545 modes[i] = ASM_OPERANDS_INPUT_MODE (asmop, i - 1);
1546 }
1547
1548 /* The output is in the SET.
1549 Its constraint is in the ASM_OPERANDS itself. */
1550 if (operands)
1551 operands[0] = SET_DEST (body);
1552 if (operand_locs)
1553 operand_locs[0] = &SET_DEST (body);
1554 if (constraints)
1555 constraints[0] = ASM_OPERANDS_OUTPUT_CONSTRAINT (asmop);
1556 if (modes)
1557 modes[0] = GET_MODE (SET_DEST (body));
1558 template = ASM_OPERANDS_TEMPLATE (asmop);
1559 }
1560 else if (GET_CODE (body) == ASM_OPERANDS)
1561 {
1562 rtx asmop = body;
1563 /* No output operands: BODY is (asm_operands ....). */
1564
1565 noperands = ASM_OPERANDS_INPUT_LENGTH (asmop);
1566
1567 /* The input operands are found in the 1st element vector. */
1568 /* Constraints for inputs are in the 2nd element vector. */
1569 for (i = 0; i < noperands; i++)
1570 {
1571 if (operand_locs)
1572 operand_locs[i] = &ASM_OPERANDS_INPUT (asmop, i);
1573 if (operands)
1574 operands[i] = ASM_OPERANDS_INPUT (asmop, i);
1575 if (constraints)
1576 constraints[i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
1577 if (modes)
1578 modes[i] = ASM_OPERANDS_INPUT_MODE (asmop, i);
1579 }
1580 template = ASM_OPERANDS_TEMPLATE (asmop);
1581 }
1582 else if (GET_CODE (body) == PARALLEL
1583 && GET_CODE (XVECEXP (body, 0, 0)) == SET
1584 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
1585 {
1586 rtx asmop = SET_SRC (XVECEXP (body, 0, 0));
1587 int nparallel = XVECLEN (body, 0); /* Includes CLOBBERs. */
1588 int nin = ASM_OPERANDS_INPUT_LENGTH (asmop);
1589 int nout = 0; /* Does not include CLOBBERs. */
1590
1591 /* At least one output, plus some CLOBBERs. */
1592
1593 /* The outputs are in the SETs.
1594 Their constraints are in the ASM_OPERANDS itself. */
1595 for (i = 0; i < nparallel; i++)
1596 {
1597 if (GET_CODE (XVECEXP (body, 0, i)) == CLOBBER)
1598 break; /* Past last SET */
1599
1600 if (operands)
1601 operands[i] = SET_DEST (XVECEXP (body, 0, i));
1602 if (operand_locs)
1603 operand_locs[i] = &SET_DEST (XVECEXP (body, 0, i));
1604 if (constraints)
1605 constraints[i] = XSTR (SET_SRC (XVECEXP (body, 0, i)), 1);
1606 if (modes)
1607 modes[i] = GET_MODE (SET_DEST (XVECEXP (body, 0, i)));
1608 nout++;
1609 }
1610
1611 for (i = 0; i < nin; i++)
1612 {
1613 if (operand_locs)
1614 operand_locs[i + nout] = &ASM_OPERANDS_INPUT (asmop, i);
1615 if (operands)
1616 operands[i + nout] = ASM_OPERANDS_INPUT (asmop, i);
1617 if (constraints)
1618 constraints[i + nout] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
1619 if (modes)
1620 modes[i + nout] = ASM_OPERANDS_INPUT_MODE (asmop, i);
1621 }
1622
1623 template = ASM_OPERANDS_TEMPLATE (asmop);
1624 }
1625 else if (GET_CODE (body) == PARALLEL
1626 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1627 {
1628 /* No outputs, but some CLOBBERs. */
1629
1630 rtx asmop = XVECEXP (body, 0, 0);
1631 int nin = ASM_OPERANDS_INPUT_LENGTH (asmop);
1632
1633 for (i = 0; i < nin; i++)
1634 {
1635 if (operand_locs)
1636 operand_locs[i] = &ASM_OPERANDS_INPUT (asmop, i);
1637 if (operands)
1638 operands[i] = ASM_OPERANDS_INPUT (asmop, i);
1639 if (constraints)
1640 constraints[i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
1641 if (modes)
1642 modes[i] = ASM_OPERANDS_INPUT_MODE (asmop, i);
1643 }
1644
1645 template = ASM_OPERANDS_TEMPLATE (asmop);
1646 }
1647
1648 return template;
1649}
1650
1651/* Check if an asm_operand matches it's constraints.
1652 Return > 0 if ok, = 0 if bad, < 0 if inconclusive. */
1653
1654int
1655asm_operand_ok (op, constraint)
1656 rtx op;
1657 const char *constraint;
1658{
1659 int result = 0;
1660
1661 /* Use constrain_operands after reload. */
1662 if (reload_completed)
1663 abort ();
1664
1665 while (*constraint)
1666 {
1667 char c = *constraint++;
1668 switch (c)
1669 {
1670 case '=':
1671 case '+':
1672 case '*':
1673 case '%':
1674 case '?':
1675 case '!':
1676 case '#':
1677 case '&':
1678 case ',':
1679 break;
1680
1681 case '0': case '1': case '2': case '3': case '4':
1682 case '5': case '6': case '7': case '8': case '9':
1683 /* For best results, our caller should have given us the
1684 proper matching constraint, but we can't actually fail
1685 the check if they didn't. Indicate that results are
1686 inconclusive. */
1687 while (ISDIGIT (*constraint))
1688 constraint++;
1689 result = -1;
1690 break;
1691
1692 case 'p':
1693 if (address_operand (op, VOIDmode))
1694 return 1;
1695 break;
1696
1697 case 'm':
1698 case 'V': /* non-offsettable */
1699 if (memory_operand (op, VOIDmode))
1700 return 1;
1701 break;
1702
1703 case 'o': /* offsettable */
1704 if (offsettable_nonstrict_memref_p (op))
1705 return 1;
1706 break;
1707
1708 case '<':
1709 /* ??? Before flow, auto inc/dec insns are not supposed to exist,
1710 excepting those that expand_call created. Further, on some
1711 machines which do not have generalized auto inc/dec, an inc/dec
1712 is not a memory_operand.
1713
1714 Match any memory and hope things are resolved after reload. */
1715
1716 if (GET_CODE (op) == MEM
1717 && (1
1718 || GET_CODE (XEXP (op, 0)) == PRE_DEC
1719 || GET_CODE (XEXP (op, 0)) == POST_DEC))
1720 return 1;
1721 break;
1722
1723 case '>':
1724 if (GET_CODE (op) == MEM
1725 && (1
1726 || GET_CODE (XEXP (op, 0)) == PRE_INC
1727 || GET_CODE (XEXP (op, 0)) == POST_INC))
1728 return 1;
1729 break;
1730
1731 case 'E':
1732#ifndef REAL_ARITHMETIC
1733 /* Match any floating double constant, but only if
1734 we can examine the bits of it reliably. */
1735 if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
1736 || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
1737 && GET_MODE (op) != VOIDmode && ! flag_pretend_float)
1738 break;
1739#endif
1740 /* FALLTHRU */
1741
1742 case 'F':
1743 if (GET_CODE (op) == CONST_DOUBLE)
1744 return 1;
1745 break;
1746
1747 case 'G':
1748 if (GET_CODE (op) == CONST_DOUBLE
1749 && CONST_DOUBLE_OK_FOR_LETTER_P (op, 'G'))
1750 return 1;
1751 break;
1752 case 'H':
1753 if (GET_CODE (op) == CONST_DOUBLE
1754 && CONST_DOUBLE_OK_FOR_LETTER_P (op, 'H'))
1755 return 1;
1756 break;
1757
1758 case 's':
1759 if (GET_CODE (op) == CONST_INT
1760 || (GET_CODE (op) == CONST_DOUBLE
1761 && GET_MODE (op) == VOIDmode))
1762 break;
1763 /* FALLTHRU */
1764
1765 case 'i':
1766 if (CONSTANT_P (op)
1767#ifdef LEGITIMATE_PIC_OPERAND_P
1768 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
1769#endif
1770 )
1771 return 1;
1772 break;
1773
1774 case 'n':
1775 if (GET_CODE (op) == CONST_INT
1776 || (GET_CODE (op) == CONST_DOUBLE
1777 && GET_MODE (op) == VOIDmode))
1778 return 1;
1779 break;
1780
1781 case 'I':
1782 if (GET_CODE (op) == CONST_INT
1783 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'))
1784 return 1;
1785 break;
1786 case 'J':
1787 if (GET_CODE (op) == CONST_INT
1788 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'J'))
1789 return 1;
1790 break;
1791 case 'K':
1792 if (GET_CODE (op) == CONST_INT
1793 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'K'))
1794 return 1;
1795 break;
1796 case 'L':
1797 if (GET_CODE (op) == CONST_INT
1798 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'))
1799 return 1;
1800 break;
1801 case 'M':
1802 if (GET_CODE (op) == CONST_INT
1803 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'M'))
1804 return 1;
1805 break;
1806 case 'N':
1807 if (GET_CODE (op) == CONST_INT
1808 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'N'))
1809 return 1;
1810 break;
1811 case 'O':
1812 if (GET_CODE (op) == CONST_INT
1813 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'O'))
1814 return 1;
1815 break;
1816 case 'P':
1817 if (GET_CODE (op) == CONST_INT
1818 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'P'))
1819 return 1;
1820 break;
1821
1822 case 'X':
1823 return 1;
1824
1825 case 'g':
1826 if (general_operand (op, VOIDmode))
1827 return 1;
1828 break;
1829
1830 default:
1831 /* For all other letters, we first check for a register class,
1832 otherwise it is an EXTRA_CONSTRAINT. */
1833 if (REG_CLASS_FROM_LETTER (c) != NO_REGS)
1834 {
1835 case 'r':
1836 if (GET_MODE (op) == BLKmode)
1837 break;
1838 if (register_operand (op, VOIDmode))
1839 return 1;
1840 }
1841#ifdef EXTRA_CONSTRAINT
1842 if (EXTRA_CONSTRAINT (op, c))
1843 return 1;
1844#endif
1845 break;
1846 }
1847 }
1848
1849 return result;
1850}
1851
1852
1853/* Given an rtx *P, if it is a sum containing an integer constant term,
1854 return the location (type rtx *) of the pointer to that constant term.
1855 Otherwise, return a null pointer. */
1856
1857rtx *
1858find_constant_term_loc (p)
1859 rtx *p;
1860{
1861 rtx *tem;
1862 enum rtx_code code = GET_CODE (*p);
1863
1864 /* If *P IS such a constant term, P is its location. */
1865
1866 if (code == CONST_INT || code == SYMBOL_REF || code == LABEL_REF
1867 || code == CONST)
1868 return p;
1869
1870 /* Otherwise, if not a sum, it has no constant term. */
1871
1872 if (GET_CODE (*p) != PLUS)
1873 return 0;
1874
1875 /* If one of the summands is constant, return its location. */
1876
1877 if (XEXP (*p, 0) && CONSTANT_P (XEXP (*p, 0))
1878 && XEXP (*p, 1) && CONSTANT_P (XEXP (*p, 1)))
1879 return p;
1880
1881 /* Otherwise, check each summand for containing a constant term. */
1882
1883 if (XEXP (*p, 0) != 0)
1884 {
1885 tem = find_constant_term_loc (&XEXP (*p, 0));
1886 if (tem != 0)
1887 return tem;
1888 }
1889
1890 if (XEXP (*p, 1) != 0)
1891 {
1892 tem = find_constant_term_loc (&XEXP (*p, 1));
1893 if (tem != 0)
1894 return tem;
1895 }
1896
1897 return 0;
1898}
1899
1900
1901/* Return 1 if OP is a memory reference
1902 whose address contains no side effects
1903 and remains valid after the addition
1904 of a positive integer less than the
1905 size of the object being referenced.
1906
1907 We assume that the original address is valid and do not check it.
1908
1909 This uses strict_memory_address_p as a subroutine, so
1910 don't use it before reload. */
1911
1912int
1913offsettable_memref_p (op)
1914 rtx op;
1915{
1916 return ((GET_CODE (op) == MEM)
1917 && offsettable_address_p (1, GET_MODE (op), XEXP (op, 0)));
1918}
1919
1920/* Similar, but don't require a strictly valid mem ref:
1921 consider pseudo-regs valid as index or base regs. */
1922
1923int
1924offsettable_nonstrict_memref_p (op)
1925 rtx op;
1926{
1927 return ((GET_CODE (op) == MEM)
1928 && offsettable_address_p (0, GET_MODE (op), XEXP (op, 0)));
1929}
1930
1931/* Return 1 if Y is a memory address which contains no side effects
1932 and would remain valid after the addition of a positive integer
1933 less than the size of that mode.
1934
1935 We assume that the original address is valid and do not check it.
1936 We do check that it is valid for narrower modes.
1937
1938 If STRICTP is nonzero, we require a strictly valid address,
1939 for the sake of use in reload.c. */
1940
1941int
1942offsettable_address_p (strictp, mode, y)
1943 int strictp;
1944 enum machine_mode mode;
1945 rtx y;
1946{
1947 enum rtx_code ycode = GET_CODE (y);
1948 rtx z;
1949 rtx y1 = y;
1950 rtx *y2;
1951 int (*addressp) PARAMS ((enum machine_mode, rtx)) =
1952 (strictp ? strict_memory_address_p : memory_address_p);
1953 unsigned int mode_sz = GET_MODE_SIZE (mode);
1954
1955 if (CONSTANT_ADDRESS_P (y))
1956 return 1;
1957
1958 /* Adjusting an offsettable address involves changing to a narrower mode.
1959 Make sure that's OK. */
1960
1961 if (mode_dependent_address_p (y))
1962 return 0;
1963
1964 /* ??? How much offset does an offsettable BLKmode reference need?
1965 Clearly that depends on the situation in which it's being used.
1966 However, the current situation in which we test 0xffffffff is
1967 less than ideal. Caveat user. */
1968 if (mode_sz == 0)
1969 mode_sz = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
1970
1971 /* If the expression contains a constant term,
1972 see if it remains valid when max possible offset is added. */
1973
1974 if ((ycode == PLUS) && (y2 = find_constant_term_loc (&y1)))
1975 {
1976 int good;
1977
1978 y1 = *y2;
1979 *y2 = plus_constant (*y2, mode_sz - 1);
1980 /* Use QImode because an odd displacement may be automatically invalid
1981 for any wider mode. But it should be valid for a single byte. */
1982 good = (*addressp) (QImode, y);
1983
1984 /* In any case, restore old contents of memory. */
1985 *y2 = y1;
1986 return good;
1987 }
1988
1989 if (GET_RTX_CLASS (ycode) == 'a')
1990 return 0;
1991
1992 /* The offset added here is chosen as the maximum offset that
1993 any instruction could need to add when operating on something
1994 of the specified mode. We assume that if Y and Y+c are
1995 valid addresses then so is Y+d for all 0<d<c. adjust_address will
1996 go inside a LO_SUM here, so we do so as well. */
1997 if (GET_CODE (y) == LO_SUM
1998 && mode != BLKmode
1999 && mode_sz <= GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT)
2000 z = gen_rtx_LO_SUM (GET_MODE (y), XEXP (y, 0),
2001 plus_constant (XEXP (y, 1), mode_sz - 1));
2002 else
2003 z = plus_constant (y, mode_sz - 1);
2004
2005 /* Use QImode because an odd displacement may be automatically invalid
2006 for any wider mode. But it should be valid for a single byte. */
2007 return (*addressp) (QImode, z);
2008}
2009
2010/* Return 1 if ADDR is an address-expression whose effect depends
2011 on the mode of the memory reference it is used in.
2012
2013 Autoincrement addressing is a typical example of mode-dependence
2014 because the amount of the increment depends on the mode. */
2015
2016int
2017mode_dependent_address_p (addr)
2018 rtx addr ATTRIBUTE_UNUSED; /* Maybe used in GO_IF_MODE_DEPENDENT_ADDRESS. */
2019{
2020 GO_IF_MODE_DEPENDENT_ADDRESS (addr, win);
2021 return 0;
2022 /* Label `win' might (not) be used via GO_IF_MODE_DEPENDENT_ADDRESS. */
2023 win: ATTRIBUTE_UNUSED_LABEL
2024 return 1;
2025}
2026
2027/* Return 1 if OP is a general operand
2028 other than a memory ref with a mode dependent address. */
2029
2030int
2031mode_independent_operand (op, mode)
2032 enum machine_mode mode;
2033 rtx op;
2034{
2035 rtx addr;
2036
2037 if (! general_operand (op, mode))
2038 return 0;
2039
2040 if (GET_CODE (op) != MEM)
2041 return 1;
2042
2043 addr = XEXP (op, 0);
2044 GO_IF_MODE_DEPENDENT_ADDRESS (addr, lose);
2045 return 1;
2046 /* Label `lose' might (not) be used via GO_IF_MODE_DEPENDENT_ADDRESS. */
2047 lose: ATTRIBUTE_UNUSED_LABEL
2048 return 0;
2049}
2050
2051
2052/* Like extract_insn, but save insn extracted and don't extract again, when
2053 called again for the same insn expecting that recog_data still contain the
2054 valid information. This is used primary by gen_attr infrastructure that
2055 often does extract insn again and again. */
2056void
2057extract_insn_cached (insn)
2058 rtx insn;
2059{
2060 if (recog_data.insn == insn && INSN_CODE (insn) >= 0)
2061 return;
2062 extract_insn (insn);
2063 recog_data.insn = insn;
2064}
2065/* Do cached extract_insn, constrain_operand and complain about failures.
2066 Used by insn_attrtab. */
2067void
2068extract_constrain_insn_cached (insn)
2069 rtx insn;
2070{
2071 extract_insn_cached (insn);
2072 if (which_alternative == -1
2073 && !constrain_operands (reload_completed))
2074 fatal_insn_not_found (insn);
2075}
2076/* Do cached constrain_operand and complain about failures. */
2077int
2078constrain_operands_cached (strict)
2079 int strict;
2080{
2081 if (which_alternative == -1)
2082 return constrain_operands (strict);
2083 else
2084 return 1;
2085}
2086
2087
2088/* Analyze INSN and fill in recog_data. */
2089
2090void
2091extract_insn (insn)
2092 rtx insn;
2093{
2094 int i;
2095 int icode;
2096 int noperands;
2097 rtx body = PATTERN (insn);
2098
2099 recog_data.insn = NULL;
2100 recog_data.n_operands = 0;
2101 recog_data.n_alternatives = 0;
2102 recog_data.n_dups = 0;
2103 which_alternative = -1;
2104
2105 switch (GET_CODE (body))
2106 {
2107 case USE:
2108 case CLOBBER:
2109 case ASM_INPUT:
2110 case ADDR_VEC:
2111 case ADDR_DIFF_VEC:
2112 return;
2113
2114 case SET:
2115 if (GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
2116 goto asm_insn;
2117 else
2118 goto normal_insn;
2119 case PARALLEL:
2120 if ((GET_CODE (XVECEXP (body, 0, 0)) == SET
2121 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
2122 || GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
2123 goto asm_insn;
2124 else
2125 goto normal_insn;
2126 case ASM_OPERANDS:
2127 asm_insn:
2128 recog_data.n_operands = noperands = asm_noperands (body);
2129 if (noperands >= 0)
2130 {
2131 /* This insn is an `asm' with operands. */
2132
2133 /* expand_asm_operands makes sure there aren't too many operands. */
2134 if (noperands > MAX_RECOG_OPERANDS)
2135 abort ();
2136
2137 /* Now get the operand values and constraints out of the insn. */
2138 decode_asm_operands (body, recog_data.operand,
2139 recog_data.operand_loc,
2140 recog_data.constraints,
2141 recog_data.operand_mode);
2142 if (noperands > 0)
2143 {
2144 const char *p = recog_data.constraints[0];
2145 recog_data.n_alternatives = 1;
2146 while (*p)
2147 recog_data.n_alternatives += (*p++ == ',');
2148 }
2149 break;
2150 }
2151 fatal_insn_not_found (insn);
2152
2153 default:
2154 normal_insn:
2155 /* Ordinary insn: recognize it, get the operands via insn_extract
2156 and get the constraints. */
2157
2158 icode = recog_memoized (insn);
2159 if (icode < 0)
2160 fatal_insn_not_found (insn);
2161
2162 recog_data.n_operands = noperands = insn_data[icode].n_operands;
2163 recog_data.n_alternatives = insn_data[icode].n_alternatives;
2164 recog_data.n_dups = insn_data[icode].n_dups;
2165
2166 insn_extract (insn);
2167
2168 for (i = 0; i < noperands; i++)
2169 {
2170 recog_data.constraints[i] = insn_data[icode].operand[i].constraint;
2171 recog_data.operand_mode[i] = insn_data[icode].operand[i].mode;
2172 /* VOIDmode match_operands gets mode from their real operand. */
2173 if (recog_data.operand_mode[i] == VOIDmode)
2174 recog_data.operand_mode[i] = GET_MODE (recog_data.operand[i]);
2175 }
2176 }
2177 for (i = 0; i < noperands; i++)
2178 recog_data.operand_type[i]
2179 = (recog_data.constraints[i][0] == '=' ? OP_OUT
2180 : recog_data.constraints[i][0] == '+' ? OP_INOUT
2181 : OP_IN);
2182
2183 if (recog_data.n_alternatives > MAX_RECOG_ALTERNATIVES)
2184 abort ();
2185}
2186
2187/* After calling extract_insn, you can use this function to extract some
2188 information from the constraint strings into a more usable form.
2189 The collected data is stored in recog_op_alt. */
2190void
2191preprocess_constraints ()
2192{
2193 int i;
2194
2195 memset (recog_op_alt, 0, sizeof recog_op_alt);
2196 for (i = 0; i < recog_data.n_operands; i++)
2197 {
2198 int j;
2199 struct operand_alternative *op_alt;
2200 const char *p = recog_data.constraints[i];
2201
2202 op_alt = recog_op_alt[i];
2203
2204 for (j = 0; j < recog_data.n_alternatives; j++)
2205 {
2206 op_alt[j].class = NO_REGS;
2207 op_alt[j].constraint = p;
2208 op_alt[j].matches = -1;
2209 op_alt[j].matched = -1;
2210
2211 if (*p == '\0' || *p == ',')
2212 {
2213 op_alt[j].anything_ok = 1;
2214 continue;
2215 }
2216
2217 for (;;)
2218 {
2219 char c = *p++;
2220 if (c == '#')
2221 do
2222 c = *p++;
2223 while (c != ',' && c != '\0');
2224 if (c == ',' || c == '\0')
2225 break;
2226
2227 switch (c)
2228 {
2229 case '=': case '+': case '*': case '%':
2230 case 'E': case 'F': case 'G': case 'H':
2231 case 's': case 'i': case 'n':
2232 case 'I': case 'J': case 'K': case 'L':
2233 case 'M': case 'N': case 'O': case 'P':
2234 /* These don't say anything we care about. */
2235 break;
2236
2237 case '?':
2238 op_alt[j].reject += 6;
2239 break;
2240 case '!':
2241 op_alt[j].reject += 600;
2242 break;
2243 case '&':
2244 op_alt[j].earlyclobber = 1;
2245 break;
2246
2247 case '0': case '1': case '2': case '3': case '4':
2248 case '5': case '6': case '7': case '8': case '9':
2249 {
2250 char *end;
2251 op_alt[j].matches = strtoul (p - 1, &end, 10);
2252 recog_op_alt[op_alt[j].matches][j].matched = i;
2253 p = end;
2254 }
2255 break;
2256
2257 case 'm':
2258 op_alt[j].memory_ok = 1;
2259 break;
2260 case '<':
2261 op_alt[j].decmem_ok = 1;
2262 break;
2263 case '>':
2264 op_alt[j].incmem_ok = 1;
2265 break;
2266 case 'V':
2267 op_alt[j].nonoffmem_ok = 1;
2268 break;
2269 case 'o':
2270 op_alt[j].offmem_ok = 1;
2271 break;
2272 case 'X':
2273 op_alt[j].anything_ok = 1;
2274 break;
2275
2276 case 'p':
2277 op_alt[j].is_address = 1;
2278 op_alt[j].class = reg_class_subunion[(int) op_alt[j].class]
2279 [(int) MODE_BASE_REG_CLASS (VOIDmode)];
2280 break;
2281
2282 case 'g': case 'r':
2283 op_alt[j].class = reg_class_subunion[(int) op_alt[j].class][(int) GENERAL_REGS];
2284 break;
2285
2286 default:
2287 op_alt[j].class = reg_class_subunion[(int) op_alt[j].class][(int) REG_CLASS_FROM_LETTER ((unsigned char) c)];
2288 break;
2289 }
2290 }
2291 }
2292 }
2293}
2294
2295/* Check the operands of an insn against the insn's operand constraints
2296 and return 1 if they are valid.
2297 The information about the insn's operands, constraints, operand modes
2298 etc. is obtained from the global variables set up by extract_insn.
2299
2300 WHICH_ALTERNATIVE is set to a number which indicates which
2301 alternative of constraints was matched: 0 for the first alternative,
2302 1 for the next, etc.
2303
2304 In addition, when two operands are match
2305 and it happens that the output operand is (reg) while the
2306 input operand is --(reg) or ++(reg) (a pre-inc or pre-dec),
2307 make the output operand look like the input.
2308 This is because the output operand is the one the template will print.
2309
2310 This is used in final, just before printing the assembler code and by
2311 the routines that determine an insn's attribute.
2312
2313 If STRICT is a positive non-zero value, it means that we have been
2314 called after reload has been completed. In that case, we must
2315 do all checks strictly. If it is zero, it means that we have been called
2316 before reload has completed. In that case, we first try to see if we can
2317 find an alternative that matches strictly. If not, we try again, this
2318 time assuming that reload will fix up the insn. This provides a "best
2319 guess" for the alternative and is used to compute attributes of insns prior
2320 to reload. A negative value of STRICT is used for this internal call. */
2321
2322struct funny_match
2323{
2324 int this, other;
2325};
2326
2327int
2328constrain_operands (strict)
2329 int strict;
2330{
2331 const char *constraints[MAX_RECOG_OPERANDS];
2332 int matching_operands[MAX_RECOG_OPERANDS];
2333 int earlyclobber[MAX_RECOG_OPERANDS];
2334 int c;
2335
2336 struct funny_match funny_match[MAX_RECOG_OPERANDS];
2337 int funny_match_index;
2338
2339 which_alternative = 0;
2340 if (recog_data.n_operands == 0 || recog_data.n_alternatives == 0)
2341 return 1;
2342
2343 for (c = 0; c < recog_data.n_operands; c++)
2344 {
2345 constraints[c] = recog_data.constraints[c];
2346 matching_operands[c] = -1;
2347 }
2348
2349 do
2350 {
2351 int opno;
2352 int lose = 0;
2353 funny_match_index = 0;
2354
2355 for (opno = 0; opno < recog_data.n_operands; opno++)
2356 {
2357 rtx op = recog_data.operand[opno];
2358 enum machine_mode mode = GET_MODE (op);
2359 const char *p = constraints[opno];
2360 int offset = 0;
2361 int win = 0;
2362 int val;
2363
2364 earlyclobber[opno] = 0;
2365
2366 /* A unary operator may be accepted by the predicate, but it
2367 is irrelevant for matching constraints. */
2368 if (GET_RTX_CLASS (GET_CODE (op)) == '1')
2369 op = XEXP (op, 0);
2370
2371 if (GET_CODE (op) == SUBREG)
2372 {
2373 if (GET_CODE (SUBREG_REG (op)) == REG
2374 && REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER)
2375 offset = subreg_regno_offset (REGNO (SUBREG_REG (op)),
2376 GET_MODE (SUBREG_REG (op)),
2377 SUBREG_BYTE (op),
2378 GET_MODE (op));
2379 op = SUBREG_REG (op);
2380 }
2381
2382 /* An empty constraint or empty alternative
2383 allows anything which matched the pattern. */
2384 if (*p == 0 || *p == ',')
2385 win = 1;
2386
2387 while (*p && (c = *p++) != ',')
2388 switch (c)
2389 {
2390 case '?': case '!': case '*': case '%':
2391 case '=': case '+':
2392 break;
2393
2394 case '#':
2395 /* Ignore rest of this alternative as far as
2396 constraint checking is concerned. */
2397 while (*p && *p != ',')
2398 p++;
2399 break;
2400
2401 case '&':
2402 earlyclobber[opno] = 1;
2403 break;
2404
2405 case '0': case '1': case '2': case '3': case '4':
2406 case '5': case '6': case '7': case '8': case '9':
2407 {
2408 /* This operand must be the same as a previous one.
2409 This kind of constraint is used for instructions such
2410 as add when they take only two operands.
2411
2412 Note that the lower-numbered operand is passed first.
2413
2414 If we are not testing strictly, assume that this
2415 constraint will be satisfied. */
2416
2417 char *end;
2418 int match;
2419
2420 match = strtoul (p - 1, &end, 10);
2421 p = end;
2422
2423 if (strict < 0)
2424 val = 1;
2425 else
2426 {
2427 rtx op1 = recog_data.operand[match];
2428 rtx op2 = recog_data.operand[opno];
2429
2430 /* A unary operator may be accepted by the predicate,
2431 but it is irrelevant for matching constraints. */
2432 if (GET_RTX_CLASS (GET_CODE (op1)) == '1')
2433 op1 = XEXP (op1, 0);
2434 if (GET_RTX_CLASS (GET_CODE (op2)) == '1')
2435 op2 = XEXP (op2, 0);
2436
2437 val = operands_match_p (op1, op2);
2438 }
2439
2440 matching_operands[opno] = match;
2441 matching_operands[match] = opno;
2442
2443 if (val != 0)
2444 win = 1;
2445
2446 /* If output is *x and input is *--x, arrange later
2447 to change the output to *--x as well, since the
2448 output op is the one that will be printed. */
2449 if (val == 2 && strict > 0)
2450 {
2451 funny_match[funny_match_index].this = opno;
2452 funny_match[funny_match_index++].other = match;
2453 }
2454 }
2455 break;
2456
2457 case 'p':
2458 /* p is used for address_operands. When we are called by
2459 gen_reload, no one will have checked that the address is
2460 strictly valid, i.e., that all pseudos requiring hard regs
2461 have gotten them. */
2462 if (strict <= 0
2463 || (strict_memory_address_p (recog_data.operand_mode[opno],
2464 op)))
2465 win = 1;
2466 break;
2467
2468 /* No need to check general_operand again;
2469 it was done in insn-recog.c. */
2470 case 'g':
2471 /* Anything goes unless it is a REG and really has a hard reg
2472 but the hard reg is not in the class GENERAL_REGS. */
2473 if (strict < 0
2474 || GENERAL_REGS == ALL_REGS
2475 || GET_CODE (op) != REG
2476 || (reload_in_progress
2477 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2478 || reg_fits_class_p (op, GENERAL_REGS, offset, mode))
2479 win = 1;
2480 break;
2481
2482 case 'X':
2483 /* This is used for a MATCH_SCRATCH in the cases when
2484 we don't actually need anything. So anything goes
2485 any time. */
2486 win = 1;
2487 break;
2488
2489 case 'm':
2490 if (GET_CODE (op) == MEM
2491 /* Before reload, accept what reload can turn into mem. */
2492 || (strict < 0 && CONSTANT_P (op))
2493 /* During reload, accept a pseudo */
2494 || (reload_in_progress && GET_CODE (op) == REG
2495 && REGNO (op) >= FIRST_PSEUDO_REGISTER))
2496 win = 1;
2497 break;
2498
2499 case '<':
2500 if (GET_CODE (op) == MEM
2501 && (GET_CODE (XEXP (op, 0)) == PRE_DEC
2502 || GET_CODE (XEXP (op, 0)) == POST_DEC))
2503 win = 1;
2504 break;
2505
2506 case '>':
2507 if (GET_CODE (op) == MEM
2508 && (GET_CODE (XEXP (op, 0)) == PRE_INC
2509 || GET_CODE (XEXP (op, 0)) == POST_INC))
2510 win = 1;
2511 break;
2512
2513 case 'E':
2514#ifndef REAL_ARITHMETIC
2515 /* Match any CONST_DOUBLE, but only if
2516 we can examine the bits of it reliably. */
2517 if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
2518 || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
2519 && GET_MODE (op) != VOIDmode && ! flag_pretend_float)
2520 break;
2521#endif
2522 if (GET_CODE (op) == CONST_DOUBLE)
2523 win = 1;
2524 break;
2525
2526 case 'F':
2527 if (GET_CODE (op) == CONST_DOUBLE)
2528 win = 1;
2529 break;
2530
2531 case 'G':
2532 case 'H':
2533 if (GET_CODE (op) == CONST_DOUBLE
2534 && CONST_DOUBLE_OK_FOR_LETTER_P (op, c))
2535 win = 1;
2536 break;
2537
2538 case 's':
2539 if (GET_CODE (op) == CONST_INT
2540 || (GET_CODE (op) == CONST_DOUBLE
2541 && GET_MODE (op) == VOIDmode))
2542 break;
2543 case 'i':
2544 if (CONSTANT_P (op))
2545 win = 1;
2546 break;
2547
2548 case 'n':
2549 if (GET_CODE (op) == CONST_INT
2550 || (GET_CODE (op) == CONST_DOUBLE
2551 && GET_MODE (op) == VOIDmode))
2552 win = 1;
2553 break;
2554
2555 case 'I':
2556 case 'J':
2557 case 'K':
2558 case 'L':
2559 case 'M':
2560 case 'N':
2561 case 'O':
2562 case 'P':
2563 if (GET_CODE (op) == CONST_INT
2564 && CONST_OK_FOR_LETTER_P (INTVAL (op), c))
2565 win = 1;
2566 break;
2567
2568 case 'V':
2569 if (GET_CODE (op) == MEM
2570 && ((strict > 0 && ! offsettable_memref_p (op))
2571 || (strict < 0
2572 && !(CONSTANT_P (op) || GET_CODE (op) == MEM))
2573 || (reload_in_progress
2574 && !(GET_CODE (op) == REG
2575 && REGNO (op) >= FIRST_PSEUDO_REGISTER))))
2576 win = 1;
2577 break;
2578
2579 case 'o':
2580 if ((strict > 0 && offsettable_memref_p (op))
2581 || (strict == 0 && offsettable_nonstrict_memref_p (op))
2582 /* Before reload, accept what reload can handle. */
2583 || (strict < 0
2584 && (CONSTANT_P (op) || GET_CODE (op) == MEM))
2585 /* During reload, accept a pseudo */
2586 || (reload_in_progress && GET_CODE (op) == REG
2587 && REGNO (op) >= FIRST_PSEUDO_REGISTER))
2588 win = 1;
2589 break;
2590
2591 default:
2592 {
2593 enum reg_class class;
2594
2595 class = (c == 'r' ? GENERAL_REGS : REG_CLASS_FROM_LETTER (c));
2596 if (class != NO_REGS)
2597 {
2598 if (strict < 0
2599 || (strict == 0
2600 && GET_CODE (op) == REG
2601 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2602 || (strict == 0 && GET_CODE (op) == SCRATCH)
2603 || (GET_CODE (op) == REG
2604 && reg_fits_class_p (op, class, offset, mode)))
2605 win = 1;
2606 }
2607#ifdef EXTRA_CONSTRAINT
2608 else if (EXTRA_CONSTRAINT (op, c))
2609 win = 1;
2610#endif
2611 break;
2612 }
2613 }
2614
2615 constraints[opno] = p;
2616 /* If this operand did not win somehow,
2617 this alternative loses. */
2618 if (! win)
2619 lose = 1;
2620 }
2621 /* This alternative won; the operands are ok.
2622 Change whichever operands this alternative says to change. */
2623 if (! lose)
2624 {
2625 int opno, eopno;
2626
2627 /* See if any earlyclobber operand conflicts with some other
2628 operand. */
2629
2630 if (strict > 0)
2631 for (eopno = 0; eopno < recog_data.n_operands; eopno++)
2632 /* Ignore earlyclobber operands now in memory,
2633 because we would often report failure when we have
2634 two memory operands, one of which was formerly a REG. */
2635 if (earlyclobber[eopno]
2636 && GET_CODE (recog_data.operand[eopno]) == REG)
2637 for (opno = 0; opno < recog_data.n_operands; opno++)
2638 if ((GET_CODE (recog_data.operand[opno]) == MEM
2639 || recog_data.operand_type[opno] != OP_OUT)
2640 && opno != eopno
2641 /* Ignore things like match_operator operands. */
2642 && *recog_data.constraints[opno] != 0
2643 && ! (matching_operands[opno] == eopno
2644 && operands_match_p (recog_data.operand[opno],
2645 recog_data.operand[eopno]))
2646 && ! safe_from_earlyclobber (recog_data.operand[opno],
2647 recog_data.operand[eopno]))
2648 lose = 1;
2649
2650 if (! lose)
2651 {
2652 while (--funny_match_index >= 0)
2653 {
2654 recog_data.operand[funny_match[funny_match_index].other]
2655 = recog_data.operand[funny_match[funny_match_index].this];
2656 }
2657
2658 return 1;
2659 }
2660 }
2661
2662 which_alternative++;
2663 }
2664 while (which_alternative < recog_data.n_alternatives);
2665
2666 which_alternative = -1;
2667 /* If we are about to reject this, but we are not to test strictly,
2668 try a very loose test. Only return failure if it fails also. */
2669 if (strict == 0)
2670 return constrain_operands (-1);
2671 else
2672 return 0;
2673}
2674
2675/* Return 1 iff OPERAND (assumed to be a REG rtx)
2676 is a hard reg in class CLASS when its regno is offset by OFFSET
2677 and changed to mode MODE.
2678 If REG occupies multiple hard regs, all of them must be in CLASS. */
2679
2680int
2681reg_fits_class_p (operand, class, offset, mode)
2682 rtx operand;
2683 enum reg_class class;
2684 int offset;
2685 enum machine_mode mode;
2686{
2687 int regno = REGNO (operand);
2688 if (regno < FIRST_PSEUDO_REGISTER
2689 && TEST_HARD_REG_BIT (reg_class_contents[(int) class],
2690 regno + offset))
2691 {
2692 int sr;
2693 regno += offset;
2694 for (sr = HARD_REGNO_NREGS (regno, mode) - 1;
2695 sr > 0; sr--)
2696 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
2697 regno + sr))
2698 break;
2699 return sr == 0;
2700 }
2701
2702 return 0;
2703}
2704
2705
2706/* Split single instruction. Helper function for split_all_insns.
2707 Return last insn in the sequence if successful, or NULL if unsuccessful. */
2708static rtx
2709split_insn (insn)
2710 rtx insn;
2711{
2712 rtx set;
2713 if (!INSN_P (insn))
2714 ;
2715 /* Don't split no-op move insns. These should silently
2716 disappear later in final. Splitting such insns would
2717 break the code that handles REG_NO_CONFLICT blocks. */
2718
2719 else if ((set = single_set (insn)) != NULL && set_noop_p (set))
2720 {
2721 /* Nops get in the way while scheduling, so delete them
2722 now if register allocation has already been done. It
2723 is too risky to try to do this before register
2724 allocation, and there are unlikely to be very many
2725 nops then anyways. */
2726 if (reload_completed)
2727 {
2728 PUT_CODE (insn, NOTE);
2729 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2730 NOTE_SOURCE_FILE (insn) = 0;
2731 }
2732 }
2733 else
2734 {
2735 /* Split insns here to get max fine-grain parallelism. */
2736 rtx first = PREV_INSN (insn);
2737 rtx last = try_split (PATTERN (insn), insn, 1);
2738
2739 if (last != insn)
2740 {
2741 /* try_split returns the NOTE that INSN became. */
2742 PUT_CODE (insn, NOTE);
2743 NOTE_SOURCE_FILE (insn) = 0;
2744 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2745
2746 /* ??? Coddle to md files that generate subregs in post-
2747 reload splitters instead of computing the proper
2748 hard register. */
2749 if (reload_completed && first != last)
2750 {
2751 first = NEXT_INSN (first);
2752 while (1)
2753 {
2754 if (INSN_P (first))
2755 cleanup_subreg_operands (first);
2756 if (first == last)
2757 break;
2758 first = NEXT_INSN (first);
2759 }
2760 }
2761 return last;
2762 }
2763 }
2764 return NULL_RTX;
2765}
2766/* Split all insns in the function. If UPD_LIFE, update life info after. */
2767
2768void
2769split_all_insns (upd_life)
2770 int upd_life;
2771{
2772 sbitmap blocks;
2773 int changed;
2774 int i;
2775
2776 blocks = sbitmap_alloc (n_basic_blocks);
2777 sbitmap_zero (blocks);
2778 changed = 0;
2779
2780 for (i = n_basic_blocks - 1; i >= 0; --i)
2781 {
2782 basic_block bb = BASIC_BLOCK (i);
2783 rtx insn, next;
2784
2785 for (insn = bb->head; insn ; insn = next)
2786 {
2787 rtx last;
2788
2789 /* Can't use `next_real_insn' because that might go across
2790 CODE_LABELS and short-out basic blocks. */
2791 next = NEXT_INSN (insn);
2792 last = split_insn (insn);
2793 if (last)
2794 {
2795 /* The split sequence may include barrier, but the
2796 BB boundary we are interested in will be set to previous
2797 one. */
2798
2799 while (GET_CODE (last) == BARRIER)
2800 last = PREV_INSN (last);
2801 SET_BIT (blocks, i);
2802 changed = 1;
2803 insn = last;
2804 }
2805
2806 if (insn == bb->end)
2807 break;
2808 }
2809
2810 if (insn == NULL)
2811 abort ();
2812 }
2813
2814 if (changed)
2815 {
2816 find_many_sub_basic_blocks (blocks);
2817 }
2818
2819 if (changed && upd_life)
2820 {
2821 count_or_remove_death_notes (blocks, 1);
2822 update_life_info (blocks, UPDATE_LIFE_LOCAL, PROP_DEATH_NOTES);
2823 }
2824#ifdef ENABLE_CHECKING
2825 verify_flow_info ();
2826#endif
2827
2828 sbitmap_free (blocks);
2829}
2830
2831/* Same as split_all_insns, but do not expect CFG to be available.
2832 Used by machine depedent reorg passes. */
2833
2834void
2835split_all_insns_noflow ()
2836{
2837 rtx next, insn;
2838
2839 for (insn = get_insns (); insn; insn = next)
2840 {
2841 next = NEXT_INSN (insn);
2842 split_insn (insn);
2843 }
2844 return;
2845}
2846
2847
2848#ifdef HAVE_peephole2
2849struct peep2_insn_data
2850{
2851 rtx insn;
2852 regset live_before;
2853};
2854
2855static struct peep2_insn_data peep2_insn_data[MAX_INSNS_PER_PEEP2 + 1];
2856static int peep2_current;
2857
2858/* A non-insn marker indicating the last insn of the block.
2859 The live_before regset for this element is correct, indicating
2860 global_live_at_end for the block. */
2861#define PEEP2_EOB pc_rtx
2862
2863/* Return the Nth non-note insn after `current', or return NULL_RTX if it
2864 does not exist. Used by the recognizer to find the next insn to match
2865 in a multi-insn pattern. */
2866
2867rtx
2868peep2_next_insn (n)
2869 int n;
2870{
2871 if (n >= MAX_INSNS_PER_PEEP2 + 1)
2872 abort ();
2873
2874 n += peep2_current;
2875 if (n >= MAX_INSNS_PER_PEEP2 + 1)
2876 n -= MAX_INSNS_PER_PEEP2 + 1;
2877
2878 if (peep2_insn_data[n].insn == PEEP2_EOB)
2879 return NULL_RTX;
2880 return peep2_insn_data[n].insn;
2881}
2882
2883/* Return true if REGNO is dead before the Nth non-note insn
2884 after `current'. */
2885
2886int
2887peep2_regno_dead_p (ofs, regno)
2888 int ofs;
2889 int regno;
2890{
2891 if (ofs >= MAX_INSNS_PER_PEEP2 + 1)
2892 abort ();
2893
2894 ofs += peep2_current;
2895 if (ofs >= MAX_INSNS_PER_PEEP2 + 1)
2896 ofs -= MAX_INSNS_PER_PEEP2 + 1;
2897
2898 if (peep2_insn_data[ofs].insn == NULL_RTX)
2899 abort ();
2900
2901 return ! REGNO_REG_SET_P (peep2_insn_data[ofs].live_before, regno);
2902}
2903
2904/* Similarly for a REG. */
2905
2906int
2907peep2_reg_dead_p (ofs, reg)
2908 int ofs;
2909 rtx reg;
2910{
2911 int regno, n;
2912
2913 if (ofs >= MAX_INSNS_PER_PEEP2 + 1)
2914 abort ();
2915
2916 ofs += peep2_current;
2917 if (ofs >= MAX_INSNS_PER_PEEP2 + 1)
2918 ofs -= MAX_INSNS_PER_PEEP2 + 1;
2919
2920 if (peep2_insn_data[ofs].insn == NULL_RTX)
2921 abort ();
2922
2923 regno = REGNO (reg);
2924 n = HARD_REGNO_NREGS (regno, GET_MODE (reg));
2925 while (--n >= 0)
2926 if (REGNO_REG_SET_P (peep2_insn_data[ofs].live_before, regno + n))
2927 return 0;
2928 return 1;
2929}
2930
2931/* Try to find a hard register of mode MODE, matching the register class in
2932 CLASS_STR, which is available at the beginning of insn CURRENT_INSN and
2933 remains available until the end of LAST_INSN. LAST_INSN may be NULL_RTX,
2934 in which case the only condition is that the register must be available
2935 before CURRENT_INSN.
2936 Registers that already have bits set in REG_SET will not be considered.
2937
2938 If an appropriate register is available, it will be returned and the
2939 corresponding bit(s) in REG_SET will be set; otherwise, NULL_RTX is
2940 returned. */
2941
2942rtx
2943peep2_find_free_register (from, to, class_str, mode, reg_set)
2944 int from, to;
2945 const char *class_str;
2946 enum machine_mode mode;
2947 HARD_REG_SET *reg_set;
2948{
2949 static int search_ofs;
2950 enum reg_class class;
2951 HARD_REG_SET live;
2952 int i;
2953
2954 if (from >= MAX_INSNS_PER_PEEP2 + 1 || to >= MAX_INSNS_PER_PEEP2 + 1)
2955 abort ();
2956
2957 from += peep2_current;
2958 if (from >= MAX_INSNS_PER_PEEP2 + 1)
2959 from -= MAX_INSNS_PER_PEEP2 + 1;
2960 to += peep2_current;
2961 if (to >= MAX_INSNS_PER_PEEP2 + 1)
2962 to -= MAX_INSNS_PER_PEEP2 + 1;
2963
2964 if (peep2_insn_data[from].insn == NULL_RTX)
2965 abort ();
2966 REG_SET_TO_HARD_REG_SET (live, peep2_insn_data[from].live_before);
2967
2968 while (from != to)
2969 {
2970 HARD_REG_SET this_live;
2971
2972 if (++from >= MAX_INSNS_PER_PEEP2 + 1)
2973 from = 0;
2974 if (peep2_insn_data[from].insn == NULL_RTX)
2975 abort ();
2976 REG_SET_TO_HARD_REG_SET (this_live, peep2_insn_data[from].live_before);
2977 IOR_HARD_REG_SET (live, this_live);
2978 }
2979
2980 class = (class_str[0] == 'r' ? GENERAL_REGS
2981 : REG_CLASS_FROM_LETTER (class_str[0]));
2982
2983 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2984 {
2985 int raw_regno, regno, success, j;
2986
2987 /* Distribute the free registers as much as possible. */
2988 raw_regno = search_ofs + i;
2989 if (raw_regno >= FIRST_PSEUDO_REGISTER)
2990 raw_regno -= FIRST_PSEUDO_REGISTER;
2991#ifdef REG_ALLOC_ORDER
2992 regno = reg_alloc_order[raw_regno];
2993#else
2994 regno = raw_regno;
2995#endif
2996
2997 /* Don't allocate fixed registers. */
2998 if (fixed_regs[regno])
2999 continue;
3000 /* Make sure the register is of the right class. */
3001 if (! TEST_HARD_REG_BIT (reg_class_contents[class], regno))
3002 continue;
3003 /* And can support the mode we need. */
3004 if (! HARD_REGNO_MODE_OK (regno, mode))
3005 continue;
3006 /* And that we don't create an extra save/restore. */
3007 if (! call_used_regs[regno] && ! regs_ever_live[regno])
3008 continue;
3009 /* And we don't clobber traceback for noreturn functions. */
3010 if ((regno == FRAME_POINTER_REGNUM || regno == HARD_FRAME_POINTER_REGNUM)
3011 && (! reload_completed || frame_pointer_needed))
3012 continue;
3013
3014 success = 1;
3015 for (j = HARD_REGNO_NREGS (regno, mode) - 1; j >= 0; j--)
3016 {
3017 if (TEST_HARD_REG_BIT (*reg_set, regno + j)
3018 || TEST_HARD_REG_BIT (live, regno + j))
3019 {
3020 success = 0;
3021 break;
3022 }
3023 }
3024 if (success)
3025 {
3026 for (j = HARD_REGNO_NREGS (regno, mode) - 1; j >= 0; j--)
3027 SET_HARD_REG_BIT (*reg_set, regno + j);
3028
3029 /* Start the next search with the next register. */
3030 if (++raw_regno >= FIRST_PSEUDO_REGISTER)
3031 raw_regno = 0;
3032 search_ofs = raw_regno;
3033
3034 return gen_rtx_REG (mode, regno);
3035 }
3036 }
3037
3038 search_ofs = 0;
3039 return NULL_RTX;
3040}
3041
3042/* Perform the peephole2 optimization pass. */
3043
3044void
3045peephole2_optimize (dump_file)
3046 FILE *dump_file ATTRIBUTE_UNUSED;
3047{
3048 regset_head rs_heads[MAX_INSNS_PER_PEEP2 + 2];
3049 rtx insn, prev;
3050 regset live;
3051 int i, b;
3052#ifdef HAVE_conditional_execution
3053 sbitmap blocks;
3054 bool changed;
3055#endif
3056 bool do_cleanup_cfg = false;
3057 bool do_rebuild_jump_labels = false;
3058
3059 /* Initialize the regsets we're going to use. */
3060 for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
3061 peep2_insn_data[i].live_before = INITIALIZE_REG_SET (rs_heads[i]);
3062 live = INITIALIZE_REG_SET (rs_heads[i]);
3063
3064#ifdef HAVE_conditional_execution
3065 blocks = sbitmap_alloc (n_basic_blocks);
3066 sbitmap_zero (blocks);
3067 changed = false;
3068#else
3069 count_or_remove_death_notes (NULL, 1);
3070#endif
3071
3072 for (b = n_basic_blocks - 1; b >= 0; --b)
3073 {
3074 basic_block bb = BASIC_BLOCK (b);
3075 struct propagate_block_info *pbi;
3076
3077 /* Indicate that all slots except the last holds invalid data. */
3078 for (i = 0; i < MAX_INSNS_PER_PEEP2; ++i)
3079 peep2_insn_data[i].insn = NULL_RTX;
3080
3081 /* Indicate that the last slot contains live_after data. */
3082 peep2_insn_data[MAX_INSNS_PER_PEEP2].insn = PEEP2_EOB;
3083 peep2_current = MAX_INSNS_PER_PEEP2;
3084
3085 /* Start up propagation. */
3086 COPY_REG_SET (live, bb->global_live_at_end);
3087 COPY_REG_SET (peep2_insn_data[MAX_INSNS_PER_PEEP2].live_before, live);
3088
3089#ifdef HAVE_conditional_execution
3090 pbi = init_propagate_block_info (bb, live, NULL, NULL, 0);
3091#else
3092 pbi = init_propagate_block_info (bb, live, NULL, NULL, PROP_DEATH_NOTES);
3093#endif
3094
3095 for (insn = bb->end; ; insn = prev)
3096 {
3097 prev = PREV_INSN (insn);
3098 if (INSN_P (insn))
3099 {
3100 rtx try, before_try, x;
3101 int match_len;
3102 rtx note;
3103
3104 /* Record this insn. */
3105 if (--peep2_current < 0)
3106 peep2_current = MAX_INSNS_PER_PEEP2;
3107 peep2_insn_data[peep2_current].insn = insn;
3108 propagate_one_insn (pbi, insn);
3109 COPY_REG_SET (peep2_insn_data[peep2_current].live_before, live);
3110
3111 /* Match the peephole. */
3112 try = peephole2_insns (PATTERN (insn), insn, &match_len);
3113 if (try != NULL)
3114 {
3115 /* If we are splitting a CALL_INSN, look for the CALL_INSN
3116 in SEQ and copy our CALL_INSN_FUNCTION_USAGE and other
3117 cfg-related call notes. */
3118 for (i = 0; i <= match_len; ++i)
3119 {
3120 int j, k;
3121 rtx old_insn, new_insn, note;
3122
3123 j = i + peep2_current;
3124 if (j >= MAX_INSNS_PER_PEEP2 + 1)
3125 j -= MAX_INSNS_PER_PEEP2 + 1;
3126 old_insn = peep2_insn_data[j].insn;
3127 if (GET_CODE (old_insn) != CALL_INSN)
3128 continue;
3129
3130 new_insn = NULL_RTX;
3131 if (GET_CODE (try) == SEQUENCE)
3132 for (k = XVECLEN (try, 0) - 1; k >= 0; k--)
3133 {
3134 rtx x = XVECEXP (try, 0, k);
3135 if (GET_CODE (x) == CALL_INSN)
3136 {
3137 new_insn = x;
3138 break;
3139 }
3140 }
3141 else if (GET_CODE (try) == CALL_INSN)
3142 new_insn = try;
3143 if (! new_insn)
3144 abort ();
3145
3146 CALL_INSN_FUNCTION_USAGE (new_insn)
3147 = CALL_INSN_FUNCTION_USAGE (old_insn);
3148
3149 for (note = REG_NOTES (old_insn);
3150 note;
3151 note = XEXP (note, 1))
3152 switch (REG_NOTE_KIND (note))
3153 {
3154 case REG_NORETURN:
3155 case REG_SETJMP:
3156 case REG_ALWAYS_RETURN:
3157 REG_NOTES (new_insn)
3158 = gen_rtx_EXPR_LIST (REG_NOTE_KIND (note),
3159 XEXP (note, 0),
3160 REG_NOTES (new_insn));
3161 default:
3162 /* Discard all other reg notes. */
3163 break;
3164 }
3165
3166 /* Croak if there is another call in the sequence. */
3167 while (++i <= match_len)
3168 {
3169 j = i + peep2_current;
3170 if (j >= MAX_INSNS_PER_PEEP2 + 1)
3171 j -= MAX_INSNS_PER_PEEP2 + 1;
3172 old_insn = peep2_insn_data[j].insn;
3173 if (GET_CODE (old_insn) == CALL_INSN)
3174 abort ();
3175 }
3176 break;
3177 }
3178
3179 i = match_len + peep2_current;
3180 if (i >= MAX_INSNS_PER_PEEP2 + 1)
3181 i -= MAX_INSNS_PER_PEEP2 + 1;
3182
3183 note = find_reg_note (peep2_insn_data[i].insn,
3184 REG_EH_REGION, NULL_RTX);
3185
3186 /* Replace the old sequence with the new. */
3187 try = emit_insn_after (try, peep2_insn_data[i].insn);
3188 before_try = PREV_INSN (insn);
3189 delete_insn_chain (insn, peep2_insn_data[i].insn);
3190
3191 /* Re-insert the EH_REGION notes. */
3192 if (note)
3193 {
3194 edge eh_edge;
3195
3196 for (eh_edge = bb->succ; eh_edge
3197 ; eh_edge = eh_edge->succ_next)
3198 if (eh_edge->flags & EDGE_EH)
3199 break;
3200
3201 for (x = try ; x != before_try ; x = PREV_INSN (x))
3202 if (GET_CODE (x) == CALL_INSN
3203 || (flag_non_call_exceptions
3204 && may_trap_p (PATTERN (x))
3205 && !find_reg_note (x, REG_EH_REGION, NULL)))
3206 {
3207 REG_NOTES (x)
3208 = gen_rtx_EXPR_LIST (REG_EH_REGION,
3209 XEXP (note, 0),
3210 REG_NOTES (x));
3211
3212 if (x != bb->end && eh_edge)
3213 {
3214 edge nfte, nehe;
3215 int flags;
3216
3217 nfte = split_block (bb, x);
3218 flags = EDGE_EH | EDGE_ABNORMAL;
3219 if (GET_CODE (x) == CALL_INSN)
3220 flags |= EDGE_ABNORMAL_CALL;
3221 nehe = make_edge (nfte->src, eh_edge->dest,
3222 flags);
3223
3224 nehe->probability = eh_edge->probability;
3225 nfte->probability
3226 = REG_BR_PROB_BASE - nehe->probability;
3227
3228 do_cleanup_cfg |= purge_dead_edges (nfte->dest);
3229#ifdef HAVE_conditional_execution
3230 SET_BIT (blocks, nfte->dest->index);
3231 changed = true;
3232#endif
3233 bb = nfte->src;
3234 eh_edge = nehe;
3235 }
3236 }
3237
3238 /* Converting possibly trapping insn to non-trapping is
3239 possible. Zap dummy outgoing edges. */
3240 do_cleanup_cfg |= purge_dead_edges (bb);
3241 }
3242
3243#ifdef HAVE_conditional_execution
3244 /* With conditional execution, we cannot back up the
3245 live information so easily, since the conditional
3246 death data structures are not so self-contained.
3247 So record that we've made a modification to this
3248 block and update life information at the end. */
3249 SET_BIT (blocks, b);
3250 changed = true;
3251
3252 for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
3253 peep2_insn_data[i].insn = NULL_RTX;
3254 peep2_insn_data[peep2_current].insn = PEEP2_EOB;
3255#else
3256 /* Back up lifetime information past the end of the
3257 newly created sequence. */
3258 if (++i >= MAX_INSNS_PER_PEEP2 + 1)
3259 i = 0;
3260 COPY_REG_SET (live, peep2_insn_data[i].live_before);
3261
3262 /* Update life information for the new sequence. */
3263 x = try;
3264 do
3265 {
3266 if (INSN_P (x))
3267 {
3268 if (--i < 0)
3269 i = MAX_INSNS_PER_PEEP2;
3270 peep2_insn_data[i].insn = x;
3271 propagate_one_insn (pbi, x);
3272 COPY_REG_SET (peep2_insn_data[i].live_before, live);
3273 }
3274 x = PREV_INSN (x);
3275 }
3276 while (x != prev);
3277
3278 /* ??? Should verify that LIVE now matches what we
3279 had before the new sequence. */
3280
3281 peep2_current = i;
3282#endif
3283
3284 /* If we generated a jump instruction, it won't have
3285 JUMP_LABEL set. Recompute after we're done. */
3286 for (x = try; x != before_try; x = PREV_INSN (x))
3287 if (GET_CODE (x) == JUMP_INSN)
3288 {
3289 do_rebuild_jump_labels = true;
3290 break;
3291 }
3292 }
3293 }
3294
3295 if (insn == bb->head)
3296 break;
3297 }
3298
3299 free_propagate_block_info (pbi);
3300 }
3301
3302 for (i = 0; i < MAX_INSNS_PER_PEEP2 + 1; ++i)
3303 FREE_REG_SET (peep2_insn_data[i].live_before);
3304 FREE_REG_SET (live);
3305
3306 if (do_rebuild_jump_labels)
3307 rebuild_jump_labels (get_insns ());
3308
3309 /* If we eliminated EH edges, we may be able to merge blocks. Further,
3310 we've changed global life since exception handlers are no longer
3311 reachable. */
3312 if (do_cleanup_cfg)
3313 {
3314 cleanup_cfg (0);
3315 update_life_info (0, UPDATE_LIFE_GLOBAL_RM_NOTES, PROP_DEATH_NOTES);
3316 }
3317#ifdef HAVE_conditional_execution
3318 else
3319 {
3320 count_or_remove_death_notes (blocks, 1);
3321 update_life_info (blocks, UPDATE_LIFE_LOCAL, PROP_DEATH_NOTES);
3322 }
3323 sbitmap_free (blocks);
3324#endif
3325}
3326#endif /* HAVE_peephole2 */
Note: See TracBrowser for help on using the repository browser.