[llvm] AMDGPU gfx12: Add _dvgpr$ symbols for dynamic VGPRs (PR #148251)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 13 23:38:07 PDT 2025


================
@@ -194,6 +194,29 @@ void AMDGPUAsmPrinter::emitFunctionBodyStart() {
     return;
   }
 
+  if (STM.isDynamicVGPREnabled() &&
+      MF->getFunction().getCallingConv() == CallingConv::AMDGPU_CS_Chain) {
+    // 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 (16 VGPRs per block, no more than 128) in bits 5..3 of the
+    // symbol value. 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.
+    MCContext &Ctx = MF->getContext();
+    unsigned EncodedNumVGPRs = (ResourceUsage->NumVGPR - 1) >> 1 & 0x38;
+    MCSymbol *CurPCSym = Ctx.createTempSymbol();
+    OutStreamer->emitLabel(CurPCSym);
+    const MCExpr *DVgprFuncVal = MCBinaryExpr::createAdd(
+        MCSymbolRefExpr::create(CurPCSym, Ctx),
+        MCConstantExpr::create(EncodedNumVGPRs, Ctx), Ctx);
+    MCSymbol *DVgprFuncSym =
+        Ctx.getOrCreateSymbol(Twine("_dvgpr$") + MF->getFunction().getName());
----------------
arsenm wrote:

Is this the right prefix to use? Is this using the right visibility? 

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


More information about the llvm-commits mailing list