Changeset View
Changeset View
Standalone View
Standalone View
include/clang/Basic/OpenCLBuiltins.td
- This file was added.
//==--- OpenCLBuiltins.td - OpenCL builtin definitions --------------------===// | |||||
// | |||||
// The LLVM Compiler Infrastructure | |||||
// | |||||
// This file is distributed under the University of Illinois Open Source | |||||
// License. See LICENSE.TXT for details. | |||||
// | |||||
//===----------------------------------------------------------------------===// | |||||
class Type<string Name> { | |||||
string name = Name; | |||||
int vecWidth = 0; | |||||
int isPointer = 0; | |||||
string as = "clang::LangAS::Default"; | |||||
int has_rounding = 0; | |||||
int is_integer = 0; | |||||
} | |||||
class VectorType<Type Ty, int VecWidth> : Type<Ty.name> { | |||||
int vecWidth = VecWidth; | |||||
} | |||||
class AddressSpace<string _as> { | |||||
string as = _as; | |||||
} | |||||
def Global: AddressSpace<"clang::LangAS::opencl_global">; | |||||
def Constant: AddressSpace<"clang::LangAS::opencl_constant">; | |||||
def Generic: AddressSpace<"clang::LangAS::opencl_generic">; | |||||
class PointerType<Type Ty, AddressSpace AS = Global> : Type<Ty.name> { | |||||
int isPointer = 1; | |||||
string as = AS.as; | |||||
} | |||||
class Version<int v> { | |||||
int version = v; | |||||
} | |||||
def CL10: Version<100>; | |||||
def CL11: Version<110>; | |||||
def CL12: Version<120>; | |||||
def CL20: Version<200>; | |||||
def void_t: Type<"void_t">; | |||||
def size_t_t: Type<"size_t">; | |||||
let is_integer = 1 in { | |||||
def char_t : Type<"char">; | |||||
def uchar_t : Type<"uchar">; | |||||
def short_t : Type<"short">; | |||||
def ushort_t : Type<"ushort">; | |||||
def int_t : Type<"int">; | |||||
def uint_t : Type<"uint">; | |||||
def long_t : Type<"long">; | |||||
def ulong_t : Type<"ulong">; | |||||
} | |||||
def int2 : VectorType<int_t, 2>; | |||||
def half_t : Type<"half">; | |||||
let has_rounding = 1 in { | |||||
def float_t : Type<"float">; | |||||
def double_t : Type<"double">; | |||||
} | |||||
def float4_t : VectorType<float_t, 4>; | |||||
def image2d_ro_t : Type<"image2d_ro_t">; | |||||
def image2d_wo_t : Type<"image2d_wo_t">; | |||||
class Builtin<string Name, Type ReturnType, list<Type> Args> { | |||||
string name = Name; | |||||
string extension; | |||||
list<Type> args = !listconcat([ReturnType], Args); | |||||
string extension = ""; | |||||
Version version = CL10; | |||||
} | |||||
// Creates builtins for one argument BIFs, taking and returning the same type. | |||||
multiclass bi_vec<string name, Type ReturnType> { | |||||
def: Builtin<name, ReturnType, [ReturnType]>; | |||||
foreach v = [2, 3, 4, 8, 16] in { | |||||
def : Builtin<name, VectorType<ReturnType, v>, [VectorType<ReturnType, v>]>; | |||||
} | |||||
} | |||||
// Creates builtins for two argument BIFs, taking and returning the same type. | |||||
multiclass bi_vec2<string name, Type ReturnType> { | |||||
def: Builtin<name, ReturnType, [ReturnType]>; | |||||
foreach v = [2, 3, 4, 8, 16] in { | |||||
def : Builtin<name, VectorType<ReturnType, v>, [VectorType<ReturnType, v>, VectorType<ReturnType, v>]>; | |||||
} | |||||
} | |||||
// Creates builtins for two argument BIFs, taking a vector and a scale and returning the vector type. | |||||
multiclass bi_vec3<string name, Type ReturnType> { | |||||
foreach v = [2, 3, 4, 8, 16] in { | |||||
def : Builtin<name, VectorType<ReturnType, v>, [VectorType<ReturnType, v>, ReturnType]>; | |||||
} | |||||
} | |||||
// 6.12.2 | |||||
foreach name = ["acos", "acosh", "acospi", "asin", "asinh", "asinpi", "atan"] in { | |||||
foreach type = [float_t, double_t] in { | |||||
defm name#type : bi_vec<name, type>; | |||||
} | |||||
} | |||||
foreach name = ["atan2"] in { | |||||
foreach type = [float_t, double_t] in { | |||||
defm name#type : bi_vec2<name, type>; | |||||
} | |||||
} | |||||
foreach name = ["fmax", "fmin"] in { | |||||
foreach type = [float_t, double_t] in { | |||||
defm: bi_vec2<name, type>; | |||||
defm: bi_vec3<name, type>; | |||||
} | |||||
} | |||||
// example 'foo', to show using 'version' | |||||
def: Builtin<"foo_version", int_t, [PointerType<int_t, Global>]>; | |||||
let version = CL20 in { | |||||
def: Builtin<"foo_version", int_t, [PointerType<int_t, Constant>]>; | |||||
} | |||||
// Helper classes for the convert_ BIFs. | |||||
class SatModes<Type ty> { | |||||
list<string> modes = !if(ty.is_integer, ["", "_sat"], [""]); | |||||
} | |||||
class RoundingModes<Type ty, Type ty2> { | |||||
list<string> modes = !if(!or(ty.has_rounding, ty2.has_rounding), ["", "_rte", "_rtz", "_rtp", "_rtn"], [""]); | |||||
} | |||||
// Generate the convert_ builtins. | |||||
foreach type = [float_t, double_t, char_t, uchar_t, short_t, ushort_t, | |||||
int_t, uint_t, long_t, ulong_t] in { | |||||
foreach type2 = [float_t, double_t, char_t, uchar_t, short_t, ushort_t, | |||||
int_t, uint_t, long_t, ulong_t] in { | |||||
foreach sat = SatModes<type>.modes in { | |||||
foreach rte = RoundingModes<type, type2>.modes in { | |||||
def: Builtin<"convert_" # type.name # sat # rte, type, [type2]>; | |||||
foreach v = [2, 3, 4, 8, 16] in { | |||||
def: Builtin<"convert_" # type.name # v # sat # rte, VectorType<type, v>, [VectorType<type2, v>]>; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | |||||
// Example showing 'extension' | |||||
let extension = "cl_khr_subgroups" in { | |||||
def : Builtin<"get_sub_group_size", uint_t, []>; | |||||
} | |||||
// samplerless read image | |||||
def : Builtin<"read_imagef", float4_t, [image2d_ro_t, VectorType<int_t, 2>]>; | |||||
def : Builtin<"write_imagef", void_t, [image2d_wo_t, VectorType<int_t, 2>, VectorType<float_t, 4>]>; | |||||
// 6.11.1 | |||||
def get_work_dim : Builtin<"get_work_dim", uint_t, []>; | |||||
foreach name = ["get_global_size", "get_global_id", "get_local_size", | |||||
"get_local_id", "get_num_groups", "get_group_id", | |||||
"get_global_offset"] in { | |||||
def name : Builtin<name, size_t_t, [uint_t]>; | |||||
} |