(distribute_notes, case REG_DEAD): If a call uses a
[official-gcc.git] / gcc / emit-rtl.c
blob3afcccbcf5e9372b62945f749f784cfe59b0dae0
1 /* Emit RTL for the GNU C-Compiler expander.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* Middle-to-low level generation of rtx code and insns.
23 This file contains the functions `gen_rtx', `gen_reg_rtx'
24 and `gen_label_rtx' that are the usual ways of creating rtl
25 expressions for most purposes.
27 It also has the functions for creating insns and linking
28 them in the doubly-linked chain.
30 The patterns of the insns are created by machine-dependent
31 routines in insn-emit.c, which is generated automatically from
32 the machine description. These routines use `gen_rtx' to make
33 the individual rtx's of the pattern; what is machine dependent
34 is the kind of rtx's they make and what arguments they use. */
36 #include "config.h"
37 #ifdef __STDC__
38 #include <stdarg.h>
39 #else
40 #include <varargs.h>
41 #endif
42 #include "rtl.h"
43 #include "tree.h"
44 #include "flags.h"
45 #include "function.h"
46 #include "expr.h"
47 #include "regs.h"
48 #include "insn-config.h"
49 #include "real.h"
50 #include "obstack.h"
52 #include "bytecode.h"
53 #include "machmode.h"
54 #include "bc-opcode.h"
55 #include "bc-typecd.h"
56 #include "bc-optab.h"
57 #include "bc-emit.h"
59 #include <stdio.h>
62 /* Opcode names */
63 #ifdef BCDEBUG_PRINT_CODE
64 char *opcode_name[] =
66 #include "bc-opname.h"
68 "***END***"
70 #endif
73 /* Commonly used modes. */
75 enum machine_mode byte_mode; /* Mode whose width is BITS_PER_UNIT */
76 enum machine_mode word_mode; /* Mode whose width is BITS_PER_WORD */
78 /* This is reset to LAST_VIRTUAL_REGISTER + 1 at the start of each function.
79 After rtl generation, it is 1 plus the largest register number used. */
81 int reg_rtx_no = LAST_VIRTUAL_REGISTER + 1;
83 /* This is *not* reset after each function. It gives each CODE_LABEL
84 in the entire compilation a unique label number. */
86 static int label_num = 1;
88 /* Lowest label number in current function. */
90 static int first_label_num;
92 /* Highest label number in current function.
93 Zero means use the value of label_num instead.
94 This is nonzero only when belatedly compiling an inline function. */
96 static int last_label_num;
98 /* Value label_num had when set_new_first_and_last_label_number was called.
99 If label_num has not changed since then, last_label_num is valid. */
101 static int base_label_num;
103 /* Nonzero means do not generate NOTEs for source line numbers. */
105 static int no_line_numbers;
107 /* Commonly used rtx's, so that we only need space for one copy.
108 These are initialized once for the entire compilation.
109 All of these except perhaps the floating-point CONST_DOUBLEs
110 are unique; no other rtx-object will be equal to any of these. */
112 rtx pc_rtx; /* (PC) */
113 rtx cc0_rtx; /* (CC0) */
114 rtx cc1_rtx; /* (CC1) (not actually used nowadays) */
115 rtx const0_rtx; /* (CONST_INT 0) */
116 rtx const1_rtx; /* (CONST_INT 1) */
117 rtx const2_rtx; /* (CONST_INT 2) */
118 rtx constm1_rtx; /* (CONST_INT -1) */
119 rtx const_true_rtx; /* (CONST_INT STORE_FLAG_VALUE) */
121 /* We record floating-point CONST_DOUBLEs in each floating-point mode for
122 the values of 0, 1, and 2. For the integer entries and VOIDmode, we
123 record a copy of const[012]_rtx. */
125 rtx const_tiny_rtx[3][(int) MAX_MACHINE_MODE];
127 REAL_VALUE_TYPE dconst0;
128 REAL_VALUE_TYPE dconst1;
129 REAL_VALUE_TYPE dconst2;
130 REAL_VALUE_TYPE dconstm1;
132 /* All references to the following fixed hard registers go through
133 these unique rtl objects. On machines where the frame-pointer and
134 arg-pointer are the same register, they use the same unique object.
136 After register allocation, other rtl objects which used to be pseudo-regs
137 may be clobbered to refer to the frame-pointer register.
138 But references that were originally to the frame-pointer can be
139 distinguished from the others because they contain frame_pointer_rtx.
141 When to use frame_pointer_rtx and hard_frame_pointer_rtx is a little
142 tricky: until register elimination has taken place hard_frame_pointer_rtx
143 should be used if it is being set, and frame_pointer_rtx otherwise. After
144 register elimination hard_frame_pointer_rtx should always be used.
145 On machines where the two registers are same (most) then these are the
146 same.
148 In an inline procedure, the stack and frame pointer rtxs may not be
149 used for anything else. */
150 rtx stack_pointer_rtx; /* (REG:Pmode STACK_POINTER_REGNUM) */
151 rtx frame_pointer_rtx; /* (REG:Pmode FRAME_POINTER_REGNUM) */
152 rtx hard_frame_pointer_rtx; /* (REG:Pmode HARD_FRAME_POINTER_REGNUM) */
153 rtx arg_pointer_rtx; /* (REG:Pmode ARG_POINTER_REGNUM) */
154 rtx struct_value_rtx; /* (REG:Pmode STRUCT_VALUE_REGNUM) */
155 rtx struct_value_incoming_rtx; /* (REG:Pmode STRUCT_VALUE_INCOMING_REGNUM) */
156 rtx static_chain_rtx; /* (REG:Pmode STATIC_CHAIN_REGNUM) */
157 rtx static_chain_incoming_rtx; /* (REG:Pmode STATIC_CHAIN_INCOMING_REGNUM) */
158 rtx pic_offset_table_rtx; /* (REG:Pmode PIC_OFFSET_TABLE_REGNUM) */
160 rtx virtual_incoming_args_rtx; /* (REG:Pmode VIRTUAL_INCOMING_ARGS_REGNUM) */
161 rtx virtual_stack_vars_rtx; /* (REG:Pmode VIRTUAL_STACK_VARS_REGNUM) */
162 rtx virtual_stack_dynamic_rtx; /* (REG:Pmode VIRTUAL_STACK_DYNAMIC_REGNUM) */
163 rtx virtual_outgoing_args_rtx; /* (REG:Pmode VIRTUAL_OUTGOING_ARGS_REGNUM) */
165 /* We make one copy of (const_int C) where C is in
166 [- MAX_SAVED_CONST_INT, MAX_SAVED_CONST_INT]
167 to save space during the compilation and simplify comparisons of
168 integers. */
170 #define MAX_SAVED_CONST_INT 64
172 static rtx const_int_rtx[MAX_SAVED_CONST_INT * 2 + 1];
174 /* The ends of the doubly-linked chain of rtl for the current function.
175 Both are reset to null at the start of rtl generation for the function.
177 start_sequence saves both of these on `sequence_stack' along with
178 `sequence_rtl_expr' and then starts a new, nested sequence of insns. */
180 static rtx first_insn = NULL;
181 static rtx last_insn = NULL;
183 /* RTL_EXPR within which the current sequence will be placed. Use to
184 prevent reuse of any temporaries within the sequence until after the
185 RTL_EXPR is emitted. */
187 tree sequence_rtl_expr = NULL;
189 /* INSN_UID for next insn emitted.
190 Reset to 1 for each function compiled. */
192 static int cur_insn_uid = 1;
194 /* Line number and source file of the last line-number NOTE emitted.
195 This is used to avoid generating duplicates. */
197 static int last_linenum = 0;
198 static char *last_filename = 0;
200 /* A vector indexed by pseudo reg number. The allocated length
201 of this vector is regno_pointer_flag_length. Since this
202 vector is needed during the expansion phase when the total
203 number of registers in the function is not yet known,
204 it is copied and made bigger when necessary. */
206 char *regno_pointer_flag;
207 int regno_pointer_flag_length;
209 /* Indexed by pseudo register number, gives the rtx for that pseudo.
210 Allocated in parallel with regno_pointer_flag. */
212 rtx *regno_reg_rtx;
214 /* Stack of pending (incomplete) sequences saved by `start_sequence'.
215 Each element describes one pending sequence.
216 The main insn-chain is saved in the last element of the chain,
217 unless the chain is empty. */
219 struct sequence_stack *sequence_stack;
221 /* start_sequence and gen_sequence can make a lot of rtx expressions which are
222 shortly thrown away. We use two mechanisms to prevent this waste:
224 First, we keep a list of the expressions used to represent the sequence
225 stack in sequence_element_free_list.
227 Second, for sizes up to 5 elements, we keep a SEQUENCE and its associated
228 rtvec for use by gen_sequence. One entry for each size is sufficient
229 because most cases are calls to gen_sequence followed by immediately
230 emitting the SEQUENCE. Reuse is safe since emitting a sequence is
231 destructive on the insn in it anyway and hence can't be redone.
233 We do not bother to save this cached data over nested function calls.
234 Instead, we just reinitialize them. */
236 #define SEQUENCE_RESULT_SIZE 5
238 static struct sequence_stack *sequence_element_free_list;
239 static rtx sequence_result[SEQUENCE_RESULT_SIZE];
241 extern int rtx_equal_function_value_matters;
243 /* Filename and line number of last line-number note,
244 whether we actually emitted it or not. */
245 extern char *emit_filename;
246 extern int emit_lineno;
248 rtx change_address ();
249 void init_emit ();
251 extern struct obstack *rtl_obstack;
253 extern int stack_depth;
254 extern int max_stack_depth;
256 /* rtx gen_rtx (code, mode, [element1, ..., elementn])
258 ** This routine generates an RTX of the size specified by
259 ** <code>, which is an RTX code. The RTX structure is initialized
260 ** from the arguments <element1> through <elementn>, which are
261 ** interpreted according to the specific RTX type's format. The
262 ** special machine mode associated with the rtx (if any) is specified
263 ** in <mode>.
265 ** gen_rtx can be invoked in a way which resembles the lisp-like
266 ** rtx it will generate. For example, the following rtx structure:
268 ** (plus:QI (mem:QI (reg:SI 1))
269 ** (mem:QI (plusw:SI (reg:SI 2) (reg:SI 3))))
271 ** ...would be generated by the following C code:
273 ** gen_rtx (PLUS, QImode,
274 ** gen_rtx (MEM, QImode,
275 ** gen_rtx (REG, SImode, 1)),
276 ** gen_rtx (MEM, QImode,
277 ** gen_rtx (PLUS, SImode,
278 ** gen_rtx (REG, SImode, 2),
279 ** gen_rtx (REG, SImode, 3)))),
282 /*VARARGS2*/
284 gen_rtx VPROTO((enum rtx_code code, enum machine_mode mode, ...))
286 #ifndef __STDC__
287 enum rtx_code code;
288 enum machine_mode mode;
289 #endif
290 va_list p;
291 register int i; /* Array indices... */
292 register char *fmt; /* Current rtx's format... */
293 register rtx rt_val; /* RTX to return to caller... */
295 VA_START (p, mode);
297 #ifndef __STDC__
298 code = va_arg (p, enum rtx_code);
299 mode = va_arg (p, enum machine_mode);
300 #endif
302 if (code == CONST_INT)
304 HOST_WIDE_INT arg = va_arg (p, HOST_WIDE_INT);
306 if (arg >= - MAX_SAVED_CONST_INT && arg <= MAX_SAVED_CONST_INT)
307 return const_int_rtx[arg + MAX_SAVED_CONST_INT];
309 if (const_true_rtx && arg == STORE_FLAG_VALUE)
310 return const_true_rtx;
312 rt_val = rtx_alloc (code);
313 INTVAL (rt_val) = arg;
315 else if (code == REG)
317 int regno = va_arg (p, int);
319 /* In case the MD file explicitly references the frame pointer, have
320 all such references point to the same frame pointer. This is used
321 during frame pointer elimination to distinguish the explicit
322 references to these registers from pseudos that happened to be
323 assigned to them.
325 If we have eliminated the frame pointer or arg pointer, we will
326 be using it as a normal register, for example as a spill register.
327 In such cases, we might be accessing it in a mode that is not
328 Pmode and therefore cannot use the pre-allocated rtx.
330 Also don't do this when we are making new REGs in reload,
331 since we don't want to get confused with the real pointers. */
333 if (frame_pointer_rtx && regno == FRAME_POINTER_REGNUM && mode == Pmode
334 && ! reload_in_progress)
335 return frame_pointer_rtx;
336 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
337 if (hard_frame_pointer_rtx && regno == HARD_FRAME_POINTER_REGNUM
338 && mode == Pmode && ! reload_in_progress)
339 return hard_frame_pointer_rtx;
340 #endif
341 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM && HARD_FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
342 if (arg_pointer_rtx && regno == ARG_POINTER_REGNUM && mode == Pmode
343 && ! reload_in_progress)
344 return arg_pointer_rtx;
345 #endif
346 if (stack_pointer_rtx && regno == STACK_POINTER_REGNUM && mode == Pmode
347 && ! reload_in_progress)
348 return stack_pointer_rtx;
349 else
351 rt_val = rtx_alloc (code);
352 rt_val->mode = mode;
353 REGNO (rt_val) = regno;
354 return rt_val;
357 else
359 rt_val = rtx_alloc (code); /* Allocate the storage space. */
360 rt_val->mode = mode; /* Store the machine mode... */
362 fmt = GET_RTX_FORMAT (code); /* Find the right format... */
363 for (i = 0; i < GET_RTX_LENGTH (code); i++)
365 switch (*fmt++)
367 case '0': /* Unused field. */
368 break;
370 case 'i': /* An integer? */
371 XINT (rt_val, i) = va_arg (p, int);
372 break;
374 case 'w': /* A wide integer? */
375 XWINT (rt_val, i) = va_arg (p, HOST_WIDE_INT);
376 break;
378 case 's': /* A string? */
379 XSTR (rt_val, i) = va_arg (p, char *);
380 break;
382 case 'e': /* An expression? */
383 case 'u': /* An insn? Same except when printing. */
384 XEXP (rt_val, i) = va_arg (p, rtx);
385 break;
387 case 'E': /* An RTX vector? */
388 XVEC (rt_val, i) = va_arg (p, rtvec);
389 break;
391 default:
392 abort ();
396 va_end (p);
397 return rt_val; /* Return the new RTX... */
400 /* gen_rtvec (n, [rt1, ..., rtn])
402 ** This routine creates an rtvec and stores within it the
403 ** pointers to rtx's which are its arguments.
406 /*VARARGS1*/
407 rtvec
408 gen_rtvec VPROTO((int n, ...))
410 #ifndef __STDC__
411 int n;
412 #endif
413 int i;
414 va_list p;
415 rtx *vector;
417 VA_START (p, n);
419 #ifndef __STDC__
420 n = va_arg (p, int);
421 #endif
423 if (n == 0)
424 return NULL_RTVEC; /* Don't allocate an empty rtvec... */
426 vector = (rtx *) alloca (n * sizeof (rtx));
428 for (i = 0; i < n; i++)
429 vector[i] = va_arg (p, rtx);
430 va_end (p);
432 return gen_rtvec_v (n, vector);
435 rtvec
436 gen_rtvec_v (n, argp)
437 int n;
438 rtx *argp;
440 register int i;
441 register rtvec rt_val;
443 if (n == 0)
444 return NULL_RTVEC; /* Don't allocate an empty rtvec... */
446 rt_val = rtvec_alloc (n); /* Allocate an rtvec... */
448 for (i = 0; i < n; i++)
449 rt_val->elem[i].rtx = *argp++;
451 return rt_val;
454 /* Generate a REG rtx for a new pseudo register of mode MODE.
455 This pseudo is assigned the next sequential register number. */
458 gen_reg_rtx (mode)
459 enum machine_mode mode;
461 register rtx val;
463 /* Don't let anything called by or after reload create new registers
464 (actually, registers can't be created after flow, but this is a good
465 approximation). */
467 if (reload_in_progress || reload_completed)
468 abort ();
470 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
471 || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
473 /* For complex modes, don't make a single pseudo.
474 Instead, make a CONCAT of two pseudos.
475 This allows noncontiguous allocation of the real and imaginary parts,
476 which makes much better code. Besides, allocating DCmode
477 pseudos overstrains reload on some machines like the 386. */
478 rtx realpart, imagpart;
479 int size = GET_MODE_UNIT_SIZE (mode);
480 enum machine_mode partmode
481 = mode_for_size (size * BITS_PER_UNIT,
482 (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
483 ? MODE_FLOAT : MODE_INT),
486 realpart = gen_reg_rtx (partmode);
487 imagpart = gen_reg_rtx (partmode);
488 return gen_rtx (CONCAT, mode, realpart, imagpart);
491 /* Make sure regno_pointer_flag and regno_reg_rtx are large
492 enough to have an element for this pseudo reg number. */
494 if (reg_rtx_no == regno_pointer_flag_length)
496 rtx *new1;
497 char *new =
498 (char *) oballoc (regno_pointer_flag_length * 2);
499 bcopy (regno_pointer_flag, new, regno_pointer_flag_length);
500 bzero (&new[regno_pointer_flag_length], regno_pointer_flag_length);
501 regno_pointer_flag = new;
503 new1 = (rtx *) oballoc (regno_pointer_flag_length * 2 * sizeof (rtx));
504 bcopy ((char *) regno_reg_rtx, (char *) new1,
505 regno_pointer_flag_length * sizeof (rtx));
506 bzero ((char *) &new1[regno_pointer_flag_length],
507 regno_pointer_flag_length * sizeof (rtx));
508 regno_reg_rtx = new1;
510 regno_pointer_flag_length *= 2;
513 val = gen_rtx (REG, mode, reg_rtx_no);
514 regno_reg_rtx[reg_rtx_no++] = val;
515 return val;
518 /* Identify REG as a probable pointer register. */
520 void
521 mark_reg_pointer (reg)
522 rtx reg;
524 REGNO_POINTER_FLAG (REGNO (reg)) = 1;
527 /* Return 1 plus largest pseudo reg number used in the current function. */
530 max_reg_num ()
532 return reg_rtx_no;
535 /* Return 1 + the largest label number used so far in the current function. */
538 max_label_num ()
540 if (last_label_num && label_num == base_label_num)
541 return last_label_num;
542 return label_num;
545 /* Return first label number used in this function (if any were used). */
548 get_first_label_num ()
550 return first_label_num;
553 /* Return a value representing some low-order bits of X, where the number
554 of low-order bits is given by MODE. Note that no conversion is done
555 between floating-point and fixed-point values, rather, the bit
556 representation is returned.
558 This function handles the cases in common between gen_lowpart, below,
559 and two variants in cse.c and combine.c. These are the cases that can
560 be safely handled at all points in the compilation.
562 If this is not a case we can handle, return 0. */
565 gen_lowpart_common (mode, x)
566 enum machine_mode mode;
567 register rtx x;
569 int word = 0;
571 if (GET_MODE (x) == mode)
572 return x;
574 /* MODE must occupy no more words than the mode of X. */
575 if (GET_MODE (x) != VOIDmode
576 && ((GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD
577 > ((GET_MODE_SIZE (GET_MODE (x)) + (UNITS_PER_WORD - 1))
578 / UNITS_PER_WORD)))
579 return 0;
581 if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
582 word = ((GET_MODE_SIZE (GET_MODE (x))
583 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD))
584 / UNITS_PER_WORD);
586 if ((GET_CODE (x) == ZERO_EXTEND || GET_CODE (x) == SIGN_EXTEND)
587 && (GET_MODE_CLASS (mode) == MODE_INT
588 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT))
590 /* If we are getting the low-order part of something that has been
591 sign- or zero-extended, we can either just use the object being
592 extended or make a narrower extension. If we want an even smaller
593 piece than the size of the object being extended, call ourselves
594 recursively.
596 This case is used mostly by combine and cse. */
598 if (GET_MODE (XEXP (x, 0)) == mode)
599 return XEXP (x, 0);
600 else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (XEXP (x, 0))))
601 return gen_lowpart_common (mode, XEXP (x, 0));
602 else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (x)))
603 return gen_rtx (GET_CODE (x), mode, XEXP (x, 0));
605 else if (GET_CODE (x) == SUBREG
606 && (GET_MODE_SIZE (mode) <= UNITS_PER_WORD
607 || GET_MODE_SIZE (mode) == GET_MODE_UNIT_SIZE (GET_MODE (x))))
608 return (GET_MODE (SUBREG_REG (x)) == mode && SUBREG_WORD (x) == 0
609 ? SUBREG_REG (x)
610 : gen_rtx (SUBREG, mode, SUBREG_REG (x), SUBREG_WORD (x)));
611 else if (GET_CODE (x) == REG)
613 /* If the register is not valid for MODE, return 0. If we don't
614 do this, there is no way to fix up the resulting REG later.
615 But we do do this if the current REG is not valid for its
616 mode. This latter is a kludge, but is required due to the
617 way that parameters are passed on some machines, most
618 notably Sparc. */
619 if (REGNO (x) < FIRST_PSEUDO_REGISTER
620 && ! HARD_REGNO_MODE_OK (REGNO (x) + word, mode)
621 && HARD_REGNO_MODE_OK (REGNO (x), GET_MODE (x)))
622 return 0;
623 else if (REGNO (x) < FIRST_PSEUDO_REGISTER
624 /* integrate.c can't handle parts of a return value register. */
625 && (! REG_FUNCTION_VALUE_P (x)
626 || ! rtx_equal_function_value_matters)
627 /* We want to keep the stack, frame, and arg pointers
628 special. */
629 && x != frame_pointer_rtx
630 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
631 && x != arg_pointer_rtx
632 #endif
633 && x != stack_pointer_rtx)
634 return gen_rtx (REG, mode, REGNO (x) + word);
635 else
636 return gen_rtx (SUBREG, mode, x, word);
638 /* If X is a CONST_INT or a CONST_DOUBLE, extract the appropriate bits
639 from the low-order part of the constant. */
640 else if ((GET_MODE_CLASS (mode) == MODE_INT
641 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
642 && GET_MODE (x) == VOIDmode
643 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
645 /* If MODE is twice the host word size, X is already the desired
646 representation. Otherwise, if MODE is wider than a word, we can't
647 do this. If MODE is exactly a word, return just one CONST_INT.
648 If MODE is smaller than a word, clear the bits that don't belong
649 in our mode, unless they and our sign bit are all one. So we get
650 either a reasonable negative value or a reasonable unsigned value
651 for this mode. */
653 if (GET_MODE_BITSIZE (mode) == 2 * HOST_BITS_PER_WIDE_INT)
654 return x;
655 else if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
656 return 0;
657 else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
658 return (GET_CODE (x) == CONST_INT ? x
659 : GEN_INT (CONST_DOUBLE_LOW (x)));
660 else
662 /* MODE must be narrower than HOST_BITS_PER_INT. */
663 int width = GET_MODE_BITSIZE (mode);
664 HOST_WIDE_INT val = (GET_CODE (x) == CONST_INT ? INTVAL (x)
665 : CONST_DOUBLE_LOW (x));
667 if (((val & ((HOST_WIDE_INT) (-1) << (width - 1)))
668 != ((HOST_WIDE_INT) (-1) << (width - 1))))
669 val &= ((HOST_WIDE_INT) 1 << width) - 1;
671 return (GET_CODE (x) == CONST_INT && INTVAL (x) == val ? x
672 : GEN_INT (val));
676 /* If X is an integral constant but we want it in floating-point, it
677 must be the case that we have a union of an integer and a floating-point
678 value. If the machine-parameters allow it, simulate that union here
679 and return the result. The two-word and single-word cases are
680 different. */
682 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
683 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
684 || flag_pretend_float)
685 && GET_MODE_CLASS (mode) == MODE_FLOAT
686 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
687 && GET_CODE (x) == CONST_INT
688 && sizeof (float) * HOST_BITS_PER_CHAR == HOST_BITS_PER_WIDE_INT)
689 #ifdef REAL_ARITHMETIC
691 REAL_VALUE_TYPE r;
692 HOST_WIDE_INT i;
694 i = INTVAL (x);
695 r = REAL_VALUE_FROM_TARGET_SINGLE (i);
696 return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
698 #else
700 union {HOST_WIDE_INT i; float d; } u;
702 u.i = INTVAL (x);
703 return CONST_DOUBLE_FROM_REAL_VALUE (u.d, mode);
705 #endif
706 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
707 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
708 || flag_pretend_float)
709 && GET_MODE_CLASS (mode) == MODE_FLOAT
710 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
711 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
712 && GET_MODE (x) == VOIDmode
713 && (sizeof (double) * HOST_BITS_PER_CHAR
714 == 2 * HOST_BITS_PER_WIDE_INT))
715 #ifdef REAL_ARITHMETIC
717 REAL_VALUE_TYPE r;
718 HOST_WIDE_INT i[2];
719 HOST_WIDE_INT low, high;
721 if (GET_CODE (x) == CONST_INT)
722 low = INTVAL (x), high = low >> (HOST_BITS_PER_WIDE_INT -1);
723 else
724 low = CONST_DOUBLE_LOW (x), high = CONST_DOUBLE_HIGH (x);
726 /* REAL_VALUE_TARGET_DOUBLE takes the addressing order of the
727 target machine. */
728 if (WORDS_BIG_ENDIAN)
729 i[0] = high, i[1] = low;
730 else
731 i[0] = low, i[1] = high;
733 r = REAL_VALUE_FROM_TARGET_DOUBLE (i);
734 return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
736 #else
738 union {HOST_WIDE_INT i[2]; double d; } u;
739 HOST_WIDE_INT low, high;
741 if (GET_CODE (x) == CONST_INT)
742 low = INTVAL (x), high = low >> (HOST_BITS_PER_WIDE_INT -1);
743 else
744 low = CONST_DOUBLE_LOW (x), high = CONST_DOUBLE_HIGH (x);
746 #ifdef HOST_WORDS_BIG_ENDIAN
747 u.i[0] = high, u.i[1] = low;
748 #else
749 u.i[0] = low, u.i[1] = high;
750 #endif
752 return CONST_DOUBLE_FROM_REAL_VALUE (u.d, mode);
754 #endif
755 /* Similarly, if this is converting a floating-point value into a
756 single-word integer. Only do this is the host and target parameters are
757 compatible. */
759 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
760 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
761 || flag_pretend_float)
762 && (GET_MODE_CLASS (mode) == MODE_INT
763 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
764 && GET_CODE (x) == CONST_DOUBLE
765 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT
766 && GET_MODE_BITSIZE (mode) == BITS_PER_WORD)
767 return operand_subword (x, 0, 0, GET_MODE (x));
769 /* Similarly, if this is converting a floating-point value into a
770 two-word integer, we can do this one word at a time and make an
771 integer. Only do this is the host and target parameters are
772 compatible. */
774 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
775 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
776 || flag_pretend_float)
777 && (GET_MODE_CLASS (mode) == MODE_INT
778 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
779 && GET_CODE (x) == CONST_DOUBLE
780 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT
781 && GET_MODE_BITSIZE (mode) == 2 * BITS_PER_WORD)
783 rtx lowpart = operand_subword (x, WORDS_BIG_ENDIAN, 0, GET_MODE (x));
784 rtx highpart = operand_subword (x, ! WORDS_BIG_ENDIAN, 0, GET_MODE (x));
786 if (lowpart && GET_CODE (lowpart) == CONST_INT
787 && highpart && GET_CODE (highpart) == CONST_INT)
788 return immed_double_const (INTVAL (lowpart), INTVAL (highpart), mode);
791 /* Otherwise, we can't do this. */
792 return 0;
795 /* Return the real part (which has mode MODE) of a complex value X.
796 This always comes at the low address in memory. */
799 gen_realpart (mode, x)
800 enum machine_mode mode;
801 register rtx x;
803 if (GET_CODE (x) == CONCAT && GET_MODE (XEXP (x, 0)) == mode)
804 return XEXP (x, 0);
805 else if (WORDS_BIG_ENDIAN)
806 return gen_highpart (mode, x);
807 else
808 return gen_lowpart (mode, x);
811 /* Return the imaginary part (which has mode MODE) of a complex value X.
812 This always comes at the high address in memory. */
815 gen_imagpart (mode, x)
816 enum machine_mode mode;
817 register rtx x;
819 if (GET_CODE (x) == CONCAT && GET_MODE (XEXP (x, 0)) == mode)
820 return XEXP (x, 1);
821 else if (WORDS_BIG_ENDIAN)
822 return gen_lowpart (mode, x);
823 else
824 return gen_highpart (mode, x);
827 /* Return 1 iff X, assumed to be a SUBREG,
828 refers to the real part of the complex value in its containing reg.
829 Complex values are always stored with the real part in the first word,
830 regardless of WORDS_BIG_ENDIAN. */
833 subreg_realpart_p (x)
834 rtx x;
836 if (GET_CODE (x) != SUBREG)
837 abort ();
839 return SUBREG_WORD (x) == 0;
842 /* Assuming that X is an rtx (e.g., MEM, REG or SUBREG) for a value,
843 return an rtx (MEM, SUBREG, or CONST_INT) that refers to the
844 least-significant part of X.
845 MODE specifies how big a part of X to return;
846 it usually should not be larger than a word.
847 If X is a MEM whose address is a QUEUED, the value may be so also. */
850 gen_lowpart (mode, x)
851 enum machine_mode mode;
852 register rtx x;
854 rtx result = gen_lowpart_common (mode, x);
856 if (result)
857 return result;
858 else if (GET_CODE (x) == MEM)
860 /* The only additional case we can do is MEM. */
861 register int offset = 0;
862 if (WORDS_BIG_ENDIAN)
863 offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
864 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
866 if (BYTES_BIG_ENDIAN)
867 /* Adjust the address so that the address-after-the-data
868 is unchanged. */
869 offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))
870 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
872 return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
874 else
875 abort ();
878 /* Like `gen_lowpart', but refer to the most significant part.
879 This is used to access the imaginary part of a complex number. */
882 gen_highpart (mode, x)
883 enum machine_mode mode;
884 register rtx x;
886 /* This case loses if X is a subreg. To catch bugs early,
887 complain if an invalid MODE is used even in other cases. */
888 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
889 && GET_MODE_SIZE (mode) != GET_MODE_UNIT_SIZE (GET_MODE (x)))
890 abort ();
891 if (GET_CODE (x) == CONST_DOUBLE
892 #if !(TARGET_FLOAT_FORMAT != HOST_FLOAT_FORMAT || defined (REAL_IS_NOT_DOUBLE))
893 && GET_MODE_CLASS (GET_MODE (x)) != MODE_FLOAT
894 #endif
896 return gen_rtx (CONST_INT, VOIDmode,
897 CONST_DOUBLE_HIGH (x) & GET_MODE_MASK (mode));
898 else if (GET_CODE (x) == CONST_INT)
899 return const0_rtx;
900 else if (GET_CODE (x) == MEM)
902 register int offset = 0;
903 if (! WORDS_BIG_ENDIAN)
904 offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
905 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
907 if (! BYTES_BIG_ENDIAN
908 && GET_MODE_SIZE (mode) < UNITS_PER_WORD)
909 offset -= (GET_MODE_SIZE (mode)
910 - MIN (UNITS_PER_WORD,
911 GET_MODE_SIZE (GET_MODE (x))));
913 return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
915 else if (GET_CODE (x) == SUBREG)
917 /* The only time this should occur is when we are looking at a
918 multi-word item with a SUBREG whose mode is the same as that of the
919 item. It isn't clear what we would do if it wasn't. */
920 if (SUBREG_WORD (x) != 0)
921 abort ();
922 return gen_highpart (mode, SUBREG_REG (x));
924 else if (GET_CODE (x) == REG)
926 int word = 0;
928 if (! WORDS_BIG_ENDIAN
929 && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
930 word = ((GET_MODE_SIZE (GET_MODE (x))
931 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD))
932 / UNITS_PER_WORD);
934 if (REGNO (x) < FIRST_PSEUDO_REGISTER
935 /* integrate.c can't handle parts of a return value register. */
936 && (! REG_FUNCTION_VALUE_P (x)
937 || ! rtx_equal_function_value_matters)
938 /* We want to keep the stack, frame, and arg pointers special. */
939 && x != frame_pointer_rtx
940 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
941 && x != arg_pointer_rtx
942 #endif
943 && x != stack_pointer_rtx)
944 return gen_rtx (REG, mode, REGNO (x) + word);
945 else
946 return gen_rtx (SUBREG, mode, x, word);
948 else
949 abort ();
952 /* Return 1 iff X, assumed to be a SUBREG,
953 refers to the least significant part of its containing reg.
954 If X is not a SUBREG, always return 1 (it is its own low part!). */
957 subreg_lowpart_p (x)
958 rtx x;
960 if (GET_CODE (x) != SUBREG)
961 return 1;
963 if (WORDS_BIG_ENDIAN
964 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) > UNITS_PER_WORD)
965 return (SUBREG_WORD (x)
966 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
967 - MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD))
968 / UNITS_PER_WORD));
970 return SUBREG_WORD (x) == 0;
973 /* Return subword I of operand OP.
974 The word number, I, is interpreted as the word number starting at the
975 low-order address. Word 0 is the low-order word if not WORDS_BIG_ENDIAN,
976 otherwise it is the high-order word.
978 If we cannot extract the required word, we return zero. Otherwise, an
979 rtx corresponding to the requested word will be returned.
981 VALIDATE_ADDRESS is nonzero if the address should be validated. Before
982 reload has completed, a valid address will always be returned. After
983 reload, if a valid address cannot be returned, we return zero.
985 If VALIDATE_ADDRESS is zero, we simply form the required address; validating
986 it is the responsibility of the caller.
988 MODE is the mode of OP in case it is a CONST_INT. */
991 operand_subword (op, i, validate_address, mode)
992 rtx op;
993 int i;
994 int validate_address;
995 enum machine_mode mode;
997 HOST_WIDE_INT val;
998 int size_ratio = HOST_BITS_PER_WIDE_INT / BITS_PER_WORD;
1000 if (mode == VOIDmode)
1001 mode = GET_MODE (op);
1003 if (mode == VOIDmode)
1004 abort ();
1006 /* If OP is narrower than a word or if we want a word outside OP, fail. */
1007 if (mode != BLKmode
1008 && (GET_MODE_SIZE (mode) < UNITS_PER_WORD
1009 || (i + 1) * UNITS_PER_WORD > GET_MODE_SIZE (mode)))
1010 return 0;
1012 /* If OP is already an integer word, return it. */
1013 if (GET_MODE_CLASS (mode) == MODE_INT
1014 && GET_MODE_SIZE (mode) == UNITS_PER_WORD)
1015 return op;
1017 /* If OP is a REG or SUBREG, we can handle it very simply. */
1018 if (GET_CODE (op) == REG)
1020 /* If the register is not valid for MODE, return 0. If we don't
1021 do this, there is no way to fix up the resulting REG later. */
1022 if (REGNO (op) < FIRST_PSEUDO_REGISTER
1023 && ! HARD_REGNO_MODE_OK (REGNO (op) + i, word_mode))
1024 return 0;
1025 else if (REGNO (op) >= FIRST_PSEUDO_REGISTER
1026 || (REG_FUNCTION_VALUE_P (op)
1027 && rtx_equal_function_value_matters)
1028 /* We want to keep the stack, frame, and arg pointers
1029 special. */
1030 || op == frame_pointer_rtx
1031 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1032 || op == arg_pointer_rtx
1033 #endif
1034 || op == stack_pointer_rtx)
1035 return gen_rtx (SUBREG, word_mode, op, i);
1036 else
1037 return gen_rtx (REG, word_mode, REGNO (op) + i);
1039 else if (GET_CODE (op) == SUBREG)
1040 return gen_rtx (SUBREG, word_mode, SUBREG_REG (op), i + SUBREG_WORD (op));
1041 else if (GET_CODE (op) == CONCAT)
1043 int partwords = GET_MODE_UNIT_SIZE (GET_MODE (op)) / UNITS_PER_WORD;
1044 if (i < partwords)
1045 return operand_subword (XEXP (op, 0), i, validate_address, mode);
1046 return operand_subword (XEXP (op, 1), i - partwords,
1047 validate_address, mode);
1050 /* Form a new MEM at the requested address. */
1051 if (GET_CODE (op) == MEM)
1053 rtx addr = plus_constant (XEXP (op, 0), i * UNITS_PER_WORD);
1054 rtx new;
1056 if (validate_address)
1058 if (reload_completed)
1060 if (! strict_memory_address_p (word_mode, addr))
1061 return 0;
1063 else
1064 addr = memory_address (word_mode, addr);
1067 new = gen_rtx (MEM, word_mode, addr);
1069 MEM_VOLATILE_P (new) = MEM_VOLATILE_P (op);
1070 MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (op);
1071 RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (op);
1073 return new;
1076 /* The only remaining cases are when OP is a constant. If the host and
1077 target floating formats are the same, handling two-word floating
1078 constants are easy. Note that REAL_VALUE_TO_TARGET_{SINGLE,DOUBLE}
1079 are defined as returning one or two 32 bit values, respectively,
1080 and not values of BITS_PER_WORD bits. */
1081 #ifdef REAL_ARITHMETIC
1082 /* The output is some bits, the width of the target machine's word.
1083 A wider-word host can surely hold them in a CONST_INT. A narrower-word
1084 host can't. */
1085 if (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
1086 && GET_MODE_CLASS (mode) == MODE_FLOAT
1087 && GET_MODE_BITSIZE (mode) == 64
1088 && GET_CODE (op) == CONST_DOUBLE)
1090 long k[2];
1091 REAL_VALUE_TYPE rv;
1093 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1094 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
1096 /* We handle 32-bit and >= 64-bit words here. Note that the order in
1097 which the words are written depends on the word endianness.
1099 ??? This is a potential portability problem and should
1100 be fixed at some point. */
1101 if (BITS_PER_WORD == 32)
1102 return GEN_INT ((HOST_WIDE_INT) k[i]);
1103 #if HOST_BITS_PER_WIDE_INT > 32
1104 else if (BITS_PER_WORD >= 64 && i == 0)
1105 return GEN_INT ((((HOST_WIDE_INT) k[! WORDS_BIG_ENDIAN]) << 32)
1106 | (HOST_WIDE_INT) k[WORDS_BIG_ENDIAN]);
1107 #endif
1108 else
1109 abort ();
1111 #else /* no REAL_ARITHMETIC */
1112 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1113 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1114 || flag_pretend_float)
1115 && GET_MODE_CLASS (mode) == MODE_FLOAT
1116 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
1117 && GET_CODE (op) == CONST_DOUBLE)
1119 /* The constant is stored in the host's word-ordering,
1120 but we want to access it in the target's word-ordering. Some
1121 compilers don't like a conditional inside macro args, so we have two
1122 copies of the return. */
1123 #ifdef HOST_WORDS_BIG_ENDIAN
1124 return GEN_INT (i == WORDS_BIG_ENDIAN
1125 ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
1126 #else
1127 return GEN_INT (i != WORDS_BIG_ENDIAN
1128 ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
1129 #endif
1131 #endif /* no REAL_ARITHMETIC */
1133 /* Single word float is a little harder, since single- and double-word
1134 values often do not have the same high-order bits. We have already
1135 verified that we want the only defined word of the single-word value. */
1136 #ifdef REAL_ARITHMETIC
1137 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1138 && GET_MODE_BITSIZE (mode) == 32
1139 && GET_CODE (op) == CONST_DOUBLE)
1141 long l;
1142 REAL_VALUE_TYPE rv;
1144 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1145 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
1146 return GEN_INT ((HOST_WIDE_INT) l);
1148 #else
1149 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1150 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1151 || flag_pretend_float)
1152 && GET_MODE_CLASS (mode) == MODE_FLOAT
1153 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
1154 && GET_CODE (op) == CONST_DOUBLE)
1156 double d;
1157 union {float f; HOST_WIDE_INT i; } u;
1159 REAL_VALUE_FROM_CONST_DOUBLE (d, op);
1161 u.f = d;
1162 return GEN_INT (u.i);
1164 #endif /* no REAL_ARITHMETIC */
1166 /* The only remaining cases that we can handle are integers.
1167 Convert to proper endianness now since these cases need it.
1168 At this point, i == 0 means the low-order word.
1170 We do not want to handle the case when BITS_PER_WORD <= HOST_BITS_PER_INT
1171 in general. However, if OP is (const_int 0), we can just return
1172 it for any word. */
1174 if (op == const0_rtx)
1175 return op;
1177 if (GET_MODE_CLASS (mode) != MODE_INT
1178 || (GET_CODE (op) != CONST_INT && GET_CODE (op) != CONST_DOUBLE)
1179 || BITS_PER_WORD > HOST_BITS_PER_INT)
1180 return 0;
1182 if (WORDS_BIG_ENDIAN)
1183 i = GET_MODE_SIZE (mode) / UNITS_PER_WORD - 1 - i;
1185 /* Find out which word on the host machine this value is in and get
1186 it from the constant. */
1187 val = (i / size_ratio == 0
1188 ? (GET_CODE (op) == CONST_INT ? INTVAL (op) : CONST_DOUBLE_LOW (op))
1189 : (GET_CODE (op) == CONST_INT
1190 ? (INTVAL (op) < 0 ? ~0 : 0) : CONST_DOUBLE_HIGH (op)));
1192 /* If BITS_PER_WORD is smaller than an int, get the appropriate bits. */
1193 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT)
1194 val = ((val >> ((i % size_ratio) * BITS_PER_WORD))
1195 & (((HOST_WIDE_INT) 1
1196 << (BITS_PER_WORD % HOST_BITS_PER_WIDE_INT)) - 1));
1198 return GEN_INT (val);
1201 /* Similar to `operand_subword', but never return 0. If we can't extract
1202 the required subword, put OP into a register and try again. If that fails,
1203 abort. We always validate the address in this case. It is not valid
1204 to call this function after reload; it is mostly meant for RTL
1205 generation.
1207 MODE is the mode of OP, in case it is CONST_INT. */
1210 operand_subword_force (op, i, mode)
1211 rtx op;
1212 int i;
1213 enum machine_mode mode;
1215 rtx result = operand_subword (op, i, 1, mode);
1217 if (result)
1218 return result;
1220 if (mode != BLKmode && mode != VOIDmode)
1221 op = force_reg (mode, op);
1223 result = operand_subword (op, i, 1, mode);
1224 if (result == 0)
1225 abort ();
1227 return result;
1230 /* Given a compare instruction, swap the operands.
1231 A test instruction is changed into a compare of 0 against the operand. */
1233 void
1234 reverse_comparison (insn)
1235 rtx insn;
1237 rtx body = PATTERN (insn);
1238 rtx comp;
1240 if (GET_CODE (body) == SET)
1241 comp = SET_SRC (body);
1242 else
1243 comp = SET_SRC (XVECEXP (body, 0, 0));
1245 if (GET_CODE (comp) == COMPARE)
1247 rtx op0 = XEXP (comp, 0);
1248 rtx op1 = XEXP (comp, 1);
1249 XEXP (comp, 0) = op1;
1250 XEXP (comp, 1) = op0;
1252 else
1254 rtx new = gen_rtx (COMPARE, VOIDmode,
1255 CONST0_RTX (GET_MODE (comp)), comp);
1256 if (GET_CODE (body) == SET)
1257 SET_SRC (body) = new;
1258 else
1259 SET_SRC (XVECEXP (body, 0, 0)) = new;
1263 /* Return a memory reference like MEMREF, but with its mode changed
1264 to MODE and its address changed to ADDR.
1265 (VOIDmode means don't change the mode.
1266 NULL for ADDR means don't change the address.) */
1269 change_address (memref, mode, addr)
1270 rtx memref;
1271 enum machine_mode mode;
1272 rtx addr;
1274 rtx new;
1276 if (GET_CODE (memref) != MEM)
1277 abort ();
1278 if (mode == VOIDmode)
1279 mode = GET_MODE (memref);
1280 if (addr == 0)
1281 addr = XEXP (memref, 0);
1283 /* If reload is in progress or has completed, ADDR must be valid.
1284 Otherwise, we can call memory_address to make it valid. */
1285 if (reload_completed || reload_in_progress)
1287 if (! memory_address_p (mode, addr))
1288 abort ();
1290 else
1291 addr = memory_address (mode, addr);
1293 new = gen_rtx (MEM, mode, addr);
1294 MEM_VOLATILE_P (new) = MEM_VOLATILE_P (memref);
1295 RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (memref);
1296 MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (memref);
1297 return new;
1300 /* Return a newly created CODE_LABEL rtx with a unique label number. */
1303 gen_label_rtx ()
1305 register rtx label;
1307 label = (output_bytecode
1308 ? gen_rtx (CODE_LABEL, VOIDmode, NULL, bc_get_bytecode_label ())
1309 : gen_rtx (CODE_LABEL, VOIDmode, 0, 0, 0, label_num++, NULL_PTR));
1311 LABEL_NUSES (label) = 0;
1312 return label;
1315 /* For procedure integration. */
1317 /* Return a newly created INLINE_HEADER rtx. Should allocate this
1318 from a permanent obstack when the opportunity arises. */
1321 gen_inline_header_rtx (first_insn, first_parm_insn, first_labelno,
1322 last_labelno, max_parm_regnum, max_regnum, args_size,
1323 pops_args, stack_slots, function_flags,
1324 outgoing_args_size, original_arg_vector,
1325 original_decl_initial)
1326 rtx first_insn, first_parm_insn;
1327 int first_labelno, last_labelno, max_parm_regnum, max_regnum, args_size;
1328 int pops_args;
1329 rtx stack_slots;
1330 int function_flags;
1331 int outgoing_args_size;
1332 rtvec original_arg_vector;
1333 rtx original_decl_initial;
1335 rtx header = gen_rtx (INLINE_HEADER, VOIDmode,
1336 cur_insn_uid++, NULL_RTX,
1337 first_insn, first_parm_insn,
1338 first_labelno, last_labelno,
1339 max_parm_regnum, max_regnum, args_size, pops_args,
1340 stack_slots, function_flags, outgoing_args_size,
1341 original_arg_vector, original_decl_initial);
1342 return header;
1345 /* Install new pointers to the first and last insns in the chain.
1346 Used for an inline-procedure after copying the insn chain. */
1348 void
1349 set_new_first_and_last_insn (first, last)
1350 rtx first, last;
1352 first_insn = first;
1353 last_insn = last;
1356 /* Set the range of label numbers found in the current function.
1357 This is used when belatedly compiling an inline function. */
1359 void
1360 set_new_first_and_last_label_num (first, last)
1361 int first, last;
1363 base_label_num = label_num;
1364 first_label_num = first;
1365 last_label_num = last;
1368 /* Save all variables describing the current status into the structure *P.
1369 This is used before starting a nested function. */
1371 void
1372 save_emit_status (p)
1373 struct function *p;
1375 p->reg_rtx_no = reg_rtx_no;
1376 p->first_label_num = first_label_num;
1377 p->first_insn = first_insn;
1378 p->last_insn = last_insn;
1379 p->sequence_rtl_expr = sequence_rtl_expr;
1380 p->sequence_stack = sequence_stack;
1381 p->cur_insn_uid = cur_insn_uid;
1382 p->last_linenum = last_linenum;
1383 p->last_filename = last_filename;
1384 p->regno_pointer_flag = regno_pointer_flag;
1385 p->regno_pointer_flag_length = regno_pointer_flag_length;
1386 p->regno_reg_rtx = regno_reg_rtx;
1389 /* Restore all variables describing the current status from the structure *P.
1390 This is used after a nested function. */
1392 void
1393 restore_emit_status (p)
1394 struct function *p;
1396 int i;
1398 reg_rtx_no = p->reg_rtx_no;
1399 first_label_num = p->first_label_num;
1400 last_label_num = 0;
1401 first_insn = p->first_insn;
1402 last_insn = p->last_insn;
1403 sequence_rtl_expr = p->sequence_rtl_expr;
1404 sequence_stack = p->sequence_stack;
1405 cur_insn_uid = p->cur_insn_uid;
1406 last_linenum = p->last_linenum;
1407 last_filename = p->last_filename;
1408 regno_pointer_flag = p->regno_pointer_flag;
1409 regno_pointer_flag_length = p->regno_pointer_flag_length;
1410 regno_reg_rtx = p->regno_reg_rtx;
1412 /* Clear our cache of rtx expressions for start_sequence and gen_sequence. */
1413 sequence_element_free_list = 0;
1414 for (i = 0; i < SEQUENCE_RESULT_SIZE; i++)
1415 sequence_result[i] = 0;
1418 /* Go through all the RTL insn bodies and copy any invalid shared structure.
1419 It does not work to do this twice, because the mark bits set here
1420 are not cleared afterwards. */
1422 void
1423 unshare_all_rtl (insn)
1424 register rtx insn;
1426 for (; insn; insn = NEXT_INSN (insn))
1427 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
1428 || GET_CODE (insn) == CALL_INSN)
1430 PATTERN (insn) = copy_rtx_if_shared (PATTERN (insn));
1431 REG_NOTES (insn) = copy_rtx_if_shared (REG_NOTES (insn));
1432 LOG_LINKS (insn) = copy_rtx_if_shared (LOG_LINKS (insn));
1435 /* Make sure the addresses of stack slots found outside the insn chain
1436 (such as, in DECL_RTL of a variable) are not shared
1437 with the insn chain.
1439 This special care is necessary when the stack slot MEM does not
1440 actually appear in the insn chain. If it does appear, its address
1441 is unshared from all else at that point. */
1443 copy_rtx_if_shared (stack_slot_list);
1446 /* Mark ORIG as in use, and return a copy of it if it was already in use.
1447 Recursively does the same for subexpressions. */
1450 copy_rtx_if_shared (orig)
1451 rtx orig;
1453 register rtx x = orig;
1454 register int i;
1455 register enum rtx_code code;
1456 register char *format_ptr;
1457 int copied = 0;
1459 if (x == 0)
1460 return 0;
1462 code = GET_CODE (x);
1464 /* These types may be freely shared. */
1466 switch (code)
1468 case REG:
1469 case QUEUED:
1470 case CONST_INT:
1471 case CONST_DOUBLE:
1472 case SYMBOL_REF:
1473 case CODE_LABEL:
1474 case PC:
1475 case CC0:
1476 case SCRATCH:
1477 /* SCRATCH must be shared because they represent distinct values. */
1478 return x;
1480 case CONST:
1481 /* CONST can be shared if it contains a SYMBOL_REF. If it contains
1482 a LABEL_REF, it isn't sharable. */
1483 if (GET_CODE (XEXP (x, 0)) == PLUS
1484 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
1485 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
1486 return x;
1487 break;
1489 case INSN:
1490 case JUMP_INSN:
1491 case CALL_INSN:
1492 case NOTE:
1493 case BARRIER:
1494 /* The chain of insns is not being copied. */
1495 return x;
1497 case MEM:
1498 /* A MEM is allowed to be shared if its address is constant
1499 or is a constant plus one of the special registers. */
1500 if (CONSTANT_ADDRESS_P (XEXP (x, 0))
1501 || XEXP (x, 0) == virtual_stack_vars_rtx
1502 || XEXP (x, 0) == virtual_incoming_args_rtx)
1503 return x;
1505 if (GET_CODE (XEXP (x, 0)) == PLUS
1506 && (XEXP (XEXP (x, 0), 0) == virtual_stack_vars_rtx
1507 || XEXP (XEXP (x, 0), 0) == virtual_incoming_args_rtx)
1508 && CONSTANT_ADDRESS_P (XEXP (XEXP (x, 0), 1)))
1510 /* This MEM can appear in more than one place,
1511 but its address better not be shared with anything else. */
1512 if (! x->used)
1513 XEXP (x, 0) = copy_rtx_if_shared (XEXP (x, 0));
1514 x->used = 1;
1515 return x;
1519 /* This rtx may not be shared. If it has already been seen,
1520 replace it with a copy of itself. */
1522 if (x->used)
1524 register rtx copy;
1526 copy = rtx_alloc (code);
1527 bcopy ((char *) x, (char *) copy,
1528 (sizeof (*copy) - sizeof (copy->fld)
1529 + sizeof (copy->fld[0]) * GET_RTX_LENGTH (code)));
1530 x = copy;
1531 copied = 1;
1533 x->used = 1;
1535 /* Now scan the subexpressions recursively.
1536 We can store any replaced subexpressions directly into X
1537 since we know X is not shared! Any vectors in X
1538 must be copied if X was copied. */
1540 format_ptr = GET_RTX_FORMAT (code);
1542 for (i = 0; i < GET_RTX_LENGTH (code); i++)
1544 switch (*format_ptr++)
1546 case 'e':
1547 XEXP (x, i) = copy_rtx_if_shared (XEXP (x, i));
1548 break;
1550 case 'E':
1551 if (XVEC (x, i) != NULL)
1553 register int j;
1554 int len = XVECLEN (x, i);
1556 if (copied && len > 0)
1557 XVEC (x, i) = gen_rtvec_v (len, &XVECEXP (x, i, 0));
1558 for (j = 0; j < len; j++)
1559 XVECEXP (x, i, j) = copy_rtx_if_shared (XVECEXP (x, i, j));
1561 break;
1564 return x;
1567 /* Clear all the USED bits in X to allow copy_rtx_if_shared to be used
1568 to look for shared sub-parts. */
1570 void
1571 reset_used_flags (x)
1572 rtx x;
1574 register int i, j;
1575 register enum rtx_code code;
1576 register char *format_ptr;
1578 if (x == 0)
1579 return;
1581 code = GET_CODE (x);
1583 /* These types may be freely shared so we needn't do any reseting
1584 for them. */
1586 switch (code)
1588 case REG:
1589 case QUEUED:
1590 case CONST_INT:
1591 case CONST_DOUBLE:
1592 case SYMBOL_REF:
1593 case CODE_LABEL:
1594 case PC:
1595 case CC0:
1596 return;
1598 case INSN:
1599 case JUMP_INSN:
1600 case CALL_INSN:
1601 case NOTE:
1602 case LABEL_REF:
1603 case BARRIER:
1604 /* The chain of insns is not being copied. */
1605 return;
1608 x->used = 0;
1610 format_ptr = GET_RTX_FORMAT (code);
1611 for (i = 0; i < GET_RTX_LENGTH (code); i++)
1613 switch (*format_ptr++)
1615 case 'e':
1616 reset_used_flags (XEXP (x, i));
1617 break;
1619 case 'E':
1620 for (j = 0; j < XVECLEN (x, i); j++)
1621 reset_used_flags (XVECEXP (x, i, j));
1622 break;
1627 /* Copy X if necessary so that it won't be altered by changes in OTHER.
1628 Return X or the rtx for the pseudo reg the value of X was copied into.
1629 OTHER must be valid as a SET_DEST. */
1632 make_safe_from (x, other)
1633 rtx x, other;
1635 while (1)
1636 switch (GET_CODE (other))
1638 case SUBREG:
1639 other = SUBREG_REG (other);
1640 break;
1641 case STRICT_LOW_PART:
1642 case SIGN_EXTEND:
1643 case ZERO_EXTEND:
1644 other = XEXP (other, 0);
1645 break;
1646 default:
1647 goto done;
1649 done:
1650 if ((GET_CODE (other) == MEM
1651 && ! CONSTANT_P (x)
1652 && GET_CODE (x) != REG
1653 && GET_CODE (x) != SUBREG)
1654 || (GET_CODE (other) == REG
1655 && (REGNO (other) < FIRST_PSEUDO_REGISTER
1656 || reg_mentioned_p (other, x))))
1658 rtx temp = gen_reg_rtx (GET_MODE (x));
1659 emit_move_insn (temp, x);
1660 return temp;
1662 return x;
1665 /* Emission of insns (adding them to the doubly-linked list). */
1667 /* Return the first insn of the current sequence or current function. */
1670 get_insns ()
1672 return first_insn;
1675 /* Return the last insn emitted in current sequence or current function. */
1678 get_last_insn ()
1680 return last_insn;
1683 /* Specify a new insn as the last in the chain. */
1685 void
1686 set_last_insn (insn)
1687 rtx insn;
1689 if (NEXT_INSN (insn) != 0)
1690 abort ();
1691 last_insn = insn;
1694 /* Return the last insn emitted, even if it is in a sequence now pushed. */
1697 get_last_insn_anywhere ()
1699 struct sequence_stack *stack;
1700 if (last_insn)
1701 return last_insn;
1702 for (stack = sequence_stack; stack; stack = stack->next)
1703 if (stack->last != 0)
1704 return stack->last;
1705 return 0;
1708 /* Return a number larger than any instruction's uid in this function. */
1711 get_max_uid ()
1713 return cur_insn_uid;
1716 /* Return the next insn. If it is a SEQUENCE, return the first insn
1717 of the sequence. */
1720 next_insn (insn)
1721 rtx insn;
1723 if (insn)
1725 insn = NEXT_INSN (insn);
1726 if (insn && GET_CODE (insn) == INSN
1727 && GET_CODE (PATTERN (insn)) == SEQUENCE)
1728 insn = XVECEXP (PATTERN (insn), 0, 0);
1731 return insn;
1734 /* Return the previous insn. If it is a SEQUENCE, return the last insn
1735 of the sequence. */
1738 previous_insn (insn)
1739 rtx insn;
1741 if (insn)
1743 insn = PREV_INSN (insn);
1744 if (insn && GET_CODE (insn) == INSN
1745 && GET_CODE (PATTERN (insn)) == SEQUENCE)
1746 insn = XVECEXP (PATTERN (insn), 0, XVECLEN (PATTERN (insn), 0) - 1);
1749 return insn;
1752 /* Return the next insn after INSN that is not a NOTE. This routine does not
1753 look inside SEQUENCEs. */
1756 next_nonnote_insn (insn)
1757 rtx insn;
1759 while (insn)
1761 insn = NEXT_INSN (insn);
1762 if (insn == 0 || GET_CODE (insn) != NOTE)
1763 break;
1766 return insn;
1769 /* Return the previous insn before INSN that is not a NOTE. This routine does
1770 not look inside SEQUENCEs. */
1773 prev_nonnote_insn (insn)
1774 rtx insn;
1776 while (insn)
1778 insn = PREV_INSN (insn);
1779 if (insn == 0 || GET_CODE (insn) != NOTE)
1780 break;
1783 return insn;
1786 /* Return the next INSN, CALL_INSN or JUMP_INSN after INSN;
1787 or 0, if there is none. This routine does not look inside
1788 SEQUENCEs. */
1791 next_real_insn (insn)
1792 rtx insn;
1794 while (insn)
1796 insn = NEXT_INSN (insn);
1797 if (insn == 0 || GET_CODE (insn) == INSN
1798 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN)
1799 break;
1802 return insn;
1805 /* Return the last INSN, CALL_INSN or JUMP_INSN before INSN;
1806 or 0, if there is none. This routine does not look inside
1807 SEQUENCEs. */
1810 prev_real_insn (insn)
1811 rtx insn;
1813 while (insn)
1815 insn = PREV_INSN (insn);
1816 if (insn == 0 || GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
1817 || GET_CODE (insn) == JUMP_INSN)
1818 break;
1821 return insn;
1824 /* Find the next insn after INSN that really does something. This routine
1825 does not look inside SEQUENCEs. Until reload has completed, this is the
1826 same as next_real_insn. */
1829 next_active_insn (insn)
1830 rtx insn;
1832 while (insn)
1834 insn = NEXT_INSN (insn);
1835 if (insn == 0
1836 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN
1837 || (GET_CODE (insn) == INSN
1838 && (! reload_completed
1839 || (GET_CODE (PATTERN (insn)) != USE
1840 && GET_CODE (PATTERN (insn)) != CLOBBER))))
1841 break;
1844 return insn;
1847 /* Find the last insn before INSN that really does something. This routine
1848 does not look inside SEQUENCEs. Until reload has completed, this is the
1849 same as prev_real_insn. */
1852 prev_active_insn (insn)
1853 rtx insn;
1855 while (insn)
1857 insn = PREV_INSN (insn);
1858 if (insn == 0
1859 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN
1860 || (GET_CODE (insn) == INSN
1861 && (! reload_completed
1862 || (GET_CODE (PATTERN (insn)) != USE
1863 && GET_CODE (PATTERN (insn)) != CLOBBER))))
1864 break;
1867 return insn;
1870 /* Return the next CODE_LABEL after the insn INSN, or 0 if there is none. */
1873 next_label (insn)
1874 rtx insn;
1876 while (insn)
1878 insn = NEXT_INSN (insn);
1879 if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
1880 break;
1883 return insn;
1886 /* Return the last CODE_LABEL before the insn INSN, or 0 if there is none. */
1889 prev_label (insn)
1890 rtx insn;
1892 while (insn)
1894 insn = PREV_INSN (insn);
1895 if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
1896 break;
1899 return insn;
1902 #ifdef HAVE_cc0
1903 /* INSN uses CC0 and is being moved into a delay slot. Set up REG_CC_SETTER
1904 and REG_CC_USER notes so we can find it. */
1906 void
1907 link_cc0_insns (insn)
1908 rtx insn;
1910 rtx user = next_nonnote_insn (insn);
1912 if (GET_CODE (user) == INSN && GET_CODE (PATTERN (user)) == SEQUENCE)
1913 user = XVECEXP (PATTERN (user), 0, 0);
1915 REG_NOTES (user) = gen_rtx (INSN_LIST, REG_CC_SETTER, insn,
1916 REG_NOTES (user));
1917 REG_NOTES (insn) = gen_rtx (INSN_LIST, REG_CC_USER, user, REG_NOTES (insn));
1920 /* Return the next insn that uses CC0 after INSN, which is assumed to
1921 set it. This is the inverse of prev_cc0_setter (i.e., prev_cc0_setter
1922 applied to the result of this function should yield INSN).
1924 Normally, this is simply the next insn. However, if a REG_CC_USER note
1925 is present, it contains the insn that uses CC0.
1927 Return 0 if we can't find the insn. */
1930 next_cc0_user (insn)
1931 rtx insn;
1933 rtx note = find_reg_note (insn, REG_CC_USER, NULL_RTX);
1935 if (note)
1936 return XEXP (note, 0);
1938 insn = next_nonnote_insn (insn);
1939 if (insn && GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
1940 insn = XVECEXP (PATTERN (insn), 0, 0);
1942 if (insn && GET_RTX_CLASS (GET_CODE (insn)) == 'i'
1943 && reg_mentioned_p (cc0_rtx, PATTERN (insn)))
1944 return insn;
1946 return 0;
1949 /* Find the insn that set CC0 for INSN. Unless INSN has a REG_CC_SETTER
1950 note, it is the previous insn. */
1953 prev_cc0_setter (insn)
1954 rtx insn;
1956 rtx note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
1957 rtx link;
1959 if (note)
1960 return XEXP (note, 0);
1962 insn = prev_nonnote_insn (insn);
1963 if (! sets_cc0_p (PATTERN (insn)))
1964 abort ();
1966 return insn;
1968 #endif
1970 /* Try splitting insns that can be split for better scheduling.
1971 PAT is the pattern which might split.
1972 TRIAL is the insn providing PAT.
1973 LAST is non-zero if we should return the last insn of the sequence produced.
1975 If this routine succeeds in splitting, it returns the first or last
1976 replacement insn depending on the value of LAST. Otherwise, it
1977 returns TRIAL. If the insn to be returned can be split, it will be. */
1980 try_split (pat, trial, last)
1981 rtx pat, trial;
1982 int last;
1984 rtx before = PREV_INSN (trial);
1985 rtx after = NEXT_INSN (trial);
1986 rtx seq = split_insns (pat, trial);
1987 int has_barrier = 0;
1988 rtx tem;
1990 /* If we are splitting a JUMP_INSN, it might be followed by a BARRIER.
1991 We may need to handle this specially. */
1992 if (after && GET_CODE (after) == BARRIER)
1994 has_barrier = 1;
1995 after = NEXT_INSN (after);
1998 if (seq)
2000 /* SEQ can either be a SEQUENCE or the pattern of a single insn.
2001 The latter case will normally arise only when being done so that
2002 it, in turn, will be split (SFmode on the 29k is an example). */
2003 if (GET_CODE (seq) == SEQUENCE)
2005 /* If we are splitting a JUMP_INSN, look for the JUMP_INSN in
2006 SEQ and copy our JUMP_LABEL to it. If JUMP_LABEL is non-zero,
2007 increment the usage count so we don't delete the label. */
2008 int i;
2010 if (GET_CODE (trial) == JUMP_INSN)
2011 for (i = XVECLEN (seq, 0) - 1; i >= 0; i--)
2012 if (GET_CODE (XVECEXP (seq, 0, i)) == JUMP_INSN)
2014 JUMP_LABEL (XVECEXP (seq, 0, i)) = JUMP_LABEL (trial);
2016 if (JUMP_LABEL (trial))
2017 LABEL_NUSES (JUMP_LABEL (trial))++;
2020 tem = emit_insn_after (seq, before);
2022 delete_insn (trial);
2023 if (has_barrier)
2024 emit_barrier_after (tem);
2026 /* Recursively call try_split for each new insn created; by the
2027 time control returns here that insn will be fully split, so
2028 set LAST and continue from the insn after the one returned.
2029 We can't use next_active_insn here since AFTER may be a note.
2030 Ignore deleted insns, which can be occur if not optimizing. */
2031 for (tem = NEXT_INSN (before); tem != after;
2032 tem = NEXT_INSN (tem))
2033 if (! INSN_DELETED_P (tem))
2034 tem = try_split (PATTERN (tem), tem, 1);
2036 /* Avoid infinite loop if the result matches the original pattern. */
2037 else if (rtx_equal_p (seq, pat))
2038 return trial;
2039 else
2041 PATTERN (trial) = seq;
2042 INSN_CODE (trial) = -1;
2043 try_split (seq, trial, last);
2046 /* Return either the first or the last insn, depending on which was
2047 requested. */
2048 return last ? prev_active_insn (after) : next_active_insn (before);
2051 return trial;
2054 /* Make and return an INSN rtx, initializing all its slots.
2055 Store PATTERN in the pattern slots. */
2058 make_insn_raw (pattern)
2059 rtx pattern;
2061 register rtx insn;
2063 insn = rtx_alloc (INSN);
2064 INSN_UID (insn) = cur_insn_uid++;
2066 PATTERN (insn) = pattern;
2067 INSN_CODE (insn) = -1;
2068 LOG_LINKS (insn) = NULL;
2069 REG_NOTES (insn) = NULL;
2071 return insn;
2074 /* Like `make_insn' but make a JUMP_INSN instead of an insn. */
2076 static rtx
2077 make_jump_insn_raw (pattern)
2078 rtx pattern;
2080 register rtx insn;
2082 insn = rtx_alloc (JUMP_INSN);
2083 INSN_UID (insn) = cur_insn_uid++;
2085 PATTERN (insn) = pattern;
2086 INSN_CODE (insn) = -1;
2087 LOG_LINKS (insn) = NULL;
2088 REG_NOTES (insn) = NULL;
2089 JUMP_LABEL (insn) = NULL;
2091 return insn;
2094 /* Like `make_insn' but make a CALL_INSN instead of an insn. */
2096 static rtx
2097 make_call_insn_raw (pattern)
2098 rtx pattern;
2100 register rtx insn;
2102 insn = rtx_alloc (CALL_INSN);
2103 INSN_UID (insn) = cur_insn_uid++;
2105 PATTERN (insn) = pattern;
2106 INSN_CODE (insn) = -1;
2107 LOG_LINKS (insn) = NULL;
2108 REG_NOTES (insn) = NULL;
2109 CALL_INSN_FUNCTION_USAGE (insn) = NULL;
2111 return insn;
2114 /* Add INSN to the end of the doubly-linked list.
2115 INSN may be an INSN, JUMP_INSN, CALL_INSN, CODE_LABEL, BARRIER or NOTE. */
2117 void
2118 add_insn (insn)
2119 register rtx insn;
2121 PREV_INSN (insn) = last_insn;
2122 NEXT_INSN (insn) = 0;
2124 if (NULL != last_insn)
2125 NEXT_INSN (last_insn) = insn;
2127 if (NULL == first_insn)
2128 first_insn = insn;
2130 last_insn = insn;
2133 /* Add INSN into the doubly-linked list after insn AFTER. This should be the
2134 only function called to insert an insn once delay slots have been filled
2135 since only it knows how to update a SEQUENCE. */
2137 void
2138 add_insn_after (insn, after)
2139 rtx insn, after;
2141 rtx next = NEXT_INSN (after);
2143 NEXT_INSN (insn) = next;
2144 PREV_INSN (insn) = after;
2146 if (next)
2148 PREV_INSN (next) = insn;
2149 if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == SEQUENCE)
2150 PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = insn;
2152 else if (last_insn == after)
2153 last_insn = insn;
2154 else
2156 struct sequence_stack *stack = sequence_stack;
2157 /* Scan all pending sequences too. */
2158 for (; stack; stack = stack->next)
2159 if (after == stack->last)
2160 stack->last = insn;
2163 NEXT_INSN (after) = insn;
2164 if (GET_CODE (after) == INSN && GET_CODE (PATTERN (after)) == SEQUENCE)
2166 rtx sequence = PATTERN (after);
2167 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2171 /* Delete all insns made since FROM.
2172 FROM becomes the new last instruction. */
2174 void
2175 delete_insns_since (from)
2176 rtx from;
2178 if (from == 0)
2179 first_insn = 0;
2180 else
2181 NEXT_INSN (from) = 0;
2182 last_insn = from;
2185 /* This function is deprecated, please use sequences instead.
2187 Move a consecutive bunch of insns to a different place in the chain.
2188 The insns to be moved are those between FROM and TO.
2189 They are moved to a new position after the insn AFTER.
2190 AFTER must not be FROM or TO or any insn in between.
2192 This function does not know about SEQUENCEs and hence should not be
2193 called after delay-slot filling has been done. */
2195 void
2196 reorder_insns (from, to, after)
2197 rtx from, to, after;
2199 /* Splice this bunch out of where it is now. */
2200 if (PREV_INSN (from))
2201 NEXT_INSN (PREV_INSN (from)) = NEXT_INSN (to);
2202 if (NEXT_INSN (to))
2203 PREV_INSN (NEXT_INSN (to)) = PREV_INSN (from);
2204 if (last_insn == to)
2205 last_insn = PREV_INSN (from);
2206 if (first_insn == from)
2207 first_insn = NEXT_INSN (to);
2209 /* Make the new neighbors point to it and it to them. */
2210 if (NEXT_INSN (after))
2211 PREV_INSN (NEXT_INSN (after)) = to;
2213 NEXT_INSN (to) = NEXT_INSN (after);
2214 PREV_INSN (from) = after;
2215 NEXT_INSN (after) = from;
2216 if (after == last_insn)
2217 last_insn = to;
2220 /* Return the line note insn preceding INSN. */
2222 static rtx
2223 find_line_note (insn)
2224 rtx insn;
2226 if (no_line_numbers)
2227 return 0;
2229 for (; insn; insn = PREV_INSN (insn))
2230 if (GET_CODE (insn) == NOTE
2231 && NOTE_LINE_NUMBER (insn) >= 0)
2232 break;
2234 return insn;
2237 /* Like reorder_insns, but inserts line notes to preserve the line numbers
2238 of the moved insns when debugging. This may insert a note between AFTER
2239 and FROM, and another one after TO. */
2241 void
2242 reorder_insns_with_line_notes (from, to, after)
2243 rtx from, to, after;
2245 rtx from_line = find_line_note (from);
2246 rtx after_line = find_line_note (after);
2248 reorder_insns (from, to, after);
2250 if (from_line == after_line)
2251 return;
2253 if (from_line)
2254 emit_line_note_after (NOTE_SOURCE_FILE (from_line),
2255 NOTE_LINE_NUMBER (from_line),
2256 after);
2257 if (after_line)
2258 emit_line_note_after (NOTE_SOURCE_FILE (after_line),
2259 NOTE_LINE_NUMBER (after_line),
2260 to);
2263 /* Emit an insn of given code and pattern
2264 at a specified place within the doubly-linked list. */
2266 /* Make an instruction with body PATTERN
2267 and output it before the instruction BEFORE. */
2270 emit_insn_before (pattern, before)
2271 register rtx pattern, before;
2273 register rtx insn = before;
2275 if (GET_CODE (pattern) == SEQUENCE)
2277 register int i;
2279 for (i = 0; i < XVECLEN (pattern, 0); i++)
2281 insn = XVECEXP (pattern, 0, i);
2282 add_insn_after (insn, PREV_INSN (before));
2284 if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
2285 sequence_result[XVECLEN (pattern, 0)] = pattern;
2287 else
2289 insn = make_insn_raw (pattern);
2290 add_insn_after (insn, PREV_INSN (before));
2293 return insn;
2296 /* Make an instruction with body PATTERN and code JUMP_INSN
2297 and output it before the instruction BEFORE. */
2300 emit_jump_insn_before (pattern, before)
2301 register rtx pattern, before;
2303 register rtx insn;
2305 if (GET_CODE (pattern) == SEQUENCE)
2306 insn = emit_insn_before (pattern, before);
2307 else
2309 insn = make_jump_insn_raw (pattern);
2310 add_insn_after (insn, PREV_INSN (before));
2313 return insn;
2316 /* Make an instruction with body PATTERN and code CALL_INSN
2317 and output it before the instruction BEFORE. */
2320 emit_call_insn_before (pattern, before)
2321 register rtx pattern, before;
2323 register rtx insn;
2325 if (GET_CODE (pattern) == SEQUENCE)
2326 insn = emit_insn_before (pattern, before);
2327 else
2329 insn = make_call_insn_raw (pattern);
2330 add_insn_after (insn, PREV_INSN (before));
2331 PUT_CODE (insn, CALL_INSN);
2334 return insn;
2337 /* Make an insn of code BARRIER
2338 and output it before the insn AFTER. */
2341 emit_barrier_before (before)
2342 register rtx before;
2344 register rtx insn = rtx_alloc (BARRIER);
2346 INSN_UID (insn) = cur_insn_uid++;
2348 add_insn_after (insn, PREV_INSN (before));
2349 return insn;
2352 /* Emit a note of subtype SUBTYPE before the insn BEFORE. */
2355 emit_note_before (subtype, before)
2356 int subtype;
2357 rtx before;
2359 register rtx note = rtx_alloc (NOTE);
2360 INSN_UID (note) = cur_insn_uid++;
2361 NOTE_SOURCE_FILE (note) = 0;
2362 NOTE_LINE_NUMBER (note) = subtype;
2364 add_insn_after (note, PREV_INSN (before));
2365 return note;
2368 /* Make an insn of code INSN with body PATTERN
2369 and output it after the insn AFTER. */
2372 emit_insn_after (pattern, after)
2373 register rtx pattern, after;
2375 register rtx insn = after;
2377 if (GET_CODE (pattern) == SEQUENCE)
2379 register int i;
2381 for (i = 0; i < XVECLEN (pattern, 0); i++)
2383 insn = XVECEXP (pattern, 0, i);
2384 add_insn_after (insn, after);
2385 after = insn;
2387 if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
2388 sequence_result[XVECLEN (pattern, 0)] = pattern;
2390 else
2392 insn = make_insn_raw (pattern);
2393 add_insn_after (insn, after);
2396 return insn;
2399 /* Similar to emit_insn_after, except that line notes are to be inserted so
2400 as to act as if this insn were at FROM. */
2402 void
2403 emit_insn_after_with_line_notes (pattern, after, from)
2404 rtx pattern, after, from;
2406 rtx from_line = find_line_note (from);
2407 rtx after_line = find_line_note (after);
2408 rtx insn = emit_insn_after (pattern, after);
2410 if (from_line)
2411 emit_line_note_after (NOTE_SOURCE_FILE (from_line),
2412 NOTE_LINE_NUMBER (from_line),
2413 after);
2415 if (after_line)
2416 emit_line_note_after (NOTE_SOURCE_FILE (after_line),
2417 NOTE_LINE_NUMBER (after_line),
2418 insn);
2421 /* Make an insn of code JUMP_INSN with body PATTERN
2422 and output it after the insn AFTER. */
2425 emit_jump_insn_after (pattern, after)
2426 register rtx pattern, after;
2428 register rtx insn;
2430 if (GET_CODE (pattern) == SEQUENCE)
2431 insn = emit_insn_after (pattern, after);
2432 else
2434 insn = make_jump_insn_raw (pattern);
2435 add_insn_after (insn, after);
2438 return insn;
2441 /* Make an insn of code BARRIER
2442 and output it after the insn AFTER. */
2445 emit_barrier_after (after)
2446 register rtx after;
2448 register rtx insn = rtx_alloc (BARRIER);
2450 INSN_UID (insn) = cur_insn_uid++;
2452 add_insn_after (insn, after);
2453 return insn;
2456 /* Emit the label LABEL after the insn AFTER. */
2459 emit_label_after (label, after)
2460 rtx label, after;
2462 /* This can be called twice for the same label
2463 as a result of the confusion that follows a syntax error!
2464 So make it harmless. */
2465 if (INSN_UID (label) == 0)
2467 INSN_UID (label) = cur_insn_uid++;
2468 add_insn_after (label, after);
2471 return label;
2474 /* Emit a note of subtype SUBTYPE after the insn AFTER. */
2477 emit_note_after (subtype, after)
2478 int subtype;
2479 rtx after;
2481 register rtx note = rtx_alloc (NOTE);
2482 INSN_UID (note) = cur_insn_uid++;
2483 NOTE_SOURCE_FILE (note) = 0;
2484 NOTE_LINE_NUMBER (note) = subtype;
2485 add_insn_after (note, after);
2486 return note;
2489 /* Emit a line note for FILE and LINE after the insn AFTER. */
2492 emit_line_note_after (file, line, after)
2493 char *file;
2494 int line;
2495 rtx after;
2497 register rtx note;
2499 if (no_line_numbers && line > 0)
2501 cur_insn_uid++;
2502 return 0;
2505 note = rtx_alloc (NOTE);
2506 INSN_UID (note) = cur_insn_uid++;
2507 NOTE_SOURCE_FILE (note) = file;
2508 NOTE_LINE_NUMBER (note) = line;
2509 add_insn_after (note, after);
2510 return note;
2513 /* Make an insn of code INSN with pattern PATTERN
2514 and add it to the end of the doubly-linked list.
2515 If PATTERN is a SEQUENCE, take the elements of it
2516 and emit an insn for each element.
2518 Returns the last insn emitted. */
2521 emit_insn (pattern)
2522 rtx pattern;
2524 rtx insn = last_insn;
2526 if (GET_CODE (pattern) == SEQUENCE)
2528 register int i;
2530 for (i = 0; i < XVECLEN (pattern, 0); i++)
2532 insn = XVECEXP (pattern, 0, i);
2533 add_insn (insn);
2535 if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
2536 sequence_result[XVECLEN (pattern, 0)] = pattern;
2538 else
2540 insn = make_insn_raw (pattern);
2541 add_insn (insn);
2544 return insn;
2547 /* Emit the insns in a chain starting with INSN.
2548 Return the last insn emitted. */
2551 emit_insns (insn)
2552 rtx insn;
2554 rtx last = 0;
2556 while (insn)
2558 rtx next = NEXT_INSN (insn);
2559 add_insn (insn);
2560 last = insn;
2561 insn = next;
2564 return last;
2567 /* Emit the insns in a chain starting with INSN and place them in front of
2568 the insn BEFORE. Return the last insn emitted. */
2571 emit_insns_before (insn, before)
2572 rtx insn;
2573 rtx before;
2575 rtx last = 0;
2577 while (insn)
2579 rtx next = NEXT_INSN (insn);
2580 add_insn_after (insn, PREV_INSN (before));
2581 last = insn;
2582 insn = next;
2585 return last;
2588 /* Emit the insns in a chain starting with FIRST and place them in back of
2589 the insn AFTER. Return the last insn emitted. */
2592 emit_insns_after (first, after)
2593 register rtx first;
2594 register rtx after;
2596 register rtx last;
2597 register rtx after_after;
2599 if (!after)
2600 abort ();
2602 if (!first)
2603 return first;
2605 for (last = first; NEXT_INSN (last); last = NEXT_INSN (last))
2606 continue;
2608 after_after = NEXT_INSN (after);
2610 NEXT_INSN (after) = first;
2611 PREV_INSN (first) = after;
2612 NEXT_INSN (last) = after_after;
2613 if (after_after)
2614 PREV_INSN (after_after) = last;
2616 if (after == last_insn)
2617 last_insn = last;
2618 return last;
2621 /* Make an insn of code JUMP_INSN with pattern PATTERN
2622 and add it to the end of the doubly-linked list. */
2625 emit_jump_insn (pattern)
2626 rtx pattern;
2628 if (GET_CODE (pattern) == SEQUENCE)
2629 return emit_insn (pattern);
2630 else
2632 register rtx insn = make_jump_insn_raw (pattern);
2633 add_insn (insn);
2634 return insn;
2638 /* Make an insn of code CALL_INSN with pattern PATTERN
2639 and add it to the end of the doubly-linked list. */
2642 emit_call_insn (pattern)
2643 rtx pattern;
2645 if (GET_CODE (pattern) == SEQUENCE)
2646 return emit_insn (pattern);
2647 else
2649 register rtx insn = make_call_insn_raw (pattern);
2650 add_insn (insn);
2651 PUT_CODE (insn, CALL_INSN);
2652 return insn;
2656 /* Add the label LABEL to the end of the doubly-linked list. */
2659 emit_label (label)
2660 rtx label;
2662 /* This can be called twice for the same label
2663 as a result of the confusion that follows a syntax error!
2664 So make it harmless. */
2665 if (INSN_UID (label) == 0)
2667 INSN_UID (label) = cur_insn_uid++;
2668 add_insn (label);
2670 return label;
2673 /* Make an insn of code BARRIER
2674 and add it to the end of the doubly-linked list. */
2677 emit_barrier ()
2679 register rtx barrier = rtx_alloc (BARRIER);
2680 INSN_UID (barrier) = cur_insn_uid++;
2681 add_insn (barrier);
2682 return barrier;
2685 /* Make an insn of code NOTE
2686 with data-fields specified by FILE and LINE
2687 and add it to the end of the doubly-linked list,
2688 but only if line-numbers are desired for debugging info. */
2691 emit_line_note (file, line)
2692 char *file;
2693 int line;
2695 if (output_bytecode)
2697 /* FIXME: for now we do nothing, but eventually we will have to deal with
2698 debugging information. */
2699 return 0;
2702 emit_filename = file;
2703 emit_lineno = line;
2705 #if 0
2706 if (no_line_numbers)
2707 return 0;
2708 #endif
2710 return emit_note (file, line);
2713 /* Make an insn of code NOTE
2714 with data-fields specified by FILE and LINE
2715 and add it to the end of the doubly-linked list.
2716 If it is a line-number NOTE, omit it if it matches the previous one. */
2719 emit_note (file, line)
2720 char *file;
2721 int line;
2723 register rtx note;
2725 if (line > 0)
2727 if (file && last_filename && !strcmp (file, last_filename)
2728 && line == last_linenum)
2729 return 0;
2730 last_filename = file;
2731 last_linenum = line;
2734 if (no_line_numbers && line > 0)
2736 cur_insn_uid++;
2737 return 0;
2740 note = rtx_alloc (NOTE);
2741 INSN_UID (note) = cur_insn_uid++;
2742 NOTE_SOURCE_FILE (note) = file;
2743 NOTE_LINE_NUMBER (note) = line;
2744 add_insn (note);
2745 return note;
2748 /* Emit a NOTE, and don't omit it even if LINE it the previous note. */
2751 emit_line_note_force (file, line)
2752 char *file;
2753 int line;
2755 last_linenum = -1;
2756 return emit_line_note (file, line);
2759 /* Cause next statement to emit a line note even if the line number
2760 has not changed. This is used at the beginning of a function. */
2762 void
2763 force_next_line_note ()
2765 last_linenum = -1;
2768 /* Return an indication of which type of insn should have X as a body.
2769 The value is CODE_LABEL, INSN, CALL_INSN or JUMP_INSN. */
2771 enum rtx_code
2772 classify_insn (x)
2773 rtx x;
2775 if (GET_CODE (x) == CODE_LABEL)
2776 return CODE_LABEL;
2777 if (GET_CODE (x) == CALL)
2778 return CALL_INSN;
2779 if (GET_CODE (x) == RETURN)
2780 return JUMP_INSN;
2781 if (GET_CODE (x) == SET)
2783 if (SET_DEST (x) == pc_rtx)
2784 return JUMP_INSN;
2785 else if (GET_CODE (SET_SRC (x)) == CALL)
2786 return CALL_INSN;
2787 else
2788 return INSN;
2790 if (GET_CODE (x) == PARALLEL)
2792 register int j;
2793 for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
2794 if (GET_CODE (XVECEXP (x, 0, j)) == CALL)
2795 return CALL_INSN;
2796 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
2797 && SET_DEST (XVECEXP (x, 0, j)) == pc_rtx)
2798 return JUMP_INSN;
2799 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
2800 && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == CALL)
2801 return CALL_INSN;
2803 return INSN;
2806 /* Emit the rtl pattern X as an appropriate kind of insn.
2807 If X is a label, it is simply added into the insn chain. */
2810 emit (x)
2811 rtx x;
2813 enum rtx_code code = classify_insn (x);
2815 if (code == CODE_LABEL)
2816 return emit_label (x);
2817 else if (code == INSN)
2818 return emit_insn (x);
2819 else if (code == JUMP_INSN)
2821 register rtx insn = emit_jump_insn (x);
2822 if (simplejump_p (insn) || GET_CODE (x) == RETURN)
2823 return emit_barrier ();
2824 return insn;
2826 else if (code == CALL_INSN)
2827 return emit_call_insn (x);
2828 else
2829 abort ();
2832 /* Begin emitting insns to a sequence which can be packaged in an RTL_EXPR. */
2834 void
2835 start_sequence ()
2837 struct sequence_stack *tem;
2839 if (sequence_element_free_list)
2841 /* Reuse a previously-saved struct sequence_stack. */
2842 tem = sequence_element_free_list;
2843 sequence_element_free_list = tem->next;
2845 else
2846 tem = (struct sequence_stack *) permalloc (sizeof (struct sequence_stack));
2848 tem->next = sequence_stack;
2849 tem->first = first_insn;
2850 tem->last = last_insn;
2851 tem->sequence_rtl_expr = sequence_rtl_expr;
2853 sequence_stack = tem;
2855 first_insn = 0;
2856 last_insn = 0;
2859 /* Similarly, but indicate that this sequence will be placed in
2860 T, an RTL_EXPR. */
2862 void
2863 start_sequence_for_rtl_expr (t)
2864 tree t;
2866 start_sequence ();
2868 sequence_rtl_expr = t;
2871 /* Set up the insn chain starting with FIRST
2872 as the current sequence, saving the previously current one. */
2874 void
2875 push_to_sequence (first)
2876 rtx first;
2878 rtx last;
2880 start_sequence ();
2882 for (last = first; last && NEXT_INSN (last); last = NEXT_INSN (last));
2884 first_insn = first;
2885 last_insn = last;
2888 /* Set up the outer-level insn chain
2889 as the current sequence, saving the previously current one. */
2891 void
2892 push_topmost_sequence ()
2894 struct sequence_stack *stack, *top;
2896 start_sequence ();
2898 for (stack = sequence_stack; stack; stack = stack->next)
2899 top = stack;
2901 first_insn = top->first;
2902 last_insn = top->last;
2903 sequence_rtl_expr = top->sequence_rtl_expr;
2906 /* After emitting to the outer-level insn chain, update the outer-level
2907 insn chain, and restore the previous saved state. */
2909 void
2910 pop_topmost_sequence ()
2912 struct sequence_stack *stack, *top;
2914 for (stack = sequence_stack; stack; stack = stack->next)
2915 top = stack;
2917 top->first = first_insn;
2918 top->last = last_insn;
2919 /* ??? Why don't we save sequence_rtl_expr here? */
2921 end_sequence ();
2924 /* After emitting to a sequence, restore previous saved state.
2926 To get the contents of the sequence just made,
2927 you must call `gen_sequence' *before* calling here. */
2929 void
2930 end_sequence ()
2932 struct sequence_stack *tem = sequence_stack;
2934 first_insn = tem->first;
2935 last_insn = tem->last;
2936 sequence_rtl_expr = tem->sequence_rtl_expr;
2937 sequence_stack = tem->next;
2939 tem->next = sequence_element_free_list;
2940 sequence_element_free_list = tem;
2943 /* Return 1 if currently emitting into a sequence. */
2946 in_sequence_p ()
2948 return sequence_stack != 0;
2951 /* Generate a SEQUENCE rtx containing the insns already emitted
2952 to the current sequence.
2954 This is how the gen_... function from a DEFINE_EXPAND
2955 constructs the SEQUENCE that it returns. */
2958 gen_sequence ()
2960 rtx result;
2961 rtx tem;
2962 int i;
2963 int len;
2965 /* Count the insns in the chain. */
2966 len = 0;
2967 for (tem = first_insn; tem; tem = NEXT_INSN (tem))
2968 len++;
2970 /* If only one insn, return its pattern rather than a SEQUENCE.
2971 (Now that we cache SEQUENCE expressions, it isn't worth special-casing
2972 the case of an empty list.) */
2973 if (len == 1
2974 && (GET_CODE (first_insn) == INSN
2975 || GET_CODE (first_insn) == JUMP_INSN
2976 || GET_CODE (first_insn) == CALL_INSN))
2977 return PATTERN (first_insn);
2979 /* Put them in a vector. See if we already have a SEQUENCE of the
2980 appropriate length around. */
2981 if (len < SEQUENCE_RESULT_SIZE && (result = sequence_result[len]) != 0)
2982 sequence_result[len] = 0;
2983 else
2985 /* Ensure that this rtl goes in saveable_obstack, since we may be
2986 caching it. */
2987 push_obstacks_nochange ();
2988 rtl_in_saveable_obstack ();
2989 result = gen_rtx (SEQUENCE, VOIDmode, rtvec_alloc (len));
2990 pop_obstacks ();
2993 for (i = 0, tem = first_insn; tem; tem = NEXT_INSN (tem), i++)
2994 XVECEXP (result, 0, i) = tem;
2996 return result;
2999 /* Set up regno_reg_rtx, reg_rtx_no and regno_pointer_flag
3000 according to the chain of insns starting with FIRST.
3002 Also set cur_insn_uid to exceed the largest uid in that chain.
3004 This is used when an inline function's rtl is saved
3005 and passed to rest_of_compilation later. */
3007 static void restore_reg_data_1 ();
3009 void
3010 restore_reg_data (first)
3011 rtx first;
3013 register rtx insn;
3014 int i;
3015 register int max_uid = 0;
3017 for (insn = first; insn; insn = NEXT_INSN (insn))
3019 if (INSN_UID (insn) >= max_uid)
3020 max_uid = INSN_UID (insn);
3022 switch (GET_CODE (insn))
3024 case NOTE:
3025 case CODE_LABEL:
3026 case BARRIER:
3027 break;
3029 case JUMP_INSN:
3030 case CALL_INSN:
3031 case INSN:
3032 restore_reg_data_1 (PATTERN (insn));
3033 break;
3037 /* Don't duplicate the uids already in use. */
3038 cur_insn_uid = max_uid + 1;
3040 /* If any regs are missing, make them up.
3042 ??? word_mode is not necessarily the right mode. Most likely these REGs
3043 are never used. At some point this should be checked. */
3045 for (i = FIRST_PSEUDO_REGISTER; i < reg_rtx_no; i++)
3046 if (regno_reg_rtx[i] == 0)
3047 regno_reg_rtx[i] = gen_rtx (REG, word_mode, i);
3050 static void
3051 restore_reg_data_1 (orig)
3052 rtx orig;
3054 register rtx x = orig;
3055 register int i;
3056 register enum rtx_code code;
3057 register char *format_ptr;
3059 code = GET_CODE (x);
3061 switch (code)
3063 case QUEUED:
3064 case CONST_INT:
3065 case CONST_DOUBLE:
3066 case SYMBOL_REF:
3067 case CODE_LABEL:
3068 case PC:
3069 case CC0:
3070 case LABEL_REF:
3071 return;
3073 case REG:
3074 if (REGNO (x) >= FIRST_PSEUDO_REGISTER)
3076 /* Make sure regno_pointer_flag and regno_reg_rtx are large
3077 enough to have an element for this pseudo reg number. */
3078 if (REGNO (x) >= reg_rtx_no)
3080 reg_rtx_no = REGNO (x);
3082 if (reg_rtx_no >= regno_pointer_flag_length)
3084 int newlen = MAX (regno_pointer_flag_length * 2,
3085 reg_rtx_no + 30);
3086 rtx *new1;
3087 char *new = (char *) oballoc (newlen);
3088 bzero (new, newlen);
3089 bcopy (regno_pointer_flag, new, regno_pointer_flag_length);
3091 new1 = (rtx *) oballoc (newlen * sizeof (rtx));
3092 bzero ((char *) new1, newlen * sizeof (rtx));
3093 bcopy ((char *) regno_reg_rtx, (char *) new1,
3094 regno_pointer_flag_length * sizeof (rtx));
3096 regno_pointer_flag = new;
3097 regno_reg_rtx = new1;
3098 regno_pointer_flag_length = newlen;
3100 reg_rtx_no ++;
3102 regno_reg_rtx[REGNO (x)] = x;
3104 return;
3106 case MEM:
3107 if (GET_CODE (XEXP (x, 0)) == REG)
3108 mark_reg_pointer (XEXP (x, 0));
3109 restore_reg_data_1 (XEXP (x, 0));
3110 return;
3113 /* Now scan the subexpressions recursively. */
3115 format_ptr = GET_RTX_FORMAT (code);
3117 for (i = 0; i < GET_RTX_LENGTH (code); i++)
3119 switch (*format_ptr++)
3121 case 'e':
3122 restore_reg_data_1 (XEXP (x, i));
3123 break;
3125 case 'E':
3126 if (XVEC (x, i) != NULL)
3128 register int j;
3130 for (j = 0; j < XVECLEN (x, i); j++)
3131 restore_reg_data_1 (XVECEXP (x, i, j));
3133 break;
3138 /* Initialize data structures and variables in this file
3139 before generating rtl for each function. */
3141 void
3142 init_emit ()
3144 int i;
3146 first_insn = NULL;
3147 last_insn = NULL;
3148 sequence_rtl_expr = NULL;
3149 cur_insn_uid = 1;
3150 reg_rtx_no = LAST_VIRTUAL_REGISTER + 1;
3151 last_linenum = 0;
3152 last_filename = 0;
3153 first_label_num = label_num;
3154 last_label_num = 0;
3155 sequence_stack = NULL;
3157 /* Clear the start_sequence/gen_sequence cache. */
3158 sequence_element_free_list = 0;
3159 for (i = 0; i < SEQUENCE_RESULT_SIZE; i++)
3160 sequence_result[i] = 0;
3162 /* Init the tables that describe all the pseudo regs. */
3164 regno_pointer_flag_length = LAST_VIRTUAL_REGISTER + 101;
3166 regno_pointer_flag
3167 = (char *) oballoc (regno_pointer_flag_length);
3168 bzero (regno_pointer_flag, regno_pointer_flag_length);
3170 regno_reg_rtx
3171 = (rtx *) oballoc (regno_pointer_flag_length * sizeof (rtx));
3172 bzero ((char *) regno_reg_rtx, regno_pointer_flag_length * sizeof (rtx));
3174 /* Put copies of all the virtual register rtx into regno_reg_rtx. */
3175 regno_reg_rtx[VIRTUAL_INCOMING_ARGS_REGNUM] = virtual_incoming_args_rtx;
3176 regno_reg_rtx[VIRTUAL_STACK_VARS_REGNUM] = virtual_stack_vars_rtx;
3177 regno_reg_rtx[VIRTUAL_STACK_DYNAMIC_REGNUM] = virtual_stack_dynamic_rtx;
3178 regno_reg_rtx[VIRTUAL_OUTGOING_ARGS_REGNUM] = virtual_outgoing_args_rtx;
3180 /* Indicate that the virtual registers and stack locations are
3181 all pointers. */
3182 REGNO_POINTER_FLAG (STACK_POINTER_REGNUM) = 1;
3183 REGNO_POINTER_FLAG (FRAME_POINTER_REGNUM) = 1;
3184 REGNO_POINTER_FLAG (ARG_POINTER_REGNUM) = 1;
3186 REGNO_POINTER_FLAG (VIRTUAL_INCOMING_ARGS_REGNUM) = 1;
3187 REGNO_POINTER_FLAG (VIRTUAL_STACK_VARS_REGNUM) = 1;
3188 REGNO_POINTER_FLAG (VIRTUAL_STACK_DYNAMIC_REGNUM) = 1;
3189 REGNO_POINTER_FLAG (VIRTUAL_OUTGOING_ARGS_REGNUM) = 1;
3191 #ifdef INIT_EXPANDERS
3192 INIT_EXPANDERS;
3193 #endif
3196 /* Create some permanent unique rtl objects shared between all functions.
3197 LINE_NUMBERS is nonzero if line numbers are to be generated. */
3199 void
3200 init_emit_once (line_numbers)
3201 int line_numbers;
3203 int i;
3204 enum machine_mode mode;
3206 no_line_numbers = ! line_numbers;
3208 sequence_stack = NULL;
3210 /* Compute the word and byte modes. */
3212 byte_mode = VOIDmode;
3213 word_mode = VOIDmode;
3215 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
3216 mode = GET_MODE_WIDER_MODE (mode))
3218 if (GET_MODE_BITSIZE (mode) == BITS_PER_UNIT
3219 && byte_mode == VOIDmode)
3220 byte_mode = mode;
3222 if (GET_MODE_BITSIZE (mode) == BITS_PER_WORD
3223 && word_mode == VOIDmode)
3224 word_mode = mode;
3227 /* Create the unique rtx's for certain rtx codes and operand values. */
3229 pc_rtx = gen_rtx (PC, VOIDmode);
3230 cc0_rtx = gen_rtx (CC0, VOIDmode);
3232 /* Don't use gen_rtx here since gen_rtx in this case
3233 tries to use these variables. */
3234 for (i = - MAX_SAVED_CONST_INT; i <= MAX_SAVED_CONST_INT; i++)
3236 const_int_rtx[i + MAX_SAVED_CONST_INT] = rtx_alloc (CONST_INT);
3237 PUT_MODE (const_int_rtx[i + MAX_SAVED_CONST_INT], VOIDmode);
3238 INTVAL (const_int_rtx[i + MAX_SAVED_CONST_INT]) = i;
3241 /* These four calls obtain some of the rtx expressions made above. */
3242 const0_rtx = GEN_INT (0);
3243 const1_rtx = GEN_INT (1);
3244 const2_rtx = GEN_INT (2);
3245 constm1_rtx = GEN_INT (-1);
3247 /* This will usually be one of the above constants, but may be a new rtx. */
3248 const_true_rtx = GEN_INT (STORE_FLAG_VALUE);
3250 dconst0 = REAL_VALUE_ATOF ("0", DFmode);
3251 dconst1 = REAL_VALUE_ATOF ("1", DFmode);
3252 dconst2 = REAL_VALUE_ATOF ("2", DFmode);
3253 dconstm1 = REAL_VALUE_ATOF ("-1", DFmode);
3255 for (i = 0; i <= 2; i++)
3257 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
3258 mode = GET_MODE_WIDER_MODE (mode))
3260 rtx tem = rtx_alloc (CONST_DOUBLE);
3261 union real_extract u;
3263 bzero ((char *) &u, sizeof u); /* Zero any holes in a structure. */
3264 u.d = i == 0 ? dconst0 : i == 1 ? dconst1 : dconst2;
3266 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (tem), sizeof u);
3267 CONST_DOUBLE_MEM (tem) = cc0_rtx;
3268 PUT_MODE (tem, mode);
3270 const_tiny_rtx[i][(int) mode] = tem;
3273 const_tiny_rtx[i][(int) VOIDmode] = GEN_INT (i);
3275 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
3276 mode = GET_MODE_WIDER_MODE (mode))
3277 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
3279 for (mode = GET_CLASS_NARROWEST_MODE (MODE_PARTIAL_INT);
3280 mode != VOIDmode;
3281 mode = GET_MODE_WIDER_MODE (mode))
3282 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
3285 for (mode = GET_CLASS_NARROWEST_MODE (MODE_CC); mode != VOIDmode;
3286 mode = GET_MODE_WIDER_MODE (mode))
3287 const_tiny_rtx[0][(int) mode] = const0_rtx;
3289 stack_pointer_rtx = gen_rtx (REG, Pmode, STACK_POINTER_REGNUM);
3290 frame_pointer_rtx = gen_rtx (REG, Pmode, FRAME_POINTER_REGNUM);
3292 if (HARD_FRAME_POINTER_REGNUM == FRAME_POINTER_REGNUM)
3293 hard_frame_pointer_rtx = frame_pointer_rtx;
3294 else
3295 hard_frame_pointer_rtx = gen_rtx (REG, Pmode, HARD_FRAME_POINTER_REGNUM);
3297 if (FRAME_POINTER_REGNUM == ARG_POINTER_REGNUM)
3298 arg_pointer_rtx = frame_pointer_rtx;
3299 else if (HARD_FRAME_POINTER_REGNUM == ARG_POINTER_REGNUM)
3300 arg_pointer_rtx = hard_frame_pointer_rtx;
3301 else if (STACK_POINTER_REGNUM == ARG_POINTER_REGNUM)
3302 arg_pointer_rtx = stack_pointer_rtx;
3303 else
3304 arg_pointer_rtx = gen_rtx (REG, Pmode, ARG_POINTER_REGNUM);
3306 /* Create the virtual registers. Do so here since the following objects
3307 might reference them. */
3309 virtual_incoming_args_rtx = gen_rtx (REG, Pmode,
3310 VIRTUAL_INCOMING_ARGS_REGNUM);
3311 virtual_stack_vars_rtx = gen_rtx (REG, Pmode,
3312 VIRTUAL_STACK_VARS_REGNUM);
3313 virtual_stack_dynamic_rtx = gen_rtx (REG, Pmode,
3314 VIRTUAL_STACK_DYNAMIC_REGNUM);
3315 virtual_outgoing_args_rtx = gen_rtx (REG, Pmode,
3316 VIRTUAL_OUTGOING_ARGS_REGNUM);
3318 #ifdef STRUCT_VALUE
3319 struct_value_rtx = STRUCT_VALUE;
3320 #else
3321 struct_value_rtx = gen_rtx (REG, Pmode, STRUCT_VALUE_REGNUM);
3322 #endif
3324 #ifdef STRUCT_VALUE_INCOMING
3325 struct_value_incoming_rtx = STRUCT_VALUE_INCOMING;
3326 #else
3327 #ifdef STRUCT_VALUE_INCOMING_REGNUM
3328 struct_value_incoming_rtx
3329 = gen_rtx (REG, Pmode, STRUCT_VALUE_INCOMING_REGNUM);
3330 #else
3331 struct_value_incoming_rtx = struct_value_rtx;
3332 #endif
3333 #endif
3335 #ifdef STATIC_CHAIN_REGNUM
3336 static_chain_rtx = gen_rtx (REG, Pmode, STATIC_CHAIN_REGNUM);
3338 #ifdef STATIC_CHAIN_INCOMING_REGNUM
3339 if (STATIC_CHAIN_INCOMING_REGNUM != STATIC_CHAIN_REGNUM)
3340 static_chain_incoming_rtx = gen_rtx (REG, Pmode, STATIC_CHAIN_INCOMING_REGNUM);
3341 else
3342 #endif
3343 static_chain_incoming_rtx = static_chain_rtx;
3344 #endif
3346 #ifdef STATIC_CHAIN
3347 static_chain_rtx = STATIC_CHAIN;
3349 #ifdef STATIC_CHAIN_INCOMING
3350 static_chain_incoming_rtx = STATIC_CHAIN_INCOMING;
3351 #else
3352 static_chain_incoming_rtx = static_chain_rtx;
3353 #endif
3354 #endif
3356 #ifdef PIC_OFFSET_TABLE_REGNUM
3357 pic_offset_table_rtx = gen_rtx (REG, Pmode, PIC_OFFSET_TABLE_REGNUM);
3358 #endif