* config/h8300/h8300.h (ENCODE_SECTION_INFO): Check to see if DECL
[official-gcc.git] / gcc / emit-rtl.c
blob46243cd0c23e9dfe8f32e97000aa4a1f97bc76b8
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 && offset < GET_MODE_ALIGNMENT (GET_MODE (memref)) / BITS_PER_UNIT)
1647 addr = gen_rtx_LO_SUM (mode, XEXP (addr, 0),
1648 plus_constant (XEXP (addr, 1), offset));
1649 else
1650 addr = plus_constant (addr, offset);
1652 return change_address (memref, mode, addr);
1655 /* Likewise, but the reference is not required to be valid. */
1658 adjust_address_nv (memref, mode, offset)
1659 rtx memref;
1660 enum machine_mode mode;
1661 HOST_WIDE_INT offset;
1663 /* For now, this is just a wrapper for change_address, but eventually
1664 will do memref tracking. */
1665 rtx addr = XEXP (memref, 0);
1667 /* If MEMREF is a LO_SUM and the offset is within the size of the
1668 object, we can merge it into the LO_SUM. */
1669 if (GET_MODE (memref) != BLKmode && GET_CODE (addr) == LO_SUM
1670 && offset >= 0
1671 && offset < GET_MODE_ALIGNMENT (GET_MODE (memref)) / BITS_PER_UNIT)
1672 addr = gen_rtx_LO_SUM (mode, XEXP (addr, 0),
1673 plus_constant (XEXP (addr, 1), offset));
1674 else
1675 addr = plus_constant (addr, offset);
1677 return change_address_1 (memref, mode, addr, 0);
1680 /* Return a memory reference like MEMREF, but with its address changed to
1681 ADDR. The caller is asserting that the actual piece of memory pointed
1682 to is the same, just the form of the address is being changed, such as
1683 by putting something into a register. */
1686 replace_equiv_address (memref, addr)
1687 rtx memref;
1688 rtx addr;
1690 /* For now, this is just a wrapper for change_address, but eventually
1691 will do memref tracking. */
1692 return change_address (memref, VOIDmode, addr);
1694 /* Likewise, but the reference is not required to be valid. */
1697 replace_equiv_address_nv (memref, addr)
1698 rtx memref;
1699 rtx addr;
1701 /* For now, this is just a wrapper for change_address, but eventually
1702 will do memref tracking. */
1703 return change_address_1 (memref, VOIDmode, addr, 0);
1706 /* Return a newly created CODE_LABEL rtx with a unique label number. */
1709 gen_label_rtx ()
1711 register rtx label;
1713 label = gen_rtx_CODE_LABEL (VOIDmode, 0, NULL_RTX,
1714 NULL_RTX, label_num++, NULL, NULL);
1716 LABEL_NUSES (label) = 0;
1717 LABEL_ALTERNATE_NAME (label) = NULL;
1718 return label;
1721 /* For procedure integration. */
1723 /* Install new pointers to the first and last insns in the chain.
1724 Also, set cur_insn_uid to one higher than the last in use.
1725 Used for an inline-procedure after copying the insn chain. */
1727 void
1728 set_new_first_and_last_insn (first, last)
1729 rtx first, last;
1731 rtx insn;
1733 first_insn = first;
1734 last_insn = last;
1735 cur_insn_uid = 0;
1737 for (insn = first; insn; insn = NEXT_INSN (insn))
1738 cur_insn_uid = MAX (cur_insn_uid, INSN_UID (insn));
1740 cur_insn_uid++;
1743 /* Set the range of label numbers found in the current function.
1744 This is used when belatedly compiling an inline function. */
1746 void
1747 set_new_first_and_last_label_num (first, last)
1748 int first, last;
1750 base_label_num = label_num;
1751 first_label_num = first;
1752 last_label_num = last;
1755 /* Set the last label number found in the current function.
1756 This is used when belatedly compiling an inline function. */
1758 void
1759 set_new_last_label_num (last)
1760 int last;
1762 base_label_num = label_num;
1763 last_label_num = last;
1766 /* Restore all variables describing the current status from the structure *P.
1767 This is used after a nested function. */
1769 void
1770 restore_emit_status (p)
1771 struct function *p ATTRIBUTE_UNUSED;
1773 last_label_num = 0;
1774 clear_emit_caches ();
1777 /* Clear out all parts of the state in F that can safely be discarded
1778 after the function has been compiled, to let garbage collection
1779 reclaim the memory. */
1781 void
1782 free_emit_status (f)
1783 struct function *f;
1785 free (f->emit->x_regno_reg_rtx);
1786 free (f->emit->regno_pointer_align);
1787 free (f->emit);
1788 f->emit = NULL;
1791 /* Go through all the RTL insn bodies and copy any invalid shared
1792 structure. This routine should only be called once. */
1794 void
1795 unshare_all_rtl (fndecl, insn)
1796 tree fndecl;
1797 rtx insn;
1799 tree decl;
1801 /* Make sure that virtual parameters are not shared. */
1802 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
1803 SET_DECL_RTL (decl, copy_rtx_if_shared (DECL_RTL (decl)));
1805 /* Make sure that virtual stack slots are not shared. */
1806 unshare_all_decls (DECL_INITIAL (fndecl));
1808 /* Unshare just about everything else. */
1809 unshare_all_rtl_1 (insn);
1811 /* Make sure the addresses of stack slots found outside the insn chain
1812 (such as, in DECL_RTL of a variable) are not shared
1813 with the insn chain.
1815 This special care is necessary when the stack slot MEM does not
1816 actually appear in the insn chain. If it does appear, its address
1817 is unshared from all else at that point. */
1818 stack_slot_list = copy_rtx_if_shared (stack_slot_list);
1821 /* Go through all the RTL insn bodies and copy any invalid shared
1822 structure, again. This is a fairly expensive thing to do so it
1823 should be done sparingly. */
1825 void
1826 unshare_all_rtl_again (insn)
1827 rtx insn;
1829 rtx p;
1830 tree decl;
1832 for (p = insn; p; p = NEXT_INSN (p))
1833 if (INSN_P (p))
1835 reset_used_flags (PATTERN (p));
1836 reset_used_flags (REG_NOTES (p));
1837 reset_used_flags (LOG_LINKS (p));
1840 /* Make sure that virtual stack slots are not shared. */
1841 reset_used_decls (DECL_INITIAL (cfun->decl));
1843 /* Make sure that virtual parameters are not shared. */
1844 for (decl = DECL_ARGUMENTS (cfun->decl); decl; decl = TREE_CHAIN (decl))
1845 reset_used_flags (DECL_RTL (decl));
1847 reset_used_flags (stack_slot_list);
1849 unshare_all_rtl (cfun->decl, insn);
1852 /* Go through all the RTL insn bodies and copy any invalid shared structure.
1853 Assumes the mark bits are cleared at entry. */
1855 static void
1856 unshare_all_rtl_1 (insn)
1857 rtx insn;
1859 for (; insn; insn = NEXT_INSN (insn))
1860 if (INSN_P (insn))
1862 PATTERN (insn) = copy_rtx_if_shared (PATTERN (insn));
1863 REG_NOTES (insn) = copy_rtx_if_shared (REG_NOTES (insn));
1864 LOG_LINKS (insn) = copy_rtx_if_shared (LOG_LINKS (insn));
1868 /* Go through all virtual stack slots of a function and copy any
1869 shared structure. */
1870 static void
1871 unshare_all_decls (blk)
1872 tree blk;
1874 tree t;
1876 /* Copy shared decls. */
1877 for (t = BLOCK_VARS (blk); t; t = TREE_CHAIN (t))
1878 if (DECL_RTL_SET_P (t))
1879 SET_DECL_RTL (t, copy_rtx_if_shared (DECL_RTL (t)));
1881 /* Now process sub-blocks. */
1882 for (t = BLOCK_SUBBLOCKS (blk); t; t = TREE_CHAIN (t))
1883 unshare_all_decls (t);
1886 /* Go through all virtual stack slots of a function and mark them as
1887 not shared. */
1888 static void
1889 reset_used_decls (blk)
1890 tree blk;
1892 tree t;
1894 /* Mark decls. */
1895 for (t = BLOCK_VARS (blk); t; t = TREE_CHAIN (t))
1896 if (DECL_RTL_SET_P (t))
1897 reset_used_flags (DECL_RTL (t));
1899 /* Now process sub-blocks. */
1900 for (t = BLOCK_SUBBLOCKS (blk); t; t = TREE_CHAIN (t))
1901 reset_used_decls (t);
1904 /* Mark ORIG as in use, and return a copy of it if it was already in use.
1905 Recursively does the same for subexpressions. */
1908 copy_rtx_if_shared (orig)
1909 rtx orig;
1911 register rtx x = orig;
1912 register int i;
1913 register enum rtx_code code;
1914 register const char *format_ptr;
1915 int copied = 0;
1917 if (x == 0)
1918 return 0;
1920 code = GET_CODE (x);
1922 /* These types may be freely shared. */
1924 switch (code)
1926 case REG:
1927 case QUEUED:
1928 case CONST_INT:
1929 case CONST_DOUBLE:
1930 case SYMBOL_REF:
1931 case CODE_LABEL:
1932 case PC:
1933 case CC0:
1934 case SCRATCH:
1935 /* SCRATCH must be shared because they represent distinct values. */
1936 return x;
1938 case CONST:
1939 /* CONST can be shared if it contains a SYMBOL_REF. If it contains
1940 a LABEL_REF, it isn't sharable. */
1941 if (GET_CODE (XEXP (x, 0)) == PLUS
1942 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
1943 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
1944 return x;
1945 break;
1947 case INSN:
1948 case JUMP_INSN:
1949 case CALL_INSN:
1950 case NOTE:
1951 case BARRIER:
1952 /* The chain of insns is not being copied. */
1953 return x;
1955 case MEM:
1956 /* A MEM is allowed to be shared if its address is constant.
1958 We used to allow sharing of MEMs which referenced
1959 virtual_stack_vars_rtx or virtual_incoming_args_rtx, but
1960 that can lose. instantiate_virtual_regs will not unshare
1961 the MEMs, and combine may change the structure of the address
1962 because it looks safe and profitable in one context, but
1963 in some other context it creates unrecognizable RTL. */
1964 if (CONSTANT_ADDRESS_P (XEXP (x, 0)))
1965 return x;
1967 break;
1969 default:
1970 break;
1973 /* This rtx may not be shared. If it has already been seen,
1974 replace it with a copy of itself. */
1976 if (x->used)
1978 register rtx copy;
1980 copy = rtx_alloc (code);
1981 memcpy (copy, x,
1982 (sizeof (*copy) - sizeof (copy->fld)
1983 + sizeof (copy->fld[0]) * GET_RTX_LENGTH (code)));
1984 x = copy;
1985 copied = 1;
1987 x->used = 1;
1989 /* Now scan the subexpressions recursively.
1990 We can store any replaced subexpressions directly into X
1991 since we know X is not shared! Any vectors in X
1992 must be copied if X was copied. */
1994 format_ptr = GET_RTX_FORMAT (code);
1996 for (i = 0; i < GET_RTX_LENGTH (code); i++)
1998 switch (*format_ptr++)
2000 case 'e':
2001 XEXP (x, i) = copy_rtx_if_shared (XEXP (x, i));
2002 break;
2004 case 'E':
2005 if (XVEC (x, i) != NULL)
2007 register int j;
2008 int len = XVECLEN (x, i);
2010 if (copied && len > 0)
2011 XVEC (x, i) = gen_rtvec_v (len, XVEC (x, i)->elem);
2012 for (j = 0; j < len; j++)
2013 XVECEXP (x, i, j) = copy_rtx_if_shared (XVECEXP (x, i, j));
2015 break;
2018 return x;
2021 /* Clear all the USED bits in X to allow copy_rtx_if_shared to be used
2022 to look for shared sub-parts. */
2024 void
2025 reset_used_flags (x)
2026 rtx x;
2028 register int i, j;
2029 register enum rtx_code code;
2030 register const char *format_ptr;
2032 if (x == 0)
2033 return;
2035 code = GET_CODE (x);
2037 /* These types may be freely shared so we needn't do any resetting
2038 for them. */
2040 switch (code)
2042 case REG:
2043 case QUEUED:
2044 case CONST_INT:
2045 case CONST_DOUBLE:
2046 case SYMBOL_REF:
2047 case CODE_LABEL:
2048 case PC:
2049 case CC0:
2050 return;
2052 case INSN:
2053 case JUMP_INSN:
2054 case CALL_INSN:
2055 case NOTE:
2056 case LABEL_REF:
2057 case BARRIER:
2058 /* The chain of insns is not being copied. */
2059 return;
2061 default:
2062 break;
2065 x->used = 0;
2067 format_ptr = GET_RTX_FORMAT (code);
2068 for (i = 0; i < GET_RTX_LENGTH (code); i++)
2070 switch (*format_ptr++)
2072 case 'e':
2073 reset_used_flags (XEXP (x, i));
2074 break;
2076 case 'E':
2077 for (j = 0; j < XVECLEN (x, i); j++)
2078 reset_used_flags (XVECEXP (x, i, j));
2079 break;
2084 /* Copy X if necessary so that it won't be altered by changes in OTHER.
2085 Return X or the rtx for the pseudo reg the value of X was copied into.
2086 OTHER must be valid as a SET_DEST. */
2089 make_safe_from (x, other)
2090 rtx x, other;
2092 while (1)
2093 switch (GET_CODE (other))
2095 case SUBREG:
2096 other = SUBREG_REG (other);
2097 break;
2098 case STRICT_LOW_PART:
2099 case SIGN_EXTEND:
2100 case ZERO_EXTEND:
2101 other = XEXP (other, 0);
2102 break;
2103 default:
2104 goto done;
2106 done:
2107 if ((GET_CODE (other) == MEM
2108 && ! CONSTANT_P (x)
2109 && GET_CODE (x) != REG
2110 && GET_CODE (x) != SUBREG)
2111 || (GET_CODE (other) == REG
2112 && (REGNO (other) < FIRST_PSEUDO_REGISTER
2113 || reg_mentioned_p (other, x))))
2115 rtx temp = gen_reg_rtx (GET_MODE (x));
2116 emit_move_insn (temp, x);
2117 return temp;
2119 return x;
2122 /* Emission of insns (adding them to the doubly-linked list). */
2124 /* Return the first insn of the current sequence or current function. */
2127 get_insns ()
2129 return first_insn;
2132 /* Return the last insn emitted in current sequence or current function. */
2135 get_last_insn ()
2137 return last_insn;
2140 /* Specify a new insn as the last in the chain. */
2142 void
2143 set_last_insn (insn)
2144 rtx insn;
2146 if (NEXT_INSN (insn) != 0)
2147 abort ();
2148 last_insn = insn;
2151 /* Return the last insn emitted, even if it is in a sequence now pushed. */
2154 get_last_insn_anywhere ()
2156 struct sequence_stack *stack;
2157 if (last_insn)
2158 return last_insn;
2159 for (stack = seq_stack; stack; stack = stack->next)
2160 if (stack->last != 0)
2161 return stack->last;
2162 return 0;
2165 /* Return a number larger than any instruction's uid in this function. */
2168 get_max_uid ()
2170 return cur_insn_uid;
2173 /* Renumber instructions so that no instruction UIDs are wasted. */
2175 void
2176 renumber_insns (stream)
2177 FILE *stream;
2179 rtx insn;
2181 /* If we're not supposed to renumber instructions, don't. */
2182 if (!flag_renumber_insns)
2183 return;
2185 /* If there aren't that many instructions, then it's not really
2186 worth renumbering them. */
2187 if (flag_renumber_insns == 1 && get_max_uid () < 25000)
2188 return;
2190 cur_insn_uid = 1;
2192 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2194 if (stream)
2195 fprintf (stream, "Renumbering insn %d to %d\n",
2196 INSN_UID (insn), cur_insn_uid);
2197 INSN_UID (insn) = cur_insn_uid++;
2201 /* Return the next insn. If it is a SEQUENCE, return the first insn
2202 of the sequence. */
2205 next_insn (insn)
2206 rtx insn;
2208 if (insn)
2210 insn = NEXT_INSN (insn);
2211 if (insn && GET_CODE (insn) == INSN
2212 && GET_CODE (PATTERN (insn)) == SEQUENCE)
2213 insn = XVECEXP (PATTERN (insn), 0, 0);
2216 return insn;
2219 /* Return the previous insn. If it is a SEQUENCE, return the last insn
2220 of the sequence. */
2223 previous_insn (insn)
2224 rtx insn;
2226 if (insn)
2228 insn = PREV_INSN (insn);
2229 if (insn && GET_CODE (insn) == INSN
2230 && GET_CODE (PATTERN (insn)) == SEQUENCE)
2231 insn = XVECEXP (PATTERN (insn), 0, XVECLEN (PATTERN (insn), 0) - 1);
2234 return insn;
2237 /* Return the next insn after INSN that is not a NOTE. This routine does not
2238 look inside SEQUENCEs. */
2241 next_nonnote_insn (insn)
2242 rtx insn;
2244 while (insn)
2246 insn = NEXT_INSN (insn);
2247 if (insn == 0 || GET_CODE (insn) != NOTE)
2248 break;
2251 return insn;
2254 /* Return the previous insn before INSN that is not a NOTE. This routine does
2255 not look inside SEQUENCEs. */
2258 prev_nonnote_insn (insn)
2259 rtx insn;
2261 while (insn)
2263 insn = PREV_INSN (insn);
2264 if (insn == 0 || GET_CODE (insn) != NOTE)
2265 break;
2268 return insn;
2271 /* Return the next INSN, CALL_INSN or JUMP_INSN after INSN;
2272 or 0, if there is none. This routine does not look inside
2273 SEQUENCEs. */
2276 next_real_insn (insn)
2277 rtx insn;
2279 while (insn)
2281 insn = NEXT_INSN (insn);
2282 if (insn == 0 || GET_CODE (insn) == INSN
2283 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN)
2284 break;
2287 return insn;
2290 /* Return the last INSN, CALL_INSN or JUMP_INSN before INSN;
2291 or 0, if there is none. This routine does not look inside
2292 SEQUENCEs. */
2295 prev_real_insn (insn)
2296 rtx insn;
2298 while (insn)
2300 insn = PREV_INSN (insn);
2301 if (insn == 0 || GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
2302 || GET_CODE (insn) == JUMP_INSN)
2303 break;
2306 return insn;
2309 /* Find the next insn after INSN that really does something. This routine
2310 does not look inside SEQUENCEs. Until reload has completed, this is the
2311 same as next_real_insn. */
2314 active_insn_p (insn)
2315 rtx insn;
2317 return (GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN
2318 || (GET_CODE (insn) == INSN
2319 && (! reload_completed
2320 || (GET_CODE (PATTERN (insn)) != USE
2321 && GET_CODE (PATTERN (insn)) != CLOBBER))));
2325 next_active_insn (insn)
2326 rtx insn;
2328 while (insn)
2330 insn = NEXT_INSN (insn);
2331 if (insn == 0 || active_insn_p (insn))
2332 break;
2335 return insn;
2338 /* Find the last insn before INSN that really does something. This routine
2339 does not look inside SEQUENCEs. Until reload has completed, this is the
2340 same as prev_real_insn. */
2343 prev_active_insn (insn)
2344 rtx insn;
2346 while (insn)
2348 insn = PREV_INSN (insn);
2349 if (insn == 0 || active_insn_p (insn))
2350 break;
2353 return insn;
2356 /* Return the next CODE_LABEL after the insn INSN, or 0 if there is none. */
2359 next_label (insn)
2360 rtx insn;
2362 while (insn)
2364 insn = NEXT_INSN (insn);
2365 if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
2366 break;
2369 return insn;
2372 /* Return the last CODE_LABEL before the insn INSN, or 0 if there is none. */
2375 prev_label (insn)
2376 rtx insn;
2378 while (insn)
2380 insn = PREV_INSN (insn);
2381 if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
2382 break;
2385 return insn;
2388 #ifdef HAVE_cc0
2389 /* INSN uses CC0 and is being moved into a delay slot. Set up REG_CC_SETTER
2390 and REG_CC_USER notes so we can find it. */
2392 void
2393 link_cc0_insns (insn)
2394 rtx insn;
2396 rtx user = next_nonnote_insn (insn);
2398 if (GET_CODE (user) == INSN && GET_CODE (PATTERN (user)) == SEQUENCE)
2399 user = XVECEXP (PATTERN (user), 0, 0);
2401 REG_NOTES (user) = gen_rtx_INSN_LIST (REG_CC_SETTER, insn,
2402 REG_NOTES (user));
2403 REG_NOTES (insn) = gen_rtx_INSN_LIST (REG_CC_USER, user, REG_NOTES (insn));
2406 /* Return the next insn that uses CC0 after INSN, which is assumed to
2407 set it. This is the inverse of prev_cc0_setter (i.e., prev_cc0_setter
2408 applied to the result of this function should yield INSN).
2410 Normally, this is simply the next insn. However, if a REG_CC_USER note
2411 is present, it contains the insn that uses CC0.
2413 Return 0 if we can't find the insn. */
2416 next_cc0_user (insn)
2417 rtx insn;
2419 rtx note = find_reg_note (insn, REG_CC_USER, NULL_RTX);
2421 if (note)
2422 return XEXP (note, 0);
2424 insn = next_nonnote_insn (insn);
2425 if (insn && GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
2426 insn = XVECEXP (PATTERN (insn), 0, 0);
2428 if (insn && INSN_P (insn) && reg_mentioned_p (cc0_rtx, PATTERN (insn)))
2429 return insn;
2431 return 0;
2434 /* Find the insn that set CC0 for INSN. Unless INSN has a REG_CC_SETTER
2435 note, it is the previous insn. */
2438 prev_cc0_setter (insn)
2439 rtx insn;
2441 rtx note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
2443 if (note)
2444 return XEXP (note, 0);
2446 insn = prev_nonnote_insn (insn);
2447 if (! sets_cc0_p (PATTERN (insn)))
2448 abort ();
2450 return insn;
2452 #endif
2454 /* Increment the label uses for all labels present in rtx. */
2456 static void
2457 mark_label_nuses(x)
2458 rtx x;
2460 register enum rtx_code code;
2461 register int i, j;
2462 register const char *fmt;
2464 code = GET_CODE (x);
2465 if (code == LABEL_REF)
2466 LABEL_NUSES (XEXP (x, 0))++;
2468 fmt = GET_RTX_FORMAT (code);
2469 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2471 if (fmt[i] == 'e')
2472 mark_label_nuses (XEXP (x, i));
2473 else if (fmt[i] == 'E')
2474 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2475 mark_label_nuses (XVECEXP (x, i, j));
2480 /* Try splitting insns that can be split for better scheduling.
2481 PAT is the pattern which might split.
2482 TRIAL is the insn providing PAT.
2483 LAST is non-zero if we should return the last insn of the sequence produced.
2485 If this routine succeeds in splitting, it returns the first or last
2486 replacement insn depending on the value of LAST. Otherwise, it
2487 returns TRIAL. If the insn to be returned can be split, it will be. */
2490 try_split (pat, trial, last)
2491 rtx pat, trial;
2492 int last;
2494 rtx before = PREV_INSN (trial);
2495 rtx after = NEXT_INSN (trial);
2496 int has_barrier = 0;
2497 rtx tem;
2498 rtx note, seq;
2499 int probability;
2501 if (any_condjump_p (trial)
2502 && (note = find_reg_note (trial, REG_BR_PROB, 0)))
2503 split_branch_probability = INTVAL (XEXP (note, 0));
2504 probability = split_branch_probability;
2506 seq = split_insns (pat, trial);
2508 split_branch_probability = -1;
2510 /* If we are splitting a JUMP_INSN, it might be followed by a BARRIER.
2511 We may need to handle this specially. */
2512 if (after && GET_CODE (after) == BARRIER)
2514 has_barrier = 1;
2515 after = NEXT_INSN (after);
2518 if (seq)
2520 /* SEQ can either be a SEQUENCE or the pattern of a single insn.
2521 The latter case will normally arise only when being done so that
2522 it, in turn, will be split (SFmode on the 29k is an example). */
2523 if (GET_CODE (seq) == SEQUENCE)
2525 int i, njumps = 0;
2526 rtx eh_note;
2528 /* Avoid infinite loop if any insn of the result matches
2529 the original pattern. */
2530 for (i = 0; i < XVECLEN (seq, 0); i++)
2531 if (GET_CODE (XVECEXP (seq, 0, i)) == INSN
2532 && rtx_equal_p (PATTERN (XVECEXP (seq, 0, i)), pat))
2533 return trial;
2535 /* Mark labels. */
2536 for (i = XVECLEN (seq, 0) - 1; i >= 0; i--)
2537 if (GET_CODE (XVECEXP (seq, 0, i)) == JUMP_INSN)
2539 rtx insn = XVECEXP (seq, 0, i);
2540 mark_jump_label (PATTERN (insn),
2541 XVECEXP (seq, 0, i), 0);
2542 njumps++;
2543 if (probability != -1
2544 && any_condjump_p (insn)
2545 && !find_reg_note (insn, REG_BR_PROB, 0))
2547 /* We can preserve the REG_BR_PROB notes only if exactly
2548 one jump is created, otherwise the machinde description
2549 is responsible for this step using
2550 split_branch_probability variable. */
2551 if (njumps != 1)
2552 abort ();
2553 REG_NOTES (insn)
2554 = gen_rtx_EXPR_LIST (REG_BR_PROB,
2555 GEN_INT (probability),
2556 REG_NOTES (insn));
2559 /* If we are splitting a CALL_INSN, look for the CALL_INSN
2560 in SEQ and copy our CALL_INSN_FUNCTION_USAGE to it. */
2561 if (GET_CODE (trial) == CALL_INSN)
2562 for (i = XVECLEN (seq, 0) - 1; i >= 0; i--)
2563 if (GET_CODE (XVECEXP (seq, 0, i)) == CALL_INSN)
2564 CALL_INSN_FUNCTION_USAGE (XVECEXP (seq, 0, i))
2565 = CALL_INSN_FUNCTION_USAGE (trial);
2567 /* Copy EH notes. */
2568 if ((eh_note = find_reg_note (trial, REG_EH_REGION, NULL_RTX)))
2569 for (i = 0; i < XVECLEN (seq, 0); i++)
2571 rtx insn = XVECEXP (seq, 0, i);
2572 if (GET_CODE (insn) == CALL_INSN
2573 || (flag_non_call_exceptions
2574 && may_trap_p (PATTERN (insn))))
2575 REG_NOTES (insn)
2576 = gen_rtx_EXPR_LIST (REG_EH_REGION, XEXP (eh_note, 0),
2577 REG_NOTES (insn));
2580 /* If there are LABELS inside the split insns increment the
2581 usage count so we don't delete the label. */
2582 if (GET_CODE (trial) == INSN)
2583 for (i = XVECLEN (seq, 0) - 1; i >= 0; i--)
2584 if (GET_CODE (XVECEXP (seq, 0, i)) == INSN)
2585 mark_label_nuses (PATTERN (XVECEXP (seq, 0, i)));
2587 tem = emit_insn_after (seq, before);
2589 delete_insn (trial);
2590 if (has_barrier)
2591 emit_barrier_after (tem);
2593 /* Recursively call try_split for each new insn created; by the
2594 time control returns here that insn will be fully split, so
2595 set LAST and continue from the insn after the one returned.
2596 We can't use next_active_insn here since AFTER may be a note.
2597 Ignore deleted insns, which can be occur if not optimizing. */
2598 for (tem = NEXT_INSN (before); tem != after; tem = NEXT_INSN (tem))
2599 if (! INSN_DELETED_P (tem) && INSN_P (tem))
2600 tem = try_split (PATTERN (tem), tem, 1);
2602 /* Avoid infinite loop if the result matches the original pattern. */
2603 else if (rtx_equal_p (seq, pat))
2604 return trial;
2605 else
2607 PATTERN (trial) = seq;
2608 INSN_CODE (trial) = -1;
2609 try_split (seq, trial, last);
2612 /* Return either the first or the last insn, depending on which was
2613 requested. */
2614 return last
2615 ? (after ? PREV_INSN (after) : last_insn)
2616 : NEXT_INSN (before);
2619 return trial;
2622 /* Make and return an INSN rtx, initializing all its slots.
2623 Store PATTERN in the pattern slots. */
2626 make_insn_raw (pattern)
2627 rtx pattern;
2629 register rtx insn;
2631 insn = rtx_alloc (INSN);
2633 INSN_UID (insn) = cur_insn_uid++;
2634 PATTERN (insn) = pattern;
2635 INSN_CODE (insn) = -1;
2636 LOG_LINKS (insn) = NULL;
2637 REG_NOTES (insn) = NULL;
2639 #ifdef ENABLE_RTL_CHECKING
2640 if (insn
2641 && INSN_P (insn)
2642 && (returnjump_p (insn)
2643 || (GET_CODE (insn) == SET
2644 && SET_DEST (insn) == pc_rtx)))
2646 warning ("ICE: emit_insn used where emit_jump_insn needed:\n");
2647 debug_rtx (insn);
2649 #endif
2651 return insn;
2654 /* Like `make_insn' but make a JUMP_INSN instead of an insn. */
2656 static rtx
2657 make_jump_insn_raw (pattern)
2658 rtx pattern;
2660 register rtx insn;
2662 insn = rtx_alloc (JUMP_INSN);
2663 INSN_UID (insn) = cur_insn_uid++;
2665 PATTERN (insn) = pattern;
2666 INSN_CODE (insn) = -1;
2667 LOG_LINKS (insn) = NULL;
2668 REG_NOTES (insn) = NULL;
2669 JUMP_LABEL (insn) = NULL;
2671 return insn;
2674 /* Like `make_insn' but make a CALL_INSN instead of an insn. */
2676 static rtx
2677 make_call_insn_raw (pattern)
2678 rtx pattern;
2680 register rtx insn;
2682 insn = rtx_alloc (CALL_INSN);
2683 INSN_UID (insn) = cur_insn_uid++;
2685 PATTERN (insn) = pattern;
2686 INSN_CODE (insn) = -1;
2687 LOG_LINKS (insn) = NULL;
2688 REG_NOTES (insn) = NULL;
2689 CALL_INSN_FUNCTION_USAGE (insn) = NULL;
2691 return insn;
2694 /* Add INSN to the end of the doubly-linked list.
2695 INSN may be an INSN, JUMP_INSN, CALL_INSN, CODE_LABEL, BARRIER or NOTE. */
2697 void
2698 add_insn (insn)
2699 register rtx insn;
2701 PREV_INSN (insn) = last_insn;
2702 NEXT_INSN (insn) = 0;
2704 if (NULL != last_insn)
2705 NEXT_INSN (last_insn) = insn;
2707 if (NULL == first_insn)
2708 first_insn = insn;
2710 last_insn = insn;
2713 /* Add INSN into the doubly-linked list after insn AFTER. This and
2714 the next should be the only functions called to insert an insn once
2715 delay slots have been filled since only they know how to update a
2716 SEQUENCE. */
2718 void
2719 add_insn_after (insn, after)
2720 rtx insn, after;
2722 rtx next = NEXT_INSN (after);
2724 if (optimize && INSN_DELETED_P (after))
2725 abort ();
2727 NEXT_INSN (insn) = next;
2728 PREV_INSN (insn) = after;
2730 if (next)
2732 PREV_INSN (next) = insn;
2733 if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == SEQUENCE)
2734 PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = insn;
2736 else if (last_insn == after)
2737 last_insn = insn;
2738 else
2740 struct sequence_stack *stack = seq_stack;
2741 /* Scan all pending sequences too. */
2742 for (; stack; stack = stack->next)
2743 if (after == stack->last)
2745 stack->last = insn;
2746 break;
2749 if (stack == 0)
2750 abort ();
2753 NEXT_INSN (after) = insn;
2754 if (GET_CODE (after) == INSN && GET_CODE (PATTERN (after)) == SEQUENCE)
2756 rtx sequence = PATTERN (after);
2757 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2761 /* Add INSN into the doubly-linked list before insn BEFORE. This and
2762 the previous should be the only functions called to insert an insn once
2763 delay slots have been filled since only they know how to update a
2764 SEQUENCE. */
2766 void
2767 add_insn_before (insn, before)
2768 rtx insn, before;
2770 rtx prev = PREV_INSN (before);
2772 if (optimize && INSN_DELETED_P (before))
2773 abort ();
2775 PREV_INSN (insn) = prev;
2776 NEXT_INSN (insn) = before;
2778 if (prev)
2780 NEXT_INSN (prev) = insn;
2781 if (GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == SEQUENCE)
2783 rtx sequence = PATTERN (prev);
2784 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2787 else if (first_insn == before)
2788 first_insn = insn;
2789 else
2791 struct sequence_stack *stack = seq_stack;
2792 /* Scan all pending sequences too. */
2793 for (; stack; stack = stack->next)
2794 if (before == stack->first)
2796 stack->first = insn;
2797 break;
2800 if (stack == 0)
2801 abort ();
2804 PREV_INSN (before) = insn;
2805 if (GET_CODE (before) == INSN && GET_CODE (PATTERN (before)) == SEQUENCE)
2806 PREV_INSN (XVECEXP (PATTERN (before), 0, 0)) = insn;
2809 /* Remove an insn from its doubly-linked list. This function knows how
2810 to handle sequences. */
2811 void
2812 remove_insn (insn)
2813 rtx insn;
2815 rtx next = NEXT_INSN (insn);
2816 rtx prev = PREV_INSN (insn);
2817 if (prev)
2819 NEXT_INSN (prev) = next;
2820 if (GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == SEQUENCE)
2822 rtx sequence = PATTERN (prev);
2823 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = next;
2826 else if (first_insn == insn)
2827 first_insn = next;
2828 else
2830 struct sequence_stack *stack = seq_stack;
2831 /* Scan all pending sequences too. */
2832 for (; stack; stack = stack->next)
2833 if (insn == stack->first)
2835 stack->first = next;
2836 break;
2839 if (stack == 0)
2840 abort ();
2843 if (next)
2845 PREV_INSN (next) = prev;
2846 if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == SEQUENCE)
2847 PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = prev;
2849 else if (last_insn == insn)
2850 last_insn = prev;
2851 else
2853 struct sequence_stack *stack = seq_stack;
2854 /* Scan all pending sequences too. */
2855 for (; stack; stack = stack->next)
2856 if (insn == stack->last)
2858 stack->last = prev;
2859 break;
2862 if (stack == 0)
2863 abort ();
2867 /* Delete all insns made since FROM.
2868 FROM becomes the new last instruction. */
2870 void
2871 delete_insns_since (from)
2872 rtx from;
2874 if (from == 0)
2875 first_insn = 0;
2876 else
2877 NEXT_INSN (from) = 0;
2878 last_insn = from;
2881 /* This function is deprecated, please use sequences instead.
2883 Move a consecutive bunch of insns to a different place in the chain.
2884 The insns to be moved are those between FROM and TO.
2885 They are moved to a new position after the insn AFTER.
2886 AFTER must not be FROM or TO or any insn in between.
2888 This function does not know about SEQUENCEs and hence should not be
2889 called after delay-slot filling has been done. */
2891 void
2892 reorder_insns (from, to, after)
2893 rtx from, to, after;
2895 /* Splice this bunch out of where it is now. */
2896 if (PREV_INSN (from))
2897 NEXT_INSN (PREV_INSN (from)) = NEXT_INSN (to);
2898 if (NEXT_INSN (to))
2899 PREV_INSN (NEXT_INSN (to)) = PREV_INSN (from);
2900 if (last_insn == to)
2901 last_insn = PREV_INSN (from);
2902 if (first_insn == from)
2903 first_insn = NEXT_INSN (to);
2905 /* Make the new neighbors point to it and it to them. */
2906 if (NEXT_INSN (after))
2907 PREV_INSN (NEXT_INSN (after)) = to;
2909 NEXT_INSN (to) = NEXT_INSN (after);
2910 PREV_INSN (from) = after;
2911 NEXT_INSN (after) = from;
2912 if (after == last_insn)
2913 last_insn = to;
2916 /* Return the line note insn preceding INSN. */
2918 static rtx
2919 find_line_note (insn)
2920 rtx insn;
2922 if (no_line_numbers)
2923 return 0;
2925 for (; insn; insn = PREV_INSN (insn))
2926 if (GET_CODE (insn) == NOTE
2927 && NOTE_LINE_NUMBER (insn) >= 0)
2928 break;
2930 return insn;
2933 /* Like reorder_insns, but inserts line notes to preserve the line numbers
2934 of the moved insns when debugging. This may insert a note between AFTER
2935 and FROM, and another one after TO. */
2937 void
2938 reorder_insns_with_line_notes (from, to, after)
2939 rtx from, to, after;
2941 rtx from_line = find_line_note (from);
2942 rtx after_line = find_line_note (after);
2944 reorder_insns (from, to, after);
2946 if (from_line == after_line)
2947 return;
2949 if (from_line)
2950 emit_line_note_after (NOTE_SOURCE_FILE (from_line),
2951 NOTE_LINE_NUMBER (from_line),
2952 after);
2953 if (after_line)
2954 emit_line_note_after (NOTE_SOURCE_FILE (after_line),
2955 NOTE_LINE_NUMBER (after_line),
2956 to);
2959 /* Remove unnecessary notes from the instruction stream. */
2961 void
2962 remove_unnecessary_notes ()
2964 rtx block_stack = NULL_RTX;
2965 rtx eh_stack = NULL_RTX;
2966 rtx insn;
2967 rtx next;
2968 rtx tmp;
2970 /* We must not remove the first instruction in the function because
2971 the compiler depends on the first instruction being a note. */
2972 for (insn = NEXT_INSN (get_insns ()); insn; insn = next)
2974 /* Remember what's next. */
2975 next = NEXT_INSN (insn);
2977 /* We're only interested in notes. */
2978 if (GET_CODE (insn) != NOTE)
2979 continue;
2981 switch (NOTE_LINE_NUMBER (insn))
2983 case NOTE_INSN_DELETED:
2984 remove_insn (insn);
2985 break;
2987 case NOTE_INSN_EH_REGION_BEG:
2988 eh_stack = alloc_INSN_LIST (insn, eh_stack);
2989 break;
2991 case NOTE_INSN_EH_REGION_END:
2992 /* Too many end notes. */
2993 if (eh_stack == NULL_RTX)
2994 abort ();
2995 /* Mismatched nesting. */
2996 if (NOTE_EH_HANDLER (XEXP (eh_stack, 0)) != NOTE_EH_HANDLER (insn))
2997 abort ();
2998 tmp = eh_stack;
2999 eh_stack = XEXP (eh_stack, 1);
3000 free_INSN_LIST_node (tmp);
3001 break;
3003 case NOTE_INSN_BLOCK_BEG:
3004 /* By now, all notes indicating lexical blocks should have
3005 NOTE_BLOCK filled in. */
3006 if (NOTE_BLOCK (insn) == NULL_TREE)
3007 abort ();
3008 block_stack = alloc_INSN_LIST (insn, block_stack);
3009 break;
3011 case NOTE_INSN_BLOCK_END:
3012 /* Too many end notes. */
3013 if (block_stack == NULL_RTX)
3014 abort ();
3015 /* Mismatched nesting. */
3016 if (NOTE_BLOCK (XEXP (block_stack, 0)) != NOTE_BLOCK (insn))
3017 abort ();
3018 tmp = block_stack;
3019 block_stack = XEXP (block_stack, 1);
3020 free_INSN_LIST_node (tmp);
3022 /* Scan back to see if there are any non-note instructions
3023 between INSN and the beginning of this block. If not,
3024 then there is no PC range in the generated code that will
3025 actually be in this block, so there's no point in
3026 remembering the existence of the block. */
3027 for (tmp = PREV_INSN (insn); tmp ; tmp = PREV_INSN (tmp))
3029 /* This block contains a real instruction. Note that we
3030 don't include labels; if the only thing in the block
3031 is a label, then there are still no PC values that
3032 lie within the block. */
3033 if (INSN_P (tmp))
3034 break;
3036 /* We're only interested in NOTEs. */
3037 if (GET_CODE (tmp) != NOTE)
3038 continue;
3040 if (NOTE_LINE_NUMBER (tmp) == NOTE_INSN_BLOCK_BEG)
3042 /* We just verified that this BLOCK matches us with
3043 the block_stack check above. Never delete the
3044 BLOCK for the outermost scope of the function; we
3045 can refer to names from that scope even if the
3046 block notes are messed up. */
3047 if (! is_body_block (NOTE_BLOCK (insn))
3048 && (*debug_hooks->ignore_block) (NOTE_BLOCK (insn)))
3050 remove_insn (tmp);
3051 remove_insn (insn);
3053 break;
3055 else if (NOTE_LINE_NUMBER (tmp) == NOTE_INSN_BLOCK_END)
3056 /* There's a nested block. We need to leave the
3057 current block in place since otherwise the debugger
3058 wouldn't be able to show symbols from our block in
3059 the nested block. */
3060 break;
3065 /* Too many begin notes. */
3066 if (block_stack || eh_stack)
3067 abort ();
3071 /* Emit an insn of given code and pattern
3072 at a specified place within the doubly-linked list. */
3074 /* Make an instruction with body PATTERN
3075 and output it before the instruction BEFORE. */
3078 emit_insn_before (pattern, before)
3079 register rtx pattern, before;
3081 register rtx insn = before;
3083 if (GET_CODE (pattern) == SEQUENCE)
3085 register int i;
3087 for (i = 0; i < XVECLEN (pattern, 0); i++)
3089 insn = XVECEXP (pattern, 0, i);
3090 add_insn_before (insn, before);
3093 else
3095 insn = make_insn_raw (pattern);
3096 add_insn_before (insn, before);
3099 return insn;
3102 /* Similar to emit_insn_before, but update basic block boundaries as well. */
3105 emit_block_insn_before (pattern, before, block)
3106 rtx pattern, before;
3107 basic_block block;
3109 rtx prev = PREV_INSN (before);
3110 rtx r = emit_insn_before (pattern, before);
3111 if (block && block->head == before)
3112 block->head = NEXT_INSN (prev);
3113 return r;
3116 /* Make an instruction with body PATTERN and code JUMP_INSN
3117 and output it before the instruction BEFORE. */
3120 emit_jump_insn_before (pattern, before)
3121 register rtx pattern, before;
3123 register rtx insn;
3125 if (GET_CODE (pattern) == SEQUENCE)
3126 insn = emit_insn_before (pattern, before);
3127 else
3129 insn = make_jump_insn_raw (pattern);
3130 add_insn_before (insn, before);
3133 return insn;
3136 /* Make an instruction with body PATTERN and code CALL_INSN
3137 and output it before the instruction BEFORE. */
3140 emit_call_insn_before (pattern, before)
3141 register rtx pattern, before;
3143 register rtx insn;
3145 if (GET_CODE (pattern) == SEQUENCE)
3146 insn = emit_insn_before (pattern, before);
3147 else
3149 insn = make_call_insn_raw (pattern);
3150 add_insn_before (insn, before);
3151 PUT_CODE (insn, CALL_INSN);
3154 return insn;
3157 /* Make an insn of code BARRIER
3158 and output it before the insn BEFORE. */
3161 emit_barrier_before (before)
3162 register rtx before;
3164 register rtx insn = rtx_alloc (BARRIER);
3166 INSN_UID (insn) = cur_insn_uid++;
3168 add_insn_before (insn, before);
3169 return insn;
3172 /* Emit the label LABEL before the insn BEFORE. */
3175 emit_label_before (label, before)
3176 rtx label, before;
3178 /* This can be called twice for the same label as a result of the
3179 confusion that follows a syntax error! So make it harmless. */
3180 if (INSN_UID (label) == 0)
3182 INSN_UID (label) = cur_insn_uid++;
3183 add_insn_before (label, before);
3186 return label;
3189 /* Emit a note of subtype SUBTYPE before the insn BEFORE. */
3192 emit_note_before (subtype, before)
3193 int subtype;
3194 rtx before;
3196 register rtx note = rtx_alloc (NOTE);
3197 INSN_UID (note) = cur_insn_uid++;
3198 NOTE_SOURCE_FILE (note) = 0;
3199 NOTE_LINE_NUMBER (note) = subtype;
3201 add_insn_before (note, before);
3202 return note;
3205 /* Make an insn of code INSN with body PATTERN
3206 and output it after the insn AFTER. */
3209 emit_insn_after (pattern, after)
3210 register rtx pattern, after;
3212 register rtx insn = after;
3214 if (GET_CODE (pattern) == SEQUENCE)
3216 register int i;
3218 for (i = 0; i < XVECLEN (pattern, 0); i++)
3220 insn = XVECEXP (pattern, 0, i);
3221 add_insn_after (insn, after);
3222 after = insn;
3225 else
3227 insn = make_insn_raw (pattern);
3228 add_insn_after (insn, after);
3231 return insn;
3234 /* Similar to emit_insn_after, except that line notes are to be inserted so
3235 as to act as if this insn were at FROM. */
3237 void
3238 emit_insn_after_with_line_notes (pattern, after, from)
3239 rtx pattern, after, from;
3241 rtx from_line = find_line_note (from);
3242 rtx after_line = find_line_note (after);
3243 rtx insn = emit_insn_after (pattern, after);
3245 if (from_line)
3246 emit_line_note_after (NOTE_SOURCE_FILE (from_line),
3247 NOTE_LINE_NUMBER (from_line),
3248 after);
3250 if (after_line)
3251 emit_line_note_after (NOTE_SOURCE_FILE (after_line),
3252 NOTE_LINE_NUMBER (after_line),
3253 insn);
3256 /* Similar to emit_insn_after, but update basic block boundaries as well. */
3259 emit_block_insn_after (pattern, after, block)
3260 rtx pattern, after;
3261 basic_block block;
3263 rtx r = emit_insn_after (pattern, after);
3264 if (block && block->end == after)
3265 block->end = r;
3266 return r;
3269 /* Make an insn of code JUMP_INSN with body PATTERN
3270 and output it after the insn AFTER. */
3273 emit_jump_insn_after (pattern, after)
3274 register rtx pattern, after;
3276 register rtx insn;
3278 if (GET_CODE (pattern) == SEQUENCE)
3279 insn = emit_insn_after (pattern, after);
3280 else
3282 insn = make_jump_insn_raw (pattern);
3283 add_insn_after (insn, after);
3286 return insn;
3289 /* Make an insn of code BARRIER
3290 and output it after the insn AFTER. */
3293 emit_barrier_after (after)
3294 register rtx after;
3296 register rtx insn = rtx_alloc (BARRIER);
3298 INSN_UID (insn) = cur_insn_uid++;
3300 add_insn_after (insn, after);
3301 return insn;
3304 /* Emit the label LABEL after the insn AFTER. */
3307 emit_label_after (label, after)
3308 rtx label, after;
3310 /* This can be called twice for the same label
3311 as a result of the confusion that follows a syntax error!
3312 So make it harmless. */
3313 if (INSN_UID (label) == 0)
3315 INSN_UID (label) = cur_insn_uid++;
3316 add_insn_after (label, after);
3319 return label;
3322 /* Emit a note of subtype SUBTYPE after the insn AFTER. */
3325 emit_note_after (subtype, after)
3326 int subtype;
3327 rtx after;
3329 register rtx note = rtx_alloc (NOTE);
3330 INSN_UID (note) = cur_insn_uid++;
3331 NOTE_SOURCE_FILE (note) = 0;
3332 NOTE_LINE_NUMBER (note) = subtype;
3333 add_insn_after (note, after);
3334 return note;
3337 /* Emit a line note for FILE and LINE after the insn AFTER. */
3340 emit_line_note_after (file, line, after)
3341 const char *file;
3342 int line;
3343 rtx after;
3345 register rtx note;
3347 if (no_line_numbers && line > 0)
3349 cur_insn_uid++;
3350 return 0;
3353 note = rtx_alloc (NOTE);
3354 INSN_UID (note) = cur_insn_uid++;
3355 NOTE_SOURCE_FILE (note) = file;
3356 NOTE_LINE_NUMBER (note) = line;
3357 add_insn_after (note, after);
3358 return note;
3361 /* Make an insn of code INSN with pattern PATTERN
3362 and add it to the end of the doubly-linked list.
3363 If PATTERN is a SEQUENCE, take the elements of it
3364 and emit an insn for each element.
3366 Returns the last insn emitted. */
3369 emit_insn (pattern)
3370 rtx pattern;
3372 rtx insn = last_insn;
3374 if (GET_CODE (pattern) == SEQUENCE)
3376 register int i;
3378 for (i = 0; i < XVECLEN (pattern, 0); i++)
3380 insn = XVECEXP (pattern, 0, i);
3381 add_insn (insn);
3384 else
3386 insn = make_insn_raw (pattern);
3387 add_insn (insn);
3390 return insn;
3393 /* Emit the insns in a chain starting with INSN.
3394 Return the last insn emitted. */
3397 emit_insns (insn)
3398 rtx insn;
3400 rtx last = 0;
3402 while (insn)
3404 rtx next = NEXT_INSN (insn);
3405 add_insn (insn);
3406 last = insn;
3407 insn = next;
3410 return last;
3413 /* Emit the insns in a chain starting with INSN and place them in front of
3414 the insn BEFORE. Return the last insn emitted. */
3417 emit_insns_before (insn, before)
3418 rtx insn;
3419 rtx before;
3421 rtx last = 0;
3423 while (insn)
3425 rtx next = NEXT_INSN (insn);
3426 add_insn_before (insn, before);
3427 last = insn;
3428 insn = next;
3431 return last;
3434 /* Emit the insns in a chain starting with FIRST and place them in back of
3435 the insn AFTER. Return the last insn emitted. */
3438 emit_insns_after (first, after)
3439 register rtx first;
3440 register rtx after;
3442 register rtx last;
3443 register rtx after_after;
3445 if (!after)
3446 abort ();
3448 if (!first)
3449 return first;
3451 for (last = first; NEXT_INSN (last); last = NEXT_INSN (last))
3452 continue;
3454 after_after = NEXT_INSN (after);
3456 NEXT_INSN (after) = first;
3457 PREV_INSN (first) = after;
3458 NEXT_INSN (last) = after_after;
3459 if (after_after)
3460 PREV_INSN (after_after) = last;
3462 if (after == last_insn)
3463 last_insn = last;
3464 return last;
3467 /* Make an insn of code JUMP_INSN with pattern PATTERN
3468 and add it to the end of the doubly-linked list. */
3471 emit_jump_insn (pattern)
3472 rtx pattern;
3474 if (GET_CODE (pattern) == SEQUENCE)
3475 return emit_insn (pattern);
3476 else
3478 register rtx insn = make_jump_insn_raw (pattern);
3479 add_insn (insn);
3480 return insn;
3484 /* Make an insn of code CALL_INSN with pattern PATTERN
3485 and add it to the end of the doubly-linked list. */
3488 emit_call_insn (pattern)
3489 rtx pattern;
3491 if (GET_CODE (pattern) == SEQUENCE)
3492 return emit_insn (pattern);
3493 else
3495 register rtx insn = make_call_insn_raw (pattern);
3496 add_insn (insn);
3497 PUT_CODE (insn, CALL_INSN);
3498 return insn;
3502 /* Add the label LABEL to the end of the doubly-linked list. */
3505 emit_label (label)
3506 rtx label;
3508 /* This can be called twice for the same label
3509 as a result of the confusion that follows a syntax error!
3510 So make it harmless. */
3511 if (INSN_UID (label) == 0)
3513 INSN_UID (label) = cur_insn_uid++;
3514 add_insn (label);
3516 return label;
3519 /* Make an insn of code BARRIER
3520 and add it to the end of the doubly-linked list. */
3523 emit_barrier ()
3525 register rtx barrier = rtx_alloc (BARRIER);
3526 INSN_UID (barrier) = cur_insn_uid++;
3527 add_insn (barrier);
3528 return barrier;
3531 /* Make an insn of code NOTE
3532 with data-fields specified by FILE and LINE
3533 and add it to the end of the doubly-linked list,
3534 but only if line-numbers are desired for debugging info. */
3537 emit_line_note (file, line)
3538 const char *file;
3539 int line;
3541 set_file_and_line_for_stmt (file, line);
3543 #if 0
3544 if (no_line_numbers)
3545 return 0;
3546 #endif
3548 return emit_note (file, line);
3551 /* Make an insn of code NOTE
3552 with data-fields specified by FILE and LINE
3553 and add it to the end of the doubly-linked list.
3554 If it is a line-number NOTE, omit it if it matches the previous one. */
3557 emit_note (file, line)
3558 const char *file;
3559 int line;
3561 register rtx note;
3563 if (line > 0)
3565 if (file && last_filename && !strcmp (file, last_filename)
3566 && line == last_linenum)
3567 return 0;
3568 last_filename = file;
3569 last_linenum = line;
3572 if (no_line_numbers && line > 0)
3574 cur_insn_uid++;
3575 return 0;
3578 note = rtx_alloc (NOTE);
3579 INSN_UID (note) = cur_insn_uid++;
3580 NOTE_SOURCE_FILE (note) = file;
3581 NOTE_LINE_NUMBER (note) = line;
3582 add_insn (note);
3583 return note;
3586 /* Emit a NOTE, and don't omit it even if LINE is the previous note. */
3589 emit_line_note_force (file, line)
3590 const char *file;
3591 int line;
3593 last_linenum = -1;
3594 return emit_line_note (file, line);
3597 /* Cause next statement to emit a line note even if the line number
3598 has not changed. This is used at the beginning of a function. */
3600 void
3601 force_next_line_note ()
3603 last_linenum = -1;
3606 /* Place a note of KIND on insn INSN with DATUM as the datum. If a
3607 note of this type already exists, remove it first. */
3609 void
3610 set_unique_reg_note (insn, kind, datum)
3611 rtx insn;
3612 enum reg_note kind;
3613 rtx datum;
3615 rtx note = find_reg_note (insn, kind, NULL_RTX);
3617 /* First remove the note if there already is one. */
3618 if (note)
3619 remove_note (insn, note);
3621 REG_NOTES (insn) = gen_rtx_EXPR_LIST (kind, datum, REG_NOTES (insn));
3624 /* Return an indication of which type of insn should have X as a body.
3625 The value is CODE_LABEL, INSN, CALL_INSN or JUMP_INSN. */
3627 enum rtx_code
3628 classify_insn (x)
3629 rtx x;
3631 if (GET_CODE (x) == CODE_LABEL)
3632 return CODE_LABEL;
3633 if (GET_CODE (x) == CALL)
3634 return CALL_INSN;
3635 if (GET_CODE (x) == RETURN)
3636 return JUMP_INSN;
3637 if (GET_CODE (x) == SET)
3639 if (SET_DEST (x) == pc_rtx)
3640 return JUMP_INSN;
3641 else if (GET_CODE (SET_SRC (x)) == CALL)
3642 return CALL_INSN;
3643 else
3644 return INSN;
3646 if (GET_CODE (x) == PARALLEL)
3648 register int j;
3649 for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
3650 if (GET_CODE (XVECEXP (x, 0, j)) == CALL)
3651 return CALL_INSN;
3652 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
3653 && SET_DEST (XVECEXP (x, 0, j)) == pc_rtx)
3654 return JUMP_INSN;
3655 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
3656 && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == CALL)
3657 return CALL_INSN;
3659 return INSN;
3662 /* Emit the rtl pattern X as an appropriate kind of insn.
3663 If X is a label, it is simply added into the insn chain. */
3666 emit (x)
3667 rtx x;
3669 enum rtx_code code = classify_insn (x);
3671 if (code == CODE_LABEL)
3672 return emit_label (x);
3673 else if (code == INSN)
3674 return emit_insn (x);
3675 else if (code == JUMP_INSN)
3677 register rtx insn = emit_jump_insn (x);
3678 if (any_uncondjump_p (insn) || GET_CODE (x) == RETURN)
3679 return emit_barrier ();
3680 return insn;
3682 else if (code == CALL_INSN)
3683 return emit_call_insn (x);
3684 else
3685 abort ();
3688 /* Begin emitting insns to a sequence which can be packaged in an
3689 RTL_EXPR. If this sequence will contain something that might cause
3690 the compiler to pop arguments to function calls (because those
3691 pops have previously been deferred; see INHIBIT_DEFER_POP for more
3692 details), use do_pending_stack_adjust before calling this function.
3693 That will ensure that the deferred pops are not accidentally
3694 emitted in the middle of this sequence. */
3696 void
3697 start_sequence ()
3699 struct sequence_stack *tem;
3701 tem = (struct sequence_stack *) xmalloc (sizeof (struct sequence_stack));
3703 tem->next = seq_stack;
3704 tem->first = first_insn;
3705 tem->last = last_insn;
3706 tem->sequence_rtl_expr = seq_rtl_expr;
3708 seq_stack = tem;
3710 first_insn = 0;
3711 last_insn = 0;
3714 /* Similarly, but indicate that this sequence will be placed in T, an
3715 RTL_EXPR. See the documentation for start_sequence for more
3716 information about how to use this function. */
3718 void
3719 start_sequence_for_rtl_expr (t)
3720 tree t;
3722 start_sequence ();
3724 seq_rtl_expr = t;
3727 /* Set up the insn chain starting with FIRST as the current sequence,
3728 saving the previously current one. See the documentation for
3729 start_sequence for more information about how to use this function. */
3731 void
3732 push_to_sequence (first)
3733 rtx first;
3735 rtx last;
3737 start_sequence ();
3739 for (last = first; last && NEXT_INSN (last); last = NEXT_INSN (last));
3741 first_insn = first;
3742 last_insn = last;
3745 /* Set up the insn chain from a chain stort in FIRST to LAST. */
3747 void
3748 push_to_full_sequence (first, last)
3749 rtx first, last;
3751 start_sequence ();
3752 first_insn = first;
3753 last_insn = last;
3754 /* We really should have the end of the insn chain here. */
3755 if (last && NEXT_INSN (last))
3756 abort ();
3759 /* Set up the outer-level insn chain
3760 as the current sequence, saving the previously current one. */
3762 void
3763 push_topmost_sequence ()
3765 struct sequence_stack *stack, *top = NULL;
3767 start_sequence ();
3769 for (stack = seq_stack; stack; stack = stack->next)
3770 top = stack;
3772 first_insn = top->first;
3773 last_insn = top->last;
3774 seq_rtl_expr = top->sequence_rtl_expr;
3777 /* After emitting to the outer-level insn chain, update the outer-level
3778 insn chain, and restore the previous saved state. */
3780 void
3781 pop_topmost_sequence ()
3783 struct sequence_stack *stack, *top = NULL;
3785 for (stack = seq_stack; stack; stack = stack->next)
3786 top = stack;
3788 top->first = first_insn;
3789 top->last = last_insn;
3790 /* ??? Why don't we save seq_rtl_expr here? */
3792 end_sequence ();
3795 /* After emitting to a sequence, restore previous saved state.
3797 To get the contents of the sequence just made, you must call
3798 `gen_sequence' *before* calling here.
3800 If the compiler might have deferred popping arguments while
3801 generating this sequence, and this sequence will not be immediately
3802 inserted into the instruction stream, use do_pending_stack_adjust
3803 before calling gen_sequence. That will ensure that the deferred
3804 pops are inserted into this sequence, and not into some random
3805 location in the instruction stream. See INHIBIT_DEFER_POP for more
3806 information about deferred popping of arguments. */
3808 void
3809 end_sequence ()
3811 struct sequence_stack *tem = seq_stack;
3813 first_insn = tem->first;
3814 last_insn = tem->last;
3815 seq_rtl_expr = tem->sequence_rtl_expr;
3816 seq_stack = tem->next;
3818 free (tem);
3821 /* This works like end_sequence, but records the old sequence in FIRST
3822 and LAST. */
3824 void
3825 end_full_sequence (first, last)
3826 rtx *first, *last;
3828 *first = first_insn;
3829 *last = last_insn;
3830 end_sequence();
3833 /* Return 1 if currently emitting into a sequence. */
3836 in_sequence_p ()
3838 return seq_stack != 0;
3841 /* Generate a SEQUENCE rtx containing the insns already emitted
3842 to the current sequence.
3844 This is how the gen_... function from a DEFINE_EXPAND
3845 constructs the SEQUENCE that it returns. */
3848 gen_sequence ()
3850 rtx result;
3851 rtx tem;
3852 int i;
3853 int len;
3855 /* Count the insns in the chain. */
3856 len = 0;
3857 for (tem = first_insn; tem; tem = NEXT_INSN (tem))
3858 len++;
3860 /* If only one insn, return it rather than a SEQUENCE.
3861 (Now that we cache SEQUENCE expressions, it isn't worth special-casing
3862 the case of an empty list.)
3863 We only return the pattern of an insn if its code is INSN and it
3864 has no notes. This ensures that no information gets lost. */
3865 if (len == 1
3866 && ! RTX_FRAME_RELATED_P (first_insn)
3867 && GET_CODE (first_insn) == INSN
3868 /* Don't throw away any reg notes. */
3869 && REG_NOTES (first_insn) == 0)
3870 return PATTERN (first_insn);
3872 result = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (len));
3874 for (i = 0, tem = first_insn; tem; tem = NEXT_INSN (tem), i++)
3875 XVECEXP (result, 0, i) = tem;
3877 return result;
3880 /* Put the various virtual registers into REGNO_REG_RTX. */
3882 void
3883 init_virtual_regs (es)
3884 struct emit_status *es;
3886 rtx *ptr = es->x_regno_reg_rtx;
3887 ptr[VIRTUAL_INCOMING_ARGS_REGNUM] = virtual_incoming_args_rtx;
3888 ptr[VIRTUAL_STACK_VARS_REGNUM] = virtual_stack_vars_rtx;
3889 ptr[VIRTUAL_STACK_DYNAMIC_REGNUM] = virtual_stack_dynamic_rtx;
3890 ptr[VIRTUAL_OUTGOING_ARGS_REGNUM] = virtual_outgoing_args_rtx;
3891 ptr[VIRTUAL_CFA_REGNUM] = virtual_cfa_rtx;
3894 void
3895 clear_emit_caches ()
3897 int i;
3899 /* Clear the start_sequence/gen_sequence cache. */
3900 for (i = 0; i < SEQUENCE_RESULT_SIZE; i++)
3901 sequence_result[i] = 0;
3902 free_insn = 0;
3905 /* Used by copy_insn_1 to avoid copying SCRATCHes more than once. */
3906 static rtx copy_insn_scratch_in[MAX_RECOG_OPERANDS];
3907 static rtx copy_insn_scratch_out[MAX_RECOG_OPERANDS];
3908 static int copy_insn_n_scratches;
3910 /* When an insn is being copied by copy_insn_1, this is nonzero if we have
3911 copied an ASM_OPERANDS.
3912 In that case, it is the original input-operand vector. */
3913 static rtvec orig_asm_operands_vector;
3915 /* When an insn is being copied by copy_insn_1, this is nonzero if we have
3916 copied an ASM_OPERANDS.
3917 In that case, it is the copied input-operand vector. */
3918 static rtvec copy_asm_operands_vector;
3920 /* Likewise for the constraints vector. */
3921 static rtvec orig_asm_constraints_vector;
3922 static rtvec copy_asm_constraints_vector;
3924 /* Recursively create a new copy of an rtx for copy_insn.
3925 This function differs from copy_rtx in that it handles SCRATCHes and
3926 ASM_OPERANDs properly.
3927 Normally, this function is not used directly; use copy_insn as front end.
3928 However, you could first copy an insn pattern with copy_insn and then use
3929 this function afterwards to properly copy any REG_NOTEs containing
3930 SCRATCHes. */
3933 copy_insn_1 (orig)
3934 register rtx orig;
3936 register rtx copy;
3937 register int i, j;
3938 register RTX_CODE code;
3939 register const char *format_ptr;
3941 code = GET_CODE (orig);
3943 switch (code)
3945 case REG:
3946 case QUEUED:
3947 case CONST_INT:
3948 case CONST_DOUBLE:
3949 case SYMBOL_REF:
3950 case CODE_LABEL:
3951 case PC:
3952 case CC0:
3953 case ADDRESSOF:
3954 return orig;
3956 case SCRATCH:
3957 for (i = 0; i < copy_insn_n_scratches; i++)
3958 if (copy_insn_scratch_in[i] == orig)
3959 return copy_insn_scratch_out[i];
3960 break;
3962 case CONST:
3963 /* CONST can be shared if it contains a SYMBOL_REF. If it contains
3964 a LABEL_REF, it isn't sharable. */
3965 if (GET_CODE (XEXP (orig, 0)) == PLUS
3966 && GET_CODE (XEXP (XEXP (orig, 0), 0)) == SYMBOL_REF
3967 && GET_CODE (XEXP (XEXP (orig, 0), 1)) == CONST_INT)
3968 return orig;
3969 break;
3971 /* A MEM with a constant address is not sharable. The problem is that
3972 the constant address may need to be reloaded. If the mem is shared,
3973 then reloading one copy of this mem will cause all copies to appear
3974 to have been reloaded. */
3976 default:
3977 break;
3980 copy = rtx_alloc (code);
3982 /* Copy the various flags, and other information. We assume that
3983 all fields need copying, and then clear the fields that should
3984 not be copied. That is the sensible default behavior, and forces
3985 us to explicitly document why we are *not* copying a flag. */
3986 memcpy (copy, orig, sizeof (struct rtx_def) - sizeof (rtunion));
3988 /* We do not copy the USED flag, which is used as a mark bit during
3989 walks over the RTL. */
3990 copy->used = 0;
3992 /* We do not copy JUMP, CALL, or FRAME_RELATED for INSNs. */
3993 if (GET_RTX_CLASS (code) == 'i')
3995 copy->jump = 0;
3996 copy->call = 0;
3997 copy->frame_related = 0;
4000 format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
4002 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
4004 copy->fld[i] = orig->fld[i];
4005 switch (*format_ptr++)
4007 case 'e':
4008 if (XEXP (orig, i) != NULL)
4009 XEXP (copy, i) = copy_insn_1 (XEXP (orig, i));
4010 break;
4012 case 'E':
4013 case 'V':
4014 if (XVEC (orig, i) == orig_asm_constraints_vector)
4015 XVEC (copy, i) = copy_asm_constraints_vector;
4016 else if (XVEC (orig, i) == orig_asm_operands_vector)
4017 XVEC (copy, i) = copy_asm_operands_vector;
4018 else if (XVEC (orig, i) != NULL)
4020 XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
4021 for (j = 0; j < XVECLEN (copy, i); j++)
4022 XVECEXP (copy, i, j) = copy_insn_1 (XVECEXP (orig, i, j));
4024 break;
4026 case 't':
4027 case 'w':
4028 case 'i':
4029 case 's':
4030 case 'S':
4031 case 'u':
4032 case '0':
4033 /* These are left unchanged. */
4034 break;
4036 default:
4037 abort ();
4041 if (code == SCRATCH)
4043 i = copy_insn_n_scratches++;
4044 if (i >= MAX_RECOG_OPERANDS)
4045 abort ();
4046 copy_insn_scratch_in[i] = orig;
4047 copy_insn_scratch_out[i] = copy;
4049 else if (code == ASM_OPERANDS)
4051 orig_asm_operands_vector = ASM_OPERANDS_INPUT_VEC (orig);
4052 copy_asm_operands_vector = ASM_OPERANDS_INPUT_VEC (copy);
4053 orig_asm_constraints_vector = ASM_OPERANDS_INPUT_CONSTRAINT_VEC (orig);
4054 copy_asm_constraints_vector = ASM_OPERANDS_INPUT_CONSTRAINT_VEC (copy);
4057 return copy;
4060 /* Create a new copy of an rtx.
4061 This function differs from copy_rtx in that it handles SCRATCHes and
4062 ASM_OPERANDs properly.
4063 INSN doesn't really have to be a full INSN; it could be just the
4064 pattern. */
4066 copy_insn (insn)
4067 rtx insn;
4069 copy_insn_n_scratches = 0;
4070 orig_asm_operands_vector = 0;
4071 orig_asm_constraints_vector = 0;
4072 copy_asm_operands_vector = 0;
4073 copy_asm_constraints_vector = 0;
4074 return copy_insn_1 (insn);
4077 /* Initialize data structures and variables in this file
4078 before generating rtl for each function. */
4080 void
4081 init_emit ()
4083 struct function *f = cfun;
4085 f->emit = (struct emit_status *) xmalloc (sizeof (struct emit_status));
4086 first_insn = NULL;
4087 last_insn = NULL;
4088 seq_rtl_expr = NULL;
4089 cur_insn_uid = 1;
4090 reg_rtx_no = LAST_VIRTUAL_REGISTER + 1;
4091 last_linenum = 0;
4092 last_filename = 0;
4093 first_label_num = label_num;
4094 last_label_num = 0;
4095 seq_stack = NULL;
4097 clear_emit_caches ();
4099 /* Init the tables that describe all the pseudo regs. */
4101 f->emit->regno_pointer_align_length = LAST_VIRTUAL_REGISTER + 101;
4103 f->emit->regno_pointer_align
4104 = (unsigned char *) xcalloc (f->emit->regno_pointer_align_length,
4105 sizeof (unsigned char));
4107 regno_reg_rtx
4108 = (rtx *) xcalloc (f->emit->regno_pointer_align_length * sizeof (rtx),
4109 sizeof (rtx));
4111 /* Put copies of all the virtual register rtx into regno_reg_rtx. */
4112 init_virtual_regs (f->emit);
4114 /* Indicate that the virtual registers and stack locations are
4115 all pointers. */
4116 REG_POINTER (stack_pointer_rtx) = 1;
4117 REG_POINTER (frame_pointer_rtx) = 1;
4118 REG_POINTER (hard_frame_pointer_rtx) = 1;
4119 REG_POINTER (arg_pointer_rtx) = 1;
4121 REG_POINTER (virtual_incoming_args_rtx) = 1;
4122 REG_POINTER (virtual_stack_vars_rtx) = 1;
4123 REG_POINTER (virtual_stack_dynamic_rtx) = 1;
4124 REG_POINTER (virtual_outgoing_args_rtx) = 1;
4125 REG_POINTER (virtual_cfa_rtx) = 1;
4127 #ifdef STACK_BOUNDARY
4128 REGNO_POINTER_ALIGN (STACK_POINTER_REGNUM) = STACK_BOUNDARY;
4129 REGNO_POINTER_ALIGN (FRAME_POINTER_REGNUM) = STACK_BOUNDARY;
4130 REGNO_POINTER_ALIGN (HARD_FRAME_POINTER_REGNUM) = STACK_BOUNDARY;
4131 REGNO_POINTER_ALIGN (ARG_POINTER_REGNUM) = STACK_BOUNDARY;
4133 REGNO_POINTER_ALIGN (VIRTUAL_INCOMING_ARGS_REGNUM) = STACK_BOUNDARY;
4134 REGNO_POINTER_ALIGN (VIRTUAL_STACK_VARS_REGNUM) = STACK_BOUNDARY;
4135 REGNO_POINTER_ALIGN (VIRTUAL_STACK_DYNAMIC_REGNUM) = STACK_BOUNDARY;
4136 REGNO_POINTER_ALIGN (VIRTUAL_OUTGOING_ARGS_REGNUM) = STACK_BOUNDARY;
4137 REGNO_POINTER_ALIGN (VIRTUAL_CFA_REGNUM) = BITS_PER_WORD;
4138 #endif
4140 #ifdef INIT_EXPANDERS
4141 INIT_EXPANDERS;
4142 #endif
4145 /* Mark SS for GC. */
4147 static void
4148 mark_sequence_stack (ss)
4149 struct sequence_stack *ss;
4151 while (ss)
4153 ggc_mark_rtx (ss->first);
4154 ggc_mark_tree (ss->sequence_rtl_expr);
4155 ss = ss->next;
4159 /* Mark ES for GC. */
4161 void
4162 mark_emit_status (es)
4163 struct emit_status *es;
4165 rtx *r;
4166 int i;
4168 if (es == 0)
4169 return;
4171 for (i = es->regno_pointer_align_length, r = es->x_regno_reg_rtx;
4172 i > 0; --i, ++r)
4173 ggc_mark_rtx (*r);
4175 mark_sequence_stack (es->sequence_stack);
4176 ggc_mark_tree (es->sequence_rtl_expr);
4177 ggc_mark_rtx (es->x_first_insn);
4180 /* Create some permanent unique rtl objects shared between all functions.
4181 LINE_NUMBERS is nonzero if line numbers are to be generated. */
4183 void
4184 init_emit_once (line_numbers)
4185 int line_numbers;
4187 int i;
4188 enum machine_mode mode;
4189 enum machine_mode double_mode;
4191 /* Initialize the CONST_INT hash table. */
4192 const_int_htab = htab_create (37, const_int_htab_hash,
4193 const_int_htab_eq, NULL);
4194 ggc_add_root (&const_int_htab, 1, sizeof (const_int_htab),
4195 rtx_htab_mark);
4197 no_line_numbers = ! line_numbers;
4199 /* Compute the word and byte modes. */
4201 byte_mode = VOIDmode;
4202 word_mode = VOIDmode;
4203 double_mode = VOIDmode;
4205 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
4206 mode = GET_MODE_WIDER_MODE (mode))
4208 if (GET_MODE_BITSIZE (mode) == BITS_PER_UNIT
4209 && byte_mode == VOIDmode)
4210 byte_mode = mode;
4212 if (GET_MODE_BITSIZE (mode) == BITS_PER_WORD
4213 && word_mode == VOIDmode)
4214 word_mode = mode;
4217 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
4218 mode = GET_MODE_WIDER_MODE (mode))
4220 if (GET_MODE_BITSIZE (mode) == DOUBLE_TYPE_SIZE
4221 && double_mode == VOIDmode)
4222 double_mode = mode;
4225 ptr_mode = mode_for_size (POINTER_SIZE, GET_MODE_CLASS (Pmode), 0);
4227 /* Assign register numbers to the globally defined register rtx.
4228 This must be done at runtime because the register number field
4229 is in a union and some compilers can't initialize unions. */
4231 pc_rtx = gen_rtx (PC, VOIDmode);
4232 cc0_rtx = gen_rtx (CC0, VOIDmode);
4233 stack_pointer_rtx = gen_raw_REG (Pmode, STACK_POINTER_REGNUM);
4234 frame_pointer_rtx = gen_raw_REG (Pmode, FRAME_POINTER_REGNUM);
4235 if (hard_frame_pointer_rtx == 0)
4236 hard_frame_pointer_rtx = gen_raw_REG (Pmode,
4237 HARD_FRAME_POINTER_REGNUM);
4238 if (arg_pointer_rtx == 0)
4239 arg_pointer_rtx = gen_raw_REG (Pmode, ARG_POINTER_REGNUM);
4240 virtual_incoming_args_rtx =
4241 gen_raw_REG (Pmode, VIRTUAL_INCOMING_ARGS_REGNUM);
4242 virtual_stack_vars_rtx =
4243 gen_raw_REG (Pmode, VIRTUAL_STACK_VARS_REGNUM);
4244 virtual_stack_dynamic_rtx =
4245 gen_raw_REG (Pmode, VIRTUAL_STACK_DYNAMIC_REGNUM);
4246 virtual_outgoing_args_rtx =
4247 gen_raw_REG (Pmode, VIRTUAL_OUTGOING_ARGS_REGNUM);
4248 virtual_cfa_rtx = gen_raw_REG (Pmode, VIRTUAL_CFA_REGNUM);
4250 /* These rtx must be roots if GC is enabled. */
4251 ggc_add_rtx_root (global_rtl, GR_MAX);
4253 #ifdef INIT_EXPANDERS
4254 /* This is to initialize {init|mark|free}_machine_status before the first
4255 call to push_function_context_to. This is needed by the Chill front
4256 end which calls push_function_context_to before the first cal to
4257 init_function_start. */
4258 INIT_EXPANDERS;
4259 #endif
4261 /* Create the unique rtx's for certain rtx codes and operand values. */
4263 /* Don't use gen_rtx here since gen_rtx in this case
4264 tries to use these variables. */
4265 for (i = - MAX_SAVED_CONST_INT; i <= MAX_SAVED_CONST_INT; i++)
4266 const_int_rtx[i + MAX_SAVED_CONST_INT] =
4267 gen_rtx_raw_CONST_INT (VOIDmode, i);
4268 ggc_add_rtx_root (const_int_rtx, 2 * MAX_SAVED_CONST_INT + 1);
4270 if (STORE_FLAG_VALUE >= - MAX_SAVED_CONST_INT
4271 && STORE_FLAG_VALUE <= MAX_SAVED_CONST_INT)
4272 const_true_rtx = const_int_rtx[STORE_FLAG_VALUE + MAX_SAVED_CONST_INT];
4273 else
4274 const_true_rtx = gen_rtx_CONST_INT (VOIDmode, STORE_FLAG_VALUE);
4276 dconst0 = REAL_VALUE_ATOF ("0", double_mode);
4277 dconst1 = REAL_VALUE_ATOF ("1", double_mode);
4278 dconst2 = REAL_VALUE_ATOF ("2", double_mode);
4279 dconstm1 = REAL_VALUE_ATOF ("-1", double_mode);
4281 for (i = 0; i <= 2; i++)
4283 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
4284 mode = GET_MODE_WIDER_MODE (mode))
4286 rtx tem = rtx_alloc (CONST_DOUBLE);
4287 union real_extract u;
4289 /* Zero any holes in a structure. */
4290 memset ((char *) &u, 0, sizeof u);
4291 u.d = i == 0 ? dconst0 : i == 1 ? dconst1 : dconst2;
4293 /* Avoid trailing garbage in the rtx. */
4294 if (sizeof (u) < sizeof (HOST_WIDE_INT))
4295 CONST_DOUBLE_LOW (tem) = 0;
4296 if (sizeof (u) < 2 * sizeof (HOST_WIDE_INT))
4297 CONST_DOUBLE_HIGH (tem) = 0;
4299 memcpy (&CONST_DOUBLE_LOW (tem), &u, sizeof u);
4300 CONST_DOUBLE_MEM (tem) = cc0_rtx;
4301 CONST_DOUBLE_CHAIN (tem) = NULL_RTX;
4302 PUT_MODE (tem, mode);
4304 const_tiny_rtx[i][(int) mode] = tem;
4307 const_tiny_rtx[i][(int) VOIDmode] = GEN_INT (i);
4309 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
4310 mode = GET_MODE_WIDER_MODE (mode))
4311 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
4313 for (mode = GET_CLASS_NARROWEST_MODE (MODE_PARTIAL_INT);
4314 mode != VOIDmode;
4315 mode = GET_MODE_WIDER_MODE (mode))
4316 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
4319 for (i = (int) CCmode; i < (int) MAX_MACHINE_MODE; ++i)
4320 if (GET_MODE_CLASS ((enum machine_mode) i) == MODE_CC)
4321 const_tiny_rtx[0][i] = const0_rtx;
4323 const_tiny_rtx[0][(int) BImode] = const0_rtx;
4324 if (STORE_FLAG_VALUE == 1)
4325 const_tiny_rtx[1][(int) BImode] = const1_rtx;
4327 /* For bounded pointers, `&const_tiny_rtx[0][0]' is not the same as
4328 `(rtx *) const_tiny_rtx'. The former has bounds that only cover
4329 `const_tiny_rtx[0]', whereas the latter has bounds that cover all. */
4330 ggc_add_rtx_root ((rtx *) const_tiny_rtx, sizeof const_tiny_rtx / sizeof (rtx));
4331 ggc_add_rtx_root (&const_true_rtx, 1);
4333 #ifdef RETURN_ADDRESS_POINTER_REGNUM
4334 return_address_pointer_rtx
4335 = gen_raw_REG (Pmode, RETURN_ADDRESS_POINTER_REGNUM);
4336 #endif
4338 #ifdef STRUCT_VALUE
4339 struct_value_rtx = STRUCT_VALUE;
4340 #else
4341 struct_value_rtx = gen_rtx_REG (Pmode, STRUCT_VALUE_REGNUM);
4342 #endif
4344 #ifdef STRUCT_VALUE_INCOMING
4345 struct_value_incoming_rtx = STRUCT_VALUE_INCOMING;
4346 #else
4347 #ifdef STRUCT_VALUE_INCOMING_REGNUM
4348 struct_value_incoming_rtx
4349 = gen_rtx_REG (Pmode, STRUCT_VALUE_INCOMING_REGNUM);
4350 #else
4351 struct_value_incoming_rtx = struct_value_rtx;
4352 #endif
4353 #endif
4355 #ifdef STATIC_CHAIN_REGNUM
4356 static_chain_rtx = gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM);
4358 #ifdef STATIC_CHAIN_INCOMING_REGNUM
4359 if (STATIC_CHAIN_INCOMING_REGNUM != STATIC_CHAIN_REGNUM)
4360 static_chain_incoming_rtx
4361 = gen_rtx_REG (Pmode, STATIC_CHAIN_INCOMING_REGNUM);
4362 else
4363 #endif
4364 static_chain_incoming_rtx = static_chain_rtx;
4365 #endif
4367 #ifdef STATIC_CHAIN
4368 static_chain_rtx = STATIC_CHAIN;
4370 #ifdef STATIC_CHAIN_INCOMING
4371 static_chain_incoming_rtx = STATIC_CHAIN_INCOMING;
4372 #else
4373 static_chain_incoming_rtx = static_chain_rtx;
4374 #endif
4375 #endif
4377 if (PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM)
4378 pic_offset_table_rtx = gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM);
4380 ggc_add_rtx_root (&pic_offset_table_rtx, 1);
4381 ggc_add_rtx_root (&struct_value_rtx, 1);
4382 ggc_add_rtx_root (&struct_value_incoming_rtx, 1);
4383 ggc_add_rtx_root (&static_chain_rtx, 1);
4384 ggc_add_rtx_root (&static_chain_incoming_rtx, 1);
4385 ggc_add_rtx_root (&return_address_pointer_rtx, 1);
4388 /* Query and clear/ restore no_line_numbers. This is used by the
4389 switch / case handling in stmt.c to give proper line numbers in
4390 warnings about unreachable code. */
4393 force_line_numbers ()
4395 int old = no_line_numbers;
4397 no_line_numbers = 0;
4398 if (old)
4399 force_next_line_note ();
4400 return old;
4403 void
4404 restore_line_number_status (old_value)
4405 int old_value;
4407 no_line_numbers = old_value;