Improve scheduler dumps of ready list
[gcc.git] / gcc / function.c
1 /* Expands front end tree to back end RTL for GCC.
2 Copyright (C) 1987-2014 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
10
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
19
20 /* This file handles the generation of rtl code from tree structure
21 at the level of the function as a whole.
22 It creates the rtl expressions for parameters and auto variables
23 and has full responsibility for allocating stack slots.
24
25 `expand_function_start' is called at the beginning of a function,
26 before the function body is parsed, and `expand_function_end' is
27 called after parsing the body.
28
29 Call `assign_stack_local' to allocate a stack slot for a local variable.
30 This is usually done during the RTL generation for the function body,
31 but it can also be done in the reload pass when a pseudo-register does
32 not get a hard register. */
33
34 #include "config.h"
35 #include "system.h"
36 #include "coretypes.h"
37 #include "tm.h"
38 #include "rtl-error.h"
39 #include "tree.h"
40 #include "stor-layout.h"
41 #include "varasm.h"
42 #include "stringpool.h"
43 #include "flags.h"
44 #include "except.h"
45 #include "hashtab.h"
46 #include "hash-set.h"
47 #include "vec.h"
48 #include "machmode.h"
49 #include "hard-reg-set.h"
50 #include "input.h"
51 #include "function.h"
52 #include "expr.h"
53 #include "optabs.h"
54 #include "libfuncs.h"
55 #include "regs.h"
56 #include "insn-config.h"
57 #include "recog.h"
58 #include "output.h"
59 #include "tm_p.h"
60 #include "langhooks.h"
61 #include "target.h"
62 #include "common/common-target.h"
63 #include "gimple-expr.h"
64 #include "gimplify.h"
65 #include "tree-pass.h"
66 #include "predict.h"
67 #include "df.h"
68 #include "params.h"
69 #include "bb-reorder.h"
70 #include "shrink-wrap.h"
71 #include "toplev.h"
72 #include "rtl-iter.h"
73
74 /* So we can assign to cfun in this file. */
75 #undef cfun
76
77 #ifndef STACK_ALIGNMENT_NEEDED
78 #define STACK_ALIGNMENT_NEEDED 1
79 #endif
80
81 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
82
83 /* Round a value to the lowest integer less than it that is a multiple of
84 the required alignment. Avoid using division in case the value is
85 negative. Assume the alignment is a power of two. */
86 #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
87
88 /* Similar, but round to the next highest integer that meets the
89 alignment. */
90 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
91
92 /* Nonzero once virtual register instantiation has been done.
93 assign_stack_local uses frame_pointer_rtx when this is nonzero.
94 calls.c:emit_library_call_value_1 uses it to set up
95 post-instantiation libcalls. */
96 int virtuals_instantiated;
97
98 /* Assign unique numbers to labels generated for profiling, debugging, etc. */
99 static GTY(()) int funcdef_no;
100
101 /* These variables hold pointers to functions to create and destroy
102 target specific, per-function data structures. */
103 struct machine_function * (*init_machine_status) (void);
104
105 /* The currently compiled function. */
106 struct function *cfun = 0;
107
108 /* These hashes record the prologue and epilogue insns. */
109 static GTY((if_marked ("ggc_marked_p"), param_is (struct rtx_def)))
110 htab_t prologue_insn_hash;
111 static GTY((if_marked ("ggc_marked_p"), param_is (struct rtx_def)))
112 htab_t epilogue_insn_hash;
113 \f
114
115 hash_table<used_type_hasher> *types_used_by_vars_hash = NULL;
116 vec<tree, va_gc> *types_used_by_cur_var_decl;
117
118 /* Forward declarations. */
119
120 static struct temp_slot *find_temp_slot_from_address (rtx);
121 static void pad_to_arg_alignment (struct args_size *, int, struct args_size *);
122 static void pad_below (struct args_size *, enum machine_mode, tree);
123 static void reorder_blocks_1 (rtx_insn *, tree, vec<tree> *);
124 static int all_blocks (tree, tree *);
125 static tree *get_block_vector (tree, int *);
126 extern tree debug_find_var_in_block_tree (tree, tree);
127 /* We always define `record_insns' even if it's not used so that we
128 can always export `prologue_epilogue_contains'. */
129 static void record_insns (rtx_insn *, rtx, htab_t *) ATTRIBUTE_UNUSED;
130 static bool contains (const_rtx, htab_t);
131 static void prepare_function_start (void);
132 static void do_clobber_return_reg (rtx, void *);
133 static void do_use_return_reg (rtx, void *);
134 \f
135 /* Stack of nested functions. */
136 /* Keep track of the cfun stack. */
137
138 typedef struct function *function_p;
139
140 static vec<function_p> function_context_stack;
141
142 /* Save the current context for compilation of a nested function.
143 This is called from language-specific code. */
144
145 void
146 push_function_context (void)
147 {
148 if (cfun == 0)
149 allocate_struct_function (NULL, false);
150
151 function_context_stack.safe_push (cfun);
152 set_cfun (NULL);
153 }
154
155 /* Restore the last saved context, at the end of a nested function.
156 This function is called from language-specific code. */
157
158 void
159 pop_function_context (void)
160 {
161 struct function *p = function_context_stack.pop ();
162 set_cfun (p);
163 current_function_decl = p->decl;
164
165 /* Reset variables that have known state during rtx generation. */
166 virtuals_instantiated = 0;
167 generating_concat_p = 1;
168 }
169
170 /* Clear out all parts of the state in F that can safely be discarded
171 after the function has been parsed, but not compiled, to let
172 garbage collection reclaim the memory. */
173
174 void
175 free_after_parsing (struct function *f)
176 {
177 f->language = 0;
178 }
179
180 /* Clear out all parts of the state in F that can safely be discarded
181 after the function has been compiled, to let garbage collection
182 reclaim the memory. */
183
184 void
185 free_after_compilation (struct function *f)
186 {
187 prologue_insn_hash = NULL;
188 epilogue_insn_hash = NULL;
189
190 free (crtl->emit.regno_pointer_align);
191
192 memset (crtl, 0, sizeof (struct rtl_data));
193 f->eh = NULL;
194 f->machine = NULL;
195 f->cfg = NULL;
196
197 regno_reg_rtx = NULL;
198 }
199 \f
200 /* Return size needed for stack frame based on slots so far allocated.
201 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
202 the caller may have to do that. */
203
204 HOST_WIDE_INT
205 get_frame_size (void)
206 {
207 if (FRAME_GROWS_DOWNWARD)
208 return -frame_offset;
209 else
210 return frame_offset;
211 }
212
213 /* Issue an error message and return TRUE if frame OFFSET overflows in
214 the signed target pointer arithmetics for function FUNC. Otherwise
215 return FALSE. */
216
217 bool
218 frame_offset_overflow (HOST_WIDE_INT offset, tree func)
219 {
220 unsigned HOST_WIDE_INT size = FRAME_GROWS_DOWNWARD ? -offset : offset;
221
222 if (size > ((unsigned HOST_WIDE_INT) 1 << (GET_MODE_BITSIZE (Pmode) - 1))
223 /* Leave room for the fixed part of the frame. */
224 - 64 * UNITS_PER_WORD)
225 {
226 error_at (DECL_SOURCE_LOCATION (func),
227 "total size of local objects too large");
228 return TRUE;
229 }
230
231 return FALSE;
232 }
233
234 /* Return stack slot alignment in bits for TYPE and MODE. */
235
236 static unsigned int
237 get_stack_local_alignment (tree type, enum machine_mode mode)
238 {
239 unsigned int alignment;
240
241 if (mode == BLKmode)
242 alignment = BIGGEST_ALIGNMENT;
243 else
244 alignment = GET_MODE_ALIGNMENT (mode);
245
246 /* Allow the frond-end to (possibly) increase the alignment of this
247 stack slot. */
248 if (! type)
249 type = lang_hooks.types.type_for_mode (mode, 0);
250
251 return STACK_SLOT_ALIGNMENT (type, mode, alignment);
252 }
253
254 /* Determine whether it is possible to fit a stack slot of size SIZE and
255 alignment ALIGNMENT into an area in the stack frame that starts at
256 frame offset START and has a length of LENGTH. If so, store the frame
257 offset to be used for the stack slot in *POFFSET and return true;
258 return false otherwise. This function will extend the frame size when
259 given a start/length pair that lies at the end of the frame. */
260
261 static bool
262 try_fit_stack_local (HOST_WIDE_INT start, HOST_WIDE_INT length,
263 HOST_WIDE_INT size, unsigned int alignment,
264 HOST_WIDE_INT *poffset)
265 {
266 HOST_WIDE_INT this_frame_offset;
267 int frame_off, frame_alignment, frame_phase;
268
269 /* Calculate how many bytes the start of local variables is off from
270 stack alignment. */
271 frame_alignment = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
272 frame_off = STARTING_FRAME_OFFSET % frame_alignment;
273 frame_phase = frame_off ? frame_alignment - frame_off : 0;
274
275 /* Round the frame offset to the specified alignment. */
276
277 /* We must be careful here, since FRAME_OFFSET might be negative and
278 division with a negative dividend isn't as well defined as we might
279 like. So we instead assume that ALIGNMENT is a power of two and
280 use logical operations which are unambiguous. */
281 if (FRAME_GROWS_DOWNWARD)
282 this_frame_offset
283 = (FLOOR_ROUND (start + length - size - frame_phase,
284 (unsigned HOST_WIDE_INT) alignment)
285 + frame_phase);
286 else
287 this_frame_offset
288 = (CEIL_ROUND (start - frame_phase,
289 (unsigned HOST_WIDE_INT) alignment)
290 + frame_phase);
291
292 /* See if it fits. If this space is at the edge of the frame,
293 consider extending the frame to make it fit. Our caller relies on
294 this when allocating a new slot. */
295 if (frame_offset == start && this_frame_offset < frame_offset)
296 frame_offset = this_frame_offset;
297 else if (this_frame_offset < start)
298 return false;
299 else if (start + length == frame_offset
300 && this_frame_offset + size > start + length)
301 frame_offset = this_frame_offset + size;
302 else if (this_frame_offset + size > start + length)
303 return false;
304
305 *poffset = this_frame_offset;
306 return true;
307 }
308
309 /* Create a new frame_space structure describing free space in the stack
310 frame beginning at START and ending at END, and chain it into the
311 function's frame_space_list. */
312
313 static void
314 add_frame_space (HOST_WIDE_INT start, HOST_WIDE_INT end)
315 {
316 struct frame_space *space = ggc_alloc<frame_space> ();
317 space->next = crtl->frame_space_list;
318 crtl->frame_space_list = space;
319 space->start = start;
320 space->length = end - start;
321 }
322
323 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
324 with machine mode MODE.
325
326 ALIGN controls the amount of alignment for the address of the slot:
327 0 means according to MODE,
328 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
329 -2 means use BITS_PER_UNIT,
330 positive specifies alignment boundary in bits.
331
332 KIND has ASLK_REDUCE_ALIGN bit set if it is OK to reduce
333 alignment and ASLK_RECORD_PAD bit set if we should remember
334 extra space we allocated for alignment purposes. When we are
335 called from assign_stack_temp_for_type, it is not set so we don't
336 track the same stack slot in two independent lists.
337
338 We do not round to stack_boundary here. */
339
340 rtx
341 assign_stack_local_1 (enum machine_mode mode, HOST_WIDE_INT size,
342 int align, int kind)
343 {
344 rtx x, addr;
345 int bigend_correction = 0;
346 HOST_WIDE_INT slot_offset = 0, old_frame_offset;
347 unsigned int alignment, alignment_in_bits;
348
349 if (align == 0)
350 {
351 alignment = get_stack_local_alignment (NULL, mode);
352 alignment /= BITS_PER_UNIT;
353 }
354 else if (align == -1)
355 {
356 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
357 size = CEIL_ROUND (size, alignment);
358 }
359 else if (align == -2)
360 alignment = 1; /* BITS_PER_UNIT / BITS_PER_UNIT */
361 else
362 alignment = align / BITS_PER_UNIT;
363
364 alignment_in_bits = alignment * BITS_PER_UNIT;
365
366 /* Ignore alignment if it exceeds MAX_SUPPORTED_STACK_ALIGNMENT. */
367 if (alignment_in_bits > MAX_SUPPORTED_STACK_ALIGNMENT)
368 {
369 alignment_in_bits = MAX_SUPPORTED_STACK_ALIGNMENT;
370 alignment = alignment_in_bits / BITS_PER_UNIT;
371 }
372
373 if (SUPPORTS_STACK_ALIGNMENT)
374 {
375 if (crtl->stack_alignment_estimated < alignment_in_bits)
376 {
377 if (!crtl->stack_realign_processed)
378 crtl->stack_alignment_estimated = alignment_in_bits;
379 else
380 {
381 /* If stack is realigned and stack alignment value
382 hasn't been finalized, it is OK not to increase
383 stack_alignment_estimated. The bigger alignment
384 requirement is recorded in stack_alignment_needed
385 below. */
386 gcc_assert (!crtl->stack_realign_finalized);
387 if (!crtl->stack_realign_needed)
388 {
389 /* It is OK to reduce the alignment as long as the
390 requested size is 0 or the estimated stack
391 alignment >= mode alignment. */
392 gcc_assert ((kind & ASLK_REDUCE_ALIGN)
393 || size == 0
394 || (crtl->stack_alignment_estimated
395 >= GET_MODE_ALIGNMENT (mode)));
396 alignment_in_bits = crtl->stack_alignment_estimated;
397 alignment = alignment_in_bits / BITS_PER_UNIT;
398 }
399 }
400 }
401 }
402
403 if (crtl->stack_alignment_needed < alignment_in_bits)
404 crtl->stack_alignment_needed = alignment_in_bits;
405 if (crtl->max_used_stack_slot_alignment < alignment_in_bits)
406 crtl->max_used_stack_slot_alignment = alignment_in_bits;
407
408 if (mode != BLKmode || size != 0)
409 {
410 if (kind & ASLK_RECORD_PAD)
411 {
412 struct frame_space **psp;
413
414 for (psp = &crtl->frame_space_list; *psp; psp = &(*psp)->next)
415 {
416 struct frame_space *space = *psp;
417 if (!try_fit_stack_local (space->start, space->length, size,
418 alignment, &slot_offset))
419 continue;
420 *psp = space->next;
421 if (slot_offset > space->start)
422 add_frame_space (space->start, slot_offset);
423 if (slot_offset + size < space->start + space->length)
424 add_frame_space (slot_offset + size,
425 space->start + space->length);
426 goto found_space;
427 }
428 }
429 }
430 else if (!STACK_ALIGNMENT_NEEDED)
431 {
432 slot_offset = frame_offset;
433 goto found_space;
434 }
435
436 old_frame_offset = frame_offset;
437
438 if (FRAME_GROWS_DOWNWARD)
439 {
440 frame_offset -= size;
441 try_fit_stack_local (frame_offset, size, size, alignment, &slot_offset);
442
443 if (kind & ASLK_RECORD_PAD)
444 {
445 if (slot_offset > frame_offset)
446 add_frame_space (frame_offset, slot_offset);
447 if (slot_offset + size < old_frame_offset)
448 add_frame_space (slot_offset + size, old_frame_offset);
449 }
450 }
451 else
452 {
453 frame_offset += size;
454 try_fit_stack_local (old_frame_offset, size, size, alignment, &slot_offset);
455
456 if (kind & ASLK_RECORD_PAD)
457 {
458 if (slot_offset > old_frame_offset)
459 add_frame_space (old_frame_offset, slot_offset);
460 if (slot_offset + size < frame_offset)
461 add_frame_space (slot_offset + size, frame_offset);
462 }
463 }
464
465 found_space:
466 /* On a big-endian machine, if we are allocating more space than we will use,
467 use the least significant bytes of those that are allocated. */
468 if (BYTES_BIG_ENDIAN && mode != BLKmode && GET_MODE_SIZE (mode) < size)
469 bigend_correction = size - GET_MODE_SIZE (mode);
470
471 /* If we have already instantiated virtual registers, return the actual
472 address relative to the frame pointer. */
473 if (virtuals_instantiated)
474 addr = plus_constant (Pmode, frame_pointer_rtx,
475 trunc_int_for_mode
476 (slot_offset + bigend_correction
477 + STARTING_FRAME_OFFSET, Pmode));
478 else
479 addr = plus_constant (Pmode, virtual_stack_vars_rtx,
480 trunc_int_for_mode
481 (slot_offset + bigend_correction,
482 Pmode));
483
484 x = gen_rtx_MEM (mode, addr);
485 set_mem_align (x, alignment_in_bits);
486 MEM_NOTRAP_P (x) = 1;
487
488 stack_slot_list
489 = gen_rtx_EXPR_LIST (VOIDmode, x, stack_slot_list);
490
491 if (frame_offset_overflow (frame_offset, current_function_decl))
492 frame_offset = 0;
493
494 return x;
495 }
496
497 /* Wrap up assign_stack_local_1 with last parameter as false. */
498
499 rtx
500 assign_stack_local (enum machine_mode mode, HOST_WIDE_INT size, int align)
501 {
502 return assign_stack_local_1 (mode, size, align, ASLK_RECORD_PAD);
503 }
504 \f
505 /* In order to evaluate some expressions, such as function calls returning
506 structures in memory, we need to temporarily allocate stack locations.
507 We record each allocated temporary in the following structure.
508
509 Associated with each temporary slot is a nesting level. When we pop up
510 one level, all temporaries associated with the previous level are freed.
511 Normally, all temporaries are freed after the execution of the statement
512 in which they were created. However, if we are inside a ({...}) grouping,
513 the result may be in a temporary and hence must be preserved. If the
514 result could be in a temporary, we preserve it if we can determine which
515 one it is in. If we cannot determine which temporary may contain the
516 result, all temporaries are preserved. A temporary is preserved by
517 pretending it was allocated at the previous nesting level. */
518
519 struct GTY(()) temp_slot {
520 /* Points to next temporary slot. */
521 struct temp_slot *next;
522 /* Points to previous temporary slot. */
523 struct temp_slot *prev;
524 /* The rtx to used to reference the slot. */
525 rtx slot;
526 /* The size, in units, of the slot. */
527 HOST_WIDE_INT size;
528 /* The type of the object in the slot, or zero if it doesn't correspond
529 to a type. We use this to determine whether a slot can be reused.
530 It can be reused if objects of the type of the new slot will always
531 conflict with objects of the type of the old slot. */
532 tree type;
533 /* The alignment (in bits) of the slot. */
534 unsigned int align;
535 /* Nonzero if this temporary is currently in use. */
536 char in_use;
537 /* Nesting level at which this slot is being used. */
538 int level;
539 /* The offset of the slot from the frame_pointer, including extra space
540 for alignment. This info is for combine_temp_slots. */
541 HOST_WIDE_INT base_offset;
542 /* The size of the slot, including extra space for alignment. This
543 info is for combine_temp_slots. */
544 HOST_WIDE_INT full_size;
545 };
546
547 /* Entry for the below hash table. */
548 struct GTY((for_user)) temp_slot_address_entry {
549 hashval_t hash;
550 rtx address;
551 struct temp_slot *temp_slot;
552 };
553
554 struct temp_address_hasher : ggc_hasher<temp_slot_address_entry *>
555 {
556 static hashval_t hash (temp_slot_address_entry *);
557 static bool equal (temp_slot_address_entry *, temp_slot_address_entry *);
558 };
559
560 /* A table of addresses that represent a stack slot. The table is a mapping
561 from address RTXen to a temp slot. */
562 static GTY(()) hash_table<temp_address_hasher> *temp_slot_address_table;
563 static size_t n_temp_slots_in_use;
564
565 /* Removes temporary slot TEMP from LIST. */
566
567 static void
568 cut_slot_from_list (struct temp_slot *temp, struct temp_slot **list)
569 {
570 if (temp->next)
571 temp->next->prev = temp->prev;
572 if (temp->prev)
573 temp->prev->next = temp->next;
574 else
575 *list = temp->next;
576
577 temp->prev = temp->next = NULL;
578 }
579
580 /* Inserts temporary slot TEMP to LIST. */
581
582 static void
583 insert_slot_to_list (struct temp_slot *temp, struct temp_slot **list)
584 {
585 temp->next = *list;
586 if (*list)
587 (*list)->prev = temp;
588 temp->prev = NULL;
589 *list = temp;
590 }
591
592 /* Returns the list of used temp slots at LEVEL. */
593
594 static struct temp_slot **
595 temp_slots_at_level (int level)
596 {
597 if (level >= (int) vec_safe_length (used_temp_slots))
598 vec_safe_grow_cleared (used_temp_slots, level + 1);
599
600 return &(*used_temp_slots)[level];
601 }
602
603 /* Returns the maximal temporary slot level. */
604
605 static int
606 max_slot_level (void)
607 {
608 if (!used_temp_slots)
609 return -1;
610
611 return used_temp_slots->length () - 1;
612 }
613
614 /* Moves temporary slot TEMP to LEVEL. */
615
616 static void
617 move_slot_to_level (struct temp_slot *temp, int level)
618 {
619 cut_slot_from_list (temp, temp_slots_at_level (temp->level));
620 insert_slot_to_list (temp, temp_slots_at_level (level));
621 temp->level = level;
622 }
623
624 /* Make temporary slot TEMP available. */
625
626 static void
627 make_slot_available (struct temp_slot *temp)
628 {
629 cut_slot_from_list (temp, temp_slots_at_level (temp->level));
630 insert_slot_to_list (temp, &avail_temp_slots);
631 temp->in_use = 0;
632 temp->level = -1;
633 n_temp_slots_in_use--;
634 }
635
636 /* Compute the hash value for an address -> temp slot mapping.
637 The value is cached on the mapping entry. */
638 static hashval_t
639 temp_slot_address_compute_hash (struct temp_slot_address_entry *t)
640 {
641 int do_not_record = 0;
642 return hash_rtx (t->address, GET_MODE (t->address),
643 &do_not_record, NULL, false);
644 }
645
646 /* Return the hash value for an address -> temp slot mapping. */
647 hashval_t
648 temp_address_hasher::hash (temp_slot_address_entry *t)
649 {
650 return t->hash;
651 }
652
653 /* Compare two address -> temp slot mapping entries. */
654 bool
655 temp_address_hasher::equal (temp_slot_address_entry *t1,
656 temp_slot_address_entry *t2)
657 {
658 return exp_equiv_p (t1->address, t2->address, 0, true);
659 }
660
661 /* Add ADDRESS as an alias of TEMP_SLOT to the addess -> temp slot mapping. */
662 static void
663 insert_temp_slot_address (rtx address, struct temp_slot *temp_slot)
664 {
665 struct temp_slot_address_entry *t = ggc_alloc<temp_slot_address_entry> ();
666 t->address = address;
667 t->temp_slot = temp_slot;
668 t->hash = temp_slot_address_compute_hash (t);
669 *temp_slot_address_table->find_slot_with_hash (t, t->hash, INSERT) = t;
670 }
671
672 /* Remove an address -> temp slot mapping entry if the temp slot is
673 not in use anymore. Callback for remove_unused_temp_slot_addresses. */
674 int
675 remove_unused_temp_slot_addresses_1 (temp_slot_address_entry **slot, void *)
676 {
677 const struct temp_slot_address_entry *t = *slot;
678 if (! t->temp_slot->in_use)
679 temp_slot_address_table->clear_slot (slot);
680 return 1;
681 }
682
683 /* Remove all mappings of addresses to unused temp slots. */
684 static void
685 remove_unused_temp_slot_addresses (void)
686 {
687 /* Use quicker clearing if there aren't any active temp slots. */
688 if (n_temp_slots_in_use)
689 temp_slot_address_table->traverse
690 <void *, remove_unused_temp_slot_addresses_1> (NULL);
691 else
692 temp_slot_address_table->empty ();
693 }
694
695 /* Find the temp slot corresponding to the object at address X. */
696
697 static struct temp_slot *
698 find_temp_slot_from_address (rtx x)
699 {
700 struct temp_slot *p;
701 struct temp_slot_address_entry tmp, *t;
702
703 /* First try the easy way:
704 See if X exists in the address -> temp slot mapping. */
705 tmp.address = x;
706 tmp.temp_slot = NULL;
707 tmp.hash = temp_slot_address_compute_hash (&tmp);
708 t = temp_slot_address_table->find_with_hash (&tmp, tmp.hash);
709 if (t)
710 return t->temp_slot;
711
712 /* If we have a sum involving a register, see if it points to a temp
713 slot. */
714 if (GET_CODE (x) == PLUS && REG_P (XEXP (x, 0))
715 && (p = find_temp_slot_from_address (XEXP (x, 0))) != 0)
716 return p;
717 else if (GET_CODE (x) == PLUS && REG_P (XEXP (x, 1))
718 && (p = find_temp_slot_from_address (XEXP (x, 1))) != 0)
719 return p;
720
721 /* Last resort: Address is a virtual stack var address. */
722 if (GET_CODE (x) == PLUS
723 && XEXP (x, 0) == virtual_stack_vars_rtx
724 && CONST_INT_P (XEXP (x, 1)))
725 {
726 int i;
727 for (i = max_slot_level (); i >= 0; i--)
728 for (p = *temp_slots_at_level (i); p; p = p->next)
729 {
730 if (INTVAL (XEXP (x, 1)) >= p->base_offset
731 && INTVAL (XEXP (x, 1)) < p->base_offset + p->full_size)
732 return p;
733 }
734 }
735
736 return NULL;
737 }
738 \f
739 /* Allocate a temporary stack slot and record it for possible later
740 reuse.
741
742 MODE is the machine mode to be given to the returned rtx.
743
744 SIZE is the size in units of the space required. We do no rounding here
745 since assign_stack_local will do any required rounding.
746
747 TYPE is the type that will be used for the stack slot. */
748
749 rtx
750 assign_stack_temp_for_type (enum machine_mode mode, HOST_WIDE_INT size,
751 tree type)
752 {
753 unsigned int align;
754 struct temp_slot *p, *best_p = 0, *selected = NULL, **pp;
755 rtx slot;
756
757 /* If SIZE is -1 it means that somebody tried to allocate a temporary
758 of a variable size. */
759 gcc_assert (size != -1);
760
761 align = get_stack_local_alignment (type, mode);
762
763 /* Try to find an available, already-allocated temporary of the proper
764 mode which meets the size and alignment requirements. Choose the
765 smallest one with the closest alignment.
766
767 If assign_stack_temp is called outside of the tree->rtl expansion,
768 we cannot reuse the stack slots (that may still refer to
769 VIRTUAL_STACK_VARS_REGNUM). */
770 if (!virtuals_instantiated)
771 {
772 for (p = avail_temp_slots; p; p = p->next)
773 {
774 if (p->align >= align && p->size >= size
775 && GET_MODE (p->slot) == mode
776 && objects_must_conflict_p (p->type, type)
777 && (best_p == 0 || best_p->size > p->size
778 || (best_p->size == p->size && best_p->align > p->align)))
779 {
780 if (p->align == align && p->size == size)
781 {
782 selected = p;
783 cut_slot_from_list (selected, &avail_temp_slots);
784 best_p = 0;
785 break;
786 }
787 best_p = p;
788 }
789 }
790 }
791
792 /* Make our best, if any, the one to use. */
793 if (best_p)
794 {
795 selected = best_p;
796 cut_slot_from_list (selected, &avail_temp_slots);
797
798 /* If there are enough aligned bytes left over, make them into a new
799 temp_slot so that the extra bytes don't get wasted. Do this only
800 for BLKmode slots, so that we can be sure of the alignment. */
801 if (GET_MODE (best_p->slot) == BLKmode)
802 {
803 int alignment = best_p->align / BITS_PER_UNIT;
804 HOST_WIDE_INT rounded_size = CEIL_ROUND (size, alignment);
805
806 if (best_p->size - rounded_size >= alignment)
807 {
808 p = ggc_alloc<temp_slot> ();
809 p->in_use = 0;
810 p->size = best_p->size - rounded_size;
811 p->base_offset = best_p->base_offset + rounded_size;
812 p->full_size = best_p->full_size - rounded_size;
813 p->slot = adjust_address_nv (best_p->slot, BLKmode, rounded_size);
814 p->align = best_p->align;
815 p->type = best_p->type;
816 insert_slot_to_list (p, &avail_temp_slots);
817
818 stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, p->slot,
819 stack_slot_list);
820
821 best_p->size = rounded_size;
822 best_p->full_size = rounded_size;
823 }
824 }
825 }
826
827 /* If we still didn't find one, make a new temporary. */
828 if (selected == 0)
829 {
830 HOST_WIDE_INT frame_offset_old = frame_offset;
831
832 p = ggc_alloc<temp_slot> ();
833
834 /* We are passing an explicit alignment request to assign_stack_local.
835 One side effect of that is assign_stack_local will not round SIZE
836 to ensure the frame offset remains suitably aligned.
837
838 So for requests which depended on the rounding of SIZE, we go ahead
839 and round it now. We also make sure ALIGNMENT is at least
840 BIGGEST_ALIGNMENT. */
841 gcc_assert (mode != BLKmode || align == BIGGEST_ALIGNMENT);
842 p->slot = assign_stack_local_1 (mode,
843 (mode == BLKmode
844 ? CEIL_ROUND (size,
845 (int) align
846 / BITS_PER_UNIT)
847 : size),
848 align, 0);
849
850 p->align = align;
851
852 /* The following slot size computation is necessary because we don't
853 know the actual size of the temporary slot until assign_stack_local
854 has performed all the frame alignment and size rounding for the
855 requested temporary. Note that extra space added for alignment
856 can be either above or below this stack slot depending on which
857 way the frame grows. We include the extra space if and only if it
858 is above this slot. */
859 if (FRAME_GROWS_DOWNWARD)
860 p->size = frame_offset_old - frame_offset;
861 else
862 p->size = size;
863
864 /* Now define the fields used by combine_temp_slots. */
865 if (FRAME_GROWS_DOWNWARD)
866 {
867 p->base_offset = frame_offset;
868 p->full_size = frame_offset_old - frame_offset;
869 }
870 else
871 {
872 p->base_offset = frame_offset_old;
873 p->full_size = frame_offset - frame_offset_old;
874 }
875
876 selected = p;
877 }
878
879 p = selected;
880 p->in_use = 1;
881 p->type = type;
882 p->level = temp_slot_level;
883 n_temp_slots_in_use++;
884
885 pp = temp_slots_at_level (p->level);
886 insert_slot_to_list (p, pp);
887 insert_temp_slot_address (XEXP (p->slot, 0), p);
888
889 /* Create a new MEM rtx to avoid clobbering MEM flags of old slots. */
890 slot = gen_rtx_MEM (mode, XEXP (p->slot, 0));
891 stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, slot, stack_slot_list);
892
893 /* If we know the alias set for the memory that will be used, use
894 it. If there's no TYPE, then we don't know anything about the
895 alias set for the memory. */
896 set_mem_alias_set (slot, type ? get_alias_set (type) : 0);
897 set_mem_align (slot, align);
898
899 /* If a type is specified, set the relevant flags. */
900 if (type != 0)
901 MEM_VOLATILE_P (slot) = TYPE_VOLATILE (type);
902 MEM_NOTRAP_P (slot) = 1;
903
904 return slot;
905 }
906
907 /* Allocate a temporary stack slot and record it for possible later
908 reuse. First two arguments are same as in preceding function. */
909
910 rtx
911 assign_stack_temp (enum machine_mode mode, HOST_WIDE_INT size)
912 {
913 return assign_stack_temp_for_type (mode, size, NULL_TREE);
914 }
915 \f
916 /* Assign a temporary.
917 If TYPE_OR_DECL is a decl, then we are doing it on behalf of the decl
918 and so that should be used in error messages. In either case, we
919 allocate of the given type.
920 MEMORY_REQUIRED is 1 if the result must be addressable stack memory;
921 it is 0 if a register is OK.
922 DONT_PROMOTE is 1 if we should not promote values in register
923 to wider modes. */
924
925 rtx
926 assign_temp (tree type_or_decl, int memory_required,
927 int dont_promote ATTRIBUTE_UNUSED)
928 {
929 tree type, decl;
930 enum machine_mode mode;
931 #ifdef PROMOTE_MODE
932 int unsignedp;
933 #endif
934
935 if (DECL_P (type_or_decl))
936 decl = type_or_decl, type = TREE_TYPE (decl);
937 else
938 decl = NULL, type = type_or_decl;
939
940 mode = TYPE_MODE (type);
941 #ifdef PROMOTE_MODE
942 unsignedp = TYPE_UNSIGNED (type);
943 #endif
944
945 if (mode == BLKmode || memory_required)
946 {
947 HOST_WIDE_INT size = int_size_in_bytes (type);
948 rtx tmp;
949
950 /* Zero sized arrays are GNU C extension. Set size to 1 to avoid
951 problems with allocating the stack space. */
952 if (size == 0)
953 size = 1;
954
955 /* Unfortunately, we don't yet know how to allocate variable-sized
956 temporaries. However, sometimes we can find a fixed upper limit on
957 the size, so try that instead. */
958 else if (size == -1)
959 size = max_int_size_in_bytes (type);
960
961 /* The size of the temporary may be too large to fit into an integer. */
962 /* ??? Not sure this should happen except for user silliness, so limit
963 this to things that aren't compiler-generated temporaries. The
964 rest of the time we'll die in assign_stack_temp_for_type. */
965 if (decl && size == -1
966 && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST)
967 {
968 error ("size of variable %q+D is too large", decl);
969 size = 1;
970 }
971
972 tmp = assign_stack_temp_for_type (mode, size, type);
973 return tmp;
974 }
975
976 #ifdef PROMOTE_MODE
977 if (! dont_promote)
978 mode = promote_mode (type, mode, &unsignedp);
979 #endif
980
981 return gen_reg_rtx (mode);
982 }
983 \f
984 /* Combine temporary stack slots which are adjacent on the stack.
985
986 This allows for better use of already allocated stack space. This is only
987 done for BLKmode slots because we can be sure that we won't have alignment
988 problems in this case. */
989
990 static void
991 combine_temp_slots (void)
992 {
993 struct temp_slot *p, *q, *next, *next_q;
994 int num_slots;
995
996 /* We can't combine slots, because the information about which slot
997 is in which alias set will be lost. */
998 if (flag_strict_aliasing)
999 return;
1000
1001 /* If there are a lot of temp slots, don't do anything unless
1002 high levels of optimization. */
1003 if (! flag_expensive_optimizations)
1004 for (p = avail_temp_slots, num_slots = 0; p; p = p->next, num_slots++)
1005 if (num_slots > 100 || (num_slots > 10 && optimize == 0))
1006 return;
1007
1008 for (p = avail_temp_slots; p; p = next)
1009 {
1010 int delete_p = 0;
1011
1012 next = p->next;
1013
1014 if (GET_MODE (p->slot) != BLKmode)
1015 continue;
1016
1017 for (q = p->next; q; q = next_q)
1018 {
1019 int delete_q = 0;
1020
1021 next_q = q->next;
1022
1023 if (GET_MODE (q->slot) != BLKmode)
1024 continue;
1025
1026 if (p->base_offset + p->full_size == q->base_offset)
1027 {
1028 /* Q comes after P; combine Q into P. */
1029 p->size += q->size;
1030 p->full_size += q->full_size;
1031 delete_q = 1;
1032 }
1033 else if (q->base_offset + q->full_size == p->base_offset)
1034 {
1035 /* P comes after Q; combine P into Q. */
1036 q->size += p->size;
1037 q->full_size += p->full_size;
1038 delete_p = 1;
1039 break;
1040 }
1041 if (delete_q)
1042 cut_slot_from_list (q, &avail_temp_slots);
1043 }
1044
1045 /* Either delete P or advance past it. */
1046 if (delete_p)
1047 cut_slot_from_list (p, &avail_temp_slots);
1048 }
1049 }
1050 \f
1051 /* Indicate that NEW_RTX is an alternate way of referring to the temp
1052 slot that previously was known by OLD_RTX. */
1053
1054 void
1055 update_temp_slot_address (rtx old_rtx, rtx new_rtx)
1056 {
1057 struct temp_slot *p;
1058
1059 if (rtx_equal_p (old_rtx, new_rtx))
1060 return;
1061
1062 p = find_temp_slot_from_address (old_rtx);
1063
1064 /* If we didn't find one, see if both OLD_RTX is a PLUS. If so, and
1065 NEW_RTX is a register, see if one operand of the PLUS is a
1066 temporary location. If so, NEW_RTX points into it. Otherwise,
1067 if both OLD_RTX and NEW_RTX are a PLUS and if there is a register
1068 in common between them. If so, try a recursive call on those
1069 values. */
1070 if (p == 0)
1071 {
1072 if (GET_CODE (old_rtx) != PLUS)
1073 return;
1074
1075 if (REG_P (new_rtx))
1076 {
1077 update_temp_slot_address (XEXP (old_rtx, 0), new_rtx);
1078 update_temp_slot_address (XEXP (old_rtx, 1), new_rtx);
1079 return;
1080 }
1081 else if (GET_CODE (new_rtx) != PLUS)
1082 return;
1083
1084 if (rtx_equal_p (XEXP (old_rtx, 0), XEXP (new_rtx, 0)))
1085 update_temp_slot_address (XEXP (old_rtx, 1), XEXP (new_rtx, 1));
1086 else if (rtx_equal_p (XEXP (old_rtx, 1), XEXP (new_rtx, 0)))
1087 update_temp_slot_address (XEXP (old_rtx, 0), XEXP (new_rtx, 1));
1088 else if (rtx_equal_p (XEXP (old_rtx, 0), XEXP (new_rtx, 1)))
1089 update_temp_slot_address (XEXP (old_rtx, 1), XEXP (new_rtx, 0));
1090 else if (rtx_equal_p (XEXP (old_rtx, 1), XEXP (new_rtx, 1)))
1091 update_temp_slot_address (XEXP (old_rtx, 0), XEXP (new_rtx, 0));
1092
1093 return;
1094 }
1095
1096 /* Otherwise add an alias for the temp's address. */
1097 insert_temp_slot_address (new_rtx, p);
1098 }
1099
1100 /* If X could be a reference to a temporary slot, mark that slot as
1101 belonging to the to one level higher than the current level. If X
1102 matched one of our slots, just mark that one. Otherwise, we can't
1103 easily predict which it is, so upgrade all of them.
1104
1105 This is called when an ({...}) construct occurs and a statement
1106 returns a value in memory. */
1107
1108 void
1109 preserve_temp_slots (rtx x)
1110 {
1111 struct temp_slot *p = 0, *next;
1112
1113 if (x == 0)
1114 return;
1115
1116 /* If X is a register that is being used as a pointer, see if we have
1117 a temporary slot we know it points to. */
1118 if (REG_P (x) && REG_POINTER (x))
1119 p = find_temp_slot_from_address (x);
1120
1121 /* If X is not in memory or is at a constant address, it cannot be in
1122 a temporary slot. */
1123 if (p == 0 && (!MEM_P (x) || CONSTANT_P (XEXP (x, 0))))
1124 return;
1125
1126 /* First see if we can find a match. */
1127 if (p == 0)
1128 p = find_temp_slot_from_address (XEXP (x, 0));
1129
1130 if (p != 0)
1131 {
1132 if (p->level == temp_slot_level)
1133 move_slot_to_level (p, temp_slot_level - 1);
1134 return;
1135 }
1136
1137 /* Otherwise, preserve all non-kept slots at this level. */
1138 for (p = *temp_slots_at_level (temp_slot_level); p; p = next)
1139 {
1140 next = p->next;
1141 move_slot_to_level (p, temp_slot_level - 1);
1142 }
1143 }
1144
1145 /* Free all temporaries used so far. This is normally called at the
1146 end of generating code for a statement. */
1147
1148 void
1149 free_temp_slots (void)
1150 {
1151 struct temp_slot *p, *next;
1152 bool some_available = false;
1153
1154 for (p = *temp_slots_at_level (temp_slot_level); p; p = next)
1155 {
1156 next = p->next;
1157 make_slot_available (p);
1158 some_available = true;
1159 }
1160
1161 if (some_available)
1162 {
1163 remove_unused_temp_slot_addresses ();
1164 combine_temp_slots ();
1165 }
1166 }
1167
1168 /* Push deeper into the nesting level for stack temporaries. */
1169
1170 void
1171 push_temp_slots (void)
1172 {
1173 temp_slot_level++;
1174 }
1175
1176 /* Pop a temporary nesting level. All slots in use in the current level
1177 are freed. */
1178
1179 void
1180 pop_temp_slots (void)
1181 {
1182 free_temp_slots ();
1183 temp_slot_level--;
1184 }
1185
1186 /* Initialize temporary slots. */
1187
1188 void
1189 init_temp_slots (void)
1190 {
1191 /* We have not allocated any temporaries yet. */
1192 avail_temp_slots = 0;
1193 vec_alloc (used_temp_slots, 0);
1194 temp_slot_level = 0;
1195 n_temp_slots_in_use = 0;
1196
1197 /* Set up the table to map addresses to temp slots. */
1198 if (! temp_slot_address_table)
1199 temp_slot_address_table = hash_table<temp_address_hasher>::create_ggc (32);
1200 else
1201 temp_slot_address_table->empty ();
1202 }
1203 \f
1204 /* Functions and data structures to keep track of the values hard regs
1205 had at the start of the function. */
1206
1207 /* Private type used by get_hard_reg_initial_reg, get_hard_reg_initial_val,
1208 and has_hard_reg_initial_val.. */
1209 typedef struct GTY(()) initial_value_pair {
1210 rtx hard_reg;
1211 rtx pseudo;
1212 } initial_value_pair;
1213 /* ??? This could be a VEC but there is currently no way to define an
1214 opaque VEC type. This could be worked around by defining struct
1215 initial_value_pair in function.h. */
1216 typedef struct GTY(()) initial_value_struct {
1217 int num_entries;
1218 int max_entries;
1219 initial_value_pair * GTY ((length ("%h.num_entries"))) entries;
1220 } initial_value_struct;
1221
1222 /* If a pseudo represents an initial hard reg (or expression), return
1223 it, else return NULL_RTX. */
1224
1225 rtx
1226 get_hard_reg_initial_reg (rtx reg)
1227 {
1228 struct initial_value_struct *ivs = crtl->hard_reg_initial_vals;
1229 int i;
1230
1231 if (ivs == 0)
1232 return NULL_RTX;
1233
1234 for (i = 0; i < ivs->num_entries; i++)
1235 if (rtx_equal_p (ivs->entries[i].pseudo, reg))
1236 return ivs->entries[i].hard_reg;
1237
1238 return NULL_RTX;
1239 }
1240
1241 /* Make sure that there's a pseudo register of mode MODE that stores the
1242 initial value of hard register REGNO. Return an rtx for such a pseudo. */
1243
1244 rtx
1245 get_hard_reg_initial_val (enum machine_mode mode, unsigned int regno)
1246 {
1247 struct initial_value_struct *ivs;
1248 rtx rv;
1249
1250 rv = has_hard_reg_initial_val (mode, regno);
1251 if (rv)
1252 return rv;
1253
1254 ivs = crtl->hard_reg_initial_vals;
1255 if (ivs == 0)
1256 {
1257 ivs = ggc_alloc<initial_value_struct> ();
1258 ivs->num_entries = 0;
1259 ivs->max_entries = 5;
1260 ivs->entries = ggc_vec_alloc<initial_value_pair> (5);
1261 crtl->hard_reg_initial_vals = ivs;
1262 }
1263
1264 if (ivs->num_entries >= ivs->max_entries)
1265 {
1266 ivs->max_entries += 5;
1267 ivs->entries = GGC_RESIZEVEC (initial_value_pair, ivs->entries,
1268 ivs->max_entries);
1269 }
1270
1271 ivs->entries[ivs->num_entries].hard_reg = gen_rtx_REG (mode, regno);
1272 ivs->entries[ivs->num_entries].pseudo = gen_reg_rtx (mode);
1273
1274 return ivs->entries[ivs->num_entries++].pseudo;
1275 }
1276
1277 /* See if get_hard_reg_initial_val has been used to create a pseudo
1278 for the initial value of hard register REGNO in mode MODE. Return
1279 the associated pseudo if so, otherwise return NULL. */
1280
1281 rtx
1282 has_hard_reg_initial_val (enum machine_mode mode, unsigned int regno)
1283 {
1284 struct initial_value_struct *ivs;
1285 int i;
1286
1287 ivs = crtl->hard_reg_initial_vals;
1288 if (ivs != 0)
1289 for (i = 0; i < ivs->num_entries; i++)
1290 if (GET_MODE (ivs->entries[i].hard_reg) == mode
1291 && REGNO (ivs->entries[i].hard_reg) == regno)
1292 return ivs->entries[i].pseudo;
1293
1294 return NULL_RTX;
1295 }
1296
1297 unsigned int
1298 emit_initial_value_sets (void)
1299 {
1300 struct initial_value_struct *ivs = crtl->hard_reg_initial_vals;
1301 int i;
1302 rtx_insn *seq;
1303
1304 if (ivs == 0)
1305 return 0;
1306
1307 start_sequence ();
1308 for (i = 0; i < ivs->num_entries; i++)
1309 emit_move_insn (ivs->entries[i].pseudo, ivs->entries[i].hard_reg);
1310 seq = get_insns ();
1311 end_sequence ();
1312
1313 emit_insn_at_entry (seq);
1314 return 0;
1315 }
1316
1317 /* Return the hardreg-pseudoreg initial values pair entry I and
1318 TRUE if I is a valid entry, or FALSE if I is not a valid entry. */
1319 bool
1320 initial_value_entry (int i, rtx *hreg, rtx *preg)
1321 {
1322 struct initial_value_struct *ivs = crtl->hard_reg_initial_vals;
1323 if (!ivs || i >= ivs->num_entries)
1324 return false;
1325
1326 *hreg = ivs->entries[i].hard_reg;
1327 *preg = ivs->entries[i].pseudo;
1328 return true;
1329 }
1330 \f
1331 /* These routines are responsible for converting virtual register references
1332 to the actual hard register references once RTL generation is complete.
1333
1334 The following four variables are used for communication between the
1335 routines. They contain the offsets of the virtual registers from their
1336 respective hard registers. */
1337
1338 static int in_arg_offset;
1339 static int var_offset;
1340 static int dynamic_offset;
1341 static int out_arg_offset;
1342 static int cfa_offset;
1343
1344 /* In most machines, the stack pointer register is equivalent to the bottom
1345 of the stack. */
1346
1347 #ifndef STACK_POINTER_OFFSET
1348 #define STACK_POINTER_OFFSET 0
1349 #endif
1350
1351 #if defined (REG_PARM_STACK_SPACE) && !defined (INCOMING_REG_PARM_STACK_SPACE)
1352 #define INCOMING_REG_PARM_STACK_SPACE REG_PARM_STACK_SPACE
1353 #endif
1354
1355 /* If not defined, pick an appropriate default for the offset of dynamically
1356 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
1357 INCOMING_REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
1358
1359 #ifndef STACK_DYNAMIC_OFFSET
1360
1361 /* The bottom of the stack points to the actual arguments. If
1362 REG_PARM_STACK_SPACE is defined, this includes the space for the register
1363 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
1364 stack space for register parameters is not pushed by the caller, but
1365 rather part of the fixed stack areas and hence not included in
1366 `crtl->outgoing_args_size'. Nevertheless, we must allow
1367 for it when allocating stack dynamic objects. */
1368
1369 #ifdef INCOMING_REG_PARM_STACK_SPACE
1370 #define STACK_DYNAMIC_OFFSET(FNDECL) \
1371 ((ACCUMULATE_OUTGOING_ARGS \
1372 ? (crtl->outgoing_args_size \
1373 + (OUTGOING_REG_PARM_STACK_SPACE ((!(FNDECL) ? NULL_TREE : TREE_TYPE (FNDECL))) ? 0 \
1374 : INCOMING_REG_PARM_STACK_SPACE (FNDECL))) \
1375 : 0) + (STACK_POINTER_OFFSET))
1376 #else
1377 #define STACK_DYNAMIC_OFFSET(FNDECL) \
1378 ((ACCUMULATE_OUTGOING_ARGS ? crtl->outgoing_args_size : 0) \
1379 + (STACK_POINTER_OFFSET))
1380 #endif
1381 #endif
1382
1383 \f
1384 /* Given a piece of RTX and a pointer to a HOST_WIDE_INT, if the RTX
1385 is a virtual register, return the equivalent hard register and set the
1386 offset indirectly through the pointer. Otherwise, return 0. */
1387
1388 static rtx
1389 instantiate_new_reg (rtx x, HOST_WIDE_INT *poffset)
1390 {
1391 rtx new_rtx;
1392 HOST_WIDE_INT offset;
1393
1394 if (x == virtual_incoming_args_rtx)
1395 {
1396 if (stack_realign_drap)
1397 {
1398 /* Replace virtual_incoming_args_rtx with internal arg
1399 pointer if DRAP is used to realign stack. */
1400 new_rtx = crtl->args.internal_arg_pointer;
1401 offset = 0;
1402 }
1403 else
1404 new_rtx = arg_pointer_rtx, offset = in_arg_offset;
1405 }
1406 else if (x == virtual_stack_vars_rtx)
1407 new_rtx = frame_pointer_rtx, offset = var_offset;
1408 else if (x == virtual_stack_dynamic_rtx)
1409 new_rtx = stack_pointer_rtx, offset = dynamic_offset;
1410 else if (x == virtual_outgoing_args_rtx)
1411 new_rtx = stack_pointer_rtx, offset = out_arg_offset;
1412 else if (x == virtual_cfa_rtx)
1413 {
1414 #ifdef FRAME_POINTER_CFA_OFFSET
1415 new_rtx = frame_pointer_rtx;
1416 #else
1417 new_rtx = arg_pointer_rtx;
1418 #endif
1419 offset = cfa_offset;
1420 }
1421 else if (x == virtual_preferred_stack_boundary_rtx)
1422 {
1423 new_rtx = GEN_INT (crtl->preferred_stack_boundary / BITS_PER_UNIT);
1424 offset = 0;
1425 }
1426 else
1427 return NULL_RTX;
1428
1429 *poffset = offset;
1430 return new_rtx;
1431 }
1432
1433 /* A subroutine of instantiate_virtual_regs. Instantiate any virtual
1434 registers present inside of *LOC. The expression is simplified,
1435 as much as possible, but is not to be considered "valid" in any sense
1436 implied by the target. Return true if any change is made. */
1437
1438 static bool
1439 instantiate_virtual_regs_in_rtx (rtx *loc)
1440 {
1441 if (!*loc)
1442 return false;
1443 bool changed = false;
1444 subrtx_ptr_iterator::array_type array;
1445 FOR_EACH_SUBRTX_PTR (iter, array, loc, NONCONST)
1446 {
1447 rtx *loc = *iter;
1448 if (rtx x = *loc)
1449 {
1450 rtx new_rtx;
1451 HOST_WIDE_INT offset;
1452 switch (GET_CODE (x))
1453 {
1454 case REG:
1455 new_rtx = instantiate_new_reg (x, &offset);
1456 if (new_rtx)
1457 {
1458 *loc = plus_constant (GET_MODE (x), new_rtx, offset);
1459 changed = true;
1460 }
1461 iter.skip_subrtxes ();
1462 break;
1463
1464 case PLUS:
1465 new_rtx = instantiate_new_reg (XEXP (x, 0), &offset);
1466 if (new_rtx)
1467 {
1468 XEXP (x, 0) = new_rtx;
1469 *loc = plus_constant (GET_MODE (x), x, offset, true);
1470 changed = true;
1471 iter.skip_subrtxes ();
1472 break;
1473 }
1474
1475 /* FIXME -- from old code */
1476 /* If we have (plus (subreg (virtual-reg)) (const_int)), we know
1477 we can commute the PLUS and SUBREG because pointers into the
1478 frame are well-behaved. */
1479 break;
1480
1481 default:
1482 break;
1483 }
1484 }
1485 }
1486 return changed;
1487 }
1488
1489 /* A subroutine of instantiate_virtual_regs_in_insn. Return true if X
1490 matches the predicate for insn CODE operand OPERAND. */
1491
1492 static int
1493 safe_insn_predicate (int code, int operand, rtx x)
1494 {
1495 return code < 0 || insn_operand_matches ((enum insn_code) code, operand, x);
1496 }
1497
1498 /* A subroutine of instantiate_virtual_regs. Instantiate any virtual
1499 registers present inside of insn. The result will be a valid insn. */
1500
1501 static void
1502 instantiate_virtual_regs_in_insn (rtx_insn *insn)
1503 {
1504 HOST_WIDE_INT offset;
1505 int insn_code, i;
1506 bool any_change = false;
1507 rtx set, new_rtx, x;
1508 rtx_insn *seq;
1509
1510 /* There are some special cases to be handled first. */
1511 set = single_set (insn);
1512 if (set)
1513 {
1514 /* We're allowed to assign to a virtual register. This is interpreted
1515 to mean that the underlying register gets assigned the inverse
1516 transformation. This is used, for example, in the handling of
1517 non-local gotos. */
1518 new_rtx = instantiate_new_reg (SET_DEST (set), &offset);
1519 if (new_rtx)
1520 {
1521 start_sequence ();
1522
1523 instantiate_virtual_regs_in_rtx (&SET_SRC (set));
1524 x = simplify_gen_binary (PLUS, GET_MODE (new_rtx), SET_SRC (set),
1525 gen_int_mode (-offset, GET_MODE (new_rtx)));
1526 x = force_operand (x, new_rtx);
1527 if (x != new_rtx)
1528 emit_move_insn (new_rtx, x);
1529
1530 seq = get_insns ();
1531 end_sequence ();
1532
1533 emit_insn_before (seq, insn);
1534 delete_insn (insn);
1535 return;
1536 }
1537
1538 /* Handle a straight copy from a virtual register by generating a
1539 new add insn. The difference between this and falling through
1540 to the generic case is avoiding a new pseudo and eliminating a
1541 move insn in the initial rtl stream. */
1542 new_rtx = instantiate_new_reg (SET_SRC (set), &offset);
1543 if (new_rtx && offset != 0
1544 && REG_P (SET_DEST (set))
1545 && REGNO (SET_DEST (set)) > LAST_VIRTUAL_REGISTER)
1546 {
1547 start_sequence ();
1548
1549 x = expand_simple_binop (GET_MODE (SET_DEST (set)), PLUS, new_rtx,
1550 gen_int_mode (offset,
1551 GET_MODE (SET_DEST (set))),
1552 SET_DEST (set), 1, OPTAB_LIB_WIDEN);
1553 if (x != SET_DEST (set))
1554 emit_move_insn (SET_DEST (set), x);
1555
1556 seq = get_insns ();
1557 end_sequence ();
1558
1559 emit_insn_before (seq, insn);
1560 delete_insn (insn);
1561 return;
1562 }
1563
1564 extract_insn (insn);
1565 insn_code = INSN_CODE (insn);
1566
1567 /* Handle a plus involving a virtual register by determining if the
1568 operands remain valid if they're modified in place. */
1569 if (GET_CODE (SET_SRC (set)) == PLUS
1570 && recog_data.n_operands >= 3
1571 && recog_data.operand_loc[1] == &XEXP (SET_SRC (set), 0)
1572 && recog_data.operand_loc[2] == &XEXP (SET_SRC (set), 1)
1573 && CONST_INT_P (recog_data.operand[2])
1574 && (new_rtx = instantiate_new_reg (recog_data.operand[1], &offset)))
1575 {
1576 offset += INTVAL (recog_data.operand[2]);
1577
1578 /* If the sum is zero, then replace with a plain move. */
1579 if (offset == 0
1580 && REG_P (SET_DEST (set))
1581 && REGNO (SET_DEST (set)) > LAST_VIRTUAL_REGISTER)
1582 {
1583 start_sequence ();
1584 emit_move_insn (SET_DEST (set), new_rtx);
1585 seq = get_insns ();
1586 end_sequence ();
1587
1588 emit_insn_before (seq, insn);
1589 delete_insn (insn);
1590 return;
1591 }
1592
1593 x = gen_int_mode (offset, recog_data.operand_mode[2]);
1594
1595 /* Using validate_change and apply_change_group here leaves
1596 recog_data in an invalid state. Since we know exactly what
1597 we want to check, do those two by hand. */
1598 if (safe_insn_predicate (insn_code, 1, new_rtx)
1599 && safe_insn_predicate (insn_code, 2, x))
1600 {
1601 *recog_data.operand_loc[1] = recog_data.operand[1] = new_rtx;
1602 *recog_data.operand_loc[2] = recog_data.operand[2] = x;
1603 any_change = true;
1604
1605 /* Fall through into the regular operand fixup loop in
1606 order to take care of operands other than 1 and 2. */
1607 }
1608 }
1609 }
1610 else
1611 {
1612 extract_insn (insn);
1613 insn_code = INSN_CODE (insn);
1614 }
1615
1616 /* In the general case, we expect virtual registers to appear only in
1617 operands, and then only as either bare registers or inside memories. */
1618 for (i = 0; i < recog_data.n_operands; ++i)
1619 {
1620 x = recog_data.operand[i];
1621 switch (GET_CODE (x))
1622 {
1623 case MEM:
1624 {
1625 rtx addr = XEXP (x, 0);
1626
1627 if (!instantiate_virtual_regs_in_rtx (&addr))
1628 continue;
1629
1630 start_sequence ();
1631 x = replace_equiv_address (x, addr, true);
1632 /* It may happen that the address with the virtual reg
1633 was valid (e.g. based on the virtual stack reg, which might
1634 be acceptable to the predicates with all offsets), whereas
1635 the address now isn't anymore, for instance when the address
1636 is still offsetted, but the base reg isn't virtual-stack-reg
1637 anymore. Below we would do a force_reg on the whole operand,
1638 but this insn might actually only accept memory. Hence,
1639 before doing that last resort, try to reload the address into
1640 a register, so this operand stays a MEM. */
1641 if (!safe_insn_predicate (insn_code, i, x))
1642 {
1643 addr = force_reg (GET_MODE (addr), addr);
1644 x = replace_equiv_address (x, addr, true);
1645 }
1646 seq = get_insns ();
1647 end_sequence ();
1648 if (seq)
1649 emit_insn_before (seq, insn);
1650 }
1651 break;
1652
1653 case REG:
1654 new_rtx = instantiate_new_reg (x, &offset);
1655 if (new_rtx == NULL)
1656 continue;
1657 if (offset == 0)
1658 x = new_rtx;
1659 else
1660 {
1661 start_sequence ();
1662
1663 /* Careful, special mode predicates may have stuff in
1664 insn_data[insn_code].operand[i].mode that isn't useful
1665 to us for computing a new value. */
1666 /* ??? Recognize address_operand and/or "p" constraints
1667 to see if (plus new offset) is a valid before we put
1668 this through expand_simple_binop. */
1669 x = expand_simple_binop (GET_MODE (x), PLUS, new_rtx,
1670 gen_int_mode (offset, GET_MODE (x)),
1671 NULL_RTX, 1, OPTAB_LIB_WIDEN);
1672 seq = get_insns ();
1673 end_sequence ();
1674 emit_insn_before (seq, insn);
1675 }
1676 break;
1677
1678 case SUBREG:
1679 new_rtx = instantiate_new_reg (SUBREG_REG (x), &offset);
1680 if (new_rtx == NULL)
1681 continue;
1682 if (offset != 0)
1683 {
1684 start_sequence ();
1685 new_rtx = expand_simple_binop
1686 (GET_MODE (new_rtx), PLUS, new_rtx,
1687 gen_int_mode (offset, GET_MODE (new_rtx)),
1688 NULL_RTX, 1, OPTAB_LIB_WIDEN);
1689 seq = get_insns ();
1690 end_sequence ();
1691 emit_insn_before (seq, insn);
1692 }
1693 x = simplify_gen_subreg (recog_data.operand_mode[i], new_rtx,
1694 GET_MODE (new_rtx), SUBREG_BYTE (x));
1695 gcc_assert (x);
1696 break;
1697
1698 default:
1699 continue;
1700 }
1701
1702 /* At this point, X contains the new value for the operand.
1703 Validate the new value vs the insn predicate. Note that
1704 asm insns will have insn_code -1 here. */
1705 if (!safe_insn_predicate (insn_code, i, x))
1706 {
1707 start_sequence ();
1708 if (REG_P (x))
1709 {
1710 gcc_assert (REGNO (x) <= LAST_VIRTUAL_REGISTER);
1711 x = copy_to_reg (x);
1712 }
1713 else
1714 x = force_reg (insn_data[insn_code].operand[i].mode, x);
1715 seq = get_insns ();
1716 end_sequence ();
1717 if (seq)
1718 emit_insn_before (seq, insn);
1719 }
1720
1721 *recog_data.operand_loc[i] = recog_data.operand[i] = x;
1722 any_change = true;
1723 }
1724
1725 if (any_change)
1726 {
1727 /* Propagate operand changes into the duplicates. */
1728 for (i = 0; i < recog_data.n_dups; ++i)
1729 *recog_data.dup_loc[i]
1730 = copy_rtx (recog_data.operand[(unsigned)recog_data.dup_num[i]]);
1731
1732 /* Force re-recognition of the instruction for validation. */
1733 INSN_CODE (insn) = -1;
1734 }
1735
1736 if (asm_noperands (PATTERN (insn)) >= 0)
1737 {
1738 if (!check_asm_operands (PATTERN (insn)))
1739 {
1740 error_for_asm (insn, "impossible constraint in %<asm%>");
1741 /* For asm goto, instead of fixing up all the edges
1742 just clear the template and clear input operands
1743 (asm goto doesn't have any output operands). */
1744 if (JUMP_P (insn))
1745 {
1746 rtx asm_op = extract_asm_operands (PATTERN (insn));
1747 ASM_OPERANDS_TEMPLATE (asm_op) = ggc_strdup ("");
1748 ASM_OPERANDS_INPUT_VEC (asm_op) = rtvec_alloc (0);
1749 ASM_OPERANDS_INPUT_CONSTRAINT_VEC (asm_op) = rtvec_alloc (0);
1750 }
1751 else
1752 delete_insn (insn);
1753 }
1754 }
1755 else
1756 {
1757 if (recog_memoized (insn) < 0)
1758 fatal_insn_not_found (insn);
1759 }
1760 }
1761
1762 /* Subroutine of instantiate_decls. Given RTL representing a decl,
1763 do any instantiation required. */
1764
1765 void
1766 instantiate_decl_rtl (rtx x)
1767 {
1768 rtx addr;
1769
1770 if (x == 0)
1771 return;
1772
1773 /* If this is a CONCAT, recurse for the pieces. */
1774 if (GET_CODE (x) == CONCAT)
1775 {
1776 instantiate_decl_rtl (XEXP (x, 0));
1777 instantiate_decl_rtl (XEXP (x, 1));
1778 return;
1779 }
1780
1781 /* If this is not a MEM, no need to do anything. Similarly if the
1782 address is a constant or a register that is not a virtual register. */
1783 if (!MEM_P (x))
1784 return;
1785
1786 addr = XEXP (x, 0);
1787 if (CONSTANT_P (addr)
1788 || (REG_P (addr)
1789 && (REGNO (addr) < FIRST_VIRTUAL_REGISTER
1790 || REGNO (addr) > LAST_VIRTUAL_REGISTER)))
1791 return;
1792
1793 instantiate_virtual_regs_in_rtx (&XEXP (x, 0));
1794 }
1795
1796 /* Helper for instantiate_decls called via walk_tree: Process all decls
1797 in the given DECL_VALUE_EXPR. */
1798
1799 static tree
1800 instantiate_expr (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
1801 {
1802 tree t = *tp;
1803 if (! EXPR_P (t))
1804 {
1805 *walk_subtrees = 0;
1806 if (DECL_P (t))
1807 {
1808 if (DECL_RTL_SET_P (t))
1809 instantiate_decl_rtl (DECL_RTL (t));
1810 if (TREE_CODE (t) == PARM_DECL && DECL_NAMELESS (t)
1811 && DECL_INCOMING_RTL (t))
1812 instantiate_decl_rtl (DECL_INCOMING_RTL (t));
1813 if ((TREE_CODE (t) == VAR_DECL
1814 || TREE_CODE (t) == RESULT_DECL)
1815 && DECL_HAS_VALUE_EXPR_P (t))
1816 {
1817 tree v = DECL_VALUE_EXPR (t);
1818 walk_tree (&v, instantiate_expr, NULL, NULL);
1819 }
1820 }
1821 }
1822 return NULL;
1823 }
1824
1825 /* Subroutine of instantiate_decls: Process all decls in the given
1826 BLOCK node and all its subblocks. */
1827
1828 static void
1829 instantiate_decls_1 (tree let)
1830 {
1831 tree t;
1832
1833 for (t = BLOCK_VARS (let); t; t = DECL_CHAIN (t))
1834 {
1835 if (DECL_RTL_SET_P (t))
1836 instantiate_decl_rtl (DECL_RTL (t));
1837 if (TREE_CODE (t) == VAR_DECL && DECL_HAS_VALUE_EXPR_P (t))
1838 {
1839 tree v = DECL_VALUE_EXPR (t);
1840 walk_tree (&v, instantiate_expr, NULL, NULL);
1841 }
1842 }
1843
1844 /* Process all subblocks. */
1845 for (t = BLOCK_SUBBLOCKS (let); t; t = BLOCK_CHAIN (t))
1846 instantiate_decls_1 (t);
1847 }
1848
1849 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
1850 all virtual registers in their DECL_RTL's. */
1851
1852 static void
1853 instantiate_decls (tree fndecl)
1854 {
1855 tree decl;
1856 unsigned ix;
1857
1858 /* Process all parameters of the function. */
1859 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = DECL_CHAIN (decl))
1860 {
1861 instantiate_decl_rtl (DECL_RTL (decl));
1862 instantiate_decl_rtl (DECL_INCOMING_RTL (decl));
1863 if (DECL_HAS_VALUE_EXPR_P (decl))
1864 {
1865 tree v = DECL_VALUE_EXPR (decl);
1866 walk_tree (&v, instantiate_expr, NULL, NULL);
1867 }
1868 }
1869
1870 if ((decl = DECL_RESULT (fndecl))
1871 && TREE_CODE (decl) == RESULT_DECL)
1872 {
1873 if (DECL_RTL_SET_P (decl))
1874 instantiate_decl_rtl (DECL_RTL (decl));
1875 if (DECL_HAS_VALUE_EXPR_P (decl))
1876 {
1877 tree v = DECL_VALUE_EXPR (decl);
1878 walk_tree (&v, instantiate_expr, NULL, NULL);
1879 }
1880 }
1881
1882 /* Process the saved static chain if it exists. */
1883 decl = DECL_STRUCT_FUNCTION (fndecl)->static_chain_decl;
1884 if (decl && DECL_HAS_VALUE_EXPR_P (decl))
1885 instantiate_decl_rtl (DECL_RTL (DECL_VALUE_EXPR (decl)));
1886
1887 /* Now process all variables defined in the function or its subblocks. */
1888 instantiate_decls_1 (DECL_INITIAL (fndecl));
1889
1890 FOR_EACH_LOCAL_DECL (cfun, ix, decl)
1891 if (DECL_RTL_SET_P (decl))
1892 instantiate_decl_rtl (DECL_RTL (decl));
1893 vec_free (cfun->local_decls);
1894 }
1895
1896 /* Pass through the INSNS of function FNDECL and convert virtual register
1897 references to hard register references. */
1898
1899 static unsigned int
1900 instantiate_virtual_regs (void)
1901 {
1902 rtx_insn *insn;
1903
1904 /* Compute the offsets to use for this function. */
1905 in_arg_offset = FIRST_PARM_OFFSET (current_function_decl);
1906 var_offset = STARTING_FRAME_OFFSET;
1907 dynamic_offset = STACK_DYNAMIC_OFFSET (current_function_decl);
1908 out_arg_offset = STACK_POINTER_OFFSET;
1909 #ifdef FRAME_POINTER_CFA_OFFSET
1910 cfa_offset = FRAME_POINTER_CFA_OFFSET (current_function_decl);
1911 #else
1912 cfa_offset = ARG_POINTER_CFA_OFFSET (current_function_decl);
1913 #endif
1914
1915 /* Initialize recognition, indicating that volatile is OK. */
1916 init_recog ();
1917
1918 /* Scan through all the insns, instantiating every virtual register still
1919 present. */
1920 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
1921 if (INSN_P (insn))
1922 {
1923 /* These patterns in the instruction stream can never be recognized.
1924 Fortunately, they shouldn't contain virtual registers either. */
1925 if (GET_CODE (PATTERN (insn)) == USE
1926 || GET_CODE (PATTERN (insn)) == CLOBBER
1927 || GET_CODE (PATTERN (insn)) == ASM_INPUT)
1928 continue;
1929 else if (DEBUG_INSN_P (insn))
1930 instantiate_virtual_regs_in_rtx (&INSN_VAR_LOCATION (insn));
1931 else
1932 instantiate_virtual_regs_in_insn (insn);
1933
1934 if (insn->deleted ())
1935 continue;
1936
1937 instantiate_virtual_regs_in_rtx (&REG_NOTES (insn));
1938
1939 /* Instantiate any virtual registers in CALL_INSN_FUNCTION_USAGE. */
1940 if (CALL_P (insn))
1941 instantiate_virtual_regs_in_rtx (&CALL_INSN_FUNCTION_USAGE (insn));
1942 }
1943
1944 /* Instantiate the virtual registers in the DECLs for debugging purposes. */
1945 instantiate_decls (current_function_decl);
1946
1947 targetm.instantiate_decls ();
1948
1949 /* Indicate that, from now on, assign_stack_local should use
1950 frame_pointer_rtx. */
1951 virtuals_instantiated = 1;
1952
1953 return 0;
1954 }
1955
1956 namespace {
1957
1958 const pass_data pass_data_instantiate_virtual_regs =
1959 {
1960 RTL_PASS, /* type */
1961 "vregs", /* name */
1962 OPTGROUP_NONE, /* optinfo_flags */
1963 TV_NONE, /* tv_id */
1964 0, /* properties_required */
1965 0, /* properties_provided */
1966 0, /* properties_destroyed */
1967 0, /* todo_flags_start */
1968 0, /* todo_flags_finish */
1969 };
1970
1971 class pass_instantiate_virtual_regs : public rtl_opt_pass
1972 {
1973 public:
1974 pass_instantiate_virtual_regs (gcc::context *ctxt)
1975 : rtl_opt_pass (pass_data_instantiate_virtual_regs, ctxt)
1976 {}
1977
1978 /* opt_pass methods: */
1979 virtual unsigned int execute (function *)
1980 {
1981 return instantiate_virtual_regs ();
1982 }
1983
1984 }; // class pass_instantiate_virtual_regs
1985
1986 } // anon namespace
1987
1988 rtl_opt_pass *
1989 make_pass_instantiate_virtual_regs (gcc::context *ctxt)
1990 {
1991 return new pass_instantiate_virtual_regs (ctxt);
1992 }
1993
1994 \f
1995 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
1996 This means a type for which function calls must pass an address to the
1997 function or get an address back from the function.
1998 EXP may be a type node or an expression (whose type is tested). */
1999
2000 int
2001 aggregate_value_p (const_tree exp, const_tree fntype)
2002 {
2003 const_tree type = (TYPE_P (exp)) ? exp : TREE_TYPE (exp);
2004 int i, regno, nregs;
2005 rtx reg;
2006
2007 if (fntype)
2008 switch (TREE_CODE (fntype))
2009 {
2010 case CALL_EXPR:
2011 {
2012 tree fndecl = get_callee_fndecl (fntype);
2013 fntype = (fndecl
2014 ? TREE_TYPE (fndecl)
2015 : TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (fntype))));
2016 }
2017 break;
2018 case FUNCTION_DECL:
2019 fntype = TREE_TYPE (fntype);
2020 break;
2021 case FUNCTION_TYPE:
2022 case METHOD_TYPE:
2023 break;
2024 case IDENTIFIER_NODE:
2025 fntype = NULL_TREE;
2026 break;
2027 default:
2028 /* We don't expect other tree types here. */
2029 gcc_unreachable ();
2030 }
2031
2032 if (VOID_TYPE_P (type))
2033 return 0;
2034
2035 /* If a record should be passed the same as its first (and only) member
2036 don't pass it as an aggregate. */
2037 if (TREE_CODE (type) == RECORD_TYPE && TYPE_TRANSPARENT_AGGR (type))
2038 return aggregate_value_p (first_field (type), fntype);
2039
2040 /* If the front end has decided that this needs to be passed by
2041 reference, do so. */
2042 if ((TREE_CODE (exp) == PARM_DECL || TREE_CODE (exp) == RESULT_DECL)
2043 && DECL_BY_REFERENCE (exp))
2044 return 1;
2045
2046 /* Function types that are TREE_ADDRESSABLE force return in memory. */
2047 if (fntype && TREE_ADDRESSABLE (fntype))
2048 return 1;
2049
2050 /* Types that are TREE_ADDRESSABLE must be constructed in memory,
2051 and thus can't be returned in registers. */
2052 if (TREE_ADDRESSABLE (type))
2053 return 1;
2054
2055 if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type))
2056 return 1;
2057
2058 if (targetm.calls.return_in_memory (type, fntype))
2059 return 1;
2060
2061 /* Make sure we have suitable call-clobbered regs to return
2062 the value in; if not, we must return it in memory. */
2063 reg = hard_function_value (type, 0, fntype, 0);
2064
2065 /* If we have something other than a REG (e.g. a PARALLEL), then assume
2066 it is OK. */
2067 if (!REG_P (reg))
2068 return 0;
2069
2070 regno = REGNO (reg);
2071 nregs = hard_regno_nregs[regno][TYPE_MODE (type)];
2072 for (i = 0; i < nregs; i++)
2073 if (! call_used_regs[regno + i])
2074 return 1;
2075
2076 return 0;
2077 }
2078 \f
2079 /* Return true if we should assign DECL a pseudo register; false if it
2080 should live on the local stack. */
2081
2082 bool
2083 use_register_for_decl (const_tree decl)
2084 {
2085 if (!targetm.calls.allocate_stack_slots_for_args ())
2086 return true;
2087
2088 /* Honor volatile. */
2089 if (TREE_SIDE_EFFECTS (decl))
2090 return false;
2091
2092 /* Honor addressability. */
2093 if (TREE_ADDRESSABLE (decl))
2094 return false;
2095
2096 /* Only register-like things go in registers. */
2097 if (DECL_MODE (decl) == BLKmode)
2098 return false;
2099
2100 /* If -ffloat-store specified, don't put explicit float variables
2101 into registers. */
2102 /* ??? This should be checked after DECL_ARTIFICIAL, but tree-ssa
2103 propagates values across these stores, and it probably shouldn't. */
2104 if (flag_float_store && FLOAT_TYPE_P (TREE_TYPE (decl)))
2105 return false;
2106
2107 /* If we're not interested in tracking debugging information for
2108 this decl, then we can certainly put it in a register. */
2109 if (DECL_IGNORED_P (decl))
2110 return true;
2111
2112 if (optimize)
2113 return true;
2114
2115 if (!DECL_REGISTER (decl))
2116 return false;
2117
2118 switch (TREE_CODE (TREE_TYPE (decl)))
2119 {
2120 case RECORD_TYPE:
2121 case UNION_TYPE:
2122 case QUAL_UNION_TYPE:
2123 /* When not optimizing, disregard register keyword for variables with
2124 types containing methods, otherwise the methods won't be callable
2125 from the debugger. */
2126 if (TYPE_METHODS (TREE_TYPE (decl)))
2127 return false;
2128 break;
2129 default:
2130 break;
2131 }
2132
2133 return true;
2134 }
2135
2136 /* Return true if TYPE should be passed by invisible reference. */
2137
2138 bool
2139 pass_by_reference (CUMULATIVE_ARGS *ca, enum machine_mode mode,
2140 tree type, bool named_arg)
2141 {
2142 if (type)
2143 {
2144 /* If this type contains non-trivial constructors, then it is
2145 forbidden for the middle-end to create any new copies. */
2146 if (TREE_ADDRESSABLE (type))
2147 return true;
2148
2149 /* GCC post 3.4 passes *all* variable sized types by reference. */
2150 if (!TYPE_SIZE (type) || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
2151 return true;
2152
2153 /* If a record type should be passed the same as its first (and only)
2154 member, use the type and mode of that member. */
2155 if (TREE_CODE (type) == RECORD_TYPE && TYPE_TRANSPARENT_AGGR (type))
2156 {
2157 type = TREE_TYPE (first_field (type));
2158 mode = TYPE_MODE (type);
2159 }
2160 }
2161
2162 return targetm.calls.pass_by_reference (pack_cumulative_args (ca), mode,
2163 type, named_arg);
2164 }
2165
2166 /* Return true if TYPE, which is passed by reference, should be callee
2167 copied instead of caller copied. */
2168
2169 bool
2170 reference_callee_copied (CUMULATIVE_ARGS *ca, enum machine_mode mode,
2171 tree type, bool named_arg)
2172 {
2173 if (type && TREE_ADDRESSABLE (type))
2174 return false;
2175 return targetm.calls.callee_copies (pack_cumulative_args (ca), mode, type,
2176 named_arg);
2177 }
2178
2179 /* Structures to communicate between the subroutines of assign_parms.
2180 The first holds data persistent across all parameters, the second
2181 is cleared out for each parameter. */
2182
2183 struct assign_parm_data_all
2184 {
2185 /* When INIT_CUMULATIVE_ARGS gets revamped, allocating CUMULATIVE_ARGS
2186 should become a job of the target or otherwise encapsulated. */
2187 CUMULATIVE_ARGS args_so_far_v;
2188 cumulative_args_t args_so_far;
2189 struct args_size stack_args_size;
2190 tree function_result_decl;
2191 tree orig_fnargs;
2192 rtx_insn *first_conversion_insn;
2193 rtx_insn *last_conversion_insn;
2194 HOST_WIDE_INT pretend_args_size;
2195 HOST_WIDE_INT extra_pretend_bytes;
2196 int reg_parm_stack_space;
2197 };
2198
2199 struct assign_parm_data_one
2200 {
2201 tree nominal_type;
2202 tree passed_type;
2203 rtx entry_parm;
2204 rtx stack_parm;
2205 enum machine_mode nominal_mode;
2206 enum machine_mode passed_mode;
2207 enum machine_mode promoted_mode;
2208 struct locate_and_pad_arg_data locate;
2209 int partial;
2210 BOOL_BITFIELD named_arg : 1;
2211 BOOL_BITFIELD passed_pointer : 1;
2212 BOOL_BITFIELD on_stack : 1;
2213 BOOL_BITFIELD loaded_in_reg : 1;
2214 };
2215
2216 /* A subroutine of assign_parms. Initialize ALL. */
2217
2218 static void
2219 assign_parms_initialize_all (struct assign_parm_data_all *all)
2220 {
2221 tree fntype ATTRIBUTE_UNUSED;
2222
2223 memset (all, 0, sizeof (*all));
2224
2225 fntype = TREE_TYPE (current_function_decl);
2226
2227 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
2228 INIT_CUMULATIVE_INCOMING_ARGS (all->args_so_far_v, fntype, NULL_RTX);
2229 #else
2230 INIT_CUMULATIVE_ARGS (all->args_so_far_v, fntype, NULL_RTX,
2231 current_function_decl, -1);
2232 #endif
2233 all->args_so_far = pack_cumulative_args (&all->args_so_far_v);
2234
2235 #ifdef INCOMING_REG_PARM_STACK_SPACE
2236 all->reg_parm_stack_space
2237 = INCOMING_REG_PARM_STACK_SPACE (current_function_decl);
2238 #endif
2239 }
2240
2241 /* If ARGS contains entries with complex types, split the entry into two
2242 entries of the component type. Return a new list of substitutions are
2243 needed, else the old list. */
2244
2245 static void
2246 split_complex_args (vec<tree> *args)
2247 {
2248 unsigned i;
2249 tree p;
2250
2251 FOR_EACH_VEC_ELT (*args, i, p)
2252 {
2253 tree type = TREE_TYPE (p);
2254 if (TREE_CODE (type) == COMPLEX_TYPE
2255 && targetm.calls.split_complex_arg (type))
2256 {
2257 tree decl;
2258 tree subtype = TREE_TYPE (type);
2259 bool addressable = TREE_ADDRESSABLE (p);
2260
2261 /* Rewrite the PARM_DECL's type with its component. */
2262 p = copy_node (p);
2263 TREE_TYPE (p) = subtype;
2264 DECL_ARG_TYPE (p) = TREE_TYPE (DECL_ARG_TYPE (p));
2265 DECL_MODE (p) = VOIDmode;
2266 DECL_SIZE (p) = NULL;
2267 DECL_SIZE_UNIT (p) = NULL;
2268 /* If this arg must go in memory, put it in a pseudo here.
2269 We can't allow it to go in memory as per normal parms,
2270 because the usual place might not have the imag part
2271 adjacent to the real part. */
2272 DECL_ARTIFICIAL (p) = addressable;
2273 DECL_IGNORED_P (p) = addressable;
2274 TREE_ADDRESSABLE (p) = 0;
2275 layout_decl (p, 0);
2276 (*args)[i] = p;
2277
2278 /* Build a second synthetic decl. */
2279 decl = build_decl (EXPR_LOCATION (p),
2280 PARM_DECL, NULL_TREE, subtype);
2281 DECL_ARG_TYPE (decl) = DECL_ARG_TYPE (p);
2282 DECL_ARTIFICIAL (decl) = addressable;
2283 DECL_IGNORED_P (decl) = addressable;
2284 layout_decl (decl, 0);
2285 args->safe_insert (++i, decl);
2286 }
2287 }
2288 }
2289
2290 /* A subroutine of assign_parms. Adjust the parameter list to incorporate
2291 the hidden struct return argument, and (abi willing) complex args.
2292 Return the new parameter list. */
2293
2294 static vec<tree>
2295 assign_parms_augmented_arg_list (struct assign_parm_data_all *all)
2296 {
2297 tree fndecl = current_function_decl;
2298 tree fntype = TREE_TYPE (fndecl);
2299 vec<tree> fnargs = vNULL;
2300 tree arg;
2301
2302 for (arg = DECL_ARGUMENTS (fndecl); arg; arg = DECL_CHAIN (arg))
2303 fnargs.safe_push (arg);
2304
2305 all->orig_fnargs = DECL_ARGUMENTS (fndecl);
2306
2307 /* If struct value address is treated as the first argument, make it so. */
2308 if (aggregate_value_p (DECL_RESULT (fndecl), fndecl)
2309 && ! cfun->returns_pcc_struct
2310 && targetm.calls.struct_value_rtx (TREE_TYPE (fndecl), 1) == 0)
2311 {
2312 tree type = build_pointer_type (TREE_TYPE (fntype));
2313 tree decl;
2314
2315 decl = build_decl (DECL_SOURCE_LOCATION (fndecl),
2316 PARM_DECL, get_identifier (".result_ptr"), type);
2317 DECL_ARG_TYPE (decl) = type;
2318 DECL_ARTIFICIAL (decl) = 1;
2319 DECL_NAMELESS (decl) = 1;
2320 TREE_CONSTANT (decl) = 1;
2321
2322 DECL_CHAIN (decl) = all->orig_fnargs;
2323 all->orig_fnargs = decl;
2324 fnargs.safe_insert (0, decl);
2325
2326 all->function_result_decl = decl;
2327 }
2328
2329 /* If the target wants to split complex arguments into scalars, do so. */
2330 if (targetm.calls.split_complex_arg)
2331 split_complex_args (&fnargs);
2332
2333 return fnargs;
2334 }
2335
2336 /* A subroutine of assign_parms. Examine PARM and pull out type and mode
2337 data for the parameter. Incorporate ABI specifics such as pass-by-
2338 reference and type promotion. */
2339
2340 static void
2341 assign_parm_find_data_types (struct assign_parm_data_all *all, tree parm,
2342 struct assign_parm_data_one *data)
2343 {
2344 tree nominal_type, passed_type;
2345 enum machine_mode nominal_mode, passed_mode, promoted_mode;
2346 int unsignedp;
2347
2348 memset (data, 0, sizeof (*data));
2349
2350 /* NAMED_ARG is a misnomer. We really mean 'non-variadic'. */
2351 if (!cfun->stdarg)
2352 data->named_arg = 1; /* No variadic parms. */
2353 else if (DECL_CHAIN (parm))
2354 data->named_arg = 1; /* Not the last non-variadic parm. */
2355 else if (targetm.calls.strict_argument_naming (all->args_so_far))
2356 data->named_arg = 1; /* Only variadic ones are unnamed. */
2357 else
2358 data->named_arg = 0; /* Treat as variadic. */
2359
2360 nominal_type = TREE_TYPE (parm);
2361 passed_type = DECL_ARG_TYPE (parm);
2362
2363 /* Look out for errors propagating this far. Also, if the parameter's
2364 type is void then its value doesn't matter. */
2365 if (TREE_TYPE (parm) == error_mark_node
2366 /* This can happen after weird syntax errors
2367 or if an enum type is defined among the parms. */
2368 || TREE_CODE (parm) != PARM_DECL
2369 || passed_type == NULL
2370 || VOID_TYPE_P (nominal_type))
2371 {
2372 nominal_type = passed_type = void_type_node;
2373 nominal_mode = passed_mode = promoted_mode = VOIDmode;
2374 goto egress;
2375 }
2376
2377 /* Find mode of arg as it is passed, and mode of arg as it should be
2378 during execution of this function. */
2379 passed_mode = TYPE_MODE (passed_type);
2380 nominal_mode = TYPE_MODE (nominal_type);
2381
2382 /* If the parm is to be passed as a transparent union or record, use the
2383 type of the first field for the tests below. We have already verified
2384 that the modes are the same. */
2385 if ((TREE_CODE (passed_type) == UNION_TYPE
2386 || TREE_CODE (passed_type) == RECORD_TYPE)
2387 && TYPE_TRANSPARENT_AGGR (passed_type))
2388 passed_type = TREE_TYPE (first_field (passed_type));
2389
2390 /* See if this arg was passed by invisible reference. */
2391 if (pass_by_reference (&all->args_so_far_v, passed_mode,
2392 passed_type, data->named_arg))
2393 {
2394 passed_type = nominal_type = build_pointer_type (passed_type);
2395 data->passed_pointer = true;
2396 passed_mode = nominal_mode = TYPE_MODE (nominal_type);
2397 }
2398
2399 /* Find mode as it is passed by the ABI. */
2400 unsignedp = TYPE_UNSIGNED (passed_type);
2401 promoted_mode = promote_function_mode (passed_type, passed_mode, &unsignedp,
2402 TREE_TYPE (current_function_decl), 0);
2403
2404 egress:
2405 data->nominal_type = nominal_type;
2406 data->passed_type = passed_type;
2407 data->nominal_mode = nominal_mode;
2408 data->passed_mode = passed_mode;
2409 data->promoted_mode = promoted_mode;
2410 }
2411
2412 /* A subroutine of assign_parms. Invoke setup_incoming_varargs. */
2413
2414 static void
2415 assign_parms_setup_varargs (struct assign_parm_data_all *all,
2416 struct assign_parm_data_one *data, bool no_rtl)
2417 {
2418 int varargs_pretend_bytes = 0;
2419
2420 targetm.calls.setup_incoming_varargs (all->args_so_far,
2421 data->promoted_mode,
2422 data->passed_type,
2423 &varargs_pretend_bytes, no_rtl);
2424
2425 /* If the back-end has requested extra stack space, record how much is
2426 needed. Do not change pretend_args_size otherwise since it may be
2427 nonzero from an earlier partial argument. */
2428 if (varargs_pretend_bytes > 0)
2429 all->pretend_args_size = varargs_pretend_bytes;
2430 }
2431
2432 /* A subroutine of assign_parms. Set DATA->ENTRY_PARM corresponding to
2433 the incoming location of the current parameter. */
2434
2435 static void
2436 assign_parm_find_entry_rtl (struct assign_parm_data_all *all,
2437 struct assign_parm_data_one *data)
2438 {
2439 HOST_WIDE_INT pretend_bytes = 0;
2440 rtx entry_parm;
2441 bool in_regs;
2442
2443 if (data->promoted_mode == VOIDmode)
2444 {
2445 data->entry_parm = data->stack_parm = const0_rtx;
2446 return;
2447 }
2448
2449 entry_parm = targetm.calls.function_incoming_arg (all->args_so_far,
2450 data->promoted_mode,
2451 data->passed_type,
2452 data->named_arg);
2453
2454 if (entry_parm == 0)
2455 data->promoted_mode = data->passed_mode;
2456
2457 /* Determine parm's home in the stack, in case it arrives in the stack
2458 or we should pretend it did. Compute the stack position and rtx where
2459 the argument arrives and its size.
2460
2461 There is one complexity here: If this was a parameter that would
2462 have been passed in registers, but wasn't only because it is
2463 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
2464 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
2465 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of 0
2466 as it was the previous time. */
2467 in_regs = entry_parm != 0;
2468 #ifdef STACK_PARMS_IN_REG_PARM_AREA
2469 in_regs = true;
2470 #endif
2471 if (!in_regs && !data->named_arg)
2472 {
2473 if (targetm.calls.pretend_outgoing_varargs_named (all->args_so_far))
2474 {
2475 rtx tem;
2476 tem = targetm.calls.function_incoming_arg (all->args_so_far,
2477 data->promoted_mode,
2478 data->passed_type, true);
2479 in_regs = tem != NULL;
2480 }
2481 }
2482
2483 /* If this parameter was passed both in registers and in the stack, use
2484 the copy on the stack. */
2485 if (targetm.calls.must_pass_in_stack (data->promoted_mode,
2486 data->passed_type))
2487 entry_parm = 0;
2488
2489 if (entry_parm)
2490 {
2491 int partial;
2492
2493 partial = targetm.calls.arg_partial_bytes (all->args_so_far,
2494 data->promoted_mode,
2495 data->passed_type,
2496 data->named_arg);
2497 data->partial = partial;
2498
2499 /* The caller might already have allocated stack space for the
2500 register parameters. */
2501 if (partial != 0 && all->reg_parm_stack_space == 0)
2502 {
2503 /* Part of this argument is passed in registers and part
2504 is passed on the stack. Ask the prologue code to extend
2505 the stack part so that we can recreate the full value.
2506
2507 PRETEND_BYTES is the size of the registers we need to store.
2508 CURRENT_FUNCTION_PRETEND_ARGS_SIZE is the amount of extra
2509 stack space that the prologue should allocate.
2510
2511 Internally, gcc assumes that the argument pointer is aligned
2512 to STACK_BOUNDARY bits. This is used both for alignment
2513 optimizations (see init_emit) and to locate arguments that are
2514 aligned to more than PARM_BOUNDARY bits. We must preserve this
2515 invariant by rounding CURRENT_FUNCTION_PRETEND_ARGS_SIZE up to
2516 a stack boundary. */
2517
2518 /* We assume at most one partial arg, and it must be the first
2519 argument on the stack. */
2520 gcc_assert (!all->extra_pretend_bytes && !all->pretend_args_size);
2521
2522 pretend_bytes = partial;
2523 all->pretend_args_size = CEIL_ROUND (pretend_bytes, STACK_BYTES);
2524
2525 /* We want to align relative to the actual stack pointer, so
2526 don't include this in the stack size until later. */
2527 all->extra_pretend_bytes = all->pretend_args_size;
2528 }
2529 }
2530
2531 locate_and_pad_parm (data->promoted_mode, data->passed_type, in_regs,
2532 all->reg_parm_stack_space,
2533 entry_parm ? data->partial : 0, current_function_decl,
2534 &all->stack_args_size, &data->locate);
2535
2536 /* Update parm_stack_boundary if this parameter is passed in the
2537 stack. */
2538 if (!in_regs && crtl->parm_stack_boundary < data->locate.boundary)
2539 crtl->parm_stack_boundary = data->locate.boundary;
2540
2541 /* Adjust offsets to include the pretend args. */
2542 pretend_bytes = all->extra_pretend_bytes - pretend_bytes;
2543 data->locate.slot_offset.constant += pretend_bytes;
2544 data->locate.offset.constant += pretend_bytes;
2545
2546 data->entry_parm = entry_parm;
2547 }
2548
2549 /* A subroutine of assign_parms. If there is actually space on the stack
2550 for this parm, count it in stack_args_size and return true. */
2551
2552 static bool
2553 assign_parm_is_stack_parm (struct assign_parm_data_all *all,
2554 struct assign_parm_data_one *data)
2555 {
2556 /* Trivially true if we've no incoming register. */
2557 if (data->entry_parm == NULL)
2558 ;
2559 /* Also true if we're partially in registers and partially not,
2560 since we've arranged to drop the entire argument on the stack. */
2561 else if (data->partial != 0)
2562 ;
2563 /* Also true if the target says that it's passed in both registers
2564 and on the stack. */
2565 else if (GET_CODE (data->entry_parm) == PARALLEL
2566 && XEXP (XVECEXP (data->entry_parm, 0, 0), 0) == NULL_RTX)
2567 ;
2568 /* Also true if the target says that there's stack allocated for
2569 all register parameters. */
2570 else if (all->reg_parm_stack_space > 0)
2571 ;
2572 /* Otherwise, no, this parameter has no ABI defined stack slot. */
2573 else
2574 return false;
2575
2576 all->stack_args_size.constant += data->locate.size.constant;
2577 if (data->locate.size.var)
2578 ADD_PARM_SIZE (all->stack_args_size, data->locate.size.var);
2579
2580 return true;
2581 }
2582
2583 /* A subroutine of assign_parms. Given that this parameter is allocated
2584 stack space by the ABI, find it. */
2585
2586 static void
2587 assign_parm_find_stack_rtl (tree parm, struct assign_parm_data_one *data)
2588 {
2589 rtx offset_rtx, stack_parm;
2590 unsigned int align, boundary;
2591
2592 /* If we're passing this arg using a reg, make its stack home the
2593 aligned stack slot. */
2594 if (data->entry_parm)
2595 offset_rtx = ARGS_SIZE_RTX (data->locate.slot_offset);
2596 else
2597 offset_rtx = ARGS_SIZE_RTX (data->locate.offset);
2598
2599 stack_parm = crtl->args.internal_arg_pointer;
2600 if (offset_rtx != const0_rtx)
2601 stack_parm = gen_rtx_PLUS (Pmode, stack_parm, offset_rtx);
2602 stack_parm = gen_rtx_MEM (data->promoted_mode, stack_parm);
2603
2604 if (!data->passed_pointer)
2605 {
2606 set_mem_attributes (stack_parm, parm, 1);
2607 /* set_mem_attributes could set MEM_SIZE to the passed mode's size,
2608 while promoted mode's size is needed. */
2609 if (data->promoted_mode != BLKmode
2610 && data->promoted_mode != DECL_MODE (parm))
2611 {
2612 set_mem_size (stack_parm, GET_MODE_SIZE (data->promoted_mode));
2613 if (MEM_EXPR (stack_parm) && MEM_OFFSET_KNOWN_P (stack_parm))
2614 {
2615 int offset = subreg_lowpart_offset (DECL_MODE (parm),
2616 data->promoted_mode);
2617 if (offset)
2618 set_mem_offset (stack_parm, MEM_OFFSET (stack_parm) - offset);
2619 }
2620 }
2621 }
2622
2623 boundary = data->locate.boundary;
2624 align = BITS_PER_UNIT;
2625
2626 /* If we're padding upward, we know that the alignment of the slot
2627 is TARGET_FUNCTION_ARG_BOUNDARY. If we're using slot_offset, we're
2628 intentionally forcing upward padding. Otherwise we have to come
2629 up with a guess at the alignment based on OFFSET_RTX. */
2630 if (data->locate.where_pad != downward || data->entry_parm)
2631 align = boundary;
2632 else if (CONST_INT_P (offset_rtx))
2633 {
2634 align = INTVAL (offset_rtx) * BITS_PER_UNIT | boundary;
2635 align = align & -align;
2636 }
2637 set_mem_align (stack_parm, align);
2638
2639 if (data->entry_parm)
2640 set_reg_attrs_for_parm (data->entry_parm, stack_parm);
2641
2642 data->stack_parm = stack_parm;
2643 }
2644
2645 /* A subroutine of assign_parms. Adjust DATA->ENTRY_RTL such that it's
2646 always valid and contiguous. */
2647
2648 static void
2649 assign_parm_adjust_entry_rtl (struct assign_parm_data_one *data)
2650 {
2651 rtx entry_parm = data->entry_parm;
2652 rtx stack_parm = data->stack_parm;
2653
2654 /* If this parm was passed part in regs and part in memory, pretend it
2655 arrived entirely in memory by pushing the register-part onto the stack.
2656 In the special case of a DImode or DFmode that is split, we could put
2657 it together in a pseudoreg directly, but for now that's not worth
2658 bothering with. */
2659 if (data->partial != 0)
2660 {
2661 /* Handle calls that pass values in multiple non-contiguous
2662 locations. The Irix 6 ABI has examples of this. */
2663 if (GET_CODE (entry_parm) == PARALLEL)
2664 emit_group_store (validize_mem (copy_rtx (stack_parm)), entry_parm,
2665 data->passed_type,
2666 int_size_in_bytes (data->passed_type));
2667 else
2668 {
2669 gcc_assert (data->partial % UNITS_PER_WORD == 0);
2670 move_block_from_reg (REGNO (entry_parm),
2671 validize_mem (copy_rtx (stack_parm)),
2672 data->partial / UNITS_PER_WORD);
2673 }
2674
2675 entry_parm = stack_parm;
2676 }
2677
2678 /* If we didn't decide this parm came in a register, by default it came
2679 on the stack. */
2680 else if (entry_parm == NULL)
2681 entry_parm = stack_parm;
2682
2683 /* When an argument is passed in multiple locations, we can't make use
2684 of this information, but we can save some copying if the whole argument
2685 is passed in a single register. */
2686 else if (GET_CODE (entry_parm) == PARALLEL
2687 && data->nominal_mode != BLKmode
2688 && data->passed_mode != BLKmode)
2689 {
2690 size_t i, len = XVECLEN (entry_parm, 0);
2691
2692 for (i = 0; i < len; i++)
2693 if (XEXP (XVECEXP (entry_parm, 0, i), 0) != NULL_RTX
2694 && REG_P (XEXP (XVECEXP (entry_parm, 0, i), 0))
2695 && (GET_MODE (XEXP (XVECEXP (entry_parm, 0, i), 0))
2696 == data->passed_mode)
2697 && INTVAL (XEXP (XVECEXP (entry_parm, 0, i), 1)) == 0)
2698 {
2699 entry_parm = XEXP (XVECEXP (entry_parm, 0, i), 0);
2700 break;
2701 }
2702 }
2703
2704 data->entry_parm = entry_parm;
2705 }
2706
2707 /* A subroutine of assign_parms. Reconstitute any values which were
2708 passed in multiple registers and would fit in a single register. */
2709
2710 static void
2711 assign_parm_remove_parallels (struct assign_parm_data_one *data)
2712 {
2713 rtx entry_parm = data->entry_parm;
2714
2715 /* Convert the PARALLEL to a REG of the same mode as the parallel.
2716 This can be done with register operations rather than on the
2717 stack, even if we will store the reconstituted parameter on the
2718 stack later. */
2719 if (GET_CODE (entry_parm) == PARALLEL && GET_MODE (entry_parm) != BLKmode)
2720 {
2721 rtx parmreg = gen_reg_rtx (GET_MODE (entry_parm));
2722 emit_group_store (parmreg, entry_parm, data->passed_type,
2723 GET_MODE_SIZE (GET_MODE (entry_parm)));
2724 entry_parm = parmreg;
2725 }
2726
2727 data->entry_parm = entry_parm;
2728 }
2729
2730 /* A subroutine of assign_parms. Adjust DATA->STACK_RTL such that it's
2731 always valid and properly aligned. */
2732
2733 static void
2734 assign_parm_adjust_stack_rtl (struct assign_parm_data_one *data)
2735 {
2736 rtx stack_parm = data->stack_parm;
2737
2738 /* If we can't trust the parm stack slot to be aligned enough for its
2739 ultimate type, don't use that slot after entry. We'll make another
2740 stack slot, if we need one. */
2741 if (stack_parm
2742 && ((STRICT_ALIGNMENT
2743 && GET_MODE_ALIGNMENT (data->nominal_mode) > MEM_ALIGN (stack_parm))
2744 || (data->nominal_type
2745 && TYPE_ALIGN (data->nominal_type) > MEM_ALIGN (stack_parm)
2746 && MEM_ALIGN (stack_parm) < PREFERRED_STACK_BOUNDARY)))
2747 stack_parm = NULL;
2748
2749 /* If parm was passed in memory, and we need to convert it on entry,
2750 don't store it back in that same slot. */
2751 else if (data->entry_parm == stack_parm
2752 && data->nominal_mode != BLKmode
2753 && data->nominal_mode != data->passed_mode)
2754 stack_parm = NULL;
2755
2756 /* If stack protection is in effect for this function, don't leave any
2757 pointers in their passed stack slots. */
2758 else if (crtl->stack_protect_guard
2759 && (flag_stack_protect == 2
2760 || data->passed_pointer
2761 || POINTER_TYPE_P (data->nominal_type)))
2762 stack_parm = NULL;
2763
2764 data->stack_parm = stack_parm;
2765 }
2766
2767 /* A subroutine of assign_parms. Return true if the current parameter
2768 should be stored as a BLKmode in the current frame. */
2769
2770 static bool
2771 assign_parm_setup_block_p (struct assign_parm_data_one *data)
2772 {
2773 if (data->nominal_mode == BLKmode)
2774 return true;
2775 if (GET_MODE (data->entry_parm) == BLKmode)
2776 return true;
2777
2778 #ifdef BLOCK_REG_PADDING
2779 /* Only assign_parm_setup_block knows how to deal with register arguments
2780 that are padded at the least significant end. */
2781 if (REG_P (data->entry_parm)
2782 && GET_MODE_SIZE (data->promoted_mode) < UNITS_PER_WORD
2783 && (BLOCK_REG_PADDING (data->passed_mode, data->passed_type, 1)
2784 == (BYTES_BIG_ENDIAN ? upward : downward)))
2785 return true;
2786 #endif
2787
2788 return false;
2789 }
2790
2791 /* A subroutine of assign_parms. Arrange for the parameter to be
2792 present and valid in DATA->STACK_RTL. */
2793
2794 static void
2795 assign_parm_setup_block (struct assign_parm_data_all *all,
2796 tree parm, struct assign_parm_data_one *data)
2797 {
2798 rtx entry_parm = data->entry_parm;
2799 rtx stack_parm = data->stack_parm;
2800 HOST_WIDE_INT size;
2801 HOST_WIDE_INT size_stored;
2802
2803 if (GET_CODE (entry_parm) == PARALLEL)
2804 entry_parm = emit_group_move_into_temps (entry_parm);
2805
2806 size = int_size_in_bytes (data->passed_type);
2807 size_stored = CEIL_ROUND (size, UNITS_PER_WORD);
2808 if (stack_parm == 0)
2809 {
2810 DECL_ALIGN (parm) = MAX (DECL_ALIGN (parm), BITS_PER_WORD);
2811 stack_parm = assign_stack_local (BLKmode, size_stored,
2812 DECL_ALIGN (parm));
2813 if (GET_MODE_SIZE (GET_MODE (entry_parm)) == size)
2814 PUT_MODE (stack_parm, GET_MODE (entry_parm));
2815 set_mem_attributes (stack_parm, parm, 1);
2816 }
2817
2818 /* If a BLKmode arrives in registers, copy it to a stack slot. Handle
2819 calls that pass values in multiple non-contiguous locations. */
2820 if (REG_P (entry_parm) || GET_CODE (entry_parm) == PARALLEL)
2821 {
2822 rtx mem;
2823
2824 /* Note that we will be storing an integral number of words.
2825 So we have to be careful to ensure that we allocate an
2826 integral number of words. We do this above when we call
2827 assign_stack_local if space was not allocated in the argument
2828 list. If it was, this will not work if PARM_BOUNDARY is not
2829 a multiple of BITS_PER_WORD. It isn't clear how to fix this
2830 if it becomes a problem. Exception is when BLKmode arrives
2831 with arguments not conforming to word_mode. */
2832
2833 if (data->stack_parm == 0)
2834 ;
2835 else if (GET_CODE (entry_parm) == PARALLEL)
2836 ;
2837 else
2838 gcc_assert (!size || !(PARM_BOUNDARY % BITS_PER_WORD));
2839
2840 mem = validize_mem (copy_rtx (stack_parm));
2841
2842 /* Handle values in multiple non-contiguous locations. */
2843 if (GET_CODE (entry_parm) == PARALLEL)
2844 {
2845 push_to_sequence2 (all->first_conversion_insn,
2846 all->last_conversion_insn);
2847 emit_group_store (mem, entry_parm, data->passed_type, size);
2848 all->first_conversion_insn = get_insns ();
2849 all->last_conversion_insn = get_last_insn ();
2850 end_sequence ();
2851 }
2852
2853 else if (size == 0)
2854 ;
2855
2856 /* If SIZE is that of a mode no bigger than a word, just use
2857 that mode's store operation. */
2858 else if (size <= UNITS_PER_WORD)
2859 {
2860 enum machine_mode mode
2861 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
2862
2863 if (mode != BLKmode
2864 #ifdef BLOCK_REG_PADDING
2865 && (size == UNITS_PER_WORD
2866 || (BLOCK_REG_PADDING (mode, data->passed_type, 1)
2867 != (BYTES_BIG_ENDIAN ? upward : downward)))
2868 #endif
2869 )
2870 {
2871 rtx reg;
2872
2873 /* We are really truncating a word_mode value containing
2874 SIZE bytes into a value of mode MODE. If such an
2875 operation requires no actual instructions, we can refer
2876 to the value directly in mode MODE, otherwise we must
2877 start with the register in word_mode and explicitly
2878 convert it. */
2879 if (TRULY_NOOP_TRUNCATION (size * BITS_PER_UNIT, BITS_PER_WORD))
2880 reg = gen_rtx_REG (mode, REGNO (entry_parm));
2881 else
2882 {
2883 reg = gen_rtx_REG (word_mode, REGNO (entry_parm));
2884 reg = convert_to_mode (mode, copy_to_reg (reg), 1);
2885 }
2886 emit_move_insn (change_address (mem, mode, 0), reg);
2887 }
2888
2889 /* Blocks smaller than a word on a BYTES_BIG_ENDIAN
2890 machine must be aligned to the left before storing
2891 to memory. Note that the previous test doesn't
2892 handle all cases (e.g. SIZE == 3). */
2893 else if (size != UNITS_PER_WORD
2894 #ifdef BLOCK_REG_PADDING
2895 && (BLOCK_REG_PADDING (mode, data->passed_type, 1)
2896 == downward)
2897 #else
2898 && BYTES_BIG_ENDIAN
2899 #endif
2900 )
2901 {
2902 rtx tem, x;
2903 int by = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
2904 rtx reg = gen_rtx_REG (word_mode, REGNO (entry_parm));
2905
2906 x = expand_shift (LSHIFT_EXPR, word_mode, reg, by, NULL_RTX, 1);
2907 tem = change_address (mem, word_mode, 0);
2908 emit_move_insn (tem, x);
2909 }
2910 else
2911 move_block_from_reg (REGNO (entry_parm), mem,
2912 size_stored / UNITS_PER_WORD);
2913 }
2914 else
2915 move_block_from_reg (REGNO (entry_parm), mem,
2916 size_stored / UNITS_PER_WORD);
2917 }
2918 else if (data->stack_parm == 0)
2919 {
2920 push_to_sequence2 (all->first_conversion_insn, all->last_conversion_insn);
2921 emit_block_move (stack_parm, data->entry_parm, GEN_INT (size),
2922 BLOCK_OP_NORMAL);
2923 all->first_conversion_insn = get_insns ();
2924 all->last_conversion_insn = get_last_insn ();
2925 end_sequence ();
2926 }
2927
2928 data->stack_parm = stack_parm;
2929 SET_DECL_RTL (parm, stack_parm);
2930 }
2931
2932 /* A subroutine of assign_parms. Allocate a pseudo to hold the current
2933 parameter. Get it there. Perform all ABI specified conversions. */
2934
2935 static void
2936 assign_parm_setup_reg (struct assign_parm_data_all *all, tree parm,
2937 struct assign_parm_data_one *data)
2938 {
2939 rtx parmreg, validated_mem;
2940 rtx equiv_stack_parm;
2941 enum machine_mode promoted_nominal_mode;
2942 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (parm));
2943 bool did_conversion = false;
2944 bool need_conversion, moved;
2945
2946 /* Store the parm in a pseudoregister during the function, but we may
2947 need to do it in a wider mode. Using 2 here makes the result
2948 consistent with promote_decl_mode and thus expand_expr_real_1. */
2949 promoted_nominal_mode
2950 = promote_function_mode (data->nominal_type, data->nominal_mode, &unsignedp,
2951 TREE_TYPE (current_function_decl), 2);
2952
2953 parmreg = gen_reg_rtx (promoted_nominal_mode);
2954
2955 if (!DECL_ARTIFICIAL (parm))
2956 mark_user_reg (parmreg);
2957
2958 /* If this was an item that we received a pointer to,
2959 set DECL_RTL appropriately. */
2960 if (data->passed_pointer)
2961 {
2962 rtx x = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (data->passed_type)), parmreg);
2963 set_mem_attributes (x, parm, 1);
2964 SET_DECL_RTL (parm, x);
2965 }
2966 else
2967 SET_DECL_RTL (parm, parmreg);
2968
2969 assign_parm_remove_parallels (data);
2970
2971 /* Copy the value into the register, thus bridging between
2972 assign_parm_find_data_types and expand_expr_real_1. */
2973
2974 equiv_stack_parm = data->stack_parm;
2975 validated_mem = validize_mem (copy_rtx (data->entry_parm));
2976
2977 need_conversion = (data->nominal_mode != data->passed_mode
2978 || promoted_nominal_mode != data->promoted_mode);
2979 moved = false;
2980
2981 if (need_conversion
2982 && GET_MODE_CLASS (data->nominal_mode) == MODE_INT
2983 && data->nominal_mode == data->passed_mode
2984 && data->nominal_mode == GET_MODE (data->entry_parm))
2985 {
2986 /* ENTRY_PARM has been converted to PROMOTED_MODE, its
2987 mode, by the caller. We now have to convert it to
2988 NOMINAL_MODE, if different. However, PARMREG may be in
2989 a different mode than NOMINAL_MODE if it is being stored
2990 promoted.
2991
2992 If ENTRY_PARM is a hard register, it might be in a register
2993 not valid for operating in its mode (e.g., an odd-numbered
2994 register for a DFmode). In that case, moves are the only
2995 thing valid, so we can't do a convert from there. This
2996 occurs when the calling sequence allow such misaligned
2997 usages.
2998
2999 In addition, the conversion may involve a call, which could
3000 clobber parameters which haven't been copied to pseudo
3001 registers yet.
3002
3003 First, we try to emit an insn which performs the necessary
3004 conversion. We verify that this insn does not clobber any
3005 hard registers. */
3006
3007 enum insn_code icode;
3008 rtx op0, op1;
3009
3010 icode = can_extend_p (promoted_nominal_mode, data->passed_mode,
3011 unsignedp);
3012
3013 op0 = parmreg;
3014 op1 = validated_mem;
3015 if (icode != CODE_FOR_nothing
3016 && insn_operand_matches (icode, 0, op0)
3017 && insn_operand_matches (icode, 1, op1))
3018 {
3019 enum rtx_code code = unsignedp ? ZERO_EXTEND : SIGN_EXTEND;
3020 rtx_insn *insn, *insns;
3021 rtx t = op1;
3022 HARD_REG_SET hardregs;
3023
3024 start_sequence ();
3025 /* If op1 is a hard register that is likely spilled, first
3026 force it into a pseudo, otherwise combiner might extend
3027 its lifetime too much. */
3028 if (GET_CODE (t) == SUBREG)
3029 t = SUBREG_REG (t);
3030 if (REG_P (t)
3031 && HARD_REGISTER_P (t)
3032 && ! TEST_HARD_REG_BIT (fixed_reg_set, REGNO (t))
3033 && targetm.class_likely_spilled_p (REGNO_REG_CLASS (REGNO (t))))
3034 {
3035 t = gen_reg_rtx (GET_MODE (op1));
3036 emit_move_insn (t, op1);
3037 }
3038 else
3039 t = op1;
3040 rtx pat = gen_extend_insn (op0, t, promoted_nominal_mode,
3041 data->passed_mode, unsignedp);
3042 emit_insn (pat);
3043 insns = get_insns ();
3044
3045 moved = true;
3046 CLEAR_HARD_REG_SET (hardregs);
3047 for (insn = insns; insn && moved; insn = NEXT_INSN (insn))
3048 {
3049 if (INSN_P (insn))
3050 note_stores (PATTERN (insn), record_hard_reg_sets,
3051 &hardregs);
3052 if (!hard_reg_set_empty_p (hardregs))
3053 moved = false;
3054 }
3055
3056 end_sequence ();
3057
3058 if (moved)
3059 {
3060 emit_insn (insns);
3061 if (equiv_stack_parm != NULL_RTX)
3062 equiv_stack_parm = gen_rtx_fmt_e (code, GET_MODE (parmreg),
3063 equiv_stack_parm);
3064 }
3065 }
3066 }
3067
3068 if (moved)
3069 /* Nothing to do. */
3070 ;
3071 else if (need_conversion)
3072 {
3073 /* We did not have an insn to convert directly, or the sequence
3074 generated appeared unsafe. We must first copy the parm to a
3075 pseudo reg, and save the conversion until after all
3076 parameters have been moved. */
3077
3078 int save_tree_used;
3079 rtx tempreg = gen_reg_rtx (GET_MODE (data->entry_parm));
3080
3081 emit_move_insn (tempreg, validated_mem);
3082
3083 push_to_sequence2 (all->first_conversion_insn, all->last_conversion_insn);
3084 tempreg = convert_to_mode (data->nominal_mode, tempreg, unsignedp);
3085
3086 if (GET_CODE (tempreg) == SUBREG
3087 && GET_MODE (tempreg) == data->nominal_mode
3088 && REG_P (SUBREG_REG (tempreg))
3089 && data->nominal_mode == data->passed_mode
3090 && GET_MODE (SUBREG_REG (tempreg)) == GET_MODE (data->entry_parm)
3091 && GET_MODE_SIZE (GET_MODE (tempreg))
3092 < GET_MODE_SIZE (GET_MODE (data->entry_parm)))
3093 {
3094 /* The argument is already sign/zero extended, so note it
3095 into the subreg. */
3096 SUBREG_PROMOTED_VAR_P (tempreg) = 1;
3097 SUBREG_PROMOTED_SET (tempreg, unsignedp);
3098 }
3099
3100 /* TREE_USED gets set erroneously during expand_assignment. */
3101 save_tree_used = TREE_USED (parm);
3102 expand_assignment (parm, make_tree (data->nominal_type, tempreg), false);
3103 TREE_USED (parm) = save_tree_used;
3104 all->first_conversion_insn = get_insns ();
3105 all->last_conversion_insn = get_last_insn ();
3106 end_sequence ();
3107
3108 did_conversion = true;
3109 }
3110 else
3111 emit_move_insn (parmreg, validated_mem);
3112
3113 /* If we were passed a pointer but the actual value can safely live
3114 in a register, retrieve it and use it directly. */
3115 if (data->passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode)
3116 {
3117 /* We can't use nominal_mode, because it will have been set to
3118 Pmode above. We must use the actual mode of the parm. */
3119 if (use_register_for_decl (parm))
3120 {
3121 parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
3122 mark_user_reg (parmreg);
3123 }
3124 else
3125 {
3126 int align = STACK_SLOT_ALIGNMENT (TREE_TYPE (parm),
3127 TYPE_MODE (TREE_TYPE (parm)),
3128 TYPE_ALIGN (TREE_TYPE (parm)));
3129 parmreg
3130 = assign_stack_local (TYPE_MODE (TREE_TYPE (parm)),
3131 GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parm))),
3132 align);
3133 set_mem_attributes (parmreg, parm, 1);
3134 }
3135
3136 if (GET_MODE (parmreg) != GET_MODE (DECL_RTL (parm)))
3137 {
3138 rtx tempreg = gen_reg_rtx (GET_MODE (DECL_RTL (parm)));
3139 int unsigned_p = TYPE_UNSIGNED (TREE_TYPE (parm));
3140
3141 push_to_sequence2 (all->first_conversion_insn,
3142 all->last_conversion_insn);
3143 emit_move_insn (tempreg, DECL_RTL (parm));
3144 tempreg = convert_to_mode (GET_MODE (parmreg), tempreg, unsigned_p);
3145 emit_move_insn (parmreg, tempreg);
3146 all->first_conversion_insn = get_insns ();
3147 all->last_conversion_insn = get_last_insn ();
3148 end_sequence ();
3149
3150 did_conversion = true;
3151 }
3152 else
3153 emit_move_insn (parmreg, DECL_RTL (parm));
3154
3155 SET_DECL_RTL (parm, parmreg);
3156
3157 /* STACK_PARM is the pointer, not the parm, and PARMREG is
3158 now the parm. */
3159 data->stack_parm = NULL;
3160 }
3161
3162 /* Mark the register as eliminable if we did no conversion and it was
3163 copied from memory at a fixed offset, and the arg pointer was not
3164 copied to a pseudo-reg. If the arg pointer is a pseudo reg or the
3165 offset formed an invalid address, such memory-equivalences as we
3166 make here would screw up life analysis for it. */
3167 if (data->nominal_mode == data->passed_mode
3168 && !did_conversion
3169 && data->stack_parm != 0
3170 && MEM_P (data->stack_parm)
3171 && data->locate.offset.var == 0
3172 && reg_mentioned_p (virtual_incoming_args_rtx,
3173 XEXP (data->stack_parm, 0)))
3174 {
3175 rtx_insn *linsn = get_last_insn ();
3176 rtx_insn *sinsn;
3177 rtx set;
3178
3179 /* Mark complex types separately. */
3180 if (GET_CODE (parmreg) == CONCAT)
3181 {
3182 enum machine_mode submode
3183 = GET_MODE_INNER (GET_MODE (parmreg));
3184 int regnor = REGNO (XEXP (parmreg, 0));
3185 int regnoi = REGNO (XEXP (parmreg, 1));
3186 rtx stackr = adjust_address_nv (data->stack_parm, submode, 0);
3187 rtx stacki = adjust_address_nv (data->stack_parm, submode,
3188 GET_MODE_SIZE (submode));
3189
3190 /* Scan backwards for the set of the real and
3191 imaginary parts. */
3192 for (sinsn = linsn; sinsn != 0;
3193 sinsn = prev_nonnote_insn (sinsn))
3194 {
3195 set = single_set (sinsn);
3196 if (set == 0)
3197 continue;
3198
3199 if (SET_DEST (set) == regno_reg_rtx [regnoi])
3200 set_unique_reg_note (sinsn, REG_EQUIV, stacki);
3201 else if (SET_DEST (set) == regno_reg_rtx [regnor])
3202 set_unique_reg_note (sinsn, REG_EQUIV, stackr);
3203 }
3204 }
3205 else
3206 set_dst_reg_note (linsn, REG_EQUIV, equiv_stack_parm, parmreg);
3207 }
3208
3209 /* For pointer data type, suggest pointer register. */
3210 if (POINTER_TYPE_P (TREE_TYPE (parm)))
3211 mark_reg_pointer (parmreg,
3212 TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm))));
3213 }
3214
3215 /* A subroutine of assign_parms. Allocate stack space to hold the current
3216 parameter. Get it there. Perform all ABI specified conversions. */
3217
3218 static void
3219 assign_parm_setup_stack (struct assign_parm_data_all *all, tree parm,
3220 struct assign_parm_data_one *data)
3221 {
3222 /* Value must be stored in the stack slot STACK_PARM during function
3223 execution. */
3224 bool to_conversion = false;
3225
3226 assign_parm_remove_parallels (data);
3227
3228 if (data->promoted_mode != data->nominal_mode)
3229 {
3230 /* Conversion is required. */
3231 rtx tempreg = gen_reg_rtx (GET_MODE (data->entry_parm));
3232
3233 emit_move_insn (tempreg, validize_mem (copy_rtx (data->entry_parm)));
3234
3235 push_to_sequence2 (all->first_conversion_insn, all->last_conversion_insn);
3236 to_conversion = true;
3237
3238 data->entry_parm = convert_to_mode (data->nominal_mode, tempreg,
3239 TYPE_UNSIGNED (TREE_TYPE (parm)));
3240
3241 if (data->stack_parm)
3242 {
3243 int offset = subreg_lowpart_offset (data->nominal_mode,
3244 GET_MODE (data->stack_parm));
3245 /* ??? This may need a big-endian conversion on sparc64. */
3246 data->stack_parm
3247 = adjust_address (data->stack_parm, data->nominal_mode, 0);
3248 if (offset && MEM_OFFSET_KNOWN_P (data->stack_parm))
3249 set_mem_offset (data->stack_parm,
3250 MEM_OFFSET (data->stack_parm) + offset);
3251 }
3252 }
3253
3254 if (data->entry_parm != data->stack_parm)
3255 {
3256 rtx src, dest;
3257
3258 if (data->stack_parm == 0)
3259 {
3260 int align = STACK_SLOT_ALIGNMENT (data->passed_type,
3261 GET_MODE (data->entry_parm),
3262 TYPE_ALIGN (data->passed_type));
3263 data->stack_parm
3264 = assign_stack_local (GET_MODE (data->entry_parm),
3265 GET_MODE_SIZE (GET_MODE (data->entry_parm)),
3266 align);
3267 set_mem_attributes (data->stack_parm, parm, 1);
3268 }
3269
3270 dest = validize_mem (copy_rtx (data->stack_parm));
3271 src = validize_mem (copy_rtx (data->entry_parm));
3272
3273 if (MEM_P (src))
3274 {
3275 /* Use a block move to handle potentially misaligned entry_parm. */
3276 if (!to_conversion)
3277 push_to_sequence2 (all->first_conversion_insn,
3278 all->last_conversion_insn);
3279 to_conversion = true;
3280
3281 emit_block_move (dest, src,
3282 GEN_INT (int_size_in_bytes (data->passed_type)),
3283 BLOCK_OP_NORMAL);
3284 }
3285 else
3286 emit_move_insn (dest, src);
3287 }
3288
3289 if (to_conversion)
3290 {
3291 all->first_conversion_insn = get_insns ();
3292 all->last_conversion_insn = get_last_insn ();
3293 end_sequence ();
3294 }
3295
3296 SET_DECL_RTL (parm, data->stack_parm);
3297 }
3298
3299 /* A subroutine of assign_parms. If the ABI splits complex arguments, then
3300 undo the frobbing that we did in assign_parms_augmented_arg_list. */
3301
3302 static void
3303 assign_parms_unsplit_complex (struct assign_parm_data_all *all,
3304 vec<tree> fnargs)
3305 {
3306 tree parm;
3307 tree orig_fnargs = all->orig_fnargs;
3308 unsigned i = 0;
3309
3310 for (parm = orig_fnargs; parm; parm = TREE_CHAIN (parm), ++i)
3311 {
3312 if (TREE_CODE (TREE_TYPE (parm)) == COMPLEX_TYPE
3313 && targetm.calls.split_complex_arg (TREE_TYPE (parm)))
3314 {
3315 rtx tmp, real, imag;
3316 enum machine_mode inner = GET_MODE_INNER (DECL_MODE (parm));
3317
3318 real = DECL_RTL (fnargs[i]);
3319 imag = DECL_RTL (fnargs[i + 1]);
3320 if (inner != GET_MODE (real))
3321 {
3322 real = gen_lowpart_SUBREG (inner, real);
3323 imag = gen_lowpart_SUBREG (inner, imag);
3324 }
3325
3326 if (TREE_ADDRESSABLE (parm))
3327 {
3328 rtx rmem, imem;
3329 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (parm));
3330 int align = STACK_SLOT_ALIGNMENT (TREE_TYPE (parm),
3331 DECL_MODE (parm),
3332 TYPE_ALIGN (TREE_TYPE (parm)));
3333
3334 /* split_complex_arg put the real and imag parts in
3335 pseudos. Move them to memory. */
3336 tmp = assign_stack_local (DECL_MODE (parm), size, align);
3337 set_mem_attributes (tmp, parm, 1);
3338 rmem = adjust_address_nv (tmp, inner, 0);
3339 imem = adjust_address_nv (tmp, inner, GET_MODE_SIZE (inner));
3340 push_to_sequence2 (all->first_conversion_insn,
3341 all->last_conversion_insn);
3342 emit_move_insn (rmem, real);
3343 emit_move_insn (imem, imag);
3344 all->first_conversion_insn = get_insns ();
3345 all->last_conversion_insn = get_last_insn ();
3346 end_sequence ();
3347 }
3348 else
3349 tmp = gen_rtx_CONCAT (DECL_MODE (parm), real, imag);
3350 SET_DECL_RTL (parm, tmp);
3351
3352 real = DECL_INCOMING_RTL (fnargs[i]);
3353 imag = DECL_INCOMING_RTL (fnargs[i + 1]);
3354 if (inner != GET_MODE (real))
3355 {
3356 real = gen_lowpart_SUBREG (inner, real);
3357 imag = gen_lowpart_SUBREG (inner, imag);
3358 }
3359 tmp = gen_rtx_CONCAT (DECL_MODE (parm), real, imag);
3360 set_decl_incoming_rtl (parm, tmp, false);
3361 i++;
3362 }
3363 }
3364 }
3365
3366 /* Assign RTL expressions to the function's parameters. This may involve
3367 copying them into registers and using those registers as the DECL_RTL. */
3368
3369 static void
3370 assign_parms (tree fndecl)
3371 {
3372 struct assign_parm_data_all all;
3373 tree parm;
3374 vec<tree> fnargs;
3375 unsigned i;
3376
3377 crtl->args.internal_arg_pointer
3378 = targetm.calls.internal_arg_pointer ();
3379
3380 assign_parms_initialize_all (&all);
3381 fnargs = assign_parms_augmented_arg_list (&all);
3382
3383 FOR_EACH_VEC_ELT (fnargs, i, parm)
3384 {
3385 struct assign_parm_data_one data;
3386
3387 /* Extract the type of PARM; adjust it according to ABI. */
3388 assign_parm_find_data_types (&all, parm, &data);
3389
3390 /* Early out for errors and void parameters. */
3391 if (data.passed_mode == VOIDmode)
3392 {
3393 SET_DECL_RTL (parm, const0_rtx);
3394 DECL_INCOMING_RTL (parm) = DECL_RTL (parm);
3395 continue;
3396 }
3397
3398 /* Estimate stack alignment from parameter alignment. */
3399 if (SUPPORTS_STACK_ALIGNMENT)
3400 {
3401 unsigned int align
3402 = targetm.calls.function_arg_boundary (data.promoted_mode,
3403 data.passed_type);
3404 align = MINIMUM_ALIGNMENT (data.passed_type, data.promoted_mode,
3405 align);
3406 if (TYPE_ALIGN (data.nominal_type) > align)
3407 align = MINIMUM_ALIGNMENT (data.nominal_type,
3408 TYPE_MODE (data.nominal_type),
3409 TYPE_ALIGN (data.nominal_type));
3410 if (crtl->stack_alignment_estimated < align)
3411 {
3412 gcc_assert (!crtl->stack_realign_processed);
3413 crtl->stack_alignment_estimated = align;
3414 }
3415 }
3416
3417 if (cfun->stdarg && !DECL_CHAIN (parm))
3418 assign_parms_setup_varargs (&all, &data, false);
3419
3420 /* Find out where the parameter arrives in this function. */
3421 assign_parm_find_entry_rtl (&all, &data);
3422
3423 /* Find out where stack space for this parameter might be. */
3424 if (assign_parm_is_stack_parm (&all, &data))
3425 {
3426 assign_parm_find_stack_rtl (parm, &data);
3427 assign_parm_adjust_entry_rtl (&data);
3428 }
3429
3430 /* Record permanently how this parm was passed. */
3431 if (data.passed_pointer)
3432 {
3433 rtx incoming_rtl
3434 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (data.passed_type)),
3435 data.entry_parm);
3436 set_decl_incoming_rtl (parm, incoming_rtl, true);
3437 }
3438 else
3439 set_decl_incoming_rtl (parm, data.entry_parm, false);
3440
3441 /* Update info on where next arg arrives in registers. */
3442 targetm.calls.function_arg_advance (all.args_so_far, data.promoted_mode,
3443 data.passed_type, data.named_arg);
3444
3445 assign_parm_adjust_stack_rtl (&data);
3446
3447 if (assign_parm_setup_block_p (&data))
3448 assign_parm_setup_block (&all, parm, &data);
3449 else if (data.passed_pointer || use_register_for_decl (parm))
3450 assign_parm_setup_reg (&all, parm, &data);
3451 else
3452 assign_parm_setup_stack (&all, parm, &data);
3453 }
3454
3455 if (targetm.calls.split_complex_arg)
3456 assign_parms_unsplit_complex (&all, fnargs);
3457
3458 fnargs.release ();
3459
3460 /* Initialize pic_offset_table_rtx with a pseudo register
3461 if required. */
3462 if (targetm.use_pseudo_pic_reg ())
3463 pic_offset_table_rtx = gen_reg_rtx (Pmode);
3464
3465 /* Output all parameter conversion instructions (possibly including calls)
3466 now that all parameters have been copied out of hard registers. */
3467 emit_insn (all.first_conversion_insn);
3468
3469 /* Estimate reload stack alignment from scalar return mode. */
3470 if (SUPPORTS_STACK_ALIGNMENT)
3471 {
3472 if (DECL_RESULT (fndecl))
3473 {
3474 tree type = TREE_TYPE (DECL_RESULT (fndecl));
3475 enum machine_mode mode = TYPE_MODE (type);
3476
3477 if (mode != BLKmode
3478 && mode != VOIDmode
3479 && !AGGREGATE_TYPE_P (type))
3480 {
3481 unsigned int align = GET_MODE_ALIGNMENT (mode);
3482 if (crtl->stack_alignment_estimated < align)
3483 {
3484 gcc_assert (!crtl->stack_realign_processed);
3485 crtl->stack_alignment_estimated = align;
3486 }
3487 }
3488 }
3489 }
3490
3491 /* If we are receiving a struct value address as the first argument, set up
3492 the RTL for the function result. As this might require code to convert
3493 the transmitted address to Pmode, we do this here to ensure that possible
3494 preliminary conversions of the address have been emitted already. */
3495 if (all.function_result_decl)
3496 {
3497 tree result = DECL_RESULT (current_function_decl);
3498 rtx addr = DECL_RTL (all.function_result_decl);
3499 rtx x;
3500
3501 if (DECL_BY_REFERENCE (result))
3502 {
3503 SET_DECL_VALUE_EXPR (result, all.function_result_decl);
3504 x = addr;
3505 }
3506 else
3507 {
3508 SET_DECL_VALUE_EXPR (result,
3509 build1 (INDIRECT_REF, TREE_TYPE (result),
3510 all.function_result_decl));
3511 addr = convert_memory_address (Pmode, addr);
3512 x = gen_rtx_MEM (DECL_MODE (result), addr);
3513 set_mem_attributes (x, result, 1);
3514 }
3515
3516 DECL_HAS_VALUE_EXPR_P (result) = 1;
3517
3518 SET_DECL_RTL (result, x);
3519 }
3520
3521 /* We have aligned all the args, so add space for the pretend args. */
3522 crtl->args.pretend_args_size = all.pretend_args_size;
3523 all.stack_args_size.constant += all.extra_pretend_bytes;
3524 crtl->args.size = all.stack_args_size.constant;
3525
3526 /* Adjust function incoming argument size for alignment and
3527 minimum length. */
3528
3529 crtl->args.size = MAX (crtl->args.size, all.reg_parm_stack_space);
3530 crtl->args.size = CEIL_ROUND (crtl->args.size,
3531 PARM_BOUNDARY / BITS_PER_UNIT);
3532
3533 #ifdef ARGS_GROW_DOWNWARD
3534 crtl->args.arg_offset_rtx
3535 = (all.stack_args_size.var == 0 ? GEN_INT (-all.stack_args_size.constant)
3536 : expand_expr (size_diffop (all.stack_args_size.var,
3537 size_int (-all.stack_args_size.constant)),
3538 NULL_RTX, VOIDmode, EXPAND_NORMAL));
3539 #else
3540 crtl->args.arg_offset_rtx = ARGS_SIZE_RTX (all.stack_args_size);
3541 #endif
3542
3543 /* See how many bytes, if any, of its args a function should try to pop
3544 on return. */
3545
3546 crtl->args.pops_args = targetm.calls.return_pops_args (fndecl,
3547 TREE_TYPE (fndecl),
3548 crtl->args.size);
3549
3550 /* For stdarg.h function, save info about
3551 regs and stack space used by the named args. */
3552
3553 crtl->args.info = all.args_so_far_v;
3554
3555 /* Set the rtx used for the function return value. Put this in its
3556 own variable so any optimizers that need this information don't have
3557 to include tree.h. Do this here so it gets done when an inlined
3558 function gets output. */
3559
3560 crtl->return_rtx
3561 = (DECL_RTL_SET_P (DECL_RESULT (fndecl))
3562 ? DECL_RTL (DECL_RESULT (fndecl)) : NULL_RTX);
3563
3564 /* If scalar return value was computed in a pseudo-reg, or was a named
3565 return value that got dumped to the stack, copy that to the hard
3566 return register. */
3567 if (DECL_RTL_SET_P (DECL_RESULT (fndecl)))
3568 {
3569 tree decl_result = DECL_RESULT (fndecl);
3570 rtx decl_rtl = DECL_RTL (decl_result);
3571
3572 if (REG_P (decl_rtl)
3573 ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER
3574 : DECL_REGISTER (decl_result))
3575 {
3576 rtx real_decl_rtl;
3577
3578 real_decl_rtl = targetm.calls.function_value (TREE_TYPE (decl_result),
3579 fndecl, true);
3580 REG_FUNCTION_VALUE_P (real_decl_rtl) = 1;
3581 /* The delay slot scheduler assumes that crtl->return_rtx
3582 holds the hard register containing the return value, not a
3583 temporary pseudo. */
3584 crtl->return_rtx = real_decl_rtl;
3585 }
3586 }
3587 }
3588
3589 /* A subroutine of gimplify_parameters, invoked via walk_tree.
3590 For all seen types, gimplify their sizes. */
3591
3592 static tree
3593 gimplify_parm_type (tree *tp, int *walk_subtrees, void *data)
3594 {
3595 tree t = *tp;
3596
3597 *walk_subtrees = 0;
3598 if (TYPE_P (t))
3599 {
3600 if (POINTER_TYPE_P (t))
3601 *walk_subtrees = 1;
3602 else if (TYPE_SIZE (t) && !TREE_CONSTANT (TYPE_SIZE (t))
3603 && !TYPE_SIZES_GIMPLIFIED (t))
3604 {
3605 gimplify_type_sizes (t, (gimple_seq *) data);
3606 *walk_subtrees = 1;
3607 }
3608 }
3609
3610 return NULL;
3611 }
3612
3613 /* Gimplify the parameter list for current_function_decl. This involves
3614 evaluating SAVE_EXPRs of variable sized parameters and generating code
3615 to implement callee-copies reference parameters. Returns a sequence of
3616 statements to add to the beginning of the function. */
3617
3618 gimple_seq
3619 gimplify_parameters (void)
3620 {
3621 struct assign_parm_data_all all;
3622 tree parm;
3623 gimple_seq stmts = NULL;
3624 vec<tree> fnargs;
3625 unsigned i;
3626
3627 assign_parms_initialize_all (&all);
3628 fnargs = assign_parms_augmented_arg_list (&all);
3629
3630 FOR_EACH_VEC_ELT (fnargs, i, parm)
3631 {
3632 struct assign_parm_data_one data;
3633
3634 /* Extract the type of PARM; adjust it according to ABI. */
3635 assign_parm_find_data_types (&all, parm, &data);
3636
3637 /* Early out for errors and void parameters. */
3638 if (data.passed_mode == VOIDmode || DECL_SIZE (parm) == NULL)
3639 continue;
3640
3641 /* Update info on where next arg arrives in registers. */
3642 targetm.calls.function_arg_advance (all.args_so_far, data.promoted_mode,
3643 data.passed_type, data.named_arg);
3644
3645 /* ??? Once upon a time variable_size stuffed parameter list
3646 SAVE_EXPRs (amongst others) onto a pending sizes list. This
3647 turned out to be less than manageable in the gimple world.
3648 Now we have to hunt them down ourselves. */
3649 walk_tree_without_duplicates (&data.passed_type,
3650 gimplify_parm_type, &stmts);
3651
3652 if (TREE_CODE (DECL_SIZE_UNIT (parm)) != INTEGER_CST)
3653 {
3654 gimplify_one_sizepos (&DECL_SIZE (parm), &stmts);
3655 gimplify_one_sizepos (&DECL_SIZE_UNIT (parm), &stmts);
3656 }
3657
3658 if (data.passed_pointer)
3659 {
3660 tree type = TREE_TYPE (data.passed_type);
3661 if (reference_callee_copied (&all.args_so_far_v, TYPE_MODE (type),
3662 type, data.named_arg))
3663 {
3664 tree local, t;
3665
3666 /* For constant-sized objects, this is trivial; for
3667 variable-sized objects, we have to play games. */
3668 if (TREE_CODE (DECL_SIZE_UNIT (parm)) == INTEGER_CST
3669 && !(flag_stack_check == GENERIC_STACK_CHECK
3670 && compare_tree_int (DECL_SIZE_UNIT (parm),
3671 STACK_CHECK_MAX_VAR_SIZE) > 0))
3672 {
3673 local = create_tmp_var (type, get_name (parm));
3674 DECL_IGNORED_P (local) = 0;
3675 /* If PARM was addressable, move that flag over
3676 to the local copy, as its address will be taken,
3677 not the PARMs. Keep the parms address taken
3678 as we'll query that flag during gimplification. */
3679 if (TREE_ADDRESSABLE (parm))
3680 TREE_ADDRESSABLE (local) = 1;
3681 else if (TREE_CODE (type) == COMPLEX_TYPE
3682 || TREE_CODE (type) == VECTOR_TYPE)
3683 DECL_GIMPLE_REG_P (local) = 1;
3684 }
3685 else
3686 {
3687 tree ptr_type, addr;
3688
3689 ptr_type = build_pointer_type (type);
3690 addr = create_tmp_reg (ptr_type, get_name (parm));
3691 DECL_IGNORED_P (addr) = 0;
3692 local = build_fold_indirect_ref (addr);
3693
3694 t = builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN);
3695 t = build_call_expr (t, 2, DECL_SIZE_UNIT (parm),
3696 size_int (DECL_ALIGN (parm)));
3697
3698 /* The call has been built for a variable-sized object. */
3699 CALL_ALLOCA_FOR_VAR_P (t) = 1;
3700 t = fold_convert (ptr_type, t);
3701 t = build2 (MODIFY_EXPR, TREE_TYPE (addr), addr, t);
3702 gimplify_and_add (t, &stmts);
3703 }
3704
3705 gimplify_assign (local, parm, &stmts);
3706
3707 SET_DECL_VALUE_EXPR (parm, local);
3708 DECL_HAS_VALUE_EXPR_P (parm) = 1;
3709 }
3710 }
3711 }
3712
3713 fnargs.release ();
3714
3715 return stmts;
3716 }
3717 \f
3718 /* Compute the size and offset from the start of the stacked arguments for a
3719 parm passed in mode PASSED_MODE and with type TYPE.
3720
3721 INITIAL_OFFSET_PTR points to the current offset into the stacked
3722 arguments.
3723
3724 The starting offset and size for this parm are returned in
3725 LOCATE->OFFSET and LOCATE->SIZE, respectively. When IN_REGS is
3726 nonzero, the offset is that of stack slot, which is returned in
3727 LOCATE->SLOT_OFFSET. LOCATE->ALIGNMENT_PAD is the amount of
3728 padding required from the initial offset ptr to the stack slot.
3729
3730 IN_REGS is nonzero if the argument will be passed in registers. It will
3731 never be set if REG_PARM_STACK_SPACE is not defined.
3732
3733 REG_PARM_STACK_SPACE is the number of bytes of stack space reserved
3734 for arguments which are passed in registers.
3735
3736 FNDECL is the function in which the argument was defined.
3737
3738 There are two types of rounding that are done. The first, controlled by
3739 TARGET_FUNCTION_ARG_BOUNDARY, forces the offset from the start of the
3740 argument list to be aligned to the specific boundary (in bits). This
3741 rounding affects the initial and starting offsets, but not the argument
3742 size.
3743
3744 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
3745 optionally rounds the size of the parm to PARM_BOUNDARY. The
3746 initial offset is not affected by this rounding, while the size always
3747 is and the starting offset may be. */
3748
3749 /* LOCATE->OFFSET will be negative for ARGS_GROW_DOWNWARD case;
3750 INITIAL_OFFSET_PTR is positive because locate_and_pad_parm's
3751 callers pass in the total size of args so far as
3752 INITIAL_OFFSET_PTR. LOCATE->SIZE is always positive. */
3753
3754 void
3755 locate_and_pad_parm (enum machine_mode passed_mode, tree type, int in_regs,
3756 int reg_parm_stack_space, int partial,
3757 tree fndecl ATTRIBUTE_UNUSED,
3758 struct args_size *initial_offset_ptr,
3759 struct locate_and_pad_arg_data *locate)
3760 {
3761 tree sizetree;
3762 enum direction where_pad;
3763 unsigned int boundary, round_boundary;
3764 int part_size_in_regs;
3765
3766 /* If we have found a stack parm before we reach the end of the
3767 area reserved for registers, skip that area. */
3768 if (! in_regs)
3769 {
3770 if (reg_parm_stack_space > 0)
3771 {
3772 if (initial_offset_ptr->var)
3773 {
3774 initial_offset_ptr->var
3775 = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
3776 ssize_int (reg_parm_stack_space));
3777 initial_offset_ptr->constant = 0;
3778 }
3779 else if (initial_offset_ptr->constant < reg_parm_stack_space)
3780 initial_offset_ptr->constant = reg_parm_stack_space;
3781 }
3782 }
3783
3784 part_size_in_regs = (reg_parm_stack_space == 0 ? partial : 0);
3785
3786 sizetree
3787 = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode));
3788 where_pad = FUNCTION_ARG_PADDING (passed_mode, type);
3789 boundary = targetm.calls.function_arg_boundary (passed_mode, type);
3790 round_boundary = targetm.calls.function_arg_round_boundary (passed_mode,
3791 type);
3792 locate->where_pad = where_pad;
3793
3794 /* Alignment can't exceed MAX_SUPPORTED_STACK_ALIGNMENT. */
3795 if (boundary > MAX_SUPPORTED_STACK_ALIGNMENT)
3796 boundary = MAX_SUPPORTED_STACK_ALIGNMENT;
3797
3798 locate->boundary = boundary;
3799
3800 if (SUPPORTS_STACK_ALIGNMENT)
3801 {
3802 /* stack_alignment_estimated can't change after stack has been
3803 realigned. */
3804 if (crtl->stack_alignment_estimated < boundary)
3805 {
3806 if (!crtl->stack_realign_processed)
3807 crtl->stack_alignment_estimated = boundary;
3808 else
3809 {
3810 /* If stack is realigned and stack alignment value
3811 hasn't been finalized, it is OK not to increase
3812 stack_alignment_estimated. The bigger alignment
3813 requirement is recorded in stack_alignment_needed
3814 below. */
3815 gcc_assert (!crtl->stack_realign_finalized
3816 && crtl->stack_realign_needed);
3817 }
3818 }
3819 }
3820
3821 /* Remember if the outgoing parameter requires extra alignment on the
3822 calling function side. */
3823 if (crtl->stack_alignment_needed < boundary)
3824 crtl->stack_alignment_needed = boundary;
3825 if (crtl->preferred_stack_boundary < boundary)
3826 crtl->preferred_stack_boundary = boundary;
3827
3828 #ifdef ARGS_GROW_DOWNWARD
3829 locate->slot_offset.constant = -initial_offset_ptr->constant;
3830 if (initial_offset_ptr->var)
3831 locate->slot_offset.var = size_binop (MINUS_EXPR, ssize_int (0),
3832 initial_offset_ptr->var);
3833
3834 {
3835 tree s2 = sizetree;
3836 if (where_pad != none
3837 && (!tree_fits_uhwi_p (sizetree)
3838 || (tree_to_uhwi (sizetree) * BITS_PER_UNIT) % round_boundary))
3839 s2 = round_up (s2, round_boundary / BITS_PER_UNIT);
3840 SUB_PARM_SIZE (locate->slot_offset, s2);
3841 }
3842
3843 locate->slot_offset.constant += part_size_in_regs;
3844
3845 if (!in_regs || reg_parm_stack_space > 0)
3846 pad_to_arg_alignment (&locate->slot_offset, boundary,
3847 &locate->alignment_pad);
3848
3849 locate->size.constant = (-initial_offset_ptr->constant
3850 - locate->slot_offset.constant);
3851 if (initial_offset_ptr->var)
3852 locate->size.var = size_binop (MINUS_EXPR,
3853 size_binop (MINUS_EXPR,
3854 ssize_int (0),
3855 initial_offset_ptr->var),
3856 locate->slot_offset.var);
3857
3858 /* Pad_below needs the pre-rounded size to know how much to pad
3859 below. */
3860 locate->offset = locate->slot_offset;
3861 if (where_pad == downward)
3862 pad_below (&locate->offset, passed_mode, sizetree);
3863
3864 #else /* !ARGS_GROW_DOWNWARD */
3865 if (!in_regs || reg_parm_stack_space > 0)
3866 pad_to_arg_alignment (initial_offset_ptr, boundary,
3867 &locate->alignment_pad);
3868 locate->slot_offset = *initial_offset_ptr;
3869
3870 #ifdef PUSH_ROUNDING
3871 if (passed_mode != BLKmode)
3872 sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
3873 #endif
3874
3875 /* Pad_below needs the pre-rounded size to know how much to pad below
3876 so this must be done before rounding up. */
3877 locate->offset = locate->slot_offset;
3878 if (where_pad == downward)
3879 pad_below (&locate->offset, passed_mode, sizetree);
3880
3881 if (where_pad != none
3882 && (!tree_fits_uhwi_p (sizetree)
3883 || (tree_to_uhwi (sizetree) * BITS_PER_UNIT) % round_boundary))
3884 sizetree = round_up (sizetree, round_boundary / BITS_PER_UNIT);
3885
3886 ADD_PARM_SIZE (locate->size, sizetree);
3887
3888 locate->size.constant -= part_size_in_regs;
3889 #endif /* ARGS_GROW_DOWNWARD */
3890
3891 #ifdef FUNCTION_ARG_OFFSET
3892 locate->offset.constant += FUNCTION_ARG_OFFSET (passed_mode, type);
3893 #endif
3894 }
3895
3896 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
3897 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
3898
3899 static void
3900 pad_to_arg_alignment (struct args_size *offset_ptr, int boundary,
3901 struct args_size *alignment_pad)
3902 {
3903 tree save_var = NULL_TREE;
3904 HOST_WIDE_INT save_constant = 0;
3905 int boundary_in_bytes = boundary / BITS_PER_UNIT;
3906 HOST_WIDE_INT sp_offset = STACK_POINTER_OFFSET;
3907
3908 #ifdef SPARC_STACK_BOUNDARY_HACK
3909 /* ??? The SPARC port may claim a STACK_BOUNDARY higher than
3910 the real alignment of %sp. However, when it does this, the
3911 alignment of %sp+STACK_POINTER_OFFSET is STACK_BOUNDARY. */
3912 if (SPARC_STACK_BOUNDARY_HACK)
3913 sp_offset = 0;
3914 #endif
3915
3916 if (boundary > PARM_BOUNDARY)
3917 {
3918 save_var = offset_ptr->var;
3919 save_constant = offset_ptr->constant;
3920 }
3921
3922 alignment_pad->var = NULL_TREE;
3923 alignment_pad->constant = 0;
3924
3925 if (boundary > BITS_PER_UNIT)
3926 {
3927 if (offset_ptr->var)
3928 {
3929 tree sp_offset_tree = ssize_int (sp_offset);
3930 tree offset = size_binop (PLUS_EXPR,
3931 ARGS_SIZE_TREE (*offset_ptr),
3932 sp_offset_tree);
3933 #ifdef ARGS_GROW_DOWNWARD
3934 tree rounded = round_down (offset, boundary / BITS_PER_UNIT);
3935 #else
3936 tree rounded = round_up (offset, boundary / BITS_PER_UNIT);
3937 #endif
3938
3939 offset_ptr->var = size_binop (MINUS_EXPR, rounded, sp_offset_tree);
3940 /* ARGS_SIZE_TREE includes constant term. */
3941 offset_ptr->constant = 0;
3942 if (boundary > PARM_BOUNDARY)
3943 alignment_pad->var = size_binop (MINUS_EXPR, offset_ptr->var,
3944 save_var);
3945 }
3946 else
3947 {
3948 offset_ptr->constant = -sp_offset +
3949 #ifdef ARGS_GROW_DOWNWARD
3950 FLOOR_ROUND (offset_ptr->constant + sp_offset, boundary_in_bytes);
3951 #else
3952 CEIL_ROUND (offset_ptr->constant + sp_offset, boundary_in_bytes);
3953 #endif
3954 if (boundary > PARM_BOUNDARY)
3955 alignment_pad->constant = offset_ptr->constant - save_constant;
3956 }
3957 }
3958 }
3959
3960 static void
3961 pad_below (struct args_size *offset_ptr, enum machine_mode passed_mode, tree sizetree)
3962 {
3963 if (passed_mode != BLKmode)
3964 {
3965 if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
3966 offset_ptr->constant
3967 += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
3968 / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
3969 - GET_MODE_SIZE (passed_mode));
3970 }
3971 else
3972 {
3973 if (TREE_CODE (sizetree) != INTEGER_CST
3974 || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
3975 {
3976 /* Round the size up to multiple of PARM_BOUNDARY bits. */
3977 tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
3978 /* Add it in. */
3979 ADD_PARM_SIZE (*offset_ptr, s2);
3980 SUB_PARM_SIZE (*offset_ptr, sizetree);
3981 }
3982 }
3983 }
3984 \f
3985
3986 /* True if register REGNO was alive at a place where `setjmp' was
3987 called and was set more than once or is an argument. Such regs may
3988 be clobbered by `longjmp'. */
3989
3990 static bool
3991 regno_clobbered_at_setjmp (bitmap setjmp_crosses, int regno)
3992 {
3993 /* There appear to be cases where some local vars never reach the
3994 backend but have bogus regnos. */
3995 if (regno >= max_reg_num ())
3996 return false;
3997
3998 return ((REG_N_SETS (regno) > 1
3999 || REGNO_REG_SET_P (df_get_live_out (ENTRY_BLOCK_PTR_FOR_FN (cfun)),
4000 regno))
4001 && REGNO_REG_SET_P (setjmp_crosses, regno));
4002 }
4003
4004 /* Walk the tree of blocks describing the binding levels within a
4005 function and warn about variables the might be killed by setjmp or
4006 vfork. This is done after calling flow_analysis before register
4007 allocation since that will clobber the pseudo-regs to hard
4008 regs. */
4009
4010 static void
4011 setjmp_vars_warning (bitmap setjmp_crosses, tree block)
4012 {
4013 tree decl, sub;
4014
4015 for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
4016 {
4017 if (TREE_CODE (decl) == VAR_DECL
4018 && DECL_RTL_SET_P (decl)
4019 && REG_P (DECL_RTL (decl))
4020 && regno_clobbered_at_setjmp (setjmp_crosses, REGNO (DECL_RTL (decl))))
4021 warning (OPT_Wclobbered, "variable %q+D might be clobbered by"
4022 " %<longjmp%> or %<vfork%>", decl);
4023 }
4024
4025 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = BLOCK_CHAIN (sub))
4026 setjmp_vars_warning (setjmp_crosses, sub);
4027 }
4028
4029 /* Do the appropriate part of setjmp_vars_warning
4030 but for arguments instead of local variables. */
4031
4032 static void
4033 setjmp_args_warning (bitmap setjmp_crosses)
4034 {
4035 tree decl;
4036 for (decl = DECL_ARGUMENTS (current_function_decl);
4037 decl; decl = DECL_CHAIN (decl))
4038 if (DECL_RTL (decl) != 0
4039 && REG_P (DECL_RTL (decl))
4040 && regno_clobbered_at_setjmp (setjmp_crosses, REGNO (DECL_RTL (decl))))
4041 warning (OPT_Wclobbered,
4042 "argument %q+D might be clobbered by %<longjmp%> or %<vfork%>",
4043 decl);
4044 }
4045
4046 /* Generate warning messages for variables live across setjmp. */
4047
4048 void
4049 generate_setjmp_warnings (void)
4050 {
4051 bitmap setjmp_crosses = regstat_get_setjmp_crosses ();
4052
4053 if (n_basic_blocks_for_fn (cfun) == NUM_FIXED_BLOCKS
4054 || bitmap_empty_p (setjmp_crosses))
4055 return;
4056
4057 setjmp_vars_warning (setjmp_crosses, DECL_INITIAL (current_function_decl));
4058 setjmp_args_warning (setjmp_crosses);
4059 }
4060
4061 \f
4062 /* Reverse the order of elements in the fragment chain T of blocks,
4063 and return the new head of the chain (old last element).
4064 In addition to that clear BLOCK_SAME_RANGE flags when needed
4065 and adjust BLOCK_SUPERCONTEXT from the super fragment to
4066 its super fragment origin. */
4067
4068 static tree
4069 block_fragments_nreverse (tree t)
4070 {
4071 tree prev = 0, block, next, prev_super = 0;
4072 tree super = BLOCK_SUPERCONTEXT (t);
4073 if (BLOCK_FRAGMENT_ORIGIN (super))
4074 super = BLOCK_FRAGMENT_ORIGIN (super);
4075 for (block = t; block; block = next)
4076 {
4077 next = BLOCK_FRAGMENT_CHAIN (block);
4078 BLOCK_FRAGMENT_CHAIN (block) = prev;
4079 if ((prev && !BLOCK_SAME_RANGE (prev))
4080 || (BLOCK_FRAGMENT_CHAIN (BLOCK_SUPERCONTEXT (block))
4081 != prev_super))
4082 BLOCK_SAME_RANGE (block) = 0;
4083 prev_super = BLOCK_SUPERCONTEXT (block);
4084 BLOCK_SUPERCONTEXT (block) = super;
4085 prev = block;
4086 }
4087 t = BLOCK_FRAGMENT_ORIGIN (t);
4088 if (BLOCK_FRAGMENT_CHAIN (BLOCK_SUPERCONTEXT (t))
4089 != prev_super)
4090 BLOCK_SAME_RANGE (t) = 0;
4091 BLOCK_SUPERCONTEXT (t) = super;
4092 return prev;
4093 }
4094
4095 /* Reverse the order of elements in the chain T of blocks,
4096 and return the new head of the chain (old last element).
4097 Also do the same on subblocks and reverse the order of elements
4098 in BLOCK_FRAGMENT_CHAIN as well. */
4099
4100 static tree
4101 blocks_nreverse_all (tree t)
4102 {
4103 tree prev = 0, block, next;
4104 for (block = t; block; block = next)
4105 {
4106 next = BLOCK_CHAIN (block);
4107 BLOCK_CHAIN (block) = prev;
4108 if (BLOCK_FRAGMENT_CHAIN (block)
4109 && BLOCK_FRAGMENT_ORIGIN (block) == NULL_TREE)
4110 {
4111 BLOCK_FRAGMENT_CHAIN (block)
4112 = block_fragments_nreverse (BLOCK_FRAGMENT_CHAIN (block));
4113 if (!BLOCK_SAME_RANGE (BLOCK_FRAGMENT_CHAIN (block)))
4114 BLOCK_SAME_RANGE (block) = 0;
4115 }
4116 BLOCK_SUBBLOCKS (block) = blocks_nreverse_all (BLOCK_SUBBLOCKS (block));
4117 prev = block;
4118 }
4119 return prev;
4120 }
4121
4122
4123 /* Identify BLOCKs referenced by more than one NOTE_INSN_BLOCK_{BEG,END},
4124 and create duplicate blocks. */
4125 /* ??? Need an option to either create block fragments or to create
4126 abstract origin duplicates of a source block. It really depends
4127 on what optimization has been performed. */
4128
4129 void
4130 reorder_blocks (void)
4131 {
4132 tree block = DECL_INITIAL (current_function_decl);
4133
4134 if (block == NULL_TREE)
4135 return;
4136
4137 auto_vec<tree, 10> block_stack;
4138
4139 /* Reset the TREE_ASM_WRITTEN bit for all blocks. */
4140 clear_block_marks (block);
4141
4142 /* Prune the old trees away, so that they don't get in the way. */
4143 BLOCK_SUBBLOCKS (block) = NULL_TREE;
4144 BLOCK_CHAIN (block) = NULL_TREE;
4145
4146 /* Recreate the block tree from the note nesting. */
4147 reorder_blocks_1 (get_insns (), block, &block_stack);
4148 BLOCK_SUBBLOCKS (block) = blocks_nreverse_all (BLOCK_SUBBLOCKS (block));
4149 }
4150
4151 /* Helper function for reorder_blocks. Reset TREE_ASM_WRITTEN. */
4152
4153 void
4154 clear_block_marks (tree block)
4155 {
4156 while (block)
4157 {
4158 TREE_ASM_WRITTEN (block) = 0;
4159 clear_block_marks (BLOCK_SUBBLOCKS (block));
4160 block = BLOCK_CHAIN (block);
4161 }
4162 }
4163
4164 static void
4165 reorder_blocks_1 (rtx_insn *insns, tree current_block,
4166 vec<tree> *p_block_stack)
4167 {
4168 rtx_insn *insn;
4169 tree prev_beg = NULL_TREE, prev_end = NULL_TREE;
4170
4171 for (insn = insns; insn; insn = NEXT_INSN (insn))
4172 {
4173 if (NOTE_P (insn))
4174 {
4175 if (NOTE_KIND (insn) == NOTE_INSN_BLOCK_BEG)
4176 {
4177 tree block = NOTE_BLOCK (insn);
4178 tree origin;
4179
4180 gcc_assert (BLOCK_FRAGMENT_ORIGIN (block) == NULL_TREE);
4181 origin = block;
4182
4183 if (prev_end)
4184 BLOCK_SAME_RANGE (prev_end) = 0;
4185 prev_end = NULL_TREE;
4186
4187 /* If we have seen this block before, that means it now
4188 spans multiple address regions. Create a new fragment. */
4189 if (TREE_ASM_WRITTEN (block))
4190 {
4191 tree new_block = copy_node (block);
4192
4193 BLOCK_SAME_RANGE (new_block) = 0;
4194 BLOCK_FRAGMENT_ORIGIN (new_block) = origin;
4195 BLOCK_FRAGMENT_CHAIN (new_block)
4196 = BLOCK_FRAGMENT_CHAIN (origin);
4197 BLOCK_FRAGMENT_CHAIN (origin) = new_block;
4198
4199 NOTE_BLOCK (insn) = new_block;
4200 block = new_block;
4201 }
4202
4203 if (prev_beg == current_block && prev_beg)
4204 BLOCK_SAME_RANGE (block) = 1;
4205
4206 prev_beg = origin;
4207
4208 BLOCK_SUBBLOCKS (block) = 0;
4209 TREE_ASM_WRITTEN (block) = 1;
4210 /* When there's only one block for the entire function,
4211 current_block == block and we mustn't do this, it
4212 will cause infinite recursion. */
4213 if (block != current_block)
4214 {
4215 tree super;
4216 if (block != origin)
4217 gcc_assert (BLOCK_SUPERCONTEXT (origin) == current_block
4218 || BLOCK_FRAGMENT_ORIGIN (BLOCK_SUPERCONTEXT
4219 (origin))
4220 == current_block);
4221 if (p_block_stack->is_empty ())
4222 super = current_block;
4223 else
4224 {
4225 super = p_block_stack->last ();
4226 gcc_assert (super == current_block
4227 || BLOCK_FRAGMENT_ORIGIN (super)
4228 == current_block);
4229 }
4230 BLOCK_SUPERCONTEXT (block) = super;
4231 BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block);
4232 BLOCK_SUBBLOCKS (current_block) = block;
4233 current_block = origin;
4234 }
4235 p_block_stack->safe_push (block);
4236 }
4237 else if (NOTE_KIND (insn) == NOTE_INSN_BLOCK_END)
4238 {
4239 NOTE_BLOCK (insn) = p_block_stack->pop ();
4240 current_block = BLOCK_SUPERCONTEXT (current_block);
4241 if (BLOCK_FRAGMENT_ORIGIN (current_block))
4242 current_block = BLOCK_FRAGMENT_ORIGIN (current_block);
4243 prev_beg = NULL_TREE;
4244 prev_end = BLOCK_SAME_RANGE (NOTE_BLOCK (insn))
4245 ? NOTE_BLOCK (insn) : NULL_TREE;
4246 }
4247 }
4248 else
4249 {
4250 prev_beg = NULL_TREE;
4251 if (prev_end)
4252 BLOCK_SAME_RANGE (prev_end) = 0;
4253 prev_end = NULL_TREE;
4254 }
4255 }
4256 }
4257
4258 /* Reverse the order of elements in the chain T of blocks,
4259 and return the new head of the chain (old last element). */
4260
4261 tree
4262 blocks_nreverse (tree t)
4263 {
4264 tree prev = 0, block, next;
4265 for (block = t; block; block = next)
4266 {
4267 next = BLOCK_CHAIN (block);
4268 BLOCK_CHAIN (block) = prev;
4269 prev = block;
4270 }
4271 return prev;
4272 }
4273
4274 /* Concatenate two chains of blocks (chained through BLOCK_CHAIN)
4275 by modifying the last node in chain 1 to point to chain 2. */
4276
4277 tree
4278 block_chainon (tree op1, tree op2)
4279 {
4280 tree t1;
4281
4282 if (!op1)
4283 return op2;
4284 if (!op2)
4285 return op1;
4286
4287 for (t1 = op1; BLOCK_CHAIN (t1); t1 = BLOCK_CHAIN (t1))
4288 continue;
4289 BLOCK_CHAIN (t1) = op2;
4290
4291 #ifdef ENABLE_TREE_CHECKING
4292 {
4293 tree t2;
4294 for (t2 = op2; t2; t2 = BLOCK_CHAIN (t2))
4295 gcc_assert (t2 != t1);
4296 }
4297 #endif
4298
4299 return op1;
4300 }
4301
4302 /* Count the subblocks of the list starting with BLOCK. If VECTOR is
4303 non-NULL, list them all into VECTOR, in a depth-first preorder
4304 traversal of the block tree. Also clear TREE_ASM_WRITTEN in all
4305 blocks. */
4306
4307 static int
4308 all_blocks (tree block, tree *vector)
4309 {
4310 int n_blocks = 0;
4311
4312 while (block)
4313 {
4314 TREE_ASM_WRITTEN (block) = 0;
4315
4316 /* Record this block. */
4317 if (vector)
4318 vector[n_blocks] = block;
4319
4320 ++n_blocks;
4321
4322 /* Record the subblocks, and their subblocks... */
4323 n_blocks += all_blocks (BLOCK_SUBBLOCKS (block),
4324 vector ? vector + n_blocks : 0);
4325 block = BLOCK_CHAIN (block);
4326 }
4327
4328 return n_blocks;
4329 }
4330
4331 /* Return a vector containing all the blocks rooted at BLOCK. The
4332 number of elements in the vector is stored in N_BLOCKS_P. The
4333 vector is dynamically allocated; it is the caller's responsibility
4334 to call `free' on the pointer returned. */
4335
4336 static tree *
4337 get_block_vector (tree block, int *n_blocks_p)
4338 {
4339 tree *block_vector;
4340
4341 *n_blocks_p = all_blocks (block, NULL);
4342 block_vector = XNEWVEC (tree, *n_blocks_p);
4343 all_blocks (block, block_vector);
4344
4345 return block_vector;
4346 }
4347
4348 static GTY(()) int next_block_index = 2;
4349
4350 /* Set BLOCK_NUMBER for all the blocks in FN. */
4351
4352 void
4353 number_blocks (tree fn)
4354 {
4355 int i;
4356 int n_blocks;
4357 tree *block_vector;
4358
4359 /* For SDB and XCOFF debugging output, we start numbering the blocks
4360 from 1 within each function, rather than keeping a running
4361 count. */
4362 #if defined (SDB_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
4363 if (write_symbols == SDB_DEBUG || write_symbols == XCOFF_DEBUG)
4364 next_block_index = 1;
4365 #endif
4366
4367 block_vector = get_block_vector (DECL_INITIAL (fn), &n_blocks);
4368
4369 /* The top-level BLOCK isn't numbered at all. */
4370 for (i = 1; i < n_blocks; ++i)
4371 /* We number the blocks from two. */
4372 BLOCK_NUMBER (block_vector[i]) = next_block_index++;
4373
4374 free (block_vector);
4375
4376 return;
4377 }
4378
4379 /* If VAR is present in a subblock of BLOCK, return the subblock. */
4380
4381 DEBUG_FUNCTION tree
4382 debug_find_var_in_block_tree (tree var, tree block)
4383 {
4384 tree t;
4385
4386 for (t = BLOCK_VARS (block); t; t = TREE_CHAIN (t))
4387 if (t == var)
4388 return block;
4389
4390 for (t = BLOCK_SUBBLOCKS (block); t; t = TREE_CHAIN (t))
4391 {
4392 tree ret = debug_find_var_in_block_tree (var, t);
4393 if (ret)
4394 return ret;
4395 }
4396
4397 return NULL_TREE;
4398 }
4399 \f
4400 /* Keep track of whether we're in a dummy function context. If we are,
4401 we don't want to invoke the set_current_function hook, because we'll
4402 get into trouble if the hook calls target_reinit () recursively or
4403 when the initial initialization is not yet complete. */
4404
4405 static bool in_dummy_function;
4406
4407 /* Invoke the target hook when setting cfun. Update the optimization options
4408 if the function uses different options than the default. */
4409
4410 static void
4411 invoke_set_current_function_hook (tree fndecl)
4412 {
4413 if (!in_dummy_function)
4414 {
4415 tree opts = ((fndecl)
4416 ? DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl)
4417 : optimization_default_node);
4418
4419 if (!opts)
4420 opts = optimization_default_node;
4421
4422 /* Change optimization options if needed. */
4423 if (optimization_current_node != opts)
4424 {
4425 optimization_current_node = opts;
4426 cl_optimization_restore (&global_options, TREE_OPTIMIZATION (opts));
4427 }
4428
4429 targetm.set_current_function (fndecl);
4430 this_fn_optabs = this_target_optabs;
4431
4432 if (opts != optimization_default_node)
4433 {
4434 init_tree_optimization_optabs (opts);
4435 if (TREE_OPTIMIZATION_OPTABS (opts))
4436 this_fn_optabs = (struct target_optabs *)
4437 TREE_OPTIMIZATION_OPTABS (opts);
4438 }
4439 }
4440 }
4441
4442 /* cfun should never be set directly; use this function. */
4443
4444 void
4445 set_cfun (struct function *new_cfun)
4446 {
4447 if (cfun != new_cfun)
4448 {
4449 cfun = new_cfun;
4450 invoke_set_current_function_hook (new_cfun ? new_cfun->decl : NULL_TREE);
4451 }
4452 }
4453
4454 /* Initialized with NOGC, making this poisonous to the garbage collector. */
4455
4456 static vec<function_p> cfun_stack;
4457
4458 /* Push the current cfun onto the stack, and set cfun to new_cfun. Also set
4459 current_function_decl accordingly. */
4460
4461 void
4462 push_cfun (struct function *new_cfun)
4463 {
4464 gcc_assert ((!cfun && !current_function_decl)
4465 || (cfun && current_function_decl == cfun->decl));
4466 cfun_stack.safe_push (cfun);
4467 current_function_decl = new_cfun ? new_cfun->decl : NULL_TREE;
4468 set_cfun (new_cfun);
4469 }
4470
4471 /* Pop cfun from the stack. Also set current_function_decl accordingly. */
4472
4473 void
4474 pop_cfun (void)
4475 {
4476 struct function *new_cfun = cfun_stack.pop ();
4477 /* When in_dummy_function, we do have a cfun but current_function_decl is
4478 NULL. We also allow pushing NULL cfun and subsequently changing
4479 current_function_decl to something else and have both restored by
4480 pop_cfun. */
4481 gcc_checking_assert (in_dummy_function
4482 || !cfun
4483 || current_function_decl == cfun->decl);
4484 set_cfun (new_cfun);
4485 current_function_decl = new_cfun ? new_cfun->decl : NULL_TREE;
4486 }
4487
4488 /* Return value of funcdef and increase it. */
4489 int
4490 get_next_funcdef_no (void)
4491 {
4492 return funcdef_no++;
4493 }
4494
4495 /* Return value of funcdef. */
4496 int
4497 get_last_funcdef_no (void)
4498 {
4499 return funcdef_no;
4500 }
4501
4502 /* Allocate a function structure for FNDECL and set its contents
4503 to the defaults. Set cfun to the newly-allocated object.
4504 Some of the helper functions invoked during initialization assume
4505 that cfun has already been set. Therefore, assign the new object
4506 directly into cfun and invoke the back end hook explicitly at the
4507 very end, rather than initializing a temporary and calling set_cfun
4508 on it.
4509
4510 ABSTRACT_P is true if this is a function that will never be seen by
4511 the middle-end. Such functions are front-end concepts (like C++
4512 function templates) that do not correspond directly to functions
4513 placed in object files. */
4514
4515 void
4516 allocate_struct_function (tree fndecl, bool abstract_p)
4517 {
4518 tree fntype = fndecl ? TREE_TYPE (fndecl) : NULL_TREE;
4519
4520 cfun = ggc_cleared_alloc<function> ();
4521
4522 init_eh_for_function ();
4523
4524 if (init_machine_status)
4525 cfun->machine = (*init_machine_status) ();
4526
4527 #ifdef OVERRIDE_ABI_FORMAT
4528 OVERRIDE_ABI_FORMAT (fndecl);
4529 #endif
4530
4531 if (fndecl != NULL_TREE)
4532 {
4533 DECL_STRUCT_FUNCTION (fndecl) = cfun;
4534 cfun->decl = fndecl;
4535 current_function_funcdef_no = get_next_funcdef_no ();
4536 }
4537
4538 invoke_set_current_function_hook (fndecl);
4539
4540 if (fndecl != NULL_TREE)
4541 {
4542 tree result = DECL_RESULT (fndecl);
4543 if (!abstract_p && aggregate_value_p (result, fndecl))
4544 {
4545 #ifdef PCC_STATIC_STRUCT_RETURN
4546 cfun->returns_pcc_struct = 1;
4547 #endif
4548 cfun->returns_struct = 1;
4549 }
4550
4551 cfun->stdarg = stdarg_p (fntype);
4552
4553 /* Assume all registers in stdarg functions need to be saved. */
4554 cfun->va_list_gpr_size = VA_LIST_MAX_GPR_SIZE;
4555 cfun->va_list_fpr_size = VA_LIST_MAX_FPR_SIZE;
4556
4557 /* ??? This could be set on a per-function basis by the front-end
4558 but is this worth the hassle? */
4559 cfun->can_throw_non_call_exceptions = flag_non_call_exceptions;
4560 cfun->can_delete_dead_exceptions = flag_delete_dead_exceptions;
4561
4562 if (!profile_flag && !flag_instrument_function_entry_exit)
4563 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (fndecl) = 1;
4564 }
4565 }
4566
4567 /* This is like allocate_struct_function, but pushes a new cfun for FNDECL
4568 instead of just setting it. */
4569
4570 void
4571 push_struct_function (tree fndecl)
4572 {
4573 /* When in_dummy_function we might be in the middle of a pop_cfun and
4574 current_function_decl and cfun may not match. */
4575 gcc_assert (in_dummy_function
4576 || (!cfun && !current_function_decl)
4577 || (cfun && current_function_decl == cfun->decl));
4578 cfun_stack.safe_push (cfun);
4579 current_function_decl = fndecl;
4580 allocate_struct_function (fndecl, false);
4581 }
4582
4583 /* Reset crtl and other non-struct-function variables to defaults as
4584 appropriate for emitting rtl at the start of a function. */
4585
4586 static void
4587 prepare_function_start (void)
4588 {
4589 gcc_assert (!crtl->emit.x_last_insn);
4590 init_temp_slots ();
4591 init_emit ();
4592 init_varasm_status ();
4593 init_expr ();
4594 default_rtl_profile ();
4595
4596 if (flag_stack_usage_info)
4597 {
4598 cfun->su = ggc_cleared_alloc<stack_usage> ();
4599 cfun->su->static_stack_size = -1;
4600 }
4601
4602 cse_not_expected = ! optimize;
4603
4604 /* Caller save not needed yet. */
4605 caller_save_needed = 0;
4606
4607 /* We haven't done register allocation yet. */
4608 reg_renumber = 0;
4609
4610 /* Indicate that we have not instantiated virtual registers yet. */
4611 virtuals_instantiated = 0;
4612
4613 /* Indicate that we want CONCATs now. */
4614 generating_concat_p = 1;
4615
4616 /* Indicate we have no need of a frame pointer yet. */
4617 frame_pointer_needed = 0;
4618 }
4619
4620 /* Initialize the rtl expansion mechanism so that we can do simple things
4621 like generate sequences. This is used to provide a context during global
4622 initialization of some passes. You must call expand_dummy_function_end
4623 to exit this context. */
4624
4625 void
4626 init_dummy_function_start (void)
4627 {
4628 gcc_assert (!in_dummy_function);
4629 in_dummy_function = true;
4630 push_struct_function (NULL_TREE);
4631 prepare_function_start ();
4632 }
4633
4634 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
4635 and initialize static variables for generating RTL for the statements
4636 of the function. */
4637
4638 void
4639 init_function_start (tree subr)
4640 {
4641 if (subr && DECL_STRUCT_FUNCTION (subr))
4642 set_cfun (DECL_STRUCT_FUNCTION (subr));
4643 else
4644 allocate_struct_function (subr, false);
4645
4646 /* Initialize backend, if needed. */
4647 initialize_rtl ();
4648
4649 prepare_function_start ();
4650 decide_function_section (subr);
4651
4652 /* Warn if this value is an aggregate type,
4653 regardless of which calling convention we are using for it. */
4654 if (AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
4655 warning (OPT_Waggregate_return, "function returns an aggregate");
4656 }
4657
4658 /* Expand code to verify the stack_protect_guard. This is invoked at
4659 the end of a function to be protected. */
4660
4661 #ifndef HAVE_stack_protect_test
4662 # define HAVE_stack_protect_test 0
4663 # define gen_stack_protect_test(x, y, z) (gcc_unreachable (), NULL_RTX)
4664 #endif
4665
4666 void
4667 stack_protect_epilogue (void)
4668 {
4669 tree guard_decl = targetm.stack_protect_guard ();
4670 rtx_code_label *label = gen_label_rtx ();
4671 rtx x, y, tmp;
4672
4673 x = expand_normal (crtl->stack_protect_guard);
4674 y = expand_normal (guard_decl);
4675
4676 /* Allow the target to compare Y with X without leaking either into
4677 a register. */
4678 switch ((int) (HAVE_stack_protect_test != 0))
4679 {
4680 case 1:
4681 tmp = gen_stack_protect_test (x, y, label);
4682 if (tmp)
4683 {
4684 emit_insn (tmp);
4685 break;
4686 }
4687 /* FALLTHRU */
4688
4689 default:
4690 emit_cmp_and_jump_insns (x, y, EQ, NULL_RTX, ptr_mode, 1, label);
4691 break;
4692 }
4693
4694 /* The noreturn predictor has been moved to the tree level. The rtl-level
4695 predictors estimate this branch about 20%, which isn't enough to get
4696 things moved out of line. Since this is the only extant case of adding
4697 a noreturn function at the rtl level, it doesn't seem worth doing ought
4698 except adding the prediction by hand. */
4699 tmp = get_last_insn ();
4700 if (JUMP_P (tmp))
4701 predict_insn_def (as_a <rtx_insn *> (tmp), PRED_NORETURN, TAKEN);
4702
4703 expand_call (targetm.stack_protect_fail (), NULL_RTX, /*ignore=*/true);
4704 free_temp_slots ();
4705 emit_label (label);
4706 }
4707 \f
4708 /* Start the RTL for a new function, and set variables used for
4709 emitting RTL.
4710 SUBR is the FUNCTION_DECL node.
4711 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
4712 the function's parameters, which must be run at any return statement. */
4713
4714 void
4715 expand_function_start (tree subr)
4716 {
4717 /* Make sure volatile mem refs aren't considered
4718 valid operands of arithmetic insns. */
4719 init_recog_no_volatile ();
4720
4721 crtl->profile
4722 = (profile_flag
4723 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr));
4724
4725 crtl->limit_stack
4726 = (stack_limit_rtx != NULL_RTX && ! DECL_NO_LIMIT_STACK (subr));
4727
4728 /* Make the label for return statements to jump to. Do not special
4729 case machines with special return instructions -- they will be
4730 handled later during jump, ifcvt, or epilogue creation. */
4731 return_label = gen_label_rtx ();
4732
4733 /* Initialize rtx used to return the value. */
4734 /* Do this before assign_parms so that we copy the struct value address
4735 before any library calls that assign parms might generate. */
4736
4737 /* Decide whether to return the value in memory or in a register. */
4738 if (aggregate_value_p (DECL_RESULT (subr), subr))
4739 {
4740 /* Returning something that won't go in a register. */
4741 rtx value_address = 0;
4742
4743 #ifdef PCC_STATIC_STRUCT_RETURN
4744 if (cfun->returns_pcc_struct)
4745 {
4746 int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
4747 value_address = assemble_static_space (size);
4748 }
4749 else
4750 #endif
4751 {
4752 rtx sv = targetm.calls.struct_value_rtx (TREE_TYPE (subr), 2);
4753 /* Expect to be passed the address of a place to store the value.
4754 If it is passed as an argument, assign_parms will take care of
4755 it. */
4756 if (sv)
4757 {
4758 value_address = gen_reg_rtx (Pmode);
4759 emit_move_insn (value_address, sv);
4760 }
4761 }
4762 if (value_address)
4763 {
4764 rtx x = value_address;
4765 if (!DECL_BY_REFERENCE (DECL_RESULT (subr)))
4766 {
4767 x = gen_rtx_MEM (DECL_MODE (DECL_RESULT (subr)), x);
4768 set_mem_attributes (x, DECL_RESULT (subr), 1);
4769 }
4770 SET_DECL_RTL (DECL_RESULT (subr), x);
4771 }
4772 }
4773 else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
4774 /* If return mode is void, this decl rtl should not be used. */
4775 SET_DECL_RTL (DECL_RESULT (subr), NULL_RTX);
4776 else
4777 {
4778 /* Compute the return values into a pseudo reg, which we will copy
4779 into the true return register after the cleanups are done. */
4780 tree return_type = TREE_TYPE (DECL_RESULT (subr));
4781 if (TYPE_MODE (return_type) != BLKmode
4782 && targetm.calls.return_in_msb (return_type))
4783 /* expand_function_end will insert the appropriate padding in
4784 this case. Use the return value's natural (unpadded) mode
4785 within the function proper. */
4786 SET_DECL_RTL (DECL_RESULT (subr),
4787 gen_reg_rtx (TYPE_MODE (return_type)));
4788 else
4789 {
4790 /* In order to figure out what mode to use for the pseudo, we
4791 figure out what the mode of the eventual return register will
4792 actually be, and use that. */
4793 rtx hard_reg = hard_function_value (return_type, subr, 0, 1);
4794
4795 /* Structures that are returned in registers are not
4796 aggregate_value_p, so we may see a PARALLEL or a REG. */
4797 if (REG_P (hard_reg))
4798 SET_DECL_RTL (DECL_RESULT (subr),
4799 gen_reg_rtx (GET_MODE (hard_reg)));
4800 else
4801 {
4802 gcc_assert (GET_CODE (hard_reg) == PARALLEL);
4803 SET_DECL_RTL (DECL_RESULT (subr), gen_group_rtx (hard_reg));
4804 }
4805 }
4806
4807 /* Set DECL_REGISTER flag so that expand_function_end will copy the
4808 result to the real return register(s). */
4809 DECL_REGISTER (DECL_RESULT (subr)) = 1;
4810 }
4811
4812 /* Initialize rtx for parameters and local variables.
4813 In some cases this requires emitting insns. */
4814 assign_parms (subr);
4815
4816 /* If function gets a static chain arg, store it. */
4817 if (cfun->static_chain_decl)
4818 {
4819 tree parm = cfun->static_chain_decl;
4820 rtx local, chain, insn;
4821
4822 local = gen_reg_rtx (Pmode);
4823 chain = targetm.calls.static_chain (current_function_decl, true);
4824
4825 set_decl_incoming_rtl (parm, chain, false);
4826 SET_DECL_RTL (parm, local);
4827 mark_reg_pointer (local, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm))));
4828
4829 insn = emit_move_insn (local, chain);
4830
4831 /* Mark the register as eliminable, similar to parameters. */
4832 if (MEM_P (chain)
4833 && reg_mentioned_p (arg_pointer_rtx, XEXP (chain, 0)))
4834 set_dst_reg_note (insn, REG_EQUIV, chain, local);
4835
4836 /* If we aren't optimizing, save the static chain onto the stack. */
4837 if (!optimize)
4838 {
4839 tree saved_static_chain_decl
4840 = build_decl (DECL_SOURCE_LOCATION (parm), VAR_DECL,
4841 DECL_NAME (parm), TREE_TYPE (parm));
4842 rtx saved_static_chain_rtx
4843 = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
4844 SET_DECL_RTL (saved_static_chain_decl, saved_static_chain_rtx);
4845 emit_move_insn (saved_static_chain_rtx, chain);
4846 SET_DECL_VALUE_EXPR (parm, saved_static_chain_decl);
4847 DECL_HAS_VALUE_EXPR_P (parm) = 1;
4848 }
4849 }
4850
4851 /* If the function receives a non-local goto, then store the
4852 bits we need to restore the frame pointer. */
4853 if (cfun->nonlocal_goto_save_area)
4854 {
4855 tree t_save;
4856 rtx r_save;
4857
4858 tree var = TREE_OPERAND (cfun->nonlocal_goto_save_area, 0);
4859 gcc_assert (DECL_RTL_SET_P (var));
4860
4861 t_save = build4 (ARRAY_REF,
4862 TREE_TYPE (TREE_TYPE (cfun->nonlocal_goto_save_area)),
4863 cfun->nonlocal_goto_save_area,
4864 integer_zero_node, NULL_TREE, NULL_TREE);
4865 r_save = expand_expr (t_save, NULL_RTX, VOIDmode, EXPAND_WRITE);
4866 gcc_assert (GET_MODE (r_save) == Pmode);
4867
4868 emit_move_insn (r_save, targetm.builtin_setjmp_frame_value ());
4869 update_nonlocal_goto_save_area ();
4870 }
4871
4872 /* The following was moved from init_function_start.
4873 The move is supposed to make sdb output more accurate. */
4874 /* Indicate the beginning of the function body,
4875 as opposed to parm setup. */
4876 emit_note (NOTE_INSN_FUNCTION_BEG);
4877
4878 gcc_assert (NOTE_P (get_last_insn ()));
4879
4880 parm_birth_insn = get_last_insn ();
4881
4882 if (crtl->profile)
4883 {
4884 #ifdef PROFILE_HOOK
4885 PROFILE_HOOK (current_function_funcdef_no);
4886 #endif
4887 }
4888
4889 /* If we are doing generic stack checking, the probe should go here. */
4890 if (flag_stack_check == GENERIC_STACK_CHECK)
4891 stack_check_probe_note = emit_note (NOTE_INSN_DELETED);
4892 }
4893 \f
4894 /* Undo the effects of init_dummy_function_start. */
4895 void
4896 expand_dummy_function_end (void)
4897 {
4898 gcc_assert (in_dummy_function);
4899
4900 /* End any sequences that failed to be closed due to syntax errors. */
4901 while (in_sequence_p ())
4902 end_sequence ();
4903
4904 /* Outside function body, can't compute type's actual size
4905 until next function's body starts. */
4906
4907 free_after_parsing (cfun);
4908 free_after_compilation (cfun);
4909 pop_cfun ();
4910 in_dummy_function = false;
4911 }
4912
4913 /* Call DOIT for each hard register used as a return value from
4914 the current function. */
4915
4916 void
4917 diddle_return_value (void (*doit) (rtx, void *), void *arg)
4918 {
4919 rtx outgoing = crtl->return_rtx;
4920
4921 if (! outgoing)
4922 return;
4923
4924 if (REG_P (outgoing))
4925 (*doit) (outgoing, arg);
4926 else if (GET_CODE (outgoing) == PARALLEL)
4927 {
4928 int i;
4929
4930 for (i = 0; i < XVECLEN (outgoing, 0); i++)
4931 {
4932 rtx x = XEXP (XVECEXP (outgoing, 0, i), 0);
4933
4934 if (REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER)
4935 (*doit) (x, arg);
4936 }
4937 }
4938 }
4939
4940 static void
4941 do_clobber_return_reg (rtx reg, void *arg ATTRIBUTE_UNUSED)
4942 {
4943 emit_clobber (reg);
4944 }
4945
4946 void
4947 clobber_return_register (void)
4948 {
4949 diddle_return_value (do_clobber_return_reg, NULL);
4950
4951 /* In case we do use pseudo to return value, clobber it too. */
4952 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl)))
4953 {
4954 tree decl_result = DECL_RESULT (current_function_decl);
4955 rtx decl_rtl = DECL_RTL (decl_result);
4956 if (REG_P (decl_rtl) && REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER)
4957 {
4958 do_clobber_return_reg (decl_rtl, NULL);
4959 }
4960 }
4961 }
4962
4963 static void
4964 do_use_return_reg (rtx reg, void *arg ATTRIBUTE_UNUSED)
4965 {
4966 emit_use (reg);
4967 }
4968
4969 static void
4970 use_return_register (void)
4971 {
4972 diddle_return_value (do_use_return_reg, NULL);
4973 }
4974
4975 /* Possibly warn about unused parameters. */
4976 void
4977 do_warn_unused_parameter (tree fn)
4978 {
4979 tree decl;
4980
4981 for (decl = DECL_ARGUMENTS (fn);
4982 decl; decl = DECL_CHAIN (decl))
4983 if (!TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL
4984 && DECL_NAME (decl) && !DECL_ARTIFICIAL (decl)
4985 && !TREE_NO_WARNING (decl))
4986 warning (OPT_Wunused_parameter, "unused parameter %q+D", decl);
4987 }
4988
4989 /* Set the location of the insn chain starting at INSN to LOC. */
4990
4991 static void
4992 set_insn_locations (rtx_insn *insn, int loc)
4993 {
4994 while (insn != NULL)
4995 {
4996 if (INSN_P (insn))
4997 INSN_LOCATION (insn) = loc;
4998 insn = NEXT_INSN (insn);
4999 }
5000 }
5001
5002 /* Generate RTL for the end of the current function. */
5003
5004 void
5005 expand_function_end (void)
5006 {
5007 rtx clobber_after;
5008
5009 /* If arg_pointer_save_area was referenced only from a nested
5010 function, we will not have initialized it yet. Do that now. */
5011 if (arg_pointer_save_area && ! crtl->arg_pointer_save_area_init)
5012 get_arg_pointer_save_area ();
5013
5014 /* If we are doing generic stack checking and this function makes calls,
5015 do a stack probe at the start of the function to ensure we have enough
5016 space for another stack frame. */
5017 if (flag_stack_check == GENERIC_STACK_CHECK)
5018 {
5019 rtx_insn *insn, *seq;
5020
5021 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
5022 if (CALL_P (insn))
5023 {
5024 rtx max_frame_size = GEN_INT (STACK_CHECK_MAX_FRAME_SIZE);
5025 start_sequence ();
5026 if (STACK_CHECK_MOVING_SP)
5027 anti_adjust_stack_and_probe (max_frame_size, true);
5028 else
5029 probe_stack_range (STACK_OLD_CHECK_PROTECT, max_frame_size);
5030 seq = get_insns ();
5031 end_sequence ();
5032 set_insn_locations (seq, prologue_location);
5033 emit_insn_before (seq, stack_check_probe_note);
5034 break;
5035 }
5036 }
5037
5038 /* End any sequences that failed to be closed due to syntax errors. */
5039 while (in_sequence_p ())
5040 end_sequence ();
5041
5042 clear_pending_stack_adjust ();
5043 do_pending_stack_adjust ();
5044
5045 /* Output a linenumber for the end of the function.
5046 SDB depends on this. */
5047 set_curr_insn_location (input_location);
5048
5049 /* Before the return label (if any), clobber the return
5050 registers so that they are not propagated live to the rest of
5051 the function. This can only happen with functions that drop
5052 through; if there had been a return statement, there would
5053 have either been a return rtx, or a jump to the return label.
5054
5055 We delay actual code generation after the current_function_value_rtx
5056 is computed. */
5057 clobber_after = get_last_insn ();
5058
5059 /* Output the label for the actual return from the function. */
5060 emit_label (return_label);
5061
5062 if (targetm_common.except_unwind_info (&global_options) == UI_SJLJ)
5063 {
5064 /* Let except.c know where it should emit the call to unregister
5065 the function context for sjlj exceptions. */
5066 if (flag_exceptions)
5067 sjlj_emit_function_exit_after (get_last_insn ());
5068 }
5069 else
5070 {
5071 /* We want to ensure that instructions that may trap are not
5072 moved into the epilogue by scheduling, because we don't
5073 always emit unwind information for the epilogue. */
5074 if (cfun->can_throw_non_call_exceptions)
5075 emit_insn (gen_blockage ());
5076 }
5077
5078 /* If this is an implementation of throw, do what's necessary to
5079 communicate between __builtin_eh_return and the epilogue. */
5080 expand_eh_return ();
5081
5082 /* If scalar return value was computed in a pseudo-reg, or was a named
5083 return value that got dumped to the stack, copy that to the hard
5084 return register. */
5085 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl)))
5086 {
5087 tree decl_result = DECL_RESULT (current_function_decl);
5088 rtx decl_rtl = DECL_RTL (decl_result);
5089
5090 if (REG_P (decl_rtl)
5091 ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER
5092 : DECL_REGISTER (decl_result))
5093 {
5094 rtx real_decl_rtl = crtl->return_rtx;
5095
5096 /* This should be set in assign_parms. */
5097 gcc_assert (REG_FUNCTION_VALUE_P (real_decl_rtl));
5098
5099 /* If this is a BLKmode structure being returned in registers,
5100 then use the mode computed in expand_return. Note that if
5101 decl_rtl is memory, then its mode may have been changed,
5102 but that crtl->return_rtx has not. */
5103 if (GET_MODE (real_decl_rtl) == BLKmode)
5104 PUT_MODE (real_decl_rtl, GET_MODE (decl_rtl));
5105
5106 /* If a non-BLKmode return value should be padded at the least
5107 significant end of the register, shift it left by the appropriate
5108 amount. BLKmode results are handled using the group load/store
5109 machinery. */
5110 if (TYPE_MODE (TREE_TYPE (decl_result)) != BLKmode
5111 && REG_P (real_decl_rtl)
5112 && targetm.calls.return_in_msb (TREE_TYPE (decl_result)))
5113 {
5114 emit_move_insn (gen_rtx_REG (GET_MODE (decl_rtl),
5115 REGNO (real_decl_rtl)),
5116 decl_rtl);
5117 shift_return_value (GET_MODE (decl_rtl), true, real_decl_rtl);
5118 }
5119 /* If a named return value dumped decl_return to memory, then
5120 we may need to re-do the PROMOTE_MODE signed/unsigned
5121 extension. */
5122 else if (GET_MODE (real_decl_rtl) != GET_MODE (decl_rtl))
5123 {
5124 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (decl_result));
5125 promote_function_mode (TREE_TYPE (decl_result),
5126 GET_MODE (decl_rtl), &unsignedp,
5127 TREE_TYPE (current_function_decl), 1);
5128
5129 convert_move (real_decl_rtl, decl_rtl, unsignedp);
5130 }
5131 else if (GET_CODE (real_decl_rtl) == PARALLEL)
5132 {
5133 /* If expand_function_start has created a PARALLEL for decl_rtl,
5134 move the result to the real return registers. Otherwise, do
5135 a group load from decl_rtl for a named return. */
5136 if (GET_CODE (decl_rtl) == PARALLEL)
5137 emit_group_move (real_decl_rtl, decl_rtl);
5138 else
5139 emit_group_load (real_decl_rtl, decl_rtl,
5140 TREE_TYPE (decl_result),
5141 int_size_in_bytes (TREE_TYPE (decl_result)));
5142 }
5143 /* In the case of complex integer modes smaller than a word, we'll
5144 need to generate some non-trivial bitfield insertions. Do that
5145 on a pseudo and not the hard register. */
5146 else if (GET_CODE (decl_rtl) == CONCAT
5147 && GET_MODE_CLASS (GET_MODE (decl_rtl)) == MODE_COMPLEX_INT
5148 && GET_MODE_BITSIZE (GET_MODE (decl_rtl)) <= BITS_PER_WORD)
5149 {
5150 int old_generating_concat_p;
5151 rtx tmp;
5152
5153 old_generating_concat_p = generating_concat_p;
5154 generating_concat_p = 0;
5155 tmp = gen_reg_rtx (GET_MODE (decl_rtl));
5156 generating_concat_p = old_generating_concat_p;
5157
5158 emit_move_insn (tmp, decl_rtl);
5159 emit_move_insn (real_decl_rtl, tmp);
5160 }
5161 else
5162 emit_move_insn (real_decl_rtl, decl_rtl);
5163 }
5164 }
5165
5166 /* If returning a structure, arrange to return the address of the value
5167 in a place where debuggers expect to find it.
5168
5169 If returning a structure PCC style,
5170 the caller also depends on this value.
5171 And cfun->returns_pcc_struct is not necessarily set. */
5172 if (cfun->returns_struct
5173 || cfun->returns_pcc_struct)
5174 {
5175 rtx value_address = DECL_RTL (DECL_RESULT (current_function_decl));
5176 tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
5177 rtx outgoing;
5178
5179 if (DECL_BY_REFERENCE (DECL_RESULT (current_function_decl)))
5180 type = TREE_TYPE (type);
5181 else
5182 value_address = XEXP (value_address, 0);
5183
5184 outgoing = targetm.calls.function_value (build_pointer_type (type),
5185 current_function_decl, true);
5186
5187 /* Mark this as a function return value so integrate will delete the
5188 assignment and USE below when inlining this function. */
5189 REG_FUNCTION_VALUE_P (outgoing) = 1;
5190
5191 /* The address may be ptr_mode and OUTGOING may be Pmode. */
5192 value_address = convert_memory_address (GET_MODE (outgoing),
5193 value_address);
5194
5195 emit_move_insn (outgoing, value_address);
5196
5197 /* Show return register used to hold result (in this case the address
5198 of the result. */
5199 crtl->return_rtx = outgoing;
5200 }
5201
5202 /* Emit the actual code to clobber return register. Don't emit
5203 it if clobber_after is a barrier, then the previous basic block
5204 certainly doesn't fall thru into the exit block. */
5205 if (!BARRIER_P (clobber_after))
5206 {
5207 rtx seq;
5208
5209 start_sequence ();
5210 clobber_return_register ();
5211 seq = get_insns ();
5212 end_sequence ();
5213
5214 emit_insn_after (seq, clobber_after);
5215 }
5216
5217 /* Output the label for the naked return from the function. */
5218 if (naked_return_label)
5219 emit_label (naked_return_label);
5220
5221 /* @@@ This is a kludge. We want to ensure that instructions that
5222 may trap are not moved into the epilogue by scheduling, because
5223 we don't always emit unwind information for the epilogue. */
5224 if (cfun->can_throw_non_call_exceptions
5225 && targetm_common.except_unwind_info (&global_options) != UI_SJLJ)
5226 emit_insn (gen_blockage ());
5227
5228 /* If stack protection is enabled for this function, check the guard. */
5229 if (crtl->stack_protect_guard)
5230 stack_protect_epilogue ();
5231
5232 /* If we had calls to alloca, and this machine needs
5233 an accurate stack pointer to exit the function,
5234 insert some code to save and restore the stack pointer. */
5235 if (! EXIT_IGNORE_STACK
5236 && cfun->calls_alloca)
5237 {
5238 rtx tem = 0, seq;
5239
5240 start_sequence ();
5241 emit_stack_save (SAVE_FUNCTION, &tem);
5242 seq = get_insns ();
5243 end_sequence ();
5244 emit_insn_before (seq, parm_birth_insn);
5245
5246 emit_stack_restore (SAVE_FUNCTION, tem);
5247 }
5248
5249 /* ??? This should no longer be necessary since stupid is no longer with
5250 us, but there are some parts of the compiler (eg reload_combine, and
5251 sh mach_dep_reorg) that still try and compute their own lifetime info
5252 instead of using the general framework. */
5253 use_return_register ();
5254 }
5255
5256 rtx
5257 get_arg_pointer_save_area (void)
5258 {
5259 rtx ret = arg_pointer_save_area;
5260
5261 if (! ret)
5262 {
5263 ret = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
5264 arg_pointer_save_area = ret;
5265 }
5266
5267 if (! crtl->arg_pointer_save_area_init)
5268 {
5269 rtx seq;
5270
5271 /* Save the arg pointer at the beginning of the function. The
5272 generated stack slot may not be a valid memory address, so we
5273 have to check it and fix it if necessary. */
5274 start_sequence ();
5275 emit_move_insn (validize_mem (copy_rtx (ret)),
5276 crtl->args.internal_arg_pointer);
5277 seq = get_insns ();
5278 end_sequence ();
5279
5280 push_topmost_sequence ();
5281 emit_insn_after (seq, entry_of_function ());
5282 pop_topmost_sequence ();
5283
5284 crtl->arg_pointer_save_area_init = true;
5285 }
5286
5287 return ret;
5288 }
5289 \f
5290 /* Add a list of INSNS to the hash HASHP, possibly allocating HASHP
5291 for the first time. */
5292
5293 static void
5294 record_insns (rtx_insn *insns, rtx end, htab_t *hashp)
5295 {
5296 rtx_insn *tmp;
5297 htab_t hash = *hashp;
5298
5299 if (hash == NULL)
5300 *hashp = hash
5301 = htab_create_ggc (17, htab_hash_pointer, htab_eq_pointer, NULL);
5302
5303 for (tmp = insns; tmp != end; tmp = NEXT_INSN (tmp))
5304 {
5305 void **slot = htab_find_slot (hash, tmp, INSERT);
5306 gcc_assert (*slot == NULL);
5307 *slot = tmp;
5308 }
5309 }
5310
5311 /* INSN has been duplicated or replaced by as COPY, perhaps by duplicating a
5312 basic block, splitting or peepholes. If INSN is a prologue or epilogue
5313 insn, then record COPY as well. */
5314
5315 void
5316 maybe_copy_prologue_epilogue_insn (rtx insn, rtx copy)
5317 {
5318 htab_t hash;
5319 void **slot;
5320
5321 hash = epilogue_insn_hash;
5322 if (!hash || !htab_find (hash, insn))
5323 {
5324 hash = prologue_insn_hash;
5325 if (!hash || !htab_find (hash, insn))
5326 return;
5327 }
5328
5329 slot = htab_find_slot (hash, copy, INSERT);
5330 gcc_assert (*slot == NULL);
5331 *slot = copy;
5332 }
5333
5334 /* Determine if any INSNs in HASH are, or are part of, INSN. Because
5335 we can be running after reorg, SEQUENCE rtl is possible. */
5336
5337 static bool
5338 contains (const_rtx insn, htab_t hash)
5339 {
5340 if (hash == NULL)
5341 return false;
5342
5343 if (NONJUMP_INSN_P (insn) && GET_CODE (PATTERN (insn)) == SEQUENCE)
5344 {
5345 rtx_sequence *seq = as_a <rtx_sequence *> (PATTERN (insn));
5346 int i;
5347 for (i = seq->len () - 1; i >= 0; i--)
5348 if (htab_find (hash, seq->element (i)))
5349 return true;
5350 return false;
5351 }
5352
5353 return htab_find (hash, insn) != NULL;
5354 }
5355
5356 int
5357 prologue_epilogue_contains (const_rtx insn)
5358 {
5359 if (contains (insn, prologue_insn_hash))
5360 return 1;
5361 if (contains (insn, epilogue_insn_hash))
5362 return 1;
5363 return 0;
5364 }
5365
5366 #ifdef HAVE_return
5367 /* Insert use of return register before the end of BB. */
5368
5369 static void
5370 emit_use_return_register_into_block (basic_block bb)
5371 {
5372 rtx seq, insn;
5373 start_sequence ();
5374 use_return_register ();
5375 seq = get_insns ();
5376 end_sequence ();
5377 insn = BB_END (bb);
5378 #ifdef HAVE_cc0
5379 if (reg_mentioned_p (cc0_rtx, PATTERN (insn)))
5380 insn = prev_cc0_setter (insn);
5381 #endif
5382 emit_insn_before (seq, insn);
5383 }
5384
5385
5386 /* Create a return pattern, either simple_return or return, depending on
5387 simple_p. */
5388
5389 static rtx
5390 gen_return_pattern (bool simple_p)
5391 {
5392 #ifdef HAVE_simple_return
5393 return simple_p ? gen_simple_return () : gen_return ();
5394 #else
5395 gcc_assert (!simple_p);
5396 return gen_return ();
5397 #endif
5398 }
5399
5400 /* Insert an appropriate return pattern at the end of block BB. This
5401 also means updating block_for_insn appropriately. SIMPLE_P is
5402 the same as in gen_return_pattern and passed to it. */
5403
5404 void
5405 emit_return_into_block (bool simple_p, basic_block bb)
5406 {
5407 rtx jump, pat;
5408 jump = emit_jump_insn_after (gen_return_pattern (simple_p), BB_END (bb));
5409 pat = PATTERN (jump);
5410 if (GET_CODE (pat) == PARALLEL)
5411 pat = XVECEXP (pat, 0, 0);
5412 gcc_assert (ANY_RETURN_P (pat));
5413 JUMP_LABEL (jump) = pat;
5414 }
5415 #endif
5416
5417 /* Set JUMP_LABEL for a return insn. */
5418
5419 void
5420 set_return_jump_label (rtx returnjump)
5421 {
5422 rtx pat = PATTERN (returnjump);
5423 if (GET_CODE (pat) == PARALLEL)
5424 pat = XVECEXP (pat, 0, 0);
5425 if (ANY_RETURN_P (pat))
5426 JUMP_LABEL (returnjump) = pat;
5427 else
5428 JUMP_LABEL (returnjump) = ret_rtx;
5429 }
5430
5431 #if defined (HAVE_return) || defined (HAVE_simple_return)
5432 /* Return true if there are any active insns between HEAD and TAIL. */
5433 bool
5434 active_insn_between (rtx_insn *head, rtx_insn *tail)
5435 {
5436 while (tail)
5437 {
5438 if (active_insn_p (tail))
5439 return true;
5440 if (tail == head)
5441 return false;
5442 tail = PREV_INSN (tail);
5443 }
5444 return false;
5445 }
5446
5447 /* LAST_BB is a block that exits, and empty of active instructions.
5448 Examine its predecessors for jumps that can be converted to
5449 (conditional) returns. */
5450 vec<edge>
5451 convert_jumps_to_returns (basic_block last_bb, bool simple_p,
5452 vec<edge> unconverted ATTRIBUTE_UNUSED)
5453 {
5454 int i;
5455 basic_block bb;
5456 rtx label;
5457 edge_iterator ei;
5458 edge e;
5459 auto_vec<basic_block> src_bbs (EDGE_COUNT (last_bb->preds));
5460
5461 FOR_EACH_EDGE (e, ei, last_bb->preds)
5462 if (e->src != ENTRY_BLOCK_PTR_FOR_FN (cfun))
5463 src_bbs.quick_push (e->src);
5464
5465 label = BB_HEAD (last_bb);
5466
5467 FOR_EACH_VEC_ELT (src_bbs, i, bb)
5468 {
5469 rtx_insn *jump = BB_END (bb);
5470
5471 if (!JUMP_P (jump) || JUMP_LABEL (jump) != label)
5472 continue;
5473
5474 e = find_edge (bb, last_bb);
5475
5476 /* If we have an unconditional jump, we can replace that
5477 with a simple return instruction. */
5478 if (simplejump_p (jump))
5479 {
5480 /* The use of the return register might be present in the exit
5481 fallthru block. Either:
5482 - removing the use is safe, and we should remove the use in
5483 the exit fallthru block, or
5484 - removing the use is not safe, and we should add it here.
5485 For now, we conservatively choose the latter. Either of the
5486 2 helps in crossjumping. */
5487 emit_use_return_register_into_block (bb);
5488
5489 emit_return_into_block (simple_p, bb);
5490 delete_insn (jump);
5491 }
5492
5493 /* If we have a conditional jump branching to the last
5494 block, we can try to replace that with a conditional
5495 return instruction. */
5496 else if (condjump_p (jump))
5497 {
5498 rtx dest;
5499
5500 if (simple_p)
5501 dest = simple_return_rtx;
5502 else
5503 dest = ret_rtx;
5504 if (!redirect_jump (jump, dest, 0))
5505 {
5506 #ifdef HAVE_simple_return
5507 if (simple_p)
5508 {
5509 if (dump_file)
5510 fprintf (dump_file,
5511 "Failed to redirect bb %d branch.\n", bb->index);
5512 unconverted.safe_push (e);
5513 }
5514 #endif
5515 continue;
5516 }
5517
5518 /* See comment in simplejump_p case above. */
5519 emit_use_return_register_into_block (bb);
5520
5521 /* If this block has only one successor, it both jumps
5522 and falls through to the fallthru block, so we can't
5523 delete the edge. */
5524 if (single_succ_p (bb))
5525 continue;
5526 }
5527 else
5528 {
5529 #ifdef HAVE_simple_return
5530 if (simple_p)
5531 {
5532 if (dump_file)
5533 fprintf (dump_file,
5534 "Failed to redirect bb %d branch.\n", bb->index);
5535 unconverted.safe_push (e);
5536 }
5537 #endif
5538 continue;
5539 }
5540
5541 /* Fix up the CFG for the successful change we just made. */
5542 redirect_edge_succ (e, EXIT_BLOCK_PTR_FOR_FN (cfun));
5543 e->flags &= ~EDGE_CROSSING;
5544 }
5545 src_bbs.release ();
5546 return unconverted;
5547 }
5548
5549 /* Emit a return insn for the exit fallthru block. */
5550 basic_block
5551 emit_return_for_exit (edge exit_fallthru_edge, bool simple_p)
5552 {
5553 basic_block last_bb = exit_fallthru_edge->src;
5554
5555 if (JUMP_P (BB_END (last_bb)))
5556 {
5557 last_bb = split_edge (exit_fallthru_edge);
5558 exit_fallthru_edge = single_succ_edge (last_bb);
5559 }
5560 emit_barrier_after (BB_END (last_bb));
5561 emit_return_into_block (simple_p, last_bb);
5562 exit_fallthru_edge->flags &= ~EDGE_FALLTHRU;
5563 return last_bb;
5564 }
5565 #endif
5566
5567
5568 /* Generate the prologue and epilogue RTL if the machine supports it. Thread
5569 this into place with notes indicating where the prologue ends and where
5570 the epilogue begins. Update the basic block information when possible.
5571
5572 Notes on epilogue placement:
5573 There are several kinds of edges to the exit block:
5574 * a single fallthru edge from LAST_BB
5575 * possibly, edges from blocks containing sibcalls
5576 * possibly, fake edges from infinite loops
5577
5578 The epilogue is always emitted on the fallthru edge from the last basic
5579 block in the function, LAST_BB, into the exit block.
5580
5581 If LAST_BB is empty except for a label, it is the target of every
5582 other basic block in the function that ends in a return. If a
5583 target has a return or simple_return pattern (possibly with
5584 conditional variants), these basic blocks can be changed so that a
5585 return insn is emitted into them, and their target is adjusted to
5586 the real exit block.
5587
5588 Notes on shrink wrapping: We implement a fairly conservative
5589 version of shrink-wrapping rather than the textbook one. We only
5590 generate a single prologue and a single epilogue. This is
5591 sufficient to catch a number of interesting cases involving early
5592 exits.
5593
5594 First, we identify the blocks that require the prologue to occur before
5595 them. These are the ones that modify a call-saved register, or reference
5596 any of the stack or frame pointer registers. To simplify things, we then
5597 mark everything reachable from these blocks as also requiring a prologue.
5598 This takes care of loops automatically, and avoids the need to examine
5599 whether MEMs reference the frame, since it is sufficient to check for
5600 occurrences of the stack or frame pointer.
5601
5602 We then compute the set of blocks for which the need for a prologue
5603 is anticipatable (borrowing terminology from the shrink-wrapping
5604 description in Muchnick's book). These are the blocks which either
5605 require a prologue themselves, or those that have only successors
5606 where the prologue is anticipatable. The prologue needs to be
5607 inserted on all edges from BB1->BB2 where BB2 is in ANTIC and BB1
5608 is not. For the moment, we ensure that only one such edge exists.
5609
5610 The epilogue is placed as described above, but we make a
5611 distinction between inserting return and simple_return patterns
5612 when modifying other blocks that end in a return. Blocks that end
5613 in a sibcall omit the sibcall_epilogue if the block is not in
5614 ANTIC. */
5615
5616 static void
5617 thread_prologue_and_epilogue_insns (void)
5618 {
5619 bool inserted;
5620 #ifdef HAVE_simple_return
5621 vec<edge> unconverted_simple_returns = vNULL;
5622 bitmap_head bb_flags;
5623 #endif
5624 rtx_insn *returnjump;
5625 rtx_insn *epilogue_end ATTRIBUTE_UNUSED;
5626 rtx_insn *prologue_seq ATTRIBUTE_UNUSED, *split_prologue_seq ATTRIBUTE_UNUSED;
5627 edge e, entry_edge, orig_entry_edge, exit_fallthru_edge;
5628 edge_iterator ei;
5629
5630 df_analyze ();
5631
5632 rtl_profile_for_bb (ENTRY_BLOCK_PTR_FOR_FN (cfun));
5633
5634 inserted = false;
5635 epilogue_end = NULL;
5636 returnjump = NULL;
5637
5638 /* Can't deal with multiple successors of the entry block at the
5639 moment. Function should always have at least one entry
5640 point. */
5641 gcc_assert (single_succ_p (ENTRY_BLOCK_PTR_FOR_FN (cfun)));
5642 entry_edge = single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun));
5643 orig_entry_edge = entry_edge;
5644
5645 split_prologue_seq = NULL;
5646 if (flag_split_stack
5647 && (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (cfun->decl))
5648 == NULL))
5649 {
5650 #ifndef HAVE_split_stack_prologue
5651 gcc_unreachable ();
5652 #else
5653 gcc_assert (HAVE_split_stack_prologue);
5654
5655 start_sequence ();
5656 emit_insn (gen_split_stack_prologue ());
5657 split_prologue_seq = get_insns ();
5658 end_sequence ();
5659
5660 record_insns (split_prologue_seq, NULL, &prologue_insn_hash);
5661 set_insn_locations (split_prologue_seq, prologue_location);
5662 #endif
5663 }
5664
5665 prologue_seq = NULL;
5666 #ifdef HAVE_prologue
5667 if (HAVE_prologue)
5668 {
5669 start_sequence ();
5670 rtx_insn *seq = safe_as_a <rtx_insn *> (gen_prologue ());
5671 emit_insn (seq);
5672
5673 /* Insert an explicit USE for the frame pointer
5674 if the profiling is on and the frame pointer is required. */
5675 if (crtl->profile && frame_pointer_needed)
5676 emit_use (hard_frame_pointer_rtx);
5677
5678 /* Retain a map of the prologue insns. */
5679 record_insns (seq, NULL, &prologue_insn_hash);
5680 emit_note (NOTE_INSN_PROLOGUE_END);
5681
5682 /* Ensure that instructions are not moved into the prologue when
5683 profiling is on. The call to the profiling routine can be
5684 emitted within the live range of a call-clobbered register. */
5685 if (!targetm.profile_before_prologue () && crtl->profile)
5686 emit_insn (gen_blockage ());
5687
5688 prologue_seq = get_insns ();
5689 end_sequence ();
5690 set_insn_locations (prologue_seq, prologue_location);
5691 }
5692 #endif
5693
5694 #ifdef HAVE_simple_return
5695 bitmap_initialize (&bb_flags, &bitmap_default_obstack);
5696
5697 /* Try to perform a kind of shrink-wrapping, making sure the
5698 prologue/epilogue is emitted only around those parts of the
5699 function that require it. */
5700
5701 try_shrink_wrapping (&entry_edge, orig_entry_edge, &bb_flags, prologue_seq);
5702 #endif
5703
5704 if (split_prologue_seq != NULL_RTX)
5705 {
5706 insert_insn_on_edge (split_prologue_seq, orig_entry_edge);
5707 inserted = true;
5708 }
5709 if (prologue_seq != NULL_RTX)
5710 {
5711 insert_insn_on_edge (prologue_seq, entry_edge);
5712 inserted = true;
5713 }
5714
5715 /* If the exit block has no non-fake predecessors, we don't need
5716 an epilogue. */
5717 FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
5718 if ((e->flags & EDGE_FAKE) == 0)
5719 break;
5720 if (e == NULL)
5721 goto epilogue_done;
5722
5723 rtl_profile_for_bb (EXIT_BLOCK_PTR_FOR_FN (cfun));
5724
5725 exit_fallthru_edge = find_fallthru_edge (EXIT_BLOCK_PTR_FOR_FN (cfun)->preds);
5726
5727 #ifdef HAVE_simple_return
5728 if (entry_edge != orig_entry_edge)
5729 exit_fallthru_edge
5730 = get_unconverted_simple_return (exit_fallthru_edge, bb_flags,
5731 &unconverted_simple_returns,
5732 &returnjump);
5733 #endif
5734 #ifdef HAVE_return
5735 if (HAVE_return)
5736 {
5737 if (exit_fallthru_edge == NULL)
5738 goto epilogue_done;
5739
5740 if (optimize)
5741 {
5742 basic_block last_bb = exit_fallthru_edge->src;
5743
5744 if (LABEL_P (BB_HEAD (last_bb))
5745 && !active_insn_between (BB_HEAD (last_bb), BB_END (last_bb)))
5746 convert_jumps_to_returns (last_bb, false, vNULL);
5747
5748 if (EDGE_COUNT (last_bb->preds) != 0
5749 && single_succ_p (last_bb))
5750 {
5751 last_bb = emit_return_for_exit (exit_fallthru_edge, false);
5752 epilogue_end = returnjump = BB_END (last_bb);
5753 #ifdef HAVE_simple_return
5754 /* Emitting the return may add a basic block.
5755 Fix bb_flags for the added block. */
5756 if (last_bb != exit_fallthru_edge->src)
5757 bitmap_set_bit (&bb_flags, last_bb->index);
5758 #endif
5759 goto epilogue_done;
5760 }
5761 }
5762 }
5763 #endif
5764
5765 /* A small fib -- epilogue is not yet completed, but we wish to re-use
5766 this marker for the splits of EH_RETURN patterns, and nothing else
5767 uses the flag in the meantime. */
5768 epilogue_completed = 1;
5769
5770 #ifdef HAVE_eh_return
5771 /* Find non-fallthru edges that end with EH_RETURN instructions. On
5772 some targets, these get split to a special version of the epilogue
5773 code. In order to be able to properly annotate these with unwind
5774 info, try to split them now. If we get a valid split, drop an
5775 EPILOGUE_BEG note and mark the insns as epilogue insns. */
5776 FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
5777 {
5778 rtx_insn *prev, *last, *trial;
5779
5780 if (e->flags & EDGE_FALLTHRU)
5781 continue;
5782 last = BB_END (e->src);
5783 if (!eh_returnjump_p (last))
5784 continue;
5785
5786 prev = PREV_INSN (last);
5787 trial = try_split (PATTERN (last), last, 1);
5788 if (trial == last)
5789 continue;
5790
5791 record_insns (NEXT_INSN (prev), NEXT_INSN (trial), &epilogue_insn_hash);
5792 emit_note_after (NOTE_INSN_EPILOGUE_BEG, prev);
5793 }
5794 #endif
5795
5796 /* If nothing falls through into the exit block, we don't need an
5797 epilogue. */
5798
5799 if (exit_fallthru_edge == NULL)
5800 goto epilogue_done;
5801
5802 #ifdef HAVE_epilogue
5803 if (HAVE_epilogue)
5804 {
5805 start_sequence ();
5806 epilogue_end = emit_note (NOTE_INSN_EPILOGUE_BEG);
5807 rtx_insn *seq = as_a <rtx_insn *> (gen_epilogue ());
5808 if (seq)
5809 emit_jump_insn (seq);
5810
5811 /* Retain a map of the epilogue insns. */
5812 record_insns (seq, NULL, &epilogue_insn_hash);
5813 set_insn_locations (seq, epilogue_location);
5814
5815 seq = get_insns ();
5816 returnjump = get_last_insn ();
5817 end_sequence ();
5818
5819 insert_insn_on_edge (seq, exit_fallthru_edge);
5820 inserted = true;
5821
5822 if (JUMP_P (returnjump))
5823 set_return_jump_label (returnjump);
5824 }
5825 else
5826 #endif
5827 {
5828 basic_block cur_bb;
5829
5830 if (! next_active_insn (BB_END (exit_fallthru_edge->src)))
5831 goto epilogue_done;
5832 /* We have a fall-through edge to the exit block, the source is not
5833 at the end of the function, and there will be an assembler epilogue
5834 at the end of the function.
5835 We can't use force_nonfallthru here, because that would try to
5836 use return. Inserting a jump 'by hand' is extremely messy, so
5837 we take advantage of cfg_layout_finalize using
5838 fixup_fallthru_exit_predecessor. */
5839 cfg_layout_initialize (0);
5840 FOR_EACH_BB_FN (cur_bb, cfun)
5841 if (cur_bb->index >= NUM_FIXED_BLOCKS
5842 && cur_bb->next_bb->index >= NUM_FIXED_BLOCKS)
5843 cur_bb->aux = cur_bb->next_bb;
5844 cfg_layout_finalize ();
5845 }
5846
5847 epilogue_done:
5848
5849 default_rtl_profile ();
5850
5851 if (inserted)
5852 {
5853 sbitmap blocks;
5854
5855 commit_edge_insertions ();
5856
5857 /* Look for basic blocks within the prologue insns. */
5858 blocks = sbitmap_alloc (last_basic_block_for_fn (cfun));
5859 bitmap_clear (blocks);
5860 bitmap_set_bit (blocks, entry_edge->dest->index);
5861 bitmap_set_bit (blocks, orig_entry_edge->dest->index);
5862 find_many_sub_basic_blocks (blocks);
5863 sbitmap_free (blocks);
5864
5865 /* The epilogue insns we inserted may cause the exit edge to no longer
5866 be fallthru. */
5867 FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
5868 {
5869 if (((e->flags & EDGE_FALLTHRU) != 0)
5870 && returnjump_p (BB_END (e->src)))
5871 e->flags &= ~EDGE_FALLTHRU;
5872 }
5873 }
5874
5875 #ifdef HAVE_simple_return
5876 convert_to_simple_return (entry_edge, orig_entry_edge, bb_flags, returnjump,
5877 unconverted_simple_returns);
5878 #endif
5879
5880 #ifdef HAVE_sibcall_epilogue
5881 /* Emit sibling epilogues before any sibling call sites. */
5882 for (ei = ei_start (EXIT_BLOCK_PTR_FOR_FN (cfun)->preds); (e =
5883 ei_safe_edge (ei));
5884 )
5885 {
5886 basic_block bb = e->src;
5887 rtx_insn *insn = BB_END (bb);
5888 rtx ep_seq;
5889
5890 if (!CALL_P (insn)
5891 || ! SIBLING_CALL_P (insn)
5892 #ifdef HAVE_simple_return
5893 || (entry_edge != orig_entry_edge
5894 && !bitmap_bit_p (&bb_flags, bb->index))
5895 #endif
5896 )
5897 {
5898 ei_next (&ei);
5899 continue;
5900 }
5901
5902 ep_seq = gen_sibcall_epilogue ();
5903 if (ep_seq)
5904 {
5905 start_sequence ();
5906 emit_note (NOTE_INSN_EPILOGUE_BEG);
5907 emit_insn (ep_seq);
5908 rtx_insn *seq = get_insns ();
5909 end_sequence ();
5910
5911 /* Retain a map of the epilogue insns. Used in life analysis to
5912 avoid getting rid of sibcall epilogue insns. Do this before we
5913 actually emit the sequence. */
5914 record_insns (seq, NULL, &epilogue_insn_hash);
5915 set_insn_locations (seq, epilogue_location);
5916
5917 emit_insn_before (seq, insn);
5918 }
5919 ei_next (&ei);
5920 }
5921 #endif
5922
5923 #ifdef HAVE_epilogue
5924 if (epilogue_end)
5925 {
5926 rtx_insn *insn, *next;
5927
5928 /* Similarly, move any line notes that appear after the epilogue.
5929 There is no need, however, to be quite so anal about the existence
5930 of such a note. Also possibly move
5931 NOTE_INSN_FUNCTION_BEG notes, as those can be relevant for debug
5932 info generation. */
5933 for (insn = epilogue_end; insn; insn = next)
5934 {
5935 next = NEXT_INSN (insn);
5936 if (NOTE_P (insn)
5937 && (NOTE_KIND (insn) == NOTE_INSN_FUNCTION_BEG))
5938 reorder_insns (insn, insn, PREV_INSN (epilogue_end));
5939 }
5940 }
5941 #endif
5942
5943 #ifdef HAVE_simple_return
5944 bitmap_clear (&bb_flags);
5945 #endif
5946
5947 /* Threading the prologue and epilogue changes the artificial refs
5948 in the entry and exit blocks. */
5949 epilogue_completed = 1;
5950 df_update_entry_exit_and_calls ();
5951 }
5952
5953 /* Reposition the prologue-end and epilogue-begin notes after
5954 instruction scheduling. */
5955
5956 void
5957 reposition_prologue_and_epilogue_notes (void)
5958 {
5959 #if defined (HAVE_prologue) || defined (HAVE_epilogue) \
5960 || defined (HAVE_sibcall_epilogue)
5961 /* Since the hash table is created on demand, the fact that it is
5962 non-null is a signal that it is non-empty. */
5963 if (prologue_insn_hash != NULL)
5964 {
5965 size_t len = htab_elements (prologue_insn_hash);
5966 rtx_insn *insn, *last = NULL, *note = NULL;
5967
5968 /* Scan from the beginning until we reach the last prologue insn. */
5969 /* ??? While we do have the CFG intact, there are two problems:
5970 (1) The prologue can contain loops (typically probing the stack),
5971 which means that the end of the prologue isn't in the first bb.
5972 (2) Sometimes the PROLOGUE_END note gets pushed into the next bb. */
5973 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
5974 {
5975 if (NOTE_P (insn))
5976 {
5977 if (NOTE_KIND (insn) == NOTE_INSN_PROLOGUE_END)
5978 note = insn;
5979 }
5980 else if (contains (insn, prologue_insn_hash))
5981 {
5982 last = insn;
5983 if (--len == 0)
5984 break;
5985 }
5986 }
5987
5988 if (last)
5989 {
5990 if (note == NULL)
5991 {
5992 /* Scan forward looking for the PROLOGUE_END note. It should
5993 be right at the beginning of the block, possibly with other
5994 insn notes that got moved there. */
5995 for (note = NEXT_INSN (last); ; note = NEXT_INSN (note))
5996 {
5997 if (NOTE_P (note)
5998 && NOTE_KIND (note) == NOTE_INSN_PROLOGUE_END)
5999 break;
6000 }
6001 }
6002
6003 /* Avoid placing note between CODE_LABEL and BASIC_BLOCK note. */
6004 if (LABEL_P (last))
6005 last = NEXT_INSN (last);
6006 reorder_insns (note, note, last);
6007 }
6008 }
6009
6010 if (epilogue_insn_hash != NULL)
6011 {
6012 edge_iterator ei;
6013 edge e;
6014
6015 FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
6016 {
6017 rtx_insn *insn, *first = NULL, *note = NULL;
6018 basic_block bb = e->src;
6019
6020 /* Scan from the beginning until we reach the first epilogue insn. */
6021 FOR_BB_INSNS (bb, insn)
6022 {
6023 if (NOTE_P (insn))
6024 {
6025 if (NOTE_KIND (insn) == NOTE_INSN_EPILOGUE_BEG)
6026 {
6027 note = insn;
6028 if (first != NULL)
6029 break;
6030 }
6031 }
6032 else if (first == NULL && contains (insn, epilogue_insn_hash))
6033 {
6034 first = insn;
6035 if (note != NULL)
6036 break;
6037 }
6038 }
6039
6040 if (note)
6041 {
6042 /* If the function has a single basic block, and no real
6043 epilogue insns (e.g. sibcall with no cleanup), the
6044 epilogue note can get scheduled before the prologue
6045 note. If we have frame related prologue insns, having
6046 them scanned during the epilogue will result in a crash.
6047 In this case re-order the epilogue note to just before
6048 the last insn in the block. */
6049 if (first == NULL)
6050 first = BB_END (bb);
6051
6052 if (PREV_INSN (first) != note)
6053 reorder_insns (note, note, PREV_INSN (first));
6054 }
6055 }
6056 }
6057 #endif /* HAVE_prologue or HAVE_epilogue */
6058 }
6059
6060 /* Returns the name of function declared by FNDECL. */
6061 const char *
6062 fndecl_name (tree fndecl)
6063 {
6064 if (fndecl == NULL)
6065 return "(nofn)";
6066 return lang_hooks.decl_printable_name (fndecl, 2);
6067 }
6068
6069 /* Returns the name of function FN. */
6070 const char *
6071 function_name (struct function *fn)
6072 {
6073 tree fndecl = (fn == NULL) ? NULL : fn->decl;
6074 return fndecl_name (fndecl);
6075 }
6076
6077 /* Returns the name of the current function. */
6078 const char *
6079 current_function_name (void)
6080 {
6081 return function_name (cfun);
6082 }
6083 \f
6084
6085 static unsigned int
6086 rest_of_handle_check_leaf_regs (void)
6087 {
6088 #ifdef LEAF_REGISTERS
6089 crtl->uses_only_leaf_regs
6090 = optimize > 0 && only_leaf_regs_used () && leaf_function_p ();
6091 #endif
6092 return 0;
6093 }
6094
6095 /* Insert a TYPE into the used types hash table of CFUN. */
6096
6097 static void
6098 used_types_insert_helper (tree type, struct function *func)
6099 {
6100 if (type != NULL && func != NULL)
6101 {
6102 if (func->used_types_hash == NULL)
6103 func->used_types_hash = hash_set<tree>::create_ggc (37);
6104
6105 func->used_types_hash->add (type);
6106 }
6107 }
6108
6109 /* Given a type, insert it into the used hash table in cfun. */
6110 void
6111 used_types_insert (tree t)
6112 {
6113 while (POINTER_TYPE_P (t) || TREE_CODE (t) == ARRAY_TYPE)
6114 if (TYPE_NAME (t))
6115 break;
6116 else
6117 t = TREE_TYPE (t);
6118 if (TREE_CODE (t) == ERROR_MARK)
6119 return;
6120 if (TYPE_NAME (t) == NULL_TREE
6121 || TYPE_NAME (t) == TYPE_NAME (TYPE_MAIN_VARIANT (t)))
6122 t = TYPE_MAIN_VARIANT (t);
6123 if (debug_info_level > DINFO_LEVEL_NONE)
6124 {
6125 if (cfun)
6126 used_types_insert_helper (t, cfun);
6127 else
6128 {
6129 /* So this might be a type referenced by a global variable.
6130 Record that type so that we can later decide to emit its
6131 debug information. */
6132 vec_safe_push (types_used_by_cur_var_decl, t);
6133 }
6134 }
6135 }
6136
6137 /* Helper to Hash a struct types_used_by_vars_entry. */
6138
6139 static hashval_t
6140 hash_types_used_by_vars_entry (const struct types_used_by_vars_entry *entry)
6141 {
6142 gcc_assert (entry && entry->var_decl && entry->type);
6143
6144 return iterative_hash_object (entry->type,
6145 iterative_hash_object (entry->var_decl, 0));
6146 }
6147
6148 /* Hash function of the types_used_by_vars_entry hash table. */
6149
6150 hashval_t
6151 used_type_hasher::hash (types_used_by_vars_entry *entry)
6152 {
6153 return hash_types_used_by_vars_entry (entry);
6154 }
6155
6156 /*Equality function of the types_used_by_vars_entry hash table. */
6157
6158 bool
6159 used_type_hasher::equal (types_used_by_vars_entry *e1,
6160 types_used_by_vars_entry *e2)
6161 {
6162 return (e1->var_decl == e2->var_decl && e1->type == e2->type);
6163 }
6164
6165 /* Inserts an entry into the types_used_by_vars_hash hash table. */
6166
6167 void
6168 types_used_by_var_decl_insert (tree type, tree var_decl)
6169 {
6170 if (type != NULL && var_decl != NULL)
6171 {
6172 types_used_by_vars_entry **slot;
6173 struct types_used_by_vars_entry e;
6174 e.var_decl = var_decl;
6175 e.type = type;
6176 if (types_used_by_vars_hash == NULL)
6177 types_used_by_vars_hash
6178 = hash_table<used_type_hasher>::create_ggc (37);
6179
6180 slot = types_used_by_vars_hash->find_slot (&e, INSERT);
6181 if (*slot == NULL)
6182 {
6183 struct types_used_by_vars_entry *entry;
6184 entry = ggc_alloc<types_used_by_vars_entry> ();
6185 entry->type = type;
6186 entry->var_decl = var_decl;
6187 *slot = entry;
6188 }
6189 }
6190 }
6191
6192 namespace {
6193
6194 const pass_data pass_data_leaf_regs =
6195 {
6196 RTL_PASS, /* type */
6197 "*leaf_regs", /* name */
6198 OPTGROUP_NONE, /* optinfo_flags */
6199 TV_NONE, /* tv_id */
6200 0, /* properties_required */
6201 0, /* properties_provided */
6202 0, /* properties_destroyed */
6203 0, /* todo_flags_start */
6204 0, /* todo_flags_finish */
6205 };
6206
6207 class pass_leaf_regs : public rtl_opt_pass
6208 {
6209 public:
6210 pass_leaf_regs (gcc::context *ctxt)
6211 : rtl_opt_pass (pass_data_leaf_regs, ctxt)
6212 {}
6213
6214 /* opt_pass methods: */
6215 virtual unsigned int execute (function *)
6216 {
6217 return rest_of_handle_check_leaf_regs ();
6218 }
6219
6220 }; // class pass_leaf_regs
6221
6222 } // anon namespace
6223
6224 rtl_opt_pass *
6225 make_pass_leaf_regs (gcc::context *ctxt)
6226 {
6227 return new pass_leaf_regs (ctxt);
6228 }
6229
6230 static unsigned int
6231 rest_of_handle_thread_prologue_and_epilogue (void)
6232 {
6233 if (optimize)
6234 cleanup_cfg (CLEANUP_EXPENSIVE);
6235
6236 /* On some machines, the prologue and epilogue code, or parts thereof,
6237 can be represented as RTL. Doing so lets us schedule insns between
6238 it and the rest of the code and also allows delayed branch
6239 scheduling to operate in the epilogue. */
6240 thread_prologue_and_epilogue_insns ();
6241
6242 /* Shrink-wrapping can result in unreachable edges in the epilogue,
6243 see PR57320. */
6244 cleanup_cfg (0);
6245
6246 /* The stack usage info is finalized during prologue expansion. */
6247 if (flag_stack_usage_info)
6248 output_stack_usage ();
6249
6250 return 0;
6251 }
6252
6253 namespace {
6254
6255 const pass_data pass_data_thread_prologue_and_epilogue =
6256 {
6257 RTL_PASS, /* type */
6258 "pro_and_epilogue", /* name */
6259 OPTGROUP_NONE, /* optinfo_flags */
6260 TV_THREAD_PROLOGUE_AND_EPILOGUE, /* tv_id */
6261 0, /* properties_required */
6262 0, /* properties_provided */
6263 0, /* properties_destroyed */
6264 0, /* todo_flags_start */
6265 ( TODO_df_verify | TODO_df_finish ), /* todo_flags_finish */
6266 };
6267
6268 class pass_thread_prologue_and_epilogue : public rtl_opt_pass
6269 {
6270 public:
6271 pass_thread_prologue_and_epilogue (gcc::context *ctxt)
6272 : rtl_opt_pass (pass_data_thread_prologue_and_epilogue, ctxt)
6273 {}
6274
6275 /* opt_pass methods: */
6276 virtual unsigned int execute (function *)
6277 {
6278 return rest_of_handle_thread_prologue_and_epilogue ();
6279 }
6280
6281 }; // class pass_thread_prologue_and_epilogue
6282
6283 } // anon namespace
6284
6285 rtl_opt_pass *
6286 make_pass_thread_prologue_and_epilogue (gcc::context *ctxt)
6287 {
6288 return new pass_thread_prologue_and_epilogue (ctxt);
6289 }
6290 \f
6291
6292 /* This mini-pass fixes fall-out from SSA in asm statements that have
6293 in-out constraints. Say you start with
6294
6295 orig = inout;
6296 asm ("": "+mr" (inout));
6297 use (orig);
6298
6299 which is transformed very early to use explicit output and match operands:
6300
6301 orig = inout;
6302 asm ("": "=mr" (inout) : "0" (inout));
6303 use (orig);
6304
6305 Or, after SSA and copyprop,
6306
6307 asm ("": "=mr" (inout_2) : "0" (inout_1));
6308 use (inout_1);
6309
6310 Clearly inout_2 and inout_1 can't be coalesced easily anymore, as
6311 they represent two separate values, so they will get different pseudo
6312 registers during expansion. Then, since the two operands need to match
6313 per the constraints, but use different pseudo registers, reload can
6314 only register a reload for these operands. But reloads can only be
6315 satisfied by hardregs, not by memory, so we need a register for this
6316 reload, just because we are presented with non-matching operands.
6317 So, even though we allow memory for this operand, no memory can be
6318 used for it, just because the two operands don't match. This can
6319 cause reload failures on register-starved targets.
6320
6321 So it's a symptom of reload not being able to use memory for reloads
6322 or, alternatively it's also a symptom of both operands not coming into
6323 reload as matching (in which case the pseudo could go to memory just
6324 fine, as the alternative allows it, and no reload would be necessary).
6325 We fix the latter problem here, by transforming
6326
6327 asm ("": "=mr" (inout_2) : "0" (inout_1));
6328
6329 back to
6330
6331 inout_2 = inout_1;
6332 asm ("": "=mr" (inout_2) : "0" (inout_2)); */
6333
6334 static void
6335 match_asm_constraints_1 (rtx_insn *insn, rtx *p_sets, int noutputs)
6336 {
6337 int i;
6338 bool changed = false;
6339 rtx op = SET_SRC (p_sets[0]);
6340 int ninputs = ASM_OPERANDS_INPUT_LENGTH (op);
6341 rtvec inputs = ASM_OPERANDS_INPUT_VEC (op);
6342 bool *output_matched = XALLOCAVEC (bool, noutputs);
6343
6344 memset (output_matched, 0, noutputs * sizeof (bool));
6345 for (i = 0; i < ninputs; i++)
6346 {
6347 rtx input, output;
6348 rtx_insn *insns;
6349 const char *constraint = ASM_OPERANDS_INPUT_CONSTRAINT (op, i);
6350 char *end;
6351 int match, j;
6352
6353 if (*constraint == '%')
6354 constraint++;
6355
6356 match = strtoul (constraint, &end, 10);
6357 if (end == constraint)
6358 continue;
6359
6360 gcc_assert (match < noutputs);
6361 output = SET_DEST (p_sets[match]);
6362 input = RTVEC_ELT (inputs, i);
6363 /* Only do the transformation for pseudos. */
6364 if (! REG_P (output)
6365 || rtx_equal_p (output, input)
6366 || (GET_MODE (input) != VOIDmode
6367 && GET_MODE (input) != GET_MODE (output)))
6368 continue;
6369
6370 /* We can't do anything if the output is also used as input,
6371 as we're going to overwrite it. */
6372 for (j = 0; j < ninputs; j++)
6373 if (reg_overlap_mentioned_p (output, RTVEC_ELT (inputs, j)))
6374 break;
6375 if (j != ninputs)
6376 continue;
6377
6378 /* Avoid changing the same input several times. For
6379 asm ("" : "=mr" (out1), "=mr" (out2) : "0" (in), "1" (in));
6380 only change in once (to out1), rather than changing it
6381 first to out1 and afterwards to out2. */
6382 if (i > 0)
6383 {
6384 for (j = 0; j < noutputs; j++)
6385 if (output_matched[j] && input == SET_DEST (p_sets[j]))
6386 break;
6387 if (j != noutputs)
6388 continue;
6389 }
6390 output_matched[match] = true;
6391
6392 start_sequence ();
6393 emit_move_insn (output, input);
6394 insns = get_insns ();
6395 end_sequence ();
6396 emit_insn_before (insns, insn);
6397
6398 /* Now replace all mentions of the input with output. We can't
6399 just replace the occurrence in inputs[i], as the register might
6400 also be used in some other input (or even in an address of an
6401 output), which would mean possibly increasing the number of
6402 inputs by one (namely 'output' in addition), which might pose
6403 a too complicated problem for reload to solve. E.g. this situation:
6404
6405 asm ("" : "=r" (output), "=m" (input) : "0" (input))
6406
6407 Here 'input' is used in two occurrences as input (once for the
6408 input operand, once for the address in the second output operand).
6409 If we would replace only the occurrence of the input operand (to
6410 make the matching) we would be left with this:
6411
6412 output = input
6413 asm ("" : "=r" (output), "=m" (input) : "0" (output))
6414
6415 Now we suddenly have two different input values (containing the same
6416 value, but different pseudos) where we formerly had only one.
6417 With more complicated asms this might lead to reload failures
6418 which wouldn't have happen without this pass. So, iterate over
6419 all operands and replace all occurrences of the register used. */
6420 for (j = 0; j < noutputs; j++)
6421 if (!rtx_equal_p (SET_DEST (p_sets[j]), input)
6422 && reg_overlap_mentioned_p (input, SET_DEST (p_sets[j])))
6423 SET_DEST (p_sets[j]) = replace_rtx (SET_DEST (p_sets[j]),
6424 input, output);
6425 for (j = 0; j < ninputs; j++)
6426 if (reg_overlap_mentioned_p (input, RTVEC_ELT (inputs, j)))
6427 RTVEC_ELT (inputs, j) = replace_rtx (RTVEC_ELT (inputs, j),
6428 input, output);
6429
6430 changed = true;
6431 }
6432
6433 if (changed)
6434 df_insn_rescan (insn);
6435 }
6436
6437 namespace {
6438
6439 const pass_data pass_data_match_asm_constraints =
6440 {
6441 RTL_PASS, /* type */
6442 "asmcons", /* name */
6443 OPTGROUP_NONE, /* optinfo_flags */
6444 TV_NONE, /* tv_id */
6445 0, /* properties_required */
6446 0, /* properties_provided */
6447 0, /* properties_destroyed */
6448 0, /* todo_flags_start */
6449 0, /* todo_flags_finish */
6450 };
6451
6452 class pass_match_asm_constraints : public rtl_opt_pass
6453 {
6454 public:
6455 pass_match_asm_constraints (gcc::context *ctxt)
6456 : rtl_opt_pass (pass_data_match_asm_constraints, ctxt)
6457 {}
6458
6459 /* opt_pass methods: */
6460 virtual unsigned int execute (function *);
6461
6462 }; // class pass_match_asm_constraints
6463
6464 unsigned
6465 pass_match_asm_constraints::execute (function *fun)
6466 {
6467 basic_block bb;
6468 rtx_insn *insn;
6469 rtx pat, *p_sets;
6470 int noutputs;
6471
6472 if (!crtl->has_asm_statement)
6473 return 0;
6474
6475 df_set_flags (DF_DEFER_INSN_RESCAN);
6476 FOR_EACH_BB_FN (bb, fun)
6477 {
6478 FOR_BB_INSNS (bb, insn)
6479 {
6480 if (!INSN_P (insn))
6481 continue;
6482
6483 pat = PATTERN (insn);
6484 if (GET_CODE (pat) == PARALLEL)
6485 p_sets = &XVECEXP (pat, 0, 0), noutputs = XVECLEN (pat, 0);
6486 else if (GET_CODE (pat) == SET)
6487 p_sets = &PATTERN (insn), noutputs = 1;
6488 else
6489 continue;
6490
6491 if (GET_CODE (*p_sets) == SET
6492 && GET_CODE (SET_SRC (*p_sets)) == ASM_OPERANDS)
6493 match_asm_constraints_1 (insn, p_sets, noutputs);
6494 }
6495 }
6496
6497 return TODO_df_finish;
6498 }
6499
6500 } // anon namespace
6501
6502 rtl_opt_pass *
6503 make_pass_match_asm_constraints (gcc::context *ctxt)
6504 {
6505 return new pass_match_asm_constraints (ctxt);
6506 }
6507
6508
6509 #include "gt-function.h"