Re: [PATCH, ARM] attribute target (thumb,arm) [4/6] respin (5th)

2015-06-08 Thread Ramana Radhakrishnan



On 08/06/15 09:45, Christian Bruel wrote:

Hi Ramana,



Ok, I see.
The patch looks ok to me modulo the typo nits I pointed out, but I
think Ramana
should have the final say here as he's already started reviewing it
and it adds quite
a lot of functionality.

Thanks,
Kyrill



do you have other feedbacks for the remaining parts ?

many thanks

Christian



This is OK, thanks.

Ramana


Re: [PATCH, ARM] attribute target (thumb,arm) [4/6] respin (5th)

2015-06-01 Thread Kyrill Tkachov


On 01/06/15 12:29, Christian Bruel wrote:

hi Kyrill


On 06/01/2015 12:39 PM, Kyrill Tkachov wrote:

On 18/05/15 09:14, Christian Bruel wrote:

Hi,

Hi Christian,
A couple comments inline.
Overall, the approach looks ok to me, though I think we'll have to
generalise arm_valid_target_attribute_rec in the future if we want
to allow other target attributes.


the other fpu target attributes will be part of another set of
developments, specific parsing strings will be added as they are
implemented.


Ok, so you plan on working on fpu attributes as well?




+
+/* Establish appropriate back-end context for processing the function
+   FNDECL.  The argument might be NULL to indicate processing at top
+   level, outside of any function scope.  */
+static void
+arm_set_current_function (tree fndecl)
+{
+  if (!fndecl || fndecl == arm_previous_fndecl)
+return;
+
+  tree old_tree = (arm_previous_fndecl
+  ? DECL_FUNCTION_SPECIFIC_TARGET (arm_previous_fndecl)
+  : NULL_TREE);
+
+  tree new_tree = DECL_FUNCTION_SPECIFIC_TARGET (fndecl);
+
+  arm_previous_fndecl = fndecl;
+  if (old_tree == new_tree)
+;
+
+  else if (new_tree)
+{
+  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)
+{
+  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 ();
+}
+
+  arm_option_params_internal (global_options);


I thought the more common approach was to define TARGET_OPTION_RESTORE
that was supposed to restore the backend state, including calling 
arm_option_params_internal?
That way, cl_target_option_restore would do all that needs to be done to 
restore the backend.


TARGET_OPTION_RESTORE is fine to restore target-specific
information from struct cl_target_option. Other global states might as
well be expressed within set_current_function (e.g indeed I might use
TARGET_OPTION_RESTORE to switch arm_fpu_attr in the fpu neon attribute).
But IMHO arm_option_params_internal are fine to be called there since
the 2 params only depend from x_target_flags without the need of a new
macro.


Ok, I see.
The patch looks ok to me modulo the typo nits I pointed out, but I think Ramana
should have the final say here as he's already started reviewing it and it adds 
quite
a lot of functionality.

Thanks,
Kyrill








Re: [PATCH, ARM] attribute target (thumb,arm) [4/6] respin (5th)

2015-06-01 Thread Kyrill Tkachov


On 18/05/15 09:14, Christian Bruel wrote:

Hi,


Hi Christian,
A couple comments inline.
Overall, the approach looks ok to me, though I think we'll have to
generalise arm_valid_target_attribute_rec in the future if we want
to allow other target attributes.

Thanks,
Kyrill



Here is again a new version for patch [4/6]: (Implements and document
the hooks to support target_attributes.)

   - Rewrote for conflicts introduced by the new macros defined in
 https://gcc.gnu.org/ml/gcc-patches/2015-05/msg01198.html

   - Take your comments and Sandra's for documentation

   - I'd like to leave the inlining question apart with its own patch
until we settle it. Is it OK with you ?
 https://gcc.gnu.org/ml/gcc-patches/2015-05/msg01527.html

many thanks,

Christian

p4.patch


2014-09-23  Christian Bruelchristian.br...@st.com

* config/arm/arm.opt (THUMB, arm_restrict_it, inline_asm_unified): Save.
* config/arm/arm.h (arm_valid_target_attribute_tree): Declare.
(arm_reset_previous_fndecl, arm_change_mode_p): Likewise.
(SWITCHABLE_TARGET): Define.
* config/arm/arm.c (arm_reset_previous_fndecl): New functions.
(arm_valid_target_attribute_tree, arm_change_mode_p): Likewise.
(arm_valid_target_attribute_p): Likewise.
(arm_set_current_function, arm_can_inline_p): Likewise.
(arm_valid_target_attribute_rec): Likewise.
(arm_previous_fndecl): New variable.
(TARGET_SET_CURRENT_FUNCTION, TARGET_OPTION_VALID_ATTRIBUTE_P): Define.
(TARGET_CAN_INLINE_P): Define.
(arm_asm_trampoline_template): Emit mode.
(arm_file_start): Don't set unified syntax.
(arm_declare_function_name): Set unified syntax and mode.
(arm_option_override): Init target_option_default_node.
and target_option_current_node.
* config/arm/arm.md (*call_value_symbol): Set mode when possible.
(*call_symbol): Likewise.
* doc/extend.texi: Document ARM/Thumb target attribute.
* doc/invoke.texi: Likewise.

2014-09-23  Christian Bruelchristian.br...@st.com

* gcc.target/arm/attr_arm.c: New test
* gcc.target/arm/attr_arm-err.c: New test
* gcc.target/arm/attr_thumb.c: New test
* gcc.target/arm/attr_thumb-static.c: New test


Full stops at end of New test

snip

 
+/* Check that FUNC is called with a different mode.  */

+
+bool
+arm_change_mode_p (tree func)
+{
+  if (TREE_CODE (func) != FUNCTION_DECL)
+return false;
+
+  tree callee_tree = DECL_FUNCTION_SPECIFIC_TARGET (func);
+
+  if (!callee_tree)
+callee_tree = target_option_default_node;
+
+  struct cl_target_option *callee_opts = TREE_TARGET_OPTION (callee_tree);
+  int flags = callee_opts -x_target_flags;


No space after callee_opts.

snip
 
+/* Remember the last target of arm_set_current_function.  */

+static GTY(()) tree arm_previous_fndecl;
+
+/* Invalidate arm_previous_fndecl.  */
+void
+arm_reset_previous_fndecl (void)
+{
+  arm_previous_fndecl = NULL_TREE;
+}
+
+/* Establish appropriate back-end context for processing the function
+   FNDECL.  The argument might be NULL to indicate processing at top
+   level, outside of any function scope.  */
+static void
+arm_set_current_function (tree fndecl)
+{
+  if (!fndecl || fndecl == arm_previous_fndecl)
+return;
+
+  tree old_tree = (arm_previous_fndecl
+  ? DECL_FUNCTION_SPECIFIC_TARGET (arm_previous_fndecl)
+  : NULL_TREE);
+
+  tree new_tree = DECL_FUNCTION_SPECIFIC_TARGET (fndecl);
+
+  arm_previous_fndecl = fndecl;
+  if (old_tree == new_tree)
+;
+
+  else if (new_tree)
+{
+  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)
+{
+  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 ();
+}
+
+  arm_option_params_internal (global_options);


I thought the more common approach was to define TARGET_OPTION_RESTORE
that was supposed to restore the backend state, including calling 
arm_option_params_internal?
That way, cl_target_option_restore would do all that needs to be done to 
restore the backend.

snip

diff '--exclude=.svn' -ruN 
gnu_trunk.p2/gcc/gcc/testsuite/gcc.target/arm/attr_arm.c 
gnu_trunk.p4/gcc/gcc/testsuite/gcc.target/arm/attr_arm.c
--- 

Re: [PATCH, ARM] attribute target (thumb,arm) [4/6] respin (4th)

2015-05-08 Thread Ramana Radhakrishnan


I'm still playing with the code, so this is a partial review.

We should prevent inlining of ARM state functions into functions we know 
will be T16 if !TARGET_SOFT_FLOAT on the grounds that the architecture 
doesn't have floating point instruction encodings in the T16 ISA 
(Thumb1). We'll just cause internal compiler errors if we allow this.



On 07/05/15 00:03, Sandra Loosemore wrote:

On 05/06/2015 08:24 AM, Christian Bruel wrote:

diff '--exclude=.svn' -ruN gnu_trunk.p3/gcc/gcc/doc/extend.texi 
gnu_trunk.p4/gcc/gcc/doc/extend.texi
--- gnu_trunk.p3/gcc/gcc/doc/extend.texi2015-05-06 09:00:31.232943164 
+0200
+++ gnu_trunk.p4/gcc/gcc/doc/extend.texi2015-05-06 14:50:05.632612233 
+0200
@@ -3419,6 +3419,25 @@
  the compiler rejects attempts to specify an alternative.
  @end table

+@item target (@var{options})
+@cindex @code{target} function attribute
+As discussed in @ref{Common Function Attributes}, this attribute
+allows specification of target-specific compilation options.
+
+On ARM, the following options are allowed:
+
+@table @samp
+@item thumb
+@cindex @code{target(thumb)} function attribute, ARM
+Force Thumb1 Thumb2 code generation depending on the architecture.


Force Thumb or Thumb-2 code generation, depending on the architecture.


I'd rather it said something like

Force code generation in the Thumb (T16/ T32) ISA. The exact 
instructions chosen depends on the architecture levels chosen.



+
+@item arm
+@cindex @code{target(arm)} function attribute, ARM
+Force ARM code generation.


Force code generation in the ARM (A32) ISA.


+@end table
+
+Functions from different modes can be inlined using the caller mode.


Rewrite this based on the review comment about inlining in the Thumb16 
state from ARM state.





...the caller's mode.


+
  @node AVR Function Attributes
  @subsection AVR Function Attributes

@@ -18436,8 +18455,9 @@
  @xref{Function Attributes}, for more information about the
  @code{target} attribute and the attribute syntax.

-The @code{#pragma GCC target} pragma is presently implemented for
-x86, PowerPC, and Nios II targets only.
+The @code{#pragma GCC target} pragma is implemented for
+ARM, x86, PowerPC, and Nios II targets.
+


I'd rather say this once we have proper support with arch, cpu and fpu 
options enabled. Until such a time I think this hunk is a bit premature.



Ramana


Re: [PATCH, ARM] attribute target (thumb,arm) [4/6] respin (4th)

2015-05-07 Thread Christian Bruel
+ Sandra's doc review fixes.

tested with make doc pdf

thanks

Christian

On 05/06/2015 04:24 PM, Christian Bruel wrote:
 Implements and document the hooks to support target_attributes.
 
 The emission of blx is handled directly for armv5 to overcome a bug with
 the current binutils that fails with calls to a static symbol in a
 different section. (e.g .text - .text.startup) in different modes.
 
 (ref https://sourceware.org/bugzilla/show_bug.cgi?id=17505)
 
 Regtests included
 
 Thanks
 
 Christian
 
2014-09-23  Christian Bruel  christian.br...@st.com

	* config/arm/arm.opt (THUMB, arm_restrict_it, inline_asm_unified): Save.
	* config/arm/arm.h (arm_valid_target_attribute_tree): Declare.
	(arm_reset_previous_fndecl, arm_change_mode_p): Likewise.
	(SWITCHABLE_TARGET): Define.
	* config/arm/arm.c (arm_reset_previous_fndecl): New functions.
	(arm_valid_target_attribute_tree, arm_change_mode_p): Likewise.
	(arm_valid_target_attribute_p): Likewise.
	(arm_set_current_function, arm_can_inline_p): Likewise.
	(arm_valid_target_attribute_rec): Likewise.
	(arm_previous_fndecl): New variable.
	(TARGET_SET_CURRENT_FUNCTION, TARGET_OPTION_VALID_ATTRIBUTE_P): Define.
	(TARGET_CAN_INLINE_P): Define.
	(arm_asm_trampoline_template): Emit mode.
	(arm_file_start): Don't set unified syntax.
	(arm_declare_function_name): Set unified syntax and mode.
	(arm_option_override): Init target_option_default_node.
	and target_option_current_node.
	* config/arm/arm.md (*call_value_symbol): Set mode when possible.
	(*call_symbol): Likewise.
	* doc/extend.texi: Document ARM target and pragma attribute.
	* doc/invoke.texi: Likewise.

2014-09-23  Christian Bruel  christian.br...@st.com

	* gcc.target/arm/attr_arm.c: New test
	* gcc.target/arm/attr_arm-err.c: New test
	* gcc.target/arm/attr_thumb.c: New test
	* gcc.target/arm/attr_thumb-static.c: New test



diff '--exclude=.svn' -ruN gnu_trunk.p3/gcc/gcc/config/arm/arm.c gnu_trunk.p4/gcc/gcc/config/arm/arm.c
--- gnu_trunk.p3/gcc/gcc/config/arm/arm.c	2015-05-06 14:31:48.750726995 +0200
+++ gnu_trunk.p4/gcc/gcc/config/arm/arm.c	2015-05-06 15:03:29.393992051 +0200
@@ -94,6 +94,7 @@
 #include opts.h
 #include dumpfile.h
 #include gimple-expr.h
+#include target-globals.h
 #include builtins.h
 #include tm-constrs.h
 #include rtl-iter.h
@@ -264,6 +265,9 @@
 static void arm_expand_builtin_va_start (tree, rtx);
 static tree arm_gimplify_va_arg_expr (tree, tree, gimple_seq *, gimple_seq *);
 static void arm_option_override (void);
+static void arm_set_current_function (tree);
+static bool arm_can_inline_p (tree, tree);
+static bool arm_valid_target_attribute_p (tree, tree, tree, int);
 static unsigned HOST_WIDE_INT arm_shift_truncation_mask (machine_mode);
 static bool arm_macro_fusion_p (void);
 static bool arm_cannot_copy_insn_p (rtx_insn *);
@@ -412,6 +416,9 @@
 #undef  TARGET_ASM_FUNCTION_EPILOGUE
 #define TARGET_ASM_FUNCTION_EPILOGUE arm_output_function_epilogue
 
+#undef TARGET_CAN_INLINE_P
+#define TARGET_CAN_INLINE_P arm_can_inline_p
+
 #undef  TARGET_OPTION_OVERRIDE
 #define TARGET_OPTION_OVERRIDE arm_option_override
 
@@ -430,6 +437,12 @@
 #undef  TARGET_SCHED_ADJUST_COST
 #define TARGET_SCHED_ADJUST_COST arm_adjust_cost
 
+#undef TARGET_SET_CURRENT_FUNCTION
+#define TARGET_SET_CURRENT_FUNCTION arm_set_current_function
+
+#undef TARGET_OPTION_VALID_ATTRIBUTE_P
+#define TARGET_OPTION_VALID_ATTRIBUTE_P arm_valid_target_attribute_p
+
 #undef TARGET_SCHED_REORDER
 #define TARGET_SCHED_REORDER arm_sched_reorder
 
@@ -2750,6 +2763,9 @@
 }
 }
 
+/* Options after initial target override.  */
+static GTY(()) tree init_optimize;
+
 /* Reset options between modes that the user has specified.  */
 static void
 arm_option_override_internal (struct gcc_options *opts,
@@ -2772,6 +2788,10 @@
   if (TREE_TARGET_THUMB (opts)  TARGET_CALLEE_INTERWORKING)
 opts-x_target_flags |= MASK_INTERWORK;
 
+  /* need to remember initial values so combinaisons of options like
+ -mflip-thumb -mthumb -fno-schedule-insns work for any attribute.  */
+  cl_optimization *to = TREE_OPTIMIZATION (init_optimize);
+
   if (! opts_set-x_arm_restrict_it)
 opts-x_arm_restrict_it = arm_arch8;
 
@@ -2779,15 +2799,17 @@
 opts-x_arm_restrict_it = 0;
 
   if (TREE_TARGET_THUMB1 (opts))
-{
-  /* Don't warn since it's on by default in -O2.  */
-  opts-x_flag_schedule_insns = 0;
-}
+/* Don't warn since it's on by default in -O2.  */
+opts-x_flag_schedule_insns = 0;
+  else
+opts-x_flag_schedule_insns = to-x_flag_schedule_insns;
 
   /* Disable shrink-wrap when optimizing function for size, since it tends to
  generate additional returns.  */
   if (optimize_function_for_size_p (cfun)  TREE_TARGET_THUMB2 (opts))
 opts-x_flag_shrink_wrap = false;
+  else
+opts-x_flag_shrink_wrap = to-x_flag_shrink_wrap;
 
   /* In Thumb1 mode, we emit the epilogue in RTL, but the last insn
  - epilogue_insns - does not accurately model the corresponding insns
@@ -2799,6 +2821,8 @@
  fipa-ra. 

[PATCH, ARM] attribute target (thumb,arm) [4/6] respin (4th)

2015-05-06 Thread Christian Bruel
Implements and document the hooks to support target_attributes.

The emission of blx is handled directly for armv5 to overcome a bug with
the current binutils that fails with calls to a static symbol in a
different section. (e.g .text - .text.startup) in different modes.

(ref https://sourceware.org/bugzilla/show_bug.cgi?id=17505)

Regtests included

Thanks

Christian

2014-09-23  Christian Bruel  christian.br...@st.com

	* config/arm/arm.opt (THUMB, arm_restrict_it, inline_asm_unified): Save.
	* config/arm/arm.h (arm_valid_target_attribute_tree): Declare.
	(arm_reset_previous_fndecl, arm_change_mode_p): Likewise.
	(SWITCHABLE_TARGET): Define.
	* config/arm/arm.c (arm_reset_previous_fndecl): New functions.
	(arm_valid_target_attribute_tree, arm_change_mode_p): Likewise.
	(arm_valid_target_attribute_p): Likewise.
	(arm_set_current_function, arm_can_inline_p): Likewise.
	(arm_valid_target_attribute_rec): Likewise.
	(arm_previous_fndecl): New variable.
	(TARGET_SET_CURRENT_FUNCTION, TARGET_OPTION_VALID_ATTRIBUTE_P): Define.
	(TARGET_CAN_INLINE_P): Define.
	(arm_asm_trampoline_template): Emit mode.
	(arm_file_start): Don't set unified syntax.
	(arm_declare_function_name): Set unified syntax and mode.
	(arm_option_override): Init target_option_default_node.
	and target_option_current_node.
	* config/arm/arm.md (*call_value_symbol): Set mode when possible.
	(*call_symbol): Likewise.
	* doc/extend.texi: Document ARM target and pragma attribute.
	* doc/invoke.texi: Likewise.

diff '--exclude=.svn' -ruN gnu_trunk.p3/gcc/gcc/config/arm/arm.c gnu_trunk.p4/gcc/gcc/config/arm/arm.c
--- gnu_trunk.p3/gcc/gcc/config/arm/arm.c	2015-05-06 14:31:48.750726995 +0200
+++ gnu_trunk.p4/gcc/gcc/config/arm/arm.c	2015-05-06 15:03:29.393992051 +0200
@@ -94,6 +94,7 @@
 #include opts.h
 #include dumpfile.h
 #include gimple-expr.h
+#include target-globals.h
 #include builtins.h
 #include tm-constrs.h
 #include rtl-iter.h
@@ -264,6 +265,9 @@
 static void arm_expand_builtin_va_start (tree, rtx);
 static tree arm_gimplify_va_arg_expr (tree, tree, gimple_seq *, gimple_seq *);
 static void arm_option_override (void);
+static void arm_set_current_function (tree);
+static bool arm_can_inline_p (tree, tree);
+static bool arm_valid_target_attribute_p (tree, tree, tree, int);
 static unsigned HOST_WIDE_INT arm_shift_truncation_mask (machine_mode);
 static bool arm_macro_fusion_p (void);
 static bool arm_cannot_copy_insn_p (rtx_insn *);
@@ -412,6 +416,9 @@
 #undef  TARGET_ASM_FUNCTION_EPILOGUE
 #define TARGET_ASM_FUNCTION_EPILOGUE arm_output_function_epilogue
 
+#undef TARGET_CAN_INLINE_P
+#define TARGET_CAN_INLINE_P arm_can_inline_p
+
 #undef  TARGET_OPTION_OVERRIDE
 #define TARGET_OPTION_OVERRIDE arm_option_override
 
@@ -430,6 +437,12 @@
 #undef  TARGET_SCHED_ADJUST_COST
 #define TARGET_SCHED_ADJUST_COST arm_adjust_cost
 
+#undef TARGET_SET_CURRENT_FUNCTION
+#define TARGET_SET_CURRENT_FUNCTION arm_set_current_function
+
+#undef TARGET_OPTION_VALID_ATTRIBUTE_P
+#define TARGET_OPTION_VALID_ATTRIBUTE_P arm_valid_target_attribute_p
+
 #undef TARGET_SCHED_REORDER
 #define TARGET_SCHED_REORDER arm_sched_reorder
 
@@ -2750,6 +2763,9 @@
 }
 }
 
+/* Options after initial target override.  */
+static GTY(()) tree init_optimize;
+
 /* Reset options between modes that the user has specified.  */
 static void
 arm_option_override_internal (struct gcc_options *opts,
@@ -2772,6 +2788,10 @@
   if (TREE_TARGET_THUMB (opts)  TARGET_CALLEE_INTERWORKING)
 opts-x_target_flags |= MASK_INTERWORK;
 
+  /* need to remember initial values so combinaisons of options like
+ -mflip-thumb -mthumb -fno-schedule-insns work for any attribute.  */
+  cl_optimization *to = TREE_OPTIMIZATION (init_optimize);
+
   if (! opts_set-x_arm_restrict_it)
 opts-x_arm_restrict_it = arm_arch8;
 
@@ -2779,15 +2799,17 @@
 opts-x_arm_restrict_it = 0;
 
   if (TREE_TARGET_THUMB1 (opts))
-{
-  /* Don't warn since it's on by default in -O2.  */
-  opts-x_flag_schedule_insns = 0;
-}
+/* Don't warn since it's on by default in -O2.  */
+opts-x_flag_schedule_insns = 0;
+  else
+opts-x_flag_schedule_insns = to-x_flag_schedule_insns;
 
   /* Disable shrink-wrap when optimizing function for size, since it tends to
  generate additional returns.  */
   if (optimize_function_for_size_p (cfun)  TREE_TARGET_THUMB2 (opts))
 opts-x_flag_shrink_wrap = false;
+  else
+opts-x_flag_shrink_wrap = to-x_flag_shrink_wrap;
 
   /* In Thumb1 mode, we emit the epilogue in RTL, but the last insn
  - epilogue_insns - does not accurately model the corresponding insns
@@ -2799,6 +2821,8 @@
  fipa-ra.  */
   if (TREE_TARGET_THUMB1 (opts))
 opts-x_flag_ipa_ra = 0;
+  else
+opts-x_flag_ipa_ra = to-x_flag_ipa_ra;
 
   /* Thumb2 inline assembly code should always use unified syntax.
  This will apply to ARM and Thumb1 eventually.  */
@@ -3291,12 +3315,20 @@
(!arm_arch7 || !current_tune-prefer_ldrd_strd))
 flag_schedule_fusion = 0;
 
+  

Re: [PATCH, ARM] attribute target (thumb,arm) [4/6] respin (4th)

2015-05-06 Thread Sandra Loosemore

On 05/06/2015 08:24 AM, Christian Bruel wrote:

diff '--exclude=.svn' -ruN gnu_trunk.p3/gcc/gcc/doc/extend.texi 
gnu_trunk.p4/gcc/gcc/doc/extend.texi
--- gnu_trunk.p3/gcc/gcc/doc/extend.texi2015-05-06 09:00:31.232943164 
+0200
+++ gnu_trunk.p4/gcc/gcc/doc/extend.texi2015-05-06 14:50:05.632612233 
+0200
@@ -3419,6 +3419,25 @@
 the compiler rejects attempts to specify an alternative.
 @end table

+@item target (@var{options})
+@cindex @code{target} function attribute
+As discussed in @ref{Common Function Attributes}, this attribute
+allows specification of target-specific compilation options.
+
+On ARM, the following options are allowed:
+
+@table @samp
+@item thumb
+@cindex @code{target(thumb)} function attribute, ARM
+Force Thumb1 Thumb2 code generation depending on the architecture.


Force Thumb or Thumb-2 code generation, depending on the architecture.

(I believe that's ARM's official terminology, rather than Thumb1 or 
Thumb2.)



+
+@item arm
+@cindex @code{target(arm)} function attribute, ARM
+Force ARM code generation.
+@end table
+
+Functions from different modes can be inlined using the caller mode.


...the caller's mode.


+
 @node AVR Function Attributes
 @subsection AVR Function Attributes

@@ -18436,8 +18455,9 @@
 @xref{Function Attributes}, for more information about the
 @code{target} attribute and the attribute syntax.

-The @code{#pragma GCC target} pragma is presently implemented for
-x86, PowerPC, and Nios II targets only.
+The @code{#pragma GCC target} pragma is implemented for
+ARM, x86, PowerPC, and Nios II targets.
+
 @end table

 @table @code


Please also add a cross-reference to ARM Function Attributes in the main 
entry for @item target in Common Function Attributes, in this paragraph:


The options supported are specific to each target; refer to @ref{x86
Function Attributes}, @ref{PowerPC Function Attributes}, and
@ref{Nios II Function Attributes}, for details.


diff '--exclude=.svn' -ruN gnu_trunk.p3/gcc/gcc/doc/invoke.texi 
gnu_trunk.p4/gcc/gcc/doc/invoke.texi
--- gnu_trunk.p3/gcc/gcc/doc/invoke.texi2015-05-06 09:00:31.232943164 
+0200
+++ gnu_trunk.p4/gcc/gcc/doc/invoke.texi2015-05-06 14:36:32.331213593 
+0200
@@ -13434,6 +13434,10 @@
 configuring GCC with the @option{--with-mode=}@var{state}
 configure option.

+You can also override the ARM and Thumb mode for each function
+by using the @code{target(thumb)} and @code{target(arm)} function 
attributes
+(@pxref{Function Attributes}) or pragmas (@pxref{Function Specific Option 
Pragmas}).


You can make the first reference point at the ARM Function Attributes 
node, now that it exists, instead of the generic Function Attributes 
section.



+
 @item -mtpcs-frame
 @opindex mtpcs-frame
 Generate a stack frame that is compliant with the Thumb Procedure Call


-Sandra



[PATCH, ARM] attribute target (thumb,arm) [4/6]

2014-11-19 Thread Christian Bruel

Implements and document the hooks to support target_attributes.

The emission of blx is handled directly for armv5 to overcome a bug with 
the current binutils that fails with calls to a static symbol in a 
different section. (e.g .text - .text.startup) in different modes.

(ref https://sourceware.org/bugzilla/show_bug.cgi?id=17505)

Regtests included

Thanks

Christian
2014-09-23  Christian Bruel  christian.br...@st.com

	* config/arm/arm.opt (mthumb): Save.
	* config/arm/arm.h (arm_valid_target_attribute_tree): Declare.
	(arm_reset_previous_fndecl, arm_change_mode_p): Likewise.
	(SWITCHABLE_TARGET): Define.
	* config/arm/arm.c (arm_reset_previous_fndecl): New functions.
	(arm_valid_target_attribute_tree, arm_change_mode_p): Likewise.
	(arm_valid_target_attribute_p): Likewise.
	(arm_set_current_function, arm_can_inline_p): Likewise.
	(arm_valid_target_attribute_rec): Likewise.
	(arm_previous_fndecl): New variable.
	(TARGET_SET_CURRENT_FUNCTION, TARGET_OPTION_VALID_ATTRIBUTE_P): Define.
	(TARGET_CAN_INLINE_P): Define.
	(arm_asm_trampoline_template): Emit mode.
	(arm_file_start): Don't set unified syntax.
	(arm_declare_function_name): Set unified syntax and mode.
	(arm_option_override): Init target_option_default_node.
	and target_option_current_node.
	* config/arm/arm.md (*call_value_symbol): Set mode when possible.
	(*call_symbol): Likewise.
	* doc/extend.texi: Document ARM target and pragma attribute.
	* doc/invoke.texi: Likewise.

diff '--exclude=ChangeLog*' '--exclude=.svn' '--exclude=*~' '--exclude=#*#' -rupN d/gcc/gcc/config/arm/arm.c e/gcc/gcc/config/arm/arm.c
--- d/gcc/gcc/config/arm/arm.c	2014-11-18 08:51:50.0 +0100
+++ e/gcc/gcc/config/arm/arm.c	2014-11-18 09:05:57.0 +0100
@@ -80,6 +80,7 @@
 #include opts.h
 #include dumpfile.h
 #include gimple-expr.h
+#include target-globals.h
 #include builtins.h
 #include tm-constrs.h
 #include rtl-iter.h
@@ -258,6 +259,9 @@ static tree arm_build_builtin_va_list (v
 static void arm_expand_builtin_va_start (tree, rtx);
 static tree arm_gimplify_va_arg_expr (tree, tree, gimple_seq *, gimple_seq *);
 static void arm_option_override (void);
+static void arm_set_current_function (tree);
+static bool arm_can_inline_p (tree, tree);
+static bool arm_valid_target_attribute_p (tree, tree, tree, int);
 static unsigned HOST_WIDE_INT arm_shift_truncation_mask (machine_mode);
 static bool arm_cannot_copy_insn_p (rtx_insn *);
 static int arm_issue_rate (void);
@@ -400,6 +404,9 @@ static const struct attribute_spec arm_a
 #undef  TARGET_ASM_FUNCTION_EPILOGUE
 #define TARGET_ASM_FUNCTION_EPILOGUE arm_output_function_epilogue
 
+#undef TARGET_CAN_INLINE_P
+#define TARGET_CAN_INLINE_P arm_can_inline_p
+
 #undef  TARGET_OPTION_OVERRIDE
 #define TARGET_OPTION_OVERRIDE arm_option_override
 
@@ -412,6 +419,12 @@ static const struct attribute_spec arm_a
 #undef  TARGET_SCHED_ADJUST_COST
 #define TARGET_SCHED_ADJUST_COST arm_adjust_cost
 
+#undef TARGET_SET_CURRENT_FUNCTION
+#define TARGET_SET_CURRENT_FUNCTION arm_set_current_function
+
+#undef TARGET_OPTION_VALID_ATTRIBUTE_P
+#define TARGET_OPTION_VALID_ATTRIBUTE_P arm_valid_target_attribute_p
+
 #undef TARGET_SCHED_REORDER
 #define TARGET_SCHED_REORDER arm_sched_reorder
 
@@ -3205,6 +3218,11 @@ arm_option_override (void)
 
   /* Register global variables with the garbage collector.  */
   arm_add_gc_roots ();
+
+  /* Save the initial options in case the user does function specific
+ options.  */
+  target_option_default_node = target_option_current_node
+= build_target_option_node (global_options);
 }
 
 static void
@@ -3358,13 +3376,20 @@ arm_warn_func_return (tree decl)
 static void
 arm_asm_trampoline_template (FILE *f)
 {
+  if (TARGET_UNIFIED_ASM)
+fprintf (f, \t.syntax unified\n);
+  else
+fprintf (f, \t.syntax divided\n);
+
   if (TARGET_ARM)
 {
+  fprintf (f, \t.arm\n);
   asm_fprintf (f, \tldr\t%r, [%r, #0]\n, STATIC_CHAIN_REGNUM, PC_REGNUM);
   asm_fprintf (f, \tldr\t%r, [%r, #0]\n, PC_REGNUM, PC_REGNUM);
 }
   else if (TARGET_THUMB2)
 {
+  fprintf (f, \t.thumb\n);
   /* The Thumb-2 trampoline is similar to the arm implementation.
 	 Unlike 16-bit Thumb, we enter the stub in thumb mode.  */
   asm_fprintf (f, \tldr.w\t%r, [%r, #4]\n,
@@ -26874,6 +26899,23 @@ thumb_far_jump_used_p (void)
   return 0;
 }
 
+/* Check that FUNC is called with a different mode.  */
+
+bool
+arm_change_mode_p (tree func)
+{
+  if (TREE_CODE (func) != FUNCTION_DECL)
+return false;
+
+  tree callee_tree = DECL_FUNCTION_SPECIFIC_TARGET (func);
+
+  if (!callee_tree)
+callee_tree = target_option_default_node;
+
+  struct cl_target_option *callee_opts = TREE_TARGET_OPTION (callee_tree);
+
+  return (TREE_TARGET_THUMB (callee_opts) != TARGET_THUMB);
+}
 
 /* Given the stack offsets and register mask in OFFSETS, decide how
many additional registers to push instead of subtracting a constant
@@ -28448,9 +28490,6 @@ arm_file_start (void)
 {
   int val;
 
-  if