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