Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
target/hexagon/*.py: clean up used 'toss' and 'numregs' vars
Many Hexagon python scripts call hex_common.get_tagregs(), but only one
call site use the full reg structure given by this function. To make the
code cleaner, let's make get_tagregs() filter out the unused fields
(i.e. 'toss' and 'numregs'), properly removed the unused variables at
the call sites. The hex_common.bad_register() function is also adjusted
to work exclusively with 'regtype' and 'regid' args. For the single call
site that does use toss/numregs, we provide an optional parameter to
get_tagregs() which will restore the old full behavior.

Suggested-by: Taylor Simpson <tsimpson@quicinc.com>
Signed-off-by: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
Reviewed-by: Taylor Simpson <tsimpson@quicinc.com>
Tested-by: Taylor Simpson <tsimpson@quicinc.com>
Signed-off-by: Taylor Simpson <tsimpson@quicinc.com>
Message-Id: <3ffd4ccb972879f57f499705c624e8eaba7f8b52.1684939078.git.quic_mathbern@quicinc.com>
  • Loading branch information
quic-mathbern authored and taylorsimpson committed May 26, 2023
1 parent 3fd49e2 commit 3608c24
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 70 deletions.
10 changes: 5 additions & 5 deletions target/hexagon/gen_analyze_funcs.py
Expand Up @@ -165,7 +165,7 @@ def analyze_opn_new(f, tag, regtype, regid, regno):
hex_common.bad_register(regtype, regid)


def analyze_opn(f, tag, regtype, regid, toss, numregs, i):
def analyze_opn(f, tag, regtype, regid, i):
if hex_common.is_pair(regid):
analyze_opn_old(f, tag, regtype, regid, i)
elif hex_common.is_single(regid):
Expand All @@ -174,9 +174,9 @@ def analyze_opn(f, tag, regtype, regid, toss, numregs, i):
elif hex_common.is_new_val(regtype, regid, tag):
analyze_opn_new(f, tag, regtype, regid, i)
else:
hex_common.bad_register(regtype, regid, toss, numregs)
hex_common.bad_register(regtype, regid)
else:
hex_common.bad_register(regtype, regid, toss, numregs)
hex_common.bad_register(regtype, regid)


##
Expand All @@ -202,8 +202,8 @@ def gen_analyze_func(f, tag, regs, imms):

i = 0
## Analyze all the registers
for regtype, regid, toss, numregs in regs:
analyze_opn(f, tag, regtype, regid, toss, numregs, i)
for regtype, regid in regs:
analyze_opn(f, tag, regtype, regid, i)
i += 1

has_generated_helper = not hex_common.skip_qemu_helper(
Expand Down
30 changes: 15 additions & 15 deletions target/hexagon/gen_helper_funcs.py
Expand Up @@ -87,9 +87,9 @@ def gen_helper_arg_opn(f, regtype, regid, i, tag):
elif hex_common.is_new_val(regtype, regid, tag):
gen_helper_arg_new(f, regtype, regid, i)
else:
hex_common.bad_register(regtype, regid, toss, numregs)
hex_common.bad_register(regtype, regid)
else:
hex_common.bad_register(regtype, regid, toss, numregs)
hex_common.bad_register(regtype, regid)


def gen_helper_arg_imm(f, immlett):
Expand Down Expand Up @@ -135,7 +135,7 @@ def gen_helper_dest_decl_opn(f, regtype, regid, i):
else:
gen_helper_dest_decl(f, regtype, regid, i)
else:
hex_common.bad_register(regtype, regid, toss, numregs)
hex_common.bad_register(regtype, regid)


def gen_helper_src_var_ext(f, regtype, regid):
Expand Down Expand Up @@ -185,7 +185,7 @@ def gen_helper_return_opn(f, regtype, regid, i):
else:
gen_helper_return(f, regtype, regid, i)
else:
hex_common.bad_register(regtype, regid, toss, numregs)
hex_common.bad_register(regtype, regid)


##
Expand All @@ -208,7 +208,7 @@ def gen_helper_function(f, tag, tagregs, tagimms):
numresults = 0
numscalarresults = 0
numscalarreadwrite = 0
for regtype, regid, toss, numregs in regs:
for regtype, regid in regs:
if hex_common.is_written(regid):
numresults += 1
if hex_common.is_scalar_reg(regtype):
Expand All @@ -226,7 +226,7 @@ def gen_helper_function(f, tag, tagregs, tagimms):
## The return type of the function is the type of the destination
## register (if scalar)
i = 0
for regtype, regid, toss, numregs in regs:
for regtype, regid in regs:
if hex_common.is_written(regid):
if hex_common.is_pair(regid):
if hex_common.is_hvx_reg(regtype):
Expand All @@ -239,7 +239,7 @@ def gen_helper_function(f, tag, tagregs, tagimms):
else:
gen_helper_return_type(f, regtype, regid, i)
else:
hex_common.bad_register(regtype, regid, toss, numregs)
hex_common.bad_register(regtype, regid)
i += 1

if numscalarresults == 0:
Expand All @@ -248,7 +248,7 @@ def gen_helper_function(f, tag, tagregs, tagimms):

## Arguments include the vector destination operands
i = 1
for regtype, regid, toss, numregs in regs:
for regtype, regid in regs:
if hex_common.is_written(regid):
if hex_common.is_pair(regid):
if hex_common.is_hvx_reg(regtype):
Expand All @@ -262,20 +262,20 @@ def gen_helper_function(f, tag, tagregs, tagimms):
# This is the return value of the function
continue
else:
hex_common.bad_register(regtype, regid, toss, numregs)
hex_common.bad_register(regtype, regid)
i += 1

## For conditional instructions, we pass in the destination register
if "A_CONDEXEC" in hex_common.attribdict[tag]:
for regtype, regid, toss, numregs in regs:
for regtype, regid in regs:
if hex_common.is_writeonly(regid) and not hex_common.is_hvx_reg(
regtype
):
gen_helper_arg_opn(f, regtype, regid, i, tag)
i += 1

## Arguments to the helper function are the source regs and immediates
for regtype, regid, toss, numregs in regs:
for regtype, regid in regs:
if hex_common.is_read(regid):
if hex_common.is_hvx_reg(regtype) and hex_common.is_readwrite(regid):
continue
Expand Down Expand Up @@ -315,12 +315,12 @@ def gen_helper_function(f, tag, tagregs, tagimms):
## Declare the return variable
i = 0
if "A_CONDEXEC" not in hex_common.attribdict[tag]:
for regtype, regid, toss, numregs in regs:
for regtype, regid in regs:
if hex_common.is_writeonly(regid):
gen_helper_dest_decl_opn(f, regtype, regid, i)
i += 1

for regtype, regid, toss, numregs in regs:
for regtype, regid in regs:
if hex_common.is_read(regid):
if hex_common.is_pair(regid):
if hex_common.is_hvx_reg(regtype):
Expand All @@ -329,7 +329,7 @@ def gen_helper_function(f, tag, tagregs, tagimms):
if hex_common.is_hvx_reg(regtype):
gen_helper_src_var_ext(f, regtype, regid)
else:
hex_common.bad_register(regtype, regid, toss, numregs)
hex_common.bad_register(regtype, regid)

if hex_common.need_slot(tag):
if "A_LOAD" in hex_common.attribdict[tag]:
Expand All @@ -345,7 +345,7 @@ def gen_helper_function(f, tag, tagregs, tagimms):
f.write(" arch_fpop_end(env);\n")

## Save/return the return variable
for regtype, regid, toss, numregs in regs:
for regtype, regid in regs:
if hex_common.is_written(regid):
gen_helper_return_opn(f, regtype, regid, i)
f.write("}\n\n")
Expand Down
22 changes: 11 additions & 11 deletions target/hexagon/gen_helper_protos.py
Expand Up @@ -46,13 +46,13 @@
}


def gen_def_helper_opn(f, tag, regtype, regid, toss, numregs, i):
def gen_def_helper_opn(f, tag, regtype, regid, i):
if hex_common.is_pair(regid):
f.write(f", {def_helper_types_pair[regtype]}")
elif hex_common.is_single(regid):
f.write(f", {def_helper_types[regtype]}")
else:
hex_common.bad_register(regtype, regid, toss, numregs)
hex_common.bad_register(regtype, regid)


##
Expand All @@ -68,7 +68,7 @@ def gen_helper_prototype(f, tag, tagregs, tagimms):
numresults = 0
numscalarresults = 0
numscalarreadwrite = 0
for regtype, regid, toss, numregs in regs:
for regtype, regid in regs:
if hex_common.is_written(regid):
numresults += 1
if hex_common.is_scalar_reg(regtype):
Expand Down Expand Up @@ -124,38 +124,38 @@ def gen_helper_prototype(f, tag, tagregs, tagimms):
## - Emit the scalar result
## - Emit the vector result
i = 0
for regtype, regid, toss, numregs in regs:
for regtype, regid in regs:
if hex_common.is_written(regid):
if not hex_common.is_hvx_reg(regtype):
gen_def_helper_opn(f, tag, regtype, regid, toss, numregs, i)
gen_def_helper_opn(f, tag, regtype, regid, i)
i += 1

## Put the env between the outputs and inputs
f.write(", env")
i += 1

# Second pass
for regtype, regid, toss, numregs in regs:
for regtype, regid in regs:
if hex_common.is_written(regid):
if hex_common.is_hvx_reg(regtype):
gen_def_helper_opn(f, tag, regtype, regid, toss, numregs, i)
gen_def_helper_opn(f, tag, regtype, regid, i)
i += 1

## For conditional instructions, we pass in the destination register
if "A_CONDEXEC" in hex_common.attribdict[tag]:
for regtype, regid, toss, numregs in regs:
for regtype, regid in regs:
if hex_common.is_writeonly(regid) and not hex_common.is_hvx_reg(
regtype
):
gen_def_helper_opn(f, tag, regtype, regid, toss, numregs, i)
gen_def_helper_opn(f, tag, regtype, regid, i)
i += 1

## Generate the qemu type for each input operand (regs and immediates)
for regtype, regid, toss, numregs in regs:
for regtype, regid in regs:
if hex_common.is_read(regid):
if hex_common.is_hvx_reg(regtype) and hex_common.is_readwrite(regid):
continue
gen_def_helper_opn(f, tag, regtype, regid, toss, numregs, i)
gen_def_helper_opn(f, tag, regtype, regid, i)
i += 1
for immlett, bits, immshift in imms:
f.write(", s32")
Expand Down
4 changes: 2 additions & 2 deletions target/hexagon/gen_idef_parser_funcs.py
Expand Up @@ -131,7 +131,7 @@ def main():
imms = tagimms[tag]

arguments = []
for regtype, regid, toss, numregs in regs:
for regtype, regid in regs:
prefix = "in " if hex_common.is_read(regid) else ""

is_pair = hex_common.is_pair(regid)
Expand All @@ -147,7 +147,7 @@ def main():
elif is_single_new:
arguments.append(f"{prefix}{regtype}{regid}N")
else:
hex_common.bad_register(regtype, regid, toss, numregs)
hex_common.bad_register(regtype, regid)

for immlett, bits, immshift in imms:
arguments.append(hex_common.imm_name(immlett))
Expand Down
4 changes: 2 additions & 2 deletions target/hexagon/gen_op_regs.py
Expand Up @@ -70,7 +70,7 @@ def strip_reg_prefix(x):
def main():
hex_common.read_semantics_file(sys.argv[1])
hex_common.read_attribs_file(sys.argv[2])
tagregs = hex_common.get_tagregs()
tagregs = hex_common.get_tagregs(full=True)
tagimms = hex_common.get_tagimms()

with open(sys.argv[3], "w") as f:
Expand All @@ -79,7 +79,7 @@ def main():
rregs = []
wregs = []
regids = ""
for regtype, regid, toss, numregs in regs:
for regtype, regid, _, numregs in regs:
if hex_common.is_read(regid):
if regid[0] not in regids:
regids += regid[0]
Expand Down

0 comments on commit 3608c24

Please sign in to comment.