blob: 3b2d5c2bf092ae62412c78fa029d35a843c78552 [file] [log] [blame]
Eugene Zelenkod96089b2017-02-14 00:33:36 +00001//===- AMDGPUBaseInfo.h - Top level definitions for AMDGPU ------*- C++ -*-===//
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//===----------------------------------------------------------------------===//
9
10#ifndef LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUBASEINFO_H
11#define LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUBASEINFO_H
12
Yaxun Liu1a14bfa2017-03-27 14:04:01 +000013#include "AMDGPU.h"
Tom Stellard347ac792015-06-26 21:15:07 +000014#include "AMDKernelCodeT.h"
Matt Arsenault4bd72362016-12-10 00:39:12 +000015#include "SIDefines.h"
Eugene Zelenkod96089b2017-02-14 00:33:36 +000016#include "llvm/ADT/StringRef.h"
17#include "llvm/IR/CallingConv.h"
18#include "llvm/MC/MCInstrDesc.h"
19#include "llvm/Support/Compiler.h"
20#include "llvm/Support/ErrorHandling.h"
21#include <cstdint>
Konstantin Zhuravlyov9c05b2b2017-10-14 15:40:33 +000022#include <string>
Eugene Zelenkod96089b2017-02-14 00:33:36 +000023#include <utility>
Matt Arsenault4bd72362016-12-10 00:39:12 +000024
Tom Stellard347ac792015-06-26 21:15:07 +000025namespace llvm {
26
Matt Arsenault894e53d2017-07-26 20:39:42 +000027class Argument;
Tom Stellard347ac792015-06-26 21:15:07 +000028class FeatureBitset;
Tom Stellardac00eb52015-12-15 16:26:16 +000029class Function;
Tom Stellarde3b5aea2015-12-02 17:00:42 +000030class GlobalValue;
Tom Stellard08efb7e2017-01-27 18:41:14 +000031class MachineMemOperand;
Tom Stellarde135ffd2015-09-25 21:41:28 +000032class MCContext;
Krzysztof Parzyszekc8715502016-10-19 17:40:36 +000033class MCRegisterClass;
Sam Kolton1eeb11b2016-09-09 14:44:04 +000034class MCRegisterInfo;
Tom Stellarde135ffd2015-09-25 21:41:28 +000035class MCSection;
Tom Stellard2b65ed32015-12-21 18:44:27 +000036class MCSubtargetInfo;
Eugene Zelenkod96089b2017-02-14 00:33:36 +000037class Triple;
Tom Stellard347ac792015-06-26 21:15:07 +000038
39namespace AMDGPU {
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +000040namespace IsaInfo {
Sam Koltona3ec5c12016-10-07 14:46:06 +000041
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +000042enum {
43 // The closed Vulkan driver sets 96, which limits the wave count to 8 but
44 // doesn't spill SGPRs as much as when 80 is set.
Konstantin Zhuravlyovc72ece62018-05-16 20:47:48 +000045 FIXED_NUM_SGPRS_FOR_INIT_BUG = 96,
46 TRAP_NUM_SGPRS = 16
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +000047};
48
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000049/// Instruction set architecture version.
Tom Stellard347ac792015-06-26 21:15:07 +000050struct IsaVersion {
51 unsigned Major;
52 unsigned Minor;
53 unsigned Stepping;
54};
55
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +000056/// \returns Isa version for given subtarget \p Features.
Tom Stellard347ac792015-06-26 21:15:07 +000057IsaVersion getIsaVersion(const FeatureBitset &Features);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +000058
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000059/// Streams isa version string for given subtarget \p STI into \p Stream.
Konstantin Zhuravlyov9c05b2b2017-10-14 15:40:33 +000060void streamIsaVersion(const MCSubtargetInfo *STI, raw_ostream &Stream);
61
Konstantin Zhuravlyov00f2cb12018-06-12 18:02:46 +000062/// \returns True if given subtarget \p STI supports code object version 3,
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +000063/// false otherwise.
Konstantin Zhuravlyov00f2cb12018-06-12 18:02:46 +000064bool hasCodeObjectV3(const MCSubtargetInfo *STI);
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +000065
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +000066/// \returns Wavefront size for given subtarget \p Features.
67unsigned getWavefrontSize(const FeatureBitset &Features);
68
69/// \returns Local memory size in bytes for given subtarget \p Features.
70unsigned getLocalMemorySize(const FeatureBitset &Features);
71
72/// \returns Number of execution units per compute unit for given subtarget \p
73/// Features.
74unsigned getEUsPerCU(const FeatureBitset &Features);
75
76/// \returns Maximum number of work groups per compute unit for given subtarget
77/// \p Features and limited by given \p FlatWorkGroupSize.
78unsigned getMaxWorkGroupsPerCU(const FeatureBitset &Features,
79 unsigned FlatWorkGroupSize);
80
81/// \returns Maximum number of waves per compute unit for given subtarget \p
82/// Features without any kind of limitation.
83unsigned getMaxWavesPerCU(const FeatureBitset &Features);
84
85/// \returns Maximum number of waves per compute unit for given subtarget \p
86/// Features and limited by given \p FlatWorkGroupSize.
87unsigned getMaxWavesPerCU(const FeatureBitset &Features,
88 unsigned FlatWorkGroupSize);
89
90/// \returns Minimum number of waves per execution unit for given subtarget \p
91/// Features.
92unsigned getMinWavesPerEU(const FeatureBitset &Features);
93
94/// \returns Maximum number of waves per execution unit for given subtarget \p
95/// Features without any kind of limitation.
96unsigned getMaxWavesPerEU(const FeatureBitset &Features);
97
98/// \returns Maximum number of waves per execution unit for given subtarget \p
99/// Features and limited by given \p FlatWorkGroupSize.
100unsigned getMaxWavesPerEU(const FeatureBitset &Features,
101 unsigned FlatWorkGroupSize);
102
103/// \returns Minimum flat work group size for given subtarget \p Features.
104unsigned getMinFlatWorkGroupSize(const FeatureBitset &Features);
105
106/// \returns Maximum flat work group size for given subtarget \p Features.
107unsigned getMaxFlatWorkGroupSize(const FeatureBitset &Features);
108
109/// \returns Number of waves per work group for given subtarget \p Features and
110/// limited by given \p FlatWorkGroupSize.
111unsigned getWavesPerWorkGroup(const FeatureBitset &Features,
112 unsigned FlatWorkGroupSize);
113
114/// \returns SGPR allocation granularity for given subtarget \p Features.
115unsigned getSGPRAllocGranule(const FeatureBitset &Features);
116
117/// \returns SGPR encoding granularity for given subtarget \p Features.
118unsigned getSGPREncodingGranule(const FeatureBitset &Features);
119
120/// \returns Total number of SGPRs for given subtarget \p Features.
121unsigned getTotalNumSGPRs(const FeatureBitset &Features);
122
123/// \returns Addressable number of SGPRs for given subtarget \p Features.
124unsigned getAddressableNumSGPRs(const FeatureBitset &Features);
125
126/// \returns Minimum number of SGPRs that meets the given number of waves per
127/// execution unit requirement for given subtarget \p Features.
128unsigned getMinNumSGPRs(const FeatureBitset &Features, unsigned WavesPerEU);
129
130/// \returns Maximum number of SGPRs that meets the given number of waves per
131/// execution unit requirement for given subtarget \p Features.
132unsigned getMaxNumSGPRs(const FeatureBitset &Features, unsigned WavesPerEU,
133 bool Addressable);
134
135/// \returns VGPR allocation granularity for given subtarget \p Features.
136unsigned getVGPRAllocGranule(const FeatureBitset &Features);
137
138/// \returns VGPR encoding granularity for given subtarget \p Features.
139unsigned getVGPREncodingGranule(const FeatureBitset &Features);
140
141/// \returns Total number of VGPRs for given subtarget \p Features.
142unsigned getTotalNumVGPRs(const FeatureBitset &Features);
143
144/// \returns Addressable number of VGPRs for given subtarget \p Features.
145unsigned getAddressableNumVGPRs(const FeatureBitset &Features);
146
147/// \returns Minimum number of VGPRs that meets given number of waves per
148/// execution unit requirement for given subtarget \p Features.
149unsigned getMinNumVGPRs(const FeatureBitset &Features, unsigned WavesPerEU);
150
151/// \returns Maximum number of VGPRs that meets given number of waves per
152/// execution unit requirement for given subtarget \p Features.
153unsigned getMaxNumVGPRs(const FeatureBitset &Features, unsigned WavesPerEU);
154
Eugene Zelenkod96089b2017-02-14 00:33:36 +0000155} // end namespace IsaInfo
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000156
157LLVM_READONLY
158int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx);
159
Matt Arsenaultcad7fa82017-12-13 21:07:51 +0000160LLVM_READONLY
161int getMaskedMIMGOp(const MCInstrInfo &MII,
162 unsigned Opc, unsigned NewChannels);
Dmitry Preobrazhensky0b4eb1e2018-01-26 15:43:29 +0000163
164LLVM_READONLY
165int getMaskedMIMGAtomicOp(const MCInstrInfo &MII,
166 unsigned Opc, unsigned NewChannels);
167
Matt Arsenaultcad7fa82017-12-13 21:07:51 +0000168LLVM_READONLY
Nicolai Haehnlef2674312018-06-21 13:36:01 +0000169int getMIMGGatherOpPackedD16(uint16_t Opcode);
170
171LLVM_READONLY
Matt Arsenaultcad7fa82017-12-13 21:07:51 +0000172int getMCOpcode(uint16_t Opcode, unsigned Gen);
173
Tom Stellardff7416b2015-06-26 21:58:31 +0000174void initDefaultAMDKernelCodeT(amd_kernel_code_t &Header,
175 const FeatureBitset &Features);
Tom Stellard9760f032015-12-03 03:34:32 +0000176
Konstantin Zhuravlyov435151a2017-11-01 19:12:38 +0000177bool isGroupSegment(const GlobalValue *GV);
178bool isGlobalSegment(const GlobalValue *GV);
179bool isReadOnlySegment(const GlobalValue *GV);
Tom Stellarde3b5aea2015-12-02 17:00:42 +0000180
Konstantin Zhuravlyov08326b62016-10-20 18:12:38 +0000181/// \returns True if constants should be emitted to .text section for given
182/// target triple \p TT, false otherwise.
183bool shouldEmitConstantsToTextSection(const Triple &TT);
184
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000185/// \returns Integer value requested using \p F's \p Name attribute.
186///
187/// \returns \p Default if attribute is not present.
188///
189/// \returns \p Default and emits error if requested value cannot be converted
190/// to integer.
Matt Arsenault83002722016-05-12 02:45:18 +0000191int getIntegerAttribute(const Function &F, StringRef Name, int Default);
192
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000193/// \returns A pair of integer values requested using \p F's \p Name attribute
194/// in "first[,second]" format ("second" is optional unless \p OnlyFirstRequired
195/// is false).
196///
197/// \returns \p Default if attribute is not present.
198///
199/// \returns \p Default and emits error if one of the requested values cannot be
200/// converted to integer, or \p OnlyFirstRequired is false and "second" value is
201/// not present.
202std::pair<int, int> getIntegerPairAttribute(const Function &F,
203 StringRef Name,
204 std::pair<int, int> Default,
205 bool OnlyFirstRequired = false);
206
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000207/// \returns Vmcnt bit mask for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000208unsigned getVmcntBitMask(const IsaInfo::IsaVersion &Version);
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +0000209
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000210/// \returns Expcnt bit mask for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000211unsigned getExpcntBitMask(const IsaInfo::IsaVersion &Version);
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +0000212
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000213/// \returns Lgkmcnt bit mask for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000214unsigned getLgkmcntBitMask(const IsaInfo::IsaVersion &Version);
215
216/// \returns Waitcnt bit mask for given isa \p Version.
217unsigned getWaitcntBitMask(const IsaInfo::IsaVersion &Version);
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +0000218
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000219/// \returns Decoded Vmcnt from given \p Waitcnt for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000220unsigned decodeVmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt);
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +0000221
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000222/// \returns Decoded Expcnt from given \p Waitcnt for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000223unsigned decodeExpcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt);
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000224
225/// \returns Decoded Lgkmcnt from given \p Waitcnt for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000226unsigned decodeLgkmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt);
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000227
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000228/// Decodes Vmcnt, Expcnt and Lgkmcnt from given \p Waitcnt for given isa
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000229/// \p Version, and writes decoded values into \p Vmcnt, \p Expcnt and
230/// \p Lgkmcnt respectively.
231///
232/// \details \p Vmcnt, \p Expcnt and \p Lgkmcnt are decoded as follows:
Matt Arsenaulte823d922017-02-18 18:29:53 +0000233/// \p Vmcnt = \p Waitcnt[3:0] (pre-gfx9 only)
234/// \p Vmcnt = \p Waitcnt[3:0] | \p Waitcnt[15:14] (gfx9+ only)
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000235/// \p Expcnt = \p Waitcnt[6:4]
236/// \p Lgkmcnt = \p Waitcnt[11:8]
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000237void decodeWaitcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt,
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000238 unsigned &Vmcnt, unsigned &Expcnt, unsigned &Lgkmcnt);
239
240/// \returns \p Waitcnt with encoded \p Vmcnt for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000241unsigned encodeVmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt,
242 unsigned Vmcnt);
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000243
244/// \returns \p Waitcnt with encoded \p Expcnt for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000245unsigned encodeExpcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt,
246 unsigned Expcnt);
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000247
248/// \returns \p Waitcnt with encoded \p Lgkmcnt for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000249unsigned encodeLgkmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt,
250 unsigned Lgkmcnt);
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000251
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000252/// Encodes \p Vmcnt, \p Expcnt and \p Lgkmcnt into Waitcnt for given isa
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000253/// \p Version.
254///
255/// \details \p Vmcnt, \p Expcnt and \p Lgkmcnt are encoded as follows:
Matt Arsenaulte823d922017-02-18 18:29:53 +0000256/// Waitcnt[3:0] = \p Vmcnt (pre-gfx9 only)
257/// Waitcnt[3:0] = \p Vmcnt[3:0] (gfx9+ only)
258/// Waitcnt[6:4] = \p Expcnt
259/// Waitcnt[11:8] = \p Lgkmcnt
260/// Waitcnt[15:14] = \p Vmcnt[5:4] (gfx9+ only)
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000261///
262/// \returns Waitcnt with encoded \p Vmcnt, \p Expcnt and \p Lgkmcnt for given
263/// isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000264unsigned encodeWaitcnt(const IsaInfo::IsaVersion &Version,
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000265 unsigned Vmcnt, unsigned Expcnt, unsigned Lgkmcnt);
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +0000266
Marek Olsakfccabaf2016-01-13 11:45:36 +0000267unsigned getInitialPSInputAddr(const Function &F);
268
Matt Arsenaulte622dc32017-04-11 22:29:24 +0000269LLVM_READNONE
270bool isShader(CallingConv::ID CC);
271
272LLVM_READNONE
273bool isCompute(CallingConv::ID CC);
274
275LLVM_READNONE
276bool isEntryFunctionCC(CallingConv::ID CC);
277
Matt Arsenaultefa9f4b2017-04-11 22:29:28 +0000278// FIXME: Remove this when calling conventions cleaned up
279LLVM_READNONE
280inline bool isKernel(CallingConv::ID CC) {
281 switch (CC) {
Matt Arsenaultefa9f4b2017-04-11 22:29:28 +0000282 case CallingConv::AMDGPU_KERNEL:
283 case CallingConv::SPIR_KERNEL:
284 return true;
285 default:
286 return false;
287 }
288}
Tom Stellardac00eb52015-12-15 16:26:16 +0000289
Dmitry Preobrazhensky3afbd822018-01-10 14:22:19 +0000290bool hasXNACK(const MCSubtargetInfo &STI);
Dmitry Preobrazhenskye3271ae2018-02-05 12:45:43 +0000291bool hasMIMG_R128(const MCSubtargetInfo &STI);
Dmitry Preobrazhensky0a1ff462018-02-05 14:18:53 +0000292bool hasPackedD16(const MCSubtargetInfo &STI);
Dmitry Preobrazhenskye3271ae2018-02-05 12:45:43 +0000293
Tom Stellard2b65ed32015-12-21 18:44:27 +0000294bool isSI(const MCSubtargetInfo &STI);
295bool isCI(const MCSubtargetInfo &STI);
296bool isVI(const MCSubtargetInfo &STI);
Sam Koltonf7659d712017-05-23 10:08:55 +0000297bool isGFX9(const MCSubtargetInfo &STI);
298
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000299/// Is Reg - scalar register
Sam Koltonf7659d712017-05-23 10:08:55 +0000300bool isSGPR(unsigned Reg, const MCRegisterInfo* TRI);
Tom Stellard2b65ed32015-12-21 18:44:27 +0000301
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000302/// Is there any intersection between registers
Dmitry Preobrazhenskydc4ac822017-06-21 14:41:34 +0000303bool isRegIntersect(unsigned Reg0, unsigned Reg1, const MCRegisterInfo* TRI);
304
Tom Stellard2b65ed32015-12-21 18:44:27 +0000305/// If \p Reg is a pseudo reg, return the correct hardware register given
306/// \p STI otherwise return \p Reg.
307unsigned getMCReg(unsigned Reg, const MCSubtargetInfo &STI);
308
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000309/// Convert hardware register \p Reg to a pseudo register
Dmitry Preobrazhensky03880f82017-03-03 14:31:06 +0000310LLVM_READNONE
311unsigned mc2PseudoReg(unsigned Reg);
312
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000313/// Can this operand also contain immediate values?
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000314bool isSISrcOperand(const MCInstrDesc &Desc, unsigned OpNo);
315
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000316/// Is this floating-point operand?
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000317bool isSISrcFPOperand(const MCInstrDesc &Desc, unsigned OpNo);
318
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000319/// Does this opearnd support only inlinable literals?
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000320bool isSISrcInlinableOperand(const MCInstrDesc &Desc, unsigned OpNo);
321
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000322/// Get the size in bits of a register from the register class \p RC.
Tom Stellardb133fbb2016-10-27 23:05:31 +0000323unsigned getRegBitWidth(unsigned RCID);
324
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000325/// Get the size in bits of a register from the register class \p RC.
Krzysztof Parzyszekc8715502016-10-19 17:40:36 +0000326unsigned getRegBitWidth(const MCRegisterClass &RC);
327
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000328/// Get size of register operand
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000329unsigned getRegOperandSize(const MCRegisterInfo *MRI, const MCInstrDesc &Desc,
330 unsigned OpNo);
331
Matt Arsenault4bd72362016-12-10 00:39:12 +0000332LLVM_READNONE
333inline unsigned getOperandSize(const MCOperandInfo &OpInfo) {
334 switch (OpInfo.OperandType) {
335 case AMDGPU::OPERAND_REG_IMM_INT32:
336 case AMDGPU::OPERAND_REG_IMM_FP32:
337 case AMDGPU::OPERAND_REG_INLINE_C_INT32:
338 case AMDGPU::OPERAND_REG_INLINE_C_FP32:
339 return 4;
340
341 case AMDGPU::OPERAND_REG_IMM_INT64:
342 case AMDGPU::OPERAND_REG_IMM_FP64:
343 case AMDGPU::OPERAND_REG_INLINE_C_INT64:
344 case AMDGPU::OPERAND_REG_INLINE_C_FP64:
345 return 8;
346
347 case AMDGPU::OPERAND_REG_IMM_INT16:
348 case AMDGPU::OPERAND_REG_IMM_FP16:
349 case AMDGPU::OPERAND_REG_INLINE_C_INT16:
350 case AMDGPU::OPERAND_REG_INLINE_C_FP16:
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000351 case AMDGPU::OPERAND_REG_INLINE_C_V2INT16:
352 case AMDGPU::OPERAND_REG_INLINE_C_V2FP16:
Matt Arsenault4bd72362016-12-10 00:39:12 +0000353 return 2;
354
355 default:
356 llvm_unreachable("unhandled operand type");
357 }
358}
359
360LLVM_READNONE
361inline unsigned getOperandSize(const MCInstrDesc &Desc, unsigned OpNo) {
362 return getOperandSize(Desc.OpInfo[OpNo]);
363}
364
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000365/// Is this literal inlinable
Matt Arsenault26faed32016-12-05 22:26:17 +0000366LLVM_READNONE
367bool isInlinableLiteral64(int64_t Literal, bool HasInv2Pi);
368
369LLVM_READNONE
370bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi);
371
Matt Arsenault4bd72362016-12-10 00:39:12 +0000372LLVM_READNONE
373bool isInlinableLiteral16(int16_t Literal, bool HasInv2Pi);
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000374
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000375LLVM_READNONE
376bool isInlinableLiteralV216(int32_t Literal, bool HasInv2Pi);
377
Matt Arsenault894e53d2017-07-26 20:39:42 +0000378bool isArgPassedInSGPR(const Argument *Arg);
Tom Stellard08efb7e2017-01-27 18:41:14 +0000379
380/// \returns The encoding that will be used for \p ByteOffset in the SMRD
381/// offset field.
382int64_t getSMRDEncodedOffset(const MCSubtargetInfo &ST, int64_t ByteOffset);
383
384/// \returns true if this offset is small enough to fit in the SMRD
385/// offset field. \p ByteOffset should be the offset in bytes and
386/// not the encoded offset.
387bool isLegalSMRDImmOffset(const MCSubtargetInfo &ST, int64_t ByteOffset);
388
Alexander Timofeev2e5eece2018-03-05 15:12:21 +0000389/// \returns true if the intrinsic is divergent
390bool isIntrinsicSourceOfDivergence(unsigned IntrID);
391
Tom Stellard347ac792015-06-26 21:15:07 +0000392} // end namespace AMDGPU
393} // end namespace llvm
394
Eugene Zelenkod96089b2017-02-14 00:33:36 +0000395#endif // LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUBASEINFO_H