[PATCH] D150609: [AMDGPU] Do not assume stack size for PAL code object indirect calls

Baptiste Saleil via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 15 13:37:21 PDT 2023


bsaleil created this revision.
bsaleil added reviewers: arsenm, foad, sebastian-ne.
bsaleil added projects: LLVM, AMDGPU.
Herald added subscribers: StephenFan, kerbowa, hiraditya, tpr, dstuttard, yaxunl, jvesely, kzhuravl.
Herald added a project: All.
bsaleil requested review of this revision.
Herald added subscribers: llvm-commits, wdng.

There is no need to set a big default stack size for PAL code object indirect calls. The driver knows the max recursion depth, so it can compute a more accurate value from the minimum scratch size.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150609

Files:
  llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp
  llvm/test/CodeGen/AMDGPU/resource-usage-pal.ll


Index: llvm/test/CodeGen/AMDGPU/resource-usage-pal.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AMDGPU/resource-usage-pal.ll
@@ -0,0 +1,12 @@
+; RUN llc -mtriple=amdgcn-amd-amdpal -mcpu=gfx1100 -verify-machineinstrs < %s | FileCheck %s
+
+; CHECK: ScratchSize: 0
+define amdgpu_vs void @test() {
+.entry:
+  %0 = call i64 @llvm.amdgcn.s.getpc()
+  %1 = inttoptr i64 %0 to ptr
+  call amdgpu_gfx void %1()
+  ret void
+}
+
+declare i64 @llvm.amdgcn.s.getpc()
Index: llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPUResourceUsageAnalysis.cpp
@@ -104,19 +104,22 @@
 
   MachineModuleInfo &MMI = getAnalysis<MachineModuleInfoWrapperPass>().getMMI();
   const TargetMachine &TM = TPC->getTM<TargetMachine>();
+  const MCSubtargetInfo &STI = *TM.getMCSubtargetInfo();
   bool HasIndirectCall = false;
 
   CallGraph CG = CallGraph(M);
   auto End = po_end(&CG);
 
-  // By default, for code object v5 and later, track only the minimum scratch
-  // size
-  if (AMDGPU::getCodeObjectVersion(M) >= AMDGPU::AMDHSA_COV5) {
-    if (!AssumedStackSizeForDynamicSizeObjects.getNumOccurrences())
-      AssumedStackSizeForDynamicSizeObjects = 0;
-    if (!AssumedStackSizeForExternalCall.getNumOccurrences())
+  // By default, for code object v5 and later and PAL code object, track only
+  // the minimum scratch size
+  if ((STI.getTargetTriple().getOS() == Triple::AMDPAL ||
+       AMDGPU::getCodeObjectVersion(M) >= AMDGPU::AMDHSA_COV5) &&
+      !AssumedStackSizeForExternalCall.getNumOccurrences())
       AssumedStackSizeForExternalCall = 0;
-  }
+
+  if (AMDGPU::getCodeObjectVersion(M) >= AMDGPU::AMDHSA_COV5 &&
+      !AssumedStackSizeForDynamicSizeObjects.getNumOccurrences())
+      AssumedStackSizeForDynamicSizeObjects = 0;
 
   for (auto IT = po_begin(&CG); IT != End; ++IT) {
     Function *F = IT->getFunction();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150609.522315.patch
Type: text/x-patch
Size: 2045 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230515/9443a967/attachment.bin>


More information about the llvm-commits mailing list