* except.c (expand_start_all_catch): One more do_pending_stack_adjust.
[official-gcc.git] / gcc / emit-rtl.c
blob50c6597281902e79b6e6a23feb1718cd39be0347
1 /* Emit RTL for the GNU C-Compiler expander.
2 Copyright (C) 1987, 88, 92-96, 1997 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 "except.h"
47 #include "function.h"
48 #include "expr.h"
49 #include "regs.h"
50 #include "insn-config.h"
51 #include "real.h"
52 #include "obstack.h"
54 #include "bytecode.h"
55 #include "machmode.h"
56 #include "bc-opcode.h"
57 #include "bc-typecd.h"
58 #include "bc-optab.h"
59 #include "bc-emit.h"
61 #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 /* During RTL generation, we also keep a list of free INSN rtl codes. */
253 static rtx free_insn;
255 extern int rtx_equal_function_value_matters;
257 /* Filename and line number of last line-number note,
258 whether we actually emitted it or not. */
259 extern char *emit_filename;
260 extern int emit_lineno;
262 /* rtx gen_rtx (code, mode, [element1, ..., elementn])
264 ** This routine generates an RTX of the size specified by
265 ** <code>, which is an RTX code. The RTX structure is initialized
266 ** from the arguments <element1> through <elementn>, which are
267 ** interpreted according to the specific RTX type's format. The
268 ** special machine mode associated with the rtx (if any) is specified
269 ** in <mode>.
271 ** gen_rtx can be invoked in a way which resembles the lisp-like
272 ** rtx it will generate. For example, the following rtx structure:
274 ** (plus:QI (mem:QI (reg:SI 1))
275 ** (mem:QI (plusw:SI (reg:SI 2) (reg:SI 3))))
277 ** ...would be generated by the following C code:
279 ** gen_rtx (PLUS, QImode,
280 ** gen_rtx (MEM, QImode,
281 ** gen_rtx (REG, SImode, 1)),
282 ** gen_rtx (MEM, QImode,
283 ** gen_rtx (PLUS, SImode,
284 ** gen_rtx (REG, SImode, 2),
285 ** gen_rtx (REG, SImode, 3)))),
288 /*VARARGS2*/
290 gen_rtx VPROTO((enum rtx_code code, enum machine_mode mode, ...))
292 #ifndef __STDC__
293 enum rtx_code code;
294 enum machine_mode mode;
295 #endif
296 va_list p;
297 register int i; /* Array indices... */
298 register char *fmt; /* Current rtx's format... */
299 register rtx rt_val; /* RTX to return to caller... */
301 VA_START (p, mode);
303 #ifndef __STDC__
304 code = va_arg (p, enum rtx_code);
305 mode = va_arg (p, enum machine_mode);
306 #endif
308 if (code == CONST_INT)
310 HOST_WIDE_INT arg = va_arg (p, HOST_WIDE_INT);
312 if (arg >= - MAX_SAVED_CONST_INT && arg <= MAX_SAVED_CONST_INT)
313 return const_int_rtx[arg + MAX_SAVED_CONST_INT];
315 if (const_true_rtx && arg == STORE_FLAG_VALUE)
316 return const_true_rtx;
318 rt_val = rtx_alloc (code);
319 INTVAL (rt_val) = arg;
321 else if (code == REG)
323 int regno = va_arg (p, int);
325 /* In case the MD file explicitly references the frame pointer, have
326 all such references point to the same frame pointer. This is used
327 during frame pointer elimination to distinguish the explicit
328 references to these registers from pseudos that happened to be
329 assigned to them.
331 If we have eliminated the frame pointer or arg pointer, we will
332 be using it as a normal register, for example as a spill register.
333 In such cases, we might be accessing it in a mode that is not
334 Pmode and therefore cannot use the pre-allocated rtx.
336 Also don't do this when we are making new REGs in reload,
337 since we don't want to get confused with the real pointers. */
339 if (frame_pointer_rtx && regno == FRAME_POINTER_REGNUM && mode == Pmode
340 && ! reload_in_progress)
341 return frame_pointer_rtx;
342 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
343 if (hard_frame_pointer_rtx && regno == HARD_FRAME_POINTER_REGNUM
344 && mode == Pmode && ! reload_in_progress)
345 return hard_frame_pointer_rtx;
346 #endif
347 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM && HARD_FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
348 if (arg_pointer_rtx && regno == ARG_POINTER_REGNUM && mode == Pmode
349 && ! reload_in_progress)
350 return arg_pointer_rtx;
351 #endif
352 #ifdef RETURN_ADDRESS_POINTER_REGNUM
353 if (return_address_pointer_rtx && regno == RETURN_ADDRESS_POINTER_REGNUM
354 && mode == Pmode && ! reload_in_progress)
355 return return_address_pointer_rtx;
356 #endif
357 if (stack_pointer_rtx && regno == STACK_POINTER_REGNUM && mode == Pmode
358 && ! reload_in_progress)
359 return stack_pointer_rtx;
360 else
362 rt_val = rtx_alloc (code);
363 rt_val->mode = mode;
364 REGNO (rt_val) = regno;
365 return rt_val;
368 else
370 rt_val = rtx_alloc (code); /* Allocate the storage space. */
371 rt_val->mode = mode; /* Store the machine mode... */
373 fmt = GET_RTX_FORMAT (code); /* Find the right format... */
374 for (i = 0; i < GET_RTX_LENGTH (code); i++)
376 switch (*fmt++)
378 case '0': /* Unused field. */
379 break;
381 case 'i': /* An integer? */
382 XINT (rt_val, i) = va_arg (p, int);
383 break;
385 case 'w': /* A wide integer? */
386 XWINT (rt_val, i) = va_arg (p, HOST_WIDE_INT);
387 break;
389 case 's': /* A string? */
390 XSTR (rt_val, i) = va_arg (p, char *);
391 break;
393 case 'e': /* An expression? */
394 case 'u': /* An insn? Same except when printing. */
395 XEXP (rt_val, i) = va_arg (p, rtx);
396 break;
398 case 'E': /* An RTX vector? */
399 XVEC (rt_val, i) = va_arg (p, rtvec);
400 break;
402 default:
403 abort ();
407 va_end (p);
408 return rt_val; /* Return the new RTX... */
411 /* gen_rtvec (n, [rt1, ..., rtn])
413 ** This routine creates an rtvec and stores within it the
414 ** pointers to rtx's which are its arguments.
417 /*VARARGS1*/
418 rtvec
419 gen_rtvec VPROTO((int n, ...))
421 #ifndef __STDC__
422 int n;
423 #endif
424 int i;
425 va_list p;
426 rtx *vector;
428 VA_START (p, n);
430 #ifndef __STDC__
431 n = va_arg (p, int);
432 #endif
434 if (n == 0)
435 return NULL_RTVEC; /* Don't allocate an empty rtvec... */
437 vector = (rtx *) alloca (n * sizeof (rtx));
439 for (i = 0; i < n; i++)
440 vector[i] = va_arg (p, rtx);
441 va_end (p);
443 return gen_rtvec_v (n, vector);
446 rtvec
447 gen_rtvec_v (n, argp)
448 int n;
449 rtx *argp;
451 register int i;
452 register rtvec rt_val;
454 if (n == 0)
455 return NULL_RTVEC; /* Don't allocate an empty rtvec... */
457 rt_val = rtvec_alloc (n); /* Allocate an rtvec... */
459 for (i = 0; i < n; i++)
460 rt_val->elem[i].rtx = *argp++;
462 return rt_val;
465 rtvec
466 gen_rtvec_vv (n, argp)
467 int n;
468 rtunion *argp;
470 register int i;
471 register rtvec rt_val;
473 if (n == 0)
474 return NULL_RTVEC; /* Don't allocate an empty rtvec... */
476 rt_val = rtvec_alloc (n); /* Allocate an rtvec... */
478 for (i = 0; i < n; i++)
479 rt_val->elem[i].rtx = (argp++)->rtx;
481 return rt_val;
484 /* Generate a REG rtx for a new pseudo register of mode MODE.
485 This pseudo is assigned the next sequential register number. */
488 gen_reg_rtx (mode)
489 enum machine_mode mode;
491 register rtx val;
493 /* Don't let anything called by or after reload create new registers
494 (actually, registers can't be created after flow, but this is a good
495 approximation). */
497 if (reload_in_progress || reload_completed)
498 abort ();
500 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
501 || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
503 /* For complex modes, don't make a single pseudo.
504 Instead, make a CONCAT of two pseudos.
505 This allows noncontiguous allocation of the real and imaginary parts,
506 which makes much better code. Besides, allocating DCmode
507 pseudos overstrains reload on some machines like the 386. */
508 rtx realpart, imagpart;
509 int size = GET_MODE_UNIT_SIZE (mode);
510 enum machine_mode partmode
511 = mode_for_size (size * BITS_PER_UNIT,
512 (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
513 ? MODE_FLOAT : MODE_INT),
516 realpart = gen_reg_rtx (partmode);
517 imagpart = gen_reg_rtx (partmode);
518 return gen_rtx (CONCAT, mode, realpart, imagpart);
521 /* Make sure regno_pointer_flag and regno_reg_rtx are large
522 enough to have an element for this pseudo reg number. */
524 if (reg_rtx_no == regno_pointer_flag_length)
526 rtx *new1;
527 char *new =
528 (char *) savealloc (regno_pointer_flag_length * 2);
529 bcopy (regno_pointer_flag, new, regno_pointer_flag_length);
530 bzero (&new[regno_pointer_flag_length], regno_pointer_flag_length);
531 regno_pointer_flag = new;
533 new = (char *) savealloc (regno_pointer_flag_length * 2);
534 bcopy (regno_pointer_align, new, regno_pointer_flag_length);
535 bzero (&new[regno_pointer_flag_length], regno_pointer_flag_length);
536 regno_pointer_align = new;
538 new1 = (rtx *) savealloc (regno_pointer_flag_length * 2 * sizeof (rtx));
539 bcopy ((char *) regno_reg_rtx, (char *) new1,
540 regno_pointer_flag_length * sizeof (rtx));
541 bzero ((char *) &new1[regno_pointer_flag_length],
542 regno_pointer_flag_length * sizeof (rtx));
543 regno_reg_rtx = new1;
545 regno_pointer_flag_length *= 2;
548 val = gen_rtx (REG, mode, reg_rtx_no);
549 regno_reg_rtx[reg_rtx_no++] = val;
550 return val;
553 /* Identify REG (which may be a CONCAT) as a user register. */
555 void
556 mark_user_reg (reg)
557 rtx reg;
559 if (GET_CODE (reg) == CONCAT)
561 REG_USERVAR_P (XEXP (reg, 0)) = 1;
562 REG_USERVAR_P (XEXP (reg, 1)) = 1;
564 else if (GET_CODE (reg) == REG)
565 REG_USERVAR_P (reg) = 1;
566 else
567 abort ();
570 /* Identify REG as a probable pointer register and show its alignment
571 as ALIGN, if nonzero. */
573 void
574 mark_reg_pointer (reg, align)
575 rtx reg;
576 int align;
578 REGNO_POINTER_FLAG (REGNO (reg)) = 1;
580 if (align)
581 REGNO_POINTER_ALIGN (REGNO (reg)) = align;
584 /* Return 1 plus largest pseudo reg number used in the current function. */
587 max_reg_num ()
589 return reg_rtx_no;
592 /* Return 1 + the largest label number used so far in the current function. */
595 max_label_num ()
597 if (last_label_num && label_num == base_label_num)
598 return last_label_num;
599 return label_num;
602 /* Return first label number used in this function (if any were used). */
605 get_first_label_num ()
607 return first_label_num;
610 /* Return a value representing some low-order bits of X, where the number
611 of low-order bits is given by MODE. Note that no conversion is done
612 between floating-point and fixed-point values, rather, the bit
613 representation is returned.
615 This function handles the cases in common between gen_lowpart, below,
616 and two variants in cse.c and combine.c. These are the cases that can
617 be safely handled at all points in the compilation.
619 If this is not a case we can handle, return 0. */
622 gen_lowpart_common (mode, x)
623 enum machine_mode mode;
624 register rtx x;
626 int word = 0;
628 if (GET_MODE (x) == mode)
629 return x;
631 /* MODE must occupy no more words than the mode of X. */
632 if (GET_MODE (x) != VOIDmode
633 && ((GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD
634 > ((GET_MODE_SIZE (GET_MODE (x)) + (UNITS_PER_WORD - 1))
635 / UNITS_PER_WORD)))
636 return 0;
638 if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
639 word = ((GET_MODE_SIZE (GET_MODE (x))
640 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD))
641 / UNITS_PER_WORD);
643 if ((GET_CODE (x) == ZERO_EXTEND || GET_CODE (x) == SIGN_EXTEND)
644 && (GET_MODE_CLASS (mode) == MODE_INT
645 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT))
647 /* If we are getting the low-order part of something that has been
648 sign- or zero-extended, we can either just use the object being
649 extended or make a narrower extension. If we want an even smaller
650 piece than the size of the object being extended, call ourselves
651 recursively.
653 This case is used mostly by combine and cse. */
655 if (GET_MODE (XEXP (x, 0)) == mode)
656 return XEXP (x, 0);
657 else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (XEXP (x, 0))))
658 return gen_lowpart_common (mode, XEXP (x, 0));
659 else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (x)))
660 return gen_rtx (GET_CODE (x), mode, XEXP (x, 0));
662 else if (GET_CODE (x) == SUBREG
663 && (GET_MODE_SIZE (mode) <= UNITS_PER_WORD
664 || GET_MODE_SIZE (mode) == GET_MODE_UNIT_SIZE (GET_MODE (x))))
665 return (GET_MODE (SUBREG_REG (x)) == mode && SUBREG_WORD (x) == 0
666 ? SUBREG_REG (x)
667 : gen_rtx (SUBREG, mode, SUBREG_REG (x), SUBREG_WORD (x) + word));
668 else if (GET_CODE (x) == REG)
670 /* If the register is not valid for MODE, return 0. If we don't
671 do this, there is no way to fix up the resulting REG later.
672 But we do do this if the current REG is not valid for its
673 mode. This latter is a kludge, but is required due to the
674 way that parameters are passed on some machines, most
675 notably Sparc. */
676 if (REGNO (x) < FIRST_PSEUDO_REGISTER
677 && ! HARD_REGNO_MODE_OK (REGNO (x) + word, mode)
678 && HARD_REGNO_MODE_OK (REGNO (x), GET_MODE (x)))
679 return 0;
680 else if (REGNO (x) < FIRST_PSEUDO_REGISTER
681 /* integrate.c can't handle parts of a return value register. */
682 && (! REG_FUNCTION_VALUE_P (x)
683 || ! rtx_equal_function_value_matters)
684 /* We want to keep the stack, frame, and arg pointers
685 special. */
686 && x != frame_pointer_rtx
687 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
688 && x != arg_pointer_rtx
689 #endif
690 && x != stack_pointer_rtx)
691 return gen_rtx (REG, mode, REGNO (x) + word);
692 else
693 return gen_rtx (SUBREG, mode, x, word);
695 /* If X is a CONST_INT or a CONST_DOUBLE, extract the appropriate bits
696 from the low-order part of the constant. */
697 else if ((GET_MODE_CLASS (mode) == MODE_INT
698 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
699 && GET_MODE (x) == VOIDmode
700 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
702 /* If MODE is twice the host word size, X is already the desired
703 representation. Otherwise, if MODE is wider than a word, we can't
704 do this. If MODE is exactly a word, return just one CONST_INT.
705 If MODE is smaller than a word, clear the bits that don't belong
706 in our mode, unless they and our sign bit are all one. So we get
707 either a reasonable negative value or a reasonable unsigned value
708 for this mode. */
710 if (GET_MODE_BITSIZE (mode) >= 2 * HOST_BITS_PER_WIDE_INT)
711 return x;
712 else if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
713 return 0;
714 else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
715 return (GET_CODE (x) == CONST_INT ? x
716 : GEN_INT (CONST_DOUBLE_LOW (x)));
717 else
719 /* MODE must be narrower than HOST_BITS_PER_INT. */
720 int width = GET_MODE_BITSIZE (mode);
721 HOST_WIDE_INT val = (GET_CODE (x) == CONST_INT ? INTVAL (x)
722 : CONST_DOUBLE_LOW (x));
724 if (((val & ((HOST_WIDE_INT) (-1) << (width - 1)))
725 != ((HOST_WIDE_INT) (-1) << (width - 1))))
726 val &= ((HOST_WIDE_INT) 1 << width) - 1;
728 return (GET_CODE (x) == CONST_INT && INTVAL (x) == val ? x
729 : GEN_INT (val));
733 /* If X is an integral constant but we want it in floating-point, it
734 must be the case that we have a union of an integer and a floating-point
735 value. If the machine-parameters allow it, simulate that union here
736 and return the result. The two-word and single-word cases are
737 different. */
739 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
740 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
741 || flag_pretend_float)
742 && GET_MODE_CLASS (mode) == MODE_FLOAT
743 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
744 && GET_CODE (x) == CONST_INT
745 && sizeof (float) * HOST_BITS_PER_CHAR == HOST_BITS_PER_WIDE_INT)
746 #ifdef REAL_ARITHMETIC
748 REAL_VALUE_TYPE r;
749 HOST_WIDE_INT i;
751 i = INTVAL (x);
752 r = REAL_VALUE_FROM_TARGET_SINGLE (i);
753 return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
755 #else
757 union {HOST_WIDE_INT i; float d; } u;
759 u.i = INTVAL (x);
760 return CONST_DOUBLE_FROM_REAL_VALUE (u.d, mode);
762 #endif
763 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
764 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
765 || flag_pretend_float)
766 && GET_MODE_CLASS (mode) == MODE_FLOAT
767 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
768 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
769 && GET_MODE (x) == VOIDmode
770 && (sizeof (double) * HOST_BITS_PER_CHAR
771 == 2 * HOST_BITS_PER_WIDE_INT))
772 #ifdef REAL_ARITHMETIC
774 REAL_VALUE_TYPE r;
775 HOST_WIDE_INT i[2];
776 HOST_WIDE_INT low, high;
778 if (GET_CODE (x) == CONST_INT)
779 low = INTVAL (x), high = low >> (HOST_BITS_PER_WIDE_INT -1);
780 else
781 low = CONST_DOUBLE_LOW (x), high = CONST_DOUBLE_HIGH (x);
783 /* REAL_VALUE_TARGET_DOUBLE takes the addressing order of the
784 target machine. */
785 if (WORDS_BIG_ENDIAN)
786 i[0] = high, i[1] = low;
787 else
788 i[0] = low, i[1] = high;
790 r = REAL_VALUE_FROM_TARGET_DOUBLE (i);
791 return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
793 #else
795 union {HOST_WIDE_INT i[2]; double d; } u;
796 HOST_WIDE_INT low, high;
798 if (GET_CODE (x) == CONST_INT)
799 low = INTVAL (x), high = low >> (HOST_BITS_PER_WIDE_INT -1);
800 else
801 low = CONST_DOUBLE_LOW (x), high = CONST_DOUBLE_HIGH (x);
803 #ifdef HOST_WORDS_BIG_ENDIAN
804 u.i[0] = high, u.i[1] = low;
805 #else
806 u.i[0] = low, u.i[1] = high;
807 #endif
809 return CONST_DOUBLE_FROM_REAL_VALUE (u.d, mode);
811 #endif
813 /* We need an extra case for machines where HOST_BITS_PER_WIDE_INT is the
814 same as sizeof (double), such as the alpha. We only handle the
815 REAL_ARITHMETIC case, which is easy. Testing HOST_BITS_PER_WIDE_INT
816 is not strictly necessary, but is done to restrict this code to cases
817 where it is known to work. */
818 #ifdef REAL_ARITHMETIC
819 else if (mode == SFmode
820 && GET_CODE (x) == CONST_INT
821 && GET_MODE_BITSIZE (mode) * 2 == HOST_BITS_PER_WIDE_INT)
823 REAL_VALUE_TYPE r;
824 HOST_WIDE_INT i;
826 i = INTVAL (x);
827 r = REAL_VALUE_FROM_TARGET_SINGLE (i);
828 return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
830 #endif
832 /* Similarly, if this is converting a floating-point value into a
833 single-word integer. Only do this is the host and target parameters are
834 compatible. */
836 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
837 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
838 || flag_pretend_float)
839 && (GET_MODE_CLASS (mode) == MODE_INT
840 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
841 && GET_CODE (x) == CONST_DOUBLE
842 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT
843 && GET_MODE_BITSIZE (mode) == BITS_PER_WORD)
844 return operand_subword (x, word, 0, GET_MODE (x));
846 /* Similarly, if this is converting a floating-point value into a
847 two-word integer, we can do this one word at a time and make an
848 integer. Only do this is the host and target parameters are
849 compatible. */
851 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
852 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
853 || flag_pretend_float)
854 && (GET_MODE_CLASS (mode) == MODE_INT
855 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
856 && GET_CODE (x) == CONST_DOUBLE
857 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT
858 && GET_MODE_BITSIZE (mode) == 2 * BITS_PER_WORD)
860 rtx lowpart
861 = operand_subword (x, word + WORDS_BIG_ENDIAN, 0, GET_MODE (x));
862 rtx highpart
863 = operand_subword (x, word + ! WORDS_BIG_ENDIAN, 0, GET_MODE (x));
865 if (lowpart && GET_CODE (lowpart) == CONST_INT
866 && highpart && GET_CODE (highpart) == CONST_INT)
867 return immed_double_const (INTVAL (lowpart), INTVAL (highpart), mode);
870 /* Otherwise, we can't do this. */
871 return 0;
874 /* Return the real part (which has mode MODE) of a complex value X.
875 This always comes at the low address in memory. */
878 gen_realpart (mode, x)
879 enum machine_mode mode;
880 register rtx x;
882 if (GET_CODE (x) == CONCAT && GET_MODE (XEXP (x, 0)) == mode)
883 return XEXP (x, 0);
884 else if (WORDS_BIG_ENDIAN)
885 return gen_highpart (mode, x);
886 else
887 return gen_lowpart (mode, x);
890 /* Return the imaginary part (which has mode MODE) of a complex value X.
891 This always comes at the high address in memory. */
894 gen_imagpart (mode, x)
895 enum machine_mode mode;
896 register rtx x;
898 if (GET_CODE (x) == CONCAT && GET_MODE (XEXP (x, 0)) == mode)
899 return XEXP (x, 1);
900 else if (WORDS_BIG_ENDIAN)
901 return gen_lowpart (mode, x);
902 else
903 return gen_highpart (mode, x);
906 /* Return 1 iff X, assumed to be a SUBREG,
907 refers to the real part of the complex value in its containing reg.
908 Complex values are always stored with the real part in the first word,
909 regardless of WORDS_BIG_ENDIAN. */
912 subreg_realpart_p (x)
913 rtx x;
915 if (GET_CODE (x) != SUBREG)
916 abort ();
918 return SUBREG_WORD (x) == 0;
921 /* Assuming that X is an rtx (e.g., MEM, REG or SUBREG) for a value,
922 return an rtx (MEM, SUBREG, or CONST_INT) that refers to the
923 least-significant part of X.
924 MODE specifies how big a part of X to return;
925 it usually should not be larger than a word.
926 If X is a MEM whose address is a QUEUED, the value may be so also. */
929 gen_lowpart (mode, x)
930 enum machine_mode mode;
931 register rtx x;
933 rtx result = gen_lowpart_common (mode, x);
935 if (result)
936 return result;
937 else if (GET_CODE (x) == REG)
939 /* Must be a hard reg that's not valid in MODE. */
940 result = gen_lowpart_common (mode, copy_to_reg (x));
941 if (result == 0)
942 abort ();
943 return result;
945 else if (GET_CODE (x) == MEM)
947 /* The only additional case we can do is MEM. */
948 register int offset = 0;
949 if (WORDS_BIG_ENDIAN)
950 offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
951 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
953 if (BYTES_BIG_ENDIAN)
954 /* Adjust the address so that the address-after-the-data
955 is unchanged. */
956 offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))
957 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
959 return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
961 else
962 abort ();
965 /* Like `gen_lowpart', but refer to the most significant part.
966 This is used to access the imaginary part of a complex number. */
969 gen_highpart (mode, x)
970 enum machine_mode mode;
971 register rtx x;
973 /* This case loses if X is a subreg. To catch bugs early,
974 complain if an invalid MODE is used even in other cases. */
975 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
976 && GET_MODE_SIZE (mode) != GET_MODE_UNIT_SIZE (GET_MODE (x)))
977 abort ();
978 if (GET_CODE (x) == CONST_DOUBLE
979 #if !(TARGET_FLOAT_FORMAT != HOST_FLOAT_FORMAT || defined (REAL_IS_NOT_DOUBLE))
980 && GET_MODE_CLASS (GET_MODE (x)) != MODE_FLOAT
981 #endif
983 return gen_rtx (CONST_INT, VOIDmode,
984 CONST_DOUBLE_HIGH (x) & GET_MODE_MASK (mode));
985 else if (GET_CODE (x) == CONST_INT)
986 return const0_rtx;
987 else if (GET_CODE (x) == MEM)
989 register int offset = 0;
990 if (! WORDS_BIG_ENDIAN)
991 offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
992 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
994 if (! BYTES_BIG_ENDIAN
995 && GET_MODE_SIZE (mode) < UNITS_PER_WORD)
996 offset -= (GET_MODE_SIZE (mode)
997 - MIN (UNITS_PER_WORD,
998 GET_MODE_SIZE (GET_MODE (x))));
1000 return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
1002 else if (GET_CODE (x) == SUBREG)
1004 /* The only time this should occur is when we are looking at a
1005 multi-word item with a SUBREG whose mode is the same as that of the
1006 item. It isn't clear what we would do if it wasn't. */
1007 if (SUBREG_WORD (x) != 0)
1008 abort ();
1009 return gen_highpart (mode, SUBREG_REG (x));
1011 else if (GET_CODE (x) == REG)
1013 int word = 0;
1015 if (! WORDS_BIG_ENDIAN
1016 && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
1017 word = ((GET_MODE_SIZE (GET_MODE (x))
1018 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD))
1019 / UNITS_PER_WORD);
1022 * ??? This fails miserably for complex values being passed in registers
1023 * where the sizeof the real and imaginary part are not equal to the
1024 * sizeof SImode. FIXME
1027 if (REGNO (x) < FIRST_PSEUDO_REGISTER
1028 /* integrate.c can't handle parts of a return value register. */
1029 && (! REG_FUNCTION_VALUE_P (x)
1030 || ! rtx_equal_function_value_matters)
1031 /* We want to keep the stack, frame, and arg pointers special. */
1032 && x != frame_pointer_rtx
1033 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1034 && x != arg_pointer_rtx
1035 #endif
1036 && x != stack_pointer_rtx)
1037 return gen_rtx (REG, mode, REGNO (x) + word);
1038 else
1039 return gen_rtx (SUBREG, mode, x, word);
1041 else
1042 abort ();
1045 /* Return 1 iff X, assumed to be a SUBREG,
1046 refers to the least significant part of its containing reg.
1047 If X is not a SUBREG, always return 1 (it is its own low part!). */
1050 subreg_lowpart_p (x)
1051 rtx x;
1053 if (GET_CODE (x) != SUBREG)
1054 return 1;
1055 else if (GET_MODE (SUBREG_REG (x)) == VOIDmode)
1056 return 0;
1058 if (WORDS_BIG_ENDIAN
1059 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) > UNITS_PER_WORD)
1060 return (SUBREG_WORD (x)
1061 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
1062 - MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD))
1063 / UNITS_PER_WORD));
1065 return SUBREG_WORD (x) == 0;
1068 /* Return subword I of operand OP.
1069 The word number, I, is interpreted as the word number starting at the
1070 low-order address. Word 0 is the low-order word if not WORDS_BIG_ENDIAN,
1071 otherwise it is the high-order word.
1073 If we cannot extract the required word, we return zero. Otherwise, an
1074 rtx corresponding to the requested word will be returned.
1076 VALIDATE_ADDRESS is nonzero if the address should be validated. Before
1077 reload has completed, a valid address will always be returned. After
1078 reload, if a valid address cannot be returned, we return zero.
1080 If VALIDATE_ADDRESS is zero, we simply form the required address; validating
1081 it is the responsibility of the caller.
1083 MODE is the mode of OP in case it is a CONST_INT. */
1086 operand_subword (op, i, validate_address, mode)
1087 rtx op;
1088 int i;
1089 int validate_address;
1090 enum machine_mode mode;
1092 HOST_WIDE_INT val;
1093 int size_ratio = HOST_BITS_PER_WIDE_INT / BITS_PER_WORD;
1095 if (mode == VOIDmode)
1096 mode = GET_MODE (op);
1098 if (mode == VOIDmode)
1099 abort ();
1101 /* If OP is narrower than a word or if we want a word outside OP, fail. */
1102 if (mode != BLKmode
1103 && (GET_MODE_SIZE (mode) < UNITS_PER_WORD
1104 || (i + 1) * UNITS_PER_WORD > GET_MODE_SIZE (mode)))
1105 return 0;
1107 /* If OP is already an integer word, return it. */
1108 if (GET_MODE_CLASS (mode) == MODE_INT
1109 && GET_MODE_SIZE (mode) == UNITS_PER_WORD)
1110 return op;
1112 /* If OP is a REG or SUBREG, we can handle it very simply. */
1113 if (GET_CODE (op) == REG)
1115 /* If the register is not valid for MODE, return 0. If we don't
1116 do this, there is no way to fix up the resulting REG later. */
1117 if (REGNO (op) < FIRST_PSEUDO_REGISTER
1118 && ! HARD_REGNO_MODE_OK (REGNO (op) + i, word_mode))
1119 return 0;
1120 else if (REGNO (op) >= FIRST_PSEUDO_REGISTER
1121 || (REG_FUNCTION_VALUE_P (op)
1122 && rtx_equal_function_value_matters)
1123 /* We want to keep the stack, frame, and arg pointers
1124 special. */
1125 || op == frame_pointer_rtx
1126 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1127 || op == arg_pointer_rtx
1128 #endif
1129 || op == stack_pointer_rtx)
1130 return gen_rtx (SUBREG, word_mode, op, i);
1131 else
1132 return gen_rtx (REG, word_mode, REGNO (op) + i);
1134 else if (GET_CODE (op) == SUBREG)
1135 return gen_rtx (SUBREG, word_mode, SUBREG_REG (op), i + SUBREG_WORD (op));
1136 else if (GET_CODE (op) == CONCAT)
1138 int partwords = GET_MODE_UNIT_SIZE (GET_MODE (op)) / UNITS_PER_WORD;
1139 if (i < partwords)
1140 return operand_subword (XEXP (op, 0), i, validate_address, mode);
1141 return operand_subword (XEXP (op, 1), i - partwords,
1142 validate_address, mode);
1145 /* Form a new MEM at the requested address. */
1146 if (GET_CODE (op) == MEM)
1148 rtx addr = plus_constant (XEXP (op, 0), i * UNITS_PER_WORD);
1149 rtx new;
1151 if (validate_address)
1153 if (reload_completed)
1155 if (! strict_memory_address_p (word_mode, addr))
1156 return 0;
1158 else
1159 addr = memory_address (word_mode, addr);
1162 new = gen_rtx (MEM, word_mode, addr);
1164 MEM_VOLATILE_P (new) = MEM_VOLATILE_P (op);
1165 MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (op);
1166 RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (op);
1168 return new;
1171 /* The only remaining cases are when OP is a constant. If the host and
1172 target floating formats are the same, handling two-word floating
1173 constants are easy. Note that REAL_VALUE_TO_TARGET_{SINGLE,DOUBLE}
1174 are defined as returning one or two 32 bit values, respectively,
1175 and not values of BITS_PER_WORD bits. */
1176 #ifdef REAL_ARITHMETIC
1177 /* The output is some bits, the width of the target machine's word.
1178 A wider-word host can surely hold them in a CONST_INT. A narrower-word
1179 host can't. */
1180 if (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
1181 && GET_MODE_CLASS (mode) == MODE_FLOAT
1182 && GET_MODE_BITSIZE (mode) == 64
1183 && GET_CODE (op) == CONST_DOUBLE)
1185 long k[2];
1186 REAL_VALUE_TYPE rv;
1188 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1189 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
1191 /* We handle 32-bit and >= 64-bit words here. Note that the order in
1192 which the words are written depends on the word endianness.
1194 ??? This is a potential portability problem and should
1195 be fixed at some point. */
1196 if (BITS_PER_WORD == 32)
1197 return GEN_INT ((HOST_WIDE_INT) k[i]);
1198 #if HOST_BITS_PER_WIDE_INT > 32
1199 else if (BITS_PER_WORD >= 64 && i == 0)
1200 return GEN_INT ((((HOST_WIDE_INT) k[! WORDS_BIG_ENDIAN]) << 32)
1201 | (HOST_WIDE_INT) k[WORDS_BIG_ENDIAN]);
1202 #endif
1203 else if (BITS_PER_WORD == 16)
1205 long value;
1206 value = k[i >> 1];
1207 if ((i & 0x1) == 0)
1208 value >>= 16;
1209 value &= 0xffff;
1210 return GEN_INT ((HOST_WIDE_INT) value);
1212 else
1213 abort ();
1215 else if (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
1216 && GET_MODE_CLASS (mode) == MODE_FLOAT
1217 && GET_MODE_BITSIZE (mode) > 64
1218 && GET_CODE (op) == CONST_DOUBLE)
1220 long k[4];
1221 REAL_VALUE_TYPE rv;
1223 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1224 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
1226 if (BITS_PER_WORD == 32)
1227 return GEN_INT ((HOST_WIDE_INT) k[i]);
1229 #else /* no REAL_ARITHMETIC */
1230 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1231 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1232 || flag_pretend_float)
1233 && GET_MODE_CLASS (mode) == MODE_FLOAT
1234 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
1235 && GET_CODE (op) == CONST_DOUBLE)
1237 /* The constant is stored in the host's word-ordering,
1238 but we want to access it in the target's word-ordering. Some
1239 compilers don't like a conditional inside macro args, so we have two
1240 copies of the return. */
1241 #ifdef HOST_WORDS_BIG_ENDIAN
1242 return GEN_INT (i == WORDS_BIG_ENDIAN
1243 ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
1244 #else
1245 return GEN_INT (i != WORDS_BIG_ENDIAN
1246 ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
1247 #endif
1249 #endif /* no REAL_ARITHMETIC */
1251 /* Single word float is a little harder, since single- and double-word
1252 values often do not have the same high-order bits. We have already
1253 verified that we want the only defined word of the single-word value. */
1254 #ifdef REAL_ARITHMETIC
1255 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1256 && GET_MODE_BITSIZE (mode) == 32
1257 && GET_CODE (op) == CONST_DOUBLE)
1259 long l;
1260 REAL_VALUE_TYPE rv;
1262 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1263 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
1264 return GEN_INT ((HOST_WIDE_INT) l);
1266 #else
1267 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1268 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1269 || flag_pretend_float)
1270 && sizeof (float) * 8 == HOST_BITS_PER_WIDE_INT
1271 && GET_MODE_CLASS (mode) == MODE_FLOAT
1272 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
1273 && GET_CODE (op) == CONST_DOUBLE)
1275 double d;
1276 union {float f; HOST_WIDE_INT i; } u;
1278 REAL_VALUE_FROM_CONST_DOUBLE (d, op);
1280 u.f = d;
1281 return GEN_INT (u.i);
1283 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1284 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1285 || flag_pretend_float)
1286 && sizeof (double) * 8 == HOST_BITS_PER_WIDE_INT
1287 && GET_MODE_CLASS (mode) == MODE_FLOAT
1288 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
1289 && GET_CODE (op) == CONST_DOUBLE)
1291 double d;
1292 union {double d; HOST_WIDE_INT i; } u;
1294 REAL_VALUE_FROM_CONST_DOUBLE (d, op);
1296 u.d = d;
1297 return GEN_INT (u.i);
1299 #endif /* no REAL_ARITHMETIC */
1301 /* The only remaining cases that we can handle are integers.
1302 Convert to proper endianness now since these cases need it.
1303 At this point, i == 0 means the low-order word.
1305 We do not want to handle the case when BITS_PER_WORD <= HOST_BITS_PER_INT
1306 in general. However, if OP is (const_int 0), we can just return
1307 it for any word. */
1309 if (op == const0_rtx)
1310 return op;
1312 if (GET_MODE_CLASS (mode) != MODE_INT
1313 || (GET_CODE (op) != CONST_INT && GET_CODE (op) != CONST_DOUBLE)
1314 || BITS_PER_WORD > HOST_BITS_PER_WIDE_INT)
1315 return 0;
1317 if (WORDS_BIG_ENDIAN)
1318 i = GET_MODE_SIZE (mode) / UNITS_PER_WORD - 1 - i;
1320 /* Find out which word on the host machine this value is in and get
1321 it from the constant. */
1322 val = (i / size_ratio == 0
1323 ? (GET_CODE (op) == CONST_INT ? INTVAL (op) : CONST_DOUBLE_LOW (op))
1324 : (GET_CODE (op) == CONST_INT
1325 ? (INTVAL (op) < 0 ? ~0 : 0) : CONST_DOUBLE_HIGH (op)));
1327 /* If BITS_PER_WORD is smaller than an int, get the appropriate bits. */
1328 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT)
1329 val = ((val >> ((i % size_ratio) * BITS_PER_WORD))
1330 & (((HOST_WIDE_INT) 1
1331 << (BITS_PER_WORD % HOST_BITS_PER_WIDE_INT)) - 1));
1333 return GEN_INT (val);
1336 /* Similar to `operand_subword', but never return 0. If we can't extract
1337 the required subword, put OP into a register and try again. If that fails,
1338 abort. We always validate the address in this case. It is not valid
1339 to call this function after reload; it is mostly meant for RTL
1340 generation.
1342 MODE is the mode of OP, in case it is CONST_INT. */
1345 operand_subword_force (op, i, mode)
1346 rtx op;
1347 int i;
1348 enum machine_mode mode;
1350 rtx result = operand_subword (op, i, 1, mode);
1352 if (result)
1353 return result;
1355 if (mode != BLKmode && mode != VOIDmode)
1356 op = force_reg (mode, op);
1358 result = operand_subword (op, i, 1, mode);
1359 if (result == 0)
1360 abort ();
1362 return result;
1365 /* Given a compare instruction, swap the operands.
1366 A test instruction is changed into a compare of 0 against the operand. */
1368 void
1369 reverse_comparison (insn)
1370 rtx insn;
1372 rtx body = PATTERN (insn);
1373 rtx comp;
1375 if (GET_CODE (body) == SET)
1376 comp = SET_SRC (body);
1377 else
1378 comp = SET_SRC (XVECEXP (body, 0, 0));
1380 if (GET_CODE (comp) == COMPARE)
1382 rtx op0 = XEXP (comp, 0);
1383 rtx op1 = XEXP (comp, 1);
1384 XEXP (comp, 0) = op1;
1385 XEXP (comp, 1) = op0;
1387 else
1389 rtx new = gen_rtx (COMPARE, VOIDmode,
1390 CONST0_RTX (GET_MODE (comp)), comp);
1391 if (GET_CODE (body) == SET)
1392 SET_SRC (body) = new;
1393 else
1394 SET_SRC (XVECEXP (body, 0, 0)) = new;
1398 /* Return a memory reference like MEMREF, but with its mode changed
1399 to MODE and its address changed to ADDR.
1400 (VOIDmode means don't change the mode.
1401 NULL for ADDR means don't change the address.) */
1404 change_address (memref, mode, addr)
1405 rtx memref;
1406 enum machine_mode mode;
1407 rtx addr;
1409 rtx new;
1411 if (GET_CODE (memref) != MEM)
1412 abort ();
1413 if (mode == VOIDmode)
1414 mode = GET_MODE (memref);
1415 if (addr == 0)
1416 addr = XEXP (memref, 0);
1418 /* If reload is in progress or has completed, ADDR must be valid.
1419 Otherwise, we can call memory_address to make it valid. */
1420 if (reload_completed || reload_in_progress)
1422 if (! memory_address_p (mode, addr))
1423 abort ();
1425 else
1426 addr = memory_address (mode, addr);
1428 if (rtx_equal_p (addr, XEXP (memref, 0)) && mode == GET_MODE (memref))
1429 return memref;
1431 new = gen_rtx (MEM, mode, addr);
1432 MEM_VOLATILE_P (new) = MEM_VOLATILE_P (memref);
1433 RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (memref);
1434 MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (memref);
1435 return new;
1438 /* Return a newly created CODE_LABEL rtx with a unique label number. */
1441 gen_label_rtx ()
1443 register rtx label;
1445 label = (output_bytecode
1446 ? gen_rtx (CODE_LABEL, VOIDmode, NULL, bc_get_bytecode_label ())
1447 : gen_rtx (CODE_LABEL, VOIDmode, 0, NULL_RTX,
1448 NULL_RTX, label_num++, NULL_PTR));
1450 LABEL_NUSES (label) = 0;
1451 return label;
1454 /* For procedure integration. */
1456 /* Return a newly created INLINE_HEADER rtx. Should allocate this
1457 from a permanent obstack when the opportunity arises. */
1460 gen_inline_header_rtx (first_insn, first_parm_insn, first_labelno,
1461 last_labelno, max_parm_regnum, max_regnum, args_size,
1462 pops_args, stack_slots, forced_labels, function_flags,
1463 outgoing_args_size, original_arg_vector,
1464 original_decl_initial, regno_rtx, regno_flag,
1465 regno_align)
1466 rtx first_insn, first_parm_insn;
1467 int first_labelno, last_labelno, max_parm_regnum, max_regnum, args_size;
1468 int pops_args;
1469 rtx stack_slots;
1470 rtx forced_labels;
1471 int function_flags;
1472 int outgoing_args_size;
1473 rtvec original_arg_vector;
1474 rtx original_decl_initial;
1475 rtvec regno_rtx;
1476 char *regno_flag;
1477 char *regno_align;
1479 rtx header = gen_rtx (INLINE_HEADER, VOIDmode,
1480 cur_insn_uid++, NULL_RTX,
1481 first_insn, first_parm_insn,
1482 first_labelno, last_labelno,
1483 max_parm_regnum, max_regnum, args_size, pops_args,
1484 stack_slots, forced_labels, function_flags,
1485 outgoing_args_size, original_arg_vector,
1486 original_decl_initial,
1487 regno_rtx, regno_flag, regno_align);
1488 return header;
1491 /* Install new pointers to the first and last insns in the chain.
1492 Also, set cur_insn_uid to one higher than the last in use.
1493 Used for an inline-procedure after copying the insn chain. */
1495 void
1496 set_new_first_and_last_insn (first, last)
1497 rtx first, last;
1499 rtx insn;
1501 first_insn = first;
1502 last_insn = last;
1503 cur_insn_uid = 0;
1505 for (insn = first; insn; insn = NEXT_INSN (insn))
1506 cur_insn_uid = MAX (cur_insn_uid, INSN_UID (insn));
1508 cur_insn_uid++;
1511 /* Set the range of label numbers found in the current function.
1512 This is used when belatedly compiling an inline function. */
1514 void
1515 set_new_first_and_last_label_num (first, last)
1516 int first, last;
1518 base_label_num = label_num;
1519 first_label_num = first;
1520 last_label_num = last;
1523 /* Save all variables describing the current status into the structure *P.
1524 This is used before starting a nested function. */
1526 void
1527 save_emit_status (p)
1528 struct function *p;
1530 p->reg_rtx_no = reg_rtx_no;
1531 p->first_label_num = first_label_num;
1532 p->first_insn = first_insn;
1533 p->last_insn = last_insn;
1534 p->sequence_rtl_expr = sequence_rtl_expr;
1535 p->sequence_stack = sequence_stack;
1536 p->cur_insn_uid = cur_insn_uid;
1537 p->last_linenum = last_linenum;
1538 p->last_filename = last_filename;
1539 p->regno_pointer_flag = regno_pointer_flag;
1540 p->regno_pointer_align = regno_pointer_align;
1541 p->regno_pointer_flag_length = regno_pointer_flag_length;
1542 p->regno_reg_rtx = regno_reg_rtx;
1545 /* Restore all variables describing the current status from the structure *P.
1546 This is used after a nested function. */
1548 void
1549 restore_emit_status (p)
1550 struct function *p;
1552 int i;
1554 reg_rtx_no = p->reg_rtx_no;
1555 first_label_num = p->first_label_num;
1556 last_label_num = 0;
1557 first_insn = p->first_insn;
1558 last_insn = p->last_insn;
1559 sequence_rtl_expr = p->sequence_rtl_expr;
1560 sequence_stack = p->sequence_stack;
1561 cur_insn_uid = p->cur_insn_uid;
1562 last_linenum = p->last_linenum;
1563 last_filename = p->last_filename;
1564 regno_pointer_flag = p->regno_pointer_flag;
1565 regno_pointer_align = p->regno_pointer_align;
1566 regno_pointer_flag_length = p->regno_pointer_flag_length;
1567 regno_reg_rtx = p->regno_reg_rtx;
1569 /* Clear our cache of rtx expressions for start_sequence and
1570 gen_sequence. */
1571 sequence_element_free_list = 0;
1572 for (i = 0; i < SEQUENCE_RESULT_SIZE; i++)
1573 sequence_result[i] = 0;
1575 free_insn = 0;
1578 /* Go through all the RTL insn bodies and copy any invalid shared structure.
1579 It does not work to do this twice, because the mark bits set here
1580 are not cleared afterwards. */
1582 void
1583 unshare_all_rtl (insn)
1584 register rtx insn;
1586 for (; insn; insn = NEXT_INSN (insn))
1587 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
1588 || GET_CODE (insn) == CALL_INSN)
1590 PATTERN (insn) = copy_rtx_if_shared (PATTERN (insn));
1591 REG_NOTES (insn) = copy_rtx_if_shared (REG_NOTES (insn));
1592 LOG_LINKS (insn) = copy_rtx_if_shared (LOG_LINKS (insn));
1595 /* Make sure the addresses of stack slots found outside the insn chain
1596 (such as, in DECL_RTL of a variable) are not shared
1597 with the insn chain.
1599 This special care is necessary when the stack slot MEM does not
1600 actually appear in the insn chain. If it does appear, its address
1601 is unshared from all else at that point. */
1603 copy_rtx_if_shared (stack_slot_list);
1606 /* Mark ORIG as in use, and return a copy of it if it was already in use.
1607 Recursively does the same for subexpressions. */
1610 copy_rtx_if_shared (orig)
1611 rtx orig;
1613 register rtx x = orig;
1614 register int i;
1615 register enum rtx_code code;
1616 register char *format_ptr;
1617 int copied = 0;
1619 if (x == 0)
1620 return 0;
1622 code = GET_CODE (x);
1624 /* These types may be freely shared. */
1626 switch (code)
1628 case REG:
1629 case QUEUED:
1630 case CONST_INT:
1631 case CONST_DOUBLE:
1632 case SYMBOL_REF:
1633 case CODE_LABEL:
1634 case PC:
1635 case CC0:
1636 case SCRATCH:
1637 /* SCRATCH must be shared because they represent distinct values. */
1638 return x;
1640 case CONST:
1641 /* CONST can be shared if it contains a SYMBOL_REF. If it contains
1642 a LABEL_REF, it isn't sharable. */
1643 if (GET_CODE (XEXP (x, 0)) == PLUS
1644 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
1645 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
1646 return x;
1647 break;
1649 case INSN:
1650 case JUMP_INSN:
1651 case CALL_INSN:
1652 case NOTE:
1653 case BARRIER:
1654 /* The chain of insns is not being copied. */
1655 return x;
1657 case MEM:
1658 /* A MEM is allowed to be shared if its address is constant
1659 or is a constant plus one of the special registers. */
1660 if (CONSTANT_ADDRESS_P (XEXP (x, 0))
1661 || XEXP (x, 0) == virtual_stack_vars_rtx
1662 || XEXP (x, 0) == virtual_incoming_args_rtx)
1663 return x;
1665 if (GET_CODE (XEXP (x, 0)) == PLUS
1666 && (XEXP (XEXP (x, 0), 0) == virtual_stack_vars_rtx
1667 || XEXP (XEXP (x, 0), 0) == virtual_incoming_args_rtx)
1668 && CONSTANT_ADDRESS_P (XEXP (XEXP (x, 0), 1)))
1670 /* This MEM can appear in more than one place,
1671 but its address better not be shared with anything else. */
1672 if (! x->used)
1673 XEXP (x, 0) = copy_rtx_if_shared (XEXP (x, 0));
1674 x->used = 1;
1675 return x;
1679 /* This rtx may not be shared. If it has already been seen,
1680 replace it with a copy of itself. */
1682 if (x->used)
1684 register rtx copy;
1686 copy = rtx_alloc (code);
1687 bcopy ((char *) x, (char *) copy,
1688 (sizeof (*copy) - sizeof (copy->fld)
1689 + sizeof (copy->fld[0]) * GET_RTX_LENGTH (code)));
1690 x = copy;
1691 copied = 1;
1693 x->used = 1;
1695 /* Now scan the subexpressions recursively.
1696 We can store any replaced subexpressions directly into X
1697 since we know X is not shared! Any vectors in X
1698 must be copied if X was copied. */
1700 format_ptr = GET_RTX_FORMAT (code);
1702 for (i = 0; i < GET_RTX_LENGTH (code); i++)
1704 switch (*format_ptr++)
1706 case 'e':
1707 XEXP (x, i) = copy_rtx_if_shared (XEXP (x, i));
1708 break;
1710 case 'E':
1711 if (XVEC (x, i) != NULL)
1713 register int j;
1714 int len = XVECLEN (x, i);
1716 if (copied && len > 0)
1717 XVEC (x, i) = gen_rtvec_vv (len, XVEC (x, i)->elem);
1718 for (j = 0; j < len; j++)
1719 XVECEXP (x, i, j) = copy_rtx_if_shared (XVECEXP (x, i, j));
1721 break;
1724 return x;
1727 /* Clear all the USED bits in X to allow copy_rtx_if_shared to be used
1728 to look for shared sub-parts. */
1730 void
1731 reset_used_flags (x)
1732 rtx x;
1734 register int i, j;
1735 register enum rtx_code code;
1736 register char *format_ptr;
1738 if (x == 0)
1739 return;
1741 code = GET_CODE (x);
1743 /* These types may be freely shared so we needn't do any resetting
1744 for them. */
1746 switch (code)
1748 case REG:
1749 case QUEUED:
1750 case CONST_INT:
1751 case CONST_DOUBLE:
1752 case SYMBOL_REF:
1753 case CODE_LABEL:
1754 case PC:
1755 case CC0:
1756 return;
1758 case INSN:
1759 case JUMP_INSN:
1760 case CALL_INSN:
1761 case NOTE:
1762 case LABEL_REF:
1763 case BARRIER:
1764 /* The chain of insns is not being copied. */
1765 return;
1768 x->used = 0;
1770 format_ptr = GET_RTX_FORMAT (code);
1771 for (i = 0; i < GET_RTX_LENGTH (code); i++)
1773 switch (*format_ptr++)
1775 case 'e':
1776 reset_used_flags (XEXP (x, i));
1777 break;
1779 case 'E':
1780 for (j = 0; j < XVECLEN (x, i); j++)
1781 reset_used_flags (XVECEXP (x, i, j));
1782 break;
1787 /* Copy X if necessary so that it won't be altered by changes in OTHER.
1788 Return X or the rtx for the pseudo reg the value of X was copied into.
1789 OTHER must be valid as a SET_DEST. */
1792 make_safe_from (x, other)
1793 rtx x, other;
1795 while (1)
1796 switch (GET_CODE (other))
1798 case SUBREG:
1799 other = SUBREG_REG (other);
1800 break;
1801 case STRICT_LOW_PART:
1802 case SIGN_EXTEND:
1803 case ZERO_EXTEND:
1804 other = XEXP (other, 0);
1805 break;
1806 default:
1807 goto done;
1809 done:
1810 if ((GET_CODE (other) == MEM
1811 && ! CONSTANT_P (x)
1812 && GET_CODE (x) != REG
1813 && GET_CODE (x) != SUBREG)
1814 || (GET_CODE (other) == REG
1815 && (REGNO (other) < FIRST_PSEUDO_REGISTER
1816 || reg_mentioned_p (other, x))))
1818 rtx temp = gen_reg_rtx (GET_MODE (x));
1819 emit_move_insn (temp, x);
1820 return temp;
1822 return x;
1825 /* Emission of insns (adding them to the doubly-linked list). */
1827 /* Return the first insn of the current sequence or current function. */
1830 get_insns ()
1832 return first_insn;
1835 /* Return the last insn emitted in current sequence or current function. */
1838 get_last_insn ()
1840 return last_insn;
1843 /* Specify a new insn as the last in the chain. */
1845 void
1846 set_last_insn (insn)
1847 rtx insn;
1849 if (NEXT_INSN (insn) != 0)
1850 abort ();
1851 last_insn = insn;
1854 /* Return the last insn emitted, even if it is in a sequence now pushed. */
1857 get_last_insn_anywhere ()
1859 struct sequence_stack *stack;
1860 if (last_insn)
1861 return last_insn;
1862 for (stack = sequence_stack; stack; stack = stack->next)
1863 if (stack->last != 0)
1864 return stack->last;
1865 return 0;
1868 /* Return a number larger than any instruction's uid in this function. */
1871 get_max_uid ()
1873 return cur_insn_uid;
1876 /* Return the next insn. If it is a SEQUENCE, return the first insn
1877 of the sequence. */
1880 next_insn (insn)
1881 rtx insn;
1883 if (insn)
1885 insn = NEXT_INSN (insn);
1886 if (insn && GET_CODE (insn) == INSN
1887 && GET_CODE (PATTERN (insn)) == SEQUENCE)
1888 insn = XVECEXP (PATTERN (insn), 0, 0);
1891 return insn;
1894 /* Return the previous insn. If it is a SEQUENCE, return the last insn
1895 of the sequence. */
1898 previous_insn (insn)
1899 rtx insn;
1901 if (insn)
1903 insn = PREV_INSN (insn);
1904 if (insn && GET_CODE (insn) == INSN
1905 && GET_CODE (PATTERN (insn)) == SEQUENCE)
1906 insn = XVECEXP (PATTERN (insn), 0, XVECLEN (PATTERN (insn), 0) - 1);
1909 return insn;
1912 /* Return the next insn after INSN that is not a NOTE. This routine does not
1913 look inside SEQUENCEs. */
1916 next_nonnote_insn (insn)
1917 rtx insn;
1919 while (insn)
1921 insn = NEXT_INSN (insn);
1922 if (insn == 0 || GET_CODE (insn) != NOTE)
1923 break;
1926 return insn;
1929 /* Return the previous insn before INSN that is not a NOTE. This routine does
1930 not look inside SEQUENCEs. */
1933 prev_nonnote_insn (insn)
1934 rtx insn;
1936 while (insn)
1938 insn = PREV_INSN (insn);
1939 if (insn == 0 || GET_CODE (insn) != NOTE)
1940 break;
1943 return insn;
1946 /* Return the next INSN, CALL_INSN or JUMP_INSN after INSN;
1947 or 0, if there is none. This routine does not look inside
1948 SEQUENCEs. */
1951 next_real_insn (insn)
1952 rtx insn;
1954 while (insn)
1956 insn = NEXT_INSN (insn);
1957 if (insn == 0 || GET_CODE (insn) == INSN
1958 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN)
1959 break;
1962 return insn;
1965 /* Return the last INSN, CALL_INSN or JUMP_INSN before INSN;
1966 or 0, if there is none. This routine does not look inside
1967 SEQUENCEs. */
1970 prev_real_insn (insn)
1971 rtx insn;
1973 while (insn)
1975 insn = PREV_INSN (insn);
1976 if (insn == 0 || GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
1977 || GET_CODE (insn) == JUMP_INSN)
1978 break;
1981 return insn;
1984 /* Find the next insn after INSN that really does something. This routine
1985 does not look inside SEQUENCEs. Until reload has completed, this is the
1986 same as next_real_insn. */
1989 next_active_insn (insn)
1990 rtx insn;
1992 while (insn)
1994 insn = NEXT_INSN (insn);
1995 if (insn == 0
1996 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN
1997 || (GET_CODE (insn) == INSN
1998 && (! reload_completed
1999 || (GET_CODE (PATTERN (insn)) != USE
2000 && GET_CODE (PATTERN (insn)) != CLOBBER))))
2001 break;
2004 return insn;
2007 /* Find the last insn before INSN that really does something. This routine
2008 does not look inside SEQUENCEs. Until reload has completed, this is the
2009 same as prev_real_insn. */
2012 prev_active_insn (insn)
2013 rtx insn;
2015 while (insn)
2017 insn = PREV_INSN (insn);
2018 if (insn == 0
2019 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN
2020 || (GET_CODE (insn) == INSN
2021 && (! reload_completed
2022 || (GET_CODE (PATTERN (insn)) != USE
2023 && GET_CODE (PATTERN (insn)) != CLOBBER))))
2024 break;
2027 return insn;
2030 /* Return the next CODE_LABEL after the insn INSN, or 0 if there is none. */
2033 next_label (insn)
2034 rtx insn;
2036 while (insn)
2038 insn = NEXT_INSN (insn);
2039 if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
2040 break;
2043 return insn;
2046 /* Return the last CODE_LABEL before the insn INSN, or 0 if there is none. */
2049 prev_label (insn)
2050 rtx insn;
2052 while (insn)
2054 insn = PREV_INSN (insn);
2055 if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
2056 break;
2059 return insn;
2062 #ifdef HAVE_cc0
2063 /* INSN uses CC0 and is being moved into a delay slot. Set up REG_CC_SETTER
2064 and REG_CC_USER notes so we can find it. */
2066 void
2067 link_cc0_insns (insn)
2068 rtx insn;
2070 rtx user = next_nonnote_insn (insn);
2072 if (GET_CODE (user) == INSN && GET_CODE (PATTERN (user)) == SEQUENCE)
2073 user = XVECEXP (PATTERN (user), 0, 0);
2075 REG_NOTES (user) = gen_rtx (INSN_LIST, REG_CC_SETTER, insn,
2076 REG_NOTES (user));
2077 REG_NOTES (insn) = gen_rtx (INSN_LIST, REG_CC_USER, user, REG_NOTES (insn));
2080 /* Return the next insn that uses CC0 after INSN, which is assumed to
2081 set it. This is the inverse of prev_cc0_setter (i.e., prev_cc0_setter
2082 applied to the result of this function should yield INSN).
2084 Normally, this is simply the next insn. However, if a REG_CC_USER note
2085 is present, it contains the insn that uses CC0.
2087 Return 0 if we can't find the insn. */
2090 next_cc0_user (insn)
2091 rtx insn;
2093 rtx note = find_reg_note (insn, REG_CC_USER, NULL_RTX);
2095 if (note)
2096 return XEXP (note, 0);
2098 insn = next_nonnote_insn (insn);
2099 if (insn && GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
2100 insn = XVECEXP (PATTERN (insn), 0, 0);
2102 if (insn && GET_RTX_CLASS (GET_CODE (insn)) == 'i'
2103 && reg_mentioned_p (cc0_rtx, PATTERN (insn)))
2104 return insn;
2106 return 0;
2109 /* Find the insn that set CC0 for INSN. Unless INSN has a REG_CC_SETTER
2110 note, it is the previous insn. */
2113 prev_cc0_setter (insn)
2114 rtx insn;
2116 rtx note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
2117 rtx link;
2119 if (note)
2120 return XEXP (note, 0);
2122 insn = prev_nonnote_insn (insn);
2123 if (! sets_cc0_p (PATTERN (insn)))
2124 abort ();
2126 return insn;
2128 #endif
2130 /* Try splitting insns that can be split for better scheduling.
2131 PAT is the pattern which might split.
2132 TRIAL is the insn providing PAT.
2133 LAST is non-zero if we should return the last insn of the sequence produced.
2135 If this routine succeeds in splitting, it returns the first or last
2136 replacement insn depending on the value of LAST. Otherwise, it
2137 returns TRIAL. If the insn to be returned can be split, it will be. */
2140 try_split (pat, trial, last)
2141 rtx pat, trial;
2142 int last;
2144 rtx before = PREV_INSN (trial);
2145 rtx after = NEXT_INSN (trial);
2146 rtx seq = split_insns (pat, trial);
2147 int has_barrier = 0;
2148 rtx tem;
2150 /* If we are splitting a JUMP_INSN, it might be followed by a BARRIER.
2151 We may need to handle this specially. */
2152 if (after && GET_CODE (after) == BARRIER)
2154 has_barrier = 1;
2155 after = NEXT_INSN (after);
2158 if (seq)
2160 /* SEQ can either be a SEQUENCE or the pattern of a single insn.
2161 The latter case will normally arise only when being done so that
2162 it, in turn, will be split (SFmode on the 29k is an example). */
2163 if (GET_CODE (seq) == SEQUENCE)
2165 /* If we are splitting a JUMP_INSN, look for the JUMP_INSN in
2166 SEQ and copy our JUMP_LABEL to it. If JUMP_LABEL is non-zero,
2167 increment the usage count so we don't delete the label. */
2168 int i;
2170 if (GET_CODE (trial) == JUMP_INSN)
2171 for (i = XVECLEN (seq, 0) - 1; i >= 0; i--)
2172 if (GET_CODE (XVECEXP (seq, 0, i)) == JUMP_INSN)
2174 JUMP_LABEL (XVECEXP (seq, 0, i)) = JUMP_LABEL (trial);
2176 if (JUMP_LABEL (trial))
2177 LABEL_NUSES (JUMP_LABEL (trial))++;
2180 tem = emit_insn_after (seq, before);
2182 delete_insn (trial);
2183 if (has_barrier)
2184 emit_barrier_after (tem);
2186 /* Recursively call try_split for each new insn created; by the
2187 time control returns here that insn will be fully split, so
2188 set LAST and continue from the insn after the one returned.
2189 We can't use next_active_insn here since AFTER may be a note.
2190 Ignore deleted insns, which can be occur if not optimizing. */
2191 for (tem = NEXT_INSN (before); tem != after;
2192 tem = NEXT_INSN (tem))
2193 if (! INSN_DELETED_P (tem))
2194 tem = try_split (PATTERN (tem), tem, 1);
2196 /* Avoid infinite loop if the result matches the original pattern. */
2197 else if (rtx_equal_p (seq, pat))
2198 return trial;
2199 else
2201 PATTERN (trial) = seq;
2202 INSN_CODE (trial) = -1;
2203 try_split (seq, trial, last);
2206 /* Return either the first or the last insn, depending on which was
2207 requested. */
2208 return last ? prev_active_insn (after) : next_active_insn (before);
2211 return trial;
2214 /* Make and return an INSN rtx, initializing all its slots.
2215 Store PATTERN in the pattern slots. */
2218 make_insn_raw (pattern)
2219 rtx pattern;
2221 register rtx insn;
2223 /* If in RTL generation phase, see if FREE_INSN can be used. */
2224 if (free_insn != 0 && rtx_equal_function_value_matters)
2226 insn = free_insn;
2227 free_insn = NEXT_INSN (free_insn);
2228 PUT_CODE (insn, INSN);
2230 else
2231 insn = rtx_alloc (INSN);
2233 INSN_UID (insn) = cur_insn_uid++;
2234 PATTERN (insn) = pattern;
2235 INSN_CODE (insn) = -1;
2236 LOG_LINKS (insn) = NULL;
2237 REG_NOTES (insn) = NULL;
2239 return insn;
2242 /* Like `make_insn' but make a JUMP_INSN instead of an insn. */
2244 static rtx
2245 make_jump_insn_raw (pattern)
2246 rtx pattern;
2248 register rtx insn;
2250 insn = rtx_alloc (JUMP_INSN);
2251 INSN_UID (insn) = cur_insn_uid++;
2253 PATTERN (insn) = pattern;
2254 INSN_CODE (insn) = -1;
2255 LOG_LINKS (insn) = NULL;
2256 REG_NOTES (insn) = NULL;
2257 JUMP_LABEL (insn) = NULL;
2259 return insn;
2262 /* Like `make_insn' but make a CALL_INSN instead of an insn. */
2264 static rtx
2265 make_call_insn_raw (pattern)
2266 rtx pattern;
2268 register rtx insn;
2270 insn = rtx_alloc (CALL_INSN);
2271 INSN_UID (insn) = cur_insn_uid++;
2273 PATTERN (insn) = pattern;
2274 INSN_CODE (insn) = -1;
2275 LOG_LINKS (insn) = NULL;
2276 REG_NOTES (insn) = NULL;
2277 CALL_INSN_FUNCTION_USAGE (insn) = NULL;
2279 return insn;
2282 /* Add INSN to the end of the doubly-linked list.
2283 INSN may be an INSN, JUMP_INSN, CALL_INSN, CODE_LABEL, BARRIER or NOTE. */
2285 void
2286 add_insn (insn)
2287 register rtx insn;
2289 PREV_INSN (insn) = last_insn;
2290 NEXT_INSN (insn) = 0;
2292 if (NULL != last_insn)
2293 NEXT_INSN (last_insn) = insn;
2295 if (NULL == first_insn)
2296 first_insn = insn;
2298 last_insn = insn;
2301 /* Add INSN into the doubly-linked list after insn AFTER. This and
2302 the next should be the only functions called to insert an insn once
2303 delay slots have been filled since only they know how to update a
2304 SEQUENCE. */
2306 void
2307 add_insn_after (insn, after)
2308 rtx insn, after;
2310 rtx next = NEXT_INSN (after);
2312 if (optimize && INSN_DELETED_P (after))
2313 abort ();
2315 NEXT_INSN (insn) = next;
2316 PREV_INSN (insn) = after;
2318 if (next)
2320 PREV_INSN (next) = insn;
2321 if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == SEQUENCE)
2322 PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = insn;
2324 else if (last_insn == after)
2325 last_insn = insn;
2326 else
2328 struct sequence_stack *stack = sequence_stack;
2329 /* Scan all pending sequences too. */
2330 for (; stack; stack = stack->next)
2331 if (after == stack->last)
2333 stack->last = insn;
2334 break;
2337 if (stack == 0)
2338 abort ();
2341 NEXT_INSN (after) = insn;
2342 if (GET_CODE (after) == INSN && GET_CODE (PATTERN (after)) == SEQUENCE)
2344 rtx sequence = PATTERN (after);
2345 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2349 /* Add INSN into the doubly-linked list before insn BEFORE. This and
2350 the previous should be the only functions called to insert an insn once
2351 delay slots have been filled since only they know how to update a
2352 SEQUENCE. */
2354 void
2355 add_insn_before (insn, before)
2356 rtx insn, before;
2358 rtx prev = PREV_INSN (before);
2360 if (optimize && INSN_DELETED_P (before))
2361 abort ();
2363 PREV_INSN (insn) = prev;
2364 NEXT_INSN (insn) = before;
2366 if (prev)
2368 NEXT_INSN (prev) = insn;
2369 if (GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == SEQUENCE)
2371 rtx sequence = PATTERN (prev);
2372 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2375 else if (first_insn == before)
2376 first_insn = insn;
2377 else
2379 struct sequence_stack *stack = sequence_stack;
2380 /* Scan all pending sequences too. */
2381 for (; stack; stack = stack->next)
2382 if (before == stack->first)
2384 stack->first = insn;
2385 break;
2388 if (stack == 0)
2389 abort ();
2392 PREV_INSN (before) = insn;
2393 if (GET_CODE (before) == INSN && GET_CODE (PATTERN (before)) == SEQUENCE)
2394 PREV_INSN (XVECEXP (PATTERN (before), 0, 0)) = insn;
2397 /* Delete all insns made since FROM.
2398 FROM becomes the new last instruction. */
2400 void
2401 delete_insns_since (from)
2402 rtx from;
2404 if (from == 0)
2405 first_insn = 0;
2406 else
2407 NEXT_INSN (from) = 0;
2408 last_insn = from;
2411 /* This function is deprecated, please use sequences instead.
2413 Move a consecutive bunch of insns to a different place in the chain.
2414 The insns to be moved are those between FROM and TO.
2415 They are moved to a new position after the insn AFTER.
2416 AFTER must not be FROM or TO or any insn in between.
2418 This function does not know about SEQUENCEs and hence should not be
2419 called after delay-slot filling has been done. */
2421 void
2422 reorder_insns (from, to, after)
2423 rtx from, to, after;
2425 /* Splice this bunch out of where it is now. */
2426 if (PREV_INSN (from))
2427 NEXT_INSN (PREV_INSN (from)) = NEXT_INSN (to);
2428 if (NEXT_INSN (to))
2429 PREV_INSN (NEXT_INSN (to)) = PREV_INSN (from);
2430 if (last_insn == to)
2431 last_insn = PREV_INSN (from);
2432 if (first_insn == from)
2433 first_insn = NEXT_INSN (to);
2435 /* Make the new neighbors point to it and it to them. */
2436 if (NEXT_INSN (after))
2437 PREV_INSN (NEXT_INSN (after)) = to;
2439 NEXT_INSN (to) = NEXT_INSN (after);
2440 PREV_INSN (from) = after;
2441 NEXT_INSN (after) = from;
2442 if (after == last_insn)
2443 last_insn = to;
2446 /* Return the line note insn preceding INSN. */
2448 static rtx
2449 find_line_note (insn)
2450 rtx insn;
2452 if (no_line_numbers)
2453 return 0;
2455 for (; insn; insn = PREV_INSN (insn))
2456 if (GET_CODE (insn) == NOTE
2457 && NOTE_LINE_NUMBER (insn) >= 0)
2458 break;
2460 return insn;
2463 /* Like reorder_insns, but inserts line notes to preserve the line numbers
2464 of the moved insns when debugging. This may insert a note between AFTER
2465 and FROM, and another one after TO. */
2467 void
2468 reorder_insns_with_line_notes (from, to, after)
2469 rtx from, to, after;
2471 rtx from_line = find_line_note (from);
2472 rtx after_line = find_line_note (after);
2474 reorder_insns (from, to, after);
2476 if (from_line == after_line)
2477 return;
2479 if (from_line)
2480 emit_line_note_after (NOTE_SOURCE_FILE (from_line),
2481 NOTE_LINE_NUMBER (from_line),
2482 after);
2483 if (after_line)
2484 emit_line_note_after (NOTE_SOURCE_FILE (after_line),
2485 NOTE_LINE_NUMBER (after_line),
2486 to);
2489 /* Emit an insn of given code and pattern
2490 at a specified place within the doubly-linked list. */
2492 /* Make an instruction with body PATTERN
2493 and output it before the instruction BEFORE. */
2496 emit_insn_before (pattern, before)
2497 register rtx pattern, before;
2499 register rtx insn = before;
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_before (insn, before);
2510 if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
2511 sequence_result[XVECLEN (pattern, 0)] = pattern;
2513 else
2515 insn = make_insn_raw (pattern);
2516 add_insn_before (insn, before);
2519 return insn;
2522 /* Make an instruction with body PATTERN and code JUMP_INSN
2523 and output it before the instruction BEFORE. */
2526 emit_jump_insn_before (pattern, before)
2527 register rtx pattern, before;
2529 register rtx insn;
2531 if (GET_CODE (pattern) == SEQUENCE)
2532 insn = emit_insn_before (pattern, before);
2533 else
2535 insn = make_jump_insn_raw (pattern);
2536 add_insn_before (insn, before);
2539 return insn;
2542 /* Make an instruction with body PATTERN and code CALL_INSN
2543 and output it before the instruction BEFORE. */
2546 emit_call_insn_before (pattern, before)
2547 register rtx pattern, before;
2549 register rtx insn;
2551 if (GET_CODE (pattern) == SEQUENCE)
2552 insn = emit_insn_before (pattern, before);
2553 else
2555 insn = make_call_insn_raw (pattern);
2556 add_insn_before (insn, before);
2557 PUT_CODE (insn, CALL_INSN);
2560 return insn;
2563 /* Make an insn of code BARRIER
2564 and output it before the insn AFTER. */
2567 emit_barrier_before (before)
2568 register rtx before;
2570 register rtx insn = rtx_alloc (BARRIER);
2572 INSN_UID (insn) = cur_insn_uid++;
2574 add_insn_before (insn, before);
2575 return insn;
2578 /* Emit a note of subtype SUBTYPE before the insn BEFORE. */
2581 emit_note_before (subtype, before)
2582 int subtype;
2583 rtx before;
2585 register rtx note = rtx_alloc (NOTE);
2586 INSN_UID (note) = cur_insn_uid++;
2587 NOTE_SOURCE_FILE (note) = 0;
2588 NOTE_LINE_NUMBER (note) = subtype;
2590 add_insn_before (note, before);
2591 return note;
2594 /* Make an insn of code INSN with body PATTERN
2595 and output it after the insn AFTER. */
2598 emit_insn_after (pattern, after)
2599 register rtx pattern, after;
2601 register rtx insn = after;
2603 if (GET_CODE (pattern) == SEQUENCE)
2605 register int i;
2607 for (i = 0; i < XVECLEN (pattern, 0); i++)
2609 insn = XVECEXP (pattern, 0, i);
2610 add_insn_after (insn, after);
2611 after = insn;
2613 if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
2614 sequence_result[XVECLEN (pattern, 0)] = pattern;
2616 else
2618 insn = make_insn_raw (pattern);
2619 add_insn_after (insn, after);
2622 return insn;
2625 /* Similar to emit_insn_after, except that line notes are to be inserted so
2626 as to act as if this insn were at FROM. */
2628 void
2629 emit_insn_after_with_line_notes (pattern, after, from)
2630 rtx pattern, after, from;
2632 rtx from_line = find_line_note (from);
2633 rtx after_line = find_line_note (after);
2634 rtx insn = emit_insn_after (pattern, after);
2636 if (from_line)
2637 emit_line_note_after (NOTE_SOURCE_FILE (from_line),
2638 NOTE_LINE_NUMBER (from_line),
2639 after);
2641 if (after_line)
2642 emit_line_note_after (NOTE_SOURCE_FILE (after_line),
2643 NOTE_LINE_NUMBER (after_line),
2644 insn);
2647 /* Make an insn of code JUMP_INSN with body PATTERN
2648 and output it after the insn AFTER. */
2651 emit_jump_insn_after (pattern, after)
2652 register rtx pattern, after;
2654 register rtx insn;
2656 if (GET_CODE (pattern) == SEQUENCE)
2657 insn = emit_insn_after (pattern, after);
2658 else
2660 insn = make_jump_insn_raw (pattern);
2661 add_insn_after (insn, after);
2664 return insn;
2667 /* Make an insn of code BARRIER
2668 and output it after the insn AFTER. */
2671 emit_barrier_after (after)
2672 register rtx after;
2674 register rtx insn = rtx_alloc (BARRIER);
2676 INSN_UID (insn) = cur_insn_uid++;
2678 add_insn_after (insn, after);
2679 return insn;
2682 /* Emit the label LABEL after the insn AFTER. */
2685 emit_label_after (label, after)
2686 rtx label, after;
2688 /* This can be called twice for the same label
2689 as a result of the confusion that follows a syntax error!
2690 So make it harmless. */
2691 if (INSN_UID (label) == 0)
2693 INSN_UID (label) = cur_insn_uid++;
2694 add_insn_after (label, after);
2697 return label;
2700 /* Emit a note of subtype SUBTYPE after the insn AFTER. */
2703 emit_note_after (subtype, after)
2704 int subtype;
2705 rtx after;
2707 register rtx note = rtx_alloc (NOTE);
2708 INSN_UID (note) = cur_insn_uid++;
2709 NOTE_SOURCE_FILE (note) = 0;
2710 NOTE_LINE_NUMBER (note) = subtype;
2711 add_insn_after (note, after);
2712 return note;
2715 /* Emit a line note for FILE and LINE after the insn AFTER. */
2718 emit_line_note_after (file, line, after)
2719 char *file;
2720 int line;
2721 rtx after;
2723 register rtx note;
2725 if (no_line_numbers && line > 0)
2727 cur_insn_uid++;
2728 return 0;
2731 note = rtx_alloc (NOTE);
2732 INSN_UID (note) = cur_insn_uid++;
2733 NOTE_SOURCE_FILE (note) = file;
2734 NOTE_LINE_NUMBER (note) = line;
2735 add_insn_after (note, after);
2736 return note;
2739 /* Make an insn of code INSN with pattern PATTERN
2740 and add it to the end of the doubly-linked list.
2741 If PATTERN is a SEQUENCE, take the elements of it
2742 and emit an insn for each element.
2744 Returns the last insn emitted. */
2747 emit_insn (pattern)
2748 rtx pattern;
2750 rtx insn = last_insn;
2752 if (GET_CODE (pattern) == SEQUENCE)
2754 register int i;
2756 for (i = 0; i < XVECLEN (pattern, 0); i++)
2758 insn = XVECEXP (pattern, 0, i);
2759 add_insn (insn);
2761 if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
2762 sequence_result[XVECLEN (pattern, 0)] = pattern;
2764 else
2766 insn = make_insn_raw (pattern);
2767 add_insn (insn);
2770 return insn;
2773 /* Emit the insns in a chain starting with INSN.
2774 Return the last insn emitted. */
2777 emit_insns (insn)
2778 rtx insn;
2780 rtx last = 0;
2782 while (insn)
2784 rtx next = NEXT_INSN (insn);
2785 add_insn (insn);
2786 last = insn;
2787 insn = next;
2790 return last;
2793 /* Emit the insns in a chain starting with INSN and place them in front of
2794 the insn BEFORE. Return the last insn emitted. */
2797 emit_insns_before (insn, before)
2798 rtx insn;
2799 rtx before;
2801 rtx last = 0;
2803 while (insn)
2805 rtx next = NEXT_INSN (insn);
2806 add_insn_before (insn, before);
2807 last = insn;
2808 insn = next;
2811 return last;
2814 /* Emit the insns in a chain starting with FIRST and place them in back of
2815 the insn AFTER. Return the last insn emitted. */
2818 emit_insns_after (first, after)
2819 register rtx first;
2820 register rtx after;
2822 register rtx last;
2823 register rtx after_after;
2825 if (!after)
2826 abort ();
2828 if (!first)
2829 return first;
2831 for (last = first; NEXT_INSN (last); last = NEXT_INSN (last))
2832 continue;
2834 after_after = NEXT_INSN (after);
2836 NEXT_INSN (after) = first;
2837 PREV_INSN (first) = after;
2838 NEXT_INSN (last) = after_after;
2839 if (after_after)
2840 PREV_INSN (after_after) = last;
2842 if (after == last_insn)
2843 last_insn = last;
2844 return last;
2847 /* Make an insn of code JUMP_INSN with pattern PATTERN
2848 and add it to the end of the doubly-linked list. */
2851 emit_jump_insn (pattern)
2852 rtx pattern;
2854 if (GET_CODE (pattern) == SEQUENCE)
2855 return emit_insn (pattern);
2856 else
2858 register rtx insn = make_jump_insn_raw (pattern);
2859 add_insn (insn);
2860 return insn;
2864 /* Make an insn of code CALL_INSN with pattern PATTERN
2865 and add it to the end of the doubly-linked list. */
2868 emit_call_insn (pattern)
2869 rtx pattern;
2871 if (GET_CODE (pattern) == SEQUENCE)
2872 return emit_insn (pattern);
2873 else
2875 register rtx insn = make_call_insn_raw (pattern);
2876 add_insn (insn);
2877 PUT_CODE (insn, CALL_INSN);
2878 return insn;
2882 /* Add the label LABEL to the end of the doubly-linked list. */
2885 emit_label (label)
2886 rtx label;
2888 /* This can be called twice for the same label
2889 as a result of the confusion that follows a syntax error!
2890 So make it harmless. */
2891 if (INSN_UID (label) == 0)
2893 INSN_UID (label) = cur_insn_uid++;
2894 add_insn (label);
2896 return label;
2899 /* Make an insn of code BARRIER
2900 and add it to the end of the doubly-linked list. */
2903 emit_barrier ()
2905 register rtx barrier = rtx_alloc (BARRIER);
2906 INSN_UID (barrier) = cur_insn_uid++;
2907 add_insn (barrier);
2908 return barrier;
2911 /* Make an insn of code NOTE
2912 with data-fields specified by FILE and LINE
2913 and add it to the end of the doubly-linked list,
2914 but only if line-numbers are desired for debugging info. */
2917 emit_line_note (file, line)
2918 char *file;
2919 int line;
2921 if (output_bytecode)
2923 /* FIXME: for now we do nothing, but eventually we will have to deal with
2924 debugging information. */
2925 return 0;
2928 emit_filename = file;
2929 emit_lineno = line;
2931 #if 0
2932 if (no_line_numbers)
2933 return 0;
2934 #endif
2936 return emit_note (file, line);
2939 /* Make an insn of code NOTE
2940 with data-fields specified by FILE and LINE
2941 and add it to the end of the doubly-linked list.
2942 If it is a line-number NOTE, omit it if it matches the previous one. */
2945 emit_note (file, line)
2946 char *file;
2947 int line;
2949 register rtx note;
2951 if (line > 0)
2953 if (file && last_filename && !strcmp (file, last_filename)
2954 && line == last_linenum)
2955 return 0;
2956 last_filename = file;
2957 last_linenum = line;
2960 if (no_line_numbers && line > 0)
2962 cur_insn_uid++;
2963 return 0;
2966 note = rtx_alloc (NOTE);
2967 INSN_UID (note) = cur_insn_uid++;
2968 NOTE_SOURCE_FILE (note) = file;
2969 NOTE_LINE_NUMBER (note) = line;
2970 add_insn (note);
2971 return note;
2974 /* Emit a NOTE, and don't omit it even if LINE it the previous note. */
2977 emit_line_note_force (file, line)
2978 char *file;
2979 int line;
2981 last_linenum = -1;
2982 return emit_line_note (file, line);
2985 /* Cause next statement to emit a line note even if the line number
2986 has not changed. This is used at the beginning of a function. */
2988 void
2989 force_next_line_note ()
2991 last_linenum = -1;
2994 /* Return an indication of which type of insn should have X as a body.
2995 The value is CODE_LABEL, INSN, CALL_INSN or JUMP_INSN. */
2997 enum rtx_code
2998 classify_insn (x)
2999 rtx x;
3001 if (GET_CODE (x) == CODE_LABEL)
3002 return CODE_LABEL;
3003 if (GET_CODE (x) == CALL)
3004 return CALL_INSN;
3005 if (GET_CODE (x) == RETURN)
3006 return JUMP_INSN;
3007 if (GET_CODE (x) == SET)
3009 if (SET_DEST (x) == pc_rtx)
3010 return JUMP_INSN;
3011 else if (GET_CODE (SET_SRC (x)) == CALL)
3012 return CALL_INSN;
3013 else
3014 return INSN;
3016 if (GET_CODE (x) == PARALLEL)
3018 register int j;
3019 for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
3020 if (GET_CODE (XVECEXP (x, 0, j)) == CALL)
3021 return CALL_INSN;
3022 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
3023 && SET_DEST (XVECEXP (x, 0, j)) == pc_rtx)
3024 return JUMP_INSN;
3025 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
3026 && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == CALL)
3027 return CALL_INSN;
3029 return INSN;
3032 /* Emit the rtl pattern X as an appropriate kind of insn.
3033 If X is a label, it is simply added into the insn chain. */
3036 emit (x)
3037 rtx x;
3039 enum rtx_code code = classify_insn (x);
3041 if (code == CODE_LABEL)
3042 return emit_label (x);
3043 else if (code == INSN)
3044 return emit_insn (x);
3045 else if (code == JUMP_INSN)
3047 register rtx insn = emit_jump_insn (x);
3048 if (simplejump_p (insn) || GET_CODE (x) == RETURN)
3049 return emit_barrier ();
3050 return insn;
3052 else if (code == CALL_INSN)
3053 return emit_call_insn (x);
3054 else
3055 abort ();
3058 /* Begin emitting insns to a sequence which can be packaged in an RTL_EXPR. */
3060 void
3061 start_sequence ()
3063 struct sequence_stack *tem;
3065 if (sequence_element_free_list)
3067 /* Reuse a previously-saved struct sequence_stack. */
3068 tem = sequence_element_free_list;
3069 sequence_element_free_list = tem->next;
3071 else
3072 tem = (struct sequence_stack *) permalloc (sizeof (struct sequence_stack));
3074 tem->next = sequence_stack;
3075 tem->first = first_insn;
3076 tem->last = last_insn;
3077 tem->sequence_rtl_expr = sequence_rtl_expr;
3079 sequence_stack = tem;
3081 first_insn = 0;
3082 last_insn = 0;
3085 /* Similarly, but indicate that this sequence will be placed in
3086 T, an RTL_EXPR. */
3088 void
3089 start_sequence_for_rtl_expr (t)
3090 tree t;
3092 start_sequence ();
3094 sequence_rtl_expr = t;
3097 /* Set up the insn chain starting with FIRST
3098 as the current sequence, saving the previously current one. */
3100 void
3101 push_to_sequence (first)
3102 rtx first;
3104 rtx last;
3106 start_sequence ();
3108 for (last = first; last && NEXT_INSN (last); last = NEXT_INSN (last));
3110 first_insn = first;
3111 last_insn = last;
3114 /* Set up the outer-level insn chain
3115 as the current sequence, saving the previously current one. */
3117 void
3118 push_topmost_sequence ()
3120 struct sequence_stack *stack, *top;
3122 start_sequence ();
3124 for (stack = sequence_stack; stack; stack = stack->next)
3125 top = stack;
3127 first_insn = top->first;
3128 last_insn = top->last;
3129 sequence_rtl_expr = top->sequence_rtl_expr;
3132 /* After emitting to the outer-level insn chain, update the outer-level
3133 insn chain, and restore the previous saved state. */
3135 void
3136 pop_topmost_sequence ()
3138 struct sequence_stack *stack, *top;
3140 for (stack = sequence_stack; stack; stack = stack->next)
3141 top = stack;
3143 top->first = first_insn;
3144 top->last = last_insn;
3145 /* ??? Why don't we save sequence_rtl_expr here? */
3147 end_sequence ();
3150 /* After emitting to a sequence, restore previous saved state.
3152 To get the contents of the sequence just made,
3153 you must call `gen_sequence' *before* calling here. */
3155 void
3156 end_sequence ()
3158 struct sequence_stack *tem = sequence_stack;
3160 first_insn = tem->first;
3161 last_insn = tem->last;
3162 sequence_rtl_expr = tem->sequence_rtl_expr;
3163 sequence_stack = tem->next;
3165 tem->next = sequence_element_free_list;
3166 sequence_element_free_list = tem;
3169 /* Return 1 if currently emitting into a sequence. */
3172 in_sequence_p ()
3174 return sequence_stack != 0;
3177 /* Generate a SEQUENCE rtx containing the insns already emitted
3178 to the current sequence.
3180 This is how the gen_... function from a DEFINE_EXPAND
3181 constructs the SEQUENCE that it returns. */
3184 gen_sequence ()
3186 rtx result;
3187 rtx tem;
3188 int i;
3189 int len;
3191 /* Count the insns in the chain. */
3192 len = 0;
3193 for (tem = first_insn; tem; tem = NEXT_INSN (tem))
3194 len++;
3196 /* If only one insn, return its pattern rather than a SEQUENCE.
3197 (Now that we cache SEQUENCE expressions, it isn't worth special-casing
3198 the case of an empty list.) */
3199 if (len == 1
3200 && ! RTX_FRAME_RELATED_P (first_insn)
3201 && (GET_CODE (first_insn) == INSN
3202 || GET_CODE (first_insn) == JUMP_INSN
3203 /* Don't discard the call usage field. */
3204 || (GET_CODE (first_insn) == CALL_INSN
3205 && CALL_INSN_FUNCTION_USAGE (first_insn) == NULL_RTX)))
3207 NEXT_INSN (first_insn) = free_insn;
3208 free_insn = first_insn;
3209 return PATTERN (first_insn);
3212 /* Put them in a vector. See if we already have a SEQUENCE of the
3213 appropriate length around. */
3214 if (len < SEQUENCE_RESULT_SIZE && (result = sequence_result[len]) != 0)
3215 sequence_result[len] = 0;
3216 else
3218 /* Ensure that this rtl goes in saveable_obstack, since we may
3219 cache it. */
3220 push_obstacks_nochange ();
3221 rtl_in_saveable_obstack ();
3222 result = gen_rtx (SEQUENCE, VOIDmode, rtvec_alloc (len));
3223 pop_obstacks ();
3226 for (i = 0, tem = first_insn; tem; tem = NEXT_INSN (tem), i++)
3227 XVECEXP (result, 0, i) = tem;
3229 return result;
3232 /* Initialize data structures and variables in this file
3233 before generating rtl for each function. */
3235 void
3236 init_emit ()
3238 int i;
3240 first_insn = NULL;
3241 last_insn = NULL;
3242 sequence_rtl_expr = NULL;
3243 cur_insn_uid = 1;
3244 reg_rtx_no = LAST_VIRTUAL_REGISTER + 1;
3245 last_linenum = 0;
3246 last_filename = 0;
3247 first_label_num = label_num;
3248 last_label_num = 0;
3249 sequence_stack = NULL;
3251 /* Clear the start_sequence/gen_sequence cache. */
3252 sequence_element_free_list = 0;
3253 for (i = 0; i < SEQUENCE_RESULT_SIZE; i++)
3254 sequence_result[i] = 0;
3255 free_insn = 0;
3257 /* Init the tables that describe all the pseudo regs. */
3259 regno_pointer_flag_length = LAST_VIRTUAL_REGISTER + 101;
3261 regno_pointer_flag
3262 = (char *) savealloc (regno_pointer_flag_length);
3263 bzero (regno_pointer_flag, regno_pointer_flag_length);
3265 regno_pointer_align
3266 = (char *) savealloc (regno_pointer_flag_length);
3267 bzero (regno_pointer_align, regno_pointer_flag_length);
3269 regno_reg_rtx
3270 = (rtx *) savealloc (regno_pointer_flag_length * sizeof (rtx));
3271 bzero ((char *) regno_reg_rtx, regno_pointer_flag_length * sizeof (rtx));
3273 /* Put copies of all the virtual register rtx into regno_reg_rtx. */
3274 regno_reg_rtx[VIRTUAL_INCOMING_ARGS_REGNUM] = virtual_incoming_args_rtx;
3275 regno_reg_rtx[VIRTUAL_STACK_VARS_REGNUM] = virtual_stack_vars_rtx;
3276 regno_reg_rtx[VIRTUAL_STACK_DYNAMIC_REGNUM] = virtual_stack_dynamic_rtx;
3277 regno_reg_rtx[VIRTUAL_OUTGOING_ARGS_REGNUM] = virtual_outgoing_args_rtx;
3279 /* Indicate that the virtual registers and stack locations are
3280 all pointers. */
3281 REGNO_POINTER_FLAG (STACK_POINTER_REGNUM) = 1;
3282 REGNO_POINTER_FLAG (FRAME_POINTER_REGNUM) = 1;
3283 REGNO_POINTER_FLAG (HARD_FRAME_POINTER_REGNUM) = 1;
3284 REGNO_POINTER_FLAG (ARG_POINTER_REGNUM) = 1;
3286 REGNO_POINTER_FLAG (VIRTUAL_INCOMING_ARGS_REGNUM) = 1;
3287 REGNO_POINTER_FLAG (VIRTUAL_STACK_VARS_REGNUM) = 1;
3288 REGNO_POINTER_FLAG (VIRTUAL_STACK_DYNAMIC_REGNUM) = 1;
3289 REGNO_POINTER_FLAG (VIRTUAL_OUTGOING_ARGS_REGNUM) = 1;
3291 #ifdef STACK_BOUNDARY
3292 REGNO_POINTER_ALIGN (STACK_POINTER_REGNUM) = STACK_BOUNDARY / BITS_PER_UNIT;
3293 REGNO_POINTER_ALIGN (FRAME_POINTER_REGNUM) = STACK_BOUNDARY / BITS_PER_UNIT;
3294 REGNO_POINTER_ALIGN (HARD_FRAME_POINTER_REGNUM)
3295 = STACK_BOUNDARY / BITS_PER_UNIT;
3296 REGNO_POINTER_ALIGN (ARG_POINTER_REGNUM) = STACK_BOUNDARY / BITS_PER_UNIT;
3298 REGNO_POINTER_ALIGN (VIRTUAL_INCOMING_ARGS_REGNUM)
3299 = STACK_BOUNDARY / BITS_PER_UNIT;
3300 REGNO_POINTER_ALIGN (VIRTUAL_STACK_VARS_REGNUM)
3301 = STACK_BOUNDARY / BITS_PER_UNIT;
3302 REGNO_POINTER_ALIGN (VIRTUAL_STACK_DYNAMIC_REGNUM)
3303 = STACK_BOUNDARY / BITS_PER_UNIT;
3304 REGNO_POINTER_ALIGN (VIRTUAL_OUTGOING_ARGS_REGNUM)
3305 = STACK_BOUNDARY / BITS_PER_UNIT;
3306 #endif
3308 #ifdef INIT_EXPANDERS
3309 INIT_EXPANDERS;
3310 #endif
3313 /* Create some permanent unique rtl objects shared between all functions.
3314 LINE_NUMBERS is nonzero if line numbers are to be generated. */
3316 void
3317 init_emit_once (line_numbers)
3318 int line_numbers;
3320 int i;
3321 enum machine_mode mode;
3323 no_line_numbers = ! line_numbers;
3325 sequence_stack = NULL;
3327 /* Compute the word and byte modes. */
3329 byte_mode = VOIDmode;
3330 word_mode = VOIDmode;
3332 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
3333 mode = GET_MODE_WIDER_MODE (mode))
3335 if (GET_MODE_BITSIZE (mode) == BITS_PER_UNIT
3336 && byte_mode == VOIDmode)
3337 byte_mode = mode;
3339 if (GET_MODE_BITSIZE (mode) == BITS_PER_WORD
3340 && word_mode == VOIDmode)
3341 word_mode = mode;
3344 ptr_mode = mode_for_size (POINTER_SIZE, GET_MODE_CLASS (Pmode), 0);
3346 /* Create the unique rtx's for certain rtx codes and operand values. */
3348 pc_rtx = gen_rtx (PC, VOIDmode);
3349 cc0_rtx = gen_rtx (CC0, VOIDmode);
3351 /* Don't use gen_rtx here since gen_rtx in this case
3352 tries to use these variables. */
3353 for (i = - MAX_SAVED_CONST_INT; i <= MAX_SAVED_CONST_INT; i++)
3355 const_int_rtx[i + MAX_SAVED_CONST_INT] = rtx_alloc (CONST_INT);
3356 PUT_MODE (const_int_rtx[i + MAX_SAVED_CONST_INT], VOIDmode);
3357 INTVAL (const_int_rtx[i + MAX_SAVED_CONST_INT]) = i;
3360 /* These four calls obtain some of the rtx expressions made above. */
3361 const0_rtx = GEN_INT (0);
3362 const1_rtx = GEN_INT (1);
3363 const2_rtx = GEN_INT (2);
3364 constm1_rtx = GEN_INT (-1);
3366 /* This will usually be one of the above constants, but may be a new rtx. */
3367 const_true_rtx = GEN_INT (STORE_FLAG_VALUE);
3369 dconst0 = REAL_VALUE_ATOF ("0", DFmode);
3370 dconst1 = REAL_VALUE_ATOF ("1", DFmode);
3371 dconst2 = REAL_VALUE_ATOF ("2", DFmode);
3372 dconstm1 = REAL_VALUE_ATOF ("-1", DFmode);
3374 for (i = 0; i <= 2; i++)
3376 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
3377 mode = GET_MODE_WIDER_MODE (mode))
3379 rtx tem = rtx_alloc (CONST_DOUBLE);
3380 union real_extract u;
3382 bzero ((char *) &u, sizeof u); /* Zero any holes in a structure. */
3383 u.d = i == 0 ? dconst0 : i == 1 ? dconst1 : dconst2;
3385 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (tem), sizeof u);
3386 CONST_DOUBLE_MEM (tem) = cc0_rtx;
3387 PUT_MODE (tem, mode);
3389 const_tiny_rtx[i][(int) mode] = tem;
3392 const_tiny_rtx[i][(int) VOIDmode] = GEN_INT (i);
3394 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
3395 mode = GET_MODE_WIDER_MODE (mode))
3396 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
3398 for (mode = GET_CLASS_NARROWEST_MODE (MODE_PARTIAL_INT);
3399 mode != VOIDmode;
3400 mode = GET_MODE_WIDER_MODE (mode))
3401 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
3404 for (mode = GET_CLASS_NARROWEST_MODE (MODE_CC); mode != VOIDmode;
3405 mode = GET_MODE_WIDER_MODE (mode))
3406 const_tiny_rtx[0][(int) mode] = const0_rtx;
3408 stack_pointer_rtx = gen_rtx (REG, Pmode, STACK_POINTER_REGNUM);
3409 frame_pointer_rtx = gen_rtx (REG, Pmode, FRAME_POINTER_REGNUM);
3411 if (HARD_FRAME_POINTER_REGNUM == FRAME_POINTER_REGNUM)
3412 hard_frame_pointer_rtx = frame_pointer_rtx;
3413 else
3414 hard_frame_pointer_rtx = gen_rtx (REG, Pmode, HARD_FRAME_POINTER_REGNUM);
3416 if (FRAME_POINTER_REGNUM == ARG_POINTER_REGNUM)
3417 arg_pointer_rtx = frame_pointer_rtx;
3418 else if (HARD_FRAME_POINTER_REGNUM == ARG_POINTER_REGNUM)
3419 arg_pointer_rtx = hard_frame_pointer_rtx;
3420 else if (STACK_POINTER_REGNUM == ARG_POINTER_REGNUM)
3421 arg_pointer_rtx = stack_pointer_rtx;
3422 else
3423 arg_pointer_rtx = gen_rtx (REG, Pmode, ARG_POINTER_REGNUM);
3425 #ifdef RETURN_ADDRESS_POINTER_REGNUM
3426 return_address_pointer_rtx = gen_rtx (REG, Pmode,
3427 RETURN_ADDRESS_POINTER_REGNUM);
3428 #endif
3430 /* Create the virtual registers. Do so here since the following objects
3431 might reference them. */
3433 virtual_incoming_args_rtx = gen_rtx (REG, Pmode,
3434 VIRTUAL_INCOMING_ARGS_REGNUM);
3435 virtual_stack_vars_rtx = gen_rtx (REG, Pmode,
3436 VIRTUAL_STACK_VARS_REGNUM);
3437 virtual_stack_dynamic_rtx = gen_rtx (REG, Pmode,
3438 VIRTUAL_STACK_DYNAMIC_REGNUM);
3439 virtual_outgoing_args_rtx = gen_rtx (REG, Pmode,
3440 VIRTUAL_OUTGOING_ARGS_REGNUM);
3442 #ifdef STRUCT_VALUE
3443 struct_value_rtx = STRUCT_VALUE;
3444 #else
3445 struct_value_rtx = gen_rtx (REG, Pmode, STRUCT_VALUE_REGNUM);
3446 #endif
3448 #ifdef STRUCT_VALUE_INCOMING
3449 struct_value_incoming_rtx = STRUCT_VALUE_INCOMING;
3450 #else
3451 #ifdef STRUCT_VALUE_INCOMING_REGNUM
3452 struct_value_incoming_rtx
3453 = gen_rtx (REG, Pmode, STRUCT_VALUE_INCOMING_REGNUM);
3454 #else
3455 struct_value_incoming_rtx = struct_value_rtx;
3456 #endif
3457 #endif
3459 #ifdef STATIC_CHAIN_REGNUM
3460 static_chain_rtx = gen_rtx (REG, Pmode, STATIC_CHAIN_REGNUM);
3462 #ifdef STATIC_CHAIN_INCOMING_REGNUM
3463 if (STATIC_CHAIN_INCOMING_REGNUM != STATIC_CHAIN_REGNUM)
3464 static_chain_incoming_rtx = gen_rtx (REG, Pmode, STATIC_CHAIN_INCOMING_REGNUM);
3465 else
3466 #endif
3467 static_chain_incoming_rtx = static_chain_rtx;
3468 #endif
3470 #ifdef STATIC_CHAIN
3471 static_chain_rtx = STATIC_CHAIN;
3473 #ifdef STATIC_CHAIN_INCOMING
3474 static_chain_incoming_rtx = STATIC_CHAIN_INCOMING;
3475 #else
3476 static_chain_incoming_rtx = static_chain_rtx;
3477 #endif
3478 #endif
3480 #ifdef PIC_OFFSET_TABLE_REGNUM
3481 pic_offset_table_rtx = gen_rtx (REG, Pmode, PIC_OFFSET_TABLE_REGNUM);
3482 #endif