[llvm] [IR] IRVerifier: Should not allow calls kernel functions (PR #134987)
Aniket Lal via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 9 03:20:38 PDT 2025
https://github.com/lalaniket8 created https://github.com/llvm/llvm-project/pull/134987
The `Unsupported calling convention` error coming out of backend (Issue : https://github.com/llvm/llvm-project/issues/60313) should be flagged in IR Verifier.
>From 51ce5bce575666f742b7a012022bb0fa8e0201f3 Mon Sep 17 00:00:00 2001
From: anikelal <anikelal at amd.com>
Date: Wed, 9 Apr 2025 15:46:23 +0530
Subject: [PATCH] Do not allow calls to AMDGPU_KERNEL and SPIR_KERNEL functions
in llvm IR
---
llvm/lib/IR/Verifier.cpp | 3 +++
llvm/test/Verifier/amdgcn-kernel-call.ll | 32 ++++++++++++++++++++++++
llvm/test/Verifier/spir-kernel-call.ll | 30 ++++++++++++++++++++++
3 files changed, 65 insertions(+)
create mode 100644 llvm/test/Verifier/amdgcn-kernel-call.ll
create mode 100644 llvm/test/Verifier/spir-kernel-call.ll
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 7423e746dfa9a..1958e8d74ce47 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -3607,6 +3607,9 @@ void Verifier::visitCallBase(CallBase &Call) {
"not allowed. Please use the @llvm.amdgpu.cs.chain intrinsic instead.",
Call);
+ Check(CC != CallingConv::AMDGPU_KERNEL && CC != CallingConv::SPIR_KERNEL,
+ "Calls to kernel functions are not supported");
+
// Disallow passing/returning values with alignment higher than we can
// represent.
// FIXME: Consider making DataLayout cap the alignment, so this isn't
diff --git a/llvm/test/Verifier/amdgcn-kernel-call.ll b/llvm/test/Verifier/amdgcn-kernel-call.ll
new file mode 100644
index 0000000000000..1d8b2d4d1e825
--- /dev/null
+++ b/llvm/test/Verifier/amdgcn-kernel-call.ll
@@ -0,0 +1,32 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+; CHECK: Calls to kernel functions are not supported
+
+target triple = "amdgcn"
+
+ at __oclc_ABI_version = weak_odr hidden local_unnamed_addr addrspace(4) constant i32 500
+
+; Function Attrs: convergent noinline norecurse nounwind optnone
+define dso_local amdgpu_kernel void @CalleeKernel() #0 !kernel_arg_addr_space !4 !kernel_arg_access_qual !4 !kernel_arg_type !4 !kernel_arg_base_type !4 !kernel_arg_type_qual !4 {
+entry:
+ ret void
+}
+
+; Function Attrs: convergent noinline norecurse nounwind optnone
+define dso_local amdgpu_kernel void @CallerKernel() #0 !kernel_arg_addr_space !4 !kernel_arg_access_qual !4 !kernel_arg_type !4 !kernel_arg_base_type !4 !kernel_arg_type_qual !4 {
+entry:
+ call amdgpu_kernel void @CalleeKernel() #1
+ ret void
+}
+
+attributes #0 = { convergent noinline norecurse nounwind optnone "amdgpu-flat-work-group-size"="1,256" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "uniform-work-group-size"="true" }
+attributes #1 = { convergent nounwind "uniform-work-group-size"="true" }
+
+!llvm.module.flags = !{!0, !1}
+!opencl.ocl.version = !{!2}
+!llvm.ident = !{!3}
+
+!0 = !{i32 1, !"amdhsa_code_object_version", i32 500}
+!1 = !{i32 1, !"wchar_size", i32 4}
+!2 = !{i32 1, i32 2}
+!3 = !{!"clang version 21.0.0git (git at github.com:llvm/llvm-project.git 37565e60b3325324c9396ce236cb005a958f157e)"}
+!4 = !{}
diff --git a/llvm/test/Verifier/spir-kernel-call.ll b/llvm/test/Verifier/spir-kernel-call.ll
new file mode 100644
index 0000000000000..7cca2e4e902e9
--- /dev/null
+++ b/llvm/test/Verifier/spir-kernel-call.ll
@@ -0,0 +1,30 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+; CHECK: Calls to kernel functions are not supported
+
+target triple = "i686-pc-darwin"
+
+; Function Attrs: convergent noinline norecurse nounwind optnone
+define spir_kernel void @CalleeKernel() #0 !kernel_arg_addr_space !4 !kernel_arg_access_qual !4 !kernel_arg_type !4 !kernel_arg_base_type !4 !kernel_arg_type_qual !4 {
+entry:
+ ret void
+}
+
+; Function Attrs: convergent noinline norecurse nounwind optnone
+define spir_kernel void @CallerKernel() #0 !kernel_arg_addr_space !4 !kernel_arg_access_qual !4 !kernel_arg_type !4 !kernel_arg_base_type !4 !kernel_arg_type_qual !4 {
+entry:
+ call spir_kernel void @CalleeKernel() #1
+ ret void
+}
+
+attributes #0 = { convergent noinline norecurse nounwind optnone "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+x87" "uniform-work-group-size"="true" }
+attributes #1 = { convergent nounwind "uniform-work-group-size"="true" }
+
+!llvm.module.flags = !{!0, !1}
+!opencl.ocl.version = !{!2}
+!llvm.ident = !{!3}
+
+!0 = !{i32 1, !"NumRegisterParameters", i32 0}
+!1 = !{i32 1, !"wchar_size", i32 4}
+!2 = !{i32 1, i32 2}
+!3 = !{!"clang version 21.0.0git (git at github.com:llvm/llvm-project.git 37565e60b3325324c9396ce236cb005a958f157e)"}
+!4 = !{}
More information about the llvm-commits
mailing list