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

2015-06-09 Thread Kyrill Tkachov

Hi Christian,


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

On 05/06/2015 04:29 PM, Christian Bruel wrote:

Implement the -mflip-thump option. Undocumented for internal testing
only. This option artificially inserts alternative attribute thumb/modes
on functions.

This close the patch set. Thanks for your review,

Christian


to close the series. redo patch rebased.
  


snip


  static bool
diff '--exclude=.svn' -ruN gnu_trunk.p5/gcc/gcc/config/arm/arm.opt 
gnu_trunk.p6/gcc/gcc/config/arm/arm.opt
--- gnu_trunk.p5/gcc/gcc/config/arm/arm.opt 2015-05-18 10:20:26.545835080 
+0200
+++ gnu_trunk.p6/gcc/gcc/config/arm/arm.opt 2015-05-13 13:13:11.014686529 
+0200
@@ -122,6 +122,10 @@
  EnumValue
  Enum(float_abi_type) String(hard) Value(ARM_FLOAT_ABI_HARD)
  
+mflip-thumb

+Target Report Var(TARGET_FLIP_THUMB)
+Switch ARM/Thumb modes on alternating functions for compiler testing


How about adding 'Undocumented' to the properties here?

Can we also get a test or two just to sanity check the option?
Otherwise the patch looks ok to me.

Thanks,
Kyrill



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

2015-05-06 Thread Christian Bruel
Implement the -mflip-thump option. Undocumented for internal testing
only. This option artificially inserts alternative attribute thumb/modes
on functions.

This close the patch set. Thanks for your review,

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

	* config/arm/arm.c (add_attribute, arm_insert_attributes): New functions
	(TARGET_INSERT_ATTRIBUTES): Define.
	(thumb_flipper): New var.
	* config/arm/arm.opt (-mflip-thumb): New switch.

diff '--exclude=.svn' -ruN gnu_trunk.p5/gcc/gcc/config/arm/arm.c gnu_trunk.p6/gcc/gcc/config/arm/arm.c
--- gnu_trunk.p5/gcc/gcc/config/arm/arm.c	2015-05-06 15:03:29.393992051 +0200
+++ gnu_trunk.p6/gcc/gcc/config/arm/arm.c	2015-05-06 15:04:15.970072133 +0200
@@ -99,6 +99,7 @@
 #include tm-constrs.h
 #include rtl-iter.h
 #include sched-int.h
+#include tree.h
 
 /* Forward definitions of types.  */
 typedef struct minipool_nodeMnode;
@@ -232,6 +233,7 @@
 
 static void arm_file_end (void);
 static void arm_file_start (void);
+static void arm_insert_attributes (tree, tree *);
 
 static void arm_setup_incoming_varargs (cumulative_args_t, machine_mode,
 	tree, int *, int);
@@ -390,6 +392,9 @@
 #undef  TARGET_ATTRIBUTE_TABLE
 #define TARGET_ATTRIBUTE_TABLE arm_attribute_table
 
+#undef  TARGET_INSERT_ATTRIBUTES
+#define TARGET_INSERT_ATTRIBUTES arm_insert_attributes
+
 #undef TARGET_ASM_FILE_START
 #define TARGET_ASM_FILE_START arm_file_start
 #undef TARGET_ASM_FILE_END
@@ -2763,6 +2768,10 @@
 }
 }
 
+/* True if -mflip-thumb should next add an attribute for the default
+   mode, false if it should next add an attribute for the opposite mode.  */
+static GTY(()) bool thumb_flipper;
+
 /* Options after initial target override.  */
 static GTY(()) tree init_optimize;
 
@@ -3329,6 +3338,9 @@
  options.  */
   target_option_default_node = target_option_current_node
 = build_target_option_node (global_options);
+
+  /* Init initial mode for testing.  */
+  thumb_flipper = TARGET_THUMB;
 }
 
 static void
@@ -29459,6 +29471,52 @@
   return build_target_option_node (opts);
 }
 
