Skip to content

Commit dbc1b71

Browse files
[RISCV][llvm-mca] Vector Unit Stride Loads and stores use EEW and EMU… (#69409)
…L based on instruction EEW Vector Unit Stride Loads and stores EEW and EMUL depend on the EEW given in the instruction name and the SEW from vtype. llvm-mca needs some help to correctly report this information.
1 parent 51835df commit dbc1b71

File tree

2 files changed

+1298
-6
lines changed

2 files changed

+1298
-6
lines changed

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

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,38 @@ RISCVInstrumentManager::createInstruments(const MCInst &Inst) {
185185
return SmallVector<UniqueInstrument>();
186186
}
187187

188+
static std::pair<uint8_t, uint8_t>
189+
getEEWAndEMULForUnitStrideLoadStore(unsigned Opcode, RISCVII::VLMUL LMUL,
190+
uint8_t SEW) {
191+
uint8_t EEW;
192+
switch (Opcode) {
193+
case RISCV::VLM_V:
194+
case RISCV::VSM_V:
195+
case RISCV::VLE8_V:
196+
case RISCV::VSE8_V:
197+
EEW = 8;
198+
break;
199+
case RISCV::VLE16_V:
200+
case RISCV::VSE16_V:
201+
EEW = 16;
202+
break;
203+
case RISCV::VLE32_V:
204+
case RISCV::VSE32_V:
205+
EEW = 32;
206+
break;
207+
case RISCV::VLE64_V:
208+
case RISCV::VSE64_V:
209+
EEW = 64;
210+
break;
211+
default:
212+
llvm_unreachable("Opcode is not a vector unit stride load nor store");
213+
}
214+
215+
uint8_t EMUL =
216+
static_cast<uint8_t>(RISCVVType::getSameRatioLMUL(SEW, LMUL, EEW));
217+
return std::make_pair(EEW, EMUL);
218+
}
219+
188220
unsigned RISCVInstrumentManager::getSchedClassID(
189221
const MCInstrInfo &MCII, const MCInst &MCI,
190222
const llvm::SmallVector<Instrument *> &IVec) const {
@@ -214,12 +246,23 @@ unsigned RISCVInstrumentManager::getSchedClassID(
214246
// or (Opcode, LMUL, SEW) if SEW instrument is active, and depends on LMUL
215247
// and SEW, or (Opcode, LMUL, 0) if does not depend on SEW.
216248
uint8_t SEW = SI ? SI->getSEW() : 0;
217-
// Check if it depends on LMUL and SEW
218-
const RISCVVInversePseudosTable::PseudoInfo *RVV =
219-
RISCVVInversePseudosTable::getBaseInfo(Opcode, LMUL, SEW);
220-
// Check if it depends only on LMUL
221-
if (!RVV)
222-
RVV = RISCVVInversePseudosTable::getBaseInfo(Opcode, LMUL, 0);
249+
250+
const RISCVVInversePseudosTable::PseudoInfo *RVV = nullptr;
251+
if (Opcode == RISCV::VLM_V || Opcode == RISCV::VSM_V ||
252+
Opcode == RISCV::VLE8_V || Opcode == RISCV::VSE8_V ||
253+
Opcode == RISCV::VLE16_V || Opcode == RISCV::VSE16_V ||
254+
Opcode == RISCV::VLE32_V || Opcode == RISCV::VSE32_V ||
255+
Opcode == RISCV::VLE64_V || Opcode == RISCV::VSE64_V) {
256+
RISCVII::VLMUL VLMUL = static_cast<RISCVII::VLMUL>(LMUL);
257+
auto [EEW, EMUL] = getEEWAndEMULForUnitStrideLoadStore(Opcode, VLMUL, SEW);
258+
RVV = RISCVVInversePseudosTable::getBaseInfo(Opcode, EMUL, EEW);
259+
} else {
260+
// Check if it depends on LMUL and SEW
261+
RVV = RISCVVInversePseudosTable::getBaseInfo(Opcode, LMUL, SEW);
262+
// Check if it depends only on LMUL
263+
if (!RVV)
264+
RVV = RISCVVInversePseudosTable::getBaseInfo(Opcode, LMUL, 0);
265+
}
223266

224267
// Not a RVV instr
225268
if (!RVV) {

0 commit comments

Comments
 (0)