@@ -630,6 +630,7 @@ static const struct attribute_spec mips_attribute_table[] = {
mips_handle_use_shadow_register_set_attr, NULL },
{ "keep_interrupts_masked", 0, 0, false, true, true, false, NULL, NULL },
{ "use_debug_exception_return", 0, 0, false, true, true, false, NULL, NULL },
+ { "use_hazard_barrier_return", 0, 0, true, false, false, false, NULL, NULL },
{ NULL, 0, 0, false, false, false, false, NULL, NULL }
};
@@ -3386,6 +3386,9 @@ struct GTY(()) machine_function {
/* True if GCC stored callee saved registers in the frame header. */
bool use_frame_header_for_callee_saved_regs;
+
+ /* True if the function should generate hazard barrier return. */
+ bool use_hazard_barrier_return_p;
};
#endif
@@ -159,6 +159,7 @@
;; The `.insn' pseudo-op.
UNSPEC_INSN_PSEUDO
+ UNSPEC_JRHB
])
(define_constants
@@ -6679,6 +6680,20 @@
[(set_attr "type" "jump")
(set_attr "mode" "none")])
+;; Insn to clear execution and instruction hazards while returning.
+;; However, it doesn't clear hazards created by the insn in its delay slot.
+;; Thus, explicitly place a nop in its delay slot.
+
+(define_insn "mips_hb_return_internal"
+ [(return)
+ (unspec_volatile [(match_operand 0 "pmode_register_operand" "")]
+ UNSPEC_JRHB)]
+ ""
+ {
+ return "%(jr.hb\t$31%/%)";
+ }
+ [(set_attr "insn_count" "2")])
+
;; Normal return.
(define_insn "<optab>_internal"
@@ -5653,6 +5653,12 @@ On MIPS targets, you can use the @code{nocompression} function attribute
to locally turn off MIPS16 and microMIPS code generation. This attribute
overrides the @option{-mips16} and @option{-mmicromips} options on the
command line (@pxref{MIPS Options}).
+
+@item use_hazard_barrier_return
+@cindex @code{use_hazard_barrier_return} function attribute, MIPS
+This function attribute instructs the compiler to generate a hazard barrier
+return that clears all execution and instruction hazards while returning,
+instead of generating a normal return instruction.
@end table
@node MSP430 Function Attributes
new file mode 100644
@@ -0,0 +1,20 @@
+/* Test attribute for clearing hazards while returning. */
+/* { dg-do compile } */
+/* { dg-options "isa_rev>=2 -mno-mips16" } */
+
+extern int bar ();
+
+static int __attribute__ ((use_hazard_barrier_return))
+foo0 ()
+{
+ return bar ();
+}
+
+int
+foo1 ()
+{
+ return foo0 ();
+}
+
+/* { dg-final { scan-assembler "foo0:" } } */
+/* { dg-final { scan-assembler-times "\tjr.hb\t\\\$31\n\tnop\\n" 1 } } */