Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling SPIRV LLVM translator-produced IR with duplicate names #87

Open
maleadt opened this issue Sep 9, 2024 · 1 comment
Open

Handling SPIRV LLVM translator-produced IR with duplicate names #87

maleadt opened this issue Sep 9, 2024 · 1 comment

Comments

@maleadt
Copy link

maleadt commented Sep 9, 2024

I was playing with spirv2clc in my LLVM-based toolflow, which relies on the SPIRV to LLVM translator to generate SPIR-V. For example, a simple kernel that returns nothing looks as follows in LLVM IR:

target triple = "spir64-unknown-unknown"

define spir_kernel void @_Z6kernel() {
  ret void
}

... which produces the following SPIR-V IR:

; SPIR-V
; Version: 1.0
; Generator: Khronos LLVM/SPIR-V Translator; 14
; Bound: 9
; Schema: 0
               OpCapability Addresses
               OpCapability Linkage
               OpCapability Kernel
          %1 = OpExtInstImport "OpenCL.std"
               OpMemoryModel Physical64 OpenCL
               OpEntryPoint Kernel %6 "_Z6kernel"
               OpSource Unknown 0
               OpName %_Z6kernel "_Z6kernel"
               OpDecorate %_Z6kernel LinkageAttributes "_Z6kernel" Export
       %void = OpTypeVoid
          %3 = OpTypeFunction %void
  %_Z6kernel = OpFunction %void None %3
          %5 = OpLabel
               OpReturn
               OpFunctionEnd
          %6 = OpFunction %void None %3
          %7 = OpLabel
          %8 = OpFunctionCall %void %_Z6kernel
               OpReturn
               OpFunctionEnd

The generated SPIR-V code here is peculiar, it looks like the spir_kernel attribute is handled by the translator by generating a wrapper entry-point calling the inner kernel. spirv2clc doesn't handle that very well, producing the following invalid OpenCL code:

void _Z6kernel(){
conversion:;
  return;
}
void kernel _Z6kernel(){
v7:;
  _Z6kernel();
  return;
}
<kernel>:5:6: warning: attribute declaration must precede definition
void kernel _Z6kernel(){
     ^
<kernel>:1:6: note: previous definition is here
void _Z6kernel(){
     ^
<kernel>:5:13: error: redefinition of '_Z6kernel'
void kernel _Z6kernel(){
            ^
<kernel>:1:6: note: previous definition is here
void _Z6kernel(){
     ^
@maleadt
Copy link
Author

maleadt commented Sep 10, 2024

Hm, there doesn't seem to be an easy way around this.

x-ref KhronosGroup/SPIRV-LLVM-Translator#2029

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant