[llvm] [AMDGPU] Skip lowerNonKernelLDSAccesses if function is declaration. (PR #106975)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 4 07:11:26 PDT 2024


https://github.com/skc7 updated https://github.com/llvm/llvm-project/pull/106975

>From 010b2787204f821f7273b9e4800ff887cdb51d9d Mon Sep 17 00:00:00 2001
From: skc7 <Krishna.Sankisa at amd.com>
Date: Mon, 2 Sep 2024 17:30:49 +0530
Subject: [PATCH 1/2] [AMDGPU] Skip lowerNonKernelLDSAccesses if function is
 declaration.

---
 llvm/lib/Target/AMDGPU/AMDGPUSwLowerLDS.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUSwLowerLDS.cpp b/llvm/lib/Target/AMDGPU/AMDGPUSwLowerLDS.cpp
index b2ab7e9c03e528..ca796200ee6c6f 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUSwLowerLDS.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUSwLowerLDS.cpp
@@ -1218,6 +1218,8 @@ bool AMDGPUSwLowerLDS::run() {
     for (auto &K : FuncLDSAccessInfo.NonKernelToLDSAccessMap) {
       Function *Func = K.first;
       DenseSet<GlobalVariable *> &LDSGlobals = K.second;
+      if (Func->isDeclaration() || LDSGlobals.empty())
+        continue;
       SetVector<GlobalVariable *> OrderedLDSGlobals = sortByName(
           std::vector<GlobalVariable *>(LDSGlobals.begin(), LDSGlobals.end()));
       lowerNonKernelLDSAccesses(Func, OrderedLDSGlobals, NKLDSParams);
@@ -1226,6 +1228,8 @@ bool AMDGPUSwLowerLDS::run() {
       auto &K = FuncLDSAccessInfo.NonKernelToLDSAccessMap;
       if (K.find(Func) != K.end())
         continue;
+      if (Func->isDeclaration())
+        continue;
       SetVector<llvm::GlobalVariable *> Vec;
       lowerNonKernelLDSAccesses(Func, Vec, NKLDSParams);
     }

>From e3f18649c6e8205632ffc2f16618418b226e37ce Mon Sep 17 00:00:00 2001
From: skc7 <Krishna.Sankisa at amd.com>
Date: Wed, 4 Sep 2024 19:40:01 +0530
Subject: [PATCH 2/2] [AMDGPU] Skip adding function to kernelToLDS maps if its
 a declaration.

---
 llvm/lib/Target/AMDGPU/AMDGPUSwLowerLDS.cpp | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
 mode change 100644 => 100755 llvm/lib/Target/AMDGPU/AMDGPUSwLowerLDS.cpp

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUSwLowerLDS.cpp b/llvm/lib/Target/AMDGPU/AMDGPUSwLowerLDS.cpp
old mode 100644
new mode 100755
index ca796200ee6c6f..d311e129127167
--- a/llvm/lib/Target/AMDGPU/AMDGPUSwLowerLDS.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUSwLowerLDS.cpp
@@ -274,6 +274,8 @@ void AMDGPUSwLowerLDS::getNonKernelsWithLDSArguments(const CallGraph &CG) {
       Function *CalledFunc = CallerCGN->getFunction();
       if (!CalledFunc)
         continue;
+      if (CalledFunc->isDeclaration())
+        continue;
       if (AMDGPU::isKernelLDS(CalledFunc))
         continue;
       for (auto AI = CalledFunc->arg_begin(), E = CalledFunc->arg_end();
@@ -300,7 +302,8 @@ void AMDGPUSwLowerLDS::getUsesOfLDSByNonKernels() {
     for (User *V : GV->users()) {
       if (auto *I = dyn_cast<Instruction>(V)) {
         Function *F = I->getFunction();
-        if (!isKernelLDS(F) && F->hasFnAttribute(Attribute::SanitizeAddress))
+        if (!isKernelLDS(F) && F->hasFnAttribute(Attribute::SanitizeAddress) &&
+            !(F->isDeclaration()))
           FuncLDSAccessInfo.NonKernelToLDSAccessMap[F].insert(GV);
       }
     }
@@ -1218,8 +1221,6 @@ bool AMDGPUSwLowerLDS::run() {
     for (auto &K : FuncLDSAccessInfo.NonKernelToLDSAccessMap) {
       Function *Func = K.first;
       DenseSet<GlobalVariable *> &LDSGlobals = K.second;
-      if (Func->isDeclaration() || LDSGlobals.empty())
-        continue;
       SetVector<GlobalVariable *> OrderedLDSGlobals = sortByName(
           std::vector<GlobalVariable *>(LDSGlobals.begin(), LDSGlobals.end()));
       lowerNonKernelLDSAccesses(Func, OrderedLDSGlobals, NKLDSParams);
@@ -1228,8 +1229,6 @@ bool AMDGPUSwLowerLDS::run() {
       auto &K = FuncLDSAccessInfo.NonKernelToLDSAccessMap;
       if (K.find(Func) != K.end())
         continue;
-      if (Func->isDeclaration())
-        continue;
       SetVector<llvm::GlobalVariable *> Vec;
       lowerNonKernelLDSAccesses(Func, Vec, NKLDSParams);
     }



More information about the llvm-commits mailing list