[llvm] AMDGPU gfx12: Add _dvgpr$ symbols for dynamic VGPRs (PR #148251)
Tim Renouf via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 21 23:52:04 PDT 2025
================
@@ -890,6 +871,51 @@ bool AMDGPUAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
return false;
}
+// When appropriate, add a _dvgpr$ symbol, with the value of the function
+// symbol, plus an offset encoding one less than the number of VGPR blocks used
+// by the function in bits 5..3 of the symbol value. A "VGPR block" can be
+// either 16 VGPRs (for a max of 128), or 32 VGPRs (for a max of 256). This is
+// used by a front-end to have functions that are chained rather than called,
+// and a dispatcher that dynamically resizes the VGPR count before dispatching
+// to a function.
+void AMDGPUAsmPrinter::emitDVgprSymbol(MachineFunction &MF) {
+ const SIMachineFunctionInfo &MFI = *MF.getInfo<SIMachineFunctionInfo>();
+ if (MFI.isDynamicVGPREnabled() &&
+ MF.getFunction().getCallingConv() == CallingConv::AMDGPU_CS_Chain) {
+ MCContext &Ctx = MF.getContext();
+ unsigned BlockSize = MFI.getDynamicVGPRBlockSize();
+ MCValue NumVGPRs;
+ if (!CurrentProgramInfo.NumVGPRsForWavesPerEU->evaluateAsRelocatable(
+ NumVGPRs, nullptr) ||
+ !NumVGPRs.isAbsolute()) {
+ OutContext.reportError({}, "Unable to resolve _dvgpr$ symbol for '" +
+ Twine(MF.getName()) + "'");
+ return;
+ }
+ // Calculate number of VGPR blocks.
+ // Treat 0 VGPRs as 1 VGPR to avoid underflowing.
+ unsigned NumBlocks =
+ (std::max(unsigned(NumVGPRs.getConstant()), 1U) + BlockSize - 1) /
+ BlockSize;
+ if (NumBlocks > 8) {
+ OutContext.reportError({},
+ "Too many DVGPR blocks for _dvgpr$ symbol for '" +
----------------
trenouf wrote:
I have added a test for the "too many" error. I don't know if it is possible to provoke the "unable to resolve" error, where the number of vgprs symbol cannot be resolved to an absolute value. If not, should it be an assert rather than an error?
https://github.com/llvm/llvm-project/pull/148251
More information about the llvm-commits
mailing list