new file mode 100644
@@ -0,0 +1,38 @@
+/* { dg-do run } */
+/* { dg-options "-fuse-caller-save -save-temps" } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-Os" } } */
+/* Testing -fuse-caller-save optimization option. */
+
+static int __attribute__((noinline))
+bar (int x)
+{
+ return x + 3;
+}
+
+int __attribute__((noinline))
+foo (int y)
+{
+ return y + bar (y);
+}
+
+int
+main (void)
+{
+ return !(foo (5) == 13);
+}
+
+/* Check that there are only 2 stack-saves: r31 in main and foo. */
+
+/* Variant not mips16. Check that there only 2 sw/sd. */
+/* { dg-final { scan-assembler-times "(?n)s\[wd\]\t\\\$.*,.*\\(\\\$sp\\)" 2 { target { ! mips16 } } } } */
+
+/* Variant not mips16, Subvariant micromips. Additionally check there's no
+ swm. */
+/* { dg-final { scan-assembler-times "(?n)swm\t\\\$.*,.*\\(\\\$sp\\)" 0 {target micromips } } } */
+
+/* Variant mips16. The save can save 1 or more registers, check that only 1 is
+ saved, twice in total. */
+/* { dg-final { scan-assembler-times "(?n)save\t\[0-9\]*,\\\$\[^,\]*\$" 2 { target mips16 } } } */
+
+/* Check that the first caller-save register is unused. */
+/* { dg-final { scan-assembler-not "(\\\$16)" } } */
@@ -246,6 +246,7 @@ set mips_option_groups {
small-data "-G[0-9]+"
warnings "-w"
dump "-fdump-.*"
+ save_temps "-save-temps"
}
# Add -mfoo/-mno-foo options to mips_option_groups.
@@ -302,6 +303,7 @@ foreach option {
tree-vectorize
unroll-all-loops
unroll-loops
+ use-caller-save
} {
lappend mips_option_groups $option "-f(no-|)$option"
}
@@ -918,6 +918,26 @@ proc check_effective_target_mips16_attribute { } {
} [add_options_for_mips16_attribute ""]]
}
+# Return 1 if the target generates mips16 code by default.
+
+proc check_effective_target_mips16 { } {
+ return [check_no_compiler_messages mips16 assembly {
+ #if !(defined __mips16)
+ #error FOO
+ #endif
+ } ""]
+}
+
+# Return 1 if the target generates micromips code by default.
+
+proc check_effective_target_micromips { } {
+ return [check_no_compiler_messages micromips assembly {
+ #if !(defined __mips_micromips)
+ #error FOO
+ #endif
+ } ""]
+}
+
# Return 1 if the target supports long double larger than double when
# using the new ABI, 0 otherwise.