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::IDRegClass);
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::IDRegClass);
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::IDRegClass);
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::IDRegClass);
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::IDRegClass);
690 MRI->setRegClass(ExpectedArg, &SPIRV::IDRegClass);
691 MRI->setRegClass(Desired, &SPIRV::IDRegClass);
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::IDRegClass);
733 MRI->setRegClass(Call->Arguments[4], &SPIRV::IDRegClass);
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::IDRegClass);
760 Register Tmp = !IsCmpxchg ?
MRI->createGenericVirtualRegister(DesiredLLT)
761 : Call->ReturnRegister;
762 if (!
MRI->getRegClassOrNull(Tmp))
763 MRI->setRegClass(Tmp, &SPIRV::IDRegClass);
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::IDRegClass);
804 Call->Arguments.size() >= 3 ? Call->Arguments[2] :
Register();
806 Semantics, MIRBuilder, GR);
807 MRI->setRegClass(Call->Arguments[1], &SPIRV::IDRegClass);
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::IDRegClass);
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::IDRegClass);
854 Register ScopeReg = Call->Arguments[1];
855 MRI->setRegClass(ScopeReg, &SPIRV::IDRegClass);
857 Register MemSemanticsReg = Call->Arguments[2];
858 MRI->setRegClass(MemSemanticsReg, &SPIRV::IDRegClass);
860 Register ValueReg = Call->Arguments[3];
861 MRI->setRegClass(ValueReg, &SPIRV::IDRegClass);
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::IDRegClass);
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::IDRegClass);
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::IDRegClass);
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::IDRegClass);
1094 Register ConstRegister = Call->Arguments[0];
1096 (void)ArgInstruction;
1098 assert(ArgInstruction->getOpcode() == TargetOpcode::G_CONSTANT &&
1099 "Only constant bool value args are supported");
1106 Register GroupResultRegister = Call->ReturnRegister;
1107 SPIRVType *GroupResultType = Call->ReturnType;
1111 const bool HasBoolReturnTy =
1116 if (HasBoolReturnTy)
1117 std::tie(GroupResultRegister, GroupResultType) =
1120 auto Scope = Builtin->
Name.
starts_with(
"sub_group") ? SPIRV::Scope::Subgroup
1121 : SPIRV::Scope::Workgroup;
1126 .
addDef(GroupResultRegister)
1132 if (Call->Arguments.size() > 0) {
1134 MRI->setRegClass(Call->Arguments[0], &SPIRV::IDRegClass);
1135 for (
unsigned i = 1; i < Call->Arguments.size(); i++) {
1136 MIB.addUse(Call->Arguments[i]);
1137 MRI->setRegClass(Call->Arguments[i], &SPIRV::IDRegClass);
1142 if (HasBoolReturnTy)
1143 buildSelectInst(MIRBuilder, Call->ReturnRegister, GroupResultRegister,
1144 Call->ReturnType, GR);
1154 if (!ST->canUseExtension(SPIRV::Extension::SPV_INTEL_subgroups)) {
1155 std::string DiagMsg = std::string(Builtin->
Name) +
1156 ": the builtin requires the following SPIR-V "
1157 "extension: SPV_INTEL_subgroups";
1161 SPIRV::lookupIntelSubgroupsBuiltin(Builtin->
Name);
1164 if (Call->isSpirvOp()) {
1165 bool IsSet = OpCode != SPIRV::OpSubgroupBlockWriteINTEL &&
1166 OpCode != SPIRV::OpSubgroupImageBlockWriteINTEL;
1173 if (IntelSubgroups->
IsBlock) {
1176 if (Arg0Type->getOpcode() == SPIRV::OpTypeImage) {
1182 case SPIRV::OpSubgroupBlockReadINTEL:
1183 OpCode = SPIRV::OpSubgroupImageBlockReadINTEL;
1185 case SPIRV::OpSubgroupBlockWriteINTEL:
1186 OpCode = SPIRV::OpSubgroupImageBlockWriteINTEL;
1207 .
addDef(Call->ReturnRegister)
1209 for (
size_t i = 0; i < Call->Arguments.size(); ++i) {
1210 MIB.
addUse(Call->Arguments[i]);
1211 MRI->setRegClass(Call->Arguments[i], &SPIRV::IDRegClass);
1223 if (!ST->canUseExtension(
1224 SPIRV::Extension::SPV_KHR_uniform_group_instructions)) {
1225 std::string DiagMsg = std::string(Builtin->
Name) +
1226 ": the builtin requires the following SPIR-V "
1227 "extension: SPV_KHR_uniform_group_instructions";
1231 SPIRV::lookupGroupUniformBuiltin(Builtin->
Name);
1234 Register GroupResultReg = Call->ReturnRegister;
1235 MRI->setRegClass(GroupResultReg, &SPIRV::IDRegClass);
1238 Register ScopeReg = Call->Arguments[0];
1239 MRI->setRegClass(ScopeReg, &SPIRV::IDRegClass);
1242 Register ConstGroupOpReg = Call->Arguments[1];
1244 if (!Const || Const->getOpcode() != TargetOpcode::G_CONSTANT)
1246 "expect a constant group operation for a uniform group instruction",
1249 if (!ConstOperand.
isCImm())
1255 Register ValueReg = Call->Arguments[2];
1256 MRI->setRegClass(ValueReg, &SPIRV::IDRegClass);
1263 MIB.addUse(ValueReg);
1274 if (!ST->canUseExtension(SPIRV::Extension::SPV_KHR_shader_clock)) {
1275 std::string DiagMsg = std::string(Builtin->
Name) +
1276 ": the builtin requires the following SPIR-V "
1277 "extension: SPV_KHR_shader_clock";
1282 Register ResultReg = Call->ReturnRegister;
1283 MRI->setRegClass(ResultReg, &SPIRV::IDRegClass);
1286 SPIRV::Scope::Scope ScopeArg =
1288 .
EndsWith(
"device", SPIRV::Scope::Scope::Device)
1289 .
EndsWith(
"work_group", SPIRV::Scope::Scope::Workgroup)
1290 .
EndsWith(
"sub_group", SPIRV::Scope::Scope::Subgroup);
1330 SPIRV::BuiltIn::BuiltIn BuiltinValue,
1332 Register IndexRegister = Call->Arguments[0];
1333 const unsigned ResultWidth = Call->ReturnType->getOperand(1).getImm();
1341 Register ToTruncate = Call->ReturnRegister;
1344 bool IsConstantIndex =
1345 IndexInstruction->getOpcode() == TargetOpcode::G_CONSTANT;
1350 Register DefaultReg = Call->ReturnRegister;
1351 if (PointerSize != ResultWidth) {
1352 DefaultReg =
MRI->createGenericVirtualRegister(
LLT::scalar(PointerSize));
1353 MRI->setRegClass(DefaultReg, &SPIRV::IDRegClass);
1355 MIRBuilder.
getMF());
1356 ToTruncate = DefaultReg;
1360 MIRBuilder.
buildCopy(DefaultReg, NewRegister);
1368 Register Extracted = Call->ReturnRegister;
1369 if (!IsConstantIndex || PointerSize != ResultWidth) {
1370 Extracted =
MRI->createGenericVirtualRegister(
LLT::scalar(PointerSize));
1371 MRI->setRegClass(Extracted, &SPIRV::IDRegClass);
1378 ExtractInst.
addUse(LoadedVector).
addUse(IndexRegister);
1381 if (!IsConstantIndex) {
1390 MRI->setRegClass(CompareRegister, &SPIRV::IDRegClass);
1403 Register SelectionResult = Call->ReturnRegister;
1404 if (PointerSize != ResultWidth) {
1407 MRI->setRegClass(SelectionResult, &SPIRV::IDRegClass);
1409 MIRBuilder.
getMF());
1412 MIRBuilder.
buildSelect(SelectionResult, CompareRegister, Extracted,
1414 ToTruncate = SelectionResult;
1416 ToTruncate = Extracted;
1420 if (PointerSize != ResultWidth)
1430 SPIRV::BuiltIn::BuiltIn
Value =
1431 SPIRV::lookupGetBuiltin(Builtin->
Name, Builtin->
Set)->
Value;
1433 if (
Value == SPIRV::BuiltIn::GlobalInvocationId)
1439 if (Call->ReturnType->getOpcode() == SPIRV::OpTypeVector)
1446 LLType, Call->ReturnRegister);
1455 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
1458 case SPIRV::OpStore:
1460 case SPIRV::OpAtomicLoad:
1462 case SPIRV::OpAtomicStore:
1464 case SPIRV::OpAtomicCompareExchange:
1465 case SPIRV::OpAtomicCompareExchangeWeak:
1468 case SPIRV::OpAtomicIAdd:
1469 case SPIRV::OpAtomicISub:
1470 case SPIRV::OpAtomicOr:
1471 case SPIRV::OpAtomicXor:
1472 case SPIRV::OpAtomicAnd:
1473 case SPIRV::OpAtomicExchange:
1475 case SPIRV::OpMemoryBarrier:
1477 case SPIRV::OpAtomicFlagTestAndSet:
1478 case SPIRV::OpAtomicFlagClear:
1481 if (Call->isSpirvOp())
1493 unsigned Opcode = SPIRV::lookupAtomicFloatingBuiltin(Builtin->
Name)->Opcode;
1496 case SPIRV::OpAtomicFAddEXT:
1497 case SPIRV::OpAtomicFMinEXT:
1498 case SPIRV::OpAtomicFMaxEXT:
1511 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
1518 MIRBuilder.
buildInstr(TargetOpcode::G_ADDRSPACE_CAST)
1519 .
addDef(Call->ReturnRegister)
1520 .
addUse(Call->Arguments[0]);
1527 if (Call->isSpirvOp())
1531 bool IsVec = Opcode == SPIRV::OpTypeVector;
1533 MIRBuilder.
buildInstr(IsVec ? SPIRV::OpDot : SPIRV::OpFMulS)
1534 .
addDef(Call->ReturnRegister)
1536 .
addUse(Call->Arguments[0])
1537 .
addUse(Call->Arguments[1]);
1545 SPIRV::BuiltIn::BuiltIn
Value =
1546 SPIRV::lookupGetBuiltin(Builtin->
Name, Builtin->
Set)->
Value;
1549 assert(Call->ReturnType->getOpcode() == SPIRV::OpTypeInt);
1553 MIRBuilder, Call->ReturnType, GR,
Value, LLType, Call->ReturnRegister,
1561 SPIRV::BuiltIn::BuiltIn
Value =
1562 SPIRV::lookupGetBuiltin(Call->Builtin->Name, Call->Builtin->Set)->
Value;
1563 uint64_t IsDefault = (
Value == SPIRV::BuiltIn::GlobalSize ||
1564 Value == SPIRV::BuiltIn::WorkgroupSize ||
1565 Value == SPIRV::BuiltIn::EnqueuedWorkgroupSize);
1575 SPIRV::lookupImageQueryBuiltin(Builtin->
Name, Builtin->
Set)->Component;
1580 unsigned NumExpectedRetComponents =
RetTy->getOpcode() == SPIRV::OpTypeVector
1581 ?
RetTy->getOperand(2).getImm()
1586 Register QueryResult = Call->ReturnRegister;
1587 SPIRVType *QueryResultType = Call->ReturnType;
1588 if (NumExpectedRetComponents != NumActualRetComponents) {
1594 IntTy, NumActualRetComponents, MIRBuilder);
1599 IsDimBuf ? SPIRV::OpImageQuerySize : SPIRV::OpImageQuerySizeLod;
1604 .
addUse(Call->Arguments[0]);
1607 if (NumExpectedRetComponents == NumActualRetComponents)
1609 if (NumExpectedRetComponents == 1) {
1611 unsigned ExtractedComposite =
1612 Component == 3 ? NumActualRetComponents - 1 : Component;
1613 assert(ExtractedComposite < NumActualRetComponents &&
1614 "Invalid composite index!");
1617 if (QueryResultType->
getOpcode() == SPIRV::OpTypeVector) {
1619 if (TypeReg != NewTypeReg &&
1621 TypeReg = NewTypeReg;
1623 MIRBuilder.
buildInstr(SPIRV::OpCompositeExtract)
1624 .
addDef(Call->ReturnRegister)
1627 .
addImm(ExtractedComposite);
1628 if (NewType !=
nullptr)
1633 auto MIB = MIRBuilder.
buildInstr(SPIRV::OpVectorShuffle)
1634 .
addDef(Call->ReturnRegister)
1638 for (
unsigned i = 0; i < NumExpectedRetComponents; ++i)
1639 MIB.
addImm(i < NumActualRetComponents ? i : 0xffffffff);
1647 assert(Call->ReturnType->getOpcode() == SPIRV::OpTypeInt &&
1648 "Image samples query result must be of int type!");
1653 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
1655 Register Image = Call->Arguments[0];
1657 SPIRV::Dim::Dim ImageDimensionality =
static_cast<SPIRV::Dim::Dim
>(
1659 (void)ImageDimensionality;
1662 case SPIRV::OpImageQuerySamples:
1663 assert(ImageDimensionality == SPIRV::Dim::DIM_2D &&
1664 "Image must be of 2D dimensionality");
1666 case SPIRV::OpImageQueryLevels:
1667 assert((ImageDimensionality == SPIRV::Dim::DIM_1D ||
1668 ImageDimensionality == SPIRV::Dim::DIM_2D ||
1669 ImageDimensionality == SPIRV::Dim::DIM_3D ||
1670 ImageDimensionality == SPIRV::Dim::DIM_Cube) &&
1671 "Image must be of 1D/2D/3D/Cube dimensionality");
1676 .
addDef(Call->ReturnRegister)
1683static SPIRV::SamplerAddressingMode::SamplerAddressingMode
1685 switch (Bitmask & SPIRV::CLK_ADDRESS_MODE_MASK) {
1686 case SPIRV::CLK_ADDRESS_CLAMP:
1687 return SPIRV::SamplerAddressingMode::Clamp;
1688 case SPIRV::CLK_ADDRESS_CLAMP_TO_EDGE:
1689 return SPIRV::SamplerAddressingMode::ClampToEdge;
1690 case SPIRV::CLK_ADDRESS_REPEAT:
1691 return SPIRV::SamplerAddressingMode::Repeat;
1692 case SPIRV::CLK_ADDRESS_MIRRORED_REPEAT:
1693 return SPIRV::SamplerAddressingMode::RepeatMirrored;
1694 case SPIRV::CLK_ADDRESS_NONE:
1695 return SPIRV::SamplerAddressingMode::None;
1702 return (Bitmask & SPIRV::CLK_NORMALIZED_COORDS_TRUE) ? 1 : 0;
1705static SPIRV::SamplerFilterMode::SamplerFilterMode
1707 if (Bitmask & SPIRV::CLK_FILTER_LINEAR)
1708 return SPIRV::SamplerFilterMode::Linear;
1709 if (Bitmask & SPIRV::CLK_FILTER_NEAREST)
1710 return SPIRV::SamplerFilterMode::Nearest;
1711 return SPIRV::SamplerFilterMode::Nearest;
1718 Register Image = Call->Arguments[0];
1720 MRI->setRegClass(Image, &SPIRV::IDRegClass);
1721 MRI->setRegClass(Call->Arguments[1], &SPIRV::IDRegClass);
1724 if (HasOclSampler || HasMsaa)
1725 MRI->setRegClass(Call->Arguments[2], &SPIRV::IDRegClass);
1726 if (HasOclSampler) {
1727 Register Sampler = Call->Arguments[1];
1741 Register SampledImage =
MRI->createVirtualRegister(&SPIRV::IDRegClass);
1752 bool NeedsExtraction =
false;
1753 if (TempType->
getOpcode() != SPIRV::OpTypeVector) {
1756 NeedsExtraction =
true;
1759 Register TempRegister =
MRI->createGenericVirtualRegister(LLType);
1760 MRI->setRegClass(TempRegister, &SPIRV::IDRegClass);
1763 MIRBuilder.
buildInstr(SPIRV::OpImageSampleExplicitLod)
1764 .
addDef(NeedsExtraction ? TempRegister : Call->ReturnRegister)
1767 .
addUse(Call->Arguments[2])
1768 .
addImm(SPIRV::ImageOperand::Lod)
1771 if (NeedsExtraction)
1772 MIRBuilder.
buildInstr(SPIRV::OpCompositeExtract)
1773 .
addDef(Call->ReturnRegister)
1777 }
else if (HasMsaa) {
1779 .
addDef(Call->ReturnRegister)
1782 .
addUse(Call->Arguments[1])
1783 .
addImm(SPIRV::ImageOperand::Sample)
1784 .
addUse(Call->Arguments[2]);
1787 .
addDef(Call->ReturnRegister)
1790 .
addUse(Call->Arguments[1]);
1802 .
addUse(Call->Arguments[0])
1803 .
addUse(Call->Arguments[1])
1804 .
addUse(Call->Arguments[2]);
1813 if (Call->Builtin->Name.contains_insensitive(
1814 "__translate_sampler_initializer")) {
1821 return Sampler.isValid();
1822 }
else if (Call->Builtin->Name.contains_insensitive(
"__spirv_SampledImage")) {
1824 Register Image = Call->Arguments[0];
1829 Call->ReturnRegister.isValid()
1830 ? Call->ReturnRegister
1831 :
MRI->createVirtualRegister(&SPIRV::IDRegClass);
1836 .
addUse(Call->Arguments[1]);
1838 }
else if (Call->Builtin->Name.contains_insensitive(
1839 "__spirv_ImageSampleExplicitLod")) {
1841 std::string ReturnType = DemangledCall.
str();
1842 if (DemangledCall.
contains(
"_R")) {
1843 ReturnType = ReturnType.substr(ReturnType.find(
"_R") + 2);
1844 ReturnType = ReturnType.substr(0, ReturnType.find(
'('));
1851 std::string DiagMsg =
1852 "Unable to recognize SPIRV type name: " + ReturnType;
1855 MRI->setRegClass(Call->Arguments[0], &SPIRV::IDRegClass);
1856 MRI->setRegClass(Call->Arguments[1], &SPIRV::IDRegClass);
1857 MRI->setRegClass(Call->Arguments[3], &SPIRV::IDRegClass);
1859 MIRBuilder.
buildInstr(SPIRV::OpImageSampleExplicitLod)
1860 .
addDef(Call->ReturnRegister)
1862 .
addUse(Call->Arguments[0])
1863 .
addUse(Call->Arguments[1])
1864 .
addImm(SPIRV::ImageOperand::Lod)
1865 .
addUse(Call->Arguments[3]);
1873 MIRBuilder.
buildSelect(Call->ReturnRegister, Call->Arguments[0],
1874 Call->Arguments[1], Call->Arguments[2]);
1890 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
1891 bool IsSet = Opcode != SPIRV::OpCooperativeMatrixStoreKHR;
1892 unsigned ArgSz = Call->Arguments.size();
1893 unsigned LiteralIdx = 0;
1894 if (Opcode == SPIRV::OpCooperativeMatrixLoadKHR && ArgSz > 3)
1896 else if (Opcode == SPIRV::OpCooperativeMatrixStoreKHR && ArgSz > 4)
1903 if (Opcode == SPIRV::OpCooperativeMatrixLengthKHR) {
1908 .
addDef(Call->ReturnRegister)
1914 IsSet ? TypeReg :
Register(0), ImmArgs);
1923 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
1927 case SPIRV::OpSpecConstant: {
1931 buildOpDecorate(Call->ReturnRegister, MIRBuilder, SPIRV::Decoration::SpecId,
1934 Register ConstRegister = Call->Arguments[1];
1937 (Const->getOpcode() == TargetOpcode::G_CONSTANT ||
1938 Const->getOpcode() == TargetOpcode::G_FCONSTANT) &&
1939 "Argument should be either an int or floating-point constant");
1942 if (Call->ReturnType->getOpcode() == SPIRV::OpTypeBool) {
1943 assert(ConstOperand.
isCImm() &&
"Int constant operand is expected");
1945 ? SPIRV::OpSpecConstantTrue
1946 : SPIRV::OpSpecConstantFalse;
1949 .
addDef(Call->ReturnRegister)
1952 if (Call->ReturnType->getOpcode() != SPIRV::OpTypeBool) {
1953 if (Const->getOpcode() == TargetOpcode::G_CONSTANT)
1960 case SPIRV::OpSpecConstantComposite: {
1962 .
addDef(Call->ReturnRegister)
1964 for (
unsigned i = 0; i < Call->Arguments.size(); i++)
1965 MIB.
addUse(Call->Arguments[i]);
1977 MRI->setRegClass(Call->Arguments[0], &SPIRV::IDRegClass);
1984 Register TmpReg =
MRI->createVirtualRegister(&SPIRV::IDRegClass);
1988 unsigned NumArgs = Call->Arguments.size();
1990 Register GlobalWorkSize = Call->Arguments[NumArgs < 4 ? 1 : 2];
1991 MRI->setRegClass(GlobalWorkSize, &SPIRV::IDRegClass);
1993 NumArgs == 2 ?
Register(0) : Call->Arguments[NumArgs < 4 ? 2 : 3];
1995 MRI->setRegClass(LocalWorkSize, &SPIRV::IDRegClass);
1996 Register GlobalWorkOffset = NumArgs <= 3 ?
Register(0) : Call->Arguments[1];
1997 if (GlobalWorkOffset.
isValid())
1998 MRI->setRegClass(GlobalWorkOffset, &SPIRV::IDRegClass);
2002 if (SpvTy->
getOpcode() == SPIRV::OpTypePointer) {
2007 if (!
MRI->getRegClassOrNull(GWSPtr))
2008 MRI->setRegClass(GWSPtr, &SPIRV::IDRegClass);
2010 unsigned Size = Call->Builtin->Name ==
"ndrange_3D" ? 3 : 2;
2015 GlobalWorkSize =
MRI->createVirtualRegister(&SPIRV::IDRegClass);
2024 SpvFieldTy, *ST.getInstrInfo());
2029 LocalWorkSize = Const;
2030 if (!GlobalWorkOffset.
isValid())
2031 GlobalWorkOffset = Const;
2039 .
addUse(GlobalWorkOffset);
2041 .
addUse(Call->Arguments[0])
2066 bool IsSpirvOp = Call->isSpirvOp();
2067 bool HasEvents = Call->Builtin->Name.contains(
"events") || IsSpirvOp;
2074 if (Call->Builtin->Name.contains(
"_varargs") || IsSpirvOp) {
2075 const unsigned LocalSizeArrayIdx = HasEvents ? 9 : 6;
2076 Register GepReg = Call->Arguments[LocalSizeArrayIdx];
2083 assert(LocalSizeTy &&
"Local size type is expected");
2085 cast<ArrayType>(LocalSizeTy)->getNumElements();
2089 Int32Ty, MIRBuilder, SPIRV::StorageClass::Function);
2090 for (
unsigned I = 0;
I < LocalSizeNum; ++
I) {
2092 MRI->setType(
Reg, LLType);
2106 auto MIB = MIRBuilder.
buildInstr(SPIRV::OpEnqueueKernel)
2107 .
addDef(Call->ReturnRegister)
2111 const unsigned BlockFIdx = HasEvents ? 6 : 3;
2112 for (
unsigned i = 0; i < BlockFIdx; i++)
2113 MIB.addUse(Call->Arguments[i]);
2120 MIB.addUse(NullPtr);
2121 MIB.addUse(NullPtr);
2129 Register BlockLiteralReg = Call->Arguments[BlockFIdx + 1];
2131 MIB.addUse(BlockLiteralReg);
2141 for (
unsigned i = 0; i < LocalSizes.
size(); i++)
2142 MIB.addUse(LocalSizes[i]);
2152 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
2155 case SPIRV::OpRetainEvent:
2156 case SPIRV::OpReleaseEvent:
2159 case SPIRV::OpCreateUserEvent:
2160 case SPIRV::OpGetDefaultQueue:
2162 .
addDef(Call->ReturnRegister)
2164 case SPIRV::OpIsValidEvent:
2167 .
addDef(Call->ReturnRegister)
2169 .
addUse(Call->Arguments[0]);
2170 case SPIRV::OpSetUserEventStatus:
2174 .
addUse(Call->Arguments[0])
2175 .
addUse(Call->Arguments[1]);
2176 case SPIRV::OpCaptureEventProfilingInfo:
2181 .
addUse(Call->Arguments[0])
2182 .
addUse(Call->Arguments[1])
2183 .
addUse(Call->Arguments[2]);
2184 case SPIRV::OpBuildNDRange:
2186 case SPIRV::OpEnqueueKernel:
2199 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
2201 bool IsSet = Opcode == SPIRV::OpGroupAsyncCopy;
2203 if (Call->isSpirvOp())
2210 case SPIRV::OpGroupAsyncCopy: {
2212 Call->ReturnType->getOpcode() == SPIRV::OpTypeEvent
2216 unsigned NumArgs = Call->Arguments.size();
2217 Register EventReg = Call->Arguments[NumArgs - 1];
2219 .
addDef(Call->ReturnRegister)
2222 .
addUse(Call->Arguments[0])
2223 .
addUse(Call->Arguments[1])
2224 .
addUse(Call->Arguments[2])
2225 .
addUse(Call->Arguments.size() > 4
2226 ? Call->Arguments[3]
2229 if (NewType !=
nullptr)
2234 case SPIRV::OpGroupWaitEvents:
2237 .
addUse(Call->Arguments[0])
2238 .
addUse(Call->Arguments[1]);
2250 SPIRV::lookupConvertBuiltin(Call->Builtin->Name, Call->Builtin->Set);
2252 if (!Builtin && Call->isSpirvOp()) {
2255 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
2262 SPIRV::Decoration::SaturatedConversion, {});
2265 SPIRV::Decoration::FPRoundingMode,
2266 {(unsigned)Builtin->RoundingMode});
2268 std::string NeedExtMsg;
2269 bool IsRightComponentsNumber =
true;
2270 unsigned Opcode = SPIRV::OpNop;
2277 : SPIRV::OpSatConvertSToU;
2280 : SPIRV::OpSConvert;
2282 SPIRV::OpTypeFloat)) {
2287 if (!ST->canUseExtension(
2288 SPIRV::Extension::SPV_INTEL_bfloat16_conversion))
2289 NeedExtMsg =
"SPV_INTEL_bfloat16_conversion";
2290 IsRightComponentsNumber =
2293 Opcode = SPIRV::OpConvertBF16ToFINTEL;
2295 bool IsSourceSigned =
2297 Opcode = IsSourceSigned ? SPIRV::OpConvertSToF : SPIRV::OpConvertUToF;
2301 SPIRV::OpTypeFloat)) {
2308 if (!ST->canUseExtension(
2309 SPIRV::Extension::SPV_INTEL_bfloat16_conversion))
2310 NeedExtMsg =
"SPV_INTEL_bfloat16_conversion";
2311 IsRightComponentsNumber =
2314 Opcode = SPIRV::OpConvertFToBF16INTEL;
2317 : SPIRV::OpConvertFToU;
2320 SPIRV::OpTypeFloat)) {
2322 Opcode = SPIRV::OpFConvert;
2326 if (!NeedExtMsg.empty()) {
2327 std::string DiagMsg = std::string(Builtin->
Name) +
2328 ": the builtin requires the following SPIR-V "
2333 if (!IsRightComponentsNumber) {
2334 std::string DiagMsg =
2335 std::string(Builtin->
Name) +
2336 ": result and argument must have the same number of components";
2339 assert(Opcode != SPIRV::OpNop &&
2340 "Conversion between the types not implemented!");
2343 .
addDef(Call->ReturnRegister)
2345 .
addUse(Call->Arguments[0]);
2354 SPIRV::lookupVectorLoadStoreBuiltin(Call->Builtin->Name,
2355 Call->Builtin->Set);
2359 .
addDef(Call->ReturnRegister)
2361 .
addImm(
static_cast<uint32_t>(SPIRV::InstructionSet::OpenCL_std))
2363 for (
auto Argument : Call->Arguments)
2381 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
2382 bool IsLoad = Opcode == SPIRV::OpLoad;
2386 MIB.
addDef(Call->ReturnRegister);
2390 MIB.
addUse(Call->Arguments[0]);
2392 MRI->setRegClass(Call->Arguments[0], &SPIRV::IDRegClass);
2395 MIB.addUse(Call->Arguments[1]);
2396 MRI->setRegClass(Call->Arguments[1], &SPIRV::IDRegClass);
2399 unsigned NumArgs = Call->Arguments.size();
2400 if ((IsLoad && NumArgs >= 2) || NumArgs >= 3) {
2402 MRI->setRegClass(Call->Arguments[IsLoad ? 1 : 2], &SPIRV::IDRegClass);
2404 if ((IsLoad && NumArgs >= 3) || NumArgs >= 4) {
2406 MRI->setRegClass(Call->Arguments[IsLoad ? 2 : 3], &SPIRV::IDRegClass);
2419std::tuple<int, unsigned, unsigned>
2421 SPIRV::InstructionSet::InstructionSet Set) {
2424 std::unique_ptr<const IncomingCall> Call =
2427 return std::make_tuple(-1, 0, 0);
2429 switch (Call->Builtin->Group) {
2430 case SPIRV::Relational:
2432 case SPIRV::Barrier:
2433 case SPIRV::CastToPtr:
2434 case SPIRV::ImageMiscQuery:
2435 case SPIRV::SpecConstant:
2436 case SPIRV::Enqueue:
2437 case SPIRV::AsyncCopy:
2438 case SPIRV::LoadStore:
2439 case SPIRV::CoopMatr:
2441 SPIRV::lookupNativeBuiltin(Call->Builtin->Name, Call->Builtin->Set))
2442 return std::make_tuple(Call->Builtin->Group, R->Opcode, 0);
2444 case SPIRV::Extended:
2445 if (
const auto *R = SPIRV::lookupExtendedBuiltin(Call->Builtin->Name,
2446 Call->Builtin->Set))
2447 return std::make_tuple(Call->Builtin->Group, 0, R->Number);
2449 case SPIRV::VectorLoadStore:
2450 if (
const auto *R = SPIRV::lookupVectorLoadStoreBuiltin(Call->Builtin->Name,
2451 Call->Builtin->Set))
2452 return std::make_tuple(SPIRV::Extended, 0, R->Number);
2455 if (
const auto *R = SPIRV::lookupGroupBuiltin(Call->Builtin->Name))
2456 return std::make_tuple(Call->Builtin->Group, R->Opcode, 0);
2458 case SPIRV::AtomicFloating:
2459 if (
const auto *R = SPIRV::lookupAtomicFloatingBuiltin(Call->Builtin->Name))
2460 return std::make_tuple(Call->Builtin->Group, R->Opcode, 0);
2462 case SPIRV::IntelSubgroups:
2463 if (
const auto *R = SPIRV::lookupIntelSubgroupsBuiltin(Call->Builtin->Name))
2464 return std::make_tuple(Call->Builtin->Group, R->Opcode, 0);
2466 case SPIRV::GroupUniform:
2467 if (
const auto *R = SPIRV::lookupGroupUniformBuiltin(Call->Builtin->Name))
2468 return std::make_tuple(Call->Builtin->Group, R->Opcode, 0);
2470 case SPIRV::WriteImage:
2471 return std::make_tuple(Call->Builtin->Group, SPIRV::OpImageWrite, 0);
2473 return std::make_tuple(Call->Builtin->Group, TargetOpcode::G_SELECT, 0);
2474 case SPIRV::Construct:
2475 return std::make_tuple(Call->Builtin->Group, SPIRV::OpCompositeConstruct,
2477 case SPIRV::KernelClock:
2478 return std::make_tuple(Call->Builtin->Group, SPIRV::OpReadClockKHR, 0);
2480 return std::make_tuple(-1, 0, 0);
2482 return std::make_tuple(-1, 0, 0);
2486 SPIRV::InstructionSet::InstructionSet Set,
2491 LLVM_DEBUG(
dbgs() <<
"Lowering builtin call: " << DemangledCall <<
"\n");
2496 if (OrigRetTy && !OrigRetTy->
isVoidTy()) {
2500 }
else if (OrigRetTy && OrigRetTy->
isVoidTy()) {
2507 std::unique_ptr<const IncomingCall> Call =
2508 lookupBuiltin(DemangledCall, Set, ReturnRegister, ReturnType, Args);
2512 return std::nullopt;
2516 assert(Args.size() >= Call->Builtin->MinNumArgs &&
2517 "Too few arguments to generate the builtin");
2518 if (Call->Builtin->MaxNumArgs && Args.size() > Call->Builtin->MaxNumArgs)
2519 LLVM_DEBUG(
dbgs() <<
"More arguments provided than required!\n");
2522 switch (Call->Builtin->Group) {
2523 case SPIRV::Extended:
2525 case SPIRV::Relational:
2529 case SPIRV::Variable:
2533 case SPIRV::AtomicFloating:
2535 case SPIRV::Barrier:
2537 case SPIRV::CastToPtr:
2543 case SPIRV::GetQuery:
2545 case SPIRV::ImageSizeQuery:
2547 case SPIRV::ImageMiscQuery:
2549 case SPIRV::ReadImage:
2551 case SPIRV::WriteImage:
2553 case SPIRV::SampleImage:
2557 case SPIRV::Construct:
2559 case SPIRV::SpecConstant:
2561 case SPIRV::Enqueue:
2563 case SPIRV::AsyncCopy:
2565 case SPIRV::Convert:
2567 case SPIRV::VectorLoadStore:
2569 case SPIRV::LoadStore:
2571 case SPIRV::IntelSubgroups:
2573 case SPIRV::GroupUniform:
2575 case SPIRV::KernelClock:
2577 case SPIRV::CoopMatr:
2587 DemangledCall.
slice(DemangledCall.
find(
'(') + 1, DemangledCall.
find(
')'));
2588 BuiltinArgs.
split(BuiltinArgsTypeStrs,
',', -1,
false);
2589 if (ArgIdx >= BuiltinArgsTypeStrs.
size())
2591 StringRef TypeStr = BuiltinArgsTypeStrs[ArgIdx].trim();
2597 [[maybe_unused]]
bool IsOCLBuiltinType = TypeStr.
consume_front(
"ocl_");
2598 assert(IsOCLBuiltinType &&
"Invalid OpenCL builtin prefix");
2615 unsigned VecElts = 0;
2626 TypeStr = TypeStr.
substr(0, TypeStr.
find(
']'));
2641#define GET_BuiltinTypes_DECL
2642#define GET_BuiltinTypes_IMPL
2649#define GET_OpenCLTypes_DECL
2650#define GET_OpenCLTypes_IMPL
2652#include "SPIRVGenTables.inc"
2660 if (
Name.starts_with(
"void"))
2662 else if (
Name.starts_with(
"int") ||
Name.starts_with(
"uint"))
2664 else if (
Name.starts_with(
"float"))
2666 else if (
Name.starts_with(
"half"))
2679 unsigned Opcode = TypeRecord->
Opcode;
2694 "Invalid number of parameters for SPIR-V pipe builtin!");
2697 SPIRV::AccessQualifier::AccessQualifier(
2705 "Invalid number of parameters for SPIR-V coop matrices builtin!");
2707 "SPIR-V coop matrices builtin type must have a type parameter!");
2712 MIRBuilder, ExtensionType, ElemType, ExtensionType->
getIntParameter(0),
2719 const SPIRV::AccessQualifier::AccessQualifier Qualifier,
2722 "SPIR-V image builtin type must have sampled type parameter!");
2726 "Invalid number of parameters for SPIR-V image builtin!");
2729 MIRBuilder, SampledType,
2734 Qualifier == SPIRV::AccessQualifier::WriteOnly
2735 ? SPIRV::AccessQualifier::WriteOnly
2736 : SPIRV::AccessQualifier::AccessQualifier(
2744 OpaqueType, SPIRV::AccessQualifier::ReadOnly, MIRBuilder, GR);
2752 StringRef NameWithParameters = TypeName;
2759 SPIRV::lookupOpenCLType(NameWithParameters);
2762 NameWithParameters);
2770 "Unknown builtin opaque type!");
2774 if (!NameWithParameters.
contains(
'_'))
2778 unsigned BaseNameLength = NameWithParameters.
find(
'_') - 1;
2779 SplitString(NameWithParameters.
substr(BaseNameLength + 1), Parameters,
"_");
2782 bool HasTypeParameter = !
isDigit(Parameters[0][0]);
2783 if (HasTypeParameter)
2786 for (
unsigned i = HasTypeParameter ? 1 : 0; i < Parameters.size(); i++) {
2787 unsigned IntParameter = 0;
2788 bool ValidLiteral = !Parameters[i].getAsInteger(10, IntParameter);
2791 "Invalid format of SPIR-V builtin parameter literal!");
2795 NameWithParameters.
substr(0, BaseNameLength),
2796 TypeParameters, IntParameters);
2800 SPIRV::AccessQualifier::AccessQualifier AccessQual,
2831 switch (TypeRecord->
Opcode) {
2832 case SPIRV::OpTypeImage:
2835 case SPIRV::OpTypePipe:
2838 case SPIRV::OpTypeDeviceEvent:
2841 case SPIRV::OpTypeSampler:
2844 case SPIRV::OpTypeSampledImage:
2847 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