diff --git a/clang/lib/Sema/OpenCLBuiltins.td b/clang/lib/Sema/OpenCLBuiltins.td --- a/clang/lib/Sema/OpenCLBuiltins.td +++ b/clang/lib/Sema/OpenCLBuiltins.td @@ -543,9 +543,10 @@ def : Builtin; } -// --- Version dependent --- -let MaxVersion = CL20 in { - foreach AS = [GlobalAS, LocalAS, PrivateAS] in { +// The following math builtins take pointer arguments. Which overloads are +// available depends on whether the generic address space feature is enabled. +multiclass MathWithPointer addrspaces> { + foreach AS = addrspaces in { foreach name = ["fract", "modf", "sincos"] in { def : Builtin]>; } @@ -561,19 +562,12 @@ } } } + +let MaxVersion = CL20 in { + defm : MathWithPointer<[GlobalAS, LocalAS, PrivateAS]>; +} let MinVersion = CL20 in { - foreach name = ["fract", "modf", "sincos"] in { - def : Builtin]>; - } - foreach name = ["frexp", "lgamma_r"] in { - foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in { - def : Builtin]>; - } } - foreach name = ["remquo"] in { - foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in { - def : Builtin]>; - } - } + defm : MathWithPointer<[GenericAS]>; } // --- Table 9 --- @@ -783,10 +777,8 @@ // OpenCL v1.1 s6.11.7, v1.2 s6.12.7, v2.0 s6.13.7 - Vector Data Load and Store Functions // OpenCL Extension v1.1 s9.3.6 and s9.6.6, v1.2 s9.5.6, v2.0 s5.1.6 and s6.1.6 - Vector Data Load and Store Functions // --- Table 15 --- -// Variants for OpenCL versions below 2.0, using pointers to the global, local -// and private address spaces. -let MaxVersion = CL20 in { - foreach AS = [GlobalAS, LocalAS, PrivateAS] in { +multiclass VloadVstore addrspaces, bit defStores> { + foreach AS = addrspaces in { foreach VSize = [2, 3, 4, 8, 16] in { foreach name = ["vload" # VSize] in { def : Builtin, Size, PointerType, AS>]>; @@ -801,116 +793,45 @@ def : Builtin, Size, PointerType, AS>]>; def : Builtin, Size, PointerType, AS>]>; } - foreach name = ["vstore" # VSize] in { - def : Builtin, Size, PointerType]>; - def : Builtin, Size, PointerType]>; - def : Builtin, Size, PointerType]>; - def : Builtin, Size, PointerType]>; - def : Builtin, Size, PointerType]>; - def : Builtin, Size, PointerType]>; - def : Builtin, Size, PointerType]>; - def : Builtin, Size, PointerType]>; - def : Builtin, Size, PointerType]>; - def : Builtin, Size, PointerType]>; - def : Builtin, Size, PointerType]>; - } foreach name = ["vloada_half" # VSize] in { def : Builtin, Size, PointerType, AS>]>; } - foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in { - foreach name = ["vstorea_half" # VSize # rnd] in { - def : Builtin, Size, PointerType]>; - def : Builtin, Size, PointerType]>; + if defStores then { + foreach name = ["vstore" # VSize] in { + def : Builtin, Size, PointerType]>; + def : Builtin, Size, PointerType]>; + def : Builtin, Size, PointerType]>; + def : Builtin, Size, PointerType]>; + def : Builtin, Size, PointerType]>; + def : Builtin, Size, PointerType]>; + def : Builtin, Size, PointerType]>; + def : Builtin, Size, PointerType]>; + def : Builtin, Size, PointerType]>; + def : Builtin, Size, PointerType]>; + def : Builtin, Size, PointerType]>; + } + foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in { + foreach name = ["vstorea_half" # VSize # rnd] in { + def : Builtin, Size, PointerType]>; + def : Builtin, Size, PointerType]>; + } } } } } } -// Variants for OpenCL versions above 2.0, using pointers to the generic -// address space. -let MinVersion = CL20 in { - foreach VSize = [2, 3, 4, 8, 16] in { - foreach name = ["vload" # VSize] in { - def : Builtin, Size, PointerType, GenericAS>]>; - def : Builtin, Size, PointerType, GenericAS>]>; - def : Builtin, Size, PointerType, GenericAS>]>; - def : Builtin, Size, PointerType, GenericAS>]>; - def : Builtin, Size, PointerType, GenericAS>]>; - def : Builtin, Size, PointerType, GenericAS>]>; - def : Builtin, Size, PointerType, GenericAS>]>; - def : Builtin, Size, PointerType, GenericAS>]>; - def : Builtin, Size, PointerType, GenericAS>]>; - def : Builtin, Size, PointerType, GenericAS>]>; - def : Builtin, Size, PointerType, GenericAS>]>; - } - foreach name = ["vstore" # VSize] in { - def : Builtin, Size, PointerType]>; - def : Builtin, Size, PointerType]>; - def : Builtin, Size, PointerType]>; - def : Builtin, Size, PointerType]>; - def : Builtin, Size, PointerType]>; - def : Builtin, Size, PointerType]>; - def : Builtin, Size, PointerType]>; - def : Builtin, Size, PointerType]>; - def : Builtin, Size, PointerType]>; - def : Builtin, Size, PointerType]>; - def : Builtin, Size, PointerType]>; - } - foreach name = ["vloada_half" # VSize] in { - def : Builtin, Size, PointerType, GenericAS>]>; - } - foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in { - foreach name = ["vstorea_half" # VSize # rnd] in { - def : Builtin, Size, PointerType]>; - def : Builtin, Size, PointerType]>; - } - } - } -} -// Variants using pointers to the constant address space. -foreach VSize = [2, 3, 4, 8, 16] in { - foreach name = ["vload" # VSize] in { - def : Builtin, Size, PointerType, ConstantAS>]>; - def : Builtin, Size, PointerType, ConstantAS>]>; - def : Builtin, Size, PointerType, ConstantAS>]>; - def : Builtin, Size, PointerType, ConstantAS>]>; - def : Builtin, Size, PointerType, ConstantAS>]>; - def : Builtin, Size, PointerType, ConstantAS>]>; - def : Builtin, Size, PointerType, ConstantAS>]>; - def : Builtin, Size, PointerType, ConstantAS>]>; - def : Builtin, Size, PointerType, ConstantAS>]>; - def : Builtin, Size, PointerType, ConstantAS>]>; - def : Builtin, Size, PointerType, ConstantAS>]>; - } - foreach name = ["vloada_half" # VSize] in { - def : Builtin, Size, PointerType, ConstantAS>]>; - } -} + let MaxVersion = CL20 in { - foreach AS = [GlobalAS, LocalAS, PrivateAS] in { - def : Builtin<"vload_half", [Float, Size, PointerType, AS>]>; - def : Builtin<"vloada_half", [Float, Size, PointerType, AS>]>; - foreach VSize = [2, 3, 4, 8, 16] in { - foreach name = ["vload_half" # VSize] in { - def : Builtin, Size, PointerType, AS>]>; - } - } - foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in { - foreach name = ["vstore_half" # rnd, "vstorea_half" # rnd] in { - def : Builtin]>; - def : Builtin]>; - } - foreach VSize = [2, 3, 4, 8, 16] in { - foreach name = ["vstore_half" # VSize # rnd] in { - def : Builtin, Size, PointerType]>; - def : Builtin, Size, PointerType]>; - } - } - } - } + defm : VloadVstore<[GlobalAS, LocalAS, PrivateAS], 1>; } let MinVersion = CL20 in { - foreach AS = [GenericAS] in { + defm : VloadVstore<[GenericAS], 1>; +} +// vload with constant address space is available regardless of version. +defm : VloadVstore<[ConstantAS], 0>; + +multiclass VloadVstoreHalf addrspaces, bit defStores> { + foreach AS = addrspaces in { def : Builtin<"vload_half", [Float, Size, PointerType, AS>]>; def : Builtin<"vloada_half", [Float, Size, PointerType, AS>]>; foreach VSize = [2, 3, 4, 8, 16] in { @@ -918,30 +839,31 @@ def : Builtin, Size, PointerType, AS>]>; } } - foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in { - foreach name = ["vstore_half" # rnd, "vstorea_half" # rnd] in { - def : Builtin]>; - def : Builtin]>; - } - foreach VSize = [2, 3, 4, 8, 16] in { - foreach name = ["vstore_half" # VSize # rnd] in { - def : Builtin, Size, PointerType]>; - def : Builtin, Size, PointerType]>; + if defStores then { + foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in { + foreach name = ["vstore_half" # rnd, "vstorea_half" # rnd] in { + def : Builtin]>; + def : Builtin]>; + } + foreach VSize = [2, 3, 4, 8, 16] in { + foreach name = ["vstore_half" # VSize # rnd] in { + def : Builtin, Size, PointerType]>; + def : Builtin, Size, PointerType]>; + } } } } } } -foreach AS = [ConstantAS] in { - def : Builtin<"vload_half", [Float, Size, PointerType, AS>]>; - def : Builtin<"vloada_half", [Float, Size, PointerType, AS>]>; - foreach VSize = [2, 3, 4, 8, 16] in { - foreach name = ["vload_half" # VSize] in { - def : Builtin, Size, PointerType, AS>]>; - } - } +let MaxVersion = CL20 in { + defm : VloadVstoreHalf<[GlobalAS, LocalAS, PrivateAS], 1>; +} +let MinVersion = CL20 in { + defm : VloadVstoreHalf<[GenericAS], 1>; } +// vload with constant address space is available regardless of version. +defm : VloadVstoreHalf<[ConstantAS], 0>; // OpenCL v3.0 s6.15.8 - Synchronization Functions. def : Builtin<"barrier", [Void, MemFenceFlags], Attr.Convergent>;