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.

Change-Id: Ifae73ffa2a07a595ed2a7f6ab7b82d8f51328a2a
---
 gcc/config/loongarch/loongarch-c.cc | 109 +++++++++++++++++-----------
 1 file changed, 66 insertions(+), 43 deletions(-)

diff --git a/gcc/config/loongarch/loongarch-c.cc 
b/gcc/config/loongarch/loongarch-c.cc
index 5d8c02e094b..9fe911325ab 100644
--- a/gcc/config/loongarch/loongarch-c.cc
+++ b/gcc/config/loongarch/loongarch-c.cc
@@ -31,13 +31,21 @@ 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)
+{
+  if (def_p)
+    cpp_define (pfile, macro);
+  else
+    cpp_undef (pfile, macro);
+}
+
+static void
+loongarch_define_unconditional_macros (cpp_reader *pfile)
 {
-  builtin_assert ("machine=loongarch");
-  builtin_assert ("cpu=loongarch");
   builtin_define ("__loongarch__");
 
   builtin_define_with_value ("__loongarch_arch",
@@ -66,45 +74,6 @@ loongarch_cpu_cpp_builtins (cpp_reader *pfile)
       builtin_define ("__loongarch_lp64");
     }
 
-  /* These defines reflect the ABI in use, not whether the
-     FPU is directly accessible.  */
-  if (TARGET_DOUBLE_FLOAT_ABI)
-    builtin_define ("__loongarch_double_float=1");
-  else if (TARGET_SINGLE_FLOAT_ABI)
-    builtin_define ("__loongarch_single_float=1");
-
-  if (TARGET_DOUBLE_FLOAT_ABI || TARGET_SINGLE_FLOAT_ABI)
-    builtin_define ("__loongarch_hard_float=1");
-  else
-    builtin_define ("__loongarch_soft_float=1");
-
-
-  /* ISA Extensions.  */
-  if (TARGET_DOUBLE_FLOAT)
-    builtin_define ("__loongarch_frlen=64");
-  else if (TARGET_SINGLE_FLOAT)
-    builtin_define ("__loongarch_frlen=32");
-  else
-    builtin_define ("__loongarch_frlen=0");
-
-  if (TARGET_HARD_FLOAT && ISA_HAS_FRECIPE)
-    builtin_define ("__loongarch_frecipe");
-
-  if (ISA_HAS_LSX)
-    {
-      builtin_define ("__loongarch_simd");
-      builtin_define ("__loongarch_sx");
-
-      if (!ISA_HAS_LASX)
-       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;
 
@@ -145,7 +114,61 @@ loongarch_cpu_cpp_builtins (cpp_reader *pfile)
   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)
+{
+  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)
+    builtin_define ("__loongarch_double_float=1");
+  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
+    builtin_define ("__loongarch_soft_float=1");
+
+
+  /* ISA Extensions.  */
+  if (TARGET_DOUBLE_FLOAT)
+    builtin_define ("__loongarch_frlen=64");
+  else if (TARGET_SINGLE_FLOAT)
+    builtin_define ("__loongarch_frlen=32");
+  else
+    builtin_define ("__loongarch_frlen=0");
+
+  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)
+    {
+      if (ISA_HAS_LASX)
+       builtin_define ("__loongarch_simd_width=256");
+      else
+       builtin_define ("__loongarch_simd_width=128");
+    }
+}
+
+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
-- 
2.34.1

Reply via email to