LLVM: lib/Target/RISCV/MCA/RISCVCustomBehaviour.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
22
23#define DEBUG_TYPE "llvm-mca-riscv-custombehaviour"
24
33
34#define GET_RISCVBaseVXMemOpTable_IMPL
35#include "RISCVGenSearchableTables.inc"
36}
37
38namespace llvm {
39namespace mca {
40
42
44
46 .Cases({"M1", "M2", "M4", "M8", "MF2", "MF4", "MF8"}, true)
48}
49
51
52
54 "Cannot get LMUL because invalid Data value");
55
57 .Case("M1", 0b000)
58 .Case("M2", 0b001)
59 .Case("M4", 0b010)
60 .Case("M8", 0b011)
61 .Case("MF2", 0b111)
62 .Case("MF4", 0b110)
63 .Case("MF8", 0b101);
64}
65
67
69
71 .Cases({"E8", "E16", "E32", "E64"}, true)
73}
74
76
77
79
81 .Case("E8", 8)
82 .Case("E16", 16)
83 .Case("E32", 32)
84 .Case("E64", 64);
85}
86
93
99 LDBG() << "RVCB: Bad data for instrument kind " << Desc << ": " << Data
100 << '\n';
101 return nullptr;
102 }
103 return std::make_unique(Data);
104 }
105
108 LDBG() << "RVCB: Bad data for instrument kind " << Desc << ": " << Data
109 << '\n';
110 return nullptr;
111 }
112 return std::make_unique(Data);
113 }
114
115 LDBG() << "RVCB: Creating default instrument for Desc: " << Desc << '\n';
117}
118
121 if (Inst.getOpcode() == RISCV::VSETVLI ||
122 Inst.getOpcode() == RISCV::VSETIVLI) {
123 LDBG() << "RVCB: Found VSETVLI and creating instrument for it: " << Inst
124 << "\n";
127
129 switch (VLMUL) {
131 LMUL = "M1";
132 break;
134 LMUL = "M2";
135 break;
137 LMUL = "M4";
138 break;
140 LMUL = "M8";
141 break;
143 LMUL = "MF2";
144 break;
146 LMUL = "MF4";
147 break;
149 LMUL = "MF8";
150 break;
152 llvm_unreachable("Cannot create instrument for LMUL_RESERVED");
153 }
157
160 switch (SEW) {
161 case 8:
162 SEWStr = "E8";
163 break;
164 case 16:
165 SEWStr = "E16";
166 break;
167 case 32:
168 SEWStr = "E32";
169 break;
170 case 64:
171 SEWStr = "E64";
172 break;
173 default:
175 }
178
179 return Instruments;
180 }
182}
183
184static std::pair<uint8_t, uint8_t>
187 switch (Opcode) {
188 case RISCV::VLM_V:
189 case RISCV::VSM_V:
190 case RISCV::VLE8_V:
191 case RISCV::VSE8_V:
192 case RISCV::VLSE8_V:
193 case RISCV::VSSE8_V:
194 EEW = 8;
195 break;
196 case RISCV::VLE16_V:
197 case RISCV::VSE16_V:
198 case RISCV::VLSE16_V:
199 case RISCV::VSSE16_V:
200 EEW = 16;
201 break;
202 case RISCV::VLE32_V:
203 case RISCV::VSE32_V:
204 case RISCV::VLSE32_V:
205 case RISCV::VSSE32_V:
206 EEW = 32;
207 break;
208 case RISCV::VLE64_V:
209 case RISCV::VSE64_V:
210 case RISCV::VLSE64_V:
211 case RISCV::VSSE64_V:
212 EEW = 64;
213 break;
214 default:
216 }
217
219 if (!EEW)
221 return std::make_pair(EEW, *EMUL);
222}
223
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;
234}
235
239 unsigned short Opcode = MCI.getOpcode();
240 unsigned SchedClassID = MCII.get(Opcode).getSchedClass();
241
242
245 for (auto &I : IVec) {
250 }
251
252
253
254 if (!LI) {
255 LDBG() << "RVCB: Did not use instrumentation to override Opcode.\n";
256 return SchedClassID;
257 }
259
260
261
262
264
265 std::optional VPOpcode;
266 if (const auto *VXMO = RISCV::getVXMemOpInfo(Opcode)) {
267
268
269 unsigned IndexEMUL = ((1 << VXMO->Log2IdxEEW) * LMUL) / SEW;
270
271 if (!VXMO->NF) {
272
273 if (VXMO->IsStore) {
274 if (const auto *VXP = RISCV::getVSXPseudo(
275 0, VXMO->IsOrdered, VXMO->Log2IdxEEW, LMUL,
276 IndexEMUL))
277 VPOpcode = VXP->Pseudo;
278 } else {
279 if (const auto *VXP = RISCV::getVLXPseudo(
280 0, VXMO->IsOrdered, VXMO->Log2IdxEEW, LMUL,
281 IndexEMUL))
282 VPOpcode = VXP->Pseudo;
283 }
284 } else {
285
286 if (VXMO->IsStore) {
287 if (const auto *VXP =
288 RISCV::getVSXSEGPseudo(VXMO->NF, 0, VXMO->IsOrdered,
289 VXMO->Log2IdxEEW, LMUL, IndexEMUL))
290 VPOpcode = VXP->Pseudo;
291 } else {
292 if (const auto *VXP =
293 RISCV::getVLXSEGPseudo(VXMO->NF, 0, VXMO->IsOrdered,
294 VXMO->Log2IdxEEW, LMUL, IndexEMUL))
295 VPOpcode = VXP->Pseudo;
296 }
297 }
300 auto [EEW, EMUL] = getEEWAndEMUL(Opcode, VLMUL, SEW);
301 if (const auto *RVV =
302 RISCVVInversePseudosTable::getBaseInfo(Opcode, EMUL, EEW))
303 VPOpcode = RVV->Pseudo;
304 } else {
305
306 const auto *RVV = RISCVVInversePseudosTable::getBaseInfo(Opcode, LMUL, SEW);
307
308 if ()
309 RVV = RISCVVInversePseudosTable::getBaseInfo(Opcode, LMUL, 0);
310
312 VPOpcode = RVV->Pseudo;
313 }
314
315
316 if (!VPOpcode) {
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';
323 return SchedClassID;
324 }
325
326
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';
332 return MCII.get(*VPOpcode).getSchedClass();
333}
334
335}
336}
337
338using namespace llvm;
339using namespace mca;
340
346
347
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.
Definition RISCVCustomBehaviour.cpp:349
static InstrumentManager * createRISCVInstrumentManager(const MCSubtargetInfo &STI, const MCInstrInfo &MCII)
Definition RISCVCustomBehaviour.cpp:342
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
Definition RISCVCustomBehaviour.cpp:87
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...
Definition RISCVCustomBehaviour.cpp:236
UniqueInstrument createInstrument(StringRef Desc, StringRef Data) override
Create a Instrument for RISC-V target.
Definition RISCVCustomBehaviour.cpp:95
SmallVector< UniqueInstrument > createInstruments(const MCInst &Inst) override
Return a list of unique pointers to Instruments, where each Instrument is allocated by this function.
Definition RISCVCustomBehaviour.cpp:120
uint8_t getLMUL() const
Definition RISCVCustomBehaviour.cpp:50
static bool isDataValid(StringRef Data)
Definition RISCVCustomBehaviour.cpp:43
static const StringRef DESC_NAME
static bool isDataValid(StringRef Data)
Definition RISCVCustomBehaviour.cpp:68
static const StringRef DESC_NAME
uint8_t getSEW() const
Definition RISCVCustomBehaviour.cpp:75
#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)
Definition RISCVCustomBehaviour.cpp:224
static std::pair< uint8_t, uint8_t > getEEWAndEMUL(unsigned Opcode, RISCVVType::VLMUL LMUL, uint8_t SEW)
Definition RISCVCustomBehaviour.cpp:185
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.
unsigned NF
Definition RISCVCustomBehaviour.cpp:30
unsigned Log2IdxEEW
Definition RISCVCustomBehaviour.cpp:27
unsigned IsOrdered
Definition RISCVCustomBehaviour.cpp:28
unsigned IsStore
Definition RISCVCustomBehaviour.cpp:29
unsigned BaseInstr
Definition RISCVCustomBehaviour.cpp:31
static void RegisterInstrumentManager(Target &T, Target::InstrumentManagerCtorTy Fn)
RegisterInstrumentManager - Register an InstrumentManager implementation for the given target.