1 /* Save and restore call-clobbered registers which are live across a call.
2 Copyright (C) 1989-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
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
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
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/>. */
22 #include "coretypes.h"
26 #include "insn-config.h"
28 #include "hard-reg-set.h"
32 #include "dominance.h"
34 #include "basic-block.h"
48 #include "diagnostic-core.h"
50 #include "addresses.h"
54 #define MOVE_MAX_WORDS (MOVE_MAX / UNITS_PER_WORD)
56 #define regno_save_mode \
57 (this_target_reload->x_regno_save_mode)
58 #define cached_reg_save_code \
59 (this_target_reload->x_cached_reg_save_code)
60 #define cached_reg_restore_code \
61 (this_target_reload->x_cached_reg_restore_code)
63 /* For each hard register, a place on the stack where it can be saved,
67 regno_save_mem
[FIRST_PSEUDO_REGISTER
][MAX_MOVE_MAX
/ MIN_UNITS_PER_WORD
+ 1];
69 /* The number of elements in the subsequent array. */
70 static int save_slots_num
;
72 /* Allocated slots so far. */
73 static rtx save_slots
[FIRST_PSEUDO_REGISTER
];
75 /* Set of hard regs currently residing in save area (during insn scan). */
77 static HARD_REG_SET hard_regs_saved
;
79 /* Number of registers currently in hard_regs_saved. */
81 static int n_regs_saved
;
83 /* Computed by mark_referenced_regs, all regs referenced in a given
85 static HARD_REG_SET referenced_regs
;
88 typedef void refmarker_fn (rtx
*loc
, machine_mode mode
, int hardregno
,
91 static int reg_save_code (int, machine_mode
);
92 static int reg_restore_code (int, machine_mode
);
94 struct saved_hard_reg
;
95 static void initiate_saved_hard_regs (void);
96 static void new_saved_hard_reg (int, int);
97 static void finish_saved_hard_regs (void);
98 static int saved_hard_reg_compare_func (const void *, const void *);
100 static void mark_set_regs (rtx
, const_rtx
, void *);
101 static void mark_referenced_regs (rtx
*, refmarker_fn
*mark
, void *mark_arg
);
102 static refmarker_fn mark_reg_as_referenced
;
103 static refmarker_fn replace_reg_with_saved_mem
;
104 static int insert_save (struct insn_chain
*, int, int, HARD_REG_SET
*,
106 static int insert_restore (struct insn_chain
*, int, int, int,
108 static struct insn_chain
*insert_one_insn (struct insn_chain
*, int, int,
110 static void add_stored_regs (rtx
, const_rtx
, void *);
114 static GTY(()) rtx savepat
;
115 static GTY(()) rtx restpat
;
116 static GTY(()) rtx test_reg
;
117 static GTY(()) rtx test_mem
;
118 static GTY(()) rtx_insn
*saveinsn
;
119 static GTY(()) rtx_insn
*restinsn
;
121 /* Return the INSN_CODE used to save register REG in mode MODE. */
123 reg_save_code (int reg
, machine_mode mode
)
126 if (cached_reg_save_code
[reg
][mode
])
127 return cached_reg_save_code
[reg
][mode
];
128 if (!HARD_REGNO_MODE_OK (reg
, mode
))
130 /* Depending on how HARD_REGNO_MODE_OK is defined, range propagation
131 might deduce here that reg >= FIRST_PSEUDO_REGISTER. So the assert
132 below silences a warning. */
133 gcc_assert (reg
< FIRST_PSEUDO_REGISTER
);
134 cached_reg_save_code
[reg
][mode
] = -1;
135 cached_reg_restore_code
[reg
][mode
] = -1;
139 /* Update the register number and modes of the register
140 and memory operand. */
141 set_mode_and_regno (test_reg
, mode
, reg
);
142 PUT_MODE (test_mem
, mode
);
144 /* Force re-recognition of the modified insns. */
145 INSN_CODE (saveinsn
) = -1;
146 INSN_CODE (restinsn
) = -1;
148 cached_reg_save_code
[reg
][mode
] = recog_memoized (saveinsn
);
149 cached_reg_restore_code
[reg
][mode
] = recog_memoized (restinsn
);
151 /* Now extract both insns and see if we can meet their
152 constraints. We don't know here whether the save and restore will
153 be in size- or speed-tuned code, so just use the set of enabled
155 ok
= (cached_reg_save_code
[reg
][mode
] != -1
156 && cached_reg_restore_code
[reg
][mode
] != -1);
159 extract_insn (saveinsn
);
160 ok
= constrain_operands (1, get_enabled_alternatives (saveinsn
));
161 extract_insn (restinsn
);
162 ok
&= constrain_operands (1, get_enabled_alternatives (restinsn
));
167 cached_reg_save_code
[reg
][mode
] = -1;
168 cached_reg_restore_code
[reg
][mode
] = -1;
170 gcc_assert (cached_reg_save_code
[reg
][mode
]);
171 return cached_reg_save_code
[reg
][mode
];
174 /* Return the INSN_CODE used to restore register REG in mode MODE. */
176 reg_restore_code (int reg
, machine_mode mode
)
178 if (cached_reg_restore_code
[reg
][mode
])
179 return cached_reg_restore_code
[reg
][mode
];
180 /* Populate our cache. */
181 reg_save_code (reg
, mode
);
182 return cached_reg_restore_code
[reg
][mode
];
185 /* Initialize for caller-save.
187 Look at all the hard registers that are used by a call and for which
188 reginfo.c has not already excluded from being used across a call.
190 Ensure that we can find a mode to save the register and that there is a
191 simple insn to save and restore the register. This latter check avoids
192 problems that would occur if we tried to save the MQ register of some
193 machines directly into memory. */
196 init_caller_save (void)
203 if (caller_save_initialized_p
)
206 caller_save_initialized_p
= true;
208 CLEAR_HARD_REG_SET (no_caller_save_reg_set
);
209 /* First find all the registers that we need to deal with and all
210 the modes that they can have. If we can't find a mode to use,
211 we can't have the register live over calls. */
213 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
215 if (call_used_regs
[i
]
216 && !TEST_HARD_REG_BIT (call_fixed_reg_set
, i
))
218 for (j
= 1; j
<= MOVE_MAX_WORDS
; j
++)
220 regno_save_mode
[i
][j
] = HARD_REGNO_CALLER_SAVE_MODE (i
, j
,
222 if (regno_save_mode
[i
][j
] == VOIDmode
&& j
== 1)
224 SET_HARD_REG_BIT (call_fixed_reg_set
, i
);
229 regno_save_mode
[i
][1] = VOIDmode
;
232 /* The following code tries to approximate the conditions under which
233 we can easily save and restore a register without scratch registers or
234 other complexities. It will usually work, except under conditions where
235 the validity of an insn operand is dependent on the address offset.
236 No such cases are currently known.
238 We first find a typical offset from some BASE_REG_CLASS register.
239 This address is chosen by finding the first register in the class
240 and by finding the smallest power of two that is a valid offset from
241 that register in every mode we will use to save registers. */
243 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
244 if (TEST_HARD_REG_BIT
246 [(int) base_reg_class (regno_save_mode
[i
][1], ADDR_SPACE_GENERIC
,
247 PLUS
, CONST_INT
)], i
))
250 gcc_assert (i
< FIRST_PSEUDO_REGISTER
);
252 addr_reg
= gen_rtx_REG (Pmode
, i
);
254 for (offset
= 1 << (HOST_BITS_PER_INT
/ 2); offset
; offset
>>= 1)
256 address
= gen_rtx_PLUS (Pmode
, addr_reg
, gen_int_mode (offset
, Pmode
));
258 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
259 if (regno_save_mode
[i
][1] != VOIDmode
260 && ! strict_memory_address_p (regno_save_mode
[i
][1], address
))
263 if (i
== FIRST_PSEUDO_REGISTER
)
267 /* If we didn't find a valid address, we must use register indirect. */
271 /* Next we try to form an insn to save and restore the register. We
272 see if such an insn is recognized and meets its constraints.
274 To avoid lots of unnecessary RTL allocation, we construct all the RTL
275 once, then modify the memory and register operands in-place. */
277 test_reg
= gen_rtx_REG (word_mode
, LAST_VIRTUAL_REGISTER
+ 1);
278 test_mem
= gen_rtx_MEM (word_mode
, address
);
279 savepat
= gen_rtx_SET (test_mem
, test_reg
);
280 restpat
= gen_rtx_SET (test_reg
, test_mem
);
282 saveinsn
= gen_rtx_INSN (VOIDmode
, 0, 0, 0, savepat
, 0, -1, 0);
283 restinsn
= gen_rtx_INSN (VOIDmode
, 0, 0, 0, restpat
, 0, -1, 0);
285 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
286 for (j
= 1; j
<= MOVE_MAX_WORDS
; j
++)
287 if (reg_save_code (i
,regno_save_mode
[i
][j
]) == -1)
289 regno_save_mode
[i
][j
] = VOIDmode
;
292 SET_HARD_REG_BIT (call_fixed_reg_set
, i
);
293 if (call_used_regs
[i
])
294 SET_HARD_REG_BIT (no_caller_save_reg_set
, i
);
301 /* Initialize save areas by showing that we haven't allocated any yet. */
304 init_save_areas (void)
308 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
309 for (j
= 1; j
<= MOVE_MAX_WORDS
; j
++)
310 regno_save_mem
[i
][j
] = 0;
315 /* The structure represents a hard register which should be saved
316 through the call. It is used when the integrated register
317 allocator (IRA) is used and sharing save slots is on. */
318 struct saved_hard_reg
320 /* Order number starting with 0. */
322 /* The hard regno. */
324 /* Execution frequency of all calls through which given hard
325 register should be saved. */
327 /* Stack slot reserved to save the hard register through calls. */
329 /* True if it is first hard register in the chain of hard registers
330 sharing the same stack slot. */
332 /* Order number of the next hard register structure with the same
333 slot in the chain. -1 represents end of the chain. */
337 /* Map: hard register number to the corresponding structure. */
338 static struct saved_hard_reg
*hard_reg_map
[FIRST_PSEUDO_REGISTER
];
340 /* The number of all structures representing hard registers should be
341 saved, in order words, the number of used elements in the following
343 static int saved_regs_num
;
345 /* Pointers to all the structures. Index is the order number of the
346 corresponding structure. */
347 static struct saved_hard_reg
*all_saved_regs
[FIRST_PSEUDO_REGISTER
];
349 /* First called function for work with saved hard registers. */
351 initiate_saved_hard_regs (void)
356 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
357 hard_reg_map
[i
] = NULL
;
360 /* Allocate and return new saved hard register with given REGNO and
363 new_saved_hard_reg (int regno
, int call_freq
)
365 struct saved_hard_reg
*saved_reg
;
368 = (struct saved_hard_reg
*) xmalloc (sizeof (struct saved_hard_reg
));
369 hard_reg_map
[regno
] = all_saved_regs
[saved_regs_num
] = saved_reg
;
370 saved_reg
->num
= saved_regs_num
++;
371 saved_reg
->hard_regno
= regno
;
372 saved_reg
->call_freq
= call_freq
;
373 saved_reg
->first_p
= FALSE
;
374 saved_reg
->next
= -1;
377 /* Free memory allocated for the saved hard registers. */
379 finish_saved_hard_regs (void)
383 for (i
= 0; i
< saved_regs_num
; i
++)
384 free (all_saved_regs
[i
]);
387 /* The function is used to sort the saved hard register structures
388 according their frequency. */
390 saved_hard_reg_compare_func (const void *v1p
, const void *v2p
)
392 const struct saved_hard_reg
*p1
= *(struct saved_hard_reg
* const *) v1p
;
393 const struct saved_hard_reg
*p2
= *(struct saved_hard_reg
* const *) v2p
;
395 if (flag_omit_frame_pointer
)
397 if (p1
->call_freq
- p2
->call_freq
!= 0)
398 return p1
->call_freq
- p2
->call_freq
;
400 else if (p2
->call_freq
- p1
->call_freq
!= 0)
401 return p2
->call_freq
- p1
->call_freq
;
403 return p1
->num
- p2
->num
;
406 /* Allocate save areas for any hard registers that might need saving.
407 We take a conservative approach here and look for call-clobbered hard
408 registers that are assigned to pseudos that cross calls. This may
409 overestimate slightly (especially if some of these registers are later
410 used as spill registers), but it should not be significant.
412 For IRA we use priority coloring to decrease stack slots needed for
413 saving hard registers through calls. We build conflicts for them
418 In the fallback case we should iterate backwards across all possible
419 modes for the save, choosing the largest available one instead of
420 falling back to the smallest mode immediately. (eg TF -> DF -> SF).
422 We do not try to use "move multiple" instructions that exist
423 on some machines (such as the 68k moveml). It could be a win to try
424 and use them when possible. The hard part is doing it in a way that is
425 machine independent since they might be saving non-consecutive
426 registers. (imagine caller-saving d0,d1,a0,a1 on the 68k) */
429 setup_save_areas (void)
432 HARD_REG_SET hard_regs_used
;
433 struct saved_hard_reg
*saved_reg
;
435 struct insn_chain
*chain
, *next
;
437 HARD_REG_SET hard_regs_to_save
, used_regs
, this_insn_sets
;
438 reg_set_iterator rsi
;
440 CLEAR_HARD_REG_SET (hard_regs_used
);
442 /* Find every CALL_INSN and record which hard regs are live across the
443 call into HARD_REG_MAP and HARD_REGS_USED. */
444 initiate_saved_hard_regs ();
445 /* Create hard reg saved regs. */
446 for (chain
= reload_insn_chain
; chain
!= 0; chain
= next
)
453 || find_reg_note (insn
, REG_NORETURN
, NULL
))
455 freq
= REG_FREQ_FROM_BB (BLOCK_FOR_INSN (insn
));
456 REG_SET_TO_HARD_REG_SET (hard_regs_to_save
,
457 &chain
->live_throughout
);
458 get_call_reg_set_usage (insn
, &used_regs
, call_used_reg_set
);
460 /* Record all registers set in this call insn. These don't
461 need to be saved. N.B. the call insn might set a subreg
462 of a multi-hard-reg pseudo; then the pseudo is considered
463 live during the call, but the subreg that is set
465 CLEAR_HARD_REG_SET (this_insn_sets
);
466 note_stores (PATTERN (insn
), mark_set_regs
, &this_insn_sets
);
467 /* Sibcalls are considered to set the return value. */
468 if (SIBLING_CALL_P (insn
) && crtl
->return_rtx
)
469 mark_set_regs (crtl
->return_rtx
, NULL_RTX
, &this_insn_sets
);
471 AND_COMPL_HARD_REG_SET (used_regs
, call_fixed_reg_set
);
472 AND_COMPL_HARD_REG_SET (used_regs
, this_insn_sets
);
473 AND_HARD_REG_SET (hard_regs_to_save
, used_regs
);
474 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
475 if (TEST_HARD_REG_BIT (hard_regs_to_save
, regno
))
477 if (hard_reg_map
[regno
] != NULL
)
478 hard_reg_map
[regno
]->call_freq
+= freq
;
480 new_saved_hard_reg (regno
, freq
);
481 SET_HARD_REG_BIT (hard_regs_used
, regno
);
483 cheap
= find_reg_note (insn
, REG_RETURNED
, NULL
);
485 cheap
= XEXP (cheap
, 0);
486 /* Look through all live pseudos, mark their hard registers. */
487 EXECUTE_IF_SET_IN_REG_SET
488 (&chain
->live_throughout
, FIRST_PSEUDO_REGISTER
, regno
, rsi
)
490 int r
= reg_renumber
[regno
];
493 if (r
< 0 || regno_reg_rtx
[regno
] == cheap
)
496 bound
= r
+ hard_regno_nregs
[r
][PSEUDO_REGNO_MODE (regno
)];
497 for (; r
< bound
; r
++)
498 if (TEST_HARD_REG_BIT (used_regs
, r
))
500 if (hard_reg_map
[r
] != NULL
)
501 hard_reg_map
[r
]->call_freq
+= freq
;
503 new_saved_hard_reg (r
, freq
);
504 SET_HARD_REG_BIT (hard_regs_to_save
, r
);
505 SET_HARD_REG_BIT (hard_regs_used
, r
);
510 /* If requested, figure out which hard regs can share save slots. */
511 if (optimize
&& flag_ira_share_save_slots
)
514 char *saved_reg_conflicts
;
516 struct saved_hard_reg
*saved_reg2
, *saved_reg3
;
517 int call_saved_regs_num
;
518 struct saved_hard_reg
*call_saved_regs
[FIRST_PSEUDO_REGISTER
];
520 int prev_save_slots_num
;
521 rtx prev_save_slots
[FIRST_PSEUDO_REGISTER
];
523 /* Find saved hard register conflicts. */
524 saved_reg_conflicts
= (char *) xmalloc (saved_regs_num
* saved_regs_num
);
525 memset (saved_reg_conflicts
, 0, saved_regs_num
* saved_regs_num
);
526 for (chain
= reload_insn_chain
; chain
!= 0; chain
= next
)
529 call_saved_regs_num
= 0;
533 || find_reg_note (insn
, REG_NORETURN
, NULL
))
536 cheap
= find_reg_note (insn
, REG_RETURNED
, NULL
);
538 cheap
= XEXP (cheap
, 0);
540 REG_SET_TO_HARD_REG_SET (hard_regs_to_save
,
541 &chain
->live_throughout
);
542 get_call_reg_set_usage (insn
, &used_regs
, call_used_reg_set
);
544 /* Record all registers set in this call insn. These don't
545 need to be saved. N.B. the call insn might set a subreg
546 of a multi-hard-reg pseudo; then the pseudo is considered
547 live during the call, but the subreg that is set
549 CLEAR_HARD_REG_SET (this_insn_sets
);
550 note_stores (PATTERN (insn
), mark_set_regs
, &this_insn_sets
);
551 /* Sibcalls are considered to set the return value,
552 compare df-scan.c:df_get_call_refs. */
553 if (SIBLING_CALL_P (insn
) && crtl
->return_rtx
)
554 mark_set_regs (crtl
->return_rtx
, NULL_RTX
, &this_insn_sets
);
556 AND_COMPL_HARD_REG_SET (used_regs
, call_fixed_reg_set
);
557 AND_COMPL_HARD_REG_SET (used_regs
, this_insn_sets
);
558 AND_HARD_REG_SET (hard_regs_to_save
, used_regs
);
559 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
560 if (TEST_HARD_REG_BIT (hard_regs_to_save
, regno
))
562 gcc_assert (hard_reg_map
[regno
] != NULL
);
563 call_saved_regs
[call_saved_regs_num
++] = hard_reg_map
[regno
];
565 /* Look through all live pseudos, mark their hard registers. */
566 EXECUTE_IF_SET_IN_REG_SET
567 (&chain
->live_throughout
, FIRST_PSEUDO_REGISTER
, regno
, rsi
)
569 int r
= reg_renumber
[regno
];
572 if (r
< 0 || regno_reg_rtx
[regno
] == cheap
)
575 bound
= r
+ hard_regno_nregs
[r
][PSEUDO_REGNO_MODE (regno
)];
576 for (; r
< bound
; r
++)
577 if (TEST_HARD_REG_BIT (used_regs
, r
))
578 call_saved_regs
[call_saved_regs_num
++] = hard_reg_map
[r
];
580 for (i
= 0; i
< call_saved_regs_num
; i
++)
582 saved_reg
= call_saved_regs
[i
];
583 for (j
= 0; j
< call_saved_regs_num
; j
++)
586 saved_reg2
= call_saved_regs
[j
];
587 saved_reg_conflicts
[saved_reg
->num
* saved_regs_num
589 = saved_reg_conflicts
[saved_reg2
->num
* saved_regs_num
595 /* Sort saved hard regs. */
596 qsort (all_saved_regs
, saved_regs_num
, sizeof (struct saved_hard_reg
*),
597 saved_hard_reg_compare_func
);
598 /* Initiate slots available from the previous reload
600 prev_save_slots_num
= save_slots_num
;
601 memcpy (prev_save_slots
, save_slots
, save_slots_num
* sizeof (rtx
));
603 /* Allocate stack slots for the saved hard registers. */
604 for (i
= 0; i
< saved_regs_num
; i
++)
606 saved_reg
= all_saved_regs
[i
];
607 regno
= saved_reg
->hard_regno
;
608 for (j
= 0; j
< i
; j
++)
610 saved_reg2
= all_saved_regs
[j
];
611 if (! saved_reg2
->first_p
)
613 slot
= saved_reg2
->slot
;
614 for (k
= j
; k
>= 0; k
= next_k
)
616 saved_reg3
= all_saved_regs
[k
];
617 next_k
= saved_reg3
->next
;
618 if (saved_reg_conflicts
[saved_reg
->num
* saved_regs_num
623 && (GET_MODE_SIZE (regno_save_mode
[regno
][1])
624 <= GET_MODE_SIZE (regno_save_mode
625 [saved_reg2
->hard_regno
][1])))
629 (slot
, regno_save_mode
[saved_reg
->hard_regno
][1], 0);
630 regno_save_mem
[regno
][1] = saved_reg
->slot
;
631 saved_reg
->next
= saved_reg2
->next
;
632 saved_reg2
->next
= i
;
633 if (dump_file
!= NULL
)
634 fprintf (dump_file
, "%d uses slot of %d\n",
635 regno
, saved_reg2
->hard_regno
);
641 saved_reg
->first_p
= TRUE
;
642 for (best_slot_num
= -1, j
= 0; j
< prev_save_slots_num
; j
++)
644 slot
= prev_save_slots
[j
];
645 if (slot
== NULL_RTX
)
647 if (GET_MODE_SIZE (regno_save_mode
[regno
][1])
648 <= GET_MODE_SIZE (GET_MODE (slot
))
649 && best_slot_num
< 0)
651 if (GET_MODE (slot
) == regno_save_mode
[regno
][1])
654 if (best_slot_num
>= 0)
656 saved_reg
->slot
= prev_save_slots
[best_slot_num
];
660 regno_save_mode
[saved_reg
->hard_regno
][1], 0);
661 if (dump_file
!= NULL
)
663 "%d uses a slot from prev iteration\n", regno
);
664 prev_save_slots
[best_slot_num
] = NULL_RTX
;
665 if (best_slot_num
+ 1 == prev_save_slots_num
)
666 prev_save_slots_num
--;
671 = assign_stack_local_1
672 (regno_save_mode
[regno
][1],
673 GET_MODE_SIZE (regno_save_mode
[regno
][1]), 0,
675 if (dump_file
!= NULL
)
676 fprintf (dump_file
, "%d uses a new slot\n", regno
);
678 regno_save_mem
[regno
][1] = saved_reg
->slot
;
679 save_slots
[save_slots_num
++] = saved_reg
->slot
;
682 free (saved_reg_conflicts
);
683 finish_saved_hard_regs ();
687 /* We are not sharing slots.
689 Run through all the call-used hard-registers and allocate
690 space for each in the caller-save area. Try to allocate space
691 in a manner which allows multi-register saves/restores to be done. */
693 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
694 for (j
= MOVE_MAX_WORDS
; j
> 0; j
--)
698 /* If no mode exists for this size, try another. Also break out
699 if we have already saved this hard register. */
700 if (regno_save_mode
[i
][j
] == VOIDmode
|| regno_save_mem
[i
][1] != 0)
703 /* See if any register in this group has been saved. */
704 for (k
= 0; k
< j
; k
++)
705 if (regno_save_mem
[i
+ k
][1])
713 for (k
= 0; k
< j
; k
++)
714 if (! TEST_HARD_REG_BIT (hard_regs_used
, i
+ k
))
722 /* We have found an acceptable mode to store in. Since
723 hard register is always saved in the widest mode
724 available, the mode may be wider than necessary, it is
725 OK to reduce the alignment of spill space. We will
726 verify that it is equal to or greater than required
727 when we restore and save the hard register in
728 insert_restore and insert_save. */
730 = assign_stack_local_1 (regno_save_mode
[i
][j
],
731 GET_MODE_SIZE (regno_save_mode
[i
][j
]),
732 0, ASLK_REDUCE_ALIGN
);
734 /* Setup single word save area just in case... */
735 for (k
= 0; k
< j
; k
++)
736 /* This should not depend on WORDS_BIG_ENDIAN.
737 The order of words in regs is the same as in memory. */
738 regno_save_mem
[i
+ k
][1]
739 = adjust_address_nv (regno_save_mem
[i
][j
],
740 regno_save_mode
[i
+ k
][1],
745 /* Now loop again and set the alias set of any save areas we made to
746 the alias set used to represent frame objects. */
747 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
748 for (j
= MOVE_MAX_WORDS
; j
> 0; j
--)
749 if (regno_save_mem
[i
][j
] != 0)
750 set_mem_alias_set (regno_save_mem
[i
][j
], get_frame_alias_set ());
755 /* Find the places where hard regs are live across calls and save them. */
758 save_call_clobbered_regs (void)
760 struct insn_chain
*chain
, *next
, *last
= NULL
;
761 machine_mode save_mode
[FIRST_PSEUDO_REGISTER
];
763 /* Computed in mark_set_regs, holds all registers set by the current
765 HARD_REG_SET this_insn_sets
;
767 CLEAR_HARD_REG_SET (hard_regs_saved
);
770 for (chain
= reload_insn_chain
; chain
!= 0; chain
= next
)
772 rtx_insn
*insn
= chain
->insn
;
773 enum rtx_code code
= GET_CODE (insn
);
777 gcc_assert (!chain
->is_caller_save_insn
);
779 if (NONDEBUG_INSN_P (insn
))
781 /* If some registers have been saved, see if INSN references
782 any of them. We must restore them before the insn if so. */
787 HARD_REG_SET this_insn_sets
;
789 if (code
== JUMP_INSN
)
790 /* Restore all registers if this is a JUMP_INSN. */
791 COPY_HARD_REG_SET (referenced_regs
, hard_regs_saved
);
794 CLEAR_HARD_REG_SET (referenced_regs
);
795 mark_referenced_regs (&PATTERN (insn
),
796 mark_reg_as_referenced
, NULL
);
797 AND_HARD_REG_SET (referenced_regs
, hard_regs_saved
);
800 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
801 if (TEST_HARD_REG_BIT (referenced_regs
, regno
))
802 regno
+= insert_restore (chain
, 1, regno
, MOVE_MAX_WORDS
,
804 /* If a saved register is set after the call, this means we no
805 longer should restore it. This can happen when parts of a
806 multi-word pseudo do not conflict with other pseudos, so
807 IRA may allocate the same hard register for both. One may
808 be live across the call, while the other is set
810 CLEAR_HARD_REG_SET (this_insn_sets
);
811 note_stores (PATTERN (insn
), mark_set_regs
, &this_insn_sets
);
812 AND_COMPL_HARD_REG_SET (hard_regs_saved
, this_insn_sets
);
815 if (code
== CALL_INSN
816 && ! SIBLING_CALL_P (insn
)
817 && ! find_reg_note (insn
, REG_NORETURN
, NULL
))
820 HARD_REG_SET hard_regs_to_save
;
821 HARD_REG_SET call_def_reg_set
;
822 reg_set_iterator rsi
;
825 cheap
= find_reg_note (insn
, REG_RETURNED
, NULL
);
827 cheap
= XEXP (cheap
, 0);
829 /* Use the register life information in CHAIN to compute which
830 regs are live during the call. */
831 REG_SET_TO_HARD_REG_SET (hard_regs_to_save
,
832 &chain
->live_throughout
);
833 /* Save hard registers always in the widest mode available. */
834 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
835 if (TEST_HARD_REG_BIT (hard_regs_to_save
, regno
))
836 save_mode
[regno
] = regno_save_mode
[regno
][1];
838 save_mode
[regno
] = VOIDmode
;
840 /* Look through all live pseudos, mark their hard registers
841 and choose proper mode for saving. */
842 EXECUTE_IF_SET_IN_REG_SET
843 (&chain
->live_throughout
, FIRST_PSEUDO_REGISTER
, regno
, rsi
)
845 int r
= reg_renumber
[regno
];
849 if (r
< 0 || regno_reg_rtx
[regno
] == cheap
)
851 nregs
= hard_regno_nregs
[r
][PSEUDO_REGNO_MODE (regno
)];
852 mode
= HARD_REGNO_CALLER_SAVE_MODE
853 (r
, nregs
, PSEUDO_REGNO_MODE (regno
));
854 if (GET_MODE_BITSIZE (mode
)
855 > GET_MODE_BITSIZE (save_mode
[r
]))
858 SET_HARD_REG_BIT (hard_regs_to_save
, r
+ nregs
);
861 /* Record all registers set in this call insn. These don't need
862 to be saved. N.B. the call insn might set a subreg of a
863 multi-hard-reg pseudo; then the pseudo is considered live
864 during the call, but the subreg that is set isn't. */
865 CLEAR_HARD_REG_SET (this_insn_sets
);
866 note_stores (PATTERN (insn
), mark_set_regs
, &this_insn_sets
);
868 /* Compute which hard regs must be saved before this call. */
869 AND_COMPL_HARD_REG_SET (hard_regs_to_save
, call_fixed_reg_set
);
870 AND_COMPL_HARD_REG_SET (hard_regs_to_save
, this_insn_sets
);
871 AND_COMPL_HARD_REG_SET (hard_regs_to_save
, hard_regs_saved
);
872 get_call_reg_set_usage (insn
, &call_def_reg_set
,
874 AND_HARD_REG_SET (hard_regs_to_save
, call_def_reg_set
);
876 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
877 if (TEST_HARD_REG_BIT (hard_regs_to_save
, regno
))
878 regno
+= insert_save (chain
, 1, regno
, &hard_regs_to_save
, save_mode
);
880 /* Must recompute n_regs_saved. */
882 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
883 if (TEST_HARD_REG_BIT (hard_regs_saved
, regno
))
887 && HARD_REGISTER_P (cheap
)
888 && TEST_HARD_REG_BIT (call_used_reg_set
, REGNO (cheap
)))
891 rtx pat
= PATTERN (insn
);
892 if (GET_CODE (pat
) == PARALLEL
)
893 pat
= XVECEXP (pat
, 0, 0);
894 dest
= SET_DEST (pat
);
895 /* For multiple return values dest is PARALLEL.
896 Currently we handle only single return value case. */
899 newpat
= gen_rtx_SET (cheap
, copy_rtx (dest
));
900 chain
= insert_one_insn (chain
, 0, -1, newpat
);
906 else if (DEBUG_INSN_P (insn
) && n_regs_saved
)
907 mark_referenced_regs (&PATTERN (insn
),
908 replace_reg_with_saved_mem
,
911 if (chain
->next
== 0 || chain
->next
->block
!= chain
->block
)
914 /* At the end of the basic block, we must restore any registers that
915 remain saved. If the last insn in the block is a JUMP_INSN, put
916 the restore before the insn, otherwise, put it after the insn. */
919 && DEBUG_INSN_P (insn
)
921 && last
->block
== chain
->block
)
923 rtx_insn
*ins
, *prev
;
924 basic_block bb
= BLOCK_FOR_INSN (insn
);
926 /* When adding hard reg restores after a DEBUG_INSN, move
927 all notes between last real insn and this DEBUG_INSN after
928 the DEBUG_INSN, otherwise we could get code
929 -g/-g0 differences. */
930 for (ins
= PREV_INSN (insn
); ins
!= last
->insn
; ins
= prev
)
932 prev
= PREV_INSN (ins
);
935 SET_NEXT_INSN (prev
) = NEXT_INSN (ins
);
936 SET_PREV_INSN (NEXT_INSN (ins
)) = prev
;
937 SET_PREV_INSN (ins
) = insn
;
938 SET_NEXT_INSN (ins
) = NEXT_INSN (insn
);
939 SET_NEXT_INSN (insn
) = ins
;
941 SET_PREV_INSN (NEXT_INSN (ins
)) = ins
;
942 if (BB_END (bb
) == insn
)
946 gcc_assert (DEBUG_INSN_P (ins
));
952 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
953 if (TEST_HARD_REG_BIT (hard_regs_saved
, regno
))
954 regno
+= insert_restore (chain
, JUMP_P (insn
),
955 regno
, MOVE_MAX_WORDS
, save_mode
);
960 /* Here from note_stores, or directly from save_call_clobbered_regs, when
961 an insn stores a value in a register.
962 Set the proper bit or bits in this_insn_sets. All pseudos that have
963 been assigned hard regs have had their register number changed already,
964 so we can ignore pseudos. */
966 mark_set_regs (rtx reg
, const_rtx setter ATTRIBUTE_UNUSED
, void *data
)
968 int regno
, endregno
, i
;
969 HARD_REG_SET
*this_insn_sets
= (HARD_REG_SET
*) data
;
971 if (GET_CODE (reg
) == SUBREG
)
973 rtx inner
= SUBREG_REG (reg
);
974 if (!REG_P (inner
) || REGNO (inner
) >= FIRST_PSEUDO_REGISTER
)
976 regno
= subreg_regno (reg
);
977 endregno
= regno
+ subreg_nregs (reg
);
980 && REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
983 endregno
= END_REGNO (reg
);
988 for (i
= regno
; i
< endregno
; i
++)
989 SET_HARD_REG_BIT (*this_insn_sets
, i
);
992 /* Here from note_stores when an insn stores a value in a register.
993 Set the proper bit or bits in the passed regset. All pseudos that have
994 been assigned hard regs have had their register number changed already,
995 so we can ignore pseudos. */
997 add_stored_regs (rtx reg
, const_rtx setter
, void *data
)
999 int regno
, endregno
, i
;
1000 machine_mode mode
= GET_MODE (reg
);
1003 if (GET_CODE (setter
) == CLOBBER
)
1006 if (GET_CODE (reg
) == SUBREG
1007 && REG_P (SUBREG_REG (reg
))
1008 && REGNO (SUBREG_REG (reg
)) < FIRST_PSEUDO_REGISTER
)
1010 offset
= subreg_regno_offset (REGNO (SUBREG_REG (reg
)),
1011 GET_MODE (SUBREG_REG (reg
)),
1014 regno
= REGNO (SUBREG_REG (reg
)) + offset
;
1015 endregno
= regno
+ subreg_nregs (reg
);
1019 if (!REG_P (reg
) || REGNO (reg
) >= FIRST_PSEUDO_REGISTER
)
1022 regno
= REGNO (reg
) + offset
;
1023 endregno
= end_hard_regno (mode
, regno
);
1026 for (i
= regno
; i
< endregno
; i
++)
1027 SET_REGNO_REG_SET ((regset
) data
, i
);
1030 /* Walk X and record all referenced registers in REFERENCED_REGS. */
1032 mark_referenced_regs (rtx
*loc
, refmarker_fn
*mark
, void *arg
)
1034 enum rtx_code code
= GET_CODE (*loc
);
1039 mark_referenced_regs (&SET_SRC (*loc
), mark
, arg
);
1040 if (code
== SET
|| code
== CLOBBER
)
1042 loc
= &SET_DEST (*loc
);
1043 code
= GET_CODE (*loc
);
1044 if ((code
== REG
&& REGNO (*loc
) < FIRST_PSEUDO_REGISTER
)
1045 || code
== PC
|| code
== CC0
1046 || (code
== SUBREG
&& REG_P (SUBREG_REG (*loc
))
1047 && REGNO (SUBREG_REG (*loc
)) < FIRST_PSEUDO_REGISTER
1048 /* If we're setting only part of a multi-word register,
1049 we shall mark it as referenced, because the words
1050 that are not being set should be restored. */
1051 && ((GET_MODE_SIZE (GET_MODE (*loc
))
1052 >= GET_MODE_SIZE (GET_MODE (SUBREG_REG (*loc
))))
1053 || (GET_MODE_SIZE (GET_MODE (SUBREG_REG (*loc
)))
1054 <= UNITS_PER_WORD
))))
1057 if (code
== MEM
|| code
== SUBREG
)
1059 loc
= &XEXP (*loc
, 0);
1060 code
= GET_CODE (*loc
);
1065 int regno
= REGNO (*loc
);
1066 int hardregno
= (regno
< FIRST_PSEUDO_REGISTER
? regno
1067 : reg_renumber
[regno
]);
1070 mark (loc
, GET_MODE (*loc
), hardregno
, arg
);
1072 /* ??? Will we ever end up with an equiv expression in a debug
1073 insn, that would have required restoring a reg, or will
1074 reload take care of it for us? */
1076 /* If this is a pseudo that did not get a hard register, scan its
1077 memory location, since it might involve the use of another
1078 register, which might be saved. */
1079 else if (reg_equiv_mem (regno
) != 0)
1080 mark_referenced_regs (&XEXP (reg_equiv_mem (regno
), 0), mark
, arg
);
1081 else if (reg_equiv_address (regno
) != 0)
1082 mark_referenced_regs (®_equiv_address (regno
), mark
, arg
);
1086 fmt
= GET_RTX_FORMAT (code
);
1087 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1090 mark_referenced_regs (&XEXP (*loc
, i
), mark
, arg
);
1091 else if (fmt
[i
] == 'E')
1092 for (j
= XVECLEN (*loc
, i
) - 1; j
>= 0; j
--)
1093 mark_referenced_regs (&XVECEXP (*loc
, i
, j
), mark
, arg
);
1097 /* Parameter function for mark_referenced_regs() that adds registers
1098 present in the insn and in equivalent mems and addresses to
1102 mark_reg_as_referenced (rtx
*loc ATTRIBUTE_UNUSED
,
1105 void *arg ATTRIBUTE_UNUSED
)
1107 add_to_hard_reg_set (&referenced_regs
, mode
, hardregno
);
1110 /* Parameter function for mark_referenced_regs() that replaces
1111 registers referenced in a debug_insn that would have been restored,
1112 should it be a non-debug_insn, with their save locations. */
1115 replace_reg_with_saved_mem (rtx
*loc
,
1120 unsigned int i
, nregs
= hard_regno_nregs
[regno
][mode
];
1122 machine_mode
*save_mode
= (machine_mode
*)arg
;
1124 for (i
= 0; i
< nregs
; i
++)
1125 if (TEST_HARD_REG_BIT (hard_regs_saved
, regno
+ i
))
1128 /* If none of the registers in the range would need restoring, we're
1134 if (!TEST_HARD_REG_BIT (hard_regs_saved
, regno
+ i
))
1138 && regno_save_mem
[regno
][nregs
])
1140 mem
= copy_rtx (regno_save_mem
[regno
][nregs
]);
1142 if (nregs
== (unsigned int) hard_regno_nregs
[regno
][save_mode
[regno
]])
1143 mem
= adjust_address_nv (mem
, save_mode
[regno
], 0);
1145 if (GET_MODE (mem
) != mode
)
1147 /* This is gen_lowpart_if_possible(), but without validating
1148 the newly-formed address. */
1151 if (WORDS_BIG_ENDIAN
)
1152 offset
= (MAX (GET_MODE_SIZE (GET_MODE (mem
)), UNITS_PER_WORD
)
1153 - MAX (GET_MODE_SIZE (mode
), UNITS_PER_WORD
));
1154 if (BYTES_BIG_ENDIAN
)
1155 /* Adjust the address so that the address-after-the-data is
1157 offset
-= (MIN (UNITS_PER_WORD
, GET_MODE_SIZE (mode
))
1158 - MIN (UNITS_PER_WORD
, GET_MODE_SIZE (GET_MODE (mem
))));
1160 mem
= adjust_address_nv (mem
, mode
, offset
);
1165 mem
= gen_rtx_CONCATN (mode
, rtvec_alloc (nregs
));
1166 for (i
= 0; i
< nregs
; i
++)
1167 if (TEST_HARD_REG_BIT (hard_regs_saved
, regno
+ i
))
1169 gcc_assert (regno_save_mem
[regno
+ i
][1]);
1170 XVECEXP (mem
, 0, i
) = copy_rtx (regno_save_mem
[regno
+ i
][1]);
1174 machine_mode smode
= save_mode
[regno
];
1175 gcc_assert (smode
!= VOIDmode
);
1176 if (hard_regno_nregs
[regno
][smode
] > 1)
1177 smode
= mode_for_size (GET_MODE_SIZE (mode
) / nregs
,
1178 GET_MODE_CLASS (mode
), 0);
1179 XVECEXP (mem
, 0, i
) = gen_rtx_REG (smode
, regno
+ i
);
1183 gcc_assert (GET_MODE (mem
) == mode
);
1188 /* Insert a sequence of insns to restore. Place these insns in front of
1189 CHAIN if BEFORE_P is nonzero, behind the insn otherwise. MAXRESTORE is
1190 the maximum number of registers which should be restored during this call.
1191 It should never be less than 1 since we only work with entire registers.
1193 Note that we have verified in init_caller_save that we can do this
1194 with a simple SET, so use it. Set INSN_CODE to what we save there
1195 since the address might not be valid so the insn might not be recognized.
1196 These insns will be reloaded and have register elimination done by
1197 find_reload, so we need not worry about that here.
1199 Return the extra number of registers saved. */
1202 insert_restore (struct insn_chain
*chain
, int before_p
, int regno
,
1203 int maxrestore
, machine_mode
*save_mode
)
1208 unsigned int numregs
= 0;
1209 struct insn_chain
*new_chain
;
1212 /* A common failure mode if register status is not correct in the
1213 RTL is for this routine to be called with a REGNO we didn't
1214 expect to save. That will cause us to write an insn with a (nil)
1215 SET_DEST or SET_SRC. Instead of doing so and causing a crash
1216 later, check for this common case here instead. This will remove
1217 one step in debugging such problems. */
1218 gcc_assert (regno_save_mem
[regno
][1]);
1220 /* Get the pattern to emit and update our status.
1222 See if we can restore `maxrestore' registers at once. Work
1223 backwards to the single register case. */
1224 for (i
= maxrestore
; i
> 0; i
--)
1229 if (regno_save_mem
[regno
][i
] == 0)
1232 for (j
= 0; j
< i
; j
++)
1233 if (! TEST_HARD_REG_BIT (hard_regs_saved
, regno
+ j
))
1238 /* Must do this one restore at a time. */
1246 mem
= regno_save_mem
[regno
][numregs
];
1247 if (save_mode
[regno
] != VOIDmode
1248 && save_mode
[regno
] != GET_MODE (mem
)
1249 && numregs
== (unsigned int) hard_regno_nregs
[regno
][save_mode
[regno
]]
1250 /* Check that insn to restore REGNO in save_mode[regno] is
1252 && reg_save_code (regno
, save_mode
[regno
]) >= 0)
1253 mem
= adjust_address_nv (mem
, save_mode
[regno
], 0);
1255 mem
= copy_rtx (mem
);
1257 /* Verify that the alignment of spill space is equal to or greater
1259 gcc_assert (MIN (MAX_SUPPORTED_STACK_ALIGNMENT
,
1260 GET_MODE_ALIGNMENT (GET_MODE (mem
))) <= MEM_ALIGN (mem
));
1262 pat
= gen_rtx_SET (gen_rtx_REG (GET_MODE (mem
), regno
), mem
);
1263 code
= reg_restore_code (regno
, GET_MODE (mem
));
1264 new_chain
= insert_one_insn (chain
, before_p
, code
, pat
);
1266 /* Clear status for all registers we restored. */
1267 for (k
= 0; k
< i
; k
++)
1269 CLEAR_HARD_REG_BIT (hard_regs_saved
, regno
+ k
);
1270 SET_REGNO_REG_SET (&new_chain
->dead_or_set
, regno
+ k
);
1274 /* Tell our callers how many extra registers we saved/restored. */
1278 /* Like insert_restore above, but save registers instead. */
1281 insert_save (struct insn_chain
*chain
, int before_p
, int regno
,
1282 HARD_REG_SET (*to_save
), machine_mode
*save_mode
)
1288 unsigned int numregs
= 0;
1289 struct insn_chain
*new_chain
;
1292 /* A common failure mode if register status is not correct in the
1293 RTL is for this routine to be called with a REGNO we didn't
1294 expect to save. That will cause us to write an insn with a (nil)
1295 SET_DEST or SET_SRC. Instead of doing so and causing a crash
1296 later, check for this common case here. This will remove one
1297 step in debugging such problems. */
1298 gcc_assert (regno_save_mem
[regno
][1]);
1300 /* Get the pattern to emit and update our status.
1302 See if we can save several registers with a single instruction.
1303 Work backwards to the single register case. */
1304 for (i
= MOVE_MAX_WORDS
; i
> 0; i
--)
1308 if (regno_save_mem
[regno
][i
] == 0)
1311 for (j
= 0; j
< i
; j
++)
1312 if (! TEST_HARD_REG_BIT (*to_save
, regno
+ j
))
1317 /* Must do this one save at a time. */
1325 mem
= regno_save_mem
[regno
][numregs
];
1326 if (save_mode
[regno
] != VOIDmode
1327 && save_mode
[regno
] != GET_MODE (mem
)
1328 && numregs
== (unsigned int) hard_regno_nregs
[regno
][save_mode
[regno
]]
1329 /* Check that insn to save REGNO in save_mode[regno] is
1331 && reg_save_code (regno
, save_mode
[regno
]) >= 0)
1332 mem
= adjust_address_nv (mem
, save_mode
[regno
], 0);
1334 mem
= copy_rtx (mem
);
1336 /* Verify that the alignment of spill space is equal to or greater
1338 gcc_assert (MIN (MAX_SUPPORTED_STACK_ALIGNMENT
,
1339 GET_MODE_ALIGNMENT (GET_MODE (mem
))) <= MEM_ALIGN (mem
));
1341 pat
= gen_rtx_SET (mem
, gen_rtx_REG (GET_MODE (mem
), regno
));
1342 code
= reg_save_code (regno
, GET_MODE (mem
));
1343 new_chain
= insert_one_insn (chain
, before_p
, code
, pat
);
1345 /* Set hard_regs_saved and dead_or_set for all the registers we saved. */
1346 for (k
= 0; k
< numregs
; k
++)
1348 SET_HARD_REG_BIT (hard_regs_saved
, regno
+ k
);
1349 SET_REGNO_REG_SET (&new_chain
->dead_or_set
, regno
+ k
);
1353 /* Tell our callers how many extra registers we saved/restored. */
1357 /* A note_uses callback used by insert_one_insn. Add the hard-register
1358 equivalent of each REG to regset DATA. */
1361 add_used_regs (rtx
*loc
, void *data
)
1363 subrtx_iterator::array_type array
;
1364 FOR_EACH_SUBRTX (iter
, array
, *loc
, NONCONST
)
1366 const_rtx x
= *iter
;
1369 unsigned int regno
= REGNO (x
);
1370 if (HARD_REGISTER_NUM_P (regno
))
1371 bitmap_set_range ((regset
) data
, regno
,
1372 hard_regno_nregs
[regno
][GET_MODE (x
)]);
1374 gcc_checking_assert (reg_renumber
[regno
] < 0);
1379 /* Emit a new caller-save insn and set the code. */
1380 static struct insn_chain
*
1381 insert_one_insn (struct insn_chain
*chain
, int before_p
, int code
, rtx pat
)
1383 rtx_insn
*insn
= chain
->insn
;
1384 struct insn_chain
*new_chain
;
1386 /* If INSN references CC0, put our insns in front of the insn that sets
1387 CC0. This is always safe, since the only way we could be passed an
1388 insn that references CC0 is for a restore, and doing a restore earlier
1389 isn't a problem. We do, however, assume here that CALL_INSNs don't
1390 reference CC0. Guard against non-INSN's like CODE_LABEL. */
1392 if (HAVE_cc0
&& (NONJUMP_INSN_P (insn
) || JUMP_P (insn
))
1394 && reg_referenced_p (cc0_rtx
, PATTERN (insn
)))
1395 chain
= chain
->prev
, insn
= chain
->insn
;
1397 new_chain
= new_insn_chain ();
1402 new_chain
->prev
= chain
->prev
;
1403 if (new_chain
->prev
!= 0)
1404 new_chain
->prev
->next
= new_chain
;
1406 reload_insn_chain
= new_chain
;
1408 chain
->prev
= new_chain
;
1409 new_chain
->next
= chain
;
1410 new_chain
->insn
= emit_insn_before (pat
, insn
);
1411 /* ??? It would be nice if we could exclude the already / still saved
1412 registers from the live sets. */
1413 COPY_REG_SET (&new_chain
->live_throughout
, &chain
->live_throughout
);
1414 note_uses (&PATTERN (chain
->insn
), add_used_regs
,
1415 &new_chain
->live_throughout
);
1416 /* If CHAIN->INSN is a call, then the registers which contain
1417 the arguments to the function are live in the new insn. */
1418 if (CALL_P (chain
->insn
))
1419 for (link
= CALL_INSN_FUNCTION_USAGE (chain
->insn
);
1421 link
= XEXP (link
, 1))
1422 note_uses (&XEXP (link
, 0), add_used_regs
,
1423 &new_chain
->live_throughout
);
1425 CLEAR_REG_SET (&new_chain
->dead_or_set
);
1426 if (chain
->insn
== BB_HEAD (BASIC_BLOCK_FOR_FN (cfun
, chain
->block
)))
1427 BB_HEAD (BASIC_BLOCK_FOR_FN (cfun
, chain
->block
)) = new_chain
->insn
;
1431 new_chain
->next
= chain
->next
;
1432 if (new_chain
->next
!= 0)
1433 new_chain
->next
->prev
= new_chain
;
1434 chain
->next
= new_chain
;
1435 new_chain
->prev
= chain
;
1436 new_chain
->insn
= emit_insn_after (pat
, insn
);
1437 /* ??? It would be nice if we could exclude the already / still saved
1438 registers from the live sets, and observe REG_UNUSED notes. */
1439 COPY_REG_SET (&new_chain
->live_throughout
, &chain
->live_throughout
);
1440 /* Registers that are set in CHAIN->INSN live in the new insn.
1441 (Unless there is a REG_UNUSED note for them, but we don't
1442 look for them here.) */
1443 note_stores (PATTERN (chain
->insn
), add_stored_regs
,
1444 &new_chain
->live_throughout
);
1445 CLEAR_REG_SET (&new_chain
->dead_or_set
);
1446 if (chain
->insn
== BB_END (BASIC_BLOCK_FOR_FN (cfun
, chain
->block
)))
1447 BB_END (BASIC_BLOCK_FOR_FN (cfun
, chain
->block
)) = new_chain
->insn
;
1449 new_chain
->block
= chain
->block
;
1450 new_chain
->is_caller_save_insn
= 1;
1452 INSN_CODE (new_chain
->insn
) = code
;
1455 #include "gt-caller-save.h"