23#define DEBUG_TYPE "llvm-mca-riscv-custombehaviour"
34#define GET_RISCVBaseVXMemOpTable_IMPL
35#include "RISCVGenSearchableTables.inc"
46 .
Cases({
"M1",
"M2",
"M4",
"M8",
"MF2",
"MF4",
"MF8"},
true)
54 "Cannot get LMUL because invalid Data value");
71 .
Cases({
"E8",
"E16",
"E32",
"E64"},
true)
99 LDBG() <<
"RVCB: Bad data for instrument kind " <<
Desc <<
": " <<
Data
103 return std::make_unique<RISCVLMULInstrument>(
Data);
108 LDBG() <<
"RVCB: Bad data for instrument kind " <<
Desc <<
": " <<
Data
112 return std::make_unique<RISCVSEWInstrument>(
Data);
115 LDBG() <<
"RVCB: Creating default instrument for Desc: " <<
Desc <<
'\n';
121 if (Inst.
getOpcode() == RISCV::VSETVLI ||
123 LDBG() <<
"RVCB: Found VSETVLI and creating instrument for it: " << Inst
184static std::pair<uint8_t, uint8_t>
198 case RISCV::VLSE16_V:
199 case RISCV::VSSE16_V:
204 case RISCV::VLSE32_V:
205 case RISCV::VSSE32_V:
210 case RISCV::VLSE64_V:
211 case RISCV::VSSE64_V:
222 return std::make_pair(EEW, *EMUL);
226 return Opcode == RISCV::VLM_V || Opcode == RISCV::VSM_V ||
227 Opcode == RISCV::VLE8_V || Opcode == RISCV::VSE8_V ||
228 Opcode == RISCV::VLE16_V || Opcode == RISCV::VSE16_V ||
229 Opcode == RISCV::VLE32_V || Opcode == RISCV::VSE32_V ||
230 Opcode == RISCV::VLE64_V || Opcode == RISCV::VSE64_V ||
231 Opcode == RISCV::VLSE8_V || Opcode == RISCV::VSSE8_V ||
232 Opcode == RISCV::VLSE16_V || Opcode == RISCV::VSSE16_V ||
233 Opcode == RISCV::VLSE32_V || Opcode == RISCV::VSSE32_V ||
234 Opcode == RISCV::VLSE64_V || Opcode == RISCV::VSSE64_V;
241 unsigned SchedClassID =
MCII.get(Opcode).getSchedClass();
246 for (
auto &
I : IVec) {
256 LDBG() <<
"RVCB: Did not use instrumentation to override Opcode.\n";
266 std::optional<unsigned> VPOpcode;
267 if (
const auto *VXMO = RISCV::getVXMemOpInfo(Opcode)) {
270 unsigned IndexEMUL = ((1 << VXMO->Log2IdxEEW) * LMUL) / SEW;
275 if (
const auto *VXP = RISCV::getVSXPseudo(
276 0, VXMO->IsOrdered, VXMO->Log2IdxEEW, LMUL,
278 VPOpcode = VXP->Pseudo;
280 if (
const auto *VXP = RISCV::getVLXPseudo(
281 0, VXMO->IsOrdered, VXMO->Log2IdxEEW, LMUL,
283 VPOpcode = VXP->Pseudo;
288 if (
const auto *VXP =
289 RISCV::getVSXSEGPseudo(VXMO->NF, 0, VXMO->IsOrdered,
290 VXMO->Log2IdxEEW, LMUL, IndexEMUL))
291 VPOpcode = VXP->Pseudo;
293 if (
const auto *VXP =
294 RISCV::getVLXSEGPseudo(VXMO->NF, 0, VXMO->IsOrdered,
295 VXMO->Log2IdxEEW, LMUL, IndexEMUL))
296 VPOpcode = VXP->Pseudo;
302 if (
const auto *
RVV =
303 RISCVVInversePseudosTable::getBaseInfo(Opcode, EMUL, EEW))
304 VPOpcode =
RVV->Pseudo;
307 const auto *
RVV = RISCVVInversePseudosTable::getBaseInfo(Opcode, LMUL, SEW);
310 RVV = RISCVVInversePseudosTable::getBaseInfo(Opcode, LMUL, 0);
313 VPOpcode =
RVV->Pseudo;
318 LDBG() <<
"RVCB: Could not find PseudoInstruction for Opcode "
319 <<
MCII.getName(Opcode)
320 <<
", LMUL=" << (LI ? LI->
getData() :
"Unspecified")
321 <<
", SEW=" << (
SI ?
SI->getData() :
"Unspecified")
322 <<
". Ignoring instrumentation and using original SchedClassID="
323 << SchedClassID <<
'\n';
328 LDBG() <<
"RVCB: Found Pseudo Instruction for Opcode " <<
MCII.getName(Opcode)
330 <<
", SEW=" << (
SI ?
SI->getData() :
"Unspecified")
331 <<
". Overriding original SchedClassID=" << SchedClassID <<
" with "
332 <<
MCII.getName(*VPOpcode) <<
'\n';
333 return MCII.get(*VPOpcode).getSchedClass();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_EXTERNAL_VISIBILITY
#define LDBG(...)
LDBG() is a macro that can be used as a raw_ostream for debugging.
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeRISCVTargetMCA()
Extern function to initialize the targets for the RISC-V backend.
static InstrumentManager * createRISCVInstrumentManager(const MCSubtargetInfo &STI, const MCInstrInfo &MCII)
This file defines the RISCVCustomBehaviour class which inherits from CustomBehaviour.
Instances of this class represent a single low-level machine instruction.
unsigned getOpcode() const
const MCOperand & getOperand(unsigned i) const
Interface to description of machine instruction set.
Generic base class for all target subtargets.
reference emplace_back(ArgTypes &&... Args)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
StringSwitch & Cases(std::initializer_list< StringLiteral > CaseStrings, T Value)
The instances of the Type class are immutable: once they are created, they are never changed.
This class allows targets to optionally customize the logic that resolves scheduling class IDs.
virtual UniqueInstrument createInstrument(StringRef Desc, StringRef Data)
Allocate an Instrument, and return a unique pointer to it.
virtual bool supportsInstrumentType(StringRef Type) const
StringRef getData() const
bool supportsInstrumentType(StringRef Type) const override
unsigned getSchedClassID(const MCInstrInfo &MCII, const MCInst &MCI, const SmallVector< Instrument * > &IVec) const override
Using the Instrument, returns a SchedClassID to use instead of the SchedClassID that belongs to the M...
UniqueInstrument createInstrument(StringRef Desc, StringRef Data) override
Create a Instrument for RISC-V target.
SmallVector< UniqueInstrument > createInstruments(const MCInst &Inst) override
Return a list of unique pointers to Instruments, where each Instrument is allocated by this function.
static bool isDataValid(StringRef Data)
static const StringRef DESC_NAME
static bool isDataValid(StringRef Data)
static const StringRef DESC_NAME
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI std::optional< VLMUL > getSameRatioLMUL(unsigned Ratio, unsigned EEW)
LLVM_ABI unsigned getSEWLMULRatio(unsigned SEW, VLMUL VLMul)
static unsigned getSEW(unsigned VType)
static VLMUL getVLMUL(unsigned VType)
std::unique_ptr< Instrument > UniqueInstrument
static bool opcodeHasEEWAndEMULInfo(unsigned short Opcode)
static std::pair< uint8_t, uint8_t > getEEWAndEMUL(unsigned Opcode, RISCVVType::VLMUL LMUL, uint8_t SEW)
This is an optimization pass for GlobalISel generic memory operations.
Target & getTheRISCV32Target()
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Target & getTheRISCV64Target()
@ Default
The result values are uniform if and only if all operands are uniform.
static void RegisterInstrumentManager(Target &T, Target::InstrumentManagerCtorTy Fn)
RegisterInstrumentManager - Register an InstrumentManager implementation for the given target.