blob: 177b030b31fae497c9e5e370c1a06addc3a8676f [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) {
Konstantin Zhuravlyovc40d9f22017-12-08 20:52:28 +0000106 // GCN GFX6 (Southern Islands (SI)).
Wei Ding7c3e5112017-06-10 03:53:19 +0000107 if (Features.test(FeatureISAVersion6_0_0))
108 return {6, 0, 0};
109 if (Features.test(FeatureISAVersion6_0_1))
110 return {6, 0, 1};
Konstantin Zhuravlyovc40d9f22017-12-08 20:52:28 +0000111
112 // GCN GFX7 (Sea Islands (CI)).
Tom Stellard347ac792015-06-26 21:15:07 +0000113 if (Features.test(FeatureISAVersion7_0_0))
114 return {7, 0, 0};
Tom Stellard347ac792015-06-26 21:15:07 +0000115 if (Features.test(FeatureISAVersion7_0_1))
116 return {7, 0, 1};
Yaxun Liu94add852016-10-26 16:37:56 +0000117 if (Features.test(FeatureISAVersion7_0_2))
118 return {7, 0, 2};
Wei Ding7c3e5112017-06-10 03:53:19 +0000119 if (Features.test(FeatureISAVersion7_0_3))
120 return {7, 0, 3};
Konstantin Zhuravlyovc40d9f22017-12-08 20:52:28 +0000121 if (Features.test(FeatureISAVersion7_0_4))
122 return {7, 0, 4};
Yaxun Liu94add852016-10-26 16:37:56 +0000123
Konstantin Zhuravlyovc40d9f22017-12-08 20:52:28 +0000124 // GCN GFX8 (Volcanic Islands (VI)).
Tom Stellard347ac792015-06-26 21:15:07 +0000125 if (Features.test(FeatureISAVersion8_0_0))
126 return {8, 0, 0};
Tom Stellard347ac792015-06-26 21:15:07 +0000127 if (Features.test(FeatureISAVersion8_0_1))
128 return {8, 0, 1};
Changpeng Fang98317d22016-10-11 16:00:47 +0000129 if (Features.test(FeatureISAVersion8_0_2))
130 return {8, 0, 2};
Changpeng Fangc16be002016-01-13 20:39:25 +0000131 if (Features.test(FeatureISAVersion8_0_3))
132 return {8, 0, 3};
Yaxun Liu94add852016-10-26 16:37:56 +0000133 if (Features.test(FeatureISAVersion8_1_0))
134 return {8, 1, 0};
135
Konstantin Zhuravlyovc40d9f22017-12-08 20:52:28 +0000136 // GCN GFX9.
Matt Arsenaulte823d922017-02-18 18:29:53 +0000137 if (Features.test(FeatureISAVersion9_0_0))
138 return {9, 0, 0};
Wei Ding7c3e5112017-06-10 03:53:19 +0000139 if (Features.test(FeatureISAVersion9_0_2))
140 return {9, 0, 2};
Matt Arsenaulte823d922017-02-18 18:29:53 +0000141
Konstantin Zhuravlyov94b3b472017-07-11 17:57:41 +0000142 if (!Features.test(FeatureGCN) || Features.test(FeatureSouthernIslands))
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000143 return {0, 0, 0};
144 return {7, 0, 0};
Tom Stellard347ac792015-06-26 21:15:07 +0000145}
146
Konstantin Zhuravlyov9c05b2b2017-10-14 15:40:33 +0000147void streamIsaVersion(const MCSubtargetInfo *STI, raw_ostream &Stream) {
148 auto TargetTriple = STI->getTargetTriple();
149 auto ISAVersion = IsaInfo::getIsaVersion(STI->getFeatureBits());
150
151 Stream << TargetTriple.getArchName() << '-'
152 << TargetTriple.getVendorName() << '-'
153 << TargetTriple.getOSName() << '-'
154 << TargetTriple.getEnvironmentName() << '-'
155 << "gfx"
156 << ISAVersion.Major
157 << ISAVersion.Minor
158 << ISAVersion.Stepping;
159 Stream.flush();
160}
161
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +0000162bool hasCodeObjectV3(const FeatureBitset &Features) {
163 return Features.test(FeatureCodeObjectV3);
164}
165
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000166unsigned getWavefrontSize(const FeatureBitset &Features) {
167 if (Features.test(FeatureWavefrontSize16))
168 return 16;
169 if (Features.test(FeatureWavefrontSize32))
170 return 32;
171
172 return 64;
173}
174
175unsigned getLocalMemorySize(const FeatureBitset &Features) {
176 if (Features.test(FeatureLocalMemorySize32768))
177 return 32768;
178 if (Features.test(FeatureLocalMemorySize65536))
179 return 65536;
180
181 return 0;
182}
183
184unsigned getEUsPerCU(const FeatureBitset &Features) {
185 return 4;
186}
187
188unsigned getMaxWorkGroupsPerCU(const FeatureBitset &Features,
189 unsigned FlatWorkGroupSize) {
190 if (!Features.test(FeatureGCN))
191 return 8;
Stanislav Mekhanoshin19f98c62017-02-15 01:03:59 +0000192 unsigned N = getWavesPerWorkGroup(Features, FlatWorkGroupSize);
193 if (N == 1)
194 return 40;
195 N = 40 / N;
196 return std::min(N, 16u);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000197}
198
199unsigned getMaxWavesPerCU(const FeatureBitset &Features) {
200 return getMaxWavesPerEU(Features) * getEUsPerCU(Features);
201}
202
203unsigned getMaxWavesPerCU(const FeatureBitset &Features,
204 unsigned FlatWorkGroupSize) {
205 return getWavesPerWorkGroup(Features, FlatWorkGroupSize);
206}
207
208unsigned getMinWavesPerEU(const FeatureBitset &Features) {
209 return 1;
210}
211
212unsigned getMaxWavesPerEU(const FeatureBitset &Features) {
213 if (!Features.test(FeatureGCN))
214 return 8;
215 // FIXME: Need to take scratch memory into account.
216 return 10;
217}
218
219unsigned getMaxWavesPerEU(const FeatureBitset &Features,
220 unsigned FlatWorkGroupSize) {
221 return alignTo(getMaxWavesPerCU(Features, FlatWorkGroupSize),
222 getEUsPerCU(Features)) / getEUsPerCU(Features);
223}
224
225unsigned getMinFlatWorkGroupSize(const FeatureBitset &Features) {
226 return 1;
227}
228
229unsigned getMaxFlatWorkGroupSize(const FeatureBitset &Features) {
230 return 2048;
231}
232
233unsigned getWavesPerWorkGroup(const FeatureBitset &Features,
234 unsigned FlatWorkGroupSize) {
235 return alignTo(FlatWorkGroupSize, getWavefrontSize(Features)) /
236 getWavefrontSize(Features);
237}
238
239unsigned getSGPRAllocGranule(const FeatureBitset &Features) {
240 IsaVersion Version = getIsaVersion(Features);
241 if (Version.Major >= 8)
242 return 16;
243 return 8;
244}
245
246unsigned getSGPREncodingGranule(const FeatureBitset &Features) {
247 return 8;
248}
249
250unsigned getTotalNumSGPRs(const FeatureBitset &Features) {
251 IsaVersion Version = getIsaVersion(Features);
252 if (Version.Major >= 8)
253 return 800;
254 return 512;
255}
256
257unsigned getAddressableNumSGPRs(const FeatureBitset &Features) {
258 if (Features.test(FeatureSGPRInitBug))
259 return FIXED_NUM_SGPRS_FOR_INIT_BUG;
260
261 IsaVersion Version = getIsaVersion(Features);
262 if (Version.Major >= 8)
263 return 102;
264 return 104;
265}
266
267unsigned getMinNumSGPRs(const FeatureBitset &Features, unsigned WavesPerEU) {
Konstantin Zhuravlyovfd871372017-02-09 21:33:23 +0000268 assert(WavesPerEU != 0);
269
270 if (WavesPerEU >= getMaxWavesPerEU(Features))
271 return 0;
272 unsigned MinNumSGPRs =
273 alignDown(getTotalNumSGPRs(Features) / (WavesPerEU + 1),
274 getSGPRAllocGranule(Features)) + 1;
275 return std::min(MinNumSGPRs, getAddressableNumSGPRs(Features));
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000276}
277
278unsigned getMaxNumSGPRs(const FeatureBitset &Features, unsigned WavesPerEU,
279 bool Addressable) {
Konstantin Zhuravlyovfd871372017-02-09 21:33:23 +0000280 assert(WavesPerEU != 0);
281
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000282 IsaVersion Version = getIsaVersion(Features);
Konstantin Zhuravlyovfd871372017-02-09 21:33:23 +0000283 unsigned MaxNumSGPRs = alignDown(getTotalNumSGPRs(Features) / WavesPerEU,
284 getSGPRAllocGranule(Features));
285 unsigned AddressableNumSGPRs = getAddressableNumSGPRs(Features);
286 if (Version.Major >= 8 && !Addressable)
287 AddressableNumSGPRs = 112;
288 return std::min(MaxNumSGPRs, AddressableNumSGPRs);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000289}
290
291unsigned getVGPRAllocGranule(const FeatureBitset &Features) {
292 return 4;
293}
294
295unsigned getVGPREncodingGranule(const FeatureBitset &Features) {
296 return getVGPRAllocGranule(Features);
297}
298
299unsigned getTotalNumVGPRs(const FeatureBitset &Features) {
300 return 256;
301}
302
303unsigned getAddressableNumVGPRs(const FeatureBitset &Features) {
304 return getTotalNumVGPRs(Features);
305}
306
307unsigned getMinNumVGPRs(const FeatureBitset &Features, unsigned WavesPerEU) {
Konstantin Zhuravlyovfd871372017-02-09 21:33:23 +0000308 assert(WavesPerEU != 0);
309
310 if (WavesPerEU >= getMaxWavesPerEU(Features))
311 return 0;
312 unsigned MinNumVGPRs =
313 alignDown(getTotalNumVGPRs(Features) / (WavesPerEU + 1),
314 getVGPRAllocGranule(Features)) + 1;
315 return std::min(MinNumVGPRs, getAddressableNumVGPRs(Features));
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000316}
317
318unsigned getMaxNumVGPRs(const FeatureBitset &Features, unsigned WavesPerEU) {
Konstantin Zhuravlyovfd871372017-02-09 21:33:23 +0000319 assert(WavesPerEU != 0);
320
321 unsigned MaxNumVGPRs = alignDown(getTotalNumVGPRs(Features) / WavesPerEU,
322 getVGPRAllocGranule(Features));
323 unsigned AddressableNumVGPRs = getAddressableNumVGPRs(Features);
324 return std::min(MaxNumVGPRs, AddressableNumVGPRs);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000325}
326
Eugene Zelenkod96089b2017-02-14 00:33:36 +0000327} // end namespace IsaInfo
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000328
Tom Stellardff7416b2015-06-26 21:58:31 +0000329void initDefaultAMDKernelCodeT(amd_kernel_code_t &Header,
330 const FeatureBitset &Features) {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000331 IsaInfo::IsaVersion ISA = IsaInfo::getIsaVersion(Features);
Tom Stellardff7416b2015-06-26 21:58:31 +0000332
333 memset(&Header, 0, sizeof(Header));
334
335 Header.amd_kernel_code_version_major = 1;
Konstantin Zhuravlyov182e9cc2017-02-28 17:17:52 +0000336 Header.amd_kernel_code_version_minor = 1;
Tom Stellardff7416b2015-06-26 21:58:31 +0000337 Header.amd_machine_kind = 1; // AMD_MACHINE_KIND_AMDGPU
338 Header.amd_machine_version_major = ISA.Major;
339 Header.amd_machine_version_minor = ISA.Minor;
340 Header.amd_machine_version_stepping = ISA.Stepping;
341 Header.kernel_code_entry_byte_offset = sizeof(Header);
342 // wavefront_size is specified as a power of 2: 2^6 = 64 threads.
343 Header.wavefront_size = 6;
Matt Arsenault5d910192017-01-25 20:21:57 +0000344
345 // If the code object does not support indirect functions, then the value must
346 // be 0xffffffff.
347 Header.call_convention = -1;
348
Tom Stellardff7416b2015-06-26 21:58:31 +0000349 // These alignment values are specified in powers of two, so alignment =
350 // 2^n. The minimum alignment is 2^4 = 16.
351 Header.kernarg_segment_alignment = 4;
352 Header.group_segment_alignment = 4;
353 Header.private_segment_alignment = 4;
354}
355
Konstantin Zhuravlyov435151a2017-11-01 19:12:38 +0000356bool isGroupSegment(const GlobalValue *GV) {
357 return GV->getType()->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
Tom Stellarde3b5aea2015-12-02 17:00:42 +0000358}
359
Konstantin Zhuravlyov435151a2017-11-01 19:12:38 +0000360bool isGlobalSegment(const GlobalValue *GV) {
361 return GV->getType()->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS;
Tom Stellard00f2f912015-12-02 19:47:57 +0000362}
363
Konstantin Zhuravlyov435151a2017-11-01 19:12:38 +0000364bool isReadOnlySegment(const GlobalValue *GV) {
365 return GV->getType()->getAddressSpace() == AMDGPUAS::CONSTANT_ADDRESS;
Tom Stellard00f2f912015-12-02 19:47:57 +0000366}
367
Konstantin Zhuravlyov08326b62016-10-20 18:12:38 +0000368bool shouldEmitConstantsToTextSection(const Triple &TT) {
369 return TT.getOS() != Triple::AMDHSA;
370}
371
Matt Arsenault83002722016-05-12 02:45:18 +0000372int getIntegerAttribute(const Function &F, StringRef Name, int Default) {
Marek Olsakfccabaf2016-01-13 11:45:36 +0000373 Attribute A = F.getFnAttribute(Name);
Matt Arsenault83002722016-05-12 02:45:18 +0000374 int Result = Default;
Tom Stellardac00eb52015-12-15 16:26:16 +0000375
376 if (A.isStringAttribute()) {
377 StringRef Str = A.getValueAsString();
Marek Olsakfccabaf2016-01-13 11:45:36 +0000378 if (Str.getAsInteger(0, Result)) {
Tom Stellardac00eb52015-12-15 16:26:16 +0000379 LLVMContext &Ctx = F.getContext();
Matt Arsenault83002722016-05-12 02:45:18 +0000380 Ctx.emitError("can't parse integer attribute " + Name);
Tom Stellardac00eb52015-12-15 16:26:16 +0000381 }
382 }
Matt Arsenault83002722016-05-12 02:45:18 +0000383
Marek Olsakfccabaf2016-01-13 11:45:36 +0000384 return Result;
385}
386
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000387std::pair<int, int> getIntegerPairAttribute(const Function &F,
388 StringRef Name,
389 std::pair<int, int> Default,
390 bool OnlyFirstRequired) {
391 Attribute A = F.getFnAttribute(Name);
392 if (!A.isStringAttribute())
393 return Default;
394
395 LLVMContext &Ctx = F.getContext();
396 std::pair<int, int> Ints = Default;
397 std::pair<StringRef, StringRef> Strs = A.getValueAsString().split(',');
398 if (Strs.first.trim().getAsInteger(0, Ints.first)) {
399 Ctx.emitError("can't parse first integer attribute " + Name);
400 return Default;
401 }
402 if (Strs.second.trim().getAsInteger(0, Ints.second)) {
Eugene Zelenkod96089b2017-02-14 00:33:36 +0000403 if (!OnlyFirstRequired || !Strs.second.trim().empty()) {
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000404 Ctx.emitError("can't parse second integer attribute " + Name);
405 return Default;
406 }
407 }
408
409 return Ints;
Tom Stellard79a1fd72016-04-14 16:27:07 +0000410}
411
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000412unsigned getVmcntBitMask(const IsaInfo::IsaVersion &Version) {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000413 unsigned VmcntLo = (1 << getVmcntBitWidthLo()) - 1;
414 if (Version.Major < 9)
415 return VmcntLo;
416
417 unsigned VmcntHi = ((1 << getVmcntBitWidthHi()) - 1) << getVmcntBitWidthLo();
418 return VmcntLo | VmcntHi;
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000419}
420
421unsigned getExpcntBitMask(const IsaInfo::IsaVersion &Version) {
422 return (1 << getExpcntBitWidth()) - 1;
423}
424
425unsigned getLgkmcntBitMask(const IsaInfo::IsaVersion &Version) {
426 return (1 << getLgkmcntBitWidth()) - 1;
427}
428
429unsigned getWaitcntBitMask(const IsaInfo::IsaVersion &Version) {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000430 unsigned VmcntLo = getBitMask(getVmcntBitShiftLo(), getVmcntBitWidthLo());
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000431 unsigned Expcnt = getBitMask(getExpcntBitShift(), getExpcntBitWidth());
432 unsigned Lgkmcnt = getBitMask(getLgkmcntBitShift(), getLgkmcntBitWidth());
Matt Arsenaulte823d922017-02-18 18:29:53 +0000433 unsigned Waitcnt = VmcntLo | Expcnt | Lgkmcnt;
434 if (Version.Major < 9)
435 return Waitcnt;
436
437 unsigned VmcntHi = getBitMask(getVmcntBitShiftHi(), getVmcntBitWidthHi());
438 return Waitcnt | VmcntHi;
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +0000439}
440
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000441unsigned decodeVmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt) {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000442 unsigned VmcntLo =
443 unpackBits(Waitcnt, getVmcntBitShiftLo(), getVmcntBitWidthLo());
444 if (Version.Major < 9)
445 return VmcntLo;
446
447 unsigned VmcntHi =
448 unpackBits(Waitcnt, getVmcntBitShiftHi(), getVmcntBitWidthHi());
449 VmcntHi <<= getVmcntBitWidthLo();
450 return VmcntLo | VmcntHi;
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +0000451}
452
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000453unsigned decodeExpcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt) {
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000454 return unpackBits(Waitcnt, getExpcntBitShift(), getExpcntBitWidth());
455}
456
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000457unsigned decodeLgkmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt) {
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000458 return unpackBits(Waitcnt, getLgkmcntBitShift(), getLgkmcntBitWidth());
459}
460
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000461void decodeWaitcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt,
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000462 unsigned &Vmcnt, unsigned &Expcnt, unsigned &Lgkmcnt) {
463 Vmcnt = decodeVmcnt(Version, Waitcnt);
464 Expcnt = decodeExpcnt(Version, Waitcnt);
465 Lgkmcnt = decodeLgkmcnt(Version, Waitcnt);
466}
467
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000468unsigned encodeVmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt,
469 unsigned Vmcnt) {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000470 Waitcnt =
471 packBits(Vmcnt, Waitcnt, getVmcntBitShiftLo(), getVmcntBitWidthLo());
472 if (Version.Major < 9)
473 return Waitcnt;
474
475 Vmcnt >>= getVmcntBitWidthLo();
476 return packBits(Vmcnt, Waitcnt, getVmcntBitShiftHi(), getVmcntBitWidthHi());
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000477}
478
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000479unsigned encodeExpcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt,
480 unsigned Expcnt) {
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000481 return packBits(Expcnt, Waitcnt, getExpcntBitShift(), getExpcntBitWidth());
482}
483
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000484unsigned encodeLgkmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt,
485 unsigned Lgkmcnt) {
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000486 return packBits(Lgkmcnt, Waitcnt, getLgkmcntBitShift(), getLgkmcntBitWidth());
487}
488
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000489unsigned encodeWaitcnt(const IsaInfo::IsaVersion &Version,
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000490 unsigned Vmcnt, unsigned Expcnt, unsigned Lgkmcnt) {
Konstantin Zhuravlyov31dbb032017-01-06 17:23:21 +0000491 unsigned Waitcnt = getWaitcntBitMask(Version);
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000492 Waitcnt = encodeVmcnt(Version, Waitcnt, Vmcnt);
493 Waitcnt = encodeExpcnt(Version, Waitcnt, Expcnt);
494 Waitcnt = encodeLgkmcnt(Version, Waitcnt, Lgkmcnt);
495 return Waitcnt;
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +0000496}
497
Marek Olsakfccabaf2016-01-13 11:45:36 +0000498unsigned getInitialPSInputAddr(const Function &F) {
499 return getIntegerAttribute(F, "InitialPSInputAddr", 0);
Tom Stellardac00eb52015-12-15 16:26:16 +0000500}
501
Nicolai Haehnledf3a20c2016-04-06 19:40:20 +0000502bool isShader(CallingConv::ID cc) {
503 switch(cc) {
504 case CallingConv::AMDGPU_VS:
Tim Renoufef1ae8f2017-09-29 09:51:22 +0000505 case CallingConv::AMDGPU_LS:
Marek Olsaka302a7362017-05-02 15:41:10 +0000506 case CallingConv::AMDGPU_HS:
Tim Renoufef1ae8f2017-09-29 09:51:22 +0000507 case CallingConv::AMDGPU_ES:
Nicolai Haehnledf3a20c2016-04-06 19:40:20 +0000508 case CallingConv::AMDGPU_GS:
509 case CallingConv::AMDGPU_PS:
510 case CallingConv::AMDGPU_CS:
511 return true;
512 default:
513 return false;
514 }
515}
516
517bool isCompute(CallingConv::ID cc) {
518 return !isShader(cc) || cc == CallingConv::AMDGPU_CS;
519}
520
Matt Arsenaulte622dc32017-04-11 22:29:24 +0000521bool isEntryFunctionCC(CallingConv::ID CC) {
Matt Arsenault2b1f9aa2017-05-17 21:56:25 +0000522 switch (CC) {
523 case CallingConv::AMDGPU_KERNEL:
524 case CallingConv::SPIR_KERNEL:
525 case CallingConv::AMDGPU_VS:
526 case CallingConv::AMDGPU_GS:
527 case CallingConv::AMDGPU_PS:
528 case CallingConv::AMDGPU_CS:
Tim Renoufef1ae8f2017-09-29 09:51:22 +0000529 case CallingConv::AMDGPU_ES:
Matt Arsenault2b1f9aa2017-05-17 21:56:25 +0000530 case CallingConv::AMDGPU_HS:
Tim Renoufef1ae8f2017-09-29 09:51:22 +0000531 case CallingConv::AMDGPU_LS:
Matt Arsenault2b1f9aa2017-05-17 21:56:25 +0000532 return true;
533 default:
534 return false;
535 }
Matt Arsenaulte622dc32017-04-11 22:29:24 +0000536}
537
Tom Stellard2b65ed32015-12-21 18:44:27 +0000538bool isSI(const MCSubtargetInfo &STI) {
539 return STI.getFeatureBits()[AMDGPU::FeatureSouthernIslands];
540}
541
542bool isCI(const MCSubtargetInfo &STI) {
543 return STI.getFeatureBits()[AMDGPU::FeatureSeaIslands];
544}
545
546bool isVI(const MCSubtargetInfo &STI) {
547 return STI.getFeatureBits()[AMDGPU::FeatureVolcanicIslands];
548}
549
Sam Koltonf7659d712017-05-23 10:08:55 +0000550bool isGFX9(const MCSubtargetInfo &STI) {
551 return STI.getFeatureBits()[AMDGPU::FeatureGFX9];
552}
553
Matt Arsenault8728c5f2017-08-07 14:58:04 +0000554bool isGCN3Encoding(const MCSubtargetInfo &STI) {
555 return STI.getFeatureBits()[AMDGPU::FeatureGCN3Encoding];
556}
557
Sam Koltonf7659d712017-05-23 10:08:55 +0000558bool isSGPR(unsigned Reg, const MCRegisterInfo* TRI) {
559 const MCRegisterClass SGPRClass = TRI->getRegClass(AMDGPU::SReg_32RegClassID);
560 const unsigned FirstSubReg = TRI->getSubReg(Reg, 1);
561 return SGPRClass.contains(FirstSubReg != 0 ? FirstSubReg : Reg) ||
562 Reg == AMDGPU::SCC;
563}
564
Dmitry Preobrazhenskydc4ac822017-06-21 14:41:34 +0000565bool isRegIntersect(unsigned Reg0, unsigned Reg1, const MCRegisterInfo* TRI) {
Dmitry Preobrazhensky00deef82017-07-18 11:14:02 +0000566 for (MCRegAliasIterator R(Reg0, TRI, true); R.isValid(); ++R) {
567 if (*R == Reg1) return true;
Dmitry Preobrazhenskydc4ac822017-06-21 14:41:34 +0000568 }
Dmitry Preobrazhenskydc4ac822017-06-21 14:41:34 +0000569 return false;
570}
571
Tom Stellard2b65ed32015-12-21 18:44:27 +0000572unsigned getMCReg(unsigned Reg, const MCSubtargetInfo &STI) {
573
574 switch(Reg) {
575 default: break;
576 case AMDGPU::FLAT_SCR:
577 assert(!isSI(STI));
578 return isCI(STI) ? AMDGPU::FLAT_SCR_ci : AMDGPU::FLAT_SCR_vi;
579
580 case AMDGPU::FLAT_SCR_LO:
581 assert(!isSI(STI));
582 return isCI(STI) ? AMDGPU::FLAT_SCR_LO_ci : AMDGPU::FLAT_SCR_LO_vi;
583
584 case AMDGPU::FLAT_SCR_HI:
585 assert(!isSI(STI));
586 return isCI(STI) ? AMDGPU::FLAT_SCR_HI_ci : AMDGPU::FLAT_SCR_HI_vi;
587 }
588 return Reg;
589}
590
Dmitry Preobrazhensky03880f82017-03-03 14:31:06 +0000591unsigned mc2PseudoReg(unsigned Reg) {
592 switch (Reg) {
593 case AMDGPU::FLAT_SCR_ci:
594 case AMDGPU::FLAT_SCR_vi:
595 return FLAT_SCR;
596
597 case AMDGPU::FLAT_SCR_LO_ci:
598 case AMDGPU::FLAT_SCR_LO_vi:
599 return AMDGPU::FLAT_SCR_LO;
600
601 case AMDGPU::FLAT_SCR_HI_ci:
602 case AMDGPU::FLAT_SCR_HI_vi:
603 return AMDGPU::FLAT_SCR_HI;
604
605 default:
606 return Reg;
607 }
608}
609
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000610bool isSISrcOperand(const MCInstrDesc &Desc, unsigned OpNo) {
Artem Tamazov43b61562017-02-03 12:47:30 +0000611 assert(OpNo < Desc.NumOperands);
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000612 unsigned OpType = Desc.OpInfo[OpNo].OperandType;
Matt Arsenault4bd72362016-12-10 00:39:12 +0000613 return OpType >= AMDGPU::OPERAND_SRC_FIRST &&
614 OpType <= AMDGPU::OPERAND_SRC_LAST;
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000615}
616
617bool isSISrcFPOperand(const MCInstrDesc &Desc, unsigned OpNo) {
Artem Tamazov43b61562017-02-03 12:47:30 +0000618 assert(OpNo < Desc.NumOperands);
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000619 unsigned OpType = Desc.OpInfo[OpNo].OperandType;
Matt Arsenault4bd72362016-12-10 00:39:12 +0000620 switch (OpType) {
621 case AMDGPU::OPERAND_REG_IMM_FP32:
622 case AMDGPU::OPERAND_REG_IMM_FP64:
623 case AMDGPU::OPERAND_REG_IMM_FP16:
624 case AMDGPU::OPERAND_REG_INLINE_C_FP32:
625 case AMDGPU::OPERAND_REG_INLINE_C_FP64:
626 case AMDGPU::OPERAND_REG_INLINE_C_FP16:
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000627 case AMDGPU::OPERAND_REG_INLINE_C_V2FP16:
Matt Arsenault4bd72362016-12-10 00:39:12 +0000628 return true;
629 default:
630 return false;
631 }
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000632}
633
634bool isSISrcInlinableOperand(const MCInstrDesc &Desc, unsigned OpNo) {
Artem Tamazov43b61562017-02-03 12:47:30 +0000635 assert(OpNo < Desc.NumOperands);
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000636 unsigned OpType = Desc.OpInfo[OpNo].OperandType;
Matt Arsenault4bd72362016-12-10 00:39:12 +0000637 return OpType >= AMDGPU::OPERAND_REG_INLINE_C_FIRST &&
638 OpType <= AMDGPU::OPERAND_REG_INLINE_C_LAST;
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000639}
640
Krzysztof Parzyszekc8715502016-10-19 17:40:36 +0000641// Avoid using MCRegisterClass::getSize, since that function will go away
642// (move from MC* level to Target* level). Return size in bits.
Tom Stellardb133fbb2016-10-27 23:05:31 +0000643unsigned getRegBitWidth(unsigned RCID) {
644 switch (RCID) {
Krzysztof Parzyszekc8715502016-10-19 17:40:36 +0000645 case AMDGPU::SGPR_32RegClassID:
646 case AMDGPU::VGPR_32RegClassID:
647 case AMDGPU::VS_32RegClassID:
648 case AMDGPU::SReg_32RegClassID:
649 case AMDGPU::SReg_32_XM0RegClassID:
650 return 32;
651 case AMDGPU::SGPR_64RegClassID:
652 case AMDGPU::VS_64RegClassID:
653 case AMDGPU::SReg_64RegClassID:
654 case AMDGPU::VReg_64RegClassID:
655 return 64;
656 case AMDGPU::VReg_96RegClassID:
657 return 96;
658 case AMDGPU::SGPR_128RegClassID:
659 case AMDGPU::SReg_128RegClassID:
660 case AMDGPU::VReg_128RegClassID:
661 return 128;
662 case AMDGPU::SReg_256RegClassID:
663 case AMDGPU::VReg_256RegClassID:
664 return 256;
665 case AMDGPU::SReg_512RegClassID:
666 case AMDGPU::VReg_512RegClassID:
667 return 512;
668 default:
669 llvm_unreachable("Unexpected register class");
670 }
671}
672
Tom Stellardb133fbb2016-10-27 23:05:31 +0000673unsigned getRegBitWidth(const MCRegisterClass &RC) {
674 return getRegBitWidth(RC.getID());
675}
676
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000677unsigned getRegOperandSize(const MCRegisterInfo *MRI, const MCInstrDesc &Desc,
678 unsigned OpNo) {
Artem Tamazov43b61562017-02-03 12:47:30 +0000679 assert(OpNo < Desc.NumOperands);
Krzysztof Parzyszekc8715502016-10-19 17:40:36 +0000680 unsigned RCID = Desc.OpInfo[OpNo].RegClass;
681 return getRegBitWidth(MRI->getRegClass(RCID)) / 8;
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000682}
683
Matt Arsenault26faed32016-12-05 22:26:17 +0000684bool isInlinableLiteral64(int64_t Literal, bool HasInv2Pi) {
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000685 if (Literal >= -16 && Literal <= 64)
686 return true;
687
Matt Arsenault26faed32016-12-05 22:26:17 +0000688 uint64_t Val = static_cast<uint64_t>(Literal);
689 return (Val == DoubleToBits(0.0)) ||
690 (Val == DoubleToBits(1.0)) ||
691 (Val == DoubleToBits(-1.0)) ||
692 (Val == DoubleToBits(0.5)) ||
693 (Val == DoubleToBits(-0.5)) ||
694 (Val == DoubleToBits(2.0)) ||
695 (Val == DoubleToBits(-2.0)) ||
696 (Val == DoubleToBits(4.0)) ||
697 (Val == DoubleToBits(-4.0)) ||
698 (Val == 0x3fc45f306dc9c882 && HasInv2Pi);
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000699}
700
Matt Arsenault26faed32016-12-05 22:26:17 +0000701bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi) {
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000702 if (Literal >= -16 && Literal <= 64)
703 return true;
704
Matt Arsenault4bd72362016-12-10 00:39:12 +0000705 // The actual type of the operand does not seem to matter as long
706 // as the bits match one of the inline immediate values. For example:
707 //
708 // -nan has the hexadecimal encoding of 0xfffffffe which is -2 in decimal,
709 // so it is a legal inline immediate.
710 //
711 // 1065353216 has the hexadecimal encoding 0x3f800000 which is 1.0f in
712 // floating-point, so it is a legal inline immediate.
713
Matt Arsenault26faed32016-12-05 22:26:17 +0000714 uint32_t Val = static_cast<uint32_t>(Literal);
715 return (Val == FloatToBits(0.0f)) ||
716 (Val == FloatToBits(1.0f)) ||
717 (Val == FloatToBits(-1.0f)) ||
718 (Val == FloatToBits(0.5f)) ||
719 (Val == FloatToBits(-0.5f)) ||
720 (Val == FloatToBits(2.0f)) ||
721 (Val == FloatToBits(-2.0f)) ||
722 (Val == FloatToBits(4.0f)) ||
723 (Val == FloatToBits(-4.0f)) ||
724 (Val == 0x3e22f983 && HasInv2Pi);
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000725}
726
Matt Arsenault4bd72362016-12-10 00:39:12 +0000727bool isInlinableLiteral16(int16_t Literal, bool HasInv2Pi) {
Sam Kolton9dffada2017-01-17 15:26:02 +0000728 if (!HasInv2Pi)
729 return false;
Matt Arsenault4bd72362016-12-10 00:39:12 +0000730
731 if (Literal >= -16 && Literal <= 64)
732 return true;
733
734 uint16_t Val = static_cast<uint16_t>(Literal);
735 return Val == 0x3C00 || // 1.0
736 Val == 0xBC00 || // -1.0
737 Val == 0x3800 || // 0.5
738 Val == 0xB800 || // -0.5
739 Val == 0x4000 || // 2.0
740 Val == 0xC000 || // -2.0
741 Val == 0x4400 || // 4.0
742 Val == 0xC400 || // -4.0
743 Val == 0x3118; // 1/2pi
744}
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000745
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000746bool isInlinableLiteralV216(int32_t Literal, bool HasInv2Pi) {
747 assert(HasInv2Pi);
748
Konstantin Zhuravlyov3d1cc882017-04-21 19:45:22 +0000749 if (!EnablePackedInlinableLiterals)
750 return false;
751
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000752 int16_t Lo16 = static_cast<int16_t>(Literal);
753 int16_t Hi16 = static_cast<int16_t>(Literal >> 16);
754 return Lo16 == Hi16 && isInlinableLiteral16(Lo16, HasInv2Pi);
755}
756
Matt Arsenault894e53d2017-07-26 20:39:42 +0000757bool isArgPassedInSGPR(const Argument *A) {
758 const Function *F = A->getParent();
759
760 // Arguments to compute shaders are never a source of divergence.
761 CallingConv::ID CC = F->getCallingConv();
762 switch (CC) {
763 case CallingConv::AMDGPU_KERNEL:
764 case CallingConv::SPIR_KERNEL:
765 return true;
766 case CallingConv::AMDGPU_VS:
Tim Renoufef1ae8f2017-09-29 09:51:22 +0000767 case CallingConv::AMDGPU_LS:
Matt Arsenault894e53d2017-07-26 20:39:42 +0000768 case CallingConv::AMDGPU_HS:
Tim Renoufef1ae8f2017-09-29 09:51:22 +0000769 case CallingConv::AMDGPU_ES:
Matt Arsenault894e53d2017-07-26 20:39:42 +0000770 case CallingConv::AMDGPU_GS:
771 case CallingConv::AMDGPU_PS:
772 case CallingConv::AMDGPU_CS:
773 // For non-compute shaders, SGPR inputs are marked with either inreg or byval.
774 // Everything else is in VGPRs.
775 return F->getAttributes().hasParamAttribute(A->getArgNo(), Attribute::InReg) ||
776 F->getAttributes().hasParamAttribute(A->getArgNo(), Attribute::ByVal);
777 default:
778 // TODO: Should calls support inreg for SGPR inputs?
779 return false;
780 }
781}
782
783// TODO: Should largely merge with AMDGPUTTIImpl::isSourceOfDivergence.
Tom Stellard08efb7e2017-01-27 18:41:14 +0000784bool isUniformMMO(const MachineMemOperand *MMO) {
785 const Value *Ptr = MMO->getValue();
786 // UndefValue means this is a load of a kernel input. These are uniform.
787 // Sometimes LDS instructions have constant pointers.
788 // If Ptr is null, then that means this mem operand contains a
789 // PseudoSourceValue like GOT.
Matt Arsenault894e53d2017-07-26 20:39:42 +0000790 if (!Ptr || isa<UndefValue>(Ptr) ||
Tom Stellard08efb7e2017-01-27 18:41:14 +0000791 isa<Constant>(Ptr) || isa<GlobalValue>(Ptr))
792 return true;
793
Matt Arsenault894e53d2017-07-26 20:39:42 +0000794 if (const Argument *Arg = dyn_cast<Argument>(Ptr))
795 return isArgPassedInSGPR(Arg);
796
Tom Stellard08efb7e2017-01-27 18:41:14 +0000797 const Instruction *I = dyn_cast<Instruction>(Ptr);
798 return I && I->getMetadata("amdgpu.uniform");
799}
800
801int64_t getSMRDEncodedOffset(const MCSubtargetInfo &ST, int64_t ByteOffset) {
Matt Arsenault8728c5f2017-08-07 14:58:04 +0000802 if (isGCN3Encoding(ST))
803 return ByteOffset;
804 return ByteOffset >> 2;
Tom Stellard08efb7e2017-01-27 18:41:14 +0000805}
806
807bool isLegalSMRDImmOffset(const MCSubtargetInfo &ST, int64_t ByteOffset) {
808 int64_t EncodedOffset = getSMRDEncodedOffset(ST, ByteOffset);
Matt Arsenault8728c5f2017-08-07 14:58:04 +0000809 return isGCN3Encoding(ST) ?
810 isUInt<20>(EncodedOffset) : isUInt<8>(EncodedOffset);
Tom Stellard08efb7e2017-01-27 18:41:14 +0000811}
Eugene Zelenkod96089b2017-02-14 00:33:36 +0000812} // end namespace AMDGPU
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000813
Eugene Zelenkod96089b2017-02-14 00:33:36 +0000814} // end namespace llvm
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000815
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000816namespace llvm {
817namespace AMDGPU {
818
819AMDGPUAS getAMDGPUAS(Triple T) {
820 auto Env = T.getEnvironmentName();
821 AMDGPUAS AS;
822 if (Env == "amdgiz" || Env == "amdgizcl") {
823 AS.FLAT_ADDRESS = 0;
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000824 AS.PRIVATE_ADDRESS = 5;
Yaxun Liu76ae47c2017-04-06 19:17:32 +0000825 AS.REGION_ADDRESS = 4;
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000826 }
827 else {
828 AS.FLAT_ADDRESS = 4;
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000829 AS.PRIVATE_ADDRESS = 0;
830 AS.REGION_ADDRESS = 5;
831 }
832 return AS;
833}
834
835AMDGPUAS getAMDGPUAS(const TargetMachine &M) {
836 return getAMDGPUAS(M.getTargetTriple());
837}
838
839AMDGPUAS getAMDGPUAS(const Module &M) {
840 return getAMDGPUAS(Triple(M.getTargetTriple()));
841}
842} // namespace AMDGPU
843} // namespace llvm