[llvm] 780cef1 - Verifier: Check byref address space for AMDGPU calling conventions

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 20 08:13:19 PDT 2020


Author: Matt Arsenault
Date: 2020-07-20T11:13:11-04:00
New Revision: 780cef1f34373b872ea3cfc8e0180a889ce388fe

URL: https://github.com/llvm/llvm-project/commit/780cef1f34373b872ea3cfc8e0180a889ce388fe
DIFF: https://github.com/llvm/llvm-project/commit/780cef1f34373b872ea3cfc8e0180a889ce388fe.diff

LOG: Verifier: Check byref address space for AMDGPU calling conventions

Added: 
    

Modified: 
    llvm/lib/IR/Verifier.cpp
    llvm/test/Verifier/amdgpu-cc.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index f638ed7040b1..67a295e7a71c 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -2314,13 +2314,24 @@ void Verifier::visitFunction(const Function &F) {
     Assert(!F.hasStructRetAttr(),
            "Calling convention does not allow sret", &F);
     if (F.getCallingConv() != CallingConv::SPIR_KERNEL) {
-      for (unsigned i = 0, e = F.arg_size(); i != e; ++i) {
+      const unsigned StackAS = DL.getAllocaAddrSpace();
+      unsigned i = 0;
+      for (const Argument &Arg : F.args()) {
         Assert(!Attrs.hasParamAttribute(i, Attribute::ByVal),
                "Calling convention disallows byval", &F);
         Assert(!Attrs.hasParamAttribute(i, Attribute::Preallocated),
                "Calling convention disallows preallocated", &F);
         Assert(!Attrs.hasParamAttribute(i, Attribute::InAlloca),
                "Calling convention disallows inalloca", &F);
+
+        if (Attrs.hasParamAttribute(i, Attribute::ByRef)) {
+          // FIXME: Should also disallow LDS and GDS, but we don't have the enum
+          // value here.
+          Assert(Arg.getType()->getPointerAddressSpace() != StackAS,
+                 "Calling convention disallows stack byref", &F);
+        }
+
+        ++i;
       }
     }
 

diff  --git a/llvm/test/Verifier/amdgpu-cc.ll b/llvm/test/Verifier/amdgpu-cc.ll
index 25b8d9088acc..1cd1b3467413 100644
--- a/llvm/test/Verifier/amdgpu-cc.ll
+++ b/llvm/test/Verifier/amdgpu-cc.ll
@@ -121,3 +121,9 @@ define amdgpu_kernel void @preallocated_as0_cc_amdgpu_kernel(i32* preallocated(i
 define amdgpu_kernel void @inalloca_as0_cc_amdgpu_kernel(i32* inalloca %ptr) {
   ret void
 }
+
+; CHECK: Calling convention disallows stack byref
+; CHECK-NEXT: void (i32 addrspace(5)*)* @byref_as5_cc_amdgpu_kernel
+define amdgpu_kernel void @byref_as5_cc_amdgpu_kernel(i32 addrspace(5)* byref(i32) %ptr) {
+  ret void
+}


        


More information about the llvm-commits mailing list