| 1 | //===-- NVPTXBaseInfo.h - Top-level definitions for NVPTX -------*- 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 | // This file contains small standalone helper functions and enum definitions for |
| 10 | // the NVPTX target useful for the compiler back-end and the MC libraries. |
| 11 | // As such, it deliberately does not include references to LLVM core |
| 12 | // code gen types, passes, etc.. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #ifndef LLVM_LIB_TARGET_NVPTX_MCTARGETDESC_NVPTXBASEINFO_H |
| 17 | #define LLVM_LIB_TARGET_NVPTX_MCTARGETDESC_NVPTXBASEINFO_H |
| 18 | |
| 19 | #include "llvm/ADT/StringRef.h" |
| 20 | #include "llvm/MC/MCRegister.h" |
| 21 | #include "llvm/Support/ErrorHandling.h" |
| 22 | #include "llvm/Support/NVPTXAddrSpace.h" |
| 23 | namespace llvm { |
| 24 | |
| 25 | using namespace NVPTXAS; |
| 26 | |
| 27 | namespace NVPTX { |
| 28 | |
| 29 | // PTX virtual registers are numbered per register class. The asm printer |
| 30 | // packs the class into the upper bits of the register number so that the inst |
| 31 | // printer can recover the name the register was declared with. |
| 32 | enum class VirtualRegisterKind : unsigned { |
| 33 | Physical = 0, |
| 34 | B1 = 1, |
| 35 | B16 = 2, |
| 36 | B32 = 3, |
| 37 | B64 = 4, |
| 38 | B128 = 5, |
| 39 | }; |
| 40 | |
| 41 | constexpr unsigned VirtualRegisterKindShift = 27; |
| 42 | constexpr unsigned VirtualRegisterNumMask = |
| 43 | (1u << VirtualRegisterKindShift) - 1; |
| 44 | |
| 45 | // The packed registers are carried in MCOperands, so they must stay inside the |
| 46 | // range MCRegister reserves for physical registers. |
| 47 | static_assert(((static_cast<unsigned>(VirtualRegisterKind::B128) |
| 48 | << VirtualRegisterKindShift) | |
| 49 | VirtualRegisterNumMask) <= MCRegister::LastPhysicalReg, |
| 50 | "Packed virtual register does not fit in an MCRegister" ); |
| 51 | |
| 52 | /// The name prefix shared by all virtual registers of \p Kind. |
| 53 | inline StringRef getVirtualRegisterPrefix(VirtualRegisterKind Kind) { |
| 54 | switch (Kind) { |
| 55 | case VirtualRegisterKind::B1: |
| 56 | return "%p" ; |
| 57 | case VirtualRegisterKind::B16: |
| 58 | return "%rs" ; |
| 59 | case VirtualRegisterKind::B32: |
| 60 | return "%r" ; |
| 61 | case VirtualRegisterKind::B64: |
| 62 | return "%rd" ; |
| 63 | case VirtualRegisterKind::B128: |
| 64 | return "%rq" ; |
| 65 | case VirtualRegisterKind::Physical: |
| 66 | break; |
| 67 | } |
| 68 | llvm_unreachable("Invalid virtual register kind" ); |
| 69 | } |
| 70 | |
| 71 | } // namespace NVPTX |
| 72 | |
| 73 | namespace NVPTXII { |
| 74 | enum { |
| 75 | // These must be kept in sync with TSFlags in NVPTXInstrFormats.td |
| 76 | // clang-format off |
| 77 | IsTexFlag = 0x40, |
| 78 | IsSuldMask = 0x180, |
| 79 | IsSuldShift = 0x7, |
| 80 | IsSustFlag = 0x200, |
| 81 | IsSurfTexQueryFlag = 0x400, |
| 82 | IsTexModeUnifiedFlag = 0x800, |
| 83 | // clang-format on |
| 84 | }; |
| 85 | } // namespace NVPTXII |
| 86 | |
| 87 | } // namespace llvm |
| 88 | #endif |
| 89 | |