[PATCH] LoongArch: Deprecate $v[01] and $fv[01] names per spec
WANG Xuerui
i.swmail@xen0n.name
Wed Jul 27 09:56:05 GMT 2022
From: WANG Xuerui <git@xen0n.name>
As outlined in the LoongArch ELF psABI spec [1], it is actually already
2 versions after the initial LoongArch support, and the $v[01] and
$fv[01] names should really get sunset by now. Issue warnings for such
usages per the deprecation procedure detailed in the spec, so we can
finally remove support in the next release cycle after this.
[1]: https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html
---
gas/config/tc-loongarch.c | 41 +++++++++++++++++++++++++++++++++-----
include/opcode/loongarch.h | 4 ++--
opcodes/loongarch-opc.c | 4 ++--
3 files changed, 40 insertions(+), 9 deletions(-)
diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c
index fbbaca55085..c9ce529b7cc 100644
--- a/gas/config/tc-loongarch.c
+++ b/gas/config/tc-loongarch.c
@@ -51,6 +51,7 @@ struct loongarch_cl_insn
size_t insn_length;
offsetT args[MAX_ARG_NUM_PLUS_2];
+ const char *used_deprecated_reg;
struct reloc_info reloc_info[MAX_RELOC_NUMBER_A_INSN];
size_t reloc_num;
@@ -206,7 +207,9 @@ md_parse_option (int c, const char *arg)
}
static struct htab *r_htab = NULL;
+static struct htab *r_deprecated_htab = NULL;
static struct htab *f_htab = NULL;
+static struct htab *f_deprecated_htab = NULL;
static struct htab *c_htab = NULL;
static struct htab *cr_htab = NULL;
static struct htab *v_htab = NULL;
@@ -250,6 +253,9 @@ loongarch_after_parse_args ()
/* Init ilp32/lp64 registers names. */
if (!r_htab)
r_htab = str_htab_create (), str_hash_insert (r_htab, "", 0, 0);
+ if (!r_deprecated_htab)
+ r_deprecated_htab = str_htab_create (),
+ str_hash_insert (r_deprecated_htab, "", 0, 0);
for (i = 0; i < ARRAY_SIZE (loongarch_r_normal_name); i++)
str_hash_insert (r_htab, loongarch_r_normal_name[i], (void *) (i + 1), 0);
@@ -265,6 +271,9 @@ loongarch_after_parse_args ()
{
if (!f_htab)
f_htab = str_htab_create (), str_hash_insert (f_htab, "", 0, 0);
+ if (!f_deprecated_htab)
+ f_deprecated_htab = str_htab_create (),
+ str_hash_insert (f_deprecated_htab, "", 0, 0);
for (i = 0; i < ARRAY_SIZE (loongarch_f_normal_name); i++)
str_hash_insert (f_htab, loongarch_f_normal_name[i], (void *) (i + 1),
@@ -305,9 +314,9 @@ loongarch_after_parse_args ()
for (i = 0; i < ARRAY_SIZE (loongarch_r_lp64_name); i++)
str_hash_insert (r_htab, loongarch_r_lp64_name[i], (void *) (i + 1),
0);
- for (i = 0; i < ARRAY_SIZE (loongarch_r_lp64_name1); i++)
- str_hash_insert (r_htab, loongarch_r_lp64_name1[i], (void *) (i + 1),
- 0);
+ for (i = 0; i < ARRAY_SIZE (loongarch_r_lp64_name_deprecated); i++)
+ str_hash_insert (r_deprecated_htab, loongarch_r_lp64_name_deprecated[i],
+ (void *) (i + 1), 0);
}
/* Init float-lp64 registers alias */
@@ -316,8 +325,8 @@ loongarch_after_parse_args ()
for (i = 0; i < ARRAY_SIZE (loongarch_f_lp64_name); i++)
str_hash_insert (f_htab, loongarch_f_lp64_name[i],
(void *) (i + 1), 0);
- for (i = 0; i < ARRAY_SIZE (loongarch_f_lp64_name1); i++)
- str_hash_insert (f_htab, loongarch_f_lp64_name1[i],
+ for (i = 0; i < ARRAY_SIZE (loongarch_f_lp64_name_deprecated); i++)
+ str_hash_insert (f_deprecated_htab, loongarch_f_lp64_name_deprecated[i],
(void *) (i + 1), 0);
}
}
@@ -654,11 +663,27 @@ loongarch_args_parser_can_match_arg_helper (char esc_ch1, char esc_ch2,
imm = (intptr_t) str_hash_find (r_htab, arg);
ip->match_now = 0 < imm;
ret = imm - 1;
+ if (ip->match_now)
+ break;
+ /* Handle potential usage of deprecated register aliases. */
+ imm = (intptr_t) str_hash_find (r_deprecated_htab, arg);
+ ip->match_now = 0 < imm;
+ ret = imm - 1;
+ if (ip->match_now)
+ ip->used_deprecated_reg = arg;
break;
case 'f':
imm = (intptr_t) str_hash_find (f_htab, arg);
ip->match_now = 0 < imm;
ret = imm - 1;
+ if (ip->match_now)
+ break;
+ /* Handle potential usage of deprecated register aliases. */
+ imm = (intptr_t) str_hash_find (f_deprecated_htab, arg);
+ ip->match_now = 0 < imm;
+ ret = imm - 1;
+ if (ip->match_now)
+ ip->used_deprecated_reg = arg;
break;
case 'c':
switch (esc_ch2)
@@ -688,6 +713,12 @@ loongarch_args_parser_can_match_arg_helper (char esc_ch1, char esc_ch2,
ip->insn->mask ? loongarch_insn_length (ip->insn->match) : 0;
/* FIXME: now we have no relax insn. */
ip->relax_max_length = ip->insn_length;
+
+ /* Warn usages of deprecated register names only once, i.e. preventing
+ double-fire on macro insns. */
+ if (ip->insn_length != 0 && ip->used_deprecated_reg != NULL)
+ as_warn (_("use of deprecated register name %s"),
+ ip->used_deprecated_reg);
break;
default:
as_fatal (_("unknown escape"));
diff --git a/include/opcode/loongarch.h b/include/opcode/loongarch.h
index c3922348a56..1862092db95 100644
--- a/include/opcode/loongarch.h
+++ b/include/opcode/loongarch.h
@@ -179,10 +179,10 @@ dec2 : [1-9][0-9]?
extern const char *const loongarch_r_normal_name[32];
extern const char *const loongarch_r_lp64_name[32];
- extern const char *const loongarch_r_lp64_name1[32];
+ extern const char *const loongarch_r_lp64_name_deprecated[32];
extern const char *const loongarch_f_normal_name[32];
extern const char *const loongarch_f_lp64_name[32];
- extern const char *const loongarch_f_lp64_name1[32];
+ extern const char *const loongarch_f_lp64_name_deprecated[32];
extern const char *const loongarch_c_normal_name[8];
extern const char *const loongarch_cr_normal_name[4];
extern const char *const loongarch_v_normal_name[32];
diff --git a/opcodes/loongarch-opc.c b/opcodes/loongarch-opc.c
index be0de61c3aa..08ba101a902 100644
--- a/opcodes/loongarch-opc.c
+++ b/opcodes/loongarch-opc.c
@@ -46,7 +46,7 @@ const char *const loongarch_r_lp64_name[32] =
"$s1", "$s2", "$s3", "$s4", "$s5", "$s6", "$s7", "$s8",
};
-const char *const loongarch_r_lp64_name1[32] =
+const char *const loongarch_r_lp64_name_deprecated[32] =
{
"", "", "", "", "$v0", "$v1", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
@@ -68,7 +68,7 @@ const char *const loongarch_f_lp64_name[32] =
"$fs0", "$fs1", "$fs2", "$fs3", "$fs4", "$fs5", "$fs6", "$fs7",
};
-const char *const loongarch_f_lp64_name1[32] =
+const char *const loongarch_f_lp64_name_deprecated[32] =
{
"$fv0", "$fv1", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
--
2.35.1
More information about the Binutils
mailing list