Skip to content

Commit ab907df

Browse files
committed
Added gisel size and asm
1 parent 9430996 commit ab907df

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

llvm/utils/costmodeltest.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,41 +28,49 @@ def getcost(costkind, print):
2828
cost = sum([int(x[len(costpre):len(costpre)+x[len(costpre):].find(' ')]) for x in costs if x.startswith(costpre)])
2929
return (cost, text.strip())
3030

31-
def checkcosts(llasm):
32-
logging.debug(llasm)
33-
with open("costtest.ll", "w") as f:
34-
f.write(llasm)
35-
36-
run(f"llc {'-mtriple='+args.mtriple if args.mtriple else ''} {'-mattr='+args.mattr if args.mattr else ''} costtest.ll -o costtest.s")
37-
#run(f"llc {'-mtriple='+args.mtriple if args.mtriple else ''} {'-mattr='+args.mattr if args.mattr else ''} costtest.ll -o costtest.o -filetype=obj --function-sections")
38-
#sizelines = run(f"llvm-size -A costtest.o")
39-
#size = int([x for x in sizelines.split('\n') if ".text.test" in x][0].split()[1]) // 4 - 1
31+
def getasm(extraflags):
32+
try:
33+
run(f"llc {'-mtriple='+args.mtriple if args.mtriple else ''} {'-mattr='+args.mattr if args.mattr else ''} {extraflags} costtest.ll -o costtest.s")
34+
except subprocess.CalledProcessError as e:
35+
return (["ERROR: " + e.output.decode('utf-8')], -1)
4036
with open("costtest.s") as f:
4137
lines = [l.strip() for l in f]
42-
# This tries to remove .declarations, comments and invariant instructions (movs and constants).
38+
# This tries to remove .declarations, comments etc
4339
lines = [l for l in lines if l[0] != '.' and l[0] != '/' and not l.startswith('test:')]
4440
#logging.debug(lines)
41+
4542
# TODOD: Improve the filtering to what is invariant, somehow. Or include it in the costs.
4643
filteredlines = [l for l in lines if not l.startswith('movi') and not l.startswith('mov\tw') and l != 'ret' and not l.startswith('adrp') and not l.startswith('ldr') and not l.startswith('dup') and not l.startswith('fmov')]
4744
logging.debug(filteredlines)
4845
size = len(filteredlines)
4946
logging.debug(f"size = {size}")
5047

48+
return (lines, size)
49+
50+
def checkcosts(llasm):
51+
logging.debug(llasm)
52+
with open("costtest.ll", "w") as f:
53+
f.write(llasm)
54+
55+
lines, size = getasm('')
56+
57+
gilines, gisize = getasm('-global-isel')
58+
5159
codesize = getcost('code-size', True)
5260
thru = getcost('throughput', False)
5361
lat = getcost('latency', False)
5462
sizelat = getcost('size-latency', False)
5563

5664
logging.debug(f"cost = codesize:{codesize[0]} throughput:{thru[0]} lat:{lat[0]} sizelat:{sizelat[0]}")
57-
return (size, [codesize, thru, lat, sizelat], llasm, ('\n'.join(lines)).replace('\t', ' '))
65+
return (size, gisize, [codesize, thru, lat, sizelat], llasm, ('\n'.join(lines)).replace('\t', ' '), ('\n'.join(gilines)).replace('\t', ' '))
5866

5967
# TODOD:
6068
#if args.checkopted:
6169
# run(f"opt {'-mtriple='+args.mtriple if args.mtriple else ''} {'-mattr='+args.mattr if args.mattr else ''} costtest.ll -O1 -S -o -")
6270

6371

6472
def generate_const(ty, sameval):
65-
consts = ['3', '2'] if not ty.isFloat() else ['3.0', '2.0']
73+
consts = ['7', '6'] if not ty.isFloat() else ['7.0', '6.0']
6674
if ty.elts == 1:
6775
return consts[0]
6876
if sameval:
@@ -149,10 +157,10 @@ def binop_variants(ty):
149157

150158
def do(instr, variant, ty, extrasize, data):
151159
logging.info(f"{variant} {instr} with {ty.str()}")
152-
(size, costs, ll, asm) = checkcosts(generate(variant, instr, ty))
160+
(size, gisize, costs, ll, asm, giasm) = checkcosts(generate(variant, instr, ty))
153161
if costs[0][0] != size - extrasize:
154162
logging.warning(f">>> {variant} {instr} with {ty.str()} size = {size} vs cost = {costs[0][0]} (expected extrasize={extrasize})")
155-
data.append({"instr":instr, "ty":str(ty), "variant":variant, "codesize":costs[0][0], "thru":costs[1][0], "lat":costs[2][0], "sizelat":costs[3][0], "size":size, "extrasize":extrasize, "asm":asm, "ll":ll, "costoutput":costs[0][1]})
163+
data.append({"instr":instr, "ty":str(ty), "variant":variant, "codesize":costs[0][0], "thru":costs[1][0], "lat":costs[2][0], "sizelat":costs[3][0], "size":size, "gisize":gisize, "extrasize":extrasize, "asm":asm, "giasm":giasm, "ll":ll, "costoutput":costs[0][1]})
156164
logging.debug('')
157165

158166
# Operations are the ones in https://github.com/llvm/llvm-project/issues/115133

0 commit comments

Comments
 (0)