]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Nios2: Add TARGET_CAN_INLINE_P hook.
authorSandra Loosemore <sandra@codesourcery.com>
Tue, 9 Nov 2021 03:10:58 +0000 (19:10 -0800)
committerSandra Loosemore <sandra@codesourcery.com>
Wed, 10 Nov 2021 02:00:54 +0000 (18:00 -0800)
2021-11-09  Sandra Loosemore  <sandra@codesourcery.com>

gcc/
* config/nios2/nios2.c (nios2_can_inline_p): New.
(TARGET_CAN_INLINE_P): Define.

gcc/testsuite/
* gcc.target/nios2/custom-fp-inline-1.c: New.
* gcc.target/nios2/custom-fp-inline-2.c: New.
* gcc.target/nios2/custom-fp-inline-3.c: New.
* gcc.target/nios2/custom-fp-inline-4.c: New.

gcc/config/nios2/nios2.c
gcc/testsuite/gcc.target/nios2/custom-fp-inline-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/nios2/custom-fp-inline-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/nios2/custom-fp-inline-3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/nios2/custom-fp-inline-4.c [new file with mode: 0644]

index 7a613e4c13e5444fc4bc2d5883835aa9723e48c3..f77f7e6e07d3b92ae624cfd2ed6669fc8b8524a5 100644 (file)
@@ -4162,6 +4162,40 @@ nios2_option_restore (struct gcc_options *opts ATTRIBUTE_UNUSED,
          sizeof (custom_code_index));
 }
 
+static bool
+nios2_can_inline_p (tree caller, tree callee)
+{
+  tree callee_opts = DECL_FUNCTION_SPECIFIC_TARGET (callee);
+  tree caller_opts = DECL_FUNCTION_SPECIFIC_TARGET (caller);
+  struct cl_target_option *callee_ptr, *caller_ptr;
+  unsigned int i;
+
+  if (! callee_opts)
+    callee_opts = target_option_default_node;
+  if (! caller_opts)
+    caller_opts = target_option_default_node;
+
+  /* If both caller and callee have attributes, assume that if the
+     pointer is different, the two functions have different target
+     options since build_target_option_node uses a hash table for the
+     options.  */
+  if (callee_opts == caller_opts)
+    return true;
+
+  /* The only target options we recognize via function attributes are
+     those related to custom instructions.  If we failed the above test,
+     check that any custom instructions enabled in the callee are also
+     enabled with the same value in the caller.  */
+  callee_ptr = TREE_TARGET_OPTION (callee_opts);
+  caller_ptr = TREE_TARGET_OPTION (caller_opts);
+  for (i = 0; i < ARRAY_SIZE (nios2_fpu_insn); i++)
+    if (callee_ptr->saved_fpu_custom_code[i] != -1
+       && (callee_ptr->saved_fpu_custom_code[i]
+           != caller_ptr->saved_fpu_custom_code[i]))
+      return false;
+  return true;
+}
+
 /* Inner function to process the attribute((target(...))), take an argument and
    set the current options from the argument.  If we have a list, recursively
    go over the list.  */
@@ -5554,6 +5588,9 @@ nios2_adjust_reg_alloc_order (void)
 #undef TARGET_OPTION_RESTORE
 #define TARGET_OPTION_RESTORE nios2_option_restore
 
+#undef TARGET_CAN_INLINE_P
+#define TARGET_CAN_INLINE_P nios2_can_inline_p
+
 #undef TARGET_SET_CURRENT_FUNCTION
 #define TARGET_SET_CURRENT_FUNCTION nios2_set_current_function
 
