28#include "llvm/IR/IntrinsicsSPIRV.h"
43 if (LI->getType()->isAggregateType())
50 return PType->getAddressSpace();
52 return PType->getAddressSpace();
55 return ExtTy->getIntParameter(0);
62 case SPIRV::StorageClass::Uniform:
63 case SPIRV::StorageClass::PushConstant:
64 case SPIRV::StorageClass::StorageBuffer:
65 case SPIRV::StorageClass::PhysicalStorageBufferEXT:
67 case SPIRV::StorageClass::UniformConstant:
68 case SPIRV::StorageClass::Input:
69 case SPIRV::StorageClass::Output:
70 case SPIRV::StorageClass::Workgroup:
71 case SPIRV::StorageClass::CrossWorkgroup:
72 case SPIRV::StorageClass::Private:
73 case SPIRV::StorageClass::Function:
74 case SPIRV::StorageClass::Generic:
75 case SPIRV::StorageClass::AtomicCounter:
76 case SPIRV::StorageClass::Image:
77 case SPIRV::StorageClass::CallableDataNV:
78 case SPIRV::StorageClass::IncomingCallableDataNV:
79 case SPIRV::StorageClass::RayPayloadNV:
80 case SPIRV::StorageClass::HitAttributeNV:
81 case SPIRV::StorageClass::IncomingRayPayloadNV:
82 case SPIRV::StorageClass::ShaderRecordBufferNV:
83 case SPIRV::StorageClass::CodeSectionINTEL:
84 case SPIRV::StorageClass::DeviceOnlyINTEL:
85 case SPIRV::StorageClass::HostOnlyINTEL:
92 : DL(DL), Bound(0),
CurMF(nullptr) {}
94void SPIRVGlobalRegistry::constrainSelectedInstRegOperands(
98 *ST.getRegBankInfo());
112 SPIRV::AccessQualifier::AccessQualifier AccessQual,
bool EmitIR) {
122 VRegToTypeMap[&MF][VReg] = SpirvType;
127 MRI.setRegClass(Res, &SPIRV::TYPERegClass);
136 return createConstOrTypeAtFunctionEntry(
137 MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
138 return MIRBuilder.
buildInstr(SPIRV::OpTypeBool)
143unsigned SPIRVGlobalRegistry::adjustOpTypeIntWidth(
unsigned Width)
const {
145 if (
ST.canUseExtension(
146 SPIRV::Extension::SPV_ALTERA_arbitrary_precision_integers) ||
147 (Width == 4 &&
ST.canUseExtension(SPIRV::Extension::SPV_INTEL_int4)))
151 else if (Width <= 16)
153 else if (Width <= 32)
155 else if (Width <= 64)
157 else if (Width <= 128)
162SPIRVTypeInst SPIRVGlobalRegistry::getOpTypeInt(
unsigned Width,
165 Width = adjustOpTypeIntWidth(Width);
166 const SPIRVSubtarget &
ST =
168 return createConstOrTypeAtFunctionEntry(MIRBuilder, [&](MachineIRBuilder
170 if (Width == 4 &&
ST.canUseExtension(SPIRV::Extension::SPV_INTEL_int4)) {
172 .
addImm(SPIRV::Extension::SPV_INTEL_int4);
174 .
addImm(SPIRV::Capability::Int4TypeINTEL);
177 SPIRV::Extension::SPV_ALTERA_arbitrary_precision_integers)) {
179 .
addImm(SPIRV::Extension::SPV_ALTERA_arbitrary_precision_integers);
181 .
addImm(SPIRV::Capability::ArbitraryPrecisionIntegersALTERA);
183 return MIRBuilder.
buildInstr(SPIRV::OpTypeInt)
186 .
addImm(IsSigned ? 1 : 0);
191SPIRVGlobalRegistry::getOpTypeFloat(uint32_t Width,
193 return createConstOrTypeAtFunctionEntry(MIRBuilder, [&](MachineIRBuilder
195 return MIRBuilder.
buildInstr(SPIRV::OpTypeFloat)
202SPIRVGlobalRegistry::getOpTypeFloat(uint32_t Width,
204 SPIRV::FPEncoding::FPEncoding FPEncode) {
205 return createConstOrTypeAtFunctionEntry(MIRBuilder, [&](MachineIRBuilder
207 return MIRBuilder.
buildInstr(SPIRV::OpTypeFloat)
215 return createConstOrTypeAtFunctionEntry(
217 return MIRBuilder.
buildInstr(SPIRV::OpTypeVoid)
242 "Cannot invalidate aliasing instructions.");
243 assert(
MI->getOpcode() != SPIRV::OpFunction &&
244 "Cannot invalidate OpFunction.");
246 if (
MI->getOpcode() == SPIRV::OpFunctionCall) {
248 auto It = ForwardCalls.find(
F);
249 if (It != ForwardCalls.end()) {
250 It->second.erase(
MI);
251 if (It->second.empty())
252 ForwardCalls.erase(It);
258 auto It = LastInsertedTypeMap.find(MF);
259 if (It != LastInsertedTypeMap.end() && It->second ==
MI)
260 LastInsertedTypeMap.erase(MF);
271 if (
MI.getNumDefs() &&
TII.isTypeDeclInstr(
MI))
284 auto TypesIt = VRegToTypeMap.find(&MF);
285 if (TypesIt == VRegToTypeMap.end())
291 for (
auto [Reg, Ty] : TypesIt->second) {
295 if (TypeReg != Reg && !
MRI.reg_empty(Reg))
302const MachineInstr *SPIRVGlobalRegistry::createConstOrTypeAtFunctionEntry(
306 assert(oldInsertPoint.isValid() &&
"Builder must have insertion point set!");
310 auto LastInsertedType = LastInsertedTypeMap.find(
CurMF);
311 if (LastInsertedType != LastInsertedTypeMap.end()) {
312 auto It = LastInsertedType->second->getIterator();
316 if (It->getParent() != NewMBB)
317 InsertAt = oldInsertPoint->getParent() == NewMBB
320 else if (It->getNextNode())
321 InsertAt = It->getNextNode()->getIterator();
327 auto Result = LastInsertedTypeMap.try_emplace(
CurMF,
nullptr);
329 LastInsertedType = Result.first;
332 MachineInstr *ConstOrType =
Op(MIRBuilder);
336 LastInsertedType->second = ConstOrType;
339 while (
auto *
Next = LastInsertedType->second->getNextNode()) {
340 unsigned Opc =
Next->getOpcode();
341 if (
Opc == SPIRV::OpTypeStructContinuedINTEL ||
342 Opc == SPIRV::OpConstantCompositeContinuedINTEL ||
343 Opc == SPIRV::OpSpecConstantCompositeContinuedINTEL ||
344 Opc == SPIRV::OpCompositeConstructContinuedINTEL)
345 LastInsertedType->second =
Next;
356 bool IsLongVectorEXT) {
360 SPIRV::Extension::SPV_INTEL_masked_gather_scatter)) {
364 "Vector of pointers requires SPV_INTEL_masked_gather_scatter "
369 [[maybe_unused]]
auto EleOpc = ElemType->
getOpcode();
370 assert((EleOpc == SPIRV::OpTypeInt || EleOpc == SPIRV::OpTypeFloat ||
371 EleOpc == SPIRV::OpTypeBool) &&
372 "Invalid vector element type");
375 return createConstOrTypeAtFunctionEntry(
376 MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
378 IsLongVectorEXT ? SPIRV::OpTypeVectorIdEXT : SPIRV::OpTypeVector;
382 if (!IsLongVectorEXT)
383 return MIB.
addImm(NumElems);
388 Int32Ty, *
ST.getInstrInfo()));
393SPIRVGlobalRegistry::getOpTypeVector(uint32_t NumElems,
SPIRVTypeInst ElemType,
395 assert(NumElems >= 2 &&
"SPIR-V OpTypeVector requires at least 2 components");
396 return getOpTypeVectorImpl(NumElems, ElemType, MIRBuilder);
401 assert(NumElems != 2 && NumElems != 3 && NumElems != 4 &&
403 (NumElems != 8 && NumElems != 16)) &&
404 "SPIR-V OpTypeVectorIdExt should only be used for extended vectors");
405 return getOpTypeVectorImpl(NumElems, ElemType, MIRBuilder,
true);
413 auto *
const CF = ConstantFP::get(Ctx, Val);
415 if (
MI && (
MI->getOpcode() == SPIRV::OpConstantNull ||
416 MI->getOpcode() == SPIRV::OpConstantF))
417 return MI->getOperand(0).getReg();
429 CurMF->getRegInfo().setRegClass(Res, &SPIRV::fIDRegClass);
435 const MachineInstr *Const = createConstOrTypeAtFunctionEntry(
440 MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantNull)
444 MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantF)
451 constrainSelectedInstRegOperands(MIB);
463 SpvType,
TII, ZeroAsNull);
471 auto *
const CI = ConstantInt::get(
474 if (
MI && (
MI->getOpcode() == SPIRV::OpConstantNull ||
475 MI->getOpcode() == SPIRV::OpConstantI))
476 return MI->getOperand(0).getReg();
487 Register Res =
CurMF->getRegInfo().createGenericVirtualRegister(LLTy);
488 CurMF->getRegInfo().setRegClass(Res, &SPIRV::iIDRegClass);
494 const MachineInstr *Const = createConstOrTypeAtFunctionEntry(
500 : SPIRV::OpConstantTrue)
503 }
else if (!CI->
isZero() || !ZeroAsNull) {
504 MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantI)
509 MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantNull)
513 constrainSelectedInstRegOperands(MIB);
523 bool EmitIR,
bool ZeroAsNull) {
525 auto &MF = MIRBuilder.
getMF();
529 auto *
const CI = ConstantInt::get(
const_cast<IntegerType *
>(Ty), Val,
538 Res =
MRI.createGenericVirtualRegister(LLTy);
539 MRI.setRegClass(Res, &SPIRV::iIDRegClass);
543 const MachineInstr *Const = createConstOrTypeAtFunctionEntry(
549 if (Val || !ZeroAsNull) {
550 MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantI)
555 MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantNull)
559 constrainSelectedInstRegOperands(MIB);
569 auto &MF = MIRBuilder.
getMF();
573 SPIRV::AccessQualifier::ReadWrite,
true);
574 auto *
const CF = ConstantFP::get(Ctx, Val);
579 Res = MF.getRegInfo().createGenericVirtualRegister(
getRegType(SpvType));
580 MF.getRegInfo().setRegClass(Res, &SPIRV::fIDRegClass);
583 const MachineInstr *Const = createConstOrTypeAtFunctionEntry(
586 MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantF)
589 addNumImm(CF->getValueAPF().bitcastToAPInt(), MIB);
596Register SPIRVGlobalRegistry::getOrCreateBaseRegister(
604 if (
Type->getOpcode() == SPIRV::OpTypeFloat) {
609 assert(
Type->getOpcode() == SPIRV::OpTypeInt);
615Register SPIRVGlobalRegistry::getOrCreateCompositeOrNull(
618 unsigned ElemCnt,
bool ZeroAsNull) {
626 getOrCreateBaseRegister(Val,
I, SpvType,
TII,
BitWidth, ZeroAsNull);
629 Register Res =
CurMF->getRegInfo().createGenericVirtualRegister(LLTy);
633 MachineInstr *DepMI =
634 const_cast<MachineInstr *
>(
static_cast<const MachineInstr *
>(SpvType));
636 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
637 MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
638 MachineInstrBuilder MIB;
640 MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantComposite)
643 for (
unsigned i = 0; i < ElemCnt; ++i)
646 MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantNull)
650 constrainSelectedInstRegOperands(MIB);
663 I, SpvType,
TII, ZeroAsNull);
673 "Expected vector type for constant vector creation");
676 [[maybe_unused]]
const auto &ST =
I.getMF()->getSubtarget<
SPIRVSubtarget>();
680 SPIRV::Extension::SPV_INTEL_masked_gather_scatter))) &&
681 "Expected either integer element type for APInt constant vector or "
682 "pointer type if the SPV_INTEL_masked_gather_scatter extension is "
686 ConstVal = ConstantInt::get(LLVMBaseTy, Val);
696 return getOrCreateCompositeOrNull(ConstVal,
I, SpvType,
TII, ConstVec, BW,
711 auto *ConstVal = ConstantFP::get(LLVMBaseTy, Val);
715 return getOrCreateCompositeOrNull(ConstVal,
I, SpvType,
TII, ConstVec, BW,
727 Constant *CI = ConstantInt::get(LLVMBaseTy, Val);
742 ConstantInt::get(LLVMBaseTy, Val), ConstantInt::get(I64Ty, Num)});
743 return getOrCreateCompositeOrNull(CI,
I, SpvType,
TII, UniqueKey, BW,
747Register SPIRVGlobalRegistry::getOrCreateIntCompositeOrNull(
764 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
770 auto MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantComposite)
773 for (
unsigned i = 0; i < ElemCnt; ++i)
778 return MIRBuilder.
buildInstr(SPIRV::OpConstantNull)
793 const auto ConstInt = ConstantInt::get(LLVMBaseTy, Val);
797 return getOrCreateIntCompositeOrNull(
798 Val, MIRBuilder, SpvType, EmitIR, ConstVec, BW,
816 Res =
CurMF->getRegInfo().createGenericVirtualRegister(LLTy);
817 CurMF->getRegInfo().setRegClass(Res, &SPIRV::pIDRegClass);
820 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
822 return MIRBuilder.
buildInstr(SPIRV::OpConstantNull)
832 unsigned Param,
unsigned FilerMode,
845 MIRBuilder.
buildInstr(SPIRV::OpConstantSampler)
856 const GlobalValue *GV, SPIRV::StorageClass::StorageClass Storage,
858 const std::optional<SPIRV::LinkageType::LinkageType> &LinkageType,
867 GVar = M->getGlobalVariable(Name);
868 if (GVar ==
nullptr) {
892 if (&GVBuilder.
getMBB() != &EntryBB)
897 const bool UseUntypedPointers =
898 BaseType->getOpcode() == SPIRV::OpTypeUntypedPointerKHR;
899 const unsigned VariableOpcode =
900 UseUntypedPointers ? SPIRV::OpUntypedVariableKHR : SPIRV::OpVariable;
902 auto MIB = GVBuilder.
buildInstr(VariableOpcode)
909 if (UseUntypedPointers) {
913 SPIRV::AccessQualifier::ReadWrite,
919 "Could not deduce the data type of untyped global variable '" +
925 SPIRV::AccessQualifier::ReadWrite,
935 if (IsInstSelector) {
936 constrainSelectedInstRegOperands(MIB);
945 if (Reg != ResVReg) {
948 MRI->setType(Reg, RegLLTy);
967 if (IsConst && !ST.isShader())
972 buildOpDecorate(Reg, MIRBuilder, SPIRV::Decoration::Alignment, {Alignment});
977 {
static_cast<uint32_t>(*LinkageType)}, Name);
979 SPIRV::BuiltIn::BuiltIn BuiltInId;
982 {
static_cast<uint32_t>(BuiltInId)});
988 if (GVar && (GVarMD = GVar->
getMetadata(
"spirv.Decorations")) !=
nullptr)
1005 std::nullopt, MIRBuilder,
false);
1007 buildOpDecorate(VarReg, MIRBuilder, SPIRV::Decoration::DescriptorSet, {Set});
1008 buildOpDecorate(VarReg, MIRBuilder, SPIRV::Decoration::Binding, {Binding});
1017 bool ExplicitLayoutRequired,
1020 "Invalid array element type");
1025 if (NumElems != 0) {
1028 ArrayType = createConstOrTypeAtFunctionEntry(
1030 return MIRBuilder.
buildInstr(SPIRV::OpTypeArray)
1033 .
addUse(NumElementsVReg);
1041 ArrayType = createConstOrTypeAtFunctionEntry(
1042 MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
1043 return MIRBuilder.
buildInstr(SPIRV::OpTypeArray)
1046 .
addUse(NumElementsVReg);
1049 if (!
ST.isShader()) {
1051 "Runtime arrays are not allowed in non-shader "
1055 ArrayType = createConstOrTypeAtFunctionEntry(
1056 MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
1057 return MIRBuilder.
buildInstr(SPIRV::OpTypeRuntimeArray)
1065 addArrayStrideDecorations(
ArrayType->defs().begin()->getReg(), ET,
1073SPIRVGlobalRegistry::getOpTypeOpaque(
const StructType *Ty,
1078 return createConstOrTypeAtFunctionEntry(
1079 MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
1089 SPIRV::AccessQualifier::AccessQualifier AccQual,
1091 Type *OriginalElementType =
nullptr;
1094 SPIRVTypeInst ElementSPIRVType = findSPIRVType(
1095 OriginalElementType, MIRBuilder, AccQual,
1096 Decorator !=
nullptr, EmitIR);
1097 return getOpTypeArray(TotalSize, ElementSPIRVType, MIRBuilder,
1098 Decorator !=
nullptr,
1102 const SPIRVSubtarget &
ST =
1105 constexpr unsigned MaxWordCount = UINT16_MAX;
1108 size_t MaxNumElements = MaxWordCount - 2;
1109 size_t SPIRVStructNumElements = NumElements;
1110 if (NumElements > MaxNumElements) {
1112 SPIRVStructNumElements = MaxNumElements;
1113 MaxNumElements = MaxWordCount - 1;
1116 for (
const auto &Elem : Ty->
elements()) {
1117 SPIRVTypeInst ElemTy = findSPIRVType(
1119 Decorator !=
nullptr, EmitIR);
1121 "Invalid struct element type");
1130 SPIRVTypeInst SPVType = createConstOrTypeAtFunctionEntry(
1131 MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
1134 for (
size_t I = 0;
I < SPIRVStructNumElements; ++
I)
1135 MIBStruct.
addUse(FieldTypes[
I]);
1136 for (
size_t I = SPIRVStructNumElements;
I < NumElements;
1137 I += MaxNumElements) {
1139 MIRBuilder.
buildInstr(SPIRV::OpTypeStructContinuedINTEL);
1140 for (
size_t J =
I; J < std::min(
I + MaxNumElements, NumElements); ++J)
1141 MIBCont.
addUse(FieldTypes[J]);
1147 Decorator(SPVType->defs().begin()->getReg());
1154 SPIRV::AccessQualifier::AccessQualifier AccQual) {
1160 SPIRV::StorageClass::StorageClass SC,
SPIRVTypeInst ElemType,
1163 const SPIRVSubtarget &
ST =
1171 return createConstOrTypeAtFunctionEntry(MIRBuilder, [&](MachineIRBuilder
1173 return MIRBuilder.
buildInstr(SPIRV::OpTypePointer)
1175 .
addImm(
static_cast<uint32_t
>(SC))
1184 const SPIRVSubtarget *
ST =
1185 static_cast<const SPIRVSubtarget *
>(&MIRBuilder.
getMF().getSubtarget());
1186 if (Ty->isVarArg() &&
ST->isShader()) {
1188 Ty->getContext().diagnose(DiagnosticInfoUnsupported(
1189 Fn,
"SPIR-V shaders do not support variadic functions",
1192 return createConstOrTypeAtFunctionEntry(MIRBuilder, [&](MachineIRBuilder
1194 auto MIB = MIRBuilder.
buildInstr(SPIRV::OpTypeFunction)
1197 for (
auto &ArgType : ArgTypes)
1211 add(Ty,
false, NewMI);
1212 return finishCreatingSPIRVType(Ty, NewMI);
1217 SPIRV::AccessQualifier::AccessQualifier AccQual,
1218 bool ExplicitLayoutRequired,
bool EmitIR) {
1222 FVT && FVT->getNumElements() == 1 &&
1223 !STI.canUseExtension(SPIRV::Extension::SPV_EXT_long_vector))
1224 return findSPIRVType(FVT->getElementType(), MIRBuilder, AccQual,
1225 ExplicitLayoutRequired, EmitIR);
1226 Ty = adjustIntTypeByWidth(Ty);
1229 findMI(Ty, ExplicitLayoutRequired, &MIRBuilder.
getMF()))
1231 if (
auto It = ForwardPointerTypes.find(Ty); It != ForwardPointerTypes.end())
1233 return restOfCreateSPIRVType(Ty, MIRBuilder, AccQual, ExplicitLayoutRequired,
1238 assert(SpirvType &&
"Attempting to get type id for nullptr type.");
1239 if (SpirvType->
getOpcode() == SPIRV::OpTypeForwardPointer ||
1240 SpirvType->
getOpcode() == SPIRV::OpTypeStructContinuedINTEL)
1241 return SpirvType->
uses().
begin()->getReg();
1242 return SpirvType->
defs().
begin()->getReg();
1253const Type *SPIRVGlobalRegistry::adjustIntTypeByWidth(
const Type *Ty)
const {
1255 unsigned SrcBitWidth = IType->getBitWidth();
1256 if (SrcBitWidth > 1) {
1257 unsigned BitWidth = adjustOpTypeIntWidth(SrcBitWidth);
1268 SPIRV::AccessQualifier::AccessQualifier AccQual,
1269 bool ExplicitLayoutRequired,
bool EmitIR) {
1271 return getOrCreateSpecialType(Ty, MIRBuilder, AccQual);
1273 if (
const MachineInstr *
MI =
1274 findMI(Ty, ExplicitLayoutRequired, &MIRBuilder.
getMF()))
1278 const unsigned Width = IType->getBitWidth();
1279 return Width == 1 ? getOpTypeBool(MIRBuilder)
1280 : getOpTypeInt(Width, MIRBuilder,
false);
1287 SPIRV::FPEncoding::BFloat16KHR);
1297 AccQual, ExplicitLayoutRequired, EmitIR);
1301 STI.canUseExtension(SPIRV::Extension::SPV_EXT_long_vector))
1302 return getOpTypeVectorIdEXT(NumElts, El, MIRBuilder);
1303 return getOpTypeVector(NumElts, El, MIRBuilder);
1307 AccQual, ExplicitLayoutRequired, EmitIR);
1309 ExplicitLayoutRequired, EmitIR);
1312 if (SType->isOpaque())
1313 return getOpTypeOpaque(SType, MIRBuilder);
1316 if (ExplicitLayoutRequired) {
1317 Decorator = [&MIRBuilder, SType,
this](
Register Reg) {
1318 addStructOffsetDecorations(
Reg,
const_cast<StructType *
>(SType),
1322 return getOpTypeStruct(SType, MIRBuilder, AccQual, std::move(Decorator),
1326 SPIRVTypeInst RetTy =
1327 findSPIRVType(FType->getReturnType(), MIRBuilder, AccQual,
1328 ExplicitLayoutRequired, EmitIR);
1330 for (
const auto &ParamTy : FType->params())
1331 ParamTypes.
push_back(findSPIRVType(ParamTy, MIRBuilder, AccQual,
1332 ExplicitLayoutRequired, EmitIR));
1333 return getOpTypeFunction(FType, RetTy, ParamTypes, MIRBuilder);
1339 const SPIRVSubtarget *
ST =
1340 static_cast<const SPIRVSubtarget *
>(&MIRBuilder.
getMF().getSubtarget());
1343 SPIRVTypeInst SpvElementType =
nullptr;
1346 !
ST->canUseExtension(SPIRV::Extension::SPV_INTEL_function_pointers))
1359 if (
auto It = ForwardPointerTypes.find(Ty); It != ForwardPointerTypes.end()) {
1362 return getOpTypePointer(SC, SpvElementType, MIRBuilder,
Reg);
1370 SPIRV::AccessQualifier::AccessQualifier AccessQual,
1371 bool ExplicitLayoutRequired,
bool EmitIR) {
1376 TypesInProcessing.insert(Ty);
1377 SPIRVTypeInst SpirvType = createSPIRVType(Ty, MIRBuilder, AccessQual,
1378 ExplicitLayoutRequired, EmitIR);
1379 TypesInProcessing.erase(Ty);
1386 if (SpirvType->
getOpcode() == SPIRV::OpTypeForwardPointer ||
1387 SpirvType->
getOpcode() == SPIRV::OpTypeUntypedPointerKHR ||
1393 add(ExtTy->getTypeParameter(0), ExtTy->getIntParameter(0), SpirvType);
1395 add(Ty, ExplicitLayoutRequired, SpirvType);
1408 auto t = VRegToTypeMap.find(MF ? MF :
CurMF);
1409 if (t != VRegToTypeMap.end()) {
1410 auto tt = t->second.find(VReg);
1411 if (tt != t->second.end())
1427 SPIRV::AccessQualifier::AccessQualifier AccessQual,
1428 bool ExplicitLayoutRequired,
bool EmitIR) {
1433 FVT && FVT->getNumElements() == 1 &&
1434 !STI.canUseExtension(SPIRV::Extension::SPV_EXT_long_vector))
1436 ExplicitLayoutRequired, EmitIR);
1441 Reg =
find(ExtTy->getTypeParameter(0), ExtTy->getIntParameter(0), MF);
1443 Reg =
find(Ty = adjustIntTypeByWidth(Ty), ExplicitLayoutRequired, MF);
1453 TypesInProcessing.clear();
1454 SPIRVTypeInst STy = restOfCreateSPIRVType(Ty, MIRBuilder, AccessQual,
1455 ExplicitLayoutRequired, EmitIR);
1457 for (
auto &
CU : ForwardPointerTypes) {
1460 bool PtrNeedsLayout =
false;
1461 const Type *Ty2 =
CU.first;
1463 if ((Reg =
find(Ty2, PtrNeedsLayout, MF)).
isValid())
1466 STy2 = restOfCreateSPIRVType(Ty2, MIRBuilder, AccessQual, PtrNeedsLayout,
1471 ForwardPointerTypes.clear();
1476 unsigned TypeOpcode)
const {
1478 assert(
Type &&
"isScalarOfType VReg has no type assigned");
1479 return Type->getOpcode() == TypeOpcode;
1483 unsigned TypeOpcode)
const {
1485 assert(
Type &&
"isScalarOrVectorOfType VReg has no type assigned");
1486 if (
Type->getOpcode() == TypeOpcode)
1490 Register ScalarTypeVReg =
Type->getOperand(1).getReg();
1492 return ScalarType->
getOpcode() == TypeOpcode;
1496 switch (
Type->getOpcode()) {
1497 case SPIRV::OpTypeImage:
1498 case SPIRV::OpTypeSampler:
1499 case SPIRV::OpTypeSampledImage:
1501 case SPIRV::OpTypeStruct:
1502 return BlockDecoratedTypes.contains(
Type);
1518 return (
Type->getOpcode() == SPIRV::OpTypeVector)
1519 ?
static_cast<unsigned>(
Type->getOperand(2).
getImm())
1529 :
Type->getOperand(0).getReg();
1540 if (ScalarType->
getOpcode() == SPIRV::OpTypeInt ||
1541 ScalarType->
getOpcode() == SPIRV::OpTypeFloat)
1543 if (ScalarType->
getOpcode() == SPIRV::OpTypeBool)
1545 if (ScalarType->
getOpcode() == SPIRV::OpTypePointer)
1548 "Attempting to get bit width of non-integer/float/pointer type.");
1556 return ScalarType->
getOpcode() == SPIRV::OpTypeInt ||
1557 ScalarType->
getOpcode() == SPIRV::OpTypeFloat
1565 if (ElemType && ElemType->
getOpcode() == SPIRV::OpTypeFunction)
1567 auto It = SPIRVToLLVMType.find(ElemType);
1568 return It != SPIRVToLLVMType.end() && It->second &&
1575 return ST.canUseExtension(SPIRV::Extension::SPV_KHR_untyped_pointers) &&
1582 return ScalarType && ScalarType->
getOpcode() == SPIRV::OpTypeInt ? ScalarType
1592 return PtrType && PtrType->
getOpcode() == SPIRV::OpTypePointer
1599 if (!Type1 || !Type2)
1612 return Bits1 > 0 && Bits1 == Bits2;
1615SPIRV::StorageClass::StorageClass
1619 "Pointer type is expected");
1623SPIRV::StorageClass::StorageClass
1625 return static_cast<SPIRV::StorageClass::StorageClass
>(
1631 SPIRV::StorageClass::StorageClass SC,
bool IsWritable,
bool EmitIr) {
1642 ExplicitLayoutRequired, EmitIr);
1645 SPIRV::Decoration::Block, {});
1646 BlockDecoratedTypes.insert(BlockType);
1650 SPIRV::Decoration::NonWritable, 0, {});
1654 getOrCreateSPIRVPointerTypeInternal(BlockType, MIRBuilder, SC);
1666 finishCreatingSPIRVType(
T, R);
1673 const auto SC = SPIRV::StorageClass::PushConstant;
1682 T, MIRBuilder, SPIRV::AccessQualifier::None,
1686 SPIRV::Decoration::Block, {});
1687 BlockDecoratedTypes.insert(BlockType);
1701 assert(ST->getNumElements() == Offsets.size());
1714 getOpTypeStruct(ST, MIRBuilder, SPIRV::AccessQualifier::None,
1715 std::move(Decorator), EmitIr);
1716 add(
Key, SPIRVStructType);
1717 return SPIRVStructType;
1722 const SPIRV::AccessQualifier::AccessQualifier Qualifier,
1725 "SPIR-V image builtin type must have sampled type parameter!");
1728 SPIRV::AccessQualifier::ReadWrite,
true);
1731 "Invalid number of parameters for SPIR-V image builtin!");
1733 SPIRV::AccessQualifier::AccessQualifier accessQualifier =
1734 SPIRV::AccessQualifier::None;
1736 accessQualifier = Qualifier == SPIRV::AccessQualifier::WriteOnly
1737 ? SPIRV::AccessQualifier::WriteOnly
1738 : SPIRV::AccessQualifier::AccessQualifier(
1744 MIRBuilder, SampledType,
1750 SPIRVToLLVMType[R] = ExtensionType;
1758 SPIRV::ImageFormat::ImageFormat ImageFormat,
1759 SPIRV::AccessQualifier::AccessQualifier AccessQual) {
1761 Depth, Arrayed, Multisampled, Sampled,
1762 ImageFormat, AccessQual);
1765 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
1777 if (AccessQual != SPIRV::AccessQualifier::None)
1791 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
1793 return MIRBuilder.
buildInstr(SPIRV::OpTypeSampler)
1802 SPIRV::AccessQualifier::AccessQualifier AccessQual) {
1806 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
1808 return MIRBuilder.
buildInstr(SPIRV::OpTypePipe)
1821 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
1823 return MIRBuilder.
buildInstr(SPIRV::OpTypeDeviceEvent)
1838 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
1840 return MIRBuilder.
buildInstr(SPIRV::OpTypeSampledImage)
1853 findMI(ExtensionType,
false, &MIRBuilder.
getMF()))
1855 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
1862 .canUseExtension(SPIRV::Extension::SPV_INTEL_int4)) {
1864 .
addImm(SPIRV::Capability::Int4CooperativeMatrixINTEL);
1866 return MIRBuilder.
buildInstr(SPIRV::OpTypeCooperativeMatrixKHR)
1874 add(ExtensionType,
false, NewMI);
1882 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
1886 add(Ty,
false, NewMI);
1896 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
1902 assert((Operand.isReg() || Operand.isImm()) &&
1903 "Expected register or immediate operand");
1908 add(Ty,
false, NewMI);
1915 SPIRV::StorageClass::StorageClass SC,
1916 SPIRV::AccessQualifier::AccessQualifier AQ) {
1917 unsigned VecElts = 0;
1924 MIRBuilder, AQ,
false,
true);
1945 TypeStr = TypeStr.
substr(0, TypeStr.
find(
']'));
1962 MIRBuilder, SPIRV::AccessQualifier::ReadWrite,
false,
true);
1966SPIRVGlobalRegistry::finishCreatingSPIRVType(
const Type *LLVMTy,
1977 unsigned SPIRVOPcode,
Type *Ty) {
1982 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
1985 MIRBuilder.
getDL(),
TII.get(SPIRVOPcode))
1989 if (!Ty->isFloatTy()) {
1990 return NewTypeMI.addImm(0);
1995 add(Ty,
false, NewMI);
1996 return finishCreatingSPIRVType(Ty, NewMI);
2036 MIRBuilder, SPIRV::AccessQualifier::ReadWrite,
false, EmitIR);
2047 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
2050 MIRBuilder.
getDL(),
TII.get(SPIRV::OpTypeBool))
2053 add(Ty,
false, NewMI);
2054 return finishCreatingSPIRVType(Ty, NewMI);
2063 MIRBuilder, SPIRV::AccessQualifier::ReadWrite,
false, EmitIR);
2070 if (!STI.canUseExtension(SPIRV::Extension::SPV_EXT_long_vector))
2073 assert(NumElements >= 2 &&
2074 "SPIR-V vectors must have at least 2 components");
2082 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
2090 add(Ty,
false, NewMI);
2091 return finishCreatingSPIRVType(Ty, NewMI);
2103 SPIRV::StorageClass::StorageClass SC,
bool ForceTyped) {
2106 .canUseExtension(SPIRV::Extension::SPV_INTEL_function_pointers)) {
2108 F.getContext().diagnose(
2110 "Function used as a data pointer requires "
2111 "SPV_INTEL_function_pointers extension",
2116 BaseType, MIRBuilder, SPIRV::AccessQualifier::ReadWrite,
2119 return getOrCreateSPIRVPointerTypeInternal(SpirvBaseType, MIRBuilder, SC,
2124 SPIRVTypeInst PtrType, SPIRV::StorageClass::StorageClass SC,
2126 [[maybe_unused]] SPIRV::StorageClass::StorageClass OldSC =
2133 return getOrCreateSPIRVPointerTypeInternal(PointeeType, MIRBuilder, SC);
2138 SPIRV::StorageClass::StorageClass SC) {
2143 (R->getOpcode() == SPIRV::OpTypeUntypedPointerKHR ||
2145 "The base type was not correctly laid out for the given storage class.");
2149SPIRVTypeInst SPIRVGlobalRegistry::getOrCreateSPIRVPointerTypeInternal(
2151 SPIRV::StorageClass::StorageClass SC,
bool ForceTyped) {
2164 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
2168 MIRBuilder.
getTII().
get(SPIRV::OpTypePointer))
2174 return finishCreatingSPIRVType(Ty, NewMI);
2181 assert(ST.canUseExtension(SPIRV::Extension::SPV_KHR_untyped_pointers) &&
2182 !ST.isShader() &&
"Untyped pointers are not available");
2191 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
2195 MIRBuilder.
getTII().
get(SPIRV::OpTypeUntypedPointerKHR))
2200 return finishCreatingSPIRVType(Ty, NewMI);
2213 Res =
CurMF->getRegInfo().createGenericVirtualRegister(LLTy);
2214 CurMF->getRegInfo().setRegClass(Res, &SPIRV::iIDRegClass);
2220 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
2223 MIRBuilder.
getDL(),
TII.get(SPIRV::OpUndef))
2226 constrainSelectedInstRegOperands(MIB);
2237 case SPIRV::OpTypeFloat:
2238 return &SPIRV::fIDRegClass;
2239 case SPIRV::OpTypePointer:
2240 case SPIRV::OpTypeUntypedPointerKHR:
2241 return &SPIRV::pIDRegClass;
2242 case SPIRV::OpTypeVector:
2243 case SPIRV::OpTypeVectorIdEXT: {
2245 unsigned ElemOpcode = ElemType ? ElemType->
getOpcode() : 0;
2246 if (ElemOpcode == SPIRV::OpTypeFloat)
2247 return &SPIRV::vfIDRegClass;
2249 return &SPIRV::vpIDRegClass;
2250 return &SPIRV::viIDRegClass;
2253 return &SPIRV::iIDRegClass;
2258 static_cast<SPIRV::StorageClass::StorageClass
>(
2270 unsigned Opcode = SpvType ? SpvType->
getOpcode() : 0;
2272 case SPIRV::OpTypeFloat:
2274 case SPIRV::OpTypeInt:
2275 case SPIRV::OpTypeBool:
2277 case SPIRV::OpTypePointer:
2278 case SPIRV::OpTypeUntypedPointerKHR:
2280 case SPIRV::OpTypeVector:
2281 case SPIRV::OpTypeVectorIdEXT: {
2284 switch (ElemType ? ElemType->
getOpcode() : 0) {
2285 case SPIRV::OpTypePointer:
2286 case SPIRV::OpTypeUntypedPointerKHR:
2289 case SPIRV::OpTypeFloat:
2292 case SPIRV::OpTypeInt:
2293 case SPIRV::OpTypeBool:
2317 if (
auto L = AliasInstMDMap.find({MF, AliasingListMD});
2318 L != AliasInstMDMap.end())
2325 if (ScopeMD->getNumOperands() < 2)
2331 auto D = AliasInstMDMap.find({MF, DomainMD});
2332 if (
D != AliasInstMDMap.end())
2334 const Register Ret =
MRI->createVirtualRegister(&SPIRV::IDRegClass);
2339 AliasInstMDMap.insert(
2340 std::make_pair(std::make_pair(MF, DomainMD),
Domain));
2342 auto S = AliasInstMDMap.find({MF, ScopeMD});
2343 if (S != AliasInstMDMap.end())
2345 const Register Ret =
MRI->createVirtualRegister(&SPIRV::IDRegClass);
2346 auto MIB = MIRBuilder.
buildInstr(SPIRV::OpAliasScopeDeclINTEL)
2351 AliasInstMDMap.insert(std::make_pair(std::make_pair(MF, ScopeMD), Scope));
2356 const Register Ret =
MRI->createVirtualRegister(&SPIRV::IDRegClass);
2359 for (
auto *Scope : ScopeList)
2360 MIB.
addUse(Scope->getOperand(0).getReg());
2363 std::make_pair(std::make_pair(MF, AliasingListMD),
List));
2369 const MDNode *AliasingListMD) {
2387 bool CanUseAnyVectorRank) {
2396 B.CreateIntrinsic(Intrinsic::spv_value_md,
2398 AssignCI =
B.CreateIntrinsicWithoutFolding(Intrinsic::fake_use, {Arg});
2401 OfType, Arg, {},
B);
2411 B.GetInsertBlock() ?
B.GetInsertBlock()->getParent() :
nullptr;
2412 if (AssignPtrTyCI ==
nullptr ||
2413 AssignPtrTyCI->
getParent()->getParent() != CurrF) {
2415 Intrinsic::spv_assign_ptr_type, {Arg->
getType()}, OfType, Arg,
2429 Intrinsic::spv_assign_ptr_type)
2438void SPIRVGlobalRegistry::addStructOffsetDecorations(
2441 for (
uint32_t I = 0;
I < Ty->getNumElements(); ++
I) {
2447void SPIRVGlobalRegistry::addArrayStrideDecorations(
2449 uint32_t SizeInBytes = DL.getTypeAllocSize(ElementType);
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
Function Alias Analysis false
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const HexagonInstrInfo * TII
static constexpr Value * getValue(Ty &ValueOrUse)
Promote Memory to Register
MachineRegisterInfo & MRI
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
static bool storageClassRequiresExplictLayout(SPIRV::StorageClass::StorageClass SC)
static Register createTypeVReg(MachineRegisterInfo &MRI)
static SmallVector< const MachineInstr * > getTypeDecls(const MachineFunction &MF)
static bool allowEmitFakeUse(const Value *Arg)
static unsigned typeToAddressSpace(const Type *Ty)
static LLT getFloatRegType(SPIRVTypeInst FloatType)
unsigned getAS(SPIRVTypeInst SpvType)
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
APInt bitcastToAPInt() const
Class for arbitrary precision integers.
uint64_t getZExtValue() const
Get zero extended value.
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
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
const APFloat & getValueAPF() 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.
const APInt & getValue() const
Return the constant as an APInt value reference.
static LLVM_ABI 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 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.
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
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,...
A parsed version of the target data layout string in and methods for querying it.
Diagnostic information for unsupported feature in backend.
static constexpr ElementCount getFixed(ScalarTy MinVal)
Class to represent fixed width SIMD vectors.
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
Class to represent function types.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this GlobalObject.
Module * getParent()
Get the module that this global value is contained inside of...
@ ExternalLinkage
Externally visible function.
Type * getValueType() const
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.
static constexpr LLT bfloat16()
static constexpr LLT scalarOrVector(ElementCount EC, LLT ScalarTy)
static LLT floatIEEE(unsigned SizeInBits)
This is an important class for using LLVM in a threaded context.
LLVM_ABI void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
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.
MachineInstrBundleIterator< MachineInstr > iterator
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.
const MachineBasicBlock & front() const
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.
MachineIRBuilderState & getState()
Getter for the State.
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.
void constrainAllUses(const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI) const
const MachineInstrBuilder & addUse(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register use operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addDef(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register definition operand.
MachineInstr * getInstr() const
If conversion operators fail, use this method to get the MachineInstr explicitly.
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
unsigned getNumOperands() const
Retuns the total number of operands.
LLVM_ABI void insert(mop_iterator InsertBefore, ArrayRef< MachineOperand > Ops)
Inserts Ops BEFORE It. Can untie/retie tied operands.
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
MachineOperand class - Representation of each machine instruction operand.
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI LLVM_READONLY 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...
A Module instance is used to store all the information related to an LLVM module.
static LLVM_ABI PointerType * get(LLVMContext &C, unsigned AddressSpace)
This constructs an opaque pointer to an object in a numbered address space.
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
void buildAssignType(IRBuilder<> &B, Type *Ty, Value *Arg, bool CanUseAnyVectorRank)
SPIRVTypeInst getImageType(const TargetExtType *ExtensionType, const SPIRV::AccessQualifier::AccessQualifier Qualifier, MachineIRBuilder &MIRBuilder)
bool isScalarOrVectorSigned(SPIRVTypeInst Type) const
void addAssignPtrTypeInstr(Value *Val, CallInst *AssignPtrTyCI)
SPIRVTypeInst getOrCreateOpTypeSampledImage(SPIRVTypeInst ImageType, MachineIRBuilder &MIRBuilder)
unsigned getNumScalarOrVectorTotalBitWidth(SPIRVTypeInst Type) const
SPIRVTypeInst getOrCreateUnknownType(const Type *Ty, MachineIRBuilder &MIRBuilder, unsigned Opcode, const ArrayRef< MachineOperand > Operands)
void assignSPIRVTypeToVReg(SPIRVTypeInst Type, Register VReg, const MachineFunction &MF)
SPIRVTypeInst getOrCreateOpTypeFunctionWithArgs(const Type *Ty, SPIRVTypeInst RetType, const SmallVectorImpl< SPIRVTypeInst > &ArgTypes, MachineIRBuilder &MIRBuilder)
SPIRVTypeInst getOrCreateSPIRVPointerType(const Type *BaseType, MachineIRBuilder &MIRBuilder, SPIRV::StorageClass::StorageClass SC, bool ForceTyped=false)
void buildAssignPtr(IRBuilder<> &B, Type *ElemTy, Value *Arg)
const TargetRegisterClass * getRegClass(SPIRVTypeInst SpvType) const
MachineInstr * getOrAddMemAliasingINTELInst(MachineIRBuilder &MIRBuilder, const MDNode *AliasingListMD)
unsigned getScalarOrVectorBitWidth(SPIRVTypeInst Type) const
SPIRVTypeInst getOrCreateSPIRVIntegerType(unsigned BitWidth, MachineIRBuilder &MIRBuilder)
SPIRVTypeInst getOrCreateSPIRVVectorType(SPIRVTypeInst BaseType, unsigned NumElements, MachineIRBuilder &MIRBuilder, bool EmitIR)
SPIRVTypeInst getOrCreateSPIRVTypeByName(StringRef TypeStr, MachineIRBuilder &MIRBuilder, bool EmitIR, SPIRV::StorageClass::StorageClass SC=SPIRV::StorageClass::Function, SPIRV::AccessQualifier::AccessQualifier AQ=SPIRV::AccessQualifier::ReadWrite)
Register buildGlobalVariable(Register Reg, SPIRVTypeInst BaseType, StringRef Name, const GlobalValue *GV, SPIRV::StorageClass::StorageClass Storage, const MachineInstr *Init, bool IsConst, const std::optional< SPIRV::LinkageType::LinkageType > &LinkageType, MachineIRBuilder &MIRBuilder, bool IsInstSelector)
SPIRVTypeInst assignIntTypeToVReg(unsigned BitWidth, Register VReg, MachineInstr &I, const SPIRVInstrInfo &TII)
SPIRVTypeInst getResultType(Register VReg, MachineFunction *MF=nullptr)
void replaceAllUsesWith(Value *Old, Value *New, bool DeleteOld=true)
SPIRVTypeInst getOrCreateOpTypeByOpcode(const Type *Ty, MachineIRBuilder &MIRBuilder, unsigned Opcode)
unsigned getScalarOrVectorComponentCount(Register VReg) const
const Type * getTypeForSPIRVType(SPIRVTypeInst Ty) const
bool isBitcastCompatible(SPIRVTypeInst Type1, SPIRVTypeInst Type2) const
void addDeducedElementType(Value *Val, Type *Ty)
bool shouldKeepTypedPtrType(SPIRVTypeInst ElemType) const
SPIRVTypeInst getOrCreatePaddingType(MachineIRBuilder &MIRBuilder)
unsigned getPointerSize() const
Register getOrCreateConstFP(APFloat Val, MachineInstr &I, SPIRVTypeInst SpvType, const SPIRVInstrInfo &TII, bool ZeroAsNull=true)
LLT getRegType(SPIRVTypeInst SpvType) const
SPIRVGlobalRegistry(DataLayout DL)
SPIRVTypeInst getOpTypeVoid(MachineIRBuilder &MIRBuilder)
void invalidateMachineInstr(MachineInstr *MI)
bool isResourceType(SPIRVTypeInst Type) const
SPIRVTypeInst getOrCreateSPIRVBoolType(MachineIRBuilder &MIRBuilder, bool EmitIR)
void updateIfExistDeducedElementType(Value *OldVal, Value *NewVal, bool DeleteOld)
bool isScalarOfType(Register VReg, unsigned TypeOpcode) const
Register getSPIRVTypeID(SPIRVTypeInst SpirvType) const
Register getOrCreateConstInt(uint64_t Val, MachineInstr &I, SPIRVTypeInst SpvType, const SPIRVInstrInfo &TII, bool ZeroAsNull=true)
Register getOrCreateConstIntArray(uint64_t Val, size_t Num, MachineInstr &I, SPIRVTypeInst SpvType, const SPIRVInstrInfo &TII)
SPIRVTypeInst retrieveScalarOrVectorIntType(SPIRVTypeInst Type) const
Register getOrCreateGlobalVariableWithBinding(SPIRVTypeInst VarType, uint32_t Set, uint32_t Binding, StringRef Name, MachineIRBuilder &MIRBuilder)
SPIRVTypeInst getOrCreateOpTypeCoopMatr(MachineIRBuilder &MIRBuilder, const TargetExtType *ExtensionType, SPIRVTypeInst ElemType, uint32_t Scope, uint32_t Rows, uint32_t Columns, uint32_t Use, bool EmitIR)
SPIRVTypeInst changePointerStorageClass(SPIRVTypeInst PtrType, SPIRV::StorageClass::StorageClass SC, MachineInstr &I)
Register getOrCreateConstVector(uint64_t Val, MachineInstr &I, SPIRVTypeInst SpvType, const SPIRVInstrInfo &TII, bool ZeroAsNull=true)
Register buildConstantFP(APFloat Val, MachineIRBuilder &MIRBuilder, SPIRVTypeInst SpvType=nullptr)
SPIRVTypeInst getOrCreateOpTypePipe(MachineIRBuilder &MIRBuilder, SPIRV::AccessQualifier::AccessQualifier AccQual)
void addGlobalObject(const Value *V, const MachineFunction *MF, Register R)
SPIRVTypeInst getScalarOrVectorComponentType(SPIRVTypeInst Type) const
SPIRVTypeInst getOrCreateSPIRVFloatType(unsigned BitWidth, MachineInstr &I, const SPIRVInstrInfo &TII)
SPIRVTypeInst getOrCreateVulkanBufferType(MachineIRBuilder &MIRBuilder, Type *ElemType, SPIRV::StorageClass::StorageClass SC, bool IsWritable, bool EmitIr=false)
SPIRVTypeInst getPointeeType(SPIRVTypeInst PtrType)
SPIRVTypeInst getOrCreateSPIRVType(const Type *Type, MachineInstr &I, SPIRV::AccessQualifier::AccessQualifier AQ, bool EmitIR)
Register getOrCreateConsIntVector(uint64_t Val, MachineIRBuilder &MIRBuilder, SPIRVTypeInst SpvType, bool EmitIR)
void updateIfExistAssignPtrTypeInstr(Value *OldVal, Value *NewVal, bool DeleteOld)
SPIRVTypeInst assignTypeToVReg(const Type *Type, Register VReg, MachineIRBuilder &MIRBuilder, SPIRV::AccessQualifier::AccessQualifier AQ, bool EmitIR)
bool isScalarOrVectorOfType(Register VReg, unsigned TypeOpcode) const
SPIRVTypeInst getOrCreateLayoutType(MachineIRBuilder &MIRBuilder, const TargetExtType *T, bool EmitIr=false)
void restoreFromMIR(const MachineFunction &MF)
Register createConstInt(const ConstantInt *CI, MachineInstr &I, SPIRVTypeInst SpvType, const SPIRVInstrInfo &TII, bool ZeroAsNull)
Register getOrCreateConstNullPtr(MachineIRBuilder &MIRBuilder, SPIRVTypeInst SpvType)
SPIRVTypeInst getSPIRVTypeForVReg(Register VReg, const MachineFunction *MF=nullptr) const
SPIRVTypeInst getOrCreateSPIRVUntypedPointerType(SPIRV::StorageClass::StorageClass SC, MachineIRBuilder &MIRBuilder)
Register getOrCreateUndef(MachineInstr &I, SPIRVTypeInst SpvType, const SPIRVInstrInfo &TII)
SPIRVTypeInst getOrCreateOpTypeSampler(MachineIRBuilder &MIRBuilder)
void buildMemAliasingOpDecorate(Register Reg, MachineIRBuilder &MIRBuilder, uint32_t Dec, const MDNode *GVarMD)
SPIRV::StorageClass::StorageClass getPointerStorageClass(Register VReg) const
bool shouldUseUntypedPointer(SPIRVTypeInst ElemType, const SPIRVSubtarget &ST) const
Register buildConstantSampler(Register Res, unsigned AddrMode, unsigned Param, unsigned FilerMode, MachineIRBuilder &MIRBuilder)
SmallVector< std::pair< Register, Register > > getVRegTypeIDs(const MachineFunction &MF) const
void updateAssignType(CallInst *AssignCI, Value *Arg, Value *OfType)
CallInst * findAssignPtrTypeInstr(const Value *Val)
Register buildConstantInt(uint64_t Val, MachineIRBuilder &MIRBuilder, SPIRVTypeInst SpvType, bool EmitIR, bool ZeroAsNull=true)
SPIRVTypeInst getOrCreateVulkanPushConstantType(MachineIRBuilder &MIRBuilder, Type *ElemType)
Register createConstFP(const ConstantFP *CF, MachineInstr &I, SPIRVTypeInst SpvType, const SPIRVInstrInfo &TII, bool ZeroAsNull)
SPIRVTypeInst getOrCreateOpTypeDeviceEvent(MachineIRBuilder &MIRBuilder)
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)
void insert_range(Range &&R)
bool contains(ConstPtrType Ptr) const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
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
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).
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
bool consume_front(char Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
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 IntegerType * getInt64Ty(LLVMContext &C)
LLVM_ABI unsigned getIntegerBitWidth() const
bool isVectorTy() const
True if this is an instance of VectorType.
bool isArrayTy() const
True if this is an instance of ArrayType.
bool isPointerTy() const
True if this is an instance of PointerType.
Type * getArrayElementType() const
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
LLVM_ABI uint64_t getArrayNumElements() const
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
bool isFP128Ty() const
Return true if this is 'fp128'.
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
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.
static LLVM_ABI Type * getDoubleTy(LLVMContext &C)
static LLVM_ABI Type * getFloatTy(LLVMContext &C)
static LLVM_ABI Type * getHalfTy(LLVMContext &C)
bool isVoidTy() const
Return true if this is 'void'.
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.
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_padding()
IRHandle irhandle_vkbuffer(const Type *ElementType, StorageClass::StorageClass SC, bool IsWriteable)
IRHandle irhandle_untyped_pointer(unsigned AddressSpace)
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...
IRHandle irhandle_event()
SPIRVTypeInst lowerBuiltinType(const Type *OpaqueType, SPIRV::AccessQualifier::AccessQualifier AccessQual, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
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)
This is an optimization pass for GlobalISel generic memory operations.
void addStringImm(StringRef Str, MCInst &Inst)
MachineBasicBlock::iterator getOpVariableMBBIt(MachineFunction &MF)
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)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
void addNumImm(const APInt &Imm, MachineInstrBuilder &MIB)
CallInst * buildIntrWithMD(Intrinsic::ID IntrID, ArrayRef< Type * > Types, Value *Arg, Value *Arg2, ArrayRef< Constant * > Imms, IRBuilder<> &B)
bool matchPeeledArrayPattern(const StructType *Ty, Type *&OriginalElementType, uint64_t &TotalSize)
void buildOpDecorate(Register Reg, MachineIRBuilder &MIRBuilder, SPIRV::Decoration::Decoration Dec, ArrayRef< uint32_t > DecArgs, StringRef StrImm)
LLVM_ABI void reportFatalInternalError(Error Err)
Report a fatal error that indicates a bug in LLVM.
constexpr unsigned storageClassToAddressSpace(SPIRV::StorageClass::StorageClass SC)
bool isVectorType(SPIRVTypeInst SPVTy)
bool getSpirvBuiltInIdByName(llvm::StringRef Name, SPIRV::BuiltIn::BuiltIn &BI)
MetadataAsValue * buildMD(Value *Arg)
bool isTypedPointerTy(const Type *T)
void buildOpName(Register Target, StringRef Name, MachineIRBuilder &MIRBuilder)
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
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 sort(IteratorTy Start, IteratorTy End)
Type * toTypedPointer(Type *Ty)
bool isSpecialOpaqueType(const Type *Ty)
bool isPointerTy(const Type *T)
MachineBasicBlock::iterator getInsertPtValidEnd(MachineBasicBlock *MBB)
const Type * unifyPtrType(const Type *Ty)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
std::function< void(Register)> StructOffsetDecorator
SPIRV::StorageClass::StorageClass addressSpaceToStorageClass(unsigned AddrSpace, const SPIRVSubtarget &STI)
void buildOpSpirvDecorations(Register Reg, MachineIRBuilder &MIRBuilder, const MDNode *GVarMD, const SPIRVSubtarget &ST)
int64_t foldImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
bool isLongVectorEXT(const Type *Ty, bool CanUseVector16=true)
Type * parseBasicTypeName(StringRef &TypeName, LLVMContext &Ctx)
DWARFExpression::Operation Op
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
bool hasBuiltinTypePrefix(StringRef Name)
void buildOpMemberDecorate(Register Reg, MachineIRBuilder &MIRBuilder, SPIRV::Decoration::Decoration Dec, uint32_t Member, ArrayRef< uint32_t > DecArgs, StringRef StrImm)
bool isPointerTyOrWrapper(const Type *Ty)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
bool isSpvIntrinsic(const MachineInstr &MI, Intrinsic::ID IntrinsicID)
PoisonValue * getNormalizedPoisonValue(Type *Ty, bool CanUseAnyVectorRank)
MachineInstr * getVRegDef(MachineRegisterInfo &MRI, Register Reg)
MCRegisterClass TargetRegisterClass
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
constexpr 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.