Skip to content

[IR] IRVerifier: Should not allow calls kernel functions #134987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

lalaniket8
Copy link
Contributor

The Unsupported calling convention error coming out of backend (Issue : #60313) should be flagged in IR Verifier.

@llvmbot
Copy link
Member

llvmbot commented Apr 9, 2025

@llvm/pr-subscribers-llvm-ir

Author: Aniket Lal (lalaniket8)

Changes

The Unsupported calling convention error coming out of backend (Issue : #60313) should be flagged in IR Verifier.


Full diff: https://github.com/llvm/llvm-project/pull/134987.diff

3 Files Affected:

  • (modified) llvm/lib/IR/Verifier.cpp (+3)
  • (added) llvm/test/Verifier/amdgcn-kernel-call.ll (+32)
  • (added) llvm/test/Verifier/spir-kernel-call.ll (+30)
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"
+
+@__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 ([email protected]: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 ([email protected]:llvm/llvm-project.git 37565e60b3325324c9396ce236cb005a958f157e)"}
+!4 = !{}

Copy link
Contributor

@arsenm arsenm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing callsite test coverage, and other ccs @shiltian also has a PR for this

@shiltian
Copy link
Contributor

shiltian commented Apr 9, 2025

FYI #134910

@lalaniket8
Copy link
Contributor Author

Closing this PR, since it is duplicate of #134910

@lalaniket8 lalaniket8 closed this Apr 10, 2025
@arsenm arsenm deleted the users/lalaniket8/ir-verifier-calls-to-kernel-not-supported branch April 10, 2025 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants