diff --git a/clang/lib/Headers/opencl-c-base.h b/clang/lib/Headers/opencl-c-base.h index 7485386c823466..4f63e7bbdcbba5 100644 --- a/clang/lib/Headers/opencl-c-base.h +++ b/clang/lib/Headers/opencl-c-base.h @@ -68,6 +68,7 @@ // For the SPIR and SPIR-V target all features are supported. #if defined(__SPIR__) || defined(__SPIRV__) #define __opencl_c_atomic_scope_all_devices 1 +#define __opencl_c_read_write_images 1 #endif // defined(__SPIR__) #endif // (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300) diff --git a/clang/lib/Sema/OpenCLBuiltins.td b/clang/lib/Sema/OpenCLBuiltins.td index 38debc5aa9fc5a..df2f206041c105 100644 --- a/clang/lib/Sema/OpenCLBuiltins.td +++ b/clang/lib/Sema/OpenCLBuiltins.td @@ -80,11 +80,14 @@ def FuncExtKhrLocalInt32ExtendedAtomics : FunctionExtension<"cl_khr_local_int32 def FuncExtKhrInt64BaseAtomics : FunctionExtension<"cl_khr_int64_base_atomics">; def FuncExtKhrInt64ExtendedAtomics : FunctionExtension<"cl_khr_int64_extended_atomics">; def FuncExtKhrMipmapImage : FunctionExtension<"cl_khr_mipmap_image">; +def FuncExtKhrMipmapImageReadWrite : FunctionExtension<"cl_khr_mipmap_image __opencl_c_read_write_images">; def FuncExtKhrMipmapImageWrites : FunctionExtension<"cl_khr_mipmap_image_writes">; def FuncExtKhrGlMsaaSharing : FunctionExtension<"cl_khr_gl_msaa_sharing">; +def FuncExtKhrGlMsaaSharingReadWrite : FunctionExtension<"cl_khr_gl_msaa_sharing __opencl_c_read_write_images">; def FuncExtOpenCLCPipes : FunctionExtension<"__opencl_c_pipes">; def FuncExtOpenCLCWGCollectiveFunctions : FunctionExtension<"__opencl_c_work_group_collective_functions">; +def FuncExtOpenCLCReadWriteImages : FunctionExtension<"__opencl_c_read_write_images">; def FuncExtFloatAtomicsFp16GlobalLoadStore : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_global_atomic_load_store">; def FuncExtFloatAtomicsFp16LocalLoadStore : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_local_atomic_load_store">; def FuncExtFloatAtomicsFp16GenericLoadStore : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_global_atomic_load_store __opencl_c_ext_fp16_local_atomic_load_store">; @@ -1390,30 +1393,35 @@ foreach coordTy = [Int, Float] in { } // --- Table 23: Sampler-less Read Functions --- +multiclass ImageReadSamplerless { + foreach imgTy = [Image2d, Image1dArray] in { + def : Builtin<"read_imagef", [VectorType, ImageType, VectorType], Attr.Pure>; + def : Builtin<"read_imagei", [VectorType, ImageType, VectorType], Attr.Pure>; + def : Builtin<"read_imageui", [VectorType, ImageType, VectorType], Attr.Pure>; + } + foreach imgTy = [Image3d, Image2dArray] in { + def : Builtin<"read_imagef", [VectorType, ImageType, VectorType], Attr.Pure>; + def : Builtin<"read_imagei", [VectorType, ImageType, VectorType], Attr.Pure>; + def : Builtin<"read_imageui", [VectorType, ImageType, VectorType], Attr.Pure>; + } + foreach imgTy = [Image1d, Image1dBuffer] in { + def : Builtin<"read_imagef", [VectorType, ImageType, Int], Attr.Pure>; + def : Builtin<"read_imagei", [VectorType, ImageType, Int], Attr.Pure>; + def : Builtin<"read_imageui", [VectorType, ImageType, Int], Attr.Pure>; + } + def : Builtin<"read_imagef", [Float, ImageType, VectorType], Attr.Pure>; + def : Builtin<"read_imagef", [Float, ImageType, VectorType], Attr.Pure>; +} + let MinVersion = CL12 in { - foreach aQual = ["RO", "RW"] in { - foreach imgTy = [Image2d, Image1dArray] in { - def : Builtin<"read_imagef", [VectorType, ImageType, VectorType], Attr.Pure>; - def : Builtin<"read_imagei", [VectorType, ImageType, VectorType], Attr.Pure>; - def : Builtin<"read_imageui", [VectorType, ImageType, VectorType], Attr.Pure>; - } - foreach imgTy = [Image3d, Image2dArray] in { - def : Builtin<"read_imagef", [VectorType, ImageType, VectorType], Attr.Pure>; - def : Builtin<"read_imagei", [VectorType, ImageType, VectorType], Attr.Pure>; - def : Builtin<"read_imageui", [VectorType, ImageType, VectorType], Attr.Pure>; - } - foreach imgTy = [Image1d, Image1dBuffer] in { - def : Builtin<"read_imagef", [VectorType, ImageType, Int], Attr.Pure>; - def : Builtin<"read_imagei", [VectorType, ImageType, Int], Attr.Pure>; - def : Builtin<"read_imageui", [VectorType, ImageType, Int], Attr.Pure>; - } - def : Builtin<"read_imagef", [Float, ImageType, VectorType], Attr.Pure>; - def : Builtin<"read_imagef", [Float, ImageType, VectorType], Attr.Pure>; + defm : ImageReadSamplerless<"RO">; + let Extension = FuncExtOpenCLCReadWriteImages in { + defm : ImageReadSamplerless<"RW">; } } // --- Table 24: Image Write Functions --- -foreach aQual = ["WO", "RW"] in { +multiclass ImageWrite { foreach imgTy = [Image2d] in { def : Builtin<"write_imagef", [Void, ImageType, VectorType, VectorType]>; def : Builtin<"write_imagei", [Void, ImageType, VectorType, VectorType]>; @@ -1443,8 +1451,13 @@ foreach aQual = ["WO", "RW"] in { def : Builtin<"write_imagef", [Void, ImageType, VectorType, Float]>; } +defm : ImageWrite<"WO">; +let Extension = FuncExtOpenCLCReadWriteImages in { + defm : ImageWrite<"RW">; +} + // --- Table 25: Image Query Functions --- -foreach aQual = ["RO", "WO", "RW"] in { +multiclass ImageQuery { foreach imgTy = [Image1d, Image1dBuffer, Image2d, Image3d, Image1dArray, Image2dArray, Image2dDepth, Image2dArrayDepth] in { @@ -1468,6 +1481,12 @@ foreach aQual = ["RO", "WO", "RW"] in { } } +defm : ImageQuery<"RO">; +defm : ImageQuery<"WO">; +let Extension = FuncExtOpenCLCReadWriteImages in { + defm : ImageQuery<"RW">; +} + // OpenCL extension v2.0 s5.1.9: Built-in Image Read Functions // --- Table 8 --- foreach aQual = ["RO"] in { @@ -1488,7 +1507,7 @@ foreach aQual = ["RO"] in { // OpenCL extension v2.0 s5.1.10: Built-in Image Sampler-less Read Functions // --- Table 9 --- let MinVersion = CL12 in { - foreach aQual = ["RO", "RW"] in { + multiclass ImageReadHalf { foreach name = ["read_imageh"] in { foreach imgTy = [Image2d, Image1dArray] in { def : Builtin, ImageType, VectorType], Attr.Pure>; @@ -1501,10 +1520,14 @@ let MinVersion = CL12 in { } } } + defm : ImageReadHalf<"RO">; + let Extension = FuncExtOpenCLCReadWriteImages in { + defm : ImageReadHalf<"RW">; + } } // OpenCL extension v2.0 s5.1.11: Built-in Image Write Functions // --- Table 10 --- -foreach aQual = ["WO", "RW"] in { +multiclass ImageWriteHalf { foreach name = ["write_imageh"] in { def : Builtin, VectorType, VectorType]>; def : Builtin, VectorType, VectorType]>; @@ -1515,6 +1538,12 @@ foreach aQual = ["WO", "RW"] in { } } +defm : ImageWriteHalf<"WO">; +let Extension = FuncExtOpenCLCReadWriteImages in { + defm : ImageWriteHalf<"RW">; +} + + //-------------------------------------------------------------------- // OpenCL v2.0 s6.13.15 - Work-group Functions @@ -1688,14 +1717,24 @@ let Extension = FuncExtKhrMipmapImage in { } } } - // Added to section 6.13.14.5 - foreach aQual = ["RO", "WO", "RW"] in { - foreach imgTy = [Image1d, Image2d, Image3d, Image1dArray, Image2dArray, Image2dDepth, Image2dArrayDepth] in { - def : Builtin<"get_image_num_mip_levels", [Int, ImageType]>; - } +} + +// Added to section 6.13.14.5 +multiclass ImageQueryNumMipLevels { + foreach imgTy = [Image1d, Image2d, Image3d, Image1dArray, Image2dArray, Image2dDepth, Image2dArrayDepth] in { + def : Builtin<"get_image_num_mip_levels", [Int, ImageType]>; } } +let Extension = FuncExtKhrMipmapImage in { + defm : ImageQueryNumMipLevels<"RO">; + defm : ImageQueryNumMipLevels<"WO">; +} + +let Extension = FuncExtKhrMipmapImageReadWrite in { + defm : ImageQueryNumMipLevels<"RW">; +} + // Write functions are enabled using a separate extension. let Extension = FuncExtKhrMipmapImageWrites in { // Added to section 6.13.14.4. @@ -1734,39 +1773,48 @@ let Extension = FuncExtKhrMipmapImageWrites in { //-------------------------------------------------------------------- // OpenCL Extension v2.0 s18.3 - Creating OpenCL Memory Objects from OpenGL MSAA Textures -let Extension = FuncExtKhrGlMsaaSharing in { - // --- Table 6.13.14.3 --- - foreach aQual = ["RO", "RW"] in { - foreach imgTy = [Image2dMsaa] in { - def : Builtin<"read_imagef", [VectorType, ImageType, VectorType, Int], Attr.Pure>; - def : Builtin<"read_imagei", [VectorType, ImageType, VectorType, Int], Attr.Pure>; - def : Builtin<"read_imageui", [VectorType, ImageType, VectorType, Int], Attr.Pure>; - } - foreach imgTy = [Image2dArrayMsaa] in { - def : Builtin<"read_imagef", [VectorType, ImageType, VectorType, Int], Attr.Pure>; - def : Builtin<"read_imagei", [VectorType, ImageType, VectorType, Int], Attr.Pure>; - def : Builtin<"read_imageui", [VectorType, ImageType, VectorType, Int], Attr.Pure>; - } - foreach name = ["read_imagef"] in { - def : Builtin, VectorType, Int], Attr.Pure>; - def : Builtin, VectorType, Int], Attr.Pure>; - } - } - - // --- Table 6.13.14.5 --- - foreach aQual = ["RO", "WO", "RW"] in { - foreach imgTy = [Image2dMsaa, Image2dArrayMsaa, Image2dMsaaDepth, Image2dArrayMsaaDepth] in { - foreach name = ["get_image_width", "get_image_height", - "get_image_channel_data_type", "get_image_channel_order", - "get_image_num_samples"] in { - def : Builtin], Attr.Const>; - } - def : Builtin<"get_image_dim", [VectorType, ImageType], Attr.Const>; - } - foreach imgTy = [Image2dArrayMsaa, Image2dArrayMsaaDepth] in { - def : Builtin<"get_image_array_size", [Size, ImageType], Attr.Const>; +// --- Table 6.13.14.3 --- +multiclass ImageReadMsaa { + foreach imgTy = [Image2dMsaa] in { + def : Builtin<"read_imagef", [VectorType, ImageType, VectorType, Int], Attr.Pure>; + def : Builtin<"read_imagei", [VectorType, ImageType, VectorType, Int], Attr.Pure>; + def : Builtin<"read_imageui", [VectorType, ImageType, VectorType, Int], Attr.Pure>; + } + foreach imgTy = [Image2dArrayMsaa] in { + def : Builtin<"read_imagef", [VectorType, ImageType, VectorType, Int], Attr.Pure>; + def : Builtin<"read_imagei", [VectorType, ImageType, VectorType, Int], Attr.Pure>; + def : Builtin<"read_imageui", [VectorType, ImageType, VectorType, Int], Attr.Pure>; + } + foreach name = ["read_imagef"] in { + def : Builtin, VectorType, Int], Attr.Pure>; + def : Builtin, VectorType, Int], Attr.Pure>; + } +} + +// --- Table 6.13.14.5 --- +multiclass ImageQueryMsaa { + foreach imgTy = [Image2dMsaa, Image2dArrayMsaa, Image2dMsaaDepth, Image2dArrayMsaaDepth] in { + foreach name = ["get_image_width", "get_image_height", + "get_image_channel_data_type", "get_image_channel_order", + "get_image_num_samples"] in { + def : Builtin], Attr.Const>; } + def : Builtin<"get_image_dim", [VectorType, ImageType], Attr.Const>; } + foreach imgTy = [Image2dArrayMsaa, Image2dArrayMsaaDepth] in { + def : Builtin<"get_image_array_size", [Size, ImageType], Attr.Const>; + } +} + +let Extension = FuncExtKhrGlMsaaSharing in { + defm : ImageReadMsaa<"RO">; + defm : ImageQueryMsaa<"RO">; + defm : ImageQueryMsaa<"WO">; +} + +let Extension = FuncExtKhrGlMsaaSharingReadWrite in { + defm : ImageReadMsaa<"RW">; + defm : ImageQueryMsaa<"RW">; } //-------------------------------------------------------------------- diff --git a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl index 5da38c121e393a..be6e53a07bdf3a 100644 --- a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl +++ b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl @@ -74,6 +74,7 @@ typedef struct {int a;} ndrange_t; #define cl_khr_subgroup_ballot 1 #define cl_khr_subgroup_non_uniform_arithmetic 1 #define cl_khr_subgroup_clustered_reduce 1 +#define __opencl_c_read_write_images 1 #endif #endif