public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][AArch64][7/14] Implement TARGET_SET_CURRENT_FUNCTION
@ 2015-07-16 15:21 Kyrill Tkachov
  2015-07-21 11:15 ` James Greenhalgh
  0 siblings, 1 reply; 2+ messages in thread
From: Kyrill Tkachov @ 2015-07-16 15:21 UTC (permalink / raw)
  To: GCC Patches; +Cc: Marcus Shawcroft, Richard Earnshaw, James Greenhalgh

[-- Attachment #1: Type: text/plain, Size: 1148 bytes --]

Hi all,

This patch implements TARGET_SET_CURRENT_FUNCTION and defines SWITCHABLE_TARGET.
With this patch in the series, we should be far enough to get LTO option switching to work properly.

The implementation if TARGET_SET_CURRENT_FUNCTION is pretty much a direct copy from the rs6000 backend,
and i386 has a very similar structure as well.  I tried to simplify this for aarch64, but in the end
this implementation was the one that worked.

TARGET_SET_CURRENT_FUNCTION should take the target-specific options from DECL_FUNCTION_SPECIFIC_TARGET
and use them to set up the backend state.  Since it may be called many times for the same function,
we keep track of the previous function this got called on in order to avoid repeating work.

Bootstrapped and tested on aarch64.

Ok for trunk?

Thanks,
Kyrill

2015-07-16  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>

     * config/aarch64/aarch64.h (SWITCHABLE_TARGET): Define.
     * config/aarch64/aarch64.c: Include target-globals.h
     (aarch64_previous_fndecl): New variable.
     (aarch64_set_current_function): New function.
     (TARGET_SET_CURRENT_FUNCTION): Define.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: aarch64-attrs-7.patch --]
[-- Type: text/x-patch; name=aarch64-attrs-7.patch, Size: 3424 bytes --]

commit f3c5c9df8bb5a26a7df65e7b68d9eb6f60eccb40
Author: Kyrylo Tkachov <kyrylo.tkachov@arm.com>
Date:   Thu May 7 14:06:04 2015 +0100

    [AArch64][7/N] Implement TARGET_SET_CURRENT_FUNCTION

diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 2891690..ff87631 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -73,6 +73,7 @@
 #include "tm-constrs.h"
 #include "sched-int.h"
 #include "cortex-a57-fma-steering.h"
+#include "target-globals.h"
 
 /* This file should be included last.  */
 #include "target-def.h"
@@ -7927,6 +7928,58 @@ aarch64_option_print (FILE *file, int indent, struct cl_target_option *ptr)
   aarch64_print_extension (file, isa_flags);
 }
 
+static GTY(()) tree aarch64_previous_fndecl;
+
+/* Implement TARGET_SET_CURRENT_FUNCTION.  Unpack the codegen decisions
+   like tuning and ISA features from the DECL_FUNCTION_SPECIFIC_TARGET
+   of the function, if such exists.  This function may be called multiple
+   times on a single function so use aarch64_previous_fndecl to avoid
+   setting up identical state.  */
+
+static void
+aarch64_set_current_function (tree fndecl)
+{
+  tree old_tree = (aarch64_previous_fndecl
+		   ? DECL_FUNCTION_SPECIFIC_TARGET (aarch64_previous_fndecl)
+		   : NULL_TREE);
+
+  tree new_tree = (fndecl
+		   ? DECL_FUNCTION_SPECIFIC_TARGET (fndecl)
+		   : NULL_TREE);
+
+
+  if (fndecl && fndecl != aarch64_previous_fndecl)
+    {
+      aarch64_previous_fndecl = fndecl;
+      if (old_tree == new_tree)
+	;
+
+      else if (new_tree && new_tree != target_option_default_node)
+	{
+	  cl_target_option_restore (&global_options,
+				    TREE_TARGET_OPTION (new_tree));
+	  if (TREE_TARGET_GLOBALS (new_tree))
+	    restore_target_globals (TREE_TARGET_GLOBALS (new_tree));
+	  else
+	    TREE_TARGET_GLOBALS (new_tree)
+	      = save_target_globals_default_opts ();
+	}
+
+      else if (old_tree && old_tree != target_option_default_node)
+	{
+	  new_tree = target_option_current_node;
+	  cl_target_option_restore (&global_options,
+				    TREE_TARGET_OPTION (new_tree));
+	  if (TREE_TARGET_GLOBALS (new_tree))
+	    restore_target_globals (TREE_TARGET_GLOBALS (new_tree));
+	  else if (new_tree == target_option_default_node)
+	    restore_target_globals (&default_target_globals);
+	  else
+	    TREE_TARGET_GLOBALS (new_tree)
+	      = save_target_globals_default_opts ();
+	}
+    }
+}
 
 /* Return true if SYMBOL_REF X binds locally.  */
 
@@ -12399,6 +12452,9 @@ aarch64_unspec_may_trap_p (const_rtx x, unsigned flags)
 #undef TARGET_OPTION_PRINT
 #define TARGET_OPTION_PRINT aarch64_option_print
 
+#undef TARGET_SET_CURRENT_FUNCTION
+#define TARGET_SET_CURRENT_FUNCTION aarch64_set_current_function
+
 #undef TARGET_PASS_BY_REFERENCE
 #define TARGET_PASS_BY_REFERENCE aarch64_pass_by_reference
 
diff --git a/gcc/config/aarch64/aarch64.h b/gcc/config/aarch64/aarch64.h
index 6d792c4..2c1b6ce 100644
--- a/gcc/config/aarch64/aarch64.h
+++ b/gcc/config/aarch64/aarch64.h
@@ -920,6 +920,9 @@ do {									     \
 #define HARD_REGNO_CALL_PART_CLOBBERED(REGNO, MODE) \
 		(FP_REGNUM_P (REGNO) && GET_MODE_SIZE (MODE) > 8)
 
+#undef SWITCHABLE_TARGET
+#define SWITCHABLE_TARGET 1
+
 /* Check TLS Descriptors mechanism is selected.  */
 #define TARGET_TLS_DESC (aarch64_tls_dialect == TLS_DESCRIPTORS)
 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH][AArch64][7/14] Implement TARGET_SET_CURRENT_FUNCTION
  2015-07-16 15:21 [PATCH][AArch64][7/14] Implement TARGET_SET_CURRENT_FUNCTION Kyrill Tkachov
@ 2015-07-21 11:15 ` James Greenhalgh
  0 siblings, 0 replies; 2+ messages in thread
