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