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. */