| Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 1 | //===-- AMDGPUSubtarget.cpp - AMDGPU Subtarget Information ----------------===// |
| 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 | /// \file |
| 11 | /// \brief Implements the AMDGPU specific subclass of TargetSubtarget. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "AMDGPUSubtarget.h" |
| Konstantin Zhuravlyov | e03b1d7 | 2017-02-08 13:02:33 +0000 | [diff] [blame] | 16 | #include "SIMachineFunctionInfo.h" |
| Matt Arsenault | d9a23ab | 2014-07-13 02:08:26 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/SmallString.h" |
| Tom Stellard | 83f0bce | 2015-01-29 16:55:25 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineScheduler.h" |
| Eugene Zelenko | 6a9226d | 2016-12-12 22:23:53 +0000 | [diff] [blame] | 19 | #include "llvm/Target/TargetFrameLowering.h" |
| 20 | #include <algorithm> |
| Matt Arsenault | d9a23ab | 2014-07-13 02:08:26 +0000 | [diff] [blame] | 21 | |
| Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 22 | using namespace llvm; |
| 23 | |
| Chandler Carruth | e96dd89 | 2014-04-21 22:55:11 +0000 | [diff] [blame] | 24 | #define DEBUG_TYPE "amdgpu-subtarget" |
| 25 | |
| Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 26 | #define GET_SUBTARGETINFO_ENUM |
| 27 | #define GET_SUBTARGETINFO_TARGET_DESC |
| 28 | #define GET_SUBTARGETINFO_CTOR |
| 29 | #include "AMDGPUGenSubtargetInfo.inc" |
| 30 | |
| Eugene Zelenko | 6a9226d | 2016-12-12 22:23:53 +0000 | [diff] [blame] | 31 | AMDGPUSubtarget::~AMDGPUSubtarget() = default; |
| Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 32 | |
| Eric Christopher | ac4b69e | 2014-07-25 22:22:39 +0000 | [diff] [blame] | 33 | AMDGPUSubtarget & |
| Daniel Sanders | a73f1fd | 2015-06-10 12:11:26 +0000 | [diff] [blame] | 34 | AMDGPUSubtarget::initializeSubtargetDependencies(const Triple &TT, |
| 35 | StringRef GPU, StringRef FS) { |
| Eric Christopher | ac4b69e | 2014-07-25 22:22:39 +0000 | [diff] [blame] | 36 | // Determine default and user-specified characteristics |
| Matt Arsenault | f171cf2 | 2014-07-14 23:40:49 +0000 | [diff] [blame] | 37 | // On SI+, we want FP64 denormals to be on by default. FP32 denormals can be |
| 38 | // enabled, but some instructions do not respect them and they run at the |
| 39 | // double precision rate, so don't enable by default. |
| 40 | // |
| 41 | // We want to be able to turn these off, but making this a subtarget feature |
| 42 | // for SI has the unhelpful behavior that it unsets everything else if you |
| 43 | // disable it. |
| Matt Arsenault | d9a23ab | 2014-07-13 02:08:26 +0000 | [diff] [blame] | 44 | |
| Matt Arsenault | 2fdf2a1 | 2017-02-21 23:35:48 +0000 | [diff] [blame] | 45 | SmallString<256> FullFS("+promote-alloca,+fp64-fp16-denormals,+dx10-clamp,+load-store-opt,"); |
| Changpeng Fang | b41574a | 2015-12-22 20:55:23 +0000 | [diff] [blame] | 46 | if (isAmdHsaOS()) // Turn on FlatForGlobal for HSA. |
| Wei Ding | 205bfdb | 2017-02-10 02:15:29 +0000 | [diff] [blame] | 47 | FullFS += "+flat-for-global,+unaligned-buffer-access,+trap-handler,"; |
| Matt Arsenault | a6867fd | 2017-01-23 22:31:03 +0000 | [diff] [blame] | 48 | |
| Matt Arsenault | d9a23ab | 2014-07-13 02:08:26 +0000 | [diff] [blame] | 49 | FullFS += FS; |
| 50 | |
| 51 | ParseSubtargetFeatures(GPU, FullFS); |
| Tom Stellard | 2e59a45 | 2014-06-13 01:32:00 +0000 | [diff] [blame] | 52 | |
| Matt Arsenault | d8f7ea3 | 2017-01-27 17:42:26 +0000 | [diff] [blame] | 53 | // Unless +-flat-for-global is specified, turn on FlatForGlobal for all OS-es |
| 54 | // on VI and newer hardware to avoid assertion failures due to missing ADDR64 |
| 55 | // variants of MUBUF instructions. |
| 56 | if (!hasAddr64() && !FS.contains("flat-for-global")) { |
| 57 | FlatForGlobal = true; |
| 58 | } |
| 59 | |
| Eric Christopher | ac4b69e | 2014-07-25 22:22:39 +0000 | [diff] [blame] | 60 | // FIXME: I don't think think Evergreen has any useful support for |
| 61 | // denormals, but should be checked. Should we issue a warning somewhere |
| 62 | // if someone tries to enable these? |
| Tom Stellard | 2e59a45 | 2014-06-13 01:32:00 +0000 | [diff] [blame] | 63 | if (getGeneration() <= AMDGPUSubtarget::NORTHERN_ISLANDS) { |
| Matt Arsenault | a6867fd | 2017-01-23 22:31:03 +0000 | [diff] [blame] | 64 | FP64FP16Denormals = false; |
| Matt Arsenault | f171cf2 | 2014-07-14 23:40:49 +0000 | [diff] [blame] | 65 | FP32Denormals = false; |
| Eric Christopher | ac4b69e | 2014-07-25 22:22:39 +0000 | [diff] [blame] | 66 | } |
| Matt Arsenault | 24ee078 | 2016-02-12 02:40:47 +0000 | [diff] [blame] | 67 | |
| 68 | // Set defaults if needed. |
| 69 | if (MaxPrivateElementSize == 0) |
| Matt Arsenault | e8ed8e5 | 2016-05-11 00:28:54 +0000 | [diff] [blame] | 70 | MaxPrivateElementSize = 4; |
| Matt Arsenault | 24ee078 | 2016-02-12 02:40:47 +0000 | [diff] [blame] | 71 | |
| Eric Christopher | ac4b69e | 2014-07-25 22:22:39 +0000 | [diff] [blame] | 72 | return *this; |
| 73 | } |
| 74 | |
| Daniel Sanders | a73f1fd | 2015-06-10 12:11:26 +0000 | [diff] [blame] | 75 | AMDGPUSubtarget::AMDGPUSubtarget(const Triple &TT, StringRef GPU, StringRef FS, |
| Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 76 | const TargetMachine &TM) |
| 77 | : AMDGPUGenSubtargetInfo(TT, GPU, FS), |
| 78 | TargetTriple(TT), |
| 79 | Gen(TT.getArch() == Triple::amdgcn ? SOUTHERN_ISLANDS : R600), |
| 80 | IsaVersion(ISAVersion0_0_0), |
| 81 | WavefrontSize(64), |
| 82 | LocalMemorySize(0), |
| 83 | LDSBankCount(0), |
| 84 | MaxPrivateElementSize(0), |
| Tom Stellard | 40ce8af | 2015-01-28 16:04:26 +0000 | [diff] [blame] | 85 | |
| Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 86 | FastFMAF32(false), |
| 87 | HalfRate64Ops(false), |
| 88 | |
| 89 | FP32Denormals(false), |
| Matt Arsenault | a6867fd | 2017-01-23 22:31:03 +0000 | [diff] [blame] | 90 | FP64FP16Denormals(false), |
| Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 91 | FPExceptions(false), |
| Matt Arsenault | 2fdf2a1 | 2017-02-21 23:35:48 +0000 | [diff] [blame] | 92 | DX10Clamp(false), |
| Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 93 | FlatForGlobal(false), |
| Tom Stellard | 64a9d08 | 2016-10-14 18:10:39 +0000 | [diff] [blame] | 94 | UnalignedScratchAccess(false), |
| Matt Arsenault | 7f681ac | 2016-07-01 23:03:44 +0000 | [diff] [blame] | 95 | UnalignedBufferAccess(false), |
| 96 | |
| Matt Arsenault | e823d92 | 2017-02-18 18:29:53 +0000 | [diff] [blame] | 97 | HasApertureRegs(false), |
| Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 98 | EnableXNACK(false), |
| Wei Ding | 205bfdb | 2017-02-10 02:15:29 +0000 | [diff] [blame] | 99 | TrapHandler(false), |
| Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 100 | DebuggerInsertNops(false), |
| 101 | DebuggerReserveRegs(false), |
| Konstantin Zhuravlyov | f2f3d14 | 2016-06-25 03:11:28 +0000 | [diff] [blame] | 102 | DebuggerEmitPrologue(false), |
| Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 103 | |
| 104 | EnableVGPRSpilling(false), |
| Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 105 | EnablePromoteAlloca(false), |
| Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 106 | EnableLoadStoreOpt(false), |
| 107 | EnableUnsafeDSOffsetFolding(false), |
| 108 | EnableSIScheduler(false), |
| 109 | DumpCode(false), |
| 110 | |
| 111 | FP64(false), |
| 112 | IsGCN(false), |
| 113 | GCN1Encoding(false), |
| 114 | GCN3Encoding(false), |
| 115 | CIInsts(false), |
| Matt Arsenault | 2021f08 | 2017-02-18 19:12:26 +0000 | [diff] [blame] | 116 | GFX9Insts(false), |
| Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 117 | SGPRInitBug(false), |
| 118 | HasSMemRealTime(false), |
| 119 | Has16BitInsts(false), |
| Matt Arsenault | cc88ce3 | 2016-10-12 18:00:51 +0000 | [diff] [blame] | 120 | HasMovrel(false), |
| 121 | HasVGPRIndexMode(false), |
| Matt Arsenault | c88ba36 | 2016-10-29 04:05:06 +0000 | [diff] [blame] | 122 | HasScalarStores(false), |
| Benjamin Kramer | 11590b8 | 2017-01-20 10:37:53 +0000 | [diff] [blame] | 123 | HasInv2PiInlineImm(false), |
| Sam Kolton | 07dbde2 | 2017-01-20 10:01:25 +0000 | [diff] [blame] | 124 | HasSDWA(false), |
| 125 | HasDPP(false), |
| Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 126 | FlatAddressSpace(false), |
| 127 | |
| 128 | R600ALUInst(false), |
| 129 | CaymanISA(false), |
| 130 | CFALUBug(false), |
| 131 | HasVertexCache(false), |
| 132 | TexVTXClauseSize(0), |
| Alexander Timofeev | 1800956 | 2016-12-08 17:28:47 +0000 | [diff] [blame] | 133 | ScalarizeGlobal(false), |
| Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 134 | |
| 135 | FeatureDisable(false), |
| Eugene Zelenko | 6a9226d | 2016-12-12 22:23:53 +0000 | [diff] [blame] | 136 | InstrItins(getInstrItineraryForCPU(GPU)) { |
| Tom Stellard | 40ce8af | 2015-01-28 16:04:26 +0000 | [diff] [blame] | 137 | initializeSubtargetDependencies(TT, GPU, FS); |
| Tom Stellard | a40f971 | 2014-01-22 21:55:43 +0000 | [diff] [blame] | 138 | } |
| Tom Stellard | b8fd6ef | 2014-12-02 22:00:07 +0000 | [diff] [blame] | 139 | |
| Stanislav Mekhanoshin | 2b913b1 | 2017-02-01 22:59:50 +0000 | [diff] [blame] | 140 | unsigned AMDGPUSubtarget::getMaxLocalMemSizeWithWaveCount(unsigned NWaves, |
| 141 | const Function &F) const { |
| 142 | if (NWaves == 1) |
| Matt Arsenault | 8a028bf | 2016-05-16 21:19:59 +0000 | [diff] [blame] | 143 | return getLocalMemorySize(); |
| Stanislav Mekhanoshin | 2b913b1 | 2017-02-01 22:59:50 +0000 | [diff] [blame] | 144 | unsigned WorkGroupSize = getFlatWorkGroupSizes(F).second; |
| 145 | unsigned WorkGroupsPerCu = getMaxWorkGroupsPerCU(WorkGroupSize); |
| 146 | unsigned MaxWaves = getMaxWavesPerEU(); |
| 147 | return getLocalMemorySize() * MaxWaves / WorkGroupsPerCu / NWaves; |
| Matt Arsenault | 8a028bf | 2016-05-16 21:19:59 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| Stanislav Mekhanoshin | 2b913b1 | 2017-02-01 22:59:50 +0000 | [diff] [blame] | 150 | unsigned AMDGPUSubtarget::getOccupancyWithLocalMemSize(uint32_t Bytes, |
| 151 | const Function &F) const { |
| 152 | unsigned WorkGroupSize = getFlatWorkGroupSizes(F).second; |
| 153 | unsigned WorkGroupsPerCu = getMaxWorkGroupsPerCU(WorkGroupSize); |
| 154 | unsigned MaxWaves = getMaxWavesPerEU(); |
| 155 | unsigned Limit = getLocalMemorySize() * MaxWaves / WorkGroupsPerCu; |
| 156 | unsigned NumWaves = Limit / (Bytes ? Bytes : 1u); |
| 157 | NumWaves = std::min(NumWaves, MaxWaves); |
| 158 | NumWaves = std::max(NumWaves, 1u); |
| 159 | return NumWaves; |
| Matt Arsenault | 8a028bf | 2016-05-16 21:19:59 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| Konstantin Zhuravlyov | 1d65026 | 2016-09-06 20:22:28 +0000 | [diff] [blame] | 162 | std::pair<unsigned, unsigned> AMDGPUSubtarget::getFlatWorkGroupSizes( |
| 163 | const Function &F) const { |
| Konstantin Zhuravlyov | 1d65026 | 2016-09-06 20:22:28 +0000 | [diff] [blame] | 164 | // Default minimum/maximum flat work group sizes. |
| 165 | std::pair<unsigned, unsigned> Default = |
| 166 | AMDGPU::isCompute(F.getCallingConv()) ? |
| 167 | std::pair<unsigned, unsigned>(getWavefrontSize() * 2, |
| 168 | getWavefrontSize() * 4) : |
| 169 | std::pair<unsigned, unsigned>(1, getWavefrontSize()); |
| 170 | |
| 171 | // TODO: Do not process "amdgpu-max-work-group-size" attribute once mesa |
| 172 | // starts using "amdgpu-flat-work-group-size" attribute. |
| 173 | Default.second = AMDGPU::getIntegerAttribute( |
| 174 | F, "amdgpu-max-work-group-size", Default.second); |
| 175 | Default.first = std::min(Default.first, Default.second); |
| 176 | |
| 177 | // Requested minimum/maximum flat work group sizes. |
| 178 | std::pair<unsigned, unsigned> Requested = AMDGPU::getIntegerPairAttribute( |
| 179 | F, "amdgpu-flat-work-group-size", Default); |
| 180 | |
| 181 | // Make sure requested minimum is less than requested maximum. |
| 182 | if (Requested.first > Requested.second) |
| 183 | return Default; |
| 184 | |
| 185 | // Make sure requested values do not violate subtarget's specifications. |
| 186 | if (Requested.first < getMinFlatWorkGroupSize()) |
| 187 | return Default; |
| 188 | if (Requested.second > getMaxFlatWorkGroupSize()) |
| 189 | return Default; |
| 190 | |
| 191 | return Requested; |
| 192 | } |
| 193 | |
| 194 | std::pair<unsigned, unsigned> AMDGPUSubtarget::getWavesPerEU( |
| 195 | const Function &F) const { |
| Konstantin Zhuravlyov | 1d65026 | 2016-09-06 20:22:28 +0000 | [diff] [blame] | 196 | // Default minimum/maximum number of waves per execution unit. |
| Konstantin Zhuravlyov | fd87137 | 2017-02-09 21:33:23 +0000 | [diff] [blame] | 197 | std::pair<unsigned, unsigned> Default(1, getMaxWavesPerEU()); |
| Konstantin Zhuravlyov | 1d65026 | 2016-09-06 20:22:28 +0000 | [diff] [blame] | 198 | |
| 199 | // Default/requested minimum/maximum flat work group sizes. |
| 200 | std::pair<unsigned, unsigned> FlatWorkGroupSizes = getFlatWorkGroupSizes(F); |
| 201 | |
| 202 | // If minimum/maximum flat work group sizes were explicitly requested using |
| 203 | // "amdgpu-flat-work-group-size" attribute, then set default minimum/maximum |
| 204 | // number of waves per execution unit to values implied by requested |
| 205 | // minimum/maximum flat work group sizes. |
| 206 | unsigned MinImpliedByFlatWorkGroupSize = |
| 207 | getMaxWavesPerEU(FlatWorkGroupSizes.second); |
| 208 | bool RequestedFlatWorkGroupSize = false; |
| 209 | |
| 210 | // TODO: Do not process "amdgpu-max-work-group-size" attribute once mesa |
| 211 | // starts using "amdgpu-flat-work-group-size" attribute. |
| 212 | if (F.hasFnAttribute("amdgpu-max-work-group-size") || |
| 213 | F.hasFnAttribute("amdgpu-flat-work-group-size")) { |
| 214 | Default.first = MinImpliedByFlatWorkGroupSize; |
| 215 | RequestedFlatWorkGroupSize = true; |
| 216 | } |
| 217 | |
| 218 | // Requested minimum/maximum number of waves per execution unit. |
| 219 | std::pair<unsigned, unsigned> Requested = AMDGPU::getIntegerPairAttribute( |
| 220 | F, "amdgpu-waves-per-eu", Default, true); |
| 221 | |
| 222 | // Make sure requested minimum is less than requested maximum. |
| 223 | if (Requested.second && Requested.first > Requested.second) |
| 224 | return Default; |
| 225 | |
| 226 | // Make sure requested values do not violate subtarget's specifications. |
| 227 | if (Requested.first < getMinWavesPerEU() || |
| 228 | Requested.first > getMaxWavesPerEU()) |
| 229 | return Default; |
| 230 | if (Requested.second > getMaxWavesPerEU()) |
| 231 | return Default; |
| 232 | |
| 233 | // Make sure requested values are compatible with values implied by requested |
| 234 | // minimum/maximum flat work group sizes. |
| 235 | if (RequestedFlatWorkGroupSize && |
| 236 | Requested.first > MinImpliedByFlatWorkGroupSize) |
| 237 | return Default; |
| 238 | |
| 239 | return Requested; |
| 240 | } |
| 241 | |
| Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 242 | R600Subtarget::R600Subtarget(const Triple &TT, StringRef GPU, StringRef FS, |
| 243 | const TargetMachine &TM) : |
| 244 | AMDGPUSubtarget(TT, GPU, FS, TM), |
| 245 | InstrInfo(*this), |
| 246 | FrameLowering(TargetFrameLowering::StackGrowsUp, getStackAlignment(), 0), |
| 247 | TLInfo(TM, *this) {} |
| 248 | |
| 249 | SISubtarget::SISubtarget(const Triple &TT, StringRef GPU, StringRef FS, |
| 250 | const TargetMachine &TM) : |
| 251 | AMDGPUSubtarget(TT, GPU, FS, TM), |
| 252 | InstrInfo(*this), |
| 253 | FrameLowering(TargetFrameLowering::StackGrowsUp, getStackAlignment(), 0), |
| Eugene Zelenko | 6a9226d | 2016-12-12 22:23:53 +0000 | [diff] [blame] | 254 | TLInfo(TM, *this) {} |
| Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 255 | |
| Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 256 | void SISubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy, |
| Matt Arsenault | 55dff27 | 2016-06-28 00:11:26 +0000 | [diff] [blame] | 257 | unsigned NumRegionInstrs) const { |
| Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 258 | // Track register pressure so the scheduler can try to decrease |
| 259 | // pressure once register usage is above the threshold defined by |
| 260 | // SIRegisterInfo::getRegPressureSetLimit() |
| 261 | Policy.ShouldTrackPressure = true; |
| Tom Stellard | 83f0bce | 2015-01-29 16:55:25 +0000 | [diff] [blame] | 262 | |
| Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 263 | // Enabling both top down and bottom up scheduling seems to give us less |
| 264 | // register spills than just using one of these approaches on its own. |
| 265 | Policy.OnlyTopDown = false; |
| 266 | Policy.OnlyBottomUp = false; |
| Tom Stellard | 83f0bce | 2015-01-29 16:55:25 +0000 | [diff] [blame] | 267 | |
| Alexander Timofeev | 9f61fea | 2017-02-14 14:29:05 +0000 | [diff] [blame] | 268 | // Enabling ShouldTrackLaneMasks crashes the SI Machine Scheduler. |
| 269 | if (!enableSIScheduler()) |
| 270 | Policy.ShouldTrackLaneMasks = true; |
| Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 271 | } |
| Tom Stellard | 0bc954e | 2016-03-30 16:35:09 +0000 | [diff] [blame] | 272 | |
| Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 273 | bool SISubtarget::isVGPRSpillingEnabled(const Function& F) const { |
| 274 | return EnableVGPRSpilling || !AMDGPU::isShader(F.getCallingConv()); |
| 275 | } |
| Tom Stellard | 0d23ebe | 2016-08-29 19:42:52 +0000 | [diff] [blame] | 276 | |
| Tom Stellard | 2f3f985 | 2017-01-25 01:25:13 +0000 | [diff] [blame] | 277 | unsigned SISubtarget::getKernArgSegmentSize(const MachineFunction &MF, |
| Konstantin Zhuravlyov | 27d64c3 | 2017-02-08 13:29:23 +0000 | [diff] [blame] | 278 | unsigned ExplicitArgBytes) const { |
| Tom Stellard | 2f3f985 | 2017-01-25 01:25:13 +0000 | [diff] [blame] | 279 | unsigned ImplicitBytes = getImplicitArgNumBytes(MF); |
| Tom Stellard | e88bbc3 | 2016-09-23 01:33:26 +0000 | [diff] [blame] | 280 | if (ImplicitBytes == 0) |
| 281 | return ExplicitArgBytes; |
| 282 | |
| 283 | unsigned Alignment = getAlignmentForImplicitArgPtr(); |
| 284 | return alignTo(ExplicitArgBytes, Alignment) + ImplicitBytes; |
| 285 | } |
| 286 | |
| Tom Stellard | 0d23ebe | 2016-08-29 19:42:52 +0000 | [diff] [blame] | 287 | unsigned SISubtarget::getOccupancyWithNumSGPRs(unsigned SGPRs) const { |
| 288 | if (getGeneration() >= SISubtarget::VOLCANIC_ISLANDS) { |
| 289 | if (SGPRs <= 80) |
| 290 | return 10; |
| 291 | if (SGPRs <= 88) |
| 292 | return 9; |
| 293 | if (SGPRs <= 100) |
| 294 | return 8; |
| 295 | return 7; |
| 296 | } |
| 297 | if (SGPRs <= 48) |
| 298 | return 10; |
| 299 | if (SGPRs <= 56) |
| 300 | return 9; |
| 301 | if (SGPRs <= 64) |
| 302 | return 8; |
| 303 | if (SGPRs <= 72) |
| 304 | return 7; |
| 305 | if (SGPRs <= 80) |
| 306 | return 6; |
| 307 | return 5; |
| 308 | } |
| 309 | |
| 310 | unsigned SISubtarget::getOccupancyWithNumVGPRs(unsigned VGPRs) const { |
| 311 | if (VGPRs <= 24) |
| 312 | return 10; |
| 313 | if (VGPRs <= 28) |
| 314 | return 9; |
| 315 | if (VGPRs <= 32) |
| 316 | return 8; |
| 317 | if (VGPRs <= 36) |
| 318 | return 7; |
| 319 | if (VGPRs <= 40) |
| 320 | return 6; |
| 321 | if (VGPRs <= 48) |
| 322 | return 5; |
| 323 | if (VGPRs <= 64) |
| 324 | return 4; |
| 325 | if (VGPRs <= 84) |
| 326 | return 3; |
| 327 | if (VGPRs <= 128) |
| 328 | return 2; |
| 329 | return 1; |
| 330 | } |
| Matt Arsenault | 4eae301 | 2016-10-28 20:31:47 +0000 | [diff] [blame] | 331 | |
| Konstantin Zhuravlyov | e03b1d7 | 2017-02-08 13:02:33 +0000 | [diff] [blame] | 332 | unsigned SISubtarget::getReservedNumSGPRs(const MachineFunction &MF) const { |
| 333 | const SIMachineFunctionInfo &MFI = *MF.getInfo<SIMachineFunctionInfo>(); |
| 334 | if (MFI.hasFlatScratchInit()) { |
| 335 | if (getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS) |
| 336 | return 6; // FLAT_SCRATCH, XNACK, VCC (in that order). |
| 337 | if (getGeneration() == AMDGPUSubtarget::SEA_ISLANDS) |
| 338 | return 4; // FLAT_SCRATCH, VCC (in that order). |
| 339 | } |
| 340 | |
| 341 | if (isXNACKEnabled()) |
| 342 | return 4; // XNACK, VCC (in that order). |
| 343 | return 2; // VCC. |
| 344 | } |
| 345 | |
| 346 | unsigned SISubtarget::getMaxNumSGPRs(const MachineFunction &MF) const { |
| 347 | const Function &F = *MF.getFunction(); |
| 348 | const SIMachineFunctionInfo &MFI = *MF.getInfo<SIMachineFunctionInfo>(); |
| 349 | |
| 350 | // Compute maximum number of SGPRs function can use using default/requested |
| 351 | // minimum number of waves per execution unit. |
| 352 | std::pair<unsigned, unsigned> WavesPerEU = MFI.getWavesPerEU(); |
| 353 | unsigned MaxNumSGPRs = getMaxNumSGPRs(WavesPerEU.first, false); |
| 354 | unsigned MaxAddressableNumSGPRs = getMaxNumSGPRs(WavesPerEU.first, true); |
| 355 | |
| 356 | // Check if maximum number of SGPRs was explicitly requested using |
| 357 | // "amdgpu-num-sgpr" attribute. |
| 358 | if (F.hasFnAttribute("amdgpu-num-sgpr")) { |
| 359 | unsigned Requested = AMDGPU::getIntegerAttribute( |
| 360 | F, "amdgpu-num-sgpr", MaxNumSGPRs); |
| 361 | |
| 362 | // Make sure requested value does not violate subtarget's specifications. |
| 363 | if (Requested && (Requested <= getReservedNumSGPRs(MF))) |
| 364 | Requested = 0; |
| 365 | |
| 366 | // If more SGPRs are required to support the input user/system SGPRs, |
| 367 | // increase to accommodate them. |
| 368 | // |
| 369 | // FIXME: This really ends up using the requested number of SGPRs + number |
| 370 | // of reserved special registers in total. Theoretically you could re-use |
| 371 | // the last input registers for these special registers, but this would |
| 372 | // require a lot of complexity to deal with the weird aliasing. |
| 373 | unsigned InputNumSGPRs = MFI.getNumPreloadedSGPRs(); |
| 374 | if (Requested && Requested < InputNumSGPRs) |
| 375 | Requested = InputNumSGPRs; |
| 376 | |
| 377 | // Make sure requested value is compatible with values implied by |
| 378 | // default/requested minimum/maximum number of waves per execution unit. |
| 379 | if (Requested && Requested > getMaxNumSGPRs(WavesPerEU.first, false)) |
| 380 | Requested = 0; |
| 381 | if (WavesPerEU.second && |
| 382 | Requested && Requested < getMinNumSGPRs(WavesPerEU.second)) |
| 383 | Requested = 0; |
| 384 | |
| 385 | if (Requested) |
| 386 | MaxNumSGPRs = Requested; |
| 387 | } |
| 388 | |
| Matt Arsenault | 4eae301 | 2016-10-28 20:31:47 +0000 | [diff] [blame] | 389 | if (hasSGPRInitBug()) |
| Konstantin Zhuravlyov | 9f89ede | 2017-02-08 14:05:23 +0000 | [diff] [blame] | 390 | MaxNumSGPRs = AMDGPU::IsaInfo::FIXED_NUM_SGPRS_FOR_INIT_BUG; |
| Matt Arsenault | 4eae301 | 2016-10-28 20:31:47 +0000 | [diff] [blame] | 391 | |
| Konstantin Zhuravlyov | e03b1d7 | 2017-02-08 13:02:33 +0000 | [diff] [blame] | 392 | return std::min(MaxNumSGPRs - getReservedNumSGPRs(MF), |
| 393 | MaxAddressableNumSGPRs); |
| 394 | } |
| Matt Arsenault | 4eae301 | 2016-10-28 20:31:47 +0000 | [diff] [blame] | 395 | |
| Konstantin Zhuravlyov | e03b1d7 | 2017-02-08 13:02:33 +0000 | [diff] [blame] | 396 | unsigned SISubtarget::getMaxNumVGPRs(const MachineFunction &MF) const { |
| 397 | const Function &F = *MF.getFunction(); |
| 398 | const SIMachineFunctionInfo &MFI = *MF.getInfo<SIMachineFunctionInfo>(); |
| 399 | |
| 400 | // Compute maximum number of VGPRs function can use using default/requested |
| 401 | // minimum number of waves per execution unit. |
| 402 | std::pair<unsigned, unsigned> WavesPerEU = MFI.getWavesPerEU(); |
| 403 | unsigned MaxNumVGPRs = getMaxNumVGPRs(WavesPerEU.first); |
| 404 | |
| 405 | // Check if maximum number of VGPRs was explicitly requested using |
| 406 | // "amdgpu-num-vgpr" attribute. |
| 407 | if (F.hasFnAttribute("amdgpu-num-vgpr")) { |
| 408 | unsigned Requested = AMDGPU::getIntegerAttribute( |
| 409 | F, "amdgpu-num-vgpr", MaxNumVGPRs); |
| 410 | |
| 411 | // Make sure requested value does not violate subtarget's specifications. |
| 412 | if (Requested && Requested <= getReservedNumVGPRs(MF)) |
| 413 | Requested = 0; |
| 414 | |
| 415 | // Make sure requested value is compatible with values implied by |
| 416 | // default/requested minimum/maximum number of waves per execution unit. |
| 417 | if (Requested && Requested > getMaxNumVGPRs(WavesPerEU.first)) |
| 418 | Requested = 0; |
| 419 | if (WavesPerEU.second && |
| 420 | Requested && Requested < getMinNumVGPRs(WavesPerEU.second)) |
| 421 | Requested = 0; |
| 422 | |
| 423 | if (Requested) |
| 424 | MaxNumVGPRs = Requested; |
| 425 | } |
| 426 | |
| 427 | return MaxNumVGPRs - getReservedNumVGPRs(MF); |
| Matt Arsenault | 4eae301 | 2016-10-28 20:31:47 +0000 | [diff] [blame] | 428 | } |