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