Avoid explicitly declare OCL builtin match function

Hi, im pretty new to LLVM and clang.

Currently, I utilize the Clang Frontend to compile OpenCL kernel files and generate only LLVM IR as output. To achieve this, I use the C library of Clang and execute the clang::EmitLLVMOnlyAction.
the kernel likes:

#pragma OPENCL EXTENSION cl_khr_fp16 : enable
typedef half half4 __attribute__((ext_vector_type(4)))
__attribute__((overloadable)) half4 native_exp(half4 );
__kernel void test(__global half* in, __global half* out, int idx) {
half4 data ;
data[0] = in[idx];
data[1] = in[idx+1];
data[2] = in[idx+2];
data[3] = in[idx+3];
data = native_exp(data);
out[0] = data[0];
}

How can I avoid the need to explicitly declare __attribute__((overloadable)) half4 native_exp(half4 ); in the kernel?

Thank you in advance for any advice you can provide

You can pass -finclude-default-header option to the compiler front-end. In addition to that you might want to add -fdeclare-opencl-builtins to speed-up the parsing of the header with OpenCL built-in function declarations.
See OpenCL Support — Clang 18.0.0git documentation (llvm.org) documentation for more details about these options.

You can also do this in clang with -nogpulib and -nogpuinc Compiler Explorer.

After adding -finclude-default to the compiler and removing __attribute__((overloadable)) half4 native_exp(half4 ); from the kernel, I encountered an error.
half.cl:31:12: error: no matching function for call to 'native_exp' data = native_exp(data); ^~~~~~~~~~ /usr/lib/llvm-10/lib/clang/10.0.0/include/opencl-c.h:8902:21: note: candidate function not viable: no known conversion from '__private half4' (vector of 4 'half' values) to '__private float' for 1st argument float __ovld __cnfn native_exp(float x); ^ /usr/lib/llvm-10/lib/clang/10.0.0/include/opencl-c.h:8903:22: note: candidate function not viable: no known conversion from '__private half4' (vector of 4 'half' values) to '__private float2' (vector of 2 'float' values) for 1st argument float2 __ovld __cnfn native_exp(float2 x); ^ /usr/lib/llvm-10/lib/clang/10.0.0/include/opencl-c.h:8904:22: note: candidate function not viable: no known conversion from '__private half4' (vector of 4 'half' values) to '__private float3' (vector of 3 'float' values) for 1st argument float3 __ovld __cnfn native_exp(float3 x); ^ /usr/lib/llvm-10/lib/clang/10.0.0/include/opencl-c.h:8905:22: note: candidate function not viable: no known conversion from '__private half4' (vector of 4 'half' values) to '__private float4' (vector of 4 'float' values) for 1st argument float4 __ovld __cnfn native_exp(float4 x); ^ /usr/lib/llvm-10/lib/clang/10.0.0/include/opencl-c.h:8906:22: note: candidate function not viable: no known conversion from '__private half4' (vector of 4 'half' values) to '__private float8' (vector of 8 'float' values) for 1st argument float8 __ovld __cnfn native_exp(float8 x); ^ /usr/lib/llvm-10/lib/clang/10.0.0/include/opencl-c.h:8907:23: note: candidate function not viable: no known conversion from '__private half4' (vector of 4 'half' values) to '__private float16' (vector of 16 'float' values) for 1st argument float16 __ovld __cnfn native_exp(float16 x); ^ 1 error generated.
Did I miss something?

You should pass -finclude-default-header instead of -finclude-default. Here is an example from the documentation:

clang -Xclang -finclude-default-header test.cl