According to the SPIR 2.0 spec[1], the name of OpenCL builtins are mangled.
However, when I compile OpenCl code with Clang 3.9 with the “spir64-unknown-unknown” target, Clang generates IR without mangling the builtins, e.g. for:
__kernel void input_zip_int(__global int *in0) {
*in0 = get_global_id(0);
}
I saw that in [1], printf is mangled to _Z6printfPrU3AS2cz, while in clang’s opencl-c.h[2], printf does not have the overload attribute:
int printf(__constant const char* st, …); (and it is different from the standard, which is printf(restrict __constant char *, …))
I try the following code:
#include <opencl-c.h>
__kernel void vadd(__global const int* a, __global const int* b, __global int* c) {
printf(“aaaaa”);
with the following command line:
clang -cc1 -internal-isystem /wrk/xsjhdnobkup2/hongbinz/omp/build-llvm/bin/…/lib/clang/3.9.0/include -nostdsysteminc -S -emit-llvm -o -
2.10.3 The printf function
The printf function is supported, and is mangled according to its prototype as follows:
int printf(constant char * restrict fmt, … )
Note that the ellipsis formal argument (…) is mangled to argument type specifier z
*2.10.3 The printf function*
The printf function is supported, and is mangled according to its
prototype as follows:
int printf(constant char * restrict fmt, ... )
clang 3.9 will drop the 'restrict' when it mangle this name, or I am
missing some commandline argument?
I’d like to clarify that old SPIR 1.2 and SPIR 2.0 formats are flavors of LLVM IR version 3.2/3.4, so clang 3.9 will never be able to produce “conformant” SPIR programs. Considering this I think it makes sense to evaluate the benefit of features from SPIR 1.2/2.0 specification we are trying to implement in ToT clang.
Could you clarify the problem you are trying to solve by mangling printf function?
I’d like to clarify that old SPIR 1.2 and SPIR 2.0 formats are flavors of
LLVM IR version 3.2/3.4, so clang 3.9 will never be able to produce
“conformant” SPIR programs. Considering this I think it makes sense to
evaluate the benefit of features from SPIR 1.2/2.0 specification we are
trying to implement in ToT clang.
Could you clarify the problem you are trying to solve by mangling printf
function?
I am not solving any problem by mangling the printf. I just confused when I
saw the header and the SPIR 2.0 "Provisional" specs do not agree