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