[llvm] [AMDGPU] Enable kernarg preloading by default on gfx940 (PR #110691)

Austin Kerbow via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 2 13:35:26 PDT 2024


================
@@ -1014,12 +1014,49 @@ struct AAAMDGPUNoAGPR
 
 const char AAAMDGPUNoAGPR::ID = 0;
 
+static unsigned getMaxNumPreloadArgs(const Function &F, const DataLayout &DL,
+                                     const TargetMachine &TM) {
+  const GCNSubtarget &ST = TM.getSubtarget<GCNSubtarget>(F);
+  unsigned Offset = 0;
+  unsigned ArgsToPreload = 0;
+  for (const auto &Arg : F.args()) {
+    if (Arg.hasByRefAttr())
+      break;
+
+    Type *Ty = Arg.getType();
+    Align ArgAlign = DL.getABITypeAlign(Ty);
+    auto Size = DL.getTypeAllocSize(Ty);
+    Offset = alignTo(Offset, ArgAlign);
+    if (((Offset + Size) / 4) > ST.getMaxNumUserSGPRs())
+      break;
+
+    Offset += Size;
+    ArgsToPreload++;
+  }
+
+  return ArgsToPreload;
+}
+
 static void addPreloadKernArgHint(Function &F, TargetMachine &TM) {
   const GCNSubtarget &ST = TM.getSubtarget<GCNSubtarget>(F);
-  for (unsigned I = 0;
-       I < F.arg_size() &&
-       I < std::min(KernargPreloadCount.getValue(), ST.getMaxNumUserSGPRs());
-       ++I) {
+  if (!ST.hasKernargPreload())
+    return;
+
+  // Enable kernarg preloading by default on GFX940+.
+  size_t PreloadCount;
+  if (KernargPreloadCount.getNumOccurrences() > 0) {
----------------
kerbowa wrote:

What's the benefit of having the logic outside of the pass and using a pass parameter?

I want to keep it so the flag works as before and users can override the defaults. I would still need the cl opt somewhere.

https://github.com/llvm/llvm-project/pull/110691


More information about the llvm-commits mailing list