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