+static void 
+add_attribute  (const char * mode, tree *attributes)
+{
+  size_t len = strlen (mode);
+  tree value = build_string (len, mode);
+
+  TREE_TYPE (value) = build_array_type (char_type_node,
+	build_index_type (size_int (len)));
+
+  *attributes = tree_cons (get_identifier (target),
+			   build_tree_list (NULL_TREE, value),
+			   *attributes);
+}
+
+/* For testing. Insert thumb or arm modes alternatively on functions.  */
+
+static void
+arm_insert_attributes (tree fndecl, tree * attributes)
+{
+  const char *mode;
+
+  if (! TARGET_FLIP_THUMB)
+return;
+
+  if (TREE_CODE (fndecl) != FUNCTION_DECL || DECL_EXTERNAL(fndecl)
+  || DECL_BUILT_IN (fndecl) || DECL_ARTIFICIAL (fndecl))
+   return;
+
+  /* Nested definitions must inherit mode.  */
+  if (current_function_decl)
+   {
+ mode = TARGET_THUMB ? thumb : arm;  
+ add_attribute (mode, attributes);
+ return;
+   }
+
+  /* If there is already a setting don't change it.  */
+  if (lookup_attribute (target, *attributes) != NULL)
+return;
+
+  mode = thumb_flipper ? thumb : arm;
+  add_attribute (mode, attributes);
+
+  thumb_flipper = !thumb_flipper;
+}
+
 /* Hook to validate attribute((target(string))).  */
 
 static bool
@@ -29470,13 +29528,15 @@
   tree cur_tree, new_optimize;
   gcc_assert ((fndecl != NULL_TREE)  (args != NULL_TREE));
 
+  tree old_optimize = build_optimization_node (global_options);
+
   /* Get the optimization options of the current function.  */
   tree func_optimize = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl);
 
   /* If the function changed the optimization levels as well as setting target
  options, start with the optimizations specified.  */
   if (!func_optimize)
-func_optimize = optimization_default_node;
+func_optimize = old_optimize;
 
   /* Init func_options.  */
   memset (func_options, 0, sizeof (func_options));
@@ -29494,14 +29554,17 @@
   cur_tree = arm_valid_target_attribute_tree (args, func_options,
 	  global_options_set);
 
-  if (cur_tree == NULL_TREE)
-ret = false;
-
   new_optimize = build_optimization_node (func_options);
 
-  DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = cur_tree;
+  if (cur_tree == NULL_TREE)
+ret = false;
+  else
+{
+  DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = cur_tree;
 
-  DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl) = new_optimize;
+  if (old_optimize != new_optimize)
+	DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl) = new_optimize;
+}
 
   return ret;
 }
diff '--exclude=.svn' -ruN gnu_trunk.p5/gcc/gcc/config/arm/arm-c.c gnu_trunk.p6/gcc/gcc/config/arm/arm-c.c
--- gnu_trunk.p5/gcc/gcc/config/arm/arm-c.c	2015-05-06 14:36:21.987195830 +0200
+++ gnu_trunk.p6/gcc/gcc/config/arm/arm-c.c	2015-05-06 14:37:58.799362130 +0200
@@ -20,7 +20,6 @@
 #include system.h
 #include coretypes.h
 #include tm.h
-#include tm_p.h
 #include hash-set.h
 #include machmode.h
 #include vec.h
@@ -31,7 +30,11 

Re: [PATCH, ARM] attribute target (thumb,arm) [6/6] - [7/7]

2014-12-18 Thread Christian Bruel

Hello Ramana,

I don't know if you have started to look at it, but the attribute 
support fails after upgrading.


This patch aims to catch up on the changes around the fipa_ra 
-masm-syntax-unified options since the initial posting. They were not 
tested/supported with the attribute, and of course generated new 
failures after an update, as they needs resetting depending on thumb mode.


It also fixes various minor thinkos, one that prevented global flags 
(e.g -fschedule_insns) depending on thumb mode to be correctly reset on 
situation were -mthumb was passed on the command line and thumb/arm 
attribute was used alternatively. The other is around the -mflip-thumb 
option setting.


Last, a minor fix in the test attr_arm-err.c that had false failures 
with conflicting -march.


Aside, a funny thing: The ACLE doc 
(https://gcc.gnu.org/onlinedocs/gcc/ARM-C-Language-Extensions-_0028ACLE_0029.html#ARM-C-Language-Extensions-_0028ACLE_0029) 
already as a visionary description of the attribute. I might have missed 
something but this time the doc comes earlier than the implementation 
:-) without the historical background.


Best Regards

Christian

2014-12-14  Christian Bruel  christian.br...@st.com

	* config/arm/arm.c (arm_option_override_internal): add opts_set param. Use it to set 
	restrict_it. Handle flag_ipa_ra and inline_asm_unified.
	(arm_valid_target_attribute_tree): Add opts_set param.
	Initialize init_optimize.
	(init_optimize): New static variable.
	(thumb_flipper): Set.
	( arm_valid_target_attribute_p): Rewrite.
	config/arm/arm-protos.h	(arm_valid_target_attribute_tree): New opts_set param
	* config/arm/arm-c.c (arm_pragma_target_parse): Likewiese.
	* config/arm/arm.opt (inline_asm_unified): Save.

