20#include "llvm/IR/IntrinsicsSPIRV.h"
24#define DEBUG_TYPE "spirv-builtins"
28#define GET_BuiltinGroup_DECL
29#include "SPIRVGenTables.inc"
33 InstructionSet::InstructionSet
Set;
39#define GET_DemangledBuiltins_DECL
40#define GET_DemangledBuiltins_IMPL
62 InstructionSet::InstructionSet
Set;
66#define GET_NativeBuiltins_DECL
67#define GET_NativeBuiltins_IMPL
85#define GET_GroupBuiltins_DECL
86#define GET_GroupBuiltins_IMPL
95#define GET_IntelSubgroupsBuiltins_DECL
96#define GET_IntelSubgroupsBuiltins_IMPL
103#define GET_AtomicFloatingBuiltins_DECL
104#define GET_AtomicFloatingBuiltins_IMPL
111#define GET_GroupUniformBuiltins_DECL
112#define GET_GroupUniformBuiltins_IMPL
116 InstructionSet::InstructionSet
Set;
120using namespace BuiltIn;
121#define GET_GetBuiltins_DECL
122#define GET_GetBuiltins_IMPL
126 InstructionSet::InstructionSet
Set;
130#define GET_ImageQueryBuiltins_DECL
131#define GET_ImageQueryBuiltins_IMPL
135 InstructionSet::InstructionSet
Set;
145 InstructionSet::InstructionSet
Set;
152using namespace FPRoundingMode;
153#define GET_ConvertBuiltins_DECL
154#define GET_ConvertBuiltins_IMPL
156using namespace InstructionSet;
157#define GET_VectorLoadStoreBuiltins_DECL
158#define GET_VectorLoadStoreBuiltins_IMPL
160#define GET_CLMemoryScope_DECL
161#define GET_CLSamplerAddressingMode_DECL
162#define GET_CLMemoryFenceFlags_DECL
163#define GET_ExtendedBuiltins_DECL
164#include "SPIRVGenTables.inc"
175 const static std::string PassPrefix =
"(anonymous namespace)::";
176 std::string BuiltinName;
179 BuiltinName = DemangledCall.
substr(PassPrefix.length());
181 BuiltinName = DemangledCall;
184 BuiltinName = BuiltinName.
substr(0, BuiltinName.find(
'('));
187 if (BuiltinName.rfind(
"__spirv_ocl_", 0) == 0)
188 BuiltinName = BuiltinName.
substr(12);
193 if (BuiltinName.find(
'<') && BuiltinName.back() ==
'>') {
194 BuiltinName = BuiltinName.
substr(0, BuiltinName.find(
'<'));
195 BuiltinName = BuiltinName.
substr(BuiltinName.find_last_of(
' ') + 1);
203 BuiltinName = BuiltinName.
substr(0, BuiltinName.find(
"_R"));
220static std::unique_ptr<const SPIRV::IncomingCall>
222 SPIRV::InstructionSet::InstructionSet Set,
229 DemangledCall.
slice(DemangledCall.
find(
'(') + 1, DemangledCall.
find(
')'));
230 BuiltinArgs.
split(BuiltinArgumentTypes,
',', -1,
false);
235 if ((Builtin = SPIRV::lookupBuiltin(BuiltinName, Set)))
236 return std::make_unique<SPIRV::IncomingCall>(
237 BuiltinName, Builtin, ReturnRegister, ReturnType,
Arguments);
242 if (BuiltinArgumentTypes.
size() >= 1) {
243 char FirstArgumentType = BuiltinArgumentTypes[0][0];
248 switch (FirstArgumentType) {
251 if (Set == SPIRV::InstructionSet::OpenCL_std)
253 else if (Set == SPIRV::InstructionSet::GLSL_std_450)
261 if (Set == SPIRV::InstructionSet::OpenCL_std)
263 else if (Set == SPIRV::InstructionSet::GLSL_std_450)
270 if (Set == SPIRV::InstructionSet::OpenCL_std ||
271 Set == SPIRV::InstructionSet::GLSL_std_450)
277 if (!Prefix.empty() &&
278 (Builtin = SPIRV::lookupBuiltin(Prefix + BuiltinName, Set)))
279 return std::make_unique<SPIRV::IncomingCall>(
280 BuiltinName, Builtin, ReturnRegister, ReturnType,
Arguments);
287 switch (FirstArgumentType) {
308 if (!Suffix.empty() &&
309 (Builtin = SPIRV::lookupBuiltin(BuiltinName + Suffix, Set)))
310 return std::make_unique<SPIRV::IncomingCall>(
311 BuiltinName, Builtin, ReturnRegister, ReturnType,
Arguments);
326 assert(
MI->getOpcode() == TargetOpcode::G_ADDRSPACE_CAST &&
327 MI->getOperand(1).isReg());
328 Register BitcastReg =
MI->getOperand(1).getReg();
359 Register ValueReg =
MI->getOperand(0).getReg();
365 assert(Ty &&
"Type is expected");
377 if (
MI->getOpcode() == TargetOpcode::G_GLOBAL_VALUE)
378 return MI->getOperand(1).getGlobal()->getType();
380 "Blocks in OpenCL C must be traceable to allocation site");
392static std::tuple<Register, SPIRVType *>
398 if (ResultType->
getOpcode() == SPIRV::OpTypeVector) {
413 return std::make_tuple(ResultRegister, BoolType);
424 if (ReturnType->getOpcode() == SPIRV::OpTypeVector) {
433 return MIRBuilder.
buildSelect(ReturnRegister, SourceRegister, TrueConst,
444 if (!DestinationReg.isValid()) {
445 DestinationReg =
MRI->createVirtualRegister(&SPIRV::iIDRegClass);
452 MIRBuilder.
buildLoad(DestinationReg, PtrRegister, PtrInfo,
Align());
453 return DestinationReg;
467 VariableType, MIRBuilder, SPIRV::StorageClass::Input);
473 SPIRV::StorageClass::Input,
nullptr, isConst,
474 hasLinkageTy, SPIRV::LinkageType::Import, MIRBuilder,
481 return LoadedRegister;
490 SPIRVGlobalRegistry *GR,
491 MachineIRBuilder &MIB,
492 MachineRegisterInfo &
MRI);
495static SPIRV::MemorySemantics::MemorySemantics
498 case std::memory_order::memory_order_relaxed:
499 return SPIRV::MemorySemantics::None;
500 case std::memory_order::memory_order_acquire:
501 return SPIRV::MemorySemantics::Acquire;
502 case std::memory_order::memory_order_release:
503 return SPIRV::MemorySemantics::Release;
504 case std::memory_order::memory_order_acq_rel:
505 return SPIRV::MemorySemantics::AcquireRelease;
506 case std::memory_order::memory_order_seq_cst:
507 return SPIRV::MemorySemantics::SequentiallyConsistent;
515 case SPIRV::CLMemoryScope::memory_scope_work_item:
516 return SPIRV::Scope::Invocation;
517 case SPIRV::CLMemoryScope::memory_scope_work_group:
518 return SPIRV::Scope::Workgroup;
519 case SPIRV::CLMemoryScope::memory_scope_device:
520 return SPIRV::Scope::Device;
521 case SPIRV::CLMemoryScope::memory_scope_all_svm_devices:
522 return SPIRV::Scope::CrossDevice;
523 case SPIRV::CLMemoryScope::memory_scope_sub_group:
524 return SPIRV::Scope::Subgroup;
537 SPIRV::Scope::Scope Scope,
541 if (CLScopeRegister.
isValid()) {
546 if (CLScope ==
static_cast<unsigned>(Scope)) {
547 MRI->setRegClass(CLScopeRegister, &SPIRV::iIDRegClass);
548 return CLScopeRegister;
555 Register PtrRegister,
unsigned &Semantics,
558 if (SemanticsRegister.
isValid()) {
560 std::memory_order Order =
566 if (Order == Semantics) {
567 MRI->setRegClass(SemanticsRegister, &SPIRV::iIDRegClass);
568 return SemanticsRegister;
578 MachineRegisterInfo *
MRI = MIRBuilder.
getMRI();
582 unsigned Sz = Call->Arguments.size() - ImmArgs.size();
583 for (
unsigned i = 0; i < Sz; ++i) {
584 Register ArgReg = Call->Arguments[i];
585 if (!
MRI->getRegClassOrNull(ArgReg))
586 MRI->setRegClass(ArgReg, &SPIRV::iIDRegClass);
597 if (Call->isSpirvOp())
600 assert(Call->Arguments.size() == 2 &&
601 "Need 2 arguments for atomic init translation");
605 .
addUse(Call->Arguments[0])
606 .
addUse(Call->Arguments[1]);
615 if (Call->isSpirvOp())
618 Register PtrRegister = Call->Arguments[0];
624 if (Call->Arguments.size() > 1) {
625 ScopeRegister = Call->Arguments[1];
631 if (Call->Arguments.size() > 2) {
633 MemSemanticsReg = Call->Arguments[2];
637 SPIRV::MemorySemantics::SequentiallyConsistent |
643 .
addDef(Call->ReturnRegister)
655 if (Call->isSpirvOp())
660 Register PtrRegister = Call->Arguments[0];
663 SPIRV::MemorySemantics::SequentiallyConsistent |
671 .
addUse(Call->Arguments[1]);
679 if (Call->isSpirvOp())
683 bool IsCmpxchg = Call->Builtin->Name.contains(
"cmpxchg");
686 Register ObjectPtr = Call->Arguments[0];
687 Register ExpectedArg = Call->Arguments[1];
688 Register Desired = Call->Arguments[2];
689 MRI->setRegClass(ObjectPtr, &SPIRV::iIDRegClass);
690 MRI->setRegClass(ExpectedArg, &SPIRV::iIDRegClass);
691 MRI->setRegClass(Desired, &SPIRV::iIDRegClass);
693 LLT DesiredLLT =
MRI->getType(Desired);
696 SPIRV::OpTypePointer);
699 assert(IsCmpxchg ? ExpectedType == SPIRV::OpTypeInt
700 : ExpectedType == SPIRV::OpTypePointer);
705 auto StorageClass =
static_cast<SPIRV::StorageClass::StorageClass
>(
713 ? SPIRV::MemorySemantics::None
714 : SPIRV::MemorySemantics::SequentiallyConsistent | MemSemStorage;
717 ? SPIRV::MemorySemantics::None
718 : SPIRV::MemorySemantics::SequentiallyConsistent | MemSemStorage;
719 if (Call->Arguments.size() >= 4) {
720 assert(Call->Arguments.size() >= 5 &&
721 "Need 5+ args for explicit atomic cmpxchg");
728 if (MemOrdEq == MemSemEqual)
729 MemSemEqualReg = Call->Arguments[3];
730 if (MemOrdNeq == MemSemEqual)
731 MemSemUnequalReg = Call->Arguments[4];
732 MRI->setRegClass(Call->Arguments[3], &SPIRV::iIDRegClass);
733 MRI->setRegClass(Call->Arguments[4], &SPIRV::iIDRegClass);
737 if (!MemSemUnequalReg.
isValid())
741 auto Scope = IsCmpxchg ? SPIRV::Scope::Workgroup : SPIRV::Scope::Device;
742 if (Call->Arguments.size() >= 6) {
743 assert(Call->Arguments.size() == 6 &&
744 "Extra args for explicit atomic cmpxchg");
745 auto ClScope =
static_cast<SPIRV::CLMemoryScope
>(
748 if (ClScope ==
static_cast<unsigned>(Scope))
749 ScopeReg = Call->Arguments[5];
750 MRI->setRegClass(Call->Arguments[5], &SPIRV::iIDRegClass);
760 Register Tmp = !IsCmpxchg ?
MRI->createGenericVirtualRegister(DesiredLLT)
761 : Call->ReturnRegister;
762 if (!
MRI->getRegClassOrNull(Tmp))
763 MRI->setRegClass(Tmp, &SPIRV::iIDRegClass);
787 if (Call->isSpirvOp())
793 Call->Arguments.size() >= 4 ? Call->Arguments[3] :
Register();
795 assert(Call->Arguments.size() <= 4 &&
796 "Too many args for explicit atomic RMW");
797 ScopeRegister =
buildScopeReg(ScopeRegister, SPIRV::Scope::Workgroup,
798 MIRBuilder, GR,
MRI);
800 Register PtrRegister = Call->Arguments[0];
801 unsigned Semantics = SPIRV::MemorySemantics::None;
802 MRI->setRegClass(PtrRegister, &SPIRV::iIDRegClass);
804 Call->Arguments.size() >= 3 ? Call->Arguments[2] :
Register();
806 Semantics, MIRBuilder, GR);
807 MRI->setRegClass(Call->Arguments[1], &SPIRV::iIDRegClass);
808 Register ValueReg = Call->Arguments[1];
811 if (Call->ReturnType->getOpcode() == SPIRV::OpTypeFloat) {
812 if (Opcode == SPIRV::OpAtomicIAdd) {
813 Opcode = SPIRV::OpAtomicFAddEXT;
814 }
else if (Opcode == SPIRV::OpAtomicISub) {
817 Opcode = SPIRV::OpAtomicFAddEXT;
819 MRI->createGenericVirtualRegister(
MRI->getType(ValueReg));
820 MRI->setRegClass(NegValueReg, &SPIRV::iIDRegClass);
828 ValueReg = NegValueReg;
832 .
addDef(Call->ReturnRegister)
846 assert(Call->Arguments.size() == 4 &&
847 "Wrong number of atomic floating-type builtin");
851 Register PtrReg = Call->Arguments[0];
852 MRI->setRegClass(PtrReg, &SPIRV::iIDRegClass);
854 Register ScopeReg = Call->Arguments[1];
855 MRI->setRegClass(ScopeReg, &SPIRV::iIDRegClass);
857 Register MemSemanticsReg = Call->Arguments[2];
858 MRI->setRegClass(MemSemanticsReg, &SPIRV::iIDRegClass);
860 Register ValueReg = Call->Arguments[3];
861 MRI->setRegClass(ValueReg, &SPIRV::iIDRegClass);
864 .
addDef(Call->ReturnRegister)
878 bool IsSet = Opcode == SPIRV::OpAtomicFlagTestAndSet;
880 if (Call->isSpirvOp())
885 Register PtrRegister = Call->Arguments[0];
886 unsigned Semantics = SPIRV::MemorySemantics::SequentiallyConsistent;
888 Call->Arguments.size() >= 2 ? Call->Arguments[1] :
Register();
890 Semantics, MIRBuilder, GR);
892 assert((Opcode != SPIRV::OpAtomicFlagClear ||
893 (Semantics != SPIRV::MemorySemantics::Acquire &&
894 Semantics != SPIRV::MemorySemantics::AcquireRelease)) &&
895 "Invalid memory order argument!");
898 Call->Arguments.size() >= 3 ? Call->Arguments[2] :
Register();
915 if (Call->isSpirvOp())
920 unsigned MemSemantics = SPIRV::MemorySemantics::None;
922 if (MemFlags & SPIRV::CLK_LOCAL_MEM_FENCE)
923 MemSemantics |= SPIRV::MemorySemantics::WorkgroupMemory;
925 if (MemFlags & SPIRV::CLK_GLOBAL_MEM_FENCE)
926 MemSemantics |= SPIRV::MemorySemantics::CrossWorkgroupMemory;
928 if (MemFlags & SPIRV::CLK_IMAGE_MEM_FENCE)
929 MemSemantics |= SPIRV::MemorySemantics::ImageMemory;
931 if (Opcode == SPIRV::OpMemoryBarrier) {
932 std::memory_order MemOrder =
936 MemSemantics |= SPIRV::MemorySemantics::SequentiallyConsistent;
940 if (MemFlags == MemSemantics) {
941 MemSemanticsReg = Call->Arguments[0];
942 MRI->setRegClass(MemSemanticsReg, &SPIRV::iIDRegClass);
947 SPIRV::Scope::Scope Scope = SPIRV::Scope::Workgroup;
948 SPIRV::Scope::Scope MemScope = Scope;
949 if (Call->Arguments.size() >= 2) {
951 ((Opcode != SPIRV::OpMemoryBarrier && Call->Arguments.size() == 2) ||
952 (Opcode == SPIRV::OpMemoryBarrier && Call->Arguments.size() == 3)) &&
953 "Extra args for explicitly scoped barrier");
954 Register ScopeArg = (Opcode == SPIRV::OpMemoryBarrier) ? Call->Arguments[2]
955 : Call->Arguments[1];
956 SPIRV::CLMemoryScope CLScope =
959 if (!(MemFlags & SPIRV::CLK_LOCAL_MEM_FENCE) ||
960 (Opcode == SPIRV::OpMemoryBarrier))
963 if (CLScope ==
static_cast<unsigned>(Scope)) {
964 ScopeReg = Call->Arguments[1];
965 MRI->setRegClass(ScopeReg, &SPIRV::iIDRegClass);
973 if (Opcode != SPIRV::OpMemoryBarrier)
975 MIB.
addUse(MemSemanticsReg);
981 case SPIRV::Dim::DIM_1D:
982 case SPIRV::Dim::DIM_Buffer:
984 case SPIRV::Dim::DIM_2D:
985 case SPIRV::Dim::DIM_Cube:
986 case SPIRV::Dim::DIM_Rect:
988 case SPIRV::Dim::DIM_3D:
1001 return arrayed ? numComps + 1 : numComps;
1014 SPIRV::lookupExtendedBuiltin(Builtin->
Name, Builtin->
Set)->Number;
1019 .
addDef(Call->ReturnRegister)
1021 .
addImm(
static_cast<uint32_t>(SPIRV::InstructionSet::OpenCL_std))
1024 for (
auto Argument : Call->Arguments)
1035 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
1039 std::tie(CompareRegister, RelationType) =
1047 for (
auto Argument : Call->Arguments)
1051 return buildSelectInst(MIRBuilder, Call->ReturnRegister, CompareRegister,
1052 Call->ReturnType, GR);
1060 SPIRV::lookupGroupBuiltin(Builtin->
Name);
1063 if (Call->isSpirvOp()) {
1069 Register GroupOpReg = Call->Arguments[1];
1071 if (!
MI ||
MI->getOpcode() != TargetOpcode::G_CONSTANT)
1073 "Group Operation parameter must be an integer constant");
1074 uint64_t GrpOp =
MI->getOperand(1).getCImm()->getValue().getZExtValue();
1075 Register ScopeReg = Call->Arguments[0];
1076 if (!
MRI->getRegClassOrNull(ScopeReg))
1077 MRI->setRegClass(ScopeReg, &SPIRV::iIDRegClass);
1079 .
addDef(Call->ReturnRegister)
1083 for (
unsigned i = 2; i < Call->Arguments.size(); ++i) {
1084 Register ArgReg = Call->Arguments[i];
1085 if (!
MRI->getRegClassOrNull(ArgReg))
1086 MRI->setRegClass(ArgReg, &SPIRV::iIDRegClass);
1095 Register BoolReg = Call->Arguments[0];
1100 if (ArgInstruction->
getOpcode() == TargetOpcode::G_CONSTANT) {
1101 if (BoolRegType->
getOpcode() != SPIRV::OpTypeBool)
1105 if (BoolRegType->
getOpcode() == SPIRV::OpTypeInt) {
1107 MRI->setRegClass(Arg0, &SPIRV::IDRegClass);
1113 }
else if (BoolRegType->
getOpcode() != SPIRV::OpTypeBool) {
1120 Register GroupResultRegister = Call->ReturnRegister;
1121 SPIRVType *GroupResultType = Call->ReturnType;
1125 const bool HasBoolReturnTy =
1130 if (HasBoolReturnTy)
1131 std::tie(GroupResultRegister, GroupResultType) =
1134 auto Scope = Builtin->
Name.
starts_with(
"sub_group") ? SPIRV::Scope::Subgroup
1135 : SPIRV::Scope::Workgroup;
1139 if (GroupBuiltin->
Opcode == SPIRV::OpGroupBroadcast &&
1140 Call->Arguments.size() > 2) {
1146 Register ElemReg = Call->Arguments[1];
1148 if (!ElemType || ElemType->
getOpcode() != SPIRV::OpTypeInt)
1150 unsigned VecLen = Call->Arguments.size() - 1;
1151 VecReg =
MRI->createGenericVirtualRegister(
1153 MRI->setRegClass(VecReg, &SPIRV::vIDRegClass);
1159 for (
unsigned i = 1; i < Call->Arguments.size(); i++) {
1160 MIB.
addUse(Call->Arguments[i]);
1161 MRI->setRegClass(Call->Arguments[i], &SPIRV::iIDRegClass);
1169 .
addDef(GroupResultRegister)
1175 if (Call->Arguments.size() > 0) {
1177 MRI->setRegClass(Call->Arguments[0], &SPIRV::iIDRegClass);
1181 for (
unsigned i = 1; i < Call->Arguments.size(); i++) {
1182 MIB.addUse(Call->Arguments[i]);
1183 MRI->setRegClass(Call->Arguments[i], &SPIRV::iIDRegClass);
1188 if (HasBoolReturnTy)
1189 buildSelectInst(MIRBuilder, Call->ReturnRegister, GroupResultRegister,
1190 Call->ReturnType, GR);
1200 if (!ST->canUseExtension(SPIRV::Extension::SPV_INTEL_subgroups)) {
1201 std::string DiagMsg = std::string(Builtin->
Name) +
1202 ": the builtin requires the following SPIR-V "
1203 "extension: SPV_INTEL_subgroups";
1207 SPIRV::lookupIntelSubgroupsBuiltin(Builtin->
Name);
1210 if (Call->isSpirvOp()) {
1211 bool IsSet = OpCode != SPIRV::OpSubgroupBlockWriteINTEL &&
1212 OpCode != SPIRV::OpSubgroupImageBlockWriteINTEL;
1219 if (IntelSubgroups->
IsBlock) {
1222 if (Arg0Type->getOpcode() == SPIRV::OpTypeImage) {
1228 case SPIRV::OpSubgroupBlockReadINTEL:
1229 OpCode = SPIRV::OpSubgroupImageBlockReadINTEL;
1231 case SPIRV::OpSubgroupBlockWriteINTEL:
1232 OpCode = SPIRV::OpSubgroupImageBlockWriteINTEL;
1253 .
addDef(Call->ReturnRegister)
1255 for (
size_t i = 0; i < Call->Arguments.size(); ++i) {
1256 MIB.
addUse(Call->Arguments[i]);
1257 MRI->setRegClass(Call->Arguments[i], &SPIRV::iIDRegClass);
1269 if (!ST->canUseExtension(
1270 SPIRV::Extension::SPV_KHR_uniform_group_instructions)) {
1271 std::string DiagMsg = std::string(Builtin->
Name) +
1272 ": the builtin requires the following SPIR-V "
1273 "extension: SPV_KHR_uniform_group_instructions";
1277 SPIRV::lookupGroupUniformBuiltin(Builtin->
Name);
1280 Register GroupResultReg = Call->ReturnRegister;
1281 MRI->setRegClass(GroupResultReg, &SPIRV::iIDRegClass);
1284 Register ScopeReg = Call->Arguments[0];
1285 MRI->setRegClass(ScopeReg, &SPIRV::iIDRegClass);
1288 Register ConstGroupOpReg = Call->Arguments[1];
1290 if (!Const || Const->getOpcode() != TargetOpcode::G_CONSTANT)
1292 "expect a constant group operation for a uniform group instruction",
1295 if (!ConstOperand.
isCImm())
1301 Register ValueReg = Call->Arguments[2];
1302 MRI->setRegClass(ValueReg, &SPIRV::iIDRegClass);
1309 MIB.addUse(ValueReg);
1320 if (!ST->canUseExtension(SPIRV::Extension::SPV_KHR_shader_clock)) {
1321 std::string DiagMsg = std::string(Builtin->
Name) +
1322 ": the builtin requires the following SPIR-V "
1323 "extension: SPV_KHR_shader_clock";
1328 Register ResultReg = Call->ReturnRegister;
1329 MRI->setRegClass(ResultReg, &SPIRV::iIDRegClass);
1332 SPIRV::Scope::Scope ScopeArg =
1334 .
EndsWith(
"device", SPIRV::Scope::Scope::Device)
1335 .
EndsWith(
"work_group", SPIRV::Scope::Scope::Workgroup)
1336 .
EndsWith(
"sub_group", SPIRV::Scope::Scope::Subgroup);
1376 SPIRV::BuiltIn::BuiltIn BuiltinValue,
1378 Register IndexRegister = Call->Arguments[0];
1379 const unsigned ResultWidth = Call->ReturnType->getOperand(1).getImm();
1387 Register ToTruncate = Call->ReturnRegister;
1390 bool IsConstantIndex =
1391 IndexInstruction->getOpcode() == TargetOpcode::G_CONSTANT;
1396 Register DefaultReg = Call->ReturnRegister;
1397 if (PointerSize != ResultWidth) {
1398 DefaultReg =
MRI->createGenericVirtualRegister(
LLT::scalar(PointerSize));
1399 MRI->setRegClass(DefaultReg, &SPIRV::iIDRegClass);
1401 MIRBuilder.
getMF());
1402 ToTruncate = DefaultReg;
1406 MIRBuilder.
buildCopy(DefaultReg, NewRegister);
1414 Register Extracted = Call->ReturnRegister;
1415 if (!IsConstantIndex || PointerSize != ResultWidth) {
1416 Extracted =
MRI->createGenericVirtualRegister(
LLT::scalar(PointerSize));
1417 MRI->setRegClass(Extracted, &SPIRV::iIDRegClass);
1424 ExtractInst.
addUse(LoadedVector).
addUse(IndexRegister);
1427 if (!IsConstantIndex) {
1436 MRI->setRegClass(CompareRegister, &SPIRV::iIDRegClass);
1449 Register SelectionResult = Call->ReturnRegister;
1450 if (PointerSize != ResultWidth) {
1453 MRI->setRegClass(SelectionResult, &SPIRV::iIDRegClass);
1455 MIRBuilder.
getMF());
1458 MIRBuilder.
buildSelect(SelectionResult, CompareRegister, Extracted,
1460 ToTruncate = SelectionResult;
1462 ToTruncate = Extracted;
1466 if (PointerSize != ResultWidth)
1476 SPIRV::BuiltIn::BuiltIn
Value =
1477 SPIRV::lookupGetBuiltin(Builtin->
Name, Builtin->
Set)->
Value;
1479 if (
Value == SPIRV::BuiltIn::GlobalInvocationId)
1485 if (Call->ReturnType->getOpcode() == SPIRV::OpTypeVector)
1492 LLType, Call->ReturnRegister);
1501 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
1504 case SPIRV::OpStore:
1506 case SPIRV::OpAtomicLoad:
1508 case SPIRV::OpAtomicStore:
1510 case SPIRV::OpAtomicCompareExchange:
1511 case SPIRV::OpAtomicCompareExchangeWeak:
1514 case SPIRV::OpAtomicIAdd:
1515 case SPIRV::OpAtomicISub:
1516 case SPIRV::OpAtomicOr:
1517 case SPIRV::OpAtomicXor:
1518 case SPIRV::OpAtomicAnd:
1519 case SPIRV::OpAtomicExchange:
1521 case SPIRV::OpMemoryBarrier:
1523 case SPIRV::OpAtomicFlagTestAndSet:
1524 case SPIRV::OpAtomicFlagClear:
1527 if (Call->isSpirvOp())
1539 unsigned Opcode = SPIRV::lookupAtomicFloatingBuiltin(Builtin->
Name)->Opcode;
1542 case SPIRV::OpAtomicFAddEXT:
1543 case SPIRV::OpAtomicFMinEXT:
1544 case SPIRV::OpAtomicFMaxEXT:
1557 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
1564 MIRBuilder.
buildInstr(TargetOpcode::G_ADDRSPACE_CAST)
1565 .
addDef(Call->ReturnRegister)
1566 .
addUse(Call->Arguments[0]);
1573 if (Call->isSpirvOp())
1577 bool IsVec = Opcode == SPIRV::OpTypeVector;
1579 MIRBuilder.
buildInstr(IsVec ? SPIRV::OpDot : SPIRV::OpFMulS)
1580 .
addDef(Call->ReturnRegister)
1582 .
addUse(Call->Arguments[0])
1583 .
addUse(Call->Arguments[1]);
1591 SPIRV::BuiltIn::BuiltIn
Value =
1592 SPIRV::lookupGetBuiltin(Builtin->
Name, Builtin->
Set)->
Value;
1595 assert(Call->ReturnType->getOpcode() == SPIRV::OpTypeInt);
1599 MIRBuilder, Call->ReturnType, GR,
Value, LLType, Call->ReturnRegister,
1607 SPIRV::BuiltIn::BuiltIn
Value =
1608 SPIRV::lookupGetBuiltin(Call->Builtin->Name, Call->Builtin->Set)->
Value;
1609 uint64_t IsDefault = (
Value == SPIRV::BuiltIn::GlobalSize ||
1610 Value == SPIRV::BuiltIn::WorkgroupSize ||
1611 Value == SPIRV::BuiltIn::EnqueuedWorkgroupSize);
1621 SPIRV::lookupImageQueryBuiltin(Builtin->
Name, Builtin->
Set)->Component;
1626 unsigned NumExpectedRetComponents =
RetTy->getOpcode() == SPIRV::OpTypeVector
1627 ?
RetTy->getOperand(2).getImm()
1632 Register QueryResult = Call->ReturnRegister;
1633 SPIRVType *QueryResultType = Call->ReturnType;
1634 if (NumExpectedRetComponents != NumActualRetComponents) {
1640 IntTy, NumActualRetComponents, MIRBuilder);
1645 IsDimBuf ? SPIRV::OpImageQuerySize : SPIRV::OpImageQuerySizeLod;
1650 .
addUse(Call->Arguments[0]);
1653 if (NumExpectedRetComponents == NumActualRetComponents)
1655 if (NumExpectedRetComponents == 1) {
1657 unsigned ExtractedComposite =
1658 Component == 3 ? NumActualRetComponents - 1 : Component;
1659 assert(ExtractedComposite < NumActualRetComponents &&
1660 "Invalid composite index!");
1663 if (QueryResultType->
getOpcode() == SPIRV::OpTypeVector) {
1665 if (TypeReg != NewTypeReg &&
1667 TypeReg = NewTypeReg;
1669 MIRBuilder.
buildInstr(SPIRV::OpCompositeExtract)
1670 .
addDef(Call->ReturnRegister)
1673 .
addImm(ExtractedComposite);
1674 if (NewType !=
nullptr)
1679 auto MIB = MIRBuilder.
buildInstr(SPIRV::OpVectorShuffle)
1680 .
addDef(Call->ReturnRegister)
1684 for (
unsigned i = 0; i < NumExpectedRetComponents; ++i)
1685 MIB.
addImm(i < NumActualRetComponents ? i : 0xffffffff);
1693 assert(Call->ReturnType->getOpcode() == SPIRV::OpTypeInt &&
1694 "Image samples query result must be of int type!");
1699 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
1701 Register Image = Call->Arguments[0];
1703 SPIRV::Dim::Dim ImageDimensionality =
static_cast<SPIRV::Dim::Dim
>(
1705 (void)ImageDimensionality;
1708 case SPIRV::OpImageQuerySamples:
1709 assert(ImageDimensionality == SPIRV::Dim::DIM_2D &&
1710 "Image must be of 2D dimensionality");
1712 case SPIRV::OpImageQueryLevels:
1713 assert((ImageDimensionality == SPIRV::Dim::DIM_1D ||
1714 ImageDimensionality == SPIRV::Dim::DIM_2D ||
1715 ImageDimensionality == SPIRV::Dim::DIM_3D ||
1716 ImageDimensionality == SPIRV::Dim::DIM_Cube) &&
1717 "Image must be of 1D/2D/3D/Cube dimensionality");
1722 .
addDef(Call->ReturnRegister)
1729static SPIRV::SamplerAddressingMode::SamplerAddressingMode
1731 switch (Bitmask & SPIRV::CLK_ADDRESS_MODE_MASK) {
1732 case SPIRV::CLK_ADDRESS_CLAMP:
1733 return SPIRV::SamplerAddressingMode::Clamp;
1734 case SPIRV::CLK_ADDRESS_CLAMP_TO_EDGE:
1735 return SPIRV::SamplerAddressingMode::ClampToEdge;
1736 case SPIRV::CLK_ADDRESS_REPEAT:
1737 return SPIRV::SamplerAddressingMode::Repeat;
1738 case SPIRV::CLK_ADDRESS_MIRRORED_REPEAT:
1739 return SPIRV::SamplerAddressingMode::RepeatMirrored;
1740 case SPIRV::CLK_ADDRESS_NONE:
1741 return SPIRV::SamplerAddressingMode::None;
1748 return (Bitmask & SPIRV::CLK_NORMALIZED_COORDS_TRUE) ? 1 : 0;
1751static SPIRV::SamplerFilterMode::SamplerFilterMode
1753 if (Bitmask & SPIRV::CLK_FILTER_LINEAR)
1754 return SPIRV::SamplerFilterMode::Linear;
1755 if (Bitmask & SPIRV::CLK_FILTER_NEAREST)
1756 return SPIRV::SamplerFilterMode::Nearest;
1757 return SPIRV::SamplerFilterMode::Nearest;
1764 Register Image = Call->Arguments[0];
1766 MRI->setRegClass(Image, &SPIRV::iIDRegClass);
1767 MRI->setRegClass(Call->Arguments[1], &SPIRV::iIDRegClass);
1770 if (HasOclSampler || HasMsaa)
1771 MRI->setRegClass(Call->Arguments[2], &SPIRV::iIDRegClass);
1772 if (HasOclSampler) {
1773 Register Sampler = Call->Arguments[1];
1787 Register SampledImage =
MRI->createVirtualRegister(&SPIRV::iIDRegClass);
1798 bool NeedsExtraction =
false;
1799 if (TempType->
getOpcode() != SPIRV::OpTypeVector) {
1802 NeedsExtraction =
true;
1805 Register TempRegister =
MRI->createGenericVirtualRegister(LLType);
1806 MRI->setRegClass(TempRegister, &SPIRV::iIDRegClass);
1809 MIRBuilder.
buildInstr(SPIRV::OpImageSampleExplicitLod)
1810 .
addDef(NeedsExtraction ? TempRegister : Call->ReturnRegister)
1813 .
addUse(Call->Arguments[2])
1814 .
addImm(SPIRV::ImageOperand::Lod)
1817 if (NeedsExtraction)
1818 MIRBuilder.
buildInstr(SPIRV::OpCompositeExtract)
1819 .
addDef(Call->ReturnRegister)
1823 }
else if (HasMsaa) {
1825 .
addDef(Call->ReturnRegister)
1828 .
addUse(Call->Arguments[1])
1829 .
addImm(SPIRV::ImageOperand::Sample)
1830 .
addUse(Call->Arguments[2]);
1833 .
addDef(Call->ReturnRegister)
1836 .
addUse(Call->Arguments[1]);
1848 .
addUse(Call->Arguments[0])
1849 .
addUse(Call->Arguments[1])
1850 .
addUse(Call->Arguments[2]);
1859 if (Call->Builtin->Name.contains_insensitive(
1860 "__translate_sampler_initializer")) {
1867 return Sampler.isValid();
1868 }
else if (Call->Builtin->Name.contains_insensitive(
"__spirv_SampledImage")) {
1870 Register Image = Call->Arguments[0];
1875 Call->ReturnRegister.isValid()
1876 ? Call->ReturnRegister
1877 :
MRI->createVirtualRegister(&SPIRV::iIDRegClass);
1882 .
addUse(Call->Arguments[1]);
1884 }
else if (Call->Builtin->Name.contains_insensitive(
1885 "__spirv_ImageSampleExplicitLod")) {
1887 std::string ReturnType = DemangledCall.
str();
1888 if (DemangledCall.
contains(
"_R")) {
1889 ReturnType = ReturnType.substr(ReturnType.find(
"_R") + 2);
1890 ReturnType = ReturnType.substr(0, ReturnType.find(
'('));
1897 std::string DiagMsg =
1898 "Unable to recognize SPIRV type name: " + ReturnType;
1901 MRI->setRegClass(Call->Arguments[0], &SPIRV::iIDRegClass);
1902 MRI->setRegClass(Call->Arguments[1], &SPIRV::iIDRegClass);
1903 MRI->setRegClass(Call->Arguments[3], &SPIRV::iIDRegClass);
1905 MIRBuilder.
buildInstr(SPIRV::OpImageSampleExplicitLod)
1906 .
addDef(Call->ReturnRegister)
1908 .
addUse(Call->Arguments[0])
1909 .
addUse(Call->Arguments[1])
1910 .
addImm(SPIRV::ImageOperand::Lod)
1911 .
addUse(Call->Arguments[3]);
1919 MIRBuilder.
buildSelect(Call->ReturnRegister, Call->Arguments[0],
1920 Call->Arguments[1], Call->Arguments[2]);
1936 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
1937 bool IsSet = Opcode != SPIRV::OpCooperativeMatrixStoreKHR;
1938 unsigned ArgSz = Call->Arguments.size();
1939 unsigned LiteralIdx = 0;
1940 if (Opcode == SPIRV::OpCooperativeMatrixLoadKHR && ArgSz > 3)
1942 else if (Opcode == SPIRV::OpCooperativeMatrixStoreKHR && ArgSz > 4)
1949 if (Opcode == SPIRV::OpCooperativeMatrixLengthKHR) {
1954 .
addDef(Call->ReturnRegister)
1960 IsSet ? TypeReg :
Register(0), ImmArgs);
1969 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
1973 case SPIRV::OpSpecConstant: {
1977 buildOpDecorate(Call->ReturnRegister, MIRBuilder, SPIRV::Decoration::SpecId,
1980 Register ConstRegister = Call->Arguments[1];
1983 (Const->getOpcode() == TargetOpcode::G_CONSTANT ||
1984 Const->getOpcode() == TargetOpcode::G_FCONSTANT) &&
1985 "Argument should be either an int or floating-point constant");
1988 if (Call->ReturnType->getOpcode() == SPIRV::OpTypeBool) {
1989 assert(ConstOperand.
isCImm() &&
"Int constant operand is expected");
1991 ? SPIRV::OpSpecConstantTrue
1992 : SPIRV::OpSpecConstantFalse;
1995 .
addDef(Call->ReturnRegister)
1998 if (Call->ReturnType->getOpcode() != SPIRV::OpTypeBool) {
1999 if (Const->getOpcode() == TargetOpcode::G_CONSTANT)
2006 case SPIRV::OpSpecConstantComposite: {
2008 .
addDef(Call->ReturnRegister)
2010 for (
unsigned i = 0; i < Call->Arguments.size(); i++)
2011 MIB.
addUse(Call->Arguments[i]);
2023 MRI->setRegClass(Call->Arguments[0], &SPIRV::iIDRegClass);
2030 Register TmpReg =
MRI->createVirtualRegister(&SPIRV::iIDRegClass);
2034 unsigned NumArgs = Call->Arguments.size();
2036 Register GlobalWorkSize = Call->Arguments[NumArgs < 4 ? 1 : 2];
2037 MRI->setRegClass(GlobalWorkSize, &SPIRV::iIDRegClass);
2039 NumArgs == 2 ?
Register(0) : Call->Arguments[NumArgs < 4 ? 2 : 3];
2041 MRI->setRegClass(LocalWorkSize, &SPIRV::iIDRegClass);
2042 Register GlobalWorkOffset = NumArgs <= 3 ?
Register(0) : Call->Arguments[1];
2043 if (GlobalWorkOffset.
isValid())
2044 MRI->setRegClass(GlobalWorkOffset, &SPIRV::iIDRegClass);
2048 if (SpvTy->
getOpcode() == SPIRV::OpTypePointer) {
2053 if (!
MRI->getRegClassOrNull(GWSPtr))
2054 MRI->setRegClass(GWSPtr, &SPIRV::iIDRegClass);
2056 unsigned Size = Call->Builtin->Name ==
"ndrange_3D" ? 3 : 2;
2061 GlobalWorkSize =
MRI->createVirtualRegister(&SPIRV::iIDRegClass);
2070 SpvFieldTy, *ST.getInstrInfo());
2075 LocalWorkSize = Const;
2076 if (!GlobalWorkOffset.
isValid())
2077 GlobalWorkOffset = Const;
2085 .
addUse(GlobalWorkOffset);
2087 .
addUse(Call->Arguments[0])
2112 bool IsSpirvOp = Call->isSpirvOp();
2113 bool HasEvents = Call->Builtin->Name.contains(
"events") || IsSpirvOp;
2120 if (Call->Builtin->Name.contains(
"_varargs") || IsSpirvOp) {
2121 const unsigned LocalSizeArrayIdx = HasEvents ? 9 : 6;
2122 Register GepReg = Call->Arguments[LocalSizeArrayIdx];
2129 assert(LocalSizeTy &&
"Local size type is expected");
2131 cast<ArrayType>(LocalSizeTy)->getNumElements();
2135 Int32Ty, MIRBuilder, SPIRV::StorageClass::Function);
2136 for (
unsigned I = 0;
I < LocalSizeNum; ++
I) {
2138 MRI->setType(
Reg, LLType);
2152 auto MIB = MIRBuilder.
buildInstr(SPIRV::OpEnqueueKernel)
2153 .
addDef(Call->ReturnRegister)
2157 const unsigned BlockFIdx = HasEvents ? 6 : 3;
2158 for (
unsigned i = 0; i < BlockFIdx; i++)
2159 MIB.addUse(Call->Arguments[i]);
2166 MIB.addUse(NullPtr);
2167 MIB.addUse(NullPtr);
2175 Register BlockLiteralReg = Call->Arguments[BlockFIdx + 1];
2177 MIB.addUse(BlockLiteralReg);
2187 for (
unsigned i = 0; i < LocalSizes.
size(); i++)
2188 MIB.addUse(LocalSizes[i]);
2198 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
2201 case SPIRV::OpRetainEvent:
2202 case SPIRV::OpReleaseEvent:
2205 case SPIRV::OpCreateUserEvent:
2206 case SPIRV::OpGetDefaultQueue:
2208 .
addDef(Call->ReturnRegister)
2210 case SPIRV::OpIsValidEvent:
2213 .
addDef(Call->ReturnRegister)
2215 .
addUse(Call->Arguments[0]);
2216 case SPIRV::OpSetUserEventStatus:
2220 .
addUse(Call->Arguments[0])
2221 .
addUse(Call->Arguments[1]);
2222 case SPIRV::OpCaptureEventProfilingInfo:
2227 .
addUse(Call->Arguments[0])
2228 .
addUse(Call->Arguments[1])
2229 .
addUse(Call->Arguments[2]);
2230 case SPIRV::OpBuildNDRange:
2232 case SPIRV::OpEnqueueKernel:
2245 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
2247 bool IsSet = Opcode == SPIRV::OpGroupAsyncCopy;
2249 if (Call->isSpirvOp())
2256 case SPIRV::OpGroupAsyncCopy: {
2258 Call->ReturnType->getOpcode() == SPIRV::OpTypeEvent
2262 unsigned NumArgs = Call->Arguments.size();
2263 Register EventReg = Call->Arguments[NumArgs - 1];
2265 .
addDef(Call->ReturnRegister)
2268 .
addUse(Call->Arguments[0])
2269 .
addUse(Call->Arguments[1])
2270 .
addUse(Call->Arguments[2])
2271 .
addUse(Call->Arguments.size() > 4
2272 ? Call->Arguments[3]
2275 if (NewType !=
nullptr)
2280 case SPIRV::OpGroupWaitEvents:
2283 .
addUse(Call->Arguments[0])
2284 .
addUse(Call->Arguments[1]);
2296 SPIRV::lookupConvertBuiltin(Call->Builtin->Name, Call->Builtin->Set);
2298 if (!Builtin && Call->isSpirvOp()) {
2301 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
2308 SPIRV::Decoration::SaturatedConversion, {});
2311 SPIRV::Decoration::FPRoundingMode,
2312 {(unsigned)Builtin->RoundingMode});
2314 std::string NeedExtMsg;
2315 bool IsRightComponentsNumber =
true;
2316 unsigned Opcode = SPIRV::OpNop;
2323 : SPIRV::OpSatConvertSToU;
2326 : SPIRV::OpSConvert;
2328 SPIRV::OpTypeFloat)) {
2333 if (!ST->canUseExtension(
2334 SPIRV::Extension::SPV_INTEL_bfloat16_conversion))
2335 NeedExtMsg =
"SPV_INTEL_bfloat16_conversion";
2336 IsRightComponentsNumber =
2339 Opcode = SPIRV::OpConvertBF16ToFINTEL;
2341 bool IsSourceSigned =
2343 Opcode = IsSourceSigned ? SPIRV::OpConvertSToF : SPIRV::OpConvertUToF;
2347 SPIRV::OpTypeFloat)) {
2354 if (!ST->canUseExtension(
2355 SPIRV::Extension::SPV_INTEL_bfloat16_conversion))
2356 NeedExtMsg =
"SPV_INTEL_bfloat16_conversion";
2357 IsRightComponentsNumber =
2360 Opcode = SPIRV::OpConvertFToBF16INTEL;
2363 : SPIRV::OpConvertFToU;
2366 SPIRV::OpTypeFloat)) {
2368 Opcode = SPIRV::OpFConvert;
2372 if (!NeedExtMsg.empty()) {
2373 std::string DiagMsg = std::string(Builtin->
Name) +
2374 ": the builtin requires the following SPIR-V "
2379 if (!IsRightComponentsNumber) {
2380 std::string DiagMsg =
2381 std::string(Builtin->
Name) +
2382 ": result and argument must have the same number of components";
2385 assert(Opcode != SPIRV::OpNop &&
2386 "Conversion between the types not implemented!");
2389 .
addDef(Call->ReturnRegister)
2391 .
addUse(Call->Arguments[0]);
2400 SPIRV::lookupVectorLoadStoreBuiltin(Call->Builtin->Name,
2401 Call->Builtin->Set);
2405 .
addDef(Call->ReturnRegister)
2407 .
addImm(
static_cast<uint32_t>(SPIRV::InstructionSet::OpenCL_std))
2409 for (
auto Argument : Call->Arguments)
2427 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
2428 bool IsLoad = Opcode == SPIRV::OpLoad;
2432 MIB.
addDef(Call->ReturnRegister);
2436 MIB.
addUse(Call->Arguments[0]);
2438 MRI->setRegClass(Call->Arguments[0], &SPIRV::iIDRegClass);
2441 MIB.addUse(Call->Arguments[1]);
2442 MRI->setRegClass(Call->Arguments[1], &SPIRV::iIDRegClass);
2445 unsigned NumArgs = Call->Arguments.size();
2446 if ((IsLoad && NumArgs >= 2) || NumArgs >= 3) {
2448 MRI->setRegClass(Call->Arguments[IsLoad ? 1 : 2], &SPIRV::iIDRegClass);
2450 if ((IsLoad && NumArgs >= 3) || NumArgs >= 4) {
2452 MRI->setRegClass(Call->Arguments[IsLoad ? 2 : 3], &SPIRV::iIDRegClass);
2465std::tuple<int, unsigned, unsigned>
2467 SPIRV::InstructionSet::InstructionSet Set) {
2470 std::unique_ptr<const IncomingCall> Call =
2473 return std::make_tuple(-1, 0, 0);
2475 switch (Call->Builtin->Group) {
2476 case SPIRV::Relational:
2478 case SPIRV::Barrier:
2479 case SPIRV::CastToPtr:
2480 case SPIRV::ImageMiscQuery:
2481 case SPIRV::SpecConstant:
2482 case SPIRV::Enqueue:
2483 case SPIRV::AsyncCopy:
2484 case SPIRV::LoadStore:
2485 case SPIRV::CoopMatr:
2487 SPIRV::lookupNativeBuiltin(Call->Builtin->Name, Call->Builtin->Set))
2488 return std::make_tuple(Call->Builtin->Group, R->Opcode, 0);
2490 case SPIRV::Extended:
2491 if (
const auto *R = SPIRV::lookupExtendedBuiltin(Call->Builtin->Name,
2492 Call->Builtin->Set))
2493 return std::make_tuple(Call->Builtin->Group, 0, R->Number);
2495 case SPIRV::VectorLoadStore:
2496 if (
const auto *R = SPIRV::lookupVectorLoadStoreBuiltin(Call->Builtin->Name,
2497 Call->Builtin->Set))
2498 return std::make_tuple(SPIRV::Extended, 0, R->Number);
2501 if (
const auto *R = SPIRV::lookupGroupBuiltin(Call->Builtin->Name))
2502 return std::make_tuple(Call->Builtin->Group, R->Opcode, 0);
2504 case SPIRV::AtomicFloating:
2505 if (
const auto *R = SPIRV::lookupAtomicFloatingBuiltin(Call->Builtin->Name))
2506 return std::make_tuple(Call->Builtin->Group, R->Opcode, 0);
2508 case SPIRV::IntelSubgroups:
2509 if (
const auto *R = SPIRV::lookupIntelSubgroupsBuiltin(Call->Builtin->Name))
2510 return std::make_tuple(Call->Builtin->Group, R->Opcode, 0);
2512 case SPIRV::GroupUniform:
2513 if (
const auto *R = SPIRV::lookupGroupUniformBuiltin(Call->Builtin->Name))
2514 return std::make_tuple(Call->Builtin->Group, R->Opcode, 0);
2516 case SPIRV::WriteImage:
2517 return std::make_tuple(Call->Builtin->Group, SPIRV::OpImageWrite, 0);
2519 return std::make_tuple(Call->Builtin->Group, TargetOpcode::G_SELECT, 0);
2520 case SPIRV::Construct:
2521 return std::make_tuple(Call->Builtin->Group, SPIRV::OpCompositeConstruct,
2523 case SPIRV::KernelClock:
2524 return std::make_tuple(Call->Builtin->Group, SPIRV::OpReadClockKHR, 0);
2526 return std::make_tuple(-1, 0, 0);
2528 return std::make_tuple(-1, 0, 0);
2532 SPIRV::InstructionSet::InstructionSet Set,
2537 LLVM_DEBUG(
dbgs() <<
"Lowering builtin call: " << DemangledCall <<
"\n");
2542 if (OrigRetTy && !OrigRetTy->
isVoidTy()) {
2546 }
else if (OrigRetTy && OrigRetTy->
isVoidTy()) {
2553 std::unique_ptr<const IncomingCall> Call =
2554 lookupBuiltin(DemangledCall, Set, ReturnRegister, ReturnType, Args);
2558 return std::nullopt;
2562 assert(Args.size() >= Call->Builtin->MinNumArgs &&
2563 "Too few arguments to generate the builtin");
2564 if (Call->Builtin->MaxNumArgs && Args.size() > Call->Builtin->MaxNumArgs)
2565 LLVM_DEBUG(
dbgs() <<
"More arguments provided than required!\n");
2568 switch (Call->Builtin->Group) {
2569 case SPIRV::Extended:
2571 case SPIRV::Relational:
2575 case SPIRV::Variable:
2579 case SPIRV::AtomicFloating:
2581 case SPIRV::Barrier:
2583 case SPIRV::CastToPtr:
2589 case SPIRV::GetQuery:
2591 case SPIRV::ImageSizeQuery:
2593 case SPIRV::ImageMiscQuery:
2595 case SPIRV::ReadImage:
2597 case SPIRV::WriteImage:
2599 case SPIRV::SampleImage:
2603 case SPIRV::Construct:
2605 case SPIRV::SpecConstant:
2607 case SPIRV::Enqueue:
2609 case SPIRV::AsyncCopy:
2611 case SPIRV::Convert:
2613 case SPIRV::VectorLoadStore:
2615 case SPIRV::LoadStore:
2617 case SPIRV::IntelSubgroups:
2619 case SPIRV::GroupUniform:
2621 case SPIRV::KernelClock:
2623 case SPIRV::CoopMatr:
2633 DemangledCall.
slice(DemangledCall.
find(
'(') + 1, DemangledCall.
find(
')'));
2634 BuiltinArgs.
split(BuiltinArgsTypeStrs,
',', -1,
false);
2635 if (ArgIdx >= BuiltinArgsTypeStrs.
size())
2637 StringRef TypeStr = BuiltinArgsTypeStrs[ArgIdx].trim();
2643 [[maybe_unused]]
bool IsOCLBuiltinType = TypeStr.
consume_front(
"ocl_");
2644 assert(IsOCLBuiltinType &&
"Invalid OpenCL builtin prefix");
2661 unsigned VecElts = 0;
2672 TypeStr = TypeStr.
substr(0, TypeStr.
find(
']'));
2687#define GET_BuiltinTypes_DECL
2688#define GET_BuiltinTypes_IMPL
2695#define GET_OpenCLTypes_DECL
2696#define GET_OpenCLTypes_IMPL
2698#include "SPIRVGenTables.inc"
2706 if (
Name.starts_with(
"void"))
2708 else if (
Name.starts_with(
"int") ||
Name.starts_with(
"uint"))
2710 else if (
Name.starts_with(
"float"))
2712 else if (
Name.starts_with(
"half"))
2725 unsigned Opcode = TypeRecord->
Opcode;
2740 "Invalid number of parameters for SPIR-V pipe builtin!");
2743 SPIRV::AccessQualifier::AccessQualifier(
2751 "Invalid number of parameters for SPIR-V coop matrices builtin!");
2753 "SPIR-V coop matrices builtin type must have a type parameter!");
2758 MIRBuilder, ExtensionType, ElemType, ExtensionType->
getIntParameter(0),
2765 const SPIRV::AccessQualifier::AccessQualifier Qualifier,
2768 "SPIR-V image builtin type must have sampled type parameter!");
2772 "Invalid number of parameters for SPIR-V image builtin!");
2775 MIRBuilder, SampledType,
2780 Qualifier == SPIRV::AccessQualifier::WriteOnly
2781 ? SPIRV::AccessQualifier::WriteOnly
2782 : SPIRV::AccessQualifier::AccessQualifier(
2790 OpaqueType, SPIRV::AccessQualifier::ReadOnly, MIRBuilder, GR);
2798 StringRef NameWithParameters = TypeName;
2805 SPIRV::lookupOpenCLType(NameWithParameters);
2808 NameWithParameters);
2816 "Unknown builtin opaque type!");
2820 if (!NameWithParameters.
contains(
'_'))
2824 unsigned BaseNameLength = NameWithParameters.
find(
'_') - 1;
2825 SplitString(NameWithParameters.
substr(BaseNameLength + 1), Parameters,
"_");
2828 bool HasTypeParameter = !
isDigit(Parameters[0][0]);
2829 if (HasTypeParameter)
2832 for (
unsigned i = HasTypeParameter ? 1 : 0; i < Parameters.size(); i++) {
2833 unsigned IntParameter = 0;
2834 bool ValidLiteral = !Parameters[i].getAsInteger(10, IntParameter);
2837 "Invalid format of SPIR-V builtin parameter literal!");
2841 NameWithParameters.
substr(0, BaseNameLength),
2842 TypeParameters, IntParameters);
2846 SPIRV::AccessQualifier::AccessQualifier AccessQual,
2877 switch (TypeRecord->
Opcode) {
2878 case SPIRV::OpTypeImage:
2881 case SPIRV::OpTypePipe:
2884 case SPIRV::OpTypeDeviceEvent:
2887 case SPIRV::OpTypeSampler:
2890 case SPIRV::OpTypeSampledImage:
2893 case SPIRV::OpTypeCooperativeMatrixKHR:
unsigned const MachineRegisterInfo * MRI
MachineInstrBuilder MachineInstrBuilder & DefMI
AMDGPU Lower Kernel Arguments
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static bool isDigit(const char C)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
BaseType
A given derived pointer can have multiple base pointers through phi/selects.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
APInt bitcastToAPInt() const
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
uint64_t getZExtValue() const
Get zero extended value.
This class represents an incoming formal argument to a Function.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
@ ICMP_ULT
unsigned less than
const APFloat & getValueAPF() const
const APInt & getValue() const
Return the constant as an APInt value reference.
A parsed version of the target data layout string in and methods for querying it.
Tagged union holding either a T or a Error.
Class to represent fixed width SIMD vectors.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
static constexpr LLT vector(ElementCount EC, unsigned ScalarSizeInBits)
Get a low-level vector of some number of elements and element width.
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
static constexpr LLT pointer(unsigned AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space.
static constexpr LLT fixed_vector(unsigned NumElements, unsigned ScalarSizeInBits)
Get a low-level fixed-width vector of some number of elements and element width.
This is an important class for using LLVM in a threaded context.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
Helper class to build MachineInstr.
LLVMContext & getContext() const
MachineInstrBuilder buildSelect(const DstOp &Res, const SrcOp &Tst, const SrcOp &Op0, const SrcOp &Op1, std::optional< unsigned > Flags=std::nullopt)
Build and insert a Res = G_SELECT Tst, Op0, Op1.
MachineInstrBuilder buildICmp(CmpInst::Predicate Pred, const DstOp &Res, const SrcOp &Op0, const SrcOp &Op1)
Build and insert a Res = G_ICMP Pred, Op0, Op1.
MachineBasicBlock::iterator getInsertPt()
Current insertion point for new instructions.
MachineInstrBuilder buildIntrinsic(Intrinsic::ID ID, ArrayRef< Register > Res, bool HasSideEffects, bool isConvergent)
Build and insert a G_INTRINSIC instruction.
MachineInstrBuilder buildLoad(const DstOp &Res, const SrcOp &Addr, MachineMemOperand &MMO)
Build and insert Res = G_LOAD Addr, MMO.
MachineInstrBuilder buildZExtOrTrunc(const DstOp &Res, const SrcOp &Op)
Build and insert Res = G_ZEXT Op, Res = G_TRUNC Op, or Res = COPY Op depending on the differing sizes...
MachineInstrBuilder buildInstr(unsigned Opcode)
Build and insert <empty> = Opcode <empty>.
MachineFunction & getMF()
Getter for the function we currently build.
MachineRegisterInfo * getMRI()
Getter for MRI.
MachineInstrBuilder buildCopy(const DstOp &Res, const SrcOp &Op)
Build and insert Res = COPY Op.
const DataLayout & getDataLayout() const
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & addUse(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register use operand.
const MachineInstrBuilder & addDef(Register RegNo, unsigned Flags=0, unsigned SubReg=0) const
Add a virtual register definition operand.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
MachineOperand class - Representation of each machine instruction operand.
const GlobalValue * getGlobal() const
const ConstantInt * getCImm() const
bool isCImm() const
isCImm - Test if this is a MO_CImmediate operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
const MDNode * getMetadata() const
Register getReg() const
getReg - Returns the register number.
const ConstantFP * getFPImm() const
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
void setType(Register VReg, LLT Ty)
Set the low-level type of VReg to Ty.
void setRegClass(Register Reg, const TargetRegisterClass *RC)
setRegClass - Set the register class of the specified virtual register.
Register createGenericVirtualRegister(LLT Ty, StringRef Name="")
Create and return a new generic virtual register with low-level type Ty.
const TargetRegisterClass * getRegClassOrNull(Register Reg) const
Return the register class of Reg, or null if Reg has not been assigned a register class yet.
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
Wrapper class representing virtual and physical registers.
constexpr bool isValid() const
SPIRVType * getOrCreateOpTypePipe(MachineIRBuilder &MIRBuilder, SPIRV::AccessQualifier::AccessQualifier AccQual)
SPIRVType * getSPIRVTypeForVReg(Register VReg, const MachineFunction *MF=nullptr) const
SPIRVType * getOrCreateSPIRVBoolType(MachineIRBuilder &MIRBuilder)
Register getOrCreateConsIntVector(uint64_t Val, MachineIRBuilder &MIRBuilder, SPIRVType *SpvType, bool EmitIR=true)
const Type * getTypeForSPIRVType(const SPIRVType *Ty) const
Register buildConstantSampler(Register Res, unsigned AddrMode, unsigned Param, unsigned FilerMode, MachineIRBuilder &MIRBuilder, SPIRVType *SpvType)
unsigned getScalarOrVectorComponentCount(Register VReg) const
SPIRVType * getOrCreateOpTypeImage(MachineIRBuilder &MIRBuilder, SPIRVType *SampledType, SPIRV::Dim::Dim Dim, uint32_t Depth, uint32_t Arrayed, uint32_t Multisampled, uint32_t Sampled, SPIRV::ImageFormat::ImageFormat ImageFormat, SPIRV::AccessQualifier::AccessQualifier AccQual)
unsigned getPointerSize() const
SPIRVType * getOrCreateOpTypeByOpcode(const Type *Ty, MachineIRBuilder &MIRBuilder, unsigned Opcode)
Register buildConstantFP(APFloat Val, MachineIRBuilder &MIRBuilder, SPIRVType *SpvType=nullptr)
Register getSPIRVTypeID(const SPIRVType *SpirvType) const
SPIRVType * getOrCreateSPIRVType(const Type *Type, MachineIRBuilder &MIRBuilder, SPIRV::AccessQualifier::AccessQualifier AQ=SPIRV::AccessQualifier::ReadWrite, bool EmitIR=true)
void assignSPIRVTypeToVReg(SPIRVType *Type, Register VReg, MachineFunction &MF)
bool isScalarOfType(Register VReg, unsigned TypeOpcode) const
Register buildGlobalVariable(Register Reg, SPIRVType *BaseType, StringRef Name, const GlobalValue *GV, SPIRV::StorageClass::StorageClass Storage, const MachineInstr *Init, bool IsConst, bool HasLinkageTy, SPIRV::LinkageType::LinkageType LinkageType, MachineIRBuilder &MIRBuilder, bool IsInstSelector)
SPIRVType * getOrCreateOpTypeSampledImage(SPIRVType *ImageType, MachineIRBuilder &MIRBuilder)
SPIRVType * getOrCreateSPIRVTypeByName(StringRef TypeStr, MachineIRBuilder &MIRBuilder, SPIRV::StorageClass::StorageClass SC=SPIRV::StorageClass::Function, SPIRV::AccessQualifier::AccessQualifier AQ=SPIRV::AccessQualifier::ReadWrite)
SPIRVType * assignTypeToVReg(const Type *Type, Register VReg, MachineIRBuilder &MIRBuilder, SPIRV::AccessQualifier::AccessQualifier AQ=SPIRV::AccessQualifier::ReadWrite, bool EmitIR=true)
bool isScalarOrVectorOfType(Register VReg, unsigned TypeOpcode) const
Register getOrCreateConstIntArray(uint64_t Val, size_t Num, MachineInstr &I, SPIRVType *SpvType, const SPIRVInstrInfo &TII)
SPIRVType * getOrCreateOpTypeDeviceEvent(MachineIRBuilder &MIRBuilder)
SPIRVType * getOrCreateSPIRVPointerType(SPIRVType *BaseType, MachineIRBuilder &MIRBuilder, SPIRV::StorageClass::StorageClass SClass=SPIRV::StorageClass::Function)
SPIRVType * getOrCreateOpTypeCoopMatr(MachineIRBuilder &MIRBuilder, const TargetExtType *ExtensionType, const SPIRVType *ElemType, uint32_t Scope, uint32_t Rows, uint32_t Columns, uint32_t Use)
SPIRVType * getOrCreateSPIRVVectorType(SPIRVType *BaseType, unsigned NumElements, MachineIRBuilder &MIRBuilder)
SPIRVType * getOrCreateSPIRVIntegerType(unsigned BitWidth, MachineIRBuilder &MIRBuilder)
SPIRV::StorageClass::StorageClass getPointerStorageClass(Register VReg) const
SPIRVType * getOrCreateOpTypeSampler(MachineIRBuilder &MIRBuilder)
Register buildConstantInt(uint64_t Val, MachineIRBuilder &MIRBuilder, SPIRVType *SpvType=nullptr, bool EmitIR=true)
Register getOrCreateConstNullPtr(MachineIRBuilder &MIRBuilder, SPIRVType *SpvType)
unsigned getScalarOrVectorBitWidth(const SPIRVType *Type) const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
bool consume_back(StringRef Suffix)
Returns true if this StringRef has the given suffix and removes that suffix.
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
std::string str() const
str - Get the contents as an std::string.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
bool contains_insensitive(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
size_t find_first_of(char C, size_t From=0) const
Find the first character in the string that is C, or npos if not found.
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
bool ends_with(StringRef Suffix) const
Check if this string ends with the given Suffix.
A switch()-like statement whose cases are string literals.
StringSwitch & EndsWith(StringLiteral S, T Value)
Class to represent struct types.
static StructType * getTypeByName(LLVMContext &C, StringRef Name)
Return the type with the specified name, or null if there is none by that name.
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Class to represent target extensions types, which are generally unintrospectable from target-independ...
unsigned getNumIntParameters() const
static TargetExtType * get(LLVMContext &Context, StringRef Name, ArrayRef< Type * > Types=std::nullopt, ArrayRef< unsigned > Ints=std::nullopt)
Return a target extension type having the specified name and optional type and integer parameters.
Type * getTypeParameter(unsigned i) const
unsigned getNumTypeParameters() const
unsigned getIntParameter(unsigned i) const
The instances of the Type class are immutable: once they are created, they are never changed.
static Type * getHalfTy(LLVMContext &C)
StringRef getStructName() const
static Type * getVoidTy(LLVMContext &C)
static IntegerType * getInt8Ty(LLVMContext &C)
static IntegerType * getInt32Ty(LLVMContext &C)
static Type * getFloatTy(LLVMContext &C)
bool isVoidTy() const
Return true if this is 'void'.
LLVM Value Representation.
Value(Type *Ty, unsigned scid)
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount)
Create a vector type that contains a defined type and has a specific number of elements.
std::tuple< int, unsigned, unsigned > mapBuiltinToOpcode(const StringRef DemangledCall, SPIRV::InstructionSet::InstructionSet Set)
Helper function for finding a builtin function attributes by a demangled function name.
Type * parseBuiltinCallArgumentBaseType(const StringRef DemangledCall, unsigned ArgIdx, LLVMContext &Ctx)
Parses the provided ArgIdx argument base type in the DemangledCall skeleton.
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...
std::optional< bool > lowerBuiltin(const StringRef DemangledCall, SPIRV::InstructionSet::InstructionSet Set, MachineIRBuilder &MIRBuilder, const Register OrigRet, const Type *OrigRetTy, const SmallVectorImpl< Register > &Args, SPIRVGlobalRegistry *GR)
SPIRVType * lowerBuiltinType(const Type *OpaqueType, SPIRV::AccessQualifier::AccessQualifier AccessQual, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
std::string lookupBuiltinNameHelper(StringRef DemangledCall)
Parses the name part of the demangled builtin call.
This is an optimization pass for GlobalISel generic memory operations.
void buildOpName(Register Target, const StringRef &Name, MachineIRBuilder &MIRBuilder)
unsigned storageClassToAddressSpace(SPIRV::StorageClass::StorageClass SC)
static bool generateGetQueryInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static bool generateLoadStoreInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static Register buildConstantIntReg(uint64_t Val, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR, unsigned BitWidth=32)
static bool generateConstructInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static bool buildAtomicFlagInst(const SPIRV::IncomingCall *Call, unsigned Opcode, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
Helper function for building atomic flag instructions (e.g.
static Register buildBuiltinVariableLoad(MachineIRBuilder &MIRBuilder, SPIRVType *VariableType, SPIRVGlobalRegistry *GR, SPIRV::BuiltIn::BuiltIn BuiltinValue, LLT LLType, Register Reg=Register(0), bool isConst=true, bool hasLinkageTy=true)
Helper function for building a load instruction for loading a builtin global variable of BuiltinValue...
static bool generateImageSizeQueryInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static SPIRV::SamplerFilterMode::SamplerFilterMode getSamplerFilterModeFromBitmask(unsigned Bitmask)
static bool buildAtomicStoreInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
Helper function for building an atomic store instruction.
void addNumImm(const APInt &Imm, MachineInstrBuilder &MIB)
static const Type * getBlockStructType(Register ParamReg, MachineRegisterInfo *MRI)
static bool generateGroupInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static unsigned getNumComponentsForDim(SPIRV::Dim::Dim dim)
Register insertAssignInstr(Register Reg, Type *Ty, SPIRVType *SpirvTy, SPIRVGlobalRegistry *GR, MachineIRBuilder &MIB, MachineRegisterInfo &MRI)
Helper external function for inserting ASSIGN_TYPE instuction between Reg and its definition,...
static Register buildScopeReg(Register CLScopeRegister, SPIRV::Scope::Scope Scope, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR, MachineRegisterInfo *MRI)
static std::tuple< Register, SPIRVType * > buildBoolRegister(MachineIRBuilder &MIRBuilder, const SPIRVType *ResultType, SPIRVGlobalRegistry *GR)
Helper function building either a resulting scalar or vector bool register depending on the expected ...
static unsigned getNumSizeComponents(SPIRVType *imgType)
Helper function for obtaining the number of size components.
uint64_t getIConstVal(Register ConstReg, const MachineRegisterInfo *MRI)
static SPIRVType * getSampledImageType(const TargetExtType *OpaqueType, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
SPIRV::MemorySemantics::MemorySemantics getMemSemanticsForStorageClass(SPIRV::StorageClass::StorageClass SC)
static bool generateDotOrFMulInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static bool generateSampleImageInst(const StringRef DemangledCall, const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static bool generateBarrierInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static SPIRVType * getCoopMatrType(const TargetExtType *ExtensionType, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static bool generateKernelClockInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static bool generateGroupUniformInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static bool generateWaveInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static SPIRVType * getImageType(const TargetExtType *ExtensionType, const SPIRV::AccessQualifier::AccessQualifier Qualifier, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
void buildOpDecorate(Register Reg, MachineIRBuilder &MIRBuilder, SPIRV::Decoration::Decoration Dec, const std::vector< uint32_t > &DecArgs, StringRef StrImm)
static bool buildBarrierInst(const SPIRV::IncomingCall *Call, unsigned Opcode, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
Helper function for building barriers, i.e., memory/control ordering operations.
static bool generateAsyncCopy(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static SPIRV::Scope::Scope getSPIRVScope(SPIRV::CLMemoryScope ClScope)
static SPIRVType * getSamplerType(MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static Register buildLoadInst(SPIRVType *BaseType, Register PtrRegister, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR, LLT LowLevelType, Register DestinationReg=Register(0))
Helper function for building a load instruction loading into the DestinationReg.
static bool generateEnqueueInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
static bool buildSelectInst(MachineIRBuilder &MIRBuilder, Register ReturnRegister, Register SourceRegister, const SPIRVType *ReturnType, SPIRVGlobalRegistry *GR)
Helper function for building either a vector or scalar select instruction depending on the expected R...
static const Type * getMachineInstrType(MachineInstr *MI)
static SPIRV::SamplerAddressingMode::SamplerAddressingMode getSamplerAddressingModeFromBitmask(unsigned Bitmask)
static bool generateAtomicInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static bool generateConvertInst(const StringRef DemangledCall, const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static Register buildMemSemanticsReg(Register SemanticsRegister, Register PtrRegister, unsigned &Semantics, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static unsigned getConstFromIntrinsic(Register Reg, MachineRegisterInfo *MRI)
static bool generateImageMiscQueryInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static bool generateSelectInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder)
static bool buildAtomicLoadInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
Helper function for building an atomic load instruction.
static bool generateIntelSubgroupsInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static bool generateSpecConstantInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static SPIRVType * getOrCreateSPIRVDeviceEventPointer(MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
Type * parseBasicTypeName(StringRef &TypeName, LLVMContext &Ctx)
static bool generateVectorLoadStoreInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static bool genWorkgroupQuery(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR, SPIRV::BuiltIn::BuiltIn BuiltinValue, uint64_t DefaultValue)
static bool generateCoopMatrInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static std::unique_ptr< const SPIRV::IncomingCall > lookupBuiltin(StringRef DemangledCall, SPIRV::InstructionSet::InstructionSet Set, Register ReturnRegister, const SPIRVType *ReturnType, const SmallVectorImpl< Register > &Arguments)
Looks up the demangled builtin call in the SPIRVBuiltins.td records using the provided DemangledCall ...
static bool buildAtomicFloatingRMWInst(const SPIRV::IncomingCall *Call, unsigned Opcode, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
Helper function for building an atomic floating-type instruction.
MachineInstr * getDefInstrMaybeConstant(Register &ConstReg, const MachineRegisterInfo *MRI)
constexpr unsigned BitWidth
const MachineInstr SPIRVType
static bool generateReadImageInst(const StringRef DemangledCall, const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
bool hasBuiltinTypePrefix(StringRef Name)
static bool buildEnqueueKernel(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
Type * getMDOperandAsType(const MDNode *N, unsigned I)
static bool buildAtomicRMWInst(const SPIRV::IncomingCall *Call, unsigned Opcode, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
Helper function for building atomic instructions.
static SPIRV::MemorySemantics::MemorySemantics getSPIRVMemSemantics(std::memory_order MemOrder)
static bool generateRelationalInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static bool buildAtomicInitInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder)
Helper function for translating atomic init to OpStore.
static bool generateWriteImageInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static SPIRVType * getPipeType(const TargetExtType *ExtensionType, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static Type * parseTypeString(const StringRef Name, LLVMContext &Context)
bool isSpvIntrinsic(const MachineInstr &MI, Intrinsic::ID IntrinsicID)
static bool generateCastToPtrInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder)
static bool generateAtomicFloatingInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static bool generateExtInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static bool buildNDRange(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static SPIRVType * getNonParameterizedType(const TargetExtType *ExtensionType, const SPIRV::BuiltinType *TypeRecord, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static MachineInstr * getBlockStructInstr(Register ParamReg, MachineRegisterInfo *MRI)
static bool buildOpFromWrapper(MachineIRBuilder &MIRBuilder, unsigned Opcode, const SPIRV::IncomingCall *Call, Register TypeReg, ArrayRef< uint32_t > ImmArgs={})
static unsigned getSamplerParamFromBitmask(unsigned Bitmask)
static bool buildAtomicCompareExchangeInst(const SPIRV::IncomingCall *Call, const SPIRV::DemangledBuiltin *Builtin, unsigned Opcode, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
Helper function for building an atomic compare-exchange instruction.
std::string getLinkStringForBuiltIn(SPIRV::BuiltIn::BuiltIn BuiltInValue)
static bool generateBuiltinVar(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static const fltSemantics & IEEEsingle() LLVM_READNONE
This struct is a compact representation of a valid (non-zero power of two) alignment.
This class contains a discriminated union of information about pointers in memory operands,...
FPRoundingMode::FPRoundingMode RoundingMode
InstructionSet::InstructionSet Set
InstructionSet::InstructionSet Set
InstructionSet::InstructionSet Set
InstructionSet::InstructionSet Set
const SmallVectorImpl< Register > & Arguments
const std::string BuiltinName
const SPIRVType * ReturnType
const Register ReturnRegister
const DemangledBuiltin * Builtin
IncomingCall(const std::string BuiltinName, const DemangledBuiltin *Builtin, const Register ReturnRegister, const SPIRVType *ReturnType, const SmallVectorImpl< Register > &Arguments)
InstructionSet::InstructionSet Set
StringRef SpirvTypeLiteral
InstructionSet::InstructionSet Set
FPRoundingMode::FPRoundingMode RoundingMode