Execution Frequency of Blocks

Hi, I want to do some rate analysis in standard dialect.
For instance, I want to extract the loop trip count and keep it in the standard dialect.
That can be represented as the execution frequency of blocks.

So I wonder if anyone has done this before and can share any idea to represent the execution frequency for blocks in standard dialect?

My idea is to encode the frequency of the block in the terminator, e.g. condbranches. For instance, a condbranch with N outputs can have an attribute of int[N] to indicate how many times the current block will go to each successor. The frequency of the block is the sum of all these values.

Please feel free to share your thoughts. Thanks!

This reminds me of branch weight metadata in LLVM IR LLVM Language Reference Manual — LLVM 12 documentation that is modeled as an IntElementsAttribute in the LLVM dialect - llvm-project/LLVMOps.td at f870c551f090b6edc83892efd68e9e96ed5c19a8 · llvm/llvm-project · GitHub.

1 Like

Thanks for sharing! Yes, I think this is useful for MLIR as well.
Is there any plan to add this attribute in std.br?

Not that I am aware of