@@ -28,41 +28,49 @@ def getcost(costkind, print):
28
28
cost = sum ([int (x [len (costpre ):len (costpre )+ x [len (costpre ):].find (' ' )]) for x in costs if x .startswith (costpre )])
29
29
return (cost , text .strip ())
30
30
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 )
40
36
with open ("costtest.s" ) as f :
41
37
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
43
39
lines = [l for l in lines if l [0 ] != '.' and l [0 ] != '/' and not l .startswith ('test:' )]
44
40
#logging.debug(lines)
41
+
45
42
# TODOD: Improve the filtering to what is invariant, somehow. Or include it in the costs.
46
43
filteredlines = [l for l in lines if not l .startswith ('movi' ) and not l .startswith ('mov\t w' ) and l != 'ret' and not l .startswith ('adrp' ) and not l .startswith ('ldr' ) and not l .startswith ('dup' ) and not l .startswith ('fmov' )]
47
44
logging .debug (filteredlines )
48
45
size = len (filteredlines )
49
46
logging .debug (f"size = { size } " )
50
47
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
+
51
59
codesize = getcost ('code-size' , True )
52
60
thru = getcost ('throughput' , False )
53
61
lat = getcost ('latency' , False )
54
62
sizelat = getcost ('size-latency' , False )
55
63
56
64
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 ' , ' ' ))
58
66
59
67
# TODOD:
60
68
#if args.checkopted:
61
69
# run(f"opt {'-mtriple='+args.mtriple if args.mtriple else ''} {'-mattr='+args.mattr if args.mattr else ''} costtest.ll -O1 -S -o -")
62
70
63
71
64
72
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' ]
66
74
if ty .elts == 1 :
67
75
return consts [0 ]
68
76
if sameval :
@@ -149,10 +157,10 @@ def binop_variants(ty):
149
157
150
158
def do (instr , variant , ty , extrasize , data ):
151
159
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 ))
153
161
if costs [0 ][0 ] != size - extrasize :
154
162
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 ]})
156
164
logging .debug ('' )
157
165
158
166
# Operations are the ones in https://github.com/llvm/llvm-project/issues/115133
0 commit comments