blob: 0779d1d786b259e5fa172fa323d947f1dcdccac0 [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"
Eric Christopherac4b69e2014-07-25 22:22:39 +000019#include "SIISelLowering.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000020#include "SIInstrInfo.h"
Tom Stellarde99fb652015-01-20 19:33:04 +000021#include "SIMachineFunctionInfo.h"
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +000022#include "llvm/ADT/SmallString.h"
Tom Stellard83f0bce2015-01-29 16:55:25 +000023#include "llvm/CodeGen/MachineScheduler.h"
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +000024
Tom Stellard75aadc22012-12-11 21:25:42 +000025using namespace llvm;
26
Chandler Carruthe96dd892014-04-21 22:55:11 +000027#define DEBUG_TYPE "amdgpu-subtarget"
28
Tom Stellard75aadc22012-12-11 21:25:42 +000029#define GET_SUBTARGETINFO_ENUM
30#define GET_SUBTARGETINFO_TARGET_DESC
31#define GET_SUBTARGETINFO_CTOR
32#include "AMDGPUGenSubtargetInfo.inc"
33
Eric Christopherac4b69e2014-07-25 22:22:39 +000034AMDGPUSubtarget &
Daniel Sandersa73f1fd2015-06-10 12:11:26 +000035AMDGPUSubtarget::initializeSubtargetDependencies(const Triple &TT,
36 StringRef GPU, StringRef FS) {
Eric Christopherac4b69e2014-07-25 22:22:39 +000037 // Determine default and user-specified characteristics
Matt Arsenaultf171cf22014-07-14 23:40:49 +000038 // On SI+, we want FP64 denormals to be on by default. FP32 denormals can be
39 // enabled, but some instructions do not respect them and they run at the
40 // double precision rate, so don't enable by default.
41 //
42 // We want to be able to turn these off, but making this a subtarget feature
43 // for SI has the unhelpful behavior that it unsets everything else if you
44 // disable it.
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +000045
Matt Arsenaultf171cf22014-07-14 23:40:49 +000046 SmallString<256> FullFS("+promote-alloca,+fp64-denormals,");
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +000047 FullFS += FS;
48
Daniel Sandersa73f1fd2015-06-10 12:11:26 +000049 if (GPU == "" && TT.getArch() == Triple::amdgcn)
Tom Stellardeba56482015-01-28 15:38:42 +000050 GPU = "SI";
51
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +000052 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 }
61 return *this;
62}
63
Daniel Sandersa73f1fd2015-06-10 12:11:26 +000064AMDGPUSubtarget::AMDGPUSubtarget(const Triple &TT, StringRef GPU, StringRef FS,
Eric Christopherac4b69e2014-07-25 22:22:39 +000065 TargetMachine &TM)
66 : AMDGPUGenSubtargetInfo(TT, GPU, FS), DevName(GPU), Is64bit(false),
67 DumpCode(false), R600ALUInst(false), HasVertexCache(false),
68 TexVTXClauseSize(0), Gen(AMDGPUSubtarget::R600), FP64(false),
Eric Christopher111de892015-02-19 00:15:33 +000069 FP64Denormals(false), FP32Denormals(false), FastFMAF32(false),
70 CaymanISA(false), FlatAddressSpace(false), EnableIRStructurizer(true),
71 EnablePromoteAlloca(false), EnableIfCvt(true), EnableLoadStoreOpt(false),
72 WavefrontSize(0), CFALUBug(false), LocalMemorySize(0),
Daniel Sandersa73f1fd2015-06-10 12:11:26 +000073 EnableVGPRSpilling(false), SGPRInitBug(false), IsGCN(false),
74 GCN1Encoding(false), GCN3Encoding(false), CIInsts(false), LDSBankCount(0),
Tom Stellard347ac792015-06-26 21:15:07 +000075 IsaVersion(ISAVersion0_0_0),
Eric Christopherac4b69e2014-07-25 22:22:39 +000076 FrameLowering(TargetFrameLowering::StackGrowsUp,
77 64 * 16, // Maximum stack alignment (long16)
78 0),
Eric Christopher111de892015-02-19 00:15:33 +000079 InstrItins(getInstrItineraryForCPU(GPU)), TargetTriple(TT) {
Tom Stellard40ce8af2015-01-28 16:04:26 +000080
81 initializeSubtargetDependencies(TT, GPU, FS);
82
Eric Christopherac4b69e2014-07-25 22:22:39 +000083 if (getGeneration() <= AMDGPUSubtarget::NORTHERN_ISLANDS) {
84 InstrInfo.reset(new R600InstrInfo(*this));
Eric Christopher7792e322015-01-30 23:24:40 +000085 TLInfo.reset(new R600TargetLowering(TM, *this));
Tom Stellard2e59a452014-06-13 01:32:00 +000086 } else {
87 InstrInfo.reset(new SIInstrInfo(*this));
Eric Christopher7792e322015-01-30 23:24:40 +000088 TLInfo.reset(new SITargetLowering(TM, *this));
Tom Stellard2e59a452014-06-13 01:32:00 +000089 }
Tom Stellard75aadc22012-12-11 21:25:42 +000090}
91
Matt Arsenaultd782d052014-06-27 17:57:00 +000092unsigned AMDGPUSubtarget::getStackEntrySize() const {
Tom Stellarda40f9712014-01-22 21:55:43 +000093 assert(getGeneration() <= NORTHERN_ISLANDS);
94 switch(getWavefrontSize()) {
95 case 16:
96 return 8;
97 case 32:
Matt Arsenaultd782d052014-06-27 17:57:00 +000098 return hasCaymanISA() ? 4 : 8;
Tom Stellarda40f9712014-01-22 21:55:43 +000099 case 64:
100 return 4;
101 default:
102 llvm_unreachable("Illegal wavefront size.");
103 }
104}
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000105
106unsigned AMDGPUSubtarget::getAmdKernelCodeChipID() const {
107 switch(getGeneration()) {
108 default: llvm_unreachable("ChipID unknown");
109 case SEA_ISLANDS: return 12;
110 }
111}
Tom Stellarde99fb652015-01-20 19:33:04 +0000112
Tom Stellard347ac792015-06-26 21:15:07 +0000113AMDGPU::IsaVersion AMDGPUSubtarget::getIsaVersion() const {
114 return AMDGPU::getIsaVersion(getFeatureBits());
115}
116
Tom Stellarde99fb652015-01-20 19:33:04 +0000117bool AMDGPUSubtarget::isVGPRSpillingEnabled(
118 const SIMachineFunctionInfo *MFI) const {
119 return MFI->getShaderType() == ShaderType::COMPUTE || EnableVGPRSpilling;
120}
Tom Stellard83f0bce2015-01-29 16:55:25 +0000121
122void AMDGPUSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
123 MachineInstr *begin,
124 MachineInstr *end,
125 unsigned NumRegionInstrs) const {
126 if (getGeneration() >= SOUTHERN_ISLANDS) {
127
128 // Track register pressure so the scheduler can try to decrease
129 // pressure once register usage is above the threshold defined by
130 // SIRegisterInfo::getRegPressureSetLimit()
131 Policy.ShouldTrackPressure = true;
132
133 // Enabling both top down and bottom up scheduling seems to give us less
134 // register spills than just using one of these approaches on its own.
135 Policy.OnlyTopDown = false;
136 Policy.OnlyBottomUp = false;
137 }
138}
Tom Stellard347ac792015-06-26 21:15:07 +0000139