[gcc(refs/users/aoliva/heads/testme)] strub: enable conditional support
Alexandre Oliva
aoliva@gcc.gnu.org
Wed Dec 6 23:20:08 GMT 2023
https://gcc.gnu.org/g:7d0d3a704cdf6a188463ac16e43e991398e047ef
commit 7d0d3a704cdf6a188463ac16e43e991398e047ef
Author: Alexandre Oliva <oliva@gnu.org>
Date: Wed Dec 6 19:36:02 2023 -0300
strub: enable conditional support
Diff:
---
gcc/config/i386/i386.cc | 4 ++++
gcc/config/nvptx/nvptx.cc | 3 +++
gcc/doc/tm.texi | 6 ++++++
gcc/doc/tm.texi.in | 2 ++
gcc/ipa-strub.cc | 45 +++++++++++++++++++++++++++++++++++++++++++--
gcc/target.def | 8 ++++++++
6 files changed, 66 insertions(+), 2 deletions(-)
diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index 7c5cab4e2c6..f933c9c23c7 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -26658,6 +26658,10 @@ ix86_libm_function_max_error (unsigned cfn, machine_mode mode,
#define TARGET_RUN_TARGET_SELFTESTS selftest::ix86_run_selftests
#endif /* #if CHECKING_P */
+// ??? for testing only
+#undef TARGET_HAVE_STRUB_SUPPORT_FOR
+#define TARGET_HAVE_STRUB_SUPPORT_FOR hook_bool_tree_false
+
struct gcc_target targetm = TARGET_INITIALIZER;
#include "gt-i386.h"
diff --git a/gcc/config/nvptx/nvptx.cc b/gcc/config/nvptx/nvptx.cc
index ae20802c879..3fb1deb70fd 100644
--- a/gcc/config/nvptx/nvptx.cc
+++ b/gcc/config/nvptx/nvptx.cc
@@ -7789,6 +7789,9 @@ nvptx_asm_output_def_from_decls (FILE *stream, tree name, tree value)
#undef TARGET_LIBC_HAS_FUNCTION
#define TARGET_LIBC_HAS_FUNCTION nvptx_libc_has_function
+#undef TARGET_HAVE_STRUB_SUPPORT_FOR
+#define TARGET_HAVE_STRUB_SUPPORT_FOR hook_bool_tree_false
+
struct gcc_target targetm = TARGET_INITIALIZER;
#include "gt-nvptx.h"
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 89a1735dd79..768ada0af52 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -3450,6 +3450,12 @@ in DWARF 2 debug information. The default is zero. A different value
may reduce the size of debug information on some ports.
@end defmac
+@deftypefn {Target Hook} bool TARGET_HAVE_STRUB_SUPPORT_FOR (tree)
+Returns true if the target supports stack scrubbing for the given function
+or type, otherwise return false. The default implementation always returns
+true.
+@end deftypefn
+
@defmac TARGET_STRUB_USE_DYNAMIC_ARRAY
If defined to nonzero, @code{__strub_leave} will allocate a dynamic
array covering the stack range that needs scrubbing before clearing it.
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index ebc1d3de5ca..4fe0805394e 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -2686,6 +2686,8 @@ in DWARF 2 debug information. The default is zero. A different value
may reduce the size of debug information on some ports.
@end defmac
+@hook TARGET_HAVE_STRUB_SUPPORT_FOR
+
@defmac TARGET_STRUB_USE_DYNAMIC_ARRAY
If defined to nonzero, @code{__strub_leave} will allocate a dynamic
array covering the stack range that needs scrubbing before clearing it.
diff --git a/gcc/ipa-strub.cc b/gcc/ipa-strub.cc
index 293bec132b8..b7aff03804e 100644
--- a/gcc/ipa-strub.cc
+++ b/gcc/ipa-strub.cc
@@ -60,6 +60,7 @@ along with GCC; see the file COPYING3. If not see
#include "ipa-strub.h"
#include "symtab-thunks.h"
#include "attr-fnspec.h"
+#include "target.h"
/* This file introduces two passes that, together, implement
machine-independent stack scrubbing, strub for short. It arranges
@@ -631,17 +632,53 @@ strub_always_inline_p (cgraph_node *node)
return lookup_attribute ("always_inline", DECL_ATTRIBUTES (node->decl));
}
+/* Return TRUE iff the target has strub support for T, a function decl
+ or a type, and optionally REPORT thereasons for ineligibility. */
+static inline bool
+strub_target_support_p (tree t, bool report = false)
+{
+ bool result = true;
+
+ if (!targetm.have_strub_support_for (t))
+ {
+ result = false;
+
+ if (!report)
+ return result;
+
+ sorry_at (DECL_SOURCE_LOCATION (t),
+ "%qD is not eligible for %<strub%>"
+ " on the target system",
+ t);
+ }
+
+ return result;
+}
+
/* Return TRUE iff NODE is potentially eligible for any strub-enabled mode, and
optionally REPORT the reasons for ineligibility. */
static inline bool
can_strub_p (cgraph_node *node, bool report = false)
{
- bool result = true;
+ bool result = strub_target_support_p (node->decl, report);
- if (!report && strub_always_inline_p (node))
+ if (!report && (!result || strub_always_inline_p (node)))
return result;
+ if (flag_split_stack)
+ {
+ result = false;
+
+ if (!report)
+ return result;
+
+ sorry_at (DECL_SOURCE_LOCATION (node->decl),
+ "%qD is not eligible for %<strub%>"
+ " because %<-fsplit-stack%> is enabled",
+ node->decl);
+ }
+
if (lookup_attribute ("noipa", DECL_ATTRIBUTES (node->decl)))
{
result = false;
@@ -2417,6 +2454,10 @@ pass_ipa_strub::adjust_at_calls_call (cgraph_edge *e, int named_args,
&& (TREE_TYPE (gimple_call_arg (ocall, named_args))
== get_pwmt ())));
+ if (!strub_target_support_p (TREE_TYPE (gimple_call_arg (ocall, named_args)),
+ true))
+ return;
+
/* If we're already within a strub context, pass on the incoming watermark
pointer, and omit the enter and leave calls around the modified call, as an
optimization, or as a means to satisfy a tail-call requirement. */
diff --git a/gcc/target.def b/gcc/target.def
index 52b83e091b9..08218f3a42a 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -4457,6 +4457,14 @@ otherwise return false. The default implementation always returns true.",
bool, (void),
hook_bool_void_true)
+DEFHOOK
+(have_strub_support_for,
+ "Returns true if the target supports stack scrubbing for the given function\n\
+or type, otherwise return false. The default implementation always returns\n\
+true.",
+ bool, (tree),
+ hook_bool_tree_true)
+
DEFHOOK
(have_speculation_safe_value,
"This hook is used to determine the level of target support for\n\
More information about the Gcc-cvs
mailing list