2014-02-07 Richard Sandiford <rsandifo@linux.vnet.ibm.com>
+ * config/s390/s390-protos.h (s390_can_use_simple_return_insn)
+ (s390_can_use_return_insn): Declare.
+ * config/s390/s390.h (EPILOGUE_USES): Define.
+ * config/s390/s390.c (s390_mainpool_start): Allow two main_pool
+ instructions.
+ (s390_chunkify_start): Handle return JUMP_LABELs.
+ (s390_early_mach): Emit a main_pool instruction on the entry edge.
+ (s300_set_up_by_prologue, s390_can_use_simple_return_insn)
+ (s390_can_use_return_insn): New functions.
+ (s390_fix_long_loop_prediction): Handle conditional returns.
+ (TARGET_SET_UP_BY_PROLOGUE): Define.
+ * config/s390/s390.md (ANY_RETURN): New code iterator.
+ (*creturn, *csimple_return, return, simple_return): New patterns.
+
+2014-02-07 Richard Sandiford <rsandifo@linux.vnet.ibm.com>
+
* config/s390/s390.c (s390_restore_gprs_from_fprs): Add REG_CFA_RESTORE
notes to each restore. Also add REG_CFA_DEF_CFA when restoring %r15.
(s390_optimize_prologue): Don't clear RTX_FRAME_RELATED_P. Update the
&& GET_CODE (SET_SRC (PATTERN (insn))) == UNSPEC_VOLATILE
&& XINT (SET_SRC (PATTERN (insn)), 1) == UNSPECV_MAIN_POOL)
{
- gcc_assert (!pool->pool_insn);
+ /* There might be two main_pool instructions if base_reg
+ is call-clobbered; one for shrink-wrapped code and one
+ for the rest. We want to keep the first. */
+ if (pool->pool_insn)
+ {
+ insn = PREV_INSN (insn);
+ delete_insn (NEXT_INSN (insn));
+ continue;
+ }
pool->pool_insn = insn;
}
if (GET_CODE (pat) == SET)
{
rtx label = JUMP_LABEL (insn);
- if (label)
+ if (label && !ANY_RETURN_P (label))
{
if (s390_find_pool (pool_list, label)
!= s390_find_pool (pool_list, insn))
/* Re-compute register info. */
s390_register_info ();
+ /* If we're using a base register, ensure that it is always valid for
+ the first non-prologue instruction. */
+ if (cfun->machine->base_reg)
+ emit_insn_at_entry (gen_main_pool (cfun->machine->base_reg));
+
/* Annotate all constant pool references to let the scheduler know
they implicitly use the base register. */
for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
}
}
+/* Implement TARGET_SET_UP_BY_PROLOGUE. */
+
+static void
+s300_set_up_by_prologue (hard_reg_set_container *regs)
+{
+ if (cfun->machine->base_reg
+ && !call_really_used_regs[REGNO (cfun->machine->base_reg)])
+ SET_HARD_REG_BIT (regs->set, REGNO (cfun->machine->base_reg));
+}
+
+/* Return true if the function can use simple_return to return outside
+ of a shrink-wrapped region. At present shrink-wrapping is supported
+ in all cases. */
+
+bool
+s390_can_use_simple_return_insn (void)
+{
+ return true;
+}
+
+/* Return true if the epilogue is guaranteed to contain only a return
+ instruction and if a direct return can therefore be used instead.
+ One of the main advantages of using direct return instructions
+ is that we can then use conditional returns. */
+
+bool
+s390_can_use_return_insn (void)
+{
+ int i;
+
+ if (!reload_completed)
+ return false;
+
+ if (crtl->profile)
+ return false;
+
+ if (TARGET_TPF_PROFILING)
+ return false;
+
+ for (i = 0; i < 16; i++)
+ if (cfun_gpr_save_slot (i))
+ return false;
+
+ if (cfun->machine->base_reg
+ && !call_really_used_regs[REGNO (cfun->machine->base_reg)])
+ return false;
+
+ return cfun_frame_layout.frame_size == 0;
+}
/* Return the size in bytes of a function argument of
type TYPE and/or mode MODE. At least one of TYPE or
|| GET_CODE (SET_SRC(set)) != IF_THEN_ELSE)
return false;
+ /* Skip conditional returns. */
+ if (ANY_RETURN_P (XEXP (SET_SRC (set), 1))
+ && XEXP (SET_SRC (set), 2) == pc_rtx)
+ return false;
+
label_ref = (GET_CODE (XEXP (SET_SRC (set), 1)) == LABEL_REF ?
XEXP (SET_SRC (set), 1) : XEXP (SET_SRC (set), 2));
#undef TARGET_CAN_INLINE_P
#define TARGET_CAN_INLINE_P s390_can_inline_p
+#undef TARGET_SET_UP_BY_PROLOGUE
+#define TARGET_SET_UP_BY_PROLOGUE s300_set_up_by_prologue
+
struct gcc_target targetm = TARGET_INITIALIZER;
#include "gt-s390.h"
;; In place of GET_MODE_BITSIZE (<MODE>mode)
(define_mode_attr bitsize [(DI "64") (SI "32") (HI "16") (QI "8")])
+;; Allow return and simple_return to be defined from a single template.
+(define_code_iterator ANY_RETURN [return simple_return])
+
;;
;;- Compare instructions.
;;
(set_attr "type" "branch")
(set_attr "atype" "agen")])
+;; A conditional return instruction.
+(define_insn "*c<code>"
+ [(set (pc)
+ (if_then_else
+ (match_operator 0 "s390_comparison" [(reg CC_REGNUM) (const_int 0)])
+ (ANY_RETURN)
+ (pc)))]
+ "s390_can_use_<code>_insn ()"
+ "b%C0r\t%%r14"
+ [(set_attr "op_type" "RR")
+ (set_attr "type" "jsr")
+ (set_attr "atype" "agen")])
;;
;;- Negated conditional jump instructions.
""
"s390_emit_epilogue (true); DONE;")
+;; A direct return instruction, without using an epilogue.
+(define_insn "<code>"
+ [(ANY_RETURN)]
+ "s390_can_use_<code>_insn ()"
+ "br\t%%r14"
+ [(set_attr "op_type" "RR")
+ (set_attr "type" "jsr")
+ (set_attr "atype" "agen")])
+
(define_insn "*return"
[(return)
(use (match_operand 0 "register_operand" "a"))]