Page MenuHomePhabricator

[mlir] print-op-stats: Print top-k locations

Authored by springerm on Sep 12 2021, 10:41 PM.



Add a new option for printing the top-k locations by "number of operations".

This is useful for debugging code size explosions: Those locations that result in a large number of operations after running a lowering are printed.

Diff Detail

Unit TestsFailed

70 msx64 windows > MLIR.IR::op-stats.mlir
Script: -- : 'RUN: at line 1'; c:\ws\w8\llvm-project\premerge-checks\build\bin\mlir-opt.exe -allow-unregistered-dialect -print-op-stats="top-k-locs=5" C:\ws\w8\llvm-project\premerge-checks\mlir\test\IR\op-stats.mlir -o=/dev/null 2>&1 | c:\ws\w8\llvm-project\premerge-checks\build\bin\filecheck.exe C:\ws\w8\llvm-project\premerge-checks\mlir\test\IR\op-stats.mlir

Event Timeline

springerm created this revision.Sep 12 2021, 10:41 PM
springerm requested review of this revision.Sep 12 2021, 10:41 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 12 2021, 10:41 PM

Example output:

RUN: mlir-opt -allow-unregistered-dialect -print-op-stats="top-k-locs=5" %s -o=/dev/null 2>&1 [OK]
mlir-opt -allow-unregistered-dialect -print-op-stats="top-k-locs=5" llvm-project/mlir/test/IR/op-stats.mlir -o=/dev/null 2>&1
Operations encountered:
  builtin.func         , 1
  builtin.module       , 1
          long_op_name , 1
      std.addf         , 6
      std.return       , 1
      xla.add          , 17

Top locations by number of operations:
...llvm/llvm-project/mlir/test/IR/op-stats.mlir":7:8) , 1
...lvm/llvm-project/mlir/test/IR/op-stats.mlir":28:9) , 1
...lvm/llvm-project/mlir/test/IR/op-stats.mlir":11:8) , 1
...llvm/llvm-project/mlir/test/IR/op-stats.mlir":9:8) , 1
...lvm/llvm-project/mlir/test/IR/op-stats.mlir":19:9) , 1

Is there a way to potentially compose these? E.g., it feels like (and I don't necessarily have good suggestion yet) that we have print op count, print top K locations (well which we could also just have print count per location and then defer to "grep loc\( | head -N K") and the follow up count per top loc. Basically, how much do we want to make this smarter vs relying on common unix tools? (summing per location using awk I invariably need to look up awk syntax again :) so counting is useful, but we could always emit a summary and then just have a group-by-location or also-group-by-location option [and then one would just have the global op count listed too], and then defer all else to awk/sed/grep or just searching in vim).

springerm abandoned this revision.Sat, Oct 16, 9:33 PM