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" |
Eric Christopher | ac4b69e | 2014-07-25 22:22:39 +0000 | [diff] [blame] | 16 | #include "R600ISelLowering.h" |
Tom Stellard | 2e59a45 | 2014-06-13 01:32:00 +0000 | [diff] [blame] | 17 | #include "R600InstrInfo.h" |
Eric Christopher | ac4b69e | 2014-07-25 22:22:39 +0000 | [diff] [blame] | 18 | #include "R600MachineScheduler.h" |
Matt Arsenault | f59e538 | 2015-11-06 18:23:00 +0000 | [diff] [blame] | 19 | #include "SIFrameLowering.h" |
Eric Christopher | ac4b69e | 2014-07-25 22:22:39 +0000 | [diff] [blame] | 20 | #include "SIISelLowering.h" |
Chandler Carruth | d990388 | 2015-01-14 11:23:27 +0000 | [diff] [blame] | 21 | #include "SIInstrInfo.h" |
Tom Stellard | e99fb65 | 2015-01-20 19:33:04 +0000 | [diff] [blame] | 22 | #include "SIMachineFunctionInfo.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" |
Matt Arsenault | d9a23ab | 2014-07-13 02:08:26 +0000 | [diff] [blame] | 25 | |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 26 | using namespace llvm; |
| 27 | |
Chandler Carruth | e96dd89 | 2014-04-21 22:55:11 +0000 | [diff] [blame] | 28 | #define DEBUG_TYPE "amdgpu-subtarget" |
| 29 | |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 30 | #define GET_SUBTARGETINFO_ENUM |
| 31 | #define GET_SUBTARGETINFO_TARGET_DESC |
| 32 | #define GET_SUBTARGETINFO_CTOR |
| 33 | #include "AMDGPUGenSubtargetInfo.inc" |
| 34 | |
Eric Christopher | ac4b69e | 2014-07-25 22:22:39 +0000 | [diff] [blame] | 35 | AMDGPUSubtarget & |
Daniel Sanders | a73f1fd | 2015-06-10 12:11:26 +0000 | [diff] [blame] | 36 | AMDGPUSubtarget::initializeSubtargetDependencies(const Triple &TT, |
| 37 | StringRef GPU, StringRef FS) { |
Eric Christopher | ac4b69e | 2014-07-25 22:22:39 +0000 | [diff] [blame] | 38 | // Determine default and user-specified characteristics |
Matt Arsenault | f171cf2 | 2014-07-14 23:40:49 +0000 | [diff] [blame] | 39 | // On SI+, we want FP64 denormals to be on by default. FP32 denormals can be |
| 40 | // enabled, but some instructions do not respect them and they run at the |
| 41 | // double precision rate, so don't enable by default. |
| 42 | // |
| 43 | // We want to be able to turn these off, but making this a subtarget feature |
| 44 | // for SI has the unhelpful behavior that it unsets everything else if you |
| 45 | // disable it. |
Matt Arsenault | d9a23ab | 2014-07-13 02:08:26 +0000 | [diff] [blame] | 46 | |
Matt Arsenault | f171cf2 | 2014-07-14 23:40:49 +0000 | [diff] [blame] | 47 | SmallString<256> FullFS("+promote-alloca,+fp64-denormals,"); |
Changpeng Fang | b41574a | 2015-12-22 20:55:23 +0000 | [diff] [blame] | 48 | if (isAmdHsaOS()) // Turn on FlatForGlobal for HSA. |
| 49 | FullFS += "+flat-for-global,"; |
Matt Arsenault | d9a23ab | 2014-07-13 02:08:26 +0000 | [diff] [blame] | 50 | FullFS += FS; |
| 51 | |
Daniel Sanders | a73f1fd | 2015-06-10 12:11:26 +0000 | [diff] [blame] | 52 | if (GPU == "" && TT.getArch() == Triple::amdgcn) |
Tom Stellard | eba5648 | 2015-01-28 15:38:42 +0000 | [diff] [blame] | 53 | GPU = "SI"; |
| 54 | |
Matt Arsenault | d9a23ab | 2014-07-13 02:08:26 +0000 | [diff] [blame] | 55 | ParseSubtargetFeatures(GPU, FullFS); |
Tom Stellard | 2e59a45 | 2014-06-13 01:32:00 +0000 | [diff] [blame] | 56 | |
Eric Christopher | ac4b69e | 2014-07-25 22:22:39 +0000 | [diff] [blame] | 57 | // FIXME: I don't think think Evergreen has any useful support for |
| 58 | // denormals, but should be checked. Should we issue a warning somewhere |
| 59 | // if someone tries to enable these? |
Tom Stellard | 2e59a45 | 2014-06-13 01:32:00 +0000 | [diff] [blame] | 60 | if (getGeneration() <= AMDGPUSubtarget::NORTHERN_ISLANDS) { |
Matt Arsenault | f171cf2 | 2014-07-14 23:40:49 +0000 | [diff] [blame] | 61 | FP32Denormals = false; |
| 62 | FP64Denormals = false; |
Eric Christopher | ac4b69e | 2014-07-25 22:22:39 +0000 | [diff] [blame] | 63 | } |
| 64 | return *this; |
| 65 | } |
| 66 | |
Daniel Sanders | a73f1fd | 2015-06-10 12:11:26 +0000 | [diff] [blame] | 67 | AMDGPUSubtarget::AMDGPUSubtarget(const Triple &TT, StringRef GPU, StringRef FS, |
Eric Christopher | ac4b69e | 2014-07-25 22:22:39 +0000 | [diff] [blame] | 68 | TargetMachine &TM) |
Matt Arsenault | 2a93bb6 | 2016-01-23 05:32:14 +0000 | [diff] [blame] | 69 | : AMDGPUGenSubtargetInfo(TT, GPU, FS), DevName(GPU), |
Daniel Sanders | 50f1723 | 2015-09-15 16:17:27 +0000 | [diff] [blame] | 70 | DumpCode(false), R600ALUInst(false), HasVertexCache(false), |
| 71 | TexVTXClauseSize(0), Gen(AMDGPUSubtarget::R600), FP64(false), |
| 72 | FP64Denormals(false), FP32Denormals(false), FastFMAF32(false), |
Matt Arsenault | e83690c | 2016-01-18 21:13:50 +0000 | [diff] [blame] | 73 | HalfRate64Ops(false), CaymanISA(false), FlatAddressSpace(false), |
| 74 | FlatForGlobal(false), EnableIRStructurizer(true), |
| 75 | EnablePromoteAlloca(false), |
| 76 | EnableIfCvt(true), EnableLoadStoreOpt(false), |
| 77 | EnableUnsafeDSOffsetFolding(false), |
Nicolai Haehnle | 5b50497 | 2016-01-04 23:35:53 +0000 | [diff] [blame] | 78 | EnableXNACK(false), |
Matt Arsenault | e83690c | 2016-01-18 21:13:50 +0000 | [diff] [blame] | 79 | WavefrontSize(0), CFALUBug(false), |
| 80 | LocalMemorySize(0), |
Daniel Sanders | a73f1fd | 2015-06-10 12:11:26 +0000 | [diff] [blame] | 81 | EnableVGPRSpilling(false), SGPRInitBug(false), IsGCN(false), |
| 82 | GCN1Encoding(false), GCN3Encoding(false), CIInsts(false), LDSBankCount(0), |
Tom Stellard | c98ee20 | 2015-07-16 19:40:07 +0000 | [diff] [blame] | 83 | IsaVersion(ISAVersion0_0_0), EnableHugeScratchBuffer(false), |
Tom Stellard | de008d3 | 2016-01-21 04:28:34 +0000 | [diff] [blame] | 84 | EnableSIScheduler(false), FrameLowering(nullptr), |
Eric Christopher | 111de89 | 2015-02-19 00:15:33 +0000 | [diff] [blame] | 85 | InstrItins(getInstrItineraryForCPU(GPU)), TargetTriple(TT) { |
Tom Stellard | 40ce8af | 2015-01-28 16:04:26 +0000 | [diff] [blame] | 86 | |
| 87 | initializeSubtargetDependencies(TT, GPU, FS); |
| 88 | |
Matt Arsenault | 0c90e95 | 2015-11-06 18:17:45 +0000 | [diff] [blame] | 89 | const unsigned MaxStackAlign = 64 * 16; // Maximum stack alignment (long16) |
| 90 | |
Eric Christopher | ac4b69e | 2014-07-25 22:22:39 +0000 | [diff] [blame] | 91 | if (getGeneration() <= AMDGPUSubtarget::NORTHERN_ISLANDS) { |
| 92 | InstrInfo.reset(new R600InstrInfo(*this)); |
Eric Christopher | 7792e32 | 2015-01-30 23:24:40 +0000 | [diff] [blame] | 93 | TLInfo.reset(new R600TargetLowering(TM, *this)); |
Matt Arsenault | 0c90e95 | 2015-11-06 18:17:45 +0000 | [diff] [blame] | 94 | |
| 95 | // FIXME: Should have R600 specific FrameLowering |
| 96 | FrameLowering.reset(new AMDGPUFrameLowering( |
| 97 | TargetFrameLowering::StackGrowsUp, |
| 98 | MaxStackAlign, |
| 99 | 0)); |
Tom Stellard | 2e59a45 | 2014-06-13 01:32:00 +0000 | [diff] [blame] | 100 | } else { |
| 101 | InstrInfo.reset(new SIInstrInfo(*this)); |
Eric Christopher | 7792e32 | 2015-01-30 23:24:40 +0000 | [diff] [blame] | 102 | TLInfo.reset(new SITargetLowering(TM, *this)); |
Matt Arsenault | 0c90e95 | 2015-11-06 18:17:45 +0000 | [diff] [blame] | 103 | FrameLowering.reset(new SIFrameLowering( |
| 104 | TargetFrameLowering::StackGrowsUp, |
| 105 | MaxStackAlign, |
| 106 | 0)); |
Tom Stellard | 2e59a45 | 2014-06-13 01:32:00 +0000 | [diff] [blame] | 107 | } |
Tom Stellard | 75aadc2 | 2012-12-11 21:25:42 +0000 | [diff] [blame] | 108 | } |
| 109 | |
Matt Arsenault | d782d05 | 2014-06-27 17:57:00 +0000 | [diff] [blame] | 110 | unsigned AMDGPUSubtarget::getStackEntrySize() const { |
Tom Stellard | a40f971 | 2014-01-22 21:55:43 +0000 | [diff] [blame] | 111 | assert(getGeneration() <= NORTHERN_ISLANDS); |
| 112 | switch(getWavefrontSize()) { |
| 113 | case 16: |
| 114 | return 8; |
| 115 | case 32: |
Matt Arsenault | d782d05 | 2014-06-27 17:57:00 +0000 | [diff] [blame] | 116 | return hasCaymanISA() ? 4 : 8; |
Tom Stellard | a40f971 | 2014-01-22 21:55:43 +0000 | [diff] [blame] | 117 | case 64: |
| 118 | return 4; |
| 119 | default: |
| 120 | llvm_unreachable("Illegal wavefront size."); |
| 121 | } |
| 122 | } |
Tom Stellard | b8fd6ef | 2014-12-02 22:00:07 +0000 | [diff] [blame] | 123 | |
| 124 | unsigned AMDGPUSubtarget::getAmdKernelCodeChipID() const { |
| 125 | switch(getGeneration()) { |
| 126 | default: llvm_unreachable("ChipID unknown"); |
| 127 | case SEA_ISLANDS: return 12; |
| 128 | } |
| 129 | } |
Tom Stellard | e99fb65 | 2015-01-20 19:33:04 +0000 | [diff] [blame] | 130 | |
Tom Stellard | 347ac79 | 2015-06-26 21:15:07 +0000 | [diff] [blame] | 131 | AMDGPU::IsaVersion AMDGPUSubtarget::getIsaVersion() const { |
| 132 | return AMDGPU::getIsaVersion(getFeatureBits()); |
| 133 | } |
| 134 | |
Tom Stellard | e99fb65 | 2015-01-20 19:33:04 +0000 | [diff] [blame] | 135 | bool AMDGPUSubtarget::isVGPRSpillingEnabled( |
| 136 | const SIMachineFunctionInfo *MFI) const { |
| 137 | return MFI->getShaderType() == ShaderType::COMPUTE || EnableVGPRSpilling; |
| 138 | } |
Tom Stellard | 83f0bce | 2015-01-29 16:55:25 +0000 | [diff] [blame] | 139 | |
| 140 | void AMDGPUSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy, |
| 141 | MachineInstr *begin, |
| 142 | MachineInstr *end, |
| 143 | unsigned NumRegionInstrs) const { |
| 144 | if (getGeneration() >= SOUTHERN_ISLANDS) { |
| 145 | |
| 146 | // Track register pressure so the scheduler can try to decrease |
| 147 | // pressure once register usage is above the threshold defined by |
| 148 | // SIRegisterInfo::getRegPressureSetLimit() |
| 149 | Policy.ShouldTrackPressure = true; |
| 150 | |
| 151 | // Enabling both top down and bottom up scheduling seems to give us less |
| 152 | // register spills than just using one of these approaches on its own. |
| 153 | Policy.OnlyTopDown = false; |
| 154 | Policy.OnlyBottomUp = false; |
| 155 | } |
| 156 | } |
Tom Stellard | 347ac79 | 2015-06-26 21:15:07 +0000 | [diff] [blame] | 157 | |