]>
Commit | Line | Data |
---|---|---|
6f086dfc | 1 | /* Expands front end tree to back end RTL for GNU C-Compiler |
1b2ac438 | 2 | Copyright (C) 1987, 1988, 1989, 1991, 1992 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 | |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | ||
20 | ||
21 | /* This file handles the generation of rtl code from tree structure | |
22 | at the level of the function as a whole. | |
23 | It creates the rtl expressions for parameters and auto variables | |
24 | and has full responsibility for allocating stack slots. | |
25 | ||
26 | `expand_function_start' is called at the beginning of a function, | |
27 | before the function body is parsed, and `expand_function_end' is | |
28 | called after parsing the body. | |
29 | ||
30 | Call `assign_stack_local' to allocate a stack slot for a local variable. | |
31 | This is usually done during the RTL generation for the function body, | |
32 | but it can also be done in the reload pass when a pseudo-register does | |
33 | not get a hard register. | |
34 | ||
35 | Call `put_var_into_stack' when you learn, belatedly, that a variable | |
36 | previously given a pseudo-register must in fact go in the stack. | |
37 | This function changes the DECL_RTL to be a stack slot instead of a reg | |
38 | then scans all the RTL instructions so far generated to correct them. */ | |
39 | ||
40 | #include "config.h" | |
41 | ||
42 | #include <stdio.h> | |
43 | ||
44 | #include "rtl.h" | |
45 | #include "tree.h" | |
46 | #include "flags.h" | |
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" |
6f086dfc RS |
57 | |
58 | /* Round a value to the lowest integer less than it that is a multiple of | |
59 | the required alignment. Avoid using division in case the value is | |
60 | negative. Assume the alignment is a power of two. */ | |
61 | #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1)) | |
62 | ||
63 | /* Similar, but round to the next highest integer that meets the | |
64 | alignment. */ | |
65 | #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1)) | |
66 | ||
67 | /* NEED_SEPARATE_AP means that we cannot derive ap from the value of fp | |
68 | during rtl generation. If they are different register numbers, this is | |
69 | always true. It may also be true if | |
70 | FIRST_PARM_OFFSET - STARTING_FRAME_OFFSET is not a constant during rtl | |
71 | generation. See fix_lexical_addr for details. */ | |
72 | ||
73 | #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM | |
74 | #define NEED_SEPARATE_AP | |
75 | #endif | |
76 | ||
77 | /* Number of bytes of args popped by function being compiled on its return. | |
78 | Zero if no bytes are to be popped. | |
79 | May affect compilation of return insn or of function epilogue. */ | |
80 | ||
81 | int current_function_pops_args; | |
82 | ||
83 | /* Nonzero if function being compiled needs to be given an address | |
84 | where the value should be stored. */ | |
85 | ||
86 | int current_function_returns_struct; | |
87 | ||
88 | /* Nonzero if function being compiled needs to | |
89 | return the address of where it has put a structure value. */ | |
90 | ||
91 | int current_function_returns_pcc_struct; | |
92 | ||
93 | /* Nonzero if function being compiled needs to be passed a static chain. */ | |
94 | ||
95 | int current_function_needs_context; | |
96 | ||
97 | /* Nonzero if function being compiled can call setjmp. */ | |
98 | ||
99 | int current_function_calls_setjmp; | |
100 | ||
101 | /* Nonzero if function being compiled can call longjmp. */ | |
102 | ||
103 | int current_function_calls_longjmp; | |
104 | ||
105 | /* Nonzero if function being compiled receives nonlocal gotos | |
106 | from nested functions. */ | |
107 | ||
108 | int current_function_has_nonlocal_label; | |
109 | ||
110 | /* Nonzero if function being compiled contains nested functions. */ | |
111 | ||
112 | int current_function_contains_functions; | |
113 | ||
114 | /* Nonzero if function being compiled can call alloca, | |
115 | either as a subroutine or builtin. */ | |
116 | ||
117 | int current_function_calls_alloca; | |
118 | ||
119 | /* Nonzero if the current function returns a pointer type */ | |
120 | ||
121 | int current_function_returns_pointer; | |
122 | ||
123 | /* If some insns can be deferred to the delay slots of the epilogue, the | |
124 | delay list for them is recorded here. */ | |
125 | ||
126 | rtx current_function_epilogue_delay_list; | |
127 | ||
128 | /* If function's args have a fixed size, this is that size, in bytes. | |
129 | Otherwise, it is -1. | |
130 | May affect compilation of return insn or of function epilogue. */ | |
131 | ||
132 | int current_function_args_size; | |
133 | ||
134 | /* # bytes the prologue should push and pretend that the caller pushed them. | |
135 | The prologue must do this, but only if parms can be passed in registers. */ | |
136 | ||
137 | int current_function_pretend_args_size; | |
138 | ||
139 | /* # of bytes of outgoing arguments required to be pushed by the prologue. | |
140 | If this is non-zero, it means that ACCUMULATE_OUTGOING_ARGS was defined | |
141 | and no stack adjusts will be done on function calls. */ | |
142 | ||
143 | int current_function_outgoing_args_size; | |
144 | ||
145 | /* This is the offset from the arg pointer to the place where the first | |
146 | anonymous arg can be found, if there is one. */ | |
147 | ||
148 | rtx current_function_arg_offset_rtx; | |
149 | ||
150 | /* Nonzero if current function uses varargs.h or equivalent. | |
151 | Zero for functions that use stdarg.h. */ | |
152 | ||
153 | int current_function_varargs; | |
154 | ||
155 | /* Quantities of various kinds of registers | |
156 | used for the current function's args. */ | |
157 | ||
158 | CUMULATIVE_ARGS current_function_args_info; | |
159 | ||
160 | /* Name of function now being compiled. */ | |
161 | ||
162 | char *current_function_name; | |
163 | ||
164 | /* If non-zero, an RTL expression for that location at which the current | |
165 | function returns its result. Always equal to | |
166 | DECL_RTL (DECL_RESULT (current_function_decl)), but provided | |
167 | independently of the tree structures. */ | |
168 | ||
169 | rtx current_function_return_rtx; | |
170 | ||
171 | /* Nonzero if the current function uses the constant pool. */ | |
172 | ||
173 | int current_function_uses_const_pool; | |
174 | ||
175 | /* Nonzero if the current function uses pic_offset_table_rtx. */ | |
176 | int current_function_uses_pic_offset_table; | |
177 | ||
178 | /* The arg pointer hard register, or the pseudo into which it was copied. */ | |
179 | rtx current_function_internal_arg_pointer; | |
180 | ||
181 | /* The FUNCTION_DECL for an inline function currently being expanded. */ | |
182 | tree inline_function_decl; | |
183 | ||
184 | /* Number of function calls seen so far in current function. */ | |
185 | ||
186 | int function_call_count; | |
187 | ||
188 | /* List (chain of TREE_LIST) of LABEL_DECLs for all nonlocal labels | |
189 | (labels to which there can be nonlocal gotos from nested functions) | |
190 | in this function. */ | |
191 | ||
192 | tree nonlocal_labels; | |
193 | ||
194 | /* RTX for stack slot that holds the current handler for nonlocal gotos. | |
195 | Zero when function does not have nonlocal labels. */ | |
196 | ||
197 | rtx nonlocal_goto_handler_slot; | |
198 | ||
199 | /* RTX for stack slot that holds the stack pointer value to restore | |
200 | for a nonlocal goto. | |
201 | Zero when function does not have nonlocal labels. */ | |
202 | ||
203 | rtx nonlocal_goto_stack_level; | |
204 | ||
205 | /* Label that will go on parm cleanup code, if any. | |
206 | Jumping to this label runs cleanup code for parameters, if | |
207 | such code must be run. Following this code is the logical return label. */ | |
208 | ||
209 | rtx cleanup_label; | |
210 | ||
211 | /* Label that will go on function epilogue. | |
212 | Jumping to this label serves as a "return" instruction | |
213 | on machines which require execution of the epilogue on all returns. */ | |
214 | ||
215 | rtx return_label; | |
216 | ||
217 | /* List (chain of EXPR_LISTs) of pseudo-regs of SAVE_EXPRs. | |
218 | So we can mark them all live at the end of the function, if nonopt. */ | |
219 | rtx save_expr_regs; | |
220 | ||
221 | /* List (chain of EXPR_LISTs) of all stack slots in this function. | |
222 | Made for the sake of unshare_all_rtl. */ | |
223 | rtx stack_slot_list; | |
224 | ||
225 | /* Chain of all RTL_EXPRs that have insns in them. */ | |
226 | tree rtl_expr_chain; | |
227 | ||
228 | /* Label to jump back to for tail recursion, or 0 if we have | |
229 | not yet needed one for this function. */ | |
230 | rtx tail_recursion_label; | |
231 | ||
232 | /* Place after which to insert the tail_recursion_label if we need one. */ | |
233 | rtx tail_recursion_reentry; | |
234 | ||
235 | /* Location at which to save the argument pointer if it will need to be | |
236 | referenced. There are two cases where this is done: if nonlocal gotos | |
237 | exist, or if vars stored at an offset from the argument pointer will be | |
238 | needed by inner routines. */ | |
239 | ||
240 | rtx arg_pointer_save_area; | |
241 | ||
242 | /* Offset to end of allocated area of stack frame. | |
243 | If stack grows down, this is the address of the last stack slot allocated. | |
244 | If stack grows up, this is the address for the next slot. */ | |
245 | int frame_offset; | |
246 | ||
247 | /* List (chain of TREE_LISTs) of static chains for containing functions. | |
248 | Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx | |
249 | in an RTL_EXPR in the TREE_VALUE. */ | |
250 | static tree context_display; | |
251 | ||
252 | /* List (chain of TREE_LISTs) of trampolines for nested functions. | |
253 | The trampoline sets up the static chain and jumps to the function. | |
254 | We supply the trampoline's address when the function's address is requested. | |
255 | ||
256 | Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx | |
257 | in an RTL_EXPR in the TREE_VALUE. */ | |
258 | static tree trampoline_list; | |
259 | ||
260 | /* Insn after which register parms and SAVE_EXPRs are born, if nonopt. */ | |
261 | static rtx parm_birth_insn; | |
262 | ||
263 | #if 0 | |
264 | /* Nonzero if a stack slot has been generated whose address is not | |
265 | actually valid. It means that the generated rtl must all be scanned | |
266 | to detect and correct the invalid addresses where they occur. */ | |
267 | static int invalid_stack_slot; | |
268 | #endif | |
269 | ||
270 | /* Last insn of those whose job was to put parms into their nominal homes. */ | |
271 | static rtx last_parm_insn; | |
272 | ||
273 | /* 1 + last pseudo register number used for loading a copy | |
274 | of a parameter of this function. */ | |
275 | static int max_parm_reg; | |
276 | ||
277 | /* Vector indexed by REGNO, containing location on stack in which | |
278 | to put the parm which is nominally in pseudo register REGNO, | |
279 | if we discover that that parm must go in the stack. */ | |
280 | static rtx *parm_reg_stack_loc; | |
281 | ||
282 | #if 0 /* Turned off because 0 seems to work just as well. */ | |
283 | /* Cleanup lists are required for binding levels regardless of whether | |
284 | that binding level has cleanups or not. This node serves as the | |
285 | cleanup list whenever an empty list is required. */ | |
286 | static tree empty_cleanup_list; | |
287 | #endif | |
288 | ||
289 | /* Nonzero once virtual register instantiation has been done. | |
290 | assign_stack_local uses frame_pointer_rtx when this is nonzero. */ | |
291 | static int virtuals_instantiated; | |
292 | ||
293 | /* Nonzero if we need to distinguish between the return value of this function | |
294 | and the return value of a function called by this function. This helps | |
295 | integrate.c */ | |
296 | ||
297 | extern int rtx_equal_function_value_matters; | |
298 | ||
299 | void fixup_gotos (); | |
300 | ||
301 | static tree round_down (); | |
302 | static rtx round_trampoline_addr (); | |
303 | static rtx fixup_stack_1 (); | |
304 | static void fixup_var_refs (); | |
305 | static void fixup_var_refs_insns (); | |
306 | static void fixup_var_refs_1 (); | |
307 | static void optimize_bit_field (); | |
308 | static void instantiate_decls (); | |
309 | static void instantiate_decls_1 (); | |
5a73491b | 310 | static void instantiate_decl (); |
6f086dfc RS |
311 | static int instantiate_virtual_regs_1 (); |
312 | static rtx fixup_memory_subreg (); | |
313 | static rtx walk_fixup_memory_subreg (); | |
314 | \f | |
315 | /* In order to evaluate some expressions, such as function calls returning | |
316 | structures in memory, we need to temporarily allocate stack locations. | |
317 | We record each allocated temporary in the following structure. | |
318 | ||
319 | Associated with each temporary slot is a nesting level. When we pop up | |
320 | one level, all temporaries associated with the previous level are freed. | |
321 | Normally, all temporaries are freed after the execution of the statement | |
322 | in which they were created. However, if we are inside a ({...}) grouping, | |
323 | the result may be in a temporary and hence must be preserved. If the | |
324 | result could be in a temporary, we preserve it if we can determine which | |
325 | one it is in. If we cannot determine which temporary may contain the | |
326 | result, all temporaries are preserved. A temporary is preserved by | |
327 | pretending it was allocated at the previous nesting level. | |
328 | ||
329 | Automatic variables are also assigned temporary slots, at the nesting | |
330 | level where they are defined. They are marked a "kept" so that | |
331 | free_temp_slots will not free them. */ | |
332 | ||
333 | struct temp_slot | |
334 | { | |
335 | /* Points to next temporary slot. */ | |
336 | struct temp_slot *next; | |
337 | /* The rtx to used to reference the slot. */ | |
338 | rtx slot; | |
339 | /* The size, in units, of the slot. */ | |
340 | int size; | |
341 | /* Non-zero if this temporary is currently in use. */ | |
342 | char in_use; | |
343 | /* Nesting level at which this slot is being used. */ | |
344 | int level; | |
345 | /* Non-zero if this should survive a call to free_temp_slots. */ | |
346 | int keep; | |
347 | }; | |
348 | ||
349 | /* List of all temporaries allocated, both available and in use. */ | |
350 | ||
351 | struct temp_slot *temp_slots; | |
352 | ||
353 | /* Current nesting level for temporaries. */ | |
354 | ||
355 | int temp_slot_level; | |
356 | \f | |
357 | /* Pointer to chain of `struct function' for containing functions. */ | |
358 | struct function *outer_function_chain; | |
359 | ||
360 | /* Given a function decl for a containing function, | |
361 | return the `struct function' for it. */ | |
362 | ||
363 | struct function * | |
364 | find_function_data (decl) | |
365 | tree decl; | |
366 | { | |
367 | struct function *p; | |
368 | for (p = outer_function_chain; p; p = p->next) | |
369 | if (p->decl == decl) | |
370 | return p; | |
371 | abort (); | |
372 | } | |
373 | ||
374 | /* Save the current context for compilation of a nested function. | |
375 | This is called from language-specific code. | |
376 | The caller is responsible for saving any language-specific status, | |
6dc42e49 | 377 | since this function knows only about language-independent variables. */ |
6f086dfc RS |
378 | |
379 | void | |
380 | push_function_context () | |
381 | { | |
382 | struct function *p = (struct function *) xmalloc (sizeof (struct function)); | |
383 | ||
384 | p->next = outer_function_chain; | |
385 | outer_function_chain = p; | |
386 | ||
387 | p->name = current_function_name; | |
388 | p->decl = current_function_decl; | |
389 | p->pops_args = current_function_pops_args; | |
390 | p->returns_struct = current_function_returns_struct; | |
391 | p->returns_pcc_struct = current_function_returns_pcc_struct; | |
392 | p->needs_context = current_function_needs_context; | |
393 | p->calls_setjmp = current_function_calls_setjmp; | |
394 | p->calls_longjmp = current_function_calls_longjmp; | |
395 | p->calls_alloca = current_function_calls_alloca; | |
396 | p->has_nonlocal_label = current_function_has_nonlocal_label; | |
397 | p->args_size = current_function_args_size; | |
398 | p->pretend_args_size = current_function_pretend_args_size; | |
399 | p->arg_offset_rtx = current_function_arg_offset_rtx; | |
400 | p->uses_const_pool = current_function_uses_const_pool; | |
401 | p->uses_pic_offset_table = current_function_uses_pic_offset_table; | |
402 | p->internal_arg_pointer = current_function_internal_arg_pointer; | |
403 | p->max_parm_reg = max_parm_reg; | |
404 | p->parm_reg_stack_loc = parm_reg_stack_loc; | |
405 | p->outgoing_args_size = current_function_outgoing_args_size; | |
406 | p->return_rtx = current_function_return_rtx; | |
407 | p->nonlocal_goto_handler_slot = nonlocal_goto_handler_slot; | |
408 | p->nonlocal_goto_stack_level = nonlocal_goto_stack_level; | |
409 | p->nonlocal_labels = nonlocal_labels; | |
410 | p->cleanup_label = cleanup_label; | |
411 | p->return_label = return_label; | |
412 | p->save_expr_regs = save_expr_regs; | |
413 | p->stack_slot_list = stack_slot_list; | |
414 | p->parm_birth_insn = parm_birth_insn; | |
415 | p->frame_offset = frame_offset; | |
416 | p->tail_recursion_label = tail_recursion_label; | |
417 | p->tail_recursion_reentry = tail_recursion_reentry; | |
418 | p->arg_pointer_save_area = arg_pointer_save_area; | |
419 | p->rtl_expr_chain = rtl_expr_chain; | |
420 | p->last_parm_insn = last_parm_insn; | |
421 | p->context_display = context_display; | |
422 | p->trampoline_list = trampoline_list; | |
423 | p->function_call_count = function_call_count; | |
424 | p->temp_slots = temp_slots; | |
425 | p->temp_slot_level = temp_slot_level; | |
426 | p->fixup_var_refs_queue = 0; | |
f979c996 | 427 | p->epilogue_delay_list = current_function_epilogue_delay_list; |
6f086dfc RS |
428 | |
429 | save_tree_status (p); | |
430 | save_storage_status (p); | |
431 | save_emit_status (p); | |
432 | init_emit (); | |
433 | save_expr_status (p); | |
434 | save_stmt_status (p); | |
435 | } | |
436 | ||
437 | /* Restore the last saved context, at the end of a nested function. | |
438 | This function is called from language-specific code. */ | |
439 | ||
440 | void | |
441 | pop_function_context () | |
442 | { | |
443 | struct function *p = outer_function_chain; | |
444 | ||
445 | outer_function_chain = p->next; | |
446 | ||
447 | current_function_name = p->name; | |
448 | current_function_decl = p->decl; | |
449 | current_function_pops_args = p->pops_args; | |
450 | current_function_returns_struct = p->returns_struct; | |
451 | current_function_returns_pcc_struct = p->returns_pcc_struct; | |
452 | current_function_needs_context = p->needs_context; | |
453 | current_function_calls_setjmp = p->calls_setjmp; | |
454 | current_function_calls_longjmp = p->calls_longjmp; | |
455 | current_function_calls_alloca = p->calls_alloca; | |
456 | current_function_has_nonlocal_label = p->has_nonlocal_label; | |
457 | current_function_contains_functions = 1; | |
458 | current_function_args_size = p->args_size; | |
459 | current_function_pretend_args_size = p->pretend_args_size; | |
460 | current_function_arg_offset_rtx = p->arg_offset_rtx; | |
461 | current_function_uses_const_pool = p->uses_const_pool; | |
462 | current_function_uses_pic_offset_table = p->uses_pic_offset_table; | |
463 | current_function_internal_arg_pointer = p->internal_arg_pointer; | |
464 | max_parm_reg = p->max_parm_reg; | |
465 | parm_reg_stack_loc = p->parm_reg_stack_loc; | |
466 | current_function_outgoing_args_size = p->outgoing_args_size; | |
467 | current_function_return_rtx = p->return_rtx; | |
468 | nonlocal_goto_handler_slot = p->nonlocal_goto_handler_slot; | |
469 | nonlocal_goto_stack_level = p->nonlocal_goto_stack_level; | |
470 | nonlocal_labels = p->nonlocal_labels; | |
471 | cleanup_label = p->cleanup_label; | |
472 | return_label = p->return_label; | |
473 | save_expr_regs = p->save_expr_regs; | |
474 | stack_slot_list = p->stack_slot_list; | |
475 | parm_birth_insn = p->parm_birth_insn; | |
476 | frame_offset = p->frame_offset; | |
477 | tail_recursion_label = p->tail_recursion_label; | |
478 | tail_recursion_reentry = p->tail_recursion_reentry; | |
479 | arg_pointer_save_area = p->arg_pointer_save_area; | |
480 | rtl_expr_chain = p->rtl_expr_chain; | |
481 | last_parm_insn = p->last_parm_insn; | |
482 | context_display = p->context_display; | |
483 | trampoline_list = p->trampoline_list; | |
484 | function_call_count = p->function_call_count; | |
485 | temp_slots = p->temp_slots; | |
486 | temp_slot_level = p->temp_slot_level; | |
f979c996 | 487 | current_function_epilogue_delay_list = p->epilogue_delay_list; |
6f086dfc RS |
488 | |
489 | restore_tree_status (p); | |
490 | restore_storage_status (p); | |
491 | restore_expr_status (p); | |
492 | restore_emit_status (p); | |
493 | restore_stmt_status (p); | |
494 | ||
495 | /* Finish doing put_var_into_stack for any of our variables | |
496 | which became addressable during the nested function. */ | |
497 | { | |
498 | struct var_refs_queue *queue = p->fixup_var_refs_queue; | |
499 | for (; queue; queue = queue->next) | |
00d8a4c1 | 500 | fixup_var_refs (queue->modified, queue->promoted_mode, queue->unsignedp); |
6f086dfc RS |
501 | } |
502 | ||
503 | free (p); | |
504 | ||
505 | /* Reset variables that have known state during rtx generation. */ | |
506 | rtx_equal_function_value_matters = 1; | |
507 | virtuals_instantiated = 0; | |
508 | } | |
509 | \f | |
510 | /* Allocate fixed slots in the stack frame of the current function. */ | |
511 | ||
512 | /* Return size needed for stack frame based on slots so far allocated. | |
513 | This size counts from zero. It is not rounded to STACK_BOUNDARY; | |
514 | the caller may have to do that. */ | |
515 | ||
516 | int | |
517 | get_frame_size () | |
518 | { | |
519 | #ifdef FRAME_GROWS_DOWNWARD | |
520 | return -frame_offset; | |
521 | #else | |
522 | return frame_offset; | |
523 | #endif | |
524 | } | |
525 | ||
526 | /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it | |
527 | with machine mode MODE. | |
528 | ||
529 | ALIGN controls the amount of alignment for the address of the slot: | |
530 | 0 means according to MODE, | |
531 | -1 means use BIGGEST_ALIGNMENT and round size to multiple of that, | |
532 | positive specifies alignment boundary in bits. | |
533 | ||
534 | We do not round to stack_boundary here. */ | |
535 | ||
536 | rtx | |
537 | assign_stack_local (mode, size, align) | |
538 | enum machine_mode mode; | |
539 | int size; | |
540 | int align; | |
541 | { | |
542 | register rtx x, addr; | |
543 | int bigend_correction = 0; | |
544 | int alignment; | |
545 | ||
546 | if (align == 0) | |
547 | { | |
548 | alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT; | |
549 | if (mode == BLKmode) | |
550 | alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT; | |
551 | } | |
552 | else if (align == -1) | |
553 | { | |
554 | alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT; | |
555 | size = CEIL_ROUND (size, alignment); | |
556 | } | |
557 | else | |
558 | alignment = align / BITS_PER_UNIT; | |
559 | ||
6f086dfc RS |
560 | /* Round frame offset to that alignment. |
561 | We must be careful here, since FRAME_OFFSET might be negative and | |
562 | division with a negative dividend isn't as well defined as we might | |
563 | like. So we instead assume that ALIGNMENT is a power of two and | |
564 | use logical operations which are unambiguous. */ | |
565 | #ifdef FRAME_GROWS_DOWNWARD | |
566 | frame_offset = FLOOR_ROUND (frame_offset, alignment); | |
567 | #else | |
568 | frame_offset = CEIL_ROUND (frame_offset, alignment); | |
569 | #endif | |
570 | ||
571 | /* On a big-endian machine, if we are allocating more space than we will use, | |
572 | use the least significant bytes of those that are allocated. */ | |
573 | #if BYTES_BIG_ENDIAN | |
574 | if (mode != BLKmode) | |
575 | bigend_correction = size - GET_MODE_SIZE (mode); | |
576 | #endif | |
577 | ||
578 | #ifdef FRAME_GROWS_DOWNWARD | |
579 | frame_offset -= size; | |
580 | #endif | |
581 | ||
582 | /* If we have already instantiated virtual registers, return the actual | |
583 | address relative to the frame pointer. */ | |
584 | if (virtuals_instantiated) | |
585 | addr = plus_constant (frame_pointer_rtx, | |
586 | (frame_offset + bigend_correction | |
587 | + STARTING_FRAME_OFFSET)); | |
588 | else | |
589 | addr = plus_constant (virtual_stack_vars_rtx, | |
590 | frame_offset + bigend_correction); | |
591 | ||
592 | #ifndef FRAME_GROWS_DOWNWARD | |
593 | frame_offset += size; | |
594 | #endif | |
595 | ||
596 | x = gen_rtx (MEM, mode, addr); | |
597 | ||
598 | stack_slot_list = gen_rtx (EXPR_LIST, VOIDmode, x, stack_slot_list); | |
599 | ||
600 | return x; | |
601 | } | |
602 | ||
603 | /* Assign a stack slot in a containing function. | |
604 | First three arguments are same as in preceding function. | |
605 | The last argument specifies the function to allocate in. */ | |
606 | ||
607 | rtx | |
608 | assign_outer_stack_local (mode, size, align, function) | |
609 | enum machine_mode mode; | |
610 | int size; | |
611 | int align; | |
612 | struct function *function; | |
613 | { | |
614 | register rtx x, addr; | |
615 | int bigend_correction = 0; | |
616 | int alignment; | |
617 | ||
618 | /* Allocate in the memory associated with the function in whose frame | |
619 | we are assigning. */ | |
620 | push_obstacks (function->function_obstack, | |
621 | function->function_maybepermanent_obstack); | |
622 | ||
623 | if (align == 0) | |
624 | { | |
625 | alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT; | |
626 | if (mode == BLKmode) | |
627 | alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT; | |
628 | } | |
629 | else if (align == -1) | |
630 | { | |
631 | alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT; | |
632 | size = CEIL_ROUND (size, alignment); | |
633 | } | |
634 | else | |
635 | alignment = align / BITS_PER_UNIT; | |
636 | ||
6f086dfc RS |
637 | /* Round frame offset to that alignment. */ |
638 | #ifdef FRAME_GROWS_DOWNWARD | |
639 | frame_offset = FLOOR_ROUND (frame_offset, alignment); | |
640 | #else | |
641 | frame_offset = CEIL_ROUND (frame_offset, alignment); | |
642 | #endif | |
643 | ||
644 | /* On a big-endian machine, if we are allocating more space than we will use, | |
645 | use the least significant bytes of those that are allocated. */ | |
646 | #if BYTES_BIG_ENDIAN | |
647 | if (mode != BLKmode) | |
648 | bigend_correction = size - GET_MODE_SIZE (mode); | |
649 | #endif | |
650 | ||
651 | #ifdef FRAME_GROWS_DOWNWARD | |
652 | function->frame_offset -= size; | |
653 | #endif | |
654 | addr = plus_constant (virtual_stack_vars_rtx, | |
655 | function->frame_offset + bigend_correction); | |
656 | #ifndef FRAME_GROWS_DOWNWARD | |
657 | function->frame_offset += size; | |
658 | #endif | |
659 | ||
660 | x = gen_rtx (MEM, mode, addr); | |
661 | ||
662 | function->stack_slot_list | |
663 | = gen_rtx (EXPR_LIST, VOIDmode, x, function->stack_slot_list); | |
664 | ||
665 | pop_obstacks (); | |
666 | ||
667 | return x; | |
668 | } | |
669 | \f | |
670 | /* Allocate a temporary stack slot and record it for possible later | |
671 | reuse. | |
672 | ||
673 | MODE is the machine mode to be given to the returned rtx. | |
674 | ||
675 | SIZE is the size in units of the space required. We do no rounding here | |
676 | since assign_stack_local will do any required rounding. | |
677 | ||
678 | KEEP is non-zero if this slot is to be retained after a call to | |
679 | free_temp_slots. Automatic variables for a block are allocated with this | |
680 | flag. */ | |
681 | ||
682 | rtx | |
683 | assign_stack_temp (mode, size, keep) | |
684 | enum machine_mode mode; | |
685 | int size; | |
686 | int keep; | |
687 | { | |
688 | struct temp_slot *p, *best_p = 0; | |
689 | ||
690 | /* First try to find an available, already-allocated temporary that is the | |
691 | exact size we require. */ | |
692 | for (p = temp_slots; p; p = p->next) | |
693 | if (p->size == size && GET_MODE (p->slot) == mode && ! p->in_use) | |
694 | break; | |
695 | ||
696 | /* If we didn't find, one, try one that is larger than what we want. We | |
697 | find the smallest such. */ | |
698 | if (p == 0) | |
699 | for (p = temp_slots; p; p = p->next) | |
700 | if (p->size > size && GET_MODE (p->slot) == mode && ! p->in_use | |
701 | && (best_p == 0 || best_p->size > p->size)) | |
702 | best_p = p; | |
703 | ||
704 | /* Make our best, if any, the one to use. */ | |
705 | if (best_p) | |
706 | p = best_p; | |
707 | ||
708 | /* If we still didn't find one, make a new temporary. */ | |
709 | if (p == 0) | |
710 | { | |
711 | p = (struct temp_slot *) oballoc (sizeof (struct temp_slot)); | |
712 | p->size = size; | |
713 | /* If the temp slot mode doesn't indicate the alignment, | |
714 | use the largest possible, so no one will be disappointed. */ | |
715 | p->slot = assign_stack_local (mode, size, mode == BLKmode ? -1 : 0); | |
716 | p->next = temp_slots; | |
717 | temp_slots = p; | |
718 | } | |
719 | ||
720 | p->in_use = 1; | |
721 | p->level = temp_slot_level; | |
722 | p->keep = keep; | |
723 | return p->slot; | |
724 | } | |
725 | \f | |
726 | /* If X could be a reference to a temporary slot, mark that slot as belonging | |
727 | to the to one level higher. If X matched one of our slots, just mark that | |
728 | one. Otherwise, we can't easily predict which it is, so upgrade all of | |
729 | them. Kept slots need not be touched. | |
730 | ||
731 | This is called when an ({...}) construct occurs and a statement | |
732 | returns a value in memory. */ | |
733 | ||
734 | void | |
735 | preserve_temp_slots (x) | |
736 | rtx x; | |
737 | { | |
738 | struct temp_slot *p; | |
739 | ||
740 | /* If X is not in memory or is at a constant address, it cannot be in | |
741 | a temporary slot. */ | |
742 | if (x == 0 || GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0))) | |
743 | return; | |
744 | ||
745 | /* First see if we can find a match. */ | |
746 | for (p = temp_slots; p; p = p->next) | |
747 | if (p->in_use && x == p->slot) | |
748 | { | |
749 | p->level--; | |
750 | return; | |
751 | } | |
752 | ||
753 | /* Otherwise, preserve all non-kept slots at this level. */ | |
754 | for (p = temp_slots; p; p = p->next) | |
755 | if (p->in_use && p->level == temp_slot_level && ! p->keep) | |
756 | p->level--; | |
757 | } | |
758 | ||
759 | /* Free all temporaries used so far. This is normally called at the end | |
760 | of generating code for a statement. */ | |
761 | ||
762 | void | |
763 | free_temp_slots () | |
764 | { | |
765 | struct temp_slot *p; | |
766 | ||
767 | for (p = temp_slots; p; p = p->next) | |
768 | if (p->in_use && p->level == temp_slot_level && ! p->keep) | |
769 | p->in_use = 0; | |
770 | } | |
771 | ||
772 | /* Push deeper into the nesting level for stack temporaries. */ | |
773 | ||
774 | void | |
775 | push_temp_slots () | |
776 | { | |
777 | /* For GNU C++, we must allow a sequence to be emitted anywhere in | |
778 | the level where the sequence was started. By not changing levels | |
779 | when the compiler is inside a sequence, the temporaries for the | |
780 | sequence and the temporaries will not unwittingly conflict with | |
781 | the temporaries for other sequences and/or code at that level. */ | |
782 | if (in_sequence_p ()) | |
783 | return; | |
784 | ||
785 | temp_slot_level++; | |
786 | } | |
787 | ||
788 | /* Pop a temporary nesting level. All slots in use in the current level | |
789 | are freed. */ | |
790 | ||
791 | void | |
792 | pop_temp_slots () | |
793 | { | |
794 | struct temp_slot *p; | |
795 | ||
796 | /* See comment in push_temp_slots about why we don't change levels | |
797 | in sequences. */ | |
798 | if (in_sequence_p ()) | |
799 | return; | |
800 | ||
801 | for (p = temp_slots; p; p = p->next) | |
802 | if (p->in_use && p->level == temp_slot_level) | |
803 | p->in_use = 0; | |
804 | ||
805 | temp_slot_level--; | |
806 | } | |
807 | \f | |
808 | /* Retroactively move an auto variable from a register to a stack slot. | |
809 | This is done when an address-reference to the variable is seen. */ | |
810 | ||
811 | void | |
812 | put_var_into_stack (decl) | |
813 | tree decl; | |
814 | { | |
815 | register rtx reg; | |
816 | register rtx new = 0; | |
00d8a4c1 | 817 | enum machine_mode promoted_mode, decl_mode; |
6f086dfc RS |
818 | struct function *function = 0; |
819 | tree context = decl_function_context (decl); | |
820 | ||
00d8a4c1 | 821 | /* Get the current rtl used for this object and it's original mode. */ |
6f086dfc | 822 | reg = TREE_CODE (decl) == SAVE_EXPR ? SAVE_EXPR_RTL (decl) : DECL_RTL (decl); |
2baccce2 RS |
823 | |
824 | /* No need to do anything if decl has no rtx yet | |
825 | since in that case caller is setting TREE_ADDRESSABLE | |
826 | and a stack slot will be assigned when the rtl is made. */ | |
827 | if (reg == 0) | |
828 | return; | |
00d8a4c1 RK |
829 | |
830 | /* Get the declared mode for this object. */ | |
831 | decl_mode = (TREE_CODE (decl) == SAVE_EXPR ? TYPE_MODE (TREE_TYPE (decl)) | |
832 | : DECL_MODE (decl)); | |
2baccce2 RS |
833 | /* Get the mode it's actually stored in. */ |
834 | promoted_mode = GET_MODE (reg); | |
6f086dfc RS |
835 | |
836 | /* If this variable comes from an outer function, | |
837 | find that function's saved context. */ | |
838 | if (context != current_function_decl) | |
839 | for (function = outer_function_chain; function; function = function->next) | |
840 | if (function->decl == context) | |
841 | break; | |
842 | ||
6f086dfc RS |
843 | /* If this is a variable-size object with a pseudo to address it, |
844 | put that pseudo into the stack, if the var is nonlocal. */ | |
a82ad570 | 845 | if (DECL_NONLOCAL (decl) |
6f086dfc RS |
846 | && GET_CODE (reg) == MEM |
847 | && GET_CODE (XEXP (reg, 0)) == REG | |
848 | && REGNO (XEXP (reg, 0)) > LAST_VIRTUAL_REGISTER) | |
849 | reg = XEXP (reg, 0); | |
850 | if (GET_CODE (reg) != REG) | |
851 | return; | |
852 | ||
853 | if (function) | |
854 | { | |
855 | if (REGNO (reg) < function->max_parm_reg) | |
856 | new = function->parm_reg_stack_loc[REGNO (reg)]; | |
857 | if (new == 0) | |
858 | new = assign_outer_stack_local (GET_MODE (reg), | |
00d8a4c1 | 859 | GET_MODE_SIZE (decl_mode), |
6f086dfc RS |
860 | 0, function); |
861 | } | |
862 | else | |
863 | { | |
864 | if (REGNO (reg) < max_parm_reg) | |
865 | new = parm_reg_stack_loc[REGNO (reg)]; | |
866 | if (new == 0) | |
867 | new = assign_stack_local (GET_MODE (reg), | |
00d8a4c1 | 868 | GET_MODE_SIZE (decl_mode), 0); |
6f086dfc RS |
869 | } |
870 | ||
871 | XEXP (reg, 0) = XEXP (new, 0); | |
872 | /* `volatil' bit means one thing for MEMs, another entirely for REGs. */ | |
873 | REG_USERVAR_P (reg) = 0; | |
874 | PUT_CODE (reg, MEM); | |
00d8a4c1 | 875 | PUT_MODE (reg, decl_mode); |
6f086dfc RS |
876 | |
877 | /* If this is a memory ref that contains aggregate components, | |
878 | mark it as such for cse and loop optimize. */ | |
879 | MEM_IN_STRUCT_P (reg) | |
880 | = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE | |
881 | || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE | |
882 | || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE); | |
883 | ||
884 | /* Now make sure that all refs to the variable, previously made | |
885 | when it was a register, are fixed up to be valid again. */ | |
886 | if (function) | |
887 | { | |
888 | struct var_refs_queue *temp; | |
889 | ||
890 | /* Variable is inherited; fix it up when we get back to its function. */ | |
891 | push_obstacks (function->function_obstack, | |
892 | function->function_maybepermanent_obstack); | |
893 | temp | |
894 | = (struct var_refs_queue *) oballoc (sizeof (struct var_refs_queue)); | |
895 | temp->modified = reg; | |
00d8a4c1 RK |
896 | temp->promoted_mode = promoted_mode; |
897 | temp->unsignedp = TREE_UNSIGNED (TREE_TYPE (decl)); | |
6f086dfc RS |
898 | temp->next = function->fixup_var_refs_queue; |
899 | function->fixup_var_refs_queue = temp; | |
900 | pop_obstacks (); | |
901 | } | |
902 | else | |
903 | /* Variable is local; fix it up now. */ | |
00d8a4c1 | 904 | fixup_var_refs (reg, promoted_mode, TREE_UNSIGNED (TREE_TYPE (decl))); |
6f086dfc RS |
905 | } |
906 | \f | |
907 | static void | |
00d8a4c1 | 908 | fixup_var_refs (var, promoted_mode, unsignedp) |
6f086dfc | 909 | rtx var; |
00d8a4c1 RK |
910 | enum machine_mode promoted_mode; |
911 | int unsignedp; | |
6f086dfc RS |
912 | { |
913 | tree pending; | |
914 | rtx first_insn = get_insns (); | |
915 | struct sequence_stack *stack = sequence_stack; | |
916 | tree rtl_exps = rtl_expr_chain; | |
917 | ||
918 | /* Must scan all insns for stack-refs that exceed the limit. */ | |
00d8a4c1 | 919 | fixup_var_refs_insns (var, promoted_mode, unsignedp, first_insn, stack == 0); |
6f086dfc RS |
920 | |
921 | /* Scan all pending sequences too. */ | |
922 | for (; stack; stack = stack->next) | |
923 | { | |
924 | push_to_sequence (stack->first); | |
00d8a4c1 RK |
925 | fixup_var_refs_insns (var, promoted_mode, unsignedp, |
926 | stack->first, stack->next != 0); | |
6f086dfc RS |
927 | /* Update remembered end of sequence |
928 | in case we added an insn at the end. */ | |
929 | stack->last = get_last_insn (); | |
930 | end_sequence (); | |
931 | } | |
932 | ||
933 | /* Scan all waiting RTL_EXPRs too. */ | |
934 | for (pending = rtl_exps; pending; pending = TREE_CHAIN (pending)) | |
935 | { | |
936 | rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending)); | |
937 | if (seq != const0_rtx && seq != 0) | |
938 | { | |
939 | push_to_sequence (seq); | |
00d8a4c1 | 940 | fixup_var_refs_insns (var, promoted_mode, unsignedp, seq, 0); |
6f086dfc RS |
941 | end_sequence (); |
942 | } | |
943 | } | |
944 | } | |
945 | \f | |
946 | /* This structure is used by the following two functions to record MEMs or | |
947 | pseudos used to replace VAR, any SUBREGs of VAR, and any MEMs containing | |
948 | VAR as an address. We need to maintain this list in case two operands of | |
949 | an insn were required to match; in that case we must ensure we use the | |
950 | same replacement. */ | |
951 | ||
952 | struct fixup_replacement | |
953 | { | |
954 | rtx old; | |
955 | rtx new; | |
956 | struct fixup_replacement *next; | |
957 | }; | |
958 | ||
959 | /* REPLACEMENTS is a pointer to a list of the above structures and X is | |
960 | some part of an insn. Return a struct fixup_replacement whose OLD | |
961 | value is equal to X. Allocate a new structure if no such entry exists. */ | |
962 | ||
963 | static struct fixup_replacement * | |
964 | find_replacement (replacements, x) | |
965 | struct fixup_replacement **replacements; | |
966 | rtx x; | |
967 | { | |
968 | struct fixup_replacement *p; | |
969 | ||
970 | /* See if we have already replaced this. */ | |
971 | for (p = *replacements; p && p->old != x; p = p->next) | |
972 | ; | |
973 | ||
974 | if (p == 0) | |
975 | { | |
976 | p = (struct fixup_replacement *) oballoc (sizeof (struct fixup_replacement)); | |
977 | p->old = x; | |
978 | p->new = 0; | |
979 | p->next = *replacements; | |
980 | *replacements = p; | |
981 | } | |
982 | ||
983 | return p; | |
984 | } | |
985 | ||
986 | /* Scan the insn-chain starting with INSN for refs to VAR | |
987 | and fix them up. TOPLEVEL is nonzero if this chain is the | |
988 | main chain of insns for the current function. */ | |
989 | ||
990 | static void | |
00d8a4c1 | 991 | fixup_var_refs_insns (var, promoted_mode, unsignedp, insn, toplevel) |
6f086dfc | 992 | rtx var; |
00d8a4c1 RK |
993 | enum machine_mode promoted_mode; |
994 | int unsignedp; | |
6f086dfc RS |
995 | rtx insn; |
996 | int toplevel; | |
997 | { | |
998 | while (insn) | |
999 | { | |
1000 | rtx next = NEXT_INSN (insn); | |
1001 | rtx note; | |
1002 | if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN | |
1003 | || GET_CODE (insn) == JUMP_INSN) | |
1004 | { | |
1005 | /* The insn to load VAR from a home in the arglist | |
1006 | is now a no-op. When we see it, just delete it. */ | |
1007 | if (toplevel | |
1008 | && GET_CODE (PATTERN (insn)) == SET | |
1009 | && SET_DEST (PATTERN (insn)) == var | |
1010 | && rtx_equal_p (SET_SRC (PATTERN (insn)), var)) | |
1011 | { | |
1012 | next = delete_insn (insn); | |
1013 | if (insn == last_parm_insn) | |
1014 | last_parm_insn = PREV_INSN (next); | |
1015 | } | |
1016 | else | |
1017 | { | |
1018 | /* See if we have to do anything to INSN now that VAR is in | |
1019 | memory. If it needs to be loaded into a pseudo, use a single | |
1020 | pseudo for the entire insn in case there is a MATCH_DUP | |
1021 | between two operands. We pass a pointer to the head of | |
1022 | a list of struct fixup_replacements. If fixup_var_refs_1 | |
1023 | needs to allocate pseudos or replacement MEMs (for SUBREGs), | |
1024 | it will record them in this list. | |
1025 | ||
1026 | If it allocated a pseudo for any replacement, we copy into | |
1027 | it here. */ | |
1028 | ||
1029 | struct fixup_replacement *replacements = 0; | |
1030 | ||
00d8a4c1 RK |
1031 | fixup_var_refs_1 (var, promoted_mode, &PATTERN (insn), insn, |
1032 | &replacements); | |
6f086dfc RS |
1033 | |
1034 | while (replacements) | |
1035 | { | |
1036 | if (GET_CODE (replacements->new) == REG) | |
1037 | { | |
1038 | rtx insert_before; | |
00d8a4c1 | 1039 | rtx seq; |
6f086dfc RS |
1040 | |
1041 | /* OLD might be a (subreg (mem)). */ | |
1042 | if (GET_CODE (replacements->old) == SUBREG) | |
1043 | replacements->old | |
1044 | = fixup_memory_subreg (replacements->old, insn, 0); | |
1045 | else | |
1046 | replacements->old | |
1047 | = fixup_stack_1 (replacements->old, insn); | |
1048 | ||
1049 | /* We can not separate USE insns from the CALL_INSN | |
1050 | that they belong to. If this is a CALL_INSN, insert | |
b335c2cc | 1051 | the move insn before the USE insns preceding it |
6f086dfc RS |
1052 | instead of immediately before the insn. */ |
1053 | if (GET_CODE (insn) == CALL_INSN) | |
1054 | { | |
1055 | insert_before = insn; | |
1056 | while (GET_CODE (PREV_INSN (insert_before)) == INSN | |
1057 | && GET_CODE (PATTERN (PREV_INSN (insert_before))) == USE) | |
1058 | insert_before = PREV_INSN (insert_before); | |
1059 | } | |
1060 | else | |
1061 | insert_before = insn; | |
1062 | ||
00d8a4c1 RK |
1063 | /* If we are changing the mode, do a conversion. |
1064 | This might be wasteful, but combine.c will | |
1065 | eliminate much of the waste. */ | |
1066 | ||
1067 | if (GET_MODE (replacements->new) | |
1068 | != GET_MODE (replacements->old)) | |
1069 | { | |
1070 | start_sequence (); | |
1071 | convert_move (replacements->new, | |
1072 | replacements->old, unsignedp); | |
1073 | seq = gen_sequence (); | |
1074 | end_sequence (); | |
1075 | } | |
1076 | else | |
1077 | seq = gen_move_insn (replacements->new, | |
1078 | replacements->old); | |
1079 | ||
1080 | emit_insn_before (seq, insert_before); | |
6f086dfc RS |
1081 | } |
1082 | ||
1083 | replacements = replacements->next; | |
1084 | } | |
1085 | } | |
1086 | ||
1087 | /* Also fix up any invalid exprs in the REG_NOTES of this insn. | |
1088 | But don't touch other insns referred to by reg-notes; | |
1089 | we will get them elsewhere. */ | |
1090 | for (note = REG_NOTES (insn); note; note = XEXP (note, 1)) | |
1091 | if (GET_CODE (note) != INSN_LIST) | |
1092 | XEXP (note, 0) = walk_fixup_memory_subreg (XEXP (note, 0), insn); | |
1093 | } | |
1094 | insn = next; | |
1095 | } | |
1096 | } | |
1097 | \f | |
00d8a4c1 RK |
1098 | /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE. |
1099 | See if the rtx expression at *LOC in INSN needs to be changed. | |
6f086dfc RS |
1100 | |
1101 | REPLACEMENTS is a pointer to a list head that starts out zero, but may | |
1102 | contain a list of original rtx's and replacements. If we find that we need | |
1103 | to modify this insn by replacing a memory reference with a pseudo or by | |
1104 | making a new MEM to implement a SUBREG, we consult that list to see if | |
1105 | we have already chosen a replacement. If none has already been allocated, | |
1106 | we allocate it and update the list. fixup_var_refs_insns will copy VAR | |
1107 | or the SUBREG, as appropriate, to the pseudo. */ | |
1108 | ||
1109 | static void | |
00d8a4c1 | 1110 | fixup_var_refs_1 (var, promoted_mode, loc, insn, replacements) |
6f086dfc | 1111 | register rtx var; |
00d8a4c1 | 1112 | enum machine_mode promoted_mode; |
6f086dfc RS |
1113 | register rtx *loc; |
1114 | rtx insn; | |
1115 | struct fixup_replacement **replacements; | |
1116 | { | |
1117 | register int i; | |
1118 | register rtx x = *loc; | |
1119 | RTX_CODE code = GET_CODE (x); | |
1120 | register char *fmt; | |
1121 | register rtx tem, tem1; | |
1122 | struct fixup_replacement *replacement; | |
1123 | ||
1124 | switch (code) | |
1125 | { | |
1126 | case MEM: | |
1127 | if (var == x) | |
1128 | { | |
1129 | /* If we already have a replacement, use it. Otherwise, | |
1130 | try to fix up this address in case it is invalid. */ | |
1131 | ||
1132 | replacement = find_replacement (replacements, var); | |
1133 | if (replacement->new) | |
1134 | { | |
1135 | *loc = replacement->new; | |
1136 | return; | |
1137 | } | |
1138 | ||
1139 | *loc = replacement->new = x = fixup_stack_1 (x, insn); | |
1140 | ||
00d8a4c1 RK |
1141 | /* Unless we are forcing memory to register or we changed the mode, |
1142 | we can leave things the way they are if the insn is valid. */ | |
6f086dfc RS |
1143 | |
1144 | INSN_CODE (insn) = -1; | |
00d8a4c1 RK |
1145 | if (! flag_force_mem && GET_MODE (x) == promoted_mode |
1146 | && recog_memoized (insn) >= 0) | |
6f086dfc RS |
1147 | return; |
1148 | ||
00d8a4c1 | 1149 | *loc = replacement->new = gen_reg_rtx (promoted_mode); |
6f086dfc RS |
1150 | return; |
1151 | } | |
1152 | ||
1153 | /* If X contains VAR, we need to unshare it here so that we update | |
1154 | each occurrence separately. But all identical MEMs in one insn | |
1155 | must be replaced with the same rtx because of the possibility of | |
1156 | MATCH_DUPs. */ | |
1157 | ||
1158 | if (reg_mentioned_p (var, x)) | |
1159 | { | |
1160 | replacement = find_replacement (replacements, x); | |
1161 | if (replacement->new == 0) | |
1162 | replacement->new = copy_most_rtx (x, var); | |
1163 | ||
1164 | *loc = x = replacement->new; | |
1165 | } | |
1166 | break; | |
1167 | ||
1168 | case REG: | |
1169 | case CC0: | |
1170 | case PC: | |
1171 | case CONST_INT: | |
1172 | case CONST: | |
1173 | case SYMBOL_REF: | |
1174 | case LABEL_REF: | |
1175 | case CONST_DOUBLE: | |
1176 | return; | |
1177 | ||
1178 | case SIGN_EXTRACT: | |
1179 | case ZERO_EXTRACT: | |
1180 | /* Note that in some cases those types of expressions are altered | |
1181 | by optimize_bit_field, and do not survive to get here. */ | |
1182 | if (XEXP (x, 0) == var | |
1183 | || (GET_CODE (XEXP (x, 0)) == SUBREG | |
1184 | && SUBREG_REG (XEXP (x, 0)) == var)) | |
1185 | { | |
1186 | /* Get TEM as a valid MEM in the mode presently in the insn. | |
1187 | ||
1188 | We don't worry about the possibility of MATCH_DUP here; it | |
1189 | is highly unlikely and would be tricky to handle. */ | |
1190 | ||
1191 | tem = XEXP (x, 0); | |
1192 | if (GET_CODE (tem) == SUBREG) | |
1193 | tem = fixup_memory_subreg (tem, insn, 1); | |
1194 | tem = fixup_stack_1 (tem, insn); | |
1195 | ||
1196 | /* Unless we want to load from memory, get TEM into the proper mode | |
1197 | for an extract from memory. This can only be done if the | |
1198 | extract is at a constant position and length. */ | |
1199 | ||
1200 | if (! flag_force_mem && GET_CODE (XEXP (x, 1)) == CONST_INT | |
1201 | && GET_CODE (XEXP (x, 2)) == CONST_INT | |
1202 | && ! mode_dependent_address_p (XEXP (tem, 0)) | |
1203 | && ! MEM_VOLATILE_P (tem)) | |
1204 | { | |
1205 | enum machine_mode wanted_mode = VOIDmode; | |
1206 | enum machine_mode is_mode = GET_MODE (tem); | |
1207 | int width = INTVAL (XEXP (x, 1)); | |
1208 | int pos = INTVAL (XEXP (x, 2)); | |
1209 | ||
1210 | #ifdef HAVE_extzv | |
1211 | if (GET_CODE (x) == ZERO_EXTRACT) | |
1212 | wanted_mode = insn_operand_mode[(int) CODE_FOR_extzv][1]; | |
1213 | #endif | |
1214 | #ifdef HAVE_extv | |
1215 | if (GET_CODE (x) == SIGN_EXTRACT) | |
1216 | wanted_mode = insn_operand_mode[(int) CODE_FOR_extv][1]; | |
1217 | #endif | |
6dc42e49 | 1218 | /* If we have a narrower mode, we can do something. */ |
6f086dfc RS |
1219 | if (wanted_mode != VOIDmode |
1220 | && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode)) | |
1221 | { | |
1222 | int offset = pos / BITS_PER_UNIT; | |
1223 | rtx old_pos = XEXP (x, 2); | |
1224 | rtx newmem; | |
1225 | ||
1226 | /* If the bytes and bits are counted differently, we | |
1227 | must adjust the offset. */ | |
1228 | #if BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN | |
1229 | offset = (GET_MODE_SIZE (is_mode) | |
1230 | - GET_MODE_SIZE (wanted_mode) - offset); | |
1231 | #endif | |
1232 | ||
1233 | pos %= GET_MODE_BITSIZE (wanted_mode); | |
1234 | ||
1235 | newmem = gen_rtx (MEM, wanted_mode, | |
1236 | plus_constant (XEXP (tem, 0), offset)); | |
1237 | RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem); | |
1238 | MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem); | |
1239 | MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem); | |
1240 | ||
1241 | /* Make the change and see if the insn remains valid. */ | |
1242 | INSN_CODE (insn) = -1; | |
1243 | XEXP (x, 0) = newmem; | |
5f4f0e22 | 1244 | XEXP (x, 2) = GEN_INT (pos); |
6f086dfc RS |
1245 | |
1246 | if (recog_memoized (insn) >= 0) | |
1247 | return; | |
1248 | ||
1249 | /* Otherwise, restore old position. XEXP (x, 0) will be | |
1250 | restored later. */ | |
1251 | XEXP (x, 2) = old_pos; | |
1252 | } | |
1253 | } | |
1254 | ||
1255 | /* If we get here, the bitfield extract insn can't accept a memory | |
1256 | reference. Copy the input into a register. */ | |
1257 | ||
1258 | tem1 = gen_reg_rtx (GET_MODE (tem)); | |
1259 | emit_insn_before (gen_move_insn (tem1, tem), insn); | |
1260 | XEXP (x, 0) = tem1; | |
1261 | return; | |
1262 | } | |
1263 | break; | |
1264 | ||
1265 | case SUBREG: | |
1266 | if (SUBREG_REG (x) == var) | |
1267 | { | |
00d8a4c1 RK |
1268 | /* If this is a special SUBREG made because VAR was promoted |
1269 | from a wider mode, replace it with VAR and call ourself | |
1270 | recursively, this time saying that the object previously | |
1271 | had its current mode (by virtue of the SUBREG). */ | |
1272 | ||
1273 | if (SUBREG_PROMOTED_VAR_P (x)) | |
1274 | { | |
1275 | *loc = var; | |
1276 | fixup_var_refs_1 (var, GET_MODE (var), loc, insn, replacements); | |
1277 | return; | |
1278 | } | |
1279 | ||
6f086dfc RS |
1280 | /* If this SUBREG makes VAR wider, it has become a paradoxical |
1281 | SUBREG with VAR in memory, but these aren't allowed at this | |
1282 | stage of the compilation. So load VAR into a pseudo and take | |
1283 | a SUBREG of that pseudo. */ | |
1284 | if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (var))) | |
1285 | { | |
1286 | replacement = find_replacement (replacements, var); | |
1287 | if (replacement->new == 0) | |
1288 | replacement->new = gen_reg_rtx (GET_MODE (var)); | |
1289 | SUBREG_REG (x) = replacement->new; | |
1290 | return; | |
1291 | } | |
1292 | ||
1293 | /* See if we have already found a replacement for this SUBREG. | |
1294 | If so, use it. Otherwise, make a MEM and see if the insn | |
1295 | is recognized. If not, or if we should force MEM into a register, | |
1296 | make a pseudo for this SUBREG. */ | |
1297 | replacement = find_replacement (replacements, x); | |
1298 | if (replacement->new) | |
1299 | { | |
1300 | *loc = replacement->new; | |
1301 | return; | |
1302 | } | |
1303 | ||
1304 | replacement->new = *loc = fixup_memory_subreg (x, insn, 0); | |
1305 | ||
1306 | if (! flag_force_mem && recog_memoized (insn) >= 0) | |
1307 | return; | |
1308 | ||
1309 | *loc = replacement->new = gen_reg_rtx (GET_MODE (x)); | |
1310 | return; | |
1311 | } | |
1312 | break; | |
1313 | ||
1314 | case SET: | |
1315 | /* First do special simplification of bit-field references. */ | |
1316 | if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT | |
1317 | || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT) | |
1318 | optimize_bit_field (x, insn, 0); | |
1319 | if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT | |
1320 | || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT) | |
5f4f0e22 | 1321 | optimize_bit_field (x, insn, NULL_PTR); |
6f086dfc RS |
1322 | |
1323 | /* If SET_DEST is now a paradoxical SUBREG, put the result of this | |
1324 | insn into a pseudo and store the low part of the pseudo into VAR. */ | |
1325 | if (GET_CODE (SET_DEST (x)) == SUBREG | |
1326 | && SUBREG_REG (SET_DEST (x)) == var | |
1327 | && (GET_MODE_SIZE (GET_MODE (SET_DEST (x))) | |
1328 | > GET_MODE_SIZE (GET_MODE (var)))) | |
1329 | { | |
1330 | SET_DEST (x) = tem = gen_reg_rtx (GET_MODE (SET_DEST (x))); | |
1331 | emit_insn_after (gen_move_insn (var, gen_lowpart (GET_MODE (var), | |
1332 | tem)), | |
1333 | insn); | |
1334 | break; | |
1335 | } | |
1336 | ||
1337 | { | |
1338 | rtx dest = SET_DEST (x); | |
1339 | rtx src = SET_SRC (x); | |
1340 | rtx outerdest = dest; | |
1341 | ||
1342 | while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART | |
1343 | || GET_CODE (dest) == SIGN_EXTRACT | |
1344 | || GET_CODE (dest) == ZERO_EXTRACT) | |
1345 | dest = XEXP (dest, 0); | |
1346 | ||
1347 | if (GET_CODE (src) == SUBREG) | |
1348 | src = XEXP (src, 0); | |
1349 | ||
1350 | /* If VAR does not appear at the top level of the SET | |
1351 | just scan the lower levels of the tree. */ | |
1352 | ||
1353 | if (src != var && dest != var) | |
1354 | break; | |
1355 | ||
1356 | /* We will need to rerecognize this insn. */ | |
1357 | INSN_CODE (insn) = -1; | |
1358 | ||
1359 | #ifdef HAVE_insv | |
1360 | if (GET_CODE (outerdest) == ZERO_EXTRACT && dest == var) | |
1361 | { | |
1362 | /* Since this case will return, ensure we fixup all the | |
1363 | operands here. */ | |
00d8a4c1 RK |
1364 | fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 1), |
1365 | insn, replacements); | |
1366 | fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 2), | |
1367 | insn, replacements); | |
1368 | fixup_var_refs_1 (var, promoted_mode, &SET_SRC (x), | |
1369 | insn, replacements); | |
6f086dfc RS |
1370 | |
1371 | tem = XEXP (outerdest, 0); | |
1372 | ||
1373 | /* Clean up (SUBREG:SI (MEM:mode ...) 0) | |
1374 | that may appear inside a ZERO_EXTRACT. | |
1375 | This was legitimate when the MEM was a REG. */ | |
1376 | if (GET_CODE (tem) == SUBREG | |
1377 | && SUBREG_REG (tem) == var) | |
1378 | tem = fixup_memory_subreg (tem, insn, 1); | |
1379 | else | |
1380 | tem = fixup_stack_1 (tem, insn); | |
1381 | ||
1382 | if (GET_CODE (XEXP (outerdest, 1)) == CONST_INT | |
1383 | && GET_CODE (XEXP (outerdest, 2)) == CONST_INT | |
1384 | && ! mode_dependent_address_p (XEXP (tem, 0)) | |
1385 | && ! MEM_VOLATILE_P (tem)) | |
1386 | { | |
1387 | enum machine_mode wanted_mode | |
1388 | = insn_operand_mode[(int) CODE_FOR_insv][0]; | |
1389 | enum machine_mode is_mode = GET_MODE (tem); | |
1390 | int width = INTVAL (XEXP (outerdest, 1)); | |
1391 | int pos = INTVAL (XEXP (outerdest, 2)); | |
1392 | ||
6dc42e49 | 1393 | /* If we have a narrower mode, we can do something. */ |
6f086dfc RS |
1394 | if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode)) |
1395 | { | |
1396 | int offset = pos / BITS_PER_UNIT; | |
1397 | rtx old_pos = XEXP (outerdest, 2); | |
1398 | rtx newmem; | |
1399 | ||
1400 | #if BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN | |
1401 | offset = (GET_MODE_SIZE (is_mode) | |
1402 | - GET_MODE_SIZE (wanted_mode) - offset); | |
1403 | #endif | |
1404 | ||
1405 | pos %= GET_MODE_BITSIZE (wanted_mode); | |
1406 | ||
1407 | newmem = gen_rtx (MEM, wanted_mode, | |
1408 | plus_constant (XEXP (tem, 0), offset)); | |
1409 | RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem); | |
1410 | MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem); | |
1411 | MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem); | |
1412 | ||
1413 | /* Make the change and see if the insn remains valid. */ | |
1414 | INSN_CODE (insn) = -1; | |
1415 | XEXP (outerdest, 0) = newmem; | |
5f4f0e22 | 1416 | XEXP (outerdest, 2) = GEN_INT (pos); |
6f086dfc RS |
1417 | |
1418 | if (recog_memoized (insn) >= 0) | |
1419 | return; | |
1420 | ||
1421 | /* Otherwise, restore old position. XEXP (x, 0) will be | |
1422 | restored later. */ | |
1423 | XEXP (outerdest, 2) = old_pos; | |
1424 | } | |
1425 | } | |
1426 | ||
1427 | /* If we get here, the bit-field store doesn't allow memory | |
1428 | or isn't located at a constant position. Load the value into | |
1429 | a register, do the store, and put it back into memory. */ | |
1430 | ||
1431 | tem1 = gen_reg_rtx (GET_MODE (tem)); | |
1432 | emit_insn_before (gen_move_insn (tem1, tem), insn); | |
1433 | emit_insn_after (gen_move_insn (tem, tem1), insn); | |
1434 | XEXP (outerdest, 0) = tem1; | |
1435 | return; | |
1436 | } | |
1437 | #endif | |
1438 | ||
1439 | /* STRICT_LOW_PART is a no-op on memory references | |
1440 | and it can cause combinations to be unrecognizable, | |
1441 | so eliminate it. */ | |
1442 | ||
1443 | if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART) | |
1444 | SET_DEST (x) = XEXP (SET_DEST (x), 0); | |
1445 | ||
1446 | /* A valid insn to copy VAR into or out of a register | |
1447 | must be left alone, to avoid an infinite loop here. | |
1448 | If the reference to VAR is by a subreg, fix that up, | |
1449 | since SUBREG is not valid for a memref. | |
1450 | Also fix up the address of the stack slot. */ | |
1451 | ||
1452 | if ((SET_SRC (x) == var | |
1453 | || (GET_CODE (SET_SRC (x)) == SUBREG | |
1454 | && SUBREG_REG (SET_SRC (x)) == var)) | |
1455 | && (GET_CODE (SET_DEST (x)) == REG | |
1456 | || (GET_CODE (SET_DEST (x)) == SUBREG | |
1457 | && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG)) | |
1458 | && recog_memoized (insn) >= 0) | |
1459 | { | |
1460 | replacement = find_replacement (replacements, SET_SRC (x)); | |
1461 | if (replacement->new) | |
1462 | { | |
1463 | SET_SRC (x) = replacement->new; | |
1464 | return; | |
1465 | } | |
1466 | else if (GET_CODE (SET_SRC (x)) == SUBREG) | |
1467 | SET_SRC (x) = replacement->new | |
1468 | = fixup_memory_subreg (SET_SRC (x), insn, 0); | |
1469 | else | |
1470 | SET_SRC (x) = replacement->new | |
1471 | = fixup_stack_1 (SET_SRC (x), insn); | |
1472 | return; | |
1473 | } | |
1474 | ||
1475 | if ((SET_DEST (x) == var | |
1476 | || (GET_CODE (SET_DEST (x)) == SUBREG | |
1477 | && SUBREG_REG (SET_DEST (x)) == var)) | |
1478 | && (GET_CODE (SET_SRC (x)) == REG | |
1479 | || (GET_CODE (SET_SRC (x)) == SUBREG | |
1480 | && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG)) | |
1481 | && recog_memoized (insn) >= 0) | |
1482 | { | |
1483 | if (GET_CODE (SET_DEST (x)) == SUBREG) | |
1484 | SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn, 0); | |
1485 | else | |
1486 | SET_DEST (x) = fixup_stack_1 (SET_DEST (x), insn); | |
1487 | return; | |
1488 | } | |
1489 | ||
1490 | /* Otherwise, storing into VAR must be handled specially | |
1491 | by storing into a temporary and copying that into VAR | |
00d8a4c1 RK |
1492 | with a new insn after this one. Note that this case |
1493 | will be used when storing into a promoted scalar since | |
1494 | the insn will now have different modes on the input | |
1495 | and output and hence will be invalid (except for the case | |
1496 | of setting it to a constant, which does not need any | |
1497 | change if it is valid). We generate extra code in that case, | |
1498 | but combine.c will eliminate it. */ | |
6f086dfc RS |
1499 | |
1500 | if (dest == var) | |
1501 | { | |
1502 | rtx temp; | |
00d8a4c1 RK |
1503 | rtx fixeddest = SET_DEST (x); |
1504 | ||
6f086dfc | 1505 | /* STRICT_LOW_PART can be discarded, around a MEM. */ |
00d8a4c1 RK |
1506 | if (GET_CODE (fixeddest) == STRICT_LOW_PART) |
1507 | fixeddest = XEXP (fixeddest, 0); | |
6f086dfc | 1508 | /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */ |
00d8a4c1 RK |
1509 | if (GET_CODE (fixeddest) == SUBREG) |
1510 | fixeddest = fixup_memory_subreg (fixeddest, insn, 0); | |
6f086dfc | 1511 | else |
00d8a4c1 RK |
1512 | fixeddest = fixup_stack_1 (fixeddest, insn); |
1513 | ||
1514 | temp = gen_reg_rtx (GET_MODE (SET_SRC (x)) == VOIDmode | |
1515 | ? GET_MODE (fixeddest) | |
1516 | : GET_MODE (SET_SRC (x))); | |
1517 | ||
1518 | emit_insn_after (gen_move_insn (fixeddest, | |
1519 | gen_lowpart (GET_MODE (fixeddest), | |
1520 | temp)), | |
1521 | insn); | |
6f086dfc | 1522 | |
6f086dfc RS |
1523 | SET_DEST (x) = temp; |
1524 | } | |
1525 | } | |
1526 | } | |
1527 | ||
1528 | /* Nothing special about this RTX; fix its operands. */ | |
1529 | ||
1530 | fmt = GET_RTX_FORMAT (code); | |
1531 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
1532 | { | |
1533 | if (fmt[i] == 'e') | |
00d8a4c1 | 1534 | fixup_var_refs_1 (var, promoted_mode, &XEXP (x, i), insn, replacements); |
6f086dfc RS |
1535 | if (fmt[i] == 'E') |
1536 | { | |
1537 | register int j; | |
1538 | for (j = 0; j < XVECLEN (x, i); j++) | |
00d8a4c1 RK |
1539 | fixup_var_refs_1 (var, promoted_mode, &XVECEXP (x, i, j), |
1540 | insn, replacements); | |
6f086dfc RS |
1541 | } |
1542 | } | |
1543 | } | |
1544 | \f | |
1545 | /* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)), | |
1546 | return an rtx (MEM:m1 newaddr) which is equivalent. | |
1547 | If any insns must be emitted to compute NEWADDR, put them before INSN. | |
1548 | ||
1549 | UNCRITICAL nonzero means accept paradoxical subregs. | |
1550 | This is used for subregs found inside of ZERO_EXTRACTs. */ | |
1551 | ||
1552 | static rtx | |
1553 | fixup_memory_subreg (x, insn, uncritical) | |
1554 | rtx x; | |
1555 | rtx insn; | |
1556 | int uncritical; | |
1557 | { | |
1558 | int offset = SUBREG_WORD (x) * UNITS_PER_WORD; | |
1559 | rtx addr = XEXP (SUBREG_REG (x), 0); | |
1560 | enum machine_mode mode = GET_MODE (x); | |
1561 | rtx saved, result; | |
1562 | ||
1563 | /* Paradoxical SUBREGs are usually invalid during RTL generation. */ | |
1564 | if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) | |
1565 | && ! uncritical) | |
1566 | abort (); | |
1567 | ||
1568 | #if BYTES_BIG_ENDIAN | |
1569 | offset += (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))) | |
1570 | - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))); | |
1571 | #endif | |
1572 | addr = plus_constant (addr, offset); | |
1573 | if (!flag_force_addr && memory_address_p (mode, addr)) | |
1574 | /* Shortcut if no insns need be emitted. */ | |
1575 | return change_address (SUBREG_REG (x), mode, addr); | |
1576 | start_sequence (); | |
1577 | result = change_address (SUBREG_REG (x), mode, addr); | |
1578 | emit_insn_before (gen_sequence (), insn); | |
1579 | end_sequence (); | |
1580 | return result; | |
1581 | } | |
1582 | ||
1583 | /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X. | |
1584 | Replace subexpressions of X in place. | |
1585 | If X itself is a (SUBREG (MEM ...) ...), return the replacement expression. | |
1586 | Otherwise return X, with its contents possibly altered. | |
1587 | ||
1588 | If any insns must be emitted to compute NEWADDR, put them before INSN. */ | |
1589 | ||
1590 | static rtx | |
1591 | walk_fixup_memory_subreg (x, insn) | |
1592 | register rtx x; | |
1593 | rtx insn; | |
1594 | { | |
1595 | register enum rtx_code code; | |
1596 | register char *fmt; | |
1597 | register int i; | |
1598 | ||
1599 | if (x == 0) | |
1600 | return 0; | |
1601 | ||
1602 | code = GET_CODE (x); | |
1603 | ||
1604 | if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM) | |
1605 | return fixup_memory_subreg (x, insn, 0); | |
1606 | ||
1607 | /* Nothing special about this RTX; fix its operands. */ | |
1608 | ||
1609 | fmt = GET_RTX_FORMAT (code); | |
1610 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
1611 | { | |
1612 | if (fmt[i] == 'e') | |
1613 | XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn); | |
1614 | if (fmt[i] == 'E') | |
1615 | { | |
1616 | register int j; | |
1617 | for (j = 0; j < XVECLEN (x, i); j++) | |
1618 | XVECEXP (x, i, j) | |
1619 | = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn); | |
1620 | } | |
1621 | } | |
1622 | return x; | |
1623 | } | |
1624 | \f | |
1625 | #if 0 | |
1626 | /* Fix up any references to stack slots that are invalid memory addresses | |
1627 | because they exceed the maximum range of a displacement. */ | |
1628 | ||
1629 | void | |
1630 | fixup_stack_slots () | |
1631 | { | |
1632 | register rtx insn; | |
1633 | ||
1634 | /* Did we generate a stack slot that is out of range | |
1635 | or otherwise has an invalid address? */ | |
1636 | if (invalid_stack_slot) | |
1637 | { | |
1638 | /* Yes. Must scan all insns for stack-refs that exceed the limit. */ | |
1639 | for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) | |
1640 | if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN | |
1641 | || GET_CODE (insn) == JUMP_INSN) | |
1642 | fixup_stack_1 (PATTERN (insn), insn); | |
1643 | } | |
1644 | } | |
1645 | #endif | |
1646 | ||
1647 | /* For each memory ref within X, if it refers to a stack slot | |
1648 | with an out of range displacement, put the address in a temp register | |
1649 | (emitting new insns before INSN to load these registers) | |
1650 | and alter the memory ref to use that register. | |
1651 | Replace each such MEM rtx with a copy, to avoid clobberage. */ | |
1652 | ||
1653 | static rtx | |
1654 | fixup_stack_1 (x, insn) | |
1655 | rtx x; | |
1656 | rtx insn; | |
1657 | { | |
1658 | register int i; | |
1659 | register RTX_CODE code = GET_CODE (x); | |
1660 | register char *fmt; | |
1661 | ||
1662 | if (code == MEM) | |
1663 | { | |
1664 | register rtx ad = XEXP (x, 0); | |
1665 | /* If we have address of a stack slot but it's not valid | |
1666 | (displacement is too large), compute the sum in a register. */ | |
1667 | if (GET_CODE (ad) == PLUS | |
1668 | && GET_CODE (XEXP (ad, 0)) == REG | |
1669 | && REGNO (XEXP (ad, 0)) >= FIRST_VIRTUAL_REGISTER | |
1670 | && REGNO (XEXP (ad, 0)) <= LAST_VIRTUAL_REGISTER | |
1671 | && GET_CODE (XEXP (ad, 1)) == CONST_INT) | |
1672 | { | |
1673 | rtx temp, seq; | |
1674 | if (memory_address_p (GET_MODE (x), ad)) | |
1675 | return x; | |
1676 | ||
1677 | start_sequence (); | |
1678 | temp = copy_to_reg (ad); | |
1679 | seq = gen_sequence (); | |
1680 | end_sequence (); | |
1681 | emit_insn_before (seq, insn); | |
1682 | return change_address (x, VOIDmode, temp); | |
1683 | } | |
1684 | return x; | |
1685 | } | |
1686 | ||
1687 | fmt = GET_RTX_FORMAT (code); | |
1688 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
1689 | { | |
1690 | if (fmt[i] == 'e') | |
1691 | XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn); | |
1692 | if (fmt[i] == 'E') | |
1693 | { | |
1694 | register int j; | |
1695 | for (j = 0; j < XVECLEN (x, i); j++) | |
1696 | XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn); | |
1697 | } | |
1698 | } | |
1699 | return x; | |
1700 | } | |
1701 | \f | |
1702 | /* Optimization: a bit-field instruction whose field | |
1703 | happens to be a byte or halfword in memory | |
1704 | can be changed to a move instruction. | |
1705 | ||
1706 | We call here when INSN is an insn to examine or store into a bit-field. | |
1707 | BODY is the SET-rtx to be altered. | |
1708 | ||
1709 | EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0. | |
1710 | (Currently this is called only from function.c, and EQUIV_MEM | |
1711 | is always 0.) */ | |
1712 | ||
1713 | static void | |
1714 | optimize_bit_field (body, insn, equiv_mem) | |
1715 | rtx body; | |
1716 | rtx insn; | |
1717 | rtx *equiv_mem; | |
1718 | { | |
1719 | register rtx bitfield; | |
1720 | int destflag; | |
1721 | rtx seq = 0; | |
1722 | enum machine_mode mode; | |
1723 | ||
1724 | if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT | |
1725 | || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT) | |
1726 | bitfield = SET_DEST (body), destflag = 1; | |
1727 | else | |
1728 | bitfield = SET_SRC (body), destflag = 0; | |
1729 | ||
1730 | /* First check that the field being stored has constant size and position | |
1731 | and is in fact a byte or halfword suitably aligned. */ | |
1732 | ||
1733 | if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT | |
1734 | && GET_CODE (XEXP (bitfield, 2)) == CONST_INT | |
1735 | && ((mode = mode_for_size (INTVAL (XEXP (bitfield, 1)), MODE_INT, 1)) | |
1736 | != BLKmode) | |
1737 | && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0) | |
1738 | { | |
1739 | register rtx memref = 0; | |
1740 | ||
1741 | /* Now check that the containing word is memory, not a register, | |
1742 | and that it is safe to change the machine mode. */ | |
1743 | ||
1744 | if (GET_CODE (XEXP (bitfield, 0)) == MEM) | |
1745 | memref = XEXP (bitfield, 0); | |
1746 | else if (GET_CODE (XEXP (bitfield, 0)) == REG | |
1747 | && equiv_mem != 0) | |
1748 | memref = equiv_mem[REGNO (XEXP (bitfield, 0))]; | |
1749 | else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG | |
1750 | && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM) | |
1751 | memref = SUBREG_REG (XEXP (bitfield, 0)); | |
1752 | else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG | |
1753 | && equiv_mem != 0 | |
1754 | && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG) | |
1755 | memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))]; | |
1756 | ||
1757 | if (memref | |
1758 | && ! mode_dependent_address_p (XEXP (memref, 0)) | |
1759 | && ! MEM_VOLATILE_P (memref)) | |
1760 | { | |
1761 | /* Now adjust the address, first for any subreg'ing | |
1762 | that we are now getting rid of, | |
1763 | and then for which byte of the word is wanted. */ | |
1764 | ||
1765 | register int offset = INTVAL (XEXP (bitfield, 2)); | |
1766 | /* Adjust OFFSET to count bits from low-address byte. */ | |
1767 | #if BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN | |
1768 | offset = (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield, 0))) | |
1769 | - offset - INTVAL (XEXP (bitfield, 1))); | |
1770 | #endif | |
1771 | /* Adjust OFFSET to count bytes from low-address byte. */ | |
1772 | offset /= BITS_PER_UNIT; | |
1773 | if (GET_CODE (XEXP (bitfield, 0)) == SUBREG) | |
1774 | { | |
1775 | offset += SUBREG_WORD (XEXP (bitfield, 0)) * UNITS_PER_WORD; | |
1776 | #if BYTES_BIG_ENDIAN | |
1777 | offset -= (MIN (UNITS_PER_WORD, | |
1778 | GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0)))) | |
1779 | - MIN (UNITS_PER_WORD, | |
1780 | GET_MODE_SIZE (GET_MODE (memref)))); | |
1781 | #endif | |
1782 | } | |
1783 | ||
1784 | memref = change_address (memref, mode, | |
1785 | plus_constant (XEXP (memref, 0), offset)); | |
1786 | ||
1787 | /* Store this memory reference where | |
1788 | we found the bit field reference. */ | |
1789 | ||
1790 | if (destflag) | |
1791 | { | |
1792 | validate_change (insn, &SET_DEST (body), memref, 1); | |
1793 | if (! CONSTANT_ADDRESS_P (SET_SRC (body))) | |
1794 | { | |
1795 | rtx src = SET_SRC (body); | |
1796 | while (GET_CODE (src) == SUBREG | |
1797 | && SUBREG_WORD (src) == 0) | |
1798 | src = SUBREG_REG (src); | |
1799 | if (GET_MODE (src) != GET_MODE (memref)) | |
1800 | src = gen_lowpart (GET_MODE (memref), SET_SRC (body)); | |
1801 | validate_change (insn, &SET_SRC (body), src, 1); | |
1802 | } | |
1803 | else if (GET_MODE (SET_SRC (body)) != VOIDmode | |
1804 | && GET_MODE (SET_SRC (body)) != GET_MODE (memref)) | |
1805 | /* This shouldn't happen because anything that didn't have | |
1806 | one of these modes should have got converted explicitly | |
1807 | and then referenced through a subreg. | |
1808 | This is so because the original bit-field was | |
1809 | handled by agg_mode and so its tree structure had | |
1810 | the same mode that memref now has. */ | |
1811 | abort (); | |
1812 | } | |
1813 | else | |
1814 | { | |
1815 | rtx dest = SET_DEST (body); | |
1816 | ||
1817 | while (GET_CODE (dest) == SUBREG | |
1818 | && SUBREG_WORD (dest) == 0) | |
1819 | dest = SUBREG_REG (dest); | |
1820 | ||
1821 | validate_change (insn, &SET_DEST (body), dest, 1); | |
1822 | ||
1823 | if (GET_MODE (dest) == GET_MODE (memref)) | |
1824 | validate_change (insn, &SET_SRC (body), memref, 1); | |
1825 | else | |
1826 | { | |
1827 | /* Convert the mem ref to the destination mode. */ | |
1828 | rtx newreg = gen_reg_rtx (GET_MODE (dest)); | |
1829 | ||
1830 | start_sequence (); | |
1831 | convert_move (newreg, memref, | |
1832 | GET_CODE (SET_SRC (body)) == ZERO_EXTRACT); | |
1833 | seq = get_insns (); | |
1834 | end_sequence (); | |
1835 | ||
1836 | validate_change (insn, &SET_SRC (body), newreg, 1); | |
1837 | } | |
1838 | } | |
1839 | ||
1840 | /* See if we can convert this extraction or insertion into | |
1841 | a simple move insn. We might not be able to do so if this | |
1842 | was, for example, part of a PARALLEL. | |
1843 | ||
1844 | If we succeed, write out any needed conversions. If we fail, | |
1845 | it is hard to guess why we failed, so don't do anything | |
1846 | special; just let the optimization be suppressed. */ | |
1847 | ||
1848 | if (apply_change_group () && seq) | |
1849 | emit_insns_before (seq, insn); | |
1850 | } | |
1851 | } | |
1852 | } | |
1853 | \f | |
1854 | /* These routines are responsible for converting virtual register references | |
1855 | to the actual hard register references once RTL generation is complete. | |
1856 | ||
1857 | The following four variables are used for communication between the | |
1858 | routines. They contain the offsets of the virtual registers from their | |
1859 | respective hard registers. */ | |
1860 | ||
1861 | static int in_arg_offset; | |
1862 | static int var_offset; | |
1863 | static int dynamic_offset; | |
1864 | static int out_arg_offset; | |
1865 | ||
1866 | /* In most machines, the stack pointer register is equivalent to the bottom | |
1867 | of the stack. */ | |
1868 | ||
1869 | #ifndef STACK_POINTER_OFFSET | |
1870 | #define STACK_POINTER_OFFSET 0 | |
1871 | #endif | |
1872 | ||
1873 | /* If not defined, pick an appropriate default for the offset of dynamically | |
1874 | allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS, | |
1875 | REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */ | |
1876 | ||
1877 | #ifndef STACK_DYNAMIC_OFFSET | |
1878 | ||
1879 | #ifdef ACCUMULATE_OUTGOING_ARGS | |
1880 | /* The bottom of the stack points to the actual arguments. If | |
1881 | REG_PARM_STACK_SPACE is defined, this includes the space for the register | |
1882 | parameters. However, if OUTGOING_REG_PARM_STACK space is not defined, | |
1883 | stack space for register parameters is not pushed by the caller, but | |
1884 | rather part of the fixed stack areas and hence not included in | |
1885 | `current_function_outgoing_args_size'. Nevertheless, we must allow | |
1886 | for it when allocating stack dynamic objects. */ | |
1887 | ||
1888 | #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE) | |
1889 | #define STACK_DYNAMIC_OFFSET(FNDECL) \ | |
1890 | (current_function_outgoing_args_size \ | |
1891 | + REG_PARM_STACK_SPACE (FNDECL) + (STACK_POINTER_OFFSET)) | |
1892 | ||
1893 | #else | |
1894 | #define STACK_DYNAMIC_OFFSET(FNDECL) \ | |
1895 | (current_function_outgoing_args_size + (STACK_POINTER_OFFSET)) | |
1896 | #endif | |
1897 | ||
1898 | #else | |
1899 | #define STACK_DYNAMIC_OFFSET(FNDECL) STACK_POINTER_OFFSET | |
1900 | #endif | |
1901 | #endif | |
1902 | ||
1903 | /* Pass through the INSNS of function FNDECL and convert virtual register | |
1904 | references to hard register references. */ | |
1905 | ||
1906 | void | |
1907 | instantiate_virtual_regs (fndecl, insns) | |
1908 | tree fndecl; | |
1909 | rtx insns; | |
1910 | { | |
1911 | rtx insn; | |
1912 | ||
1913 | /* Compute the offsets to use for this function. */ | |
1914 | in_arg_offset = FIRST_PARM_OFFSET (fndecl); | |
1915 | var_offset = STARTING_FRAME_OFFSET; | |
1916 | dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl); | |
1917 | out_arg_offset = STACK_POINTER_OFFSET; | |
1918 | ||
1919 | /* Scan all variables and parameters of this function. For each that is | |
1920 | in memory, instantiate all virtual registers if the result is a valid | |
1921 | address. If not, we do it later. That will handle most uses of virtual | |
1922 | regs on many machines. */ | |
1923 | instantiate_decls (fndecl, 1); | |
1924 | ||
1925 | /* Initialize recognition, indicating that volatile is OK. */ | |
1926 | init_recog (); | |
1927 | ||
1928 | /* Scan through all the insns, instantiating every virtual register still | |
1929 | present. */ | |
1930 | for (insn = insns; insn; insn = NEXT_INSN (insn)) | |
1931 | if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN | |
1932 | || GET_CODE (insn) == CALL_INSN) | |
1933 | { | |
1934 | instantiate_virtual_regs_1 (&PATTERN (insn), insn, 1); | |
5f4f0e22 | 1935 | instantiate_virtual_regs_1 (®_NOTES (insn), NULL_RTX, 0); |
6f086dfc RS |
1936 | } |
1937 | ||
1938 | /* Now instantiate the remaining register equivalences for debugging info. | |
1939 | These will not be valid addresses. */ | |
1940 | instantiate_decls (fndecl, 0); | |
1941 | ||
1942 | /* Indicate that, from now on, assign_stack_local should use | |
1943 | frame_pointer_rtx. */ | |
1944 | virtuals_instantiated = 1; | |
1945 | } | |
1946 | ||
1947 | /* Scan all decls in FNDECL (both variables and parameters) and instantiate | |
1948 | all virtual registers in their DECL_RTL's. | |
1949 | ||
1950 | If VALID_ONLY, do this only if the resulting address is still valid. | |
1951 | Otherwise, always do it. */ | |
1952 | ||
1953 | static void | |
1954 | instantiate_decls (fndecl, valid_only) | |
1955 | tree fndecl; | |
1956 | int valid_only; | |
1957 | { | |
1958 | tree decl; | |
1959 | ||
a82ad570 | 1960 | if (DECL_INLINE (fndecl)) |
6f086dfc RS |
1961 | /* When compiling an inline function, the obstack used for |
1962 | rtl allocation is the maybepermanent_obstack. Calling | |
1963 | `resume_temporary_allocation' switches us back to that | |
1964 | obstack while we process this function's parameters. */ | |
1965 | resume_temporary_allocation (); | |
1966 | ||
1967 | /* Process all parameters of the function. */ | |
1968 | for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl)) | |
1969 | { | |
5a73491b RK |
1970 | instantiate_decl (DECL_RTL (decl), int_size_in_bytes (TREE_TYPE (decl)), |
1971 | valid_only); | |
1972 | instantiate_decl (DECL_INCOMING_RTL (decl), | |
1973 | int_size_in_bytes (TREE_TYPE (decl)), valid_only); | |
6f086dfc RS |
1974 | } |
1975 | ||
1976 | /* Now process all variables defined in the function or its subblocks. */ | |
1977 | instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only); | |
1978 | ||
a82ad570 | 1979 | if (DECL_INLINE (fndecl)) |
6f086dfc RS |
1980 | { |
1981 | /* Save all rtl allocated for this function by raising the | |
1982 | high-water mark on the maybepermanent_obstack. */ | |
1983 | preserve_data (); | |
1984 | /* All further rtl allocation is now done in the current_obstack. */ | |
1985 | rtl_in_current_obstack (); | |
1986 | } | |
1987 | } | |
1988 | ||
1989 | /* Subroutine of instantiate_decls: Process all decls in the given | |
1990 | BLOCK node and all its subblocks. */ | |
1991 | ||
1992 | static void | |
1993 | instantiate_decls_1 (let, valid_only) | |
1994 | tree let; | |
1995 | int valid_only; | |
1996 | { | |
1997 | tree t; | |
1998 | ||
1999 | for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t)) | |
5a73491b RK |
2000 | instantiate_decl (DECL_RTL (t), int_size_in_bytes (TREE_TYPE (t)), |
2001 | valid_only); | |
6f086dfc RS |
2002 | |
2003 | /* Process all subblocks. */ | |
2004 | for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t)) | |
2005 | instantiate_decls_1 (t, valid_only); | |
2006 | } | |
5a73491b RK |
2007 | |
2008 | /* Subroutine of the preceeding procedures: Given RTL representing a | |
2009 | decl and the size of the object, do any instantiation required. | |
2010 | ||
2011 | If VALID_ONLY is non-zero, it means that the RTL should only be | |
2012 | changed if the new address is valid. */ | |
2013 | ||
2014 | static void | |
2015 | instantiate_decl (x, size, valid_only) | |
2016 | rtx x; | |
2017 | int size; | |
2018 | int valid_only; | |
2019 | { | |
2020 | enum machine_mode mode; | |
2021 | rtx addr; | |
2022 | ||
2023 | /* If this is not a MEM, no need to do anything. Similarly if the | |
2024 | address is a constant or a register that is not a virtual register. */ | |
2025 | ||
2026 | if (x == 0 || GET_CODE (x) != MEM) | |
2027 | return; | |
2028 | ||
2029 | addr = XEXP (x, 0); | |
2030 | if (CONSTANT_P (addr) | |
2031 | || (GET_CODE (addr) == REG | |
2032 | && (REGNO (addr) < FIRST_VIRTUAL_REGISTER | |
2033 | || REGNO (addr) > LAST_VIRTUAL_REGISTER))) | |
2034 | return; | |
2035 | ||
2036 | /* If we should only do this if the address is valid, copy the address. | |
2037 | We need to do this so we can undo any changes that might make the | |
2038 | address invalid. This copy is unfortunate, but probably can't be | |
2039 | avoided. */ | |
2040 | ||
2041 | if (valid_only) | |
2042 | addr = copy_rtx (addr); | |
2043 | ||
2044 | instantiate_virtual_regs_1 (&addr, NULL_RTX, 0); | |
2045 | ||
2046 | if (! valid_only) | |
2047 | return; | |
2048 | ||
2049 | /* Now verify that the resulting address is valid for every integer or | |
2050 | floating-point mode up to and including SIZE bytes long. We do this | |
2051 | since the object might be accessed in any mode and frame addresses | |
2052 | are shared. */ | |
2053 | ||
2054 | for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); | |
2055 | mode != VOIDmode && GET_MODE_SIZE (mode) <= size; | |
2056 | mode = GET_MODE_WIDER_MODE (mode)) | |
2057 | if (! memory_address_p (mode, addr)) | |
2058 | return; | |
2059 | ||
2060 | for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); | |
2061 | mode != VOIDmode && GET_MODE_SIZE (mode) <= size; | |
2062 | mode = GET_MODE_WIDER_MODE (mode)) | |
2063 | if (! memory_address_p (mode, addr)) | |
2064 | return; | |
2065 | ||
2066 | /* Otherwise, put back the address, now that we have updated it and we | |
2067 | know it is valid. */ | |
2068 | ||
2069 | XEXP (x, 0) = addr; | |
2070 | } | |
6f086dfc RS |
2071 | \f |
2072 | /* Given a pointer to a piece of rtx and an optional pointer to the | |
2073 | containing object, instantiate any virtual registers present in it. | |
2074 | ||
2075 | If EXTRA_INSNS, we always do the replacement and generate | |
2076 | any extra insns before OBJECT. If it zero, we do nothing if replacement | |
2077 | is not valid. | |
2078 | ||
2079 | Return 1 if we either had nothing to do or if we were able to do the | |
2080 | needed replacement. Return 0 otherwise; we only return zero if | |
2081 | EXTRA_INSNS is zero. | |
2082 | ||
2083 | We first try some simple transformations to avoid the creation of extra | |
2084 | pseudos. */ | |
2085 | ||
2086 | static int | |
2087 | instantiate_virtual_regs_1 (loc, object, extra_insns) | |
2088 | rtx *loc; | |
2089 | rtx object; | |
2090 | int extra_insns; | |
2091 | { | |
2092 | rtx x; | |
2093 | RTX_CODE code; | |
2094 | rtx new = 0; | |
2095 | int offset; | |
2096 | rtx temp; | |
2097 | rtx seq; | |
2098 | int i, j; | |
2099 | char *fmt; | |
2100 | ||
2101 | /* Re-start here to avoid recursion in common cases. */ | |
2102 | restart: | |
2103 | ||
2104 | x = *loc; | |
2105 | if (x == 0) | |
2106 | return 1; | |
2107 | ||
2108 | code = GET_CODE (x); | |
2109 | ||
2110 | /* Check for some special cases. */ | |
2111 | switch (code) | |
2112 | { | |
2113 | case CONST_INT: | |
2114 | case CONST_DOUBLE: | |
2115 | case CONST: | |
2116 | case SYMBOL_REF: | |
2117 | case CODE_LABEL: | |
2118 | case PC: | |
2119 | case CC0: | |
2120 | case ASM_INPUT: | |
2121 | case ADDR_VEC: | |
2122 | case ADDR_DIFF_VEC: | |
2123 | case RETURN: | |
2124 | return 1; | |
2125 | ||
2126 | case SET: | |
2127 | /* We are allowed to set the virtual registers. This means that | |
2128 | that the actual register should receive the source minus the | |
2129 | appropriate offset. This is used, for example, in the handling | |
2130 | of non-local gotos. */ | |
2131 | if (SET_DEST (x) == virtual_incoming_args_rtx) | |
2132 | new = arg_pointer_rtx, offset = - in_arg_offset; | |
2133 | else if (SET_DEST (x) == virtual_stack_vars_rtx) | |
2134 | new = frame_pointer_rtx, offset = - var_offset; | |
2135 | else if (SET_DEST (x) == virtual_stack_dynamic_rtx) | |
2136 | new = stack_pointer_rtx, offset = - dynamic_offset; | |
2137 | else if (SET_DEST (x) == virtual_outgoing_args_rtx) | |
2138 | new = stack_pointer_rtx, offset = - out_arg_offset; | |
2139 | ||
2140 | if (new) | |
2141 | { | |
2142 | /* The only valid sources here are PLUS or REG. Just do | |
2143 | the simplest possible thing to handle them. */ | |
2144 | if (GET_CODE (SET_SRC (x)) != REG | |
2145 | && GET_CODE (SET_SRC (x)) != PLUS) | |
2146 | abort (); | |
2147 | ||
2148 | start_sequence (); | |
2149 | if (GET_CODE (SET_SRC (x)) != REG) | |
5f4f0e22 | 2150 | temp = force_operand (SET_SRC (x), NULL_RTX); |
6f086dfc RS |
2151 | else |
2152 | temp = SET_SRC (x); | |
5f4f0e22 | 2153 | temp = force_operand (plus_constant (temp, offset), NULL_RTX); |
6f086dfc RS |
2154 | seq = get_insns (); |
2155 | end_sequence (); | |
2156 | ||
2157 | emit_insns_before (seq, object); | |
2158 | SET_DEST (x) = new; | |
2159 | ||
2160 | if (!validate_change (object, &SET_SRC (x), temp, 0) | |
2161 | || ! extra_insns) | |
2162 | abort (); | |
2163 | ||
2164 | return 1; | |
2165 | } | |
2166 | ||
2167 | instantiate_virtual_regs_1 (&SET_DEST (x), object, extra_insns); | |
2168 | loc = &SET_SRC (x); | |
2169 | goto restart; | |
2170 | ||
2171 | case PLUS: | |
2172 | /* Handle special case of virtual register plus constant. */ | |
2173 | if (CONSTANT_P (XEXP (x, 1))) | |
2174 | { | |
2175 | rtx old; | |
2176 | ||
2177 | /* Check for (plus (plus VIRT foo) (const_int)) first. */ | |
2178 | if (GET_CODE (XEXP (x, 0)) == PLUS) | |
2179 | { | |
2180 | rtx inner = XEXP (XEXP (x, 0), 0); | |
2181 | ||
2182 | if (inner == virtual_incoming_args_rtx) | |
2183 | new = arg_pointer_rtx, offset = in_arg_offset; | |
2184 | else if (inner == virtual_stack_vars_rtx) | |
2185 | new = frame_pointer_rtx, offset = var_offset; | |
2186 | else if (inner == virtual_stack_dynamic_rtx) | |
2187 | new = stack_pointer_rtx, offset = dynamic_offset; | |
2188 | else if (inner == virtual_outgoing_args_rtx) | |
2189 | new = stack_pointer_rtx, offset = out_arg_offset; | |
2190 | else | |
2191 | { | |
2192 | loc = &XEXP (x, 0); | |
2193 | goto restart; | |
2194 | } | |
2195 | ||
2196 | instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object, | |
2197 | extra_insns); | |
2198 | new = gen_rtx (PLUS, Pmode, new, XEXP (XEXP (x, 0), 1)); | |
2199 | } | |
2200 | ||
2201 | else if (XEXP (x, 0) == virtual_incoming_args_rtx) | |
2202 | new = arg_pointer_rtx, offset = in_arg_offset; | |
2203 | else if (XEXP (x, 0) == virtual_stack_vars_rtx) | |
2204 | new = frame_pointer_rtx, offset = var_offset; | |
2205 | else if (XEXP (x, 0) == virtual_stack_dynamic_rtx) | |
2206 | new = stack_pointer_rtx, offset = dynamic_offset; | |
2207 | else if (XEXP (x, 0) == virtual_outgoing_args_rtx) | |
2208 | new = stack_pointer_rtx, offset = out_arg_offset; | |
2209 | else | |
2210 | { | |
2211 | /* We know the second operand is a constant. Unless the | |
2212 | first operand is a REG (which has been already checked), | |
2213 | it needs to be checked. */ | |
2214 | if (GET_CODE (XEXP (x, 0)) != REG) | |
2215 | { | |
2216 | loc = &XEXP (x, 0); | |
2217 | goto restart; | |
2218 | } | |
2219 | return 1; | |
2220 | } | |
2221 | ||
2222 | old = XEXP (x, 0); | |
2223 | XEXP (x, 0) = new; | |
2224 | new = plus_constant (XEXP (x, 1), offset); | |
2225 | ||
2226 | /* If the new constant is zero, try to replace the sum with its | |
2227 | first operand. */ | |
2228 | if (new == const0_rtx | |
2229 | && validate_change (object, loc, XEXP (x, 0), 0)) | |
2230 | return 1; | |
2231 | ||
2232 | /* Next try to replace constant with new one. */ | |
2233 | if (!validate_change (object, &XEXP (x, 1), new, 0)) | |
2234 | { | |
2235 | if (! extra_insns) | |
2236 | { | |
2237 | XEXP (x, 0) = old; | |
2238 | return 0; | |
2239 | } | |
2240 | ||
2241 | /* Otherwise copy the new constant into a register and replace | |
2242 | constant with that register. */ | |
2243 | temp = gen_reg_rtx (Pmode); | |
2244 | if (validate_change (object, &XEXP (x, 1), temp, 0)) | |
2245 | emit_insn_before (gen_move_insn (temp, new), object); | |
2246 | else | |
2247 | { | |
2248 | /* If that didn't work, replace this expression with a | |
2249 | register containing the sum. */ | |
2250 | ||
2251 | new = gen_rtx (PLUS, Pmode, XEXP (x, 0), new); | |
2252 | XEXP (x, 0) = old; | |
2253 | ||
2254 | start_sequence (); | |
5f4f0e22 | 2255 | temp = force_operand (new, NULL_RTX); |
6f086dfc RS |
2256 | seq = get_insns (); |
2257 | end_sequence (); | |
2258 | ||
2259 | emit_insns_before (seq, object); | |
2260 | if (! validate_change (object, loc, temp, 0) | |
2261 | && ! validate_replace_rtx (x, temp, object)) | |
2262 | abort (); | |
2263 | } | |
2264 | } | |
2265 | ||
2266 | return 1; | |
2267 | } | |
2268 | ||
2269 | /* Fall through to generic two-operand expression case. */ | |
2270 | case EXPR_LIST: | |
2271 | case CALL: | |
2272 | case COMPARE: | |
2273 | case MINUS: | |
2274 | case MULT: | |
2275 | case DIV: case UDIV: | |
2276 | case MOD: case UMOD: | |
2277 | case AND: case IOR: case XOR: | |
2278 | case LSHIFT: case ASHIFT: case ROTATE: | |
2279 | case ASHIFTRT: case LSHIFTRT: case ROTATERT: | |
2280 | case NE: case EQ: | |
2281 | case GE: case GT: case GEU: case GTU: | |
2282 | case LE: case LT: case LEU: case LTU: | |
2283 | if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1))) | |
2284 | instantiate_virtual_regs_1 (&XEXP (x, 1), object, extra_insns); | |
2285 | loc = &XEXP (x, 0); | |
2286 | goto restart; | |
2287 | ||
2288 | case MEM: | |
2289 | /* Most cases of MEM that convert to valid addresses have already been | |
2290 | handled by our scan of regno_reg_rtx. The only special handling we | |
2291 | need here is to make a copy of the rtx to ensure it isn't being | |
b335c2cc | 2292 | shared if we have to change it to a pseudo. |
6f086dfc RS |
2293 | |
2294 | If the rtx is a simple reference to an address via a virtual register, | |
2295 | it can potentially be shared. In such cases, first try to make it | |
2296 | a valid address, which can also be shared. Otherwise, copy it and | |
2297 | proceed normally. | |
2298 | ||
2299 | First check for common cases that need no processing. These are | |
2300 | usually due to instantiation already being done on a previous instance | |
2301 | of a shared rtx. */ | |
2302 | ||
2303 | temp = XEXP (x, 0); | |
2304 | if (CONSTANT_ADDRESS_P (temp) | |
2305 | #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM | |
2306 | || temp == arg_pointer_rtx | |
2307 | #endif | |
2308 | || temp == frame_pointer_rtx) | |
2309 | return 1; | |
2310 | ||
2311 | if (GET_CODE (temp) == PLUS | |
2312 | && CONSTANT_ADDRESS_P (XEXP (temp, 1)) | |
2313 | && (XEXP (temp, 0) == frame_pointer_rtx | |
2314 | #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM | |
2315 | || XEXP (temp, 0) == arg_pointer_rtx | |
2316 | #endif | |
2317 | )) | |
2318 | return 1; | |
2319 | ||
2320 | if (temp == virtual_stack_vars_rtx | |
2321 | || temp == virtual_incoming_args_rtx | |
2322 | || (GET_CODE (temp) == PLUS | |
2323 | && CONSTANT_ADDRESS_P (XEXP (temp, 1)) | |
2324 | && (XEXP (temp, 0) == virtual_stack_vars_rtx | |
2325 | || XEXP (temp, 0) == virtual_incoming_args_rtx))) | |
2326 | { | |
2327 | /* This MEM may be shared. If the substitution can be done without | |
2328 | the need to generate new pseudos, we want to do it in place | |
2329 | so all copies of the shared rtx benefit. The call below will | |
2330 | only make substitutions if the resulting address is still | |
2331 | valid. | |
2332 | ||
2333 | Note that we cannot pass X as the object in the recursive call | |
2334 | since the insn being processed may not allow all valid | |
6461be14 RS |
2335 | addresses. However, if we were not passed on object, we can |
2336 | only modify X without copying it if X will have a valid | |
2337 | address. | |
6f086dfc | 2338 | |
6461be14 RS |
2339 | ??? Also note that this can still lose if OBJECT is an insn that |
2340 | has less restrictions on an address that some other insn. | |
2341 | In that case, we will modify the shared address. This case | |
2342 | doesn't seem very likely, though. */ | |
2343 | ||
2344 | if (instantiate_virtual_regs_1 (&XEXP (x, 0), | |
2345 | object ? object : x, 0)) | |
6f086dfc RS |
2346 | return 1; |
2347 | ||
2348 | /* Otherwise make a copy and process that copy. We copy the entire | |
2349 | RTL expression since it might be a PLUS which could also be | |
2350 | shared. */ | |
2351 | *loc = x = copy_rtx (x); | |
2352 | } | |
2353 | ||
2354 | /* Fall through to generic unary operation case. */ | |
2355 | case USE: | |
2356 | case CLOBBER: | |
2357 | case SUBREG: | |
2358 | case STRICT_LOW_PART: | |
2359 | case NEG: case NOT: | |
2360 | case PRE_DEC: case PRE_INC: case POST_DEC: case POST_INC: | |
2361 | case SIGN_EXTEND: case ZERO_EXTEND: | |
2362 | case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE: | |
2363 | case FLOAT: case FIX: | |
2364 | case UNSIGNED_FIX: case UNSIGNED_FLOAT: | |
2365 | case ABS: | |
2366 | case SQRT: | |
2367 | case FFS: | |
2368 | /* These case either have just one operand or we know that we need not | |
2369 | check the rest of the operands. */ | |
2370 | loc = &XEXP (x, 0); | |
2371 | goto restart; | |
2372 | ||
2373 | case REG: | |
2374 | /* Try to replace with a PLUS. If that doesn't work, compute the sum | |
2375 | in front of this insn and substitute the temporary. */ | |
2376 | if (x == virtual_incoming_args_rtx) | |
2377 | new = arg_pointer_rtx, offset = in_arg_offset; | |
2378 | else if (x == virtual_stack_vars_rtx) | |
2379 | new = frame_pointer_rtx, offset = var_offset; | |
2380 | else if (x == virtual_stack_dynamic_rtx) | |
2381 | new = stack_pointer_rtx, offset = dynamic_offset; | |
2382 | else if (x == virtual_outgoing_args_rtx) | |
2383 | new = stack_pointer_rtx, offset = out_arg_offset; | |
2384 | ||
2385 | if (new) | |
2386 | { | |
2387 | temp = plus_constant (new, offset); | |
2388 | if (!validate_change (object, loc, temp, 0)) | |
2389 | { | |
2390 | if (! extra_insns) | |
2391 | return 0; | |
2392 | ||
2393 | start_sequence (); | |
5f4f0e22 | 2394 | temp = force_operand (temp, NULL_RTX); |
6f086dfc RS |
2395 | seq = get_insns (); |
2396 | end_sequence (); | |
2397 | ||
2398 | emit_insns_before (seq, object); | |
2399 | if (! validate_change (object, loc, temp, 0) | |
2400 | && ! validate_replace_rtx (x, temp, object)) | |
2401 | abort (); | |
2402 | } | |
2403 | } | |
2404 | ||
2405 | return 1; | |
2406 | } | |
2407 | ||
2408 | /* Scan all subexpressions. */ | |
2409 | fmt = GET_RTX_FORMAT (code); | |
2410 | for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++) | |
2411 | if (*fmt == 'e') | |
2412 | { | |
2413 | if (!instantiate_virtual_regs_1 (&XEXP (x, i), object, extra_insns)) | |
2414 | return 0; | |
2415 | } | |
2416 | else if (*fmt == 'E') | |
2417 | for (j = 0; j < XVECLEN (x, i); j++) | |
2418 | if (! instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object, | |
2419 | extra_insns)) | |
2420 | return 0; | |
2421 | ||
2422 | return 1; | |
2423 | } | |
2424 | \f | |
2425 | /* Optimization: assuming this function does not receive nonlocal gotos, | |
2426 | delete the handlers for such, as well as the insns to establish | |
2427 | and disestablish them. */ | |
2428 | ||
2429 | static void | |
2430 | delete_handlers () | |
2431 | { | |
2432 | rtx insn; | |
2433 | for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) | |
2434 | { | |
2435 | /* Delete the handler by turning off the flag that would | |
2436 | prevent jump_optimize from deleting it. | |
2437 | Also permit deletion of the nonlocal labels themselves | |
2438 | if nothing local refers to them. */ | |
2439 | if (GET_CODE (insn) == CODE_LABEL) | |
2440 | LABEL_PRESERVE_P (insn) = 0; | |
2441 | if (GET_CODE (insn) == INSN | |
59257ff7 RK |
2442 | && ((nonlocal_goto_handler_slot != 0 |
2443 | && reg_mentioned_p (nonlocal_goto_handler_slot, PATTERN (insn))) | |
2444 | || (nonlocal_goto_stack_level != 0 | |
2445 | && reg_mentioned_p (nonlocal_goto_stack_level, | |
2446 | PATTERN (insn))))) | |
6f086dfc RS |
2447 | delete_insn (insn); |
2448 | } | |
2449 | } | |
2450 | ||
2451 | /* Return a list (chain of EXPR_LIST nodes) for the nonlocal labels | |
2452 | of the current function. */ | |
2453 | ||
2454 | rtx | |
2455 | nonlocal_label_rtx_list () | |
2456 | { | |
2457 | tree t; | |
2458 | rtx x = 0; | |
2459 | ||
2460 | for (t = nonlocal_labels; t; t = TREE_CHAIN (t)) | |
2461 | x = gen_rtx (EXPR_LIST, VOIDmode, label_rtx (TREE_VALUE (t)), x); | |
2462 | ||
2463 | return x; | |
2464 | } | |
2465 | \f | |
2466 | /* Output a USE for any register use in RTL. | |
2467 | This is used with -noreg to mark the extent of lifespan | |
2468 | of any registers used in a user-visible variable's DECL_RTL. */ | |
2469 | ||
2470 | void | |
2471 | use_variable (rtl) | |
2472 | rtx rtl; | |
2473 | { | |
2474 | if (GET_CODE (rtl) == REG) | |
2475 | /* This is a register variable. */ | |
2476 | emit_insn (gen_rtx (USE, VOIDmode, rtl)); | |
2477 | else if (GET_CODE (rtl) == MEM | |
2478 | && GET_CODE (XEXP (rtl, 0)) == REG | |
2479 | && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER | |
2480 | || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER) | |
2481 | && XEXP (rtl, 0) != current_function_internal_arg_pointer) | |
2482 | /* This is a variable-sized structure. */ | |
2483 | emit_insn (gen_rtx (USE, VOIDmode, XEXP (rtl, 0))); | |
2484 | } | |
2485 | ||
2486 | /* Like use_variable except that it outputs the USEs after INSN | |
2487 | instead of at the end of the insn-chain. */ | |
2488 | ||
2489 | void | |
2490 | use_variable_after (rtl, insn) | |
2491 | rtx rtl, insn; | |
2492 | { | |
2493 | if (GET_CODE (rtl) == REG) | |
2494 | /* This is a register variable. */ | |
2495 | emit_insn_after (gen_rtx (USE, VOIDmode, rtl), insn); | |
2496 | else if (GET_CODE (rtl) == MEM | |
2497 | && GET_CODE (XEXP (rtl, 0)) == REG | |
2498 | && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER | |
2499 | || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER) | |
2500 | && XEXP (rtl, 0) != current_function_internal_arg_pointer) | |
2501 | /* This is a variable-sized structure. */ | |
2502 | emit_insn_after (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)), insn); | |
2503 | } | |
2504 | \f | |
2505 | int | |
2506 | max_parm_reg_num () | |
2507 | { | |
2508 | return max_parm_reg; | |
2509 | } | |
2510 | ||
2511 | /* Return the first insn following those generated by `assign_parms'. */ | |
2512 | ||
2513 | rtx | |
2514 | get_first_nonparm_insn () | |
2515 | { | |
2516 | if (last_parm_insn) | |
2517 | return NEXT_INSN (last_parm_insn); | |
2518 | return get_insns (); | |
2519 | } | |
2520 | ||
5378192b RS |
2521 | /* Return the first NOTE_INSN_BLOCK_BEG note in the function. |
2522 | Crash if there is none. */ | |
2523 | ||
2524 | rtx | |
2525 | get_first_block_beg () | |
2526 | { | |
2527 | register rtx searcher; | |
2528 | register rtx insn = get_first_nonparm_insn (); | |
2529 | ||
2530 | for (searcher = insn; searcher; searcher = NEXT_INSN (searcher)) | |
2531 | if (GET_CODE (searcher) == NOTE | |
2532 | && NOTE_LINE_NUMBER (searcher) == NOTE_INSN_BLOCK_BEG) | |
2533 | return searcher; | |
2534 | ||
2535 | abort (); /* Invalid call to this function. (See comments above.) */ | |
2536 | return NULL_RTX; | |
2537 | } | |
2538 | ||
6f086dfc RS |
2539 | /* Return 1 if EXP returns an aggregate value, for which an address |
2540 | must be passed to the function or returned by the function. */ | |
2541 | ||
2542 | int | |
2543 | aggregate_value_p (exp) | |
2544 | tree exp; | |
2545 | { | |
2546 | if (TYPE_MODE (TREE_TYPE (exp)) == BLKmode) | |
2547 | return 1; | |
2548 | if (RETURN_IN_MEMORY (TREE_TYPE (exp))) | |
2549 | return 1; | |
2550 | if (flag_pcc_struct_return | |
2551 | && (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE | |
2552 | || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)) | |
2553 | return 1; | |
2554 | return 0; | |
2555 | } | |
2556 | \f | |
2557 | /* Assign RTL expressions to the function's parameters. | |
2558 | This may involve copying them into registers and using | |
2559 | those registers as the RTL for them. | |
2560 | ||
2561 | If SECOND_TIME is non-zero it means that this function is being | |
2562 | called a second time. This is done by integrate.c when a function's | |
2563 | compilation is deferred. We need to come back here in case the | |
2564 | FUNCTION_ARG macro computes items needed for the rest of the compilation | |
2565 | (such as changing which registers are fixed or caller-saved). But suppress | |
2566 | writing any insns or setting DECL_RTL of anything in this case. */ | |
2567 | ||
2568 | void | |
2569 | assign_parms (fndecl, second_time) | |
2570 | tree fndecl; | |
2571 | int second_time; | |
2572 | { | |
2573 | register tree parm; | |
2574 | register rtx entry_parm = 0; | |
2575 | register rtx stack_parm = 0; | |
2576 | CUMULATIVE_ARGS args_so_far; | |
a53e14c0 | 2577 | enum machine_mode promoted_mode, passed_mode, nominal_mode; |
00d8a4c1 | 2578 | int unsignedp; |
6f086dfc RS |
2579 | /* Total space needed so far for args on the stack, |
2580 | given as a constant and a tree-expression. */ | |
2581 | struct args_size stack_args_size; | |
2582 | tree fntype = TREE_TYPE (fndecl); | |
2583 | tree fnargs = DECL_ARGUMENTS (fndecl); | |
2584 | /* This is used for the arg pointer when referring to stack args. */ | |
2585 | rtx internal_arg_pointer; | |
2586 | /* This is a dummy PARM_DECL that we used for the function result if | |
2587 | the function returns a structure. */ | |
2588 | tree function_result_decl = 0; | |
2589 | int nparmregs = list_length (fnargs) + LAST_VIRTUAL_REGISTER + 1; | |
2590 | int varargs_setup = 0; | |
2591 | ||
2592 | /* Nonzero if the last arg is named `__builtin_va_alist', | |
2593 | which is used on some machines for old-fashioned non-ANSI varargs.h; | |
2594 | this should be stuck onto the stack as if it had arrived there. */ | |
2595 | int vararg | |
2596 | = (fnargs | |
2597 | && (parm = tree_last (fnargs)) != 0 | |
2598 | && DECL_NAME (parm) | |
2599 | && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)), | |
2600 | "__builtin_va_alist"))); | |
2601 | ||
2602 | /* Nonzero if function takes extra anonymous args. | |
2603 | This means the last named arg must be on the stack | |
2604 | right before the anonymous ones. */ | |
2605 | int stdarg | |
2606 | = (TYPE_ARG_TYPES (fntype) != 0 | |
2607 | && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype))) | |
2608 | != void_type_node)); | |
2609 | ||
2610 | /* If the reg that the virtual arg pointer will be translated into is | |
2611 | not a fixed reg or is the stack pointer, make a copy of the virtual | |
2612 | arg pointer, and address parms via the copy. The frame pointer is | |
2613 | considered fixed even though it is not marked as such. | |
2614 | ||
2615 | The second time through, simply use ap to avoid generating rtx. */ | |
2616 | ||
2617 | if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM | |
2618 | || ! (fixed_regs[ARG_POINTER_REGNUM] | |
2619 | || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM)) | |
2620 | && ! second_time) | |
2621 | internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx); | |
2622 | else | |
2623 | internal_arg_pointer = virtual_incoming_args_rtx; | |
2624 | current_function_internal_arg_pointer = internal_arg_pointer; | |
2625 | ||
2626 | stack_args_size.constant = 0; | |
2627 | stack_args_size.var = 0; | |
2628 | ||
2629 | /* If struct value address is treated as the first argument, make it so. */ | |
2630 | if (aggregate_value_p (DECL_RESULT (fndecl)) | |
2631 | && ! current_function_returns_pcc_struct | |
2632 | && struct_value_incoming_rtx == 0) | |
2633 | { | |
2634 | tree type = build_pointer_type (fntype); | |
2635 | ||
5f4f0e22 | 2636 | function_result_decl = build_decl (PARM_DECL, NULL_TREE, type); |
6f086dfc RS |
2637 | |
2638 | DECL_ARG_TYPE (function_result_decl) = type; | |
2639 | TREE_CHAIN (function_result_decl) = fnargs; | |
2640 | fnargs = function_result_decl; | |
2641 | } | |
2642 | ||
2643 | parm_reg_stack_loc = (rtx *) oballoc (nparmregs * sizeof (rtx)); | |
2644 | bzero (parm_reg_stack_loc, nparmregs * sizeof (rtx)); | |
2645 | ||
2646 | #ifdef INIT_CUMULATIVE_INCOMING_ARGS | |
5f4f0e22 | 2647 | INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, NULL_PTR); |
6f086dfc | 2648 | #else |
5f4f0e22 | 2649 | INIT_CUMULATIVE_ARGS (args_so_far, fntype, NULL_PTR); |
6f086dfc RS |
2650 | #endif |
2651 | ||
2652 | /* We haven't yet found an argument that we must push and pretend the | |
2653 | caller did. */ | |
2654 | current_function_pretend_args_size = 0; | |
2655 | ||
2656 | for (parm = fnargs; parm; parm = TREE_CHAIN (parm)) | |
2657 | { | |
2658 | int aggregate | |
2659 | = (TREE_CODE (TREE_TYPE (parm)) == ARRAY_TYPE | |
2660 | || TREE_CODE (TREE_TYPE (parm)) == RECORD_TYPE | |
2661 | || TREE_CODE (TREE_TYPE (parm)) == UNION_TYPE); | |
2662 | struct args_size stack_offset; | |
2663 | struct args_size arg_size; | |
2664 | int passed_pointer = 0; | |
2665 | tree passed_type = DECL_ARG_TYPE (parm); | |
2666 | ||
2667 | /* Set LAST_NAMED if this is last named arg before some | |
2668 | anonymous args. We treat it as if it were anonymous too. */ | |
2669 | int last_named = ((TREE_CHAIN (parm) == 0 | |
2670 | || DECL_NAME (TREE_CHAIN (parm)) == 0) | |
2671 | && (vararg || stdarg)); | |
2672 | ||
2673 | if (TREE_TYPE (parm) == error_mark_node | |
2674 | /* This can happen after weird syntax errors | |
2675 | or if an enum type is defined among the parms. */ | |
2676 | || TREE_CODE (parm) != PARM_DECL | |
2677 | || passed_type == NULL) | |
2678 | { | |
2679 | DECL_RTL (parm) = gen_rtx (MEM, BLKmode, const0_rtx); | |
2680 | TREE_USED (parm) = 1; | |
2681 | continue; | |
2682 | } | |
2683 | ||
2684 | /* For varargs.h function, save info about regs and stack space | |
2685 | used by the individual args, not including the va_alist arg. */ | |
2686 | if (vararg && last_named) | |
2687 | current_function_args_info = args_so_far; | |
2688 | ||
2689 | /* Find mode of arg as it is passed, and mode of arg | |
2690 | as it should be during execution of this function. */ | |
2691 | passed_mode = TYPE_MODE (passed_type); | |
2692 | nominal_mode = TYPE_MODE (TREE_TYPE (parm)); | |
2693 | ||
16bae307 RS |
2694 | /* If the parm's mode is VOID, its value doesn't matter, |
2695 | and avoid the usual things like emit_move_insn that could crash. */ | |
2696 | if (nominal_mode == VOIDmode) | |
2697 | { | |
2698 | DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = const0_rtx; | |
2699 | continue; | |
2700 | } | |
2701 | ||
6f086dfc RS |
2702 | #ifdef FUNCTION_ARG_PASS_BY_REFERENCE |
2703 | /* See if this arg was passed by invisible reference. */ | |
2704 | if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode, | |
2705 | passed_type, ! last_named)) | |
2706 | { | |
2707 | passed_type = build_pointer_type (passed_type); | |
2708 | passed_pointer = 1; | |
2709 | passed_mode = nominal_mode = Pmode; | |
2710 | } | |
2711 | #endif | |
2712 | ||
a53e14c0 RK |
2713 | promoted_mode = passed_mode; |
2714 | ||
2715 | #ifdef PROMOTE_FUNCTION_ARGS | |
2716 | /* Compute the mode in which the arg is actually extended to. */ | |
2717 | if (TREE_CODE (passed_type) == INTEGER_TYPE | |
2718 | || TREE_CODE (passed_type) == ENUMERAL_TYPE | |
2719 | || TREE_CODE (passed_type) == BOOLEAN_TYPE | |
2720 | || TREE_CODE (passed_type) == CHAR_TYPE | |
2721 | || TREE_CODE (passed_type) == REAL_TYPE | |
2722 | || TREE_CODE (passed_type) == POINTER_TYPE | |
2723 | || TREE_CODE (passed_type) == OFFSET_TYPE) | |
2724 | { | |
2725 | unsignedp = TREE_UNSIGNED (passed_type); | |
2726 | PROMOTE_MODE (promoted_mode, unsignedp, passed_type); | |
2727 | } | |
2728 | #endif | |
2729 | ||
6f086dfc RS |
2730 | /* Let machine desc say which reg (if any) the parm arrives in. |
2731 | 0 means it arrives on the stack. */ | |
2732 | #ifdef FUNCTION_INCOMING_ARG | |
a53e14c0 | 2733 | entry_parm = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode, |
6f086dfc RS |
2734 | passed_type, ! last_named); |
2735 | #else | |
a53e14c0 | 2736 | entry_parm = FUNCTION_ARG (args_so_far, promoted_mode, |
6f086dfc RS |
2737 | passed_type, ! last_named); |
2738 | #endif | |
2739 | ||
a53e14c0 RK |
2740 | if (entry_parm) |
2741 | passed_mode = promoted_mode; | |
2742 | ||
6f086dfc RS |
2743 | #ifdef SETUP_INCOMING_VARARGS |
2744 | /* If this is the last named parameter, do any required setup for | |
2745 | varargs or stdargs. We need to know about the case of this being an | |
2746 | addressable type, in which case we skip the registers it | |
2747 | would have arrived in. | |
2748 | ||
2749 | For stdargs, LAST_NAMED will be set for two parameters, the one that | |
2750 | is actually the last named, and the dummy parameter. We only | |
2751 | want to do this action once. | |
2752 | ||
2753 | Also, indicate when RTL generation is to be suppressed. */ | |
2754 | if (last_named && !varargs_setup) | |
2755 | { | |
2756 | SETUP_INCOMING_VARARGS (args_so_far, passed_mode, passed_type, | |
2757 | current_function_pretend_args_size, | |
2758 | second_time); | |
2759 | varargs_setup = 1; | |
2760 | } | |
2761 | #endif | |
2762 | ||
2763 | /* Determine parm's home in the stack, | |
2764 | in case it arrives in the stack or we should pretend it did. | |
2765 | ||
2766 | Compute the stack position and rtx where the argument arrives | |
2767 | and its size. | |
2768 | ||
2769 | There is one complexity here: If this was a parameter that would | |
2770 | have been passed in registers, but wasn't only because it is | |
2771 | __builtin_va_alist, we want locate_and_pad_parm to treat it as if | |
2772 | it came in a register so that REG_PARM_STACK_SPACE isn't skipped. | |
2773 | In this case, we call FUNCTION_ARG with NAMED set to 1 instead of | |
2774 | 0 as it was the previous time. */ | |
2775 | ||
2776 | locate_and_pad_parm (passed_mode, passed_type, | |
2777 | #ifdef STACK_PARMS_IN_REG_PARM_AREA | |
2778 | 1, | |
2779 | #else | |
2780 | #ifdef FUNCTION_INCOMING_ARG | |
2781 | FUNCTION_INCOMING_ARG (args_so_far, passed_mode, | |
2782 | passed_type, | |
2783 | (! last_named | |
2784 | || varargs_setup)) != 0, | |
2785 | #else | |
2786 | FUNCTION_ARG (args_so_far, passed_mode, | |
2787 | passed_type, | |
2788 | ! last_named || varargs_setup) != 0, | |
2789 | #endif | |
2790 | #endif | |
2791 | fndecl, &stack_args_size, &stack_offset, &arg_size); | |
2792 | ||
2793 | if (! second_time) | |
2794 | { | |
2795 | rtx offset_rtx = ARGS_SIZE_RTX (stack_offset); | |
2796 | ||
2797 | if (offset_rtx == const0_rtx) | |
2798 | stack_parm = gen_rtx (MEM, passed_mode, internal_arg_pointer); | |
2799 | else | |
2800 | stack_parm = gen_rtx (MEM, passed_mode, | |
2801 | gen_rtx (PLUS, Pmode, | |
2802 | internal_arg_pointer, offset_rtx)); | |
2803 | ||
2804 | /* If this is a memory ref that contains aggregate components, | |
2805 | mark it as such for cse and loop optimize. */ | |
2806 | MEM_IN_STRUCT_P (stack_parm) = aggregate; | |
2807 | } | |
2808 | ||
2809 | /* If this parameter was passed both in registers and in the stack, | |
2810 | use the copy on the stack. */ | |
2811 | if (MUST_PASS_IN_STACK (passed_mode, passed_type)) | |
2812 | entry_parm = 0; | |
2813 | ||
2814 | /* If this parm was passed part in regs and part in memory, | |
2815 | pretend it arrived entirely in memory | |
2816 | by pushing the register-part onto the stack. | |
2817 | ||
2818 | In the special case of a DImode or DFmode that is split, | |
2819 | we could put it together in a pseudoreg directly, | |
2820 | but for now that's not worth bothering with. */ | |
2821 | ||
2822 | if (entry_parm) | |
2823 | { | |
2824 | int nregs = 0; | |
2825 | #ifdef FUNCTION_ARG_PARTIAL_NREGS | |
2826 | nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, passed_mode, | |
2827 | passed_type, ! last_named); | |
2828 | #endif | |
2829 | ||
2830 | if (nregs > 0) | |
2831 | { | |
2832 | current_function_pretend_args_size | |
2833 | = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1) | |
2834 | / (PARM_BOUNDARY / BITS_PER_UNIT) | |
2835 | * (PARM_BOUNDARY / BITS_PER_UNIT)); | |
2836 | ||
2837 | if (! second_time) | |
2838 | move_block_from_reg (REGNO (entry_parm), | |
2839 | validize_mem (stack_parm), nregs); | |
2840 | entry_parm = stack_parm; | |
2841 | } | |
2842 | } | |
2843 | ||
2844 | /* If we didn't decide this parm came in a register, | |
2845 | by default it came on the stack. */ | |
2846 | if (entry_parm == 0) | |
2847 | entry_parm = stack_parm; | |
2848 | ||
2849 | /* Record permanently how this parm was passed. */ | |
2850 | if (! second_time) | |
2851 | DECL_INCOMING_RTL (parm) = entry_parm; | |
2852 | ||
2853 | /* If there is actually space on the stack for this parm, | |
2854 | count it in stack_args_size; otherwise set stack_parm to 0 | |
2855 | to indicate there is no preallocated stack slot for the parm. */ | |
2856 | ||
2857 | if (entry_parm == stack_parm | |
d9ca49d5 | 2858 | #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE) |
6f086dfc | 2859 | /* On some machines, even if a parm value arrives in a register |
d9ca49d5 JW |
2860 | there is still an (uninitialized) stack slot allocated for it. |
2861 | ||
2862 | ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell | |
2863 | whether this parameter already has a stack slot allocated, | |
2864 | because an arg block exists only if current_function_args_size | |
2865 | is larger than some threshhold, and we haven't calculated that | |
2866 | yet. So, for now, we just assume that stack slots never exist | |
2867 | in this case. */ | |
6f086dfc RS |
2868 | || REG_PARM_STACK_SPACE (fndecl) > 0 |
2869 | #endif | |
2870 | ) | |
2871 | { | |
2872 | stack_args_size.constant += arg_size.constant; | |
2873 | if (arg_size.var) | |
2874 | ADD_PARM_SIZE (stack_args_size, arg_size.var); | |
2875 | } | |
2876 | else | |
2877 | /* No stack slot was pushed for this parm. */ | |
2878 | stack_parm = 0; | |
2879 | ||
2880 | /* Update info on where next arg arrives in registers. */ | |
2881 | ||
2882 | FUNCTION_ARG_ADVANCE (args_so_far, passed_mode, | |
2883 | passed_type, ! last_named); | |
2884 | ||
2885 | /* If this is our second time through, we are done with this parm. */ | |
2886 | if (second_time) | |
2887 | continue; | |
2888 | ||
e16c591a RS |
2889 | /* If we can't trust the parm stack slot to be aligned enough |
2890 | for its ultimate type, don't use that slot after entry. | |
2891 | We'll make another stack slot, if we need one. */ | |
2892 | { | |
2893 | #ifdef FUNCTION_ARG_BOUNDARY | |
2894 | int thisparm_boundary | |
2895 | = FUNCTION_ARG_BOUNDARY (passed_mode, passed_type); | |
2896 | #else | |
2897 | int thisparm_boundary = PARM_BOUNDARY; | |
2898 | #endif | |
2899 | ||
2900 | if (GET_MODE_ALIGNMENT (nominal_mode) > thisparm_boundary) | |
2901 | stack_parm = 0; | |
2902 | } | |
2903 | ||
6f086dfc RS |
2904 | /* Now adjust STACK_PARM to the mode and precise location |
2905 | where this parameter should live during execution, | |
2906 | if we discover that it must live in the stack during execution. | |
2907 | To make debuggers happier on big-endian machines, we store | |
2908 | the value in the last bytes of the space available. */ | |
2909 | ||
2910 | if (nominal_mode != BLKmode && nominal_mode != passed_mode | |
2911 | && stack_parm != 0) | |
2912 | { | |
2913 | rtx offset_rtx; | |
2914 | ||
2915 | #if BYTES_BIG_ENDIAN | |
2916 | if (GET_MODE_SIZE (nominal_mode) < UNITS_PER_WORD) | |
2917 | stack_offset.constant += (GET_MODE_SIZE (passed_mode) | |
2918 | - GET_MODE_SIZE (nominal_mode)); | |
2919 | #endif | |
2920 | ||
2921 | offset_rtx = ARGS_SIZE_RTX (stack_offset); | |
2922 | if (offset_rtx == const0_rtx) | |
2923 | stack_parm = gen_rtx (MEM, nominal_mode, internal_arg_pointer); | |
2924 | else | |
2925 | stack_parm = gen_rtx (MEM, nominal_mode, | |
2926 | gen_rtx (PLUS, Pmode, | |
2927 | internal_arg_pointer, offset_rtx)); | |
2928 | ||
2929 | /* If this is a memory ref that contains aggregate components, | |
2930 | mark it as such for cse and loop optimize. */ | |
2931 | MEM_IN_STRUCT_P (stack_parm) = aggregate; | |
2932 | } | |
2933 | ||
2934 | /* ENTRY_PARM is an RTX for the parameter as it arrives, | |
2935 | in the mode in which it arrives. | |
2936 | STACK_PARM is an RTX for a stack slot where the parameter can live | |
2937 | during the function (in case we want to put it there). | |
2938 | STACK_PARM is 0 if no stack slot was pushed for it. | |
2939 | ||
2940 | Now output code if necessary to convert ENTRY_PARM to | |
2941 | the type in which this function declares it, | |
2942 | and store that result in an appropriate place, | |
2943 | which may be a pseudo reg, may be STACK_PARM, | |
2944 | or may be a local stack slot if STACK_PARM is 0. | |
2945 | ||
2946 | Set DECL_RTL to that place. */ | |
2947 | ||
2948 | if (nominal_mode == BLKmode) | |
2949 | { | |
2950 | /* If a BLKmode arrives in registers, copy it to a stack slot. */ | |
2951 | if (GET_CODE (entry_parm) == REG) | |
2952 | { | |
2953 | int size_stored = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)), | |
2954 | UNITS_PER_WORD); | |
2955 | ||
2956 | /* Note that we will be storing an integral number of words. | |
2957 | So we have to be careful to ensure that we allocate an | |
2958 | integral number of words. We do this below in the | |
2959 | assign_stack_local if space was not allocated in the argument | |
2960 | list. If it was, this will not work if PARM_BOUNDARY is not | |
2961 | a multiple of BITS_PER_WORD. It isn't clear how to fix this | |
2962 | if it becomes a problem. */ | |
2963 | ||
2964 | if (stack_parm == 0) | |
7e41ffa2 RS |
2965 | { |
2966 | stack_parm | |
2967 | = assign_stack_local (GET_MODE (entry_parm), size_stored, 0); | |
2968 | /* If this is a memory ref that contains aggregate components, | |
2969 | mark it as such for cse and loop optimize. */ | |
2970 | MEM_IN_STRUCT_P (stack_parm) = aggregate; | |
2971 | } | |
2972 | ||
6f086dfc RS |
2973 | else if (PARM_BOUNDARY % BITS_PER_WORD != 0) |
2974 | abort (); | |
2975 | ||
2976 | move_block_from_reg (REGNO (entry_parm), | |
2977 | validize_mem (stack_parm), | |
2978 | size_stored / UNITS_PER_WORD); | |
2979 | } | |
2980 | DECL_RTL (parm) = stack_parm; | |
2981 | } | |
74bd77a8 | 2982 | else if (! ((obey_regdecls && ! DECL_REGISTER (parm) |
a82ad570 | 2983 | && ! DECL_INLINE (fndecl)) |
6f086dfc RS |
2984 | /* layout_decl may set this. */ |
2985 | || TREE_ADDRESSABLE (parm) | |
2986 | || TREE_SIDE_EFFECTS (parm) | |
2987 | /* If -ffloat-store specified, don't put explicit | |
2988 | float variables into registers. */ | |
2989 | || (flag_float_store | |
2990 | && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)) | |
2991 | /* Always assign pseudo to structure return or item passed | |
2992 | by invisible reference. */ | |
2993 | || passed_pointer || parm == function_result_decl) | |
2994 | { | |
00d8a4c1 RK |
2995 | /* Store the parm in a pseudoregister during the function, but we |
2996 | may need to do it in a wider mode. */ | |
2997 | ||
2998 | register rtx parmreg; | |
2999 | ||
3000 | unsignedp = TREE_UNSIGNED (TREE_TYPE (parm)); | |
3001 | if (TREE_CODE (TREE_TYPE (parm)) == INTEGER_TYPE | |
3002 | || TREE_CODE (TREE_TYPE (parm)) == ENUMERAL_TYPE | |
3003 | || TREE_CODE (TREE_TYPE (parm)) == BOOLEAN_TYPE | |
3004 | || TREE_CODE (TREE_TYPE (parm)) == CHAR_TYPE | |
3005 | || TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE | |
3006 | || TREE_CODE (TREE_TYPE (parm)) == POINTER_TYPE | |
3007 | || TREE_CODE (TREE_TYPE (parm)) == OFFSET_TYPE) | |
3008 | { | |
3009 | PROMOTE_MODE (nominal_mode, unsignedp, TREE_TYPE (parm)); | |
3010 | } | |
6f086dfc | 3011 | |
00d8a4c1 | 3012 | parmreg = gen_reg_rtx (nominal_mode); |
6f086dfc RS |
3013 | REG_USERVAR_P (parmreg) = 1; |
3014 | ||
3015 | /* If this was an item that we received a pointer to, set DECL_RTL | |
3016 | appropriately. */ | |
3017 | if (passed_pointer) | |
3018 | { | |
3019 | DECL_RTL (parm) = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (passed_type)), parmreg); | |
3020 | MEM_IN_STRUCT_P (DECL_RTL (parm)) = aggregate; | |
3021 | } | |
3022 | else | |
3023 | DECL_RTL (parm) = parmreg; | |
3024 | ||
3025 | /* Copy the value into the register. */ | |
3026 | if (GET_MODE (parmreg) != GET_MODE (entry_parm)) | |
86f8eff3 RK |
3027 | { |
3028 | /* If ENTRY_PARM is a hard register, it might be in a register | |
3029 | not valid for operating in its mode (e.g., an odd-numbered | |
3030 | register for a DFmode). In that case, moves are the only | |
3031 | thing valid, so we can't do a convert from there. This | |
3032 | occurs when the calling sequence allow such misaligned | |
3033 | usages. */ | |
3034 | if (GET_CODE (entry_parm) == REG | |
3035 | && REGNO (entry_parm) < FIRST_PSEUDO_REGISTER | |
3036 | && ! HARD_REGNO_MODE_OK (REGNO (entry_parm), | |
3037 | GET_MODE (entry_parm))) | |
00d8a4c1 | 3038 | convert_move (parmreg, copy_to_reg (entry_parm), unsignedp); |
86f8eff3 | 3039 | else |
00d8a4c1 | 3040 | convert_move (parmreg, validize_mem (entry_parm), unsignedp); |
86f8eff3 | 3041 | } |
6f086dfc RS |
3042 | else |
3043 | emit_move_insn (parmreg, validize_mem (entry_parm)); | |
3044 | ||
74bd77a8 RS |
3045 | /* If we were passed a pointer but the actual value |
3046 | can safely live in a register, put it in one. */ | |
16bae307 | 3047 | if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode |
74bd77a8 RS |
3048 | && ! ((obey_regdecls && ! DECL_REGISTER (parm) |
3049 | && ! DECL_INLINE (fndecl)) | |
3050 | /* layout_decl may set this. */ | |
3051 | || TREE_ADDRESSABLE (parm) | |
3052 | || TREE_SIDE_EFFECTS (parm) | |
3053 | /* If -ffloat-store specified, don't put explicit | |
3054 | float variables into registers. */ | |
3055 | || (flag_float_store | |
3056 | && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))) | |
3057 | { | |
2654605a JW |
3058 | /* We can't use nominal_mode, because it will have been set to |
3059 | Pmode above. We must use the actual mode of the parm. */ | |
3060 | parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm))); | |
74bd77a8 RS |
3061 | emit_move_insn (parmreg, DECL_RTL (parm)); |
3062 | DECL_RTL (parm) = parmreg; | |
3063 | } | |
3064 | ||
6f086dfc RS |
3065 | /* In any case, record the parm's desired stack location |
3066 | in case we later discover it must live in the stack. */ | |
3067 | if (REGNO (parmreg) >= nparmregs) | |
3068 | { | |
3069 | rtx *new; | |
3070 | nparmregs = REGNO (parmreg) + 5; | |
3071 | new = (rtx *) oballoc (nparmregs * sizeof (rtx)); | |
3072 | bcopy (parm_reg_stack_loc, new, nparmregs * sizeof (rtx)); | |
3073 | parm_reg_stack_loc = new; | |
3074 | } | |
3075 | parm_reg_stack_loc[REGNO (parmreg)] = stack_parm; | |
3076 | ||
3077 | /* Mark the register as eliminable if we did no conversion | |
3078 | and it was copied from memory at a fixed offset, | |
3079 | and the arg pointer was not copied to a pseudo-reg. | |
3080 | If the arg pointer is a pseudo reg or the offset formed | |
3081 | an invalid address, such memory-equivalences | |
3082 | as we make here would screw up life analysis for it. */ | |
3083 | if (nominal_mode == passed_mode | |
3084 | && GET_CODE (entry_parm) == MEM | |
e16c591a | 3085 | && entry_parm == stack_parm |
6f086dfc RS |
3086 | && stack_offset.var == 0 |
3087 | && reg_mentioned_p (virtual_incoming_args_rtx, | |
3088 | XEXP (entry_parm, 0))) | |
3089 | REG_NOTES (get_last_insn ()) | |
3090 | = gen_rtx (EXPR_LIST, REG_EQUIV, | |
3091 | entry_parm, REG_NOTES (get_last_insn ())); | |
3092 | ||
3093 | /* For pointer data type, suggest pointer register. */ | |
3094 | if (TREE_CODE (TREE_TYPE (parm)) == POINTER_TYPE) | |
3095 | mark_reg_pointer (parmreg); | |
3096 | } | |
3097 | else | |
3098 | { | |
3099 | /* Value must be stored in the stack slot STACK_PARM | |
3100 | during function execution. */ | |
3101 | ||
3102 | if (passed_mode != nominal_mode) | |
86f8eff3 RK |
3103 | { |
3104 | /* Conversion is required. */ | |
3105 | if (GET_CODE (entry_parm) == REG | |
3106 | && REGNO (entry_parm) < FIRST_PSEUDO_REGISTER | |
3107 | && ! HARD_REGNO_MODE_OK (REGNO (entry_parm), passed_mode)) | |
3108 | entry_parm = copy_to_reg (entry_parm); | |
3109 | ||
a53e14c0 RK |
3110 | entry_parm = convert_to_mode (nominal_mode, entry_parm, |
3111 | TREE_UNSIGNED (TREE_TYPE (parm))); | |
86f8eff3 | 3112 | } |
6f086dfc RS |
3113 | |
3114 | if (entry_parm != stack_parm) | |
3115 | { | |
3116 | if (stack_parm == 0) | |
7e41ffa2 RS |
3117 | { |
3118 | stack_parm | |
3119 | = assign_stack_local (GET_MODE (entry_parm), | |
3120 | GET_MODE_SIZE (GET_MODE (entry_parm)), 0); | |
3121 | /* If this is a memory ref that contains aggregate components, | |
3122 | mark it as such for cse and loop optimize. */ | |
3123 | MEM_IN_STRUCT_P (stack_parm) = aggregate; | |
3124 | } | |
3125 | ||
6f086dfc RS |
3126 | emit_move_insn (validize_mem (stack_parm), |
3127 | validize_mem (entry_parm)); | |
3128 | } | |
3129 | ||
3130 | DECL_RTL (parm) = stack_parm; | |
3131 | } | |
3132 | ||
3133 | /* If this "parameter" was the place where we are receiving the | |
3134 | function's incoming structure pointer, set up the result. */ | |
3135 | if (parm == function_result_decl) | |
3136 | DECL_RTL (DECL_RESULT (fndecl)) | |
3137 | = gen_rtx (MEM, DECL_MODE (DECL_RESULT (fndecl)), DECL_RTL (parm)); | |
3138 | ||
3139 | if (TREE_THIS_VOLATILE (parm)) | |
3140 | MEM_VOLATILE_P (DECL_RTL (parm)) = 1; | |
3141 | if (TREE_READONLY (parm)) | |
3142 | RTX_UNCHANGING_P (DECL_RTL (parm)) = 1; | |
3143 | } | |
3144 | ||
3145 | max_parm_reg = max_reg_num (); | |
3146 | last_parm_insn = get_last_insn (); | |
3147 | ||
3148 | current_function_args_size = stack_args_size.constant; | |
3149 | ||
3150 | /* Adjust function incoming argument size for alignment and | |
3151 | minimum length. */ | |
3152 | ||
3153 | #ifdef REG_PARM_STACK_SPACE | |
6f90e075 | 3154 | #ifndef MAYBE_REG_PARM_STACK_SPACE |
6f086dfc RS |
3155 | current_function_args_size = MAX (current_function_args_size, |
3156 | REG_PARM_STACK_SPACE (fndecl)); | |
3157 | #endif | |
6f90e075 | 3158 | #endif |
6f086dfc RS |
3159 | |
3160 | #ifdef STACK_BOUNDARY | |
3161 | #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT) | |
3162 | ||
3163 | current_function_args_size | |
3164 | = ((current_function_args_size + STACK_BYTES - 1) | |
3165 | / STACK_BYTES) * STACK_BYTES; | |
3166 | #endif | |
3167 | ||
3168 | #ifdef ARGS_GROW_DOWNWARD | |
3169 | current_function_arg_offset_rtx | |
5f4f0e22 | 3170 | = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant) |
6f086dfc RS |
3171 | : expand_expr (size_binop (MINUS_EXPR, stack_args_size.var, |
3172 | size_int (-stack_args_size.constant)), | |
5f4f0e22 | 3173 | NULL_RTX, VOIDmode, 0)); |
6f086dfc RS |
3174 | #else |
3175 | current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size); | |
3176 | #endif | |
3177 | ||
3178 | /* See how many bytes, if any, of its args a function should try to pop | |
3179 | on return. */ | |
3180 | ||
3181 | current_function_pops_args = RETURN_POPS_ARGS (TREE_TYPE (fndecl), | |
3182 | current_function_args_size); | |
3183 | ||
3184 | /* For stdarg.h function, save info about regs and stack space | |
3185 | used by the named args. */ | |
3186 | ||
3187 | if (stdarg) | |
3188 | current_function_args_info = args_so_far; | |
3189 | ||
3190 | /* Set the rtx used for the function return value. Put this in its | |
3191 | own variable so any optimizers that need this information don't have | |
3192 | to include tree.h. Do this here so it gets done when an inlined | |
3193 | function gets output. */ | |
3194 | ||
3195 | current_function_return_rtx = DECL_RTL (DECL_RESULT (fndecl)); | |
3196 | } | |
3197 | \f | |
3198 | /* Compute the size and offset from the start of the stacked arguments for a | |
3199 | parm passed in mode PASSED_MODE and with type TYPE. | |
3200 | ||
3201 | INITIAL_OFFSET_PTR points to the current offset into the stacked | |
3202 | arguments. | |
3203 | ||
3204 | The starting offset and size for this parm are returned in *OFFSET_PTR | |
3205 | and *ARG_SIZE_PTR, respectively. | |
3206 | ||
3207 | IN_REGS is non-zero if the argument will be passed in registers. It will | |
3208 | never be set if REG_PARM_STACK_SPACE is not defined. | |
3209 | ||
3210 | FNDECL is the function in which the argument was defined. | |
3211 | ||
3212 | There are two types of rounding that are done. The first, controlled by | |
3213 | FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument | |
3214 | list to be aligned to the specific boundary (in bits). This rounding | |
3215 | affects the initial and starting offsets, but not the argument size. | |
3216 | ||
3217 | The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY, | |
3218 | optionally rounds the size of the parm to PARM_BOUNDARY. The | |
3219 | initial offset is not affected by this rounding, while the size always | |
3220 | is and the starting offset may be. */ | |
3221 | ||
3222 | /* offset_ptr will be negative for ARGS_GROW_DOWNWARD case; | |
3223 | initial_offset_ptr is positive because locate_and_pad_parm's | |
3224 | callers pass in the total size of args so far as | |
3225 | initial_offset_ptr. arg_size_ptr is always positive.*/ | |
3226 | ||
3227 | static void pad_to_arg_alignment (), pad_below (); | |
3228 | ||
3229 | void | |
3230 | locate_and_pad_parm (passed_mode, type, in_regs, fndecl, | |
3231 | initial_offset_ptr, offset_ptr, arg_size_ptr) | |
3232 | enum machine_mode passed_mode; | |
3233 | tree type; | |
3234 | int in_regs; | |
3235 | tree fndecl; | |
3236 | struct args_size *initial_offset_ptr; | |
3237 | struct args_size *offset_ptr; | |
3238 | struct args_size *arg_size_ptr; | |
3239 | { | |
3240 | tree sizetree | |
3241 | = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode)); | |
3242 | enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type); | |
3243 | int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type); | |
3244 | int boundary_in_bytes = boundary / BITS_PER_UNIT; | |
3245 | int reg_parm_stack_space = 0; | |
3246 | ||
3247 | #ifdef REG_PARM_STACK_SPACE | |
3248 | /* If we have found a stack parm before we reach the end of the | |
3249 | area reserved for registers, skip that area. */ | |
3250 | if (! in_regs) | |
3251 | { | |
29008b51 JW |
3252 | #ifdef MAYBE_REG_PARM_STACK_SPACE |
3253 | reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE; | |
3254 | #else | |
6f086dfc | 3255 | reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl); |
29008b51 | 3256 | #endif |
6f086dfc RS |
3257 | if (reg_parm_stack_space > 0) |
3258 | { | |
3259 | if (initial_offset_ptr->var) | |
3260 | { | |
3261 | initial_offset_ptr->var | |
3262 | = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr), | |
3263 | size_int (reg_parm_stack_space)); | |
3264 | initial_offset_ptr->constant = 0; | |
3265 | } | |
3266 | else if (initial_offset_ptr->constant < reg_parm_stack_space) | |
3267 | initial_offset_ptr->constant = reg_parm_stack_space; | |
3268 | } | |
3269 | } | |
3270 | #endif /* REG_PARM_STACK_SPACE */ | |
3271 | ||
3272 | arg_size_ptr->var = 0; | |
3273 | arg_size_ptr->constant = 0; | |
3274 | ||
3275 | #ifdef ARGS_GROW_DOWNWARD | |
3276 | if (initial_offset_ptr->var) | |
3277 | { | |
3278 | offset_ptr->constant = 0; | |
3279 | offset_ptr->var = size_binop (MINUS_EXPR, integer_zero_node, | |
3280 | initial_offset_ptr->var); | |
3281 | } | |
3282 | else | |
3283 | { | |
3284 | offset_ptr->constant = - initial_offset_ptr->constant; | |
3285 | offset_ptr->var = 0; | |
3286 | } | |
3287 | if (where_pad == upward | |
3288 | && (TREE_CODE (sizetree) != INTEGER_CST | |
3289 | || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY))) | |
3290 | sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT); | |
3291 | SUB_PARM_SIZE (*offset_ptr, sizetree); | |
3292 | pad_to_arg_alignment (offset_ptr, boundary); | |
3293 | if (initial_offset_ptr->var) | |
3294 | { | |
3295 | arg_size_ptr->var = size_binop (MINUS_EXPR, | |
3296 | size_binop (MINUS_EXPR, | |
3297 | integer_zero_node, | |
3298 | initial_offset_ptr->var), | |
3299 | offset_ptr->var); | |
3300 | } | |
3301 | else | |
3302 | { | |
3303 | arg_size_ptr->constant = (- initial_offset_ptr->constant - | |
3304 | offset_ptr->constant); | |
3305 | } | |
3306 | /* ADD_PARM_SIZE (*arg_size_ptr, sizetree); */ | |
3307 | if (where_pad == downward) | |
3308 | pad_below (arg_size_ptr, passed_mode, sizetree); | |
3309 | #else /* !ARGS_GROW_DOWNWARD */ | |
3310 | pad_to_arg_alignment (initial_offset_ptr, boundary); | |
3311 | *offset_ptr = *initial_offset_ptr; | |
3312 | if (where_pad == downward) | |
3313 | pad_below (offset_ptr, passed_mode, sizetree); | |
3314 | ||
3315 | #ifdef PUSH_ROUNDING | |
3316 | if (passed_mode != BLKmode) | |
3317 | sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree))); | |
3318 | #endif | |
3319 | ||
3320 | if (where_pad != none | |
3321 | && (TREE_CODE (sizetree) != INTEGER_CST | |
3322 | || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY))) | |
3323 | sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT); | |
3324 | ||
3325 | ADD_PARM_SIZE (*arg_size_ptr, sizetree); | |
3326 | #endif /* ARGS_GROW_DOWNWARD */ | |
3327 | } | |
3328 | ||
e16c591a RS |
3329 | /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY. |
3330 | BOUNDARY is measured in bits, but must be a multiple of a storage unit. */ | |
3331 | ||
6f086dfc RS |
3332 | static void |
3333 | pad_to_arg_alignment (offset_ptr, boundary) | |
3334 | struct args_size *offset_ptr; | |
3335 | int boundary; | |
3336 | { | |
3337 | int boundary_in_bytes = boundary / BITS_PER_UNIT; | |
3338 | ||
3339 | if (boundary > BITS_PER_UNIT) | |
3340 | { | |
3341 | if (offset_ptr->var) | |
3342 | { | |
3343 | offset_ptr->var = | |
3344 | #ifdef ARGS_GROW_DOWNWARD | |
3345 | round_down | |
3346 | #else | |
3347 | round_up | |
3348 | #endif | |
3349 | (ARGS_SIZE_TREE (*offset_ptr), | |
3350 | boundary / BITS_PER_UNIT); | |
3351 | offset_ptr->constant = 0; /*?*/ | |
3352 | } | |
3353 | else | |
3354 | offset_ptr->constant = | |
3355 | #ifdef ARGS_GROW_DOWNWARD | |
3356 | FLOOR_ROUND (offset_ptr->constant, boundary_in_bytes); | |
3357 | #else | |
3358 | CEIL_ROUND (offset_ptr->constant, boundary_in_bytes); | |
3359 | #endif | |
3360 | } | |
3361 | } | |
3362 | ||
3363 | static void | |
3364 | pad_below (offset_ptr, passed_mode, sizetree) | |
3365 | struct args_size *offset_ptr; | |
3366 | enum machine_mode passed_mode; | |
3367 | tree sizetree; | |
3368 | { | |
3369 | if (passed_mode != BLKmode) | |
3370 | { | |
3371 | if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY) | |
3372 | offset_ptr->constant | |
3373 | += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1) | |
3374 | / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT) | |
3375 | - GET_MODE_SIZE (passed_mode)); | |
3376 | } | |
3377 | else | |
3378 | { | |
3379 | if (TREE_CODE (sizetree) != INTEGER_CST | |
3380 | || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY) | |
3381 | { | |
3382 | /* Round the size up to multiple of PARM_BOUNDARY bits. */ | |
3383 | tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT); | |
3384 | /* Add it in. */ | |
3385 | ADD_PARM_SIZE (*offset_ptr, s2); | |
3386 | SUB_PARM_SIZE (*offset_ptr, sizetree); | |
3387 | } | |
3388 | } | |
3389 | } | |
3390 | ||
3391 | static tree | |
3392 | round_down (value, divisor) | |
3393 | tree value; | |
3394 | int divisor; | |
3395 | { | |
3396 | return size_binop (MULT_EXPR, | |
3397 | size_binop (FLOOR_DIV_EXPR, value, size_int (divisor)), | |
3398 | size_int (divisor)); | |
3399 | } | |
3400 | \f | |
3401 | /* Walk the tree of blocks describing the binding levels within a function | |
3402 | and warn about uninitialized variables. | |
3403 | This is done after calling flow_analysis and before global_alloc | |
3404 | clobbers the pseudo-regs to hard regs. */ | |
3405 | ||
3406 | void | |
3407 | uninitialized_vars_warning (block) | |
3408 | tree block; | |
3409 | { | |
3410 | register tree decl, sub; | |
3411 | for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl)) | |
3412 | { | |
3413 | if (TREE_CODE (decl) == VAR_DECL | |
3414 | /* These warnings are unreliable for and aggregates | |
3415 | because assigning the fields one by one can fail to convince | |
3416 | flow.c that the entire aggregate was initialized. | |
3417 | Unions are troublesome because members may be shorter. */ | |
3418 | && TREE_CODE (TREE_TYPE (decl)) != RECORD_TYPE | |
3419 | && TREE_CODE (TREE_TYPE (decl)) != UNION_TYPE | |
3420 | && TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE | |
3421 | && DECL_RTL (decl) != 0 | |
3422 | && GET_CODE (DECL_RTL (decl)) == REG | |
3423 | && regno_uninitialized (REGNO (DECL_RTL (decl)))) | |
3424 | warning_with_decl (decl, | |
3425 | "`%s' may be used uninitialized in this function"); | |
3426 | if (TREE_CODE (decl) == VAR_DECL | |
3427 | && DECL_RTL (decl) != 0 | |
3428 | && GET_CODE (DECL_RTL (decl)) == REG | |
3429 | && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl)))) | |
3430 | warning_with_decl (decl, | |
3431 | "variable `%s' may be clobbered by `longjmp'"); | |
3432 | } | |
3433 | for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub)) | |
3434 | uninitialized_vars_warning (sub); | |
3435 | } | |
3436 | ||
3437 | /* Do the appropriate part of uninitialized_vars_warning | |
3438 | but for arguments instead of local variables. */ | |
3439 | ||
3440 | void | |
3441 | setjmp_args_warning (block) | |
3442 | tree block; | |
3443 | { | |
3444 | register tree decl; | |
3445 | for (decl = DECL_ARGUMENTS (current_function_decl); | |
3446 | decl; decl = TREE_CHAIN (decl)) | |
3447 | if (DECL_RTL (decl) != 0 | |
3448 | && GET_CODE (DECL_RTL (decl)) == REG | |
3449 | && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl)))) | |
3450 | warning_with_decl (decl, "argument `%s' may be clobbered by `longjmp'"); | |
3451 | } | |
3452 | ||
3453 | /* If this function call setjmp, put all vars into the stack | |
3454 | unless they were declared `register'. */ | |
3455 | ||
3456 | void | |
3457 | setjmp_protect (block) | |
3458 | tree block; | |
3459 | { | |
3460 | register tree decl, sub; | |
3461 | for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl)) | |
3462 | if ((TREE_CODE (decl) == VAR_DECL | |
3463 | || TREE_CODE (decl) == PARM_DECL) | |
3464 | && DECL_RTL (decl) != 0 | |
3465 | && GET_CODE (DECL_RTL (decl)) == REG | |
b335c2cc TW |
3466 | /* If this variable came from an inline function, it must be |
3467 | that it's life doesn't overlap the setjmp. If there was a | |
3468 | setjmp in the function, it would already be in memory. We | |
3469 | must exclude such variable because their DECL_RTL might be | |
3470 | set to strange things such as virtual_stack_vars_rtx. */ | |
3471 | && ! DECL_FROM_INLINE (decl) | |
6f086dfc RS |
3472 | && ( |
3473 | #ifdef NON_SAVING_SETJMP | |
3474 | /* If longjmp doesn't restore the registers, | |
3475 | don't put anything in them. */ | |
3476 | NON_SAVING_SETJMP | |
3477 | || | |
3478 | #endif | |
a82ad570 | 3479 | ! DECL_REGISTER (decl))) |
6f086dfc RS |
3480 | put_var_into_stack (decl); |
3481 | for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub)) | |
3482 | setjmp_protect (sub); | |
3483 | } | |
3484 | \f | |
3485 | /* Like the previous function, but for args instead of local variables. */ | |
3486 | ||
3487 | void | |
3488 | setjmp_protect_args () | |
3489 | { | |
3490 | register tree decl, sub; | |
3491 | for (decl = DECL_ARGUMENTS (current_function_decl); | |
3492 | decl; decl = TREE_CHAIN (decl)) | |
3493 | if ((TREE_CODE (decl) == VAR_DECL | |
3494 | || TREE_CODE (decl) == PARM_DECL) | |
3495 | && DECL_RTL (decl) != 0 | |
3496 | && GET_CODE (DECL_RTL (decl)) == REG | |
3497 | && ( | |
3498 | /* If longjmp doesn't restore the registers, | |
3499 | don't put anything in them. */ | |
3500 | #ifdef NON_SAVING_SETJMP | |
3501 | NON_SAVING_SETJMP | |
3502 | || | |
3503 | #endif | |
a82ad570 | 3504 | ! DECL_REGISTER (decl))) |
6f086dfc RS |
3505 | put_var_into_stack (decl); |
3506 | } | |
3507 | \f | |
3508 | /* Return the context-pointer register corresponding to DECL, | |
3509 | or 0 if it does not need one. */ | |
3510 | ||
3511 | rtx | |
3512 | lookup_static_chain (decl) | |
3513 | tree decl; | |
3514 | { | |
3515 | tree context = decl_function_context (decl); | |
3516 | tree link; | |
3517 | ||
3518 | if (context == 0) | |
3519 | return 0; | |
3520 | ||
3521 | /* We treat inline_function_decl as an alias for the current function | |
3522 | because that is the inline function whose vars, types, etc. | |
3523 | are being merged into the current function. | |
3524 | See expand_inline_function. */ | |
3525 | if (context == current_function_decl || context == inline_function_decl) | |
3526 | return virtual_stack_vars_rtx; | |
3527 | ||
3528 | for (link = context_display; link; link = TREE_CHAIN (link)) | |
3529 | if (TREE_PURPOSE (link) == context) | |
3530 | return RTL_EXPR_RTL (TREE_VALUE (link)); | |
3531 | ||
3532 | abort (); | |
3533 | } | |
3534 | \f | |
3535 | /* Convert a stack slot address ADDR for variable VAR | |
3536 | (from a containing function) | |
3537 | into an address valid in this function (using a static chain). */ | |
3538 | ||
3539 | rtx | |
3540 | fix_lexical_addr (addr, var) | |
3541 | rtx addr; | |
3542 | tree var; | |
3543 | { | |
3544 | rtx basereg; | |
3545 | int displacement; | |
3546 | tree context = decl_function_context (var); | |
3547 | struct function *fp; | |
3548 | rtx base = 0; | |
3549 | ||
3550 | /* If this is the present function, we need not do anything. */ | |
3551 | if (context == current_function_decl || context == inline_function_decl) | |
3552 | return addr; | |
3553 | ||
3554 | for (fp = outer_function_chain; fp; fp = fp->next) | |
3555 | if (fp->decl == context) | |
3556 | break; | |
3557 | ||
3558 | if (fp == 0) | |
3559 | abort (); | |
3560 | ||
3561 | /* Decode given address as base reg plus displacement. */ | |
3562 | if (GET_CODE (addr) == REG) | |
3563 | basereg = addr, displacement = 0; | |
3564 | else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT) | |
3565 | basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1)); | |
3566 | else | |
3567 | abort (); | |
3568 | ||
3569 | /* We accept vars reached via the containing function's | |
3570 | incoming arg pointer and via its stack variables pointer. */ | |
3571 | if (basereg == fp->internal_arg_pointer) | |
3572 | { | |
3573 | /* If reached via arg pointer, get the arg pointer value | |
3574 | out of that function's stack frame. | |
3575 | ||
3576 | There are two cases: If a separate ap is needed, allocate a | |
3577 | slot in the outer function for it and dereference it that way. | |
3578 | This is correct even if the real ap is actually a pseudo. | |
3579 | Otherwise, just adjust the offset from the frame pointer to | |
3580 | compensate. */ | |
3581 | ||
3582 | #ifdef NEED_SEPARATE_AP | |
3583 | rtx addr; | |
3584 | ||
3585 | if (fp->arg_pointer_save_area == 0) | |
3586 | fp->arg_pointer_save_area | |
3587 | = assign_outer_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0, fp); | |
3588 | ||
3589 | addr = fix_lexical_addr (XEXP (fp->arg_pointer_save_area, 0), var); | |
3590 | addr = memory_address (Pmode, addr); | |
3591 | ||
3592 | base = copy_to_reg (gen_rtx (MEM, Pmode, addr)); | |
3593 | #else | |
3594 | displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET); | |
86f8eff3 | 3595 | base = lookup_static_chain (var); |
6f086dfc RS |
3596 | #endif |
3597 | } | |
3598 | ||
3599 | else if (basereg == virtual_stack_vars_rtx) | |
3600 | { | |
3601 | /* This is the same code as lookup_static_chain, duplicated here to | |
3602 | avoid an extra call to decl_function_context. */ | |
3603 | tree link; | |
3604 | ||
3605 | for (link = context_display; link; link = TREE_CHAIN (link)) | |
3606 | if (TREE_PURPOSE (link) == context) | |
3607 | { | |
3608 | base = RTL_EXPR_RTL (TREE_VALUE (link)); | |
3609 | break; | |
3610 | } | |
3611 | } | |
3612 | ||
3613 | if (base == 0) | |
3614 | abort (); | |
3615 | ||
3616 | /* Use same offset, relative to appropriate static chain or argument | |
3617 | pointer. */ | |
3618 | return plus_constant (base, displacement); | |
3619 | } | |
3620 | \f | |
3621 | /* Return the address of the trampoline for entering nested fn FUNCTION. | |
3622 | If necessary, allocate a trampoline (in the stack frame) | |
3623 | and emit rtl to initialize its contents (at entry to this function). */ | |
3624 | ||
3625 | rtx | |
3626 | trampoline_address (function) | |
3627 | tree function; | |
3628 | { | |
3629 | tree link; | |
3630 | tree rtlexp; | |
3631 | rtx tramp; | |
3632 | struct function *fp; | |
3633 | tree fn_context; | |
3634 | ||
3635 | /* Find an existing trampoline and return it. */ | |
3636 | for (link = trampoline_list; link; link = TREE_CHAIN (link)) | |
3637 | if (TREE_PURPOSE (link) == function) | |
3638 | return XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0); | |
3639 | for (fp = outer_function_chain; fp; fp = fp->next) | |
3640 | for (link = fp->trampoline_list; link; link = TREE_CHAIN (link)) | |
3641 | if (TREE_PURPOSE (link) == function) | |
3642 | { | |
3643 | tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0), | |
3644 | function); | |
3645 | return round_trampoline_addr (tramp); | |
3646 | } | |
3647 | ||
3648 | /* None exists; we must make one. */ | |
3649 | ||
3650 | /* Find the `struct function' for the function containing FUNCTION. */ | |
3651 | fp = 0; | |
3652 | fn_context = decl_function_context (function); | |
3653 | if (fn_context != current_function_decl) | |
3654 | for (fp = outer_function_chain; fp; fp = fp->next) | |
3655 | if (fp->decl == fn_context) | |
3656 | break; | |
3657 | ||
3658 | /* Allocate run-time space for this trampoline | |
3659 | (usually in the defining function's stack frame). */ | |
3660 | #ifdef ALLOCATE_TRAMPOLINE | |
3661 | tramp = ALLOCATE_TRAMPOLINE (fp); | |
3662 | #else | |
3663 | /* If rounding needed, allocate extra space | |
3664 | to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */ | |
3665 | #ifdef TRAMPOLINE_ALIGNMENT | |
3666 | #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE + TRAMPOLINE_ALIGNMENT - 1) | |
3667 | #else | |
3668 | #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE) | |
3669 | #endif | |
3670 | if (fp != 0) | |
3671 | tramp = assign_outer_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0, fp); | |
3672 | else | |
3673 | tramp = assign_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0); | |
3674 | #endif | |
3675 | ||
3676 | /* Record the trampoline for reuse and note it for later initialization | |
3677 | by expand_function_end. */ | |
3678 | if (fp != 0) | |
3679 | { | |
3680 | push_obstacks (fp->current_obstack, fp->function_maybepermanent_obstack); | |
3681 | rtlexp = make_node (RTL_EXPR); | |
3682 | RTL_EXPR_RTL (rtlexp) = tramp; | |
3683 | fp->trampoline_list = tree_cons (function, rtlexp, fp->trampoline_list); | |
3684 | pop_obstacks (); | |
3685 | } | |
3686 | else | |
3687 | { | |
3688 | /* Make the RTL_EXPR node temporary, not momentary, so that the | |
3689 | trampoline_list doesn't become garbage. */ | |
3690 | int momentary = suspend_momentary (); | |
3691 | rtlexp = make_node (RTL_EXPR); | |
3692 | resume_momentary (momentary); | |
3693 | ||
3694 | RTL_EXPR_RTL (rtlexp) = tramp; | |
3695 | trampoline_list = tree_cons (function, rtlexp, trampoline_list); | |
3696 | } | |
3697 | ||
3698 | tramp = fix_lexical_addr (XEXP (tramp, 0), function); | |
3699 | return round_trampoline_addr (tramp); | |
3700 | } | |
3701 | ||
3702 | /* Given a trampoline address, | |
3703 | round it to multiple of TRAMPOLINE_ALIGNMENT. */ | |
3704 | ||
3705 | static rtx | |
3706 | round_trampoline_addr (tramp) | |
3707 | rtx tramp; | |
3708 | { | |
3709 | #ifdef TRAMPOLINE_ALIGNMENT | |
3710 | /* Round address up to desired boundary. */ | |
3711 | rtx temp = gen_reg_rtx (Pmode); | |
3712 | temp = expand_binop (Pmode, add_optab, tramp, | |
5f4f0e22 | 3713 | GEN_INT (TRAMPOLINE_ALIGNMENT - 1), |
6f086dfc RS |
3714 | temp, 0, OPTAB_LIB_WIDEN); |
3715 | tramp = expand_binop (Pmode, and_optab, temp, | |
5f4f0e22 | 3716 | GEN_INT (- TRAMPOLINE_ALIGNMENT), |
6f086dfc RS |
3717 | temp, 0, OPTAB_LIB_WIDEN); |
3718 | #endif | |
3719 | return tramp; | |
3720 | } | |
3721 | \f | |
467456d0 RS |
3722 | /* The functions identify_blocks and reorder_blocks provide a way to |
3723 | reorder the tree of BLOCK nodes, for optimizers that reshuffle or | |
3724 | duplicate portions of the RTL code. Call identify_blocks before | |
3725 | changing the RTL, and call reorder_blocks after. */ | |
3726 | ||
3727 | static int all_blocks (); | |
3728 | static tree blocks_nreverse (); | |
3729 | ||
3730 | /* Put all this function's BLOCK nodes into a vector, and return it. | |
3731 | Also store in each NOTE for the beginning or end of a block | |
3732 | the index of that block in the vector. | |
3733 | The arguments are TOP_BLOCK, the top-level block of the function, | |
3734 | and INSNS, the insn chain of the function. */ | |
3735 | ||
3736 | tree * | |
3737 | identify_blocks (top_block, insns) | |
3738 | tree top_block; | |
3739 | rtx insns; | |
3740 | { | |
fc289cd1 JW |
3741 | int n_blocks; |
3742 | tree *block_vector; | |
3743 | int *block_stack; | |
467456d0 RS |
3744 | int depth = 0; |
3745 | int next_block_number = 0; | |
3746 | int current_block_number = 0; | |
3747 | rtx insn; | |
3748 | ||
fc289cd1 JW |
3749 | if (top_block == 0) |
3750 | return 0; | |
3751 | ||
3752 | n_blocks = all_blocks (top_block, 0); | |
3753 | block_vector = (tree *) xmalloc (n_blocks * sizeof (tree)); | |
3754 | block_stack = (int *) alloca (n_blocks * sizeof (int)); | |
3755 | ||
467456d0 RS |
3756 | all_blocks (top_block, block_vector); |
3757 | ||
3758 | for (insn = insns; insn; insn = NEXT_INSN (insn)) | |
3759 | if (GET_CODE (insn) == NOTE) | |
3760 | { | |
3761 | if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG) | |
3762 | { | |
3763 | block_stack[depth++] = current_block_number; | |
3764 | current_block_number = next_block_number; | |
1b2ac438 | 3765 | NOTE_BLOCK_NUMBER (insn) = next_block_number++; |
467456d0 RS |
3766 | } |
3767 | if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END) | |
3768 | { | |
3769 | current_block_number = block_stack[--depth]; | |
1b2ac438 | 3770 | NOTE_BLOCK_NUMBER (insn) = current_block_number; |
467456d0 RS |
3771 | } |
3772 | } | |
3773 | ||
3774 | return block_vector; | |
3775 | } | |
3776 | ||
3777 | /* Given BLOCK_VECTOR which was returned by identify_blocks, | |
3778 | and a revised instruction chain, rebuild the tree structure | |
3779 | of BLOCK nodes to correspond to the new order of RTL. | |
fc289cd1 | 3780 | The new block tree is inserted below TOP_BLOCK. |
467456d0 RS |
3781 | Returns the current top-level block. */ |
3782 | ||
3783 | tree | |
fc289cd1 | 3784 | reorder_blocks (block_vector, top_block, insns) |
467456d0 | 3785 | tree *block_vector; |
fc289cd1 | 3786 | tree top_block; |
467456d0 RS |
3787 | rtx insns; |
3788 | { | |
fc289cd1 | 3789 | tree current_block = top_block; |
467456d0 RS |
3790 | rtx insn; |
3791 | ||
fc289cd1 JW |
3792 | if (block_vector == 0) |
3793 | return top_block; | |
3794 | ||
3795 | /* Prune the old tree away, so that it doesn't get in the way. */ | |
3796 | BLOCK_SUBBLOCKS (current_block) = 0; | |
3797 | ||
467456d0 RS |
3798 | for (insn = insns; insn; insn = NEXT_INSN (insn)) |
3799 | if (GET_CODE (insn) == NOTE) | |
3800 | { | |
3801 | if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG) | |
3802 | { | |
3803 | tree block = block_vector[NOTE_BLOCK_NUMBER (insn)]; | |
3804 | /* If we have seen this block before, copy it. */ | |
3805 | if (TREE_ASM_WRITTEN (block)) | |
3806 | block = copy_node (block); | |
fc289cd1 | 3807 | BLOCK_SUBBLOCKS (block) = 0; |
467456d0 RS |
3808 | TREE_ASM_WRITTEN (block) = 1; |
3809 | BLOCK_SUPERCONTEXT (block) = current_block; | |
3810 | BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block); | |
3811 | BLOCK_SUBBLOCKS (current_block) = block; | |
3812 | current_block = block; | |
1b2ac438 | 3813 | NOTE_SOURCE_FILE (insn) = 0; |
467456d0 RS |
3814 | } |
3815 | if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END) | |
3816 | { | |
3817 | BLOCK_SUBBLOCKS (current_block) | |
3818 | = blocks_nreverse (BLOCK_SUBBLOCKS (current_block)); | |
3819 | current_block = BLOCK_SUPERCONTEXT (current_block); | |
1b2ac438 | 3820 | NOTE_SOURCE_FILE (insn) = 0; |
467456d0 RS |
3821 | } |
3822 | } | |
3823 | ||
3824 | return current_block; | |
3825 | } | |
3826 | ||
3827 | /* Reverse the order of elements in the chain T of blocks, | |
3828 | and return the new head of the chain (old last element). */ | |
3829 | ||
3830 | static tree | |
3831 | blocks_nreverse (t) | |
3832 | tree t; | |
3833 | { | |
3834 | register tree prev = 0, decl, next; | |
3835 | for (decl = t; decl; decl = next) | |
3836 | { | |
3837 | next = BLOCK_CHAIN (decl); | |
3838 | BLOCK_CHAIN (decl) = prev; | |
3839 | prev = decl; | |
3840 | } | |
3841 | return prev; | |
3842 | } | |
3843 | ||
3844 | /* Count the subblocks of BLOCK, and list them all into the vector VECTOR. | |
3845 | Also clear TREE_ASM_WRITTEN in all blocks. */ | |
3846 | ||
3847 | static int | |
3848 | all_blocks (block, vector) | |
3849 | tree block; | |
3850 | tree *vector; | |
3851 | { | |
3852 | int n_blocks = 1; | |
3853 | tree subblocks; | |
3854 | ||
3855 | TREE_ASM_WRITTEN (block) = 0; | |
3856 | /* Record this block. */ | |
fc289cd1 JW |
3857 | if (vector) |
3858 | vector[0] = block; | |
467456d0 RS |
3859 | |
3860 | /* Record the subblocks, and their subblocks. */ | |
3861 | for (subblocks = BLOCK_SUBBLOCKS (block); | |
3862 | subblocks; subblocks = BLOCK_CHAIN (subblocks)) | |
fc289cd1 | 3863 | n_blocks += all_blocks (subblocks, vector ? vector + n_blocks : 0); |
467456d0 RS |
3864 | |
3865 | return n_blocks; | |
3866 | } | |
3867 | \f | |
6f086dfc RS |
3868 | /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node) |
3869 | and initialize static variables for generating RTL for the statements | |
3870 | of the function. */ | |
3871 | ||
3872 | void | |
3873 | init_function_start (subr, filename, line) | |
3874 | tree subr; | |
3875 | char *filename; | |
3876 | int line; | |
3877 | { | |
3878 | char *junk; | |
3879 | ||
3880 | init_stmt_for_function (); | |
3881 | ||
3882 | cse_not_expected = ! optimize; | |
3883 | ||
3884 | /* Caller save not needed yet. */ | |
3885 | caller_save_needed = 0; | |
3886 | ||
3887 | /* No stack slots have been made yet. */ | |
3888 | stack_slot_list = 0; | |
3889 | ||
3890 | /* There is no stack slot for handling nonlocal gotos. */ | |
3891 | nonlocal_goto_handler_slot = 0; | |
3892 | nonlocal_goto_stack_level = 0; | |
3893 | ||
3894 | /* No labels have been declared for nonlocal use. */ | |
3895 | nonlocal_labels = 0; | |
3896 | ||
3897 | /* No function calls so far in this function. */ | |
3898 | function_call_count = 0; | |
3899 | ||
3900 | /* No parm regs have been allocated. | |
3901 | (This is important for output_inline_function.) */ | |
3902 | max_parm_reg = LAST_VIRTUAL_REGISTER + 1; | |
3903 | ||
3904 | /* Initialize the RTL mechanism. */ | |
3905 | init_emit (); | |
3906 | ||
3907 | /* Initialize the queue of pending postincrement and postdecrements, | |
3908 | and some other info in expr.c. */ | |
3909 | init_expr (); | |
3910 | ||
3911 | /* We haven't done register allocation yet. */ | |
3912 | reg_renumber = 0; | |
3913 | ||
3914 | init_const_rtx_hash_table (); | |
3915 | ||
3916 | current_function_name = (*decl_printable_name) (subr, &junk); | |
3917 | ||
3918 | /* Nonzero if this is a nested function that uses a static chain. */ | |
3919 | ||
3920 | current_function_needs_context | |
3921 | = (decl_function_context (current_function_decl) != 0); | |
3922 | ||
3923 | /* Set if a call to setjmp is seen. */ | |
3924 | current_function_calls_setjmp = 0; | |
3925 | ||
3926 | /* Set if a call to longjmp is seen. */ | |
3927 | current_function_calls_longjmp = 0; | |
3928 | ||
3929 | current_function_calls_alloca = 0; | |
3930 | current_function_has_nonlocal_label = 0; | |
3931 | current_function_contains_functions = 0; | |
3932 | ||
3933 | current_function_returns_pcc_struct = 0; | |
3934 | current_function_returns_struct = 0; | |
3935 | current_function_epilogue_delay_list = 0; | |
3936 | current_function_uses_const_pool = 0; | |
3937 | current_function_uses_pic_offset_table = 0; | |
3938 | ||
3939 | /* We have not yet needed to make a label to jump to for tail-recursion. */ | |
3940 | tail_recursion_label = 0; | |
3941 | ||
3942 | /* We haven't had a need to make a save area for ap yet. */ | |
3943 | ||
3944 | arg_pointer_save_area = 0; | |
3945 | ||
3946 | /* No stack slots allocated yet. */ | |
3947 | frame_offset = 0; | |
3948 | ||
3949 | /* No SAVE_EXPRs in this function yet. */ | |
3950 | save_expr_regs = 0; | |
3951 | ||
3952 | /* No RTL_EXPRs in this function yet. */ | |
3953 | rtl_expr_chain = 0; | |
3954 | ||
3955 | /* We have not allocated any temporaries yet. */ | |
3956 | temp_slots = 0; | |
3957 | temp_slot_level = 0; | |
3958 | ||
3959 | /* Within function body, compute a type's size as soon it is laid out. */ | |
3960 | immediate_size_expand++; | |
3961 | ||
3962 | init_pending_stack_adjust (); | |
3963 | inhibit_defer_pop = 0; | |
3964 | ||
3965 | current_function_outgoing_args_size = 0; | |
3966 | ||
3967 | /* Initialize the insn lengths. */ | |
3968 | init_insn_lengths (); | |
3969 | ||
3970 | /* Prevent ever trying to delete the first instruction of a function. | |
3971 | Also tell final how to output a linenum before the function prologue. */ | |
3972 | emit_line_note (filename, line); | |
3973 | ||
3974 | /* Make sure first insn is a note even if we don't want linenums. | |
3975 | This makes sure the first insn will never be deleted. | |
3976 | Also, final expects a note to appear there. */ | |
5f4f0e22 | 3977 | emit_note (NULL_PTR, NOTE_INSN_DELETED); |
6f086dfc RS |
3978 | |
3979 | /* Set flags used by final.c. */ | |
3980 | if (aggregate_value_p (DECL_RESULT (subr))) | |
3981 | { | |
3982 | #ifdef PCC_STATIC_STRUCT_RETURN | |
3983 | if (flag_pcc_struct_return) | |
3984 | current_function_returns_pcc_struct = 1; | |
3985 | else | |
3986 | #endif | |
3987 | current_function_returns_struct = 1; | |
3988 | } | |
3989 | ||
3990 | /* Warn if this value is an aggregate type, | |
3991 | regardless of which calling convention we are using for it. */ | |
3992 | if (warn_aggregate_return | |
3993 | && (TREE_CODE (TREE_TYPE (DECL_RESULT (subr))) == RECORD_TYPE | |
3994 | || TREE_CODE (TREE_TYPE (DECL_RESULT (subr))) == UNION_TYPE | |
3995 | || TREE_CODE (TREE_TYPE (DECL_RESULT (subr))) == ARRAY_TYPE)) | |
3996 | warning ("function returns an aggregate"); | |
3997 | ||
3998 | current_function_returns_pointer | |
3999 | = (TREE_CODE (TREE_TYPE (DECL_RESULT (subr))) == POINTER_TYPE); | |
4000 | ||
4001 | /* Indicate that we need to distinguish between the return value of the | |
4002 | present function and the return value of a function being called. */ | |
4003 | rtx_equal_function_value_matters = 1; | |
4004 | ||
4005 | /* Indicate that we have not instantiated virtual registers yet. */ | |
4006 | virtuals_instantiated = 0; | |
4007 | ||
4008 | /* Indicate we have no need of a frame pointer yet. */ | |
4009 | frame_pointer_needed = 0; | |
4010 | ||
4011 | /* By default assume not varargs. */ | |
4012 | current_function_varargs = 0; | |
4013 | } | |
4014 | ||
4015 | /* Indicate that the current function uses extra args | |
4016 | not explicitly mentioned in the argument list in any fashion. */ | |
4017 | ||
4018 | void | |
4019 | mark_varargs () | |
4020 | { | |
4021 | current_function_varargs = 1; | |
4022 | } | |
4023 | ||
4024 | /* Expand a call to __main at the beginning of a possible main function. */ | |
4025 | ||
4026 | void | |
4027 | expand_main_function () | |
4028 | { | |
b335c2cc | 4029 | #if !defined (INIT_SECTION_ASM_OP) || defined (INVOKE__main) |
6f086dfc RS |
4030 | emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "__main"), 0, |
4031 | VOIDmode, 0); | |
b335c2cc | 4032 | #endif /* not INIT_SECTION_ASM_OP or INVOKE__main */ |
6f086dfc RS |
4033 | } |
4034 | \f | |
4035 | /* Start the RTL for a new function, and set variables used for | |
4036 | emitting RTL. | |
4037 | SUBR is the FUNCTION_DECL node. | |
4038 | PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with | |
4039 | the function's parameters, which must be run at any return statement. */ | |
4040 | ||
4041 | void | |
4042 | expand_function_start (subr, parms_have_cleanups) | |
4043 | tree subr; | |
4044 | int parms_have_cleanups; | |
4045 | { | |
4046 | register int i; | |
4047 | tree tem; | |
4048 | rtx last_ptr; | |
4049 | ||
4050 | /* Make sure volatile mem refs aren't considered | |
4051 | valid operands of arithmetic insns. */ | |
4052 | init_recog_no_volatile (); | |
4053 | ||
4054 | /* If function gets a static chain arg, store it in the stack frame. | |
4055 | Do this first, so it gets the first stack slot offset. */ | |
4056 | if (current_function_needs_context) | |
3e2481e9 JW |
4057 | { |
4058 | last_ptr = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0); | |
4059 | emit_move_insn (last_ptr, static_chain_incoming_rtx); | |
4060 | } | |
6f086dfc RS |
4061 | |
4062 | /* If the parameters of this function need cleaning up, get a label | |
4063 | for the beginning of the code which executes those cleanups. This must | |
4064 | be done before doing anything with return_label. */ | |
4065 | if (parms_have_cleanups) | |
4066 | cleanup_label = gen_label_rtx (); | |
4067 | else | |
4068 | cleanup_label = 0; | |
4069 | ||
4070 | /* Make the label for return statements to jump to, if this machine | |
4071 | does not have a one-instruction return and uses an epilogue, | |
4072 | or if it returns a structure, or if it has parm cleanups. */ | |
4073 | #ifdef HAVE_return | |
4074 | if (cleanup_label == 0 && HAVE_return | |
4075 | && ! current_function_returns_pcc_struct | |
4076 | && ! (current_function_returns_struct && ! optimize)) | |
4077 | return_label = 0; | |
4078 | else | |
4079 | return_label = gen_label_rtx (); | |
4080 | #else | |
4081 | return_label = gen_label_rtx (); | |
4082 | #endif | |
4083 | ||
4084 | /* Initialize rtx used to return the value. */ | |
4085 | /* Do this before assign_parms so that we copy the struct value address | |
4086 | before any library calls that assign parms might generate. */ | |
4087 | ||
4088 | /* Decide whether to return the value in memory or in a register. */ | |
4089 | if (aggregate_value_p (DECL_RESULT (subr))) | |
4090 | { | |
4091 | /* Returning something that won't go in a register. */ | |
4092 | register rtx value_address; | |
4093 | ||
4094 | #ifdef PCC_STATIC_STRUCT_RETURN | |
4095 | if (current_function_returns_pcc_struct) | |
4096 | { | |
4097 | int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr))); | |
4098 | value_address = assemble_static_space (size); | |
4099 | } | |
4100 | else | |
4101 | #endif | |
4102 | { | |
4103 | /* Expect to be passed the address of a place to store the value. | |
4104 | If it is passed as an argument, assign_parms will take care of | |
4105 | it. */ | |
4106 | if (struct_value_incoming_rtx) | |
4107 | { | |
4108 | value_address = gen_reg_rtx (Pmode); | |
4109 | emit_move_insn (value_address, struct_value_incoming_rtx); | |
4110 | } | |
4111 | } | |
4112 | if (value_address) | |
4113 | DECL_RTL (DECL_RESULT (subr)) | |
4114 | = gen_rtx (MEM, DECL_MODE (DECL_RESULT (subr)), | |
4115 | value_address); | |
4116 | } | |
4117 | else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode) | |
4118 | /* If return mode is void, this decl rtl should not be used. */ | |
4119 | DECL_RTL (DECL_RESULT (subr)) = 0; | |
4120 | else if (parms_have_cleanups) | |
a53e14c0 RK |
4121 | { |
4122 | /* If function will end with cleanup code for parms, | |
4123 | compute the return values into a pseudo reg, | |
4124 | which we will copy into the true return register | |
4125 | after the cleanups are done. */ | |
4126 | ||
4127 | enum machine_mode mode = DECL_MODE (DECL_RESULT (subr)); | |
4128 | #ifdef PROMOTE_FUNCTION_RETURN | |
4129 | tree type = TREE_TYPE (DECL_RESULT (subr)); | |
4130 | int unsignedp = TREE_UNSIGNED (type); | |
4131 | ||
4132 | if (TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == ENUMERAL_TYPE | |
4133 | || TREE_CODE (type) == BOOLEAN_TYPE || TREE_CODE (type) == CHAR_TYPE | |
4134 | || TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == POINTER_TYPE | |
4135 | || TREE_CODE (type) == OFFSET_TYPE) | |
4136 | { | |
4137 | PROMOTE_MODE (mode, unsignedp, type); | |
4138 | } | |
4139 | #endif | |
4140 | ||
4141 | DECL_RTL (DECL_RESULT (subr)) = gen_reg_rtx (mode); | |
4142 | } | |
6f086dfc RS |
4143 | else |
4144 | /* Scalar, returned in a register. */ | |
4145 | { | |
4146 | #ifdef FUNCTION_OUTGOING_VALUE | |
4147 | DECL_RTL (DECL_RESULT (subr)) | |
4148 | = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr); | |
4149 | #else | |
4150 | DECL_RTL (DECL_RESULT (subr)) | |
4151 | = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr); | |
4152 | #endif | |
4153 | ||
4154 | /* Mark this reg as the function's return value. */ | |
4155 | if (GET_CODE (DECL_RTL (DECL_RESULT (subr))) == REG) | |
4156 | { | |
4157 | REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr))) = 1; | |
4158 | /* Needed because we may need to move this to memory | |
4159 | in case it's a named return value whose address is taken. */ | |
a82ad570 | 4160 | DECL_REGISTER (DECL_RESULT (subr)) = 1; |
6f086dfc RS |
4161 | } |
4162 | } | |
4163 | ||
4164 | /* Initialize rtx for parameters and local variables. | |
4165 | In some cases this requires emitting insns. */ | |
4166 | ||
4167 | assign_parms (subr, 0); | |
4168 | ||
4169 | /* The following was moved from init_function_start. | |
4170 | The move is supposed to make sdb output more accurate. */ | |
4171 | /* Indicate the beginning of the function body, | |
4172 | as opposed to parm setup. */ | |
5f4f0e22 | 4173 | emit_note (NULL_PTR, NOTE_INSN_FUNCTION_BEG); |
6f086dfc RS |
4174 | |
4175 | /* If doing stupid allocation, mark parms as born here. */ | |
4176 | ||
4177 | if (GET_CODE (get_last_insn ()) != NOTE) | |
5f4f0e22 | 4178 | emit_note (NULL_PTR, NOTE_INSN_DELETED); |
6f086dfc RS |
4179 | parm_birth_insn = get_last_insn (); |
4180 | ||
4181 | if (obey_regdecls) | |
4182 | { | |
4183 | for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++) | |
4184 | use_variable (regno_reg_rtx[i]); | |
4185 | ||
4186 | if (current_function_internal_arg_pointer != virtual_incoming_args_rtx) | |
4187 | use_variable (current_function_internal_arg_pointer); | |
4188 | } | |
4189 | ||
4190 | /* Fetch static chain values for containing functions. */ | |
4191 | tem = decl_function_context (current_function_decl); | |
3e2481e9 JW |
4192 | /* If not doing stupid register allocation, then start off with the static |
4193 | chain pointer in a pseudo register. Otherwise, we use the stack | |
4194 | address that was generated above. */ | |
4195 | if (tem && ! obey_regdecls) | |
6f086dfc RS |
4196 | last_ptr = copy_to_reg (static_chain_incoming_rtx); |
4197 | context_display = 0; | |
4198 | while (tem) | |
4199 | { | |
4200 | tree rtlexp = make_node (RTL_EXPR); | |
4201 | ||
4202 | RTL_EXPR_RTL (rtlexp) = last_ptr; | |
4203 | context_display = tree_cons (tem, rtlexp, context_display); | |
4204 | tem = decl_function_context (tem); | |
4205 | if (tem == 0) | |
4206 | break; | |
4207 | /* Chain thru stack frames, assuming pointer to next lexical frame | |
4208 | is found at the place we always store it. */ | |
4209 | #ifdef FRAME_GROWS_DOWNWARD | |
4210 | last_ptr = plus_constant (last_ptr, - GET_MODE_SIZE (Pmode)); | |
4211 | #endif | |
4212 | last_ptr = copy_to_reg (gen_rtx (MEM, Pmode, | |
4213 | memory_address (Pmode, last_ptr))); | |
4214 | } | |
4215 | ||
4216 | /* After the display initializations is where the tail-recursion label | |
4217 | should go, if we end up needing one. Ensure we have a NOTE here | |
4218 | since some things (like trampolines) get placed before this. */ | |
5f4f0e22 | 4219 | tail_recursion_reentry = emit_note (NULL_PTR, NOTE_INSN_DELETED); |
6f086dfc RS |
4220 | |
4221 | /* Evaluate now the sizes of any types declared among the arguments. */ | |
4222 | for (tem = nreverse (get_pending_sizes ()); tem; tem = TREE_CHAIN (tem)) | |
5f4f0e22 | 4223 | expand_expr (TREE_VALUE (tem), NULL_RTX, VOIDmode, 0); |
6f086dfc RS |
4224 | |
4225 | /* Make sure there is a line number after the function entry setup code. */ | |
4226 | force_next_line_note (); | |
4227 | } | |
4228 | \f | |
4229 | /* Generate RTL for the end of the current function. | |
4230 | FILENAME and LINE are the current position in the source file. */ | |
4231 | ||
4232 | /* It is up to language-specific callers to do cleanups for parameters. */ | |
4233 | ||
4234 | void | |
4235 | expand_function_end (filename, line) | |
4236 | char *filename; | |
4237 | int line; | |
4238 | { | |
4239 | register int i; | |
4240 | tree link; | |
4241 | ||
4242 | static rtx initial_trampoline; | |
4243 | ||
4244 | #ifdef NON_SAVING_SETJMP | |
4245 | /* Don't put any variables in registers if we call setjmp | |
4246 | on a machine that fails to restore the registers. */ | |
4247 | if (NON_SAVING_SETJMP && current_function_calls_setjmp) | |
4248 | { | |
4249 | setjmp_protect (DECL_INITIAL (current_function_decl)); | |
4250 | setjmp_protect_args (); | |
4251 | } | |
4252 | #endif | |
4253 | ||
4254 | /* Save the argument pointer if a save area was made for it. */ | |
4255 | if (arg_pointer_save_area) | |
4256 | { | |
4257 | rtx x = gen_move_insn (arg_pointer_save_area, virtual_incoming_args_rtx); | |
4258 | emit_insn_before (x, tail_recursion_reentry); | |
4259 | } | |
4260 | ||
4261 | /* Initialize any trampolines required by this function. */ | |
4262 | for (link = trampoline_list; link; link = TREE_CHAIN (link)) | |
4263 | { | |
4264 | tree function = TREE_PURPOSE (link); | |
4265 | rtx context = lookup_static_chain (function); | |
4266 | rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link)); | |
4267 | rtx seq; | |
4268 | ||
4269 | /* First make sure this compilation has a template for | |
4270 | initializing trampolines. */ | |
4271 | if (initial_trampoline == 0) | |
86f8eff3 RK |
4272 | { |
4273 | end_temporary_allocation (); | |
4274 | initial_trampoline | |
4275 | = gen_rtx (MEM, BLKmode, assemble_trampoline_template ()); | |
4276 | resume_temporary_allocation (); | |
4277 | } | |
6f086dfc RS |
4278 | |
4279 | /* Generate insns to initialize the trampoline. */ | |
4280 | start_sequence (); | |
4281 | tramp = change_address (initial_trampoline, BLKmode, | |
4282 | round_trampoline_addr (XEXP (tramp, 0))); | |
5f4f0e22 | 4283 | emit_block_move (tramp, initial_trampoline, GEN_INT (TRAMPOLINE_SIZE), |
6f086dfc RS |
4284 | FUNCTION_BOUNDARY / BITS_PER_UNIT); |
4285 | INITIALIZE_TRAMPOLINE (XEXP (tramp, 0), | |
4286 | XEXP (DECL_RTL (function), 0), context); | |
4287 | seq = get_insns (); | |
4288 | end_sequence (); | |
4289 | ||
4290 | /* Put those insns at entry to the containing function (this one). */ | |
4291 | emit_insns_before (seq, tail_recursion_reentry); | |
4292 | } | |
4293 | /* Clear the trampoline_list for the next function. */ | |
4294 | trampoline_list = 0; | |
4295 | ||
4296 | #if 0 /* I think unused parms are legitimate enough. */ | |
4297 | /* Warn about unused parms. */ | |
4298 | if (warn_unused) | |
4299 | { | |
4300 | rtx decl; | |
4301 | ||
4302 | for (decl = DECL_ARGUMENTS (current_function_decl); | |
4303 | decl; decl = TREE_CHAIN (decl)) | |
4304 | if (! TREE_USED (decl) && TREE_CODE (decl) == VAR_DECL) | |
4305 | warning_with_decl (decl, "unused parameter `%s'"); | |
4306 | } | |
4307 | #endif | |
4308 | ||
4309 | /* Delete handlers for nonlocal gotos if nothing uses them. */ | |
4310 | if (nonlocal_goto_handler_slot != 0 && !current_function_has_nonlocal_label) | |
4311 | delete_handlers (); | |
4312 | ||
4313 | /* End any sequences that failed to be closed due to syntax errors. */ | |
4314 | while (in_sequence_p ()) | |
5f4f0e22 | 4315 | end_sequence (); |
6f086dfc RS |
4316 | |
4317 | /* Outside function body, can't compute type's actual size | |
4318 | until next function's body starts. */ | |
4319 | immediate_size_expand--; | |
4320 | ||
4321 | /* If doing stupid register allocation, | |
4322 | mark register parms as dying here. */ | |
4323 | ||
4324 | if (obey_regdecls) | |
4325 | { | |
4326 | rtx tem; | |
4327 | for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++) | |
4328 | use_variable (regno_reg_rtx[i]); | |
4329 | ||
4330 | /* Likewise for the regs of all the SAVE_EXPRs in the function. */ | |
4331 | ||
4332 | for (tem = save_expr_regs; tem; tem = XEXP (tem, 1)) | |
4333 | { | |
4334 | use_variable (XEXP (tem, 0)); | |
4335 | use_variable_after (XEXP (tem, 0), parm_birth_insn); | |
4336 | } | |
4337 | ||
4338 | if (current_function_internal_arg_pointer != virtual_incoming_args_rtx) | |
4339 | use_variable (current_function_internal_arg_pointer); | |
4340 | } | |
4341 | ||
4342 | clear_pending_stack_adjust (); | |
4343 | do_pending_stack_adjust (); | |
4344 | ||
4345 | /* Mark the end of the function body. | |
4346 | If control reaches this insn, the function can drop through | |
4347 | without returning a value. */ | |
5f4f0e22 | 4348 | emit_note (NULL_PTR, NOTE_INSN_FUNCTION_END); |
6f086dfc RS |
4349 | |
4350 | /* Output a linenumber for the end of the function. | |
4351 | SDB depends on this. */ | |
4352 | emit_line_note_force (filename, line); | |
4353 | ||
4354 | /* Output the label for the actual return from the function, | |
4355 | if one is expected. This happens either because a function epilogue | |
4356 | is used instead of a return instruction, or because a return was done | |
4357 | with a goto in order to run local cleanups, or because of pcc-style | |
4358 | structure returning. */ | |
4359 | ||
4360 | if (return_label) | |
4361 | emit_label (return_label); | |
4362 | ||
4363 | /* If we had calls to alloca, and this machine needs | |
4364 | an accurate stack pointer to exit the function, | |
4365 | insert some code to save and restore the stack pointer. */ | |
4366 | #ifdef EXIT_IGNORE_STACK | |
4367 | if (! EXIT_IGNORE_STACK) | |
4368 | #endif | |
4369 | if (current_function_calls_alloca) | |
4370 | { | |
59257ff7 RK |
4371 | rtx tem = 0; |
4372 | ||
4373 | emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn); | |
5f4f0e22 | 4374 | emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX); |
6f086dfc RS |
4375 | } |
4376 | ||
4377 | /* If scalar return value was computed in a pseudo-reg, | |
4378 | copy that to the hard return register. */ | |
4379 | if (DECL_RTL (DECL_RESULT (current_function_decl)) != 0 | |
4380 | && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG | |
4381 | && (REGNO (DECL_RTL (DECL_RESULT (current_function_decl))) | |
4382 | >= FIRST_PSEUDO_REGISTER)) | |
4383 | { | |
4384 | rtx real_decl_result; | |
4385 | ||
4386 | #ifdef FUNCTION_OUTGOING_VALUE | |
4387 | real_decl_result | |
4388 | = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)), | |
4389 | current_function_decl); | |
4390 | #else | |
4391 | real_decl_result | |
4392 | = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)), | |
4393 | current_function_decl); | |
4394 | #endif | |
4395 | REG_FUNCTION_VALUE_P (real_decl_result) = 1; | |
4396 | emit_move_insn (real_decl_result, | |
4397 | DECL_RTL (DECL_RESULT (current_function_decl))); | |
4398 | emit_insn (gen_rtx (USE, VOIDmode, real_decl_result)); | |
4399 | } | |
4400 | ||
4401 | /* If returning a structure, arrange to return the address of the value | |
4402 | in a place where debuggers expect to find it. | |
4403 | ||
4404 | If returning a structure PCC style, | |
4405 | the caller also depends on this value. | |
4406 | And current_function_returns_pcc_struct is not necessarily set. */ | |
4407 | if (current_function_returns_struct | |
4408 | || current_function_returns_pcc_struct) | |
4409 | { | |
4410 | rtx value_address = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0); | |
4411 | tree type = TREE_TYPE (DECL_RESULT (current_function_decl)); | |
4412 | #ifdef FUNCTION_OUTGOING_VALUE | |
4413 | rtx outgoing | |
4414 | = FUNCTION_OUTGOING_VALUE (build_pointer_type (type), | |
4415 | current_function_decl); | |
4416 | #else | |
4417 | rtx outgoing | |
4418 | = FUNCTION_VALUE (build_pointer_type (type), | |
4419 | current_function_decl); | |
4420 | #endif | |
4421 | ||
4422 | /* Mark this as a function return value so integrate will delete the | |
4423 | assignment and USE below when inlining this function. */ | |
4424 | REG_FUNCTION_VALUE_P (outgoing) = 1; | |
4425 | ||
4426 | emit_move_insn (outgoing, value_address); | |
4427 | use_variable (outgoing); | |
4428 | } | |
4429 | ||
4430 | /* Output a return insn if we are using one. | |
4431 | Otherwise, let the rtl chain end here, to drop through | |
4432 | into the epilogue. */ | |
4433 | ||
4434 | #ifdef HAVE_return | |
4435 | if (HAVE_return) | |
4436 | { | |
4437 | emit_jump_insn (gen_return ()); | |
4438 | emit_barrier (); | |
4439 | } | |
4440 | #endif | |
4441 | ||
4442 | /* Fix up any gotos that jumped out to the outermost | |
4443 | binding level of the function. | |
4444 | Must follow emitting RETURN_LABEL. */ | |
4445 | ||
4446 | /* If you have any cleanups to do at this point, | |
4447 | and they need to create temporary variables, | |
4448 | then you will lose. */ | |
5f4f0e22 | 4449 | fixup_gotos (NULL_PTR, NULL_RTX, NULL_TREE, get_insns (), 0); |
6f086dfc | 4450 | } |
bdac5f58 TW |
4451 | \f |
4452 | /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */ | |
4453 | ||
4454 | static int *prologue; | |
4455 | static int *epilogue; | |
4456 | ||
4457 | /* Create an array that records the INSN_UIDs of INSNS (either a sequence | |
4458 | or a single insn). */ | |
4459 | ||
4460 | static int * | |
4461 | record_insns (insns) | |
4462 | rtx insns; | |
4463 | { | |
4464 | int *vec; | |
4465 | ||
4466 | if (GET_CODE (insns) == SEQUENCE) | |
4467 | { | |
4468 | int len = XVECLEN (insns, 0); | |
4469 | vec = (int *) oballoc ((len + 1) * sizeof (int)); | |
4470 | vec[len] = 0; | |
4471 | while (--len >= 0) | |
4472 | vec[len] = INSN_UID (XVECEXP (insns, 0, len)); | |
4473 | } | |
4474 | else | |
4475 | { | |
4476 | vec = (int *) oballoc (2 * sizeof (int)); | |
4477 | vec[0] = INSN_UID (insns); | |
4478 | vec[1] = 0; | |
4479 | } | |
4480 | return vec; | |
4481 | } | |
4482 | ||
10914065 | 4483 | /* Determine how many INSN_UIDs in VEC are part of INSN. */ |
bdac5f58 | 4484 | |
10914065 | 4485 | static int |
bdac5f58 TW |
4486 | contains (insn, vec) |
4487 | rtx insn; | |
4488 | int *vec; | |
4489 | { | |
4490 | register int i, j; | |
4491 | ||
4492 | if (GET_CODE (insn) == INSN | |
4493 | && GET_CODE (PATTERN (insn)) == SEQUENCE) | |
4494 | { | |
10914065 | 4495 | int count = 0; |
bdac5f58 TW |
4496 | for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--) |
4497 | for (j = 0; vec[j]; j++) | |
4498 | if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == vec[j]) | |
10914065 TW |
4499 | count++; |
4500 | return count; | |
bdac5f58 TW |
4501 | } |
4502 | else | |
4503 | { | |
4504 | for (j = 0; vec[j]; j++) | |
4505 | if (INSN_UID (insn) == vec[j]) | |
10914065 | 4506 | return 1; |
bdac5f58 TW |
4507 | } |
4508 | return 0; | |
4509 | } | |
4510 | ||
4511 | /* Generate the prologe and epilogue RTL if the machine supports it. Thread | |
4512 | this into place with notes indicating where the prologue ends and where | |
4513 | the epilogue begins. Update the basic block information when possible. */ | |
4514 | ||
4515 | void | |
4516 | thread_prologue_and_epilogue_insns (f) | |
4517 | rtx f; | |
4518 | { | |
4519 | #ifdef HAVE_prologue | |
4520 | if (HAVE_prologue) | |
4521 | { | |
4522 | rtx head, seq, insn; | |
4523 | ||
4524 | /* The first insn (a NOTE_INSN_DELETED) is followed by zero or more | |
4525 | prologue insns and a NOTE_INSN_PROLOGUE_END. */ | |
4526 | emit_note_after (NOTE_INSN_PROLOGUE_END, f); | |
4527 | seq = gen_prologue (); | |
4528 | head = emit_insn_after (seq, f); | |
4529 | ||
4530 | /* Include the new prologue insns in the first block. Ignore them | |
4531 | if they form a basic block unto themselves. */ | |
4532 | if (basic_block_head && n_basic_blocks | |
4533 | && GET_CODE (basic_block_head[0]) != CODE_LABEL) | |
4534 | basic_block_head[0] = NEXT_INSN (f); | |
4535 | ||
4536 | /* Retain a map of the prologue insns. */ | |
4537 | prologue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : head); | |
4538 | } | |
4539 | else | |
4540 | #endif | |
4541 | prologue = 0; | |
4542 | ||
4543 | #ifdef HAVE_epilogue | |
4544 | if (HAVE_epilogue) | |
4545 | { | |
4546 | rtx insn = get_last_insn (); | |
4547 | rtx prev = prev_nonnote_insn (insn); | |
4548 | ||
4549 | /* If we end with a BARRIER, we don't need an epilogue. */ | |
4550 | if (! (prev && GET_CODE (prev) == BARRIER)) | |
4551 | { | |
4552 | rtx tail, seq; | |
4553 | ||
4554 | /* The last basic block ends with a NOTE_INSN_EPILOGUE_BEG, | |
4555 | the epilogue insns (this must include the jump insn that | |
4556 | returns), USE insns ad the end of a function, and a BARRIER. */ | |
4557 | ||
4558 | emit_barrier_after (insn); | |
4559 | ||
4560 | /* Place the epilogue before the USE insns at the end of a | |
4561 | function. */ | |
4562 | while (prev | |
4563 | && GET_CODE (prev) == INSN | |
4564 | && GET_CODE (PATTERN (prev)) == USE) | |
4565 | { | |
4566 | insn = PREV_INSN (prev); | |
4567 | prev = prev_nonnote_insn (prev); | |
4568 | } | |
4569 | ||
4570 | seq = gen_epilogue (); | |
4571 | tail = emit_jump_insn_after (seq, insn); | |
4572 | emit_note_after (NOTE_INSN_EPILOGUE_BEG, insn); | |
4573 | ||
4574 | /* Include the new epilogue insns in the last block. Ignore | |
4575 | them if they form a basic block unto themselves. */ | |
4576 | if (basic_block_end && n_basic_blocks | |
4577 | && GET_CODE (basic_block_end[n_basic_blocks - 1]) != JUMP_INSN) | |
4578 | basic_block_end[n_basic_blocks - 1] = tail; | |
4579 | ||
4580 | /* Retain a map of the epilogue insns. */ | |
4581 | epilogue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : tail); | |
4582 | return; | |
4583 | } | |
4584 | } | |
4585 | #endif | |
4586 | epilogue = 0; | |
4587 | } | |
4588 | ||
4589 | /* Reposition the prologue-end and epilogue-begin notes after instruction | |
4590 | scheduling and delayed branch scheduling. */ | |
4591 | ||
4592 | void | |
4593 | reposition_prologue_and_epilogue_notes (f) | |
4594 | rtx f; | |
4595 | { | |
4596 | #if defined (HAVE_prologue) || defined (HAVE_epilogue) | |
4597 | /* Reposition the prologue and epilogue notes. */ | |
4598 | if (n_basic_blocks) | |
4599 | { | |
4600 | rtx next, prev; | |
bf526252 | 4601 | int len; |
bdac5f58 TW |
4602 | |
4603 | if (prologue) | |
4604 | { | |
bf526252 RK |
4605 | register rtx insn, note = 0; |
4606 | ||
4607 | /* Scan from the beginning until we reach the last prologue insn. | |
4608 | We apparently can't depend on basic_block_{head,end} after | |
4609 | reorg has run. */ | |
4610 | for (len = 0; prologue[len]; len++) | |
4611 | ; | |
4612 | for (insn = f; insn; insn = NEXT_INSN (insn)) | |
4613 | if (GET_CODE (insn) == NOTE) | |
4614 | { | |
4615 | if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END) | |
4616 | note = insn; | |
4617 | } | |
10914065 | 4618 | else if ((len -= contains (insn, prologue)) == 0) |
bdac5f58 | 4619 | { |
bf526252 RK |
4620 | /* Find the prologue-end note if we haven't already, and |
4621 | move it to just after the last prologue insn. */ | |
4622 | if (note == 0) | |
4623 | for (note = insn; note = NEXT_INSN (note);) | |
4624 | if (GET_CODE (note) == NOTE | |
4625 | && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END) | |
4626 | break; | |
4627 | next = NEXT_INSN (note); | |
4628 | prev = PREV_INSN (note); | |
bdac5f58 TW |
4629 | if (prev) |
4630 | NEXT_INSN (prev) = next; | |
4631 | if (next) | |
4632 | PREV_INSN (next) = prev; | |
bf526252 | 4633 | add_insn_after (note, insn); |
bdac5f58 TW |
4634 | break; |
4635 | } | |
4636 | } | |
4637 | ||
4638 | if (epilogue) | |
4639 | { | |
bf526252 RK |
4640 | register rtx insn, note = 0; |
4641 | ||
4642 | /* Scan from the end until we reach the first epilogue insn. | |
4643 | We apparently can't depend on basic_block_{head,end} after | |
4644 | reorg has run. */ | |
4645 | for (len = 0; epilogue[len]; len++) | |
4646 | ; | |
4647 | for (insn = get_last_insn (); insn; insn = PREV_INSN (insn)) | |
4648 | if (GET_CODE (insn) == NOTE) | |
4649 | { | |
4650 | if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG) | |
4651 | note = insn; | |
4652 | } | |
10914065 | 4653 | else if ((len -= contains (insn, epilogue)) == 0) |
bdac5f58 | 4654 | { |
bf526252 RK |
4655 | /* Find the epilogue-begin note if we haven't already, and |
4656 | move it to just before the first epilogue insn. */ | |
4657 | if (note == 0) | |
4658 | for (note = insn; note = PREV_INSN (note);) | |
4659 | if (GET_CODE (note) == NOTE | |
4660 | && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG) | |
4661 | break; | |
4662 | next = NEXT_INSN (note); | |
4663 | prev = PREV_INSN (note); | |
bdac5f58 TW |
4664 | if (prev) |
4665 | NEXT_INSN (prev) = next; | |
4666 | if (next) | |
4667 | PREV_INSN (next) = prev; | |
bf526252 | 4668 | add_insn_after (note, PREV_INSN (insn)); |
bdac5f58 TW |
4669 | break; |
4670 | } | |
4671 | } | |
4672 | } | |
4673 | #endif /* HAVE_prologue or HAVE_epilogue */ | |
4674 | } |