Skip to content

Commit c040f9a

Browse files
authored
[SYCL] Move GroupNonUniform SPIR-V built-in declarations to clang SPIRVBuiltins.td (#17627)
This PR changes scope parameter type from enum to int, aligning with SPV-IR. Mangling becomes more portable for targets that bypass SPIR-V. This PR constrains Id type in GroupNonUniformBroadcast to be either uint32_t or uint64_t. Following parameter types are constrained to be uint32_t: * Index in OpGroupNonUniformBallotBitExtract * Id/Mask/Delta in GroupNonUniformShuffle* * ClusterSize in GroupNonUniformI*/S*/U*/F*, GroupNonUniformBitwise*, and GroupNonUniformLogical* The constraints should align with current built-in implementations and SPV-IR.
1 parent 5726072 commit c040f9a

File tree

6 files changed

+492
-160
lines changed

6 files changed

+492
-160
lines changed

clang/lib/Sema/SPIRVBuiltins.td

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@ def Vec1234 : IntList<"Vec1234", [1, 2, 3, 4]>;
358358
// Type lists.
359359
def TLAll : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>;
360360
def TLAllUnsigned : TypeList<[UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong, UInt, ULong, UShort]>;
361+
def TLAllWithBool : TypeList<[Bool, Char, UChar, Short, UShort, Int, UInt, Long,
362+
ULong, Float, Double, Half]>;
361363
def TLFloat : TypeList<[Float, Double, Half]>;
362364
// FIXME: handle properly char (signed or unsigned depending on host)
363365
def TLSignedInts : TypeList<[Char, Short, Int, Long]>;
@@ -383,6 +385,10 @@ def TLAllInts : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULo
383385
def AGenType1 : GenericType<"AGenType1", TLAll, Vec1>;
384386
def AGenTypeN : GenericType<"AGenTypeN", TLAll, VecAndScalar>;
385387
def AGenTypeNNoScalar : GenericType<"AGenTypeNNoScalar", TLAll, VecNoScalar>;
388+
def AGenTypeNWithBool
389+
: GenericType<"AGenTypeNWithBool", TLAllWithBool, VecAndScalar>;
390+
// Bool
391+
def BoolGenTypeN : GenericType<"BoolGenTypeN", TypeList<[Bool]>, VecAndScalar>;
386392
// All integer
387393
def AIGenType1 : GenericType<"AIGenType1", TLAllInts, Vec1>;
388394
def AIGenTypeN : GenericType<"AIGenTypeN", TLAllInts, VecAndScalar>;
@@ -395,6 +401,7 @@ def AI2UGenTypeN : GenericType<"AI2UGenTypeN", TLAllUIntsTwice, VecAnd
395401
def SGenTypeN : GenericType<"SGenTypeN", TLSignedInts, VecAndScalar>;
396402
// Unsigned integer
397403
def UGenTypeN : GenericType<"UGenTypeN", TLUnsignedInts, VecAndScalar>;
404+
def UInt4 : GenericType<"UInt4", TypeList<[UInt]>, Vec4>;
398405
// Float
399406
def FGenTypeN : GenericType<"FGenTypeN", TLFloat, VecAndScalar>;
400407
// (u)int, (u)long, and all floats
@@ -976,3 +983,92 @@ foreach name = ["GroupSMin", "GroupSMax"] in {
976983
foreach name = ["GroupLogicalAndKHR", "GroupLogicalOrKHR"] in {
977984
def : SPVBuiltin<name, [Bool, Int, Int, Bool], Attr.Convergent>;
978985
}
986+
987+
// 3.56.24. Non-Uniform Instructions
988+
989+
foreach name = ["GroupNonUniformElect"] in {
990+
def : SPVBuiltin<name, [Bool, Int], Attr.Convergent>;
991+
}
992+
993+
foreach name = ["GroupNonUniformAll", "GroupNonUniformAny"] in {
994+
def : SPVBuiltin<name, [Bool, Int, Bool], Attr.Convergent>;
995+
}
996+
997+
foreach name = ["GroupNonUniformAllEqual"] in {
998+
def : SPVBuiltin<name, [Bool, Int, AGenTypeNWithBool], Attr.Convergent>;
999+
}
1000+
1001+
foreach name = ["GroupNonUniformBroadcast"] in {
1002+
foreach IDType = [UInt, ULong] in {
1003+
def : SPVBuiltin<name, [AGenTypeNWithBool, Int, AGenTypeNWithBool, IDType],
1004+
Attr.Convergent>;
1005+
}
1006+
}
1007+
1008+
foreach name = ["GroupNonUniformBroadcastFirst"] in {
1009+
def : SPVBuiltin<name, [AGenTypeNWithBool, Int, AGenTypeNWithBool],
1010+
Attr.Convergent>;
1011+
}
1012+
1013+
foreach name = ["GroupNonUniformBallot"] in {
1014+
def : SPVBuiltin<name, [UInt4, Int, Bool], Attr.Convergent>;
1015+
}
1016+
1017+
foreach name = ["GroupNonUniformInverseBallot"] in {
1018+
def : SPVBuiltin<name, [Bool, Int, UInt4], Attr.Convergent>;
1019+
}
1020+
1021+
foreach name = ["GroupNonUniformBallotBitExtract"] in {
1022+
def : SPVBuiltin<name, [Bool, Int, UInt4, UInt], Attr.Convergent>;
1023+
}
1024+
1025+
foreach name = ["GroupNonUniformBallotBitCount", "GroupNonUniformBallotFindLSB",
1026+
"GroupNonUniformBallotFindMSB"] in {
1027+
def : SPVBuiltin<name, [UInt, Int, Int, UInt4], Attr.Convergent>;
1028+
}
1029+
1030+
foreach name = ["GroupNonUniformShuffle", "GroupNonUniformShuffleXor",
1031+
"GroupNonUniformShuffleUp", "GroupNonUniformShuffleDown"] in {
1032+
def : SPVBuiltin<name, [AGenTypeNWithBool, Int, AGenTypeNWithBool, UInt],
1033+
Attr.Convergent>;
1034+
}
1035+
1036+
foreach name = ["GroupNonUniformIAdd", "GroupNonUniformIMul"] in {
1037+
def : SPVBuiltin<name, [AIGenTypeN, Int, Int, AIGenTypeN], Attr.Convergent>;
1038+
def : SPVBuiltin<name, [AIGenTypeN, Int, Int, AIGenTypeN, UInt],
1039+
Attr.Convergent>;
1040+
}
1041+
1042+
foreach name = ["GroupNonUniformSMin", "GroupNonUniformSMax"] in {
1043+
def : SPVBuiltin<name, [SGenTypeN, Int, Int, SGenTypeN], Attr.Convergent>;
1044+
def : SPVBuiltin<name, [SGenTypeN, Int, Int, SGenTypeN, UInt],
1045+
Attr.Convergent>;
1046+
}
1047+
1048+
foreach name = ["GroupNonUniformUMin", "GroupNonUniformUMax"] in {
1049+
def : SPVBuiltin<name, [UGenTypeN, Int, Int, UGenTypeN], Attr.Convergent>;
1050+
def : SPVBuiltin<name, [UGenTypeN, Int, Int, UGenTypeN, UInt],
1051+
Attr.Convergent>;
1052+
}
1053+
1054+
foreach name = ["GroupNonUniformFAdd", "GroupNonUniformFMul",
1055+
"GroupNonUniformFMin", "GroupNonUniformFMax"] in {
1056+
def : SPVBuiltin<name, [FGenTypeN, Int, Int, FGenTypeN], Attr.Convergent>;
1057+
def : SPVBuiltin<name, [FGenTypeN, Int, Int, FGenTypeN, UInt],
1058+
Attr.Convergent>;
1059+
}
1060+
1061+
foreach name = ["GroupNonUniformBitwiseAnd", "GroupNonUniformBitwiseOr",
1062+
"GroupNonUniformBitwiseXor"] in {
1063+
def : SPVBuiltin<name, [AIGenTypeN, Int, Int, AIGenTypeN], Attr.Convergent>;
1064+
def : SPVBuiltin<name, [AIGenTypeN, Int, Int, AIGenTypeN, UInt],
1065+
Attr.Convergent>;
1066+
}
1067+
1068+
foreach name = ["GroupNonUniformLogicalAnd", "GroupNonUniformLogicalOr",
1069+
"GroupNonUniformLogicalXor"] in {
1070+
def : SPVBuiltin<name, [BoolGenTypeN, Int, Int, BoolGenTypeN],
1071+
Attr.Convergent>;
1072+
def : SPVBuiltin<name, [BoolGenTypeN, Int, Int, BoolGenTypeN, UInt],
1073+
Attr.Convergent>;
1074+
}

0 commit comments

Comments
 (0)