AMDGPU: Add core backend files for R600/SI codegen v6
[oota-llvm.git] / lib / Target / AMDGPU / AMDILSubtarget.cpp
1 //===- AMDILSubtarget.cpp - AMDIL 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 // This file implements the AMD IL specific subclass of TargetSubtarget.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "AMDILSubtarget.h"
15 #include "AMDIL.h"
16 #include "AMDILDevices.h"
17 #include "AMDILUtilityFunctions.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/StringExtras.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/MC/SubtargetFeature.h"
22
23 using namespace llvm;
24
25 #define GET_SUBTARGETINFO_ENUM
26 #define GET_SUBTARGETINFO_CTOR
27 #define GET_SUBTARGETINFO_TARGET_DESC
28 #include "AMDGPUGenSubtargetInfo.inc"
29
30 AMDILSubtarget::AMDILSubtarget(llvm::StringRef TT, llvm::StringRef CPU, llvm::StringRef FS) : AMDILGenSubtargetInfo( TT, CPU, FS ),
31   mDumpCode(false)
32 {
33   memset(CapsOverride, 0, sizeof(*CapsOverride)
34       * AMDILDeviceInfo::MaxNumberCapabilities);
35   // Default card
36   std::string GPU = "rv770";
37   GPU = CPU;
38   mIs64bit = false;
39   mVersion = 0;
40   SmallVector<StringRef, DEFAULT_VEC_SLOTS> Features;
41   SplitString(FS, Features, ",");
42   mDefaultSize[0] = 64;
43   mDefaultSize[1] = 1;
44   mDefaultSize[2] = 1;
45   std::string newFeatures = "";
46 #if defined(_DEBUG) || defined(DEBUG)
47   bool useTest = false;
48 #endif
49   for (size_t x = 0; x < Features.size(); ++x) {
50     if (Features[x].startswith("+mwgs")) {
51       SmallVector<StringRef, DEFAULT_VEC_SLOTS> sizes;
52       SplitString(Features[x], sizes, "-");
53       size_t mDim = ::atoi(sizes[1].data());
54       if (mDim > 3) {
55         mDim = 3;
56       }
57       for (size_t y = 0; y < mDim; ++y) {
58         mDefaultSize[y] = ::atoi(sizes[y+2].data());
59       }
60 #if defined(_DEBUG) || defined(DEBUG)
61     } else if (!Features[x].compare("test")) {
62       useTest = true;
63 #endif
64     } else if (Features[x].startswith("+cal")) {
65       SmallVector<StringRef, DEFAULT_VEC_SLOTS> version;
66       SplitString(Features[x], version, "=");
67       mVersion = ::atoi(version[1].data());
68     } else {
69       GPU = CPU;
70       if (x > 0) newFeatures += ',';
71       newFeatures += Features[x];
72     }
73   }
74   // If we don't have a version then set it to
75   // -1 which enables everything. This is for
76   // offline devices.
77   if (!mVersion) {
78     mVersion = (uint32_t)-1;
79   }
80   for (int x = 0; x < 3; ++x) {
81     if (!mDefaultSize[x]) {
82       mDefaultSize[x] = 1;
83     }
84   }
85 #if defined(_DEBUG) || defined(DEBUG)
86   if (useTest) {
87     GPU = "kauai";
88   }
89 #endif
90   ParseSubtargetFeatures(GPU, newFeatures);
91 #if defined(_DEBUG) || defined(DEBUG)
92   if (useTest) {
93     GPU = "test";
94   }
95 #endif
96   mDevName = GPU;
97   mDevice = AMDILDeviceInfo::getDeviceFromName(mDevName, this, mIs64bit);
98 }
99 AMDILSubtarget::~AMDILSubtarget()
100 {
101   delete mDevice;
102 }
103 bool
104 AMDILSubtarget::isOverride(AMDILDeviceInfo::Caps caps) const
105 {
106   assert(caps < AMDILDeviceInfo::MaxNumberCapabilities &&
107       "Caps index is out of bounds!");
108   return CapsOverride[caps];
109 }
110 bool
111 AMDILSubtarget::is64bit() const 
112 {
113   return mIs64bit;
114 }
115 bool
116 AMDILSubtarget::isTargetELF() const
117 {
118   return false;
119 }
120 size_t
121 AMDILSubtarget::getDefaultSize(uint32_t dim) const
122 {
123   if (dim > 3) {
124     return 1;
125   } else {
126     return mDefaultSize[dim];
127   }
128 }
129 uint32_t
130 AMDILSubtarget::calVersion() const
131 {
132   return mVersion;
133 }
134
135 AMDILGlobalManager*
136 AMDILSubtarget::getGlobalManager() const
137 {
138   return mGM;
139 }
140 void
141 AMDILSubtarget::setGlobalManager(AMDILGlobalManager *gm) const
142 {
143   mGM = gm;
144 }
145
146 AMDILKernelManager*
147 AMDILSubtarget::getKernelManager() const
148 {
149   return mKM;
150 }
151 void
152 AMDILSubtarget::setKernelManager(AMDILKernelManager *km) const
153 {
154   mKM = km;
155 }
156 std::string
157 AMDILSubtarget::getDataLayout() const
158 {
159     if (!mDevice) {
160         return std::string("e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16"
161                 "-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f80:32:32"
162                 "-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64"
163                 "-v96:128:128-v128:128:128-v192:256:256-v256:256:256"
164                 "-v512:512:512-v1024:1024:1024-v2048:2048:2048-a0:0:64");
165     }
166     return mDevice->getDataLayout();
167 }
168
169 std::string
170 AMDILSubtarget::getDeviceName() const
171 {
172   return mDevName;
173 }
174 const AMDILDevice *
175 AMDILSubtarget::device() const
176 {
177   return mDevice;
178 }