1 //===- AMDGPUBaseInfo.h - Top level definitions for AMDGPU ------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUBASEINFO_H 10 #define LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUBASEINFO_H 11 12 #include "SIDefines.h" 13 #include "llvm/IR/CallingConv.h" 14 #include "llvm/IR/InstrTypes.h" 15 #include "llvm/IR/Module.h" 16 #include "llvm/Support/Alignment.h" 17 #include <array> 18 #include <functional> 19 #include <utility> 20 21 struct amd_kernel_code_t; 22 23 namespace llvm { 24 25 struct Align; 26 class Argument; 27 class Function; 28 class GlobalValue; 29 class MCInstrInfo; 30 class MCRegisterClass; 31 class MCRegisterInfo; 32 class MCSubtargetInfo; 33 class StringRef; 34 class TargetRegisterClass; 35 class Triple; 36 class raw_ostream; 37 38 namespace amdhsa { 39 struct kernel_descriptor_t; 40 } 41 42 namespace AMDGPU { 43 44 struct IsaVersion; 45 46 enum { 47 AMDHSA_COV2 = 2, 48 AMDHSA_COV3 = 3, 49 AMDHSA_COV4 = 4, 50 AMDHSA_COV5 = 5 51 }; 52 53 /// \returns HSA OS ABI Version identification. 54 std::optional<uint8_t> getHsaAbiVersion(const MCSubtargetInfo *STI); 55 /// \returns True if HSA OS ABI Version identification is 2, 56 /// false otherwise. 57 bool isHsaAbiVersion2(const MCSubtargetInfo *STI); 58 /// \returns True if HSA OS ABI Version identification is 3, 59 /// false otherwise. 60 bool isHsaAbiVersion3(const MCSubtargetInfo *STI); 61 /// \returns True if HSA OS ABI Version identification is 4, 62 /// false otherwise. 63 bool isHsaAbiVersion4(const MCSubtargetInfo *STI); 64 /// \returns True if HSA OS ABI Version identification is 5, 65 /// false otherwise. 66 bool isHsaAbiVersion5(const MCSubtargetInfo *STI); 67 /// \returns True if HSA OS ABI Version identification is 3 and above, 68 /// false otherwise. 69 bool isHsaAbiVersion3AndAbove(const MCSubtargetInfo *STI); 70 71 /// \returns The offset of the multigrid_sync_arg argument from implicitarg_ptr 72 unsigned getMultigridSyncArgImplicitArgPosition(unsigned COV); 73 74 /// \returns The offset of the hostcall pointer argument from implicitarg_ptr 75 unsigned getHostcallImplicitArgPosition(unsigned COV); 76 77 unsigned getDefaultQueueImplicitArgPosition(unsigned COV); 78 unsigned getCompletionActionImplicitArgPosition(unsigned COV); 79 80 /// \returns Code object version. 81 unsigned getAmdhsaCodeObjectVersion(); 82 83 /// \returns Code object version. 84 unsigned getCodeObjectVersion(const Module &M); 85 86 struct GcnBufferFormatInfo { 87 unsigned Format; 88 unsigned BitsPerComp; 89 unsigned NumComponents; 90 unsigned NumFormat; 91 unsigned DataFormat; 92 }; 93 94 struct MAIInstInfo { 95 uint16_t Opcode; 96 bool is_dgemm; 97 bool is_gfx940_xdl; 98 }; 99 100 #define GET_MIMGBaseOpcode_DECL 101 #define GET_MIMGDim_DECL 102 #define GET_MIMGEncoding_DECL 103 #define GET_MIMGLZMapping_DECL 104 #define GET_MIMGMIPMapping_DECL 105 #define GET_MIMGBiASMapping_DECL 106 #define GET_MAIInstInfoTable_DECL 107 #include "AMDGPUGenSearchableTables.inc" 108 109 namespace IsaInfo { 110 111 enum { 112 // The closed Vulkan driver sets 96, which limits the wave count to 8 but 113 // doesn't spill SGPRs as much as when 80 is set. 114 FIXED_NUM_SGPRS_FOR_INIT_BUG = 96, 115 TRAP_NUM_SGPRS = 16 116 }; 117 118 enum class TargetIDSetting { 119 Unsupported, 120 Any, 121 Off, 122 On 123 }; 124 125 class AMDGPUTargetID { 126 private: 127 const MCSubtargetInfo &STI; 128 TargetIDSetting XnackSetting; 129 TargetIDSetting SramEccSetting; 130 unsigned CodeObjectVersion; 131 132 public: 133 explicit AMDGPUTargetID(const MCSubtargetInfo &STI); 134 ~AMDGPUTargetID() = default; 135 136 /// \return True if the current xnack setting is not "Unsupported". 137 bool isXnackSupported() const { 138 return XnackSetting != TargetIDSetting::Unsupported; 139 } 140 141 /// \returns True if the current xnack setting is "On" or "Any". 142 bool isXnackOnOrAny() const { 143 return XnackSetting == TargetIDSetting::On || 144 XnackSetting == TargetIDSetting::Any; 145 } 146 147 /// \returns True if current xnack setting is "On" or "Off", 148 /// false otherwise. 149 bool isXnackOnOrOff() const { 150 return getXnackSetting() == TargetIDSetting::On || 151 getXnackSetting() == TargetIDSetting::Off; 152 } 153 154 /// \returns The current xnack TargetIDSetting, possible options are 155 /// "Unsupported", "Any", "Off", and "On". 156 TargetIDSetting getXnackSetting() const { 157 return XnackSetting; 158 } 159 160 void setCodeObjectVersion(unsigned COV) { 161 CodeObjectVersion = COV; 162 } 163 164 /// Sets xnack setting to \p NewXnackSetting. 165 void setXnackSetting(TargetIDSetting NewXnackSetting) { 166 XnackSetting = NewXnackSetting; 167 } 168 169 /// \return True if the current sramecc setting is not "Unsupported". 170 bool isSramEccSupported() const { 171 return SramEccSetting != TargetIDSetting::Unsupported; 172 } 173 174 /// \returns True if the current sramecc setting is "On" or "Any". 175 bool isSramEccOnOrAny() const { 176 return SramEccSetting == TargetIDSetting::On || 177 SramEccSetting == TargetIDSetting::Any; 178 } 179 180 /// \returns True if current sramecc setting is "On" or "Off", 181 /// false otherwise. 182 bool isSramEccOnOrOff() const { 183 return getSramEccSetting() == TargetIDSetting::On || 184 getSramEccSetting() == TargetIDSetting::Off; 185 } 186 187 /// \returns The current sramecc TargetIDSetting, possible options are 188 /// "Unsupported", "Any", "Off", and "On". 189 TargetIDSetting getSramEccSetting() const { 190 return SramEccSetting; 191 } 192 193 /// Sets sramecc setting to \p NewSramEccSetting. 194 void setSramEccSetting(TargetIDSetting NewSramEccSetting) { 195 SramEccSetting = NewSramEccSetting; 196 } 197 198 void setTargetIDFromFeaturesString(StringRef FS); 199 void setTargetIDFromTargetIDStream(StringRef TargetID); 200 201 /// \returns String representation of an object. 202 std::string toString() const; 203 }; 204 205 /// \returns Wavefront size for given subtarget \p STI. 206 unsigned getWavefrontSize(const MCSubtargetInfo *STI); 207 208 /// \returns Local memory size in bytes for given subtarget \p STI. 209 unsigned getLocalMemorySize(const MCSubtargetInfo *STI); 210 211 /// \returns Maximum addressable local memory size in bytes for given subtarget 212 /// \p STI. 213 unsigned getAddressableLocalMemorySize(const MCSubtargetInfo *STI); 214 215 /// \returns Number of execution units per compute unit for given subtarget \p 216 /// STI. 217 unsigned getEUsPerCU(const MCSubtargetInfo *STI); 218 219 /// \returns Maximum number of work groups per compute unit for given subtarget 220 /// \p STI and limited by given \p FlatWorkGroupSize. 221 unsigned getMaxWorkGroupsPerCU(const MCSubtargetInfo *STI, 222 unsigned FlatWorkGroupSize); 223 224 /// \returns Minimum number of waves per execution unit for given subtarget \p 225 /// STI. 226 unsigned getMinWavesPerEU(const MCSubtargetInfo *STI); 227 228 /// \returns Maximum number of waves per execution unit for given subtarget \p 229 /// STI without any kind of limitation. 230 unsigned getMaxWavesPerEU(const MCSubtargetInfo *STI); 231 232 /// \returns Number of waves per execution unit required to support the given \p 233 /// FlatWorkGroupSize. 234 unsigned getWavesPerEUForWorkGroup(const MCSubtargetInfo *STI, 235 unsigned FlatWorkGroupSize); 236 237 /// \returns Minimum flat work group size for given subtarget \p STI. 238 unsigned getMinFlatWorkGroupSize(const MCSubtargetInfo *STI); 239 240 /// \returns Maximum flat work group size for given subtarget \p STI. 241 unsigned getMaxFlatWorkGroupSize(const MCSubtargetInfo *STI); 242 243 /// \returns Number of waves per work group for given subtarget \p STI and 244 /// \p FlatWorkGroupSize. 245 unsigned getWavesPerWorkGroup(const MCSubtargetInfo *STI, 246 unsigned FlatWorkGroupSize); 247 248 /// \returns SGPR allocation granularity for given subtarget \p STI. 249 unsigned getSGPRAllocGranule(const MCSubtargetInfo *STI); 250 251 /// \returns SGPR encoding granularity for given subtarget \p STI. 252 unsigned getSGPREncodingGranule(const MCSubtargetInfo *STI); 253 254 /// \returns Total number of SGPRs for given subtarget \p STI. 255 unsigned getTotalNumSGPRs(const MCSubtargetInfo *STI); 256 257 /// \returns Addressable number of SGPRs for given subtarget \p STI. 258 unsigned getAddressableNumSGPRs(const MCSubtargetInfo *STI); 259 260 /// \returns Minimum number of SGPRs that meets the given number of waves per 261 /// execution unit requirement for given subtarget \p STI. 262 unsigned getMinNumSGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU); 263 264 /// \returns Maximum number of SGPRs that meets the given number of waves per 265 /// execution unit requirement for given subtarget \p STI. 266 unsigned getMaxNumSGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU, 267 bool Addressable); 268 269 /// \returns Number of extra SGPRs implicitly required by given subtarget \p 270 /// STI when the given special registers are used. 271 unsigned getNumExtraSGPRs(const MCSubtargetInfo *STI, bool VCCUsed, 272 bool FlatScrUsed, bool XNACKUsed); 273 274 /// \returns Number of extra SGPRs implicitly required by given subtarget \p 275 /// STI when the given special registers are used. XNACK is inferred from 276 /// \p STI. 277 unsigned getNumExtraSGPRs(const MCSubtargetInfo *STI, bool VCCUsed, 278 bool FlatScrUsed); 279 280 /// \returns Number of SGPR blocks needed for given subtarget \p STI when 281 /// \p NumSGPRs are used. \p NumSGPRs should already include any special 282 /// register counts. 283 unsigned getNumSGPRBlocks(const MCSubtargetInfo *STI, unsigned NumSGPRs); 284 285 /// \returns VGPR allocation granularity for given subtarget \p STI. 286 /// 287 /// For subtargets which support it, \p EnableWavefrontSize32 should match 288 /// the ENABLE_WAVEFRONT_SIZE32 kernel descriptor field. 289 unsigned 290 getVGPRAllocGranule(const MCSubtargetInfo *STI, 291 std::optional<bool> EnableWavefrontSize32 = std::nullopt); 292 293 /// \returns VGPR encoding granularity for given subtarget \p STI. 294 /// 295 /// For subtargets which support it, \p EnableWavefrontSize32 should match 296 /// the ENABLE_WAVEFRONT_SIZE32 kernel descriptor field. 297 unsigned getVGPREncodingGranule( 298 const MCSubtargetInfo *STI, 299 std::optional<bool> EnableWavefrontSize32 = std::nullopt); 300 301 /// \returns Total number of VGPRs for given subtarget \p STI. 302 unsigned getTotalNumVGPRs(const MCSubtargetInfo *STI); 303 304 /// \returns Addressable number of VGPRs for given subtarget \p STI. 305 unsigned getAddressableNumVGPRs(const MCSubtargetInfo *STI); 306 307 /// \returns Minimum number of VGPRs that meets given number of waves per 308 /// execution unit requirement for given subtarget \p STI. 309 unsigned getMinNumVGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU); 310 311 /// \returns Maximum number of VGPRs that meets given number of waves per 312 /// execution unit requirement for given subtarget \p STI. 313 unsigned getMaxNumVGPRs(const MCSubtargetInfo *STI, unsigned WavesPerEU); 314 315 /// \returns Number of waves reachable for a given \p NumVGPRs usage for given 316 /// subtarget \p STI. 317 unsigned getNumWavesPerEUWithNumVGPRs(const MCSubtargetInfo *STI, 318 unsigned NumVGPRs); 319 320 /// \returns Number of VGPR blocks needed for given subtarget \p STI when 321 /// \p NumVGPRs are used. 322 /// 323 /// For subtargets which support it, \p EnableWavefrontSize32 should match the 324 /// ENABLE_WAVEFRONT_SIZE32 kernel descriptor field. 325 unsigned 326 getNumVGPRBlocks(const MCSubtargetInfo *STI, unsigned NumSGPRs, 327 std::optional<bool> EnableWavefrontSize32 = std::nullopt); 328 329 } // end namespace IsaInfo 330 331 LLVM_READONLY 332 int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx); 333 334 LLVM_READONLY 335 inline bool hasNamedOperand(uint64_t Opcode, uint64_t NamedIdx) { 336 return getNamedOperandIdx(Opcode, NamedIdx) != -1; 337 } 338 339 LLVM_READONLY 340 int getSOPPWithRelaxation(uint16_t Opcode); 341 342 struct MIMGBaseOpcodeInfo { 343 MIMGBaseOpcode BaseOpcode; 344 bool Store; 345 bool Atomic; 346 bool AtomicX2; 347 bool Sampler; 348 bool Gather4; 349 350 uint8_t NumExtraArgs; 351 bool Gradients; 352 bool G16; 353 bool Coordinates; 354 bool LodOrClampOrMip; 355 bool HasD16; 356 bool MSAA; 357 bool BVH; 358 bool A16; 359 }; 360 361 LLVM_READONLY 362 const MIMGBaseOpcodeInfo *getMIMGBaseOpcode(unsigned Opc); 363 364 LLVM_READONLY 365 const MIMGBaseOpcodeInfo *getMIMGBaseOpcodeInfo(unsigned BaseOpcode); 366 367 struct MIMGDimInfo { 368 MIMGDim Dim; 369 uint8_t NumCoords; 370 uint8_t NumGradients; 371 bool MSAA; 372 bool DA; 373 uint8_t Encoding; 374 const char *AsmSuffix; 375 }; 376 377 LLVM_READONLY 378 const MIMGDimInfo *getMIMGDimInfo(unsigned DimEnum); 379 380 LLVM_READONLY 381 const MIMGDimInfo *getMIMGDimInfoByEncoding(uint8_t DimEnc); 382 383 LLVM_READONLY 384 const MIMGDimInfo *getMIMGDimInfoByAsmSuffix(StringRef AsmSuffix); 385 386 struct MIMGLZMappingInfo { 387 MIMGBaseOpcode L; 388 MIMGBaseOpcode LZ; 389 }; 390 391 struct MIMGMIPMappingInfo { 392 MIMGBaseOpcode MIP; 393 MIMGBaseOpcode NONMIP; 394 }; 395 396 struct MIMGBiasMappingInfo { 397 MIMGBaseOpcode Bias; 398 MIMGBaseOpcode NoBias; 399 }; 400 401 struct MIMGOffsetMappingInfo { 402 MIMGBaseOpcode Offset; 403 MIMGBaseOpcode NoOffset; 404 }; 405 406 struct MIMGG16MappingInfo { 407 MIMGBaseOpcode G; 408 MIMGBaseOpcode G16; 409 }; 410 411 LLVM_READONLY 412 const MIMGLZMappingInfo *getMIMGLZMappingInfo(unsigned L); 413 414 struct WMMAOpcodeMappingInfo { 415 unsigned Opcode2Addr; 416 unsigned Opcode3Addr; 417 }; 418 419 LLVM_READONLY 420 const MIMGMIPMappingInfo *getMIMGMIPMappingInfo(unsigned MIP); 421 422 LLVM_READONLY 423 const MIMGBiasMappingInfo *getMIMGBiasMappingInfo(unsigned Bias); 424 425 LLVM_READONLY 426 const MIMGOffsetMappingInfo *getMIMGOffsetMappingInfo(unsigned Offset); 427 428 LLVM_READONLY 429 const MIMGG16MappingInfo *getMIMGG16MappingInfo(unsigned G); 430 431 LLVM_READONLY 432 int getMIMGOpcode(unsigned BaseOpcode, unsigned MIMGEncoding, 433 unsigned VDataDwords, unsigned VAddrDwords); 434 435 LLVM_READONLY 436 int getMaskedMIMGOp(unsigned Opc, unsigned NewChannels); 437 438 LLVM_READONLY 439 unsigned getAddrSizeMIMGOp(const MIMGBaseOpcodeInfo *BaseOpcode, 440 const MIMGDimInfo *Dim, bool IsA16, 441 bool IsG16Supported); 442 443 struct MIMGInfo { 444 uint16_t Opcode; 445 uint16_t BaseOpcode; 446 uint8_t MIMGEncoding; 447 uint8_t VDataDwords; 448 uint8_t VAddrDwords; 449 uint8_t VAddrOperands; 450 }; 451 452 LLVM_READONLY 453 const MIMGInfo *getMIMGInfo(unsigned Opc); 454 455 LLVM_READONLY 456 int getMTBUFBaseOpcode(unsigned Opc); 457 458 LLVM_READONLY 459 int getMTBUFOpcode(unsigned BaseOpc, unsigned Elements); 460 461 LLVM_READONLY 462 int getMTBUFElements(unsigned Opc); 463 464 LLVM_READONLY 465 bool getMTBUFHasVAddr(unsigned Opc); 466 467 LLVM_READONLY 468 bool getMTBUFHasSrsrc(unsigned Opc); 469 470 LLVM_READONLY 471 bool getMTBUFHasSoffset(unsigned Opc); 472 473 LLVM_READONLY 474 int getMUBUFBaseOpcode(unsigned Opc); 475 476 LLVM_READONLY 477 int getMUBUFOpcode(unsigned BaseOpc, unsigned Elements); 478 479 LLVM_READONLY 480 int getMUBUFElements(unsigned Opc); 481 482 LLVM_READONLY 483 bool getMUBUFHasVAddr(unsigned Opc); 484 485 LLVM_READONLY 486 bool getMUBUFHasSrsrc(unsigned Opc); 487 488 LLVM_READONLY 489 bool getMUBUFHasSoffset(unsigned Opc); 490 491 LLVM_READONLY 492 bool getMUBUFIsBufferInv(unsigned Opc); 493 494 LLVM_READONLY 495 bool getSMEMIsBuffer(unsigned Opc); 496 497 LLVM_READONLY 498 bool getVOP1IsSingle(unsigned Opc); 499 500 LLVM_READONLY 501 bool getVOP2IsSingle(unsigned Opc); 502 503 LLVM_READONLY 504 bool getVOP3IsSingle(unsigned Opc); 505 506 LLVM_READONLY 507 bool isVOPC64DPP(unsigned Opc); 508 509 /// Returns true if MAI operation is a double precision GEMM. 510 LLVM_READONLY 511 bool getMAIIsDGEMM(unsigned Opc); 512 513 LLVM_READONLY 514 bool getMAIIsGFX940XDL(unsigned Opc); 515 516 struct CanBeVOPD { 517 bool X; 518 bool Y; 519 }; 520 521 LLVM_READONLY 522 CanBeVOPD getCanBeVOPD(unsigned Opc); 523 524 LLVM_READONLY 525 const GcnBufferFormatInfo *getGcnBufferFormatInfo(uint8_t BitsPerComp, 526 uint8_t NumComponents, 527 uint8_t NumFormat, 528 const MCSubtargetInfo &STI); 529 LLVM_READONLY 530 const GcnBufferFormatInfo *getGcnBufferFormatInfo(uint8_t Format, 531 const MCSubtargetInfo &STI); 532 533 LLVM_READONLY 534 int getMCOpcode(uint16_t Opcode, unsigned Gen); 535 536 LLVM_READONLY 537 unsigned getVOPDOpcode(unsigned Opc); 538 539 LLVM_READONLY 540 int getVOPDFull(unsigned OpX, unsigned OpY); 541 542 LLVM_READONLY 543 bool isVOPD(unsigned Opc); 544 545 LLVM_READNONE 546 bool isMAC(unsigned Opc); 547 548 LLVM_READNONE 549 bool isPermlane16(unsigned Opc); 550 551 namespace VOPD { 552 553 enum Component : unsigned { 554 DST = 0, 555 SRC0, 556 SRC1, 557 SRC2, 558 559 DST_NUM = 1, 560 MAX_SRC_NUM = 3, 561 MAX_OPR_NUM = DST_NUM + MAX_SRC_NUM 562 }; 563 564 // LSB mask for VGPR banks per VOPD component operand. 565 // 4 banks result in a mask 3, setting 2 lower bits. 566 constexpr unsigned VOPD_VGPR_BANK_MASKS[] = {1, 3, 3, 1}; 567 568 enum ComponentIndex : unsigned { X = 0, Y = 1 }; 569 constexpr unsigned COMPONENTS[] = {ComponentIndex::X, ComponentIndex::Y}; 570 constexpr unsigned COMPONENTS_NUM = 2; 571 572 // Properties of VOPD components. 573 class ComponentProps { 574 private: 575 unsigned SrcOperandsNum = 0; 576 unsigned MandatoryLiteralIdx = ~0u; 577 bool HasSrc2Acc = false; 578 579 public: 580 ComponentProps() = default; 581 ComponentProps(const MCInstrDesc &OpDesc); 582 583 // Return the total number of src operands this component has. 584 unsigned getCompSrcOperandsNum() const { return SrcOperandsNum; } 585 586 // Return the number of src operands of this component visible to the parser. 587 unsigned getCompParsedSrcOperandsNum() const { 588 return SrcOperandsNum - HasSrc2Acc; 589 } 590 591 // Return true iif this component has a mandatory literal. 592 bool hasMandatoryLiteral() const { return MandatoryLiteralIdx != ~0u; } 593 594 // If this component has a mandatory literal, return component operand 595 // index of this literal (i.e. either Component::SRC1 or Component::SRC2). 596 unsigned getMandatoryLiteralCompOperandIndex() const { 597 assert(hasMandatoryLiteral()); 598 return MandatoryLiteralIdx; 599 } 600 601 // Return true iif this component has operand 602 // with component index CompSrcIdx and this operand may be a register. 603 bool hasRegSrcOperand(unsigned CompSrcIdx) const { 604 assert(CompSrcIdx < Component::MAX_SRC_NUM); 605 return SrcOperandsNum > CompSrcIdx && !hasMandatoryLiteralAt(CompSrcIdx); 606 } 607 608 // Return true iif this component has tied src2. 609 bool hasSrc2Acc() const { return HasSrc2Acc; } 610 611 private: 612 bool hasMandatoryLiteralAt(unsigned CompSrcIdx) const { 613 assert(CompSrcIdx < Component::MAX_SRC_NUM); 614 return MandatoryLiteralIdx == Component::DST_NUM + CompSrcIdx; 615 } 616 }; 617 618 enum ComponentKind : unsigned { 619 SINGLE = 0, // A single VOP1 or VOP2 instruction which may be used in VOPD. 620 COMPONENT_X, // A VOPD instruction, X component. 621 COMPONENT_Y, // A VOPD instruction, Y component. 622 MAX = COMPONENT_Y 623 }; 624 625 // Interface functions of this class map VOPD component operand indices 626 // to indices of operands in MachineInstr/MCInst or parsed operands array. 627 // 628 // Note that this class operates with 3 kinds of indices: 629 // - VOPD component operand indices (Component::DST, Component::SRC0, etc.); 630 // - MC operand indices (they refer operands in a MachineInstr/MCInst); 631 // - parsed operand indices (they refer operands in parsed operands array). 632 // 633 // For SINGLE components mapping between these indices is trivial. 634 // But things get more complicated for COMPONENT_X and 635 // COMPONENT_Y because these components share the same 636 // MachineInstr/MCInst and the same parsed operands array. 637 // Below is an example of component operand to parsed operand 638 // mapping for the following instruction: 639 // 640 // v_dual_add_f32 v255, v4, v5 :: v_dual_mov_b32 v6, v1 641 // 642 // PARSED COMPONENT PARSED 643 // COMPONENT OPERANDS OPERAND INDEX OPERAND INDEX 644 // ------------------------------------------------------------------- 645 // "v_dual_add_f32" 0 646 // v_dual_add_f32 v255 0 (DST) --> 1 647 // v4 1 (SRC0) --> 2 648 // v5 2 (SRC1) --> 3 649 // "::" 4 650 // "v_dual_mov_b32" 5 651 // v_dual_mov_b32 v6 0 (DST) --> 6 652 // v1 1 (SRC0) --> 7 653 // ------------------------------------------------------------------- 654 // 655 class ComponentLayout { 656 private: 657 // Regular MachineInstr/MCInst operands are ordered as follows: 658 // dst, src0 [, other src operands] 659 // VOPD MachineInstr/MCInst operands are ordered as follows: 660 // dstX, dstY, src0X [, other OpX operands], src0Y [, other OpY operands] 661 // Each ComponentKind has operand indices defined below. 662 static constexpr unsigned MC_DST_IDX[] = {0, 0, 1}; 663 static constexpr unsigned FIRST_MC_SRC_IDX[] = {1, 2, 2 /* + OpX.MCSrcNum */}; 664 665 // Parsed operands of regular instructions are ordered as follows: 666 // Mnemo dst src0 [vsrc1 ...] 667 // Parsed VOPD operands are ordered as follows: 668 // OpXMnemo dstX src0X [vsrc1X|imm vsrc1X|vsrc1X imm] '::' 669 // OpYMnemo dstY src0Y [vsrc1Y|imm vsrc1Y|vsrc1Y imm] 670 // Each ComponentKind has operand indices defined below. 671 static constexpr unsigned PARSED_DST_IDX[] = {1, 1, 672 4 /* + OpX.ParsedSrcNum */}; 673 static constexpr unsigned FIRST_PARSED_SRC_IDX[] = { 674 2, 2, 5 /* + OpX.ParsedSrcNum */}; 675 676 private: 677 const ComponentKind Kind; 678 const ComponentProps PrevComp; 679 680 public: 681 // Create layout for COMPONENT_X or SINGLE component. 682 ComponentLayout(ComponentKind Kind) : Kind(Kind) { 683 assert(Kind == ComponentKind::SINGLE || Kind == ComponentKind::COMPONENT_X); 684 } 685 686 // Create layout for COMPONENT_Y which depends on COMPONENT_X layout. 687 ComponentLayout(const ComponentProps &OpXProps) 688 : Kind(ComponentKind::COMPONENT_Y), PrevComp(OpXProps) {} 689 690 public: 691 // Return the index of dst operand in MCInst operands. 692 unsigned getIndexOfDstInMCOperands() const { return MC_DST_IDX[Kind]; } 693 694 // Return the index of the specified src operand in MCInst operands. 695 unsigned getIndexOfSrcInMCOperands(unsigned CompSrcIdx) const { 696 assert(CompSrcIdx < Component::MAX_SRC_NUM); 697 return FIRST_MC_SRC_IDX[Kind] + getPrevCompSrcNum() + CompSrcIdx; 698 } 699 700 // Return the index of dst operand in the parsed operands array. 701 unsigned getIndexOfDstInParsedOperands() const { 702 return PARSED_DST_IDX[Kind] + getPrevCompParsedSrcNum(); 703 } 704 705 // Return the index of the specified src operand in the parsed operands array. 706 unsigned getIndexOfSrcInParsedOperands(unsigned CompSrcIdx) const { 707 assert(CompSrcIdx < Component::MAX_SRC_NUM); 708 return FIRST_PARSED_SRC_IDX[Kind] + getPrevCompParsedSrcNum() + CompSrcIdx; 709 } 710 711 private: 712 unsigned getPrevCompSrcNum() const { 713 return PrevComp.getCompSrcOperandsNum(); 714 } 715 unsigned getPrevCompParsedSrcNum() const { 716 return PrevComp.getCompParsedSrcOperandsNum(); 717 } 718 }; 719 720 // Layout and properties of VOPD components. 721 class ComponentInfo : public ComponentLayout, public ComponentProps { 722 public: 723 // Create ComponentInfo for COMPONENT_X or SINGLE component. 724 ComponentInfo(const MCInstrDesc &OpDesc, 725 ComponentKind Kind = ComponentKind::SINGLE) 726 : ComponentLayout(Kind), ComponentProps(OpDesc) {} 727 728 // Create ComponentInfo for COMPONENT_Y which depends on COMPONENT_X layout. 729 ComponentInfo(const MCInstrDesc &OpDesc, const ComponentProps &OpXProps) 730 : ComponentLayout(OpXProps), ComponentProps(OpDesc) {} 731 732 // Map component operand index to parsed operand index. 733 // Return 0 if the specified operand does not exist. 734 unsigned getIndexInParsedOperands(unsigned CompOprIdx) const; 735 }; 736 737 // Properties of VOPD instructions. 738 class InstInfo { 739 private: 740 const ComponentInfo CompInfo[COMPONENTS_NUM]; 741 742 public: 743 using RegIndices = std::array<unsigned, Component::MAX_OPR_NUM>; 744 745 InstInfo(const MCInstrDesc &OpX, const MCInstrDesc &OpY) 746 : CompInfo{OpX, OpY} {} 747 748 InstInfo(const ComponentInfo &OprInfoX, const ComponentInfo &OprInfoY) 749 : CompInfo{OprInfoX, OprInfoY} {} 750 751 const ComponentInfo &operator[](size_t ComponentIdx) const { 752 assert(ComponentIdx < COMPONENTS_NUM); 753 return CompInfo[ComponentIdx]; 754 } 755 756 // Check VOPD operands constraints. 757 // GetRegIdx(Component, MCOperandIdx) must return a VGPR register index 758 // for the specified component and MC operand. The callback must return 0 759 // if the operand is not a register or not a VGPR. 760 bool hasInvalidOperand( 761 std::function<unsigned(unsigned, unsigned)> GetRegIdx) const { 762 return getInvalidCompOperandIndex(GetRegIdx).has_value(); 763 } 764 765 // Check VOPD operands constraints. 766 // Return the index of an invalid component operand, if any. 767 std::optional<unsigned> getInvalidCompOperandIndex( 768 std::function<unsigned(unsigned, unsigned)> GetRegIdx) const; 769 770 private: 771 RegIndices 772 getRegIndices(unsigned ComponentIdx, 773 std::function<unsigned(unsigned, unsigned)> GetRegIdx) const; 774 }; 775 776 } // namespace VOPD 777 778 LLVM_READONLY 779 std::pair<unsigned, unsigned> getVOPDComponents(unsigned VOPDOpcode); 780 781 LLVM_READONLY 782 // Get properties of 2 single VOP1/VOP2 instructions 783 // used as components to create a VOPD instruction. 784 VOPD::InstInfo getVOPDInstInfo(const MCInstrDesc &OpX, const MCInstrDesc &OpY); 785 786 LLVM_READONLY 787 // Get properties of VOPD X and Y components. 788 VOPD::InstInfo 789 getVOPDInstInfo(unsigned VOPDOpcode, const MCInstrInfo *InstrInfo); 790 791 LLVM_READONLY 792 bool isTrue16Inst(unsigned Opc); 793 794 LLVM_READONLY 795 unsigned mapWMMA2AddrTo3AddrOpcode(unsigned Opc); 796 797 LLVM_READONLY 798 unsigned mapWMMA3AddrTo2AddrOpcode(unsigned Opc); 799 800 void initDefaultAMDKernelCodeT(amd_kernel_code_t &Header, 801 const MCSubtargetInfo *STI); 802 803 amdhsa::kernel_descriptor_t getDefaultAmdhsaKernelDescriptor( 804 const MCSubtargetInfo *STI); 805 806 bool isGroupSegment(const GlobalValue *GV); 807 bool isGlobalSegment(const GlobalValue *GV); 808 bool isReadOnlySegment(const GlobalValue *GV); 809 810 /// \returns True if constants should be emitted to .text section for given 811 /// target triple \p TT, false otherwise. 812 bool shouldEmitConstantsToTextSection(const Triple &TT); 813 814 /// \returns Integer value requested using \p F's \p Name attribute. 815 /// 816 /// \returns \p Default if attribute is not present. 817 /// 818 /// \returns \p Default and emits error if requested value cannot be converted 819 /// to integer. 820 int getIntegerAttribute(const Function &F, StringRef Name, int Default); 821 822 /// \returns A pair of integer values requested using \p F's \p Name attribute 823 /// in "first[,second]" format ("second" is optional unless \p OnlyFirstRequired 824 /// is false). 825 /// 826 /// \returns \p Default if attribute is not present. 827 /// 828 /// \returns \p Default and emits error if one of the requested values cannot be 829 /// converted to integer, or \p OnlyFirstRequired is false and "second" value is 830 /// not present. 831 std::pair<unsigned, unsigned> 832 getIntegerPairAttribute(const Function &F, StringRef Name, 833 std::pair<unsigned, unsigned> Default, 834 bool OnlyFirstRequired = false); 835 836 /// Represents the counter values to wait for in an s_waitcnt instruction. 837 /// 838 /// Large values (including the maximum possible integer) can be used to 839 /// represent "don't care" waits. 840 struct Waitcnt { 841 unsigned VmCnt = ~0u; 842 unsigned ExpCnt = ~0u; 843 unsigned LgkmCnt = ~0u; 844 unsigned VsCnt = ~0u; 845 846 Waitcnt() = default; 847 Waitcnt(unsigned VmCnt, unsigned ExpCnt, unsigned LgkmCnt, unsigned VsCnt) 848 : VmCnt(VmCnt), ExpCnt(ExpCnt), LgkmCnt(LgkmCnt), VsCnt(VsCnt) {} 849 850 static Waitcnt allZero(bool HasVscnt) { 851 return Waitcnt(0, 0, 0, HasVscnt ? 0 : ~0u); 852 } 853 static Waitcnt allZeroExceptVsCnt() { return Waitcnt(0, 0, 0, ~0u); } 854 855 bool hasWait() const { 856 return VmCnt != ~0u || ExpCnt != ~0u || LgkmCnt != ~0u || VsCnt != ~0u; 857 } 858 859 bool hasWaitExceptVsCnt() const { 860 return VmCnt != ~0u || ExpCnt != ~0u || LgkmCnt != ~0u; 861 } 862 863 bool hasWaitVsCnt() const { 864 return VsCnt != ~0u; 865 } 866 867 Waitcnt combined(const Waitcnt &Other) const { 868 return Waitcnt(std::min(VmCnt, Other.VmCnt), std::min(ExpCnt, Other.ExpCnt), 869 std::min(LgkmCnt, Other.LgkmCnt), 870 std::min(VsCnt, Other.VsCnt)); 871 } 872 }; 873 874 /// \returns Vmcnt bit mask for given isa \p Version. 875 unsigned getVmcntBitMask(const IsaVersion &Version); 876 877 /// \returns Expcnt bit mask for given isa \p Version. 878 unsigned getExpcntBitMask(const IsaVersion &Version); 879 880 /// \returns Lgkmcnt bit mask for given isa \p Version. 881 unsigned getLgkmcntBitMask(const IsaVersion &Version); 882 883 /// \returns Waitcnt bit mask for given isa \p Version. 884 unsigned getWaitcntBitMask(const IsaVersion &Version); 885 886 /// \returns Decoded Vmcnt from given \p Waitcnt for given isa \p Version. 887 unsigned decodeVmcnt(const IsaVersion &Version, unsigned Waitcnt); 888 889 /// \returns Decoded Expcnt from given \p Waitcnt for given isa \p Version. 890 unsigned decodeExpcnt(const IsaVersion &Version, unsigned Waitcnt); 891 892 /// \returns Decoded Lgkmcnt from given \p Waitcnt for given isa \p Version. 893 unsigned decodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt); 894 895 /// Decodes Vmcnt, Expcnt and Lgkmcnt from given \p Waitcnt for given isa 896 /// \p Version, and writes decoded values into \p Vmcnt, \p Expcnt and 897 /// \p Lgkmcnt respectively. 898 /// 899 /// \details \p Vmcnt, \p Expcnt and \p Lgkmcnt are decoded as follows: 900 /// \p Vmcnt = \p Waitcnt[3:0] (pre-gfx9) 901 /// \p Vmcnt = \p Waitcnt[15:14,3:0] (gfx9,10) 902 /// \p Vmcnt = \p Waitcnt[15:10] (gfx11+) 903 /// \p Expcnt = \p Waitcnt[6:4] (pre-gfx11) 904 /// \p Expcnt = \p Waitcnt[2:0] (gfx11+) 905 /// \p Lgkmcnt = \p Waitcnt[11:8] (pre-gfx10) 906 /// \p Lgkmcnt = \p Waitcnt[13:8] (gfx10) 907 /// \p Lgkmcnt = \p Waitcnt[9:4] (gfx11+) 908 void decodeWaitcnt(const IsaVersion &Version, unsigned Waitcnt, 909 unsigned &Vmcnt, unsigned &Expcnt, unsigned &Lgkmcnt); 910 911 Waitcnt decodeWaitcnt(const IsaVersion &Version, unsigned Encoded); 912 913 /// \returns \p Waitcnt with encoded \p Vmcnt for given isa \p Version. 914 unsigned encodeVmcnt(const IsaVersion &Version, unsigned Waitcnt, 915 unsigned Vmcnt); 916 917 /// \returns \p Waitcnt with encoded \p Expcnt for given isa \p Version. 918 unsigned encodeExpcnt(const IsaVersion &Version, unsigned Waitcnt, 919 unsigned Expcnt); 920 921 /// \returns \p Waitcnt with encoded \p Lgkmcnt for given isa \p Version. 922 unsigned encodeLgkmcnt(const IsaVersion &Version, unsigned Waitcnt, 923 unsigned Lgkmcnt); 924 925 /// Encodes \p Vmcnt, \p Expcnt and \p Lgkmcnt into Waitcnt for given isa 926 /// \p Version. 927 /// 928 /// \details \p Vmcnt, \p Expcnt and \p Lgkmcnt are encoded as follows: 929 /// Waitcnt[2:0] = \p Expcnt (gfx11+) 930 /// Waitcnt[3:0] = \p Vmcnt (pre-gfx9) 931 /// Waitcnt[3:0] = \p Vmcnt[3:0] (gfx9,10) 932 /// Waitcnt[6:4] = \p Expcnt (pre-gfx11) 933 /// Waitcnt[9:4] = \p Lgkmcnt (gfx11+) 934 /// Waitcnt[11:8] = \p Lgkmcnt (pre-gfx10) 935 /// Waitcnt[13:8] = \p Lgkmcnt (gfx10) 936 /// Waitcnt[15:10] = \p Vmcnt (gfx11+) 937 /// Waitcnt[15:14] = \p Vmcnt[5:4] (gfx9,10) 938 /// 939 /// \returns Waitcnt with encoded \p Vmcnt, \p Expcnt and \p Lgkmcnt for given 940 /// isa \p Version. 941 unsigned encodeWaitcnt(const IsaVersion &Version, 942 unsigned Vmcnt, unsigned Expcnt, unsigned Lgkmcnt); 943 944 unsigned encodeWaitcnt(const IsaVersion &Version, const Waitcnt &Decoded); 945 946 namespace Hwreg { 947 948 LLVM_READONLY 949 int64_t getHwregId(const StringRef Name, const MCSubtargetInfo &STI); 950 951 LLVM_READNONE 952 bool isValidHwreg(int64_t Id); 953 954 LLVM_READNONE 955 bool isValidHwregOffset(int64_t Offset); 956 957 LLVM_READNONE 958 bool isValidHwregWidth(int64_t Width); 959 960 LLVM_READNONE 961 uint64_t encodeHwreg(uint64_t Id, uint64_t Offset, uint64_t Width); 962 963 LLVM_READNONE 964 StringRef getHwreg(unsigned Id, const MCSubtargetInfo &STI); 965 966 void decodeHwreg(unsigned Val, unsigned &Id, unsigned &Offset, unsigned &Width); 967 968 } // namespace Hwreg 969 970 namespace DepCtr { 971 972 int getDefaultDepCtrEncoding(const MCSubtargetInfo &STI); 973 int encodeDepCtr(const StringRef Name, int64_t Val, unsigned &UsedOprMask, 974 const MCSubtargetInfo &STI); 975 bool isSymbolicDepCtrEncoding(unsigned Code, bool &HasNonDefaultVal, 976 const MCSubtargetInfo &STI); 977 bool decodeDepCtr(unsigned Code, int &Id, StringRef &Name, unsigned &Val, 978 bool &IsDefault, const MCSubtargetInfo &STI); 979 980 /// \returns Decoded VaVdst from given immediate \p Encoded. 981 unsigned decodeFieldVaVdst(unsigned Encoded); 982 983 /// \returns Decoded VmVsrc from given immediate \p Encoded. 984 unsigned decodeFieldVmVsrc(unsigned Encoded); 985 986 /// \returns Decoded SaSdst from given immediate \p Encoded. 987 unsigned decodeFieldSaSdst(unsigned Encoded); 988 989 /// \returns \p VmVsrc as an encoded Depctr immediate. 990 unsigned encodeFieldVmVsrc(unsigned VmVsrc); 991 992 /// \returns \p Encoded combined with encoded \p VmVsrc. 993 unsigned encodeFieldVmVsrc(unsigned Encoded, unsigned VmVsrc); 994 995 /// \returns \p VaVdst as an encoded Depctr immediate. 996 unsigned encodeFieldVaVdst(unsigned VaVdst); 997 998 /// \returns \p Encoded combined with encoded \p VaVdst. 999 unsigned encodeFieldVaVdst(unsigned Encoded, unsigned VaVdst); 1000 1001 /// \returns \p SaSdst as an encoded Depctr immediate. 1002 unsigned encodeFieldSaSdst(unsigned SaSdst); 1003 1004 /// \returns \p Encoded combined with encoded \p SaSdst. 1005 unsigned encodeFieldSaSdst(unsigned Encoded, unsigned SaSdst); 1006 1007 } // namespace DepCtr 1008 1009 namespace Exp { 1010 1011 bool getTgtName(unsigned Id, StringRef &Name, int &Index); 1012 1013 LLVM_READONLY 1014 unsigned getTgtId(const StringRef Name); 1015 1016 LLVM_READNONE 1017 bool isSupportedTgtId(unsigned Id, const MCSubtargetInfo &STI); 1018 1019 } // namespace Exp 1020 1021 namespace MTBUFFormat { 1022 1023 LLVM_READNONE 1024 int64_t encodeDfmtNfmt(unsigned Dfmt, unsigned Nfmt); 1025 1026 void decodeDfmtNfmt(unsigned Format, unsigned &Dfmt, unsigned &Nfmt); 1027 1028 int64_t getDfmt(const StringRef Name); 1029 1030 StringRef getDfmtName(unsigned Id); 1031 1032 int64_t getNfmt(const StringRef Name, const MCSubtargetInfo &STI); 1033 1034 StringRef getNfmtName(unsigned Id, const MCSubtargetInfo &STI); 1035 1036 bool isValidDfmtNfmt(unsigned Val, const MCSubtargetInfo &STI); 1037 1038 bool isValidNfmt(unsigned Val, const MCSubtargetInfo &STI); 1039 1040 int64_t getUnifiedFormat(const StringRef Name, const MCSubtargetInfo &STI); 1041 1042 StringRef getUnifiedFormatName(unsigned Id, const MCSubtargetInfo &STI); 1043 1044 bool isValidUnifiedFormat(unsigned Val, const MCSubtargetInfo &STI); 1045 1046 int64_t convertDfmtNfmt2Ufmt(unsigned Dfmt, unsigned Nfmt, 1047 const MCSubtargetInfo &STI); 1048 1049 bool isValidFormatEncoding(unsigned Val, const MCSubtargetInfo &STI); 1050 1051 unsigned getDefaultFormatEncoding(const MCSubtargetInfo &STI); 1052 1053 } // namespace MTBUFFormat 1054 1055 namespace SendMsg { 1056 1057 LLVM_READONLY 1058 int64_t getMsgId(const StringRef Name, const MCSubtargetInfo &STI); 1059 1060 LLVM_READONLY 1061 int64_t getMsgOpId(int64_t MsgId, const StringRef Name); 1062 1063 LLVM_READNONE 1064 StringRef getMsgName(int64_t MsgId, const MCSubtargetInfo &STI); 1065 1066 LLVM_READNONE 1067 StringRef getMsgOpName(int64_t MsgId, int64_t OpId, const MCSubtargetInfo &STI); 1068 1069 LLVM_READNONE 1070 bool isValidMsgId(int64_t MsgId, const MCSubtargetInfo &STI); 1071 1072 LLVM_READNONE 1073 bool isValidMsgOp(int64_t MsgId, int64_t OpId, const MCSubtargetInfo &STI, 1074 bool Strict = true); 1075 1076 LLVM_READNONE 1077 bool isValidMsgStream(int64_t MsgId, int64_t OpId, int64_t StreamId, 1078 const MCSubtargetInfo &STI, bool Strict = true); 1079 1080 LLVM_READNONE 1081 bool msgRequiresOp(int64_t MsgId, const MCSubtargetInfo &STI); 1082 1083 LLVM_READNONE 1084 bool msgSupportsStream(int64_t MsgId, int64_t OpId, const MCSubtargetInfo &STI); 1085 1086 void decodeMsg(unsigned Val, uint16_t &MsgId, uint16_t &OpId, 1087 uint16_t &StreamId, const MCSubtargetInfo &STI); 1088 1089 LLVM_READNONE 1090 uint64_t encodeMsg(uint64_t MsgId, 1091 uint64_t OpId, 1092 uint64_t StreamId); 1093 1094 } // namespace SendMsg 1095 1096 1097 unsigned getInitialPSInputAddr(const Function &F); 1098 1099 bool getHasColorExport(const Function &F); 1100 1101 bool getHasDepthExport(const Function &F); 1102 1103 LLVM_READNONE 1104 bool isShader(CallingConv::ID CC); 1105 1106 LLVM_READNONE 1107 bool isGraphics(CallingConv::ID CC); 1108 1109 LLVM_READNONE 1110 bool isCompute(CallingConv::ID CC); 1111 1112 LLVM_READNONE 1113 bool isEntryFunctionCC(CallingConv::ID CC); 1114 1115 // These functions are considered entrypoints into the current module, i.e. they 1116 // are allowed to be called from outside the current module. This is different 1117 // from isEntryFunctionCC, which is only true for functions that are entered by 1118 // the hardware. Module entry points include all entry functions but also 1119 // include functions that can be called from other functions inside or outside 1120 // the current module. Module entry functions are allowed to allocate LDS. 1121 LLVM_READNONE 1122 bool isModuleEntryFunctionCC(CallingConv::ID CC); 1123 1124 bool isKernelCC(const Function *Func); 1125 1126 // FIXME: Remove this when calling conventions cleaned up 1127 LLVM_READNONE 1128 inline bool isKernel(CallingConv::ID CC) { 1129 switch (CC) { 1130 case CallingConv::AMDGPU_KERNEL: 1131 case CallingConv::SPIR_KERNEL: 1132 return true; 1133 default: 1134 return false; 1135 } 1136 } 1137 1138 bool hasXNACK(const MCSubtargetInfo &STI); 1139 bool hasSRAMECC(const MCSubtargetInfo &STI); 1140 bool hasMIMG_R128(const MCSubtargetInfo &STI); 1141 bool hasA16(const MCSubtargetInfo &STI); 1142 bool hasG16(const MCSubtargetInfo &STI); 1143 bool hasPackedD16(const MCSubtargetInfo &STI); 1144 unsigned getNSAMaxSize(const MCSubtargetInfo &STI); 1145 1146 bool isSI(const MCSubtargetInfo &STI); 1147 bool isCI(const MCSubtargetInfo &STI); 1148 bool isVI(const MCSubtargetInfo &STI); 1149 bool isGFX9(const MCSubtargetInfo &STI); 1150 bool isGFX9_GFX10(const MCSubtargetInfo &STI); 1151 bool isGFX8_GFX9_GFX10(const MCSubtargetInfo &STI); 1152 bool isGFX8Plus(const MCSubtargetInfo &STI); 1153 bool isGFX9Plus(const MCSubtargetInfo &STI); 1154 bool isGFX10(const MCSubtargetInfo &STI); 1155 bool isGFX10Plus(const MCSubtargetInfo &STI); 1156 bool isNotGFX10Plus(const MCSubtargetInfo &STI); 1157 bool isGFX10Before1030(const MCSubtargetInfo &STI); 1158 bool isGFX11(const MCSubtargetInfo &STI); 1159 bool isGFX11Plus(const MCSubtargetInfo &STI); 1160 bool isNotGFX11Plus(const MCSubtargetInfo &STI); 1161 bool isGCN3Encoding(const MCSubtargetInfo &STI); 1162 bool isGFX10_AEncoding(const MCSubtargetInfo &STI); 1163 bool isGFX10_BEncoding(const MCSubtargetInfo &STI); 1164 bool hasGFX10_3Insts(const MCSubtargetInfo &STI); 1165 bool isGFX90A(const MCSubtargetInfo &STI); 1166 bool isGFX940(const MCSubtargetInfo &STI); 1167 bool hasArchitectedFlatScratch(const MCSubtargetInfo &STI); 1168 bool hasMAIInsts(const MCSubtargetInfo &STI); 1169 bool hasVOPD(const MCSubtargetInfo &STI); 1170 int getTotalNumVGPRs(bool has90AInsts, int32_t ArgNumAGPR, int32_t ArgNumVGPR); 1171 1172 /// Is Reg - scalar register 1173 bool isSGPR(unsigned Reg, const MCRegisterInfo* TRI); 1174 1175 /// If \p Reg is a pseudo reg, return the correct hardware register given 1176 /// \p STI otherwise return \p Reg. 1177 unsigned getMCReg(unsigned Reg, const MCSubtargetInfo &STI); 1178 1179 /// Convert hardware register \p Reg to a pseudo register 1180 LLVM_READNONE 1181 unsigned mc2PseudoReg(unsigned Reg); 1182 1183 LLVM_READNONE 1184 bool isInlineValue(unsigned Reg); 1185 1186 /// Is this an AMDGPU specific source operand? These include registers, 1187 /// inline constants, literals and mandatory literals (KImm). 1188 bool isSISrcOperand(const MCInstrDesc &Desc, unsigned OpNo); 1189 1190 /// Is this a KImm operand? 1191 bool isKImmOperand(const MCInstrDesc &Desc, unsigned OpNo); 1192 1193 /// Is this floating-point operand? 1194 bool isSISrcFPOperand(const MCInstrDesc &Desc, unsigned OpNo); 1195 1196 /// Does this operand support only inlinable literals? 1197 bool isSISrcInlinableOperand(const MCInstrDesc &Desc, unsigned OpNo); 1198 1199 /// Get the size in bits of a register from the register class \p RC. 1200 unsigned getRegBitWidth(unsigned RCID); 1201 1202 /// Get the size in bits of a register from the register class \p RC. 1203 unsigned getRegBitWidth(const MCRegisterClass &RC); 1204 1205 /// Get the size in bits of a register from the register class \p RC. 1206 unsigned getRegBitWidth(const TargetRegisterClass &RC); 1207 1208 /// Get size of register operand 1209 unsigned getRegOperandSize(const MCRegisterInfo *MRI, const MCInstrDesc &Desc, 1210 unsigned OpNo); 1211 1212 LLVM_READNONE 1213 inline unsigned getOperandSize(const MCOperandInfo &OpInfo) { 1214 switch (OpInfo.OperandType) { 1215 case AMDGPU::OPERAND_REG_IMM_INT32: 1216 case AMDGPU::OPERAND_REG_IMM_FP32: 1217 case AMDGPU::OPERAND_REG_IMM_FP32_DEFERRED: 1218 case AMDGPU::OPERAND_REG_INLINE_C_INT32: 1219 case AMDGPU::OPERAND_REG_INLINE_C_FP32: 1220 case AMDGPU::OPERAND_REG_INLINE_AC_INT32: 1221 case AMDGPU::OPERAND_REG_INLINE_AC_FP32: 1222 case AMDGPU::OPERAND_REG_IMM_V2INT32: 1223 case AMDGPU::OPERAND_REG_IMM_V2FP32: 1224 case AMDGPU::OPERAND_REG_INLINE_C_V2INT32: 1225 case AMDGPU::OPERAND_REG_INLINE_C_V2FP32: 1226 case AMDGPU::OPERAND_KIMM32: 1227 case AMDGPU::OPERAND_KIMM16: // mandatory literal is always size 4 1228 return 4; 1229 1230 case AMDGPU::OPERAND_REG_IMM_INT64: 1231 case AMDGPU::OPERAND_REG_IMM_FP64: 1232 case AMDGPU::OPERAND_REG_INLINE_C_INT64: 1233 case AMDGPU::OPERAND_REG_INLINE_C_FP64: 1234 case AMDGPU::OPERAND_REG_INLINE_AC_FP64: 1235 return 8; 1236 1237 case AMDGPU::OPERAND_REG_IMM_INT16: 1238 case AMDGPU::OPERAND_REG_IMM_FP16: 1239 case AMDGPU::OPERAND_REG_IMM_FP16_DEFERRED: 1240 case AMDGPU::OPERAND_REG_INLINE_C_INT16: 1241 case AMDGPU::OPERAND_REG_INLINE_C_FP16: 1242 case AMDGPU::OPERAND_REG_INLINE_C_V2INT16: 1243 case AMDGPU::OPERAND_REG_INLINE_C_V2FP16: 1244 case AMDGPU::OPERAND_REG_INLINE_AC_INT16: 1245 case AMDGPU::OPERAND_REG_INLINE_AC_FP16: 1246 case AMDGPU::OPERAND_REG_INLINE_AC_V2INT16: 1247 case AMDGPU::OPERAND_REG_INLINE_AC_V2FP16: 1248 case AMDGPU::OPERAND_REG_IMM_V2INT16: 1249 case AMDGPU::OPERAND_REG_IMM_V2FP16: 1250 return 2; 1251 1252 default: 1253 llvm_unreachable("unhandled operand type"); 1254 } 1255 } 1256 1257 LLVM_READNONE 1258 inline unsigned getOperandSize(const MCInstrDesc &Desc, unsigned OpNo) { 1259 return getOperandSize(Desc.operands()[OpNo]); 1260 } 1261 1262 /// Is this literal inlinable, and not one of the values intended for floating 1263 /// point values. 1264 LLVM_READNONE 1265 inline bool isInlinableIntLiteral(int64_t Literal) { 1266 return Literal >= -16 && Literal <= 64; 1267 } 1268 1269 /// Is this literal inlinable 1270 LLVM_READNONE 1271 bool isInlinableLiteral64(int64_t Literal, bool HasInv2Pi); 1272 1273 LLVM_READNONE 1274 bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi); 1275 1276 LLVM_READNONE 1277 bool isInlinableLiteral16(int16_t Literal, bool HasInv2Pi); 1278 1279 LLVM_READNONE 1280 bool isInlinableLiteralV216(int32_t Literal, bool HasInv2Pi); 1281 1282 LLVM_READNONE 1283 bool isInlinableIntLiteralV216(int32_t Literal); 1284 1285 LLVM_READNONE 1286 bool isFoldableLiteralV216(int32_t Literal, bool HasInv2Pi); 1287 1288 bool isArgPassedInSGPR(const Argument *Arg); 1289 1290 bool isArgPassedInSGPR(const CallBase *CB, unsigned ArgNo); 1291 1292 LLVM_READONLY 1293 bool isLegalSMRDEncodedUnsignedOffset(const MCSubtargetInfo &ST, 1294 int64_t EncodedOffset); 1295 1296 LLVM_READONLY 1297 bool isLegalSMRDEncodedSignedOffset(const MCSubtargetInfo &ST, 1298 int64_t EncodedOffset, 1299 bool IsBuffer); 1300 1301 /// Convert \p ByteOffset to dwords if the subtarget uses dword SMRD immediate 1302 /// offsets. 1303 uint64_t convertSMRDOffsetUnits(const MCSubtargetInfo &ST, uint64_t ByteOffset); 1304 1305 /// \returns The encoding that will be used for \p ByteOffset in the 1306 /// SMRD offset field, or std::nullopt if it won't fit. On GFX9 and GFX10 1307 /// S_LOAD instructions have a signed offset, on other subtargets it is 1308 /// unsigned. S_BUFFER has an unsigned offset for all subtargets. 1309 std::optional<int64_t> getSMRDEncodedOffset(const MCSubtargetInfo &ST, 1310 int64_t ByteOffset, bool IsBuffer); 1311 1312 /// \return The encoding that can be used for a 32-bit literal offset in an SMRD 1313 /// instruction. This is only useful on CI.s 1314 std::optional<int64_t> getSMRDEncodedLiteralOffset32(const MCSubtargetInfo &ST, 1315 int64_t ByteOffset); 1316 1317 /// For FLAT segment the offset must be positive; 1318 /// MSB is ignored and forced to zero. 1319 /// 1320 /// \return The number of bits available for the signed offset field in flat 1321 /// instructions. Note that some forms of the instruction disallow negative 1322 /// offsets. 1323 unsigned getNumFlatOffsetBits(const MCSubtargetInfo &ST); 1324 1325 /// \returns true if this offset is small enough to fit in the SMRD 1326 /// offset field. \p ByteOffset should be the offset in bytes and 1327 /// not the encoded offset. 1328 bool isLegalSMRDImmOffset(const MCSubtargetInfo &ST, int64_t ByteOffset); 1329 1330 LLVM_READNONE 1331 inline bool isLegal64BitDPPControl(unsigned DC) { 1332 return DC >= DPP::ROW_NEWBCAST_FIRST && DC <= DPP::ROW_NEWBCAST_LAST; 1333 } 1334 1335 /// \returns true if the intrinsic is divergent 1336 bool isIntrinsicSourceOfDivergence(unsigned IntrID); 1337 1338 /// \returns true if the intrinsic is uniform 1339 bool isIntrinsicAlwaysUniform(unsigned IntrID); 1340 1341 } // end namespace AMDGPU 1342 1343 raw_ostream &operator<<(raw_ostream &OS, 1344 const AMDGPU::IsaInfo::TargetIDSetting S); 1345 1346 } // end namespace llvm 1347 1348 #endif // LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUBASEINFO_H 1349