Pass 9th fp argument correctly on System V/eabi; Add @plt for -fPIC/-mrelocatable
[official-gcc.git] / gcc / emit-rtl.c
blob2204cec03c307eedae7ec87fed2ed0413babe8aa
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 #include <stdio.h>
39 #ifdef __STDC__
40 #include <stdarg.h>
41 #else
42 #include <varargs.h>
43 #endif
44 #include "rtl.h"
45 #include "tree.h"
46 #include "flags.h"
47 #include "except.h"
48 #include "function.h"
49 #include "expr.h"
50 #include "regs.h"
51 #include "insn-config.h"
52 #include "recog.h"
53 #include "real.h"
54 #include "obstack.h"
56 #include "bytecode.h"
57 #include "machmode.h"
58 #include "bc-opcode.h"
59 #include "bc-typecd.h"
60 #include "bc-optab.h"
61 #include "bc-emit.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 if (GET_CODE (x) == ADDRESSOF)
962 return gen_lowpart (mode, force_reg (GET_MODE (x), x));
963 else
964 abort ();
967 /* Like `gen_lowpart', but refer to the most significant part.
968 This is used to access the imaginary part of a complex number. */
971 gen_highpart (mode, x)
972 enum machine_mode mode;
973 register rtx x;
975 /* This case loses if X is a subreg. To catch bugs early,
976 complain if an invalid MODE is used even in other cases. */
977 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
978 && GET_MODE_SIZE (mode) != GET_MODE_UNIT_SIZE (GET_MODE (x)))
979 abort ();
980 if (GET_CODE (x) == CONST_DOUBLE
981 #if !(TARGET_FLOAT_FORMAT != HOST_FLOAT_FORMAT || defined (REAL_IS_NOT_DOUBLE))
982 && GET_MODE_CLASS (GET_MODE (x)) != MODE_FLOAT
983 #endif
985 return gen_rtx (CONST_INT, VOIDmode,
986 CONST_DOUBLE_HIGH (x) & GET_MODE_MASK (mode));
987 else if (GET_CODE (x) == CONST_INT)
988 return const0_rtx;
989 else if (GET_CODE (x) == MEM)
991 register int offset = 0;
992 if (! WORDS_BIG_ENDIAN)
993 offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
994 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
996 if (! BYTES_BIG_ENDIAN
997 && GET_MODE_SIZE (mode) < UNITS_PER_WORD)
998 offset -= (GET_MODE_SIZE (mode)
999 - MIN (UNITS_PER_WORD,
1000 GET_MODE_SIZE (GET_MODE (x))));
1002 return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
1004 else if (GET_CODE (x) == SUBREG)
1006 /* The only time this should occur is when we are looking at a
1007 multi-word item with a SUBREG whose mode is the same as that of the
1008 item. It isn't clear what we would do if it wasn't. */
1009 if (SUBREG_WORD (x) != 0)
1010 abort ();
1011 return gen_highpart (mode, SUBREG_REG (x));
1013 else if (GET_CODE (x) == REG)
1015 int word = 0;
1017 if (! WORDS_BIG_ENDIAN
1018 && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
1019 word = ((GET_MODE_SIZE (GET_MODE (x))
1020 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD))
1021 / UNITS_PER_WORD);
1024 * ??? This fails miserably for complex values being passed in registers
1025 * where the sizeof the real and imaginary part are not equal to the
1026 * sizeof SImode. FIXME
1029 if (REGNO (x) < FIRST_PSEUDO_REGISTER
1030 /* integrate.c can't handle parts of a return value register. */
1031 && (! REG_FUNCTION_VALUE_P (x)
1032 || ! rtx_equal_function_value_matters)
1033 /* We want to keep the stack, frame, and arg pointers special. */
1034 && x != frame_pointer_rtx
1035 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1036 && x != arg_pointer_rtx
1037 #endif
1038 && x != stack_pointer_rtx)
1039 return gen_rtx (REG, mode, REGNO (x) + word);
1040 else
1041 return gen_rtx (SUBREG, mode, x, word);
1043 else
1044 abort ();
1047 /* Return 1 iff X, assumed to be a SUBREG,
1048 refers to the least significant part of its containing reg.
1049 If X is not a SUBREG, always return 1 (it is its own low part!). */
1052 subreg_lowpart_p (x)
1053 rtx x;
1055 if (GET_CODE (x) != SUBREG)
1056 return 1;
1057 else if (GET_MODE (SUBREG_REG (x)) == VOIDmode)
1058 return 0;
1060 if (WORDS_BIG_ENDIAN
1061 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) > UNITS_PER_WORD)
1062 return (SUBREG_WORD (x)
1063 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
1064 - MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD))
1065 / UNITS_PER_WORD));
1067 return SUBREG_WORD (x) == 0;
1070 /* Return subword I of operand OP.
1071 The word number, I, is interpreted as the word number starting at the
1072 low-order address. Word 0 is the low-order word if not WORDS_BIG_ENDIAN,
1073 otherwise it is the high-order word.
1075 If we cannot extract the required word, we return zero. Otherwise, an
1076 rtx corresponding to the requested word will be returned.
1078 VALIDATE_ADDRESS is nonzero if the address should be validated. Before
1079 reload has completed, a valid address will always be returned. After
1080 reload, if a valid address cannot be returned, we return zero.
1082 If VALIDATE_ADDRESS is zero, we simply form the required address; validating
1083 it is the responsibility of the caller.
1085 MODE is the mode of OP in case it is a CONST_INT. */
1088 operand_subword (op, i, validate_address, mode)
1089 rtx op;
1090 int i;
1091 int validate_address;
1092 enum machine_mode mode;
1094 HOST_WIDE_INT val;
1095 int size_ratio = HOST_BITS_PER_WIDE_INT / BITS_PER_WORD;
1097 if (mode == VOIDmode)
1098 mode = GET_MODE (op);
1100 if (mode == VOIDmode)
1101 abort ();
1103 /* If OP is narrower than a word or if we want a word outside OP, fail. */
1104 if (mode != BLKmode
1105 && (GET_MODE_SIZE (mode) < UNITS_PER_WORD
1106 || (i + 1) * UNITS_PER_WORD > GET_MODE_SIZE (mode)))
1107 return 0;
1109 /* If OP is already an integer word, return it. */
1110 if (GET_MODE_CLASS (mode) == MODE_INT
1111 && GET_MODE_SIZE (mode) == UNITS_PER_WORD)
1112 return op;
1114 /* If OP is a REG or SUBREG, we can handle it very simply. */
1115 if (GET_CODE (op) == REG)
1117 /* If the register is not valid for MODE, return 0. If we don't
1118 do this, there is no way to fix up the resulting REG later. */
1119 if (REGNO (op) < FIRST_PSEUDO_REGISTER
1120 && ! HARD_REGNO_MODE_OK (REGNO (op) + i, word_mode))
1121 return 0;
1122 else if (REGNO (op) >= FIRST_PSEUDO_REGISTER
1123 || (REG_FUNCTION_VALUE_P (op)
1124 && rtx_equal_function_value_matters)
1125 /* We want to keep the stack, frame, and arg pointers
1126 special. */
1127 || op == frame_pointer_rtx
1128 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1129 || op == arg_pointer_rtx
1130 #endif
1131 || op == stack_pointer_rtx)
1132 return gen_rtx (SUBREG, word_mode, op, i);
1133 else
1134 return gen_rtx (REG, word_mode, REGNO (op) + i);
1136 else if (GET_CODE (op) == SUBREG)
1137 return gen_rtx (SUBREG, word_mode, SUBREG_REG (op), i + SUBREG_WORD (op));
1138 else if (GET_CODE (op) == CONCAT)
1140 int partwords = GET_MODE_UNIT_SIZE (GET_MODE (op)) / UNITS_PER_WORD;
1141 if (i < partwords)
1142 return operand_subword (XEXP (op, 0), i, validate_address, mode);
1143 return operand_subword (XEXP (op, 1), i - partwords,
1144 validate_address, mode);
1147 /* Form a new MEM at the requested address. */
1148 if (GET_CODE (op) == MEM)
1150 rtx addr = plus_constant (XEXP (op, 0), i * UNITS_PER_WORD);
1151 rtx new;
1153 if (validate_address)
1155 if (reload_completed)
1157 if (! strict_memory_address_p (word_mode, addr))
1158 return 0;
1160 else
1161 addr = memory_address (word_mode, addr);
1164 new = gen_rtx (MEM, word_mode, addr);
1166 MEM_VOLATILE_P (new) = MEM_VOLATILE_P (op);
1167 MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (op);
1168 RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (op);
1170 return new;
1173 /* The only remaining cases are when OP is a constant. If the host and
1174 target floating formats are the same, handling two-word floating
1175 constants are easy. Note that REAL_VALUE_TO_TARGET_{SINGLE,DOUBLE}
1176 are defined as returning one or two 32 bit values, respectively,
1177 and not values of BITS_PER_WORD bits. */
1178 #ifdef REAL_ARITHMETIC
1179 /* The output is some bits, the width of the target machine's word.
1180 A wider-word host can surely hold them in a CONST_INT. A narrower-word
1181 host can't. */
1182 if (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
1183 && GET_MODE_CLASS (mode) == MODE_FLOAT
1184 && GET_MODE_BITSIZE (mode) == 64
1185 && GET_CODE (op) == CONST_DOUBLE)
1187 long k[2];
1188 REAL_VALUE_TYPE rv;
1190 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1191 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
1193 /* We handle 32-bit and >= 64-bit words here. Note that the order in
1194 which the words are written depends on the word endianness.
1196 ??? This is a potential portability problem and should
1197 be fixed at some point. */
1198 if (BITS_PER_WORD == 32)
1199 return GEN_INT ((HOST_WIDE_INT) k[i]);
1200 #if HOST_BITS_PER_WIDE_INT > 32
1201 else if (BITS_PER_WORD >= 64 && i == 0)
1202 return GEN_INT ((((HOST_WIDE_INT) k[! WORDS_BIG_ENDIAN]) << 32)
1203 | (HOST_WIDE_INT) k[WORDS_BIG_ENDIAN]);
1204 #endif
1205 else if (BITS_PER_WORD == 16)
1207 long value;
1208 value = k[i >> 1];
1209 if ((i & 0x1) == 0)
1210 value >>= 16;
1211 value &= 0xffff;
1212 return GEN_INT ((HOST_WIDE_INT) value);
1214 else
1215 abort ();
1217 else if (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
1218 && GET_MODE_CLASS (mode) == MODE_FLOAT
1219 && GET_MODE_BITSIZE (mode) > 64
1220 && GET_CODE (op) == CONST_DOUBLE)
1222 long k[4];
1223 REAL_VALUE_TYPE rv;
1225 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1226 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
1228 if (BITS_PER_WORD == 32)
1229 return GEN_INT ((HOST_WIDE_INT) k[i]);
1231 #else /* no REAL_ARITHMETIC */
1232 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1233 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1234 || flag_pretend_float)
1235 && GET_MODE_CLASS (mode) == MODE_FLOAT
1236 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
1237 && GET_CODE (op) == CONST_DOUBLE)
1239 /* The constant is stored in the host's word-ordering,
1240 but we want to access it in the target's word-ordering. Some
1241 compilers don't like a conditional inside macro args, so we have two
1242 copies of the return. */
1243 #ifdef HOST_WORDS_BIG_ENDIAN
1244 return GEN_INT (i == WORDS_BIG_ENDIAN
1245 ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
1246 #else
1247 return GEN_INT (i != WORDS_BIG_ENDIAN
1248 ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
1249 #endif
1251 #endif /* no REAL_ARITHMETIC */
1253 /* Single word float is a little harder, since single- and double-word
1254 values often do not have the same high-order bits. We have already
1255 verified that we want the only defined word of the single-word value. */
1256 #ifdef REAL_ARITHMETIC
1257 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1258 && GET_MODE_BITSIZE (mode) == 32
1259 && GET_CODE (op) == CONST_DOUBLE)
1261 long l;
1262 REAL_VALUE_TYPE rv;
1264 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1265 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
1266 return GEN_INT ((HOST_WIDE_INT) l);
1268 #else
1269 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1270 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1271 || flag_pretend_float)
1272 && sizeof (float) * 8 == HOST_BITS_PER_WIDE_INT
1273 && GET_MODE_CLASS (mode) == MODE_FLOAT
1274 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
1275 && GET_CODE (op) == CONST_DOUBLE)
1277 double d;
1278 union {float f; HOST_WIDE_INT i; } u;
1280 REAL_VALUE_FROM_CONST_DOUBLE (d, op);
1282 u.f = d;
1283 return GEN_INT (u.i);
1285 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1286 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1287 || flag_pretend_float)
1288 && sizeof (double) * 8 == HOST_BITS_PER_WIDE_INT
1289 && GET_MODE_CLASS (mode) == MODE_FLOAT
1290 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
1291 && GET_CODE (op) == CONST_DOUBLE)
1293 double d;
1294 union {double d; HOST_WIDE_INT i; } u;
1296 REAL_VALUE_FROM_CONST_DOUBLE (d, op);
1298 u.d = d;
1299 return GEN_INT (u.i);
1301 #endif /* no REAL_ARITHMETIC */
1303 /* The only remaining cases that we can handle are integers.
1304 Convert to proper endianness now since these cases need it.
1305 At this point, i == 0 means the low-order word.
1307 We do not want to handle the case when BITS_PER_WORD <= HOST_BITS_PER_INT
1308 in general. However, if OP is (const_int 0), we can just return
1309 it for any word. */
1311 if (op == const0_rtx)
1312 return op;
1314 if (GET_MODE_CLASS (mode) != MODE_INT
1315 || (GET_CODE (op) != CONST_INT && GET_CODE (op) != CONST_DOUBLE)
1316 || BITS_PER_WORD > HOST_BITS_PER_WIDE_INT)
1317 return 0;
1319 if (WORDS_BIG_ENDIAN)
1320 i = GET_MODE_SIZE (mode) / UNITS_PER_WORD - 1 - i;
1322 /* Find out which word on the host machine this value is in and get
1323 it from the constant. */
1324 val = (i / size_ratio == 0
1325 ? (GET_CODE (op) == CONST_INT ? INTVAL (op) : CONST_DOUBLE_LOW (op))
1326 : (GET_CODE (op) == CONST_INT
1327 ? (INTVAL (op) < 0 ? ~0 : 0) : CONST_DOUBLE_HIGH (op)));
1329 /* If BITS_PER_WORD is smaller than an int, get the appropriate bits. */
1330 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT)
1331 val = ((val >> ((i % size_ratio) * BITS_PER_WORD))
1332 & (((HOST_WIDE_INT) 1
1333 << (BITS_PER_WORD % HOST_BITS_PER_WIDE_INT)) - 1));
1335 return GEN_INT (val);
1338 /* Similar to `operand_subword', but never return 0. If we can't extract
1339 the required subword, put OP into a register and try again. If that fails,
1340 abort. We always validate the address in this case. It is not valid
1341 to call this function after reload; it is mostly meant for RTL
1342 generation.
1344 MODE is the mode of OP, in case it is CONST_INT. */
1347 operand_subword_force (op, i, mode)
1348 rtx op;
1349 int i;
1350 enum machine_mode mode;
1352 rtx result = operand_subword (op, i, 1, mode);
1354 if (result)
1355 return result;
1357 if (mode != BLKmode && mode != VOIDmode)
1358 op = force_reg (mode, op);
1360 result = operand_subword (op, i, 1, mode);
1361 if (result == 0)
1362 abort ();
1364 return result;
1367 /* Given a compare instruction, swap the operands.
1368 A test instruction is changed into a compare of 0 against the operand. */
1370 void
1371 reverse_comparison (insn)
1372 rtx insn;
1374 rtx body = PATTERN (insn);
1375 rtx comp;
1377 if (GET_CODE (body) == SET)
1378 comp = SET_SRC (body);
1379 else
1380 comp = SET_SRC (XVECEXP (body, 0, 0));
1382 if (GET_CODE (comp) == COMPARE)
1384 rtx op0 = XEXP (comp, 0);
1385 rtx op1 = XEXP (comp, 1);
1386 XEXP (comp, 0) = op1;
1387 XEXP (comp, 1) = op0;
1389 else
1391 rtx new = gen_rtx (COMPARE, VOIDmode,
1392 CONST0_RTX (GET_MODE (comp)), comp);
1393 if (GET_CODE (body) == SET)
1394 SET_SRC (body) = new;
1395 else
1396 SET_SRC (XVECEXP (body, 0, 0)) = new;
1400 /* Return a memory reference like MEMREF, but with its mode changed
1401 to MODE and its address changed to ADDR.
1402 (VOIDmode means don't change the mode.
1403 NULL for ADDR means don't change the address.) */
1406 change_address (memref, mode, addr)
1407 rtx memref;
1408 enum machine_mode mode;
1409 rtx addr;
1411 rtx new;
1413 if (GET_CODE (memref) != MEM)
1414 abort ();
1415 if (mode == VOIDmode)
1416 mode = GET_MODE (memref);
1417 if (addr == 0)
1418 addr = XEXP (memref, 0);
1420 /* If reload is in progress or has completed, ADDR must be valid.
1421 Otherwise, we can call memory_address to make it valid. */
1422 if (reload_completed || reload_in_progress)
1424 if (! memory_address_p (mode, addr))
1425 abort ();
1427 else
1428 addr = memory_address (mode, addr);
1430 if (rtx_equal_p (addr, XEXP (memref, 0)) && mode == GET_MODE (memref))
1431 return memref;
1433 new = gen_rtx (MEM, mode, addr);
1434 MEM_VOLATILE_P (new) = MEM_VOLATILE_P (memref);
1435 RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (memref);
1436 MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (memref);
1437 return new;
1440 /* Return a newly created CODE_LABEL rtx with a unique label number. */
1443 gen_label_rtx ()
1445 register rtx label;
1447 label = (output_bytecode
1448 ? gen_rtx (CODE_LABEL, VOIDmode, NULL, bc_get_bytecode_label ())
1449 : gen_rtx (CODE_LABEL, VOIDmode, 0, NULL_RTX,
1450 NULL_RTX, label_num++, NULL_PTR));
1452 LABEL_NUSES (label) = 0;
1453 return label;
1456 /* For procedure integration. */
1458 /* Return a newly created INLINE_HEADER rtx. Should allocate this
1459 from a permanent obstack when the opportunity arises. */
1462 gen_inline_header_rtx (first_insn, first_parm_insn, first_labelno,
1463 last_labelno, max_parm_regnum, max_regnum, args_size,
1464 pops_args, stack_slots, forced_labels, function_flags,
1465 outgoing_args_size, original_arg_vector,
1466 original_decl_initial, regno_rtx, regno_flag,
1467 regno_align, parm_reg_stack_loc)
1468 rtx first_insn, first_parm_insn;
1469 int first_labelno, last_labelno, max_parm_regnum, max_regnum, args_size;
1470 int pops_args;
1471 rtx stack_slots;
1472 rtx forced_labels;
1473 int function_flags;
1474 int outgoing_args_size;
1475 rtvec original_arg_vector;
1476 rtx original_decl_initial;
1477 rtvec regno_rtx;
1478 char *regno_flag;
1479 char *regno_align;
1480 rtvec parm_reg_stack_loc;
1482 rtx header = gen_rtx (INLINE_HEADER, VOIDmode,
1483 cur_insn_uid++, NULL_RTX,
1484 first_insn, first_parm_insn,
1485 first_labelno, last_labelno,
1486 max_parm_regnum, max_regnum, args_size, pops_args,
1487 stack_slots, forced_labels, function_flags,
1488 outgoing_args_size, original_arg_vector,
1489 original_decl_initial,
1490 regno_rtx, regno_flag, regno_align,
1491 parm_reg_stack_loc);
1492 return header;
1495 /* Install new pointers to the first and last insns in the chain.
1496 Also, set cur_insn_uid to one higher than the last in use.
1497 Used for an inline-procedure after copying the insn chain. */
1499 void
1500 set_new_first_and_last_insn (first, last)
1501 rtx first, last;
1503 rtx insn;
1505 first_insn = first;
1506 last_insn = last;
1507 cur_insn_uid = 0;
1509 for (insn = first; insn; insn = NEXT_INSN (insn))
1510 cur_insn_uid = MAX (cur_insn_uid, INSN_UID (insn));
1512 cur_insn_uid++;
1515 /* Set the range of label numbers found in the current function.
1516 This is used when belatedly compiling an inline function. */
1518 void
1519 set_new_first_and_last_label_num (first, last)
1520 int first, last;
1522 base_label_num = label_num;
1523 first_label_num = first;
1524 last_label_num = last;
1527 /* Save all variables describing the current status into the structure *P.
1528 This is used before starting a nested function. */
1530 void
1531 save_emit_status (p)
1532 struct function *p;
1534 p->reg_rtx_no = reg_rtx_no;
1535 p->first_label_num = first_label_num;
1536 p->first_insn = first_insn;
1537 p->last_insn = last_insn;
1538 p->sequence_rtl_expr = sequence_rtl_expr;
1539 p->sequence_stack = sequence_stack;
1540 p->cur_insn_uid = cur_insn_uid;
1541 p->last_linenum = last_linenum;
1542 p->last_filename = last_filename;
1543 p->regno_pointer_flag = regno_pointer_flag;
1544 p->regno_pointer_align = regno_pointer_align;
1545 p->regno_pointer_flag_length = regno_pointer_flag_length;
1546 p->regno_reg_rtx = regno_reg_rtx;
1549 /* Restore all variables describing the current status from the structure *P.
1550 This is used after a nested function. */
1552 void
1553 restore_emit_status (p)
1554 struct function *p;
1556 int i;
1558 reg_rtx_no = p->reg_rtx_no;
1559 first_label_num = p->first_label_num;
1560 last_label_num = 0;
1561 first_insn = p->first_insn;
1562 last_insn = p->last_insn;
1563 sequence_rtl_expr = p->sequence_rtl_expr;
1564 sequence_stack = p->sequence_stack;
1565 cur_insn_uid = p->cur_insn_uid;
1566 last_linenum = p->last_linenum;
1567 last_filename = p->last_filename;
1568 regno_pointer_flag = p->regno_pointer_flag;
1569 regno_pointer_align = p->regno_pointer_align;
1570 regno_pointer_flag_length = p->regno_pointer_flag_length;
1571 regno_reg_rtx = p->regno_reg_rtx;
1573 /* Clear our cache of rtx expressions for start_sequence and
1574 gen_sequence. */
1575 sequence_element_free_list = 0;
1576 for (i = 0; i < SEQUENCE_RESULT_SIZE; i++)
1577 sequence_result[i] = 0;
1579 free_insn = 0;
1582 /* Go through all the RTL insn bodies and copy any invalid shared structure.
1583 It does not work to do this twice, because the mark bits set here
1584 are not cleared afterwards. */
1586 void
1587 unshare_all_rtl (insn)
1588 register rtx insn;
1590 for (; insn; insn = NEXT_INSN (insn))
1591 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
1592 || GET_CODE (insn) == CALL_INSN)
1594 PATTERN (insn) = copy_rtx_if_shared (PATTERN (insn));
1595 REG_NOTES (insn) = copy_rtx_if_shared (REG_NOTES (insn));
1596 LOG_LINKS (insn) = copy_rtx_if_shared (LOG_LINKS (insn));
1599 /* Make sure the addresses of stack slots found outside the insn chain
1600 (such as, in DECL_RTL of a variable) are not shared
1601 with the insn chain.
1603 This special care is necessary when the stack slot MEM does not
1604 actually appear in the insn chain. If it does appear, its address
1605 is unshared from all else at that point. */
1607 copy_rtx_if_shared (stack_slot_list);
1610 /* Mark ORIG as in use, and return a copy of it if it was already in use.
1611 Recursively does the same for subexpressions. */
1614 copy_rtx_if_shared (orig)
1615 rtx orig;
1617 register rtx x = orig;
1618 register int i;
1619 register enum rtx_code code;
1620 register char *format_ptr;
1621 int copied = 0;
1623 if (x == 0)
1624 return 0;
1626 code = GET_CODE (x);
1628 /* These types may be freely shared. */
1630 switch (code)
1632 case REG:
1633 case QUEUED:
1634 case CONST_INT:
1635 case CONST_DOUBLE:
1636 case SYMBOL_REF:
1637 case CODE_LABEL:
1638 case PC:
1639 case CC0:
1640 case SCRATCH:
1641 /* SCRATCH must be shared because they represent distinct values. */
1642 return x;
1644 case CONST:
1645 /* CONST can be shared if it contains a SYMBOL_REF. If it contains
1646 a LABEL_REF, it isn't sharable. */
1647 if (GET_CODE (XEXP (x, 0)) == PLUS
1648 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
1649 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
1650 return x;
1651 break;
1653 case INSN:
1654 case JUMP_INSN:
1655 case CALL_INSN:
1656 case NOTE:
1657 case BARRIER:
1658 /* The chain of insns is not being copied. */
1659 return x;
1661 case MEM:
1662 /* A MEM is allowed to be shared if its address is constant
1663 or is a constant plus one of the special registers. */
1664 if (CONSTANT_ADDRESS_P (XEXP (x, 0))
1665 || XEXP (x, 0) == virtual_stack_vars_rtx
1666 || XEXP (x, 0) == virtual_incoming_args_rtx)
1667 return x;
1669 if (GET_CODE (XEXP (x, 0)) == PLUS
1670 && (XEXP (XEXP (x, 0), 0) == virtual_stack_vars_rtx
1671 || XEXP (XEXP (x, 0), 0) == virtual_incoming_args_rtx)
1672 && CONSTANT_ADDRESS_P (XEXP (XEXP (x, 0), 1)))
1674 /* This MEM can appear in more than one place,
1675 but its address better not be shared with anything else. */
1676 if (! x->used)
1677 XEXP (x, 0) = copy_rtx_if_shared (XEXP (x, 0));
1678 x->used = 1;
1679 return x;
1681 break;
1683 default:
1684 break;
1687 /* This rtx may not be shared. If it has already been seen,
1688 replace it with a copy of itself. */
1690 if (x->used)
1692 register rtx copy;
1694 copy = rtx_alloc (code);
1695 bcopy ((char *) x, (char *) copy,
1696 (sizeof (*copy) - sizeof (copy->fld)
1697 + sizeof (copy->fld[0]) * GET_RTX_LENGTH (code)));
1698 x = copy;
1699 copied = 1;
1701 x->used = 1;
1703 /* Now scan the subexpressions recursively.
1704 We can store any replaced subexpressions directly into X
1705 since we know X is not shared! Any vectors in X
1706 must be copied if X was copied. */
1708 format_ptr = GET_RTX_FORMAT (code);
1710 for (i = 0; i < GET_RTX_LENGTH (code); i++)
1712 switch (*format_ptr++)
1714 case 'e':
1715 XEXP (x, i) = copy_rtx_if_shared (XEXP (x, i));
1716 break;
1718 case 'E':
1719 if (XVEC (x, i) != NULL)
1721 register int j;
1722 int len = XVECLEN (x, i);
1724 if (copied && len > 0)
1725 XVEC (x, i) = gen_rtvec_vv (len, XVEC (x, i)->elem);
1726 for (j = 0; j < len; j++)
1727 XVECEXP (x, i, j) = copy_rtx_if_shared (XVECEXP (x, i, j));
1729 break;
1732 return x;
1735 /* Clear all the USED bits in X to allow copy_rtx_if_shared to be used
1736 to look for shared sub-parts. */
1738 void
1739 reset_used_flags (x)
1740 rtx x;
1742 register int i, j;
1743 register enum rtx_code code;
1744 register char *format_ptr;
1746 if (x == 0)
1747 return;
1749 code = GET_CODE (x);
1751 /* These types may be freely shared so we needn't do any resetting
1752 for them. */
1754 switch (code)
1756 case REG:
1757 case QUEUED:
1758 case CONST_INT:
1759 case CONST_DOUBLE:
1760 case SYMBOL_REF:
1761 case CODE_LABEL:
1762 case PC:
1763 case CC0:
1764 return;
1766 case INSN:
1767 case JUMP_INSN:
1768 case CALL_INSN:
1769 case NOTE:
1770 case LABEL_REF:
1771 case BARRIER:
1772 /* The chain of insns is not being copied. */
1773 return;
1775 default:
1776 break;
1779 x->used = 0;
1781 format_ptr = GET_RTX_FORMAT (code);
1782 for (i = 0; i < GET_RTX_LENGTH (code); i++)
1784 switch (*format_ptr++)
1786 case 'e':
1787 reset_used_flags (XEXP (x, i));
1788 break;
1790 case 'E':
1791 for (j = 0; j < XVECLEN (x, i); j++)
1792 reset_used_flags (XVECEXP (x, i, j));
1793 break;
1798 /* Copy X if necessary so that it won't be altered by changes in OTHER.
1799 Return X or the rtx for the pseudo reg the value of X was copied into.
1800 OTHER must be valid as a SET_DEST. */
1803 make_safe_from (x, other)
1804 rtx x, other;
1806 while (1)
1807 switch (GET_CODE (other))
1809 case SUBREG:
1810 other = SUBREG_REG (other);
1811 break;
1812 case STRICT_LOW_PART:
1813 case SIGN_EXTEND:
1814 case ZERO_EXTEND:
1815 other = XEXP (other, 0);
1816 break;
1817 default:
1818 goto done;
1820 done:
1821 if ((GET_CODE (other) == MEM
1822 && ! CONSTANT_P (x)
1823 && GET_CODE (x) != REG
1824 && GET_CODE (x) != SUBREG)
1825 || (GET_CODE (other) == REG
1826 && (REGNO (other) < FIRST_PSEUDO_REGISTER
1827 || reg_mentioned_p (other, x))))
1829 rtx temp = gen_reg_rtx (GET_MODE (x));
1830 emit_move_insn (temp, x);
1831 return temp;
1833 return x;
1836 /* Emission of insns (adding them to the doubly-linked list). */
1838 /* Return the first insn of the current sequence or current function. */
1841 get_insns ()
1843 return first_insn;
1846 /* Return the last insn emitted in current sequence or current function. */
1849 get_last_insn ()
1851 return last_insn;
1854 /* Specify a new insn as the last in the chain. */
1856 void
1857 set_last_insn (insn)
1858 rtx insn;
1860 if (NEXT_INSN (insn) != 0)
1861 abort ();
1862 last_insn = insn;
1865 /* Return the last insn emitted, even if it is in a sequence now pushed. */
1868 get_last_insn_anywhere ()
1870 struct sequence_stack *stack;
1871 if (last_insn)
1872 return last_insn;
1873 for (stack = sequence_stack; stack; stack = stack->next)
1874 if (stack->last != 0)
1875 return stack->last;
1876 return 0;
1879 /* Return a number larger than any instruction's uid in this function. */
1882 get_max_uid ()
1884 return cur_insn_uid;
1887 /* Return the next insn. If it is a SEQUENCE, return the first insn
1888 of the sequence. */
1891 next_insn (insn)
1892 rtx insn;
1894 if (insn)
1896 insn = NEXT_INSN (insn);
1897 if (insn && GET_CODE (insn) == INSN
1898 && GET_CODE (PATTERN (insn)) == SEQUENCE)
1899 insn = XVECEXP (PATTERN (insn), 0, 0);
1902 return insn;
1905 /* Return the previous insn. If it is a SEQUENCE, return the last insn
1906 of the sequence. */
1909 previous_insn (insn)
1910 rtx insn;
1912 if (insn)
1914 insn = PREV_INSN (insn);
1915 if (insn && GET_CODE (insn) == INSN
1916 && GET_CODE (PATTERN (insn)) == SEQUENCE)
1917 insn = XVECEXP (PATTERN (insn), 0, XVECLEN (PATTERN (insn), 0) - 1);
1920 return insn;
1923 /* Return the next insn after INSN that is not a NOTE. This routine does not
1924 look inside SEQUENCEs. */
1927 next_nonnote_insn (insn)
1928 rtx insn;
1930 while (insn)
1932 insn = NEXT_INSN (insn);
1933 if (insn == 0 || GET_CODE (insn) != NOTE)
1934 break;
1937 return insn;
1940 /* Return the previous insn before INSN that is not a NOTE. This routine does
1941 not look inside SEQUENCEs. */
1944 prev_nonnote_insn (insn)
1945 rtx insn;
1947 while (insn)
1949 insn = PREV_INSN (insn);
1950 if (insn == 0 || GET_CODE (insn) != NOTE)
1951 break;
1954 return insn;
1957 /* Return the next INSN, CALL_INSN or JUMP_INSN after INSN;
1958 or 0, if there is none. This routine does not look inside
1959 SEQUENCEs. */
1962 next_real_insn (insn)
1963 rtx insn;
1965 while (insn)
1967 insn = NEXT_INSN (insn);
1968 if (insn == 0 || GET_CODE (insn) == INSN
1969 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN)
1970 break;
1973 return insn;
1976 /* Return the last INSN, CALL_INSN or JUMP_INSN before INSN;
1977 or 0, if there is none. This routine does not look inside
1978 SEQUENCEs. */
1981 prev_real_insn (insn)
1982 rtx insn;
1984 while (insn)
1986 insn = PREV_INSN (insn);
1987 if (insn == 0 || GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
1988 || GET_CODE (insn) == JUMP_INSN)
1989 break;
1992 return insn;
1995 /* Find the next insn after INSN that really does something. This routine
1996 does not look inside SEQUENCEs. Until reload has completed, this is the
1997 same as next_real_insn. */
2000 next_active_insn (insn)
2001 rtx insn;
2003 while (insn)
2005 insn = NEXT_INSN (insn);
2006 if (insn == 0
2007 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN
2008 || (GET_CODE (insn) == INSN
2009 && (! reload_completed
2010 || (GET_CODE (PATTERN (insn)) != USE
2011 && GET_CODE (PATTERN (insn)) != CLOBBER))))
2012 break;
2015 return insn;
2018 /* Find the last insn before INSN that really does something. This routine
2019 does not look inside SEQUENCEs. Until reload has completed, this is the
2020 same as prev_real_insn. */
2023 prev_active_insn (insn)
2024 rtx insn;
2026 while (insn)
2028 insn = PREV_INSN (insn);
2029 if (insn == 0
2030 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN
2031 || (GET_CODE (insn) == INSN
2032 && (! reload_completed
2033 || (GET_CODE (PATTERN (insn)) != USE
2034 && GET_CODE (PATTERN (insn)) != CLOBBER))))
2035 break;
2038 return insn;
2041 /* Return the next CODE_LABEL after the insn INSN, or 0 if there is none. */
2044 next_label (insn)
2045 rtx insn;
2047 while (insn)
2049 insn = NEXT_INSN (insn);
2050 if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
2051 break;
2054 return insn;
2057 /* Return the last CODE_LABEL before the insn INSN, or 0 if there is none. */
2060 prev_label (insn)
2061 rtx insn;
2063 while (insn)
2065 insn = PREV_INSN (insn);
2066 if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
2067 break;
2070 return insn;
2073 #ifdef HAVE_cc0
2074 /* INSN uses CC0 and is being moved into a delay slot. Set up REG_CC_SETTER
2075 and REG_CC_USER notes so we can find it. */
2077 void
2078 link_cc0_insns (insn)
2079 rtx insn;
2081 rtx user = next_nonnote_insn (insn);
2083 if (GET_CODE (user) == INSN && GET_CODE (PATTERN (user)) == SEQUENCE)
2084 user = XVECEXP (PATTERN (user), 0, 0);
2086 REG_NOTES (user) = gen_rtx (INSN_LIST, REG_CC_SETTER, insn,
2087 REG_NOTES (user));
2088 REG_NOTES (insn) = gen_rtx (INSN_LIST, REG_CC_USER, user, REG_NOTES (insn));
2091 /* Return the next insn that uses CC0 after INSN, which is assumed to
2092 set it. This is the inverse of prev_cc0_setter (i.e., prev_cc0_setter
2093 applied to the result of this function should yield INSN).
2095 Normally, this is simply the next insn. However, if a REG_CC_USER note
2096 is present, it contains the insn that uses CC0.
2098 Return 0 if we can't find the insn. */
2101 next_cc0_user (insn)
2102 rtx insn;
2104 rtx note = find_reg_note (insn, REG_CC_USER, NULL_RTX);
2106 if (note)
2107 return XEXP (note, 0);
2109 insn = next_nonnote_insn (insn);
2110 if (insn && GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
2111 insn = XVECEXP (PATTERN (insn), 0, 0);
2113 if (insn && GET_RTX_CLASS (GET_CODE (insn)) == 'i'
2114 && reg_mentioned_p (cc0_rtx, PATTERN (insn)))
2115 return insn;
2117 return 0;
2120 /* Find the insn that set CC0 for INSN. Unless INSN has a REG_CC_SETTER
2121 note, it is the previous insn. */
2124 prev_cc0_setter (insn)
2125 rtx insn;
2127 rtx note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
2128 rtx link;
2130 if (note)
2131 return XEXP (note, 0);
2133 insn = prev_nonnote_insn (insn);
2134 if (! sets_cc0_p (PATTERN (insn)))
2135 abort ();
2137 return insn;
2139 #endif
2141 /* Try splitting insns that can be split for better scheduling.
2142 PAT is the pattern which might split.
2143 TRIAL is the insn providing PAT.
2144 LAST is non-zero if we should return the last insn of the sequence produced.
2146 If this routine succeeds in splitting, it returns the first or last
2147 replacement insn depending on the value of LAST. Otherwise, it
2148 returns TRIAL. If the insn to be returned can be split, it will be. */
2151 try_split (pat, trial, last)
2152 rtx pat, trial;
2153 int last;
2155 rtx before = PREV_INSN (trial);
2156 rtx after = NEXT_INSN (trial);
2157 rtx seq = split_insns (pat, trial);
2158 int has_barrier = 0;
2159 rtx tem;
2161 /* If we are splitting a JUMP_INSN, it might be followed by a BARRIER.
2162 We may need to handle this specially. */
2163 if (after && GET_CODE (after) == BARRIER)
2165 has_barrier = 1;
2166 after = NEXT_INSN (after);
2169 if (seq)
2171 /* SEQ can either be a SEQUENCE or the pattern of a single insn.
2172 The latter case will normally arise only when being done so that
2173 it, in turn, will be split (SFmode on the 29k is an example). */
2174 if (GET_CODE (seq) == SEQUENCE)
2176 /* If we are splitting a JUMP_INSN, look for the JUMP_INSN in
2177 SEQ and copy our JUMP_LABEL to it. If JUMP_LABEL is non-zero,
2178 increment the usage count so we don't delete the label. */
2179 int i;
2181 if (GET_CODE (trial) == JUMP_INSN)
2182 for (i = XVECLEN (seq, 0) - 1; i >= 0; i--)
2183 if (GET_CODE (XVECEXP (seq, 0, i)) == JUMP_INSN)
2185 JUMP_LABEL (XVECEXP (seq, 0, i)) = JUMP_LABEL (trial);
2187 if (JUMP_LABEL (trial))
2188 LABEL_NUSES (JUMP_LABEL (trial))++;
2191 tem = emit_insn_after (seq, before);
2193 delete_insn (trial);
2194 if (has_barrier)
2195 emit_barrier_after (tem);
2197 /* Recursively call try_split for each new insn created; by the
2198 time control returns here that insn will be fully split, so
2199 set LAST and continue from the insn after the one returned.
2200 We can't use next_active_insn here since AFTER may be a note.
2201 Ignore deleted insns, which can be occur if not optimizing. */
2202 for (tem = NEXT_INSN (before); tem != after;
2203 tem = NEXT_INSN (tem))
2204 if (! INSN_DELETED_P (tem))
2205 tem = try_split (PATTERN (tem), tem, 1);
2207 /* Avoid infinite loop if the result matches the original pattern. */
2208 else if (rtx_equal_p (seq, pat))
2209 return trial;
2210 else
2212 PATTERN (trial) = seq;
2213 INSN_CODE (trial) = -1;
2214 try_split (seq, trial, last);
2217 /* Return either the first or the last insn, depending on which was
2218 requested. */
2219 return last ? prev_active_insn (after) : next_active_insn (before);
2222 return trial;
2225 /* Make and return an INSN rtx, initializing all its slots.
2226 Store PATTERN in the pattern slots. */
2229 make_insn_raw (pattern)
2230 rtx pattern;
2232 register rtx insn;
2234 /* If in RTL generation phase, see if FREE_INSN can be used. */
2235 if (free_insn != 0 && rtx_equal_function_value_matters)
2237 insn = free_insn;
2238 free_insn = NEXT_INSN (free_insn);
2239 PUT_CODE (insn, INSN);
2241 else
2242 insn = rtx_alloc (INSN);
2244 INSN_UID (insn) = cur_insn_uid++;
2245 PATTERN (insn) = pattern;
2246 INSN_CODE (insn) = -1;
2247 LOG_LINKS (insn) = NULL;
2248 REG_NOTES (insn) = NULL;
2250 return insn;
2253 /* Like `make_insn' but make a JUMP_INSN instead of an insn. */
2255 static rtx
2256 make_jump_insn_raw (pattern)
2257 rtx pattern;
2259 register rtx insn;
2261 insn = rtx_alloc (JUMP_INSN);
2262 INSN_UID (insn) = cur_insn_uid++;
2264 PATTERN (insn) = pattern;
2265 INSN_CODE (insn) = -1;
2266 LOG_LINKS (insn) = NULL;
2267 REG_NOTES (insn) = NULL;
2268 JUMP_LABEL (insn) = NULL;
2270 return insn;
2273 /* Like `make_insn' but make a CALL_INSN instead of an insn. */
2275 static rtx
2276 make_call_insn_raw (pattern)
2277 rtx pattern;
2279 register rtx insn;
2281 insn = rtx_alloc (CALL_INSN);
2282 INSN_UID (insn) = cur_insn_uid++;
2284 PATTERN (insn) = pattern;
2285 INSN_CODE (insn) = -1;
2286 LOG_LINKS (insn) = NULL;
2287 REG_NOTES (insn) = NULL;
2288 CALL_INSN_FUNCTION_USAGE (insn) = NULL;
2290 return insn;
2293 /* Add INSN to the end of the doubly-linked list.
2294 INSN may be an INSN, JUMP_INSN, CALL_INSN, CODE_LABEL, BARRIER or NOTE. */
2296 void
2297 add_insn (insn)
2298 register rtx insn;
2300 PREV_INSN (insn) = last_insn;
2301 NEXT_INSN (insn) = 0;
2303 if (NULL != last_insn)
2304 NEXT_INSN (last_insn) = insn;
2306 if (NULL == first_insn)
2307 first_insn = insn;
2309 last_insn = insn;
2312 /* Add INSN into the doubly-linked list after insn AFTER. This and
2313 the next should be the only functions called to insert an insn once
2314 delay slots have been filled since only they know how to update a
2315 SEQUENCE. */
2317 void
2318 add_insn_after (insn, after)
2319 rtx insn, after;
2321 rtx next = NEXT_INSN (after);
2323 if (optimize && INSN_DELETED_P (after))
2324 abort ();
2326 NEXT_INSN (insn) = next;
2327 PREV_INSN (insn) = after;
2329 if (next)
2331 PREV_INSN (next) = insn;
2332 if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == SEQUENCE)
2333 PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = insn;
2335 else if (last_insn == after)
2336 last_insn = insn;
2337 else
2339 struct sequence_stack *stack = sequence_stack;
2340 /* Scan all pending sequences too. */
2341 for (; stack; stack = stack->next)
2342 if (after == stack->last)
2344 stack->last = insn;
2345 break;
2348 if (stack == 0)
2349 abort ();
2352 NEXT_INSN (after) = insn;
2353 if (GET_CODE (after) == INSN && GET_CODE (PATTERN (after)) == SEQUENCE)
2355 rtx sequence = PATTERN (after);
2356 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2360 /* Add INSN into the doubly-linked list before insn BEFORE. This and
2361 the previous should be the only functions called to insert an insn once
2362 delay slots have been filled since only they know how to update a
2363 SEQUENCE. */
2365 void
2366 add_insn_before (insn, before)
2367 rtx insn, before;
2369 rtx prev = PREV_INSN (before);
2371 if (optimize && INSN_DELETED_P (before))
2372 abort ();
2374 PREV_INSN (insn) = prev;
2375 NEXT_INSN (insn) = before;
2377 if (prev)
2379 NEXT_INSN (prev) = insn;
2380 if (GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == SEQUENCE)
2382 rtx sequence = PATTERN (prev);
2383 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2386 else if (first_insn == before)
2387 first_insn = insn;
2388 else
2390 struct sequence_stack *stack = sequence_stack;
2391 /* Scan all pending sequences too. */
2392 for (; stack; stack = stack->next)
2393 if (before == stack->first)
2395 stack->first = insn;
2396 break;
2399 if (stack == 0)
2400 abort ();
2403 PREV_INSN (before) = insn;
2404 if (GET_CODE (before) == INSN && GET_CODE (PATTERN (before)) == SEQUENCE)
2405 PREV_INSN (XVECEXP (PATTERN (before), 0, 0)) = insn;
2408 /* Delete all insns made since FROM.
2409 FROM becomes the new last instruction. */
2411 void
2412 delete_insns_since (from)
2413 rtx from;
2415 if (from == 0)
2416 first_insn = 0;
2417 else
2418 NEXT_INSN (from) = 0;
2419 last_insn = from;
2422 /* This function is deprecated, please use sequences instead.
2424 Move a consecutive bunch of insns to a different place in the chain.
2425 The insns to be moved are those between FROM and TO.
2426 They are moved to a new position after the insn AFTER.
2427 AFTER must not be FROM or TO or any insn in between.
2429 This function does not know about SEQUENCEs and hence should not be
2430 called after delay-slot filling has been done. */
2432 void
2433 reorder_insns (from, to, after)
2434 rtx from, to, after;
2436 /* Splice this bunch out of where it is now. */
2437 if (PREV_INSN (from))
2438 NEXT_INSN (PREV_INSN (from)) = NEXT_INSN (to);
2439 if (NEXT_INSN (to))
2440 PREV_INSN (NEXT_INSN (to)) = PREV_INSN (from);
2441 if (last_insn == to)
2442 last_insn = PREV_INSN (from);
2443 if (first_insn == from)
2444 first_insn = NEXT_INSN (to);
2446 /* Make the new neighbors point to it and it to them. */
2447 if (NEXT_INSN (after))
2448 PREV_INSN (NEXT_INSN (after)) = to;
2450 NEXT_INSN (to) = NEXT_INSN (after);
2451 PREV_INSN (from) = after;
2452 NEXT_INSN (after) = from;
2453 if (after == last_insn)
2454 last_insn = to;
2457 /* Return the line note insn preceding INSN. */
2459 static rtx
2460 find_line_note (insn)
2461 rtx insn;
2463 if (no_line_numbers)
2464 return 0;
2466 for (; insn; insn = PREV_INSN (insn))
2467 if (GET_CODE (insn) == NOTE
2468 && NOTE_LINE_NUMBER (insn) >= 0)
2469 break;
2471 return insn;
2474 /* Like reorder_insns, but inserts line notes to preserve the line numbers
2475 of the moved insns when debugging. This may insert a note between AFTER
2476 and FROM, and another one after TO. */
2478 void
2479 reorder_insns_with_line_notes (from, to, after)
2480 rtx from, to, after;
2482 rtx from_line = find_line_note (from);
2483 rtx after_line = find_line_note (after);
2485 reorder_insns (from, to, after);
2487 if (from_line == after_line)
2488 return;
2490 if (from_line)
2491 emit_line_note_after (NOTE_SOURCE_FILE (from_line),
2492 NOTE_LINE_NUMBER (from_line),
2493 after);
2494 if (after_line)
2495 emit_line_note_after (NOTE_SOURCE_FILE (after_line),
2496 NOTE_LINE_NUMBER (after_line),
2497 to);
2500 /* Emit an insn of given code and pattern
2501 at a specified place within the doubly-linked list. */
2503 /* Make an instruction with body PATTERN
2504 and output it before the instruction BEFORE. */
2507 emit_insn_before (pattern, before)
2508 register rtx pattern, before;
2510 register rtx insn = before;
2512 if (GET_CODE (pattern) == SEQUENCE)
2514 register int i;
2516 for (i = 0; i < XVECLEN (pattern, 0); i++)
2518 insn = XVECEXP (pattern, 0, i);
2519 add_insn_before (insn, before);
2521 if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
2522 sequence_result[XVECLEN (pattern, 0)] = pattern;
2524 else
2526 insn = make_insn_raw (pattern);
2527 add_insn_before (insn, before);
2530 return insn;
2533 /* Make an instruction with body PATTERN and code JUMP_INSN
2534 and output it before the instruction BEFORE. */
2537 emit_jump_insn_before (pattern, before)
2538 register rtx pattern, before;
2540 register rtx insn;
2542 if (GET_CODE (pattern) == SEQUENCE)
2543 insn = emit_insn_before (pattern, before);
2544 else
2546 insn = make_jump_insn_raw (pattern);
2547 add_insn_before (insn, before);
2550 return insn;
2553 /* Make an instruction with body PATTERN and code CALL_INSN
2554 and output it before the instruction BEFORE. */
2557 emit_call_insn_before (pattern, before)
2558 register rtx pattern, before;
2560 register rtx insn;
2562 if (GET_CODE (pattern) == SEQUENCE)
2563 insn = emit_insn_before (pattern, before);
2564 else
2566 insn = make_call_insn_raw (pattern);
2567 add_insn_before (insn, before);
2568 PUT_CODE (insn, CALL_INSN);
2571 return insn;
2574 /* Make an insn of code BARRIER
2575 and output it before the insn AFTER. */
2578 emit_barrier_before (before)
2579 register rtx before;
2581 register rtx insn = rtx_alloc (BARRIER);
2583 INSN_UID (insn) = cur_insn_uid++;
2585 add_insn_before (insn, before);
2586 return insn;
2589 /* Emit a note of subtype SUBTYPE before the insn BEFORE. */
2592 emit_note_before (subtype, before)
2593 int subtype;
2594 rtx before;
2596 register rtx note = rtx_alloc (NOTE);
2597 INSN_UID (note) = cur_insn_uid++;
2598 NOTE_SOURCE_FILE (note) = 0;
2599 NOTE_LINE_NUMBER (note) = subtype;
2601 add_insn_before (note, before);
2602 return note;
2605 /* Make an insn of code INSN with body PATTERN
2606 and output it after the insn AFTER. */
2609 emit_insn_after (pattern, after)
2610 register rtx pattern, after;
2612 register rtx insn = after;
2614 if (GET_CODE (pattern) == SEQUENCE)
2616 register int i;
2618 for (i = 0; i < XVECLEN (pattern, 0); i++)
2620 insn = XVECEXP (pattern, 0, i);
2621 add_insn_after (insn, after);
2622 after = insn;
2624 if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
2625 sequence_result[XVECLEN (pattern, 0)] = pattern;
2627 else
2629 insn = make_insn_raw (pattern);
2630 add_insn_after (insn, after);
2633 return insn;
2636 /* Similar to emit_insn_after, except that line notes are to be inserted so
2637 as to act as if this insn were at FROM. */
2639 void
2640 emit_insn_after_with_line_notes (pattern, after, from)
2641 rtx pattern, after, from;
2643 rtx from_line = find_line_note (from);
2644 rtx after_line = find_line_note (after);
2645 rtx insn = emit_insn_after (pattern, after);
2647 if (from_line)
2648 emit_line_note_after (NOTE_SOURCE_FILE (from_line),
2649 NOTE_LINE_NUMBER (from_line),
2650 after);
2652 if (after_line)
2653 emit_line_note_after (NOTE_SOURCE_FILE (after_line),
2654 NOTE_LINE_NUMBER (after_line),
2655 insn);
2658 /* Make an insn of code JUMP_INSN with body PATTERN
2659 and output it after the insn AFTER. */
2662 emit_jump_insn_after (pattern, after)
2663 register rtx pattern, after;
2665 register rtx insn;
2667 if (GET_CODE (pattern) == SEQUENCE)
2668 insn = emit_insn_after (pattern, after);
2669 else
2671 insn = make_jump_insn_raw (pattern);
2672 add_insn_after (insn, after);
2675 return insn;
2678 /* Make an insn of code BARRIER
2679 and output it after the insn AFTER. */
2682 emit_barrier_after (after)
2683 register rtx after;
2685 register rtx insn = rtx_alloc (BARRIER);
2687 INSN_UID (insn) = cur_insn_uid++;
2689 add_insn_after (insn, after);
2690 return insn;
2693 /* Emit the label LABEL after the insn AFTER. */
2696 emit_label_after (label, after)
2697 rtx label, after;
2699 /* This can be called twice for the same label
2700 as a result of the confusion that follows a syntax error!
2701 So make it harmless. */
2702 if (INSN_UID (label) == 0)
2704 INSN_UID (label) = cur_insn_uid++;
2705 add_insn_after (label, after);
2708 return label;
2711 /* Emit a note of subtype SUBTYPE after the insn AFTER. */
2714 emit_note_after (subtype, after)
2715 int subtype;
2716 rtx after;
2718 register rtx note = rtx_alloc (NOTE);
2719 INSN_UID (note) = cur_insn_uid++;
2720 NOTE_SOURCE_FILE (note) = 0;
2721 NOTE_LINE_NUMBER (note) = subtype;
2722 add_insn_after (note, after);
2723 return note;
2726 /* Emit a line note for FILE and LINE after the insn AFTER. */
2729 emit_line_note_after (file, line, after)
2730 char *file;
2731 int line;
2732 rtx after;
2734 register rtx note;
2736 if (no_line_numbers && line > 0)
2738 cur_insn_uid++;
2739 return 0;
2742 note = rtx_alloc (NOTE);
2743 INSN_UID (note) = cur_insn_uid++;
2744 NOTE_SOURCE_FILE (note) = file;
2745 NOTE_LINE_NUMBER (note) = line;
2746 add_insn_after (note, after);
2747 return note;
2750 /* Make an insn of code INSN with pattern PATTERN
2751 and add it to the end of the doubly-linked list.
2752 If PATTERN is a SEQUENCE, take the elements of it
2753 and emit an insn for each element.
2755 Returns the last insn emitted. */
2758 emit_insn (pattern)
2759 rtx pattern;
2761 rtx insn = last_insn;
2763 if (GET_CODE (pattern) == SEQUENCE)
2765 register int i;
2767 for (i = 0; i < XVECLEN (pattern, 0); i++)
2769 insn = XVECEXP (pattern, 0, i);
2770 add_insn (insn);
2772 if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
2773 sequence_result[XVECLEN (pattern, 0)] = pattern;
2775 else
2777 insn = make_insn_raw (pattern);
2778 add_insn (insn);
2781 return insn;
2784 /* Emit the insns in a chain starting with INSN.
2785 Return the last insn emitted. */
2788 emit_insns (insn)
2789 rtx insn;
2791 rtx last = 0;
2793 while (insn)
2795 rtx next = NEXT_INSN (insn);
2796 add_insn (insn);
2797 last = insn;
2798 insn = next;
2801 return last;
2804 /* Emit the insns in a chain starting with INSN and place them in front of
2805 the insn BEFORE. Return the last insn emitted. */
2808 emit_insns_before (insn, before)
2809 rtx insn;
2810 rtx before;
2812 rtx last = 0;
2814 while (insn)
2816 rtx next = NEXT_INSN (insn);
2817 add_insn_before (insn, before);
2818 last = insn;
2819 insn = next;
2822 return last;
2825 /* Emit the insns in a chain starting with FIRST and place them in back of
2826 the insn AFTER. Return the last insn emitted. */
2829 emit_insns_after (first, after)
2830 register rtx first;
2831 register rtx after;
2833 register rtx last;
2834 register rtx after_after;
2836 if (!after)
2837 abort ();
2839 if (!first)
2840 return first;
2842 for (last = first; NEXT_INSN (last); last = NEXT_INSN (last))
2843 continue;
2845 after_after = NEXT_INSN (after);
2847 NEXT_INSN (after) = first;
2848 PREV_INSN (first) = after;
2849 NEXT_INSN (last) = after_after;
2850 if (after_after)
2851 PREV_INSN (after_after) = last;
2853 if (after == last_insn)
2854 last_insn = last;
2855 return last;
2858 /* Make an insn of code JUMP_INSN with pattern PATTERN
2859 and add it to the end of the doubly-linked list. */
2862 emit_jump_insn (pattern)
2863 rtx pattern;
2865 if (GET_CODE (pattern) == SEQUENCE)
2866 return emit_insn (pattern);
2867 else
2869 register rtx insn = make_jump_insn_raw (pattern);
2870 add_insn (insn);
2871 return insn;
2875 /* Make an insn of code CALL_INSN with pattern PATTERN
2876 and add it to the end of the doubly-linked list. */
2879 emit_call_insn (pattern)
2880 rtx pattern;
2882 if (GET_CODE (pattern) == SEQUENCE)
2883 return emit_insn (pattern);
2884 else
2886 register rtx insn = make_call_insn_raw (pattern);
2887 add_insn (insn);
2888 PUT_CODE (insn, CALL_INSN);
2889 return insn;
2893 /* Add the label LABEL to the end of the doubly-linked list. */
2896 emit_label (label)
2897 rtx label;
2899 /* This can be called twice for the same label
2900 as a result of the confusion that follows a syntax error!
2901 So make it harmless. */
2902 if (INSN_UID (label) == 0)
2904 INSN_UID (label) = cur_insn_uid++;
2905 add_insn (label);
2907 return label;
2910 /* Make an insn of code BARRIER
2911 and add it to the end of the doubly-linked list. */
2914 emit_barrier ()
2916 register rtx barrier = rtx_alloc (BARRIER);
2917 INSN_UID (barrier) = cur_insn_uid++;
2918 add_insn (barrier);
2919 return barrier;
2922 /* Make an insn of code NOTE
2923 with data-fields specified by FILE and LINE
2924 and add it to the end of the doubly-linked list,
2925 but only if line-numbers are desired for debugging info. */
2928 emit_line_note (file, line)
2929 char *file;
2930 int line;
2932 if (output_bytecode)
2934 /* FIXME: for now we do nothing, but eventually we will have to deal with
2935 debugging information. */
2936 return 0;
2939 emit_filename = file;
2940 emit_lineno = line;
2942 #if 0
2943 if (no_line_numbers)
2944 return 0;
2945 #endif
2947 return emit_note (file, line);
2950 /* Make an insn of code NOTE
2951 with data-fields specified by FILE and LINE
2952 and add it to the end of the doubly-linked list.
2953 If it is a line-number NOTE, omit it if it matches the previous one. */
2956 emit_note (file, line)
2957 char *file;
2958 int line;
2960 register rtx note;
2962 if (line > 0)
2964 if (file && last_filename && !strcmp (file, last_filename)
2965 && line == last_linenum)
2966 return 0;
2967 last_filename = file;
2968 last_linenum = line;
2971 if (no_line_numbers && line > 0)
2973 cur_insn_uid++;
2974 return 0;
2977 note = rtx_alloc (NOTE);
2978 INSN_UID (note) = cur_insn_uid++;
2979 NOTE_SOURCE_FILE (note) = file;
2980 NOTE_LINE_NUMBER (note) = line;
2981 add_insn (note);
2982 return note;
2985 /* Emit a NOTE, and don't omit it even if LINE it the previous note. */
2988 emit_line_note_force (file, line)
2989 char *file;
2990 int line;
2992 last_linenum = -1;
2993 return emit_line_note (file, line);
2996 /* Cause next statement to emit a line note even if the line number
2997 has not changed. This is used at the beginning of a function. */
2999 void
3000 force_next_line_note ()
3002 last_linenum = -1;
3005 /* Return an indication of which type of insn should have X as a body.
3006 The value is CODE_LABEL, INSN, CALL_INSN or JUMP_INSN. */
3008 enum rtx_code
3009 classify_insn (x)
3010 rtx x;
3012 if (GET_CODE (x) == CODE_LABEL)
3013 return CODE_LABEL;
3014 if (GET_CODE (x) == CALL)
3015 return CALL_INSN;
3016 if (GET_CODE (x) == RETURN)
3017 return JUMP_INSN;
3018 if (GET_CODE (x) == SET)
3020 if (SET_DEST (x) == pc_rtx)
3021 return JUMP_INSN;
3022 else if (GET_CODE (SET_SRC (x)) == CALL)
3023 return CALL_INSN;
3024 else
3025 return INSN;
3027 if (GET_CODE (x) == PARALLEL)
3029 register int j;
3030 for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
3031 if (GET_CODE (XVECEXP (x, 0, j)) == CALL)
3032 return CALL_INSN;
3033 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
3034 && SET_DEST (XVECEXP (x, 0, j)) == pc_rtx)
3035 return JUMP_INSN;
3036 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
3037 && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == CALL)
3038 return CALL_INSN;
3040 return INSN;
3043 /* Emit the rtl pattern X as an appropriate kind of insn.
3044 If X is a label, it is simply added into the insn chain. */
3047 emit (x)
3048 rtx x;
3050 enum rtx_code code = classify_insn (x);
3052 if (code == CODE_LABEL)
3053 return emit_label (x);
3054 else if (code == INSN)
3055 return emit_insn (x);
3056 else if (code == JUMP_INSN)
3058 register rtx insn = emit_jump_insn (x);
3059 if (simplejump_p (insn) || GET_CODE (x) == RETURN)
3060 return emit_barrier ();
3061 return insn;
3063 else if (code == CALL_INSN)
3064 return emit_call_insn (x);
3065 else
3066 abort ();
3069 /* Begin emitting insns to a sequence which can be packaged in an RTL_EXPR. */
3071 void
3072 start_sequence ()
3074 struct sequence_stack *tem;
3076 if (sequence_element_free_list)
3078 /* Reuse a previously-saved struct sequence_stack. */
3079 tem = sequence_element_free_list;
3080 sequence_element_free_list = tem->next;
3082 else
3083 tem = (struct sequence_stack *) permalloc (sizeof (struct sequence_stack));
3085 tem->next = sequence_stack;
3086 tem->first = first_insn;
3087 tem->last = last_insn;
3088 tem->sequence_rtl_expr = sequence_rtl_expr;
3090 sequence_stack = tem;
3092 first_insn = 0;
3093 last_insn = 0;
3096 /* Similarly, but indicate that this sequence will be placed in
3097 T, an RTL_EXPR. */
3099 void
3100 start_sequence_for_rtl_expr (t)
3101 tree t;
3103 start_sequence ();
3105 sequence_rtl_expr = t;
3108 /* Set up the insn chain starting with FIRST
3109 as the current sequence, saving the previously current one. */
3111 void
3112 push_to_sequence (first)
3113 rtx first;
3115 rtx last;
3117 start_sequence ();
3119 for (last = first; last && NEXT_INSN (last); last = NEXT_INSN (last));
3121 first_insn = first;
3122 last_insn = last;
3125 /* Set up the outer-level insn chain
3126 as the current sequence, saving the previously current one. */
3128 void
3129 push_topmost_sequence ()
3131 struct sequence_stack *stack, *top;
3133 start_sequence ();
3135 for (stack = sequence_stack; stack; stack = stack->next)
3136 top = stack;
3138 first_insn = top->first;
3139 last_insn = top->last;
3140 sequence_rtl_expr = top->sequence_rtl_expr;
3143 /* After emitting to the outer-level insn chain, update the outer-level
3144 insn chain, and restore the previous saved state. */
3146 void
3147 pop_topmost_sequence ()
3149 struct sequence_stack *stack, *top;
3151 for (stack = sequence_stack; stack; stack = stack->next)
3152 top = stack;
3154 top->first = first_insn;
3155 top->last = last_insn;
3156 /* ??? Why don't we save sequence_rtl_expr here? */
3158 end_sequence ();
3161 /* After emitting to a sequence, restore previous saved state.
3163 To get the contents of the sequence just made,
3164 you must call `gen_sequence' *before* calling here. */
3166 void
3167 end_sequence ()
3169 struct sequence_stack *tem = sequence_stack;
3171 first_insn = tem->first;
3172 last_insn = tem->last;
3173 sequence_rtl_expr = tem->sequence_rtl_expr;
3174 sequence_stack = tem->next;
3176 tem->next = sequence_element_free_list;
3177 sequence_element_free_list = tem;
3180 /* Return 1 if currently emitting into a sequence. */
3183 in_sequence_p ()
3185 return sequence_stack != 0;
3188 /* Generate a SEQUENCE rtx containing the insns already emitted
3189 to the current sequence.
3191 This is how the gen_... function from a DEFINE_EXPAND
3192 constructs the SEQUENCE that it returns. */
3195 gen_sequence ()
3197 rtx result;
3198 rtx tem;
3199 int i;
3200 int len;
3202 /* Count the insns in the chain. */
3203 len = 0;
3204 for (tem = first_insn; tem; tem = NEXT_INSN (tem))
3205 len++;
3207 /* If only one insn, return its pattern rather than a SEQUENCE.
3208 (Now that we cache SEQUENCE expressions, it isn't worth special-casing
3209 the case of an empty list.) */
3210 if (len == 1
3211 && ! RTX_FRAME_RELATED_P (first_insn)
3212 && (GET_CODE (first_insn) == INSN
3213 || GET_CODE (first_insn) == JUMP_INSN
3214 /* Don't discard the call usage field. */
3215 || (GET_CODE (first_insn) == CALL_INSN
3216 && CALL_INSN_FUNCTION_USAGE (first_insn) == NULL_RTX)))
3218 NEXT_INSN (first_insn) = free_insn;
3219 free_insn = first_insn;
3220 return PATTERN (first_insn);
3223 /* Put them in a vector. See if we already have a SEQUENCE of the
3224 appropriate length around. */
3225 if (len < SEQUENCE_RESULT_SIZE && (result = sequence_result[len]) != 0)
3226 sequence_result[len] = 0;
3227 else
3229 /* Ensure that this rtl goes in saveable_obstack, since we may
3230 cache it. */
3231 push_obstacks_nochange ();
3232 rtl_in_saveable_obstack ();
3233 result = gen_rtx (SEQUENCE, VOIDmode, rtvec_alloc (len));
3234 pop_obstacks ();
3237 for (i = 0, tem = first_insn; tem; tem = NEXT_INSN (tem), i++)
3238 XVECEXP (result, 0, i) = tem;
3240 return result;
3243 /* Initialize data structures and variables in this file
3244 before generating rtl for each function. */
3246 void
3247 init_emit ()
3249 int i;
3251 first_insn = NULL;
3252 last_insn = NULL;
3253 sequence_rtl_expr = NULL;
3254 cur_insn_uid = 1;
3255 reg_rtx_no = LAST_VIRTUAL_REGISTER + 1;
3256 last_linenum = 0;
3257 last_filename = 0;
3258 first_label_num = label_num;
3259 last_label_num = 0;
3260 sequence_stack = NULL;
3262 /* Clear the start_sequence/gen_sequence cache. */
3263 sequence_element_free_list = 0;
3264 for (i = 0; i < SEQUENCE_RESULT_SIZE; i++)
3265 sequence_result[i] = 0;
3266 free_insn = 0;
3268 /* Init the tables that describe all the pseudo regs. */
3270 regno_pointer_flag_length = LAST_VIRTUAL_REGISTER + 101;
3272 regno_pointer_flag
3273 = (char *) savealloc (regno_pointer_flag_length);
3274 bzero (regno_pointer_flag, regno_pointer_flag_length);
3276 regno_pointer_align
3277 = (char *) savealloc (regno_pointer_flag_length);
3278 bzero (regno_pointer_align, regno_pointer_flag_length);
3280 regno_reg_rtx
3281 = (rtx *) savealloc (regno_pointer_flag_length * sizeof (rtx));
3282 bzero ((char *) regno_reg_rtx, regno_pointer_flag_length * sizeof (rtx));
3284 /* Put copies of all the virtual register rtx into regno_reg_rtx. */
3285 regno_reg_rtx[VIRTUAL_INCOMING_ARGS_REGNUM] = virtual_incoming_args_rtx;
3286 regno_reg_rtx[VIRTUAL_STACK_VARS_REGNUM] = virtual_stack_vars_rtx;
3287 regno_reg_rtx[VIRTUAL_STACK_DYNAMIC_REGNUM] = virtual_stack_dynamic_rtx;
3288 regno_reg_rtx[VIRTUAL_OUTGOING_ARGS_REGNUM] = virtual_outgoing_args_rtx;
3290 /* Indicate that the virtual registers and stack locations are
3291 all pointers. */
3292 REGNO_POINTER_FLAG (STACK_POINTER_REGNUM) = 1;
3293 REGNO_POINTER_FLAG (FRAME_POINTER_REGNUM) = 1;
3294 REGNO_POINTER_FLAG (HARD_FRAME_POINTER_REGNUM) = 1;
3295 REGNO_POINTER_FLAG (ARG_POINTER_REGNUM) = 1;
3297 REGNO_POINTER_FLAG (VIRTUAL_INCOMING_ARGS_REGNUM) = 1;
3298 REGNO_POINTER_FLAG (VIRTUAL_STACK_VARS_REGNUM) = 1;
3299 REGNO_POINTER_FLAG (VIRTUAL_STACK_DYNAMIC_REGNUM) = 1;
3300 REGNO_POINTER_FLAG (VIRTUAL_OUTGOING_ARGS_REGNUM) = 1;
3302 #ifdef STACK_BOUNDARY
3303 REGNO_POINTER_ALIGN (STACK_POINTER_REGNUM) = STACK_BOUNDARY / BITS_PER_UNIT;
3304 REGNO_POINTER_ALIGN (FRAME_POINTER_REGNUM) = STACK_BOUNDARY / BITS_PER_UNIT;
3305 REGNO_POINTER_ALIGN (HARD_FRAME_POINTER_REGNUM)
3306 = STACK_BOUNDARY / BITS_PER_UNIT;
3307 REGNO_POINTER_ALIGN (ARG_POINTER_REGNUM) = STACK_BOUNDARY / BITS_PER_UNIT;
3309 REGNO_POINTER_ALIGN (VIRTUAL_INCOMING_ARGS_REGNUM)
3310 = STACK_BOUNDARY / BITS_PER_UNIT;
3311 REGNO_POINTER_ALIGN (VIRTUAL_STACK_VARS_REGNUM)
3312 = STACK_BOUNDARY / BITS_PER_UNIT;
3313 REGNO_POINTER_ALIGN (VIRTUAL_STACK_DYNAMIC_REGNUM)
3314 = STACK_BOUNDARY / BITS_PER_UNIT;
3315 REGNO_POINTER_ALIGN (VIRTUAL_OUTGOING_ARGS_REGNUM)
3316 = STACK_BOUNDARY / BITS_PER_UNIT;
3317 #endif
3319 #ifdef INIT_EXPANDERS
3320 INIT_EXPANDERS;
3321 #endif
3324 /* Create some permanent unique rtl objects shared between all functions.
3325 LINE_NUMBERS is nonzero if line numbers are to be generated. */
3327 void
3328 init_emit_once (line_numbers)
3329 int line_numbers;
3331 int i;
3332 enum machine_mode mode;
3334 no_line_numbers = ! line_numbers;
3336 sequence_stack = NULL;
3338 /* Compute the word and byte modes. */
3340 byte_mode = VOIDmode;
3341 word_mode = VOIDmode;
3343 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
3344 mode = GET_MODE_WIDER_MODE (mode))
3346 if (GET_MODE_BITSIZE (mode) == BITS_PER_UNIT
3347 && byte_mode == VOIDmode)
3348 byte_mode = mode;
3350 if (GET_MODE_BITSIZE (mode) == BITS_PER_WORD
3351 && word_mode == VOIDmode)
3352 word_mode = mode;
3355 ptr_mode = mode_for_size (POINTER_SIZE, GET_MODE_CLASS (Pmode), 0);
3357 /* Create the unique rtx's for certain rtx codes and operand values. */
3359 pc_rtx = gen_rtx (PC, VOIDmode);
3360 cc0_rtx = gen_rtx (CC0, VOIDmode);
3362 /* Don't use gen_rtx here since gen_rtx in this case
3363 tries to use these variables. */
3364 for (i = - MAX_SAVED_CONST_INT; i <= MAX_SAVED_CONST_INT; i++)
3366 const_int_rtx[i + MAX_SAVED_CONST_INT] = rtx_alloc (CONST_INT);
3367 PUT_MODE (const_int_rtx[i + MAX_SAVED_CONST_INT], VOIDmode);
3368 INTVAL (const_int_rtx[i + MAX_SAVED_CONST_INT]) = i;
3371 /* These four calls obtain some of the rtx expressions made above. */
3372 const0_rtx = GEN_INT (0);
3373 const1_rtx = GEN_INT (1);
3374 const2_rtx = GEN_INT (2);
3375 constm1_rtx = GEN_INT (-1);
3377 /* This will usually be one of the above constants, but may be a new rtx. */
3378 const_true_rtx = GEN_INT (STORE_FLAG_VALUE);
3380 dconst0 = REAL_VALUE_ATOF ("0", DFmode);
3381 dconst1 = REAL_VALUE_ATOF ("1", DFmode);
3382 dconst2 = REAL_VALUE_ATOF ("2", DFmode);
3383 dconstm1 = REAL_VALUE_ATOF ("-1", DFmode);
3385 for (i = 0; i <= 2; i++)
3387 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
3388 mode = GET_MODE_WIDER_MODE (mode))
3390 rtx tem = rtx_alloc (CONST_DOUBLE);
3391 union real_extract u;
3393 bzero ((char *) &u, sizeof u); /* Zero any holes in a structure. */
3394 u.d = i == 0 ? dconst0 : i == 1 ? dconst1 : dconst2;
3396 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (tem), sizeof u);
3397 CONST_DOUBLE_MEM (tem) = cc0_rtx;
3398 PUT_MODE (tem, mode);
3400 const_tiny_rtx[i][(int) mode] = tem;
3403 const_tiny_rtx[i][(int) VOIDmode] = GEN_INT (i);
3405 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
3406 mode = GET_MODE_WIDER_MODE (mode))
3407 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
3409 for (mode = GET_CLASS_NARROWEST_MODE (MODE_PARTIAL_INT);
3410 mode != VOIDmode;
3411 mode = GET_MODE_WIDER_MODE (mode))
3412 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
3415 for (mode = GET_CLASS_NARROWEST_MODE (MODE_CC); mode != VOIDmode;
3416 mode = GET_MODE_WIDER_MODE (mode))
3417 const_tiny_rtx[0][(int) mode] = const0_rtx;
3419 stack_pointer_rtx = gen_rtx (REG, Pmode, STACK_POINTER_REGNUM);
3420 frame_pointer_rtx = gen_rtx (REG, Pmode, FRAME_POINTER_REGNUM);
3422 if (HARD_FRAME_POINTER_REGNUM == FRAME_POINTER_REGNUM)
3423 hard_frame_pointer_rtx = frame_pointer_rtx;
3424 else
3425 hard_frame_pointer_rtx = gen_rtx (REG, Pmode, HARD_FRAME_POINTER_REGNUM);
3427 if (FRAME_POINTER_REGNUM == ARG_POINTER_REGNUM)
3428 arg_pointer_rtx = frame_pointer_rtx;
3429 else if (HARD_FRAME_POINTER_REGNUM == ARG_POINTER_REGNUM)
3430 arg_pointer_rtx = hard_frame_pointer_rtx;
3431 else if (STACK_POINTER_REGNUM == ARG_POINTER_REGNUM)
3432 arg_pointer_rtx = stack_pointer_rtx;
3433 else
3434 arg_pointer_rtx = gen_rtx (REG, Pmode, ARG_POINTER_REGNUM);
3436 #ifdef RETURN_ADDRESS_POINTER_REGNUM
3437 return_address_pointer_rtx = gen_rtx (REG, Pmode,
3438 RETURN_ADDRESS_POINTER_REGNUM);
3439 #endif
3441 /* Create the virtual registers. Do so here since the following objects
3442 might reference them. */
3444 virtual_incoming_args_rtx = gen_rtx (REG, Pmode,
3445 VIRTUAL_INCOMING_ARGS_REGNUM);
3446 virtual_stack_vars_rtx = gen_rtx (REG, Pmode,
3447 VIRTUAL_STACK_VARS_REGNUM);
3448 virtual_stack_dynamic_rtx = gen_rtx (REG, Pmode,
3449 VIRTUAL_STACK_DYNAMIC_REGNUM);
3450 virtual_outgoing_args_rtx = gen_rtx (REG, Pmode,
3451 VIRTUAL_OUTGOING_ARGS_REGNUM);
3453 #ifdef STRUCT_VALUE
3454 struct_value_rtx = STRUCT_VALUE;
3455 #else
3456 struct_value_rtx = gen_rtx (REG, Pmode, STRUCT_VALUE_REGNUM);
3457 #endif
3459 #ifdef STRUCT_VALUE_INCOMING
3460 struct_value_incoming_rtx = STRUCT_VALUE_INCOMING;
3461 #else
3462 #ifdef STRUCT_VALUE_INCOMING_REGNUM
3463 struct_value_incoming_rtx
3464 = gen_rtx (REG, Pmode, STRUCT_VALUE_INCOMING_REGNUM);
3465 #else
3466 struct_value_incoming_rtx = struct_value_rtx;
3467 #endif
3468 #endif
3470 #ifdef STATIC_CHAIN_REGNUM
3471 static_chain_rtx = gen_rtx (REG, Pmode, STATIC_CHAIN_REGNUM);
3473 #ifdef STATIC_CHAIN_INCOMING_REGNUM
3474 if (STATIC_CHAIN_INCOMING_REGNUM != STATIC_CHAIN_REGNUM)
3475 static_chain_incoming_rtx = gen_rtx (REG, Pmode, STATIC_CHAIN_INCOMING_REGNUM);
3476 else
3477 #endif
3478 static_chain_incoming_rtx = static_chain_rtx;
3479 #endif
3481 #ifdef STATIC_CHAIN
3482 static_chain_rtx = STATIC_CHAIN;
3484 #ifdef STATIC_CHAIN_INCOMING
3485 static_chain_incoming_rtx = STATIC_CHAIN_INCOMING;
3486 #else
3487 static_chain_incoming_rtx = static_chain_rtx;
3488 #endif
3489 #endif
3491 #ifdef PIC_OFFSET_TABLE_REGNUM
3492 pic_offset_table_rtx = gen_rtx (REG, Pmode, PIC_OFFSET_TABLE_REGNUM);
3493 #endif