File indexing completed on 2026-05-10 08:44:27
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef LLVM_SUPPORT_AMDGPUMETADATA_H
0016 #define LLVM_SUPPORT_AMDGPUMETADATA_H
0017
0018 #include "llvm/ADT/StringRef.h"
0019 #include <cstdint>
0020 #include <string>
0021 #include <system_error>
0022 #include <vector>
0023
0024 namespace llvm {
0025 namespace AMDGPU {
0026
0027
0028
0029
0030 namespace HSAMD {
0031
0032
0033 constexpr uint32_t VersionMajorV3 = 1;
0034
0035 constexpr uint32_t VersionMinorV3 = 0;
0036
0037
0038 constexpr uint32_t VersionMajorV4 = 1;
0039
0040 constexpr uint32_t VersionMinorV4 = 1;
0041
0042
0043 constexpr uint32_t VersionMajorV5 = 1;
0044
0045 constexpr uint32_t VersionMinorV5 = 2;
0046
0047
0048 constexpr uint32_t VersionMajorV6 = 1;
0049
0050 constexpr uint32_t VersionMinorV6 = 2;
0051
0052
0053
0054
0055
0056 constexpr char AssemblerDirectiveBegin[] = ".amd_amdgpu_hsa_metadata";
0057
0058
0059 enum class AccessQualifier : uint8_t {
0060 Default = 0,
0061 ReadOnly = 1,
0062 WriteOnly = 2,
0063 ReadWrite = 3,
0064 Unknown = 0xff
0065 };
0066
0067
0068 enum class AddressSpaceQualifier : uint8_t {
0069 Private = 0,
0070 Global = 1,
0071 Constant = 2,
0072 Local = 3,
0073 Generic = 4,
0074 Region = 5,
0075 Unknown = 0xff
0076 };
0077
0078
0079 enum class ValueKind : uint8_t {
0080 ByValue = 0,
0081 GlobalBuffer = 1,
0082 DynamicSharedPointer = 2,
0083 Sampler = 3,
0084 Image = 4,
0085 Pipe = 5,
0086 Queue = 6,
0087 HiddenGlobalOffsetX = 7,
0088 HiddenGlobalOffsetY = 8,
0089 HiddenGlobalOffsetZ = 9,
0090 HiddenNone = 10,
0091 HiddenPrintfBuffer = 11,
0092 HiddenDefaultQueue = 12,
0093 HiddenCompletionAction = 13,
0094 HiddenMultiGridSyncArg = 14,
0095 HiddenHostcallBuffer = 15,
0096 Unknown = 0xff
0097 };
0098
0099
0100
0101 enum class ValueType : uint8_t {
0102 Struct = 0,
0103 I8 = 1,
0104 U8 = 2,
0105 I16 = 3,
0106 U16 = 4,
0107 F16 = 5,
0108 I32 = 6,
0109 U32 = 7,
0110 F32 = 8,
0111 I64 = 9,
0112 U64 = 10,
0113 F64 = 11,
0114 Unknown = 0xff
0115 };
0116
0117
0118
0119
0120 namespace Kernel {
0121
0122
0123
0124
0125 namespace Attrs {
0126
0127 namespace Key {
0128
0129 constexpr char ReqdWorkGroupSize[] = "ReqdWorkGroupSize";
0130
0131 constexpr char WorkGroupSizeHint[] = "WorkGroupSizeHint";
0132
0133 constexpr char VecTypeHint[] = "VecTypeHint";
0134
0135 constexpr char RuntimeHandle[] = "RuntimeHandle";
0136 }
0137
0138
0139 struct Metadata final {
0140
0141 std::vector<uint32_t> mReqdWorkGroupSize = std::vector<uint32_t>();
0142
0143 std::vector<uint32_t> mWorkGroupSizeHint = std::vector<uint32_t>();
0144
0145 std::string mVecTypeHint = std::string();
0146
0147
0148 std::string mRuntimeHandle = std::string();
0149
0150
0151 Metadata() = default;
0152
0153
0154 bool empty() const {
0155 return !notEmpty();
0156 }
0157
0158
0159 bool notEmpty() const {
0160 return !mReqdWorkGroupSize.empty() || !mWorkGroupSizeHint.empty() ||
0161 !mVecTypeHint.empty() || !mRuntimeHandle.empty();
0162 }
0163 };
0164
0165 }
0166
0167
0168
0169
0170 namespace Arg {
0171
0172 namespace Key {
0173
0174 constexpr char Name[] = "Name";
0175
0176 constexpr char TypeName[] = "TypeName";
0177
0178 constexpr char Size[] = "Size";
0179
0180 constexpr char Offset[] = "Offset";
0181
0182 constexpr char Align[] = "Align";
0183
0184 constexpr char ValueKind[] = "ValueKind";
0185
0186 constexpr char ValueType[] = "ValueType";
0187
0188 constexpr char PointeeAlign[] = "PointeeAlign";
0189
0190 constexpr char AddrSpaceQual[] = "AddrSpaceQual";
0191
0192 constexpr char AccQual[] = "AccQual";
0193
0194 constexpr char ActualAccQual[] = "ActualAccQual";
0195
0196 constexpr char IsConst[] = "IsConst";
0197
0198 constexpr char IsRestrict[] = "IsRestrict";
0199
0200 constexpr char IsVolatile[] = "IsVolatile";
0201
0202 constexpr char IsPipe[] = "IsPipe";
0203 }
0204
0205
0206 struct Metadata final {
0207
0208 std::string mName = std::string();
0209
0210 std::string mTypeName = std::string();
0211
0212 uint32_t mSize = 0;
0213
0214 uint32_t mOffset = 0;
0215
0216 uint32_t mAlign = 0;
0217
0218 ValueKind mValueKind = ValueKind::Unknown;
0219
0220 uint32_t mPointeeAlign = 0;
0221
0222 AddressSpaceQualifier mAddrSpaceQual = AddressSpaceQualifier::Unknown;
0223
0224 AccessQualifier mAccQual = AccessQualifier::Unknown;
0225
0226 AccessQualifier mActualAccQual = AccessQualifier::Unknown;
0227
0228 bool mIsConst = false;
0229
0230 bool mIsRestrict = false;
0231
0232 bool mIsVolatile = false;
0233
0234 bool mIsPipe = false;
0235
0236
0237 Metadata() = default;
0238 };
0239
0240 }
0241
0242
0243
0244
0245 namespace CodeProps {
0246
0247 namespace Key {
0248
0249 constexpr char KernargSegmentSize[] = "KernargSegmentSize";
0250
0251 constexpr char GroupSegmentFixedSize[] = "GroupSegmentFixedSize";
0252
0253 constexpr char PrivateSegmentFixedSize[] = "PrivateSegmentFixedSize";
0254
0255 constexpr char KernargSegmentAlign[] = "KernargSegmentAlign";
0256
0257 constexpr char WavefrontSize[] = "WavefrontSize";
0258
0259 constexpr char NumSGPRs[] = "NumSGPRs";
0260
0261 constexpr char NumVGPRs[] = "NumVGPRs";
0262
0263 constexpr char MaxFlatWorkGroupSize[] = "MaxFlatWorkGroupSize";
0264
0265 constexpr char IsDynamicCallStack[] = "IsDynamicCallStack";
0266
0267 constexpr char IsXNACKEnabled[] = "IsXNACKEnabled";
0268
0269 constexpr char NumSpilledSGPRs[] = "NumSpilledSGPRs";
0270
0271 constexpr char NumSpilledVGPRs[] = "NumSpilledVGPRs";
0272 }
0273
0274
0275 struct Metadata final {
0276
0277
0278 uint64_t mKernargSegmentSize = 0;
0279
0280
0281
0282 uint32_t mGroupSegmentFixedSize = 0;
0283
0284
0285 uint32_t mPrivateSegmentFixedSize = 0;
0286
0287
0288 uint32_t mKernargSegmentAlign = 0;
0289
0290 uint32_t mWavefrontSize = 0;
0291
0292 uint16_t mNumSGPRs = 0;
0293
0294 uint16_t mNumVGPRs = 0;
0295
0296 uint32_t mMaxFlatWorkGroupSize = 0;
0297
0298
0299 bool mIsDynamicCallStack = false;
0300
0301
0302 bool mIsXNACKEnabled = false;
0303
0304 uint16_t mNumSpilledSGPRs = 0;
0305
0306 uint16_t mNumSpilledVGPRs = 0;
0307
0308
0309 Metadata() = default;
0310
0311
0312
0313 bool empty() const {
0314 return !notEmpty();
0315 }
0316
0317
0318
0319 bool notEmpty() const {
0320 return true;
0321 }
0322 };
0323
0324 }
0325
0326
0327
0328
0329 namespace DebugProps {
0330
0331 namespace Key {
0332
0333 constexpr char DebuggerABIVersion[] = "DebuggerABIVersion";
0334
0335 constexpr char ReservedNumVGPRs[] = "ReservedNumVGPRs";
0336
0337 constexpr char ReservedFirstVGPR[] = "ReservedFirstVGPR";
0338
0339 constexpr char PrivateSegmentBufferSGPR[] = "PrivateSegmentBufferSGPR";
0340
0341
0342 constexpr char WavefrontPrivateSegmentOffsetSGPR[] =
0343 "WavefrontPrivateSegmentOffsetSGPR";
0344 }
0345
0346
0347 struct Metadata final {
0348
0349 std::vector<uint32_t> mDebuggerABIVersion = std::vector<uint32_t>();
0350
0351
0352 uint16_t mReservedNumVGPRs = 0;
0353
0354
0355 uint16_t mReservedFirstVGPR = uint16_t(-1);
0356
0357
0358
0359 uint16_t mPrivateSegmentBufferSGPR = uint16_t(-1);
0360
0361
0362
0363 uint16_t mWavefrontPrivateSegmentOffsetSGPR = uint16_t(-1);
0364
0365
0366 Metadata() = default;
0367
0368
0369
0370 bool empty() const {
0371 return !notEmpty();
0372 }
0373
0374
0375
0376 bool notEmpty() const {
0377 return !mDebuggerABIVersion.empty();
0378 }
0379 };
0380
0381 }
0382
0383 namespace Key {
0384
0385 constexpr char Name[] = "Name";
0386
0387 constexpr char SymbolName[] = "SymbolName";
0388
0389 constexpr char Language[] = "Language";
0390
0391 constexpr char LanguageVersion[] = "LanguageVersion";
0392
0393 constexpr char Attrs[] = "Attrs";
0394
0395 constexpr char Args[] = "Args";
0396
0397 constexpr char CodeProps[] = "CodeProps";
0398
0399 constexpr char DebugProps[] = "DebugProps";
0400 }
0401
0402
0403 struct Metadata final {
0404
0405 std::string mName = std::string();
0406
0407 std::string mSymbolName = std::string();
0408
0409 std::string mLanguage = std::string();
0410
0411 std::vector<uint32_t> mLanguageVersion = std::vector<uint32_t>();
0412
0413 Attrs::Metadata mAttrs = Attrs::Metadata();
0414
0415 std::vector<Arg::Metadata> mArgs = std::vector<Arg::Metadata>();
0416
0417 CodeProps::Metadata mCodeProps = CodeProps::Metadata();
0418
0419 DebugProps::Metadata mDebugProps = DebugProps::Metadata();
0420
0421
0422 Metadata() = default;
0423 };
0424
0425 }
0426
0427 namespace Key {
0428
0429 constexpr char Version[] = "Version";
0430
0431 constexpr char Printf[] = "Printf";
0432
0433 constexpr char Kernels[] = "Kernels";
0434 }
0435
0436
0437 struct Metadata final {
0438
0439 std::vector<uint32_t> mVersion = std::vector<uint32_t>();
0440
0441 std::vector<std::string> mPrintf = std::vector<std::string>();
0442
0443 std::vector<Kernel::Metadata> mKernels = std::vector<Kernel::Metadata>();
0444
0445
0446 Metadata() = default;
0447 };
0448
0449
0450 std::error_code fromString(StringRef String, Metadata &HSAMetadata);
0451
0452
0453 std::error_code toString(Metadata HSAMetadata, std::string &String);
0454
0455
0456
0457
0458 namespace V3 {
0459
0460 constexpr uint32_t VersionMajor = 1;
0461
0462 constexpr uint32_t VersionMinor = 0;
0463
0464
0465 constexpr char AssemblerDirectiveBegin[] = ".amdgpu_metadata";
0466
0467 constexpr char AssemblerDirectiveEnd[] = ".end_amdgpu_metadata";
0468 }
0469
0470 }
0471
0472
0473
0474
0475 namespace PALMD {
0476
0477
0478 constexpr char AssemblerDirective[] = ".amd_amdgpu_pal_metadata";
0479
0480
0481 constexpr char AssemblerDirectiveBegin[] = ".amdgpu_pal_metadata";
0482
0483
0484 constexpr char AssemblerDirectiveEnd[] = ".end_amdgpu_pal_metadata";
0485
0486
0487 enum Key : uint32_t {
0488 R_2E12_COMPUTE_PGM_RSRC1 = 0x2e12,
0489 R_2D4A_SPI_SHADER_PGM_RSRC1_LS = 0x2d4a,
0490 R_2D0A_SPI_SHADER_PGM_RSRC1_HS = 0x2d0a,
0491 R_2CCA_SPI_SHADER_PGM_RSRC1_ES = 0x2cca,
0492 R_2C8A_SPI_SHADER_PGM_RSRC1_GS = 0x2c8a,
0493 R_2C4A_SPI_SHADER_PGM_RSRC1_VS = 0x2c4a,
0494 R_2C0A_SPI_SHADER_PGM_RSRC1_PS = 0x2c0a,
0495 R_2E00_COMPUTE_DISPATCH_INITIATOR = 0x2e00,
0496 R_A1B3_SPI_PS_INPUT_ENA = 0xa1b3,
0497 R_A1B4_SPI_PS_INPUT_ADDR = 0xa1b4,
0498 R_A1B6_SPI_PS_IN_CONTROL = 0xa1b6,
0499 R_A2D5_VGT_SHADER_STAGES_EN = 0xa2d5,
0500
0501 LS_NUM_USED_VGPRS = 0x10000021,
0502 HS_NUM_USED_VGPRS = 0x10000022,
0503 ES_NUM_USED_VGPRS = 0x10000023,
0504 GS_NUM_USED_VGPRS = 0x10000024,
0505 VS_NUM_USED_VGPRS = 0x10000025,
0506 PS_NUM_USED_VGPRS = 0x10000026,
0507 CS_NUM_USED_VGPRS = 0x10000027,
0508
0509 LS_NUM_USED_SGPRS = 0x10000028,
0510 HS_NUM_USED_SGPRS = 0x10000029,
0511 ES_NUM_USED_SGPRS = 0x1000002a,
0512 GS_NUM_USED_SGPRS = 0x1000002b,
0513 VS_NUM_USED_SGPRS = 0x1000002c,
0514 PS_NUM_USED_SGPRS = 0x1000002d,
0515 CS_NUM_USED_SGPRS = 0x1000002e,
0516
0517 LS_SCRATCH_SIZE = 0x10000044,
0518 HS_SCRATCH_SIZE = 0x10000045,
0519 ES_SCRATCH_SIZE = 0x10000046,
0520 GS_SCRATCH_SIZE = 0x10000047,
0521 VS_SCRATCH_SIZE = 0x10000048,
0522 PS_SCRATCH_SIZE = 0x10000049,
0523 CS_SCRATCH_SIZE = 0x1000004a
0524 };
0525
0526 }
0527 }
0528 }
0529
0530 #endif