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