aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorLulu Cheng <chenglulu@loongson.cn>2025-02-11 20:05:13 +0800
committerLulu Cheng <chenglulu@loongson.cn>2025-02-14 15:48:37 +0800
commitc1af05f3d0320b5af98f27a76abfc9263bd42bb8 (patch)
tree17f5d61b7ce25f745995530157f03176cd2bcfa4 /gcc
parent46ce50b44e3d06f103c9136bc052a7354e07cfca (diff)
downloadgcc-c1af05f3d0320b5af98f27a76abfc9263bd42bb8.zip
gcc-c1af05f3d0320b5af98f27a76abfc9263bd42bb8.tar.gz
gcc-c1af05f3d0320b5af98f27a76abfc9263bd42bb8.tar.bz2
LoongArch: Split the function loongarch_cpu_cpp_builtins into two functions.
Split the implementation of the function loongarch_cpu_cpp_builtins into two parts: 1. Macro definitions that do not change (only considering 64-bit architecture) 2. Macro definitions that change with different compilation options. gcc/ChangeLog: * config/loongarch/loongarch-c.cc (builtin_undef): New macro. (loongarch_cpu_cpp_builtins): Split to loongarch_update_cpp_builtins and loongarch_define_unconditional_macros. (loongarch_def_or_undef): New functions. (loongarch_define_unconditional_macros): Likewise. (loongarch_update_cpp_builtins): Likewise.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/config/loongarch/loongarch-c.cc122
1 files changed, 77 insertions, 45 deletions
diff --git a/gcc/config/loongarch/loongarch-c.cc b/gcc/config/loongarch/loongarch-c.cc
index 5d8c02e..9a8de1e 100644
--- a/gcc/config/loongarch/loongarch-c.cc
+++ b/gcc/config/loongarch/loongarch-c.cc
@@ -31,26 +31,22 @@ along with GCC; see the file COPYING3. If not see
#define preprocessing_asm_p() (cpp_get_options (pfile)->lang == CLK_ASM)
#define builtin_define(TXT) cpp_define (pfile, TXT)
+#define builtin_undef(TXT) cpp_undef (pfile, TXT)
#define builtin_assert(TXT) cpp_assert (pfile, TXT)
-void
-loongarch_cpu_cpp_builtins (cpp_reader *pfile)
+static void
+loongarch_def_or_undef (bool def_p, const char *macro, cpp_reader *pfile)
{
- builtin_assert ("machine=loongarch");
- builtin_assert ("cpu=loongarch");
- builtin_define ("__loongarch__");
-
- builtin_define_with_value ("__loongarch_arch",
- loongarch_arch_strings[la_target.cpu_arch], 1);
-
- builtin_define_with_value ("__loongarch_tune",
- loongarch_tune_strings[la_target.cpu_tune], 1);
-
- builtin_define_with_value ("_LOONGARCH_ARCH",
- loongarch_arch_strings[la_target.cpu_arch], 1);
+ if (def_p)
+ cpp_define (pfile, macro);
+ else
+ cpp_undef (pfile, macro);
+}
- builtin_define_with_value ("_LOONGARCH_TUNE",
- loongarch_tune_strings[la_target.cpu_tune], 1);
+static void
+loongarch_define_unconditional_macros (cpp_reader *pfile)
+{
+ builtin_define ("__loongarch__");
/* Base architecture / ABI. */
if (TARGET_64BIT)
@@ -66,6 +62,48 @@ loongarch_cpu_cpp_builtins (cpp_reader *pfile)
builtin_define ("__loongarch_lp64");
}
+ /* Add support for FLOAT128_TYPE on the LoongArch architecture. */
+ builtin_define ("__FLOAT128_TYPE__");
+
+ /* Map the old _Float128 'q' builtins into the new 'f128' builtins. */
+ builtin_define ("__builtin_fabsq=__builtin_fabsf128");
+ builtin_define ("__builtin_copysignq=__builtin_copysignf128");
+ builtin_define ("__builtin_nanq=__builtin_nanf128");
+ builtin_define ("__builtin_nansq=__builtin_nansf128");
+ builtin_define ("__builtin_infq=__builtin_inff128");
+ builtin_define ("__builtin_huge_valq=__builtin_huge_valf128");
+
+ /* Native Data Sizes. */
+ builtin_define_with_int_value ("_LOONGARCH_SZINT", INT_TYPE_SIZE);
+ builtin_define_with_int_value ("_LOONGARCH_SZLONG", LONG_TYPE_SIZE);
+ builtin_define_with_int_value ("_LOONGARCH_SZPTR", POINTER_SIZE);
+ builtin_define_with_int_value ("_LOONGARCH_FPSET", 32);
+ builtin_define_with_int_value ("_LOONGARCH_SPFPSET", 32);
+}
+
+static void
+loongarch_update_cpp_builtins (cpp_reader *pfile)
+{
+ /* Since the macros in this function might be redefined, it's necessary to
+ undef them first.*/
+ builtin_undef ("__loongarch_arch");
+ builtin_define_with_value ("__loongarch_arch",
+ loongarch_arch_strings[la_target.cpu_arch], 1);
+
+ builtin_undef ("__loongarch_tune");
+ builtin_define_with_value ("__loongarch_tune",
+ loongarch_tune_strings[la_target.cpu_tune], 1);
+
+ builtin_undef ("_LOONGARCH_ARCH");
+ builtin_define_with_value ("_LOONGARCH_ARCH",
+ loongarch_arch_strings[la_target.cpu_arch], 1);
+
+ builtin_undef ("_LOONGARCH_TUNE");
+ builtin_define_with_value ("_LOONGARCH_TUNE",
+ loongarch_tune_strings[la_target.cpu_tune], 1);
+
+ builtin_undef ("__loongarch_double_float");
+ builtin_undef ("__loongarch_single_float");
/* These defines reflect the ABI in use, not whether the
FPU is directly accessible. */
if (TARGET_DOUBLE_FLOAT_ABI)
@@ -73,6 +111,8 @@ loongarch_cpu_cpp_builtins (cpp_reader *pfile)
else if (TARGET_SINGLE_FLOAT_ABI)
builtin_define ("__loongarch_single_float=1");
+ builtin_undef ("__loongarch_soft_float");
+ builtin_undef ("__loongarch_hard_float");
if (TARGET_DOUBLE_FLOAT_ABI || TARGET_SINGLE_FLOAT_ABI)
builtin_define ("__loongarch_hard_float=1");
else
@@ -80,6 +120,7 @@ loongarch_cpu_cpp_builtins (cpp_reader *pfile)
/* ISA Extensions. */
+ builtin_undef ("__loongarch_frlen");
if (TARGET_DOUBLE_FLOAT)
builtin_define ("__loongarch_frlen=64");
else if (TARGET_SINGLE_FLOAT)
@@ -87,24 +128,22 @@ loongarch_cpu_cpp_builtins (cpp_reader *pfile)
else
builtin_define ("__loongarch_frlen=0");
- if (TARGET_HARD_FLOAT && ISA_HAS_FRECIPE)
- builtin_define ("__loongarch_frecipe");
+ loongarch_def_or_undef (TARGET_HARD_FLOAT && ISA_HAS_FRECIPE,
+ "__loongarch_frecipe", pfile);
+
+ loongarch_def_or_undef (ISA_HAS_LSX, "__loongarch_simd", pfile);
+ loongarch_def_or_undef (ISA_HAS_LSX, "__loongarch_sx", pfile);
+ loongarch_def_or_undef (ISA_HAS_LASX, "__loongarch_asx", pfile);
+ builtin_undef ("__loongarch_simd_width");
if (ISA_HAS_LSX)
{
- builtin_define ("__loongarch_simd");
- builtin_define ("__loongarch_sx");
-
- if (!ISA_HAS_LASX)
+ if (ISA_HAS_LASX)
+ builtin_define ("__loongarch_simd_width=256");
+ else
builtin_define ("__loongarch_simd_width=128");
}
- if (ISA_HAS_LASX)
- {
- builtin_define ("__loongarch_asx");
- builtin_define ("__loongarch_simd_width=256");
- }
-
/* ISA evolution features */
int max_v_major = 1, max_v_minor = 0;
@@ -122,30 +161,23 @@ loongarch_cpu_cpp_builtins (cpp_reader *pfile)
}
/* Find the minimum ISA version required to run the target program. */
+ builtin_undef ("__loongarch_version_major");
+ builtin_undef ("__loongarch_version_minor");
if (!(max_v_major == 1 && max_v_minor <= 1 && ISA_HAS_LASX))
{
builtin_define_with_int_value ("__loongarch_version_major", max_v_major);
builtin_define_with_int_value ("__loongarch_version_minor", max_v_minor);
}
+}
- /* Add support for FLOAT128_TYPE on the LoongArch architecture. */
- builtin_define ("__FLOAT128_TYPE__");
-
- /* Map the old _Float128 'q' builtins into the new 'f128' builtins. */
- builtin_define ("__builtin_fabsq=__builtin_fabsf128");
- builtin_define ("__builtin_copysignq=__builtin_copysignf128");
- builtin_define ("__builtin_nanq=__builtin_nanf128");
- builtin_define ("__builtin_nansq=__builtin_nansf128");
- builtin_define ("__builtin_infq=__builtin_inff128");
- builtin_define ("__builtin_huge_valq=__builtin_huge_valf128");
-
- /* Native Data Sizes. */
- builtin_define_with_int_value ("_LOONGARCH_SZINT", INT_TYPE_SIZE);
- builtin_define_with_int_value ("_LOONGARCH_SZLONG", LONG_TYPE_SIZE);
- builtin_define_with_int_value ("_LOONGARCH_SZPTR", POINTER_SIZE);
- builtin_define_with_int_value ("_LOONGARCH_FPSET", 32);
- builtin_define_with_int_value ("_LOONGARCH_SPFPSET", 32);
+void
+loongarch_cpu_cpp_builtins (cpp_reader *pfile)
+{
+ builtin_assert ("machine=loongarch");
+ builtin_assert ("cpu=loongarch");
+ loongarch_define_unconditional_macros (pfile);
+ loongarch_update_cpp_builtins (pfile);
}
/* Hook to validate the current #pragma GCC target and set the state, and