1 //===-- AMDGPUSubtarget.cpp - AMDGPU Subtarget Information ----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief Implements the AMDGPU specific subclass of TargetSubtarget.
13 //===----------------------------------------------------------------------===//
15 #include "AMDGPUSubtarget.h"
16 #include "R600ISelLowering.h"
17 #include "R600InstrInfo.h"
18 #include "R600MachineScheduler.h"
19 #include "SIISelLowering.h"
20 #include "SIInstrInfo.h"
21 #include "SIMachineFunctionInfo.h"
22 #include "llvm/ADT/SmallString.h"
23 #include "llvm/CodeGen/MachineScheduler.h"
27 #define DEBUG_TYPE "amdgpu-subtarget"
29 #define GET_SUBTARGETINFO_ENUM
30 #define GET_SUBTARGETINFO_TARGET_DESC
31 #define GET_SUBTARGETINFO_CTOR
32 #include "AMDGPUGenSubtargetInfo.inc"
35 AMDGPUSubtarget::initializeSubtargetDependencies(StringRef TT, StringRef GPU, StringRef FS) {
36 // Determine default and user-specified characteristics
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.
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
45 SmallString<256> FullFS("+promote-alloca,+fp64-denormals,");
48 if (GPU == "" && Triple(TT).getArch() == Triple::amdgcn)
51 ParseSubtargetFeatures(GPU, FullFS);
53 // FIXME: I don't think think Evergreen has any useful support for
54 // denormals, but should be checked. Should we issue a warning somewhere
55 // if someone tries to enable these?
56 if (getGeneration() <= AMDGPUSubtarget::NORTHERN_ISLANDS) {
57 FP32Denormals = false;
58 FP64Denormals = false;
63 AMDGPUSubtarget::AMDGPUSubtarget(StringRef TT, StringRef GPU, StringRef FS,
65 : AMDGPUGenSubtargetInfo(TT, GPU, FS), DevName(GPU), Is64bit(false),
66 DumpCode(false), R600ALUInst(false), HasVertexCache(false),
67 TexVTXClauseSize(0), Gen(AMDGPUSubtarget::R600), FP64(false),
68 FP64Denormals(false), FP32Denormals(false),
69 FastFMAF32(false), CaymanISA(false),
70 FlatAddressSpace(false), EnableIRStructurizer(true),
71 EnablePromoteAlloca(false), EnableIfCvt(true),
72 EnableLoadStoreOpt(false), WavefrontSize(0), CFALUBug(false), LocalMemorySize(0),
73 EnableVGPRSpilling(false),
74 FrameLowering(TargetFrameLowering::StackGrowsUp,
75 64 * 16, // Maximum stack alignment (long16)
77 InstrItins(getInstrItineraryForCPU(GPU)),
80 initializeSubtargetDependencies(TT, GPU, FS);
82 if (getGeneration() <= AMDGPUSubtarget::NORTHERN_ISLANDS) {
83 InstrInfo.reset(new R600InstrInfo(*this));
84 TLInfo.reset(new R600TargetLowering(TM, *this));
86 InstrInfo.reset(new SIInstrInfo(*this));
87 TLInfo.reset(new SITargetLowering(TM, *this));
91 unsigned AMDGPUSubtarget::getStackEntrySize() const {
92 assert(getGeneration() <= NORTHERN_ISLANDS);
93 switch(getWavefrontSize()) {
97 return hasCaymanISA() ? 4 : 8;
101 llvm_unreachable("Illegal wavefront size.");
105 unsigned AMDGPUSubtarget::getAmdKernelCodeChipID() const {
106 switch(getGeneration()) {
107 default: llvm_unreachable("ChipID unknown");
108 case SEA_ISLANDS: return 12;
112 bool AMDGPUSubtarget::isVGPRSpillingEnabled(
113 const SIMachineFunctionInfo *MFI) const {
114 return MFI->getShaderType() == ShaderType::COMPUTE || EnableVGPRSpilling;
117 void AMDGPUSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
120 unsigned NumRegionInstrs) const {
121 if (getGeneration() >= SOUTHERN_ISLANDS) {
123 // Track register pressure so the scheduler can try to decrease
124 // pressure once register usage is above the threshold defined by
125 // SIRegisterInfo::getRegPressureSetLimit()
126 Policy.ShouldTrackPressure = true;
128 // Enabling both top down and bottom up scheduling seems to give us less
129 // register spills than just using one of these approaches on its own.
130 Policy.OnlyTopDown = false;
131 Policy.OnlyBottomUp = false;