20#include "llvm/IR/IntrinsicsSPIRV.h"
25#define DEBUG_TYPE "spirv-builtins"
29#define GET_BuiltinGroup_DECL
30#include "SPIRVGenTables.inc"
34 InstructionSet::InstructionSet
Set;
40#define GET_DemangledBuiltins_DECL
41#define GET_DemangledBuiltins_IMPL
63 InstructionSet::InstructionSet
Set;
67#define GET_NativeBuiltins_DECL
68#define GET_NativeBuiltins_IMPL
86#define GET_GroupBuiltins_DECL
87#define GET_GroupBuiltins_IMPL
97#define GET_IntelSubgroupsBuiltins_DECL
98#define GET_IntelSubgroupsBuiltins_IMPL
105#define GET_AtomicFloatingBuiltins_DECL
106#define GET_AtomicFloatingBuiltins_IMPL
113#define GET_GroupUniformBuiltins_DECL
114#define GET_GroupUniformBuiltins_IMPL
118 InstructionSet::InstructionSet
Set;
122using namespace BuiltIn;
123#define GET_GetBuiltins_DECL
124#define GET_GetBuiltins_IMPL
128 InstructionSet::InstructionSet
Set;
132#define GET_ImageQueryBuiltins_DECL
133#define GET_ImageQueryBuiltins_IMPL
141#define GET_IntegerDotProductBuiltins_DECL
142#define GET_IntegerDotProductBuiltins_IMPL
146 InstructionSet::InstructionSet
Set;
156 InstructionSet::InstructionSet
Set;
163using namespace FPRoundingMode;
164#define GET_ConvertBuiltins_DECL
165#define GET_ConvertBuiltins_IMPL
167using namespace InstructionSet;
168#define GET_VectorLoadStoreBuiltins_DECL
169#define GET_VectorLoadStoreBuiltins_IMPL
171#define GET_CLMemoryScope_DECL
172#define GET_CLSamplerAddressingMode_DECL
173#define GET_CLMemoryFenceFlags_DECL
174#define GET_ExtendedBuiltins_DECL
175#include "SPIRVGenTables.inc"
187 const static std::string PassPrefix =
"(anonymous namespace)::";
188 std::string BuiltinName;
191 BuiltinName = DemangledCall.
substr(PassPrefix.length());
193 BuiltinName = DemangledCall;
196 BuiltinName = BuiltinName.
substr(0, BuiltinName.find(
'('));
199 if (BuiltinName.rfind(
"__spirv_ocl_", 0) == 0)
200 BuiltinName = BuiltinName.
substr(12);
205 std::size_t Pos1 = BuiltinName.
rfind(
'<');
206 if (Pos1 != std::string::npos && BuiltinName.back() ==
'>') {
207 std::size_t Pos2 = BuiltinName.rfind(
' ', Pos1);
208 if (Pos2 == std::string::npos)
212 BuiltinName = BuiltinName.substr(Pos2, Pos1 - Pos2);
213 BuiltinName = BuiltinName.substr(BuiltinName.find_last_of(
' ') + 1);
238 static const std::regex SpvWithR(
239 "(__spirv_(ImageSampleExplicitLod|ImageRead|ImageQuerySizeLod|UDotKHR|"
240 "SDotKHR|SUDotKHR|SDotAccSatKHR|UDotAccSatKHR|SUDotAccSatKHR|"
241 "ReadClockKHR|SubgroupBlockReadINTEL|SubgroupImageBlockReadINTEL|"
242 "SubgroupImageMediaBlockReadINTEL|SubgroupImageMediaBlockWriteINTEL|"
244 "UConvert|SConvert|FConvert|SatConvert).*)_R[^_]*_?(\\w+)?.*");
246 if (std::regex_match(BuiltinName,
Match, SpvWithR) &&
Match.size() > 1) {
247 std::ssub_match SubMatch;
248 if (DecorationId &&
Match.size() > 3) {
253 BuiltinName = SubMatch.str();
270static std::unique_ptr<const SPIRV::IncomingCall>
272 SPIRV::InstructionSet::InstructionSet Set,
279 DemangledCall.
slice(DemangledCall.
find(
'(') + 1, DemangledCall.
find(
')'));
280 BuiltinArgs.
split(BuiltinArgumentTypes,
',', -1,
false);
285 if ((Builtin = SPIRV::lookupBuiltin(BuiltinName, Set)))
286 return std::make_unique<SPIRV::IncomingCall>(
287 BuiltinName, Builtin, ReturnRegister, ReturnType,
Arguments);
292 if (BuiltinArgumentTypes.
size() >= 1) {
293 char FirstArgumentType = BuiltinArgumentTypes[0][0];
298 switch (FirstArgumentType) {
301 if (Set == SPIRV::InstructionSet::OpenCL_std)
303 else if (Set == SPIRV::InstructionSet::GLSL_std_450)
311 if (Set == SPIRV::InstructionSet::OpenCL_std)
313 else if (Set == SPIRV::InstructionSet::GLSL_std_450)
320 if (Set == SPIRV::InstructionSet::OpenCL_std ||
321 Set == SPIRV::InstructionSet::GLSL_std_450)
327 if (!Prefix.empty() &&
328 (Builtin = SPIRV::lookupBuiltin(Prefix + BuiltinName, Set)))
329 return std::make_unique<SPIRV::IncomingCall>(
330 BuiltinName, Builtin, ReturnRegister, ReturnType,
Arguments);
337 switch (FirstArgumentType) {
358 if (!Suffix.empty() &&
359 (Builtin = SPIRV::lookupBuiltin(BuiltinName + Suffix, Set)))
360 return std::make_unique<SPIRV::IncomingCall>(
361 BuiltinName, Builtin, ReturnRegister, ReturnType,
Arguments);
376 assert(
MI->getOpcode() == TargetOpcode::G_ADDRSPACE_CAST &&
377 MI->getOperand(1).isReg());
378 Register BitcastReg =
MI->getOperand(1).getReg();
409 Register ValueReg =
MI->getOperand(0).getReg();
415 assert(Ty &&
"Type is expected");
427 if (
MI->getOpcode() == TargetOpcode::G_GLOBAL_VALUE)
428 return MI->getOperand(1).getGlobal()->getType();
430 "Blocks in OpenCL C must be traceable to allocation site");
442static std::tuple<Register, SPIRVType *>
448 if (ResultType->
getOpcode() == SPIRV::OpTypeVector) {
463 return std::make_tuple(ResultRegister, BoolType);
474 if (ReturnType->getOpcode() == SPIRV::OpTypeVector) {
484 return MIRBuilder.
buildSelect(ReturnRegister, SourceRegister, TrueConst,
494 if (!DestinationReg.isValid())
499 MIRBuilder.
buildLoad(DestinationReg, PtrRegister, PtrInfo,
Align());
500 return DestinationReg;
516 VariableType, MIRBuilder, SPIRV::StorageClass::Input);
522 SPIRV::StorageClass::Input,
nullptr, isConst,
523 hasLinkageTy, SPIRV::LinkageType::Import, MIRBuilder,
530 return LoadedRegister;
539 SPIRVGlobalRegistry *GR,
540 MachineIRBuilder &MIB,
541 MachineRegisterInfo &
MRI);
544static SPIRV::MemorySemantics::MemorySemantics
547 case std::memory_order_relaxed:
548 return SPIRV::MemorySemantics::None;
549 case std::memory_order_acquire:
550 return SPIRV::MemorySemantics::Acquire;
551 case std::memory_order_release:
552 return SPIRV::MemorySemantics::Release;
553 case std::memory_order_acq_rel:
554 return SPIRV::MemorySemantics::AcquireRelease;
555 case std::memory_order_seq_cst:
556 return SPIRV::MemorySemantics::SequentiallyConsistent;
564 case SPIRV::CLMemoryScope::memory_scope_work_item:
565 return SPIRV::Scope::Invocation;
566 case SPIRV::CLMemoryScope::memory_scope_work_group:
567 return SPIRV::Scope::Workgroup;
568 case SPIRV::CLMemoryScope::memory_scope_device:
569 return SPIRV::Scope::Device;
570 case SPIRV::CLMemoryScope::memory_scope_all_svm_devices:
571 return SPIRV::Scope::CrossDevice;
572 case SPIRV::CLMemoryScope::memory_scope_sub_group:
573 return SPIRV::Scope::Subgroup;
586 SPIRV::Scope::Scope Scope,
590 if (CLScopeRegister.
isValid()) {
595 if (CLScope ==
static_cast<unsigned>(Scope)) {
596 MRI->setRegClass(CLScopeRegister, &SPIRV::iIDRegClass);
597 return CLScopeRegister;
605 if (
MRI->getRegClassOrNull(
Reg))
609 SpvType ? GR->
getRegClass(SpvType) : &SPIRV::iIDRegClass);
613 Register PtrRegister,
unsigned &Semantics,
616 if (SemanticsRegister.
isValid()) {
618 std::memory_order Order =
623 if (
static_cast<unsigned>(Order) == Semantics) {
624 MRI->setRegClass(SemanticsRegister, &SPIRV::iIDRegClass);
625 return SemanticsRegister;
638 unsigned Sz = Call->Arguments.size() - ImmArgs.size();
639 for (
unsigned i = 0; i < Sz; ++i)
640 MIB.addUse(Call->Arguments[i]);
649 if (Call->isSpirvOp())
652 assert(Call->Arguments.size() == 2 &&
653 "Need 2 arguments for atomic init translation");
655 .
addUse(Call->Arguments[0])
656 .
addUse(Call->Arguments[1]);
665 if (Call->isSpirvOp())
668 Register PtrRegister = Call->Arguments[0];
673 Call->Arguments.size() > 1
677 if (Call->Arguments.size() > 2) {
679 MemSemanticsReg = Call->Arguments[2];
682 SPIRV::MemorySemantics::SequentiallyConsistent |
688 .
addDef(Call->ReturnRegister)
700 if (Call->isSpirvOp())
705 Register PtrRegister = Call->Arguments[0];
707 SPIRV::MemorySemantics::SequentiallyConsistent |
714 .
addUse(Call->Arguments[1]);
722 if (Call->isSpirvOp())
726 bool IsCmpxchg = Call->Builtin->Name.contains(
"cmpxchg");
729 Register ObjectPtr = Call->Arguments[0];
730 Register ExpectedArg = Call->Arguments[1];
731 Register Desired = Call->Arguments[2];
733 LLT DesiredLLT =
MRI->getType(Desired);
736 SPIRV::OpTypePointer);
739 assert(IsCmpxchg ? ExpectedType == SPIRV::OpTypeInt
740 : ExpectedType == SPIRV::OpTypePointer);
745 auto StorageClass =
static_cast<SPIRV::StorageClass::StorageClass
>(
753 ? SPIRV::MemorySemantics::None
754 : SPIRV::MemorySemantics::SequentiallyConsistent | MemSemStorage;
757 ? SPIRV::MemorySemantics::None
758 : SPIRV::MemorySemantics::SequentiallyConsistent | MemSemStorage;
759 if (Call->Arguments.size() >= 4) {
760 assert(Call->Arguments.size() >= 5 &&
761 "Need 5+ args for explicit atomic cmpxchg");
768 if (
static_cast<unsigned>(MemOrdEq) == MemSemEqual)
769 MemSemEqualReg = Call->Arguments[3];
770 if (
static_cast<unsigned>(MemOrdNeq) == MemSemEqual)
771 MemSemUnequalReg = Call->Arguments[4];
775 if (!MemSemUnequalReg.
isValid())
779 auto Scope = IsCmpxchg ? SPIRV::Scope::Workgroup : SPIRV::Scope::Device;
780 if (Call->Arguments.size() >= 6) {
781 assert(Call->Arguments.size() == 6 &&
782 "Extra args for explicit atomic cmpxchg");
783 auto ClScope =
static_cast<SPIRV::CLMemoryScope
>(
786 if (ClScope ==
static_cast<unsigned>(Scope))
787 ScopeReg = Call->Arguments[5];
797 Register Tmp = !IsCmpxchg ?
MRI->createGenericVirtualRegister(DesiredLLT)
798 : Call->ReturnRegister;
799 if (!
MRI->getRegClassOrNull(Tmp))
824 if (Call->isSpirvOp())
830 Call->Arguments.size() >= 4 ? Call->Arguments[3] :
Register();
832 assert(Call->Arguments.size() <= 4 &&
833 "Too many args for explicit atomic RMW");
834 ScopeRegister =
buildScopeReg(ScopeRegister, SPIRV::Scope::Workgroup,
835 MIRBuilder, GR,
MRI);
837 Register PtrRegister = Call->Arguments[0];
838 unsigned Semantics = SPIRV::MemorySemantics::None;
840 Call->Arguments.size() >= 3 ? Call->Arguments[2] :
Register();
842 Semantics, MIRBuilder, GR);
843 Register ValueReg = Call->Arguments[1];
846 if (Call->ReturnType->getOpcode() == SPIRV::OpTypeFloat) {
847 if (Opcode == SPIRV::OpAtomicIAdd) {
848 Opcode = SPIRV::OpAtomicFAddEXT;
849 }
else if (Opcode == SPIRV::OpAtomicISub) {
852 Opcode = SPIRV::OpAtomicFAddEXT;
854 MRI->createGenericVirtualRegister(
MRI->getType(ValueReg));
863 ValueReg = NegValueReg;
867 .
addDef(Call->ReturnRegister)
881 assert(Call->Arguments.size() == 4 &&
882 "Wrong number of atomic floating-type builtin");
883 Register PtrReg = Call->Arguments[0];
884 Register ScopeReg = Call->Arguments[1];
885 Register MemSemanticsReg = Call->Arguments[2];
886 Register ValueReg = Call->Arguments[3];
888 .
addDef(Call->ReturnRegister)
902 bool IsSet = Opcode == SPIRV::OpAtomicFlagTestAndSet;
904 if (Call->isSpirvOp())
909 Register PtrRegister = Call->Arguments[0];
910 unsigned Semantics = SPIRV::MemorySemantics::SequentiallyConsistent;
912 Call->Arguments.size() >= 2 ? Call->Arguments[1] :
Register();
914 Semantics, MIRBuilder, GR);
916 assert((Opcode != SPIRV::OpAtomicFlagClear ||
917 (Semantics != SPIRV::MemorySemantics::Acquire &&
918 Semantics != SPIRV::MemorySemantics::AcquireRelease)) &&
919 "Invalid memory order argument!");
922 Call->Arguments.size() >= 3 ? Call->Arguments[2] :
Register();
942 if ((Opcode == SPIRV::OpControlBarrierArriveINTEL ||
943 Opcode == SPIRV::OpControlBarrierWaitINTEL) &&
944 !ST->canUseExtension(SPIRV::Extension::SPV_INTEL_split_barrier)) {
945 std::string DiagMsg = std::string(Builtin->
Name) +
946 ": the builtin requires the following SPIR-V "
947 "extension: SPV_INTEL_split_barrier";
951 if (Call->isSpirvOp())
956 unsigned MemSemantics = SPIRV::MemorySemantics::None;
958 if (MemFlags & SPIRV::CLK_LOCAL_MEM_FENCE)
959 MemSemantics |= SPIRV::MemorySemantics::WorkgroupMemory;
961 if (MemFlags & SPIRV::CLK_GLOBAL_MEM_FENCE)
962 MemSemantics |= SPIRV::MemorySemantics::CrossWorkgroupMemory;
964 if (MemFlags & SPIRV::CLK_IMAGE_MEM_FENCE)
965 MemSemantics |= SPIRV::MemorySemantics::ImageMemory;
967 if (Opcode == SPIRV::OpMemoryBarrier)
971 else if (Opcode == SPIRV::OpControlBarrierArriveINTEL)
972 MemSemantics |= SPIRV::MemorySemantics::Release;
973 else if (Opcode == SPIRV::OpControlBarrierWaitINTEL)
974 MemSemantics |= SPIRV::MemorySemantics::Acquire;
976 MemSemantics |= SPIRV::MemorySemantics::SequentiallyConsistent;
979 MemFlags == MemSemantics
983 SPIRV::Scope::Scope Scope = SPIRV::Scope::Workgroup;
984 SPIRV::Scope::Scope MemScope = Scope;
985 if (Call->Arguments.size() >= 2) {
987 ((Opcode != SPIRV::OpMemoryBarrier && Call->Arguments.size() == 2) ||
988 (Opcode == SPIRV::OpMemoryBarrier && Call->Arguments.size() == 3)) &&
989 "Extra args for explicitly scoped barrier");
990 Register ScopeArg = (Opcode == SPIRV::OpMemoryBarrier) ? Call->Arguments[2]
991 : Call->Arguments[1];
992 SPIRV::CLMemoryScope CLScope =
995 if (!(MemFlags & SPIRV::CLK_LOCAL_MEM_FENCE) ||
996 (Opcode == SPIRV::OpMemoryBarrier))
998 if (CLScope ==
static_cast<unsigned>(Scope))
999 ScopeReg = Call->Arguments[1];
1006 if (Opcode != SPIRV::OpMemoryBarrier)
1008 MIB.
addUse(MemSemanticsReg);
1020 if ((Opcode == SPIRV::OpBitFieldInsert ||
1021 Opcode == SPIRV::OpBitFieldSExtract ||
1022 Opcode == SPIRV::OpBitFieldUExtract || Opcode == SPIRV::OpBitReverse) &&
1023 !ST->canUseExtension(SPIRV::Extension::SPV_KHR_bit_instructions)) {
1024 std::string DiagMsg = std::string(Builtin->
Name) +
1025 ": the builtin requires the following SPIR-V "
1026 "extension: SPV_KHR_bit_instructions";
1031 if (Call->isSpirvOp())
1036 .
addDef(Call->ReturnRegister)
1038 for (
unsigned i = 0; i < Call->Arguments.size(); ++i)
1039 MIB.
addUse(Call->Arguments[i]);
1046 case SPIRV::Dim::DIM_1D:
1047 case SPIRV::Dim::DIM_Buffer:
1049 case SPIRV::Dim::DIM_2D:
1050 case SPIRV::Dim::DIM_Cube:
1051 case SPIRV::Dim::DIM_Rect:
1053 case SPIRV::Dim::DIM_3D:
1066 return arrayed ? numComps + 1 : numComps;
1079 SPIRV::lookupExtendedBuiltin(Builtin->
Name, Builtin->
Set)->Number;
1084 .
addDef(Call->ReturnRegister)
1086 .
addImm(
static_cast<uint32_t>(SPIRV::InstructionSet::OpenCL_std))
1089 for (
auto Argument : Call->Arguments)
1100 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
1104 std::tie(CompareRegister, RelationType) =
1112 for (
auto Argument : Call->Arguments)
1116 return buildSelectInst(MIRBuilder, Call->ReturnRegister, CompareRegister,
1117 Call->ReturnType, GR);
1125 SPIRV::lookupGroupBuiltin(Builtin->
Name);
1128 if (Call->isSpirvOp()) {
1134 Register GroupOpReg = Call->Arguments[1];
1136 if (!
MI ||
MI->getOpcode() != TargetOpcode::G_CONSTANT)
1138 "Group Operation parameter must be an integer constant");
1139 uint64_t GrpOp =
MI->getOperand(1).getCImm()->getValue().getZExtValue();
1140 Register ScopeReg = Call->Arguments[0];
1142 .
addDef(Call->ReturnRegister)
1146 for (
unsigned i = 2; i < Call->Arguments.size(); ++i)
1147 MIB.
addUse(Call->Arguments[i]);
1154 Register BoolReg = Call->Arguments[0];
1159 if (ArgInstruction->
getOpcode() == TargetOpcode::G_CONSTANT) {
1160 if (BoolRegType->
getOpcode() != SPIRV::OpTypeBool)
1164 if (BoolRegType->
getOpcode() == SPIRV::OpTypeInt) {
1166 MRI->setRegClass(Arg0, &SPIRV::iIDRegClass);
1172 }
else if (BoolRegType->
getOpcode() != SPIRV::OpTypeBool) {
1179 Register GroupResultRegister = Call->ReturnRegister;
1180 SPIRVType *GroupResultType = Call->ReturnType;
1184 const bool HasBoolReturnTy =
1189 if (HasBoolReturnTy)
1190 std::tie(GroupResultRegister, GroupResultType) =
1193 auto Scope = Builtin->
Name.
starts_with(
"sub_group") ? SPIRV::Scope::Subgroup
1194 : SPIRV::Scope::Workgroup;
1198 if (GroupBuiltin->
Opcode == SPIRV::OpGroupBroadcast &&
1199 Call->Arguments.size() > 2) {
1205 Register ElemReg = Call->Arguments[1];
1207 if (!ElemType || ElemType->
getOpcode() != SPIRV::OpTypeInt)
1209 unsigned VecLen = Call->Arguments.size() - 1;
1210 VecReg =
MRI->createGenericVirtualRegister(
1212 MRI->setRegClass(VecReg, &SPIRV::vIDRegClass);
1218 for (
unsigned i = 1; i < Call->Arguments.size(); i++) {
1219 MIB.
addUse(Call->Arguments[i]);
1228 .
addDef(GroupResultRegister)
1234 if (Call->Arguments.size() > 0) {
1240 for (
unsigned i = 1; i < Call->Arguments.size(); i++)
1241 MIB.addUse(Call->Arguments[i]);
1245 if (HasBoolReturnTy)
1246 buildSelectInst(MIRBuilder, Call->ReturnRegister, GroupResultRegister,
1247 Call->ReturnType, GR);
1258 SPIRV::lookupIntelSubgroupsBuiltin(Builtin->
Name);
1260 if (IntelSubgroups->
IsMedia &&
1261 !ST->canUseExtension(SPIRV::Extension::SPV_INTEL_media_block_io)) {
1262 std::string DiagMsg = std::string(Builtin->
Name) +
1263 ": the builtin requires the following SPIR-V "
1264 "extension: SPV_INTEL_media_block_io";
1266 }
else if (!IntelSubgroups->
IsMedia &&
1267 !ST->canUseExtension(SPIRV::Extension::SPV_INTEL_subgroups)) {
1268 std::string DiagMsg = std::string(Builtin->
Name) +
1269 ": the builtin requires the following SPIR-V "
1270 "extension: SPV_INTEL_subgroups";
1275 if (Call->isSpirvOp()) {
1276 bool IsSet = OpCode != SPIRV::OpSubgroupBlockWriteINTEL &&
1277 OpCode != SPIRV::OpSubgroupImageBlockWriteINTEL &&
1278 OpCode != SPIRV::OpSubgroupImageMediaBlockWriteINTEL;
1284 if (IntelSubgroups->
IsBlock) {
1287 if (Arg0Type->getOpcode() == SPIRV::OpTypeImage) {
1293 case SPIRV::OpSubgroupBlockReadINTEL:
1294 OpCode = SPIRV::OpSubgroupImageBlockReadINTEL;
1296 case SPIRV::OpSubgroupBlockWriteINTEL:
1297 OpCode = SPIRV::OpSubgroupImageBlockWriteINTEL;
1318 .
addDef(Call->ReturnRegister)
1320 for (
size_t i = 0; i < Call->Arguments.size(); ++i)
1321 MIB.
addUse(Call->Arguments[i]);
1331 if (!ST->canUseExtension(
1332 SPIRV::Extension::SPV_KHR_uniform_group_instructions)) {
1333 std::string DiagMsg = std::string(Builtin->
Name) +
1334 ": the builtin requires the following SPIR-V "
1335 "extension: SPV_KHR_uniform_group_instructions";
1339 SPIRV::lookupGroupUniformBuiltin(Builtin->
Name);
1342 Register GroupResultReg = Call->ReturnRegister;
1343 Register ScopeReg = Call->Arguments[0];
1344 Register ValueReg = Call->Arguments[2];
1347 Register ConstGroupOpReg = Call->Arguments[1];
1349 if (!Const || Const->getOpcode() != TargetOpcode::G_CONSTANT)
1351 "expect a constant group operation for a uniform group instruction",
1354 if (!ConstOperand.
isCImm())
1364 MIB.addUse(ValueReg);
1375 if (!ST->canUseExtension(SPIRV::Extension::SPV_KHR_shader_clock)) {
1376 std::string DiagMsg = std::string(Builtin->
Name) +
1377 ": the builtin requires the following SPIR-V "
1378 "extension: SPV_KHR_shader_clock";
1382 Register ResultReg = Call->ReturnRegister;
1385 SPIRV::Scope::Scope ScopeArg =
1387 .
EndsWith(
"device", SPIRV::Scope::Scope::Device)
1388 .
EndsWith(
"work_group", SPIRV::Scope::Scope::Workgroup)
1389 .
EndsWith(
"sub_group", SPIRV::Scope::Scope::Subgroup);
1429 SPIRV::BuiltIn::BuiltIn BuiltinValue,
1431 Register IndexRegister = Call->Arguments[0];
1432 const unsigned ResultWidth = Call->ReturnType->getOperand(1).getImm();
1440 Register ToTruncate = Call->ReturnRegister;
1443 bool IsConstantIndex =
1444 IndexInstruction->getOpcode() == TargetOpcode::G_CONSTANT;
1449 Register DefaultReg = Call->ReturnRegister;
1450 if (PointerSize != ResultWidth) {
1451 DefaultReg =
MRI->createGenericVirtualRegister(
LLT::scalar(PointerSize));
1452 MRI->setRegClass(DefaultReg, &SPIRV::iIDRegClass);
1454 MIRBuilder.
getMF());
1455 ToTruncate = DefaultReg;
1459 MIRBuilder.
buildCopy(DefaultReg, NewRegister);
1467 Register Extracted = Call->ReturnRegister;
1468 if (!IsConstantIndex || PointerSize != ResultWidth) {
1469 Extracted =
MRI->createGenericVirtualRegister(
LLT::scalar(PointerSize));
1470 MRI->setRegClass(Extracted, &SPIRV::iIDRegClass);
1477 ExtractInst.
addUse(LoadedVector).
addUse(IndexRegister);
1480 if (!IsConstantIndex) {
1489 MRI->setRegClass(CompareRegister, &SPIRV::iIDRegClass);
1502 Register SelectionResult = Call->ReturnRegister;
1503 if (PointerSize != ResultWidth) {
1506 MRI->setRegClass(SelectionResult, &SPIRV::iIDRegClass);
1508 MIRBuilder.
getMF());
1511 MIRBuilder.
buildSelect(SelectionResult, CompareRegister, Extracted,
1513 ToTruncate = SelectionResult;
1515 ToTruncate = Extracted;
1519 if (PointerSize != ResultWidth)
1529 SPIRV::BuiltIn::BuiltIn
Value =
1530 SPIRV::lookupGetBuiltin(Builtin->
Name, Builtin->
Set)->
Value;
1532 if (
Value == SPIRV::BuiltIn::GlobalInvocationId)
1538 if (Call->ReturnType->getOpcode() == SPIRV::OpTypeVector)
1545 LLType, Call->ReturnRegister);
1554 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
1557 case SPIRV::OpStore:
1559 case SPIRV::OpAtomicLoad:
1561 case SPIRV::OpAtomicStore:
1563 case SPIRV::OpAtomicCompareExchange:
1564 case SPIRV::OpAtomicCompareExchangeWeak:
1567 case SPIRV::OpAtomicIAdd:
1568 case SPIRV::OpAtomicISub:
1569 case SPIRV::OpAtomicOr:
1570 case SPIRV::OpAtomicXor:
1571 case SPIRV::OpAtomicAnd:
1572 case SPIRV::OpAtomicExchange:
1574 case SPIRV::OpMemoryBarrier:
1576 case SPIRV::OpAtomicFlagTestAndSet:
1577 case SPIRV::OpAtomicFlagClear:
1580 if (Call->isSpirvOp())
1592 unsigned Opcode = SPIRV::lookupAtomicFloatingBuiltin(Builtin->
Name)->Opcode;
1595 case SPIRV::OpAtomicFAddEXT:
1596 case SPIRV::OpAtomicFMinEXT:
1597 case SPIRV::OpAtomicFMaxEXT:
1610 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
1617 MIRBuilder.
buildInstr(TargetOpcode::G_ADDRSPACE_CAST)
1618 .
addDef(Call->ReturnRegister)
1619 .
addUse(Call->Arguments[0]);
1627 if (Call->isSpirvOp())
1632 SPIRV::OpTypeVector;
1634 uint32_t OC = IsVec ? SPIRV::OpDot : SPIRV::OpFMulS;
1635 bool IsSwapReq =
false;
1640 (ST->canUseExtension(SPIRV::Extension::SPV_KHR_integer_dot_product) ||
1644 SPIRV::lookupIntegerDotProductBuiltin(Builtin->
Name);
1654 bool IsFirstSigned = TypeStrs[0].trim()[0] !=
'u';
1655 bool IsSecondSigned = TypeStrs[1].trim()[0] !=
'u';
1657 if (Call->BuiltinName ==
"dot") {
1658 if (IsFirstSigned && IsSecondSigned)
1660 else if (!IsFirstSigned && !IsSecondSigned)
1663 OC = SPIRV::OpSUDot;
1667 }
else if (Call->BuiltinName ==
"dot_acc_sat") {
1668 if (IsFirstSigned && IsSecondSigned)
1669 OC = SPIRV::OpSDotAccSat;
1670 else if (!IsFirstSigned && !IsSecondSigned)
1671 OC = SPIRV::OpUDotAccSat;
1673 OC = SPIRV::OpSUDotAccSat;
1682 .
addDef(Call->ReturnRegister)
1686 MIB.
addUse(Call->Arguments[1]);
1687 MIB.
addUse(Call->Arguments[0]);
1689 for (
size_t i = 2; i < Call->Arguments.size(); ++i)
1690 MIB.
addUse(Call->Arguments[i]);
1692 for (
size_t i = 0; i < Call->Arguments.size(); ++i)
1693 MIB.
addUse(Call->Arguments[i]);
1698 if (!IsVec && OC != SPIRV::OpFMulS)
1708 SPIRV::BuiltIn::BuiltIn
Value =
1709 SPIRV::lookupGetBuiltin(Builtin->
Name, Builtin->
Set)->
Value;
1712 assert(Call->ReturnType->getOpcode() == SPIRV::OpTypeInt);
1716 MIRBuilder, Call->ReturnType, GR,
Value, LLType, Call->ReturnRegister,
1731 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
1733 Register SRetReg = Call->Arguments[0];
1738 if (RetType->
getOpcode() != SPIRV::OpTypeStruct)
1740 "overflow builtins");
1744 if (!OpType1 || !OpType2 || OpType1 != OpType2)
1746 if (OpType1->
getOpcode() == SPIRV::OpTypeVector)
1748 case SPIRV::OpIAddCarryS:
1749 Opcode = SPIRV::OpIAddCarryV;
1751 case SPIRV::OpISubBorrowS:
1752 Opcode = SPIRV::OpISubBorrowV;
1757 Register ResReg =
MRI->createVirtualRegister(&SPIRV::iIDRegClass);
1759 MRI->getRegClassOrNull(Call->Arguments[1])) {
1760 MRI->setRegClass(ResReg, DstRC);
1761 MRI->setType(ResReg,
MRI->getType(Call->Arguments[1]));
1769 .
addUse(Call->Arguments[1])
1770 .
addUse(Call->Arguments[2]);
1779 SPIRV::BuiltIn::BuiltIn
Value =
1780 SPIRV::lookupGetBuiltin(Call->Builtin->Name, Call->Builtin->Set)->
Value;
1781 uint64_t IsDefault = (
Value == SPIRV::BuiltIn::GlobalSize ||
1782 Value == SPIRV::BuiltIn::WorkgroupSize ||
1783 Value == SPIRV::BuiltIn::EnqueuedWorkgroupSize);
1793 SPIRV::lookupImageQueryBuiltin(Builtin->
Name, Builtin->
Set)->Component;
1798 unsigned NumExpectedRetComponents =
RetTy->getOpcode() == SPIRV::OpTypeVector
1799 ?
RetTy->getOperand(2).getImm()
1804 Register QueryResult = Call->ReturnRegister;
1805 SPIRVType *QueryResultType = Call->ReturnType;
1806 if (NumExpectedRetComponents != NumActualRetComponents) {
1812 IntTy, NumActualRetComponents, MIRBuilder);
1817 IsDimBuf ? SPIRV::OpImageQuerySize : SPIRV::OpImageQuerySizeLod;
1821 .
addUse(Call->Arguments[0]);
1824 if (NumExpectedRetComponents == NumActualRetComponents)
1826 if (NumExpectedRetComponents == 1) {
1828 unsigned ExtractedComposite =
1829 Component == 3 ? NumActualRetComponents - 1 : Component;
1830 assert(ExtractedComposite < NumActualRetComponents &&
1831 "Invalid composite index!");
1834 if (QueryResultType->
getOpcode() == SPIRV::OpTypeVector) {
1836 if (TypeReg != NewTypeReg &&
1838 TypeReg = NewTypeReg;
1840 MIRBuilder.
buildInstr(SPIRV::OpCompositeExtract)
1841 .
addDef(Call->ReturnRegister)
1844 .
addImm(ExtractedComposite);
1845 if (NewType !=
nullptr)
1850 auto MIB = MIRBuilder.
buildInstr(SPIRV::OpVectorShuffle)
1851 .
addDef(Call->ReturnRegister)
1855 for (
unsigned i = 0; i < NumExpectedRetComponents; ++i)
1856 MIB.
addImm(i < NumActualRetComponents ? i : 0xffffffff);
1864 assert(Call->ReturnType->getOpcode() == SPIRV::OpTypeInt &&
1865 "Image samples query result must be of int type!");
1870 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
1872 Register Image = Call->Arguments[0];
1873 SPIRV::Dim::Dim ImageDimensionality =
static_cast<SPIRV::Dim::Dim
>(
1875 (void)ImageDimensionality;
1878 case SPIRV::OpImageQuerySamples:
1879 assert(ImageDimensionality == SPIRV::Dim::DIM_2D &&
1880 "Image must be of 2D dimensionality");
1882 case SPIRV::OpImageQueryLevels:
1883 assert((ImageDimensionality == SPIRV::Dim::DIM_1D ||
1884 ImageDimensionality == SPIRV::Dim::DIM_2D ||
1885 ImageDimensionality == SPIRV::Dim::DIM_3D ||
1886 ImageDimensionality == SPIRV::Dim::DIM_Cube) &&
1887 "Image must be of 1D/2D/3D/Cube dimensionality");
1892 .
addDef(Call->ReturnRegister)
1899static SPIRV::SamplerAddressingMode::SamplerAddressingMode
1901 switch (Bitmask & SPIRV::CLK_ADDRESS_MODE_MASK) {
1902 case SPIRV::CLK_ADDRESS_CLAMP:
1903 return SPIRV::SamplerAddressingMode::Clamp;
1904 case SPIRV::CLK_ADDRESS_CLAMP_TO_EDGE:
1905 return SPIRV::SamplerAddressingMode::ClampToEdge;
1906 case SPIRV::CLK_ADDRESS_REPEAT:
1907 return SPIRV::SamplerAddressingMode::Repeat;
1908 case SPIRV::CLK_ADDRESS_MIRRORED_REPEAT:
1909 return SPIRV::SamplerAddressingMode::RepeatMirrored;
1910 case SPIRV::CLK_ADDRESS_NONE:
1911 return SPIRV::SamplerAddressingMode::None;
1918 return (Bitmask & SPIRV::CLK_NORMALIZED_COORDS_TRUE) ? 1 : 0;
1921static SPIRV::SamplerFilterMode::SamplerFilterMode
1923 if (Bitmask & SPIRV::CLK_FILTER_LINEAR)
1924 return SPIRV::SamplerFilterMode::Linear;
1925 if (Bitmask & SPIRV::CLK_FILTER_NEAREST)
1926 return SPIRV::SamplerFilterMode::Nearest;
1927 return SPIRV::SamplerFilterMode::Nearest;
1934 Register Image = Call->Arguments[0];
1938 if (HasOclSampler) {
1939 Register Sampler = Call->Arguments[1];
1953 Register SampledImage =
MRI->createVirtualRegister(&SPIRV::iIDRegClass);
1964 if (Call->ReturnType->getOpcode() != SPIRV::OpTypeVector) {
1968 MRI->createGenericVirtualRegister(GR->
getRegType(TempType));
1971 MIRBuilder.
buildInstr(SPIRV::OpImageSampleExplicitLod)
1975 .
addUse(Call->Arguments[2])
1976 .
addImm(SPIRV::ImageOperand::Lod)
1978 MIRBuilder.
buildInstr(SPIRV::OpCompositeExtract)
1979 .
addDef(Call->ReturnRegister)
1984 MIRBuilder.
buildInstr(SPIRV::OpImageSampleExplicitLod)
1985 .
addDef(Call->ReturnRegister)
1988 .
addUse(Call->Arguments[2])
1989 .
addImm(SPIRV::ImageOperand::Lod)
1992 }
else if (HasMsaa) {
1994 .
addDef(Call->ReturnRegister)
1997 .
addUse(Call->Arguments[1])
1998 .
addImm(SPIRV::ImageOperand::Sample)
1999 .
addUse(Call->Arguments[2]);
2002 .
addDef(Call->ReturnRegister)
2005 .
addUse(Call->Arguments[1]);
2014 .
addUse(Call->Arguments[0])
2015 .
addUse(Call->Arguments[1])
2016 .
addUse(Call->Arguments[2]);
2025 if (Call->Builtin->Name.contains_insensitive(
2026 "__translate_sampler_initializer")) {
2033 return Sampler.isValid();
2034 }
else if (Call->Builtin->Name.contains_insensitive(
"__spirv_SampledImage")) {
2036 Register Image = Call->Arguments[0];
2041 Call->ReturnRegister.isValid()
2042 ? Call->ReturnRegister
2043 :
MRI->createVirtualRegister(&SPIRV::iIDRegClass);
2048 .
addUse(Call->Arguments[1]);
2050 }
else if (Call->Builtin->Name.contains_insensitive(
2051 "__spirv_ImageSampleExplicitLod")) {
2053 std::string ReturnType = DemangledCall.
str();
2054 if (DemangledCall.
contains(
"_R")) {
2055 ReturnType = ReturnType.substr(ReturnType.find(
"_R") + 2);
2056 ReturnType = ReturnType.substr(0, ReturnType.find(
'('));
2063 std::string DiagMsg =
2064 "Unable to recognize SPIRV type name: " + ReturnType;
2067 MIRBuilder.
buildInstr(SPIRV::OpImageSampleExplicitLod)
2068 .
addDef(Call->ReturnRegister)
2070 .
addUse(Call->Arguments[0])
2071 .
addUse(Call->Arguments[1])
2072 .
addImm(SPIRV::ImageOperand::Lod)
2073 .
addUse(Call->Arguments[3]);
2081 MIRBuilder.
buildSelect(Call->ReturnRegister, Call->Arguments[0],
2082 Call->Arguments[1], Call->Arguments[2]);
2098 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
2099 bool IsSet = Opcode != SPIRV::OpCooperativeMatrixStoreKHR &&
2100 Opcode != SPIRV::OpCooperativeMatrixStoreCheckedINTEL &&
2101 Opcode != SPIRV::OpCooperativeMatrixPrefetchINTEL;
2102 unsigned ArgSz = Call->Arguments.size();
2103 unsigned LiteralIdx = 0;
2106 case SPIRV::OpCooperativeMatrixLoadKHR:
2107 LiteralIdx = ArgSz > 3 ? 3 : 0;
2109 case SPIRV::OpCooperativeMatrixStoreKHR:
2110 LiteralIdx = ArgSz > 4 ? 4 : 0;
2112 case SPIRV::OpCooperativeMatrixLoadCheckedINTEL:
2113 LiteralIdx = ArgSz > 7 ? 7 : 0;
2115 case SPIRV::OpCooperativeMatrixStoreCheckedINTEL:
2116 LiteralIdx = ArgSz > 8 ? 8 : 0;
2119 case SPIRV::OpCooperativeMatrixMulAddKHR:
2120 LiteralIdx = ArgSz > 3 ? 3 : 0;
2126 if (Opcode == SPIRV::OpCooperativeMatrixPrefetchINTEL) {
2128 auto MIB = MIRBuilder.
buildInstr(SPIRV::OpCooperativeMatrixPrefetchINTEL)
2129 .
addUse(Call->Arguments[0])
2130 .
addUse(Call->Arguments[1])
2131 .
addUse(Call->Arguments[2])
2133 .
addUse(Call->Arguments[4]);
2135 MIB.
addUse(Call->Arguments[5]);
2145 if (Opcode == SPIRV::OpCooperativeMatrixLengthKHR) {
2150 .
addDef(Call->ReturnRegister)
2156 IsSet ? TypeReg :
Register(0), ImmArgs);
2165 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
2169 case SPIRV::OpSpecConstant: {
2173 buildOpDecorate(Call->ReturnRegister, MIRBuilder, SPIRV::Decoration::SpecId,
2176 Register ConstRegister = Call->Arguments[1];
2179 (Const->getOpcode() == TargetOpcode::G_CONSTANT ||
2180 Const->getOpcode() == TargetOpcode::G_FCONSTANT) &&
2181 "Argument should be either an int or floating-point constant");
2184 if (Call->ReturnType->getOpcode() == SPIRV::OpTypeBool) {
2185 assert(ConstOperand.
isCImm() &&
"Int constant operand is expected");
2187 ? SPIRV::OpSpecConstantTrue
2188 : SPIRV::OpSpecConstantFalse;
2191 .
addDef(Call->ReturnRegister)
2194 if (Call->ReturnType->getOpcode() != SPIRV::OpTypeBool) {
2195 if (Const->getOpcode() == TargetOpcode::G_CONSTANT)
2202 case SPIRV::OpSpecConstantComposite: {
2204 .
addDef(Call->ReturnRegister)
2206 for (
unsigned i = 0; i < Call->Arguments.size(); i++)
2207 MIB.
addUse(Call->Arguments[i]);
2221 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
2236 Register TmpReg =
MRI->createVirtualRegister(&SPIRV::iIDRegClass);
2240 unsigned NumArgs = Call->Arguments.size();
2242 Register GlobalWorkSize = Call->Arguments[NumArgs < 4 ? 1 : 2];
2244 NumArgs == 2 ?
Register(0) : Call->Arguments[NumArgs < 4 ? 2 : 3];
2245 Register GlobalWorkOffset = NumArgs <= 3 ?
Register(0) : Call->Arguments[1];
2249 if (SpvTy->
getOpcode() == SPIRV::OpTypePointer) {
2255 unsigned Size = Call->Builtin->Name ==
"ndrange_3D" ? 3 : 2;
2260 GlobalWorkSize =
MRI->createVirtualRegister(&SPIRV::iIDRegClass);
2269 SpvFieldTy, *ST.getInstrInfo());
2274 LocalWorkSize = Const;
2275 if (!GlobalWorkOffset.
isValid())
2276 GlobalWorkOffset = Const;
2284 .
addUse(GlobalWorkOffset);
2286 .
addUse(Call->Arguments[0])
2305 bool IsSpirvOp = Call->isSpirvOp();
2306 bool HasEvents = Call->Builtin->Name.contains(
"events") || IsSpirvOp;
2313 if (Call->Builtin->Name.contains(
"_varargs") || IsSpirvOp) {
2314 const unsigned LocalSizeArrayIdx = HasEvents ? 9 : 6;
2315 Register GepReg = Call->Arguments[LocalSizeArrayIdx];
2322 assert(LocalSizeTy &&
"Local size type is expected");
2324 cast<ArrayType>(LocalSizeTy)->getNumElements();
2328 Int32Ty, MIRBuilder, SPIRV::StorageClass::Function);
2329 for (
unsigned I = 0;
I < LocalSizeNum; ++
I) {
2331 MRI->setType(
Reg, LLType);
2345 auto MIB = MIRBuilder.
buildInstr(SPIRV::OpEnqueueKernel)
2346 .
addDef(Call->ReturnRegister)
2350 const unsigned BlockFIdx = HasEvents ? 6 : 3;
2351 for (
unsigned i = 0; i < BlockFIdx; i++)
2352 MIB.addUse(Call->Arguments[i]);
2359 MIB.addUse(NullPtr);
2360 MIB.addUse(NullPtr);
2368 Register BlockLiteralReg = Call->Arguments[BlockFIdx + 1];
2370 MIB.addUse(BlockLiteralReg);
2380 for (
unsigned i = 0; i < LocalSizes.
size(); i++)
2381 MIB.addUse(LocalSizes[i]);
2391 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
2394 case SPIRV::OpRetainEvent:
2395 case SPIRV::OpReleaseEvent:
2397 case SPIRV::OpCreateUserEvent:
2398 case SPIRV::OpGetDefaultQueue:
2400 .
addDef(Call->ReturnRegister)
2402 case SPIRV::OpIsValidEvent:
2404 .
addDef(Call->ReturnRegister)
2406 .
addUse(Call->Arguments[0]);
2407 case SPIRV::OpSetUserEventStatus:
2409 .
addUse(Call->Arguments[0])
2410 .
addUse(Call->Arguments[1]);
2411 case SPIRV::OpCaptureEventProfilingInfo:
2413 .
addUse(Call->Arguments[0])
2414 .
addUse(Call->Arguments[1])
2415 .
addUse(Call->Arguments[2]);
2416 case SPIRV::OpBuildNDRange:
2418 case SPIRV::OpEnqueueKernel:
2431 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
2433 bool IsSet = Opcode == SPIRV::OpGroupAsyncCopy;
2435 if (Call->isSpirvOp())
2442 case SPIRV::OpGroupAsyncCopy: {
2444 Call->ReturnType->getOpcode() == SPIRV::OpTypeEvent
2448 unsigned NumArgs = Call->Arguments.size();
2449 Register EventReg = Call->Arguments[NumArgs - 1];
2451 .
addDef(Call->ReturnRegister)
2454 .
addUse(Call->Arguments[0])
2455 .
addUse(Call->Arguments[1])
2456 .
addUse(Call->Arguments[2])
2457 .
addUse(Call->Arguments.size() > 4
2458 ? Call->Arguments[3]
2461 if (NewType !=
nullptr)
2466 case SPIRV::OpGroupWaitEvents:
2469 .
addUse(Call->Arguments[0])
2470 .
addUse(Call->Arguments[1]);
2482 SPIRV::lookupConvertBuiltin(Call->Builtin->Name, Call->Builtin->Set);
2484 if (!Builtin && Call->isSpirvOp()) {
2487 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
2494 SPIRV::Decoration::SaturatedConversion, {});
2497 SPIRV::Decoration::FPRoundingMode,
2498 {(unsigned)Builtin->RoundingMode});
2500 std::string NeedExtMsg;
2501 bool IsRightComponentsNumber =
true;
2502 unsigned Opcode = SPIRV::OpNop;
2509 : SPIRV::OpSatConvertSToU;
2512 : SPIRV::OpSConvert;
2514 SPIRV::OpTypeFloat)) {
2519 if (!ST->canUseExtension(
2520 SPIRV::Extension::SPV_INTEL_bfloat16_conversion))
2521 NeedExtMsg =
"SPV_INTEL_bfloat16_conversion";
2522 IsRightComponentsNumber =
2525 Opcode = SPIRV::OpConvertBF16ToFINTEL;
2527 bool IsSourceSigned =
2529 Opcode = IsSourceSigned ? SPIRV::OpConvertSToF : SPIRV::OpConvertUToF;
2533 SPIRV::OpTypeFloat)) {
2540 if (!ST->canUseExtension(
2541 SPIRV::Extension::SPV_INTEL_bfloat16_conversion))
2542 NeedExtMsg =
"SPV_INTEL_bfloat16_conversion";
2543 IsRightComponentsNumber =
2546 Opcode = SPIRV::OpConvertFToBF16INTEL;
2549 : SPIRV::OpConvertFToU;
2552 SPIRV::OpTypeFloat)) {
2554 Opcode = SPIRV::OpFConvert;
2558 if (!NeedExtMsg.empty()) {
2559 std::string DiagMsg = std::string(Builtin->
Name) +
2560 ": the builtin requires the following SPIR-V "
2565 if (!IsRightComponentsNumber) {
2566 std::string DiagMsg =
2567 std::string(Builtin->
Name) +
2568 ": result and argument must have the same number of components";
2571 assert(Opcode != SPIRV::OpNop &&
2572 "Conversion between the types not implemented!");
2575 .
addDef(Call->ReturnRegister)
2577 .
addUse(Call->Arguments[0]);
2586 SPIRV::lookupVectorLoadStoreBuiltin(Call->Builtin->Name,
2587 Call->Builtin->Set);
2591 .
addDef(Call->ReturnRegister)
2593 .
addImm(
static_cast<uint32_t>(SPIRV::InstructionSet::OpenCL_std))
2595 for (
auto Argument : Call->Arguments)
2613 SPIRV::lookupNativeBuiltin(Builtin->
Name, Builtin->
Set)->Opcode;
2614 bool IsLoad = Opcode == SPIRV::OpLoad;
2618 MIB.
addDef(Call->ReturnRegister);
2622 MIB.
addUse(Call->Arguments[0]);
2626 MIB.addUse(Call->Arguments[1]);
2628 unsigned NumArgs = Call->Arguments.size();
2629 if ((IsLoad && NumArgs >= 2) || NumArgs >= 3)
2631 if ((IsLoad && NumArgs >= 3) || NumArgs >= 4)
2644std::tuple<int, unsigned, unsigned>
2646 SPIRV::InstructionSet::InstructionSet Set) {
2649 std::unique_ptr<const IncomingCall> Call =
2652 return std::make_tuple(-1, 0, 0);
2654 switch (Call->Builtin->Group) {
2655 case SPIRV::Relational:
2657 case SPIRV::Barrier:
2658 case SPIRV::CastToPtr:
2659 case SPIRV::ImageMiscQuery:
2660 case SPIRV::SpecConstant:
2661 case SPIRV::Enqueue:
2662 case SPIRV::AsyncCopy:
2663 case SPIRV::LoadStore:
2664 case SPIRV::CoopMatr:
2666 SPIRV::lookupNativeBuiltin(Call->Builtin->Name, Call->Builtin->Set))
2667 return std::make_tuple(Call->Builtin->Group, R->Opcode, 0);
2669 case SPIRV::Extended:
2670 if (
const auto *R = SPIRV::lookupExtendedBuiltin(Call->Builtin->Name,
2671 Call->Builtin->Set))
2672 return std::make_tuple(Call->Builtin->Group, 0, R->Number);
2674 case SPIRV::VectorLoadStore:
2675 if (
const auto *R = SPIRV::lookupVectorLoadStoreBuiltin(Call->Builtin->Name,
2676 Call->Builtin->Set))
2677 return std::make_tuple(SPIRV::Extended, 0, R->Number);
2680 if (
const auto *R = SPIRV::lookupGroupBuiltin(Call->Builtin->Name))
2681 return std::make_tuple(Call->Builtin->Group, R->Opcode, 0);
2683 case SPIRV::AtomicFloating:
2684 if (
const auto *R = SPIRV::lookupAtomicFloatingBuiltin(Call->Builtin->Name))
2685 return std::make_tuple(Call->Builtin->Group, R->Opcode, 0);
2687 case SPIRV::IntelSubgroups:
2688 if (
const auto *R = SPIRV::lookupIntelSubgroupsBuiltin(Call->Builtin->Name))
2689 return std::make_tuple(Call->Builtin->Group, R->Opcode, 0);
2691 case SPIRV::GroupUniform:
2692 if (
const auto *R = SPIRV::lookupGroupUniformBuiltin(Call->Builtin->Name))
2693 return std::make_tuple(Call->Builtin->Group, R->Opcode, 0);
2695 case SPIRV::IntegerDot:
2697 SPIRV::lookupIntegerDotProductBuiltin(Call->Builtin->Name))
2698 return std::make_tuple(Call->Builtin->Group, R->Opcode, 0);
2700 case SPIRV::WriteImage:
2701 return std::make_tuple(Call->Builtin->Group, SPIRV::OpImageWrite, 0);
2703 return std::make_tuple(Call->Builtin->Group, TargetOpcode::G_SELECT, 0);
2704 case SPIRV::Construct:
2705 return std::make_tuple(Call->Builtin->Group, SPIRV::OpCompositeConstruct,
2707 case SPIRV::KernelClock:
2708 return std::make_tuple(Call->Builtin->Group, SPIRV::OpReadClockKHR, 0);
2710 return std::make_tuple(-1, 0, 0);
2712 return std::make_tuple(-1, 0, 0);
2716 SPIRV::InstructionSet::InstructionSet Set,
2721 LLVM_DEBUG(
dbgs() <<
"Lowering builtin call: " << DemangledCall <<
"\n");
2725 assert(SpvType &&
"Inconsistent return register: expected valid type info");
2726 std::unique_ptr<const IncomingCall> Call =
2731 return std::nullopt;
2735 assert(Args.size() >= Call->Builtin->MinNumArgs &&
2736 "Too few arguments to generate the builtin");
2737 if (Call->Builtin->MaxNumArgs && Args.size() > Call->Builtin->MaxNumArgs)
2738 LLVM_DEBUG(
dbgs() <<
"More arguments provided than required!\n");
2741 switch (Call->Builtin->Group) {
2742 case SPIRV::Extended:
2744 case SPIRV::Relational:
2748 case SPIRV::Variable:
2752 case SPIRV::AtomicFloating:
2754 case SPIRV::Barrier:
2756 case SPIRV::CastToPtr:
2759 case SPIRV::IntegerDot:
2763 case SPIRV::ICarryBorrow:
2765 case SPIRV::GetQuery:
2767 case SPIRV::ImageSizeQuery:
2769 case SPIRV::ImageMiscQuery:
2771 case SPIRV::ReadImage:
2773 case SPIRV::WriteImage:
2775 case SPIRV::SampleImage:
2779 case SPIRV::Construct:
2781 case SPIRV::SpecConstant:
2783 case SPIRV::Enqueue:
2785 case SPIRV::AsyncCopy:
2787 case SPIRV::Convert:
2789 case SPIRV::VectorLoadStore:
2791 case SPIRV::LoadStore:
2793 case SPIRV::IntelSubgroups:
2795 case SPIRV::GroupUniform:
2797 case SPIRV::KernelClock:
2799 case SPIRV::CoopMatr:
2801 case SPIRV::ExtendedBitOps:
2812 [[maybe_unused]]
bool IsOCLBuiltinType = TypeStr.
consume_front(
"ocl_");
2813 assert(IsOCLBuiltinType &&
"Invalid OpenCL builtin prefix");
2830 unsigned VecElts = 0;
2841 TypeStr = TypeStr.
substr(0, TypeStr.
find(
']'));
2853 auto Pos1 = DemangledCall.
find(
'(');
2856 auto Pos2 = DemangledCall.
find(
')');
2859 DemangledCall.
slice(Pos1 + 1, Pos2)
2860 .
split(BuiltinArgsTypeStrs,
',', -1,
false);
2868 if (ArgIdx >= BuiltinArgsTypeStrs.
size())
2870 StringRef TypeStr = BuiltinArgsTypeStrs[ArgIdx].trim();
2879#define GET_BuiltinTypes_DECL
2880#define GET_BuiltinTypes_IMPL
2887#define GET_OpenCLTypes_DECL
2888#define GET_OpenCLTypes_IMPL
2890#include "SPIRVGenTables.inc"
2898 if (
Name.starts_with(
"void"))
2900 else if (
Name.starts_with(
"int") ||
Name.starts_with(
"uint"))
2902 else if (
Name.starts_with(
"float"))
2904 else if (
Name.starts_with(
"half"))
2917 unsigned Opcode = TypeRecord->
Opcode;
2932 "Invalid number of parameters for SPIR-V pipe builtin!");
2935 SPIRV::AccessQualifier::AccessQualifier(
2943 "Invalid number of parameters for SPIR-V coop matrices builtin!");
2945 "SPIR-V coop matrices builtin type must have a type parameter!");
2950 MIRBuilder, ExtensionType, ElemType, ExtensionType->
getIntParameter(0),
2957 const SPIRV::AccessQualifier::AccessQualifier Qualifier,
2960 "SPIR-V image builtin type must have sampled type parameter!");
2965 "Invalid number of parameters for SPIR-V image builtin!");
2967 SPIRV::AccessQualifier::AccessQualifier accessQualifier =
2968 SPIRV::AccessQualifier::None;
2970 accessQualifier = Qualifier == SPIRV::AccessQualifier::WriteOnly
2971 ? SPIRV::AccessQualifier::WriteOnly
2972 : SPIRV::AccessQualifier::AccessQualifier(
2978 MIRBuilder, SampledType,
2990 OpaqueType, SPIRV::AccessQualifier::ReadOnly, MIRBuilder, GR);
2998 StringRef NameWithParameters = TypeName;
3005 SPIRV::lookupOpenCLType(NameWithParameters);
3008 NameWithParameters);
3016 "Unknown builtin opaque type!");
3020 if (!NameWithParameters.
contains(
'_'))
3024 unsigned BaseNameLength = NameWithParameters.
find(
'_') - 1;
3025 SplitString(NameWithParameters.
substr(BaseNameLength + 1), Parameters,
"_");
3028 bool HasTypeParameter = !
isDigit(Parameters[0][0]);
3029 if (HasTypeParameter)
3032 for (
unsigned i = HasTypeParameter ? 1 : 0; i < Parameters.size(); i++) {
3033 unsigned IntParameter = 0;
3034 bool ValidLiteral = !Parameters[i].getAsInteger(10, IntParameter);
3037 "Invalid format of SPIR-V builtin parameter literal!");
3041 NameWithParameters.
substr(0, BaseNameLength),
3042 TypeParameters, IntParameters);
3046 SPIRV::AccessQualifier::AccessQualifier AccessQual,
3077 switch (TypeRecord->
Opcode) {
3078 case SPIRV::OpTypeImage:
3081 case SPIRV::OpTypePipe:
3084 case SPIRV::OpTypeDeviceEvent:
3087 case SPIRV::OpTypeSampler:
3090 case SPIRV::OpTypeSampledImage:
3093 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.
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, std::optional< unsigned > Flags=std::nullopt)
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.
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
void assignSPIRVTypeToVReg(SPIRVType *Type, Register VReg, const MachineFunction &MF)
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)
SPIRVType * getPointeeType(SPIRVType *PtrType)
Register getSPIRVTypeID(const SPIRVType *SpirvType) const
SPIRVType * getOrCreateSPIRVType(const Type *Type, MachineIRBuilder &MIRBuilder, SPIRV::AccessQualifier::AccessQualifier AQ=SPIRV::AccessQualifier::ReadWrite, bool EmitIR=true)
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)
const TargetRegisterClass * getRegClass(SPIRVType *SpvType) const
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)
LLT getRegType(SPIRVType *SpvType) const
SPIRV::StorageClass::StorageClass getPointerStorageClass(Register VReg) const
SPIRVType * getOrCreateOpTypeSampler(MachineIRBuilder &MIRBuilder)
Register getOrCreateConstNullPtr(MachineIRBuilder &MIRBuilder, SPIRVType *SpvType)
unsigned getScalarOrVectorBitWidth(const SPIRVType *Type) const
Register buildConstantInt(uint64_t Val, MachineIRBuilder &MIRBuilder, SPIRVType *SpvType, bool EmitIR=true, bool ZeroAsNull=true)
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 rfind(char C, size_t From=npos) const
Search for the last character C in the string.
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.
static constexpr size_t npos
A switch()-like statement whose cases are string literals.
StringSwitch & EndsWith(StringLiteral S, T Value)
Class to represent struct types.
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={}, ArrayRef< unsigned > Ints={})
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)
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.
Represents a version number in the form major[.minor[.subminor[.build]]].
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::string lookupBuiltinNameHelper(StringRef DemangledCall, FPDecorationId *DecorationId)
Parses the name part of the demangled builtin call.
Type * parseBuiltinCallArgumentType(StringRef TypeStr, LLVMContext &Ctx)
bool parseBuiltinTypeStr(SmallVector< StringRef, 10 > &BuiltinArgsTypeStrs, const StringRef DemangledCall, LLVMContext &Ctx)
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)
This is an optimization pass for GlobalISel generic memory operations.
void buildOpName(Register Target, const StringRef &Name, MachineIRBuilder &MIRBuilder)
static bool generateGetQueryInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static bool generateLoadStoreInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
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 bool buildExtendedBitOpsInst(const SPIRV::IncomingCall *Call, unsigned Opcode, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
Helper function for building extended bit operations.
static const Type * getBlockStructType(Register ParamReg, MachineRegisterInfo *MRI)
static bool generateGroupInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
FPDecorationId demangledPostfixToDecorationId(const std::string &S)
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 bool generateICarryBorrowInst(const SPIRV::IncomingCall *Call, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
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 Register buildConstantIntReg32(uint64_t Val, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
static SPIRVType * getSampledImageType(const TargetExtType *OpaqueType, MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR)
SPIRV::MemorySemantics::MemorySemantics getMemSemanticsForStorageClass(SPIRV::StorageClass::StorageClass SC)
constexpr unsigned storageClassToAddressSpace(SPIRV::StorageClass::StorageClass SC)
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 void setRegClassIfNull(Register Reg, MachineRegisterInfo *MRI, 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)
Register createVirtualRegister(SPIRVType *SpvType, SPIRVGlobalRegistry *GR, MachineRegisterInfo *MRI, const MachineFunction &MF)
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 generateDotOrFMulInst(const StringRef DemangledCall, 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 generateExtendedBitOpsInst(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