Mark ChangeLog
[official-gcc.git] / gcc / emit-rtl.c
blob3041b9e7a182d52e67b936374bfe5949af780b58
1 /* Emit RTL for the GCC expander.
2 Copyright (C) 1987-2014 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
21 /* Middle-to-low level generation of rtx code and insns.
23 This file contains support functions for creating rtl expressions
24 and manipulating them in the doubly-linked chain of insns.
26 The patterns of the insns are created by machine-dependent
27 routines in insn-emit.c, which is generated automatically from
28 the machine description. These routines make the individual rtx's
29 of the pattern with `gen_rtx_fmt_ee' and others in genrtl.[ch],
30 which are automatically generated from rtl.def; what is machine
31 dependent is the kind of rtx's they make and what arguments they
32 use. */
34 #include "config.h"
35 #include "system.h"
36 #include "coretypes.h"
37 #include "tm.h"
38 #include "diagnostic-core.h"
39 #include "rtl.h"
40 #include "tree.h"
41 #include "varasm.h"
42 #include "basic-block.h"
43 #include "tree-eh.h"
44 #include "tm_p.h"
45 #include "flags.h"
46 #include "function.h"
47 #include "stringpool.h"
48 #include "expr.h"
49 #include "regs.h"
50 #include "hard-reg-set.h"
51 #include "hashtab.h"
52 #include "insn-config.h"
53 #include "recog.h"
54 #include "bitmap.h"
55 #include "debug.h"
56 #include "langhooks.h"
57 #include "df.h"
58 #include "params.h"
59 #include "target.h"
61 struct target_rtl default_target_rtl;
62 #if SWITCHABLE_TARGET
63 struct target_rtl *this_target_rtl = &default_target_rtl;
64 #endif
66 #define initial_regno_reg_rtx (this_target_rtl->x_initial_regno_reg_rtx)
68 /* Commonly used modes. */
70 enum machine_mode byte_mode; /* Mode whose width is BITS_PER_UNIT. */
71 enum machine_mode word_mode; /* Mode whose width is BITS_PER_WORD. */
72 enum machine_mode double_mode; /* Mode whose width is DOUBLE_TYPE_SIZE. */
73 enum machine_mode ptr_mode; /* Mode whose width is POINTER_SIZE. */
75 /* Datastructures maintained for currently processed function in RTL form. */
77 struct rtl_data x_rtl;
79 /* Indexed by pseudo register number, gives the rtx for that pseudo.
80 Allocated in parallel with regno_pointer_align.
81 FIXME: We could put it into emit_status struct, but gengtype is not able to deal
82 with length attribute nested in top level structures. */
84 rtx * regno_reg_rtx;
86 /* This is *not* reset after each function. It gives each CODE_LABEL
87 in the entire compilation a unique label number. */
89 static GTY(()) int label_num = 1;
91 /* We record floating-point CONST_DOUBLEs in each floating-point mode for
92 the values of 0, 1, and 2. For the integer entries and VOIDmode, we
93 record a copy of const[012]_rtx and constm1_rtx. CONSTM1_RTX
94 is set only for MODE_INT and MODE_VECTOR_INT modes. */
96 rtx const_tiny_rtx[4][(int) MAX_MACHINE_MODE];
98 rtx const_true_rtx;
100 REAL_VALUE_TYPE dconst0;
101 REAL_VALUE_TYPE dconst1;
102 REAL_VALUE_TYPE dconst2;
103 REAL_VALUE_TYPE dconstm1;
104 REAL_VALUE_TYPE dconsthalf;
106 /* Record fixed-point constant 0 and 1. */
107 FIXED_VALUE_TYPE fconst0[MAX_FCONST0];
108 FIXED_VALUE_TYPE fconst1[MAX_FCONST1];
110 /* We make one copy of (const_int C) where C is in
111 [- MAX_SAVED_CONST_INT, MAX_SAVED_CONST_INT]
112 to save space during the compilation and simplify comparisons of
113 integers. */
115 rtx const_int_rtx[MAX_SAVED_CONST_INT * 2 + 1];
117 /* Standard pieces of rtx, to be substituted directly into things. */
118 rtx pc_rtx;
119 rtx ret_rtx;
120 rtx simple_return_rtx;
121 rtx cc0_rtx;
123 /* A hash table storing CONST_INTs whose absolute value is greater
124 than MAX_SAVED_CONST_INT. */
126 static GTY ((if_marked ("ggc_marked_p"), param_is (struct rtx_def)))
127 htab_t const_int_htab;
129 /* A hash table storing register attribute structures. */
130 static GTY ((if_marked ("ggc_marked_p"), param_is (struct reg_attrs)))
131 htab_t reg_attrs_htab;
133 /* A hash table storing all CONST_DOUBLEs. */
134 static GTY ((if_marked ("ggc_marked_p"), param_is (struct rtx_def)))
135 htab_t const_double_htab;
137 /* A hash table storing all CONST_FIXEDs. */
138 static GTY ((if_marked ("ggc_marked_p"), param_is (struct rtx_def)))
139 htab_t const_fixed_htab;
141 #define cur_insn_uid (crtl->emit.x_cur_insn_uid)
142 #define cur_debug_insn_uid (crtl->emit.x_cur_debug_insn_uid)
143 #define first_label_num (crtl->emit.x_first_label_num)
145 static rtx change_address_1 (rtx, enum machine_mode, rtx, int);
146 static void set_used_decls (tree);
147 static void mark_label_nuses (rtx);
148 static hashval_t const_int_htab_hash (const void *);
149 static int const_int_htab_eq (const void *, const void *);
150 static hashval_t const_double_htab_hash (const void *);
151 static int const_double_htab_eq (const void *, const void *);
152 static rtx lookup_const_double (rtx);
153 static hashval_t const_fixed_htab_hash (const void *);
154 static int const_fixed_htab_eq (const void *, const void *);
155 static rtx lookup_const_fixed (rtx);
156 static hashval_t reg_attrs_htab_hash (const void *);
157 static int reg_attrs_htab_eq (const void *, const void *);
158 static reg_attrs *get_reg_attrs (tree, int);
159 static rtx gen_const_vector (enum machine_mode, int);
160 static void copy_rtx_if_shared_1 (rtx *orig);
162 /* Probability of the conditional branch currently proceeded by try_split.
163 Set to -1 otherwise. */
164 int split_branch_probability = -1;
166 /* Returns a hash code for X (which is a really a CONST_INT). */
168 static hashval_t
169 const_int_htab_hash (const void *x)
171 return (hashval_t) INTVAL ((const_rtx) x);
174 /* Returns nonzero if the value represented by X (which is really a
175 CONST_INT) is the same as that given by Y (which is really a
176 HOST_WIDE_INT *). */
178 static int
179 const_int_htab_eq (const void *x, const void *y)
181 return (INTVAL ((const_rtx) x) == *((const HOST_WIDE_INT *) y));
184 /* Returns a hash code for X (which is really a CONST_DOUBLE). */
185 static hashval_t
186 const_double_htab_hash (const void *x)
188 const_rtx const value = (const_rtx) x;
189 hashval_t h;
191 if (GET_MODE (value) == VOIDmode)
192 h = CONST_DOUBLE_LOW (value) ^ CONST_DOUBLE_HIGH (value);
193 else
195 h = real_hash (CONST_DOUBLE_REAL_VALUE (value));
196 /* MODE is used in the comparison, so it should be in the hash. */
197 h ^= GET_MODE (value);
199 return h;
202 /* Returns nonzero if the value represented by X (really a ...)
203 is the same as that represented by Y (really a ...) */
204 static int
205 const_double_htab_eq (const void *x, const void *y)
207 const_rtx const a = (const_rtx)x, b = (const_rtx)y;
209 if (GET_MODE (a) != GET_MODE (b))
210 return 0;
211 if (GET_MODE (a) == VOIDmode)
212 return (CONST_DOUBLE_LOW (a) == CONST_DOUBLE_LOW (b)
213 && CONST_DOUBLE_HIGH (a) == CONST_DOUBLE_HIGH (b));
214 else
215 return real_identical (CONST_DOUBLE_REAL_VALUE (a),
216 CONST_DOUBLE_REAL_VALUE (b));
219 /* Returns a hash code for X (which is really a CONST_FIXED). */
221 static hashval_t
222 const_fixed_htab_hash (const void *x)
224 const_rtx const value = (const_rtx) x;
225 hashval_t h;
227 h = fixed_hash (CONST_FIXED_VALUE (value));
228 /* MODE is used in the comparison, so it should be in the hash. */
229 h ^= GET_MODE (value);
230 return h;
233 /* Returns nonzero if the value represented by X (really a ...)
234 is the same as that represented by Y (really a ...). */
236 static int
237 const_fixed_htab_eq (const void *x, const void *y)
239 const_rtx const a = (const_rtx) x, b = (const_rtx) y;
241 if (GET_MODE (a) != GET_MODE (b))
242 return 0;
243 return fixed_identical (CONST_FIXED_VALUE (a), CONST_FIXED_VALUE (b));
246 /* Return true if the given memory attributes are equal. */
248 bool
249 mem_attrs_eq_p (const struct mem_attrs *p, const struct mem_attrs *q)
251 if (p == q)
252 return true;
253 if (!p || !q)
254 return false;
255 return (p->alias == q->alias
256 && p->offset_known_p == q->offset_known_p
257 && (!p->offset_known_p || p->offset == q->offset)
258 && p->size_known_p == q->size_known_p
259 && (!p->size_known_p || p->size == q->size)
260 && p->align == q->align
261 && p->addrspace == q->addrspace
262 && (p->expr == q->expr
263 || (p->expr != NULL_TREE && q->expr != NULL_TREE
264 && operand_equal_p (p->expr, q->expr, 0))));
267 /* Set MEM's memory attributes so that they are the same as ATTRS. */
269 static void
270 set_mem_attrs (rtx mem, mem_attrs *attrs)
272 /* If everything is the default, we can just clear the attributes. */
273 if (mem_attrs_eq_p (attrs, mode_mem_attrs[(int) GET_MODE (mem)]))
275 MEM_ATTRS (mem) = 0;
276 return;
279 if (!MEM_ATTRS (mem)
280 || !mem_attrs_eq_p (attrs, MEM_ATTRS (mem)))
282 MEM_ATTRS (mem) = ggc_alloc_mem_attrs ();
283 memcpy (MEM_ATTRS (mem), attrs, sizeof (mem_attrs));
287 /* Returns a hash code for X (which is a really a reg_attrs *). */
289 static hashval_t
290 reg_attrs_htab_hash (const void *x)
292 const reg_attrs *const p = (const reg_attrs *) x;
294 return ((p->offset * 1000) ^ (intptr_t) p->decl);
297 /* Returns nonzero if the value represented by X (which is really a
298 reg_attrs *) is the same as that given by Y (which is also really a
299 reg_attrs *). */
301 static int
302 reg_attrs_htab_eq (const void *x, const void *y)
304 const reg_attrs *const p = (const reg_attrs *) x;
305 const reg_attrs *const q = (const reg_attrs *) y;
307 return (p->decl == q->decl && p->offset == q->offset);
309 /* Allocate a new reg_attrs structure and insert it into the hash table if
310 one identical to it is not already in the table. We are doing this for
311 MEM of mode MODE. */
313 static reg_attrs *
314 get_reg_attrs (tree decl, int offset)
316 reg_attrs attrs;
317 void **slot;
319 /* If everything is the default, we can just return zero. */
320 if (decl == 0 && offset == 0)
321 return 0;
323 attrs.decl = decl;
324 attrs.offset = offset;
326 slot = htab_find_slot (reg_attrs_htab, &attrs, INSERT);
327 if (*slot == 0)
329 *slot = ggc_alloc_reg_attrs ();
330 memcpy (*slot, &attrs, sizeof (reg_attrs));
333 return (reg_attrs *) *slot;
337 #if !HAVE_blockage
338 /* Generate an empty ASM_INPUT, which is used to block attempts to schedule,
339 and to block register equivalences to be seen across this insn. */
342 gen_blockage (void)
344 rtx x = gen_rtx_ASM_INPUT (VOIDmode, "");
345 MEM_VOLATILE_P (x) = true;
346 return x;
348 #endif
351 /* Generate a new REG rtx. Make sure ORIGINAL_REGNO is set properly, and
352 don't attempt to share with the various global pieces of rtl (such as
353 frame_pointer_rtx). */
356 gen_raw_REG (enum machine_mode mode, int regno)
358 rtx x = gen_rtx_raw_REG (mode, regno);
359 ORIGINAL_REGNO (x) = regno;
360 return x;
363 /* There are some RTL codes that require special attention; the generation
364 functions do the raw handling. If you add to this list, modify
365 special_rtx in gengenrtl.c as well. */
368 gen_rtx_CONST_INT (enum machine_mode mode ATTRIBUTE_UNUSED, HOST_WIDE_INT arg)
370 void **slot;
372 if (arg >= - MAX_SAVED_CONST_INT && arg <= MAX_SAVED_CONST_INT)
373 return const_int_rtx[arg + MAX_SAVED_CONST_INT];
375 #if STORE_FLAG_VALUE != 1 && STORE_FLAG_VALUE != -1
376 if (const_true_rtx && arg == STORE_FLAG_VALUE)
377 return const_true_rtx;
378 #endif
380 /* Look up the CONST_INT in the hash table. */
381 slot = htab_find_slot_with_hash (const_int_htab, &arg,
382 (hashval_t) arg, INSERT);
383 if (*slot == 0)
384 *slot = gen_rtx_raw_CONST_INT (VOIDmode, arg);
386 return (rtx) *slot;
390 gen_int_mode (HOST_WIDE_INT c, enum machine_mode mode)
392 return GEN_INT (trunc_int_for_mode (c, mode));
395 /* CONST_DOUBLEs might be created from pairs of integers, or from
396 REAL_VALUE_TYPEs. Also, their length is known only at run time,
397 so we cannot use gen_rtx_raw_CONST_DOUBLE. */
399 /* Determine whether REAL, a CONST_DOUBLE, already exists in the
400 hash table. If so, return its counterpart; otherwise add it
401 to the hash table and return it. */
402 static rtx
403 lookup_const_double (rtx real)
405 void **slot = htab_find_slot (const_double_htab, real, INSERT);
406 if (*slot == 0)
407 *slot = real;
409 return (rtx) *slot;
412 /* Return a CONST_DOUBLE rtx for a floating-point value specified by
413 VALUE in mode MODE. */
415 const_double_from_real_value (REAL_VALUE_TYPE value, enum machine_mode mode)
417 rtx real = rtx_alloc (CONST_DOUBLE);
418 PUT_MODE (real, mode);
420 real->u.rv = value;
422 return lookup_const_double (real);
425 /* Determine whether FIXED, a CONST_FIXED, already exists in the
426 hash table. If so, return its counterpart; otherwise add it
427 to the hash table and return it. */
429 static rtx
430 lookup_const_fixed (rtx fixed)
432 void **slot = htab_find_slot (const_fixed_htab, fixed, INSERT);
433 if (*slot == 0)
434 *slot = fixed;
436 return (rtx) *slot;
439 /* Return a CONST_FIXED rtx for a fixed-point value specified by
440 VALUE in mode MODE. */
443 const_fixed_from_fixed_value (FIXED_VALUE_TYPE value, enum machine_mode mode)
445 rtx fixed = rtx_alloc (CONST_FIXED);
446 PUT_MODE (fixed, mode);
448 fixed->u.fv = value;
450 return lookup_const_fixed (fixed);
453 /* Constructs double_int from rtx CST. */
455 double_int
456 rtx_to_double_int (const_rtx cst)
458 double_int r;
460 if (CONST_INT_P (cst))
461 r = double_int::from_shwi (INTVAL (cst));
462 else if (CONST_DOUBLE_AS_INT_P (cst))
464 r.low = CONST_DOUBLE_LOW (cst);
465 r.high = CONST_DOUBLE_HIGH (cst);
467 else
468 gcc_unreachable ();
470 return r;
474 /* Return a CONST_DOUBLE or CONST_INT for a value specified as
475 a double_int. */
478 immed_double_int_const (double_int i, enum machine_mode mode)
480 return immed_double_const (i.low, i.high, mode);
483 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair
484 of ints: I0 is the low-order word and I1 is the high-order word.
485 For values that are larger than HOST_BITS_PER_DOUBLE_INT, the
486 implied upper bits are copies of the high bit of i1. The value
487 itself is neither signed nor unsigned. Do not use this routine for
488 non-integer modes; convert to REAL_VALUE_TYPE and use
489 CONST_DOUBLE_FROM_REAL_VALUE. */
492 immed_double_const (HOST_WIDE_INT i0, HOST_WIDE_INT i1, enum machine_mode mode)
494 rtx value;
495 unsigned int i;
497 /* There are the following cases (note that there are no modes with
498 HOST_BITS_PER_WIDE_INT < GET_MODE_BITSIZE (mode) < HOST_BITS_PER_DOUBLE_INT):
500 1) If GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT, then we use
501 gen_int_mode.
502 2) If the value of the integer fits into HOST_WIDE_INT anyway
503 (i.e., i1 consists only from copies of the sign bit, and sign
504 of i0 and i1 are the same), then we return a CONST_INT for i0.
505 3) Otherwise, we create a CONST_DOUBLE for i0 and i1. */
506 if (mode != VOIDmode)
508 gcc_assert (GET_MODE_CLASS (mode) == MODE_INT
509 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT
510 /* We can get a 0 for an error mark. */
511 || GET_MODE_CLASS (mode) == MODE_VECTOR_INT
512 || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT);
514 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
515 return gen_int_mode (i0, mode);
518 /* If this integer fits in one word, return a CONST_INT. */
519 if ((i1 == 0 && i0 >= 0) || (i1 == ~0 && i0 < 0))
520 return GEN_INT (i0);
522 /* We use VOIDmode for integers. */
523 value = rtx_alloc (CONST_DOUBLE);
524 PUT_MODE (value, VOIDmode);
526 CONST_DOUBLE_LOW (value) = i0;
527 CONST_DOUBLE_HIGH (value) = i1;
529 for (i = 2; i < (sizeof CONST_DOUBLE_FORMAT - 1); i++)
530 XWINT (value, i) = 0;
532 return lookup_const_double (value);
536 gen_rtx_REG (enum machine_mode mode, unsigned int regno)
538 /* In case the MD file explicitly references the frame pointer, have
539 all such references point to the same frame pointer. This is
540 used during frame pointer elimination to distinguish the explicit
541 references to these registers from pseudos that happened to be
542 assigned to them.
544 If we have eliminated the frame pointer or arg pointer, we will
545 be using it as a normal register, for example as a spill
546 register. In such cases, we might be accessing it in a mode that
547 is not Pmode and therefore cannot use the pre-allocated rtx.
549 Also don't do this when we are making new REGs in reload, since
550 we don't want to get confused with the real pointers. */
552 if (mode == Pmode && !reload_in_progress && !lra_in_progress)
554 if (regno == FRAME_POINTER_REGNUM
555 && (!reload_completed || frame_pointer_needed))
556 return frame_pointer_rtx;
557 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
558 if (regno == HARD_FRAME_POINTER_REGNUM
559 && (!reload_completed || frame_pointer_needed))
560 return hard_frame_pointer_rtx;
561 #endif
562 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM && !HARD_FRAME_POINTER_IS_ARG_POINTER
563 if (regno == ARG_POINTER_REGNUM)
564 return arg_pointer_rtx;
565 #endif
566 #ifdef RETURN_ADDRESS_POINTER_REGNUM
567 if (regno == RETURN_ADDRESS_POINTER_REGNUM)
568 return return_address_pointer_rtx;
569 #endif
570 if (regno == (unsigned) PIC_OFFSET_TABLE_REGNUM
571 && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
572 && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
573 return pic_offset_table_rtx;
574 if (regno == STACK_POINTER_REGNUM)
575 return stack_pointer_rtx;
578 #if 0
579 /* If the per-function register table has been set up, try to re-use
580 an existing entry in that table to avoid useless generation of RTL.
582 This code is disabled for now until we can fix the various backends
583 which depend on having non-shared hard registers in some cases. Long
584 term we want to re-enable this code as it can significantly cut down
585 on the amount of useless RTL that gets generated.
587 We'll also need to fix some code that runs after reload that wants to
588 set ORIGINAL_REGNO. */
590 if (cfun
591 && cfun->emit
592 && regno_reg_rtx
593 && regno < FIRST_PSEUDO_REGISTER
594 && reg_raw_mode[regno] == mode)
595 return regno_reg_rtx[regno];
596 #endif
598 return gen_raw_REG (mode, regno);
602 gen_rtx_MEM (enum machine_mode mode, rtx addr)
604 rtx rt = gen_rtx_raw_MEM (mode, addr);
606 /* This field is not cleared by the mere allocation of the rtx, so
607 we clear it here. */
608 MEM_ATTRS (rt) = 0;
610 return rt;
613 /* Generate a memory referring to non-trapping constant memory. */
616 gen_const_mem (enum machine_mode mode, rtx addr)
618 rtx mem = gen_rtx_MEM (mode, addr);
619 MEM_READONLY_P (mem) = 1;
620 MEM_NOTRAP_P (mem) = 1;
621 return mem;
624 /* Generate a MEM referring to fixed portions of the frame, e.g., register
625 save areas. */
628 gen_frame_mem (enum machine_mode mode, rtx addr)
630 rtx mem = gen_rtx_MEM (mode, addr);
631 MEM_NOTRAP_P (mem) = 1;
632 set_mem_alias_set (mem, get_frame_alias_set ());
633 return mem;
636 /* Generate a MEM referring to a temporary use of the stack, not part
637 of the fixed stack frame. For example, something which is pushed
638 by a target splitter. */
640 gen_tmp_stack_mem (enum machine_mode mode, rtx addr)
642 rtx mem = gen_rtx_MEM (mode, addr);
643 MEM_NOTRAP_P (mem) = 1;
644 if (!cfun->calls_alloca)
645 set_mem_alias_set (mem, get_frame_alias_set ());
646 return mem;
649 /* We want to create (subreg:OMODE (obj:IMODE) OFFSET). Return true if
650 this construct would be valid, and false otherwise. */
652 bool
653 validate_subreg (enum machine_mode omode, enum machine_mode imode,
654 const_rtx reg, unsigned int offset)
656 unsigned int isize = GET_MODE_SIZE (imode);
657 unsigned int osize = GET_MODE_SIZE (omode);
659 /* All subregs must be aligned. */
660 if (offset % osize != 0)
661 return false;
663 /* The subreg offset cannot be outside the inner object. */
664 if (offset >= isize)
665 return false;
667 /* ??? This should not be here. Temporarily continue to allow word_mode
668 subregs of anything. The most common offender is (subreg:SI (reg:DF)).
669 Generally, backends are doing something sketchy but it'll take time to
670 fix them all. */
671 if (omode == word_mode)
673 /* ??? Similarly, e.g. with (subreg:DF (reg:TI)). Though store_bit_field
674 is the culprit here, and not the backends. */
675 else if (osize >= UNITS_PER_WORD && isize >= osize)
677 /* Allow component subregs of complex and vector. Though given the below
678 extraction rules, it's not always clear what that means. */
679 else if ((COMPLEX_MODE_P (imode) || VECTOR_MODE_P (imode))
680 && GET_MODE_INNER (imode) == omode)
682 /* ??? x86 sse code makes heavy use of *paradoxical* vector subregs,
683 i.e. (subreg:V4SF (reg:SF) 0). This surely isn't the cleanest way to
684 represent this. It's questionable if this ought to be represented at
685 all -- why can't this all be hidden in post-reload splitters that make
686 arbitrarily mode changes to the registers themselves. */
687 else if (VECTOR_MODE_P (omode) && GET_MODE_INNER (omode) == imode)
689 /* Subregs involving floating point modes are not allowed to
690 change size. Therefore (subreg:DI (reg:DF) 0) is fine, but
691 (subreg:SI (reg:DF) 0) isn't. */
692 else if (FLOAT_MODE_P (imode) || FLOAT_MODE_P (omode))
694 if (! (isize == osize
695 /* LRA can use subreg to store a floating point value in
696 an integer mode. Although the floating point and the
697 integer modes need the same number of hard registers,
698 the size of floating point mode can be less than the
699 integer mode. LRA also uses subregs for a register
700 should be used in different mode in on insn. */
701 || lra_in_progress))
702 return false;
705 /* Paradoxical subregs must have offset zero. */
706 if (osize > isize)
707 return offset == 0;
709 /* This is a normal subreg. Verify that the offset is representable. */
711 /* For hard registers, we already have most of these rules collected in
712 subreg_offset_representable_p. */
713 if (reg && REG_P (reg) && HARD_REGISTER_P (reg))
715 unsigned int regno = REGNO (reg);
717 #ifdef CANNOT_CHANGE_MODE_CLASS
718 if ((COMPLEX_MODE_P (imode) || VECTOR_MODE_P (imode))
719 && GET_MODE_INNER (imode) == omode)
721 else if (REG_CANNOT_CHANGE_MODE_P (regno, imode, omode))
722 return false;
723 #endif
725 return subreg_offset_representable_p (regno, imode, offset, omode);
728 /* For pseudo registers, we want most of the same checks. Namely:
729 If the register no larger than a word, the subreg must be lowpart.
730 If the register is larger than a word, the subreg must be the lowpart
731 of a subword. A subreg does *not* perform arbitrary bit extraction.
732 Given that we've already checked mode/offset alignment, we only have
733 to check subword subregs here. */
734 if (osize < UNITS_PER_WORD
735 && ! (lra_in_progress && (FLOAT_MODE_P (imode) || FLOAT_MODE_P (omode))))
737 enum machine_mode wmode = isize > UNITS_PER_WORD ? word_mode : imode;
738 unsigned int low_off = subreg_lowpart_offset (omode, wmode);
739 if (offset % UNITS_PER_WORD != low_off)
740 return false;
742 return true;
746 gen_rtx_SUBREG (enum machine_mode mode, rtx reg, int offset)
748 gcc_assert (validate_subreg (mode, GET_MODE (reg), reg, offset));
749 return gen_rtx_raw_SUBREG (mode, reg, offset);
752 /* Generate a SUBREG representing the least-significant part of REG if MODE
753 is smaller than mode of REG, otherwise paradoxical SUBREG. */
756 gen_lowpart_SUBREG (enum machine_mode mode, rtx reg)
758 enum machine_mode inmode;
760 inmode = GET_MODE (reg);
761 if (inmode == VOIDmode)
762 inmode = mode;
763 return gen_rtx_SUBREG (mode, reg,
764 subreg_lowpart_offset (mode, inmode));
768 /* Create an rtvec and stores within it the RTXen passed in the arguments. */
770 rtvec
771 gen_rtvec (int n, ...)
773 int i;
774 rtvec rt_val;
775 va_list p;
777 va_start (p, n);
779 /* Don't allocate an empty rtvec... */
780 if (n == 0)
782 va_end (p);
783 return NULL_RTVEC;
786 rt_val = rtvec_alloc (n);
788 for (i = 0; i < n; i++)
789 rt_val->elem[i] = va_arg (p, rtx);
791 va_end (p);
792 return rt_val;
795 rtvec
796 gen_rtvec_v (int n, rtx *argp)
798 int i;
799 rtvec rt_val;
801 /* Don't allocate an empty rtvec... */
802 if (n == 0)
803 return NULL_RTVEC;
805 rt_val = rtvec_alloc (n);
807 for (i = 0; i < n; i++)
808 rt_val->elem[i] = *argp++;
810 return rt_val;
813 /* Return the number of bytes between the start of an OUTER_MODE
814 in-memory value and the start of an INNER_MODE in-memory value,
815 given that the former is a lowpart of the latter. It may be a
816 paradoxical lowpart, in which case the offset will be negative
817 on big-endian targets. */
820 byte_lowpart_offset (enum machine_mode outer_mode,
821 enum machine_mode inner_mode)
823 if (GET_MODE_SIZE (outer_mode) < GET_MODE_SIZE (inner_mode))
824 return subreg_lowpart_offset (outer_mode, inner_mode);
825 else
826 return -subreg_lowpart_offset (inner_mode, outer_mode);
829 /* Generate a REG rtx for a new pseudo register of mode MODE.
830 This pseudo is assigned the next sequential register number. */
833 gen_reg_rtx (enum machine_mode mode)
835 rtx val;
836 unsigned int align = GET_MODE_ALIGNMENT (mode);
838 gcc_assert (can_create_pseudo_p ());
840 /* If a virtual register with bigger mode alignment is generated,
841 increase stack alignment estimation because it might be spilled
842 to stack later. */
843 if (SUPPORTS_STACK_ALIGNMENT
844 && crtl->stack_alignment_estimated < align
845 && !crtl->stack_realign_processed)
847 unsigned int min_align = MINIMUM_ALIGNMENT (NULL, mode, align);
848 if (crtl->stack_alignment_estimated < min_align)
849 crtl->stack_alignment_estimated = min_align;
852 if (generating_concat_p
853 && (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
854 || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT))
856 /* For complex modes, don't make a single pseudo.
857 Instead, make a CONCAT of two pseudos.
858 This allows noncontiguous allocation of the real and imaginary parts,
859 which makes much better code. Besides, allocating DCmode
860 pseudos overstrains reload on some machines like the 386. */
861 rtx realpart, imagpart;
862 enum machine_mode partmode = GET_MODE_INNER (mode);
864 realpart = gen_reg_rtx (partmode);
865 imagpart = gen_reg_rtx (partmode);
866 return gen_rtx_CONCAT (mode, realpart, imagpart);
869 /* Do not call gen_reg_rtx with uninitialized crtl. */
870 gcc_assert (crtl->emit.regno_pointer_align_length);
872 /* Make sure regno_pointer_align, and regno_reg_rtx are large
873 enough to have an element for this pseudo reg number. */
875 if (reg_rtx_no == crtl->emit.regno_pointer_align_length)
877 int old_size = crtl->emit.regno_pointer_align_length;
878 char *tmp;
879 rtx *new1;
881 tmp = XRESIZEVEC (char, crtl->emit.regno_pointer_align, old_size * 2);
882 memset (tmp + old_size, 0, old_size);
883 crtl->emit.regno_pointer_align = (unsigned char *) tmp;
885 new1 = GGC_RESIZEVEC (rtx, regno_reg_rtx, old_size * 2);
886 memset (new1 + old_size, 0, old_size * sizeof (rtx));
887 regno_reg_rtx = new1;
889 crtl->emit.regno_pointer_align_length = old_size * 2;
892 val = gen_raw_REG (mode, reg_rtx_no);
893 regno_reg_rtx[reg_rtx_no++] = val;
894 return val;
897 /* Return TRUE if REG is a PARM_DECL, FALSE otherwise. */
899 bool
900 reg_is_parm_p (rtx reg)
902 tree decl;
904 gcc_assert (REG_P (reg));
905 decl = REG_EXPR (reg);
906 return (decl && TREE_CODE (decl) == PARM_DECL);
909 /* Update NEW with the same attributes as REG, but with OFFSET added
910 to the REG_OFFSET. */
912 static void
913 update_reg_offset (rtx new_rtx, rtx reg, int offset)
915 REG_ATTRS (new_rtx) = get_reg_attrs (REG_EXPR (reg),
916 REG_OFFSET (reg) + offset);
919 /* Generate a register with same attributes as REG, but with OFFSET
920 added to the REG_OFFSET. */
923 gen_rtx_REG_offset (rtx reg, enum machine_mode mode, unsigned int regno,
924 int offset)
926 rtx new_rtx = gen_rtx_REG (mode, regno);
928 update_reg_offset (new_rtx, reg, offset);
929 return new_rtx;
932 /* Generate a new pseudo-register with the same attributes as REG, but
933 with OFFSET added to the REG_OFFSET. */
936 gen_reg_rtx_offset (rtx reg, enum machine_mode mode, int offset)
938 rtx new_rtx = gen_reg_rtx (mode);
940 update_reg_offset (new_rtx, reg, offset);
941 return new_rtx;
944 /* Adjust REG in-place so that it has mode MODE. It is assumed that the
945 new register is a (possibly paradoxical) lowpart of the old one. */
947 void
948 adjust_reg_mode (rtx reg, enum machine_mode mode)
950 update_reg_offset (reg, reg, byte_lowpart_offset (mode, GET_MODE (reg)));
951 PUT_MODE (reg, mode);
954 /* Copy REG's attributes from X, if X has any attributes. If REG and X
955 have different modes, REG is a (possibly paradoxical) lowpart of X. */
957 void
958 set_reg_attrs_from_value (rtx reg, rtx x)
960 int offset;
961 bool can_be_reg_pointer = true;
963 /* Don't call mark_reg_pointer for incompatible pointer sign
964 extension. */
965 while (GET_CODE (x) == SIGN_EXTEND
966 || GET_CODE (x) == ZERO_EXTEND
967 || GET_CODE (x) == TRUNCATE
968 || (GET_CODE (x) == SUBREG && subreg_lowpart_p (x)))
970 #if defined(POINTERS_EXTEND_UNSIGNED) && !defined(HAVE_ptr_extend)
971 if ((GET_CODE (x) == SIGN_EXTEND && POINTERS_EXTEND_UNSIGNED)
972 || (GET_CODE (x) != SIGN_EXTEND && ! POINTERS_EXTEND_UNSIGNED))
973 can_be_reg_pointer = false;
974 #endif
975 x = XEXP (x, 0);
978 /* Hard registers can be reused for multiple purposes within the same
979 function, so setting REG_ATTRS, REG_POINTER and REG_POINTER_ALIGN
980 on them is wrong. */
981 if (HARD_REGISTER_P (reg))
982 return;
984 offset = byte_lowpart_offset (GET_MODE (reg), GET_MODE (x));
985 if (MEM_P (x))
987 if (MEM_OFFSET_KNOWN_P (x))
988 REG_ATTRS (reg) = get_reg_attrs (MEM_EXPR (x),
989 MEM_OFFSET (x) + offset);
990 if (can_be_reg_pointer && MEM_POINTER (x))
991 mark_reg_pointer (reg, 0);
993 else if (REG_P (x))
995 if (REG_ATTRS (x))
996 update_reg_offset (reg, x, offset);
997 if (can_be_reg_pointer && REG_POINTER (x))
998 mark_reg_pointer (reg, REGNO_POINTER_ALIGN (REGNO (x)));
1002 /* Generate a REG rtx for a new pseudo register, copying the mode
1003 and attributes from X. */
1006 gen_reg_rtx_and_attrs (rtx x)
1008 rtx reg = gen_reg_rtx (GET_MODE (x));
1009 set_reg_attrs_from_value (reg, x);
1010 return reg;
1013 /* Set the register attributes for registers contained in PARM_RTX.
1014 Use needed values from memory attributes of MEM. */
1016 void
1017 set_reg_attrs_for_parm (rtx parm_rtx, rtx mem)
1019 if (REG_P (parm_rtx))
1020 set_reg_attrs_from_value (parm_rtx, mem);
1021 else if (GET_CODE (parm_rtx) == PARALLEL)
1023 /* Check for a NULL entry in the first slot, used to indicate that the
1024 parameter goes both on the stack and in registers. */
1025 int i = XEXP (XVECEXP (parm_rtx, 0, 0), 0) ? 0 : 1;
1026 for (; i < XVECLEN (parm_rtx, 0); i++)
1028 rtx x = XVECEXP (parm_rtx, 0, i);
1029 if (REG_P (XEXP (x, 0)))
1030 REG_ATTRS (XEXP (x, 0))
1031 = get_reg_attrs (MEM_EXPR (mem),
1032 INTVAL (XEXP (x, 1)));
1037 /* Set the REG_ATTRS for registers in value X, given that X represents
1038 decl T. */
1040 void
1041 set_reg_attrs_for_decl_rtl (tree t, rtx x)
1043 if (GET_CODE (x) == SUBREG)
1045 gcc_assert (subreg_lowpart_p (x));
1046 x = SUBREG_REG (x);
1048 if (REG_P (x))
1049 REG_ATTRS (x)
1050 = get_reg_attrs (t, byte_lowpart_offset (GET_MODE (x),
1051 DECL_MODE (t)));
1052 if (GET_CODE (x) == CONCAT)
1054 if (REG_P (XEXP (x, 0)))
1055 REG_ATTRS (XEXP (x, 0)) = get_reg_attrs (t, 0);
1056 if (REG_P (XEXP (x, 1)))
1057 REG_ATTRS (XEXP (x, 1))
1058 = get_reg_attrs (t, GET_MODE_UNIT_SIZE (GET_MODE (XEXP (x, 0))));
1060 if (GET_CODE (x) == PARALLEL)
1062 int i, start;
1064 /* Check for a NULL entry, used to indicate that the parameter goes
1065 both on the stack and in registers. */
1066 if (XEXP (XVECEXP (x, 0, 0), 0))
1067 start = 0;
1068 else
1069 start = 1;
1071 for (i = start; i < XVECLEN (x, 0); i++)
1073 rtx y = XVECEXP (x, 0, i);
1074 if (REG_P (XEXP (y, 0)))
1075 REG_ATTRS (XEXP (y, 0)) = get_reg_attrs (t, INTVAL (XEXP (y, 1)));
1080 /* Assign the RTX X to declaration T. */
1082 void
1083 set_decl_rtl (tree t, rtx x)
1085 DECL_WRTL_CHECK (t)->decl_with_rtl.rtl = x;
1086 if (x)
1087 set_reg_attrs_for_decl_rtl (t, x);
1090 /* Assign the RTX X to parameter declaration T. BY_REFERENCE_P is true
1091 if the ABI requires the parameter to be passed by reference. */
1093 void
1094 set_decl_incoming_rtl (tree t, rtx x, bool by_reference_p)
1096 DECL_INCOMING_RTL (t) = x;
1097 if (x && !by_reference_p)
1098 set_reg_attrs_for_decl_rtl (t, x);
1101 /* Identify REG (which may be a CONCAT) as a user register. */
1103 void
1104 mark_user_reg (rtx reg)
1106 if (GET_CODE (reg) == CONCAT)
1108 REG_USERVAR_P (XEXP (reg, 0)) = 1;
1109 REG_USERVAR_P (XEXP (reg, 1)) = 1;
1111 else
1113 gcc_assert (REG_P (reg));
1114 REG_USERVAR_P (reg) = 1;
1118 /* Identify REG as a probable pointer register and show its alignment
1119 as ALIGN, if nonzero. */
1121 void
1122 mark_reg_pointer (rtx reg, int align)
1124 if (! REG_POINTER (reg))
1126 REG_POINTER (reg) = 1;
1128 if (align)
1129 REGNO_POINTER_ALIGN (REGNO (reg)) = align;
1131 else if (align && align < REGNO_POINTER_ALIGN (REGNO (reg)))
1132 /* We can no-longer be sure just how aligned this pointer is. */
1133 REGNO_POINTER_ALIGN (REGNO (reg)) = align;
1136 /* Return 1 plus largest pseudo reg number used in the current function. */
1139 max_reg_num (void)
1141 return reg_rtx_no;
1144 /* Return 1 + the largest label number used so far in the current function. */
1147 max_label_num (void)
1149 return label_num;
1152 /* Return first label number used in this function (if any were used). */
1155 get_first_label_num (void)
1157 return first_label_num;
1160 /* If the rtx for label was created during the expansion of a nested
1161 function, then first_label_num won't include this label number.
1162 Fix this now so that array indices work later. */
1164 void
1165 maybe_set_first_label_num (rtx x)
1167 if (CODE_LABEL_NUMBER (x) < first_label_num)
1168 first_label_num = CODE_LABEL_NUMBER (x);
1171 /* Return a value representing some low-order bits of X, where the number
1172 of low-order bits is given by MODE. Note that no conversion is done
1173 between floating-point and fixed-point values, rather, the bit
1174 representation is returned.
1176 This function handles the cases in common between gen_lowpart, below,
1177 and two variants in cse.c and combine.c. These are the cases that can
1178 be safely handled at all points in the compilation.
1180 If this is not a case we can handle, return 0. */
1183 gen_lowpart_common (enum machine_mode mode, rtx x)
1185 int msize = GET_MODE_SIZE (mode);
1186 int xsize;
1187 int offset = 0;
1188 enum machine_mode innermode;
1190 /* Unfortunately, this routine doesn't take a parameter for the mode of X,
1191 so we have to make one up. Yuk. */
1192 innermode = GET_MODE (x);
1193 if (CONST_INT_P (x)
1194 && msize * BITS_PER_UNIT <= HOST_BITS_PER_WIDE_INT)
1195 innermode = mode_for_size (HOST_BITS_PER_WIDE_INT, MODE_INT, 0);
1196 else if (innermode == VOIDmode)
1197 innermode = mode_for_size (HOST_BITS_PER_DOUBLE_INT, MODE_INT, 0);
1199 xsize = GET_MODE_SIZE (innermode);
1201 gcc_assert (innermode != VOIDmode && innermode != BLKmode);
1203 if (innermode == mode)
1204 return x;
1206 /* MODE must occupy no more words than the mode of X. */
1207 if ((msize + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD
1208 > ((xsize + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD))
1209 return 0;
1211 /* Don't allow generating paradoxical FLOAT_MODE subregs. */
1212 if (SCALAR_FLOAT_MODE_P (mode) && msize > xsize)
1213 return 0;
1215 offset = subreg_lowpart_offset (mode, innermode);
1217 if ((GET_CODE (x) == ZERO_EXTEND || GET_CODE (x) == SIGN_EXTEND)
1218 && (GET_MODE_CLASS (mode) == MODE_INT
1219 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT))
1221 /* If we are getting the low-order part of something that has been
1222 sign- or zero-extended, we can either just use the object being
1223 extended or make a narrower extension. If we want an even smaller
1224 piece than the size of the object being extended, call ourselves
1225 recursively.
1227 This case is used mostly by combine and cse. */
1229 if (GET_MODE (XEXP (x, 0)) == mode)
1230 return XEXP (x, 0);
1231 else if (msize < GET_MODE_SIZE (GET_MODE (XEXP (x, 0))))
1232 return gen_lowpart_common (mode, XEXP (x, 0));
1233 else if (msize < xsize)
1234 return gen_rtx_fmt_e (GET_CODE (x), mode, XEXP (x, 0));
1236 else if (GET_CODE (x) == SUBREG || REG_P (x)
1237 || GET_CODE (x) == CONCAT || GET_CODE (x) == CONST_VECTOR
1238 || CONST_DOUBLE_AS_FLOAT_P (x) || CONST_SCALAR_INT_P (x))
1239 return simplify_gen_subreg (mode, x, innermode, offset);
1241 /* Otherwise, we can't do this. */
1242 return 0;
1246 gen_highpart (enum machine_mode mode, rtx x)
1248 unsigned int msize = GET_MODE_SIZE (mode);
1249 rtx result;
1251 /* This case loses if X is a subreg. To catch bugs early,
1252 complain if an invalid MODE is used even in other cases. */
1253 gcc_assert (msize <= UNITS_PER_WORD
1254 || msize == (unsigned int) GET_MODE_UNIT_SIZE (GET_MODE (x)));
1256 result = simplify_gen_subreg (mode, x, GET_MODE (x),
1257 subreg_highpart_offset (mode, GET_MODE (x)));
1258 gcc_assert (result);
1260 /* simplify_gen_subreg is not guaranteed to return a valid operand for
1261 the target if we have a MEM. gen_highpart must return a valid operand,
1262 emitting code if necessary to do so. */
1263 if (MEM_P (result))
1265 result = validize_mem (result);
1266 gcc_assert (result);
1269 return result;
1272 /* Like gen_highpart, but accept mode of EXP operand in case EXP can
1273 be VOIDmode constant. */
1275 gen_highpart_mode (enum machine_mode outermode, enum machine_mode innermode, rtx exp)
1277 if (GET_MODE (exp) != VOIDmode)
1279 gcc_assert (GET_MODE (exp) == innermode);
1280 return gen_highpart (outermode, exp);
1282 return simplify_gen_subreg (outermode, exp, innermode,
1283 subreg_highpart_offset (outermode, innermode));
1286 /* Return the SUBREG_BYTE for an OUTERMODE lowpart of an INNERMODE value. */
1288 unsigned int
1289 subreg_lowpart_offset (enum machine_mode outermode, enum machine_mode innermode)
1291 unsigned int offset = 0;
1292 int difference = (GET_MODE_SIZE (innermode) - GET_MODE_SIZE (outermode));
1294 if (difference > 0)
1296 if (WORDS_BIG_ENDIAN)
1297 offset += (difference / UNITS_PER_WORD) * UNITS_PER_WORD;
1298 if (BYTES_BIG_ENDIAN)
1299 offset += difference % UNITS_PER_WORD;
1302 return offset;
1305 /* Return offset in bytes to get OUTERMODE high part
1306 of the value in mode INNERMODE stored in memory in target format. */
1307 unsigned int
1308 subreg_highpart_offset (enum machine_mode outermode, enum machine_mode innermode)
1310 unsigned int offset = 0;
1311 int difference = (GET_MODE_SIZE (innermode) - GET_MODE_SIZE (outermode));
1313 gcc_assert (GET_MODE_SIZE (innermode) >= GET_MODE_SIZE (outermode));
1315 if (difference > 0)
1317 if (! WORDS_BIG_ENDIAN)
1318 offset += (difference / UNITS_PER_WORD) * UNITS_PER_WORD;
1319 if (! BYTES_BIG_ENDIAN)
1320 offset += difference % UNITS_PER_WORD;
1323 return offset;
1326 /* Return 1 iff X, assumed to be a SUBREG,
1327 refers to the least significant part of its containing reg.
1328 If X is not a SUBREG, always return 1 (it is its own low part!). */
1331 subreg_lowpart_p (const_rtx x)
1333 if (GET_CODE (x) != SUBREG)
1334 return 1;
1335 else if (GET_MODE (SUBREG_REG (x)) == VOIDmode)
1336 return 0;
1338 return (subreg_lowpart_offset (GET_MODE (x), GET_MODE (SUBREG_REG (x)))
1339 == SUBREG_BYTE (x));
1342 /* Return true if X is a paradoxical subreg, false otherwise. */
1343 bool
1344 paradoxical_subreg_p (const_rtx x)
1346 if (GET_CODE (x) != SUBREG)
1347 return false;
1348 return (GET_MODE_PRECISION (GET_MODE (x))
1349 > GET_MODE_PRECISION (GET_MODE (SUBREG_REG (x))));
1352 /* Return subword OFFSET of operand OP.
1353 The word number, OFFSET, is interpreted as the word number starting
1354 at the low-order address. OFFSET 0 is the low-order word if not
1355 WORDS_BIG_ENDIAN, otherwise it is the high-order word.
1357 If we cannot extract the required word, we return zero. Otherwise,
1358 an rtx corresponding to the requested word will be returned.
1360 VALIDATE_ADDRESS is nonzero if the address should be validated. Before
1361 reload has completed, a valid address will always be returned. After
1362 reload, if a valid address cannot be returned, we return zero.
1364 If VALIDATE_ADDRESS is zero, we simply form the required address; validating
1365 it is the responsibility of the caller.
1367 MODE is the mode of OP in case it is a CONST_INT.
1369 ??? This is still rather broken for some cases. The problem for the
1370 moment is that all callers of this thing provide no 'goal mode' to
1371 tell us to work with. This exists because all callers were written
1372 in a word based SUBREG world.
1373 Now use of this function can be deprecated by simplify_subreg in most
1374 cases.
1378 operand_subword (rtx op, unsigned int offset, int validate_address, enum machine_mode mode)
1380 if (mode == VOIDmode)
1381 mode = GET_MODE (op);
1383 gcc_assert (mode != VOIDmode);
1385 /* If OP is narrower than a word, fail. */
1386 if (mode != BLKmode
1387 && (GET_MODE_SIZE (mode) < UNITS_PER_WORD))
1388 return 0;
1390 /* If we want a word outside OP, return zero. */
1391 if (mode != BLKmode
1392 && (offset + 1) * UNITS_PER_WORD > GET_MODE_SIZE (mode))
1393 return const0_rtx;
1395 /* Form a new MEM at the requested address. */
1396 if (MEM_P (op))
1398 rtx new_rtx = adjust_address_nv (op, word_mode, offset * UNITS_PER_WORD);
1400 if (! validate_address)
1401 return new_rtx;
1403 else if (reload_completed)
1405 if (! strict_memory_address_addr_space_p (word_mode,
1406 XEXP (new_rtx, 0),
1407 MEM_ADDR_SPACE (op)))
1408 return 0;
1410 else
1411 return replace_equiv_address (new_rtx, XEXP (new_rtx, 0));
1414 /* Rest can be handled by simplify_subreg. */
1415 return simplify_gen_subreg (word_mode, op, mode, (offset * UNITS_PER_WORD));
1418 /* Similar to `operand_subword', but never return 0. If we can't
1419 extract the required subword, put OP into a register and try again.
1420 The second attempt must succeed. We always validate the address in
1421 this case.
1423 MODE is the mode of OP, in case it is CONST_INT. */
1426 operand_subword_force (rtx op, unsigned int offset, enum machine_mode mode)
1428 rtx result = operand_subword (op, offset, 1, mode);
1430 if (result)
1431 return result;
1433 if (mode != BLKmode && mode != VOIDmode)
1435 /* If this is a register which can not be accessed by words, copy it
1436 to a pseudo register. */
1437 if (REG_P (op))
1438 op = copy_to_reg (op);
1439 else
1440 op = force_reg (mode, op);
1443 result = operand_subword (op, offset, 1, mode);
1444 gcc_assert (result);
1446 return result;
1449 /* Returns 1 if both MEM_EXPR can be considered equal
1450 and 0 otherwise. */
1453 mem_expr_equal_p (const_tree expr1, const_tree expr2)
1455 if (expr1 == expr2)
1456 return 1;
1458 if (! expr1 || ! expr2)
1459 return 0;
1461 if (TREE_CODE (expr1) != TREE_CODE (expr2))
1462 return 0;
1464 return operand_equal_p (expr1, expr2, 0);
1467 /* Return OFFSET if XEXP (MEM, 0) - OFFSET is known to be ALIGN
1468 bits aligned for 0 <= OFFSET < ALIGN / BITS_PER_UNIT, or
1469 -1 if not known. */
1472 get_mem_align_offset (rtx mem, unsigned int align)
1474 tree expr;
1475 unsigned HOST_WIDE_INT offset;
1477 /* This function can't use
1478 if (!MEM_EXPR (mem) || !MEM_OFFSET_KNOWN_P (mem)
1479 || (MAX (MEM_ALIGN (mem),
1480 MAX (align, get_object_alignment (MEM_EXPR (mem))))
1481 < align))
1482 return -1;
1483 else
1484 return (- MEM_OFFSET (mem)) & (align / BITS_PER_UNIT - 1);
1485 for two reasons:
1486 - COMPONENT_REFs in MEM_EXPR can have NULL first operand,
1487 for <variable>. get_inner_reference doesn't handle it and
1488 even if it did, the alignment in that case needs to be determined
1489 from DECL_FIELD_CONTEXT's TYPE_ALIGN.
1490 - it would do suboptimal job for COMPONENT_REFs, even if MEM_EXPR
1491 isn't sufficiently aligned, the object it is in might be. */
1492 gcc_assert (MEM_P (mem));
1493 expr = MEM_EXPR (mem);
1494 if (expr == NULL_TREE || !MEM_OFFSET_KNOWN_P (mem))
1495 return -1;
1497 offset = MEM_OFFSET (mem);
1498 if (DECL_P (expr))
1500 if (DECL_ALIGN (expr) < align)
1501 return -1;
1503 else if (INDIRECT_REF_P (expr))
1505 if (TYPE_ALIGN (TREE_TYPE (expr)) < (unsigned int) align)
1506 return -1;
1508 else if (TREE_CODE (expr) == COMPONENT_REF)
1510 while (1)
1512 tree inner = TREE_OPERAND (expr, 0);
1513 tree field = TREE_OPERAND (expr, 1);
1514 tree byte_offset = component_ref_field_offset (expr);
1515 tree bit_offset = DECL_FIELD_BIT_OFFSET (field);
1517 if (!byte_offset
1518 || !tree_fits_uhwi_p (byte_offset)
1519 || !tree_fits_uhwi_p (bit_offset))
1520 return -1;
1522 offset += tree_to_uhwi (byte_offset);
1523 offset += tree_to_uhwi (bit_offset) / BITS_PER_UNIT;
1525 if (inner == NULL_TREE)
1527 if (TYPE_ALIGN (DECL_FIELD_CONTEXT (field))
1528 < (unsigned int) align)
1529 return -1;
1530 break;
1532 else if (DECL_P (inner))
1534 if (DECL_ALIGN (inner) < align)
1535 return -1;
1536 break;
1538 else if (TREE_CODE (inner) != COMPONENT_REF)
1539 return -1;
1540 expr = inner;
1543 else
1544 return -1;
1546 return offset & ((align / BITS_PER_UNIT) - 1);
1549 /* Given REF (a MEM) and T, either the type of X or the expression
1550 corresponding to REF, set the memory attributes. OBJECTP is nonzero
1551 if we are making a new object of this type. BITPOS is nonzero if
1552 there is an offset outstanding on T that will be applied later. */
1554 void
1555 set_mem_attributes_minus_bitpos (rtx ref, tree t, int objectp,
1556 HOST_WIDE_INT bitpos)
1558 HOST_WIDE_INT apply_bitpos = 0;
1559 tree type;
1560 struct mem_attrs attrs, *defattrs, *refattrs;
1561 addr_space_t as;
1563 /* It can happen that type_for_mode was given a mode for which there
1564 is no language-level type. In which case it returns NULL, which
1565 we can see here. */
1566 if (t == NULL_TREE)
1567 return;
1569 type = TYPE_P (t) ? t : TREE_TYPE (t);
1570 if (type == error_mark_node)
1571 return;
1573 /* If we have already set DECL_RTL = ref, get_alias_set will get the
1574 wrong answer, as it assumes that DECL_RTL already has the right alias
1575 info. Callers should not set DECL_RTL until after the call to
1576 set_mem_attributes. */
1577 gcc_assert (!DECL_P (t) || ref != DECL_RTL_IF_SET (t));
1579 memset (&attrs, 0, sizeof (attrs));
1581 /* Get the alias set from the expression or type (perhaps using a
1582 front-end routine) and use it. */
1583 attrs.alias = get_alias_set (t);
1585 MEM_VOLATILE_P (ref) |= TYPE_VOLATILE (type);
1586 MEM_POINTER (ref) = POINTER_TYPE_P (type);
1588 /* Default values from pre-existing memory attributes if present. */
1589 refattrs = MEM_ATTRS (ref);
1590 if (refattrs)
1592 /* ??? Can this ever happen? Calling this routine on a MEM that
1593 already carries memory attributes should probably be invalid. */
1594 attrs.expr = refattrs->expr;
1595 attrs.offset_known_p = refattrs->offset_known_p;
1596 attrs.offset = refattrs->offset;
1597 attrs.size_known_p = refattrs->size_known_p;
1598 attrs.size = refattrs->size;
1599 attrs.align = refattrs->align;
1602 /* Otherwise, default values from the mode of the MEM reference. */
1603 else
1605 defattrs = mode_mem_attrs[(int) GET_MODE (ref)];
1606 gcc_assert (!defattrs->expr);
1607 gcc_assert (!defattrs->offset_known_p);
1609 /* Respect mode size. */
1610 attrs.size_known_p = defattrs->size_known_p;
1611 attrs.size = defattrs->size;
1612 /* ??? Is this really necessary? We probably should always get
1613 the size from the type below. */
1615 /* Respect mode alignment for STRICT_ALIGNMENT targets if T is a type;
1616 if T is an object, always compute the object alignment below. */
1617 if (TYPE_P (t))
1618 attrs.align = defattrs->align;
1619 else
1620 attrs.align = BITS_PER_UNIT;
1621 /* ??? If T is a type, respecting mode alignment may *also* be wrong
1622 e.g. if the type carries an alignment attribute. Should we be
1623 able to simply always use TYPE_ALIGN? */
1626 /* We can set the alignment from the type if we are making an object,
1627 this is an INDIRECT_REF, or if TYPE_ALIGN_OK. */
1628 if (objectp || TREE_CODE (t) == INDIRECT_REF || TYPE_ALIGN_OK (type))
1629 attrs.align = MAX (attrs.align, TYPE_ALIGN (type));
1631 /* If the size is known, we can set that. */
1632 tree new_size = TYPE_SIZE_UNIT (type);
1634 /* The address-space is that of the type. */
1635 as = TYPE_ADDR_SPACE (type);
1637 /* If T is not a type, we may be able to deduce some more information about
1638 the expression. */
1639 if (! TYPE_P (t))
1641 tree base;
1643 if (TREE_THIS_VOLATILE (t))
1644 MEM_VOLATILE_P (ref) = 1;
1646 /* Now remove any conversions: they don't change what the underlying
1647 object is. Likewise for SAVE_EXPR. */
1648 while (CONVERT_EXPR_P (t)
1649 || TREE_CODE (t) == VIEW_CONVERT_EXPR
1650 || TREE_CODE (t) == SAVE_EXPR)
1651 t = TREE_OPERAND (t, 0);
1653 /* Note whether this expression can trap. */
1654 MEM_NOTRAP_P (ref) = !tree_could_trap_p (t);
1656 base = get_base_address (t);
1657 if (base)
1659 if (DECL_P (base)
1660 && TREE_READONLY (base)
1661 && (TREE_STATIC (base) || DECL_EXTERNAL (base))
1662 && !TREE_THIS_VOLATILE (base))
1663 MEM_READONLY_P (ref) = 1;
1665 /* Mark static const strings readonly as well. */
1666 if (TREE_CODE (base) == STRING_CST
1667 && TREE_READONLY (base)
1668 && TREE_STATIC (base))
1669 MEM_READONLY_P (ref) = 1;
1671 /* Address-space information is on the base object. */
1672 if (TREE_CODE (base) == MEM_REF
1673 || TREE_CODE (base) == TARGET_MEM_REF)
1674 as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (TREE_OPERAND (base,
1675 0))));
1676 else
1677 as = TYPE_ADDR_SPACE (TREE_TYPE (base));
1680 /* If this expression uses it's parent's alias set, mark it such
1681 that we won't change it. */
1682 if (component_uses_parent_alias_set_from (t) != NULL_TREE)
1683 MEM_KEEP_ALIAS_SET_P (ref) = 1;
1685 /* If this is a decl, set the attributes of the MEM from it. */
1686 if (DECL_P (t))
1688 attrs.expr = t;
1689 attrs.offset_known_p = true;
1690 attrs.offset = 0;
1691 apply_bitpos = bitpos;
1692 new_size = DECL_SIZE_UNIT (t);
1695 /* ??? If we end up with a constant here do record a MEM_EXPR. */
1696 else if (CONSTANT_CLASS_P (t))
1699 /* If this is a field reference, record it. */
1700 else if (TREE_CODE (t) == COMPONENT_REF)
1702 attrs.expr = t;
1703 attrs.offset_known_p = true;
1704 attrs.offset = 0;
1705 apply_bitpos = bitpos;
1706 if (DECL_BIT_FIELD (TREE_OPERAND (t, 1)))
1707 new_size = DECL_SIZE_UNIT (TREE_OPERAND (t, 1));
1710 /* If this is an array reference, look for an outer field reference. */
1711 else if (TREE_CODE (t) == ARRAY_REF)
1713 tree off_tree = size_zero_node;
1714 /* We can't modify t, because we use it at the end of the
1715 function. */
1716 tree t2 = t;
1720 tree index = TREE_OPERAND (t2, 1);
1721 tree low_bound = array_ref_low_bound (t2);
1722 tree unit_size = array_ref_element_size (t2);
1724 /* We assume all arrays have sizes that are a multiple of a byte.
1725 First subtract the lower bound, if any, in the type of the
1726 index, then convert to sizetype and multiply by the size of
1727 the array element. */
1728 if (! integer_zerop (low_bound))
1729 index = fold_build2 (MINUS_EXPR, TREE_TYPE (index),
1730 index, low_bound);
1732 off_tree = size_binop (PLUS_EXPR,
1733 size_binop (MULT_EXPR,
1734 fold_convert (sizetype,
1735 index),
1736 unit_size),
1737 off_tree);
1738 t2 = TREE_OPERAND (t2, 0);
1740 while (TREE_CODE (t2) == ARRAY_REF);
1742 if (DECL_P (t2)
1743 || TREE_CODE (t2) == COMPONENT_REF)
1745 attrs.expr = t2;
1746 attrs.offset_known_p = false;
1747 if (tree_fits_uhwi_p (off_tree))
1749 attrs.offset_known_p = true;
1750 attrs.offset = tree_to_uhwi (off_tree);
1751 apply_bitpos = bitpos;
1754 /* Else do not record a MEM_EXPR. */
1757 /* If this is an indirect reference, record it. */
1758 else if (TREE_CODE (t) == MEM_REF
1759 || TREE_CODE (t) == TARGET_MEM_REF)
1761 attrs.expr = t;
1762 attrs.offset_known_p = true;
1763 attrs.offset = 0;
1764 apply_bitpos = bitpos;
1767 /* Compute the alignment. */
1768 unsigned int obj_align;
1769 unsigned HOST_WIDE_INT obj_bitpos;
1770 get_object_alignment_1 (t, &obj_align, &obj_bitpos);
1771 obj_bitpos = (obj_bitpos - bitpos) & (obj_align - 1);
1772 if (obj_bitpos != 0)
1773 obj_align = (obj_bitpos & -obj_bitpos);
1774 attrs.align = MAX (attrs.align, obj_align);
1777 if (tree_fits_uhwi_p (new_size))
1779 attrs.size_known_p = true;
1780 attrs.size = tree_to_uhwi (new_size);
1783 /* If we modified OFFSET based on T, then subtract the outstanding
1784 bit position offset. Similarly, increase the size of the accessed
1785 object to contain the negative offset. */
1786 if (apply_bitpos)
1788 gcc_assert (attrs.offset_known_p);
1789 attrs.offset -= apply_bitpos / BITS_PER_UNIT;
1790 if (attrs.size_known_p)
1791 attrs.size += apply_bitpos / BITS_PER_UNIT;
1794 /* Now set the attributes we computed above. */
1795 attrs.addrspace = as;
1796 set_mem_attrs (ref, &attrs);
1799 void
1800 set_mem_attributes (rtx ref, tree t, int objectp)
1802 set_mem_attributes_minus_bitpos (ref, t, objectp, 0);
1805 /* Set the alias set of MEM to SET. */
1807 void
1808 set_mem_alias_set (rtx mem, alias_set_type set)
1810 struct mem_attrs attrs;
1812 /* If the new and old alias sets don't conflict, something is wrong. */
1813 gcc_checking_assert (alias_sets_conflict_p (set, MEM_ALIAS_SET (mem)));
1814 attrs = *get_mem_attrs (mem);
1815 attrs.alias = set;
1816 set_mem_attrs (mem, &attrs);
1819 /* Set the address space of MEM to ADDRSPACE (target-defined). */
1821 void
1822 set_mem_addr_space (rtx mem, addr_space_t addrspace)
1824 struct mem_attrs attrs;
1826 attrs = *get_mem_attrs (mem);
1827 attrs.addrspace = addrspace;
1828 set_mem_attrs (mem, &attrs);
1831 /* Set the alignment of MEM to ALIGN bits. */
1833 void
1834 set_mem_align (rtx mem, unsigned int align)
1836 struct mem_attrs attrs;
1838 attrs = *get_mem_attrs (mem);
1839 attrs.align = align;
1840 set_mem_attrs (mem, &attrs);
1843 /* Set the expr for MEM to EXPR. */
1845 void
1846 set_mem_expr (rtx mem, tree expr)
1848 struct mem_attrs attrs;
1850 attrs = *get_mem_attrs (mem);
1851 attrs.expr = expr;
1852 set_mem_attrs (mem, &attrs);
1855 /* Set the offset of MEM to OFFSET. */
1857 void
1858 set_mem_offset (rtx mem, HOST_WIDE_INT offset)
1860 struct mem_attrs attrs;
1862 attrs = *get_mem_attrs (mem);
1863 attrs.offset_known_p = true;
1864 attrs.offset = offset;
1865 set_mem_attrs (mem, &attrs);
1868 /* Clear the offset of MEM. */
1870 void
1871 clear_mem_offset (rtx mem)
1873 struct mem_attrs attrs;
1875 attrs = *get_mem_attrs (mem);
1876 attrs.offset_known_p = false;
1877 set_mem_attrs (mem, &attrs);
1880 /* Set the size of MEM to SIZE. */
1882 void
1883 set_mem_size (rtx mem, HOST_WIDE_INT size)
1885 struct mem_attrs attrs;
1887 attrs = *get_mem_attrs (mem);
1888 attrs.size_known_p = true;
1889 attrs.size = size;
1890 set_mem_attrs (mem, &attrs);
1893 /* Clear the size of MEM. */
1895 void
1896 clear_mem_size (rtx mem)
1898 struct mem_attrs attrs;
1900 attrs = *get_mem_attrs (mem);
1901 attrs.size_known_p = false;
1902 set_mem_attrs (mem, &attrs);
1905 /* Return a memory reference like MEMREF, but with its mode changed to MODE
1906 and its address changed to ADDR. (VOIDmode means don't change the mode.
1907 NULL for ADDR means don't change the address.) VALIDATE is nonzero if the
1908 returned memory location is required to be valid. The memory
1909 attributes are not changed. */
1911 static rtx
1912 change_address_1 (rtx memref, enum machine_mode mode, rtx addr, int validate)
1914 addr_space_t as;
1915 rtx new_rtx;
1917 gcc_assert (MEM_P (memref));
1918 as = MEM_ADDR_SPACE (memref);
1919 if (mode == VOIDmode)
1920 mode = GET_MODE (memref);
1921 if (addr == 0)
1922 addr = XEXP (memref, 0);
1923 if (mode == GET_MODE (memref) && addr == XEXP (memref, 0)
1924 && (!validate || memory_address_addr_space_p (mode, addr, as)))
1925 return memref;
1927 /* Don't validate address for LRA. LRA can make the address valid
1928 by itself in most efficient way. */
1929 if (validate && !lra_in_progress)
1931 if (reload_in_progress || reload_completed)
1932 gcc_assert (memory_address_addr_space_p (mode, addr, as));
1933 else
1934 addr = memory_address_addr_space (mode, addr, as);
1937 if (rtx_equal_p (addr, XEXP (memref, 0)) && mode == GET_MODE (memref))
1938 return memref;
1940 new_rtx = gen_rtx_MEM (mode, addr);
1941 MEM_COPY_ATTRIBUTES (new_rtx, memref);
1942 return new_rtx;
1945 /* Like change_address_1 with VALIDATE nonzero, but we are not saying in what
1946 way we are changing MEMREF, so we only preserve the alias set. */
1949 change_address (rtx memref, enum machine_mode mode, rtx addr)
1951 rtx new_rtx = change_address_1 (memref, mode, addr, 1);
1952 enum machine_mode mmode = GET_MODE (new_rtx);
1953 struct mem_attrs attrs, *defattrs;
1955 attrs = *get_mem_attrs (memref);
1956 defattrs = mode_mem_attrs[(int) mmode];
1957 attrs.expr = NULL_TREE;
1958 attrs.offset_known_p = false;
1959 attrs.size_known_p = defattrs->size_known_p;
1960 attrs.size = defattrs->size;
1961 attrs.align = defattrs->align;
1963 /* If there are no changes, just return the original memory reference. */
1964 if (new_rtx == memref)
1966 if (mem_attrs_eq_p (get_mem_attrs (memref), &attrs))
1967 return new_rtx;
1969 new_rtx = gen_rtx_MEM (mmode, XEXP (memref, 0));
1970 MEM_COPY_ATTRIBUTES (new_rtx, memref);
1973 set_mem_attrs (new_rtx, &attrs);
1974 return new_rtx;
1977 /* Return a memory reference like MEMREF, but with its mode changed
1978 to MODE and its address offset by OFFSET bytes. If VALIDATE is
1979 nonzero, the memory address is forced to be valid.
1980 If ADJUST_ADDRESS is zero, OFFSET is only used to update MEM_ATTRS
1981 and the caller is responsible for adjusting MEMREF base register.
1982 If ADJUST_OBJECT is zero, the underlying object associated with the
1983 memory reference is left unchanged and the caller is responsible for
1984 dealing with it. Otherwise, if the new memory reference is outside
1985 the underlying object, even partially, then the object is dropped.
1986 SIZE, if nonzero, is the size of an access in cases where MODE
1987 has no inherent size. */
1990 adjust_address_1 (rtx memref, enum machine_mode mode, HOST_WIDE_INT offset,
1991 int validate, int adjust_address, int adjust_object,
1992 HOST_WIDE_INT size)
1994 rtx addr = XEXP (memref, 0);
1995 rtx new_rtx;
1996 enum machine_mode address_mode;
1997 int pbits;
1998 struct mem_attrs attrs = *get_mem_attrs (memref), *defattrs;
1999 unsigned HOST_WIDE_INT max_align;
2000 #ifdef POINTERS_EXTEND_UNSIGNED
2001 enum machine_mode pointer_mode
2002 = targetm.addr_space.pointer_mode (attrs.addrspace);
2003 #endif
2005 /* VOIDmode means no mode change for change_address_1. */
2006 if (mode == VOIDmode)
2007 mode = GET_MODE (memref);
2009 /* Take the size of non-BLKmode accesses from the mode. */
2010 defattrs = mode_mem_attrs[(int) mode];
2011 if (defattrs->size_known_p)
2012 size = defattrs->size;
2014 /* If there are no changes, just return the original memory reference. */
2015 if (mode == GET_MODE (memref) && !offset
2016 && (size == 0 || (attrs.size_known_p && attrs.size == size))
2017 && (!validate || memory_address_addr_space_p (mode, addr,
2018 attrs.addrspace)))
2019 return memref;
2021 /* ??? Prefer to create garbage instead of creating shared rtl.
2022 This may happen even if offset is nonzero -- consider
2023 (plus (plus reg reg) const_int) -- so do this always. */
2024 addr = copy_rtx (addr);
2026 /* Convert a possibly large offset to a signed value within the
2027 range of the target address space. */
2028 address_mode = get_address_mode (memref);
2029 pbits = GET_MODE_BITSIZE (address_mode);
2030 if (HOST_BITS_PER_WIDE_INT > pbits)
2032 int shift = HOST_BITS_PER_WIDE_INT - pbits;
2033 offset = (((HOST_WIDE_INT) ((unsigned HOST_WIDE_INT) offset << shift))
2034 >> shift);
2037 if (adjust_address)
2039 /* If MEMREF is a LO_SUM and the offset is within the alignment of the
2040 object, we can merge it into the LO_SUM. */
2041 if (GET_MODE (memref) != BLKmode && GET_CODE (addr) == LO_SUM
2042 && offset >= 0
2043 && (unsigned HOST_WIDE_INT) offset
2044 < GET_MODE_ALIGNMENT (GET_MODE (memref)) / BITS_PER_UNIT)
2045 addr = gen_rtx_LO_SUM (address_mode, XEXP (addr, 0),
2046 plus_constant (address_mode,
2047 XEXP (addr, 1), offset));
2048 #ifdef POINTERS_EXTEND_UNSIGNED
2049 /* If MEMREF is a ZERO_EXTEND from pointer_mode and the offset is valid
2050 in that mode, we merge it into the ZERO_EXTEND. We take advantage of
2051 the fact that pointers are not allowed to overflow. */
2052 else if (POINTERS_EXTEND_UNSIGNED > 0
2053 && GET_CODE (addr) == ZERO_EXTEND
2054 && GET_MODE (XEXP (addr, 0)) == pointer_mode
2055 && trunc_int_for_mode (offset, pointer_mode) == offset)
2056 addr = gen_rtx_ZERO_EXTEND (address_mode,
2057 plus_constant (pointer_mode,
2058 XEXP (addr, 0), offset));
2059 #endif
2060 else
2061 addr = plus_constant (address_mode, addr, offset);
2064 new_rtx = change_address_1 (memref, mode, addr, validate);
2066 /* If the address is a REG, change_address_1 rightfully returns memref,
2067 but this would destroy memref's MEM_ATTRS. */
2068 if (new_rtx == memref && offset != 0)
2069 new_rtx = copy_rtx (new_rtx);
2071 /* Conservatively drop the object if we don't know where we start from. */
2072 if (adjust_object && (!attrs.offset_known_p || !attrs.size_known_p))
2074 attrs.expr = NULL_TREE;
2075 attrs.alias = 0;
2078 /* Compute the new values of the memory attributes due to this adjustment.
2079 We add the offsets and update the alignment. */
2080 if (attrs.offset_known_p)
2082 attrs.offset += offset;
2084 /* Drop the object if the new left end is not within its bounds. */
2085 if (adjust_object && attrs.offset < 0)
2087 attrs.expr = NULL_TREE;
2088 attrs.alias = 0;
2092 /* Compute the new alignment by taking the MIN of the alignment and the
2093 lowest-order set bit in OFFSET, but don't change the alignment if OFFSET
2094 if zero. */
2095 if (offset != 0)
2097 max_align = (offset & -offset) * BITS_PER_UNIT;
2098 attrs.align = MIN (attrs.align, max_align);
2101 if (size)
2103 /* Drop the object if the new right end is not within its bounds. */
2104 if (adjust_object && (offset + size) > attrs.size)
2106 attrs.expr = NULL_TREE;
2107 attrs.alias = 0;
2109 attrs.size_known_p = true;
2110 attrs.size = size;
2112 else if (attrs.size_known_p)
2114 gcc_assert (!adjust_object);
2115 attrs.size -= offset;
2116 /* ??? The store_by_pieces machinery generates negative sizes,
2117 so don't assert for that here. */
2120 set_mem_attrs (new_rtx, &attrs);
2122 return new_rtx;
2125 /* Return a memory reference like MEMREF, but with its mode changed
2126 to MODE and its address changed to ADDR, which is assumed to be
2127 MEMREF offset by OFFSET bytes. If VALIDATE is
2128 nonzero, the memory address is forced to be valid. */
2131 adjust_automodify_address_1 (rtx memref, enum machine_mode mode, rtx addr,
2132 HOST_WIDE_INT offset, int validate)
2134 memref = change_address_1 (memref, VOIDmode, addr, validate);
2135 return adjust_address_1 (memref, mode, offset, validate, 0, 0, 0);
2138 /* Return a memory reference like MEMREF, but whose address is changed by
2139 adding OFFSET, an RTX, to it. POW2 is the highest power of two factor
2140 known to be in OFFSET (possibly 1). */
2143 offset_address (rtx memref, rtx offset, unsigned HOST_WIDE_INT pow2)
2145 rtx new_rtx, addr = XEXP (memref, 0);
2146 enum machine_mode address_mode;
2147 struct mem_attrs attrs, *defattrs;
2149 attrs = *get_mem_attrs (memref);
2150 address_mode = get_address_mode (memref);
2151 new_rtx = simplify_gen_binary (PLUS, address_mode, addr, offset);
2153 /* At this point we don't know _why_ the address is invalid. It
2154 could have secondary memory references, multiplies or anything.
2156 However, if we did go and rearrange things, we can wind up not
2157 being able to recognize the magic around pic_offset_table_rtx.
2158 This stuff is fragile, and is yet another example of why it is
2159 bad to expose PIC machinery too early. */
2160 if (! memory_address_addr_space_p (GET_MODE (memref), new_rtx,
2161 attrs.addrspace)
2162 && GET_CODE (addr) == PLUS
2163 && XEXP (addr, 0) == pic_offset_table_rtx)
2165 addr = force_reg (GET_MODE (addr), addr);
2166 new_rtx = simplify_gen_binary (PLUS, address_mode, addr, offset);
2169 update_temp_slot_address (XEXP (memref, 0), new_rtx);
2170 new_rtx = change_address_1 (memref, VOIDmode, new_rtx, 1);
2172 /* If there are no changes, just return the original memory reference. */
2173 if (new_rtx == memref)
2174 return new_rtx;
2176 /* Update the alignment to reflect the offset. Reset the offset, which
2177 we don't know. */
2178 defattrs = mode_mem_attrs[(int) GET_MODE (new_rtx)];
2179 attrs.offset_known_p = false;
2180 attrs.size_known_p = defattrs->size_known_p;
2181 attrs.size = defattrs->size;
2182 attrs.align = MIN (attrs.align, pow2 * BITS_PER_UNIT);
2183 set_mem_attrs (new_rtx, &attrs);
2184 return new_rtx;
2187 /* Return a memory reference like MEMREF, but with its address changed to
2188 ADDR. The caller is asserting that the actual piece of memory pointed
2189 to is the same, just the form of the address is being changed, such as
2190 by putting something into a register. */
2193 replace_equiv_address (rtx memref, rtx addr)
2195 /* change_address_1 copies the memory attribute structure without change
2196 and that's exactly what we want here. */
2197 update_temp_slot_address (XEXP (memref, 0), addr);
2198 return change_address_1 (memref, VOIDmode, addr, 1);
2201 /* Likewise, but the reference is not required to be valid. */
2204 replace_equiv_address_nv (rtx memref, rtx addr)
2206 return change_address_1 (memref, VOIDmode, addr, 0);
2209 /* Return a memory reference like MEMREF, but with its mode widened to
2210 MODE and offset by OFFSET. This would be used by targets that e.g.
2211 cannot issue QImode memory operations and have to use SImode memory
2212 operations plus masking logic. */
2215 widen_memory_access (rtx memref, enum machine_mode mode, HOST_WIDE_INT offset)
2217 rtx new_rtx = adjust_address_1 (memref, mode, offset, 1, 1, 0, 0);
2218 struct mem_attrs attrs;
2219 unsigned int size = GET_MODE_SIZE (mode);
2221 /* If there are no changes, just return the original memory reference. */
2222 if (new_rtx == memref)
2223 return new_rtx;
2225 attrs = *get_mem_attrs (new_rtx);
2227 /* If we don't know what offset we were at within the expression, then
2228 we can't know if we've overstepped the bounds. */
2229 if (! attrs.offset_known_p)
2230 attrs.expr = NULL_TREE;
2232 while (attrs.expr)
2234 if (TREE_CODE (attrs.expr) == COMPONENT_REF)
2236 tree field = TREE_OPERAND (attrs.expr, 1);
2237 tree offset = component_ref_field_offset (attrs.expr);
2239 if (! DECL_SIZE_UNIT (field))
2241 attrs.expr = NULL_TREE;
2242 break;
2245 /* Is the field at least as large as the access? If so, ok,
2246 otherwise strip back to the containing structure. */
2247 if (TREE_CODE (DECL_SIZE_UNIT (field)) == INTEGER_CST
2248 && compare_tree_int (DECL_SIZE_UNIT (field), size) >= 0
2249 && attrs.offset >= 0)
2250 break;
2252 if (! tree_fits_uhwi_p (offset))
2254 attrs.expr = NULL_TREE;
2255 break;
2258 attrs.expr = TREE_OPERAND (attrs.expr, 0);
2259 attrs.offset += tree_to_uhwi (offset);
2260 attrs.offset += (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field))
2261 / BITS_PER_UNIT);
2263 /* Similarly for the decl. */
2264 else if (DECL_P (attrs.expr)
2265 && DECL_SIZE_UNIT (attrs.expr)
2266 && TREE_CODE (DECL_SIZE_UNIT (attrs.expr)) == INTEGER_CST
2267 && compare_tree_int (DECL_SIZE_UNIT (attrs.expr), size) >= 0
2268 && (! attrs.offset_known_p || attrs.offset >= 0))
2269 break;
2270 else
2272 /* The widened memory access overflows the expression, which means
2273 that it could alias another expression. Zap it. */
2274 attrs.expr = NULL_TREE;
2275 break;
2279 if (! attrs.expr)
2280 attrs.offset_known_p = false;
2282 /* The widened memory may alias other stuff, so zap the alias set. */
2283 /* ??? Maybe use get_alias_set on any remaining expression. */
2284 attrs.alias = 0;
2285 attrs.size_known_p = true;
2286 attrs.size = size;
2287 set_mem_attrs (new_rtx, &attrs);
2288 return new_rtx;
2291 /* A fake decl that is used as the MEM_EXPR of spill slots. */
2292 static GTY(()) tree spill_slot_decl;
2294 tree
2295 get_spill_slot_decl (bool force_build_p)
2297 tree d = spill_slot_decl;
2298 rtx rd;
2299 struct mem_attrs attrs;
2301 if (d || !force_build_p)
2302 return d;
2304 d = build_decl (DECL_SOURCE_LOCATION (current_function_decl),
2305 VAR_DECL, get_identifier ("%sfp"), void_type_node);
2306 DECL_ARTIFICIAL (d) = 1;
2307 DECL_IGNORED_P (d) = 1;
2308 TREE_USED (d) = 1;
2309 spill_slot_decl = d;
2311 rd = gen_rtx_MEM (BLKmode, frame_pointer_rtx);
2312 MEM_NOTRAP_P (rd) = 1;
2313 attrs = *mode_mem_attrs[(int) BLKmode];
2314 attrs.alias = new_alias_set ();
2315 attrs.expr = d;
2316 set_mem_attrs (rd, &attrs);
2317 SET_DECL_RTL (d, rd);
2319 return d;
2322 /* Given MEM, a result from assign_stack_local, fill in the memory
2323 attributes as appropriate for a register allocator spill slot.
2324 These slots are not aliasable by other memory. We arrange for
2325 them all to use a single MEM_EXPR, so that the aliasing code can
2326 work properly in the case of shared spill slots. */
2328 void
2329 set_mem_attrs_for_spill (rtx mem)
2331 struct mem_attrs attrs;
2332 rtx addr;
2334 attrs = *get_mem_attrs (mem);
2335 attrs.expr = get_spill_slot_decl (true);
2336 attrs.alias = MEM_ALIAS_SET (DECL_RTL (attrs.expr));
2337 attrs.addrspace = ADDR_SPACE_GENERIC;
2339 /* We expect the incoming memory to be of the form:
2340 (mem:MODE (plus (reg sfp) (const_int offset)))
2341 with perhaps the plus missing for offset = 0. */
2342 addr = XEXP (mem, 0);
2343 attrs.offset_known_p = true;
2344 attrs.offset = 0;
2345 if (GET_CODE (addr) == PLUS
2346 && CONST_INT_P (XEXP (addr, 1)))
2347 attrs.offset = INTVAL (XEXP (addr, 1));
2349 set_mem_attrs (mem, &attrs);
2350 MEM_NOTRAP_P (mem) = 1;
2353 /* Return a newly created CODE_LABEL rtx with a unique label number. */
2356 gen_label_rtx (void)
2358 return gen_rtx_CODE_LABEL (VOIDmode, 0, NULL_RTX, NULL_RTX,
2359 NULL, label_num++, NULL);
2362 /* For procedure integration. */
2364 /* Install new pointers to the first and last insns in the chain.
2365 Also, set cur_insn_uid to one higher than the last in use.
2366 Used for an inline-procedure after copying the insn chain. */
2368 void
2369 set_new_first_and_last_insn (rtx first, rtx last)
2371 rtx insn;
2373 set_first_insn (first);
2374 set_last_insn (last);
2375 cur_insn_uid = 0;
2377 if (MIN_NONDEBUG_INSN_UID || MAY_HAVE_DEBUG_INSNS)
2379 int debug_count = 0;
2381 cur_insn_uid = MIN_NONDEBUG_INSN_UID - 1;
2382 cur_debug_insn_uid = 0;
2384 for (insn = first; insn; insn = NEXT_INSN (insn))
2385 if (INSN_UID (insn) < MIN_NONDEBUG_INSN_UID)
2386 cur_debug_insn_uid = MAX (cur_debug_insn_uid, INSN_UID (insn));
2387 else
2389 cur_insn_uid = MAX (cur_insn_uid, INSN_UID (insn));
2390 if (DEBUG_INSN_P (insn))
2391 debug_count++;
2394 if (debug_count)
2395 cur_debug_insn_uid = MIN_NONDEBUG_INSN_UID + debug_count;
2396 else
2397 cur_debug_insn_uid++;
2399 else
2400 for (insn = first; insn; insn = NEXT_INSN (insn))
2401 cur_insn_uid = MAX (cur_insn_uid, INSN_UID (insn));
2403 cur_insn_uid++;
2406 /* Go through all the RTL insn bodies and copy any invalid shared
2407 structure. This routine should only be called once. */
2409 static void
2410 unshare_all_rtl_1 (rtx insn)
2412 /* Unshare just about everything else. */
2413 unshare_all_rtl_in_chain (insn);
2415 /* Make sure the addresses of stack slots found outside the insn chain
2416 (such as, in DECL_RTL of a variable) are not shared
2417 with the insn chain.
2419 This special care is necessary when the stack slot MEM does not
2420 actually appear in the insn chain. If it does appear, its address
2421 is unshared from all else at that point. */
2422 stack_slot_list = copy_rtx_if_shared (stack_slot_list);
2425 /* Go through all the RTL insn bodies and copy any invalid shared
2426 structure, again. This is a fairly expensive thing to do so it
2427 should be done sparingly. */
2429 void
2430 unshare_all_rtl_again (rtx insn)
2432 rtx p;
2433 tree decl;
2435 for (p = insn; p; p = NEXT_INSN (p))
2436 if (INSN_P (p))
2438 reset_used_flags (PATTERN (p));
2439 reset_used_flags (REG_NOTES (p));
2440 if (CALL_P (p))
2441 reset_used_flags (CALL_INSN_FUNCTION_USAGE (p));
2444 /* Make sure that virtual stack slots are not shared. */
2445 set_used_decls (DECL_INITIAL (cfun->decl));
2447 /* Make sure that virtual parameters are not shared. */
2448 for (decl = DECL_ARGUMENTS (cfun->decl); decl; decl = DECL_CHAIN (decl))
2449 set_used_flags (DECL_RTL (decl));
2451 reset_used_flags (stack_slot_list);
2453 unshare_all_rtl_1 (insn);
2456 unsigned int
2457 unshare_all_rtl (void)
2459 unshare_all_rtl_1 (get_insns ());
2460 return 0;
2464 /* Check that ORIG is not marked when it should not be and mark ORIG as in use,
2465 Recursively does the same for subexpressions. */
2467 static void
2468 verify_rtx_sharing (rtx orig, rtx insn)
2470 rtx x = orig;
2471 int i;
2472 enum rtx_code code;
2473 const char *format_ptr;
2475 if (x == 0)
2476 return;
2478 code = GET_CODE (x);
2480 /* These types may be freely shared. */
2482 switch (code)
2484 case REG:
2485 case DEBUG_EXPR:
2486 case VALUE:
2487 CASE_CONST_ANY:
2488 case SYMBOL_REF:
2489 case LABEL_REF:
2490 case CODE_LABEL:
2491 case PC:
2492 case CC0:
2493 case RETURN:
2494 case SIMPLE_RETURN:
2495 case SCRATCH:
2496 /* SCRATCH must be shared because they represent distinct values. */
2497 return;
2498 case CLOBBER:
2499 /* Share clobbers of hard registers (like cc0), but do not share pseudo reg
2500 clobbers or clobbers of hard registers that originated as pseudos.
2501 This is needed to allow safe register renaming. */
2502 if (REG_P (XEXP (x, 0)) && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
2503 && ORIGINAL_REGNO (XEXP (x, 0)) == REGNO (XEXP (x, 0)))
2504 return;
2505 break;
2507 case CONST:
2508 if (shared_const_p (orig))
2509 return;
2510 break;
2512 case MEM:
2513 /* A MEM is allowed to be shared if its address is constant. */
2514 if (CONSTANT_ADDRESS_P (XEXP (x, 0))
2515 || reload_completed || reload_in_progress)
2516 return;
2518 break;
2520 default:
2521 break;
2524 /* This rtx may not be shared. If it has already been seen,
2525 replace it with a copy of itself. */
2526 #ifdef ENABLE_CHECKING
2527 if (RTX_FLAG (x, used))
2529 error ("invalid rtl sharing found in the insn");
2530 debug_rtx (insn);
2531 error ("shared rtx");
2532 debug_rtx (x);
2533 internal_error ("internal consistency failure");
2535 #endif
2536 gcc_assert (!RTX_FLAG (x, used));
2538 RTX_FLAG (x, used) = 1;
2540 /* Now scan the subexpressions recursively. */
2542 format_ptr = GET_RTX_FORMAT (code);
2544 for (i = 0; i < GET_RTX_LENGTH (code); i++)
2546 switch (*format_ptr++)
2548 case 'e':
2549 verify_rtx_sharing (XEXP (x, i), insn);
2550 break;
2552 case 'E':
2553 if (XVEC (x, i) != NULL)
2555 int j;
2556 int len = XVECLEN (x, i);
2558 for (j = 0; j < len; j++)
2560 /* We allow sharing of ASM_OPERANDS inside single
2561 instruction. */
2562 if (j && GET_CODE (XVECEXP (x, i, j)) == SET
2563 && (GET_CODE (SET_SRC (XVECEXP (x, i, j)))
2564 == ASM_OPERANDS))
2565 verify_rtx_sharing (SET_DEST (XVECEXP (x, i, j)), insn);
2566 else
2567 verify_rtx_sharing (XVECEXP (x, i, j), insn);
2570 break;
2573 return;
2576 /* Reset used-flags for INSN. */
2578 static void
2579 reset_insn_used_flags (rtx insn)
2581 gcc_assert (INSN_P (insn));
2582 reset_used_flags (PATTERN (insn));
2583 reset_used_flags (REG_NOTES (insn));
2584 if (CALL_P (insn))
2585 reset_used_flags (CALL_INSN_FUNCTION_USAGE (insn));
2588 /* Go through all the RTL insn bodies and clear all the USED bits. */
2590 static void
2591 reset_all_used_flags (void)
2593 rtx p;
2595 for (p = get_insns (); p; p = NEXT_INSN (p))
2596 if (INSN_P (p))
2598 rtx pat = PATTERN (p);
2599 if (GET_CODE (pat) != SEQUENCE)
2600 reset_insn_used_flags (p);
2601 else
2603 gcc_assert (REG_NOTES (p) == NULL);
2604 for (int i = 0; i < XVECLEN (pat, 0); i++)
2605 reset_insn_used_flags (XVECEXP (pat, 0, i));
2610 /* Verify sharing in INSN. */
2612 static void
2613 verify_insn_sharing (rtx insn)
2615 gcc_assert (INSN_P (insn));
2616 reset_used_flags (PATTERN (insn));
2617 reset_used_flags (REG_NOTES (insn));
2618 if (CALL_P (insn))
2619 reset_used_flags (CALL_INSN_FUNCTION_USAGE (insn));
2622 /* Go through all the RTL insn bodies and check that there is no unexpected
2623 sharing in between the subexpressions. */
2625 DEBUG_FUNCTION void
2626 verify_rtl_sharing (void)
2628 rtx p;
2630 timevar_push (TV_VERIFY_RTL_SHARING);
2632 reset_all_used_flags ();
2634 for (p = get_insns (); p; p = NEXT_INSN (p))
2635 if (INSN_P (p))
2637 rtx pat = PATTERN (p);
2638 if (GET_CODE (pat) != SEQUENCE)
2639 verify_insn_sharing (p);
2640 else
2641 for (int i = 0; i < XVECLEN (pat, 0); i++)
2642 verify_insn_sharing (XVECEXP (pat, 0, i));
2645 reset_all_used_flags ();
2647 timevar_pop (TV_VERIFY_RTL_SHARING);
2650 /* Go through all the RTL insn bodies and copy any invalid shared structure.
2651 Assumes the mark bits are cleared at entry. */
2653 void
2654 unshare_all_rtl_in_chain (rtx insn)
2656 for (; insn; insn = NEXT_INSN (insn))
2657 if (INSN_P (insn))
2659 PATTERN (insn) = copy_rtx_if_shared (PATTERN (insn));
2660 REG_NOTES (insn) = copy_rtx_if_shared (REG_NOTES (insn));
2661 if (CALL_P (insn))
2662 CALL_INSN_FUNCTION_USAGE (insn)
2663 = copy_rtx_if_shared (CALL_INSN_FUNCTION_USAGE (insn));
2667 /* Go through all virtual stack slots of a function and mark them as
2668 shared. We never replace the DECL_RTLs themselves with a copy,
2669 but expressions mentioned into a DECL_RTL cannot be shared with
2670 expressions in the instruction stream.
2672 Note that reload may convert pseudo registers into memories in-place.
2673 Pseudo registers are always shared, but MEMs never are. Thus if we
2674 reset the used flags on MEMs in the instruction stream, we must set
2675 them again on MEMs that appear in DECL_RTLs. */
2677 static void
2678 set_used_decls (tree blk)
2680 tree t;
2682 /* Mark decls. */
2683 for (t = BLOCK_VARS (blk); t; t = DECL_CHAIN (t))
2684 if (DECL_RTL_SET_P (t))
2685 set_used_flags (DECL_RTL (t));
2687 /* Now process sub-blocks. */
2688 for (t = BLOCK_SUBBLOCKS (blk); t; t = BLOCK_CHAIN (t))
2689 set_used_decls (t);
2692 /* Mark ORIG as in use, and return a copy of it if it was already in use.
2693 Recursively does the same for subexpressions. Uses
2694 copy_rtx_if_shared_1 to reduce stack space. */
2697 copy_rtx_if_shared (rtx orig)
2699 copy_rtx_if_shared_1 (&orig);
2700 return orig;
2703 /* Mark *ORIG1 as in use, and set it to a copy of it if it was already in
2704 use. Recursively does the same for subexpressions. */
2706 static void
2707 copy_rtx_if_shared_1 (rtx *orig1)
2709 rtx x;
2710 int i;
2711 enum rtx_code code;
2712 rtx *last_ptr;
2713 const char *format_ptr;
2714 int copied = 0;
2715 int length;
2717 /* Repeat is used to turn tail-recursion into iteration. */
2718 repeat:
2719 x = *orig1;
2721 if (x == 0)
2722 return;
2724 code = GET_CODE (x);
2726 /* These types may be freely shared. */
2728 switch (code)
2730 case REG:
2731 case DEBUG_EXPR:
2732 case VALUE:
2733 CASE_CONST_ANY:
2734 case SYMBOL_REF:
2735 case LABEL_REF:
2736 case CODE_LABEL:
2737 case PC:
2738 case CC0:
2739 case RETURN:
2740 case SIMPLE_RETURN:
2741 case SCRATCH:
2742 /* SCRATCH must be shared because they represent distinct values. */
2743 return;
2744 case CLOBBER:
2745 /* Share clobbers of hard registers (like cc0), but do not share pseudo reg
2746 clobbers or clobbers of hard registers that originated as pseudos.
2747 This is needed to allow safe register renaming. */
2748 if (REG_P (XEXP (x, 0)) && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
2749 && ORIGINAL_REGNO (XEXP (x, 0)) == REGNO (XEXP (x, 0)))
2750 return;
2751 break;
2753 case CONST:
2754 if (shared_const_p (x))
2755 return;
2756 break;
2758 case DEBUG_INSN:
2759 case INSN:
2760 case JUMP_INSN:
2761 case CALL_INSN:
2762 case NOTE:
2763 case BARRIER:
2764 /* The chain of insns is not being copied. */
2765 return;
2767 default:
2768 break;
2771 /* This rtx may not be shared. If it has already been seen,
2772 replace it with a copy of itself. */
2774 if (RTX_FLAG (x, used))
2776 x = shallow_copy_rtx (x);
2777 copied = 1;
2779 RTX_FLAG (x, used) = 1;
2781 /* Now scan the subexpressions recursively.
2782 We can store any replaced subexpressions directly into X
2783 since we know X is not shared! Any vectors in X
2784 must be copied if X was copied. */
2786 format_ptr = GET_RTX_FORMAT (code);
2787 length = GET_RTX_LENGTH (code);
2788 last_ptr = NULL;
2790 for (i = 0; i < length; i++)
2792 switch (*format_ptr++)
2794 case 'e':
2795 if (last_ptr)
2796 copy_rtx_if_shared_1 (last_ptr);
2797 last_ptr = &XEXP (x, i);
2798 break;
2800 case 'E':
2801 if (XVEC (x, i) != NULL)
2803 int j;
2804 int len = XVECLEN (x, i);
2806 /* Copy the vector iff I copied the rtx and the length
2807 is nonzero. */
2808 if (copied && len > 0)
2809 XVEC (x, i) = gen_rtvec_v (len, XVEC (x, i)->elem);
2811 /* Call recursively on all inside the vector. */
2812 for (j = 0; j < len; j++)
2814 if (last_ptr)
2815 copy_rtx_if_shared_1 (last_ptr);
2816 last_ptr = &XVECEXP (x, i, j);
2819 break;
2822 *orig1 = x;
2823 if (last_ptr)
2825 orig1 = last_ptr;
2826 goto repeat;
2828 return;
2831 /* Set the USED bit in X and its non-shareable subparts to FLAG. */
2833 static void
2834 mark_used_flags (rtx x, int flag)
2836 int i, j;
2837 enum rtx_code code;
2838 const char *format_ptr;
2839 int length;
2841 /* Repeat is used to turn tail-recursion into iteration. */
2842 repeat:
2843 if (x == 0)
2844 return;
2846 code = GET_CODE (x);
2848 /* These types may be freely shared so we needn't do any resetting
2849 for them. */
2851 switch (code)
2853 case REG:
2854 case DEBUG_EXPR:
2855 case VALUE:
2856 CASE_CONST_ANY:
2857 case SYMBOL_REF:
2858 case CODE_LABEL:
2859 case PC:
2860 case CC0:
2861 case RETURN:
2862 case SIMPLE_RETURN:
2863 return;
2865 case DEBUG_INSN:
2866 case INSN:
2867 case JUMP_INSN:
2868 case CALL_INSN:
2869 case NOTE:
2870 case LABEL_REF:
2871 case BARRIER:
2872 /* The chain of insns is not being copied. */
2873 return;
2875 default:
2876 break;
2879 RTX_FLAG (x, used) = flag;
2881 format_ptr = GET_RTX_FORMAT (code);
2882 length = GET_RTX_LENGTH (code);
2884 for (i = 0; i < length; i++)
2886 switch (*format_ptr++)
2888 case 'e':
2889 if (i == length-1)
2891 x = XEXP (x, i);
2892 goto repeat;
2894 mark_used_flags (XEXP (x, i), flag);
2895 break;
2897 case 'E':
2898 for (j = 0; j < XVECLEN (x, i); j++)
2899 mark_used_flags (XVECEXP (x, i, j), flag);
2900 break;
2905 /* Clear all the USED bits in X to allow copy_rtx_if_shared to be used
2906 to look for shared sub-parts. */
2908 void
2909 reset_used_flags (rtx x)
2911 mark_used_flags (x, 0);
2914 /* Set all the USED bits in X to allow copy_rtx_if_shared to be used
2915 to look for shared sub-parts. */
2917 void
2918 set_used_flags (rtx x)
2920 mark_used_flags (x, 1);
2923 /* Copy X if necessary so that it won't be altered by changes in OTHER.
2924 Return X or the rtx for the pseudo reg the value of X was copied into.
2925 OTHER must be valid as a SET_DEST. */
2928 make_safe_from (rtx x, rtx other)
2930 while (1)
2931 switch (GET_CODE (other))
2933 case SUBREG:
2934 other = SUBREG_REG (other);
2935 break;
2936 case STRICT_LOW_PART:
2937 case SIGN_EXTEND:
2938 case ZERO_EXTEND:
2939 other = XEXP (other, 0);
2940 break;
2941 default:
2942 goto done;
2944 done:
2945 if ((MEM_P (other)
2946 && ! CONSTANT_P (x)
2947 && !REG_P (x)
2948 && GET_CODE (x) != SUBREG)
2949 || (REG_P (other)
2950 && (REGNO (other) < FIRST_PSEUDO_REGISTER
2951 || reg_mentioned_p (other, x))))
2953 rtx temp = gen_reg_rtx (GET_MODE (x));
2954 emit_move_insn (temp, x);
2955 return temp;
2957 return x;
2960 /* Emission of insns (adding them to the doubly-linked list). */
2962 /* Return the last insn emitted, even if it is in a sequence now pushed. */
2965 get_last_insn_anywhere (void)
2967 struct sequence_stack *stack;
2968 if (get_last_insn ())
2969 return get_last_insn ();
2970 for (stack = seq_stack; stack; stack = stack->next)
2971 if (stack->last != 0)
2972 return stack->last;
2973 return 0;
2976 /* Return the first nonnote insn emitted in current sequence or current
2977 function. This routine looks inside SEQUENCEs. */
2980 get_first_nonnote_insn (void)
2982 rtx insn = get_insns ();
2984 if (insn)
2986 if (NOTE_P (insn))
2987 for (insn = next_insn (insn);
2988 insn && NOTE_P (insn);
2989 insn = next_insn (insn))
2990 continue;
2991 else
2993 if (NONJUMP_INSN_P (insn)
2994 && GET_CODE (PATTERN (insn)) == SEQUENCE)
2995 insn = XVECEXP (PATTERN (insn), 0, 0);
2999 return insn;
3002 /* Return the last nonnote insn emitted in current sequence or current
3003 function. This routine looks inside SEQUENCEs. */
3006 get_last_nonnote_insn (void)
3008 rtx insn = get_last_insn ();
3010 if (insn)
3012 if (NOTE_P (insn))
3013 for (insn = previous_insn (insn);
3014 insn && NOTE_P (insn);
3015 insn = previous_insn (insn))
3016 continue;
3017 else
3019 if (NONJUMP_INSN_P (insn)
3020 && GET_CODE (PATTERN (insn)) == SEQUENCE)
3021 insn = XVECEXP (PATTERN (insn), 0,
3022 XVECLEN (PATTERN (insn), 0) - 1);
3026 return insn;
3029 /* Return the number of actual (non-debug) insns emitted in this
3030 function. */
3033 get_max_insn_count (void)
3035 int n = cur_insn_uid;
3037 /* The table size must be stable across -g, to avoid codegen
3038 differences due to debug insns, and not be affected by
3039 -fmin-insn-uid, to avoid excessive table size and to simplify
3040 debugging of -fcompare-debug failures. */
3041 if (cur_debug_insn_uid > MIN_NONDEBUG_INSN_UID)
3042 n -= cur_debug_insn_uid;
3043 else
3044 n -= MIN_NONDEBUG_INSN_UID;
3046 return n;
3050 /* Return the next insn. If it is a SEQUENCE, return the first insn
3051 of the sequence. */
3054 next_insn (rtx insn)
3056 if (insn)
3058 insn = NEXT_INSN (insn);
3059 if (insn && NONJUMP_INSN_P (insn)
3060 && GET_CODE (PATTERN (insn)) == SEQUENCE)
3061 insn = XVECEXP (PATTERN (insn), 0, 0);
3064 return insn;
3067 /* Return the previous insn. If it is a SEQUENCE, return the last insn
3068 of the sequence. */
3071 previous_insn (rtx insn)
3073 if (insn)
3075 insn = PREV_INSN (insn);
3076 if (insn && NONJUMP_INSN_P (insn)
3077 && GET_CODE (PATTERN (insn)) == SEQUENCE)
3078 insn = XVECEXP (PATTERN (insn), 0, XVECLEN (PATTERN (insn), 0) - 1);
3081 return insn;
3084 /* Return the next insn after INSN that is not a NOTE. This routine does not
3085 look inside SEQUENCEs. */
3088 next_nonnote_insn (rtx insn)
3090 while (insn)
3092 insn = NEXT_INSN (insn);
3093 if (insn == 0 || !NOTE_P (insn))
3094 break;
3097 return insn;
3100 /* Return the next insn after INSN that is not a NOTE, but stop the
3101 search before we enter another basic block. This routine does not
3102 look inside SEQUENCEs. */
3105 next_nonnote_insn_bb (rtx insn)
3107 while (insn)
3109 insn = NEXT_INSN (insn);
3110 if (insn == 0 || !NOTE_P (insn))
3111 break;
3112 if (NOTE_INSN_BASIC_BLOCK_P (insn))
3113 return NULL_RTX;
3116 return insn;
3119 /* Return the previous insn before INSN that is not a NOTE. This routine does
3120 not look inside SEQUENCEs. */
3123 prev_nonnote_insn (rtx insn)
3125 while (insn)
3127 insn = PREV_INSN (insn);
3128 if (insn == 0 || !NOTE_P (insn))
3129 break;
3132 return insn;
3135 /* Return the previous insn before INSN that is not a NOTE, but stop
3136 the search before we enter another basic block. This routine does
3137 not look inside SEQUENCEs. */
3140 prev_nonnote_insn_bb (rtx insn)
3142 while (insn)
3144 insn = PREV_INSN (insn);
3145 if (insn == 0 || !NOTE_P (insn))
3146 break;
3147 if (NOTE_INSN_BASIC_BLOCK_P (insn))
3148 return NULL_RTX;
3151 return insn;
3154 /* Return the next insn after INSN that is not a DEBUG_INSN. This
3155 routine does not look inside SEQUENCEs. */
3158 next_nondebug_insn (rtx insn)
3160 while (insn)
3162 insn = NEXT_INSN (insn);
3163 if (insn == 0 || !DEBUG_INSN_P (insn))
3164 break;
3167 return insn;
3170 /* Return the previous insn before INSN that is not a DEBUG_INSN.
3171 This routine does not look inside SEQUENCEs. */
3174 prev_nondebug_insn (rtx insn)
3176 while (insn)
3178 insn = PREV_INSN (insn);
3179 if (insn == 0 || !DEBUG_INSN_P (insn))
3180 break;
3183 return insn;
3186 /* Return the next insn after INSN that is not a NOTE nor DEBUG_INSN.
3187 This routine does not look inside SEQUENCEs. */
3190 next_nonnote_nondebug_insn (rtx insn)
3192 while (insn)
3194 insn = NEXT_INSN (insn);
3195 if (insn == 0 || (!NOTE_P (insn) && !DEBUG_INSN_P (insn)))
3196 break;
3199 return insn;
3202 /* Return the previous insn before INSN that is not a NOTE nor DEBUG_INSN.
3203 This routine does not look inside SEQUENCEs. */
3206 prev_nonnote_nondebug_insn (rtx insn)
3208 while (insn)
3210 insn = PREV_INSN (insn);
3211 if (insn == 0 || (!NOTE_P (insn) && !DEBUG_INSN_P (insn)))
3212 break;
3215 return insn;
3218 /* Return the next INSN, CALL_INSN or JUMP_INSN after INSN;
3219 or 0, if there is none. This routine does not look inside
3220 SEQUENCEs. */
3223 next_real_insn (rtx insn)
3225 while (insn)
3227 insn = NEXT_INSN (insn);
3228 if (insn == 0 || INSN_P (insn))
3229 break;
3232 return insn;
3235 /* Return the last INSN, CALL_INSN or JUMP_INSN before INSN;
3236 or 0, if there is none. This routine does not look inside
3237 SEQUENCEs. */
3240 prev_real_insn (rtx insn)
3242 while (insn)
3244 insn = PREV_INSN (insn);
3245 if (insn == 0 || INSN_P (insn))
3246 break;
3249 return insn;
3252 /* Return the last CALL_INSN in the current list, or 0 if there is none.
3253 This routine does not look inside SEQUENCEs. */
3256 last_call_insn (void)
3258 rtx insn;
3260 for (insn = get_last_insn ();
3261 insn && !CALL_P (insn);
3262 insn = PREV_INSN (insn))
3265 return insn;
3268 /* Find the next insn after INSN that really does something. This routine
3269 does not look inside SEQUENCEs. After reload this also skips over
3270 standalone USE and CLOBBER insn. */
3273 active_insn_p (const_rtx insn)
3275 return (CALL_P (insn) || JUMP_P (insn)
3276 || JUMP_TABLE_DATA_P (insn) /* FIXME */
3277 || (NONJUMP_INSN_P (insn)
3278 && (! reload_completed
3279 || (GET_CODE (PATTERN (insn)) != USE
3280 && GET_CODE (PATTERN (insn)) != CLOBBER))));
3284 next_active_insn (rtx insn)
3286 while (insn)
3288 insn = NEXT_INSN (insn);
3289 if (insn == 0 || active_insn_p (insn))
3290 break;
3293 return insn;
3296 /* Find the last insn before INSN that really does something. This routine
3297 does not look inside SEQUENCEs. After reload this also skips over
3298 standalone USE and CLOBBER insn. */
3301 prev_active_insn (rtx insn)
3303 while (insn)
3305 insn = PREV_INSN (insn);
3306 if (insn == 0 || active_insn_p (insn))
3307 break;
3310 return insn;
3313 #ifdef HAVE_cc0
3314 /* Return the next insn that uses CC0 after INSN, which is assumed to
3315 set it. This is the inverse of prev_cc0_setter (i.e., prev_cc0_setter
3316 applied to the result of this function should yield INSN).
3318 Normally, this is simply the next insn. However, if a REG_CC_USER note
3319 is present, it contains the insn that uses CC0.
3321 Return 0 if we can't find the insn. */
3324 next_cc0_user (rtx insn)
3326 rtx note = find_reg_note (insn, REG_CC_USER, NULL_RTX);
3328 if (note)
3329 return XEXP (note, 0);
3331 insn = next_nonnote_insn (insn);
3332 if (insn && NONJUMP_INSN_P (insn) && GET_CODE (PATTERN (insn)) == SEQUENCE)
3333 insn = XVECEXP (PATTERN (insn), 0, 0);
3335 if (insn && INSN_P (insn) && reg_mentioned_p (cc0_rtx, PATTERN (insn)))
3336 return insn;
3338 return 0;
3341 /* Find the insn that set CC0 for INSN. Unless INSN has a REG_CC_SETTER
3342 note, it is the previous insn. */
3345 prev_cc0_setter (rtx insn)
3347 rtx note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
3349 if (note)
3350 return XEXP (note, 0);
3352 insn = prev_nonnote_insn (insn);
3353 gcc_assert (sets_cc0_p (PATTERN (insn)));
3355 return insn;
3357 #endif
3359 #ifdef AUTO_INC_DEC
3360 /* Find a RTX_AUTOINC class rtx which matches DATA. */
3362 static int
3363 find_auto_inc (rtx *xp, void *data)
3365 rtx x = *xp;
3366 rtx reg = (rtx) data;
3368 if (GET_RTX_CLASS (GET_CODE (x)) != RTX_AUTOINC)
3369 return 0;
3371 switch (GET_CODE (x))
3373 case PRE_DEC:
3374 case PRE_INC:
3375 case POST_DEC:
3376 case POST_INC:
3377 case PRE_MODIFY:
3378 case POST_MODIFY:
3379 if (rtx_equal_p (reg, XEXP (x, 0)))
3380 return 1;
3381 break;
3383 default:
3384 gcc_unreachable ();
3386 return -1;
3388 #endif
3390 /* Increment the label uses for all labels present in rtx. */
3392 static void
3393 mark_label_nuses (rtx x)
3395 enum rtx_code code;
3396 int i, j;
3397 const char *fmt;
3399 code = GET_CODE (x);
3400 if (code == LABEL_REF && LABEL_P (XEXP (x, 0)))
3401 LABEL_NUSES (XEXP (x, 0))++;
3403 fmt = GET_RTX_FORMAT (code);
3404 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
3406 if (fmt[i] == 'e')
3407 mark_label_nuses (XEXP (x, i));
3408 else if (fmt[i] == 'E')
3409 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
3410 mark_label_nuses (XVECEXP (x, i, j));
3415 /* Try splitting insns that can be split for better scheduling.
3416 PAT is the pattern which might split.
3417 TRIAL is the insn providing PAT.
3418 LAST is nonzero if we should return the last insn of the sequence produced.
3420 If this routine succeeds in splitting, it returns the first or last
3421 replacement insn depending on the value of LAST. Otherwise, it
3422 returns TRIAL. If the insn to be returned can be split, it will be. */
3425 try_split (rtx pat, rtx trial, int last)
3427 rtx before = PREV_INSN (trial);
3428 rtx after = NEXT_INSN (trial);
3429 int has_barrier = 0;
3430 rtx note, seq, tem;
3431 int probability;
3432 rtx insn_last, insn;
3433 int njumps = 0;
3435 /* We're not good at redistributing frame information. */
3436 if (RTX_FRAME_RELATED_P (trial))
3437 return trial;
3439 if (any_condjump_p (trial)
3440 && (note = find_reg_note (trial, REG_BR_PROB, 0)))
3441 split_branch_probability = XINT (note, 0);
3442 probability = split_branch_probability;
3444 seq = split_insns (pat, trial);
3446 split_branch_probability = -1;
3448 /* If we are splitting a JUMP_INSN, it might be followed by a BARRIER.
3449 We may need to handle this specially. */
3450 if (after && BARRIER_P (after))
3452 has_barrier = 1;
3453 after = NEXT_INSN (after);
3456 if (!seq)
3457 return trial;
3459 /* Avoid infinite loop if any insn of the result matches
3460 the original pattern. */
3461 insn_last = seq;
3462 while (1)
3464 if (INSN_P (insn_last)
3465 && rtx_equal_p (PATTERN (insn_last), pat))
3466 return trial;
3467 if (!NEXT_INSN (insn_last))
3468 break;
3469 insn_last = NEXT_INSN (insn_last);
3472 /* We will be adding the new sequence to the function. The splitters
3473 may have introduced invalid RTL sharing, so unshare the sequence now. */
3474 unshare_all_rtl_in_chain (seq);
3476 /* Mark labels. */
3477 for (insn = insn_last; insn ; insn = PREV_INSN (insn))
3479 if (JUMP_P (insn))
3481 mark_jump_label (PATTERN (insn), insn, 0);
3482 njumps++;
3483 if (probability != -1
3484 && any_condjump_p (insn)
3485 && !find_reg_note (insn, REG_BR_PROB, 0))
3487 /* We can preserve the REG_BR_PROB notes only if exactly
3488 one jump is created, otherwise the machine description
3489 is responsible for this step using
3490 split_branch_probability variable. */
3491 gcc_assert (njumps == 1);
3492 add_int_reg_note (insn, REG_BR_PROB, probability);
3497 /* If we are splitting a CALL_INSN, look for the CALL_INSN
3498 in SEQ and copy any additional information across. */
3499 if (CALL_P (trial))
3501 for (insn = insn_last; insn ; insn = PREV_INSN (insn))
3502 if (CALL_P (insn))
3504 rtx next, *p;
3506 /* Add the old CALL_INSN_FUNCTION_USAGE to whatever the
3507 target may have explicitly specified. */
3508 p = &CALL_INSN_FUNCTION_USAGE (insn);
3509 while (*p)
3510 p = &XEXP (*p, 1);
3511 *p = CALL_INSN_FUNCTION_USAGE (trial);
3513 /* If the old call was a sibling call, the new one must
3514 be too. */
3515 SIBLING_CALL_P (insn) = SIBLING_CALL_P (trial);
3517 /* If the new call is the last instruction in the sequence,
3518 it will effectively replace the old call in-situ. Otherwise
3519 we must move any following NOTE_INSN_CALL_ARG_LOCATION note
3520 so that it comes immediately after the new call. */
3521 if (NEXT_INSN (insn))
3522 for (next = NEXT_INSN (trial);
3523 next && NOTE_P (next);
3524 next = NEXT_INSN (next))
3525 if (NOTE_KIND (next) == NOTE_INSN_CALL_ARG_LOCATION)
3527 remove_insn (next);
3528 add_insn_after (next, insn, NULL);
3529 break;
3534 /* Copy notes, particularly those related to the CFG. */
3535 for (note = REG_NOTES (trial); note; note = XEXP (note, 1))
3537 switch (REG_NOTE_KIND (note))
3539 case REG_EH_REGION:
3540 copy_reg_eh_region_note_backward (note, insn_last, NULL);
3541 break;
3543 case REG_NORETURN:
3544 case REG_SETJMP:
3545 case REG_TM:
3546 for (insn = insn_last; insn != NULL_RTX; insn = PREV_INSN (insn))
3548 if (CALL_P (insn))
3549 add_reg_note (insn, REG_NOTE_KIND (note), XEXP (note, 0));
3551 break;
3553 case REG_NON_LOCAL_GOTO:
3554 case REG_CROSSING_JUMP:
3555 for (insn = insn_last; insn != NULL_RTX; insn = PREV_INSN (insn))
3557 if (JUMP_P (insn))
3558 add_reg_note (insn, REG_NOTE_KIND (note), XEXP (note, 0));
3560 break;
3562 #ifdef AUTO_INC_DEC
3563 case REG_INC:
3564 for (insn = insn_last; insn != NULL_RTX; insn = PREV_INSN (insn))
3566 rtx reg = XEXP (note, 0);
3567 if (!FIND_REG_INC_NOTE (insn, reg)
3568 && for_each_rtx (&PATTERN (insn), find_auto_inc, reg) > 0)
3569 add_reg_note (insn, REG_INC, reg);
3571 break;
3572 #endif
3574 case REG_ARGS_SIZE:
3575 fixup_args_size_notes (NULL_RTX, insn_last, INTVAL (XEXP (note, 0)));
3576 break;
3578 default:
3579 break;
3583 /* If there are LABELS inside the split insns increment the
3584 usage count so we don't delete the label. */
3585 if (INSN_P (trial))
3587 insn = insn_last;
3588 while (insn != NULL_RTX)
3590 /* JUMP_P insns have already been "marked" above. */
3591 if (NONJUMP_INSN_P (insn))
3592 mark_label_nuses (PATTERN (insn));
3594 insn = PREV_INSN (insn);
3598 tem = emit_insn_after_setloc (seq, trial, INSN_LOCATION (trial));
3600 delete_insn (trial);
3601 if (has_barrier)
3602 emit_barrier_after (tem);
3604 /* Recursively call try_split for each new insn created; by the
3605 time control returns here that insn will be fully split, so
3606 set LAST and continue from the insn after the one returned.
3607 We can't use next_active_insn here since AFTER may be a note.
3608 Ignore deleted insns, which can be occur if not optimizing. */
3609 for (tem = NEXT_INSN (before); tem != after; tem = NEXT_INSN (tem))
3610 if (! INSN_DELETED_P (tem) && INSN_P (tem))
3611 tem = try_split (PATTERN (tem), tem, 1);
3613 /* Return either the first or the last insn, depending on which was
3614 requested. */
3615 return last
3616 ? (after ? PREV_INSN (after) : get_last_insn ())
3617 : NEXT_INSN (before);
3620 /* Make and return an INSN rtx, initializing all its slots.
3621 Store PATTERN in the pattern slots. */
3624 make_insn_raw (rtx pattern)
3626 rtx insn;
3628 insn = rtx_alloc (INSN);
3630 INSN_UID (insn) = cur_insn_uid++;
3631 PATTERN (insn) = pattern;
3632 INSN_CODE (insn) = -1;
3633 REG_NOTES (insn) = NULL;
3634 INSN_LOCATION (insn) = curr_insn_location ();
3635 BLOCK_FOR_INSN (insn) = NULL;
3637 #ifdef ENABLE_RTL_CHECKING
3638 if (insn
3639 && INSN_P (insn)
3640 && (returnjump_p (insn)
3641 || (GET_CODE (insn) == SET
3642 && SET_DEST (insn) == pc_rtx)))
3644 warning (0, "ICE: emit_insn used where emit_jump_insn needed:\n");
3645 debug_rtx (insn);
3647 #endif
3649 return insn;
3652 /* Like `make_insn_raw' but make a DEBUG_INSN instead of an insn. */
3654 static rtx
3655 make_debug_insn_raw (rtx pattern)
3657 rtx insn;
3659 insn = rtx_alloc (DEBUG_INSN);
3660 INSN_UID (insn) = cur_debug_insn_uid++;
3661 if (cur_debug_insn_uid > MIN_NONDEBUG_INSN_UID)
3662 INSN_UID (insn) = cur_insn_uid++;
3664 PATTERN (insn) = pattern;
3665 INSN_CODE (insn) = -1;
3666 REG_NOTES (insn) = NULL;
3667 INSN_LOCATION (insn) = curr_insn_location ();
3668 BLOCK_FOR_INSN (insn) = NULL;
3670 return insn;
3673 /* Like `make_insn_raw' but make a JUMP_INSN instead of an insn. */
3675 static rtx
3676 make_jump_insn_raw (rtx pattern)
3678 rtx insn;
3680 insn = rtx_alloc (JUMP_INSN);
3681 INSN_UID (insn) = cur_insn_uid++;
3683 PATTERN (insn) = pattern;
3684 INSN_CODE (insn) = -1;
3685 REG_NOTES (insn) = NULL;
3686 JUMP_LABEL (insn) = NULL;
3687 INSN_LOCATION (insn) = curr_insn_location ();
3688 BLOCK_FOR_INSN (insn) = NULL;
3690 return insn;
3693 /* Like `make_insn_raw' but make a CALL_INSN instead of an insn. */
3695 static rtx
3696 make_call_insn_raw (rtx pattern)
3698 rtx insn;
3700 insn = rtx_alloc (CALL_INSN);
3701 INSN_UID (insn) = cur_insn_uid++;
3703 PATTERN (insn) = pattern;
3704 INSN_CODE (insn) = -1;
3705 REG_NOTES (insn) = NULL;
3706 CALL_INSN_FUNCTION_USAGE (insn) = NULL;
3707 INSN_LOCATION (insn) = curr_insn_location ();
3708 BLOCK_FOR_INSN (insn) = NULL;
3710 return insn;
3713 /* Like `make_insn_raw' but make a NOTE instead of an insn. */
3715 static rtx
3716 make_note_raw (enum insn_note subtype)
3718 /* Some notes are never created this way at all. These notes are
3719 only created by patching out insns. */
3720 gcc_assert (subtype != NOTE_INSN_DELETED_LABEL
3721 && subtype != NOTE_INSN_DELETED_DEBUG_LABEL);
3723 rtx note = rtx_alloc (NOTE);
3724 INSN_UID (note) = cur_insn_uid++;
3725 NOTE_KIND (note) = subtype;
3726 BLOCK_FOR_INSN (note) = NULL;
3727 memset (&NOTE_DATA (note), 0, sizeof (NOTE_DATA (note)));
3728 return note;
3731 /* Add INSN to the end of the doubly-linked list, between PREV and NEXT.
3732 INSN may be any object that can appear in the chain: INSN_P and NOTE_P objects,
3733 but also BARRIERs and JUMP_TABLE_DATAs. PREV and NEXT may be NULL. */
3735 static inline void
3736 link_insn_into_chain (rtx insn, rtx prev, rtx next)
3738 PREV_INSN (insn) = prev;
3739 NEXT_INSN (insn) = next;
3740 if (prev != NULL)
3742 NEXT_INSN (prev) = insn;
3743 if (NONJUMP_INSN_P (prev) && GET_CODE (PATTERN (prev)) == SEQUENCE)
3745 rtx sequence = PATTERN (prev);
3746 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
3749 if (next != NULL)
3751 PREV_INSN (next) = insn;
3752 if (NONJUMP_INSN_P (next) && GET_CODE (PATTERN (next)) == SEQUENCE)
3753 PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = insn;
3756 if (NONJUMP_INSN_P (insn) && GET_CODE (PATTERN (insn)) == SEQUENCE)
3758 rtx sequence = PATTERN (insn);
3759 PREV_INSN (XVECEXP (sequence, 0, 0)) = prev;
3760 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = next;
3764 /* Add INSN to the end of the doubly-linked list.
3765 INSN may be an INSN, JUMP_INSN, CALL_INSN, CODE_LABEL, BARRIER or NOTE. */
3767 void
3768 add_insn (rtx insn)
3770 rtx prev = get_last_insn ();
3771 link_insn_into_chain (insn, prev, NULL);
3772 if (NULL == get_insns ())
3773 set_first_insn (insn);
3774 set_last_insn (insn);
3777 /* Add INSN into the doubly-linked list after insn AFTER. */
3779 static void
3780 add_insn_after_nobb (rtx insn, rtx after)
3782 rtx next = NEXT_INSN (after);
3784 gcc_assert (!optimize || !INSN_DELETED_P (after));
3786 link_insn_into_chain (insn, after, next);
3788 if (next == NULL)
3790 if (get_last_insn () == after)
3791 set_last_insn (insn);
3792 else
3794 struct sequence_stack *stack = seq_stack;
3795 /* Scan all pending sequences too. */
3796 for (; stack; stack = stack->next)
3797 if (after == stack->last)
3799 stack->last = insn;
3800 break;
3806 /* Add INSN into the doubly-linked list before insn BEFORE. */
3808 static void
3809 add_insn_before_nobb (rtx insn, rtx before)
3811 rtx prev = PREV_INSN (before);
3813 gcc_assert (!optimize || !INSN_DELETED_P (before));
3815 link_insn_into_chain (insn, prev, before);
3817 if (prev == NULL)
3819 if (get_insns () == before)
3820 set_first_insn (insn);
3821 else
3823 struct sequence_stack *stack = seq_stack;
3824 /* Scan all pending sequences too. */
3825 for (; stack; stack = stack->next)
3826 if (before == stack->first)
3828 stack->first = insn;
3829 break;
3832 gcc_assert (stack);
3837 /* Like add_insn_after_nobb, but try to set BLOCK_FOR_INSN.
3838 If BB is NULL, an attempt is made to infer the bb from before.
3840 This and the next function should be the only functions called
3841 to insert an insn once delay slots have been filled since only
3842 they know how to update a SEQUENCE. */
3844 void
3845 add_insn_after (rtx insn, rtx after, basic_block bb)
3847 add_insn_after_nobb (insn, after);
3848 if (!BARRIER_P (after)
3849 && !BARRIER_P (insn)
3850 && (bb = BLOCK_FOR_INSN (after)))
3852 set_block_for_insn (insn, bb);
3853 if (INSN_P (insn))
3854 df_insn_rescan (insn);
3855 /* Should not happen as first in the BB is always
3856 either NOTE or LABEL. */
3857 if (BB_END (bb) == after
3858 /* Avoid clobbering of structure when creating new BB. */
3859 && !BARRIER_P (insn)
3860 && !NOTE_INSN_BASIC_BLOCK_P (insn))
3861 BB_END (bb) = insn;
3865 /* Like add_insn_before_nobb, but try to set BLOCK_FOR_INSN.
3866 If BB is NULL, an attempt is made to infer the bb from before.
3868 This and the previous function should be the only functions called
3869 to insert an insn once delay slots have been filled since only
3870 they know how to update a SEQUENCE. */
3872 void
3873 add_insn_before (rtx insn, rtx before, basic_block bb)
3875 add_insn_before_nobb (insn, before);
3877 if (!bb
3878 && !BARRIER_P (before)
3879 && !BARRIER_P (insn))
3880 bb = BLOCK_FOR_INSN (before);
3882 if (bb)
3884 set_block_for_insn (insn, bb);
3885 if (INSN_P (insn))
3886 df_insn_rescan (insn);
3887 /* Should not happen as first in the BB is always either NOTE or
3888 LABEL. */
3889 gcc_assert (BB_HEAD (bb) != insn
3890 /* Avoid clobbering of structure when creating new BB. */
3891 || BARRIER_P (insn)
3892 || NOTE_INSN_BASIC_BLOCK_P (insn));
3896 /* Replace insn with an deleted instruction note. */
3898 void
3899 set_insn_deleted (rtx insn)
3901 if (INSN_P (insn))
3902 df_insn_delete (insn);
3903 PUT_CODE (insn, NOTE);
3904 NOTE_KIND (insn) = NOTE_INSN_DELETED;
3908 /* Unlink INSN from the insn chain.
3910 This function knows how to handle sequences.
3912 This function does not invalidate data flow information associated with
3913 INSN (i.e. does not call df_insn_delete). That makes this function
3914 usable for only disconnecting an insn from the chain, and re-emit it
3915 elsewhere later.
3917 To later insert INSN elsewhere in the insn chain via add_insn and
3918 similar functions, PREV_INSN and NEXT_INSN must be nullified by
3919 the caller. Nullifying them here breaks many insn chain walks.
3921 To really delete an insn and related DF information, use delete_insn. */
3923 void
3924 remove_insn (rtx insn)
3926 rtx next = NEXT_INSN (insn);
3927 rtx prev = PREV_INSN (insn);
3928 basic_block bb;
3930 if (prev)
3932 NEXT_INSN (prev) = next;
3933 if (NONJUMP_INSN_P (prev) && GET_CODE (PATTERN (prev)) == SEQUENCE)
3935 rtx sequence = PATTERN (prev);
3936 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = next;
3939 else if (get_insns () == insn)
3941 if (next)
3942 PREV_INSN (next) = NULL;
3943 set_first_insn (next);
3945 else
3947 struct sequence_stack *stack = seq_stack;
3948 /* Scan all pending sequences too. */
3949 for (; stack; stack = stack->next)
3950 if (insn == stack->first)
3952 stack->first = next;
3953 break;
3956 gcc_assert (stack);
3959 if (next)
3961 PREV_INSN (next) = prev;
3962 if (NONJUMP_INSN_P (next) && GET_CODE (PATTERN (next)) == SEQUENCE)
3963 PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = prev;
3965 else if (get_last_insn () == insn)
3966 set_last_insn (prev);
3967 else
3969 struct sequence_stack *stack = seq_stack;
3970 /* Scan all pending sequences too. */
3971 for (; stack; stack = stack->next)
3972 if (insn == stack->last)
3974 stack->last = prev;
3975 break;
3978 gcc_assert (stack);
3981 /* Fix up basic block boundaries, if necessary. */
3982 if (!BARRIER_P (insn)
3983 && (bb = BLOCK_FOR_INSN (insn)))
3985 if (BB_HEAD (bb) == insn)
3987 /* Never ever delete the basic block note without deleting whole
3988 basic block. */
3989 gcc_assert (!NOTE_P (insn));
3990 BB_HEAD (bb) = next;
3992 if (BB_END (bb) == insn)
3993 BB_END (bb) = prev;
3997 /* Append CALL_FUSAGE to the CALL_INSN_FUNCTION_USAGE for CALL_INSN. */
3999 void
4000 add_function_usage_to (rtx call_insn, rtx call_fusage)
4002 gcc_assert (call_insn && CALL_P (call_insn));
4004 /* Put the register usage information on the CALL. If there is already
4005 some usage information, put ours at the end. */
4006 if (CALL_INSN_FUNCTION_USAGE (call_insn))
4008 rtx link;
4010 for (link = CALL_INSN_FUNCTION_USAGE (call_insn); XEXP (link, 1) != 0;
4011 link = XEXP (link, 1))
4014 XEXP (link, 1) = call_fusage;
4016 else
4017 CALL_INSN_FUNCTION_USAGE (call_insn) = call_fusage;
4020 /* Delete all insns made since FROM.
4021 FROM becomes the new last instruction. */
4023 void
4024 delete_insns_since (rtx from)
4026 if (from == 0)
4027 set_first_insn (0);
4028 else
4029 NEXT_INSN (from) = 0;
4030 set_last_insn (from);
4033 /* This function is deprecated, please use sequences instead.
4035 Move a consecutive bunch of insns to a different place in the chain.
4036 The insns to be moved are those between FROM and TO.
4037 They are moved to a new position after the insn AFTER.
4038 AFTER must not be FROM or TO or any insn in between.
4040 This function does not know about SEQUENCEs and hence should not be
4041 called after delay-slot filling has been done. */
4043 void
4044 reorder_insns_nobb (rtx from, rtx to, rtx after)
4046 #ifdef ENABLE_CHECKING
4047 rtx x;
4048 for (x = from; x != to; x = NEXT_INSN (x))
4049 gcc_assert (after != x);
4050 gcc_assert (after != to);
4051 #endif
4053 /* Splice this bunch out of where it is now. */
4054 if (PREV_INSN (from))
4055 NEXT_INSN (PREV_INSN (from)) = NEXT_INSN (to);
4056 if (NEXT_INSN (to))
4057 PREV_INSN (NEXT_INSN (to)) = PREV_INSN (from);
4058 if (get_last_insn () == to)
4059 set_last_insn (PREV_INSN (from));
4060 if (get_insns () == from)
4061 set_first_insn (NEXT_INSN (to));
4063 /* Make the new neighbors point to it and it to them. */
4064 if (NEXT_INSN (after))
4065 PREV_INSN (NEXT_INSN (after)) = to;
4067 NEXT_INSN (to) = NEXT_INSN (after);
4068 PREV_INSN (from) = after;
4069 NEXT_INSN (after) = from;
4070 if (after == get_last_insn ())
4071 set_last_insn (to);
4074 /* Same as function above, but take care to update BB boundaries. */
4075 void
4076 reorder_insns (rtx from, rtx to, rtx after)
4078 rtx prev = PREV_INSN (from);
4079 basic_block bb, bb2;
4081 reorder_insns_nobb (from, to, after);
4083 if (!BARRIER_P (after)
4084 && (bb = BLOCK_FOR_INSN (after)))
4086 rtx x;
4087 df_set_bb_dirty (bb);
4089 if (!BARRIER_P (from)
4090 && (bb2 = BLOCK_FOR_INSN (from)))
4092 if (BB_END (bb2) == to)
4093 BB_END (bb2) = prev;
4094 df_set_bb_dirty (bb2);
4097 if (BB_END (bb) == after)
4098 BB_END (bb) = to;
4100 for (x = from; x != NEXT_INSN (to); x = NEXT_INSN (x))
4101 if (!BARRIER_P (x))
4102 df_insn_change_bb (x, bb);
4107 /* Emit insn(s) of given code and pattern
4108 at a specified place within the doubly-linked list.
4110 All of the emit_foo global entry points accept an object
4111 X which is either an insn list or a PATTERN of a single
4112 instruction.
4114 There are thus a few canonical ways to generate code and
4115 emit it at a specific place in the instruction stream. For
4116 example, consider the instruction named SPOT and the fact that
4117 we would like to emit some instructions before SPOT. We might
4118 do it like this:
4120 start_sequence ();
4121 ... emit the new instructions ...
4122 insns_head = get_insns ();
4123 end_sequence ();
4125 emit_insn_before (insns_head, SPOT);
4127 It used to be common to generate SEQUENCE rtl instead, but that
4128 is a relic of the past which no longer occurs. The reason is that
4129 SEQUENCE rtl results in much fragmented RTL memory since the SEQUENCE
4130 generated would almost certainly die right after it was created. */
4132 static rtx
4133 emit_pattern_before_noloc (rtx x, rtx before, rtx last, basic_block bb,
4134 rtx (*make_raw) (rtx))
4136 rtx insn;
4138 gcc_assert (before);
4140 if (x == NULL_RTX)
4141 return last;
4143 switch (GET_CODE (x))
4145 case DEBUG_INSN:
4146 case INSN:
4147 case JUMP_INSN:
4148 case CALL_INSN:
4149 case CODE_LABEL:
4150 case BARRIER:
4151 case NOTE:
4152 insn = x;
4153 while (insn)
4155 rtx next = NEXT_INSN (insn);
4156 add_insn_before (insn, before, bb);
4157 last = insn;
4158 insn = next;
4160 break;
4162 #ifdef ENABLE_RTL_CHECKING
4163 case SEQUENCE:
4164 gcc_unreachable ();
4165 break;
4166 #endif
4168 default:
4169 last = (*make_raw) (x);
4170 add_insn_before (last, before, bb);
4171 break;
4174 return last;
4177 /* Make X be output before the instruction BEFORE. */
4180 emit_insn_before_noloc (rtx x, rtx before, basic_block bb)
4182 return emit_pattern_before_noloc (x, before, before, bb, make_insn_raw);
4185 /* Make an instruction with body X and code JUMP_INSN
4186 and output it before the instruction BEFORE. */
4189 emit_jump_insn_before_noloc (rtx x, rtx before)
4191 return emit_pattern_before_noloc (x, before, NULL_RTX, NULL,
4192 make_jump_insn_raw);
4195 /* Make an instruction with body X and code CALL_INSN
4196 and output it before the instruction BEFORE. */
4199 emit_call_insn_before_noloc (rtx x, rtx before)
4201 return emit_pattern_before_noloc (x, before, NULL_RTX, NULL,
4202 make_call_insn_raw);
4205 /* Make an instruction with body X and code DEBUG_INSN
4206 and output it before the instruction BEFORE. */
4209 emit_debug_insn_before_noloc (rtx x, rtx before)
4211 return emit_pattern_before_noloc (x, before, NULL_RTX, NULL,
4212 make_debug_insn_raw);
4215 /* Make an insn of code BARRIER
4216 and output it before the insn BEFORE. */
4219 emit_barrier_before (rtx before)
4221 rtx insn = rtx_alloc (BARRIER);
4223 INSN_UID (insn) = cur_insn_uid++;
4225 add_insn_before (insn, before, NULL);
4226 return insn;
4229 /* Emit the label LABEL before the insn BEFORE. */
4232 emit_label_before (rtx label, rtx before)
4234 gcc_checking_assert (INSN_UID (label) == 0);
4235 INSN_UID (label) = cur_insn_uid++;
4236 add_insn_before (label, before, NULL);
4237 return label;
4240 /* Helper for emit_insn_after, handles lists of instructions
4241 efficiently. */
4243 static rtx
4244 emit_insn_after_1 (rtx first, rtx after, basic_block bb)
4246 rtx last;
4247 rtx after_after;
4248 if (!bb && !BARRIER_P (after))
4249 bb = BLOCK_FOR_INSN (after);
4251 if (bb)
4253 df_set_bb_dirty (bb);
4254 for (last = first; NEXT_INSN (last); last = NEXT_INSN (last))
4255 if (!BARRIER_P (last))
4257 set_block_for_insn (last, bb);
4258 df_insn_rescan (last);
4260 if (!BARRIER_P (last))
4262 set_block_for_insn (last, bb);
4263 df_insn_rescan (last);
4265 if (BB_END (bb) == after)
4266 BB_END (bb) = last;
4268 else
4269 for (last = first; NEXT_INSN (last); last = NEXT_INSN (last))
4270 continue;
4272 after_after = NEXT_INSN (after);
4274 NEXT_INSN (after) = first;
4275 PREV_INSN (first) = after;
4276 NEXT_INSN (last) = after_after;
4277 if (after_after)
4278 PREV_INSN (after_after) = last;
4280 if (after == get_last_insn ())
4281 set_last_insn (last);
4283 return last;
4286 static rtx
4287 emit_pattern_after_noloc (rtx x, rtx after, basic_block bb,
4288 rtx (*make_raw)(rtx))
4290 rtx last = after;
4292 gcc_assert (after);
4294 if (x == NULL_RTX)
4295 return last;
4297 switch (GET_CODE (x))
4299 case DEBUG_INSN:
4300 case INSN:
4301 case JUMP_INSN:
4302 case CALL_INSN:
4303 case CODE_LABEL:
4304 case BARRIER:
4305 case NOTE:
4306 last = emit_insn_after_1 (x, after, bb);
4307 break;
4309 #ifdef ENABLE_RTL_CHECKING
4310 case SEQUENCE:
4311 gcc_unreachable ();
4312 break;
4313 #endif
4315 default:
4316 last = (*make_raw) (x);
4317 add_insn_after (last, after, bb);
4318 break;
4321 return last;
4324 /* Make X be output after the insn AFTER and set the BB of insn. If
4325 BB is NULL, an attempt is made to infer the BB from AFTER. */
4328 emit_insn_after_noloc (rtx x, rtx after, basic_block bb)
4330 return emit_pattern_after_noloc (x, after, bb, make_insn_raw);
4334 /* Make an insn of code JUMP_INSN with body X
4335 and output it after the insn AFTER. */
4338 emit_jump_insn_after_noloc (rtx x, rtx after)
4340 return emit_pattern_after_noloc (x, after, NULL, make_jump_insn_raw);
4343 /* Make an instruction with body X and code CALL_INSN
4344 and output it after the instruction AFTER. */
4347 emit_call_insn_after_noloc (rtx x, rtx after)
4349 return emit_pattern_after_noloc (x, after, NULL, make_call_insn_raw);
4352 /* Make an instruction with body X and code CALL_INSN
4353 and output it after the instruction AFTER. */
4356 emit_debug_insn_after_noloc (rtx x, rtx after)
4358 return emit_pattern_after_noloc (x, after, NULL, make_debug_insn_raw);
4361 /* Make an insn of code BARRIER
4362 and output it after the insn AFTER. */
4365 emit_barrier_after (rtx after)
4367 rtx insn = rtx_alloc (BARRIER);
4369 INSN_UID (insn) = cur_insn_uid++;
4371 add_insn_after (insn, after, NULL);
4372 return insn;
4375 /* Emit the label LABEL after the insn AFTER. */
4378 emit_label_after (rtx label, rtx after)
4380 gcc_checking_assert (INSN_UID (label) == 0);
4381 INSN_UID (label) = cur_insn_uid++;
4382 add_insn_after (label, after, NULL);
4383 return label;
4386 /* Notes require a bit of special handling: Some notes need to have their
4387 BLOCK_FOR_INSN set, others should never have it set, and some should
4388 have it set or clear depending on the context. */
4390 /* Return true iff a note of kind SUBTYPE should be emitted with routines
4391 that never set BLOCK_FOR_INSN on NOTE. BB_BOUNDARY is true if the
4392 caller is asked to emit a note before BB_HEAD, or after BB_END. */
4394 static bool
4395 note_outside_basic_block_p (enum insn_note subtype, bool on_bb_boundary_p)
4397 switch (subtype)
4399 /* NOTE_INSN_SWITCH_TEXT_SECTIONS only appears between basic blocks. */
4400 case NOTE_INSN_SWITCH_TEXT_SECTIONS:
4401 return true;
4403 /* Notes for var tracking and EH region markers can appear between or
4404 inside basic blocks. If the caller is emitting on the basic block
4405 boundary, do not set BLOCK_FOR_INSN on the new note. */
4406 case NOTE_INSN_VAR_LOCATION:
4407 case NOTE_INSN_CALL_ARG_LOCATION:
4408 case NOTE_INSN_EH_REGION_BEG:
4409 case NOTE_INSN_EH_REGION_END:
4410 return on_bb_boundary_p;
4412 /* Otherwise, BLOCK_FOR_INSN must be set. */
4413 default:
4414 return false;
4418 /* Emit a note of subtype SUBTYPE after the insn AFTER. */
4421 emit_note_after (enum insn_note subtype, rtx after)
4423 rtx note = make_note_raw (subtype);
4424 basic_block bb = BARRIER_P (after) ? NULL : BLOCK_FOR_INSN (after);
4425 bool on_bb_boundary_p = (bb != NULL && BB_END (bb) == after);
4427 if (note_outside_basic_block_p (subtype, on_bb_boundary_p))
4428 add_insn_after_nobb (note, after);
4429 else
4430 add_insn_after (note, after, bb);
4431 return note;
4434 /* Emit a note of subtype SUBTYPE before the insn BEFORE. */
4437 emit_note_before (enum insn_note subtype, rtx before)
4439 rtx note = make_note_raw (subtype);
4440 basic_block bb = BARRIER_P (before) ? NULL : BLOCK_FOR_INSN (before);
4441 bool on_bb_boundary_p = (bb != NULL && BB_HEAD (bb) == before);
4443 if (note_outside_basic_block_p (subtype, on_bb_boundary_p))
4444 add_insn_before_nobb (note, before);
4445 else
4446 add_insn_before (note, before, bb);
4447 return note;
4450 /* Insert PATTERN after AFTER, setting its INSN_LOCATION to LOC.
4451 MAKE_RAW indicates how to turn PATTERN into a real insn. */
4453 static rtx
4454 emit_pattern_after_setloc (rtx pattern, rtx after, int loc,
4455 rtx (*make_raw) (rtx))
4457 rtx last = emit_pattern_after_noloc (pattern, after, NULL, make_raw);
4459 if (pattern == NULL_RTX || !loc)
4460 return last;
4462 after = NEXT_INSN (after);
4463 while (1)
4465 if (active_insn_p (after) && !INSN_LOCATION (after))
4466 INSN_LOCATION (after) = loc;
4467 if (after == last)
4468 break;
4469 after = NEXT_INSN (after);
4471 return last;
4474 /* Insert PATTERN after AFTER. MAKE_RAW indicates how to turn PATTERN
4475 into a real insn. SKIP_DEBUG_INSNS indicates whether to insert after
4476 any DEBUG_INSNs. */
4478 static rtx
4479 emit_pattern_after (rtx pattern, rtx after, bool skip_debug_insns,
4480 rtx (*make_raw) (rtx))
4482 rtx prev = after;
4484 if (skip_debug_insns)
4485 while (DEBUG_INSN_P (prev))
4486 prev = PREV_INSN (prev);
4488 if (INSN_P (prev))
4489 return emit_pattern_after_setloc (pattern, after, INSN_LOCATION (prev),
4490 make_raw);
4491 else
4492 return emit_pattern_after_noloc (pattern, after, NULL, make_raw);
4495 /* Like emit_insn_after_noloc, but set INSN_LOCATION according to LOC. */
4497 emit_insn_after_setloc (rtx pattern, rtx after, int loc)
4499 return emit_pattern_after_setloc (pattern, after, loc, make_insn_raw);
4502 /* Like emit_insn_after_noloc, but set INSN_LOCATION according to AFTER. */
4504 emit_insn_after (rtx pattern, rtx after)
4506 return emit_pattern_after (pattern, after, true, make_insn_raw);
4509 /* Like emit_jump_insn_after_noloc, but set INSN_LOCATION according to LOC. */
4511 emit_jump_insn_after_setloc (rtx pattern, rtx after, int loc)
4513 return emit_pattern_after_setloc (pattern, after, loc, make_jump_insn_raw);
4516 /* Like emit_jump_insn_after_noloc, but set INSN_LOCATION according to AFTER. */
4518 emit_jump_insn_after (rtx pattern, rtx after)
4520 return emit_pattern_after (pattern, after, true, make_jump_insn_raw);
4523 /* Like emit_call_insn_after_noloc, but set INSN_LOCATION according to LOC. */
4525 emit_call_insn_after_setloc (rtx pattern, rtx after, int loc)
4527 return emit_pattern_after_setloc (pattern, after, loc, make_call_insn_raw);
4530 /* Like emit_call_insn_after_noloc, but set INSN_LOCATION according to AFTER. */
4532 emit_call_insn_after (rtx pattern, rtx after)
4534 return emit_pattern_after (pattern, after, true, make_call_insn_raw);
4537 /* Like emit_debug_insn_after_noloc, but set INSN_LOCATION according to LOC. */
4539 emit_debug_insn_after_setloc (rtx pattern, rtx after, int loc)
4541 return emit_pattern_after_setloc (pattern, after, loc, make_debug_insn_raw);
4544 /* Like emit_debug_insn_after_noloc, but set INSN_LOCATION according to AFTER. */
4546 emit_debug_insn_after (rtx pattern, rtx after)
4548 return emit_pattern_after (pattern, after, false, make_debug_insn_raw);
4551 /* Insert PATTERN before BEFORE, setting its INSN_LOCATION to LOC.
4552 MAKE_RAW indicates how to turn PATTERN into a real insn. INSNP
4553 indicates if PATTERN is meant for an INSN as opposed to a JUMP_INSN,
4554 CALL_INSN, etc. */
4556 static rtx
4557 emit_pattern_before_setloc (rtx pattern, rtx before, int loc, bool insnp,
4558 rtx (*make_raw) (rtx))
4560 rtx first = PREV_INSN (before);
4561 rtx last = emit_pattern_before_noloc (pattern, before,
4562 insnp ? before : NULL_RTX,
4563 NULL, make_raw);
4565 if (pattern == NULL_RTX || !loc)
4566 return last;
4568 if (!first)
4569 first = get_insns ();
4570 else
4571 first = NEXT_INSN (first);
4572 while (1)
4574 if (active_insn_p (first) && !INSN_LOCATION (first))
4575 INSN_LOCATION (first) = loc;
4576 if (first == last)
4577 break;
4578 first = NEXT_INSN (first);
4580 return last;
4583 /* Insert PATTERN before BEFORE. MAKE_RAW indicates how to turn PATTERN
4584 into a real insn. SKIP_DEBUG_INSNS indicates whether to insert
4585 before any DEBUG_INSNs. INSNP indicates if PATTERN is meant for an
4586 INSN as opposed to a JUMP_INSN, CALL_INSN, etc. */
4588 static rtx
4589 emit_pattern_before (rtx pattern, rtx before, bool skip_debug_insns,
4590 bool insnp, rtx (*make_raw) (rtx))
4592 rtx next = before;
4594 if (skip_debug_insns)
4595 while (DEBUG_INSN_P (next))
4596 next = PREV_INSN (next);
4598 if (INSN_P (next))
4599 return emit_pattern_before_setloc (pattern, before, INSN_LOCATION (next),
4600 insnp, make_raw);
4601 else
4602 return emit_pattern_before_noloc (pattern, before,
4603 insnp ? before : NULL_RTX,
4604 NULL, make_raw);
4607 /* Like emit_insn_before_noloc, but set INSN_LOCATION according to LOC. */
4609 emit_insn_before_setloc (rtx pattern, rtx before, int loc)
4611 return emit_pattern_before_setloc (pattern, before, loc, true,
4612 make_insn_raw);
4615 /* Like emit_insn_before_noloc, but set INSN_LOCATION according to BEFORE. */
4617 emit_insn_before (rtx pattern, rtx before)
4619 return emit_pattern_before (pattern, before, true, true, make_insn_raw);
4622 /* like emit_insn_before_noloc, but set INSN_LOCATION according to LOC. */
4624 emit_jump_insn_before_setloc (rtx pattern, rtx before, int loc)
4626 return emit_pattern_before_setloc (pattern, before, loc, false,
4627 make_jump_insn_raw);
4630 /* Like emit_jump_insn_before_noloc, but set INSN_LOCATION according to BEFORE. */
4632 emit_jump_insn_before (rtx pattern, rtx before)
4634 return emit_pattern_before (pattern, before, true, false,
4635 make_jump_insn_raw);
4638 /* Like emit_insn_before_noloc, but set INSN_LOCATION according to LOC. */
4640 emit_call_insn_before_setloc (rtx pattern, rtx before, int loc)
4642 return emit_pattern_before_setloc (pattern, before, loc, false,
4643 make_call_insn_raw);
4646 /* Like emit_call_insn_before_noloc,
4647 but set insn_location according to BEFORE. */
4649 emit_call_insn_before (rtx pattern, rtx before)
4651 return emit_pattern_before (pattern, before, true, false,
4652 make_call_insn_raw);
4655 /* Like emit_insn_before_noloc, but set INSN_LOCATION according to LOC. */
4657 emit_debug_insn_before_setloc (rtx pattern, rtx before, int loc)
4659 return emit_pattern_before_setloc (pattern, before, loc, false,
4660 make_debug_insn_raw);
4663 /* Like emit_debug_insn_before_noloc,
4664 but set insn_location according to BEFORE. */
4666 emit_debug_insn_before (rtx pattern, rtx before)
4668 return emit_pattern_before (pattern, before, false, false,
4669 make_debug_insn_raw);
4672 /* Take X and emit it at the end of the doubly-linked
4673 INSN list.
4675 Returns the last insn emitted. */
4678 emit_insn (rtx x)
4680 rtx last = get_last_insn ();
4681 rtx insn;
4683 if (x == NULL_RTX)
4684 return last;
4686 switch (GET_CODE (x))
4688 case DEBUG_INSN:
4689 case INSN:
4690 case JUMP_INSN:
4691 case CALL_INSN:
4692 case CODE_LABEL:
4693 case BARRIER:
4694 case NOTE:
4695 insn = x;
4696 while (insn)
4698 rtx next = NEXT_INSN (insn);
4699 add_insn (insn);
4700 last = insn;
4701 insn = next;
4703 break;
4705 #ifdef ENABLE_RTL_CHECKING
4706 case JUMP_TABLE_DATA:
4707 case SEQUENCE:
4708 gcc_unreachable ();
4709 break;
4710 #endif
4712 default:
4713 last = make_insn_raw (x);
4714 add_insn (last);
4715 break;
4718 return last;
4721 /* Make an insn of code DEBUG_INSN with pattern X
4722 and add it to the end of the doubly-linked list. */
4725 emit_debug_insn (rtx x)
4727 rtx last = get_last_insn ();
4728 rtx insn;
4730 if (x == NULL_RTX)
4731 return last;
4733 switch (GET_CODE (x))
4735 case DEBUG_INSN:
4736 case INSN:
4737 case JUMP_INSN:
4738 case CALL_INSN:
4739 case CODE_LABEL:
4740 case BARRIER:
4741 case NOTE:
4742 insn = x;
4743 while (insn)
4745 rtx next = NEXT_INSN (insn);
4746 add_insn (insn);
4747 last = insn;
4748 insn = next;
4750 break;
4752 #ifdef ENABLE_RTL_CHECKING
4753 case JUMP_TABLE_DATA:
4754 case SEQUENCE:
4755 gcc_unreachable ();
4756 break;
4757 #endif
4759 default:
4760 last = make_debug_insn_raw (x);
4761 add_insn (last);
4762 break;
4765 return last;
4768 /* Make an insn of code JUMP_INSN with pattern X
4769 and add it to the end of the doubly-linked list. */
4772 emit_jump_insn (rtx x)
4774 rtx last = NULL_RTX, insn;
4776 switch (GET_CODE (x))
4778 case DEBUG_INSN:
4779 case INSN:
4780 case JUMP_INSN:
4781 case CALL_INSN:
4782 case CODE_LABEL:
4783 case BARRIER:
4784 case NOTE:
4785 insn = x;
4786 while (insn)
4788 rtx next = NEXT_INSN (insn);
4789 add_insn (insn);
4790 last = insn;
4791 insn = next;
4793 break;
4795 #ifdef ENABLE_RTL_CHECKING
4796 case JUMP_TABLE_DATA:
4797 case SEQUENCE:
4798 gcc_unreachable ();
4799 break;
4800 #endif
4802 default:
4803 last = make_jump_insn_raw (x);
4804 add_insn (last);
4805 break;
4808 return last;
4811 /* Make an insn of code CALL_INSN with pattern X
4812 and add it to the end of the doubly-linked list. */
4815 emit_call_insn (rtx x)
4817 rtx insn;
4819 switch (GET_CODE (x))
4821 case DEBUG_INSN:
4822 case INSN:
4823 case JUMP_INSN:
4824 case CALL_INSN:
4825 case CODE_LABEL:
4826 case BARRIER:
4827 case NOTE:
4828 insn = emit_insn (x);
4829 break;
4831 #ifdef ENABLE_RTL_CHECKING
4832 case SEQUENCE:
4833 case JUMP_TABLE_DATA:
4834 gcc_unreachable ();
4835 break;
4836 #endif
4838 default:
4839 insn = make_call_insn_raw (x);
4840 add_insn (insn);
4841 break;
4844 return insn;
4847 /* Add the label LABEL to the end of the doubly-linked list. */
4850 emit_label (rtx label)
4852 gcc_checking_assert (INSN_UID (label) == 0);
4853 INSN_UID (label) = cur_insn_uid++;
4854 add_insn (label);
4855 return label;
4858 /* Make an insn of code JUMP_TABLE_DATA
4859 and add it to the end of the doubly-linked list. */
4862 emit_jump_table_data (rtx table)
4864 rtx jump_table_data = rtx_alloc (JUMP_TABLE_DATA);
4865 INSN_UID (jump_table_data) = cur_insn_uid++;
4866 PATTERN (jump_table_data) = table;
4867 BLOCK_FOR_INSN (jump_table_data) = NULL;
4868 add_insn (jump_table_data);
4869 return jump_table_data;
4872 /* Make an insn of code BARRIER
4873 and add it to the end of the doubly-linked list. */
4876 emit_barrier (void)
4878 rtx barrier = rtx_alloc (BARRIER);
4879 INSN_UID (barrier) = cur_insn_uid++;
4880 add_insn (barrier);
4881 return barrier;
4884 /* Emit a copy of note ORIG. */
4887 emit_note_copy (rtx orig)
4889 enum insn_note kind = (enum insn_note) NOTE_KIND (orig);
4890 rtx note = make_note_raw (kind);
4891 NOTE_DATA (note) = NOTE_DATA (orig);
4892 add_insn (note);
4893 return note;
4896 /* Make an insn of code NOTE or type NOTE_NO
4897 and add it to the end of the doubly-linked list. */
4900 emit_note (enum insn_note kind)
4902 rtx note = make_note_raw (kind);
4903 add_insn (note);
4904 return note;
4907 /* Emit a clobber of lvalue X. */
4910 emit_clobber (rtx x)
4912 /* CONCATs should not appear in the insn stream. */
4913 if (GET_CODE (x) == CONCAT)
4915 emit_clobber (XEXP (x, 0));
4916 return emit_clobber (XEXP (x, 1));
4918 return emit_insn (gen_rtx_CLOBBER (VOIDmode, x));
4921 /* Return a sequence of insns to clobber lvalue X. */
4924 gen_clobber (rtx x)
4926 rtx seq;
4928 start_sequence ();
4929 emit_clobber (x);
4930 seq = get_insns ();
4931 end_sequence ();
4932 return seq;
4935 /* Emit a use of rvalue X. */
4938 emit_use (rtx x)
4940 /* CONCATs should not appear in the insn stream. */
4941 if (GET_CODE (x) == CONCAT)
4943 emit_use (XEXP (x, 0));
4944 return emit_use (XEXP (x, 1));
4946 return emit_insn (gen_rtx_USE (VOIDmode, x));
4949 /* Return a sequence of insns to use rvalue X. */
4952 gen_use (rtx x)
4954 rtx seq;
4956 start_sequence ();
4957 emit_use (x);
4958 seq = get_insns ();
4959 end_sequence ();
4960 return seq;
4963 /* Place a note of KIND on insn INSN with DATUM as the datum. If a
4964 note of this type already exists, remove it first. */
4967 set_unique_reg_note (rtx insn, enum reg_note kind, rtx datum)
4969 rtx note = find_reg_note (insn, kind, NULL_RTX);
4971 switch (kind)
4973 case REG_EQUAL:
4974 case REG_EQUIV:
4975 /* Don't add REG_EQUAL/REG_EQUIV notes if the insn
4976 has multiple sets (some callers assume single_set
4977 means the insn only has one set, when in fact it
4978 means the insn only has one * useful * set). */
4979 if (GET_CODE (PATTERN (insn)) == PARALLEL && multiple_sets (insn))
4981 gcc_assert (!note);
4982 return NULL_RTX;
4985 /* Don't add ASM_OPERAND REG_EQUAL/REG_EQUIV notes.
4986 It serves no useful purpose and breaks eliminate_regs. */
4987 if (GET_CODE (datum) == ASM_OPERANDS)
4988 return NULL_RTX;
4990 if (note)
4992 XEXP (note, 0) = datum;
4993 df_notes_rescan (insn);
4994 return note;
4996 break;
4998 default:
4999 if (note)
5001 XEXP (note, 0) = datum;
5002 return note;
5004 break;
5007 add_reg_note (insn, kind, datum);
5009 switch (kind)
5011 case REG_EQUAL:
5012 case REG_EQUIV:
5013 df_notes_rescan (insn);
5014 break;
5015 default:
5016 break;
5019 return REG_NOTES (insn);
5022 /* Like set_unique_reg_note, but don't do anything unless INSN sets DST. */
5024 set_dst_reg_note (rtx insn, enum reg_note kind, rtx datum, rtx dst)
5026 rtx set = single_set (insn);
5028 if (set && SET_DEST (set) == dst)
5029 return set_unique_reg_note (insn, kind, datum);
5030 return NULL_RTX;
5033 /* Return an indication of which type of insn should have X as a body.
5034 The value is CODE_LABEL, INSN, CALL_INSN or JUMP_INSN. */
5036 static enum rtx_code
5037 classify_insn (rtx x)
5039 if (LABEL_P (x))
5040 return CODE_LABEL;
5041 if (GET_CODE (x) == CALL)
5042 return CALL_INSN;
5043 if (ANY_RETURN_P (x))
5044 return JUMP_INSN;
5045 if (GET_CODE (x) == SET)
5047 if (SET_DEST (x) == pc_rtx)
5048 return JUMP_INSN;
5049 else if (GET_CODE (SET_SRC (x)) == CALL)
5050 return CALL_INSN;
5051 else
5052 return INSN;
5054 if (GET_CODE (x) == PARALLEL)
5056 int j;
5057 for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
5058 if (GET_CODE (XVECEXP (x, 0, j)) == CALL)
5059 return CALL_INSN;
5060 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
5061 && SET_DEST (XVECEXP (x, 0, j)) == pc_rtx)
5062 return JUMP_INSN;
5063 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
5064 && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == CALL)
5065 return CALL_INSN;
5067 return INSN;
5070 /* Emit the rtl pattern X as an appropriate kind of insn.
5071 If X is a label, it is simply added into the insn chain. */
5074 emit (rtx x)
5076 enum rtx_code code = classify_insn (x);
5078 switch (code)
5080 case CODE_LABEL:
5081 return emit_label (x);
5082 case INSN:
5083 return emit_insn (x);
5084 case JUMP_INSN:
5086 rtx insn = emit_jump_insn (x);
5087 if (any_uncondjump_p (insn) || GET_CODE (x) == RETURN)
5088 return emit_barrier ();
5089 return insn;
5091 case CALL_INSN:
5092 return emit_call_insn (x);
5093 case DEBUG_INSN:
5094 return emit_debug_insn (x);
5095 default:
5096 gcc_unreachable ();
5100 /* Space for free sequence stack entries. */
5101 static GTY ((deletable)) struct sequence_stack *free_sequence_stack;
5103 /* Begin emitting insns to a sequence. If this sequence will contain
5104 something that might cause the compiler to pop arguments to function
5105 calls (because those pops have previously been deferred; see
5106 INHIBIT_DEFER_POP for more details), use do_pending_stack_adjust
5107 before calling this function. That will ensure that the deferred
5108 pops are not accidentally emitted in the middle of this sequence. */
5110 void
5111 start_sequence (void)
5113 struct sequence_stack *tem;
5115 if (free_sequence_stack != NULL)
5117 tem = free_sequence_stack;
5118 free_sequence_stack = tem->next;
5120 else
5121 tem = ggc_alloc_sequence_stack ();
5123 tem->next = seq_stack;
5124 tem->first = get_insns ();
5125 tem->last = get_last_insn ();
5127 seq_stack = tem;
5129 set_first_insn (0);
5130 set_last_insn (0);
5133 /* Set up the insn chain starting with FIRST as the current sequence,
5134 saving the previously current one. See the documentation for
5135 start_sequence for more information about how to use this function. */
5137 void
5138 push_to_sequence (rtx first)
5140 rtx last;
5142 start_sequence ();
5144 for (last = first; last && NEXT_INSN (last); last = NEXT_INSN (last))
5147 set_first_insn (first);
5148 set_last_insn (last);
5151 /* Like push_to_sequence, but take the last insn as an argument to avoid
5152 looping through the list. */
5154 void
5155 push_to_sequence2 (rtx first, rtx last)
5157 start_sequence ();
5159 set_first_insn (first);
5160 set_last_insn (last);
5163 /* Set up the outer-level insn chain
5164 as the current sequence, saving the previously current one. */
5166 void
5167 push_topmost_sequence (void)
5169 struct sequence_stack *stack, *top = NULL;
5171 start_sequence ();
5173 for (stack = seq_stack; stack; stack = stack->next)
5174 top = stack;
5176 set_first_insn (top->first);
5177 set_last_insn (top->last);
5180 /* After emitting to the outer-level insn chain, update the outer-level
5181 insn chain, and restore the previous saved state. */
5183 void
5184 pop_topmost_sequence (void)
5186 struct sequence_stack *stack, *top = NULL;
5188 for (stack = seq_stack; stack; stack = stack->next)
5189 top = stack;
5191 top->first = get_insns ();
5192 top->last = get_last_insn ();
5194 end_sequence ();
5197 /* After emitting to a sequence, restore previous saved state.
5199 To get the contents of the sequence just made, you must call
5200 `get_insns' *before* calling here.
5202 If the compiler might have deferred popping arguments while
5203 generating this sequence, and this sequence will not be immediately
5204 inserted into the instruction stream, use do_pending_stack_adjust
5205 before calling get_insns. That will ensure that the deferred
5206 pops are inserted into this sequence, and not into some random
5207 location in the instruction stream. See INHIBIT_DEFER_POP for more
5208 information about deferred popping of arguments. */
5210 void
5211 end_sequence (void)
5213 struct sequence_stack *tem = seq_stack;
5215 set_first_insn (tem->first);
5216 set_last_insn (tem->last);
5217 seq_stack = tem->next;
5219 memset (tem, 0, sizeof (*tem));
5220 tem->next = free_sequence_stack;
5221 free_sequence_stack = tem;
5224 /* Return 1 if currently emitting into a sequence. */
5227 in_sequence_p (void)
5229 return seq_stack != 0;
5232 /* Put the various virtual registers into REGNO_REG_RTX. */
5234 static void
5235 init_virtual_regs (void)
5237 regno_reg_rtx[VIRTUAL_INCOMING_ARGS_REGNUM] = virtual_incoming_args_rtx;
5238 regno_reg_rtx[VIRTUAL_STACK_VARS_REGNUM] = virtual_stack_vars_rtx;
5239 regno_reg_rtx[VIRTUAL_STACK_DYNAMIC_REGNUM] = virtual_stack_dynamic_rtx;
5240 regno_reg_rtx[VIRTUAL_OUTGOING_ARGS_REGNUM] = virtual_outgoing_args_rtx;
5241 regno_reg_rtx[VIRTUAL_CFA_REGNUM] = virtual_cfa_rtx;
5242 regno_reg_rtx[VIRTUAL_PREFERRED_STACK_BOUNDARY_REGNUM]
5243 = virtual_preferred_stack_boundary_rtx;
5247 /* Used by copy_insn_1 to avoid copying SCRATCHes more than once. */
5248 static rtx copy_insn_scratch_in[MAX_RECOG_OPERANDS];
5249 static rtx copy_insn_scratch_out[MAX_RECOG_OPERANDS];
5250 static int copy_insn_n_scratches;
5252 /* When an insn is being copied by copy_insn_1, this is nonzero if we have
5253 copied an ASM_OPERANDS.
5254 In that case, it is the original input-operand vector. */
5255 static rtvec orig_asm_operands_vector;
5257 /* When an insn is being copied by copy_insn_1, this is nonzero if we have
5258 copied an ASM_OPERANDS.
5259 In that case, it is the copied input-operand vector. */
5260 static rtvec copy_asm_operands_vector;
5262 /* Likewise for the constraints vector. */
5263 static rtvec orig_asm_constraints_vector;
5264 static rtvec copy_asm_constraints_vector;
5266 /* Recursively create a new copy of an rtx for copy_insn.
5267 This function differs from copy_rtx in that it handles SCRATCHes and
5268 ASM_OPERANDs properly.
5269 Normally, this function is not used directly; use copy_insn as front end.
5270 However, you could first copy an insn pattern with copy_insn and then use
5271 this function afterwards to properly copy any REG_NOTEs containing
5272 SCRATCHes. */
5275 copy_insn_1 (rtx orig)
5277 rtx copy;
5278 int i, j;
5279 RTX_CODE code;
5280 const char *format_ptr;
5282 if (orig == NULL)
5283 return NULL;
5285 code = GET_CODE (orig);
5287 switch (code)
5289 case REG:
5290 case DEBUG_EXPR:
5291 CASE_CONST_ANY:
5292 case SYMBOL_REF:
5293 case CODE_LABEL:
5294 case PC:
5295 case CC0:
5296 case RETURN:
5297 case SIMPLE_RETURN:
5298 return orig;
5299 case CLOBBER:
5300 /* Share clobbers of hard registers (like cc0), but do not share pseudo reg
5301 clobbers or clobbers of hard registers that originated as pseudos.
5302 This is needed to allow safe register renaming. */
5303 if (REG_P (XEXP (orig, 0)) && REGNO (XEXP (orig, 0)) < FIRST_PSEUDO_REGISTER
5304 && ORIGINAL_REGNO (XEXP (orig, 0)) == REGNO (XEXP (orig, 0)))
5305 return orig;
5306 break;
5308 case SCRATCH:
5309 for (i = 0; i < copy_insn_n_scratches; i++)
5310 if (copy_insn_scratch_in[i] == orig)
5311 return copy_insn_scratch_out[i];
5312 break;
5314 case CONST:
5315 if (shared_const_p (orig))
5316 return orig;
5317 break;
5319 /* A MEM with a constant address is not sharable. The problem is that
5320 the constant address may need to be reloaded. If the mem is shared,
5321 then reloading one copy of this mem will cause all copies to appear
5322 to have been reloaded. */
5324 default:
5325 break;
5328 /* Copy the various flags, fields, and other information. We assume
5329 that all fields need copying, and then clear the fields that should
5330 not be copied. That is the sensible default behavior, and forces
5331 us to explicitly document why we are *not* copying a flag. */
5332 copy = shallow_copy_rtx (orig);
5334 /* We do not copy the USED flag, which is used as a mark bit during
5335 walks over the RTL. */
5336 RTX_FLAG (copy, used) = 0;
5338 /* We do not copy JUMP, CALL, or FRAME_RELATED for INSNs. */
5339 if (INSN_P (orig))
5341 RTX_FLAG (copy, jump) = 0;
5342 RTX_FLAG (copy, call) = 0;
5343 RTX_FLAG (copy, frame_related) = 0;
5346 format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
5348 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
5349 switch (*format_ptr++)
5351 case 'e':
5352 if (XEXP (orig, i) != NULL)
5353 XEXP (copy, i) = copy_insn_1 (XEXP (orig, i));
5354 break;
5356 case 'E':
5357 case 'V':
5358 if (XVEC (orig, i) == orig_asm_constraints_vector)
5359 XVEC (copy, i) = copy_asm_constraints_vector;
5360 else if (XVEC (orig, i) == orig_asm_operands_vector)
5361 XVEC (copy, i) = copy_asm_operands_vector;
5362 else if (XVEC (orig, i) != NULL)
5364 XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
5365 for (j = 0; j < XVECLEN (copy, i); j++)
5366 XVECEXP (copy, i, j) = copy_insn_1 (XVECEXP (orig, i, j));
5368 break;
5370 case 't':
5371 case 'w':
5372 case 'i':
5373 case 's':
5374 case 'S':
5375 case 'u':
5376 case '0':
5377 /* These are left unchanged. */
5378 break;
5380 default:
5381 gcc_unreachable ();
5384 if (code == SCRATCH)
5386 i = copy_insn_n_scratches++;
5387 gcc_assert (i < MAX_RECOG_OPERANDS);
5388 copy_insn_scratch_in[i] = orig;
5389 copy_insn_scratch_out[i] = copy;
5391 else if (code == ASM_OPERANDS)
5393 orig_asm_operands_vector = ASM_OPERANDS_INPUT_VEC (orig);
5394 copy_asm_operands_vector = ASM_OPERANDS_INPUT_VEC (copy);
5395 orig_asm_constraints_vector = ASM_OPERANDS_INPUT_CONSTRAINT_VEC (orig);
5396 copy_asm_constraints_vector = ASM_OPERANDS_INPUT_CONSTRAINT_VEC (copy);
5399 return copy;
5402 /* Create a new copy of an rtx.
5403 This function differs from copy_rtx in that it handles SCRATCHes and
5404 ASM_OPERANDs properly.
5405 INSN doesn't really have to be a full INSN; it could be just the
5406 pattern. */
5408 copy_insn (rtx insn)
5410 copy_insn_n_scratches = 0;
5411 orig_asm_operands_vector = 0;
5412 orig_asm_constraints_vector = 0;
5413 copy_asm_operands_vector = 0;
5414 copy_asm_constraints_vector = 0;
5415 return copy_insn_1 (insn);
5418 /* Return a copy of INSN that can be used in a SEQUENCE delay slot,
5419 on that assumption that INSN itself remains in its original place. */
5422 copy_delay_slot_insn (rtx insn)
5424 /* Copy INSN with its rtx_code, all its notes, location etc. */
5425 insn = copy_rtx (insn);
5426 INSN_UID (insn) = cur_insn_uid++;
5427 return insn;
5430 /* Initialize data structures and variables in this file
5431 before generating rtl for each function. */
5433 void
5434 init_emit (void)
5436 set_first_insn (NULL);
5437 set_last_insn (NULL);
5438 if (MIN_NONDEBUG_INSN_UID)
5439 cur_insn_uid = MIN_NONDEBUG_INSN_UID;
5440 else
5441 cur_insn_uid = 1;
5442 cur_debug_insn_uid = 1;
5443 reg_rtx_no = LAST_VIRTUAL_REGISTER + 1;
5444 first_label_num = label_num;
5445 seq_stack = NULL;
5447 /* Init the tables that describe all the pseudo regs. */
5449 crtl->emit.regno_pointer_align_length = LAST_VIRTUAL_REGISTER + 101;
5451 crtl->emit.regno_pointer_align
5452 = XCNEWVEC (unsigned char, crtl->emit.regno_pointer_align_length);
5454 regno_reg_rtx = ggc_alloc_vec_rtx (crtl->emit.regno_pointer_align_length);
5456 /* Put copies of all the hard registers into regno_reg_rtx. */
5457 memcpy (regno_reg_rtx,
5458 initial_regno_reg_rtx,
5459 FIRST_PSEUDO_REGISTER * sizeof (rtx));
5461 /* Put copies of all the virtual register rtx into regno_reg_rtx. */
5462 init_virtual_regs ();
5464 /* Indicate that the virtual registers and stack locations are
5465 all pointers. */
5466 REG_POINTER (stack_pointer_rtx) = 1;
5467 REG_POINTER (frame_pointer_rtx) = 1;
5468 REG_POINTER (hard_frame_pointer_rtx) = 1;
5469 REG_POINTER (arg_pointer_rtx) = 1;
5471 REG_POINTER (virtual_incoming_args_rtx) = 1;
5472 REG_POINTER (virtual_stack_vars_rtx) = 1;
5473 REG_POINTER (virtual_stack_dynamic_rtx) = 1;
5474 REG_POINTER (virtual_outgoing_args_rtx) = 1;
5475 REG_POINTER (virtual_cfa_rtx) = 1;
5477 #ifdef STACK_BOUNDARY
5478 REGNO_POINTER_ALIGN (STACK_POINTER_REGNUM) = STACK_BOUNDARY;
5479 REGNO_POINTER_ALIGN (FRAME_POINTER_REGNUM) = STACK_BOUNDARY;
5480 REGNO_POINTER_ALIGN (HARD_FRAME_POINTER_REGNUM) = STACK_BOUNDARY;
5481 REGNO_POINTER_ALIGN (ARG_POINTER_REGNUM) = STACK_BOUNDARY;
5483 REGNO_POINTER_ALIGN (VIRTUAL_INCOMING_ARGS_REGNUM) = STACK_BOUNDARY;
5484 REGNO_POINTER_ALIGN (VIRTUAL_STACK_VARS_REGNUM) = STACK_BOUNDARY;
5485 REGNO_POINTER_ALIGN (VIRTUAL_STACK_DYNAMIC_REGNUM) = STACK_BOUNDARY;
5486 REGNO_POINTER_ALIGN (VIRTUAL_OUTGOING_ARGS_REGNUM) = STACK_BOUNDARY;
5487 REGNO_POINTER_ALIGN (VIRTUAL_CFA_REGNUM) = BITS_PER_WORD;
5488 #endif
5490 #ifdef INIT_EXPANDERS
5491 INIT_EXPANDERS;
5492 #endif
5495 /* Generate a vector constant for mode MODE and constant value CONSTANT. */
5497 static rtx
5498 gen_const_vector (enum machine_mode mode, int constant)
5500 rtx tem;
5501 rtvec v;
5502 int units, i;
5503 enum machine_mode inner;
5505 units = GET_MODE_NUNITS (mode);
5506 inner = GET_MODE_INNER (mode);
5508 gcc_assert (!DECIMAL_FLOAT_MODE_P (inner));
5510 v = rtvec_alloc (units);
5512 /* We need to call this function after we set the scalar const_tiny_rtx
5513 entries. */
5514 gcc_assert (const_tiny_rtx[constant][(int) inner]);
5516 for (i = 0; i < units; ++i)
5517 RTVEC_ELT (v, i) = const_tiny_rtx[constant][(int) inner];
5519 tem = gen_rtx_raw_CONST_VECTOR (mode, v);
5520 return tem;
5523 /* Generate a vector like gen_rtx_raw_CONST_VEC, but use the zero vector when
5524 all elements are zero, and the one vector when all elements are one. */
5526 gen_rtx_CONST_VECTOR (enum machine_mode mode, rtvec v)
5528 enum machine_mode inner = GET_MODE_INNER (mode);
5529 int nunits = GET_MODE_NUNITS (mode);
5530 rtx x;
5531 int i;
5533 /* Check to see if all of the elements have the same value. */
5534 x = RTVEC_ELT (v, nunits - 1);
5535 for (i = nunits - 2; i >= 0; i--)
5536 if (RTVEC_ELT (v, i) != x)
5537 break;
5539 /* If the values are all the same, check to see if we can use one of the
5540 standard constant vectors. */
5541 if (i == -1)
5543 if (x == CONST0_RTX (inner))
5544 return CONST0_RTX (mode);
5545 else if (x == CONST1_RTX (inner))
5546 return CONST1_RTX (mode);
5547 else if (x == CONSTM1_RTX (inner))
5548 return CONSTM1_RTX (mode);
5551 return gen_rtx_raw_CONST_VECTOR (mode, v);
5554 /* Initialise global register information required by all functions. */
5556 void
5557 init_emit_regs (void)
5559 int i;
5560 enum machine_mode mode;
5561 mem_attrs *attrs;
5563 /* Reset register attributes */
5564 htab_empty (reg_attrs_htab);
5566 /* We need reg_raw_mode, so initialize the modes now. */
5567 init_reg_modes_target ();
5569 /* Assign register numbers to the globally defined register rtx. */
5570 stack_pointer_rtx = gen_raw_REG (Pmode, STACK_POINTER_REGNUM);
5571 frame_pointer_rtx = gen_raw_REG (Pmode, FRAME_POINTER_REGNUM);
5572 hard_frame_pointer_rtx = gen_raw_REG (Pmode, HARD_FRAME_POINTER_REGNUM);
5573 arg_pointer_rtx = gen_raw_REG (Pmode, ARG_POINTER_REGNUM);
5574 virtual_incoming_args_rtx =
5575 gen_raw_REG (Pmode, VIRTUAL_INCOMING_ARGS_REGNUM);
5576 virtual_stack_vars_rtx =
5577 gen_raw_REG (Pmode, VIRTUAL_STACK_VARS_REGNUM);
5578 virtual_stack_dynamic_rtx =
5579 gen_raw_REG (Pmode, VIRTUAL_STACK_DYNAMIC_REGNUM);
5580 virtual_outgoing_args_rtx =
5581 gen_raw_REG (Pmode, VIRTUAL_OUTGOING_ARGS_REGNUM);
5582 virtual_cfa_rtx = gen_raw_REG (Pmode, VIRTUAL_CFA_REGNUM);
5583 virtual_preferred_stack_boundary_rtx =
5584 gen_raw_REG (Pmode, VIRTUAL_PREFERRED_STACK_BOUNDARY_REGNUM);
5586 /* Initialize RTL for commonly used hard registers. These are
5587 copied into regno_reg_rtx as we begin to compile each function. */
5588 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
5589 initial_regno_reg_rtx[i] = gen_raw_REG (reg_raw_mode[i], i);
5591 #ifdef RETURN_ADDRESS_POINTER_REGNUM
5592 return_address_pointer_rtx
5593 = gen_raw_REG (Pmode, RETURN_ADDRESS_POINTER_REGNUM);
5594 #endif
5596 if ((unsigned) PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM)
5597 pic_offset_table_rtx = gen_raw_REG (Pmode, PIC_OFFSET_TABLE_REGNUM);
5598 else
5599 pic_offset_table_rtx = NULL_RTX;
5601 for (i = 0; i < (int) MAX_MACHINE_MODE; i++)
5603 mode = (enum machine_mode) i;
5604 attrs = ggc_alloc_cleared_mem_attrs ();
5605 attrs->align = BITS_PER_UNIT;
5606 attrs->addrspace = ADDR_SPACE_GENERIC;
5607 if (mode != BLKmode)
5609 attrs->size_known_p = true;
5610 attrs->size = GET_MODE_SIZE (mode);
5611 if (STRICT_ALIGNMENT)
5612 attrs->align = GET_MODE_ALIGNMENT (mode);
5614 mode_mem_attrs[i] = attrs;
5618 /* Create some permanent unique rtl objects shared between all functions. */
5620 void
5621 init_emit_once (void)
5623 int i;
5624 enum machine_mode mode;
5625 enum machine_mode double_mode;
5627 /* Initialize the CONST_INT, CONST_DOUBLE, CONST_FIXED, and memory attribute
5628 hash tables. */
5629 const_int_htab = htab_create_ggc (37, const_int_htab_hash,
5630 const_int_htab_eq, NULL);
5632 const_double_htab = htab_create_ggc (37, const_double_htab_hash,
5633 const_double_htab_eq, NULL);
5635 const_fixed_htab = htab_create_ggc (37, const_fixed_htab_hash,
5636 const_fixed_htab_eq, NULL);
5638 reg_attrs_htab = htab_create_ggc (37, reg_attrs_htab_hash,
5639 reg_attrs_htab_eq, NULL);
5641 /* Compute the word and byte modes. */
5643 byte_mode = VOIDmode;
5644 word_mode = VOIDmode;
5645 double_mode = VOIDmode;
5647 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
5648 mode != VOIDmode;
5649 mode = GET_MODE_WIDER_MODE (mode))
5651 if (GET_MODE_BITSIZE (mode) == BITS_PER_UNIT
5652 && byte_mode == VOIDmode)
5653 byte_mode = mode;
5655 if (GET_MODE_BITSIZE (mode) == BITS_PER_WORD
5656 && word_mode == VOIDmode)
5657 word_mode = mode;
5660 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
5661 mode != VOIDmode;
5662 mode = GET_MODE_WIDER_MODE (mode))
5664 if (GET_MODE_BITSIZE (mode) == DOUBLE_TYPE_SIZE
5665 && double_mode == VOIDmode)
5666 double_mode = mode;
5669 ptr_mode = mode_for_size (POINTER_SIZE, GET_MODE_CLASS (Pmode), 0);
5671 #ifdef INIT_EXPANDERS
5672 /* This is to initialize {init|mark|free}_machine_status before the first
5673 call to push_function_context_to. This is needed by the Chill front
5674 end which calls push_function_context_to before the first call to
5675 init_function_start. */
5676 INIT_EXPANDERS;
5677 #endif
5679 /* Create the unique rtx's for certain rtx codes and operand values. */
5681 /* Don't use gen_rtx_CONST_INT here since gen_rtx_CONST_INT in this case
5682 tries to use these variables. */
5683 for (i = - MAX_SAVED_CONST_INT; i <= MAX_SAVED_CONST_INT; i++)
5684 const_int_rtx[i + MAX_SAVED_CONST_INT] =
5685 gen_rtx_raw_CONST_INT (VOIDmode, (HOST_WIDE_INT) i);
5687 if (STORE_FLAG_VALUE >= - MAX_SAVED_CONST_INT
5688 && STORE_FLAG_VALUE <= MAX_SAVED_CONST_INT)
5689 const_true_rtx = const_int_rtx[STORE_FLAG_VALUE + MAX_SAVED_CONST_INT];
5690 else
5691 const_true_rtx = gen_rtx_CONST_INT (VOIDmode, STORE_FLAG_VALUE);
5693 REAL_VALUE_FROM_INT (dconst0, 0, 0, double_mode);
5694 REAL_VALUE_FROM_INT (dconst1, 1, 0, double_mode);
5695 REAL_VALUE_FROM_INT (dconst2, 2, 0, double_mode);
5697 dconstm1 = dconst1;
5698 dconstm1.sign = 1;
5700 dconsthalf = dconst1;
5701 SET_REAL_EXP (&dconsthalf, REAL_EXP (&dconsthalf) - 1);
5703 for (i = 0; i < 3; i++)
5705 const REAL_VALUE_TYPE *const r =
5706 (i == 0 ? &dconst0 : i == 1 ? &dconst1 : &dconst2);
5708 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
5709 mode != VOIDmode;
5710 mode = GET_MODE_WIDER_MODE (mode))
5711 const_tiny_rtx[i][(int) mode] =
5712 CONST_DOUBLE_FROM_REAL_VALUE (*r, mode);
5714 for (mode = GET_CLASS_NARROWEST_MODE (MODE_DECIMAL_FLOAT);
5715 mode != VOIDmode;
5716 mode = GET_MODE_WIDER_MODE (mode))
5717 const_tiny_rtx[i][(int) mode] =
5718 CONST_DOUBLE_FROM_REAL_VALUE (*r, mode);
5720 const_tiny_rtx[i][(int) VOIDmode] = GEN_INT (i);
5722 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
5723 mode != VOIDmode;
5724 mode = GET_MODE_WIDER_MODE (mode))
5725 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
5727 for (mode = MIN_MODE_PARTIAL_INT;
5728 mode <= MAX_MODE_PARTIAL_INT;
5729 mode = (enum machine_mode)((int)(mode) + 1))
5730 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
5733 const_tiny_rtx[3][(int) VOIDmode] = constm1_rtx;
5735 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
5736 mode != VOIDmode;
5737 mode = GET_MODE_WIDER_MODE (mode))
5738 const_tiny_rtx[3][(int) mode] = constm1_rtx;
5740 for (mode = MIN_MODE_PARTIAL_INT;
5741 mode <= MAX_MODE_PARTIAL_INT;
5742 mode = (enum machine_mode)((int)(mode) + 1))
5743 const_tiny_rtx[3][(int) mode] = constm1_rtx;
5745 for (mode = GET_CLASS_NARROWEST_MODE (MODE_COMPLEX_INT);
5746 mode != VOIDmode;
5747 mode = GET_MODE_WIDER_MODE (mode))
5749 rtx inner = const_tiny_rtx[0][(int)GET_MODE_INNER (mode)];
5750 const_tiny_rtx[0][(int) mode] = gen_rtx_CONCAT (mode, inner, inner);
5753 for (mode = GET_CLASS_NARROWEST_MODE (MODE_COMPLEX_FLOAT);
5754 mode != VOIDmode;
5755 mode = GET_MODE_WIDER_MODE (mode))
5757 rtx inner = const_tiny_rtx[0][(int)GET_MODE_INNER (mode)];
5758 const_tiny_rtx[0][(int) mode] = gen_rtx_CONCAT (mode, inner, inner);
5761 for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_INT);
5762 mode != VOIDmode;
5763 mode = GET_MODE_WIDER_MODE (mode))
5765 const_tiny_rtx[0][(int) mode] = gen_const_vector (mode, 0);
5766 const_tiny_rtx[1][(int) mode] = gen_const_vector (mode, 1);
5767 const_tiny_rtx[3][(int) mode] = gen_const_vector (mode, 3);
5770 for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_FLOAT);
5771 mode != VOIDmode;
5772 mode = GET_MODE_WIDER_MODE (mode))
5774 const_tiny_rtx[0][(int) mode] = gen_const_vector (mode, 0);
5775 const_tiny_rtx[1][(int) mode] = gen_const_vector (mode, 1);
5778 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FRACT);
5779 mode != VOIDmode;
5780 mode = GET_MODE_WIDER_MODE (mode))
5782 FCONST0 (mode).data.high = 0;
5783 FCONST0 (mode).data.low = 0;
5784 FCONST0 (mode).mode = mode;
5785 const_tiny_rtx[0][(int) mode] = CONST_FIXED_FROM_FIXED_VALUE (
5786 FCONST0 (mode), mode);
5789 for (mode = GET_CLASS_NARROWEST_MODE (MODE_UFRACT);
5790 mode != VOIDmode;
5791 mode = GET_MODE_WIDER_MODE (mode))
5793 FCONST0 (mode).data.high = 0;
5794 FCONST0 (mode).data.low = 0;
5795 FCONST0 (mode).mode = mode;
5796 const_tiny_rtx[0][(int) mode] = CONST_FIXED_FROM_FIXED_VALUE (
5797 FCONST0 (mode), mode);
5800 for (mode = GET_CLASS_NARROWEST_MODE (MODE_ACCUM);
5801 mode != VOIDmode;
5802 mode = GET_MODE_WIDER_MODE (mode))
5804 FCONST0 (mode).data.high = 0;
5805 FCONST0 (mode).data.low = 0;
5806 FCONST0 (mode).mode = mode;
5807 const_tiny_rtx[0][(int) mode] = CONST_FIXED_FROM_FIXED_VALUE (
5808 FCONST0 (mode), mode);
5810 /* We store the value 1. */
5811 FCONST1 (mode).data.high = 0;
5812 FCONST1 (mode).data.low = 0;
5813 FCONST1 (mode).mode = mode;
5814 FCONST1 (mode).data
5815 = double_int_one.lshift (GET_MODE_FBIT (mode),
5816 HOST_BITS_PER_DOUBLE_INT,
5817 SIGNED_FIXED_POINT_MODE_P (mode));
5818 const_tiny_rtx[1][(int) mode] = CONST_FIXED_FROM_FIXED_VALUE (
5819 FCONST1 (mode), mode);
5822 for (mode = GET_CLASS_NARROWEST_MODE (MODE_UACCUM);
5823 mode != VOIDmode;
5824 mode = GET_MODE_WIDER_MODE (mode))
5826 FCONST0 (mode).data.high = 0;
5827 FCONST0 (mode).data.low = 0;
5828 FCONST0 (mode).mode = mode;
5829 const_tiny_rtx[0][(int) mode] = CONST_FIXED_FROM_FIXED_VALUE (
5830 FCONST0 (mode), mode);
5832 /* We store the value 1. */
5833 FCONST1 (mode).data.high = 0;
5834 FCONST1 (mode).data.low = 0;
5835 FCONST1 (mode).mode = mode;
5836 FCONST1 (mode).data
5837 = double_int_one.lshift (GET_MODE_FBIT (mode),
5838 HOST_BITS_PER_DOUBLE_INT,
5839 SIGNED_FIXED_POINT_MODE_P (mode));
5840 const_tiny_rtx[1][(int) mode] = CONST_FIXED_FROM_FIXED_VALUE (
5841 FCONST1 (mode), mode);
5844 for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_FRACT);
5845 mode != VOIDmode;
5846 mode = GET_MODE_WIDER_MODE (mode))
5848 const_tiny_rtx[0][(int) mode] = gen_const_vector (mode, 0);
5851 for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_UFRACT);
5852 mode != VOIDmode;
5853 mode = GET_MODE_WIDER_MODE (mode))
5855 const_tiny_rtx[0][(int) mode] = gen_const_vector (mode, 0);
5858 for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_ACCUM);
5859 mode != VOIDmode;
5860 mode = GET_MODE_WIDER_MODE (mode))
5862 const_tiny_rtx[0][(int) mode] = gen_const_vector (mode, 0);
5863 const_tiny_rtx[1][(int) mode] = gen_const_vector (mode, 1);
5866 for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_UACCUM);
5867 mode != VOIDmode;
5868 mode = GET_MODE_WIDER_MODE (mode))
5870 const_tiny_rtx[0][(int) mode] = gen_const_vector (mode, 0);
5871 const_tiny_rtx[1][(int) mode] = gen_const_vector (mode, 1);
5874 for (i = (int) CCmode; i < (int) MAX_MACHINE_MODE; ++i)
5875 if (GET_MODE_CLASS ((enum machine_mode) i) == MODE_CC)
5876 const_tiny_rtx[0][i] = const0_rtx;
5878 const_tiny_rtx[0][(int) BImode] = const0_rtx;
5879 if (STORE_FLAG_VALUE == 1)
5880 const_tiny_rtx[1][(int) BImode] = const1_rtx;
5882 pc_rtx = gen_rtx_fmt_ (PC, VOIDmode);
5883 ret_rtx = gen_rtx_fmt_ (RETURN, VOIDmode);
5884 simple_return_rtx = gen_rtx_fmt_ (SIMPLE_RETURN, VOIDmode);
5885 cc0_rtx = gen_rtx_fmt_ (CC0, VOIDmode);
5888 /* Produce exact duplicate of insn INSN after AFTER.
5889 Care updating of libcall regions if present. */
5892 emit_copy_of_insn_after (rtx insn, rtx after)
5894 rtx new_rtx, link;
5896 switch (GET_CODE (insn))
5898 case INSN:
5899 new_rtx = emit_insn_after (copy_insn (PATTERN (insn)), after);
5900 break;
5902 case JUMP_INSN:
5903 new_rtx = emit_jump_insn_after (copy_insn (PATTERN (insn)), after);
5904 break;
5906 case DEBUG_INSN:
5907 new_rtx = emit_debug_insn_after (copy_insn (PATTERN (insn)), after);
5908 break;
5910 case CALL_INSN:
5911 new_rtx = emit_call_insn_after (copy_insn (PATTERN (insn)), after);
5912 if (CALL_INSN_FUNCTION_USAGE (insn))
5913 CALL_INSN_FUNCTION_USAGE (new_rtx)
5914 = copy_insn (CALL_INSN_FUNCTION_USAGE (insn));
5915 SIBLING_CALL_P (new_rtx) = SIBLING_CALL_P (insn);
5916 RTL_CONST_CALL_P (new_rtx) = RTL_CONST_CALL_P (insn);
5917 RTL_PURE_CALL_P (new_rtx) = RTL_PURE_CALL_P (insn);
5918 RTL_LOOPING_CONST_OR_PURE_CALL_P (new_rtx)
5919 = RTL_LOOPING_CONST_OR_PURE_CALL_P (insn);
5920 break;
5922 default:
5923 gcc_unreachable ();
5926 /* Update LABEL_NUSES. */
5927 mark_jump_label (PATTERN (new_rtx), new_rtx, 0);
5929 INSN_LOCATION (new_rtx) = INSN_LOCATION (insn);
5931 /* If the old insn is frame related, then so is the new one. This is
5932 primarily needed for IA-64 unwind info which marks epilogue insns,
5933 which may be duplicated by the basic block reordering code. */
5934 RTX_FRAME_RELATED_P (new_rtx) = RTX_FRAME_RELATED_P (insn);
5936 /* Copy all REG_NOTES except REG_LABEL_OPERAND since mark_jump_label
5937 will make them. REG_LABEL_TARGETs are created there too, but are
5938 supposed to be sticky, so we copy them. */
5939 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
5940 if (REG_NOTE_KIND (link) != REG_LABEL_OPERAND)
5942 if (GET_CODE (link) == EXPR_LIST)
5943 add_reg_note (new_rtx, REG_NOTE_KIND (link),
5944 copy_insn_1 (XEXP (link, 0)));
5945 else
5946 add_shallow_copy_of_reg_note (new_rtx, link);
5949 INSN_CODE (new_rtx) = INSN_CODE (insn);
5950 return new_rtx;
5953 static GTY((deletable)) rtx hard_reg_clobbers [NUM_MACHINE_MODES][FIRST_PSEUDO_REGISTER];
5955 gen_hard_reg_clobber (enum machine_mode mode, unsigned int regno)
5957 if (hard_reg_clobbers[mode][regno])
5958 return hard_reg_clobbers[mode][regno];
5959 else
5960 return (hard_reg_clobbers[mode][regno] =
5961 gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (mode, regno)));
5964 location_t prologue_location;
5965 location_t epilogue_location;
5967 /* Hold current location information and last location information, so the
5968 datastructures are built lazily only when some instructions in given
5969 place are needed. */
5970 static location_t curr_location;
5972 /* Allocate insn location datastructure. */
5973 void
5974 insn_locations_init (void)
5976 prologue_location = epilogue_location = 0;
5977 curr_location = UNKNOWN_LOCATION;
5980 /* At the end of emit stage, clear current location. */
5981 void
5982 insn_locations_finalize (void)
5984 epilogue_location = curr_location;
5985 curr_location = UNKNOWN_LOCATION;
5988 /* Set current location. */
5989 void
5990 set_curr_insn_location (location_t location)
5992 curr_location = location;
5995 /* Get current location. */
5996 location_t
5997 curr_insn_location (void)
5999 return curr_location;
6002 /* Return lexical scope block insn belongs to. */
6003 tree
6004 insn_scope (const_rtx insn)
6006 return LOCATION_BLOCK (INSN_LOCATION (insn));
6009 /* Return line number of the statement that produced this insn. */
6011 insn_line (const_rtx insn)
6013 return LOCATION_LINE (INSN_LOCATION (insn));
6016 /* Return source file of the statement that produced this insn. */
6017 const char *
6018 insn_file (const_rtx insn)
6020 return LOCATION_FILE (INSN_LOCATION (insn));
6023 /* Return true if memory model MODEL requires a pre-operation (release-style)
6024 barrier or a post-operation (acquire-style) barrier. While not universal,
6025 this function matches behavior of several targets. */
6027 bool
6028 need_atomic_barrier_p (enum memmodel model, bool pre)
6030 switch (model & MEMMODEL_MASK)
6032 case MEMMODEL_RELAXED:
6033 case MEMMODEL_CONSUME:
6034 return false;
6035 case MEMMODEL_RELEASE:
6036 return pre;
6037 case MEMMODEL_ACQUIRE:
6038 return !pre;
6039 case MEMMODEL_ACQ_REL:
6040 case MEMMODEL_SEQ_CST:
6041 return true;
6042 default:
6043 gcc_unreachable ();
6047 #include "gt-emit-rtl.h"