Tom Stellard | 347ac79 | 2015-06-26 21:15:07 +0000 | [diff] [blame] | 1 | //===-- AMDGPUBaseInfo.h - Top level definitions for AMDGPU -----*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUBASEINFO_H |
| 11 | #define LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUBASEINFO_H |
| 12 | |
| 13 | #include "AMDKernelCodeT.h" |
Nicolai Haehnle | df3a20c | 2016-04-06 19:40:20 +0000 | [diff] [blame] | 14 | #include "llvm/IR/CallingConv.h" |
Tom Stellard | 347ac79 | 2015-06-26 21:15:07 +0000 | [diff] [blame] | 15 | |
Sam Kolton | a3ec5c1 | 2016-10-07 14:46:06 +0000 | [diff] [blame] | 16 | #define GET_INSTRINFO_OPERAND_ENUM |
| 17 | #include "AMDGPUGenInstrInfo.inc" |
| 18 | #undef GET_INSTRINFO_OPERAND_ENUM |
| 19 | |
Tom Stellard | 347ac79 | 2015-06-26 21:15:07 +0000 | [diff] [blame] | 20 | namespace llvm { |
| 21 | |
| 22 | class FeatureBitset; |
Tom Stellard | ac00eb5 | 2015-12-15 16:26:16 +0000 | [diff] [blame] | 23 | class Function; |
Tom Stellard | e3b5aea | 2015-12-02 17:00:42 +0000 | [diff] [blame] | 24 | class GlobalValue; |
Tom Stellard | e135ffd | 2015-09-25 21:41:28 +0000 | [diff] [blame] | 25 | class MCContext; |
Sam Kolton | 1eeb11b | 2016-09-09 14:44:04 +0000 | [diff] [blame] | 26 | class MCInstrDesc; |
Krzysztof Parzyszek | c871550 | 2016-10-19 17:40:36 +0000 | [diff] [blame] | 27 | class MCRegisterClass; |
Sam Kolton | 1eeb11b | 2016-09-09 14:44:04 +0000 | [diff] [blame] | 28 | class MCRegisterInfo; |
Tom Stellard | e135ffd | 2015-09-25 21:41:28 +0000 | [diff] [blame] | 29 | class MCSection; |
Tom Stellard | 2b65ed3 | 2015-12-21 18:44:27 +0000 | [diff] [blame] | 30 | class MCSubtargetInfo; |
Tom Stellard | 347ac79 | 2015-06-26 21:15:07 +0000 | [diff] [blame] | 31 | |
| 32 | namespace AMDGPU { |
| 33 | |
Sam Kolton | a3ec5c1 | 2016-10-07 14:46:06 +0000 | [diff] [blame] | 34 | LLVM_READONLY |
| 35 | int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx); |
| 36 | |
Tom Stellard | 347ac79 | 2015-06-26 21:15:07 +0000 | [diff] [blame] | 37 | struct IsaVersion { |
| 38 | unsigned Major; |
| 39 | unsigned Minor; |
| 40 | unsigned Stepping; |
| 41 | }; |
| 42 | |
| 43 | IsaVersion getIsaVersion(const FeatureBitset &Features); |
Tom Stellard | ff7416b | 2015-06-26 21:58:31 +0000 | [diff] [blame] | 44 | void initDefaultAMDKernelCodeT(amd_kernel_code_t &Header, |
| 45 | const FeatureBitset &Features); |
Tom Stellard | e135ffd | 2015-09-25 21:41:28 +0000 | [diff] [blame] | 46 | MCSection *getHSATextSection(MCContext &Ctx); |
Tom Stellard | 347ac79 | 2015-06-26 21:15:07 +0000 | [diff] [blame] | 47 | |
Tom Stellard | 00f2f91 | 2015-12-02 19:47:57 +0000 | [diff] [blame] | 48 | MCSection *getHSADataGlobalAgentSection(MCContext &Ctx); |
| 49 | |
| 50 | MCSection *getHSADataGlobalProgramSection(MCContext &Ctx); |
| 51 | |
Tom Stellard | 9760f03 | 2015-12-03 03:34:32 +0000 | [diff] [blame] | 52 | MCSection *getHSARodataReadonlyAgentSection(MCContext &Ctx); |
| 53 | |
Tom Stellard | e3b5aea | 2015-12-02 17:00:42 +0000 | [diff] [blame] | 54 | bool isGroupSegment(const GlobalValue *GV); |
Tom Stellard | 00f2f91 | 2015-12-02 19:47:57 +0000 | [diff] [blame] | 55 | bool isGlobalSegment(const GlobalValue *GV); |
| 56 | bool isReadOnlySegment(const GlobalValue *GV); |
Tom Stellard | e3b5aea | 2015-12-02 17:00:42 +0000 | [diff] [blame] | 57 | |
Konstantin Zhuravlyov | 08326b6 | 2016-10-20 18:12:38 +0000 | [diff] [blame] | 58 | /// \returns True if constants should be emitted to .text section for given |
| 59 | /// target triple \p TT, false otherwise. |
| 60 | bool shouldEmitConstantsToTextSection(const Triple &TT); |
| 61 | |
Konstantin Zhuravlyov | 1d65026 | 2016-09-06 20:22:28 +0000 | [diff] [blame] | 62 | /// \returns Integer value requested using \p F's \p Name attribute. |
| 63 | /// |
| 64 | /// \returns \p Default if attribute is not present. |
| 65 | /// |
| 66 | /// \returns \p Default and emits error if requested value cannot be converted |
| 67 | /// to integer. |
Matt Arsenault | 8300272 | 2016-05-12 02:45:18 +0000 | [diff] [blame] | 68 | int getIntegerAttribute(const Function &F, StringRef Name, int Default); |
| 69 | |
Konstantin Zhuravlyov | 1d65026 | 2016-09-06 20:22:28 +0000 | [diff] [blame] | 70 | /// \returns A pair of integer values requested using \p F's \p Name attribute |
| 71 | /// in "first[,second]" format ("second" is optional unless \p OnlyFirstRequired |
| 72 | /// is false). |
| 73 | /// |
| 74 | /// \returns \p Default if attribute is not present. |
| 75 | /// |
| 76 | /// \returns \p Default and emits error if one of the requested values cannot be |
| 77 | /// converted to integer, or \p OnlyFirstRequired is false and "second" value is |
| 78 | /// not present. |
| 79 | std::pair<int, int> getIntegerPairAttribute(const Function &F, |
| 80 | StringRef Name, |
| 81 | std::pair<int, int> Default, |
| 82 | bool OnlyFirstRequired = false); |
| 83 | |
Konstantin Zhuravlyov | cdd4547 | 2016-10-11 18:58:22 +0000 | [diff] [blame] | 84 | /// \returns Waitcnt bit mask for given isa \p Version. |
| 85 | unsigned getWaitcntBitMask(IsaVersion Version); |
Konstantin Zhuravlyov | 836cbff | 2016-09-30 17:01:40 +0000 | [diff] [blame] | 86 | |
Konstantin Zhuravlyov | cdd4547 | 2016-10-11 18:58:22 +0000 | [diff] [blame] | 87 | /// \returns Vmcnt bit mask for given isa \p Version. |
| 88 | unsigned getVmcntBitMask(IsaVersion Version); |
Konstantin Zhuravlyov | 836cbff | 2016-09-30 17:01:40 +0000 | [diff] [blame] | 89 | |
Konstantin Zhuravlyov | cdd4547 | 2016-10-11 18:58:22 +0000 | [diff] [blame] | 90 | /// \returns Expcnt bit mask for given isa \p Version. |
| 91 | unsigned getExpcntBitMask(IsaVersion Version); |
Konstantin Zhuravlyov | 836cbff | 2016-09-30 17:01:40 +0000 | [diff] [blame] | 92 | |
Konstantin Zhuravlyov | cdd4547 | 2016-10-11 18:58:22 +0000 | [diff] [blame] | 93 | /// \returns Lgkmcnt bit mask for given isa \p Version. |
| 94 | unsigned getLgkmcntBitMask(IsaVersion Version); |
Konstantin Zhuravlyov | 836cbff | 2016-09-30 17:01:40 +0000 | [diff] [blame] | 95 | |
Konstantin Zhuravlyov | cdd4547 | 2016-10-11 18:58:22 +0000 | [diff] [blame] | 96 | /// \returns Decoded Vmcnt from given \p Waitcnt for given isa \p Version. |
| 97 | unsigned decodeVmcnt(IsaVersion Version, unsigned Waitcnt); |
Konstantin Zhuravlyov | 836cbff | 2016-09-30 17:01:40 +0000 | [diff] [blame] | 98 | |
Konstantin Zhuravlyov | cdd4547 | 2016-10-11 18:58:22 +0000 | [diff] [blame] | 99 | /// \returns Decoded Expcnt from given \p Waitcnt for given isa \p Version. |
| 100 | unsigned decodeExpcnt(IsaVersion Version, unsigned Waitcnt); |
| 101 | |
| 102 | /// \returns Decoded Lgkmcnt from given \p Waitcnt for given isa \p Version. |
| 103 | unsigned decodeLgkmcnt(IsaVersion Version, unsigned Waitcnt); |
| 104 | |
| 105 | /// \brief Decodes Vmcnt, Expcnt and Lgkmcnt from given \p Waitcnt for given isa |
| 106 | /// \p Version, and writes decoded values into \p Vmcnt, \p Expcnt and |
| 107 | /// \p Lgkmcnt respectively. |
| 108 | /// |
| 109 | /// \details \p Vmcnt, \p Expcnt and \p Lgkmcnt are decoded as follows: |
| 110 | /// \p Vmcnt = \p Waitcnt[3:0] |
| 111 | /// \p Expcnt = \p Waitcnt[6:4] |
| 112 | /// \p Lgkmcnt = \p Waitcnt[11:8] |
| 113 | void decodeWaitcnt(IsaVersion Version, unsigned Waitcnt, |
| 114 | unsigned &Vmcnt, unsigned &Expcnt, unsigned &Lgkmcnt); |
| 115 | |
| 116 | /// \returns \p Waitcnt with encoded \p Vmcnt for given isa \p Version. |
| 117 | unsigned encodeVmcnt(IsaVersion Version, unsigned Waitcnt, unsigned Vmcnt); |
| 118 | |
| 119 | /// \returns \p Waitcnt with encoded \p Expcnt for given isa \p Version. |
| 120 | unsigned encodeExpcnt(IsaVersion Version, unsigned Waitcnt, unsigned Expcnt); |
| 121 | |
| 122 | /// \returns \p Waitcnt with encoded \p Lgkmcnt for given isa \p Version. |
| 123 | unsigned encodeLgkmcnt(IsaVersion Version, unsigned Waitcnt, unsigned Lgkmcnt); |
| 124 | |
| 125 | /// \brief Encodes \p Vmcnt, \p Expcnt and \p Lgkmcnt into Waitcnt for given isa |
| 126 | /// \p Version. |
| 127 | /// |
| 128 | /// \details \p Vmcnt, \p Expcnt and \p Lgkmcnt are encoded as follows: |
| 129 | /// Waitcnt[3:0] = \p Vmcnt |
| 130 | /// Waitcnt[6:4] = \p Expcnt |
| 131 | /// Waitcnt[11:8] = \p Lgkmcnt |
| 132 | /// |
| 133 | /// \returns Waitcnt with encoded \p Vmcnt, \p Expcnt and \p Lgkmcnt for given |
| 134 | /// isa \p Version. |
| 135 | unsigned encodeWaitcnt(IsaVersion Version, |
| 136 | unsigned Vmcnt, unsigned Expcnt, unsigned Lgkmcnt); |
Konstantin Zhuravlyov | 836cbff | 2016-09-30 17:01:40 +0000 | [diff] [blame] | 137 | |
Marek Olsak | fccabaf | 2016-01-13 11:45:36 +0000 | [diff] [blame] | 138 | unsigned getInitialPSInputAddr(const Function &F); |
| 139 | |
Nicolai Haehnle | df3a20c | 2016-04-06 19:40:20 +0000 | [diff] [blame] | 140 | bool isShader(CallingConv::ID cc); |
| 141 | bool isCompute(CallingConv::ID cc); |
Tom Stellard | ac00eb5 | 2015-12-15 16:26:16 +0000 | [diff] [blame] | 142 | |
Tom Stellard | 2b65ed3 | 2015-12-21 18:44:27 +0000 | [diff] [blame] | 143 | bool isSI(const MCSubtargetInfo &STI); |
| 144 | bool isCI(const MCSubtargetInfo &STI); |
| 145 | bool isVI(const MCSubtargetInfo &STI); |
| 146 | |
| 147 | /// If \p Reg is a pseudo reg, return the correct hardware register given |
| 148 | /// \p STI otherwise return \p Reg. |
| 149 | unsigned getMCReg(unsigned Reg, const MCSubtargetInfo &STI); |
| 150 | |
Sam Kolton | 1eeb11b | 2016-09-09 14:44:04 +0000 | [diff] [blame] | 151 | /// \brief Can this operand also contain immediate values? |
| 152 | bool isSISrcOperand(const MCInstrDesc &Desc, unsigned OpNo); |
| 153 | |
| 154 | /// \brief Is this floating-point operand? |
| 155 | bool isSISrcFPOperand(const MCInstrDesc &Desc, unsigned OpNo); |
| 156 | |
| 157 | /// \brief Does this opearnd support only inlinable literals? |
| 158 | bool isSISrcInlinableOperand(const MCInstrDesc &Desc, unsigned OpNo); |
| 159 | |
Krzysztof Parzyszek | c871550 | 2016-10-19 17:40:36 +0000 | [diff] [blame] | 160 | /// \brief Get the size in bits of a register from the register class \p RC. |
Tom Stellard | b133fbb | 2016-10-27 23:05:31 +0000 | [diff] [blame] | 161 | unsigned getRegBitWidth(unsigned RCID); |
| 162 | |
| 163 | /// \brief Get the size in bits of a register from the register class \p RC. |
Krzysztof Parzyszek | c871550 | 2016-10-19 17:40:36 +0000 | [diff] [blame] | 164 | unsigned getRegBitWidth(const MCRegisterClass &RC); |
| 165 | |
Sam Kolton | 1eeb11b | 2016-09-09 14:44:04 +0000 | [diff] [blame] | 166 | /// \brief Get size of register operand |
| 167 | unsigned getRegOperandSize(const MCRegisterInfo *MRI, const MCInstrDesc &Desc, |
| 168 | unsigned OpNo); |
| 169 | |
| 170 | /// \brief Is this literal inlinable |
Matt Arsenault | 26faed3 | 2016-12-05 22:26:17 +0000 | [diff] [blame^] | 171 | LLVM_READNONE |
| 172 | bool isInlinableLiteral64(int64_t Literal, bool HasInv2Pi); |
| 173 | |
| 174 | LLVM_READNONE |
| 175 | bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi); |
| 176 | |
Sam Kolton | 1eeb11b | 2016-09-09 14:44:04 +0000 | [diff] [blame] | 177 | |
Tom Stellard | 347ac79 | 2015-06-26 21:15:07 +0000 | [diff] [blame] | 178 | } // end namespace AMDGPU |
| 179 | } // end namespace llvm |
| 180 | |
| 181 | #endif |