* arm/arm.h: (CPP_SPEC): Define __ARMEB__, __ARMEL__, and
[official-gcc.git] / gcc / emit-rtl.c
blob6b5732d7ed8d34d85d66012f4e4043a092fe9bdb
1 /* Emit RTL for the GNU C-Compiler expander.
2 Copyright (C) 1987, 88, 92, 93, 94, 1995 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, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* Middle-to-low level generation of rtx code and insns.
24 This file contains the functions `gen_rtx', `gen_reg_rtx'
25 and `gen_label_rtx' that are the usual ways of creating rtl
26 expressions for most purposes.
28 It also has the functions for creating insns and linking
29 them in the doubly-linked chain.
31 The patterns of the insns are created by machine-dependent
32 routines in insn-emit.c, which is generated automatically from
33 the machine description. These routines use `gen_rtx' to make
34 the individual rtx's of the pattern; what is machine dependent
35 is the kind of rtx's they make and what arguments they use. */
37 #include "config.h"
38 #ifdef __STDC__
39 #include <stdarg.h>
40 #else
41 #include <varargs.h>
42 #endif
43 #include "rtl.h"
44 #include "tree.h"
45 #include "flags.h"
46 #include "function.h"
47 #include "expr.h"
48 #include "regs.h"
49 #include "insn-config.h"
50 #include "real.h"
51 #include "obstack.h"
53 #include "bytecode.h"
54 #include "machmode.h"
55 #include "bc-opcode.h"
56 #include "bc-typecd.h"
57 #include "bc-optab.h"
58 #include "bc-emit.h"
60 #include <stdio.h>
63 /* Opcode names */
64 #ifdef BCDEBUG_PRINT_CODE
65 char *opcode_name[] =
67 #include "bc-opname.h"
69 "***END***"
71 #endif
74 /* Commonly used modes. */
76 enum machine_mode byte_mode; /* Mode whose width is BITS_PER_UNIT. */
77 enum machine_mode word_mode; /* Mode whose width is BITS_PER_WORD. */
78 enum machine_mode ptr_mode; /* Mode whose width is POINTER_SIZE. */
80 /* This is reset to LAST_VIRTUAL_REGISTER + 1 at the start of each function.
81 After rtl generation, it is 1 plus the largest register number used. */
83 int reg_rtx_no = LAST_VIRTUAL_REGISTER + 1;
85 /* This is *not* reset after each function. It gives each CODE_LABEL
86 in the entire compilation a unique label number. */
88 static int label_num = 1;
90 /* Lowest label number in current function. */
92 static int first_label_num;
94 /* Highest label number in current function.
95 Zero means use the value of label_num instead.
96 This is nonzero only when belatedly compiling an inline function. */
98 static int last_label_num;
100 /* Value label_num had when set_new_first_and_last_label_number was called.
101 If label_num has not changed since then, last_label_num is valid. */
103 static int base_label_num;
105 /* Nonzero means do not generate NOTEs for source line numbers. */
107 static int no_line_numbers;
109 /* Commonly used rtx's, so that we only need space for one copy.
110 These are initialized once for the entire compilation.
111 All of these except perhaps the floating-point CONST_DOUBLEs
112 are unique; no other rtx-object will be equal to any of these. */
114 rtx pc_rtx; /* (PC) */
115 rtx cc0_rtx; /* (CC0) */
116 rtx cc1_rtx; /* (CC1) (not actually used nowadays) */
117 rtx const0_rtx; /* (CONST_INT 0) */
118 rtx const1_rtx; /* (CONST_INT 1) */
119 rtx const2_rtx; /* (CONST_INT 2) */
120 rtx constm1_rtx; /* (CONST_INT -1) */
121 rtx const_true_rtx; /* (CONST_INT STORE_FLAG_VALUE) */
123 /* We record floating-point CONST_DOUBLEs in each floating-point mode for
124 the values of 0, 1, and 2. For the integer entries and VOIDmode, we
125 record a copy of const[012]_rtx. */
127 rtx const_tiny_rtx[3][(int) MAX_MACHINE_MODE];
129 REAL_VALUE_TYPE dconst0;
130 REAL_VALUE_TYPE dconst1;
131 REAL_VALUE_TYPE dconst2;
132 REAL_VALUE_TYPE dconstm1;
134 /* All references to the following fixed hard registers go through
135 these unique rtl objects. On machines where the frame-pointer and
136 arg-pointer are the same register, they use the same unique object.
138 After register allocation, other rtl objects which used to be pseudo-regs
139 may be clobbered to refer to the frame-pointer register.
140 But references that were originally to the frame-pointer can be
141 distinguished from the others because they contain frame_pointer_rtx.
143 When to use frame_pointer_rtx and hard_frame_pointer_rtx is a little
144 tricky: until register elimination has taken place hard_frame_pointer_rtx
145 should be used if it is being set, and frame_pointer_rtx otherwise. After
146 register elimination hard_frame_pointer_rtx should always be used.
147 On machines where the two registers are same (most) then these are the
148 same.
150 In an inline procedure, the stack and frame pointer rtxs may not be
151 used for anything else. */
152 rtx stack_pointer_rtx; /* (REG:Pmode STACK_POINTER_REGNUM) */
153 rtx frame_pointer_rtx; /* (REG:Pmode FRAME_POINTER_REGNUM) */
154 rtx hard_frame_pointer_rtx; /* (REG:Pmode HARD_FRAME_POINTER_REGNUM) */
155 rtx arg_pointer_rtx; /* (REG:Pmode ARG_POINTER_REGNUM) */
156 rtx struct_value_rtx; /* (REG:Pmode STRUCT_VALUE_REGNUM) */
157 rtx struct_value_incoming_rtx; /* (REG:Pmode STRUCT_VALUE_INCOMING_REGNUM) */
158 rtx static_chain_rtx; /* (REG:Pmode STATIC_CHAIN_REGNUM) */
159 rtx static_chain_incoming_rtx; /* (REG:Pmode STATIC_CHAIN_INCOMING_REGNUM) */
160 rtx pic_offset_table_rtx; /* (REG:Pmode PIC_OFFSET_TABLE_REGNUM) */
162 /* This is used to implement __builtin_return_address for some machines.
163 See for instance the MIPS port. */
164 rtx return_address_pointer_rtx; /* (REG:Pmode RETURN_ADDRESS_POINTER_REGNUM) */
166 rtx virtual_incoming_args_rtx; /* (REG:Pmode VIRTUAL_INCOMING_ARGS_REGNUM) */
167 rtx virtual_stack_vars_rtx; /* (REG:Pmode VIRTUAL_STACK_VARS_REGNUM) */
168 rtx virtual_stack_dynamic_rtx; /* (REG:Pmode VIRTUAL_STACK_DYNAMIC_REGNUM) */
169 rtx virtual_outgoing_args_rtx; /* (REG:Pmode VIRTUAL_OUTGOING_ARGS_REGNUM) */
171 /* We make one copy of (const_int C) where C is in
172 [- MAX_SAVED_CONST_INT, MAX_SAVED_CONST_INT]
173 to save space during the compilation and simplify comparisons of
174 integers. */
176 #define MAX_SAVED_CONST_INT 64
178 static rtx const_int_rtx[MAX_SAVED_CONST_INT * 2 + 1];
180 /* The ends of the doubly-linked chain of rtl for the current function.
181 Both are reset to null at the start of rtl generation for the function.
183 start_sequence saves both of these on `sequence_stack' along with
184 `sequence_rtl_expr' and then starts a new, nested sequence of insns. */
186 static rtx first_insn = NULL;
187 static rtx last_insn = NULL;
189 /* RTL_EXPR within which the current sequence will be placed. Use to
190 prevent reuse of any temporaries within the sequence until after the
191 RTL_EXPR is emitted. */
193 tree sequence_rtl_expr = NULL;
195 /* INSN_UID for next insn emitted.
196 Reset to 1 for each function compiled. */
198 static int cur_insn_uid = 1;
200 /* Line number and source file of the last line-number NOTE emitted.
201 This is used to avoid generating duplicates. */
203 static int last_linenum = 0;
204 static char *last_filename = 0;
206 /* A vector indexed by pseudo reg number. The allocated length
207 of this vector is regno_pointer_flag_length. Since this
208 vector is needed during the expansion phase when the total
209 number of registers in the function is not yet known,
210 it is copied and made bigger when necessary. */
212 char *regno_pointer_flag;
213 int regno_pointer_flag_length;
215 /* Indexed by pseudo register number, if nonzero gives the known alignment
216 for that pseudo (if regno_pointer_flag is set).
217 Allocated in parallel with regno_pointer_flag. */
218 char *regno_pointer_align;
220 /* Indexed by pseudo register number, gives the rtx for that pseudo.
221 Allocated in parallel with regno_pointer_flag. */
223 rtx *regno_reg_rtx;
225 /* Stack of pending (incomplete) sequences saved by `start_sequence'.
226 Each element describes one pending sequence.
227 The main insn-chain is saved in the last element of the chain,
228 unless the chain is empty. */
230 struct sequence_stack *sequence_stack;
232 /* start_sequence and gen_sequence can make a lot of rtx expressions which are
233 shortly thrown away. We use two mechanisms to prevent this waste:
235 First, we keep a list of the expressions used to represent the sequence
236 stack in sequence_element_free_list.
238 Second, for sizes up to 5 elements, we keep a SEQUENCE and its associated
239 rtvec for use by gen_sequence. One entry for each size is sufficient
240 because most cases are calls to gen_sequence followed by immediately
241 emitting the SEQUENCE. Reuse is safe since emitting a sequence is
242 destructive on the insn in it anyway and hence can't be redone.
244 We do not bother to save this cached data over nested function calls.
245 Instead, we just reinitialize them. */
247 #define SEQUENCE_RESULT_SIZE 5
249 static struct sequence_stack *sequence_element_free_list;
250 static rtx sequence_result[SEQUENCE_RESULT_SIZE];
252 extern int rtx_equal_function_value_matters;
254 /* Filename and line number of last line-number note,
255 whether we actually emitted it or not. */
256 extern char *emit_filename;
257 extern int emit_lineno;
259 rtx change_address ();
260 void init_emit ();
262 extern struct obstack *rtl_obstack;
264 extern int stack_depth;
265 extern int max_stack_depth;
267 /* rtx gen_rtx (code, mode, [element1, ..., elementn])
269 ** This routine generates an RTX of the size specified by
270 ** <code>, which is an RTX code. The RTX structure is initialized
271 ** from the arguments <element1> through <elementn>, which are
272 ** interpreted according to the specific RTX type's format. The
273 ** special machine mode associated with the rtx (if any) is specified
274 ** in <mode>.
276 ** gen_rtx can be invoked in a way which resembles the lisp-like
277 ** rtx it will generate. For example, the following rtx structure:
279 ** (plus:QI (mem:QI (reg:SI 1))
280 ** (mem:QI (plusw:SI (reg:SI 2) (reg:SI 3))))
282 ** ...would be generated by the following C code:
284 ** gen_rtx (PLUS, QImode,
285 ** gen_rtx (MEM, QImode,
286 ** gen_rtx (REG, SImode, 1)),
287 ** gen_rtx (MEM, QImode,
288 ** gen_rtx (PLUS, SImode,
289 ** gen_rtx (REG, SImode, 2),
290 ** gen_rtx (REG, SImode, 3)))),
293 /*VARARGS2*/
295 gen_rtx VPROTO((enum rtx_code code, enum machine_mode mode, ...))
297 #ifndef __STDC__
298 enum rtx_code code;
299 enum machine_mode mode;
300 #endif
301 va_list p;
302 register int i; /* Array indices... */
303 register char *fmt; /* Current rtx's format... */
304 register rtx rt_val; /* RTX to return to caller... */
306 VA_START (p, mode);
308 #ifndef __STDC__
309 code = va_arg (p, enum rtx_code);
310 mode = va_arg (p, enum machine_mode);
311 #endif
313 if (code == CONST_INT)
315 HOST_WIDE_INT arg = va_arg (p, HOST_WIDE_INT);
317 if (arg >= - MAX_SAVED_CONST_INT && arg <= MAX_SAVED_CONST_INT)
318 return const_int_rtx[arg + MAX_SAVED_CONST_INT];
320 if (const_true_rtx && arg == STORE_FLAG_VALUE)
321 return const_true_rtx;
323 rt_val = rtx_alloc (code);
324 INTVAL (rt_val) = arg;
326 else if (code == REG)
328 int regno = va_arg (p, int);
330 /* In case the MD file explicitly references the frame pointer, have
331 all such references point to the same frame pointer. This is used
332 during frame pointer elimination to distinguish the explicit
333 references to these registers from pseudos that happened to be
334 assigned to them.
336 If we have eliminated the frame pointer or arg pointer, we will
337 be using it as a normal register, for example as a spill register.
338 In such cases, we might be accessing it in a mode that is not
339 Pmode and therefore cannot use the pre-allocated rtx.
341 Also don't do this when we are making new REGs in reload,
342 since we don't want to get confused with the real pointers. */
344 if (frame_pointer_rtx && regno == FRAME_POINTER_REGNUM && mode == Pmode
345 && ! reload_in_progress)
346 return frame_pointer_rtx;
347 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
348 if (hard_frame_pointer_rtx && regno == HARD_FRAME_POINTER_REGNUM
349 && mode == Pmode && ! reload_in_progress)
350 return hard_frame_pointer_rtx;
351 #endif
352 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM && HARD_FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
353 if (arg_pointer_rtx && regno == ARG_POINTER_REGNUM && mode == Pmode
354 && ! reload_in_progress)
355 return arg_pointer_rtx;
356 #endif
357 #ifdef RETURN_ADDRESS_POINTER_REGNUM
358 if (return_address_pointer_rtx && regno == RETURN_ADDRESS_POINTER_REGNUM
359 && mode == Pmode && ! reload_in_progress)
360 return return_address_pointer_rtx;
361 #endif
362 if (stack_pointer_rtx && regno == STACK_POINTER_REGNUM && mode == Pmode
363 && ! reload_in_progress)
364 return stack_pointer_rtx;
365 else
367 rt_val = rtx_alloc (code);
368 rt_val->mode = mode;
369 REGNO (rt_val) = regno;
370 return rt_val;
373 else
375 rt_val = rtx_alloc (code); /* Allocate the storage space. */
376 rt_val->mode = mode; /* Store the machine mode... */
378 fmt = GET_RTX_FORMAT (code); /* Find the right format... */
379 for (i = 0; i < GET_RTX_LENGTH (code); i++)
381 switch (*fmt++)
383 case '0': /* Unused field. */
384 break;
386 case 'i': /* An integer? */
387 XINT (rt_val, i) = va_arg (p, int);
388 break;
390 case 'w': /* A wide integer? */
391 XWINT (rt_val, i) = va_arg (p, HOST_WIDE_INT);
392 break;
394 case 's': /* A string? */
395 XSTR (rt_val, i) = va_arg (p, char *);
396 break;
398 case 'e': /* An expression? */
399 case 'u': /* An insn? Same except when printing. */
400 XEXP (rt_val, i) = va_arg (p, rtx);
401 break;
403 case 'E': /* An RTX vector? */
404 XVEC (rt_val, i) = va_arg (p, rtvec);
405 break;
407 default:
408 abort ();
412 va_end (p);
413 return rt_val; /* Return the new RTX... */
416 /* gen_rtvec (n, [rt1, ..., rtn])
418 ** This routine creates an rtvec and stores within it the
419 ** pointers to rtx's which are its arguments.
422 /*VARARGS1*/
423 rtvec
424 gen_rtvec VPROTO((int n, ...))
426 #ifndef __STDC__
427 int n;
428 #endif
429 int i;
430 va_list p;
431 rtx *vector;
433 VA_START (p, n);
435 #ifndef __STDC__
436 n = va_arg (p, int);
437 #endif
439 if (n == 0)
440 return NULL_RTVEC; /* Don't allocate an empty rtvec... */
442 vector = (rtx *) alloca (n * sizeof (rtx));
444 for (i = 0; i < n; i++)
445 vector[i] = va_arg (p, rtx);
446 va_end (p);
448 return gen_rtvec_v (n, vector);
451 rtvec
452 gen_rtvec_v (n, argp)
453 int n;
454 rtx *argp;
456 register int i;
457 register rtvec rt_val;
459 if (n == 0)
460 return NULL_RTVEC; /* Don't allocate an empty rtvec... */
462 rt_val = rtvec_alloc (n); /* Allocate an rtvec... */
464 for (i = 0; i < n; i++)
465 rt_val->elem[i].rtx = *argp++;
467 return rt_val;
470 /* Generate a REG rtx for a new pseudo register of mode MODE.
471 This pseudo is assigned the next sequential register number. */
474 gen_reg_rtx (mode)
475 enum machine_mode mode;
477 register rtx val;
479 /* Don't let anything called by or after reload create new registers
480 (actually, registers can't be created after flow, but this is a good
481 approximation). */
483 if (reload_in_progress || reload_completed)
484 abort ();
486 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
487 || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
489 /* For complex modes, don't make a single pseudo.
490 Instead, make a CONCAT of two pseudos.
491 This allows noncontiguous allocation of the real and imaginary parts,
492 which makes much better code. Besides, allocating DCmode
493 pseudos overstrains reload on some machines like the 386. */
494 rtx realpart, imagpart;
495 int size = GET_MODE_UNIT_SIZE (mode);
496 enum machine_mode partmode
497 = mode_for_size (size * BITS_PER_UNIT,
498 (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
499 ? MODE_FLOAT : MODE_INT),
502 realpart = gen_reg_rtx (partmode);
503 imagpart = gen_reg_rtx (partmode);
504 return gen_rtx (CONCAT, mode, realpart, imagpart);
507 /* Make sure regno_pointer_flag and regno_reg_rtx are large
508 enough to have an element for this pseudo reg number. */
510 if (reg_rtx_no == regno_pointer_flag_length)
512 rtx *new1;
513 char *new =
514 (char *) savealloc (regno_pointer_flag_length * 2);
515 bcopy (regno_pointer_flag, new, regno_pointer_flag_length);
516 bzero (&new[regno_pointer_flag_length], regno_pointer_flag_length);
517 regno_pointer_flag = new;
519 new = (char *) savealloc (regno_pointer_flag_length * 2);
520 bcopy (regno_pointer_align, new, regno_pointer_flag_length);
521 bzero (&new[regno_pointer_flag_length], regno_pointer_flag_length);
522 regno_pointer_align = new;
524 new1 = (rtx *) savealloc (regno_pointer_flag_length * 2 * sizeof (rtx));
525 bcopy ((char *) regno_reg_rtx, (char *) new1,
526 regno_pointer_flag_length * sizeof (rtx));
527 bzero ((char *) &new1[regno_pointer_flag_length],
528 regno_pointer_flag_length * sizeof (rtx));
529 regno_reg_rtx = new1;
531 regno_pointer_flag_length *= 2;
534 val = gen_rtx (REG, mode, reg_rtx_no);
535 regno_reg_rtx[reg_rtx_no++] = val;
536 return val;
539 /* Identify REG as a probable pointer register and show its alignment
540 as ALIGN, if nonzero. */
542 void
543 mark_reg_pointer (reg, align)
544 rtx reg;
545 int align;
547 REGNO_POINTER_FLAG (REGNO (reg)) = 1;
549 if (align)
550 REGNO_POINTER_ALIGN (REGNO (reg)) = align;
553 /* Return 1 plus largest pseudo reg number used in the current function. */
556 max_reg_num ()
558 return reg_rtx_no;
561 /* Return 1 + the largest label number used so far in the current function. */
564 max_label_num ()
566 if (last_label_num && label_num == base_label_num)
567 return last_label_num;
568 return label_num;
571 /* Return first label number used in this function (if any were used). */
574 get_first_label_num ()
576 return first_label_num;
579 /* Return a value representing some low-order bits of X, where the number
580 of low-order bits is given by MODE. Note that no conversion is done
581 between floating-point and fixed-point values, rather, the bit
582 representation is returned.
584 This function handles the cases in common between gen_lowpart, below,
585 and two variants in cse.c and combine.c. These are the cases that can
586 be safely handled at all points in the compilation.
588 If this is not a case we can handle, return 0. */
591 gen_lowpart_common (mode, x)
592 enum machine_mode mode;
593 register rtx x;
595 int word = 0;
597 if (GET_MODE (x) == mode)
598 return x;
600 /* MODE must occupy no more words than the mode of X. */
601 if (GET_MODE (x) != VOIDmode
602 && ((GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD
603 > ((GET_MODE_SIZE (GET_MODE (x)) + (UNITS_PER_WORD - 1))
604 / UNITS_PER_WORD)))
605 return 0;
607 if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
608 word = ((GET_MODE_SIZE (GET_MODE (x))
609 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD))
610 / UNITS_PER_WORD);
612 if ((GET_CODE (x) == ZERO_EXTEND || GET_CODE (x) == SIGN_EXTEND)
613 && (GET_MODE_CLASS (mode) == MODE_INT
614 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT))
616 /* If we are getting the low-order part of something that has been
617 sign- or zero-extended, we can either just use the object being
618 extended or make a narrower extension. If we want an even smaller
619 piece than the size of the object being extended, call ourselves
620 recursively.
622 This case is used mostly by combine and cse. */
624 if (GET_MODE (XEXP (x, 0)) == mode)
625 return XEXP (x, 0);
626 else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (XEXP (x, 0))))
627 return gen_lowpart_common (mode, XEXP (x, 0));
628 else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (x)))
629 return gen_rtx (GET_CODE (x), mode, XEXP (x, 0));
631 else if (GET_CODE (x) == SUBREG
632 && (GET_MODE_SIZE (mode) <= UNITS_PER_WORD
633 || GET_MODE_SIZE (mode) == GET_MODE_UNIT_SIZE (GET_MODE (x))))
634 return (GET_MODE (SUBREG_REG (x)) == mode && SUBREG_WORD (x) == 0
635 ? SUBREG_REG (x)
636 : gen_rtx (SUBREG, mode, SUBREG_REG (x), SUBREG_WORD (x)));
637 else if (GET_CODE (x) == REG)
639 /* If the register is not valid for MODE, return 0. If we don't
640 do this, there is no way to fix up the resulting REG later.
641 But we do do this if the current REG is not valid for its
642 mode. This latter is a kludge, but is required due to the
643 way that parameters are passed on some machines, most
644 notably Sparc. */
645 if (REGNO (x) < FIRST_PSEUDO_REGISTER
646 && ! HARD_REGNO_MODE_OK (REGNO (x) + word, mode)
647 && HARD_REGNO_MODE_OK (REGNO (x), GET_MODE (x)))
648 return 0;
649 else if (REGNO (x) < FIRST_PSEUDO_REGISTER
650 /* integrate.c can't handle parts of a return value register. */
651 && (! REG_FUNCTION_VALUE_P (x)
652 || ! rtx_equal_function_value_matters)
653 /* We want to keep the stack, frame, and arg pointers
654 special. */
655 && x != frame_pointer_rtx
656 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
657 && x != arg_pointer_rtx
658 #endif
659 && x != stack_pointer_rtx)
660 return gen_rtx (REG, mode, REGNO (x) + word);
661 else
662 return gen_rtx (SUBREG, mode, x, word);
664 /* If X is a CONST_INT or a CONST_DOUBLE, extract the appropriate bits
665 from the low-order part of the constant. */
666 else if ((GET_MODE_CLASS (mode) == MODE_INT
667 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
668 && GET_MODE (x) == VOIDmode
669 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
671 /* If MODE is twice the host word size, X is already the desired
672 representation. Otherwise, if MODE is wider than a word, we can't
673 do this. If MODE is exactly a word, return just one CONST_INT.
674 If MODE is smaller than a word, clear the bits that don't belong
675 in our mode, unless they and our sign bit are all one. So we get
676 either a reasonable negative value or a reasonable unsigned value
677 for this mode. */
679 if (GET_MODE_BITSIZE (mode) >= 2 * HOST_BITS_PER_WIDE_INT)
680 return x;
681 else if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
682 return 0;
683 else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
684 return (GET_CODE (x) == CONST_INT ? x
685 : GEN_INT (CONST_DOUBLE_LOW (x)));
686 else
688 /* MODE must be narrower than HOST_BITS_PER_INT. */
689 int width = GET_MODE_BITSIZE (mode);
690 HOST_WIDE_INT val = (GET_CODE (x) == CONST_INT ? INTVAL (x)
691 : CONST_DOUBLE_LOW (x));
693 if (((val & ((HOST_WIDE_INT) (-1) << (width - 1)))
694 != ((HOST_WIDE_INT) (-1) << (width - 1))))
695 val &= ((HOST_WIDE_INT) 1 << width) - 1;
697 return (GET_CODE (x) == CONST_INT && INTVAL (x) == val ? x
698 : GEN_INT (val));
702 /* If X is an integral constant but we want it in floating-point, it
703 must be the case that we have a union of an integer and a floating-point
704 value. If the machine-parameters allow it, simulate that union here
705 and return the result. The two-word and single-word cases are
706 different. */
708 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
709 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
710 || flag_pretend_float)
711 && GET_MODE_CLASS (mode) == MODE_FLOAT
712 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
713 && GET_CODE (x) == CONST_INT
714 && sizeof (float) * HOST_BITS_PER_CHAR == HOST_BITS_PER_WIDE_INT)
715 #ifdef REAL_ARITHMETIC
717 REAL_VALUE_TYPE r;
718 HOST_WIDE_INT i;
720 i = INTVAL (x);
721 r = REAL_VALUE_FROM_TARGET_SINGLE (i);
722 return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
724 #else
726 union {HOST_WIDE_INT i; float d; } u;
728 u.i = INTVAL (x);
729 return CONST_DOUBLE_FROM_REAL_VALUE (u.d, mode);
731 #endif
732 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
733 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
734 || flag_pretend_float)
735 && GET_MODE_CLASS (mode) == MODE_FLOAT
736 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
737 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
738 && GET_MODE (x) == VOIDmode
739 && (sizeof (double) * HOST_BITS_PER_CHAR
740 == 2 * HOST_BITS_PER_WIDE_INT))
741 #ifdef REAL_ARITHMETIC
743 REAL_VALUE_TYPE r;
744 HOST_WIDE_INT i[2];
745 HOST_WIDE_INT low, high;
747 if (GET_CODE (x) == CONST_INT)
748 low = INTVAL (x), high = low >> (HOST_BITS_PER_WIDE_INT -1);
749 else
750 low = CONST_DOUBLE_LOW (x), high = CONST_DOUBLE_HIGH (x);
752 /* REAL_VALUE_TARGET_DOUBLE takes the addressing order of the
753 target machine. */
754 if (WORDS_BIG_ENDIAN)
755 i[0] = high, i[1] = low;
756 else
757 i[0] = low, i[1] = high;
759 r = REAL_VALUE_FROM_TARGET_DOUBLE (i);
760 return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
762 #else
764 union {HOST_WIDE_INT i[2]; double d; } u;
765 HOST_WIDE_INT low, high;
767 if (GET_CODE (x) == CONST_INT)
768 low = INTVAL (x), high = low >> (HOST_BITS_PER_WIDE_INT -1);
769 else
770 low = CONST_DOUBLE_LOW (x), high = CONST_DOUBLE_HIGH (x);
772 #ifdef HOST_WORDS_BIG_ENDIAN
773 u.i[0] = high, u.i[1] = low;
774 #else
775 u.i[0] = low, u.i[1] = high;
776 #endif
778 return CONST_DOUBLE_FROM_REAL_VALUE (u.d, mode);
780 #endif
781 /* Similarly, if this is converting a floating-point value into a
782 single-word integer. Only do this is the host and target parameters are
783 compatible. */
785 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
786 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
787 || flag_pretend_float)
788 && (GET_MODE_CLASS (mode) == MODE_INT
789 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
790 && GET_CODE (x) == CONST_DOUBLE
791 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT
792 && GET_MODE_BITSIZE (mode) == BITS_PER_WORD)
793 return operand_subword (x, 0, 0, GET_MODE (x));
795 /* Similarly, if this is converting a floating-point value into a
796 two-word integer, we can do this one word at a time and make an
797 integer. Only do this is the host and target parameters are
798 compatible. */
800 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
801 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
802 || flag_pretend_float)
803 && (GET_MODE_CLASS (mode) == MODE_INT
804 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
805 && GET_CODE (x) == CONST_DOUBLE
806 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT
807 && GET_MODE_BITSIZE (mode) == 2 * BITS_PER_WORD)
809 rtx lowpart = operand_subword (x, WORDS_BIG_ENDIAN, 0, GET_MODE (x));
810 rtx highpart = operand_subword (x, ! WORDS_BIG_ENDIAN, 0, GET_MODE (x));
812 if (lowpart && GET_CODE (lowpart) == CONST_INT
813 && highpart && GET_CODE (highpart) == CONST_INT)
814 return immed_double_const (INTVAL (lowpart), INTVAL (highpart), mode);
817 /* Otherwise, we can't do this. */
818 return 0;
821 /* Return the real part (which has mode MODE) of a complex value X.
822 This always comes at the low address in memory. */
825 gen_realpart (mode, x)
826 enum machine_mode mode;
827 register rtx x;
829 if (GET_CODE (x) == CONCAT && GET_MODE (XEXP (x, 0)) == mode)
830 return XEXP (x, 0);
831 else if (WORDS_BIG_ENDIAN)
832 return gen_highpart (mode, x);
833 else
834 return gen_lowpart (mode, x);
837 /* Return the imaginary part (which has mode MODE) of a complex value X.
838 This always comes at the high address in memory. */
841 gen_imagpart (mode, x)
842 enum machine_mode mode;
843 register rtx x;
845 if (GET_CODE (x) == CONCAT && GET_MODE (XEXP (x, 0)) == mode)
846 return XEXP (x, 1);
847 else if (WORDS_BIG_ENDIAN)
848 return gen_lowpart (mode, x);
849 else
850 return gen_highpart (mode, x);
853 /* Return 1 iff X, assumed to be a SUBREG,
854 refers to the real part of the complex value in its containing reg.
855 Complex values are always stored with the real part in the first word,
856 regardless of WORDS_BIG_ENDIAN. */
859 subreg_realpart_p (x)
860 rtx x;
862 if (GET_CODE (x) != SUBREG)
863 abort ();
865 return SUBREG_WORD (x) == 0;
868 /* Assuming that X is an rtx (e.g., MEM, REG or SUBREG) for a value,
869 return an rtx (MEM, SUBREG, or CONST_INT) that refers to the
870 least-significant part of X.
871 MODE specifies how big a part of X to return;
872 it usually should not be larger than a word.
873 If X is a MEM whose address is a QUEUED, the value may be so also. */
876 gen_lowpart (mode, x)
877 enum machine_mode mode;
878 register rtx x;
880 rtx result = gen_lowpart_common (mode, x);
882 if (result)
883 return result;
884 else if (GET_CODE (x) == REG)
886 /* Must be a hard reg that's not valid in MODE. */
887 result = gen_lowpart_common (mode, copy_to_reg (x));
888 if (result == 0)
889 abort ();
891 else if (GET_CODE (x) == MEM)
893 /* The only additional case we can do is MEM. */
894 register int offset = 0;
895 if (WORDS_BIG_ENDIAN)
896 offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
897 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
899 if (BYTES_BIG_ENDIAN)
900 /* Adjust the address so that the address-after-the-data
901 is unchanged. */
902 offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))
903 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
905 return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
907 else
908 abort ();
911 /* Like `gen_lowpart', but refer to the most significant part.
912 This is used to access the imaginary part of a complex number. */
915 gen_highpart (mode, x)
916 enum machine_mode mode;
917 register rtx x;
919 /* This case loses if X is a subreg. To catch bugs early,
920 complain if an invalid MODE is used even in other cases. */
921 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
922 && GET_MODE_SIZE (mode) != GET_MODE_UNIT_SIZE (GET_MODE (x)))
923 abort ();
924 if (GET_CODE (x) == CONST_DOUBLE
925 #if !(TARGET_FLOAT_FORMAT != HOST_FLOAT_FORMAT || defined (REAL_IS_NOT_DOUBLE))
926 && GET_MODE_CLASS (GET_MODE (x)) != MODE_FLOAT
927 #endif
929 return gen_rtx (CONST_INT, VOIDmode,
930 CONST_DOUBLE_HIGH (x) & GET_MODE_MASK (mode));
931 else if (GET_CODE (x) == CONST_INT)
932 return const0_rtx;
933 else if (GET_CODE (x) == MEM)
935 register int offset = 0;
936 if (! WORDS_BIG_ENDIAN)
937 offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
938 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
940 if (! BYTES_BIG_ENDIAN
941 && GET_MODE_SIZE (mode) < UNITS_PER_WORD)
942 offset -= (GET_MODE_SIZE (mode)
943 - MIN (UNITS_PER_WORD,
944 GET_MODE_SIZE (GET_MODE (x))));
946 return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
948 else if (GET_CODE (x) == SUBREG)
950 /* The only time this should occur is when we are looking at a
951 multi-word item with a SUBREG whose mode is the same as that of the
952 item. It isn't clear what we would do if it wasn't. */
953 if (SUBREG_WORD (x) != 0)
954 abort ();
955 return gen_highpart (mode, SUBREG_REG (x));
957 else if (GET_CODE (x) == REG)
959 int word = 0;
961 if (! WORDS_BIG_ENDIAN
962 && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
963 word = ((GET_MODE_SIZE (GET_MODE (x))
964 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD))
965 / UNITS_PER_WORD);
968 * ??? This fails miserably for complex values being passed in registers
969 * where the sizeof the real and imaginary part are not equal to the
970 * sizeof SImode. FIXME
973 if (REGNO (x) < FIRST_PSEUDO_REGISTER
974 /* integrate.c can't handle parts of a return value register. */
975 && (! REG_FUNCTION_VALUE_P (x)
976 || ! rtx_equal_function_value_matters)
977 /* We want to keep the stack, frame, and arg pointers special. */
978 && x != frame_pointer_rtx
979 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
980 && x != arg_pointer_rtx
981 #endif
982 && x != stack_pointer_rtx)
983 return gen_rtx (REG, mode, REGNO (x) + word);
984 else
985 return gen_rtx (SUBREG, mode, x, word);
987 else
988 abort ();
991 /* Return 1 iff X, assumed to be a SUBREG,
992 refers to the least significant part of its containing reg.
993 If X is not a SUBREG, always return 1 (it is its own low part!). */
996 subreg_lowpart_p (x)
997 rtx x;
999 if (GET_CODE (x) != SUBREG)
1000 return 1;
1002 if (WORDS_BIG_ENDIAN
1003 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) > UNITS_PER_WORD)
1004 return (SUBREG_WORD (x)
1005 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
1006 - MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD))
1007 / UNITS_PER_WORD));
1009 return SUBREG_WORD (x) == 0;
1012 /* Return subword I of operand OP.
1013 The word number, I, is interpreted as the word number starting at the
1014 low-order address. Word 0 is the low-order word if not WORDS_BIG_ENDIAN,
1015 otherwise it is the high-order word.
1017 If we cannot extract the required word, we return zero. Otherwise, an
1018 rtx corresponding to the requested word will be returned.
1020 VALIDATE_ADDRESS is nonzero if the address should be validated. Before
1021 reload has completed, a valid address will always be returned. After
1022 reload, if a valid address cannot be returned, we return zero.
1024 If VALIDATE_ADDRESS is zero, we simply form the required address; validating
1025 it is the responsibility of the caller.
1027 MODE is the mode of OP in case it is a CONST_INT. */
1030 operand_subword (op, i, validate_address, mode)
1031 rtx op;
1032 int i;
1033 int validate_address;
1034 enum machine_mode mode;
1036 HOST_WIDE_INT val;
1037 int size_ratio = HOST_BITS_PER_WIDE_INT / BITS_PER_WORD;
1039 if (mode == VOIDmode)
1040 mode = GET_MODE (op);
1042 if (mode == VOIDmode)
1043 abort ();
1045 /* If OP is narrower than a word or if we want a word outside OP, fail. */
1046 if (mode != BLKmode
1047 && (GET_MODE_SIZE (mode) < UNITS_PER_WORD
1048 || (i + 1) * UNITS_PER_WORD > GET_MODE_SIZE (mode)))
1049 return 0;
1051 /* If OP is already an integer word, return it. */
1052 if (GET_MODE_CLASS (mode) == MODE_INT
1053 && GET_MODE_SIZE (mode) == UNITS_PER_WORD)
1054 return op;
1056 /* If OP is a REG or SUBREG, we can handle it very simply. */
1057 if (GET_CODE (op) == REG)
1059 /* If the register is not valid for MODE, return 0. If we don't
1060 do this, there is no way to fix up the resulting REG later. */
1061 if (REGNO (op) < FIRST_PSEUDO_REGISTER
1062 && ! HARD_REGNO_MODE_OK (REGNO (op) + i, word_mode))
1063 return 0;
1064 else if (REGNO (op) >= FIRST_PSEUDO_REGISTER
1065 || (REG_FUNCTION_VALUE_P (op)
1066 && rtx_equal_function_value_matters)
1067 /* We want to keep the stack, frame, and arg pointers
1068 special. */
1069 || op == frame_pointer_rtx
1070 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1071 || op == arg_pointer_rtx
1072 #endif
1073 || op == stack_pointer_rtx)
1074 return gen_rtx (SUBREG, word_mode, op, i);
1075 else
1076 return gen_rtx (REG, word_mode, REGNO (op) + i);
1078 else if (GET_CODE (op) == SUBREG)
1079 return gen_rtx (SUBREG, word_mode, SUBREG_REG (op), i + SUBREG_WORD (op));
1080 else if (GET_CODE (op) == CONCAT)
1082 int partwords = GET_MODE_UNIT_SIZE (GET_MODE (op)) / UNITS_PER_WORD;
1083 if (i < partwords)
1084 return operand_subword (XEXP (op, 0), i, validate_address, mode);
1085 return operand_subword (XEXP (op, 1), i - partwords,
1086 validate_address, mode);
1089 /* Form a new MEM at the requested address. */
1090 if (GET_CODE (op) == MEM)
1092 rtx addr = plus_constant (XEXP (op, 0), i * UNITS_PER_WORD);
1093 rtx new;
1095 if (validate_address)
1097 if (reload_completed)
1099 if (! strict_memory_address_p (word_mode, addr))
1100 return 0;
1102 else
1103 addr = memory_address (word_mode, addr);
1106 new = gen_rtx (MEM, word_mode, addr);
1108 MEM_VOLATILE_P (new) = MEM_VOLATILE_P (op);
1109 MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (op);
1110 RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (op);
1112 return new;
1115 /* The only remaining cases are when OP is a constant. If the host and
1116 target floating formats are the same, handling two-word floating
1117 constants are easy. Note that REAL_VALUE_TO_TARGET_{SINGLE,DOUBLE}
1118 are defined as returning one or two 32 bit values, respectively,
1119 and not values of BITS_PER_WORD bits. */
1120 #ifdef REAL_ARITHMETIC
1121 /* The output is some bits, the width of the target machine's word.
1122 A wider-word host can surely hold them in a CONST_INT. A narrower-word
1123 host can't. */
1124 if (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
1125 && GET_MODE_CLASS (mode) == MODE_FLOAT
1126 && GET_MODE_BITSIZE (mode) == 64
1127 && GET_CODE (op) == CONST_DOUBLE)
1129 long k[2];
1130 REAL_VALUE_TYPE rv;
1132 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1133 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
1135 /* We handle 32-bit and >= 64-bit words here. Note that the order in
1136 which the words are written depends on the word endianness.
1138 ??? This is a potential portability problem and should
1139 be fixed at some point. */
1140 if (BITS_PER_WORD == 32)
1141 return GEN_INT ((HOST_WIDE_INT) k[i]);
1142 #if HOST_BITS_PER_WIDE_INT > 32
1143 else if (BITS_PER_WORD >= 64 && i == 0)
1144 return GEN_INT ((((HOST_WIDE_INT) k[! WORDS_BIG_ENDIAN]) << 32)
1145 | (HOST_WIDE_INT) k[WORDS_BIG_ENDIAN]);
1146 #endif
1147 else if (BITS_PER_WORD == 16)
1149 long value;
1150 value = k[i >> 1];
1151 if ((i & 0x1) == 0)
1152 value >>= 16;
1153 value &= 0xffff;
1154 return GEN_INT ((HOST_WIDE_INT) value);
1156 else
1157 abort ();
1159 #else /* no REAL_ARITHMETIC */
1160 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1161 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1162 || flag_pretend_float)
1163 && GET_MODE_CLASS (mode) == MODE_FLOAT
1164 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
1165 && GET_CODE (op) == CONST_DOUBLE)
1167 /* The constant is stored in the host's word-ordering,
1168 but we want to access it in the target's word-ordering. Some
1169 compilers don't like a conditional inside macro args, so we have two
1170 copies of the return. */
1171 #ifdef HOST_WORDS_BIG_ENDIAN
1172 return GEN_INT (i == WORDS_BIG_ENDIAN
1173 ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
1174 #else
1175 return GEN_INT (i != WORDS_BIG_ENDIAN
1176 ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
1177 #endif
1179 #endif /* no REAL_ARITHMETIC */
1181 /* Single word float is a little harder, since single- and double-word
1182 values often do not have the same high-order bits. We have already
1183 verified that we want the only defined word of the single-word value. */
1184 #ifdef REAL_ARITHMETIC
1185 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1186 && GET_MODE_BITSIZE (mode) == 32
1187 && GET_CODE (op) == CONST_DOUBLE)
1189 long l;
1190 REAL_VALUE_TYPE rv;
1192 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1193 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
1194 return GEN_INT ((HOST_WIDE_INT) l);
1196 #else
1197 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1198 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1199 || flag_pretend_float)
1200 && GET_MODE_CLASS (mode) == MODE_FLOAT
1201 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
1202 && GET_CODE (op) == CONST_DOUBLE)
1204 double d;
1205 union {float f; HOST_WIDE_INT i; } u;
1207 REAL_VALUE_FROM_CONST_DOUBLE (d, op);
1209 u.f = d;
1210 return GEN_INT (u.i);
1212 #endif /* no REAL_ARITHMETIC */
1214 /* The only remaining cases that we can handle are integers.
1215 Convert to proper endianness now since these cases need it.
1216 At this point, i == 0 means the low-order word.
1218 We do not want to handle the case when BITS_PER_WORD <= HOST_BITS_PER_INT
1219 in general. However, if OP is (const_int 0), we can just return
1220 it for any word. */
1222 if (op == const0_rtx)
1223 return op;
1225 if (GET_MODE_CLASS (mode) != MODE_INT
1226 || (GET_CODE (op) != CONST_INT && GET_CODE (op) != CONST_DOUBLE)
1227 || BITS_PER_WORD > HOST_BITS_PER_WIDE_INT)
1228 return 0;
1230 if (WORDS_BIG_ENDIAN)
1231 i = GET_MODE_SIZE (mode) / UNITS_PER_WORD - 1 - i;
1233 /* Find out which word on the host machine this value is in and get
1234 it from the constant. */
1235 val = (i / size_ratio == 0
1236 ? (GET_CODE (op) == CONST_INT ? INTVAL (op) : CONST_DOUBLE_LOW (op))
1237 : (GET_CODE (op) == CONST_INT
1238 ? (INTVAL (op) < 0 ? ~0 : 0) : CONST_DOUBLE_HIGH (op)));
1240 /* If BITS_PER_WORD is smaller than an int, get the appropriate bits. */
1241 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT)
1242 val = ((val >> ((i % size_ratio) * BITS_PER_WORD))
1243 & (((HOST_WIDE_INT) 1
1244 << (BITS_PER_WORD % HOST_BITS_PER_WIDE_INT)) - 1));
1246 return GEN_INT (val);
1249 /* Similar to `operand_subword', but never return 0. If we can't extract
1250 the required subword, put OP into a register and try again. If that fails,
1251 abort. We always validate the address in this case. It is not valid
1252 to call this function after reload; it is mostly meant for RTL
1253 generation.
1255 MODE is the mode of OP, in case it is CONST_INT. */
1258 operand_subword_force (op, i, mode)
1259 rtx op;
1260 int i;
1261 enum machine_mode mode;
1263 rtx result = operand_subword (op, i, 1, mode);
1265 if (result)
1266 return result;
1268 if (mode != BLKmode && mode != VOIDmode)
1269 op = force_reg (mode, op);
1271 result = operand_subword (op, i, 1, mode);
1272 if (result == 0)
1273 abort ();
1275 return result;
1278 /* Given a compare instruction, swap the operands.
1279 A test instruction is changed into a compare of 0 against the operand. */
1281 void
1282 reverse_comparison (insn)
1283 rtx insn;
1285 rtx body = PATTERN (insn);
1286 rtx comp;
1288 if (GET_CODE (body) == SET)
1289 comp = SET_SRC (body);
1290 else
1291 comp = SET_SRC (XVECEXP (body, 0, 0));
1293 if (GET_CODE (comp) == COMPARE)
1295 rtx op0 = XEXP (comp, 0);
1296 rtx op1 = XEXP (comp, 1);
1297 XEXP (comp, 0) = op1;
1298 XEXP (comp, 1) = op0;
1300 else
1302 rtx new = gen_rtx (COMPARE, VOIDmode,
1303 CONST0_RTX (GET_MODE (comp)), comp);
1304 if (GET_CODE (body) == SET)
1305 SET_SRC (body) = new;
1306 else
1307 SET_SRC (XVECEXP (body, 0, 0)) = new;
1311 /* Return a memory reference like MEMREF, but with its mode changed
1312 to MODE and its address changed to ADDR.
1313 (VOIDmode means don't change the mode.
1314 NULL for ADDR means don't change the address.) */
1317 change_address (memref, mode, addr)
1318 rtx memref;
1319 enum machine_mode mode;
1320 rtx addr;
1322 rtx new;
1324 if (GET_CODE (memref) != MEM)
1325 abort ();
1326 if (mode == VOIDmode)
1327 mode = GET_MODE (memref);
1328 if (addr == 0)
1329 addr = XEXP (memref, 0);
1331 /* If reload is in progress or has completed, ADDR must be valid.
1332 Otherwise, we can call memory_address to make it valid. */
1333 if (reload_completed || reload_in_progress)
1335 if (! memory_address_p (mode, addr))
1336 abort ();
1338 else
1339 addr = memory_address (mode, addr);
1341 new = gen_rtx (MEM, mode, addr);
1342 MEM_VOLATILE_P (new) = MEM_VOLATILE_P (memref);
1343 RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (memref);
1344 MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (memref);
1345 return new;
1348 /* Return a newly created CODE_LABEL rtx with a unique label number. */
1351 gen_label_rtx ()
1353 register rtx label;
1355 label = (output_bytecode
1356 ? gen_rtx (CODE_LABEL, VOIDmode, NULL, bc_get_bytecode_label ())
1357 : gen_rtx (CODE_LABEL, VOIDmode, 0, 0, 0, label_num++, NULL_PTR));
1359 LABEL_NUSES (label) = 0;
1360 return label;
1363 /* For procedure integration. */
1365 /* Return a newly created INLINE_HEADER rtx. Should allocate this
1366 from a permanent obstack when the opportunity arises. */
1369 gen_inline_header_rtx (first_insn, first_parm_insn, first_labelno,
1370 last_labelno, max_parm_regnum, max_regnum, args_size,
1371 pops_args, stack_slots, forced_labels, function_flags,
1372 outgoing_args_size, original_arg_vector,
1373 original_decl_initial, regno_rtx, regno_flag,
1374 regno_align)
1375 rtx first_insn, first_parm_insn;
1376 int first_labelno, last_labelno, max_parm_regnum, max_regnum, args_size;
1377 int pops_args;
1378 rtx stack_slots;
1379 rtx forced_labels;
1380 int function_flags;
1381 int outgoing_args_size;
1382 rtvec original_arg_vector;
1383 rtx original_decl_initial;
1384 rtvec regno_rtx;
1385 char *regno_flag;
1386 char *regno_align;
1388 rtx header = gen_rtx (INLINE_HEADER, VOIDmode,
1389 cur_insn_uid++, NULL_RTX,
1390 first_insn, first_parm_insn,
1391 first_labelno, last_labelno,
1392 max_parm_regnum, max_regnum, args_size, pops_args,
1393 stack_slots, forced_labels, function_flags,
1394 outgoing_args_size, original_arg_vector,
1395 original_decl_initial,
1396 regno_rtx, regno_flag, regno_align);
1397 return header;
1400 /* Install new pointers to the first and last insns in the chain.
1401 Also, set cur_insn_uid to one higher than the last in use.
1402 Used for an inline-procedure after copying the insn chain. */
1404 void
1405 set_new_first_and_last_insn (first, last)
1406 rtx first, last;
1408 rtx insn;
1410 first_insn = first;
1411 last_insn = last;
1412 cur_insn_uid = 0;
1414 for (insn = first; insn; insn = NEXT_INSN (insn))
1415 cur_insn_uid = MAX (cur_insn_uid, INSN_UID (insn));
1417 cur_insn_uid++;
1420 /* Set the range of label numbers found in the current function.
1421 This is used when belatedly compiling an inline function. */
1423 void
1424 set_new_first_and_last_label_num (first, last)
1425 int first, last;
1427 base_label_num = label_num;
1428 first_label_num = first;
1429 last_label_num = last;
1432 /* Save all variables describing the current status into the structure *P.
1433 This is used before starting a nested function. */
1435 void
1436 save_emit_status (p)
1437 struct function *p;
1439 p->reg_rtx_no = reg_rtx_no;
1440 p->first_label_num = first_label_num;
1441 p->first_insn = first_insn;
1442 p->last_insn = last_insn;
1443 p->sequence_rtl_expr = sequence_rtl_expr;
1444 p->sequence_stack = sequence_stack;
1445 p->cur_insn_uid = cur_insn_uid;
1446 p->last_linenum = last_linenum;
1447 p->last_filename = last_filename;
1448 p->regno_pointer_flag = regno_pointer_flag;
1449 p->regno_pointer_align = regno_pointer_align;
1450 p->regno_pointer_flag_length = regno_pointer_flag_length;
1451 p->regno_reg_rtx = regno_reg_rtx;
1454 /* Restore all variables describing the current status from the structure *P.
1455 This is used after a nested function. */
1457 void
1458 restore_emit_status (p)
1459 struct function *p;
1461 int i;
1463 reg_rtx_no = p->reg_rtx_no;
1464 first_label_num = p->first_label_num;
1465 last_label_num = 0;
1466 first_insn = p->first_insn;
1467 last_insn = p->last_insn;
1468 sequence_rtl_expr = p->sequence_rtl_expr;
1469 sequence_stack = p->sequence_stack;
1470 cur_insn_uid = p->cur_insn_uid;
1471 last_linenum = p->last_linenum;
1472 last_filename = p->last_filename;
1473 regno_pointer_flag = p->regno_pointer_flag;
1474 regno_pointer_align = p->regno_pointer_align;
1475 regno_pointer_flag_length = p->regno_pointer_flag_length;
1476 regno_reg_rtx = p->regno_reg_rtx;
1478 /* Clear our cache of rtx expressions for start_sequence and gen_sequence. */
1479 sequence_element_free_list = 0;
1480 for (i = 0; i < SEQUENCE_RESULT_SIZE; i++)
1481 sequence_result[i] = 0;
1484 /* Go through all the RTL insn bodies and copy any invalid shared structure.
1485 It does not work to do this twice, because the mark bits set here
1486 are not cleared afterwards. */
1488 void
1489 unshare_all_rtl (insn)
1490 register rtx insn;
1492 for (; insn; insn = NEXT_INSN (insn))
1493 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
1494 || GET_CODE (insn) == CALL_INSN)
1496 PATTERN (insn) = copy_rtx_if_shared (PATTERN (insn));
1497 REG_NOTES (insn) = copy_rtx_if_shared (REG_NOTES (insn));
1498 LOG_LINKS (insn) = copy_rtx_if_shared (LOG_LINKS (insn));
1501 /* Make sure the addresses of stack slots found outside the insn chain
1502 (such as, in DECL_RTL of a variable) are not shared
1503 with the insn chain.
1505 This special care is necessary when the stack slot MEM does not
1506 actually appear in the insn chain. If it does appear, its address
1507 is unshared from all else at that point. */
1509 copy_rtx_if_shared (stack_slot_list);
1512 /* Mark ORIG as in use, and return a copy of it if it was already in use.
1513 Recursively does the same for subexpressions. */
1516 copy_rtx_if_shared (orig)
1517 rtx orig;
1519 register rtx x = orig;
1520 register int i;
1521 register enum rtx_code code;
1522 register char *format_ptr;
1523 int copied = 0;
1525 if (x == 0)
1526 return 0;
1528 code = GET_CODE (x);
1530 /* These types may be freely shared. */
1532 switch (code)
1534 case REG:
1535 case QUEUED:
1536 case CONST_INT:
1537 case CONST_DOUBLE:
1538 case SYMBOL_REF:
1539 case CODE_LABEL:
1540 case PC:
1541 case CC0:
1542 case SCRATCH:
1543 /* SCRATCH must be shared because they represent distinct values. */
1544 return x;
1546 case CONST:
1547 /* CONST can be shared if it contains a SYMBOL_REF. If it contains
1548 a LABEL_REF, it isn't sharable. */
1549 if (GET_CODE (XEXP (x, 0)) == PLUS
1550 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
1551 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
1552 return x;
1553 break;
1555 case INSN:
1556 case JUMP_INSN:
1557 case CALL_INSN:
1558 case NOTE:
1559 case BARRIER:
1560 /* The chain of insns is not being copied. */
1561 return x;
1563 case MEM:
1564 /* A MEM is allowed to be shared if its address is constant
1565 or is a constant plus one of the special registers. */
1566 if (CONSTANT_ADDRESS_P (XEXP (x, 0))
1567 || XEXP (x, 0) == virtual_stack_vars_rtx
1568 || XEXP (x, 0) == virtual_incoming_args_rtx)
1569 return x;
1571 if (GET_CODE (XEXP (x, 0)) == PLUS
1572 && (XEXP (XEXP (x, 0), 0) == virtual_stack_vars_rtx
1573 || XEXP (XEXP (x, 0), 0) == virtual_incoming_args_rtx)
1574 && CONSTANT_ADDRESS_P (XEXP (XEXP (x, 0), 1)))
1576 /* This MEM can appear in more than one place,
1577 but its address better not be shared with anything else. */
1578 if (! x->used)
1579 XEXP (x, 0) = copy_rtx_if_shared (XEXP (x, 0));
1580 x->used = 1;
1581 return x;
1585 /* This rtx may not be shared. If it has already been seen,
1586 replace it with a copy of itself. */
1588 if (x->used)
1590 register rtx copy;
1592 copy = rtx_alloc (code);
1593 bcopy ((char *) x, (char *) copy,
1594 (sizeof (*copy) - sizeof (copy->fld)
1595 + sizeof (copy->fld[0]) * GET_RTX_LENGTH (code)));
1596 x = copy;
1597 copied = 1;
1599 x->used = 1;
1601 /* Now scan the subexpressions recursively.
1602 We can store any replaced subexpressions directly into X
1603 since we know X is not shared! Any vectors in X
1604 must be copied if X was copied. */
1606 format_ptr = GET_RTX_FORMAT (code);
1608 for (i = 0; i < GET_RTX_LENGTH (code); i++)
1610 switch (*format_ptr++)
1612 case 'e':
1613 XEXP (x, i) = copy_rtx_if_shared (XEXP (x, i));
1614 break;
1616 case 'E':
1617 if (XVEC (x, i) != NULL)
1619 register int j;
1620 int len = XVECLEN (x, i);
1622 if (copied && len > 0)
1623 XVEC (x, i) = gen_rtvec_v (len, &XVECEXP (x, i, 0));
1624 for (j = 0; j < len; j++)
1625 XVECEXP (x, i, j) = copy_rtx_if_shared (XVECEXP (x, i, j));
1627 break;
1630 return x;
1633 /* Clear all the USED bits in X to allow copy_rtx_if_shared to be used
1634 to look for shared sub-parts. */
1636 void
1637 reset_used_flags (x)
1638 rtx x;
1640 register int i, j;
1641 register enum rtx_code code;
1642 register char *format_ptr;
1644 if (x == 0)
1645 return;
1647 code = GET_CODE (x);
1649 /* These types may be freely shared so we needn't do any resetting
1650 for them. */
1652 switch (code)
1654 case REG:
1655 case QUEUED:
1656 case CONST_INT:
1657 case CONST_DOUBLE:
1658 case SYMBOL_REF:
1659 case CODE_LABEL:
1660 case PC:
1661 case CC0:
1662 return;
1664 case INSN:
1665 case JUMP_INSN:
1666 case CALL_INSN:
1667 case NOTE:
1668 case LABEL_REF:
1669 case BARRIER:
1670 /* The chain of insns is not being copied. */
1671 return;
1674 x->used = 0;
1676 format_ptr = GET_RTX_FORMAT (code);
1677 for (i = 0; i < GET_RTX_LENGTH (code); i++)
1679 switch (*format_ptr++)
1681 case 'e':
1682 reset_used_flags (XEXP (x, i));
1683 break;
1685 case 'E':
1686 for (j = 0; j < XVECLEN (x, i); j++)
1687 reset_used_flags (XVECEXP (x, i, j));
1688 break;
1693 /* Copy X if necessary so that it won't be altered by changes in OTHER.
1694 Return X or the rtx for the pseudo reg the value of X was copied into.
1695 OTHER must be valid as a SET_DEST. */
1698 make_safe_from (x, other)
1699 rtx x, other;
1701 while (1)
1702 switch (GET_CODE (other))
1704 case SUBREG:
1705 other = SUBREG_REG (other);
1706 break;
1707 case STRICT_LOW_PART:
1708 case SIGN_EXTEND:
1709 case ZERO_EXTEND:
1710 other = XEXP (other, 0);
1711 break;
1712 default:
1713 goto done;
1715 done:
1716 if ((GET_CODE (other) == MEM
1717 && ! CONSTANT_P (x)
1718 && GET_CODE (x) != REG
1719 && GET_CODE (x) != SUBREG)
1720 || (GET_CODE (other) == REG
1721 && (REGNO (other) < FIRST_PSEUDO_REGISTER
1722 || reg_mentioned_p (other, x))))
1724 rtx temp = gen_reg_rtx (GET_MODE (x));
1725 emit_move_insn (temp, x);
1726 return temp;
1728 return x;
1731 /* Emission of insns (adding them to the doubly-linked list). */
1733 /* Return the first insn of the current sequence or current function. */
1736 get_insns ()
1738 return first_insn;
1741 /* Return the last insn emitted in current sequence or current function. */
1744 get_last_insn ()
1746 return last_insn;
1749 /* Specify a new insn as the last in the chain. */
1751 void
1752 set_last_insn (insn)
1753 rtx insn;
1755 if (NEXT_INSN (insn) != 0)
1756 abort ();
1757 last_insn = insn;
1760 /* Return the last insn emitted, even if it is in a sequence now pushed. */
1763 get_last_insn_anywhere ()
1765 struct sequence_stack *stack;
1766 if (last_insn)
1767 return last_insn;
1768 for (stack = sequence_stack; stack; stack = stack->next)
1769 if (stack->last != 0)
1770 return stack->last;
1771 return 0;
1774 /* Return a number larger than any instruction's uid in this function. */
1777 get_max_uid ()
1779 return cur_insn_uid;
1782 /* Return the next insn. If it is a SEQUENCE, return the first insn
1783 of the sequence. */
1786 next_insn (insn)
1787 rtx insn;
1789 if (insn)
1791 insn = NEXT_INSN (insn);
1792 if (insn && GET_CODE (insn) == INSN
1793 && GET_CODE (PATTERN (insn)) == SEQUENCE)
1794 insn = XVECEXP (PATTERN (insn), 0, 0);
1797 return insn;
1800 /* Return the previous insn. If it is a SEQUENCE, return the last insn
1801 of the sequence. */
1804 previous_insn (insn)
1805 rtx insn;
1807 if (insn)
1809 insn = PREV_INSN (insn);
1810 if (insn && GET_CODE (insn) == INSN
1811 && GET_CODE (PATTERN (insn)) == SEQUENCE)
1812 insn = XVECEXP (PATTERN (insn), 0, XVECLEN (PATTERN (insn), 0) - 1);
1815 return insn;
1818 /* Return the next insn after INSN that is not a NOTE. This routine does not
1819 look inside SEQUENCEs. */
1822 next_nonnote_insn (insn)
1823 rtx insn;
1825 while (insn)
1827 insn = NEXT_INSN (insn);
1828 if (insn == 0 || GET_CODE (insn) != NOTE)
1829 break;
1832 return insn;
1835 /* Return the previous insn before INSN that is not a NOTE. This routine does
1836 not look inside SEQUENCEs. */
1839 prev_nonnote_insn (insn)
1840 rtx insn;
1842 while (insn)
1844 insn = PREV_INSN (insn);
1845 if (insn == 0 || GET_CODE (insn) != NOTE)
1846 break;
1849 return insn;
1852 /* Return the next INSN, CALL_INSN or JUMP_INSN after INSN;
1853 or 0, if there is none. This routine does not look inside
1854 SEQUENCEs. */
1857 next_real_insn (insn)
1858 rtx insn;
1860 while (insn)
1862 insn = NEXT_INSN (insn);
1863 if (insn == 0 || GET_CODE (insn) == INSN
1864 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN)
1865 break;
1868 return insn;
1871 /* Return the last INSN, CALL_INSN or JUMP_INSN before INSN;
1872 or 0, if there is none. This routine does not look inside
1873 SEQUENCEs. */
1876 prev_real_insn (insn)
1877 rtx insn;
1879 while (insn)
1881 insn = PREV_INSN (insn);
1882 if (insn == 0 || GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
1883 || GET_CODE (insn) == JUMP_INSN)
1884 break;
1887 return insn;
1890 /* Find the next insn after INSN that really does something. This routine
1891 does not look inside SEQUENCEs. Until reload has completed, this is the
1892 same as next_real_insn. */
1895 next_active_insn (insn)
1896 rtx insn;
1898 while (insn)
1900 insn = NEXT_INSN (insn);
1901 if (insn == 0
1902 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN
1903 || (GET_CODE (insn) == INSN
1904 && (! reload_completed
1905 || (GET_CODE (PATTERN (insn)) != USE
1906 && GET_CODE (PATTERN (insn)) != CLOBBER))))
1907 break;
1910 return insn;
1913 /* Find the last insn before INSN that really does something. This routine
1914 does not look inside SEQUENCEs. Until reload has completed, this is the
1915 same as prev_real_insn. */
1918 prev_active_insn (insn)
1919 rtx insn;
1921 while (insn)
1923 insn = PREV_INSN (insn);
1924 if (insn == 0
1925 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN
1926 || (GET_CODE (insn) == INSN
1927 && (! reload_completed
1928 || (GET_CODE (PATTERN (insn)) != USE
1929 && GET_CODE (PATTERN (insn)) != CLOBBER))))
1930 break;
1933 return insn;
1936 /* Return the next CODE_LABEL after the insn INSN, or 0 if there is none. */
1939 next_label (insn)
1940 rtx insn;
1942 while (insn)
1944 insn = NEXT_INSN (insn);
1945 if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
1946 break;
1949 return insn;
1952 /* Return the last CODE_LABEL before the insn INSN, or 0 if there is none. */
1955 prev_label (insn)
1956 rtx insn;
1958 while (insn)
1960 insn = PREV_INSN (insn);
1961 if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
1962 break;
1965 return insn;
1968 #ifdef HAVE_cc0
1969 /* INSN uses CC0 and is being moved into a delay slot. Set up REG_CC_SETTER
1970 and REG_CC_USER notes so we can find it. */
1972 void
1973 link_cc0_insns (insn)
1974 rtx insn;
1976 rtx user = next_nonnote_insn (insn);
1978 if (GET_CODE (user) == INSN && GET_CODE (PATTERN (user)) == SEQUENCE)
1979 user = XVECEXP (PATTERN (user), 0, 0);
1981 REG_NOTES (user) = gen_rtx (INSN_LIST, REG_CC_SETTER, insn,
1982 REG_NOTES (user));
1983 REG_NOTES (insn) = gen_rtx (INSN_LIST, REG_CC_USER, user, REG_NOTES (insn));
1986 /* Return the next insn that uses CC0 after INSN, which is assumed to
1987 set it. This is the inverse of prev_cc0_setter (i.e., prev_cc0_setter
1988 applied to the result of this function should yield INSN).
1990 Normally, this is simply the next insn. However, if a REG_CC_USER note
1991 is present, it contains the insn that uses CC0.
1993 Return 0 if we can't find the insn. */
1996 next_cc0_user (insn)
1997 rtx insn;
1999 rtx note = find_reg_note (insn, REG_CC_USER, NULL_RTX);
2001 if (note)
2002 return XEXP (note, 0);
2004 insn = next_nonnote_insn (insn);
2005 if (insn && GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
2006 insn = XVECEXP (PATTERN (insn), 0, 0);
2008 if (insn && GET_RTX_CLASS (GET_CODE (insn)) == 'i'
2009 && reg_mentioned_p (cc0_rtx, PATTERN (insn)))
2010 return insn;
2012 return 0;
2015 /* Find the insn that set CC0 for INSN. Unless INSN has a REG_CC_SETTER
2016 note, it is the previous insn. */
2019 prev_cc0_setter (insn)
2020 rtx insn;
2022 rtx note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
2023 rtx link;
2025 if (note)
2026 return XEXP (note, 0);
2028 insn = prev_nonnote_insn (insn);
2029 if (! sets_cc0_p (PATTERN (insn)))
2030 abort ();
2032 return insn;
2034 #endif
2036 /* Try splitting insns that can be split for better scheduling.
2037 PAT is the pattern which might split.
2038 TRIAL is the insn providing PAT.
2039 LAST is non-zero if we should return the last insn of the sequence produced.
2041 If this routine succeeds in splitting, it returns the first or last
2042 replacement insn depending on the value of LAST. Otherwise, it
2043 returns TRIAL. If the insn to be returned can be split, it will be. */
2046 try_split (pat, trial, last)
2047 rtx pat, trial;
2048 int last;
2050 rtx before = PREV_INSN (trial);
2051 rtx after = NEXT_INSN (trial);
2052 rtx seq = split_insns (pat, trial);
2053 int has_barrier = 0;
2054 rtx tem;
2056 /* If we are splitting a JUMP_INSN, it might be followed by a BARRIER.
2057 We may need to handle this specially. */
2058 if (after && GET_CODE (after) == BARRIER)
2060 has_barrier = 1;
2061 after = NEXT_INSN (after);
2064 if (seq)
2066 /* SEQ can either be a SEQUENCE or the pattern of a single insn.
2067 The latter case will normally arise only when being done so that
2068 it, in turn, will be split (SFmode on the 29k is an example). */
2069 if (GET_CODE (seq) == SEQUENCE)
2071 /* If we are splitting a JUMP_INSN, look for the JUMP_INSN in
2072 SEQ and copy our JUMP_LABEL to it. If JUMP_LABEL is non-zero,
2073 increment the usage count so we don't delete the label. */
2074 int i;
2076 if (GET_CODE (trial) == JUMP_INSN)
2077 for (i = XVECLEN (seq, 0) - 1; i >= 0; i--)
2078 if (GET_CODE (XVECEXP (seq, 0, i)) == JUMP_INSN)
2080 JUMP_LABEL (XVECEXP (seq, 0, i)) = JUMP_LABEL (trial);
2082 if (JUMP_LABEL (trial))
2083 LABEL_NUSES (JUMP_LABEL (trial))++;
2086 tem = emit_insn_after (seq, before);
2088 delete_insn (trial);
2089 if (has_barrier)
2090 emit_barrier_after (tem);
2092 /* Recursively call try_split for each new insn created; by the
2093 time control returns here that insn will be fully split, so
2094 set LAST and continue from the insn after the one returned.
2095 We can't use next_active_insn here since AFTER may be a note.
2096 Ignore deleted insns, which can be occur if not optimizing. */
2097 for (tem = NEXT_INSN (before); tem != after;
2098 tem = NEXT_INSN (tem))
2099 if (! INSN_DELETED_P (tem))
2100 tem = try_split (PATTERN (tem), tem, 1);
2102 /* Avoid infinite loop if the result matches the original pattern. */
2103 else if (rtx_equal_p (seq, pat))
2104 return trial;
2105 else
2107 PATTERN (trial) = seq;
2108 INSN_CODE (trial) = -1;
2109 try_split (seq, trial, last);
2112 /* Return either the first or the last insn, depending on which was
2113 requested. */
2114 return last ? prev_active_insn (after) : next_active_insn (before);
2117 return trial;
2120 /* Make and return an INSN rtx, initializing all its slots.
2121 Store PATTERN in the pattern slots. */
2124 make_insn_raw (pattern)
2125 rtx pattern;
2127 register rtx insn;
2129 insn = rtx_alloc (INSN);
2130 INSN_UID (insn) = cur_insn_uid++;
2132 PATTERN (insn) = pattern;
2133 INSN_CODE (insn) = -1;
2134 LOG_LINKS (insn) = NULL;
2135 REG_NOTES (insn) = NULL;
2137 return insn;
2140 /* Like `make_insn' but make a JUMP_INSN instead of an insn. */
2142 static rtx
2143 make_jump_insn_raw (pattern)
2144 rtx pattern;
2146 register rtx insn;
2148 insn = rtx_alloc (JUMP_INSN);
2149 INSN_UID (insn) = cur_insn_uid++;
2151 PATTERN (insn) = pattern;
2152 INSN_CODE (insn) = -1;
2153 LOG_LINKS (insn) = NULL;
2154 REG_NOTES (insn) = NULL;
2155 JUMP_LABEL (insn) = NULL;
2157 return insn;
2160 /* Like `make_insn' but make a CALL_INSN instead of an insn. */
2162 static rtx
2163 make_call_insn_raw (pattern)
2164 rtx pattern;
2166 register rtx insn;
2168 insn = rtx_alloc (CALL_INSN);
2169 INSN_UID (insn) = cur_insn_uid++;
2171 PATTERN (insn) = pattern;
2172 INSN_CODE (insn) = -1;
2173 LOG_LINKS (insn) = NULL;
2174 REG_NOTES (insn) = NULL;
2175 CALL_INSN_FUNCTION_USAGE (insn) = NULL;
2177 return insn;
2180 /* Add INSN to the end of the doubly-linked list.
2181 INSN may be an INSN, JUMP_INSN, CALL_INSN, CODE_LABEL, BARRIER or NOTE. */
2183 void
2184 add_insn (insn)
2185 register rtx insn;
2187 PREV_INSN (insn) = last_insn;
2188 NEXT_INSN (insn) = 0;
2190 if (NULL != last_insn)
2191 NEXT_INSN (last_insn) = insn;
2193 if (NULL == first_insn)
2194 first_insn = insn;
2196 last_insn = insn;
2199 /* Add INSN into the doubly-linked list after insn AFTER. This and
2200 the next should be the only functions called to insert an insn once
2201 delay slots have been filled since only they know how to update a
2202 SEQUENCE. */
2204 void
2205 add_insn_after (insn, after)
2206 rtx insn, after;
2208 rtx next = NEXT_INSN (after);
2210 if (optimize && INSN_DELETED_P (after))
2211 abort ();
2213 NEXT_INSN (insn) = next;
2214 PREV_INSN (insn) = after;
2216 if (next)
2218 PREV_INSN (next) = insn;
2219 if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == SEQUENCE)
2220 PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = insn;
2222 else if (last_insn == after)
2223 last_insn = insn;
2224 else
2226 struct sequence_stack *stack = sequence_stack;
2227 /* Scan all pending sequences too. */
2228 for (; stack; stack = stack->next)
2229 if (after == stack->last)
2231 stack->last = insn;
2232 break;
2235 if (stack == 0)
2236 abort ();
2239 NEXT_INSN (after) = insn;
2240 if (GET_CODE (after) == INSN && GET_CODE (PATTERN (after)) == SEQUENCE)
2242 rtx sequence = PATTERN (after);
2243 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2247 /* Add INSN into the doubly-linked list before insn BEFORE. This and
2248 the previous should be the only functions called to insert an insn once
2249 delay slots have been filled since only they know how to update a
2250 SEQUENCE. */
2252 void
2253 add_insn_before (insn, before)
2254 rtx insn, before;
2256 rtx prev = PREV_INSN (before);
2258 if (optimize && INSN_DELETED_P (before))
2259 abort ();
2261 PREV_INSN (insn) = prev;
2262 NEXT_INSN (insn) = before;
2264 if (prev)
2266 NEXT_INSN (prev) = insn;
2267 if (GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == SEQUENCE)
2269 rtx sequence = PATTERN (prev);
2270 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2273 else if (first_insn == before)
2274 first_insn = insn;
2275 else
2277 struct sequence_stack *stack = sequence_stack;
2278 /* Scan all pending sequences too. */
2279 for (; stack; stack = stack->next)
2280 if (before == stack->first)
2282 stack->first = insn;
2283 break;
2286 if (stack == 0)
2287 abort ();
2290 PREV_INSN (before) = insn;
2291 if (GET_CODE (before) == INSN && GET_CODE (PATTERN (before)) == SEQUENCE)
2292 PREV_INSN (XVECEXP (PATTERN (before), 0, 0)) = insn;
2295 /* Delete all insns made since FROM.
2296 FROM becomes the new last instruction. */
2298 void
2299 delete_insns_since (from)
2300 rtx from;
2302 if (from == 0)
2303 first_insn = 0;
2304 else
2305 NEXT_INSN (from) = 0;
2306 last_insn = from;
2309 /* This function is deprecated, please use sequences instead.
2311 Move a consecutive bunch of insns to a different place in the chain.
2312 The insns to be moved are those between FROM and TO.
2313 They are moved to a new position after the insn AFTER.
2314 AFTER must not be FROM or TO or any insn in between.
2316 This function does not know about SEQUENCEs and hence should not be
2317 called after delay-slot filling has been done. */
2319 void
2320 reorder_insns (from, to, after)
2321 rtx from, to, after;
2323 /* Splice this bunch out of where it is now. */
2324 if (PREV_INSN (from))
2325 NEXT_INSN (PREV_INSN (from)) = NEXT_INSN (to);
2326 if (NEXT_INSN (to))
2327 PREV_INSN (NEXT_INSN (to)) = PREV_INSN (from);
2328 if (last_insn == to)
2329 last_insn = PREV_INSN (from);
2330 if (first_insn == from)
2331 first_insn = NEXT_INSN (to);
2333 /* Make the new neighbors point to it and it to them. */
2334 if (NEXT_INSN (after))
2335 PREV_INSN (NEXT_INSN (after)) = to;
2337 NEXT_INSN (to) = NEXT_INSN (after);
2338 PREV_INSN (from) = after;
2339 NEXT_INSN (after) = from;
2340 if (after == last_insn)
2341 last_insn = to;
2344 /* Return the line note insn preceding INSN. */
2346 static rtx
2347 find_line_note (insn)
2348 rtx insn;
2350 if (no_line_numbers)
2351 return 0;
2353 for (; insn; insn = PREV_INSN (insn))
2354 if (GET_CODE (insn) == NOTE
2355 && NOTE_LINE_NUMBER (insn) >= 0)
2356 break;
2358 return insn;
2361 /* Like reorder_insns, but inserts line notes to preserve the line numbers
2362 of the moved insns when debugging. This may insert a note between AFTER
2363 and FROM, and another one after TO. */
2365 void
2366 reorder_insns_with_line_notes (from, to, after)
2367 rtx from, to, after;
2369 rtx from_line = find_line_note (from);
2370 rtx after_line = find_line_note (after);
2372 reorder_insns (from, to, after);
2374 if (from_line == after_line)
2375 return;
2377 if (from_line)
2378 emit_line_note_after (NOTE_SOURCE_FILE (from_line),
2379 NOTE_LINE_NUMBER (from_line),
2380 after);
2381 if (after_line)
2382 emit_line_note_after (NOTE_SOURCE_FILE (after_line),
2383 NOTE_LINE_NUMBER (after_line),
2384 to);
2387 /* Emit an insn of given code and pattern
2388 at a specified place within the doubly-linked list. */
2390 /* Make an instruction with body PATTERN
2391 and output it before the instruction BEFORE. */
2394 emit_insn_before (pattern, before)
2395 register rtx pattern, before;
2397 register rtx insn = before;
2399 if (GET_CODE (pattern) == SEQUENCE)
2401 register int i;
2403 for (i = 0; i < XVECLEN (pattern, 0); i++)
2405 insn = XVECEXP (pattern, 0, i);
2406 add_insn_before (insn, before);
2408 if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
2409 sequence_result[XVECLEN (pattern, 0)] = pattern;
2411 else
2413 insn = make_insn_raw (pattern);
2414 add_insn_before (insn, before);
2417 return insn;
2420 /* Make an instruction with body PATTERN and code JUMP_INSN
2421 and output it before the instruction BEFORE. */
2424 emit_jump_insn_before (pattern, before)
2425 register rtx pattern, before;
2427 register rtx insn;
2429 if (GET_CODE (pattern) == SEQUENCE)
2430 insn = emit_insn_before (pattern, before);
2431 else
2433 insn = make_jump_insn_raw (pattern);
2434 add_insn_before (insn, before);
2437 return insn;
2440 /* Make an instruction with body PATTERN and code CALL_INSN
2441 and output it before the instruction BEFORE. */
2444 emit_call_insn_before (pattern, before)
2445 register rtx pattern, before;
2447 register rtx insn;
2449 if (GET_CODE (pattern) == SEQUENCE)
2450 insn = emit_insn_before (pattern, before);
2451 else
2453 insn = make_call_insn_raw (pattern);
2454 add_insn_before (insn, before);
2455 PUT_CODE (insn, CALL_INSN);
2458 return insn;
2461 /* Make an insn of code BARRIER
2462 and output it before the insn AFTER. */
2465 emit_barrier_before (before)
2466 register rtx before;
2468 register rtx insn = rtx_alloc (BARRIER);
2470 INSN_UID (insn) = cur_insn_uid++;
2472 add_insn_before (insn, before);
2473 return insn;
2476 /* Emit a note of subtype SUBTYPE before the insn BEFORE. */
2479 emit_note_before (subtype, before)
2480 int subtype;
2481 rtx before;
2483 register rtx note = rtx_alloc (NOTE);
2484 INSN_UID (note) = cur_insn_uid++;
2485 NOTE_SOURCE_FILE (note) = 0;
2486 NOTE_LINE_NUMBER (note) = subtype;
2488 add_insn_before (note, before);
2489 return note;
2492 /* Make an insn of code INSN with body PATTERN
2493 and output it after the insn AFTER. */
2496 emit_insn_after (pattern, after)
2497 register rtx pattern, after;
2499 register rtx insn = after;
2501 if (GET_CODE (pattern) == SEQUENCE)
2503 register int i;
2505 for (i = 0; i < XVECLEN (pattern, 0); i++)
2507 insn = XVECEXP (pattern, 0, i);
2508 add_insn_after (insn, after);
2509 after = insn;
2511 if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
2512 sequence_result[XVECLEN (pattern, 0)] = pattern;
2514 else
2516 insn = make_insn_raw (pattern);
2517 add_insn_after (insn, after);
2520 return insn;
2523 /* Similar to emit_insn_after, except that line notes are to be inserted so
2524 as to act as if this insn were at FROM. */
2526 void
2527 emit_insn_after_with_line_notes (pattern, after, from)
2528 rtx pattern, after, from;
2530 rtx from_line = find_line_note (from);
2531 rtx after_line = find_line_note (after);
2532 rtx insn = emit_insn_after (pattern, after);
2534 if (from_line)
2535 emit_line_note_after (NOTE_SOURCE_FILE (from_line),
2536 NOTE_LINE_NUMBER (from_line),
2537 after);
2539 if (after_line)
2540 emit_line_note_after (NOTE_SOURCE_FILE (after_line),
2541 NOTE_LINE_NUMBER (after_line),
2542 insn);
2545 /* Make an insn of code JUMP_INSN with body PATTERN
2546 and output it after the insn AFTER. */
2549 emit_jump_insn_after (pattern, after)
2550 register rtx pattern, after;
2552 register rtx insn;
2554 if (GET_CODE (pattern) == SEQUENCE)
2555 insn = emit_insn_after (pattern, after);
2556 else
2558 insn = make_jump_insn_raw (pattern);
2559 add_insn_after (insn, after);
2562 return insn;
2565 /* Make an insn of code BARRIER
2566 and output it after the insn AFTER. */
2569 emit_barrier_after (after)
2570 register rtx after;
2572 register rtx insn = rtx_alloc (BARRIER);
2574 INSN_UID (insn) = cur_insn_uid++;
2576 add_insn_after (insn, after);
2577 return insn;
2580 /* Emit the label LABEL after the insn AFTER. */
2583 emit_label_after (label, after)
2584 rtx label, after;
2586 /* This can be called twice for the same label
2587 as a result of the confusion that follows a syntax error!
2588 So make it harmless. */
2589 if (INSN_UID (label) == 0)
2591 INSN_UID (label) = cur_insn_uid++;
2592 add_insn_after (label, after);
2595 return label;
2598 /* Emit a note of subtype SUBTYPE after the insn AFTER. */
2601 emit_note_after (subtype, after)
2602 int subtype;
2603 rtx after;
2605 register rtx note = rtx_alloc (NOTE);
2606 INSN_UID (note) = cur_insn_uid++;
2607 NOTE_SOURCE_FILE (note) = 0;
2608 NOTE_LINE_NUMBER (note) = subtype;
2609 add_insn_after (note, after);
2610 return note;
2613 /* Emit a line note for FILE and LINE after the insn AFTER. */
2616 emit_line_note_after (file, line, after)
2617 char *file;
2618 int line;
2619 rtx after;
2621 register rtx note;
2623 if (no_line_numbers && line > 0)
2625 cur_insn_uid++;
2626 return 0;
2629 note = rtx_alloc (NOTE);
2630 INSN_UID (note) = cur_insn_uid++;
2631 NOTE_SOURCE_FILE (note) = file;
2632 NOTE_LINE_NUMBER (note) = line;
2633 add_insn_after (note, after);
2634 return note;
2637 /* Make an insn of code INSN with pattern PATTERN
2638 and add it to the end of the doubly-linked list.
2639 If PATTERN is a SEQUENCE, take the elements of it
2640 and emit an insn for each element.
2642 Returns the last insn emitted. */
2645 emit_insn (pattern)
2646 rtx pattern;
2648 rtx insn = last_insn;
2650 if (GET_CODE (pattern) == SEQUENCE)
2652 register int i;
2654 for (i = 0; i < XVECLEN (pattern, 0); i++)
2656 insn = XVECEXP (pattern, 0, i);
2657 add_insn (insn);
2659 if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
2660 sequence_result[XVECLEN (pattern, 0)] = pattern;
2662 else
2664 insn = make_insn_raw (pattern);
2665 add_insn (insn);
2668 return insn;
2671 /* Emit the insns in a chain starting with INSN.
2672 Return the last insn emitted. */
2675 emit_insns (insn)
2676 rtx insn;
2678 rtx last = 0;
2680 while (insn)
2682 rtx next = NEXT_INSN (insn);
2683 add_insn (insn);
2684 last = insn;
2685 insn = next;
2688 return last;
2691 /* Emit the insns in a chain starting with INSN and place them in front of
2692 the insn BEFORE. Return the last insn emitted. */
2695 emit_insns_before (insn, before)
2696 rtx insn;
2697 rtx before;
2699 rtx last = 0;
2701 while (insn)
2703 rtx next = NEXT_INSN (insn);
2704 add_insn_before (insn, before);
2705 last = insn;
2706 insn = next;
2709 return last;
2712 /* Emit the insns in a chain starting with FIRST and place them in back of
2713 the insn AFTER. Return the last insn emitted. */
2716 emit_insns_after (first, after)
2717 register rtx first;
2718 register rtx after;
2720 register rtx last;
2721 register rtx after_after;
2723 if (!after)
2724 abort ();
2726 if (!first)
2727 return first;
2729 for (last = first; NEXT_INSN (last); last = NEXT_INSN (last))
2730 continue;
2732 after_after = NEXT_INSN (after);
2734 NEXT_INSN (after) = first;
2735 PREV_INSN (first) = after;
2736 NEXT_INSN (last) = after_after;
2737 if (after_after)
2738 PREV_INSN (after_after) = last;
2740 if (after == last_insn)
2741 last_insn = last;
2742 return last;
2745 /* Make an insn of code JUMP_INSN with pattern PATTERN
2746 and add it to the end of the doubly-linked list. */
2749 emit_jump_insn (pattern)
2750 rtx pattern;
2752 if (GET_CODE (pattern) == SEQUENCE)
2753 return emit_insn (pattern);
2754 else
2756 register rtx insn = make_jump_insn_raw (pattern);
2757 add_insn (insn);
2758 return insn;
2762 /* Make an insn of code CALL_INSN with pattern PATTERN
2763 and add it to the end of the doubly-linked list. */
2766 emit_call_insn (pattern)
2767 rtx pattern;
2769 if (GET_CODE (pattern) == SEQUENCE)
2770 return emit_insn (pattern);
2771 else
2773 register rtx insn = make_call_insn_raw (pattern);
2774 add_insn (insn);
2775 PUT_CODE (insn, CALL_INSN);
2776 return insn;
2780 /* Add the label LABEL to the end of the doubly-linked list. */
2783 emit_label (label)
2784 rtx label;
2786 /* This can be called twice for the same label
2787 as a result of the confusion that follows a syntax error!
2788 So make it harmless. */
2789 if (INSN_UID (label) == 0)
2791 INSN_UID (label) = cur_insn_uid++;
2792 add_insn (label);
2794 return label;
2797 /* Make an insn of code BARRIER
2798 and add it to the end of the doubly-linked list. */
2801 emit_barrier ()
2803 register rtx barrier = rtx_alloc (BARRIER);
2804 INSN_UID (barrier) = cur_insn_uid++;
2805 add_insn (barrier);
2806 return barrier;
2809 /* Make an insn of code NOTE
2810 with data-fields specified by FILE and LINE
2811 and add it to the end of the doubly-linked list,
2812 but only if line-numbers are desired for debugging info. */
2815 emit_line_note (file, line)
2816 char *file;
2817 int line;
2819 if (output_bytecode)
2821 /* FIXME: for now we do nothing, but eventually we will have to deal with
2822 debugging information. */
2823 return 0;
2826 emit_filename = file;
2827 emit_lineno = line;
2829 #if 0
2830 if (no_line_numbers)
2831 return 0;
2832 #endif
2834 return emit_note (file, line);
2837 /* Make an insn of code NOTE
2838 with data-fields specified by FILE and LINE
2839 and add it to the end of the doubly-linked list.
2840 If it is a line-number NOTE, omit it if it matches the previous one. */
2843 emit_note (file, line)
2844 char *file;
2845 int line;
2847 register rtx note;
2849 if (line > 0)
2851 if (file && last_filename && !strcmp (file, last_filename)
2852 && line == last_linenum)
2853 return 0;
2854 last_filename = file;
2855 last_linenum = line;
2858 if (no_line_numbers && line > 0)
2860 cur_insn_uid++;
2861 return 0;
2864 note = rtx_alloc (NOTE);
2865 INSN_UID (note) = cur_insn_uid++;
2866 NOTE_SOURCE_FILE (note) = file;
2867 NOTE_LINE_NUMBER (note) = line;
2868 add_insn (note);
2869 return note;
2872 /* Emit a NOTE, and don't omit it even if LINE it the previous note. */
2875 emit_line_note_force (file, line)
2876 char *file;
2877 int line;
2879 last_linenum = -1;
2880 return emit_line_note (file, line);
2883 /* Cause next statement to emit a line note even if the line number
2884 has not changed. This is used at the beginning of a function. */
2886 void
2887 force_next_line_note ()
2889 last_linenum = -1;
2892 /* Return an indication of which type of insn should have X as a body.
2893 The value is CODE_LABEL, INSN, CALL_INSN or JUMP_INSN. */
2895 enum rtx_code
2896 classify_insn (x)
2897 rtx x;
2899 if (GET_CODE (x) == CODE_LABEL)
2900 return CODE_LABEL;
2901 if (GET_CODE (x) == CALL)
2902 return CALL_INSN;
2903 if (GET_CODE (x) == RETURN)
2904 return JUMP_INSN;
2905 if (GET_CODE (x) == SET)
2907 if (SET_DEST (x) == pc_rtx)
2908 return JUMP_INSN;
2909 else if (GET_CODE (SET_SRC (x)) == CALL)
2910 return CALL_INSN;
2911 else
2912 return INSN;
2914 if (GET_CODE (x) == PARALLEL)
2916 register int j;
2917 for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
2918 if (GET_CODE (XVECEXP (x, 0, j)) == CALL)
2919 return CALL_INSN;
2920 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
2921 && SET_DEST (XVECEXP (x, 0, j)) == pc_rtx)
2922 return JUMP_INSN;
2923 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
2924 && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == CALL)
2925 return CALL_INSN;
2927 return INSN;
2930 /* Emit the rtl pattern X as an appropriate kind of insn.
2931 If X is a label, it is simply added into the insn chain. */
2934 emit (x)
2935 rtx x;
2937 enum rtx_code code = classify_insn (x);
2939 if (code == CODE_LABEL)
2940 return emit_label (x);
2941 else if (code == INSN)
2942 return emit_insn (x);
2943 else if (code == JUMP_INSN)
2945 register rtx insn = emit_jump_insn (x);
2946 if (simplejump_p (insn) || GET_CODE (x) == RETURN)
2947 return emit_barrier ();
2948 return insn;
2950 else if (code == CALL_INSN)
2951 return emit_call_insn (x);
2952 else
2953 abort ();
2956 /* Begin emitting insns to a sequence which can be packaged in an RTL_EXPR. */
2958 void
2959 start_sequence ()
2961 struct sequence_stack *tem;
2963 if (sequence_element_free_list)
2965 /* Reuse a previously-saved struct sequence_stack. */
2966 tem = sequence_element_free_list;
2967 sequence_element_free_list = tem->next;
2969 else
2970 tem = (struct sequence_stack *) permalloc (sizeof (struct sequence_stack));
2972 tem->next = sequence_stack;
2973 tem->first = first_insn;
2974 tem->last = last_insn;
2975 tem->sequence_rtl_expr = sequence_rtl_expr;
2977 sequence_stack = tem;
2979 first_insn = 0;
2980 last_insn = 0;
2983 /* Similarly, but indicate that this sequence will be placed in
2984 T, an RTL_EXPR. */
2986 void
2987 start_sequence_for_rtl_expr (t)
2988 tree t;
2990 start_sequence ();
2992 sequence_rtl_expr = t;
2995 /* Set up the insn chain starting with FIRST
2996 as the current sequence, saving the previously current one. */
2998 void
2999 push_to_sequence (first)
3000 rtx first;
3002 rtx last;
3004 start_sequence ();
3006 for (last = first; last && NEXT_INSN (last); last = NEXT_INSN (last));
3008 first_insn = first;
3009 last_insn = last;
3012 /* Set up the outer-level insn chain
3013 as the current sequence, saving the previously current one. */
3015 void
3016 push_topmost_sequence ()
3018 struct sequence_stack *stack, *top;
3020 start_sequence ();
3022 for (stack = sequence_stack; stack; stack = stack->next)
3023 top = stack;
3025 first_insn = top->first;
3026 last_insn = top->last;
3027 sequence_rtl_expr = top->sequence_rtl_expr;
3030 /* After emitting to the outer-level insn chain, update the outer-level
3031 insn chain, and restore the previous saved state. */
3033 void
3034 pop_topmost_sequence ()
3036 struct sequence_stack *stack, *top;
3038 for (stack = sequence_stack; stack; stack = stack->next)
3039 top = stack;
3041 top->first = first_insn;
3042 top->last = last_insn;
3043 /* ??? Why don't we save sequence_rtl_expr here? */
3045 end_sequence ();
3048 /* After emitting to a sequence, restore previous saved state.
3050 To get the contents of the sequence just made,
3051 you must call `gen_sequence' *before* calling here. */
3053 void
3054 end_sequence ()
3056 struct sequence_stack *tem = sequence_stack;
3058 first_insn = tem->first;
3059 last_insn = tem->last;
3060 sequence_rtl_expr = tem->sequence_rtl_expr;
3061 sequence_stack = tem->next;
3063 tem->next = sequence_element_free_list;
3064 sequence_element_free_list = tem;
3067 /* Return 1 if currently emitting into a sequence. */
3070 in_sequence_p ()
3072 return sequence_stack != 0;
3075 /* Generate a SEQUENCE rtx containing the insns already emitted
3076 to the current sequence.
3078 This is how the gen_... function from a DEFINE_EXPAND
3079 constructs the SEQUENCE that it returns. */
3082 gen_sequence ()
3084 rtx result;
3085 rtx tem;
3086 int i;
3087 int len;
3089 /* Count the insns in the chain. */
3090 len = 0;
3091 for (tem = first_insn; tem; tem = NEXT_INSN (tem))
3092 len++;
3094 /* If only one insn, return its pattern rather than a SEQUENCE.
3095 (Now that we cache SEQUENCE expressions, it isn't worth special-casing
3096 the case of an empty list.) */
3097 if (len == 1
3098 && (GET_CODE (first_insn) == INSN
3099 || GET_CODE (first_insn) == JUMP_INSN
3100 /* Don't discard the call usage field. */
3101 || (GET_CODE (first_insn) == CALL_INSN
3102 && CALL_INSN_FUNCTION_USAGE (first_insn) == NULL_RTX)))
3103 return PATTERN (first_insn);
3105 /* Put them in a vector. See if we already have a SEQUENCE of the
3106 appropriate length around. */
3107 if (len < SEQUENCE_RESULT_SIZE && (result = sequence_result[len]) != 0)
3108 sequence_result[len] = 0;
3109 else
3111 /* Ensure that this rtl goes in saveable_obstack, since we may
3112 cache it. */
3113 push_obstacks_nochange ();
3114 rtl_in_saveable_obstack ();
3115 result = gen_rtx (SEQUENCE, VOIDmode, rtvec_alloc (len));
3116 pop_obstacks ();
3119 for (i = 0, tem = first_insn; tem; tem = NEXT_INSN (tem), i++)
3120 XVECEXP (result, 0, i) = tem;
3122 return result;
3125 /* Initialize data structures and variables in this file
3126 before generating rtl for each function. */
3128 void
3129 init_emit ()
3131 int i;
3133 first_insn = NULL;
3134 last_insn = NULL;
3135 sequence_rtl_expr = NULL;
3136 cur_insn_uid = 1;
3137 reg_rtx_no = LAST_VIRTUAL_REGISTER + 1;
3138 last_linenum = 0;
3139 last_filename = 0;
3140 first_label_num = label_num;
3141 last_label_num = 0;
3142 sequence_stack = NULL;
3144 /* Clear the start_sequence/gen_sequence cache. */
3145 sequence_element_free_list = 0;
3146 for (i = 0; i < SEQUENCE_RESULT_SIZE; i++)
3147 sequence_result[i] = 0;
3149 /* Init the tables that describe all the pseudo regs. */
3151 regno_pointer_flag_length = LAST_VIRTUAL_REGISTER + 101;
3153 regno_pointer_flag
3154 = (char *) savealloc (regno_pointer_flag_length);
3155 bzero (regno_pointer_flag, regno_pointer_flag_length);
3157 regno_pointer_align
3158 = (char *) savealloc (regno_pointer_flag_length);
3159 bzero (regno_pointer_align, regno_pointer_flag_length);
3161 regno_reg_rtx
3162 = (rtx *) savealloc (regno_pointer_flag_length * sizeof (rtx));
3163 bzero ((char *) regno_reg_rtx, regno_pointer_flag_length * sizeof (rtx));
3165 /* Put copies of all the virtual register rtx into regno_reg_rtx. */
3166 regno_reg_rtx[VIRTUAL_INCOMING_ARGS_REGNUM] = virtual_incoming_args_rtx;
3167 regno_reg_rtx[VIRTUAL_STACK_VARS_REGNUM] = virtual_stack_vars_rtx;
3168 regno_reg_rtx[VIRTUAL_STACK_DYNAMIC_REGNUM] = virtual_stack_dynamic_rtx;
3169 regno_reg_rtx[VIRTUAL_OUTGOING_ARGS_REGNUM] = virtual_outgoing_args_rtx;
3171 /* Indicate that the virtual registers and stack locations are
3172 all pointers. */
3173 REGNO_POINTER_FLAG (STACK_POINTER_REGNUM) = 1;
3174 REGNO_POINTER_FLAG (FRAME_POINTER_REGNUM) = 1;
3175 REGNO_POINTER_FLAG (HARD_FRAME_POINTER_REGNUM) = 1;
3176 REGNO_POINTER_FLAG (ARG_POINTER_REGNUM) = 1;
3178 REGNO_POINTER_FLAG (VIRTUAL_INCOMING_ARGS_REGNUM) = 1;
3179 REGNO_POINTER_FLAG (VIRTUAL_STACK_VARS_REGNUM) = 1;
3180 REGNO_POINTER_FLAG (VIRTUAL_STACK_DYNAMIC_REGNUM) = 1;
3181 REGNO_POINTER_FLAG (VIRTUAL_OUTGOING_ARGS_REGNUM) = 1;
3183 #ifdef STACK_BOUNDARY
3184 REGNO_POINTER_ALIGN (STACK_POINTER_REGNUM) = STACK_BOUNDARY / BITS_PER_UNIT;
3185 REGNO_POINTER_ALIGN (FRAME_POINTER_REGNUM) = STACK_BOUNDARY / BITS_PER_UNIT;
3186 REGNO_POINTER_ALIGN (HARD_FRAME_POINTER_REGNUM)
3187 = STACK_BOUNDARY / BITS_PER_UNIT;
3188 REGNO_POINTER_ALIGN (ARG_POINTER_REGNUM) = STACK_BOUNDARY / BITS_PER_UNIT;
3190 REGNO_POINTER_ALIGN (VIRTUAL_INCOMING_ARGS_REGNUM)
3191 = STACK_BOUNDARY / BITS_PER_UNIT;
3192 REGNO_POINTER_ALIGN (VIRTUAL_STACK_VARS_REGNUM)
3193 = STACK_BOUNDARY / BITS_PER_UNIT;
3194 REGNO_POINTER_ALIGN (VIRTUAL_STACK_DYNAMIC_REGNUM)
3195 = STACK_BOUNDARY / BITS_PER_UNIT;
3196 REGNO_POINTER_ALIGN (VIRTUAL_OUTGOING_ARGS_REGNUM)
3197 = STACK_BOUNDARY / BITS_PER_UNIT;
3198 #endif
3200 #ifdef INIT_EXPANDERS
3201 INIT_EXPANDERS;
3202 #endif
3205 /* Create some permanent unique rtl objects shared between all functions.
3206 LINE_NUMBERS is nonzero if line numbers are to be generated. */
3208 void
3209 init_emit_once (line_numbers)
3210 int line_numbers;
3212 int i;
3213 enum machine_mode mode;
3215 no_line_numbers = ! line_numbers;
3217 sequence_stack = NULL;
3219 /* Compute the word and byte modes. */
3221 byte_mode = VOIDmode;
3222 word_mode = VOIDmode;
3224 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
3225 mode = GET_MODE_WIDER_MODE (mode))
3227 if (GET_MODE_BITSIZE (mode) == BITS_PER_UNIT
3228 && byte_mode == VOIDmode)
3229 byte_mode = mode;
3231 if (GET_MODE_BITSIZE (mode) == BITS_PER_WORD
3232 && word_mode == VOIDmode)
3233 word_mode = mode;
3236 ptr_mode = mode_for_size (POINTER_SIZE, GET_MODE_CLASS (Pmode), 0);
3238 /* Create the unique rtx's for certain rtx codes and operand values. */
3240 pc_rtx = gen_rtx (PC, VOIDmode);
3241 cc0_rtx = gen_rtx (CC0, VOIDmode);
3243 /* Don't use gen_rtx here since gen_rtx in this case
3244 tries to use these variables. */
3245 for (i = - MAX_SAVED_CONST_INT; i <= MAX_SAVED_CONST_INT; i++)
3247 const_int_rtx[i + MAX_SAVED_CONST_INT] = rtx_alloc (CONST_INT);
3248 PUT_MODE (const_int_rtx[i + MAX_SAVED_CONST_INT], VOIDmode);
3249 INTVAL (const_int_rtx[i + MAX_SAVED_CONST_INT]) = i;
3252 /* These four calls obtain some of the rtx expressions made above. */
3253 const0_rtx = GEN_INT (0);
3254 const1_rtx = GEN_INT (1);
3255 const2_rtx = GEN_INT (2);
3256 constm1_rtx = GEN_INT (-1);
3258 /* This will usually be one of the above constants, but may be a new rtx. */
3259 const_true_rtx = GEN_INT (STORE_FLAG_VALUE);
3261 dconst0 = REAL_VALUE_ATOF ("0", DFmode);
3262 dconst1 = REAL_VALUE_ATOF ("1", DFmode);
3263 dconst2 = REAL_VALUE_ATOF ("2", DFmode);
3264 dconstm1 = REAL_VALUE_ATOF ("-1", DFmode);
3266 for (i = 0; i <= 2; i++)
3268 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
3269 mode = GET_MODE_WIDER_MODE (mode))
3271 rtx tem = rtx_alloc (CONST_DOUBLE);
3272 union real_extract u;
3274 bzero ((char *) &u, sizeof u); /* Zero any holes in a structure. */
3275 u.d = i == 0 ? dconst0 : i == 1 ? dconst1 : dconst2;
3277 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (tem), sizeof u);
3278 CONST_DOUBLE_MEM (tem) = cc0_rtx;
3279 PUT_MODE (tem, mode);
3281 const_tiny_rtx[i][(int) mode] = tem;
3284 const_tiny_rtx[i][(int) VOIDmode] = GEN_INT (i);
3286 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
3287 mode = GET_MODE_WIDER_MODE (mode))
3288 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
3290 for (mode = GET_CLASS_NARROWEST_MODE (MODE_PARTIAL_INT);
3291 mode != VOIDmode;
3292 mode = GET_MODE_WIDER_MODE (mode))
3293 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
3296 for (mode = GET_CLASS_NARROWEST_MODE (MODE_CC); mode != VOIDmode;
3297 mode = GET_MODE_WIDER_MODE (mode))
3298 const_tiny_rtx[0][(int) mode] = const0_rtx;
3300 stack_pointer_rtx = gen_rtx (REG, Pmode, STACK_POINTER_REGNUM);
3301 frame_pointer_rtx = gen_rtx (REG, Pmode, FRAME_POINTER_REGNUM);
3303 if (HARD_FRAME_POINTER_REGNUM == FRAME_POINTER_REGNUM)
3304 hard_frame_pointer_rtx = frame_pointer_rtx;
3305 else
3306 hard_frame_pointer_rtx = gen_rtx (REG, Pmode, HARD_FRAME_POINTER_REGNUM);
3308 if (FRAME_POINTER_REGNUM == ARG_POINTER_REGNUM)
3309 arg_pointer_rtx = frame_pointer_rtx;
3310 else if (HARD_FRAME_POINTER_REGNUM == ARG_POINTER_REGNUM)
3311 arg_pointer_rtx = hard_frame_pointer_rtx;
3312 else if (STACK_POINTER_REGNUM == ARG_POINTER_REGNUM)
3313 arg_pointer_rtx = stack_pointer_rtx;
3314 else
3315 arg_pointer_rtx = gen_rtx (REG, Pmode, ARG_POINTER_REGNUM);
3317 #ifdef RETURN_ADDRESS_POINTER_REGNUM
3318 return_address_pointer_rtx = gen_rtx (REG, Pmode,
3319 RETURN_ADDRESS_POINTER_REGNUM);
3320 #endif
3322 /* Create the virtual registers. Do so here since the following objects
3323 might reference them. */
3325 virtual_incoming_args_rtx = gen_rtx (REG, Pmode,
3326 VIRTUAL_INCOMING_ARGS_REGNUM);
3327 virtual_stack_vars_rtx = gen_rtx (REG, Pmode,
3328 VIRTUAL_STACK_VARS_REGNUM);
3329 virtual_stack_dynamic_rtx = gen_rtx (REG, Pmode,
3330 VIRTUAL_STACK_DYNAMIC_REGNUM);
3331 virtual_outgoing_args_rtx = gen_rtx (REG, Pmode,
3332 VIRTUAL_OUTGOING_ARGS_REGNUM);
3334 #ifdef STRUCT_VALUE
3335 struct_value_rtx = STRUCT_VALUE;
3336 #else
3337 struct_value_rtx = gen_rtx (REG, Pmode, STRUCT_VALUE_REGNUM);
3338 #endif
3340 #ifdef STRUCT_VALUE_INCOMING
3341 struct_value_incoming_rtx = STRUCT_VALUE_INCOMING;
3342 #else
3343 #ifdef STRUCT_VALUE_INCOMING_REGNUM
3344 struct_value_incoming_rtx
3345 = gen_rtx (REG, Pmode, STRUCT_VALUE_INCOMING_REGNUM);
3346 #else
3347 struct_value_incoming_rtx = struct_value_rtx;
3348 #endif
3349 #endif
3351 #ifdef STATIC_CHAIN_REGNUM
3352 static_chain_rtx = gen_rtx (REG, Pmode, STATIC_CHAIN_REGNUM);
3354 #ifdef STATIC_CHAIN_INCOMING_REGNUM
3355 if (STATIC_CHAIN_INCOMING_REGNUM != STATIC_CHAIN_REGNUM)
3356 static_chain_incoming_rtx = gen_rtx (REG, Pmode, STATIC_CHAIN_INCOMING_REGNUM);
3357 else
3358 #endif
3359 static_chain_incoming_rtx = static_chain_rtx;
3360 #endif
3362 #ifdef STATIC_CHAIN
3363 static_chain_rtx = STATIC_CHAIN;
3365 #ifdef STATIC_CHAIN_INCOMING
3366 static_chain_incoming_rtx = STATIC_CHAIN_INCOMING;
3367 #else
3368 static_chain_incoming_rtx = static_chain_rtx;
3369 #endif
3370 #endif
3372 #ifdef PIC_OFFSET_TABLE_REGNUM
3373 pic_offset_table_rtx = gen_rtx (REG, Pmode, PIC_OFFSET_TABLE_REGNUM);
3374 #endif