2014-12-14  Christian Bruel  christian.br...@st.com

* gcc.target/arm/attr_arm-err.c: Check conflicting -march options.

diff '--exclude=*~' '--exclude=.svn' -ru a/gcc/gcc/config/arm/arm.c b/gcc/gcc/config/arm/arm.c
--- a/gcc/gcc/config/arm/arm.c	2014-12-18 14:36:06.0 +0100
+++ b/gcc/gcc/config/arm/arm.c	2014-12-18 14:35:12.0 +0100
@@ -2625,9 +2625,16 @@
 }
 }
 
+/* True if -mflip-thumb should next add an attribute for the default
+   mode, false if it should next add an attribute for the opposite mode.  */
+static GTY(()) bool thumb_flipper;
+
+static GTY(()) tree init_optimize;
+
 /* Reset options between modes that the user has specified.  */
 static void
-arm_option_override_internal (struct gcc_options *opts)
+arm_option_override_internal (struct gcc_options *opts,
+			  struct gcc_options *opts_set)
 {
   if (TREE_TARGET_THUMB (opts)  !(insn_flags  FL_THUMB))
 {
@@ -2646,13 +2653,13 @@
   if (TREE_TARGET_THUMB (opts)  TARGET_CALLEE_INTERWORKING)
 opts-x_target_flags |= MASK_INTERWORK;
 
-  if (restrict_default)
+  if (! opts_set-x_arm_restrict_it)
 opts-x_arm_restrict_it = arm_arch8;
 
   if (!TREE_TARGET_THUMB2 (opts))
 opts-x_arm_restrict_it = 0;
 
-  if (TREE_TARGET_THUMB1 (opts)  opts-x_flag_schedule_insns)
+  if (TREE_TARGET_THUMB1 (opts))
 {
   /* Don't warn since it's on by default in -O2.  */
   opts-x_flag_schedule_insns = 0;
@@ -2663,9 +2670,21 @@
   if (optimize_function_for_size_p (cfun)  TREE_TARGET_THUMB2 (opts))
 opts-x_flag_shrink_wrap = false;
 
+  /* In Thumb1 mode, we emit the epilogue in RTL, but the last insn
+ - epilogue_insns - does not accurately model the corresponding insns
+ emitted in the asm file.  In particular, see the comment in thumb_exit
+ 'Find out how many of the (return) argument registers we can corrupt'.
+ As a consequence, the epilogue may clobber registers without fipa-ra
+ finding out about it.  Therefore, disable fipa-ra in Thumb1 mode.
+ TODO: Accurately model clobbers for epilogue_insns and reenable
+ fipa-ra.  */
+  if (TREE_TARGET_THUMB1 (opts))
+opts-x_flag_ipa_ra = 0;
+
   /* Thumb2 inline assembly code should always use unified syntax.
  This will apply to ARM and Thumb1 eventually.  */
-  opts-x_inline_asm_unified = TREE_TARGET_THUMB2 (opts);
+  if (TREE_TARGET_THUMB2 (opts))
+  opts-x_inline_asm_unified = 1;
 }
 
 /* Fix up any incompatible options that the user has specified.  */
@@ -3127,27 +3146,17 @@
   if (target_slow_flash_data)
 arm_disable_literal_pool = true;
 
-  /* Override flags, but not the user's one.  */
-  restrict_default = (arm_restrict_it == 2);
-
   /* Disable scheduling fusion by default if it's not armv7 processor
  or doesn't prefer ldrd/strd.  */
   if (flag_schedule_fusion == 2
(!arm_arch7 || !current_tune-prefer_ldrd_strd))
 flag_schedule_fusion = 0;
 
-  /* In Thumb1 mode, we emit the epilogue in RTL, but the last insn
- - epilogue_insns - does not accurately model the corresponding insns
- emitted in the asm file.  In particular, see the comment in thumb_exit
- 'Find out how many of the (return) argument registers we can corrupt'.
- As a consequence, the epilogue may clobber 

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

2014-11-19 Thread Christian Bruel
Implement the -mflip-thump option. Undocumented for internal testing 
only. This option artificially inserts alternative attribute thumb/modes 
on functions.


This close the patch set. Thanks for your review,

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

	* config/arm/arm.c (add_attribute, arm_insert_attributes): New functions
	(TARGET_INSERT_ATTRIBUTES): Define.
	(thumb_flipper): New var.
	* config/arm/arm.opt (-mflip-thumb): New switch.

diff '--exclude=ChangeLog*' '--exclude=.svn' '--exclude=*~' '--exclude=#*#' -rupN f/gcc/gcc/config/arm/arm.c g/gcc/gcc/config/arm/arm.c
--- f/gcc/gcc/config/arm/arm.c	2014-11-18 13:16:44.0 +0100
+++ g/gcc/gcc/config/arm/arm.c	2014-11-19 14:04:22.0 +0100
@@ -218,6 +218,7 @@ static void arm_encode_section_info (tre
 
 static void arm_file_end (void);
 static void arm_file_start (void);
+static void arm_insert_attributes (tree, tree *);
 
 static void arm_setup_incoming_varargs (cumulative_args_t, machine_mode,
 	tree, int *, int);
@@ -370,6 +371,9 @@ static const struct attribute_spec arm_a
 #undef  TARGET_ATTRIBUTE_TABLE
 #define TARGET_ATTRIBUTE_TABLE arm_attribute_table
 
+#undef  TARGET_INSERT_ATTRIBUTES
+#define TARGET_INSERT_ATTRIBUTES arm_insert_attributes
+
 #undef TARGET_ASM_FILE_START
 #define TARGET_ASM_FILE_START arm_file_start
 #undef TARGET_ASM_FILE_END
@@ -29403,6 +29407,56 @@ arm_valid_target_attribute_tree (tree ar
   return t;
 }
 
+/* True if -mflip-thumb should next add an attribute for the default
+   mode, false if it should next add an attribute for the opposite mode.  */
+static GTY(()) bool thumb_flipper = TARGET_THUMB;
+
+static void 
+add_attribute  (const char * mode, tree *attributes)
+{
+  size_t len = strlen (mode);
+  tree value = build_string (len, mode);
+
+  TREE_TYPE (value) = build_array_type (char_type_node,
+	build_index_type (size_int (len)));
+
+  *attributes = tree_cons (get_identifier (target),
+			   build_tree_list (NULL_TREE, value),
+			   *attributes);
+}
+
+/* For testing. Insert thumb or arm modes alternatively on functions.  */
+
+static void
+arm_insert_attributes (tree fndecl, tree * attributes)
+{
+  const char *mode;
+
+  if (TREE_CODE (fndecl) != FUNCTION_DECL || DECL_EXTERNAL(fndecl)
+  || DECL_BUILT_IN (fndecl) || DECL_ARTIFICIAL (fndecl))
+   return;
+
+  /* Nested definitions must inherit mode.  */
+  if (current_function_decl)
+   {
+ mode = TARGET_THUMB ? thumb : arm;  
+ add_attribute (mode, attributes);
+ return;
+   }
+
+  if (! TARGET_FLIP_THUMB)
+return;
+
+  /* If there is already a setting don't change it.  */
+  if (lookup_attribute (target, *attributes) != NULL)
+return;
+
+  mode = thumb_flipper ? thumb : arm;
+  add_attribute (mode, attributes);
+
+  thumb_flipper = !thumb_flipper;
+}
+
 /* Hook to validate attribute((target(string))).  */
 
 static bool
diff '--exclude=ChangeLog*' '--exclude=.svn' '--exclude=*~' '--exclude=#*#' -rupN f/gcc/gcc/config/arm/arm.opt g/gcc/gcc/config/arm/arm.opt
--- f/gcc/gcc/config/arm/arm.opt	2014-11-13 14:05:34.0 +0100
+++ g/gcc/gcc/config/arm/arm.opt	2014-11-19 13:59:46.0 +0100
@@ -122,6 +122,10 @@ Enum(float_abi_type) String(softfp) Valu
 EnumValue
 Enum(float_abi_type) String(hard) Value(ARM_FLOAT_ABI_HARD)
 
+mflip-thumb
+Target Report Var(TARGET_FLIP_THUMB)
+Switch ARM/Thumb modes on alternating functions for compiler testing
+
 mfp16-format=
 Target RejectNegative Joined Enum(arm_fp16_format_type) Var(arm_fp16_format) Init(ARM_FP16_FORMAT_NONE)
 Specify the __fp16 floating-point format