blob: ae70dd2893c8bcce3878a67e9ca0fa094912f22f [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 Zhuravlyoveda425e2017-10-14 15:59:07 +0000165bool hasCodeObjectV3(const FeatureBitset &Features) {
166 return Features.test(FeatureCodeObjectV3);
167}
168
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000169unsigned getWavefrontSize(const FeatureBitset &Features) {
170 if (Features.test(FeatureWavefrontSize16))
171 return 16;
172 if (Features.test(FeatureWavefrontSize32))
173 return 32;
174
175 return 64;
176}
177
178unsigned getLocalMemorySize(const FeatureBitset &Features) {
179 if (Features.test(FeatureLocalMemorySize32768))
180 return 32768;
181 if (Features.test(FeatureLocalMemorySize65536))
182 return 65536;
183
184 return 0;
185}
186
187unsigned getEUsPerCU(const FeatureBitset &Features) {
188 return 4;
189}
190
191unsigned getMaxWorkGroupsPerCU(const FeatureBitset &Features,
192 unsigned FlatWorkGroupSize) {
193 if (!Features.test(FeatureGCN))
194 return 8;
Stanislav Mekhanoshin19f98c62017-02-15 01:03:59 +0000195 unsigned N = getWavesPerWorkGroup(Features, FlatWorkGroupSize);
196 if (N == 1)
197 return 40;
198 N = 40 / N;
199 return std::min(N, 16u);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000200}
201
202unsigned getMaxWavesPerCU(const FeatureBitset &Features) {
203 return getMaxWavesPerEU(Features) * getEUsPerCU(Features);
204}
205
206unsigned getMaxWavesPerCU(const FeatureBitset &Features,
207 unsigned FlatWorkGroupSize) {
208 return getWavesPerWorkGroup(Features, FlatWorkGroupSize);
209}
210
211unsigned getMinWavesPerEU(const FeatureBitset &Features) {
212 return 1;
213}
214
215unsigned getMaxWavesPerEU(const FeatureBitset &Features) {
216 if (!Features.test(FeatureGCN))
217 return 8;
218 // FIXME: Need to take scratch memory into account.
219 return 10;
220}
221
222unsigned getMaxWavesPerEU(const FeatureBitset &Features,
223 unsigned FlatWorkGroupSize) {
224 return alignTo(getMaxWavesPerCU(Features, FlatWorkGroupSize),
225 getEUsPerCU(Features)) / getEUsPerCU(Features);
226}
227
228unsigned getMinFlatWorkGroupSize(const FeatureBitset &Features) {
229 return 1;
230}
231
232unsigned getMaxFlatWorkGroupSize(const FeatureBitset &Features) {
233 return 2048;
234}
235
236unsigned getWavesPerWorkGroup(const FeatureBitset &Features,
237 unsigned FlatWorkGroupSize) {
238 return alignTo(FlatWorkGroupSize, getWavefrontSize(Features)) /
239 getWavefrontSize(Features);
240}
241
242unsigned getSGPRAllocGranule(const FeatureBitset &Features) {
243 IsaVersion Version = getIsaVersion(Features);
244 if (Version.Major >= 8)
245 return 16;
246 return 8;
247}
248
249unsigned getSGPREncodingGranule(const FeatureBitset &Features) {
250 return 8;
251}
252
253unsigned getTotalNumSGPRs(const FeatureBitset &Features) {
254 IsaVersion Version = getIsaVersion(Features);
255 if (Version.Major >= 8)
256 return 800;
257 return 512;
258}
259
260unsigned getAddressableNumSGPRs(const FeatureBitset &Features) {
261 if (Features.test(FeatureSGPRInitBug))
262 return FIXED_NUM_SGPRS_FOR_INIT_BUG;
263
264 IsaVersion Version = getIsaVersion(Features);
265 if (Version.Major >= 8)
266 return 102;
267 return 104;
268}
269
270unsigned getMinNumSGPRs(const FeatureBitset &Features, unsigned WavesPerEU) {
Konstantin Zhuravlyovfd871372017-02-09 21:33:23 +0000271 assert(WavesPerEU != 0);
272
273 if (WavesPerEU >= getMaxWavesPerEU(Features))
274 return 0;
275 unsigned MinNumSGPRs =
276 alignDown(getTotalNumSGPRs(Features) / (WavesPerEU + 1),
277 getSGPRAllocGranule(Features)) + 1;
278 return std::min(MinNumSGPRs, getAddressableNumSGPRs(Features));
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000279}
280
281unsigned getMaxNumSGPRs(const FeatureBitset &Features, unsigned WavesPerEU,
282 bool Addressable) {
Konstantin Zhuravlyovfd871372017-02-09 21:33:23 +0000283 assert(WavesPerEU != 0);
284
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000285 IsaVersion Version = getIsaVersion(Features);
Konstantin Zhuravlyovfd871372017-02-09 21:33:23 +0000286 unsigned MaxNumSGPRs = alignDown(getTotalNumSGPRs(Features) / WavesPerEU,
287 getSGPRAllocGranule(Features));
288 unsigned AddressableNumSGPRs = getAddressableNumSGPRs(Features);
289 if (Version.Major >= 8 && !Addressable)
290 AddressableNumSGPRs = 112;
291 return std::min(MaxNumSGPRs, AddressableNumSGPRs);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000292}
293
294unsigned getVGPRAllocGranule(const FeatureBitset &Features) {
295 return 4;
296}
297
298unsigned getVGPREncodingGranule(const FeatureBitset &Features) {
299 return getVGPRAllocGranule(Features);
300}
301
302unsigned getTotalNumVGPRs(const FeatureBitset &Features) {
303 return 256;
304}
305
306unsigned getAddressableNumVGPRs(const FeatureBitset &Features) {
307 return getTotalNumVGPRs(Features);
308}
309
310unsigned getMinNumVGPRs(const FeatureBitset &Features, unsigned WavesPerEU) {
Konstantin Zhuravlyovfd871372017-02-09 21:33:23 +0000311 assert(WavesPerEU != 0);
312
313 if (WavesPerEU >= getMaxWavesPerEU(Features))
314 return 0;
315 unsigned MinNumVGPRs =
316 alignDown(getTotalNumVGPRs(Features) / (WavesPerEU + 1),
317 getVGPRAllocGranule(Features)) + 1;
318 return std::min(MinNumVGPRs, getAddressableNumVGPRs(Features));
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000319}
320
321unsigned getMaxNumVGPRs(const FeatureBitset &Features, unsigned WavesPerEU) {
Konstantin Zhuravlyovfd871372017-02-09 21:33:23 +0000322 assert(WavesPerEU != 0);
323
324 unsigned MaxNumVGPRs = alignDown(getTotalNumVGPRs(Features) / WavesPerEU,
325 getVGPRAllocGranule(Features));
326 unsigned AddressableNumVGPRs = getAddressableNumVGPRs(Features);
327 return std::min(MaxNumVGPRs, AddressableNumVGPRs);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000328}
329
Eugene Zelenkod96089b2017-02-14 00:33:36 +0000330} // end namespace IsaInfo
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000331
Tom Stellardff7416b2015-06-26 21:58:31 +0000332void initDefaultAMDKernelCodeT(amd_kernel_code_t &Header,
333 const FeatureBitset &Features) {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000334 IsaInfo::IsaVersion ISA = IsaInfo::getIsaVersion(Features);
Tom Stellardff7416b2015-06-26 21:58:31 +0000335
336 memset(&Header, 0, sizeof(Header));
337
338 Header.amd_kernel_code_version_major = 1;
Konstantin Zhuravlyov182e9cc2017-02-28 17:17:52 +0000339 Header.amd_kernel_code_version_minor = 1;
Tom Stellardff7416b2015-06-26 21:58:31 +0000340 Header.amd_machine_kind = 1; // AMD_MACHINE_KIND_AMDGPU
341 Header.amd_machine_version_major = ISA.Major;
342 Header.amd_machine_version_minor = ISA.Minor;
343 Header.amd_machine_version_stepping = ISA.Stepping;
344 Header.kernel_code_entry_byte_offset = sizeof(Header);
345 // wavefront_size is specified as a power of 2: 2^6 = 64 threads.
346 Header.wavefront_size = 6;
Matt Arsenault5d910192017-01-25 20:21:57 +0000347
348 // If the code object does not support indirect functions, then the value must
349 // be 0xffffffff.
350 Header.call_convention = -1;
351
Tom Stellardff7416b2015-06-26 21:58:31 +0000352 // These alignment values are specified in powers of two, so alignment =
353 // 2^n. The minimum alignment is 2^4 = 16.
354 Header.kernarg_segment_alignment = 4;
355 Header.group_segment_alignment = 4;
356 Header.private_segment_alignment = 4;
357}
358
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000359bool isGroupSegment(const GlobalValue *GV, AMDGPUAS AS) {
360 return GV->getType()->getAddressSpace() == AS.LOCAL_ADDRESS;
Tom Stellarde3b5aea2015-12-02 17:00:42 +0000361}
362
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000363bool isGlobalSegment(const GlobalValue *GV, AMDGPUAS AS) {
364 return GV->getType()->getAddressSpace() == AS.GLOBAL_ADDRESS;
Tom Stellard00f2f912015-12-02 19:47:57 +0000365}
366
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000367bool isReadOnlySegment(const GlobalValue *GV, AMDGPUAS AS) {
368 return GV->getType()->getAddressSpace() == AS.CONSTANT_ADDRESS;
Tom Stellard00f2f912015-12-02 19:47:57 +0000369}
370
Konstantin Zhuravlyov08326b62016-10-20 18:12:38 +0000371bool shouldEmitConstantsToTextSection(const Triple &TT) {
372 return TT.getOS() != Triple::AMDHSA;
373}
374
Matt Arsenault83002722016-05-12 02:45:18 +0000375int getIntegerAttribute(const Function &F, StringRef Name, int Default) {
Marek Olsakfccabaf2016-01-13 11:45:36 +0000376 Attribute A = F.getFnAttribute(Name);
Matt Arsenault83002722016-05-12 02:45:18 +0000377 int Result = Default;
Tom Stellardac00eb52015-12-15 16:26:16 +0000378
379 if (A.isStringAttribute()) {
380 StringRef Str = A.getValueAsString();
Marek Olsakfccabaf2016-01-13 11:45:36 +0000381 if (Str.getAsInteger(0, Result)) {
Tom Stellardac00eb52015-12-15 16:26:16 +0000382 LLVMContext &Ctx = F.getContext();
Matt Arsenault83002722016-05-12 02:45:18 +0000383 Ctx.emitError("can't parse integer attribute " + Name);
Tom Stellardac00eb52015-12-15 16:26:16 +0000384 }
385 }
Matt Arsenault83002722016-05-12 02:45:18 +0000386
Marek Olsakfccabaf2016-01-13 11:45:36 +0000387 return Result;
388}
389
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000390std::pair<int, int> getIntegerPairAttribute(const Function &F,
391 StringRef Name,
392 std::pair<int, int> Default,
393 bool OnlyFirstRequired) {
394 Attribute A = F.getFnAttribute(Name);
395 if (!A.isStringAttribute())
396 return Default;
397
398 LLVMContext &Ctx = F.getContext();
399 std::pair<int, int> Ints = Default;
400 std::pair<StringRef, StringRef> Strs = A.getValueAsString().split(',');
401 if (Strs.first.trim().getAsInteger(0, Ints.first)) {
402 Ctx.emitError("can't parse first integer attribute " + Name);
403 return Default;
404 }
405 if (Strs.second.trim().getAsInteger(0, Ints.second)) {
Eugene Zelenkod96089b2017-02-14 00:33:36 +0000406 if (!OnlyFirstRequired || !Strs.second.trim().empty()) {
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000407 Ctx.emitError("can't parse second integer attribute " + Name);
408 return Default;
409 }
410 }
411
412 return Ints;
Tom Stellard79a1fd72016-04-14 16:27:07 +0000413}
414
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000415unsigned getVmcntBitMask(const IsaInfo::IsaVersion &Version) {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000416 unsigned VmcntLo = (1 << getVmcntBitWidthLo()) - 1;
417 if (Version.Major < 9)
418 return VmcntLo;
419
420 unsigned VmcntHi = ((1 << getVmcntBitWidthHi()) - 1) << getVmcntBitWidthLo();
421 return VmcntLo | VmcntHi;
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000422}
423
424unsigned getExpcntBitMask(const IsaInfo::IsaVersion &Version) {
425 return (1 << getExpcntBitWidth()) - 1;
426}
427
428unsigned getLgkmcntBitMask(const IsaInfo::IsaVersion &Version) {
429 return (1 << getLgkmcntBitWidth()) - 1;
430}
431
432unsigned getWaitcntBitMask(const IsaInfo::IsaVersion &Version) {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000433 unsigned VmcntLo = getBitMask(getVmcntBitShiftLo(), getVmcntBitWidthLo());
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000434 unsigned Expcnt = getBitMask(getExpcntBitShift(), getExpcntBitWidth());
435 unsigned Lgkmcnt = getBitMask(getLgkmcntBitShift(), getLgkmcntBitWidth());
Matt Arsenaulte823d922017-02-18 18:29:53 +0000436 unsigned Waitcnt = VmcntLo | Expcnt | Lgkmcnt;
437 if (Version.Major < 9)
438 return Waitcnt;
439
440 unsigned VmcntHi = getBitMask(getVmcntBitShiftHi(), getVmcntBitWidthHi());
441 return Waitcnt | VmcntHi;
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +0000442}
443
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000444unsigned decodeVmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt) {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000445 unsigned VmcntLo =
446 unpackBits(Waitcnt, getVmcntBitShiftLo(), getVmcntBitWidthLo());
447 if (Version.Major < 9)
448 return VmcntLo;
449
450 unsigned VmcntHi =
451 unpackBits(Waitcnt, getVmcntBitShiftHi(), getVmcntBitWidthHi());
452 VmcntHi <<= getVmcntBitWidthLo();
453 return VmcntLo | VmcntHi;
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +0000454}
455
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000456unsigned decodeExpcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt) {
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000457 return unpackBits(Waitcnt, getExpcntBitShift(), getExpcntBitWidth());
458}
459
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000460unsigned decodeLgkmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt) {
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000461 return unpackBits(Waitcnt, getLgkmcntBitShift(), getLgkmcntBitWidth());
462}
463
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000464void decodeWaitcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt,
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000465 unsigned &Vmcnt, unsigned &Expcnt, unsigned &Lgkmcnt) {
466 Vmcnt = decodeVmcnt(Version, Waitcnt);
467 Expcnt = decodeExpcnt(Version, Waitcnt);
468 Lgkmcnt = decodeLgkmcnt(Version, Waitcnt);
469}
470
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000471unsigned encodeVmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt,
472 unsigned Vmcnt) {
Matt Arsenaulte823d922017-02-18 18:29:53 +0000473 Waitcnt =
474 packBits(Vmcnt, Waitcnt, getVmcntBitShiftLo(), getVmcntBitWidthLo());
475 if (Version.Major < 9)
476 return Waitcnt;
477
478 Vmcnt >>= getVmcntBitWidthLo();
479 return packBits(Vmcnt, Waitcnt, getVmcntBitShiftHi(), getVmcntBitWidthHi());
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000480}
481
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000482unsigned encodeExpcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt,
483 unsigned Expcnt) {
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000484 return packBits(Expcnt, Waitcnt, getExpcntBitShift(), getExpcntBitWidth());
485}
486
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000487unsigned encodeLgkmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt,
488 unsigned Lgkmcnt) {
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000489 return packBits(Lgkmcnt, Waitcnt, getLgkmcntBitShift(), getLgkmcntBitWidth());
490}
491
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000492unsigned encodeWaitcnt(const IsaInfo::IsaVersion &Version,
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000493 unsigned Vmcnt, unsigned Expcnt, unsigned Lgkmcnt) {
Konstantin Zhuravlyov31dbb032017-01-06 17:23:21 +0000494 unsigned Waitcnt = getWaitcntBitMask(Version);
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000495 Waitcnt = encodeVmcnt(Version, Waitcnt, Vmcnt);
496 Waitcnt = encodeExpcnt(Version, Waitcnt, Expcnt);
497 Waitcnt = encodeLgkmcnt(Version, Waitcnt, Lgkmcnt);
498 return Waitcnt;
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +0000499}
500
Marek Olsakfccabaf2016-01-13 11:45:36 +0000501unsigned getInitialPSInputAddr(const Function &F) {
502 return getIntegerAttribute(F, "InitialPSInputAddr", 0);
Tom Stellardac00eb52015-12-15 16:26:16 +0000503}
504
Nicolai Haehnledf3a20c2016-04-06 19:40:20 +0000505bool isShader(CallingConv::ID cc) {
506 switch(cc) {
507 case CallingConv::AMDGPU_VS:
Tim Renoufef1ae8f2017-09-29 09:51:22 +0000508 case CallingConv::AMDGPU_LS:
Marek Olsaka302a7362017-05-02 15:41:10 +0000509 case CallingConv::AMDGPU_HS:
Tim Renoufef1ae8f2017-09-29 09:51:22 +0000510 case CallingConv::AMDGPU_ES:
Nicolai Haehnledf3a20c2016-04-06 19:40:20 +0000511 case CallingConv::AMDGPU_GS:
512 case CallingConv::AMDGPU_PS:
513 case CallingConv::AMDGPU_CS:
514 return true;
515 default:
516 return false;
517 }
518}
519
520bool isCompute(CallingConv::ID cc) {
521 return !isShader(cc) || cc == CallingConv::AMDGPU_CS;
522}
523
Matt Arsenaulte622dc32017-04-11 22:29:24 +0000524bool isEntryFunctionCC(CallingConv::ID CC) {
Matt Arsenault2b1f9aa2017-05-17 21:56:25 +0000525 switch (CC) {
526 case CallingConv::AMDGPU_KERNEL:
527 case CallingConv::SPIR_KERNEL:
528 case CallingConv::AMDGPU_VS:
529 case CallingConv::AMDGPU_GS:
530 case CallingConv::AMDGPU_PS:
531 case CallingConv::AMDGPU_CS:
Tim Renoufef1ae8f2017-09-29 09:51:22 +0000532 case CallingConv::AMDGPU_ES:
Matt Arsenault2b1f9aa2017-05-17 21:56:25 +0000533 case CallingConv::AMDGPU_HS:
Tim Renoufef1ae8f2017-09-29 09:51:22 +0000534 case CallingConv::AMDGPU_LS:
Matt Arsenault2b1f9aa2017-05-17 21:56:25 +0000535 return true;
536 default:
537 return false;
538 }
Matt Arsenaulte622dc32017-04-11 22:29:24 +0000539}
540
Tom Stellard2b65ed32015-12-21 18:44:27 +0000541bool isSI(const MCSubtargetInfo &STI) {
542 return STI.getFeatureBits()[AMDGPU::FeatureSouthernIslands];
543}
544
545bool isCI(const MCSubtargetInfo &STI) {
546 return STI.getFeatureBits()[AMDGPU::FeatureSeaIslands];
547}
548
549bool isVI(const MCSubtargetInfo &STI) {
550 return STI.getFeatureBits()[AMDGPU::FeatureVolcanicIslands];
551}
552
Sam Koltonf7659d712017-05-23 10:08:55 +0000553bool isGFX9(const MCSubtargetInfo &STI) {
554 return STI.getFeatureBits()[AMDGPU::FeatureGFX9];
555}
556
Matt Arsenault8728c5f2017-08-07 14:58:04 +0000557bool isGCN3Encoding(const MCSubtargetInfo &STI) {
558 return STI.getFeatureBits()[AMDGPU::FeatureGCN3Encoding];
559}
560
Sam Koltonf7659d712017-05-23 10:08:55 +0000561bool isSGPR(unsigned Reg, const MCRegisterInfo* TRI) {
562 const MCRegisterClass SGPRClass = TRI->getRegClass(AMDGPU::SReg_32RegClassID);
563 const unsigned FirstSubReg = TRI->getSubReg(Reg, 1);
564 return SGPRClass.contains(FirstSubReg != 0 ? FirstSubReg : Reg) ||
565 Reg == AMDGPU::SCC;
566}
567
Dmitry Preobrazhenskydc4ac822017-06-21 14:41:34 +0000568bool isRegIntersect(unsigned Reg0, unsigned Reg1, const MCRegisterInfo* TRI) {
Dmitry Preobrazhensky00deef82017-07-18 11:14:02 +0000569 for (MCRegAliasIterator R(Reg0, TRI, true); R.isValid(); ++R) {
570 if (*R == Reg1) return true;
Dmitry Preobrazhenskydc4ac822017-06-21 14:41:34 +0000571 }
Dmitry Preobrazhenskydc4ac822017-06-21 14:41:34 +0000572 return false;
573}
574
Tom Stellard2b65ed32015-12-21 18:44:27 +0000575unsigned getMCReg(unsigned Reg, const MCSubtargetInfo &STI) {
576
577 switch(Reg) {
578 default: break;
579 case AMDGPU::FLAT_SCR:
580 assert(!isSI(STI));
581 return isCI(STI) ? AMDGPU::FLAT_SCR_ci : AMDGPU::FLAT_SCR_vi;
582
583 case AMDGPU::FLAT_SCR_LO:
584 assert(!isSI(STI));
585 return isCI(STI) ? AMDGPU::FLAT_SCR_LO_ci : AMDGPU::FLAT_SCR_LO_vi;
586
587 case AMDGPU::FLAT_SCR_HI:
588 assert(!isSI(STI));
589 return isCI(STI) ? AMDGPU::FLAT_SCR_HI_ci : AMDGPU::FLAT_SCR_HI_vi;
590 }
591 return Reg;
592}
593
Dmitry Preobrazhensky03880f82017-03-03 14:31:06 +0000594unsigned mc2PseudoReg(unsigned Reg) {
595 switch (Reg) {
596 case AMDGPU::FLAT_SCR_ci:
597 case AMDGPU::FLAT_SCR_vi:
598 return FLAT_SCR;
599
600 case AMDGPU::FLAT_SCR_LO_ci:
601 case AMDGPU::FLAT_SCR_LO_vi:
602 return AMDGPU::FLAT_SCR_LO;
603
604 case AMDGPU::FLAT_SCR_HI_ci:
605 case AMDGPU::FLAT_SCR_HI_vi:
606 return AMDGPU::FLAT_SCR_HI;
607
608 default:
609 return Reg;
610 }
611}
612
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000613bool isSISrcOperand(const MCInstrDesc &Desc, unsigned OpNo) {
Artem Tamazov43b61562017-02-03 12:47:30 +0000614 assert(OpNo < Desc.NumOperands);
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000615 unsigned OpType = Desc.OpInfo[OpNo].OperandType;
Matt Arsenault4bd72362016-12-10 00:39:12 +0000616 return OpType >= AMDGPU::OPERAND_SRC_FIRST &&
617 OpType <= AMDGPU::OPERAND_SRC_LAST;
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000618}
619
620bool isSISrcFPOperand(const MCInstrDesc &Desc, unsigned OpNo) {
Artem Tamazov43b61562017-02-03 12:47:30 +0000621 assert(OpNo < Desc.NumOperands);
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000622 unsigned OpType = Desc.OpInfo[OpNo].OperandType;
Matt Arsenault4bd72362016-12-10 00:39:12 +0000623 switch (OpType) {
624 case AMDGPU::OPERAND_REG_IMM_FP32:
625 case AMDGPU::OPERAND_REG_IMM_FP64:
626 case AMDGPU::OPERAND_REG_IMM_FP16:
627 case AMDGPU::OPERAND_REG_INLINE_C_FP32:
628 case AMDGPU::OPERAND_REG_INLINE_C_FP64:
629 case AMDGPU::OPERAND_REG_INLINE_C_FP16:
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000630 case AMDGPU::OPERAND_REG_INLINE_C_V2FP16:
Matt Arsenault4bd72362016-12-10 00:39:12 +0000631 return true;
632 default:
633 return false;
634 }
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000635}
636
637bool isSISrcInlinableOperand(const MCInstrDesc &Desc, unsigned OpNo) {
Artem Tamazov43b61562017-02-03 12:47:30 +0000638 assert(OpNo < Desc.NumOperands);
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000639 unsigned OpType = Desc.OpInfo[OpNo].OperandType;
Matt Arsenault4bd72362016-12-10 00:39:12 +0000640 return OpType >= AMDGPU::OPERAND_REG_INLINE_C_FIRST &&
641 OpType <= AMDGPU::OPERAND_REG_INLINE_C_LAST;
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000642}
643
Krzysztof Parzyszekc8715502016-10-19 17:40:36 +0000644// Avoid using MCRegisterClass::getSize, since that function will go away
645// (move from MC* level to Target* level). Return size in bits.
Tom Stellardb133fbb2016-10-27 23:05:31 +0000646unsigned getRegBitWidth(unsigned RCID) {
647 switch (RCID) {
Krzysztof Parzyszekc8715502016-10-19 17:40:36 +0000648 case AMDGPU::SGPR_32RegClassID:
649 case AMDGPU::VGPR_32RegClassID:
650 case AMDGPU::VS_32RegClassID:
651 case AMDGPU::SReg_32RegClassID:
652 case AMDGPU::SReg_32_XM0RegClassID:
653 return 32;
654 case AMDGPU::SGPR_64RegClassID:
655 case AMDGPU::VS_64RegClassID:
656 case AMDGPU::SReg_64RegClassID:
657 case AMDGPU::VReg_64RegClassID:
658 return 64;
659 case AMDGPU::VReg_96RegClassID:
660 return 96;
661 case AMDGPU::SGPR_128RegClassID:
662 case AMDGPU::SReg_128RegClassID:
663 case AMDGPU::VReg_128RegClassID:
664 return 128;
665 case AMDGPU::SReg_256RegClassID:
666 case AMDGPU::VReg_256RegClassID:
667 return 256;
668 case AMDGPU::SReg_512RegClassID:
669 case AMDGPU::VReg_512RegClassID:
670 return 512;
671 default:
672 llvm_unreachable("Unexpected register class");
673 }
674}
675
Tom Stellardb133fbb2016-10-27 23:05:31 +0000676unsigned getRegBitWidth(const MCRegisterClass &RC) {
677 return getRegBitWidth(RC.getID());
678}
679
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000680unsigned getRegOperandSize(const MCRegisterInfo *MRI, const MCInstrDesc &Desc,
681 unsigned OpNo) {
Artem Tamazov43b61562017-02-03 12:47:30 +0000682 assert(OpNo < Desc.NumOperands);
Krzysztof Parzyszekc8715502016-10-19 17:40:36 +0000683 unsigned RCID = Desc.OpInfo[OpNo].RegClass;
684 return getRegBitWidth(MRI->getRegClass(RCID)) / 8;
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000685}
686
Matt Arsenault26faed32016-12-05 22:26:17 +0000687bool isInlinableLiteral64(int64_t Literal, bool HasInv2Pi) {
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000688 if (Literal >= -16 && Literal <= 64)
689 return true;
690
Matt Arsenault26faed32016-12-05 22:26:17 +0000691 uint64_t Val = static_cast<uint64_t>(Literal);
692 return (Val == DoubleToBits(0.0)) ||
693 (Val == DoubleToBits(1.0)) ||
694 (Val == DoubleToBits(-1.0)) ||
695 (Val == DoubleToBits(0.5)) ||
696 (Val == DoubleToBits(-0.5)) ||
697 (Val == DoubleToBits(2.0)) ||
698 (Val == DoubleToBits(-2.0)) ||
699 (Val == DoubleToBits(4.0)) ||
700 (Val == DoubleToBits(-4.0)) ||
701 (Val == 0x3fc45f306dc9c882 && HasInv2Pi);
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000702}
703
Matt Arsenault26faed32016-12-05 22:26:17 +0000704bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi) {
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000705 if (Literal >= -16 && Literal <= 64)
706 return true;
707
Matt Arsenault4bd72362016-12-10 00:39:12 +0000708 // The actual type of the operand does not seem to matter as long
709 // as the bits match one of the inline immediate values. For example:
710 //
711 // -nan has the hexadecimal encoding of 0xfffffffe which is -2 in decimal,
712 // so it is a legal inline immediate.
713 //
714 // 1065353216 has the hexadecimal encoding 0x3f800000 which is 1.0f in
715 // floating-point, so it is a legal inline immediate.
716
Matt Arsenault26faed32016-12-05 22:26:17 +0000717 uint32_t Val = static_cast<uint32_t>(Literal);
718 return (Val == FloatToBits(0.0f)) ||
719 (Val == FloatToBits(1.0f)) ||
720 (Val == FloatToBits(-1.0f)) ||
721 (Val == FloatToBits(0.5f)) ||
722 (Val == FloatToBits(-0.5f)) ||
723 (Val == FloatToBits(2.0f)) ||
724 (Val == FloatToBits(-2.0f)) ||
725 (Val == FloatToBits(4.0f)) ||
726 (Val == FloatToBits(-4.0f)) ||
727 (Val == 0x3e22f983 && HasInv2Pi);
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000728}
729
Matt Arsenault4bd72362016-12-10 00:39:12 +0000730bool isInlinableLiteral16(int16_t Literal, bool HasInv2Pi) {
Sam Kolton9dffada2017-01-17 15:26:02 +0000731 if (!HasInv2Pi)
732 return false;
Matt Arsenault4bd72362016-12-10 00:39:12 +0000733
734 if (Literal >= -16 && Literal <= 64)
735 return true;
736
737 uint16_t Val = static_cast<uint16_t>(Literal);
738 return Val == 0x3C00 || // 1.0
739 Val == 0xBC00 || // -1.0
740 Val == 0x3800 || // 0.5
741 Val == 0xB800 || // -0.5
742 Val == 0x4000 || // 2.0
743 Val == 0xC000 || // -2.0
744 Val == 0x4400 || // 4.0
745 Val == 0xC400 || // -4.0
746 Val == 0x3118; // 1/2pi
747}
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000748
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000749bool isInlinableLiteralV216(int32_t Literal, bool HasInv2Pi) {
750 assert(HasInv2Pi);
751
Konstantin Zhuravlyov3d1cc882017-04-21 19:45:22 +0000752 if (!EnablePackedInlinableLiterals)
753 return false;
754
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000755 int16_t Lo16 = static_cast<int16_t>(Literal);
756 int16_t Hi16 = static_cast<int16_t>(Literal >> 16);
757 return Lo16 == Hi16 && isInlinableLiteral16(Lo16, HasInv2Pi);
758}
759
Matt Arsenault894e53d2017-07-26 20:39:42 +0000760bool isArgPassedInSGPR(const Argument *A) {
761 const Function *F = A->getParent();
762
763 // Arguments to compute shaders are never a source of divergence.
764 CallingConv::ID CC = F->getCallingConv();
765 switch (CC) {
766 case CallingConv::AMDGPU_KERNEL:
767 case CallingConv::SPIR_KERNEL:
768 return true;
769 case CallingConv::AMDGPU_VS:
Tim Renoufef1ae8f2017-09-29 09:51:22 +0000770 case CallingConv::AMDGPU_LS:
Matt Arsenault894e53d2017-07-26 20:39:42 +0000771 case CallingConv::AMDGPU_HS:
Tim Renoufef1ae8f2017-09-29 09:51:22 +0000772 case CallingConv::AMDGPU_ES:
Matt Arsenault894e53d2017-07-26 20:39:42 +0000773 case CallingConv::AMDGPU_GS:
774 case CallingConv::AMDGPU_PS:
775 case CallingConv::AMDGPU_CS:
776 // For non-compute shaders, SGPR inputs are marked with either inreg or byval.
777 // Everything else is in VGPRs.
778 return F->getAttributes().hasParamAttribute(A->getArgNo(), Attribute::InReg) ||
779 F->getAttributes().hasParamAttribute(A->getArgNo(), Attribute::ByVal);
780 default:
781 // TODO: Should calls support inreg for SGPR inputs?
782 return false;
783 }
784}
785
786// TODO: Should largely merge with AMDGPUTTIImpl::isSourceOfDivergence.
Tom Stellard08efb7e2017-01-27 18:41:14 +0000787bool isUniformMMO(const MachineMemOperand *MMO) {
788 const Value *Ptr = MMO->getValue();
789 // UndefValue means this is a load of a kernel input. These are uniform.
790 // Sometimes LDS instructions have constant pointers.
791 // If Ptr is null, then that means this mem operand contains a
792 // PseudoSourceValue like GOT.
Matt Arsenault894e53d2017-07-26 20:39:42 +0000793 if (!Ptr || isa<UndefValue>(Ptr) ||
Tom Stellard08efb7e2017-01-27 18:41:14 +0000794 isa<Constant>(Ptr) || isa<GlobalValue>(Ptr))
795 return true;
796
Matt Arsenault894e53d2017-07-26 20:39:42 +0000797 if (const Argument *Arg = dyn_cast<Argument>(Ptr))
798 return isArgPassedInSGPR(Arg);
799
Tom Stellard08efb7e2017-01-27 18:41:14 +0000800 const Instruction *I = dyn_cast<Instruction>(Ptr);
801 return I && I->getMetadata("amdgpu.uniform");
802}
803
804int64_t getSMRDEncodedOffset(const MCSubtargetInfo &ST, int64_t ByteOffset) {
Matt Arsenault8728c5f2017-08-07 14:58:04 +0000805 if (isGCN3Encoding(ST))
806 return ByteOffset;
807 return ByteOffset >> 2;
Tom Stellard08efb7e2017-01-27 18:41:14 +0000808}
809
810bool isLegalSMRDImmOffset(const MCSubtargetInfo &ST, int64_t ByteOffset) {
811 int64_t EncodedOffset = getSMRDEncodedOffset(ST, ByteOffset);
Matt Arsenault8728c5f2017-08-07 14:58:04 +0000812 return isGCN3Encoding(ST) ?
813 isUInt<20>(EncodedOffset) : isUInt<8>(EncodedOffset);
Tom Stellard08efb7e2017-01-27 18:41:14 +0000814}
Eugene Zelenkod96089b2017-02-14 00:33:36 +0000815} // end namespace AMDGPU
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000816
Eugene Zelenkod96089b2017-02-14 00:33:36 +0000817} // end namespace llvm
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000818
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000819namespace llvm {
820namespace AMDGPU {
821
822AMDGPUAS getAMDGPUAS(Triple T) {
823 auto Env = T.getEnvironmentName();
824 AMDGPUAS AS;
825 if (Env == "amdgiz" || Env == "amdgizcl") {
826 AS.FLAT_ADDRESS = 0;
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000827 AS.PRIVATE_ADDRESS = 5;
Yaxun Liu76ae47c2017-04-06 19:17:32 +0000828 AS.REGION_ADDRESS = 4;
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000829 }
830 else {
831 AS.FLAT_ADDRESS = 4;
Yaxun Liu1a14bfa2017-03-27 14:04:01 +0000832 AS.PRIVATE_ADDRESS = 0;
833 AS.REGION_ADDRESS = 5;
834 }
835 return AS;
836}
837
838AMDGPUAS getAMDGPUAS(const TargetMachine &M) {
839 return getAMDGPUAS(M.getTargetTriple());
840}
841
842AMDGPUAS getAMDGPUAS(const Module &M) {
843 return getAMDGPUAS(Triple(M.getTargetTriple()));
844}
845} // namespace AMDGPU
846} // namespace llvm