31 : PointerSize(PointerSize), Bound(0) {}
62 SPIRV::AccessQualifier::AccessQualifier AccessQual,
bool EmitIR) {
72 VRegToTypeMap[&MF][VReg] = SpirvType;
78 MRI.setRegClass(Res, &SPIRV::TYPERegClass);
84 MRI.setRegClass(Res, &SPIRV::TYPERegClass);
89 return MIRBuilder.
buildInstr(SPIRV::OpTypeBool)
93unsigned SPIRVGlobalRegistry::adjustOpTypeIntWidth(
unsigned Width)
const {
97 if (
ST.canUseExtension(
98 SPIRV::Extension::SPV_INTEL_arbitrary_precision_integers))
102 else if (Width <= 16)
104 else if (Width <= 32)
111SPIRVType *SPIRVGlobalRegistry::getOpTypeInt(
unsigned Width,
114 Width = adjustOpTypeIntWidth(Width);
117 if (
ST.canUseExtension(
118 SPIRV::Extension::SPV_INTEL_arbitrary_precision_integers)) {
120 .
addImm(SPIRV::Extension::SPV_INTEL_arbitrary_precision_integers);
122 .
addImm(SPIRV::Capability::ArbitraryPrecisionIntegersINTEL);
124 auto MIB = MIRBuilder.
buildInstr(SPIRV::OpTypeInt)
127 .
addImm(IsSigned ? 1 : 0);
133 auto MIB = MIRBuilder.
buildInstr(SPIRV::OpTypeFloat)
140 return MIRBuilder.
buildInstr(SPIRV::OpTypeVoid)
149 assert((EleOpc == SPIRV::OpTypeInt || EleOpc == SPIRV::OpTypeFloat ||
150 EleOpc == SPIRV::OpTypeBool) &&
151 "Invalid vector element type");
153 auto MIB = MIRBuilder.
buildInstr(SPIRV::OpTypeVector)
160std::tuple<Register, ConstantInt *, bool>
170 bool NewInstr =
false;
188 return std::make_tuple(Res, CI, NewInstr);
191std::tuple<Register, ConstantFP *, bool, unsigned>
192SPIRVGlobalRegistry::getOrCreateConstFloatReg(
APFloat Val,
SPIRVType *SpvType,
196 const Type *LLVMFloatTy;
206 bool NewInstr =
false;
208 auto *
const CI = ConstantFP::get(Ctx, Val);
225 return std::make_tuple(Res, CI, NewInstr,
BitWidth);
238 getOrCreateConstFloatReg(Val, SpvType,
nullptr, &
I, &
TII);
241 if (!New && (!
I.getOperand(0).isReg() || Res !=
I.getOperand(0).getReg()))
247 MIB =
BuildMI(BB,
I,
I.getDebugLoc(),
TII.get(SPIRV::OpConstantNull))
251 MIB =
BuildMI(BB,
I,
I.getDebugLoc(),
TII.get(SPIRV::OpConstantF))
260 *ST.getRegisterInfo(), *ST.getRegBankInfo());
272 std::tie(Res, CI, New) =
273 getOrCreateConstIntReg(Val, SpvType,
nullptr, &
I, &
TII);
276 if (!New && (!
I.getOperand(0).isReg() || Res !=
I.getOperand(0).getReg()))
280 if (Val || !ZeroAsNull) {
281 MIB =
BuildMI(BB,
I,
I.getDebugLoc(),
TII.get(SPIRV::OpConstantI))
286 MIB =
BuildMI(BB,
I,
I.getDebugLoc(),
TII.get(SPIRV::OpConstantNull))
292 *ST.getRegisterInfo(), *ST.getRegBankInfo());
300 auto &MF = MIRBuilder.
getMF();
307 const auto ConstInt =
308 ConstantInt::get(
const_cast<IntegerType *
>(LLVMIntTy), Val);
313 Res = MF.getRegInfo().createGenericVirtualRegister(LLTy);
314 MF.getRegInfo().setRegClass(Res, &SPIRV::iIDRegClass);
316 SPIRV::AccessQualifier::ReadWrite, EmitIR);
317 DT.
add(ConstInt, &MIRBuilder.
getMF(), Res);
325 MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantI)
330 MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantNull)
336 *Subtarget.getRegisterInfo(),
337 *Subtarget.getRegBankInfo());
346 auto &MF = MIRBuilder.
getMF();
347 auto &Ctx = MF.getFunction().getContext();
353 const auto ConstFP = ConstantFP::get(Ctx, Val);
356 Res = MF.getRegInfo().createGenericVirtualRegister(
LLT::scalar(32));
357 MF.getRegInfo().setRegClass(Res, &SPIRV::fIDRegClass);
359 DT.
add(ConstFP, &MF, Res);
362 MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantF)
365 addNumImm(ConstFP->getValueAPF().bitcastToAPInt(), MIB);
371Register SPIRVGlobalRegistry::getOrCreateBaseRegister(
375 if (SpvType->
getOpcode() == SPIRV::OpTypeVector ||
376 SpvType->
getOpcode() == SPIRV::OpTypeArray) {
380 if (
Type->getOpcode() == SPIRV::OpTypeFloat) {
383 SpvBaseType,
TII, ZeroAsNull);
385 assert(
Type->getOpcode() == SPIRV::OpTypeInt);
388 SpvBaseType,
TII, ZeroAsNull);
391Register SPIRVGlobalRegistry::getOrCreateCompositeOrNull(
394 unsigned ElemCnt,
bool ZeroAsNull) {
406 getOrCreateBaseRegister(Val,
I, SpvType,
TII,
BitWidth, ZeroAsNull);
419 MIB =
BuildMI(BB,
I,
I.getDebugLoc(),
TII.get(SPIRV::OpConstantComposite))
422 for (
unsigned i = 0; i < ElemCnt; ++i)
425 MIB =
BuildMI(BB,
I,
I.getDebugLoc(),
TII.get(SPIRV::OpConstantNull))
431 *Subtarget.getRegisterInfo(),
432 *Subtarget.getRegBankInfo());
448 auto *ConstVal = ConstantInt::get(LLVMBaseTy, Val);
452 return getOrCreateCompositeOrNull(ConstVal,
I, SpvType,
TII, ConstVec, BW,
467 auto *ConstVal = ConstantFP::get(LLVMBaseTy, Val);
471 return getOrCreateCompositeOrNull(ConstVal,
I, SpvType,
TII, ConstVec, BW,
481 const ArrayType *LLVMArrTy = cast<ArrayType>(LLVMTy);
483 Constant *CI = ConstantInt::get(LLVMBaseTy, Val);
496 ConstantInt::get(LLVMBaseTy, Val), ConstantInt::get(LLVMBaseTy, Num)});
497 return getOrCreateCompositeOrNull(CI,
I, SpvType,
TII, UniqueKey, BW,
501Register SPIRVGlobalRegistry::getOrCreateIntCompositeOrNull(
522 auto MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantComposite)
525 for (
unsigned i = 0; i < ElemCnt; ++i)
546 const auto ConstInt = ConstantInt::get(LLVMBaseTy, Val);
550 return getOrCreateIntCompositeOrNull(Val, MIRBuilder, SpvType, EmitIR,
584 MIRBuilder)) ==
nullptr)
591 auto Res = MIRBuilder.
buildInstr(SPIRV::OpConstantSampler)
597 assert(Res->getOperand(0).isReg());
598 return Res->getOperand(0).getReg();
603 const GlobalValue *GV, SPIRV::StorageClass::StorageClass Storage,
606 bool IsInstSelector) {
609 GVar = cast<const GlobalVariable>(GV);
614 GVar = M->getGlobalVariable(
Name);
615 if (GVar ==
nullptr) {
631 auto MIB = MIRBuilder.
buildInstr(SPIRV::OpVariable)
642 if (IsInstSelector) {
645 *Subtarget.getRegisterInfo(),
646 *Subtarget.getRegBankInfo());
649 DT.
add(GVar, &MIRBuilder.
getMF(), Reg);
653 assert(
MRI->getType(ResVReg).isPointer() &&
"Pointer type is expected");
654 if (Reg != ResVReg) {
657 MRI->setType(Reg, RegLLTy);
664 if (!DefType || DefType !=
BaseType)
676 if (IsConst && ST.isOpenCLEnv())
681 buildOpDecorate(Reg, MIRBuilder, SPIRV::Decoration::Alignment, {Alignment});
688 SPIRV::BuiltIn::BuiltIn BuiltInId;
691 {
static_cast<uint32_t>(BuiltInId)});
697 if (GVar && (GVarMD = GVar->
getMetadata(
"spirv.Decorations")) !=
nullptr)
708 "Invalid array element type");
711 auto MIB = MIRBuilder.
buildInstr(SPIRV::OpTypeArray)
733 for (
const auto &Elem : Ty->
elements()) {
736 "Invalid struct element type");
741 for (
const auto &Ty : FieldTypes)
750SPIRVType *SPIRVGlobalRegistry::getOrCreateSpecialType(
752 SPIRV::AccessQualifier::AccessQualifier AccQual) {
757SPIRVType *SPIRVGlobalRegistry::getOpTypePointer(
758 SPIRV::StorageClass::StorageClass SC,
SPIRVType *ElemType,
762 return MIRBuilder.
buildInstr(SPIRV::OpTypePointer)
768SPIRVType *SPIRVGlobalRegistry::getOpTypeForwardPointer(
770 return MIRBuilder.
buildInstr(SPIRV::OpTypeForwardPointer)
775SPIRVType *SPIRVGlobalRegistry::getOpTypeFunction(
778 auto MIB = MIRBuilder.
buildInstr(SPIRV::OpTypeFunction)
781 for (
const SPIRVType *ArgType : ArgTypes)
793 SPIRVType *SpirvType = getOpTypeFunction(RetType, ArgTypes, MIRBuilder);
795 return finishCreatingSPIRVType(Ty, SpirvType);
798SPIRVType *SPIRVGlobalRegistry::findSPIRVType(
800 SPIRV::AccessQualifier::AccessQualifier AccQual,
bool EmitIR) {
801 Ty = adjustIntTypeByWidth(Ty);
805 if (ForwardPointerTypes.contains(Ty))
806 return ForwardPointerTypes[Ty];
807 return restOfCreateSPIRVType(Ty, MIRBuilder, AccQual, EmitIR);
811 assert(SpirvType &&
"Attempting to get type id for nullptr type.");
812 if (SpirvType->
getOpcode() == SPIRV::OpTypeForwardPointer)
813 return SpirvType->
uses().begin()->getReg();
814 return SpirvType->
defs().begin()->getReg();
825const Type *SPIRVGlobalRegistry::adjustIntTypeByWidth(
const Type *Ty)
const {
826 if (
auto IType = dyn_cast<IntegerType>(Ty)) {
827 unsigned SrcBitWidth = IType->getBitWidth();
828 if (SrcBitWidth > 1) {
829 unsigned BitWidth = adjustOpTypeIntWidth(SrcBitWidth);
838SPIRVType *SPIRVGlobalRegistry::createSPIRVType(
840 SPIRV::AccessQualifier::AccessQualifier AccQual,
bool EmitIR) {
842 return getOrCreateSpecialType(Ty, MIRBuilder, AccQual);
843 auto &TypeToSPIRVTypeMap = DT.
getTypes()->getAllUses();
844 auto t = TypeToSPIRVTypeMap.find(Ty);
845 if (t != TypeToSPIRVTypeMap.end()) {
846 auto tt = t->second.find(&MIRBuilder.
getMF());
847 if (tt != t->second.end())
851 if (
auto IType = dyn_cast<IntegerType>(Ty)) {
852 const unsigned Width = IType->getBitWidth();
853 return Width == 1 ? getOpTypeBool(MIRBuilder)
854 : getOpTypeInt(Width, MIRBuilder,
false);
859 return getOpTypeVoid(MIRBuilder);
862 findSPIRVType(cast<FixedVectorType>(Ty)->getElementType(), MIRBuilder);
863 return getOpTypeVector(cast<FixedVectorType>(Ty)->
getNumElements(), El,
870 if (
auto SType = dyn_cast<StructType>(Ty)) {
871 if (SType->isOpaque())
872 return getOpTypeOpaque(SType, MIRBuilder);
873 return getOpTypeStruct(SType, MIRBuilder, EmitIR);
875 if (
auto FType = dyn_cast<FunctionType>(Ty)) {
876 SPIRVType *
RetTy = findSPIRVType(FType->getReturnType(), MIRBuilder);
878 for (
const auto &t : FType->params()) {
879 ParamTypes.
push_back(findSPIRVType(t, MIRBuilder));
881 return getOpTypeFunction(
RetTy, ParamTypes, MIRBuilder);
883 unsigned AddrSpace = 0xFFFF;
884 if (
auto PType = dyn_cast<TypedPointerType>(Ty))
885 AddrSpace = PType->getAddressSpace();
886 else if (
auto PType = dyn_cast<PointerType>(Ty))
887 AddrSpace = PType->getAddressSpace();
892 if (
auto PType = dyn_cast<TypedPointerType>(Ty))
904 if (SpvElementType ==
nullptr) {
905 if (!ForwardPointerTypes.contains(Ty))
906 ForwardPointerTypes[Ty] = getOpTypeForwardPointer(SC, MIRBuilder);
907 return ForwardPointerTypes[Ty];
911 if (ForwardPointerTypes.contains(Ty)) {
913 return getOpTypePointer(SC, SpvElementType, MIRBuilder, Reg);
919SPIRVType *SPIRVGlobalRegistry::restOfCreateSPIRVType(
921 SPIRV::AccessQualifier::AccessQualifier AccessQual,
bool EmitIR) {
922 if (TypesInProcessing.count(Ty) && !
isPointerTy(Ty))
924 TypesInProcessing.insert(Ty);
925 SPIRVType *SpirvType = createSPIRVType(Ty, MIRBuilder, AccessQual, EmitIR);
926 TypesInProcessing.erase(Ty);
932 if (SpirvType->
getOpcode() != SPIRV::OpTypeForwardPointer && !
Reg.isValid() &&
937 DT.
add(cast<TypedPointerType>(Ty)->getElementType(),
952 auto t = VRegToTypeMap.find(MF ? MF :
CurMF);
953 if (t != VRegToTypeMap.end()) {
954 auto tt = t->second.find(VReg);
955 if (tt != t->second.end())
963 SPIRV::AccessQualifier::AccessQualifier AccessQual,
bool EmitIR) {
966 Ty = adjustIntTypeByWidth(Ty);
969 Reg = DT.
find(cast<TypedPointerType>(Ty)->getElementType(),
979 TypesInProcessing.clear();
980 SPIRVType *STy = restOfCreateSPIRVType(Ty, MIRBuilder, AccessQual, EmitIR);
982 for (
auto &
CU : ForwardPointerTypes) {
983 const Type *Ty2 =
CU.first;
985 if ((Reg = DT.
find(Ty2, &MIRBuilder.
getMF())).isValid())
988 STy2 = restOfCreateSPIRVType(Ty2, MIRBuilder, AccessQual, EmitIR);
992 ForwardPointerTypes.clear();
997 unsigned TypeOpcode)
const {
999 assert(
Type &&
"isScalarOfType VReg has no type assigned");
1000 return Type->getOpcode() == TypeOpcode;
1004 unsigned TypeOpcode)
const {
1006 assert(
Type &&
"isScalarOrVectorOfType VReg has no type assigned");
1007 if (
Type->getOpcode() == TypeOpcode)
1009 if (
Type->getOpcode() == SPIRV::OpTypeVector) {
1010 Register ScalarTypeVReg =
Type->getOperand(1).getReg();
1012 return ScalarType->
getOpcode() == TypeOpcode;
1026 return Type->getOpcode() == SPIRV::OpTypeVector
1027 ?
static_cast<unsigned>(
Type->getOperand(2).getImm())
1034 if (
Type->getOpcode() == SPIRV::OpTypeVector) {
1035 auto EleTypeReg =
Type->getOperand(1).getReg();
1038 if (
Type->getOpcode() == SPIRV::OpTypeInt ||
1039 Type->getOpcode() == SPIRV::OpTypeFloat)
1040 return Type->getOperand(1).getImm();
1041 if (
Type->getOpcode() == SPIRV::OpTypeBool)
1043 llvm_unreachable(
"Attempting to get bit width of non-integer/float type.");
1049 unsigned NumElements = 1;
1050 if (
Type->getOpcode() == SPIRV::OpTypeVector) {
1051 NumElements =
static_cast<unsigned>(
Type->getOperand(2).getImm());
1054 return Type->getOpcode() == SPIRV::OpTypeInt ||
1055 Type->getOpcode() == SPIRV::OpTypeFloat
1056 ? NumElements *
Type->getOperand(1).getImm()
1062 if (
Type &&
Type->getOpcode() == SPIRV::OpTypeVector)
1064 return Type &&
Type->getOpcode() == SPIRV::OpTypeInt ?
Type :
nullptr;
1073 return PtrType && PtrType->
getOpcode() == SPIRV::OpTypePointer
1080 return ElemType ? ElemType->
getOpcode() : 0;
1085 if (!Type1 || !
Type2)
1091 if (Op1 == SPIRV::OpTypePointer &&
1094 if (Op2 == SPIRV::OpTypePointer &&
1099 return Bits1 > 0 && Bits1 == Bits2;
1102SPIRV::StorageClass::StorageClass
1106 Type->getOperand(1).isImm() &&
"Pointer type is expected");
1107 return static_cast<SPIRV::StorageClass::StorageClass
>(
1108 Type->getOperand(1).getImm());
1114 SPIRV::ImageFormat::ImageFormat ImageFormat,
1115 SPIRV::AccessQualifier::AccessQualifier AccessQual) {
1117 Depth, Arrayed, Multisampled, Sampled,
1118 ImageFormat, AccessQual);
1119 if (
auto *Res = checkSpecialInstr(TD, MIRBuilder))
1122 DT.
add(TD, &MIRBuilder.
getMF(), ResVReg);
1123 return MIRBuilder.
buildInstr(SPIRV::OpTypeImage)
1138 if (
auto *Res = checkSpecialInstr(TD, MIRBuilder))
1141 DT.
add(TD, &MIRBuilder.
getMF(), ResVReg);
1147 SPIRV::AccessQualifier::AccessQualifier AccessQual) {
1149 if (
auto *Res = checkSpecialInstr(TD, MIRBuilder))
1152 DT.
add(TD, &MIRBuilder.
getMF(), ResVReg);
1153 return MIRBuilder.
buildInstr(SPIRV::OpTypePipe)
1161 if (
auto *Res = checkSpecialInstr(TD, MIRBuilder))
1164 DT.
add(TD, &MIRBuilder.
getMF(), ResVReg);
1174 if (
auto *Res = checkSpecialInstr(TD, MIRBuilder))
1177 DT.
add(TD, &MIRBuilder.
getMF(), ResVReg);
1178 return MIRBuilder.
buildInstr(SPIRV::OpTypeSampledImage)
1192 MIRBuilder.
buildInstr(SPIRV::OpTypeCooperativeMatrixKHR)
1199 DT.
add(ExtensionType, &MIRBuilder.
getMF(), ResVReg);
1210 DT.
add(Ty, &MIRBuilder.
getMF(), ResVReg);
1226 SPIRV::StorageClass::StorageClass SC,
1227 SPIRV::AccessQualifier::AccessQualifier AQ) {
1228 unsigned VecElts = 0;
1251 TypeStr = TypeStr.
substr(strlen(
"*"));
1258 TypeStr = TypeStr.
substr(0, TypeStr.
find(
']'));
1278SPIRVType *SPIRVGlobalRegistry::finishCreatingSPIRVType(
const Type *LLVMTy,
1289 unsigned SPIRVOPcode,
1295 auto MIB =
BuildMI(BB,
I,
I.getDebugLoc(),
TII.get(SPIRVOPcode))
1300 return finishCreatingSPIRVType(LLVMTy, MIB);
1349 auto MIB =
BuildMI(BB,
I,
I.getDebugLoc(),
TII.get(SPIRV::OpTypeBool))
1352 return finishCreatingSPIRVType(LLVMTy, MIB);
1372 auto MIB =
BuildMI(BB,
I,
I.getDebugLoc(),
TII.get(SPIRV::OpTypeVector))
1377 return finishCreatingSPIRVType(LLVMTy, MIB);
1391 auto MIB =
BuildMI(BB,
I,
I.getDebugLoc(),
TII.get(SPIRV::OpTypeArray))
1396 return finishCreatingSPIRVType(LLVMTy, MIB);
1401 SPIRV::StorageClass::StorageClass SC) {
1413 MIRBuilder.
getTII().
get(SPIRV::OpTypePointer))
1418 return finishCreatingSPIRVType(LLVMTy, MIB);
1423 SPIRV::StorageClass::StorageClass SC) {
1446 MIB =
BuildMI(*
I.getParent(),
I,
I.getDebugLoc(),
TII.get(SPIRV::OpUndef))
1451 *ST.getRegisterInfo(), *ST.getRegBankInfo());
unsigned const MachineRegisterInfo * MRI
This file implements a class to represent arbitrary precision integral constant values and operations...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const HexagonInstrInfo * TII
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static unsigned getNumElements(Type *Ty)
static Register createTypeVReg(MachineIRBuilder &MIRBuilder)
APInt bitcastToAPInt() const
Class for arbitrary precision integers.
uint64_t getZExtValue() const
Get zero extended value.
int64_t getSExtValue() const
Get sign extended value.
Class to represent array types.
uint64_t getNumElements() const
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
Type * getElementType() const
ConstantFP - Floating Point Values [float, double].
const APFloat & getValueAPF() const
This is the shared class of boolean and integer constants.
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
static Constant * getAnon(ArrayRef< Constant * > V, bool Packed=false)
Return an anonymous struct that has the specified elements.
static Constant * getSplat(ElementCount EC, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
This is an important base class in LLVM.
const APInt & getUniqueInteger() const
If C is a constant integer then return its value, otherwise C must be a vector of constant integers,...
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
Class to represent fixed width SIMD vectors.
static FixedVectorType * get(Type *ElementType, unsigned NumElts)
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
MaybeAlign getAlign() const
Returns the alignment of the given variable or function.
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
Module * getParent()
Get the module that this global value is contained inside of...
@ ExternalLinkage
Externally visible function.
Class to represent integer types.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
static constexpr LLT pointer(unsigned AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space.
static constexpr LLT fixed_vector(unsigned NumElements, unsigned ScalarSizeInBits)
Get a low-level fixed-width vector of some number of elements and element width.
This is an important class for using LLVM in a threaded context.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
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.
LLVMContext & getContext() const
const TargetInstrInfo & getTII()
MachineBasicBlock::iterator getInsertPt()
Current insertion point for new instructions.
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
MachineFunction & getMF()
Getter for the function we currently build.
const MachineBasicBlock & getMBB() const
Getter for the basic block we currently build.
const DebugLoc & getDebugLoc()
Get the current instruction's debug location.
MachineRegisterInfo * getMRI()
Getter for MRI.
MachineInstrBuilder buildCopy(const DstOp &Res, const SrcOp &Op)
Build and insert Res = COPY Op.
MachineInstrBuilder buildSplatVector(const DstOp &Res, const SrcOp &Val)
Build and insert Res = G_SPLAT_VECTOR Val.
virtual MachineInstrBuilder buildConstant(const DstOp &Res, const ConstantInt &Val)
Build and insert Res = G_CONSTANT Val.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
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.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
iterator_range< mop_iterator > uses()
Returns a range that includes all operands that are register uses.
iterator_range< mop_iterator > defs()
Returns a range over all explicit operands that are register definitions.
const MachineFunction * getMF() const
Return the function that contains the basic block that this instruction belongs to.
const MachineOperand & getOperand(unsigned i) 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 ...
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
void setRegClass(Register Reg, const TargetRegisterClass *RC)
setRegClass - Set the register class of the specified virtual register.
Register createGenericVirtualRegister(LLT Ty, StringRef Name="")
Create and return a new generic virtual register with low-level type Ty.
MachineInstr * getUniqueVRegDef(Register Reg) const
getUniqueVRegDef - Return the unique machine instr that defines the specified virtual register or nul...
A Module instance is used to store all the information related to an LLVM module.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Wrapper class representing virtual and physical registers.
constexpr bool isValid() const
void add(const Type *Ty, const MachineFunction *MF, Register R)
Register find(const Type *Ty, const MachineFunction *MF)
const SPIRVDuplicatesTracker< Type > * getTypes()
SPIRVType * getOrCreateOpTypePipe(MachineIRBuilder &MIRBuilder, SPIRV::AccessQualifier::AccessQualifier AccQual)
unsigned getNumScalarOrVectorTotalBitWidth(const SPIRVType *Type) const
SPIRVType * getSPIRVTypeForVReg(Register VReg, const MachineFunction *MF=nullptr) const
Register getOrCreateConstInt(uint64_t Val, MachineInstr &I, SPIRVType *SpvType, const SPIRVInstrInfo &TII, bool ZeroAsNull=true)
SPIRVType * assignFloatTypeToVReg(unsigned BitWidth, Register VReg, MachineInstr &I, const SPIRVInstrInfo &TII)
SPIRVType * assignVectTypeToVReg(SPIRVType *BaseType, unsigned NumElements, Register VReg, MachineInstr &I, const SPIRVInstrInfo &TII)
Register getOrCreateUndef(MachineInstr &I, SPIRVType *SpvType, const SPIRVInstrInfo &TII)
SPIRVType * getOrCreateSPIRVBoolType(MachineIRBuilder &MIRBuilder)
Register getOrCreateConsIntVector(uint64_t Val, MachineIRBuilder &MIRBuilder, SPIRVType *SpvType, bool EmitIR=true)
const Type * getTypeForSPIRVType(const SPIRVType *Ty) const
Register buildConstantSampler(Register Res, unsigned AddrMode, unsigned Param, unsigned FilerMode, MachineIRBuilder &MIRBuilder, SPIRVType *SpvType)
bool isBitcastCompatible(const SPIRVType *Type1, const SPIRVType *Type2) const
unsigned getScalarOrVectorComponentCount(Register VReg) const
SPIRVType * getOrCreateSPIRVFloatType(unsigned BitWidth, MachineInstr &I, const SPIRVInstrInfo &TII)
SPIRVType * getOrCreateOpTypeImage(MachineIRBuilder &MIRBuilder, SPIRVType *SampledType, SPIRV::Dim::Dim Dim, uint32_t Depth, uint32_t Arrayed, uint32_t Multisampled, uint32_t Sampled, SPIRV::ImageFormat::ImageFormat ImageFormat, SPIRV::AccessQualifier::AccessQualifier AccQual)
bool isScalarOrVectorSigned(const SPIRVType *Type) const
SPIRVGlobalRegistry(unsigned PointerSize)
unsigned getPointerSize() const
SPIRVType * getOrCreateOpTypeByOpcode(const Type *Ty, MachineIRBuilder &MIRBuilder, unsigned Opcode)
Register buildConstantFP(APFloat Val, MachineIRBuilder &MIRBuilder, SPIRVType *SpvType=nullptr)
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)
bool isScalarOfType(Register VReg, unsigned TypeOpcode) const
Register buildGlobalVariable(Register Reg, SPIRVType *BaseType, StringRef Name, const GlobalValue *GV, SPIRV::StorageClass::StorageClass Storage, const MachineInstr *Init, bool IsConst, bool HasLinkageTy, SPIRV::LinkageType::LinkageType LinkageType, MachineIRBuilder &MIRBuilder, bool IsInstSelector)
SPIRVType * assignIntTypeToVReg(unsigned BitWidth, Register VReg, MachineInstr &I, const SPIRVInstrInfo &TII)
unsigned getPointeeTypeOp(Register PtrReg)
SPIRVType * getOrCreateOpTypeSampledImage(SPIRVType *ImageType, MachineIRBuilder &MIRBuilder)
SPIRVType * getOrCreateSPIRVTypeByName(StringRef TypeStr, MachineIRBuilder &MIRBuilder, SPIRV::StorageClass::StorageClass SC=SPIRV::StorageClass::Function, SPIRV::AccessQualifier::AccessQualifier AQ=SPIRV::AccessQualifier::ReadWrite)
SPIRVType * assignTypeToVReg(const Type *Type, Register VReg, MachineIRBuilder &MIRBuilder, SPIRV::AccessQualifier::AccessQualifier AQ=SPIRV::AccessQualifier::ReadWrite, bool EmitIR=true)
SPIRVType * getOrCreateOpTypeFunctionWithArgs(const Type *Ty, SPIRVType *RetType, const SmallVectorImpl< SPIRVType * > &ArgTypes, MachineIRBuilder &MIRBuilder)
bool isScalarOrVectorOfType(Register VReg, unsigned TypeOpcode) const
Register getOrCreateConstIntArray(uint64_t Val, size_t Num, MachineInstr &I, SPIRVType *SpvType, const SPIRVInstrInfo &TII)
Register getOrCreateConstVector(uint64_t Val, MachineInstr &I, SPIRVType *SpvType, const SPIRVInstrInfo &TII, bool ZeroAsNull=true)
SPIRVType * getOrCreateOpTypeDeviceEvent(MachineIRBuilder &MIRBuilder)
SPIRVType * getOrCreateSPIRVPointerType(SPIRVType *BaseType, MachineIRBuilder &MIRBuilder, SPIRV::StorageClass::StorageClass SClass=SPIRV::StorageClass::Function)
SPIRVType * getOrCreateOpTypeCoopMatr(MachineIRBuilder &MIRBuilder, const TargetExtType *ExtensionType, const SPIRVType *ElemType, uint32_t Scope, uint32_t Rows, uint32_t Columns, uint32_t Use)
SPIRVType * getOrCreateSPIRVVectorType(SPIRVType *BaseType, unsigned NumElements, MachineIRBuilder &MIRBuilder)
SPIRVType * getOrCreateSPIRVIntegerType(unsigned BitWidth, MachineIRBuilder &MIRBuilder)
SPIRVType * getOrCreateSPIRVArrayType(SPIRVType *BaseType, unsigned NumElements, MachineInstr &I, const SPIRVInstrInfo &TII)
SPIRV::StorageClass::StorageClass getPointerStorageClass(Register VReg) const
SPIRVType * getOrCreateOpTypeSampler(MachineIRBuilder &MIRBuilder)
Register buildConstantInt(uint64_t Val, MachineIRBuilder &MIRBuilder, SPIRVType *SpvType=nullptr, bool EmitIR=true)
Register getOrCreateConstFP(APFloat Val, MachineInstr &I, SPIRVType *SpvType, const SPIRVInstrInfo &TII, bool ZeroAsNull=true)
Register getOrCreateConstNullPtr(MachineIRBuilder &MIRBuilder, SPIRVType *SpvType)
unsigned getScalarOrVectorBitWidth(const SPIRVType *Type) const
const SPIRVType * retrieveScalarOrVectorIntType(const SPIRVType *Type) const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
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.
bool consume_back(StringRef Suffix)
Returns true if this StringRef has the given suffix and removes that suffix.
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
std::string str() const
str - Get the contents as an std::string.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Class to represent struct types.
ArrayRef< Type * > elements() const
bool hasName() const
Return true if this is a named struct that has a non-empty name.
StringRef getName() const
Return the name for this struct type if it has an identity.
Class to represent target extensions types, which are generally unintrospectable from target-independ...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
static Type * getHalfTy(LLVMContext &C)
static Type * getDoubleTy(LLVMContext &C)
bool isVectorTy() const
True if this is an instance of VectorType.
bool isArrayTy() const
True if this is an instance of ArrayType.
Type * getArrayElementType() const
uint64_t getArrayNumElements() const
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
static IntegerType * getInt8Ty(LLVMContext &C)
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
static IntegerType * getInt32Ty(LLVMContext &C)
static Type * getFloatTy(LLVMContext &C)
bool isIntegerTy() const
True if this is an instance of IntegerType.
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
bool isVoidTy() const
Return true if this is 'void'.
A few GPU targets, such as DXIL and SPIR-V, have typed pointers.
Type * getElementType() const
static TypedPointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
'undef' values are things that do not have specified contents.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
A Use represents the edge between a Value definition and its users.
StringRef getName() const
Return a constant reference to the value's name.
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
Type * getElementType() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ SC
CHAIN = SC CHAIN, Imm128 - System call.
SpecialTypeDescriptor make_descr_pipe(uint8_t AQ)
SpecialTypeDescriptor make_descr_sampler()
std::tuple< const Type *, unsigned, unsigned > SpecialTypeDescriptor
SpecialTypeDescriptor make_descr_event()
SpecialTypeDescriptor make_descr_image(const Type *SampledTy, unsigned Dim, unsigned Depth, unsigned Arrayed, unsigned MS, unsigned Sampled, unsigned ImageFormat, unsigned AQ=0)
TargetExtType * parseBuiltinTypeNameToTargetExtType(std::string TypeName, LLVMContext &Context)
Translates a string representing a SPIR-V or OpenCL builtin type to a TargetExtType that can be furth...
SPIRVType * lowerBuiltinType(const Type *OpaqueType, SPIRV::AccessQualifier::AccessQualifier AccessQual, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
SpecialTypeDescriptor make_descr_sampled_image(const Type *SampledTy, const MachineInstr *ImageTy)
Reg
All possible values of the reg field in the ModR/M byte.
This is an optimization pass for GlobalISel generic memory operations.
void buildOpName(Register Target, const StringRef &Name, MachineIRBuilder &MIRBuilder)
unsigned storageClassToAddressSpace(SPIRV::StorageClass::StorageClass SC)
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
unsigned getPointerAddressSpace(const Type *T)
void addNumImm(const APInt &Imm, MachineInstrBuilder &MIB)
bool constrainSelectedInstRegOperands(MachineInstr &I, const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI)
Mutate the newly-selected instruction I to constrain its (possibly generic) virtual register operands...
bool getSpirvBuiltInIdByName(llvm::StringRef Name, SPIRV::BuiltIn::BuiltIn &BI)
bool isTypedPointerTy(const Type *T)
void buildOpDecorate(Register Reg, MachineIRBuilder &MIRBuilder, SPIRV::Decoration::Decoration Dec, const std::vector< uint32_t > &DecArgs, StringRef StrImm)
Type * toTypedPointer(Type *Ty)
bool isSpecialOpaqueType(const Type *Ty)
bool isPointerTy(const Type *T)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
const Type * unifyPtrType(const Type *Ty)
SPIRV::StorageClass::StorageClass addressSpaceToStorageClass(unsigned AddrSpace, const SPIRVSubtarget &STI)
Type * parseBasicTypeName(StringRef &TypeName, LLVMContext &Ctx)
constexpr unsigned BitWidth
bool hasBuiltinTypePrefix(StringRef Name)
void addStringImm(const StringRef &Str, MCInst &Inst)
void buildOpSpirvDecorations(Register Reg, MachineIRBuilder &MIRBuilder, const MDNode *GVarMD)
uint64_t value() const
This is a hole in the type system and should not be abused.
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.