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