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