R600/SI: Define a schedule model and enable the generic machine scheduler
[oota-llvm.git] / lib / Target / R600 / AMDGPUSubtarget.cpp
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"
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"
24
25 using namespace llvm;
26
27 #define DEBUG_TYPE "amdgpu-subtarget"
28
29 #define GET_SUBTARGETINFO_ENUM
30 #define GET_SUBTARGETINFO_TARGET_DESC
31 #define GET_SUBTARGETINFO_CTOR
32 #include "AMDGPUGenSubtargetInfo.inc"
33
34 AMDGPUSubtarget &
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.
40   //
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
43   // disable it.
44
45   SmallString<256> FullFS("+promote-alloca,+fp64-denormals,");
46   FullFS += FS;
47
48   if (GPU == "" && Triple(TT).getArch() == Triple::amdgcn)
49     GPU = "SI";
50
51   ParseSubtargetFeatures(GPU, FullFS);
52
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;
59   }
60   return *this;
61 }
62
63 AMDGPUSubtarget::AMDGPUSubtarget(StringRef TT, StringRef GPU, StringRef FS,
64                                  TargetMachine &TM)
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), CaymanISA(false),
69       FlatAddressSpace(false), EnableIRStructurizer(true),
70       EnablePromoteAlloca(false), EnableIfCvt(true),
71       EnableLoadStoreOpt(false), WavefrontSize(0), CFALUBug(false), LocalMemorySize(0),
72       EnableVGPRSpilling(false),
73       FrameLowering(TargetFrameLowering::StackGrowsUp,
74                     64 * 16, // Maximum stack alignment (long16)
75                     0),
76       InstrItins(getInstrItineraryForCPU(GPU)),
77       TargetTriple(TT) {
78
79   initializeSubtargetDependencies(TT, GPU, FS);
80
81   if (getGeneration() <= AMDGPUSubtarget::NORTHERN_ISLANDS) {
82     InstrInfo.reset(new R600InstrInfo(*this));
83     TLInfo.reset(new R600TargetLowering(TM));
84   } else {
85     InstrInfo.reset(new SIInstrInfo(*this));
86     TLInfo.reset(new SITargetLowering(TM));
87   }
88 }
89
90 unsigned AMDGPUSubtarget::getStackEntrySize() const {
91   assert(getGeneration() <= NORTHERN_ISLANDS);
92   switch(getWavefrontSize()) {
93   case 16:
94     return 8;
95   case 32:
96     return hasCaymanISA() ? 4 : 8;
97   case 64:
98     return 4;
99   default:
100     llvm_unreachable("Illegal wavefront size.");
101   }
102 }
103
104 unsigned AMDGPUSubtarget::getAmdKernelCodeChipID() const {
105   switch(getGeneration()) {
106   default: llvm_unreachable("ChipID unknown");
107   case SEA_ISLANDS: return 12;
108   }
109 }
110
111 bool AMDGPUSubtarget::isVGPRSpillingEnabled(
112                                        const SIMachineFunctionInfo *MFI) const {
113   return MFI->getShaderType() == ShaderType::COMPUTE || EnableVGPRSpilling;
114 }
115
116 void AMDGPUSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy,
117                                           MachineInstr *begin,
118                                           MachineInstr *end,
119                                           unsigned NumRegionInstrs) const {
120   if (getGeneration() >= SOUTHERN_ISLANDS) {
121
122     // Track register pressure so the scheduler can try to decrease
123     // pressure once register usage is above the threshold defined by
124     // SIRegisterInfo::getRegPressureSetLimit()
125     Policy.ShouldTrackPressure = true;
126
127     // Enabling both top down and bottom up scheduling seems to give us less
128     // register spills than just using one of these approaches on its own.
129     Policy.OnlyTopDown = false;
130     Policy.OnlyBottomUp = false;
131   }
132 }