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:
221 return std::make_pair(EEW, *EMUL);
225 return Opcode == RISCV::VLM_V || Opcode == RISCV::VSM_V ||
226 Opcode == RISCV::VLE8_V || Opcode == RISCV::VSE8_V ||
227 Opcode == RISCV::VLE16_V || Opcode == RISCV::VSE16_V ||
228 Opcode == RISCV::VLE32_V || Opcode == RISCV::VSE32_V ||
229 Opcode == RISCV::VLE64_V || Opcode == RISCV::VSE64_V ||
230 Opcode == RISCV::VLSE8_V || Opcode == RISCV::VSSE8_V ||
231 Opcode == RISCV::VLSE16_V || Opcode == RISCV::VSSE16_V ||
232 Opcode == RISCV::VLSE32_V || Opcode == RISCV::VSSE32_V ||
233 Opcode == RISCV::VLSE64_V || Opcode == RISCV::VSSE64_V;
240 unsigned SchedClassID =
MCII.get(Opcode).getSchedClass();
245 for (
auto &
I : IVec) {
255 LDBG() <<
"RVCB: Did not use instrumentation to override Opcode.\n";
265 std::optional<unsigned> VPOpcode;
266 if (
const auto *VXMO = RISCV::getVXMemOpInfo(Opcode)) {
269 unsigned IndexEMUL = ((1 << VXMO->Log2IdxEEW) * LMUL) / SEW;
274 if (
const auto *VXP = RISCV::getVSXPseudo(
275 0, VXMO->IsOrdered, VXMO->Log2IdxEEW, LMUL,
277 VPOpcode = VXP->Pseudo;
279 if (
const auto *VXP = RISCV::getVLXPseudo(
280 0, VXMO->IsOrdered, VXMO->Log2IdxEEW, LMUL,
282 VPOpcode = VXP->Pseudo;
287 if (
const auto *VXP =
288 RISCV::getVSXSEGPseudo(VXMO->NF, 0, VXMO->IsOrdered,
289 VXMO->Log2IdxEEW, LMUL, IndexEMUL))
290 VPOpcode = VXP->Pseudo;
292 if (
const auto *VXP =
293 RISCV::getVLXSEGPseudo(VXMO->NF, 0, VXMO->IsOrdered,
294 VXMO->Log2IdxEEW, LMUL, IndexEMUL))
295 VPOpcode = VXP->Pseudo;
301 if (
const auto *
RVV =
302 RISCVVInversePseudosTable::getBaseInfo(Opcode, EMUL, EEW))
303 VPOpcode =
RVV->Pseudo;
306 const auto *
RVV = RISCVVInversePseudosTable::getBaseInfo(Opcode, LMUL, SEW);
309 RVV = RISCVVInversePseudosTable::getBaseInfo(Opcode, LMUL, 0);
312 VPOpcode =
RVV->Pseudo;
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';
327 LDBG() <<
"RVCB: Found Pseudo Instruction for Opcode " <<
MCII.getName(Opcode)
329 <<
", SEW=" << (
SI ?
SI->getData() :
"Unspecified")
330 <<
". Overriding original SchedClassID=" << SchedClassID <<
" with "
331 <<
MCII.getName(*VPOpcode) <<
'\n';
332 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(StringLiteral S0, StringLiteral S1, 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 SEW, VLMUL VLMUL, unsigned EEW)
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()
static void RegisterInstrumentManager(Target &T, Target::InstrumentManagerCtorTy Fn)
RegisterInstrumentManager - Register an InstrumentManager implementation for the given target.