Files
llvm-project/libclc/opencl/lib/r600/image/read_image_impl.ll
Fraser Cormack 32cf55aef3 [libclc] Reorganize OpenCL builtins (#140557)
This commits moves all OpenCL builtins under a top-level 'opencl'
directory, akin to how the CLC builtins are organized. This new
structure aims to better convey the separation of the two layers and
that 'CLC' is not a subset of OpenCL or a libclc target.

In doing so this commit moves the location of the 'lib' directory to
match CLC: libclc/generic/lib/ becomes libclc/opencl/lib/generic/. This
allows us to remove some special casing in CMake and ensure a common
directory structure.

It also tries to better communicate that the OpenCL headers are
libclc-specific OpenCL headers and should not be confused with or used
as standard OpenCL headers. It does so by ensuring includes are of the
form <clc/opencl/*>. It might be that we don't specifically need the
libclc OpenCL headers and we simply could use clang's built-in
declarations, but we can revisit that later.

Aside from the code move, there is some code formatting and updating a
couple of OpenCL builtin includes to use the readily available gentype
helpers. This allows us to remove some '.inc' files.
2025-05-20 09:51:30 +01:00

55 lines
2.2 KiB
LLVM

;;===----------------------------------------------------------------------===;;
;
; Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
; See https://llvm.org/LICENSE.txt for license information.
; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
;
;;===----------------------------------------------------------------------===;;
%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> poison, 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
}