From: James Greenhalgh @ 2015-07-21 11:15 UTC (permalink / raw)
  To: Kyrill Tkachov; +Cc: GCC Patches, Marcus Shawcroft, Richard Earnshaw

On Thu, Jul 16, 2015 at 04:20:56PM +0100, Kyrill Tkachov wrote:
> Hi all,
> 
> This patch implements TARGET_SET_CURRENT_FUNCTION and defines SWITCHABLE_TARGET.
> With this patch in the series, we should be far enough to get LTO option switching to work properly.
> 
> The implementation if TARGET_SET_CURRENT_FUNCTION is pretty much a direct copy from the rs6000 backend,
> and i386 has a very similar structure as well.  I tried to simplify this for aarch64, but in the end
> this implementation was the one that worked.
> 
> TARGET_SET_CURRENT_FUNCTION should take the target-specific options from DECL_FUNCTION_SPECIFIC_TARGET
> and use them to set up the backend state.  Since it may be called many times for the same function,
> we keep track of the previous function this got called on in order to avoid repeating work.
> 
> Bootstrapped and tested on aarch64.
> 
> Ok for trunk?

OK.

Thanks,
James

> 
> Thanks,
> Kyrill
> 
> 2015-07-16  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
> 
>      * config/aarch64/aarch64.h (SWITCHABLE_TARGET): Define.
>      * config/aarch64/aarch64.c: Include target-globals.h
>      (aarch64_previous_fndecl): New variable.
>      (aarch64_set_current_function): New function.
>      (TARGET_SET_CURRENT_FUNCTION): Define.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-07-21 11:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-16 15:21 [PATCH][AArch64][7/14] Implement TARGET_SET_CURRENT_FUNCTION Kyrill Tkachov
2015-07-21 11:15 ` James Greenhalgh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).