OpenGL shading language (GLSL) is like a C subset language, but it contains some special features, ex: native vector type & swizzle.
In GLSL, you can declare vector types:
You can access the element of vector by using .xyzw, it means the 1st, 2nd, 3rd, 4th element of the vector are x, y, z, w.
vec4 a = vec4(1.0, 2.0, 3.0, 4.0);
vec4 b = vec4(3.0, 4.0, 5.0, 6.0);
v4.xyw = vec2(2.5, 3.3. 7.7);
f = v4.y;
b.xy += a.xy;
Because my chip supports this facility in instruction & register level, I think I have to preserve the semantic of this ‘vector’ and ‘swizzle’. I don’t think this GLSL::vector can be represented directly by the llvm::vector type, because I can just operate on some elements on a GLSL::vector rather than 4 elements all the time. (Am I right about this thought?)
Hence, I think I would need to add some new ‘intrinsic’ function in LLVM, and use llvm::vector to represent GLSL::vector.
a.xyz = b;
will be translate to
intrinsic_vector3_to_vector4_assign(a, 0, 1, 2, b);
Then in the backend, I can see this intrinsic function, and do instruction selections based on this intrinsic. Ex: intrinsic_vector3_to_vector4_assign will be translated to single machine instruction: mov a.xyz, b.xyz.
Am I right on this thought? Does it really needs to add LLVM intrinsic functions to support OpenGL shading language?
Or am I missing some really usful mechanism in LLVM to natively support this?
Comments are welcome.