]> gcc.gnu.org Git - gcc.git/blame - gcc/recog.c
cp-tree.def (CLEANUP_STMT): New node.
[gcc.git] / gcc / recog.c
CommitLineData
2055cea7 1/* Subroutines used by or related to instruction recognition.
1f06ee8d 2 Copyright (C) 1987, 1988, 91-98, 1999 Free Software Foundation, Inc.
2055cea7
RK
3
4This file is part of GNU CC.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU CC; see the file COPYING. If not, write to
e99215a3
RK
18the Free Software Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
2055cea7
RK
20
21
22#include "config.h"
670ee920 23#include "system.h"
38a448ca 24#include "rtl.h"
2055cea7
RK
25#include "insn-config.h"
26#include "insn-attr.h"
27#include "insn-flags.h"
28#include "insn-codes.h"
29#include "recog.h"
30#include "regs.h"
31#include "hard-reg-set.h"
49ad7cfa 32#include "function.h"
2055cea7
RK
33#include "flags.h"
34#include "real.h"
7f7f8214 35#include "toplev.h"
ca545bb5 36#include "basic-block.h"
ede7cd44
RH
37#include "output.h"
38#include "resource.h"
2055cea7
RK
39
40#ifndef STACK_PUSH_CODE
41#ifdef STACK_GROWS_DOWNWARD
42#define STACK_PUSH_CODE PRE_DEC
43#else
44#define STACK_PUSH_CODE PRE_INC
45#endif
46#endif
47
6fbe9bd8
RH
48#ifndef STACK_POP_CODE
49#ifdef STACK_GROWS_DOWNWARD
50#define STACK_POP_CODE POST_INC
51#else
52#define STACK_POP_CODE POST_DEC
53#endif
54#endif
55
61719ba7
BS
56static void validate_replace_rtx_1 PROTO((rtx *, rtx, rtx, rtx));
57static rtx *find_single_use_1 PROTO((rtx, rtx *));
58static rtx *find_constant_term_loc PROTO((rtx *));
59static int insn_invalid_p PROTO((rtx));
2055cea7
RK
60
61/* Nonzero means allow operands to be volatile.
62 This should be 0 if you are generating rtl, such as if you are calling
63 the functions in optabs.c and expmed.c (most of the time).
64 This should be 1 if all valid insns need to be recognized,
65 such as in regclass.c and final.c and reload.c.
66
67 init_recog and init_recog_no_volatile are responsible for setting this. */
68
69int volatile_ok;
70
0eadeb15
BS
71/* The next variables are set up by extract_insn. The first four of them
72 are also set up during insn_extract. */
0a578fee
BS
73
74/* Indexed by N, gives value of operand N. */
75rtx recog_operand[MAX_RECOG_OPERANDS];
76
77/* Indexed by N, gives location where operand N was found. */
78rtx *recog_operand_loc[MAX_RECOG_OPERANDS];
79
80/* Indexed by N, gives location where the Nth duplicate-appearance of
81 an operand was found. This is something that matched MATCH_DUP. */
82rtx *recog_dup_loc[MAX_RECOG_OPERANDS];
83
84/* Indexed by N, gives the operand number that was duplicated in the
85 Nth duplicate-appearance of an operand. */
86char recog_dup_num[MAX_RECOG_OPERANDS];
87
0a578fee
BS
88/* The number of operands of the insn. */
89int recog_n_operands;
90
91/* The number of MATCH_DUPs in the insn. */
92int recog_n_dups;
93
94/* The number of alternatives in the constraints for the insn. */
95int recog_n_alternatives;
96
97/* Indexed by N, gives the mode of operand N. */
98enum machine_mode recog_operand_mode[MAX_RECOG_OPERANDS];
99
100/* Indexed by N, gives the constraint string for operand N. */
9b3142b3 101const char *recog_constraints[MAX_RECOG_OPERANDS];
0a578fee 102
0eadeb15
BS
103/* Indexed by N, gives the type (in, out, inout) for operand N. */
104enum op_type recog_op_type[MAX_RECOG_OPERANDS];
105
0a578fee
BS
106#ifndef REGISTER_CONSTRAINTS
107/* Indexed by N, nonzero if operand N should be an address. */
108char recog_operand_address_p[MAX_RECOG_OPERANDS];
109#endif
110
f62a15e3
BS
111/* Contains a vector of operand_alternative structures for every operand.
112 Set up by preprocess_constraints. */
113struct operand_alternative recog_op_alt[MAX_RECOG_OPERANDS][MAX_RECOG_ALTERNATIVES];
114
2055cea7
RK
115/* On return from `constrain_operands', indicate which alternative
116 was satisfied. */
117
118int which_alternative;
119
120/* Nonzero after end of reload pass.
121 Set to 1 or 0 by toplev.c.
122 Controls the significance of (SUBREG (MEM)). */
123
124int reload_completed;
125
126/* Initialize data used by the function `recog'.
127 This must be called once in the compilation of a function
128 before any insn recognition may be done in the function. */
129
130void
131init_recog_no_volatile ()
132{
133 volatile_ok = 0;
134}
135
e0069e43 136void
2055cea7
RK
137init_recog ()
138{
139 volatile_ok = 1;
140}
141
142/* Try recognizing the instruction INSN,
143 and return the code number that results.
9faa82d8 144 Remember the code so that repeated calls do not
2055cea7
RK
145 need to spend the time for actual rerecognition.
146
147 This function is the normal interface to instruction recognition.
148 The automatically-generated function `recog' is normally called
149 through this one. (The only exception is in combine.c.) */
150
151int
152recog_memoized (insn)
153 rtx insn;
154{
155 if (INSN_CODE (insn) < 0)
9e4223f2 156 INSN_CODE (insn) = recog (PATTERN (insn), insn, NULL_PTR);
2055cea7
RK
157 return INSN_CODE (insn);
158}
159\f
160/* Check that X is an insn-body for an `asm' with operands
161 and that the operands mentioned in it are legitimate. */
162
163int
164check_asm_operands (x)
165 rtx x;
166{
1f06ee8d 167 int noperands;
2055cea7 168 rtx *operands;
9b3142b3 169 const char **constraints;
2055cea7
RK
170 int i;
171
1f06ee8d
RH
172 /* Post-reload, be more strict with things. */
173 if (reload_completed)
174 {
175 /* ??? Doh! We've not got the wrapping insn. Cook one up. */
176 extract_insn (make_insn_raw (x));
177 constrain_operands (1);
178 return which_alternative >= 0;
179 }
180
181 noperands = asm_noperands (x);
2055cea7
RK
182 if (noperands < 0)
183 return 0;
184 if (noperands == 0)
185 return 1;
186
187 operands = (rtx *) alloca (noperands * sizeof (rtx));
9b3142b3 188 constraints = (const char **) alloca (noperands * sizeof (char *));
1f06ee8d
RH
189
190 decode_asm_operands (x, operands, NULL_PTR, constraints, NULL_PTR);
2055cea7
RK
191
192 for (i = 0; i < noperands; i++)
1f06ee8d 193 {
9b3142b3 194 const char *c = constraints[i];
1afbe1c4
RH
195 if (c[0] == '%')
196 c++;
197 if (ISDIGIT ((unsigned char)c[0]) && c[1] == '\0')
1f06ee8d
RH
198 c = constraints[c[0] - '0'];
199
200 if (! asm_operand_ok (operands[i], c))
201 return 0;
202 }
2055cea7
RK
203
204 return 1;
205}
206\f
41a972a9 207/* Static data for the next two routines. */
2055cea7 208
41a972a9
MM
209typedef struct change_t
210{
211 rtx object;
212 int old_code;
213 rtx *loc;
214 rtx old;
215} change_t;
2055cea7 216
41a972a9
MM
217static change_t *changes;
218static int changes_allocated;
2055cea7
RK
219
220static int num_changes = 0;
221
222/* Validate a proposed change to OBJECT. LOC is the location in the rtl for
223 at which NEW will be placed. If OBJECT is zero, no validation is done,
224 the change is simply made.
225
226 Two types of objects are supported: If OBJECT is a MEM, memory_address_p
227 will be called with the address and mode as parameters. If OBJECT is
228 an INSN, CALL_INSN, or JUMP_INSN, the insn will be re-recognized with
229 the change in place.
230
231 IN_GROUP is non-zero if this is part of a group of changes that must be
232 performed as a group. In that case, the changes will be stored. The
233 function `apply_change_group' will validate and apply the changes.
234
235 If IN_GROUP is zero, this is a single change. Try to recognize the insn
236 or validate the memory reference with the change applied. If the result
237 is not valid for the machine, suppress the change and return zero.
238 Otherwise, perform the change and return 1. */
239
240int
241validate_change (object, loc, new, in_group)
242 rtx object;
243 rtx *loc;
244 rtx new;
245 int in_group;
246{
247 rtx old = *loc;
248
249 if (old == new || rtx_equal_p (old, new))
250 return 1;
251
41a972a9 252 if (in_group == 0 && num_changes != 0)
2055cea7
RK
253 abort ();
254
255 *loc = new;
256
257 /* Save the information describing this change. */
41a972a9
MM
258 if (num_changes >= changes_allocated)
259 {
260 if (changes_allocated == 0)
261 /* This value allows for repeated substitutions inside complex
262 indexed addresses, or changes in up to 5 insns. */
263 changes_allocated = MAX_RECOG_OPERANDS * 5;
264 else
265 changes_allocated *= 2;
266
267 changes =
268 (change_t*) xrealloc (changes,
269 sizeof (change_t) * changes_allocated);
270 }
271
272 changes[num_changes].object = object;
273 changes[num_changes].loc = loc;
274 changes[num_changes].old = old;
2055cea7
RK
275
276 if (object && GET_CODE (object) != MEM)
277 {
278 /* Set INSN_CODE to force rerecognition of insn. Save old code in
279 case invalid. */
41a972a9 280 changes[num_changes].old_code = INSN_CODE (object);
2055cea7
RK
281 INSN_CODE (object) = -1;
282 }
283
284 num_changes++;
285
286 /* If we are making a group of changes, return 1. Otherwise, validate the
287 change group we made. */
288
289 if (in_group)
290 return 1;
291 else
292 return apply_change_group ();
293}
294
61719ba7
BS
295/* This subroutine of apply_change_group verifies whether the changes to INSN
296 were valid; i.e. whether INSN can still be recognized. */
297
298static int
299insn_invalid_p (insn)
300 rtx insn;
301{
302 int icode = recog_memoized (insn);
303 int is_asm = icode < 0 && asm_noperands (PATTERN (insn)) >= 0;
304
0eadeb15
BS
305 if (is_asm && ! check_asm_operands (PATTERN (insn)))
306 return 1;
307 if (! is_asm && icode < 0)
61719ba7
BS
308 return 1;
309
310 /* After reload, verify that all constraints are satisfied. */
311 if (reload_completed)
312 {
0eadeb15 313 extract_insn (insn);
61719ba7 314
0eadeb15 315 if (! constrain_operands (1))
61719ba7
BS
316 return 1;
317 }
318
319 return 0;
320}
321
2055cea7
RK
322/* Apply a group of changes previously issued with `validate_change'.
323 Return 1 if all changes are valid, zero otherwise. */
324
325int
326apply_change_group ()
327{
328 int i;
329
330 /* The changes have been applied and all INSN_CODEs have been reset to force
331 rerecognition.
332
333 The changes are valid if we aren't given an object, or if we are
334 given a MEM and it still is a valid address, or if this is in insn
335 and it is recognized. In the latter case, if reload has completed,
336 we also require that the operands meet the constraints for
0eadeb15 337 the insn. */
2055cea7
RK
338
339 for (i = 0; i < num_changes; i++)
340 {
41a972a9 341 rtx object = changes[i].object;
2055cea7
RK
342
343 if (object == 0)
344 continue;
345
346 if (GET_CODE (object) == MEM)
347 {
348 if (! memory_address_p (GET_MODE (object), XEXP (object, 0)))
349 break;
350 }
61719ba7 351 else if (insn_invalid_p (object))
2055cea7
RK
352 {
353 rtx pat = PATTERN (object);
354
355 /* Perhaps we couldn't recognize the insn because there were
356 extra CLOBBERs at the end. If so, try to re-recognize
357 without the last CLOBBER (later iterations will cause each of
358 them to be eliminated, in turn). But don't do this if we
359 have an ASM_OPERAND. */
360 if (GET_CODE (pat) == PARALLEL
361 && GET_CODE (XVECEXP (pat, 0, XVECLEN (pat, 0) - 1)) == CLOBBER
362 && asm_noperands (PATTERN (object)) < 0)
363 {
364 rtx newpat;
365
366 if (XVECLEN (pat, 0) == 2)
367 newpat = XVECEXP (pat, 0, 0);
368 else
369 {
370 int j;
371
c5c76735
JL
372 newpat
373 = gen_rtx_PARALLEL (VOIDmode,
374 gen_rtvec (XVECLEN (pat, 0) - 1));
2055cea7
RK
375 for (j = 0; j < XVECLEN (newpat, 0); j++)
376 XVECEXP (newpat, 0, j) = XVECEXP (pat, 0, j);
377 }
378
379 /* Add a new change to this group to replace the pattern
380 with this new pattern. Then consider this change
381 as having succeeded. The change we added will
382 cause the entire call to fail if things remain invalid.
383
384 Note that this can lose if a later change than the one
385 we are processing specified &XVECEXP (PATTERN (object), 0, X)
386 but this shouldn't occur. */
387
388 validate_change (object, &PATTERN (object), newpat, 1);
389 }
390 else if (GET_CODE (pat) == USE || GET_CODE (pat) == CLOBBER)
391 /* If this insn is a CLOBBER or USE, it is always valid, but is
392 never recognized. */
393 continue;
394 else
395 break;
396 }
397 }
398
399 if (i == num_changes)
400 {
401 num_changes = 0;
402 return 1;
403 }
404 else
405 {
406 cancel_changes (0);
407 return 0;
408 }
409}
410
411/* Return the number of changes so far in the current group. */
412
413int
414num_validated_changes ()
415{
416 return num_changes;
417}
418
419/* Retract the changes numbered NUM and up. */
420
421void
422cancel_changes (num)
423 int num;
424{
425 int i;
426
427 /* Back out all the changes. Do this in the opposite order in which
428 they were made. */
429 for (i = num_changes - 1; i >= num; i--)
430 {
41a972a9
MM
431 *changes[i].loc = changes[i].old;
432 if (changes[i].object && GET_CODE (changes[i].object) != MEM)
433 INSN_CODE (changes[i].object) = changes[i].old_code;
2055cea7
RK
434 }
435 num_changes = num;
436}
437
438/* Replace every occurrence of FROM in X with TO. Mark each change with
439 validate_change passing OBJECT. */
440
441static void
442validate_replace_rtx_1 (loc, from, to, object)
443 rtx *loc;
444 rtx from, to, object;
445{
446 register int i, j;
6f7d635c 447 register const char *fmt;
2055cea7
RK
448 register rtx x = *loc;
449 enum rtx_code code = GET_CODE (x);
450
451 /* X matches FROM if it is the same rtx or they are both referring to the
452 same register in the same mode. Avoid calling rtx_equal_p unless the
453 operands look similar. */
454
455 if (x == from
456 || (GET_CODE (x) == REG && GET_CODE (from) == REG
457 && GET_MODE (x) == GET_MODE (from)
458 && REGNO (x) == REGNO (from))
459 || (GET_CODE (x) == GET_CODE (from) && GET_MODE (x) == GET_MODE (from)
460 && rtx_equal_p (x, from)))
461 {
462 validate_change (object, loc, to, 1);
463 return;
464 }
465
466 /* For commutative or comparison operations, try replacing each argument
467 separately and seeing if we made any changes. If so, put a constant
468 argument last.*/
469 if (GET_RTX_CLASS (code) == '<' || GET_RTX_CLASS (code) == 'c')
470 {
471 int prev_changes = num_changes;
472
473 validate_replace_rtx_1 (&XEXP (x, 0), from, to, object);
474 validate_replace_rtx_1 (&XEXP (x, 1), from, to, object);
475 if (prev_changes != num_changes && CONSTANT_P (XEXP (x, 0)))
476 {
477 validate_change (object, loc,
38a448ca
RH
478 gen_rtx_fmt_ee (GET_RTX_CLASS (code) == 'c' ? code
479 : swap_condition (code),
480 GET_MODE (x), XEXP (x, 1),
481 XEXP (x, 0)),
2055cea7
RK
482 1);
483 x = *loc;
484 code = GET_CODE (x);
485 }
486 }
487
06140bdf
RK
488 /* Note that if CODE's RTX_CLASS is "c" or "<" we will have already
489 done the substitution, otherwise we won't. */
490
2055cea7
RK
491 switch (code)
492 {
493 case PLUS:
38e01259 494 /* If we have a PLUS whose second operand is now a CONST_INT, use
2055cea7
RK
495 plus_constant to try to simplify it. */
496 if (GET_CODE (XEXP (x, 1)) == CONST_INT && XEXP (x, 1) == to)
06140bdf
RK
497 validate_change (object, loc, plus_constant (XEXP (x, 0), INTVAL (to)),
498 1);
2055cea7 499 return;
06140bdf
RK
500
501 case MINUS:
502 if (GET_CODE (to) == CONST_INT && XEXP (x, 1) == from)
503 {
504 validate_change (object, loc,
505 plus_constant (XEXP (x, 0), - INTVAL (to)),
506 1);
507 return;
508 }
509 break;
2055cea7
RK
510
511 case ZERO_EXTEND:
512 case SIGN_EXTEND:
513 /* In these cases, the operation to be performed depends on the mode
514 of the operand. If we are replacing the operand with a VOIDmode
515 constant, we lose the information. So try to simplify the operation
516 in that case. If it fails, substitute in something that we know
6dc42e49 517 won't be recognized. */
2055cea7
RK
518 if (GET_MODE (to) == VOIDmode
519 && (XEXP (x, 0) == from
520 || (GET_CODE (XEXP (x, 0)) == REG && GET_CODE (from) == REG
521 && GET_MODE (XEXP (x, 0)) == GET_MODE (from)
522 && REGNO (XEXP (x, 0)) == REGNO (from))))
523 {
524 rtx new = simplify_unary_operation (code, GET_MODE (x), to,
525 GET_MODE (from));
526 if (new == 0)
38a448ca 527 new = gen_rtx_CLOBBER (GET_MODE (x), const0_rtx);
2055cea7
RK
528
529 validate_change (object, loc, new, 1);
530 return;
531 }
532 break;
533
534 case SUBREG:
535 /* If we have a SUBREG of a register that we are replacing and we are
536 replacing it with a MEM, make a new MEM and try replacing the
537 SUBREG with it. Don't do this if the MEM has a mode-dependent address
538 or if we would be widening it. */
539
540 if (SUBREG_REG (x) == from
541 && GET_CODE (from) == REG
542 && GET_CODE (to) == MEM
543 && ! mode_dependent_address_p (XEXP (to, 0))
544 && ! MEM_VOLATILE_P (to)
545 && GET_MODE_SIZE (GET_MODE (x)) <= GET_MODE_SIZE (GET_MODE (to)))
546 {
547 int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
548 enum machine_mode mode = GET_MODE (x);
549 rtx new;
550
f76b9db2
ILT
551 if (BYTES_BIG_ENDIAN)
552 offset += (MIN (UNITS_PER_WORD,
553 GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
554 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)));
2055cea7 555
38a448ca 556 new = gen_rtx_MEM (mode, plus_constant (XEXP (to, 0), offset));
2055cea7 557 RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (to);
c6df88cb 558 MEM_COPY_ATTRIBUTES (new, to);
2055cea7
RK
559 validate_change (object, loc, new, 1);
560 return;
561 }
562 break;
563
564 case ZERO_EXTRACT:
565 case SIGN_EXTRACT:
566 /* If we are replacing a register with memory, try to change the memory
567 to be the mode required for memory in extract operations (this isn't
568 likely to be an insertion operation; if it was, nothing bad will
569 happen, we might just fail in some cases). */
570
571 if (XEXP (x, 0) == from && GET_CODE (from) == REG && GET_CODE (to) == MEM
572 && GET_CODE (XEXP (x, 1)) == CONST_INT
573 && GET_CODE (XEXP (x, 2)) == CONST_INT
574 && ! mode_dependent_address_p (XEXP (to, 0))
575 && ! MEM_VOLATILE_P (to))
576 {
577 enum machine_mode wanted_mode = VOIDmode;
578 enum machine_mode is_mode = GET_MODE (to);
2055cea7
RK
579 int pos = INTVAL (XEXP (x, 2));
580
581#ifdef HAVE_extzv
582 if (code == ZERO_EXTRACT)
0d8e55d8
JL
583 {
584 wanted_mode = insn_operand_mode[(int) CODE_FOR_extzv][1];
585 if (wanted_mode == VOIDmode)
586 wanted_mode = word_mode;
587 }
2055cea7
RK
588#endif
589#ifdef HAVE_extv
590 if (code == SIGN_EXTRACT)
0d8e55d8
JL
591 {
592 wanted_mode = insn_operand_mode[(int) CODE_FOR_extv][1];
593 if (wanted_mode == VOIDmode)
594 wanted_mode = word_mode;
595 }
2055cea7
RK
596#endif
597
6dc42e49 598 /* If we have a narrower mode, we can do something. */
2055cea7
RK
599 if (wanted_mode != VOIDmode
600 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
601 {
602 int offset = pos / BITS_PER_UNIT;
603 rtx newmem;
604
605 /* If the bytes and bits are counted differently, we
606 must adjust the offset. */
f76b9db2
ILT
607 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
608 offset = (GET_MODE_SIZE (is_mode) - GET_MODE_SIZE (wanted_mode)
609 - offset);
2055cea7
RK
610
611 pos %= GET_MODE_BITSIZE (wanted_mode);
612
38a448ca
RH
613 newmem = gen_rtx_MEM (wanted_mode,
614 plus_constant (XEXP (to, 0), offset));
2055cea7 615 RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (to);
c6df88cb 616 MEM_COPY_ATTRIBUTES (newmem, to);
2055cea7 617
9e4223f2 618 validate_change (object, &XEXP (x, 2), GEN_INT (pos), 1);
2055cea7
RK
619 validate_change (object, &XEXP (x, 0), newmem, 1);
620 }
621 }
622
623 break;
38a448ca
RH
624
625 default:
626 break;
2055cea7
RK
627 }
628
f745c7a2
AB
629 /* For commutative or comparison operations we've already performed
630 replacements. Don't try to perform them again. */
631 if (GET_RTX_CLASS (code) != '<' && GET_RTX_CLASS (code) != 'c')
2055cea7 632 {
f745c7a2
AB
633 fmt = GET_RTX_FORMAT (code);
634 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
635 {
636 if (fmt[i] == 'e')
637 validate_replace_rtx_1 (&XEXP (x, i), from, to, object);
638 else if (fmt[i] == 'E')
639 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
640 validate_replace_rtx_1 (&XVECEXP (x, i, j), from, to, object);
641 }
2055cea7
RK
642 }
643}
644
645/* Try replacing every occurrence of FROM in INSN with TO. After all
646 changes have been made, validate by seeing if INSN is still valid. */
647
648int
649validate_replace_rtx (from, to, insn)
650 rtx from, to, insn;
651{
652 validate_replace_rtx_1 (&PATTERN (insn), from, to, insn);
653 return apply_change_group ();
654}
7506f491 655
edfac33e
JL
656/* Try replacing every occurrence of FROM in INSN with TO. After all
657 changes have been made, validate by seeing if INSN is still valid. */
658
659void
660validate_replace_rtx_group (from, to, insn)
661 rtx from, to, insn;
662{
663 validate_replace_rtx_1 (&PATTERN (insn), from, to, insn);
664}
665
7506f491
DE
666/* Try replacing every occurrence of FROM in INSN with TO, avoiding
667 SET_DESTs. After all changes have been made, validate by seeing if
668 INSN is still valid. */
669
670int
671validate_replace_src (from, to, insn)
672 rtx from, to, insn;
673{
674 if ((GET_CODE (insn) != INSN && GET_CODE (insn) != JUMP_INSN)
675 || GET_CODE (PATTERN (insn)) != SET)
676 abort ();
677
678 validate_replace_rtx_1 (&SET_SRC (PATTERN (insn)), from, to, insn);
679 if (GET_CODE (SET_DEST (PATTERN (insn))) == MEM)
680 validate_replace_rtx_1 (&XEXP (SET_DEST (PATTERN (insn)), 0),
681 from, to, insn);
682 return apply_change_group ();
683}
2055cea7
RK
684\f
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 register 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 register 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\f
735/* This is used by find_single_use to locate an rtx that contains exactly one
736 use of DEST, which is typically either a REG or CC0. It returns a
737 pointer to the innermost rtx expression containing DEST. Appearances of
738 DEST that are being used to totally replace it are not counted. */
739
740static rtx *
741find_single_use_1 (dest, loc)
742 rtx dest;
743 rtx *loc;
744{
745 rtx x = *loc;
746 enum rtx_code code = GET_CODE (x);
747 rtx *result = 0;
748 rtx *this_result;
749 int i;
6f7d635c 750 const char *fmt;
2055cea7
RK
751
752 switch (code)
753 {
754 case CONST_INT:
755 case CONST:
756 case LABEL_REF:
757 case SYMBOL_REF:
758 case CONST_DOUBLE:
759 case CLOBBER:
760 return 0;
761
762 case SET:
763 /* If the destination is anything other than CC0, PC, a REG or a SUBREG
764 of a REG that occupies all of the REG, the insn uses DEST if
765 it is mentioned in the destination or the source. Otherwise, we
766 need just check the source. */
767 if (GET_CODE (SET_DEST (x)) != CC0
768 && GET_CODE (SET_DEST (x)) != PC
769 && GET_CODE (SET_DEST (x)) != REG
770 && ! (GET_CODE (SET_DEST (x)) == SUBREG
771 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG
772 && (((GET_MODE_SIZE (GET_MODE (SUBREG_REG (SET_DEST (x))))
773 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)
774 == ((GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
775 + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD))))
776 break;
777
778 return find_single_use_1 (dest, &SET_SRC (x));
779
780 case MEM:
781 case SUBREG:
782 return find_single_use_1 (dest, &XEXP (x, 0));
38a448ca
RH
783
784 default:
785 break;
2055cea7
RK
786 }
787
788 /* If it wasn't one of the common cases above, check each expression and
789 vector of this code. Look for a unique usage of DEST. */
790
791 fmt = GET_RTX_FORMAT (code);
792 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
793 {
794 if (fmt[i] == 'e')
795 {
796 if (dest == XEXP (x, i)
797 || (GET_CODE (dest) == REG && GET_CODE (XEXP (x, i)) == REG
798 && REGNO (dest) == REGNO (XEXP (x, i))))
799 this_result = loc;
800 else
801 this_result = find_single_use_1 (dest, &XEXP (x, i));
802
803 if (result == 0)
804 result = this_result;
805 else if (this_result)
806 /* Duplicate usage. */
807 return 0;
808 }
809 else if (fmt[i] == 'E')
810 {
811 int j;
812
813 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
814 {
815 if (XVECEXP (x, i, j) == dest
816 || (GET_CODE (dest) == REG
817 && GET_CODE (XVECEXP (x, i, j)) == REG
818 && REGNO (XVECEXP (x, i, j)) == REGNO (dest)))
819 this_result = loc;
820 else
821 this_result = find_single_use_1 (dest, &XVECEXP (x, i, j));
822
823 if (result == 0)
824 result = this_result;
825 else if (this_result)
826 return 0;
827 }
828 }
829 }
830
831 return result;
832}
833\f
834/* See if DEST, produced in INSN, is used only a single time in the
835 sequel. If so, return a pointer to the innermost rtx expression in which
836 it is used.
837
838 If PLOC is non-zero, *PLOC is set to the insn containing the single use.
839
840 This routine will return usually zero either before flow is called (because
841 there will be no LOG_LINKS notes) or after reload (because the REG_DEAD
842 note can't be trusted).
843
844 If DEST is cc0_rtx, we look only at the next insn. In that case, we don't
845 care about REG_DEAD notes or LOG_LINKS.
846
847 Otherwise, we find the single use by finding an insn that has a
848 LOG_LINKS pointing at INSN and has a REG_DEAD note for DEST. If DEST is
849 only referenced once in that insn, we know that it must be the first
850 and last insn referencing DEST. */
851
852rtx *
853find_single_use (dest, insn, ploc)
854 rtx dest;
855 rtx insn;
856 rtx *ploc;
857{
858 rtx next;
859 rtx *result;
860 rtx link;
861
862#ifdef HAVE_cc0
863 if (dest == cc0_rtx)
864 {
865 next = NEXT_INSN (insn);
866 if (next == 0
867 || (GET_CODE (next) != INSN && GET_CODE (next) != JUMP_INSN))
868 return 0;
869
870 result = find_single_use_1 (dest, &PATTERN (next));
871 if (result && ploc)
872 *ploc = next;
873 return result;
874 }
875#endif
876
877 if (reload_completed || reload_in_progress || GET_CODE (dest) != REG)
878 return 0;
879
880 for (next = next_nonnote_insn (insn);
881 next != 0 && GET_CODE (next) != CODE_LABEL;
882 next = next_nonnote_insn (next))
883 if (GET_RTX_CLASS (GET_CODE (next)) == 'i' && dead_or_set_p (next, dest))
884 {
885 for (link = LOG_LINKS (next); link; link = XEXP (link, 1))
886 if (XEXP (link, 0) == insn)
887 break;
888
889 if (link)
890 {
891 result = find_single_use_1 (dest, &PATTERN (next));
892 if (ploc)
893 *ploc = next;
894 return result;
895 }
896 }
897
898 return 0;
899}
900\f
901/* Return 1 if OP is a valid general operand for machine mode MODE.
902 This is either a register reference, a memory reference,
903 or a constant. In the case of a memory reference, the address
904 is checked for general validity for the target machine.
905
906 Register and memory references must have mode MODE in order to be valid,
907 but some constants have no machine mode and are valid for any mode.
908
909 If MODE is VOIDmode, OP is checked for validity for whatever mode
910 it has.
911
912 The main use of this function is as a predicate in match_operand
913 expressions in the machine description.
914
6dc42e49 915 For an explanation of this function's behavior for registers of
2055cea7
RK
916 class NO_REGS, see the comment for `register_operand'. */
917
918int
919general_operand (op, mode)
920 register rtx op;
921 enum machine_mode mode;
922{
923 register enum rtx_code code = GET_CODE (op);
924 int mode_altering_drug = 0;
925
926 if (mode == VOIDmode)
927 mode = GET_MODE (op);
928
929 /* Don't accept CONST_INT or anything similar
930 if the caller wants something floating. */
931 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
4bb4c82e
RK
932 && GET_MODE_CLASS (mode) != MODE_INT
933 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
2055cea7
RK
934 return 0;
935
936 if (CONSTANT_P (op))
937 return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode)
938#ifdef LEGITIMATE_PIC_OPERAND_P
939 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
940#endif
941 && LEGITIMATE_CONSTANT_P (op));
942
943 /* Except for certain constants with VOIDmode, already checked for,
944 OP's mode must match MODE if MODE specifies a mode. */
945
946 if (GET_MODE (op) != mode)
947 return 0;
948
949 if (code == SUBREG)
950 {
951#ifdef INSN_SCHEDULING
952 /* On machines that have insn scheduling, we want all memory
953 reference to be explicit, so outlaw paradoxical SUBREGs. */
954 if (GET_CODE (SUBREG_REG (op)) == MEM
955 && GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))))
956 return 0;
957#endif
958
959 op = SUBREG_REG (op);
960 code = GET_CODE (op);
961#if 0
962 /* No longer needed, since (SUBREG (MEM...))
963 will load the MEM into a reload reg in the MEM's own mode. */
964 mode_altering_drug = 1;
965#endif
966 }
967
968 if (code == REG)
969 /* A register whose class is NO_REGS is not a general operand. */
970 return (REGNO (op) >= FIRST_PSEUDO_REGISTER
971 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS);
972
973 if (code == MEM)
974 {
975 register rtx y = XEXP (op, 0);
976 if (! volatile_ok && MEM_VOLATILE_P (op))
977 return 0;
38a448ca
RH
978 if (GET_CODE (y) == ADDRESSOF)
979 return 1;
2055cea7
RK
980 /* Use the mem's mode, since it will be reloaded thus. */
981 mode = GET_MODE (op);
982 GO_IF_LEGITIMATE_ADDRESS (mode, y, win);
983 }
38a448ca
RH
984
985 /* Pretend this is an operand for now; we'll run force_operand
986 on its replacement in fixup_var_refs_1. */
987 if (code == ADDRESSOF)
988 return 1;
989
2055cea7
RK
990 return 0;
991
992 win:
993 if (mode_altering_drug)
994 return ! mode_dependent_address_p (XEXP (op, 0));
995 return 1;
996}
997\f
998/* Return 1 if OP is a valid memory address for a memory reference
999 of mode MODE.
1000
1001 The main use of this function is as a predicate in match_operand
1002 expressions in the machine description. */
1003
1004int
1005address_operand (op, mode)
1006 register rtx op;
1007 enum machine_mode mode;
1008{
1009 return memory_address_p (mode, op);
1010}
1011
1012/* Return 1 if OP is a register reference of mode MODE.
1013 If MODE is VOIDmode, accept a register in any mode.
1014
1015 The main use of this function is as a predicate in match_operand
1016 expressions in the machine description.
1017
1018 As a special exception, registers whose class is NO_REGS are
1019 not accepted by `register_operand'. The reason for this change
1020 is to allow the representation of special architecture artifacts
1021 (such as a condition code register) without extending the rtl
1022 definitions. Since registers of class NO_REGS cannot be used
1023 as registers in any case where register classes are examined,
1024 it is most consistent to keep this function from accepting them. */
1025
1026int
1027register_operand (op, mode)
1028 register rtx op;
1029 enum machine_mode mode;
1030{
1031 if (GET_MODE (op) != mode && mode != VOIDmode)
1032 return 0;
1033
1034 if (GET_CODE (op) == SUBREG)
1035 {
1036 /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
1037 because it is guaranteed to be reloaded into one.
1038 Just make sure the MEM is valid in itself.
1039 (Ideally, (SUBREG (MEM)...) should not exist after reload,
1040 but currently it does result from (SUBREG (REG)...) where the
1041 reg went on the stack.) */
1042 if (! reload_completed && GET_CODE (SUBREG_REG (op)) == MEM)
1043 return general_operand (op, mode);
cba057ed
RK
1044
1045#ifdef CLASS_CANNOT_CHANGE_SIZE
1046 if (GET_CODE (SUBREG_REG (op)) == REG
1047 && REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER
1048 && TEST_HARD_REG_BIT (reg_class_contents[(int) CLASS_CANNOT_CHANGE_SIZE],
1049 REGNO (SUBREG_REG (op)))
1050 && (GET_MODE_SIZE (mode)
50dc6373
RK
1051 != GET_MODE_SIZE (GET_MODE (SUBREG_REG (op))))
1052 && GET_MODE_CLASS (GET_MODE (SUBREG_REG (op))) != MODE_COMPLEX_INT
1053 && GET_MODE_CLASS (GET_MODE (SUBREG_REG (op))) != MODE_COMPLEX_FLOAT)
cba057ed
RK
1054 return 0;
1055#endif
1056
2055cea7
RK
1057 op = SUBREG_REG (op);
1058 }
1059
1060 /* We don't consider registers whose class is NO_REGS
1061 to be a register operand. */
1062 return (GET_CODE (op) == REG
1063 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
1064 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
1065}
1066
1067/* Return 1 if OP should match a MATCH_SCRATCH, i.e., if it is a SCRATCH
1068 or a hard register. */
1069
1070int
1071scratch_operand (op, mode)
1072 register rtx op;
1073 enum machine_mode mode;
1074{
1075 return (GET_MODE (op) == mode
1076 && (GET_CODE (op) == SCRATCH
1077 || (GET_CODE (op) == REG
1078 && REGNO (op) < FIRST_PSEUDO_REGISTER)));
1079}
1080
1081/* Return 1 if OP is a valid immediate operand for mode MODE.
1082
1083 The main use of this function is as a predicate in match_operand
1084 expressions in the machine description. */
1085
1086int
1087immediate_operand (op, mode)
1088 register rtx op;
1089 enum machine_mode mode;
1090{
1091 /* Don't accept CONST_INT or anything similar
1092 if the caller wants something floating. */
1093 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
4bb4c82e
RK
1094 && GET_MODE_CLASS (mode) != MODE_INT
1095 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
2055cea7
RK
1096 return 0;
1097
ee5332b8
RH
1098 /* Accept CONSTANT_P_RTX, since it will be gone by CSE1 and
1099 result in 0/1. It seems a safe assumption that this is
1100 in range for everyone. */
1101 if (GET_CODE (op) == CONSTANT_P_RTX)
1102 return 1;
1103
2055cea7
RK
1104 return (CONSTANT_P (op)
1105 && (GET_MODE (op) == mode || mode == VOIDmode
1106 || GET_MODE (op) == VOIDmode)
1107#ifdef LEGITIMATE_PIC_OPERAND_P
1108 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
1109#endif
1110 && LEGITIMATE_CONSTANT_P (op));
1111}
1112
1113/* Returns 1 if OP is an operand that is a CONST_INT. */
1114
1115int
1116const_int_operand (op, mode)
1117 register rtx op;
e51712db 1118 enum machine_mode mode ATTRIBUTE_UNUSED;
2055cea7
RK
1119{
1120 return GET_CODE (op) == CONST_INT;
1121}
1122
1123/* Returns 1 if OP is an operand that is a constant integer or constant
1124 floating-point number. */
1125
1126int
1127const_double_operand (op, mode)
1128 register rtx op;
1129 enum machine_mode mode;
1130{
1131 /* Don't accept CONST_INT or anything similar
1132 if the caller wants something floating. */
1133 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
4bb4c82e
RK
1134 && GET_MODE_CLASS (mode) != MODE_INT
1135 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
2055cea7
RK
1136 return 0;
1137
1138 return ((GET_CODE (op) == CONST_DOUBLE || GET_CODE (op) == CONST_INT)
1139 && (mode == VOIDmode || GET_MODE (op) == mode
1140 || GET_MODE (op) == VOIDmode));
1141}
1142
1143/* Return 1 if OP is a general operand that is not an immediate operand. */
1144
1145int
1146nonimmediate_operand (op, mode)
1147 register rtx op;
1148 enum machine_mode mode;
1149{
1150 return (general_operand (op, mode) && ! CONSTANT_P (op));
1151}
1152
1153/* Return 1 if OP is a register reference or immediate value of mode MODE. */
1154
1155int
1156nonmemory_operand (op, mode)
1157 register rtx op;
1158 enum machine_mode mode;
1159{
1160 if (CONSTANT_P (op))
1161 {
1162 /* Don't accept CONST_INT or anything similar
1163 if the caller wants something floating. */
1164 if (GET_MODE (op) == VOIDmode && mode != VOIDmode
4bb4c82e
RK
1165 && GET_MODE_CLASS (mode) != MODE_INT
1166 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
2055cea7
RK
1167 return 0;
1168
1169 return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode)
1170#ifdef LEGITIMATE_PIC_OPERAND_P
1171 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
1172#endif
1173 && LEGITIMATE_CONSTANT_P (op));
1174 }
1175
1176 if (GET_MODE (op) != mode && mode != VOIDmode)
1177 return 0;
1178
1179 if (GET_CODE (op) == SUBREG)
1180 {
1181 /* Before reload, we can allow (SUBREG (MEM...)) as a register operand
1182 because it is guaranteed to be reloaded into one.
1183 Just make sure the MEM is valid in itself.
1184 (Ideally, (SUBREG (MEM)...) should not exist after reload,
1185 but currently it does result from (SUBREG (REG)...) where the
1186 reg went on the stack.) */
1187 if (! reload_completed && GET_CODE (SUBREG_REG (op)) == MEM)
1188 return general_operand (op, mode);
1189 op = SUBREG_REG (op);
1190 }
1191
1192 /* We don't consider registers whose class is NO_REGS
1193 to be a register operand. */
1194 return (GET_CODE (op) == REG
1195 && (REGNO (op) >= FIRST_PSEUDO_REGISTER
1196 || REGNO_REG_CLASS (REGNO (op)) != NO_REGS));
1197}
1198
1199/* Return 1 if OP is a valid operand that stands for pushing a
1200 value of mode MODE onto the stack.
1201
1202 The main use of this function is as a predicate in match_operand
1203 expressions in the machine description. */
1204
1205int
1206push_operand (op, mode)
1207 rtx op;
1208 enum machine_mode mode;
1209{
1210 if (GET_CODE (op) != MEM)
1211 return 0;
1212
aeb7ff68 1213 if (mode != VOIDmode && GET_MODE (op) != mode)
2055cea7
RK
1214 return 0;
1215
1216 op = XEXP (op, 0);
1217
1218 if (GET_CODE (op) != STACK_PUSH_CODE)
1219 return 0;
1220
1221 return XEXP (op, 0) == stack_pointer_rtx;
1222}
1223
6fbe9bd8
RH
1224/* Return 1 if OP is a valid operand that stands for popping a
1225 value of mode MODE off the stack.
1226
1227 The main use of this function is as a predicate in match_operand
1228 expressions in the machine description. */
1229
1230int
1231pop_operand (op, mode)
1232 rtx op;
1233 enum machine_mode mode;
1234{
1235 if (GET_CODE (op) != MEM)
1236 return 0;
1237
aeb7ff68 1238 if (mode != VOIDmode && GET_MODE (op) != mode)
6fbe9bd8
RH
1239 return 0;
1240
1241 op = XEXP (op, 0);
1242
1243 if (GET_CODE (op) != STACK_POP_CODE)
1244 return 0;
1245
1246 return XEXP (op, 0) == stack_pointer_rtx;
1247}
1248
2055cea7
RK
1249/* Return 1 if ADDR is a valid memory address for mode MODE. */
1250
1251int
1252memory_address_p (mode, addr)
1253 enum machine_mode mode;
1254 register rtx addr;
1255{
38a448ca
RH
1256 if (GET_CODE (addr) == ADDRESSOF)
1257 return 1;
1258
2055cea7
RK
1259 GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
1260 return 0;
1261
1262 win:
1263 return 1;
1264}
1265
1266/* Return 1 if OP is a valid memory reference with mode MODE,
1267 including a valid address.
1268
1269 The main use of this function is as a predicate in match_operand
1270 expressions in the machine description. */
1271
1272int
1273memory_operand (op, mode)
1274 register rtx op;
1275 enum machine_mode mode;
1276{
1277 rtx inner;
1278
1279 if (! reload_completed)
1280 /* Note that no SUBREG is a memory operand before end of reload pass,
1281 because (SUBREG (MEM...)) forces reloading into a register. */
1282 return GET_CODE (op) == MEM && general_operand (op, mode);
1283
1284 if (mode != VOIDmode && GET_MODE (op) != mode)
1285 return 0;
1286
1287 inner = op;
1288 if (GET_CODE (inner) == SUBREG)
1289 inner = SUBREG_REG (inner);
1290
1291 return (GET_CODE (inner) == MEM && general_operand (op, mode));
1292}
1293
1294/* Return 1 if OP is a valid indirect memory reference with mode MODE;
1295 that is, a memory reference whose address is a general_operand. */
1296
1297int
1298indirect_operand (op, mode)
1299 register rtx op;
1300 enum machine_mode mode;
1301{
1302 /* Before reload, a SUBREG isn't in memory (see memory_operand, above). */
1303 if (! reload_completed
1304 && GET_CODE (op) == SUBREG && GET_CODE (SUBREG_REG (op)) == MEM)
1305 {
1306 register int offset = SUBREG_WORD (op) * UNITS_PER_WORD;
1307 rtx inner = SUBREG_REG (op);
1308
f76b9db2
ILT
1309 if (BYTES_BIG_ENDIAN)
1310 offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (op)))
1311 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (inner))));
2055cea7 1312
b0e0a0f9
RK
1313 if (mode != VOIDmode && GET_MODE (op) != mode)
1314 return 0;
1315
2055cea7
RK
1316 /* The only way that we can have a general_operand as the resulting
1317 address is if OFFSET is zero and the address already is an operand
1318 or if the address is (plus Y (const_int -OFFSET)) and Y is an
1319 operand. */
1320
1321 return ((offset == 0 && general_operand (XEXP (inner, 0), Pmode))
1322 || (GET_CODE (XEXP (inner, 0)) == PLUS
1323 && GET_CODE (XEXP (XEXP (inner, 0), 1)) == CONST_INT
1324 && INTVAL (XEXP (XEXP (inner, 0), 1)) == -offset
1325 && general_operand (XEXP (XEXP (inner, 0), 0), Pmode)));
1326 }
1327
1328 return (GET_CODE (op) == MEM
1329 && memory_operand (op, mode)
1330 && general_operand (XEXP (op, 0), Pmode));
1331}
1332
1333/* Return 1 if this is a comparison operator. This allows the use of
1334 MATCH_OPERATOR to recognize all the branch insns. */
1335
1336int
1337comparison_operator (op, mode)
1338 register rtx op;
1339 enum machine_mode mode;
1340{
1341 return ((mode == VOIDmode || GET_MODE (op) == mode)
1342 && GET_RTX_CLASS (GET_CODE (op)) == '<');
1343}
1344\f
1345/* If BODY is an insn body that uses ASM_OPERANDS,
1346 return the number of operands (both input and output) in the insn.
1347 Otherwise return -1. */
1348
1349int
1350asm_noperands (body)
1351 rtx body;
1352{
1353 if (GET_CODE (body) == ASM_OPERANDS)
1354 /* No output operands: return number of input operands. */
1355 return ASM_OPERANDS_INPUT_LENGTH (body);
1356 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1357 /* Single output operand: BODY is (set OUTPUT (asm_operands ...)). */
1358 return ASM_OPERANDS_INPUT_LENGTH (SET_SRC (body)) + 1;
1359 else if (GET_CODE (body) == PARALLEL
1360 && GET_CODE (XVECEXP (body, 0, 0)) == SET
1361 && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
1362 {
1363 /* Multiple output operands, or 1 output plus some clobbers:
1364 body is [(set OUTPUT (asm_operands ...))... (clobber (reg ...))...]. */
1365 int i;
1366 int n_sets;
1367
1368 /* Count backwards through CLOBBERs to determine number of SETs. */
1369 for (i = XVECLEN (body, 0); i > 0; i--)
1370 {
1371 if (GET_CODE (XVECEXP (body, 0, i - 1)) == SET)
1372 break;
1373 if (GET_CODE (XVECEXP (body, 0, i - 1)) != CLOBBER)
1374 return -1;
1375 }
1376
1377 /* N_SETS is now number of output operands. */
1378 n_sets = i;
1379
1380 /* Verify that all the SETs we have
1381 came from a single original asm_operands insn
1382 (so that invalid combinations are blocked). */
1383 for (i = 0; i < n_sets; i++)
1384 {
1385 rtx elt = XVECEXP (body, 0, i);
1386 if (GET_CODE (elt) != SET)
1387 return -1;
1388 if (GET_CODE (SET_SRC (elt)) != ASM_OPERANDS)
1389 return -1;
1390 /* If these ASM_OPERANDS rtx's came from different original insns
1391 then they aren't allowed together. */
1392 if (ASM_OPERANDS_INPUT_VEC (SET_SRC (elt))
1393 != ASM_OPERANDS_INPUT_VEC (SET_SRC (XVECEXP (body, 0, 0))))
1394 return -1;
1395 }
1396 return (ASM_OPERANDS_INPUT_LENGTH (SET_SRC (XVECEXP (body, 0, 0)))
1397 + n_sets);
1398 }
1399 else if (GET_CODE (body) == PARALLEL
1400 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1401 {
1402 /* 0 outputs, but some clobbers:
1403 body is [(asm_operands ...) (clobber (reg ...))...]. */
1404 int i;
1405
1406 /* Make sure all the other parallel things really are clobbers. */
1407 for (i = XVECLEN (body, 0) - 1; i > 0; i--)
1408 if (GET_CODE (XVECEXP (body, 0, i)) != CLOBBER)
1409 return -1;
1410
1411 return ASM_OPERANDS_INPUT_LENGTH (XVECEXP (body, 0, 0));
1412 }
1413 else
1414 return -1;
1415}
1416
1417/* Assuming BODY is an insn body that uses ASM_OPERANDS,
1418 copy its operands (both input and output) into the vector OPERANDS,
1419 the locations of the operands within the insn into the vector OPERAND_LOCS,
1420 and the constraints for the operands into CONSTRAINTS.
1421 Write the modes of the operands into MODES.
1422 Return the assembler-template.
1423
1424 If MODES, OPERAND_LOCS, CONSTRAINTS or OPERANDS is 0,
1425 we don't store that info. */
1426
1427char *
1428decode_asm_operands (body, operands, operand_locs, constraints, modes)
1429 rtx body;
1430 rtx *operands;
1431 rtx **operand_locs;
9b3142b3 1432 const char **constraints;
2055cea7
RK
1433 enum machine_mode *modes;
1434{
1435 register int i;
1436 int noperands;
1437 char *template = 0;
1438
1439 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
1440 {
1441 rtx asmop = SET_SRC (body);
1442 /* Single output operand: BODY is (set OUTPUT (asm_operands ....)). */
1443
1444 noperands = ASM_OPERANDS_INPUT_LENGTH (asmop) + 1;
1445
1446 for (i = 1; i < noperands; i++)
1447 {
1448 if (operand_locs)
1449 operand_locs[i] = &ASM_OPERANDS_INPUT (asmop, i - 1);
1450 if (operands)
1451 operands[i] = ASM_OPERANDS_INPUT (asmop, i - 1);
1452 if (constraints)
1453 constraints[i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i - 1);
1454 if (modes)
1455 modes[i] = ASM_OPERANDS_INPUT_MODE (asmop, i - 1);
1456 }
1457
1458 /* The output is in the SET.
1459 Its constraint is in the ASM_OPERANDS itself. */
1460 if (operands)
1461 operands[0] = SET_DEST (body);
1462 if (operand_locs)
1463 operand_locs[0] = &SET_DEST (body);
1464 if (constraints)
1465 constraints[0] = ASM_OPERANDS_OUTPUT_CONSTRAINT (asmop);
1466 if (modes)
1467 modes[0] = GET_MODE (SET_DEST (body));
1468 template = ASM_OPERANDS_TEMPLATE (asmop);
1469 }
1470 else if (GET_CODE (body) == ASM_OPERANDS)
1471 {
1472 rtx asmop = body;
1473 /* No output operands: BODY is (asm_operands ....). */
1474
1475 noperands = ASM_OPERANDS_INPUT_LENGTH (asmop);
1476
1477 /* The input operands are found in the 1st element vector. */
1478 /* Constraints for inputs are in the 2nd element vector. */
1479 for (i = 0; i < noperands; i++)
1480 {
1481 if (operand_locs)
1482 operand_locs[i] = &ASM_OPERANDS_INPUT (asmop, i);
1483 if (operands)
1484 operands[i] = ASM_OPERANDS_INPUT (asmop, i);
1485 if (constraints)
1486 constraints[i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
1487 if (modes)
1488 modes[i] = ASM_OPERANDS_INPUT_MODE (asmop, i);
1489 }
1490 template = ASM_OPERANDS_TEMPLATE (asmop);
1491 }
1492 else if (GET_CODE (body) == PARALLEL
1493 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
1494 {
1495 rtx asmop = SET_SRC (XVECEXP (body, 0, 0));
1496 int nparallel = XVECLEN (body, 0); /* Includes CLOBBERs. */
1497 int nin = ASM_OPERANDS_INPUT_LENGTH (asmop);
1498 int nout = 0; /* Does not include CLOBBERs. */
1499
1500 /* At least one output, plus some CLOBBERs. */
1501
1502 /* The outputs are in the SETs.
1503 Their constraints are in the ASM_OPERANDS itself. */
1504 for (i = 0; i < nparallel; i++)
1505 {
1506 if (GET_CODE (XVECEXP (body, 0, i)) == CLOBBER)
1507 break; /* Past last SET */
1508
1509 if (operands)
1510 operands[i] = SET_DEST (XVECEXP (body, 0, i));
1511 if (operand_locs)
1512 operand_locs[i] = &SET_DEST (XVECEXP (body, 0, i));
1513 if (constraints)
1514 constraints[i] = XSTR (SET_SRC (XVECEXP (body, 0, i)), 1);
1515 if (modes)
1516 modes[i] = GET_MODE (SET_DEST (XVECEXP (body, 0, i)));
1517 nout++;
1518 }
1519
1520 for (i = 0; i < nin; i++)
1521 {
1522 if (operand_locs)
1523 operand_locs[i + nout] = &ASM_OPERANDS_INPUT (asmop, i);
1524 if (operands)
1525 operands[i + nout] = ASM_OPERANDS_INPUT (asmop, i);
1526 if (constraints)
1527 constraints[i + nout] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
1528 if (modes)
1529 modes[i + nout] = ASM_OPERANDS_INPUT_MODE (asmop, i);
1530 }
1531
1532 template = ASM_OPERANDS_TEMPLATE (asmop);
1533 }
1534 else if (GET_CODE (body) == PARALLEL
1535 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1536 {
1537 /* No outputs, but some CLOBBERs. */
1538
1539 rtx asmop = XVECEXP (body, 0, 0);
1540 int nin = ASM_OPERANDS_INPUT_LENGTH (asmop);
1541
1542 for (i = 0; i < nin; i++)
1543 {
1544 if (operand_locs)
1545 operand_locs[i] = &ASM_OPERANDS_INPUT (asmop, i);
1546 if (operands)
1547 operands[i] = ASM_OPERANDS_INPUT (asmop, i);
1548 if (constraints)
1549 constraints[i] = ASM_OPERANDS_INPUT_CONSTRAINT (asmop, i);
1550 if (modes)
1551 modes[i] = ASM_OPERANDS_INPUT_MODE (asmop, i);
1552 }
1553
1554 template = ASM_OPERANDS_TEMPLATE (asmop);
1555 }
1556
1557 return template;
1558}
1f06ee8d 1559
1afbe1c4
RH
1560/* Check if an asm_operand matches it's constraints.
1561 Return > 0 if ok, = 0 if bad, < 0 if inconclusive. */
1f06ee8d
RH
1562
1563int
1564asm_operand_ok (op, constraint)
1565 rtx op;
1566 const char *constraint;
1567{
1afbe1c4
RH
1568 int result = 0;
1569
1f06ee8d
RH
1570 /* Use constrain_operands after reload. */
1571 if (reload_completed)
1572 abort ();
1573
1574 while (*constraint)
1575 {
1576 switch (*constraint++)
1577 {
1578 case '=':
1579 case '+':
1580 case '*':
1581 case '%':
1582 case '?':
1583 case '!':
1584 case '#':
1585 case '&':
1586 case ',':
1587 break;
1588
1589 case '0': case '1': case '2': case '3': case '4':
1590 case '5': case '6': case '7': case '8': case '9':
1afbe1c4
RH
1591 /* For best results, our caller should have given us the
1592 proper matching constraint, but we can't actually fail
1593 the check if they didn't. Indicate that results are
1594 inconclusive. */
1595 result = -1;
1f06ee8d
RH
1596 break;
1597
1598 case 'p':
1599 if (address_operand (op, VOIDmode))
1600 return 1;
1601 break;
1602
1603 case 'm':
1604 case 'V': /* non-offsettable */
1605 if (memory_operand (op, VOIDmode))
1606 return 1;
1607 break;
1608
1609 case 'o': /* offsettable */
1610 if (offsettable_nonstrict_memref_p (op))
1611 return 1;
1612 break;
1613
1614 case '<':
1afbe1c4
RH
1615 /* ??? Before flow, auto inc/dec insns are not supposed to exist,
1616 excepting those that expand_call created. Further, on some
1617 machines which do not have generalized auto inc/dec, an inc/dec
1618 is not a memory_operand.
1619
1620 Match any memory and hope things are resolved after reload. */
1621
1f06ee8d 1622 if (GET_CODE (op) == MEM
1afbe1c4
RH
1623 && (1
1624 || GET_CODE (XEXP (op, 0)) == PRE_DEC
1f06ee8d
RH
1625 || GET_CODE (XEXP (op, 0)) == POST_DEC))
1626 return 1;
1627 break;
1628
1629 case '>':
1630 if (GET_CODE (op) == MEM
1afbe1c4
RH
1631 && (1
1632 || GET_CODE (XEXP (op, 0)) == PRE_INC
1f06ee8d
RH
1633 || GET_CODE (XEXP (op, 0)) == POST_INC))
1634 return 1;
1635 break;
1636
1637 case 'E':
1638#ifndef REAL_ARITHMETIC
1639 /* Match any floating double constant, but only if
1640 we can examine the bits of it reliably. */
1641 if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
1642 || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
1643 && GET_MODE (op) != VOIDmode && ! flag_pretend_float)
1644 break;
1645#endif
1646 /* FALLTHRU */
1647
1648 case 'F':
1649 if (GET_CODE (op) == CONST_DOUBLE)
1650 return 1;
1651 break;
1652
1653 case 'G':
1654 if (GET_CODE (op) == CONST_DOUBLE
1655 && CONST_DOUBLE_OK_FOR_LETTER_P (op, 'G'))
1656 return 1;
1657 break;
1658 case 'H':
1659 if (GET_CODE (op) == CONST_DOUBLE
1660 && CONST_DOUBLE_OK_FOR_LETTER_P (op, 'H'))
1661 return 1;
1662 break;
1663
1664 case 's':
1665 if (GET_CODE (op) == CONST_INT
1666 || (GET_CODE (op) == CONST_DOUBLE
1667 && GET_MODE (op) == VOIDmode))
1668 break;
1669 /* FALLTHRU */
1670
1671 case 'i':
1672 if (CONSTANT_P (op)
1673#ifdef LEGITIMATE_PIC_OPERAND_P
1674 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))
1675#endif
1676 )
1677 return 1;
1678 break;
1679
1680 case 'n':
1681 if (GET_CODE (op) == CONST_INT
1682 || (GET_CODE (op) == CONST_DOUBLE
1683 && GET_MODE (op) == VOIDmode))
1684 return 1;
1685 break;
1686
1687 case 'I':
1688 if (GET_CODE (op) == CONST_INT
1689 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'))
1690 return 1;
1691 break;
1692 case 'J':
1693 if (GET_CODE (op) == CONST_INT
1694 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'J'))
1695 return 1;
1696 break;
1697 case 'K':
1698 if (GET_CODE (op) == CONST_INT
1699 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'K'))
1700 return 1;
1701 break;
1702 case 'L':
1703 if (GET_CODE (op) == CONST_INT
1704 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'))
1705 return 1;
1706 break;
1707 case 'M':
1708 if (GET_CODE (op) == CONST_INT
1709 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'M'))
1710 return 1;
1711 break;
1712 case 'N':
1713 if (GET_CODE (op) == CONST_INT
1714 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'N'))
1715 return 1;
1716 break;
1717 case 'O':
1718 if (GET_CODE (op) == CONST_INT
1719 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'O'))
1720 return 1;
1721 break;
1722 case 'P':
1723 if (GET_CODE (op) == CONST_INT
1724 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'P'))
1725 return 1;
1726 break;
1727
1728 case 'X':
1729 return 1;
1730
1731 case 'g':
1732 if (general_operand (op, VOIDmode))
1733 return 1;
1734 break;
1735
1736#ifdef EXTRA_CONSTRAINT
1737 case 'Q':
1738 if (EXTRA_CONSTRAINT (op, 'Q'))
1739 return 1;
1740 break;
1741 case 'R':
1742 if (EXTRA_CONSTRAINT (op, 'R'))
1743 return 1;
1744 break;
1745 case 'S':
1746 if (EXTRA_CONSTRAINT (op, 'S'))
1747 return 1;
1748 break;
1749 case 'T':
1750 if (EXTRA_CONSTRAINT (op, 'T'))
1751 return 1;
1752 break;
1753 case 'U':
1754 if (EXTRA_CONSTRAINT (op, 'U'))
1755 return 1;
1756 break;
1757#endif
1758
1759 case 'r':
1760 default:
1761 if (GET_MODE (op) == BLKmode)
1762 break;
1763 if (register_operand (op, VOIDmode))
1764 return 1;
1765 break;
1766 }
1767 }
1768
1afbe1c4 1769 return result;
1f06ee8d 1770}
2055cea7 1771\f
2055cea7
RK
1772/* Given an rtx *P, if it is a sum containing an integer constant term,
1773 return the location (type rtx *) of the pointer to that constant term.
1774 Otherwise, return a null pointer. */
1775
1776static rtx *
1777find_constant_term_loc (p)
1778 rtx *p;
1779{
1780 register rtx *tem;
1781 register enum rtx_code code = GET_CODE (*p);
1782
1783 /* If *P IS such a constant term, P is its location. */
1784
1785 if (code == CONST_INT || code == SYMBOL_REF || code == LABEL_REF
1786 || code == CONST)
1787 return p;
1788
1789 /* Otherwise, if not a sum, it has no constant term. */
1790
1791 if (GET_CODE (*p) != PLUS)
1792 return 0;
1793
1794 /* If one of the summands is constant, return its location. */
1795
1796 if (XEXP (*p, 0) && CONSTANT_P (XEXP (*p, 0))
1797 && XEXP (*p, 1) && CONSTANT_P (XEXP (*p, 1)))
1798 return p;
1799
1800 /* Otherwise, check each summand for containing a constant term. */
1801
1802 if (XEXP (*p, 0) != 0)
1803 {
1804 tem = find_constant_term_loc (&XEXP (*p, 0));
1805 if (tem != 0)
1806 return tem;
1807 }
1808
1809 if (XEXP (*p, 1) != 0)
1810 {
1811 tem = find_constant_term_loc (&XEXP (*p, 1));
1812 if (tem != 0)
1813 return tem;
1814 }
1815
1816 return 0;
1817}
1818\f
1819/* Return 1 if OP is a memory reference
1820 whose address contains no side effects
1821 and remains valid after the addition
1822 of a positive integer less than the
1823 size of the object being referenced.
1824
1825 We assume that the original address is valid and do not check it.
1826
1827 This uses strict_memory_address_p as a subroutine, so
1828 don't use it before reload. */
1829
1830int
1831offsettable_memref_p (op)
1832 rtx op;
1833{
1834 return ((GET_CODE (op) == MEM)
1835 && offsettable_address_p (1, GET_MODE (op), XEXP (op, 0)));
1836}
1837
1838/* Similar, but don't require a strictly valid mem ref:
1839 consider pseudo-regs valid as index or base regs. */
1840
1841int
1842offsettable_nonstrict_memref_p (op)
1843 rtx op;
1844{
1845 return ((GET_CODE (op) == MEM)
1846 && offsettable_address_p (0, GET_MODE (op), XEXP (op, 0)));
1847}
1848
1849/* Return 1 if Y is a memory address which contains no side effects
1850 and would remain valid after the addition of a positive integer
1851 less than the size of that mode.
1852
1853 We assume that the original address is valid and do not check it.
1854 We do check that it is valid for narrower modes.
1855
1856 If STRICTP is nonzero, we require a strictly valid address,
1857 for the sake of use in reload.c. */
1858
1859int
1860offsettable_address_p (strictp, mode, y)
1861 int strictp;
1862 enum machine_mode mode;
1863 register rtx y;
1864{
1865 register enum rtx_code ycode = GET_CODE (y);
1866 register rtx z;
1867 rtx y1 = y;
1868 rtx *y2;
1869 int (*addressp) () = (strictp ? strict_memory_address_p : memory_address_p);
1870
1871 if (CONSTANT_ADDRESS_P (y))
1872 return 1;
1873
1874 /* Adjusting an offsettable address involves changing to a narrower mode.
1875 Make sure that's OK. */
1876
1877 if (mode_dependent_address_p (y))
1878 return 0;
1879
1880 /* If the expression contains a constant term,
1881 see if it remains valid when max possible offset is added. */
1882
1883 if ((ycode == PLUS) && (y2 = find_constant_term_loc (&y1)))
1884 {
1885 int good;
1886
1887 y1 = *y2;
1888 *y2 = plus_constant (*y2, GET_MODE_SIZE (mode) - 1);
1889 /* Use QImode because an odd displacement may be automatically invalid
1890 for any wider mode. But it should be valid for a single byte. */
1891 good = (*addressp) (QImode, y);
1892
1893 /* In any case, restore old contents of memory. */
1894 *y2 = y1;
1895 return good;
1896 }
1897
1898 if (ycode == PRE_DEC || ycode == PRE_INC
1899 || ycode == POST_DEC || ycode == POST_INC)
1900 return 0;
1901
1902 /* The offset added here is chosen as the maximum offset that
1903 any instruction could need to add when operating on something
1904 of the specified mode. We assume that if Y and Y+c are
1905 valid addresses then so is Y+d for all 0<d<c. */
1906
1907 z = plus_constant_for_output (y, GET_MODE_SIZE (mode) - 1);
1908
1909 /* Use QImode because an odd displacement may be automatically invalid
1910 for any wider mode. But it should be valid for a single byte. */
1911 return (*addressp) (QImode, z);
1912}
1913
1914/* Return 1 if ADDR is an address-expression whose effect depends
1915 on the mode of the memory reference it is used in.
1916
1917 Autoincrement addressing is a typical example of mode-dependence
1918 because the amount of the increment depends on the mode. */
1919
1920int
1921mode_dependent_address_p (addr)
47c3ed98 1922 rtx addr ATTRIBUTE_UNUSED; /* Maybe used in GO_IF_MODE_DEPENDENT_ADDRESS. */
2055cea7
RK
1923{
1924 GO_IF_MODE_DEPENDENT_ADDRESS (addr, win);
1925 return 0;
47c3ed98
KG
1926 /* Label `win' might (not) be used via GO_IF_MODE_DEPENDENT_ADDRESS. */
1927 win: ATTRIBUTE_UNUSED_LABEL
2055cea7
RK
1928 return 1;
1929}
1930
1931/* Return 1 if OP is a general operand
1932 other than a memory ref with a mode dependent address. */
1933
1934int
1935mode_independent_operand (op, mode)
1936 enum machine_mode mode;
1937 rtx op;
1938{
1939 rtx addr;
1940
1941 if (! general_operand (op, mode))
1942 return 0;
1943
1944 if (GET_CODE (op) != MEM)
1945 return 1;
1946
1947 addr = XEXP (op, 0);
1948 GO_IF_MODE_DEPENDENT_ADDRESS (addr, lose);
1949 return 1;
47c3ed98
KG
1950 /* Label `lose' might (not) be used via GO_IF_MODE_DEPENDENT_ADDRESS. */
1951 lose: ATTRIBUTE_UNUSED_LABEL
2055cea7
RK
1952 return 0;
1953}
1954
1955/* Given an operand OP that is a valid memory reference
1956 which satisfies offsettable_memref_p,
1957 return a new memory reference whose address has been adjusted by OFFSET.
1958 OFFSET should be positive and less than the size of the object referenced.
1959*/
1960
1961rtx
1962adj_offsettable_operand (op, offset)
1963 rtx op;
1964 int offset;
1965{
1966 register enum rtx_code code = GET_CODE (op);
1967
1968 if (code == MEM)
1969 {
1970 register rtx y = XEXP (op, 0);
1971 register rtx new;
1972
1973 if (CONSTANT_ADDRESS_P (y))
1974 {
c5c76735
JL
1975 new = gen_rtx_MEM (GET_MODE (op),
1976 plus_constant_for_output (y, offset));
2055cea7
RK
1977 RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (op);
1978 return new;
1979 }
1980
1981 if (GET_CODE (y) == PLUS)
1982 {
1983 rtx z = y;
1984 register rtx *const_loc;
1985
1986 op = copy_rtx (op);
1987 z = XEXP (op, 0);
1988 const_loc = find_constant_term_loc (&z);
1989 if (const_loc)
1990 {
1991 *const_loc = plus_constant_for_output (*const_loc, offset);
1992 return op;
1993 }
1994 }
1995
38a448ca 1996 new = gen_rtx_MEM (GET_MODE (op), plus_constant_for_output (y, offset));
2055cea7
RK
1997 RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (op);
1998 return new;
1999 }
2000 abort ();
2001}
2002\f
0a578fee
BS
2003/* Analyze INSN and compute the variables recog_n_operands, recog_n_dups,
2004 recog_n_alternatives, recog_operand, recog_operand_loc, recog_constraints,
2005 recog_operand_mode, recog_dup_loc and recog_dup_num.
2006 If REGISTER_CONSTRAINTS is not defined, also compute
2007 recog_operand_address_p. */
2008void
2009extract_insn (insn)
2010 rtx insn;
2011{
2012 int i;
2013 int icode;
2014 int noperands;
2015 rtx body = PATTERN (insn);
2016
2017 recog_n_operands = 0;
2018 recog_n_alternatives = 0;
2019 recog_n_dups = 0;
2020
2021 switch (GET_CODE (body))
2022 {
2023 case USE:
2024 case CLOBBER:
2025 case ASM_INPUT:
2026 case ADDR_VEC:
2027 case ADDR_DIFF_VEC:
2028 return;
2029
2030 case SET:
2031 case PARALLEL:
2032 case ASM_OPERANDS:
2033 recog_n_operands = noperands = asm_noperands (body);
2034 if (noperands >= 0)
2035 {
0a578fee
BS
2036 /* This insn is an `asm' with operands. */
2037
2038 /* expand_asm_operands makes sure there aren't too many operands. */
2039 if (noperands > MAX_RECOG_OPERANDS)
2040 abort ();
2041
2042 /* Now get the operand values and constraints out of the insn. */
2043 decode_asm_operands (body, recog_operand, recog_operand_loc,
2044 recog_constraints, recog_operand_mode);
2045 if (noperands > 0)
2046 {
9b3142b3 2047 const char *p = recog_constraints[0];
0a578fee
BS
2048 recog_n_alternatives = 1;
2049 while (*p)
2050 recog_n_alternatives += (*p++ == ',');
2051 }
2052#ifndef REGISTER_CONSTRAINTS
2053 bzero (recog_operand_address_p, sizeof recog_operand_address_p);
2054#endif
2055 break;
2056 }
2057
2058 /* FALLTHROUGH */
2059
2060 default:
2061 /* Ordinary insn: recognize it, get the operands via insn_extract
2062 and get the constraints. */
2063
2064 icode = recog_memoized (insn);
2065 if (icode < 0)
2066 fatal_insn_not_found (insn);
2067
2068 recog_n_operands = noperands = insn_n_operands[icode];
2069 recog_n_alternatives = insn_n_alternatives[icode];
2070 recog_n_dups = insn_n_dups[icode];
2071
2072 insn_extract (insn);
2073
2074 for (i = 0; i < noperands; i++)
2075 {
2076#ifdef REGISTER_CONSTRAINTS
2077 recog_constraints[i] = insn_operand_constraint[icode][i];
2078#else
2079 recog_operand_address_p[i] = insn_operand_address_p[icode][i];
2080#endif
2081 recog_operand_mode[i] = insn_operand_mode[icode][i];
2082 }
2083 }
0eadeb15
BS
2084 for (i = 0; i < noperands; i++)
2085 recog_op_type[i] = (recog_constraints[i][0] == '=' ? OP_OUT
2086 : recog_constraints[i][0] == '+' ? OP_INOUT
2087 : OP_IN);
f62a15e3
BS
2088
2089 if (recog_n_alternatives > MAX_RECOG_ALTERNATIVES)
2090 abort ();
0a578fee
BS
2091}
2092
f62a15e3
BS
2093/* After calling extract_insn, you can use this function to extract some
2094 information from the constraint strings into a more usable form.
2095 The collected data is stored in recog_op_alt. */
2096void
2097preprocess_constraints ()
2098{
2099 int i;
2100
cc3dea85 2101 bzero (recog_op_alt, sizeof recog_op_alt);
f62a15e3
BS
2102 for (i = 0; i < recog_n_operands; i++)
2103 {
2104 int j;
2105 struct operand_alternative *op_alt;
9b3142b3 2106 const char *p = recog_constraints[i];
f62a15e3
BS
2107
2108 op_alt = recog_op_alt[i];
2109
2110 for (j = 0; j < recog_n_alternatives; j++)
2111 {
2112 op_alt[j].class = NO_REGS;
2113 op_alt[j].constraint = p;
2114 op_alt[j].matches = -1;
2115 op_alt[j].matched = -1;
2116
2117 if (*p == '\0' || *p == ',')
2118 {
2119 op_alt[j].anything_ok = 1;
2120 continue;
2121 }
2122
2123 for (;;)
2124 {
2125 char c = *p++;
2126 if (c == '#')
2127 do
2128 c = *p++;
2129 while (c != ',' && c != '\0');
2130 if (c == ',' || c == '\0')
2131 break;
2132
2133 switch (c)
2134 {
2135 case '=': case '+': case '*': case '%':
2136 case 'E': case 'F': case 'G': case 'H':
2137 case 's': case 'i': case 'n':
2138 case 'I': case 'J': case 'K': case 'L':
2139 case 'M': case 'N': case 'O': case 'P':
2140#ifdef EXTRA_CONSTRAINT
2141 case 'Q': case 'R': case 'S': case 'T': case 'U':
2142#endif
2143 /* These don't say anything we care about. */
2144 break;
2145
2146 case '?':
2147 op_alt[j].reject += 6;
2148 break;
2149 case '!':
2150 op_alt[j].reject += 600;
2151 break;
2152 case '&':
2153 op_alt[j].earlyclobber = 1;
2154 break;
2155
2156 case '0': case '1': case '2': case '3': case '4':
2157 case '5': case '6': case '7': case '8': case '9':
2158 op_alt[j].matches = c - '0';
2159 op_alt[op_alt[j].matches].matched = i;
2160 break;
2161
2162 case 'm':
2163 op_alt[j].memory_ok = 1;
2164 break;
2165 case '<':
2166 op_alt[j].decmem_ok = 1;
2167 break;
2168 case '>':
2169 op_alt[j].incmem_ok = 1;
2170 break;
2171 case 'V':
2172 op_alt[j].nonoffmem_ok = 1;
2173 break;
2174 case 'o':
2175 op_alt[j].offmem_ok = 1;
2176 break;
2177 case 'X':
2178 op_alt[j].anything_ok = 1;
2179 break;
2180
2181 case 'p':
2182 op_alt[j].class = reg_class_subunion[(int) op_alt[j].class][(int) BASE_REG_CLASS];
2183 break;
2184
2185 case 'g': case 'r':
2186 op_alt[j].class = reg_class_subunion[(int) op_alt[j].class][(int) GENERAL_REGS];
2187 break;
2188
2189 default:
973838fd 2190 op_alt[j].class = reg_class_subunion[(int) op_alt[j].class][(int) REG_CLASS_FROM_LETTER ((unsigned char)c)];
f62a15e3
BS
2191 break;
2192 }
2193 }
2194 }
2195 }
2196}
2197
2055cea7
RK
2198#ifdef REGISTER_CONSTRAINTS
2199
0eadeb15 2200/* Check the operands of an insn against the insn's operand constraints
2055cea7 2201 and return 1 if they are valid.
0eadeb15
BS
2202 The information about the insn's operands, constraints, operand modes
2203 etc. is obtained from the global variables set up by extract_insn.
2055cea7
RK
2204
2205 WHICH_ALTERNATIVE is set to a number which indicates which
2206 alternative of constraints was matched: 0 for the first alternative,
2207 1 for the next, etc.
2208
2209 In addition, when two operands are match
2210 and it happens that the output operand is (reg) while the
2211 input operand is --(reg) or ++(reg) (a pre-inc or pre-dec),
2212 make the output operand look like the input.
2213 This is because the output operand is the one the template will print.
2214
2215 This is used in final, just before printing the assembler code and by
2216 the routines that determine an insn's attribute.
2217
2218 If STRICT is a positive non-zero value, it means that we have been
2219 called after reload has been completed. In that case, we must
2220 do all checks strictly. If it is zero, it means that we have been called
2221 before reload has completed. In that case, we first try to see if we can
2222 find an alternative that matches strictly. If not, we try again, this
2223 time assuming that reload will fix up the insn. This provides a "best
2224 guess" for the alternative and is used to compute attributes of insns prior
2225 to reload. A negative value of STRICT is used for this internal call. */
2226
2227struct funny_match
2228{
2229 int this, other;
2230};
2231
2232int
0eadeb15 2233constrain_operands (strict)
2055cea7
RK
2234 int strict;
2235{
9b3142b3 2236 const char *constraints[MAX_RECOG_OPERANDS];
9e21be9d 2237 int matching_operands[MAX_RECOG_OPERANDS];
9e21be9d 2238 int earlyclobber[MAX_RECOG_OPERANDS];
2055cea7 2239 register int c;
2055cea7
RK
2240
2241 struct funny_match funny_match[MAX_RECOG_OPERANDS];
2242 int funny_match_index;
2055cea7 2243
0eadeb15 2244 if (recog_n_operands == 0 || recog_n_alternatives == 0)
2055cea7
RK
2245 return 1;
2246
0eadeb15 2247 for (c = 0; c < recog_n_operands; c++)
9e21be9d 2248 {
0eadeb15 2249 constraints[c] = recog_constraints[c];
9e21be9d 2250 matching_operands[c] = -1;
9e21be9d 2251 }
2055cea7
RK
2252
2253 which_alternative = 0;
2254
0eadeb15 2255 while (which_alternative < recog_n_alternatives)
2055cea7
RK
2256 {
2257 register int opno;
2258 int lose = 0;
2259 funny_match_index = 0;
2260
0eadeb15 2261 for (opno = 0; opno < recog_n_operands; opno++)
2055cea7
RK
2262 {
2263 register rtx op = recog_operand[opno];
2264 enum machine_mode mode = GET_MODE (op);
9b3142b3 2265 register const char *p = constraints[opno];
2055cea7
RK
2266 int offset = 0;
2267 int win = 0;
2268 int val;
2269
9e21be9d
RK
2270 earlyclobber[opno] = 0;
2271
b85f21c0 2272 /* A unary operator may be accepted by the predicate, but it
38a448ca 2273 is irrelevant for matching constraints. */
b85f21c0
ILT
2274 if (GET_RTX_CLASS (GET_CODE (op)) == '1')
2275 op = XEXP (op, 0);
2276
2055cea7
RK
2277 if (GET_CODE (op) == SUBREG)
2278 {
2279 if (GET_CODE (SUBREG_REG (op)) == REG
2280 && REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER)
2281 offset = SUBREG_WORD (op);
2282 op = SUBREG_REG (op);
2283 }
2284
2285 /* An empty constraint or empty alternative
2286 allows anything which matched the pattern. */
2287 if (*p == 0 || *p == ',')
2288 win = 1;
2289
2290 while (*p && (c = *p++) != ',')
2291 switch (c)
2292 {
c5c76735
JL
2293 case '?': case '!': case '*': case '%':
2294 case '=': case '+':
2055cea7
RK
2295 break;
2296
4d3067db
RK
2297 case '#':
2298 /* Ignore rest of this alternative as far as
2299 constraint checking is concerned. */
2300 while (*p && *p != ',')
2301 p++;
2302 break;
2303
9e21be9d
RK
2304 case '&':
2305 earlyclobber[opno] = 1;
2306 break;
2307
c5c76735
JL
2308 case '0': case '1': case '2': case '3': case '4':
2309 case '5': case '6': case '7': case '8': case '9':
2310
2055cea7
RK
2311 /* This operand must be the same as a previous one.
2312 This kind of constraint is used for instructions such
2313 as add when they take only two operands.
2314
2315 Note that the lower-numbered operand is passed first.
2316
2317 If we are not testing strictly, assume that this constraint
2318 will be satisfied. */
2319 if (strict < 0)
2320 val = 1;
2321 else
62674ffe
JH
2322 {
2323 rtx op1 = recog_operand[c - '0'];
2324 rtx op2 = recog_operand[opno];
2325
2326 /* A unary operator may be accepted by the predicate,
2327 but it is irrelevant for matching constraints. */
2328 if (GET_RTX_CLASS (GET_CODE (op1)) == '1')
2329 op1 = XEXP (op1, 0);
2330 if (GET_RTX_CLASS (GET_CODE (op2)) == '1')
2331 op2 = XEXP (op2, 0);
2332
2333 val = operands_match_p (op1, op2);
2334 }
2055cea7 2335
9e21be9d
RK
2336 matching_operands[opno] = c - '0';
2337 matching_operands[c - '0'] = opno;
2338
2055cea7
RK
2339 if (val != 0)
2340 win = 1;
2341 /* If output is *x and input is *--x,
2342 arrange later to change the output to *--x as well,
2343 since the output op is the one that will be printed. */
2344 if (val == 2 && strict > 0)
2345 {
2346 funny_match[funny_match_index].this = opno;
2347 funny_match[funny_match_index++].other = c - '0';
2348 }
2349 break;
2350
2351 case 'p':
2352 /* p is used for address_operands. When we are called by
a8647766
RK
2353 gen_reload, no one will have checked that the address is
2354 strictly valid, i.e., that all pseudos requiring hard regs
2355 have gotten them. */
2055cea7 2356 if (strict <= 0
0eadeb15
BS
2357 || (strict_memory_address_p (recog_operand_mode[opno],
2358 op)))
2055cea7
RK
2359 win = 1;
2360 break;
2361
2362 /* No need to check general_operand again;
2363 it was done in insn-recog.c. */
2364 case 'g':
2365 /* Anything goes unless it is a REG and really has a hard reg
2366 but the hard reg is not in the class GENERAL_REGS. */
2367 if (strict < 0
2368 || GENERAL_REGS == ALL_REGS
2369 || GET_CODE (op) != REG
3c3eeea6
RK
2370 || (reload_in_progress
2371 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2055cea7
RK
2372 || reg_fits_class_p (op, GENERAL_REGS, offset, mode))
2373 win = 1;
2374 break;
2375
2376 case 'r':
2377 if (strict < 0
2378 || (strict == 0
2379 && GET_CODE (op) == REG
2380 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2381 || (strict == 0 && GET_CODE (op) == SCRATCH)
2382 || (GET_CODE (op) == REG
5a19ad3f
RK
2383 && ((GENERAL_REGS == ALL_REGS
2384 && REGNO (op) < FIRST_PSEUDO_REGISTER)
2055cea7
RK
2385 || reg_fits_class_p (op, GENERAL_REGS,
2386 offset, mode))))
2387 win = 1;
2388 break;
2389
2390 case 'X':
0f41302f
MS
2391 /* This is used for a MATCH_SCRATCH in the cases when
2392 we don't actually need anything. So anything goes
2393 any time. */
2055cea7
RK
2394 win = 1;
2395 break;
2396
2397 case 'm':
2398 if (GET_CODE (op) == MEM
2399 /* Before reload, accept what reload can turn into mem. */
3c3eeea6
RK
2400 || (strict < 0 && CONSTANT_P (op))
2401 /* During reload, accept a pseudo */
2402 || (reload_in_progress && GET_CODE (op) == REG
2403 && REGNO (op) >= FIRST_PSEUDO_REGISTER))
2055cea7
RK
2404 win = 1;
2405 break;
2406
2407 case '<':
2408 if (GET_CODE (op) == MEM
2409 && (GET_CODE (XEXP (op, 0)) == PRE_DEC
2410 || GET_CODE (XEXP (op, 0)) == POST_DEC))
2411 win = 1;
2412 break;
2413
2414 case '>':
2415 if (GET_CODE (op) == MEM
2416 && (GET_CODE (XEXP (op, 0)) == PRE_INC
2417 || GET_CODE (XEXP (op, 0)) == POST_INC))
2418 win = 1;
2419 break;
2420
2421 case 'E':
b990f635 2422#ifndef REAL_ARITHMETIC
2055cea7
RK
2423 /* Match any CONST_DOUBLE, but only if
2424 we can examine the bits of it reliably. */
2425 if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
9e4223f2 2426 || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD)
d1b765a5 2427 && GET_MODE (op) != VOIDmode && ! flag_pretend_float)
2055cea7 2428 break;
b990f635 2429#endif
2055cea7
RK
2430 if (GET_CODE (op) == CONST_DOUBLE)
2431 win = 1;
2432 break;
2433
2434 case 'F':
2435 if (GET_CODE (op) == CONST_DOUBLE)
2436 win = 1;
2437 break;
2438
2439 case 'G':
2440 case 'H':
2441 if (GET_CODE (op) == CONST_DOUBLE
2442 && CONST_DOUBLE_OK_FOR_LETTER_P (op, c))
2443 win = 1;
2444 break;
2445
2446 case 's':
2447 if (GET_CODE (op) == CONST_INT
2448 || (GET_CODE (op) == CONST_DOUBLE
2449 && GET_MODE (op) == VOIDmode))
2450 break;
2451 case 'i':
2452 if (CONSTANT_P (op))
2453 win = 1;
2454 break;
2455
2456 case 'n':
2457 if (GET_CODE (op) == CONST_INT
2458 || (GET_CODE (op) == CONST_DOUBLE
2459 && GET_MODE (op) == VOIDmode))
2460 win = 1;
2461 break;
2462
2463 case 'I':
2464 case 'J':
2465 case 'K':
2466 case 'L':
2467 case 'M':
2468 case 'N':
2469 case 'O':
2470 case 'P':
2471 if (GET_CODE (op) == CONST_INT
2472 && CONST_OK_FOR_LETTER_P (INTVAL (op), c))
2473 win = 1;
2474 break;
2475
2476#ifdef EXTRA_CONSTRAINT
2477 case 'Q':
2478 case 'R':
2479 case 'S':
2480 case 'T':
2481 case 'U':
2482 if (EXTRA_CONSTRAINT (op, c))
2483 win = 1;
2484 break;
2485#endif
2486
2487 case 'V':
2488 if (GET_CODE (op) == MEM
69f724c0
JL
2489 && ((strict > 0 && ! offsettable_memref_p (op))
2490 || (strict < 0
2491 && !(CONSTANT_P (op) || GET_CODE (op) == MEM))
2492 || (reload_in_progress
2493 && !(GET_CODE (op) == REG
2494 && REGNO (op) >= FIRST_PSEUDO_REGISTER))))
2055cea7
RK
2495 win = 1;
2496 break;
2497
2498 case 'o':
2499 if ((strict > 0 && offsettable_memref_p (op))
2500 || (strict == 0 && offsettable_nonstrict_memref_p (op))
2501 /* Before reload, accept what reload can handle. */
2502 || (strict < 0
3c3eeea6
RK
2503 && (CONSTANT_P (op) || GET_CODE (op) == MEM))
2504 /* During reload, accept a pseudo */
2505 || (reload_in_progress && GET_CODE (op) == REG
2506 && REGNO (op) >= FIRST_PSEUDO_REGISTER))
2055cea7
RK
2507 win = 1;
2508 break;
2509
2510 default:
2511 if (strict < 0
2512 || (strict == 0
2513 && GET_CODE (op) == REG
2514 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
2515 || (strict == 0 && GET_CODE (op) == SCRATCH)
2516 || (GET_CODE (op) == REG
2517 && reg_fits_class_p (op, REG_CLASS_FROM_LETTER (c),
2518 offset, mode)))
2519 win = 1;
2520 }
2521
2522 constraints[opno] = p;
2523 /* If this operand did not win somehow,
2524 this alternative loses. */
2525 if (! win)
2526 lose = 1;
2527 }
2528 /* This alternative won; the operands are ok.
2529 Change whichever operands this alternative says to change. */
2530 if (! lose)
2531 {
9e21be9d
RK
2532 int opno, eopno;
2533
2534 /* See if any earlyclobber operand conflicts with some other
2535 operand. */
2536
2537 if (strict > 0)
0eadeb15 2538 for (eopno = 0; eopno < recog_n_operands; eopno++)
62946075
RS
2539 /* Ignore earlyclobber operands now in memory,
2540 because we would often report failure when we have
2541 two memory operands, one of which was formerly a REG. */
2542 if (earlyclobber[eopno]
2543 && GET_CODE (recog_operand[eopno]) == REG)
0eadeb15 2544 for (opno = 0; opno < recog_n_operands; opno++)
9e21be9d 2545 if ((GET_CODE (recog_operand[opno]) == MEM
0eadeb15 2546 || recog_op_type[opno] != OP_OUT)
9e21be9d 2547 && opno != eopno
0f41302f 2548 /* Ignore things like match_operator operands. */
0eadeb15 2549 && *recog_constraints[opno] != 0
9e21be9d 2550 && ! (matching_operands[opno] == eopno
011063bd
JW
2551 && operands_match_p (recog_operand[opno],
2552 recog_operand[eopno]))
9e21be9d
RK
2553 && ! safe_from_earlyclobber (recog_operand[opno],
2554 recog_operand[eopno]))
2555 lose = 1;
2556
2557 if (! lose)
2055cea7 2558 {
9e21be9d
RK
2559 while (--funny_match_index >= 0)
2560 {
2561 recog_operand[funny_match[funny_match_index].other]
2562 = recog_operand[funny_match[funny_match_index].this];
2563 }
2564
2565 return 1;
2055cea7 2566 }
2055cea7
RK
2567 }
2568
2569 which_alternative++;
2570 }
2571
2572 /* If we are about to reject this, but we are not to test strictly,
2573 try a very loose test. Only return failure if it fails also. */
2574 if (strict == 0)
0eadeb15 2575 return constrain_operands (-1);
2055cea7
RK
2576 else
2577 return 0;
2578}
2579
2580/* Return 1 iff OPERAND (assumed to be a REG rtx)
38a448ca 2581 is a hard reg in class CLASS when its regno is offset by OFFSET
2055cea7
RK
2582 and changed to mode MODE.
2583 If REG occupies multiple hard regs, all of them must be in CLASS. */
2584
2585int
2586reg_fits_class_p (operand, class, offset, mode)
2587 rtx operand;
2588 register enum reg_class class;
2589 int offset;
2590 enum machine_mode mode;
2591{
2592 register int regno = REGNO (operand);
2593 if (regno < FIRST_PSEUDO_REGISTER
2594 && TEST_HARD_REG_BIT (reg_class_contents[(int) class],
2595 regno + offset))
2596 {
2597 register int sr;
2598 regno += offset;
2599 for (sr = HARD_REGNO_NREGS (regno, mode) - 1;
2600 sr > 0; sr--)
2601 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
2602 regno + sr))
2603 break;
2604 return sr == 0;
2605 }
2606
2607 return 0;
2608}
2609
2610#endif /* REGISTER_CONSTRAINTS */
ca545bb5
BM
2611\f
2612/* Do the splitting of insns in the block B. Only try to actually split if
2613 DO_SPLIT is true; otherwise, just remove nops. */
2614
2615void
2616split_block_insns (b, do_split)
2617 int b;
2618 int do_split;
2619{
2620 rtx insn, next;
2621
2622 for (insn = BLOCK_HEAD (b);; insn = next)
2623 {
2624 rtx set;
2625
2626 /* Can't use `next_real_insn' because that
2627 might go across CODE_LABELS and short-out basic blocks. */
2628 next = NEXT_INSN (insn);
2629 if (GET_CODE (insn) != INSN)
2630 {
2631 if (insn == BLOCK_END (b))
2632 break;
2633
2634 continue;
2635 }
2636
2637 /* Don't split no-op move insns. These should silently disappear
2638 later in final. Splitting such insns would break the code
2639 that handles REG_NO_CONFLICT blocks. */
2640 set = single_set (insn);
2641 if (set && rtx_equal_p (SET_SRC (set), SET_DEST (set)))
2642 {
2643 if (insn == BLOCK_END (b))
2644 break;
2645
2646 /* Nops get in the way while scheduling, so delete them now if
2647 register allocation has already been done. It is too risky
2648 to try to do this before register allocation, and there are
2649 unlikely to be very many nops then anyways. */
2650 if (reload_completed)
2651 {
2652
2653 PUT_CODE (insn, NOTE);
2654 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2655 NOTE_SOURCE_FILE (insn) = 0;
2656 }
2657
2658 continue;
2659 }
2660
2661 if (do_split)
2662 {
2663 /* Split insns here to get max fine-grain parallelism. */
2664 rtx first = PREV_INSN (insn);
2665 rtx notes = REG_NOTES (insn);
2666 rtx last = try_split (PATTERN (insn), insn, 1);
2667
2668 if (last != insn)
2669 {
2670 /* try_split returns the NOTE that INSN became. */
2671 first = NEXT_INSN (first);
3c4fc1cc 2672#ifdef INSN_SCHEDULING
f2a1bc02 2673 update_life_info (notes, first, last, insn, insn);
bbf9d88c 2674#endif
ca545bb5
BM
2675 PUT_CODE (insn, NOTE);
2676 NOTE_SOURCE_FILE (insn) = 0;
2677 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2678 if (insn == BLOCK_HEAD (b))
2679 BLOCK_HEAD (b) = first;
2680 if (insn == BLOCK_END (b))
2681 {
2682 BLOCK_END (b) = last;
2683 break;
2684 }
2685 }
2686 }
2687
2688 if (insn == BLOCK_END (b))
2689 break;
2690 }
2691}
ede7cd44
RH
2692\f
2693#ifdef HAVE_peephole2
2694/* Return the Nth non-note insn after INSN, or return NULL_RTX if it does
2695 not exist. Used by the recognizer to find the next insn to match in a
2696 multi-insn pattern. */
2697rtx
2698recog_next_insn (insn, n)
2699 rtx insn;
2700 int n;
2701{
2702 while (insn != NULL_RTX && n > 0)
2703 {
2704 insn = next_nonnote_insn (insn);
2705
2706 if (insn == NULL_RTX)
2707 return insn;
2708
2709 if (GET_RTX_CLASS (GET_CODE (insn)) != 'i')
2710 return NULL_RTX;
2711
2712 n--;
2713 }
2714
2715 return insn;
2716}
2717
2718/* Perform the peephole2 optimization pass. */
2719void
2720peephole2_optimize (dump_file)
2721 FILE *dump_file ATTRIBUTE_UNUSED;
2722{
2723 rtx insn;
2724 rtx epilogue_insn = 0;
2725
2726 for (insn = get_last_insn (); insn != NULL_RTX; insn = PREV_INSN (insn))
2727 {
2728 if (GET_CODE (insn) == NOTE
2729 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
2730 {
2731 epilogue_insn = insn;
2732 break;
2733 }
2734 }
2735
2736 init_resource_info (epilogue_insn);
2737
2738 for (insn = get_insns (); insn != NULL;
2739 insn = next_nonnote_insn (insn))
2740 {
2741 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN)
2742 {
2743 rtx last_insn;
2744 rtx before = PREV_INSN (insn);
2745
2746 rtx try = peephole2_insns (PATTERN (insn), insn, &last_insn);
2747 if (try != NULL)
2748 {
2749 replace_insns (insn, last_insn, try, NULL_RTX);
2750 insn = NEXT_INSN (before);
2751 }
2752 }
2753 }
2754
2755 free_resource_info ();
2756}
2757#endif
This page took 1.396231 seconds and 5 git commands to generate.