25
25
pass
26
26
opname .append (name )
27
27
28
+ # opcode_name --> opcode
29
+ # Sort alphabetically.
30
+ opmap = {name : i for i , name in enumerate (opname )}
31
+ opmap = dict (sorted (opmap .items ()))
32
+
28
33
TOTAL = "specialization.deferred" , "specialization.hit" , "specialization.miss" , "execution_count"
29
34
30
35
def print_specialization_stats (name , family_stats , defines ):
@@ -281,16 +286,16 @@ def get_total(opcode_stats):
281
286
return total
282
287
283
288
def emit_pair_counts (opcode_stats , total ):
289
+ pair_counts = []
290
+ for i , opcode_stat in enumerate (opcode_stats ):
291
+ if i == 0 :
292
+ continue
293
+ for key , value in opcode_stat .items ():
294
+ if key .startswith ("pair_count" ):
295
+ x , _ , _ = key [11 :].partition ("]" )
296
+ if value :
297
+ pair_counts .append ((value , (i , int (x ))))
284
298
with Section ("Pair counts" , summary = "Pair counts for top 100 pairs" ):
285
- pair_counts = []
286
- for i , opcode_stat in enumerate (opcode_stats ):
287
- if i == 0 :
288
- continue
289
- for key , value in opcode_stat .items ():
290
- if key .startswith ("pair_count" ):
291
- x , _ , _ = key [11 :].partition ("]" )
292
- if value :
293
- pair_counts .append ((value , (i , int (x ))))
294
299
pair_counts .sort (reverse = True )
295
300
cumulative = 0
296
301
rows = []
@@ -302,6 +307,36 @@ def emit_pair_counts(opcode_stats, total):
302
307
emit_table (("Pair" , "Count:" , "Self:" , "Cumulative:" ),
303
308
rows
304
309
)
310
+ with Section ("Predecessor/Successor Pairs" , summary = "Top 3 predecessors and successors of each opcode" ):
311
+ predecessors = collections .defaultdict (collections .Counter )
312
+ successors = collections .defaultdict (collections .Counter )
313
+ total_predecessors = collections .Counter ()
314
+ total_successors = collections .Counter ()
315
+ for count , (first , second ) in pair_counts :
316
+ if count :
317
+ predecessors [second ][first ] = count
318
+ successors [first ][second ] = count
319
+ total_predecessors [second ] += count
320
+ total_successors [first ] += count
321
+ for name , i in opmap .items ():
322
+ total1 = total_predecessors [i ]
323
+ total2 = total_successors [i ]
324
+ if total1 == 0 and total2 == 0 :
325
+ continue
326
+ pred_rows = succ_rows = ()
327
+ if total1 :
328
+ pred_rows = [(opname [pred ], count , f"{ count / total1 :.1%} " )
329
+ for (pred , count ) in predecessors [i ].most_common (3 )]
330
+ if total2 :
331
+ succ_rows = [(opname [succ ], count , f"{ count / total2 :.1%} " )
332
+ for (succ , count ) in successors [i ].most_common (3 )]
333
+ with Section (name , 3 , f"Successors and predecessors for { name } " ):
334
+ emit_table (("Predecessors" , "Count:" , "Percentage:" ),
335
+ pred_rows
336
+ )
337
+ emit_table (("Successors" , "Count:" , "Percentage:" ),
338
+ succ_rows
339
+ )
305
340
306
341
def main ():
307
342
stats = gather_stats ()
0 commit comments