Skip to content

Commit 51a86e7

Browse files
authored
[MCA][RISCV]Enable latency instrument on RISCV (#160063)
Recently added latency customization ([PR](#155420)) does not work on RISCV since it has target-specific InstrumentManager that overrides default functionality. Added calls to base class to ensure that common instruments (including latency customizer) are available.
1 parent f3762b7 commit 51a86e7

File tree

2 files changed

+82
-23
lines changed

2 files changed

+82
-23
lines changed

llvm/lib/Target/RISCV/MCA/RISCVCustomBehaviour.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/MC/TargetRegistry.h"
1919
#include "llvm/Support/Compiler.h"
2020
#include "llvm/Support/Debug.h"
21+
#include "llvm/Support/DebugLog.h"
2122

2223
#define DEBUG_TYPE "llvm-mca-riscv-custombehaviour"
2324

@@ -86,40 +87,41 @@ uint8_t RISCVSEWInstrument::getSEW() const {
8687
bool RISCVInstrumentManager::supportsInstrumentType(
8788
llvm::StringRef Type) const {
8889
return Type == RISCVLMULInstrument::DESC_NAME ||
89-
Type == RISCVSEWInstrument::DESC_NAME;
90+
Type == RISCVSEWInstrument::DESC_NAME ||
91+
InstrumentManager::supportsInstrumentType(Type);
9092
}
9193

9294
UniqueInstrument
9395
RISCVInstrumentManager::createInstrument(llvm::StringRef Desc,
9496
llvm::StringRef Data) {
9597
if (Desc == RISCVLMULInstrument::DESC_NAME) {
9698
if (!RISCVLMULInstrument::isDataValid(Data)) {
97-
LLVM_DEBUG(dbgs() << "RVCB: Bad data for instrument kind " << Desc << ": "
98-
<< Data << '\n');
99+
LDBG() << "RVCB: Bad data for instrument kind " << Desc << ": " << Data
100+
<< '\n';
99101
return nullptr;
100102
}
101103
return std::make_unique<RISCVLMULInstrument>(Data);
102104
}
103105

104106
if (Desc == RISCVSEWInstrument::DESC_NAME) {
105107
if (!RISCVSEWInstrument::isDataValid(Data)) {
106-
LLVM_DEBUG(dbgs() << "RVCB: Bad data for instrument kind " << Desc << ": "
107-
<< Data << '\n');
108+
LDBG() << "RVCB: Bad data for instrument kind " << Desc << ": " << Data
109+
<< '\n';
108110
return nullptr;
109111
}
110112
return std::make_unique<RISCVSEWInstrument>(Data);
111113
}
112114

113-
LLVM_DEBUG(dbgs() << "RVCB: Unknown instrumentation Desc: " << Desc << '\n');
114-
return nullptr;
115+
LDBG() << "RVCB: Creating default instrument for Desc: " << Desc << '\n';
116+
return InstrumentManager::createInstrument(Desc, Data);
115117
}
116118

117119
SmallVector<UniqueInstrument>
118120
RISCVInstrumentManager::createInstruments(const MCInst &Inst) {
119121
if (Inst.getOpcode() == RISCV::VSETVLI ||
120122
Inst.getOpcode() == RISCV::VSETIVLI) {
121-
LLVM_DEBUG(dbgs() << "RVCB: Found VSETVLI and creating instrument for it: "
122-
<< Inst << "\n");
123+
LDBG() << "RVCB: Found VSETVLI and creating instrument for it: " << Inst
124+
<< "\n";
123125
unsigned VTypeI = Inst.getOperand(2).getImm();
124126
RISCVVType::VLMUL VLMUL = RISCVVType::getVLMUL(VTypeI);
125127

@@ -250,8 +252,7 @@ unsigned RISCVInstrumentManager::getSchedClassID(
250252
// Need LMUL or LMUL, SEW in order to override opcode. If no LMUL is provided,
251253
// then no option to override.
252254
if (!LI) {
253-
LLVM_DEBUG(
254-
dbgs() << "RVCB: Did not use instrumentation to override Opcode.\n");
255+
LDBG() << "RVCB: Did not use instrumentation to override Opcode.\n";
255256
return SchedClassID;
256257
}
257258
uint8_t LMUL = LI->getLMUL();
@@ -313,22 +314,21 @@ unsigned RISCVInstrumentManager::getSchedClassID(
313314

314315
// Not a RVV instr
315316
if (!VPOpcode) {
316-
LLVM_DEBUG(
317-
dbgs() << "RVCB: Could not find PseudoInstruction for Opcode "
318-
<< MCII.getName(Opcode)
319-
<< ", LMUL=" << (LI ? LI->getData() : "Unspecified")
320-
<< ", SEW=" << (SI ? SI->getData() : "Unspecified")
321-
<< ". Ignoring instrumentation and using original SchedClassID="
322-
<< SchedClassID << '\n');
317+
LDBG() << "RVCB: Could not find PseudoInstruction for Opcode "
318+
<< MCII.getName(Opcode)
319+
<< ", LMUL=" << (LI ? LI->getData() : "Unspecified")
320+
<< ", SEW=" << (SI ? SI->getData() : "Unspecified")
321+
<< ". Ignoring instrumentation and using original SchedClassID="
322+
<< SchedClassID << '\n';
323323
return SchedClassID;
324324
}
325325

326326
// Override using pseudo
327-
LLVM_DEBUG(dbgs() << "RVCB: Found Pseudo Instruction for Opcode "
328-
<< MCII.getName(Opcode) << ", LMUL=" << LI->getData()
329-
<< ", SEW=" << (SI ? SI->getData() : "Unspecified")
330-
<< ". Overriding original SchedClassID=" << SchedClassID
331-
<< " with " << MCII.getName(*VPOpcode) << '\n');
327+
LDBG() << "RVCB: Found Pseudo Instruction for Opcode " << MCII.getName(Opcode)
328+
<< ", LMUL=" << LI->getData()
329+
<< ", SEW=" << (SI ? SI->getData() : "Unspecified")
330+
<< ". Overriding original SchedClassID=" << SchedClassID << " with "
331+
<< MCII.getName(*VPOpcode) << '\n';
332332
return MCII.get(*VPOpcode).getSchedClass();
333333
}
334334

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mca_test_checks.py
2+
# RUN: llvm-mca -mtriple=riscv64 -mcpu=sifive-x280 --timeline -iterations=1 < %s | FileCheck %s
3+
4+
# LLVM-MCA-LATENCY 20
5+
add a0, a0, a0
6+
7+
# CHECK: Iterations: 1
8+
# CHECK-NEXT: Instructions: 1
9+
# CHECK-NEXT: Total Cycles: 21
10+
# CHECK-NEXT: Total uOps: 1
11+
12+
# CHECK: Dispatch Width: 2
13+
# CHECK-NEXT: uOps Per Cycle: 0.05
14+
# CHECK-NEXT: IPC: 0.05
15+
# CHECK-NEXT: Block RThroughput: 0.5
16+
17+
# CHECK: Instruction Info:
18+
# CHECK-NEXT: [1]: #uOps
19+
# CHECK-NEXT: [2]: Latency
20+
# CHECK-NEXT: [3]: RThroughput
21+
# CHECK-NEXT: [4]: MayLoad
22+
# CHECK-NEXT: [5]: MayStore
23+
# CHECK-NEXT: [6]: HasSideEffects (U)
24+
25+
# CHECK: [1] [2] [3] [4] [5] [6] Instructions:
26+
# CHECK-NEXT: 1 3 0.50 add a0, a0, a0
27+
28+
# CHECK: Resources:
29+
# CHECK-NEXT: [0] - VLEN512SiFive7FDiv
30+
# CHECK-NEXT: [1] - VLEN512SiFive7IDiv
31+
# CHECK-NEXT: [2] - VLEN512SiFive7PipeA
32+
# CHECK-NEXT: [3] - VLEN512SiFive7PipeB
33+
# CHECK-NEXT: [4] - VLEN512SiFive7VA
34+
# CHECK-NEXT: [5] - VLEN512SiFive7VCQ
35+
# CHECK-NEXT: [6] - VLEN512SiFive7VL
36+
# CHECK-NEXT: [7] - VLEN512SiFive7VS
37+
38+
# CHECK: Resource pressure per iteration:
39+
# CHECK-NEXT: [0] [1] [2] [3] [4] [5] [6] [7]
40+
# CHECK-NEXT: - - - 1.00 - - - -
41+
42+
# CHECK: Resource pressure by instruction:
43+
# CHECK-NEXT: [0] [1] [2] [3] [4] [5] [6] [7] Instructions:
44+
# CHECK-NEXT: - - - 1.00 - - - - add a0, a0, a0
45+
46+
# CHECK: Timeline view:
47+
# CHECK-NEXT: 0123456789
48+
# CHECK-NEXT: Index 0123456789 0
49+
50+
# CHECK: [0,0] DeeeeeeeeeeeeeeeeeeeE add a0, a0, a0
51+
52+
# CHECK: Average Wait times (based on the timeline view):
53+
# CHECK-NEXT: [0]: Executions
54+
# CHECK-NEXT: [1]: Average time spent waiting in a scheduler's queue
55+
# CHECK-NEXT: [2]: Average time spent waiting in a scheduler's queue while ready
56+
# CHECK-NEXT: [3]: Average time elapsed from WB until retire stage
57+
58+
# CHECK: [0] [1] [2] [3]
59+
# CHECK-NEXT: 0. 1 0.0 0.0 0.0 add a0, a0, a0

0 commit comments

Comments
 (0)