Skip to content

Commit 5beec6d

Browse files
authored
[SPIR-V] Correct/improve declaration of SPIR-V builtins (#1519)
Make the address space overloads more flexible by supporting OpenCL and SYCL. Correct the signature of __spirv_ocl_native_* and __spirv_ocl_half_* builtins. Correct the naming of overloads of __spirv_ocl_vload* and __spirv_ocl_vstore* builtins. Add missing overloads for conversion with specific rounding modes and saturation. Remove inexistent __spirv_All(bool) and __spirv_Any(bool) overloads. Signed-off-by: Victor Lomuller <[email protected]>
1 parent bb8fce9 commit 5beec6d

File tree

1 file changed

+82
-79
lines changed

1 file changed

+82
-79
lines changed

clang/lib/Sema/SPIRVBuiltins.td

+82-79
Original file line numberDiff line numberDiff line change
@@ -485,23 +485,16 @@ foreach name = ["half_cos",
485485
"half_exp", "half_exp2", "half_exp10",
486486
"half_log", "half_log2", "half_log10",
487487
"half_recip", "half_rsqrt",
488-
"half_sin", "half_sqrt", "half_tan"] in {
489-
def : ConstOCLSPVBuiltin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar]>;
490-
}
491-
492-
foreach name = ["half_divide", "half_powr"] in {
493-
def : ConstOCLSPVBuiltin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar]>;
494-
}
495-
496-
foreach name = ["native_cos", "native_exp", "native_exp2", "native_exp10",
488+
"half_sin", "half_sqrt", "half_tan",
489+
"native_cos", "native_exp", "native_exp2", "native_exp10",
497490
"native_log", "native_log2", "native_log10",
498491
"native_recip", "native_rsqrt",
499492
"native_sin", "native_sqrt", "native_tan"] in {
500-
def : ConstOCLSPVBuiltin<name, [FGenTypeN, FGenTypeN]>;
493+
def : ConstOCLSPVBuiltin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar]>;
501494
}
502495

503-
foreach name = ["native_divide", "native_powr"] in {
504-
def : ConstOCLSPVBuiltin<name, [FGenTypeN, FGenTypeN, FGenTypeN]>;
496+
foreach name = ["half_divide", "half_powr", "native_divide", "native_powr"] in {
497+
def : ConstOCLSPVBuiltin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar]>;
505498
}
506499

507500
// 2.2. Integer instructions
@@ -635,20 +628,22 @@ foreach VSize = [2, 3, 4, 8, 16] in {
635628
}
636629
}
637630
foreach name = ["vloada_halfn", "vload_halfn"] in {
638-
def : OCLSPVBuiltin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
631+
def : OCLSPVBuiltin<name # "_Rfloat" # VSize, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
639632
}
640633
}
641634
foreach AS = [GlobalAS, LocalAS, PrivateAS, GenericAS, DefaultAS] in {
642635
foreach Ty = TLAll.List in {
643636
foreach name = ["vstoren"] in {
644-
def : OCLSPVBuiltin<name, [Void, VectorType<Ty, VSize>, Size, PointerType<ConstType<Ty>, AS>]>;
637+
def : OCLSPVBuiltin<name, [Void, VectorType<Ty, VSize>, Size, PointerType<Ty, AS>]>;
645638
}
646639
}
647-
foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
648-
foreach name = ["vstore_halfn" # rnd, "vstorea_halfn" # rnd] in {
649-
def : OCLSPVBuiltin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
650-
def : OCLSPVBuiltin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
651-
}
640+
foreach name = ["vstore_halfn", "vstorea_halfn"] in {
641+
def : OCLSPVBuiltin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
642+
def : OCLSPVBuiltin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
643+
}
644+
foreach name = ["vstore_halfn_r", "vstorea_halfn_r"] in {
645+
def : OCLSPVBuiltin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>, UInt]>;
646+
def : OCLSPVBuiltin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>, UInt]>;
652647
}
653648
}
654649
}
@@ -660,11 +655,13 @@ foreach AS = [GlobalAS, LocalAS, PrivateAS, ConstantAS, GenericAS, DefaultAS] in
660655
}
661656

