This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] [ARC] New CPU C-define handler.
- From: Claudiu Zissulescu <Claudiu dot Zissulescu at synopsys dot com>
- To: <gcc-patches at gcc dot gnu dot org>
- Cc: <Claudiu dot Zissulescu at synopsys dot com>, <gnu at amylaar dot uk>, <Francois dot Bedard at synopsys dot com>
- Date: Thu, 19 May 2016 13:57:44 +0200
- Subject: [PATCH] [ARC] New CPU C-define handler.
- Authentication-results: sourceware.org; auth=none
This patch refactors how we handle the built-in preprocessor macros and assertions for ARC.
OK to apply?
Claudiu
gcc/
2016-05-02 Claudiu Zissulescu <claziss@synopsys.com>
* config/arc/arc-c.c: New file.
* config/arc/arc-c.def: Likewise.
* config/arc/t-arc: Likewise.
* config.gcc: Include arc-c.o as c and cpp object.
* config/arc/arc-protos.h (arc_cpu_cpp_builtins): Add prototype.
* config/arc/arc.h (TARGET_CPU_CPP_BUILTINS): Use
arc_cpu_cpp_builtins.
---
gcc/config.gcc | 2 ++
gcc/config/arc/arc-c.c | 69 +++++++++++++++++++++++++++++++++++++++++++++
gcc/config/arc/arc-c.def | 68 ++++++++++++++++++++++++++++++++++++++++++++
gcc/config/arc/arc-protos.h | 1 +
gcc/config/arc/arc.h | 56 +-----------------------------------
gcc/config/arc/t-arc | 29 +++++++++++++++++++
6 files changed, 170 insertions(+), 55 deletions(-)
create mode 100644 gcc/config/arc/arc-c.c
create mode 100644 gcc/config/arc/arc-c.def
create mode 100644 gcc/config/arc/t-arc
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 4e98df7..148e020 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -323,6 +323,8 @@ am33_2.0-*-linux*)
;;
arc*-*-*)
cpu_type=arc
+ c_target_objs="arc-c.o"
+ cxx_target_objs="arc-c.o"
;;
arm*-*-*)
cpu_type=arm
diff --git a/gcc/config/arc/arc-c.c b/gcc/config/arc/arc-c.c
new file mode 100644
index 0000000..3bf3fd2
--- /dev/null
+++ b/gcc/config/arc/arc-c.c
@@ -0,0 +1,69 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+
+ This file is part of GCC.
+
+ GCC is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ GCC is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GCC; see the file COPYING3. If not see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "tree.h"
+#include "tm_p.h"
+#include "cpplib.h"
+#include "c-family/c-common.h"
+#include "target.h"
+
+#define builtin_define(TXT) cpp_define (pfile, TXT)
+#define builtin_assert(TXT) cpp_assert (pfile, TXT)
+
+/* Define or undefine macros based on the current target. */
+
+static void
+def_or_undef_macro (cpp_reader* pfile, const char *name, bool def_p)
+{
+ if (def_p)
+ cpp_define (pfile, name);
+ else
+ cpp_undef (pfile, name);
+}
+
+/* Helper for TARGET_CPU_CPP_BUILTINS hook. */
+
+void
+arc_cpu_cpp_builtins (cpp_reader * pfile)
+{
+ builtin_assert ("cpu=arc");
+ builtin_assert ("machine=arc");
+
+ builtin_define ("__arc__");
+
+#undef ARC_C_DEF
+#define ARC_C_DEF(NAME, CONDITION) \
+ def_or_undef_macro (pfile, NAME, CONDITION);
+
+#include "arc-c.def"
+#undef ARC_C_DEF
+
+ builtin_define_with_int_value ("__ARC_TLS_REGNO__",
+ arc_tp_regno);
+
+ builtin_define (TARGET_BIG_ENDIAN
+ ? "__BIG_ENDIAN__" : "__LITTLE_ENDIAN__");
+ if (TARGET_BIG_ENDIAN)
+ builtin_define ("__big_endian__");
+
+}
diff --git a/gcc/config/arc/arc-c.def b/gcc/config/arc/arc-c.def
new file mode 100644
index 0000000..88c65ac
--- /dev/null
+++ b/gcc/config/arc/arc-c.def
@@ -0,0 +1,68 @@
+/* Copyright (C) 2016 Free Software Foundation, Inc.
+
+ This file is part of GCC.
+
+ GCC is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ GCC is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GCC; see the file COPYING3. If not see
+ <http://www.gnu.org/licenses/>.
+*/
+
+ARC_C_DEF ("__ARC600__", TARGET_ARC600)
+ARC_C_DEF ("__ARC601__", TARGET_ARC601)
+ARC_C_DEF ("__ARC700__", TARGET_ARC700)
+ARC_C_DEF ("__ARCEM__", TARGET_EM)
+ARC_C_DEF ("__ARCHS__", TARGET_HS)
+ARC_C_DEF ("__ARC_ATOMIC__", TARGET_ATOMIC)
+ARC_C_DEF ("__ARC_NORM__", TARGET_NORM)
+ARC_C_DEF ("__ARC_MUL64__", TARGET_MUL64_SET)
+ARC_C_DEF ("__ARC_MUL32BY16__", TARGET_MULMAC_32BY16_SET)
+ARC_C_DEF ("__ARC_SIMD__", TARGET_SIMD_SET)
+
+ARC_C_DEF ("__ARC_BARREL_SHIFTER__", TARGET_BARREL_SHIFTER)
+
+ARC_C_DEF ("__ARC_LL64__", TARGET_LL64)
+ARC_C_DEF ("__ARC_MPY__", !TARGET_NOMPY_SET)
+ARC_C_DEF ("__ARC_SWAP__", TARGET_SWAP)
+ARC_C_DEF ("__ARC_EA__", TARGET_EA_SET)
+ARC_C_DEF ("__ARC_FPX_SP__", (TARGET_SPFP_FAST_SET || TARGET_SPFP_COMPACT_SET))
+ARC_C_DEF ("__ARC_FPX_DP__", (TARGET_DPFP_FAST_SET || TARGET_DPFP_COMPACT_SET))
+ARC_C_DEF ("__ARC_MULT32__", TARGET_MUL64_SET)
+ARC_C_DEF ("__ARC_DIVREM__", TARGET_DIVREM)
+
+ARC_C_DEF ("__ARC_CODE_DENSITY__", TARGET_CODE_DENSITY)
+
+ARC_C_DEF ("__ARC_MPY_WLHX__", (arc_mpy_option >= 2))
+ARC_C_DEF ("__ARC_MPY_WLH1__", (arc_mpy_option == 2))
+ARC_C_DEF ("__ARC_MPY_WLH2__", (arc_mpy_option == 3))
+ARC_C_DEF ("__ARC_MPY_WLH3__", (arc_mpy_option == 4))
+ARC_C_DEF ("__ARC_MPY_WLH4__", (arc_mpy_option == 5))
+ARC_C_DEF ("__ARC_MPY_WLH5__", (arc_mpy_option == 6))
+ARC_C_DEF ("__ARC_MPY_DMPY__", (arc_mpy_option == 7))
+ARC_C_DEF ("__ARC_MPY_MACD__", (arc_mpy_option == 8))
+ARC_C_DEF ("__ARC_MPY_QMACW__", (arc_mpy_option == 9))
+
+ARC_C_DEF ("__ARC_FPU_SP__", TARGET_FP_SP_BASE)
+ARC_C_DEF ("__ARC_FPU_DP__", TARGET_FP_DP_BASE)
+ARC_C_DEF ("__ARC_FPU_SP_DIV__", TARGET_FP_SP_SQRT)
+ARC_C_DEF ("__ARC_FPU_DP_DIV__", TARGET_FP_DP_SQRT)
+ARC_C_DEF ("__ARC_FPU_SP_FMA__", TARGET_FP_SP_FUSED)
+ARC_C_DEF ("__ARC_FPU_DP_FMA__", TARGET_FP_DP_FUSED)
+ARC_C_DEF ("__ARC_FPU_ASSIST__", TARGET_FP_DP_AX)
+
+/* To be deprecated. */
+ARC_C_DEF ("__A6__", TARGET_ARC600)
+ARC_C_DEF ("__A7__", TARGET_ARC700)
+ARC_C_DEF ("__EM__", TARGET_EM)
+ARC_C_DEF ("__HS__", TARGET_HS)
+ARC_C_DEF ("__Xnorm", TARGET_NORM)
+ARC_C_DEF ("__Xbarrel_shifter", TARGET_BARREL_SHIFTER)
diff --git a/gcc/config/arc/arc-protos.h b/gcc/config/arc/arc-protos.h
index 8630e2d..b6ed392 100644
--- a/gcc/config/arc/arc-protos.h
+++ b/gcc/config/arc/arc-protos.h
@@ -123,3 +123,4 @@ extern int arc_return_slot_offset (void);
extern bool arc_legitimize_reload_address (rtx *, machine_mode, int, int);
extern void arc_secondary_reload_conv (rtx, rtx, rtx, bool);
extern bool insn_is_tls_gd_dispatch (rtx_insn *);
+extern void arc_cpu_cpp_builtins (cpp_reader *);
diff --git a/gcc/config/arc/arc.h b/gcc/config/arc/arc.h
index f6b85ea..c02e1cd 100644
--- a/gcc/config/arc/arc.h
+++ b/gcc/config/arc/arc.h
@@ -64,61 +64,7 @@ along with GCC; see the file COPYING3. If not see
#undef CC1_SPEC
/* Names to predefine in the preprocessor for this target machine. */
-#define TARGET_CPU_CPP_BUILTINS() \
- do { \
- builtin_define ("__arc__"); \
- if (TARGET_ARC600) \
- { \
- builtin_define ("__A6__"); \
- builtin_define ("__ARC600__"); \
- } \
- else if (TARGET_ARC601) \
- { \
- builtin_define ("__ARC601__"); \
- } \
- else if (TARGET_ARC700) \
- { \
- builtin_define ("__A7__"); \
- builtin_define ("__ARC700__"); \
- } \
- else if (TARGET_EM) \
- { \
- builtin_define ("__EM__"); \
- } \
- else if (TARGET_HS) \
- { \
- builtin_define ("__HS__"); \
- } \
- if (TARGET_ATOMIC) \
- { \
- builtin_define ("__ARC_ATOMIC__"); \
- } \
- if (TARGET_NORM) \
- { \
- builtin_define ("__ARC_NORM__");\
- builtin_define ("__Xnorm"); \
- } \
- if (TARGET_LL64) \
- { \
- builtin_define ("__ARC_LL64__");\
- } \
- if (TARGET_MUL64_SET) \
- builtin_define ("__ARC_MUL64__");\
- if (TARGET_MULMAC_32BY16_SET) \
- builtin_define ("__ARC_MUL32BY16__");\
- if (TARGET_SIMD_SET) \
- builtin_define ("__ARC_SIMD__"); \
- if (TARGET_BARREL_SHIFTER) \
- builtin_define ("__Xbarrel_shifter");\
- builtin_define_with_int_value ("__ARC_TLS_REGNO__", \
- arc_tp_regno); \
- builtin_assert ("cpu=arc"); \
- builtin_assert ("machine=arc"); \
- builtin_define (TARGET_BIG_ENDIAN \
- ? "__BIG_ENDIAN__" : "__LITTLE_ENDIAN__"); \
- if (TARGET_BIG_ENDIAN) \
- builtin_define ("__big_endian__"); \
-} while(0)
+#define TARGET_CPU_CPP_BUILTINS() arc_cpu_cpp_builtins (pfile)
#if DEFAULT_LIBC == LIBC_UCLIBC
diff --git a/gcc/config/arc/t-arc b/gcc/config/arc/t-arc
new file mode 100644
index 0000000..4252e73
--- /dev/null
+++ b/gcc/config/arc/t-arc
@@ -0,0 +1,29 @@
+# GCC Makefile fragment for Synopsys DesignWare ARC.
+#
+# Copyright (C) 2016 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 3, or (at your option) any later version.
+#
+# GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along
+# with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+TM_H += $(srcdir)/config/arc/arc-c.def
+
+arc-c.o: $(srcdir)/config/arc/arc-c.c $(CONFIG_H) $(SYSTEM_H) \
+$(TREE_H) $(TM_H) $(TM_P_H) coretypes.h
+ $(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
+ $(srcdir)/config/arc/arc-c.c
+
+# Local Variables:
+# mode: Makefile
+# End:
--
1.9.1