On 27/02/26, Brian Cain wrote:
> From: Brian Cain <[email protected]>
>
> Signed-off-by: Brian Cain <[email protected]>
> ---
> target/hexagon/gen_analyze_funcs.py | 21 +++-
> target/hexagon/hex_common.py | 161 ++++++++++++++++++++++++++++
> 2 files changed, 179 insertions(+), 3 deletions(-)
>
> diff --git a/target/hexagon/gen_analyze_funcs.py
> b/target/hexagon/gen_analyze_funcs.py
> index fdefd5b4b36..985386c1309 100755
> --- a/target/hexagon/gen_analyze_funcs.py
> +++ b/target/hexagon/gen_analyze_funcs.py
> @@ -22,6 +22,8 @@
> import string
> import hex_common
>
> +def has_analyze_func(reg, mode):
> + return callable(getattr(reg, f"analyze_{mode}", None))
>
> ##
> ## Generate the code to analyze the instruction
> @@ -42,6 +44,14 @@ def gen_analyze_func(f, tag, regs, imms):
> f.write(f"static void analyze_{tag}(DisasContext *ctx)\n")
> f.write("{\n")
>
> + if hex_common.tag_ignore(tag):
> + f.write("}\n\n")
> + return
> +
> + if ("A_PRIV" in hex_common.attribdict[tag] or
> + "A_GUEST" in hex_common.attribdict[tag]):
> + f.write("#ifndef CONFIG_USER_ONLY\n")
use hex_common.is_sysemu_tag(tag) here instead!
> +
> f.write(" Insn *insn G_GNUC_UNUSED = ctx->insn;\n")
> if (hex_common.is_hvx_insn(tag)):
> if hex_common.has_hvx_helper(tag):
> @@ -58,13 +68,14 @@ def gen_analyze_func(f, tag, regs, imms):
> for regno, register in enumerate(regs):
> reg_type, reg_id = register
> reg = hex_common.get_register(tag, reg_type, reg_id)
> - reg.decl_reg_num(f, regno)
> + if has_analyze_func(reg, "read") or has_analyze_func(reg, "write"):
> + reg.decl_reg_num(f, regno)
I'm not a huge fan of redirecting control flow based on whether or not
the register class has certain functions, feels hard to follow. It's
also unclear to me why this is needed, I assume we have some registers
where reg.is_read()/reg.is_written() are false but we still want to emit
analyze code for them?
>
> ## Analyze the register reads
> for regno, register in enumerate(regs):
> reg_type, reg_id = register
> reg = hex_common.get_register(tag, reg_type, reg_id)
> - if reg.is_read():
> + if reg.is_read() and has_analyze_func(reg, "read"):
> reg.analyze_read(f, regno)
>
> f.write(" mark_implicit_reads(ctx);\n")
> @@ -73,11 +84,15 @@ def gen_analyze_func(f, tag, regs, imms):
> for regno, register in enumerate(regs):
> reg_type, reg_id = register
> reg = hex_common.get_register(tag, reg_type, reg_id)
> - if reg.is_written():
> + if reg.is_written() and has_analyze_func(reg, "write"):
> reg.analyze_write(f, tag, regno)
>
> f.write(" mark_implicit_writes(ctx);\n")
>
> + if ("A_PRIV" in hex_common.attribdict[tag] or
> + "A_GUEST" in hex_common.attribdict[tag]):
> + f.write("#endif /* !CONFIG_USER_ONLY */\n")
and use hex_common.is_sysemu_tag(tag) here also
> +
> f.write("}\n\n")
>
>
> diff --git a/target/hexagon/hex_common.py b/target/hexagon/hex_common.py
> index 63f83a8de2a..b5ab2efa5a5 100755
> --- a/target/hexagon/hex_common.py
> +++ b/target/hexagon/hex_common.py
> @@ -33,6 +33,42 @@
> overrides = {} # tags with helper overrides
> idef_parser_enabled = {} # tags enabled for idef-parser
>
> +
> +def is_sysemu_tag(tag):
> + return "A_PRIV" in attribdict[tag] or "A_GUEST" in attribdict[tag]
> +
> +
> +def tag_ignore(tag):
> + tag_skips = (
> + "Y6_diag",
> + "Y6_diag0",
> + "Y6_diag1",
> + )
> + attr_skips = (
> + "A_FAKEINSN",
> + "A_MAPPING",
> + "A_CONDMAPPING",
> + )
> + return tag in tag_skips or \
> + any(attr in attribdict[tag] for attr in attr_skips)
Up to you if you think this is easier to read or not, but you could make
attr_skips a set and do set intsersection instead
attr_skips = {
"A_FAKEINSN",
"A_MAPPING",
"A_CONDMAPPING",
}
return tag in tag_skips or attribdict[tag] & attr_skips
--
Anton Johansson
rev.ng Labs Srl.