]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/emit-rtl.c
configure (gcc_version): When setting, narrow search to lines containing `version_str...
[thirdparty/gcc.git] / gcc / emit-rtl.c
CommitLineData
23b2ce53 1/* Emit RTL for the GNU C-Compiler expander.
711d877c 2 Copyright (C) 1987, 88, 92-99, 2000 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"
670ee920 38#include "system.h"
01198c2f 39#include "toplev.h"
23b2ce53 40#include "rtl.h"
a25c7971 41#include "tree.h"
6baf1cc8 42#include "tm_p.h"
23b2ce53
RS
43#include "flags.h"
44#include "function.h"
45#include "expr.h"
46#include "regs.h"
aff48bca 47#include "hard-reg-set.h"
23b2ce53 48#include "insn-config.h"
e9a25f70 49#include "recog.h"
23b2ce53 50#include "real.h"
ca695ac9 51#include "obstack.h"
0dfa1860 52#include "bitmap.h"
a05924f9 53#include "basic-block.h"
87ff9c8e 54#include "ggc.h"
ca695ac9 55
1d445e9e
ILT
56/* Commonly used modes. */
57
0f41302f
MS
58enum machine_mode byte_mode; /* Mode whose width is BITS_PER_UNIT. */
59enum machine_mode word_mode; /* Mode whose width is BITS_PER_WORD. */
9ec36da5 60enum machine_mode double_mode; /* Mode whose width is DOUBLE_TYPE_SIZE. */
0f41302f 61enum machine_mode ptr_mode; /* Mode whose width is POINTER_SIZE. */
1d445e9e 62
23b2ce53
RS
63
64/* This is *not* reset after each function. It gives each CODE_LABEL
65 in the entire compilation a unique label number. */
66
67static int label_num = 1;
68
23b2ce53
RS
69/* Highest label number in current function.
70 Zero means use the value of label_num instead.
71 This is nonzero only when belatedly compiling an inline function. */
72
73static int last_label_num;
74
75/* Value label_num had when set_new_first_and_last_label_number was called.
76 If label_num has not changed since then, last_label_num is valid. */
77
78static int base_label_num;
79
80/* Nonzero means do not generate NOTEs for source line numbers. */
81
82static int no_line_numbers;
83
84/* Commonly used rtx's, so that we only need space for one copy.
85 These are initialized once for the entire compilation.
86 All of these except perhaps the floating-point CONST_DOUBLEs
87 are unique; no other rtx-object will be equal to any of these. */
88
5da077de 89rtx global_rtl[GR_MAX];
23b2ce53
RS
90
91/* We record floating-point CONST_DOUBLEs in each floating-point mode for
92 the values of 0, 1, and 2. For the integer entries and VOIDmode, we
93 record a copy of const[012]_rtx. */
94
95rtx const_tiny_rtx[3][(int) MAX_MACHINE_MODE];
96
68d75312
JC
97rtx const_true_rtx;
98
23b2ce53
RS
99REAL_VALUE_TYPE dconst0;
100REAL_VALUE_TYPE dconst1;
101REAL_VALUE_TYPE dconst2;
102REAL_VALUE_TYPE dconstm1;
103
104/* All references to the following fixed hard registers go through
105 these unique rtl objects. On machines where the frame-pointer and
106 arg-pointer are the same register, they use the same unique object.
107
108 After register allocation, other rtl objects which used to be pseudo-regs
109 may be clobbered to refer to the frame-pointer register.
110 But references that were originally to the frame-pointer can be
111 distinguished from the others because they contain frame_pointer_rtx.
112
ac6f08b0
DE
113 When to use frame_pointer_rtx and hard_frame_pointer_rtx is a little
114 tricky: until register elimination has taken place hard_frame_pointer_rtx
115 should be used if it is being set, and frame_pointer_rtx otherwise. After
116 register elimination hard_frame_pointer_rtx should always be used.
117 On machines where the two registers are same (most) then these are the
118 same.
119
23b2ce53
RS
120 In an inline procedure, the stack and frame pointer rtxs may not be
121 used for anything else. */
23b2ce53
RS
122rtx struct_value_rtx; /* (REG:Pmode STRUCT_VALUE_REGNUM) */
123rtx struct_value_incoming_rtx; /* (REG:Pmode STRUCT_VALUE_INCOMING_REGNUM) */
124rtx static_chain_rtx; /* (REG:Pmode STATIC_CHAIN_REGNUM) */
125rtx static_chain_incoming_rtx; /* (REG:Pmode STATIC_CHAIN_INCOMING_REGNUM) */
126rtx pic_offset_table_rtx; /* (REG:Pmode PIC_OFFSET_TABLE_REGNUM) */
127
a4417a86
JW
128/* This is used to implement __builtin_return_address for some machines.
129 See for instance the MIPS port. */
130rtx return_address_pointer_rtx; /* (REG:Pmode RETURN_ADDRESS_POINTER_REGNUM) */
131
23b2ce53
RS
132/* We make one copy of (const_int C) where C is in
133 [- MAX_SAVED_CONST_INT, MAX_SAVED_CONST_INT]
134 to save space during the compilation and simplify comparisons of
135 integers. */
136
5da077de 137rtx const_int_rtx[MAX_SAVED_CONST_INT * 2 + 1];
23b2ce53 138
23b2ce53
RS
139/* start_sequence and gen_sequence can make a lot of rtx expressions which are
140 shortly thrown away. We use two mechanisms to prevent this waste:
141
a3770a81
RH
142 For sizes up to 5 elements, we keep a SEQUENCE and its associated
143 rtvec for use by gen_sequence. One entry for each size is
144 sufficient because most cases are calls to gen_sequence followed by
145 immediately emitting the SEQUENCE. Reuse is safe since emitting a
146 sequence is destructive on the insn in it anyway and hence can't be
147 redone.
23b2ce53
RS
148
149 We do not bother to save this cached data over nested function calls.
150 Instead, we just reinitialize them. */
151
152#define SEQUENCE_RESULT_SIZE 5
153
23b2ce53
RS
154static rtx sequence_result[SEQUENCE_RESULT_SIZE];
155
0f41302f 156/* During RTL generation, we also keep a list of free INSN rtl codes. */
43127294
RK
157static rtx free_insn;
158
01d939e8
BS
159#define first_insn (cfun->emit->x_first_insn)
160#define last_insn (cfun->emit->x_last_insn)
161#define cur_insn_uid (cfun->emit->x_cur_insn_uid)
162#define last_linenum (cfun->emit->x_last_linenum)
163#define last_filename (cfun->emit->x_last_filename)
164#define first_label_num (cfun->emit->x_first_label_num)
23b2ce53 165
da43a810
BS
166/* This is where the pointer to the obstack being used for RTL is stored. */
167extern struct obstack *rtl_obstack;
168
711d877c
KG
169static rtx make_jump_insn_raw PARAMS ((rtx));
170static rtx make_call_insn_raw PARAMS ((rtx));
171static rtx find_line_note PARAMS ((rtx));
172static void mark_sequence_stack PARAMS ((struct sequence_stack *));
d1b81779 173static void unshare_all_rtl_1 PARAMS ((rtx));
ca695ac9 174\f
c5c76735
JL
175/* There are some RTL codes that require special attention; the generation
176 functions do the raw handling. If you add to this list, modify
177 special_rtx in gengenrtl.c as well. */
178
3b80f6ca
RH
179rtx
180gen_rtx_CONST_INT (mode, arg)
181 enum machine_mode mode;
182 HOST_WIDE_INT arg;
183{
184 if (arg >= - MAX_SAVED_CONST_INT && arg <= MAX_SAVED_CONST_INT)
5da077de 185 return const_int_rtx[arg + MAX_SAVED_CONST_INT];
3b80f6ca
RH
186
187#if STORE_FLAG_VALUE != 1 && STORE_FLAG_VALUE != -1
188 if (const_true_rtx && arg == STORE_FLAG_VALUE)
189 return const_true_rtx;
190#endif
191
192 return gen_rtx_raw_CONST_INT (mode, arg);
193}
194
0133b7d9
RH
195/* CONST_DOUBLEs needs special handling because its length is known
196 only at run-time. */
197rtx
198gen_rtx_CONST_DOUBLE (mode, arg0, arg1, arg2)
199 enum machine_mode mode;
200 rtx arg0;
201 HOST_WIDE_INT arg1, arg2;
202{
203 rtx r = rtx_alloc (CONST_DOUBLE);
2454beaf
RH
204 int i;
205
0133b7d9
RH
206 PUT_MODE (r, mode);
207 XEXP (r, 0) = arg0;
ef178af3 208 X0EXP (r, 1) = NULL_RTX;
2454beaf
RH
209 XWINT (r, 2) = arg1;
210 XWINT (r, 3) = arg2;
211
212 for (i = GET_RTX_LENGTH (CONST_DOUBLE) - 1; i > 3; --i)
213 XWINT (r, i) = 0;
214
0133b7d9
RH
215 return r;
216}
217
3b80f6ca
RH
218rtx
219gen_rtx_REG (mode, regno)
220 enum machine_mode mode;
221 int regno;
222{
223 /* In case the MD file explicitly references the frame pointer, have
224 all such references point to the same frame pointer. This is
225 used during frame pointer elimination to distinguish the explicit
226 references to these registers from pseudos that happened to be
227 assigned to them.
228
229 If we have eliminated the frame pointer or arg pointer, we will
230 be using it as a normal register, for example as a spill
231 register. In such cases, we might be accessing it in a mode that
232 is not Pmode and therefore cannot use the pre-allocated rtx.
233
234 Also don't do this when we are making new REGs in reload, since
235 we don't want to get confused with the real pointers. */
236
237 if (mode == Pmode && !reload_in_progress)
238 {
bcb33994 239 if (regno == FRAME_POINTER_REGNUM)
3b80f6ca
RH
240 return frame_pointer_rtx;
241#if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
bcb33994 242 if (regno == HARD_FRAME_POINTER_REGNUM)
3b80f6ca
RH
243 return hard_frame_pointer_rtx;
244#endif
245#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM && HARD_FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
bcb33994 246 if (regno == ARG_POINTER_REGNUM)
3b80f6ca
RH
247 return arg_pointer_rtx;
248#endif
249#ifdef RETURN_ADDRESS_POINTER_REGNUM
bcb33994 250 if (regno == RETURN_ADDRESS_POINTER_REGNUM)
3b80f6ca
RH
251 return return_address_pointer_rtx;
252#endif
bcb33994 253 if (regno == STACK_POINTER_REGNUM)
3b80f6ca
RH
254 return stack_pointer_rtx;
255 }
256
257 return gen_rtx_raw_REG (mode, regno);
258}
259
41472af8
MM
260rtx
261gen_rtx_MEM (mode, addr)
262 enum machine_mode mode;
263 rtx addr;
264{
265 rtx rt = gen_rtx_raw_MEM (mode, addr);
266
267 /* This field is not cleared by the mere allocation of the rtx, so
268 we clear it here. */
269 MEM_ALIAS_SET (rt) = 0;
270
271 return rt;
272}
c5c76735 273\f
23b2ce53
RS
274/* rtx gen_rtx (code, mode, [element1, ..., elementn])
275**
276** This routine generates an RTX of the size specified by
277** <code>, which is an RTX code. The RTX structure is initialized
278** from the arguments <element1> through <elementn>, which are
279** interpreted according to the specific RTX type's format. The
280** special machine mode associated with the rtx (if any) is specified
281** in <mode>.
282**
1632afca 283** gen_rtx can be invoked in a way which resembles the lisp-like
23b2ce53
RS
284** rtx it will generate. For example, the following rtx structure:
285**
286** (plus:QI (mem:QI (reg:SI 1))
287** (mem:QI (plusw:SI (reg:SI 2) (reg:SI 3))))
288**
289** ...would be generated by the following C code:
290**
291** gen_rtx (PLUS, QImode,
292** gen_rtx (MEM, QImode,
293** gen_rtx (REG, SImode, 1)),
294** gen_rtx (MEM, QImode,
295** gen_rtx (PLUS, SImode,
296** gen_rtx (REG, SImode, 2),
297** gen_rtx (REG, SImode, 3)))),
298*/
299
300/*VARARGS2*/
301rtx
711d877c 302gen_rtx VPARAMS ((enum rtx_code code, enum machine_mode mode, ...))
23b2ce53 303{
5148a72b 304#ifndef ANSI_PROTOTYPES
23b2ce53
RS
305 enum rtx_code code;
306 enum machine_mode mode;
4f90e4a0
RK
307#endif
308 va_list p;
23b2ce53 309 register int i; /* Array indices... */
6f7d635c 310 register const char *fmt; /* Current rtx's format... */
23b2ce53
RS
311 register rtx rt_val; /* RTX to return to caller... */
312
4f90e4a0
RK
313 VA_START (p, mode);
314
5148a72b 315#ifndef ANSI_PROTOTYPES
23b2ce53
RS
316 code = va_arg (p, enum rtx_code);
317 mode = va_arg (p, enum machine_mode);
4f90e4a0 318#endif
23b2ce53 319
0133b7d9 320 switch (code)
23b2ce53 321 {
0133b7d9
RH
322 case CONST_INT:
323 rt_val = gen_rtx_CONST_INT (mode, va_arg (p, HOST_WIDE_INT));
324 break;
325
326 case CONST_DOUBLE:
327 {
328 rtx arg0 = va_arg (p, rtx);
329 HOST_WIDE_INT arg1 = va_arg (p, HOST_WIDE_INT);
330 HOST_WIDE_INT arg2 = va_arg (p, HOST_WIDE_INT);
331 rt_val = gen_rtx_CONST_DOUBLE (mode, arg0, arg1, arg2);
332 }
333 break;
334
335 case REG:
336 rt_val = gen_rtx_REG (mode, va_arg (p, int));
337 break;
338
339 case MEM:
340 rt_val = gen_rtx_MEM (mode, va_arg (p, rtx));
341 break;
342
343 default:
23b2ce53
RS
344 rt_val = rtx_alloc (code); /* Allocate the storage space. */
345 rt_val->mode = mode; /* Store the machine mode... */
346
347 fmt = GET_RTX_FORMAT (code); /* Find the right format... */
348 for (i = 0; i < GET_RTX_LENGTH (code); i++)
349 {
350 switch (*fmt++)
351 {
352 case '0': /* Unused field. */
353 break;
354
355 case 'i': /* An integer? */
356 XINT (rt_val, i) = va_arg (p, int);
357 break;
358
906c4e36
RK
359 case 'w': /* A wide integer? */
360 XWINT (rt_val, i) = va_arg (p, HOST_WIDE_INT);
361 break;
362
23b2ce53
RS
363 case 's': /* A string? */
364 XSTR (rt_val, i) = va_arg (p, char *);
365 break;
366
367 case 'e': /* An expression? */
368 case 'u': /* An insn? Same except when printing. */
369 XEXP (rt_val, i) = va_arg (p, rtx);
370 break;
371
372 case 'E': /* An RTX vector? */
373 XVEC (rt_val, i) = va_arg (p, rtvec);
374 break;
375
0dfa1860
MM
376 case 'b': /* A bitmap? */
377 XBITMAP (rt_val, i) = va_arg (p, bitmap);
378 break;
379
380 case 't': /* A tree? */
381 XTREE (rt_val, i) = va_arg (p, tree);
382 break;
383
23b2ce53 384 default:
1632afca 385 abort ();
23b2ce53
RS
386 }
387 }
0133b7d9 388 break;
23b2ce53 389 }
0133b7d9 390
23b2ce53 391 va_end (p);
0133b7d9 392 return rt_val;
23b2ce53
RS
393}
394
395/* gen_rtvec (n, [rt1, ..., rtn])
396**
397** This routine creates an rtvec and stores within it the
398** pointers to rtx's which are its arguments.
399*/
400
401/*VARARGS1*/
402rtvec
711d877c 403gen_rtvec VPARAMS ((int n, ...))
23b2ce53 404{
5148a72b 405#ifndef ANSI_PROTOTYPES
4f90e4a0
RK
406 int n;
407#endif
408 int i;
23b2ce53
RS
409 va_list p;
410 rtx *vector;
411
4f90e4a0
RK
412 VA_START (p, n);
413
5148a72b 414#ifndef ANSI_PROTOTYPES
23b2ce53 415 n = va_arg (p, int);
4f90e4a0 416#endif
23b2ce53
RS
417
418 if (n == 0)
419 return NULL_RTVEC; /* Don't allocate an empty rtvec... */
420
421 vector = (rtx *) alloca (n * sizeof (rtx));
4f90e4a0 422
23b2ce53
RS
423 for (i = 0; i < n; i++)
424 vector[i] = va_arg (p, rtx);
425 va_end (p);
426
427 return gen_rtvec_v (n, vector);
428}
429
430rtvec
431gen_rtvec_v (n, argp)
432 int n;
433 rtx *argp;
434{
435 register int i;
436 register rtvec rt_val;
437
438 if (n == 0)
439 return NULL_RTVEC; /* Don't allocate an empty rtvec... */
440
441 rt_val = rtvec_alloc (n); /* Allocate an rtvec... */
442
443 for (i = 0; i < n; i++)
8f985ec4 444 rt_val->elem[i] = *argp++;
23b2ce53
RS
445
446 return rt_val;
447}
ba444f92 448
23b2ce53
RS
449\f
450/* Generate a REG rtx for a new pseudo register of mode MODE.
451 This pseudo is assigned the next sequential register number. */
452
453rtx
454gen_reg_rtx (mode)
455 enum machine_mode mode;
456{
01d939e8 457 struct function *f = cfun;
23b2ce53
RS
458 register rtx val;
459
f1db3576
JL
460 /* Don't let anything called after initial flow analysis create new
461 registers. */
462 if (no_new_pseudos)
23b2ce53
RS
463 abort ();
464
fc84e8a8
RS
465 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
466 || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
467 {
468 /* For complex modes, don't make a single pseudo.
469 Instead, make a CONCAT of two pseudos.
470 This allows noncontiguous allocation of the real and imaginary parts,
471 which makes much better code. Besides, allocating DCmode
472 pseudos overstrains reload on some machines like the 386. */
473 rtx realpart, imagpart;
474 int size = GET_MODE_UNIT_SIZE (mode);
475 enum machine_mode partmode
476 = mode_for_size (size * BITS_PER_UNIT,
477 (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
478 ? MODE_FLOAT : MODE_INT),
479 0);
480
481 realpart = gen_reg_rtx (partmode);
482 imagpart = gen_reg_rtx (partmode);
3b80f6ca 483 return gen_rtx_CONCAT (mode, realpart, imagpart);
fc84e8a8
RS
484 }
485
23b2ce53
RS
486 /* Make sure regno_pointer_flag and regno_reg_rtx are large
487 enough to have an element for this pseudo reg number. */
488
49ad7cfa 489 if (reg_rtx_no == f->emit->regno_pointer_flag_length)
23b2ce53 490 {
49ad7cfa 491 int old_size = f->emit->regno_pointer_flag_length;
23b2ce53 492 rtx *new1;
e2ecd91c
BS
493 char *new;
494 new = xrealloc (f->emit->regno_pointer_flag, old_size * 2);
49ad7cfa
BS
495 memset (new + old_size, 0, old_size);
496 f->emit->regno_pointer_flag = new;
497
e2ecd91c 498 new = xrealloc (f->emit->regno_pointer_align, old_size * 2);
49ad7cfa
BS
499 memset (new + old_size, 0, old_size);
500 f->emit->regno_pointer_align = new;
501
e2ecd91c
BS
502 new1 = (rtx *) xrealloc (f->emit->x_regno_reg_rtx,
503 old_size * 2 * sizeof (rtx));
49ad7cfa 504 memset (new1 + old_size, 0, old_size * sizeof (rtx));
23b2ce53
RS
505 regno_reg_rtx = new1;
506
49ad7cfa 507 f->emit->regno_pointer_flag_length = old_size * 2;
23b2ce53
RS
508 }
509
3b80f6ca 510 val = gen_rtx_raw_REG (mode, reg_rtx_no);
23b2ce53
RS
511 regno_reg_rtx[reg_rtx_no++] = val;
512 return val;
513}
514
754fdcca
RK
515/* Identify REG (which may be a CONCAT) as a user register. */
516
517void
518mark_user_reg (reg)
519 rtx reg;
520{
521 if (GET_CODE (reg) == CONCAT)
522 {
523 REG_USERVAR_P (XEXP (reg, 0)) = 1;
524 REG_USERVAR_P (XEXP (reg, 1)) = 1;
525 }
526 else if (GET_CODE (reg) == REG)
527 REG_USERVAR_P (reg) = 1;
528 else
529 abort ();
530}
531
86fe05e0
RK
532/* Identify REG as a probable pointer register and show its alignment
533 as ALIGN, if nonzero. */
23b2ce53
RS
534
535void
86fe05e0 536mark_reg_pointer (reg, align)
23b2ce53 537 rtx reg;
86fe05e0 538 int align;
23b2ce53 539{
00995e78
RE
540 if (! REGNO_POINTER_FLAG (REGNO (reg)))
541 {
542 REGNO_POINTER_FLAG (REGNO (reg)) = 1;
86fe05e0 543
00995e78
RE
544 if (align)
545 REGNO_POINTER_ALIGN (REGNO (reg)) = align;
546 }
547 else if (align && align < REGNO_POINTER_ALIGN (REGNO (reg)))
548 /* We can no-longer be sure just how aligned this pointer is */
86fe05e0 549 REGNO_POINTER_ALIGN (REGNO (reg)) = align;
23b2ce53
RS
550}
551
552/* Return 1 plus largest pseudo reg number used in the current function. */
553
554int
555max_reg_num ()
556{
557 return reg_rtx_no;
558}
559
560/* Return 1 + the largest label number used so far in the current function. */
561
562int
563max_label_num ()
564{
565 if (last_label_num && label_num == base_label_num)
566 return last_label_num;
567 return label_num;
568}
569
570/* Return first label number used in this function (if any were used). */
571
572int
573get_first_label_num ()
574{
575 return first_label_num;
576}
577\f
578/* Return a value representing some low-order bits of X, where the number
579 of low-order bits is given by MODE. Note that no conversion is done
580 between floating-point and fixed-point values, rather, the bit
581 representation is returned.
582
583 This function handles the cases in common between gen_lowpart, below,
584 and two variants in cse.c and combine.c. These are the cases that can
585 be safely handled at all points in the compilation.
586
587 If this is not a case we can handle, return 0. */
588
589rtx
590gen_lowpart_common (mode, x)
591 enum machine_mode mode;
592 register rtx x;
593{
594 int word = 0;
595
596 if (GET_MODE (x) == mode)
597 return x;
598
599 /* MODE must occupy no more words than the mode of X. */
600 if (GET_MODE (x) != VOIDmode
601 && ((GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD
602 > ((GET_MODE_SIZE (GET_MODE (x)) + (UNITS_PER_WORD - 1))
603 / UNITS_PER_WORD)))
604 return 0;
605
606 if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
607 word = ((GET_MODE_SIZE (GET_MODE (x))
608 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD))
609 / UNITS_PER_WORD);
610
611 if ((GET_CODE (x) == ZERO_EXTEND || GET_CODE (x) == SIGN_EXTEND)
83e9c679
RK
612 && (GET_MODE_CLASS (mode) == MODE_INT
613 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT))
23b2ce53
RS
614 {
615 /* If we are getting the low-order part of something that has been
616 sign- or zero-extended, we can either just use the object being
617 extended or make a narrower extension. If we want an even smaller
618 piece than the size of the object being extended, call ourselves
619 recursively.
620
621 This case is used mostly by combine and cse. */
622
623 if (GET_MODE (XEXP (x, 0)) == mode)
624 return XEXP (x, 0);
625 else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (XEXP (x, 0))))
626 return gen_lowpart_common (mode, XEXP (x, 0));
627 else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (x)))
3b80f6ca 628 return gen_rtx_fmt_e (GET_CODE (x), mode, XEXP (x, 0));
23b2ce53
RS
629 }
630 else if (GET_CODE (x) == SUBREG
631 && (GET_MODE_SIZE (mode) <= UNITS_PER_WORD
632 || GET_MODE_SIZE (mode) == GET_MODE_UNIT_SIZE (GET_MODE (x))))
633 return (GET_MODE (SUBREG_REG (x)) == mode && SUBREG_WORD (x) == 0
634 ? SUBREG_REG (x)
3b80f6ca 635 : gen_rtx_SUBREG (mode, SUBREG_REG (x), SUBREG_WORD (x) + word));
23b2ce53
RS
636 else if (GET_CODE (x) == REG)
637 {
4901a643
RH
638 /* Let the backend decide how many registers to skip. This is needed
639 in particular for Sparc64 where fp regs are smaller than a word. */
640 /* ??? Note that subregs are now ambiguous, in that those against
641 pseudos are sized by the Word Size, while those against hard
642 regs are sized by the underlying register size. Better would be
643 to always interpret the subreg offset parameter as bytes or bits. */
644
645 if (WORDS_BIG_ENDIAN && REGNO (x) < FIRST_PSEUDO_REGISTER)
646 word = (HARD_REGNO_NREGS (REGNO (x), GET_MODE (x))
647 - HARD_REGNO_NREGS (REGNO (x), mode));
648
23b2ce53 649 /* If the register is not valid for MODE, return 0. If we don't
674d5d8b
RK
650 do this, there is no way to fix up the resulting REG later.
651 But we do do this if the current REG is not valid for its
652 mode. This latter is a kludge, but is required due to the
653 way that parameters are passed on some machines, most
654 notably Sparc. */
23b2ce53 655 if (REGNO (x) < FIRST_PSEUDO_REGISTER
674d5d8b
RK
656 && ! HARD_REGNO_MODE_OK (REGNO (x) + word, mode)
657 && HARD_REGNO_MODE_OK (REGNO (x), GET_MODE (x)))
23b2ce53
RS
658 return 0;
659 else if (REGNO (x) < FIRST_PSEUDO_REGISTER
660 /* integrate.c can't handle parts of a return value register. */
661 && (! REG_FUNCTION_VALUE_P (x)
cb00f51a 662 || ! rtx_equal_function_value_matters)
aff48bca
JL
663#ifdef CLASS_CANNOT_CHANGE_SIZE
664 && ! (GET_MODE_SIZE (mode) != GET_MODE_SIZE (GET_MODE (x))
665 && GET_MODE_CLASS (GET_MODE (x)) != MODE_COMPLEX_INT
666 && GET_MODE_CLASS (GET_MODE (x)) != MODE_COMPLEX_FLOAT
667 && (TEST_HARD_REG_BIT
668 (reg_class_contents[(int) CLASS_CANNOT_CHANGE_SIZE],
669 REGNO (x))))
670#endif
cb00f51a
RK
671 /* We want to keep the stack, frame, and arg pointers
672 special. */
65e8fe02 673 && x != frame_pointer_rtx
cb00f51a 674#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
65e8fe02 675 && x != arg_pointer_rtx
cb00f51a 676#endif
65e8fe02 677 && x != stack_pointer_rtx)
3b80f6ca 678 return gen_rtx_REG (mode, REGNO (x) + word);
23b2ce53 679 else
3b80f6ca 680 return gen_rtx_SUBREG (mode, x, word);
23b2ce53 681 }
23b2ce53
RS
682 /* If X is a CONST_INT or a CONST_DOUBLE, extract the appropriate bits
683 from the low-order part of the constant. */
83e9c679
RK
684 else if ((GET_MODE_CLASS (mode) == MODE_INT
685 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
686 && GET_MODE (x) == VOIDmode
23b2ce53 687 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
1a5b457d
RK
688 {
689 /* If MODE is twice the host word size, X is already the desired
690 representation. Otherwise, if MODE is wider than a word, we can't
691 do this. If MODE is exactly a word, return just one CONST_INT.
692 If MODE is smaller than a word, clear the bits that don't belong
693 in our mode, unless they and our sign bit are all one. So we get
694 either a reasonable negative value or a reasonable unsigned value
695 for this mode. */
696
a8dd0e73 697 if (GET_MODE_BITSIZE (mode) >= 2 * HOST_BITS_PER_WIDE_INT)
1a5b457d 698 return x;
906c4e36 699 else if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
1a5b457d 700 return 0;
906c4e36 701 else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
1a5b457d 702 return (GET_CODE (x) == CONST_INT ? x
906c4e36 703 : GEN_INT (CONST_DOUBLE_LOW (x)));
1a5b457d
RK
704 else
705 {
27eef9ce 706 /* MODE must be narrower than HOST_BITS_PER_WIDE_INT. */
1a5b457d 707 int width = GET_MODE_BITSIZE (mode);
906c4e36
RK
708 HOST_WIDE_INT val = (GET_CODE (x) == CONST_INT ? INTVAL (x)
709 : CONST_DOUBLE_LOW (x));
1a5b457d 710
27eef9ce
JC
711 /* Sign extend to HOST_WIDE_INT. */
712 val = val << (HOST_BITS_PER_WIDE_INT - width) >> (HOST_BITS_PER_WIDE_INT - width);
1a5b457d
RK
713
714 return (GET_CODE (x) == CONST_INT && INTVAL (x) == val ? x
906c4e36 715 : GEN_INT (val));
1a5b457d
RK
716 }
717 }
23b2ce53 718
8aada4ad
RK
719 /* If X is an integral constant but we want it in floating-point, it
720 must be the case that we have a union of an integer and a floating-point
721 value. If the machine-parameters allow it, simulate that union here
d6020413
RK
722 and return the result. The two-word and single-word cases are
723 different. */
8aada4ad 724
b3bf132d 725 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
906c4e36 726 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
b3bf132d 727 || flag_pretend_float)
8aada4ad 728 && GET_MODE_CLASS (mode) == MODE_FLOAT
d6020413
RK
729 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
730 && GET_CODE (x) == CONST_INT
906c4e36 731 && sizeof (float) * HOST_BITS_PER_CHAR == HOST_BITS_PER_WIDE_INT)
b6a524cb
RS
732#ifdef REAL_ARITHMETIC
733 {
734 REAL_VALUE_TYPE r;
735 HOST_WIDE_INT i;
736
737 i = INTVAL (x);
738 r = REAL_VALUE_FROM_TARGET_SINGLE (i);
53596fba 739 return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
b6a524cb
RS
740 }
741#else
d6020413 742 {
906c4e36 743 union {HOST_WIDE_INT i; float d; } u;
d6020413
RK
744
745 u.i = INTVAL (x);
53596fba 746 return CONST_DOUBLE_FROM_REAL_VALUE (u.d, mode);
d6020413 747 }
b6a524cb 748#endif
d6020413 749 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
906c4e36 750 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
d6020413
RK
751 || flag_pretend_float)
752 && GET_MODE_CLASS (mode) == MODE_FLOAT
753 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
8aada4ad
RK
754 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
755 && GET_MODE (x) == VOIDmode
906c4e36
RK
756 && (sizeof (double) * HOST_BITS_PER_CHAR
757 == 2 * HOST_BITS_PER_WIDE_INT))
b6a524cb
RS
758#ifdef REAL_ARITHMETIC
759 {
760 REAL_VALUE_TYPE r;
761 HOST_WIDE_INT i[2];
762 HOST_WIDE_INT low, high;
763
764 if (GET_CODE (x) == CONST_INT)
765 low = INTVAL (x), high = low >> (HOST_BITS_PER_WIDE_INT -1);
766 else
767 low = CONST_DOUBLE_LOW (x), high = CONST_DOUBLE_HIGH (x);
768
8698cce3 769 /* REAL_VALUE_TARGET_DOUBLE takes the addressing order of the
0f41302f 770 target machine. */
8698cce3
RK
771 if (WORDS_BIG_ENDIAN)
772 i[0] = high, i[1] = low;
773 else
774 i[0] = low, i[1] = high;
b6a524cb
RS
775
776 r = REAL_VALUE_FROM_TARGET_DOUBLE (i);
53596fba 777 return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
b6a524cb
RS
778 }
779#else
8aada4ad 780 {
906c4e36
RK
781 union {HOST_WIDE_INT i[2]; double d; } u;
782 HOST_WIDE_INT low, high;
8aada4ad
RK
783
784 if (GET_CODE (x) == CONST_INT)
906c4e36 785 low = INTVAL (x), high = low >> (HOST_BITS_PER_WIDE_INT -1);
8aada4ad
RK
786 else
787 low = CONST_DOUBLE_LOW (x), high = CONST_DOUBLE_HIGH (x);
788
789#ifdef HOST_WORDS_BIG_ENDIAN
790 u.i[0] = high, u.i[1] = low;
791#else
792 u.i[0] = low, u.i[1] = high;
793#endif
794
53596fba 795 return CONST_DOUBLE_FROM_REAL_VALUE (u.d, mode);
8aada4ad 796 }
b6a524cb 797#endif
a6a503ed
JW
798
799 /* We need an extra case for machines where HOST_BITS_PER_WIDE_INT is the
4926b75a
JL
800 same as sizeof (double) or when sizeof (float) is larger than the
801 size of a word on the target machine. */
a6a503ed 802#ifdef REAL_ARITHMETIC
4926b75a 803 else if (mode == SFmode && GET_CODE (x) == CONST_INT)
a6a503ed
JW
804 {
805 REAL_VALUE_TYPE r;
806 HOST_WIDE_INT i;
807
808 i = INTVAL (x);
809 r = REAL_VALUE_FROM_TARGET_SINGLE (i);
810 return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
811 }
8fc4af0f
JJ
812 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
813 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
814 || flag_pretend_float)
815 && GET_MODE_CLASS (mode) == MODE_FLOAT
816 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
817 && GET_CODE (x) == CONST_INT
818 && (sizeof (double) * HOST_BITS_PER_CHAR
819 == HOST_BITS_PER_WIDE_INT))
820 {
821 REAL_VALUE_TYPE r;
822 HOST_WIDE_INT i;
823
824 i = INTVAL (x);
825 r = REAL_VALUE_FROM_TARGET_DOUBLE (&i);
826 return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
827 }
a6a503ed
JW
828#endif
829
b3bf132d
RK
830 /* Similarly, if this is converting a floating-point value into a
831 single-word integer. Only do this is the host and target parameters are
832 compatible. */
833
834 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
906c4e36 835 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
b3bf132d 836 || flag_pretend_float)
83e9c679
RK
837 && (GET_MODE_CLASS (mode) == MODE_INT
838 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
b3bf132d
RK
839 && GET_CODE (x) == CONST_DOUBLE
840 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT
841 && GET_MODE_BITSIZE (mode) == BITS_PER_WORD)
a80586cc 842 return operand_subword (x, word, 0, GET_MODE (x));
b3bf132d 843
8aada4ad
RK
844 /* Similarly, if this is converting a floating-point value into a
845 two-word integer, we can do this one word at a time and make an
846 integer. Only do this is the host and target parameters are
847 compatible. */
848
b3bf132d 849 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
906c4e36 850 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
b3bf132d 851 || flag_pretend_float)
83e9c679 852 && (GET_MODE_CLASS (mode) == MODE_INT
f5a2fb25 853 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
8aada4ad
RK
854 && GET_CODE (x) == CONST_DOUBLE
855 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT
856 && GET_MODE_BITSIZE (mode) == 2 * BITS_PER_WORD)
857 {
a80586cc
RK
858 rtx lowpart
859 = operand_subword (x, word + WORDS_BIG_ENDIAN, 0, GET_MODE (x));
860 rtx highpart
861 = operand_subword (x, word + ! WORDS_BIG_ENDIAN, 0, GET_MODE (x));
8aada4ad
RK
862
863 if (lowpart && GET_CODE (lowpart) == CONST_INT
864 && highpart && GET_CODE (highpart) == CONST_INT)
865 return immed_double_const (INTVAL (lowpart), INTVAL (highpart), mode);
866 }
867
23b2ce53
RS
868 /* Otherwise, we can't do this. */
869 return 0;
870}
871\f
280194b0
RS
872/* Return the real part (which has mode MODE) of a complex value X.
873 This always comes at the low address in memory. */
874
875rtx
876gen_realpart (mode, x)
877 enum machine_mode mode;
878 register rtx x;
879{
dc139c90
RK
880 if (GET_CODE (x) == CONCAT && GET_MODE (XEXP (x, 0)) == mode)
881 return XEXP (x, 0);
40c0c3cf
JL
882 else if (WORDS_BIG_ENDIAN
883 && GET_MODE_BITSIZE (mode) < BITS_PER_WORD
884 && REG_P (x)
885 && REGNO (x) < FIRST_PSEUDO_REGISTER)
886 fatal ("Unable to access real part of complex value in a hard register on this target");
dc139c90 887 else if (WORDS_BIG_ENDIAN)
280194b0
RS
888 return gen_highpart (mode, x);
889 else
890 return gen_lowpart (mode, x);
891}
892
893/* Return the imaginary part (which has mode MODE) of a complex value X.
894 This always comes at the high address in memory. */
895
896rtx
897gen_imagpart (mode, x)
898 enum machine_mode mode;
899 register rtx x;
900{
dc139c90
RK
901 if (GET_CODE (x) == CONCAT && GET_MODE (XEXP (x, 0)) == mode)
902 return XEXP (x, 1);
903 else if (WORDS_BIG_ENDIAN)
280194b0 904 return gen_lowpart (mode, x);
40c0c3cf
JL
905 else if (!WORDS_BIG_ENDIAN
906 && GET_MODE_BITSIZE (mode) < BITS_PER_WORD
907 && REG_P (x)
908 && REGNO (x) < FIRST_PSEUDO_REGISTER)
909 fatal ("Unable to access imaginary part of complex value in a hard register on this target");
280194b0
RS
910 else
911 return gen_highpart (mode, x);
912}
81284a6a
JW
913
914/* Return 1 iff X, assumed to be a SUBREG,
915 refers to the real part of the complex value in its containing reg.
916 Complex values are always stored with the real part in the first word,
917 regardless of WORDS_BIG_ENDIAN. */
918
919int
920subreg_realpart_p (x)
921 rtx x;
922{
923 if (GET_CODE (x) != SUBREG)
924 abort ();
925
ddc54eaa 926 return SUBREG_WORD (x) * UNITS_PER_WORD < GET_MODE_UNIT_SIZE (GET_MODE (SUBREG_REG (x)));
81284a6a 927}
280194b0 928\f
23b2ce53
RS
929/* Assuming that X is an rtx (e.g., MEM, REG or SUBREG) for a value,
930 return an rtx (MEM, SUBREG, or CONST_INT) that refers to the
931 least-significant part of X.
932 MODE specifies how big a part of X to return;
933 it usually should not be larger than a word.
934 If X is a MEM whose address is a QUEUED, the value may be so also. */
935
936rtx
937gen_lowpart (mode, x)
938 enum machine_mode mode;
939 register rtx x;
940{
941 rtx result = gen_lowpart_common (mode, x);
942
943 if (result)
944 return result;
ea8262b0
RK
945 else if (GET_CODE (x) == REG)
946 {
947 /* Must be a hard reg that's not valid in MODE. */
948 result = gen_lowpart_common (mode, copy_to_reg (x));
949 if (result == 0)
950 abort ();
72c3833b 951 return result;
ea8262b0 952 }
23b2ce53
RS
953 else if (GET_CODE (x) == MEM)
954 {
955 /* The only additional case we can do is MEM. */
956 register int offset = 0;
957 if (WORDS_BIG_ENDIAN)
958 offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
959 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
960
961 if (BYTES_BIG_ENDIAN)
962 /* Adjust the address so that the address-after-the-data
963 is unchanged. */
964 offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))
965 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
966
967 return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
968 }
e9a25f70
JL
969 else if (GET_CODE (x) == ADDRESSOF)
970 return gen_lowpart (mode, force_reg (GET_MODE (x), x));
23b2ce53
RS
971 else
972 abort ();
973}
974
ccba022b
RS
975/* Like `gen_lowpart', but refer to the most significant part.
976 This is used to access the imaginary part of a complex number. */
977
978rtx
979gen_highpart (mode, x)
980 enum machine_mode mode;
981 register rtx x;
982{
983 /* This case loses if X is a subreg. To catch bugs early,
984 complain if an invalid MODE is used even in other cases. */
985 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
986 && GET_MODE_SIZE (mode) != GET_MODE_UNIT_SIZE (GET_MODE (x)))
987 abort ();
988 if (GET_CODE (x) == CONST_DOUBLE
1632afca 989#if !(TARGET_FLOAT_FORMAT != HOST_FLOAT_FORMAT || defined (REAL_IS_NOT_DOUBLE))
ccba022b
RS
990 && GET_MODE_CLASS (GET_MODE (x)) != MODE_FLOAT
991#endif
992 )
3b80f6ca 993 return GEN_INT (CONST_DOUBLE_HIGH (x) & GET_MODE_MASK (mode));
ccba022b 994 else if (GET_CODE (x) == CONST_INT)
27eef9ce
JC
995 {
996 if (HOST_BITS_PER_WIDE_INT <= BITS_PER_WORD)
997 return const0_rtx;
998 return GEN_INT (INTVAL (x) >> (HOST_BITS_PER_WIDE_INT - BITS_PER_WORD));
999 }
ccba022b
RS
1000 else if (GET_CODE (x) == MEM)
1001 {
1002 register int offset = 0;
8698cce3
RK
1003 if (! WORDS_BIG_ENDIAN)
1004 offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
1005 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
1006
1007 if (! BYTES_BIG_ENDIAN
1008 && GET_MODE_SIZE (mode) < UNITS_PER_WORD)
ccba022b
RS
1009 offset -= (GET_MODE_SIZE (mode)
1010 - MIN (UNITS_PER_WORD,
1011 GET_MODE_SIZE (GET_MODE (x))));
8698cce3 1012
ccba022b
RS
1013 return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
1014 }
1015 else if (GET_CODE (x) == SUBREG)
1016 {
1017 /* The only time this should occur is when we are looking at a
1018 multi-word item with a SUBREG whose mode is the same as that of the
1019 item. It isn't clear what we would do if it wasn't. */
1020 if (SUBREG_WORD (x) != 0)
1021 abort ();
1022 return gen_highpart (mode, SUBREG_REG (x));
1023 }
1024 else if (GET_CODE (x) == REG)
1025 {
6cca74ab 1026 int word;
ccba022b 1027
4901a643
RH
1028 /* Let the backend decide how many registers to skip. This is needed
1029 in particular for sparc64 where fp regs are smaller than a word. */
1030 /* ??? Note that subregs are now ambiguous, in that those against
6cca74ab 1031 pseudos are sized by the word size, while those against hard
4901a643
RH
1032 regs are sized by the underlying register size. Better would be
1033 to always interpret the subreg offset parameter as bytes or bits. */
1034
6cca74ab
GM
1035 if (WORDS_BIG_ENDIAN)
1036 word = 0;
1037 else if (REGNO (x) < FIRST_PSEUDO_REGISTER)
4901a643
RH
1038 word = (HARD_REGNO_NREGS (REGNO (x), GET_MODE (x))
1039 - HARD_REGNO_NREGS (REGNO (x), mode));
6cca74ab
GM
1040 else
1041 word = ((GET_MODE_SIZE (GET_MODE (x))
1042 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD))
1043 / UNITS_PER_WORD);
3e4a14ef 1044
cb00f51a 1045 if (REGNO (x) < FIRST_PSEUDO_REGISTER
0f41302f 1046 /* integrate.c can't handle parts of a return value register. */
4badc528
RS
1047 && (! REG_FUNCTION_VALUE_P (x)
1048 || ! rtx_equal_function_value_matters)
cb00f51a 1049 /* We want to keep the stack, frame, and arg pointers special. */
65e8fe02 1050 && x != frame_pointer_rtx
cb00f51a 1051#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
65e8fe02 1052 && x != arg_pointer_rtx
cb00f51a 1053#endif
65e8fe02 1054 && x != stack_pointer_rtx)
3b80f6ca 1055 return gen_rtx_REG (mode, REGNO (x) + word);
ccba022b 1056 else
3b80f6ca 1057 return gen_rtx_SUBREG (mode, x, word);
ccba022b
RS
1058 }
1059 else
1060 abort ();
1061}
1062
23b2ce53
RS
1063/* Return 1 iff X, assumed to be a SUBREG,
1064 refers to the least significant part of its containing reg.
1065 If X is not a SUBREG, always return 1 (it is its own low part!). */
1066
1067int
1068subreg_lowpart_p (x)
1069 rtx x;
1070{
1071 if (GET_CODE (x) != SUBREG)
1072 return 1;
a3a03040
RK
1073 else if (GET_MODE (SUBREG_REG (x)) == VOIDmode)
1074 return 0;
23b2ce53
RS
1075
1076 if (WORDS_BIG_ENDIAN
1077 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) > UNITS_PER_WORD)
1078 return (SUBREG_WORD (x)
1079 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
1080 - MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD))
1081 / UNITS_PER_WORD));
1082
1083 return SUBREG_WORD (x) == 0;
1084}
1085\f
1086/* Return subword I of operand OP.
1087 The word number, I, is interpreted as the word number starting at the
1088 low-order address. Word 0 is the low-order word if not WORDS_BIG_ENDIAN,
1089 otherwise it is the high-order word.
1090
1091 If we cannot extract the required word, we return zero. Otherwise, an
1092 rtx corresponding to the requested word will be returned.
1093
1094 VALIDATE_ADDRESS is nonzero if the address should be validated. Before
1095 reload has completed, a valid address will always be returned. After
1096 reload, if a valid address cannot be returned, we return zero.
1097
1098 If VALIDATE_ADDRESS is zero, we simply form the required address; validating
1099 it is the responsibility of the caller.
1100
1101 MODE is the mode of OP in case it is a CONST_INT. */
1102
1103rtx
1104operand_subword (op, i, validate_address, mode)
1105 rtx op;
1106 int i;
1107 int validate_address;
1108 enum machine_mode mode;
1109{
906c4e36
RK
1110 HOST_WIDE_INT val;
1111 int size_ratio = HOST_BITS_PER_WIDE_INT / BITS_PER_WORD;
23b2ce53
RS
1112
1113 if (mode == VOIDmode)
1114 mode = GET_MODE (op);
1115
1116 if (mode == VOIDmode)
1117 abort ();
1118
0003feb2 1119 /* If OP is narrower than a word, fail. */
23b2ce53 1120 if (mode != BLKmode
0003feb2 1121 && (GET_MODE_SIZE (mode) < UNITS_PER_WORD))
23b2ce53 1122 return 0;
0003feb2
VM
1123
1124 /* If we want a word outside OP, return zero. */
1125 if (mode != BLKmode
1126 && (i + 1) * UNITS_PER_WORD > GET_MODE_SIZE (mode))
1127 return const0_rtx;
23b2ce53
RS
1128
1129 /* If OP is already an integer word, return it. */
1130 if (GET_MODE_CLASS (mode) == MODE_INT
1131 && GET_MODE_SIZE (mode) == UNITS_PER_WORD)
1132 return op;
1133
1134 /* If OP is a REG or SUBREG, we can handle it very simply. */
1135 if (GET_CODE (op) == REG)
1136 {
227d6ce0
JL
1137 /* ??? There is a potential problem with this code. It does not
1138 properly handle extractions of a subword from a hard register
1139 that is larger than word_mode. Presumably the check for
1140 HARD_REGNO_MODE_OK catches these most of these cases. */
1141
1142 /* If OP is a hard register, but OP + I is not a hard register,
1143 then extracting a subword is impossible.
1144
1145 For example, consider if OP is the last hard register and it is
1146 larger than word_mode. If we wanted word N (for N > 0) because a
1147 part of that hard register was known to contain a useful value,
1148 then OP + I would refer to a pseudo, not the hard register we
1149 actually wanted. */
1150 if (REGNO (op) < FIRST_PSEUDO_REGISTER
1151 && REGNO (op) + i >= FIRST_PSEUDO_REGISTER)
1152 return 0;
1153
1154 /* If the register is not valid for MODE, return 0. Note we
1155 have to check both OP and OP + I since they may refer to
1156 different parts of the register file.
1157
1158 Consider if OP refers to the last 96bit FP register and we want
1159 subword 3 because that subword is known to contain a value we
1160 needed. */
23b2ce53 1161 if (REGNO (op) < FIRST_PSEUDO_REGISTER
227d6ce0
JL
1162 && (! HARD_REGNO_MODE_OK (REGNO (op), word_mode)
1163 || ! HARD_REGNO_MODE_OK (REGNO (op) + i, word_mode)))
23b2ce53
RS
1164 return 0;
1165 else if (REGNO (op) >= FIRST_PSEUDO_REGISTER
1166 || (REG_FUNCTION_VALUE_P (op)
cb00f51a
RK
1167 && rtx_equal_function_value_matters)
1168 /* We want to keep the stack, frame, and arg pointers
1169 special. */
65e8fe02 1170 || op == frame_pointer_rtx
cb00f51a 1171#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
65e8fe02 1172 || op == arg_pointer_rtx
cb00f51a 1173#endif
65e8fe02 1174 || op == stack_pointer_rtx)
3b80f6ca 1175 return gen_rtx_SUBREG (word_mode, op, i);
23b2ce53 1176 else
3b80f6ca 1177 return gen_rtx_REG (word_mode, REGNO (op) + i);
23b2ce53
RS
1178 }
1179 else if (GET_CODE (op) == SUBREG)
3b80f6ca 1180 return gen_rtx_SUBREG (word_mode, SUBREG_REG (op), i + SUBREG_WORD (op));
fc84e8a8
RS
1181 else if (GET_CODE (op) == CONCAT)
1182 {
1183 int partwords = GET_MODE_UNIT_SIZE (GET_MODE (op)) / UNITS_PER_WORD;
1184 if (i < partwords)
1185 return operand_subword (XEXP (op, 0), i, validate_address, mode);
1186 return operand_subword (XEXP (op, 1), i - partwords,
1187 validate_address, mode);
1188 }
23b2ce53
RS
1189
1190 /* Form a new MEM at the requested address. */
1191 if (GET_CODE (op) == MEM)
1192 {
1193 rtx addr = plus_constant (XEXP (op, 0), i * UNITS_PER_WORD);
1194 rtx new;
1195
1196 if (validate_address)
1197 {
1198 if (reload_completed)
1199 {
1200 if (! strict_memory_address_p (word_mode, addr))
1201 return 0;
1202 }
1203 else
1204 addr = memory_address (word_mode, addr);
1205 }
1206
3b80f6ca 1207 new = gen_rtx_MEM (word_mode, addr);
23b2ce53 1208
c6df88cb 1209 MEM_COPY_ATTRIBUTES (new, op);
23b2ce53 1210 RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (op);
d3707adb 1211 MEM_ALIAS_SET (new) = MEM_ALIAS_SET (op);
23b2ce53
RS
1212
1213 return new;
1214 }
1215
1216 /* The only remaining cases are when OP is a constant. If the host and
1217 target floating formats are the same, handling two-word floating
7677ffa4 1218 constants are easy. Note that REAL_VALUE_TO_TARGET_{SINGLE,DOUBLE}
9847c2f6
RK
1219 are defined as returning one or two 32 bit values, respectively,
1220 and not values of BITS_PER_WORD bits. */
1632afca 1221#ifdef REAL_ARITHMETIC
5495cc55
RH
1222 /* The output is some bits, the width of the target machine's word.
1223 A wider-word host can surely hold them in a CONST_INT. A narrower-word
1224 host can't. */
9847c2f6 1225 if (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
1632afca 1226 && GET_MODE_CLASS (mode) == MODE_FLOAT
7677ffa4 1227 && GET_MODE_BITSIZE (mode) == 64
1632afca
RS
1228 && GET_CODE (op) == CONST_DOUBLE)
1229 {
9847c2f6 1230 long k[2];
1632afca
RS
1231 REAL_VALUE_TYPE rv;
1232
1233 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1234 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
7677ffa4 1235
9847c2f6 1236 /* We handle 32-bit and >= 64-bit words here. Note that the order in
7677ffa4 1237 which the words are written depends on the word endianness.
7677ffa4 1238 ??? This is a potential portability problem and should
7cae975e
RH
1239 be fixed at some point.
1240
1241 We must excercise caution with the sign bit. By definition there
1242 are 32 significant bits in K; there may be more in a HOST_WIDE_INT.
1243 Consider a host with a 32-bit long and a 64-bit HOST_WIDE_INT.
1244 So we explicitly mask and sign-extend as necessary. */
9847c2f6 1245 if (BITS_PER_WORD == 32)
7cae975e
RH
1246 {
1247 val = k[i];
1248 val = ((val & 0xffffffff) ^ 0x80000000) - 0x80000000;
1249 return GEN_INT (val);
1250 }
1251#if HOST_BITS_PER_WIDE_INT >= 64
9847c2f6 1252 else if (BITS_PER_WORD >= 64 && i == 0)
7cae975e
RH
1253 {
1254 val = k[! WORDS_BIG_ENDIAN];
1255 val = (((val & 0xffffffff) ^ 0x80000000) - 0x80000000) << 32;
1256 val |= (HOST_WIDE_INT) k[WORDS_BIG_ENDIAN] & 0xffffffff;
1257 return GEN_INT (val);
1258 }
9847c2f6 1259#endif
47b34d40
JW
1260 else if (BITS_PER_WORD == 16)
1261 {
7cae975e
RH
1262 val = k[i >> 1];
1263 if ((i & 1) == !WORDS_BIG_ENDIAN)
1264 val >>= 16;
1265 val &= 0xffff;
1266 return GEN_INT (val);
47b34d40 1267 }
7677ffa4
RK
1268 else
1269 abort ();
1632afca 1270 }
a5559dbc
RE
1271 else if (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
1272 && GET_MODE_CLASS (mode) == MODE_FLOAT
1273 && GET_MODE_BITSIZE (mode) > 64
1274 && GET_CODE (op) == CONST_DOUBLE)
5495cc55
RH
1275 {
1276 long k[4];
1277 REAL_VALUE_TYPE rv;
a5559dbc 1278
5495cc55
RH
1279 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1280 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
a5559dbc 1281
5495cc55
RH
1282 if (BITS_PER_WORD == 32)
1283 {
1284 val = k[i];
1285 val = ((val & 0xffffffff) ^ 0x80000000) - 0x80000000;
1286 return GEN_INT (val);
1287 }
1288#if HOST_BITS_PER_WIDE_INT >= 64
1289 else if (BITS_PER_WORD >= 64 && i <= 1)
1290 {
1291 val = k[i*2 + ! WORDS_BIG_ENDIAN];
1292 val = (((val & 0xffffffff) ^ 0x80000000) - 0x80000000) << 32;
1293 val |= (HOST_WIDE_INT) k[i*2 + WORDS_BIG_ENDIAN] & 0xffffffff;
1294 return GEN_INT (val);
1295 }
1296#endif
1297 else
1298 abort ();
1299 }
1632afca 1300#else /* no REAL_ARITHMETIC */
23b2ce53 1301 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
906c4e36 1302 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
23b2ce53
RS
1303 || flag_pretend_float)
1304 && GET_MODE_CLASS (mode) == MODE_FLOAT
1305 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
1306 && GET_CODE (op) == CONST_DOUBLE)
7529ac93
CH
1307 {
1308 /* The constant is stored in the host's word-ordering,
1309 but we want to access it in the target's word-ordering. Some
1310 compilers don't like a conditional inside macro args, so we have two
1311 copies of the return. */
2fe02d7e 1312#ifdef HOST_WORDS_BIG_ENDIAN
7529ac93
CH
1313 return GEN_INT (i == WORDS_BIG_ENDIAN
1314 ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
2fe02d7e 1315#else
7529ac93
CH
1316 return GEN_INT (i != WORDS_BIG_ENDIAN
1317 ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
2fe02d7e 1318#endif
7529ac93 1319 }
1632afca 1320#endif /* no REAL_ARITHMETIC */
23b2ce53
RS
1321
1322 /* Single word float is a little harder, since single- and double-word
1323 values often do not have the same high-order bits. We have already
1324 verified that we want the only defined word of the single-word value. */
1632afca 1325#ifdef REAL_ARITHMETIC
9847c2f6 1326 if (GET_MODE_CLASS (mode) == MODE_FLOAT
7677ffa4 1327 && GET_MODE_BITSIZE (mode) == 32
1632afca
RS
1328 && GET_CODE (op) == CONST_DOUBLE)
1329 {
9847c2f6 1330 long l;
1632afca
RS
1331 REAL_VALUE_TYPE rv;
1332
1333 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1334 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
aa2ae679 1335
7cae975e
RH
1336 /* Sign extend from known 32-bit value to HOST_WIDE_INT. */
1337 val = l;
1338 val = ((val & 0xffffffff) ^ 0x80000000) - 0x80000000;
b5a3eb84 1339
aa2ae679
JL
1340 if (BITS_PER_WORD == 16)
1341 {
7cae975e
RH
1342 if ((i & 1) == !WORDS_BIG_ENDIAN)
1343 val >>= 16;
1344 val &= 0xffff;
aa2ae679 1345 }
7cae975e
RH
1346
1347 return GEN_INT (val);
1632afca
RS
1348 }
1349#else
23b2ce53 1350 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
906c4e36 1351 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
23b2ce53 1352 || flag_pretend_float)
e01a2cec 1353 && sizeof (float) * 8 == HOST_BITS_PER_WIDE_INT
23b2ce53
RS
1354 && GET_MODE_CLASS (mode) == MODE_FLOAT
1355 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
1356 && GET_CODE (op) == CONST_DOUBLE)
1357 {
1358 double d;
906c4e36 1359 union {float f; HOST_WIDE_INT i; } u;
23b2ce53
RS
1360
1361 REAL_VALUE_FROM_CONST_DOUBLE (d, op);
1362
1363 u.f = d;
906c4e36 1364 return GEN_INT (u.i);
23b2ce53 1365 }
e01a2cec
RK
1366 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1367 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1368 || flag_pretend_float)
1369 && sizeof (double) * 8 == HOST_BITS_PER_WIDE_INT
1370 && GET_MODE_CLASS (mode) == MODE_FLOAT
1371 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
1372 && GET_CODE (op) == CONST_DOUBLE)
1373 {
1374 double d;
1375 union {double d; HOST_WIDE_INT i; } u;
1376
1377 REAL_VALUE_FROM_CONST_DOUBLE (d, op);
1378
1379 u.d = d;
1380 return GEN_INT (u.i);
1381 }
1632afca 1382#endif /* no REAL_ARITHMETIC */
23b2ce53
RS
1383
1384 /* The only remaining cases that we can handle are integers.
1385 Convert to proper endianness now since these cases need it.
1386 At this point, i == 0 means the low-order word.
1387
2d4f57f8
RK
1388 We do not want to handle the case when BITS_PER_WORD <= HOST_BITS_PER_INT
1389 in general. However, if OP is (const_int 0), we can just return
1390 it for any word. */
1391
1392 if (op == const0_rtx)
1393 return op;
23b2ce53
RS
1394
1395 if (GET_MODE_CLASS (mode) != MODE_INT
2d4f57f8 1396 || (GET_CODE (op) != CONST_INT && GET_CODE (op) != CONST_DOUBLE)
0cf214a0 1397 || BITS_PER_WORD > HOST_BITS_PER_WIDE_INT)
23b2ce53
RS
1398 return 0;
1399
1400 if (WORDS_BIG_ENDIAN)
1401 i = GET_MODE_SIZE (mode) / UNITS_PER_WORD - 1 - i;
1402
1403 /* Find out which word on the host machine this value is in and get
1404 it from the constant. */
1405 val = (i / size_ratio == 0
1406 ? (GET_CODE (op) == CONST_INT ? INTVAL (op) : CONST_DOUBLE_LOW (op))
1407 : (GET_CODE (op) == CONST_INT
1408 ? (INTVAL (op) < 0 ? ~0 : 0) : CONST_DOUBLE_HIGH (op)));
1409
3f518020 1410 /* Get the value we want into the low bits of val. */
906c4e36 1411 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT)
3f518020
JL
1412 val = ((val >> ((i % size_ratio) * BITS_PER_WORD)));
1413
7e4ce834 1414 val = trunc_int_for_mode (val, word_mode);
23b2ce53 1415
906c4e36 1416 return GEN_INT (val);
23b2ce53
RS
1417}
1418
1419/* Similar to `operand_subword', but never return 0. If we can't extract
1420 the required subword, put OP into a register and try again. If that fails,
1421 abort. We always validate the address in this case. It is not valid
1422 to call this function after reload; it is mostly meant for RTL
1423 generation.
1424
1425 MODE is the mode of OP, in case it is CONST_INT. */
1426
1427rtx
1428operand_subword_force (op, i, mode)
1429 rtx op;
1430 int i;
1431 enum machine_mode mode;
1432{
1433 rtx result = operand_subword (op, i, 1, mode);
1434
1435 if (result)
1436 return result;
1437
1438 if (mode != BLKmode && mode != VOIDmode)
77e6b0eb
JC
1439 {
1440 /* If this is a register which can not be accessed by words, copy it
1441 to a pseudo register. */
1442 if (GET_CODE (op) == REG)
1443 op = copy_to_reg (op);
1444 else
1445 op = force_reg (mode, op);
1446 }
23b2ce53
RS
1447
1448 result = operand_subword (op, i, 1, mode);
1449 if (result == 0)
1450 abort ();
1451
1452 return result;
1453}
1454\f
1455/* Given a compare instruction, swap the operands.
1456 A test instruction is changed into a compare of 0 against the operand. */
1457
1458void
1459reverse_comparison (insn)
1460 rtx insn;
1461{
1462 rtx body = PATTERN (insn);
1463 rtx comp;
1464
1465 if (GET_CODE (body) == SET)
1466 comp = SET_SRC (body);
1467 else
1468 comp = SET_SRC (XVECEXP (body, 0, 0));
1469
1470 if (GET_CODE (comp) == COMPARE)
1471 {
1472 rtx op0 = XEXP (comp, 0);
1473 rtx op1 = XEXP (comp, 1);
1474 XEXP (comp, 0) = op1;
1475 XEXP (comp, 1) = op0;
1476 }
1477 else
1478 {
c5c76735
JL
1479 rtx new = gen_rtx_COMPARE (VOIDmode,
1480 CONST0_RTX (GET_MODE (comp)), comp);
23b2ce53
RS
1481 if (GET_CODE (body) == SET)
1482 SET_SRC (body) = new;
1483 else
1484 SET_SRC (XVECEXP (body, 0, 0)) = new;
1485 }
1486}
1487\f
1488/* Return a memory reference like MEMREF, but with its mode changed
1489 to MODE and its address changed to ADDR.
1490 (VOIDmode means don't change the mode.
1491 NULL for ADDR means don't change the address.) */
1492
1493rtx
1494change_address (memref, mode, addr)
1495 rtx memref;
1496 enum machine_mode mode;
1497 rtx addr;
1498{
1499 rtx new;
1500
1501 if (GET_CODE (memref) != MEM)
1502 abort ();
1503 if (mode == VOIDmode)
1504 mode = GET_MODE (memref);
1505 if (addr == 0)
1506 addr = XEXP (memref, 0);
1507
1508 /* If reload is in progress or has completed, ADDR must be valid.
1509 Otherwise, we can call memory_address to make it valid. */
1510 if (reload_completed || reload_in_progress)
1511 {
1512 if (! memory_address_p (mode, addr))
1513 abort ();
1514 }
1515 else
1516 addr = memory_address (mode, addr);
1517
9b04c6a8
RK
1518 if (rtx_equal_p (addr, XEXP (memref, 0)) && mode == GET_MODE (memref))
1519 return memref;
1520
3b80f6ca 1521 new = gen_rtx_MEM (mode, addr);
23b2ce53 1522 RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (memref);
c6df88cb 1523 MEM_COPY_ATTRIBUTES (new, memref);
d3707adb 1524 MEM_ALIAS_SET (new) = MEM_ALIAS_SET (memref);
23b2ce53
RS
1525 return new;
1526}
1527\f
1528/* Return a newly created CODE_LABEL rtx with a unique label number. */
1529
1530rtx
1531gen_label_rtx ()
1532{
ca695ac9
JB
1533 register rtx label;
1534
b93a436e 1535 label = gen_rtx_CODE_LABEL (VOIDmode, 0, NULL_RTX,
8cd0faaf 1536 NULL_RTX, label_num++, NULL_PTR, NULL_PTR);
ca695ac9 1537
23b2ce53 1538 LABEL_NUSES (label) = 0;
8cd0faaf 1539 LABEL_ALTERNATE_NAME (label) = NULL;
23b2ce53
RS
1540 return label;
1541}
1542\f
1543/* For procedure integration. */
1544
23b2ce53 1545/* Install new pointers to the first and last insns in the chain.
86fe05e0 1546 Also, set cur_insn_uid to one higher than the last in use.
23b2ce53
RS
1547 Used for an inline-procedure after copying the insn chain. */
1548
1549void
1550set_new_first_and_last_insn (first, last)
1551 rtx first, last;
1552{
86fe05e0
RK
1553 rtx insn;
1554
23b2ce53
RS
1555 first_insn = first;
1556 last_insn = last;
86fe05e0
RK
1557 cur_insn_uid = 0;
1558
1559 for (insn = first; insn; insn = NEXT_INSN (insn))
1560 cur_insn_uid = MAX (cur_insn_uid, INSN_UID (insn));
1561
1562 cur_insn_uid++;
23b2ce53
RS
1563}
1564
1565/* Set the range of label numbers found in the current function.
1566 This is used when belatedly compiling an inline function. */
1567
1568void
1569set_new_first_and_last_label_num (first, last)
1570 int first, last;
1571{
1572 base_label_num = label_num;
1573 first_label_num = first;
1574 last_label_num = last;
1575}
49ad7cfa
BS
1576
1577/* Set the last label number found in the current function.
1578 This is used when belatedly compiling an inline function. */
23b2ce53
RS
1579
1580void
49ad7cfa
BS
1581set_new_last_label_num (last)
1582 int last;
23b2ce53 1583{
49ad7cfa
BS
1584 base_label_num = label_num;
1585 last_label_num = last;
23b2ce53 1586}
49ad7cfa 1587\f
23b2ce53
RS
1588/* Restore all variables describing the current status from the structure *P.
1589 This is used after a nested function. */
1590
1591void
1592restore_emit_status (p)
272df862 1593 struct function *p ATTRIBUTE_UNUSED;
23b2ce53 1594{
457a2d9c 1595 last_label_num = 0;
49ad7cfa 1596 clear_emit_caches ();
23b2ce53 1597}
e2ecd91c 1598
21cd906e 1599/* Clear out all parts of the state in F that can safely be discarded
e2ecd91c 1600 after the function has been compiled, to let garbage collection
0a8a198c 1601 reclaim the memory. */
21cd906e 1602
e2ecd91c 1603void
0a8a198c 1604free_emit_status (f)
e2ecd91c
BS
1605 struct function *f;
1606{
1607 free (f->emit->x_regno_reg_rtx);
1608 free (f->emit->regno_pointer_flag);
1609 free (f->emit->regno_pointer_align);
fa51b01b
RH
1610 free (f->emit);
1611 f->emit = NULL;
e2ecd91c 1612}
23b2ce53 1613\f
d1b81779
GK
1614/* Go through all the RTL insn bodies and copy any invalid shared
1615 structure. This routine should only be called once. */
23b2ce53
RS
1616
1617void
d1b81779
GK
1618unshare_all_rtl (fndecl, insn)
1619 tree fndecl;
1620 rtx insn;
23b2ce53 1621{
d1b81779 1622 tree decl;
23b2ce53 1623
d1b81779
GK
1624 /* Make sure that virtual parameters are not shared. */
1625 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
1626 {
1627 copy_rtx_if_shared (DECL_RTL (decl));
1628 }
1629
1630 /* Unshare just about everything else. */
1631 unshare_all_rtl_1 (insn);
1632
23b2ce53
RS
1633 /* Make sure the addresses of stack slots found outside the insn chain
1634 (such as, in DECL_RTL of a variable) are not shared
1635 with the insn chain.
1636
1637 This special care is necessary when the stack slot MEM does not
1638 actually appear in the insn chain. If it does appear, its address
1639 is unshared from all else at that point. */
23b2ce53
RS
1640 copy_rtx_if_shared (stack_slot_list);
1641}
1642
d1b81779
GK
1643/* Go through all the RTL insn bodies and copy any invalid shared
1644 structure, again. This is a fairly expensive thing to do so it
1645 should be done sparingly. */
1646
1647void
1648unshare_all_rtl_again (insn)
1649 rtx insn;
1650{
1651 rtx p;
1652 for (p = insn; p; p = NEXT_INSN (p))
1653 if (GET_RTX_CLASS (GET_CODE (p)) == 'i')
1654 {
1655 reset_used_flags (PATTERN (p));
1656 reset_used_flags (REG_NOTES (p));
1657 reset_used_flags (LOG_LINKS (p));
1658 }
1659 unshare_all_rtl_1 (insn);
1660}
1661
1662/* Go through all the RTL insn bodies and copy any invalid shared structure.
1663 Assumes the mark bits are cleared at entry. */
1664
1665static void
1666unshare_all_rtl_1 (insn)
1667 rtx insn;
1668{
1669 for (; insn; insn = NEXT_INSN (insn))
1670 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
1671 {
1672 PATTERN (insn) = copy_rtx_if_shared (PATTERN (insn));
1673 REG_NOTES (insn) = copy_rtx_if_shared (REG_NOTES (insn));
1674 LOG_LINKS (insn) = copy_rtx_if_shared (LOG_LINKS (insn));
1675 }
1676}
1677
23b2ce53
RS
1678/* Mark ORIG as in use, and return a copy of it if it was already in use.
1679 Recursively does the same for subexpressions. */
1680
1681rtx
1682copy_rtx_if_shared (orig)
1683 rtx orig;
1684{
1685 register rtx x = orig;
1686 register int i;
1687 register enum rtx_code code;
6f7d635c 1688 register const char *format_ptr;
23b2ce53
RS
1689 int copied = 0;
1690
1691 if (x == 0)
1692 return 0;
1693
1694 code = GET_CODE (x);
1695
1696 /* These types may be freely shared. */
1697
1698 switch (code)
1699 {
1700 case REG:
1701 case QUEUED:
1702 case CONST_INT:
1703 case CONST_DOUBLE:
1704 case SYMBOL_REF:
1705 case CODE_LABEL:
1706 case PC:
1707 case CC0:
1708 case SCRATCH:
0f41302f 1709 /* SCRATCH must be shared because they represent distinct values. */
23b2ce53
RS
1710 return x;
1711
b851ea09
RK
1712 case CONST:
1713 /* CONST can be shared if it contains a SYMBOL_REF. If it contains
1714 a LABEL_REF, it isn't sharable. */
1715 if (GET_CODE (XEXP (x, 0)) == PLUS
1716 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
1717 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
1718 return x;
1719 break;
1720
23b2ce53
RS
1721 case INSN:
1722 case JUMP_INSN:
1723 case CALL_INSN:
1724 case NOTE:
23b2ce53
RS
1725 case BARRIER:
1726 /* The chain of insns is not being copied. */
1727 return x;
1728
1729 case MEM:
83512665
JL
1730 /* A MEM is allowed to be shared if its address is constant.
1731
1732 We used to allow sharing of MEMs which referenced
1733 virtual_stack_vars_rtx or virtual_incoming_args_rtx, but
1734 that can lose. instantiate_virtual_regs will not unshare
1735 the MEMs, and combine may change the structure of the address
1736 because it looks safe and profitable in one context, but
1737 in some other context it creates unrecognizable RTL. */
1738 if (CONSTANT_ADDRESS_P (XEXP (x, 0)))
23b2ce53
RS
1739 return x;
1740
e9a25f70
JL
1741 break;
1742
1743 default:
1744 break;
23b2ce53
RS
1745 }
1746
1747 /* This rtx may not be shared. If it has already been seen,
1748 replace it with a copy of itself. */
1749
1750 if (x->used)
1751 {
1752 register rtx copy;
1753
1754 copy = rtx_alloc (code);
4c9a05bc
RK
1755 bcopy ((char *) x, (char *) copy,
1756 (sizeof (*copy) - sizeof (copy->fld)
1757 + sizeof (copy->fld[0]) * GET_RTX_LENGTH (code)));
23b2ce53
RS
1758 x = copy;
1759 copied = 1;
1760 }
1761 x->used = 1;
1762
1763 /* Now scan the subexpressions recursively.
1764 We can store any replaced subexpressions directly into X
1765 since we know X is not shared! Any vectors in X
1766 must be copied if X was copied. */
1767
1768 format_ptr = GET_RTX_FORMAT (code);
1769
1770 for (i = 0; i < GET_RTX_LENGTH (code); i++)
1771 {
1772 switch (*format_ptr++)
1773 {
1774 case 'e':
1775 XEXP (x, i) = copy_rtx_if_shared (XEXP (x, i));
1776 break;
1777
1778 case 'E':
1779 if (XVEC (x, i) != NULL)
1780 {
1781 register int j;
f0722107 1782 int len = XVECLEN (x, i);
23b2ce53 1783
f0722107 1784 if (copied && len > 0)
8f985ec4 1785 XVEC (x, i) = gen_rtvec_v (len, XVEC (x, i)->elem);
f0722107
RS
1786 for (j = 0; j < len; j++)
1787 XVECEXP (x, i, j) = copy_rtx_if_shared (XVECEXP (x, i, j));
23b2ce53
RS
1788 }
1789 break;
1790 }
1791 }
1792 return x;
1793}
1794
1795/* Clear all the USED bits in X to allow copy_rtx_if_shared to be used
1796 to look for shared sub-parts. */
1797
1798void
1799reset_used_flags (x)
1800 rtx x;
1801{
1802 register int i, j;
1803 register enum rtx_code code;
6f7d635c 1804 register const char *format_ptr;
23b2ce53
RS
1805
1806 if (x == 0)
1807 return;
1808
1809 code = GET_CODE (x);
1810
9faa82d8 1811 /* These types may be freely shared so we needn't do any resetting
23b2ce53
RS
1812 for them. */
1813
1814 switch (code)
1815 {
1816 case REG:
1817 case QUEUED:
1818 case CONST_INT:
1819 case CONST_DOUBLE:
1820 case SYMBOL_REF:
1821 case CODE_LABEL:
1822 case PC:
1823 case CC0:
1824 return;
1825
1826 case INSN:
1827 case JUMP_INSN:
1828 case CALL_INSN:
1829 case NOTE:
1830 case LABEL_REF:
1831 case BARRIER:
1832 /* The chain of insns is not being copied. */
1833 return;
e9a25f70
JL
1834
1835 default:
1836 break;
23b2ce53
RS
1837 }
1838
1839 x->used = 0;
1840
1841 format_ptr = GET_RTX_FORMAT (code);
1842 for (i = 0; i < GET_RTX_LENGTH (code); i++)
1843 {
1844 switch (*format_ptr++)
1845 {
1846 case 'e':
1847 reset_used_flags (XEXP (x, i));
1848 break;
1849
1850 case 'E':
1851 for (j = 0; j < XVECLEN (x, i); j++)
1852 reset_used_flags (XVECEXP (x, i, j));
1853 break;
1854 }
1855 }
1856}
1857\f
1858/* Copy X if necessary so that it won't be altered by changes in OTHER.
1859 Return X or the rtx for the pseudo reg the value of X was copied into.
1860 OTHER must be valid as a SET_DEST. */
1861
1862rtx
1863make_safe_from (x, other)
1864 rtx x, other;
1865{
1866 while (1)
1867 switch (GET_CODE (other))
1868 {
1869 case SUBREG:
1870 other = SUBREG_REG (other);
1871 break;
1872 case STRICT_LOW_PART:
1873 case SIGN_EXTEND:
1874 case ZERO_EXTEND:
1875 other = XEXP (other, 0);
1876 break;
1877 default:
1878 goto done;
1879 }
1880 done:
1881 if ((GET_CODE (other) == MEM
1882 && ! CONSTANT_P (x)
1883 && GET_CODE (x) != REG
1884 && GET_CODE (x) != SUBREG)
1885 || (GET_CODE (other) == REG
1886 && (REGNO (other) < FIRST_PSEUDO_REGISTER
1887 || reg_mentioned_p (other, x))))
1888 {
1889 rtx temp = gen_reg_rtx (GET_MODE (x));
1890 emit_move_insn (temp, x);
1891 return temp;
1892 }
1893 return x;
1894}
1895\f
1896/* Emission of insns (adding them to the doubly-linked list). */
1897
1898/* Return the first insn of the current sequence or current function. */
1899
1900rtx
1901get_insns ()
1902{
1903 return first_insn;
1904}
1905
1906/* Return the last insn emitted in current sequence or current function. */
1907
1908rtx
1909get_last_insn ()
1910{
1911 return last_insn;
1912}
1913
1914/* Specify a new insn as the last in the chain. */
1915
1916void
1917set_last_insn (insn)
1918 rtx insn;
1919{
1920 if (NEXT_INSN (insn) != 0)
1921 abort ();
1922 last_insn = insn;
1923}
1924
1925/* Return the last insn emitted, even if it is in a sequence now pushed. */
1926
1927rtx
1928get_last_insn_anywhere ()
1929{
1930 struct sequence_stack *stack;
1931 if (last_insn)
1932 return last_insn;
49ad7cfa 1933 for (stack = seq_stack; stack; stack = stack->next)
23b2ce53
RS
1934 if (stack->last != 0)
1935 return stack->last;
1936 return 0;
1937}
1938
1939/* Return a number larger than any instruction's uid in this function. */
1940
1941int
1942get_max_uid ()
1943{
1944 return cur_insn_uid;
1945}
aeeeda03 1946
673b5311
MM
1947/* Renumber instructions so that no instruction UIDs are wasted. */
1948
aeeeda03 1949void
673b5311
MM
1950renumber_insns (stream)
1951 FILE *stream;
aeeeda03
MM
1952{
1953 rtx insn;
aeeeda03 1954
673b5311
MM
1955 /* If we're not supposed to renumber instructions, don't. */
1956 if (!flag_renumber_insns)
1957 return;
1958
aeeeda03
MM
1959 /* If there aren't that many instructions, then it's not really
1960 worth renumbering them. */
673b5311 1961 if (flag_renumber_insns == 1 && get_max_uid () < 25000)
aeeeda03
MM
1962 return;
1963
1964 cur_insn_uid = 1;
1965
1966 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
673b5311
MM
1967 {
1968 if (stream)
1969 fprintf (stream, "Renumbering insn %d to %d\n",
1970 INSN_UID (insn), cur_insn_uid);
1971 INSN_UID (insn) = cur_insn_uid++;
1972 }
aeeeda03 1973}
23b2ce53
RS
1974\f
1975/* Return the next insn. If it is a SEQUENCE, return the first insn
1976 of the sequence. */
1977
1978rtx
1979next_insn (insn)
1980 rtx insn;
1981{
1982 if (insn)
1983 {
1984 insn = NEXT_INSN (insn);
1985 if (insn && GET_CODE (insn) == INSN
1986 && GET_CODE (PATTERN (insn)) == SEQUENCE)
1987 insn = XVECEXP (PATTERN (insn), 0, 0);
1988 }
1989
1990 return insn;
1991}
1992
1993/* Return the previous insn. If it is a SEQUENCE, return the last insn
1994 of the sequence. */
1995
1996rtx
1997previous_insn (insn)
1998 rtx insn;
1999{
2000 if (insn)
2001 {
2002 insn = PREV_INSN (insn);
2003 if (insn && GET_CODE (insn) == INSN
2004 && GET_CODE (PATTERN (insn)) == SEQUENCE)
2005 insn = XVECEXP (PATTERN (insn), 0, XVECLEN (PATTERN (insn), 0) - 1);
2006 }
2007
2008 return insn;
2009}
2010
2011/* Return the next insn after INSN that is not a NOTE. This routine does not
2012 look inside SEQUENCEs. */
2013
2014rtx
2015next_nonnote_insn (insn)
2016 rtx insn;
2017{
2018 while (insn)
2019 {
2020 insn = NEXT_INSN (insn);
2021 if (insn == 0 || GET_CODE (insn) != NOTE)
2022 break;
2023 }
2024
2025 return insn;
2026}
2027
2028/* Return the previous insn before INSN that is not a NOTE. This routine does
2029 not look inside SEQUENCEs. */
2030
2031rtx
2032prev_nonnote_insn (insn)
2033 rtx insn;
2034{
2035 while (insn)
2036 {
2037 insn = PREV_INSN (insn);
2038 if (insn == 0 || GET_CODE (insn) != NOTE)
2039 break;
2040 }
2041
2042 return insn;
2043}
2044
2045/* Return the next INSN, CALL_INSN or JUMP_INSN after INSN;
2046 or 0, if there is none. This routine does not look inside
0f41302f 2047 SEQUENCEs. */
23b2ce53
RS
2048
2049rtx
2050next_real_insn (insn)
2051 rtx insn;
2052{
2053 while (insn)
2054 {
2055 insn = NEXT_INSN (insn);
2056 if (insn == 0 || GET_CODE (insn) == INSN
2057 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN)
2058 break;
2059 }
2060
2061 return insn;
2062}
2063
2064/* Return the last INSN, CALL_INSN or JUMP_INSN before INSN;
2065 or 0, if there is none. This routine does not look inside
2066 SEQUENCEs. */
2067
2068rtx
2069prev_real_insn (insn)
2070 rtx insn;
2071{
2072 while (insn)
2073 {
2074 insn = PREV_INSN (insn);
2075 if (insn == 0 || GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
2076 || GET_CODE (insn) == JUMP_INSN)
2077 break;
2078 }
2079
2080 return insn;
2081}
2082
2083/* Find the next insn after INSN that really does something. This routine
2084 does not look inside SEQUENCEs. Until reload has completed, this is the
2085 same as next_real_insn. */
2086
69732dcb
RH
2087int
2088active_insn_p (insn)
2089 rtx insn;
2090{
2091 return (GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN
2092 || (GET_CODE (insn) == INSN
2093 && (! reload_completed
2094 || (GET_CODE (PATTERN (insn)) != USE
2095 && GET_CODE (PATTERN (insn)) != CLOBBER))));
2096}
2097
23b2ce53
RS
2098rtx
2099next_active_insn (insn)
2100 rtx insn;
2101{
2102 while (insn)
2103 {
2104 insn = NEXT_INSN (insn);
69732dcb 2105 if (insn == 0 || active_insn_p (insn))
23b2ce53
RS
2106 break;
2107 }
2108
2109 return insn;
2110}
2111
2112/* Find the last insn before INSN that really does something. This routine
2113 does not look inside SEQUENCEs. Until reload has completed, this is the
2114 same as prev_real_insn. */
2115
2116rtx
2117prev_active_insn (insn)
2118 rtx insn;
2119{
2120 while (insn)
2121 {
2122 insn = PREV_INSN (insn);
69732dcb 2123 if (insn == 0 || active_insn_p (insn))
23b2ce53
RS
2124 break;
2125 }
2126
2127 return insn;
2128}
2129
2130/* Return the next CODE_LABEL after the insn INSN, or 0 if there is none. */
2131
2132rtx
2133next_label (insn)
2134 rtx insn;
2135{
2136 while (insn)
2137 {
2138 insn = NEXT_INSN (insn);
2139 if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
2140 break;
2141 }
2142
2143 return insn;
2144}
2145
2146/* Return the last CODE_LABEL before the insn INSN, or 0 if there is none. */
2147
2148rtx
2149prev_label (insn)
2150 rtx insn;
2151{
2152 while (insn)
2153 {
2154 insn = PREV_INSN (insn);
2155 if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
2156 break;
2157 }
2158
2159 return insn;
2160}
2161\f
2162#ifdef HAVE_cc0
c572e5ba
JVA
2163/* INSN uses CC0 and is being moved into a delay slot. Set up REG_CC_SETTER
2164 and REG_CC_USER notes so we can find it. */
2165
2166void
2167link_cc0_insns (insn)
2168 rtx insn;
2169{
2170 rtx user = next_nonnote_insn (insn);
2171
2172 if (GET_CODE (user) == INSN && GET_CODE (PATTERN (user)) == SEQUENCE)
2173 user = XVECEXP (PATTERN (user), 0, 0);
2174
c5c76735
JL
2175 REG_NOTES (user) = gen_rtx_INSN_LIST (REG_CC_SETTER, insn,
2176 REG_NOTES (user));
3b80f6ca 2177 REG_NOTES (insn) = gen_rtx_INSN_LIST (REG_CC_USER, user, REG_NOTES (insn));
c572e5ba
JVA
2178}
2179
23b2ce53
RS
2180/* Return the next insn that uses CC0 after INSN, which is assumed to
2181 set it. This is the inverse of prev_cc0_setter (i.e., prev_cc0_setter
2182 applied to the result of this function should yield INSN).
2183
2184 Normally, this is simply the next insn. However, if a REG_CC_USER note
2185 is present, it contains the insn that uses CC0.
2186
2187 Return 0 if we can't find the insn. */
2188
2189rtx
2190next_cc0_user (insn)
2191 rtx insn;
2192{
906c4e36 2193 rtx note = find_reg_note (insn, REG_CC_USER, NULL_RTX);
23b2ce53
RS
2194
2195 if (note)
2196 return XEXP (note, 0);
2197
2198 insn = next_nonnote_insn (insn);
2199 if (insn && GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
2200 insn = XVECEXP (PATTERN (insn), 0, 0);
2201
2202 if (insn && GET_RTX_CLASS (GET_CODE (insn)) == 'i'
2203 && reg_mentioned_p (cc0_rtx, PATTERN (insn)))
2204 return insn;
2205
2206 return 0;
2207}
2208
2209/* Find the insn that set CC0 for INSN. Unless INSN has a REG_CC_SETTER
2210 note, it is the previous insn. */
2211
2212rtx
2213prev_cc0_setter (insn)
2214 rtx insn;
2215{
906c4e36 2216 rtx note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
23b2ce53
RS
2217
2218 if (note)
2219 return XEXP (note, 0);
2220
2221 insn = prev_nonnote_insn (insn);
2222 if (! sets_cc0_p (PATTERN (insn)))
2223 abort ();
2224
2225 return insn;
2226}
2227#endif
2228\f
2229/* Try splitting insns that can be split for better scheduling.
2230 PAT is the pattern which might split.
2231 TRIAL is the insn providing PAT.
11147ebe 2232 LAST is non-zero if we should return the last insn of the sequence produced.
23b2ce53
RS
2233
2234 If this routine succeeds in splitting, it returns the first or last
11147ebe 2235 replacement insn depending on the value of LAST. Otherwise, it
23b2ce53
RS
2236 returns TRIAL. If the insn to be returned can be split, it will be. */
2237
2238rtx
11147ebe 2239try_split (pat, trial, last)
23b2ce53 2240 rtx pat, trial;
11147ebe 2241 int last;
23b2ce53
RS
2242{
2243 rtx before = PREV_INSN (trial);
2244 rtx after = NEXT_INSN (trial);
2245 rtx seq = split_insns (pat, trial);
2246 int has_barrier = 0;
2247 rtx tem;
2248
2249 /* If we are splitting a JUMP_INSN, it might be followed by a BARRIER.
2250 We may need to handle this specially. */
2251 if (after && GET_CODE (after) == BARRIER)
2252 {
2253 has_barrier = 1;
2254 after = NEXT_INSN (after);
2255 }
2256
2257 if (seq)
2258 {
2259 /* SEQ can either be a SEQUENCE or the pattern of a single insn.
2260 The latter case will normally arise only when being done so that
2261 it, in turn, will be split (SFmode on the 29k is an example). */
2262 if (GET_CODE (seq) == SEQUENCE)
2263 {
2264 /* If we are splitting a JUMP_INSN, look for the JUMP_INSN in
2265 SEQ and copy our JUMP_LABEL to it. If JUMP_LABEL is non-zero,
2266 increment the usage count so we don't delete the label. */
2267 int i;
2268
2269 if (GET_CODE (trial) == JUMP_INSN)
2270 for (i = XVECLEN (seq, 0) - 1; i >= 0; i--)
2271 if (GET_CODE (XVECEXP (seq, 0, i)) == JUMP_INSN)
2272 {
2273 JUMP_LABEL (XVECEXP (seq, 0, i)) = JUMP_LABEL (trial);
2274
2275 if (JUMP_LABEL (trial))
2276 LABEL_NUSES (JUMP_LABEL (trial))++;
2277 }
2278
2279 tem = emit_insn_after (seq, before);
2280
2281 delete_insn (trial);
2282 if (has_barrier)
2283 emit_barrier_after (tem);
11147ebe
RK
2284
2285 /* Recursively call try_split for each new insn created; by the
2286 time control returns here that insn will be fully split, so
2287 set LAST and continue from the insn after the one returned.
f4a3cd05 2288 We can't use next_active_insn here since AFTER may be a note.
23886015 2289 Ignore deleted insns, which can be occur if not optimizing. */
11147ebe
RK
2290 for (tem = NEXT_INSN (before); tem != after;
2291 tem = NEXT_INSN (tem))
23886015
RH
2292 if (! INSN_DELETED_P (tem)
2293 && GET_RTX_CLASS (GET_CODE (tem)) == 'i')
f4a3cd05 2294 tem = try_split (PATTERN (tem), tem, 1);
23b2ce53
RS
2295 }
2296 /* Avoid infinite loop if the result matches the original pattern. */
2297 else if (rtx_equal_p (seq, pat))
2298 return trial;
2299 else
2300 {
2301 PATTERN (trial) = seq;
2302 INSN_CODE (trial) = -1;
11147ebe 2303 try_split (seq, trial, last);
23b2ce53
RS
2304 }
2305
11147ebe
RK
2306 /* Return either the first or the last insn, depending on which was
2307 requested. */
ba52f355
CP
2308 return last
2309 ? (after ? prev_active_insn (after) : last_insn)
2310 : next_active_insn (before);
23b2ce53
RS
2311 }
2312
2313 return trial;
2314}
2315\f
2316/* Make and return an INSN rtx, initializing all its slots.
4b1f5e8c 2317 Store PATTERN in the pattern slots. */
23b2ce53
RS
2318
2319rtx
4b1f5e8c 2320make_insn_raw (pattern)
23b2ce53 2321 rtx pattern;
23b2ce53
RS
2322{
2323 register rtx insn;
2324
43127294 2325 /* If in RTL generation phase, see if FREE_INSN can be used. */
a3770a81 2326 if (!ggc_p && free_insn != 0 && rtx_equal_function_value_matters)
43127294
RK
2327 {
2328 insn = free_insn;
2329 free_insn = NEXT_INSN (free_insn);
2330 PUT_CODE (insn, INSN);
2331 }
2332 else
2333 insn = rtx_alloc (INSN);
23b2ce53 2334
43127294 2335 INSN_UID (insn) = cur_insn_uid++;
23b2ce53
RS
2336 PATTERN (insn) = pattern;
2337 INSN_CODE (insn) = -1;
1632afca
RS
2338 LOG_LINKS (insn) = NULL;
2339 REG_NOTES (insn) = NULL;
23b2ce53
RS
2340
2341 return insn;
2342}
2343
2344/* Like `make_insn' but make a JUMP_INSN instead of an insn. */
2345
2346static rtx
4b1f5e8c 2347make_jump_insn_raw (pattern)
23b2ce53 2348 rtx pattern;
23b2ce53
RS
2349{
2350 register rtx insn;
2351
4b1f5e8c 2352 insn = rtx_alloc (JUMP_INSN);
1632afca 2353 INSN_UID (insn) = cur_insn_uid++;
23b2ce53
RS
2354
2355 PATTERN (insn) = pattern;
2356 INSN_CODE (insn) = -1;
1632afca
RS
2357 LOG_LINKS (insn) = NULL;
2358 REG_NOTES (insn) = NULL;
2359 JUMP_LABEL (insn) = NULL;
23b2ce53
RS
2360
2361 return insn;
2362}
aff507f4
RK
2363
2364/* Like `make_insn' but make a CALL_INSN instead of an insn. */
2365
2366static rtx
2367make_call_insn_raw (pattern)
2368 rtx pattern;
2369{
2370 register rtx insn;
2371
2372 insn = rtx_alloc (CALL_INSN);
2373 INSN_UID (insn) = cur_insn_uid++;
2374
2375 PATTERN (insn) = pattern;
2376 INSN_CODE (insn) = -1;
2377 LOG_LINKS (insn) = NULL;
2378 REG_NOTES (insn) = NULL;
2379 CALL_INSN_FUNCTION_USAGE (insn) = NULL;
2380
2381 return insn;
2382}
23b2ce53
RS
2383\f
2384/* Add INSN to the end of the doubly-linked list.
2385 INSN may be an INSN, JUMP_INSN, CALL_INSN, CODE_LABEL, BARRIER or NOTE. */
2386
2387void
2388add_insn (insn)
2389 register rtx insn;
2390{
2391 PREV_INSN (insn) = last_insn;
2392 NEXT_INSN (insn) = 0;
2393
2394 if (NULL != last_insn)
2395 NEXT_INSN (last_insn) = insn;
2396
2397 if (NULL == first_insn)
2398 first_insn = insn;
2399
2400 last_insn = insn;
2401}
2402
a0ae8e8d
RK
2403/* Add INSN into the doubly-linked list after insn AFTER. This and
2404 the next should be the only functions called to insert an insn once
ba213285 2405 delay slots have been filled since only they know how to update a
a0ae8e8d 2406 SEQUENCE. */
23b2ce53
RS
2407
2408void
2409add_insn_after (insn, after)
2410 rtx insn, after;
2411{
2412 rtx next = NEXT_INSN (after);
2413
6782074d 2414 if (optimize && INSN_DELETED_P (after))
ba213285
RK
2415 abort ();
2416
23b2ce53
RS
2417 NEXT_INSN (insn) = next;
2418 PREV_INSN (insn) = after;
2419
2420 if (next)
2421 {
2422 PREV_INSN (next) = insn;
2423 if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == SEQUENCE)
2424 PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = insn;
2425 }
2426 else if (last_insn == after)
2427 last_insn = insn;
2428 else
2429 {
49ad7cfa 2430 struct sequence_stack *stack = seq_stack;
23b2ce53
RS
2431 /* Scan all pending sequences too. */
2432 for (; stack; stack = stack->next)
2433 if (after == stack->last)
fef0509b
RK
2434 {
2435 stack->last = insn;
2436 break;
2437 }
a0ae8e8d
RK
2438
2439 if (stack == 0)
2440 abort ();
23b2ce53
RS
2441 }
2442
2443 NEXT_INSN (after) = insn;
2444 if (GET_CODE (after) == INSN && GET_CODE (PATTERN (after)) == SEQUENCE)
2445 {
2446 rtx sequence = PATTERN (after);
2447 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2448 }
2449}
2450
a0ae8e8d
RK
2451/* Add INSN into the doubly-linked list before insn BEFORE. This and
2452 the previous should be the only functions called to insert an insn once
ba213285 2453 delay slots have been filled since only they know how to update a
a0ae8e8d
RK
2454 SEQUENCE. */
2455
2456void
2457add_insn_before (insn, before)
2458 rtx insn, before;
2459{
2460 rtx prev = PREV_INSN (before);
2461
6782074d 2462 if (optimize && INSN_DELETED_P (before))
ba213285
RK
2463 abort ();
2464
a0ae8e8d
RK
2465 PREV_INSN (insn) = prev;
2466 NEXT_INSN (insn) = before;
2467
2468 if (prev)
2469 {
2470 NEXT_INSN (prev) = insn;
2471 if (GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == SEQUENCE)
2472 {
2473 rtx sequence = PATTERN (prev);
2474 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2475 }
2476 }
2477 else if (first_insn == before)
2478 first_insn = insn;
2479 else
2480 {
49ad7cfa 2481 struct sequence_stack *stack = seq_stack;
a0ae8e8d
RK
2482 /* Scan all pending sequences too. */
2483 for (; stack; stack = stack->next)
2484 if (before == stack->first)
fef0509b
RK
2485 {
2486 stack->first = insn;
2487 break;
2488 }
a0ae8e8d
RK
2489
2490 if (stack == 0)
2491 abort ();
2492 }
2493
2494 PREV_INSN (before) = insn;
2495 if (GET_CODE (before) == INSN && GET_CODE (PATTERN (before)) == SEQUENCE)
2496 PREV_INSN (XVECEXP (PATTERN (before), 0, 0)) = insn;
2497}
2498
89e99eea
DB
2499/* Remove an insn from its doubly-linked list. This function knows how
2500 to handle sequences. */
2501void
2502remove_insn (insn)
2503 rtx insn;
2504{
2505 rtx next = NEXT_INSN (insn);
2506 rtx prev = PREV_INSN (insn);
2507 if (prev)
2508 {
2509 NEXT_INSN (prev) = next;
2510 if (GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == SEQUENCE)
2511 {
2512 rtx sequence = PATTERN (prev);
2513 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = next;
2514 }
2515 }
2516 else if (first_insn == insn)
2517 first_insn = next;
2518 else
2519 {
49ad7cfa 2520 struct sequence_stack *stack = seq_stack;
89e99eea
DB
2521 /* Scan all pending sequences too. */
2522 for (; stack; stack = stack->next)
2523 if (insn == stack->first)
2524 {
2525 stack->first = next;
2526 break;
2527 }
2528
2529 if (stack == 0)
2530 abort ();
2531 }
2532
2533 if (next)
2534 {
2535 PREV_INSN (next) = prev;
2536 if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == SEQUENCE)
2537 PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = prev;
2538 }
2539 else if (last_insn == insn)
2540 last_insn = prev;
2541 else
2542 {
49ad7cfa 2543 struct sequence_stack *stack = seq_stack;
89e99eea
DB
2544 /* Scan all pending sequences too. */
2545 for (; stack; stack = stack->next)
2546 if (insn == stack->last)
2547 {
2548 stack->last = prev;
2549 break;
2550 }
2551
2552 if (stack == 0)
2553 abort ();
2554 }
2555}
2556
23b2ce53
RS
2557/* Delete all insns made since FROM.
2558 FROM becomes the new last instruction. */
2559
2560void
2561delete_insns_since (from)
2562 rtx from;
2563{
2564 if (from == 0)
2565 first_insn = 0;
2566 else
2567 NEXT_INSN (from) = 0;
2568 last_insn = from;
2569}
2570
5dab5552
MS
2571/* This function is deprecated, please use sequences instead.
2572
2573 Move a consecutive bunch of insns to a different place in the chain.
23b2ce53
RS
2574 The insns to be moved are those between FROM and TO.
2575 They are moved to a new position after the insn AFTER.
2576 AFTER must not be FROM or TO or any insn in between.
2577
2578 This function does not know about SEQUENCEs and hence should not be
2579 called after delay-slot filling has been done. */
2580
2581void
2582reorder_insns (from, to, after)
2583 rtx from, to, after;
2584{
2585 /* Splice this bunch out of where it is now. */
2586 if (PREV_INSN (from))
2587 NEXT_INSN (PREV_INSN (from)) = NEXT_INSN (to);
2588 if (NEXT_INSN (to))
2589 PREV_INSN (NEXT_INSN (to)) = PREV_INSN (from);
2590 if (last_insn == to)
2591 last_insn = PREV_INSN (from);
2592 if (first_insn == from)
2593 first_insn = NEXT_INSN (to);
2594
2595 /* Make the new neighbors point to it and it to them. */
2596 if (NEXT_INSN (after))
2597 PREV_INSN (NEXT_INSN (after)) = to;
2598
2599 NEXT_INSN (to) = NEXT_INSN (after);
2600 PREV_INSN (from) = after;
2601 NEXT_INSN (after) = from;
2602 if (after == last_insn)
2603 last_insn = to;
2604}
2605
2606/* Return the line note insn preceding INSN. */
2607
2608static rtx
2609find_line_note (insn)
2610 rtx insn;
2611{
2612 if (no_line_numbers)
2613 return 0;
2614
2615 for (; insn; insn = PREV_INSN (insn))
2616 if (GET_CODE (insn) == NOTE
2617 && NOTE_LINE_NUMBER (insn) >= 0)
2618 break;
2619
2620 return insn;
2621}
2622
2623/* Like reorder_insns, but inserts line notes to preserve the line numbers
2624 of the moved insns when debugging. This may insert a note between AFTER
2625 and FROM, and another one after TO. */
2626
2627void
2628reorder_insns_with_line_notes (from, to, after)
2629 rtx from, to, after;
2630{
2631 rtx from_line = find_line_note (from);
2632 rtx after_line = find_line_note (after);
2633
2634 reorder_insns (from, to, after);
2635
2636 if (from_line == after_line)
2637 return;
2638
2639 if (from_line)
2640 emit_line_note_after (NOTE_SOURCE_FILE (from_line),
2641 NOTE_LINE_NUMBER (from_line),
2642 after);
2643 if (after_line)
2644 emit_line_note_after (NOTE_SOURCE_FILE (after_line),
2645 NOTE_LINE_NUMBER (after_line),
2646 to);
2647}
aeeeda03
MM
2648
2649/* Remove unncessary notes from the instruction stream. */
2650
2651void
2652remove_unncessary_notes ()
2653{
2654 rtx insn;
2655 rtx next;
aeeeda03
MM
2656
2657 /* Remove NOTE_INSN_DELETED notes. We must not remove the first
2658 instruction in the function because the compiler depends on the
2659 first instruction being a note. */
2660 for (insn = NEXT_INSN (get_insns ()); insn; insn = next)
2661 {
2662 /* Remember what's next. */
2663 next = NEXT_INSN (insn);
2664
2665 /* We're only interested in notes. */
2666 if (GET_CODE (insn) != NOTE)
2667 continue;
2668
2669 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
2670 remove_insn (insn);
2671 }
2672}
2673
23b2ce53
RS
2674\f
2675/* Emit an insn of given code and pattern
2676 at a specified place within the doubly-linked list. */
2677
2678/* Make an instruction with body PATTERN
2679 and output it before the instruction BEFORE. */
2680
2681rtx
2682emit_insn_before (pattern, before)
2683 register rtx pattern, before;
2684{
2685 register rtx insn = before;
2686
2687 if (GET_CODE (pattern) == SEQUENCE)
2688 {
2689 register int i;
2690
2691 for (i = 0; i < XVECLEN (pattern, 0); i++)
2692 {
2693 insn = XVECEXP (pattern, 0, i);
a0ae8e8d 2694 add_insn_before (insn, before);
23b2ce53 2695 }
a3770a81 2696 if (!ggc_p && XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
23b2ce53
RS
2697 sequence_result[XVECLEN (pattern, 0)] = pattern;
2698 }
2699 else
2700 {
4b1f5e8c 2701 insn = make_insn_raw (pattern);
a0ae8e8d 2702 add_insn_before (insn, before);
23b2ce53
RS
2703 }
2704
2705 return insn;
2706}
2707
a05924f9
JH
2708/* Similar to emit_insn_before, but update basic block boundaries as well. */
2709
2710rtx
2711emit_block_insn_before (pattern, before, block)
2712 rtx pattern, before;
2713 basic_block block;
2714{
2715 rtx prev = PREV_INSN (before);
2716 rtx r = emit_insn_before (pattern, before);
2717 if (block && block->head == before)
2718 block->head = NEXT_INSN (prev);
2719 return r;
2720}
2721
23b2ce53
RS
2722/* Make an instruction with body PATTERN and code JUMP_INSN
2723 and output it before the instruction BEFORE. */
2724
2725rtx
2726emit_jump_insn_before (pattern, before)
2727 register rtx pattern, before;
2728{
2729 register rtx insn;
2730
2731 if (GET_CODE (pattern) == SEQUENCE)
2732 insn = emit_insn_before (pattern, before);
2733 else
2734 {
85cf32bc 2735 insn = make_jump_insn_raw (pattern);
a0ae8e8d 2736 add_insn_before (insn, before);
23b2ce53
RS
2737 }
2738
2739 return insn;
2740}
2741
2742/* Make an instruction with body PATTERN and code CALL_INSN
2743 and output it before the instruction BEFORE. */
2744
2745rtx
2746emit_call_insn_before (pattern, before)
2747 register rtx pattern, before;
2748{
aff507f4
RK
2749 register rtx insn;
2750
2751 if (GET_CODE (pattern) == SEQUENCE)
2752 insn = emit_insn_before (pattern, before);
2753 else
2754 {
2755 insn = make_call_insn_raw (pattern);
a0ae8e8d 2756 add_insn_before (insn, before);
aff507f4
RK
2757 PUT_CODE (insn, CALL_INSN);
2758 }
2759
23b2ce53
RS
2760 return insn;
2761}
2762
2763/* Make an insn of code BARRIER
e881bb1b 2764 and output it before the insn BEFORE. */
23b2ce53
RS
2765
2766rtx
2767emit_barrier_before (before)
2768 register rtx before;
2769{
2770 register rtx insn = rtx_alloc (BARRIER);
2771
2772 INSN_UID (insn) = cur_insn_uid++;
2773
a0ae8e8d 2774 add_insn_before (insn, before);
23b2ce53
RS
2775 return insn;
2776}
2777
e881bb1b
RH
2778/* Emit the label LABEL before the insn BEFORE. */
2779
2780rtx
2781emit_label_before (label, before)
2782 rtx label, before;
2783{
2784 /* This can be called twice for the same label as a result of the
2785 confusion that follows a syntax error! So make it harmless. */
2786 if (INSN_UID (label) == 0)
2787 {
2788 INSN_UID (label) = cur_insn_uid++;
2789 add_insn_before (label, before);
2790 }
2791
2792 return label;
2793}
2794
23b2ce53
RS
2795/* Emit a note of subtype SUBTYPE before the insn BEFORE. */
2796
2797rtx
2798emit_note_before (subtype, before)
2799 int subtype;
2800 rtx before;
2801{
2802 register rtx note = rtx_alloc (NOTE);
2803 INSN_UID (note) = cur_insn_uid++;
2804 NOTE_SOURCE_FILE (note) = 0;
2805 NOTE_LINE_NUMBER (note) = subtype;
2806
a0ae8e8d 2807 add_insn_before (note, before);
23b2ce53
RS
2808 return note;
2809}
2810\f
2811/* Make an insn of code INSN with body PATTERN
2812 and output it after the insn AFTER. */
2813
2814rtx
2815emit_insn_after (pattern, after)
2816 register rtx pattern, after;
2817{
2818 register rtx insn = after;
2819
2820 if (GET_CODE (pattern) == SEQUENCE)
2821 {
2822 register int i;
2823
2824 for (i = 0; i < XVECLEN (pattern, 0); i++)
2825 {
2826 insn = XVECEXP (pattern, 0, i);
2827 add_insn_after (insn, after);
2828 after = insn;
2829 }
a3770a81 2830 if (!ggc_p && XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
23b2ce53
RS
2831 sequence_result[XVECLEN (pattern, 0)] = pattern;
2832 }
2833 else
2834 {
4b1f5e8c 2835 insn = make_insn_raw (pattern);
23b2ce53
RS
2836 add_insn_after (insn, after);
2837 }
2838
2839 return insn;
2840}
2841
255680cf
RK
2842/* Similar to emit_insn_after, except that line notes are to be inserted so
2843 as to act as if this insn were at FROM. */
2844
2845void
2846emit_insn_after_with_line_notes (pattern, after, from)
2847 rtx pattern, after, from;
2848{
2849 rtx from_line = find_line_note (from);
2850 rtx after_line = find_line_note (after);
2851 rtx insn = emit_insn_after (pattern, after);
2852
2853 if (from_line)
2854 emit_line_note_after (NOTE_SOURCE_FILE (from_line),
2855 NOTE_LINE_NUMBER (from_line),
2856 after);
2857
2858 if (after_line)
2859 emit_line_note_after (NOTE_SOURCE_FILE (after_line),
2860 NOTE_LINE_NUMBER (after_line),
2861 insn);
2862}
2863
a05924f9
JH
2864/* Similar to emit_insn_after, but update basic block boundaries as well. */
2865
2866rtx
2867emit_block_insn_after (pattern, after, block)
2868 rtx pattern, after;
2869 basic_block block;
2870{
2871 rtx r = emit_insn_after (pattern, after);
2872 if (block && block->end == after)
2873 block->end = r;
2874 return r;
2875}
2876
23b2ce53
RS
2877/* Make an insn of code JUMP_INSN with body PATTERN
2878 and output it after the insn AFTER. */
2879
2880rtx
2881emit_jump_insn_after (pattern, after)
2882 register rtx pattern, after;
2883{
2884 register rtx insn;
2885
2886 if (GET_CODE (pattern) == SEQUENCE)
2887 insn = emit_insn_after (pattern, after);
2888 else
2889 {
85cf32bc 2890 insn = make_jump_insn_raw (pattern);
23b2ce53
RS
2891 add_insn_after (insn, after);
2892 }
2893
2894 return insn;
2895}
2896
2897/* Make an insn of code BARRIER
2898 and output it after the insn AFTER. */
2899
2900rtx
2901emit_barrier_after (after)
2902 register rtx after;
2903{
2904 register rtx insn = rtx_alloc (BARRIER);
2905
2906 INSN_UID (insn) = cur_insn_uid++;
2907
2908 add_insn_after (insn, after);
2909 return insn;
2910}
2911
2912/* Emit the label LABEL after the insn AFTER. */
2913
2914rtx
2915emit_label_after (label, after)
2916 rtx label, after;
2917{
2918 /* This can be called twice for the same label
2919 as a result of the confusion that follows a syntax error!
2920 So make it harmless. */
2921 if (INSN_UID (label) == 0)
2922 {
2923 INSN_UID (label) = cur_insn_uid++;
2924 add_insn_after (label, after);
2925 }
2926
2927 return label;
2928}
2929
2930/* Emit a note of subtype SUBTYPE after the insn AFTER. */
2931
2932rtx
2933emit_note_after (subtype, after)
2934 int subtype;
2935 rtx after;
2936{
2937 register rtx note = rtx_alloc (NOTE);
2938 INSN_UID (note) = cur_insn_uid++;
2939 NOTE_SOURCE_FILE (note) = 0;
2940 NOTE_LINE_NUMBER (note) = subtype;
2941 add_insn_after (note, after);
2942 return note;
2943}
2944
2945/* Emit a line note for FILE and LINE after the insn AFTER. */
2946
2947rtx
2948emit_line_note_after (file, line, after)
2949 char *file;
2950 int line;
2951 rtx after;
2952{
2953 register rtx note;
2954
2955 if (no_line_numbers && line > 0)
2956 {
2957 cur_insn_uid++;
2958 return 0;
2959 }
2960
2961 note = rtx_alloc (NOTE);
2962 INSN_UID (note) = cur_insn_uid++;
2963 NOTE_SOURCE_FILE (note) = file;
2964 NOTE_LINE_NUMBER (note) = line;
2965 add_insn_after (note, after);
2966 return note;
2967}
2968\f
2969/* Make an insn of code INSN with pattern PATTERN
2970 and add it to the end of the doubly-linked list.
2971 If PATTERN is a SEQUENCE, take the elements of it
2972 and emit an insn for each element.
2973
2974 Returns the last insn emitted. */
2975
2976rtx
2977emit_insn (pattern)
2978 rtx pattern;
2979{
2980 rtx insn = last_insn;
2981
2982 if (GET_CODE (pattern) == SEQUENCE)
2983 {
2984 register int i;
2985
2986 for (i = 0; i < XVECLEN (pattern, 0); i++)
2987 {
2988 insn = XVECEXP (pattern, 0, i);
2989 add_insn (insn);
2990 }
a3770a81 2991 if (!ggc_p && XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
23b2ce53
RS
2992 sequence_result[XVECLEN (pattern, 0)] = pattern;
2993 }
2994 else
2995 {
4b1f5e8c 2996 insn = make_insn_raw (pattern);
23b2ce53
RS
2997 add_insn (insn);
2998 }
2999
06be9173
NC
3000#ifdef ENABLE_RTL_CHECKING
3001 if (insn
78340c9f 3002 && GET_RTX_CLASS (GET_CODE (insn)) == 'i'
06be9173
NC
3003 && (returnjump_p (insn)
3004 || (GET_CODE (insn) == SET
3005 && SET_DEST (insn) == pc_rtx)))
3006 {
3007 warning ("ICE: emit_insn used where emit_jump_insn needed:\n");
3008 debug_rtx (insn);
3009 }
3010#endif
3011
23b2ce53
RS
3012 return insn;
3013}
3014
3015/* Emit the insns in a chain starting with INSN.
3016 Return the last insn emitted. */
3017
3018rtx
3019emit_insns (insn)
3020 rtx insn;
3021{
3022 rtx last = 0;
3023
3024 while (insn)
3025 {
3026 rtx next = NEXT_INSN (insn);
3027 add_insn (insn);
3028 last = insn;
3029 insn = next;
3030 }
3031
3032 return last;
3033}
3034
3035/* Emit the insns in a chain starting with INSN and place them in front of
3036 the insn BEFORE. Return the last insn emitted. */
3037
3038rtx
3039emit_insns_before (insn, before)
3040 rtx insn;
3041 rtx before;
3042{
3043 rtx last = 0;
3044
3045 while (insn)
3046 {
3047 rtx next = NEXT_INSN (insn);
a0ae8e8d 3048 add_insn_before (insn, before);
23b2ce53
RS
3049 last = insn;
3050 insn = next;
3051 }
3052
3053 return last;
3054}
3055
e0a5c5eb
RS
3056/* Emit the insns in a chain starting with FIRST and place them in back of
3057 the insn AFTER. Return the last insn emitted. */
3058
3059rtx
3060emit_insns_after (first, after)
3061 register rtx first;
3062 register rtx after;
3063{
3064 register rtx last;
3065 register rtx after_after;
3066
3067 if (!after)
3068 abort ();
3069
3070 if (!first)
3071 return first;
3072
3073 for (last = first; NEXT_INSN (last); last = NEXT_INSN (last))
3074 continue;
3075
3076 after_after = NEXT_INSN (after);
3077
3078 NEXT_INSN (after) = first;
3079 PREV_INSN (first) = after;
3080 NEXT_INSN (last) = after_after;
3081 if (after_after)
3082 PREV_INSN (after_after) = last;
3083
c4d990db
RS
3084 if (after == last_insn)
3085 last_insn = last;
e0a5c5eb
RS
3086 return last;
3087}
3088
23b2ce53
RS
3089/* Make an insn of code JUMP_INSN with pattern PATTERN
3090 and add it to the end of the doubly-linked list. */
3091
3092rtx
3093emit_jump_insn (pattern)
3094 rtx pattern;
3095{
3096 if (GET_CODE (pattern) == SEQUENCE)
3097 return emit_insn (pattern);
3098 else
3099 {
85cf32bc 3100 register rtx insn = make_jump_insn_raw (pattern);
23b2ce53
RS
3101 add_insn (insn);
3102 return insn;
3103 }
3104}
3105
3106/* Make an insn of code CALL_INSN with pattern PATTERN
3107 and add it to the end of the doubly-linked list. */
3108
3109rtx
3110emit_call_insn (pattern)
3111 rtx pattern;
3112{
3113 if (GET_CODE (pattern) == SEQUENCE)
3114 return emit_insn (pattern);
3115 else
3116 {
aff507f4 3117 register rtx insn = make_call_insn_raw (pattern);
23b2ce53
RS
3118 add_insn (insn);
3119 PUT_CODE (insn, CALL_INSN);
3120 return insn;
3121 }
3122}
3123
3124/* Add the label LABEL to the end of the doubly-linked list. */
3125
3126rtx
3127emit_label (label)
3128 rtx label;
3129{
3130 /* This can be called twice for the same label
3131 as a result of the confusion that follows a syntax error!
3132 So make it harmless. */
3133 if (INSN_UID (label) == 0)
3134 {
3135 INSN_UID (label) = cur_insn_uid++;
3136 add_insn (label);
3137 }
3138 return label;
3139}
3140
3141/* Make an insn of code BARRIER
3142 and add it to the end of the doubly-linked list. */
3143
3144rtx
3145emit_barrier ()
3146{
3147 register rtx barrier = rtx_alloc (BARRIER);
3148 INSN_UID (barrier) = cur_insn_uid++;
3149 add_insn (barrier);
3150 return barrier;
3151}
3152
3153/* Make an insn of code NOTE
3154 with data-fields specified by FILE and LINE
3155 and add it to the end of the doubly-linked list,
3156 but only if line-numbers are desired for debugging info. */
3157
3158rtx
3159emit_line_note (file, line)
3160 char *file;
3161 int line;
3162{
3f1d071b 3163 set_file_and_line_for_stmt (file, line);
23b2ce53
RS
3164
3165#if 0
3166 if (no_line_numbers)
3167 return 0;
3168#endif
3169
3170 return emit_note (file, line);
3171}
3172
3173/* Make an insn of code NOTE
3174 with data-fields specified by FILE and LINE
3175 and add it to the end of the doubly-linked list.
3176 If it is a line-number NOTE, omit it if it matches the previous one. */
3177
3178rtx
3179emit_note (file, line)
3180 char *file;
3181 int line;
3182{
3183 register rtx note;
3184
3185 if (line > 0)
3186 {
3187 if (file && last_filename && !strcmp (file, last_filename)
3188 && line == last_linenum)
3189 return 0;
3190 last_filename = file;
3191 last_linenum = line;
3192 }
3193
3194 if (no_line_numbers && line > 0)
3195 {
3196 cur_insn_uid++;
3197 return 0;
3198 }
3199
3200 note = rtx_alloc (NOTE);
3201 INSN_UID (note) = cur_insn_uid++;
3202 NOTE_SOURCE_FILE (note) = file;
3203 NOTE_LINE_NUMBER (note) = line;
3204 add_insn (note);
3205 return note;
3206}
3207
fe77a034 3208/* Emit a NOTE, and don't omit it even if LINE is the previous note. */
23b2ce53
RS
3209
3210rtx
3211emit_line_note_force (file, line)
3212 char *file;
3213 int line;
3214{
3215 last_linenum = -1;
3216 return emit_line_note (file, line);
3217}
3218
3219/* Cause next statement to emit a line note even if the line number
3220 has not changed. This is used at the beginning of a function. */
3221
3222void
3223force_next_line_note ()
3224{
3225 last_linenum = -1;
3226}
87b47c85
AM
3227
3228/* Place a note of KIND on insn INSN with DATUM as the datum. If a
3229 note of this type already exists, remove it first. */
3230
3231void
3232set_unique_reg_note (insn, kind, datum)
3233 rtx insn;
3234 enum reg_note kind;
3235 rtx datum;
3236{
3237 rtx note = find_reg_note (insn, kind, NULL_RTX);
3238
3239 /* First remove the note if there already is one. */
3240 if (note)
3241 remove_note (insn, note);
3242
3243 REG_NOTES (insn) = gen_rtx_EXPR_LIST (kind, datum, REG_NOTES (insn));
3244}
23b2ce53
RS
3245\f
3246/* Return an indication of which type of insn should have X as a body.
3247 The value is CODE_LABEL, INSN, CALL_INSN or JUMP_INSN. */
3248
3249enum rtx_code
3250classify_insn (x)
3251 rtx x;
3252{
3253 if (GET_CODE (x) == CODE_LABEL)
3254 return CODE_LABEL;
3255 if (GET_CODE (x) == CALL)
3256 return CALL_INSN;
3257 if (GET_CODE (x) == RETURN)
3258 return JUMP_INSN;
3259 if (GET_CODE (x) == SET)
3260 {
3261 if (SET_DEST (x) == pc_rtx)
3262 return JUMP_INSN;
3263 else if (GET_CODE (SET_SRC (x)) == CALL)
3264 return CALL_INSN;
3265 else
3266 return INSN;
3267 }
3268 if (GET_CODE (x) == PARALLEL)
3269 {
3270 register int j;
3271 for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
3272 if (GET_CODE (XVECEXP (x, 0, j)) == CALL)
3273 return CALL_INSN;
3274 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
3275 && SET_DEST (XVECEXP (x, 0, j)) == pc_rtx)
3276 return JUMP_INSN;
3277 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
3278 && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == CALL)
3279 return CALL_INSN;
3280 }
3281 return INSN;
3282}
3283
3284/* Emit the rtl pattern X as an appropriate kind of insn.
3285 If X is a label, it is simply added into the insn chain. */
3286
3287rtx
3288emit (x)
3289 rtx x;
3290{
3291 enum rtx_code code = classify_insn (x);
3292
3293 if (code == CODE_LABEL)
3294 return emit_label (x);
3295 else if (code == INSN)
3296 return emit_insn (x);
3297 else if (code == JUMP_INSN)
3298 {
3299 register rtx insn = emit_jump_insn (x);
3300 if (simplejump_p (insn) || GET_CODE (x) == RETURN)
3301 return emit_barrier ();
3302 return insn;
3303 }
3304 else if (code == CALL_INSN)
3305 return emit_call_insn (x);
3306 else
3307 abort ();
3308}
3309\f
5c7a310f
MM
3310/* Begin emitting insns to a sequence which can be packaged in an
3311 RTL_EXPR. If this sequence will contain something that might cause
3312 the compiler to pop arguments to function calls (because those
3313 pops have previously been deferred; see INHIBIT_DEFER_POP for more
3314 details), use do_pending_stack_adjust before calling this function.
3315 That will ensure that the deferred pops are not accidentally
3316 emitted in the middel of this sequence. */
23b2ce53
RS
3317
3318void
3319start_sequence ()
3320{
3321 struct sequence_stack *tem;
3322
a3770a81 3323 tem = (struct sequence_stack *) xmalloc (sizeof (struct sequence_stack));
23b2ce53 3324
49ad7cfa 3325 tem->next = seq_stack;
23b2ce53
RS
3326 tem->first = first_insn;
3327 tem->last = last_insn;
49ad7cfa 3328 tem->sequence_rtl_expr = seq_rtl_expr;
23b2ce53 3329
49ad7cfa 3330 seq_stack = tem;
23b2ce53
RS
3331
3332 first_insn = 0;
3333 last_insn = 0;
3334}
3335
5c7a310f
MM
3336/* Similarly, but indicate that this sequence will be placed in T, an
3337 RTL_EXPR. See the documentation for start_sequence for more
3338 information about how to use this function. */
a25c7971
RK
3339
3340void
3341start_sequence_for_rtl_expr (t)
3342 tree t;
3343{
3344 start_sequence ();
3345
49ad7cfa 3346 seq_rtl_expr = t;
a25c7971
RK
3347}
3348
5c7a310f
MM
3349/* Set up the insn chain starting with FIRST as the current sequence,
3350 saving the previously current one. See the documentation for
3351 start_sequence for more information about how to use this function. */
23b2ce53
RS
3352
3353void
3354push_to_sequence (first)
3355 rtx first;
3356{
3357 rtx last;
3358
3359 start_sequence ();
3360
3361 for (last = first; last && NEXT_INSN (last); last = NEXT_INSN (last));
3362
3363 first_insn = first;
3364 last_insn = last;
3365}
3366
f15ae3a1
TW
3367/* Set up the outer-level insn chain
3368 as the current sequence, saving the previously current one. */
3369
3370void
3371push_topmost_sequence ()
3372{
aefdd5ab 3373 struct sequence_stack *stack, *top = NULL;
f15ae3a1
TW
3374
3375 start_sequence ();
3376
49ad7cfa 3377 for (stack = seq_stack; stack; stack = stack->next)
f15ae3a1
TW
3378 top = stack;
3379
3380 first_insn = top->first;
3381 last_insn = top->last;
49ad7cfa 3382 seq_rtl_expr = top->sequence_rtl_expr;
f15ae3a1
TW
3383}
3384
3385/* After emitting to the outer-level insn chain, update the outer-level
3386 insn chain, and restore the previous saved state. */
3387
3388void
3389pop_topmost_sequence ()
3390{
aefdd5ab 3391 struct sequence_stack *stack, *top = NULL;
f15ae3a1 3392
49ad7cfa 3393 for (stack = seq_stack; stack; stack = stack->next)
f15ae3a1
TW
3394 top = stack;
3395
3396 top->first = first_insn;
3397 top->last = last_insn;
49ad7cfa 3398 /* ??? Why don't we save seq_rtl_expr here? */
f15ae3a1
TW
3399
3400 end_sequence ();
3401}
3402
23b2ce53
RS
3403/* After emitting to a sequence, restore previous saved state.
3404
5c7a310f
MM
3405 To get the contents of the sequence just made, you must call
3406 `gen_sequence' *before* calling here.
3407
3408 If the compiler might have deferred popping arguments while
3409 generating this sequence, and this sequence will not be immediately
3410 inserted into the instruction stream, use do_pending_stack_adjust
3411 before calling gen_sequence. That will ensure that the deferred
3412 pops are inserted into this sequence, and not into some random
3413 location in the instruction stream. See INHIBIT_DEFER_POP for more
3414 information about deferred popping of arguments. */
23b2ce53
RS
3415
3416void
3417end_sequence ()
3418{
49ad7cfa 3419 struct sequence_stack *tem = seq_stack;
23b2ce53
RS
3420
3421 first_insn = tem->first;
3422 last_insn = tem->last;
49ad7cfa
BS
3423 seq_rtl_expr = tem->sequence_rtl_expr;
3424 seq_stack = tem->next;
23b2ce53 3425
a3770a81 3426 free (tem);
23b2ce53
RS
3427}
3428
3429/* Return 1 if currently emitting into a sequence. */
3430
3431int
3432in_sequence_p ()
3433{
49ad7cfa 3434 return seq_stack != 0;
23b2ce53
RS
3435}
3436
3437/* Generate a SEQUENCE rtx containing the insns already emitted
3438 to the current sequence.
3439
3440 This is how the gen_... function from a DEFINE_EXPAND
3441 constructs the SEQUENCE that it returns. */
3442
3443rtx
3444gen_sequence ()
3445{
3446 rtx result;
3447 rtx tem;
23b2ce53
RS
3448 int i;
3449 int len;
3450
3451 /* Count the insns in the chain. */
3452 len = 0;
3453 for (tem = first_insn; tem; tem = NEXT_INSN (tem))
3454 len++;
3455
ee265800 3456 /* If only one insn, return it rather than a SEQUENCE.
23b2ce53 3457 (Now that we cache SEQUENCE expressions, it isn't worth special-casing
ee265800
AH
3458 the case of an empty list.)
3459 We only return the pattern of an insn if its code is INSN and it
3460 has no notes. This ensures that no information gets lost. */
23b2ce53 3461 if (len == 1
ca55abae 3462 && ! RTX_FRAME_RELATED_P (first_insn)
ee265800
AH
3463 && GET_CODE (first_insn) == INSN
3464 /* Don't throw away any reg notes. */
3465 && REG_NOTES (first_insn) == 0)
43127294 3466 {
a3770a81
RH
3467 if (!ggc_p)
3468 {
3469 NEXT_INSN (first_insn) = free_insn;
3470 free_insn = first_insn;
3471 }
43127294
RK
3472 return PATTERN (first_insn);
3473 }
23b2ce53
RS
3474
3475 /* Put them in a vector. See if we already have a SEQUENCE of the
3476 appropriate length around. */
a3770a81
RH
3477 if (!ggc_p && len < SEQUENCE_RESULT_SIZE
3478 && (result = sequence_result[len]) != 0)
23b2ce53
RS
3479 sequence_result[len] = 0;
3480 else
3481 {
9faa82d8
RK
3482 /* Ensure that this rtl goes in saveable_obstack, since we may
3483 cache it. */
d508ebba
JW
3484 push_obstacks_nochange ();
3485 rtl_in_saveable_obstack ();
3b80f6ca 3486 result = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (len));
d508ebba 3487 pop_obstacks ();
23b2ce53
RS
3488 }
3489
3490 for (i = 0, tem = first_insn; tem; tem = NEXT_INSN (tem), i++)
3491 XVECEXP (result, 0, i) = tem;
3492
3493 return result;
3494}
3495\f
59ec66dc
MM
3496/* Put the various virtual registers into REGNO_REG_RTX. */
3497
3498void
49ad7cfa
BS
3499init_virtual_regs (es)
3500 struct emit_status *es;
59ec66dc 3501{
49ad7cfa
BS
3502 rtx *ptr = es->x_regno_reg_rtx;
3503 ptr[VIRTUAL_INCOMING_ARGS_REGNUM] = virtual_incoming_args_rtx;
3504 ptr[VIRTUAL_STACK_VARS_REGNUM] = virtual_stack_vars_rtx;
3505 ptr[VIRTUAL_STACK_DYNAMIC_REGNUM] = virtual_stack_dynamic_rtx;
3506 ptr[VIRTUAL_OUTGOING_ARGS_REGNUM] = virtual_outgoing_args_rtx;
3507 ptr[VIRTUAL_CFA_REGNUM] = virtual_cfa_rtx;
3508}
3509
3510void
3511clear_emit_caches ()
3512{
3513 int i;
3514
3515 /* Clear the start_sequence/gen_sequence cache. */
49ad7cfa
BS
3516 for (i = 0; i < SEQUENCE_RESULT_SIZE; i++)
3517 sequence_result[i] = 0;
3518 free_insn = 0;
59ec66dc 3519}
da43a810
BS
3520\f
3521/* Used by copy_insn_1 to avoid copying SCRATCHes more than once. */
3522static rtx copy_insn_scratch_in[MAX_RECOG_OPERANDS];
3523static rtx copy_insn_scratch_out[MAX_RECOG_OPERANDS];
3524static int copy_insn_n_scratches;
3525
3526/* When an insn is being copied by copy_insn_1, this is nonzero if we have
3527 copied an ASM_OPERANDS.
3528 In that case, it is the original input-operand vector. */
3529static rtvec orig_asm_operands_vector;
3530
3531/* When an insn is being copied by copy_insn_1, this is nonzero if we have
3532 copied an ASM_OPERANDS.
3533 In that case, it is the copied input-operand vector. */
3534static rtvec copy_asm_operands_vector;
3535
3536/* Likewise for the constraints vector. */
3537static rtvec orig_asm_constraints_vector;
3538static rtvec copy_asm_constraints_vector;
3539
3540/* Recursively create a new copy of an rtx for copy_insn.
3541 This function differs from copy_rtx in that it handles SCRATCHes and
3542 ASM_OPERANDs properly.
3543 Normally, this function is not used directly; use copy_insn as front end.
3544 However, you could first copy an insn pattern with copy_insn and then use
3545 this function afterwards to properly copy any REG_NOTEs containing
3546 SCRATCHes. */
3547
3548rtx
3549copy_insn_1 (orig)
3550 register rtx orig;
3551{
3552 register rtx copy;
3553 register int i, j;
3554 register RTX_CODE code;
4724334a 3555 register const char *format_ptr;
da43a810
BS
3556
3557 code = GET_CODE (orig);
3558
3559 switch (code)
3560 {
3561 case REG:
3562 case QUEUED:
3563 case CONST_INT:
3564 case CONST_DOUBLE:
3565 case SYMBOL_REF:
3566 case CODE_LABEL:
3567 case PC:
3568 case CC0:
3569 case ADDRESSOF:
3570 return orig;
3571
3572 case SCRATCH:
3573 for (i = 0; i < copy_insn_n_scratches; i++)
3574 if (copy_insn_scratch_in[i] == orig)
3575 return copy_insn_scratch_out[i];
3576 break;
3577
3578 case CONST:
3579 /* CONST can be shared if it contains a SYMBOL_REF. If it contains
3580 a LABEL_REF, it isn't sharable. */
3581 if (GET_CODE (XEXP (orig, 0)) == PLUS
3582 && GET_CODE (XEXP (XEXP (orig, 0), 0)) == SYMBOL_REF
3583 && GET_CODE (XEXP (XEXP (orig, 0), 1)) == CONST_INT)
3584 return orig;
3585 break;
3586
3587 /* A MEM with a constant address is not sharable. The problem is that
3588 the constant address may need to be reloaded. If the mem is shared,
3589 then reloading one copy of this mem will cause all copies to appear
3590 to have been reloaded. */
3591
3592 default:
3593 break;
3594 }
3595
3596 copy = rtx_alloc (code);
3597
3598 /* Copy the various flags, and other information. We assume that
3599 all fields need copying, and then clear the fields that should
3600 not be copied. That is the sensible default behavior, and forces
3601 us to explicitly document why we are *not* copying a flag. */
3602 memcpy (copy, orig, sizeof (struct rtx_def) - sizeof (rtunion));
3603
3604 /* We do not copy the USED flag, which is used as a mark bit during
3605 walks over the RTL. */
3606 copy->used = 0;
3607
3608 /* We do not copy JUMP, CALL, or FRAME_RELATED for INSNs. */
3609 if (GET_RTX_CLASS (code) == 'i')
3610 {
3611 copy->jump = 0;
3612 copy->call = 0;
3613 copy->frame_related = 0;
3614 }
3615
3616 format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
3617
3618 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
3619 {
e63db8f6 3620 copy->fld[i] = orig->fld[i];
da43a810
BS
3621 switch (*format_ptr++)
3622 {
3623 case 'e':
da43a810
BS
3624 if (XEXP (orig, i) != NULL)
3625 XEXP (copy, i) = copy_insn_1 (XEXP (orig, i));
3626 break;
3627
da43a810
BS
3628 case 'E':
3629 case 'V':
da43a810
BS
3630 if (XVEC (orig, i) == orig_asm_constraints_vector)
3631 XVEC (copy, i) = copy_asm_constraints_vector;
3632 else if (XVEC (orig, i) == orig_asm_operands_vector)
3633 XVEC (copy, i) = copy_asm_operands_vector;
3634 else if (XVEC (orig, i) != NULL)
3635 {
3636 XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
3637 for (j = 0; j < XVECLEN (copy, i); j++)
3638 XVECEXP (copy, i, j) = copy_insn_1 (XVECEXP (orig, i, j));
3639 }
3640 break;
3641
3642 case 'b':
3643 {
3644 bitmap new_bits = BITMAP_OBSTACK_ALLOC (rtl_obstack);
3645 bitmap_copy (new_bits, XBITMAP (orig, i));
3646 XBITMAP (copy, i) = new_bits;
3647 break;
3648 }
3649
3650 case 't':
da43a810 3651 case 'w':
da43a810 3652 case 'i':
da43a810
BS
3653 case 's':
3654 case 'S':
e63db8f6
BS
3655 case 'u':
3656 case '0':
3657 /* These are left unchanged. */
da43a810
BS
3658 break;
3659
3660 default:
3661 abort ();
3662 }
3663 }
3664
3665 if (code == SCRATCH)
3666 {
3667 i = copy_insn_n_scratches++;
3668 if (i >= MAX_RECOG_OPERANDS)
3669 abort ();
3670 copy_insn_scratch_in[i] = orig;
3671 copy_insn_scratch_out[i] = copy;
3672 }
3673 else if (code == ASM_OPERANDS)
3674 {
3675 orig_asm_operands_vector = XVEC (orig, 3);
3676 copy_asm_operands_vector = XVEC (copy, 3);
3677 orig_asm_constraints_vector = XVEC (orig, 4);
3678 copy_asm_constraints_vector = XVEC (copy, 4);
3679 }
3680
3681 return copy;
3682}
3683
3684/* Create a new copy of an rtx.
3685 This function differs from copy_rtx in that it handles SCRATCHes and
3686 ASM_OPERANDs properly.
3687 INSN doesn't really have to be a full INSN; it could be just the
3688 pattern. */
3689rtx
3690copy_insn (insn)
3691 rtx insn;
3692{
3693 copy_insn_n_scratches = 0;
3694 orig_asm_operands_vector = 0;
3695 orig_asm_constraints_vector = 0;
3696 copy_asm_operands_vector = 0;
3697 copy_asm_constraints_vector = 0;
3698 return copy_insn_1 (insn);
3699}
59ec66dc 3700
23b2ce53
RS
3701/* Initialize data structures and variables in this file
3702 before generating rtl for each function. */
3703
3704void
3705init_emit ()
3706{
01d939e8 3707 struct function *f = cfun;
23b2ce53 3708
49ad7cfa 3709 f->emit = (struct emit_status *) xmalloc (sizeof (struct emit_status));
23b2ce53
RS
3710 first_insn = NULL;
3711 last_insn = NULL;
49ad7cfa 3712 seq_rtl_expr = NULL;
23b2ce53
RS
3713 cur_insn_uid = 1;
3714 reg_rtx_no = LAST_VIRTUAL_REGISTER + 1;
3715 last_linenum = 0;
3716 last_filename = 0;
3717 first_label_num = label_num;
3718 last_label_num = 0;
49ad7cfa 3719 seq_stack = NULL;
23b2ce53 3720
49ad7cfa 3721 clear_emit_caches ();
23b2ce53
RS
3722
3723 /* Init the tables that describe all the pseudo regs. */
3724
49ad7cfa 3725 f->emit->regno_pointer_flag_length = LAST_VIRTUAL_REGISTER + 101;
23b2ce53 3726
49ad7cfa 3727 f->emit->regno_pointer_flag
a3770a81 3728 = (char *) xcalloc (f->emit->regno_pointer_flag_length, sizeof (char));
23b2ce53 3729
49ad7cfa 3730 f->emit->regno_pointer_align
a3770a81
RH
3731 = (char *) xcalloc (f->emit->regno_pointer_flag_length,
3732 sizeof (char));
86fe05e0 3733
23b2ce53 3734 regno_reg_rtx
a3770a81
RH
3735 = (rtx *) xcalloc (f->emit->regno_pointer_flag_length * sizeof (rtx),
3736 sizeof (rtx));
23b2ce53
RS
3737
3738 /* Put copies of all the virtual register rtx into regno_reg_rtx. */
49ad7cfa 3739 init_virtual_regs (f->emit);
740ab4a2
RK
3740
3741 /* Indicate that the virtual registers and stack locations are
3742 all pointers. */
3743 REGNO_POINTER_FLAG (STACK_POINTER_REGNUM) = 1;
3744 REGNO_POINTER_FLAG (FRAME_POINTER_REGNUM) = 1;
15c9248c 3745 REGNO_POINTER_FLAG (HARD_FRAME_POINTER_REGNUM) = 1;
740ab4a2
RK
3746 REGNO_POINTER_FLAG (ARG_POINTER_REGNUM) = 1;
3747
3748 REGNO_POINTER_FLAG (VIRTUAL_INCOMING_ARGS_REGNUM) = 1;
3749 REGNO_POINTER_FLAG (VIRTUAL_STACK_VARS_REGNUM) = 1;
3750 REGNO_POINTER_FLAG (VIRTUAL_STACK_DYNAMIC_REGNUM) = 1;
3751 REGNO_POINTER_FLAG (VIRTUAL_OUTGOING_ARGS_REGNUM) = 1;
71038426 3752 REGNO_POINTER_FLAG (VIRTUAL_CFA_REGNUM) = 1;
5e82e7bd 3753
86fe05e0
RK
3754#ifdef STACK_BOUNDARY
3755 REGNO_POINTER_ALIGN (STACK_POINTER_REGNUM) = STACK_BOUNDARY / BITS_PER_UNIT;
3756 REGNO_POINTER_ALIGN (FRAME_POINTER_REGNUM) = STACK_BOUNDARY / BITS_PER_UNIT;
3757 REGNO_POINTER_ALIGN (HARD_FRAME_POINTER_REGNUM)
3758 = STACK_BOUNDARY / BITS_PER_UNIT;
3759 REGNO_POINTER_ALIGN (ARG_POINTER_REGNUM) = STACK_BOUNDARY / BITS_PER_UNIT;
3760
3761 REGNO_POINTER_ALIGN (VIRTUAL_INCOMING_ARGS_REGNUM)
3762 = STACK_BOUNDARY / BITS_PER_UNIT;
3763 REGNO_POINTER_ALIGN (VIRTUAL_STACK_VARS_REGNUM)
3764 = STACK_BOUNDARY / BITS_PER_UNIT;
3765 REGNO_POINTER_ALIGN (VIRTUAL_STACK_DYNAMIC_REGNUM)
3766 = STACK_BOUNDARY / BITS_PER_UNIT;
3767 REGNO_POINTER_ALIGN (VIRTUAL_OUTGOING_ARGS_REGNUM)
3768 = STACK_BOUNDARY / BITS_PER_UNIT;
71038426 3769 REGNO_POINTER_ALIGN (VIRTUAL_CFA_REGNUM) = UNITS_PER_WORD;
86fe05e0
RK
3770#endif
3771
5e82e7bd
JVA
3772#ifdef INIT_EXPANDERS
3773 INIT_EXPANDERS;
3774#endif
23b2ce53
RS
3775}
3776
87ff9c8e
RH
3777/* Mark SS for GC. */
3778
3779static void
3780mark_sequence_stack (ss)
3781 struct sequence_stack *ss;
3782{
3783 while (ss)
3784 {
3785 ggc_mark_rtx (ss->first);
3786 ggc_mark_tree (ss->sequence_rtl_expr);
3787 ss = ss->next;
3788 }
3789}
3790
3791/* Mark ES for GC. */
3792
3793void
fa51b01b 3794mark_emit_status (es)
87ff9c8e
RH
3795 struct emit_status *es;
3796{
3797 rtx *r;
3798 int i;
3799
3800 if (es == 0)
3801 return;
3802
3803 for (i = es->regno_pointer_flag_length, r = es->x_regno_reg_rtx;
3804 i > 0; --i, ++r)
3805 ggc_mark_rtx (*r);
3806
3807 mark_sequence_stack (es->sequence_stack);
3808 ggc_mark_tree (es->sequence_rtl_expr);
3809 ggc_mark_rtx (es->x_first_insn);
3810}
3811
23b2ce53
RS
3812/* Create some permanent unique rtl objects shared between all functions.
3813 LINE_NUMBERS is nonzero if line numbers are to be generated. */
3814
3815void
3816init_emit_once (line_numbers)
3817 int line_numbers;
3818{
3819 int i;
3820 enum machine_mode mode;
9ec36da5 3821 enum machine_mode double_mode;
23b2ce53
RS
3822
3823 no_line_numbers = ! line_numbers;
3824
43fa6302
AS
3825 /* Compute the word and byte modes. */
3826
3827 byte_mode = VOIDmode;
3828 word_mode = VOIDmode;
3829 double_mode = VOIDmode;
3830
3831 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
3832 mode = GET_MODE_WIDER_MODE (mode))
3833 {
3834 if (GET_MODE_BITSIZE (mode) == BITS_PER_UNIT
3835 && byte_mode == VOIDmode)
3836 byte_mode = mode;
3837
3838 if (GET_MODE_BITSIZE (mode) == BITS_PER_WORD
3839 && word_mode == VOIDmode)
3840 word_mode = mode;
3841 }
3842
3843#ifndef DOUBLE_TYPE_SIZE
3844#define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
3845#endif
3846
3847 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
3848 mode = GET_MODE_WIDER_MODE (mode))
3849 {
3850 if (GET_MODE_BITSIZE (mode) == DOUBLE_TYPE_SIZE
3851 && double_mode == VOIDmode)
3852 double_mode = mode;
3853 }
3854
3855 ptr_mode = mode_for_size (POINTER_SIZE, GET_MODE_CLASS (Pmode), 0);
3856
5da077de
AS
3857 /* Assign register numbers to the globally defined register rtx.
3858 This must be done at runtime because the register number field
3859 is in a union and some compilers can't initialize unions. */
3860
3861 pc_rtx = gen_rtx (PC, VOIDmode);
3862 cc0_rtx = gen_rtx (CC0, VOIDmode);
3863 stack_pointer_rtx = gen_rtx_raw_REG (Pmode, STACK_POINTER_REGNUM);
3864 frame_pointer_rtx = gen_rtx_raw_REG (Pmode, FRAME_POINTER_REGNUM);
3865 if (hard_frame_pointer_rtx == 0)
3866 hard_frame_pointer_rtx = gen_rtx_raw_REG (Pmode,
3867 HARD_FRAME_POINTER_REGNUM);
3868 if (arg_pointer_rtx == 0)
3869 arg_pointer_rtx = gen_rtx_raw_REG (Pmode, ARG_POINTER_REGNUM);
3870 virtual_incoming_args_rtx =
3871 gen_rtx_raw_REG (Pmode, VIRTUAL_INCOMING_ARGS_REGNUM);
3872 virtual_stack_vars_rtx =
3873 gen_rtx_raw_REG (Pmode, VIRTUAL_STACK_VARS_REGNUM);
3874 virtual_stack_dynamic_rtx =
3875 gen_rtx_raw_REG (Pmode, VIRTUAL_STACK_DYNAMIC_REGNUM);
3876 virtual_outgoing_args_rtx =
3877 gen_rtx_raw_REG (Pmode, VIRTUAL_OUTGOING_ARGS_REGNUM);
3878 virtual_cfa_rtx = gen_rtx_raw_REG (Pmode, VIRTUAL_CFA_REGNUM);
3879
3880 /* These rtx must be roots if GC is enabled. */
3881 if (ggc_p)
3882 ggc_add_rtx_root (global_rtl, GR_MAX);
3883
5da077de
AS
3884#ifdef INIT_EXPANDERS
3885 /* This is to initialize save_machine_status and restore_machine_status before
3886 the first call to push_function_context_to. This is needed by the Chill
3887 front end which calls push_function_context_to before the first cal to
3888 init_function_start. */
3889 INIT_EXPANDERS;
3890#endif
3891
23b2ce53
RS
3892 /* Create the unique rtx's for certain rtx codes and operand values. */
3893
c5c76735
JL
3894 /* Don't use gen_rtx here since gen_rtx in this case
3895 tries to use these variables. */
23b2ce53 3896 for (i = - MAX_SAVED_CONST_INT; i <= MAX_SAVED_CONST_INT; i++)
5da077de
AS
3897 const_int_rtx[i + MAX_SAVED_CONST_INT] =
3898 gen_rtx_raw_CONST_INT (VOIDmode, i);
3899 if (ggc_p)
3900 ggc_add_rtx_root (const_int_rtx, 2 * MAX_SAVED_CONST_INT + 1);
23b2ce53 3901
68d75312
JC
3902 if (STORE_FLAG_VALUE >= - MAX_SAVED_CONST_INT
3903 && STORE_FLAG_VALUE <= MAX_SAVED_CONST_INT)
5da077de 3904 const_true_rtx = const_int_rtx[STORE_FLAG_VALUE + MAX_SAVED_CONST_INT];
68d75312 3905 else
3b80f6ca 3906 const_true_rtx = gen_rtx_CONST_INT (VOIDmode, STORE_FLAG_VALUE);
23b2ce53 3907
9ec36da5
JL
3908 dconst0 = REAL_VALUE_ATOF ("0", double_mode);
3909 dconst1 = REAL_VALUE_ATOF ("1", double_mode);
3910 dconst2 = REAL_VALUE_ATOF ("2", double_mode);
3911 dconstm1 = REAL_VALUE_ATOF ("-1", double_mode);
23b2ce53
RS
3912
3913 for (i = 0; i <= 2; i++)
3914 {
3915 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
3916 mode = GET_MODE_WIDER_MODE (mode))
3917 {
3918 rtx tem = rtx_alloc (CONST_DOUBLE);
3919 union real_extract u;
3920
4c9a05bc 3921 bzero ((char *) &u, sizeof u); /* Zero any holes in a structure. */
23b2ce53
RS
3922 u.d = i == 0 ? dconst0 : i == 1 ? dconst1 : dconst2;
3923
4c9a05bc 3924 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (tem), sizeof u);
23b2ce53
RS
3925 CONST_DOUBLE_MEM (tem) = cc0_rtx;
3926 PUT_MODE (tem, mode);
3927
3928 const_tiny_rtx[i][(int) mode] = tem;
3929 }
3930
906c4e36 3931 const_tiny_rtx[i][(int) VOIDmode] = GEN_INT (i);
23b2ce53
RS
3932
3933 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
3934 mode = GET_MODE_WIDER_MODE (mode))
906c4e36 3935 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
33d3e559
RS
3936
3937 for (mode = GET_CLASS_NARROWEST_MODE (MODE_PARTIAL_INT);
3938 mode != VOIDmode;
3939 mode = GET_MODE_WIDER_MODE (mode))
3940 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
23b2ce53
RS
3941 }
3942
aea87e88
RH
3943 for (mode = CCmode; mode < MAX_MACHINE_MODE; ++mode)
3944 if (GET_MODE_CLASS (mode) == MODE_CC)
3945 const_tiny_rtx[0][(int) mode] = const0_rtx;
23b2ce53 3946
d7db6646 3947 ggc_add_rtx_root (&const_tiny_rtx[0][0], sizeof(const_tiny_rtx)/sizeof(rtx));
21cd906e 3948 ggc_add_rtx_root (&const_true_rtx, 1);
a7e1e2ac
AO
3949
3950#ifdef RETURN_ADDRESS_POINTER_REGNUM
3951 return_address_pointer_rtx
3952 = gen_rtx_raw_REG (Pmode, RETURN_ADDRESS_POINTER_REGNUM);
3953#endif
3954
3955#ifdef STRUCT_VALUE
3956 struct_value_rtx = STRUCT_VALUE;
3957#else
3958 struct_value_rtx = gen_rtx_REG (Pmode, STRUCT_VALUE_REGNUM);
3959#endif
3960
3961#ifdef STRUCT_VALUE_INCOMING
3962 struct_value_incoming_rtx = STRUCT_VALUE_INCOMING;
3963#else
3964#ifdef STRUCT_VALUE_INCOMING_REGNUM
3965 struct_value_incoming_rtx
3966 = gen_rtx_REG (Pmode, STRUCT_VALUE_INCOMING_REGNUM);
3967#else
3968 struct_value_incoming_rtx = struct_value_rtx;
3969#endif
3970#endif
3971
3972#ifdef STATIC_CHAIN_REGNUM
3973 static_chain_rtx = gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM);
3974
3975#ifdef STATIC_CHAIN_INCOMING_REGNUM
3976 if (STATIC_CHAIN_INCOMING_REGNUM != STATIC_CHAIN_REGNUM)
3977 static_chain_incoming_rtx
3978 = gen_rtx_REG (Pmode, STATIC_CHAIN_INCOMING_REGNUM);
3979 else
3980#endif
3981 static_chain_incoming_rtx = static_chain_rtx;
3982#endif
3983
3984#ifdef STATIC_CHAIN
3985 static_chain_rtx = STATIC_CHAIN;
3986
3987#ifdef STATIC_CHAIN_INCOMING
3988 static_chain_incoming_rtx = STATIC_CHAIN_INCOMING;
3989#else
3990 static_chain_incoming_rtx = static_chain_rtx;
3991#endif
3992#endif
3993
3994#ifdef PIC_OFFSET_TABLE_REGNUM
3995 pic_offset_table_rtx = gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM);
3996#endif
3997
d7db6646
RH
3998 ggc_add_rtx_root (&pic_offset_table_rtx, 1);
3999 ggc_add_rtx_root (&struct_value_rtx, 1);
4000 ggc_add_rtx_root (&struct_value_incoming_rtx, 1);
4001 ggc_add_rtx_root (&static_chain_rtx, 1);
4002 ggc_add_rtx_root (&static_chain_incoming_rtx, 1);
4003 ggc_add_rtx_root (&return_address_pointer_rtx, 1);
23b2ce53 4004}
a11759a3
JR
4005\f
4006/* Query and clear/ restore no_line_numbers. This is used by the
4007 switch / case handling in stmt.c to give proper line numbers in
4008 warnings about unreachable code. */
4009
4010int
4011force_line_numbers ()
4012{
4013 int old = no_line_numbers;
4014
4015 no_line_numbers = 0;
4016 if (old)
4017 force_next_line_note ();
4018 return old;
4019}
4020
4021void
4022restore_line_number_status (old_value)
4023 int old_value;
4024{
4025 no_line_numbers = old_value;
4026}