Skip to content

Commit c9babcb

Browse files
committed
[RISCV] Collect Statistics on Compressed Instructions
Summary: It is useful to keep statistics on how many instructions we have compressed, so we can see if future changes are increasing or decreasing this number. Reviewers: asb, luismarques Reviewed By: asb, luismarques Subscribers: xbolva00, sameer.abuasal, hiraditya, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, kito-cheng, shiva0217, jrtc27, MaskRay, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, PkmX, jocewei, psnobl, benna, Jim, s.egerton, pzheng, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67495
1 parent ddf0442 commit c9babcb

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "Utils/RISCVMatInt.h"
1616
#include "llvm/ADT/STLExtras.h"
1717
#include "llvm/ADT/SmallVector.h"
18+
#include "llvm/ADT/Statistic.h"
1819
#include "llvm/ADT/StringSwitch.h"
1920
#include "llvm/CodeGen/Register.h"
2021
#include "llvm/MC/MCAssembler.h"
@@ -37,10 +38,15 @@
3738

3839
using namespace llvm;
3940

41+
#define DEBUG_TYPE "riscv-asm-parser"
42+
4043
// Include the auto-generated portion of the compress emitter.
4144
#define GEN_COMPRESS_INSTR
4245
#include "RISCVGenCompressInstEmitter.inc"
4346

47+
STATISTIC(RISCVNumInstrsCompressed,
48+
"Number of RISC-V Compressed instructions emitted");
49+
4450
namespace {
4551
struct RISCVOperand;
4652

@@ -1615,6 +1621,8 @@ bool RISCVAsmParser::parseDirectiveOption() {
16151621
void RISCVAsmParser::emitToStreamer(MCStreamer &S, const MCInst &Inst) {
16161622
MCInst CInst;
16171623
bool Res = compressInst(CInst, Inst, getSTI(), S.getContext());
1624+
if (Res)
1625+
++RISCVNumInstrsCompressed;
16181626
S.EmitInstruction((Res ? CInst : Inst), getSTI());
16191627
}
16201628

llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "MCTargetDesc/RISCVMCExpr.h"
1717
#include "RISCVTargetMachine.h"
1818
#include "TargetInfo/RISCVTargetInfo.h"
19+
#include "llvm/ADT/Statistic.h"
1920
#include "llvm/CodeGen/AsmPrinter.h"
2021
#include "llvm/CodeGen/MachineConstantPool.h"
2122
#include "llvm/CodeGen/MachineFunctionPass.h"
@@ -31,6 +32,9 @@ using namespace llvm;
3132

3233
#define DEBUG_TYPE "asm-printer"
3334

35+
STATISTIC(RISCVNumInstrsCompressed,
36+
"Number of RISC-V Compressed instructions emitted");
37+
3438
namespace {
3539
class RISCVAsmPrinter : public AsmPrinter {
3640
public:
@@ -64,6 +68,8 @@ void RISCVAsmPrinter::EmitToStreamer(MCStreamer &S, const MCInst &Inst) {
6468
MCInst CInst;
6569
bool Res = compressInst(CInst, Inst, *TM.getMCSubtargetInfo(),
6670
OutStreamer->getContext());
71+
if (Res)
72+
++RISCVNumInstrsCompressed;
6773
AsmPrinter::EmitToStreamer(*OutStreamer, Res ? CInst : Inst);
6874
}
6975

0 commit comments

Comments
 (0)