[AsmPrinter] Add per BB instruction mix remark.
authorFlorian Hahn <flo@fhahn.com>
Mon, 26 Oct 2020 09:01:51 +0000 (09:01 +0000)
committerFlorian Hahn <flo@fhahn.com>
Mon, 26 Oct 2020 09:25:45 +0000 (09:25 +0000)
commitb2bec7cece9bb7d17799ac0af65a770cab4397ee
treeb8eda60f5d7113b1e77a8858bc8e23a65ec7b1fc
parenta094b4fa4b7f00d3e389a55c401e4078534494b8
[AsmPrinter] Add per BB instruction mix remark.

This patch adds a remarks that provides counts for each opcode per basic block.

An snippet of the generated information can be seen below.

The current implementation uses the target specific opcode for the counts. For example, on AArch64 this means we currently get 2 entries for `add` instructions if the block contains 32 and 64 bit adds. Similarly, immediate version are treated differently.

Unfortunately there seems to be no convenient way to get only the mnemonic part of the instruction as a string AFAIK. This could be improved in the future.

```
--- !Analysis
Pass:            asm-printer
Name:            InstructionMix
DebugLoc:        { File: arm64-instruction-mix-remarks.ll, Line: 30, Column: 30 }
Function:        foo
Args:
  - String:          'BasicBlock: '
  - BasicBlock:      else
  - String:          "\n"
  - String:          INST_MADDWrrr
  - String:          ': '
  - INST_MADDWrrr:   '2'
  - String:          "\n"
  - String:          INST_MOVZWi
  - String:          ': '
  - INST_MOVZWi:     '1'
```

Reviewed By: anemet, thegameg, paquette

Differential Revision: https://reviews.llvm.org/D89892
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/test/CodeGen/AArch64/arm64-instruction-mix-remarks.ll [new file with mode: 0644]