Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 1 | //===-- AMDGPUSubtarget.cpp - AMDGPU Subtarget Information ----------------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | /// \file |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 10 | /// Implements the AMDGPU specific subclass of TargetSubtarget. |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "AMDGPUSubtarget.h" |
Quentin Colombet | f3f7d4d | 2017-07-05 18:40:56 +0000 | [diff] [blame] | 15 | #include "AMDGPU.h" |
| 16 | #include "AMDGPUTargetMachine.h" |
Quentin Colombet | f3f7d4d | 2017-07-05 18:40:56 +0000 | [diff] [blame] | 17 | #include "AMDGPUCallLowering.h" |
| 18 | #include "AMDGPUInstructionSelector.h" |
| 19 | #include "AMDGPULegalizerInfo.h" |
| 20 | #include "AMDGPURegisterBankInfo.h" |
Konstantin Zhuravlyov | e03b1d7 | 2017-02-08 13:02:33 +0000 | [diff] [blame] | 21 | #include "SIMachineFunctionInfo.h" |
Tom Stellard | 44b30b4 | 2018-05-22 02:03:23 +0000 | [diff] [blame] | 22 | #include "MCTargetDesc/AMDGPUMCTargetDesc.h" |
Matt Arsenault | d9a23ab | 2014-07-13 02:08:26 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/SmallString.h" |
Tom Stellard | 83f0bce | 2015-01-29 16:55:25 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/MachineScheduler.h" |
Tom Stellard | c5a154d | 2018-06-28 23:47:12 +0000 | [diff] [blame] | 25 | #include "llvm/MC/MCSubtargetInfo.h" |
Stanislav Mekhanoshin | c90347d | 2017-04-12 20:48:56 +0000 | [diff] [blame] | 26 | #include "llvm/IR/MDBuilder.h" |
David Blaikie | 1be62f0 | 2017-11-03 22:32:11 +0000 | [diff] [blame] | 27 | #include "llvm/CodeGen/TargetFrameLowering.h" |
Eugene Zelenko | 6a9226d | 2016-12-12 22:23:53 +0000 | [diff] [blame] | 28 | #include <algorithm> |
Matt Arsenault | d9a23ab | 2014-07-13 02:08:26 +0000 | [diff] [blame] | 29 | |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 30 | using namespace llvm; |
| 31 | |
Chandler Carruth | e96dd89 | 2014-04-21 22:55:11 +0000 | [diff] [blame] | 32 | #define DEBUG_TYPE "amdgpu-subtarget" |
| 33 | |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 34 | #define GET_SUBTARGETINFO_TARGET_DESC |
| 35 | #define GET_SUBTARGETINFO_CTOR |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 36 | #define AMDGPUSubtarget GCNSubtarget |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 37 | #include "AMDGPUGenSubtargetInfo.inc" |
Tom Stellard | c5a154d | 2018-06-28 23:47:12 +0000 | [diff] [blame] | 38 | #define GET_SUBTARGETINFO_TARGET_DESC |
| 39 | #define GET_SUBTARGETINFO_CTOR |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 40 | #undef AMDGPUSubtarget |
Tom Stellard | c5a154d | 2018-06-28 23:47:12 +0000 | [diff] [blame] | 41 | #include "R600GenSubtargetInfo.inc" |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 42 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 43 | GCNSubtarget::~GCNSubtarget() = default; |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 44 | |
Tom Stellard | c5a154d | 2018-06-28 23:47:12 +0000 | [diff] [blame] | 45 | R600Subtarget & |
| 46 | R600Subtarget::initializeSubtargetDependencies(const Triple &TT, |
| 47 | StringRef GPU, StringRef FS) { |
Matt Arsenault | 055e4dc | 2019-03-29 19:14:54 +0000 | [diff] [blame] | 48 | SmallString<256> FullFS("+promote-alloca,"); |
Tom Stellard | c5a154d | 2018-06-28 23:47:12 +0000 | [diff] [blame] | 49 | FullFS += FS; |
| 50 | ParseSubtargetFeatures(GPU, FullFS); |
| 51 | |
| 52 | // FIXME: I don't think think Evergreen has any useful support for |
| 53 | // denormals, but should be checked. Should we issue a warning somewhere |
| 54 | // if someone tries to enable these? |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 55 | if (getGeneration() <= AMDGPUSubtarget::NORTHERN_ISLANDS) { |
Tom Stellard | c5a154d | 2018-06-28 23:47:12 +0000 | [diff] [blame] | 56 | FP32Denormals = false; |
| 57 | } |
| 58 | |
| 59 | HasMulU24 = getGeneration() >= EVERGREEN; |
| 60 | HasMulI24 = hasCaymanISA(); |
| 61 | |
| 62 | return *this; |
| 63 | } |
| 64 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 65 | GCNSubtarget & |
| 66 | GCNSubtarget::initializeSubtargetDependencies(const Triple &TT, |
Matt Arsenault | f426ddb | 2019-04-03 01:58:57 +0000 | [diff] [blame] | 67 | StringRef GPU, StringRef FS) { |
Eric Christopher | ac4b69e | 2014-07-25 22:22:39 +0000 | [diff] [blame] | 68 | // Determine default and user-specified characteristics |
Matt Arsenault | f171cf2 | 2014-07-14 23:40:49 +0000 | [diff] [blame] | 69 | // On SI+, we want FP64 denormals to be on by default. FP32 denormals can be |
| 70 | // enabled, but some instructions do not respect them and they run at the |
| 71 | // double precision rate, so don't enable by default. |
| 72 | // |
| 73 | // We want to be able to turn these off, but making this a subtarget feature |
| 74 | // for SI has the unhelpful behavior that it unsets everything else if you |
| 75 | // disable it. |
David Stuttard | f77079f | 2019-01-14 11:55:24 +0000 | [diff] [blame] | 76 | // |
| 77 | // Similarly we want enable-prt-strict-null to be on by default and not to |
| 78 | // unset everything else if it is disabled |
Matt Arsenault | d9a23ab | 2014-07-13 02:08:26 +0000 | [diff] [blame] | 79 | |
Matt Arsenault | f426ddb | 2019-04-03 01:58:57 +0000 | [diff] [blame] | 80 | // Assuming ECC is enabled is the conservative default. |
Matt Arsenault | df24c92 | 2019-05-16 14:48:34 +0000 | [diff] [blame] | 81 | SmallString<256> FullFS("+promote-alloca,+load-store-opt,+sram-ecc,+xnack,"); |
Jan Vesely | d1c9b61 | 2017-12-04 22:57:29 +0000 | [diff] [blame] | 82 | |
Changpeng Fang | b41574a | 2015-12-22 20:55:23 +0000 | [diff] [blame] | 83 | if (isAmdHsaOS()) // Turn on FlatForGlobal for HSA. |
Matt Arsenault | e0c1f9e | 2019-03-17 21:31:35 +0000 | [diff] [blame] | 84 | FullFS += "+flat-for-global,+unaligned-buffer-access,+trap-handler,"; |
Matt Arsenault | a6867fd | 2017-01-23 22:31:03 +0000 | [diff] [blame] | 85 | |
Jan Vesely | d1c9b61 | 2017-12-04 22:57:29 +0000 | [diff] [blame] | 86 | // FIXME: I don't think think Evergreen has any useful support for |
| 87 | // denormals, but should be checked. Should we issue a warning somewhere |
| 88 | // if someone tries to enable these? |
| 89 | if (getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS) { |
| 90 | FullFS += "+fp64-fp16-denormals,"; |
| 91 | } else { |
| 92 | FullFS += "-fp32-denormals,"; |
| 93 | } |
| 94 | |
David Stuttard | f77079f | 2019-01-14 11:55:24 +0000 | [diff] [blame] | 95 | FullFS += "+enable-prt-strict-null,"; // This is overridden by a disable in FS |
| 96 | |
Stanislav Mekhanoshin | 8bcc9bb | 2019-06-13 19:18:29 +0000 | [diff] [blame] | 97 | // Disable mutually exclusive bits. |
| 98 | if (FS.find_lower("+wavefrontsize") != StringRef::npos) { |
| 99 | if (FS.find_lower("wavefrontsize16") == StringRef::npos) |
| 100 | FullFS += "-wavefrontsize16,"; |
| 101 | if (FS.find_lower("wavefrontsize32") == StringRef::npos) |
| 102 | FullFS += "-wavefrontsize32,"; |
| 103 | if (FS.find_lower("wavefrontsize64") == StringRef::npos) |
| 104 | FullFS += "-wavefrontsize64,"; |
| 105 | } |
| 106 | |
Matt Arsenault | d9a23ab | 2014-07-13 02:08:26 +0000 | [diff] [blame] | 107 | FullFS += FS; |
| 108 | |
| 109 | ParseSubtargetFeatures(GPU, FullFS); |
Tom Stellard | 2e59a45 | 2014-06-13 01:32:00 +0000 | [diff] [blame] | 110 | |
Jan Vesely | d1c9b61 | 2017-12-04 22:57:29 +0000 | [diff] [blame] | 111 | // We don't support FP64 for EG/NI atm. |
| 112 | assert(!hasFP64() || (getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS)); |
| 113 | |
Matt Arsenault | d8f7ea3 | 2017-01-27 17:42:26 +0000 | [diff] [blame] | 114 | // Unless +-flat-for-global is specified, turn on FlatForGlobal for all OS-es |
| 115 | // on VI and newer hardware to avoid assertion failures due to missing ADDR64 |
| 116 | // variants of MUBUF instructions. |
| 117 | if (!hasAddr64() && !FS.contains("flat-for-global")) { |
| 118 | FlatForGlobal = true; |
| 119 | } |
| 120 | |
Matt Arsenault | 24ee078 | 2016-02-12 02:40:47 +0000 | [diff] [blame] | 121 | // Set defaults if needed. |
| 122 | if (MaxPrivateElementSize == 0) |
Matt Arsenault | e8ed8e5 | 2016-05-11 00:28:54 +0000 | [diff] [blame] | 123 | MaxPrivateElementSize = 4; |
Matt Arsenault | 24ee078 | 2016-02-12 02:40:47 +0000 | [diff] [blame] | 124 | |
Matt Arsenault | 8728c5f | 2017-08-07 14:58:04 +0000 | [diff] [blame] | 125 | if (LDSBankCount == 0) |
| 126 | LDSBankCount = 32; |
| 127 | |
| 128 | if (TT.getArch() == Triple::amdgcn) { |
| 129 | if (LocalMemorySize == 0) |
| 130 | LocalMemorySize = 32768; |
| 131 | |
| 132 | // Do something sensible for unspecified target. |
| 133 | if (!HasMovrel && !HasVGPRIndexMode) |
| 134 | HasMovrel = true; |
| 135 | } |
| 136 | |
Matt Arsenault | d704727 | 2019-02-08 19:18:01 +0000 | [diff] [blame] | 137 | // Don't crash on invalid devices. |
| 138 | if (WavefrontSize == 0) |
| 139 | WavefrontSize = 64; |
| 140 | |
Tom Stellard | c5a154d | 2018-06-28 23:47:12 +0000 | [diff] [blame] | 141 | HasFminFmaxLegacy = getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS; |
| 142 | |
Matt Arsenault | df24c92 | 2019-05-16 14:48:34 +0000 | [diff] [blame] | 143 | if (DoesNotSupportXNACK && EnableXNACK) { |
| 144 | ToggleFeature(AMDGPU::FeatureXNACK); |
| 145 | EnableXNACK = false; |
| 146 | } |
| 147 | |
Matt Arsenault | f426ddb | 2019-04-03 01:58:57 +0000 | [diff] [blame] | 148 | // ECC is on by default, but turn it off if the hardware doesn't support it |
| 149 | // anyway. This matters for the gfx9 targets with d16 loads, but don't support |
| 150 | // ECC. |
| 151 | if (DoesNotSupportSRAMECC && EnableSRAMECC) { |
| 152 | ToggleFeature(AMDGPU::FeatureSRAMECC); |
| 153 | EnableSRAMECC = false; |
| 154 | } |
| 155 | |
Eric Christopher | ac4b69e | 2014-07-25 22:22:39 +0000 | [diff] [blame] | 156 | return *this; |
| 157 | } |
| 158 | |
Konstantin Zhuravlyov | 71e43ee | 2018-09-12 18:50:47 +0000 | [diff] [blame] | 159 | AMDGPUSubtarget::AMDGPUSubtarget(const Triple &TT) : |
Tom Stellard | c5a154d | 2018-06-28 23:47:12 +0000 | [diff] [blame] | 160 | TargetTriple(TT), |
Tom Stellard | c5a154d | 2018-06-28 23:47:12 +0000 | [diff] [blame] | 161 | Has16BitInsts(false), |
| 162 | HasMadMixInsts(false), |
| 163 | FP32Denormals(false), |
| 164 | FPExceptions(false), |
| 165 | HasSDWA(false), |
| 166 | HasVOP3PInsts(false), |
| 167 | HasMulI24(true), |
| 168 | HasMulU24(true), |
Matt Arsenault | 6c7ba82 | 2018-08-15 21:03:55 +0000 | [diff] [blame] | 169 | HasInv2PiInlineImm(false), |
Tom Stellard | c5a154d | 2018-06-28 23:47:12 +0000 | [diff] [blame] | 170 | HasFminFmaxLegacy(true), |
| 171 | EnablePromoteAlloca(false), |
David Stuttard | 20de3e9 | 2018-09-14 10:27:19 +0000 | [diff] [blame] | 172 | HasTrigReducedRange(false), |
Tom Stellard | c5a154d | 2018-06-28 23:47:12 +0000 | [diff] [blame] | 173 | LocalMemorySize(0), |
| 174 | WavefrontSize(0) |
| 175 | { } |
| 176 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 177 | GCNSubtarget::GCNSubtarget(const Triple &TT, StringRef GPU, StringRef FS, |
Konstantin Zhuravlyov | 71e43ee | 2018-09-12 18:50:47 +0000 | [diff] [blame] | 178 | const GCNTargetMachine &TM) : |
Tom Stellard | c5a154d | 2018-06-28 23:47:12 +0000 | [diff] [blame] | 179 | AMDGPUGenSubtargetInfo(TT, GPU, FS), |
Konstantin Zhuravlyov | 71e43ee | 2018-09-12 18:50:47 +0000 | [diff] [blame] | 180 | AMDGPUSubtarget(TT), |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 181 | TargetTriple(TT), |
Matt Arsenault | e0c1f9e | 2019-03-17 21:31:35 +0000 | [diff] [blame] | 182 | Gen(TT.getOS() == Triple::AMDHSA ? SEA_ISLANDS : SOUTHERN_ISLANDS), |
Stanislav Mekhanoshin | 06d3b41 | 2018-09-17 16:04:32 +0000 | [diff] [blame] | 183 | InstrItins(getInstrItineraryForCPU(GPU)), |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 184 | LDSBankCount(0), |
| 185 | MaxPrivateElementSize(0), |
Tom Stellard | 40ce8af | 2015-01-28 16:04:26 +0000 | [diff] [blame] | 186 | |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 187 | FastFMAF32(false), |
| 188 | HalfRate64Ops(false), |
| 189 | |
Matt Arsenault | a6867fd | 2017-01-23 22:31:03 +0000 | [diff] [blame] | 190 | FP64FP16Denormals(false), |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 191 | FlatForGlobal(false), |
Konstantin Zhuravlyov | be6c0ca | 2017-06-02 17:40:26 +0000 | [diff] [blame] | 192 | AutoWaitcntBeforeBarrier(false), |
Konstantin Zhuravlyov | eda425e | 2017-10-14 15:59:07 +0000 | [diff] [blame] | 193 | CodeObjectV3(false), |
Tom Stellard | 64a9d08 | 2016-10-14 18:10:39 +0000 | [diff] [blame] | 194 | UnalignedScratchAccess(false), |
Matt Arsenault | 7f681ac | 2016-07-01 23:03:44 +0000 | [diff] [blame] | 195 | UnalignedBufferAccess(false), |
| 196 | |
Matt Arsenault | e823d92 | 2017-02-18 18:29:53 +0000 | [diff] [blame] | 197 | HasApertureRegs(false), |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 198 | EnableXNACK(false), |
Matt Arsenault | df24c92 | 2019-05-16 14:48:34 +0000 | [diff] [blame] | 199 | DoesNotSupportXNACK(false), |
Stanislav Mekhanoshin | cee607e | 2019-04-24 17:03:15 +0000 | [diff] [blame] | 200 | EnableCuMode(false), |
Wei Ding | 205bfdb | 2017-02-10 02:15:29 +0000 | [diff] [blame] | 201 | TrapHandler(false), |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 202 | |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 203 | EnableLoadStoreOpt(false), |
| 204 | EnableUnsafeDSOffsetFolding(false), |
| 205 | EnableSIScheduler(false), |
Marek Olsak | a9a58fa | 2018-04-10 22:48:23 +0000 | [diff] [blame] | 206 | EnableDS128(false), |
David Stuttard | f77079f | 2019-01-14 11:55:24 +0000 | [diff] [blame] | 207 | EnablePRTStrictNull(false), |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 208 | DumpCode(false), |
| 209 | |
| 210 | FP64(false), |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 211 | GCN3Encoding(false), |
| 212 | CIInsts(false), |
Stanislav Mekhanoshin | 7895c03 | 2019-04-05 18:24:34 +0000 | [diff] [blame] | 213 | GFX8Insts(false), |
Matt Arsenault | 2021f08 | 2017-02-18 19:12:26 +0000 | [diff] [blame] | 214 | GFX9Insts(false), |
Stanislav Mekhanoshin | cee607e | 2019-04-24 17:03:15 +0000 | [diff] [blame] | 215 | GFX10Insts(false), |
Stanislav Mekhanoshin | 7895c03 | 2019-04-05 18:24:34 +0000 | [diff] [blame] | 216 | GFX7GFX8GFX9Insts(false), |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 217 | SGPRInitBug(false), |
| 218 | HasSMemRealTime(false), |
Dmitry Preobrazhensky | ff64aa5 | 2017-08-16 13:51:56 +0000 | [diff] [blame] | 219 | HasIntClamp(false), |
Matt Arsenault | 0084adc | 2018-04-30 19:08:16 +0000 | [diff] [blame] | 220 | HasFmaMixInsts(false), |
Matt Arsenault | cc88ce3 | 2016-10-12 18:00:51 +0000 | [diff] [blame] | 221 | HasMovrel(false), |
| 222 | HasVGPRIndexMode(false), |
Matt Arsenault | c88ba36 | 2016-10-29 04:05:06 +0000 | [diff] [blame] | 223 | HasScalarStores(false), |
Dmitry Preobrazhensky | 6bad04e | 2018-04-02 16:10:25 +0000 | [diff] [blame] | 224 | HasScalarAtomics(false), |
Sam Kolton | 3c4933f | 2017-06-22 06:26:41 +0000 | [diff] [blame] | 225 | HasSDWAOmod(false), |
| 226 | HasSDWAScalar(false), |
| 227 | HasSDWASdst(false), |
| 228 | HasSDWAMac(false), |
Sam Kolton | a179d25 | 2017-06-27 15:02:23 +0000 | [diff] [blame] | 229 | HasSDWAOutModsVOPC(false), |
Sam Kolton | 07dbde2 | 2017-01-20 10:01:25 +0000 | [diff] [blame] | 230 | HasDPP(false), |
Stanislav Mekhanoshin | 245b5ba | 2019-06-12 18:02:41 +0000 | [diff] [blame] | 231 | HasDPP8(false), |
Ryan Taylor | 1f334d0 | 2018-08-28 15:07:30 +0000 | [diff] [blame] | 232 | HasR128A16(false), |
Stanislav Mekhanoshin | cee607e | 2019-04-24 17:03:15 +0000 | [diff] [blame] | 233 | HasNSAEncoding(false), |
Matt Arsenault | 0084adc | 2018-04-30 19:08:16 +0000 | [diff] [blame] | 234 | HasDLInsts(false), |
Stanislav Mekhanoshin | 0e858b0 | 2019-02-09 00:34:21 +0000 | [diff] [blame] | 235 | HasDot1Insts(false), |
| 236 | HasDot2Insts(false), |
Stanislav Mekhanoshin | c43e67b | 2019-06-14 00:33:31 +0000 | [diff] [blame^] | 237 | HasDot5Insts(false), |
| 238 | HasDot6Insts(false), |
Konstantin Zhuravlyov | 108927b | 2018-11-05 22:44:19 +0000 | [diff] [blame] | 239 | EnableSRAMECC(false), |
Matt Arsenault | f426ddb | 2019-04-03 01:58:57 +0000 | [diff] [blame] | 240 | DoesNotSupportSRAMECC(false), |
Stanislav Mekhanoshin | cee607e | 2019-04-24 17:03:15 +0000 | [diff] [blame] | 241 | HasNoSdstCMPX(false), |
| 242 | HasVscnt(false), |
| 243 | HasRegisterBanking(false), |
| 244 | HasVOP3Literal(false), |
| 245 | HasNoDataDepHazard(false), |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 246 | FlatAddressSpace(false), |
Matt Arsenault | acdc765 | 2017-05-10 21:19:05 +0000 | [diff] [blame] | 247 | FlatInstOffsets(false), |
| 248 | FlatGlobalInsts(false), |
| 249 | FlatScratchInsts(false), |
Stanislav Mekhanoshin | cee607e | 2019-04-24 17:03:15 +0000 | [diff] [blame] | 250 | ScalarFlatScratchInsts(false), |
Matt Arsenault | c37fe66 | 2017-07-20 17:42:47 +0000 | [diff] [blame] | 251 | AddNoCarryInsts(false), |
Changpeng Fang | 44dfa1d | 2018-01-12 21:12:19 +0000 | [diff] [blame] | 252 | HasUnpackedD16VMem(false), |
Stanislav Mekhanoshin | cee607e | 2019-04-24 17:03:15 +0000 | [diff] [blame] | 253 | LDSMisalignedBug(false), |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 254 | |
Alexander Timofeev | 1800956 | 2016-12-08 17:28:47 +0000 | [diff] [blame] | 255 | ScalarizeGlobal(false), |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 256 | |
Stanislav Mekhanoshin | cee607e | 2019-04-24 17:03:15 +0000 | [diff] [blame] | 257 | HasVcmpxPermlaneHazard(false), |
| 258 | HasVMEMtoScalarWriteHazard(false), |
| 259 | HasSMEMtoVectorWriteHazard(false), |
| 260 | HasInstFwdPrefetchBug(false), |
| 261 | HasVcmpxExecWARHazard(false), |
| 262 | HasLdsBranchVmemWARHazard(false), |
| 263 | HasNSAtoVMEMBug(false), |
| 264 | HasFlatSegmentOffsetBug(false), |
| 265 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 266 | FeatureDisable(false), |
Tom Stellard | 752ddbd | 2018-07-11 22:15:15 +0000 | [diff] [blame] | 267 | InstrInfo(initializeSubtargetDependencies(TT, GPU, FS)), |
Matt Arsenault | 4bec7d4 | 2018-07-20 09:05:08 +0000 | [diff] [blame] | 268 | TLInfo(TM, *this), |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 269 | FrameLowering(TargetFrameLowering::StackGrowsUp, getStackAlignment(), 0) { |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 270 | CallLoweringInfo.reset(new AMDGPUCallLowering(*getTargetLowering())); |
| 271 | Legalizer.reset(new AMDGPULegalizerInfo(*this, TM)); |
| 272 | RegBankInfo.reset(new AMDGPURegisterBankInfo(*getRegisterInfo())); |
| 273 | InstSelector.reset(new AMDGPUInstructionSelector( |
| 274 | *this, *static_cast<AMDGPURegisterBankInfo *>(RegBankInfo.get()), TM)); |
Tom Stellard | a40f971 | 2014-01-22 21:55:43 +0000 | [diff] [blame] | 275 | } |
Tom Stellard | b8fd6ef | 2014-12-02 22:00:07 +0000 | [diff] [blame] | 276 | |
Stanislav Mekhanoshin | f2baae0 | 2019-05-02 03:47:23 +0000 | [diff] [blame] | 277 | unsigned GCNSubtarget::getConstantBusLimit(unsigned Opcode) const { |
| 278 | if (getGeneration() < GFX10) |
| 279 | return 1; |
| 280 | |
| 281 | switch (Opcode) { |
| 282 | case AMDGPU::V_LSHLREV_B64: |
| 283 | case AMDGPU::V_LSHLREV_B64_gfx10: |
| 284 | case AMDGPU::V_LSHL_B64: |
| 285 | case AMDGPU::V_LSHRREV_B64: |
| 286 | case AMDGPU::V_LSHRREV_B64_gfx10: |
| 287 | case AMDGPU::V_LSHR_B64: |
| 288 | case AMDGPU::V_ASHRREV_I64: |
| 289 | case AMDGPU::V_ASHRREV_I64_gfx10: |
| 290 | case AMDGPU::V_ASHR_I64: |
| 291 | return 1; |
| 292 | } |
| 293 | |
| 294 | return 2; |
| 295 | } |
| 296 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 297 | unsigned AMDGPUSubtarget::getMaxLocalMemSizeWithWaveCount(unsigned NWaves, |
Stanislav Mekhanoshin | 2b913b1 | 2017-02-01 22:59:50 +0000 | [diff] [blame] | 298 | const Function &F) const { |
| 299 | if (NWaves == 1) |
Matt Arsenault | 8a028bf | 2016-05-16 21:19:59 +0000 | [diff] [blame] | 300 | return getLocalMemorySize(); |
Stanislav Mekhanoshin | 2b913b1 | 2017-02-01 22:59:50 +0000 | [diff] [blame] | 301 | unsigned WorkGroupSize = getFlatWorkGroupSizes(F).second; |
| 302 | unsigned WorkGroupsPerCu = getMaxWorkGroupsPerCU(WorkGroupSize); |
Stanislav Mekhanoshin | cee607e | 2019-04-24 17:03:15 +0000 | [diff] [blame] | 303 | if (!WorkGroupsPerCu) |
| 304 | return 0; |
Stanislav Mekhanoshin | 2b913b1 | 2017-02-01 22:59:50 +0000 | [diff] [blame] | 305 | unsigned MaxWaves = getMaxWavesPerEU(); |
| 306 | return getLocalMemorySize() * MaxWaves / WorkGroupsPerCu / NWaves; |
Matt Arsenault | 8a028bf | 2016-05-16 21:19:59 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 309 | unsigned AMDGPUSubtarget::getOccupancyWithLocalMemSize(uint32_t Bytes, |
Stanislav Mekhanoshin | 2b913b1 | 2017-02-01 22:59:50 +0000 | [diff] [blame] | 310 | const Function &F) const { |
| 311 | unsigned WorkGroupSize = getFlatWorkGroupSizes(F).second; |
| 312 | unsigned WorkGroupsPerCu = getMaxWorkGroupsPerCU(WorkGroupSize); |
Stanislav Mekhanoshin | cee607e | 2019-04-24 17:03:15 +0000 | [diff] [blame] | 313 | if (!WorkGroupsPerCu) |
| 314 | return 0; |
Stanislav Mekhanoshin | 2b913b1 | 2017-02-01 22:59:50 +0000 | [diff] [blame] | 315 | unsigned MaxWaves = getMaxWavesPerEU(); |
| 316 | unsigned Limit = getLocalMemorySize() * MaxWaves / WorkGroupsPerCu; |
| 317 | unsigned NumWaves = Limit / (Bytes ? Bytes : 1u); |
| 318 | NumWaves = std::min(NumWaves, MaxWaves); |
| 319 | NumWaves = std::max(NumWaves, 1u); |
| 320 | return NumWaves; |
Matt Arsenault | 8a028bf | 2016-05-16 21:19:59 +0000 | [diff] [blame] | 321 | } |
| 322 | |
Tom Stellard | 44b30b4 | 2018-05-22 02:03:23 +0000 | [diff] [blame] | 323 | unsigned |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 324 | AMDGPUSubtarget::getOccupancyWithLocalMemSize(const MachineFunction &MF) const { |
Tom Stellard | 44b30b4 | 2018-05-22 02:03:23 +0000 | [diff] [blame] | 325 | const auto *MFI = MF.getInfo<SIMachineFunctionInfo>(); |
| 326 | return getOccupancyWithLocalMemSize(MFI->getLDSSize(), MF.getFunction()); |
| 327 | } |
| 328 | |
Matt Arsenault | b791802 | 2017-10-23 17:09:35 +0000 | [diff] [blame] | 329 | std::pair<unsigned, unsigned> |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 330 | AMDGPUSubtarget::getDefaultFlatWorkGroupSize(CallingConv::ID CC) const { |
Matt Arsenault | b791802 | 2017-10-23 17:09:35 +0000 | [diff] [blame] | 331 | switch (CC) { |
| 332 | case CallingConv::AMDGPU_CS: |
| 333 | case CallingConv::AMDGPU_KERNEL: |
| 334 | case CallingConv::SPIR_KERNEL: |
Stanislav Mekhanoshin | cee607e | 2019-04-24 17:03:15 +0000 | [diff] [blame] | 335 | return std::make_pair(getWavefrontSize() * 2, |
| 336 | std::max(getWavefrontSize() * 4, 256u)); |
Matt Arsenault | b791802 | 2017-10-23 17:09:35 +0000 | [diff] [blame] | 337 | case CallingConv::AMDGPU_VS: |
| 338 | case CallingConv::AMDGPU_LS: |
| 339 | case CallingConv::AMDGPU_HS: |
| 340 | case CallingConv::AMDGPU_ES: |
| 341 | case CallingConv::AMDGPU_GS: |
| 342 | case CallingConv::AMDGPU_PS: |
| 343 | return std::make_pair(1, getWavefrontSize()); |
| 344 | default: |
| 345 | return std::make_pair(1, 16 * getWavefrontSize()); |
| 346 | } |
| 347 | } |
| 348 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 349 | std::pair<unsigned, unsigned> AMDGPUSubtarget::getFlatWorkGroupSizes( |
Konstantin Zhuravlyov | 1d65026 | 2016-09-06 20:22:28 +0000 | [diff] [blame] | 350 | const Function &F) const { |
Matt Arsenault | b791802 | 2017-10-23 17:09:35 +0000 | [diff] [blame] | 351 | // FIXME: 1024 if function. |
Konstantin Zhuravlyov | 1d65026 | 2016-09-06 20:22:28 +0000 | [diff] [blame] | 352 | // Default minimum/maximum flat work group sizes. |
| 353 | std::pair<unsigned, unsigned> Default = |
Matt Arsenault | b791802 | 2017-10-23 17:09:35 +0000 | [diff] [blame] | 354 | getDefaultFlatWorkGroupSize(F.getCallingConv()); |
Konstantin Zhuravlyov | 1d65026 | 2016-09-06 20:22:28 +0000 | [diff] [blame] | 355 | |
Konstantin Zhuravlyov | 1d65026 | 2016-09-06 20:22:28 +0000 | [diff] [blame] | 356 | // Requested minimum/maximum flat work group sizes. |
| 357 | std::pair<unsigned, unsigned> Requested = AMDGPU::getIntegerPairAttribute( |
| 358 | F, "amdgpu-flat-work-group-size", Default); |
| 359 | |
| 360 | // Make sure requested minimum is less than requested maximum. |
| 361 | if (Requested.first > Requested.second) |
| 362 | return Default; |
| 363 | |
| 364 | // Make sure requested values do not violate subtarget's specifications. |
| 365 | if (Requested.first < getMinFlatWorkGroupSize()) |
| 366 | return Default; |
| 367 | if (Requested.second > getMaxFlatWorkGroupSize()) |
| 368 | return Default; |
| 369 | |
| 370 | return Requested; |
| 371 | } |
| 372 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 373 | std::pair<unsigned, unsigned> AMDGPUSubtarget::getWavesPerEU( |
Konstantin Zhuravlyov | 1d65026 | 2016-09-06 20:22:28 +0000 | [diff] [blame] | 374 | const Function &F) const { |
Konstantin Zhuravlyov | 1d65026 | 2016-09-06 20:22:28 +0000 | [diff] [blame] | 375 | // Default minimum/maximum number of waves per execution unit. |
Konstantin Zhuravlyov | fd87137 | 2017-02-09 21:33:23 +0000 | [diff] [blame] | 376 | std::pair<unsigned, unsigned> Default(1, getMaxWavesPerEU()); |
Konstantin Zhuravlyov | 1d65026 | 2016-09-06 20:22:28 +0000 | [diff] [blame] | 377 | |
| 378 | // Default/requested minimum/maximum flat work group sizes. |
| 379 | std::pair<unsigned, unsigned> FlatWorkGroupSizes = getFlatWorkGroupSizes(F); |
| 380 | |
| 381 | // If minimum/maximum flat work group sizes were explicitly requested using |
| 382 | // "amdgpu-flat-work-group-size" attribute, then set default minimum/maximum |
| 383 | // number of waves per execution unit to values implied by requested |
| 384 | // minimum/maximum flat work group sizes. |
| 385 | unsigned MinImpliedByFlatWorkGroupSize = |
| 386 | getMaxWavesPerEU(FlatWorkGroupSizes.second); |
| 387 | bool RequestedFlatWorkGroupSize = false; |
| 388 | |
Matt Arsenault | 4fb580c | 2019-06-05 20:32:32 +0000 | [diff] [blame] | 389 | if (F.hasFnAttribute("amdgpu-flat-work-group-size")) { |
Konstantin Zhuravlyov | 1d65026 | 2016-09-06 20:22:28 +0000 | [diff] [blame] | 390 | Default.first = MinImpliedByFlatWorkGroupSize; |
| 391 | RequestedFlatWorkGroupSize = true; |
| 392 | } |
| 393 | |
| 394 | // Requested minimum/maximum number of waves per execution unit. |
| 395 | std::pair<unsigned, unsigned> Requested = AMDGPU::getIntegerPairAttribute( |
| 396 | F, "amdgpu-waves-per-eu", Default, true); |
| 397 | |
| 398 | // Make sure requested minimum is less than requested maximum. |
| 399 | if (Requested.second && Requested.first > Requested.second) |
| 400 | return Default; |
| 401 | |
| 402 | // Make sure requested values do not violate subtarget's specifications. |
| 403 | if (Requested.first < getMinWavesPerEU() || |
| 404 | Requested.first > getMaxWavesPerEU()) |
| 405 | return Default; |
| 406 | if (Requested.second > getMaxWavesPerEU()) |
| 407 | return Default; |
| 408 | |
| 409 | // Make sure requested values are compatible with values implied by requested |
| 410 | // minimum/maximum flat work group sizes. |
| 411 | if (RequestedFlatWorkGroupSize && |
Konstantin Zhuravlyov | 2ec725c | 2017-07-16 19:38:47 +0000 | [diff] [blame] | 412 | Requested.first < MinImpliedByFlatWorkGroupSize) |
Konstantin Zhuravlyov | 1d65026 | 2016-09-06 20:22:28 +0000 | [diff] [blame] | 413 | return Default; |
| 414 | |
| 415 | return Requested; |
| 416 | } |
| 417 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 418 | bool AMDGPUSubtarget::makeLIDRangeMetadata(Instruction *I) const { |
Stanislav Mekhanoshin | c90347d | 2017-04-12 20:48:56 +0000 | [diff] [blame] | 419 | Function *Kernel = I->getParent()->getParent(); |
| 420 | unsigned MinSize = 0; |
| 421 | unsigned MaxSize = getFlatWorkGroupSizes(*Kernel).second; |
| 422 | bool IdQuery = false; |
| 423 | |
| 424 | // If reqd_work_group_size is present it narrows value down. |
| 425 | if (auto *CI = dyn_cast<CallInst>(I)) { |
| 426 | const Function *F = CI->getCalledFunction(); |
| 427 | if (F) { |
| 428 | unsigned Dim = UINT_MAX; |
| 429 | switch (F->getIntrinsicID()) { |
| 430 | case Intrinsic::amdgcn_workitem_id_x: |
| 431 | case Intrinsic::r600_read_tidig_x: |
| 432 | IdQuery = true; |
Simon Pilgrim | 0f5b350 | 2017-07-07 10:18:57 +0000 | [diff] [blame] | 433 | LLVM_FALLTHROUGH; |
Stanislav Mekhanoshin | c90347d | 2017-04-12 20:48:56 +0000 | [diff] [blame] | 434 | case Intrinsic::r600_read_local_size_x: |
| 435 | Dim = 0; |
| 436 | break; |
| 437 | case Intrinsic::amdgcn_workitem_id_y: |
| 438 | case Intrinsic::r600_read_tidig_y: |
| 439 | IdQuery = true; |
Simon Pilgrim | 0f5b350 | 2017-07-07 10:18:57 +0000 | [diff] [blame] | 440 | LLVM_FALLTHROUGH; |
Stanislav Mekhanoshin | c90347d | 2017-04-12 20:48:56 +0000 | [diff] [blame] | 441 | case Intrinsic::r600_read_local_size_y: |
| 442 | Dim = 1; |
| 443 | break; |
| 444 | case Intrinsic::amdgcn_workitem_id_z: |
| 445 | case Intrinsic::r600_read_tidig_z: |
| 446 | IdQuery = true; |
Simon Pilgrim | 0f5b350 | 2017-07-07 10:18:57 +0000 | [diff] [blame] | 447 | LLVM_FALLTHROUGH; |
Stanislav Mekhanoshin | c90347d | 2017-04-12 20:48:56 +0000 | [diff] [blame] | 448 | case Intrinsic::r600_read_local_size_z: |
| 449 | Dim = 2; |
| 450 | break; |
| 451 | default: |
| 452 | break; |
| 453 | } |
| 454 | if (Dim <= 3) { |
| 455 | if (auto Node = Kernel->getMetadata("reqd_work_group_size")) |
| 456 | if (Node->getNumOperands() == 3) |
| 457 | MinSize = MaxSize = mdconst::extract<ConstantInt>( |
| 458 | Node->getOperand(Dim))->getZExtValue(); |
| 459 | } |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | if (!MaxSize) |
| 464 | return false; |
| 465 | |
| 466 | // Range metadata is [Lo, Hi). For ID query we need to pass max size |
| 467 | // as Hi. For size query we need to pass Hi + 1. |
| 468 | if (IdQuery) |
| 469 | MinSize = 0; |
| 470 | else |
| 471 | ++MaxSize; |
| 472 | |
| 473 | MDBuilder MDB(I->getContext()); |
| 474 | MDNode *MaxWorkGroupSizeRange = MDB.createRange(APInt(32, MinSize), |
| 475 | APInt(32, MaxSize)); |
| 476 | I->setMetadata(LLVMContext::MD_range, MaxWorkGroupSizeRange); |
| 477 | return true; |
| 478 | } |
| 479 | |
Matt Arsenault | 4bec7d4 | 2018-07-20 09:05:08 +0000 | [diff] [blame] | 480 | uint64_t AMDGPUSubtarget::getExplicitKernArgSize(const Function &F, |
| 481 | unsigned &MaxAlign) const { |
| 482 | assert(F.getCallingConv() == CallingConv::AMDGPU_KERNEL || |
| 483 | F.getCallingConv() == CallingConv::SPIR_KERNEL); |
| 484 | |
| 485 | const DataLayout &DL = F.getParent()->getDataLayout(); |
| 486 | uint64_t ExplicitArgBytes = 0; |
| 487 | MaxAlign = 1; |
| 488 | |
| 489 | for (const Argument &Arg : F.args()) { |
| 490 | Type *ArgTy = Arg.getType(); |
| 491 | |
| 492 | unsigned Align = DL.getABITypeAlignment(ArgTy); |
| 493 | uint64_t AllocSize = DL.getTypeAllocSize(ArgTy); |
| 494 | ExplicitArgBytes = alignTo(ExplicitArgBytes, Align) + AllocSize; |
| 495 | MaxAlign = std::max(MaxAlign, Align); |
| 496 | } |
| 497 | |
| 498 | return ExplicitArgBytes; |
| 499 | } |
| 500 | |
| 501 | unsigned AMDGPUSubtarget::getKernArgSegmentSize(const Function &F, |
| 502 | unsigned &MaxAlign) const { |
| 503 | uint64_t ExplicitArgBytes = getExplicitKernArgSize(F, MaxAlign); |
| 504 | |
| 505 | unsigned ExplicitOffset = getExplicitKernelArgOffset(F); |
| 506 | |
| 507 | uint64_t TotalSize = ExplicitOffset + ExplicitArgBytes; |
| 508 | unsigned ImplicitBytes = getImplicitArgNumBytes(F); |
| 509 | if (ImplicitBytes != 0) { |
| 510 | unsigned Alignment = getAlignmentForImplicitArgPtr(); |
| 511 | TotalSize = alignTo(ExplicitArgBytes, Alignment) + ImplicitBytes; |
| 512 | } |
| 513 | |
| 514 | // Being able to dereference past the end is useful for emitting scalar loads. |
| 515 | return alignTo(TotalSize, 4); |
| 516 | } |
| 517 | |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 518 | R600Subtarget::R600Subtarget(const Triple &TT, StringRef GPU, StringRef FS, |
| 519 | const TargetMachine &TM) : |
Tom Stellard | c5a154d | 2018-06-28 23:47:12 +0000 | [diff] [blame] | 520 | R600GenSubtargetInfo(TT, GPU, FS), |
Konstantin Zhuravlyov | 71e43ee | 2018-09-12 18:50:47 +0000 | [diff] [blame] | 521 | AMDGPUSubtarget(TT), |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 522 | InstrInfo(*this), |
| 523 | FrameLowering(TargetFrameLowering::StackGrowsUp, getStackAlignment(), 0), |
Tom Stellard | c5a154d | 2018-06-28 23:47:12 +0000 | [diff] [blame] | 524 | FMA(false), |
| 525 | CaymanISA(false), |
| 526 | CFALUBug(false), |
Tom Stellard | c5a154d | 2018-06-28 23:47:12 +0000 | [diff] [blame] | 527 | HasVertexCache(false), |
| 528 | R600ALUInst(false), |
| 529 | FP64(false), |
| 530 | TexVTXClauseSize(0), |
| 531 | Gen(R600), |
| 532 | TLInfo(TM, initializeSubtargetDependencies(TT, GPU, FS)), |
Matt Arsenault | 0da6350 | 2018-08-31 05:49:54 +0000 | [diff] [blame] | 533 | InstrItins(getInstrItineraryForCPU(GPU)) { } |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 534 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 535 | void GCNSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy, |
Matt Arsenault | 55dff27 | 2016-06-28 00:11:26 +0000 | [diff] [blame] | 536 | unsigned NumRegionInstrs) const { |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 537 | // Track register pressure so the scheduler can try to decrease |
| 538 | // pressure once register usage is above the threshold defined by |
| 539 | // SIRegisterInfo::getRegPressureSetLimit() |
| 540 | Policy.ShouldTrackPressure = true; |
Tom Stellard | 83f0bce | 2015-01-29 16:55:25 +0000 | [diff] [blame] | 541 | |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 542 | // Enabling both top down and bottom up scheduling seems to give us less |
| 543 | // register spills than just using one of these approaches on its own. |
| 544 | Policy.OnlyTopDown = false; |
| 545 | Policy.OnlyBottomUp = false; |
Tom Stellard | 83f0bce | 2015-01-29 16:55:25 +0000 | [diff] [blame] | 546 | |
Alexander Timofeev | 9f61fea | 2017-02-14 14:29:05 +0000 | [diff] [blame] | 547 | // Enabling ShouldTrackLaneMasks crashes the SI Machine Scheduler. |
| 548 | if (!enableSIScheduler()) |
| 549 | Policy.ShouldTrackLaneMasks = true; |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 550 | } |
Tom Stellard | 0bc954e | 2016-03-30 16:35:09 +0000 | [diff] [blame] | 551 | |
Stanislav Mekhanoshin | cee607e | 2019-04-24 17:03:15 +0000 | [diff] [blame] | 552 | bool GCNSubtarget::hasMadF16() const { |
| 553 | return InstrInfo.pseudoToMCOpcode(AMDGPU::V_MAD_F16) != -1; |
| 554 | } |
| 555 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 556 | unsigned GCNSubtarget::getOccupancyWithNumSGPRs(unsigned SGPRs) const { |
Stanislav Mekhanoshin | cee607e | 2019-04-24 17:03:15 +0000 | [diff] [blame] | 557 | if (getGeneration() >= AMDGPUSubtarget::GFX10) |
| 558 | return 10; |
| 559 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 560 | if (getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS) { |
Tom Stellard | 0d23ebe | 2016-08-29 19:42:52 +0000 | [diff] [blame] | 561 | if (SGPRs <= 80) |
| 562 | return 10; |
| 563 | if (SGPRs <= 88) |
| 564 | return 9; |
| 565 | if (SGPRs <= 100) |
| 566 | return 8; |
| 567 | return 7; |
| 568 | } |
| 569 | if (SGPRs <= 48) |
| 570 | return 10; |
| 571 | if (SGPRs <= 56) |
| 572 | return 9; |
| 573 | if (SGPRs <= 64) |
| 574 | return 8; |
| 575 | if (SGPRs <= 72) |
| 576 | return 7; |
| 577 | if (SGPRs <= 80) |
| 578 | return 6; |
| 579 | return 5; |
| 580 | } |
| 581 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 582 | unsigned GCNSubtarget::getOccupancyWithNumVGPRs(unsigned VGPRs) const { |
Tom Stellard | 0d23ebe | 2016-08-29 19:42:52 +0000 | [diff] [blame] | 583 | if (VGPRs <= 24) |
| 584 | return 10; |
| 585 | if (VGPRs <= 28) |
| 586 | return 9; |
| 587 | if (VGPRs <= 32) |
| 588 | return 8; |
| 589 | if (VGPRs <= 36) |
| 590 | return 7; |
| 591 | if (VGPRs <= 40) |
| 592 | return 6; |
| 593 | if (VGPRs <= 48) |
| 594 | return 5; |
| 595 | if (VGPRs <= 64) |
| 596 | return 4; |
| 597 | if (VGPRs <= 84) |
| 598 | return 3; |
| 599 | if (VGPRs <= 128) |
| 600 | return 2; |
| 601 | return 1; |
| 602 | } |
Matt Arsenault | 4eae301 | 2016-10-28 20:31:47 +0000 | [diff] [blame] | 603 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 604 | unsigned GCNSubtarget::getReservedNumSGPRs(const MachineFunction &MF) const { |
Konstantin Zhuravlyov | e03b1d7 | 2017-02-08 13:02:33 +0000 | [diff] [blame] | 605 | const SIMachineFunctionInfo &MFI = *MF.getInfo<SIMachineFunctionInfo>(); |
Stanislav Mekhanoshin | cee607e | 2019-04-24 17:03:15 +0000 | [diff] [blame] | 606 | if (getGeneration() >= AMDGPUSubtarget::GFX10) |
| 607 | return 2; // VCC. FLAT_SCRATCH and XNACK are no longer in SGPRs. |
| 608 | |
Konstantin Zhuravlyov | e03b1d7 | 2017-02-08 13:02:33 +0000 | [diff] [blame] | 609 | if (MFI.hasFlatScratchInit()) { |
| 610 | if (getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS) |
| 611 | return 6; // FLAT_SCRATCH, XNACK, VCC (in that order). |
| 612 | if (getGeneration() == AMDGPUSubtarget::SEA_ISLANDS) |
| 613 | return 4; // FLAT_SCRATCH, VCC (in that order). |
| 614 | } |
| 615 | |
| 616 | if (isXNACKEnabled()) |
| 617 | return 4; // XNACK, VCC (in that order). |
| 618 | return 2; // VCC. |
| 619 | } |
| 620 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 621 | unsigned GCNSubtarget::getMaxNumSGPRs(const MachineFunction &MF) const { |
Matthias Braun | f1caa28 | 2017-12-15 22:22:58 +0000 | [diff] [blame] | 622 | const Function &F = MF.getFunction(); |
Konstantin Zhuravlyov | e03b1d7 | 2017-02-08 13:02:33 +0000 | [diff] [blame] | 623 | const SIMachineFunctionInfo &MFI = *MF.getInfo<SIMachineFunctionInfo>(); |
| 624 | |
| 625 | // Compute maximum number of SGPRs function can use using default/requested |
| 626 | // minimum number of waves per execution unit. |
| 627 | std::pair<unsigned, unsigned> WavesPerEU = MFI.getWavesPerEU(); |
| 628 | unsigned MaxNumSGPRs = getMaxNumSGPRs(WavesPerEU.first, false); |
| 629 | unsigned MaxAddressableNumSGPRs = getMaxNumSGPRs(WavesPerEU.first, true); |
| 630 | |
| 631 | // Check if maximum number of SGPRs was explicitly requested using |
| 632 | // "amdgpu-num-sgpr" attribute. |
| 633 | if (F.hasFnAttribute("amdgpu-num-sgpr")) { |
| 634 | unsigned Requested = AMDGPU::getIntegerAttribute( |
| 635 | F, "amdgpu-num-sgpr", MaxNumSGPRs); |
| 636 | |
| 637 | // Make sure requested value does not violate subtarget's specifications. |
| 638 | if (Requested && (Requested <= getReservedNumSGPRs(MF))) |
| 639 | Requested = 0; |
| 640 | |
| 641 | // If more SGPRs are required to support the input user/system SGPRs, |
| 642 | // increase to accommodate them. |
| 643 | // |
| 644 | // FIXME: This really ends up using the requested number of SGPRs + number |
| 645 | // of reserved special registers in total. Theoretically you could re-use |
| 646 | // the last input registers for these special registers, but this would |
| 647 | // require a lot of complexity to deal with the weird aliasing. |
| 648 | unsigned InputNumSGPRs = MFI.getNumPreloadedSGPRs(); |
| 649 | if (Requested && Requested < InputNumSGPRs) |
| 650 | Requested = InputNumSGPRs; |
| 651 | |
| 652 | // Make sure requested value is compatible with values implied by |
| 653 | // default/requested minimum/maximum number of waves per execution unit. |
| 654 | if (Requested && Requested > getMaxNumSGPRs(WavesPerEU.first, false)) |
| 655 | Requested = 0; |
| 656 | if (WavesPerEU.second && |
| 657 | Requested && Requested < getMinNumSGPRs(WavesPerEU.second)) |
| 658 | Requested = 0; |
| 659 | |
| 660 | if (Requested) |
| 661 | MaxNumSGPRs = Requested; |
| 662 | } |
| 663 | |
Matt Arsenault | 4eae301 | 2016-10-28 20:31:47 +0000 | [diff] [blame] | 664 | if (hasSGPRInitBug()) |
Konstantin Zhuravlyov | 9f89ede | 2017-02-08 14:05:23 +0000 | [diff] [blame] | 665 | MaxNumSGPRs = AMDGPU::IsaInfo::FIXED_NUM_SGPRS_FOR_INIT_BUG; |
Matt Arsenault | 4eae301 | 2016-10-28 20:31:47 +0000 | [diff] [blame] | 666 | |
Konstantin Zhuravlyov | e03b1d7 | 2017-02-08 13:02:33 +0000 | [diff] [blame] | 667 | return std::min(MaxNumSGPRs - getReservedNumSGPRs(MF), |
| 668 | MaxAddressableNumSGPRs); |
| 669 | } |
Matt Arsenault | 4eae301 | 2016-10-28 20:31:47 +0000 | [diff] [blame] | 670 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 671 | unsigned GCNSubtarget::getMaxNumVGPRs(const MachineFunction &MF) const { |
Matthias Braun | f1caa28 | 2017-12-15 22:22:58 +0000 | [diff] [blame] | 672 | const Function &F = MF.getFunction(); |
Konstantin Zhuravlyov | e03b1d7 | 2017-02-08 13:02:33 +0000 | [diff] [blame] | 673 | const SIMachineFunctionInfo &MFI = *MF.getInfo<SIMachineFunctionInfo>(); |
| 674 | |
| 675 | // Compute maximum number of VGPRs function can use using default/requested |
| 676 | // minimum number of waves per execution unit. |
| 677 | std::pair<unsigned, unsigned> WavesPerEU = MFI.getWavesPerEU(); |
| 678 | unsigned MaxNumVGPRs = getMaxNumVGPRs(WavesPerEU.first); |
| 679 | |
| 680 | // Check if maximum number of VGPRs was explicitly requested using |
| 681 | // "amdgpu-num-vgpr" attribute. |
| 682 | if (F.hasFnAttribute("amdgpu-num-vgpr")) { |
| 683 | unsigned Requested = AMDGPU::getIntegerAttribute( |
| 684 | F, "amdgpu-num-vgpr", MaxNumVGPRs); |
| 685 | |
Konstantin Zhuravlyov | e03b1d7 | 2017-02-08 13:02:33 +0000 | [diff] [blame] | 686 | // Make sure requested value is compatible with values implied by |
| 687 | // default/requested minimum/maximum number of waves per execution unit. |
| 688 | if (Requested && Requested > getMaxNumVGPRs(WavesPerEU.first)) |
| 689 | Requested = 0; |
| 690 | if (WavesPerEU.second && |
| 691 | Requested && Requested < getMinNumVGPRs(WavesPerEU.second)) |
| 692 | Requested = 0; |
| 693 | |
| 694 | if (Requested) |
| 695 | MaxNumVGPRs = Requested; |
| 696 | } |
| 697 | |
Konstantin Zhuravlyov | e004b3d | 2018-06-21 20:28:19 +0000 | [diff] [blame] | 698 | return MaxNumVGPRs; |
Matt Arsenault | 4eae301 | 2016-10-28 20:31:47 +0000 | [diff] [blame] | 699 | } |
Stanislav Mekhanoshin | d4ae470 | 2017-09-19 20:54:38 +0000 | [diff] [blame] | 700 | |
Benjamin Kramer | f9ab3dd | 2017-10-31 23:21:30 +0000 | [diff] [blame] | 701 | namespace { |
Stanislav Mekhanoshin | d4ae470 | 2017-09-19 20:54:38 +0000 | [diff] [blame] | 702 | struct MemOpClusterMutation : ScheduleDAGMutation { |
| 703 | const SIInstrInfo *TII; |
| 704 | |
| 705 | MemOpClusterMutation(const SIInstrInfo *tii) : TII(tii) {} |
| 706 | |
Clement Courbet | b70355f | 2019-03-29 08:33:05 +0000 | [diff] [blame] | 707 | void apply(ScheduleDAGInstrs *DAG) override { |
Stanislav Mekhanoshin | d4ae470 | 2017-09-19 20:54:38 +0000 | [diff] [blame] | 708 | SUnit *SUa = nullptr; |
| 709 | // Search for two consequent memory operations and link them |
| 710 | // to prevent scheduler from moving them apart. |
| 711 | // In DAG pre-process SUnits are in the original order of |
| 712 | // the instructions before scheduling. |
| 713 | for (SUnit &SU : DAG->SUnits) { |
| 714 | MachineInstr &MI2 = *SU.getInstr(); |
| 715 | if (!MI2.mayLoad() && !MI2.mayStore()) { |
| 716 | SUa = nullptr; |
| 717 | continue; |
| 718 | } |
| 719 | if (!SUa) { |
| 720 | SUa = &SU; |
| 721 | continue; |
| 722 | } |
| 723 | |
| 724 | MachineInstr &MI1 = *SUa->getInstr(); |
| 725 | if ((TII->isVMEM(MI1) && TII->isVMEM(MI2)) || |
| 726 | (TII->isFLAT(MI1) && TII->isFLAT(MI2)) || |
| 727 | (TII->isSMRD(MI1) && TII->isSMRD(MI2)) || |
| 728 | (TII->isDS(MI1) && TII->isDS(MI2))) { |
| 729 | SU.addPredBarrier(SUa); |
| 730 | |
| 731 | for (const SDep &SI : SU.Preds) { |
| 732 | if (SI.getSUnit() != SUa) |
| 733 | SUa->addPred(SDep(SI.getSUnit(), SDep::Artificial)); |
| 734 | } |
| 735 | |
| 736 | if (&SU != &DAG->ExitSU) { |
| 737 | for (const SDep &SI : SUa->Succs) { |
| 738 | if (SI.getSUnit() != &SU) |
| 739 | SI.getSUnit()->addPred(SDep(&SU, SDep::Artificial)); |
| 740 | } |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | SUa = &SU; |
| 745 | } |
| 746 | } |
| 747 | }; |
Benjamin Kramer | f9ab3dd | 2017-10-31 23:21:30 +0000 | [diff] [blame] | 748 | } // namespace |
Stanislav Mekhanoshin | d4ae470 | 2017-09-19 20:54:38 +0000 | [diff] [blame] | 749 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 750 | void GCNSubtarget::getPostRAMutations( |
Stanislav Mekhanoshin | d4ae470 | 2017-09-19 20:54:38 +0000 | [diff] [blame] | 751 | std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations) const { |
| 752 | Mutations.push_back(llvm::make_unique<MemOpClusterMutation>(&InstrInfo)); |
| 753 | } |
Tom Stellard | c5a154d | 2018-06-28 23:47:12 +0000 | [diff] [blame] | 754 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 755 | const AMDGPUSubtarget &AMDGPUSubtarget::get(const MachineFunction &MF) { |
Tom Stellard | c5a154d | 2018-06-28 23:47:12 +0000 | [diff] [blame] | 756 | if (MF.getTarget().getTargetTriple().getArch() == Triple::amdgcn) |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 757 | return static_cast<const AMDGPUSubtarget&>(MF.getSubtarget<GCNSubtarget>()); |
Tom Stellard | c5a154d | 2018-06-28 23:47:12 +0000 | [diff] [blame] | 758 | else |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 759 | return static_cast<const AMDGPUSubtarget&>(MF.getSubtarget<R600Subtarget>()); |
Tom Stellard | c5a154d | 2018-06-28 23:47:12 +0000 | [diff] [blame] | 760 | } |
| 761 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 762 | const AMDGPUSubtarget &AMDGPUSubtarget::get(const TargetMachine &TM, const Function &F) { |
Tom Stellard | c5a154d | 2018-06-28 23:47:12 +0000 | [diff] [blame] | 763 | if (TM.getTargetTriple().getArch() == Triple::amdgcn) |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 764 | return static_cast<const AMDGPUSubtarget&>(TM.getSubtarget<GCNSubtarget>(F)); |
Tom Stellard | c5a154d | 2018-06-28 23:47:12 +0000 | [diff] [blame] | 765 | else |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 766 | return static_cast<const AMDGPUSubtarget&>(TM.getSubtarget<R600Subtarget>(F)); |
Tom Stellard | c5a154d | 2018-06-28 23:47:12 +0000 | [diff] [blame] | 767 | } |