]> gcc.gnu.org Git - gcc.git/blame - gcc/emit-rtl.c
Merge from gcc-2.8
[gcc.git] / gcc / emit-rtl.c
CommitLineData
23b2ce53 1/* Emit RTL for the GNU C-Compiler expander.
a3a03040 2 Copyright (C) 1987, 88, 92-96, 1997 Free Software Foundation, Inc.
23b2ce53
RS
3
4This file is part of GNU CC.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU CC; see the file COPYING. If not, write to
940d9d63
RK
18the Free Software Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
23b2ce53
RS
20
21
22/* Middle-to-low level generation of rtx code and insns.
23
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.
27
28 It also has the functions for creating insns and linking
29 them in the doubly-linked chain.
30
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. */
36
37#include "config.h"
e9a25f70 38#include <stdio.h>
4f90e4a0 39#ifdef __STDC__
04fe4385 40#include <stdarg.h>
4f90e4a0 41#else
04fe4385 42#include <varargs.h>
4f90e4a0 43#endif
23b2ce53 44#include "rtl.h"
a25c7971 45#include "tree.h"
23b2ce53 46#include "flags.h"
1ef08c63 47#include "except.h"
23b2ce53
RS
48#include "function.h"
49#include "expr.h"
50#include "regs.h"
51#include "insn-config.h"
e9a25f70 52#include "recog.h"
23b2ce53 53#include "real.h"
ca695ac9
JB
54#include "obstack.h"
55
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"
62
ca695ac9
JB
63/* Opcode names */
64#ifdef BCDEBUG_PRINT_CODE
65char *opcode_name[] =
66{
67#include "bc-opname.h"
68
69"***END***"
70};
71#endif
72
73
1d445e9e
ILT
74/* Commonly used modes. */
75
0f41302f
MS
76enum machine_mode byte_mode; /* Mode whose width is BITS_PER_UNIT. */
77enum machine_mode word_mode; /* Mode whose width is BITS_PER_WORD. */
78enum machine_mode ptr_mode; /* Mode whose width is POINTER_SIZE. */
1d445e9e 79
23b2ce53
RS
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. */
82
83int reg_rtx_no = LAST_VIRTUAL_REGISTER + 1;
84
85/* This is *not* reset after each function. It gives each CODE_LABEL
86 in the entire compilation a unique label number. */
87
88static int label_num = 1;
89
90/* Lowest label number in current function. */
91
92static int first_label_num;
93
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. */
97
98static int last_label_num;
99
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. */
102
103static int base_label_num;
104
105/* Nonzero means do not generate NOTEs for source line numbers. */
106
107static int no_line_numbers;
108
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. */
113
114rtx pc_rtx; /* (PC) */
115rtx cc0_rtx; /* (CC0) */
116rtx cc1_rtx; /* (CC1) (not actually used nowadays) */
117rtx const0_rtx; /* (CONST_INT 0) */
118rtx const1_rtx; /* (CONST_INT 1) */
119rtx const2_rtx; /* (CONST_INT 2) */
120rtx constm1_rtx; /* (CONST_INT -1) */
121rtx const_true_rtx; /* (CONST_INT STORE_FLAG_VALUE) */
122
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. */
126
127rtx const_tiny_rtx[3][(int) MAX_MACHINE_MODE];
128
129REAL_VALUE_TYPE dconst0;
130REAL_VALUE_TYPE dconst1;
131REAL_VALUE_TYPE dconst2;
132REAL_VALUE_TYPE dconstm1;
133
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.
137
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.
142
ac6f08b0
DE
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.
149
23b2ce53
RS
150 In an inline procedure, the stack and frame pointer rtxs may not be
151 used for anything else. */
152rtx stack_pointer_rtx; /* (REG:Pmode STACK_POINTER_REGNUM) */
153rtx frame_pointer_rtx; /* (REG:Pmode FRAME_POINTER_REGNUM) */
ac6f08b0 154rtx hard_frame_pointer_rtx; /* (REG:Pmode HARD_FRAME_POINTER_REGNUM) */
23b2ce53
RS
155rtx arg_pointer_rtx; /* (REG:Pmode ARG_POINTER_REGNUM) */
156rtx struct_value_rtx; /* (REG:Pmode STRUCT_VALUE_REGNUM) */
157rtx struct_value_incoming_rtx; /* (REG:Pmode STRUCT_VALUE_INCOMING_REGNUM) */
158rtx static_chain_rtx; /* (REG:Pmode STATIC_CHAIN_REGNUM) */
159rtx static_chain_incoming_rtx; /* (REG:Pmode STATIC_CHAIN_INCOMING_REGNUM) */
160rtx pic_offset_table_rtx; /* (REG:Pmode PIC_OFFSET_TABLE_REGNUM) */
161
a4417a86
JW
162/* This is used to implement __builtin_return_address for some machines.
163 See for instance the MIPS port. */
164rtx return_address_pointer_rtx; /* (REG:Pmode RETURN_ADDRESS_POINTER_REGNUM) */
165
23b2ce53
RS
166rtx virtual_incoming_args_rtx; /* (REG:Pmode VIRTUAL_INCOMING_ARGS_REGNUM) */
167rtx virtual_stack_vars_rtx; /* (REG:Pmode VIRTUAL_STACK_VARS_REGNUM) */
168rtx virtual_stack_dynamic_rtx; /* (REG:Pmode VIRTUAL_STACK_DYNAMIC_REGNUM) */
169rtx virtual_outgoing_args_rtx; /* (REG:Pmode VIRTUAL_OUTGOING_ARGS_REGNUM) */
170
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. */
175
176#define MAX_SAVED_CONST_INT 64
177
178static rtx const_int_rtx[MAX_SAVED_CONST_INT * 2 + 1];
179
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.
182
a25c7971
RK
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. */
23b2ce53
RS
185
186static rtx first_insn = NULL;
187static rtx last_insn = NULL;
188
a25c7971
RK
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. */
192
193tree sequence_rtl_expr = NULL;
194
23b2ce53
RS
195/* INSN_UID for next insn emitted.
196 Reset to 1 for each function compiled. */
197
198static int cur_insn_uid = 1;
199
200/* Line number and source file of the last line-number NOTE emitted.
201 This is used to avoid generating duplicates. */
202
203static int last_linenum = 0;
204static char *last_filename = 0;
205
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. */
211
212char *regno_pointer_flag;
213int regno_pointer_flag_length;
214
86fe05e0
RK
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. */
218char *regno_pointer_align;
219
23b2ce53
RS
220/* Indexed by pseudo register number, gives the rtx for that pseudo.
221 Allocated in parallel with regno_pointer_flag. */
222
223rtx *regno_reg_rtx;
224
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. */
229
230struct sequence_stack *sequence_stack;
231
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:
234
235 First, we keep a list of the expressions used to represent the sequence
236 stack in sequence_element_free_list.
237
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.
243
244 We do not bother to save this cached data over nested function calls.
245 Instead, we just reinitialize them. */
246
247#define SEQUENCE_RESULT_SIZE 5
248
249static struct sequence_stack *sequence_element_free_list;
250static rtx sequence_result[SEQUENCE_RESULT_SIZE];
251
0f41302f 252/* During RTL generation, we also keep a list of free INSN rtl codes. */
43127294
RK
253static rtx free_insn;
254
23b2ce53
RS
255extern int rtx_equal_function_value_matters;
256
257/* Filename and line number of last line-number note,
258 whether we actually emitted it or not. */
259extern char *emit_filename;
260extern int emit_lineno;
956d6950
JL
261
262static rtx make_jump_insn_raw PROTO((rtx));
263static rtx make_call_insn_raw PROTO((rtx));
264static rtx find_line_node PROTO((rtx));
ca695ac9 265\f
23b2ce53
RS
266/* rtx gen_rtx (code, mode, [element1, ..., elementn])
267**
268** This routine generates an RTX of the size specified by
269** <code>, which is an RTX code. The RTX structure is initialized
270** from the arguments <element1> through <elementn>, which are
271** interpreted according to the specific RTX type's format. The
272** special machine mode associated with the rtx (if any) is specified
273** in <mode>.
274**
1632afca 275** gen_rtx can be invoked in a way which resembles the lisp-like
23b2ce53
RS
276** rtx it will generate. For example, the following rtx structure:
277**
278** (plus:QI (mem:QI (reg:SI 1))
279** (mem:QI (plusw:SI (reg:SI 2) (reg:SI 3))))
280**
281** ...would be generated by the following C code:
282**
283** gen_rtx (PLUS, QImode,
284** gen_rtx (MEM, QImode,
285** gen_rtx (REG, SImode, 1)),
286** gen_rtx (MEM, QImode,
287** gen_rtx (PLUS, SImode,
288** gen_rtx (REG, SImode, 2),
289** gen_rtx (REG, SImode, 3)))),
290*/
291
292/*VARARGS2*/
293rtx
4f90e4a0 294gen_rtx VPROTO((enum rtx_code code, enum machine_mode mode, ...))
23b2ce53 295{
4f90e4a0 296#ifndef __STDC__
23b2ce53
RS
297 enum rtx_code code;
298 enum machine_mode mode;
4f90e4a0
RK
299#endif
300 va_list p;
23b2ce53
RS
301 register int i; /* Array indices... */
302 register char *fmt; /* Current rtx's format... */
303 register rtx rt_val; /* RTX to return to caller... */
304
4f90e4a0
RK
305 VA_START (p, mode);
306
307#ifndef __STDC__
23b2ce53
RS
308 code = va_arg (p, enum rtx_code);
309 mode = va_arg (p, enum machine_mode);
4f90e4a0 310#endif
23b2ce53
RS
311
312 if (code == CONST_INT)
313 {
906c4e36 314 HOST_WIDE_INT arg = va_arg (p, HOST_WIDE_INT);
23b2ce53
RS
315
316 if (arg >= - MAX_SAVED_CONST_INT && arg <= MAX_SAVED_CONST_INT)
317 return const_int_rtx[arg + MAX_SAVED_CONST_INT];
318
319 if (const_true_rtx && arg == STORE_FLAG_VALUE)
320 return const_true_rtx;
321
322 rt_val = rtx_alloc (code);
323 INTVAL (rt_val) = arg;
324 }
325 else if (code == REG)
326 {
327 int regno = va_arg (p, int);
328
329 /* In case the MD file explicitly references the frame pointer, have
330 all such references point to the same frame pointer. This is used
331 during frame pointer elimination to distinguish the explicit
332 references to these registers from pseudos that happened to be
333 assigned to them.
334
335 If we have eliminated the frame pointer or arg pointer, we will
336 be using it as a normal register, for example as a spill register.
337 In such cases, we might be accessing it in a mode that is not
600a5d88 338 Pmode and therefore cannot use the pre-allocated rtx.
23b2ce53 339
600a5d88
RK
340 Also don't do this when we are making new REGs in reload,
341 since we don't want to get confused with the real pointers. */
342
343 if (frame_pointer_rtx && regno == FRAME_POINTER_REGNUM && mode == Pmode
344 && ! reload_in_progress)
23b2ce53 345 return frame_pointer_rtx;
ac6f08b0
DE
346#if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
347 if (hard_frame_pointer_rtx && regno == HARD_FRAME_POINTER_REGNUM
348 && mode == Pmode && ! reload_in_progress)
349 return hard_frame_pointer_rtx;
350#endif
351#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM && HARD_FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
600a5d88
RK
352 if (arg_pointer_rtx && regno == ARG_POINTER_REGNUM && mode == Pmode
353 && ! reload_in_progress)
23b2ce53 354 return arg_pointer_rtx;
a4417a86
JW
355#endif
356#ifdef RETURN_ADDRESS_POINTER_REGNUM
357 if (return_address_pointer_rtx && regno == RETURN_ADDRESS_POINTER_REGNUM
358 && mode == Pmode && ! reload_in_progress)
359 return return_address_pointer_rtx;
23b2ce53 360#endif
600a5d88
RK
361 if (stack_pointer_rtx && regno == STACK_POINTER_REGNUM && mode == Pmode
362 && ! reload_in_progress)
23b2ce53
RS
363 return stack_pointer_rtx;
364 else
365 {
366 rt_val = rtx_alloc (code);
367 rt_val->mode = mode;
368 REGNO (rt_val) = regno;
369 return rt_val;
370 }
371 }
372 else
373 {
374 rt_val = rtx_alloc (code); /* Allocate the storage space. */
375 rt_val->mode = mode; /* Store the machine mode... */
376
377 fmt = GET_RTX_FORMAT (code); /* Find the right format... */
378 for (i = 0; i < GET_RTX_LENGTH (code); i++)
379 {
380 switch (*fmt++)
381 {
382 case '0': /* Unused field. */
383 break;
384
385 case 'i': /* An integer? */
386 XINT (rt_val, i) = va_arg (p, int);
387 break;
388
906c4e36
RK
389 case 'w': /* A wide integer? */
390 XWINT (rt_val, i) = va_arg (p, HOST_WIDE_INT);
391 break;
392
23b2ce53
RS
393 case 's': /* A string? */
394 XSTR (rt_val, i) = va_arg (p, char *);
395 break;
396
397 case 'e': /* An expression? */
398 case 'u': /* An insn? Same except when printing. */
399 XEXP (rt_val, i) = va_arg (p, rtx);
400 break;
401
402 case 'E': /* An RTX vector? */
403 XVEC (rt_val, i) = va_arg (p, rtvec);
404 break;
405
406 default:
1632afca 407 abort ();
23b2ce53
RS
408 }
409 }
410 }
411 va_end (p);
412 return rt_val; /* Return the new RTX... */
413}
414
415/* gen_rtvec (n, [rt1, ..., rtn])
416**
417** This routine creates an rtvec and stores within it the
418** pointers to rtx's which are its arguments.
419*/
420
421/*VARARGS1*/
422rtvec
4f90e4a0 423gen_rtvec VPROTO((int n, ...))
23b2ce53 424{
4f90e4a0
RK
425#ifndef __STDC__
426 int n;
427#endif
428 int i;
23b2ce53
RS
429 va_list p;
430 rtx *vector;
431
4f90e4a0
RK
432 VA_START (p, n);
433
434#ifndef __STDC__
23b2ce53 435 n = va_arg (p, int);
4f90e4a0 436#endif
23b2ce53
RS
437
438 if (n == 0)
439 return NULL_RTVEC; /* Don't allocate an empty rtvec... */
440
441 vector = (rtx *) alloca (n * sizeof (rtx));
4f90e4a0 442
23b2ce53
RS
443 for (i = 0; i < n; i++)
444 vector[i] = va_arg (p, rtx);
445 va_end (p);
446
447 return gen_rtvec_v (n, vector);
448}
449
450rtvec
451gen_rtvec_v (n, argp)
452 int n;
453 rtx *argp;
454{
455 register int i;
456 register rtvec rt_val;
457
458 if (n == 0)
459 return NULL_RTVEC; /* Don't allocate an empty rtvec... */
460
461 rt_val = rtvec_alloc (n); /* Allocate an rtvec... */
462
463 for (i = 0; i < n; i++)
464 rt_val->elem[i].rtx = *argp++;
465
466 return rt_val;
467}
ba444f92
RK
468
469rtvec
470gen_rtvec_vv (n, argp)
471 int n;
472 rtunion *argp;
473{
474 register int i;
475 register rtvec rt_val;
476
477 if (n == 0)
478 return NULL_RTVEC; /* Don't allocate an empty rtvec... */
479
480 rt_val = rtvec_alloc (n); /* Allocate an rtvec... */
481
482 for (i = 0; i < n; i++)
483 rt_val->elem[i].rtx = (argp++)->rtx;
484
485 return rt_val;
486}
23b2ce53
RS
487\f
488/* Generate a REG rtx for a new pseudo register of mode MODE.
489 This pseudo is assigned the next sequential register number. */
490
491rtx
492gen_reg_rtx (mode)
493 enum machine_mode mode;
494{
495 register rtx val;
496
497 /* Don't let anything called by or after reload create new registers
498 (actually, registers can't be created after flow, but this is a good
499 approximation). */
500
501 if (reload_in_progress || reload_completed)
502 abort ();
503
fc84e8a8
RS
504 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
505 || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
506 {
507 /* For complex modes, don't make a single pseudo.
508 Instead, make a CONCAT of two pseudos.
509 This allows noncontiguous allocation of the real and imaginary parts,
510 which makes much better code. Besides, allocating DCmode
511 pseudos overstrains reload on some machines like the 386. */
512 rtx realpart, imagpart;
513 int size = GET_MODE_UNIT_SIZE (mode);
514 enum machine_mode partmode
515 = mode_for_size (size * BITS_PER_UNIT,
516 (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
517 ? MODE_FLOAT : MODE_INT),
518 0);
519
520 realpart = gen_reg_rtx (partmode);
521 imagpart = gen_reg_rtx (partmode);
522 return gen_rtx (CONCAT, mode, realpart, imagpart);
523 }
524
23b2ce53
RS
525 /* Make sure regno_pointer_flag and regno_reg_rtx are large
526 enough to have an element for this pseudo reg number. */
527
528 if (reg_rtx_no == regno_pointer_flag_length)
529 {
530 rtx *new1;
531 char *new =
86fe05e0 532 (char *) savealloc (regno_pointer_flag_length * 2);
23b2ce53 533 bcopy (regno_pointer_flag, new, regno_pointer_flag_length);
c0b178d0 534 bzero (&new[regno_pointer_flag_length], regno_pointer_flag_length);
23b2ce53
RS
535 regno_pointer_flag = new;
536
86fe05e0
RK
537 new = (char *) savealloc (regno_pointer_flag_length * 2);
538 bcopy (regno_pointer_align, new, regno_pointer_flag_length);
539 bzero (&new[regno_pointer_flag_length], regno_pointer_flag_length);
540 regno_pointer_align = new;
541
542 new1 = (rtx *) savealloc (regno_pointer_flag_length * 2 * sizeof (rtx));
4c9a05bc
RK
543 bcopy ((char *) regno_reg_rtx, (char *) new1,
544 regno_pointer_flag_length * sizeof (rtx));
545 bzero ((char *) &new1[regno_pointer_flag_length],
c0b178d0 546 regno_pointer_flag_length * sizeof (rtx));
23b2ce53
RS
547 regno_reg_rtx = new1;
548
549 regno_pointer_flag_length *= 2;
550 }
551
552 val = gen_rtx (REG, mode, reg_rtx_no);
553 regno_reg_rtx[reg_rtx_no++] = val;
554 return val;
555}
556
754fdcca
RK
557/* Identify REG (which may be a CONCAT) as a user register. */
558
559void
560mark_user_reg (reg)
561 rtx reg;
562{
563 if (GET_CODE (reg) == CONCAT)
564 {
565 REG_USERVAR_P (XEXP (reg, 0)) = 1;
566 REG_USERVAR_P (XEXP (reg, 1)) = 1;
567 }
568 else if (GET_CODE (reg) == REG)
569 REG_USERVAR_P (reg) = 1;
570 else
571 abort ();
572}
573
86fe05e0
RK
574/* Identify REG as a probable pointer register and show its alignment
575 as ALIGN, if nonzero. */
23b2ce53
RS
576
577void
86fe05e0 578mark_reg_pointer (reg, align)
23b2ce53 579 rtx reg;
86fe05e0 580 int align;
23b2ce53
RS
581{
582 REGNO_POINTER_FLAG (REGNO (reg)) = 1;
86fe05e0
RK
583
584 if (align)
585 REGNO_POINTER_ALIGN (REGNO (reg)) = align;
23b2ce53
RS
586}
587
588/* Return 1 plus largest pseudo reg number used in the current function. */
589
590int
591max_reg_num ()
592{
593 return reg_rtx_no;
594}
595
596/* Return 1 + the largest label number used so far in the current function. */
597
598int
599max_label_num ()
600{
601 if (last_label_num && label_num == base_label_num)
602 return last_label_num;
603 return label_num;
604}
605
606/* Return first label number used in this function (if any were used). */
607
608int
609get_first_label_num ()
610{
611 return first_label_num;
612}
613\f
614/* Return a value representing some low-order bits of X, where the number
615 of low-order bits is given by MODE. Note that no conversion is done
616 between floating-point and fixed-point values, rather, the bit
617 representation is returned.
618
619 This function handles the cases in common between gen_lowpart, below,
620 and two variants in cse.c and combine.c. These are the cases that can
621 be safely handled at all points in the compilation.
622
623 If this is not a case we can handle, return 0. */
624
625rtx
626gen_lowpart_common (mode, x)
627 enum machine_mode mode;
628 register rtx x;
629{
630 int word = 0;
631
632 if (GET_MODE (x) == mode)
633 return x;
634
635 /* MODE must occupy no more words than the mode of X. */
636 if (GET_MODE (x) != VOIDmode
637 && ((GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD
638 > ((GET_MODE_SIZE (GET_MODE (x)) + (UNITS_PER_WORD - 1))
639 / UNITS_PER_WORD)))
640 return 0;
641
642 if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
643 word = ((GET_MODE_SIZE (GET_MODE (x))
644 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD))
645 / UNITS_PER_WORD);
646
647 if ((GET_CODE (x) == ZERO_EXTEND || GET_CODE (x) == SIGN_EXTEND)
83e9c679
RK
648 && (GET_MODE_CLASS (mode) == MODE_INT
649 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT))
23b2ce53
RS
650 {
651 /* If we are getting the low-order part of something that has been
652 sign- or zero-extended, we can either just use the object being
653 extended or make a narrower extension. If we want an even smaller
654 piece than the size of the object being extended, call ourselves
655 recursively.
656
657 This case is used mostly by combine and cse. */
658
659 if (GET_MODE (XEXP (x, 0)) == mode)
660 return XEXP (x, 0);
661 else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (XEXP (x, 0))))
662 return gen_lowpart_common (mode, XEXP (x, 0));
663 else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (x)))
664 return gen_rtx (GET_CODE (x), mode, XEXP (x, 0));
665 }
666 else if (GET_CODE (x) == SUBREG
667 && (GET_MODE_SIZE (mode) <= UNITS_PER_WORD
668 || GET_MODE_SIZE (mode) == GET_MODE_UNIT_SIZE (GET_MODE (x))))
669 return (GET_MODE (SUBREG_REG (x)) == mode && SUBREG_WORD (x) == 0
670 ? SUBREG_REG (x)
04395f96 671 : gen_rtx (SUBREG, mode, SUBREG_REG (x), SUBREG_WORD (x) + word));
23b2ce53
RS
672 else if (GET_CODE (x) == REG)
673 {
674 /* If the register is not valid for MODE, return 0. If we don't
674d5d8b
RK
675 do this, there is no way to fix up the resulting REG later.
676 But we do do this if the current REG is not valid for its
677 mode. This latter is a kludge, but is required due to the
678 way that parameters are passed on some machines, most
679 notably Sparc. */
23b2ce53 680 if (REGNO (x) < FIRST_PSEUDO_REGISTER
674d5d8b
RK
681 && ! HARD_REGNO_MODE_OK (REGNO (x) + word, mode)
682 && HARD_REGNO_MODE_OK (REGNO (x), GET_MODE (x)))
23b2ce53
RS
683 return 0;
684 else if (REGNO (x) < FIRST_PSEUDO_REGISTER
685 /* integrate.c can't handle parts of a return value register. */
686 && (! REG_FUNCTION_VALUE_P (x)
cb00f51a
RK
687 || ! rtx_equal_function_value_matters)
688 /* We want to keep the stack, frame, and arg pointers
689 special. */
65e8fe02 690 && x != frame_pointer_rtx
cb00f51a 691#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
65e8fe02 692 && x != arg_pointer_rtx
cb00f51a 693#endif
65e8fe02 694 && x != stack_pointer_rtx)
23b2ce53
RS
695 return gen_rtx (REG, mode, REGNO (x) + word);
696 else
697 return gen_rtx (SUBREG, mode, x, word);
698 }
23b2ce53
RS
699 /* If X is a CONST_INT or a CONST_DOUBLE, extract the appropriate bits
700 from the low-order part of the constant. */
83e9c679
RK
701 else if ((GET_MODE_CLASS (mode) == MODE_INT
702 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
703 && GET_MODE (x) == VOIDmode
23b2ce53 704 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
1a5b457d
RK
705 {
706 /* If MODE is twice the host word size, X is already the desired
707 representation. Otherwise, if MODE is wider than a word, we can't
708 do this. If MODE is exactly a word, return just one CONST_INT.
709 If MODE is smaller than a word, clear the bits that don't belong
710 in our mode, unless they and our sign bit are all one. So we get
711 either a reasonable negative value or a reasonable unsigned value
712 for this mode. */
713
a8dd0e73 714 if (GET_MODE_BITSIZE (mode) >= 2 * HOST_BITS_PER_WIDE_INT)
1a5b457d 715 return x;
906c4e36 716 else if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
1a5b457d 717 return 0;
906c4e36 718 else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
1a5b457d 719 return (GET_CODE (x) == CONST_INT ? x
906c4e36 720 : GEN_INT (CONST_DOUBLE_LOW (x)));
1a5b457d
RK
721 else
722 {
723 /* MODE must be narrower than HOST_BITS_PER_INT. */
724 int width = GET_MODE_BITSIZE (mode);
906c4e36
RK
725 HOST_WIDE_INT val = (GET_CODE (x) == CONST_INT ? INTVAL (x)
726 : CONST_DOUBLE_LOW (x));
1a5b457d 727
906c4e36
RK
728 if (((val & ((HOST_WIDE_INT) (-1) << (width - 1)))
729 != ((HOST_WIDE_INT) (-1) << (width - 1))))
730 val &= ((HOST_WIDE_INT) 1 << width) - 1;
1a5b457d
RK
731
732 return (GET_CODE (x) == CONST_INT && INTVAL (x) == val ? x
906c4e36 733 : GEN_INT (val));
1a5b457d
RK
734 }
735 }
23b2ce53 736
8aada4ad
RK
737 /* If X is an integral constant but we want it in floating-point, it
738 must be the case that we have a union of an integer and a floating-point
739 value. If the machine-parameters allow it, simulate that union here
d6020413
RK
740 and return the result. The two-word and single-word cases are
741 different. */
8aada4ad 742
b3bf132d 743 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
906c4e36 744 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
b3bf132d 745 || flag_pretend_float)
8aada4ad 746 && GET_MODE_CLASS (mode) == MODE_FLOAT
d6020413
RK
747 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
748 && GET_CODE (x) == CONST_INT
906c4e36 749 && sizeof (float) * HOST_BITS_PER_CHAR == HOST_BITS_PER_WIDE_INT)
b6a524cb
RS
750#ifdef REAL_ARITHMETIC
751 {
752 REAL_VALUE_TYPE r;
753 HOST_WIDE_INT i;
754
755 i = INTVAL (x);
756 r = REAL_VALUE_FROM_TARGET_SINGLE (i);
53596fba 757 return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
b6a524cb
RS
758 }
759#else
d6020413 760 {
906c4e36 761 union {HOST_WIDE_INT i; float d; } u;
d6020413
RK
762
763 u.i = INTVAL (x);
53596fba 764 return CONST_DOUBLE_FROM_REAL_VALUE (u.d, mode);
d6020413 765 }
b6a524cb 766#endif
d6020413 767 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
906c4e36 768 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
d6020413
RK
769 || flag_pretend_float)
770 && GET_MODE_CLASS (mode) == MODE_FLOAT
771 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
8aada4ad
RK
772 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
773 && GET_MODE (x) == VOIDmode
906c4e36
RK
774 && (sizeof (double) * HOST_BITS_PER_CHAR
775 == 2 * HOST_BITS_PER_WIDE_INT))
b6a524cb
RS
776#ifdef REAL_ARITHMETIC
777 {
778 REAL_VALUE_TYPE r;
779 HOST_WIDE_INT i[2];
780 HOST_WIDE_INT low, high;
781
782 if (GET_CODE (x) == CONST_INT)
783 low = INTVAL (x), high = low >> (HOST_BITS_PER_WIDE_INT -1);
784 else
785 low = CONST_DOUBLE_LOW (x), high = CONST_DOUBLE_HIGH (x);
786
8698cce3 787 /* REAL_VALUE_TARGET_DOUBLE takes the addressing order of the
0f41302f 788 target machine. */
8698cce3
RK
789 if (WORDS_BIG_ENDIAN)
790 i[0] = high, i[1] = low;
791 else
792 i[0] = low, i[1] = high;
b6a524cb
RS
793
794 r = REAL_VALUE_FROM_TARGET_DOUBLE (i);
53596fba 795 return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
b6a524cb
RS
796 }
797#else
8aada4ad 798 {
906c4e36
RK
799 union {HOST_WIDE_INT i[2]; double d; } u;
800 HOST_WIDE_INT low, high;
8aada4ad
RK
801
802 if (GET_CODE (x) == CONST_INT)
906c4e36 803 low = INTVAL (x), high = low >> (HOST_BITS_PER_WIDE_INT -1);
8aada4ad
RK
804 else
805 low = CONST_DOUBLE_LOW (x), high = CONST_DOUBLE_HIGH (x);
806
807#ifdef HOST_WORDS_BIG_ENDIAN
808 u.i[0] = high, u.i[1] = low;
809#else
810 u.i[0] = low, u.i[1] = high;
811#endif
812
53596fba 813 return CONST_DOUBLE_FROM_REAL_VALUE (u.d, mode);
8aada4ad 814 }
b6a524cb 815#endif
a6a503ed
JW
816
817 /* We need an extra case for machines where HOST_BITS_PER_WIDE_INT is the
818 same as sizeof (double), such as the alpha. We only handle the
819 REAL_ARITHMETIC case, which is easy. Testing HOST_BITS_PER_WIDE_INT
820 is not strictly necessary, but is done to restrict this code to cases
821 where it is known to work. */
822#ifdef REAL_ARITHMETIC
823 else if (mode == SFmode
824 && GET_CODE (x) == CONST_INT
825 && GET_MODE_BITSIZE (mode) * 2 == HOST_BITS_PER_WIDE_INT)
826 {
827 REAL_VALUE_TYPE r;
828 HOST_WIDE_INT i;
829
830 i = INTVAL (x);
831 r = REAL_VALUE_FROM_TARGET_SINGLE (i);
832 return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
833 }
834#endif
835
b3bf132d
RK
836 /* Similarly, if this is converting a floating-point value into a
837 single-word integer. Only do this is the host and target parameters are
838 compatible. */
839
840 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
906c4e36 841 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
b3bf132d 842 || flag_pretend_float)
83e9c679
RK
843 && (GET_MODE_CLASS (mode) == MODE_INT
844 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
b3bf132d
RK
845 && GET_CODE (x) == CONST_DOUBLE
846 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT
847 && GET_MODE_BITSIZE (mode) == BITS_PER_WORD)
a80586cc 848 return operand_subword (x, word, 0, GET_MODE (x));
b3bf132d 849
8aada4ad
RK
850 /* Similarly, if this is converting a floating-point value into a
851 two-word integer, we can do this one word at a time and make an
852 integer. Only do this is the host and target parameters are
853 compatible. */
854
b3bf132d 855 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
906c4e36 856 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
b3bf132d 857 || flag_pretend_float)
83e9c679 858 && (GET_MODE_CLASS (mode) == MODE_INT
f5a2fb25 859 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
8aada4ad
RK
860 && GET_CODE (x) == CONST_DOUBLE
861 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT
862 && GET_MODE_BITSIZE (mode) == 2 * BITS_PER_WORD)
863 {
a80586cc
RK
864 rtx lowpart
865 = operand_subword (x, word + WORDS_BIG_ENDIAN, 0, GET_MODE (x));
866 rtx highpart
867 = operand_subword (x, word + ! WORDS_BIG_ENDIAN, 0, GET_MODE (x));
8aada4ad
RK
868
869 if (lowpart && GET_CODE (lowpart) == CONST_INT
870 && highpart && GET_CODE (highpart) == CONST_INT)
871 return immed_double_const (INTVAL (lowpart), INTVAL (highpart), mode);
872 }
873
23b2ce53
RS
874 /* Otherwise, we can't do this. */
875 return 0;
876}
877\f
280194b0
RS
878/* Return the real part (which has mode MODE) of a complex value X.
879 This always comes at the low address in memory. */
880
881rtx
882gen_realpart (mode, x)
883 enum machine_mode mode;
884 register rtx x;
885{
dc139c90
RK
886 if (GET_CODE (x) == CONCAT && GET_MODE (XEXP (x, 0)) == mode)
887 return XEXP (x, 0);
888 else if (WORDS_BIG_ENDIAN)
280194b0
RS
889 return gen_highpart (mode, x);
890 else
891 return gen_lowpart (mode, x);
892}
893
894/* Return the imaginary part (which has mode MODE) of a complex value X.
895 This always comes at the high address in memory. */
896
897rtx
898gen_imagpart (mode, x)
899 enum machine_mode mode;
900 register rtx x;
901{
dc139c90
RK
902 if (GET_CODE (x) == CONCAT && GET_MODE (XEXP (x, 0)) == mode)
903 return XEXP (x, 1);
904 else if (WORDS_BIG_ENDIAN)
280194b0
RS
905 return gen_lowpart (mode, x);
906 else
907 return gen_highpart (mode, x);
908}
81284a6a
JW
909
910/* Return 1 iff X, assumed to be a SUBREG,
911 refers to the real part of the complex value in its containing reg.
912 Complex values are always stored with the real part in the first word,
913 regardless of WORDS_BIG_ENDIAN. */
914
915int
916subreg_realpart_p (x)
917 rtx x;
918{
919 if (GET_CODE (x) != SUBREG)
920 abort ();
921
922 return SUBREG_WORD (x) == 0;
923}
280194b0 924\f
23b2ce53
RS
925/* Assuming that X is an rtx (e.g., MEM, REG or SUBREG) for a value,
926 return an rtx (MEM, SUBREG, or CONST_INT) that refers to the
927 least-significant part of X.
928 MODE specifies how big a part of X to return;
929 it usually should not be larger than a word.
930 If X is a MEM whose address is a QUEUED, the value may be so also. */
931
932rtx
933gen_lowpart (mode, x)
934 enum machine_mode mode;
935 register rtx x;
936{
937 rtx result = gen_lowpart_common (mode, x);
938
939 if (result)
940 return result;
ea8262b0
RK
941 else if (GET_CODE (x) == REG)
942 {
943 /* Must be a hard reg that's not valid in MODE. */
944 result = gen_lowpart_common (mode, copy_to_reg (x));
945 if (result == 0)
946 abort ();
72c3833b 947 return result;
ea8262b0 948 }
23b2ce53
RS
949 else if (GET_CODE (x) == MEM)
950 {
951 /* The only additional case we can do is MEM. */
952 register int offset = 0;
953 if (WORDS_BIG_ENDIAN)
954 offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
955 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
956
957 if (BYTES_BIG_ENDIAN)
958 /* Adjust the address so that the address-after-the-data
959 is unchanged. */
960 offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))
961 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
962
963 return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
964 }
e9a25f70
JL
965 else if (GET_CODE (x) == ADDRESSOF)
966 return gen_lowpart (mode, force_reg (GET_MODE (x), x));
23b2ce53
RS
967 else
968 abort ();
969}
970
ccba022b
RS
971/* Like `gen_lowpart', but refer to the most significant part.
972 This is used to access the imaginary part of a complex number. */
973
974rtx
975gen_highpart (mode, x)
976 enum machine_mode mode;
977 register rtx x;
978{
979 /* This case loses if X is a subreg. To catch bugs early,
980 complain if an invalid MODE is used even in other cases. */
981 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
982 && GET_MODE_SIZE (mode) != GET_MODE_UNIT_SIZE (GET_MODE (x)))
983 abort ();
984 if (GET_CODE (x) == CONST_DOUBLE
1632afca 985#if !(TARGET_FLOAT_FORMAT != HOST_FLOAT_FORMAT || defined (REAL_IS_NOT_DOUBLE))
ccba022b
RS
986 && GET_MODE_CLASS (GET_MODE (x)) != MODE_FLOAT
987#endif
988 )
989 return gen_rtx (CONST_INT, VOIDmode,
990 CONST_DOUBLE_HIGH (x) & GET_MODE_MASK (mode));
991 else if (GET_CODE (x) == CONST_INT)
992 return const0_rtx;
993 else if (GET_CODE (x) == MEM)
994 {
995 register int offset = 0;
8698cce3
RK
996 if (! WORDS_BIG_ENDIAN)
997 offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
998 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
999
1000 if (! BYTES_BIG_ENDIAN
1001 && GET_MODE_SIZE (mode) < UNITS_PER_WORD)
ccba022b
RS
1002 offset -= (GET_MODE_SIZE (mode)
1003 - MIN (UNITS_PER_WORD,
1004 GET_MODE_SIZE (GET_MODE (x))));
8698cce3 1005
ccba022b
RS
1006 return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
1007 }
1008 else if (GET_CODE (x) == SUBREG)
1009 {
1010 /* The only time this should occur is when we are looking at a
1011 multi-word item with a SUBREG whose mode is the same as that of the
1012 item. It isn't clear what we would do if it wasn't. */
1013 if (SUBREG_WORD (x) != 0)
1014 abort ();
1015 return gen_highpart (mode, SUBREG_REG (x));
1016 }
1017 else if (GET_CODE (x) == REG)
1018 {
1019 int word = 0;
1020
8698cce3
RK
1021 if (! WORDS_BIG_ENDIAN
1022 && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
ccba022b
RS
1023 word = ((GET_MODE_SIZE (GET_MODE (x))
1024 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD))
1025 / UNITS_PER_WORD);
8698cce3 1026
3e4a14ef
RK
1027 /*
1028 * ??? This fails miserably for complex values being passed in registers
1029 * where the sizeof the real and imaginary part are not equal to the
1030 * sizeof SImode. FIXME
1031 */
1032
cb00f51a 1033 if (REGNO (x) < FIRST_PSEUDO_REGISTER
0f41302f 1034 /* integrate.c can't handle parts of a return value register. */
4badc528
RS
1035 && (! REG_FUNCTION_VALUE_P (x)
1036 || ! rtx_equal_function_value_matters)
cb00f51a 1037 /* We want to keep the stack, frame, and arg pointers special. */
65e8fe02 1038 && x != frame_pointer_rtx
cb00f51a 1039#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
65e8fe02 1040 && x != arg_pointer_rtx
cb00f51a 1041#endif
65e8fe02 1042 && x != stack_pointer_rtx)
ccba022b
RS
1043 return gen_rtx (REG, mode, REGNO (x) + word);
1044 else
1045 return gen_rtx (SUBREG, mode, x, word);
1046 }
1047 else
1048 abort ();
1049}
1050
23b2ce53
RS
1051/* Return 1 iff X, assumed to be a SUBREG,
1052 refers to the least significant part of its containing reg.
1053 If X is not a SUBREG, always return 1 (it is its own low part!). */
1054
1055int
1056subreg_lowpart_p (x)
1057 rtx x;
1058{
1059 if (GET_CODE (x) != SUBREG)
1060 return 1;
a3a03040
RK
1061 else if (GET_MODE (SUBREG_REG (x)) == VOIDmode)
1062 return 0;
23b2ce53
RS
1063
1064 if (WORDS_BIG_ENDIAN
1065 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) > UNITS_PER_WORD)
1066 return (SUBREG_WORD (x)
1067 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
1068 - MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD))
1069 / UNITS_PER_WORD));
1070
1071 return SUBREG_WORD (x) == 0;
1072}
1073\f
1074/* Return subword I of operand OP.
1075 The word number, I, is interpreted as the word number starting at the
1076 low-order address. Word 0 is the low-order word if not WORDS_BIG_ENDIAN,
1077 otherwise it is the high-order word.
1078
1079 If we cannot extract the required word, we return zero. Otherwise, an
1080 rtx corresponding to the requested word will be returned.
1081
1082 VALIDATE_ADDRESS is nonzero if the address should be validated. Before
1083 reload has completed, a valid address will always be returned. After
1084 reload, if a valid address cannot be returned, we return zero.
1085
1086 If VALIDATE_ADDRESS is zero, we simply form the required address; validating
1087 it is the responsibility of the caller.
1088
1089 MODE is the mode of OP in case it is a CONST_INT. */
1090
1091rtx
1092operand_subword (op, i, validate_address, mode)
1093 rtx op;
1094 int i;
1095 int validate_address;
1096 enum machine_mode mode;
1097{
906c4e36
RK
1098 HOST_WIDE_INT val;
1099 int size_ratio = HOST_BITS_PER_WIDE_INT / BITS_PER_WORD;
23b2ce53
RS
1100
1101 if (mode == VOIDmode)
1102 mode = GET_MODE (op);
1103
1104 if (mode == VOIDmode)
1105 abort ();
1106
1107 /* If OP is narrower than a word or if we want a word outside OP, fail. */
1108 if (mode != BLKmode
1109 && (GET_MODE_SIZE (mode) < UNITS_PER_WORD
1110 || (i + 1) * UNITS_PER_WORD > GET_MODE_SIZE (mode)))
1111 return 0;
1112
1113 /* If OP is already an integer word, return it. */
1114 if (GET_MODE_CLASS (mode) == MODE_INT
1115 && GET_MODE_SIZE (mode) == UNITS_PER_WORD)
1116 return op;
1117
1118 /* If OP is a REG or SUBREG, we can handle it very simply. */
1119 if (GET_CODE (op) == REG)
1120 {
1121 /* If the register is not valid for MODE, return 0. If we don't
1122 do this, there is no way to fix up the resulting REG later. */
1123 if (REGNO (op) < FIRST_PSEUDO_REGISTER
1124 && ! HARD_REGNO_MODE_OK (REGNO (op) + i, word_mode))
1125 return 0;
1126 else if (REGNO (op) >= FIRST_PSEUDO_REGISTER
1127 || (REG_FUNCTION_VALUE_P (op)
cb00f51a
RK
1128 && rtx_equal_function_value_matters)
1129 /* We want to keep the stack, frame, and arg pointers
1130 special. */
65e8fe02 1131 || op == frame_pointer_rtx
cb00f51a 1132#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
65e8fe02 1133 || op == arg_pointer_rtx
cb00f51a 1134#endif
65e8fe02 1135 || op == stack_pointer_rtx)
23b2ce53
RS
1136 return gen_rtx (SUBREG, word_mode, op, i);
1137 else
1138 return gen_rtx (REG, word_mode, REGNO (op) + i);
1139 }
1140 else if (GET_CODE (op) == SUBREG)
1141 return gen_rtx (SUBREG, word_mode, SUBREG_REG (op), i + SUBREG_WORD (op));
fc84e8a8
RS
1142 else if (GET_CODE (op) == CONCAT)
1143 {
1144 int partwords = GET_MODE_UNIT_SIZE (GET_MODE (op)) / UNITS_PER_WORD;
1145 if (i < partwords)
1146 return operand_subword (XEXP (op, 0), i, validate_address, mode);
1147 return operand_subword (XEXP (op, 1), i - partwords,
1148 validate_address, mode);
1149 }
23b2ce53
RS
1150
1151 /* Form a new MEM at the requested address. */
1152 if (GET_CODE (op) == MEM)
1153 {
1154 rtx addr = plus_constant (XEXP (op, 0), i * UNITS_PER_WORD);
1155 rtx new;
1156
1157 if (validate_address)
1158 {
1159 if (reload_completed)
1160 {
1161 if (! strict_memory_address_p (word_mode, addr))
1162 return 0;
1163 }
1164 else
1165 addr = memory_address (word_mode, addr);
1166 }
1167
1168 new = gen_rtx (MEM, word_mode, addr);
1169
1170 MEM_VOLATILE_P (new) = MEM_VOLATILE_P (op);
1171 MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (op);
1172 RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (op);
1173
1174 return new;
1175 }
1176
1177 /* The only remaining cases are when OP is a constant. If the host and
1178 target floating formats are the same, handling two-word floating
7677ffa4 1179 constants are easy. Note that REAL_VALUE_TO_TARGET_{SINGLE,DOUBLE}
9847c2f6
RK
1180 are defined as returning one or two 32 bit values, respectively,
1181 and not values of BITS_PER_WORD bits. */
1632afca 1182#ifdef REAL_ARITHMETIC
9847c2f6
RK
1183/* The output is some bits, the width of the target machine's word.
1184 A wider-word host can surely hold them in a CONST_INT. A narrower-word
1185 host can't. */
1186 if (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
1632afca 1187 && GET_MODE_CLASS (mode) == MODE_FLOAT
7677ffa4 1188 && GET_MODE_BITSIZE (mode) == 64
1632afca
RS
1189 && GET_CODE (op) == CONST_DOUBLE)
1190 {
9847c2f6 1191 long k[2];
1632afca
RS
1192 REAL_VALUE_TYPE rv;
1193
1194 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1195 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
7677ffa4 1196
9847c2f6 1197 /* We handle 32-bit and >= 64-bit words here. Note that the order in
7677ffa4
RK
1198 which the words are written depends on the word endianness.
1199
1200 ??? This is a potential portability problem and should
1201 be fixed at some point. */
9847c2f6
RK
1202 if (BITS_PER_WORD == 32)
1203 return GEN_INT ((HOST_WIDE_INT) k[i]);
1204#if HOST_BITS_PER_WIDE_INT > 32
1205 else if (BITS_PER_WORD >= 64 && i == 0)
1206 return GEN_INT ((((HOST_WIDE_INT) k[! WORDS_BIG_ENDIAN]) << 32)
1207 | (HOST_WIDE_INT) k[WORDS_BIG_ENDIAN]);
1208#endif
47b34d40
JW
1209 else if (BITS_PER_WORD == 16)
1210 {
1211 long value;
1212 value = k[i >> 1];
1213 if ((i & 0x1) == 0)
1214 value >>= 16;
1215 value &= 0xffff;
1216 return GEN_INT ((HOST_WIDE_INT) value);
1217 }
7677ffa4
RK
1218 else
1219 abort ();
1632afca 1220 }
a5559dbc
RE
1221 else if (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
1222 && GET_MODE_CLASS (mode) == MODE_FLOAT
1223 && GET_MODE_BITSIZE (mode) > 64
1224 && GET_CODE (op) == CONST_DOUBLE)
1225 {
1226 long k[4];
1227 REAL_VALUE_TYPE rv;
1228
1229 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1230 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
1231
1232 if (BITS_PER_WORD == 32)
1233 return GEN_INT ((HOST_WIDE_INT) k[i]);
1234 }
1632afca 1235#else /* no REAL_ARITHMETIC */
23b2ce53 1236 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
906c4e36 1237 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
23b2ce53
RS
1238 || flag_pretend_float)
1239 && GET_MODE_CLASS (mode) == MODE_FLOAT
1240 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
1241 && GET_CODE (op) == CONST_DOUBLE)
7529ac93
CH
1242 {
1243 /* The constant is stored in the host's word-ordering,
1244 but we want to access it in the target's word-ordering. Some
1245 compilers don't like a conditional inside macro args, so we have two
1246 copies of the return. */
2fe02d7e 1247#ifdef HOST_WORDS_BIG_ENDIAN
7529ac93
CH
1248 return GEN_INT (i == WORDS_BIG_ENDIAN
1249 ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
2fe02d7e 1250#else
7529ac93
CH
1251 return GEN_INT (i != WORDS_BIG_ENDIAN
1252 ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
2fe02d7e 1253#endif
7529ac93 1254 }
1632afca 1255#endif /* no REAL_ARITHMETIC */
23b2ce53
RS
1256
1257 /* Single word float is a little harder, since single- and double-word
1258 values often do not have the same high-order bits. We have already
1259 verified that we want the only defined word of the single-word value. */
1632afca 1260#ifdef REAL_ARITHMETIC
9847c2f6 1261 if (GET_MODE_CLASS (mode) == MODE_FLOAT
7677ffa4 1262 && GET_MODE_BITSIZE (mode) == 32
1632afca
RS
1263 && GET_CODE (op) == CONST_DOUBLE)
1264 {
9847c2f6 1265 long l;
1632afca
RS
1266 REAL_VALUE_TYPE rv;
1267
1268 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1269 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
9847c2f6 1270 return GEN_INT ((HOST_WIDE_INT) l);
1632afca
RS
1271 }
1272#else
23b2ce53 1273 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
906c4e36 1274 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
23b2ce53 1275 || flag_pretend_float)
e01a2cec 1276 && sizeof (float) * 8 == HOST_BITS_PER_WIDE_INT
23b2ce53
RS
1277 && GET_MODE_CLASS (mode) == MODE_FLOAT
1278 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
1279 && GET_CODE (op) == CONST_DOUBLE)
1280 {
1281 double d;
906c4e36 1282 union {float f; HOST_WIDE_INT i; } u;
23b2ce53
RS
1283
1284 REAL_VALUE_FROM_CONST_DOUBLE (d, op);
1285
1286 u.f = d;
906c4e36 1287 return GEN_INT (u.i);
23b2ce53 1288 }
e01a2cec
RK
1289 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1290 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1291 || flag_pretend_float)
1292 && sizeof (double) * 8 == HOST_BITS_PER_WIDE_INT
1293 && GET_MODE_CLASS (mode) == MODE_FLOAT
1294 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
1295 && GET_CODE (op) == CONST_DOUBLE)
1296 {
1297 double d;
1298 union {double d; HOST_WIDE_INT i; } u;
1299
1300 REAL_VALUE_FROM_CONST_DOUBLE (d, op);
1301
1302 u.d = d;
1303 return GEN_INT (u.i);
1304 }
1632afca 1305#endif /* no REAL_ARITHMETIC */
23b2ce53
RS
1306
1307 /* The only remaining cases that we can handle are integers.
1308 Convert to proper endianness now since these cases need it.
1309 At this point, i == 0 means the low-order word.
1310
2d4f57f8
RK
1311 We do not want to handle the case when BITS_PER_WORD <= HOST_BITS_PER_INT
1312 in general. However, if OP is (const_int 0), we can just return
1313 it for any word. */
1314
1315 if (op == const0_rtx)
1316 return op;
23b2ce53
RS
1317
1318 if (GET_MODE_CLASS (mode) != MODE_INT
2d4f57f8 1319 || (GET_CODE (op) != CONST_INT && GET_CODE (op) != CONST_DOUBLE)
0cf214a0 1320 || BITS_PER_WORD > HOST_BITS_PER_WIDE_INT)
23b2ce53
RS
1321 return 0;
1322
1323 if (WORDS_BIG_ENDIAN)
1324 i = GET_MODE_SIZE (mode) / UNITS_PER_WORD - 1 - i;
1325
1326 /* Find out which word on the host machine this value is in and get
1327 it from the constant. */
1328 val = (i / size_ratio == 0
1329 ? (GET_CODE (op) == CONST_INT ? INTVAL (op) : CONST_DOUBLE_LOW (op))
1330 : (GET_CODE (op) == CONST_INT
1331 ? (INTVAL (op) < 0 ? ~0 : 0) : CONST_DOUBLE_HIGH (op)));
1332
1333 /* If BITS_PER_WORD is smaller than an int, get the appropriate bits. */
906c4e36 1334 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT)
23b2ce53 1335 val = ((val >> ((i % size_ratio) * BITS_PER_WORD))
906c4e36
RK
1336 & (((HOST_WIDE_INT) 1
1337 << (BITS_PER_WORD % HOST_BITS_PER_WIDE_INT)) - 1));
23b2ce53 1338
906c4e36 1339 return GEN_INT (val);
23b2ce53
RS
1340}
1341
1342/* Similar to `operand_subword', but never return 0. If we can't extract
1343 the required subword, put OP into a register and try again. If that fails,
1344 abort. We always validate the address in this case. It is not valid
1345 to call this function after reload; it is mostly meant for RTL
1346 generation.
1347
1348 MODE is the mode of OP, in case it is CONST_INT. */
1349
1350rtx
1351operand_subword_force (op, i, mode)
1352 rtx op;
1353 int i;
1354 enum machine_mode mode;
1355{
1356 rtx result = operand_subword (op, i, 1, mode);
1357
1358 if (result)
1359 return result;
1360
1361 if (mode != BLKmode && mode != VOIDmode)
1362 op = force_reg (mode, op);
1363
1364 result = operand_subword (op, i, 1, mode);
1365 if (result == 0)
1366 abort ();
1367
1368 return result;
1369}
1370\f
1371/* Given a compare instruction, swap the operands.
1372 A test instruction is changed into a compare of 0 against the operand. */
1373
1374void
1375reverse_comparison (insn)
1376 rtx insn;
1377{
1378 rtx body = PATTERN (insn);
1379 rtx comp;
1380
1381 if (GET_CODE (body) == SET)
1382 comp = SET_SRC (body);
1383 else
1384 comp = SET_SRC (XVECEXP (body, 0, 0));
1385
1386 if (GET_CODE (comp) == COMPARE)
1387 {
1388 rtx op0 = XEXP (comp, 0);
1389 rtx op1 = XEXP (comp, 1);
1390 XEXP (comp, 0) = op1;
1391 XEXP (comp, 1) = op0;
1392 }
1393 else
1394 {
1395 rtx new = gen_rtx (COMPARE, VOIDmode,
1396 CONST0_RTX (GET_MODE (comp)), comp);
1397 if (GET_CODE (body) == SET)
1398 SET_SRC (body) = new;
1399 else
1400 SET_SRC (XVECEXP (body, 0, 0)) = new;
1401 }
1402}
1403\f
1404/* Return a memory reference like MEMREF, but with its mode changed
1405 to MODE and its address changed to ADDR.
1406 (VOIDmode means don't change the mode.
1407 NULL for ADDR means don't change the address.) */
1408
1409rtx
1410change_address (memref, mode, addr)
1411 rtx memref;
1412 enum machine_mode mode;
1413 rtx addr;
1414{
1415 rtx new;
1416
1417 if (GET_CODE (memref) != MEM)
1418 abort ();
1419 if (mode == VOIDmode)
1420 mode = GET_MODE (memref);
1421 if (addr == 0)
1422 addr = XEXP (memref, 0);
1423
1424 /* If reload is in progress or has completed, ADDR must be valid.
1425 Otherwise, we can call memory_address to make it valid. */
1426 if (reload_completed || reload_in_progress)
1427 {
1428 if (! memory_address_p (mode, addr))
1429 abort ();
1430 }
1431 else
1432 addr = memory_address (mode, addr);
1433
9b04c6a8
RK
1434 if (rtx_equal_p (addr, XEXP (memref, 0)) && mode == GET_MODE (memref))
1435 return memref;
1436
23b2ce53
RS
1437 new = gen_rtx (MEM, mode, addr);
1438 MEM_VOLATILE_P (new) = MEM_VOLATILE_P (memref);
1439 RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (memref);
1440 MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (memref);
1441 return new;
1442}
1443\f
1444/* Return a newly created CODE_LABEL rtx with a unique label number. */
1445
1446rtx
1447gen_label_rtx ()
1448{
ca695ac9
JB
1449 register rtx label;
1450
8b6813aa
RS
1451 label = (output_bytecode
1452 ? gen_rtx (CODE_LABEL, VOIDmode, NULL, bc_get_bytecode_label ())
9524f769
DM
1453 : gen_rtx (CODE_LABEL, VOIDmode, 0, NULL_RTX,
1454 NULL_RTX, label_num++, NULL_PTR));
ca695ac9 1455
23b2ce53
RS
1456 LABEL_NUSES (label) = 0;
1457 return label;
1458}
1459\f
1460/* For procedure integration. */
1461
1462/* Return a newly created INLINE_HEADER rtx. Should allocate this
1463 from a permanent obstack when the opportunity arises. */
1464
1465rtx
1466gen_inline_header_rtx (first_insn, first_parm_insn, first_labelno,
1467 last_labelno, max_parm_regnum, max_regnum, args_size,
a6108925 1468 pops_args, stack_slots, forced_labels, function_flags,
23b2ce53 1469 outgoing_args_size, original_arg_vector,
86fe05e0 1470 original_decl_initial, regno_rtx, regno_flag,
e9a25f70 1471 regno_align, parm_reg_stack_loc)
23b2ce53
RS
1472 rtx first_insn, first_parm_insn;
1473 int first_labelno, last_labelno, max_parm_regnum, max_regnum, args_size;
1474 int pops_args;
1475 rtx stack_slots;
a6108925 1476 rtx forced_labels;
23b2ce53
RS
1477 int function_flags;
1478 int outgoing_args_size;
1479 rtvec original_arg_vector;
1480 rtx original_decl_initial;
86fe05e0
RK
1481 rtvec regno_rtx;
1482 char *regno_flag;
1483 char *regno_align;
e9a25f70 1484 rtvec parm_reg_stack_loc;
23b2ce53
RS
1485{
1486 rtx header = gen_rtx (INLINE_HEADER, VOIDmode,
906c4e36 1487 cur_insn_uid++, NULL_RTX,
23b2ce53
RS
1488 first_insn, first_parm_insn,
1489 first_labelno, last_labelno,
1490 max_parm_regnum, max_regnum, args_size, pops_args,
a6108925 1491 stack_slots, forced_labels, function_flags,
86fe05e0
RK
1492 outgoing_args_size, original_arg_vector,
1493 original_decl_initial,
e9a25f70
JL
1494 regno_rtx, regno_flag, regno_align,
1495 parm_reg_stack_loc);
23b2ce53
RS
1496 return header;
1497}
1498
1499/* Install new pointers to the first and last insns in the chain.
86fe05e0 1500 Also, set cur_insn_uid to one higher than the last in use.
23b2ce53
RS
1501 Used for an inline-procedure after copying the insn chain. */
1502
1503void
1504set_new_first_and_last_insn (first, last)
1505 rtx first, last;
1506{
86fe05e0
RK
1507 rtx insn;
1508
23b2ce53
RS
1509 first_insn = first;
1510 last_insn = last;
86fe05e0
RK
1511 cur_insn_uid = 0;
1512
1513 for (insn = first; insn; insn = NEXT_INSN (insn))
1514 cur_insn_uid = MAX (cur_insn_uid, INSN_UID (insn));
1515
1516 cur_insn_uid++;
23b2ce53
RS
1517}
1518
1519/* Set the range of label numbers found in the current function.
1520 This is used when belatedly compiling an inline function. */
1521
1522void
1523set_new_first_and_last_label_num (first, last)
1524 int first, last;
1525{
1526 base_label_num = label_num;
1527 first_label_num = first;
1528 last_label_num = last;
1529}
1530\f
1531/* Save all variables describing the current status into the structure *P.
1532 This is used before starting a nested function. */
1533
1534void
1535save_emit_status (p)
1536 struct function *p;
1537{
1538 p->reg_rtx_no = reg_rtx_no;
1539 p->first_label_num = first_label_num;
1540 p->first_insn = first_insn;
1541 p->last_insn = last_insn;
a25c7971 1542 p->sequence_rtl_expr = sequence_rtl_expr;
23b2ce53
RS
1543 p->sequence_stack = sequence_stack;
1544 p->cur_insn_uid = cur_insn_uid;
1545 p->last_linenum = last_linenum;
1546 p->last_filename = last_filename;
1547 p->regno_pointer_flag = regno_pointer_flag;
86fe05e0 1548 p->regno_pointer_align = regno_pointer_align;
23b2ce53
RS
1549 p->regno_pointer_flag_length = regno_pointer_flag_length;
1550 p->regno_reg_rtx = regno_reg_rtx;
1551}
1552
1553/* Restore all variables describing the current status from the structure *P.
1554 This is used after a nested function. */
1555
1556void
1557restore_emit_status (p)
1558 struct function *p;
1559{
1560 int i;
1561
1562 reg_rtx_no = p->reg_rtx_no;
1563 first_label_num = p->first_label_num;
457a2d9c 1564 last_label_num = 0;
23b2ce53
RS
1565 first_insn = p->first_insn;
1566 last_insn = p->last_insn;
a25c7971 1567 sequence_rtl_expr = p->sequence_rtl_expr;
23b2ce53
RS
1568 sequence_stack = p->sequence_stack;
1569 cur_insn_uid = p->cur_insn_uid;
1570 last_linenum = p->last_linenum;
1571 last_filename = p->last_filename;
1572 regno_pointer_flag = p->regno_pointer_flag;
86fe05e0 1573 regno_pointer_align = p->regno_pointer_align;
23b2ce53
RS
1574 regno_pointer_flag_length = p->regno_pointer_flag_length;
1575 regno_reg_rtx = p->regno_reg_rtx;
1576
0f41302f
MS
1577 /* Clear our cache of rtx expressions for start_sequence and
1578 gen_sequence. */
23b2ce53
RS
1579 sequence_element_free_list = 0;
1580 for (i = 0; i < SEQUENCE_RESULT_SIZE; i++)
1581 sequence_result[i] = 0;
43127294
RK
1582
1583 free_insn = 0;
23b2ce53
RS
1584}
1585\f
1586/* Go through all the RTL insn bodies and copy any invalid shared structure.
1587 It does not work to do this twice, because the mark bits set here
1588 are not cleared afterwards. */
1589
1590void
1591unshare_all_rtl (insn)
1592 register rtx insn;
1593{
1594 for (; insn; insn = NEXT_INSN (insn))
1595 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
1596 || GET_CODE (insn) == CALL_INSN)
1597 {
1598 PATTERN (insn) = copy_rtx_if_shared (PATTERN (insn));
1599 REG_NOTES (insn) = copy_rtx_if_shared (REG_NOTES (insn));
1600 LOG_LINKS (insn) = copy_rtx_if_shared (LOG_LINKS (insn));
1601 }
1602
1603 /* Make sure the addresses of stack slots found outside the insn chain
1604 (such as, in DECL_RTL of a variable) are not shared
1605 with the insn chain.
1606
1607 This special care is necessary when the stack slot MEM does not
1608 actually appear in the insn chain. If it does appear, its address
1609 is unshared from all else at that point. */
1610
1611 copy_rtx_if_shared (stack_slot_list);
1612}
1613
1614/* Mark ORIG as in use, and return a copy of it if it was already in use.
1615 Recursively does the same for subexpressions. */
1616
1617rtx
1618copy_rtx_if_shared (orig)
1619 rtx orig;
1620{
1621 register rtx x = orig;
1622 register int i;
1623 register enum rtx_code code;
1624 register char *format_ptr;
1625 int copied = 0;
1626
1627 if (x == 0)
1628 return 0;
1629
1630 code = GET_CODE (x);
1631
1632 /* These types may be freely shared. */
1633
1634 switch (code)
1635 {
1636 case REG:
1637 case QUEUED:
1638 case CONST_INT:
1639 case CONST_DOUBLE:
1640 case SYMBOL_REF:
1641 case CODE_LABEL:
1642 case PC:
1643 case CC0:
1644 case SCRATCH:
0f41302f 1645 /* SCRATCH must be shared because they represent distinct values. */
23b2ce53
RS
1646 return x;
1647
b851ea09
RK
1648 case CONST:
1649 /* CONST can be shared if it contains a SYMBOL_REF. If it contains
1650 a LABEL_REF, it isn't sharable. */
1651 if (GET_CODE (XEXP (x, 0)) == PLUS
1652 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
1653 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
1654 return x;
1655 break;
1656
23b2ce53
RS
1657 case INSN:
1658 case JUMP_INSN:
1659 case CALL_INSN:
1660 case NOTE:
23b2ce53
RS
1661 case BARRIER:
1662 /* The chain of insns is not being copied. */
1663 return x;
1664
1665 case MEM:
1666 /* A MEM is allowed to be shared if its address is constant
1667 or is a constant plus one of the special registers. */
1668 if (CONSTANT_ADDRESS_P (XEXP (x, 0))
1669 || XEXP (x, 0) == virtual_stack_vars_rtx
1670 || XEXP (x, 0) == virtual_incoming_args_rtx)
1671 return x;
1672
1673 if (GET_CODE (XEXP (x, 0)) == PLUS
1674 && (XEXP (XEXP (x, 0), 0) == virtual_stack_vars_rtx
1675 || XEXP (XEXP (x, 0), 0) == virtual_incoming_args_rtx)
1676 && CONSTANT_ADDRESS_P (XEXP (XEXP (x, 0), 1)))
1677 {
1678 /* This MEM can appear in more than one place,
1679 but its address better not be shared with anything else. */
1680 if (! x->used)
1681 XEXP (x, 0) = copy_rtx_if_shared (XEXP (x, 0));
1682 x->used = 1;
1683 return x;
1684 }
e9a25f70
JL
1685 break;
1686
1687 default:
1688 break;
23b2ce53
RS
1689 }
1690
1691 /* This rtx may not be shared. If it has already been seen,
1692 replace it with a copy of itself. */
1693
1694 if (x->used)
1695 {
1696 register rtx copy;
1697
1698 copy = rtx_alloc (code);
4c9a05bc
RK
1699 bcopy ((char *) x, (char *) copy,
1700 (sizeof (*copy) - sizeof (copy->fld)
1701 + sizeof (copy->fld[0]) * GET_RTX_LENGTH (code)));
23b2ce53
RS
1702 x = copy;
1703 copied = 1;
1704 }
1705 x->used = 1;
1706
1707 /* Now scan the subexpressions recursively.
1708 We can store any replaced subexpressions directly into X
1709 since we know X is not shared! Any vectors in X
1710 must be copied if X was copied. */
1711
1712 format_ptr = GET_RTX_FORMAT (code);
1713
1714 for (i = 0; i < GET_RTX_LENGTH (code); i++)
1715 {
1716 switch (*format_ptr++)
1717 {
1718 case 'e':
1719 XEXP (x, i) = copy_rtx_if_shared (XEXP (x, i));
1720 break;
1721
1722 case 'E':
1723 if (XVEC (x, i) != NULL)
1724 {
1725 register int j;
f0722107 1726 int len = XVECLEN (x, i);
23b2ce53 1727
f0722107 1728 if (copied && len > 0)
ba444f92 1729 XVEC (x, i) = gen_rtvec_vv (len, XVEC (x, i)->elem);
f0722107
RS
1730 for (j = 0; j < len; j++)
1731 XVECEXP (x, i, j) = copy_rtx_if_shared (XVECEXP (x, i, j));
23b2ce53
RS
1732 }
1733 break;
1734 }
1735 }
1736 return x;
1737}
1738
1739/* Clear all the USED bits in X to allow copy_rtx_if_shared to be used
1740 to look for shared sub-parts. */
1741
1742void
1743reset_used_flags (x)
1744 rtx x;
1745{
1746 register int i, j;
1747 register enum rtx_code code;
1748 register char *format_ptr;
23b2ce53
RS
1749
1750 if (x == 0)
1751 return;
1752
1753 code = GET_CODE (x);
1754
9faa82d8 1755 /* These types may be freely shared so we needn't do any resetting
23b2ce53
RS
1756 for them. */
1757
1758 switch (code)
1759 {
1760 case REG:
1761 case QUEUED:
1762 case CONST_INT:
1763 case CONST_DOUBLE:
1764 case SYMBOL_REF:
1765 case CODE_LABEL:
1766 case PC:
1767 case CC0:
1768 return;
1769
1770 case INSN:
1771 case JUMP_INSN:
1772 case CALL_INSN:
1773 case NOTE:
1774 case LABEL_REF:
1775 case BARRIER:
1776 /* The chain of insns is not being copied. */
1777 return;
e9a25f70
JL
1778
1779 default:
1780 break;
23b2ce53
RS
1781 }
1782
1783 x->used = 0;
1784
1785 format_ptr = GET_RTX_FORMAT (code);
1786 for (i = 0; i < GET_RTX_LENGTH (code); i++)
1787 {
1788 switch (*format_ptr++)
1789 {
1790 case 'e':
1791 reset_used_flags (XEXP (x, i));
1792 break;
1793
1794 case 'E':
1795 for (j = 0; j < XVECLEN (x, i); j++)
1796 reset_used_flags (XVECEXP (x, i, j));
1797 break;
1798 }
1799 }
1800}
1801\f
1802/* Copy X if necessary so that it won't be altered by changes in OTHER.
1803 Return X or the rtx for the pseudo reg the value of X was copied into.
1804 OTHER must be valid as a SET_DEST. */
1805
1806rtx
1807make_safe_from (x, other)
1808 rtx x, other;
1809{
1810 while (1)
1811 switch (GET_CODE (other))
1812 {
1813 case SUBREG:
1814 other = SUBREG_REG (other);
1815 break;
1816 case STRICT_LOW_PART:
1817 case SIGN_EXTEND:
1818 case ZERO_EXTEND:
1819 other = XEXP (other, 0);
1820 break;
1821 default:
1822 goto done;
1823 }
1824 done:
1825 if ((GET_CODE (other) == MEM
1826 && ! CONSTANT_P (x)
1827 && GET_CODE (x) != REG
1828 && GET_CODE (x) != SUBREG)
1829 || (GET_CODE (other) == REG
1830 && (REGNO (other) < FIRST_PSEUDO_REGISTER
1831 || reg_mentioned_p (other, x))))
1832 {
1833 rtx temp = gen_reg_rtx (GET_MODE (x));
1834 emit_move_insn (temp, x);
1835 return temp;
1836 }
1837 return x;
1838}
1839\f
1840/* Emission of insns (adding them to the doubly-linked list). */
1841
1842/* Return the first insn of the current sequence or current function. */
1843
1844rtx
1845get_insns ()
1846{
1847 return first_insn;
1848}
1849
1850/* Return the last insn emitted in current sequence or current function. */
1851
1852rtx
1853get_last_insn ()
1854{
1855 return last_insn;
1856}
1857
1858/* Specify a new insn as the last in the chain. */
1859
1860void
1861set_last_insn (insn)
1862 rtx insn;
1863{
1864 if (NEXT_INSN (insn) != 0)
1865 abort ();
1866 last_insn = insn;
1867}
1868
1869/* Return the last insn emitted, even if it is in a sequence now pushed. */
1870
1871rtx
1872get_last_insn_anywhere ()
1873{
1874 struct sequence_stack *stack;
1875 if (last_insn)
1876 return last_insn;
1877 for (stack = sequence_stack; stack; stack = stack->next)
1878 if (stack->last != 0)
1879 return stack->last;
1880 return 0;
1881}
1882
1883/* Return a number larger than any instruction's uid in this function. */
1884
1885int
1886get_max_uid ()
1887{
1888 return cur_insn_uid;
1889}
1890\f
1891/* Return the next insn. If it is a SEQUENCE, return the first insn
1892 of the sequence. */
1893
1894rtx
1895next_insn (insn)
1896 rtx insn;
1897{
1898 if (insn)
1899 {
1900 insn = NEXT_INSN (insn);
1901 if (insn && GET_CODE (insn) == INSN
1902 && GET_CODE (PATTERN (insn)) == SEQUENCE)
1903 insn = XVECEXP (PATTERN (insn), 0, 0);
1904 }
1905
1906 return insn;
1907}
1908
1909/* Return the previous insn. If it is a SEQUENCE, return the last insn
1910 of the sequence. */
1911
1912rtx
1913previous_insn (insn)
1914 rtx insn;
1915{
1916 if (insn)
1917 {
1918 insn = PREV_INSN (insn);
1919 if (insn && GET_CODE (insn) == INSN
1920 && GET_CODE (PATTERN (insn)) == SEQUENCE)
1921 insn = XVECEXP (PATTERN (insn), 0, XVECLEN (PATTERN (insn), 0) - 1);
1922 }
1923
1924 return insn;
1925}
1926
1927/* Return the next insn after INSN that is not a NOTE. This routine does not
1928 look inside SEQUENCEs. */
1929
1930rtx
1931next_nonnote_insn (insn)
1932 rtx insn;
1933{
1934 while (insn)
1935 {
1936 insn = NEXT_INSN (insn);
1937 if (insn == 0 || GET_CODE (insn) != NOTE)
1938 break;
1939 }
1940
1941 return insn;
1942}
1943
1944/* Return the previous insn before INSN that is not a NOTE. This routine does
1945 not look inside SEQUENCEs. */
1946
1947rtx
1948prev_nonnote_insn (insn)
1949 rtx insn;
1950{
1951 while (insn)
1952 {
1953 insn = PREV_INSN (insn);
1954 if (insn == 0 || GET_CODE (insn) != NOTE)
1955 break;
1956 }
1957
1958 return insn;
1959}
1960
1961/* Return the next INSN, CALL_INSN or JUMP_INSN after INSN;
1962 or 0, if there is none. This routine does not look inside
0f41302f 1963 SEQUENCEs. */
23b2ce53
RS
1964
1965rtx
1966next_real_insn (insn)
1967 rtx insn;
1968{
1969 while (insn)
1970 {
1971 insn = NEXT_INSN (insn);
1972 if (insn == 0 || GET_CODE (insn) == INSN
1973 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN)
1974 break;
1975 }
1976
1977 return insn;
1978}
1979
1980/* Return the last INSN, CALL_INSN or JUMP_INSN before INSN;
1981 or 0, if there is none. This routine does not look inside
1982 SEQUENCEs. */
1983
1984rtx
1985prev_real_insn (insn)
1986 rtx insn;
1987{
1988 while (insn)
1989 {
1990 insn = PREV_INSN (insn);
1991 if (insn == 0 || GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
1992 || GET_CODE (insn) == JUMP_INSN)
1993 break;
1994 }
1995
1996 return insn;
1997}
1998
1999/* Find the next insn after INSN that really does something. This routine
2000 does not look inside SEQUENCEs. Until reload has completed, this is the
2001 same as next_real_insn. */
2002
2003rtx
2004next_active_insn (insn)
2005 rtx insn;
2006{
2007 while (insn)
2008 {
2009 insn = NEXT_INSN (insn);
2010 if (insn == 0
2011 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN
2012 || (GET_CODE (insn) == INSN
2013 && (! reload_completed
2014 || (GET_CODE (PATTERN (insn)) != USE
2015 && GET_CODE (PATTERN (insn)) != CLOBBER))))
2016 break;
2017 }
2018
2019 return insn;
2020}
2021
2022/* Find the last insn before INSN that really does something. This routine
2023 does not look inside SEQUENCEs. Until reload has completed, this is the
2024 same as prev_real_insn. */
2025
2026rtx
2027prev_active_insn (insn)
2028 rtx insn;
2029{
2030 while (insn)
2031 {
2032 insn = PREV_INSN (insn);
2033 if (insn == 0
2034 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN
2035 || (GET_CODE (insn) == INSN
2036 && (! reload_completed
2037 || (GET_CODE (PATTERN (insn)) != USE
2038 && GET_CODE (PATTERN (insn)) != CLOBBER))))
2039 break;
2040 }
2041
2042 return insn;
2043}
2044
2045/* Return the next CODE_LABEL after the insn INSN, or 0 if there is none. */
2046
2047rtx
2048next_label (insn)
2049 rtx insn;
2050{
2051 while (insn)
2052 {
2053 insn = NEXT_INSN (insn);
2054 if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
2055 break;
2056 }
2057
2058 return insn;
2059}
2060
2061/* Return the last CODE_LABEL before the insn INSN, or 0 if there is none. */
2062
2063rtx
2064prev_label (insn)
2065 rtx insn;
2066{
2067 while (insn)
2068 {
2069 insn = PREV_INSN (insn);
2070 if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
2071 break;
2072 }
2073
2074 return insn;
2075}
2076\f
2077#ifdef HAVE_cc0
c572e5ba
JVA
2078/* INSN uses CC0 and is being moved into a delay slot. Set up REG_CC_SETTER
2079 and REG_CC_USER notes so we can find it. */
2080
2081void
2082link_cc0_insns (insn)
2083 rtx insn;
2084{
2085 rtx user = next_nonnote_insn (insn);
2086
2087 if (GET_CODE (user) == INSN && GET_CODE (PATTERN (user)) == SEQUENCE)
2088 user = XVECEXP (PATTERN (user), 0, 0);
2089
2090 REG_NOTES (user) = gen_rtx (INSN_LIST, REG_CC_SETTER, insn,
2091 REG_NOTES (user));
2092 REG_NOTES (insn) = gen_rtx (INSN_LIST, REG_CC_USER, user, REG_NOTES (insn));
2093}
2094
23b2ce53
RS
2095/* Return the next insn that uses CC0 after INSN, which is assumed to
2096 set it. This is the inverse of prev_cc0_setter (i.e., prev_cc0_setter
2097 applied to the result of this function should yield INSN).
2098
2099 Normally, this is simply the next insn. However, if a REG_CC_USER note
2100 is present, it contains the insn that uses CC0.
2101
2102 Return 0 if we can't find the insn. */
2103
2104rtx
2105next_cc0_user (insn)
2106 rtx insn;
2107{
906c4e36 2108 rtx note = find_reg_note (insn, REG_CC_USER, NULL_RTX);
23b2ce53
RS
2109
2110 if (note)
2111 return XEXP (note, 0);
2112
2113 insn = next_nonnote_insn (insn);
2114 if (insn && GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
2115 insn = XVECEXP (PATTERN (insn), 0, 0);
2116
2117 if (insn && GET_RTX_CLASS (GET_CODE (insn)) == 'i'
2118 && reg_mentioned_p (cc0_rtx, PATTERN (insn)))
2119 return insn;
2120
2121 return 0;
2122}
2123
2124/* Find the insn that set CC0 for INSN. Unless INSN has a REG_CC_SETTER
2125 note, it is the previous insn. */
2126
2127rtx
2128prev_cc0_setter (insn)
2129 rtx insn;
2130{
906c4e36 2131 rtx note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
23b2ce53
RS
2132 rtx link;
2133
2134 if (note)
2135 return XEXP (note, 0);
2136
2137 insn = prev_nonnote_insn (insn);
2138 if (! sets_cc0_p (PATTERN (insn)))
2139 abort ();
2140
2141 return insn;
2142}
2143#endif
2144\f
2145/* Try splitting insns that can be split for better scheduling.
2146 PAT is the pattern which might split.
2147 TRIAL is the insn providing PAT.
11147ebe 2148 LAST is non-zero if we should return the last insn of the sequence produced.
23b2ce53
RS
2149
2150 If this routine succeeds in splitting, it returns the first or last
11147ebe 2151 replacement insn depending on the value of LAST. Otherwise, it
23b2ce53
RS
2152 returns TRIAL. If the insn to be returned can be split, it will be. */
2153
2154rtx
11147ebe 2155try_split (pat, trial, last)
23b2ce53 2156 rtx pat, trial;
11147ebe 2157 int last;
23b2ce53
RS
2158{
2159 rtx before = PREV_INSN (trial);
2160 rtx after = NEXT_INSN (trial);
2161 rtx seq = split_insns (pat, trial);
2162 int has_barrier = 0;
2163 rtx tem;
2164
2165 /* If we are splitting a JUMP_INSN, it might be followed by a BARRIER.
2166 We may need to handle this specially. */
2167 if (after && GET_CODE (after) == BARRIER)
2168 {
2169 has_barrier = 1;
2170 after = NEXT_INSN (after);
2171 }
2172
2173 if (seq)
2174 {
2175 /* SEQ can either be a SEQUENCE or the pattern of a single insn.
2176 The latter case will normally arise only when being done so that
2177 it, in turn, will be split (SFmode on the 29k is an example). */
2178 if (GET_CODE (seq) == SEQUENCE)
2179 {
2180 /* If we are splitting a JUMP_INSN, look for the JUMP_INSN in
2181 SEQ and copy our JUMP_LABEL to it. If JUMP_LABEL is non-zero,
2182 increment the usage count so we don't delete the label. */
2183 int i;
2184
2185 if (GET_CODE (trial) == JUMP_INSN)
2186 for (i = XVECLEN (seq, 0) - 1; i >= 0; i--)
2187 if (GET_CODE (XVECEXP (seq, 0, i)) == JUMP_INSN)
2188 {
2189 JUMP_LABEL (XVECEXP (seq, 0, i)) = JUMP_LABEL (trial);
2190
2191 if (JUMP_LABEL (trial))
2192 LABEL_NUSES (JUMP_LABEL (trial))++;
2193 }
2194
2195 tem = emit_insn_after (seq, before);
2196
2197 delete_insn (trial);
2198 if (has_barrier)
2199 emit_barrier_after (tem);
11147ebe
RK
2200
2201 /* Recursively call try_split for each new insn created; by the
2202 time control returns here that insn will be fully split, so
2203 set LAST and continue from the insn after the one returned.
f4a3cd05
RK
2204 We can't use next_active_insn here since AFTER may be a note.
2205 Ignore deleted insns, which can be occur if not optimizing. */
11147ebe
RK
2206 for (tem = NEXT_INSN (before); tem != after;
2207 tem = NEXT_INSN (tem))
f4a3cd05
RK
2208 if (! INSN_DELETED_P (tem))
2209 tem = try_split (PATTERN (tem), tem, 1);
23b2ce53
RS
2210 }
2211 /* Avoid infinite loop if the result matches the original pattern. */
2212 else if (rtx_equal_p (seq, pat))
2213 return trial;
2214 else
2215 {
2216 PATTERN (trial) = seq;
2217 INSN_CODE (trial) = -1;
11147ebe 2218 try_split (seq, trial, last);
23b2ce53
RS
2219 }
2220
11147ebe
RK
2221 /* Return either the first or the last insn, depending on which was
2222 requested. */
2223 return last ? prev_active_insn (after) : next_active_insn (before);
23b2ce53
RS
2224 }
2225
2226 return trial;
2227}
2228\f
2229/* Make and return an INSN rtx, initializing all its slots.
4b1f5e8c 2230 Store PATTERN in the pattern slots. */
23b2ce53
RS
2231
2232rtx
4b1f5e8c 2233make_insn_raw (pattern)
23b2ce53 2234 rtx pattern;
23b2ce53
RS
2235{
2236 register rtx insn;
2237
43127294
RK
2238 /* If in RTL generation phase, see if FREE_INSN can be used. */
2239 if (free_insn != 0 && rtx_equal_function_value_matters)
2240 {
2241 insn = free_insn;
2242 free_insn = NEXT_INSN (free_insn);
2243 PUT_CODE (insn, INSN);
2244 }
2245 else
2246 insn = rtx_alloc (INSN);
23b2ce53 2247
43127294 2248 INSN_UID (insn) = cur_insn_uid++;
23b2ce53
RS
2249 PATTERN (insn) = pattern;
2250 INSN_CODE (insn) = -1;
1632afca
RS
2251 LOG_LINKS (insn) = NULL;
2252 REG_NOTES (insn) = NULL;
23b2ce53
RS
2253
2254 return insn;
2255}
2256
2257/* Like `make_insn' but make a JUMP_INSN instead of an insn. */
2258
2259static rtx
4b1f5e8c 2260make_jump_insn_raw (pattern)
23b2ce53 2261 rtx pattern;
23b2ce53
RS
2262{
2263 register rtx insn;
2264
4b1f5e8c 2265 insn = rtx_alloc (JUMP_INSN);
1632afca 2266 INSN_UID (insn) = cur_insn_uid++;
23b2ce53
RS
2267
2268 PATTERN (insn) = pattern;
2269 INSN_CODE (insn) = -1;
1632afca
RS
2270 LOG_LINKS (insn) = NULL;
2271 REG_NOTES (insn) = NULL;
2272 JUMP_LABEL (insn) = NULL;
23b2ce53
RS
2273
2274 return insn;
2275}
aff507f4
RK
2276
2277/* Like `make_insn' but make a CALL_INSN instead of an insn. */
2278
2279static rtx
2280make_call_insn_raw (pattern)
2281 rtx pattern;
2282{
2283 register rtx insn;
2284
2285 insn = rtx_alloc (CALL_INSN);
2286 INSN_UID (insn) = cur_insn_uid++;
2287
2288 PATTERN (insn) = pattern;
2289 INSN_CODE (insn) = -1;
2290 LOG_LINKS (insn) = NULL;
2291 REG_NOTES (insn) = NULL;
2292 CALL_INSN_FUNCTION_USAGE (insn) = NULL;
2293
2294 return insn;
2295}
23b2ce53
RS
2296\f
2297/* Add INSN to the end of the doubly-linked list.
2298 INSN may be an INSN, JUMP_INSN, CALL_INSN, CODE_LABEL, BARRIER or NOTE. */
2299
2300void
2301add_insn (insn)
2302 register rtx insn;
2303{
2304 PREV_INSN (insn) = last_insn;
2305 NEXT_INSN (insn) = 0;
2306
2307 if (NULL != last_insn)
2308 NEXT_INSN (last_insn) = insn;
2309
2310 if (NULL == first_insn)
2311 first_insn = insn;
2312
2313 last_insn = insn;
2314}
2315
a0ae8e8d
RK
2316/* Add INSN into the doubly-linked list after insn AFTER. This and
2317 the next should be the only functions called to insert an insn once
ba213285 2318 delay slots have been filled since only they know how to update a
a0ae8e8d 2319 SEQUENCE. */
23b2ce53
RS
2320
2321void
2322add_insn_after (insn, after)
2323 rtx insn, after;
2324{
2325 rtx next = NEXT_INSN (after);
2326
6782074d 2327 if (optimize && INSN_DELETED_P (after))
ba213285
RK
2328 abort ();
2329
23b2ce53
RS
2330 NEXT_INSN (insn) = next;
2331 PREV_INSN (insn) = after;
2332
2333 if (next)
2334 {
2335 PREV_INSN (next) = insn;
2336 if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == SEQUENCE)
2337 PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = insn;
2338 }
2339 else if (last_insn == after)
2340 last_insn = insn;
2341 else
2342 {
2343 struct sequence_stack *stack = sequence_stack;
2344 /* Scan all pending sequences too. */
2345 for (; stack; stack = stack->next)
2346 if (after == stack->last)
fef0509b
RK
2347 {
2348 stack->last = insn;
2349 break;
2350 }
a0ae8e8d
RK
2351
2352 if (stack == 0)
2353 abort ();
23b2ce53
RS
2354 }
2355
2356 NEXT_INSN (after) = insn;
2357 if (GET_CODE (after) == INSN && GET_CODE (PATTERN (after)) == SEQUENCE)
2358 {
2359 rtx sequence = PATTERN (after);
2360 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2361 }
2362}
2363
a0ae8e8d
RK
2364/* Add INSN into the doubly-linked list before insn BEFORE. This and
2365 the previous should be the only functions called to insert an insn once
ba213285 2366 delay slots have been filled since only they know how to update a
a0ae8e8d
RK
2367 SEQUENCE. */
2368
2369void
2370add_insn_before (insn, before)
2371 rtx insn, before;
2372{
2373 rtx prev = PREV_INSN (before);
2374
6782074d 2375 if (optimize && INSN_DELETED_P (before))
ba213285
RK
2376 abort ();
2377
a0ae8e8d
RK
2378 PREV_INSN (insn) = prev;
2379 NEXT_INSN (insn) = before;
2380
2381 if (prev)
2382 {
2383 NEXT_INSN (prev) = insn;
2384 if (GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == SEQUENCE)
2385 {
2386 rtx sequence = PATTERN (prev);
2387 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2388 }
2389 }
2390 else if (first_insn == before)
2391 first_insn = insn;
2392 else
2393 {
2394 struct sequence_stack *stack = sequence_stack;
2395 /* Scan all pending sequences too. */
2396 for (; stack; stack = stack->next)
2397 if (before == stack->first)
fef0509b
RK
2398 {
2399 stack->first = insn;
2400 break;
2401 }
a0ae8e8d
RK
2402
2403 if (stack == 0)
2404 abort ();
2405 }
2406
2407 PREV_INSN (before) = insn;
2408 if (GET_CODE (before) == INSN && GET_CODE (PATTERN (before)) == SEQUENCE)
2409 PREV_INSN (XVECEXP (PATTERN (before), 0, 0)) = insn;
2410}
2411
23b2ce53
RS
2412/* Delete all insns made since FROM.
2413 FROM becomes the new last instruction. */
2414
2415void
2416delete_insns_since (from)
2417 rtx from;
2418{
2419 if (from == 0)
2420 first_insn = 0;
2421 else
2422 NEXT_INSN (from) = 0;
2423 last_insn = from;
2424}
2425
5dab5552
MS
2426/* This function is deprecated, please use sequences instead.
2427
2428 Move a consecutive bunch of insns to a different place in the chain.
23b2ce53
RS
2429 The insns to be moved are those between FROM and TO.
2430 They are moved to a new position after the insn AFTER.
2431 AFTER must not be FROM or TO or any insn in between.
2432
2433 This function does not know about SEQUENCEs and hence should not be
2434 called after delay-slot filling has been done. */
2435
2436void
2437reorder_insns (from, to, after)
2438 rtx from, to, after;
2439{
2440 /* Splice this bunch out of where it is now. */
2441 if (PREV_INSN (from))
2442 NEXT_INSN (PREV_INSN (from)) = NEXT_INSN (to);
2443 if (NEXT_INSN (to))
2444 PREV_INSN (NEXT_INSN (to)) = PREV_INSN (from);
2445 if (last_insn == to)
2446 last_insn = PREV_INSN (from);
2447 if (first_insn == from)
2448 first_insn = NEXT_INSN (to);
2449
2450 /* Make the new neighbors point to it and it to them. */
2451 if (NEXT_INSN (after))
2452 PREV_INSN (NEXT_INSN (after)) = to;
2453
2454 NEXT_INSN (to) = NEXT_INSN (after);
2455 PREV_INSN (from) = after;
2456 NEXT_INSN (after) = from;
2457 if (after == last_insn)
2458 last_insn = to;
2459}
2460
2461/* Return the line note insn preceding INSN. */
2462
2463static rtx
2464find_line_note (insn)
2465 rtx insn;
2466{
2467 if (no_line_numbers)
2468 return 0;
2469
2470 for (; insn; insn = PREV_INSN (insn))
2471 if (GET_CODE (insn) == NOTE
2472 && NOTE_LINE_NUMBER (insn) >= 0)
2473 break;
2474
2475 return insn;
2476}
2477
2478/* Like reorder_insns, but inserts line notes to preserve the line numbers
2479 of the moved insns when debugging. This may insert a note between AFTER
2480 and FROM, and another one after TO. */
2481
2482void
2483reorder_insns_with_line_notes (from, to, after)
2484 rtx from, to, after;
2485{
2486 rtx from_line = find_line_note (from);
2487 rtx after_line = find_line_note (after);
2488
2489 reorder_insns (from, to, after);
2490
2491 if (from_line == after_line)
2492 return;
2493
2494 if (from_line)
2495 emit_line_note_after (NOTE_SOURCE_FILE (from_line),
2496 NOTE_LINE_NUMBER (from_line),
2497 after);
2498 if (after_line)
2499 emit_line_note_after (NOTE_SOURCE_FILE (after_line),
2500 NOTE_LINE_NUMBER (after_line),
2501 to);
2502}
2503\f
2504/* Emit an insn of given code and pattern
2505 at a specified place within the doubly-linked list. */
2506
2507/* Make an instruction with body PATTERN
2508 and output it before the instruction BEFORE. */
2509
2510rtx
2511emit_insn_before (pattern, before)
2512 register rtx pattern, before;
2513{
2514 register rtx insn = before;
2515
2516 if (GET_CODE (pattern) == SEQUENCE)
2517 {
2518 register int i;
2519
2520 for (i = 0; i < XVECLEN (pattern, 0); i++)
2521 {
2522 insn = XVECEXP (pattern, 0, i);
a0ae8e8d 2523 add_insn_before (insn, before);
23b2ce53
RS
2524 }
2525 if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
2526 sequence_result[XVECLEN (pattern, 0)] = pattern;
2527 }
2528 else
2529 {
4b1f5e8c 2530 insn = make_insn_raw (pattern);
a0ae8e8d 2531 add_insn_before (insn, before);
23b2ce53
RS
2532 }
2533
2534 return insn;
2535}
2536
2537/* Make an instruction with body PATTERN and code JUMP_INSN
2538 and output it before the instruction BEFORE. */
2539
2540rtx
2541emit_jump_insn_before (pattern, before)
2542 register rtx pattern, before;
2543{
2544 register rtx insn;
2545
2546 if (GET_CODE (pattern) == SEQUENCE)
2547 insn = emit_insn_before (pattern, before);
2548 else
2549 {
85cf32bc 2550 insn = make_jump_insn_raw (pattern);
a0ae8e8d 2551 add_insn_before (insn, before);
23b2ce53
RS
2552 }
2553
2554 return insn;
2555}
2556
2557/* Make an instruction with body PATTERN and code CALL_INSN
2558 and output it before the instruction BEFORE. */
2559
2560rtx
2561emit_call_insn_before (pattern, before)
2562 register rtx pattern, before;
2563{
aff507f4
RK
2564 register rtx insn;
2565
2566 if (GET_CODE (pattern) == SEQUENCE)
2567 insn = emit_insn_before (pattern, before);
2568 else
2569 {
2570 insn = make_call_insn_raw (pattern);
a0ae8e8d 2571 add_insn_before (insn, before);
aff507f4
RK
2572 PUT_CODE (insn, CALL_INSN);
2573 }
2574
23b2ce53
RS
2575 return insn;
2576}
2577
2578/* Make an insn of code BARRIER
2579 and output it before the insn AFTER. */
2580
2581rtx
2582emit_barrier_before (before)
2583 register rtx before;
2584{
2585 register rtx insn = rtx_alloc (BARRIER);
2586
2587 INSN_UID (insn) = cur_insn_uid++;
2588
a0ae8e8d 2589 add_insn_before (insn, before);
23b2ce53
RS
2590 return insn;
2591}
2592
2593/* Emit a note of subtype SUBTYPE before the insn BEFORE. */
2594
2595rtx
2596emit_note_before (subtype, before)
2597 int subtype;
2598 rtx before;
2599{
2600 register rtx note = rtx_alloc (NOTE);
2601 INSN_UID (note) = cur_insn_uid++;
2602 NOTE_SOURCE_FILE (note) = 0;
2603 NOTE_LINE_NUMBER (note) = subtype;
2604
a0ae8e8d 2605 add_insn_before (note, before);
23b2ce53
RS
2606 return note;
2607}
2608\f
2609/* Make an insn of code INSN with body PATTERN
2610 and output it after the insn AFTER. */
2611
2612rtx
2613emit_insn_after (pattern, after)
2614 register rtx pattern, after;
2615{
2616 register rtx insn = after;
2617
2618 if (GET_CODE (pattern) == SEQUENCE)
2619 {
2620 register int i;
2621
2622 for (i = 0; i < XVECLEN (pattern, 0); i++)
2623 {
2624 insn = XVECEXP (pattern, 0, i);
2625 add_insn_after (insn, after);
2626 after = insn;
2627 }
2628 if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
2629 sequence_result[XVECLEN (pattern, 0)] = pattern;
2630 }
2631 else
2632 {
4b1f5e8c 2633 insn = make_insn_raw (pattern);
23b2ce53
RS
2634 add_insn_after (insn, after);
2635 }
2636
2637 return insn;
2638}
2639
255680cf
RK
2640/* Similar to emit_insn_after, except that line notes are to be inserted so
2641 as to act as if this insn were at FROM. */
2642
2643void
2644emit_insn_after_with_line_notes (pattern, after, from)
2645 rtx pattern, after, from;
2646{
2647 rtx from_line = find_line_note (from);
2648 rtx after_line = find_line_note (after);
2649 rtx insn = emit_insn_after (pattern, after);
2650
2651 if (from_line)
2652 emit_line_note_after (NOTE_SOURCE_FILE (from_line),
2653 NOTE_LINE_NUMBER (from_line),
2654 after);
2655
2656 if (after_line)
2657 emit_line_note_after (NOTE_SOURCE_FILE (after_line),
2658 NOTE_LINE_NUMBER (after_line),
2659 insn);
2660}
2661
23b2ce53
RS
2662/* Make an insn of code JUMP_INSN with body PATTERN
2663 and output it after the insn AFTER. */
2664
2665rtx
2666emit_jump_insn_after (pattern, after)
2667 register rtx pattern, after;
2668{
2669 register rtx insn;
2670
2671 if (GET_CODE (pattern) == SEQUENCE)
2672 insn = emit_insn_after (pattern, after);
2673 else
2674 {
85cf32bc 2675 insn = make_jump_insn_raw (pattern);
23b2ce53
RS
2676 add_insn_after (insn, after);
2677 }
2678
2679 return insn;
2680}
2681
2682/* Make an insn of code BARRIER
2683 and output it after the insn AFTER. */
2684
2685rtx
2686emit_barrier_after (after)
2687 register rtx after;
2688{
2689 register rtx insn = rtx_alloc (BARRIER);
2690
2691 INSN_UID (insn) = cur_insn_uid++;
2692
2693 add_insn_after (insn, after);
2694 return insn;
2695}
2696
2697/* Emit the label LABEL after the insn AFTER. */
2698
2699rtx
2700emit_label_after (label, after)
2701 rtx label, after;
2702{
2703 /* This can be called twice for the same label
2704 as a result of the confusion that follows a syntax error!
2705 So make it harmless. */
2706 if (INSN_UID (label) == 0)
2707 {
2708 INSN_UID (label) = cur_insn_uid++;
2709 add_insn_after (label, after);
2710 }
2711
2712 return label;
2713}
2714
2715/* Emit a note of subtype SUBTYPE after the insn AFTER. */
2716
2717rtx
2718emit_note_after (subtype, after)
2719 int subtype;
2720 rtx after;
2721{
2722 register rtx note = rtx_alloc (NOTE);
2723 INSN_UID (note) = cur_insn_uid++;
2724 NOTE_SOURCE_FILE (note) = 0;
2725 NOTE_LINE_NUMBER (note) = subtype;
2726 add_insn_after (note, after);
2727 return note;
2728}
2729
2730/* Emit a line note for FILE and LINE after the insn AFTER. */
2731
2732rtx
2733emit_line_note_after (file, line, after)
2734 char *file;
2735 int line;
2736 rtx after;
2737{
2738 register rtx note;
2739
2740 if (no_line_numbers && line > 0)
2741 {
2742 cur_insn_uid++;
2743 return 0;
2744 }
2745
2746 note = rtx_alloc (NOTE);
2747 INSN_UID (note) = cur_insn_uid++;
2748 NOTE_SOURCE_FILE (note) = file;
2749 NOTE_LINE_NUMBER (note) = line;
2750 add_insn_after (note, after);
2751 return note;
2752}
2753\f
2754/* Make an insn of code INSN with pattern PATTERN
2755 and add it to the end of the doubly-linked list.
2756 If PATTERN is a SEQUENCE, take the elements of it
2757 and emit an insn for each element.
2758
2759 Returns the last insn emitted. */
2760
2761rtx
2762emit_insn (pattern)
2763 rtx pattern;
2764{
2765 rtx insn = last_insn;
2766
2767 if (GET_CODE (pattern) == SEQUENCE)
2768 {
2769 register int i;
2770
2771 for (i = 0; i < XVECLEN (pattern, 0); i++)
2772 {
2773 insn = XVECEXP (pattern, 0, i);
2774 add_insn (insn);
2775 }
2776 if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
2777 sequence_result[XVECLEN (pattern, 0)] = pattern;
2778 }
2779 else
2780 {
4b1f5e8c 2781 insn = make_insn_raw (pattern);
23b2ce53
RS
2782 add_insn (insn);
2783 }
2784
2785 return insn;
2786}
2787
2788/* Emit the insns in a chain starting with INSN.
2789 Return the last insn emitted. */
2790
2791rtx
2792emit_insns (insn)
2793 rtx insn;
2794{
2795 rtx last = 0;
2796
2797 while (insn)
2798 {
2799 rtx next = NEXT_INSN (insn);
2800 add_insn (insn);
2801 last = insn;
2802 insn = next;
2803 }
2804
2805 return last;
2806}
2807
2808/* Emit the insns in a chain starting with INSN and place them in front of
2809 the insn BEFORE. Return the last insn emitted. */
2810
2811rtx
2812emit_insns_before (insn, before)
2813 rtx insn;
2814 rtx before;
2815{
2816 rtx last = 0;
2817
2818 while (insn)
2819 {
2820 rtx next = NEXT_INSN (insn);
a0ae8e8d 2821 add_insn_before (insn, before);
23b2ce53
RS
2822 last = insn;
2823 insn = next;
2824 }
2825
2826 return last;
2827}
2828
e0a5c5eb
RS
2829/* Emit the insns in a chain starting with FIRST and place them in back of
2830 the insn AFTER. Return the last insn emitted. */
2831
2832rtx
2833emit_insns_after (first, after)
2834 register rtx first;
2835 register rtx after;
2836{
2837 register rtx last;
2838 register rtx after_after;
2839
2840 if (!after)
2841 abort ();
2842
2843 if (!first)
2844 return first;
2845
2846 for (last = first; NEXT_INSN (last); last = NEXT_INSN (last))
2847 continue;
2848
2849 after_after = NEXT_INSN (after);
2850
2851 NEXT_INSN (after) = first;
2852 PREV_INSN (first) = after;
2853 NEXT_INSN (last) = after_after;
2854 if (after_after)
2855 PREV_INSN (after_after) = last;
2856
c4d990db
RS
2857 if (after == last_insn)
2858 last_insn = last;
e0a5c5eb
RS
2859 return last;
2860}
2861
23b2ce53
RS
2862/* Make an insn of code JUMP_INSN with pattern PATTERN
2863 and add it to the end of the doubly-linked list. */
2864
2865rtx
2866emit_jump_insn (pattern)
2867 rtx pattern;
2868{
2869 if (GET_CODE (pattern) == SEQUENCE)
2870 return emit_insn (pattern);
2871 else
2872 {
85cf32bc 2873 register rtx insn = make_jump_insn_raw (pattern);
23b2ce53
RS
2874 add_insn (insn);
2875 return insn;
2876 }
2877}
2878
2879/* Make an insn of code CALL_INSN with pattern PATTERN
2880 and add it to the end of the doubly-linked list. */
2881
2882rtx
2883emit_call_insn (pattern)
2884 rtx pattern;
2885{
2886 if (GET_CODE (pattern) == SEQUENCE)
2887 return emit_insn (pattern);
2888 else
2889 {
aff507f4 2890 register rtx insn = make_call_insn_raw (pattern);
23b2ce53
RS
2891 add_insn (insn);
2892 PUT_CODE (insn, CALL_INSN);
2893 return insn;
2894 }
2895}
2896
2897/* Add the label LABEL to the end of the doubly-linked list. */
2898
2899rtx
2900emit_label (label)
2901 rtx label;
2902{
2903 /* This can be called twice for the same label
2904 as a result of the confusion that follows a syntax error!
2905 So make it harmless. */
2906 if (INSN_UID (label) == 0)
2907 {
2908 INSN_UID (label) = cur_insn_uid++;
2909 add_insn (label);
2910 }
2911 return label;
2912}
2913
2914/* Make an insn of code BARRIER
2915 and add it to the end of the doubly-linked list. */
2916
2917rtx
2918emit_barrier ()
2919{
2920 register rtx barrier = rtx_alloc (BARRIER);
2921 INSN_UID (barrier) = cur_insn_uid++;
2922 add_insn (barrier);
2923 return barrier;
2924}
2925
2926/* Make an insn of code NOTE
2927 with data-fields specified by FILE and LINE
2928 and add it to the end of the doubly-linked list,
2929 but only if line-numbers are desired for debugging info. */
2930
2931rtx
2932emit_line_note (file, line)
2933 char *file;
2934 int line;
2935{
ca695ac9
JB
2936 if (output_bytecode)
2937 {
2938 /* FIXME: for now we do nothing, but eventually we will have to deal with
2939 debugging information. */
2940 return 0;
2941 }
2942
23b2ce53
RS
2943 emit_filename = file;
2944 emit_lineno = line;
2945
2946#if 0
2947 if (no_line_numbers)
2948 return 0;
2949#endif
2950
2951 return emit_note (file, line);
2952}
2953
2954/* Make an insn of code NOTE
2955 with data-fields specified by FILE and LINE
2956 and add it to the end of the doubly-linked list.
2957 If it is a line-number NOTE, omit it if it matches the previous one. */
2958
2959rtx
2960emit_note (file, line)
2961 char *file;
2962 int line;
2963{
2964 register rtx note;
2965
2966 if (line > 0)
2967 {
2968 if (file && last_filename && !strcmp (file, last_filename)
2969 && line == last_linenum)
2970 return 0;
2971 last_filename = file;
2972 last_linenum = line;
2973 }
2974
2975 if (no_line_numbers && line > 0)
2976 {
2977 cur_insn_uid++;
2978 return 0;
2979 }
2980
2981 note = rtx_alloc (NOTE);
2982 INSN_UID (note) = cur_insn_uid++;
2983 NOTE_SOURCE_FILE (note) = file;
2984 NOTE_LINE_NUMBER (note) = line;
2985 add_insn (note);
2986 return note;
2987}
2988
2989/* Emit a NOTE, and don't omit it even if LINE it the previous note. */
2990
2991rtx
2992emit_line_note_force (file, line)
2993 char *file;
2994 int line;
2995{
2996 last_linenum = -1;
2997 return emit_line_note (file, line);
2998}
2999
3000/* Cause next statement to emit a line note even if the line number
3001 has not changed. This is used at the beginning of a function. */
3002
3003void
3004force_next_line_note ()
3005{
3006 last_linenum = -1;
3007}
3008\f
3009/* Return an indication of which type of insn should have X as a body.
3010 The value is CODE_LABEL, INSN, CALL_INSN or JUMP_INSN. */
3011
3012enum rtx_code
3013classify_insn (x)
3014 rtx x;
3015{
3016 if (GET_CODE (x) == CODE_LABEL)
3017 return CODE_LABEL;
3018 if (GET_CODE (x) == CALL)
3019 return CALL_INSN;
3020 if (GET_CODE (x) == RETURN)
3021 return JUMP_INSN;
3022 if (GET_CODE (x) == SET)
3023 {
3024 if (SET_DEST (x) == pc_rtx)
3025 return JUMP_INSN;
3026 else if (GET_CODE (SET_SRC (x)) == CALL)
3027 return CALL_INSN;
3028 else
3029 return INSN;
3030 }
3031 if (GET_CODE (x) == PARALLEL)
3032 {
3033 register int j;
3034 for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
3035 if (GET_CODE (XVECEXP (x, 0, j)) == CALL)
3036 return CALL_INSN;
3037 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
3038 && SET_DEST (XVECEXP (x, 0, j)) == pc_rtx)
3039 return JUMP_INSN;
3040 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
3041 && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == CALL)
3042 return CALL_INSN;
3043 }
3044 return INSN;
3045}
3046
3047/* Emit the rtl pattern X as an appropriate kind of insn.
3048 If X is a label, it is simply added into the insn chain. */
3049
3050rtx
3051emit (x)
3052 rtx x;
3053{
3054 enum rtx_code code = classify_insn (x);
3055
3056 if (code == CODE_LABEL)
3057 return emit_label (x);
3058 else if (code == INSN)
3059 return emit_insn (x);
3060 else if (code == JUMP_INSN)
3061 {
3062 register rtx insn = emit_jump_insn (x);
3063 if (simplejump_p (insn) || GET_CODE (x) == RETURN)
3064 return emit_barrier ();
3065 return insn;
3066 }
3067 else if (code == CALL_INSN)
3068 return emit_call_insn (x);
3069 else
3070 abort ();
3071}
3072\f
3073/* Begin emitting insns to a sequence which can be packaged in an RTL_EXPR. */
3074
3075void
3076start_sequence ()
3077{
3078 struct sequence_stack *tem;
3079
3080 if (sequence_element_free_list)
3081 {
3082 /* Reuse a previously-saved struct sequence_stack. */
3083 tem = sequence_element_free_list;
3084 sequence_element_free_list = tem->next;
3085 }
3086 else
3087 tem = (struct sequence_stack *) permalloc (sizeof (struct sequence_stack));
3088
3089 tem->next = sequence_stack;
3090 tem->first = first_insn;
3091 tem->last = last_insn;
3ae24368 3092 tem->sequence_rtl_expr = sequence_rtl_expr;
23b2ce53
RS
3093
3094 sequence_stack = tem;
3095
3096 first_insn = 0;
3097 last_insn = 0;
3098}
3099
a25c7971
RK
3100/* Similarly, but indicate that this sequence will be placed in
3101 T, an RTL_EXPR. */
3102
3103void
3104start_sequence_for_rtl_expr (t)
3105 tree t;
3106{
3107 start_sequence ();
3108
3109 sequence_rtl_expr = t;
3110}
3111
23b2ce53
RS
3112/* Set up the insn chain starting with FIRST
3113 as the current sequence, saving the previously current one. */
3114
3115void
3116push_to_sequence (first)
3117 rtx first;
3118{
3119 rtx last;
3120
3121 start_sequence ();
3122
3123 for (last = first; last && NEXT_INSN (last); last = NEXT_INSN (last));
3124
3125 first_insn = first;
3126 last_insn = last;
3127}
3128
f15ae3a1
TW
3129/* Set up the outer-level insn chain
3130 as the current sequence, saving the previously current one. */
3131
3132void
3133push_topmost_sequence ()
3134{
3135 struct sequence_stack *stack, *top;
3136
3137 start_sequence ();
3138
3139 for (stack = sequence_stack; stack; stack = stack->next)
3140 top = stack;
3141
3142 first_insn = top->first;
3143 last_insn = top->last;
629a4238 3144 sequence_rtl_expr = top->sequence_rtl_expr;
f15ae3a1
TW
3145}
3146
3147/* After emitting to the outer-level insn chain, update the outer-level
3148 insn chain, and restore the previous saved state. */
3149
3150void
3151pop_topmost_sequence ()
3152{
3153 struct sequence_stack *stack, *top;
3154
3155 for (stack = sequence_stack; stack; stack = stack->next)
3156 top = stack;
3157
3158 top->first = first_insn;
3159 top->last = last_insn;
3ae24368 3160 /* ??? Why don't we save sequence_rtl_expr here? */
f15ae3a1
TW
3161
3162 end_sequence ();
3163}
3164
23b2ce53
RS
3165/* After emitting to a sequence, restore previous saved state.
3166
3167 To get the contents of the sequence just made,
3168 you must call `gen_sequence' *before* calling here. */
3169
3170void
3171end_sequence ()
3172{
3173 struct sequence_stack *tem = sequence_stack;
3174
3175 first_insn = tem->first;
3176 last_insn = tem->last;
629a4238 3177 sequence_rtl_expr = tem->sequence_rtl_expr;
23b2ce53
RS
3178 sequence_stack = tem->next;
3179
3180 tem->next = sequence_element_free_list;
3181 sequence_element_free_list = tem;
3182}
3183
3184/* Return 1 if currently emitting into a sequence. */
3185
3186int
3187in_sequence_p ()
3188{
3189 return sequence_stack != 0;
3190}
3191
3192/* Generate a SEQUENCE rtx containing the insns already emitted
3193 to the current sequence.
3194
3195 This is how the gen_... function from a DEFINE_EXPAND
3196 constructs the SEQUENCE that it returns. */
3197
3198rtx
3199gen_sequence ()
3200{
3201 rtx result;
3202 rtx tem;
23b2ce53
RS
3203 int i;
3204 int len;
3205
3206 /* Count the insns in the chain. */
3207 len = 0;
3208 for (tem = first_insn; tem; tem = NEXT_INSN (tem))
3209 len++;
3210
3211 /* If only one insn, return its pattern rather than a SEQUENCE.
3212 (Now that we cache SEQUENCE expressions, it isn't worth special-casing
3213 the case of an empty list.) */
3214 if (len == 1
ca55abae 3215 && ! RTX_FRAME_RELATED_P (first_insn)
23b2ce53
RS
3216 && (GET_CODE (first_insn) == INSN
3217 || GET_CODE (first_insn) == JUMP_INSN
15d23f2b
DE
3218 /* Don't discard the call usage field. */
3219 || (GET_CODE (first_insn) == CALL_INSN
3220 && CALL_INSN_FUNCTION_USAGE (first_insn) == NULL_RTX)))
43127294
RK
3221 {
3222 NEXT_INSN (first_insn) = free_insn;
3223 free_insn = first_insn;
3224 return PATTERN (first_insn);
3225 }
23b2ce53
RS
3226
3227 /* Put them in a vector. See if we already have a SEQUENCE of the
3228 appropriate length around. */
3229 if (len < SEQUENCE_RESULT_SIZE && (result = sequence_result[len]) != 0)
3230 sequence_result[len] = 0;
3231 else
3232 {
9faa82d8
RK
3233 /* Ensure that this rtl goes in saveable_obstack, since we may
3234 cache it. */
d508ebba
JW
3235 push_obstacks_nochange ();
3236 rtl_in_saveable_obstack ();
23b2ce53 3237 result = gen_rtx (SEQUENCE, VOIDmode, rtvec_alloc (len));
d508ebba 3238 pop_obstacks ();
23b2ce53
RS
3239 }
3240
3241 for (i = 0, tem = first_insn; tem; tem = NEXT_INSN (tem), i++)
3242 XVECEXP (result, 0, i) = tem;
3243
3244 return result;
3245}
3246\f
23b2ce53
RS
3247/* Initialize data structures and variables in this file
3248 before generating rtl for each function. */
3249
3250void
3251init_emit ()
3252{
3253 int i;
3254
3255 first_insn = NULL;
3256 last_insn = NULL;
a25c7971 3257 sequence_rtl_expr = NULL;
23b2ce53
RS
3258 cur_insn_uid = 1;
3259 reg_rtx_no = LAST_VIRTUAL_REGISTER + 1;
3260 last_linenum = 0;
3261 last_filename = 0;
3262 first_label_num = label_num;
3263 last_label_num = 0;
24d11a9a 3264 sequence_stack = NULL;
23b2ce53
RS
3265
3266 /* Clear the start_sequence/gen_sequence cache. */
3267 sequence_element_free_list = 0;
3268 for (i = 0; i < SEQUENCE_RESULT_SIZE; i++)
3269 sequence_result[i] = 0;
43127294 3270 free_insn = 0;
23b2ce53
RS
3271
3272 /* Init the tables that describe all the pseudo regs. */
3273
3274 regno_pointer_flag_length = LAST_VIRTUAL_REGISTER + 101;
3275
3276 regno_pointer_flag
86fe05e0 3277 = (char *) savealloc (regno_pointer_flag_length);
23b2ce53
RS
3278 bzero (regno_pointer_flag, regno_pointer_flag_length);
3279
86fe05e0
RK
3280 regno_pointer_align
3281 = (char *) savealloc (regno_pointer_flag_length);
3282 bzero (regno_pointer_align, regno_pointer_flag_length);
3283
23b2ce53 3284 regno_reg_rtx
86fe05e0 3285 = (rtx *) savealloc (regno_pointer_flag_length * sizeof (rtx));
4c9a05bc 3286 bzero ((char *) regno_reg_rtx, regno_pointer_flag_length * sizeof (rtx));
23b2ce53
RS
3287
3288 /* Put copies of all the virtual register rtx into regno_reg_rtx. */
3289 regno_reg_rtx[VIRTUAL_INCOMING_ARGS_REGNUM] = virtual_incoming_args_rtx;
3290 regno_reg_rtx[VIRTUAL_STACK_VARS_REGNUM] = virtual_stack_vars_rtx;
3291 regno_reg_rtx[VIRTUAL_STACK_DYNAMIC_REGNUM] = virtual_stack_dynamic_rtx;
3292 regno_reg_rtx[VIRTUAL_OUTGOING_ARGS_REGNUM] = virtual_outgoing_args_rtx;
740ab4a2
RK
3293
3294 /* Indicate that the virtual registers and stack locations are
3295 all pointers. */
3296 REGNO_POINTER_FLAG (STACK_POINTER_REGNUM) = 1;
3297 REGNO_POINTER_FLAG (FRAME_POINTER_REGNUM) = 1;
15c9248c 3298 REGNO_POINTER_FLAG (HARD_FRAME_POINTER_REGNUM) = 1;
740ab4a2
RK
3299 REGNO_POINTER_FLAG (ARG_POINTER_REGNUM) = 1;
3300
3301 REGNO_POINTER_FLAG (VIRTUAL_INCOMING_ARGS_REGNUM) = 1;
3302 REGNO_POINTER_FLAG (VIRTUAL_STACK_VARS_REGNUM) = 1;
3303 REGNO_POINTER_FLAG (VIRTUAL_STACK_DYNAMIC_REGNUM) = 1;
3304 REGNO_POINTER_FLAG (VIRTUAL_OUTGOING_ARGS_REGNUM) = 1;
5e82e7bd 3305
86fe05e0
RK
3306#ifdef STACK_BOUNDARY
3307 REGNO_POINTER_ALIGN (STACK_POINTER_REGNUM) = STACK_BOUNDARY / BITS_PER_UNIT;
3308 REGNO_POINTER_ALIGN (FRAME_POINTER_REGNUM) = STACK_BOUNDARY / BITS_PER_UNIT;
3309 REGNO_POINTER_ALIGN (HARD_FRAME_POINTER_REGNUM)
3310 = STACK_BOUNDARY / BITS_PER_UNIT;
3311 REGNO_POINTER_ALIGN (ARG_POINTER_REGNUM) = STACK_BOUNDARY / BITS_PER_UNIT;
3312
3313 REGNO_POINTER_ALIGN (VIRTUAL_INCOMING_ARGS_REGNUM)
3314 = STACK_BOUNDARY / BITS_PER_UNIT;
3315 REGNO_POINTER_ALIGN (VIRTUAL_STACK_VARS_REGNUM)
3316 = STACK_BOUNDARY / BITS_PER_UNIT;
3317 REGNO_POINTER_ALIGN (VIRTUAL_STACK_DYNAMIC_REGNUM)
3318 = STACK_BOUNDARY / BITS_PER_UNIT;
3319 REGNO_POINTER_ALIGN (VIRTUAL_OUTGOING_ARGS_REGNUM)
3320 = STACK_BOUNDARY / BITS_PER_UNIT;
3321#endif
3322
5e82e7bd
JVA
3323#ifdef INIT_EXPANDERS
3324 INIT_EXPANDERS;
3325#endif
23b2ce53
RS
3326}
3327
3328/* Create some permanent unique rtl objects shared between all functions.
3329 LINE_NUMBERS is nonzero if line numbers are to be generated. */
3330
3331void
3332init_emit_once (line_numbers)
3333 int line_numbers;
3334{
3335 int i;
3336 enum machine_mode mode;
3337
3338 no_line_numbers = ! line_numbers;
3339
3340 sequence_stack = NULL;
3341
1d445e9e
ILT
3342 /* Compute the word and byte modes. */
3343
3344 byte_mode = VOIDmode;
3345 word_mode = VOIDmode;
3346
3347 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
3348 mode = GET_MODE_WIDER_MODE (mode))
3349 {
3350 if (GET_MODE_BITSIZE (mode) == BITS_PER_UNIT
3351 && byte_mode == VOIDmode)
3352 byte_mode = mode;
3353
3354 if (GET_MODE_BITSIZE (mode) == BITS_PER_WORD
3355 && word_mode == VOIDmode)
3356 word_mode = mode;
3357 }
3358
15c9248c
RK
3359 ptr_mode = mode_for_size (POINTER_SIZE, GET_MODE_CLASS (Pmode), 0);
3360
23b2ce53
RS
3361 /* Create the unique rtx's for certain rtx codes and operand values. */
3362
3363 pc_rtx = gen_rtx (PC, VOIDmode);
3364 cc0_rtx = gen_rtx (CC0, VOIDmode);
3365
3366 /* Don't use gen_rtx here since gen_rtx in this case
3367 tries to use these variables. */
3368 for (i = - MAX_SAVED_CONST_INT; i <= MAX_SAVED_CONST_INT; i++)
3369 {
3370 const_int_rtx[i + MAX_SAVED_CONST_INT] = rtx_alloc (CONST_INT);
3371 PUT_MODE (const_int_rtx[i + MAX_SAVED_CONST_INT], VOIDmode);
3372 INTVAL (const_int_rtx[i + MAX_SAVED_CONST_INT]) = i;
3373 }
3374
3375 /* These four calls obtain some of the rtx expressions made above. */
906c4e36
RK
3376 const0_rtx = GEN_INT (0);
3377 const1_rtx = GEN_INT (1);
3378 const2_rtx = GEN_INT (2);
3379 constm1_rtx = GEN_INT (-1);
23b2ce53
RS
3380
3381 /* This will usually be one of the above constants, but may be a new rtx. */
906c4e36 3382 const_true_rtx = GEN_INT (STORE_FLAG_VALUE);
23b2ce53 3383
1632afca
RS
3384 dconst0 = REAL_VALUE_ATOF ("0", DFmode);
3385 dconst1 = REAL_VALUE_ATOF ("1", DFmode);
3386 dconst2 = REAL_VALUE_ATOF ("2", DFmode);
3387 dconstm1 = REAL_VALUE_ATOF ("-1", DFmode);
23b2ce53
RS
3388
3389 for (i = 0; i <= 2; i++)
3390 {
3391 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
3392 mode = GET_MODE_WIDER_MODE (mode))
3393 {
3394 rtx tem = rtx_alloc (CONST_DOUBLE);
3395 union real_extract u;
3396
4c9a05bc 3397 bzero ((char *) &u, sizeof u); /* Zero any holes in a structure. */
23b2ce53
RS
3398 u.d = i == 0 ? dconst0 : i == 1 ? dconst1 : dconst2;
3399
4c9a05bc 3400 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (tem), sizeof u);
23b2ce53
RS
3401 CONST_DOUBLE_MEM (tem) = cc0_rtx;
3402 PUT_MODE (tem, mode);
3403
3404 const_tiny_rtx[i][(int) mode] = tem;
3405 }
3406
906c4e36 3407 const_tiny_rtx[i][(int) VOIDmode] = GEN_INT (i);
23b2ce53
RS
3408
3409 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
3410 mode = GET_MODE_WIDER_MODE (mode))
906c4e36 3411 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
33d3e559
RS
3412
3413 for (mode = GET_CLASS_NARROWEST_MODE (MODE_PARTIAL_INT);
3414 mode != VOIDmode;
3415 mode = GET_MODE_WIDER_MODE (mode))
3416 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
23b2ce53
RS
3417 }
3418
dfa09e23
TW
3419 for (mode = GET_CLASS_NARROWEST_MODE (MODE_CC); mode != VOIDmode;
3420 mode = GET_MODE_WIDER_MODE (mode))
3421 const_tiny_rtx[0][(int) mode] = const0_rtx;
3422
23b2ce53
RS
3423 stack_pointer_rtx = gen_rtx (REG, Pmode, STACK_POINTER_REGNUM);
3424 frame_pointer_rtx = gen_rtx (REG, Pmode, FRAME_POINTER_REGNUM);
3425
ac6f08b0
DE
3426 if (HARD_FRAME_POINTER_REGNUM == FRAME_POINTER_REGNUM)
3427 hard_frame_pointer_rtx = frame_pointer_rtx;
3428 else
3429 hard_frame_pointer_rtx = gen_rtx (REG, Pmode, HARD_FRAME_POINTER_REGNUM);
3430
23b2ce53
RS
3431 if (FRAME_POINTER_REGNUM == ARG_POINTER_REGNUM)
3432 arg_pointer_rtx = frame_pointer_rtx;
ac6f08b0
DE
3433 else if (HARD_FRAME_POINTER_REGNUM == ARG_POINTER_REGNUM)
3434 arg_pointer_rtx = hard_frame_pointer_rtx;
23b2ce53
RS
3435 else if (STACK_POINTER_REGNUM == ARG_POINTER_REGNUM)
3436 arg_pointer_rtx = stack_pointer_rtx;
3437 else
3438 arg_pointer_rtx = gen_rtx (REG, Pmode, ARG_POINTER_REGNUM);
3439
a4417a86
JW
3440#ifdef RETURN_ADDRESS_POINTER_REGNUM
3441 return_address_pointer_rtx = gen_rtx (REG, Pmode,
3442 RETURN_ADDRESS_POINTER_REGNUM);
3443#endif
3444
23b2ce53
RS
3445 /* Create the virtual registers. Do so here since the following objects
3446 might reference them. */
3447
3448 virtual_incoming_args_rtx = gen_rtx (REG, Pmode,
3449 VIRTUAL_INCOMING_ARGS_REGNUM);
3450 virtual_stack_vars_rtx = gen_rtx (REG, Pmode,
3451 VIRTUAL_STACK_VARS_REGNUM);
3452 virtual_stack_dynamic_rtx = gen_rtx (REG, Pmode,
3453 VIRTUAL_STACK_DYNAMIC_REGNUM);
3454 virtual_outgoing_args_rtx = gen_rtx (REG, Pmode,
3455 VIRTUAL_OUTGOING_ARGS_REGNUM);
3456
3457#ifdef STRUCT_VALUE
3458 struct_value_rtx = STRUCT_VALUE;
3459#else
3460 struct_value_rtx = gen_rtx (REG, Pmode, STRUCT_VALUE_REGNUM);
3461#endif
3462
3463#ifdef STRUCT_VALUE_INCOMING
3464 struct_value_incoming_rtx = STRUCT_VALUE_INCOMING;
3465#else
3466#ifdef STRUCT_VALUE_INCOMING_REGNUM
3467 struct_value_incoming_rtx
3468 = gen_rtx (REG, Pmode, STRUCT_VALUE_INCOMING_REGNUM);
3469#else
3470 struct_value_incoming_rtx = struct_value_rtx;
3471#endif
3472#endif
3473
3474#ifdef STATIC_CHAIN_REGNUM
3475 static_chain_rtx = gen_rtx (REG, Pmode, STATIC_CHAIN_REGNUM);
3476
3477#ifdef STATIC_CHAIN_INCOMING_REGNUM
3478 if (STATIC_CHAIN_INCOMING_REGNUM != STATIC_CHAIN_REGNUM)
3479 static_chain_incoming_rtx = gen_rtx (REG, Pmode, STATIC_CHAIN_INCOMING_REGNUM);
3480 else
3481#endif
3482 static_chain_incoming_rtx = static_chain_rtx;
3483#endif
3484
3485#ifdef STATIC_CHAIN
3486 static_chain_rtx = STATIC_CHAIN;
3487
3488#ifdef STATIC_CHAIN_INCOMING
3489 static_chain_incoming_rtx = STATIC_CHAIN_INCOMING;
3490#else
3491 static_chain_incoming_rtx = static_chain_rtx;
3492#endif
3493#endif
3494
3495#ifdef PIC_OFFSET_TABLE_REGNUM
3496 pic_offset_table_rtx = gen_rtx (REG, Pmode, PIC_OFFSET_TABLE_REGNUM);
3497#endif
3498}
This page took 0.77133 seconds and 5 git commands to generate.