]>
Commit | Line | Data |
---|---|---|
6f086dfc | 1 | /* Expands front end tree to back end RTL for GNU C-Compiler |
a5cad800 | 2 | Copyright (C) 1987, 88, 89, 91-98, 1999 Free Software Foundation, Inc. |
6f086dfc 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 | |
a35311b0 RK |
18 | the Free Software Foundation, 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. */ | |
6f086dfc RS |
20 | |
21 | ||
22 | /* This file handles the generation of rtl code from tree structure | |
23 | at the level of the function as a whole. | |
24 | It creates the rtl expressions for parameters and auto variables | |
25 | and has full responsibility for allocating stack slots. | |
26 | ||
27 | `expand_function_start' is called at the beginning of a function, | |
28 | before the function body is parsed, and `expand_function_end' is | |
29 | called after parsing the body. | |
30 | ||
31 | Call `assign_stack_local' to allocate a stack slot for a local variable. | |
32 | This is usually done during the RTL generation for the function body, | |
33 | but it can also be done in the reload pass when a pseudo-register does | |
34 | not get a hard register. | |
35 | ||
36 | Call `put_var_into_stack' when you learn, belatedly, that a variable | |
37 | previously given a pseudo-register must in fact go in the stack. | |
38 | This function changes the DECL_RTL to be a stack slot instead of a reg | |
39 | then scans all the RTL instructions so far generated to correct them. */ | |
40 | ||
41 | #include "config.h" | |
670ee920 | 42 | #include "system.h" |
6f086dfc RS |
43 | #include "rtl.h" |
44 | #include "tree.h" | |
45 | #include "flags.h" | |
1ef08c63 | 46 | #include "except.h" |
6f086dfc RS |
47 | #include "function.h" |
48 | #include "insn-flags.h" | |
49 | #include "expr.h" | |
50 | #include "insn-codes.h" | |
51 | #include "regs.h" | |
52 | #include "hard-reg-set.h" | |
53 | #include "insn-config.h" | |
54 | #include "recog.h" | |
55 | #include "output.h" | |
bdac5f58 | 56 | #include "basic-block.h" |
c20bf1f3 | 57 | #include "obstack.h" |
10f0ad3d | 58 | #include "toplev.h" |
6f086dfc | 59 | |
c795bca9 BS |
60 | #if !defined PREFERRED_STACK_BOUNDARY && defined STACK_BOUNDARY |
61 | #define PREFERRED_STACK_BOUNDARY STACK_BOUNDARY | |
62 | #endif | |
63 | ||
189cc377 RK |
64 | #ifndef TRAMPOLINE_ALIGNMENT |
65 | #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY | |
66 | #endif | |
67 | ||
293e3de4 RS |
68 | /* Some systems use __main in a way incompatible with its use in gcc, in these |
69 | cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to | |
70 | give the same symbol without quotes for an alternative entry point. You | |
0f41302f | 71 | must define both, or neither. */ |
293e3de4 RS |
72 | #ifndef NAME__MAIN |
73 | #define NAME__MAIN "__main" | |
74 | #define SYMBOL__MAIN __main | |
75 | #endif | |
76 | ||
6f086dfc RS |
77 | /* Round a value to the lowest integer less than it that is a multiple of |
78 | the required alignment. Avoid using division in case the value is | |
79 | negative. Assume the alignment is a power of two. */ | |
80 | #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1)) | |
81 | ||
82 | /* Similar, but round to the next highest integer that meets the | |
83 | alignment. */ | |
84 | #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1)) | |
85 | ||
86 | /* NEED_SEPARATE_AP means that we cannot derive ap from the value of fp | |
87 | during rtl generation. If they are different register numbers, this is | |
88 | always true. It may also be true if | |
89 | FIRST_PARM_OFFSET - STARTING_FRAME_OFFSET is not a constant during rtl | |
90 | generation. See fix_lexical_addr for details. */ | |
91 | ||
92 | #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM | |
93 | #define NEED_SEPARATE_AP | |
94 | #endif | |
95 | ||
96 | /* Number of bytes of args popped by function being compiled on its return. | |
97 | Zero if no bytes are to be popped. | |
98 | May affect compilation of return insn or of function epilogue. */ | |
99 | ||
100 | int current_function_pops_args; | |
101 | ||
102 | /* Nonzero if function being compiled needs to be given an address | |
103 | where the value should be stored. */ | |
104 | ||
105 | int current_function_returns_struct; | |
106 | ||
107 | /* Nonzero if function being compiled needs to | |
108 | return the address of where it has put a structure value. */ | |
109 | ||
110 | int current_function_returns_pcc_struct; | |
111 | ||
112 | /* Nonzero if function being compiled needs to be passed a static chain. */ | |
113 | ||
114 | int current_function_needs_context; | |
115 | ||
116 | /* Nonzero if function being compiled can call setjmp. */ | |
117 | ||
118 | int current_function_calls_setjmp; | |
119 | ||
120 | /* Nonzero if function being compiled can call longjmp. */ | |
121 | ||
122 | int current_function_calls_longjmp; | |
123 | ||
124 | /* Nonzero if function being compiled receives nonlocal gotos | |
125 | from nested functions. */ | |
126 | ||
127 | int current_function_has_nonlocal_label; | |
128 | ||
8634413a JW |
129 | /* Nonzero if function being compiled has nonlocal gotos to parent |
130 | function. */ | |
131 | ||
132 | int current_function_has_nonlocal_goto; | |
133 | ||
4d1d8045 BS |
134 | /* Nonzero if this function has a computed goto. |
135 | ||
136 | It is computed during find_basic_blocks or during stupid life | |
137 | analysis. */ | |
138 | ||
139 | int current_function_has_computed_jump; | |
140 | ||
6f086dfc RS |
141 | /* Nonzero if function being compiled contains nested functions. */ |
142 | ||
143 | int current_function_contains_functions; | |
144 | ||
fdb8a883 JW |
145 | /* Nonzero if function being compiled doesn't modify the stack pointer |
146 | (ignoring the prologue and epilogue). This is only valid after | |
147 | life_analysis has run. */ | |
148 | ||
149 | int current_function_sp_is_unchanging; | |
150 | ||
173cd503 JM |
151 | /* Nonzero if the current function is a thunk (a lightweight function that |
152 | just adjusts one of its arguments and forwards to another function), so | |
153 | we should try to cut corners where we can. */ | |
154 | int current_function_is_thunk; | |
155 | ||
6f086dfc RS |
156 | /* Nonzero if function being compiled can call alloca, |
157 | either as a subroutine or builtin. */ | |
158 | ||
159 | int current_function_calls_alloca; | |
160 | ||
161 | /* Nonzero if the current function returns a pointer type */ | |
162 | ||
163 | int current_function_returns_pointer; | |
164 | ||
165 | /* If some insns can be deferred to the delay slots of the epilogue, the | |
166 | delay list for them is recorded here. */ | |
167 | ||
168 | rtx current_function_epilogue_delay_list; | |
169 | ||
170 | /* If function's args have a fixed size, this is that size, in bytes. | |
171 | Otherwise, it is -1. | |
172 | May affect compilation of return insn or of function epilogue. */ | |
173 | ||
174 | int current_function_args_size; | |
175 | ||
176 | /* # bytes the prologue should push and pretend that the caller pushed them. | |
177 | The prologue must do this, but only if parms can be passed in registers. */ | |
178 | ||
179 | int current_function_pretend_args_size; | |
180 | ||
f7339633 | 181 | /* # of bytes of outgoing arguments. If ACCUMULATE_OUTGOING_ARGS is |
0f41302f | 182 | defined, the needed space is pushed by the prologue. */ |
6f086dfc RS |
183 | |
184 | int current_function_outgoing_args_size; | |
185 | ||
186 | /* This is the offset from the arg pointer to the place where the first | |
187 | anonymous arg can be found, if there is one. */ | |
188 | ||
189 | rtx current_function_arg_offset_rtx; | |
190 | ||
191 | /* Nonzero if current function uses varargs.h or equivalent. | |
192 | Zero for functions that use stdarg.h. */ | |
193 | ||
194 | int current_function_varargs; | |
195 | ||
ebb904cb RK |
196 | /* Nonzero if current function uses stdarg.h or equivalent. |
197 | Zero for functions that use varargs.h. */ | |
198 | ||
199 | int current_function_stdarg; | |
200 | ||
6f086dfc RS |
201 | /* Quantities of various kinds of registers |
202 | used for the current function's args. */ | |
203 | ||
204 | CUMULATIVE_ARGS current_function_args_info; | |
205 | ||
206 | /* Name of function now being compiled. */ | |
207 | ||
208 | char *current_function_name; | |
209 | ||
f345de42 JL |
210 | /* If non-zero, an RTL expression for the location at which the current |
211 | function returns its result. If the current function returns its | |
212 | result in a register, current_function_return_rtx will always be | |
213 | the hard register containing the result. */ | |
6f086dfc RS |
214 | |
215 | rtx current_function_return_rtx; | |
216 | ||
217 | /* Nonzero if the current function uses the constant pool. */ | |
218 | ||
219 | int current_function_uses_const_pool; | |
220 | ||
221 | /* Nonzero if the current function uses pic_offset_table_rtx. */ | |
222 | int current_function_uses_pic_offset_table; | |
223 | ||
224 | /* The arg pointer hard register, or the pseudo into which it was copied. */ | |
225 | rtx current_function_internal_arg_pointer; | |
226 | ||
aeb302bb JM |
227 | /* Language-specific reason why the current function cannot be made inline. */ |
228 | char *current_function_cannot_inline; | |
229 | ||
07417085 KR |
230 | /* Nonzero if instrumentation calls for function entry and exit should be |
231 | generated. */ | |
232 | int current_function_instrument_entry_exit; | |
233 | ||
7d384cc0 KR |
234 | /* Nonzero if memory access checking be enabled in the current function. */ |
235 | int current_function_check_memory_usage; | |
236 | ||
6f086dfc RS |
237 | /* The FUNCTION_DECL for an inline function currently being expanded. */ |
238 | tree inline_function_decl; | |
239 | ||
240 | /* Number of function calls seen so far in current function. */ | |
241 | ||
242 | int function_call_count; | |
243 | ||
244 | /* List (chain of TREE_LIST) of LABEL_DECLs for all nonlocal labels | |
245 | (labels to which there can be nonlocal gotos from nested functions) | |
246 | in this function. */ | |
247 | ||
248 | tree nonlocal_labels; | |
249 | ||
ba716ac9 BS |
250 | /* List (chain of EXPR_LIST) of stack slots that hold the current handlers |
251 | for nonlocal gotos. There is one for every nonlocal label in the function; | |
252 | this list matches the one in nonlocal_labels. | |
6f086dfc RS |
253 | Zero when function does not have nonlocal labels. */ |
254 | ||
ba716ac9 | 255 | rtx nonlocal_goto_handler_slots; |
6f086dfc RS |
256 | |
257 | /* RTX for stack slot that holds the stack pointer value to restore | |
258 | for a nonlocal goto. | |
259 | Zero when function does not have nonlocal labels. */ | |
260 | ||
261 | rtx nonlocal_goto_stack_level; | |
262 | ||
263 | /* Label that will go on parm cleanup code, if any. | |
264 | Jumping to this label runs cleanup code for parameters, if | |
265 | such code must be run. Following this code is the logical return label. */ | |
266 | ||
267 | rtx cleanup_label; | |
268 | ||
269 | /* Label that will go on function epilogue. | |
270 | Jumping to this label serves as a "return" instruction | |
271 | on machines which require execution of the epilogue on all returns. */ | |
272 | ||
273 | rtx return_label; | |
274 | ||
275 | /* List (chain of EXPR_LISTs) of pseudo-regs of SAVE_EXPRs. | |
276 | So we can mark them all live at the end of the function, if nonopt. */ | |
277 | rtx save_expr_regs; | |
278 | ||
279 | /* List (chain of EXPR_LISTs) of all stack slots in this function. | |
280 | Made for the sake of unshare_all_rtl. */ | |
281 | rtx stack_slot_list; | |
282 | ||
283 | /* Chain of all RTL_EXPRs that have insns in them. */ | |
284 | tree rtl_expr_chain; | |
285 | ||
286 | /* Label to jump back to for tail recursion, or 0 if we have | |
287 | not yet needed one for this function. */ | |
288 | rtx tail_recursion_label; | |
289 | ||
290 | /* Place after which to insert the tail_recursion_label if we need one. */ | |
291 | rtx tail_recursion_reentry; | |
292 | ||
293 | /* Location at which to save the argument pointer if it will need to be | |
294 | referenced. There are two cases where this is done: if nonlocal gotos | |
295 | exist, or if vars stored at an offset from the argument pointer will be | |
296 | needed by inner routines. */ | |
297 | ||
298 | rtx arg_pointer_save_area; | |
299 | ||
300 | /* Offset to end of allocated area of stack frame. | |
301 | If stack grows down, this is the address of the last stack slot allocated. | |
302 | If stack grows up, this is the address for the next slot. */ | |
8af5168b | 303 | HOST_WIDE_INT frame_offset; |
6f086dfc RS |
304 | |
305 | /* List (chain of TREE_LISTs) of static chains for containing functions. | |
306 | Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx | |
307 | in an RTL_EXPR in the TREE_VALUE. */ | |
308 | static tree context_display; | |
309 | ||
310 | /* List (chain of TREE_LISTs) of trampolines for nested functions. | |
311 | The trampoline sets up the static chain and jumps to the function. | |
312 | We supply the trampoline's address when the function's address is requested. | |
313 | ||
314 | Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx | |
315 | in an RTL_EXPR in the TREE_VALUE. */ | |
316 | static tree trampoline_list; | |
317 | ||
318 | /* Insn after which register parms and SAVE_EXPRs are born, if nonopt. */ | |
319 | static rtx parm_birth_insn; | |
320 | ||
321 | #if 0 | |
322 | /* Nonzero if a stack slot has been generated whose address is not | |
323 | actually valid. It means that the generated rtl must all be scanned | |
324 | to detect and correct the invalid addresses where they occur. */ | |
325 | static int invalid_stack_slot; | |
326 | #endif | |
327 | ||
328 | /* Last insn of those whose job was to put parms into their nominal homes. */ | |
329 | static rtx last_parm_insn; | |
330 | ||
e9a25f70 JL |
331 | /* 1 + last pseudo register number possibly used for loading a copy |
332 | of a parameter of this function. */ | |
333 | int max_parm_reg; | |
6f086dfc RS |
334 | |
335 | /* Vector indexed by REGNO, containing location on stack in which | |
336 | to put the parm which is nominally in pseudo register REGNO, | |
e9a25f70 JL |
337 | if we discover that that parm must go in the stack. The highest |
338 | element in this vector is one less than MAX_PARM_REG, above. */ | |
339 | rtx *parm_reg_stack_loc; | |
6f086dfc | 340 | |
6f086dfc RS |
341 | /* Nonzero once virtual register instantiation has been done. |
342 | assign_stack_local uses frame_pointer_rtx when this is nonzero. */ | |
343 | static int virtuals_instantiated; | |
344 | ||
46766466 RS |
345 | /* These variables hold pointers to functions to |
346 | save and restore machine-specific data, | |
347 | in push_function_context and pop_function_context. */ | |
9e014ded RK |
348 | void (*save_machine_status) PROTO((struct function *)); |
349 | void (*restore_machine_status) PROTO((struct function *)); | |
46766466 | 350 | |
6f086dfc RS |
351 | /* Nonzero if we need to distinguish between the return value of this function |
352 | and the return value of a function called by this function. This helps | |
353 | integrate.c */ | |
354 | ||
355 | extern int rtx_equal_function_value_matters; | |
e7a84011 | 356 | extern tree sequence_rtl_expr; |
6f086dfc RS |
357 | \f |
358 | /* In order to evaluate some expressions, such as function calls returning | |
359 | structures in memory, we need to temporarily allocate stack locations. | |
360 | We record each allocated temporary in the following structure. | |
361 | ||
362 | Associated with each temporary slot is a nesting level. When we pop up | |
363 | one level, all temporaries associated with the previous level are freed. | |
364 | Normally, all temporaries are freed after the execution of the statement | |
365 | in which they were created. However, if we are inside a ({...}) grouping, | |
366 | the result may be in a temporary and hence must be preserved. If the | |
367 | result could be in a temporary, we preserve it if we can determine which | |
368 | one it is in. If we cannot determine which temporary may contain the | |
369 | result, all temporaries are preserved. A temporary is preserved by | |
370 | pretending it was allocated at the previous nesting level. | |
371 | ||
372 | Automatic variables are also assigned temporary slots, at the nesting | |
373 | level where they are defined. They are marked a "kept" so that | |
374 | free_temp_slots will not free them. */ | |
375 | ||
376 | struct temp_slot | |
377 | { | |
378 | /* Points to next temporary slot. */ | |
379 | struct temp_slot *next; | |
0f41302f | 380 | /* The rtx to used to reference the slot. */ |
6f086dfc | 381 | rtx slot; |
e5e76139 RK |
382 | /* The rtx used to represent the address if not the address of the |
383 | slot above. May be an EXPR_LIST if multiple addresses exist. */ | |
384 | rtx address; | |
6f086dfc | 385 | /* The size, in units, of the slot. */ |
e5e809f4 | 386 | HOST_WIDE_INT size; |
e7a84011 RK |
387 | /* The value of `sequence_rtl_expr' when this temporary is allocated. */ |
388 | tree rtl_expr; | |
6f086dfc RS |
389 | /* Non-zero if this temporary is currently in use. */ |
390 | char in_use; | |
a25d4ba2 RK |
391 | /* Non-zero if this temporary has its address taken. */ |
392 | char addr_taken; | |
6f086dfc RS |
393 | /* Nesting level at which this slot is being used. */ |
394 | int level; | |
395 | /* Non-zero if this should survive a call to free_temp_slots. */ | |
396 | int keep; | |
fc91b0d0 RK |
397 | /* The offset of the slot from the frame_pointer, including extra space |
398 | for alignment. This info is for combine_temp_slots. */ | |
e5e809f4 | 399 | HOST_WIDE_INT base_offset; |
fc91b0d0 RK |
400 | /* The size of the slot, including extra space for alignment. This |
401 | info is for combine_temp_slots. */ | |
e5e809f4 | 402 | HOST_WIDE_INT full_size; |
6f086dfc RS |
403 | }; |
404 | ||
405 | /* List of all temporaries allocated, both available and in use. */ | |
406 | ||
407 | struct temp_slot *temp_slots; | |
408 | ||
409 | /* Current nesting level for temporaries. */ | |
410 | ||
411 | int temp_slot_level; | |
e5e809f4 JL |
412 | |
413 | /* Current nesting level for variables in a block. */ | |
414 | ||
415 | int var_temp_slot_level; | |
f5963e61 JL |
416 | |
417 | /* When temporaries are created by TARGET_EXPRs, they are created at | |
418 | this level of temp_slot_level, so that they can remain allocated | |
419 | until no longer needed. CLEANUP_POINT_EXPRs define the lifetime | |
420 | of TARGET_EXPRs. */ | |
421 | int target_temp_slot_level; | |
6f086dfc | 422 | \f |
e15679f8 RK |
423 | /* This structure is used to record MEMs or pseudos used to replace VAR, any |
424 | SUBREGs of VAR, and any MEMs containing VAR as an address. We need to | |
425 | maintain this list in case two operands of an insn were required to match; | |
426 | in that case we must ensure we use the same replacement. */ | |
427 | ||
428 | struct fixup_replacement | |
429 | { | |
430 | rtx old; | |
431 | rtx new; | |
432 | struct fixup_replacement *next; | |
433 | }; | |
434 | ||
435 | /* Forward declarations. */ | |
436 | ||
1ac4f799 JL |
437 | static rtx assign_outer_stack_local PROTO ((enum machine_mode, HOST_WIDE_INT, |
438 | int, struct function *)); | |
e15679f8 RK |
439 | static struct temp_slot *find_temp_slot_from_address PROTO((rtx)); |
440 | static void put_reg_into_stack PROTO((struct function *, rtx, tree, | |
0006e95b | 441 | enum machine_mode, enum machine_mode, |
e5e809f4 | 442 | int, int, int)); |
e15679f8 RK |
443 | static void fixup_var_refs PROTO((rtx, enum machine_mode, int)); |
444 | static struct fixup_replacement | |
445 | *find_fixup_replacement PROTO((struct fixup_replacement **, rtx)); | |
446 | static void fixup_var_refs_insns PROTO((rtx, enum machine_mode, int, | |
447 | rtx, int)); | |
448 | static void fixup_var_refs_1 PROTO((rtx, enum machine_mode, rtx *, rtx, | |
449 | struct fixup_replacement **)); | |
450 | static rtx fixup_memory_subreg PROTO((rtx, rtx, int)); | |
451 | static rtx walk_fixup_memory_subreg PROTO((rtx, rtx, int)); | |
452 | static rtx fixup_stack_1 PROTO((rtx, rtx)); | |
453 | static void optimize_bit_field PROTO((rtx, rtx, rtx *)); | |
454 | static void instantiate_decls PROTO((tree, int)); | |
455 | static void instantiate_decls_1 PROTO((tree, int)); | |
456 | static void instantiate_decl PROTO((rtx, int, int)); | |
457 | static int instantiate_virtual_regs_1 PROTO((rtx *, rtx, int)); | |
458 | static void delete_handlers PROTO((void)); | |
459 | static void pad_to_arg_alignment PROTO((struct args_size *, int)); | |
51723711 | 460 | #ifndef ARGS_GROW_DOWNWARD |
e15679f8 RK |
461 | static void pad_below PROTO((struct args_size *, enum machine_mode, |
462 | tree)); | |
51723711 | 463 | #endif |
487a6e06 | 464 | #ifdef ARGS_GROW_DOWNWARD |
e15679f8 | 465 | static tree round_down PROTO((tree, int)); |
487a6e06 | 466 | #endif |
e15679f8 RK |
467 | static rtx round_trampoline_addr PROTO((rtx)); |
468 | static tree blocks_nreverse PROTO((tree)); | |
469 | static int all_blocks PROTO((tree, tree *)); | |
081f5e7e | 470 | #if defined (HAVE_prologue) || defined (HAVE_epilogue) |
487a6e06 | 471 | static int *record_insns PROTO((rtx)); |
e15679f8 | 472 | static int contains PROTO((rtx, int *)); |
081f5e7e | 473 | #endif /* HAVE_prologue || HAVE_epilogue */ |
e9a25f70 | 474 | static void put_addressof_into_stack PROTO((rtx)); |
f7b6d104 | 475 | static void purge_addressof_1 PROTO((rtx *, rtx, int, int)); |
c20bf1f3 | 476 | \f |
6f086dfc RS |
477 | /* Pointer to chain of `struct function' for containing functions. */ |
478 | struct function *outer_function_chain; | |
479 | ||
480 | /* Given a function decl for a containing function, | |
481 | return the `struct function' for it. */ | |
482 | ||
483 | struct function * | |
484 | find_function_data (decl) | |
485 | tree decl; | |
486 | { | |
487 | struct function *p; | |
e5e809f4 | 488 | |
6f086dfc RS |
489 | for (p = outer_function_chain; p; p = p->next) |
490 | if (p->decl == decl) | |
491 | return p; | |
e5e809f4 | 492 | |
6f086dfc RS |
493 | abort (); |
494 | } | |
495 | ||
496 | /* Save the current context for compilation of a nested function. | |
497 | This is called from language-specific code. | |
498 | The caller is responsible for saving any language-specific status, | |
6dc42e49 | 499 | since this function knows only about language-independent variables. */ |
6f086dfc RS |
500 | |
501 | void | |
a0dabda5 JM |
502 | push_function_context_to (context) |
503 | tree context; | |
6f086dfc RS |
504 | { |
505 | struct function *p = (struct function *) xmalloc (sizeof (struct function)); | |
506 | ||
507 | p->next = outer_function_chain; | |
508 | outer_function_chain = p; | |
509 | ||
510 | p->name = current_function_name; | |
511 | p->decl = current_function_decl; | |
512 | p->pops_args = current_function_pops_args; | |
513 | p->returns_struct = current_function_returns_struct; | |
514 | p->returns_pcc_struct = current_function_returns_pcc_struct; | |
1651bdfe | 515 | p->returns_pointer = current_function_returns_pointer; |
6f086dfc RS |
516 | p->needs_context = current_function_needs_context; |
517 | p->calls_setjmp = current_function_calls_setjmp; | |
518 | p->calls_longjmp = current_function_calls_longjmp; | |
519 | p->calls_alloca = current_function_calls_alloca; | |
520 | p->has_nonlocal_label = current_function_has_nonlocal_label; | |
8634413a | 521 | p->has_nonlocal_goto = current_function_has_nonlocal_goto; |
a0dabda5 | 522 | p->contains_functions = current_function_contains_functions; |
173cd503 | 523 | p->is_thunk = current_function_is_thunk; |
6f086dfc RS |
524 | p->args_size = current_function_args_size; |
525 | p->pretend_args_size = current_function_pretend_args_size; | |
526 | p->arg_offset_rtx = current_function_arg_offset_rtx; | |
3b69d50e | 527 | p->varargs = current_function_varargs; |
ebb904cb | 528 | p->stdarg = current_function_stdarg; |
6f086dfc RS |
529 | p->uses_const_pool = current_function_uses_const_pool; |
530 | p->uses_pic_offset_table = current_function_uses_pic_offset_table; | |
531 | p->internal_arg_pointer = current_function_internal_arg_pointer; | |
aeb302bb | 532 | p->cannot_inline = current_function_cannot_inline; |
6f086dfc RS |
533 | p->max_parm_reg = max_parm_reg; |
534 | p->parm_reg_stack_loc = parm_reg_stack_loc; | |
535 | p->outgoing_args_size = current_function_outgoing_args_size; | |
536 | p->return_rtx = current_function_return_rtx; | |
ba716ac9 | 537 | p->nonlocal_goto_handler_slots = nonlocal_goto_handler_slots; |
6f086dfc RS |
538 | p->nonlocal_goto_stack_level = nonlocal_goto_stack_level; |
539 | p->nonlocal_labels = nonlocal_labels; | |
540 | p->cleanup_label = cleanup_label; | |
541 | p->return_label = return_label; | |
542 | p->save_expr_regs = save_expr_regs; | |
543 | p->stack_slot_list = stack_slot_list; | |
544 | p->parm_birth_insn = parm_birth_insn; | |
545 | p->frame_offset = frame_offset; | |
546 | p->tail_recursion_label = tail_recursion_label; | |
547 | p->tail_recursion_reentry = tail_recursion_reentry; | |
548 | p->arg_pointer_save_area = arg_pointer_save_area; | |
549 | p->rtl_expr_chain = rtl_expr_chain; | |
550 | p->last_parm_insn = last_parm_insn; | |
551 | p->context_display = context_display; | |
552 | p->trampoline_list = trampoline_list; | |
553 | p->function_call_count = function_call_count; | |
554 | p->temp_slots = temp_slots; | |
555 | p->temp_slot_level = temp_slot_level; | |
e5e809f4 JL |
556 | p->target_temp_slot_level = target_temp_slot_level; |
557 | p->var_temp_slot_level = var_temp_slot_level; | |
6f086dfc | 558 | p->fixup_var_refs_queue = 0; |
f979c996 | 559 | p->epilogue_delay_list = current_function_epilogue_delay_list; |
01c1558a | 560 | p->args_info = current_function_args_info; |
7d384cc0 | 561 | p->check_memory_usage = current_function_check_memory_usage; |
07417085 | 562 | p->instrument_entry_exit = current_function_instrument_entry_exit; |
6f086dfc | 563 | |
a0dabda5 | 564 | save_tree_status (p, context); |
6f086dfc RS |
565 | save_storage_status (p); |
566 | save_emit_status (p); | |
6f086dfc RS |
567 | save_expr_status (p); |
568 | save_stmt_status (p); | |
e9a25f70 | 569 | save_varasm_status (p, context); |
46766466 RS |
570 | if (save_machine_status) |
571 | (*save_machine_status) (p); | |
6f086dfc RS |
572 | } |
573 | ||
e4a4639e JM |
574 | void |
575 | push_function_context () | |
576 | { | |
a0dabda5 | 577 | push_function_context_to (current_function_decl); |
e4a4639e JM |
578 | } |
579 | ||
6f086dfc RS |
580 | /* Restore the last saved context, at the end of a nested function. |
581 | This function is called from language-specific code. */ | |
582 | ||
583 | void | |
a0dabda5 JM |
584 | pop_function_context_from (context) |
585 | tree context; | |
6f086dfc RS |
586 | { |
587 | struct function *p = outer_function_chain; | |
e5e809f4 | 588 | struct var_refs_queue *queue; |
6f086dfc RS |
589 | |
590 | outer_function_chain = p->next; | |
591 | ||
49468af2 RK |
592 | current_function_contains_functions |
593 | = p->contains_functions || p->inline_obstacks | |
594 | || context == current_function_decl; | |
6f086dfc RS |
595 | current_function_name = p->name; |
596 | current_function_decl = p->decl; | |
597 | current_function_pops_args = p->pops_args; | |
598 | current_function_returns_struct = p->returns_struct; | |
599 | current_function_returns_pcc_struct = p->returns_pcc_struct; | |
1651bdfe | 600 | current_function_returns_pointer = p->returns_pointer; |
6f086dfc RS |
601 | current_function_needs_context = p->needs_context; |
602 | current_function_calls_setjmp = p->calls_setjmp; | |
603 | current_function_calls_longjmp = p->calls_longjmp; | |
604 | current_function_calls_alloca = p->calls_alloca; | |
605 | current_function_has_nonlocal_label = p->has_nonlocal_label; | |
8634413a | 606 | current_function_has_nonlocal_goto = p->has_nonlocal_goto; |
173cd503 | 607 | current_function_is_thunk = p->is_thunk; |
6f086dfc RS |
608 | current_function_args_size = p->args_size; |
609 | current_function_pretend_args_size = p->pretend_args_size; | |
610 | current_function_arg_offset_rtx = p->arg_offset_rtx; | |
3b69d50e | 611 | current_function_varargs = p->varargs; |
ebb904cb | 612 | current_function_stdarg = p->stdarg; |
6f086dfc RS |
613 | current_function_uses_const_pool = p->uses_const_pool; |
614 | current_function_uses_pic_offset_table = p->uses_pic_offset_table; | |
615 | current_function_internal_arg_pointer = p->internal_arg_pointer; | |
aeb302bb | 616 | current_function_cannot_inline = p->cannot_inline; |
6f086dfc RS |
617 | max_parm_reg = p->max_parm_reg; |
618 | parm_reg_stack_loc = p->parm_reg_stack_loc; | |
619 | current_function_outgoing_args_size = p->outgoing_args_size; | |
620 | current_function_return_rtx = p->return_rtx; | |
ba716ac9 | 621 | nonlocal_goto_handler_slots = p->nonlocal_goto_handler_slots; |
6f086dfc RS |
622 | nonlocal_goto_stack_level = p->nonlocal_goto_stack_level; |
623 | nonlocal_labels = p->nonlocal_labels; | |
624 | cleanup_label = p->cleanup_label; | |
625 | return_label = p->return_label; | |
626 | save_expr_regs = p->save_expr_regs; | |
627 | stack_slot_list = p->stack_slot_list; | |
628 | parm_birth_insn = p->parm_birth_insn; | |
629 | frame_offset = p->frame_offset; | |
630 | tail_recursion_label = p->tail_recursion_label; | |
631 | tail_recursion_reentry = p->tail_recursion_reentry; | |
632 | arg_pointer_save_area = p->arg_pointer_save_area; | |
633 | rtl_expr_chain = p->rtl_expr_chain; | |
634 | last_parm_insn = p->last_parm_insn; | |
635 | context_display = p->context_display; | |
636 | trampoline_list = p->trampoline_list; | |
637 | function_call_count = p->function_call_count; | |
638 | temp_slots = p->temp_slots; | |
639 | temp_slot_level = p->temp_slot_level; | |
e5e809f4 JL |
640 | target_temp_slot_level = p->target_temp_slot_level; |
641 | var_temp_slot_level = p->var_temp_slot_level; | |
f979c996 | 642 | current_function_epilogue_delay_list = p->epilogue_delay_list; |
7cbc7b0c | 643 | reg_renumber = 0; |
01c1558a | 644 | current_function_args_info = p->args_info; |
7d384cc0 | 645 | current_function_check_memory_usage = p->check_memory_usage; |
07417085 | 646 | current_function_instrument_entry_exit = p->instrument_entry_exit; |
6f086dfc | 647 | |
d1485032 | 648 | restore_tree_status (p, context); |
6f086dfc RS |
649 | restore_storage_status (p); |
650 | restore_expr_status (p); | |
651 | restore_emit_status (p); | |
652 | restore_stmt_status (p); | |
a506307a | 653 | restore_varasm_status (p); |
6f086dfc | 654 | |
46766466 RS |
655 | if (restore_machine_status) |
656 | (*restore_machine_status) (p); | |
657 | ||
6f086dfc RS |
658 | /* Finish doing put_var_into_stack for any of our variables |
659 | which became addressable during the nested function. */ | |
e5e809f4 JL |
660 | for (queue = p->fixup_var_refs_queue; queue; queue = queue->next) |
661 | fixup_var_refs (queue->modified, queue->promoted_mode, queue->unsignedp); | |
6f086dfc RS |
662 | |
663 | free (p); | |
664 | ||
665 | /* Reset variables that have known state during rtx generation. */ | |
666 | rtx_equal_function_value_matters = 1; | |
667 | virtuals_instantiated = 0; | |
668 | } | |
e4a4639e JM |
669 | |
670 | void pop_function_context () | |
671 | { | |
a0dabda5 | 672 | pop_function_context_from (current_function_decl); |
e4a4639e | 673 | } |
6f086dfc RS |
674 | \f |
675 | /* Allocate fixed slots in the stack frame of the current function. */ | |
676 | ||
677 | /* Return size needed for stack frame based on slots so far allocated. | |
c795bca9 | 678 | This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY; |
6f086dfc RS |
679 | the caller may have to do that. */ |
680 | ||
8af5168b | 681 | HOST_WIDE_INT |
6f086dfc RS |
682 | get_frame_size () |
683 | { | |
684 | #ifdef FRAME_GROWS_DOWNWARD | |
685 | return -frame_offset; | |
686 | #else | |
687 | return frame_offset; | |
688 | #endif | |
689 | } | |
690 | ||
691 | /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it | |
692 | with machine mode MODE. | |
693 | ||
694 | ALIGN controls the amount of alignment for the address of the slot: | |
695 | 0 means according to MODE, | |
696 | -1 means use BIGGEST_ALIGNMENT and round size to multiple of that, | |
697 | positive specifies alignment boundary in bits. | |
698 | ||
699 | We do not round to stack_boundary here. */ | |
700 | ||
701 | rtx | |
702 | assign_stack_local (mode, size, align) | |
703 | enum machine_mode mode; | |
e5e809f4 | 704 | HOST_WIDE_INT size; |
6f086dfc RS |
705 | int align; |
706 | { | |
707 | register rtx x, addr; | |
708 | int bigend_correction = 0; | |
709 | int alignment; | |
710 | ||
711 | if (align == 0) | |
712 | { | |
713 | alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT; | |
714 | if (mode == BLKmode) | |
715 | alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT; | |
716 | } | |
717 | else if (align == -1) | |
718 | { | |
719 | alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT; | |
720 | size = CEIL_ROUND (size, alignment); | |
721 | } | |
722 | else | |
723 | alignment = align / BITS_PER_UNIT; | |
724 | ||
6f086dfc RS |
725 | /* Round frame offset to that alignment. |
726 | We must be careful here, since FRAME_OFFSET might be negative and | |
727 | division with a negative dividend isn't as well defined as we might | |
728 | like. So we instead assume that ALIGNMENT is a power of two and | |
729 | use logical operations which are unambiguous. */ | |
730 | #ifdef FRAME_GROWS_DOWNWARD | |
731 | frame_offset = FLOOR_ROUND (frame_offset, alignment); | |
732 | #else | |
733 | frame_offset = CEIL_ROUND (frame_offset, alignment); | |
734 | #endif | |
735 | ||
736 | /* On a big-endian machine, if we are allocating more space than we will use, | |
737 | use the least significant bytes of those that are allocated. */ | |
f76b9db2 | 738 | if (BYTES_BIG_ENDIAN && mode != BLKmode) |
6f086dfc | 739 | bigend_correction = size - GET_MODE_SIZE (mode); |
6f086dfc RS |
740 | |
741 | #ifdef FRAME_GROWS_DOWNWARD | |
742 | frame_offset -= size; | |
743 | #endif | |
744 | ||
745 | /* If we have already instantiated virtual registers, return the actual | |
746 | address relative to the frame pointer. */ | |
747 | if (virtuals_instantiated) | |
748 | addr = plus_constant (frame_pointer_rtx, | |
749 | (frame_offset + bigend_correction | |
750 | + STARTING_FRAME_OFFSET)); | |
751 | else | |
752 | addr = plus_constant (virtual_stack_vars_rtx, | |
753 | frame_offset + bigend_correction); | |
754 | ||
755 | #ifndef FRAME_GROWS_DOWNWARD | |
756 | frame_offset += size; | |
757 | #endif | |
758 | ||
38a448ca | 759 | x = gen_rtx_MEM (mode, addr); |
6f086dfc | 760 | |
38a448ca | 761 | stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, x, stack_slot_list); |
6f086dfc RS |
762 | |
763 | return x; | |
764 | } | |
765 | ||
766 | /* Assign a stack slot in a containing function. | |
767 | First three arguments are same as in preceding function. | |
768 | The last argument specifies the function to allocate in. */ | |
769 | ||
1ac4f799 | 770 | static rtx |
6f086dfc RS |
771 | assign_outer_stack_local (mode, size, align, function) |
772 | enum machine_mode mode; | |
e5e809f4 | 773 | HOST_WIDE_INT size; |
6f086dfc RS |
774 | int align; |
775 | struct function *function; | |
776 | { | |
777 | register rtx x, addr; | |
778 | int bigend_correction = 0; | |
779 | int alignment; | |
780 | ||
781 | /* Allocate in the memory associated with the function in whose frame | |
782 | we are assigning. */ | |
783 | push_obstacks (function->function_obstack, | |
784 | function->function_maybepermanent_obstack); | |
785 | ||
786 | if (align == 0) | |
787 | { | |
788 | alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT; | |
789 | if (mode == BLKmode) | |
790 | alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT; | |
791 | } | |
792 | else if (align == -1) | |
793 | { | |
794 | alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT; | |
795 | size = CEIL_ROUND (size, alignment); | |
796 | } | |
797 | else | |
798 | alignment = align / BITS_PER_UNIT; | |
799 | ||
6f086dfc RS |
800 | /* Round frame offset to that alignment. */ |
801 | #ifdef FRAME_GROWS_DOWNWARD | |
2af69b62 | 802 | function->frame_offset = FLOOR_ROUND (function->frame_offset, alignment); |
6f086dfc | 803 | #else |
2af69b62 | 804 | function->frame_offset = CEIL_ROUND (function->frame_offset, alignment); |
6f086dfc RS |
805 | #endif |
806 | ||
807 | /* On a big-endian machine, if we are allocating more space than we will use, | |
808 | use the least significant bytes of those that are allocated. */ | |
f76b9db2 | 809 | if (BYTES_BIG_ENDIAN && mode != BLKmode) |
6f086dfc | 810 | bigend_correction = size - GET_MODE_SIZE (mode); |
6f086dfc RS |
811 | |
812 | #ifdef FRAME_GROWS_DOWNWARD | |
813 | function->frame_offset -= size; | |
814 | #endif | |
815 | addr = plus_constant (virtual_stack_vars_rtx, | |
816 | function->frame_offset + bigend_correction); | |
817 | #ifndef FRAME_GROWS_DOWNWARD | |
818 | function->frame_offset += size; | |
819 | #endif | |
820 | ||
38a448ca | 821 | x = gen_rtx_MEM (mode, addr); |
6f086dfc RS |
822 | |
823 | function->stack_slot_list | |
38a448ca | 824 | = gen_rtx_EXPR_LIST (VOIDmode, x, function->stack_slot_list); |
6f086dfc RS |
825 | |
826 | pop_obstacks (); | |
827 | ||
828 | return x; | |
829 | } | |
830 | \f | |
831 | /* Allocate a temporary stack slot and record it for possible later | |
832 | reuse. | |
833 | ||
834 | MODE is the machine mode to be given to the returned rtx. | |
835 | ||
836 | SIZE is the size in units of the space required. We do no rounding here | |
837 | since assign_stack_local will do any required rounding. | |
838 | ||
d93d4205 MS |
839 | KEEP is 1 if this slot is to be retained after a call to |
840 | free_temp_slots. Automatic variables for a block are allocated | |
e5e809f4 JL |
841 | with this flag. KEEP is 2 if we allocate a longer term temporary, |
842 | whose lifetime is controlled by CLEANUP_POINT_EXPRs. KEEP is 3 | |
843 | if we are to allocate something at an inner level to be treated as | |
844 | a variable in the block (e.g., a SAVE_EXPR). */ | |
6f086dfc RS |
845 | |
846 | rtx | |
847 | assign_stack_temp (mode, size, keep) | |
848 | enum machine_mode mode; | |
e5e809f4 | 849 | HOST_WIDE_INT size; |
6f086dfc RS |
850 | int keep; |
851 | { | |
852 | struct temp_slot *p, *best_p = 0; | |
853 | ||
303ec2aa RK |
854 | /* If SIZE is -1 it means that somebody tried to allocate a temporary |
855 | of a variable size. */ | |
856 | if (size == -1) | |
857 | abort (); | |
858 | ||
6f086dfc RS |
859 | /* First try to find an available, already-allocated temporary that is the |
860 | exact size we require. */ | |
861 | for (p = temp_slots; p; p = p->next) | |
862 | if (p->size == size && GET_MODE (p->slot) == mode && ! p->in_use) | |
863 | break; | |
864 | ||
865 | /* If we didn't find, one, try one that is larger than what we want. We | |
866 | find the smallest such. */ | |
867 | if (p == 0) | |
868 | for (p = temp_slots; p; p = p->next) | |
869 | if (p->size > size && GET_MODE (p->slot) == mode && ! p->in_use | |
870 | && (best_p == 0 || best_p->size > p->size)) | |
871 | best_p = p; | |
872 | ||
873 | /* Make our best, if any, the one to use. */ | |
874 | if (best_p) | |
a45035b6 JW |
875 | { |
876 | /* If there are enough aligned bytes left over, make them into a new | |
877 | temp_slot so that the extra bytes don't get wasted. Do this only | |
878 | for BLKmode slots, so that we can be sure of the alignment. */ | |
879 | if (GET_MODE (best_p->slot) == BLKmode) | |
880 | { | |
881 | int alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT; | |
e5e809f4 | 882 | HOST_WIDE_INT rounded_size = CEIL_ROUND (size, alignment); |
a45035b6 JW |
883 | |
884 | if (best_p->size - rounded_size >= alignment) | |
885 | { | |
886 | p = (struct temp_slot *) oballoc (sizeof (struct temp_slot)); | |
a25d4ba2 | 887 | p->in_use = p->addr_taken = 0; |
a45035b6 | 888 | p->size = best_p->size - rounded_size; |
307d8cd6 RK |
889 | p->base_offset = best_p->base_offset + rounded_size; |
890 | p->full_size = best_p->full_size - rounded_size; | |
38a448ca RH |
891 | p->slot = gen_rtx_MEM (BLKmode, |
892 | plus_constant (XEXP (best_p->slot, 0), | |
893 | rounded_size)); | |
e5e76139 | 894 | p->address = 0; |
84e24c03 | 895 | p->rtl_expr = 0; |
a45035b6 JW |
896 | p->next = temp_slots; |
897 | temp_slots = p; | |
898 | ||
38a448ca RH |
899 | stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, p->slot, |
900 | stack_slot_list); | |
a45035b6 JW |
901 | |
902 | best_p->size = rounded_size; | |
291dde90 | 903 | best_p->full_size = rounded_size; |
a45035b6 JW |
904 | } |
905 | } | |
906 | ||
907 | p = best_p; | |
908 | } | |
909 | ||
6f086dfc RS |
910 | /* If we still didn't find one, make a new temporary. */ |
911 | if (p == 0) | |
912 | { | |
e5e809f4 JL |
913 | HOST_WIDE_INT frame_offset_old = frame_offset; |
914 | ||
6f086dfc | 915 | p = (struct temp_slot *) oballoc (sizeof (struct temp_slot)); |
e5e809f4 | 916 | |
6f086dfc RS |
917 | /* If the temp slot mode doesn't indicate the alignment, |
918 | use the largest possible, so no one will be disappointed. */ | |
e5e76139 | 919 | p->slot = assign_stack_local (mode, size, mode == BLKmode ? -1 : 0); |
e5e809f4 | 920 | |
b2a80c0d DE |
921 | /* The following slot size computation is necessary because we don't |
922 | know the actual size of the temporary slot until assign_stack_local | |
923 | has performed all the frame alignment and size rounding for the | |
fc91b0d0 RK |
924 | requested temporary. Note that extra space added for alignment |
925 | can be either above or below this stack slot depending on which | |
926 | way the frame grows. We include the extra space if and only if it | |
927 | is above this slot. */ | |
b2a80c0d DE |
928 | #ifdef FRAME_GROWS_DOWNWARD |
929 | p->size = frame_offset_old - frame_offset; | |
930 | #else | |
fc91b0d0 RK |
931 | p->size = size; |
932 | #endif | |
e5e809f4 | 933 | |
fc91b0d0 RK |
934 | /* Now define the fields used by combine_temp_slots. */ |
935 | #ifdef FRAME_GROWS_DOWNWARD | |
936 | p->base_offset = frame_offset; | |
937 | p->full_size = frame_offset_old - frame_offset; | |
938 | #else | |
939 | p->base_offset = frame_offset_old; | |
940 | p->full_size = frame_offset - frame_offset_old; | |
b2a80c0d | 941 | #endif |
e5e76139 | 942 | p->address = 0; |
6f086dfc RS |
943 | p->next = temp_slots; |
944 | temp_slots = p; | |
945 | } | |
946 | ||
947 | p->in_use = 1; | |
a25d4ba2 | 948 | p->addr_taken = 0; |
e7a84011 | 949 | p->rtl_expr = sequence_rtl_expr; |
a25d4ba2 | 950 | |
d93d4205 MS |
951 | if (keep == 2) |
952 | { | |
953 | p->level = target_temp_slot_level; | |
954 | p->keep = 0; | |
955 | } | |
e5e809f4 JL |
956 | else if (keep == 3) |
957 | { | |
958 | p->level = var_temp_slot_level; | |
959 | p->keep = 0; | |
960 | } | |
d93d4205 MS |
961 | else |
962 | { | |
963 | p->level = temp_slot_level; | |
964 | p->keep = keep; | |
965 | } | |
1995f267 RK |
966 | |
967 | /* We may be reusing an old slot, so clear any MEM flags that may have been | |
968 | set from before. */ | |
969 | RTX_UNCHANGING_P (p->slot) = 0; | |
970 | MEM_IN_STRUCT_P (p->slot) = 0; | |
c6df88cb MM |
971 | MEM_SCALAR_P (p->slot) = 0; |
972 | MEM_ALIAS_SET (p->slot) = 0; | |
6f086dfc RS |
973 | return p->slot; |
974 | } | |
638141a6 | 975 | \f |
230f21b4 PB |
976 | /* Assign a temporary of given TYPE. |
977 | KEEP is as for assign_stack_temp. | |
978 | MEMORY_REQUIRED is 1 if the result must be addressable stack memory; | |
b55d9ff8 RK |
979 | it is 0 if a register is OK. |
980 | DONT_PROMOTE is 1 if we should not promote values in register | |
981 | to wider modes. */ | |
230f21b4 PB |
982 | |
983 | rtx | |
b55d9ff8 | 984 | assign_temp (type, keep, memory_required, dont_promote) |
230f21b4 PB |
985 | tree type; |
986 | int keep; | |
987 | int memory_required; | |
b55d9ff8 | 988 | int dont_promote; |
230f21b4 PB |
989 | { |
990 | enum machine_mode mode = TYPE_MODE (type); | |
638141a6 RK |
991 | int unsignedp = TREE_UNSIGNED (type); |
992 | ||
230f21b4 PB |
993 | if (mode == BLKmode || memory_required) |
994 | { | |
e5e809f4 | 995 | HOST_WIDE_INT size = int_size_in_bytes (type); |
230f21b4 PB |
996 | rtx tmp; |
997 | ||
998 | /* Unfortunately, we don't yet know how to allocate variable-sized | |
999 | temporaries. However, sometimes we have a fixed upper limit on | |
1000 | the size (which is stored in TYPE_ARRAY_MAX_SIZE) and can use that | |
0f41302f | 1001 | instead. This is the case for Chill variable-sized strings. */ |
230f21b4 PB |
1002 | if (size == -1 && TREE_CODE (type) == ARRAY_TYPE |
1003 | && TYPE_ARRAY_MAX_SIZE (type) != NULL_TREE | |
1004 | && TREE_CODE (TYPE_ARRAY_MAX_SIZE (type)) == INTEGER_CST) | |
1005 | size = TREE_INT_CST_LOW (TYPE_ARRAY_MAX_SIZE (type)); | |
1006 | ||
1007 | tmp = assign_stack_temp (mode, size, keep); | |
c6df88cb | 1008 | MEM_SET_IN_STRUCT_P (tmp, AGGREGATE_TYPE_P (type)); |
230f21b4 PB |
1009 | return tmp; |
1010 | } | |
638141a6 | 1011 | |
230f21b4 | 1012 | #ifndef PROMOTE_FOR_CALL_ONLY |
b55d9ff8 RK |
1013 | if (! dont_promote) |
1014 | mode = promote_mode (type, mode, &unsignedp, 0); | |
230f21b4 | 1015 | #endif |
638141a6 | 1016 | |
230f21b4 PB |
1017 | return gen_reg_rtx (mode); |
1018 | } | |
638141a6 | 1019 | \f |
a45035b6 JW |
1020 | /* Combine temporary stack slots which are adjacent on the stack. |
1021 | ||
1022 | This allows for better use of already allocated stack space. This is only | |
1023 | done for BLKmode slots because we can be sure that we won't have alignment | |
1024 | problems in this case. */ | |
1025 | ||
1026 | void | |
1027 | combine_temp_slots () | |
1028 | { | |
1029 | struct temp_slot *p, *q; | |
1030 | struct temp_slot *prev_p, *prev_q; | |
e5e809f4 JL |
1031 | int num_slots; |
1032 | ||
1033 | /* If there are a lot of temp slots, don't do anything unless | |
1034 | high levels of optimizaton. */ | |
1035 | if (! flag_expensive_optimizations) | |
1036 | for (p = temp_slots, num_slots = 0; p; p = p->next, num_slots++) | |
1037 | if (num_slots > 100 || (num_slots > 10 && optimize == 0)) | |
1038 | return; | |
a45035b6 | 1039 | |
e9b7093a RS |
1040 | for (p = temp_slots, prev_p = 0; p; p = prev_p ? prev_p->next : temp_slots) |
1041 | { | |
1042 | int delete_p = 0; | |
e5e809f4 | 1043 | |
e9b7093a RS |
1044 | if (! p->in_use && GET_MODE (p->slot) == BLKmode) |
1045 | for (q = p->next, prev_q = p; q; q = prev_q->next) | |
a45035b6 | 1046 | { |
e9b7093a RS |
1047 | int delete_q = 0; |
1048 | if (! q->in_use && GET_MODE (q->slot) == BLKmode) | |
a45035b6 | 1049 | { |
fc91b0d0 | 1050 | if (p->base_offset + p->full_size == q->base_offset) |
e9b7093a RS |
1051 | { |
1052 | /* Q comes after P; combine Q into P. */ | |
1053 | p->size += q->size; | |
307d8cd6 | 1054 | p->full_size += q->full_size; |
e9b7093a RS |
1055 | delete_q = 1; |
1056 | } | |
fc91b0d0 | 1057 | else if (q->base_offset + q->full_size == p->base_offset) |
e9b7093a RS |
1058 | { |
1059 | /* P comes after Q; combine P into Q. */ | |
1060 | q->size += p->size; | |
307d8cd6 | 1061 | q->full_size += p->full_size; |
e9b7093a RS |
1062 | delete_p = 1; |
1063 | break; | |
1064 | } | |
a45035b6 | 1065 | } |
e9b7093a RS |
1066 | /* Either delete Q or advance past it. */ |
1067 | if (delete_q) | |
1068 | prev_q->next = q->next; | |
1069 | else | |
1070 | prev_q = q; | |
a45035b6 | 1071 | } |
e9b7093a RS |
1072 | /* Either delete P or advance past it. */ |
1073 | if (delete_p) | |
1074 | { | |
1075 | if (prev_p) | |
1076 | prev_p->next = p->next; | |
1077 | else | |
1078 | temp_slots = p->next; | |
1079 | } | |
1080 | else | |
1081 | prev_p = p; | |
1082 | } | |
a45035b6 | 1083 | } |
6f086dfc | 1084 | \f |
e5e76139 RK |
1085 | /* Find the temp slot corresponding to the object at address X. */ |
1086 | ||
1087 | static struct temp_slot * | |
1088 | find_temp_slot_from_address (x) | |
1089 | rtx x; | |
1090 | { | |
1091 | struct temp_slot *p; | |
1092 | rtx next; | |
1093 | ||
1094 | for (p = temp_slots; p; p = p->next) | |
1095 | { | |
1096 | if (! p->in_use) | |
1097 | continue; | |
e5e809f4 | 1098 | |
e5e76139 | 1099 | else if (XEXP (p->slot, 0) == x |
abb52246 RK |
1100 | || p->address == x |
1101 | || (GET_CODE (x) == PLUS | |
1102 | && XEXP (x, 0) == virtual_stack_vars_rtx | |
1103 | && GET_CODE (XEXP (x, 1)) == CONST_INT | |
1104 | && INTVAL (XEXP (x, 1)) >= p->base_offset | |
1105 | && INTVAL (XEXP (x, 1)) < p->base_offset + p->full_size)) | |
e5e76139 RK |
1106 | return p; |
1107 | ||
1108 | else if (p->address != 0 && GET_CODE (p->address) == EXPR_LIST) | |
1109 | for (next = p->address; next; next = XEXP (next, 1)) | |
1110 | if (XEXP (next, 0) == x) | |
1111 | return p; | |
1112 | } | |
1113 | ||
1114 | return 0; | |
1115 | } | |
1116 | ||
9faa82d8 | 1117 | /* Indicate that NEW is an alternate way of referring to the temp slot |
e5e809f4 | 1118 | that previously was known by OLD. */ |
e5e76139 RK |
1119 | |
1120 | void | |
1121 | update_temp_slot_address (old, new) | |
1122 | rtx old, new; | |
1123 | { | |
1124 | struct temp_slot *p = find_temp_slot_from_address (old); | |
1125 | ||
1126 | /* If none, return. Else add NEW as an alias. */ | |
1127 | if (p == 0) | |
1128 | return; | |
1129 | else if (p->address == 0) | |
1130 | p->address = new; | |
1131 | else | |
1132 | { | |
1133 | if (GET_CODE (p->address) != EXPR_LIST) | |
38a448ca | 1134 | p->address = gen_rtx_EXPR_LIST (VOIDmode, p->address, NULL_RTX); |
e5e76139 | 1135 | |
38a448ca | 1136 | p->address = gen_rtx_EXPR_LIST (VOIDmode, new, p->address); |
e5e76139 RK |
1137 | } |
1138 | } | |
1139 | ||
a25d4ba2 | 1140 | /* If X could be a reference to a temporary slot, mark the fact that its |
9faa82d8 | 1141 | address was taken. */ |
a25d4ba2 RK |
1142 | |
1143 | void | |
1144 | mark_temp_addr_taken (x) | |
1145 | rtx x; | |
1146 | { | |
1147 | struct temp_slot *p; | |
1148 | ||
1149 | if (x == 0) | |
1150 | return; | |
1151 | ||
1152 | /* If X is not in memory or is at a constant address, it cannot be in | |
1153 | a temporary slot. */ | |
1154 | if (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0))) | |
1155 | return; | |
1156 | ||
1157 | p = find_temp_slot_from_address (XEXP (x, 0)); | |
1158 | if (p != 0) | |
1159 | p->addr_taken = 1; | |
1160 | } | |
1161 | ||
9cca6a99 MS |
1162 | /* If X could be a reference to a temporary slot, mark that slot as |
1163 | belonging to the to one level higher than the current level. If X | |
1164 | matched one of our slots, just mark that one. Otherwise, we can't | |
1165 | easily predict which it is, so upgrade all of them. Kept slots | |
1166 | need not be touched. | |
6f086dfc RS |
1167 | |
1168 | This is called when an ({...}) construct occurs and a statement | |
1169 | returns a value in memory. */ | |
1170 | ||
1171 | void | |
1172 | preserve_temp_slots (x) | |
1173 | rtx x; | |
1174 | { | |
a25d4ba2 | 1175 | struct temp_slot *p = 0; |
6f086dfc | 1176 | |
73620b82 RK |
1177 | /* If there is no result, we still might have some objects whose address |
1178 | were taken, so we need to make sure they stay around. */ | |
e3a77161 | 1179 | if (x == 0) |
73620b82 RK |
1180 | { |
1181 | for (p = temp_slots; p; p = p->next) | |
1182 | if (p->in_use && p->level == temp_slot_level && p->addr_taken) | |
1183 | p->level--; | |
1184 | ||
1185 | return; | |
1186 | } | |
e3a77161 RK |
1187 | |
1188 | /* If X is a register that is being used as a pointer, see if we have | |
1189 | a temporary slot we know it points to. To be consistent with | |
1190 | the code below, we really should preserve all non-kept slots | |
1191 | if we can't find a match, but that seems to be much too costly. */ | |
a25d4ba2 RK |
1192 | if (GET_CODE (x) == REG && REGNO_POINTER_FLAG (REGNO (x))) |
1193 | p = find_temp_slot_from_address (x); | |
1194 | ||
6f086dfc | 1195 | /* If X is not in memory or is at a constant address, it cannot be in |
e19571db RK |
1196 | a temporary slot, but it can contain something whose address was |
1197 | taken. */ | |
a25d4ba2 | 1198 | if (p == 0 && (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))) |
e19571db RK |
1199 | { |
1200 | for (p = temp_slots; p; p = p->next) | |
1201 | if (p->in_use && p->level == temp_slot_level && p->addr_taken) | |
1202 | p->level--; | |
1203 | ||
1204 | return; | |
1205 | } | |
6f086dfc RS |
1206 | |
1207 | /* First see if we can find a match. */ | |
73620b82 | 1208 | if (p == 0) |
a25d4ba2 RK |
1209 | p = find_temp_slot_from_address (XEXP (x, 0)); |
1210 | ||
e5e76139 RK |
1211 | if (p != 0) |
1212 | { | |
a25d4ba2 RK |
1213 | /* Move everything at our level whose address was taken to our new |
1214 | level in case we used its address. */ | |
1215 | struct temp_slot *q; | |
1216 | ||
9cca6a99 MS |
1217 | if (p->level == temp_slot_level) |
1218 | { | |
1219 | for (q = temp_slots; q; q = q->next) | |
1220 | if (q != p && q->addr_taken && q->level == p->level) | |
1221 | q->level--; | |
a25d4ba2 | 1222 | |
9cca6a99 MS |
1223 | p->level--; |
1224 | p->addr_taken = 0; | |
1225 | } | |
e5e76139 RK |
1226 | return; |
1227 | } | |
6f086dfc RS |
1228 | |
1229 | /* Otherwise, preserve all non-kept slots at this level. */ | |
1230 | for (p = temp_slots; p; p = p->next) | |
1231 | if (p->in_use && p->level == temp_slot_level && ! p->keep) | |
1232 | p->level--; | |
1233 | } | |
1234 | ||
422c8f63 RK |
1235 | /* X is the result of an RTL_EXPR. If it is a temporary slot associated |
1236 | with that RTL_EXPR, promote it into a temporary slot at the present | |
1237 | level so it will not be freed when we free slots made in the | |
1238 | RTL_EXPR. */ | |
1239 | ||
1240 | void | |
1241 | preserve_rtl_expr_result (x) | |
1242 | rtx x; | |
1243 | { | |
1244 | struct temp_slot *p; | |
1245 | ||
1246 | /* If X is not in memory or is at a constant address, it cannot be in | |
1247 | a temporary slot. */ | |
1248 | if (x == 0 || GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0))) | |
1249 | return; | |
1250 | ||
199b61d8 RK |
1251 | /* If we can find a match, move it to our level unless it is already at |
1252 | an upper level. */ | |
1253 | p = find_temp_slot_from_address (XEXP (x, 0)); | |
1254 | if (p != 0) | |
1255 | { | |
1256 | p->level = MIN (p->level, temp_slot_level); | |
1257 | p->rtl_expr = 0; | |
1258 | } | |
422c8f63 RK |
1259 | |
1260 | return; | |
1261 | } | |
1262 | ||
6f086dfc | 1263 | /* Free all temporaries used so far. This is normally called at the end |
e7a84011 RK |
1264 | of generating code for a statement. Don't free any temporaries |
1265 | currently in use for an RTL_EXPR that hasn't yet been emitted. | |
1266 | We could eventually do better than this since it can be reused while | |
1267 | generating the same RTL_EXPR, but this is complex and probably not | |
1268 | worthwhile. */ | |
6f086dfc RS |
1269 | |
1270 | void | |
1271 | free_temp_slots () | |
1272 | { | |
1273 | struct temp_slot *p; | |
1274 | ||
1275 | for (p = temp_slots; p; p = p->next) | |
e7a84011 RK |
1276 | if (p->in_use && p->level == temp_slot_level && ! p->keep |
1277 | && p->rtl_expr == 0) | |
1278 | p->in_use = 0; | |
1279 | ||
1280 | combine_temp_slots (); | |
1281 | } | |
1282 | ||
1283 | /* Free all temporary slots used in T, an RTL_EXPR node. */ | |
1284 | ||
1285 | void | |
1286 | free_temps_for_rtl_expr (t) | |
1287 | tree t; | |
1288 | { | |
1289 | struct temp_slot *p; | |
1290 | ||
1291 | for (p = temp_slots; p; p = p->next) | |
1292 | if (p->rtl_expr == t) | |
6f086dfc | 1293 | p->in_use = 0; |
a45035b6 JW |
1294 | |
1295 | combine_temp_slots (); | |
6f086dfc RS |
1296 | } |
1297 | ||
956d6950 | 1298 | /* Mark all temporaries ever allocated in this function as not suitable |
a94e4054 RK |
1299 | for reuse until the current level is exited. */ |
1300 | ||
1301 | void | |
1302 | mark_all_temps_used () | |
1303 | { | |
1304 | struct temp_slot *p; | |
1305 | ||
1306 | for (p = temp_slots; p; p = p->next) | |
1307 | { | |
85b119d1 | 1308 | p->in_use = p->keep = 1; |
27ce006b | 1309 | p->level = MIN (p->level, temp_slot_level); |
a94e4054 RK |
1310 | } |
1311 | } | |
1312 | ||
6f086dfc RS |
1313 | /* Push deeper into the nesting level for stack temporaries. */ |
1314 | ||
1315 | void | |
1316 | push_temp_slots () | |
1317 | { | |
6f086dfc RS |
1318 | temp_slot_level++; |
1319 | } | |
1320 | ||
e5e809f4 JL |
1321 | /* Likewise, but save the new level as the place to allocate variables |
1322 | for blocks. */ | |
1323 | ||
1324 | void | |
1325 | push_temp_slots_for_block () | |
1326 | { | |
1327 | push_temp_slots (); | |
1328 | ||
1329 | var_temp_slot_level = temp_slot_level; | |
1330 | } | |
1331 | ||
f5963e61 JL |
1332 | /* Likewise, but save the new level as the place to allocate temporaries |
1333 | for TARGET_EXPRs. */ | |
1334 | ||
1335 | void | |
1336 | push_temp_slots_for_target () | |
1337 | { | |
1338 | push_temp_slots (); | |
1339 | ||
1340 | target_temp_slot_level = temp_slot_level; | |
1341 | } | |
1342 | ||
1343 | /* Set and get the value of target_temp_slot_level. The only | |
1344 | permitted use of these functions is to save and restore this value. */ | |
1345 | ||
1346 | int | |
1347 | get_target_temp_slot_level () | |
1348 | { | |
1349 | return target_temp_slot_level; | |
1350 | } | |
1351 | ||
1352 | void | |
1353 | set_target_temp_slot_level (level) | |
1354 | int level; | |
1355 | { | |
1356 | target_temp_slot_level = level; | |
1357 | } | |
1358 | ||
6f086dfc RS |
1359 | /* Pop a temporary nesting level. All slots in use in the current level |
1360 | are freed. */ | |
1361 | ||
1362 | void | |
1363 | pop_temp_slots () | |
1364 | { | |
1365 | struct temp_slot *p; | |
1366 | ||
6f086dfc | 1367 | for (p = temp_slots; p; p = p->next) |
e7a84011 | 1368 | if (p->in_use && p->level == temp_slot_level && p->rtl_expr == 0) |
6f086dfc RS |
1369 | p->in_use = 0; |
1370 | ||
a45035b6 JW |
1371 | combine_temp_slots (); |
1372 | ||
6f086dfc RS |
1373 | temp_slot_level--; |
1374 | } | |
bc0ebdf9 RK |
1375 | |
1376 | /* Initialize temporary slots. */ | |
1377 | ||
1378 | void | |
1379 | init_temp_slots () | |
1380 | { | |
1381 | /* We have not allocated any temporaries yet. */ | |
1382 | temp_slots = 0; | |
1383 | temp_slot_level = 0; | |
e5e809f4 | 1384 | var_temp_slot_level = 0; |
bc0ebdf9 RK |
1385 | target_temp_slot_level = 0; |
1386 | } | |
6f086dfc RS |
1387 | \f |
1388 | /* Retroactively move an auto variable from a register to a stack slot. | |
1389 | This is done when an address-reference to the variable is seen. */ | |
1390 | ||
1391 | void | |
1392 | put_var_into_stack (decl) | |
1393 | tree decl; | |
1394 | { | |
1395 | register rtx reg; | |
00d8a4c1 | 1396 | enum machine_mode promoted_mode, decl_mode; |
6f086dfc | 1397 | struct function *function = 0; |
c20bf1f3 | 1398 | tree context; |
e9a25f70 | 1399 | int can_use_addressof; |
c20bf1f3 | 1400 | |
c20bf1f3 | 1401 | context = decl_function_context (decl); |
6f086dfc | 1402 | |
9ec36da5 | 1403 | /* Get the current rtl used for this object and its original mode. */ |
6f086dfc | 1404 | reg = TREE_CODE (decl) == SAVE_EXPR ? SAVE_EXPR_RTL (decl) : DECL_RTL (decl); |
2baccce2 RS |
1405 | |
1406 | /* No need to do anything if decl has no rtx yet | |
1407 | since in that case caller is setting TREE_ADDRESSABLE | |
1408 | and a stack slot will be assigned when the rtl is made. */ | |
1409 | if (reg == 0) | |
1410 | return; | |
00d8a4c1 RK |
1411 | |
1412 | /* Get the declared mode for this object. */ | |
1413 | decl_mode = (TREE_CODE (decl) == SAVE_EXPR ? TYPE_MODE (TREE_TYPE (decl)) | |
1414 | : DECL_MODE (decl)); | |
2baccce2 RS |
1415 | /* Get the mode it's actually stored in. */ |
1416 | promoted_mode = GET_MODE (reg); | |
6f086dfc RS |
1417 | |
1418 | /* If this variable comes from an outer function, | |
1419 | find that function's saved context. */ | |
4ac74fb8 | 1420 | if (context != current_function_decl && context != inline_function_decl) |
6f086dfc RS |
1421 | for (function = outer_function_chain; function; function = function->next) |
1422 | if (function->decl == context) | |
1423 | break; | |
1424 | ||
6f086dfc RS |
1425 | /* If this is a variable-size object with a pseudo to address it, |
1426 | put that pseudo into the stack, if the var is nonlocal. */ | |
a82ad570 | 1427 | if (DECL_NONLOCAL (decl) |
6f086dfc RS |
1428 | && GET_CODE (reg) == MEM |
1429 | && GET_CODE (XEXP (reg, 0)) == REG | |
1430 | && REGNO (XEXP (reg, 0)) > LAST_VIRTUAL_REGISTER) | |
4cdb3e78 RS |
1431 | { |
1432 | reg = XEXP (reg, 0); | |
1433 | decl_mode = promoted_mode = GET_MODE (reg); | |
1434 | } | |
e15762df | 1435 | |
e9a25f70 JL |
1436 | can_use_addressof |
1437 | = (function == 0 | |
e5e809f4 | 1438 | && optimize > 0 |
e9a25f70 JL |
1439 | /* FIXME make it work for promoted modes too */ |
1440 | && decl_mode == promoted_mode | |
1441 | #ifdef NON_SAVING_SETJMP | |
1442 | && ! (NON_SAVING_SETJMP && current_function_calls_setjmp) | |
1443 | #endif | |
1444 | ); | |
1445 | ||
1446 | /* If we can't use ADDRESSOF, make sure we see through one we already | |
1447 | generated. */ | |
1448 | if (! can_use_addressof && GET_CODE (reg) == MEM | |
1449 | && GET_CODE (XEXP (reg, 0)) == ADDRESSOF) | |
1450 | reg = XEXP (XEXP (reg, 0), 0); | |
1451 | ||
293e3de4 RS |
1452 | /* Now we should have a value that resides in one or more pseudo regs. */ |
1453 | ||
1454 | if (GET_CODE (reg) == REG) | |
e9a25f70 JL |
1455 | { |
1456 | /* If this variable lives in the current function and we don't need | |
1457 | to put things in the stack for the sake of setjmp, try to keep it | |
1458 | in a register until we know we actually need the address. */ | |
1459 | if (can_use_addressof) | |
1460 | gen_mem_addressof (reg, decl); | |
1461 | else | |
1462 | put_reg_into_stack (function, reg, TREE_TYPE (decl), | |
1463 | promoted_mode, decl_mode, | |
e5e809f4 JL |
1464 | TREE_SIDE_EFFECTS (decl), 0, |
1465 | TREE_USED (decl) | |
1466 | || DECL_INITIAL (decl) != 0); | |
e9a25f70 | 1467 | } |
293e3de4 RS |
1468 | else if (GET_CODE (reg) == CONCAT) |
1469 | { | |
1470 | /* A CONCAT contains two pseudos; put them both in the stack. | |
1471 | We do it so they end up consecutive. */ | |
1472 | enum machine_mode part_mode = GET_MODE (XEXP (reg, 0)); | |
1473 | tree part_type = TREE_TYPE (TREE_TYPE (decl)); | |
4738c10d | 1474 | #ifdef FRAME_GROWS_DOWNWARD |
293e3de4 | 1475 | /* Since part 0 should have a lower address, do it second. */ |
0006e95b | 1476 | put_reg_into_stack (function, XEXP (reg, 1), part_type, part_mode, |
e5e809f4 JL |
1477 | part_mode, TREE_SIDE_EFFECTS (decl), 0, |
1478 | TREE_USED (decl) || DECL_INITIAL (decl) != 0); | |
0006e95b | 1479 | put_reg_into_stack (function, XEXP (reg, 0), part_type, part_mode, |
e5e809f4 JL |
1480 | part_mode, TREE_SIDE_EFFECTS (decl), 0, |
1481 | TREE_USED (decl) || DECL_INITIAL (decl) != 0); | |
293e3de4 | 1482 | #else |
0006e95b | 1483 | put_reg_into_stack (function, XEXP (reg, 0), part_type, part_mode, |
e5e809f4 JL |
1484 | part_mode, TREE_SIDE_EFFECTS (decl), 0, |
1485 | TREE_USED (decl) || DECL_INITIAL (decl) != 0); | |
0006e95b | 1486 | put_reg_into_stack (function, XEXP (reg, 1), part_type, part_mode, |
e5e809f4 JL |
1487 | part_mode, TREE_SIDE_EFFECTS (decl), 0, |
1488 | TREE_USED (decl) || DECL_INITIAL (decl) != 0); | |
293e3de4 RS |
1489 | #endif |
1490 | ||
1491 | /* Change the CONCAT into a combined MEM for both parts. */ | |
1492 | PUT_CODE (reg, MEM); | |
0006e95b | 1493 | MEM_VOLATILE_P (reg) = MEM_VOLATILE_P (XEXP (reg, 0)); |
41472af8 | 1494 | MEM_ALIAS_SET (reg) = get_alias_set (decl); |
0006e95b | 1495 | |
293e3de4 RS |
1496 | /* The two parts are in memory order already. |
1497 | Use the lower parts address as ours. */ | |
1498 | XEXP (reg, 0) = XEXP (XEXP (reg, 0), 0); | |
1499 | /* Prevent sharing of rtl that might lose. */ | |
1500 | if (GET_CODE (XEXP (reg, 0)) == PLUS) | |
1501 | XEXP (reg, 0) = copy_rtx (XEXP (reg, 0)); | |
1502 | } | |
86fa911a RK |
1503 | else |
1504 | return; | |
1505 | ||
7d384cc0 | 1506 | if (current_function_check_memory_usage) |
86fa911a RK |
1507 | emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3, |
1508 | XEXP (reg, 0), ptr_mode, | |
1509 | GEN_INT (GET_MODE_SIZE (GET_MODE (reg))), | |
1510 | TYPE_MODE (sizetype), | |
956d6950 JL |
1511 | GEN_INT (MEMORY_USE_RW), |
1512 | TYPE_MODE (integer_type_node)); | |
293e3de4 RS |
1513 | } |
1514 | ||
1515 | /* Subroutine of put_var_into_stack. This puts a single pseudo reg REG | |
1516 | into the stack frame of FUNCTION (0 means the current function). | |
1517 | DECL_MODE is the machine mode of the user-level data type. | |
0006e95b | 1518 | PROMOTED_MODE is the machine mode of the register. |
e5e809f4 JL |
1519 | VOLATILE_P is nonzero if this is for a "volatile" decl. |
1520 | USED_P is nonzero if this reg might have already been used in an insn. */ | |
293e3de4 RS |
1521 | |
1522 | static void | |
e9a25f70 | 1523 | put_reg_into_stack (function, reg, type, promoted_mode, decl_mode, volatile_p, |
e5e809f4 | 1524 | original_regno, used_p) |
293e3de4 RS |
1525 | struct function *function; |
1526 | rtx reg; | |
1527 | tree type; | |
1528 | enum machine_mode promoted_mode, decl_mode; | |
0006e95b | 1529 | int volatile_p; |
e9a25f70 | 1530 | int original_regno; |
e5e809f4 | 1531 | int used_p; |
293e3de4 RS |
1532 | { |
1533 | rtx new = 0; | |
e9a25f70 JL |
1534 | int regno = original_regno; |
1535 | ||
1536 | if (regno == 0) | |
1537 | regno = REGNO (reg); | |
6f086dfc RS |
1538 | |
1539 | if (function) | |
1540 | { | |
e9a25f70 JL |
1541 | if (regno < function->max_parm_reg) |
1542 | new = function->parm_reg_stack_loc[regno]; | |
6f086dfc | 1543 | if (new == 0) |
e15762df | 1544 | new = assign_outer_stack_local (decl_mode, GET_MODE_SIZE (decl_mode), |
6f086dfc RS |
1545 | 0, function); |
1546 | } | |
1547 | else | |
1548 | { | |
e9a25f70 JL |
1549 | if (regno < max_parm_reg) |
1550 | new = parm_reg_stack_loc[regno]; | |
6f086dfc | 1551 | if (new == 0) |
e15762df | 1552 | new = assign_stack_local (decl_mode, GET_MODE_SIZE (decl_mode), 0); |
6f086dfc RS |
1553 | } |
1554 | ||
0006e95b | 1555 | PUT_MODE (reg, decl_mode); |
6f086dfc RS |
1556 | XEXP (reg, 0) = XEXP (new, 0); |
1557 | /* `volatil' bit means one thing for MEMs, another entirely for REGs. */ | |
0006e95b | 1558 | MEM_VOLATILE_P (reg) = volatile_p; |
6f086dfc RS |
1559 | PUT_CODE (reg, MEM); |
1560 | ||
1561 | /* If this is a memory ref that contains aggregate components, | |
bdd3e6ab JW |
1562 | mark it as such for cse and loop optimize. If we are reusing a |
1563 | previously generated stack slot, then we need to copy the bit in | |
1564 | case it was set for other reasons. For instance, it is set for | |
1565 | __builtin_va_alist. */ | |
c6df88cb MM |
1566 | MEM_SET_IN_STRUCT_P (reg, |
1567 | AGGREGATE_TYPE_P (type) || MEM_IN_STRUCT_P (new)); | |
41472af8 | 1568 | MEM_ALIAS_SET (reg) = get_alias_set (type); |
6f086dfc RS |
1569 | |
1570 | /* Now make sure that all refs to the variable, previously made | |
1571 | when it was a register, are fixed up to be valid again. */ | |
e5e809f4 JL |
1572 | |
1573 | if (used_p && function != 0) | |
6f086dfc RS |
1574 | { |
1575 | struct var_refs_queue *temp; | |
1576 | ||
1577 | /* Variable is inherited; fix it up when we get back to its function. */ | |
1578 | push_obstacks (function->function_obstack, | |
1579 | function->function_maybepermanent_obstack); | |
4da73fa0 RK |
1580 | |
1581 | /* See comment in restore_tree_status in tree.c for why this needs to be | |
1582 | on saveable obstack. */ | |
6f086dfc | 1583 | temp |
4da73fa0 | 1584 | = (struct var_refs_queue *) savealloc (sizeof (struct var_refs_queue)); |
6f086dfc | 1585 | temp->modified = reg; |
00d8a4c1 | 1586 | temp->promoted_mode = promoted_mode; |
293e3de4 | 1587 | temp->unsignedp = TREE_UNSIGNED (type); |
6f086dfc RS |
1588 | temp->next = function->fixup_var_refs_queue; |
1589 | function->fixup_var_refs_queue = temp; | |
1590 | pop_obstacks (); | |
1591 | } | |
e5e809f4 | 1592 | else if (used_p) |
6f086dfc | 1593 | /* Variable is local; fix it up now. */ |
293e3de4 | 1594 | fixup_var_refs (reg, promoted_mode, TREE_UNSIGNED (type)); |
6f086dfc RS |
1595 | } |
1596 | \f | |
1597 | static void | |
00d8a4c1 | 1598 | fixup_var_refs (var, promoted_mode, unsignedp) |
6f086dfc | 1599 | rtx var; |
00d8a4c1 RK |
1600 | enum machine_mode promoted_mode; |
1601 | int unsignedp; | |
6f086dfc RS |
1602 | { |
1603 | tree pending; | |
1604 | rtx first_insn = get_insns (); | |
1605 | struct sequence_stack *stack = sequence_stack; | |
1606 | tree rtl_exps = rtl_expr_chain; | |
1607 | ||
1608 | /* Must scan all insns for stack-refs that exceed the limit. */ | |
00d8a4c1 | 1609 | fixup_var_refs_insns (var, promoted_mode, unsignedp, first_insn, stack == 0); |
6f086dfc RS |
1610 | |
1611 | /* Scan all pending sequences too. */ | |
1612 | for (; stack; stack = stack->next) | |
1613 | { | |
1614 | push_to_sequence (stack->first); | |
00d8a4c1 RK |
1615 | fixup_var_refs_insns (var, promoted_mode, unsignedp, |
1616 | stack->first, stack->next != 0); | |
6f086dfc RS |
1617 | /* Update remembered end of sequence |
1618 | in case we added an insn at the end. */ | |
1619 | stack->last = get_last_insn (); | |
1620 | end_sequence (); | |
1621 | } | |
1622 | ||
1623 | /* Scan all waiting RTL_EXPRs too. */ | |
1624 | for (pending = rtl_exps; pending; pending = TREE_CHAIN (pending)) | |
1625 | { | |
1626 | rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending)); | |
1627 | if (seq != const0_rtx && seq != 0) | |
1628 | { | |
1629 | push_to_sequence (seq); | |
00d8a4c1 | 1630 | fixup_var_refs_insns (var, promoted_mode, unsignedp, seq, 0); |
6f086dfc RS |
1631 | end_sequence (); |
1632 | } | |
1633 | } | |
1634 | } | |
1635 | \f | |
e15679f8 | 1636 | /* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is |
6f086dfc | 1637 | some part of an insn. Return a struct fixup_replacement whose OLD |
0f41302f | 1638 | value is equal to X. Allocate a new structure if no such entry exists. */ |
6f086dfc RS |
1639 | |
1640 | static struct fixup_replacement * | |
2740a678 | 1641 | find_fixup_replacement (replacements, x) |
6f086dfc RS |
1642 | struct fixup_replacement **replacements; |
1643 | rtx x; | |
1644 | { | |
1645 | struct fixup_replacement *p; | |
1646 | ||
1647 | /* See if we have already replaced this. */ | |
1648 | for (p = *replacements; p && p->old != x; p = p->next) | |
1649 | ; | |
1650 | ||
1651 | if (p == 0) | |
1652 | { | |
1653 | p = (struct fixup_replacement *) oballoc (sizeof (struct fixup_replacement)); | |
1654 | p->old = x; | |
1655 | p->new = 0; | |
1656 | p->next = *replacements; | |
1657 | *replacements = p; | |
1658 | } | |
1659 | ||
1660 | return p; | |
1661 | } | |
1662 | ||
1663 | /* Scan the insn-chain starting with INSN for refs to VAR | |
1664 | and fix them up. TOPLEVEL is nonzero if this chain is the | |
1665 | main chain of insns for the current function. */ | |
1666 | ||
1667 | static void | |
00d8a4c1 | 1668 | fixup_var_refs_insns (var, promoted_mode, unsignedp, insn, toplevel) |
6f086dfc | 1669 | rtx var; |
00d8a4c1 RK |
1670 | enum machine_mode promoted_mode; |
1671 | int unsignedp; | |
6f086dfc RS |
1672 | rtx insn; |
1673 | int toplevel; | |
1674 | { | |
02a10449 RK |
1675 | rtx call_dest = 0; |
1676 | ||
6f086dfc RS |
1677 | while (insn) |
1678 | { | |
1679 | rtx next = NEXT_INSN (insn); | |
e5e809f4 | 1680 | rtx set, prev, prev_set; |
6f086dfc | 1681 | rtx note; |
e5e809f4 | 1682 | |
e15762df | 1683 | if (GET_RTX_CLASS (GET_CODE (insn)) == 'i') |
6f086dfc | 1684 | { |
63770d6a RK |
1685 | /* If this is a CLOBBER of VAR, delete it. |
1686 | ||
1687 | If it has a REG_LIBCALL note, delete the REG_LIBCALL | |
1688 | and REG_RETVAL notes too. */ | |
926d1ca5 | 1689 | if (GET_CODE (PATTERN (insn)) == CLOBBER |
07362cb3 JW |
1690 | && (XEXP (PATTERN (insn), 0) == var |
1691 | || (GET_CODE (XEXP (PATTERN (insn), 0)) == CONCAT | |
1692 | && (XEXP (XEXP (PATTERN (insn), 0), 0) == var | |
1693 | || XEXP (XEXP (PATTERN (insn), 0), 1) == var)))) | |
63770d6a RK |
1694 | { |
1695 | if ((note = find_reg_note (insn, REG_LIBCALL, NULL_RTX)) != 0) | |
1696 | /* The REG_LIBCALL note will go away since we are going to | |
1697 | turn INSN into a NOTE, so just delete the | |
1698 | corresponding REG_RETVAL note. */ | |
1699 | remove_note (XEXP (note, 0), | |
1700 | find_reg_note (XEXP (note, 0), REG_RETVAL, | |
1701 | NULL_RTX)); | |
1702 | ||
1703 | /* In unoptimized compilation, we shouldn't call delete_insn | |
1704 | except in jump.c doing warnings. */ | |
1705 | PUT_CODE (insn, NOTE); | |
1706 | NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED; | |
1707 | NOTE_SOURCE_FILE (insn) = 0; | |
1708 | } | |
1709 | ||
6f086dfc | 1710 | /* The insn to load VAR from a home in the arglist |
e5e809f4 JL |
1711 | is now a no-op. When we see it, just delete it. |
1712 | Similarly if this is storing VAR from a register from which | |
1713 | it was loaded in the previous insn. This will occur | |
1714 | when an ADDRESSOF was made for an arglist slot. */ | |
63770d6a | 1715 | else if (toplevel |
e5e809f4 JL |
1716 | && (set = single_set (insn)) != 0 |
1717 | && SET_DEST (set) == var | |
63770d6a RK |
1718 | /* If this represents the result of an insn group, |
1719 | don't delete the insn. */ | |
1720 | && find_reg_note (insn, REG_RETVAL, NULL_RTX) == 0 | |
e5e809f4 JL |
1721 | && (rtx_equal_p (SET_SRC (set), var) |
1722 | || (GET_CODE (SET_SRC (set)) == REG | |
1723 | && (prev = prev_nonnote_insn (insn)) != 0 | |
1724 | && (prev_set = single_set (prev)) != 0 | |
1725 | && SET_DEST (prev_set) == SET_SRC (set) | |
1726 | && rtx_equal_p (SET_SRC (prev_set), var)))) | |
6f086dfc | 1727 | { |
b4ff474c RS |
1728 | /* In unoptimized compilation, we shouldn't call delete_insn |
1729 | except in jump.c doing warnings. */ | |
1730 | PUT_CODE (insn, NOTE); | |
1731 | NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED; | |
1732 | NOTE_SOURCE_FILE (insn) = 0; | |
6f086dfc RS |
1733 | if (insn == last_parm_insn) |
1734 | last_parm_insn = PREV_INSN (next); | |
1735 | } | |
1736 | else | |
1737 | { | |
02a10449 RK |
1738 | struct fixup_replacement *replacements = 0; |
1739 | rtx next_insn = NEXT_INSN (insn); | |
1740 | ||
e9a25f70 JL |
1741 | if (SMALL_REGISTER_CLASSES) |
1742 | { | |
1743 | /* If the insn that copies the results of a CALL_INSN | |
1744 | into a pseudo now references VAR, we have to use an | |
1745 | intermediate pseudo since we want the life of the | |
1746 | return value register to be only a single insn. | |
02a10449 | 1747 | |
e9a25f70 JL |
1748 | If we don't use an intermediate pseudo, such things as |
1749 | address computations to make the address of VAR valid | |
1750 | if it is not can be placed between the CALL_INSN and INSN. | |
02a10449 | 1751 | |
e9a25f70 JL |
1752 | To make sure this doesn't happen, we record the destination |
1753 | of the CALL_INSN and see if the next insn uses both that | |
1754 | and VAR. */ | |
02a10449 | 1755 | |
f95182a4 ILT |
1756 | if (call_dest != 0 && GET_CODE (insn) == INSN |
1757 | && reg_mentioned_p (var, PATTERN (insn)) | |
1758 | && reg_mentioned_p (call_dest, PATTERN (insn))) | |
1759 | { | |
1760 | rtx temp = gen_reg_rtx (GET_MODE (call_dest)); | |
02a10449 | 1761 | |
f95182a4 | 1762 | emit_insn_before (gen_move_insn (temp, call_dest), insn); |
02a10449 | 1763 | |
f95182a4 ILT |
1764 | PATTERN (insn) = replace_rtx (PATTERN (insn), |
1765 | call_dest, temp); | |
1766 | } | |
02a10449 | 1767 | |
f95182a4 ILT |
1768 | if (GET_CODE (insn) == CALL_INSN |
1769 | && GET_CODE (PATTERN (insn)) == SET) | |
1770 | call_dest = SET_DEST (PATTERN (insn)); | |
1771 | else if (GET_CODE (insn) == CALL_INSN | |
1772 | && GET_CODE (PATTERN (insn)) == PARALLEL | |
1773 | && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET) | |
1774 | call_dest = SET_DEST (XVECEXP (PATTERN (insn), 0, 0)); | |
1775 | else | |
1776 | call_dest = 0; | |
1777 | } | |
02a10449 | 1778 | |
6f086dfc RS |
1779 | /* See if we have to do anything to INSN now that VAR is in |
1780 | memory. If it needs to be loaded into a pseudo, use a single | |
1781 | pseudo for the entire insn in case there is a MATCH_DUP | |
1782 | between two operands. We pass a pointer to the head of | |
1783 | a list of struct fixup_replacements. If fixup_var_refs_1 | |
1784 | needs to allocate pseudos or replacement MEMs (for SUBREGs), | |
1785 | it will record them in this list. | |
1786 | ||
1787 | If it allocated a pseudo for any replacement, we copy into | |
1788 | it here. */ | |
1789 | ||
00d8a4c1 RK |
1790 | fixup_var_refs_1 (var, promoted_mode, &PATTERN (insn), insn, |
1791 | &replacements); | |
6f086dfc | 1792 | |
77121fee JW |
1793 | /* If this is last_parm_insn, and any instructions were output |
1794 | after it to fix it up, then we must set last_parm_insn to | |
1795 | the last such instruction emitted. */ | |
1796 | if (insn == last_parm_insn) | |
1797 | last_parm_insn = PREV_INSN (next_insn); | |
1798 | ||
6f086dfc RS |
1799 | while (replacements) |
1800 | { | |
1801 | if (GET_CODE (replacements->new) == REG) | |
1802 | { | |
1803 | rtx insert_before; | |
00d8a4c1 | 1804 | rtx seq; |
6f086dfc RS |
1805 | |
1806 | /* OLD might be a (subreg (mem)). */ | |
1807 | if (GET_CODE (replacements->old) == SUBREG) | |
1808 | replacements->old | |
1809 | = fixup_memory_subreg (replacements->old, insn, 0); | |
1810 | else | |
1811 | replacements->old | |
1812 | = fixup_stack_1 (replacements->old, insn); | |
1813 | ||
5fa7422b | 1814 | insert_before = insn; |
6f086dfc | 1815 | |
00d8a4c1 RK |
1816 | /* If we are changing the mode, do a conversion. |
1817 | This might be wasteful, but combine.c will | |
1818 | eliminate much of the waste. */ | |
1819 | ||
1820 | if (GET_MODE (replacements->new) | |
1821 | != GET_MODE (replacements->old)) | |
1822 | { | |
1823 | start_sequence (); | |
1824 | convert_move (replacements->new, | |
1825 | replacements->old, unsignedp); | |
1826 | seq = gen_sequence (); | |
1827 | end_sequence (); | |
1828 | } | |
1829 | else | |
1830 | seq = gen_move_insn (replacements->new, | |
1831 | replacements->old); | |
1832 | ||
1833 | emit_insn_before (seq, insert_before); | |
6f086dfc RS |
1834 | } |
1835 | ||
1836 | replacements = replacements->next; | |
1837 | } | |
1838 | } | |
1839 | ||
1840 | /* Also fix up any invalid exprs in the REG_NOTES of this insn. | |
1841 | But don't touch other insns referred to by reg-notes; | |
1842 | we will get them elsewhere. */ | |
1843 | for (note = REG_NOTES (insn); note; note = XEXP (note, 1)) | |
1844 | if (GET_CODE (note) != INSN_LIST) | |
ab6155b7 RK |
1845 | XEXP (note, 0) |
1846 | = walk_fixup_memory_subreg (XEXP (note, 0), insn, 1); | |
6f086dfc RS |
1847 | } |
1848 | insn = next; | |
1849 | } | |
1850 | } | |
1851 | \f | |
00d8a4c1 RK |
1852 | /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE. |
1853 | See if the rtx expression at *LOC in INSN needs to be changed. | |
6f086dfc RS |
1854 | |
1855 | REPLACEMENTS is a pointer to a list head that starts out zero, but may | |
1856 | contain a list of original rtx's and replacements. If we find that we need | |
1857 | to modify this insn by replacing a memory reference with a pseudo or by | |
1858 | making a new MEM to implement a SUBREG, we consult that list to see if | |
1859 | we have already chosen a replacement. If none has already been allocated, | |
1860 | we allocate it and update the list. fixup_var_refs_insns will copy VAR | |
1861 | or the SUBREG, as appropriate, to the pseudo. */ | |
1862 | ||
1863 | static void | |
00d8a4c1 | 1864 | fixup_var_refs_1 (var, promoted_mode, loc, insn, replacements) |
6f086dfc | 1865 | register rtx var; |
00d8a4c1 | 1866 | enum machine_mode promoted_mode; |
6f086dfc RS |
1867 | register rtx *loc; |
1868 | rtx insn; | |
1869 | struct fixup_replacement **replacements; | |
1870 | { | |
1871 | register int i; | |
1872 | register rtx x = *loc; | |
1873 | RTX_CODE code = GET_CODE (x); | |
1874 | register char *fmt; | |
1875 | register rtx tem, tem1; | |
1876 | struct fixup_replacement *replacement; | |
1877 | ||
1878 | switch (code) | |
1879 | { | |
e9a25f70 JL |
1880 | case ADDRESSOF: |
1881 | if (XEXP (x, 0) == var) | |
1882 | { | |
956d6950 JL |
1883 | /* Prevent sharing of rtl that might lose. */ |
1884 | rtx sub = copy_rtx (XEXP (var, 0)); | |
1885 | ||
e9a25f70 | 1886 | start_sequence (); |
956d6950 JL |
1887 | |
1888 | if (! validate_change (insn, loc, sub, 0)) | |
1889 | { | |
1890 | rtx y = force_operand (sub, NULL_RTX); | |
1891 | ||
1892 | if (! validate_change (insn, loc, y, 0)) | |
1893 | *loc = copy_to_reg (y); | |
1894 | } | |
1895 | ||
e9a25f70 JL |
1896 | emit_insn_before (gen_sequence (), insn); |
1897 | end_sequence (); | |
1898 | } | |
1899 | return; | |
1900 | ||
6f086dfc RS |
1901 | case MEM: |
1902 | if (var == x) | |
1903 | { | |
1904 | /* If we already have a replacement, use it. Otherwise, | |
1905 | try to fix up this address in case it is invalid. */ | |
1906 | ||
2740a678 | 1907 | replacement = find_fixup_replacement (replacements, var); |
6f086dfc RS |
1908 | if (replacement->new) |
1909 | { | |
1910 | *loc = replacement->new; | |
1911 | return; | |
1912 | } | |
1913 | ||
1914 | *loc = replacement->new = x = fixup_stack_1 (x, insn); | |
1915 | ||
00d8a4c1 RK |
1916 | /* Unless we are forcing memory to register or we changed the mode, |
1917 | we can leave things the way they are if the insn is valid. */ | |
6f086dfc RS |
1918 | |
1919 | INSN_CODE (insn) = -1; | |
00d8a4c1 RK |
1920 | if (! flag_force_mem && GET_MODE (x) == promoted_mode |
1921 | && recog_memoized (insn) >= 0) | |
6f086dfc RS |
1922 | return; |
1923 | ||
00d8a4c1 | 1924 | *loc = replacement->new = gen_reg_rtx (promoted_mode); |
6f086dfc RS |
1925 | return; |
1926 | } | |
1927 | ||
1928 | /* If X contains VAR, we need to unshare it here so that we update | |
1929 | each occurrence separately. But all identical MEMs in one insn | |
1930 | must be replaced with the same rtx because of the possibility of | |
1931 | MATCH_DUPs. */ | |
1932 | ||
1933 | if (reg_mentioned_p (var, x)) | |
1934 | { | |
2740a678 | 1935 | replacement = find_fixup_replacement (replacements, x); |
6f086dfc RS |
1936 | if (replacement->new == 0) |
1937 | replacement->new = copy_most_rtx (x, var); | |
1938 | ||
1939 | *loc = x = replacement->new; | |
1940 | } | |
1941 | break; | |
1942 | ||
1943 | case REG: | |
1944 | case CC0: | |
1945 | case PC: | |
1946 | case CONST_INT: | |
1947 | case CONST: | |
1948 | case SYMBOL_REF: | |
1949 | case LABEL_REF: | |
1950 | case CONST_DOUBLE: | |
1951 | return; | |
1952 | ||
1953 | case SIGN_EXTRACT: | |
1954 | case ZERO_EXTRACT: | |
1955 | /* Note that in some cases those types of expressions are altered | |
1956 | by optimize_bit_field, and do not survive to get here. */ | |
1957 | if (XEXP (x, 0) == var | |
1958 | || (GET_CODE (XEXP (x, 0)) == SUBREG | |
1959 | && SUBREG_REG (XEXP (x, 0)) == var)) | |
1960 | { | |
1961 | /* Get TEM as a valid MEM in the mode presently in the insn. | |
1962 | ||
1963 | We don't worry about the possibility of MATCH_DUP here; it | |
1964 | is highly unlikely and would be tricky to handle. */ | |
1965 | ||
1966 | tem = XEXP (x, 0); | |
1967 | if (GET_CODE (tem) == SUBREG) | |
0e09cc26 RK |
1968 | { |
1969 | if (GET_MODE_BITSIZE (GET_MODE (tem)) | |
1970 | > GET_MODE_BITSIZE (GET_MODE (var))) | |
1971 | { | |
1972 | replacement = find_fixup_replacement (replacements, var); | |
1973 | if (replacement->new == 0) | |
1974 | replacement->new = gen_reg_rtx (GET_MODE (var)); | |
1975 | SUBREG_REG (tem) = replacement->new; | |
1976 | } | |
ef933d26 RK |
1977 | else |
1978 | tem = fixup_memory_subreg (tem, insn, 0); | |
0e09cc26 RK |
1979 | } |
1980 | else | |
1981 | tem = fixup_stack_1 (tem, insn); | |
6f086dfc RS |
1982 | |
1983 | /* Unless we want to load from memory, get TEM into the proper mode | |
1984 | for an extract from memory. This can only be done if the | |
1985 | extract is at a constant position and length. */ | |
1986 | ||
1987 | if (! flag_force_mem && GET_CODE (XEXP (x, 1)) == CONST_INT | |
1988 | && GET_CODE (XEXP (x, 2)) == CONST_INT | |
1989 | && ! mode_dependent_address_p (XEXP (tem, 0)) | |
1990 | && ! MEM_VOLATILE_P (tem)) | |
1991 | { | |
1992 | enum machine_mode wanted_mode = VOIDmode; | |
1993 | enum machine_mode is_mode = GET_MODE (tem); | |
e5e809f4 | 1994 | HOST_WIDE_INT pos = INTVAL (XEXP (x, 2)); |
6f086dfc RS |
1995 | |
1996 | #ifdef HAVE_extzv | |
1997 | if (GET_CODE (x) == ZERO_EXTRACT) | |
0d8e55d8 JL |
1998 | { |
1999 | wanted_mode = insn_operand_mode[(int) CODE_FOR_extzv][1]; | |
2000 | if (wanted_mode == VOIDmode) | |
2001 | wanted_mode = word_mode; | |
2002 | } | |
6f086dfc RS |
2003 | #endif |
2004 | #ifdef HAVE_extv | |
2005 | if (GET_CODE (x) == SIGN_EXTRACT) | |
0d8e55d8 JL |
2006 | { |
2007 | wanted_mode = insn_operand_mode[(int) CODE_FOR_extv][1]; | |
2008 | if (wanted_mode == VOIDmode) | |
2009 | wanted_mode = word_mode; | |
2010 | } | |
6f086dfc | 2011 | #endif |
6dc42e49 | 2012 | /* If we have a narrower mode, we can do something. */ |
6f086dfc RS |
2013 | if (wanted_mode != VOIDmode |
2014 | && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode)) | |
2015 | { | |
e5e809f4 | 2016 | HOST_WIDE_INT offset = pos / BITS_PER_UNIT; |
6f086dfc RS |
2017 | rtx old_pos = XEXP (x, 2); |
2018 | rtx newmem; | |
2019 | ||
2020 | /* If the bytes and bits are counted differently, we | |
2021 | must adjust the offset. */ | |
f76b9db2 ILT |
2022 | if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN) |
2023 | offset = (GET_MODE_SIZE (is_mode) | |
2024 | - GET_MODE_SIZE (wanted_mode) - offset); | |
6f086dfc RS |
2025 | |
2026 | pos %= GET_MODE_BITSIZE (wanted_mode); | |
2027 | ||
38a448ca RH |
2028 | newmem = gen_rtx_MEM (wanted_mode, |
2029 | plus_constant (XEXP (tem, 0), offset)); | |
6f086dfc | 2030 | RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem); |
c6df88cb | 2031 | MEM_COPY_ATTRIBUTES (newmem, tem); |
6f086dfc RS |
2032 | |
2033 | /* Make the change and see if the insn remains valid. */ | |
2034 | INSN_CODE (insn) = -1; | |
2035 | XEXP (x, 0) = newmem; | |
5f4f0e22 | 2036 | XEXP (x, 2) = GEN_INT (pos); |
6f086dfc RS |
2037 | |
2038 | if (recog_memoized (insn) >= 0) | |
2039 | return; | |
2040 | ||
2041 | /* Otherwise, restore old position. XEXP (x, 0) will be | |
2042 | restored later. */ | |
2043 | XEXP (x, 2) = old_pos; | |
2044 | } | |
2045 | } | |
2046 | ||
2047 | /* If we get here, the bitfield extract insn can't accept a memory | |
2048 | reference. Copy the input into a register. */ | |
2049 | ||
2050 | tem1 = gen_reg_rtx (GET_MODE (tem)); | |
2051 | emit_insn_before (gen_move_insn (tem1, tem), insn); | |
2052 | XEXP (x, 0) = tem1; | |
2053 | return; | |
2054 | } | |
2055 | break; | |
2056 | ||
2057 | case SUBREG: | |
2058 | if (SUBREG_REG (x) == var) | |
2059 | { | |
00d8a4c1 RK |
2060 | /* If this is a special SUBREG made because VAR was promoted |
2061 | from a wider mode, replace it with VAR and call ourself | |
2062 | recursively, this time saying that the object previously | |
2063 | had its current mode (by virtue of the SUBREG). */ | |
2064 | ||
2065 | if (SUBREG_PROMOTED_VAR_P (x)) | |
2066 | { | |
2067 | *loc = var; | |
2068 | fixup_var_refs_1 (var, GET_MODE (var), loc, insn, replacements); | |
2069 | return; | |
2070 | } | |
2071 | ||
6f086dfc RS |
2072 | /* If this SUBREG makes VAR wider, it has become a paradoxical |
2073 | SUBREG with VAR in memory, but these aren't allowed at this | |
2074 | stage of the compilation. So load VAR into a pseudo and take | |
2075 | a SUBREG of that pseudo. */ | |
2076 | if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (var))) | |
2077 | { | |
2740a678 | 2078 | replacement = find_fixup_replacement (replacements, var); |
6f086dfc RS |
2079 | if (replacement->new == 0) |
2080 | replacement->new = gen_reg_rtx (GET_MODE (var)); | |
2081 | SUBREG_REG (x) = replacement->new; | |
2082 | return; | |
2083 | } | |
2084 | ||
2085 | /* See if we have already found a replacement for this SUBREG. | |
2086 | If so, use it. Otherwise, make a MEM and see if the insn | |
2087 | is recognized. If not, or if we should force MEM into a register, | |
2088 | make a pseudo for this SUBREG. */ | |
2740a678 | 2089 | replacement = find_fixup_replacement (replacements, x); |
6f086dfc RS |
2090 | if (replacement->new) |
2091 | { | |
2092 | *loc = replacement->new; | |
2093 | return; | |
2094 | } | |
2095 | ||
2096 | replacement->new = *loc = fixup_memory_subreg (x, insn, 0); | |
2097 | ||
f898f031 | 2098 | INSN_CODE (insn) = -1; |
6f086dfc RS |
2099 | if (! flag_force_mem && recog_memoized (insn) >= 0) |
2100 | return; | |
2101 | ||
2102 | *loc = replacement->new = gen_reg_rtx (GET_MODE (x)); | |
2103 | return; | |
2104 | } | |
2105 | break; | |
2106 | ||
2107 | case SET: | |
2108 | /* First do special simplification of bit-field references. */ | |
2109 | if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT | |
2110 | || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT) | |
2111 | optimize_bit_field (x, insn, 0); | |
2112 | if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT | |
2113 | || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT) | |
5f4f0e22 | 2114 | optimize_bit_field (x, insn, NULL_PTR); |
6f086dfc | 2115 | |
0e09cc26 RK |
2116 | /* For a paradoxical SUBREG inside a ZERO_EXTRACT, load the object |
2117 | into a register and then store it back out. */ | |
2118 | if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT | |
2119 | && GET_CODE (XEXP (SET_DEST (x), 0)) == SUBREG | |
2120 | && SUBREG_REG (XEXP (SET_DEST (x), 0)) == var | |
2121 | && (GET_MODE_SIZE (GET_MODE (XEXP (SET_DEST (x), 0))) | |
2122 | > GET_MODE_SIZE (GET_MODE (var)))) | |
2123 | { | |
2124 | replacement = find_fixup_replacement (replacements, var); | |
2125 | if (replacement->new == 0) | |
2126 | replacement->new = gen_reg_rtx (GET_MODE (var)); | |
2127 | ||
2128 | SUBREG_REG (XEXP (SET_DEST (x), 0)) = replacement->new; | |
2129 | emit_insn_after (gen_move_insn (var, replacement->new), insn); | |
2130 | } | |
2131 | ||
6f086dfc | 2132 | /* If SET_DEST is now a paradoxical SUBREG, put the result of this |
0f41302f | 2133 | insn into a pseudo and store the low part of the pseudo into VAR. */ |
6f086dfc RS |
2134 | if (GET_CODE (SET_DEST (x)) == SUBREG |
2135 | && SUBREG_REG (SET_DEST (x)) == var | |
2136 | && (GET_MODE_SIZE (GET_MODE (SET_DEST (x))) | |
2137 | > GET_MODE_SIZE (GET_MODE (var)))) | |
2138 | { | |
2139 | SET_DEST (x) = tem = gen_reg_rtx (GET_MODE (SET_DEST (x))); | |
2140 | emit_insn_after (gen_move_insn (var, gen_lowpart (GET_MODE (var), | |
2141 | tem)), | |
2142 | insn); | |
2143 | break; | |
2144 | } | |
2145 | ||
2146 | { | |
2147 | rtx dest = SET_DEST (x); | |
2148 | rtx src = SET_SRC (x); | |
29a82058 | 2149 | #ifdef HAVE_insv |
6f086dfc | 2150 | rtx outerdest = dest; |
29a82058 | 2151 | #endif |
6f086dfc RS |
2152 | |
2153 | while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART | |
2154 | || GET_CODE (dest) == SIGN_EXTRACT | |
2155 | || GET_CODE (dest) == ZERO_EXTRACT) | |
2156 | dest = XEXP (dest, 0); | |
2157 | ||
2158 | if (GET_CODE (src) == SUBREG) | |
2159 | src = XEXP (src, 0); | |
2160 | ||
2161 | /* If VAR does not appear at the top level of the SET | |
2162 | just scan the lower levels of the tree. */ | |
2163 | ||
2164 | if (src != var && dest != var) | |
2165 | break; | |
2166 | ||
2167 | /* We will need to rerecognize this insn. */ | |
2168 | INSN_CODE (insn) = -1; | |
2169 | ||
2170 | #ifdef HAVE_insv | |
2171 | if (GET_CODE (outerdest) == ZERO_EXTRACT && dest == var) | |
2172 | { | |
2173 | /* Since this case will return, ensure we fixup all the | |
2174 | operands here. */ | |
00d8a4c1 RK |
2175 | fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 1), |
2176 | insn, replacements); | |
2177 | fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 2), | |
2178 | insn, replacements); | |
2179 | fixup_var_refs_1 (var, promoted_mode, &SET_SRC (x), | |
2180 | insn, replacements); | |
6f086dfc RS |
2181 | |
2182 | tem = XEXP (outerdest, 0); | |
2183 | ||
2184 | /* Clean up (SUBREG:SI (MEM:mode ...) 0) | |
2185 | that may appear inside a ZERO_EXTRACT. | |
2186 | This was legitimate when the MEM was a REG. */ | |
2187 | if (GET_CODE (tem) == SUBREG | |
2188 | && SUBREG_REG (tem) == var) | |
0e09cc26 | 2189 | tem = fixup_memory_subreg (tem, insn, 0); |
6f086dfc RS |
2190 | else |
2191 | tem = fixup_stack_1 (tem, insn); | |
2192 | ||
2193 | if (GET_CODE (XEXP (outerdest, 1)) == CONST_INT | |
2194 | && GET_CODE (XEXP (outerdest, 2)) == CONST_INT | |
2195 | && ! mode_dependent_address_p (XEXP (tem, 0)) | |
2196 | && ! MEM_VOLATILE_P (tem)) | |
2197 | { | |
0d8e55d8 | 2198 | enum machine_mode wanted_mode; |
6f086dfc | 2199 | enum machine_mode is_mode = GET_MODE (tem); |
e5e809f4 | 2200 | HOST_WIDE_INT pos = INTVAL (XEXP (outerdest, 2)); |
6f086dfc | 2201 | |
0d8e55d8 JL |
2202 | wanted_mode = insn_operand_mode[(int) CODE_FOR_insv][0]; |
2203 | if (wanted_mode == VOIDmode) | |
2204 | wanted_mode = word_mode; | |
2205 | ||
6dc42e49 | 2206 | /* If we have a narrower mode, we can do something. */ |
6f086dfc RS |
2207 | if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode)) |
2208 | { | |
e5e809f4 | 2209 | HOST_WIDE_INT offset = pos / BITS_PER_UNIT; |
6f086dfc RS |
2210 | rtx old_pos = XEXP (outerdest, 2); |
2211 | rtx newmem; | |
2212 | ||
f76b9db2 ILT |
2213 | if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN) |
2214 | offset = (GET_MODE_SIZE (is_mode) | |
2215 | - GET_MODE_SIZE (wanted_mode) - offset); | |
6f086dfc RS |
2216 | |
2217 | pos %= GET_MODE_BITSIZE (wanted_mode); | |
2218 | ||
38a448ca RH |
2219 | newmem = gen_rtx_MEM (wanted_mode, |
2220 | plus_constant (XEXP (tem, 0), offset)); | |
6f086dfc | 2221 | RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem); |
c6df88cb | 2222 | MEM_COPY_ATTRIBUTES (newmem, tem); |
6f086dfc RS |
2223 | |
2224 | /* Make the change and see if the insn remains valid. */ | |
2225 | INSN_CODE (insn) = -1; | |
2226 | XEXP (outerdest, 0) = newmem; | |
5f4f0e22 | 2227 | XEXP (outerdest, 2) = GEN_INT (pos); |
6f086dfc RS |
2228 | |
2229 | if (recog_memoized (insn) >= 0) | |
2230 | return; | |
2231 | ||
2232 | /* Otherwise, restore old position. XEXP (x, 0) will be | |
2233 | restored later. */ | |
2234 | XEXP (outerdest, 2) = old_pos; | |
2235 | } | |
2236 | } | |
2237 | ||
2238 | /* If we get here, the bit-field store doesn't allow memory | |
2239 | or isn't located at a constant position. Load the value into | |
2240 | a register, do the store, and put it back into memory. */ | |
2241 | ||
2242 | tem1 = gen_reg_rtx (GET_MODE (tem)); | |
2243 | emit_insn_before (gen_move_insn (tem1, tem), insn); | |
2244 | emit_insn_after (gen_move_insn (tem, tem1), insn); | |
2245 | XEXP (outerdest, 0) = tem1; | |
2246 | return; | |
2247 | } | |
2248 | #endif | |
2249 | ||
2250 | /* STRICT_LOW_PART is a no-op on memory references | |
2251 | and it can cause combinations to be unrecognizable, | |
2252 | so eliminate it. */ | |
2253 | ||
2254 | if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART) | |
2255 | SET_DEST (x) = XEXP (SET_DEST (x), 0); | |
2256 | ||
2257 | /* A valid insn to copy VAR into or out of a register | |
2258 | must be left alone, to avoid an infinite loop here. | |
2259 | If the reference to VAR is by a subreg, fix that up, | |
2260 | since SUBREG is not valid for a memref. | |
e15762df RK |
2261 | Also fix up the address of the stack slot. |
2262 | ||
2263 | Note that we must not try to recognize the insn until | |
2264 | after we know that we have valid addresses and no | |
2265 | (subreg (mem ...) ...) constructs, since these interfere | |
2266 | with determining the validity of the insn. */ | |
6f086dfc RS |
2267 | |
2268 | if ((SET_SRC (x) == var | |
2269 | || (GET_CODE (SET_SRC (x)) == SUBREG | |
2270 | && SUBREG_REG (SET_SRC (x)) == var)) | |
2271 | && (GET_CODE (SET_DEST (x)) == REG | |
2272 | || (GET_CODE (SET_DEST (x)) == SUBREG | |
2273 | && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG)) | |
1d273bf5 | 2274 | && GET_MODE (var) == promoted_mode |
c46722a7 | 2275 | && x == single_set (insn)) |
6f086dfc | 2276 | { |
e15762df RK |
2277 | rtx pat; |
2278 | ||
2740a678 | 2279 | replacement = find_fixup_replacement (replacements, SET_SRC (x)); |
6f086dfc | 2280 | if (replacement->new) |
6f086dfc | 2281 | SET_SRC (x) = replacement->new; |
6f086dfc RS |
2282 | else if (GET_CODE (SET_SRC (x)) == SUBREG) |
2283 | SET_SRC (x) = replacement->new | |
2284 | = fixup_memory_subreg (SET_SRC (x), insn, 0); | |
2285 | else | |
2286 | SET_SRC (x) = replacement->new | |
2287 | = fixup_stack_1 (SET_SRC (x), insn); | |
e15762df RK |
2288 | |
2289 | if (recog_memoized (insn) >= 0) | |
2290 | return; | |
2291 | ||
2292 | /* INSN is not valid, but we know that we want to | |
2293 | copy SET_SRC (x) to SET_DEST (x) in some way. So | |
2294 | we generate the move and see whether it requires more | |
2295 | than one insn. If it does, we emit those insns and | |
2296 | delete INSN. Otherwise, we an just replace the pattern | |
2297 | of INSN; we have already verified above that INSN has | |
2298 | no other function that to do X. */ | |
2299 | ||
2300 | pat = gen_move_insn (SET_DEST (x), SET_SRC (x)); | |
2301 | if (GET_CODE (pat) == SEQUENCE) | |
2302 | { | |
2303 | emit_insn_after (pat, insn); | |
2304 | PUT_CODE (insn, NOTE); | |
2305 | NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED; | |
2306 | NOTE_SOURCE_FILE (insn) = 0; | |
2307 | } | |
2308 | else | |
2309 | PATTERN (insn) = pat; | |
2310 | ||
6f086dfc RS |
2311 | return; |
2312 | } | |
2313 | ||
2314 | if ((SET_DEST (x) == var | |
2315 | || (GET_CODE (SET_DEST (x)) == SUBREG | |
2316 | && SUBREG_REG (SET_DEST (x)) == var)) | |
2317 | && (GET_CODE (SET_SRC (x)) == REG | |
2318 | || (GET_CODE (SET_SRC (x)) == SUBREG | |
2319 | && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG)) | |
1d273bf5 | 2320 | && GET_MODE (var) == promoted_mode |
c46722a7 | 2321 | && x == single_set (insn)) |
6f086dfc | 2322 | { |
e15762df RK |
2323 | rtx pat; |
2324 | ||
6f086dfc RS |
2325 | if (GET_CODE (SET_DEST (x)) == SUBREG) |
2326 | SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn, 0); | |
2327 | else | |
2328 | SET_DEST (x) = fixup_stack_1 (SET_DEST (x), insn); | |
e15762df RK |
2329 | |
2330 | if (recog_memoized (insn) >= 0) | |
2331 | return; | |
2332 | ||
2333 | pat = gen_move_insn (SET_DEST (x), SET_SRC (x)); | |
2334 | if (GET_CODE (pat) == SEQUENCE) | |
2335 | { | |
2336 | emit_insn_after (pat, insn); | |
2337 | PUT_CODE (insn, NOTE); | |
2338 | NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED; | |
2339 | NOTE_SOURCE_FILE (insn) = 0; | |
2340 | } | |
2341 | else | |
2342 | PATTERN (insn) = pat; | |
2343 | ||
6f086dfc RS |
2344 | return; |
2345 | } | |
2346 | ||
2347 | /* Otherwise, storing into VAR must be handled specially | |
2348 | by storing into a temporary and copying that into VAR | |
00d8a4c1 RK |
2349 | with a new insn after this one. Note that this case |
2350 | will be used when storing into a promoted scalar since | |
2351 | the insn will now have different modes on the input | |
2352 | and output and hence will be invalid (except for the case | |
2353 | of setting it to a constant, which does not need any | |
2354 | change if it is valid). We generate extra code in that case, | |
2355 | but combine.c will eliminate it. */ | |
6f086dfc RS |
2356 | |
2357 | if (dest == var) | |
2358 | { | |
2359 | rtx temp; | |
00d8a4c1 RK |
2360 | rtx fixeddest = SET_DEST (x); |
2361 | ||
6f086dfc | 2362 | /* STRICT_LOW_PART can be discarded, around a MEM. */ |
00d8a4c1 RK |
2363 | if (GET_CODE (fixeddest) == STRICT_LOW_PART) |
2364 | fixeddest = XEXP (fixeddest, 0); | |
6f086dfc | 2365 | /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */ |
00d8a4c1 | 2366 | if (GET_CODE (fixeddest) == SUBREG) |
926d1ca5 RK |
2367 | { |
2368 | fixeddest = fixup_memory_subreg (fixeddest, insn, 0); | |
2369 | promoted_mode = GET_MODE (fixeddest); | |
2370 | } | |
6f086dfc | 2371 | else |
00d8a4c1 RK |
2372 | fixeddest = fixup_stack_1 (fixeddest, insn); |
2373 | ||
926d1ca5 | 2374 | temp = gen_reg_rtx (promoted_mode); |
00d8a4c1 RK |
2375 | |
2376 | emit_insn_after (gen_move_insn (fixeddest, | |
2377 | gen_lowpart (GET_MODE (fixeddest), | |
2378 | temp)), | |
2379 | insn); | |
6f086dfc | 2380 | |
6f086dfc RS |
2381 | SET_DEST (x) = temp; |
2382 | } | |
2383 | } | |
e9a25f70 JL |
2384 | |
2385 | default: | |
2386 | break; | |
6f086dfc RS |
2387 | } |
2388 | ||
2389 | /* Nothing special about this RTX; fix its operands. */ | |
2390 | ||
2391 | fmt = GET_RTX_FORMAT (code); | |
2392 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
2393 | { | |
2394 | if (fmt[i] == 'e') | |
00d8a4c1 | 2395 | fixup_var_refs_1 (var, promoted_mode, &XEXP (x, i), insn, replacements); |
6f086dfc RS |
2396 | if (fmt[i] == 'E') |
2397 | { | |
2398 | register int j; | |
2399 | for (j = 0; j < XVECLEN (x, i); j++) | |
00d8a4c1 RK |
2400 | fixup_var_refs_1 (var, promoted_mode, &XVECEXP (x, i, j), |
2401 | insn, replacements); | |
6f086dfc RS |
2402 | } |
2403 | } | |
2404 | } | |
2405 | \f | |
2406 | /* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)), | |
2407 | return an rtx (MEM:m1 newaddr) which is equivalent. | |
2408 | If any insns must be emitted to compute NEWADDR, put them before INSN. | |
2409 | ||
2410 | UNCRITICAL nonzero means accept paradoxical subregs. | |
0f41302f | 2411 | This is used for subregs found inside REG_NOTES. */ |
6f086dfc RS |
2412 | |
2413 | static rtx | |
2414 | fixup_memory_subreg (x, insn, uncritical) | |
2415 | rtx x; | |
2416 | rtx insn; | |
2417 | int uncritical; | |
2418 | { | |
2419 | int offset = SUBREG_WORD (x) * UNITS_PER_WORD; | |
2420 | rtx addr = XEXP (SUBREG_REG (x), 0); | |
2421 | enum machine_mode mode = GET_MODE (x); | |
29a82058 | 2422 | rtx result; |
6f086dfc RS |
2423 | |
2424 | /* Paradoxical SUBREGs are usually invalid during RTL generation. */ | |
2425 | if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) | |
2426 | && ! uncritical) | |
2427 | abort (); | |
2428 | ||
f76b9db2 ILT |
2429 | if (BYTES_BIG_ENDIAN) |
2430 | offset += (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))) | |
2431 | - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))); | |
6f086dfc RS |
2432 | addr = plus_constant (addr, offset); |
2433 | if (!flag_force_addr && memory_address_p (mode, addr)) | |
2434 | /* Shortcut if no insns need be emitted. */ | |
2435 | return change_address (SUBREG_REG (x), mode, addr); | |
2436 | start_sequence (); | |
2437 | result = change_address (SUBREG_REG (x), mode, addr); | |
2438 | emit_insn_before (gen_sequence (), insn); | |
2439 | end_sequence (); | |
2440 | return result; | |
2441 | } | |
2442 | ||
2443 | /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X. | |
2444 | Replace subexpressions of X in place. | |
2445 | If X itself is a (SUBREG (MEM ...) ...), return the replacement expression. | |
2446 | Otherwise return X, with its contents possibly altered. | |
2447 | ||
ab6155b7 RK |
2448 | If any insns must be emitted to compute NEWADDR, put them before INSN. |
2449 | ||
2450 | UNCRITICAL is as in fixup_memory_subreg. */ | |
6f086dfc RS |
2451 | |
2452 | static rtx | |
ab6155b7 | 2453 | walk_fixup_memory_subreg (x, insn, uncritical) |
6f086dfc RS |
2454 | register rtx x; |
2455 | rtx insn; | |
ab6155b7 | 2456 | int uncritical; |
6f086dfc RS |
2457 | { |
2458 | register enum rtx_code code; | |
2459 | register char *fmt; | |
2460 | register int i; | |
2461 | ||
2462 | if (x == 0) | |
2463 | return 0; | |
2464 | ||
2465 | code = GET_CODE (x); | |
2466 | ||
2467 | if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM) | |
ab6155b7 | 2468 | return fixup_memory_subreg (x, insn, uncritical); |
6f086dfc RS |
2469 | |
2470 | /* Nothing special about this RTX; fix its operands. */ | |
2471 | ||
2472 | fmt = GET_RTX_FORMAT (code); | |
2473 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
2474 | { | |
2475 | if (fmt[i] == 'e') | |
ab6155b7 | 2476 | XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn, uncritical); |
6f086dfc RS |
2477 | if (fmt[i] == 'E') |
2478 | { | |
2479 | register int j; | |
2480 | for (j = 0; j < XVECLEN (x, i); j++) | |
2481 | XVECEXP (x, i, j) | |
ab6155b7 | 2482 | = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn, uncritical); |
6f086dfc RS |
2483 | } |
2484 | } | |
2485 | return x; | |
2486 | } | |
2487 | \f | |
6f086dfc RS |
2488 | /* For each memory ref within X, if it refers to a stack slot |
2489 | with an out of range displacement, put the address in a temp register | |
2490 | (emitting new insns before INSN to load these registers) | |
2491 | and alter the memory ref to use that register. | |
2492 | Replace each such MEM rtx with a copy, to avoid clobberage. */ | |
2493 | ||
2494 | static rtx | |
2495 | fixup_stack_1 (x, insn) | |
2496 | rtx x; | |
2497 | rtx insn; | |
2498 | { | |
2499 | register int i; | |
2500 | register RTX_CODE code = GET_CODE (x); | |
2501 | register char *fmt; | |
2502 | ||
2503 | if (code == MEM) | |
2504 | { | |
2505 | register rtx ad = XEXP (x, 0); | |
2506 | /* If we have address of a stack slot but it's not valid | |
2507 | (displacement is too large), compute the sum in a register. */ | |
2508 | if (GET_CODE (ad) == PLUS | |
2509 | && GET_CODE (XEXP (ad, 0)) == REG | |
40d05551 RK |
2510 | && ((REGNO (XEXP (ad, 0)) >= FIRST_VIRTUAL_REGISTER |
2511 | && REGNO (XEXP (ad, 0)) <= LAST_VIRTUAL_REGISTER) | |
e9a25f70 JL |
2512 | || REGNO (XEXP (ad, 0)) == FRAME_POINTER_REGNUM |
2513 | #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM | |
2514 | || REGNO (XEXP (ad, 0)) == HARD_FRAME_POINTER_REGNUM | |
2515 | #endif | |
2516 | || REGNO (XEXP (ad, 0)) == STACK_POINTER_REGNUM | |
956d6950 | 2517 | || REGNO (XEXP (ad, 0)) == ARG_POINTER_REGNUM |
40d05551 | 2518 | || XEXP (ad, 0) == current_function_internal_arg_pointer) |
6f086dfc RS |
2519 | && GET_CODE (XEXP (ad, 1)) == CONST_INT) |
2520 | { | |
2521 | rtx temp, seq; | |
2522 | if (memory_address_p (GET_MODE (x), ad)) | |
2523 | return x; | |
2524 | ||
2525 | start_sequence (); | |
2526 | temp = copy_to_reg (ad); | |
2527 | seq = gen_sequence (); | |
2528 | end_sequence (); | |
2529 | emit_insn_before (seq, insn); | |
2530 | return change_address (x, VOIDmode, temp); | |
2531 | } | |
2532 | return x; | |
2533 | } | |
2534 | ||
2535 | fmt = GET_RTX_FORMAT (code); | |
2536 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
2537 | { | |
2538 | if (fmt[i] == 'e') | |
2539 | XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn); | |
2540 | if (fmt[i] == 'E') | |
2541 | { | |
2542 | register int j; | |
2543 | for (j = 0; j < XVECLEN (x, i); j++) | |
2544 | XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn); | |
2545 | } | |
2546 | } | |
2547 | return x; | |
2548 | } | |
2549 | \f | |
2550 | /* Optimization: a bit-field instruction whose field | |
2551 | happens to be a byte or halfword in memory | |
2552 | can be changed to a move instruction. | |
2553 | ||
2554 | We call here when INSN is an insn to examine or store into a bit-field. | |
2555 | BODY is the SET-rtx to be altered. | |
2556 | ||
2557 | EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0. | |
2558 | (Currently this is called only from function.c, and EQUIV_MEM | |
2559 | is always 0.) */ | |
2560 | ||
2561 | static void | |
2562 | optimize_bit_field (body, insn, equiv_mem) | |
2563 | rtx body; | |
2564 | rtx insn; | |
2565 | rtx *equiv_mem; | |
2566 | { | |
2567 | register rtx bitfield; | |
2568 | int destflag; | |
2569 | rtx seq = 0; | |
2570 | enum machine_mode mode; | |
2571 | ||
2572 | if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT | |
2573 | || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT) | |
2574 | bitfield = SET_DEST (body), destflag = 1; | |
2575 | else | |
2576 | bitfield = SET_SRC (body), destflag = 0; | |
2577 | ||
2578 | /* First check that the field being stored has constant size and position | |
2579 | and is in fact a byte or halfword suitably aligned. */ | |
2580 | ||
2581 | if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT | |
2582 | && GET_CODE (XEXP (bitfield, 2)) == CONST_INT | |
2583 | && ((mode = mode_for_size (INTVAL (XEXP (bitfield, 1)), MODE_INT, 1)) | |
2584 | != BLKmode) | |
2585 | && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0) | |
2586 | { | |
2587 | register rtx memref = 0; | |
2588 | ||
2589 | /* Now check that the containing word is memory, not a register, | |
2590 | and that it is safe to change the machine mode. */ | |
2591 | ||
2592 | if (GET_CODE (XEXP (bitfield, 0)) == MEM) | |
2593 | memref = XEXP (bitfield, 0); | |
2594 | else if (GET_CODE (XEXP (bitfield, 0)) == REG | |
2595 | && equiv_mem != 0) | |
2596 | memref = equiv_mem[REGNO (XEXP (bitfield, 0))]; | |
2597 | else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG | |
2598 | && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM) | |
2599 | memref = SUBREG_REG (XEXP (bitfield, 0)); | |
2600 | else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG | |
2601 | && equiv_mem != 0 | |
2602 | && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG) | |
2603 | memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))]; | |
2604 | ||
2605 | if (memref | |
2606 | && ! mode_dependent_address_p (XEXP (memref, 0)) | |
2607 | && ! MEM_VOLATILE_P (memref)) | |
2608 | { | |
2609 | /* Now adjust the address, first for any subreg'ing | |
2610 | that we are now getting rid of, | |
2611 | and then for which byte of the word is wanted. */ | |
2612 | ||
e5e809f4 | 2613 | HOST_WIDE_INT offset = INTVAL (XEXP (bitfield, 2)); |
b88a3142 RK |
2614 | rtx insns; |
2615 | ||
6f086dfc | 2616 | /* Adjust OFFSET to count bits from low-address byte. */ |
f76b9db2 ILT |
2617 | if (BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN) |
2618 | offset = (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield, 0))) | |
2619 | - offset - INTVAL (XEXP (bitfield, 1))); | |
2620 | ||
6f086dfc RS |
2621 | /* Adjust OFFSET to count bytes from low-address byte. */ |
2622 | offset /= BITS_PER_UNIT; | |
2623 | if (GET_CODE (XEXP (bitfield, 0)) == SUBREG) | |
2624 | { | |
2625 | offset += SUBREG_WORD (XEXP (bitfield, 0)) * UNITS_PER_WORD; | |
f76b9db2 ILT |
2626 | if (BYTES_BIG_ENDIAN) |
2627 | offset -= (MIN (UNITS_PER_WORD, | |
2628 | GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0)))) | |
2629 | - MIN (UNITS_PER_WORD, | |
2630 | GET_MODE_SIZE (GET_MODE (memref)))); | |
6f086dfc RS |
2631 | } |
2632 | ||
b88a3142 RK |
2633 | start_sequence (); |
2634 | memref = change_address (memref, mode, | |
6f086dfc | 2635 | plus_constant (XEXP (memref, 0), offset)); |
b88a3142 RK |
2636 | insns = get_insns (); |
2637 | end_sequence (); | |
2638 | emit_insns_before (insns, insn); | |
6f086dfc RS |
2639 | |
2640 | /* Store this memory reference where | |
2641 | we found the bit field reference. */ | |
2642 | ||
2643 | if (destflag) | |
2644 | { | |
2645 | validate_change (insn, &SET_DEST (body), memref, 1); | |
2646 | if (! CONSTANT_ADDRESS_P (SET_SRC (body))) | |
2647 | { | |
2648 | rtx src = SET_SRC (body); | |
2649 | while (GET_CODE (src) == SUBREG | |
2650 | && SUBREG_WORD (src) == 0) | |
2651 | src = SUBREG_REG (src); | |
2652 | if (GET_MODE (src) != GET_MODE (memref)) | |
2653 | src = gen_lowpart (GET_MODE (memref), SET_SRC (body)); | |
2654 | validate_change (insn, &SET_SRC (body), src, 1); | |
2655 | } | |
2656 | else if (GET_MODE (SET_SRC (body)) != VOIDmode | |
2657 | && GET_MODE (SET_SRC (body)) != GET_MODE (memref)) | |
2658 | /* This shouldn't happen because anything that didn't have | |
2659 | one of these modes should have got converted explicitly | |
2660 | and then referenced through a subreg. | |
2661 | This is so because the original bit-field was | |
2662 | handled by agg_mode and so its tree structure had | |
2663 | the same mode that memref now has. */ | |
2664 | abort (); | |
2665 | } | |
2666 | else | |
2667 | { | |
2668 | rtx dest = SET_DEST (body); | |
2669 | ||
2670 | while (GET_CODE (dest) == SUBREG | |
4013a709 RK |
2671 | && SUBREG_WORD (dest) == 0 |
2672 | && (GET_MODE_CLASS (GET_MODE (dest)) | |
2673 | == GET_MODE_CLASS (GET_MODE (SUBREG_REG (dest))))) | |
6f086dfc RS |
2674 | dest = SUBREG_REG (dest); |
2675 | ||
2676 | validate_change (insn, &SET_DEST (body), dest, 1); | |
2677 | ||
2678 | if (GET_MODE (dest) == GET_MODE (memref)) | |
2679 | validate_change (insn, &SET_SRC (body), memref, 1); | |
2680 | else | |
2681 | { | |
2682 | /* Convert the mem ref to the destination mode. */ | |
2683 | rtx newreg = gen_reg_rtx (GET_MODE (dest)); | |
2684 | ||
2685 | start_sequence (); | |
2686 | convert_move (newreg, memref, | |
2687 | GET_CODE (SET_SRC (body)) == ZERO_EXTRACT); | |
2688 | seq = get_insns (); | |
2689 | end_sequence (); | |
2690 | ||
2691 | validate_change (insn, &SET_SRC (body), newreg, 1); | |
2692 | } | |
2693 | } | |
2694 | ||
2695 | /* See if we can convert this extraction or insertion into | |
2696 | a simple move insn. We might not be able to do so if this | |
2697 | was, for example, part of a PARALLEL. | |
2698 | ||
2699 | If we succeed, write out any needed conversions. If we fail, | |
2700 | it is hard to guess why we failed, so don't do anything | |
2701 | special; just let the optimization be suppressed. */ | |
2702 | ||
2703 | if (apply_change_group () && seq) | |
2704 | emit_insns_before (seq, insn); | |
2705 | } | |
2706 | } | |
2707 | } | |
2708 | \f | |
2709 | /* These routines are responsible for converting virtual register references | |
2710 | to the actual hard register references once RTL generation is complete. | |
2711 | ||
2712 | The following four variables are used for communication between the | |
2713 | routines. They contain the offsets of the virtual registers from their | |
2714 | respective hard registers. */ | |
2715 | ||
2716 | static int in_arg_offset; | |
2717 | static int var_offset; | |
2718 | static int dynamic_offset; | |
2719 | static int out_arg_offset; | |
71038426 | 2720 | static int cfa_offset; |
6f086dfc RS |
2721 | |
2722 | /* In most machines, the stack pointer register is equivalent to the bottom | |
2723 | of the stack. */ | |
2724 | ||
2725 | #ifndef STACK_POINTER_OFFSET | |
2726 | #define STACK_POINTER_OFFSET 0 | |
2727 | #endif | |
2728 | ||
2729 | /* If not defined, pick an appropriate default for the offset of dynamically | |
2730 | allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS, | |
2731 | REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */ | |
2732 | ||
2733 | #ifndef STACK_DYNAMIC_OFFSET | |
2734 | ||
2735 | #ifdef ACCUMULATE_OUTGOING_ARGS | |
2736 | /* The bottom of the stack points to the actual arguments. If | |
2737 | REG_PARM_STACK_SPACE is defined, this includes the space for the register | |
2738 | parameters. However, if OUTGOING_REG_PARM_STACK space is not defined, | |
2739 | stack space for register parameters is not pushed by the caller, but | |
2740 | rather part of the fixed stack areas and hence not included in | |
2741 | `current_function_outgoing_args_size'. Nevertheless, we must allow | |
2742 | for it when allocating stack dynamic objects. */ | |
2743 | ||
2744 | #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE) | |
2745 | #define STACK_DYNAMIC_OFFSET(FNDECL) \ | |
2746 | (current_function_outgoing_args_size \ | |
2747 | + REG_PARM_STACK_SPACE (FNDECL) + (STACK_POINTER_OFFSET)) | |
2748 | ||
2749 | #else | |
2750 | #define STACK_DYNAMIC_OFFSET(FNDECL) \ | |
2751 | (current_function_outgoing_args_size + (STACK_POINTER_OFFSET)) | |
2752 | #endif | |
2753 | ||
2754 | #else | |
2755 | #define STACK_DYNAMIC_OFFSET(FNDECL) STACK_POINTER_OFFSET | |
2756 | #endif | |
2757 | #endif | |
2758 | ||
71038426 RH |
2759 | /* On a few machines, the CFA coincides with the arg pointer. */ |
2760 | ||
2761 | #ifndef ARG_POINTER_CFA_OFFSET | |
2762 | #define ARG_POINTER_CFA_OFFSET 0 | |
2763 | #endif | |
2764 | ||
2765 | ||
e9a25f70 JL |
2766 | /* Build up a (MEM (ADDRESSOF (REG))) rtx for a register REG that just had |
2767 | its address taken. DECL is the decl for the object stored in the | |
2768 | register, for later use if we do need to force REG into the stack. | |
2769 | REG is overwritten by the MEM like in put_reg_into_stack. */ | |
2770 | ||
2771 | rtx | |
2772 | gen_mem_addressof (reg, decl) | |
2773 | rtx reg; | |
2774 | tree decl; | |
2775 | { | |
2776 | tree type = TREE_TYPE (decl); | |
38a448ca | 2777 | rtx r = gen_rtx_ADDRESSOF (Pmode, gen_reg_rtx (GET_MODE (reg)), REGNO (reg)); |
e9a25f70 | 2778 | SET_ADDRESSOF_DECL (r, decl); |
95ca22f4 MM |
2779 | /* If the original REG was a user-variable, then so is the REG whose |
2780 | address is being taken. */ | |
2781 | REG_USERVAR_P (XEXP (r, 0)) = REG_USERVAR_P (reg); | |
e9a25f70 JL |
2782 | |
2783 | XEXP (reg, 0) = r; | |
2784 | PUT_CODE (reg, MEM); | |
2785 | PUT_MODE (reg, DECL_MODE (decl)); | |
2786 | MEM_VOLATILE_P (reg) = TREE_SIDE_EFFECTS (decl); | |
c6df88cb | 2787 | MEM_SET_IN_STRUCT_P (reg, AGGREGATE_TYPE_P (type)); |
41472af8 | 2788 | MEM_ALIAS_SET (reg) = get_alias_set (decl); |
e9a25f70 | 2789 | |
e5e809f4 JL |
2790 | if (TREE_USED (decl) || DECL_INITIAL (decl) != 0) |
2791 | fixup_var_refs (reg, GET_MODE (reg), TREE_UNSIGNED (type)); | |
2792 | ||
e9a25f70 JL |
2793 | return reg; |
2794 | } | |
2795 | ||
2796 | /* If DECL has an RTL that is an ADDRESSOF rtx, put it into the stack. */ | |
2797 | ||
2798 | void | |
2799 | flush_addressof (decl) | |
2800 | tree decl; | |
2801 | { | |
2802 | if ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == VAR_DECL) | |
2803 | && DECL_RTL (decl) != 0 | |
2804 | && GET_CODE (DECL_RTL (decl)) == MEM | |
2805 | && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF | |
2806 | && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 0)) == REG) | |
2807 | put_addressof_into_stack (XEXP (DECL_RTL (decl), 0)); | |
2808 | } | |
2809 | ||
2810 | /* Force the register pointed to by R, an ADDRESSOF rtx, into the stack. */ | |
2811 | ||
2812 | static void | |
2813 | put_addressof_into_stack (r) | |
2814 | rtx r; | |
2815 | { | |
2816 | tree decl = ADDRESSOF_DECL (r); | |
2817 | rtx reg = XEXP (r, 0); | |
2818 | ||
2819 | if (GET_CODE (reg) != REG) | |
2820 | abort (); | |
2821 | ||
2822 | put_reg_into_stack (0, reg, TREE_TYPE (decl), GET_MODE (reg), | |
2823 | DECL_MODE (decl), TREE_SIDE_EFFECTS (decl), | |
e5e809f4 JL |
2824 | ADDRESSOF_REGNO (r), |
2825 | TREE_USED (decl) || DECL_INITIAL (decl) != 0); | |
e9a25f70 JL |
2826 | } |
2827 | ||
b5bd3b3c AS |
2828 | /* List of replacements made below in purge_addressof_1 when creating |
2829 | bitfield insertions. */ | |
2830 | static rtx purge_addressof_replacements; | |
2831 | ||
e9a25f70 JL |
2832 | /* Helper function for purge_addressof. See if the rtx expression at *LOC |
2833 | in INSN needs to be changed. If FORCE, always put any ADDRESSOFs into | |
2834 | the stack. */ | |
2835 | ||
2836 | static void | |
f7b6d104 | 2837 | purge_addressof_1 (loc, insn, force, store) |
e9a25f70 JL |
2838 | rtx *loc; |
2839 | rtx insn; | |
f7b6d104 | 2840 | int force, store; |
e9a25f70 JL |
2841 | { |
2842 | rtx x; | |
2843 | RTX_CODE code; | |
2844 | int i, j; | |
2845 | char *fmt; | |
2846 | ||
2847 | /* Re-start here to avoid recursion in common cases. */ | |
2848 | restart: | |
2849 | ||
2850 | x = *loc; | |
2851 | if (x == 0) | |
2852 | return; | |
2853 | ||
2854 | code = GET_CODE (x); | |
2855 | ||
2856 | if (code == ADDRESSOF && GET_CODE (XEXP (x, 0)) == MEM) | |
2857 | { | |
2858 | rtx insns; | |
956d6950 JL |
2859 | /* We must create a copy of the rtx because it was created by |
2860 | overwriting a REG rtx which is always shared. */ | |
2861 | rtx sub = copy_rtx (XEXP (XEXP (x, 0), 0)); | |
e9a25f70 | 2862 | |
956d6950 | 2863 | if (validate_change (insn, loc, sub, 0)) |
e9a25f70 JL |
2864 | return; |
2865 | ||
2866 | start_sequence (); | |
2867 | if (! validate_change (insn, loc, | |
956d6950 | 2868 | force_operand (sub, NULL_RTX), |
e9a25f70 JL |
2869 | 0)) |
2870 | abort (); | |
2871 | ||
f7b6d104 | 2872 | insns = gen_sequence (); |
e9a25f70 | 2873 | end_sequence (); |
18e765cb | 2874 | emit_insn_before (insns, insn); |
e9a25f70 JL |
2875 | return; |
2876 | } | |
2877 | else if (code == MEM && GET_CODE (XEXP (x, 0)) == ADDRESSOF && ! force) | |
2878 | { | |
2879 | rtx sub = XEXP (XEXP (x, 0), 0); | |
e5e809f4 | 2880 | |
6d8ccdbb | 2881 | if (GET_CODE (sub) == MEM) |
38a448ca | 2882 | sub = gen_rtx_MEM (GET_MODE (x), copy_rtx (XEXP (sub, 0))); |
e5e809f4 | 2883 | |
f5963e61 JL |
2884 | if (GET_CODE (sub) == REG |
2885 | && (MEM_VOLATILE_P (x) || GET_MODE (x) == BLKmode)) | |
e5e809f4 JL |
2886 | { |
2887 | put_addressof_into_stack (XEXP (x, 0)); | |
2888 | return; | |
2889 | } | |
2890 | else if (GET_CODE (sub) == REG && GET_MODE (x) != GET_MODE (sub)) | |
e9a25f70 | 2891 | { |
f7b6d104 RH |
2892 | int size_x, size_sub; |
2893 | ||
b5bd3b3c AS |
2894 | if (!insn) |
2895 | { | |
2896 | /* When processing REG_NOTES look at the list of | |
2897 | replacements done on the insn to find the register that X | |
2898 | was replaced by. */ | |
2899 | rtx tem; | |
2900 | ||
2901 | for (tem = purge_addressof_replacements; tem != NULL_RTX; | |
2902 | tem = XEXP (XEXP (tem, 1), 1)) | |
fbdfe39c RH |
2903 | { |
2904 | rtx y = XEXP (tem, 0); | |
2905 | if (GET_CODE (y) == MEM | |
2906 | && rtx_equal_p (XEXP (x, 0), XEXP (y, 0))) | |
2907 | { | |
2908 | /* It can happen that the note may speak of things in | |
2909 | a wider (or just different) mode than the code did. | |
2910 | This is especially true of REG_RETVAL. */ | |
2911 | ||
2912 | rtx z = XEXP (XEXP (tem, 1), 0); | |
2913 | if (GET_MODE (x) != GET_MODE (y)) | |
2914 | { | |
2915 | if (GET_CODE (z) == SUBREG && SUBREG_WORD (z) == 0) | |
2916 | z = SUBREG_REG (z); | |
2917 | ||
2918 | /* ??? If we'd gotten into any of the really complex | |
2919 | cases below, I'm not sure we can do a proper | |
2920 | replacement. Might we be able to delete the | |
2921 | note in some cases? */ | |
2922 | if (GET_MODE_SIZE (GET_MODE (x)) | |
2923 | < GET_MODE_SIZE (GET_MODE (y))) | |
2924 | abort (); | |
2925 | ||
2926 | z = gen_lowpart (GET_MODE (x), z); | |
2927 | } | |
2928 | ||
2929 | *loc = z; | |
2930 | return; | |
2931 | } | |
2932 | } | |
b5bd3b3c AS |
2933 | |
2934 | /* There should always be such a replacement. */ | |
2935 | abort (); | |
2936 | } | |
2937 | ||
f7b6d104 RH |
2938 | size_x = GET_MODE_BITSIZE (GET_MODE (x)); |
2939 | size_sub = GET_MODE_BITSIZE (GET_MODE (sub)); | |
2940 | ||
2941 | /* Don't even consider working with paradoxical subregs, | |
2942 | or the moral equivalent seen here. */ | |
470032d7 | 2943 | if (size_x <= size_sub |
d006aa54 | 2944 | && int_mode_for_mode (GET_MODE (sub)) != BLKmode) |
e9a25f70 | 2945 | { |
f7b6d104 RH |
2946 | /* Do a bitfield insertion to mirror what would happen |
2947 | in memory. */ | |
2948 | ||
f7b6d104 RH |
2949 | rtx val, seq; |
2950 | ||
f7b6d104 RH |
2951 | if (store) |
2952 | { | |
de0dd934 R |
2953 | rtx p; |
2954 | ||
f7b6d104 RH |
2955 | start_sequence (); |
2956 | val = gen_reg_rtx (GET_MODE (x)); | |
2957 | if (! validate_change (insn, loc, val, 0)) | |
b5bd3b3c AS |
2958 | { |
2959 | /* Discard the current sequence and put the | |
2960 | ADDRESSOF on stack. */ | |
2961 | end_sequence (); | |
2962 | goto give_up; | |
2963 | } | |
f7b6d104 RH |
2964 | seq = gen_sequence (); |
2965 | end_sequence (); | |
2966 | emit_insn_before (seq, insn); | |
2967 | ||
2968 | start_sequence (); | |
47401c4d | 2969 | store_bit_field (sub, size_x, 0, GET_MODE (x), |
f7b6d104 RH |
2970 | val, GET_MODE_SIZE (GET_MODE (sub)), |
2971 | GET_MODE_SIZE (GET_MODE (sub))); | |
2972 | ||
de0dd934 R |
2973 | /* Make sure to unshare any shared rtl that store_bit_field |
2974 | might have created. */ | |
2975 | for (p = get_insns(); p; p = NEXT_INSN (p)) | |
2976 | { | |
2977 | reset_used_flags (PATTERN (p)); | |
2978 | reset_used_flags (REG_NOTES (p)); | |
2979 | reset_used_flags (LOG_LINKS (p)); | |
2980 | } | |
2981 | unshare_all_rtl (get_insns ()); | |
2982 | ||
f7b6d104 RH |
2983 | seq = gen_sequence (); |
2984 | end_sequence (); | |
2985 | emit_insn_after (seq, insn); | |
2986 | } | |
2987 | else | |
2988 | { | |
2989 | start_sequence (); | |
47401c4d | 2990 | val = extract_bit_field (sub, size_x, 0, 1, NULL_RTX, |
f7b6d104 RH |
2991 | GET_MODE (x), GET_MODE (x), |
2992 | GET_MODE_SIZE (GET_MODE (sub)), | |
2993 | GET_MODE_SIZE (GET_MODE (sub))); | |
2994 | ||
f7b6d104 | 2995 | if (! validate_change (insn, loc, val, 0)) |
b5bd3b3c AS |
2996 | { |
2997 | /* Discard the current sequence and put the | |
2998 | ADDRESSOF on stack. */ | |
2999 | end_sequence (); | |
3000 | goto give_up; | |
3001 | } | |
f7b6d104 RH |
3002 | |
3003 | seq = gen_sequence (); | |
3004 | end_sequence (); | |
3005 | emit_insn_before (seq, insn); | |
3006 | } | |
3007 | ||
b5bd3b3c AS |
3008 | /* Remember the replacement so that the same one can be done |
3009 | on the REG_NOTES. */ | |
3010 | purge_addressof_replacements | |
3011 | = gen_rtx_EXPR_LIST (VOIDmode, x, | |
3012 | gen_rtx_EXPR_LIST (VOIDmode, val, | |
3013 | purge_addressof_replacements)); | |
3014 | ||
f7b6d104 RH |
3015 | /* We replaced with a reg -- all done. */ |
3016 | return; | |
e9a25f70 JL |
3017 | } |
3018 | } | |
3019 | else if (validate_change (insn, loc, sub, 0)) | |
fbdfe39c RH |
3020 | { |
3021 | /* Remember the replacement so that the same one can be done | |
3022 | on the REG_NOTES. */ | |
3023 | purge_addressof_replacements | |
3024 | = gen_rtx_EXPR_LIST (VOIDmode, x, | |
3025 | gen_rtx_EXPR_LIST (VOIDmode, sub, | |
3026 | purge_addressof_replacements)); | |
3027 | goto restart; | |
3028 | } | |
b5bd3b3c | 3029 | give_up:; |
e9a25f70 JL |
3030 | /* else give up and put it into the stack */ |
3031 | } | |
3032 | else if (code == ADDRESSOF) | |
3033 | { | |
3034 | put_addressof_into_stack (x); | |
3035 | return; | |
3036 | } | |
f7b6d104 RH |
3037 | else if (code == SET) |
3038 | { | |
3039 | purge_addressof_1 (&SET_DEST (x), insn, force, 1); | |
3040 | purge_addressof_1 (&SET_SRC (x), insn, force, 0); | |
3041 | return; | |
3042 | } | |
e9a25f70 JL |
3043 | |
3044 | /* Scan all subexpressions. */ | |
3045 | fmt = GET_RTX_FORMAT (code); | |
3046 | for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++) | |
3047 | { | |
3048 | if (*fmt == 'e') | |
f7b6d104 | 3049 | purge_addressof_1 (&XEXP (x, i), insn, force, 0); |
e9a25f70 JL |
3050 | else if (*fmt == 'E') |
3051 | for (j = 0; j < XVECLEN (x, i); j++) | |
f7b6d104 | 3052 | purge_addressof_1 (&XVECEXP (x, i, j), insn, force, 0); |
e9a25f70 JL |
3053 | } |
3054 | } | |
3055 | ||
3056 | /* Eliminate all occurrences of ADDRESSOF from INSNS. Elide any remaining | |
3057 | (MEM (ADDRESSOF)) patterns, and force any needed registers into the | |
3058 | stack. */ | |
3059 | ||
3060 | void | |
3061 | purge_addressof (insns) | |
3062 | rtx insns; | |
3063 | { | |
3064 | rtx insn; | |
3065 | for (insn = insns; insn; insn = NEXT_INSN (insn)) | |
3066 | if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN | |
3067 | || GET_CODE (insn) == CALL_INSN) | |
3068 | { | |
3069 | purge_addressof_1 (&PATTERN (insn), insn, | |
f7b6d104 RH |
3070 | asm_noperands (PATTERN (insn)) > 0, 0); |
3071 | purge_addressof_1 (®_NOTES (insn), NULL_RTX, 0, 0); | |
e9a25f70 | 3072 | } |
da9b1f9c | 3073 | purge_addressof_replacements = 0; |
e9a25f70 JL |
3074 | } |
3075 | \f | |
6f086dfc RS |
3076 | /* Pass through the INSNS of function FNDECL and convert virtual register |
3077 | references to hard register references. */ | |
3078 | ||
3079 | void | |
3080 | instantiate_virtual_regs (fndecl, insns) | |
3081 | tree fndecl; | |
3082 | rtx insns; | |
3083 | { | |
3084 | rtx insn; | |
e9a25f70 | 3085 | int i; |
6f086dfc RS |
3086 | |
3087 | /* Compute the offsets to use for this function. */ | |
3088 | in_arg_offset = FIRST_PARM_OFFSET (fndecl); | |
3089 | var_offset = STARTING_FRAME_OFFSET; | |
3090 | dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl); | |
3091 | out_arg_offset = STACK_POINTER_OFFSET; | |
71038426 | 3092 | cfa_offset = ARG_POINTER_CFA_OFFSET; |
6f086dfc RS |
3093 | |
3094 | /* Scan all variables and parameters of this function. For each that is | |
3095 | in memory, instantiate all virtual registers if the result is a valid | |
3096 | address. If not, we do it later. That will handle most uses of virtual | |
3097 | regs on many machines. */ | |
3098 | instantiate_decls (fndecl, 1); | |
3099 | ||
3100 | /* Initialize recognition, indicating that volatile is OK. */ | |
3101 | init_recog (); | |
3102 | ||
3103 | /* Scan through all the insns, instantiating every virtual register still | |
3104 | present. */ | |
3105 | for (insn = insns; insn; insn = NEXT_INSN (insn)) | |
3106 | if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN | |
3107 | || GET_CODE (insn) == CALL_INSN) | |
3108 | { | |
3109 | instantiate_virtual_regs_1 (&PATTERN (insn), insn, 1); | |
5f4f0e22 | 3110 | instantiate_virtual_regs_1 (®_NOTES (insn), NULL_RTX, 0); |
6f086dfc RS |
3111 | } |
3112 | ||
e9a25f70 JL |
3113 | /* Instantiate the stack slots for the parm registers, for later use in |
3114 | addressof elimination. */ | |
3115 | for (i = 0; i < max_parm_reg; ++i) | |
3116 | if (parm_reg_stack_loc[i]) | |
3117 | instantiate_virtual_regs_1 (&parm_reg_stack_loc[i], NULL_RTX, 0); | |
3118 | ||
6f086dfc RS |
3119 | /* Now instantiate the remaining register equivalences for debugging info. |
3120 | These will not be valid addresses. */ | |
3121 | instantiate_decls (fndecl, 0); | |
3122 | ||
3123 | /* Indicate that, from now on, assign_stack_local should use | |
3124 | frame_pointer_rtx. */ | |
3125 | virtuals_instantiated = 1; | |
3126 | } | |
3127 | ||
3128 | /* Scan all decls in FNDECL (both variables and parameters) and instantiate | |
3129 | all virtual registers in their DECL_RTL's. | |
3130 | ||
3131 | If VALID_ONLY, do this only if the resulting address is still valid. | |
3132 | Otherwise, always do it. */ | |
3133 | ||
3134 | static void | |
3135 | instantiate_decls (fndecl, valid_only) | |
3136 | tree fndecl; | |
3137 | int valid_only; | |
3138 | { | |
3139 | tree decl; | |
3140 | ||
e1686233 | 3141 | if (DECL_SAVED_INSNS (fndecl)) |
6f086dfc RS |
3142 | /* When compiling an inline function, the obstack used for |
3143 | rtl allocation is the maybepermanent_obstack. Calling | |
3144 | `resume_temporary_allocation' switches us back to that | |
3145 | obstack while we process this function's parameters. */ | |
3146 | resume_temporary_allocation (); | |
3147 | ||
3148 | /* Process all parameters of the function. */ | |
3149 | for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl)) | |
3150 | { | |
e5e809f4 JL |
3151 | HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl)); |
3152 | ||
ce717ce4 JW |
3153 | instantiate_decl (DECL_RTL (decl), size, valid_only); |
3154 | ||
3155 | /* If the parameter was promoted, then the incoming RTL mode may be | |
3156 | larger than the declared type size. We must use the larger of | |
3157 | the two sizes. */ | |
3158 | size = MAX (GET_MODE_SIZE (GET_MODE (DECL_INCOMING_RTL (decl))), size); | |
3159 | instantiate_decl (DECL_INCOMING_RTL (decl), size, valid_only); | |
6f086dfc RS |
3160 | } |
3161 | ||
0f41302f | 3162 | /* Now process all variables defined in the function or its subblocks. */ |
6f086dfc RS |
3163 | instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only); |
3164 | ||
79c0672e | 3165 | if (DECL_INLINE (fndecl) || DECL_DEFER_OUTPUT (fndecl)) |
6f086dfc RS |
3166 | { |
3167 | /* Save all rtl allocated for this function by raising the | |
3168 | high-water mark on the maybepermanent_obstack. */ | |
3169 | preserve_data (); | |
3170 | /* All further rtl allocation is now done in the current_obstack. */ | |
3171 | rtl_in_current_obstack (); | |
3172 | } | |
3173 | } | |
3174 | ||
3175 | /* Subroutine of instantiate_decls: Process all decls in the given | |
3176 | BLOCK node and all its subblocks. */ | |
3177 | ||
3178 | static void | |
3179 | instantiate_decls_1 (let, valid_only) | |
3180 | tree let; | |
3181 | int valid_only; | |
3182 | { | |
3183 | tree t; | |
3184 | ||
3185 | for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t)) | |
5a73491b RK |
3186 | instantiate_decl (DECL_RTL (t), int_size_in_bytes (TREE_TYPE (t)), |
3187 | valid_only); | |
6f086dfc RS |
3188 | |
3189 | /* Process all subblocks. */ | |
3190 | for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t)) | |
3191 | instantiate_decls_1 (t, valid_only); | |
3192 | } | |
5a73491b | 3193 | |
8008b228 | 3194 | /* Subroutine of the preceding procedures: Given RTL representing a |
5a73491b RK |
3195 | decl and the size of the object, do any instantiation required. |
3196 | ||
3197 | If VALID_ONLY is non-zero, it means that the RTL should only be | |
3198 | changed if the new address is valid. */ | |
3199 | ||
3200 | static void | |
3201 | instantiate_decl (x, size, valid_only) | |
3202 | rtx x; | |
3203 | int size; | |
3204 | int valid_only; | |
3205 | { | |
3206 | enum machine_mode mode; | |
3207 | rtx addr; | |
3208 | ||
3209 | /* If this is not a MEM, no need to do anything. Similarly if the | |
3210 | address is a constant or a register that is not a virtual register. */ | |
3211 | ||
3212 | if (x == 0 || GET_CODE (x) != MEM) | |
3213 | return; | |
3214 | ||
3215 | addr = XEXP (x, 0); | |
3216 | if (CONSTANT_P (addr) | |
956d6950 | 3217 | || (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == REG) |
5a73491b RK |
3218 | || (GET_CODE (addr) == REG |
3219 | && (REGNO (addr) < FIRST_VIRTUAL_REGISTER | |
3220 | || REGNO (addr) > LAST_VIRTUAL_REGISTER))) | |
3221 | return; | |
3222 | ||
3223 | /* If we should only do this if the address is valid, copy the address. | |
3224 | We need to do this so we can undo any changes that might make the | |
3225 | address invalid. This copy is unfortunate, but probably can't be | |
3226 | avoided. */ | |
3227 | ||
3228 | if (valid_only) | |
3229 | addr = copy_rtx (addr); | |
3230 | ||
3231 | instantiate_virtual_regs_1 (&addr, NULL_RTX, 0); | |
3232 | ||
87ce34d6 JW |
3233 | if (valid_only) |
3234 | { | |
3235 | /* Now verify that the resulting address is valid for every integer or | |
3236 | floating-point mode up to and including SIZE bytes long. We do this | |
3237 | since the object might be accessed in any mode and frame addresses | |
3238 | are shared. */ | |
3239 | ||
3240 | for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); | |
3241 | mode != VOIDmode && GET_MODE_SIZE (mode) <= size; | |
3242 | mode = GET_MODE_WIDER_MODE (mode)) | |
3243 | if (! memory_address_p (mode, addr)) | |
3244 | return; | |
5a73491b | 3245 | |
87ce34d6 JW |
3246 | for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); |
3247 | mode != VOIDmode && GET_MODE_SIZE (mode) <= size; | |
3248 | mode = GET_MODE_WIDER_MODE (mode)) | |
3249 | if (! memory_address_p (mode, addr)) | |
3250 | return; | |
3251 | } | |
5a73491b | 3252 | |
87ce34d6 JW |
3253 | /* Put back the address now that we have updated it and we either know |
3254 | it is valid or we don't care whether it is valid. */ | |
5a73491b RK |
3255 | |
3256 | XEXP (x, 0) = addr; | |
3257 | } | |
6f086dfc RS |
3258 | \f |
3259 | /* Given a pointer to a piece of rtx and an optional pointer to the | |
3260 | containing object, instantiate any virtual registers present in it. | |
3261 | ||
3262 | If EXTRA_INSNS, we always do the replacement and generate | |
3263 | any extra insns before OBJECT. If it zero, we do nothing if replacement | |
3264 | is not valid. | |
3265 | ||
3266 | Return 1 if we either had nothing to do or if we were able to do the | |
3267 | needed replacement. Return 0 otherwise; we only return zero if | |
3268 | EXTRA_INSNS is zero. | |
3269 | ||
3270 | We first try some simple transformations to avoid the creation of extra | |
3271 | pseudos. */ | |
3272 | ||
3273 | static int | |
3274 | instantiate_virtual_regs_1 (loc, object, extra_insns) | |
3275 | rtx *loc; | |
3276 | rtx object; | |
3277 | int extra_insns; | |
3278 | { | |
3279 | rtx x; | |
3280 | RTX_CODE code; | |
3281 | rtx new = 0; | |
e5e809f4 | 3282 | HOST_WIDE_INT offset; |
6f086dfc RS |
3283 | rtx temp; |
3284 | rtx seq; | |
3285 | int i, j; | |
3286 | char *fmt; | |
3287 | ||
3288 | /* Re-start here to avoid recursion in common cases. */ | |
3289 | restart: | |
3290 | ||
3291 | x = *loc; | |
3292 | if (x == 0) | |
3293 | return 1; | |
3294 | ||
3295 | code = GET_CODE (x); | |
3296 | ||
3297 | /* Check for some special cases. */ | |
3298 | switch (code) | |
3299 | { | |
3300 | case CONST_INT: | |
3301 | case CONST_DOUBLE: | |
3302 | case CONST: | |
3303 | case SYMBOL_REF: | |
3304 | case CODE_LABEL: | |
3305 | case PC: | |
3306 | case CC0: | |
3307 | case ASM_INPUT: | |
3308 | case ADDR_VEC: | |
3309 | case ADDR_DIFF_VEC: | |
3310 | case RETURN: | |
3311 | return 1; | |
3312 | ||
3313 | case SET: | |
3314 | /* We are allowed to set the virtual registers. This means that | |
38e01259 | 3315 | the actual register should receive the source minus the |
6f086dfc RS |
3316 | appropriate offset. This is used, for example, in the handling |
3317 | of non-local gotos. */ | |
3318 | if (SET_DEST (x) == virtual_incoming_args_rtx) | |
3319 | new = arg_pointer_rtx, offset = - in_arg_offset; | |
3320 | else if (SET_DEST (x) == virtual_stack_vars_rtx) | |
dfd3dae6 | 3321 | new = frame_pointer_rtx, offset = - var_offset; |
6f086dfc RS |
3322 | else if (SET_DEST (x) == virtual_stack_dynamic_rtx) |
3323 | new = stack_pointer_rtx, offset = - dynamic_offset; | |
3324 | else if (SET_DEST (x) == virtual_outgoing_args_rtx) | |
3325 | new = stack_pointer_rtx, offset = - out_arg_offset; | |
71038426 RH |
3326 | else if (SET_DEST (x) == virtual_cfa_rtx) |
3327 | new = arg_pointer_rtx, offset = - cfa_offset; | |
6f086dfc RS |
3328 | |
3329 | if (new) | |
3330 | { | |
3331 | /* The only valid sources here are PLUS or REG. Just do | |
3332 | the simplest possible thing to handle them. */ | |
3333 | if (GET_CODE (SET_SRC (x)) != REG | |
3334 | && GET_CODE (SET_SRC (x)) != PLUS) | |
3335 | abort (); | |
3336 | ||
3337 | start_sequence (); | |
3338 | if (GET_CODE (SET_SRC (x)) != REG) | |
5f4f0e22 | 3339 | temp = force_operand (SET_SRC (x), NULL_RTX); |
6f086dfc RS |
3340 | else |
3341 | temp = SET_SRC (x); | |
5f4f0e22 | 3342 | temp = force_operand (plus_constant (temp, offset), NULL_RTX); |
6f086dfc RS |
3343 | seq = get_insns (); |
3344 | end_sequence (); | |
3345 | ||
3346 | emit_insns_before (seq, object); | |
3347 | SET_DEST (x) = new; | |
3348 | ||
e9a25f70 | 3349 | if (! validate_change (object, &SET_SRC (x), temp, 0) |
6f086dfc RS |
3350 | || ! extra_insns) |
3351 | abort (); | |
3352 | ||
3353 | return 1; | |
3354 | } | |
3355 | ||
3356 | instantiate_virtual_regs_1 (&SET_DEST (x), object, extra_insns); | |
3357 | loc = &SET_SRC (x); | |
3358 | goto restart; | |
3359 | ||
3360 | case PLUS: | |
3361 | /* Handle special case of virtual register plus constant. */ | |
3362 | if (CONSTANT_P (XEXP (x, 1))) | |
3363 | { | |
b1f82ccf | 3364 | rtx old, new_offset; |
6f086dfc RS |
3365 | |
3366 | /* Check for (plus (plus VIRT foo) (const_int)) first. */ | |
3367 | if (GET_CODE (XEXP (x, 0)) == PLUS) | |
3368 | { | |
3369 | rtx inner = XEXP (XEXP (x, 0), 0); | |
3370 | ||
3371 | if (inner == virtual_incoming_args_rtx) | |
3372 | new = arg_pointer_rtx, offset = in_arg_offset; | |
3373 | else if (inner == virtual_stack_vars_rtx) | |
3374 | new = frame_pointer_rtx, offset = var_offset; | |
3375 | else if (inner == virtual_stack_dynamic_rtx) | |
3376 | new = stack_pointer_rtx, offset = dynamic_offset; | |
3377 | else if (inner == virtual_outgoing_args_rtx) | |
3378 | new = stack_pointer_rtx, offset = out_arg_offset; | |
71038426 RH |
3379 | else if (inner == virtual_cfa_rtx) |
3380 | new = arg_pointer_rtx, offset = cfa_offset; | |
6f086dfc RS |
3381 | else |
3382 | { | |
3383 | loc = &XEXP (x, 0); | |
3384 | goto restart; | |
3385 | } | |
3386 | ||
3387 | instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object, | |
3388 | extra_insns); | |
38a448ca | 3389 | new = gen_rtx_PLUS (Pmode, new, XEXP (XEXP (x, 0), 1)); |
6f086dfc RS |
3390 | } |
3391 | ||
3392 | else if (XEXP (x, 0) == virtual_incoming_args_rtx) | |
3393 | new = arg_pointer_rtx, offset = in_arg_offset; | |
3394 | else if (XEXP (x, 0) == virtual_stack_vars_rtx) | |
3395 | new = frame_pointer_rtx, offset = var_offset; | |
3396 | else if (XEXP (x, 0) == virtual_stack_dynamic_rtx) | |
3397 | new = stack_pointer_rtx, offset = dynamic_offset; | |
3398 | else if (XEXP (x, 0) == virtual_outgoing_args_rtx) | |
3399 | new = stack_pointer_rtx, offset = out_arg_offset; | |
71038426 RH |
3400 | else if (XEXP (x, 0) == virtual_cfa_rtx) |
3401 | new = arg_pointer_rtx, offset = cfa_offset; | |
6f086dfc RS |
3402 | else |
3403 | { | |
3404 | /* We know the second operand is a constant. Unless the | |
3405 | first operand is a REG (which has been already checked), | |
3406 | it needs to be checked. */ | |
3407 | if (GET_CODE (XEXP (x, 0)) != REG) | |
3408 | { | |
3409 | loc = &XEXP (x, 0); | |
3410 | goto restart; | |
3411 | } | |
3412 | return 1; | |
3413 | } | |
3414 | ||
b1f82ccf | 3415 | new_offset = plus_constant (XEXP (x, 1), offset); |
6f086dfc | 3416 | |
b1f82ccf DE |
3417 | /* If the new constant is zero, try to replace the sum with just |
3418 | the register. */ | |
3419 | if (new_offset == const0_rtx | |
3420 | && validate_change (object, loc, new, 0)) | |
6f086dfc RS |
3421 | return 1; |
3422 | ||
b1f82ccf DE |
3423 | /* Next try to replace the register and new offset. |
3424 | There are two changes to validate here and we can't assume that | |
3425 | in the case of old offset equals new just changing the register | |
3426 | will yield a valid insn. In the interests of a little efficiency, | |
3427 | however, we only call validate change once (we don't queue up the | |
0f41302f | 3428 | changes and then call apply_change_group). */ |
b1f82ccf DE |
3429 | |
3430 | old = XEXP (x, 0); | |
3431 | if (offset == 0 | |
3432 | ? ! validate_change (object, &XEXP (x, 0), new, 0) | |
3433 | : (XEXP (x, 0) = new, | |
3434 | ! validate_change (object, &XEXP (x, 1), new_offset, 0))) | |
6f086dfc RS |
3435 | { |
3436 | if (! extra_insns) | |
3437 | { | |
3438 | XEXP (x, 0) = old; | |
3439 | return 0; | |
3440 | } | |
3441 | ||
3442 | /* Otherwise copy the new constant into a register and replace | |
3443 | constant with that register. */ | |
3444 | temp = gen_reg_rtx (Pmode); | |
b1f82ccf | 3445 | XEXP (x, 0) = new; |
6f086dfc | 3446 | if (validate_change (object, &XEXP (x, 1), temp, 0)) |
b1f82ccf | 3447 | emit_insn_before (gen_move_insn (temp, new_offset), object); |
6f086dfc RS |
3448 | else |
3449 | { | |
3450 | /* If that didn't work, replace this expression with a | |
3451 | register containing the sum. */ | |
3452 | ||
6f086dfc | 3453 | XEXP (x, 0) = old; |
38a448ca | 3454 | new = gen_rtx_PLUS (Pmode, new, new_offset); |
6f086dfc RS |
3455 | |
3456 | start_sequence (); | |
5f4f0e22 | 3457 | temp = force_operand (new, NULL_RTX); |
6f086dfc RS |
3458 | seq = get_insns (); |
3459 | end_sequence (); | |
3460 | ||
3461 | emit_insns_before (seq, object); | |
3462 | if (! validate_change (object, loc, temp, 0) | |
3463 | && ! validate_replace_rtx (x, temp, object)) | |
3464 | abort (); | |
3465 | } | |
3466 | } | |
3467 | ||
3468 | return 1; | |
3469 | } | |
3470 | ||
3471 | /* Fall through to generic two-operand expression case. */ | |
3472 | case EXPR_LIST: | |
3473 | case CALL: | |
3474 | case COMPARE: | |
3475 | case MINUS: | |
3476 | case MULT: | |
3477 | case DIV: case UDIV: | |
3478 | case MOD: case UMOD: | |
3479 | case AND: case IOR: case XOR: | |
45620ed4 RK |
3480 | case ROTATERT: case ROTATE: |
3481 | case ASHIFTRT: case LSHIFTRT: case ASHIFT: | |
6f086dfc RS |
3482 | case NE: case EQ: |
3483 | case GE: case GT: case GEU: case GTU: | |
3484 | case LE: case LT: case LEU: case LTU: | |
3485 | if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1))) | |
3486 | instantiate_virtual_regs_1 (&XEXP (x, 1), object, extra_insns); | |
3487 | loc = &XEXP (x, 0); | |
3488 | goto restart; | |
3489 | ||
3490 | case MEM: | |
3491 | /* Most cases of MEM that convert to valid addresses have already been | |
4fd796bb | 3492 | handled by our scan of decls. The only special handling we |
6f086dfc | 3493 | need here is to make a copy of the rtx to ensure it isn't being |
b335c2cc | 3494 | shared if we have to change it to a pseudo. |
6f086dfc RS |
3495 | |
3496 | If the rtx is a simple reference to an address via a virtual register, | |
3497 | it can potentially be shared. In such cases, first try to make it | |
3498 | a valid address, which can also be shared. Otherwise, copy it and | |
3499 | proceed normally. | |
3500 | ||
3501 | First check for common cases that need no processing. These are | |
3502 | usually due to instantiation already being done on a previous instance | |
3503 | of a shared rtx. */ | |
3504 | ||
3505 | temp = XEXP (x, 0); | |
3506 | if (CONSTANT_ADDRESS_P (temp) | |
3507 | #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM | |
3508 | || temp == arg_pointer_rtx | |
b37f453b DE |
3509 | #endif |
3510 | #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM | |
3511 | || temp == hard_frame_pointer_rtx | |
6f086dfc RS |
3512 | #endif |
3513 | || temp == frame_pointer_rtx) | |
3514 | return 1; | |
3515 | ||
3516 | if (GET_CODE (temp) == PLUS | |
3517 | && CONSTANT_ADDRESS_P (XEXP (temp, 1)) | |
3518 | && (XEXP (temp, 0) == frame_pointer_rtx | |
b37f453b DE |
3519 | #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM |
3520 | || XEXP (temp, 0) == hard_frame_pointer_rtx | |
3521 | #endif | |
6f086dfc RS |
3522 | #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM |
3523 | || XEXP (temp, 0) == arg_pointer_rtx | |
3524 | #endif | |
3525 | )) | |
3526 | return 1; | |
3527 | ||
3528 | if (temp == virtual_stack_vars_rtx | |
3529 | || temp == virtual_incoming_args_rtx | |
3530 | || (GET_CODE (temp) == PLUS | |
3531 | && CONSTANT_ADDRESS_P (XEXP (temp, 1)) | |
3532 | && (XEXP (temp, 0) == virtual_stack_vars_rtx | |
3533 | || XEXP (temp, 0) == virtual_incoming_args_rtx))) | |
3534 | { | |
3535 | /* This MEM may be shared. If the substitution can be done without | |
3536 | the need to generate new pseudos, we want to do it in place | |
3537 | so all copies of the shared rtx benefit. The call below will | |
3538 | only make substitutions if the resulting address is still | |
3539 | valid. | |
3540 | ||
3541 | Note that we cannot pass X as the object in the recursive call | |
3542 | since the insn being processed may not allow all valid | |
6461be14 RS |
3543 | addresses. However, if we were not passed on object, we can |
3544 | only modify X without copying it if X will have a valid | |
3545 | address. | |
6f086dfc | 3546 | |
6461be14 RS |
3547 | ??? Also note that this can still lose if OBJECT is an insn that |
3548 | has less restrictions on an address that some other insn. | |
3549 | In that case, we will modify the shared address. This case | |
4fd796bb RK |
3550 | doesn't seem very likely, though. One case where this could |
3551 | happen is in the case of a USE or CLOBBER reference, but we | |
3552 | take care of that below. */ | |
6461be14 RS |
3553 | |
3554 | if (instantiate_virtual_regs_1 (&XEXP (x, 0), | |
3555 | object ? object : x, 0)) | |
6f086dfc RS |
3556 | return 1; |
3557 | ||
3558 | /* Otherwise make a copy and process that copy. We copy the entire | |
3559 | RTL expression since it might be a PLUS which could also be | |
3560 | shared. */ | |
3561 | *loc = x = copy_rtx (x); | |
3562 | } | |
3563 | ||
3564 | /* Fall through to generic unary operation case. */ | |
6f086dfc RS |
3565 | case SUBREG: |
3566 | case STRICT_LOW_PART: | |
3567 | case NEG: case NOT: | |
3568 | case PRE_DEC: case PRE_INC: case POST_DEC: case POST_INC: | |
3569 | case SIGN_EXTEND: case ZERO_EXTEND: | |
3570 | case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE: | |
3571 | case FLOAT: case FIX: | |
3572 | case UNSIGNED_FIX: case UNSIGNED_FLOAT: | |
3573 | case ABS: | |
3574 | case SQRT: | |
3575 | case FFS: | |
3576 | /* These case either have just one operand or we know that we need not | |
3577 | check the rest of the operands. */ | |
3578 | loc = &XEXP (x, 0); | |
3579 | goto restart; | |
3580 | ||
4fd796bb RK |
3581 | case USE: |
3582 | case CLOBBER: | |
3583 | /* If the operand is a MEM, see if the change is a valid MEM. If not, | |
3584 | go ahead and make the invalid one, but do it to a copy. For a REG, | |
3585 | just make the recursive call, since there's no chance of a problem. */ | |
3586 | ||
3587 | if ((GET_CODE (XEXP (x, 0)) == MEM | |
3588 | && instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), XEXP (x, 0), | |
3589 | 0)) | |
3590 | || (GET_CODE (XEXP (x, 0)) == REG | |
7694ce35 | 3591 | && instantiate_virtual_regs_1 (&XEXP (x, 0), object, 0))) |
4fd796bb RK |
3592 | return 1; |
3593 | ||
3594 | XEXP (x, 0) = copy_rtx (XEXP (x, 0)); | |
3595 | loc = &XEXP (x, 0); | |
3596 | goto restart; | |
3597 | ||
6f086dfc RS |
3598 | case REG: |
3599 | /* Try to replace with a PLUS. If that doesn't work, compute the sum | |
3600 | in front of this insn and substitute the temporary. */ | |
3601 | if (x == virtual_incoming_args_rtx) | |
3602 | new = arg_pointer_rtx, offset = in_arg_offset; | |
3603 | else if (x == virtual_stack_vars_rtx) | |
3604 | new = frame_pointer_rtx, offset = var_offset; | |
3605 | else if (x == virtual_stack_dynamic_rtx) | |
3606 | new = stack_pointer_rtx, offset = dynamic_offset; | |
3607 | else if (x == virtual_outgoing_args_rtx) | |
3608 | new = stack_pointer_rtx, offset = out_arg_offset; | |
71038426 RH |
3609 | else if (x == virtual_cfa_rtx) |
3610 | new = arg_pointer_rtx, offset = cfa_offset; | |
6f086dfc RS |
3611 | |
3612 | if (new) | |
3613 | { | |
3614 | temp = plus_constant (new, offset); | |
3615 | if (!validate_change (object, loc, temp, 0)) | |
3616 | { | |
3617 | if (! extra_insns) | |
3618 | return 0; | |
3619 | ||
3620 | start_sequence (); | |
5f4f0e22 | 3621 | temp = force_operand (temp, NULL_RTX); |
6f086dfc RS |
3622 | seq = get_insns (); |
3623 | end_sequence (); | |
3624 | ||
3625 | emit_insns_before (seq, object); | |
3626 | if (! validate_change (object, loc, temp, 0) | |
3627 | && ! validate_replace_rtx (x, temp, object)) | |
3628 | abort (); | |
3629 | } | |
3630 | } | |
3631 | ||
3632 | return 1; | |
e9a25f70 JL |
3633 | |
3634 | case ADDRESSOF: | |
3635 | if (GET_CODE (XEXP (x, 0)) == REG) | |
3636 | return 1; | |
3637 | ||
3638 | else if (GET_CODE (XEXP (x, 0)) == MEM) | |
3639 | { | |
3640 | /* If we have a (addressof (mem ..)), do any instantiation inside | |
3641 | since we know we'll be making the inside valid when we finally | |
3642 | remove the ADDRESSOF. */ | |
3643 | instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), NULL_RTX, 0); | |
3644 | return 1; | |
3645 | } | |
3646 | break; | |
3647 | ||
3648 | default: | |
3649 | break; | |
6f086dfc RS |
3650 | } |
3651 | ||
3652 | /* Scan all subexpressions. */ | |
3653 | fmt = GET_RTX_FORMAT (code); | |
3654 | for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++) | |
3655 | if (*fmt == 'e') | |
3656 | { | |
3657 | if (!instantiate_virtual_regs_1 (&XEXP (x, i), object, extra_insns)) | |
3658 | return 0; | |
3659 | } | |
3660 | else if (*fmt == 'E') | |
3661 | for (j = 0; j < XVECLEN (x, i); j++) | |
3662 | if (! instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object, | |
3663 | extra_insns)) | |
3664 | return 0; | |
3665 | ||
3666 | return 1; | |
3667 | } | |
3668 | \f | |
3669 | /* Optimization: assuming this function does not receive nonlocal gotos, | |
3670 | delete the handlers for such, as well as the insns to establish | |
3671 | and disestablish them. */ | |
3672 | ||
3673 | static void | |
3674 | delete_handlers () | |
3675 | { | |
3676 | rtx insn; | |
3677 | for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) | |
3678 | { | |
3679 | /* Delete the handler by turning off the flag that would | |
3680 | prevent jump_optimize from deleting it. | |
3681 | Also permit deletion of the nonlocal labels themselves | |
3682 | if nothing local refers to them. */ | |
3683 | if (GET_CODE (insn) == CODE_LABEL) | |
71cd4a8d JW |
3684 | { |
3685 | tree t, last_t; | |
3686 | ||
3687 | LABEL_PRESERVE_P (insn) = 0; | |
3688 | ||
3689 | /* Remove it from the nonlocal_label list, to avoid confusing | |
3690 | flow. */ | |
3691 | for (t = nonlocal_labels, last_t = 0; t; | |
3692 | last_t = t, t = TREE_CHAIN (t)) | |
3693 | if (DECL_RTL (TREE_VALUE (t)) == insn) | |
3694 | break; | |
3695 | if (t) | |
3696 | { | |
3697 | if (! last_t) | |
3698 | nonlocal_labels = TREE_CHAIN (nonlocal_labels); | |
3699 | else | |
3700 | TREE_CHAIN (last_t) = TREE_CHAIN (t); | |
3701 | } | |
3702 | } | |
ba716ac9 BS |
3703 | if (GET_CODE (insn) == INSN) |
3704 | { | |
3705 | int can_delete = 0; | |
3706 | rtx t; | |
3707 | for (t = nonlocal_goto_handler_slots; t != 0; t = XEXP (t, 1)) | |
3708 | if (reg_mentioned_p (t, PATTERN (insn))) | |
3709 | { | |
3710 | can_delete = 1; | |
3711 | break; | |
3712 | } | |
3713 | if (can_delete | |
59257ff7 RK |
3714 | || (nonlocal_goto_stack_level != 0 |
3715 | && reg_mentioned_p (nonlocal_goto_stack_level, | |
ba716ac9 BS |
3716 | PATTERN (insn)))) |
3717 | delete_insn (insn); | |
3718 | } | |
6f086dfc RS |
3719 | } |
3720 | } | |
3721 | ||
3722 | /* Return a list (chain of EXPR_LIST nodes) for the nonlocal labels | |
3723 | of the current function. */ | |
3724 | ||
3725 | rtx | |
3726 | nonlocal_label_rtx_list () | |
3727 | { | |
3728 | tree t; | |
3729 | rtx x = 0; | |
3730 | ||
3731 | for (t = nonlocal_labels; t; t = TREE_CHAIN (t)) | |
38a448ca | 3732 | x = gen_rtx_EXPR_LIST (VOIDmode, label_rtx (TREE_VALUE (t)), x); |
6f086dfc RS |
3733 | |
3734 | return x; | |
3735 | } | |
3736 | \f | |
3737 | /* Output a USE for any register use in RTL. | |
3738 | This is used with -noreg to mark the extent of lifespan | |
3739 | of any registers used in a user-visible variable's DECL_RTL. */ | |
3740 | ||
3741 | void | |
3742 | use_variable (rtl) | |
3743 | rtx rtl; | |
3744 | { | |
3745 | if (GET_CODE (rtl) == REG) | |
3746 | /* This is a register variable. */ | |
38a448ca | 3747 | emit_insn (gen_rtx_USE (VOIDmode, rtl)); |
6f086dfc RS |
3748 | else if (GET_CODE (rtl) == MEM |
3749 | && GET_CODE (XEXP (rtl, 0)) == REG | |
3750 | && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER | |
3751 | || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER) | |
3752 | && XEXP (rtl, 0) != current_function_internal_arg_pointer) | |
3753 | /* This is a variable-sized structure. */ | |
38a448ca | 3754 | emit_insn (gen_rtx_USE (VOIDmode, XEXP (rtl, 0))); |
6f086dfc RS |
3755 | } |
3756 | ||
3757 | /* Like use_variable except that it outputs the USEs after INSN | |
3758 | instead of at the end of the insn-chain. */ | |
3759 | ||
3760 | void | |
3761 | use_variable_after (rtl, insn) | |
3762 | rtx rtl, insn; | |
3763 | { | |
3764 | if (GET_CODE (rtl) == REG) | |
3765 | /* This is a register variable. */ | |
38a448ca | 3766 | emit_insn_after (gen_rtx_USE (VOIDmode, rtl), insn); |
6f086dfc RS |
3767 | else if (GET_CODE (rtl) == MEM |
3768 | && GET_CODE (XEXP (rtl, 0)) == REG | |
3769 | && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER | |
3770 | || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER) | |
3771 | && XEXP (rtl, 0) != current_function_internal_arg_pointer) | |
3772 | /* This is a variable-sized structure. */ | |
38a448ca | 3773 | emit_insn_after (gen_rtx_USE (VOIDmode, XEXP (rtl, 0)), insn); |
6f086dfc RS |
3774 | } |
3775 | \f | |
3776 | int | |
3777 | max_parm_reg_num () | |
3778 | { | |
3779 | return max_parm_reg; | |
3780 | } | |
3781 | ||
3782 | /* Return the first insn following those generated by `assign_parms'. */ | |
3783 | ||
3784 | rtx | |
3785 | get_first_nonparm_insn () | |
3786 | { | |
3787 | if (last_parm_insn) | |
3788 | return NEXT_INSN (last_parm_insn); | |
3789 | return get_insns (); | |
3790 | } | |
3791 | ||
5378192b RS |
3792 | /* Return the first NOTE_INSN_BLOCK_BEG note in the function. |
3793 | Crash if there is none. */ | |
3794 | ||
3795 | rtx | |
3796 | get_first_block_beg () | |
3797 | { | |
3798 | register rtx searcher; | |
3799 | register rtx insn = get_first_nonparm_insn (); | |
3800 | ||
3801 | for (searcher = insn; searcher; searcher = NEXT_INSN (searcher)) | |
3802 | if (GET_CODE (searcher) == NOTE | |
3803 | && NOTE_LINE_NUMBER (searcher) == NOTE_INSN_BLOCK_BEG) | |
3804 | return searcher; | |
3805 | ||
3806 | abort (); /* Invalid call to this function. (See comments above.) */ | |
3807 | return NULL_RTX; | |
3808 | } | |
3809 | ||
d181c154 RS |
3810 | /* Return 1 if EXP is an aggregate type (or a value with aggregate type). |
3811 | This means a type for which function calls must pass an address to the | |
3812 | function or get an address back from the function. | |
3813 | EXP may be a type node or an expression (whose type is tested). */ | |
6f086dfc RS |
3814 | |
3815 | int | |
3816 | aggregate_value_p (exp) | |
3817 | tree exp; | |
3818 | { | |
9d790a4f RS |
3819 | int i, regno, nregs; |
3820 | rtx reg; | |
d181c154 RS |
3821 | tree type; |
3822 | if (TREE_CODE_CLASS (TREE_CODE (exp)) == 't') | |
3823 | type = exp; | |
3824 | else | |
3825 | type = TREE_TYPE (exp); | |
3826 | ||
3827 | if (RETURN_IN_MEMORY (type)) | |
6f086dfc | 3828 | return 1; |
956d6950 | 3829 | /* Types that are TREE_ADDRESSABLE must be constructed in memory, |
49a2e5b2 DE |
3830 | and thus can't be returned in registers. */ |
3831 | if (TREE_ADDRESSABLE (type)) | |
3832 | return 1; | |
05e3bdb9 | 3833 | if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type)) |
6f086dfc | 3834 | return 1; |
9d790a4f RS |
3835 | /* Make sure we have suitable call-clobbered regs to return |
3836 | the value in; if not, we must return it in memory. */ | |
d181c154 | 3837 | reg = hard_function_value (type, 0); |
e71f7aa5 JW |
3838 | |
3839 | /* If we have something other than a REG (e.g. a PARALLEL), then assume | |
3840 | it is OK. */ | |
3841 | if (GET_CODE (reg) != REG) | |
3842 | return 0; | |
3843 | ||
9d790a4f | 3844 | regno = REGNO (reg); |
d181c154 | 3845 | nregs = HARD_REGNO_NREGS (regno, TYPE_MODE (type)); |
9d790a4f RS |
3846 | for (i = 0; i < nregs; i++) |
3847 | if (! call_used_regs[regno + i]) | |
3848 | return 1; | |
6f086dfc RS |
3849 | return 0; |
3850 | } | |
3851 | \f | |
3852 | /* Assign RTL expressions to the function's parameters. | |
3853 | This may involve copying them into registers and using | |
3854 | those registers as the RTL for them. | |
3855 | ||
3856 | If SECOND_TIME is non-zero it means that this function is being | |
3857 | called a second time. This is done by integrate.c when a function's | |
3858 | compilation is deferred. We need to come back here in case the | |
3859 | FUNCTION_ARG macro computes items needed for the rest of the compilation | |
3860 | (such as changing which registers are fixed or caller-saved). But suppress | |
3861 | writing any insns or setting DECL_RTL of anything in this case. */ | |
3862 | ||
3863 | void | |
3864 | assign_parms (fndecl, second_time) | |
3865 | tree fndecl; | |
3866 | int second_time; | |
3867 | { | |
3868 | register tree parm; | |
3869 | register rtx entry_parm = 0; | |
3870 | register rtx stack_parm = 0; | |
3871 | CUMULATIVE_ARGS args_so_far; | |
621061f4 RK |
3872 | enum machine_mode promoted_mode, passed_mode; |
3873 | enum machine_mode nominal_mode, promoted_nominal_mode; | |
00d8a4c1 | 3874 | int unsignedp; |
6f086dfc RS |
3875 | /* Total space needed so far for args on the stack, |
3876 | given as a constant and a tree-expression. */ | |
3877 | struct args_size stack_args_size; | |
3878 | tree fntype = TREE_TYPE (fndecl); | |
3879 | tree fnargs = DECL_ARGUMENTS (fndecl); | |
3880 | /* This is used for the arg pointer when referring to stack args. */ | |
3881 | rtx internal_arg_pointer; | |
3882 | /* This is a dummy PARM_DECL that we used for the function result if | |
3883 | the function returns a structure. */ | |
3884 | tree function_result_decl = 0; | |
6f086dfc | 3885 | int varargs_setup = 0; |
3412b298 | 3886 | rtx conversion_insns = 0; |
6f086dfc RS |
3887 | |
3888 | /* Nonzero if the last arg is named `__builtin_va_alist', | |
3889 | which is used on some machines for old-fashioned non-ANSI varargs.h; | |
3890 | this should be stuck onto the stack as if it had arrived there. */ | |
3b69d50e RK |
3891 | int hide_last_arg |
3892 | = (current_function_varargs | |
3893 | && fnargs | |
6f086dfc RS |
3894 | && (parm = tree_last (fnargs)) != 0 |
3895 | && DECL_NAME (parm) | |
3896 | && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)), | |
3897 | "__builtin_va_alist"))); | |
3898 | ||
3899 | /* Nonzero if function takes extra anonymous args. | |
3900 | This means the last named arg must be on the stack | |
0f41302f | 3901 | right before the anonymous ones. */ |
6f086dfc RS |
3902 | int stdarg |
3903 | = (TYPE_ARG_TYPES (fntype) != 0 | |
3904 | && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype))) | |
3905 | != void_type_node)); | |
3906 | ||
ebb904cb RK |
3907 | current_function_stdarg = stdarg; |
3908 | ||
6f086dfc RS |
3909 | /* If the reg that the virtual arg pointer will be translated into is |
3910 | not a fixed reg or is the stack pointer, make a copy of the virtual | |
3911 | arg pointer, and address parms via the copy. The frame pointer is | |
3912 | considered fixed even though it is not marked as such. | |
3913 | ||
3914 | The second time through, simply use ap to avoid generating rtx. */ | |
3915 | ||
3916 | if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM | |
3917 | || ! (fixed_regs[ARG_POINTER_REGNUM] | |
3918 | || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM)) | |
3919 | && ! second_time) | |
3920 | internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx); | |
3921 | else | |
3922 | internal_arg_pointer = virtual_incoming_args_rtx; | |
3923 | current_function_internal_arg_pointer = internal_arg_pointer; | |
3924 | ||
3925 | stack_args_size.constant = 0; | |
3926 | stack_args_size.var = 0; | |
3927 | ||
3928 | /* If struct value address is treated as the first argument, make it so. */ | |
3929 | if (aggregate_value_p (DECL_RESULT (fndecl)) | |
3930 | && ! current_function_returns_pcc_struct | |
3931 | && struct_value_incoming_rtx == 0) | |
3932 | { | |
f9f29478 | 3933 | tree type = build_pointer_type (TREE_TYPE (fntype)); |
6f086dfc | 3934 | |
5f4f0e22 | 3935 | function_result_decl = build_decl (PARM_DECL, NULL_TREE, type); |
6f086dfc RS |
3936 | |
3937 | DECL_ARG_TYPE (function_result_decl) = type; | |
3938 | TREE_CHAIN (function_result_decl) = fnargs; | |
3939 | fnargs = function_result_decl; | |
3940 | } | |
3941 | ||
e9a25f70 JL |
3942 | max_parm_reg = LAST_VIRTUAL_REGISTER + 1; |
3943 | parm_reg_stack_loc = (rtx *) savealloc (max_parm_reg * sizeof (rtx)); | |
3944 | bzero ((char *) parm_reg_stack_loc, max_parm_reg * sizeof (rtx)); | |
6f086dfc RS |
3945 | |
3946 | #ifdef INIT_CUMULATIVE_INCOMING_ARGS | |
ea0d4c4b | 3947 | INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, NULL_RTX); |
6f086dfc | 3948 | #else |
2c7ee1a6 | 3949 | INIT_CUMULATIVE_ARGS (args_so_far, fntype, NULL_RTX, 0); |
6f086dfc RS |
3950 | #endif |
3951 | ||
3952 | /* We haven't yet found an argument that we must push and pretend the | |
3953 | caller did. */ | |
3954 | current_function_pretend_args_size = 0; | |
3955 | ||
3956 | for (parm = fnargs; parm; parm = TREE_CHAIN (parm)) | |
3957 | { | |
05e3bdb9 | 3958 | int aggregate = AGGREGATE_TYPE_P (TREE_TYPE (parm)); |
6f086dfc RS |
3959 | struct args_size stack_offset; |
3960 | struct args_size arg_size; | |
3961 | int passed_pointer = 0; | |
621061f4 | 3962 | int did_conversion = 0; |
6f086dfc | 3963 | tree passed_type = DECL_ARG_TYPE (parm); |
621061f4 | 3964 | tree nominal_type = TREE_TYPE (parm); |
6f086dfc RS |
3965 | |
3966 | /* Set LAST_NAMED if this is last named arg before some | |
bf9c83fe | 3967 | anonymous args. */ |
6f086dfc RS |
3968 | int last_named = ((TREE_CHAIN (parm) == 0 |
3969 | || DECL_NAME (TREE_CHAIN (parm)) == 0) | |
3b69d50e | 3970 | && (stdarg || current_function_varargs)); |
bf9c83fe JW |
3971 | /* Set NAMED_ARG if this arg should be treated as a named arg. For |
3972 | most machines, if this is a varargs/stdarg function, then we treat | |
3973 | the last named arg as if it were anonymous too. */ | |
e5e809f4 | 3974 | int named_arg = STRICT_ARGUMENT_NAMING ? 1 : ! last_named; |
6f086dfc RS |
3975 | |
3976 | if (TREE_TYPE (parm) == error_mark_node | |
3977 | /* This can happen after weird syntax errors | |
3978 | or if an enum type is defined among the parms. */ | |
3979 | || TREE_CODE (parm) != PARM_DECL | |
3980 | || passed_type == NULL) | |
3981 | { | |
38a448ca RH |
3982 | DECL_INCOMING_RTL (parm) = DECL_RTL (parm) |
3983 | = gen_rtx_MEM (BLKmode, const0_rtx); | |
6f086dfc RS |
3984 | TREE_USED (parm) = 1; |
3985 | continue; | |
3986 | } | |
3987 | ||
3988 | /* For varargs.h function, save info about regs and stack space | |
3989 | used by the individual args, not including the va_alist arg. */ | |
3b69d50e | 3990 | if (hide_last_arg && last_named) |
6f086dfc RS |
3991 | current_function_args_info = args_so_far; |
3992 | ||
3993 | /* Find mode of arg as it is passed, and mode of arg | |
3994 | as it should be during execution of this function. */ | |
3995 | passed_mode = TYPE_MODE (passed_type); | |
621061f4 | 3996 | nominal_mode = TYPE_MODE (nominal_type); |
6f086dfc | 3997 | |
16bae307 RS |
3998 | /* If the parm's mode is VOID, its value doesn't matter, |
3999 | and avoid the usual things like emit_move_insn that could crash. */ | |
4000 | if (nominal_mode == VOIDmode) | |
4001 | { | |
4002 | DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = const0_rtx; | |
4003 | continue; | |
4004 | } | |
4005 | ||
3f46679a RK |
4006 | /* If the parm is to be passed as a transparent union, use the |
4007 | type of the first field for the tests below. We have already | |
4008 | verified that the modes are the same. */ | |
4009 | if (DECL_TRANSPARENT_UNION (parm) | |
4010 | || TYPE_TRANSPARENT_UNION (passed_type)) | |
4011 | passed_type = TREE_TYPE (TYPE_FIELDS (passed_type)); | |
4012 | ||
a14ae508 RK |
4013 | /* See if this arg was passed by invisible reference. It is if |
4014 | it is an object whose size depends on the contents of the | |
4015 | object itself or if the machine requires these objects be passed | |
4016 | that way. */ | |
4017 | ||
4018 | if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST | |
4019 | && contains_placeholder_p (TYPE_SIZE (passed_type))) | |
657bb6dc | 4020 | || TREE_ADDRESSABLE (passed_type) |
6f086dfc | 4021 | #ifdef FUNCTION_ARG_PASS_BY_REFERENCE |
a14ae508 | 4022 | || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode, |
bf9c83fe | 4023 | passed_type, named_arg) |
a14ae508 RK |
4024 | #endif |
4025 | ) | |
6f086dfc | 4026 | { |
621061f4 | 4027 | passed_type = nominal_type = build_pointer_type (passed_type); |
6f086dfc RS |
4028 | passed_pointer = 1; |
4029 | passed_mode = nominal_mode = Pmode; | |
4030 | } | |
6f086dfc | 4031 | |
a53e14c0 RK |
4032 | promoted_mode = passed_mode; |
4033 | ||
4034 | #ifdef PROMOTE_FUNCTION_ARGS | |
4035 | /* Compute the mode in which the arg is actually extended to. */ | |
7940255d | 4036 | unsignedp = TREE_UNSIGNED (passed_type); |
a5a52dbc | 4037 | promoted_mode = promote_mode (passed_type, promoted_mode, &unsignedp, 1); |
a53e14c0 RK |
4038 | #endif |
4039 | ||
6f086dfc RS |
4040 | /* Let machine desc say which reg (if any) the parm arrives in. |
4041 | 0 means it arrives on the stack. */ | |
4042 | #ifdef FUNCTION_INCOMING_ARG | |
a53e14c0 | 4043 | entry_parm = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode, |
bf9c83fe | 4044 | passed_type, named_arg); |
6f086dfc | 4045 | #else |
a53e14c0 | 4046 | entry_parm = FUNCTION_ARG (args_so_far, promoted_mode, |
bf9c83fe | 4047 | passed_type, named_arg); |
6f086dfc RS |
4048 | #endif |
4049 | ||
621061f4 RK |
4050 | if (entry_parm == 0) |
4051 | promoted_mode = passed_mode; | |
a53e14c0 | 4052 | |
6f086dfc RS |
4053 | #ifdef SETUP_INCOMING_VARARGS |
4054 | /* If this is the last named parameter, do any required setup for | |
4055 | varargs or stdargs. We need to know about the case of this being an | |
4056 | addressable type, in which case we skip the registers it | |
4057 | would have arrived in. | |
4058 | ||
4059 | For stdargs, LAST_NAMED will be set for two parameters, the one that | |
4060 | is actually the last named, and the dummy parameter. We only | |
4061 | want to do this action once. | |
4062 | ||
4063 | Also, indicate when RTL generation is to be suppressed. */ | |
4064 | if (last_named && !varargs_setup) | |
4065 | { | |
621061f4 | 4066 | SETUP_INCOMING_VARARGS (args_so_far, promoted_mode, passed_type, |
6f086dfc RS |
4067 | current_function_pretend_args_size, |
4068 | second_time); | |
4069 | varargs_setup = 1; | |
4070 | } | |
4071 | #endif | |
4072 | ||
4073 | /* Determine parm's home in the stack, | |
4074 | in case it arrives in the stack or we should pretend it did. | |
4075 | ||
4076 | Compute the stack position and rtx where the argument arrives | |
4077 | and its size. | |
4078 | ||
4079 | There is one complexity here: If this was a parameter that would | |
4080 | have been passed in registers, but wasn't only because it is | |
4081 | __builtin_va_alist, we want locate_and_pad_parm to treat it as if | |
4082 | it came in a register so that REG_PARM_STACK_SPACE isn't skipped. | |
4083 | In this case, we call FUNCTION_ARG with NAMED set to 1 instead of | |
4084 | 0 as it was the previous time. */ | |
4085 | ||
621061f4 | 4086 | locate_and_pad_parm (promoted_mode, passed_type, |
6f086dfc RS |
4087 | #ifdef STACK_PARMS_IN_REG_PARM_AREA |
4088 | 1, | |
4089 | #else | |
4090 | #ifdef FUNCTION_INCOMING_ARG | |
621061f4 | 4091 | FUNCTION_INCOMING_ARG (args_so_far, promoted_mode, |
6f086dfc | 4092 | passed_type, |
bf9c83fe | 4093 | (named_arg |
6f086dfc RS |
4094 | || varargs_setup)) != 0, |
4095 | #else | |
621061f4 | 4096 | FUNCTION_ARG (args_so_far, promoted_mode, |
6f086dfc | 4097 | passed_type, |
bf9c83fe | 4098 | named_arg || varargs_setup) != 0, |
6f086dfc RS |
4099 | #endif |
4100 | #endif | |
4101 | fndecl, &stack_args_size, &stack_offset, &arg_size); | |
4102 | ||
4103 | if (! second_time) | |
4104 | { | |
4105 | rtx offset_rtx = ARGS_SIZE_RTX (stack_offset); | |
4106 | ||
4107 | if (offset_rtx == const0_rtx) | |
38a448ca | 4108 | stack_parm = gen_rtx_MEM (promoted_mode, internal_arg_pointer); |
6f086dfc | 4109 | else |
38a448ca RH |
4110 | stack_parm = gen_rtx_MEM (promoted_mode, |
4111 | gen_rtx_PLUS (Pmode, | |
4112 | internal_arg_pointer, | |
4113 | offset_rtx)); | |
6f086dfc RS |
4114 | |
4115 | /* If this is a memory ref that contains aggregate components, | |
a00285d0 RK |
4116 | mark it as such for cse and loop optimize. Likewise if it |
4117 | is readonly. */ | |
c6df88cb | 4118 | MEM_SET_IN_STRUCT_P (stack_parm, aggregate); |
a00285d0 | 4119 | RTX_UNCHANGING_P (stack_parm) = TREE_READONLY (parm); |
41472af8 | 4120 | MEM_ALIAS_SET (stack_parm) = get_alias_set (parm); |
6f086dfc RS |
4121 | } |
4122 | ||
4123 | /* If this parameter was passed both in registers and in the stack, | |
4124 | use the copy on the stack. */ | |
621061f4 | 4125 | if (MUST_PASS_IN_STACK (promoted_mode, passed_type)) |
6f086dfc RS |
4126 | entry_parm = 0; |
4127 | ||
461beb10 | 4128 | #ifdef FUNCTION_ARG_PARTIAL_NREGS |
6f086dfc RS |
4129 | /* If this parm was passed part in regs and part in memory, |
4130 | pretend it arrived entirely in memory | |
4131 | by pushing the register-part onto the stack. | |
4132 | ||
4133 | In the special case of a DImode or DFmode that is split, | |
4134 | we could put it together in a pseudoreg directly, | |
4135 | but for now that's not worth bothering with. */ | |
4136 | ||
4137 | if (entry_parm) | |
4138 | { | |
621061f4 | 4139 | int nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, promoted_mode, |
bf9c83fe | 4140 | passed_type, named_arg); |
6f086dfc RS |
4141 | |
4142 | if (nregs > 0) | |
4143 | { | |
4144 | current_function_pretend_args_size | |
4145 | = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1) | |
4146 | / (PARM_BOUNDARY / BITS_PER_UNIT) | |
4147 | * (PARM_BOUNDARY / BITS_PER_UNIT)); | |
4148 | ||
4149 | if (! second_time) | |
5c4cdc9f JW |
4150 | { |
4151 | /* Handle calls that pass values in multiple non-contiguous | |
4152 | locations. The Irix 6 ABI has examples of this. */ | |
4153 | if (GET_CODE (entry_parm) == PARALLEL) | |
aac5cc16 RH |
4154 | emit_group_store (validize_mem (stack_parm), entry_parm, |
4155 | int_size_in_bytes (TREE_TYPE (parm)), | |
4156 | (TYPE_ALIGN (TREE_TYPE (parm)) | |
4157 | / BITS_PER_UNIT)); | |
5c4cdc9f JW |
4158 | else |
4159 | move_block_from_reg (REGNO (entry_parm), | |
4160 | validize_mem (stack_parm), nregs, | |
4161 | int_size_in_bytes (TREE_TYPE (parm))); | |
4162 | } | |
6f086dfc RS |
4163 | entry_parm = stack_parm; |
4164 | } | |
4165 | } | |
461beb10 | 4166 | #endif |
6f086dfc RS |
4167 | |
4168 | /* If we didn't decide this parm came in a register, | |
4169 | by default it came on the stack. */ | |
4170 | if (entry_parm == 0) | |
4171 | entry_parm = stack_parm; | |
4172 | ||
4173 | /* Record permanently how this parm was passed. */ | |
4174 | if (! second_time) | |
4175 | DECL_INCOMING_RTL (parm) = entry_parm; | |
4176 | ||
4177 | /* If there is actually space on the stack for this parm, | |
4178 | count it in stack_args_size; otherwise set stack_parm to 0 | |
4179 | to indicate there is no preallocated stack slot for the parm. */ | |
4180 | ||
4181 | if (entry_parm == stack_parm | |
d9ca49d5 | 4182 | #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE) |
6f086dfc | 4183 | /* On some machines, even if a parm value arrives in a register |
d9ca49d5 JW |
4184 | there is still an (uninitialized) stack slot allocated for it. |
4185 | ||
4186 | ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell | |
4187 | whether this parameter already has a stack slot allocated, | |
4188 | because an arg block exists only if current_function_args_size | |
abc95ed3 | 4189 | is larger than some threshold, and we haven't calculated that |
d9ca49d5 JW |
4190 | yet. So, for now, we just assume that stack slots never exist |
4191 | in this case. */ | |
6f086dfc RS |
4192 | || REG_PARM_STACK_SPACE (fndecl) > 0 |
4193 | #endif | |
4194 | ) | |
4195 | { | |
4196 | stack_args_size.constant += arg_size.constant; | |
4197 | if (arg_size.var) | |
4198 | ADD_PARM_SIZE (stack_args_size, arg_size.var); | |
4199 | } | |
4200 | else | |
4201 | /* No stack slot was pushed for this parm. */ | |
4202 | stack_parm = 0; | |
4203 | ||
4204 | /* Update info on where next arg arrives in registers. */ | |
4205 | ||
621061f4 | 4206 | FUNCTION_ARG_ADVANCE (args_so_far, promoted_mode, |
bf9c83fe | 4207 | passed_type, named_arg); |
6f086dfc | 4208 | |
0f41302f | 4209 | /* If this is our second time through, we are done with this parm. */ |
6f086dfc RS |
4210 | if (second_time) |
4211 | continue; | |
4212 | ||
e16c591a RS |
4213 | /* If we can't trust the parm stack slot to be aligned enough |
4214 | for its ultimate type, don't use that slot after entry. | |
4215 | We'll make another stack slot, if we need one. */ | |
4216 | { | |
e16c591a | 4217 | int thisparm_boundary |
621061f4 | 4218 | = FUNCTION_ARG_BOUNDARY (promoted_mode, passed_type); |
e16c591a RS |
4219 | |
4220 | if (GET_MODE_ALIGNMENT (nominal_mode) > thisparm_boundary) | |
4221 | stack_parm = 0; | |
4222 | } | |
4223 | ||
cb61f66f RS |
4224 | /* If parm was passed in memory, and we need to convert it on entry, |
4225 | don't store it back in that same slot. */ | |
4226 | if (entry_parm != 0 | |
4227 | && nominal_mode != BLKmode && nominal_mode != passed_mode) | |
4228 | stack_parm = 0; | |
4229 | ||
4230 | #if 0 | |
6f086dfc RS |
4231 | /* Now adjust STACK_PARM to the mode and precise location |
4232 | where this parameter should live during execution, | |
4233 | if we discover that it must live in the stack during execution. | |
4234 | To make debuggers happier on big-endian machines, we store | |
4235 | the value in the last bytes of the space available. */ | |
4236 | ||
4237 | if (nominal_mode != BLKmode && nominal_mode != passed_mode | |
4238 | && stack_parm != 0) | |
4239 | { | |
4240 | rtx offset_rtx; | |
4241 | ||
f76b9db2 ILT |
4242 | if (BYTES_BIG_ENDIAN |
4243 | && GET_MODE_SIZE (nominal_mode) < UNITS_PER_WORD) | |
6f086dfc RS |
4244 | stack_offset.constant += (GET_MODE_SIZE (passed_mode) |
4245 | - GET_MODE_SIZE (nominal_mode)); | |
6f086dfc RS |
4246 | |
4247 | offset_rtx = ARGS_SIZE_RTX (stack_offset); | |
4248 | if (offset_rtx == const0_rtx) | |
38a448ca | 4249 | stack_parm = gen_rtx_MEM (nominal_mode, internal_arg_pointer); |
6f086dfc | 4250 | else |
38a448ca RH |
4251 | stack_parm = gen_rtx_MEM (nominal_mode, |
4252 | gen_rtx_PLUS (Pmode, | |
4253 | internal_arg_pointer, | |
4254 | offset_rtx)); | |
6f086dfc RS |
4255 | |
4256 | /* If this is a memory ref that contains aggregate components, | |
4257 | mark it as such for cse and loop optimize. */ | |
c6df88cb | 4258 | MEM_SET_IN_STRUCT_P (stack_parm, aggregate); |
6f086dfc | 4259 | } |
cb61f66f | 4260 | #endif /* 0 */ |
6f086dfc | 4261 | |
9dc0f531 RK |
4262 | #ifdef STACK_REGS |
4263 | /* We need this "use" info, because the gcc-register->stack-register | |
4264 | converter in reg-stack.c needs to know which registers are active | |
4265 | at the start of the function call. The actual parameter loading | |
4266 | instructions are not always available then anymore, since they might | |
4267 | have been optimised away. */ | |
4268 | ||
4269 | if (GET_CODE (entry_parm) == REG && !(hide_last_arg && last_named)) | |
38a448ca | 4270 | emit_insn (gen_rtx_USE (GET_MODE (entry_parm), entry_parm)); |
9dc0f531 RK |
4271 | #endif |
4272 | ||
6f086dfc RS |
4273 | /* ENTRY_PARM is an RTX for the parameter as it arrives, |
4274 | in the mode in which it arrives. | |
4275 | STACK_PARM is an RTX for a stack slot where the parameter can live | |
4276 | during the function (in case we want to put it there). | |
4277 | STACK_PARM is 0 if no stack slot was pushed for it. | |
4278 | ||
4279 | Now output code if necessary to convert ENTRY_PARM to | |
4280 | the type in which this function declares it, | |
4281 | and store that result in an appropriate place, | |
4282 | which may be a pseudo reg, may be STACK_PARM, | |
4283 | or may be a local stack slot if STACK_PARM is 0. | |
4284 | ||
4285 | Set DECL_RTL to that place. */ | |
4286 | ||
5c4cdc9f | 4287 | if (nominal_mode == BLKmode || GET_CODE (entry_parm) == PARALLEL) |
6f086dfc | 4288 | { |
5c4cdc9f JW |
4289 | /* If a BLKmode arrives in registers, copy it to a stack slot. |
4290 | Handle calls that pass values in multiple non-contiguous | |
4291 | locations. The Irix 6 ABI has examples of this. */ | |
4292 | if (GET_CODE (entry_parm) == REG | |
4293 | || GET_CODE (entry_parm) == PARALLEL) | |
6f086dfc | 4294 | { |
621061f4 RK |
4295 | int size_stored |
4296 | = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)), | |
4297 | UNITS_PER_WORD); | |
6f086dfc RS |
4298 | |
4299 | /* Note that we will be storing an integral number of words. | |
4300 | So we have to be careful to ensure that we allocate an | |
4301 | integral number of words. We do this below in the | |
4302 | assign_stack_local if space was not allocated in the argument | |
4303 | list. If it was, this will not work if PARM_BOUNDARY is not | |
4304 | a multiple of BITS_PER_WORD. It isn't clear how to fix this | |
4305 | if it becomes a problem. */ | |
4306 | ||
4307 | if (stack_parm == 0) | |
7e41ffa2 RS |
4308 | { |
4309 | stack_parm | |
621061f4 RK |
4310 | = assign_stack_local (GET_MODE (entry_parm), |
4311 | size_stored, 0); | |
4312 | ||
4313 | /* If this is a memory ref that contains aggregate | |
4314 | components, mark it as such for cse and loop optimize. */ | |
c6df88cb | 4315 | MEM_SET_IN_STRUCT_P (stack_parm, aggregate); |
7e41ffa2 RS |
4316 | } |
4317 | ||
6f086dfc RS |
4318 | else if (PARM_BOUNDARY % BITS_PER_WORD != 0) |
4319 | abort (); | |
4320 | ||
7a30f0c4 JW |
4321 | if (TREE_READONLY (parm)) |
4322 | RTX_UNCHANGING_P (stack_parm) = 1; | |
4323 | ||
5c4cdc9f JW |
4324 | /* Handle calls that pass values in multiple non-contiguous |
4325 | locations. The Irix 6 ABI has examples of this. */ | |
4326 | if (GET_CODE (entry_parm) == PARALLEL) | |
aac5cc16 RH |
4327 | emit_group_store (validize_mem (stack_parm), entry_parm, |
4328 | int_size_in_bytes (TREE_TYPE (parm)), | |
4329 | (TYPE_ALIGN (TREE_TYPE (parm)) | |
4330 | / BITS_PER_UNIT)); | |
5c4cdc9f JW |
4331 | else |
4332 | move_block_from_reg (REGNO (entry_parm), | |
4333 | validize_mem (stack_parm), | |
4334 | size_stored / UNITS_PER_WORD, | |
4335 | int_size_in_bytes (TREE_TYPE (parm))); | |
6f086dfc RS |
4336 | } |
4337 | DECL_RTL (parm) = stack_parm; | |
4338 | } | |
74bd77a8 | 4339 | else if (! ((obey_regdecls && ! DECL_REGISTER (parm) |
a82ad570 | 4340 | && ! DECL_INLINE (fndecl)) |
6f086dfc RS |
4341 | /* layout_decl may set this. */ |
4342 | || TREE_ADDRESSABLE (parm) | |
4343 | || TREE_SIDE_EFFECTS (parm) | |
4344 | /* If -ffloat-store specified, don't put explicit | |
4345 | float variables into registers. */ | |
4346 | || (flag_float_store | |
4347 | && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)) | |
4348 | /* Always assign pseudo to structure return or item passed | |
4349 | by invisible reference. */ | |
4350 | || passed_pointer || parm == function_result_decl) | |
4351 | { | |
00d8a4c1 RK |
4352 | /* Store the parm in a pseudoregister during the function, but we |
4353 | may need to do it in a wider mode. */ | |
4354 | ||
4355 | register rtx parmreg; | |
4e86caed | 4356 | int regno, regnoi = 0, regnor = 0; |
00d8a4c1 RK |
4357 | |
4358 | unsignedp = TREE_UNSIGNED (TREE_TYPE (parm)); | |
cd5b3469 | 4359 | |
621061f4 RK |
4360 | promoted_nominal_mode |
4361 | = promote_mode (TREE_TYPE (parm), nominal_mode, &unsignedp, 0); | |
6f086dfc | 4362 | |
621061f4 | 4363 | parmreg = gen_reg_rtx (promoted_nominal_mode); |
ddb7361a | 4364 | mark_user_reg (parmreg); |
6f086dfc RS |
4365 | |
4366 | /* If this was an item that we received a pointer to, set DECL_RTL | |
4367 | appropriately. */ | |
4368 | if (passed_pointer) | |
4369 | { | |
621061f4 | 4370 | DECL_RTL (parm) |
38a448ca | 4371 | = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (passed_type)), parmreg); |
c6df88cb | 4372 | MEM_SET_IN_STRUCT_P (DECL_RTL (parm), aggregate); |
6f086dfc RS |
4373 | } |
4374 | else | |
4375 | DECL_RTL (parm) = parmreg; | |
4376 | ||
4377 | /* Copy the value into the register. */ | |
621061f4 RK |
4378 | if (nominal_mode != passed_mode |
4379 | || promoted_nominal_mode != promoted_mode) | |
86f8eff3 | 4380 | { |
efd8cba0 | 4381 | int save_tree_used; |
621061f4 RK |
4382 | /* ENTRY_PARM has been converted to PROMOTED_MODE, its |
4383 | mode, by the caller. We now have to convert it to | |
4384 | NOMINAL_MODE, if different. However, PARMREG may be in | |
956d6950 | 4385 | a different mode than NOMINAL_MODE if it is being stored |
621061f4 RK |
4386 | promoted. |
4387 | ||
4388 | If ENTRY_PARM is a hard register, it might be in a register | |
86f8eff3 RK |
4389 | not valid for operating in its mode (e.g., an odd-numbered |
4390 | register for a DFmode). In that case, moves are the only | |
4391 | thing valid, so we can't do a convert from there. This | |
4392 | occurs when the calling sequence allow such misaligned | |
3412b298 JW |
4393 | usages. |
4394 | ||
4395 | In addition, the conversion may involve a call, which could | |
4396 | clobber parameters which haven't been copied to pseudo | |
4397 | registers yet. Therefore, we must first copy the parm to | |
4398 | a pseudo reg here, and save the conversion until after all | |
4399 | parameters have been moved. */ | |
4400 | ||
4401 | rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm)); | |
4402 | ||
4403 | emit_move_insn (tempreg, validize_mem (entry_parm)); | |
4404 | ||
4405 | push_to_sequence (conversion_insns); | |
ad241351 RK |
4406 | tempreg = convert_to_mode (nominal_mode, tempreg, unsignedp); |
4407 | ||
efd8cba0 DB |
4408 | /* TREE_USED gets set erroneously during expand_assignment. */ |
4409 | save_tree_used = TREE_USED (parm); | |
621061f4 RK |
4410 | expand_assignment (parm, |
4411 | make_tree (nominal_type, tempreg), 0, 0); | |
efd8cba0 | 4412 | TREE_USED (parm) = save_tree_used; |
3412b298 | 4413 | conversion_insns = get_insns (); |
621061f4 | 4414 | did_conversion = 1; |
3412b298 | 4415 | end_sequence (); |
86f8eff3 | 4416 | } |
6f086dfc RS |
4417 | else |
4418 | emit_move_insn (parmreg, validize_mem (entry_parm)); | |
4419 | ||
74bd77a8 RS |
4420 | /* If we were passed a pointer but the actual value |
4421 | can safely live in a register, put it in one. */ | |
16bae307 | 4422 | if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode |
74bd77a8 RS |
4423 | && ! ((obey_regdecls && ! DECL_REGISTER (parm) |
4424 | && ! DECL_INLINE (fndecl)) | |
4425 | /* layout_decl may set this. */ | |
4426 | || TREE_ADDRESSABLE (parm) | |
4427 | || TREE_SIDE_EFFECTS (parm) | |
4428 | /* If -ffloat-store specified, don't put explicit | |
4429 | float variables into registers. */ | |
4430 | || (flag_float_store | |
4431 | && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))) | |
4432 | { | |
2654605a JW |
4433 | /* We can't use nominal_mode, because it will have been set to |
4434 | Pmode above. We must use the actual mode of the parm. */ | |
4435 | parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm))); | |
ddb7361a | 4436 | mark_user_reg (parmreg); |
74bd77a8 RS |
4437 | emit_move_insn (parmreg, DECL_RTL (parm)); |
4438 | DECL_RTL (parm) = parmreg; | |
c110c53d RS |
4439 | /* STACK_PARM is the pointer, not the parm, and PARMREG is |
4440 | now the parm. */ | |
4441 | stack_parm = 0; | |
74bd77a8 | 4442 | } |
137a2a7b DE |
4443 | #ifdef FUNCTION_ARG_CALLEE_COPIES |
4444 | /* If we are passed an arg by reference and it is our responsibility | |
4445 | to make a copy, do it now. | |
4446 | PASSED_TYPE and PASSED mode now refer to the pointer, not the | |
4447 | original argument, so we must recreate them in the call to | |
4448 | FUNCTION_ARG_CALLEE_COPIES. */ | |
4449 | /* ??? Later add code to handle the case that if the argument isn't | |
4450 | modified, don't do the copy. */ | |
4451 | ||
4452 | else if (passed_pointer | |
4453 | && FUNCTION_ARG_CALLEE_COPIES (args_so_far, | |
4454 | TYPE_MODE (DECL_ARG_TYPE (parm)), | |
4455 | DECL_ARG_TYPE (parm), | |
bf9c83fe | 4456 | named_arg) |
926b1b99 | 4457 | && ! TREE_ADDRESSABLE (DECL_ARG_TYPE (parm))) |
137a2a7b DE |
4458 | { |
4459 | rtx copy; | |
4460 | tree type = DECL_ARG_TYPE (parm); | |
4461 | ||
4462 | /* This sequence may involve a library call perhaps clobbering | |
4463 | registers that haven't been copied to pseudos yet. */ | |
4464 | ||
4465 | push_to_sequence (conversion_insns); | |
4466 | ||
4467 | if (TYPE_SIZE (type) == 0 | |
4468 | || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST) | |
1fd3ef7f | 4469 | /* This is a variable sized object. */ |
38a448ca RH |
4470 | copy = gen_rtx_MEM (BLKmode, |
4471 | allocate_dynamic_stack_space | |
4472 | (expr_size (parm), NULL_RTX, | |
4473 | TYPE_ALIGN (type))); | |
137a2a7b | 4474 | else |
1fd3ef7f RK |
4475 | copy = assign_stack_temp (TYPE_MODE (type), |
4476 | int_size_in_bytes (type), 1); | |
c6df88cb | 4477 | MEM_SET_IN_STRUCT_P (copy, AGGREGATE_TYPE_P (type)); |
e9a25f70 | 4478 | RTX_UNCHANGING_P (copy) = TREE_READONLY (parm); |
137a2a7b DE |
4479 | |
4480 | store_expr (parm, copy, 0); | |
4481 | emit_move_insn (parmreg, XEXP (copy, 0)); | |
7d384cc0 | 4482 | if (current_function_check_memory_usage) |
86fa911a RK |
4483 | emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3, |
4484 | XEXP (copy, 0), ptr_mode, | |
4485 | GEN_INT (int_size_in_bytes (type)), | |
4486 | TYPE_MODE (sizetype), | |
956d6950 JL |
4487 | GEN_INT (MEMORY_USE_RW), |
4488 | TYPE_MODE (integer_type_node)); | |
137a2a7b | 4489 | conversion_insns = get_insns (); |
621061f4 | 4490 | did_conversion = 1; |
137a2a7b DE |
4491 | end_sequence (); |
4492 | } | |
4493 | #endif /* FUNCTION_ARG_CALLEE_COPIES */ | |
74bd77a8 | 4494 | |
6f086dfc | 4495 | /* In any case, record the parm's desired stack location |
14aceb29 RS |
4496 | in case we later discover it must live in the stack. |
4497 | ||
4498 | If it is a COMPLEX value, store the stack location for both | |
4499 | halves. */ | |
4500 | ||
4501 | if (GET_CODE (parmreg) == CONCAT) | |
4502 | regno = MAX (REGNO (XEXP (parmreg, 0)), REGNO (XEXP (parmreg, 1))); | |
4503 | else | |
4504 | regno = REGNO (parmreg); | |
4505 | ||
e9a25f70 | 4506 | if (regno >= max_parm_reg) |
6f086dfc RS |
4507 | { |
4508 | rtx *new; | |
e9a25f70 | 4509 | int old_max_parm_reg = max_parm_reg; |
14aceb29 | 4510 | |
e9a25f70 JL |
4511 | /* It's slow to expand this one register at a time, |
4512 | but it's also rare and we need max_parm_reg to be | |
4513 | precisely correct. */ | |
4514 | max_parm_reg = regno + 1; | |
4515 | new = (rtx *) savealloc (max_parm_reg * sizeof (rtx)); | |
4c9a05bc | 4516 | bcopy ((char *) parm_reg_stack_loc, (char *) new, |
e9a25f70 JL |
4517 | old_max_parm_reg * sizeof (rtx)); |
4518 | bzero ((char *) (new + old_max_parm_reg), | |
4519 | (max_parm_reg - old_max_parm_reg) * sizeof (rtx)); | |
6f086dfc RS |
4520 | parm_reg_stack_loc = new; |
4521 | } | |
14aceb29 RS |
4522 | |
4523 | if (GET_CODE (parmreg) == CONCAT) | |
4524 | { | |
4525 | enum machine_mode submode = GET_MODE (XEXP (parmreg, 0)); | |
4526 | ||
a03caf76 RK |
4527 | regnor = REGNO (gen_realpart (submode, parmreg)); |
4528 | regnoi = REGNO (gen_imagpart (submode, parmreg)); | |
4529 | ||
7b1a0c14 RS |
4530 | if (stack_parm != 0) |
4531 | { | |
a03caf76 | 4532 | parm_reg_stack_loc[regnor] |
3d329b07 | 4533 | = gen_realpart (submode, stack_parm); |
a03caf76 | 4534 | parm_reg_stack_loc[regnoi] |
3d329b07 | 4535 | = gen_imagpart (submode, stack_parm); |
7b1a0c14 RS |
4536 | } |
4537 | else | |
4538 | { | |
a03caf76 RK |
4539 | parm_reg_stack_loc[regnor] = 0; |
4540 | parm_reg_stack_loc[regnoi] = 0; | |
7b1a0c14 | 4541 | } |
14aceb29 RS |
4542 | } |
4543 | else | |
4544 | parm_reg_stack_loc[REGNO (parmreg)] = stack_parm; | |
6f086dfc RS |
4545 | |
4546 | /* Mark the register as eliminable if we did no conversion | |
4547 | and it was copied from memory at a fixed offset, | |
4548 | and the arg pointer was not copied to a pseudo-reg. | |
4549 | If the arg pointer is a pseudo reg or the offset formed | |
4550 | an invalid address, such memory-equivalences | |
4551 | as we make here would screw up life analysis for it. */ | |
4552 | if (nominal_mode == passed_mode | |
621061f4 | 4553 | && ! did_conversion |
38b610ed ILT |
4554 | && stack_parm != 0 |
4555 | && GET_CODE (stack_parm) == MEM | |
6f086dfc RS |
4556 | && stack_offset.var == 0 |
4557 | && reg_mentioned_p (virtual_incoming_args_rtx, | |
38b610ed | 4558 | XEXP (stack_parm, 0))) |
a03caf76 RK |
4559 | { |
4560 | rtx linsn = get_last_insn (); | |
69685820 | 4561 | rtx sinsn, set; |
a03caf76 RK |
4562 | |
4563 | /* Mark complex types separately. */ | |
4564 | if (GET_CODE (parmreg) == CONCAT) | |
69685820 RK |
4565 | /* Scan backwards for the set of the real and |
4566 | imaginary parts. */ | |
4567 | for (sinsn = linsn; sinsn != 0; | |
4568 | sinsn = prev_nonnote_insn (sinsn)) | |
4569 | { | |
4570 | set = single_set (sinsn); | |
4571 | if (set != 0 | |
4572 | && SET_DEST (set) == regno_reg_rtx [regnoi]) | |
4573 | REG_NOTES (sinsn) | |
38a448ca RH |
4574 | = gen_rtx_EXPR_LIST (REG_EQUIV, |
4575 | parm_reg_stack_loc[regnoi], | |
4576 | REG_NOTES (sinsn)); | |
69685820 RK |
4577 | else if (set != 0 |
4578 | && SET_DEST (set) == regno_reg_rtx [regnor]) | |
4579 | REG_NOTES (sinsn) | |
38a448ca RH |
4580 | = gen_rtx_EXPR_LIST (REG_EQUIV, |
4581 | parm_reg_stack_loc[regnor], | |
4582 | REG_NOTES (sinsn)); | |
69685820 RK |
4583 | } |
4584 | else if ((set = single_set (linsn)) != 0 | |
4585 | && SET_DEST (set) == parmreg) | |
a03caf76 | 4586 | REG_NOTES (linsn) |
38a448ca RH |
4587 | = gen_rtx_EXPR_LIST (REG_EQUIV, |
4588 | stack_parm, REG_NOTES (linsn)); | |
a03caf76 | 4589 | } |
6f086dfc RS |
4590 | |
4591 | /* For pointer data type, suggest pointer register. */ | |
e5e809f4 | 4592 | if (POINTER_TYPE_P (TREE_TYPE (parm))) |
6c6166bd RK |
4593 | mark_reg_pointer (parmreg, |
4594 | (TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm))) | |
4595 | / BITS_PER_UNIT)); | |
6f086dfc RS |
4596 | } |
4597 | else | |
4598 | { | |
4599 | /* Value must be stored in the stack slot STACK_PARM | |
4600 | during function execution. */ | |
4601 | ||
621061f4 | 4602 | if (promoted_mode != nominal_mode) |
86f8eff3 RK |
4603 | { |
4604 | /* Conversion is required. */ | |
3412b298 JW |
4605 | rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm)); |
4606 | ||
4607 | emit_move_insn (tempreg, validize_mem (entry_parm)); | |
86f8eff3 | 4608 | |
3412b298 JW |
4609 | push_to_sequence (conversion_insns); |
4610 | entry_parm = convert_to_mode (nominal_mode, tempreg, | |
a53e14c0 | 4611 | TREE_UNSIGNED (TREE_TYPE (parm))); |
de957303 DE |
4612 | if (stack_parm) |
4613 | { | |
4614 | /* ??? This may need a big-endian conversion on sparc64. */ | |
4615 | stack_parm = change_address (stack_parm, nominal_mode, | |
4616 | NULL_RTX); | |
4617 | } | |
3412b298 | 4618 | conversion_insns = get_insns (); |
621061f4 | 4619 | did_conversion = 1; |
3412b298 | 4620 | end_sequence (); |
86f8eff3 | 4621 | } |
6f086dfc RS |
4622 | |
4623 | if (entry_parm != stack_parm) | |
4624 | { | |
4625 | if (stack_parm == 0) | |
7e41ffa2 RS |
4626 | { |
4627 | stack_parm | |
4628 | = assign_stack_local (GET_MODE (entry_parm), | |
4629 | GET_MODE_SIZE (GET_MODE (entry_parm)), 0); | |
4630 | /* If this is a memory ref that contains aggregate components, | |
4631 | mark it as such for cse and loop optimize. */ | |
c6df88cb | 4632 | MEM_SET_IN_STRUCT_P (stack_parm, aggregate); |
7e41ffa2 RS |
4633 | } |
4634 | ||
621061f4 | 4635 | if (promoted_mode != nominal_mode) |
3412b298 JW |
4636 | { |
4637 | push_to_sequence (conversion_insns); | |
4638 | emit_move_insn (validize_mem (stack_parm), | |
4639 | validize_mem (entry_parm)); | |
4640 | conversion_insns = get_insns (); | |
4641 | end_sequence (); | |
4642 | } | |
4643 | else | |
4644 | emit_move_insn (validize_mem (stack_parm), | |
4645 | validize_mem (entry_parm)); | |
6f086dfc | 4646 | } |
7d384cc0 | 4647 | if (current_function_check_memory_usage) |
86fa911a RK |
4648 | { |
4649 | push_to_sequence (conversion_insns); | |
4650 | emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3, | |
4651 | XEXP (stack_parm, 0), ptr_mode, | |
4652 | GEN_INT (GET_MODE_SIZE (GET_MODE | |
4653 | (entry_parm))), | |
4654 | TYPE_MODE (sizetype), | |
956d6950 JL |
4655 | GEN_INT (MEMORY_USE_RW), |
4656 | TYPE_MODE (integer_type_node)); | |
6f086dfc | 4657 | |
86fa911a RK |
4658 | conversion_insns = get_insns (); |
4659 | end_sequence (); | |
4660 | } | |
6f086dfc RS |
4661 | DECL_RTL (parm) = stack_parm; |
4662 | } | |
4663 | ||
4664 | /* If this "parameter" was the place where we are receiving the | |
4665 | function's incoming structure pointer, set up the result. */ | |
4666 | if (parm == function_result_decl) | |
ccdecf58 RK |
4667 | { |
4668 | tree result = DECL_RESULT (fndecl); | |
4669 | tree restype = TREE_TYPE (result); | |
4670 | ||
4671 | DECL_RTL (result) | |
38a448ca | 4672 | = gen_rtx_MEM (DECL_MODE (result), DECL_RTL (parm)); |
ccdecf58 | 4673 | |
c6df88cb MM |
4674 | MEM_SET_IN_STRUCT_P (DECL_RTL (result), |
4675 | AGGREGATE_TYPE_P (restype)); | |
ccdecf58 | 4676 | } |
6f086dfc RS |
4677 | |
4678 | if (TREE_THIS_VOLATILE (parm)) | |
4679 | MEM_VOLATILE_P (DECL_RTL (parm)) = 1; | |
4680 | if (TREE_READONLY (parm)) | |
4681 | RTX_UNCHANGING_P (DECL_RTL (parm)) = 1; | |
4682 | } | |
4683 | ||
3412b298 JW |
4684 | /* Output all parameter conversion instructions (possibly including calls) |
4685 | now that all parameters have been copied out of hard registers. */ | |
4686 | emit_insns (conversion_insns); | |
4687 | ||
6f086dfc RS |
4688 | last_parm_insn = get_last_insn (); |
4689 | ||
4690 | current_function_args_size = stack_args_size.constant; | |
4691 | ||
4692 | /* Adjust function incoming argument size for alignment and | |
4693 | minimum length. */ | |
4694 | ||
4695 | #ifdef REG_PARM_STACK_SPACE | |
6f90e075 | 4696 | #ifndef MAYBE_REG_PARM_STACK_SPACE |
6f086dfc RS |
4697 | current_function_args_size = MAX (current_function_args_size, |
4698 | REG_PARM_STACK_SPACE (fndecl)); | |
4699 | #endif | |
6f90e075 | 4700 | #endif |
6f086dfc | 4701 | |
c795bca9 BS |
4702 | #ifdef PREFERRED_STACK_BOUNDARY |
4703 | #define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT) | |
6f086dfc RS |
4704 | |
4705 | current_function_args_size | |
4706 | = ((current_function_args_size + STACK_BYTES - 1) | |
4707 | / STACK_BYTES) * STACK_BYTES; | |
4708 | #endif | |
4709 | ||
4710 | #ifdef ARGS_GROW_DOWNWARD | |
4711 | current_function_arg_offset_rtx | |
5f4f0e22 | 4712 | = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant) |
6f086dfc RS |
4713 | : expand_expr (size_binop (MINUS_EXPR, stack_args_size.var, |
4714 | size_int (-stack_args_size.constant)), | |
86fa911a | 4715 | NULL_RTX, VOIDmode, EXPAND_MEMORY_USE_BAD)); |
6f086dfc RS |
4716 | #else |
4717 | current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size); | |
4718 | #endif | |
4719 | ||
4720 | /* See how many bytes, if any, of its args a function should try to pop | |
4721 | on return. */ | |
4722 | ||
64e6d9cc | 4723 | current_function_pops_args = RETURN_POPS_ARGS (fndecl, TREE_TYPE (fndecl), |
6f086dfc RS |
4724 | current_function_args_size); |
4725 | ||
3b69d50e RK |
4726 | /* For stdarg.h function, save info about |
4727 | regs and stack space used by the named args. */ | |
6f086dfc | 4728 | |
3b69d50e | 4729 | if (!hide_last_arg) |
6f086dfc RS |
4730 | current_function_args_info = args_so_far; |
4731 | ||
4732 | /* Set the rtx used for the function return value. Put this in its | |
4733 | own variable so any optimizers that need this information don't have | |
4734 | to include tree.h. Do this here so it gets done when an inlined | |
4735 | function gets output. */ | |
4736 | ||
4737 | current_function_return_rtx = DECL_RTL (DECL_RESULT (fndecl)); | |
4738 | } | |
4739 | \f | |
75dc3319 RK |
4740 | /* Indicate whether REGNO is an incoming argument to the current function |
4741 | that was promoted to a wider mode. If so, return the RTX for the | |
4742 | register (to get its mode). PMODE and PUNSIGNEDP are set to the mode | |
4743 | that REGNO is promoted from and whether the promotion was signed or | |
4744 | unsigned. */ | |
4745 | ||
4746 | #ifdef PROMOTE_FUNCTION_ARGS | |
4747 | ||
4748 | rtx | |
4749 | promoted_input_arg (regno, pmode, punsignedp) | |
4750 | int regno; | |
4751 | enum machine_mode *pmode; | |
4752 | int *punsignedp; | |
4753 | { | |
4754 | tree arg; | |
4755 | ||
4756 | for (arg = DECL_ARGUMENTS (current_function_decl); arg; | |
4757 | arg = TREE_CHAIN (arg)) | |
4758 | if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG | |
621061f4 RK |
4759 | && REGNO (DECL_INCOMING_RTL (arg)) == regno |
4760 | && TYPE_MODE (DECL_ARG_TYPE (arg)) == TYPE_MODE (TREE_TYPE (arg))) | |
75dc3319 RK |
4761 | { |
4762 | enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg)); | |
4763 | int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg)); | |
4764 | ||
a5a52dbc | 4765 | mode = promote_mode (TREE_TYPE (arg), mode, &unsignedp, 1); |
75dc3319 RK |
4766 | if (mode == GET_MODE (DECL_INCOMING_RTL (arg)) |
4767 | && mode != DECL_MODE (arg)) | |
4768 | { | |
4769 | *pmode = DECL_MODE (arg); | |
4770 | *punsignedp = unsignedp; | |
4771 | return DECL_INCOMING_RTL (arg); | |
4772 | } | |
4773 | } | |
4774 | ||
4775 | return 0; | |
4776 | } | |
4777 | ||
4778 | #endif | |
4779 | \f | |
6f086dfc RS |
4780 | /* Compute the size and offset from the start of the stacked arguments for a |
4781 | parm passed in mode PASSED_MODE and with type TYPE. | |
4782 | ||
4783 | INITIAL_OFFSET_PTR points to the current offset into the stacked | |
4784 | arguments. | |
4785 | ||
4786 | The starting offset and size for this parm are returned in *OFFSET_PTR | |
4787 | and *ARG_SIZE_PTR, respectively. | |
4788 | ||
4789 | IN_REGS is non-zero if the argument will be passed in registers. It will | |
4790 | never be set if REG_PARM_STACK_SPACE is not defined. | |
4791 | ||
4792 | FNDECL is the function in which the argument was defined. | |
4793 | ||
4794 | There are two types of rounding that are done. The first, controlled by | |
4795 | FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument | |
4796 | list to be aligned to the specific boundary (in bits). This rounding | |
4797 | affects the initial and starting offsets, but not the argument size. | |
4798 | ||
4799 | The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY, | |
4800 | optionally rounds the size of the parm to PARM_BOUNDARY. The | |
4801 | initial offset is not affected by this rounding, while the size always | |
4802 | is and the starting offset may be. */ | |
4803 | ||
4804 | /* offset_ptr will be negative for ARGS_GROW_DOWNWARD case; | |
4805 | initial_offset_ptr is positive because locate_and_pad_parm's | |
4806 | callers pass in the total size of args so far as | |
4807 | initial_offset_ptr. arg_size_ptr is always positive.*/ | |
4808 | ||
6f086dfc RS |
4809 | void |
4810 | locate_and_pad_parm (passed_mode, type, in_regs, fndecl, | |
4811 | initial_offset_ptr, offset_ptr, arg_size_ptr) | |
4812 | enum machine_mode passed_mode; | |
4813 | tree type; | |
4814 | int in_regs; | |
4815 | tree fndecl; | |
4816 | struct args_size *initial_offset_ptr; | |
4817 | struct args_size *offset_ptr; | |
4818 | struct args_size *arg_size_ptr; | |
4819 | { | |
4820 | tree sizetree | |
4821 | = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode)); | |
4822 | enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type); | |
4823 | int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type); | |
6f086dfc RS |
4824 | |
4825 | #ifdef REG_PARM_STACK_SPACE | |
4826 | /* If we have found a stack parm before we reach the end of the | |
4827 | area reserved for registers, skip that area. */ | |
4828 | if (! in_regs) | |
4829 | { | |
29a82058 JL |
4830 | int reg_parm_stack_space = 0; |
4831 | ||
29008b51 JW |
4832 | #ifdef MAYBE_REG_PARM_STACK_SPACE |
4833 | reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE; | |
4834 | #else | |
6f086dfc | 4835 | reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl); |
29008b51 | 4836 | #endif |
6f086dfc RS |
4837 | if (reg_parm_stack_space > 0) |
4838 | { | |
4839 | if (initial_offset_ptr->var) | |
4840 | { | |
4841 | initial_offset_ptr->var | |
4842 | = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr), | |
4843 | size_int (reg_parm_stack_space)); | |
4844 | initial_offset_ptr->constant = 0; | |
4845 | } | |
4846 | else if (initial_offset_ptr->constant < reg_parm_stack_space) | |
4847 | initial_offset_ptr->constant = reg_parm_stack_space; | |
4848 | } | |
4849 | } | |
4850 | #endif /* REG_PARM_STACK_SPACE */ | |
4851 | ||
4852 | arg_size_ptr->var = 0; | |
4853 | arg_size_ptr->constant = 0; | |
4854 | ||
4855 | #ifdef ARGS_GROW_DOWNWARD | |
4856 | if (initial_offset_ptr->var) | |
4857 | { | |
4858 | offset_ptr->constant = 0; | |
4859 | offset_ptr->var = size_binop (MINUS_EXPR, integer_zero_node, | |
4860 | initial_offset_ptr->var); | |
4861 | } | |
4862 | else | |
4863 | { | |
4864 | offset_ptr->constant = - initial_offset_ptr->constant; | |
4865 | offset_ptr->var = 0; | |
4866 | } | |
0b21dcf5 | 4867 | if (where_pad != none |
6f086dfc RS |
4868 | && (TREE_CODE (sizetree) != INTEGER_CST |
4869 | || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY))) | |
4870 | sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT); | |
4871 | SUB_PARM_SIZE (*offset_ptr, sizetree); | |
66bcbe19 TG |
4872 | if (where_pad != downward) |
4873 | pad_to_arg_alignment (offset_ptr, boundary); | |
6f086dfc RS |
4874 | if (initial_offset_ptr->var) |
4875 | { | |
4876 | arg_size_ptr->var = size_binop (MINUS_EXPR, | |
4877 | size_binop (MINUS_EXPR, | |
4878 | integer_zero_node, | |
4879 | initial_offset_ptr->var), | |
4880 | offset_ptr->var); | |
4881 | } | |
4882 | else | |
4883 | { | |
db3cf6fb MS |
4884 | arg_size_ptr->constant = (- initial_offset_ptr->constant |
4885 | - offset_ptr->constant); | |
6f086dfc | 4886 | } |
6f086dfc RS |
4887 | #else /* !ARGS_GROW_DOWNWARD */ |
4888 | pad_to_arg_alignment (initial_offset_ptr, boundary); | |
4889 | *offset_ptr = *initial_offset_ptr; | |
6f086dfc RS |
4890 | |
4891 | #ifdef PUSH_ROUNDING | |
4892 | if (passed_mode != BLKmode) | |
4893 | sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree))); | |
4894 | #endif | |
4895 | ||
d4b0a7a0 DE |
4896 | /* Pad_below needs the pre-rounded size to know how much to pad below |
4897 | so this must be done before rounding up. */ | |
ea5917da DE |
4898 | if (where_pad == downward |
4899 | /* However, BLKmode args passed in regs have their padding done elsewhere. | |
4900 | The stack slot must be able to hold the entire register. */ | |
4901 | && !(in_regs && passed_mode == BLKmode)) | |
d4b0a7a0 DE |
4902 | pad_below (offset_ptr, passed_mode, sizetree); |
4903 | ||
6f086dfc RS |
4904 | if (where_pad != none |
4905 | && (TREE_CODE (sizetree) != INTEGER_CST | |
4906 | || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY))) | |
4907 | sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT); | |
4908 | ||
4909 | ADD_PARM_SIZE (*arg_size_ptr, sizetree); | |
4910 | #endif /* ARGS_GROW_DOWNWARD */ | |
4911 | } | |
4912 | ||
e16c591a RS |
4913 | /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY. |
4914 | BOUNDARY is measured in bits, but must be a multiple of a storage unit. */ | |
4915 | ||
6f086dfc RS |
4916 | static void |
4917 | pad_to_arg_alignment (offset_ptr, boundary) | |
4918 | struct args_size *offset_ptr; | |
4919 | int boundary; | |
4920 | { | |
4921 | int boundary_in_bytes = boundary / BITS_PER_UNIT; | |
4922 | ||
4923 | if (boundary > BITS_PER_UNIT) | |
4924 | { | |
4925 | if (offset_ptr->var) | |
4926 | { | |
4927 | offset_ptr->var = | |
4928 | #ifdef ARGS_GROW_DOWNWARD | |
4929 | round_down | |
4930 | #else | |
4931 | round_up | |
4932 | #endif | |
4933 | (ARGS_SIZE_TREE (*offset_ptr), | |
4934 | boundary / BITS_PER_UNIT); | |
4935 | offset_ptr->constant = 0; /*?*/ | |
4936 | } | |
4937 | else | |
4938 | offset_ptr->constant = | |
4939 | #ifdef ARGS_GROW_DOWNWARD | |
4940 | FLOOR_ROUND (offset_ptr->constant, boundary_in_bytes); | |
4941 | #else | |
4942 | CEIL_ROUND (offset_ptr->constant, boundary_in_bytes); | |
4943 | #endif | |
4944 | } | |
4945 | } | |
4946 | ||
51723711 | 4947 | #ifndef ARGS_GROW_DOWNWARD |
6f086dfc RS |
4948 | static void |
4949 | pad_below (offset_ptr, passed_mode, sizetree) | |
4950 | struct args_size *offset_ptr; | |
4951 | enum machine_mode passed_mode; | |
4952 | tree sizetree; | |
4953 | { | |
4954 | if (passed_mode != BLKmode) | |
4955 | { | |
4956 | if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY) | |
4957 | offset_ptr->constant | |
4958 | += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1) | |
4959 | / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT) | |
4960 | - GET_MODE_SIZE (passed_mode)); | |
4961 | } | |
4962 | else | |
4963 | { | |
4964 | if (TREE_CODE (sizetree) != INTEGER_CST | |
4965 | || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY) | |
4966 | { | |
4967 | /* Round the size up to multiple of PARM_BOUNDARY bits. */ | |
4968 | tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT); | |
4969 | /* Add it in. */ | |
4970 | ADD_PARM_SIZE (*offset_ptr, s2); | |
4971 | SUB_PARM_SIZE (*offset_ptr, sizetree); | |
4972 | } | |
4973 | } | |
4974 | } | |
51723711 | 4975 | #endif |
6f086dfc | 4976 | |
487a6e06 | 4977 | #ifdef ARGS_GROW_DOWNWARD |
6f086dfc RS |
4978 | static tree |
4979 | round_down (value, divisor) | |
4980 | tree value; | |
4981 | int divisor; | |
4982 | { | |
4983 | return size_binop (MULT_EXPR, | |
4984 | size_binop (FLOOR_DIV_EXPR, value, size_int (divisor)), | |
4985 | size_int (divisor)); | |
4986 | } | |
487a6e06 | 4987 | #endif |
6f086dfc RS |
4988 | \f |
4989 | /* Walk the tree of blocks describing the binding levels within a function | |
4990 | and warn about uninitialized variables. | |
4991 | This is done after calling flow_analysis and before global_alloc | |
4992 | clobbers the pseudo-regs to hard regs. */ | |
4993 | ||
4994 | void | |
4995 | uninitialized_vars_warning (block) | |
4996 | tree block; | |
4997 | { | |
4998 | register tree decl, sub; | |
4999 | for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl)) | |
5000 | { | |
5001 | if (TREE_CODE (decl) == VAR_DECL | |
5002 | /* These warnings are unreliable for and aggregates | |
5003 | because assigning the fields one by one can fail to convince | |
5004 | flow.c that the entire aggregate was initialized. | |
5005 | Unions are troublesome because members may be shorter. */ | |
05e3bdb9 | 5006 | && ! AGGREGATE_TYPE_P (TREE_TYPE (decl)) |
6f086dfc RS |
5007 | && DECL_RTL (decl) != 0 |
5008 | && GET_CODE (DECL_RTL (decl)) == REG | |
6acdd0fd JL |
5009 | /* Global optimizations can make it difficult to determine if a |
5010 | particular variable has been initialized. However, a VAR_DECL | |
5011 | with a nonzero DECL_INITIAL had an initializer, so do not | |
5012 | claim it is potentially uninitialized. | |
5013 | ||
5014 | We do not care about the actual value in DECL_INITIAL, so we do | |
5015 | not worry that it may be a dangling pointer. */ | |
5016 | && DECL_INITIAL (decl) == NULL_TREE | |
6f086dfc RS |
5017 | && regno_uninitialized (REGNO (DECL_RTL (decl)))) |
5018 | warning_with_decl (decl, | |
3c8cd8bd | 5019 | "`%s' might be used uninitialized in this function"); |
6f086dfc RS |
5020 | if (TREE_CODE (decl) == VAR_DECL |
5021 | && DECL_RTL (decl) != 0 | |
5022 | && GET_CODE (DECL_RTL (decl)) == REG | |
5023 | && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl)))) | |
5024 | warning_with_decl (decl, | |
3c8cd8bd | 5025 | "variable `%s' might be clobbered by `longjmp' or `vfork'"); |
6f086dfc RS |
5026 | } |
5027 | for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub)) | |
5028 | uninitialized_vars_warning (sub); | |
5029 | } | |
5030 | ||
5031 | /* Do the appropriate part of uninitialized_vars_warning | |
5032 | but for arguments instead of local variables. */ | |
5033 | ||
5034 | void | |
0cd6ef35 | 5035 | setjmp_args_warning () |
6f086dfc RS |
5036 | { |
5037 | register tree decl; | |
5038 | for (decl = DECL_ARGUMENTS (current_function_decl); | |
5039 | decl; decl = TREE_CHAIN (decl)) | |
5040 | if (DECL_RTL (decl) != 0 | |
5041 | && GET_CODE (DECL_RTL (decl)) == REG | |
5042 | && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl)))) | |
3c8cd8bd | 5043 | warning_with_decl (decl, "argument `%s' might be clobbered by `longjmp' or `vfork'"); |
6f086dfc RS |
5044 | } |
5045 | ||
5046 | /* If this function call setjmp, put all vars into the stack | |
5047 | unless they were declared `register'. */ | |
5048 | ||
5049 | void | |
5050 | setjmp_protect (block) | |
5051 | tree block; | |
5052 | { | |
5053 | register tree decl, sub; | |
5054 | for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl)) | |
5055 | if ((TREE_CODE (decl) == VAR_DECL | |
5056 | || TREE_CODE (decl) == PARM_DECL) | |
5057 | && DECL_RTL (decl) != 0 | |
e9a25f70 JL |
5058 | && (GET_CODE (DECL_RTL (decl)) == REG |
5059 | || (GET_CODE (DECL_RTL (decl)) == MEM | |
5060 | && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF)) | |
b335c2cc | 5061 | /* If this variable came from an inline function, it must be |
9ec36da5 | 5062 | that its life doesn't overlap the setjmp. If there was a |
b335c2cc TW |
5063 | setjmp in the function, it would already be in memory. We |
5064 | must exclude such variable because their DECL_RTL might be | |
5065 | set to strange things such as virtual_stack_vars_rtx. */ | |
5066 | && ! DECL_FROM_INLINE (decl) | |
6f086dfc RS |
5067 | && ( |
5068 | #ifdef NON_SAVING_SETJMP | |
5069 | /* If longjmp doesn't restore the registers, | |
5070 | don't put anything in them. */ | |
5071 | NON_SAVING_SETJMP | |
5072 | || | |
5073 | #endif | |
a82ad570 | 5074 | ! DECL_REGISTER (decl))) |
6f086dfc RS |
5075 | put_var_into_stack (decl); |
5076 | for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub)) | |
5077 | setjmp_protect (sub); | |
5078 | } | |
5079 | \f | |
5080 | /* Like the previous function, but for args instead of local variables. */ | |
5081 | ||
5082 | void | |
5083 | setjmp_protect_args () | |
5084 | { | |
29a82058 | 5085 | register tree decl; |
6f086dfc RS |
5086 | for (decl = DECL_ARGUMENTS (current_function_decl); |
5087 | decl; decl = TREE_CHAIN (decl)) | |
5088 | if ((TREE_CODE (decl) == VAR_DECL | |
5089 | || TREE_CODE (decl) == PARM_DECL) | |
5090 | && DECL_RTL (decl) != 0 | |
e9a25f70 JL |
5091 | && (GET_CODE (DECL_RTL (decl)) == REG |
5092 | || (GET_CODE (DECL_RTL (decl)) == MEM | |
5093 | && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF)) | |
6f086dfc RS |
5094 | && ( |
5095 | /* If longjmp doesn't restore the registers, | |
5096 | don't put anything in them. */ | |
5097 | #ifdef NON_SAVING_SETJMP | |
5098 | NON_SAVING_SETJMP | |
5099 | || | |
5100 | #endif | |
a82ad570 | 5101 | ! DECL_REGISTER (decl))) |
6f086dfc RS |
5102 | put_var_into_stack (decl); |
5103 | } | |
5104 | \f | |
5105 | /* Return the context-pointer register corresponding to DECL, | |
5106 | or 0 if it does not need one. */ | |
5107 | ||
5108 | rtx | |
5109 | lookup_static_chain (decl) | |
5110 | tree decl; | |
5111 | { | |
b001a02f PB |
5112 | tree context = decl_function_context (decl); |
5113 | tree link; | |
7ad8c4bf | 5114 | |
38ee6ed9 JM |
5115 | if (context == 0 |
5116 | || (TREE_CODE (decl) == FUNCTION_DECL && DECL_NO_STATIC_CHAIN (decl))) | |
7ad8c4bf | 5117 | return 0; |
38ee6ed9 | 5118 | |
6f086dfc RS |
5119 | /* We treat inline_function_decl as an alias for the current function |
5120 | because that is the inline function whose vars, types, etc. | |
5121 | are being merged into the current function. | |
5122 | See expand_inline_function. */ | |
5123 | if (context == current_function_decl || context == inline_function_decl) | |
5124 | return virtual_stack_vars_rtx; | |
5125 | ||
5126 | for (link = context_display; link; link = TREE_CHAIN (link)) | |
5127 | if (TREE_PURPOSE (link) == context) | |
5128 | return RTL_EXPR_RTL (TREE_VALUE (link)); | |
5129 | ||
5130 | abort (); | |
5131 | } | |
5132 | \f | |
5133 | /* Convert a stack slot address ADDR for variable VAR | |
5134 | (from a containing function) | |
5135 | into an address valid in this function (using a static chain). */ | |
5136 | ||
5137 | rtx | |
5138 | fix_lexical_addr (addr, var) | |
5139 | rtx addr; | |
5140 | tree var; | |
5141 | { | |
5142 | rtx basereg; | |
e5e809f4 | 5143 | HOST_WIDE_INT displacement; |
6f086dfc RS |
5144 | tree context = decl_function_context (var); |
5145 | struct function *fp; | |
5146 | rtx base = 0; | |
5147 | ||
5148 | /* If this is the present function, we need not do anything. */ | |
5149 | if (context == current_function_decl || context == inline_function_decl) | |
5150 | return addr; | |
5151 | ||
5152 | for (fp = outer_function_chain; fp; fp = fp->next) | |
5153 | if (fp->decl == context) | |
5154 | break; | |
5155 | ||
5156 | if (fp == 0) | |
5157 | abort (); | |
5158 | ||
e9a25f70 JL |
5159 | if (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == MEM) |
5160 | addr = XEXP (XEXP (addr, 0), 0); | |
5161 | ||
6f086dfc RS |
5162 | /* Decode given address as base reg plus displacement. */ |
5163 | if (GET_CODE (addr) == REG) | |
5164 | basereg = addr, displacement = 0; | |
5165 | else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT) | |
5166 | basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1)); | |
5167 | else | |
5168 | abort (); | |
5169 | ||
5170 | /* We accept vars reached via the containing function's | |
5171 | incoming arg pointer and via its stack variables pointer. */ | |
5172 | if (basereg == fp->internal_arg_pointer) | |
5173 | { | |
5174 | /* If reached via arg pointer, get the arg pointer value | |
5175 | out of that function's stack frame. | |
5176 | ||
5177 | There are two cases: If a separate ap is needed, allocate a | |
5178 | slot in the outer function for it and dereference it that way. | |
5179 | This is correct even if the real ap is actually a pseudo. | |
5180 | Otherwise, just adjust the offset from the frame pointer to | |
5181 | compensate. */ | |
5182 | ||
5183 | #ifdef NEED_SEPARATE_AP | |
5184 | rtx addr; | |
5185 | ||
5186 | if (fp->arg_pointer_save_area == 0) | |
5187 | fp->arg_pointer_save_area | |
5188 | = assign_outer_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0, fp); | |
5189 | ||
5190 | addr = fix_lexical_addr (XEXP (fp->arg_pointer_save_area, 0), var); | |
5191 | addr = memory_address (Pmode, addr); | |
5192 | ||
38a448ca | 5193 | base = copy_to_reg (gen_rtx_MEM (Pmode, addr)); |
6f086dfc RS |
5194 | #else |
5195 | displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET); | |
86f8eff3 | 5196 | base = lookup_static_chain (var); |
6f086dfc RS |
5197 | #endif |
5198 | } | |
5199 | ||
5200 | else if (basereg == virtual_stack_vars_rtx) | |
5201 | { | |
5202 | /* This is the same code as lookup_static_chain, duplicated here to | |
5203 | avoid an extra call to decl_function_context. */ | |
5204 | tree link; | |
5205 | ||
5206 | for (link = context_display; link; link = TREE_CHAIN (link)) | |
5207 | if (TREE_PURPOSE (link) == context) | |
5208 | { | |
5209 | base = RTL_EXPR_RTL (TREE_VALUE (link)); | |
5210 | break; | |
5211 | } | |
5212 | } | |
5213 | ||
5214 | if (base == 0) | |
5215 | abort (); | |
5216 | ||
5217 | /* Use same offset, relative to appropriate static chain or argument | |
5218 | pointer. */ | |
5219 | return plus_constant (base, displacement); | |
5220 | } | |
5221 | \f | |
5222 | /* Return the address of the trampoline for entering nested fn FUNCTION. | |
5223 | If necessary, allocate a trampoline (in the stack frame) | |
5224 | and emit rtl to initialize its contents (at entry to this function). */ | |
5225 | ||
5226 | rtx | |
5227 | trampoline_address (function) | |
5228 | tree function; | |
5229 | { | |
5230 | tree link; | |
5231 | tree rtlexp; | |
5232 | rtx tramp; | |
5233 | struct function *fp; | |
5234 | tree fn_context; | |
5235 | ||
5236 | /* Find an existing trampoline and return it. */ | |
5237 | for (link = trampoline_list; link; link = TREE_CHAIN (link)) | |
5238 | if (TREE_PURPOSE (link) == function) | |
e87ee2a9 RK |
5239 | return |
5240 | round_trampoline_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0)); | |
5241 | ||
6f086dfc RS |
5242 | for (fp = outer_function_chain; fp; fp = fp->next) |
5243 | for (link = fp->trampoline_list; link; link = TREE_CHAIN (link)) | |
5244 | if (TREE_PURPOSE (link) == function) | |
5245 | { | |
5246 | tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0), | |
5247 | function); | |
5248 | return round_trampoline_addr (tramp); | |
5249 | } | |
5250 | ||
5251 | /* None exists; we must make one. */ | |
5252 | ||
5253 | /* Find the `struct function' for the function containing FUNCTION. */ | |
5254 | fp = 0; | |
5255 | fn_context = decl_function_context (function); | |
4ac74fb8 RK |
5256 | if (fn_context != current_function_decl |
5257 | && fn_context != inline_function_decl) | |
6f086dfc RS |
5258 | for (fp = outer_function_chain; fp; fp = fp->next) |
5259 | if (fp->decl == fn_context) | |
5260 | break; | |
5261 | ||
5262 | /* Allocate run-time space for this trampoline | |
5263 | (usually in the defining function's stack frame). */ | |
5264 | #ifdef ALLOCATE_TRAMPOLINE | |
5265 | tramp = ALLOCATE_TRAMPOLINE (fp); | |
5266 | #else | |
5267 | /* If rounding needed, allocate extra space | |
5268 | to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */ | |
5269 | #ifdef TRAMPOLINE_ALIGNMENT | |
b02ab63a RK |
5270 | #define TRAMPOLINE_REAL_SIZE \ |
5271 | (TRAMPOLINE_SIZE + (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT) - 1) | |
6f086dfc RS |
5272 | #else |
5273 | #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE) | |
5274 | #endif | |
5275 | if (fp != 0) | |
5276 | tramp = assign_outer_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0, fp); | |
5277 | else | |
5278 | tramp = assign_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0); | |
5279 | #endif | |
5280 | ||
5281 | /* Record the trampoline for reuse and note it for later initialization | |
5282 | by expand_function_end. */ | |
5283 | if (fp != 0) | |
5284 | { | |
28498644 RK |
5285 | push_obstacks (fp->function_maybepermanent_obstack, |
5286 | fp->function_maybepermanent_obstack); | |
6f086dfc RS |
5287 | rtlexp = make_node (RTL_EXPR); |
5288 | RTL_EXPR_RTL (rtlexp) = tramp; | |
5289 | fp->trampoline_list = tree_cons (function, rtlexp, fp->trampoline_list); | |
5290 | pop_obstacks (); | |
5291 | } | |
5292 | else | |
5293 | { | |
5294 | /* Make the RTL_EXPR node temporary, not momentary, so that the | |
5295 | trampoline_list doesn't become garbage. */ | |
5296 | int momentary = suspend_momentary (); | |
5297 | rtlexp = make_node (RTL_EXPR); | |
5298 | resume_momentary (momentary); | |
5299 | ||
5300 | RTL_EXPR_RTL (rtlexp) = tramp; | |
5301 | trampoline_list = tree_cons (function, rtlexp, trampoline_list); | |
5302 | } | |
5303 | ||
5304 | tramp = fix_lexical_addr (XEXP (tramp, 0), function); | |
5305 | return round_trampoline_addr (tramp); | |
5306 | } | |
5307 | ||
5308 | /* Given a trampoline address, | |
5309 | round it to multiple of TRAMPOLINE_ALIGNMENT. */ | |
5310 | ||
5311 | static rtx | |
5312 | round_trampoline_addr (tramp) | |
5313 | rtx tramp; | |
5314 | { | |
5315 | #ifdef TRAMPOLINE_ALIGNMENT | |
5316 | /* Round address up to desired boundary. */ | |
5317 | rtx temp = gen_reg_rtx (Pmode); | |
5318 | temp = expand_binop (Pmode, add_optab, tramp, | |
b02ab63a | 5319 | GEN_INT (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT - 1), |
6f086dfc RS |
5320 | temp, 0, OPTAB_LIB_WIDEN); |
5321 | tramp = expand_binop (Pmode, and_optab, temp, | |
b02ab63a | 5322 | GEN_INT (- TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT), |
6f086dfc RS |
5323 | temp, 0, OPTAB_LIB_WIDEN); |
5324 | #endif | |
5325 | return tramp; | |
5326 | } | |
5327 | \f | |
467456d0 RS |
5328 | /* The functions identify_blocks and reorder_blocks provide a way to |
5329 | reorder the tree of BLOCK nodes, for optimizers that reshuffle or | |
5330 | duplicate portions of the RTL code. Call identify_blocks before | |
5331 | changing the RTL, and call reorder_blocks after. */ | |
5332 | ||
b2a59b15 MS |
5333 | /* Put all this function's BLOCK nodes including those that are chained |
5334 | onto the first block into a vector, and return it. | |
467456d0 RS |
5335 | Also store in each NOTE for the beginning or end of a block |
5336 | the index of that block in the vector. | |
b2a59b15 | 5337 | The arguments are BLOCK, the chain of top-level blocks of the function, |
467456d0 RS |
5338 | and INSNS, the insn chain of the function. */ |
5339 | ||
5340 | tree * | |
b2a59b15 MS |
5341 | identify_blocks (block, insns) |
5342 | tree block; | |
467456d0 RS |
5343 | rtx insns; |
5344 | { | |
fc289cd1 JW |
5345 | int n_blocks; |
5346 | tree *block_vector; | |
5347 | int *block_stack; | |
467456d0 | 5348 | int depth = 0; |
b2a59b15 MS |
5349 | int next_block_number = 1; |
5350 | int current_block_number = 1; | |
467456d0 RS |
5351 | rtx insn; |
5352 | ||
b2a59b15 | 5353 | if (block == 0) |
fc289cd1 JW |
5354 | return 0; |
5355 | ||
b2a59b15 | 5356 | n_blocks = all_blocks (block, 0); |
fc289cd1 JW |
5357 | block_vector = (tree *) xmalloc (n_blocks * sizeof (tree)); |
5358 | block_stack = (int *) alloca (n_blocks * sizeof (int)); | |
5359 | ||
b2a59b15 | 5360 | all_blocks (block, block_vector); |
467456d0 RS |
5361 | |
5362 | for (insn = insns; insn; insn = NEXT_INSN (insn)) | |
5363 | if (GET_CODE (insn) == NOTE) | |
5364 | { | |
5365 | if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG) | |
5366 | { | |
5367 | block_stack[depth++] = current_block_number; | |
5368 | current_block_number = next_block_number; | |
1b2ac438 | 5369 | NOTE_BLOCK_NUMBER (insn) = next_block_number++; |
467456d0 RS |
5370 | } |
5371 | if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END) | |
5372 | { | |
1b2ac438 | 5373 | NOTE_BLOCK_NUMBER (insn) = current_block_number; |
c7fdfd49 | 5374 | current_block_number = block_stack[--depth]; |
467456d0 RS |
5375 | } |
5376 | } | |
5377 | ||
b2a59b15 MS |
5378 | if (n_blocks != next_block_number) |
5379 | abort (); | |
5380 | ||
467456d0 RS |
5381 | return block_vector; |
5382 | } | |
5383 | ||
5384 | /* Given BLOCK_VECTOR which was returned by identify_blocks, | |
5385 | and a revised instruction chain, rebuild the tree structure | |
5386 | of BLOCK nodes to correspond to the new order of RTL. | |
fc289cd1 | 5387 | The new block tree is inserted below TOP_BLOCK. |
467456d0 RS |
5388 | Returns the current top-level block. */ |
5389 | ||
5390 | tree | |
b2a59b15 | 5391 | reorder_blocks (block_vector, block, insns) |
467456d0 | 5392 | tree *block_vector; |
b2a59b15 | 5393 | tree block; |
467456d0 RS |
5394 | rtx insns; |
5395 | { | |
b2a59b15 | 5396 | tree current_block = block; |
467456d0 RS |
5397 | rtx insn; |
5398 | ||
fc289cd1 | 5399 | if (block_vector == 0) |
b2a59b15 | 5400 | return block; |
fc289cd1 | 5401 | |
b2a59b15 | 5402 | /* Prune the old trees away, so that it doesn't get in the way. */ |
fc289cd1 | 5403 | BLOCK_SUBBLOCKS (current_block) = 0; |
b2a59b15 | 5404 | BLOCK_CHAIN (current_block) = 0; |
fc289cd1 | 5405 | |
467456d0 RS |
5406 | for (insn = insns; insn; insn = NEXT_INSN (insn)) |
5407 | if (GET_CODE (insn) == NOTE) | |
5408 | { | |
5409 | if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG) | |
5410 | { | |
5411 | tree block = block_vector[NOTE_BLOCK_NUMBER (insn)]; | |
5412 | /* If we have seen this block before, copy it. */ | |
5413 | if (TREE_ASM_WRITTEN (block)) | |
5414 | block = copy_node (block); | |
fc289cd1 | 5415 | BLOCK_SUBBLOCKS (block) = 0; |
467456d0 RS |
5416 | TREE_ASM_WRITTEN (block) = 1; |
5417 | BLOCK_SUPERCONTEXT (block) = current_block; | |
5418 | BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block); | |
5419 | BLOCK_SUBBLOCKS (current_block) = block; | |
5420 | current_block = block; | |
1b2ac438 | 5421 | NOTE_SOURCE_FILE (insn) = 0; |
467456d0 RS |
5422 | } |
5423 | if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END) | |
5424 | { | |
5425 | BLOCK_SUBBLOCKS (current_block) | |
5426 | = blocks_nreverse (BLOCK_SUBBLOCKS (current_block)); | |
5427 | current_block = BLOCK_SUPERCONTEXT (current_block); | |
1b2ac438 | 5428 | NOTE_SOURCE_FILE (insn) = 0; |
467456d0 RS |
5429 | } |
5430 | } | |
5431 | ||
b2a59b15 MS |
5432 | BLOCK_SUBBLOCKS (current_block) |
5433 | = blocks_nreverse (BLOCK_SUBBLOCKS (current_block)); | |
467456d0 RS |
5434 | return current_block; |
5435 | } | |
5436 | ||
5437 | /* Reverse the order of elements in the chain T of blocks, | |
5438 | and return the new head of the chain (old last element). */ | |
5439 | ||
5440 | static tree | |
5441 | blocks_nreverse (t) | |
5442 | tree t; | |
5443 | { | |
5444 | register tree prev = 0, decl, next; | |
5445 | for (decl = t; decl; decl = next) | |
5446 | { | |
5447 | next = BLOCK_CHAIN (decl); | |
5448 | BLOCK_CHAIN (decl) = prev; | |
5449 | prev = decl; | |
5450 | } | |
5451 | return prev; | |
5452 | } | |
5453 | ||
b2a59b15 MS |
5454 | /* Count the subblocks of the list starting with BLOCK, and list them |
5455 | all into the vector VECTOR. Also clear TREE_ASM_WRITTEN in all | |
5456 | blocks. */ | |
467456d0 RS |
5457 | |
5458 | static int | |
5459 | all_blocks (block, vector) | |
5460 | tree block; | |
5461 | tree *vector; | |
5462 | { | |
b2a59b15 MS |
5463 | int n_blocks = 0; |
5464 | ||
5465 | while (block) | |
5466 | { | |
5467 | TREE_ASM_WRITTEN (block) = 0; | |
5468 | ||
5469 | /* Record this block. */ | |
5470 | if (vector) | |
5471 | vector[n_blocks] = block; | |
5472 | ||
5473 | ++n_blocks; | |
5474 | ||
5475 | /* Record the subblocks, and their subblocks... */ | |
5476 | n_blocks += all_blocks (BLOCK_SUBBLOCKS (block), | |
5477 | vector ? vector + n_blocks : 0); | |
5478 | block = BLOCK_CHAIN (block); | |
5479 | } | |
467456d0 RS |
5480 | |
5481 | return n_blocks; | |
5482 | } | |
5483 | \f | |
6f086dfc RS |
5484 | /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node) |
5485 | and initialize static variables for generating RTL for the statements | |
5486 | of the function. */ | |
5487 | ||
5488 | void | |
5489 | init_function_start (subr, filename, line) | |
5490 | tree subr; | |
5491 | char *filename; | |
5492 | int line; | |
5493 | { | |
6f086dfc RS |
5494 | init_stmt_for_function (); |
5495 | ||
5496 | cse_not_expected = ! optimize; | |
5497 | ||
5498 | /* Caller save not needed yet. */ | |
5499 | caller_save_needed = 0; | |
5500 | ||
5501 | /* No stack slots have been made yet. */ | |
5502 | stack_slot_list = 0; | |
5503 | ||
5504 | /* There is no stack slot for handling nonlocal gotos. */ | |
ba716ac9 | 5505 | nonlocal_goto_handler_slots = 0; |
6f086dfc RS |
5506 | nonlocal_goto_stack_level = 0; |
5507 | ||
5508 | /* No labels have been declared for nonlocal use. */ | |
5509 | nonlocal_labels = 0; | |
5510 | ||
5511 | /* No function calls so far in this function. */ | |
5512 | function_call_count = 0; | |
5513 | ||
5514 | /* No parm regs have been allocated. | |
5515 | (This is important for output_inline_function.) */ | |
5516 | max_parm_reg = LAST_VIRTUAL_REGISTER + 1; | |
5517 | ||
5518 | /* Initialize the RTL mechanism. */ | |
5519 | init_emit (); | |
5520 | ||
5521 | /* Initialize the queue of pending postincrement and postdecrements, | |
5522 | and some other info in expr.c. */ | |
5523 | init_expr (); | |
5524 | ||
5525 | /* We haven't done register allocation yet. */ | |
5526 | reg_renumber = 0; | |
5527 | ||
5528 | init_const_rtx_hash_table (); | |
5529 | ||
a1d7ffe3 | 5530 | current_function_name = (*decl_printable_name) (subr, 2); |
6f086dfc RS |
5531 | |
5532 | /* Nonzero if this is a nested function that uses a static chain. */ | |
5533 | ||
5534 | current_function_needs_context | |
38ee6ed9 JM |
5535 | = (decl_function_context (current_function_decl) != 0 |
5536 | && ! DECL_NO_STATIC_CHAIN (current_function_decl)); | |
6f086dfc RS |
5537 | |
5538 | /* Set if a call to setjmp is seen. */ | |
5539 | current_function_calls_setjmp = 0; | |
5540 | ||
5541 | /* Set if a call to longjmp is seen. */ | |
5542 | current_function_calls_longjmp = 0; | |
5543 | ||
5544 | current_function_calls_alloca = 0; | |
5545 | current_function_has_nonlocal_label = 0; | |
8634413a | 5546 | current_function_has_nonlocal_goto = 0; |
6f086dfc | 5547 | current_function_contains_functions = 0; |
fdb8a883 | 5548 | current_function_sp_is_unchanging = 0; |
173cd503 | 5549 | current_function_is_thunk = 0; |
6f086dfc RS |
5550 | |
5551 | current_function_returns_pcc_struct = 0; | |
5552 | current_function_returns_struct = 0; | |
5553 | current_function_epilogue_delay_list = 0; | |
5554 | current_function_uses_const_pool = 0; | |
5555 | current_function_uses_pic_offset_table = 0; | |
aeb302bb | 5556 | current_function_cannot_inline = 0; |
6f086dfc RS |
5557 | |
5558 | /* We have not yet needed to make a label to jump to for tail-recursion. */ | |
5559 | tail_recursion_label = 0; | |
5560 | ||
5561 | /* We haven't had a need to make a save area for ap yet. */ | |
5562 | ||
5563 | arg_pointer_save_area = 0; | |
5564 | ||
5565 | /* No stack slots allocated yet. */ | |
5566 | frame_offset = 0; | |
5567 | ||
5568 | /* No SAVE_EXPRs in this function yet. */ | |
5569 | save_expr_regs = 0; | |
5570 | ||
5571 | /* No RTL_EXPRs in this function yet. */ | |
5572 | rtl_expr_chain = 0; | |
5573 | ||
bc0ebdf9 RK |
5574 | /* Set up to allocate temporaries. */ |
5575 | init_temp_slots (); | |
6f086dfc RS |
5576 | |
5577 | /* Within function body, compute a type's size as soon it is laid out. */ | |
5578 | immediate_size_expand++; | |
5579 | ||
d9a98e1a RK |
5580 | /* We haven't made any trampolines for this function yet. */ |
5581 | trampoline_list = 0; | |
5582 | ||
6f086dfc RS |
5583 | init_pending_stack_adjust (); |
5584 | inhibit_defer_pop = 0; | |
5585 | ||
5586 | current_function_outgoing_args_size = 0; | |
5587 | ||
6f086dfc | 5588 | /* Prevent ever trying to delete the first instruction of a function. |
b274104c PB |
5589 | Also tell final how to output a linenum before the function prologue. |
5590 | Note linenums could be missing, e.g. when compiling a Java .class file. */ | |
5591 | if (line > 0) | |
5592 | emit_line_note (filename, line); | |
6f086dfc RS |
5593 | |
5594 | /* Make sure first insn is a note even if we don't want linenums. | |
5595 | This makes sure the first insn will never be deleted. | |
5596 | Also, final expects a note to appear there. */ | |
5f4f0e22 | 5597 | emit_note (NULL_PTR, NOTE_INSN_DELETED); |
6f086dfc RS |
5598 | |
5599 | /* Set flags used by final.c. */ | |
5600 | if (aggregate_value_p (DECL_RESULT (subr))) | |
5601 | { | |
5602 | #ifdef PCC_STATIC_STRUCT_RETURN | |
1b8297c1 | 5603 | current_function_returns_pcc_struct = 1; |
6f086dfc | 5604 | #endif |
1b8297c1 | 5605 | current_function_returns_struct = 1; |
6f086dfc RS |
5606 | } |
5607 | ||
5608 | /* Warn if this value is an aggregate type, | |
5609 | regardless of which calling convention we are using for it. */ | |
5610 | if (warn_aggregate_return | |
05e3bdb9 | 5611 | && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr)))) |
6f086dfc RS |
5612 | warning ("function returns an aggregate"); |
5613 | ||
5614 | current_function_returns_pointer | |
8eda074c | 5615 | = POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (subr))); |
6f086dfc RS |
5616 | |
5617 | /* Indicate that we need to distinguish between the return value of the | |
5618 | present function and the return value of a function being called. */ | |
5619 | rtx_equal_function_value_matters = 1; | |
5620 | ||
5621 | /* Indicate that we have not instantiated virtual registers yet. */ | |
5622 | virtuals_instantiated = 0; | |
5623 | ||
5624 | /* Indicate we have no need of a frame pointer yet. */ | |
5625 | frame_pointer_needed = 0; | |
5626 | ||
ebb904cb | 5627 | /* By default assume not varargs or stdarg. */ |
6f086dfc | 5628 | current_function_varargs = 0; |
ebb904cb | 5629 | current_function_stdarg = 0; |
6f086dfc RS |
5630 | } |
5631 | ||
5632 | /* Indicate that the current function uses extra args | |
5633 | not explicitly mentioned in the argument list in any fashion. */ | |
5634 | ||
5635 | void | |
5636 | mark_varargs () | |
5637 | { | |
5638 | current_function_varargs = 1; | |
5639 | } | |
5640 | ||
5641 | /* Expand a call to __main at the beginning of a possible main function. */ | |
5642 | ||
e2fd1d94 JM |
5643 | #if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main) |
5644 | #undef HAS_INIT_SECTION | |
5645 | #define HAS_INIT_SECTION | |
5646 | #endif | |
5647 | ||
6f086dfc RS |
5648 | void |
5649 | expand_main_function () | |
5650 | { | |
e2fd1d94 | 5651 | #if !defined (HAS_INIT_SECTION) |
b93a436e JL |
5652 | emit_library_call (gen_rtx_SYMBOL_REF (Pmode, NAME__MAIN), 0, |
5653 | VOIDmode, 0); | |
e2fd1d94 | 5654 | #endif /* not HAS_INIT_SECTION */ |
6f086dfc RS |
5655 | } |
5656 | \f | |
c20bf1f3 JB |
5657 | extern struct obstack permanent_obstack; |
5658 | ||
6f086dfc RS |
5659 | /* Start the RTL for a new function, and set variables used for |
5660 | emitting RTL. | |
5661 | SUBR is the FUNCTION_DECL node. | |
5662 | PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with | |
5663 | the function's parameters, which must be run at any return statement. */ | |
5664 | ||
5665 | void | |
5666 | expand_function_start (subr, parms_have_cleanups) | |
5667 | tree subr; | |
5668 | int parms_have_cleanups; | |
5669 | { | |
5670 | register int i; | |
5671 | tree tem; | |
4e86caed | 5672 | rtx last_ptr = NULL_RTX; |
6f086dfc RS |
5673 | |
5674 | /* Make sure volatile mem refs aren't considered | |
5675 | valid operands of arithmetic insns. */ | |
5676 | init_recog_no_volatile (); | |
5677 | ||
7d384cc0 KR |
5678 | /* Set this before generating any memory accesses. */ |
5679 | current_function_check_memory_usage | |
5680 | = (flag_check_memory_usage | |
5681 | && ! DECL_NO_CHECK_MEMORY_USAGE (current_function_decl)); | |
5682 | ||
07417085 KR |
5683 | current_function_instrument_entry_exit |
5684 | = (flag_instrument_function_entry_exit | |
5685 | && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr)); | |
5686 | ||
6f086dfc RS |
5687 | /* If function gets a static chain arg, store it in the stack frame. |
5688 | Do this first, so it gets the first stack slot offset. */ | |
5689 | if (current_function_needs_context) | |
3e2481e9 JW |
5690 | { |
5691 | last_ptr = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0); | |
f0c51a1e | 5692 | |
f0c51a1e RK |
5693 | /* Delay copying static chain if it is not a register to avoid |
5694 | conflicts with regs used for parameters. */ | |
f95182a4 ILT |
5695 | if (! SMALL_REGISTER_CLASSES |
5696 | || GET_CODE (static_chain_incoming_rtx) == REG) | |
f0c51a1e | 5697 | emit_move_insn (last_ptr, static_chain_incoming_rtx); |
3e2481e9 | 5698 | } |
6f086dfc RS |
5699 | |
5700 | /* If the parameters of this function need cleaning up, get a label | |
5701 | for the beginning of the code which executes those cleanups. This must | |
5702 | be done before doing anything with return_label. */ | |
5703 | if (parms_have_cleanups) | |
5704 | cleanup_label = gen_label_rtx (); | |
5705 | else | |
5706 | cleanup_label = 0; | |
5707 | ||
5708 | /* Make the label for return statements to jump to, if this machine | |
5709 | does not have a one-instruction return and uses an epilogue, | |
5710 | or if it returns a structure, or if it has parm cleanups. */ | |
5711 | #ifdef HAVE_return | |
5712 | if (cleanup_label == 0 && HAVE_return | |
07417085 | 5713 | && ! current_function_instrument_entry_exit |
6f086dfc RS |
5714 | && ! current_function_returns_pcc_struct |
5715 | && ! (current_function_returns_struct && ! optimize)) | |
5716 | return_label = 0; | |
5717 | else | |
5718 | return_label = gen_label_rtx (); | |
5719 | #else | |
5720 | return_label = gen_label_rtx (); | |
5721 | #endif | |
5722 | ||
5723 | /* Initialize rtx used to return the value. */ | |
5724 | /* Do this before assign_parms so that we copy the struct value address | |
5725 | before any library calls that assign parms might generate. */ | |
5726 | ||
5727 | /* Decide whether to return the value in memory or in a register. */ | |
5728 | if (aggregate_value_p (DECL_RESULT (subr))) | |
5729 | { | |
5730 | /* Returning something that won't go in a register. */ | |
4acc00bf | 5731 | register rtx value_address = 0; |
6f086dfc RS |
5732 | |
5733 | #ifdef PCC_STATIC_STRUCT_RETURN | |
5734 | if (current_function_returns_pcc_struct) | |
5735 | { | |
5736 | int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr))); | |
5737 | value_address = assemble_static_space (size); | |
5738 | } | |
5739 | else | |
5740 | #endif | |
5741 | { | |
5742 | /* Expect to be passed the address of a place to store the value. | |
5743 | If it is passed as an argument, assign_parms will take care of | |
5744 | it. */ | |
5745 | if (struct_value_incoming_rtx) | |
5746 | { | |
5747 | value_address = gen_reg_rtx (Pmode); | |
5748 | emit_move_insn (value_address, struct_value_incoming_rtx); | |
5749 | } | |
5750 | } | |
5751 | if (value_address) | |
ccdecf58 RK |
5752 | { |
5753 | DECL_RTL (DECL_RESULT (subr)) | |
38a448ca | 5754 | = gen_rtx_MEM (DECL_MODE (DECL_RESULT (subr)), value_address); |
c6df88cb MM |
5755 | MEM_SET_IN_STRUCT_P (DECL_RTL (DECL_RESULT (subr)), |
5756 | AGGREGATE_TYPE_P (TREE_TYPE | |
5757 | (DECL_RESULT | |
5758 | (subr)))); | |
ccdecf58 | 5759 | } |
6f086dfc RS |
5760 | } |
5761 | else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode) | |
5762 | /* If return mode is void, this decl rtl should not be used. */ | |
5763 | DECL_RTL (DECL_RESULT (subr)) = 0; | |
07417085 | 5764 | else if (parms_have_cleanups || current_function_instrument_entry_exit) |
a53e14c0 RK |
5765 | { |
5766 | /* If function will end with cleanup code for parms, | |
5767 | compute the return values into a pseudo reg, | |
5768 | which we will copy into the true return register | |
5769 | after the cleanups are done. */ | |
5770 | ||
5771 | enum machine_mode mode = DECL_MODE (DECL_RESULT (subr)); | |
a5a52dbc | 5772 | |
a53e14c0 RK |
5773 | #ifdef PROMOTE_FUNCTION_RETURN |
5774 | tree type = TREE_TYPE (DECL_RESULT (subr)); | |
5775 | int unsignedp = TREE_UNSIGNED (type); | |
5776 | ||
a5a52dbc | 5777 | mode = promote_mode (type, mode, &unsignedp, 1); |
a53e14c0 RK |
5778 | #endif |
5779 | ||
5780 | DECL_RTL (DECL_RESULT (subr)) = gen_reg_rtx (mode); | |
5781 | } | |
6f086dfc RS |
5782 | else |
5783 | /* Scalar, returned in a register. */ | |
5784 | { | |
5785 | #ifdef FUNCTION_OUTGOING_VALUE | |
5786 | DECL_RTL (DECL_RESULT (subr)) | |
5787 | = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr); | |
5788 | #else | |
5789 | DECL_RTL (DECL_RESULT (subr)) | |
5790 | = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr); | |
5791 | #endif | |
5792 | ||
5793 | /* Mark this reg as the function's return value. */ | |
5794 | if (GET_CODE (DECL_RTL (DECL_RESULT (subr))) == REG) | |
5795 | { | |
5796 | REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr))) = 1; | |
5797 | /* Needed because we may need to move this to memory | |
5798 | in case it's a named return value whose address is taken. */ | |
a82ad570 | 5799 | DECL_REGISTER (DECL_RESULT (subr)) = 1; |
6f086dfc RS |
5800 | } |
5801 | } | |
5802 | ||
5803 | /* Initialize rtx for parameters and local variables. | |
5804 | In some cases this requires emitting insns. */ | |
5805 | ||
5806 | assign_parms (subr, 0); | |
5807 | ||
f0c51a1e RK |
5808 | /* Copy the static chain now if it wasn't a register. The delay is to |
5809 | avoid conflicts with the parameter passing registers. */ | |
5810 | ||
f95182a4 | 5811 | if (SMALL_REGISTER_CLASSES && current_function_needs_context) |
f0c51a1e RK |
5812 | if (GET_CODE (static_chain_incoming_rtx) != REG) |
5813 | emit_move_insn (last_ptr, static_chain_incoming_rtx); | |
f0c51a1e | 5814 | |
6f086dfc RS |
5815 | /* The following was moved from init_function_start. |
5816 | The move is supposed to make sdb output more accurate. */ | |
5817 | /* Indicate the beginning of the function body, | |
5818 | as opposed to parm setup. */ | |
5f4f0e22 | 5819 | emit_note (NULL_PTR, NOTE_INSN_FUNCTION_BEG); |
6f086dfc RS |
5820 | |
5821 | /* If doing stupid allocation, mark parms as born here. */ | |
5822 | ||
5823 | if (GET_CODE (get_last_insn ()) != NOTE) | |
5f4f0e22 | 5824 | emit_note (NULL_PTR, NOTE_INSN_DELETED); |
6f086dfc RS |
5825 | parm_birth_insn = get_last_insn (); |
5826 | ||
5827 | if (obey_regdecls) | |
5828 | { | |
5829 | for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++) | |
5830 | use_variable (regno_reg_rtx[i]); | |
5831 | ||
5832 | if (current_function_internal_arg_pointer != virtual_incoming_args_rtx) | |
5833 | use_variable (current_function_internal_arg_pointer); | |
5834 | } | |
5835 | ||
6d7306f7 JM |
5836 | context_display = 0; |
5837 | if (current_function_needs_context) | |
ac9e20f0 | 5838 | { |
6d7306f7 JM |
5839 | /* Fetch static chain values for containing functions. */ |
5840 | tem = decl_function_context (current_function_decl); | |
5841 | /* If not doing stupid register allocation copy the static chain | |
5842 | pointer into a pseudo. If we have small register classes, copy | |
5843 | the value from memory if static_chain_incoming_rtx is a REG. If | |
5844 | we do stupid register allocation, we use the stack address | |
5845 | generated above. */ | |
5846 | if (tem && ! obey_regdecls) | |
5847 | { | |
6d7306f7 JM |
5848 | /* If the static chain originally came in a register, put it back |
5849 | there, then move it out in the next insn. The reason for | |
5850 | this peculiar code is to satisfy function integration. */ | |
f95182a4 ILT |
5851 | if (SMALL_REGISTER_CLASSES |
5852 | && GET_CODE (static_chain_incoming_rtx) == REG) | |
6d7306f7 | 5853 | emit_move_insn (static_chain_incoming_rtx, last_ptr); |
6d7306f7 JM |
5854 | last_ptr = copy_to_reg (static_chain_incoming_rtx); |
5855 | } | |
ac9e20f0 | 5856 | |
6d7306f7 JM |
5857 | while (tem) |
5858 | { | |
5859 | tree rtlexp = make_node (RTL_EXPR); | |
6f086dfc | 5860 | |
6d7306f7 JM |
5861 | RTL_EXPR_RTL (rtlexp) = last_ptr; |
5862 | context_display = tree_cons (tem, rtlexp, context_display); | |
5863 | tem = decl_function_context (tem); | |
5864 | if (tem == 0) | |
5865 | break; | |
5866 | /* Chain thru stack frames, assuming pointer to next lexical frame | |
5867 | is found at the place we always store it. */ | |
6f086dfc | 5868 | #ifdef FRAME_GROWS_DOWNWARD |
6d7306f7 | 5869 | last_ptr = plus_constant (last_ptr, - GET_MODE_SIZE (Pmode)); |
6f086dfc | 5870 | #endif |
38a448ca RH |
5871 | last_ptr = copy_to_reg (gen_rtx_MEM (Pmode, |
5872 | memory_address (Pmode, last_ptr))); | |
6d7306f7 JM |
5873 | |
5874 | /* If we are not optimizing, ensure that we know that this | |
5875 | piece of context is live over the entire function. */ | |
5876 | if (! optimize) | |
38a448ca RH |
5877 | save_expr_regs = gen_rtx_EXPR_LIST (VOIDmode, last_ptr, |
5878 | save_expr_regs); | |
6d7306f7 | 5879 | } |
6f086dfc RS |
5880 | } |
5881 | ||
07417085 KR |
5882 | if (current_function_instrument_entry_exit) |
5883 | { | |
5884 | rtx fun = DECL_RTL (current_function_decl); | |
5885 | if (GET_CODE (fun) == MEM) | |
5886 | fun = XEXP (fun, 0); | |
5887 | else | |
5888 | abort (); | |
5889 | emit_library_call (profile_function_entry_libfunc, 0, VOIDmode, 2, | |
5890 | fun, Pmode, | |
5891 | expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS, | |
5892 | 0, | |
5893 | hard_frame_pointer_rtx), | |
5894 | Pmode); | |
5895 | } | |
5896 | ||
6f086dfc RS |
5897 | /* After the display initializations is where the tail-recursion label |
5898 | should go, if we end up needing one. Ensure we have a NOTE here | |
5899 | since some things (like trampolines) get placed before this. */ | |
5f4f0e22 | 5900 | tail_recursion_reentry = emit_note (NULL_PTR, NOTE_INSN_DELETED); |
6f086dfc RS |
5901 | |
5902 | /* Evaluate now the sizes of any types declared among the arguments. */ | |
5903 | for (tem = nreverse (get_pending_sizes ()); tem; tem = TREE_CHAIN (tem)) | |
7b05e286 | 5904 | { |
86fa911a RK |
5905 | expand_expr (TREE_VALUE (tem), const0_rtx, VOIDmode, |
5906 | EXPAND_MEMORY_USE_BAD); | |
7b05e286 JW |
5907 | /* Flush the queue in case this parameter declaration has |
5908 | side-effects. */ | |
5909 | emit_queue (); | |
5910 | } | |
6f086dfc RS |
5911 | |
5912 | /* Make sure there is a line number after the function entry setup code. */ | |
5913 | force_next_line_note (); | |
5914 | } | |
5915 | \f | |
5916 | /* Generate RTL for the end of the current function. | |
980697fd | 5917 | FILENAME and LINE are the current position in the source file. |
6f086dfc | 5918 | |
980697fd | 5919 | It is up to language-specific callers to do cleanups for parameters-- |
1be07046 | 5920 | or else, supply 1 for END_BINDINGS and we will call expand_end_bindings. */ |
6f086dfc RS |
5921 | |
5922 | void | |
1be07046 | 5923 | expand_function_end (filename, line, end_bindings) |
6f086dfc RS |
5924 | char *filename; |
5925 | int line; | |
1be07046 | 5926 | int end_bindings; |
6f086dfc RS |
5927 | { |
5928 | register int i; | |
5929 | tree link; | |
5930 | ||
1e2414db | 5931 | #ifdef TRAMPOLINE_TEMPLATE |
6f086dfc | 5932 | static rtx initial_trampoline; |
1e2414db | 5933 | #endif |
6f086dfc RS |
5934 | |
5935 | #ifdef NON_SAVING_SETJMP | |
5936 | /* Don't put any variables in registers if we call setjmp | |
5937 | on a machine that fails to restore the registers. */ | |
5938 | if (NON_SAVING_SETJMP && current_function_calls_setjmp) | |
5939 | { | |
b88a3142 RK |
5940 | if (DECL_INITIAL (current_function_decl) != error_mark_node) |
5941 | setjmp_protect (DECL_INITIAL (current_function_decl)); | |
5942 | ||
6f086dfc RS |
5943 | setjmp_protect_args (); |
5944 | } | |
5945 | #endif | |
5946 | ||
5947 | /* Save the argument pointer if a save area was made for it. */ | |
5948 | if (arg_pointer_save_area) | |
5949 | { | |
ea0f9a85 JW |
5950 | /* arg_pointer_save_area may not be a valid memory address, so we |
5951 | have to check it and fix it if necessary. */ | |
5952 | rtx seq; | |
5953 | start_sequence (); | |
5954 | emit_move_insn (validize_mem (arg_pointer_save_area), | |
5955 | virtual_incoming_args_rtx); | |
5956 | seq = gen_sequence (); | |
5957 | end_sequence (); | |
5958 | emit_insn_before (seq, tail_recursion_reentry); | |
6f086dfc RS |
5959 | } |
5960 | ||
5961 | /* Initialize any trampolines required by this function. */ | |
5962 | for (link = trampoline_list; link; link = TREE_CHAIN (link)) | |
5963 | { | |
5964 | tree function = TREE_PURPOSE (link); | |
5965 | rtx context = lookup_static_chain (function); | |
5966 | rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link)); | |
7a87758d | 5967 | #ifdef TRAMPOLINE_TEMPLATE |
1e2414db | 5968 | rtx blktramp; |
7a87758d | 5969 | #endif |
6f086dfc RS |
5970 | rtx seq; |
5971 | ||
1e2414db | 5972 | #ifdef TRAMPOLINE_TEMPLATE |
6f086dfc RS |
5973 | /* First make sure this compilation has a template for |
5974 | initializing trampolines. */ | |
5975 | if (initial_trampoline == 0) | |
86f8eff3 RK |
5976 | { |
5977 | end_temporary_allocation (); | |
5978 | initial_trampoline | |
38a448ca | 5979 | = gen_rtx_MEM (BLKmode, assemble_trampoline_template ()); |
86f8eff3 RK |
5980 | resume_temporary_allocation (); |
5981 | } | |
1e2414db | 5982 | #endif |
6f086dfc RS |
5983 | |
5984 | /* Generate insns to initialize the trampoline. */ | |
5985 | start_sequence (); | |
1e2414db RK |
5986 | tramp = round_trampoline_addr (XEXP (tramp, 0)); |
5987 | #ifdef TRAMPOLINE_TEMPLATE | |
5988 | blktramp = change_address (initial_trampoline, BLKmode, tramp); | |
5989 | emit_block_move (blktramp, initial_trampoline, | |
5990 | GEN_INT (TRAMPOLINE_SIZE), | |
189cc377 | 5991 | TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT); |
1e2414db RK |
5992 | #endif |
5993 | INITIALIZE_TRAMPOLINE (tramp, XEXP (DECL_RTL (function), 0), context); | |
6f086dfc RS |
5994 | seq = get_insns (); |
5995 | end_sequence (); | |
5996 | ||
5997 | /* Put those insns at entry to the containing function (this one). */ | |
5998 | emit_insns_before (seq, tail_recursion_reentry); | |
5999 | } | |
6f086dfc | 6000 | |
11044f66 RK |
6001 | /* If we are doing stack checking and this function makes calls, |
6002 | do a stack probe at the start of the function to ensure we have enough | |
6003 | space for another stack frame. */ | |
6004 | if (flag_stack_check && ! STACK_CHECK_BUILTIN) | |
6005 | { | |
6006 | rtx insn, seq; | |
6007 | ||
6008 | for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) | |
6009 | if (GET_CODE (insn) == CALL_INSN) | |
6010 | { | |
6011 | start_sequence (); | |
6012 | probe_stack_range (STACK_CHECK_PROTECT, | |
6013 | GEN_INT (STACK_CHECK_MAX_FRAME_SIZE)); | |
6014 | seq = get_insns (); | |
6015 | end_sequence (); | |
6016 | emit_insns_before (seq, tail_recursion_reentry); | |
6017 | break; | |
6018 | } | |
6019 | } | |
6020 | ||
db8717d9 RK |
6021 | /* Warn about unused parms if extra warnings were specified. */ |
6022 | if (warn_unused && extra_warnings) | |
6f086dfc | 6023 | { |
db8717d9 | 6024 | tree decl; |
6f086dfc RS |
6025 | |
6026 | for (decl = DECL_ARGUMENTS (current_function_decl); | |
6027 | decl; decl = TREE_CHAIN (decl)) | |
497dc802 JM |
6028 | if (! TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL |
6029 | && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl)) | |
6f086dfc RS |
6030 | warning_with_decl (decl, "unused parameter `%s'"); |
6031 | } | |
6f086dfc RS |
6032 | |
6033 | /* Delete handlers for nonlocal gotos if nothing uses them. */ | |
ba716ac9 BS |
6034 | if (nonlocal_goto_handler_slots != 0 |
6035 | && ! current_function_has_nonlocal_label) | |
6f086dfc RS |
6036 | delete_handlers (); |
6037 | ||
6038 | /* End any sequences that failed to be closed due to syntax errors. */ | |
6039 | while (in_sequence_p ()) | |
5f4f0e22 | 6040 | end_sequence (); |
6f086dfc RS |
6041 | |
6042 | /* Outside function body, can't compute type's actual size | |
6043 | until next function's body starts. */ | |
6044 | immediate_size_expand--; | |
6045 | ||
6046 | /* If doing stupid register allocation, | |
6047 | mark register parms as dying here. */ | |
6048 | ||
6049 | if (obey_regdecls) | |
6050 | { | |
6051 | rtx tem; | |
6052 | for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++) | |
6053 | use_variable (regno_reg_rtx[i]); | |
6054 | ||
6055 | /* Likewise for the regs of all the SAVE_EXPRs in the function. */ | |
6056 | ||
6057 | for (tem = save_expr_regs; tem; tem = XEXP (tem, 1)) | |
6058 | { | |
6059 | use_variable (XEXP (tem, 0)); | |
6060 | use_variable_after (XEXP (tem, 0), parm_birth_insn); | |
6061 | } | |
6062 | ||
6063 | if (current_function_internal_arg_pointer != virtual_incoming_args_rtx) | |
6064 | use_variable (current_function_internal_arg_pointer); | |
6065 | } | |
6066 | ||
6067 | clear_pending_stack_adjust (); | |
6068 | do_pending_stack_adjust (); | |
6069 | ||
6070 | /* Mark the end of the function body. | |
6071 | If control reaches this insn, the function can drop through | |
6072 | without returning a value. */ | |
5f4f0e22 | 6073 | emit_note (NULL_PTR, NOTE_INSN_FUNCTION_END); |
6f086dfc | 6074 | |
82e415a3 DE |
6075 | /* Must mark the last line number note in the function, so that the test |
6076 | coverage code can avoid counting the last line twice. This just tells | |
6077 | the code to ignore the immediately following line note, since there | |
6078 | already exists a copy of this note somewhere above. This line number | |
6079 | note is still needed for debugging though, so we can't delete it. */ | |
6080 | if (flag_test_coverage) | |
6081 | emit_note (NULL_PTR, NOTE_REPEATED_LINE_NUMBER); | |
6082 | ||
6f086dfc RS |
6083 | /* Output a linenumber for the end of the function. |
6084 | SDB depends on this. */ | |
6085 | emit_line_note_force (filename, line); | |
6086 | ||
6087 | /* Output the label for the actual return from the function, | |
6088 | if one is expected. This happens either because a function epilogue | |
6089 | is used instead of a return instruction, or because a return was done | |
6090 | with a goto in order to run local cleanups, or because of pcc-style | |
6091 | structure returning. */ | |
6092 | ||
6093 | if (return_label) | |
6094 | emit_label (return_label); | |
6095 | ||
1be07046 RS |
6096 | /* C++ uses this. */ |
6097 | if (end_bindings) | |
6098 | expand_end_bindings (0, 0, 0); | |
6099 | ||
e5a1e0e8 MS |
6100 | /* Now handle any leftover exception regions that may have been |
6101 | created for the parameters. */ | |
6102 | { | |
6103 | rtx last = get_last_insn (); | |
6104 | rtx label; | |
6105 | ||
6106 | expand_leftover_cleanups (); | |
6107 | ||
6108 | /* If the above emitted any code, may sure we jump around it. */ | |
6109 | if (last != get_last_insn ()) | |
6110 | { | |
6111 | label = gen_label_rtx (); | |
6112 | last = emit_jump_insn_after (gen_jump (label), last); | |
6113 | last = emit_barrier_after (last); | |
6114 | emit_label (label); | |
6115 | } | |
6116 | } | |
6117 | ||
07417085 KR |
6118 | if (current_function_instrument_entry_exit) |
6119 | { | |
6120 | rtx fun = DECL_RTL (current_function_decl); | |
6121 | if (GET_CODE (fun) == MEM) | |
6122 | fun = XEXP (fun, 0); | |
6123 | else | |
6124 | abort (); | |
6125 | emit_library_call (profile_function_exit_libfunc, 0, VOIDmode, 2, | |
6126 | fun, Pmode, | |
6127 | expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS, | |
6128 | 0, | |
6129 | hard_frame_pointer_rtx), | |
6130 | Pmode); | |
6131 | } | |
6132 | ||
6f086dfc RS |
6133 | /* If we had calls to alloca, and this machine needs |
6134 | an accurate stack pointer to exit the function, | |
6135 | insert some code to save and restore the stack pointer. */ | |
6136 | #ifdef EXIT_IGNORE_STACK | |
6137 | if (! EXIT_IGNORE_STACK) | |
6138 | #endif | |
6139 | if (current_function_calls_alloca) | |
6140 | { | |
59257ff7 RK |
6141 | rtx tem = 0; |
6142 | ||
6143 | emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn); | |
5f4f0e22 | 6144 | emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX); |
6f086dfc RS |
6145 | } |
6146 | ||
6147 | /* If scalar return value was computed in a pseudo-reg, | |
6148 | copy that to the hard return register. */ | |
6149 | if (DECL_RTL (DECL_RESULT (current_function_decl)) != 0 | |
6150 | && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG | |
6151 | && (REGNO (DECL_RTL (DECL_RESULT (current_function_decl))) | |
6152 | >= FIRST_PSEUDO_REGISTER)) | |
6153 | { | |
6154 | rtx real_decl_result; | |
6155 | ||
6156 | #ifdef FUNCTION_OUTGOING_VALUE | |
6157 | real_decl_result | |
6158 | = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)), | |
6159 | current_function_decl); | |
6160 | #else | |
6161 | real_decl_result | |
6162 | = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)), | |
6163 | current_function_decl); | |
6164 | #endif | |
6165 | REG_FUNCTION_VALUE_P (real_decl_result) = 1; | |
ecec4441 JW |
6166 | /* If this is a BLKmode structure being returned in registers, then use |
6167 | the mode computed in expand_return. */ | |
6168 | if (GET_MODE (real_decl_result) == BLKmode) | |
6169 | PUT_MODE (real_decl_result, | |
6170 | GET_MODE (DECL_RTL (DECL_RESULT (current_function_decl)))); | |
6f086dfc RS |
6171 | emit_move_insn (real_decl_result, |
6172 | DECL_RTL (DECL_RESULT (current_function_decl))); | |
38a448ca | 6173 | emit_insn (gen_rtx_USE (VOIDmode, real_decl_result)); |
f345de42 JL |
6174 | |
6175 | /* The delay slot scheduler assumes that current_function_return_rtx | |
6176 | holds the hard register containing the return value, not a temporary | |
6177 | pseudo. */ | |
6178 | current_function_return_rtx = real_decl_result; | |
6f086dfc RS |
6179 | } |
6180 | ||
6181 | /* If returning a structure, arrange to return the address of the value | |
6182 | in a place where debuggers expect to find it. | |
6183 | ||
6184 | If returning a structure PCC style, | |
6185 | the caller also depends on this value. | |
6186 | And current_function_returns_pcc_struct is not necessarily set. */ | |
6187 | if (current_function_returns_struct | |
6188 | || current_function_returns_pcc_struct) | |
6189 | { | |
6190 | rtx value_address = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0); | |
6191 | tree type = TREE_TYPE (DECL_RESULT (current_function_decl)); | |
6192 | #ifdef FUNCTION_OUTGOING_VALUE | |
6193 | rtx outgoing | |
6194 | = FUNCTION_OUTGOING_VALUE (build_pointer_type (type), | |
6195 | current_function_decl); | |
6196 | #else | |
6197 | rtx outgoing | |
6198 | = FUNCTION_VALUE (build_pointer_type (type), | |
6199 | current_function_decl); | |
6200 | #endif | |
6201 | ||
6202 | /* Mark this as a function return value so integrate will delete the | |
6203 | assignment and USE below when inlining this function. */ | |
6204 | REG_FUNCTION_VALUE_P (outgoing) = 1; | |
6205 | ||
6206 | emit_move_insn (outgoing, value_address); | |
6207 | use_variable (outgoing); | |
6208 | } | |
6209 | ||
71038426 RH |
6210 | /* If this is an implementation of __throw, do what's necessary to |
6211 | communicate between __builtin_eh_return and the epilogue. */ | |
6212 | expand_eh_return (); | |
6213 | ||
6f086dfc RS |
6214 | /* Output a return insn if we are using one. |
6215 | Otherwise, let the rtl chain end here, to drop through | |
6216 | into the epilogue. */ | |
6217 | ||
6218 | #ifdef HAVE_return | |
6219 | if (HAVE_return) | |
6220 | { | |
6221 | emit_jump_insn (gen_return ()); | |
6222 | emit_barrier (); | |
6223 | } | |
6224 | #endif | |
6225 | ||
6226 | /* Fix up any gotos that jumped out to the outermost | |
6227 | binding level of the function. | |
6228 | Must follow emitting RETURN_LABEL. */ | |
6229 | ||
6230 | /* If you have any cleanups to do at this point, | |
6231 | and they need to create temporary variables, | |
6232 | then you will lose. */ | |
e15679f8 | 6233 | expand_fixups (get_insns ()); |
6f086dfc | 6234 | } |
bdac5f58 TW |
6235 | \f |
6236 | /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */ | |
6237 | ||
6238 | static int *prologue; | |
6239 | static int *epilogue; | |
6240 | ||
6241 | /* Create an array that records the INSN_UIDs of INSNS (either a sequence | |
6242 | or a single insn). */ | |
6243 | ||
487a6e06 | 6244 | #if defined (HAVE_prologue) || defined (HAVE_epilogue) |
bdac5f58 TW |
6245 | static int * |
6246 | record_insns (insns) | |
6247 | rtx insns; | |
6248 | { | |
6249 | int *vec; | |
6250 | ||
6251 | if (GET_CODE (insns) == SEQUENCE) | |
6252 | { | |
6253 | int len = XVECLEN (insns, 0); | |
6254 | vec = (int *) oballoc ((len + 1) * sizeof (int)); | |
6255 | vec[len] = 0; | |
6256 | while (--len >= 0) | |
6257 | vec[len] = INSN_UID (XVECEXP (insns, 0, len)); | |
6258 | } | |
6259 | else | |
6260 | { | |
6261 | vec = (int *) oballoc (2 * sizeof (int)); | |
6262 | vec[0] = INSN_UID (insns); | |
6263 | vec[1] = 0; | |
6264 | } | |
6265 | return vec; | |
6266 | } | |
6267 | ||
10914065 | 6268 | /* Determine how many INSN_UIDs in VEC are part of INSN. */ |
bdac5f58 | 6269 | |
10914065 | 6270 | static int |
bdac5f58 TW |
6271 | contains (insn, vec) |
6272 | rtx insn; | |
6273 | int *vec; | |
6274 | { | |
6275 | register int i, j; | |
6276 | ||
6277 | if (GET_CODE (insn) == INSN | |
6278 | && GET_CODE (PATTERN (insn)) == SEQUENCE) | |
6279 | { | |
10914065 | 6280 | int count = 0; |
bdac5f58 TW |
6281 | for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--) |
6282 | for (j = 0; vec[j]; j++) | |
6283 | if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == vec[j]) | |
10914065 TW |
6284 | count++; |
6285 | return count; | |
bdac5f58 TW |
6286 | } |
6287 | else | |
6288 | { | |
6289 | for (j = 0; vec[j]; j++) | |
6290 | if (INSN_UID (insn) == vec[j]) | |
10914065 | 6291 | return 1; |
bdac5f58 TW |
6292 | } |
6293 | return 0; | |
6294 | } | |
081f5e7e | 6295 | #endif /* HAVE_prologue || HAVE_epilogue */ |
bdac5f58 | 6296 | |
9faa82d8 | 6297 | /* Generate the prologue and epilogue RTL if the machine supports it. Thread |
bdac5f58 TW |
6298 | this into place with notes indicating where the prologue ends and where |
6299 | the epilogue begins. Update the basic block information when possible. */ | |
6300 | ||
6301 | void | |
6302 | thread_prologue_and_epilogue_insns (f) | |
79c9824e | 6303 | rtx f ATTRIBUTE_UNUSED; |
bdac5f58 TW |
6304 | { |
6305 | #ifdef HAVE_prologue | |
6306 | if (HAVE_prologue) | |
6307 | { | |
29a82058 | 6308 | rtx head, seq; |
bdac5f58 TW |
6309 | |
6310 | /* The first insn (a NOTE_INSN_DELETED) is followed by zero or more | |
6311 | prologue insns and a NOTE_INSN_PROLOGUE_END. */ | |
6312 | emit_note_after (NOTE_INSN_PROLOGUE_END, f); | |
6313 | seq = gen_prologue (); | |
6314 | head = emit_insn_after (seq, f); | |
6315 | ||
6316 | /* Include the new prologue insns in the first block. Ignore them | |
6317 | if they form a basic block unto themselves. */ | |
3b413743 RH |
6318 | if (x_basic_block_head && n_basic_blocks |
6319 | && GET_CODE (BLOCK_HEAD (0)) != CODE_LABEL) | |
6320 | BLOCK_HEAD (0) = NEXT_INSN (f); | |
bdac5f58 TW |
6321 | |
6322 | /* Retain a map of the prologue insns. */ | |
6323 | prologue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : head); | |
6324 | } | |
6325 | else | |
6326 | #endif | |
6327 | prologue = 0; | |
6328 | ||
6329 | #ifdef HAVE_epilogue | |
6330 | if (HAVE_epilogue) | |
6331 | { | |
6332 | rtx insn = get_last_insn (); | |
6333 | rtx prev = prev_nonnote_insn (insn); | |
6334 | ||
6335 | /* If we end with a BARRIER, we don't need an epilogue. */ | |
6336 | if (! (prev && GET_CODE (prev) == BARRIER)) | |
6337 | { | |
a78bdb38 JW |
6338 | rtx tail, seq, tem; |
6339 | rtx first_use = 0; | |
6340 | rtx last_use = 0; | |
bdac5f58 | 6341 | |
a78bdb38 JW |
6342 | /* The last basic block ends with a NOTE_INSN_EPILOGUE_BEG, the |
6343 | epilogue insns, the USE insns at the end of a function, | |
6344 | the jump insn that returns, and then a BARRIER. */ | |
bdac5f58 | 6345 | |
a78bdb38 | 6346 | /* Move the USE insns at the end of a function onto a list. */ |
bdac5f58 TW |
6347 | while (prev |
6348 | && GET_CODE (prev) == INSN | |
6349 | && GET_CODE (PATTERN (prev)) == USE) | |
6350 | { | |
a78bdb38 | 6351 | tem = prev; |
bdac5f58 | 6352 | prev = prev_nonnote_insn (prev); |
a78bdb38 JW |
6353 | |
6354 | NEXT_INSN (PREV_INSN (tem)) = NEXT_INSN (tem); | |
6355 | PREV_INSN (NEXT_INSN (tem)) = PREV_INSN (tem); | |
83eb3b0d RK |
6356 | if (first_use) |
6357 | { | |
6358 | NEXT_INSN (tem) = first_use; | |
6359 | PREV_INSN (first_use) = tem; | |
6360 | } | |
6361 | first_use = tem; | |
6362 | if (!last_use) | |
a78bdb38 | 6363 | last_use = tem; |
bdac5f58 TW |
6364 | } |
6365 | ||
a78bdb38 JW |
6366 | emit_barrier_after (insn); |
6367 | ||
bdac5f58 TW |
6368 | seq = gen_epilogue (); |
6369 | tail = emit_jump_insn_after (seq, insn); | |
a78bdb38 JW |
6370 | |
6371 | /* Insert the USE insns immediately before the return insn, which | |
6372 | must be the first instruction before the final barrier. */ | |
6373 | if (first_use) | |
6374 | { | |
6375 | tem = prev_nonnote_insn (get_last_insn ()); | |
6376 | NEXT_INSN (PREV_INSN (tem)) = first_use; | |
6377 | PREV_INSN (first_use) = PREV_INSN (tem); | |
6378 | PREV_INSN (tem) = last_use; | |
6379 | NEXT_INSN (last_use) = tem; | |
6380 | } | |
6381 | ||
bdac5f58 TW |
6382 | emit_note_after (NOTE_INSN_EPILOGUE_BEG, insn); |
6383 | ||
6384 | /* Include the new epilogue insns in the last block. Ignore | |
6385 | them if they form a basic block unto themselves. */ | |
3b413743 RH |
6386 | if (x_basic_block_end && n_basic_blocks |
6387 | && GET_CODE (BLOCK_END (n_basic_blocks - 1)) != JUMP_INSN) | |
6388 | BLOCK_END (n_basic_blocks - 1) = tail; | |
bdac5f58 TW |
6389 | |
6390 | /* Retain a map of the epilogue insns. */ | |
6391 | epilogue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : tail); | |
6392 | return; | |
6393 | } | |
6394 | } | |
6395 | #endif | |
6396 | epilogue = 0; | |
6397 | } | |
6398 | ||
6399 | /* Reposition the prologue-end and epilogue-begin notes after instruction | |
6400 | scheduling and delayed branch scheduling. */ | |
6401 | ||
6402 | void | |
6403 | reposition_prologue_and_epilogue_notes (f) | |
79c9824e | 6404 | rtx f ATTRIBUTE_UNUSED; |
bdac5f58 TW |
6405 | { |
6406 | #if defined (HAVE_prologue) || defined (HAVE_epilogue) | |
6407 | /* Reposition the prologue and epilogue notes. */ | |
6408 | if (n_basic_blocks) | |
6409 | { | |
6410 | rtx next, prev; | |
bf526252 | 6411 | int len; |
bdac5f58 TW |
6412 | |
6413 | if (prologue) | |
6414 | { | |
bf526252 RK |
6415 | register rtx insn, note = 0; |
6416 | ||
6417 | /* Scan from the beginning until we reach the last prologue insn. | |
6418 | We apparently can't depend on basic_block_{head,end} after | |
6419 | reorg has run. */ | |
6420 | for (len = 0; prologue[len]; len++) | |
6421 | ; | |
9392c110 JH |
6422 | for (insn = f; len && insn; insn = NEXT_INSN (insn)) |
6423 | { | |
6424 | if (GET_CODE (insn) == NOTE) | |
6425 | { | |
6426 | if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END) | |
6427 | note = insn; | |
6428 | } | |
6429 | else if ((len -= contains (insn, prologue)) == 0) | |
6430 | { | |
6431 | /* Find the prologue-end note if we haven't already, and | |
6432 | move it to just after the last prologue insn. */ | |
6433 | if (note == 0) | |
6434 | { | |
51723711 | 6435 | for (note = insn; (note = NEXT_INSN (note));) |
9392c110 JH |
6436 | if (GET_CODE (note) == NOTE |
6437 | && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END) | |
6438 | break; | |
6439 | } | |
c93b03c2 | 6440 | |
9392c110 JH |
6441 | next = NEXT_INSN (note); |
6442 | prev = PREV_INSN (note); | |
6443 | if (prev) | |
6444 | NEXT_INSN (prev) = next; | |
6445 | if (next) | |
6446 | PREV_INSN (next) = prev; | |
c93b03c2 | 6447 | |
3b413743 | 6448 | /* Whether or not we can depend on BLOCK_HEAD, |
c93b03c2 | 6449 | attempt to keep it up-to-date. */ |
3b413743 RH |
6450 | if (BLOCK_HEAD (0) == note) |
6451 | BLOCK_HEAD (0) = next; | |
c93b03c2 | 6452 | |
9392c110 JH |
6453 | add_insn_after (note, insn); |
6454 | } | |
6455 | } | |
bdac5f58 TW |
6456 | } |
6457 | ||
6458 | if (epilogue) | |
6459 | { | |
bf526252 RK |
6460 | register rtx insn, note = 0; |
6461 | ||
6462 | /* Scan from the end until we reach the first epilogue insn. | |
6463 | We apparently can't depend on basic_block_{head,end} after | |
6464 | reorg has run. */ | |
6465 | for (len = 0; epilogue[len]; len++) | |
6466 | ; | |
9392c110 JH |
6467 | for (insn = get_last_insn (); len && insn; insn = PREV_INSN (insn)) |
6468 | { | |
6469 | if (GET_CODE (insn) == NOTE) | |
6470 | { | |
6471 | if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG) | |
6472 | note = insn; | |
6473 | } | |
6474 | else if ((len -= contains (insn, epilogue)) == 0) | |
6475 | { | |
6476 | /* Find the epilogue-begin note if we haven't already, and | |
6477 | move it to just before the first epilogue insn. */ | |
6478 | if (note == 0) | |
6479 | { | |
51723711 | 6480 | for (note = insn; (note = PREV_INSN (note));) |
9392c110 JH |
6481 | if (GET_CODE (note) == NOTE |
6482 | && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG) | |
6483 | break; | |
6484 | } | |
6485 | next = NEXT_INSN (note); | |
6486 | prev = PREV_INSN (note); | |
6487 | if (prev) | |
6488 | NEXT_INSN (prev) = next; | |
6489 | if (next) | |
6490 | PREV_INSN (next) = prev; | |
c93b03c2 | 6491 | |
3b413743 | 6492 | /* Whether or not we can depend on BLOCK_HEAD, |
c93b03c2 RH |
6493 | attempt to keep it up-to-date. */ |
6494 | if (n_basic_blocks | |
3b413743 RH |
6495 | && BLOCK_HEAD (n_basic_blocks-1) == insn) |
6496 | BLOCK_HEAD (n_basic_blocks-1) = note; | |
c93b03c2 RH |
6497 | |
6498 | add_insn_before (note, insn); | |
9392c110 JH |
6499 | } |
6500 | } | |
bdac5f58 TW |
6501 | } |
6502 | } | |
6503 | #endif /* HAVE_prologue or HAVE_epilogue */ | |
6504 | } |