[llvm] [AMDGPU] Add pal metadata 3.0 support to callable pal funcs (PR #67104)

David Stuttard via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 12 02:32:43 PDT 2023


================
@@ -1098,10 +1098,30 @@ void AMDGPUAsmPrinter::emitPALFunctionMetadata(const MachineFunction &MF) {
   StringRef FnName = MF.getFunction().getName();
   MD->setFunctionScratchSize(FnName, MFI.getStackSize());
 
-  // Set compute registers
-  MD->setRsrc1(CallingConv::AMDGPU_CS,
-               CurrentProgramInfo.getPGMRSrc1(CallingConv::AMDGPU_CS));
-  MD->setRsrc2(CallingConv::AMDGPU_CS, CurrentProgramInfo.getComputePGMRSrc2());
+  if (MD->getPALMajorVersion() < 3) {
+    // Set compute registers
+    MD->setRsrc1(CallingConv::AMDGPU_CS,
+                 CurrentProgramInfo.getPGMRSrc1(CallingConv::AMDGPU_CS));
+    MD->setRsrc2(CallingConv::AMDGPU_CS,
+                 CurrentProgramInfo.getComputePGMRSrc2());
+  } else {
+    MD->setHwStage(CallingConv::AMDGPU_CS, ".ieee_mode",
+                   (bool)CurrentProgramInfo.IEEEMode);
+    MD->setHwStage(CallingConv::AMDGPU_CS, ".wgp_mode",
+                   (bool)CurrentProgramInfo.WgpMode);
+    MD->setHwStage(CallingConv::AMDGPU_CS, ".mem_ordered",
+                   (bool)CurrentProgramInfo.MemOrdered);
+
+    MD->setHwStage(CallingConv::AMDGPU_CS, ".trap_present",
+                   (bool)CurrentProgramInfo.TrapHandlerEnable);
+    MD->setHwStage(CallingConv::AMDGPU_CS, ".excp_en",
+                   CurrentProgramInfo.EXCPEnable);
+
+    const unsigned LdsDwGranularity = 128;
----------------
dstutt wrote:

> Is this constant defined anywhere else that we could reuse?

Refactoring reduced this to a single definition - but I decided to put it in AMDGPUBaseInfo instead, so it's more logical if it changes in future.

> Looking at this again, this seems to be duplicating code already in AMDGPUAsmPrinter::EmitPALMetadata. Can we share code instead? Particular AMDGPUAsmPrinter::EmitPALMetadata seems to cover more fields which are perhaps relevant here too?

Yes, agreed, there is duplication. I've created a helper function to common that up.
The fields that are NOT set in the EmitPALFunctionMetadata are not required there, so those are still left as separate in the EmitPALMetadata function.


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


More information about the llvm-commits mailing list