+static void
+add_used_regs (rtx *loc, void *data)
+{
+ for_each_rtx (loc, add_used_regs_1, data);
+}
+
+/* Emit a new caller-save insn and set the code. */
+static struct insn_chain *
+insert_one_insn (struct insn_chain *chain, int before_p, int code, rtx pat)
+{
+ rtx insn = chain->insn;
+ struct insn_chain *new_chain;
+
+#ifdef HAVE_cc0
+ /* If INSN references CC0, put our insns in front of the insn that sets
+ CC0. This is always safe, since the only way we could be passed an
+ insn that references CC0 is for a restore, and doing a restore earlier
+ isn't a problem. We do, however, assume here that CALL_INSNs don't
+ reference CC0. Guard against non-INSN's like CODE_LABEL. */
+
+ if ((NONJUMP_INSN_P (insn) || JUMP_P (insn))
+ && before_p
+ && reg_referenced_p (cc0_rtx, PATTERN (insn)))
+ chain = chain->prev, insn = chain->insn;
+#endif
+
+ new_chain = new_insn_chain ();
+ if (before_p)
+ {
+ rtx link;
+
+ new_chain->prev = chain->prev;
+ if (new_chain->prev != 0)
+ new_chain->prev->next = new_chain;
+ else
+ reload_insn_chain = new_chain;
+
+ chain->prev = new_chain;
+ new_chain->next = chain;
+ new_chain->insn = emit_insn_before (pat, insn);
+ /* ??? It would be nice if we could exclude the already / still saved
+ registers from the live sets. */
+ COPY_REG_SET (&new_chain->live_throughout, &chain->live_throughout);
+ note_uses (&PATTERN (chain->insn), add_used_regs,
+ &new_chain->live_throughout);
+ /* If CHAIN->INSN is a call, then the registers which contain
+ the arguments to the function are live in the new insn. */
+ if (CALL_P (chain->insn))
+ for (link = CALL_INSN_FUNCTION_USAGE (chain->insn);
+ link != NULL_RTX;
+ link = XEXP (link, 1))
+ note_uses (&XEXP (link, 0), add_used_regs,
+ &new_chain->live_throughout);
+
+ CLEAR_REG_SET (&new_chain->dead_or_set);
+ if (chain->insn == BB_HEAD (BASIC_BLOCK (chain->block)))
+ BB_HEAD (BASIC_BLOCK (chain->block)) = new_chain->insn;
+ }
+ else
+ {
+ new_chain->next = chain->next;
+ if (new_chain->next != 0)
+ new_chain->next->prev = new_chain;
+ chain->next = new_chain;
+ new_chain->prev = chain;
+ new_chain->insn = emit_insn_after (pat, insn);
+ /* ??? It would be nice if we could exclude the already / still saved
+ registers from the live sets, and observe REG_UNUSED notes. */
+ COPY_REG_SET (&new_chain->live_throughout, &chain->live_throughout);
+ /* Registers that are set in CHAIN->INSN live in the new insn.
+ (Unless there is a REG_UNUSED note for them, but we don't
+ look for them here.) */
+ note_stores (PATTERN (chain->insn), add_stored_regs,
+ &new_chain->live_throughout);
+ CLEAR_REG_SET (&new_chain->dead_or_set);
+ if (chain->insn == BB_END (BASIC_BLOCK (chain->block)))
+ BB_END (BASIC_BLOCK (chain->block)) = new_chain->insn;
+ }
+ new_chain->block = chain->block;
+ new_chain->is_caller_save_insn = 1;
+
+ INSN_CODE (new_chain->insn) = code;
+ return new_chain;