26#include "llvm/IR/IntrinsicsSPIRV.h"
38 if (isa<AtomicCmpXchgInst, InsertValueInst, UndefValue>(Arg))
40 if (
const auto *LI = dyn_cast<LoadInst>(Arg))
41 if (LI->getType()->isAggregateType())
47 if (
auto PType = dyn_cast<TypedPointerType>(Ty))
48 return PType->getAddressSpace();
49 if (
auto PType = dyn_cast<PointerType>(Ty))
50 return PType->getAddressSpace();
51 if (
auto *ExtTy = dyn_cast<TargetExtType>(Ty);
53 return ExtTy->getIntParameter(0);
60 case SPIRV::StorageClass::Uniform:
61 case SPIRV::StorageClass::PushConstant:
62 case SPIRV::StorageClass::StorageBuffer:
63 case SPIRV::StorageClass::PhysicalStorageBufferEXT:
65 case SPIRV::StorageClass::UniformConstant:
66 case SPIRV::StorageClass::Input:
67 case SPIRV::StorageClass::Output:
68 case SPIRV::StorageClass::Workgroup:
69 case SPIRV::StorageClass::CrossWorkgroup:
70 case SPIRV::StorageClass::Private:
71 case SPIRV::StorageClass::Function:
72 case SPIRV::StorageClass::Generic:
73 case SPIRV::StorageClass::AtomicCounter:
74 case SPIRV::StorageClass::Image:
75 case SPIRV::StorageClass::CallableDataNV:
76 case SPIRV::StorageClass::IncomingCallableDataNV:
77 case SPIRV::StorageClass::RayPayloadNV:
78 case SPIRV::StorageClass::HitAttributeNV:
79 case SPIRV::StorageClass::IncomingRayPayloadNV:
80 case SPIRV::StorageClass::ShaderRecordBufferNV:
81 case SPIRV::StorageClass::CodeSectionINTEL:
82 case SPIRV::StorageClass::DeviceOnlyINTEL:
83 case SPIRV::StorageClass::HostOnlyINTEL:
90 : PointerSize(PointerSize), Bound(0), CurMF(nullptr) {}
121 SPIRV::AccessQualifier::AccessQualifier AccessQual,
bool EmitIR) {
131 VRegToTypeMap[&MF][VReg] = SpirvType;
136 MRI.setRegClass(Res, &SPIRV::TYPERegClass);
146 return MIRBuilder.
buildInstr(SPIRV::OpTypeBool)
151unsigned SPIRVGlobalRegistry::adjustOpTypeIntWidth(
unsigned Width)
const {
155 if (
ST.canUseExtension(
156 SPIRV::Extension::SPV_INTEL_arbitrary_precision_integers) ||
157 ST.canUseExtension(SPIRV::Extension::SPV_INTEL_int4))
161 else if (Width <= 16)
163 else if (Width <= 32)
170SPIRVType *SPIRVGlobalRegistry::getOpTypeInt(
unsigned Width,
173 Width = adjustOpTypeIntWidth(Width);
177 if (Width == 4 &&
ST.canUseExtension(SPIRV::Extension::SPV_INTEL_int4)) {
178 MIRBuilder.buildInstr(SPIRV::OpExtension)
179 .addImm(SPIRV::Extension::SPV_INTEL_int4);
180 MIRBuilder.buildInstr(SPIRV::OpCapability)
181 .addImm(SPIRV::Capability::Int4TypeINTEL);
184 SPIRV::Extension::SPV_INTEL_arbitrary_precision_integers)) {
185 MIRBuilder.buildInstr(SPIRV::OpExtension)
186 .addImm(SPIRV::Extension::SPV_INTEL_arbitrary_precision_integers);
187 MIRBuilder.buildInstr(SPIRV::OpCapability)
188 .addImm(SPIRV::Capability::ArbitraryPrecisionIntegersINTEL);
190 return MIRBuilder.
buildInstr(SPIRV::OpTypeInt)
193 .addImm(IsSigned ? 1 : 0);
200 return MIRBuilder.
buildInstr(SPIRV::OpTypeFloat)
208 return MIRBuilder.
buildInstr(SPIRV::OpTypeVoid)
218 auto It = LastInsertedTypeMap.find(MF);
219 if (It == LastInsertedTypeMap.end())
221 if (It->second ==
MI)
222 LastInsertedTypeMap.erase(MF);
227SPIRVType *SPIRVGlobalRegistry::createOpType(
234 auto LastInsertedType = LastInsertedTypeMap.find(
CurMF);
235 if (LastInsertedType != LastInsertedTypeMap.end()) {
236 auto It = LastInsertedType->second->getIterator();
240 if (It->getParent() != NewMBB)
241 InsertAt = oldInsertPoint->getParent() == NewMBB
244 else if (It->getNextNode())
245 InsertAt = It->getNextNode()->getIterator();
251 auto Result = LastInsertedTypeMap.try_emplace(
CurMF,
nullptr);
253 LastInsertedType = Result.first;
260 LastInsertedType->second =
Type;
271 assert((EleOpc == SPIRV::OpTypeInt || EleOpc == SPIRV::OpTypeFloat ||
272 EleOpc == SPIRV::OpTypeBool) &&
273 "Invalid vector element type");
276 return MIRBuilder.
buildInstr(SPIRV::OpTypeVector)
288 auto *
const CF = ConstantFP::get(Ctx, Val);
290 if (
MI && (
MI->getOpcode() == SPIRV::OpConstantNull ||
291 MI->getOpcode() == SPIRV::OpConstantF))
292 return MI->getOperand(0).getReg();
313 MIB = MIRBuilder.buildInstr(SPIRV::OpConstantNull)
315 .addUse(getSPIRVTypeID(SpvType));
317 MIB = MIRBuilder.buildInstr(SPIRV::OpConstantF)
319 .addUse(getSPIRVTypeID(SpvType));
320 addNumImm(APInt(BitWidth,
321 CF->getValueAPF().bitcastToAPInt().getZExtValue()),
326 *ST.getRegisterInfo(),
327 *ST.getRegBankInfo());
339 auto *
const CI = ConstantInt::get(
const_cast<IntegerType *
>(Ty), Val);
341 if (
MI && (
MI->getOpcode() == SPIRV::OpConstantNull ||
342 MI->getOpcode() == SPIRV::OpConstantI))
343 return MI->getOperand(0).getReg();
366 : SPIRV::OpConstantTrue)
369 }
else if (!CI->
isZero() || !ZeroAsNull) {
370 MIB = MIRBuilder.buildInstr(SPIRV::OpConstantI)
372 .addUse(getSPIRVTypeID(SpvType));
373 addNumImm(APInt(BitWidth, CI->getZExtValue()), MIB);
375 MIB = MIRBuilder.buildInstr(SPIRV::OpConstantNull)
377 .addUse(getSPIRVTypeID(SpvType));
381 *ST.getRegisterInfo(),
382 *ST.getRegBankInfo());
394 auto &MF = MIRBuilder.
getMF();
396 auto *
const CI = ConstantInt::get(
const_cast<IntegerType *
>(Ty), Val);
404 Res =
MRI.createGenericVirtualRegister(LLTy);
405 MRI.setRegClass(Res, &SPIRV::iIDRegClass);
415 if (Val || !ZeroAsNull) {
416 MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantI)
421 MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantNull)
427 *Subtarget.getRegisterInfo(),
428 *Subtarget.getRegBankInfo());
438 auto &MF = MIRBuilder.
getMF();
442 SPIRV::AccessQualifier::ReadWrite,
true);
443 auto *
const CF = ConstantFP::get(Ctx, Val);
449 Res = MF.getRegInfo().createGenericVirtualRegister(LLTy);
450 MF.getRegInfo().setRegClass(Res, &SPIRV::fIDRegClass);
456 MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantF)
459 addNumImm(CF->getValueAPF().bitcastToAPInt(), MIB);
466Register SPIRVGlobalRegistry::getOrCreateBaseRegister(
470 if (SpvType->
getOpcode() == SPIRV::OpTypeVector ||
471 SpvType->
getOpcode() == SPIRV::OpTypeArray) {
475 if (
Type->getOpcode() == SPIRV::OpTypeFloat) {
480 assert(
Type->getOpcode() == SPIRV::OpTypeInt);
483 SpvBaseType,
TII, ZeroAsNull);
486Register SPIRVGlobalRegistry::getOrCreateCompositeOrNull(
489 unsigned ElemCnt,
bool ZeroAsNull) {
497 getOrCreateBaseRegister(Val,
I, SpvType,
TII,
BitWidth, ZeroAsNull);
510 MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantComposite)
513 for (
unsigned i = 0; i < ElemCnt; ++i)
516 MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantNull)
522 *Subtarget.getRegisterInfo(),
523 *Subtarget.getRegBankInfo());
540 auto *ConstVal = ConstantInt::get(LLVMBaseTy, Val);
544 return getOrCreateCompositeOrNull(ConstVal,
I, SpvType,
TII, ConstVec, BW,
559 auto *ConstVal = ConstantFP::get(LLVMBaseTy, Val);
563 return getOrCreateCompositeOrNull(ConstVal,
I, SpvType,
TII, ConstVec, BW,
573 const ArrayType *LLVMArrTy = cast<ArrayType>(LLVMTy);
575 Constant *CI = ConstantInt::get(LLVMBaseTy, Val);
588 ConstantInt::get(LLVMBaseTy, Val), ConstantInt::get(LLVMBaseTy, Num)});
589 return getOrCreateCompositeOrNull(CI,
I, SpvType,
TII, UniqueKey, BW,
593Register SPIRVGlobalRegistry::getOrCreateIntCompositeOrNull(
615 auto MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantComposite)
618 for (
unsigned i = 0; i < ElemCnt; ++i)
623 return MIRBuilder.
buildInstr(SPIRV::OpConstantNull)
639 const auto ConstInt = ConstantInt::get(LLVMBaseTy, Val);
643 return getOrCreateIntCompositeOrNull(Val, MIRBuilder, SpvType, EmitIR,
668 return MIRBuilder.
buildInstr(SPIRV::OpConstantNull)
678 unsigned Param,
unsigned FilerMode,
691 MIRBuilder.
buildInstr(SPIRV::OpConstantSampler)
702 const GlobalValue *GV, SPIRV::StorageClass::StorageClass Storage,
705 bool IsInstSelector) {
708 GVar = cast<const GlobalVariable>(GV);
713 GVar = M->getGlobalVariable(
Name);
714 if (GVar ==
nullptr) {
732 auto MIB = MIRBuilder.
buildInstr(SPIRV::OpVariable)
740 if (IsInstSelector) {
743 *Subtarget.getRegisterInfo(),
744 *Subtarget.getRegBankInfo());
753 if (Reg != ResVReg) {
756 MRI->setType(Reg, RegLLTy);
763 if (!DefType || DefType !=
BaseType)
775 if (IsConst && !ST.isShader())
780 buildOpDecorate(Reg, MIRBuilder, SPIRV::Decoration::Alignment, {Alignment});
787 SPIRV::BuiltIn::BuiltIn BuiltInId;
790 {
static_cast<uint32_t>(BuiltInId)});
796 if (GVar && (GVarMD = GVar->
getMetadata(
"spirv.Decorations")) !=
nullptr)
813 SPIRV::LinkageType::Import, MIRBuilder,
false);
815 buildOpDecorate(VarReg, MIRBuilder, SPIRV::Decoration::DescriptorSet, {Set});
825 bool ExplicitLayoutRequired,
828 "Invalid array element type");
837 return MIRBuilder.
buildInstr(SPIRV::OpTypeArray)
840 .addUse(NumElementsVReg);
843 assert(
ST.isShader() &&
"Runtime arrays are not allowed in non-shader "
848 return MIRBuilder.
buildInstr(SPIRV::OpTypeRuntimeArray)
856 addArrayStrideDecorations(
ArrayType->defs().begin()->getReg(), ET,
869 auto MIB = MIRBuilder.
buildInstr(SPIRV::OpTypeOpaque).addDef(ResVReg);
876SPIRVType *SPIRVGlobalRegistry::getOpTypeStruct(
878 SPIRV::AccessQualifier::AccessQualifier AccQual,
883 constexpr unsigned MaxWordCount = UINT16_MAX;
886 size_t MaxNumElements = MaxWordCount - 2;
887 size_t SPIRVStructNumElements = NumElements;
888 if (NumElements > MaxNumElements) {
890 SPIRVStructNumElements = MaxNumElements;
891 MaxNumElements = MaxWordCount - 1;
894 for (
const auto &Elem : Ty->
elements()) {
897 Decorator !=
nullptr, EmitIR);
899 "Invalid struct element type");
911 MIRBuilder.
buildInstr(SPIRV::OpTypeStruct).addDef(ResVReg);
912 for (
size_t I = 0;
I < SPIRVStructNumElements; ++
I)
913 MIBStruct.
addUse(FieldTypes[
I]);
914 for (
size_t I = SPIRVStructNumElements;
I < NumElements;
915 I += MaxNumElements) {
917 MIRBuilder.
buildInstr(SPIRV::OpTypeStructContinuedINTEL);
918 for (
size_t J =
I; J < std::min(
I + MaxNumElements, NumElements); ++J)
925 Decorator(SPVType->defs().begin()->getReg());
930SPIRVType *SPIRVGlobalRegistry::getOrCreateSpecialType(
932 SPIRV::AccessQualifier::AccessQualifier AccQual) {
937SPIRVType *SPIRVGlobalRegistry::getOpTypePointer(
938 SPIRV::StorageClass::StorageClass SC,
SPIRVType *ElemType,
944 return MIRBuilder.
buildInstr(SPIRV::OpTypePointer)
951SPIRVType *SPIRVGlobalRegistry::getOpTypeForwardPointer(
954 return MIRBuilder.
buildInstr(SPIRV::OpTypeForwardPointer)
960SPIRVType *SPIRVGlobalRegistry::getOpTypeFunction(
964 auto MIB = MIRBuilder.
buildInstr(SPIRV::OpTypeFunction)
967 for (
const SPIRVType *ArgType : ArgTypes)
979 const MachineInstr *NewMI = getOpTypeFunction(RetType, ArgTypes, MIRBuilder);
980 add(Ty,
false, NewMI);
981 return finishCreatingSPIRVType(Ty, NewMI);
984SPIRVType *SPIRVGlobalRegistry::findSPIRVType(
986 SPIRV::AccessQualifier::AccessQualifier AccQual,
987 bool ExplicitLayoutRequired,
bool EmitIR) {
988 Ty = adjustIntTypeByWidth(Ty);
991 findMI(Ty, ExplicitLayoutRequired, &MIRBuilder.
getMF()))
993 if (
auto It = ForwardPointerTypes.find(Ty); It != ForwardPointerTypes.end())
995 return restOfCreateSPIRVType(Ty, MIRBuilder, AccQual, ExplicitLayoutRequired,
1000 assert(SpirvType &&
"Attempting to get type id for nullptr type.");
1001 if (SpirvType->
getOpcode() == SPIRV::OpTypeForwardPointer ||
1002 SpirvType->
getOpcode() == SPIRV::OpTypeStructContinuedINTEL)
1003 return SpirvType->
uses().
begin()->getReg();
1004 return SpirvType->
defs().
begin()->getReg();
1015const Type *SPIRVGlobalRegistry::adjustIntTypeByWidth(
const Type *Ty)
const {
1016 if (
auto IType = dyn_cast<IntegerType>(Ty)) {
1017 unsigned SrcBitWidth = IType->getBitWidth();
1018 if (SrcBitWidth > 1) {
1019 unsigned BitWidth = adjustOpTypeIntWidth(SrcBitWidth);
1028SPIRVType *SPIRVGlobalRegistry::createSPIRVType(
1030 SPIRV::AccessQualifier::AccessQualifier AccQual,
1031 bool ExplicitLayoutRequired,
bool EmitIR) {
1033 return getOrCreateSpecialType(Ty, MIRBuilder, AccQual);
1036 findMI(Ty, ExplicitLayoutRequired, &MIRBuilder.
getMF()))
1039 if (
auto IType = dyn_cast<IntegerType>(Ty)) {
1040 const unsigned Width = IType->getBitWidth();
1041 return Width == 1 ? getOpTypeBool(MIRBuilder)
1042 : getOpTypeInt(Width, MIRBuilder,
false);
1047 return getOpTypeVoid(MIRBuilder);
1050 findSPIRVType(cast<FixedVectorType>(Ty)->getElementType(), MIRBuilder,
1051 AccQual, ExplicitLayoutRequired, EmitIR);
1052 return getOpTypeVector(cast<FixedVectorType>(Ty)->
getNumElements(), El,
1057 AccQual, ExplicitLayoutRequired, EmitIR);
1059 ExplicitLayoutRequired, EmitIR);
1061 if (
auto SType = dyn_cast<StructType>(Ty)) {
1062 if (SType->isOpaque())
1063 return getOpTypeOpaque(SType, MIRBuilder);
1066 if (ExplicitLayoutRequired) {
1067 Decorator = [&MIRBuilder, SType,
this](
Register Reg) {
1068 addStructOffsetDecorations(Reg,
const_cast<StructType *
>(SType),
1072 return getOpTypeStruct(SType, MIRBuilder, AccQual, std::move(Decorator),
1075 if (
auto FType = dyn_cast<FunctionType>(Ty)) {
1076 SPIRVType *
RetTy = findSPIRVType(FType->getReturnType(), MIRBuilder,
1077 AccQual, ExplicitLayoutRequired, EmitIR);
1079 for (
const auto &ParamTy : FType->params())
1080 ParamTypes.
push_back(findSPIRVType(ParamTy, MIRBuilder, AccQual,
1081 ExplicitLayoutRequired, EmitIR));
1082 return getOpTypeFunction(
RetTy, ParamTypes, MIRBuilder);
1104 if (
auto It = ForwardPointerTypes.find(Ty); It != ForwardPointerTypes.end()) {
1107 return getOpTypePointer(SC, SpvElementType, MIRBuilder, Reg);
1113SPIRVType *SPIRVGlobalRegistry::restOfCreateSPIRVType(
1115 SPIRV::AccessQualifier::AccessQualifier AccessQual,
1116 bool ExplicitLayoutRequired,
bool EmitIR) {
1121 TypesInProcessing.insert(Ty);
1122 SPIRVType *SpirvType = createSPIRVType(Ty, MIRBuilder, AccessQual,
1123 ExplicitLayoutRequired, EmitIR);
1124 TypesInProcessing.erase(Ty);
1131 if (SpirvType->
getOpcode() == SPIRV::OpTypeForwardPointer ||
1135 if (
auto *ExtTy = dyn_cast<TargetExtType>(Ty);
1137 add(ExtTy->getTypeParameter(0), ExtTy->getIntParameter(0), SpirvType);
1139 add(Ty, ExplicitLayoutRequired, SpirvType);
1141 add(cast<TypedPointerType>(Ty)->getElementType(),
1152 auto t = VRegToTypeMap.find(MF ? MF :
CurMF);
1153 if (t != VRegToTypeMap.end()) {
1154 auto tt = t->second.find(VReg);
1155 if (tt != t->second.end())
1171 SPIRV::AccessQualifier::AccessQualifier AccessQual,
1172 bool ExplicitLayoutRequired,
bool EmitIR) {
1175 if (
auto *ExtTy = dyn_cast<TargetExtType>(Ty);
1177 Reg =
find(ExtTy->getTypeParameter(0), ExtTy->getIntParameter(0), MF);
1179 Reg =
find(Ty = adjustIntTypeByWidth(Ty), ExplicitLayoutRequired, MF);
1181 Reg =
find(cast<TypedPointerType>(Ty)->getElementType(),
1189 TypesInProcessing.clear();
1190 SPIRVType *STy = restOfCreateSPIRVType(Ty, MIRBuilder, AccessQual,
1191 ExplicitLayoutRequired, EmitIR);
1193 for (
auto &
CU : ForwardPointerTypes) {
1196 bool PtrNeedsLayout =
false;
1197 const Type *Ty2 =
CU.first;
1199 if ((Reg =
find(Ty2, PtrNeedsLayout, MF)).
isValid())
1202 STy2 = restOfCreateSPIRVType(Ty2, MIRBuilder, AccessQual, PtrNeedsLayout,
1207 ForwardPointerTypes.clear();
1212 unsigned TypeOpcode)
const {
1214 assert(
Type &&
"isScalarOfType VReg has no type assigned");
1215 return Type->getOpcode() == TypeOpcode;
1219 unsigned TypeOpcode)
const {
1221 assert(
Type &&
"isScalarOrVectorOfType VReg has no type assigned");
1222 if (
Type->getOpcode() == TypeOpcode)
1224 if (
Type->getOpcode() == SPIRV::OpTypeVector) {
1225 Register ScalarTypeVReg =
Type->getOperand(1).getReg();
1227 return ScalarType->
getOpcode() == TypeOpcode;
1233 switch (
Type->getOpcode()) {
1234 case SPIRV::OpTypeImage:
1235 case SPIRV::OpTypeSampler:
1236 case SPIRV::OpTypeSampledImage:
1238 case SPIRV::OpTypeStruct:
1239 return hasBlockDecoration(
Type);
1254 return Type->getOpcode() == SPIRV::OpTypeVector
1255 ?
static_cast<unsigned>(
Type->getOperand(2).getImm())
1268 Register ScalarReg =
Type->getOpcode() == SPIRV::OpTypeVector
1269 ?
Type->getOperand(1).getReg()
1270 :
Type->getOperand(0).getReg();
1280 if (
Type->getOpcode() == SPIRV::OpTypeVector) {
1281 auto EleTypeReg =
Type->getOperand(1).getReg();
1284 if (
Type->getOpcode() == SPIRV::OpTypeInt ||
1285 Type->getOpcode() == SPIRV::OpTypeFloat)
1286 return Type->getOperand(1).getImm();
1287 if (
Type->getOpcode() == SPIRV::OpTypeBool)
1289 llvm_unreachable(
"Attempting to get bit width of non-integer/float type.");
1295 unsigned NumElements = 1;
1296 if (
Type->getOpcode() == SPIRV::OpTypeVector) {
1297 NumElements =
static_cast<unsigned>(
Type->getOperand(2).getImm());
1300 return Type->getOpcode() == SPIRV::OpTypeInt ||
1301 Type->getOpcode() == SPIRV::OpTypeFloat
1302 ? NumElements *
Type->getOperand(1).getImm()
1308 if (
Type &&
Type->getOpcode() == SPIRV::OpTypeVector)
1310 return Type &&
Type->getOpcode() == SPIRV::OpTypeInt ?
Type :
nullptr;
1319 return PtrType && PtrType->
getOpcode() == SPIRV::OpTypePointer
1326 return ElemType ? ElemType->
getOpcode() : 0;
1331 if (!Type1 || !
Type2)
1337 if (Op1 == SPIRV::OpTypePointer &&
1340 if (Op2 == SPIRV::OpTypePointer &&
1345 return Bits1 > 0 && Bits1 == Bits2;
1348SPIRV::StorageClass::StorageClass
1352 Type->getOperand(1).isImm() &&
"Pointer type is expected");
1356SPIRV::StorageClass::StorageClass
1358 return static_cast<SPIRV::StorageClass::StorageClass
>(
1359 Type->getOperand(1).getImm());
1364 SPIRV::StorageClass::StorageClass SC,
bool IsWritable,
bool EmitIr) {
1375 ExplicitLayoutRequired, EmitIr);
1378 SPIRV::Decoration::Block, {});
1382 SPIRV::Decoration::NonWritable, 0, {});
1385 SPIRVType *R = getOrCreateSPIRVPointerTypeInternal(BlockType, MIRBuilder, SC);
1396 StructType *ST = cast<StructType>(
T->getTypeParameter(0));
1398 assert(ST->getNumElements() == Offsets.size());
1411 getOpTypeStruct(ST, MIRBuilder, SPIRV::AccessQualifier::None,
1412 std::move(Decorator), EmitIr);
1413 add(Key, SPIRVStructType);
1414 return SPIRVStructType;
1419 const SPIRV::AccessQualifier::AccessQualifier Qualifier,
1422 "SPIR-V image builtin type must have sampled type parameter!");
1425 SPIRV::AccessQualifier::ReadWrite,
true);
1428 "Invalid number of parameters for SPIR-V image builtin!");
1430 SPIRV::AccessQualifier::AccessQualifier accessQualifier =
1431 SPIRV::AccessQualifier::None;
1433 accessQualifier = Qualifier == SPIRV::AccessQualifier::WriteOnly
1434 ? SPIRV::AccessQualifier::WriteOnly
1435 : SPIRV::AccessQualifier::AccessQualifier(
1441 MIRBuilder, SampledType,
1447 SPIRVToLLVMType[R] = ExtensionType;
1451SPIRVType *SPIRVGlobalRegistry::getOrCreateOpTypeImage(
1454 SPIRV::ImageFormat::ImageFormat ImageFormat,
1455 SPIRV::AccessQualifier::AccessQualifier AccessQual) {
1457 Depth, Arrayed, Multisampled, Sampled,
1458 ImageFormat, AccessQual);
1470 .addImm(Multisampled)
1472 .addImm(ImageFormat);
1473 if (AccessQual != SPIRV::AccessQualifier::None)
1489 return MIRBuilder.
buildInstr(SPIRV::OpTypeSampler)
1498 SPIRV::AccessQualifier::AccessQualifier AccessQual) {
1504 return MIRBuilder.
buildInstr(SPIRV::OpTypePipe)
1506 .addImm(AccessQual);
1519 return MIRBuilder.
buildInstr(SPIRV::OpTypeDeviceEvent)
1536 return MIRBuilder.
buildInstr(SPIRV::OpTypeSampledImage)
1549 findMI(ExtensionType,
false, &MIRBuilder.
getMF()))
1557 .canUseExtension(SPIRV::Extension::SPV_INTEL_int4)) {
1559 .
addImm(SPIRV::Capability::Int4CooperativeMatrixINTEL);
1561 return MIRBuilder.
buildInstr(SPIRV::OpTypeCooperativeMatrixKHR)
1569 add(ExtensionType,
false, NewMI);
1581 add(Ty,
false, NewMI);
1597 if (Operand.isReg()) {
1598 MIB.addUse(Operand.getReg());
1599 }
else if (Operand.isImm()) {
1600 MIB.addImm(Operand.getImm());
1605 add(Ty,
false, NewMI);
1612 SPIRV::StorageClass::StorageClass SC,
1613 SPIRV::AccessQualifier::AccessQualifier AQ) {
1614 unsigned VecElts = 0;
1621 MIRBuilder, AQ,
false,
true);
1643 TypeStr = TypeStr.
substr(0, TypeStr.
find(
']'));
1660 MIRBuilder, SPIRV::AccessQualifier::ReadWrite,
false,
true);
1663SPIRVType *SPIRVGlobalRegistry::finishCreatingSPIRVType(
const Type *LLVMTy,
1674 unsigned SPIRVOPcode,
1683 MIRBuilder.
getDL(),
TII.get(SPIRVOPcode))
1688 add(Ty,
false, NewMI);
1689 return finishCreatingSPIRVType(Ty, NewMI);
1729 MIRBuilder, SPIRV::AccessQualifier::ReadWrite,
false, EmitIR);
1743 MIRBuilder.
getDL(),
TII.get(SPIRV::OpTypeBool))
1746 add(Ty,
false, NewMI);
1747 return finishCreatingSPIRVType(Ty, NewMI);
1756 MIRBuilder, SPIRV::AccessQualifier::ReadWrite,
false, EmitIR);
1771 MIRBuilder.
getDL(),
TII.get(SPIRV::OpTypeVector))
1776 add(Ty,
false, NewMI);
1777 return finishCreatingSPIRVType(Ty, NewMI);
1782 SPIRV::StorageClass::StorageClass SC) {
1789 SPIRV::StorageClass::StorageClass SC) {
1792 BaseType, MIRBuilder, SPIRV::AccessQualifier::ReadWrite,
1795 return getOrCreateSPIRVPointerTypeInternal(SpirvBaseType, MIRBuilder, SC);
1800 [[maybe_unused]] SPIRV::StorageClass::StorageClass OldSC =
1807 return getOrCreateSPIRVPointerTypeInternal(PointeeType, MIRBuilder, SC);
1812 SPIRV::StorageClass::StorageClass SC) {
1818 "The base type was not correctly laid out for the given storage class.");
1822SPIRVType *SPIRVGlobalRegistry::getOrCreateSPIRVPointerTypeInternal(
1824 SPIRV::StorageClass::StorageClass SC) {
1835 MIRBuilder.
getTII().
get(SPIRV::OpTypePointer))
1841 return finishCreatingSPIRVType(Ty, NewMI);
1863 MIRBuilder.
getDL(),
TII.get(SPIRV::OpUndef))
1868 *ST.getRegisterInfo(),
1869 *ST.getRegBankInfo());
1880 case SPIRV::OpTypeFloat:
1881 return &SPIRV::fIDRegClass;
1882 case SPIRV::OpTypePointer:
1883 return &SPIRV::pIDRegClass;
1884 case SPIRV::OpTypeVector: {
1886 unsigned ElemOpcode = ElemType ? ElemType->
getOpcode() : 0;
1887 if (ElemOpcode == SPIRV::OpTypeFloat)
1888 return &SPIRV::vfIDRegClass;
1889 if (ElemOpcode == SPIRV::OpTypePointer)
1890 return &SPIRV::vpIDRegClass;
1891 return &SPIRV::vIDRegClass;
1894 return &SPIRV::iIDRegClass;
1899 static_cast<SPIRV::StorageClass::StorageClass
>(
1904 unsigned Opcode = SpvType ? SpvType->
getOpcode() : 0;
1906 case SPIRV::OpTypeInt:
1907 case SPIRV::OpTypeFloat:
1908 case SPIRV::OpTypeBool:
1910 case SPIRV::OpTypePointer:
1912 case SPIRV::OpTypeVector: {
1915 switch (ElemType ? ElemType->
getOpcode() : 0) {
1916 case SPIRV::OpTypePointer:
1919 case SPIRV::OpTypeInt:
1920 case SPIRV::OpTypeFloat:
1921 case SPIRV::OpTypeBool:
1944 if (
auto L = AliasInstMDMap.find(AliasingListMD); L != AliasInstMDMap.end())
1950 if (
MDNode *ScopeMD = dyn_cast<MDNode>(MDListOp)) {
1951 if (ScopeMD->getNumOperands() < 2)
1953 MDNode *DomainMD = dyn_cast<MDNode>(ScopeMD->getOperand(1));
1957 auto D = AliasInstMDMap.find(DomainMD);
1958 if (
D != AliasInstMDMap.end())
1960 const Register Ret =
MRI->createVirtualRegister(&SPIRV::IDRegClass);
1965 AliasInstMDMap.insert(std::make_pair(DomainMD,
Domain));
1967 auto S = AliasInstMDMap.find(ScopeMD);
1968 if (S != AliasInstMDMap.end())
1970 const Register Ret =
MRI->createVirtualRegister(&SPIRV::IDRegClass);
1971 auto MIB = MIRBuilder.
buildInstr(SPIRV::OpAliasScopeDeclINTEL)
1976 AliasInstMDMap.insert(std::make_pair(ScopeMD, Scope));
1981 const Register Ret =
MRI->createVirtualRegister(&SPIRV::IDRegClass);
1984 for (
auto *Scope : ScopeList)
1985 MIB.
addUse(Scope->getOperand(0).getReg());
1987 AliasInstMDMap.insert(std::make_pair(AliasingListMD,
List));
1993 const MDNode *AliasingListMD) {
2020 B.CreateIntrinsic(Intrinsic::spv_value_md,
2022 AssignCI =
B.CreateIntrinsic(Intrinsic::fake_use, {Arg});
2025 OfType, Arg, {},
B);
2035 B.GetInsertBlock() ?
B.GetInsertBlock()->getParent() :
nullptr;
2036 if (AssignPtrTyCI ==
nullptr ||
2037 AssignPtrTyCI->
getParent()->getParent() != CurrF) {
2039 Intrinsic::spv_assign_ptr_type, {Arg->
getType()}, OfType, Arg,
2053 Intrinsic::spv_assign_ptr_type)
2062void SPIRVGlobalRegistry::addStructOffsetDecorations(
2072void SPIRVGlobalRegistry::addArrayStrideDecorations(
2079bool SPIRVGlobalRegistry::hasBlockDecoration(
SPIRVType *
Type)
const {
2082 Type->getMF()->getRegInfo().use_instructions(Def)) {
2083 if (
Use.getOpcode() != SPIRV::OpDecorate)
2086 if (
Use.getOperand(1).getImm() == SPIRV::Decoration::Block)
unsigned const MachineRegisterInfo * MRI
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
static unsigned getIntrinsicID(const SDNode *N)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
DXIL Resource Implicit Binding
const HexagonInstrInfo * TII
mir Rename Register Operands
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
static unsigned getNumElements(Type *Ty)
static bool storageClassRequiresExplictLayout(SPIRV::StorageClass::StorageClass SC)
static Register createTypeVReg(MachineRegisterInfo &MRI)
unsigned getAS(SPIRVType *SpvType)
static bool allowEmitFakeUse(const Value *Arg)
static unsigned typeToAddressSpace(const Type *Ty)
Class for arbitrary precision integers.
uint64_t getZExtValue() const
Get zero extended value.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Class to represent array types.
uint64_t getNumElements() const
Type * getElementType() const
void setArgOperand(unsigned i, Value *v)
This class represents a function call, abstracting a target machine's calling convention.
ConstantFP - Floating Point Values [float, double].
const APFloat & getValue() const
This is the shared class of boolean and integer constants.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
static Constant * getAnon(ArrayRef< Constant * > V, bool Packed=false)
Return an anonymous struct that has the specified elements.
static LLVM_ABI ConstantTargetNone * get(TargetExtType *T)
Static factory methods - Return objects of the specified value.
static LLVM_ABI Constant * getSplat(ElementCount EC, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
This is an important base class in LLVM.
LLVM_ABI const APInt & getUniqueInteger() const
If C is a constant integer then return its value, otherwise C must be a vector of constant integers,...
LLVM_ABI bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
Class to represent fixed width SIMD vectors.
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this 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.
MaybeAlign getAlign() const
Returns the alignment of the given variable.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Class to represent integer types.
static LLVM_ABI 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.
Instances of this class represent operands of the MCInst class.
ArrayRef< MDOperand > operands() const
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
unsigned getNumOperands() const
Return number of MDNode operands.
Tracking metadata reference owned by Metadata.
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
LLVM_ABI iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
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.
void setInsertPt(MachineBasicBlock &MBB, MachineBasicBlock::iterator II)
Set the insertion point before the specified position.
LLVMContext & getContext() const
const TargetInstrInfo & getTII()
MachineBasicBlock::iterator getInsertPt()
Current insertion point for new instructions.
MachineInstrBuilder buildSplatBuildVector(const DstOp &Res, const SrcOp &Src)
Build and insert Res = G_BUILD_VECTOR with Src replicated to fill the number of elements.
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
const DebugLoc & getDL()
Getter for DebugLoc.
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.
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.
MachineInstr * getInstr() const
If conversion operators fail, use this method to get the MachineInstr explicitly.
const MachineInstrBuilder & addDef(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
Representation of each machine instruction.
mop_range defs()
Returns all explicit operands that are register definitions.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
mop_range uses()
Returns all operands which may be register uses.
LLVM_ABI 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,...
LLVM_ABI MachineInstr * getVRegDef(Register Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
LLVM_ABI void setRegClass(Register Reg, const TargetRegisterClass *RC)
setRegClass - Set the register class of the specified virtual register.
LLVM_ABI Register createGenericVirtualRegister(LLT Ty, StringRef Name="")
Create and return a new generic virtual register with low-level type Ty.
A Module instance is used to store all the information related to an LLVM module.
static LLVM_ABI 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
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 * getResultType(Register VReg, MachineFunction *MF=nullptr)
void addAssignPtrTypeInstr(Value *Val, CallInst *AssignPtrTyCI)
SPIRVType * getOrCreateSPIRVBoolType(MachineIRBuilder &MIRBuilder, bool EmitIR)
void buildAssignPtr(IRBuilder<> &B, Type *ElemTy, Value *Arg)
SPIRVType * assignFloatTypeToVReg(unsigned BitWidth, Register VReg, MachineInstr &I, const SPIRVInstrInfo &TII)
MachineInstr * getOrAddMemAliasingINTELInst(MachineIRBuilder &MIRBuilder, const MDNode *AliasingListMD)
void assignSPIRVTypeToVReg(SPIRVType *Type, Register VReg, const MachineFunction &MF)
SPIRVType * assignVectTypeToVReg(SPIRVType *BaseType, unsigned NumElements, Register VReg, MachineInstr &I, const SPIRVInstrInfo &TII)
Register getOrCreateUndef(MachineInstr &I, SPIRVType *SpvType, const SPIRVInstrInfo &TII)
void replaceAllUsesWith(Value *Old, Value *New, bool DeleteOld=true)
SPIRVType * changePointerStorageClass(SPIRVType *PtrType, SPIRV::StorageClass::StorageClass SC, MachineInstr &I)
const Type * getTypeForSPIRVType(const SPIRVType *Ty) const
SPIRVType * getOrCreateUnknownType(const Type *Ty, MachineIRBuilder &MIRBuilder, unsigned Opcode, const ArrayRef< MCOperand > Operands)
bool isBitcastCompatible(const SPIRVType *Type1, const SPIRVType *Type2) const
unsigned getScalarOrVectorComponentCount(Register VReg) const
Register createConstInt(const ConstantInt *CI, MachineInstr &I, SPIRVType *SpvType, const SPIRVInstrInfo &TII, bool ZeroAsNull)
SPIRVType * getOrCreateSPIRVFloatType(unsigned BitWidth, MachineInstr &I, const SPIRVInstrInfo &TII)
bool isScalarOrVectorSigned(const SPIRVType *Type) const
void addDeducedElementType(Value *Val, Type *Ty)
SPIRVGlobalRegistry(unsigned PointerSize)
Register getOrCreateGlobalVariableWithBinding(const SPIRVType *VarType, uint32_t Set, uint32_t Binding, StringRef Name, MachineIRBuilder &MIRBuilder)
SPIRVType * getOrCreateSPIRVType(const Type *Type, MachineInstr &I, SPIRV::AccessQualifier::AccessQualifier AQ, bool EmitIR)
unsigned getPointerSize() const
SPIRVType * getOrCreateSPIRVPointerType(const Type *BaseType, MachineIRBuilder &MIRBuilder, SPIRV::StorageClass::StorageClass SC)
SPIRVType * getOrCreateOpTypeByOpcode(const Type *Ty, MachineIRBuilder &MIRBuilder, unsigned Opcode)
Register buildConstantFP(APFloat Val, MachineIRBuilder &MIRBuilder, SPIRVType *SpvType=nullptr)
SPIRVType * getPointeeType(SPIRVType *PtrType)
void invalidateMachineInstr(MachineInstr *MI)
Register getSPIRVTypeID(const SPIRVType *SpirvType) const
Register createConstFP(const ConstantFP *CF, MachineInstr &I, SPIRVType *SpvType, const SPIRVInstrInfo &TII, bool ZeroAsNull)
void updateIfExistDeducedElementType(Value *OldVal, Value *NewVal, bool DeleteOld)
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 * getOrCreateVulkanBufferType(MachineIRBuilder &MIRBuilder, Type *ElemType, SPIRV::StorageClass::StorageClass SC, bool IsWritable, bool EmitIr=false)
SPIRVType * getOrCreateSPIRVTypeByName(StringRef TypeStr, MachineIRBuilder &MIRBuilder, bool EmitIR, SPIRV::StorageClass::StorageClass SC=SPIRV::StorageClass::Function, SPIRV::AccessQualifier::AccessQualifier AQ=SPIRV::AccessQualifier::ReadWrite)
SPIRVType * getOrCreateLayoutType(MachineIRBuilder &MIRBuilder, const TargetExtType *T, bool EmitIr=false)
void addGlobalObject(const Value *V, const MachineFunction *MF, Register R)
SPIRVType * getScalarOrVectorComponentType(Register VReg) const
SPIRVType * getOrCreateOpTypeFunctionWithArgs(const Type *Ty, SPIRVType *RetType, const SmallVectorImpl< SPIRVType * > &ArgTypes, MachineIRBuilder &MIRBuilder)
void buildAssignType(IRBuilder<> &B, Type *Ty, Value *Arg)
Register getOrCreateConsIntVector(uint64_t Val, MachineIRBuilder &MIRBuilder, SPIRVType *SpvType, bool EmitIR)
const TargetRegisterClass * getRegClass(SPIRVType *SpvType) const
void updateIfExistAssignPtrTypeInstr(Value *OldVal, Value *NewVal, bool DeleteOld)
SPIRVType * getOrCreateSPIRVVectorType(SPIRVType *BaseType, unsigned NumElements, MachineIRBuilder &MIRBuilder, bool EmitIR)
SPIRVType * getOrCreateOpTypeCoopMatr(MachineIRBuilder &MIRBuilder, const TargetExtType *ExtensionType, const SPIRVType *ElemType, uint32_t Scope, uint32_t Rows, uint32_t Columns, uint32_t Use, bool EmitIR)
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 * getImageType(const TargetExtType *ExtensionType, const SPIRV::AccessQualifier::AccessQualifier Qualifier, MachineIRBuilder &MIRBuilder)
bool isResourceType(SPIRVType *Type) const
SPIRVType * getOrCreateSPIRVIntegerType(unsigned BitWidth, MachineIRBuilder &MIRBuilder)
Register buildConstantInt(uint64_t Val, MachineIRBuilder &MIRBuilder, SPIRVType *SpvType, bool EmitIR, bool ZeroAsNull=true)
SPIRVType * assignTypeToVReg(const Type *Type, Register VReg, MachineIRBuilder &MIRBuilder, SPIRV::AccessQualifier::AccessQualifier AQ, bool EmitIR)
LLT getRegType(SPIRVType *SpvType) const
void buildMemAliasingOpDecorate(Register Reg, MachineIRBuilder &MIRBuilder, uint32_t Dec, const MDNode *GVarMD)
SPIRV::StorageClass::StorageClass getPointerStorageClass(Register VReg) const
SPIRVType * getOrCreateOpTypeSampler(MachineIRBuilder &MIRBuilder)
Register buildConstantSampler(Register Res, unsigned AddrMode, unsigned Param, unsigned FilerMode, MachineIRBuilder &MIRBuilder)
void updateAssignType(CallInst *AssignCI, Value *Arg, Value *OfType)
Register getOrCreateConstFP(APFloat Val, MachineInstr &I, SPIRVType *SpvType, const SPIRVInstrInfo &TII, bool ZeroAsNull=true)
CallInst * findAssignPtrTypeInstr(const Value *Val)
Register getOrCreateConstNullPtr(MachineIRBuilder &MIRBuilder, SPIRVType *SpvType)
unsigned getScalarOrVectorBitWidth(const SPIRVType *Type) const
const SPIRVType * retrieveScalarOrVectorIntType(const SPIRVType *Type) const
const MachineInstr * findMI(SPIRV::IRHandle Handle, const MachineFunction *MF)
bool erase(const MachineInstr *MI)
bool add(SPIRV::IRHandle Handle, const MachineInstr *MI)
Register find(SPIRV::IRHandle Handle, const MachineFunction *MF)
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 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
static LLVM_ABI StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
unsigned getNumElements() const
Random access to the elements.
bool hasName() const
Return true if this is a named struct that has a non-empty name.
LLVM_ABI 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...
unsigned getNumIntParameters() const
Type * getTypeParameter(unsigned i) const
unsigned getNumTypeParameters() const
unsigned getIntParameter(unsigned i) const
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 LLVM_ABI Type * getFloatTy(LLVMContext &C)
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
bool isVectorTy() const
True if this is an instance of VectorType.
static LLVM_ABI Type * getDoubleTy(LLVMContext &C)
bool isArrayTy() const
True if this is an instance of ArrayType.
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
Type * getArrayElementType() const
static LLVM_ABI Type * getHalfTy(LLVMContext &C)
bool isAggregateType() const
Return true if the type is an aggregate type.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
bool isIntegerTy() const
True if this is an instance of IntegerType.
bool isVoidTy() const
Return true if this is 'void'.
LLVM_ABI unsigned getIntegerBitWidth() const
LLVM_ABI uint64_t getArrayNumElements() const
static LLVM_ABI TypedPointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
'undef' values are things that do not have specified contents.
static LLVM_ABI 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.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
LLVM_ABI 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
const ParentTy * getParent() const
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
IRHandle handle(const Type *Ty)
IRHandle irhandle_sampled_image(const Type *SampledTy, const MachineInstr *ImageTy)
IRHandle irhandle_vkbuffer(const Type *ElementType, StorageClass::StorageClass SC, bool IsWriteable)
IRHandle irhandle_sampler()
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)
IRHandle irhandle_event()
IRHandle irhandle_pipe(uint8_t AQ)
IRHandle irhandle_image(const Type *SampledTy, unsigned Dim, unsigned Depth, unsigned Arrayed, unsigned MS, unsigned Sampled, unsigned ImageFormat, unsigned AQ=0)
Reg
All possible values of the reg field in the ModR/M byte.
NodeAddr< DefNode * > Def
This is an optimization pass for GlobalISel generic memory operations.
void buildOpName(Register Target, const StringRef &Name, MachineIRBuilder &MIRBuilder)
bool isTypedPointerWrapper(const TargetExtType *ExtTy)
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)
LLVM_ABI 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...
CallInst * buildIntrWithMD(Intrinsic::ID IntrID, ArrayRef< Type * > Types, Value *Arg, Value *Arg2, ArrayRef< Constant * > Imms, IRBuilder<> &B)
LLVM_ABI void reportFatalInternalError(Error Err)
Report a fatal error that indicates a bug in LLVM.
constexpr unsigned storageClassToAddressSpace(SPIRV::StorageClass::StorageClass SC)
bool getSpirvBuiltInIdByName(llvm::StringRef Name, SPIRV::BuiltIn::BuiltIn &BI)
MetadataAsValue * buildMD(Value *Arg)
bool isTypedPointerTy(const Type *T)
void buildOpDecorate(Register Reg, MachineIRBuilder &MIRBuilder, SPIRV::Decoration::Decoration Dec, const std::vector< uint32_t > &DecArgs, StringRef StrImm)
Type * getTypedPointerWrapper(Type *ElemTy, unsigned AS)
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
void buildOpMemberDecorate(Register Reg, MachineIRBuilder &MIRBuilder, SPIRV::Decoration::Decoration Dec, uint32_t Member, const std::vector< uint32_t > &DecArgs, StringRef StrImm)
Type * toTypedPointer(Type *Ty)
bool isSpecialOpaqueType(const Type *Ty)
bool isPointerTy(const Type *T)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
MachineBasicBlock::iterator getInsertPtValidEnd(MachineBasicBlock *MBB)
const Type * unifyPtrType(const Type *Ty)
SPIRV::StorageClass::StorageClass addressSpaceToStorageClass(unsigned AddrSpace, const SPIRVSubtarget &STI)
Type * parseBasicTypeName(StringRef &TypeName, LLVMContext &Ctx)
DWARFExpression::Operation Op
constexpr unsigned BitWidth
bool hasBuiltinTypePrefix(StringRef Name)
bool isPointerTyOrWrapper(const Type *Ty)
std::function< void(Register)> StructOffsetDecorator
bool isSpvIntrinsic(const MachineInstr &MI, Intrinsic::ID IntrinsicID)
PoisonValue * getNormalizedPoisonValue(Type *Ty)
void addStringImm(const StringRef &Str, MCInst &Inst)
MachineInstr * getVRegDef(MachineRegisterInfo &MRI, Register Reg)
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.