Skip to content

Commit

Permalink
[SYCL] Fix logic in virtual function analysis (#15733)
Browse files Browse the repository at this point in the history
`computeFunctionToKernelsMapping` did not compute the mapping correctly
for leaves of its call graph if the call graph for leaves 3 levels or
more deep, which results in some kernels not having inferred
`calls-indirectly` being attached. This fixes the logic and cleans up
the duplication a bit in the function.
  • Loading branch information
jzc authored Oct 21, 2024
1 parent b023d40 commit 8398698
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
22 changes: 4 additions & 18 deletions llvm/lib/SYCLLowerIR/SYCLVirtualFunctionsAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,37 +71,23 @@ void checkKernel(const Function *F, const CallGraphTy &CG) {
void computeFunctionToKernelsMappingImpl(Function *Kernel, const Function *F,
const CallGraphTy &CG,
FuncToFuncMapTy &Mapping) {
Mapping[F].insert(Kernel);
CallGraphTy::const_iterator It = CG.find(F);
// It could be that the function itself is a leaf and doesn't call anything
if (It == CG.end())
return;

Mapping[F].insert(Kernel);

const SmallPtrSet<Value *, 8> &Callees = It->getSecond();
for (const Value *V : Callees)
if (auto *Callee = dyn_cast<Function>(V))
computeFunctionToKernelsMappingImpl(Kernel, Callee, CG, Mapping);
}

// Compute a map from functions used by a kernel to that kernel.
// For simplicity we also consider a kernel to be using itself.
void computeFunctionToKernelsMapping(Function *Kernel, const CallGraphTy &CG,
FuncToFuncMapTy &Mapping) {
// For simplicity we also consider a kernel to be using itself
Mapping[Kernel].insert(Kernel);

CallGraphTy::const_iterator It = CG.find(Kernel);
// It could be that the kernel doesn't call anything
if (It == CG.end())
return;

const SmallPtrSet<Value *, 8> &Callees = It->getSecond();
for (const Value *V : Callees) {
auto *Callee = dyn_cast<Function>(V);
if (!Callee)
continue;
Mapping[Callee].insert(Kernel);
computeFunctionToKernelsMappingImpl(Kernel, Callee, CG, Mapping);
}
computeFunctionToKernelsMappingImpl(Kernel, Kernel, CG, Mapping);
}

void collectVTablesThatUseFunction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,20 @@ entry:
ret void
}

define internal spir_func void @helper2(ptr addrspace(1) noundef align 8 %arg) {
entry:
call void @helper(ptr addrspace(1) %arg)
ret void
}

define weak_odr dso_local spir_kernel void @kernel2(ptr addrspace(1) noundef align 8 %_arg_StorageAcc) #2 {
entry:
call void @helper2(ptr addrspace(1) %_arg_StorageAcc)
ret void
}

; CHECK: @kernel{{.*}} #[[#KERNEL_ATTRS:]]
; CHECK: @kernel2{{.*}} #[[#KERNEL_ATTRS]]
;
; CHECK: attributes #[[#KERNEL_ATTRS]] = {{.*}}"calls-indirectly"="set-foo,set-bar"

Expand Down

0 comments on commit 8398698

Please sign in to comment.