[llvm] [AMDGPU] Compiler should synthesize private buffer resource descriptor from flat_scratch_init (PR #79586)
Scott Linder via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 5 13:16:09 PST 2024
================
@@ -398,6 +398,7 @@ void SIFrameLowering::emitEntryFunctionFlatScratchInit(
Register FlatScrInitLo;
Register FlatScrInitHi;
+ Register FlatScratchInitReg;
----------------
slinder1 wrote:
Nit: I'd prefer these variables agree on `Scr` vs `Scratch`
The same code is also repeated across some paths, including asserting `FlatScratchInitReg` is valid and initializing `FlatScrInit{Lo,Hi}`; could some of the code be extracted and do this setup first so it can share as much as possible? For example:
```cpp
Register FlatScratchInit;
if (ST.isAmdPalOS()) {
// Extract the scratch offset from the descriptor in the GIT
LiveRegUnits LiveUnits;
LiveUnits.init(*TRI);
LiveUnits.addLiveIns(MBB);
// Find unused reg to load flat scratch init into
ArrayRef<MCPhysReg> AllSGPR64s = TRI->getAllSGPR64(MF);
unsigned NumPreloaded = (MFI->getNumPreloadedSGPRs() + 1) / 2;
AllSGPR64s = AllSGPR64s.slice(
std::min(static_cast<unsigned>(AllSGPR64s.size()), NumPreloaded));
Register GITPtrLoReg = MFI->getGITPtrLoReg(MF);
for (MCPhysReg Reg : AllSGPR64s) {
if (LiveUnits.available(Reg) && !MRI.isReserved(Reg) &&
MRI.isAllocatable(Reg) && !TRI->isSubRegisterEq(Reg, GITPtrLoReg)) {
FlatScratchInit = Reg;
break;
}
}
} else {
FlatScratchInit =
MFI->getPreloadedReg(AMDGPUFunctionArgInfo::FLAT_SCRATCH_INIT);
MRI.addLiveIn(FlatScratchInit);
MBB.addLiveIn(FlatScratchInit);
}
assert(FlatScratchInit && "Failed to find free register for scratch init");
Register FlatScratchInitLo = TRI->getSubReg(FlatScratchInit, AMDGPU::sub0);
Register FlatScratchInitHi = TRI->getSubReg(FlatScratchInit, AMDGPU::sub1);
if (ST.isAmdPalOS()) {
buildGitPtr(MBB, I, DL, TII, FlatScratchInit);
```
https://github.com/llvm/llvm-project/pull/79586
More information about the llvm-commits
mailing list