blob: 597e558e663475d5052dd5ad0c9aa61d1fdce114 [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"
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +000021#include "llvm/ADT/SmallString.h"
22
Tom Stellard75aadc22012-12-11 21:25:42 +000023using namespace llvm;
24
Chandler Carruthe96dd892014-04-21 22:55:11 +000025#define DEBUG_TYPE "amdgpu-subtarget"
26
Tom Stellard75aadc22012-12-11 21:25:42 +000027#define GET_SUBTARGETINFO_ENUM
28#define GET_SUBTARGETINFO_TARGET_DESC
29#define GET_SUBTARGETINFO_CTOR
30#include "AMDGPUGenSubtargetInfo.inc"
31
Eric Christopherac4b69e2014-07-25 22:22:39 +000032static std::string computeDataLayout(const AMDGPUSubtarget &ST) {
33 std::string Ret = "e-p:32:32";
34
35 if (ST.is64bit()) {
Matt Arsenault515c24b2014-08-06 00:44:25 +000036 // 32-bit private, local, and region pointers. 64-bit global and constant.
Eric Christopherac4b69e2014-07-25 22:22:39 +000037 Ret += "-p1:64:64-p2:64:64-p3:32:32-p4:64:64-p5:32:32-p24:64:64";
38 }
39
40 Ret += "-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256"
41 "-v512:512-v1024:1024-v2048:2048-n32:64";
42
43 return Ret;
44}
45
46AMDGPUSubtarget &
47AMDGPUSubtarget::initializeSubtargetDependencies(StringRef GPU, StringRef FS) {
48 // Determine default and user-specified characteristics
Matt Arsenaultf171cf22014-07-14 23:40:49 +000049 // On SI+, we want FP64 denormals to be on by default. FP32 denormals can be
50 // enabled, but some instructions do not respect them and they run at the
51 // double precision rate, so don't enable by default.
52 //
53 // We want to be able to turn these off, but making this a subtarget feature
54 // for SI has the unhelpful behavior that it unsets everything else if you
55 // disable it.
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +000056
Matt Arsenaultf171cf22014-07-14 23:40:49 +000057 SmallString<256> FullFS("+promote-alloca,+fp64-denormals,");
Matt Arsenaultd9a23ab2014-07-13 02:08:26 +000058 FullFS += FS;
59
60 ParseSubtargetFeatures(GPU, FullFS);
Tom Stellard2e59a452014-06-13 01:32:00 +000061
Eric Christopherac4b69e2014-07-25 22:22:39 +000062 // FIXME: I don't think think Evergreen has any useful support for
63 // denormals, but should be checked. Should we issue a warning somewhere
64 // if someone tries to enable these?
Tom Stellard2e59a452014-06-13 01:32:00 +000065 if (getGeneration() <= AMDGPUSubtarget::NORTHERN_ISLANDS) {
Matt Arsenaultf171cf22014-07-14 23:40:49 +000066 FP32Denormals = false;
67 FP64Denormals = false;
Eric Christopherac4b69e2014-07-25 22:22:39 +000068 }
69 return *this;
70}
71
72AMDGPUSubtarget::AMDGPUSubtarget(StringRef TT, StringRef GPU, StringRef FS,
73 TargetMachine &TM)
74 : AMDGPUGenSubtargetInfo(TT, GPU, FS), DevName(GPU), Is64bit(false),
75 DumpCode(false), R600ALUInst(false), HasVertexCache(false),
76 TexVTXClauseSize(0), Gen(AMDGPUSubtarget::R600), FP64(false),
77 FP64Denormals(false), FP32Denormals(false), CaymanISA(false),
Matt Arsenault3f981402014-09-15 15:41:53 +000078 FlatAddressSpace(false), EnableIRStructurizer(true),
79 EnablePromoteAlloca(false), EnableIfCvt(true),
Matt Arsenault41033282014-10-10 22:01:59 +000080 EnableLoadStoreOpt(false), WavefrontSize(0), CFALUBug(false), LocalMemorySize(0),
Eric Christopherac4b69e2014-07-25 22:22:39 +000081 DL(computeDataLayout(initializeSubtargetDependencies(GPU, FS))),
82 FrameLowering(TargetFrameLowering::StackGrowsUp,
83 64 * 16, // Maximum stack alignment (long16)
84 0),
Tom Stellard794c8c02014-12-02 17:05:41 +000085 InstrItins(getInstrItineraryForCPU(GPU)),
86 TargetTriple(TT) {
Eric Christopherac4b69e2014-07-25 22:22:39 +000087 if (getGeneration() <= AMDGPUSubtarget::NORTHERN_ISLANDS) {
88 InstrInfo.reset(new R600InstrInfo(*this));
89 TLInfo.reset(new R600TargetLowering(TM));
Tom Stellard2e59a452014-06-13 01:32:00 +000090 } else {
91 InstrInfo.reset(new SIInstrInfo(*this));
Eric Christopherac4b69e2014-07-25 22:22:39 +000092 TLInfo.reset(new SITargetLowering(TM));
Tom Stellard2e59a452014-06-13 01:32:00 +000093 }
Tom Stellard75aadc22012-12-11 21:25:42 +000094}
95
Matt Arsenaultd782d052014-06-27 17:57:00 +000096unsigned AMDGPUSubtarget::getStackEntrySize() const {
Tom Stellarda40f9712014-01-22 21:55:43 +000097 assert(getGeneration() <= NORTHERN_ISLANDS);
98 switch(getWavefrontSize()) {
99 case 16:
100 return 8;
101 case 32:
Matt Arsenaultd782d052014-06-27 17:57:00 +0000102 return hasCaymanISA() ? 4 : 8;
Tom Stellarda40f9712014-01-22 21:55:43 +0000103 case 64:
104 return 4;
105 default:
106 llvm_unreachable("Illegal wavefront size.");
107 }
108}
Tom Stellardb8fd6ef2014-12-02 22:00:07 +0000109
110unsigned AMDGPUSubtarget::getAmdKernelCodeChipID() const {
111 switch(getGeneration()) {
112 default: llvm_unreachable("ChipID unknown");
113 case SEA_ISLANDS: return 12;
114 }
115}