diff mbox series

[15/16] aarch64: Enforce inlining restrictions for SME

Message ID mptv8njmarz.fsf@arm.com
State New
Headers show
Series aarch64: Add support for SME | expand

Commit Message

Richard Sandiford Nov. 13, 2022, 10:03 a.m. UTC
A function that has local ZA state cannot be inlined into its caller,
since we only support managing ZA switches at function scope.

A function whose body requires a particular PSTATE.SM setting can only
be inlined into a function body that guarantees that PSTATE.SM setting.
(The callee's function type doesn't matter here: one locally-streaming
function can be inlined into another.)

gcc/
	* config/aarch64/aarch64.cc (aarch64_function_attribute_inlinable_p):
	New function.
	(aarch64_can_inline_p): Use aarch64_fndecl_isa_mode to populate
	the ISA mode bits when comparing the ISA flags of the two functions.
	(TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P): Define.

gcc/testsuite/
	* gcc.target/aarch64/sme/inlining_1.c: New test.
	* gcc.target/aarch64/sme/inlining_2.c: Likewise.
	* gcc.target/aarch64/sme/inlining_3.c: Likewise.
	* gcc.target/aarch64/sme/inlining_4.c: Likewise.
	* gcc.target/aarch64/sme/inlining_5.c: Likewise.
	* gcc.target/aarch64/sme/inlining_6.c: Likewise.
	* gcc.target/aarch64/sme/inlining_7.c: Likewise.
	* gcc.target/aarch64/sme/inlining_8.c: Likewise.
---
 gcc/config/aarch64/aarch64.cc                 | 33 ++++++++++++++++---
 .../gcc.target/aarch64/sme/inlining_1.c       | 26 +++++++++++++++
 .../gcc.target/aarch64/sme/inlining_2.c       | 26 +++++++++++++++
 .../gcc.target/aarch64/sme/inlining_3.c       | 26 +++++++++++++++
 .../gcc.target/aarch64/sme/inlining_4.c       | 26 +++++++++++++++
 .../gcc.target/aarch64/sme/inlining_5.c       | 26 +++++++++++++++
 .../gcc.target/aarch64/sme/inlining_6.c       | 18 ++++++++++
 .../gcc.target/aarch64/sme/inlining_7.c       | 18 ++++++++++
 .../gcc.target/aarch64/sme/inlining_8.c       | 18 ++++++++++
 9 files changed, 212 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/aarch64/sme/inlining_1.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/sme/inlining_2.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/sme/inlining_3.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/sme/inlining_4.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/sme/inlining_5.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/sme/inlining_6.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/sme/inlining_7.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/sme/inlining_8.c
diff mbox series

Patch

diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index 48bf2de4b3d..9a4a469a078 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -20554,6 +20554,17 @@  aarch64_option_valid_attribute_p (tree fndecl, tree, tree args, int)
   return ret;
 }
 
+/* Implement TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P.  Use an opt-out
+   rather than an opt-in list.  */
+
+static bool
+aarch64_function_attribute_inlinable_p (const_tree fndecl)
+{
+  /* A function that has local ZA state cannot be inlined into its caller,
+     since we only support managing ZA switches at function scope.  */
+  return !aarch64_fndecl_has_new_za_state (fndecl);
+}
+
 /* Helper for aarch64_can_inline_p.  In the case where CALLER and CALLEE are
    tri-bool options (yes, no, don't care) and the default value is
    DEF, determine whether to reject inlining.  */
@@ -20597,12 +20608,20 @@  aarch64_can_inline_p (tree caller, tree callee)
 					   : target_option_default_node);
 
   /* Callee's ISA flags should be a subset of the caller's.  */
-  if ((caller_opts->x_aarch64_asm_isa_flags
-       & callee_opts->x_aarch64_asm_isa_flags)
-      != callee_opts->x_aarch64_asm_isa_flags)
+  auto caller_asm_isa = (caller_opts->x_aarch64_isa_flags
+			 & ~AARCH64_FL_ISA_MODES);
+  auto callee_asm_isa = (callee_opts->x_aarch64_isa_flags
+			 & ~AARCH64_FL_ISA_MODES);
+  if (callee_asm_isa & ~caller_asm_isa)
     return false;
