LLVM 20.0.0git
SPIRVISelLowering.cpp
Go to the documentation of this file.
1//===- SPIRVISelLowering.cpp - SPIR-V DAG Lowering Impl ---------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the SPIRVTargetLowering class.
10//
11//===----------------------------------------------------------------------===//
12
13#include "SPIRVISelLowering.h"
14#include "SPIRV.h"
15#include "SPIRVInstrInfo.h"
17#include "SPIRVRegisterInfo.h"
18#include "SPIRVSubtarget.h"
19#include "SPIRVTargetMachine.h"
22#include "llvm/IR/IntrinsicsSPIRV.h"
23
24#define DEBUG_TYPE "spirv-lower"
25
26using namespace llvm;
27
29 LLVMContext &Context, CallingConv::ID CC, EVT VT) const {
30 // This code avoids CallLowering fail inside getVectorTypeBreakdown
31 // on v3i1 arguments. Maybe we need to return 1 for all types.
32 // TODO: remove it once this case is supported by the default implementation.
33 if (VT.isVector() && VT.getVectorNumElements() == 3 &&
34 (VT.getVectorElementType() == MVT::i1 ||
35 VT.getVectorElementType() == MVT::i8))
36 return 1;
37 if (!VT.isVector() && VT.isInteger() && VT.getSizeInBits() <= 64)
38 return 1;
39 return getNumRegisters(Context, VT);
40}
41
44 EVT VT) const {
45 // This code avoids CallLowering fail inside getVectorTypeBreakdown
46 // on v3i1 arguments. Maybe we need to return i32 for all types.
47 // TODO: remove it once this case is supported by the default implementation.
48 if (VT.isVector() && VT.getVectorNumElements() == 3) {
49 if (VT.getVectorElementType() == MVT::i1)
50 return MVT::v4i1;
51 else if (VT.getVectorElementType() == MVT::i8)
52 return MVT::v4i8;
53 }
54 return getRegisterType(Context, VT);
55}
56
58 const CallInst &I,
60 unsigned Intrinsic) const {
61 unsigned AlignIdx = 3;
62 switch (Intrinsic) {
63 case Intrinsic::spv_load:
64 AlignIdx = 2;
65 [[fallthrough]];
66 case Intrinsic::spv_store: {
67 if (I.getNumOperands() >= AlignIdx + 1) {
68 auto *AlignOp = cast<ConstantInt>(I.getOperand(AlignIdx));
69 Info.align = Align(AlignOp->getZExtValue());
70 }
71 Info.flags = static_cast<MachineMemOperand::Flags>(
72 cast<ConstantInt>(I.getOperand(AlignIdx - 1))->getZExtValue());
73 Info.memVT = MVT::i64;
74 // TODO: take into account opaque pointers (don't use getElementType).
75 // MVT::getVT(PtrTy->getElementType());
76 return true;
77 break;
78 }
79 default:
80 break;
81 }
82 return false;
83}
84
85std::pair<unsigned, const TargetRegisterClass *>
87 StringRef Constraint,
88 MVT VT) const {
89 const TargetRegisterClass *RC = nullptr;
90 if (Constraint.starts_with("{"))
91 return std::make_pair(0u, RC);
92
93 if (VT.isFloatingPoint())
94 RC = VT.isVector() ? &SPIRV::vfIDRegClass : &SPIRV::fIDRegClass;
95 else if (VT.isInteger())
96 RC = VT.isVector() ? &SPIRV::vIDRegClass : &SPIRV::iIDRegClass;
97 else
98 RC = &SPIRV::iIDRegClass;
99
100 return std::make_pair(0u, RC);
101}
102
104 SPIRVType *TypeInst = MRI->getVRegDef(OpReg);
105 return TypeInst && TypeInst->getOpcode() == SPIRV::OpFunctionParameter
106 ? TypeInst->getOperand(1).getReg()
107 : OpReg;
108}
109
112 Register OpReg, unsigned OpIdx,
113 SPIRVType *NewPtrType) {
114 Register NewReg = MRI->createGenericVirtualRegister(LLT::scalar(64));
115 MachineIRBuilder MIB(I);
116 bool Res = MIB.buildInstr(SPIRV::OpBitcast)
117 .addDef(NewReg)
118 .addUse(GR.getSPIRVTypeID(NewPtrType))
119 .addUse(OpReg)
121 *STI.getRegBankInfo());
122 if (!Res)
123 report_fatal_error("insert validation bitcast: cannot constrain all uses");
124 MRI->setRegClass(NewReg, &SPIRV::iIDRegClass);
125 GR.assignSPIRVTypeToVReg(NewPtrType, NewReg, MIB.getMF());
126 I.getOperand(OpIdx).setReg(NewReg);
127}
128
130 SPIRVType *OpType, bool ReuseType,
131 bool EmitIR, SPIRVType *ResType,
132 const Type *ResTy) {
133 SPIRV::StorageClass::StorageClass SC =
134 static_cast<SPIRV::StorageClass::StorageClass>(
135 OpType->getOperand(1).getImm());
136 MachineIRBuilder MIB(I);
137 SPIRVType *NewBaseType =
138 ReuseType ? ResType
140 ResTy, MIB, SPIRV::AccessQualifier::ReadWrite, EmitIR);
141 return GR.getOrCreateSPIRVPointerType(NewBaseType, MIB, SC);
142}
143
144// Insert a bitcast before the instruction to keep SPIR-V code valid
145// when there is a type mismatch between results and operand types.
146static void validatePtrTypes(const SPIRVSubtarget &STI,
148 MachineInstr &I, unsigned OpIdx,
149 SPIRVType *ResType, const Type *ResTy = nullptr) {
150 // Get operand type
151 MachineFunction *MF = I.getParent()->getParent();
152 Register OpReg = I.getOperand(OpIdx).getReg();
153 Register OpTypeReg = getTypeReg(MRI, OpReg);
154 SPIRVType *OpType = GR.getSPIRVTypeForVReg(OpTypeReg, MF);
155 if (!ResType || !OpType || OpType->getOpcode() != SPIRV::OpTypePointer)
156 return;
157 // Get operand's pointee type
158 Register ElemTypeReg = OpType->getOperand(2).getReg();
159 SPIRVType *ElemType = GR.getSPIRVTypeForVReg(ElemTypeReg, MF);
160 if (!ElemType)
161 return;
162 // Check if we need a bitcast to make a statement valid
163 bool IsSameMF = MF == ResType->getParent()->getParent();
164 bool IsEqualTypes = IsSameMF ? ElemType == ResType
165 : GR.getTypeForSPIRVType(ElemType) == ResTy;
166 if (IsEqualTypes)
167 return;
168 // There is a type mismatch between results and operand types
169 // and we insert a bitcast before the instruction to keep SPIR-V code valid
170 SPIRVType *NewPtrType =
171 createNewPtrType(GR, I, OpType, IsSameMF, false, ResType, ResTy);
172 if (!GR.isBitcastCompatible(NewPtrType, OpType))
174 "insert validation bitcast: incompatible result and operand types");
175 doInsertBitcast(STI, MRI, GR, I, OpReg, OpIdx, NewPtrType);
176}
177
178// Insert a bitcast before OpGroupWaitEvents if the last argument is a pointer
179// that doesn't point to OpTypeEvent.
183 MachineInstr &I) {
184 constexpr unsigned OpIdx = 2;
185 MachineFunction *MF = I.getParent()->getParent();
186 Register OpReg = I.getOperand(OpIdx).getReg();
187 Register OpTypeReg = getTypeReg(MRI, OpReg);
188 SPIRVType *OpType = GR.getSPIRVTypeForVReg(OpTypeReg, MF);
189 if (!OpType || OpType->getOpcode() != SPIRV::OpTypePointer)
190 return;
191 SPIRVType *ElemType = GR.getSPIRVTypeForVReg(OpType->getOperand(2).getReg());
192 if (!ElemType || ElemType->getOpcode() == SPIRV::OpTypeEvent)
193 return;
194 // Insert a bitcast before the instruction to keep SPIR-V code valid.
195 LLVMContext &Context = MF->getFunction().getContext();
196 SPIRVType *NewPtrType =
197 createNewPtrType(GR, I, OpType, false, true, nullptr,
198 TargetExtType::get(Context, "spirv.Event"));
199 doInsertBitcast(STI, MRI, GR, I, OpReg, OpIdx, NewPtrType);
200}
201
205 Register PtrReg = I.getOperand(0).getReg();
206 MachineFunction *MF = I.getParent()->getParent();
207 Register PtrTypeReg = getTypeReg(MRI, PtrReg);
208 SPIRVType *PtrType = GR.getSPIRVTypeForVReg(PtrTypeReg, MF);
209 SPIRVType *PonteeElemType = PtrType ? GR.getPointeeType(PtrType) : nullptr;
210 if (!PonteeElemType || PonteeElemType->getOpcode() == SPIRV::OpTypeVoid ||
211 (PonteeElemType->getOpcode() == SPIRV::OpTypeInt &&
212 PonteeElemType->getOperand(1).getImm() == 8))
213 return;
214 // To keep the code valid a bitcast must be inserted
215 SPIRV::StorageClass::StorageClass SC =
216 static_cast<SPIRV::StorageClass::StorageClass>(
217 PtrType->getOperand(1).getImm());
218 MachineIRBuilder MIB(I);
219 LLVMContext &Context = MF->getFunction().getContext();
220 SPIRVType *ElemType =
222 SPIRVType *NewPtrType = GR.getOrCreateSPIRVPointerType(ElemType, MIB, SC);
223 doInsertBitcast(STI, MRI, GR, I, PtrReg, 0, NewPtrType);
224}
225
229 unsigned OpIdx) {
230 MachineFunction *MF = I.getParent()->getParent();
231 Register OpReg = I.getOperand(OpIdx).getReg();
232 Register OpTypeReg = getTypeReg(MRI, OpReg);
233 SPIRVType *OpType = GR.getSPIRVTypeForVReg(OpTypeReg, MF);
234 if (!OpType || OpType->getOpcode() != SPIRV::OpTypePointer)
235 return;
236 SPIRVType *ElemType = GR.getSPIRVTypeForVReg(OpType->getOperand(2).getReg());
237 if (!ElemType || ElemType->getOpcode() != SPIRV::OpTypeStruct ||
238 ElemType->getNumOperands() != 2)
239 return;
240 // It's a structure-wrapper around another type with a single member field.
241 SPIRVType *MemberType =
242 GR.getSPIRVTypeForVReg(ElemType->getOperand(1).getReg());
243 if (!MemberType)
244 return;
245 unsigned MemberTypeOp = MemberType->getOpcode();
246 if (MemberTypeOp != SPIRV::OpTypeVector && MemberTypeOp != SPIRV::OpTypeInt &&
247 MemberTypeOp != SPIRV::OpTypeFloat && MemberTypeOp != SPIRV::OpTypeBool)
248 return;
249 // It's a structure-wrapper around a valid type. Insert a bitcast before the
250 // instruction to keep SPIR-V code valid.
251 SPIRV::StorageClass::StorageClass SC =
252 static_cast<SPIRV::StorageClass::StorageClass>(
253 OpType->getOperand(1).getImm());
254 MachineIRBuilder MIB(I);
255 SPIRVType *NewPtrType = GR.getOrCreateSPIRVPointerType(MemberType, MIB, SC);
256 doInsertBitcast(STI, MRI, GR, I, OpReg, OpIdx, NewPtrType);
257}
258
259// Insert a bitcast before the function call instruction to keep SPIR-V code
260// valid when there is a type mismatch between actual and expected types of an
261// argument:
262// %formal = OpFunctionParameter %formal_type
263// ...
264// %res = OpFunctionCall %ty %fun %actual ...
265// implies that %actual is of %formal_type, and in case of opaque pointers.
266// We may need to insert a bitcast to ensure this.
268 MachineRegisterInfo *DefMRI,
269 MachineRegisterInfo *CallMRI,
270 SPIRVGlobalRegistry &GR, MachineInstr &FunCall,
271 MachineInstr *FunDef) {
272 if (FunDef->getOpcode() != SPIRV::OpFunction)
273 return;
274 unsigned OpIdx = 3;
275 for (FunDef = FunDef->getNextNode();
276 FunDef && FunDef->getOpcode() == SPIRV::OpFunctionParameter &&
277 OpIdx < FunCall.getNumOperands();
278 FunDef = FunDef->getNextNode(), OpIdx++) {
279 SPIRVType *DefPtrType = DefMRI->getVRegDef(FunDef->getOperand(1).getReg());
280 SPIRVType *DefElemType =
281 DefPtrType && DefPtrType->getOpcode() == SPIRV::OpTypePointer
282 ? GR.getSPIRVTypeForVReg(DefPtrType->getOperand(2).getReg(),
283 DefPtrType->getParent()->getParent())
284 : nullptr;
285 if (DefElemType) {
286 const Type *DefElemTy = GR.getTypeForSPIRVType(DefElemType);
287 // validatePtrTypes() works in the context if the call site
288 // When we process historical records about forward calls
289 // we need to switch context to the (forward) call site and
290 // then restore it back to the current machine function.
291 MachineFunction *CurMF =
292 GR.setCurrentFunc(*FunCall.getParent()->getParent());
293 validatePtrTypes(STI, CallMRI, GR, FunCall, OpIdx, DefElemType,
294 DefElemTy);
295 GR.setCurrentFunc(*CurMF);
296 }
297 }
298}
299
300// Ensure there is no mismatch between actual and expected arg types: calls
301// with a processed definition. Return Function pointer if it's a forward
302// call (ahead of definition), and nullptr otherwise.
304 MachineRegisterInfo *CallMRI,
306 MachineInstr &FunCall) {
307 const GlobalValue *GV = FunCall.getOperand(2).getGlobal();
308 const Function *F = dyn_cast<Function>(GV);
309 MachineInstr *FunDef =
310 const_cast<MachineInstr *>(GR.getFunctionDefinition(F));
311 if (!FunDef)
312 return F;
313 MachineRegisterInfo *DefMRI = &FunDef->getParent()->getParent()->getRegInfo();
314 validateFunCallMachineDef(STI, DefMRI, CallMRI, GR, FunCall, FunDef);
315 return nullptr;
316}
317
318// Ensure there is no mismatch between actual and expected arg types: calls
319// ahead of a processed definition.
322 MachineInstr &FunDef) {
323 const Function *F = GR.getFunctionByDefinition(&FunDef);
325 for (MachineInstr *FunCall : *FwdCalls) {
326 MachineRegisterInfo *CallMRI =
327 &FunCall->getParent()->getParent()->getRegInfo();
328 validateFunCallMachineDef(STI, DefMRI, CallMRI, GR, *FunCall, &FunDef);
329 }
330}
331
332// Validation of an access chain.
335 SPIRVType *BaseTypeInst = GR.getSPIRVTypeForVReg(I.getOperand(0).getReg());
336 if (BaseTypeInst && BaseTypeInst->getOpcode() == SPIRV::OpTypePointer) {
337 SPIRVType *BaseElemType =
338 GR.getSPIRVTypeForVReg(BaseTypeInst->getOperand(2).getReg());
339 validatePtrTypes(STI, MRI, GR, I, 2, BaseElemType);
340 }
341}
342
343// TODO: the logic of inserting additional bitcast's is to be moved
344// to pre-IRTranslation passes eventually
346 // finalizeLowering() is called twice (see GlobalISel/InstructionSelect.cpp)
347 // We'd like to avoid the needless second processing pass.
348 if (ProcessedMF.find(&MF) != ProcessedMF.end())
349 return;
350
353 GR.setCurrentFunc(MF);
354 for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
356 for (MachineBasicBlock::iterator MBBI = MBB->begin(), MBBE = MBB->end();
357 MBBI != MBBE;) {
358 MachineInstr &MI = *MBBI++;
359 switch (MI.getOpcode()) {
360 case SPIRV::OpAtomicLoad:
361 case SPIRV::OpAtomicExchange:
362 case SPIRV::OpAtomicCompareExchange:
363 case SPIRV::OpAtomicCompareExchangeWeak:
364 case SPIRV::OpAtomicIIncrement:
365 case SPIRV::OpAtomicIDecrement:
366 case SPIRV::OpAtomicIAdd:
367 case SPIRV::OpAtomicISub:
368 case SPIRV::OpAtomicSMin:
369 case SPIRV::OpAtomicUMin:
370 case SPIRV::OpAtomicSMax:
371 case SPIRV::OpAtomicUMax:
372 case SPIRV::OpAtomicAnd:
373 case SPIRV::OpAtomicOr:
374 case SPIRV::OpAtomicXor:
375 // for the above listed instructions
376 // OpAtomicXXX <ResType>, ptr %Op, ...
377 // implies that %Op is a pointer to <ResType>
378 case SPIRV::OpLoad:
379 // OpLoad <ResType>, ptr %Op implies that %Op is a pointer to <ResType>
380 validatePtrTypes(STI, MRI, GR, MI, 2,
381 GR.getSPIRVTypeForVReg(MI.getOperand(0).getReg()));
382 break;
383 case SPIRV::OpAtomicStore:
384 // OpAtomicStore ptr %Op, <Scope>, <Mem>, <Obj>
385 // implies that %Op points to the <Obj>'s type
386 validatePtrTypes(STI, MRI, GR, MI, 0,
387 GR.getSPIRVTypeForVReg(MI.getOperand(3).getReg()));
388 break;
389 case SPIRV::OpStore:
390 // OpStore ptr %Op, <Obj> implies that %Op points to the <Obj>'s type
391 validatePtrTypes(STI, MRI, GR, MI, 0,
392 GR.getSPIRVTypeForVReg(MI.getOperand(1).getReg()));
393 break;
394 case SPIRV::OpPtrCastToGeneric:
395 case SPIRV::OpGenericCastToPtr:
396 validateAccessChain(STI, MRI, GR, MI);
397 break;
398 case SPIRV::OpInBoundsPtrAccessChain:
399 if (MI.getNumOperands() == 4)
400 validateAccessChain(STI, MRI, GR, MI);
401 break;
402
403 case SPIRV::OpFunctionCall:
404 // ensure there is no mismatch between actual and expected arg types:
405 // calls with a processed definition
406 if (MI.getNumOperands() > 3)
407 if (const Function *F = validateFunCall(STI, MRI, GR, MI))
408 GR.addForwardCall(F, &MI);
409 break;
410 case SPIRV::OpFunction:
411 // ensure there is no mismatch between actual and expected arg types:
412 // calls ahead of a processed definition
413 validateForwardCalls(STI, MRI, GR, MI);
414 break;
415
416 // ensure that LLVM IR bitwise instructions result in logical SPIR-V
417 // instructions when applied to bool type
418 case SPIRV::OpBitwiseOrS:
419 case SPIRV::OpBitwiseOrV:
420 if (GR.isScalarOrVectorOfType(MI.getOperand(1).getReg(),
421 SPIRV::OpTypeBool))
422 MI.setDesc(STI.getInstrInfo()->get(SPIRV::OpLogicalOr));
423 break;
424 case SPIRV::OpBitwiseAndS:
425 case SPIRV::OpBitwiseAndV:
426 if (GR.isScalarOrVectorOfType(MI.getOperand(1).getReg(),
427 SPIRV::OpTypeBool))
428 MI.setDesc(STI.getInstrInfo()->get(SPIRV::OpLogicalAnd));
429 break;
430 case SPIRV::OpBitwiseXorS:
431 case SPIRV::OpBitwiseXorV:
432 if (GR.isScalarOrVectorOfType(MI.getOperand(1).getReg(),
433 SPIRV::OpTypeBool))
434 MI.setDesc(STI.getInstrInfo()->get(SPIRV::OpLogicalNotEqual));
435 break;
436 case SPIRV::OpLifetimeStart:
437 case SPIRV::OpLifetimeStop:
438 if (MI.getOperand(1).getImm() > 0)
439 validateLifetimeStart(STI, MRI, GR, MI);
440 break;
441 case SPIRV::OpGroupAsyncCopy:
442 validateGroupAsyncCopyPtr(STI, MRI, GR, MI, 3);
443 validateGroupAsyncCopyPtr(STI, MRI, GR, MI, 4);
444 break;
445 case SPIRV::OpGroupWaitEvents:
446 // OpGroupWaitEvents ..., ..., <pointer to OpTypeEvent>
448 break;
449 case SPIRV::OpConstantI: {
450 SPIRVType *Type = GR.getSPIRVTypeForVReg(MI.getOperand(1).getReg());
451 if (Type->getOpcode() != SPIRV::OpTypeInt && MI.getOperand(2).isImm() &&
452 MI.getOperand(2).getImm() == 0) {
453 // Validate the null constant of a target extension type
454 MI.setDesc(STI.getInstrInfo()->get(SPIRV::OpConstantNull));
455 for (unsigned i = MI.getNumOperands() - 1; i > 1; --i)
456 MI.removeOperand(i);
457 }
458 } break;
459 }
460 }
461 }
462 ProcessedMF.insert(&MF);
464}
unsigned const MachineRegisterInfo * MRI
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator MBBI
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
unsigned const TargetRegisterInfo * TRI
static void doInsertBitcast(const SPIRVSubtarget &STI, MachineRegisterInfo *MRI, SPIRVGlobalRegistry &GR, MachineInstr &I, Register OpReg, unsigned OpIdx, SPIRVType *NewPtrType)
static void validateLifetimeStart(const SPIRVSubtarget &STI, MachineRegisterInfo *MRI, SPIRVGlobalRegistry &GR, MachineInstr &I)
static void validateGroupAsyncCopyPtr(const SPIRVSubtarget &STI, MachineRegisterInfo *MRI, SPIRVGlobalRegistry &GR, MachineInstr &I, unsigned OpIdx)
static void validateGroupWaitEventsPtr(const SPIRVSubtarget &STI, MachineRegisterInfo *MRI, SPIRVGlobalRegistry &GR, MachineInstr &I)
Register getTypeReg(MachineRegisterInfo *MRI, Register OpReg)
void validateAccessChain(const SPIRVSubtarget &STI, MachineRegisterInfo *MRI, SPIRVGlobalRegistry &GR, MachineInstr &I)
void validateFunCallMachineDef(const SPIRVSubtarget &STI, MachineRegisterInfo *DefMRI, MachineRegisterInfo *CallMRI, SPIRVGlobalRegistry &GR, MachineInstr &FunCall, MachineInstr *FunDef)
void validateForwardCalls(const SPIRVSubtarget &STI, MachineRegisterInfo *DefMRI, SPIRVGlobalRegistry &GR, MachineInstr &FunDef)
const Function * validateFunCall(const SPIRVSubtarget &STI, MachineRegisterInfo *CallMRI, SPIRVGlobalRegistry &GR, MachineInstr &FunCall)
static void validatePtrTypes(const SPIRVSubtarget &STI, MachineRegisterInfo *MRI, SPIRVGlobalRegistry &GR, MachineInstr &I, unsigned OpIdx, SPIRVType *ResType, const Type *ResTy=nullptr)
static SPIRVType * createNewPtrType(SPIRVGlobalRegistry &GR, MachineInstr &I, SPIRVType *OpType, bool ReuseType, bool EmitIR, SPIRVType *ResType, const Type *ResTy)
This class represents a function call, abstracting a target machine's calling convention.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition: Function.cpp:380
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
Definition: LowLevelType.h:42
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
Machine Value Type.
bool isVector() const
Return true if this is a vector value type.
bool isInteger() const
Return true if this is an integer or a vector integer type.
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
Helper class to build MachineInstr.
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
MachineFunction & getMF()
Getter for the function we currently build.
bool constrainAllUses(const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI) const
const MachineInstrBuilder & addUse(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
const MachineInstrBuilder & addDef(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
Representation of each machine instruction.
Definition: MachineInstr.h:69
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:569
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:346
unsigned getNumOperands() const
Retuns the total number of operands.
Definition: MachineInstr.h:572
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:579
Flags
Flags values. These may be or'd together.
const GlobalValue * getGlobal() const
int64_t getImm() const
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
MachineInstr * getVRegDef(Register Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
SPIRVType * getSPIRVTypeForVReg(Register VReg, const MachineFunction *MF=nullptr) const
void addForwardCall(const Function *F, MachineInstr *MI)
const Type * getTypeForSPIRVType(const SPIRVType *Ty) const
bool isBitcastCompatible(const SPIRVType *Type1, const SPIRVType *Type2) const
const MachineInstr * getFunctionDefinition(const Function *F)
SPIRVType * getPointeeType(SPIRVType *PtrType)
Register getSPIRVTypeID(const SPIRVType *SpirvType) const
SPIRVType * getOrCreateSPIRVType(const Type *Type, MachineIRBuilder &MIRBuilder, SPIRV::AccessQualifier::AccessQualifier AQ=SPIRV::AccessQualifier::ReadWrite, bool EmitIR=true)
void assignSPIRVTypeToVReg(SPIRVType *Type, Register VReg, MachineFunction &MF)
SmallPtrSet< MachineInstr *, 8 > * getForwardCalls(const Function *F)
bool isScalarOrVectorOfType(Register VReg, unsigned TypeOpcode) const
MachineFunction * setCurrentFunc(MachineFunction &MF)
SPIRVType * getOrCreateSPIRVPointerType(SPIRVType *BaseType, MachineIRBuilder &MIRBuilder, SPIRV::StorageClass::StorageClass SClass=SPIRV::StorageClass::Function)
const Function * getFunctionByDefinition(const MachineInstr *MI)
const SPIRVInstrInfo * getInstrInfo() const override
SPIRVGlobalRegistry * getSPIRVGlobalRegistry() const
const SPIRVRegisterInfo * getRegisterInfo() const override
const RegisterBankInfo * getRegBankInfo() const override
unsigned getNumRegisters(LLVMContext &Context, EVT VT, std::optional< MVT > RegisterVT=std::nullopt) const override
Return the number of registers that this ValueType will eventually require.
unsigned getNumRegistersForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const override
Certain targets require unusual breakdowns of certain types.
MVT getRegisterTypeForCallingConv(LLVMContext &Context, CallingConv::ID CC, EVT VT) const override
Certain combinations of ABIs, Targets and features require that types are legal for some operations a...
bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I, MachineFunction &MF, unsigned Intrinsic) const override
Given an intrinsic, checks if on the target the intrinsic will need to map to a MemIntrinsicNode (tou...
void finalizeLowering(MachineFunction &MF) const override
Execute target specific actions to finalize target lowering.
std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const override
Given a physical register constraint (e.g.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:502
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:250
static TargetExtType * get(LLVMContext &Context, StringRef Name, ArrayRef< Type * > Types=std::nullopt, ArrayRef< unsigned > Ints=std::nullopt)
Return a target extension type having the specified name and optional type and integer parameters.
Definition: Type.cpp:784
virtual void finalizeLowering(MachineFunction &MF) const
Execute target specific actions to finalize target lowering.
MVT getRegisterType(MVT VT) const
Return the type of registers that this ValueType will eventually require.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
static IntegerType * getInt8Ty(LLVMContext &C)
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
Definition: ilist_node.h:353
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
Extended Value Type.
Definition: ValueTypes.h:35
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:359
bool isVector() const
Return true if this is a vector value type.
Definition: ValueTypes.h:168
EVT getVectorElementType() const
Given a vector type, return the type of each element.
Definition: ValueTypes.h:319
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition: ValueTypes.h:327
bool isInteger() const
Return true if this is an integer or a vector integer type.
Definition: ValueTypes.h:152