662657
foreach AS = [GlobalAS, LocalAS, PrivateAS, GenericAS, DefaultAS] in {
663-
foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
664-
foreach name = ["vstore_half" # rnd] in {
665-
def : OCLSPVBuiltin<name, [Void, Float, Size, PointerType<Half, AS>]>;
666-
def : OCLSPVBuiltin<name, [Void, Double, Size, PointerType<Half, AS>]>;
667-
}
658+
foreach name = ["vstore_half"] in {
659+
def : OCLSPVBuiltin<name, [Void, Float, Size, PointerType<Half, AS>]>;
660+
def : OCLSPVBuiltin<name, [Void, Double, Size, PointerType<Half, AS>]>;
661+
}
662+
foreach name = ["vstore_half_r"] in {
663+
def : OCLSPVBuiltin<name, [Void, Float, Size, PointerType<Half, AS>, UInt]>;
664+
def : OCLSPVBuiltin<name, [Void, Double, Size, PointerType<Half, AS>, UInt]>;
668665
}
669666
}
670667

@@ -710,72 +707,79 @@ foreach name = ["GenericPtrMemSemantics"] in {
710707
}
711708

712709
// 3.32.11. Conversion Instructions
713-
714-
foreach IType = [UChar, UShort, UInt, ULong] in {
715-
foreach FType = [Float, Double, Half] in {
716-
def : SPVBuiltin<"ConvertUToF_R" # FType.Name, [FType, IType], Attr.Const>;
717-
foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
718-
def : SPVBuiltin<"ConvertFToU_R" # IType.Name # rnd, [IType, FType], Attr.Const>;
719-
}
720-
foreach v = [2, 3, 4, 8, 16] in {
721-
def : SPVBuiltin<"ConvertFToU_R" # IType.Name # v,
722-
[VectorType<IType, v>, VectorType<FType, v>],
723-
Attr.Const>;
724-
def : SPVBuiltin<"ConvertUToF_R" # FType.Name # v,
725-
[VectorType<FType, v>, VectorType<IType, v>],
726-
Attr.Const>;
727-
}
728-
}
729-
}
730-
731-
foreach IType = [Char, Short, Int, Long] in {
732-
foreach FType = [Float, Double, Half] in {
733-
def : SPVBuiltin<"ConvertSToF_R" # FType.Name, [FType, IType], Attr.Const>;
734-
foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
735-
def : SPVBuiltin<"ConvertFToS_R" # IType.Name # rnd, [IType, FType], Attr.Const>;
736-
}
737-
foreach v = [2, 3, 4, 8, 16] in {
738-
def : SPVBuiltin<"ConvertFToS_R" # IType.Name # v,
739-
[VectorType<IType, v>, VectorType<FType, v>],
740-
Attr.Const>;
741-
def : SPVBuiltin<"ConvertSToF_R" # FType.Name # v,
742-
[VectorType<FType, v>, VectorType<IType, v>],
743-
Attr.Const>;
710+
foreach rnd = ["", "_rte", "_rtn", "_rtp", "_rtz"] in {
711+
foreach IType = TLUnsignedInts.List in {
712+
foreach FType = TLFloat.List in {
713+
foreach sat = ["", "_sat"] in {
714+
def : SPVBuiltin<"ConvertFToU_R" # IType.Name # sat # rnd, [IType, FType], Attr.Const>;
715+
}
716+
def : SPVBuiltin<"ConvertUToF_R" # FType.Name # rnd, [FType, IType], Attr.Const>;
717+
foreach v = [2, 3, 4, 8, 16] in {
718+
foreach sat = ["", "_sat"] in {
719+
def : SPVBuiltin<"ConvertFToU_R" # IType.Name # v # sat # rnd,
720+
[VectorType<IType, v>, VectorType<FType, v>],
721+
Attr.Const>;
722+
}
723+
def : SPVBuiltin<"ConvertUToF_R" # FType.Name # v # rnd,
724+
[VectorType<FType, v>, VectorType<IType, v>],
725+
Attr.Const>;
726+
}
744727
}
745728
}
746-
}
747729

748-
foreach InType = TLAll.List in {
749-
foreach OutType = TLUnsignedInts.List in {
750-
if !ne(OutType.ElementSize, InType.ElementSize) then {
751-
def : SPVBuiltin<"UConvert_R" # OutType.Name, [OutType, InType], Attr.Const>;
730+
foreach IType = TLSignedInts.List in {
731+
foreach FType = TLFloat.List in {
732+
foreach sat = ["", "_sat"] in {
733+
def : SPVBuiltin<"ConvertFToS_R" # IType.Name # sat # rnd, [IType, FType], Attr.Const>;
734+
}
735+
def : SPVBuiltin<"ConvertSToF_R" # FType.Name # rnd, [FType, IType], Attr.Const>;
752736
foreach v = [2, 3, 4, 8, 16] in {
753-
def : SPVBuiltin<"UConvert_R" # OutType.Name # v,
754-
[VectorType<OutType, v>, VectorType<InType, v>],
737+
foreach sat = ["", "_sat"] in {
738+
def : SPVBuiltin<"ConvertFToS_R" # IType.Name # v # sat # rnd,
739+
[VectorType<IType, v>, VectorType<FType, v>],
740+
Attr.Const>;
741+
}
742+
def : SPVBuiltin<"ConvertSToF_R" # FType.Name # v # rnd,
743+
[VectorType<FType, v>, VectorType<IType, v>],
755744
Attr.Const>;
756745
}
757746
}
758747
}
759-
foreach OutType = TLSignedInts.List in {
760-
if !ne(OutType.ElementSize, InType.ElementSize) then {
761-
def : SPVBuiltin<"SConvert_R" # OutType.Name, [OutType, InType], Attr.Const>;
762-
foreach v = [2, 3, 4, 8, 16] in {
763-
def : SPVBuiltin<"SConvert_R" # OutType.Name # v,
764-
[VectorType<OutType, v>, VectorType<InType, v>],
765-
Attr.Const>;
748+
749+
foreach InType = TLFloat.List in {
750+
foreach OutType = TLFloat.List in {
751+
if !ne(OutType.ElementSize, InType.ElementSize) then {
752+
def : SPVBuiltin<"FConvert_R" # OutType.Name # rnd, [OutType, InType], Attr.Const>;
753+
foreach v = [2, 3, 4, 8, 16] in {
754+
def : SPVBuiltin<"FConvert_R" # OutType.Name # v # rnd,
755+
[VectorType<OutType, v>, VectorType<InType, v>],
756+
Attr.Const>;
757+
}
766758
}
767759
}
768760
}
769761
}
770762

771-
foreach InType = TLFloat.List in {
772-
foreach OutType = TLFloat.List in {
773-
if !ne(OutType.ElementSize, InType.ElementSize) then {
774-
def : SPVBuiltin<"FConvert_R" # OutType.Name, [OutType, InType], Attr.Const>;
775-
foreach v = [2, 3, 4, 8, 16] in {
776-
def : SPVBuiltin<"FConvert_R" # OutType.Name # v,
777-
[VectorType<OutType, v>, VectorType<InType, v>],
778-
Attr.Const>;
763+
foreach sat = ["", "_sat"] in {
764+
foreach InType = TLAllInts.List in {
765+
foreach OutType = TLUnsignedInts.List in {
766+
if !ne(OutType.ElementSize, InType.ElementSize) then {
767+
def : SPVBuiltin<"UConvert_R" # OutType.Name # sat, [OutType, InType], Attr.Const>;
768+
foreach v = [2, 3, 4, 8, 16] in {
769+
def : SPVBuiltin<"UConvert_R" # OutType.Name # v # sat,
770+
[VectorType<OutType, v>, VectorType<InType, v>],
771+
Attr.Const>;
772+
}
773+
}
774+
}
775+
foreach OutType = TLSignedInts.List in {
776+
if !ne(OutType.ElementSize, InType.ElementSize) then {
777+
def : SPVBuiltin<"SConvert_R" # OutType.Name # sat, [OutType, InType], Attr.Const>;
778+
foreach v = [2, 3, 4, 8, 16] in {
779+
def : SPVBuiltin<"SConvert_R" # OutType.Name # v # sat,
780+
[VectorType<OutType, v>, VectorType<InType, v>],
781+
Attr.Const>;
782+
}
779783
}
780784
}
781785
}
@@ -809,7 +813,7 @@ foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
809813

810814
foreach Type = TLFloat.List in {
811815
foreach v = [2, 3, 4, 8, 16] in {
812-
def : SPVBuiltin<"VectorTimesScalar", [VectorType<Type, v>, VectorType<Type, v>, Type]>;
816+
def : SPVBuiltin<"VectorTimesScalar", [VectorType<Type, v>, VectorType<Type, v>, Type], Attr.Const>;
813817
}
814818
}
815819

@@ -820,7 +824,6 @@ foreach name = ["Dot"] in {
820824
}
821825

822826
foreach name = ["Any", "All"] in {
823-
def : SPVBuiltin<name, [Bool, Bool], Attr.Const>;
824827
def : SPVBuiltin<name, [Bool, GenTypeSCharVecNoScalar], Attr.Const>;
825828
}
826829

0 commit comments

Comments
 (0)