blob: ce9dc4f744dfa7660e408599c573b673e8a61f52 [file] [log] [blame]
Eugene Zelenkod96089b2017-02-14 00:33:36 +00001//===- AMDGPUBaseInfo.cpp - AMDGPU Base encoding information --------------===//
Tom Stellard347ac792015-06-26 21:15:07 +00002//
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//===----------------------------------------------------------------------===//
Eugene Zelenkod96089b2017-02-14 00:33:36 +00009
Eugene Zelenkod96089b2017-02-14 00:33:36 +000010#include "AMDGPUBaseInfo.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000011#include "AMDGPU.h"
Sam Kolton1eeb11b2016-09-09 14:44:04 +000012#include "SIDefines.h"
Eugene Zelenkod96089b2017-02-14 00:33:36 +000013#include "llvm/ADT/StringRef.h"
14#include "llvm/ADT/Triple.h"
Zachary Turner264b5d92017-06-07 03:48:56 +000015#include "llvm/BinaryFormat/ELF.h"
Tom Stellard08efb7e2017-01-27 18:41:14 +000016#include "llvm/CodeGen/MachineMemOperand.h"
Eugene Zelenkod96089b2017-02-14 00:33:36 +000017#include "llvm/IR/Attributes.h"
Tom Stellard08efb7e2017-01-27 18:41:14 +000018#include "llvm/IR/Constants.h"
Tom Stellardac00eb52015-12-15 16:26:16 +000019#include "llvm/IR/Function.h"
Tom Stellarde3b5aea2015-12-02 17:00:42 +000020#include "llvm/IR/GlobalValue.h"
Eugene Zelenkod96089b2017-02-14 00:33:36 +000021#include "llvm/IR/Instruction.h"
Tom Stellardca166212017-01-30 21:56:46 +000022#include "llvm/IR/LLVMContext.h"
Yaxun Liu1a14bfa2017-03-27 14:04:01 +000023#include "llvm/IR/Module.h"
Tom Stellarde135ffd2015-09-25 21:41:28 +000024#include "llvm/MC/MCContext.h"
Eugene Zelenkod96089b2017-02-14 00:33:36 +000025#include "llvm/MC/MCInstrDesc.h"
Sam Kolton1eeb11b2016-09-09 14:44:04 +000026#include "llvm/MC/MCRegisterInfo.h"
Tom Stellarde135ffd2015-09-25 21:41:28 +000027#include "llvm/MC/MCSectionELF.h"
Tom Stellard2b65ed32015-12-21 18:44:27 +000028#include "llvm/MC/MCSubtargetInfo.h"
Tom Stellard347ac792015-06-26 21:15:07 +000029#include "llvm/MC/SubtargetFeature.h"
Eugene Zelenkod96089b2017-02-14 00:33:36 +000030#include "llvm/Support/Casting.h"
Eugene Zelenkod96089b2017-02-14 00:33:36 +000031#include "llvm/Support/ErrorHandling.h"
32#include "llvm/Support/MathExtras.h"
33#include <algorithm>
34#include <cassert>
35#include <cstdint>
36#include <cstring>
37#include <utility>
Tom Stellard347ac792015-06-26 21:15:07 +000038
Matt Arsenault678e1112017-04-10 17:58:06 +000039#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
Tom Stellard347ac792015-06-26 21:15:07 +000040
Sam Koltona3ec5c12016-10-07 14:46:06 +000041#define GET_INSTRINFO_NAMED_OPS
Sam Koltona3ec5c12016-10-07 14:46:06 +000042#include "AMDGPUGenInstrInfo.inc"
43#undef GET_INSTRINFO_NAMED_OPS
Sam Koltona3ec5c12016-10-07 14:46:06 +000044
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +000045namespace {
46
47/// \returns Bit mask for given bit \p Shift and bit \p Width.
48unsigned getBitMask(unsigned Shift, unsigned Width) {
49 return ((1 << Width) - 1) << Shift;
50}
51
52/// \brief Packs \p Src into \p Dst for given bit \p Shift and bit \p Width.
53///
54/// \returns Packed \p Dst.
55unsigned packBits(unsigned Src, unsigned Dst, unsigned Shift, unsigned Width) {
56 Dst &= ~(1 << Shift) & ~getBitMask(Shift, Width);
57 Dst |= (Src << Shift) & getBitMask(Shift, Width);
58 return Dst;
59}
60
61/// \brief Unpacks bits from \p Src for given bit \p Shift and bit \p Width.
62///
63/// \returns Unpacked bits.
64unsigned unpackBits(unsigned Src, unsigned Shift, unsigned Width) {
65 return (Src & getBitMask(Shift, Width)) >> Shift;
66}
67
Matt Arsenaulte823d922017-02-18 18:29:53 +000068/// \returns Vmcnt bit shift (lower bits).
69unsigned getVmcntBitShiftLo() { return 0; }
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +000070
Matt Arsenaulte823d922017-02-18 18:29:53 +000071/// \returns Vmcnt bit width (lower bits).
72unsigned getVmcntBitWidthLo() { return 4; }
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +000073
74/// \returns Expcnt bit shift.
75unsigned getExpcntBitShift() { return 4; }
76
77/// \returns Expcnt bit width.
78unsigned getExpcntBitWidth() { return 3; }
79
80/// \returns Lgkmcnt bit shift.
81unsigned getLgkmcntBitShift() { return 8; }
82
83/// \returns Lgkmcnt bit width.
84unsigned getLgkmcntBitWidth() { return 4; }
85
Matt Arsenaulte823d922017-02-18 18:29:53 +000086/// \returns Vmcnt bit shift (higher bits).
87unsigned getVmcntBitShiftHi() { return 14; }
88
89/// \returns Vmcnt bit width (higher bits).
90unsigned getVmcntBitWidthHi() { return 2; }
91
Eugene Zelenkod96089b2017-02-14 00:33:36 +000092} // end namespace anonymous
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +000093
Tom Stellard347ac792015-06-26 21:15:07 +000094namespace llvm {
Konstantin Zhuravlyov3d1cc882017-04-21 19:45:22 +000095
96static cl::opt<bool> EnablePackedInlinableLiterals(
97 "enable-packed-inlinable-literals",
98 cl::desc("Enable packed inlinable literals (v2f16, v2i16)"),
99 cl::init(false));
100
Tom Stellard347ac792015-06-26 21:15:07 +0000101namespace AMDGPU {
102
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000103namespace IsaInfo {
Tom Stellard347ac792015-06-26 21:15:07 +0000104
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000105IsaVersion getIsaVersion(const FeatureBitset &Features) {
Wei Ding7c3e5112017-06-10 03:53:19 +0000106 // SI.
107 if (Features.test(FeatureISAVersion6_0_0))
108 return {6, 0, 0};
109 if (Features.test(FeatureISAVersion6_0_1))
110 return {6, 0, 1};
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000111 // CI.
Tom Stellard347ac792015-06-26 21:15:07 +0000112 if (Features.test(FeatureISAVersion7_0_0))
113 return {7, 0, 0};
Tom Stellard347ac792015-06-26 21:15:07 +0000114 if (Features.test(FeatureISAVersion7_0_1))
115 return {7, 0, 1};
Yaxun Liu94add852016-10-26 16:37:56 +0000116 if (Features.test(FeatureISAVersion7_0_2))
117 return {7, 0, 2};
Wei Ding7c3e5112017-06-10 03:53:19 +0000118 if (Features.test(FeatureISAVersion7_0_3))
119 return {7, 0, 3};
Yaxun Liu94add852016-10-26 16:37:56 +0000120
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000121 // VI.
Tom Stellard347ac792015-06-26 21:15:07 +0000122 if (Features.test(FeatureISAVersion8_0_0))
123 return {8, 0, 0};
Tom Stellard347ac792015-06-26 21:15:07 +0000124 if (Features.test(FeatureISAVersion8_0_1))
125 return {8, 0, 1};
Changpeng Fang98317d22016-10-11 16:00:47 +0000126 if (Features.test(FeatureISAVersion8_0_2))
127 return {8, 0, 2};
Changpeng Fangc16be002016-01-13 20:39:25 +0000128 if (Features.test(FeatureISAVersion8_0_3))
129 return {8, 0, 3};
Yaxun Liu94add852016-10-26 16:37:56 +0000130 if (Features.test(FeatureISAVersion8_0_4))
131 return {8, 0, 4};
Yaxun Liu94add852016-10-26 16:37:56 +0000132 if (Features.test(FeatureISAVersion8_1_0))
133 return {8, 1, 0};
134
Matt Arsenaulte823d922017-02-18 18:29:53 +0000135 // GFX9.
136 if (Features.test(FeatureISAVersion9_0_0))
137 return {9, 0, 0};
138 if (Features.test(FeatureISAVersion9_0_1))
139 return {9, 0, 1};
Wei Ding7c3e5112017-06-10 03:53:19 +0000140 if (Features.test(FeatureISAVersion9_0_2))
141 return {9, 0, 2};
142 if (Features.test(FeatureISAVersion9_0_3))
143 return {9, 0, 3};
Matt Arsenaulte823d922017-02-18 18:29:53 +0000144
Konstantin Zhuravlyov94b3b472017-07-11 17:57:41 +0000145 if (!Features.test(FeatureGCN) || Features.test(FeatureSouthernIslands))
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000146 return {0, 0, 0};
147 return {7, 0, 0};
Tom Stellard347ac792015-06-26 21:15:07 +0000148}
149
Konstantin Zhuravlyov9c05b2b2017-10-14 15:40:33 +0000150void streamIsaVersion(const MCSubtargetInfo *STI, raw_ostream &Stream) {
151 auto TargetTriple = STI->getTargetTriple();
152 auto ISAVersion = IsaInfo::getIsaVersion(STI->getFeatureBits());
153
154 Stream << TargetTriple.getArchName() << '-'
155 << TargetTriple.getVendorName() << '-'
156 << TargetTriple.getOSName() << '-'
157 << TargetTriple.getEnvironmentName() << '-'
158 << "gfx"
159 << ISAVersion.Major
160 << ISAVersion.Minor
161 << ISAVersion.Stepping;
162 Stream.flush();
163}
164
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000165unsigned getWavefrontSize(const FeatureBitset &Features) {
166 if (Features.test(FeatureWavefrontSize16))
167 return 16;
168 if (Features.test(FeatureWavefrontSize32))
169 return 32;
170
171 return 64;
172}
173
174unsigned getLocalMemorySize(const FeatureBitset &Features) {
175 if (Features.test(FeatureLocalMemorySize32768))
176 return 32768;
177 if (Features.test(FeatureLocalMemorySize65536))
178 return 65536;
179
180 return 0;
181}
182
183unsigned getEUsPerCU(const FeatureBitset &Features) {
184 return 4;
185}
186
187unsigned getMaxWorkGroupsPerCU(const FeatureBitset &Features,
188 unsigned FlatWorkGroupSize) {
189 if (!Features.test(FeatureGCN))
190 return 8;
Stanislav Mekhanoshin19f98c62017-02-15 01:03:59 +0000191 unsigned N = getWavesPerWorkGroup(Features, FlatWorkGroupSize);
192 if (N == 1)
193 return 40;
194 N = 40 / N;
195 return std::min(N, 16u);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000196}
197
198unsigned getMaxWavesPerCU(const FeatureBitset &Features) {
199 return getMaxWavesPerEU(Features) * getEUsPerCU(Features);
200}
201
202unsigned getMaxWavesPerCU(const FeatureBitset &Features,
203 unsigned FlatWorkGroupSize) {
204 return getWavesPerWorkGroup(Features, FlatWorkGroupSize);
205}
206
207unsigned getMinWavesPerEU(const FeatureBitset &Features) {
208 return 1;
209}
210
211unsigned getMaxWavesPerEU(const FeatureBitset &Features) {
212 if (!Features.test(FeatureGCN))
213 return 8;
214 // FIXME: Need to take scratch memory into account.
215 return 10;
216}
217
218unsigned getMaxWavesPerEU(const FeatureBitset &Features,
219 unsigned FlatWorkGroupSize) {
220 return alignTo(getMaxWavesPerCU(Features, FlatWorkGroupSize),
221 getEUsPerCU(Features)) / getEUsPerCU(Features);
222}
223
224unsigned getMinFlatWorkGroupSize(const FeatureBitset &Features) {
225 return 1;
226}
227
228unsigned getMaxFlatWorkGroupSize(const FeatureBitset &Features) {
229 return 2048;
230}
231
232unsigned getWavesPerWorkGroup(const FeatureBitset &Features,
233 unsigned FlatWorkGroupSize) {
234 return alignTo(FlatWorkGroupSize, getWavefrontSize(Features)) /
235 getWavefrontSize(Features);
236}
237
238unsigned getSGPRAllocGranule(const FeatureBitset &Features) {
239 IsaVersion Version = getIsaVersion(Features);
240 if (Version.Major >= 8)
241 return 16;
242 return 8;
243}
244
245unsigned getSGPREncodingGranule(const FeatureBitset &Features) {
246 return 8;
247}
248
249unsigned getTotalNumSGPRs(const FeatureBitset &Features) {
250 IsaVersion Version = getIsaVersion(Features);
251 if (Version.Major >= 8)
252 return 800;
253 return 512;
254}
255
256unsigned getAddressableNumSGPRs(const FeatureBitset &Features) {
257 if (Features.test(FeatureSGPRInitBug))
258 return FIXED_NUM_SGPRS_FOR_INIT_BUG;
259
260 IsaVersion Version = getIsaVersion(Features);
261 if (Version.Major >= 8)
262 return 102;
263 return 104;
264}
265
266unsigned getMinNumSGPRs(const FeatureBitset &Features, unsigned WavesPerEU) {
Konstantin Zhuravlyovfd871372017-02-09 21:33:23 +0000267 assert(WavesPerEU != 0);
268
269 if (WavesPerEU >= getMaxWavesPerEU(Features))
270 return 0;
271 unsigned MinNumSGPRs =
272 alignDown(getTotalNumSGPRs(Features) / (WavesPerEU + 1),
273 getSGPRAllocGranule(Features)) + 1;
274 return std::min(MinNumSGPRs, getAddressableNumSGPRs(Features));
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000275}
276
277unsigned getMaxNumSGPRs(const FeatureBitset &Features, unsigned WavesPerEU,
278 bool Addressable) {
Konstantin Zhuravlyovfd871372017-02-09 21:33:23 +0000279 assert(WavesPerEU != 0);
280
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000281 IsaVersion Version = getIsaVersion(Features);
Konstantin Zhuravlyovfd871372017-02-09 21:33:23 +0000282 unsigned MaxNumSGPRs = alignDown(getTotalNumSGPRs(Features) / WavesPerEU,
283 getSGPRAllocGranule(Features));
284 unsigned AddressableNumSGPRs = getAddressableNumSGPRs(Features);
285 if (Version.Major >= 8 && !Addressable)
286 AddressableNumSGPRs = 112;
287 return std::min(MaxNumSGPRs, AddressableNumSGPRs);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000288}
289
290unsigned getVGPRAllocGranule(const FeatureBitset &Features) {
291 return 4;
292}
293
294unsigned getVGPREncodingGranule(const FeatureBitset &Features) {
295 return getVGPRAllocGranule(Features);
296}
297
298unsigned getTotalNumVGPRs(const FeatureBitset &Features) {
299 return 256;
300}
301
302unsigned getAddressableNumVGPRs(const FeatureBitset &Features) {
303 return getTotalNumVGPRs(Features);
304}
305
306unsigned getMinNumVGPRs(const FeatureBitset &Features, unsigned WavesPerEU) {
Konstantin Zhuravlyovfd871372017-02-09 21:33:23 +0000307 assert(WavesPerEU != 0);
308
309 if (WavesPerEU >= getMaxWavesPerEU(Features))
310 return 0;
311 unsigned MinNumVGPRs =
312 alignDown(getTotalNumVGPRs(Features) / (WavesPerEU + 1),
313 getVGPRAllocGranule(Features)) + 1;
314 return std::min(MinNumVGPRs, getAddressableNumVGPRs(Features));
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000315}
316
317unsigned getMaxNumVGPRs(const FeatureBitset &Features, unsigned WavesPerEU) {
Konstantin Zhuravlyovfd871372017-02-09 21:33:23 +0000318 assert(WavesPerEU != 0);
319
320 unsigned MaxNumVGPRs = alignDown(getTotalNumVGPRs(Features) / WavesPerEU,
321 getVGPRAllocGranule(Features));
322 unsigned AddressableNumVGPRs = getAddressableNumVGPRs(Features);
323 return std::min(MaxNumVGPRs, AddressableNumVGPRs);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000324}
325
Eugene Zelenkod96089b2017-02-14 00:33:36 +0000326} // end namespace IsaInfo
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000327
Tom Stellardff7416b2015-06-26 21:58:31 +0000328void initDefaultAMDKernelCodeT(amd_kernel_code_t &Header,
329 const FeatureBitset &Features) {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000330 IsaInfo::IsaVersion ISA = IsaInfo::getIsaVersion(Features);
Tom Stellardff7416b2015-06-26 21:58:31 +0000331
332 memset(&Header, 0, sizeof(Header));
333
334 Header.amd_kernel_code_version_major = 1;
Konstantin Zhuravlyov182e9cc2017-02-28 17:17:52 +0000335 Header.amd_kernel_code_version_minor = 1;
Tom Stellardff7416b2015-06-26 21:58:31 +0000336 Header.amd_machine_kind = 1; // AMD_MACHINE_KIND_AMDGPU
337 Header.amd_machine_version_major = ISA.Major;
338 Header.amd_machine_version_minor = ISA.Minor;
339 Header.amd_machine_version_stepping = ISA.Stepping;
340 Header.kernel_code_entry_byte_offset = sizeof(Header);
341 // wavefront_size is specified as a power of 2: 2^6 = 64 threads.
342 Header.wavefront_size = 6;
Matt Arsenault5d910192017-01-25 20:21:57 +0000343
344 // If the code object does not support indirect functions, then the value must
345 // be 0xffffffff.
346 Header.call_convention = -1;
347
Tom Stellardff7416b2015-06-26 21:58:31 +0000348 // These alignment values are specified in powers of two, so alignment =
349 // 2^n. The minimum alignment is 2^4 = 16.
350 Header.kernarg_segment_alignment = 4;
351 Header.group_segment_alignment = 4;
352 Header.private_segment_alignment = 4;
353}
354
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000355bool isGroupSegment(const GlobalValue *GV, AMDGPUAS AS) {
356 return GV->getType()->getAddressSpace() == AS.LOCAL_ADDRESS;
Tom Stellarde3b5aea2015-12-02 17:00:42 +0000357}
358
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000359bool isGlobalSegment(const GlobalValue *GV, AMDGPUAS AS) {
360 return GV->getType()->getAddressSpace() == AS.GLOBAL_ADDRESS;
Tom Stellard00f2f912015-12-02 19:47:57 +0000361}
362
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000363bool isReadOnlySegment(const GlobalValue *GV, AMDGPUAS AS) {
364 return GV->getType()->getAddressSpace() == AS.CONSTANT_ADDRESS;
Tom Stellard00f2f912015-12-02 19:47:57 +0000365}
366
Konstantin Zhuravlyov08326b62016-10-20 18:12:38 +0000367bool shouldEmitConstantsToTextSection(const Triple &TT) {
368 return TT.getOS() != Triple::AMDHSA;
369}
370
Matt Arsenault83002722016-05-12 02:45:18 +0000371int getIntegerAttribute(const Function &F, StringRef Name, int Default) {
Marek Olsakfccabaf2016-01-13 11:45:36 +0000372 Attribute A = F.getFnAttribute(Name);
Matt Arsenault83002722016-05-12 02:45:18 +0000373 int Result = Default;
Tom Stellardac00eb52015-12-15 16:26:16 +0000374
375 if (A.isStringAttribute()) {
376 StringRef Str = A.getValueAsString();
Marek Olsakfccabaf2016-01-13 11:45:36 +0000377 if (Str.getAsInteger(0, Result)) {
Tom Stellardac00eb52015-12-15 16:26:16 +0000378 LLVMContext &Ctx = F.getContext();
Matt Arsenault83002722016-05-12 02:45:18 +0000379 Ctx.emitError("can't parse integer attribute " + Name);
Tom Stellardac00eb52015-12-15 16:26:16 +0000380 }
381 }
Matt Arsenault83002722016-05-12 02:45:18 +0000382
Marek Olsakfccabaf2016-01-13 11:45:36 +0000383 return Result;
384}
385
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000386std::pair<int, int> getIntegerPairAttribute(const Function &F,
387 StringRef Name,
388 std::pair<int, int> Default,
389 bool OnlyFirstRequired) {
390 Attribute A = F.getFnAttribute(Name);
391 if (!A.isStringAttribute())
392 return Default;
393
394 LLVMContext &Ctx = F.getContext();
395 std::pair<int, int> Ints = Default;
396 std::pair<StringRef, StringRef> Strs = A.getValueAsString().split(',');
397 if (Strs.first.trim().getAsInteger(0, Ints.first)) {
398 Ctx.emitError("can't parse first integer attribute " + Name);
399 return Default;
400 }
401 if (Strs.second.trim().getAsInteger(0, Ints.second)) {
Eugene Zelenkod96089b2017-02-14 00:33:36 +0000402 if (!OnlyFirstRequired || !Strs.second.trim().empty()) {
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000403 Ctx.emitError("can't parse second integer attribute " + Name);
404 return Default;
405 }
406 }
407
408 return Ints;
Tom Stellard79a1fd72016-04-14 16:27:07 +0000409}
410
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000411unsigned getVmcntBitMask(const IsaInfo::IsaVersion &Version) {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000412 unsigned VmcntLo = (1 << getVmcntBitWidthLo()) - 1;
413 if (Version.Major < 9)
414 return VmcntLo;
415
416 unsigned VmcntHi = ((1 << getVmcntBitWidthHi()) - 1) << getVmcntBitWidthLo();
417 return VmcntLo | VmcntHi;
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000418}
419
420unsigned getExpcntBitMask(const IsaInfo::IsaVersion &Version) {
421 return (1 << getExpcntBitWidth()) - 1;
422}
423
424unsigned getLgkmcntBitMask(const IsaInfo::IsaVersion &Version) {
425 return (1 << getLgkmcntBitWidth()) - 1;
426}
427
428unsigned getWaitcntBitMask(const IsaInfo::IsaVersion &Version) {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000429 unsigned VmcntLo = getBitMask(getVmcntBitShiftLo(), getVmcntBitWidthLo());
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000430 unsigned Expcnt = getBitMask(getExpcntBitShift(), getExpcntBitWidth());
431 unsigned Lgkmcnt = getBitMask(getLgkmcntBitShift(), getLgkmcntBitWidth());
Matt Arsenaulte823d922017-02-18 18:29:53 +0000432 unsigned Waitcnt = VmcntLo | Expcnt | Lgkmcnt;
433 if (Version.Major < 9)
434 return Waitcnt;
435
436 unsigned VmcntHi = getBitMask(getVmcntBitShiftHi(), getVmcntBitWidthHi());
437 return Waitcnt | VmcntHi;
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +0000438}
439
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000440unsigned decodeVmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt) {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000441 unsigned VmcntLo =
442 unpackBits(Waitcnt, getVmcntBitShiftLo(), getVmcntBitWidthLo());
443 if (Version.Major < 9)
444 return VmcntLo;
445
446 unsigned VmcntHi =
447 unpackBits(Waitcnt, getVmcntBitShiftHi(), getVmcntBitWidthHi());
448 VmcntHi <<= getVmcntBitWidthLo();
449 return VmcntLo | VmcntHi;
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +0000450}
451
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000452unsigned decodeExpcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt) {
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000453 return unpackBits(Waitcnt, getExpcntBitShift(), getExpcntBitWidth());
454}
455
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000456unsigned decodeLgkmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt) {
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000457 return unpackBits(Waitcnt, getLgkmcntBitShift(), getLgkmcntBitWidth());
458}
459
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000460void decodeWaitcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt,
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000461 unsigned &Vmcnt, unsigned &Expcnt, unsigned &Lgkmcnt) {
462 Vmcnt = decodeVmcnt(Version, Waitcnt);
463 Expcnt = decodeExpcnt(Version, Waitcnt);
464 Lgkmcnt = decodeLgkmcnt(Version, Waitcnt);
465}
466
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000467unsigned encodeVmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt,
468 unsigned Vmcnt) {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000469 Waitcnt =
470 packBits(Vmcnt, Waitcnt, getVmcntBitShiftLo(), getVmcntBitWidthLo());
471 if (Version.Major < 9)
472 return Waitcnt;
473
474 Vmcnt >>= getVmcntBitWidthLo();
475 return packBits(Vmcnt, Waitcnt, getVmcntBitShiftHi(), getVmcntBitWidthHi());
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000476}
477
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000478unsigned encodeExpcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt,
479 unsigned Expcnt) {
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000480 return packBits(Expcnt, Waitcnt, getExpcntBitShift(), getExpcntBitWidth());
481}
482
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000483unsigned encodeLgkmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt,
484 unsigned Lgkmcnt) {
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000485 return packBits(Lgkmcnt, Waitcnt, getLgkmcntBitShift(), getLgkmcntBitWidth());
486}
487
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000488unsigned encodeWaitcnt(const IsaInfo::IsaVersion &Version,
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000489 unsigned Vmcnt, unsigned Expcnt, unsigned Lgkmcnt) {
Konstantin Zhuravlyov31dbb032017-01-06 17:23:21 +0000490 unsigned Waitcnt = getWaitcntBitMask(Version);
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000491 Waitcnt = encodeVmcnt(Version, Waitcnt, Vmcnt);
492 Waitcnt = encodeExpcnt(Version, Waitcnt, Expcnt);
493 Waitcnt = encodeLgkmcnt(Version, Waitcnt, Lgkmcnt);
494 return Waitcnt;
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +0000495}
496
Marek Olsakfccabaf2016-01-13 11:45:36 +0000497unsigned getInitialPSInputAddr(const Function &F) {
498 return getIntegerAttribute(F, "InitialPSInputAddr", 0);
Tom Stellardac00eb52015-12-15 16:26:16 +0000499}
500
Nicolai Haehnledf3a20c2016-04-06 19:40:20 +0000501bool isShader(CallingConv::ID cc) {
502 switch(cc) {
503 case CallingConv::AMDGPU_VS:
Tim Renoufef1ae8f2017-09-29 09:51:22 +0000504 case CallingConv::AMDGPU_LS:
Marek Olsaka302a7362017-05-02 15:41:10 +0000505 case CallingConv::AMDGPU_HS:
Tim Renoufef1ae8f2017-09-29 09:51:22 +0000506 case CallingConv::AMDGPU_ES:
Nicolai Haehnledf3a20c2016-04-06 19:40:20 +0000507 case CallingConv::AMDGPU_GS:
508 case CallingConv::AMDGPU_PS:
509 case CallingConv::AMDGPU_CS:
510 return true;
511 default:
512 return false;
513 }
514}
515
516bool isCompute(CallingConv::ID cc) {
517 return !isShader(cc) || cc == CallingConv::AMDGPU_CS;
518}
519
Matt Arsenaulte622dc32017-04-11 22:29:24 +0000520bool isEntryFunctionCC(CallingConv::ID CC) {
Matt Arsenault2b1f9aa2017-05-17 21:56:25 +0000521 switch (CC) {
522 case CallingConv::AMDGPU_KERNEL:
523 case CallingConv::SPIR_KERNEL:
524 case CallingConv::AMDGPU_VS:
525 case CallingConv::AMDGPU_GS:
526 case CallingConv::AMDGPU_PS:
527 case CallingConv::AMDGPU_CS:
Tim Renoufef1ae8f2017-09-29 09:51:22 +0000528 case CallingConv::AMDGPU_ES:
Matt Arsenault2b1f9aa2017-05-17 21:56:25 +0000529 case CallingConv::AMDGPU_HS:
Tim Renoufef1ae8f2017-09-29 09:51:22 +0000530 case CallingConv::AMDGPU_LS:
Matt Arsenault2b1f9aa2017-05-17 21:56:25 +0000531 return true;
532 default:
533 return false;
534 }
Matt Arsenaulte622dc32017-04-11 22:29:24 +0000535}
536
Tom Stellard2b65ed32015-12-21 18:44:27 +0000537bool isSI(const MCSubtargetInfo &STI) {
538 return STI.getFeatureBits()[AMDGPU::FeatureSouthernIslands];
539}
540
541bool isCI(const MCSubtargetInfo &STI) {
542 return STI.getFeatureBits()[AMDGPU::FeatureSeaIslands];
543}
544
545bool isVI(const MCSubtargetInfo &STI) {
546 return STI.getFeatureBits()[AMDGPU::FeatureVolcanicIslands];
547}
548
Sam Koltonf7659d712017-05-23 10:08:55 +0000549bool isGFX9(const MCSubtargetInfo &STI) {
550 return STI.getFeatureBits()[AMDGPU::FeatureGFX9];
551}
552
Matt Arsenault8728c5f2017-08-07 14:58:04 +0000553bool isGCN3Encoding(const MCSubtargetInfo &STI) {
554 return STI.getFeatureBits()[AMDGPU::FeatureGCN3Encoding];
555}
556
Sam Koltonf7659d712017-05-23 10:08:55 +0000557bool isSGPR(unsigned Reg, const MCRegisterInfo* TRI) {
558 const MCRegisterClass SGPRClass = TRI->getRegClass(AMDGPU::SReg_32RegClassID);
559 const unsigned FirstSubReg = TRI->getSubReg(Reg, 1);
560 return SGPRClass.contains(FirstSubReg != 0 ? FirstSubReg : Reg) ||
561 Reg == AMDGPU::SCC;
562}
563
Dmitry Preobrazhenskydc4ac822017-06-21 14:41:34 +0000564bool isRegIntersect(unsigned Reg0, unsigned Reg1, const MCRegisterInfo* TRI) {
Dmitry Preobrazhensky00deef82017-07-18 11:14:02 +0000565 for (MCRegAliasIterator R(Reg0, TRI, true); R.isValid(); ++R) {
566 if (*R == Reg1) return true;
Dmitry Preobrazhenskydc4ac822017-06-21 14:41:34 +0000567 }
Dmitry Preobrazhenskydc4ac822017-06-21 14:41:34 +0000568 return false;
569}
570
Tom Stellard2b65ed32015-12-21 18:44:27 +0000571unsigned getMCReg(unsigned Reg, const MCSubtargetInfo &STI) {
572
573 switch(Reg) {
574 default: break;
575 case AMDGPU::FLAT_SCR:
576 assert(!isSI(STI));
577 return isCI(STI) ? AMDGPU::FLAT_SCR_ci : AMDGPU::FLAT_SCR_vi;
578
579 case AMDGPU::FLAT_SCR_LO:
580 assert(!isSI(STI));
581 return isCI(STI) ? AMDGPU::FLAT_SCR_LO_ci : AMDGPU::FLAT_SCR_LO_vi;
582
583 case AMDGPU::FLAT_SCR_HI:
584 assert(!isSI(STI));
585 return isCI(STI) ? AMDGPU::FLAT_SCR_HI_ci : AMDGPU::FLAT_SCR_HI_vi;
586 }
587 return Reg;
588}
589
Dmitry Preobrazhensky03880f82017-03-03 14:31:06 +0000590unsigned mc2PseudoReg(unsigned Reg) {
591 switch (Reg) {
592 case AMDGPU::FLAT_SCR_ci:
593 case AMDGPU::FLAT_SCR_vi:
594 return FLAT_SCR;
595
596 case AMDGPU::FLAT_SCR_LO_ci:
597 case AMDGPU::FLAT_SCR_LO_vi:
598 return AMDGPU::FLAT_SCR_LO;
599
600 case AMDGPU::FLAT_SCR_HI_ci:
601 case AMDGPU::FLAT_SCR_HI_vi:
602 return AMDGPU::FLAT_SCR_HI;
603
604 default:
605 return Reg;
606 }
607}
608
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000609bool isSISrcOperand(const MCInstrDesc &Desc, unsigned OpNo) {
Artem Tamazov43b61562017-02-03 12:47:30 +0000610 assert(OpNo < Desc.NumOperands);
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000611 unsigned OpType = Desc.OpInfo[OpNo].OperandType;
Matt Arsenault4bd72362016-12-10 00:39:12 +0000612 return OpType >= AMDGPU::OPERAND_SRC_FIRST &&
613 OpType <= AMDGPU::OPERAND_SRC_LAST;
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000614}
615
616bool isSISrcFPOperand(const MCInstrDesc &Desc, unsigned OpNo) {
Artem Tamazov43b61562017-02-03 12:47:30 +0000617 assert(OpNo < Desc.NumOperands);
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000618 unsigned OpType = Desc.OpInfo[OpNo].OperandType;
Matt Arsenault4bd72362016-12-10 00:39:12 +0000619 switch (OpType) {
620 case AMDGPU::OPERAND_REG_IMM_FP32:
621 case AMDGPU::OPERAND_REG_IMM_FP64:
622 case AMDGPU::OPERAND_REG_IMM_FP16:
623 case AMDGPU::OPERAND_REG_INLINE_C_FP32:
624 case AMDGPU::OPERAND_REG_INLINE_C_FP64:
625 case AMDGPU::OPERAND_REG_INLINE_C_FP16:
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000626 case AMDGPU::OPERAND_REG_INLINE_C_V2FP16:
Matt Arsenault4bd72362016-12-10 00:39:12 +0000627 return true;
628 default:
629 return false;
630 }
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000631}
632
633bool isSISrcInlinableOperand(const MCInstrDesc &Desc, unsigned OpNo) {
Artem Tamazov43b61562017-02-03 12:47:30 +0000634 assert(OpNo < Desc.NumOperands);
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000635 unsigned OpType = Desc.OpInfo[OpNo].OperandType;
Matt Arsenault4bd72362016-12-10 00:39:12 +0000636 return OpType >= AMDGPU::OPERAND_REG_INLINE_C_FIRST &&
637 OpType <= AMDGPU::OPERAND_REG_INLINE_C_LAST;
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000638}
639
Krzysztof Parzyszekc8715502016-10-19 17:40:36 +0000640// Avoid using MCRegisterClass::getSize, since that function will go away
641// (move from MC* level to Target* level). Return size in bits.
Tom Stellardb133fbb2016-10-27 23:05:31 +0000642unsigned getRegBitWidth(unsigned RCID) {
643 switch (RCID) {
Krzysztof Parzyszekc8715502016-10-19 17:40:36 +0000644 case AMDGPU::SGPR_32RegClassID:
645 case AMDGPU::VGPR_32RegClassID:
646 case AMDGPU::VS_32RegClassID:
647 case AMDGPU::SReg_32RegClassID:
648 case AMDGPU::SReg_32_XM0RegClassID:
649 return 32;
650 case AMDGPU::SGPR_64RegClassID:
651 case AMDGPU::VS_64RegClassID:
652 case AMDGPU::SReg_64RegClassID:
653 case AMDGPU::VReg_64RegClassID:
654 return 64;
655 case AMDGPU::VReg_96RegClassID:
656 return 96;
657 case AMDGPU::SGPR_128RegClassID:
658 case AMDGPU::SReg_128RegClassID:
659 case AMDGPU::VReg_128RegClassID:
660 return 128;
661 case AMDGPU::SReg_256RegClassID:
662 case AMDGPU::VReg_256RegClassID:
663 return 256;
664 case AMDGPU::SReg_512RegClassID:
665 case AMDGPU::VReg_512RegClassID:
666 return 512;
667 default:
668 llvm_unreachable("Unexpected register class");
669 }
670}
671
Tom Stellardb133fbb2016-10-27 23:05:31 +0000672unsigned getRegBitWidth(const MCRegisterClass &RC) {
673 return getRegBitWidth(RC.getID());
674}
675
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000676unsigned getRegOperandSize(const MCRegisterInfo *MRI, const MCInstrDesc &Desc,
677 unsigned OpNo) {
Artem Tamazov43b61562017-02-03 12:47:30 +0000678 assert(OpNo < Desc.NumOperands);
Krzysztof Parzyszekc8715502016-10-19 17:40:36 +0000679 unsigned RCID = Desc.OpInfo[OpNo].RegClass;
680 return getRegBitWidth(MRI->getRegClass(RCID)) / 8;
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000681}
682
Matt Arsenault26faed32016-12-05 22:26:17 +0000683bool isInlinableLiteral64(int64_t Literal, bool HasInv2Pi) {
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000684 if (Literal >= -16 && Literal <= 64)
685 return true;
686
Matt Arsenault26faed32016-12-05 22:26:17 +0000687 uint64_t Val = static_cast<uint64_t>(Literal);
688 return (Val == DoubleToBits(0.0)) ||
689 (Val == DoubleToBits(1.0)) ||
690 (Val == DoubleToBits(-1.0)) ||
691 (Val == DoubleToBits(0.5)) ||
692 (Val == DoubleToBits(-0.5)) ||
693 (Val == DoubleToBits(2.0)) ||
694 (Val == DoubleToBits(-2.0)) ||
695 (Val == DoubleToBits(4.0)) ||
696 (Val == DoubleToBits(-4.0)) ||
697 (Val == 0x3fc45f306dc9c882 && HasInv2Pi);
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000698}
699
Matt Arsenault26faed32016-12-05 22:26:17 +0000700bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi) {
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000701 if (Literal >= -16 && Literal <= 64)
702 return true;
703
Matt Arsenault4bd72362016-12-10 00:39:12 +0000704 // The actual type of the operand does not seem to matter as long
705 // as the bits match one of the inline immediate values. For example:
706 //
707 // -nan has the hexadecimal encoding of 0xfffffffe which is -2 in decimal,
708 // so it is a legal inline immediate.
709 //
710 // 1065353216 has the hexadecimal encoding 0x3f800000 which is 1.0f in
711 // floating-point, so it is a legal inline immediate.
712
Matt Arsenault26faed32016-12-05 22:26:17 +0000713 uint32_t Val = static_cast<uint32_t>(Literal);
714 return (Val == FloatToBits(0.0f)) ||
715 (Val == FloatToBits(1.0f)) ||
716 (Val == FloatToBits(-1.0f)) ||
717 (Val == FloatToBits(0.5f)) ||
718 (Val == FloatToBits(-0.5f)) ||
719 (Val == FloatToBits(2.0f)) ||
720 (Val == FloatToBits(-2.0f)) ||
721 (Val == FloatToBits(4.0f)) ||
722 (Val == FloatToBits(-4.0f)) ||
723 (Val == 0x3e22f983 && HasInv2Pi);
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000724}
725
Matt Arsenault4bd72362016-12-10 00:39:12 +0000726bool isInlinableLiteral16(int16_t Literal, bool HasInv2Pi) {
Sam Kolton9dffada2017-01-17 15:26:02 +0000727 if (!HasInv2Pi)
728 return false;
Matt Arsenault4bd72362016-12-10 00:39:12 +0000729
730 if (Literal >= -16 && Literal <= 64)
731 return true;
732
733 uint16_t Val = static_cast<uint16_t>(Literal);
734 return Val == 0x3C00 || // 1.0
735 Val == 0xBC00 || // -1.0
736 Val == 0x3800 || // 0.5
737 Val == 0xB800 || // -0.5
738 Val == 0x4000 || // 2.0
739 Val == 0xC000 || // -2.0
740 Val == 0x4400 || // 4.0
741 Val == 0xC400 || // -4.0
742 Val == 0x3118; // 1/2pi
743}
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000744
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000745bool isInlinableLiteralV216(int32_t Literal, bool HasInv2Pi) {
746 assert(HasInv2Pi);
747
Konstantin Zhuravlyov3d1cc882017-04-21 19:45:22 +0000748 if (!EnablePackedInlinableLiterals)
749 return false;
750
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000751 int16_t Lo16 = static_cast<int16_t>(Literal);
752 int16_t Hi16 = static_cast<int16_t>(Literal >> 16);
753 return Lo16 == Hi16 && isInlinableLiteral16(Lo16, HasInv2Pi);
754}
755
Matt Arsenault894e53d2017-07-26 20:39:42 +0000756bool isArgPassedInSGPR(const Argument *A) {
757 const Function *F = A->getParent();
758
759 // Arguments to compute shaders are never a source of divergence.
760 CallingConv::ID CC = F->getCallingConv();
761 switch (CC) {
762 case CallingConv::AMDGPU_KERNEL:
763 case CallingConv::SPIR_KERNEL:
764 return true;
765 case CallingConv::AMDGPU_VS:
Tim Renoufef1ae8f2017-09-29 09:51:22 +0000766 case CallingConv::AMDGPU_LS:
Matt Arsenault894e53d2017-07-26 20:39:42 +0000767 case CallingConv::AMDGPU_HS:
Tim Renoufef1ae8f2017-09-29 09:51:22 +0000768 case CallingConv::AMDGPU_ES:
Matt Arsenault894e53d2017-07-26 20:39:42 +0000769 case CallingConv::AMDGPU_GS:
770 case CallingConv::AMDGPU_PS:
771 case CallingConv::AMDGPU_CS:
772 // For non-compute shaders, SGPR inputs are marked with either inreg or byval.
773 // Everything else is in VGPRs.
774 return F->getAttributes().hasParamAttribute(A->getArgNo(), Attribute::InReg) ||
775 F->getAttributes().hasParamAttribute(A->getArgNo(), Attribute::ByVal);
776 default:
777 // TODO: Should calls support inreg for SGPR inputs?
778 return false;
779 }
780}
781
782// TODO: Should largely merge with AMDGPUTTIImpl::isSourceOfDivergence.
Tom Stellard08efb7e2017-01-27 18:41:14 +0000783bool isUniformMMO(const MachineMemOperand *MMO) {
784 const Value *Ptr = MMO->getValue();
785 // UndefValue means this is a load of a kernel input. These are uniform.
786 // Sometimes LDS instructions have constant pointers.
787 // If Ptr is null, then that means this mem operand contains a
788 // PseudoSourceValue like GOT.
Matt Arsenault894e53d2017-07-26 20:39:42 +0000789 if (!Ptr || isa<UndefValue>(Ptr) ||
Tom Stellard08efb7e2017-01-27 18:41:14 +0000790 isa<Constant>(Ptr) || isa<GlobalValue>(Ptr))
791 return true;
792
Matt Arsenault894e53d2017-07-26 20:39:42 +0000793 if (const Argument *Arg = dyn_cast<Argument>(Ptr))
794 return isArgPassedInSGPR(Arg);
795
Tom Stellard08efb7e2017-01-27 18:41:14 +0000796 const Instruction *I = dyn_cast<Instruction>(Ptr);
797 return I && I->getMetadata("amdgpu.uniform");
798}
799
800int64_t getSMRDEncodedOffset(const MCSubtargetInfo &ST, int64_t ByteOffset) {
Matt Arsenault8728c5f2017-08-07 14:58:04 +0000801 if (isGCN3Encoding(ST))
802 return ByteOffset;
803 return ByteOffset >> 2;
Tom Stellard08efb7e2017-01-27 18:41:14 +0000804}
805
806bool isLegalSMRDImmOffset(const MCSubtargetInfo &ST, int64_t ByteOffset) {
807 int64_t EncodedOffset = getSMRDEncodedOffset(ST, ByteOffset);
Matt Arsenault8728c5f2017-08-07 14:58:04 +0000808 return isGCN3Encoding(ST) ?
809 isUInt<20>(EncodedOffset) : isUInt<8>(EncodedOffset);
Tom Stellard08efb7e2017-01-27 18:41:14 +0000810}
Eugene Zelenkod96089b2017-02-14 00:33:36 +0000811} // end namespace AMDGPU
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000812
Eugene Zelenkod96089b2017-02-14 00:33:36 +0000813} // end namespace llvm
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000814
815const unsigned AMDGPUAS::MAX_COMMON_ADDRESS;
816const unsigned AMDGPUAS::GLOBAL_ADDRESS;
817const unsigned AMDGPUAS::LOCAL_ADDRESS;
818const unsigned AMDGPUAS::PARAM_D_ADDRESS;
819const unsigned AMDGPUAS::PARAM_I_ADDRESS;
820const unsigned AMDGPUAS::CONSTANT_BUFFER_0;
821const unsigned AMDGPUAS::CONSTANT_BUFFER_1;
822const unsigned AMDGPUAS::CONSTANT_BUFFER_2;
823const unsigned AMDGPUAS::CONSTANT_BUFFER_3;
824const unsigned AMDGPUAS::CONSTANT_BUFFER_4;
825const unsigned AMDGPUAS::CONSTANT_BUFFER_5;
826const unsigned AMDGPUAS::CONSTANT_BUFFER_6;
827const unsigned AMDGPUAS::CONSTANT_BUFFER_7;
828const unsigned AMDGPUAS::CONSTANT_BUFFER_8;
829const unsigned AMDGPUAS::CONSTANT_BUFFER_9;
830const unsigned AMDGPUAS::CONSTANT_BUFFER_10;
831const unsigned AMDGPUAS::CONSTANT_BUFFER_11;
832const unsigned AMDGPUAS::CONSTANT_BUFFER_12;
833const unsigned AMDGPUAS::CONSTANT_BUFFER_13;
834const unsigned AMDGPUAS::CONSTANT_BUFFER_14;
835const unsigned AMDGPUAS::CONSTANT_BUFFER_15;
836const unsigned AMDGPUAS::UNKNOWN_ADDRESS_SPACE;
837
838namespace llvm {
839namespace AMDGPU {
840
841AMDGPUAS getAMDGPUAS(Triple T) {
842 auto Env = T.getEnvironmentName();
843 AMDGPUAS AS;
844 if (Env == "amdgiz" || Env == "amdgizcl") {
845 AS.FLAT_ADDRESS = 0;
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000846 AS.PRIVATE_ADDRESS = 5;
Yaxun Liu76ae47c2017-04-06 19:17:32 +0000847 AS.REGION_ADDRESS = 4;
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000848 }
849 else {
850 AS.FLAT_ADDRESS = 4;
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000851 AS.PRIVATE_ADDRESS = 0;
852 AS.REGION_ADDRESS = 5;
853 }
854 return AS;
855}
856
857AMDGPUAS getAMDGPUAS(const TargetMachine &M) {
858 return getAMDGPUAS(M.getTargetTriple());
859}
860
861AMDGPUAS getAMDGPUAS(const Module &M) {
862 return getAMDGPUAS(Triple(M.getTargetTriple()));
863}
864} // namespace AMDGPU
865} // namespace llvm