blob: 17fa51570e16bdac15d5fdb522ace7a7ac11177f [file] [log] [blame]
Tom Stellard75aadc22012-12-11 21:25:42 +00001//===-- 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 Christopherac4b69e2014-07-25 22:22:39 +000016#include "R600ISelLowering.h"
Tom Stellard2e59a452014-06-13 01:32:00 +000017#include "R600InstrInfo.h"
Eric Christopherac4b69e2014-07-25 22:22:39 +000018#include "R600MachineScheduler.h"
Matt Arsenaultf59e5382015-11-06 18:23:00 +000019#include "SIFrameLowering.h"
Eric Christopherac4b69e2014-07-25 22:22:39 +000020#include "SIISelLowering.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000021#include "SIInstrInfo.h"
Tom Stellarde99fb652015-01-20 19:33:04 +000022#include "SIMachineFunctionInfo.h"
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +000023#include "llvm/ADT/SmallString.h"
Tom Stellard83f0bce2015-01-29 16:55:25 +000024#include "llvm/CodeGen/MachineScheduler.h"
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +000025
Tom Stellard75aadc22012-12-11 21:25:42 +000026using namespace llvm;
27
Chandler Carruthe96dd892014-04-21 22:55:11 +000028#define DEBUG_TYPE "amdgpu-subtarget"
29
Tom Stellard75aadc22012-12-11 21:25:42 +000030#define GET_SUBTARGETINFO_ENUM
31#define GET_SUBTARGETINFO_TARGET_DESC
32#define GET_SUBTARGETINFO_CTOR
33#include "AMDGPUGenSubtargetInfo.inc"
34
Eric Christopherac4b69e2014-07-25 22:22:39 +000035AMDGPUSubtarget &
Daniel Sandersa73f1fd2015-06-10 12:11:26 +000036AMDGPUSubtarget::initializeSubtargetDependencies(const Triple &TT,
37 StringRef GPU, StringRef FS) {
Eric Christopherac4b69e2014-07-25 22:22:39 +000038 // Determine default and user-specified characteristics
Matt Arsenaultf171cf22014-07-14 23:40:49 +000039 // 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 Arsenaultd9a23ab2014-07-13 02:08:26 +000046
Matt Arsenaultf171cf22014-07-14 23:40:49 +000047 SmallString<256> FullFS("+promote-alloca,+fp64-denormals,");
Changpeng Fangb41574a2015-12-22 20:55:23 +000048 if (isAmdHsaOS()) // Turn on FlatForGlobal for HSA.
49 FullFS += "+flat-for-global,";
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +000050 FullFS += FS;
51
52 ParseSubtargetFeatures(GPU, FullFS);
Tom Stellard2e59a452014-06-13 01:32:00 +000053
Eric Christopherac4b69e2014-07-25 22:22:39 +000054 // FIXME: I don't think think Evergreen has any useful support for
55 // denormals, but should be checked. Should we issue a warning somewhere
56 // if someone tries to enable these?
Tom Stellard2e59a452014-06-13 01:32:00 +000057 if (getGeneration() <= AMDGPUSubtarget::NORTHERN_ISLANDS) {
Matt Arsenaultf171cf22014-07-14 23:40:49 +000058 FP32Denormals = false;
59 FP64Denormals = false;
Eric Christopherac4b69e2014-07-25 22:22:39 +000060 }
Matt Arsenault24ee0782016-02-12 02:40:47 +000061
62 // Set defaults if needed.
63 if (MaxPrivateElementSize == 0)
64 MaxPrivateElementSize = 16;
65
Eric Christopherac4b69e2014-07-25 22:22:39 +000066 return *this;
67}
68
Daniel Sandersa73f1fd2015-06-10 12:11:26 +000069AMDGPUSubtarget::AMDGPUSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
Eric Christopherac4b69e2014-07-25 22:22:39 +000070 TargetMachine &TM)
Matt Arsenaultb22828f2016-01-27 02:17:49 +000071 : AMDGPUGenSubtargetInfo(TT, GPU, FS),
Daniel Sanders50f17232015-09-15 16:17:27 +000072 DumpCode(false), R600ALUInst(false), HasVertexCache(false),
73 TexVTXClauseSize(0), Gen(AMDGPUSubtarget::R600), FP64(false),
Matt Arsenaultf639c322016-01-28 20:53:42 +000074 FP64Denormals(false), FP32Denormals(false), FPExceptions(false),
75 FastFMAF32(false), HalfRate64Ops(false), CaymanISA(false),
76 FlatAddressSpace(false), FlatForGlobal(false), EnableIRStructurizer(true),
Matt Arsenaulte83690c2016-01-18 21:13:50 +000077 EnablePromoteAlloca(false),
78 EnableIfCvt(true), EnableLoadStoreOpt(false),
79 EnableUnsafeDSOffsetFolding(false),
Nicolai Haehnle5b504972016-01-04 23:35:53 +000080 EnableXNACK(false),
Matt Arsenaulte83690c2016-01-18 21:13:50 +000081 WavefrontSize(0), CFALUBug(false),
Matt Arsenault24ee0782016-02-12 02:40:47 +000082 LocalMemorySize(0), MaxPrivateElementSize(0),
Daniel Sandersa73f1fd2015-06-10 12:11:26 +000083 EnableVGPRSpilling(false), SGPRInitBug(false), IsGCN(false),
Matt Arsenault9d82ee72016-02-27 08:53:55 +000084 GCN1Encoding(false), GCN3Encoding(false), CIInsts(false),
85 HasSMemRealTime(false), Has16BitInsts(false),
Matt Arsenault61738cb2016-02-27 08:53:46 +000086 LDSBankCount(0),
Matt Arsenault3a619852016-02-27 20:26:57 +000087 IsaVersion(ISAVersion0_0_0),
Tom Stellardde008d32016-01-21 04:28:34 +000088 EnableSIScheduler(false), FrameLowering(nullptr),
Eric Christopher111de892015-02-19 00:15:33 +000089 InstrItins(getInstrItineraryForCPU(GPU)), TargetTriple(TT) {
Tom Stellard40ce8af2015-01-28 16:04:26 +000090
91 initializeSubtargetDependencies(TT, GPU, FS);
92
Matt Arsenault0c90e952015-11-06 18:17:45 +000093 const unsigned MaxStackAlign = 64 * 16; // Maximum stack alignment (long16)
94
Eric Christopherac4b69e2014-07-25 22:22:39 +000095 if (getGeneration() <= AMDGPUSubtarget::NORTHERN_ISLANDS) {
96 InstrInfo.reset(new R600InstrInfo(*this));
Eric Christopher7792e322015-01-30 23:24:40 +000097 TLInfo.reset(new R600TargetLowering(TM, *this));
Matt Arsenault0c90e952015-11-06 18:17:45 +000098
99 // FIXME: Should have R600 specific FrameLowering
100 FrameLowering.reset(new AMDGPUFrameLowering(
101 TargetFrameLowering::StackGrowsUp,
102 MaxStackAlign,
103 0));
Tom Stellard2e59a452014-06-13 01:32:00 +0000104 } else {
105 InstrInfo.reset(new SIInstrInfo(*this));
Eric Christopher7792e322015-01-30 23:24:40 +0000106 TLInfo.reset(new SITargetLowering(TM, *this));
Matt Arsenault0c90e952015-11-06 18:17:45 +0000107 FrameLowering.reset(new SIFrameLowering(
108 TargetFrameLowering::StackGrowsUp,
109 MaxStackAlign,
110 0));
Tom Stellard2e59a452014-06-13 01:32:00 +0000111 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000112}
113
Matt Arsenaultd782d052014-06-27 17:57:00 +0000114unsigned AMDGPUSubtarget::getStackEntrySize() const {
Tom Stellarda40f9712014-01-22 21:55:43 +0000115 assert(getGeneration() <= NORTHERN_ISLANDS);
116 switch(getWavefrontSize()) {
117 case 16:
118 return 8;
119 case 32:
Matt Arsenaultd782d052014-06-27 17:57:00 +0000120 return hasCaymanISA() ? 4 : 8;
Tom Stellarda40f9712014-01-22 21:55:43 +0000121 case 64:
122 return 4;
123 default:
124 llvm_unreachable("Illegal wavefront size.");
125 }
126}
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000127
128unsigned AMDGPUSubtarget::getAmdKernelCodeChipID() const {
129 switch(getGeneration()) {
130 default: llvm_unreachable("ChipID unknown");
131 case SEA_ISLANDS: return 12;
132 }
133}
Tom Stellarde99fb652015-01-20 19:33:04 +0000134
Tom Stellard347ac792015-06-26 21:15:07 +0000135AMDGPU::IsaVersion AMDGPUSubtarget::getIsaVersion() const {
136 return AMDGPU::getIsaVersion(getFeatureBits());
137}
138
Tom Stellarde99fb652015-01-20 19:33:04 +0000139bool AMDGPUSubtarget::isVGPRSpillingEnabled(
140 const SIMachineFunctionInfo *MFI) const {
141 return MFI->getShaderType() == ShaderType::COMPUTE || EnableVGPRSpilling;
142}
Tom Stellard83f0bce2015-01-29 16:55:25 +0000143
144void AMDGPUSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
145 MachineInstr *begin,
146 MachineInstr *end,
147 unsigned NumRegionInstrs) const {
148 if (getGeneration() >= SOUTHERN_ISLANDS) {
149
150 // Track register pressure so the scheduler can try to decrease
151 // pressure once register usage is above the threshold defined by
152 // SIRegisterInfo::getRegPressureSetLimit()
153 Policy.ShouldTrackPressure = true;
154
155 // Enabling both top down and bottom up scheduling seems to give us less
156 // register spills than just using one of these approaches on its own.
157 Policy.OnlyTopDown = false;
158 Policy.OnlyBottomUp = false;
Tom Stellard0bc954e2016-03-30 16:35:09 +0000159
160 // Enabling ShouldTrackLaneMasks crashes the SI Machine Scheduler.
161 if (!enableSIScheduler())
162 Policy.ShouldTrackLaneMasks = true;
Tom Stellard83f0bce2015-01-29 16:55:25 +0000163 }
164}
Tom Stellard347ac792015-06-26 21:15:07 +0000165