This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


In preparation of the pragma target

reorganize ÂTARGET_CPU_CPP_BUILTINSÂ to redefine mode dependent macros based on current thumb_p.

Thanks,

Christian
2014-09-23  Christian Bruel  <christian.bruel@st.com>

	* config/arm/arm-c.c (cpp_def_or_undef): New functions.
	(arm_cpp_builtins): Likewise.
	* config/arm/arm.h (TARGET_CPU_CPP_BUILTINS): Move mode dependant 
	macros to arm_cpp_builtins.
	* config/arm/arm-protos.h (arm_cpp_builtins): Declare.

diff '--exclude=ChangeLog*' '--exclude=.svn' '--exclude=*~' '--exclude=#*#' -rupN b/gcc/gcc/config/arm/arm-c.c c/gcc/gcc/config/arm/arm-c.c
--- b/gcc/gcc/config/arm/arm-c.c	2014-11-05 14:34:49.000000000 +0100
+++ c/gcc/gcc/config/arm/arm-c.c	2014-11-13 11:16:59.000000000 +0100
@@ -42,3 +42,73 @@ arm_lang_object_attributes_init (void)
 {
   arm_lang_output_object_attributes_hook = arm_output_c_attributes;
 }
+
+/* Define or undefine macro.  */
+
+static void
+cpp_def_or_undef (struct cpp_reader *in, const char *str, bool def_p)
+{
+  if (def_p)
+    cpp_define (in, str);
+  else
+    cpp_undef (in, str);
+}
+
+/* Define or undefine macros based on the current target.  If the user does
+   #pragma GCC target, we need to adjust the macros dynamically.  */
+
+void
+arm_cpp_builtins (struct cpp_reader *in, bool thumb_p)
+{
+  bool target_32bit_p = !thumb_p || arm_arch_thumb2;
+  bool thumb2_p = thumb_p && arm_arch_thumb2;
+  bool have_ldrex_p = (arm_arch6 && !thumb_p) || arm_arch7;
+  bool have_ldrexbh_p = (arm_arch6k && !thumb_p) || arm_arch7;
+  bool have_ldrexd_p = ((arm_arch6k && !thumb_p) || arm_arch7)
+    && arm_arch_notm;
+
+  int arm_feature_ldrex = (have_ldrex_p ? 4 : 0)
+    | (have_ldrexbh_p ? 3 : 0) | (have_ldrexd_p ? 8 : 0);
+
+  cpp_def_or_undef (in, "__thumb__", thumb_p);
+  if (arm_arch_thumb2)
+    cpp_def_or_undef (in, "__thumb2__", thumb_p);
+  if (TARGET_BIG_END)
+    cpp_def_or_undef (in, "__THUMBEB__", thumb_p);
+  else
+    cpp_def_or_undef (in, "__THUMBEL__", thumb_p);
+
+  cpp_def_or_undef (in, "__ARM_32BIT_STATE", target_32bit_p); /* TARGET_32BIT  */
+
+  if (arm_arch5e && (arm_arch_notm || arm_arch7))   /* TARGET_ARM_QBIT  */
+    cpp_def_or_undef (in, "__ARM_FEATURE_QBIT", target_32bit_p);
+
+  if (arm_arch6 && (arm_arch_notm || arm_arch7))    /* TARGET_ARM_SAT  */
+    cpp_def_or_undef (in, "__ARM_FEATURE_SAT", target_32bit_p);
+
+  if (arm_arch5e && (arm_arch_notm || arm_arch7em)) /* TARGET_DSP_MULTIPLY  */
+    cpp_def_or_undef (in, "__ARM_FEATURE_DSP", target_32bit_p);
+
+  if (arm_arch6 && (arm_arch_notm || arm_arch7em))  /* TARGET_INT_SIMD  */
+    cpp_def_or_undef (in, "__ARM_FEATURE_SIMD32", target_32bit_p);
+
+ /* TARGET_IDIV  */
+  cpp_def_or_undef (in, "__ARM_ARCH_EXT_IDIV__",
+		    ((!thumb_p && arm_arch_arm_hwdiv)
+		     || (thumb2_p && arm_arch_thumb_hwdiv)));
+
+  cpp_def_or_undef (in, "__ARM_FEATURE_IDIV",
+		    ((!thumb_p && arm_arch_arm_hwdiv)
+		     || (thumb2_p && arm_arch_thumb_hwdiv)));
+
+ if (arm_feature_ldrex)
+   cpp_define_formatted (in, "__ARM_FEATURE_LDREX=%d", arm_feature_ldrex);
+ else
+   cpp_undef (in, "__ARM_FEATURE_LDREX");
+
+ cpp_def_or_undef (in, "__ARM_FEATURE_CLZ",
+		   ((TARGET_ARM_ARCH >= 5 && !thumb_p) || TARGET_ARM_ARCH_ISA_THUMB >=2));
+
+ cpp_def_or_undef (in, "__ARM_ASM_SYNTAX_UNIFIED__", inline_asm_unified);
+}
+
diff '--exclude=ChangeLog*' '--exclude=.svn' '--exclude=*~' '--exclude=#*#' -rupN b/gcc/gcc/config/arm/arm.h c/gcc/gcc/config/arm/arm.h
--- b/gcc/gcc/config/arm/arm.h	2014-11-13 12:16:50.000000000 +0100
+++ c/gcc/gcc/config/arm/arm.h	2014-11-13 12:16:37.000000000 +0100
@@ -48,29 +48,12 @@ extern char arm_arch_name[];
 #define TARGET_CPU_CPP_BUILTINS()			\
   do							\
     {							\
-	if (TARGET_DSP_MULTIPLY)			\
-	   builtin_define ("__ARM_FEATURE_DSP");	\
-        if (TARGET_ARM_QBIT)				\
-           builtin_define ("__ARM_FEATURE_QBIT");	\
-        if (TARGET_ARM_SAT)				\
-           builtin_define ("__ARM_FEATURE_SAT");	\
         if (TARGET_CRYPTO)				\
 	   builtin_define ("__ARM_FEATURE_CRYPTO");	\
 	if (unaligned_access)				\
 	  builtin_define ("__ARM_FEATURE_UNALIGNED");	\
 	if (TARGET_CRC32)				\
 	  builtin_define ("__ARM_FEATURE_CRC32");	\
-	if (TARGET_32BIT)				\
-	  builtin_define ("__ARM_32BIT_STATE");		\
-	if (TARGET_ARM_FEATURE_LDREX)				\
-	  builtin_define_with_int_value (			\
-	    "__ARM_FEATURE_LDREX", TARGET_ARM_FEATURE_LDREX);	\
-	if ((TARGET_ARM_ARCH >= 5 && !TARGET_THUMB)		\
-	     || TARGET_ARM_ARCH_ISA_THUMB >=2)			\
-	  builtin_define ("__ARM_FEATURE_CLZ");			\
-	if (TARGET_INT_SIMD)					\
-	  builtin_define ("__ARM_FEATURE_SIMD32");		\
-								\
 	builtin_define_with_int_value (				\
 	  "__ARM_SIZEOF_MINIMAL_ENUM",				\
 	  flag_short_enums ? 1 : 4);				\
@@ -89,10 +72,6 @@ extern char arm_arch_name[];
 	if (arm_arch_notm)				\
 	  builtin_define ("__ARM_ARCH_ISA_ARM");	\
 	builtin_define ("__APCS_32__");			\
-	if (TARGET_THUMB)				\
-	  builtin_define ("__thumb__");			\
-	if (TARGET_THUMB2)				\
-	  builtin_define ("__thumb2__");		\
 	if (TARGET_ARM_ARCH_ISA_THUMB)			\
 	  builtin_define_with_int_value (		\
 	    "__ARM_ARCH_ISA_THUMB",			\
@@ -102,15 +81,9 @@ extern char arm_arch_name[];
 	  {						\
 	    builtin_define ("__ARMEB__");		\
 	    builtin_define ("__ARM_BIG_ENDIAN");	\
-	    if (TARGET_THUMB)				\
-	      builtin_define ("__THUMBEB__");		\
 	  }						\
         else						\
-	  {						\
 	    builtin_define ("__ARMEL__");		\
-	    if (TARGET_THUMB)				\
-	      builtin_define ("__THUMBEL__");		\
-	  }						\
 							\
 	if (TARGET_SOFT_FLOAT)				\
 	  builtin_define ("__SOFTFP__");		\
@@ -163,13 +136,8 @@ extern char arm_arch_name[];
 	      builtin_define ("__ARM_PCS");		\
 	    builtin_define ("__ARM_EABI__");		\
 	  }						\
-	if (TARGET_IDIV)				\
-         {						\
-            builtin_define ("__ARM_ARCH_EXT_IDIV__");	\
-            builtin_define ("__ARM_FEATURE_IDIV");	\
-         }						\
-	if (inline_asm_unified)				\
-	  builtin_define ("__ARM_ASM_SYNTAX_UNIFIED__");\
+	/* Remaining macros depends on TARGET_THUMB.  */\
+        arm_cpp_builtins (pfile, TARGET_THUMB);		\
     } while (0)
 
 #include "config/arm/arm-opts.h"
