KhronosGroup/SPIRV-LLVM

Invalid mangling of device execution built-ins in SPIR-V reader.

Closed this issue · 2 comments

SPIR-V reader produces incorrectly mangled enqueue_kernel built-in. I suppose what some other built-ins are also affected. Compare the reproducer output and the mangled name produced by the SPIR 2.0 generator (I expect SPIR-V generator committed by Alexey Bader uses the same mangling).

repro.zip.
$ ./llvm-spirv repro.bc && ./llvm-spirv -r repro.spv -o out.bc && ./llvm-dis < out.bc | grep "declare.*enqueue_kernel"
$ _Z14enqueue_kernel9ocl_queue22kernel_enqueue_flags_tP9ndrange_tjPU3AS412ocl_clkeventS2_U13block_pointerFvvE

SPIR 2.0 name:
_Z14enqueue_kernel9ocl_queuei9ndrange_tjPKU3AS413ocl_clk_eventPU3AS413ocl_clk_eventU13block_pointerFvvE
taken from here: https://github.com/KhronosGroup/SPIR-Tools/wiki/SPIR-2.0-built-in-functions#enqueuing-kernels

I see here few discrepancies:

  1. flags are mangled as int by SPIR 2.0 -> "i" VS enum mangling by the reader -> "22kernel_enqueue_flags_t" (which is rather bug in SPIR 2.0 generator)
  2. ndrange is passed by value so should be mangled as 9ndrange_t but it is mangled as a pointer to ndrange_t (P9ndrange_t)
  3. event_wait_list should be mangled as a pointer to constant (i.e. PKU3AS413ocl_clk_event)
  4. event_ret is mangled as S2_ by the reader
  5. 12ocl_clkevent instead of 13ocl_clk_event

Does anyone know what this code is intended to? Unfortunately there are no comments so I got lost.

I've found what it produces substitution for 'private const clk_event_t *' for enqueue_kernel buit-in.
P13opencl.clk_even_t is remembered for substitution out from PKopencl.clk_even_t. So, if the next argument is 'private clk_event_t ' it got substituted with S_ (queue_t!).
bash-4.1$ c++filt _Z14enqueue_kernel9ocl_queue22kernel_enqueue_flags_t9ndrange_tjPK13ocl_clk_eventS_U13block_pointerFvvE
enqueue_kernel(ocl_queue, kernel_enqueue_flags_t, ndrange_t, unsigned int, ocl_clk_event const
, ocl_queue, void ( block_pointer)())

It is different from mangling produced by SPIR2.0 generator:
bash-4.1$ c++filt _Z14enqueue_kernel9ocl_queuei9ndrange_tjPK13ocl_clk_eventP13ocl_clk_eventU13block_pointerFvvE
enqueue_kernel(ocl_queue, int, ndrange_t, unsigned int, ocl_clk_event const*, ocl_clk_event*, void ( block_pointer)())

I figured it out and going to fix this issue.