[llvm] 596e61c - [AMDGPU] Ignore call graph node which does not have function info.

via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 3 21:53:19 PDT 2021


Author: hsmahesha
Date: 2021-08-04T10:22:33+05:30
New Revision: 596e61c332267ae9e7074bcd3adc988829c85817

URL: https://github.com/llvm/llvm-project/commit/596e61c332267ae9e7074bcd3adc988829c85817
DIFF: https://github.com/llvm/llvm-project/commit/596e61c332267ae9e7074bcd3adc988829c85817.diff

LOG: [AMDGPU] Ignore call graph node which does not have function info.

While collecting reachable callees (from kernels), ignore call graph node which
does not have associated function or associated function is not a definition.

Reviewed By: rampitec

Differential Revision: https://reviews.llvm.org/D107329

Added: 
    llvm/test/CodeGen/AMDGPU/replace-lds-by-ptr-call-to-declare-only-func.ll

Modified: 
    llvm/lib/Target/AMDGPU/Utils/AMDGPULDSUtils.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AMDGPU/Utils/AMDGPULDSUtils.cpp b/llvm/lib/Target/AMDGPU/Utils/AMDGPULDSUtils.cpp
index da8fcf3900bb5..5af4b180c0058 100644
--- a/llvm/lib/Target/AMDGPU/Utils/AMDGPULDSUtils.cpp
+++ b/llvm/lib/Target/AMDGPU/Utils/AMDGPULDSUtils.cpp
@@ -68,6 +68,11 @@ class CollectReachableCallees {
       if (!VisitedCGNodes.insert(CGN).second)
         continue;
 
+      // Ignore call graph node which does not have associated function or
+      // associated function is not a definition.
+      if (!CGN->getFunction() || CGN->getFunction()->isDeclaration())
+        continue;
+
       for (auto GI = CGN->begin(), GE = CGN->end(); GI != GE; ++GI) {
         auto *RCB = cast<CallBase>(GI->first.getValue());
         auto *RCGN = GI->second;

diff  --git a/llvm/test/CodeGen/AMDGPU/replace-lds-by-ptr-call-to-declare-only-func.ll b/llvm/test/CodeGen/AMDGPU/replace-lds-by-ptr-call-to-declare-only-func.ll
new file mode 100644
index 0000000000000..a5e2054512e78
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/replace-lds-by-ptr-call-to-declare-only-func.ll
@@ -0,0 +1,38 @@
+; RUN: opt -S -mtriple=amdgcn--  -amdgpu-replace-lds-use-with-pointer -amdgpu-enable-lds-replace-with-pointer=true < %s | FileCheck %s
+
+; DESCRIPTION:
+;
+; The kernel 'kern' makes a call to declared only function `foo`, hence `foo`
+; is not considered as reachable callee, and is ignored. The function `goo`
+; which uses LDS is not called from kernel 'kern', hence it is also ignored.
+;
+
+; Original LDS should exist.
+; CHECK: @lds = internal local_unnamed_addr addrspace(3) global i32 undef, align 4
+ at lds = internal local_unnamed_addr addrspace(3) global i32 undef, align 4
+
+; Pointer should not be created.
+; CHECK-NOT: @lds.ptr = internal unnamed_addr addrspace(3) global i16 undef, align 2
+
+; CHECK: declare i32 @foo()
+declare i32 @foo()
+
+; No change
+define internal void @goo() {
+; CHECK-LABEL: entry:
+; CHECK:   store i32 undef, i32 addrspace(3)* @lds, align 4
+; CHECK:   ret void
+entry:
+  store i32 undef, i32 addrspace(3)* @lds, align 4
+  ret void
+}
+
+; No change
+define weak amdgpu_kernel void @kern() {
+; CHECK-LABEL: entry:
+; CHECK-LABEL:   %nt = call i32 @foo()
+; CHECK-LABEL:   ret void
+entry:
+  %nt = call i32 @foo()
+  ret void
+}


        


More information about the llvm-commits mailing list