On Tue, 2025-02-11 at 20:49 +0800, Lulu Cheng wrote: > 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;
I guess the handling for la_evo_macro_name macros (like __loongarch_div32) and __loongarch_version_major/__loongarch_version_minor should be moved as well? Things like #pragma GCC target("arch=la664") may affect them. -- Xi Ruoyao <xry...@xry111.site> School of Aerospace Science and Technology, Xidian University