Skip to content

Commit

Permalink
Allow kernels to be referenced in @llvm.global.annotations
Browse files Browse the repository at this point in the history
---------------------------
  • Loading branch information
mshelego authored and sys-cmllvm committed Mar 17, 2023
1 parent eceefb6 commit cd3aecc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
22 changes: 20 additions & 2 deletions GenXIntrinsics/lib/GenXIntrinsics/GenXSPIRVReaderAdaptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<GlobalVariable>(Array->user_back());
assert(GV && GV->getName() == "llvm.global.annotations");
}

Function *NewF = transformKernelSignature(F, ArgDescs);
F.getParent()->getFunctionList().insert(F.getIterator(), NewF);
Expand Down Expand Up @@ -521,6 +537,8 @@ static void rewriteKernelArguments(Function &F) {
}
}

F.mutateType(NewF->getType());
F.replaceAllUsesWith(NewF);
F.eraseFromParent();
}

Expand Down
5 changes: 5 additions & 0 deletions GenXIntrinsics/test/Adaptors/annotated_args_reader.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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(

Expand Down

0 comments on commit cd3aecc

Please sign in to comment.