diff options
author | Jan Vesely <jan.vesely@rutgers.edu> | 2017-10-10 18:10:21 +0000 |
---|---|---|
committer | Jan Vesely <jan.vesely@rutgers.edu> | 2017-10-10 18:10:21 +0000 |
commit | 3d349ea98e2bdf0493920acb4f7f6e15f0c4b9c2 (patch) | |
tree | 1cc44a0e4d2528fc974d6fcfb10a3c6a23c7742d /libclc/r600 | |
parent | 16b8b4715221fdb958831de1c8e8b43d3641ccb3 (diff) | |
download | llvm-3d349ea98e2bdf0493920acb4f7f6e15f0c4b9c2.zip llvm-3d349ea98e2bdf0493920acb4f7f6e15f0c4b9c2.tar.gz llvm-3d349ea98e2bdf0493920acb4f7f6e15f0c4b9c2.tar.bz2 |
Make image builtins r600/llvm-3.9 only
The implementation uses r600 sepcific intrinsics
LLVM-4 switched to _ro_t and _rw_t image types
Portions of the code can be moved back as more targets/llvm versions add image support
Reviewer: Aaron Watry
Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
llvm-svn: 315341
Diffstat (limited to 'libclc/r600')
-rw-r--r-- | libclc/r600/lib/SOURCES_3.9 | 15 | ||||
-rw-r--r-- | libclc/r600/lib/image/get_image_attributes_impl.ll | 87 | ||||
-rw-r--r-- | libclc/r600/lib/image/get_image_channel_data_type.cl | 13 | ||||
-rw-r--r-- | libclc/r600/lib/image/get_image_channel_order.cl | 13 | ||||
-rw-r--r-- | libclc/r600/lib/image/get_image_depth.cl | 8 | ||||
-rw-r--r-- | libclc/r600/lib/image/get_image_dim.cl | 9 | ||||
-rw-r--r-- | libclc/r600/lib/image/get_image_height.cl | 13 | ||||
-rw-r--r-- | libclc/r600/lib/image/get_image_width.cl | 13 | ||||
-rw-r--r-- | libclc/r600/lib/image/read_image_impl.ll | 46 | ||||
-rw-r--r-- | libclc/r600/lib/image/read_imagef.cl | 14 | ||||
-rw-r--r-- | libclc/r600/lib/image/read_imagei.cl | 23 | ||||
-rw-r--r-- | libclc/r600/lib/image/read_imageui.cl | 23 | ||||
-rw-r--r-- | libclc/r600/lib/image/write_image_impl.ll | 52 | ||||
-rw-r--r-- | libclc/r600/lib/image/write_imagef.cl | 9 | ||||
-rw-r--r-- | libclc/r600/lib/image/write_imagei.cl | 9 | ||||
-rw-r--r-- | libclc/r600/lib/image/write_imageui.cl | 9 |
16 files changed, 356 insertions, 0 deletions
diff --git a/libclc/r600/lib/SOURCES_3.9 b/libclc/r600/lib/SOURCES_3.9 new file mode 100644 index 0000000..a44a9ce --- /dev/null +++ b/libclc/r600/lib/SOURCES_3.9 @@ -0,0 +1,15 @@ +image/get_image_dim.cl +image/get_image_width.cl +image/get_image_height.cl +image/get_image_depth.cl +image/get_image_channel_data_type.cl +image/get_image_channel_order.cl +image/get_image_attributes_impl.ll +image/read_imagef.cl +image/read_imagei.cl +image/read_imageui.cl +image/read_image_impl.ll +image/write_imagef.cl +image/write_imagei.cl +image/write_imageui.cl +image/write_image_impl.ll diff --git a/libclc/r600/lib/image/get_image_attributes_impl.ll b/libclc/r600/lib/image/get_image_attributes_impl.ll new file mode 100644 index 0000000..7f1965d --- /dev/null +++ b/libclc/r600/lib/image/get_image_attributes_impl.ll @@ -0,0 +1,87 @@ +%opencl.image2d_t = type opaque +%opencl.image3d_t = type opaque + +declare i32 @llvm.OpenCL.image.get.resource.id.2d( + %opencl.image2d_t addrspace(1)*) nounwind readnone +declare i32 @llvm.OpenCL.image.get.resource.id.3d( + %opencl.image3d_t addrspace(1)*) nounwind readnone + +declare [3 x i32] @llvm.OpenCL.image.get.size.2d( + %opencl.image2d_t addrspace(1)*) nounwind readnone +declare [3 x i32] @llvm.OpenCL.image.get.size.3d( + %opencl.image3d_t addrspace(1)*) nounwind readnone + +declare [2 x i32] @llvm.OpenCL.image.get.format.2d( + %opencl.image2d_t addrspace(1)*) nounwind readnone +declare [2 x i32] @llvm.OpenCL.image.get.format.3d( + %opencl.image3d_t addrspace(1)*) nounwind readnone + +define i32 @__clc_get_image_width_2d( + %opencl.image2d_t addrspace(1)* nocapture %img) #0 { + %1 = tail call [3 x i32] @llvm.OpenCL.image.get.size.2d( + %opencl.image2d_t addrspace(1)* %img) + %2 = extractvalue [3 x i32] %1, 0 + ret i32 %2 +} +define i32 @__clc_get_image_width_3d( + %opencl.image3d_t addrspace(1)* nocapture %img) #0 { + %1 = tail call [3 x i32] @llvm.OpenCL.image.get.size.3d( + %opencl.image3d_t addrspace(1)* %img) + %2 = extractvalue [3 x i32] %1, 0 + ret i32 %2 +} + +define i32 @__clc_get_image_height_2d( + %opencl.image2d_t addrspace(1)* nocapture %img) #0 { + %1 = tail call [3 x i32] @llvm.OpenCL.image.get.size.2d( + %opencl.image2d_t addrspace(1)* %img) + %2 = extractvalue [3 x i32] %1, 1 + ret i32 %2 +} +define i32 @__clc_get_image_height_3d( + %opencl.image3d_t addrspace(1)* nocapture %img) #0 { + %1 = tail call [3 x i32] @llvm.OpenCL.image.get.size.3d( + %opencl.image3d_t addrspace(1)* %img) + %2 = extractvalue [3 x i32] %1, 1 + ret i32 %2 +} + +define i32 @__clc_get_image_depth_3d( + %opencl.image3d_t addrspace(1)* nocapture %img) #0 { + %1 = tail call [3 x i32] @llvm.OpenCL.image.get.size.3d( + %opencl.image3d_t addrspace(1)* %img) + %2 = extractvalue [3 x i32] %1, 2 + ret i32 %2 +} + +define i32 @__clc_get_image_channel_data_type_2d( + %opencl.image2d_t addrspace(1)* nocapture %img) #0 { + %1 = tail call [2 x i32] @llvm.OpenCL.image.get.format.2d( + %opencl.image2d_t addrspace(1)* %img) + %2 = extractvalue [2 x i32] %1, 0 + ret i32 %2 +} +define i32 @__clc_get_image_channel_data_type_3d( + %opencl.image3d_t addrspace(1)* nocapture %img) #0 { + %1 = tail call [2 x i32] @llvm.OpenCL.image.get.format.3d( + %opencl.image3d_t addrspace(1)* %img) + %2 = extractvalue [2 x i32] %1, 0 + ret i32 %2 +} + +define i32 @__clc_get_image_channel_order_2d( + %opencl.image2d_t addrspace(1)* nocapture %img) #0 { + %1 = tail call [2 x i32] @llvm.OpenCL.image.get.format.2d( + %opencl.image2d_t addrspace(1)* %img) + %2 = extractvalue [2 x i32] %1, 1 + ret i32 %2 +} +define i32 @__clc_get_image_channel_order_3d( + %opencl.image3d_t addrspace(1)* nocapture %img) #0 { + %1 = tail call [2 x i32] @llvm.OpenCL.image.get.format.3d( + %opencl.image3d_t addrspace(1)* %img) + %2 = extractvalue [2 x i32] %1, 1 + ret i32 %2 +} + +attributes #0 = { nounwind readnone alwaysinline } diff --git a/libclc/r600/lib/image/get_image_channel_data_type.cl b/libclc/r600/lib/image/get_image_channel_data_type.cl new file mode 100644 index 0000000..2a2478f --- /dev/null +++ b/libclc/r600/lib/image/get_image_channel_data_type.cl @@ -0,0 +1,13 @@ +#include <clc/clc.h> + +_CLC_DECL int __clc_get_image_channel_data_type_2d(image2d_t); +_CLC_DECL int __clc_get_image_channel_data_type_3d(image3d_t); + +_CLC_OVERLOAD _CLC_DEF int +get_image_channel_data_type(image2d_t image) { + return __clc_get_image_channel_data_type_2d(image); +} +_CLC_OVERLOAD _CLC_DEF int +get_image_channel_data_type(image3d_t image) { + return __clc_get_image_channel_data_type_3d(image); +} diff --git a/libclc/r600/lib/image/get_image_channel_order.cl b/libclc/r600/lib/image/get_image_channel_order.cl new file mode 100644 index 0000000..91e9b89 --- /dev/null +++ b/libclc/r600/lib/image/get_image_channel_order.cl @@ -0,0 +1,13 @@ +#include <clc/clc.h> + +_CLC_DECL int __clc_get_image_channel_order_2d(image2d_t); +_CLC_DECL int __clc_get_image_channel_order_3d(image3d_t); + +_CLC_OVERLOAD _CLC_DEF int +get_image_channel_order(image2d_t image) { + return __clc_get_image_channel_order_2d(image); +} +_CLC_OVERLOAD _CLC_DEF int +get_image_channel_order(image3d_t image) { + return __clc_get_image_channel_order_3d(image); +} diff --git a/libclc/r600/lib/image/get_image_depth.cl b/libclc/r600/lib/image/get_image_depth.cl new file mode 100644 index 0000000..1864645 --- /dev/null +++ b/libclc/r600/lib/image/get_image_depth.cl @@ -0,0 +1,8 @@ +#include <clc/clc.h> + +_CLC_DECL int __clc_get_image_depth_3d(image3d_t); + +_CLC_OVERLOAD _CLC_DEF int +get_image_depth(image3d_t image) { + return __clc_get_image_depth_3d(image); +} diff --git a/libclc/r600/lib/image/get_image_dim.cl b/libclc/r600/lib/image/get_image_dim.cl new file mode 100644 index 0000000..26dbd00 --- /dev/null +++ b/libclc/r600/lib/image/get_image_dim.cl @@ -0,0 +1,9 @@ +#include <clc/clc.h> + +_CLC_OVERLOAD _CLC_DEF int2 get_image_dim (image2d_t image) { + return (int2)(get_image_width(image), get_image_height(image)); +} +_CLC_OVERLOAD _CLC_DEF int4 get_image_dim (image3d_t image) { + return (int4)(get_image_width(image), get_image_height(image), + get_image_depth(image), 0); +} diff --git a/libclc/r600/lib/image/get_image_height.cl b/libclc/r600/lib/image/get_image_height.cl new file mode 100644 index 0000000..80b3640 --- /dev/null +++ b/libclc/r600/lib/image/get_image_height.cl @@ -0,0 +1,13 @@ +#include <clc/clc.h> + +_CLC_DECL int __clc_get_image_height_2d(image2d_t); +_CLC_DECL int __clc_get_image_height_3d(image3d_t); + +_CLC_OVERLOAD _CLC_DEF int +get_image_height(image2d_t image) { + return __clc_get_image_height_2d(image); +} +_CLC_OVERLOAD _CLC_DEF int +get_image_height(image3d_t image) { + return __clc_get_image_height_3d(image); +} diff --git a/libclc/r600/lib/image/get_image_width.cl b/libclc/r600/lib/image/get_image_width.cl new file mode 100644 index 0000000..29e4e94 --- /dev/null +++ b/libclc/r600/lib/image/get_image_width.cl @@ -0,0 +1,13 @@ +#include <clc/clc.h> + +_CLC_DECL int __clc_get_image_width_2d(image2d_t); +_CLC_DECL int __clc_get_image_width_3d(image3d_t); + +_CLC_OVERLOAD _CLC_DEF int +get_image_width(image2d_t image) { + return __clc_get_image_width_2d(image); +} +_CLC_OVERLOAD _CLC_DEF int +get_image_width(image3d_t image) { + return __clc_get_image_width_3d(image); +} diff --git a/libclc/r600/lib/image/read_image_impl.ll b/libclc/r600/lib/image/read_image_impl.ll new file mode 100644 index 0000000..229a252 --- /dev/null +++ b/libclc/r600/lib/image/read_image_impl.ll @@ -0,0 +1,46 @@ +%opencl.image2d_t = type opaque + +declare <4 x float> @llvm.R600.tex(<4 x float>, i32, i32, i32, i32, i32, i32, + i32, i32, i32) readnone +declare i32 @llvm.OpenCL.image.get.resource.id.2d( + %opencl.image2d_t addrspace(1)*) nounwind readnone +declare i32 @llvm.OpenCL.sampler.get.resource.id(i32) readnone + +define <4 x float> @__clc_v4f_from_v2f(<2 x float> %v) alwaysinline { + %e0 = extractelement <2 x float> %v, i32 0 + %e1 = extractelement <2 x float> %v, i32 1 + %res.0 = insertelement <4 x float> undef, float %e0, i32 0 + %res.1 = insertelement <4 x float> %res.0, float %e1, i32 1 + %res.2 = insertelement <4 x float> %res.1, float 0.0, i32 2 + %res.3 = insertelement <4 x float> %res.2, float 0.0, i32 3 + ret <4 x float> %res.3 +} + +define <4 x float> @__clc_read_imagef_tex( + %opencl.image2d_t addrspace(1)* nocapture %img, + i32 %sampler, <2 x float> %coord) alwaysinline { +entry: + %coord_v4 = call <4 x float> @__clc_v4f_from_v2f(<2 x float> %coord) + %smp_id = call i32 @llvm.OpenCL.sampler.get.resource.id(i32 %sampler) + %img_id = call i32 @llvm.OpenCL.image.get.resource.id.2d( + %opencl.image2d_t addrspace(1)* %img) + %tex_id = add i32 %img_id, 2 ; First 2 IDs are reserved. + + %coord_norm = and i32 %sampler, 1 + %is_norm = icmp eq i32 %coord_norm, 1 + br i1 %is_norm, label %NormCoord, label %UnnormCoord +NormCoord: + %data.norm = call <4 x float> @llvm.R600.tex( + <4 x float> %coord_v4, + i32 0, i32 0, i32 0, ; Offset. + i32 2, i32 %smp_id, + i32 1, i32 1, i32 1, i32 1) ; Normalized coords. + ret <4 x float> %data.norm +UnnormCoord: + %data.unnorm = call <4 x float> @llvm.R600.tex( + <4 x float> %coord_v4, + i32 0, i32 0, i32 0, ; Offset. + i32 %tex_id, i32 %smp_id, + i32 0, i32 0, i32 0, i32 0) ; Unnormalized coords. + ret <4 x float> %data.unnorm +} diff --git a/libclc/r600/lib/image/read_imagef.cl b/libclc/r600/lib/image/read_imagef.cl new file mode 100644 index 0000000..af80ada --- /dev/null +++ b/libclc/r600/lib/image/read_imagef.cl @@ -0,0 +1,14 @@ +#include <clc/clc.h> + +_CLC_DECL float4 __clc_read_imagef_tex(image2d_t, sampler_t, float2); + +_CLC_OVERLOAD _CLC_DEF float4 read_imagef(image2d_t image, sampler_t sampler, + int2 coord) { + float2 coord_float = (float2)(coord.x, coord.y); + return __clc_read_imagef_tex(image, sampler, coord_float); +} + +_CLC_OVERLOAD _CLC_DEF float4 read_imagef(image2d_t image, sampler_t sampler, + float2 coord) { + return __clc_read_imagef_tex(image, sampler, coord); +} diff --git a/libclc/r600/lib/image/read_imagei.cl b/libclc/r600/lib/image/read_imagei.cl new file mode 100644 index 0000000..b973aae --- /dev/null +++ b/libclc/r600/lib/image/read_imagei.cl @@ -0,0 +1,23 @@ +#include <clc/clc.h> + +_CLC_DECL float4 __clc_read_imagef_tex(image2d_t, sampler_t, float2); + +int4 __clc_reinterpret_v4f_to_v4i(float4 v) { + union { + int4 v4i; + float4 v4f; + } res = { .v4f = v}; + return res.v4i; +} + +_CLC_OVERLOAD _CLC_DEF int4 read_imagei(image2d_t image, sampler_t sampler, + int2 coord) { + float2 coord_float = (float2)(coord.x, coord.y); + return __clc_reinterpret_v4f_to_v4i( + __clc_read_imagef_tex(image, sampler, coord_float)); +} +_CLC_OVERLOAD _CLC_DEF int4 read_imagei(image2d_t image, sampler_t sampler, + float2 coord) { + return __clc_reinterpret_v4f_to_v4i( + __clc_read_imagef_tex(image, sampler, coord)); +} diff --git a/libclc/r600/lib/image/read_imageui.cl b/libclc/r600/lib/image/read_imageui.cl new file mode 100644 index 0000000..ec9836e --- /dev/null +++ b/libclc/r600/lib/image/read_imageui.cl @@ -0,0 +1,23 @@ +#include <clc/clc.h> + +_CLC_DECL float4 __clc_read_imagef_tex(image2d_t, sampler_t, float2); + +uint4 __clc_reinterpret_v4f_to_v4ui(float4 v) { + union { + uint4 v4ui; + float4 v4f; + } res = { .v4f = v}; + return res.v4ui; +} + +_CLC_OVERLOAD _CLC_DEF uint4 read_imageui(image2d_t image, sampler_t sampler, + int2 coord) { + float2 coord_float = (float2)(coord.x, coord.y); + return __clc_reinterpret_v4f_to_v4ui( + __clc_read_imagef_tex(image, sampler, coord_float)); +} +_CLC_OVERLOAD _CLC_DEF uint4 read_imageui(image2d_t image, sampler_t sampler, + float2 coord) { + return __clc_reinterpret_v4f_to_v4ui( + __clc_read_imagef_tex(image, sampler, coord)); +} diff --git a/libclc/r600/lib/image/write_image_impl.ll b/libclc/r600/lib/image/write_image_impl.ll new file mode 100644 index 0000000..265f5d6 --- /dev/null +++ b/libclc/r600/lib/image/write_image_impl.ll @@ -0,0 +1,52 @@ +%opencl.image2d_t = type opaque +%opencl.image3d_t = type opaque + +declare i32 @llvm.OpenCL.image.get.resource.id.2d( + %opencl.image2d_t addrspace(1)*) nounwind readnone +declare i32 @llvm.OpenCL.image.get.resource.id.3d( + %opencl.image3d_t addrspace(1)*) nounwind readnone + +declare void @llvm.r600.rat.store.typed(<4 x i32> %color, <4 x i32> %coord, i32 %rat_id) + +define void @__clc_write_imageui_2d( + %opencl.image2d_t addrspace(1)* nocapture %img, + <2 x i32> %coord, <4 x i32> %color) #0 { + + ; Coordinate int2 -> int4. + %e0 = extractelement <2 x i32> %coord, i32 0 + %e1 = extractelement <2 x i32> %coord, i32 1 + %coord.0 = insertelement <4 x i32> undef, i32 %e0, i32 0 + %coord.1 = insertelement <4 x i32> %coord.0, i32 %e1, i32 1 + %coord.2 = insertelement <4 x i32> %coord.1, i32 0, i32 2 + %coord.3 = insertelement <4 x i32> %coord.2, i32 0, i32 3 + + ; Get RAT ID. + %img_id = call i32 @llvm.OpenCL.image.get.resource.id.2d( + %opencl.image2d_t addrspace(1)* %img) + %rat_id = add i32 %img_id, 1 + + ; Call store intrinsic. + call void @llvm.r600.rat.store.typed(<4 x i32> %color, <4 x i32> %coord.3, i32 %rat_id) + ret void +} + +define void @__clc_write_imagei_2d( + %opencl.image2d_t addrspace(1)* nocapture %img, + <2 x i32> %coord, <4 x i32> %color) #0 { + call void @__clc_write_imageui_2d( + %opencl.image2d_t addrspace(1)* nocapture %img, + <2 x i32> %coord, <4 x i32> %color) + ret void +} + +define void @__clc_write_imagef_2d( + %opencl.image2d_t addrspace(1)* nocapture %img, + <2 x i32> %coord, <4 x float> %color) #0 { + %color.i32 = bitcast <4 x float> %color to <4 x i32> + call void @__clc_write_imageui_2d( + %opencl.image2d_t addrspace(1)* nocapture %img, + <2 x i32> %coord, <4 x i32> %color.i32) + ret void +} + +attributes #0 = { alwaysinline } diff --git a/libclc/r600/lib/image/write_imagef.cl b/libclc/r600/lib/image/write_imagef.cl new file mode 100644 index 0000000..4483fcf --- /dev/null +++ b/libclc/r600/lib/image/write_imagef.cl @@ -0,0 +1,9 @@ +#include <clc/clc.h> + +_CLC_DECL void __clc_write_imagef_2d(image2d_t image, int2 coord, float4 color); + +_CLC_OVERLOAD _CLC_DEF void +write_imagef(image2d_t image, int2 coord, float4 color) +{ + __clc_write_imagef_2d(image, coord, color); +} diff --git a/libclc/r600/lib/image/write_imagei.cl b/libclc/r600/lib/image/write_imagei.cl new file mode 100644 index 0000000..394a223 --- /dev/null +++ b/libclc/r600/lib/image/write_imagei.cl @@ -0,0 +1,9 @@ +#include <clc/clc.h> + +_CLC_DECL void __clc_write_imagei_2d(image2d_t image, int2 coord, int4 color); + +_CLC_OVERLOAD _CLC_DEF void +write_imagei(image2d_t image, int2 coord, int4 color) +{ + __clc_write_imagei_2d(image, coord, color); +} diff --git a/libclc/r600/lib/image/write_imageui.cl b/libclc/r600/lib/image/write_imageui.cl new file mode 100644 index 0000000..91344de --- /dev/null +++ b/libclc/r600/lib/image/write_imageui.cl @@ -0,0 +1,9 @@ +#include <clc/clc.h> + +_CLC_DECL void __clc_write_imageui_2d(image2d_t image, int2 coord, uint4 color); + +_CLC_OVERLOAD _CLC_DEF void +write_imageui(image2d_t image, int2 coord, uint4 color) +{ + __clc_write_imageui_2d(image, coord, color); +} |