]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/emit-rtl.c
Makefile.in (C_OBJS): Include c-pretty-print.o
[thirdparty/gcc.git] / gcc / emit-rtl.c
CommitLineData
23b2ce53 1/* Emit RTL for the GNU C-Compiler expander.
ef58a523 2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
2cc2d4bb 3 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
23b2ce53 4
1322177d 5This file is part of GCC.
23b2ce53 6
1322177d
LB
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 2, or (at your option) any later
10version.
23b2ce53 11
1322177d
LB
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
23b2ce53
RS
16
17You should have received a copy of the GNU General Public License
1322177d
LB
18along with GCC; see the file COPYING. If not, write to the Free
19Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2002111-1307, USA. */
23b2ce53
RS
21
22
23/* Middle-to-low level generation of rtx code and insns.
24
25 This file contains the functions `gen_rtx', `gen_reg_rtx'
26 and `gen_label_rtx' that are the usual ways of creating rtl
27 expressions for most purposes.
28
29 It also has the functions for creating insns and linking
30 them in the doubly-linked chain.
31
32 The patterns of the insns are created by machine-dependent
33 routines in insn-emit.c, which is generated automatically from
34 the machine description. These routines use `gen_rtx' to make
35 the individual rtx's of the pattern; what is machine dependent
36 is the kind of rtx's they make and what arguments they use. */
37
38#include "config.h"
670ee920 39#include "system.h"
01198c2f 40#include "toplev.h"
23b2ce53 41#include "rtl.h"
a25c7971 42#include "tree.h"
6baf1cc8 43#include "tm_p.h"
23b2ce53
RS
44#include "flags.h"
45#include "function.h"
46#include "expr.h"
47#include "regs.h"
aff48bca 48#include "hard-reg-set.h"
c13e8210 49#include "hashtab.h"
23b2ce53 50#include "insn-config.h"
e9a25f70 51#include "recog.h"
23b2ce53 52#include "real.h"
ca695ac9 53#include "obstack.h"
0dfa1860 54#include "bitmap.h"
a05924f9 55#include "basic-block.h"
87ff9c8e 56#include "ggc.h"
e1772ac0 57#include "debug.h"
d23c55c2 58#include "langhooks.h"
ca695ac9 59
1d445e9e
ILT
60/* Commonly used modes. */
61
0f41302f
MS
62enum machine_mode byte_mode; /* Mode whose width is BITS_PER_UNIT. */
63enum machine_mode word_mode; /* Mode whose width is BITS_PER_WORD. */
9ec36da5 64enum machine_mode double_mode; /* Mode whose width is DOUBLE_TYPE_SIZE. */
0f41302f 65enum machine_mode ptr_mode; /* Mode whose width is POINTER_SIZE. */
1d445e9e 66
23b2ce53
RS
67
68/* This is *not* reset after each function. It gives each CODE_LABEL
69 in the entire compilation a unique label number. */
70
71static int label_num = 1;
72
23b2ce53
RS
73/* Highest label number in current function.
74 Zero means use the value of label_num instead.
75 This is nonzero only when belatedly compiling an inline function. */
76
77static int last_label_num;
78
79/* Value label_num had when set_new_first_and_last_label_number was called.
80 If label_num has not changed since then, last_label_num is valid. */
81
82static int base_label_num;
83
84/* Nonzero means do not generate NOTEs for source line numbers. */
85
86static int no_line_numbers;
87
88/* Commonly used rtx's, so that we only need space for one copy.
89 These are initialized once for the entire compilation.
5692c7bc
ZW
90 All of these are unique; no other rtx-object will be equal to any
91 of these. */
23b2ce53 92
5da077de 93rtx global_rtl[GR_MAX];
23b2ce53 94
6cde4876
JL
95/* Commonly used RTL for hard registers. These objects are not necessarily
96 unique, so we allocate them separately from global_rtl. They are
97 initialized once per compilation unit, then copied into regno_reg_rtx
98 at the beginning of each function. */
99static GTY(()) rtx static_regno_reg_rtx[FIRST_PSEUDO_REGISTER];
100
23b2ce53
RS
101/* We record floating-point CONST_DOUBLEs in each floating-point mode for
102 the values of 0, 1, and 2. For the integer entries and VOIDmode, we
103 record a copy of const[012]_rtx. */
104
105rtx const_tiny_rtx[3][(int) MAX_MACHINE_MODE];
106
68d75312
JC
107rtx const_true_rtx;
108
23b2ce53
RS
109REAL_VALUE_TYPE dconst0;
110REAL_VALUE_TYPE dconst1;
111REAL_VALUE_TYPE dconst2;
112REAL_VALUE_TYPE dconstm1;
113
114/* All references to the following fixed hard registers go through
115 these unique rtl objects. On machines where the frame-pointer and
116 arg-pointer are the same register, they use the same unique object.
117
118 After register allocation, other rtl objects which used to be pseudo-regs
119 may be clobbered to refer to the frame-pointer register.
120 But references that were originally to the frame-pointer can be
121 distinguished from the others because they contain frame_pointer_rtx.
122
ac6f08b0
DE
123 When to use frame_pointer_rtx and hard_frame_pointer_rtx is a little
124 tricky: until register elimination has taken place hard_frame_pointer_rtx
750c9258 125 should be used if it is being set, and frame_pointer_rtx otherwise. After
ac6f08b0
DE
126 register elimination hard_frame_pointer_rtx should always be used.
127 On machines where the two registers are same (most) then these are the
128 same.
129
23b2ce53
RS
130 In an inline procedure, the stack and frame pointer rtxs may not be
131 used for anything else. */
23b2ce53
RS
132rtx struct_value_rtx; /* (REG:Pmode STRUCT_VALUE_REGNUM) */
133rtx struct_value_incoming_rtx; /* (REG:Pmode STRUCT_VALUE_INCOMING_REGNUM) */
134rtx static_chain_rtx; /* (REG:Pmode STATIC_CHAIN_REGNUM) */
135rtx static_chain_incoming_rtx; /* (REG:Pmode STATIC_CHAIN_INCOMING_REGNUM) */
136rtx pic_offset_table_rtx; /* (REG:Pmode PIC_OFFSET_TABLE_REGNUM) */
137
a4417a86
JW
138/* This is used to implement __builtin_return_address for some machines.
139 See for instance the MIPS port. */
140rtx return_address_pointer_rtx; /* (REG:Pmode RETURN_ADDRESS_POINTER_REGNUM) */
141
23b2ce53
RS
142/* We make one copy of (const_int C) where C is in
143 [- MAX_SAVED_CONST_INT, MAX_SAVED_CONST_INT]
144 to save space during the compilation and simplify comparisons of
145 integers. */
146
5da077de 147rtx const_int_rtx[MAX_SAVED_CONST_INT * 2 + 1];
23b2ce53 148
c13e8210
MM
149/* A hash table storing CONST_INTs whose absolute value is greater
150 than MAX_SAVED_CONST_INT. */
151
e2500fed
GK
152static GTY ((if_marked ("ggc_marked_p"), param_is (struct rtx_def)))
153 htab_t const_int_htab;
c13e8210 154
173b24b9 155/* A hash table storing memory attribute structures. */
e2500fed
GK
156static GTY ((if_marked ("ggc_marked_p"), param_is (struct mem_attrs)))
157 htab_t mem_attrs_htab;
173b24b9 158
5692c7bc 159/* A hash table storing all CONST_DOUBLEs. */
e2500fed
GK
160static GTY ((if_marked ("ggc_marked_p"), param_is (struct rtx_def)))
161 htab_t const_double_htab;
5692c7bc 162
01d939e8
BS
163#define first_insn (cfun->emit->x_first_insn)
164#define last_insn (cfun->emit->x_last_insn)
165#define cur_insn_uid (cfun->emit->x_cur_insn_uid)
166#define last_linenum (cfun->emit->x_last_linenum)
167#define last_filename (cfun->emit->x_last_filename)
168#define first_label_num (cfun->emit->x_first_label_num)
23b2ce53 169
711d877c
KG
170static rtx make_jump_insn_raw PARAMS ((rtx));
171static rtx make_call_insn_raw PARAMS ((rtx));
172static rtx find_line_note PARAMS ((rtx));
738cc472
RK
173static rtx change_address_1 PARAMS ((rtx, enum machine_mode, rtx,
174 int));
d1b81779 175static void unshare_all_rtl_1 PARAMS ((rtx));
5c6df058 176static void unshare_all_decls PARAMS ((tree));
2d4aecb3 177static void reset_used_decls PARAMS ((tree));
e5bef2e4 178static void mark_label_nuses PARAMS ((rtx));
c13e8210
MM
179static hashval_t const_int_htab_hash PARAMS ((const void *));
180static int const_int_htab_eq PARAMS ((const void *,
181 const void *));
5692c7bc
ZW
182static hashval_t const_double_htab_hash PARAMS ((const void *));
183static int const_double_htab_eq PARAMS ((const void *,
184 const void *));
185static rtx lookup_const_double PARAMS ((rtx));
173b24b9
RK
186static hashval_t mem_attrs_htab_hash PARAMS ((const void *));
187static int mem_attrs_htab_eq PARAMS ((const void *,
188 const void *));
173b24b9 189static mem_attrs *get_mem_attrs PARAMS ((HOST_WIDE_INT, tree, rtx,
10b76d73
RK
190 rtx, unsigned int,
191 enum machine_mode));
998d7deb 192static tree component_ref_for_mem_expr PARAMS ((tree));
ff88fe10 193static rtx gen_const_vector_0 PARAMS ((enum machine_mode));
c13e8210 194
6b24c259
JH
195/* Probability of the conditional branch currently proceeded by try_split.
196 Set to -1 otherwise. */
197int split_branch_probability = -1;
ca695ac9 198\f
c13e8210
MM
199/* Returns a hash code for X (which is a really a CONST_INT). */
200
201static hashval_t
202const_int_htab_hash (x)
203 const void *x;
204{
5692c7bc 205 return (hashval_t) INTVAL ((struct rtx_def *) x);
c13e8210
MM
206}
207
208/* Returns non-zero if the value represented by X (which is really a
209 CONST_INT) is the same as that given by Y (which is really a
210 HOST_WIDE_INT *). */
211
212static int
213const_int_htab_eq (x, y)
214 const void *x;
215 const void *y;
216{
5692c7bc
ZW
217 return (INTVAL ((rtx) x) == *((const HOST_WIDE_INT *) y));
218}
219
220/* Returns a hash code for X (which is really a CONST_DOUBLE). */
221static hashval_t
222const_double_htab_hash (x)
223 const void *x;
224{
225 hashval_t h = 0;
226 size_t i;
227 rtx value = (rtx) x;
228
229 for (i = 0; i < sizeof(CONST_DOUBLE_FORMAT)-1; i++)
230 h ^= XWINT (value, i);
231 return h;
232}
233
234/* Returns non-zero if the value represented by X (really a ...)
235 is the same as that represented by Y (really a ...) */
236static int
237const_double_htab_eq (x, y)
238 const void *x;
239 const void *y;
240{
241 rtx a = (rtx)x, b = (rtx)y;
242 size_t i;
243
244 if (GET_MODE (a) != GET_MODE (b))
245 return 0;
246 for (i = 0; i < sizeof(CONST_DOUBLE_FORMAT)-1; i++)
247 if (XWINT (a, i) != XWINT (b, i))
248 return 0;
249
250 return 1;
c13e8210
MM
251}
252
173b24b9
RK
253/* Returns a hash code for X (which is a really a mem_attrs *). */
254
255static hashval_t
256mem_attrs_htab_hash (x)
257 const void *x;
258{
259 mem_attrs *p = (mem_attrs *) x;
260
261 return (p->alias ^ (p->align * 1000)
262 ^ ((p->offset ? INTVAL (p->offset) : 0) * 50000)
263 ^ ((p->size ? INTVAL (p->size) : 0) * 2500000)
998d7deb 264 ^ (size_t) p->expr);
173b24b9
RK
265}
266
267/* Returns non-zero if the value represented by X (which is really a
268 mem_attrs *) is the same as that given by Y (which is also really a
269 mem_attrs *). */
c13e8210
MM
270
271static int
173b24b9
RK
272mem_attrs_htab_eq (x, y)
273 const void *x;
274 const void *y;
c13e8210 275{
173b24b9
RK
276 mem_attrs *p = (mem_attrs *) x;
277 mem_attrs *q = (mem_attrs *) y;
278
998d7deb 279 return (p->alias == q->alias && p->expr == q->expr && p->offset == q->offset
173b24b9 280 && p->size == q->size && p->align == q->align);
c13e8210
MM
281}
282
173b24b9 283/* Allocate a new mem_attrs structure and insert it into the hash table if
10b76d73
RK
284 one identical to it is not already in the table. We are doing this for
285 MEM of mode MODE. */
173b24b9
RK
286
287static mem_attrs *
998d7deb 288get_mem_attrs (alias, expr, offset, size, align, mode)
173b24b9 289 HOST_WIDE_INT alias;
998d7deb 290 tree expr;
173b24b9
RK
291 rtx offset;
292 rtx size;
293 unsigned int align;
10b76d73 294 enum machine_mode mode;
173b24b9
RK
295{
296 mem_attrs attrs;
297 void **slot;
298
10b76d73 299 /* If everything is the default, we can just return zero. */
998d7deb 300 if (alias == 0 && expr == 0 && offset == 0
10b76d73
RK
301 && (size == 0
302 || (mode != BLKmode && GET_MODE_SIZE (mode) == INTVAL (size)))
916f389b 303 && (align == BITS_PER_UNIT
917afb0c
RK
304 || (STRICT_ALIGNMENT
305 && mode != BLKmode && align == GET_MODE_ALIGNMENT (mode))))
10b76d73
RK
306 return 0;
307
173b24b9 308 attrs.alias = alias;
998d7deb 309 attrs.expr = expr;
173b24b9
RK
310 attrs.offset = offset;
311 attrs.size = size;
312 attrs.align = align;
313
314 slot = htab_find_slot (mem_attrs_htab, &attrs, INSERT);
315 if (*slot == 0)
316 {
317 *slot = ggc_alloc (sizeof (mem_attrs));
318 memcpy (*slot, &attrs, sizeof (mem_attrs));
319 }
320
321 return *slot;
c13e8210
MM
322}
323
08394eef
BS
324/* Generate a new REG rtx. Make sure ORIGINAL_REGNO is set properly, and
325 don't attempt to share with the various global pieces of rtl (such as
326 frame_pointer_rtx). */
327
328rtx
329gen_raw_REG (mode, regno)
330 enum machine_mode mode;
331 int regno;
332{
333 rtx x = gen_rtx_raw_REG (mode, regno);
334 ORIGINAL_REGNO (x) = regno;
335 return x;
336}
337
c5c76735
JL
338/* There are some RTL codes that require special attention; the generation
339 functions do the raw handling. If you add to this list, modify
340 special_rtx in gengenrtl.c as well. */
341
3b80f6ca
RH
342rtx
343gen_rtx_CONST_INT (mode, arg)
c13e8210 344 enum machine_mode mode ATTRIBUTE_UNUSED;
3b80f6ca
RH
345 HOST_WIDE_INT arg;
346{
c13e8210
MM
347 void **slot;
348
3b80f6ca 349 if (arg >= - MAX_SAVED_CONST_INT && arg <= MAX_SAVED_CONST_INT)
5da077de 350 return const_int_rtx[arg + MAX_SAVED_CONST_INT];
3b80f6ca
RH
351
352#if STORE_FLAG_VALUE != 1 && STORE_FLAG_VALUE != -1
353 if (const_true_rtx && arg == STORE_FLAG_VALUE)
354 return const_true_rtx;
355#endif
356
c13e8210 357 /* Look up the CONST_INT in the hash table. */
e38992e8
RK
358 slot = htab_find_slot_with_hash (const_int_htab, &arg,
359 (hashval_t) arg, INSERT);
29105cea 360 if (*slot == 0)
1f8f4a0b 361 *slot = gen_rtx_raw_CONST_INT (VOIDmode, arg);
c13e8210
MM
362
363 return (rtx) *slot;
3b80f6ca
RH
364}
365
2496c7bd
LB
366rtx
367gen_int_mode (c, mode)
368 HOST_WIDE_INT c;
369 enum machine_mode mode;
370{
371 return GEN_INT (trunc_int_for_mode (c, mode));
372}
373
5692c7bc
ZW
374/* CONST_DOUBLEs might be created from pairs of integers, or from
375 REAL_VALUE_TYPEs. Also, their length is known only at run time,
376 so we cannot use gen_rtx_raw_CONST_DOUBLE. */
377
378/* Determine whether REAL, a CONST_DOUBLE, already exists in the
379 hash table. If so, return its counterpart; otherwise add it
380 to the hash table and return it. */
381static rtx
382lookup_const_double (real)
383 rtx real;
384{
385 void **slot = htab_find_slot (const_double_htab, real, INSERT);
386 if (*slot == 0)
387 *slot = real;
388
389 return (rtx) *slot;
390}
29105cea 391
5692c7bc
ZW
392/* Return a CONST_DOUBLE rtx for a floating-point value specified by
393 VALUE in mode MODE. */
0133b7d9 394rtx
5692c7bc
ZW
395const_double_from_real_value (value, mode)
396 REAL_VALUE_TYPE value;
0133b7d9 397 enum machine_mode mode;
0133b7d9 398{
5692c7bc
ZW
399 rtx real = rtx_alloc (CONST_DOUBLE);
400 PUT_MODE (real, mode);
401
402 memcpy (&CONST_DOUBLE_LOW (real), &value, sizeof (REAL_VALUE_TYPE));
403
404 return lookup_const_double (real);
405}
406
407/* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair
408 of ints: I0 is the low-order word and I1 is the high-order word.
409 Do not use this routine for non-integer modes; convert to
410 REAL_VALUE_TYPE and use CONST_DOUBLE_FROM_REAL_VALUE. */
411
412rtx
413immed_double_const (i0, i1, mode)
414 HOST_WIDE_INT i0, i1;
415 enum machine_mode mode;
416{
417 rtx value;
418 unsigned int i;
419
420 if (mode != VOIDmode)
421 {
422 int width;
423 if (GET_MODE_CLASS (mode) != MODE_INT
cb2a532e
AH
424 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT
425 /* We can get a 0 for an error mark. */
426 && GET_MODE_CLASS (mode) != MODE_VECTOR_INT
427 && GET_MODE_CLASS (mode) != MODE_VECTOR_FLOAT)
5692c7bc
ZW
428 abort ();
429
430 /* We clear out all bits that don't belong in MODE, unless they and
431 our sign bit are all one. So we get either a reasonable negative
432 value or a reasonable unsigned value for this mode. */
433 width = GET_MODE_BITSIZE (mode);
434 if (width < HOST_BITS_PER_WIDE_INT
435 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
436 != ((HOST_WIDE_INT) (-1) << (width - 1))))
437 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
438 else if (width == HOST_BITS_PER_WIDE_INT
439 && ! (i1 == ~0 && i0 < 0))
440 i1 = 0;
441 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
442 /* We cannot represent this value as a constant. */
443 abort ();
444
445 /* If this would be an entire word for the target, but is not for
446 the host, then sign-extend on the host so that the number will
447 look the same way on the host that it would on the target.
448
449 For example, when building a 64 bit alpha hosted 32 bit sparc
450 targeted compiler, then we want the 32 bit unsigned value -1 to be
451 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
452 The latter confuses the sparc backend. */
453
454 if (width < HOST_BITS_PER_WIDE_INT
455 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
456 i0 |= ((HOST_WIDE_INT) (-1) << width);
2454beaf 457
5692c7bc
ZW
458 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a
459 CONST_INT.
2454beaf 460
5692c7bc
ZW
461 ??? Strictly speaking, this is wrong if we create a CONST_INT for
462 a large unsigned constant with the size of MODE being
463 HOST_BITS_PER_WIDE_INT and later try to interpret that constant
464 in a wider mode. In that case we will mis-interpret it as a
465 negative number.
2454beaf 466
5692c7bc
ZW
467 Unfortunately, the only alternative is to make a CONST_DOUBLE for
468 any constant in any mode if it is an unsigned constant larger
469 than the maximum signed integer in an int on the host. However,
470 doing this will break everyone that always expects to see a
471 CONST_INT for SImode and smaller.
472
473 We have always been making CONST_INTs in this case, so nothing
474 new is being broken. */
475
476 if (width <= HOST_BITS_PER_WIDE_INT)
477 i1 = (i0 < 0) ? ~(HOST_WIDE_INT) 0 : 0;
478 }
479
480 /* If this integer fits in one word, return a CONST_INT. */
481 if ((i1 == 0 && i0 >= 0) || (i1 == ~0 && i0 < 0))
482 return GEN_INT (i0);
483
484 /* We use VOIDmode for integers. */
485 value = rtx_alloc (CONST_DOUBLE);
486 PUT_MODE (value, VOIDmode);
487
488 CONST_DOUBLE_LOW (value) = i0;
489 CONST_DOUBLE_HIGH (value) = i1;
490
491 for (i = 2; i < (sizeof CONST_DOUBLE_FORMAT - 1); i++)
492 XWINT (value, i) = 0;
493
494 return lookup_const_double (value);
0133b7d9
RH
495}
496
3b80f6ca
RH
497rtx
498gen_rtx_REG (mode, regno)
499 enum machine_mode mode;
5692c7bc 500 unsigned int regno;
3b80f6ca
RH
501{
502 /* In case the MD file explicitly references the frame pointer, have
503 all such references point to the same frame pointer. This is
504 used during frame pointer elimination to distinguish the explicit
505 references to these registers from pseudos that happened to be
506 assigned to them.
507
508 If we have eliminated the frame pointer or arg pointer, we will
509 be using it as a normal register, for example as a spill
510 register. In such cases, we might be accessing it in a mode that
511 is not Pmode and therefore cannot use the pre-allocated rtx.
512
513 Also don't do this when we are making new REGs in reload, since
514 we don't want to get confused with the real pointers. */
515
516 if (mode == Pmode && !reload_in_progress)
517 {
bcb33994 518 if (regno == FRAME_POINTER_REGNUM)
3b80f6ca
RH
519 return frame_pointer_rtx;
520#if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
bcb33994 521 if (regno == HARD_FRAME_POINTER_REGNUM)
3b80f6ca
RH
522 return hard_frame_pointer_rtx;
523#endif
524#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM && HARD_FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
bcb33994 525 if (regno == ARG_POINTER_REGNUM)
3b80f6ca
RH
526 return arg_pointer_rtx;
527#endif
528#ifdef RETURN_ADDRESS_POINTER_REGNUM
bcb33994 529 if (regno == RETURN_ADDRESS_POINTER_REGNUM)
3b80f6ca
RH
530 return return_address_pointer_rtx;
531#endif
2d67bd7b
JDA
532 if (regno == PIC_OFFSET_TABLE_REGNUM
533 && fixed_regs[PIC_OFFSET_TABLE_REGNUM])
68252e27 534 return pic_offset_table_rtx;
bcb33994 535 if (regno == STACK_POINTER_REGNUM)
3b80f6ca
RH
536 return stack_pointer_rtx;
537 }
538
006a94b0 539#if 0
6cde4876 540 /* If the per-function register table has been set up, try to re-use
006a94b0
JL
541 an existing entry in that table to avoid useless generation of RTL.
542
543 This code is disabled for now until we can fix the various backends
544 which depend on having non-shared hard registers in some cases. Long
545 term we want to re-enable this code as it can significantly cut down
546 on the amount of useless RTL that gets generated. */
6cde4876
JL
547 if (cfun
548 && cfun->emit
549 && regno_reg_rtx
550 && regno < FIRST_PSEUDO_REGISTER
551 && reg_raw_mode[regno] == mode)
552 return regno_reg_rtx[regno];
006a94b0 553#endif
6cde4876 554
08394eef 555 return gen_raw_REG (mode, regno);
3b80f6ca
RH
556}
557
41472af8
MM
558rtx
559gen_rtx_MEM (mode, addr)
560 enum machine_mode mode;
561 rtx addr;
562{
563 rtx rt = gen_rtx_raw_MEM (mode, addr);
564
565 /* This field is not cleared by the mere allocation of the rtx, so
566 we clear it here. */
173b24b9 567 MEM_ATTRS (rt) = 0;
41472af8
MM
568
569 return rt;
570}
ddef6bc7
JJ
571
572rtx
573gen_rtx_SUBREG (mode, reg, offset)
574 enum machine_mode mode;
575 rtx reg;
576 int offset;
577{
578 /* This is the most common failure type.
579 Catch it early so we can see who does it. */
580 if ((offset % GET_MODE_SIZE (mode)) != 0)
581 abort ();
582
583 /* This check isn't usable right now because combine will
584 throw arbitrary crap like a CALL into a SUBREG in
585 gen_lowpart_for_combine so we must just eat it. */
586#if 0
587 /* Check for this too. */
588 if (offset >= GET_MODE_SIZE (GET_MODE (reg)))
589 abort ();
590#endif
5692c7bc 591 return gen_rtx_raw_SUBREG (mode, reg, offset);
ddef6bc7
JJ
592}
593
173b24b9
RK
594/* Generate a SUBREG representing the least-significant part of REG if MODE
595 is smaller than mode of REG, otherwise paradoxical SUBREG. */
596
ddef6bc7
JJ
597rtx
598gen_lowpart_SUBREG (mode, reg)
599 enum machine_mode mode;
600 rtx reg;
601{
602 enum machine_mode inmode;
ddef6bc7
JJ
603
604 inmode = GET_MODE (reg);
605 if (inmode == VOIDmode)
606 inmode = mode;
e0e08ac2
JH
607 return gen_rtx_SUBREG (mode, reg,
608 subreg_lowpart_offset (mode, inmode));
ddef6bc7 609}
c5c76735 610\f
23b2ce53
RS
611/* rtx gen_rtx (code, mode, [element1, ..., elementn])
612**
613** This routine generates an RTX of the size specified by
614** <code>, which is an RTX code. The RTX structure is initialized
615** from the arguments <element1> through <elementn>, which are
616** interpreted according to the specific RTX type's format. The
617** special machine mode associated with the rtx (if any) is specified
618** in <mode>.
619**
1632afca 620** gen_rtx can be invoked in a way which resembles the lisp-like
23b2ce53
RS
621** rtx it will generate. For example, the following rtx structure:
622**
623** (plus:QI (mem:QI (reg:SI 1))
624** (mem:QI (plusw:SI (reg:SI 2) (reg:SI 3))))
625**
626** ...would be generated by the following C code:
627**
750c9258 628** gen_rtx (PLUS, QImode,
23b2ce53
RS
629** gen_rtx (MEM, QImode,
630** gen_rtx (REG, SImode, 1)),
631** gen_rtx (MEM, QImode,
632** gen_rtx (PLUS, SImode,
633** gen_rtx (REG, SImode, 2),
634** gen_rtx (REG, SImode, 3)))),
635*/
636
637/*VARARGS2*/
638rtx
711d877c 639gen_rtx VPARAMS ((enum rtx_code code, enum machine_mode mode, ...))
23b2ce53 640{
b3694847
SS
641 int i; /* Array indices... */
642 const char *fmt; /* Current rtx's format... */
643 rtx rt_val; /* RTX to return to caller... */
23b2ce53 644
7a75edb7
AJ
645 VA_OPEN (p, mode);
646 VA_FIXEDARG (p, enum rtx_code, code);
647 VA_FIXEDARG (p, enum machine_mode, mode);
23b2ce53 648
0133b7d9 649 switch (code)
23b2ce53 650 {
0133b7d9
RH
651 case CONST_INT:
652 rt_val = gen_rtx_CONST_INT (mode, va_arg (p, HOST_WIDE_INT));
653 break;
654
655 case CONST_DOUBLE:
656 {
a79e3a45 657 HOST_WIDE_INT arg0 = va_arg (p, HOST_WIDE_INT);
0133b7d9 658 HOST_WIDE_INT arg1 = va_arg (p, HOST_WIDE_INT);
a79e3a45 659
0fb7aeda 660 rt_val = immed_double_const (arg0, arg1, mode);
0133b7d9
RH
661 }
662 break;
663
664 case REG:
665 rt_val = gen_rtx_REG (mode, va_arg (p, int));
666 break;
667
668 case MEM:
669 rt_val = gen_rtx_MEM (mode, va_arg (p, rtx));
670 break;
671
672 default:
23b2ce53
RS
673 rt_val = rtx_alloc (code); /* Allocate the storage space. */
674 rt_val->mode = mode; /* Store the machine mode... */
675
676 fmt = GET_RTX_FORMAT (code); /* Find the right format... */
677 for (i = 0; i < GET_RTX_LENGTH (code); i++)
678 {
679 switch (*fmt++)
680 {
681 case '0': /* Unused field. */
682 break;
683
684 case 'i': /* An integer? */
685 XINT (rt_val, i) = va_arg (p, int);
686 break;
687
906c4e36
RK
688 case 'w': /* A wide integer? */
689 XWINT (rt_val, i) = va_arg (p, HOST_WIDE_INT);
690 break;
691
23b2ce53
RS
692 case 's': /* A string? */
693 XSTR (rt_val, i) = va_arg (p, char *);
694 break;
695
696 case 'e': /* An expression? */
697 case 'u': /* An insn? Same except when printing. */
698 XEXP (rt_val, i) = va_arg (p, rtx);
699 break;
700
701 case 'E': /* An RTX vector? */
702 XVEC (rt_val, i) = va_arg (p, rtvec);
703 break;
704
0dfa1860
MM
705 case 'b': /* A bitmap? */
706 XBITMAP (rt_val, i) = va_arg (p, bitmap);
707 break;
708
709 case 't': /* A tree? */
710 XTREE (rt_val, i) = va_arg (p, tree);
711 break;
712
23b2ce53 713 default:
1632afca 714 abort ();
23b2ce53
RS
715 }
716 }
0133b7d9 717 break;
23b2ce53 718 }
0133b7d9 719
7a75edb7 720 VA_CLOSE (p);
0133b7d9 721 return rt_val;
23b2ce53
RS
722}
723
724/* gen_rtvec (n, [rt1, ..., rtn])
725**
726** This routine creates an rtvec and stores within it the
727** pointers to rtx's which are its arguments.
728*/
729
730/*VARARGS1*/
731rtvec
711d877c 732gen_rtvec VPARAMS ((int n, ...))
23b2ce53 733{
6268b922 734 int i, save_n;
23b2ce53
RS
735 rtx *vector;
736
7a75edb7
AJ
737 VA_OPEN (p, n);
738 VA_FIXEDARG (p, int, n);
23b2ce53
RS
739
740 if (n == 0)
741 return NULL_RTVEC; /* Don't allocate an empty rtvec... */
742
743 vector = (rtx *) alloca (n * sizeof (rtx));
4f90e4a0 744
23b2ce53
RS
745 for (i = 0; i < n; i++)
746 vector[i] = va_arg (p, rtx);
6268b922
KG
747
748 /* The definition of VA_* in K&R C causes `n' to go out of scope. */
749 save_n = n;
7a75edb7 750 VA_CLOSE (p);
23b2ce53 751
6268b922 752 return gen_rtvec_v (save_n, vector);
23b2ce53
RS
753}
754
755rtvec
756gen_rtvec_v (n, argp)
757 int n;
758 rtx *argp;
759{
b3694847
SS
760 int i;
761 rtvec rt_val;
23b2ce53
RS
762
763 if (n == 0)
764 return NULL_RTVEC; /* Don't allocate an empty rtvec... */
765
766 rt_val = rtvec_alloc (n); /* Allocate an rtvec... */
767
768 for (i = 0; i < n; i++)
8f985ec4 769 rt_val->elem[i] = *argp++;
23b2ce53
RS
770
771 return rt_val;
772}
773\f
774/* Generate a REG rtx for a new pseudo register of mode MODE.
775 This pseudo is assigned the next sequential register number. */
776
777rtx
778gen_reg_rtx (mode)
779 enum machine_mode mode;
780{
01d939e8 781 struct function *f = cfun;
b3694847 782 rtx val;
23b2ce53 783
f1db3576
JL
784 /* Don't let anything called after initial flow analysis create new
785 registers. */
786 if (no_new_pseudos)
23b2ce53
RS
787 abort ();
788
1b3d8f8a
GK
789 if (generating_concat_p
790 && (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
791 || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT))
fc84e8a8
RS
792 {
793 /* For complex modes, don't make a single pseudo.
794 Instead, make a CONCAT of two pseudos.
795 This allows noncontiguous allocation of the real and imaginary parts,
796 which makes much better code. Besides, allocating DCmode
797 pseudos overstrains reload on some machines like the 386. */
798 rtx realpart, imagpart;
799 int size = GET_MODE_UNIT_SIZE (mode);
800 enum machine_mode partmode
801 = mode_for_size (size * BITS_PER_UNIT,
802 (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
803 ? MODE_FLOAT : MODE_INT),
804 0);
805
806 realpart = gen_reg_rtx (partmode);
807 imagpart = gen_reg_rtx (partmode);
3b80f6ca 808 return gen_rtx_CONCAT (mode, realpart, imagpart);
fc84e8a8
RS
809 }
810
0d4903b8
RK
811 /* Make sure regno_pointer_align, regno_decl, and regno_reg_rtx are large
812 enough to have an element for this pseudo reg number. */
23b2ce53 813
3502dc9c 814 if (reg_rtx_no == f->emit->regno_pointer_align_length)
23b2ce53 815 {
3502dc9c 816 int old_size = f->emit->regno_pointer_align_length;
e2ecd91c 817 char *new;
0d4903b8
RK
818 rtx *new1;
819 tree *new2;
820
e2500fed 821 new = ggc_realloc (f->emit->regno_pointer_align, old_size * 2);
49ad7cfa 822 memset (new + old_size, 0, old_size);
f9e158c3 823 f->emit->regno_pointer_align = (unsigned char *) new;
49ad7cfa 824
e2500fed
GK
825 new1 = (rtx *) ggc_realloc (f->emit->x_regno_reg_rtx,
826 old_size * 2 * sizeof (rtx));
49ad7cfa 827 memset (new1 + old_size, 0, old_size * sizeof (rtx));
23b2ce53
RS
828 regno_reg_rtx = new1;
829
e2500fed
GK
830 new2 = (tree *) ggc_realloc (f->emit->regno_decl,
831 old_size * 2 * sizeof (tree));
0d4903b8
RK
832 memset (new2 + old_size, 0, old_size * sizeof (tree));
833 f->emit->regno_decl = new2;
834
3502dc9c 835 f->emit->regno_pointer_align_length = old_size * 2;
23b2ce53
RS
836 }
837
08394eef 838 val = gen_raw_REG (mode, reg_rtx_no);
23b2ce53
RS
839 regno_reg_rtx[reg_rtx_no++] = val;
840 return val;
841}
842
754fdcca
RK
843/* Identify REG (which may be a CONCAT) as a user register. */
844
845void
846mark_user_reg (reg)
847 rtx reg;
848{
849 if (GET_CODE (reg) == CONCAT)
850 {
851 REG_USERVAR_P (XEXP (reg, 0)) = 1;
852 REG_USERVAR_P (XEXP (reg, 1)) = 1;
853 }
854 else if (GET_CODE (reg) == REG)
855 REG_USERVAR_P (reg) = 1;
856 else
857 abort ();
858}
859
86fe05e0
RK
860/* Identify REG as a probable pointer register and show its alignment
861 as ALIGN, if nonzero. */
23b2ce53
RS
862
863void
86fe05e0 864mark_reg_pointer (reg, align)
23b2ce53 865 rtx reg;
86fe05e0 866 int align;
23b2ce53 867{
3502dc9c 868 if (! REG_POINTER (reg))
00995e78 869 {
3502dc9c 870 REG_POINTER (reg) = 1;
86fe05e0 871
00995e78
RE
872 if (align)
873 REGNO_POINTER_ALIGN (REGNO (reg)) = align;
874 }
875 else if (align && align < REGNO_POINTER_ALIGN (REGNO (reg)))
876 /* We can no-longer be sure just how aligned this pointer is */
86fe05e0 877 REGNO_POINTER_ALIGN (REGNO (reg)) = align;
23b2ce53
RS
878}
879
880/* Return 1 plus largest pseudo reg number used in the current function. */
881
882int
883max_reg_num ()
884{
885 return reg_rtx_no;
886}
887
888/* Return 1 + the largest label number used so far in the current function. */
889
890int
891max_label_num ()
892{
893 if (last_label_num && label_num == base_label_num)
894 return last_label_num;
895 return label_num;
896}
897
898/* Return first label number used in this function (if any were used). */
899
900int
901get_first_label_num ()
902{
903 return first_label_num;
904}
905\f
ddef6bc7
JJ
906/* Return the final regno of X, which is a SUBREG of a hard
907 register. */
908int
909subreg_hard_regno (x, check_mode)
b3694847 910 rtx x;
ddef6bc7
JJ
911 int check_mode;
912{
913 enum machine_mode mode = GET_MODE (x);
914 unsigned int byte_offset, base_regno, final_regno;
915 rtx reg = SUBREG_REG (x);
916
917 /* This is where we attempt to catch illegal subregs
918 created by the compiler. */
919 if (GET_CODE (x) != SUBREG
920 || GET_CODE (reg) != REG)
921 abort ();
922 base_regno = REGNO (reg);
923 if (base_regno >= FIRST_PSEUDO_REGISTER)
924 abort ();
0607953c 925 if (check_mode && ! HARD_REGNO_MODE_OK (base_regno, GET_MODE (reg)))
ddef6bc7
JJ
926 abort ();
927
928 /* Catch non-congruent offsets too. */
929 byte_offset = SUBREG_BYTE (x);
930 if ((byte_offset % GET_MODE_SIZE (mode)) != 0)
931 abort ();
932
933 final_regno = subreg_regno (x);
934
935 return final_regno;
936}
937
23b2ce53
RS
938/* Return a value representing some low-order bits of X, where the number
939 of low-order bits is given by MODE. Note that no conversion is done
750c9258 940 between floating-point and fixed-point values, rather, the bit
23b2ce53
RS
941 representation is returned.
942
943 This function handles the cases in common between gen_lowpart, below,
944 and two variants in cse.c and combine.c. These are the cases that can
945 be safely handled at all points in the compilation.
946
947 If this is not a case we can handle, return 0. */
948
949rtx
950gen_lowpart_common (mode, x)
951 enum machine_mode mode;
b3694847 952 rtx x;
23b2ce53 953{
ddef6bc7
JJ
954 int msize = GET_MODE_SIZE (mode);
955 int xsize = GET_MODE_SIZE (GET_MODE (x));
956 int offset = 0;
23b2ce53
RS
957
958 if (GET_MODE (x) == mode)
959 return x;
960
961 /* MODE must occupy no more words than the mode of X. */
962 if (GET_MODE (x) != VOIDmode
ddef6bc7
JJ
963 && ((msize + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD
964 > ((xsize + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)))
23b2ce53
RS
965 return 0;
966
53501a19
BS
967 /* Don't allow generating paradoxical FLOAT_MODE subregs. */
968 if (GET_MODE_CLASS (mode) == MODE_FLOAT
969 && GET_MODE (x) != VOIDmode && msize > xsize)
970 return 0;
971
e0e08ac2 972 offset = subreg_lowpart_offset (mode, GET_MODE (x));
23b2ce53
RS
973
974 if ((GET_CODE (x) == ZERO_EXTEND || GET_CODE (x) == SIGN_EXTEND)
83e9c679
RK
975 && (GET_MODE_CLASS (mode) == MODE_INT
976 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT))
23b2ce53
RS
977 {
978 /* If we are getting the low-order part of something that has been
979 sign- or zero-extended, we can either just use the object being
980 extended or make a narrower extension. If we want an even smaller
981 piece than the size of the object being extended, call ourselves
982 recursively.
983
984 This case is used mostly by combine and cse. */
985
986 if (GET_MODE (XEXP (x, 0)) == mode)
987 return XEXP (x, 0);
988 else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (XEXP (x, 0))))
989 return gen_lowpart_common (mode, XEXP (x, 0));
990 else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (x)))
3b80f6ca 991 return gen_rtx_fmt_e (GET_CODE (x), mode, XEXP (x, 0));
23b2ce53 992 }
76321db6 993 else if (GET_CODE (x) == SUBREG || GET_CODE (x) == REG
34a80643 994 || GET_CODE (x) == CONCAT || GET_CODE (x) == CONST_VECTOR)
e0e08ac2 995 return simplify_gen_subreg (mode, x, GET_MODE (x), offset);
23b2ce53
RS
996 /* If X is a CONST_INT or a CONST_DOUBLE, extract the appropriate bits
997 from the low-order part of the constant. */
83e9c679
RK
998 else if ((GET_MODE_CLASS (mode) == MODE_INT
999 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1000 && GET_MODE (x) == VOIDmode
23b2ce53 1001 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
1a5b457d
RK
1002 {
1003 /* If MODE is twice the host word size, X is already the desired
1004 representation. Otherwise, if MODE is wider than a word, we can't
e1389cac 1005 do this. If MODE is exactly a word, return just one CONST_INT. */
1a5b457d 1006
a8dd0e73 1007 if (GET_MODE_BITSIZE (mode) >= 2 * HOST_BITS_PER_WIDE_INT)
1a5b457d 1008 return x;
906c4e36 1009 else if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
1a5b457d 1010 return 0;
906c4e36 1011 else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
1a5b457d 1012 return (GET_CODE (x) == CONST_INT ? x
906c4e36 1013 : GEN_INT (CONST_DOUBLE_LOW (x)));
1a5b457d
RK
1014 else
1015 {
27eef9ce 1016 /* MODE must be narrower than HOST_BITS_PER_WIDE_INT. */
906c4e36
RK
1017 HOST_WIDE_INT val = (GET_CODE (x) == CONST_INT ? INTVAL (x)
1018 : CONST_DOUBLE_LOW (x));
1a5b457d 1019
27eef9ce 1020 /* Sign extend to HOST_WIDE_INT. */
e1389cac 1021 val = trunc_int_for_mode (val, mode);
1a5b457d
RK
1022
1023 return (GET_CODE (x) == CONST_INT && INTVAL (x) == val ? x
906c4e36 1024 : GEN_INT (val));
1a5b457d
RK
1025 }
1026 }
23b2ce53 1027
ba31d94e 1028 /* The floating-point emulator can handle all conversions between
a2061c0d
GK
1029 FP and integer operands. This simplifies reload because it
1030 doesn't have to deal with constructs like (subreg:DI
1031 (const_double:SF ...)) or (subreg:DF (const_int ...)). */
57dadce2
EC
1032 /* Single-precision floats are always 32-bits and double-precision
1033 floats are always 64-bits. */
a2061c0d 1034
76321db6 1035 else if (GET_MODE_CLASS (mode) == MODE_FLOAT
57dadce2 1036 && GET_MODE_BITSIZE (mode) == 32
a2061c0d 1037 && GET_CODE (x) == CONST_INT)
68252e27 1038 {
a2061c0d
GK
1039 REAL_VALUE_TYPE r;
1040 HOST_WIDE_INT i;
1041
1042 i = INTVAL (x);
1043 r = REAL_VALUE_FROM_TARGET_SINGLE (i);
1044 return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
68252e27 1045 }
76321db6 1046 else if (GET_MODE_CLASS (mode) == MODE_FLOAT
57dadce2 1047 && GET_MODE_BITSIZE (mode) == 64
a2061c0d
GK
1048 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
1049 && GET_MODE (x) == VOIDmode)
1050 {
1051 REAL_VALUE_TYPE r;
1052 HOST_WIDE_INT i[2];
1053 HOST_WIDE_INT low, high;
1054
1055 if (GET_CODE (x) == CONST_INT)
1056 {
1057 low = INTVAL (x);
1058 high = low >> (HOST_BITS_PER_WIDE_INT - 1);
1059 }
1060 else
1061 {
750c9258 1062 low = CONST_DOUBLE_LOW (x);
a2061c0d
GK
1063 high = CONST_DOUBLE_HIGH (x);
1064 }
1065
467cb2da 1066#if HOST_BITS_PER_WIDE_INT == 32
a2061c0d
GK
1067 /* REAL_VALUE_TARGET_DOUBLE takes the addressing order of the
1068 target machine. */
1069 if (WORDS_BIG_ENDIAN)
1070 i[0] = high, i[1] = low;
1071 else
1072 i[0] = low, i[1] = high;
467cb2da
HP
1073#else
1074 i[0] = low;
1075#endif
a2061c0d
GK
1076
1077 r = REAL_VALUE_FROM_TARGET_DOUBLE (i);
1078 return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
1079 }
1080 else if ((GET_MODE_CLASS (mode) == MODE_INT
1081 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1082 && GET_CODE (x) == CONST_DOUBLE
1083 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1084 {
1085 REAL_VALUE_TYPE r;
1086 long i[4]; /* Only the low 32 bits of each 'long' are used. */
1087 int endian = WORDS_BIG_ENDIAN ? 1 : 0;
1088
8125704b
GK
1089 /* Convert 'r' into an array of four 32-bit words in target word
1090 order. */
a2061c0d 1091 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
57dadce2 1092 switch (GET_MODE_BITSIZE (GET_MODE (x)))
a2061c0d 1093 {
57dadce2 1094 case 32:
68252e27 1095 REAL_VALUE_TO_TARGET_SINGLE (r, i[3 * endian]);
8125704b
GK
1096 i[1] = 0;
1097 i[2] = 0;
68252e27
KH
1098 i[3 - 3 * endian] = 0;
1099 break;
57dadce2 1100 case 64:
68252e27 1101 REAL_VALUE_TO_TARGET_DOUBLE (r, i + 2 * endian);
8125704b
GK
1102 i[2 - 2 * endian] = 0;
1103 i[3 - 2 * endian] = 0;
68252e27 1104 break;
57dadce2 1105 case 96:
e389897b 1106 REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, i + endian);
8125704b 1107 i[3 - 3 * endian] = 0;
76321db6 1108 break;
57dadce2 1109 case 128:
a2061c0d
GK
1110 REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, i);
1111 break;
1112 default:
1156b23c 1113 abort ();
a2061c0d 1114 }
a2061c0d
GK
1115 /* Now, pack the 32-bit elements of the array into a CONST_DOUBLE
1116 and return it. */
1117#if HOST_BITS_PER_WIDE_INT == 32
8125704b 1118 return immed_double_const (i[3 * endian], i[1 + endian], mode);
a2061c0d 1119#else
8125704b
GK
1120 if (HOST_BITS_PER_WIDE_INT != 64)
1121 abort ();
50e60bc3 1122
a76033a0
GK
1123 return immed_double_const ((((unsigned long) i[3 * endian])
1124 | ((HOST_WIDE_INT) i[1 + endian] << 32)),
1125 (((unsigned long) i[2 - endian])
1126 | ((HOST_WIDE_INT) i[3 - 3 * endian] << 32)),
8125704b 1127 mode);
a2061c0d
GK
1128#endif
1129 }
8aada4ad 1130
23b2ce53
RS
1131 /* Otherwise, we can't do this. */
1132 return 0;
1133}
1134\f
280194b0
RS
1135/* Return the real part (which has mode MODE) of a complex value X.
1136 This always comes at the low address in memory. */
1137
1138rtx
1139gen_realpart (mode, x)
1140 enum machine_mode mode;
b3694847 1141 rtx x;
280194b0 1142{
e0e08ac2
JH
1143 if (WORDS_BIG_ENDIAN
1144 && GET_MODE_BITSIZE (mode) < BITS_PER_WORD
1145 && REG_P (x)
1146 && REGNO (x) < FIRST_PSEUDO_REGISTER)
400500c4 1147 internal_error
c725bd79 1148 ("can't access real part of complex value in hard register");
dc139c90 1149 else if (WORDS_BIG_ENDIAN)
280194b0
RS
1150 return gen_highpart (mode, x);
1151 else
1152 return gen_lowpart (mode, x);
1153}
1154
1155/* Return the imaginary part (which has mode MODE) of a complex value X.
1156 This always comes at the high address in memory. */
1157
1158rtx
1159gen_imagpart (mode, x)
1160 enum machine_mode mode;
b3694847 1161 rtx x;
280194b0 1162{
e0e08ac2 1163 if (WORDS_BIG_ENDIAN)
280194b0 1164 return gen_lowpart (mode, x);
ddef6bc7 1165 else if (! WORDS_BIG_ENDIAN
40c0c3cf
JL
1166 && GET_MODE_BITSIZE (mode) < BITS_PER_WORD
1167 && REG_P (x)
1168 && REGNO (x) < FIRST_PSEUDO_REGISTER)
400500c4
RK
1169 internal_error
1170 ("can't access imaginary part of complex value in hard register");
280194b0
RS
1171 else
1172 return gen_highpart (mode, x);
1173}
81284a6a
JW
1174
1175/* Return 1 iff X, assumed to be a SUBREG,
1176 refers to the real part of the complex value in its containing reg.
1177 Complex values are always stored with the real part in the first word,
1178 regardless of WORDS_BIG_ENDIAN. */
1179
1180int
1181subreg_realpart_p (x)
1182 rtx x;
1183{
1184 if (GET_CODE (x) != SUBREG)
1185 abort ();
1186
ddef6bc7 1187 return ((unsigned int) SUBREG_BYTE (x)
770ae6cc 1188 < GET_MODE_UNIT_SIZE (GET_MODE (SUBREG_REG (x))));
81284a6a 1189}
280194b0 1190\f
23b2ce53
RS
1191/* Assuming that X is an rtx (e.g., MEM, REG or SUBREG) for a value,
1192 return an rtx (MEM, SUBREG, or CONST_INT) that refers to the
1193 least-significant part of X.
1194 MODE specifies how big a part of X to return;
1195 it usually should not be larger than a word.
1196 If X is a MEM whose address is a QUEUED, the value may be so also. */
1197
1198rtx
1199gen_lowpart (mode, x)
1200 enum machine_mode mode;
b3694847 1201 rtx x;
23b2ce53
RS
1202{
1203 rtx result = gen_lowpart_common (mode, x);
1204
1205 if (result)
1206 return result;
ea8262b0
RK
1207 else if (GET_CODE (x) == REG)
1208 {
1209 /* Must be a hard reg that's not valid in MODE. */
1210 result = gen_lowpart_common (mode, copy_to_reg (x));
1211 if (result == 0)
1212 abort ();
72c3833b 1213 return result;
ea8262b0 1214 }
23b2ce53
RS
1215 else if (GET_CODE (x) == MEM)
1216 {
1217 /* The only additional case we can do is MEM. */
b3694847 1218 int offset = 0;
23b2ce53
RS
1219 if (WORDS_BIG_ENDIAN)
1220 offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
1221 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
1222
1223 if (BYTES_BIG_ENDIAN)
1224 /* Adjust the address so that the address-after-the-data
1225 is unchanged. */
1226 offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))
1227 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
1228
f4ef873c 1229 return adjust_address (x, mode, offset);
23b2ce53 1230 }
e9a25f70
JL
1231 else if (GET_CODE (x) == ADDRESSOF)
1232 return gen_lowpart (mode, force_reg (GET_MODE (x), x));
23b2ce53
RS
1233 else
1234 abort ();
1235}
1236
750c9258 1237/* Like `gen_lowpart', but refer to the most significant part.
ccba022b
RS
1238 This is used to access the imaginary part of a complex number. */
1239
1240rtx
1241gen_highpart (mode, x)
1242 enum machine_mode mode;
b3694847 1243 rtx x;
ccba022b 1244{
ddef6bc7 1245 unsigned int msize = GET_MODE_SIZE (mode);
e0e08ac2 1246 rtx result;
ddef6bc7 1247
ccba022b
RS
1248 /* This case loses if X is a subreg. To catch bugs early,
1249 complain if an invalid MODE is used even in other cases. */
ddef6bc7
JJ
1250 if (msize > UNITS_PER_WORD
1251 && msize != GET_MODE_UNIT_SIZE (GET_MODE (x)))
ccba022b 1252 abort ();
ddef6bc7 1253
e0e08ac2
JH
1254 result = simplify_gen_subreg (mode, x, GET_MODE (x),
1255 subreg_highpart_offset (mode, GET_MODE (x)));
09482e0d
JW
1256
1257 /* simplify_gen_subreg is not guaranteed to return a valid operand for
1258 the target if we have a MEM. gen_highpart must return a valid operand,
1259 emitting code if necessary to do so. */
13b8c631 1260 if (result != NULL_RTX && GET_CODE (result) == MEM)
09482e0d
JW
1261 result = validize_mem (result);
1262
e0e08ac2
JH
1263 if (!result)
1264 abort ();
1265 return result;
1266}
5222e470
JH
1267
1268/* Like gen_highpart_mode, but accept mode of EXP operand in case EXP can
1269 be VOIDmode constant. */
1270rtx
1271gen_highpart_mode (outermode, innermode, exp)
68252e27
KH
1272 enum machine_mode outermode, innermode;
1273 rtx exp;
5222e470
JH
1274{
1275 if (GET_MODE (exp) != VOIDmode)
1276 {
1277 if (GET_MODE (exp) != innermode)
1278 abort ();
1279 return gen_highpart (outermode, exp);
1280 }
1281 return simplify_gen_subreg (outermode, exp, innermode,
1282 subreg_highpart_offset (outermode, innermode));
1283}
68252e27 1284
e0e08ac2
JH
1285/* Return offset in bytes to get OUTERMODE low part
1286 of the value in mode INNERMODE stored in memory in target format. */
8698cce3 1287
e0e08ac2
JH
1288unsigned int
1289subreg_lowpart_offset (outermode, innermode)
1290 enum machine_mode outermode, innermode;
1291{
1292 unsigned int offset = 0;
1293 int difference = (GET_MODE_SIZE (innermode) - GET_MODE_SIZE (outermode));
8698cce3 1294
e0e08ac2 1295 if (difference > 0)
ccba022b 1296 {
e0e08ac2
JH
1297 if (WORDS_BIG_ENDIAN)
1298 offset += (difference / UNITS_PER_WORD) * UNITS_PER_WORD;
1299 if (BYTES_BIG_ENDIAN)
1300 offset += difference % UNITS_PER_WORD;
ccba022b 1301 }
ddef6bc7 1302
e0e08ac2 1303 return offset;
ccba022b 1304}
eea50aa0 1305
e0e08ac2
JH
1306/* Return offset in bytes to get OUTERMODE high part
1307 of the value in mode INNERMODE stored in memory in target format. */
1308unsigned int
1309subreg_highpart_offset (outermode, innermode)
eea50aa0 1310 enum machine_mode outermode, innermode;
eea50aa0
JH
1311{
1312 unsigned int offset = 0;
1313 int difference = (GET_MODE_SIZE (innermode) - GET_MODE_SIZE (outermode));
1314
e0e08ac2 1315 if (GET_MODE_SIZE (innermode) < GET_MODE_SIZE (outermode))
68252e27 1316 abort ();
e0e08ac2 1317
eea50aa0
JH
1318 if (difference > 0)
1319 {
e0e08ac2 1320 if (! WORDS_BIG_ENDIAN)
eea50aa0 1321 offset += (difference / UNITS_PER_WORD) * UNITS_PER_WORD;
e0e08ac2 1322 if (! BYTES_BIG_ENDIAN)
eea50aa0
JH
1323 offset += difference % UNITS_PER_WORD;
1324 }
1325
e0e08ac2 1326 return offset;
eea50aa0 1327}
ccba022b 1328
23b2ce53
RS
1329/* Return 1 iff X, assumed to be a SUBREG,
1330 refers to the least significant part of its containing reg.
1331 If X is not a SUBREG, always return 1 (it is its own low part!). */
1332
1333int
1334subreg_lowpart_p (x)
1335 rtx x;
1336{
1337 if (GET_CODE (x) != SUBREG)
1338 return 1;
a3a03040
RK
1339 else if (GET_MODE (SUBREG_REG (x)) == VOIDmode)
1340 return 0;
23b2ce53 1341
e0e08ac2
JH
1342 return (subreg_lowpart_offset (GET_MODE (x), GET_MODE (SUBREG_REG (x)))
1343 == SUBREG_BYTE (x));
23b2ce53
RS
1344}
1345\f
23b2ce53 1346
ddef6bc7
JJ
1347/* Helper routine for all the constant cases of operand_subword.
1348 Some places invoke this directly. */
23b2ce53
RS
1349
1350rtx
ddef6bc7 1351constant_subword (op, offset, mode)
23b2ce53 1352 rtx op;
ddef6bc7 1353 int offset;
23b2ce53
RS
1354 enum machine_mode mode;
1355{
906c4e36 1356 int size_ratio = HOST_BITS_PER_WIDE_INT / BITS_PER_WORD;
ddef6bc7 1357 HOST_WIDE_INT val;
23b2ce53
RS
1358
1359 /* If OP is already an integer word, return it. */
1360 if (GET_MODE_CLASS (mode) == MODE_INT
1361 && GET_MODE_SIZE (mode) == UNITS_PER_WORD)
1362 return op;
1363
5495cc55
RH
1364 /* The output is some bits, the width of the target machine's word.
1365 A wider-word host can surely hold them in a CONST_INT. A narrower-word
1366 host can't. */
9847c2f6 1367 if (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
1632afca 1368 && GET_MODE_CLASS (mode) == MODE_FLOAT
7677ffa4 1369 && GET_MODE_BITSIZE (mode) == 64
1632afca
RS
1370 && GET_CODE (op) == CONST_DOUBLE)
1371 {
9847c2f6 1372 long k[2];
1632afca
RS
1373 REAL_VALUE_TYPE rv;
1374
1375 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1376 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
7677ffa4 1377
9847c2f6 1378 /* We handle 32-bit and >= 64-bit words here. Note that the order in
7677ffa4 1379 which the words are written depends on the word endianness.
7677ffa4 1380 ??? This is a potential portability problem and should
7cae975e
RH
1381 be fixed at some point.
1382
a1f300c0 1383 We must exercise caution with the sign bit. By definition there
7cae975e
RH
1384 are 32 significant bits in K; there may be more in a HOST_WIDE_INT.
1385 Consider a host with a 32-bit long and a 64-bit HOST_WIDE_INT.
1386 So we explicitly mask and sign-extend as necessary. */
9847c2f6 1387 if (BITS_PER_WORD == 32)
7cae975e 1388 {
ddef6bc7 1389 val = k[offset];
7cae975e
RH
1390 val = ((val & 0xffffffff) ^ 0x80000000) - 0x80000000;
1391 return GEN_INT (val);
1392 }
1393#if HOST_BITS_PER_WIDE_INT >= 64
ddef6bc7 1394 else if (BITS_PER_WORD >= 64 && offset == 0)
7cae975e
RH
1395 {
1396 val = k[! WORDS_BIG_ENDIAN];
1397 val = (((val & 0xffffffff) ^ 0x80000000) - 0x80000000) << 32;
1398 val |= (HOST_WIDE_INT) k[WORDS_BIG_ENDIAN] & 0xffffffff;
1399 return GEN_INT (val);
1400 }
9847c2f6 1401#endif
47b34d40
JW
1402 else if (BITS_PER_WORD == 16)
1403 {
ddef6bc7
JJ
1404 val = k[offset >> 1];
1405 if ((offset & 1) == ! WORDS_BIG_ENDIAN)
7cae975e 1406 val >>= 16;
73de376f 1407 val = ((val & 0xffff) ^ 0x8000) - 0x8000;
7cae975e 1408 return GEN_INT (val);
47b34d40 1409 }
7677ffa4
RK
1410 else
1411 abort ();
1632afca 1412 }
a5559dbc
RE
1413 else if (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
1414 && GET_MODE_CLASS (mode) == MODE_FLOAT
1415 && GET_MODE_BITSIZE (mode) > 64
1416 && GET_CODE (op) == CONST_DOUBLE)
5495cc55
RH
1417 {
1418 long k[4];
1419 REAL_VALUE_TYPE rv;
a5559dbc 1420
5495cc55
RH
1421 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1422 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
a5559dbc 1423
5495cc55
RH
1424 if (BITS_PER_WORD == 32)
1425 {
ddef6bc7 1426 val = k[offset];
5495cc55
RH
1427 val = ((val & 0xffffffff) ^ 0x80000000) - 0x80000000;
1428 return GEN_INT (val);
1429 }
1430#if HOST_BITS_PER_WIDE_INT >= 64
ddef6bc7 1431 else if (BITS_PER_WORD >= 64 && offset <= 1)
5495cc55 1432 {
ddef6bc7 1433 val = k[offset * 2 + ! WORDS_BIG_ENDIAN];
5495cc55 1434 val = (((val & 0xffffffff) ^ 0x80000000) - 0x80000000) << 32;
ddef6bc7 1435 val |= (HOST_WIDE_INT) k[offset * 2 + WORDS_BIG_ENDIAN] & 0xffffffff;
5495cc55
RH
1436 return GEN_INT (val);
1437 }
1438#endif
1439 else
1440 abort ();
1441 }
23b2ce53
RS
1442
1443 /* Single word float is a little harder, since single- and double-word
1444 values often do not have the same high-order bits. We have already
1445 verified that we want the only defined word of the single-word value. */
9847c2f6 1446 if (GET_MODE_CLASS (mode) == MODE_FLOAT
7677ffa4 1447 && GET_MODE_BITSIZE (mode) == 32
1632afca
RS
1448 && GET_CODE (op) == CONST_DOUBLE)
1449 {
9847c2f6 1450 long l;
1632afca
RS
1451 REAL_VALUE_TYPE rv;
1452
1453 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1454 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
aa2ae679 1455
7cae975e
RH
1456 /* Sign extend from known 32-bit value to HOST_WIDE_INT. */
1457 val = l;
1458 val = ((val & 0xffffffff) ^ 0x80000000) - 0x80000000;
b5a3eb84 1459
aa2ae679
JL
1460 if (BITS_PER_WORD == 16)
1461 {
ddef6bc7 1462 if ((offset & 1) == ! WORDS_BIG_ENDIAN)
7cae975e 1463 val >>= 16;
73de376f 1464 val = ((val & 0xffff) ^ 0x8000) - 0x8000;
aa2ae679 1465 }
7cae975e
RH
1466
1467 return GEN_INT (val);
1632afca 1468 }
750c9258 1469
23b2ce53
RS
1470 /* The only remaining cases that we can handle are integers.
1471 Convert to proper endianness now since these cases need it.
750c9258 1472 At this point, offset == 0 means the low-order word.
23b2ce53 1473
2d4f57f8
RK
1474 We do not want to handle the case when BITS_PER_WORD <= HOST_BITS_PER_INT
1475 in general. However, if OP is (const_int 0), we can just return
1476 it for any word. */
1477
1478 if (op == const0_rtx)
1479 return op;
23b2ce53
RS
1480
1481 if (GET_MODE_CLASS (mode) != MODE_INT
2d4f57f8 1482 || (GET_CODE (op) != CONST_INT && GET_CODE (op) != CONST_DOUBLE)
0cf214a0 1483 || BITS_PER_WORD > HOST_BITS_PER_WIDE_INT)
23b2ce53
RS
1484 return 0;
1485
1486 if (WORDS_BIG_ENDIAN)
ddef6bc7 1487 offset = GET_MODE_SIZE (mode) / UNITS_PER_WORD - 1 - offset;
23b2ce53
RS
1488
1489 /* Find out which word on the host machine this value is in and get
1490 it from the constant. */
ddef6bc7 1491 val = (offset / size_ratio == 0
23b2ce53
RS
1492 ? (GET_CODE (op) == CONST_INT ? INTVAL (op) : CONST_DOUBLE_LOW (op))
1493 : (GET_CODE (op) == CONST_INT
1494 ? (INTVAL (op) < 0 ? ~0 : 0) : CONST_DOUBLE_HIGH (op)));
1495
3f518020 1496 /* Get the value we want into the low bits of val. */
906c4e36 1497 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT)
ddef6bc7 1498 val = ((val >> ((offset % size_ratio) * BITS_PER_WORD)));
3f518020 1499
7e4ce834 1500 val = trunc_int_for_mode (val, word_mode);
23b2ce53 1501
906c4e36 1502 return GEN_INT (val);
23b2ce53
RS
1503}
1504
ddef6bc7
JJ
1505/* Return subword OFFSET of operand OP.
1506 The word number, OFFSET, is interpreted as the word number starting
1507 at the low-order address. OFFSET 0 is the low-order word if not
1508 WORDS_BIG_ENDIAN, otherwise it is the high-order word.
1509
1510 If we cannot extract the required word, we return zero. Otherwise,
1511 an rtx corresponding to the requested word will be returned.
1512
1513 VALIDATE_ADDRESS is nonzero if the address should be validated. Before
1514 reload has completed, a valid address will always be returned. After
1515 reload, if a valid address cannot be returned, we return zero.
1516
1517 If VALIDATE_ADDRESS is zero, we simply form the required address; validating
1518 it is the responsibility of the caller.
1519
1520 MODE is the mode of OP in case it is a CONST_INT.
1521
1522 ??? This is still rather broken for some cases. The problem for the
1523 moment is that all callers of this thing provide no 'goal mode' to
1524 tell us to work with. This exists because all callers were written
0631e0bf
JH
1525 in a word based SUBREG world.
1526 Now use of this function can be deprecated by simplify_subreg in most
1527 cases.
1528 */
ddef6bc7
JJ
1529
1530rtx
1531operand_subword (op, offset, validate_address, mode)
1532 rtx op;
1533 unsigned int offset;
1534 int validate_address;
1535 enum machine_mode mode;
1536{
1537 if (mode == VOIDmode)
1538 mode = GET_MODE (op);
1539
1540 if (mode == VOIDmode)
1541 abort ();
1542
30f7a378 1543 /* If OP is narrower than a word, fail. */
ddef6bc7
JJ
1544 if (mode != BLKmode
1545 && (GET_MODE_SIZE (mode) < UNITS_PER_WORD))
1546 return 0;
1547
30f7a378 1548 /* If we want a word outside OP, return zero. */
ddef6bc7
JJ
1549 if (mode != BLKmode
1550 && (offset + 1) * UNITS_PER_WORD > GET_MODE_SIZE (mode))
1551 return const0_rtx;
1552
ddef6bc7
JJ
1553 /* Form a new MEM at the requested address. */
1554 if (GET_CODE (op) == MEM)
1555 {
f1ec5147 1556 rtx new = adjust_address_nv (op, word_mode, offset * UNITS_PER_WORD);
ddef6bc7 1557
f1ec5147
RK
1558 if (! validate_address)
1559 return new;
1560
1561 else if (reload_completed)
ddef6bc7 1562 {
f1ec5147
RK
1563 if (! strict_memory_address_p (word_mode, XEXP (new, 0)))
1564 return 0;
ddef6bc7 1565 }
f1ec5147
RK
1566 else
1567 return replace_equiv_address (new, XEXP (new, 0));
ddef6bc7
JJ
1568 }
1569
0631e0bf
JH
1570 /* Rest can be handled by simplify_subreg. */
1571 return simplify_gen_subreg (word_mode, op, mode, (offset * UNITS_PER_WORD));
ddef6bc7
JJ
1572}
1573
23b2ce53
RS
1574/* Similar to `operand_subword', but never return 0. If we can't extract
1575 the required subword, put OP into a register and try again. If that fails,
750c9258 1576 abort. We always validate the address in this case.
23b2ce53
RS
1577
1578 MODE is the mode of OP, in case it is CONST_INT. */
1579
1580rtx
ddef6bc7 1581operand_subword_force (op, offset, mode)
23b2ce53 1582 rtx op;
ddef6bc7 1583 unsigned int offset;
23b2ce53
RS
1584 enum machine_mode mode;
1585{
ddef6bc7 1586 rtx result = operand_subword (op, offset, 1, mode);
23b2ce53
RS
1587
1588 if (result)
1589 return result;
1590
1591 if (mode != BLKmode && mode != VOIDmode)
77e6b0eb
JC
1592 {
1593 /* If this is a register which can not be accessed by words, copy it
1594 to a pseudo register. */
1595 if (GET_CODE (op) == REG)
1596 op = copy_to_reg (op);
1597 else
1598 op = force_reg (mode, op);
1599 }
23b2ce53 1600
ddef6bc7 1601 result = operand_subword (op, offset, 1, mode);
23b2ce53
RS
1602 if (result == 0)
1603 abort ();
1604
1605 return result;
1606}
1607\f
1608/* Given a compare instruction, swap the operands.
1609 A test instruction is changed into a compare of 0 against the operand. */
1610
1611void
1612reverse_comparison (insn)
1613 rtx insn;
1614{
1615 rtx body = PATTERN (insn);
1616 rtx comp;
1617
1618 if (GET_CODE (body) == SET)
1619 comp = SET_SRC (body);
1620 else
1621 comp = SET_SRC (XVECEXP (body, 0, 0));
1622
1623 if (GET_CODE (comp) == COMPARE)
1624 {
1625 rtx op0 = XEXP (comp, 0);
1626 rtx op1 = XEXP (comp, 1);
1627 XEXP (comp, 0) = op1;
1628 XEXP (comp, 1) = op0;
1629 }
1630 else
1631 {
c5c76735
JL
1632 rtx new = gen_rtx_COMPARE (VOIDmode,
1633 CONST0_RTX (GET_MODE (comp)), comp);
23b2ce53
RS
1634 if (GET_CODE (body) == SET)
1635 SET_SRC (body) = new;
1636 else
1637 SET_SRC (XVECEXP (body, 0, 0)) = new;
1638 }
1639}
1640\f
998d7deb
RH
1641/* Within a MEM_EXPR, we care about either (1) a component ref of a decl,
1642 or (2) a component ref of something variable. Represent the later with
1643 a NULL expression. */
1644
1645static tree
1646component_ref_for_mem_expr (ref)
1647 tree ref;
1648{
1649 tree inner = TREE_OPERAND (ref, 0);
1650
1651 if (TREE_CODE (inner) == COMPONENT_REF)
1652 inner = component_ref_for_mem_expr (inner);
c56e3582
RK
1653 else
1654 {
1655 tree placeholder_ptr = 0;
1656
1657 /* Now remove any conversions: they don't change what the underlying
1658 object is. Likewise for SAVE_EXPR. Also handle PLACEHOLDER_EXPR. */
1659 while (TREE_CODE (inner) == NOP_EXPR || TREE_CODE (inner) == CONVERT_EXPR
1660 || TREE_CODE (inner) == NON_LVALUE_EXPR
1661 || TREE_CODE (inner) == VIEW_CONVERT_EXPR
1662 || TREE_CODE (inner) == SAVE_EXPR
1663 || TREE_CODE (inner) == PLACEHOLDER_EXPR)
68252e27
KH
1664 if (TREE_CODE (inner) == PLACEHOLDER_EXPR)
1665 inner = find_placeholder (inner, &placeholder_ptr);
1666 else
1667 inner = TREE_OPERAND (inner, 0);
c56e3582
RK
1668
1669 if (! DECL_P (inner))
1670 inner = NULL_TREE;
1671 }
998d7deb
RH
1672
1673 if (inner == TREE_OPERAND (ref, 0))
1674 return ref;
1675 else
c56e3582
RK
1676 return build (COMPONENT_REF, TREE_TYPE (ref), inner,
1677 TREE_OPERAND (ref, 1));
998d7deb 1678}
173b24b9
RK
1679
1680/* Given REF, a MEM, and T, either the type of X or the expression
1681 corresponding to REF, set the memory attributes. OBJECTP is nonzero
1682 if we are making a new object of this type. */
1683
1684void
1685set_mem_attributes (ref, t, objectp)
1686 rtx ref;
1687 tree t;
1688 int objectp;
1689{
8ac61af7 1690 HOST_WIDE_INT alias = MEM_ALIAS_SET (ref);
998d7deb 1691 tree expr = MEM_EXPR (ref);
8ac61af7
RK
1692 rtx offset = MEM_OFFSET (ref);
1693 rtx size = MEM_SIZE (ref);
1694 unsigned int align = MEM_ALIGN (ref);
173b24b9
RK
1695 tree type;
1696
1697 /* It can happen that type_for_mode was given a mode for which there
1698 is no language-level type. In which case it returns NULL, which
1699 we can see here. */
1700 if (t == NULL_TREE)
1701 return;
1702
1703 type = TYPE_P (t) ? t : TREE_TYPE (t);
1704
173b24b9
RK
1705 /* If we have already set DECL_RTL = ref, get_alias_set will get the
1706 wrong answer, as it assumes that DECL_RTL already has the right alias
1707 info. Callers should not set DECL_RTL until after the call to
1708 set_mem_attributes. */
1709 if (DECL_P (t) && ref == DECL_RTL_IF_SET (t))
1710 abort ();
1711
738cc472 1712 /* Get the alias set from the expression or type (perhaps using a
8ac61af7
RK
1713 front-end routine) and use it. */
1714 alias = get_alias_set (t);
173b24b9
RK
1715
1716 MEM_VOLATILE_P (ref) = TYPE_VOLATILE (type);
1717 MEM_IN_STRUCT_P (ref) = AGGREGATE_TYPE_P (type);
03bf2c23 1718 RTX_UNCHANGING_P (ref)
1285011e
RK
1719 |= ((lang_hooks.honor_readonly
1720 && (TYPE_READONLY (type) || TREE_READONLY (t)))
1721 || (! TYPE_P (t) && TREE_CONSTANT (t)));
173b24b9 1722
8ac61af7
RK
1723 /* If we are making an object of this type, or if this is a DECL, we know
1724 that it is a scalar if the type is not an aggregate. */
1725 if ((objectp || DECL_P (t)) && ! AGGREGATE_TYPE_P (type))
173b24b9
RK
1726 MEM_SCALAR_P (ref) = 1;
1727
c3d32120
RK
1728 /* We can set the alignment from the type if we are making an object,
1729 this is an INDIRECT_REF, or if TYPE_ALIGN_OK. */
1730 if (objectp || TREE_CODE (t) == INDIRECT_REF || TYPE_ALIGN_OK (type))
1731 align = MAX (align, TYPE_ALIGN (type));
40c0668b 1732
738cc472
RK
1733 /* If the size is known, we can set that. */
1734 if (TYPE_SIZE_UNIT (type) && host_integerp (TYPE_SIZE_UNIT (type), 1))
8ac61af7 1735 size = GEN_INT (tree_low_cst (TYPE_SIZE_UNIT (type), 1));
738cc472 1736
80965c18
RK
1737 /* If T is not a type, we may be able to deduce some more information about
1738 the expression. */
1739 if (! TYPE_P (t))
8ac61af7
RK
1740 {
1741 maybe_set_unchanging (ref, t);
1742 if (TREE_THIS_VOLATILE (t))
1743 MEM_VOLATILE_P (ref) = 1;
173b24b9 1744
c56e3582
RK
1745 /* Now remove any conversions: they don't change what the underlying
1746 object is. Likewise for SAVE_EXPR. */
8ac61af7 1747 while (TREE_CODE (t) == NOP_EXPR || TREE_CODE (t) == CONVERT_EXPR
c56e3582
RK
1748 || TREE_CODE (t) == NON_LVALUE_EXPR
1749 || TREE_CODE (t) == VIEW_CONVERT_EXPR
1750 || TREE_CODE (t) == SAVE_EXPR)
8ac61af7
RK
1751 t = TREE_OPERAND (t, 0);
1752
10b76d73
RK
1753 /* If this expression can't be addressed (e.g., it contains a reference
1754 to a non-addressable field), show we don't change its alias set. */
1755 if (! can_address_p (t))
1756 MEM_KEEP_ALIAS_SET_P (ref) = 1;
1757
8ac61af7
RK
1758 /* If this is a decl, set the attributes of the MEM from it. */
1759 if (DECL_P (t))
1760 {
998d7deb
RH
1761 expr = t;
1762 offset = const0_rtx;
8ac61af7
RK
1763 size = (DECL_SIZE_UNIT (t)
1764 && host_integerp (DECL_SIZE_UNIT (t), 1)
1765 ? GEN_INT (tree_low_cst (DECL_SIZE_UNIT (t), 1)) : 0);
68252e27 1766 align = DECL_ALIGN (t);
8ac61af7
RK
1767 }
1768
40c0668b 1769 /* If this is a constant, we know the alignment. */
9ddfb1a7
RK
1770 else if (TREE_CODE_CLASS (TREE_CODE (t)) == 'c')
1771 {
1772 align = TYPE_ALIGN (type);
1773#ifdef CONSTANT_ALIGNMENT
1774 align = CONSTANT_ALIGNMENT (t, align);
1775#endif
1776 }
998d7deb
RH
1777
1778 /* If this is a field reference and not a bit-field, record it. */
1779 /* ??? There is some information that can be gleened from bit-fields,
1780 such as the word offset in the structure that might be modified.
1781 But skip it for now. */
1782 else if (TREE_CODE (t) == COMPONENT_REF
1783 && ! DECL_BIT_FIELD (TREE_OPERAND (t, 1)))
1784 {
1785 expr = component_ref_for_mem_expr (t);
1786 offset = const0_rtx;
1787 /* ??? Any reason the field size would be different than
1788 the size we got from the type? */
1789 }
1790
1791 /* If this is an array reference, look for an outer field reference. */
1792 else if (TREE_CODE (t) == ARRAY_REF)
1793 {
1794 tree off_tree = size_zero_node;
1795
1796 do
1797 {
1798 off_tree
1799 = fold (build (PLUS_EXPR, sizetype,
1800 fold (build (MULT_EXPR, sizetype,
1801 TREE_OPERAND (t, 1),
1802 TYPE_SIZE_UNIT (TREE_TYPE (t)))),
1803 off_tree));
1804 t = TREE_OPERAND (t, 0);
1805 }
1806 while (TREE_CODE (t) == ARRAY_REF);
1807
c67a1cf6
RH
1808 if (DECL_P (t))
1809 {
1810 expr = t;
40cb04f1 1811 offset = NULL;
c67a1cf6 1812 if (host_integerp (off_tree, 1))
40cb04f1
RH
1813 {
1814 HOST_WIDE_INT ioff = tree_low_cst (off_tree, 1);
1815 HOST_WIDE_INT aoff = (ioff & -ioff) * BITS_PER_UNIT;
1816 align = DECL_ALIGN (t);
1817 if (aoff && aoff < align)
1818 align = aoff;
1819 offset = GEN_INT (ioff);
1820 }
c67a1cf6
RH
1821 }
1822 else if (TREE_CODE (t) == COMPONENT_REF)
998d7deb
RH
1823 {
1824 expr = component_ref_for_mem_expr (t);
1825 if (host_integerp (off_tree, 1))
1826 offset = GEN_INT (tree_low_cst (off_tree, 1));
1827 /* ??? Any reason the field size would be different than
1828 the size we got from the type? */
1829 }
c67a1cf6
RH
1830 else if (flag_argument_noalias > 1
1831 && TREE_CODE (t) == INDIRECT_REF
1832 && TREE_CODE (TREE_OPERAND (t, 0)) == PARM_DECL)
1833 {
1834 expr = t;
1835 offset = NULL;
1836 }
1837 }
1838
1839 /* If this is a Fortran indirect argument reference, record the
1840 parameter decl. */
1841 else if (flag_argument_noalias > 1
1842 && TREE_CODE (t) == INDIRECT_REF
1843 && TREE_CODE (TREE_OPERAND (t, 0)) == PARM_DECL)
1844 {
1845 expr = t;
1846 offset = NULL;
998d7deb 1847 }
8ac61af7
RK
1848 }
1849
1850 /* Now set the attributes we computed above. */
10b76d73 1851 MEM_ATTRS (ref)
998d7deb 1852 = get_mem_attrs (alias, expr, offset, size, align, GET_MODE (ref));
8ac61af7
RK
1853
1854 /* If this is already known to be a scalar or aggregate, we are done. */
1855 if (MEM_IN_STRUCT_P (ref) || MEM_SCALAR_P (ref))
738cc472
RK
1856 return;
1857
8ac61af7
RK
1858 /* If it is a reference into an aggregate, this is part of an aggregate.
1859 Otherwise we don't know. */
173b24b9
RK
1860 else if (TREE_CODE (t) == COMPONENT_REF || TREE_CODE (t) == ARRAY_REF
1861 || TREE_CODE (t) == ARRAY_RANGE_REF
1862 || TREE_CODE (t) == BIT_FIELD_REF)
1863 MEM_IN_STRUCT_P (ref) = 1;
1864}
1865
1866/* Set the alias set of MEM to SET. */
1867
1868void
1869set_mem_alias_set (mem, set)
1870 rtx mem;
1871 HOST_WIDE_INT set;
1872{
68252e27 1873#ifdef ENABLE_CHECKING
173b24b9
RK
1874 /* If the new and old alias sets don't conflict, something is wrong. */
1875 if (!alias_sets_conflict_p (set, MEM_ALIAS_SET (mem)))
1876 abort ();
173b24b9
RK
1877#endif
1878
998d7deb 1879 MEM_ATTRS (mem) = get_mem_attrs (set, MEM_EXPR (mem), MEM_OFFSET (mem),
10b76d73
RK
1880 MEM_SIZE (mem), MEM_ALIGN (mem),
1881 GET_MODE (mem));
173b24b9 1882}
738cc472 1883
d022d93e 1884/* Set the alignment of MEM to ALIGN bits. */
738cc472
RK
1885
1886void
1887set_mem_align (mem, align)
1888 rtx mem;
1889 unsigned int align;
1890{
998d7deb 1891 MEM_ATTRS (mem) = get_mem_attrs (MEM_ALIAS_SET (mem), MEM_EXPR (mem),
10b76d73
RK
1892 MEM_OFFSET (mem), MEM_SIZE (mem), align,
1893 GET_MODE (mem));
738cc472 1894}
1285011e 1895
998d7deb 1896/* Set the expr for MEM to EXPR. */
1285011e
RK
1897
1898void
998d7deb 1899set_mem_expr (mem, expr)
1285011e 1900 rtx mem;
998d7deb 1901 tree expr;
1285011e
RK
1902{
1903 MEM_ATTRS (mem)
998d7deb 1904 = get_mem_attrs (MEM_ALIAS_SET (mem), expr, MEM_OFFSET (mem),
1285011e
RK
1905 MEM_SIZE (mem), MEM_ALIGN (mem), GET_MODE (mem));
1906}
998d7deb
RH
1907
1908/* Set the offset of MEM to OFFSET. */
1909
1910void
1911set_mem_offset (mem, offset)
1912 rtx mem, offset;
1913{
1914 MEM_ATTRS (mem) = get_mem_attrs (MEM_ALIAS_SET (mem), MEM_EXPR (mem),
1915 offset, MEM_SIZE (mem), MEM_ALIGN (mem),
1916 GET_MODE (mem));
1917}
173b24b9 1918\f
738cc472
RK
1919/* Return a memory reference like MEMREF, but with its mode changed to MODE
1920 and its address changed to ADDR. (VOIDmode means don't change the mode.
1921 NULL for ADDR means don't change the address.) VALIDATE is nonzero if the
1922 returned memory location is required to be valid. The memory
1923 attributes are not changed. */
23b2ce53 1924
738cc472 1925static rtx
f1ec5147 1926change_address_1 (memref, mode, addr, validate)
23b2ce53
RS
1927 rtx memref;
1928 enum machine_mode mode;
1929 rtx addr;
f1ec5147 1930 int validate;
23b2ce53
RS
1931{
1932 rtx new;
1933
1934 if (GET_CODE (memref) != MEM)
1935 abort ();
1936 if (mode == VOIDmode)
1937 mode = GET_MODE (memref);
1938 if (addr == 0)
1939 addr = XEXP (memref, 0);
1940
f1ec5147 1941 if (validate)
23b2ce53 1942 {
f1ec5147
RK
1943 if (reload_in_progress || reload_completed)
1944 {
1945 if (! memory_address_p (mode, addr))
1946 abort ();
1947 }
1948 else
1949 addr = memory_address (mode, addr);
23b2ce53 1950 }
750c9258 1951
9b04c6a8
RK
1952 if (rtx_equal_p (addr, XEXP (memref, 0)) && mode == GET_MODE (memref))
1953 return memref;
1954
3b80f6ca 1955 new = gen_rtx_MEM (mode, addr);
c6df88cb 1956 MEM_COPY_ATTRIBUTES (new, memref);
23b2ce53
RS
1957 return new;
1958}
792760b9 1959
738cc472
RK
1960/* Like change_address_1 with VALIDATE nonzero, but we are not saying in what
1961 way we are changing MEMREF, so we only preserve the alias set. */
f4ef873c
RK
1962
1963rtx
738cc472 1964change_address (memref, mode, addr)
f4ef873c
RK
1965 rtx memref;
1966 enum machine_mode mode;
738cc472 1967 rtx addr;
f4ef873c 1968{
738cc472
RK
1969 rtx new = change_address_1 (memref, mode, addr, 1);
1970 enum machine_mode mmode = GET_MODE (new);
c2f7bcc3 1971
738cc472
RK
1972 MEM_ATTRS (new)
1973 = get_mem_attrs (MEM_ALIAS_SET (memref), 0, 0,
1974 mmode == BLKmode ? 0 : GEN_INT (GET_MODE_SIZE (mmode)),
a06ef755
RK
1975 (mmode == BLKmode ? BITS_PER_UNIT
1976 : GET_MODE_ALIGNMENT (mmode)),
10b76d73 1977 mmode);
823e3574 1978
738cc472 1979 return new;
f4ef873c 1980}
792760b9 1981
738cc472
RK
1982/* Return a memory reference like MEMREF, but with its mode changed
1983 to MODE and its address offset by OFFSET bytes. If VALIDATE is
630036c6
JJ
1984 nonzero, the memory address is forced to be valid.
1985 If ADJUST is zero, OFFSET is only used to update MEM_ATTRS
1986 and caller is responsible for adjusting MEMREF base register. */
f1ec5147
RK
1987
1988rtx
630036c6 1989adjust_address_1 (memref, mode, offset, validate, adjust)
f1ec5147
RK
1990 rtx memref;
1991 enum machine_mode mode;
1992 HOST_WIDE_INT offset;
630036c6 1993 int validate, adjust;
f1ec5147 1994{
823e3574 1995 rtx addr = XEXP (memref, 0);
738cc472
RK
1996 rtx new;
1997 rtx memoffset = MEM_OFFSET (memref);
10b76d73 1998 rtx size = 0;
738cc472 1999 unsigned int memalign = MEM_ALIGN (memref);
823e3574 2000
d14419e4 2001 /* ??? Prefer to create garbage instead of creating shared rtl.
4a78c787 2002 This may happen even if offset is non-zero -- consider
d14419e4
RH
2003 (plus (plus reg reg) const_int) -- so do this always. */
2004 addr = copy_rtx (addr);
2005
4a78c787
RH
2006 if (adjust)
2007 {
2008 /* If MEMREF is a LO_SUM and the offset is within the alignment of the
2009 object, we can merge it into the LO_SUM. */
2010 if (GET_MODE (memref) != BLKmode && GET_CODE (addr) == LO_SUM
2011 && offset >= 0
2012 && (unsigned HOST_WIDE_INT) offset
2013 < GET_MODE_ALIGNMENT (GET_MODE (memref)) / BITS_PER_UNIT)
2014 addr = gen_rtx_LO_SUM (Pmode, XEXP (addr, 0),
2015 plus_constant (XEXP (addr, 1), offset));
2016 else
2017 addr = plus_constant (addr, offset);
2018 }
823e3574 2019
738cc472
RK
2020 new = change_address_1 (memref, mode, addr, validate);
2021
2022 /* Compute the new values of the memory attributes due to this adjustment.
2023 We add the offsets and update the alignment. */
2024 if (memoffset)
2025 memoffset = GEN_INT (offset + INTVAL (memoffset));
2026
03bf2c23
RK
2027 /* Compute the new alignment by taking the MIN of the alignment and the
2028 lowest-order set bit in OFFSET, but don't change the alignment if OFFSET
2029 if zero. */
2030 if (offset != 0)
3bf1e984
RK
2031 memalign
2032 = MIN (memalign,
2033 (unsigned HOST_WIDE_INT) (offset & -offset) * BITS_PER_UNIT);
738cc472 2034
10b76d73 2035 /* We can compute the size in a number of ways. */
a06ef755
RK
2036 if (GET_MODE (new) != BLKmode)
2037 size = GEN_INT (GET_MODE_SIZE (GET_MODE (new)));
10b76d73
RK
2038 else if (MEM_SIZE (memref))
2039 size = plus_constant (MEM_SIZE (memref), -offset);
2040
998d7deb 2041 MEM_ATTRS (new) = get_mem_attrs (MEM_ALIAS_SET (memref), MEM_EXPR (memref),
10b76d73 2042 memoffset, size, memalign, GET_MODE (new));
738cc472
RK
2043
2044 /* At some point, we should validate that this offset is within the object,
2045 if all the appropriate values are known. */
2046 return new;
f1ec5147
RK
2047}
2048
630036c6
JJ
2049/* Return a memory reference like MEMREF, but with its mode changed
2050 to MODE and its address changed to ADDR, which is assumed to be
2051 MEMREF offseted by OFFSET bytes. If VALIDATE is
2052 nonzero, the memory address is forced to be valid. */
2053
2054rtx
2055adjust_automodify_address_1 (memref, mode, addr, offset, validate)
2056 rtx memref;
2057 enum machine_mode mode;
2058 rtx addr;
2059 HOST_WIDE_INT offset;
2060 int validate;
2061{
2062 memref = change_address_1 (memref, VOIDmode, addr, validate);
2063 return adjust_address_1 (memref, mode, offset, validate, 0);
2064}
2065
8ac61af7
RK
2066/* Return a memory reference like MEMREF, but whose address is changed by
2067 adding OFFSET, an RTX, to it. POW2 is the highest power of two factor
2068 known to be in OFFSET (possibly 1). */
0d4903b8
RK
2069
2070rtx
2071offset_address (memref, offset, pow2)
2072 rtx memref;
2073 rtx offset;
2074 HOST_WIDE_INT pow2;
2075{
e3c8ea67
RH
2076 rtx new, addr = XEXP (memref, 0);
2077
2078 new = simplify_gen_binary (PLUS, Pmode, addr, offset);
2079
68252e27 2080 /* At this point we don't know _why_ the address is invalid. It
e3c8ea67
RH
2081 could have secondary memory refereces, multiplies or anything.
2082
2083 However, if we did go and rearrange things, we can wind up not
2084 being able to recognize the magic around pic_offset_table_rtx.
2085 This stuff is fragile, and is yet another example of why it is
2086 bad to expose PIC machinery too early. */
2087 if (! memory_address_p (GET_MODE (memref), new)
2088 && GET_CODE (addr) == PLUS
2089 && XEXP (addr, 0) == pic_offset_table_rtx)
2090 {
2091 addr = force_reg (GET_MODE (addr), addr);
2092 new = simplify_gen_binary (PLUS, Pmode, addr, offset);
2093 }
2094
f6041ed8 2095 update_temp_slot_address (XEXP (memref, 0), new);
e3c8ea67 2096 new = change_address_1 (memref, VOIDmode, new, 1);
0d4903b8
RK
2097
2098 /* Update the alignment to reflect the offset. Reset the offset, which
2099 we don't know. */
2cc2d4bb
RK
2100 MEM_ATTRS (new)
2101 = get_mem_attrs (MEM_ALIAS_SET (memref), MEM_EXPR (memref), 0, 0,
2102 MIN (MEM_ALIGN (memref),
3bf1e984 2103 (unsigned HOST_WIDE_INT) pow2 * BITS_PER_UNIT),
2cc2d4bb 2104 GET_MODE (new));
0d4903b8
RK
2105 return new;
2106}
68252e27 2107
792760b9
RK
2108/* Return a memory reference like MEMREF, but with its address changed to
2109 ADDR. The caller is asserting that the actual piece of memory pointed
2110 to is the same, just the form of the address is being changed, such as
2111 by putting something into a register. */
2112
2113rtx
2114replace_equiv_address (memref, addr)
2115 rtx memref;
2116 rtx addr;
2117{
738cc472
RK
2118 /* change_address_1 copies the memory attribute structure without change
2119 and that's exactly what we want here. */
40c0668b 2120 update_temp_slot_address (XEXP (memref, 0), addr);
738cc472 2121 return change_address_1 (memref, VOIDmode, addr, 1);
792760b9 2122}
738cc472 2123
f1ec5147
RK
2124/* Likewise, but the reference is not required to be valid. */
2125
2126rtx
2127replace_equiv_address_nv (memref, addr)
2128 rtx memref;
2129 rtx addr;
2130{
f1ec5147
RK
2131 return change_address_1 (memref, VOIDmode, addr, 0);
2132}
e7dfe4bb
RH
2133
2134/* Return a memory reference like MEMREF, but with its mode widened to
2135 MODE and offset by OFFSET. This would be used by targets that e.g.
2136 cannot issue QImode memory operations and have to use SImode memory
2137 operations plus masking logic. */
2138
2139rtx
2140widen_memory_access (memref, mode, offset)
2141 rtx memref;
2142 enum machine_mode mode;
2143 HOST_WIDE_INT offset;
2144{
2145 rtx new = adjust_address_1 (memref, mode, offset, 1, 1);
2146 tree expr = MEM_EXPR (new);
2147 rtx memoffset = MEM_OFFSET (new);
2148 unsigned int size = GET_MODE_SIZE (mode);
2149
2150 /* If we don't know what offset we were at within the expression, then
2151 we can't know if we've overstepped the bounds. */
fa1591cb 2152 if (! memoffset)
e7dfe4bb
RH
2153 expr = NULL_TREE;
2154
2155 while (expr)
2156 {
2157 if (TREE_CODE (expr) == COMPONENT_REF)
2158 {
2159 tree field = TREE_OPERAND (expr, 1);
2160
2161 if (! DECL_SIZE_UNIT (field))
2162 {
2163 expr = NULL_TREE;
2164 break;
2165 }
2166
2167 /* Is the field at least as large as the access? If so, ok,
2168 otherwise strip back to the containing structure. */
03667700
RK
2169 if (TREE_CODE (DECL_SIZE_UNIT (field)) == INTEGER_CST
2170 && compare_tree_int (DECL_SIZE_UNIT (field), size) >= 0
e7dfe4bb
RH
2171 && INTVAL (memoffset) >= 0)
2172 break;
2173
2174 if (! host_integerp (DECL_FIELD_OFFSET (field), 1))
2175 {
2176 expr = NULL_TREE;
2177 break;
2178 }
2179
2180 expr = TREE_OPERAND (expr, 0);
2181 memoffset = (GEN_INT (INTVAL (memoffset)
2182 + tree_low_cst (DECL_FIELD_OFFSET (field), 1)
2183 + (tree_low_cst (DECL_FIELD_BIT_OFFSET (field), 1)
2184 / BITS_PER_UNIT)));
2185 }
2186 /* Similarly for the decl. */
2187 else if (DECL_P (expr)
2188 && DECL_SIZE_UNIT (expr)
45f79783 2189 && TREE_CODE (DECL_SIZE_UNIT (expr)) == INTEGER_CST
e7dfe4bb
RH
2190 && compare_tree_int (DECL_SIZE_UNIT (expr), size) >= 0
2191 && (! memoffset || INTVAL (memoffset) >= 0))
2192 break;
2193 else
2194 {
2195 /* The widened memory access overflows the expression, which means
2196 that it could alias another expression. Zap it. */
2197 expr = NULL_TREE;
2198 break;
2199 }
2200 }
2201
2202 if (! expr)
2203 memoffset = NULL_RTX;
2204
2205 /* The widened memory may alias other stuff, so zap the alias set. */
2206 /* ??? Maybe use get_alias_set on any remaining expression. */
2207
2208 MEM_ATTRS (new) = get_mem_attrs (0, expr, memoffset, GEN_INT (size),
2209 MEM_ALIGN (new), mode);
2210
2211 return new;
2212}
23b2ce53
RS
2213\f
2214/* Return a newly created CODE_LABEL rtx with a unique label number. */
2215
2216rtx
2217gen_label_rtx ()
2218{
0dc36574
ZW
2219 return gen_rtx_CODE_LABEL (VOIDmode, 0, NULL_RTX, NULL_RTX,
2220 NULL, label_num++, NULL);
23b2ce53
RS
2221}
2222\f
2223/* For procedure integration. */
2224
23b2ce53 2225/* Install new pointers to the first and last insns in the chain.
86fe05e0 2226 Also, set cur_insn_uid to one higher than the last in use.
23b2ce53
RS
2227 Used for an inline-procedure after copying the insn chain. */
2228
2229void
2230set_new_first_and_last_insn (first, last)
2231 rtx first, last;
2232{
86fe05e0
RK
2233 rtx insn;
2234
23b2ce53
RS
2235 first_insn = first;
2236 last_insn = last;
86fe05e0
RK
2237 cur_insn_uid = 0;
2238
2239 for (insn = first; insn; insn = NEXT_INSN (insn))
2240 cur_insn_uid = MAX (cur_insn_uid, INSN_UID (insn));
2241
2242 cur_insn_uid++;
23b2ce53
RS
2243}
2244
2245/* Set the range of label numbers found in the current function.
2246 This is used when belatedly compiling an inline function. */
2247
2248void
2249set_new_first_and_last_label_num (first, last)
2250 int first, last;
2251{
2252 base_label_num = label_num;
2253 first_label_num = first;
2254 last_label_num = last;
2255}
49ad7cfa
BS
2256
2257/* Set the last label number found in the current function.
2258 This is used when belatedly compiling an inline function. */
23b2ce53
RS
2259
2260void
49ad7cfa
BS
2261set_new_last_label_num (last)
2262 int last;
23b2ce53 2263{
49ad7cfa
BS
2264 base_label_num = label_num;
2265 last_label_num = last;
23b2ce53 2266}
49ad7cfa 2267\f
23b2ce53
RS
2268/* Restore all variables describing the current status from the structure *P.
2269 This is used after a nested function. */
2270
2271void
2272restore_emit_status (p)
272df862 2273 struct function *p ATTRIBUTE_UNUSED;
23b2ce53 2274{
457a2d9c 2275 last_label_num = 0;
23b2ce53
RS
2276}
2277\f
750c9258 2278/* Go through all the RTL insn bodies and copy any invalid shared
d1b81779 2279 structure. This routine should only be called once. */
23b2ce53
RS
2280
2281void
d1b81779
GK
2282unshare_all_rtl (fndecl, insn)
2283 tree fndecl;
2284 rtx insn;
23b2ce53 2285{
d1b81779 2286 tree decl;
23b2ce53 2287
d1b81779
GK
2288 /* Make sure that virtual parameters are not shared. */
2289 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
19e7881c 2290 SET_DECL_RTL (decl, copy_rtx_if_shared (DECL_RTL (decl)));
d1b81779 2291
5c6df058
AO
2292 /* Make sure that virtual stack slots are not shared. */
2293 unshare_all_decls (DECL_INITIAL (fndecl));
2294
d1b81779
GK
2295 /* Unshare just about everything else. */
2296 unshare_all_rtl_1 (insn);
750c9258 2297
23b2ce53
RS
2298 /* Make sure the addresses of stack slots found outside the insn chain
2299 (such as, in DECL_RTL of a variable) are not shared
2300 with the insn chain.
2301
2302 This special care is necessary when the stack slot MEM does not
2303 actually appear in the insn chain. If it does appear, its address
2304 is unshared from all else at that point. */
242b0ce6 2305 stack_slot_list = copy_rtx_if_shared (stack_slot_list);
23b2ce53
RS
2306}
2307
750c9258 2308/* Go through all the RTL insn bodies and copy any invalid shared
d1b81779
GK
2309 structure, again. This is a fairly expensive thing to do so it
2310 should be done sparingly. */
2311
2312void
2313unshare_all_rtl_again (insn)
2314 rtx insn;
2315{
2316 rtx p;
624c87aa
RE
2317 tree decl;
2318
d1b81779 2319 for (p = insn; p; p = NEXT_INSN (p))
2c3c49de 2320 if (INSN_P (p))
d1b81779
GK
2321 {
2322 reset_used_flags (PATTERN (p));
2323 reset_used_flags (REG_NOTES (p));
2324 reset_used_flags (LOG_LINKS (p));
2325 }
624c87aa 2326
2d4aecb3
AO
2327 /* Make sure that virtual stack slots are not shared. */
2328 reset_used_decls (DECL_INITIAL (cfun->decl));
2329
624c87aa
RE
2330 /* Make sure that virtual parameters are not shared. */
2331 for (decl = DECL_ARGUMENTS (cfun->decl); decl; decl = TREE_CHAIN (decl))
2332 reset_used_flags (DECL_RTL (decl));
2333
2334 reset_used_flags (stack_slot_list);
2335
2336 unshare_all_rtl (cfun->decl, insn);
d1b81779
GK
2337}
2338
2339/* Go through all the RTL insn bodies and copy any invalid shared structure.
2340 Assumes the mark bits are cleared at entry. */
2341
2342static void
2343unshare_all_rtl_1 (insn)
2344 rtx insn;
2345{
2346 for (; insn; insn = NEXT_INSN (insn))
2c3c49de 2347 if (INSN_P (insn))
d1b81779
GK
2348 {
2349 PATTERN (insn) = copy_rtx_if_shared (PATTERN (insn));
2350 REG_NOTES (insn) = copy_rtx_if_shared (REG_NOTES (insn));
2351 LOG_LINKS (insn) = copy_rtx_if_shared (LOG_LINKS (insn));
2352 }
2353}
2354
5c6df058
AO
2355/* Go through all virtual stack slots of a function and copy any
2356 shared structure. */
2357static void
2358unshare_all_decls (blk)
2359 tree blk;
2360{
2361 tree t;
2362
2363 /* Copy shared decls. */
2364 for (t = BLOCK_VARS (blk); t; t = TREE_CHAIN (t))
19e7881c
MM
2365 if (DECL_RTL_SET_P (t))
2366 SET_DECL_RTL (t, copy_rtx_if_shared (DECL_RTL (t)));
5c6df058
AO
2367
2368 /* Now process sub-blocks. */
2369 for (t = BLOCK_SUBBLOCKS (blk); t; t = TREE_CHAIN (t))
2370 unshare_all_decls (t);
2371}
2372
2d4aecb3 2373/* Go through all virtual stack slots of a function and mark them as
30f7a378 2374 not shared. */
2d4aecb3
AO
2375static void
2376reset_used_decls (blk)
2377 tree blk;
2378{
2379 tree t;
2380
2381 /* Mark decls. */
2382 for (t = BLOCK_VARS (blk); t; t = TREE_CHAIN (t))
19e7881c
MM
2383 if (DECL_RTL_SET_P (t))
2384 reset_used_flags (DECL_RTL (t));
2d4aecb3
AO
2385
2386 /* Now process sub-blocks. */
2387 for (t = BLOCK_SUBBLOCKS (blk); t; t = TREE_CHAIN (t))
2388 reset_used_decls (t);
2389}
2390
127c1ba5 2391/* Similar to `copy_rtx' except that if MAY_SHARE is present, it is
93fe8e92
RK
2392 placed in the result directly, rather than being copied. MAY_SHARE is
2393 either a MEM of an EXPR_LIST of MEMs. */
127c1ba5
RK
2394
2395rtx
2396copy_most_rtx (orig, may_share)
2397 rtx orig;
2398 rtx may_share;
2399{
2400 rtx copy;
2401 int i, j;
2402 RTX_CODE code;
2403 const char *format_ptr;
2404
93fe8e92
RK
2405 if (orig == may_share
2406 || (GET_CODE (may_share) == EXPR_LIST
2407 && in_expr_list_p (may_share, orig)))
127c1ba5
RK
2408 return orig;
2409
2410 code = GET_CODE (orig);
2411
2412 switch (code)
2413 {
2414 case REG:
2415 case QUEUED:
2416 case CONST_INT:
2417 case CONST_DOUBLE:
2418 case CONST_VECTOR:
2419 case SYMBOL_REF:
2420 case CODE_LABEL:
2421 case PC:
2422 case CC0:
2423 return orig;
2424 default:
2425 break;
2426 }
2427
2428 copy = rtx_alloc (code);
2429 PUT_MODE (copy, GET_MODE (orig));
2adc7f12
JJ
2430 RTX_FLAG (copy, in_struct) = RTX_FLAG (orig, in_struct);
2431 RTX_FLAG (copy, volatil) = RTX_FLAG (orig, volatil);
2432 RTX_FLAG (copy, unchanging) = RTX_FLAG (orig, unchanging);
2433 RTX_FLAG (copy, integrated) = RTX_FLAG (orig, integrated);
2434 RTX_FLAG (copy, frame_related) = RTX_FLAG (orig, frame_related);
127c1ba5
RK
2435
2436 format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
2437
2438 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
2439 {
2440 switch (*format_ptr++)
2441 {
2442 case 'e':
2443 XEXP (copy, i) = XEXP (orig, i);
2444 if (XEXP (orig, i) != NULL && XEXP (orig, i) != may_share)
2445 XEXP (copy, i) = copy_most_rtx (XEXP (orig, i), may_share);
2446 break;
2447
2448 case 'u':
2449 XEXP (copy, i) = XEXP (orig, i);
2450 break;
2451
2452 case 'E':
2453 case 'V':
2454 XVEC (copy, i) = XVEC (orig, i);
2455 if (XVEC (orig, i) != NULL)
2456 {
2457 XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
2458 for (j = 0; j < XVECLEN (copy, i); j++)
2459 XVECEXP (copy, i, j)
2460 = copy_most_rtx (XVECEXP (orig, i, j), may_share);
2461 }
2462 break;
2463
2464 case 'w':
2465 XWINT (copy, i) = XWINT (orig, i);
2466 break;
2467
2468 case 'n':
2469 case 'i':
2470 XINT (copy, i) = XINT (orig, i);
2471 break;
2472
2473 case 't':
2474 XTREE (copy, i) = XTREE (orig, i);
2475 break;
2476
2477 case 's':
2478 case 'S':
2479 XSTR (copy, i) = XSTR (orig, i);
2480 break;
2481
2482 case '0':
2483 /* Copy this through the wide int field; that's safest. */
2484 X0WINT (copy, i) = X0WINT (orig, i);
2485 break;
2486
2487 default:
2488 abort ();
2489 }
2490 }
2491 return copy;
2492}
2493
23b2ce53
RS
2494/* Mark ORIG as in use, and return a copy of it if it was already in use.
2495 Recursively does the same for subexpressions. */
2496
2497rtx
2498copy_rtx_if_shared (orig)
2499 rtx orig;
2500{
b3694847
SS
2501 rtx x = orig;
2502 int i;
2503 enum rtx_code code;
2504 const char *format_ptr;
23b2ce53
RS
2505 int copied = 0;
2506
2507 if (x == 0)
2508 return 0;
2509
2510 code = GET_CODE (x);
2511
2512 /* These types may be freely shared. */
2513
2514 switch (code)
2515 {
2516 case REG:
2517 case QUEUED:
2518 case CONST_INT:
2519 case CONST_DOUBLE:
69ef87e2 2520 case CONST_VECTOR:
23b2ce53
RS
2521 case SYMBOL_REF:
2522 case CODE_LABEL:
2523 case PC:
2524 case CC0:
2525 case SCRATCH:
0f41302f 2526 /* SCRATCH must be shared because they represent distinct values. */
23b2ce53
RS
2527 return x;
2528
b851ea09
RK
2529 case CONST:
2530 /* CONST can be shared if it contains a SYMBOL_REF. If it contains
2531 a LABEL_REF, it isn't sharable. */
2532 if (GET_CODE (XEXP (x, 0)) == PLUS
2533 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
2534 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
2535 return x;
2536 break;
2537
23b2ce53
RS
2538 case INSN:
2539 case JUMP_INSN:
2540 case CALL_INSN:
2541 case NOTE:
23b2ce53
RS
2542 case BARRIER:
2543 /* The chain of insns is not being copied. */
2544 return x;
2545
2546 case MEM:
83512665
JL
2547 /* A MEM is allowed to be shared if its address is constant.
2548
750c9258 2549 We used to allow sharing of MEMs which referenced
83512665
JL
2550 virtual_stack_vars_rtx or virtual_incoming_args_rtx, but
2551 that can lose. instantiate_virtual_regs will not unshare
2552 the MEMs, and combine may change the structure of the address
2553 because it looks safe and profitable in one context, but
2554 in some other context it creates unrecognizable RTL. */
2555 if (CONSTANT_ADDRESS_P (XEXP (x, 0)))
23b2ce53
RS
2556 return x;
2557
e9a25f70
JL
2558 break;
2559
2560 default:
2561 break;
23b2ce53
RS
2562 }
2563
2564 /* This rtx may not be shared. If it has already been seen,
2565 replace it with a copy of itself. */
2566
2adc7f12 2567 if (RTX_FLAG (x, used))
23b2ce53 2568 {
b3694847 2569 rtx copy;
23b2ce53
RS
2570
2571 copy = rtx_alloc (code);
4e135bdd 2572 memcpy (copy, x,
4c9a05bc
RK
2573 (sizeof (*copy) - sizeof (copy->fld)
2574 + sizeof (copy->fld[0]) * GET_RTX_LENGTH (code)));
23b2ce53
RS
2575 x = copy;
2576 copied = 1;
2577 }
2adc7f12 2578 RTX_FLAG (x, used) = 1;
23b2ce53
RS
2579
2580 /* Now scan the subexpressions recursively.
2581 We can store any replaced subexpressions directly into X
2582 since we know X is not shared! Any vectors in X
2583 must be copied if X was copied. */
2584
2585 format_ptr = GET_RTX_FORMAT (code);
2586
2587 for (i = 0; i < GET_RTX_LENGTH (code); i++)
2588 {
2589 switch (*format_ptr++)
2590 {
2591 case 'e':
2592 XEXP (x, i) = copy_rtx_if_shared (XEXP (x, i));
2593 break;
2594
2595 case 'E':
2596 if (XVEC (x, i) != NULL)
2597 {
b3694847 2598 int j;
f0722107 2599 int len = XVECLEN (x, i);
23b2ce53 2600
f0722107 2601 if (copied && len > 0)
8f985ec4 2602 XVEC (x, i) = gen_rtvec_v (len, XVEC (x, i)->elem);
f0722107
RS
2603 for (j = 0; j < len; j++)
2604 XVECEXP (x, i, j) = copy_rtx_if_shared (XVECEXP (x, i, j));
23b2ce53
RS
2605 }
2606 break;
2607 }
2608 }
2609 return x;
2610}
2611
2612/* Clear all the USED bits in X to allow copy_rtx_if_shared to be used
2613 to look for shared sub-parts. */
2614
2615void
2616reset_used_flags (x)
2617 rtx x;
2618{
b3694847
SS
2619 int i, j;
2620 enum rtx_code code;
2621 const char *format_ptr;
23b2ce53
RS
2622
2623 if (x == 0)
2624 return;
2625
2626 code = GET_CODE (x);
2627
9faa82d8 2628 /* These types may be freely shared so we needn't do any resetting
23b2ce53
RS
2629 for them. */
2630
2631 switch (code)
2632 {
2633 case REG:
2634 case QUEUED:
2635 case CONST_INT:
2636 case CONST_DOUBLE:
69ef87e2 2637 case CONST_VECTOR:
23b2ce53
RS
2638 case SYMBOL_REF:
2639 case CODE_LABEL:
2640 case PC:
2641 case CC0:
2642 return;
2643
2644 case INSN:
2645 case JUMP_INSN:
2646 case CALL_INSN:
2647 case NOTE:
2648 case LABEL_REF:
2649 case BARRIER:
2650 /* The chain of insns is not being copied. */
2651 return;
750c9258 2652
e9a25f70
JL
2653 default:
2654 break;
23b2ce53
RS
2655 }
2656
2adc7f12 2657 RTX_FLAG (x, used) = 0;
23b2ce53
RS
2658
2659 format_ptr = GET_RTX_FORMAT (code);
2660 for (i = 0; i < GET_RTX_LENGTH (code); i++)
2661 {
2662 switch (*format_ptr++)
2663 {
2664 case 'e':
2665 reset_used_flags (XEXP (x, i));
2666 break;
2667
2668 case 'E':
2669 for (j = 0; j < XVECLEN (x, i); j++)
2670 reset_used_flags (XVECEXP (x, i, j));
2671 break;
2672 }
2673 }
2674}
2675\f
2676/* Copy X if necessary so that it won't be altered by changes in OTHER.
2677 Return X or the rtx for the pseudo reg the value of X was copied into.
2678 OTHER must be valid as a SET_DEST. */
2679
2680rtx
2681make_safe_from (x, other)
2682 rtx x, other;
2683{
2684 while (1)
2685 switch (GET_CODE (other))
2686 {
2687 case SUBREG:
2688 other = SUBREG_REG (other);
2689 break;
2690 case STRICT_LOW_PART:
2691 case SIGN_EXTEND:
2692 case ZERO_EXTEND:
2693 other = XEXP (other, 0);
2694 break;
2695 default:
2696 goto done;
2697 }
2698 done:
2699 if ((GET_CODE (other) == MEM
2700 && ! CONSTANT_P (x)
2701 && GET_CODE (x) != REG
2702 && GET_CODE (x) != SUBREG)
2703 || (GET_CODE (other) == REG
2704 && (REGNO (other) < FIRST_PSEUDO_REGISTER
2705 || reg_mentioned_p (other, x))))
2706 {
2707 rtx temp = gen_reg_rtx (GET_MODE (x));
2708 emit_move_insn (temp, x);
2709 return temp;
2710 }
2711 return x;
2712}
2713\f
2714/* Emission of insns (adding them to the doubly-linked list). */
2715
2716/* Return the first insn of the current sequence or current function. */
2717
2718rtx
2719get_insns ()
2720{
2721 return first_insn;
2722}
2723
3dec4024
JH
2724/* Specify a new insn as the first in the chain. */
2725
2726void
2727set_first_insn (insn)
2728 rtx insn;
2729{
2730 if (PREV_INSN (insn) != 0)
2731 abort ();
2732 first_insn = insn;
2733}
2734
23b2ce53
RS
2735/* Return the last insn emitted in current sequence or current function. */
2736
2737rtx
2738get_last_insn ()
2739{
2740 return last_insn;
2741}
2742
2743/* Specify a new insn as the last in the chain. */
2744
2745void
2746set_last_insn (insn)
2747 rtx insn;
2748{
2749 if (NEXT_INSN (insn) != 0)
2750 abort ();
2751 last_insn = insn;
2752}
2753
2754/* Return the last insn emitted, even if it is in a sequence now pushed. */
2755
2756rtx
2757get_last_insn_anywhere ()
2758{
2759 struct sequence_stack *stack;
2760 if (last_insn)
2761 return last_insn;
49ad7cfa 2762 for (stack = seq_stack; stack; stack = stack->next)
23b2ce53
RS
2763 if (stack->last != 0)
2764 return stack->last;
2765 return 0;
2766}
2767
2a496e8b
JDA
2768/* Return the first nonnote insn emitted in current sequence or current
2769 function. This routine looks inside SEQUENCEs. */
2770
2771rtx
2772get_first_nonnote_insn ()
2773{
2774 rtx insn = first_insn;
2775
2776 while (insn)
2777 {
2778 insn = next_insn (insn);
2779 if (insn == 0 || GET_CODE (insn) != NOTE)
2780 break;
2781 }
2782
2783 return insn;
2784}
2785
2786/* Return the last nonnote insn emitted in current sequence or current
2787 function. This routine looks inside SEQUENCEs. */
2788
2789rtx
2790get_last_nonnote_insn ()
2791{
2792 rtx insn = last_insn;
2793
2794 while (insn)
2795 {
2796 insn = previous_insn (insn);
2797 if (insn == 0 || GET_CODE (insn) != NOTE)
2798 break;
2799 }
2800
2801 return insn;
2802}
2803
23b2ce53
RS
2804/* Return a number larger than any instruction's uid in this function. */
2805
2806int
2807get_max_uid ()
2808{
2809 return cur_insn_uid;
2810}
aeeeda03 2811
673b5311
MM
2812/* Renumber instructions so that no instruction UIDs are wasted. */
2813
aeeeda03 2814void
673b5311
MM
2815renumber_insns (stream)
2816 FILE *stream;
aeeeda03
MM
2817{
2818 rtx insn;
aeeeda03 2819
673b5311
MM
2820 /* If we're not supposed to renumber instructions, don't. */
2821 if (!flag_renumber_insns)
2822 return;
2823
aeeeda03
MM
2824 /* If there aren't that many instructions, then it's not really
2825 worth renumbering them. */
673b5311 2826 if (flag_renumber_insns == 1 && get_max_uid () < 25000)
aeeeda03
MM
2827 return;
2828
2829 cur_insn_uid = 1;
2830
2831 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
673b5311
MM
2832 {
2833 if (stream)
750c9258 2834 fprintf (stream, "Renumbering insn %d to %d\n",
673b5311
MM
2835 INSN_UID (insn), cur_insn_uid);
2836 INSN_UID (insn) = cur_insn_uid++;
2837 }
aeeeda03 2838}
23b2ce53
RS
2839\f
2840/* Return the next insn. If it is a SEQUENCE, return the first insn
2841 of the sequence. */
2842
2843rtx
2844next_insn (insn)
2845 rtx insn;
2846{
2847 if (insn)
2848 {
2849 insn = NEXT_INSN (insn);
2850 if (insn && GET_CODE (insn) == INSN
2851 && GET_CODE (PATTERN (insn)) == SEQUENCE)
2852 insn = XVECEXP (PATTERN (insn), 0, 0);
2853 }
2854
2855 return insn;
2856}
2857
2858/* Return the previous insn. If it is a SEQUENCE, return the last insn
2859 of the sequence. */
2860
2861rtx
2862previous_insn (insn)
2863 rtx insn;
2864{
2865 if (insn)
2866 {
2867 insn = PREV_INSN (insn);
2868 if (insn && GET_CODE (insn) == INSN
2869 && GET_CODE (PATTERN (insn)) == SEQUENCE)
2870 insn = XVECEXP (PATTERN (insn), 0, XVECLEN (PATTERN (insn), 0) - 1);
2871 }
2872
2873 return insn;
2874}
2875
2876/* Return the next insn after INSN that is not a NOTE. This routine does not
2877 look inside SEQUENCEs. */
2878
2879rtx
2880next_nonnote_insn (insn)
2881 rtx insn;
2882{
2883 while (insn)
2884 {
2885 insn = NEXT_INSN (insn);
2886 if (insn == 0 || GET_CODE (insn) != NOTE)
2887 break;
2888 }
2889
2890 return insn;
2891}
2892
2893/* Return the previous insn before INSN that is not a NOTE. This routine does
2894 not look inside SEQUENCEs. */
2895
2896rtx
2897prev_nonnote_insn (insn)
2898 rtx insn;
2899{
2900 while (insn)
2901 {
2902 insn = PREV_INSN (insn);
2903 if (insn == 0 || GET_CODE (insn) != NOTE)
2904 break;
2905 }
2906
2907 return insn;
2908}
2909
2910/* Return the next INSN, CALL_INSN or JUMP_INSN after INSN;
2911 or 0, if there is none. This routine does not look inside
0f41302f 2912 SEQUENCEs. */
23b2ce53
RS
2913
2914rtx
2915next_real_insn (insn)
2916 rtx insn;
2917{
2918 while (insn)
2919 {
2920 insn = NEXT_INSN (insn);
2921 if (insn == 0 || GET_CODE (insn) == INSN
2922 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN)
2923 break;
2924 }
2925
2926 return insn;
2927}
2928
2929/* Return the last INSN, CALL_INSN or JUMP_INSN before INSN;
2930 or 0, if there is none. This routine does not look inside
2931 SEQUENCEs. */
2932
2933rtx
2934prev_real_insn (insn)
2935 rtx insn;
2936{
2937 while (insn)
2938 {
2939 insn = PREV_INSN (insn);
2940 if (insn == 0 || GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
2941 || GET_CODE (insn) == JUMP_INSN)
2942 break;
2943 }
2944
2945 return insn;
2946}
2947
2948/* Find the next insn after INSN that really does something. This routine
2949 does not look inside SEQUENCEs. Until reload has completed, this is the
2950 same as next_real_insn. */
2951
69732dcb
RH
2952int
2953active_insn_p (insn)
2954 rtx insn;
2955{
2956 return (GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN
2957 || (GET_CODE (insn) == INSN
2958 && (! reload_completed
2959 || (GET_CODE (PATTERN (insn)) != USE
2960 && GET_CODE (PATTERN (insn)) != CLOBBER))));
2961}
2962
23b2ce53
RS
2963rtx
2964next_active_insn (insn)
2965 rtx insn;
2966{
2967 while (insn)
2968 {
2969 insn = NEXT_INSN (insn);
69732dcb 2970 if (insn == 0 || active_insn_p (insn))
23b2ce53
RS
2971 break;
2972 }
2973
2974 return insn;
2975}
2976
2977/* Find the last insn before INSN that really does something. This routine
2978 does not look inside SEQUENCEs. Until reload has completed, this is the
2979 same as prev_real_insn. */
2980
2981rtx
2982prev_active_insn (insn)
2983 rtx insn;
2984{
2985 while (insn)
2986 {
2987 insn = PREV_INSN (insn);
69732dcb 2988 if (insn == 0 || active_insn_p (insn))
23b2ce53
RS
2989 break;
2990 }
2991
2992 return insn;
2993}
2994
2995/* Return the next CODE_LABEL after the insn INSN, or 0 if there is none. */
2996
2997rtx
2998next_label (insn)
2999 rtx insn;
3000{
3001 while (insn)
3002 {
3003 insn = NEXT_INSN (insn);
3004 if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
3005 break;
3006 }
3007
3008 return insn;
3009}
3010
3011/* Return the last CODE_LABEL before the insn INSN, or 0 if there is none. */
3012
3013rtx
3014prev_label (insn)
3015 rtx insn;
3016{
3017 while (insn)
3018 {
3019 insn = PREV_INSN (insn);
3020 if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
3021 break;
3022 }
3023
3024 return insn;
3025}
3026\f
3027#ifdef HAVE_cc0
c572e5ba
JVA
3028/* INSN uses CC0 and is being moved into a delay slot. Set up REG_CC_SETTER
3029 and REG_CC_USER notes so we can find it. */
3030
3031void
3032link_cc0_insns (insn)
3033 rtx insn;
3034{
3035 rtx user = next_nonnote_insn (insn);
3036
3037 if (GET_CODE (user) == INSN && GET_CODE (PATTERN (user)) == SEQUENCE)
3038 user = XVECEXP (PATTERN (user), 0, 0);
3039
c5c76735
JL
3040 REG_NOTES (user) = gen_rtx_INSN_LIST (REG_CC_SETTER, insn,
3041 REG_NOTES (user));
3b80f6ca 3042 REG_NOTES (insn) = gen_rtx_INSN_LIST (REG_CC_USER, user, REG_NOTES (insn));
c572e5ba
JVA
3043}
3044
23b2ce53
RS
3045/* Return the next insn that uses CC0 after INSN, which is assumed to
3046 set it. This is the inverse of prev_cc0_setter (i.e., prev_cc0_setter
3047 applied to the result of this function should yield INSN).
3048
3049 Normally, this is simply the next insn. However, if a REG_CC_USER note
3050 is present, it contains the insn that uses CC0.
3051
3052 Return 0 if we can't find the insn. */
3053
3054rtx
3055next_cc0_user (insn)
3056 rtx insn;
3057{
906c4e36 3058 rtx note = find_reg_note (insn, REG_CC_USER, NULL_RTX);
23b2ce53
RS
3059
3060 if (note)
3061 return XEXP (note, 0);
3062
3063 insn = next_nonnote_insn (insn);
3064 if (insn && GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
3065 insn = XVECEXP (PATTERN (insn), 0, 0);
3066
2c3c49de 3067 if (insn && INSN_P (insn) && reg_mentioned_p (cc0_rtx, PATTERN (insn)))
23b2ce53
RS
3068 return insn;
3069
3070 return 0;
3071}
3072
3073/* Find the insn that set CC0 for INSN. Unless INSN has a REG_CC_SETTER
3074 note, it is the previous insn. */
3075
3076rtx
3077prev_cc0_setter (insn)
3078 rtx insn;
3079{
906c4e36 3080 rtx note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
23b2ce53
RS
3081
3082 if (note)
3083 return XEXP (note, 0);
3084
3085 insn = prev_nonnote_insn (insn);
3086 if (! sets_cc0_p (PATTERN (insn)))
3087 abort ();
3088
3089 return insn;
3090}
3091#endif
e5bef2e4
HB
3092
3093/* Increment the label uses for all labels present in rtx. */
3094
3095static void
68252e27
KH
3096mark_label_nuses (x)
3097 rtx x;
e5bef2e4 3098{
b3694847
SS
3099 enum rtx_code code;
3100 int i, j;
3101 const char *fmt;
e5bef2e4
HB
3102
3103 code = GET_CODE (x);
3104 if (code == LABEL_REF)
3105 LABEL_NUSES (XEXP (x, 0))++;
3106
3107 fmt = GET_RTX_FORMAT (code);
3108 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
3109 {
3110 if (fmt[i] == 'e')
0fb7aeda 3111 mark_label_nuses (XEXP (x, i));
e5bef2e4 3112 else if (fmt[i] == 'E')
0fb7aeda 3113 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
e5bef2e4
HB
3114 mark_label_nuses (XVECEXP (x, i, j));
3115 }
3116}
3117
23b2ce53
RS
3118\f
3119/* Try splitting insns that can be split for better scheduling.
3120 PAT is the pattern which might split.
3121 TRIAL is the insn providing PAT.
11147ebe 3122 LAST is non-zero if we should return the last insn of the sequence produced.
23b2ce53
RS
3123
3124 If this routine succeeds in splitting, it returns the first or last
11147ebe 3125 replacement insn depending on the value of LAST. Otherwise, it
23b2ce53
RS
3126 returns TRIAL. If the insn to be returned can be split, it will be. */
3127
3128rtx
11147ebe 3129try_split (pat, trial, last)
23b2ce53 3130 rtx pat, trial;
11147ebe 3131 int last;
23b2ce53
RS
3132{
3133 rtx before = PREV_INSN (trial);
3134 rtx after = NEXT_INSN (trial);
23b2ce53
RS
3135 int has_barrier = 0;
3136 rtx tem;
6b24c259
JH
3137 rtx note, seq;
3138 int probability;
3139
3140 if (any_condjump_p (trial)
3141 && (note = find_reg_note (trial, REG_BR_PROB, 0)))
3142 split_branch_probability = INTVAL (XEXP (note, 0));
3143 probability = split_branch_probability;
3144
3145 seq = split_insns (pat, trial);
3146
3147 split_branch_probability = -1;
23b2ce53
RS
3148
3149 /* If we are splitting a JUMP_INSN, it might be followed by a BARRIER.
3150 We may need to handle this specially. */
3151 if (after && GET_CODE (after) == BARRIER)
3152 {
3153 has_barrier = 1;
3154 after = NEXT_INSN (after);
3155 }
3156
3157 if (seq)
3158 {
2f937369
DM
3159 /* Sometimes there will be only one insn in that list, this case will
3160 normally arise only when we want it in turn to be split (SFmode on
3161 the 29k is an example). */
3162 if (NEXT_INSN (seq) != NULL_RTX)
23b2ce53 3163 {
2f937369
DM
3164 rtx insn_last, insn;
3165 int njumps = 0;
750c9258
AJ
3166
3167 /* Avoid infinite loop if any insn of the result matches
4b5e8abe 3168 the original pattern. */
2f937369
DM
3169 insn_last = seq;
3170 while (1)
3171 {
6f9703af
DM
3172 if (INSN_P (insn_last)
3173 && rtx_equal_p (PATTERN (insn_last), pat))
2f937369
DM
3174 return trial;
3175 if (NEXT_INSN (insn_last) == NULL_RTX)
3176 break;
3177 insn_last = NEXT_INSN (insn_last);
3178 }
4b5e8abe 3179
90a74703 3180 /* Mark labels. */
2f937369
DM
3181 insn = insn_last;
3182 while (insn != NULL_RTX)
3183 {
3184 if (GET_CODE (insn) == JUMP_INSN)
3185 {
3186 mark_jump_label (PATTERN (insn), insn, 0);
3187 njumps++;
3188 if (probability != -1
3189 && any_condjump_p (insn)
3190 && !find_reg_note (insn, REG_BR_PROB, 0))
3191 {
3192 /* We can preserve the REG_BR_PROB notes only if exactly
3193 one jump is created, otherwise the machine description
3194 is responsible for this step using
3195 split_branch_probability variable. */
3196 if (njumps != 1)
3197 abort ();
3198 REG_NOTES (insn)
3199 = gen_rtx_EXPR_LIST (REG_BR_PROB,
3200 GEN_INT (probability),
3201 REG_NOTES (insn));
3202 }
3203 }
3204
3205 insn = PREV_INSN (insn);
3206 }
216183ce 3207
2d01e445
AO
3208 /* If we are splitting a CALL_INSN, look for the CALL_INSN
3209 in SEQ and copy our CALL_INSN_FUNCTION_USAGE to it. */
3210 if (GET_CODE (trial) == CALL_INSN)
2f937369
DM
3211 {
3212 insn = insn_last;
3213 while (insn != NULL_RTX)
3214 {
3215 if (GET_CODE (insn) == CALL_INSN)
3216 CALL_INSN_FUNCTION_USAGE (insn)
3217 = CALL_INSN_FUNCTION_USAGE (trial);
3218
3219 insn = PREV_INSN (insn);
3220 }
3221 }
2d01e445 3222
216183ce 3223 /* Copy notes, particularly those related to the CFG. */
68252e27 3224 for (note = REG_NOTES (trial); note; note = XEXP (note, 1))
216183ce
RH
3225 {
3226 switch (REG_NOTE_KIND (note))
3227 {
3228 case REG_EH_REGION:
2f937369
DM
3229 insn = insn_last;
3230 while (insn != NULL_RTX)
216183ce 3231 {
216183ce
RH
3232 if (GET_CODE (insn) == CALL_INSN
3233 || (flag_non_call_exceptions
3234 && may_trap_p (PATTERN (insn))))
3235 REG_NOTES (insn)
3236 = gen_rtx_EXPR_LIST (REG_EH_REGION,
3237 XEXP (note, 0),
3238 REG_NOTES (insn));
2f937369 3239 insn = PREV_INSN (insn);
216183ce
RH
3240 }
3241 break;
3242
3243 case REG_NORETURN:
3244 case REG_SETJMP:
3245 case REG_ALWAYS_RETURN:
2f937369
DM
3246 insn = insn_last;
3247 while (insn != NULL_RTX)
216183ce 3248 {
216183ce
RH
3249 if (GET_CODE (insn) == CALL_INSN)
3250 REG_NOTES (insn)
3251 = gen_rtx_EXPR_LIST (REG_NOTE_KIND (note),
3252 XEXP (note, 0),
3253 REG_NOTES (insn));
2f937369 3254 insn = PREV_INSN (insn);
216183ce
RH
3255 }
3256 break;
3257
3258 case REG_NON_LOCAL_GOTO:
2f937369
DM
3259 insn = insn_last;
3260 while (insn != NULL_RTX)
216183ce 3261 {
216183ce
RH
3262 if (GET_CODE (insn) == JUMP_INSN)
3263 REG_NOTES (insn)
3264 = gen_rtx_EXPR_LIST (REG_NOTE_KIND (note),
3265 XEXP (note, 0),
3266 REG_NOTES (insn));
2f937369 3267 insn = PREV_INSN (insn);
216183ce
RH
3268 }
3269 break;
3270
3271 default:
3272 break;
3273 }
3274 }
d6e95df8 3275
e5bef2e4
HB
3276 /* If there are LABELS inside the split insns increment the
3277 usage count so we don't delete the label. */
3278 if (GET_CODE (trial) == INSN)
2f937369 3279 {
c6a3fcf0 3280 insn = insn_last;
2f937369
DM
3281 while (insn != NULL_RTX)
3282 {
3283 if (GET_CODE (insn) == INSN)
3284 mark_label_nuses (PATTERN (insn));
3285
3286 insn = PREV_INSN (insn);
3287 }
3288 }
e5bef2e4 3289
0d682900 3290 tem = emit_insn_after_scope (seq, trial, INSN_SCOPE (trial));
23b2ce53 3291
83a49407 3292 delete_insn (trial);
23b2ce53
RS
3293 if (has_barrier)
3294 emit_barrier_after (tem);
11147ebe
RK
3295
3296 /* Recursively call try_split for each new insn created; by the
3297 time control returns here that insn will be fully split, so
3298 set LAST and continue from the insn after the one returned.
f4a3cd05 3299 We can't use next_active_insn here since AFTER may be a note.
23886015 3300 Ignore deleted insns, which can be occur if not optimizing. */
2c3c49de
RB
3301 for (tem = NEXT_INSN (before); tem != after; tem = NEXT_INSN (tem))
3302 if (! INSN_DELETED_P (tem) && INSN_P (tem))
f4a3cd05 3303 tem = try_split (PATTERN (tem), tem, 1);
23b2ce53
RS
3304 }
3305 /* Avoid infinite loop if the result matches the original pattern. */
2f937369 3306 else if (rtx_equal_p (PATTERN (seq), pat))
23b2ce53
RS
3307 return trial;
3308 else
3309 {
2f937369 3310 PATTERN (trial) = PATTERN (seq);
23b2ce53 3311 INSN_CODE (trial) = -1;
2f937369 3312 try_split (PATTERN (trial), trial, last);
23b2ce53
RS
3313 }
3314
11147ebe
RK
3315 /* Return either the first or the last insn, depending on which was
3316 requested. */
750c9258 3317 return last
6b24c259
JH
3318 ? (after ? PREV_INSN (after) : last_insn)
3319 : NEXT_INSN (before);
23b2ce53
RS
3320 }
3321
3322 return trial;
3323}
3324\f
3325/* Make and return an INSN rtx, initializing all its slots.
4b1f5e8c 3326 Store PATTERN in the pattern slots. */
23b2ce53
RS
3327
3328rtx
4b1f5e8c 3329make_insn_raw (pattern)
23b2ce53 3330 rtx pattern;
23b2ce53 3331{
b3694847 3332 rtx insn;
23b2ce53 3333
1f8f4a0b 3334 insn = rtx_alloc (INSN);
23b2ce53 3335
43127294 3336 INSN_UID (insn) = cur_insn_uid++;
23b2ce53
RS
3337 PATTERN (insn) = pattern;
3338 INSN_CODE (insn) = -1;
1632afca
RS
3339 LOG_LINKS (insn) = NULL;
3340 REG_NOTES (insn) = NULL;
ba4f7968
JH
3341 INSN_SCOPE (insn) = NULL;
3342 BLOCK_FOR_INSN (insn) = NULL;
23b2ce53 3343
47984720
NC
3344#ifdef ENABLE_RTL_CHECKING
3345 if (insn
2c3c49de 3346 && INSN_P (insn)
47984720
NC
3347 && (returnjump_p (insn)
3348 || (GET_CODE (insn) == SET
3349 && SET_DEST (insn) == pc_rtx)))
3350 {
3351 warning ("ICE: emit_insn used where emit_jump_insn needed:\n");
3352 debug_rtx (insn);
3353 }
3354#endif
750c9258 3355
23b2ce53
RS
3356 return insn;
3357}
3358
2f937369 3359/* Like `make_insn_raw' but make a JUMP_INSN instead of an insn. */
23b2ce53
RS
3360
3361static rtx
4b1f5e8c 3362make_jump_insn_raw (pattern)
23b2ce53 3363 rtx pattern;
23b2ce53 3364{
b3694847 3365 rtx insn;
23b2ce53 3366
4b1f5e8c 3367 insn = rtx_alloc (JUMP_INSN);
1632afca 3368 INSN_UID (insn) = cur_insn_uid++;
23b2ce53
RS
3369
3370 PATTERN (insn) = pattern;
3371 INSN_CODE (insn) = -1;
1632afca
RS
3372 LOG_LINKS (insn) = NULL;
3373 REG_NOTES (insn) = NULL;
3374 JUMP_LABEL (insn) = NULL;
ba4f7968
JH
3375 INSN_SCOPE (insn) = NULL;
3376 BLOCK_FOR_INSN (insn) = NULL;
23b2ce53
RS
3377
3378 return insn;
3379}
aff507f4 3380
2f937369 3381/* Like `make_insn_raw' but make a CALL_INSN instead of an insn. */
aff507f4
RK
3382
3383static rtx
3384make_call_insn_raw (pattern)
3385 rtx pattern;
3386{
b3694847 3387 rtx insn;
aff507f4
RK
3388
3389 insn = rtx_alloc (CALL_INSN);
3390 INSN_UID (insn) = cur_insn_uid++;
3391
3392 PATTERN (insn) = pattern;
3393 INSN_CODE (insn) = -1;
3394 LOG_LINKS (insn) = NULL;
3395 REG_NOTES (insn) = NULL;
3396 CALL_INSN_FUNCTION_USAGE (insn) = NULL;
ba4f7968
JH
3397 INSN_SCOPE (insn) = NULL;
3398 BLOCK_FOR_INSN (insn) = NULL;
aff507f4
RK
3399
3400 return insn;
3401}
23b2ce53
RS
3402\f
3403/* Add INSN to the end of the doubly-linked list.
3404 INSN may be an INSN, JUMP_INSN, CALL_INSN, CODE_LABEL, BARRIER or NOTE. */
3405
3406void
3407add_insn (insn)
b3694847 3408 rtx insn;
23b2ce53
RS
3409{
3410 PREV_INSN (insn) = last_insn;
3411 NEXT_INSN (insn) = 0;
3412
3413 if (NULL != last_insn)
3414 NEXT_INSN (last_insn) = insn;
3415
3416 if (NULL == first_insn)
3417 first_insn = insn;
3418
3419 last_insn = insn;
3420}
3421
a0ae8e8d
RK
3422/* Add INSN into the doubly-linked list after insn AFTER. This and
3423 the next should be the only functions called to insert an insn once
ba213285 3424 delay slots have been filled since only they know how to update a
a0ae8e8d 3425 SEQUENCE. */
23b2ce53
RS
3426
3427void
3428add_insn_after (insn, after)
3429 rtx insn, after;
3430{
3431 rtx next = NEXT_INSN (after);
3c030e88 3432 basic_block bb;
23b2ce53 3433
6782074d 3434 if (optimize && INSN_DELETED_P (after))
ba213285
RK
3435 abort ();
3436
23b2ce53
RS
3437 NEXT_INSN (insn) = next;
3438 PREV_INSN (insn) = after;
3439
3440 if (next)
3441 {
3442 PREV_INSN (next) = insn;
3443 if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == SEQUENCE)
3444 PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = insn;
3445 }
3446 else if (last_insn == after)
3447 last_insn = insn;
3448 else
3449 {
49ad7cfa 3450 struct sequence_stack *stack = seq_stack;
23b2ce53
RS
3451 /* Scan all pending sequences too. */
3452 for (; stack; stack = stack->next)
3453 if (after == stack->last)
fef0509b
RK
3454 {
3455 stack->last = insn;
3456 break;
3457 }
a0ae8e8d
RK
3458
3459 if (stack == 0)
3460 abort ();
23b2ce53
RS
3461 }
3462
ba4f7968
JH
3463 if (GET_CODE (after) != BARRIER
3464 && GET_CODE (insn) != BARRIER
3c030e88
JH
3465 && (bb = BLOCK_FOR_INSN (after)))
3466 {
3467 set_block_for_insn (insn, bb);
38c1593d 3468 if (INSN_P (insn))
68252e27 3469 bb->flags |= BB_DIRTY;
3c030e88 3470 /* Should not happen as first in the BB is always
a1f300c0 3471 either NOTE or LABEL. */
3c030e88
JH
3472 if (bb->end == after
3473 /* Avoid clobbering of structure when creating new BB. */
3474 && GET_CODE (insn) != BARRIER
3475 && (GET_CODE (insn) != NOTE
3476 || NOTE_LINE_NUMBER (insn) != NOTE_INSN_BASIC_BLOCK))
3477 bb->end = insn;
3478 }
3479
23b2ce53
RS
3480 NEXT_INSN (after) = insn;
3481 if (GET_CODE (after) == INSN && GET_CODE (PATTERN (after)) == SEQUENCE)
3482 {
3483 rtx sequence = PATTERN (after);
3484 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
3485 }
3486}
3487
a0ae8e8d
RK
3488/* Add INSN into the doubly-linked list before insn BEFORE. This and
3489 the previous should be the only functions called to insert an insn once
ba213285 3490 delay slots have been filled since only they know how to update a
a0ae8e8d
RK
3491 SEQUENCE. */
3492
3493void
3494add_insn_before (insn, before)
3495 rtx insn, before;
3496{
3497 rtx prev = PREV_INSN (before);
3c030e88 3498 basic_block bb;
a0ae8e8d 3499
6782074d 3500 if (optimize && INSN_DELETED_P (before))
ba213285
RK
3501 abort ();
3502
a0ae8e8d
RK
3503 PREV_INSN (insn) = prev;
3504 NEXT_INSN (insn) = before;
3505
3506 if (prev)
3507 {
3508 NEXT_INSN (prev) = insn;
3509 if (GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == SEQUENCE)
3510 {
3511 rtx sequence = PATTERN (prev);
3512 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
3513 }
3514 }
3515 else if (first_insn == before)
3516 first_insn = insn;
3517 else
3518 {
49ad7cfa 3519 struct sequence_stack *stack = seq_stack;
a0ae8e8d
RK
3520 /* Scan all pending sequences too. */
3521 for (; stack; stack = stack->next)
3522 if (before == stack->first)
fef0509b
RK
3523 {
3524 stack->first = insn;
3525 break;
3526 }
a0ae8e8d
RK
3527
3528 if (stack == 0)
3529 abort ();
3530 }
3531
ba4f7968
JH
3532 if (GET_CODE (before) != BARRIER
3533 && GET_CODE (insn) != BARRIER
3c030e88
JH
3534 && (bb = BLOCK_FOR_INSN (before)))
3535 {
3536 set_block_for_insn (insn, bb);
38c1593d 3537 if (INSN_P (insn))
68252e27 3538 bb->flags |= BB_DIRTY;
3c030e88 3539 /* Should not happen as first in the BB is always
a1f300c0 3540 either NOTE or LABEl. */
3c030e88
JH
3541 if (bb->head == insn
3542 /* Avoid clobbering of structure when creating new BB. */
3543 && GET_CODE (insn) != BARRIER
3544 && (GET_CODE (insn) != NOTE
3545 || NOTE_LINE_NUMBER (insn) != NOTE_INSN_BASIC_BLOCK))
3546 abort ();
3547 }
3548
a0ae8e8d
RK
3549 PREV_INSN (before) = insn;
3550 if (GET_CODE (before) == INSN && GET_CODE (PATTERN (before)) == SEQUENCE)
3551 PREV_INSN (XVECEXP (PATTERN (before), 0, 0)) = insn;
3552}
3553
89e99eea
DB
3554/* Remove an insn from its doubly-linked list. This function knows how
3555 to handle sequences. */
3556void
3557remove_insn (insn)
3558 rtx insn;
3559{
3560 rtx next = NEXT_INSN (insn);
3561 rtx prev = PREV_INSN (insn);
53c17031
JH
3562 basic_block bb;
3563
89e99eea
DB
3564 if (prev)
3565 {
3566 NEXT_INSN (prev) = next;
3567 if (GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == SEQUENCE)
3568 {
3569 rtx sequence = PATTERN (prev);
3570 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = next;
3571 }
3572 }
3573 else if (first_insn == insn)
3574 first_insn = next;
3575 else
3576 {
49ad7cfa 3577 struct sequence_stack *stack = seq_stack;
89e99eea
DB
3578 /* Scan all pending sequences too. */
3579 for (; stack; stack = stack->next)
3580 if (insn == stack->first)
3581 {
3582 stack->first = next;
3583 break;
3584 }
3585
3586 if (stack == 0)
3587 abort ();
3588 }
3589
3590 if (next)
3591 {
3592 PREV_INSN (next) = prev;
3593 if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == SEQUENCE)
3594 PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = prev;
3595 }
3596 else if (last_insn == insn)
3597 last_insn = prev;
3598 else
3599 {
49ad7cfa 3600 struct sequence_stack *stack = seq_stack;
89e99eea
DB
3601 /* Scan all pending sequences too. */
3602 for (; stack; stack = stack->next)
3603 if (insn == stack->last)
3604 {
3605 stack->last = prev;
3606 break;
3607 }
3608
3609 if (stack == 0)
3610 abort ();
3611 }
ba4f7968 3612 if (GET_CODE (insn) != BARRIER
53c17031
JH
3613 && (bb = BLOCK_FOR_INSN (insn)))
3614 {
38c1593d 3615 if (INSN_P (insn))
68252e27 3616 bb->flags |= BB_DIRTY;
53c17031
JH
3617 if (bb->head == insn)
3618 {
3bf1e984
RK
3619 /* Never ever delete the basic block note without deleting whole
3620 basic block. */
53c17031
JH
3621 if (GET_CODE (insn) == NOTE)
3622 abort ();
3623 bb->head = next;
3624 }
3625 if (bb->end == insn)
3626 bb->end = prev;
3627 }
89e99eea
DB
3628}
3629
23b2ce53
RS
3630/* Delete all insns made since FROM.
3631 FROM becomes the new last instruction. */
3632
3633void
3634delete_insns_since (from)
3635 rtx from;
3636{
3637 if (from == 0)
3638 first_insn = 0;
3639 else
3640 NEXT_INSN (from) = 0;
3641 last_insn = from;
3642}
3643
5dab5552
MS
3644/* This function is deprecated, please use sequences instead.
3645
3646 Move a consecutive bunch of insns to a different place in the chain.
23b2ce53
RS
3647 The insns to be moved are those between FROM and TO.
3648 They are moved to a new position after the insn AFTER.
3649 AFTER must not be FROM or TO or any insn in between.
3650
3651 This function does not know about SEQUENCEs and hence should not be
3652 called after delay-slot filling has been done. */
3653
3654void
3c030e88 3655reorder_insns_nobb (from, to, after)
23b2ce53
RS
3656 rtx from, to, after;
3657{
3658 /* Splice this bunch out of where it is now. */
3659 if (PREV_INSN (from))
3660 NEXT_INSN (PREV_INSN (from)) = NEXT_INSN (to);
3661 if (NEXT_INSN (to))
3662 PREV_INSN (NEXT_INSN (to)) = PREV_INSN (from);
3663 if (last_insn == to)
3664 last_insn = PREV_INSN (from);
3665 if (first_insn == from)
3666 first_insn = NEXT_INSN (to);
3667
3668 /* Make the new neighbors point to it and it to them. */
3669 if (NEXT_INSN (after))
3670 PREV_INSN (NEXT_INSN (after)) = to;
3671
3672 NEXT_INSN (to) = NEXT_INSN (after);
3673 PREV_INSN (from) = after;
3674 NEXT_INSN (after) = from;
3675 if (after == last_insn)
3676 last_insn = to;
3677}
3678
3c030e88
JH
3679/* Same as function above, but take care to update BB boundaries. */
3680void
3681reorder_insns (from, to, after)
3682 rtx from, to, after;
3683{
3684 rtx prev = PREV_INSN (from);
3685 basic_block bb, bb2;
3686
3687 reorder_insns_nobb (from, to, after);
3688
ba4f7968 3689 if (GET_CODE (after) != BARRIER
3c030e88
JH
3690 && (bb = BLOCK_FOR_INSN (after)))
3691 {
3692 rtx x;
38c1593d 3693 bb->flags |= BB_DIRTY;
68252e27 3694
ba4f7968 3695 if (GET_CODE (from) != BARRIER
3c030e88
JH
3696 && (bb2 = BLOCK_FOR_INSN (from)))
3697 {
3698 if (bb2->end == to)
3699 bb2->end = prev;
38c1593d 3700 bb2->flags |= BB_DIRTY;
3c030e88
JH
3701 }
3702
3703 if (bb->end == after)
3704 bb->end = to;
3705
3706 for (x = from; x != NEXT_INSN (to); x = NEXT_INSN (x))
3707 set_block_for_insn (x, bb);
3708 }
3709}
3710
23b2ce53
RS
3711/* Return the line note insn preceding INSN. */
3712
3713static rtx
3714find_line_note (insn)
3715 rtx insn;
3716{
3717 if (no_line_numbers)
3718 return 0;
3719
3720 for (; insn; insn = PREV_INSN (insn))
3721 if (GET_CODE (insn) == NOTE
0fb7aeda 3722 && NOTE_LINE_NUMBER (insn) >= 0)
23b2ce53
RS
3723 break;
3724
3725 return insn;
3726}
3727
3728/* Like reorder_insns, but inserts line notes to preserve the line numbers
3729 of the moved insns when debugging. This may insert a note between AFTER
3730 and FROM, and another one after TO. */
3731
3732void
3733reorder_insns_with_line_notes (from, to, after)
3734 rtx from, to, after;
3735{
3736 rtx from_line = find_line_note (from);
3737 rtx after_line = find_line_note (after);
3738
3739 reorder_insns (from, to, after);
3740
3741 if (from_line == after_line)
3742 return;
3743
3744 if (from_line)
3745 emit_line_note_after (NOTE_SOURCE_FILE (from_line),
3746 NOTE_LINE_NUMBER (from_line),
3747 after);
3748 if (after_line)
3749 emit_line_note_after (NOTE_SOURCE_FILE (after_line),
3750 NOTE_LINE_NUMBER (after_line),
3751 to);
3752}
aeeeda03 3753
64b59a80 3754/* Remove unnecessary notes from the instruction stream. */
aeeeda03
MM
3755
3756void
64b59a80 3757remove_unnecessary_notes ()
aeeeda03 3758{
542d73ae
RH
3759 rtx block_stack = NULL_RTX;
3760 rtx eh_stack = NULL_RTX;
aeeeda03
MM
3761 rtx insn;
3762 rtx next;
542d73ae 3763 rtx tmp;
aeeeda03 3764
116eebd6
MM
3765 /* We must not remove the first instruction in the function because
3766 the compiler depends on the first instruction being a note. */
aeeeda03
MM
3767 for (insn = NEXT_INSN (get_insns ()); insn; insn = next)
3768 {
3769 /* Remember what's next. */
3770 next = NEXT_INSN (insn);
3771
3772 /* We're only interested in notes. */
3773 if (GET_CODE (insn) != NOTE)
3774 continue;
3775
542d73ae 3776 switch (NOTE_LINE_NUMBER (insn))
18c038b9 3777 {
542d73ae 3778 case NOTE_INSN_DELETED:
e803a64b 3779 case NOTE_INSN_LOOP_END_TOP_COND:
542d73ae
RH
3780 remove_insn (insn);
3781 break;
3782
3783 case NOTE_INSN_EH_REGION_BEG:
3784 eh_stack = alloc_INSN_LIST (insn, eh_stack);
3785 break;
3786
3787 case NOTE_INSN_EH_REGION_END:
3788 /* Too many end notes. */
3789 if (eh_stack == NULL_RTX)
3790 abort ();
3791 /* Mismatched nesting. */
3792 if (NOTE_EH_HANDLER (XEXP (eh_stack, 0)) != NOTE_EH_HANDLER (insn))
3793 abort ();
3794 tmp = eh_stack;
3795 eh_stack = XEXP (eh_stack, 1);
3796 free_INSN_LIST_node (tmp);
3797 break;
3798
3799 case NOTE_INSN_BLOCK_BEG:
3800 /* By now, all notes indicating lexical blocks should have
3801 NOTE_BLOCK filled in. */
3802 if (NOTE_BLOCK (insn) == NULL_TREE)
3803 abort ();
3804 block_stack = alloc_INSN_LIST (insn, block_stack);
3805 break;
3806
3807 case NOTE_INSN_BLOCK_END:
3808 /* Too many end notes. */
3809 if (block_stack == NULL_RTX)
3810 abort ();
3811 /* Mismatched nesting. */
3812 if (NOTE_BLOCK (XEXP (block_stack, 0)) != NOTE_BLOCK (insn))
3813 abort ();
3814 tmp = block_stack;
3815 block_stack = XEXP (block_stack, 1);
3816 free_INSN_LIST_node (tmp);
3817
18c038b9
MM
3818 /* Scan back to see if there are any non-note instructions
3819 between INSN and the beginning of this block. If not,
3820 then there is no PC range in the generated code that will
3821 actually be in this block, so there's no point in
3822 remembering the existence of the block. */
68252e27 3823 for (tmp = PREV_INSN (insn); tmp; tmp = PREV_INSN (tmp))
18c038b9
MM
3824 {
3825 /* This block contains a real instruction. Note that we
3826 don't include labels; if the only thing in the block
3827 is a label, then there are still no PC values that
3828 lie within the block. */
542d73ae 3829 if (INSN_P (tmp))
18c038b9
MM
3830 break;
3831
3832 /* We're only interested in NOTEs. */
542d73ae 3833 if (GET_CODE (tmp) != NOTE)
18c038b9
MM
3834 continue;
3835
542d73ae 3836 if (NOTE_LINE_NUMBER (tmp) == NOTE_INSN_BLOCK_BEG)
18c038b9 3837 {
e1772ac0
NB
3838 /* We just verified that this BLOCK matches us with
3839 the block_stack check above. Never delete the
3840 BLOCK for the outermost scope of the function; we
3841 can refer to names from that scope even if the
3842 block notes are messed up. */
3843 if (! is_body_block (NOTE_BLOCK (insn))
3844 && (*debug_hooks->ignore_block) (NOTE_BLOCK (insn)))
deb5e280 3845 {
542d73ae 3846 remove_insn (tmp);
deb5e280
JM
3847 remove_insn (insn);
3848 }
18c038b9
MM
3849 break;
3850 }
542d73ae 3851 else if (NOTE_LINE_NUMBER (tmp) == NOTE_INSN_BLOCK_END)
18c038b9
MM
3852 /* There's a nested block. We need to leave the
3853 current block in place since otherwise the debugger
3854 wouldn't be able to show symbols from our block in
3855 the nested block. */
3856 break;
3857 }
3858 }
aeeeda03 3859 }
542d73ae
RH
3860
3861 /* Too many begin notes. */
3862 if (block_stack || eh_stack)
3863 abort ();
aeeeda03
MM
3864}
3865
23b2ce53 3866\f
2f937369
DM
3867/* Emit insn(s) of given code and pattern
3868 at a specified place within the doubly-linked list.
23b2ce53 3869
2f937369
DM
3870 All of the emit_foo global entry points accept an object
3871 X which is either an insn list or a PATTERN of a single
3872 instruction.
23b2ce53 3873
2f937369
DM
3874 There are thus a few canonical ways to generate code and
3875 emit it at a specific place in the instruction stream. For
3876 example, consider the instruction named SPOT and the fact that
3877 we would like to emit some instructions before SPOT. We might
3878 do it like this:
23b2ce53 3879
2f937369
DM
3880 start_sequence ();
3881 ... emit the new instructions ...
3882 insns_head = get_insns ();
3883 end_sequence ();
23b2ce53 3884
2f937369 3885 emit_insn_before (insns_head, SPOT);
23b2ce53 3886
2f937369
DM
3887 It used to be common to generate SEQUENCE rtl instead, but that
3888 is a relic of the past which no longer occurs. The reason is that
3889 SEQUENCE rtl results in much fragmented RTL memory since the SEQUENCE
3890 generated would almost certainly die right after it was created. */
23b2ce53 3891
2f937369 3892/* Make X be output before the instruction BEFORE. */
23b2ce53
RS
3893
3894rtx
2f937369
DM
3895emit_insn_before (x, before)
3896 rtx x, before;
23b2ce53 3897{
2f937369 3898 rtx last = before;
b3694847 3899 rtx insn;
23b2ce53 3900
2f937369
DM
3901#ifdef ENABLE_RTL_CHECKING
3902 if (before == NULL_RTX)
3903 abort ();
3904#endif
3905
3906 if (x == NULL_RTX)
3907 return last;
3908
3909 switch (GET_CODE (x))
23b2ce53 3910 {
2f937369
DM
3911 case INSN:
3912 case JUMP_INSN:
3913 case CALL_INSN:
3914 case CODE_LABEL:
3915 case BARRIER:
3916 case NOTE:
3917 insn = x;
3918 while (insn)
3919 {
3920 rtx next = NEXT_INSN (insn);
3921 add_insn_before (insn, before);
3922 last = insn;
3923 insn = next;
3924 }
3925 break;
3926
3927#ifdef ENABLE_RTL_CHECKING
3928 case SEQUENCE:
3929 abort ();
3930 break;
3931#endif
3932
3933 default:
3934 last = make_insn_raw (x);
3935 add_insn_before (last, before);
3936 break;
23b2ce53
RS
3937 }
3938
2f937369 3939 return last;
23b2ce53
RS
3940}
3941
2f937369 3942/* Make an instruction with body X and code JUMP_INSN
23b2ce53
RS
3943 and output it before the instruction BEFORE. */
3944
3945rtx
2f937369
DM
3946emit_jump_insn_before (x, before)
3947 rtx x, before;
23b2ce53 3948{
2f937369 3949 rtx insn, last;
aff507f4 3950
2f937369
DM
3951#ifdef ENABLE_RTL_CHECKING
3952 if (before == NULL_RTX)
3953 abort ();
3954#endif
3955
3956 switch (GET_CODE (x))
aff507f4 3957 {
2f937369
DM
3958 case INSN:
3959 case JUMP_INSN:
3960 case CALL_INSN:
3961 case CODE_LABEL:
3962 case BARRIER:
3963 case NOTE:
3964 insn = x;
3965 while (insn)
3966 {
3967 rtx next = NEXT_INSN (insn);
3968 add_insn_before (insn, before);
3969 last = insn;
3970 insn = next;
3971 }
3972 break;
3973
3974#ifdef ENABLE_RTL_CHECKING
3975 case SEQUENCE:
3976 abort ();
3977 break;
3978#endif
3979
3980 default:
3981 last = make_jump_insn_raw (x);
3982 add_insn_before (last, before);
3983 break;
aff507f4
RK
3984 }
3985
2f937369 3986 return last;
23b2ce53
RS
3987}
3988
2f937369 3989/* Make an instruction with body X and code CALL_INSN
969d70ca
JH
3990 and output it before the instruction BEFORE. */
3991
3992rtx
2f937369
DM
3993emit_call_insn_before (x, before)
3994 rtx x, before;
969d70ca 3995{
2f937369 3996 rtx last, insn;
969d70ca 3997
2f937369
DM
3998#ifdef ENABLE_RTL_CHECKING
3999 if (before == NULL_RTX)
4000 abort ();
4001#endif
4002
4003 switch (GET_CODE (x))
969d70ca 4004 {
2f937369
DM
4005 case INSN:
4006 case JUMP_INSN:
4007 case CALL_INSN:
4008 case CODE_LABEL:
4009 case BARRIER:
4010 case NOTE:
4011 insn = x;
4012 while (insn)
4013 {
4014 rtx next = NEXT_INSN (insn);
4015 add_insn_before (insn, before);
4016 last = insn;
4017 insn = next;
4018 }
4019 break;
4020
4021#ifdef ENABLE_RTL_CHECKING
4022 case SEQUENCE:
4023 abort ();
4024 break;
4025#endif
4026
4027 default:
4028 last = make_call_insn_raw (x);
4029 add_insn_before (last, before);
4030 break;
969d70ca
JH
4031 }
4032
2f937369 4033 return last;
969d70ca
JH
4034}
4035
23b2ce53 4036/* Make an insn of code BARRIER
e881bb1b 4037 and output it before the insn BEFORE. */
23b2ce53
RS
4038
4039rtx
4040emit_barrier_before (before)
b3694847 4041 rtx before;
23b2ce53 4042{
b3694847 4043 rtx insn = rtx_alloc (BARRIER);
23b2ce53
RS
4044
4045 INSN_UID (insn) = cur_insn_uid++;
4046
a0ae8e8d 4047 add_insn_before (insn, before);
23b2ce53
RS
4048 return insn;
4049}
4050
e881bb1b
RH
4051/* Emit the label LABEL before the insn BEFORE. */
4052
4053rtx
4054emit_label_before (label, before)
4055 rtx label, before;
4056{
4057 /* This can be called twice for the same label as a result of the
4058 confusion that follows a syntax error! So make it harmless. */
4059 if (INSN_UID (label) == 0)
4060 {
4061 INSN_UID (label) = cur_insn_uid++;
4062 add_insn_before (label, before);
4063 }
4064
4065 return label;
4066}
4067
23b2ce53
RS
4068/* Emit a note of subtype SUBTYPE before the insn BEFORE. */
4069
4070rtx
4071emit_note_before (subtype, before)
4072 int subtype;
4073 rtx before;
4074{
b3694847 4075 rtx note = rtx_alloc (NOTE);
23b2ce53
RS
4076 INSN_UID (note) = cur_insn_uid++;
4077 NOTE_SOURCE_FILE (note) = 0;
4078 NOTE_LINE_NUMBER (note) = subtype;
ba4f7968 4079 BLOCK_FOR_INSN (note) = NULL;
23b2ce53 4080
a0ae8e8d 4081 add_insn_before (note, before);
23b2ce53
RS
4082 return note;
4083}
4084\f
2f937369
DM
4085/* Helper for emit_insn_after, handles lists of instructions
4086 efficiently. */
23b2ce53 4087
2f937369
DM
4088static rtx emit_insn_after_1 PARAMS ((rtx, rtx));
4089
4090static rtx
4091emit_insn_after_1 (first, after)
4092 rtx first, after;
23b2ce53 4093{
2f937369
DM
4094 rtx last;
4095 rtx after_after;
4096 basic_block bb;
23b2ce53 4097
2f937369
DM
4098 if (GET_CODE (after) != BARRIER
4099 && (bb = BLOCK_FOR_INSN (after)))
23b2ce53 4100 {
2f937369
DM
4101 bb->flags |= BB_DIRTY;
4102 for (last = first; NEXT_INSN (last); last = NEXT_INSN (last))
4103 if (GET_CODE (last) != BARRIER)
4104 set_block_for_insn (last, bb);
4105 if (GET_CODE (last) != BARRIER)
4106 set_block_for_insn (last, bb);
4107 if (bb->end == after)
4108 bb->end = last;
23b2ce53
RS
4109 }
4110 else
2f937369
DM
4111 for (last = first; NEXT_INSN (last); last = NEXT_INSN (last))
4112 continue;
4113
4114 after_after = NEXT_INSN (after);
4115
4116 NEXT_INSN (after) = first;
4117 PREV_INSN (first) = after;
4118 NEXT_INSN (last) = after_after;
4119 if (after_after)
4120 PREV_INSN (after_after) = last;
4121
4122 if (after == last_insn)
4123 last_insn = last;
4124 return last;
4125}
4126
4127/* Make X be output after the insn AFTER. */
4128
4129rtx
4130emit_insn_after (x, after)
4131 rtx x, after;
4132{
4133 rtx last = after;
4134
4135#ifdef ENABLE_RTL_CHECKING
4136 if (after == NULL_RTX)
4137 abort ();
4138#endif
4139
4140 if (x == NULL_RTX)
4141 return last;
4142
4143 switch (GET_CODE (x))
23b2ce53 4144 {
2f937369
DM
4145 case INSN:
4146 case JUMP_INSN:
4147 case CALL_INSN:
4148 case CODE_LABEL:
4149 case BARRIER:
4150 case NOTE:
4151 last = emit_insn_after_1 (x, after);
4152 break;
4153
4154#ifdef ENABLE_RTL_CHECKING
4155 case SEQUENCE:
4156 abort ();
4157 break;
4158#endif
4159
4160 default:
4161 last = make_insn_raw (x);
4162 add_insn_after (last, after);
4163 break;
23b2ce53
RS
4164 }
4165
2f937369 4166 return last;
23b2ce53
RS
4167}
4168
255680cf
RK
4169/* Similar to emit_insn_after, except that line notes are to be inserted so
4170 as to act as if this insn were at FROM. */
4171
4172void
2f937369
DM
4173emit_insn_after_with_line_notes (x, after, from)
4174 rtx x, after, from;
255680cf
RK
4175{
4176 rtx from_line = find_line_note (from);
4177 rtx after_line = find_line_note (after);
2f937369 4178 rtx insn = emit_insn_after (x, after);
255680cf
RK
4179
4180 if (from_line)
4181 emit_line_note_after (NOTE_SOURCE_FILE (from_line),
4182 NOTE_LINE_NUMBER (from_line),
4183 after);
4184
4185 if (after_line)
4186 emit_line_note_after (NOTE_SOURCE_FILE (after_line),
4187 NOTE_LINE_NUMBER (after_line),
4188 insn);
4189}
4190
2f937369 4191/* Make an insn of code JUMP_INSN with body X
23b2ce53
RS
4192 and output it after the insn AFTER. */
4193
4194rtx
2f937369
DM
4195emit_jump_insn_after (x, after)
4196 rtx x, after;
23b2ce53 4197{
2f937369 4198 rtx last;
23b2ce53 4199
2f937369
DM
4200#ifdef ENABLE_RTL_CHECKING
4201 if (after == NULL_RTX)
4202 abort ();
4203#endif
4204
4205 switch (GET_CODE (x))
23b2ce53 4206 {
2f937369
DM
4207 case INSN:
4208 case JUMP_INSN:
4209 case CALL_INSN:
4210 case CODE_LABEL:
4211 case BARRIER:
4212 case NOTE:
4213 last = emit_insn_after_1 (x, after);
4214 break;
4215
4216#ifdef ENABLE_RTL_CHECKING
4217 case SEQUENCE:
4218 abort ();
4219 break;
4220#endif
4221
4222 default:
4223 last = make_jump_insn_raw (x);
4224 add_insn_after (last, after);
4225 break;
23b2ce53
RS
4226 }
4227
2f937369
DM
4228 return last;
4229}
4230
4231/* Make an instruction with body X and code CALL_INSN
4232 and output it after the instruction AFTER. */
4233
4234rtx
4235emit_call_insn_after (x, after)
4236 rtx x, after;
4237{
4238 rtx last;
4239
4240#ifdef ENABLE_RTL_CHECKING
4241 if (after == NULL_RTX)
4242 abort ();
4243#endif
4244
4245 switch (GET_CODE (x))
4246 {
4247 case INSN:
4248 case JUMP_INSN:
4249 case CALL_INSN:
4250 case CODE_LABEL:
4251 case BARRIER:
4252 case NOTE:
4253 last = emit_insn_after_1 (x, after);
4254 break;
4255
4256#ifdef ENABLE_RTL_CHECKING
4257 case SEQUENCE:
4258 abort ();
4259 break;
4260#endif
4261
4262 default:
4263 last = make_call_insn_raw (x);
4264 add_insn_after (last, after);
4265 break;
4266 }
4267
4268 return last;
23b2ce53
RS
4269}
4270
4271/* Make an insn of code BARRIER
4272 and output it after the insn AFTER. */
4273
4274rtx
4275emit_barrier_after (after)
b3694847 4276 rtx after;
23b2ce53 4277{
b3694847 4278 rtx insn = rtx_alloc (BARRIER);
23b2ce53
RS
4279
4280 INSN_UID (insn) = cur_insn_uid++;
4281
4282 add_insn_after (insn, after);
4283 return insn;
4284}
4285
4286/* Emit the label LABEL after the insn AFTER. */
4287
4288rtx
4289emit_label_after (label, after)
4290 rtx label, after;
4291{
4292 /* This can be called twice for the same label
4293 as a result of the confusion that follows a syntax error!
4294 So make it harmless. */
4295 if (INSN_UID (label) == 0)
4296 {
4297 INSN_UID (label) = cur_insn_uid++;
4298 add_insn_after (label, after);
4299 }
4300
4301 return label;
4302}
4303
4304/* Emit a note of subtype SUBTYPE after the insn AFTER. */
4305
4306rtx
4307emit_note_after (subtype, after)
4308 int subtype;
4309 rtx after;
4310{
b3694847 4311 rtx note = rtx_alloc (NOTE);
23b2ce53
RS
4312 INSN_UID (note) = cur_insn_uid++;
4313 NOTE_SOURCE_FILE (note) = 0;
4314 NOTE_LINE_NUMBER (note) = subtype;
ba4f7968 4315 BLOCK_FOR_INSN (note) = NULL;
23b2ce53
RS
4316 add_insn_after (note, after);
4317 return note;
4318}
4319
4320/* Emit a line note for FILE and LINE after the insn AFTER. */
4321
4322rtx
4323emit_line_note_after (file, line, after)
3cce094d 4324 const char *file;
23b2ce53
RS
4325 int line;
4326 rtx after;
4327{
b3694847 4328 rtx note;
23b2ce53
RS
4329
4330 if (no_line_numbers && line > 0)
4331 {
4332 cur_insn_uid++;
4333 return 0;
4334 }
4335
68252e27 4336 note = rtx_alloc (NOTE);
23b2ce53
RS
4337 INSN_UID (note) = cur_insn_uid++;
4338 NOTE_SOURCE_FILE (note) = file;
4339 NOTE_LINE_NUMBER (note) = line;
ba4f7968 4340 BLOCK_FOR_INSN (note) = NULL;
23b2ce53
RS
4341 add_insn_after (note, after);
4342 return note;
4343}
4344\f
0d682900
JH
4345/* Like emit_insn_after, but set INSN_SCOPE according to SCOPE. */
4346rtx
4347emit_insn_after_scope (pattern, after, scope)
4348 rtx pattern, after;
4349 tree scope;
4350{
4351 rtx last = emit_insn_after (pattern, after);
0d682900 4352
2f937369
DM
4353 after = NEXT_INSN (after);
4354 while (1)
4355 {
d11cea13
DM
4356 if (active_insn_p (after))
4357 INSN_SCOPE (after) = scope;
2f937369
DM
4358 if (after == last)
4359 break;
4360 after = NEXT_INSN (after);
4361 }
0d682900
JH
4362 return last;
4363}
4364
4365/* Like emit_jump_insn_after, but set INSN_SCOPE according to SCOPE. */
4366rtx
4367emit_jump_insn_after_scope (pattern, after, scope)
4368 rtx pattern, after;
4369 tree scope;
4370{
4371 rtx last = emit_jump_insn_after (pattern, after);
2f937369
DM
4372
4373 after = NEXT_INSN (after);
4374 while (1)
4375 {
d11cea13
DM
4376 if (active_insn_p (after))
4377 INSN_SCOPE (after) = scope;
2f937369
DM
4378 if (after == last)
4379 break;
4380 after = NEXT_INSN (after);
4381 }
0d682900
JH
4382 return last;
4383}
4384
4385/* Like emit_call_insn_after, but set INSN_SCOPE according to SCOPE. */
4386rtx
4387emit_call_insn_after_scope (pattern, after, scope)
4388 rtx pattern, after;
4389 tree scope;
4390{
4391 rtx last = emit_call_insn_after (pattern, after);
2f937369
DM
4392
4393 after = NEXT_INSN (after);
4394 while (1)
4395 {
d11cea13
DM
4396 if (active_insn_p (after))
4397 INSN_SCOPE (after) = scope;
2f937369
DM
4398 if (after == last)
4399 break;
4400 after = NEXT_INSN (after);
4401 }
0d682900
JH
4402 return last;
4403}
4404
4405/* Like emit_insn_before, but set INSN_SCOPE according to SCOPE. */
4406rtx
4407emit_insn_before_scope (pattern, before, scope)
4408 rtx pattern, before;
4409 tree scope;
4410{
4411 rtx first = PREV_INSN (before);
4412 rtx last = emit_insn_before (pattern, before);
4413
2f937369
DM
4414 first = NEXT_INSN (first);
4415 while (1)
4416 {
d11cea13
DM
4417 if (active_insn_p (first))
4418 INSN_SCOPE (first) = scope;
2f937369
DM
4419 if (first == last)
4420 break;
4421 first = NEXT_INSN (first);
4422 }
0d682900
JH
4423 return last;
4424}
4425\f
2f937369
DM
4426/* Take X and emit it at the end of the doubly-linked
4427 INSN list.
23b2ce53
RS
4428
4429 Returns the last insn emitted. */
4430
4431rtx
2f937369
DM
4432emit_insn (x)
4433 rtx x;
23b2ce53 4434{
2f937369
DM
4435 rtx last = last_insn;
4436 rtx insn;
23b2ce53 4437
2f937369
DM
4438 if (x == NULL_RTX)
4439 return last;
23b2ce53 4440
2f937369
DM
4441 switch (GET_CODE (x))
4442 {
4443 case INSN:
4444 case JUMP_INSN:
4445 case CALL_INSN:
4446 case CODE_LABEL:
4447 case BARRIER:
4448 case NOTE:
4449 insn = x;
4450 while (insn)
23b2ce53 4451 {
2f937369 4452 rtx next = NEXT_INSN (insn);
23b2ce53 4453 add_insn (insn);
2f937369
DM
4454 last = insn;
4455 insn = next;
23b2ce53 4456 }
2f937369 4457 break;
23b2ce53 4458
2f937369
DM
4459#ifdef ENABLE_RTL_CHECKING
4460 case SEQUENCE:
4461 abort ();
4462 break;
4463#endif
23b2ce53 4464
2f937369
DM
4465 default:
4466 last = make_insn_raw (x);
4467 add_insn (last);
4468 break;
23b2ce53
RS
4469 }
4470
4471 return last;
4472}
4473
2f937369
DM
4474/* Make an insn of code JUMP_INSN with pattern X
4475 and add it to the end of the doubly-linked list. */
23b2ce53
RS
4476
4477rtx
2f937369
DM
4478emit_jump_insn (x)
4479 rtx x;
23b2ce53 4480{
2f937369 4481 rtx last, insn;
23b2ce53 4482
2f937369 4483 switch (GET_CODE (x))
23b2ce53 4484 {
2f937369
DM
4485 case INSN:
4486 case JUMP_INSN:
4487 case CALL_INSN:
4488 case CODE_LABEL:
4489 case BARRIER:
4490 case NOTE:
4491 insn = x;
4492 while (insn)
4493 {
4494 rtx next = NEXT_INSN (insn);
4495 add_insn (insn);
4496 last = insn;
4497 insn = next;
4498 }
4499 break;
e0a5c5eb 4500
2f937369
DM
4501#ifdef ENABLE_RTL_CHECKING
4502 case SEQUENCE:
4503 abort ();
4504 break;
4505#endif
e0a5c5eb 4506
2f937369
DM
4507 default:
4508 last = make_jump_insn_raw (x);
4509 add_insn (last);
4510 break;
3c030e88 4511 }
e0a5c5eb
RS
4512
4513 return last;
4514}
4515
2f937369 4516/* Make an insn of code CALL_INSN with pattern X
23b2ce53
RS
4517 and add it to the end of the doubly-linked list. */
4518
4519rtx
2f937369
DM
4520emit_call_insn (x)
4521 rtx x;
23b2ce53 4522{
2f937369
DM
4523 rtx insn;
4524
4525 switch (GET_CODE (x))
23b2ce53 4526 {
2f937369
DM
4527 case INSN:
4528 case JUMP_INSN:
4529 case CALL_INSN:
4530 case CODE_LABEL:
4531 case BARRIER:
4532 case NOTE:
4533 insn = emit_insn (x);
4534 break;
23b2ce53 4535
2f937369
DM
4536#ifdef ENABLE_RTL_CHECKING
4537 case SEQUENCE:
4538 abort ();
4539 break;
4540#endif
23b2ce53 4541
2f937369
DM
4542 default:
4543 insn = make_call_insn_raw (x);
23b2ce53 4544 add_insn (insn);
2f937369 4545 break;
23b2ce53 4546 }
2f937369
DM
4547
4548 return insn;
23b2ce53
RS
4549}
4550
4551/* Add the label LABEL to the end of the doubly-linked list. */
4552
4553rtx
4554emit_label (label)
4555 rtx label;
4556{
4557 /* This can be called twice for the same label
4558 as a result of the confusion that follows a syntax error!
4559 So make it harmless. */
4560 if (INSN_UID (label) == 0)
4561 {
4562 INSN_UID (label) = cur_insn_uid++;
4563 add_insn (label);
4564 }
4565 return label;
4566}
4567
4568/* Make an insn of code BARRIER
4569 and add it to the end of the doubly-linked list. */
4570
4571rtx
4572emit_barrier ()
4573{
b3694847 4574 rtx barrier = rtx_alloc (BARRIER);
23b2ce53
RS
4575 INSN_UID (barrier) = cur_insn_uid++;
4576 add_insn (barrier);
4577 return barrier;
4578}
4579
4580/* Make an insn of code NOTE
4581 with data-fields specified by FILE and LINE
4582 and add it to the end of the doubly-linked list,
4583 but only if line-numbers are desired for debugging info. */
4584
4585rtx
4586emit_line_note (file, line)
3cce094d 4587 const char *file;
23b2ce53
RS
4588 int line;
4589{
3f1d071b 4590 set_file_and_line_for_stmt (file, line);
23b2ce53
RS
4591
4592#if 0
4593 if (no_line_numbers)
4594 return 0;
4595#endif
4596
4597 return emit_note (file, line);
4598}
4599
4600/* Make an insn of code NOTE
4601 with data-fields specified by FILE and LINE
4602 and add it to the end of the doubly-linked list.
4603 If it is a line-number NOTE, omit it if it matches the previous one. */
4604
4605rtx
4606emit_note (file, line)
3cce094d 4607 const char *file;
23b2ce53
RS
4608 int line;
4609{
b3694847 4610 rtx note;
23b2ce53
RS
4611
4612 if (line > 0)
4613 {
4614 if (file && last_filename && !strcmp (file, last_filename)
4615 && line == last_linenum)
4616 return 0;
4617 last_filename = file;
4618 last_linenum = line;
4619 }
4620
4621 if (no_line_numbers && line > 0)
4622 {
4623 cur_insn_uid++;
4624 return 0;
4625 }
4626
4627 note = rtx_alloc (NOTE);
4628 INSN_UID (note) = cur_insn_uid++;
4629 NOTE_SOURCE_FILE (note) = file;
4630 NOTE_LINE_NUMBER (note) = line;
ba4f7968 4631 BLOCK_FOR_INSN (note) = NULL;
23b2ce53
RS
4632 add_insn (note);
4633 return note;
4634}
4635
fe77a034 4636/* Emit a NOTE, and don't omit it even if LINE is the previous note. */
23b2ce53
RS
4637
4638rtx
4639emit_line_note_force (file, line)
3cce094d 4640 const char *file;
23b2ce53
RS
4641 int line;
4642{
4643 last_linenum = -1;
4644 return emit_line_note (file, line);
4645}
4646
4647/* Cause next statement to emit a line note even if the line number
4648 has not changed. This is used at the beginning of a function. */
4649
4650void
4651force_next_line_note ()
4652{
4653 last_linenum = -1;
4654}
87b47c85
AM
4655
4656/* Place a note of KIND on insn INSN with DATUM as the datum. If a
30f7a378 4657 note of this type already exists, remove it first. */
87b47c85 4658
3d238248 4659rtx
87b47c85
AM
4660set_unique_reg_note (insn, kind, datum)
4661 rtx insn;
4662 enum reg_note kind;
4663 rtx datum;
4664{
4665 rtx note = find_reg_note (insn, kind, NULL_RTX);
4666
52488da1
JW
4667 switch (kind)
4668 {
4669 case REG_EQUAL:
4670 case REG_EQUIV:
4671 /* Don't add REG_EQUAL/REG_EQUIV notes if the insn
4672 has multiple sets (some callers assume single_set
4673 means the insn only has one set, when in fact it
4674 means the insn only has one * useful * set). */
4675 if (GET_CODE (PATTERN (insn)) == PARALLEL && multiple_sets (insn))
4676 {
4677 if (note)
4678 abort ();
4679 return NULL_RTX;
4680 }
4681
4682 /* Don't add ASM_OPERAND REG_EQUAL/REG_EQUIV notes.
4683 It serves no useful purpose and breaks eliminate_regs. */
4684 if (GET_CODE (datum) == ASM_OPERANDS)
4685 return NULL_RTX;
4686 break;
4687
4688 default:
4689 break;
4690 }
3d238248 4691
750c9258 4692 if (note)
3d238248
JJ
4693 {
4694 XEXP (note, 0) = datum;
4695 return note;
4696 }
87b47c85
AM
4697
4698 REG_NOTES (insn) = gen_rtx_EXPR_LIST (kind, datum, REG_NOTES (insn));
3d238248 4699 return REG_NOTES (insn);
87b47c85 4700}
23b2ce53
RS
4701\f
4702/* Return an indication of which type of insn should have X as a body.
4703 The value is CODE_LABEL, INSN, CALL_INSN or JUMP_INSN. */
4704
4705enum rtx_code
4706classify_insn (x)
4707 rtx x;
4708{
4709 if (GET_CODE (x) == CODE_LABEL)
4710 return CODE_LABEL;
4711 if (GET_CODE (x) == CALL)
4712 return CALL_INSN;
4713 if (GET_CODE (x) == RETURN)
4714 return JUMP_INSN;
4715 if (GET_CODE (x) == SET)
4716 {
4717 if (SET_DEST (x) == pc_rtx)
4718 return JUMP_INSN;
4719 else if (GET_CODE (SET_SRC (x)) == CALL)
4720 return CALL_INSN;
4721 else
4722 return INSN;
4723 }
4724 if (GET_CODE (x) == PARALLEL)
4725 {
b3694847 4726 int j;
23b2ce53
RS
4727 for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
4728 if (GET_CODE (XVECEXP (x, 0, j)) == CALL)
4729 return CALL_INSN;
4730 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
4731 && SET_DEST (XVECEXP (x, 0, j)) == pc_rtx)
4732 return JUMP_INSN;
4733 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
4734 && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == CALL)
4735 return CALL_INSN;
4736 }
4737 return INSN;
4738}
4739
4740/* Emit the rtl pattern X as an appropriate kind of insn.
4741 If X is a label, it is simply added into the insn chain. */
4742
4743rtx
4744emit (x)
4745 rtx x;
4746{
4747 enum rtx_code code = classify_insn (x);
4748
4749 if (code == CODE_LABEL)
4750 return emit_label (x);
4751 else if (code == INSN)
4752 return emit_insn (x);
4753 else if (code == JUMP_INSN)
4754 {
b3694847 4755 rtx insn = emit_jump_insn (x);
7f1c097d 4756 if (any_uncondjump_p (insn) || GET_CODE (x) == RETURN)
23b2ce53
RS
4757 return emit_barrier ();
4758 return insn;
4759 }
4760 else if (code == CALL_INSN)
4761 return emit_call_insn (x);
4762 else
4763 abort ();
4764}
4765\f
e2500fed
GK
4766/* Space for free sequence stack entries. */
4767static GTY ((deletable (""))) struct sequence_stack *free_sequence_stack;
4768
5c7a310f
MM
4769/* Begin emitting insns to a sequence which can be packaged in an
4770 RTL_EXPR. If this sequence will contain something that might cause
4771 the compiler to pop arguments to function calls (because those
4772 pops have previously been deferred; see INHIBIT_DEFER_POP for more
4773 details), use do_pending_stack_adjust before calling this function.
4774 That will ensure that the deferred pops are not accidentally
4eb00163 4775 emitted in the middle of this sequence. */
23b2ce53
RS
4776
4777void
4778start_sequence ()
4779{
4780 struct sequence_stack *tem;
4781
e2500fed
GK
4782 if (free_sequence_stack != NULL)
4783 {
4784 tem = free_sequence_stack;
4785 free_sequence_stack = tem->next;
4786 }
4787 else
4788 tem = (struct sequence_stack *) ggc_alloc (sizeof (struct sequence_stack));
23b2ce53 4789
49ad7cfa 4790 tem->next = seq_stack;
23b2ce53
RS
4791 tem->first = first_insn;
4792 tem->last = last_insn;
591ccf92 4793 tem->sequence_rtl_expr = seq_rtl_expr;
23b2ce53 4794
49ad7cfa 4795 seq_stack = tem;
23b2ce53
RS
4796
4797 first_insn = 0;
4798 last_insn = 0;
4799}
4800
591ccf92
MM
4801/* Similarly, but indicate that this sequence will be placed in T, an
4802 RTL_EXPR. See the documentation for start_sequence for more
4803 information about how to use this function. */
4804
4805void
4806start_sequence_for_rtl_expr (t)
4807 tree t;
4808{
4809 start_sequence ();
4810
4811 seq_rtl_expr = t;
4812}
4813
5c7a310f
MM
4814/* Set up the insn chain starting with FIRST as the current sequence,
4815 saving the previously current one. See the documentation for
4816 start_sequence for more information about how to use this function. */
23b2ce53
RS
4817
4818void
4819push_to_sequence (first)
4820 rtx first;
4821{
4822 rtx last;
4823
4824 start_sequence ();
4825
4826 for (last = first; last && NEXT_INSN (last); last = NEXT_INSN (last));
4827
4828 first_insn = first;
4829 last_insn = last;
4830}
4831
c14f7160
ML
4832/* Set up the insn chain from a chain stort in FIRST to LAST. */
4833
4834void
4835push_to_full_sequence (first, last)
4836 rtx first, last;
4837{
4838 start_sequence ();
4839 first_insn = first;
4840 last_insn = last;
4841 /* We really should have the end of the insn chain here. */
4842 if (last && NEXT_INSN (last))
4843 abort ();
4844}
4845
f15ae3a1
TW
4846/* Set up the outer-level insn chain
4847 as the current sequence, saving the previously current one. */
4848
4849void
4850push_topmost_sequence ()
4851{
aefdd5ab 4852 struct sequence_stack *stack, *top = NULL;
f15ae3a1
TW
4853
4854 start_sequence ();
4855
49ad7cfa 4856 for (stack = seq_stack; stack; stack = stack->next)
f15ae3a1
TW
4857 top = stack;
4858
4859 first_insn = top->first;
4860 last_insn = top->last;
591ccf92 4861 seq_rtl_expr = top->sequence_rtl_expr;
f15ae3a1
TW
4862}
4863
4864/* After emitting to the outer-level insn chain, update the outer-level
4865 insn chain, and restore the previous saved state. */
4866
4867void
4868pop_topmost_sequence ()
4869{
aefdd5ab 4870 struct sequence_stack *stack, *top = NULL;
f15ae3a1 4871
49ad7cfa 4872 for (stack = seq_stack; stack; stack = stack->next)
f15ae3a1
TW
4873 top = stack;
4874
4875 top->first = first_insn;
4876 top->last = last_insn;
591ccf92 4877 /* ??? Why don't we save seq_rtl_expr here? */
f15ae3a1
TW
4878
4879 end_sequence ();
4880}
4881
23b2ce53
RS
4882/* After emitting to a sequence, restore previous saved state.
4883
5c7a310f 4884 To get the contents of the sequence just made, you must call
2f937369 4885 `get_insns' *before* calling here.
5c7a310f
MM
4886
4887 If the compiler might have deferred popping arguments while
4888 generating this sequence, and this sequence will not be immediately
4889 inserted into the instruction stream, use do_pending_stack_adjust
2f937369 4890 before calling get_insns. That will ensure that the deferred
5c7a310f
MM
4891 pops are inserted into this sequence, and not into some random
4892 location in the instruction stream. See INHIBIT_DEFER_POP for more
4893 information about deferred popping of arguments. */
23b2ce53
RS
4894
4895void
4896end_sequence ()
4897{
49ad7cfa 4898 struct sequence_stack *tem = seq_stack;
23b2ce53
RS
4899
4900 first_insn = tem->first;
4901 last_insn = tem->last;
591ccf92 4902 seq_rtl_expr = tem->sequence_rtl_expr;
49ad7cfa 4903 seq_stack = tem->next;
23b2ce53 4904
e2500fed
GK
4905 memset (tem, 0, sizeof (*tem));
4906 tem->next = free_sequence_stack;
4907 free_sequence_stack = tem;
23b2ce53
RS
4908}
4909
c14f7160
ML
4910/* This works like end_sequence, but records the old sequence in FIRST
4911 and LAST. */
4912
4913void
4914end_full_sequence (first, last)
4915 rtx *first, *last;
4916{
4917 *first = first_insn;
4918 *last = last_insn;
68252e27 4919 end_sequence ();
c14f7160
ML
4920}
4921
23b2ce53
RS
4922/* Return 1 if currently emitting into a sequence. */
4923
4924int
4925in_sequence_p ()
4926{
49ad7cfa 4927 return seq_stack != 0;
23b2ce53 4928}
23b2ce53 4929\f
59ec66dc
MM
4930/* Put the various virtual registers into REGNO_REG_RTX. */
4931
4932void
49ad7cfa
BS
4933init_virtual_regs (es)
4934 struct emit_status *es;
59ec66dc 4935{
49ad7cfa
BS
4936 rtx *ptr = es->x_regno_reg_rtx;
4937 ptr[VIRTUAL_INCOMING_ARGS_REGNUM] = virtual_incoming_args_rtx;
4938 ptr[VIRTUAL_STACK_VARS_REGNUM] = virtual_stack_vars_rtx;
4939 ptr[VIRTUAL_STACK_DYNAMIC_REGNUM] = virtual_stack_dynamic_rtx;
4940 ptr[VIRTUAL_OUTGOING_ARGS_REGNUM] = virtual_outgoing_args_rtx;
4941 ptr[VIRTUAL_CFA_REGNUM] = virtual_cfa_rtx;
4942}
4943
da43a810
BS
4944\f
4945/* Used by copy_insn_1 to avoid copying SCRATCHes more than once. */
4946static rtx copy_insn_scratch_in[MAX_RECOG_OPERANDS];
4947static rtx copy_insn_scratch_out[MAX_RECOG_OPERANDS];
4948static int copy_insn_n_scratches;
4949
4950/* When an insn is being copied by copy_insn_1, this is nonzero if we have
4951 copied an ASM_OPERANDS.
4952 In that case, it is the original input-operand vector. */
4953static rtvec orig_asm_operands_vector;
4954
4955/* When an insn is being copied by copy_insn_1, this is nonzero if we have
4956 copied an ASM_OPERANDS.
4957 In that case, it is the copied input-operand vector. */
4958static rtvec copy_asm_operands_vector;
4959
4960/* Likewise for the constraints vector. */
4961static rtvec orig_asm_constraints_vector;
4962static rtvec copy_asm_constraints_vector;
4963
4964/* Recursively create a new copy of an rtx for copy_insn.
4965 This function differs from copy_rtx in that it handles SCRATCHes and
4966 ASM_OPERANDs properly.
4967 Normally, this function is not used directly; use copy_insn as front end.
4968 However, you could first copy an insn pattern with copy_insn and then use
4969 this function afterwards to properly copy any REG_NOTEs containing
4970 SCRATCHes. */
4971
4972rtx
4973copy_insn_1 (orig)
b3694847 4974 rtx orig;
da43a810 4975{
b3694847
SS
4976 rtx copy;
4977 int i, j;
4978 RTX_CODE code;
4979 const char *format_ptr;
da43a810
BS
4980
4981 code = GET_CODE (orig);
4982
4983 switch (code)
4984 {
4985 case REG:
4986 case QUEUED:
4987 case CONST_INT:
4988 case CONST_DOUBLE:
69ef87e2 4989 case CONST_VECTOR:
da43a810
BS
4990 case SYMBOL_REF:
4991 case CODE_LABEL:
4992 case PC:
4993 case CC0:
4994 case ADDRESSOF:
4995 return orig;
4996
4997 case SCRATCH:
4998 for (i = 0; i < copy_insn_n_scratches; i++)
4999 if (copy_insn_scratch_in[i] == orig)
5000 return copy_insn_scratch_out[i];
5001 break;
5002
5003 case CONST:
5004 /* CONST can be shared if it contains a SYMBOL_REF. If it contains
5005 a LABEL_REF, it isn't sharable. */
5006 if (GET_CODE (XEXP (orig, 0)) == PLUS
5007 && GET_CODE (XEXP (XEXP (orig, 0), 0)) == SYMBOL_REF
5008 && GET_CODE (XEXP (XEXP (orig, 0), 1)) == CONST_INT)
5009 return orig;
5010 break;
750c9258 5011
da43a810
BS
5012 /* A MEM with a constant address is not sharable. The problem is that
5013 the constant address may need to be reloaded. If the mem is shared,
5014 then reloading one copy of this mem will cause all copies to appear
5015 to have been reloaded. */
5016
5017 default:
5018 break;
5019 }
5020
5021 copy = rtx_alloc (code);
5022
5023 /* Copy the various flags, and other information. We assume that
5024 all fields need copying, and then clear the fields that should
5025 not be copied. That is the sensible default behavior, and forces
5026 us to explicitly document why we are *not* copying a flag. */
5027 memcpy (copy, orig, sizeof (struct rtx_def) - sizeof (rtunion));
5028
5029 /* We do not copy the USED flag, which is used as a mark bit during
5030 walks over the RTL. */
2adc7f12 5031 RTX_FLAG (copy, used) = 0;
da43a810
BS
5032
5033 /* We do not copy JUMP, CALL, or FRAME_RELATED for INSNs. */
5034 if (GET_RTX_CLASS (code) == 'i')
5035 {
2adc7f12
JJ
5036 RTX_FLAG (copy, jump) = 0;
5037 RTX_FLAG (copy, call) = 0;
5038 RTX_FLAG (copy, frame_related) = 0;
da43a810 5039 }
750c9258 5040
da43a810
BS
5041 format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
5042
5043 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
5044 {
e63db8f6 5045 copy->fld[i] = orig->fld[i];
da43a810
BS
5046 switch (*format_ptr++)
5047 {
5048 case 'e':
da43a810
BS
5049 if (XEXP (orig, i) != NULL)
5050 XEXP (copy, i) = copy_insn_1 (XEXP (orig, i));
5051 break;
5052
da43a810
BS
5053 case 'E':
5054 case 'V':
da43a810
BS
5055 if (XVEC (orig, i) == orig_asm_constraints_vector)
5056 XVEC (copy, i) = copy_asm_constraints_vector;
5057 else if (XVEC (orig, i) == orig_asm_operands_vector)
5058 XVEC (copy, i) = copy_asm_operands_vector;
5059 else if (XVEC (orig, i) != NULL)
5060 {
5061 XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
5062 for (j = 0; j < XVECLEN (copy, i); j++)
5063 XVECEXP (copy, i, j) = copy_insn_1 (XVECEXP (orig, i, j));
5064 }
5065 break;
5066
da43a810 5067 case 't':
da43a810 5068 case 'w':
da43a810 5069 case 'i':
da43a810
BS
5070 case 's':
5071 case 'S':
e63db8f6
BS
5072 case 'u':
5073 case '0':
5074 /* These are left unchanged. */
da43a810
BS
5075 break;
5076
5077 default:
5078 abort ();
5079 }
5080 }
5081
5082 if (code == SCRATCH)
5083 {
5084 i = copy_insn_n_scratches++;
5085 if (i >= MAX_RECOG_OPERANDS)
5086 abort ();
5087 copy_insn_scratch_in[i] = orig;
5088 copy_insn_scratch_out[i] = copy;
5089 }
5090 else if (code == ASM_OPERANDS)
5091 {
6462bb43
AO
5092 orig_asm_operands_vector = ASM_OPERANDS_INPUT_VEC (orig);
5093 copy_asm_operands_vector = ASM_OPERANDS_INPUT_VEC (copy);
5094 orig_asm_constraints_vector = ASM_OPERANDS_INPUT_CONSTRAINT_VEC (orig);
5095 copy_asm_constraints_vector = ASM_OPERANDS_INPUT_CONSTRAINT_VEC (copy);
da43a810
BS
5096 }
5097
5098 return copy;
5099}
5100
5101/* Create a new copy of an rtx.
5102 This function differs from copy_rtx in that it handles SCRATCHes and
5103 ASM_OPERANDs properly.
5104 INSN doesn't really have to be a full INSN; it could be just the
5105 pattern. */
5106rtx
5107copy_insn (insn)
5108 rtx insn;
5109{
5110 copy_insn_n_scratches = 0;
5111 orig_asm_operands_vector = 0;
5112 orig_asm_constraints_vector = 0;
5113 copy_asm_operands_vector = 0;
5114 copy_asm_constraints_vector = 0;
5115 return copy_insn_1 (insn);
5116}
59ec66dc 5117
23b2ce53
RS
5118/* Initialize data structures and variables in this file
5119 before generating rtl for each function. */
5120
5121void
5122init_emit ()
5123{
01d939e8 5124 struct function *f = cfun;
23b2ce53 5125
e2500fed 5126 f->emit = (struct emit_status *) ggc_alloc (sizeof (struct emit_status));
23b2ce53
RS
5127 first_insn = NULL;
5128 last_insn = NULL;
591ccf92 5129 seq_rtl_expr = NULL;
23b2ce53
RS
5130 cur_insn_uid = 1;
5131 reg_rtx_no = LAST_VIRTUAL_REGISTER + 1;
5132 last_linenum = 0;
5133 last_filename = 0;
5134 first_label_num = label_num;
5135 last_label_num = 0;
49ad7cfa 5136 seq_stack = NULL;
23b2ce53 5137
23b2ce53
RS
5138 /* Init the tables that describe all the pseudo regs. */
5139
3502dc9c 5140 f->emit->regno_pointer_align_length = LAST_VIRTUAL_REGISTER + 101;
23b2ce53 5141
49ad7cfa 5142 f->emit->regno_pointer_align
e2500fed
GK
5143 = (unsigned char *) ggc_alloc_cleared (f->emit->regno_pointer_align_length
5144 * sizeof (unsigned char));
86fe05e0 5145
750c9258 5146 regno_reg_rtx
e2500fed
GK
5147 = (rtx *) ggc_alloc_cleared (f->emit->regno_pointer_align_length
5148 * sizeof (rtx));
0d4903b8
RK
5149
5150 f->emit->regno_decl
e2500fed
GK
5151 = (tree *) ggc_alloc_cleared (f->emit->regno_pointer_align_length
5152 * sizeof (tree));
23b2ce53 5153
e50126e8 5154 /* Put copies of all the hard registers into regno_reg_rtx. */
6cde4876
JL
5155 memcpy (regno_reg_rtx,
5156 static_regno_reg_rtx,
5157 FIRST_PSEUDO_REGISTER * sizeof (rtx));
e50126e8 5158
23b2ce53 5159 /* Put copies of all the virtual register rtx into regno_reg_rtx. */
49ad7cfa 5160 init_virtual_regs (f->emit);
740ab4a2
RK
5161
5162 /* Indicate that the virtual registers and stack locations are
5163 all pointers. */
3502dc9c
JDA
5164 REG_POINTER (stack_pointer_rtx) = 1;
5165 REG_POINTER (frame_pointer_rtx) = 1;
5166 REG_POINTER (hard_frame_pointer_rtx) = 1;
5167 REG_POINTER (arg_pointer_rtx) = 1;
740ab4a2 5168
3502dc9c
JDA
5169 REG_POINTER (virtual_incoming_args_rtx) = 1;
5170 REG_POINTER (virtual_stack_vars_rtx) = 1;
5171 REG_POINTER (virtual_stack_dynamic_rtx) = 1;
5172 REG_POINTER (virtual_outgoing_args_rtx) = 1;
5173 REG_POINTER (virtual_cfa_rtx) = 1;
5e82e7bd 5174
86fe05e0 5175#ifdef STACK_BOUNDARY
bdb429a5
RK
5176 REGNO_POINTER_ALIGN (STACK_POINTER_REGNUM) = STACK_BOUNDARY;
5177 REGNO_POINTER_ALIGN (FRAME_POINTER_REGNUM) = STACK_BOUNDARY;
5178 REGNO_POINTER_ALIGN (HARD_FRAME_POINTER_REGNUM) = STACK_BOUNDARY;
5179 REGNO_POINTER_ALIGN (ARG_POINTER_REGNUM) = STACK_BOUNDARY;
5180
5181 REGNO_POINTER_ALIGN (VIRTUAL_INCOMING_ARGS_REGNUM) = STACK_BOUNDARY;
5182 REGNO_POINTER_ALIGN (VIRTUAL_STACK_VARS_REGNUM) = STACK_BOUNDARY;
5183 REGNO_POINTER_ALIGN (VIRTUAL_STACK_DYNAMIC_REGNUM) = STACK_BOUNDARY;
5184 REGNO_POINTER_ALIGN (VIRTUAL_OUTGOING_ARGS_REGNUM) = STACK_BOUNDARY;
5185 REGNO_POINTER_ALIGN (VIRTUAL_CFA_REGNUM) = BITS_PER_WORD;
86fe05e0
RK
5186#endif
5187
5e82e7bd
JVA
5188#ifdef INIT_EXPANDERS
5189 INIT_EXPANDERS;
5190#endif
23b2ce53
RS
5191}
5192
ff88fe10 5193/* Generate the constant 0. */
69ef87e2
AH
5194
5195static rtx
ff88fe10 5196gen_const_vector_0 (mode)
69ef87e2
AH
5197 enum machine_mode mode;
5198{
5199 rtx tem;
5200 rtvec v;
5201 int units, i;
5202 enum machine_mode inner;
5203
5204 units = GET_MODE_NUNITS (mode);
5205 inner = GET_MODE_INNER (mode);
5206
5207 v = rtvec_alloc (units);
5208
5209 /* We need to call this function after we to set CONST0_RTX first. */
5210 if (!CONST0_RTX (inner))
5211 abort ();
5212
5213 for (i = 0; i < units; ++i)
5214 RTVEC_ELT (v, i) = CONST0_RTX (inner);
5215
a06e3c40 5216 tem = gen_rtx_raw_CONST_VECTOR (mode, v);
69ef87e2
AH
5217 return tem;
5218}
5219
a06e3c40
R
5220/* Generate a vector like gen_rtx_raw_CONST_VEC, but use the zero vector when
5221 all elements are zero. */
5222rtx
5223gen_rtx_CONST_VECTOR (mode, v)
5224 enum machine_mode mode;
5225 rtvec v;
5226{
5227 rtx inner_zero = CONST0_RTX (GET_MODE_INNER (mode));
5228 int i;
5229
5230 for (i = GET_MODE_NUNITS (mode) - 1; i >= 0; i--)
5231 if (RTVEC_ELT (v, i) != inner_zero)
5232 return gen_rtx_raw_CONST_VECTOR (mode, v);
5233 return CONST0_RTX (mode);
5234}
5235
23b2ce53
RS
5236/* Create some permanent unique rtl objects shared between all functions.
5237 LINE_NUMBERS is nonzero if line numbers are to be generated. */
5238
5239void
5240init_emit_once (line_numbers)
5241 int line_numbers;
5242{
5243 int i;
5244 enum machine_mode mode;
9ec36da5 5245 enum machine_mode double_mode;
23b2ce53 5246
5692c7bc
ZW
5247 /* Initialize the CONST_INT, CONST_DOUBLE, and memory attribute hash
5248 tables. */
750c9258 5249 const_int_htab = htab_create (37, const_int_htab_hash,
67673f5c 5250 const_int_htab_eq, NULL);
173b24b9 5251
5692c7bc
ZW
5252 const_double_htab = htab_create (37, const_double_htab_hash,
5253 const_double_htab_eq, NULL);
5692c7bc 5254
173b24b9
RK
5255 mem_attrs_htab = htab_create (37, mem_attrs_htab_hash,
5256 mem_attrs_htab_eq, NULL);
67673f5c 5257
23b2ce53
RS
5258 no_line_numbers = ! line_numbers;
5259
43fa6302
AS
5260 /* Compute the word and byte modes. */
5261
5262 byte_mode = VOIDmode;
5263 word_mode = VOIDmode;
5264 double_mode = VOIDmode;
5265
5266 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
5267 mode = GET_MODE_WIDER_MODE (mode))
5268 {
5269 if (GET_MODE_BITSIZE (mode) == BITS_PER_UNIT
5270 && byte_mode == VOIDmode)
5271 byte_mode = mode;
5272
5273 if (GET_MODE_BITSIZE (mode) == BITS_PER_WORD
5274 && word_mode == VOIDmode)
5275 word_mode = mode;
5276 }
5277
43fa6302
AS
5278 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
5279 mode = GET_MODE_WIDER_MODE (mode))
5280 {
5281 if (GET_MODE_BITSIZE (mode) == DOUBLE_TYPE_SIZE
5282 && double_mode == VOIDmode)
5283 double_mode = mode;
5284 }
5285
5286 ptr_mode = mode_for_size (POINTER_SIZE, GET_MODE_CLASS (Pmode), 0);
5287
5da077de
AS
5288 /* Assign register numbers to the globally defined register rtx.
5289 This must be done at runtime because the register number field
5290 is in a union and some compilers can't initialize unions. */
5291
5292 pc_rtx = gen_rtx (PC, VOIDmode);
5293 cc0_rtx = gen_rtx (CC0, VOIDmode);
08394eef
BS
5294 stack_pointer_rtx = gen_raw_REG (Pmode, STACK_POINTER_REGNUM);
5295 frame_pointer_rtx = gen_raw_REG (Pmode, FRAME_POINTER_REGNUM);
5da077de 5296 if (hard_frame_pointer_rtx == 0)
750c9258 5297 hard_frame_pointer_rtx = gen_raw_REG (Pmode,
08394eef 5298 HARD_FRAME_POINTER_REGNUM);
5da077de 5299 if (arg_pointer_rtx == 0)
08394eef 5300 arg_pointer_rtx = gen_raw_REG (Pmode, ARG_POINTER_REGNUM);
750c9258 5301 virtual_incoming_args_rtx =
08394eef 5302 gen_raw_REG (Pmode, VIRTUAL_INCOMING_ARGS_REGNUM);
750c9258 5303 virtual_stack_vars_rtx =
08394eef 5304 gen_raw_REG (Pmode, VIRTUAL_STACK_VARS_REGNUM);
750c9258 5305 virtual_stack_dynamic_rtx =
08394eef 5306 gen_raw_REG (Pmode, VIRTUAL_STACK_DYNAMIC_REGNUM);
750c9258
AJ
5307 virtual_outgoing_args_rtx =
5308 gen_raw_REG (Pmode, VIRTUAL_OUTGOING_ARGS_REGNUM);
08394eef 5309 virtual_cfa_rtx = gen_raw_REG (Pmode, VIRTUAL_CFA_REGNUM);
5da077de 5310
6cde4876
JL
5311 /* Initialize RTL for commonly used hard registers. These are
5312 copied into regno_reg_rtx as we begin to compile each function. */
5313 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
5314 static_regno_reg_rtx[i] = gen_raw_REG (reg_raw_mode[i], i);
5315
5da077de 5316#ifdef INIT_EXPANDERS
414c4dc4
NC
5317 /* This is to initialize {init|mark|free}_machine_status before the first
5318 call to push_function_context_to. This is needed by the Chill front
a1f300c0 5319 end which calls push_function_context_to before the first call to
5da077de
AS
5320 init_function_start. */
5321 INIT_EXPANDERS;
5322#endif
5323
23b2ce53
RS
5324 /* Create the unique rtx's for certain rtx codes and operand values. */
5325
c5c76735
JL
5326 /* Don't use gen_rtx here since gen_rtx in this case
5327 tries to use these variables. */
23b2ce53 5328 for (i = - MAX_SAVED_CONST_INT; i <= MAX_SAVED_CONST_INT; i++)
750c9258 5329 const_int_rtx[i + MAX_SAVED_CONST_INT] =
f1b690f1 5330 gen_rtx_raw_CONST_INT (VOIDmode, (HOST_WIDE_INT) i);
23b2ce53 5331
68d75312
JC
5332 if (STORE_FLAG_VALUE >= - MAX_SAVED_CONST_INT
5333 && STORE_FLAG_VALUE <= MAX_SAVED_CONST_INT)
5da077de 5334 const_true_rtx = const_int_rtx[STORE_FLAG_VALUE + MAX_SAVED_CONST_INT];
68d75312 5335 else
3b80f6ca 5336 const_true_rtx = gen_rtx_CONST_INT (VOIDmode, STORE_FLAG_VALUE);
23b2ce53 5337
5692c7bc
ZW
5338 REAL_VALUE_FROM_INT (dconst0, 0, 0, double_mode);
5339 REAL_VALUE_FROM_INT (dconst1, 1, 0, double_mode);
5340 REAL_VALUE_FROM_INT (dconst2, 2, 0, double_mode);
5341 REAL_VALUE_FROM_INT (dconstm1, -1, -1, double_mode);
23b2ce53
RS
5342
5343 for (i = 0; i <= 2; i++)
5344 {
b216cd4a
ZW
5345 REAL_VALUE_TYPE *r =
5346 (i == 0 ? &dconst0 : i == 1 ? &dconst1 : &dconst2);
5347
23b2ce53
RS
5348 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
5349 mode = GET_MODE_WIDER_MODE (mode))
5692c7bc
ZW
5350 const_tiny_rtx[i][(int) mode] =
5351 CONST_DOUBLE_FROM_REAL_VALUE (*r, mode);
23b2ce53 5352
906c4e36 5353 const_tiny_rtx[i][(int) VOIDmode] = GEN_INT (i);
23b2ce53
RS
5354
5355 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
5356 mode = GET_MODE_WIDER_MODE (mode))
906c4e36 5357 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
33d3e559
RS
5358
5359 for (mode = GET_CLASS_NARROWEST_MODE (MODE_PARTIAL_INT);
5360 mode != VOIDmode;
5361 mode = GET_MODE_WIDER_MODE (mode))
5362 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
23b2ce53
RS
5363 }
5364
69ef87e2
AH
5365 for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_INT);
5366 mode != VOIDmode;
5367 mode = GET_MODE_WIDER_MODE (mode))
ff88fe10 5368 const_tiny_rtx[0][(int) mode] = gen_const_vector_0 (mode);
69ef87e2
AH
5369
5370 for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_FLOAT);
5371 mode != VOIDmode;
5372 mode = GET_MODE_WIDER_MODE (mode))
ff88fe10 5373 const_tiny_rtx[0][(int) mode] = gen_const_vector_0 (mode);
69ef87e2 5374
dbbbbf3b
JDA
5375 for (i = (int) CCmode; i < (int) MAX_MACHINE_MODE; ++i)
5376 if (GET_MODE_CLASS ((enum machine_mode) i) == MODE_CC)
5377 const_tiny_rtx[0][i] = const0_rtx;
23b2ce53 5378
f0417c82
RH
5379 const_tiny_rtx[0][(int) BImode] = const0_rtx;
5380 if (STORE_FLAG_VALUE == 1)
5381 const_tiny_rtx[1][(int) BImode] = const1_rtx;
5382
a7e1e2ac
AO
5383#ifdef RETURN_ADDRESS_POINTER_REGNUM
5384 return_address_pointer_rtx
08394eef 5385 = gen_raw_REG (Pmode, RETURN_ADDRESS_POINTER_REGNUM);
a7e1e2ac
AO
5386#endif
5387
5388#ifdef STRUCT_VALUE
5389 struct_value_rtx = STRUCT_VALUE;
5390#else
5391 struct_value_rtx = gen_rtx_REG (Pmode, STRUCT_VALUE_REGNUM);
5392#endif
5393
5394#ifdef STRUCT_VALUE_INCOMING
5395 struct_value_incoming_rtx = STRUCT_VALUE_INCOMING;
5396#else
5397#ifdef STRUCT_VALUE_INCOMING_REGNUM
5398 struct_value_incoming_rtx
5399 = gen_rtx_REG (Pmode, STRUCT_VALUE_INCOMING_REGNUM);
5400#else
5401 struct_value_incoming_rtx = struct_value_rtx;
5402#endif
5403#endif
5404
5405#ifdef STATIC_CHAIN_REGNUM
5406 static_chain_rtx = gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM);
5407
5408#ifdef STATIC_CHAIN_INCOMING_REGNUM
5409 if (STATIC_CHAIN_INCOMING_REGNUM != STATIC_CHAIN_REGNUM)
5410 static_chain_incoming_rtx
5411 = gen_rtx_REG (Pmode, STATIC_CHAIN_INCOMING_REGNUM);
5412 else
5413#endif
5414 static_chain_incoming_rtx = static_chain_rtx;
5415#endif
5416
5417#ifdef STATIC_CHAIN
5418 static_chain_rtx = STATIC_CHAIN;
5419
5420#ifdef STATIC_CHAIN_INCOMING
5421 static_chain_incoming_rtx = STATIC_CHAIN_INCOMING;
5422#else
5423 static_chain_incoming_rtx = static_chain_rtx;
5424#endif
5425#endif
5426
848e0190 5427 if (PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM)
751551d5 5428 pic_offset_table_rtx = gen_raw_REG (Pmode, PIC_OFFSET_TABLE_REGNUM);
23b2ce53 5429}
a11759a3
JR
5430\f
5431/* Query and clear/ restore no_line_numbers. This is used by the
5432 switch / case handling in stmt.c to give proper line numbers in
5433 warnings about unreachable code. */
5434
5435int
5436force_line_numbers ()
5437{
5438 int old = no_line_numbers;
5439
5440 no_line_numbers = 0;
5441 if (old)
5442 force_next_line_note ();
5443 return old;
5444}
5445
5446void
5447restore_line_number_status (old_value)
5448 int old_value;
5449{
5450 no_line_numbers = old_value;
5451}
969d70ca
JH
5452
5453/* Produce exact duplicate of insn INSN after AFTER.
5454 Care updating of libcall regions if present. */
5455
5456rtx
5457emit_copy_of_insn_after (insn, after)
5458 rtx insn, after;
5459{
5460 rtx new;
5461 rtx note1, note2, link;
5462
5463 switch (GET_CODE (insn))
5464 {
5465 case INSN:
5466 new = emit_insn_after (copy_insn (PATTERN (insn)), after);
5467 break;
5468
5469 case JUMP_INSN:
5470 new = emit_jump_insn_after (copy_insn (PATTERN (insn)), after);
5471 break;
5472
5473 case CALL_INSN:
5474 new = emit_call_insn_after (copy_insn (PATTERN (insn)), after);
5475 if (CALL_INSN_FUNCTION_USAGE (insn))
5476 CALL_INSN_FUNCTION_USAGE (new)
5477 = copy_insn (CALL_INSN_FUNCTION_USAGE (insn));
5478 SIBLING_CALL_P (new) = SIBLING_CALL_P (insn);
5479 CONST_OR_PURE_CALL_P (new) = CONST_OR_PURE_CALL_P (insn);
5480 break;
5481
5482 default:
5483 abort ();
5484 }
5485
5486 /* Update LABEL_NUSES. */
5487 mark_jump_label (PATTERN (new), new, 0);
5488
ba4f7968
JH
5489 INSN_SCOPE (new) = INSN_SCOPE (insn);
5490
969d70ca
JH
5491 /* Copy all REG_NOTES except REG_LABEL since mark_jump_label will
5492 make them. */
5493 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
5494 if (REG_NOTE_KIND (link) != REG_LABEL)
5495 {
5496 if (GET_CODE (link) == EXPR_LIST)
5497 REG_NOTES (new)
5498 = copy_insn_1 (gen_rtx_EXPR_LIST (REG_NOTE_KIND (link),
5499 XEXP (link, 0),
5500 REG_NOTES (new)));
5501 else
5502 REG_NOTES (new)
5503 = copy_insn_1 (gen_rtx_INSN_LIST (REG_NOTE_KIND (link),
5504 XEXP (link, 0),
5505 REG_NOTES (new)));
5506 }
5507
5508 /* Fix the libcall sequences. */
5509 if ((note1 = find_reg_note (new, REG_RETVAL, NULL_RTX)) != NULL)
5510 {
5511 rtx p = new;
5512 while ((note2 = find_reg_note (p, REG_LIBCALL, NULL_RTX)) == NULL)
5513 p = PREV_INSN (p);
5514 XEXP (note1, 0) = p;
5515 XEXP (note2, 0) = new;
5516 }
5517 return new;
5518}
e2500fed
GK
5519
5520#include "gt-emit-rtl.h"