diff '--exclude=ChangeLog*' '--exclude=.svn' '--exclude=*~' '--exclude=#*#' -rupN b/gcc/gcc/config/arm/arm-protos.h c/gcc/gcc/config/arm/arm-protos.h
--- b/gcc/gcc/config/arm/arm-protos.h	2014-11-05 14:34:49.000000000 +0100
+++ c/gcc/gcc/config/arm/arm-protos.h	2014-11-13 11:16:17.000000000 +0100
@@ -215,8 +215,6 @@ extern void arm_pr_long_calls (struct cp
 extern void arm_pr_no_long_calls (struct cpp_reader *);
 extern void arm_pr_long_calls_off (struct cpp_reader *);
 
-extern void arm_lang_object_attributes_init(void);
-
 extern const char *arm_mangle_type (const_tree);
 
 extern void arm_order_regs_for_local_alloc (void);
@@ -304,6 +302,10 @@ extern void arm_emit_eabi_attribute (con
 /* Defined in gcc/common/config/arm-common.c.  */
 extern const char *arm_rewrite_selected_cpu (const char *name);
 
+/* Defined in gcc/common/config/arm-c.c.  */
+extern void arm_lang_object_attributes_init(void);
+extern void arm_cpp_builtins (struct cpp_reader *, bool);
+
 extern bool arm_is_constant_pool_ref (rtx);
 
 #endif /* ! GCC_ARM_PROTOS_H */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]