diff --git a/gcc/testsuite/gcc.target/nios2/custom-fp-inline-1.c b/gcc/testsuite/gcc.target/nios2/custom-fp-inline-1.c
new file mode 100644 (file)
index 0000000..43715e5
--- /dev/null
@@ -0,0 +1,33 @@
+/* Test that you can inline a function with custom insn attributes into
+   one with the same attributes.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O1 -ffinite-math-only" } */
+
+/* -O1 in the options is significant.  Without it FP operations may not be
+   optimized to custom instructions.  */
+
+#include <math.h>
+
+static inline
+__attribute__ ((always_inline, target ("custom-fmaxs=246,custom-fmins=247")))
+void
+custom_fp1 (float operand_a, float operand_b, float *result)
+
+{
+  result[0] = fmaxf (operand_a, operand_b);
+  result[1] = fminf (operand_a, operand_b);
+}
+
+extern void
+custom_fp (float operand_a, float operand_b, float *result)
+  __attribute__ ((target ("custom-fmaxs=246,custom-fmins=247")));
+
+void
+custom_fp (float operand_a, float operand_b, float *result)
+{
+  custom_fp1 (operand_a, operand_b, result);
+}
+
+/* { dg-final { scan-assembler "custom\\t246, .* # fmaxs .*" } } */
+/* { dg-final { scan-assembler "custom\\t247, .* # fmins .*" } } */
diff --git a/gcc/testsuite/gcc.target/nios2/custom-fp-inline-2.c b/gcc/testsuite/gcc.target/nios2/custom-fp-inline-2.c
new file mode 100644 (file)
index 0000000..3e35241
--- /dev/null
@@ -0,0 +1,29 @@
+/* Test that you cannot inline a function with custom insn attributes into
+   one without attributes.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O1 -ffinite-math-only" } */
+
+/* -O1 in the options is significant.  Without it FP operations may not be
+   optimized to custom instructions.  */
+
+#include <math.h>
+
+static inline
+__attribute__ ((always_inline, target ("custom-fmaxs=246,custom-fmins=247")))
+void
+custom_fp1 (float operand_a, float operand_b, float *result)  /* { dg-error "target specific option mismatch" } */
+{
+  result[0] = fmaxf (operand_a, operand_b);
+  result[1] = fminf (operand_a, operand_b);
+}
+
+extern void
+custom_fp (float operand_a, float operand_b, float *result);
+
+void
+custom_fp (float operand_a, float operand_b, float *result)
+{
+  custom_fp1 (operand_a, operand_b, result);
+}
+
diff --git a/gcc/testsuite/gcc.target/nios2/custom-fp-inline-3.c b/gcc/testsuite/gcc.target/nios2/custom-fp-inline-3.c
new file mode 100644 (file)
index 0000000..86b1064
--- /dev/null
@@ -0,0 +1,33 @@
+/* Test that you can inline a function without custom insn attributes into
+   one that does have custom insn attributes.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O1 -ffinite-math-only" } */
+
+/* -O1 in the options is significant.  Without it FP operations may not be
+   optimized to custom instructions.  */
+
+#include <math.h>
+
+static inline 
+__attribute__ ((always_inline))
+void
+custom_fp1 (float operand_a, float operand_b, float *result)
+
+{
+  result[0] = fmaxf (operand_a, operand_b);
+  result[1] = fminf (operand_a, operand_b);
+}
+
+extern void
+custom_fp (float operand_a, float operand_b, float *result)
+  __attribute__ ((target ("custom-fmaxs=246,custom-fmins=247")));
+
+void
+custom_fp (float operand_a, float operand_b, float *result)
+{
+  custom_fp1 (operand_a, operand_b, result);
+}
+
+/* { dg-final { scan-assembler "custom\\t246, .* # fmaxs .*" } } */
+/* { dg-final { scan-assembler "custom\\t247, .* # fmins .*" } } */
diff --git a/gcc/testsuite/gcc.target/nios2/custom-fp-inline-4.c b/gcc/testsuite/gcc.target/nios2/custom-fp-inline-4.c
new file mode 100644 (file)
index 0000000..5e2c1bc
--- /dev/null
@@ -0,0 +1,29 @@
+/* Test that you cannot inline a function with custom insn attributes into
+   one with incompatible attributes.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O1 -ffinite-math-only" } */
+
+/* -O1 in the options is significant.  Without it FP operations may not be
+   optimized to custom instructions.  */
+
+#include <math.h>
+
+static inline
+__attribute__ ((always_inline, target ("custom-fmaxs=246,custom-fmins=247")))
+void
+custom_fp1 (float operand_a, float operand_b, float *result)  /* { dg-error "target specific option mismatch" } */
+{
+  result[0] = fmaxf (operand_a, operand_b);
+  result[1] = fminf (operand_a, operand_b);
+}
+
+extern void
+custom_fp (float operand_a, float operand_b, float *result)
+  __attribute__ ((target ("custom-fmaxs=200,custom-fmins=201")));
+
+void
+custom_fp (float operand_a, float operand_b, float *result)
+{
+  custom_fp1 (operand_a, operand_b, result);
+}