[llvm] [AMDGPU] Add support for preloading hidden groupsize args (PR #83817)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 4 02:50:13 PST 2024
================
@@ -64,6 +70,111 @@ class PreloadKernelArgInfo {
NumFreeUserSGPRs -= (NumPreloadSGPRs + PaddingSGPRs);
return true;
}
+
+ // Try to allocate SGPRs to preload implicit kernel arguments.
+ void tryAllocImplicitArgPreloadSGPRs(unsigned ImplicitArgsBaseOffset,
+ IRBuilder<> &Builder) {
+ unsigned LastExplicitArgOffset = ImplicitArgsBaseOffset;
+ IntrinsicInst *ImplicitArgPtr = nullptr;
+ for (Function::iterator B = F.begin(), BE = F.end(); B != BE; ++B) {
+ for (BasicBlock::iterator I = B->begin(), IE = B->end(); I != IE; ++I) {
+ if (IntrinsicInst *CI = dyn_cast<IntrinsicInst>(I))
+ if (CI->getIntrinsicID() == Intrinsic::amdgcn_implicitarg_ptr) {
+ ImplicitArgPtr = CI;
+ break;
+ }
+ }
+ }
+ if (!ImplicitArgPtr)
+ return;
+ const DataLayout &DL = F.getParent()->getDataLayout();
+ Value *GroupSizes[3] = {nullptr, nullptr, nullptr};
+ for (auto *U : ImplicitArgPtr->users()) {
+ if (!U->hasOneUse())
+ continue;
+
+ // FIXME: The loop below is mostly copied from
+ // AMDGPULowerKernelAttributes.cpp, should combine the logic somewhere.
+ int64_t Offset = 0;
+ auto *Load =
+ dyn_cast<LoadInst>(U); // Load from ImplicitArgPtr/DispatchPtr?
+ auto *BCI = dyn_cast<BitCastInst>(U);
+ if (!Load && !BCI) {
+ if (GetPointerBaseWithConstantOffset(U, Offset, DL) != ImplicitArgPtr)
+ continue;
+ Load = dyn_cast<LoadInst>(*U->user_begin()); // Load from GEP?
+ BCI = dyn_cast<BitCastInst>(*U->user_begin());
+ }
+
+ if (BCI) {
+ if (!BCI->hasOneUse())
+ continue;
+ Load = dyn_cast<LoadInst>(*BCI->user_begin()); // Load from BCI?
----------------
arsenm wrote:
No real reason to worry about bitcasts with opaque pointers
https://github.com/llvm/llvm-project/pull/83817
More information about the llvm-commits
mailing list