On Sun, 2025-10-19 at 10:31 +0800, Lulu Cheng wrote:
> Supported options:
> -mfrecipe -mdiv32 -mlam-bh -mlamcas -mscq -mld-seq-sa.
>
> gcc/ChangeLog:
>
> * config/loongarch/loongarch-target-attr.cc
> (struct loongarch_attribute_info): Add options, and generate
> the structure through macro definition.
> (LARCH_ATTR_MASK): New macro.
> (LARCH_ATTR_ENUM): Likewise.
> (LARCH_ATTR_BOOL): Likewise.
> (loongarch_handle_option): Support for new options.
> (loongarch_process_one_target_attr): Likewise.
> * doc/extend.texi: Add new attribute description information.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/loongarch/pragma-la64V1_1.c: New test.
>
> ---
> gcc/config/loongarch/loongarch-target-attr.cc | 86 ++++++++++++++----
> gcc/doc/extend.texi | 44 ++++++++++
> .../gcc.target/loongarch/pragma-la64V1_1.c | 87 +++++++++++++++++++
> 3 files changed, 202 insertions(+), 15 deletions(-)
> create mode 100644 gcc/testsuite/gcc.target/loongarch/pragma-la64V1_1.c
>
> diff --git a/gcc/config/loongarch/loongarch-target-attr.cc
> b/gcc/config/loongarch/loongarch-target-attr.cc
> index 922aa0483b5..f7a93782372 100644
> --- a/gcc/config/loongarch/loongarch-target-attr.cc
> +++ b/gcc/config/loongarch/loongarch-target-attr.cc
> @@ -52,28 +52,64 @@ enum loongarch_attr_opt_type
> struct loongarch_attribute_info
> {
> const char *name;
> + unsigned int opt_mask;
> enum loongarch_attr_opt_type attr_type;
> - bool allow_neg;
> enum opt_code opt_num;
> + bool allow_neg;
> };
> +
> +/* Construct a loongarch_attributes from the given arguments.
> +
> + OPTS is the name of the compilation option after the "-m" string.
> +
> + OPTNUM is the opt_code corresponding to the compilation option.
> +
> + OPTMASK is the mask corresponding to the mutation option. If the
> + compilation option does not have a corresponding mask, pass 0.
> + */
> +#define LARCH_ATTR_MASK(OPTS, OPTNUM, OPTMASK) \
> + { \
> + OPTS, OPTMASK, loongarch_attr_mask, OPTNUM, true \
> + }
> +
> +#define LARCH_ATTR_ENUM(OPTS, OPTNUM, OPTMASK) \
> + { \
> + OPTS, OPTMASK, loongarch_attr_enum, OPTNUM, false \
> + }
> +
> +#define LARCH_ATTR_BOOL(OPTS, OPTNUM, OPTMASK) \
> + { \
> + OPTS, OPTMASK, loongarch_attr_bool, OPTNUM, true \
> + }
> +
> /* The target attributes that we support. */
>
> static const struct loongarch_attribute_info loongarch_attributes[] =
> {
> - { "strict-align", loongarch_attr_mask, true, OPT_mstrict_align },
> - { "cmodel", loongarch_attr_enum, false, OPT_mcmodel_ },
> - { "arch", loongarch_attr_enum, false, OPT_march_ },
> - { "tune", loongarch_attr_enum, false, OPT_mtune_ },
> - { "lsx", loongarch_attr_bool, true, OPT_mlsx },
> - { "lasx", loongarch_attr_bool, true, OPT_mlasx },
> - { NULL, loongarch_attr_bool, false, OPT____ }
> + LARCH_ATTR_MASK ("strict-align", OPT_mstrict_align, MASK_STRICT_ALIGN),
> + LARCH_ATTR_ENUM ("cmodel", OPT_mcmodel_, 0),
> + LARCH_ATTR_ENUM ("arch", OPT_march_, 0),
> + LARCH_ATTR_ENUM ("tune", OPT_mtune_, 0),
> + LARCH_ATTR_BOOL ("lsx", OPT_mlsx, 0),
> + LARCH_ATTR_BOOL ("lasx", OPT_mlasx, 0),
> + LARCH_ATTR_BOOL ("frecipe", OPT_mfrecipe, OPTION_MASK_ISA_FRECIPE),
> + LARCH_ATTR_BOOL ("div32", OPT_mdiv32, OPTION_MASK_ISA_DIV32),
> + LARCH_ATTR_BOOL ("lam-bh", OPT_mlam_bh, OPTION_MASK_ISA_LAM_BH),
> + LARCH_ATTR_BOOL ("lamcas", OPT_mlamcas, OPTION_MASK_ISA_LAMCAS),
> + LARCH_ATTR_BOOL ("scq", OPT_mscq, OPTION_MASK_ISA_SCQ),
> + LARCH_ATTR_BOOL ("ld-seq-sa", OPT_mld_seq_sa, OPTION_MASK_ISA_LD_SEQ_SA),
IMO it's better to generate them from isa-evolution.in to avoid
duplicating. How about this one?
commit 3acfd0d8bb36ab8e6e2edc1cc5412cc8af8cd305
Author: Xi Ruoyao <[email protected]>
Date: Fri Jul 4 21:54:28 2025 +0800
LoongArch: Support evolution features in the target pragma and attribute
It's convenient to have one way to enable/disable the evolution features
in the source code.
gcc/ChangeLog:
* config/loongarch/genopts/gen-evolution.awk: Output the
info needed for handling evolution features when parsing
the target pragma and attribute.
* config/loongarch/loongarch-evolution.h: Regenerate.
* config/loongarch/loongarch-target-attr.cc
(loongarch_process_one_target_attr): Handle evolution
features parsing the target pragma and attribute.
diff --git a/gcc/config/loongarch/genopts/gen-evolution.awk
b/gcc/config/loongarch/genopts/gen-evolution.awk
index 507063bd50d..6574e4db24d 100644
--- a/gcc/config/loongarch/genopts/gen-evolution.awk
+++ b/gcc/config/loongarch/genopts/gen-evolution.awk
@@ -34,6 +34,7 @@ BEGIN {
cpucfg_word[NR] = $1
cpucfg_bit_in_word[NR] = $2
name[NR] = $3
+ orig_name[NR] = $3
gsub("-", "_", name[NR])
name_capitalized[NR] = toupper(name[NR])
split($4, isa_ver, "\\.")
@@ -82,6 +83,20 @@ function gen_cpucfg_map()
print "};"
}
+function gen_attr_info()
+{
+ print "static constexpr struct {"
+ print " const char *name;"
+ print " HOST_WIDE_INT opt_mask;"
+ print "} evol_attr_info[] = {"
+
+ for (i = 1; i <= NR; i++)
+ printf (" { \"%s\", OPTION_MASK_ISA_%s},\n",
+ orig_name[i], name_capitalized[i])
+
+ print "};"
+}
+
function gen_cpucfg_useful_idx()
{
split("0 1 2 16 17 18 19", init_useful_idx)
@@ -177,6 +192,10 @@ function gen_full_header()
print ""
+ gen_attr_info()
+
+ print ""
+
gen_cpucfg_useful_idx()
print ""
diff --git a/gcc/config/loongarch/loongarch-evolution.h
b/gcc/config/loongarch/loongarch-evolution.h
index 7fb7b0d3d86..09095b75fb8 100644
--- a/gcc/config/loongarch/loongarch-evolution.h
+++ b/gcc/config/loongarch/loongarch-evolution.h
@@ -40,6 +40,18 @@ static constexpr struct {
{ 3, 1u << 23, OPTION_MASK_ISA_LD_SEQ_SA },
};
+static constexpr struct {
+ const char *name;
+ HOST_WIDE_INT opt_mask;
+} evol_attr_info[] = {
+ { "frecipe", OPTION_MASK_ISA_FRECIPE},
+ { "div32", OPTION_MASK_ISA_DIV32},
+ { "lam-bh", OPTION_MASK_ISA_LAM_BH},
+ { "lamcas", OPTION_MASK_ISA_LAMCAS},
+ { "scq", OPTION_MASK_ISA_SCQ},
+ { "ld-seq-sa", OPTION_MASK_ISA_LD_SEQ_SA},
+};
+
static constexpr int cpucfg_useful_idx[] = {
0,
1,
diff --git a/gcc/config/loongarch/loongarch-target-attr.cc
b/gcc/config/loongarch/loongarch-target-attr.cc
index ae296154b68..1ca6ec257dd 100644
--- a/gcc/config/loongarch/loongarch-target-attr.cc
+++ b/gcc/config/loongarch/loongarch-target-attr.cc
@@ -237,6 +237,22 @@ loongarch_process_one_target_attr (char *arg_str,
location_t loc)
}
}
+ for (auto info: evol_attr_info)
+ {
+ if (strcmp (info.name, str_to_check) != 0)
+ continue;
+
+ found = true;
+
+ if (invert)
+ global_options.x_la_isa_evolution &= ~info.opt_mask;
+ else
+ global_options.x_la_isa_evolution |= info.opt_mask;
+
+ global_options_set.x_la_isa_evolution |= info.opt_mask;
+ break;
+ }
+
/* If we reached here we either have found an attribute and validated
it or didn't match any. If we matched an attribute but its arguments
were malformed we will have returned false already. */
--
Xi Ruoyao <[email protected]>