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