-  if ((caller_opts->x_aarch64_isa_flags & callee_opts->x_aarch64_isa_flags)
-      != callee_opts->x_aarch64_isa_flags)
+
+  auto caller_isa = ((caller_opts->x_aarch64_isa_flags
+		      & ~AARCH64_FL_ISA_MODES)
+		     | aarch64_fndecl_isa_mode (caller));
+  auto callee_isa = ((callee_opts->x_aarch64_isa_flags
+		      & ~AARCH64_FL_ISA_MODES)
+		     | aarch64_fndecl_isa_mode (callee));
+  if (callee_isa & ~caller_isa)
     return false;
 
   /* Allow non-strict aligned functions inlining into strict
@@ -29150,6 +29169,10 @@  aarch64_run_selftests (void)
 #undef TARGET_CAN_ELIMINATE
 #define TARGET_CAN_ELIMINATE aarch64_can_eliminate
 
+#undef TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P
+#define TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P \
+  aarch64_function_attribute_inlinable_p
+
 #undef TARGET_CAN_INLINE_P
 #define TARGET_CAN_INLINE_P aarch64_can_inline_p
 
diff --git a/gcc/testsuite/gcc.target/aarch64/sme/inlining_1.c b/gcc/testsuite/gcc.target/aarch64/sme/inlining_1.c
new file mode 100644
index 00000000000..63d23cb8b41
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sme/inlining_1.c
@@ -0,0 +1,26 @@ 
+/* { dg-options "" } */
+
+inline void __attribute__((always_inline, arm_streaming_compatible))
+sc_callee () {}
+
+inline void __attribute__((always_inline, arm_streaming))
+s_callee () {} // { dg-error "inlining failed" }
+
+inline void __attribute__((always_inline))
+n_callee () {} // { dg-error "inlining failed" }
+
+inline void __attribute__((always_inline, arm_streaming_compatible, arm_locally_streaming))
+sc_ls_callee () {} // { dg-error "inlining failed" }
+
+inline void __attribute__((always_inline, arm_locally_streaming))
+n_ls_callee () {} // { dg-error "inlining failed" }
+
+void __attribute__((arm_streaming_compatible))
+sc_caller ()
+{
+  sc_callee ();
+  s_callee ();
+  n_callee ();
+  sc_ls_callee ();
+  n_ls_callee ();
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/sme/inlining_2.c b/gcc/testsuite/gcc.target/aarch64/sme/inlining_2.c
new file mode 100644
index 00000000000..277a5b691a2
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sme/inlining_2.c
@@ -0,0 +1,26 @@ 
+/* { dg-options "" } */
+
+inline void __attribute__((always_inline, arm_streaming_compatible))
+sc_callee () {}
+
+inline void __attribute__((always_inline, arm_streaming))
+s_callee () {}
+
+inline void __attribute__((always_inline))
+n_callee () {} // { dg-error "inlining failed" }
+
+inline void __attribute__((always_inline, arm_streaming_compatible, arm_locally_streaming))
+sc_ls_callee () {}
+
+inline void __attribute__((always_inline, arm_locally_streaming))
+n_ls_callee () {}
+
+void __attribute__((arm_streaming))
+s_caller ()
+{
+  sc_callee ();
+  s_callee ();
+  n_callee ();
+  sc_ls_callee ();
+  n_ls_callee ();
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/sme/inlining_3.c b/gcc/testsuite/gcc.target/aarch64/sme/inlining_3.c
new file mode 100644
index 00000000000..d9913350d05
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sme/inlining_3.c
@@ -0,0 +1,26 @@ 
+/* { dg-options "" } */
+
+inline void __attribute__((always_inline, arm_streaming_compatible))
+sc_callee () {}
+
+inline void __attribute__((always_inline, arm_streaming))
+s_callee () {} // { dg-error "inlining failed" }
+
+inline void __attribute__((always_inline))
+n_callee () {}
+
+inline void __attribute__((always_inline, arm_streaming_compatible, arm_locally_streaming))
+sc_ls_callee () {} // { dg-error "inlining failed" }
+
+inline void __attribute__((always_inline, arm_locally_streaming))
+n_ls_callee () {} // { dg-error "inlining failed" }
+
+void
+n_caller ()
+{
+  sc_callee ();
+  s_callee ();
+  n_callee ();
+  sc_ls_callee ();
+  n_ls_callee ();
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/sme/inlining_4.c b/gcc/testsuite/gcc.target/aarch64/sme/inlining_4.c
new file mode 100644
index 00000000000..db7f2cecc22
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sme/inlining_4.c
@@ -0,0 +1,26 @@ 
+/* { dg-options "" } */
+
+inline void __attribute__((always_inline, arm_streaming_compatible))
+sc_callee () {}
+
+inline void __attribute__((always_inline, arm_streaming))
+s_callee () {}
+
+inline void __attribute__((always_inline))
+n_callee () {} // { dg-error "inlining failed" }
+
+inline void __attribute__((always_inline, arm_streaming_compatible, arm_locally_streaming))
+sc_ls_callee () {}
+
+inline void __attribute__((always_inline, arm_locally_streaming))
+n_ls_callee () {}
+
+void __attribute__((arm_streaming_compatible, arm_locally_streaming))
+sc_ls_caller ()
+{
+  sc_callee ();
+  s_callee ();
+  n_callee ();
+  sc_ls_callee ();
+  n_ls_callee ();
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/sme/inlining_5.c b/gcc/testsuite/gcc.target/aarch64/sme/inlining_5.c
new file mode 100644
index 00000000000..32db426682b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sme/inlining_5.c
@@ -0,0 +1,26 @@ 
+/* { dg-options "" } */
+
+inline void __attribute__((always_inline, arm_streaming_compatible))
+sc_callee () {}
+
+inline void __attribute__((always_inline, arm_streaming))
+s_callee () {}
+
+inline void __attribute__((always_inline))
+n_callee () {} // { dg-error "inlining failed" }
+
+inline void __attribute__((always_inline, arm_streaming_compatible, arm_locally_streaming))
+sc_ls_callee () {}
+
+inline void __attribute__((always_inline, arm_locally_streaming))
+n_ls_callee () {}
+
+void __attribute__((arm_locally_streaming))
+n_ls_caller ()
+{
+  sc_callee ();
+  s_callee ();
+  n_callee ();
+  sc_ls_callee ();
+  n_ls_callee ();
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/sme/inlining_6.c b/gcc/testsuite/gcc.target/aarch64/sme/inlining_6.c
new file mode 100644
index 00000000000..cf09c61f9d4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sme/inlining_6.c
@@ -0,0 +1,18 @@ 
+/* { dg-options "" } */
+
+inline void __attribute__((always_inline, arm_shared_za))
+shared_callee () {}
+
+inline void __attribute__((always_inline, arm_new_za))
+new_callee () {} // { dg-error "inlining failed" }
+
+inline void __attribute__((always_inline))
+normal_callee () {}
+
+void __attribute__((arm_shared_za))
+shared_caller ()
+{
+  shared_callee ();
+  new_callee ();
+  normal_callee ();
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/sme/inlining_7.c b/gcc/testsuite/gcc.target/aarch64/sme/inlining_7.c
new file mode 100644
index 00000000000..8a5d261a8a2
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sme/inlining_7.c
@@ -0,0 +1,18 @@ 
+/* { dg-options "" } */
+
+inline void __attribute__((always_inline, arm_shared_za))
+shared_callee () {}
+
+inline void __attribute__((always_inline, arm_new_za))
+new_callee () {} // { dg-error "inlining failed" }
+
+inline void __attribute__((always_inline))
+normal_callee () {}
+
+void __attribute__((arm_new_za))
+new_caller ()
+{
+  shared_callee ();
+  new_callee ();
+  normal_callee ();
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/sme/inlining_8.c b/gcc/testsuite/gcc.target/aarch64/sme/inlining_8.c
new file mode 100644
index 00000000000..0706f5a5089
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sme/inlining_8.c
@@ -0,0 +1,18 @@ 
+/* { dg-options "" } */
+
+inline void __attribute__((always_inline, arm_shared_za))
+shared_callee () {} // { dg-error "inlining failed" }
+
+inline void __attribute__((always_inline, arm_new_za))
+new_callee () {} // { dg-error "inlining failed" }
+
+inline void __attribute__((always_inline))
+normal_callee () {}
+
+void
+normal_caller ()
+{
+  shared_callee ();
+  new_callee ();
+  normal_callee ();
+}