[llvm] [AMDGPU] Update code object metadata for kernarg preload (PR #134666)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 24 06:18:43 PDT 2025


================
@@ -95,11 +98,79 @@ inline raw_ostream &operator<<(raw_ostream &OS, const ArgDescriptor &Arg) {
   return OS;
 }
 
-struct KernArgPreloadDescriptor : public ArgDescriptor {
-  KernArgPreloadDescriptor() {}
-  SmallVector<MCRegister> Regs;
+namespace KernArgPreload {
+
+enum HiddenArg {
+  HIDDEN_BLOCK_COUNT_X = 0,
+  HIDDEN_BLOCK_COUNT_Y = 1,
+  HIDDEN_BLOCK_COUNT_Z = 2,
+  HIDDEN_GROUP_SIZE_X = 3,
+  HIDDEN_GROUP_SIZE_Y = 4,
+  HIDDEN_GROUP_SIZE_Z = 5,
+  HIDDEN_REMAINDER_X = 6,
+  HIDDEN_REMAINDER_Y = 7,
+  HIDDEN_REMAINDER_Z = 8,
+  END_HIDDEN_ARGS = 9
 };
 
+// Stores information about a specific hidden argument.
+struct HiddenArgInfo {
+  // Offset in bytes from the location in the kernearg segment pointed to by
+  // the implicitarg pointer.
+  uint8_t Offset = 0;
+  // The size of the hidden argument in bytes.
+  uint8_t Size = 0;
+  // The name of the hidden argument in the kernel signature.
+  const char *Name = nullptr;
+};
+
+struct HiddenArgUtils {
+  static constexpr HiddenArgInfo HiddenArgs[END_HIDDEN_ARGS] = {
+      {0, 4, "_hidden_block_count_x"}, {4, 4, "_hidden_block_count_y"},
+      {8, 4, "_hidden_block_count_z"}, {12, 2, "_hidden_group_size_x"},
+      {14, 2, "_hidden_group_size_y"}, {16, 2, "_hidden_group_size_z"},
+      {18, 2, "_hidden_remainder_x"},  {20, 2, "_hidden_remainder_y"},
+      {22, 2, "_hidden_remainder_z"}};
+
+  static HiddenArg getHiddenArgFromOffset(unsigned Offset) {
+    for (unsigned I = 0; I < END_HIDDEN_ARGS; ++I) {
+      if (HiddenArgs[I].Offset == Offset)
+        return static_cast<HiddenArg>(I);
+    }
+
+    return END_HIDDEN_ARGS;
+  }
+
+  static Type *getHiddenArgType(LLVMContext &Ctx, HiddenArg HA) {
+    if (HA < END_HIDDEN_ARGS)
+      return Type::getIntNTy(Ctx, HiddenArgs[HA].Size * 8);
+
+    llvm_unreachable("unexpected hidden argument");
+  }
+
+  static const char *getHiddenArgName(HiddenArg HA) {
+    if (HA < END_HIDDEN_ARGS)
+      return HiddenArgs[HA].Name;
+
+    llvm_unreachable("unexpected hidden argument");
+  }
+};
+
+struct KernArgPreloadDescriptor {
+  // Id of the original argument in the IR kernel function argument list.
+  unsigned OrigArgIdx = 0;
+
+  // If this IR argument was split into multiple parts, this is the index of the
+  // part in the original argument.
+  unsigned PartIdx = 0;
+
+  // The registers that the argument is preloaded into. The argument may be
+  // split accross multilpe registers.
----------------
arsenm wrote:

```suggestion
  // split across multiple registers.
```

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


More information about the llvm-commits mailing list