30#include "llvm/IR/IntrinsicsSPIRV.h"
45 if (LI->getType()->isAggregateType())
52 return PType->getAddressSpace();
54 return PType->getAddressSpace();
57 return ExtTy->getIntParameter(0);
64 case SPIRV::StorageClass::Uniform:
65 case SPIRV::StorageClass::PushConstant:
66 case SPIRV::StorageClass::StorageBuffer:
67 case SPIRV::StorageClass::PhysicalStorageBufferEXT:
69 case SPIRV::StorageClass::UniformConstant:
70 case SPIRV::StorageClass::Input:
71 case SPIRV::StorageClass::Output:
72 case SPIRV::StorageClass::Workgroup:
73 case SPIRV::StorageClass::CrossWorkgroup:
74 case SPIRV::StorageClass::Private:
75 case SPIRV::StorageClass::Function:
76 case SPIRV::StorageClass::Generic:
77 case SPIRV::StorageClass::AtomicCounter:
78 case SPIRV::StorageClass::Image:
79 case SPIRV::StorageClass::CallableDataNV:
80 case SPIRV::StorageClass::IncomingCallableDataNV:
81 case SPIRV::StorageClass::RayPayloadNV:
82 case SPIRV::StorageClass::HitAttributeNV:
83 case SPIRV::StorageClass::IncomingRayPayloadNV:
84 case SPIRV::StorageClass::ShaderRecordBufferNV:
85 case SPIRV::StorageClass::CodeSectionINTEL:
86 case SPIRV::StorageClass::DeviceOnlyINTEL:
87 case SPIRV::StorageClass::HostOnlyINTEL:
94 : DL(DL), Bound(0),
CurMF(nullptr) {}
96void SPIRVGlobalRegistry::constrainSelectedInstRegOperands(
100 *ST.getRegBankInfo());
114 SPIRV::AccessQualifier::AccessQualifier AccessQual,
bool EmitIR) {
124 VRegToTypeMap[&MF][VReg] = SpirvType;
129 MRI.setRegClass(Res, &SPIRV::TYPERegClass);
138 return createConstOrTypeAtFunctionEntry(
139 MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
140 return MIRBuilder.
buildInstr(SPIRV::OpTypeBool)
145unsigned SPIRVGlobalRegistry::adjustOpTypeIntWidth(
unsigned Width)
const {
147 if (
ST.canUseExtension(
148 SPIRV::Extension::SPV_ALTERA_arbitrary_precision_integers) ||
149 (Width == 4 &&
ST.canUseExtension(SPIRV::Extension::SPV_INTEL_int4)))
153 else if (Width <= 16)
155 else if (Width <= 32)
157 else if (Width <= 64)
159 else if (Width <= 128)
164SPIRVTypeInst SPIRVGlobalRegistry::getOpTypeInt(
unsigned Width,
167 Width = adjustOpTypeIntWidth(Width);
168 const SPIRVSubtarget &
ST =
170 return createConstOrTypeAtFunctionEntry(MIRBuilder, [&](MachineIRBuilder
172 if (Width == 4 &&
ST.canUseExtension(SPIRV::Extension::SPV_INTEL_int4)) {
174 .
addImm(SPIRV::Extension::SPV_INTEL_int4);
176 .
addImm(SPIRV::Capability::Int4TypeINTEL);
179 SPIRV::Extension::SPV_ALTERA_arbitrary_precision_integers)) {
181 .
addImm(SPIRV::Extension::SPV_ALTERA_arbitrary_precision_integers);
183 .
addImm(SPIRV::Capability::ArbitraryPrecisionIntegersALTERA);
185 return MIRBuilder.
buildInstr(SPIRV::OpTypeInt)
188 .
addImm(IsSigned ? 1 : 0);
193SPIRVGlobalRegistry::getOpTypeFloat(uint32_t Width,
195 return createConstOrTypeAtFunctionEntry(MIRBuilder, [&](MachineIRBuilder
197 return MIRBuilder.
buildInstr(SPIRV::OpTypeFloat)
204SPIRVGlobalRegistry::getOpTypeFloat(uint32_t Width,
206 SPIRV::FPEncoding::FPEncoding FPEncode) {
207 return createConstOrTypeAtFunctionEntry(MIRBuilder, [&](MachineIRBuilder
209 return MIRBuilder.
buildInstr(SPIRV::OpTypeFloat)
217 return createConstOrTypeAtFunctionEntry(
219 return MIRBuilder.
buildInstr(SPIRV::OpTypeVoid)
244 "Cannot invalidate aliasing instructions.");
245 assert(
MI->getOpcode() != SPIRV::OpFunction &&
246 "Cannot invalidate OpFunction.");
248 if (
MI->getOpcode() == SPIRV::OpFunctionCall) {
250 auto It = ForwardCalls.find(
F);
251 if (It != ForwardCalls.end()) {
252 It->second.erase(
MI);
253 if (It->second.empty())
254 ForwardCalls.erase(It);
260 auto It = LastInsertedTypeMap.find(MF);
261 if (It != LastInsertedTypeMap.end() && It->second ==
MI)
262 LastInsertedTypeMap.erase(MF);
273 if (
MI.getNumDefs() &&
TII.isTypeDeclInstr(
MI))
280 static_cast<SPIRV::StorageClass::StorageClass
>(
286 unsigned NumWords =
MI.getNumExplicitOperands() - 2;
288 for (
unsigned I = 0;
I < NumWords; ++
I)
296struct LLVMTypeRestorer {
297 const MachineRegisterInfo &
MRI;
298 const DataLayout &
DL;
300 DenseMap<const MachineInstr *, Type *>
Types;
302 DenseSet<PointerIntPair<Type *, 1, bool>> StructTypes;
305 :
MRI(MF.getRegInfo()),
DL(MF.getDataLayout()),
308 bool hasDecoration(
const MachineInstr &
MI,
309 SPIRV::Decoration::Decoration Dec)
const {
310 for (
const MachineInstr &Use :
312 if ((
Use.getOpcode() == SPIRV::OpDecorate &&
313 Use.getOperand(1).getImm() == Dec) ||
314 (
Use.getOpcode() == SPIRV::OpMemberDecorate &&
315 Use.getOperand(2).getImm() == Dec))
322 bool hasExplicitLayout(
const MachineInstr &
MI)
const {
323 return hasDecoration(
MI, SPIRV::Decoration::Offset) ||
324 hasDecoration(
MI, SPIRV::Decoration::ArrayStride);
327 bool matchesOffsets(
const MachineInstr &
MI, StructType *STy)
const {
330 const StructLayout *SL =
DL.getStructLayout(STy);
331 for (
const MachineInstr &Use :
333 if (
Use.getOpcode() != SPIRV::OpMemberDecorate ||
334 Use.getOperand(2).getImm() != SPIRV::Decoration::Offset)
346 std::optional<bool>
isPacked(
const MachineInstr &
MI,
348 if (hasDecoration(
MI, SPIRV::Decoration::CPacked))
359 StructType *getNamedStruct(
const MachineInstr &
MI,
size_t NumElems)
const {
360 for (
const MachineInstr &Use :
362 if (
Use.getOpcode() != SPIRV::OpName)
366 matchesOffsets(
MI, STy)
373 Type *getOperandType(
const MachineOperand &MO) {
375 return Def ?
get(*Def) : nullptr;
380 Type *Ty = getOperandType(MO);
384 Type *ElemTy = PtrTy->getElementType();
385 unsigned AS = PtrTy->getAddressSpace();
386 return ElemTy->
isIntegerTy(8) ? PointerType::get(Ctx, AS)
390 std::optional<uint64_t> getArrayLength(
const MachineOperand &MO) {
394 APInt
V =
Def->getOpcode() == TargetOpcode::G_CONSTANT
395 ?
Def->getOperand(1).getCImm()->getValue()
398 if (
V.isMaxValue() &&
V.getBitWidth() == 64)
400 if (
V.getActiveBits() > 64)
402 return V.getZExtValue();
405 Type *create(
const MachineInstr &
MI) {
406 switch (
MI.getOpcode()) {
407 case SPIRV::OpTypeVoid:
408 return Type::getVoidTy(Ctx);
409 case SPIRV::OpTypeBool:
410 return Type::getInt1Ty(Ctx);
411 case SPIRV::OpTypeInt: {
413 int64_t Width =
MI.getOperand(1).getImm();
419 case SPIRV::OpTypeFloat: {
420 int64_t Width =
MI.getOperand(1).getImm();
421 if (
MI.getNumOperands() > 2)
422 return Width == 16 &&
MI.getOperand(2).getImm() ==
423 SPIRV::FPEncoding::BFloat16KHR
424 ? Type::getBFloatTy(Ctx)
427 return Type::getHalfTy(Ctx);
429 return Type::getFloatTy(Ctx);
431 return Type::getDoubleTy(Ctx);
434 case SPIRV::OpTypeVector:
435 case SPIRV::OpTypeVectorIdEXT: {
437 std::optional<uint64_t>
N =
MI.getOpcode() == SPIRV::OpTypeVector
438 ?
MI.getOperand(2).getImm()
439 : getArrayLength(
MI.getOperand(2));
440 if (!ElemTy || !VectorType::isValidElementType(ElemTy) || !
N || !*
N ||
441 *
N > std::numeric_limits<unsigned>::max())
445 case SPIRV::OpTypeArray:
446 case SPIRV::OpTypeRuntimeArray: {
448 if (!ElemTy || !ArrayType::isValidElementType(ElemTy))
450 if (
MI.getOpcode() == SPIRV::OpTypeRuntimeArray)
451 return ArrayType::get(ElemTy, 0);
452 std::optional<uint64_t>
N = getArrayLength(
MI.getOperand(2));
453 return N ? ArrayType::get(ElemTy, *
N) : nullptr;
455 case SPIRV::OpTypeStruct: {
457 for (
const MachineInstr *
I = &
MI;
I;
I =
I->getNextNode()) {
458 if (
I != &
MI &&
I->getOpcode() != SPIRV::OpTypeStructContinuedINTEL)
460 for (
const MachineOperand &MO :
I->explicit_uses()) {
471 if (!hasDecoration(
MI, SPIRV::Decoration::Block)) {
472 if (StructType *Named = getNamedStruct(
MI, Elems.
size()))
478 if (!STy || !StructTypes.
insert({STy, hasExplicitLayout(MI)}).second)
482 case SPIRV::OpTypeFunction: {
483 Type *RetTy = getOperandType(
MI.getOperand(1));
484 if (!RetTy || !FunctionType::isValidReturnType(RetTy))
487 for (
const MachineOperand &MO :
drop_begin(
MI.explicit_uses())) {
489 if (!Params.
back() || !FunctionType::isValidArgumentType(Params.
back()))
492 return FunctionType::get(RetTy, Params,
false);
494 case SPIRV::OpTypePointer: {
495 Type *ElemTy = getOperandType(
MI.getOperand(2));
507 if (
auto [It, Inserted] =
Types.try_emplace(&
MI,
nullptr); !Inserted)
519 LLVMTypeRestorer Restorer(MF);
522 if (
MI->getOpcode() == SPIRV::OpTypeStruct &&
523 Restorer.hasDecoration(*
MI, SPIRV::Decoration::Block))
524 BlockDecoratedTypes.insert(
MI);
525 const Type *Ty = Restorer.get(*
MI);
528 SPIRVToLLVMType[
MI] = Ty;
529 addTypeKey(Ty, Restorer.hasExplicitLayout(*
MI),
MI, MF);
536 auto TypesIt = VRegToTypeMap.find(&MF);
537 if (TypesIt == VRegToTypeMap.end())
543 for (
auto [Reg, Ty] : TypesIt->second) {
547 if (TypeReg != Reg && !
MRI.reg_empty(Reg))
555 switch (
MI.getOpcode()) {
556 case SPIRV::OpTypeStructContinuedINTEL:
557 case SPIRV::OpConstantCompositeContinuedINTEL:
558 case SPIRV::OpSpecConstantCompositeContinuedINTEL:
559 case SPIRV::OpCompositeConstructContinuedINTEL:
568 auto It = LastInsertedTypeMap.find(&MF);
569 if (It == LastInsertedTypeMap.end())
574 if (&
MI != It->second)
589 MI =
MI->getNextNode();
590 LastInsertedTypeMap[&MF] =
MI;
593const MachineInstr *SPIRVGlobalRegistry::createConstOrTypeAtFunctionEntry(
597 assert(oldInsertPoint.isValid() &&
"Builder must have insertion point set!");
601 auto LastInsertedType = LastInsertedTypeMap.find(
CurMF);
602 if (LastInsertedType != LastInsertedTypeMap.end()) {
603 auto It = LastInsertedType->second->getIterator();
607 if (It->getParent() != NewMBB)
608 InsertAt = oldInsertPoint->getParent() == NewMBB
611 else if (It->getNextNode())
612 InsertAt = It->getNextNode()->getIterator();
620 MachineInstr *ConstOrType =
Op(MIRBuilder);
632 bool IsLongVectorEXT) {
636 SPIRV::Extension::SPV_INTEL_masked_gather_scatter)) {
640 "Vector of pointers requires SPV_INTEL_masked_gather_scatter "
645 [[maybe_unused]]
auto EleOpc = ElemType->
getOpcode();
646 assert((EleOpc == SPIRV::OpTypeInt || EleOpc == SPIRV::OpTypeFloat ||
647 EleOpc == SPIRV::OpTypeBool) &&
648 "Invalid vector element type");
651 return createConstOrTypeAtFunctionEntry(
652 MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
654 IsLongVectorEXT ? SPIRV::OpTypeVectorIdEXT : SPIRV::OpTypeVector;
658 if (!IsLongVectorEXT)
659 return MIB.
addImm(NumElems);
664 Int32Ty, *
ST.getInstrInfo()));
669SPIRVGlobalRegistry::getOpTypeVector(uint32_t NumElems,
SPIRVTypeInst ElemType,
671 assert(NumElems >= 2 &&
"SPIR-V OpTypeVector requires at least 2 components");
672 return getOpTypeVectorImpl(NumElems, ElemType, MIRBuilder);
677 assert(NumElems != 2 && NumElems != 3 && NumElems != 4 &&
679 (NumElems != 8 && NumElems != 16)) &&
680 "SPIR-V OpTypeVectorIdExt should only be used for extended vectors");
681 return getOpTypeVectorImpl(NumElems, ElemType, MIRBuilder,
true);
689 auto *
const CF = ConstantFP::get(Ctx, Val);
691 if (
MI && (
MI->getOpcode() == SPIRV::OpConstantNull ||
692 MI->getOpcode() == SPIRV::OpConstantF))
693 return MI->getOperand(0).getReg();
705 CurMF->getRegInfo().setRegClass(Res, &SPIRV::fIDRegClass);
711 const MachineInstr *Const = createConstOrTypeAtFunctionEntry(
716 MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantNull)
720 MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantF)
727 constrainSelectedInstRegOperands(MIB);
739 SpvType,
TII, ZeroAsNull);
747 auto *
const CI = ConstantInt::get(
750 if (
MI && (
MI->getOpcode() == SPIRV::OpConstantNull ||
751 MI->getOpcode() == SPIRV::OpConstantI))
752 return MI->getOperand(0).getReg();
763 Register Res =
CurMF->getRegInfo().createGenericVirtualRegister(LLTy);
764 CurMF->getRegInfo().setRegClass(Res, &SPIRV::iIDRegClass);
770 const MachineInstr *Const = createConstOrTypeAtFunctionEntry(
776 : SPIRV::OpConstantTrue)
779 }
else if (!CI->
isZero() || !ZeroAsNull) {
780 MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantI)
785 MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantNull)
789 constrainSelectedInstRegOperands(MIB);
799 bool EmitIR,
bool ZeroAsNull) {
801 auto &MF = MIRBuilder.
getMF();
805 auto *
const CI = ConstantInt::get(
const_cast<IntegerType *
>(Ty), Val,
814 Res =
MRI.createGenericVirtualRegister(LLTy);
815 MRI.setRegClass(Res, &SPIRV::iIDRegClass);
819 const MachineInstr *Const = createConstOrTypeAtFunctionEntry(
825 if (Val || !ZeroAsNull) {
826 MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantI)
831 MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantNull)
835 constrainSelectedInstRegOperands(MIB);
845 auto &MF = MIRBuilder.
getMF();
849 SPIRV::AccessQualifier::ReadWrite,
true);
850 auto *
const CF = ConstantFP::get(Ctx, Val);
855 Res = MF.getRegInfo().createGenericVirtualRegister(
getRegType(SpvType));
856 MF.getRegInfo().setRegClass(Res, &SPIRV::fIDRegClass);
859 const MachineInstr *Const = createConstOrTypeAtFunctionEntry(
862 MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantF)
865 addNumImm(CF->getValueAPF().bitcastToAPInt(), MIB);
872Register SPIRVGlobalRegistry::getOrCreateBaseRegister(
880 if (
Type->getOpcode() == SPIRV::OpTypeFloat) {
885 assert(
Type->getOpcode() == SPIRV::OpTypeInt);
891Register SPIRVGlobalRegistry::getOrCreateCompositeOrNull(
894 unsigned ElemCnt,
bool ZeroAsNull) {
902 getOrCreateBaseRegister(Val,
I, SpvType,
TII,
BitWidth, ZeroAsNull);
905 Register Res =
CurMF->getRegInfo().createGenericVirtualRegister(LLTy);
909 MachineInstr *DepMI =
910 const_cast<MachineInstr *
>(
static_cast<const MachineInstr *
>(SpvType));
912 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
913 MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
914 MachineInstrBuilder MIB;
916 MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantComposite)
919 for (
unsigned i = 0; i < ElemCnt; ++i)
922 MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantNull)
926 constrainSelectedInstRegOperands(MIB);
939 I, SpvType,
TII, ZeroAsNull);
949 "Expected vector type for constant vector creation");
952 [[maybe_unused]]
const auto &ST =
I.getMF()->getSubtarget<
SPIRVSubtarget>();
956 SPIRV::Extension::SPV_INTEL_masked_gather_scatter))) &&
957 "Expected either integer element type for APInt constant vector or "
958 "pointer type if the SPV_INTEL_masked_gather_scatter extension is "
962 ConstVal = ConstantInt::get(LLVMBaseTy, Val);
972 return getOrCreateCompositeOrNull(ConstVal,
I, SpvType,
TII, ConstVec, BW,
987 auto *ConstVal = ConstantFP::get(LLVMBaseTy, Val);
991 return getOrCreateCompositeOrNull(ConstVal,
I, SpvType,
TII, ConstVec, BW,
1003 Constant *CI = ConstantInt::get(LLVMBaseTy, Val);
1018 ConstantInt::get(LLVMBaseTy, Val), ConstantInt::get(I64Ty, Num)});
1019 return getOrCreateCompositeOrNull(CI,
I, SpvType,
TII, UniqueKey, BW,
1023Register SPIRVGlobalRegistry::getOrCreateIntCompositeOrNull(
1030 if (Val || EmitIR) {
1040 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
1046 auto MIB = MIRBuilder.
buildInstr(SPIRV::OpConstantComposite)
1049 for (
unsigned i = 0; i < ElemCnt; ++i)
1054 return MIRBuilder.
buildInstr(SPIRV::OpConstantNull)
1069 const auto ConstInt = ConstantInt::get(LLVMBaseTy, Val);
1073 return getOrCreateIntCompositeOrNull(
1074 Val, MIRBuilder, SpvType, EmitIR, ConstVec, BW,
1092 Res =
CurMF->getRegInfo().createGenericVirtualRegister(LLTy);
1093 CurMF->getRegInfo().setRegClass(Res, &SPIRV::pIDRegClass);
1096 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
1098 return MIRBuilder.
buildInstr(SPIRV::OpConstantNull)
1108 unsigned Param,
unsigned FilerMode,
1121 MIRBuilder.
buildInstr(SPIRV::OpConstantSampler)
1132 const GlobalValue *GV, SPIRV::StorageClass::StorageClass Storage,
1134 const std::optional<SPIRV::LinkageType::LinkageType> &LinkageType,
1143 GVar = M->getGlobalVariable(Name);
1144 if (GVar ==
nullptr) {
1158 if (Reg.isValid()) {
1168 if (&GVBuilder.
getMBB() != &EntryBB)
1173 const bool UseUntypedPointers =
1174 BaseType->getOpcode() == SPIRV::OpTypeUntypedPointerKHR;
1175 const unsigned VariableOpcode =
1176 UseUntypedPointers ? SPIRV::OpUntypedVariableKHR : SPIRV::OpVariable;
1178 auto MIB = GVBuilder.
buildInstr(VariableOpcode)
1185 if (UseUntypedPointers) {
1189 SPIRV::AccessQualifier::ReadWrite,
1195 "Could not deduce the data type of untyped global variable '" +
1201 SPIRV::AccessQualifier::ReadWrite,
1211 if (IsInstSelector) {
1212 constrainSelectedInstRegOperands(MIB);
1221 if (Reg != ResVReg) {
1224 MRI->setType(Reg, RegLLTy);
1243 if (IsConst && !ST.isShader())
1248 buildOpDecorate(Reg, MIRBuilder, SPIRV::Decoration::Alignment, {Alignment});
1252 buildOpDecorate(Reg, MIRBuilder, SPIRV::Decoration::LinkageAttributes,
1253 {
static_cast<uint32_t>(*LinkageType)}, Name);
1255 SPIRV::BuiltIn::BuiltIn BuiltInId;
1258 {
static_cast<uint32_t>(BuiltInId)});
1263 MDNode *GVarMD =
nullptr;
1264 if (GVar && (GVarMD = GVar->
getMetadata(
"spirv.Decorations")) !=
nullptr)
1281 std::nullopt, MIRBuilder,
false);
1283 buildOpDecorate(VarReg, MIRBuilder, SPIRV::Decoration::DescriptorSet, {Set});
1284 buildOpDecorate(VarReg, MIRBuilder, SPIRV::Decoration::Binding, {Binding});
1293 bool ExplicitLayoutRequired,
1296 "Invalid array element type");
1301 if (NumElems != 0) {
1304 ArrayType = createConstOrTypeAtFunctionEntry(
1306 return MIRBuilder.
buildInstr(SPIRV::OpTypeArray)
1309 .
addUse(NumElementsVReg);
1317 ArrayType = createConstOrTypeAtFunctionEntry(
1318 MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
1319 return MIRBuilder.
buildInstr(SPIRV::OpTypeArray)
1322 .
addUse(NumElementsVReg);
1325 if (!
ST.isShader()) {
1327 "Runtime arrays are not allowed in non-shader "
1331 ArrayType = createConstOrTypeAtFunctionEntry(
1332 MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
1333 return MIRBuilder.
buildInstr(SPIRV::OpTypeRuntimeArray)
1341 addArrayStrideDecorations(
ArrayType->defs().begin()->getReg(), ET,
1349SPIRVGlobalRegistry::getOpTypeOpaque(
const StructType *Ty,
1354 return createConstOrTypeAtFunctionEntry(
1355 MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
1365 SPIRV::AccessQualifier::AccessQualifier AccQual,
1367 Type *OriginalElementType =
nullptr;
1370 SPIRVTypeInst ElementSPIRVType = findSPIRVType(
1371 OriginalElementType, MIRBuilder, AccQual,
1372 Decorator !=
nullptr, EmitIR);
1373 return getOpTypeArray(TotalSize, ElementSPIRVType, MIRBuilder,
1374 Decorator !=
nullptr,
1378 const SPIRVSubtarget &
ST =
1381 constexpr unsigned MaxWordCount = UINT16_MAX;
1384 size_t MaxNumElements = MaxWordCount - 2;
1385 size_t SPIRVStructNumElements = NumElements;
1386 if (NumElements > MaxNumElements) {
1388 SPIRVStructNumElements = MaxNumElements;
1389 MaxNumElements = MaxWordCount - 1;
1393 SPIRVTypeInst ElemTy;
1395 if (PadTy && PadTy->getName() ==
"spirv.Padding")
1397 MIRBuilder, PadTy->getIntParameter(0),
1398 DL.getStructLayout(
const_cast<StructType *
>(Ty))
1399 ->getElementOffset(Idx));
1401 ElemTy = findSPIRVType(
toTypedPointer(Elem), MIRBuilder, AccQual,
1402 Decorator !=
nullptr,
1405 "Invalid struct element type");
1414 SPIRVTypeInst SPVType = createConstOrTypeAtFunctionEntry(
1415 MIRBuilder, [&](MachineIRBuilder &MIRBuilder) {
1418 for (
size_t I = 0;
I < SPIRVStructNumElements; ++
I)
1419 MIBStruct.
addUse(FieldTypes[
I]);
1420 for (
size_t I = SPIRVStructNumElements;
I < NumElements;
1421 I += MaxNumElements) {
1423 MIRBuilder.
buildInstr(SPIRV::OpTypeStructContinuedINTEL);
1424 for (
size_t J =
I; J < std::min(
I + MaxNumElements, NumElements); ++J)
1425 MIBCont.
addUse(FieldTypes[J]);
1431 Decorator(SPVType->defs().begin()->getReg());
1438 SPIRV::AccessQualifier::AccessQualifier AccQual) {
1444 SPIRV::StorageClass::StorageClass SC,
SPIRVTypeInst ElemType,
1447 const SPIRVSubtarget &
ST =
1455 return createConstOrTypeAtFunctionEntry(MIRBuilder, [&](MachineIRBuilder
1457 return MIRBuilder.
buildInstr(SPIRV::OpTypePointer)
1459 .
addImm(
static_cast<uint32_t
>(SC))
1468 const SPIRVSubtarget *
ST =
1469 static_cast<const SPIRVSubtarget *
>(&MIRBuilder.
getMF().getSubtarget());
1470 if (Ty->isVarArg() &&
ST->isShader()) {
1472 Ty->getContext().diagnose(DiagnosticInfoUnsupported(
1473 Fn,
"SPIR-V shaders do not support variadic functions",
1476 return createConstOrTypeAtFunctionEntry(MIRBuilder, [&](MachineIRBuilder
1478 auto MIB = MIRBuilder.
buildInstr(SPIRV::OpTypeFunction)
1481 for (
auto &ArgType : ArgTypes)
1495 add(Ty,
false, NewMI);
1496 return finishCreatingSPIRVType(Ty, NewMI);
1501 SPIRV::AccessQualifier::AccessQualifier AccQual,
1502 bool ExplicitLayoutRequired,
bool EmitIR) {
1506 FVT && FVT->getNumElements() == 1 &&
1507 !STI.canUseExtension(SPIRV::Extension::SPV_EXT_long_vector))
1508 return findSPIRVType(FVT->getElementType(), MIRBuilder, AccQual,
1509 ExplicitLayoutRequired, EmitIR);
1510 Ty = adjustIntTypeByWidth(Ty);
1513 findMI(Ty, ExplicitLayoutRequired, &MIRBuilder.
getMF()))
1515 if (
auto It = ForwardPointerTypes.find(Ty); It != ForwardPointerTypes.end())
1517 return restOfCreateSPIRVType(Ty, MIRBuilder, AccQual, ExplicitLayoutRequired,
1522 assert(SpirvType &&
"Attempting to get type id for nullptr type.");
1523 if (SpirvType->
getOpcode() == SPIRV::OpTypeForwardPointer ||
1524 SpirvType->
getOpcode() == SPIRV::OpTypeStructContinuedINTEL)
1525 return SpirvType->
uses().
begin()->getReg();
1526 return SpirvType->
defs().
begin()->getReg();
1537const Type *SPIRVGlobalRegistry::adjustIntTypeByWidth(
const Type *Ty)
const {
1539 unsigned SrcBitWidth = IType->getBitWidth();
1540 if (SrcBitWidth > 1) {
1541 unsigned BitWidth = adjustOpTypeIntWidth(SrcBitWidth);
1552 SPIRV::AccessQualifier::AccessQualifier AccQual,
1553 bool ExplicitLayoutRequired,
bool EmitIR) {
1555 return getOrCreateSpecialType(Ty, MIRBuilder, AccQual);
1557 if (
const MachineInstr *
MI =
1558 findMI(Ty, ExplicitLayoutRequired, &MIRBuilder.
getMF()))
1562 const unsigned Width = IType->getBitWidth();
1563 return Width == 1 ? getOpTypeBool(MIRBuilder)
1564 : getOpTypeInt(Width, MIRBuilder,
false);
1571 SPIRV::FPEncoding::BFloat16KHR);
1581 AccQual, ExplicitLayoutRequired, EmitIR);
1585 STI.canUseExtension(SPIRV::Extension::SPV_EXT_long_vector))
1586 return getOpTypeVectorIdEXT(NumElts, El, MIRBuilder);
1587 return getOpTypeVector(NumElts, El, MIRBuilder);
1591 AccQual, ExplicitLayoutRequired, EmitIR);
1593 ExplicitLayoutRequired, EmitIR);
1596 if (SType->isOpaque())
1597 return getOpTypeOpaque(SType, MIRBuilder);
1600 if (ExplicitLayoutRequired) {
1601 Decorator = [&MIRBuilder, SType,
this](
Register Reg) {
1602 addStructOffsetDecorations(
Reg,
const_cast<StructType *
>(SType),
1606 return getOpTypeStruct(SType, MIRBuilder, AccQual, std::move(Decorator),
1610 SPIRVTypeInst RetTy =
1611 findSPIRVType(FType->getReturnType(), MIRBuilder, AccQual,
1612 ExplicitLayoutRequired, EmitIR);
1614 for (
const auto &ParamTy : FType->params())
1615 ParamTypes.
push_back(findSPIRVType(ParamTy, MIRBuilder, AccQual,
1616 ExplicitLayoutRequired, EmitIR));
1617 return getOpTypeFunction(FType, RetTy, ParamTypes, MIRBuilder);
1623 const SPIRVSubtarget *
ST =
1624 static_cast<const SPIRVSubtarget *
>(&MIRBuilder.
getMF().getSubtarget());
1627 SPIRVTypeInst SpvElementType =
nullptr;
1630 !
ST->canUseExtension(SPIRV::Extension::SPV_INTEL_function_pointers))
1643 if (
auto It = ForwardPointerTypes.find(Ty); It != ForwardPointerTypes.end()) {
1646 return getOpTypePointer(SC, SpvElementType, MIRBuilder,
Reg);
1654 SPIRV::AccessQualifier::AccessQualifier AccessQual,
1655 bool ExplicitLayoutRequired,
bool EmitIR) {
1660 TypesInProcessing.insert(Ty);
1661 SPIRVTypeInst SpirvType = createSPIRVType(Ty, MIRBuilder, AccessQual,
1662 ExplicitLayoutRequired, EmitIR);
1663 TypesInProcessing.erase(Ty);
1671 if (!(PadTy && PadTy->getName() ==
"spirv.Padding"))
1674 if (SpirvType->
getOpcode() != SPIRV::OpTypeForwardPointer &&
1675 SpirvType->
getOpcode() != SPIRV::OpTypeUntypedPointerKHR &&
1677 addTypeKey(Ty, ExplicitLayoutRequired, SpirvType, MIRBuilder.
getMF());
1681void SPIRVGlobalRegistry::addTypeKey(
const Type *Ty,
1682 bool ExplicitLayoutRequired,
1685 if (
findMI(Ty,
false, &MF))
1689 add(ExtTy->getTypeParameter(0), ExtTy->getIntParameter(0), SpirvType);
1691 add(Ty, ExplicitLayoutRequired, SpirvType);
1703 auto t = VRegToTypeMap.find(MF ? MF :
CurMF);
1704 if (t != VRegToTypeMap.end()) {
1705 auto tt = t->second.find(VReg);
1706 if (tt != t->second.end())
1722 SPIRV::AccessQualifier::AccessQualifier AccessQual,
1723 bool ExplicitLayoutRequired,
bool EmitIR) {
1728 FVT && FVT->getNumElements() == 1 &&
1729 !STI.canUseExtension(SPIRV::Extension::SPV_EXT_long_vector))
1731 ExplicitLayoutRequired, EmitIR);
1736 Reg =
find(ExtTy->getTypeParameter(0), ExtTy->getIntParameter(0), MF);
1738 Reg =
find(Ty = adjustIntTypeByWidth(Ty), ExplicitLayoutRequired, MF);
1748 TypesInProcessing.clear();
1749 SPIRVTypeInst STy = restOfCreateSPIRVType(Ty, MIRBuilder, AccessQual,
1750 ExplicitLayoutRequired, EmitIR);
1752 for (
auto &
CU : ForwardPointerTypes) {
1755 bool PtrNeedsLayout =
false;
1756 const Type *Ty2 =
CU.first;
1758 if ((Reg =
find(Ty2, PtrNeedsLayout, MF)).
isValid())
1761 STy2 = restOfCreateSPIRVType(Ty2, MIRBuilder, AccessQual, PtrNeedsLayout,
1766 ForwardPointerTypes.clear();
1771 unsigned TypeOpcode)
const {
1773 assert(
Type &&
"isScalarOfType VReg has no type assigned");
1774 return Type->getOpcode() == TypeOpcode;
1778 unsigned TypeOpcode)
const {
1780 assert(
Type &&
"isScalarOrVectorOfType VReg has no type assigned");
1781 if (
Type->getOpcode() == TypeOpcode)
1785 Register ScalarTypeVReg =
Type->getOperand(1).getReg();
1787 return ScalarType->
getOpcode() == TypeOpcode;
1791 switch (
Type->getOpcode()) {
1792 case SPIRV::OpTypeImage:
1793 case SPIRV::OpTypeSampler:
1794 case SPIRV::OpTypeSampledImage:
1796 case SPIRV::OpTypeStruct:
1797 return BlockDecoratedTypes.contains(
Type);
1813 return (
Type->getOpcode() == SPIRV::OpTypeVector)
1814 ?
static_cast<unsigned>(
Type->getOperand(2).
getImm())
1824 :
Type->getOperand(0).getReg();
1835 if (ScalarType->
getOpcode() == SPIRV::OpTypeInt ||
1836 ScalarType->
getOpcode() == SPIRV::OpTypeFloat)
1838 if (ScalarType->
getOpcode() == SPIRV::OpTypeBool)
1840 if (ScalarType->
getOpcode() == SPIRV::OpTypePointer)
1843 "Attempting to get bit width of non-integer/float/pointer type.");
1851 return ScalarType->
getOpcode() == SPIRV::OpTypeInt ||
1852 ScalarType->
getOpcode() == SPIRV::OpTypeFloat
1860 if (ElemType && ElemType->
getOpcode() == SPIRV::OpTypeFunction)
1862 auto It = SPIRVToLLVMType.find(ElemType);
1863 return It != SPIRVToLLVMType.end() && It->second &&
1870 return ST.canUseExtension(SPIRV::Extension::SPV_KHR_untyped_pointers) &&
1877 return ScalarType && ScalarType->
getOpcode() == SPIRV::OpTypeInt ? ScalarType
1887 return PtrType && PtrType->
getOpcode() == SPIRV::OpTypePointer
1894 if (!Type1 || !Type2)
1907 return Bits1 > 0 && Bits1 == Bits2;
1910SPIRV::StorageClass::StorageClass
1914 "Pointer type is expected");
1918SPIRV::StorageClass::StorageClass
1920 return static_cast<SPIRV::StorageClass::StorageClass
>(
1926 SPIRV::StorageClass::StorageClass SC,
bool IsWritable,
bool EmitIr) {
1937 ExplicitLayoutRequired, EmitIr);
1940 SPIRV::Decoration::Block, {});
1941 BlockDecoratedTypes.insert(BlockType);
1945 SPIRV::Decoration::NonWritable, 0, {});
1949 getOrCreateSPIRVPointerTypeInternal(BlockType, MIRBuilder, SC);
1956 uint64_t PaddingSizeInBytes,
1957 uint64_t OffsetInBytes) {
1963 assert(PaddingSizeInBytes != 0 &&
"spirv.Padding must not be empty");
1964 uint64_t WidthInBytes =
1965 std::min<uint64_t>(4,
MinAlign(OffsetInBytes, PaddingSizeInBytes));
1966 unsigned Width = WidthInBytes * 8;
1972 finishCreatingSPIRVType(
T, R);
1979 const auto SC = SPIRV::StorageClass::PushConstant;
1988 T, MIRBuilder, SPIRV::AccessQualifier::None,
1992 SPIRV::Decoration::Block, {});
1993 BlockDecoratedTypes.insert(BlockType);
2007 assert(ST->getNumElements() == Offsets.size());
2020 getOpTypeStruct(ST, MIRBuilder, SPIRV::AccessQualifier::None,
2021 std::move(Decorator), EmitIr);
2022 add(
Key, SPIRVStructType);
2023 return SPIRVStructType;
2028 const SPIRV::AccessQualifier::AccessQualifier Qualifier,
2031 "SPIR-V image builtin type must have sampled type parameter!");
2034 SPIRV::AccessQualifier::ReadWrite,
true);
2037 "Invalid number of parameters for SPIR-V image builtin!");
2039 SPIRV::AccessQualifier::AccessQualifier accessQualifier =
2040 SPIRV::AccessQualifier::None;
2042 accessQualifier = Qualifier == SPIRV::AccessQualifier::WriteOnly
2043 ? SPIRV::AccessQualifier::WriteOnly
2044 : SPIRV::AccessQualifier::AccessQualifier(
2050 MIRBuilder, SampledType,
2056 SPIRVToLLVMType[R] = ExtensionType;
2064 SPIRV::ImageFormat::ImageFormat ImageFormat,
2065 SPIRV::AccessQualifier::AccessQualifier AccessQual) {
2067 Depth, Arrayed, Multisampled, Sampled,
2068 ImageFormat, AccessQual);
2075 if (ST.getTargetTriple().isVulkanOS()) {
2076 unsigned Opcode = SampledType->
getOpcode();
2077 uint64_t Width = Opcode == SPIRV::OpTypeInt || Opcode == SPIRV::OpTypeFloat
2080 if (Width != 32 && !(Width == 64 && Opcode == SPIRV::OpTypeInt))
2082 "OpTypeImage Sampled Type must be a scalar 32-bit float, 32-bit "
2083 "integer or 64-bit integer for Vulkan "
2084 "(VUID-StandaloneSpirv-OpTypeImage-04656)");
2087 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
2099 if (AccessQual != SPIRV::AccessQualifier::None)
2113 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
2115 return MIRBuilder.
buildInstr(SPIRV::OpTypeSampler)
2124 SPIRV::AccessQualifier::AccessQualifier AccessQual) {
2128 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
2130 return MIRBuilder.
buildInstr(SPIRV::OpTypePipe)
2143 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
2145 return MIRBuilder.
buildInstr(SPIRV::OpTypeDeviceEvent)
2160 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
2162 return MIRBuilder.
buildInstr(SPIRV::OpTypeSampledImage)
2175 findMI(ExtensionType,
false, &MIRBuilder.
getMF()))
2177 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
2184 .canUseExtension(SPIRV::Extension::SPV_INTEL_int4)) {
2186 .
addImm(SPIRV::Capability::Int4CooperativeMatrixINTEL);
2188 return MIRBuilder.
buildInstr(SPIRV::OpTypeCooperativeMatrixKHR)
2196 add(ExtensionType,
false, NewMI);
2204 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
2208 add(Ty,
false, NewMI);
2218 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
2224 assert((Operand.isReg() || Operand.isImm()) &&
2225 "Expected register or immediate operand");
2230 add(Ty,
false, NewMI);
2237 SPIRV::StorageClass::StorageClass SC,
2238 SPIRV::AccessQualifier::AccessQualifier AQ) {
2239 unsigned VecElts = 0;
2246 MIRBuilder, AQ,
false,
true);
2267 TypeStr = TypeStr.
substr(0, TypeStr.
find(
']'));
2284 MIRBuilder, SPIRV::AccessQualifier::ReadWrite,
false,
true);
2288SPIRVGlobalRegistry::finishCreatingSPIRVType(
const Type *LLVMTy,
2299 unsigned SPIRVOPcode,
Type *Ty) {
2304 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
2307 MIRBuilder.
getDL(),
TII.get(SPIRVOPcode))
2311 if (!Ty->isFloatTy()) {
2312 return NewTypeMI.addImm(0);
2317 add(Ty,
false, NewMI);
2318 return finishCreatingSPIRVType(Ty, NewMI);
2358 MIRBuilder, SPIRV::AccessQualifier::ReadWrite,
false, EmitIR);
2369 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
2372 MIRBuilder.
getDL(),
TII.get(SPIRV::OpTypeBool))
2375 add(Ty,
false, NewMI);
2376 return finishCreatingSPIRVType(Ty, NewMI);
2385 MIRBuilder, SPIRV::AccessQualifier::ReadWrite,
false, EmitIR);
2392 if (!STI.canUseExtension(SPIRV::Extension::SPV_EXT_long_vector))
2395 assert(NumElements >= 2 &&
2396 "SPIR-V vectors must have at least 2 components");
2404 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
2412 add(Ty,
false, NewMI);
2413 return finishCreatingSPIRVType(Ty, NewMI);
2425 SPIRV::StorageClass::StorageClass SC,
bool ForceTyped,
bool EmitIR) {
2428 .canUseExtension(SPIRV::Extension::SPV_INTEL_function_pointers)) {
2430 F.getContext().diagnose(
2432 "Function used as a data pointer requires "
2433 "SPV_INTEL_function_pointers extension",
2437 BaseType, MIRBuilder, SPIRV::AccessQualifier::ReadWrite,
2440 return getOrCreateSPIRVPointerTypeInternal(SpirvBaseType, MIRBuilder, SC,
2445 SPIRVTypeInst PtrType, SPIRV::StorageClass::StorageClass SC,
2447 [[maybe_unused]] SPIRV::StorageClass::StorageClass OldSC =
2454 return getOrCreateSPIRVPointerTypeInternal(PointeeType, MIRBuilder, SC);
2459 SPIRV::StorageClass::StorageClass SC,
bool EmitIR) {
2465 (R->getOpcode() == SPIRV::OpTypeUntypedPointerKHR ||
2467 "The base type was not correctly laid out for the given storage class.");
2471SPIRVTypeInst SPIRVGlobalRegistry::getOrCreateSPIRVPointerTypeInternal(
2473 SPIRV::StorageClass::StorageClass SC,
bool ForceTyped) {
2486 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
2490 MIRBuilder.
getTII().
get(SPIRV::OpTypePointer))
2496 return finishCreatingSPIRVType(Ty, NewMI);
2503 assert(ST.canUseExtension(SPIRV::Extension::SPV_KHR_untyped_pointers) &&
2504 !ST.isShader() &&
"Untyped pointers are not available");
2513 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
2517 MIRBuilder.
getTII().
get(SPIRV::OpTypeUntypedPointerKHR))
2522 return finishCreatingSPIRVType(Ty, NewMI);
2535 Res =
CurMF->getRegInfo().createGenericVirtualRegister(LLTy);
2536 CurMF->getRegInfo().setRegClass(Res, &SPIRV::iIDRegClass);
2542 const MachineInstr *NewMI = createConstOrTypeAtFunctionEntry(
2545 MIRBuilder.
getDL(),
TII.get(SPIRV::OpUndef))
2548 constrainSelectedInstRegOperands(MIB);
2559 case SPIRV::OpTypeFloat:
2560 return &SPIRV::fIDRegClass;
2561 case SPIRV::OpTypePointer:
2562 case SPIRV::OpTypeUntypedPointerKHR:
2563 return &SPIRV::pIDRegClass;
2564 case SPIRV::OpTypeVector:
2565 case SPIRV::OpTypeVectorIdEXT: {
2567 unsigned ElemOpcode = ElemType ? ElemType->
getOpcode() : 0;
2568 if (ElemOpcode == SPIRV::OpTypeFloat)
2569 return &SPIRV::vfIDRegClass;
2571 return &SPIRV::vpIDRegClass;
2572 return &SPIRV::viIDRegClass;
2575 return &SPIRV::iIDRegClass;
2586 unsigned Opcode = SpvType ? SpvType->
getOpcode() : 0;
2588 case SPIRV::OpTypeFloat:
2590 case SPIRV::OpTypeInt:
2591 case SPIRV::OpTypeBool:
2593 case SPIRV::OpTypePointer:
2594 case SPIRV::OpTypeUntypedPointerKHR:
2596 case SPIRV::OpTypeVector:
2597 case SPIRV::OpTypeVectorIdEXT: {
2600 switch (ElemType ? ElemType->
getOpcode() : 0) {
2601 case SPIRV::OpTypePointer:
2602 case SPIRV::OpTypeUntypedPointerKHR:
2605 case SPIRV::OpTypeFloat:
2608 case SPIRV::OpTypeInt:
2609 case SPIRV::OpTypeBool:
2633 if (
auto L = AliasInstMDMap.find({MF, AliasingListMD});
2634 L != AliasInstMDMap.end())
2641 if (ScopeMD->getNumOperands() < 2)
2647 auto D = AliasInstMDMap.find({MF, DomainMD});
2648 if (
D != AliasInstMDMap.end())
2650 const Register Ret =
MRI->createVirtualRegister(&SPIRV::IDRegClass);
2655 AliasInstMDMap.insert(
2656 std::make_pair(std::make_pair(MF, DomainMD),
Domain));
2658 auto S = AliasInstMDMap.find({MF, ScopeMD});
2659 if (S != AliasInstMDMap.end())
2661 const Register Ret =
MRI->createVirtualRegister(&SPIRV::IDRegClass);
2662 auto MIB = MIRBuilder.
buildInstr(SPIRV::OpAliasScopeDeclINTEL)
2667 AliasInstMDMap.insert(std::make_pair(std::make_pair(MF, ScopeMD), Scope));
2672 const Register Ret =
MRI->createVirtualRegister(&SPIRV::IDRegClass);
2675 for (
auto *Scope : ScopeList)
2676 MIB.
addUse(Scope->getOperand(0).getReg());
2679 std::make_pair(std::make_pair(MF, AliasingListMD),
List));
2685 const MDNode *AliasingListMD) {
2703 bool CanUseAnyVectorRank) {
2712 B.CreateIntrinsic(Intrinsic::spv_value_md,
2714 AssignCI =
B.CreateIntrinsicWithoutFolding(Intrinsic::fake_use, {Arg});
2717 OfType, Arg, {},
B);
2727 B.GetInsertBlock() ?
B.GetInsertBlock()->getParent() :
nullptr;
2728 if (AssignPtrTyCI ==
nullptr ||
2729 AssignPtrTyCI->
getParent()->getParent() != CurrF) {
2731 Intrinsic::spv_assign_ptr_type, {Arg->
getType()}, OfType, Arg,
2745 Intrinsic::spv_assign_ptr_type)
2754void SPIRVGlobalRegistry::addStructOffsetDecorations(
2757 for (
uint32_t I = 0;
I < Ty->getNumElements(); ++
I) {
2763void SPIRVGlobalRegistry::addArrayStrideDecorations(
2765 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...
static dxbc::SigComponentType getComponentType(ElementType Type, bool Legacy)
const HexagonInstrInfo * TII
static constexpr Value * getValue(Ty &ValueOrUse)
Promote Memory to Register
This file defines the PointerIntPair class.
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 isContinuedInstr(const MachineInstr &MI)
static bool allowEmitFakeUse(const Value *Arg)
static APInt decodeNumImm(const MachineInstr &MI)
static unsigned typeToAddressSpace(const Type *Ty)
static LLT getFloatRegType(SPIRVTypeInst FloatType)
unsigned getAS(SPIRVTypeInst SpvType)
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
static Function * getFunction(FunctionType *Ty, const Twine &Name, Module *M)
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.
LLVM_ABI void insertBits(const APInt &SubBits, unsigned bitPosition)
Insert the bits from a smaller APInt starting at bitPosition.
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
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.
@ MIN_INT_BITS
Minimum number of bits that can be specified.
@ MAX_INT_BITS
Maximum number of bits that can be specified.
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
unsigned getNumDefs() const
Returns the total number of definitions.
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...
iterator_range< use_instr_nodbg_iterator > use_nodbg_instructions(Register Reg) const
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)
void buildAssignPtr(IRBuilder<> &B, Type *ElemTy, Value *Arg)
const TargetRegisterClass * getRegClass(SPIRVTypeInst SpvType) const
SPIRVTypeInst getOrCreateSPIRVPointerType(const Type *BaseType, MachineIRBuilder &MIRBuilder, SPIRV::StorageClass::StorageClass SC, bool ForceTyped=false, bool EmitIR=true)
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
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)
Register getLastInsertedTypeReg(const MachineFunction &MF) const
SPIRVTypeInst getOpTypeVoid(MachineIRBuilder &MIRBuilder)
void invalidateMachineInstr(MachineInstr *MI)
bool isResourceType(SPIRVTypeInst Type) const
SPIRVTypeInst getOrCreateSPIRVBoolType(MachineIRBuilder &MIRBuilder, bool EmitIR)
void setLastInsertedType(const MachineFunction &MF, MachineInstr *MI)
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)
SPIRVTypeInst getOrCreatePaddingType(MachineIRBuilder &MIRBuilder, uint64_t PaddingSizeInBytes, uint64_t OffsetInBytes=0)
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.
TypeSize getElementOffset(unsigned Idx) const
Class to represent struct types.
static LLVM_ABI StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
ArrayRef< Type * > elements() const
static LLVM_ABI StructType * getTypeByName(LLVMContext &C, StringRef Name)
Return the type with the specified name, or null if there is none by that name.
static LLVM_ABI StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
static LLVM_ABI bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
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 bool isSized() const
isSized - Return true if this is a sized type.
bool isOpaque() const
Return true if this is a type with an identity that has no body specified yet.
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 IntegerType * getIntNTy(LLVMContext &C, unsigned N)
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 bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
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
std::pair< iterator, bool > insert(const ValueT &V)
const ParentTy * getParent() const
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr bool isPacked(const T &...O)
IRHandle handle(const Type *Ty)
IRHandle irhandle_padding(unsigned Width)
IRHandle irhandle_sampled_image(const Type *SampledTy, const MachineInstr *ImageTy)
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)
NodeAddr< DefNode * > Def
NodeAddr< UseNode * > Use
unsigned getNumElements(Type *Ty)
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
std::string getStringImm(const MachineInstr &MI, unsigned StartIndex)
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.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
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)
constexpr T MinAlign(U A, V B)
A and B are either alignments or offsets.
MetadataAsValue * buildMD(Value *Arg)
bool isTypedPointerTy(const Type *T)
auto dyn_cast_or_null(const Y &Val)
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.
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
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
ArrayRef(const T &OneElt) -> ArrayRef< T >
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)
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.