Skip to content

Commit 66070f4

Browse files
committed
IR/Verifier: Do not allow kernel to kernel calls.
Allowing a kernel to call another kernel is invalid. This extends the Verifier to recognize this fact. The calling convention is retrieved from the module because it may not be labeling the callsite.
1 parent ea0761f commit 66070f4

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

llvm/lib/IR/Verifier.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3636,6 +3636,18 @@ void Verifier::visitCallBase(CallBase &Call) {
36363636
Check(isCallableCC(Call.getCallingConv()),
36373637
"calling convention does not permit calls", Call);
36383638

3639+
// Find the actual CC of the callee from the Module.
3640+
CallingConv::ID CalleeCC = Call.getParent()->getParent()->getParent()
3641+
->getFunction(Call.getCalledFunction()->getName())->getCallingConv();
3642+
// Verify that a kernel does not call another kernel.
3643+
if (CalleeCC == CallingConv::AMDGPU_KERNEL ||
3644+
CalleeCC == CallingConv::SPIR_KERNEL) {
3645+
CallingConv::ID CallerCC = Call.getParent()->getParent()->getCallingConv();
3646+
Check(CallerCC != CallingConv::AMDGPU_KERNEL &&
3647+
CallerCC != CallingConv::SPIR_KERNEL,
3648+
"a kernel may not call a kernel", Call.getParent()->getParent());
3649+
}
3650+
36393651
// Disallow passing/returning values with alignment higher than we can
36403652
// represent.
36413653
// FIXME: Consider making DataLayout cap the alignment, so this isn't
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck %s
2+
3+
define amdgpu_kernel void @kernel(ptr addrspace(1) %out, i32 %n) {
4+
entry:
5+
; CHECK: a kernel may not call a kernel
6+
; CHECK-NEXT: ptr @kernel
7+
call void @kernel(ptr addrspace(1) %out, i32 %n)
8+
ret void
9+
}

0 commit comments

Comments
 (0)