From ad01615113f85c5dd47dcc9897d38dd21b54f8c0 Mon Sep 17 00:00:00 2001 From: Victor Lomuller Date: Tue, 14 Apr 2020 14:47:05 +0100 Subject: [PATCH] [SPIR-V] Correct/improve declaration of SPIR-V builtins 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 --- clang/lib/Sema/SPIRVBuiltins.td | 161 ++++++++++++++++---------------- 1 file changed, 82 insertions(+), 79 deletions(-) diff --git a/clang/lib/Sema/SPIRVBuiltins.td b/clang/lib/Sema/SPIRVBuiltins.td index e049fb2cb63c..d9c81db7a9f7 100644 --- a/clang/lib/Sema/SPIRVBuiltins.td +++ b/clang/lib/Sema/SPIRVBuiltins.td @@ -485,23 +485,16 @@ foreach name = ["half_cos", "half_exp", "half_exp2", "half_exp10", "half_log", "half_log2", "half_log10", "half_recip", "half_rsqrt", - "half_sin", "half_sqrt", "half_tan"] in { - def : ConstOCLSPVBuiltin; -} - -foreach name = ["half_divide", "half_powr"] in { - def : ConstOCLSPVBuiltin; -} - -foreach name = ["native_cos", "native_exp", "native_exp2", "native_exp10", + "half_sin", "half_sqrt", "half_tan", + "native_cos", "native_exp", "native_exp2", "native_exp10", "native_log", "native_log2", "native_log10", "native_recip", "native_rsqrt", "native_sin", "native_sqrt", "native_tan"] in { - def : ConstOCLSPVBuiltin; + def : ConstOCLSPVBuiltin; } -foreach name = ["native_divide", "native_powr"] in { - def : ConstOCLSPVBuiltin; +foreach name = ["half_divide", "half_powr", "native_divide", "native_powr"] in { + def : ConstOCLSPVBuiltin; } // 2.2. Integer instructions @@ -635,20 +628,22 @@ foreach VSize = [2, 3, 4, 8, 16] in { } } foreach name = ["vloada_halfn", "vload_halfn"] in { - def : OCLSPVBuiltin, Size, PointerType, AS>]>; + def : OCLSPVBuiltin, Size, PointerType, AS>]>; } } foreach AS = [GlobalAS, LocalAS, PrivateAS, GenericAS, DefaultAS] in { foreach Ty = TLAll.List in { foreach name = ["vstoren"] in { - def : OCLSPVBuiltin, Size, PointerType, AS>]>; + def : OCLSPVBuiltin, Size, PointerType]>; } } - foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in { - foreach name = ["vstore_halfn" # rnd, "vstorea_halfn" # rnd] in { - def : OCLSPVBuiltin, Size, PointerType]>; - def : OCLSPVBuiltin, Size, PointerType]>; - } + foreach name = ["vstore_halfn", "vstorea_halfn"] in { + def : OCLSPVBuiltin, Size, PointerType]>; + def : OCLSPVBuiltin, Size, PointerType]>; + } + foreach name = ["vstore_halfn_r", "vstorea_halfn_r"] in { + def : OCLSPVBuiltin, Size, PointerType, UInt]>; + def : OCLSPVBuiltin, Size, PointerType, UInt]>; } } } @@ -660,11 +655,13 @@ foreach AS = [GlobalAS, LocalAS, PrivateAS, ConstantAS, GenericAS, DefaultAS] in } foreach AS = [GlobalAS, LocalAS, PrivateAS, GenericAS, DefaultAS] in { - foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in { - foreach name = ["vstore_half" # rnd] in { - def : OCLSPVBuiltin]>; - def : OCLSPVBuiltin]>; - } + foreach name = ["vstore_half"] in { + def : OCLSPVBuiltin]>; + def : OCLSPVBuiltin]>; + } + foreach name = ["vstore_half_r"] in { + def : OCLSPVBuiltin, UInt]>; + def : OCLSPVBuiltin, UInt]>; } } @@ -710,72 +707,79 @@ foreach name = ["GenericPtrMemSemantics"] in { } // 3.32.11. Conversion Instructions - -foreach IType = [UChar, UShort, UInt, ULong] in { - foreach FType = [Float, Double, Half] in { - def : SPVBuiltin<"ConvertUToF_R" # FType.Name, [FType, IType], Attr.Const>; - foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in { - def : SPVBuiltin<"ConvertFToU_R" # IType.Name # rnd, [IType, FType], Attr.Const>; - } - foreach v = [2, 3, 4, 8, 16] in { - def : SPVBuiltin<"ConvertFToU_R" # IType.Name # v, - [VectorType, VectorType], - Attr.Const>; - def : SPVBuiltin<"ConvertUToF_R" # FType.Name # v, - [VectorType, VectorType], - Attr.Const>; - } - } -} - -foreach IType = [Char, Short, Int, Long] in { - foreach FType = [Float, Double, Half] in { - def : SPVBuiltin<"ConvertSToF_R" # FType.Name, [FType, IType], Attr.Const>; - foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in { - def : SPVBuiltin<"ConvertFToS_R" # IType.Name # rnd, [IType, FType], Attr.Const>; - } - foreach v = [2, 3, 4, 8, 16] in { - def : SPVBuiltin<"ConvertFToS_R" # IType.Name # v, - [VectorType, VectorType], - Attr.Const>; - def : SPVBuiltin<"ConvertSToF_R" # FType.Name # v, - [VectorType, VectorType], - Attr.Const>; +foreach rnd = ["", "_rte", "_rtn", "_rtp", "_rtz"] in { + foreach IType = TLUnsignedInts.List in { + foreach FType = TLFloat.List in { + foreach sat = ["", "_sat"] in { + def : SPVBuiltin<"ConvertFToU_R" # IType.Name # sat # rnd, [IType, FType], Attr.Const>; + } + def : SPVBuiltin<"ConvertUToF_R" # FType.Name # rnd, [FType, IType], Attr.Const>; + foreach v = [2, 3, 4, 8, 16] in { + foreach sat = ["", "_sat"] in { + def : SPVBuiltin<"ConvertFToU_R" # IType.Name # v # sat # rnd, + [VectorType, VectorType], + Attr.Const>; + } + def : SPVBuiltin<"ConvertUToF_R" # FType.Name # v # rnd, + [VectorType, VectorType], + Attr.Const>; + } } } -} -foreach InType = TLAll.List in { - foreach OutType = TLUnsignedInts.List in { - if !ne(OutType.ElementSize, InType.ElementSize) then { - def : SPVBuiltin<"UConvert_R" # OutType.Name, [OutType, InType], Attr.Const>; + foreach IType = TLSignedInts.List in { + foreach FType = TLFloat.List in { + foreach sat = ["", "_sat"] in { + def : SPVBuiltin<"ConvertFToS_R" # IType.Name # sat # rnd, [IType, FType], Attr.Const>; + } + def : SPVBuiltin<"ConvertSToF_R" # FType.Name # rnd, [FType, IType], Attr.Const>; foreach v = [2, 3, 4, 8, 16] in { - def : SPVBuiltin<"UConvert_R" # OutType.Name # v, - [VectorType, VectorType], + foreach sat = ["", "_sat"] in { + def : SPVBuiltin<"ConvertFToS_R" # IType.Name # v # sat # rnd, + [VectorType, VectorType], + Attr.Const>; + } + def : SPVBuiltin<"ConvertSToF_R" # FType.Name # v # rnd, + [VectorType, VectorType], Attr.Const>; } } } - foreach OutType = TLSignedInts.List in { - if !ne(OutType.ElementSize, InType.ElementSize) then { - def : SPVBuiltin<"SConvert_R" # OutType.Name, [OutType, InType], Attr.Const>; - foreach v = [2, 3, 4, 8, 16] in { - def : SPVBuiltin<"SConvert_R" # OutType.Name # v, - [VectorType, VectorType], - Attr.Const>; + + foreach InType = TLFloat.List in { + foreach OutType = TLFloat.List in { + if !ne(OutType.ElementSize, InType.ElementSize) then { + def : SPVBuiltin<"FConvert_R" # OutType.Name # rnd, [OutType, InType], Attr.Const>; + foreach v = [2, 3, 4, 8, 16] in { + def : SPVBuiltin<"FConvert_R" # OutType.Name # v # rnd, + [VectorType, VectorType], + Attr.Const>; + } } } } } -foreach InType = TLFloat.List in { - foreach OutType = TLFloat.List in { - if !ne(OutType.ElementSize, InType.ElementSize) then { - def : SPVBuiltin<"FConvert_R" # OutType.Name, [OutType, InType], Attr.Const>; - foreach v = [2, 3, 4, 8, 16] in { - def : SPVBuiltin<"FConvert_R" # OutType.Name # v, - [VectorType, VectorType], - Attr.Const>; +foreach sat = ["", "_sat"] in { + foreach InType = TLAllInts.List in { + foreach OutType = TLUnsignedInts.List in { + if !ne(OutType.ElementSize, InType.ElementSize) then { + def : SPVBuiltin<"UConvert_R" # OutType.Name # sat, [OutType, InType], Attr.Const>; + foreach v = [2, 3, 4, 8, 16] in { + def : SPVBuiltin<"UConvert_R" # OutType.Name # v # sat, + [VectorType, VectorType], + Attr.Const>; + } + } + } + foreach OutType = TLSignedInts.List in { + if !ne(OutType.ElementSize, InType.ElementSize) then { + def : SPVBuiltin<"SConvert_R" # OutType.Name # sat, [OutType, InType], Attr.Const>; + foreach v = [2, 3, 4, 8, 16] in { + def : SPVBuiltin<"SConvert_R" # OutType.Name # v # sat, + [VectorType, VectorType], + Attr.Const>; + } } } } @@ -809,7 +813,7 @@ foreach AS = [GlobalAS, LocalAS, PrivateAS] in { foreach Type = TLFloat.List in { foreach v = [2, 3, 4, 8, 16] in { - def : SPVBuiltin<"VectorTimesScalar", [VectorType, VectorType, Type]>; + def : SPVBuiltin<"VectorTimesScalar", [VectorType, VectorType, Type], Attr.Const>; } } @@ -820,7 +824,6 @@ foreach name = ["Dot"] in { } foreach name = ["Any", "All"] in { - def : SPVBuiltin; def : SPVBuiltin; }