diff --git a/GenXIntrinsics/lib/GenXIntrinsics/GenXSPIRVReaderAdaptor.cpp b/GenXIntrinsics/lib/GenXIntrinsics/GenXSPIRVReaderAdaptor.cpp index 0d3f30fc..5bf1c417 100644 --- a/GenXIntrinsics/lib/GenXIntrinsics/GenXSPIRVReaderAdaptor.cpp +++ b/GenXIntrinsics/lib/GenXIntrinsics/GenXSPIRVReaderAdaptor.cpp @@ -486,8 +486,24 @@ static void rewriteKernelArguments(Function &F) { // All arguments are in old style. return; - // No uses. Fast composite is not converted in writer part for now. - assert(F.use_empty() && "FC is not supported yet"); + // At the moment there are only two cases when kernel function with converted + // parameters can have users: + // 1. Kernel is called from another function via fast composite + // For such kernels we just don't rewrite arguments on SPIRV write, so + // there should not be presented on read + // 2. Kernel is referenced in @llvm.global.annotations + // We have to replace the original function with the new one + if (!F.use_empty()) { + assert(F.hasOneUse()); + auto *Bitcast = F.user_back(); + assert(Bitcast->hasOneUse()); + auto *Struct = Bitcast->user_back(); + assert(Struct->hasOneUse()); + auto *Array = Struct->user_back(); + assert(Array->hasOneUse()); + auto *GV = dyn_cast(Array->user_back()); + assert(GV && GV->getName() == "llvm.global.annotations"); + } Function *NewF = transformKernelSignature(F, ArgDescs); F.getParent()->getFunctionList().insert(F.getIterator(), NewF); @@ -521,6 +537,8 @@ static void rewriteKernelArguments(Function &F) { } } + F.mutateType(NewF->getType()); + F.replaceAllUsesWith(NewF); F.eraseFromParent(); } diff --git a/GenXIntrinsics/test/Adaptors/annotated_args_reader.ll b/GenXIntrinsics/test/Adaptors/annotated_args_reader.ll index fae8f5f5..c5c5bc55 100644 --- a/GenXIntrinsics/test/Adaptors/annotated_args_reader.ll +++ b/GenXIntrinsics/test/Adaptors/annotated_args_reader.ll @@ -19,6 +19,11 @@ %opencl.image3d_rw_t = type opaque %opencl.sampler_t = type opaque +@0 = private unnamed_addr constant [15 x i8] c"some attribute\00", section "llvm.metadata" +@llvm.global.annotations = appending global [1 x { i8*, i8*, i8*, i32 }] [{ i8*, i8*, i8*, i32 } { i8* bitcast (void (%intel.buffer_rw_t addrspace(1)*, %opencl.image1d_rw_t addrspace(1)*, %opencl.image1d_buffer_rw_t addrspace(1)*, %opencl.image2d_rw_t addrspace(1)*, %opencl.image3d_rw_t addrspace(1)*, %opencl.sampler_t addrspace(2)*, i8 addrspace(1)*, <4 x i32>)* @test to i8*), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @0, i32 0, i32 0), i8* undef, i32 undef }], section "llvm.metadata" +; CHECK-LABEL: @llvm.global.annotations +; CHECK void (i32, i32, i32, i32, i32, i32, i64, <4 x i32>)* @test + define spir_kernel void @test(%intel.buffer_rw_t addrspace(1)* %buf, %opencl.image1d_rw_t addrspace(1)* %im1d, %opencl.image1d_buffer_rw_t addrspace(1)* %im1db, %opencl.image2d_rw_t addrspace(1)* %im2d, %opencl.image3d_rw_t addrspace(1)* %im3d, %opencl.sampler_t addrspace(2)* %samp, i8 addrspace(1)* %ptr, <4 x i32> %gen) #0 { ; CHECK-LABEL: @test(