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