* regclass.c (fix_register): Fix typo.
[official-gcc.git] / gcc / emit-rtl.c
blobc3ba4525a3eeb88b09f1da701d102b6fa8c371bc
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 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* Middle-to-low level generation of rtx code and insns.
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.
29 It also has the functions for creating insns and linking
30 them in the doubly-linked chain.
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. */
38 #include "config.h"
39 #include "system.h"
40 #include "toplev.h"
41 #include "rtl.h"
42 #include "tree.h"
43 #include "tm_p.h"
44 #include "flags.h"
45 #include "function.h"
46 #include "expr.h"
47 #include "regs.h"
48 #include "hard-reg-set.h"
49 #include "hashtab.h"
50 #include "insn-config.h"
51 #include "recog.h"
52 #include "real.h"
53 #include "obstack.h"
54 #include "bitmap.h"
55 #include "basic-block.h"
56 #include "ggc.h"
57 #include "debug.h"
59 /* Commonly used modes. */
61 enum machine_mode byte_mode; /* Mode whose width is BITS_PER_UNIT. */
62 enum machine_mode word_mode; /* Mode whose width is BITS_PER_WORD. */
63 enum machine_mode double_mode; /* Mode whose width is DOUBLE_TYPE_SIZE. */
64 enum machine_mode ptr_mode; /* Mode whose width is POINTER_SIZE. */
67 /* This is *not* reset after each function. It gives each CODE_LABEL
68 in the entire compilation a unique label number. */
70 static int label_num = 1;
72 /* Highest label number in current function.
73 Zero means use the value of label_num instead.
74 This is nonzero only when belatedly compiling an inline function. */
76 static int last_label_num;
78 /* Value label_num had when set_new_first_and_last_label_number was called.
79 If label_num has not changed since then, last_label_num is valid. */
81 static int base_label_num;
83 /* Nonzero means do not generate NOTEs for source line numbers. */
85 static int no_line_numbers;
87 /* Commonly used rtx's, so that we only need space for one copy.
88 These are initialized once for the entire compilation.
89 All of these except perhaps the floating-point CONST_DOUBLEs
90 are unique; no other rtx-object will be equal to any of these. */
92 rtx global_rtl[GR_MAX];
94 /* We record floating-point CONST_DOUBLEs in each floating-point mode for
95 the values of 0, 1, and 2. For the integer entries and VOIDmode, we
96 record a copy of const[012]_rtx. */
98 rtx const_tiny_rtx[3][(int) MAX_MACHINE_MODE];
100 rtx const_true_rtx;
102 REAL_VALUE_TYPE dconst0;
103 REAL_VALUE_TYPE dconst1;
104 REAL_VALUE_TYPE dconst2;
105 REAL_VALUE_TYPE dconstm1;
107 /* All references to the following fixed hard registers go through
108 these unique rtl objects. On machines where the frame-pointer and
109 arg-pointer are the same register, they use the same unique object.
111 After register allocation, other rtl objects which used to be pseudo-regs
112 may be clobbered to refer to the frame-pointer register.
113 But references that were originally to the frame-pointer can be
114 distinguished from the others because they contain frame_pointer_rtx.
116 When to use frame_pointer_rtx and hard_frame_pointer_rtx is a little
117 tricky: until register elimination has taken place hard_frame_pointer_rtx
118 should be used if it is being set, and frame_pointer_rtx otherwise. After
119 register elimination hard_frame_pointer_rtx should always be used.
120 On machines where the two registers are same (most) then these are the
121 same.
123 In an inline procedure, the stack and frame pointer rtxs may not be
124 used for anything else. */
125 rtx struct_value_rtx; /* (REG:Pmode STRUCT_VALUE_REGNUM) */
126 rtx struct_value_incoming_rtx; /* (REG:Pmode STRUCT_VALUE_INCOMING_REGNUM) */
127 rtx static_chain_rtx; /* (REG:Pmode STATIC_CHAIN_REGNUM) */
128 rtx static_chain_incoming_rtx; /* (REG:Pmode STATIC_CHAIN_INCOMING_REGNUM) */
129 rtx pic_offset_table_rtx; /* (REG:Pmode PIC_OFFSET_TABLE_REGNUM) */
131 /* This is used to implement __builtin_return_address for some machines.
132 See for instance the MIPS port. */
133 rtx return_address_pointer_rtx; /* (REG:Pmode RETURN_ADDRESS_POINTER_REGNUM) */
135 /* We make one copy of (const_int C) where C is in
136 [- MAX_SAVED_CONST_INT, MAX_SAVED_CONST_INT]
137 to save space during the compilation and simplify comparisons of
138 integers. */
140 rtx const_int_rtx[MAX_SAVED_CONST_INT * 2 + 1];
142 /* A hash table storing CONST_INTs whose absolute value is greater
143 than MAX_SAVED_CONST_INT. */
145 static htab_t const_int_htab;
147 /* start_sequence and gen_sequence can make a lot of rtx expressions which are
148 shortly thrown away. We use two mechanisms to prevent this waste:
150 For sizes up to 5 elements, we keep a SEQUENCE and its associated
151 rtvec for use by gen_sequence. One entry for each size is
152 sufficient because most cases are calls to gen_sequence followed by
153 immediately emitting the SEQUENCE. Reuse is safe since emitting a
154 sequence is destructive on the insn in it anyway and hence can't be
155 redone.
157 We do not bother to save this cached data over nested function calls.
158 Instead, we just reinitialize them. */
160 #define SEQUENCE_RESULT_SIZE 5
162 static rtx sequence_result[SEQUENCE_RESULT_SIZE];
164 /* During RTL generation, we also keep a list of free INSN rtl codes. */
165 static rtx free_insn;
167 #define first_insn (cfun->emit->x_first_insn)
168 #define last_insn (cfun->emit->x_last_insn)
169 #define cur_insn_uid (cfun->emit->x_cur_insn_uid)
170 #define last_linenum (cfun->emit->x_last_linenum)
171 #define last_filename (cfun->emit->x_last_filename)
172 #define first_label_num (cfun->emit->x_first_label_num)
174 static rtx make_jump_insn_raw PARAMS ((rtx));
175 static rtx make_call_insn_raw PARAMS ((rtx));
176 static rtx find_line_note PARAMS ((rtx));
177 static void mark_sequence_stack PARAMS ((struct sequence_stack *));
178 static void unshare_all_rtl_1 PARAMS ((rtx));
179 static void unshare_all_decls PARAMS ((tree));
180 static void reset_used_decls PARAMS ((tree));
181 static void mark_label_nuses PARAMS ((rtx));
182 static hashval_t const_int_htab_hash PARAMS ((const void *));
183 static int const_int_htab_eq PARAMS ((const void *,
184 const void *));
185 static int rtx_htab_mark_1 PARAMS ((void **, void *));
186 static void rtx_htab_mark PARAMS ((void *));
188 /* Probability of the conditional branch currently proceeded by try_split.
189 Set to -1 otherwise. */
190 int split_branch_probability = -1;
193 /* Returns a hash code for X (which is a really a CONST_INT). */
195 static hashval_t
196 const_int_htab_hash (x)
197 const void *x;
199 return (hashval_t) INTVAL ((const struct rtx_def *) x);
202 /* Returns non-zero if the value represented by X (which is really a
203 CONST_INT) is the same as that given by Y (which is really a
204 HOST_WIDE_INT *). */
206 static int
207 const_int_htab_eq (x, y)
208 const void *x;
209 const void *y;
211 return (INTVAL ((const struct rtx_def *) x) == *((const HOST_WIDE_INT *) y));
214 /* Mark the hash-table element X (which is really a pointer to an
215 rtx). */
217 static int
218 rtx_htab_mark_1 (x, data)
219 void **x;
220 void *data ATTRIBUTE_UNUSED;
222 ggc_mark_rtx (*x);
223 return 1;
226 /* Mark all the elements of HTAB (which is really an htab_t full of
227 rtxs). */
229 static void
230 rtx_htab_mark (htab)
231 void *htab;
233 htab_traverse (*((htab_t *) htab), rtx_htab_mark_1, NULL);
236 /* Generate a new REG rtx. Make sure ORIGINAL_REGNO is set properly, and
237 don't attempt to share with the various global pieces of rtl (such as
238 frame_pointer_rtx). */
241 gen_raw_REG (mode, regno)
242 enum machine_mode mode;
243 int regno;
245 rtx x = gen_rtx_raw_REG (mode, regno);
246 ORIGINAL_REGNO (x) = regno;
247 return x;
250 /* There are some RTL codes that require special attention; the generation
251 functions do the raw handling. If you add to this list, modify
252 special_rtx in gengenrtl.c as well. */
255 gen_rtx_CONST_INT (mode, arg)
256 enum machine_mode mode ATTRIBUTE_UNUSED;
257 HOST_WIDE_INT arg;
259 void **slot;
261 if (arg >= - MAX_SAVED_CONST_INT && arg <= MAX_SAVED_CONST_INT)
262 return const_int_rtx[arg + MAX_SAVED_CONST_INT];
264 #if STORE_FLAG_VALUE != 1 && STORE_FLAG_VALUE != -1
265 if (const_true_rtx && arg == STORE_FLAG_VALUE)
266 return const_true_rtx;
267 #endif
269 /* Look up the CONST_INT in the hash table. */
270 slot = htab_find_slot_with_hash (const_int_htab, &arg,
271 (hashval_t) arg, INSERT);
272 if (*slot == 0)
273 *slot = gen_rtx_raw_CONST_INT (VOIDmode, arg);
275 return (rtx) *slot;
278 /* CONST_DOUBLEs needs special handling because their length is known
279 only at run-time. */
282 gen_rtx_CONST_DOUBLE (mode, arg0, arg1, arg2)
283 enum machine_mode mode;
284 rtx arg0;
285 HOST_WIDE_INT arg1, arg2;
287 rtx r = rtx_alloc (CONST_DOUBLE);
288 int i;
290 PUT_MODE (r, mode);
291 XEXP (r, 0) = arg0;
292 X0EXP (r, 1) = NULL_RTX;
293 XWINT (r, 2) = arg1;
294 XWINT (r, 3) = arg2;
296 for (i = GET_RTX_LENGTH (CONST_DOUBLE) - 1; i > 3; --i)
297 XWINT (r, i) = 0;
299 return r;
303 gen_rtx_REG (mode, regno)
304 enum machine_mode mode;
305 int regno;
307 /* In case the MD file explicitly references the frame pointer, have
308 all such references point to the same frame pointer. This is
309 used during frame pointer elimination to distinguish the explicit
310 references to these registers from pseudos that happened to be
311 assigned to them.
313 If we have eliminated the frame pointer or arg pointer, we will
314 be using it as a normal register, for example as a spill
315 register. In such cases, we might be accessing it in a mode that
316 is not Pmode and therefore cannot use the pre-allocated rtx.
318 Also don't do this when we are making new REGs in reload, since
319 we don't want to get confused with the real pointers. */
321 if (mode == Pmode && !reload_in_progress)
323 if (regno == FRAME_POINTER_REGNUM)
324 return frame_pointer_rtx;
325 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
326 if (regno == HARD_FRAME_POINTER_REGNUM)
327 return hard_frame_pointer_rtx;
328 #endif
329 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM && HARD_FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
330 if (regno == ARG_POINTER_REGNUM)
331 return arg_pointer_rtx;
332 #endif
333 #ifdef RETURN_ADDRESS_POINTER_REGNUM
334 if (regno == RETURN_ADDRESS_POINTER_REGNUM)
335 return return_address_pointer_rtx;
336 #endif
337 if (regno == STACK_POINTER_REGNUM)
338 return stack_pointer_rtx;
341 return gen_raw_REG (mode, regno);
345 gen_rtx_MEM (mode, addr)
346 enum machine_mode mode;
347 rtx addr;
349 rtx rt = gen_rtx_raw_MEM (mode, addr);
351 /* This field is not cleared by the mere allocation of the rtx, so
352 we clear it here. */
353 MEM_ALIAS_SET (rt) = 0;
355 return rt;
359 gen_rtx_SUBREG (mode, reg, offset)
360 enum machine_mode mode;
361 rtx reg;
362 int offset;
364 /* This is the most common failure type.
365 Catch it early so we can see who does it. */
366 if ((offset % GET_MODE_SIZE (mode)) != 0)
367 abort ();
369 /* This check isn't usable right now because combine will
370 throw arbitrary crap like a CALL into a SUBREG in
371 gen_lowpart_for_combine so we must just eat it. */
372 #if 0
373 /* Check for this too. */
374 if (offset >= GET_MODE_SIZE (GET_MODE (reg)))
375 abort ();
376 #endif
377 return gen_rtx_fmt_ei (SUBREG, mode, reg, offset);
380 /* Generate a SUBREG representing the least-significant part
381 * of REG if MODE is smaller than mode of REG, otherwise
382 * paradoxical SUBREG. */
384 gen_lowpart_SUBREG (mode, reg)
385 enum machine_mode mode;
386 rtx reg;
388 enum machine_mode inmode;
390 inmode = GET_MODE (reg);
391 if (inmode == VOIDmode)
392 inmode = mode;
393 return gen_rtx_SUBREG (mode, reg,
394 subreg_lowpart_offset (mode, inmode));
397 /* rtx gen_rtx (code, mode, [element1, ..., elementn])
399 ** This routine generates an RTX of the size specified by
400 ** <code>, which is an RTX code. The RTX structure is initialized
401 ** from the arguments <element1> through <elementn>, which are
402 ** interpreted according to the specific RTX type's format. The
403 ** special machine mode associated with the rtx (if any) is specified
404 ** in <mode>.
406 ** gen_rtx can be invoked in a way which resembles the lisp-like
407 ** rtx it will generate. For example, the following rtx structure:
409 ** (plus:QI (mem:QI (reg:SI 1))
410 ** (mem:QI (plusw:SI (reg:SI 2) (reg:SI 3))))
412 ** ...would be generated by the following C code:
414 ** gen_rtx (PLUS, QImode,
415 ** gen_rtx (MEM, QImode,
416 ** gen_rtx (REG, SImode, 1)),
417 ** gen_rtx (MEM, QImode,
418 ** gen_rtx (PLUS, SImode,
419 ** gen_rtx (REG, SImode, 2),
420 ** gen_rtx (REG, SImode, 3)))),
423 /*VARARGS2*/
425 gen_rtx VPARAMS ((enum rtx_code code, enum machine_mode mode, ...))
427 #ifndef ANSI_PROTOTYPES
428 enum rtx_code code;
429 enum machine_mode mode;
430 #endif
431 va_list p;
432 register int i; /* Array indices... */
433 register const char *fmt; /* Current rtx's format... */
434 register rtx rt_val; /* RTX to return to caller... */
436 VA_START (p, mode);
438 #ifndef ANSI_PROTOTYPES
439 code = va_arg (p, enum rtx_code);
440 mode = va_arg (p, enum machine_mode);
441 #endif
443 switch (code)
445 case CONST_INT:
446 rt_val = gen_rtx_CONST_INT (mode, va_arg (p, HOST_WIDE_INT));
447 break;
449 case CONST_DOUBLE:
451 rtx arg0 = va_arg (p, rtx);
452 HOST_WIDE_INT arg1 = va_arg (p, HOST_WIDE_INT);
453 HOST_WIDE_INT arg2 = va_arg (p, HOST_WIDE_INT);
454 rt_val = gen_rtx_CONST_DOUBLE (mode, arg0, arg1, arg2);
456 break;
458 case REG:
459 rt_val = gen_rtx_REG (mode, va_arg (p, int));
460 break;
462 case MEM:
463 rt_val = gen_rtx_MEM (mode, va_arg (p, rtx));
464 break;
466 default:
467 rt_val = rtx_alloc (code); /* Allocate the storage space. */
468 rt_val->mode = mode; /* Store the machine mode... */
470 fmt = GET_RTX_FORMAT (code); /* Find the right format... */
471 for (i = 0; i < GET_RTX_LENGTH (code); i++)
473 switch (*fmt++)
475 case '0': /* Unused field. */
476 break;
478 case 'i': /* An integer? */
479 XINT (rt_val, i) = va_arg (p, int);
480 break;
482 case 'w': /* A wide integer? */
483 XWINT (rt_val, i) = va_arg (p, HOST_WIDE_INT);
484 break;
486 case 's': /* A string? */
487 XSTR (rt_val, i) = va_arg (p, char *);
488 break;
490 case 'e': /* An expression? */
491 case 'u': /* An insn? Same except when printing. */
492 XEXP (rt_val, i) = va_arg (p, rtx);
493 break;
495 case 'E': /* An RTX vector? */
496 XVEC (rt_val, i) = va_arg (p, rtvec);
497 break;
499 case 'b': /* A bitmap? */
500 XBITMAP (rt_val, i) = va_arg (p, bitmap);
501 break;
503 case 't': /* A tree? */
504 XTREE (rt_val, i) = va_arg (p, tree);
505 break;
507 default:
508 abort ();
511 break;
514 va_end (p);
515 return rt_val;
518 /* gen_rtvec (n, [rt1, ..., rtn])
520 ** This routine creates an rtvec and stores within it the
521 ** pointers to rtx's which are its arguments.
524 /*VARARGS1*/
525 rtvec
526 gen_rtvec VPARAMS ((int n, ...))
528 #ifndef ANSI_PROTOTYPES
529 int n;
530 #endif
531 int i;
532 va_list p;
533 rtx *vector;
535 VA_START (p, n);
537 #ifndef ANSI_PROTOTYPES
538 n = va_arg (p, int);
539 #endif
541 if (n == 0)
542 return NULL_RTVEC; /* Don't allocate an empty rtvec... */
544 vector = (rtx *) alloca (n * sizeof (rtx));
546 for (i = 0; i < n; i++)
547 vector[i] = va_arg (p, rtx);
548 va_end (p);
550 return gen_rtvec_v (n, vector);
553 rtvec
554 gen_rtvec_v (n, argp)
555 int n;
556 rtx *argp;
558 register int i;
559 register rtvec rt_val;
561 if (n == 0)
562 return NULL_RTVEC; /* Don't allocate an empty rtvec... */
564 rt_val = rtvec_alloc (n); /* Allocate an rtvec... */
566 for (i = 0; i < n; i++)
567 rt_val->elem[i] = *argp++;
569 return rt_val;
573 /* Generate a REG rtx for a new pseudo register of mode MODE.
574 This pseudo is assigned the next sequential register number. */
577 gen_reg_rtx (mode)
578 enum machine_mode mode;
580 struct function *f = cfun;
581 register rtx val;
583 /* Don't let anything called after initial flow analysis create new
584 registers. */
585 if (no_new_pseudos)
586 abort ();
588 if (generating_concat_p
589 && (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
590 || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT))
592 /* For complex modes, don't make a single pseudo.
593 Instead, make a CONCAT of two pseudos.
594 This allows noncontiguous allocation of the real and imaginary parts,
595 which makes much better code. Besides, allocating DCmode
596 pseudos overstrains reload on some machines like the 386. */
597 rtx realpart, imagpart;
598 int size = GET_MODE_UNIT_SIZE (mode);
599 enum machine_mode partmode
600 = mode_for_size (size * BITS_PER_UNIT,
601 (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
602 ? MODE_FLOAT : MODE_INT),
605 realpart = gen_reg_rtx (partmode);
606 imagpart = gen_reg_rtx (partmode);
607 return gen_rtx_CONCAT (mode, realpart, imagpart);
610 /* Make sure regno_pointer_align and regno_reg_rtx are large enough
611 to have an element for this pseudo reg number. */
613 if (reg_rtx_no == f->emit->regno_pointer_align_length)
615 int old_size = f->emit->regno_pointer_align_length;
616 rtx *new1;
617 char *new;
618 new = xrealloc (f->emit->regno_pointer_align, old_size * 2);
619 memset (new + old_size, 0, old_size);
620 f->emit->regno_pointer_align = (unsigned char *) new;
622 new1 = (rtx *) xrealloc (f->emit->x_regno_reg_rtx,
623 old_size * 2 * sizeof (rtx));
624 memset (new1 + old_size, 0, old_size * sizeof (rtx));
625 regno_reg_rtx = new1;
627 f->emit->regno_pointer_align_length = old_size * 2;
630 val = gen_raw_REG (mode, reg_rtx_no);
631 regno_reg_rtx[reg_rtx_no++] = val;
632 return val;
635 /* Identify REG (which may be a CONCAT) as a user register. */
637 void
638 mark_user_reg (reg)
639 rtx reg;
641 if (GET_CODE (reg) == CONCAT)
643 REG_USERVAR_P (XEXP (reg, 0)) = 1;
644 REG_USERVAR_P (XEXP (reg, 1)) = 1;
646 else if (GET_CODE (reg) == REG)
647 REG_USERVAR_P (reg) = 1;
648 else
649 abort ();
652 /* Identify REG as a probable pointer register and show its alignment
653 as ALIGN, if nonzero. */
655 void
656 mark_reg_pointer (reg, align)
657 rtx reg;
658 int align;
660 if (! REG_POINTER (reg))
662 REG_POINTER (reg) = 1;
664 if (align)
665 REGNO_POINTER_ALIGN (REGNO (reg)) = align;
667 else if (align && align < REGNO_POINTER_ALIGN (REGNO (reg)))
668 /* We can no-longer be sure just how aligned this pointer is */
669 REGNO_POINTER_ALIGN (REGNO (reg)) = align;
672 /* Return 1 plus largest pseudo reg number used in the current function. */
675 max_reg_num ()
677 return reg_rtx_no;
680 /* Return 1 + the largest label number used so far in the current function. */
683 max_label_num ()
685 if (last_label_num && label_num == base_label_num)
686 return last_label_num;
687 return label_num;
690 /* Return first label number used in this function (if any were used). */
693 get_first_label_num ()
695 return first_label_num;
698 /* Return the final regno of X, which is a SUBREG of a hard
699 register. */
701 subreg_hard_regno (x, check_mode)
702 register rtx x;
703 int check_mode;
705 enum machine_mode mode = GET_MODE (x);
706 unsigned int byte_offset, base_regno, final_regno;
707 rtx reg = SUBREG_REG (x);
709 /* This is where we attempt to catch illegal subregs
710 created by the compiler. */
711 if (GET_CODE (x) != SUBREG
712 || GET_CODE (reg) != REG)
713 abort ();
714 base_regno = REGNO (reg);
715 if (base_regno >= FIRST_PSEUDO_REGISTER)
716 abort ();
717 if (check_mode && ! HARD_REGNO_MODE_OK (base_regno, GET_MODE (reg)))
718 abort ();
720 /* Catch non-congruent offsets too. */
721 byte_offset = SUBREG_BYTE (x);
722 if ((byte_offset % GET_MODE_SIZE (mode)) != 0)
723 abort ();
725 final_regno = subreg_regno (x);
727 return final_regno;
730 /* Return a value representing some low-order bits of X, where the number
731 of low-order bits is given by MODE. Note that no conversion is done
732 between floating-point and fixed-point values, rather, the bit
733 representation is returned.
735 This function handles the cases in common between gen_lowpart, below,
736 and two variants in cse.c and combine.c. These are the cases that can
737 be safely handled at all points in the compilation.
739 If this is not a case we can handle, return 0. */
742 gen_lowpart_common (mode, x)
743 enum machine_mode mode;
744 register rtx x;
746 int msize = GET_MODE_SIZE (mode);
747 int xsize = GET_MODE_SIZE (GET_MODE (x));
748 int offset = 0;
750 if (GET_MODE (x) == mode)
751 return x;
753 /* MODE must occupy no more words than the mode of X. */
754 if (GET_MODE (x) != VOIDmode
755 && ((msize + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD
756 > ((xsize + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)))
757 return 0;
759 offset = subreg_lowpart_offset (mode, GET_MODE (x));
761 if ((GET_CODE (x) == ZERO_EXTEND || GET_CODE (x) == SIGN_EXTEND)
762 && (GET_MODE_CLASS (mode) == MODE_INT
763 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT))
765 /* If we are getting the low-order part of something that has been
766 sign- or zero-extended, we can either just use the object being
767 extended or make a narrower extension. If we want an even smaller
768 piece than the size of the object being extended, call ourselves
769 recursively.
771 This case is used mostly by combine and cse. */
773 if (GET_MODE (XEXP (x, 0)) == mode)
774 return XEXP (x, 0);
775 else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (XEXP (x, 0))))
776 return gen_lowpart_common (mode, XEXP (x, 0));
777 else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (x)))
778 return gen_rtx_fmt_e (GET_CODE (x), mode, XEXP (x, 0));
780 else if (GET_CODE (x) == SUBREG || GET_CODE (x) == REG
781 || GET_CODE (x) == CONCAT)
782 return simplify_gen_subreg (mode, x, GET_MODE (x), offset);
783 /* If X is a CONST_INT or a CONST_DOUBLE, extract the appropriate bits
784 from the low-order part of the constant. */
785 else if ((GET_MODE_CLASS (mode) == MODE_INT
786 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
787 && GET_MODE (x) == VOIDmode
788 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
790 /* If MODE is twice the host word size, X is already the desired
791 representation. Otherwise, if MODE is wider than a word, we can't
792 do this. If MODE is exactly a word, return just one CONST_INT. */
794 if (GET_MODE_BITSIZE (mode) >= 2 * HOST_BITS_PER_WIDE_INT)
795 return x;
796 else if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
797 return 0;
798 else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
799 return (GET_CODE (x) == CONST_INT ? x
800 : GEN_INT (CONST_DOUBLE_LOW (x)));
801 else
803 /* MODE must be narrower than HOST_BITS_PER_WIDE_INT. */
804 HOST_WIDE_INT val = (GET_CODE (x) == CONST_INT ? INTVAL (x)
805 : CONST_DOUBLE_LOW (x));
807 /* Sign extend to HOST_WIDE_INT. */
808 val = trunc_int_for_mode (val, mode);
810 return (GET_CODE (x) == CONST_INT && INTVAL (x) == val ? x
811 : GEN_INT (val));
815 #ifndef REAL_ARITHMETIC
816 /* If X is an integral constant but we want it in floating-point, it
817 must be the case that we have a union of an integer and a floating-point
818 value. If the machine-parameters allow it, simulate that union here
819 and return the result. The two-word and single-word cases are
820 different. */
822 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
823 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
824 || flag_pretend_float)
825 && GET_MODE_CLASS (mode) == MODE_FLOAT
826 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
827 && GET_CODE (x) == CONST_INT
828 && sizeof (float) * HOST_BITS_PER_CHAR == HOST_BITS_PER_WIDE_INT)
830 union {HOST_WIDE_INT i; float d; } u;
832 u.i = INTVAL (x);
833 return CONST_DOUBLE_FROM_REAL_VALUE (u.d, mode);
835 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
836 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
837 || flag_pretend_float)
838 && GET_MODE_CLASS (mode) == MODE_FLOAT
839 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
840 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
841 && GET_MODE (x) == VOIDmode
842 && (sizeof (double) * HOST_BITS_PER_CHAR
843 == 2 * HOST_BITS_PER_WIDE_INT))
845 union {HOST_WIDE_INT i[2]; double d; } u;
846 HOST_WIDE_INT low, high;
848 if (GET_CODE (x) == CONST_INT)
849 low = INTVAL (x), high = low >> (HOST_BITS_PER_WIDE_INT -1);
850 else
851 low = CONST_DOUBLE_LOW (x), high = CONST_DOUBLE_HIGH (x);
853 #ifdef HOST_WORDS_BIG_ENDIAN
854 u.i[0] = high, u.i[1] = low;
855 #else
856 u.i[0] = low, u.i[1] = high;
857 #endif
859 return CONST_DOUBLE_FROM_REAL_VALUE (u.d, mode);
862 /* Similarly, if this is converting a floating-point value into a
863 single-word integer. Only do this is the host and target parameters are
864 compatible. */
866 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
867 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
868 || flag_pretend_float)
869 && (GET_MODE_CLASS (mode) == MODE_INT
870 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
871 && GET_CODE (x) == CONST_DOUBLE
872 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT
873 && GET_MODE_BITSIZE (mode) == BITS_PER_WORD)
874 return constant_subword (x, (offset / UNITS_PER_WORD), GET_MODE (x));
876 /* Similarly, if this is converting a floating-point value into a
877 two-word integer, we can do this one word at a time and make an
878 integer. Only do this is the host and target parameters are
879 compatible. */
881 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
882 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
883 || flag_pretend_float)
884 && (GET_MODE_CLASS (mode) == MODE_INT
885 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
886 && GET_CODE (x) == CONST_DOUBLE
887 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT
888 && GET_MODE_BITSIZE (mode) == 2 * BITS_PER_WORD)
890 rtx lowpart, highpart;
892 lowpart = constant_subword (x,
893 (offset / UNITS_PER_WORD) + WORDS_BIG_ENDIAN,
894 GET_MODE (x));
895 highpart = constant_subword (x,
896 (offset / UNITS_PER_WORD) + (! WORDS_BIG_ENDIAN),
897 GET_MODE (x));
898 if (lowpart && GET_CODE (lowpart) == CONST_INT
899 && highpart && GET_CODE (highpart) == CONST_INT)
900 return immed_double_const (INTVAL (lowpart), INTVAL (highpart), mode);
902 #else /* ifndef REAL_ARITHMETIC */
904 /* When we have a FP emulator, we can handle all conversions between
905 FP and integer operands. This simplifies reload because it
906 doesn't have to deal with constructs like (subreg:DI
907 (const_double:SF ...)) or (subreg:DF (const_int ...)). */
908 /* Single-precision floats are always 32-bits and double-precision
909 floats are always 64-bits. */
911 else if (GET_MODE_CLASS (mode) == MODE_FLOAT
912 && GET_MODE_BITSIZE (mode) == 32
913 && GET_CODE (x) == CONST_INT)
915 REAL_VALUE_TYPE r;
916 HOST_WIDE_INT i;
918 i = INTVAL (x);
919 r = REAL_VALUE_FROM_TARGET_SINGLE (i);
920 return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
922 else if (GET_MODE_CLASS (mode) == MODE_FLOAT
923 && GET_MODE_BITSIZE (mode) == 64
924 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
925 && GET_MODE (x) == VOIDmode)
927 REAL_VALUE_TYPE r;
928 HOST_WIDE_INT i[2];
929 HOST_WIDE_INT low, high;
931 if (GET_CODE (x) == CONST_INT)
933 low = INTVAL (x);
934 high = low >> (HOST_BITS_PER_WIDE_INT - 1);
936 else
938 low = CONST_DOUBLE_LOW (x);
939 high = CONST_DOUBLE_HIGH (x);
942 /* REAL_VALUE_TARGET_DOUBLE takes the addressing order of the
943 target machine. */
944 if (WORDS_BIG_ENDIAN)
945 i[0] = high, i[1] = low;
946 else
947 i[0] = low, i[1] = high;
949 r = REAL_VALUE_FROM_TARGET_DOUBLE (i);
950 return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
952 else if ((GET_MODE_CLASS (mode) == MODE_INT
953 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
954 && GET_CODE (x) == CONST_DOUBLE
955 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
957 REAL_VALUE_TYPE r;
958 long i[4]; /* Only the low 32 bits of each 'long' are used. */
959 int endian = WORDS_BIG_ENDIAN ? 1 : 0;
961 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
962 switch (GET_MODE_BITSIZE (GET_MODE (x)))
964 case 32:
965 REAL_VALUE_TO_TARGET_SINGLE (r, i[endian]);
966 i[1 - endian] = 0;
967 break;
968 case 64:
969 REAL_VALUE_TO_TARGET_DOUBLE (r, i);
970 break;
971 case 96:
972 REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, i + endian);
973 i[3-3*endian] = 0;
974 break;
975 case 128:
976 REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, i);
977 break;
978 default:
979 abort ();
982 /* Now, pack the 32-bit elements of the array into a CONST_DOUBLE
983 and return it. */
984 #if HOST_BITS_PER_WIDE_INT == 32
985 return immed_double_const (i[endian], i[1 - endian], mode);
986 #else
988 int c;
990 if (HOST_BITS_PER_WIDE_INT != 64)
991 abort ();
993 for (c = 0; c < 4; c++)
994 i[c] &= ~ (0L);
996 switch (GET_MODE_BITSIZE (GET_MODE (x)))
998 case 32:
999 case 64:
1000 return immed_double_const (((unsigned long) i[endian]) |
1001 (((HOST_WIDE_INT) i[1-endian]) << 32),
1002 0, mode);
1003 case 96:
1004 case 128:
1005 return immed_double_const (((unsigned long) i[endian*3]) |
1006 (((HOST_WIDE_INT) i[1+endian]) << 32),
1007 ((unsigned long) i[2-endian]) |
1008 (((HOST_WIDE_INT) i[3-endian*3]) << 32),
1009 mode);
1010 default:
1011 abort ();
1014 #endif
1016 #endif /* ifndef REAL_ARITHMETIC */
1018 /* Otherwise, we can't do this. */
1019 return 0;
1022 /* Return the real part (which has mode MODE) of a complex value X.
1023 This always comes at the low address in memory. */
1026 gen_realpart (mode, x)
1027 enum machine_mode mode;
1028 register rtx x;
1030 if (WORDS_BIG_ENDIAN
1031 && GET_MODE_BITSIZE (mode) < BITS_PER_WORD
1032 && REG_P (x)
1033 && REGNO (x) < FIRST_PSEUDO_REGISTER)
1034 internal_error
1035 ("Can't access real part of complex value in hard register");
1036 else if (WORDS_BIG_ENDIAN)
1037 return gen_highpart (mode, x);
1038 else
1039 return gen_lowpart (mode, x);
1042 /* Return the imaginary part (which has mode MODE) of a complex value X.
1043 This always comes at the high address in memory. */
1046 gen_imagpart (mode, x)
1047 enum machine_mode mode;
1048 register rtx x;
1050 if (WORDS_BIG_ENDIAN)
1051 return gen_lowpart (mode, x);
1052 else if (! WORDS_BIG_ENDIAN
1053 && GET_MODE_BITSIZE (mode) < BITS_PER_WORD
1054 && REG_P (x)
1055 && REGNO (x) < FIRST_PSEUDO_REGISTER)
1056 internal_error
1057 ("can't access imaginary part of complex value in hard register");
1058 else
1059 return gen_highpart (mode, x);
1062 /* Return 1 iff X, assumed to be a SUBREG,
1063 refers to the real part of the complex value in its containing reg.
1064 Complex values are always stored with the real part in the first word,
1065 regardless of WORDS_BIG_ENDIAN. */
1068 subreg_realpart_p (x)
1069 rtx x;
1071 if (GET_CODE (x) != SUBREG)
1072 abort ();
1074 return ((unsigned int) SUBREG_BYTE (x)
1075 < GET_MODE_UNIT_SIZE (GET_MODE (SUBREG_REG (x))));
1078 /* Assuming that X is an rtx (e.g., MEM, REG or SUBREG) for a value,
1079 return an rtx (MEM, SUBREG, or CONST_INT) that refers to the
1080 least-significant part of X.
1081 MODE specifies how big a part of X to return;
1082 it usually should not be larger than a word.
1083 If X is a MEM whose address is a QUEUED, the value may be so also. */
1086 gen_lowpart (mode, x)
1087 enum machine_mode mode;
1088 register rtx x;
1090 rtx result = gen_lowpart_common (mode, x);
1092 if (result)
1093 return result;
1094 else if (GET_CODE (x) == REG)
1096 /* Must be a hard reg that's not valid in MODE. */
1097 result = gen_lowpart_common (mode, copy_to_reg (x));
1098 if (result == 0)
1099 abort ();
1100 return result;
1102 else if (GET_CODE (x) == MEM)
1104 /* The only additional case we can do is MEM. */
1105 register int offset = 0;
1106 if (WORDS_BIG_ENDIAN)
1107 offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
1108 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
1110 if (BYTES_BIG_ENDIAN)
1111 /* Adjust the address so that the address-after-the-data
1112 is unchanged. */
1113 offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))
1114 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
1116 return adjust_address (x, mode, offset);
1118 else if (GET_CODE (x) == ADDRESSOF)
1119 return gen_lowpart (mode, force_reg (GET_MODE (x), x));
1120 else
1121 abort ();
1124 /* Like `gen_lowpart', but refer to the most significant part.
1125 This is used to access the imaginary part of a complex number. */
1128 gen_highpart (mode, x)
1129 enum machine_mode mode;
1130 register rtx x;
1132 unsigned int msize = GET_MODE_SIZE (mode);
1133 rtx result;
1135 /* This case loses if X is a subreg. To catch bugs early,
1136 complain if an invalid MODE is used even in other cases. */
1137 if (msize > UNITS_PER_WORD
1138 && msize != GET_MODE_UNIT_SIZE (GET_MODE (x)))
1139 abort ();
1141 result = simplify_gen_subreg (mode, x, GET_MODE (x),
1142 subreg_highpart_offset (mode, GET_MODE (x)));
1144 /* simplify_gen_subreg is not guaranteed to return a valid operand for
1145 the target if we have a MEM. gen_highpart must return a valid operand,
1146 emitting code if necessary to do so. */
1147 if (GET_CODE (result) == MEM)
1148 result = validize_mem (result);
1150 if (!result)
1151 abort ();
1152 return result;
1155 /* Like gen_highpart_mode, but accept mode of EXP operand in case EXP can
1156 be VOIDmode constant. */
1158 gen_highpart_mode (outermode, innermode, exp)
1159 enum machine_mode outermode, innermode;
1160 rtx exp;
1162 if (GET_MODE (exp) != VOIDmode)
1164 if (GET_MODE (exp) != innermode)
1165 abort ();
1166 return gen_highpart (outermode, exp);
1168 return simplify_gen_subreg (outermode, exp, innermode,
1169 subreg_highpart_offset (outermode, innermode));
1171 /* Return offset in bytes to get OUTERMODE low part
1172 of the value in mode INNERMODE stored in memory in target format. */
1174 unsigned int
1175 subreg_lowpart_offset (outermode, innermode)
1176 enum machine_mode outermode, innermode;
1178 unsigned int offset = 0;
1179 int difference = (GET_MODE_SIZE (innermode) - GET_MODE_SIZE (outermode));
1181 if (difference > 0)
1183 if (WORDS_BIG_ENDIAN)
1184 offset += (difference / UNITS_PER_WORD) * UNITS_PER_WORD;
1185 if (BYTES_BIG_ENDIAN)
1186 offset += difference % UNITS_PER_WORD;
1189 return offset;
1192 /* Return offset in bytes to get OUTERMODE high part
1193 of the value in mode INNERMODE stored in memory in target format. */
1194 unsigned int
1195 subreg_highpart_offset (outermode, innermode)
1196 enum machine_mode outermode, innermode;
1198 unsigned int offset = 0;
1199 int difference = (GET_MODE_SIZE (innermode) - GET_MODE_SIZE (outermode));
1201 if (GET_MODE_SIZE (innermode) < GET_MODE_SIZE (outermode))
1202 abort ();
1204 if (difference > 0)
1206 if (! WORDS_BIG_ENDIAN)
1207 offset += (difference / UNITS_PER_WORD) * UNITS_PER_WORD;
1208 if (! BYTES_BIG_ENDIAN)
1209 offset += difference % UNITS_PER_WORD;
1212 return offset;
1215 /* Return 1 iff X, assumed to be a SUBREG,
1216 refers to the least significant part of its containing reg.
1217 If X is not a SUBREG, always return 1 (it is its own low part!). */
1220 subreg_lowpart_p (x)
1221 rtx x;
1223 if (GET_CODE (x) != SUBREG)
1224 return 1;
1225 else if (GET_MODE (SUBREG_REG (x)) == VOIDmode)
1226 return 0;
1228 return (subreg_lowpart_offset (GET_MODE (x), GET_MODE (SUBREG_REG (x)))
1229 == SUBREG_BYTE (x));
1233 /* Helper routine for all the constant cases of operand_subword.
1234 Some places invoke this directly. */
1237 constant_subword (op, offset, mode)
1238 rtx op;
1239 int offset;
1240 enum machine_mode mode;
1242 int size_ratio = HOST_BITS_PER_WIDE_INT / BITS_PER_WORD;
1243 HOST_WIDE_INT val;
1245 /* If OP is already an integer word, return it. */
1246 if (GET_MODE_CLASS (mode) == MODE_INT
1247 && GET_MODE_SIZE (mode) == UNITS_PER_WORD)
1248 return op;
1250 #ifdef REAL_ARITHMETIC
1251 /* The output is some bits, the width of the target machine's word.
1252 A wider-word host can surely hold them in a CONST_INT. A narrower-word
1253 host can't. */
1254 if (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
1255 && GET_MODE_CLASS (mode) == MODE_FLOAT
1256 && GET_MODE_BITSIZE (mode) == 64
1257 && GET_CODE (op) == CONST_DOUBLE)
1259 long k[2];
1260 REAL_VALUE_TYPE rv;
1262 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1263 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
1265 /* We handle 32-bit and >= 64-bit words here. Note that the order in
1266 which the words are written depends on the word endianness.
1267 ??? This is a potential portability problem and should
1268 be fixed at some point.
1270 We must excercise caution with the sign bit. By definition there
1271 are 32 significant bits in K; there may be more in a HOST_WIDE_INT.
1272 Consider a host with a 32-bit long and a 64-bit HOST_WIDE_INT.
1273 So we explicitly mask and sign-extend as necessary. */
1274 if (BITS_PER_WORD == 32)
1276 val = k[offset];
1277 val = ((val & 0xffffffff) ^ 0x80000000) - 0x80000000;
1278 return GEN_INT (val);
1280 #if HOST_BITS_PER_WIDE_INT >= 64
1281 else if (BITS_PER_WORD >= 64 && offset == 0)
1283 val = k[! WORDS_BIG_ENDIAN];
1284 val = (((val & 0xffffffff) ^ 0x80000000) - 0x80000000) << 32;
1285 val |= (HOST_WIDE_INT) k[WORDS_BIG_ENDIAN] & 0xffffffff;
1286 return GEN_INT (val);
1288 #endif
1289 else if (BITS_PER_WORD == 16)
1291 val = k[offset >> 1];
1292 if ((offset & 1) == ! WORDS_BIG_ENDIAN)
1293 val >>= 16;
1294 val = ((val & 0xffff) ^ 0x8000) - 0x8000;
1295 return GEN_INT (val);
1297 else
1298 abort ();
1300 else if (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
1301 && GET_MODE_CLASS (mode) == MODE_FLOAT
1302 && GET_MODE_BITSIZE (mode) > 64
1303 && GET_CODE (op) == CONST_DOUBLE)
1305 long k[4];
1306 REAL_VALUE_TYPE rv;
1308 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1309 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
1311 if (BITS_PER_WORD == 32)
1313 val = k[offset];
1314 val = ((val & 0xffffffff) ^ 0x80000000) - 0x80000000;
1315 return GEN_INT (val);
1317 #if HOST_BITS_PER_WIDE_INT >= 64
1318 else if (BITS_PER_WORD >= 64 && offset <= 1)
1320 val = k[offset * 2 + ! WORDS_BIG_ENDIAN];
1321 val = (((val & 0xffffffff) ^ 0x80000000) - 0x80000000) << 32;
1322 val |= (HOST_WIDE_INT) k[offset * 2 + WORDS_BIG_ENDIAN] & 0xffffffff;
1323 return GEN_INT (val);
1325 #endif
1326 else
1327 abort ();
1329 #else /* no REAL_ARITHMETIC */
1330 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1331 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1332 || flag_pretend_float)
1333 && GET_MODE_CLASS (mode) == MODE_FLOAT
1334 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
1335 && GET_CODE (op) == CONST_DOUBLE)
1337 /* The constant is stored in the host's word-ordering,
1338 but we want to access it in the target's word-ordering. Some
1339 compilers don't like a conditional inside macro args, so we have two
1340 copies of the return. */
1341 #ifdef HOST_WORDS_BIG_ENDIAN
1342 return GEN_INT (offset == WORDS_BIG_ENDIAN
1343 ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
1344 #else
1345 return GEN_INT (offset != WORDS_BIG_ENDIAN
1346 ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
1347 #endif
1349 #endif /* no REAL_ARITHMETIC */
1351 /* Single word float is a little harder, since single- and double-word
1352 values often do not have the same high-order bits. We have already
1353 verified that we want the only defined word of the single-word value. */
1354 #ifdef REAL_ARITHMETIC
1355 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1356 && GET_MODE_BITSIZE (mode) == 32
1357 && GET_CODE (op) == CONST_DOUBLE)
1359 long l;
1360 REAL_VALUE_TYPE rv;
1362 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1363 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
1365 /* Sign extend from known 32-bit value to HOST_WIDE_INT. */
1366 val = l;
1367 val = ((val & 0xffffffff) ^ 0x80000000) - 0x80000000;
1369 if (BITS_PER_WORD == 16)
1371 if ((offset & 1) == ! WORDS_BIG_ENDIAN)
1372 val >>= 16;
1373 val = ((val & 0xffff) ^ 0x8000) - 0x8000;
1376 return GEN_INT (val);
1378 #else
1379 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1380 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1381 || flag_pretend_float)
1382 && sizeof (float) * 8 == HOST_BITS_PER_WIDE_INT
1383 && GET_MODE_CLASS (mode) == MODE_FLOAT
1384 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
1385 && GET_CODE (op) == CONST_DOUBLE)
1387 double d;
1388 union {float f; HOST_WIDE_INT i; } u;
1390 REAL_VALUE_FROM_CONST_DOUBLE (d, op);
1392 u.f = d;
1393 return GEN_INT (u.i);
1395 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1396 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1397 || flag_pretend_float)
1398 && sizeof (double) * 8 == HOST_BITS_PER_WIDE_INT
1399 && GET_MODE_CLASS (mode) == MODE_FLOAT
1400 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
1401 && GET_CODE (op) == CONST_DOUBLE)
1403 double d;
1404 union {double d; HOST_WIDE_INT i; } u;
1406 REAL_VALUE_FROM_CONST_DOUBLE (d, op);
1408 u.d = d;
1409 return GEN_INT (u.i);
1411 #endif /* no REAL_ARITHMETIC */
1413 /* The only remaining cases that we can handle are integers.
1414 Convert to proper endianness now since these cases need it.
1415 At this point, offset == 0 means the low-order word.
1417 We do not want to handle the case when BITS_PER_WORD <= HOST_BITS_PER_INT
1418 in general. However, if OP is (const_int 0), we can just return
1419 it for any word. */
1421 if (op == const0_rtx)
1422 return op;
1424 if (GET_MODE_CLASS (mode) != MODE_INT
1425 || (GET_CODE (op) != CONST_INT && GET_CODE (op) != CONST_DOUBLE)
1426 || BITS_PER_WORD > HOST_BITS_PER_WIDE_INT)
1427 return 0;
1429 if (WORDS_BIG_ENDIAN)
1430 offset = GET_MODE_SIZE (mode) / UNITS_PER_WORD - 1 - offset;
1432 /* Find out which word on the host machine this value is in and get
1433 it from the constant. */
1434 val = (offset / size_ratio == 0
1435 ? (GET_CODE (op) == CONST_INT ? INTVAL (op) : CONST_DOUBLE_LOW (op))
1436 : (GET_CODE (op) == CONST_INT
1437 ? (INTVAL (op) < 0 ? ~0 : 0) : CONST_DOUBLE_HIGH (op)));
1439 /* Get the value we want into the low bits of val. */
1440 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT)
1441 val = ((val >> ((offset % size_ratio) * BITS_PER_WORD)));
1443 val = trunc_int_for_mode (val, word_mode);
1445 return GEN_INT (val);
1448 /* Return subword OFFSET of operand OP.
1449 The word number, OFFSET, is interpreted as the word number starting
1450 at the low-order address. OFFSET 0 is the low-order word if not
1451 WORDS_BIG_ENDIAN, otherwise it is the high-order word.
1453 If we cannot extract the required word, we return zero. Otherwise,
1454 an rtx corresponding to the requested word will be returned.
1456 VALIDATE_ADDRESS is nonzero if the address should be validated. Before
1457 reload has completed, a valid address will always be returned. After
1458 reload, if a valid address cannot be returned, we return zero.
1460 If VALIDATE_ADDRESS is zero, we simply form the required address; validating
1461 it is the responsibility of the caller.
1463 MODE is the mode of OP in case it is a CONST_INT.
1465 ??? This is still rather broken for some cases. The problem for the
1466 moment is that all callers of this thing provide no 'goal mode' to
1467 tell us to work with. This exists because all callers were written
1468 in a word based SUBREG world.
1469 Now use of this function can be deprecated by simplify_subreg in most
1470 cases.
1474 operand_subword (op, offset, validate_address, mode)
1475 rtx op;
1476 unsigned int offset;
1477 int validate_address;
1478 enum machine_mode mode;
1480 if (mode == VOIDmode)
1481 mode = GET_MODE (op);
1483 if (mode == VOIDmode)
1484 abort ();
1486 /* If OP is narrower than a word, fail. */
1487 if (mode != BLKmode
1488 && (GET_MODE_SIZE (mode) < UNITS_PER_WORD))
1489 return 0;
1491 /* If we want a word outside OP, return zero. */
1492 if (mode != BLKmode
1493 && (offset + 1) * UNITS_PER_WORD > GET_MODE_SIZE (mode))
1494 return const0_rtx;
1496 /* Form a new MEM at the requested address. */
1497 if (GET_CODE (op) == MEM)
1499 rtx new = adjust_address_nv (op, word_mode, offset * UNITS_PER_WORD);
1501 if (! validate_address)
1502 return new;
1504 else if (reload_completed)
1506 if (! strict_memory_address_p (word_mode, XEXP (new, 0)))
1507 return 0;
1509 else
1510 return replace_equiv_address (new, XEXP (new, 0));
1513 /* Rest can be handled by simplify_subreg. */
1514 return simplify_gen_subreg (word_mode, op, mode, (offset * UNITS_PER_WORD));
1517 /* Similar to `operand_subword', but never return 0. If we can't extract
1518 the required subword, put OP into a register and try again. If that fails,
1519 abort. We always validate the address in this case.
1521 MODE is the mode of OP, in case it is CONST_INT. */
1524 operand_subword_force (op, offset, mode)
1525 rtx op;
1526 unsigned int offset;
1527 enum machine_mode mode;
1529 rtx result = operand_subword (op, offset, 1, mode);
1531 if (result)
1532 return result;
1534 if (mode != BLKmode && mode != VOIDmode)
1536 /* If this is a register which can not be accessed by words, copy it
1537 to a pseudo register. */
1538 if (GET_CODE (op) == REG)
1539 op = copy_to_reg (op);
1540 else
1541 op = force_reg (mode, op);
1544 result = operand_subword (op, offset, 1, mode);
1545 if (result == 0)
1546 abort ();
1548 return result;
1551 /* Given a compare instruction, swap the operands.
1552 A test instruction is changed into a compare of 0 against the operand. */
1554 void
1555 reverse_comparison (insn)
1556 rtx insn;
1558 rtx body = PATTERN (insn);
1559 rtx comp;
1561 if (GET_CODE (body) == SET)
1562 comp = SET_SRC (body);
1563 else
1564 comp = SET_SRC (XVECEXP (body, 0, 0));
1566 if (GET_CODE (comp) == COMPARE)
1568 rtx op0 = XEXP (comp, 0);
1569 rtx op1 = XEXP (comp, 1);
1570 XEXP (comp, 0) = op1;
1571 XEXP (comp, 1) = op0;
1573 else
1575 rtx new = gen_rtx_COMPARE (VOIDmode,
1576 CONST0_RTX (GET_MODE (comp)), comp);
1577 if (GET_CODE (body) == SET)
1578 SET_SRC (body) = new;
1579 else
1580 SET_SRC (XVECEXP (body, 0, 0)) = new;
1584 /* Return a memory reference like MEMREF, but with its mode changed
1585 to MODE and its address changed to ADDR.
1586 (VOIDmode means don't change the mode.
1587 NULL for ADDR means don't change the address.)
1588 VALIDATE is nonzero if the returned memory location is required to be
1589 valid. */
1592 change_address_1 (memref, mode, addr, validate)
1593 rtx memref;
1594 enum machine_mode mode;
1595 rtx addr;
1596 int validate;
1598 rtx new;
1600 if (GET_CODE (memref) != MEM)
1601 abort ();
1602 if (mode == VOIDmode)
1603 mode = GET_MODE (memref);
1604 if (addr == 0)
1605 addr = XEXP (memref, 0);
1607 if (validate)
1609 if (reload_in_progress || reload_completed)
1611 if (! memory_address_p (mode, addr))
1612 abort ();
1614 else
1615 addr = memory_address (mode, addr);
1618 if (rtx_equal_p (addr, XEXP (memref, 0)) && mode == GET_MODE (memref))
1619 return memref;
1621 new = gen_rtx_MEM (mode, addr);
1622 MEM_COPY_ATTRIBUTES (new, memref);
1623 return new;
1626 /* Return a memory reference like MEMREF, but with its mode changed
1627 to MODE and its address offset by OFFSET bytes. */
1630 adjust_address (memref, mode, offset)
1631 rtx memref;
1632 enum machine_mode mode;
1633 HOST_WIDE_INT offset;
1635 /* For now, this is just a wrapper for change_address, but eventually
1636 will do memref tracking. */
1637 rtx addr = XEXP (memref, 0);
1639 /* ??? Prefer to create garbage instead of creating shared rtl. */
1640 addr = copy_rtx (addr);
1642 /* If MEMREF is a LO_SUM and the offset is within the alignment of the
1643 object, we can merge it into the LO_SUM. */
1644 if (GET_MODE (memref) != BLKmode && GET_CODE (addr) == LO_SUM
1645 && offset >= 0
1646 && (unsigned HOST_WIDE_INT) offset
1647 < GET_MODE_ALIGNMENT (GET_MODE (memref)) / BITS_PER_UNIT)
1648 addr = gen_rtx_LO_SUM (mode, XEXP (addr, 0),
1649 plus_constant (XEXP (addr, 1), offset));
1650 else
1651 addr = plus_constant (addr, offset);
1653 return change_address (memref, mode, addr);
1656 /* Likewise, but the reference is not required to be valid. */
1659 adjust_address_nv (memref, mode, offset)
1660 rtx memref;
1661 enum machine_mode mode;
1662 HOST_WIDE_INT offset;
1664 /* For now, this is just a wrapper for change_address, but eventually
1665 will do memref tracking. */
1666 rtx addr = XEXP (memref, 0);
1668 /* If MEMREF is a LO_SUM and the offset is within the size of the
1669 object, we can merge it into the LO_SUM. */
1670 if (GET_MODE (memref) != BLKmode && GET_CODE (addr) == LO_SUM
1671 && offset >= 0
1672 && (unsigned HOST_WIDE_INT) offset
1673 < GET_MODE_ALIGNMENT (GET_MODE (memref)) / BITS_PER_UNIT)
1674 addr = gen_rtx_LO_SUM (mode, XEXP (addr, 0),
1675 plus_constant (XEXP (addr, 1), offset));
1676 else
1677 addr = plus_constant (addr, offset);
1679 return change_address_1 (memref, mode, addr, 0);
1682 /* Return a memory reference like MEMREF, but with its address changed to
1683 ADDR. The caller is asserting that the actual piece of memory pointed
1684 to is the same, just the form of the address is being changed, such as
1685 by putting something into a register. */
1688 replace_equiv_address (memref, addr)
1689 rtx memref;
1690 rtx addr;
1692 /* For now, this is just a wrapper for change_address, but eventually
1693 will do memref tracking. */
1694 return change_address (memref, VOIDmode, addr);
1696 /* Likewise, but the reference is not required to be valid. */
1699 replace_equiv_address_nv (memref, addr)
1700 rtx memref;
1701 rtx addr;
1703 /* For now, this is just a wrapper for change_address, but eventually
1704 will do memref tracking. */
1705 return change_address_1 (memref, VOIDmode, addr, 0);
1708 /* Return a newly created CODE_LABEL rtx with a unique label number. */
1711 gen_label_rtx ()
1713 register rtx label;
1715 label = gen_rtx_CODE_LABEL (VOIDmode, 0, NULL_RTX,
1716 NULL_RTX, label_num++, NULL, NULL);
1718 LABEL_NUSES (label) = 0;
1719 LABEL_ALTERNATE_NAME (label) = NULL;
1720 return label;
1723 /* For procedure integration. */
1725 /* Install new pointers to the first and last insns in the chain.
1726 Also, set cur_insn_uid to one higher than the last in use.
1727 Used for an inline-procedure after copying the insn chain. */
1729 void
1730 set_new_first_and_last_insn (first, last)
1731 rtx first, last;
1733 rtx insn;
1735 first_insn = first;
1736 last_insn = last;
1737 cur_insn_uid = 0;
1739 for (insn = first; insn; insn = NEXT_INSN (insn))
1740 cur_insn_uid = MAX (cur_insn_uid, INSN_UID (insn));
1742 cur_insn_uid++;
1745 /* Set the range of label numbers found in the current function.
1746 This is used when belatedly compiling an inline function. */
1748 void
1749 set_new_first_and_last_label_num (first, last)
1750 int first, last;
1752 base_label_num = label_num;
1753 first_label_num = first;
1754 last_label_num = last;
1757 /* Set the last label number found in the current function.
1758 This is used when belatedly compiling an inline function. */
1760 void
1761 set_new_last_label_num (last)
1762 int last;
1764 base_label_num = label_num;
1765 last_label_num = last;
1768 /* Restore all variables describing the current status from the structure *P.
1769 This is used after a nested function. */
1771 void
1772 restore_emit_status (p)
1773 struct function *p ATTRIBUTE_UNUSED;
1775 last_label_num = 0;
1776 clear_emit_caches ();
1779 /* Clear out all parts of the state in F that can safely be discarded
1780 after the function has been compiled, to let garbage collection
1781 reclaim the memory. */
1783 void
1784 free_emit_status (f)
1785 struct function *f;
1787 free (f->emit->x_regno_reg_rtx);
1788 free (f->emit->regno_pointer_align);
1789 free (f->emit);
1790 f->emit = NULL;
1793 /* Go through all the RTL insn bodies and copy any invalid shared
1794 structure. This routine should only be called once. */
1796 void
1797 unshare_all_rtl (fndecl, insn)
1798 tree fndecl;
1799 rtx insn;
1801 tree decl;
1803 /* Make sure that virtual parameters are not shared. */
1804 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
1805 SET_DECL_RTL (decl, copy_rtx_if_shared (DECL_RTL (decl)));
1807 /* Make sure that virtual stack slots are not shared. */
1808 unshare_all_decls (DECL_INITIAL (fndecl));
1810 /* Unshare just about everything else. */
1811 unshare_all_rtl_1 (insn);
1813 /* Make sure the addresses of stack slots found outside the insn chain
1814 (such as, in DECL_RTL of a variable) are not shared
1815 with the insn chain.
1817 This special care is necessary when the stack slot MEM does not
1818 actually appear in the insn chain. If it does appear, its address
1819 is unshared from all else at that point. */
1820 stack_slot_list = copy_rtx_if_shared (stack_slot_list);
1823 /* Go through all the RTL insn bodies and copy any invalid shared
1824 structure, again. This is a fairly expensive thing to do so it
1825 should be done sparingly. */
1827 void
1828 unshare_all_rtl_again (insn)
1829 rtx insn;
1831 rtx p;
1832 tree decl;
1834 for (p = insn; p; p = NEXT_INSN (p))
1835 if (INSN_P (p))
1837 reset_used_flags (PATTERN (p));
1838 reset_used_flags (REG_NOTES (p));
1839 reset_used_flags (LOG_LINKS (p));
1842 /* Make sure that virtual stack slots are not shared. */
1843 reset_used_decls (DECL_INITIAL (cfun->decl));
1845 /* Make sure that virtual parameters are not shared. */
1846 for (decl = DECL_ARGUMENTS (cfun->decl); decl; decl = TREE_CHAIN (decl))
1847 reset_used_flags (DECL_RTL (decl));
1849 reset_used_flags (stack_slot_list);
1851 unshare_all_rtl (cfun->decl, insn);
1854 /* Go through all the RTL insn bodies and copy any invalid shared structure.
1855 Assumes the mark bits are cleared at entry. */
1857 static void
1858 unshare_all_rtl_1 (insn)
1859 rtx insn;
1861 for (; insn; insn = NEXT_INSN (insn))
1862 if (INSN_P (insn))
1864 PATTERN (insn) = copy_rtx_if_shared (PATTERN (insn));
1865 REG_NOTES (insn) = copy_rtx_if_shared (REG_NOTES (insn));
1866 LOG_LINKS (insn) = copy_rtx_if_shared (LOG_LINKS (insn));
1870 /* Go through all virtual stack slots of a function and copy any
1871 shared structure. */
1872 static void
1873 unshare_all_decls (blk)
1874 tree blk;
1876 tree t;
1878 /* Copy shared decls. */
1879 for (t = BLOCK_VARS (blk); t; t = TREE_CHAIN (t))
1880 if (DECL_RTL_SET_P (t))
1881 SET_DECL_RTL (t, copy_rtx_if_shared (DECL_RTL (t)));
1883 /* Now process sub-blocks. */
1884 for (t = BLOCK_SUBBLOCKS (blk); t; t = TREE_CHAIN (t))
1885 unshare_all_decls (t);
1888 /* Go through all virtual stack slots of a function and mark them as
1889 not shared. */
1890 static void
1891 reset_used_decls (blk)
1892 tree blk;
1894 tree t;
1896 /* Mark decls. */
1897 for (t = BLOCK_VARS (blk); t; t = TREE_CHAIN (t))
1898 if (DECL_RTL_SET_P (t))
1899 reset_used_flags (DECL_RTL (t));
1901 /* Now process sub-blocks. */
1902 for (t = BLOCK_SUBBLOCKS (blk); t; t = TREE_CHAIN (t))
1903 reset_used_decls (t);
1906 /* Mark ORIG as in use, and return a copy of it if it was already in use.
1907 Recursively does the same for subexpressions. */
1910 copy_rtx_if_shared (orig)
1911 rtx orig;
1913 register rtx x = orig;
1914 register int i;
1915 register enum rtx_code code;
1916 register const char *format_ptr;
1917 int copied = 0;
1919 if (x == 0)
1920 return 0;
1922 code = GET_CODE (x);
1924 /* These types may be freely shared. */
1926 switch (code)
1928 case REG:
1929 case QUEUED:
1930 case CONST_INT:
1931 case CONST_DOUBLE:
1932 case SYMBOL_REF:
1933 case CODE_LABEL:
1934 case PC:
1935 case CC0:
1936 case SCRATCH:
1937 /* SCRATCH must be shared because they represent distinct values. */
1938 return x;
1940 case CONST:
1941 /* CONST can be shared if it contains a SYMBOL_REF. If it contains
1942 a LABEL_REF, it isn't sharable. */
1943 if (GET_CODE (XEXP (x, 0)) == PLUS
1944 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
1945 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
1946 return x;
1947 break;
1949 case INSN:
1950 case JUMP_INSN:
1951 case CALL_INSN:
1952 case NOTE:
1953 case BARRIER:
1954 /* The chain of insns is not being copied. */
1955 return x;
1957 case MEM:
1958 /* A MEM is allowed to be shared if its address is constant.
1960 We used to allow sharing of MEMs which referenced
1961 virtual_stack_vars_rtx or virtual_incoming_args_rtx, but
1962 that can lose. instantiate_virtual_regs will not unshare
1963 the MEMs, and combine may change the structure of the address
1964 because it looks safe and profitable in one context, but
1965 in some other context it creates unrecognizable RTL. */
1966 if (CONSTANT_ADDRESS_P (XEXP (x, 0)))
1967 return x;
1969 break;
1971 default:
1972 break;
1975 /* This rtx may not be shared. If it has already been seen,
1976 replace it with a copy of itself. */
1978 if (x->used)
1980 register rtx copy;
1982 copy = rtx_alloc (code);
1983 memcpy (copy, x,
1984 (sizeof (*copy) - sizeof (copy->fld)
1985 + sizeof (copy->fld[0]) * GET_RTX_LENGTH (code)));
1986 x = copy;
1987 copied = 1;
1989 x->used = 1;
1991 /* Now scan the subexpressions recursively.
1992 We can store any replaced subexpressions directly into X
1993 since we know X is not shared! Any vectors in X
1994 must be copied if X was copied. */
1996 format_ptr = GET_RTX_FORMAT (code);
1998 for (i = 0; i < GET_RTX_LENGTH (code); i++)
2000 switch (*format_ptr++)
2002 case 'e':
2003 XEXP (x, i) = copy_rtx_if_shared (XEXP (x, i));
2004 break;
2006 case 'E':
2007 if (XVEC (x, i) != NULL)
2009 register int j;
2010 int len = XVECLEN (x, i);
2012 if (copied && len > 0)
2013 XVEC (x, i) = gen_rtvec_v (len, XVEC (x, i)->elem);
2014 for (j = 0; j < len; j++)
2015 XVECEXP (x, i, j) = copy_rtx_if_shared (XVECEXP (x, i, j));
2017 break;
2020 return x;
2023 /* Clear all the USED bits in X to allow copy_rtx_if_shared to be used
2024 to look for shared sub-parts. */
2026 void
2027 reset_used_flags (x)
2028 rtx x;
2030 register int i, j;
2031 register enum rtx_code code;
2032 register const char *format_ptr;
2034 if (x == 0)
2035 return;
2037 code = GET_CODE (x);
2039 /* These types may be freely shared so we needn't do any resetting
2040 for them. */
2042 switch (code)
2044 case REG:
2045 case QUEUED:
2046 case CONST_INT:
2047 case CONST_DOUBLE:
2048 case SYMBOL_REF:
2049 case CODE_LABEL:
2050 case PC:
2051 case CC0:
2052 return;
2054 case INSN:
2055 case JUMP_INSN:
2056 case CALL_INSN:
2057 case NOTE:
2058 case LABEL_REF:
2059 case BARRIER:
2060 /* The chain of insns is not being copied. */
2061 return;
2063 default:
2064 break;
2067 x->used = 0;
2069 format_ptr = GET_RTX_FORMAT (code);
2070 for (i = 0; i < GET_RTX_LENGTH (code); i++)
2072 switch (*format_ptr++)
2074 case 'e':
2075 reset_used_flags (XEXP (x, i));
2076 break;
2078 case 'E':
2079 for (j = 0; j < XVECLEN (x, i); j++)
2080 reset_used_flags (XVECEXP (x, i, j));
2081 break;
2086 /* Copy X if necessary so that it won't be altered by changes in OTHER.
2087 Return X or the rtx for the pseudo reg the value of X was copied into.
2088 OTHER must be valid as a SET_DEST. */
2091 make_safe_from (x, other)
2092 rtx x, other;
2094 while (1)
2095 switch (GET_CODE (other))
2097 case SUBREG:
2098 other = SUBREG_REG (other);
2099 break;
2100 case STRICT_LOW_PART:
2101 case SIGN_EXTEND:
2102 case ZERO_EXTEND:
2103 other = XEXP (other, 0);
2104 break;
2105 default:
2106 goto done;
2108 done:
2109 if ((GET_CODE (other) == MEM
2110 && ! CONSTANT_P (x)
2111 && GET_CODE (x) != REG
2112 && GET_CODE (x) != SUBREG)
2113 || (GET_CODE (other) == REG
2114 && (REGNO (other) < FIRST_PSEUDO_REGISTER
2115 || reg_mentioned_p (other, x))))
2117 rtx temp = gen_reg_rtx (GET_MODE (x));
2118 emit_move_insn (temp, x);
2119 return temp;
2121 return x;
2124 /* Emission of insns (adding them to the doubly-linked list). */
2126 /* Return the first insn of the current sequence or current function. */
2129 get_insns ()
2131 return first_insn;
2134 /* Return the last insn emitted in current sequence or current function. */
2137 get_last_insn ()
2139 return last_insn;
2142 /* Specify a new insn as the last in the chain. */
2144 void
2145 set_last_insn (insn)
2146 rtx insn;
2148 if (NEXT_INSN (insn) != 0)
2149 abort ();
2150 last_insn = insn;
2153 /* Return the last insn emitted, even if it is in a sequence now pushed. */
2156 get_last_insn_anywhere ()
2158 struct sequence_stack *stack;
2159 if (last_insn)
2160 return last_insn;
2161 for (stack = seq_stack; stack; stack = stack->next)
2162 if (stack->last != 0)
2163 return stack->last;
2164 return 0;
2167 /* Return a number larger than any instruction's uid in this function. */
2170 get_max_uid ()
2172 return cur_insn_uid;
2175 /* Renumber instructions so that no instruction UIDs are wasted. */
2177 void
2178 renumber_insns (stream)
2179 FILE *stream;
2181 rtx insn;
2183 /* If we're not supposed to renumber instructions, don't. */
2184 if (!flag_renumber_insns)
2185 return;
2187 /* If there aren't that many instructions, then it's not really
2188 worth renumbering them. */
2189 if (flag_renumber_insns == 1 && get_max_uid () < 25000)
2190 return;
2192 cur_insn_uid = 1;
2194 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2196 if (stream)
2197 fprintf (stream, "Renumbering insn %d to %d\n",
2198 INSN_UID (insn), cur_insn_uid);
2199 INSN_UID (insn) = cur_insn_uid++;
2203 /* Return the next insn. If it is a SEQUENCE, return the first insn
2204 of the sequence. */
2207 next_insn (insn)
2208 rtx insn;
2210 if (insn)
2212 insn = NEXT_INSN (insn);
2213 if (insn && GET_CODE (insn) == INSN
2214 && GET_CODE (PATTERN (insn)) == SEQUENCE)
2215 insn = XVECEXP (PATTERN (insn), 0, 0);
2218 return insn;
2221 /* Return the previous insn. If it is a SEQUENCE, return the last insn
2222 of the sequence. */
2225 previous_insn (insn)
2226 rtx insn;
2228 if (insn)
2230 insn = PREV_INSN (insn);
2231 if (insn && GET_CODE (insn) == INSN
2232 && GET_CODE (PATTERN (insn)) == SEQUENCE)
2233 insn = XVECEXP (PATTERN (insn), 0, XVECLEN (PATTERN (insn), 0) - 1);
2236 return insn;
2239 /* Return the next insn after INSN that is not a NOTE. This routine does not
2240 look inside SEQUENCEs. */
2243 next_nonnote_insn (insn)
2244 rtx insn;
2246 while (insn)
2248 insn = NEXT_INSN (insn);
2249 if (insn == 0 || GET_CODE (insn) != NOTE)
2250 break;
2253 return insn;
2256 /* Return the previous insn before INSN that is not a NOTE. This routine does
2257 not look inside SEQUENCEs. */
2260 prev_nonnote_insn (insn)
2261 rtx insn;
2263 while (insn)
2265 insn = PREV_INSN (insn);
2266 if (insn == 0 || GET_CODE (insn) != NOTE)
2267 break;
2270 return insn;
2273 /* Return the next INSN, CALL_INSN or JUMP_INSN after INSN;
2274 or 0, if there is none. This routine does not look inside
2275 SEQUENCEs. */
2278 next_real_insn (insn)
2279 rtx insn;
2281 while (insn)
2283 insn = NEXT_INSN (insn);
2284 if (insn == 0 || GET_CODE (insn) == INSN
2285 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN)
2286 break;
2289 return insn;
2292 /* Return the last INSN, CALL_INSN or JUMP_INSN before INSN;
2293 or 0, if there is none. This routine does not look inside
2294 SEQUENCEs. */
2297 prev_real_insn (insn)
2298 rtx insn;
2300 while (insn)
2302 insn = PREV_INSN (insn);
2303 if (insn == 0 || GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
2304 || GET_CODE (insn) == JUMP_INSN)
2305 break;
2308 return insn;
2311 /* Find the next insn after INSN that really does something. This routine
2312 does not look inside SEQUENCEs. Until reload has completed, this is the
2313 same as next_real_insn. */
2316 active_insn_p (insn)
2317 rtx insn;
2319 return (GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN
2320 || (GET_CODE (insn) == INSN
2321 && (! reload_completed
2322 || (GET_CODE (PATTERN (insn)) != USE
2323 && GET_CODE (PATTERN (insn)) != CLOBBER))));
2327 next_active_insn (insn)
2328 rtx insn;
2330 while (insn)
2332 insn = NEXT_INSN (insn);
2333 if (insn == 0 || active_insn_p (insn))
2334 break;
2337 return insn;
2340 /* Find the last insn before INSN that really does something. This routine
2341 does not look inside SEQUENCEs. Until reload has completed, this is the
2342 same as prev_real_insn. */
2345 prev_active_insn (insn)
2346 rtx insn;
2348 while (insn)
2350 insn = PREV_INSN (insn);
2351 if (insn == 0 || active_insn_p (insn))
2352 break;
2355 return insn;
2358 /* Return the next CODE_LABEL after the insn INSN, or 0 if there is none. */
2361 next_label (insn)
2362 rtx insn;
2364 while (insn)
2366 insn = NEXT_INSN (insn);
2367 if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
2368 break;
2371 return insn;
2374 /* Return the last CODE_LABEL before the insn INSN, or 0 if there is none. */
2377 prev_label (insn)
2378 rtx insn;
2380 while (insn)
2382 insn = PREV_INSN (insn);
2383 if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
2384 break;
2387 return insn;
2390 #ifdef HAVE_cc0
2391 /* INSN uses CC0 and is being moved into a delay slot. Set up REG_CC_SETTER
2392 and REG_CC_USER notes so we can find it. */
2394 void
2395 link_cc0_insns (insn)
2396 rtx insn;
2398 rtx user = next_nonnote_insn (insn);
2400 if (GET_CODE (user) == INSN && GET_CODE (PATTERN (user)) == SEQUENCE)
2401 user = XVECEXP (PATTERN (user), 0, 0);
2403 REG_NOTES (user) = gen_rtx_INSN_LIST (REG_CC_SETTER, insn,
2404 REG_NOTES (user));
2405 REG_NOTES (insn) = gen_rtx_INSN_LIST (REG_CC_USER, user, REG_NOTES (insn));
2408 /* Return the next insn that uses CC0 after INSN, which is assumed to
2409 set it. This is the inverse of prev_cc0_setter (i.e., prev_cc0_setter
2410 applied to the result of this function should yield INSN).
2412 Normally, this is simply the next insn. However, if a REG_CC_USER note
2413 is present, it contains the insn that uses CC0.
2415 Return 0 if we can't find the insn. */
2418 next_cc0_user (insn)
2419 rtx insn;
2421 rtx note = find_reg_note (insn, REG_CC_USER, NULL_RTX);
2423 if (note)
2424 return XEXP (note, 0);
2426 insn = next_nonnote_insn (insn);
2427 if (insn && GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
2428 insn = XVECEXP (PATTERN (insn), 0, 0);
2430 if (insn && INSN_P (insn) && reg_mentioned_p (cc0_rtx, PATTERN (insn)))
2431 return insn;
2433 return 0;
2436 /* Find the insn that set CC0 for INSN. Unless INSN has a REG_CC_SETTER
2437 note, it is the previous insn. */
2440 prev_cc0_setter (insn)
2441 rtx insn;
2443 rtx note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
2445 if (note)
2446 return XEXP (note, 0);
2448 insn = prev_nonnote_insn (insn);
2449 if (! sets_cc0_p (PATTERN (insn)))
2450 abort ();
2452 return insn;
2454 #endif
2456 /* Increment the label uses for all labels present in rtx. */
2458 static void
2459 mark_label_nuses(x)
2460 rtx x;
2462 register enum rtx_code code;
2463 register int i, j;
2464 register const char *fmt;
2466 code = GET_CODE (x);
2467 if (code == LABEL_REF)
2468 LABEL_NUSES (XEXP (x, 0))++;
2470 fmt = GET_RTX_FORMAT (code);
2471 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2473 if (fmt[i] == 'e')
2474 mark_label_nuses (XEXP (x, i));
2475 else if (fmt[i] == 'E')
2476 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2477 mark_label_nuses (XVECEXP (x, i, j));
2482 /* Try splitting insns that can be split for better scheduling.
2483 PAT is the pattern which might split.
2484 TRIAL is the insn providing PAT.
2485 LAST is non-zero if we should return the last insn of the sequence produced.
2487 If this routine succeeds in splitting, it returns the first or last
2488 replacement insn depending on the value of LAST. Otherwise, it
2489 returns TRIAL. If the insn to be returned can be split, it will be. */
2492 try_split (pat, trial, last)
2493 rtx pat, trial;
2494 int last;
2496 rtx before = PREV_INSN (trial);
2497 rtx after = NEXT_INSN (trial);
2498 int has_barrier = 0;
2499 rtx tem;
2500 rtx note, seq;
2501 int probability;
2503 if (any_condjump_p (trial)
2504 && (note = find_reg_note (trial, REG_BR_PROB, 0)))
2505 split_branch_probability = INTVAL (XEXP (note, 0));
2506 probability = split_branch_probability;
2508 seq = split_insns (pat, trial);
2510 split_branch_probability = -1;
2512 /* If we are splitting a JUMP_INSN, it might be followed by a BARRIER.
2513 We may need to handle this specially. */
2514 if (after && GET_CODE (after) == BARRIER)
2516 has_barrier = 1;
2517 after = NEXT_INSN (after);
2520 if (seq)
2522 /* SEQ can either be a SEQUENCE or the pattern of a single insn.
2523 The latter case will normally arise only when being done so that
2524 it, in turn, will be split (SFmode on the 29k is an example). */
2525 if (GET_CODE (seq) == SEQUENCE)
2527 int i, njumps = 0;
2528 rtx eh_note;
2530 /* Avoid infinite loop if any insn of the result matches
2531 the original pattern. */
2532 for (i = 0; i < XVECLEN (seq, 0); i++)
2533 if (GET_CODE (XVECEXP (seq, 0, i)) == INSN
2534 && rtx_equal_p (PATTERN (XVECEXP (seq, 0, i)), pat))
2535 return trial;
2537 /* Mark labels. */
2538 for (i = XVECLEN (seq, 0) - 1; i >= 0; i--)
2539 if (GET_CODE (XVECEXP (seq, 0, i)) == JUMP_INSN)
2541 rtx insn = XVECEXP (seq, 0, i);
2542 mark_jump_label (PATTERN (insn),
2543 XVECEXP (seq, 0, i), 0);
2544 njumps++;
2545 if (probability != -1
2546 && any_condjump_p (insn)
2547 && !find_reg_note (insn, REG_BR_PROB, 0))
2549 /* We can preserve the REG_BR_PROB notes only if exactly
2550 one jump is created, otherwise the machinde description
2551 is responsible for this step using
2552 split_branch_probability variable. */
2553 if (njumps != 1)
2554 abort ();
2555 REG_NOTES (insn)
2556 = gen_rtx_EXPR_LIST (REG_BR_PROB,
2557 GEN_INT (probability),
2558 REG_NOTES (insn));
2561 /* If we are splitting a CALL_INSN, look for the CALL_INSN
2562 in SEQ and copy our CALL_INSN_FUNCTION_USAGE to it. */
2563 if (GET_CODE (trial) == CALL_INSN)
2564 for (i = XVECLEN (seq, 0) - 1; i >= 0; i--)
2565 if (GET_CODE (XVECEXP (seq, 0, i)) == CALL_INSN)
2566 CALL_INSN_FUNCTION_USAGE (XVECEXP (seq, 0, i))
2567 = CALL_INSN_FUNCTION_USAGE (trial);
2569 /* Copy EH notes. */
2570 if ((eh_note = find_reg_note (trial, REG_EH_REGION, NULL_RTX)))
2571 for (i = 0; i < XVECLEN (seq, 0); i++)
2573 rtx insn = XVECEXP (seq, 0, i);
2574 if (GET_CODE (insn) == CALL_INSN
2575 || (flag_non_call_exceptions
2576 && may_trap_p (PATTERN (insn))))
2577 REG_NOTES (insn)
2578 = gen_rtx_EXPR_LIST (REG_EH_REGION, XEXP (eh_note, 0),
2579 REG_NOTES (insn));
2582 /* If there are LABELS inside the split insns increment the
2583 usage count so we don't delete the label. */
2584 if (GET_CODE (trial) == INSN)
2585 for (i = XVECLEN (seq, 0) - 1; i >= 0; i--)
2586 if (GET_CODE (XVECEXP (seq, 0, i)) == INSN)
2587 mark_label_nuses (PATTERN (XVECEXP (seq, 0, i)));
2589 tem = emit_insn_after (seq, before);
2591 delete_insn (trial);
2592 if (has_barrier)
2593 emit_barrier_after (tem);
2595 /* Recursively call try_split for each new insn created; by the
2596 time control returns here that insn will be fully split, so
2597 set LAST and continue from the insn after the one returned.
2598 We can't use next_active_insn here since AFTER may be a note.
2599 Ignore deleted insns, which can be occur if not optimizing. */
2600 for (tem = NEXT_INSN (before); tem != after; tem = NEXT_INSN (tem))
2601 if (! INSN_DELETED_P (tem) && INSN_P (tem))
2602 tem = try_split (PATTERN (tem), tem, 1);
2604 /* Avoid infinite loop if the result matches the original pattern. */
2605 else if (rtx_equal_p (seq, pat))
2606 return trial;
2607 else
2609 PATTERN (trial) = seq;
2610 INSN_CODE (trial) = -1;
2611 try_split (seq, trial, last);
2614 /* Return either the first or the last insn, depending on which was
2615 requested. */
2616 return last
2617 ? (after ? PREV_INSN (after) : last_insn)
2618 : NEXT_INSN (before);
2621 return trial;
2624 /* Make and return an INSN rtx, initializing all its slots.
2625 Store PATTERN in the pattern slots. */
2628 make_insn_raw (pattern)
2629 rtx pattern;
2631 register rtx insn;
2633 insn = rtx_alloc (INSN);
2635 INSN_UID (insn) = cur_insn_uid++;
2636 PATTERN (insn) = pattern;
2637 INSN_CODE (insn) = -1;
2638 LOG_LINKS (insn) = NULL;
2639 REG_NOTES (insn) = NULL;
2641 #ifdef ENABLE_RTL_CHECKING
2642 if (insn
2643 && INSN_P (insn)
2644 && (returnjump_p (insn)
2645 || (GET_CODE (insn) == SET
2646 && SET_DEST (insn) == pc_rtx)))
2648 warning ("ICE: emit_insn used where emit_jump_insn needed:\n");
2649 debug_rtx (insn);
2651 #endif
2653 return insn;
2656 /* Like `make_insn' but make a JUMP_INSN instead of an insn. */
2658 static rtx
2659 make_jump_insn_raw (pattern)
2660 rtx pattern;
2662 register rtx insn;
2664 insn = rtx_alloc (JUMP_INSN);
2665 INSN_UID (insn) = cur_insn_uid++;
2667 PATTERN (insn) = pattern;
2668 INSN_CODE (insn) = -1;
2669 LOG_LINKS (insn) = NULL;
2670 REG_NOTES (insn) = NULL;
2671 JUMP_LABEL (insn) = NULL;
2673 return insn;
2676 /* Like `make_insn' but make a CALL_INSN instead of an insn. */
2678 static rtx
2679 make_call_insn_raw (pattern)
2680 rtx pattern;
2682 register rtx insn;
2684 insn = rtx_alloc (CALL_INSN);
2685 INSN_UID (insn) = cur_insn_uid++;
2687 PATTERN (insn) = pattern;
2688 INSN_CODE (insn) = -1;
2689 LOG_LINKS (insn) = NULL;
2690 REG_NOTES (insn) = NULL;
2691 CALL_INSN_FUNCTION_USAGE (insn) = NULL;
2693 return insn;
2696 /* Add INSN to the end of the doubly-linked list.
2697 INSN may be an INSN, JUMP_INSN, CALL_INSN, CODE_LABEL, BARRIER or NOTE. */
2699 void
2700 add_insn (insn)
2701 register rtx insn;
2703 PREV_INSN (insn) = last_insn;
2704 NEXT_INSN (insn) = 0;
2706 if (NULL != last_insn)
2707 NEXT_INSN (last_insn) = insn;
2709 if (NULL == first_insn)
2710 first_insn = insn;
2712 last_insn = insn;
2715 /* Add INSN into the doubly-linked list after insn AFTER. This and
2716 the next should be the only functions called to insert an insn once
2717 delay slots have been filled since only they know how to update a
2718 SEQUENCE. */
2720 void
2721 add_insn_after (insn, after)
2722 rtx insn, after;
2724 rtx next = NEXT_INSN (after);
2726 if (optimize && INSN_DELETED_P (after))
2727 abort ();
2729 NEXT_INSN (insn) = next;
2730 PREV_INSN (insn) = after;
2732 if (next)
2734 PREV_INSN (next) = insn;
2735 if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == SEQUENCE)
2736 PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = insn;
2738 else if (last_insn == after)
2739 last_insn = insn;
2740 else
2742 struct sequence_stack *stack = seq_stack;
2743 /* Scan all pending sequences too. */
2744 for (; stack; stack = stack->next)
2745 if (after == stack->last)
2747 stack->last = insn;
2748 break;
2751 if (stack == 0)
2752 abort ();
2755 NEXT_INSN (after) = insn;
2756 if (GET_CODE (after) == INSN && GET_CODE (PATTERN (after)) == SEQUENCE)
2758 rtx sequence = PATTERN (after);
2759 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2763 /* Add INSN into the doubly-linked list before insn BEFORE. This and
2764 the previous should be the only functions called to insert an insn once
2765 delay slots have been filled since only they know how to update a
2766 SEQUENCE. */
2768 void
2769 add_insn_before (insn, before)
2770 rtx insn, before;
2772 rtx prev = PREV_INSN (before);
2774 if (optimize && INSN_DELETED_P (before))
2775 abort ();
2777 PREV_INSN (insn) = prev;
2778 NEXT_INSN (insn) = before;
2780 if (prev)
2782 NEXT_INSN (prev) = insn;
2783 if (GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == SEQUENCE)
2785 rtx sequence = PATTERN (prev);
2786 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2789 else if (first_insn == before)
2790 first_insn = insn;
2791 else
2793 struct sequence_stack *stack = seq_stack;
2794 /* Scan all pending sequences too. */
2795 for (; stack; stack = stack->next)
2796 if (before == stack->first)
2798 stack->first = insn;
2799 break;
2802 if (stack == 0)
2803 abort ();
2806 PREV_INSN (before) = insn;
2807 if (GET_CODE (before) == INSN && GET_CODE (PATTERN (before)) == SEQUENCE)
2808 PREV_INSN (XVECEXP (PATTERN (before), 0, 0)) = insn;
2811 /* Remove an insn from its doubly-linked list. This function knows how
2812 to handle sequences. */
2813 void
2814 remove_insn (insn)
2815 rtx insn;
2817 rtx next = NEXT_INSN (insn);
2818 rtx prev = PREV_INSN (insn);
2819 if (prev)
2821 NEXT_INSN (prev) = next;
2822 if (GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == SEQUENCE)
2824 rtx sequence = PATTERN (prev);
2825 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = next;
2828 else if (first_insn == insn)
2829 first_insn = next;
2830 else
2832 struct sequence_stack *stack = seq_stack;
2833 /* Scan all pending sequences too. */
2834 for (; stack; stack = stack->next)
2835 if (insn == stack->first)
2837 stack->first = next;
2838 break;
2841 if (stack == 0)
2842 abort ();
2845 if (next)
2847 PREV_INSN (next) = prev;
2848 if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == SEQUENCE)
2849 PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = prev;
2851 else if (last_insn == insn)
2852 last_insn = prev;
2853 else
2855 struct sequence_stack *stack = seq_stack;
2856 /* Scan all pending sequences too. */
2857 for (; stack; stack = stack->next)
2858 if (insn == stack->last)
2860 stack->last = prev;
2861 break;
2864 if (stack == 0)
2865 abort ();
2869 /* Delete all insns made since FROM.
2870 FROM becomes the new last instruction. */
2872 void
2873 delete_insns_since (from)
2874 rtx from;
2876 if (from == 0)
2877 first_insn = 0;
2878 else
2879 NEXT_INSN (from) = 0;
2880 last_insn = from;
2883 /* This function is deprecated, please use sequences instead.
2885 Move a consecutive bunch of insns to a different place in the chain.
2886 The insns to be moved are those between FROM and TO.
2887 They are moved to a new position after the insn AFTER.
2888 AFTER must not be FROM or TO or any insn in between.
2890 This function does not know about SEQUENCEs and hence should not be
2891 called after delay-slot filling has been done. */
2893 void
2894 reorder_insns (from, to, after)
2895 rtx from, to, after;
2897 /* Splice this bunch out of where it is now. */
2898 if (PREV_INSN (from))
2899 NEXT_INSN (PREV_INSN (from)) = NEXT_INSN (to);
2900 if (NEXT_INSN (to))
2901 PREV_INSN (NEXT_INSN (to)) = PREV_INSN (from);
2902 if (last_insn == to)
2903 last_insn = PREV_INSN (from);
2904 if (first_insn == from)
2905 first_insn = NEXT_INSN (to);
2907 /* Make the new neighbors point to it and it to them. */
2908 if (NEXT_INSN (after))
2909 PREV_INSN (NEXT_INSN (after)) = to;
2911 NEXT_INSN (to) = NEXT_INSN (after);
2912 PREV_INSN (from) = after;
2913 NEXT_INSN (after) = from;
2914 if (after == last_insn)
2915 last_insn = to;
2918 /* Return the line note insn preceding INSN. */
2920 static rtx
2921 find_line_note (insn)
2922 rtx insn;
2924 if (no_line_numbers)
2925 return 0;
2927 for (; insn; insn = PREV_INSN (insn))
2928 if (GET_CODE (insn) == NOTE
2929 && NOTE_LINE_NUMBER (insn) >= 0)
2930 break;
2932 return insn;
2935 /* Like reorder_insns, but inserts line notes to preserve the line numbers
2936 of the moved insns when debugging. This may insert a note between AFTER
2937 and FROM, and another one after TO. */
2939 void
2940 reorder_insns_with_line_notes (from, to, after)
2941 rtx from, to, after;
2943 rtx from_line = find_line_note (from);
2944 rtx after_line = find_line_note (after);
2946 reorder_insns (from, to, after);
2948 if (from_line == after_line)
2949 return;
2951 if (from_line)
2952 emit_line_note_after (NOTE_SOURCE_FILE (from_line),
2953 NOTE_LINE_NUMBER (from_line),
2954 after);
2955 if (after_line)
2956 emit_line_note_after (NOTE_SOURCE_FILE (after_line),
2957 NOTE_LINE_NUMBER (after_line),
2958 to);
2961 /* Remove unnecessary notes from the instruction stream. */
2963 void
2964 remove_unnecessary_notes ()
2966 rtx block_stack = NULL_RTX;
2967 rtx eh_stack = NULL_RTX;
2968 rtx insn;
2969 rtx next;
2970 rtx tmp;
2972 /* We must not remove the first instruction in the function because
2973 the compiler depends on the first instruction being a note. */
2974 for (insn = NEXT_INSN (get_insns ()); insn; insn = next)
2976 /* Remember what's next. */
2977 next = NEXT_INSN (insn);
2979 /* We're only interested in notes. */
2980 if (GET_CODE (insn) != NOTE)
2981 continue;
2983 switch (NOTE_LINE_NUMBER (insn))
2985 case NOTE_INSN_DELETED:
2986 remove_insn (insn);
2987 break;
2989 case NOTE_INSN_EH_REGION_BEG:
2990 eh_stack = alloc_INSN_LIST (insn, eh_stack);
2991 break;
2993 case NOTE_INSN_EH_REGION_END:
2994 /* Too many end notes. */
2995 if (eh_stack == NULL_RTX)
2996 abort ();
2997 /* Mismatched nesting. */
2998 if (NOTE_EH_HANDLER (XEXP (eh_stack, 0)) != NOTE_EH_HANDLER (insn))
2999 abort ();
3000 tmp = eh_stack;
3001 eh_stack = XEXP (eh_stack, 1);
3002 free_INSN_LIST_node (tmp);
3003 break;
3005 case NOTE_INSN_BLOCK_BEG:
3006 /* By now, all notes indicating lexical blocks should have
3007 NOTE_BLOCK filled in. */
3008 if (NOTE_BLOCK (insn) == NULL_TREE)
3009 abort ();
3010 block_stack = alloc_INSN_LIST (insn, block_stack);
3011 break;
3013 case NOTE_INSN_BLOCK_END:
3014 /* Too many end notes. */
3015 if (block_stack == NULL_RTX)
3016 abort ();
3017 /* Mismatched nesting. */
3018 if (NOTE_BLOCK (XEXP (block_stack, 0)) != NOTE_BLOCK (insn))
3019 abort ();
3020 tmp = block_stack;
3021 block_stack = XEXP (block_stack, 1);
3022 free_INSN_LIST_node (tmp);
3024 /* Scan back to see if there are any non-note instructions
3025 between INSN and the beginning of this block. If not,
3026 then there is no PC range in the generated code that will
3027 actually be in this block, so there's no point in
3028 remembering the existence of the block. */
3029 for (tmp = PREV_INSN (insn); tmp ; tmp = PREV_INSN (tmp))
3031 /* This block contains a real instruction. Note that we
3032 don't include labels; if the only thing in the block
3033 is a label, then there are still no PC values that
3034 lie within the block. */
3035 if (INSN_P (tmp))
3036 break;
3038 /* We're only interested in NOTEs. */
3039 if (GET_CODE (tmp) != NOTE)
3040 continue;
3042 if (NOTE_LINE_NUMBER (tmp) == NOTE_INSN_BLOCK_BEG)
3044 /* We just verified that this BLOCK matches us with
3045 the block_stack check above. Never delete the
3046 BLOCK for the outermost scope of the function; we
3047 can refer to names from that scope even if the
3048 block notes are messed up. */
3049 if (! is_body_block (NOTE_BLOCK (insn))
3050 && (*debug_hooks->ignore_block) (NOTE_BLOCK (insn)))
3052 remove_insn (tmp);
3053 remove_insn (insn);
3055 break;
3057 else if (NOTE_LINE_NUMBER (tmp) == NOTE_INSN_BLOCK_END)
3058 /* There's a nested block. We need to leave the
3059 current block in place since otherwise the debugger
3060 wouldn't be able to show symbols from our block in
3061 the nested block. */
3062 break;
3067 /* Too many begin notes. */
3068 if (block_stack || eh_stack)
3069 abort ();
3073 /* Emit an insn of given code and pattern
3074 at a specified place within the doubly-linked list. */
3076 /* Make an instruction with body PATTERN
3077 and output it before the instruction BEFORE. */
3080 emit_insn_before (pattern, before)
3081 register rtx pattern, before;
3083 register rtx insn = before;
3085 if (GET_CODE (pattern) == SEQUENCE)
3087 register int i;
3089 for (i = 0; i < XVECLEN (pattern, 0); i++)
3091 insn = XVECEXP (pattern, 0, i);
3092 add_insn_before (insn, before);
3095 else
3097 insn = make_insn_raw (pattern);
3098 add_insn_before (insn, before);
3101 return insn;
3104 /* Similar to emit_insn_before, but update basic block boundaries as well. */
3107 emit_block_insn_before (pattern, before, block)
3108 rtx pattern, before;
3109 basic_block block;
3111 rtx prev = PREV_INSN (before);
3112 rtx r = emit_insn_before (pattern, before);
3113 if (block && block->head == before)
3114 block->head = NEXT_INSN (prev);
3115 return r;
3118 /* Make an instruction with body PATTERN and code JUMP_INSN
3119 and output it before the instruction BEFORE. */
3122 emit_jump_insn_before (pattern, before)
3123 register rtx pattern, before;
3125 register rtx insn;
3127 if (GET_CODE (pattern) == SEQUENCE)
3128 insn = emit_insn_before (pattern, before);
3129 else
3131 insn = make_jump_insn_raw (pattern);
3132 add_insn_before (insn, before);
3135 return insn;
3138 /* Make an instruction with body PATTERN and code CALL_INSN
3139 and output it before the instruction BEFORE. */
3142 emit_call_insn_before (pattern, before)
3143 register rtx pattern, before;
3145 register rtx insn;
3147 if (GET_CODE (pattern) == SEQUENCE)
3148 insn = emit_insn_before (pattern, before);
3149 else
3151 insn = make_call_insn_raw (pattern);
3152 add_insn_before (insn, before);
3153 PUT_CODE (insn, CALL_INSN);
3156 return insn;
3159 /* Make an insn of code BARRIER
3160 and output it before the insn BEFORE. */
3163 emit_barrier_before (before)
3164 register rtx before;
3166 register rtx insn = rtx_alloc (BARRIER);
3168 INSN_UID (insn) = cur_insn_uid++;
3170 add_insn_before (insn, before);
3171 return insn;
3174 /* Emit the label LABEL before the insn BEFORE. */
3177 emit_label_before (label, before)
3178 rtx label, before;
3180 /* This can be called twice for the same label as a result of the
3181 confusion that follows a syntax error! So make it harmless. */
3182 if (INSN_UID (label) == 0)
3184 INSN_UID (label) = cur_insn_uid++;
3185 add_insn_before (label, before);
3188 return label;
3191 /* Emit a note of subtype SUBTYPE before the insn BEFORE. */
3194 emit_note_before (subtype, before)
3195 int subtype;
3196 rtx before;
3198 register rtx note = rtx_alloc (NOTE);
3199 INSN_UID (note) = cur_insn_uid++;
3200 NOTE_SOURCE_FILE (note) = 0;
3201 NOTE_LINE_NUMBER (note) = subtype;
3203 add_insn_before (note, before);
3204 return note;
3207 /* Make an insn of code INSN with body PATTERN
3208 and output it after the insn AFTER. */
3211 emit_insn_after (pattern, after)
3212 register rtx pattern, after;
3214 register rtx insn = after;
3216 if (GET_CODE (pattern) == SEQUENCE)
3218 register int i;
3220 for (i = 0; i < XVECLEN (pattern, 0); i++)
3222 insn = XVECEXP (pattern, 0, i);
3223 add_insn_after (insn, after);
3224 after = insn;
3227 else
3229 insn = make_insn_raw (pattern);
3230 add_insn_after (insn, after);
3233 return insn;
3236 /* Similar to emit_insn_after, except that line notes are to be inserted so
3237 as to act as if this insn were at FROM. */
3239 void
3240 emit_insn_after_with_line_notes (pattern, after, from)
3241 rtx pattern, after, from;
3243 rtx from_line = find_line_note (from);
3244 rtx after_line = find_line_note (after);
3245 rtx insn = emit_insn_after (pattern, after);
3247 if (from_line)
3248 emit_line_note_after (NOTE_SOURCE_FILE (from_line),
3249 NOTE_LINE_NUMBER (from_line),
3250 after);
3252 if (after_line)
3253 emit_line_note_after (NOTE_SOURCE_FILE (after_line),
3254 NOTE_LINE_NUMBER (after_line),
3255 insn);
3258 /* Similar to emit_insn_after, but update basic block boundaries as well. */
3261 emit_block_insn_after (pattern, after, block)
3262 rtx pattern, after;
3263 basic_block block;
3265 rtx r = emit_insn_after (pattern, after);
3266 if (block && block->end == after)
3267 block->end = r;
3268 return r;
3271 /* Make an insn of code JUMP_INSN with body PATTERN
3272 and output it after the insn AFTER. */
3275 emit_jump_insn_after (pattern, after)
3276 register rtx pattern, after;
3278 register rtx insn;
3280 if (GET_CODE (pattern) == SEQUENCE)
3281 insn = emit_insn_after (pattern, after);
3282 else
3284 insn = make_jump_insn_raw (pattern);
3285 add_insn_after (insn, after);
3288 return insn;
3291 /* Make an insn of code BARRIER
3292 and output it after the insn AFTER. */
3295 emit_barrier_after (after)
3296 register rtx after;
3298 register rtx insn = rtx_alloc (BARRIER);
3300 INSN_UID (insn) = cur_insn_uid++;
3302 add_insn_after (insn, after);
3303 return insn;
3306 /* Emit the label LABEL after the insn AFTER. */
3309 emit_label_after (label, after)
3310 rtx label, after;
3312 /* This can be called twice for the same label
3313 as a result of the confusion that follows a syntax error!
3314 So make it harmless. */
3315 if (INSN_UID (label) == 0)
3317 INSN_UID (label) = cur_insn_uid++;
3318 add_insn_after (label, after);
3321 return label;
3324 /* Emit a note of subtype SUBTYPE after the insn AFTER. */
3327 emit_note_after (subtype, after)
3328 int subtype;
3329 rtx after;
3331 register rtx note = rtx_alloc (NOTE);
3332 INSN_UID (note) = cur_insn_uid++;
3333 NOTE_SOURCE_FILE (note) = 0;
3334 NOTE_LINE_NUMBER (note) = subtype;
3335 add_insn_after (note, after);
3336 return note;
3339 /* Emit a line note for FILE and LINE after the insn AFTER. */
3342 emit_line_note_after (file, line, after)
3343 const char *file;
3344 int line;
3345 rtx after;
3347 register rtx note;
3349 if (no_line_numbers && line > 0)
3351 cur_insn_uid++;
3352 return 0;
3355 note = rtx_alloc (NOTE);
3356 INSN_UID (note) = cur_insn_uid++;
3357 NOTE_SOURCE_FILE (note) = file;
3358 NOTE_LINE_NUMBER (note) = line;
3359 add_insn_after (note, after);
3360 return note;
3363 /* Make an insn of code INSN with pattern PATTERN
3364 and add it to the end of the doubly-linked list.
3365 If PATTERN is a SEQUENCE, take the elements of it
3366 and emit an insn for each element.
3368 Returns the last insn emitted. */
3371 emit_insn (pattern)
3372 rtx pattern;
3374 rtx insn = last_insn;
3376 if (GET_CODE (pattern) == SEQUENCE)
3378 register int i;
3380 for (i = 0; i < XVECLEN (pattern, 0); i++)
3382 insn = XVECEXP (pattern, 0, i);
3383 add_insn (insn);
3386 else
3388 insn = make_insn_raw (pattern);
3389 add_insn (insn);
3392 return insn;
3395 /* Emit the insns in a chain starting with INSN.
3396 Return the last insn emitted. */
3399 emit_insns (insn)
3400 rtx insn;
3402 rtx last = 0;
3404 while (insn)
3406 rtx next = NEXT_INSN (insn);
3407 add_insn (insn);
3408 last = insn;
3409 insn = next;
3412 return last;
3415 /* Emit the insns in a chain starting with INSN and place them in front of
3416 the insn BEFORE. Return the last insn emitted. */
3419 emit_insns_before (insn, before)
3420 rtx insn;
3421 rtx before;
3423 rtx last = 0;
3425 while (insn)
3427 rtx next = NEXT_INSN (insn);
3428 add_insn_before (insn, before);
3429 last = insn;
3430 insn = next;
3433 return last;
3436 /* Emit the insns in a chain starting with FIRST and place them in back of
3437 the insn AFTER. Return the last insn emitted. */
3440 emit_insns_after (first, after)
3441 register rtx first;
3442 register rtx after;
3444 register rtx last;
3445 register rtx after_after;
3447 if (!after)
3448 abort ();
3450 if (!first)
3451 return first;
3453 for (last = first; NEXT_INSN (last); last = NEXT_INSN (last))
3454 continue;
3456 after_after = NEXT_INSN (after);
3458 NEXT_INSN (after) = first;
3459 PREV_INSN (first) = after;
3460 NEXT_INSN (last) = after_after;
3461 if (after_after)
3462 PREV_INSN (after_after) = last;
3464 if (after == last_insn)
3465 last_insn = last;
3466 return last;
3469 /* Make an insn of code JUMP_INSN with pattern PATTERN
3470 and add it to the end of the doubly-linked list. */
3473 emit_jump_insn (pattern)
3474 rtx pattern;
3476 if (GET_CODE (pattern) == SEQUENCE)
3477 return emit_insn (pattern);
3478 else
3480 register rtx insn = make_jump_insn_raw (pattern);
3481 add_insn (insn);
3482 return insn;
3486 /* Make an insn of code CALL_INSN with pattern PATTERN
3487 and add it to the end of the doubly-linked list. */
3490 emit_call_insn (pattern)
3491 rtx pattern;
3493 if (GET_CODE (pattern) == SEQUENCE)
3494 return emit_insn (pattern);
3495 else
3497 register rtx insn = make_call_insn_raw (pattern);
3498 add_insn (insn);
3499 PUT_CODE (insn, CALL_INSN);
3500 return insn;
3504 /* Add the label LABEL to the end of the doubly-linked list. */
3507 emit_label (label)
3508 rtx label;
3510 /* This can be called twice for the same label
3511 as a result of the confusion that follows a syntax error!
3512 So make it harmless. */
3513 if (INSN_UID (label) == 0)
3515 INSN_UID (label) = cur_insn_uid++;
3516 add_insn (label);
3518 return label;
3521 /* Make an insn of code BARRIER
3522 and add it to the end of the doubly-linked list. */
3525 emit_barrier ()
3527 register rtx barrier = rtx_alloc (BARRIER);
3528 INSN_UID (barrier) = cur_insn_uid++;
3529 add_insn (barrier);
3530 return barrier;
3533 /* Make an insn of code NOTE
3534 with data-fields specified by FILE and LINE
3535 and add it to the end of the doubly-linked list,
3536 but only if line-numbers are desired for debugging info. */
3539 emit_line_note (file, line)
3540 const char *file;
3541 int line;
3543 set_file_and_line_for_stmt (file, line);
3545 #if 0
3546 if (no_line_numbers)
3547 return 0;
3548 #endif
3550 return emit_note (file, line);
3553 /* Make an insn of code NOTE
3554 with data-fields specified by FILE and LINE
3555 and add it to the end of the doubly-linked list.
3556 If it is a line-number NOTE, omit it if it matches the previous one. */
3559 emit_note (file, line)
3560 const char *file;
3561 int line;
3563 register rtx note;
3565 if (line > 0)
3567 if (file && last_filename && !strcmp (file, last_filename)
3568 && line == last_linenum)
3569 return 0;
3570 last_filename = file;
3571 last_linenum = line;
3574 if (no_line_numbers && line > 0)
3576 cur_insn_uid++;
3577 return 0;
3580 note = rtx_alloc (NOTE);
3581 INSN_UID (note) = cur_insn_uid++;
3582 NOTE_SOURCE_FILE (note) = file;
3583 NOTE_LINE_NUMBER (note) = line;
3584 add_insn (note);
3585 return note;
3588 /* Emit a NOTE, and don't omit it even if LINE is the previous note. */
3591 emit_line_note_force (file, line)
3592 const char *file;
3593 int line;
3595 last_linenum = -1;
3596 return emit_line_note (file, line);
3599 /* Cause next statement to emit a line note even if the line number
3600 has not changed. This is used at the beginning of a function. */
3602 void
3603 force_next_line_note ()
3605 last_linenum = -1;
3608 /* Place a note of KIND on insn INSN with DATUM as the datum. If a
3609 note of this type already exists, remove it first. */
3611 void
3612 set_unique_reg_note (insn, kind, datum)
3613 rtx insn;
3614 enum reg_note kind;
3615 rtx datum;
3617 rtx note = find_reg_note (insn, kind, NULL_RTX);
3619 /* First remove the note if there already is one. */
3620 if (note)
3621 remove_note (insn, note);
3623 REG_NOTES (insn) = gen_rtx_EXPR_LIST (kind, datum, REG_NOTES (insn));
3626 /* Return an indication of which type of insn should have X as a body.
3627 The value is CODE_LABEL, INSN, CALL_INSN or JUMP_INSN. */
3629 enum rtx_code
3630 classify_insn (x)
3631 rtx x;
3633 if (GET_CODE (x) == CODE_LABEL)
3634 return CODE_LABEL;
3635 if (GET_CODE (x) == CALL)
3636 return CALL_INSN;
3637 if (GET_CODE (x) == RETURN)
3638 return JUMP_INSN;
3639 if (GET_CODE (x) == SET)
3641 if (SET_DEST (x) == pc_rtx)
3642 return JUMP_INSN;
3643 else if (GET_CODE (SET_SRC (x)) == CALL)
3644 return CALL_INSN;
3645 else
3646 return INSN;
3648 if (GET_CODE (x) == PARALLEL)
3650 register int j;
3651 for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
3652 if (GET_CODE (XVECEXP (x, 0, j)) == CALL)
3653 return CALL_INSN;
3654 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
3655 && SET_DEST (XVECEXP (x, 0, j)) == pc_rtx)
3656 return JUMP_INSN;
3657 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
3658 && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == CALL)
3659 return CALL_INSN;
3661 return INSN;
3664 /* Emit the rtl pattern X as an appropriate kind of insn.
3665 If X is a label, it is simply added into the insn chain. */
3668 emit (x)
3669 rtx x;
3671 enum rtx_code code = classify_insn (x);
3673 if (code == CODE_LABEL)
3674 return emit_label (x);
3675 else if (code == INSN)
3676 return emit_insn (x);
3677 else if (code == JUMP_INSN)
3679 register rtx insn = emit_jump_insn (x);
3680 if (any_uncondjump_p (insn) || GET_CODE (x) == RETURN)
3681 return emit_barrier ();
3682 return insn;
3684 else if (code == CALL_INSN)
3685 return emit_call_insn (x);
3686 else
3687 abort ();
3690 /* Begin emitting insns to a sequence which can be packaged in an
3691 RTL_EXPR. If this sequence will contain something that might cause
3692 the compiler to pop arguments to function calls (because those
3693 pops have previously been deferred; see INHIBIT_DEFER_POP for more
3694 details), use do_pending_stack_adjust before calling this function.
3695 That will ensure that the deferred pops are not accidentally
3696 emitted in the middle of this sequence. */
3698 void
3699 start_sequence ()
3701 struct sequence_stack *tem;
3703 tem = (struct sequence_stack *) xmalloc (sizeof (struct sequence_stack));
3705 tem->next = seq_stack;
3706 tem->first = first_insn;
3707 tem->last = last_insn;
3708 tem->sequence_rtl_expr = seq_rtl_expr;
3710 seq_stack = tem;
3712 first_insn = 0;
3713 last_insn = 0;
3716 /* Similarly, but indicate that this sequence will be placed in T, an
3717 RTL_EXPR. See the documentation for start_sequence for more
3718 information about how to use this function. */
3720 void
3721 start_sequence_for_rtl_expr (t)
3722 tree t;
3724 start_sequence ();
3726 seq_rtl_expr = t;
3729 /* Set up the insn chain starting with FIRST as the current sequence,
3730 saving the previously current one. See the documentation for
3731 start_sequence for more information about how to use this function. */
3733 void
3734 push_to_sequence (first)
3735 rtx first;
3737 rtx last;
3739 start_sequence ();
3741 for (last = first; last && NEXT_INSN (last); last = NEXT_INSN (last));
3743 first_insn = first;
3744 last_insn = last;
3747 /* Set up the insn chain from a chain stort in FIRST to LAST. */
3749 void
3750 push_to_full_sequence (first, last)
3751 rtx first, last;
3753 start_sequence ();
3754 first_insn = first;
3755 last_insn = last;
3756 /* We really should have the end of the insn chain here. */
3757 if (last && NEXT_INSN (last))
3758 abort ();
3761 /* Set up the outer-level insn chain
3762 as the current sequence, saving the previously current one. */
3764 void
3765 push_topmost_sequence ()
3767 struct sequence_stack *stack, *top = NULL;
3769 start_sequence ();
3771 for (stack = seq_stack; stack; stack = stack->next)
3772 top = stack;
3774 first_insn = top->first;
3775 last_insn = top->last;
3776 seq_rtl_expr = top->sequence_rtl_expr;
3779 /* After emitting to the outer-level insn chain, update the outer-level
3780 insn chain, and restore the previous saved state. */
3782 void
3783 pop_topmost_sequence ()
3785 struct sequence_stack *stack, *top = NULL;
3787 for (stack = seq_stack; stack; stack = stack->next)
3788 top = stack;
3790 top->first = first_insn;
3791 top->last = last_insn;
3792 /* ??? Why don't we save seq_rtl_expr here? */
3794 end_sequence ();
3797 /* After emitting to a sequence, restore previous saved state.
3799 To get the contents of the sequence just made, you must call
3800 `gen_sequence' *before* calling here.
3802 If the compiler might have deferred popping arguments while
3803 generating this sequence, and this sequence will not be immediately
3804 inserted into the instruction stream, use do_pending_stack_adjust
3805 before calling gen_sequence. That will ensure that the deferred
3806 pops are inserted into this sequence, and not into some random
3807 location in the instruction stream. See INHIBIT_DEFER_POP for more
3808 information about deferred popping of arguments. */
3810 void
3811 end_sequence ()
3813 struct sequence_stack *tem = seq_stack;
3815 first_insn = tem->first;
3816 last_insn = tem->last;
3817 seq_rtl_expr = tem->sequence_rtl_expr;
3818 seq_stack = tem->next;
3820 free (tem);
3823 /* This works like end_sequence, but records the old sequence in FIRST
3824 and LAST. */
3826 void
3827 end_full_sequence (first, last)
3828 rtx *first, *last;
3830 *first = first_insn;
3831 *last = last_insn;
3832 end_sequence();
3835 /* Return 1 if currently emitting into a sequence. */
3838 in_sequence_p ()
3840 return seq_stack != 0;
3843 /* Generate a SEQUENCE rtx containing the insns already emitted
3844 to the current sequence.
3846 This is how the gen_... function from a DEFINE_EXPAND
3847 constructs the SEQUENCE that it returns. */
3850 gen_sequence ()
3852 rtx result;
3853 rtx tem;
3854 int i;
3855 int len;
3857 /* Count the insns in the chain. */
3858 len = 0;
3859 for (tem = first_insn; tem; tem = NEXT_INSN (tem))
3860 len++;
3862 /* If only one insn, return it rather than a SEQUENCE.
3863 (Now that we cache SEQUENCE expressions, it isn't worth special-casing
3864 the case of an empty list.)
3865 We only return the pattern of an insn if its code is INSN and it
3866 has no notes. This ensures that no information gets lost. */
3867 if (len == 1
3868 && ! RTX_FRAME_RELATED_P (first_insn)
3869 && GET_CODE (first_insn) == INSN
3870 /* Don't throw away any reg notes. */
3871 && REG_NOTES (first_insn) == 0)
3872 return PATTERN (first_insn);
3874 result = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (len));
3876 for (i = 0, tem = first_insn; tem; tem = NEXT_INSN (tem), i++)
3877 XVECEXP (result, 0, i) = tem;
3879 return result;
3882 /* Put the various virtual registers into REGNO_REG_RTX. */
3884 void
3885 init_virtual_regs (es)
3886 struct emit_status *es;
3888 rtx *ptr = es->x_regno_reg_rtx;
3889 ptr[VIRTUAL_INCOMING_ARGS_REGNUM] = virtual_incoming_args_rtx;
3890 ptr[VIRTUAL_STACK_VARS_REGNUM] = virtual_stack_vars_rtx;
3891 ptr[VIRTUAL_STACK_DYNAMIC_REGNUM] = virtual_stack_dynamic_rtx;
3892 ptr[VIRTUAL_OUTGOING_ARGS_REGNUM] = virtual_outgoing_args_rtx;
3893 ptr[VIRTUAL_CFA_REGNUM] = virtual_cfa_rtx;
3896 void
3897 clear_emit_caches ()
3899 int i;
3901 /* Clear the start_sequence/gen_sequence cache. */
3902 for (i = 0; i < SEQUENCE_RESULT_SIZE; i++)
3903 sequence_result[i] = 0;
3904 free_insn = 0;
3907 /* Used by copy_insn_1 to avoid copying SCRATCHes more than once. */
3908 static rtx copy_insn_scratch_in[MAX_RECOG_OPERANDS];
3909 static rtx copy_insn_scratch_out[MAX_RECOG_OPERANDS];
3910 static int copy_insn_n_scratches;
3912 /* When an insn is being copied by copy_insn_1, this is nonzero if we have
3913 copied an ASM_OPERANDS.
3914 In that case, it is the original input-operand vector. */
3915 static rtvec orig_asm_operands_vector;
3917 /* When an insn is being copied by copy_insn_1, this is nonzero if we have
3918 copied an ASM_OPERANDS.
3919 In that case, it is the copied input-operand vector. */
3920 static rtvec copy_asm_operands_vector;
3922 /* Likewise for the constraints vector. */
3923 static rtvec orig_asm_constraints_vector;
3924 static rtvec copy_asm_constraints_vector;
3926 /* Recursively create a new copy of an rtx for copy_insn.
3927 This function differs from copy_rtx in that it handles SCRATCHes and
3928 ASM_OPERANDs properly.
3929 Normally, this function is not used directly; use copy_insn as front end.
3930 However, you could first copy an insn pattern with copy_insn and then use
3931 this function afterwards to properly copy any REG_NOTEs containing
3932 SCRATCHes. */
3935 copy_insn_1 (orig)
3936 register rtx orig;
3938 register rtx copy;
3939 register int i, j;
3940 register RTX_CODE code;
3941 register const char *format_ptr;
3943 code = GET_CODE (orig);
3945 switch (code)
3947 case REG:
3948 case QUEUED:
3949 case CONST_INT:
3950 case CONST_DOUBLE:
3951 case SYMBOL_REF:
3952 case CODE_LABEL:
3953 case PC:
3954 case CC0:
3955 case ADDRESSOF:
3956 return orig;
3958 case SCRATCH:
3959 for (i = 0; i < copy_insn_n_scratches; i++)
3960 if (copy_insn_scratch_in[i] == orig)
3961 return copy_insn_scratch_out[i];
3962 break;
3964 case CONST:
3965 /* CONST can be shared if it contains a SYMBOL_REF. If it contains
3966 a LABEL_REF, it isn't sharable. */
3967 if (GET_CODE (XEXP (orig, 0)) == PLUS
3968 && GET_CODE (XEXP (XEXP (orig, 0), 0)) == SYMBOL_REF
3969 && GET_CODE (XEXP (XEXP (orig, 0), 1)) == CONST_INT)
3970 return orig;
3971 break;
3973 /* A MEM with a constant address is not sharable. The problem is that
3974 the constant address may need to be reloaded. If the mem is shared,
3975 then reloading one copy of this mem will cause all copies to appear
3976 to have been reloaded. */
3978 default:
3979 break;
3982 copy = rtx_alloc (code);
3984 /* Copy the various flags, and other information. We assume that
3985 all fields need copying, and then clear the fields that should
3986 not be copied. That is the sensible default behavior, and forces
3987 us to explicitly document why we are *not* copying a flag. */
3988 memcpy (copy, orig, sizeof (struct rtx_def) - sizeof (rtunion));
3990 /* We do not copy the USED flag, which is used as a mark bit during
3991 walks over the RTL. */
3992 copy->used = 0;
3994 /* We do not copy JUMP, CALL, or FRAME_RELATED for INSNs. */
3995 if (GET_RTX_CLASS (code) == 'i')
3997 copy->jump = 0;
3998 copy->call = 0;
3999 copy->frame_related = 0;
4002 format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
4004 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
4006 copy->fld[i] = orig->fld[i];
4007 switch (*format_ptr++)
4009 case 'e':
4010 if (XEXP (orig, i) != NULL)
4011 XEXP (copy, i) = copy_insn_1 (XEXP (orig, i));
4012 break;
4014 case 'E':
4015 case 'V':
4016 if (XVEC (orig, i) == orig_asm_constraints_vector)
4017 XVEC (copy, i) = copy_asm_constraints_vector;
4018 else if (XVEC (orig, i) == orig_asm_operands_vector)
4019 XVEC (copy, i) = copy_asm_operands_vector;
4020 else if (XVEC (orig, i) != NULL)
4022 XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
4023 for (j = 0; j < XVECLEN (copy, i); j++)
4024 XVECEXP (copy, i, j) = copy_insn_1 (XVECEXP (orig, i, j));
4026 break;
4028 case 't':
4029 case 'w':
4030 case 'i':
4031 case 's':
4032 case 'S':
4033 case 'u':
4034 case '0':
4035 /* These are left unchanged. */
4036 break;
4038 default:
4039 abort ();
4043 if (code == SCRATCH)
4045 i = copy_insn_n_scratches++;
4046 if (i >= MAX_RECOG_OPERANDS)
4047 abort ();
4048 copy_insn_scratch_in[i] = orig;
4049 copy_insn_scratch_out[i] = copy;
4051 else if (code == ASM_OPERANDS)
4053 orig_asm_operands_vector = ASM_OPERANDS_INPUT_VEC (orig);
4054 copy_asm_operands_vector = ASM_OPERANDS_INPUT_VEC (copy);
4055 orig_asm_constraints_vector = ASM_OPERANDS_INPUT_CONSTRAINT_VEC (orig);
4056 copy_asm_constraints_vector = ASM_OPERANDS_INPUT_CONSTRAINT_VEC (copy);
4059 return copy;
4062 /* Create a new copy of an rtx.
4063 This function differs from copy_rtx in that it handles SCRATCHes and
4064 ASM_OPERANDs properly.
4065 INSN doesn't really have to be a full INSN; it could be just the
4066 pattern. */
4068 copy_insn (insn)
4069 rtx insn;
4071 copy_insn_n_scratches = 0;
4072 orig_asm_operands_vector = 0;
4073 orig_asm_constraints_vector = 0;
4074 copy_asm_operands_vector = 0;
4075 copy_asm_constraints_vector = 0;
4076 return copy_insn_1 (insn);
4079 /* Initialize data structures and variables in this file
4080 before generating rtl for each function. */
4082 void
4083 init_emit ()
4085 struct function *f = cfun;
4087 f->emit = (struct emit_status *) xmalloc (sizeof (struct emit_status));
4088 first_insn = NULL;
4089 last_insn = NULL;
4090 seq_rtl_expr = NULL;
4091 cur_insn_uid = 1;
4092 reg_rtx_no = LAST_VIRTUAL_REGISTER + 1;
4093 last_linenum = 0;
4094 last_filename = 0;
4095 first_label_num = label_num;
4096 last_label_num = 0;
4097 seq_stack = NULL;
4099 clear_emit_caches ();
4101 /* Init the tables that describe all the pseudo regs. */
4103 f->emit->regno_pointer_align_length = LAST_VIRTUAL_REGISTER + 101;
4105 f->emit->regno_pointer_align
4106 = (unsigned char *) xcalloc (f->emit->regno_pointer_align_length,
4107 sizeof (unsigned char));
4109 regno_reg_rtx
4110 = (rtx *) xcalloc (f->emit->regno_pointer_align_length * sizeof (rtx),
4111 sizeof (rtx));
4113 /* Put copies of all the virtual register rtx into regno_reg_rtx. */
4114 init_virtual_regs (f->emit);
4116 /* Indicate that the virtual registers and stack locations are
4117 all pointers. */
4118 REG_POINTER (stack_pointer_rtx) = 1;
4119 REG_POINTER (frame_pointer_rtx) = 1;
4120 REG_POINTER (hard_frame_pointer_rtx) = 1;
4121 REG_POINTER (arg_pointer_rtx) = 1;
4123 REG_POINTER (virtual_incoming_args_rtx) = 1;
4124 REG_POINTER (virtual_stack_vars_rtx) = 1;
4125 REG_POINTER (virtual_stack_dynamic_rtx) = 1;
4126 REG_POINTER (virtual_outgoing_args_rtx) = 1;
4127 REG_POINTER (virtual_cfa_rtx) = 1;
4129 #ifdef STACK_BOUNDARY
4130 REGNO_POINTER_ALIGN (STACK_POINTER_REGNUM) = STACK_BOUNDARY;
4131 REGNO_POINTER_ALIGN (FRAME_POINTER_REGNUM) = STACK_BOUNDARY;
4132 REGNO_POINTER_ALIGN (HARD_FRAME_POINTER_REGNUM) = STACK_BOUNDARY;
4133 REGNO_POINTER_ALIGN (ARG_POINTER_REGNUM) = STACK_BOUNDARY;
4135 REGNO_POINTER_ALIGN (VIRTUAL_INCOMING_ARGS_REGNUM) = STACK_BOUNDARY;
4136 REGNO_POINTER_ALIGN (VIRTUAL_STACK_VARS_REGNUM) = STACK_BOUNDARY;
4137 REGNO_POINTER_ALIGN (VIRTUAL_STACK_DYNAMIC_REGNUM) = STACK_BOUNDARY;
4138 REGNO_POINTER_ALIGN (VIRTUAL_OUTGOING_ARGS_REGNUM) = STACK_BOUNDARY;
4139 REGNO_POINTER_ALIGN (VIRTUAL_CFA_REGNUM) = BITS_PER_WORD;
4140 #endif
4142 #ifdef INIT_EXPANDERS
4143 INIT_EXPANDERS;
4144 #endif
4147 /* Mark SS for GC. */
4149 static void
4150 mark_sequence_stack (ss)
4151 struct sequence_stack *ss;
4153 while (ss)
4155 ggc_mark_rtx (ss->first);
4156 ggc_mark_tree (ss->sequence_rtl_expr);
4157 ss = ss->next;
4161 /* Mark ES for GC. */
4163 void
4164 mark_emit_status (es)
4165 struct emit_status *es;
4167 rtx *r;
4168 int i;
4170 if (es == 0)
4171 return;
4173 for (i = es->regno_pointer_align_length, r = es->x_regno_reg_rtx;
4174 i > 0; --i, ++r)
4175 ggc_mark_rtx (*r);
4177 mark_sequence_stack (es->sequence_stack);
4178 ggc_mark_tree (es->sequence_rtl_expr);
4179 ggc_mark_rtx (es->x_first_insn);
4182 /* Create some permanent unique rtl objects shared between all functions.
4183 LINE_NUMBERS is nonzero if line numbers are to be generated. */
4185 void
4186 init_emit_once (line_numbers)
4187 int line_numbers;
4189 int i;
4190 enum machine_mode mode;
4191 enum machine_mode double_mode;
4193 /* Initialize the CONST_INT hash table. */
4194 const_int_htab = htab_create (37, const_int_htab_hash,
4195 const_int_htab_eq, NULL);
4196 ggc_add_root (&const_int_htab, 1, sizeof (const_int_htab),
4197 rtx_htab_mark);
4199 no_line_numbers = ! line_numbers;
4201 /* Compute the word and byte modes. */
4203 byte_mode = VOIDmode;
4204 word_mode = VOIDmode;
4205 double_mode = VOIDmode;
4207 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
4208 mode = GET_MODE_WIDER_MODE (mode))
4210 if (GET_MODE_BITSIZE (mode) == BITS_PER_UNIT
4211 && byte_mode == VOIDmode)
4212 byte_mode = mode;
4214 if (GET_MODE_BITSIZE (mode) == BITS_PER_WORD
4215 && word_mode == VOIDmode)
4216 word_mode = mode;
4219 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
4220 mode = GET_MODE_WIDER_MODE (mode))
4222 if (GET_MODE_BITSIZE (mode) == DOUBLE_TYPE_SIZE
4223 && double_mode == VOIDmode)
4224 double_mode = mode;
4227 ptr_mode = mode_for_size (POINTER_SIZE, GET_MODE_CLASS (Pmode), 0);
4229 /* Assign register numbers to the globally defined register rtx.
4230 This must be done at runtime because the register number field
4231 is in a union and some compilers can't initialize unions. */
4233 pc_rtx = gen_rtx (PC, VOIDmode);
4234 cc0_rtx = gen_rtx (CC0, VOIDmode);
4235 stack_pointer_rtx = gen_raw_REG (Pmode, STACK_POINTER_REGNUM);
4236 frame_pointer_rtx = gen_raw_REG (Pmode, FRAME_POINTER_REGNUM);
4237 if (hard_frame_pointer_rtx == 0)
4238 hard_frame_pointer_rtx = gen_raw_REG (Pmode,
4239 HARD_FRAME_POINTER_REGNUM);
4240 if (arg_pointer_rtx == 0)
4241 arg_pointer_rtx = gen_raw_REG (Pmode, ARG_POINTER_REGNUM);
4242 virtual_incoming_args_rtx =
4243 gen_raw_REG (Pmode, VIRTUAL_INCOMING_ARGS_REGNUM);
4244 virtual_stack_vars_rtx =
4245 gen_raw_REG (Pmode, VIRTUAL_STACK_VARS_REGNUM);
4246 virtual_stack_dynamic_rtx =
4247 gen_raw_REG (Pmode, VIRTUAL_STACK_DYNAMIC_REGNUM);
4248 virtual_outgoing_args_rtx =
4249 gen_raw_REG (Pmode, VIRTUAL_OUTGOING_ARGS_REGNUM);
4250 virtual_cfa_rtx = gen_raw_REG (Pmode, VIRTUAL_CFA_REGNUM);
4252 /* These rtx must be roots if GC is enabled. */
4253 ggc_add_rtx_root (global_rtl, GR_MAX);
4255 #ifdef INIT_EXPANDERS
4256 /* This is to initialize {init|mark|free}_machine_status before the first
4257 call to push_function_context_to. This is needed by the Chill front
4258 end which calls push_function_context_to before the first cal to
4259 init_function_start. */
4260 INIT_EXPANDERS;
4261 #endif
4263 /* Create the unique rtx's for certain rtx codes and operand values. */
4265 /* Don't use gen_rtx here since gen_rtx in this case
4266 tries to use these variables. */
4267 for (i = - MAX_SAVED_CONST_INT; i <= MAX_SAVED_CONST_INT; i++)
4268 const_int_rtx[i + MAX_SAVED_CONST_INT] =
4269 gen_rtx_raw_CONST_INT (VOIDmode, i);
4270 ggc_add_rtx_root (const_int_rtx, 2 * MAX_SAVED_CONST_INT + 1);
4272 if (STORE_FLAG_VALUE >= - MAX_SAVED_CONST_INT
4273 && STORE_FLAG_VALUE <= MAX_SAVED_CONST_INT)
4274 const_true_rtx = const_int_rtx[STORE_FLAG_VALUE + MAX_SAVED_CONST_INT];
4275 else
4276 const_true_rtx = gen_rtx_CONST_INT (VOIDmode, STORE_FLAG_VALUE);
4278 dconst0 = REAL_VALUE_ATOF ("0", double_mode);
4279 dconst1 = REAL_VALUE_ATOF ("1", double_mode);
4280 dconst2 = REAL_VALUE_ATOF ("2", double_mode);
4281 dconstm1 = REAL_VALUE_ATOF ("-1", double_mode);
4283 for (i = 0; i <= 2; i++)
4285 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
4286 mode = GET_MODE_WIDER_MODE (mode))
4288 rtx tem = rtx_alloc (CONST_DOUBLE);
4289 union real_extract u;
4291 /* Zero any holes in a structure. */
4292 memset ((char *) &u, 0, sizeof u);
4293 u.d = i == 0 ? dconst0 : i == 1 ? dconst1 : dconst2;
4295 /* Avoid trailing garbage in the rtx. */
4296 if (sizeof (u) < sizeof (HOST_WIDE_INT))
4297 CONST_DOUBLE_LOW (tem) = 0;
4298 if (sizeof (u) < 2 * sizeof (HOST_WIDE_INT))
4299 CONST_DOUBLE_HIGH (tem) = 0;
4301 memcpy (&CONST_DOUBLE_LOW (tem), &u, sizeof u);
4302 CONST_DOUBLE_MEM (tem) = cc0_rtx;
4303 CONST_DOUBLE_CHAIN (tem) = NULL_RTX;
4304 PUT_MODE (tem, mode);
4306 const_tiny_rtx[i][(int) mode] = tem;
4309 const_tiny_rtx[i][(int) VOIDmode] = GEN_INT (i);
4311 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
4312 mode = GET_MODE_WIDER_MODE (mode))
4313 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
4315 for (mode = GET_CLASS_NARROWEST_MODE (MODE_PARTIAL_INT);
4316 mode != VOIDmode;
4317 mode = GET_MODE_WIDER_MODE (mode))
4318 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
4321 for (i = (int) CCmode; i < (int) MAX_MACHINE_MODE; ++i)
4322 if (GET_MODE_CLASS ((enum machine_mode) i) == MODE_CC)
4323 const_tiny_rtx[0][i] = const0_rtx;
4325 const_tiny_rtx[0][(int) BImode] = const0_rtx;
4326 if (STORE_FLAG_VALUE == 1)
4327 const_tiny_rtx[1][(int) BImode] = const1_rtx;
4329 /* For bounded pointers, `&const_tiny_rtx[0][0]' is not the same as
4330 `(rtx *) const_tiny_rtx'. The former has bounds that only cover
4331 `const_tiny_rtx[0]', whereas the latter has bounds that cover all. */
4332 ggc_add_rtx_root ((rtx *) const_tiny_rtx, sizeof const_tiny_rtx / sizeof (rtx));
4333 ggc_add_rtx_root (&const_true_rtx, 1);
4335 #ifdef RETURN_ADDRESS_POINTER_REGNUM
4336 return_address_pointer_rtx
4337 = gen_raw_REG (Pmode, RETURN_ADDRESS_POINTER_REGNUM);
4338 #endif
4340 #ifdef STRUCT_VALUE
4341 struct_value_rtx = STRUCT_VALUE;
4342 #else
4343 struct_value_rtx = gen_rtx_REG (Pmode, STRUCT_VALUE_REGNUM);
4344 #endif
4346 #ifdef STRUCT_VALUE_INCOMING
4347 struct_value_incoming_rtx = STRUCT_VALUE_INCOMING;
4348 #else
4349 #ifdef STRUCT_VALUE_INCOMING_REGNUM
4350 struct_value_incoming_rtx
4351 = gen_rtx_REG (Pmode, STRUCT_VALUE_INCOMING_REGNUM);
4352 #else
4353 struct_value_incoming_rtx = struct_value_rtx;
4354 #endif
4355 #endif
4357 #ifdef STATIC_CHAIN_REGNUM
4358 static_chain_rtx = gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM);
4360 #ifdef STATIC_CHAIN_INCOMING_REGNUM
4361 if (STATIC_CHAIN_INCOMING_REGNUM != STATIC_CHAIN_REGNUM)
4362 static_chain_incoming_rtx
4363 = gen_rtx_REG (Pmode, STATIC_CHAIN_INCOMING_REGNUM);
4364 else
4365 #endif
4366 static_chain_incoming_rtx = static_chain_rtx;
4367 #endif
4369 #ifdef STATIC_CHAIN
4370 static_chain_rtx = STATIC_CHAIN;
4372 #ifdef STATIC_CHAIN_INCOMING
4373 static_chain_incoming_rtx = STATIC_CHAIN_INCOMING;
4374 #else
4375 static_chain_incoming_rtx = static_chain_rtx;
4376 #endif
4377 #endif
4379 if (PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM)
4380 pic_offset_table_rtx = gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM);
4382 ggc_add_rtx_root (&pic_offset_table_rtx, 1);
4383 ggc_add_rtx_root (&struct_value_rtx, 1);
4384 ggc_add_rtx_root (&struct_value_incoming_rtx, 1);
4385 ggc_add_rtx_root (&static_chain_rtx, 1);
4386 ggc_add_rtx_root (&static_chain_incoming_rtx, 1);
4387 ggc_add_rtx_root (&return_address_pointer_rtx, 1);
4390 /* Query and clear/ restore no_line_numbers. This is used by the
4391 switch / case handling in stmt.c to give proper line numbers in
4392 warnings about unreachable code. */
4395 force_line_numbers ()
4397 int old = no_line_numbers;
4399 no_line_numbers = 0;
4400 if (old)
4401 force_next_line_note ();
4402 return old;
4405 void
4406 restore_line_number_status (old_value)
4407 int old_value;
4409 no_line_numbers = old_value;