blob: a59571c49c6f59c6bd94a1d35c6c24f0af9714dc [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 {
Nicolai Haehnle0ab200b2018-06-21 13:36:44 +000040
41#define GET_MIMGBaseOpcode_DECL
Nicolai Haehnle7a9c03f2018-06-21 13:36:57 +000042#define GET_MIMGDim_DECL
Nicolai Haehnle0ab200b2018-06-21 13:36:44 +000043#define GET_MIMGEncoding_DECL
44#include "AMDGPUGenSearchableTables.inc"
45
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +000046namespace IsaInfo {
Sam Koltona3ec5c12016-10-07 14:46:06 +000047
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +000048enum {
49 // The closed Vulkan driver sets 96, which limits the wave count to 8 but
50 // doesn't spill SGPRs as much as when 80 is set.
Konstantin Zhuravlyovc72ece62018-05-16 20:47:48 +000051 FIXED_NUM_SGPRS_FOR_INIT_BUG = 96,
52 TRAP_NUM_SGPRS = 16
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +000053};
54
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000055/// Instruction set architecture version.
Tom Stellard347ac792015-06-26 21:15:07 +000056struct IsaVersion {
57 unsigned Major;
58 unsigned Minor;
59 unsigned Stepping;
60};
61
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +000062/// \returns Isa version for given subtarget \p Features.
Tom Stellard347ac792015-06-26 21:15:07 +000063IsaVersion getIsaVersion(const FeatureBitset &Features);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +000064
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000065/// Streams isa version string for given subtarget \p STI into \p Stream.
Konstantin Zhuravlyov9c05b2b2017-10-14 15:40:33 +000066void streamIsaVersion(const MCSubtargetInfo *STI, raw_ostream &Stream);
67
Konstantin Zhuravlyov00f2cb12018-06-12 18:02:46 +000068/// \returns True if given subtarget \p STI supports code object version 3,
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +000069/// false otherwise.
Konstantin Zhuravlyov00f2cb12018-06-12 18:02:46 +000070bool hasCodeObjectV3(const MCSubtargetInfo *STI);
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +000071
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +000072/// \returns Wavefront size for given subtarget \p Features.
73unsigned getWavefrontSize(const FeatureBitset &Features);
74
75/// \returns Local memory size in bytes for given subtarget \p Features.
76unsigned getLocalMemorySize(const FeatureBitset &Features);
77
78/// \returns Number of execution units per compute unit for given subtarget \p
79/// Features.
80unsigned getEUsPerCU(const FeatureBitset &Features);
81
82/// \returns Maximum number of work groups per compute unit for given subtarget
83/// \p Features and limited by given \p FlatWorkGroupSize.
84unsigned getMaxWorkGroupsPerCU(const FeatureBitset &Features,
85 unsigned FlatWorkGroupSize);
86
87/// \returns Maximum number of waves per compute unit for given subtarget \p
88/// Features without any kind of limitation.
89unsigned getMaxWavesPerCU(const FeatureBitset &Features);
90
91/// \returns Maximum number of waves per compute unit for given subtarget \p
92/// Features and limited by given \p FlatWorkGroupSize.
93unsigned getMaxWavesPerCU(const FeatureBitset &Features,
94 unsigned FlatWorkGroupSize);
95
96/// \returns Minimum number of waves per execution unit for given subtarget \p
97/// Features.
98unsigned getMinWavesPerEU(const FeatureBitset &Features);
99
100/// \returns Maximum number of waves per execution unit for given subtarget \p
101/// Features without any kind of limitation.
102unsigned getMaxWavesPerEU(const FeatureBitset &Features);
103
104/// \returns Maximum number of waves per execution unit for given subtarget \p
105/// Features and limited by given \p FlatWorkGroupSize.
106unsigned getMaxWavesPerEU(const FeatureBitset &Features,
107 unsigned FlatWorkGroupSize);
108
109/// \returns Minimum flat work group size for given subtarget \p Features.
110unsigned getMinFlatWorkGroupSize(const FeatureBitset &Features);
111
112/// \returns Maximum flat work group size for given subtarget \p Features.
113unsigned getMaxFlatWorkGroupSize(const FeatureBitset &Features);
114
115/// \returns Number of waves per work group for given subtarget \p Features and
116/// limited by given \p FlatWorkGroupSize.
117unsigned getWavesPerWorkGroup(const FeatureBitset &Features,
118 unsigned FlatWorkGroupSize);
119
120/// \returns SGPR allocation granularity for given subtarget \p Features.
121unsigned getSGPRAllocGranule(const FeatureBitset &Features);
122
123/// \returns SGPR encoding granularity for given subtarget \p Features.
124unsigned getSGPREncodingGranule(const FeatureBitset &Features);
125
126/// \returns Total number of SGPRs for given subtarget \p Features.
127unsigned getTotalNumSGPRs(const FeatureBitset &Features);
128
129/// \returns Addressable number of SGPRs for given subtarget \p Features.
130unsigned getAddressableNumSGPRs(const FeatureBitset &Features);
131
132/// \returns Minimum number of SGPRs that meets the given number of waves per
133/// execution unit requirement for given subtarget \p Features.
134unsigned getMinNumSGPRs(const FeatureBitset &Features, unsigned WavesPerEU);
135
136/// \returns Maximum number of SGPRs that meets the given number of waves per
137/// execution unit requirement for given subtarget \p Features.
138unsigned getMaxNumSGPRs(const FeatureBitset &Features, unsigned WavesPerEU,
139 bool Addressable);
140
141/// \returns VGPR allocation granularity for given subtarget \p Features.
142unsigned getVGPRAllocGranule(const FeatureBitset &Features);
143
144/// \returns VGPR encoding granularity for given subtarget \p Features.
145unsigned getVGPREncodingGranule(const FeatureBitset &Features);
146
147/// \returns Total number of VGPRs for given subtarget \p Features.
148unsigned getTotalNumVGPRs(const FeatureBitset &Features);
149
150/// \returns Addressable number of VGPRs for given subtarget \p Features.
151unsigned getAddressableNumVGPRs(const FeatureBitset &Features);
152
153/// \returns Minimum number of VGPRs that meets given number of waves per
154/// execution unit requirement for given subtarget \p Features.
155unsigned getMinNumVGPRs(const FeatureBitset &Features, unsigned WavesPerEU);
156
157/// \returns Maximum number of VGPRs that meets given number of waves per
158/// execution unit requirement for given subtarget \p Features.
159unsigned getMaxNumVGPRs(const FeatureBitset &Features, unsigned WavesPerEU);
160
Eugene Zelenkod96089b2017-02-14 00:33:36 +0000161} // end namespace IsaInfo
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000162
163LLVM_READONLY
164int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx);
165
Nicolai Haehnle7a9c03f2018-06-21 13:36:57 +0000166struct MIMGBaseOpcodeInfo {
167 MIMGBaseOpcode BaseOpcode;
168 bool Store;
169 bool Atomic;
170 bool AtomicX2;
171 bool Sampler;
172
173 uint8_t NumExtraArgs;
174 bool Gradients;
175 bool Coordinates;
176 bool LodOrClampOrMip;
177 bool HasD16;
178};
179
180LLVM_READONLY
181const MIMGBaseOpcodeInfo *getMIMGBaseOpcodeInfo(unsigned BaseOpcode);
182
183struct MIMGDimInfo {
184 MIMGDim Dim;
185 uint8_t NumCoords;
186 uint8_t NumGradients;
187 bool DA;
188};
189
190LLVM_READONLY
191const MIMGDimInfo *getMIMGDimInfo(unsigned Dim);
192
193LLVM_READONLY
194int getMIMGOpcode(unsigned BaseOpcode, unsigned MIMGEncoding,
195 unsigned VDataDwords, unsigned VAddrDwords);
196
Matt Arsenaultcad7fa82017-12-13 21:07:51 +0000197LLVM_READONLY
Nicolai Haehnle0ab200b2018-06-21 13:36:44 +0000198int getMaskedMIMGOp(unsigned Opc, unsigned NewChannels);
Nicolai Haehnlef2674312018-06-21 13:36:01 +0000199
200LLVM_READONLY
Matt Arsenaultcad7fa82017-12-13 21:07:51 +0000201int getMCOpcode(uint16_t Opcode, unsigned Gen);
202
Tom Stellardff7416b2015-06-26 21:58:31 +0000203void initDefaultAMDKernelCodeT(amd_kernel_code_t &Header,
204 const FeatureBitset &Features);
Tom Stellard9760f032015-12-03 03:34:32 +0000205
Konstantin Zhuravlyov435151a2017-11-01 19:12:38 +0000206bool isGroupSegment(const GlobalValue *GV);
207bool isGlobalSegment(const GlobalValue *GV);
208bool isReadOnlySegment(const GlobalValue *GV);
Tom Stellarde3b5aea2015-12-02 17:00:42 +0000209
Konstantin Zhuravlyov08326b62016-10-20 18:12:38 +0000210/// \returns True if constants should be emitted to .text section for given
211/// target triple \p TT, false otherwise.
212bool shouldEmitConstantsToTextSection(const Triple &TT);
213
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000214/// \returns Integer value requested using \p F's \p Name attribute.
215///
216/// \returns \p Default if attribute is not present.
217///
218/// \returns \p Default and emits error if requested value cannot be converted
219/// to integer.
Matt Arsenault83002722016-05-12 02:45:18 +0000220int getIntegerAttribute(const Function &F, StringRef Name, int Default);
221
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000222/// \returns A pair of integer values requested using \p F's \p Name attribute
223/// in "first[,second]" format ("second" is optional unless \p OnlyFirstRequired
224/// is false).
225///
226/// \returns \p Default if attribute is not present.
227///
228/// \returns \p Default and emits error if one of the requested values cannot be
229/// converted to integer, or \p OnlyFirstRequired is false and "second" value is
230/// not present.
231std::pair<int, int> getIntegerPairAttribute(const Function &F,
232 StringRef Name,
233 std::pair<int, int> Default,
234 bool OnlyFirstRequired = false);
235
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000236/// \returns Vmcnt bit mask for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000237unsigned getVmcntBitMask(const IsaInfo::IsaVersion &Version);
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +0000238
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000239/// \returns Expcnt bit mask for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000240unsigned getExpcntBitMask(const IsaInfo::IsaVersion &Version);
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +0000241
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000242/// \returns Lgkmcnt bit mask for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000243unsigned getLgkmcntBitMask(const IsaInfo::IsaVersion &Version);
244
245/// \returns Waitcnt bit mask for given isa \p Version.
246unsigned getWaitcntBitMask(const IsaInfo::IsaVersion &Version);
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +0000247
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000248/// \returns Decoded Vmcnt from given \p Waitcnt for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000249unsigned decodeVmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt);
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +0000250
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000251/// \returns Decoded Expcnt from given \p Waitcnt for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000252unsigned decodeExpcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt);
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000253
254/// \returns Decoded Lgkmcnt from given \p Waitcnt for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000255unsigned decodeLgkmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt);
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000256
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000257/// Decodes Vmcnt, Expcnt and Lgkmcnt from given \p Waitcnt for given isa
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000258/// \p Version, and writes decoded values into \p Vmcnt, \p Expcnt and
259/// \p Lgkmcnt respectively.
260///
261/// \details \p Vmcnt, \p Expcnt and \p Lgkmcnt are decoded as follows:
Matt Arsenaulte823d922017-02-18 18:29:53 +0000262/// \p Vmcnt = \p Waitcnt[3:0] (pre-gfx9 only)
263/// \p Vmcnt = \p Waitcnt[3:0] | \p Waitcnt[15:14] (gfx9+ only)
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000264/// \p Expcnt = \p Waitcnt[6:4]
265/// \p Lgkmcnt = \p Waitcnt[11:8]
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000266void decodeWaitcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt,
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000267 unsigned &Vmcnt, unsigned &Expcnt, unsigned &Lgkmcnt);
268
269/// \returns \p Waitcnt with encoded \p Vmcnt for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000270unsigned encodeVmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt,
271 unsigned Vmcnt);
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000272
273/// \returns \p Waitcnt with encoded \p Expcnt for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000274unsigned encodeExpcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt,
275 unsigned Expcnt);
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000276
277/// \returns \p Waitcnt with encoded \p Lgkmcnt for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000278unsigned encodeLgkmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt,
279 unsigned Lgkmcnt);
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000280
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000281/// Encodes \p Vmcnt, \p Expcnt and \p Lgkmcnt into Waitcnt for given isa
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000282/// \p Version.
283///
284/// \details \p Vmcnt, \p Expcnt and \p Lgkmcnt are encoded as follows:
Matt Arsenaulte823d922017-02-18 18:29:53 +0000285/// Waitcnt[3:0] = \p Vmcnt (pre-gfx9 only)
286/// Waitcnt[3:0] = \p Vmcnt[3:0] (gfx9+ only)
287/// Waitcnt[6:4] = \p Expcnt
288/// Waitcnt[11:8] = \p Lgkmcnt
289/// Waitcnt[15:14] = \p Vmcnt[5:4] (gfx9+ only)
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000290///
291/// \returns Waitcnt with encoded \p Vmcnt, \p Expcnt and \p Lgkmcnt for given
292/// isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000293unsigned encodeWaitcnt(const IsaInfo::IsaVersion &Version,
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000294 unsigned Vmcnt, unsigned Expcnt, unsigned Lgkmcnt);
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +0000295
Marek Olsakfccabaf2016-01-13 11:45:36 +0000296unsigned getInitialPSInputAddr(const Function &F);
297
Matt Arsenaulte622dc32017-04-11 22:29:24 +0000298LLVM_READNONE
299bool isShader(CallingConv::ID CC);
300
301LLVM_READNONE
302bool isCompute(CallingConv::ID CC);
303
304LLVM_READNONE
305bool isEntryFunctionCC(CallingConv::ID CC);
306
Matt Arsenaultefa9f4b2017-04-11 22:29:28 +0000307// FIXME: Remove this when calling conventions cleaned up
308LLVM_READNONE
309inline bool isKernel(CallingConv::ID CC) {
310 switch (CC) {
Matt Arsenaultefa9f4b2017-04-11 22:29:28 +0000311 case CallingConv::AMDGPU_KERNEL:
312 case CallingConv::SPIR_KERNEL:
313 return true;
314 default:
315 return false;
316 }
317}
Tom Stellardac00eb52015-12-15 16:26:16 +0000318
Dmitry Preobrazhensky3afbd822018-01-10 14:22:19 +0000319bool hasXNACK(const MCSubtargetInfo &STI);
Dmitry Preobrazhenskye3271ae2018-02-05 12:45:43 +0000320bool hasMIMG_R128(const MCSubtargetInfo &STI);
Dmitry Preobrazhensky0a1ff462018-02-05 14:18:53 +0000321bool hasPackedD16(const MCSubtargetInfo &STI);
Dmitry Preobrazhenskye3271ae2018-02-05 12:45:43 +0000322
Tom Stellard2b65ed32015-12-21 18:44:27 +0000323bool isSI(const MCSubtargetInfo &STI);
324bool isCI(const MCSubtargetInfo &STI);
325bool isVI(const MCSubtargetInfo &STI);
Sam Koltonf7659d712017-05-23 10:08:55 +0000326bool isGFX9(const MCSubtargetInfo &STI);
327
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000328/// Is Reg - scalar register
Sam Koltonf7659d712017-05-23 10:08:55 +0000329bool isSGPR(unsigned Reg, const MCRegisterInfo* TRI);
Tom Stellard2b65ed32015-12-21 18:44:27 +0000330
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000331/// Is there any intersection between registers
Dmitry Preobrazhenskydc4ac822017-06-21 14:41:34 +0000332bool isRegIntersect(unsigned Reg0, unsigned Reg1, const MCRegisterInfo* TRI);
333
Tom Stellard2b65ed32015-12-21 18:44:27 +0000334/// If \p Reg is a pseudo reg, return the correct hardware register given
335/// \p STI otherwise return \p Reg.
336unsigned getMCReg(unsigned Reg, const MCSubtargetInfo &STI);
337
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000338/// Convert hardware register \p Reg to a pseudo register
Dmitry Preobrazhensky03880f82017-03-03 14:31:06 +0000339LLVM_READNONE
340unsigned mc2PseudoReg(unsigned Reg);
341
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000342/// Can this operand also contain immediate values?
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000343bool isSISrcOperand(const MCInstrDesc &Desc, unsigned OpNo);
344
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000345/// Is this floating-point operand?
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000346bool isSISrcFPOperand(const MCInstrDesc &Desc, unsigned OpNo);
347
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000348/// Does this opearnd support only inlinable literals?
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000349bool isSISrcInlinableOperand(const MCInstrDesc &Desc, unsigned OpNo);
350
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000351/// Get the size in bits of a register from the register class \p RC.
Tom Stellardb133fbb2016-10-27 23:05:31 +0000352unsigned getRegBitWidth(unsigned RCID);
353
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000354/// Get the size in bits of a register from the register class \p RC.
Krzysztof Parzyszekc8715502016-10-19 17:40:36 +0000355unsigned getRegBitWidth(const MCRegisterClass &RC);
356
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000357/// Get size of register operand
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000358unsigned getRegOperandSize(const MCRegisterInfo *MRI, const MCInstrDesc &Desc,
359 unsigned OpNo);
360
Matt Arsenault4bd72362016-12-10 00:39:12 +0000361LLVM_READNONE
362inline unsigned getOperandSize(const MCOperandInfo &OpInfo) {
363 switch (OpInfo.OperandType) {
364 case AMDGPU::OPERAND_REG_IMM_INT32:
365 case AMDGPU::OPERAND_REG_IMM_FP32:
366 case AMDGPU::OPERAND_REG_INLINE_C_INT32:
367 case AMDGPU::OPERAND_REG_INLINE_C_FP32:
368 return 4;
369
370 case AMDGPU::OPERAND_REG_IMM_INT64:
371 case AMDGPU::OPERAND_REG_IMM_FP64:
372 case AMDGPU::OPERAND_REG_INLINE_C_INT64:
373 case AMDGPU::OPERAND_REG_INLINE_C_FP64:
374 return 8;
375
376 case AMDGPU::OPERAND_REG_IMM_INT16:
377 case AMDGPU::OPERAND_REG_IMM_FP16:
378 case AMDGPU::OPERAND_REG_INLINE_C_INT16:
379 case AMDGPU::OPERAND_REG_INLINE_C_FP16:
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000380 case AMDGPU::OPERAND_REG_INLINE_C_V2INT16:
381 case AMDGPU::OPERAND_REG_INLINE_C_V2FP16:
Matt Arsenault4bd72362016-12-10 00:39:12 +0000382 return 2;
383
384 default:
385 llvm_unreachable("unhandled operand type");
386 }
387}
388
389LLVM_READNONE
390inline unsigned getOperandSize(const MCInstrDesc &Desc, unsigned OpNo) {
391 return getOperandSize(Desc.OpInfo[OpNo]);
392}
393
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000394/// Is this literal inlinable
Matt Arsenault26faed32016-12-05 22:26:17 +0000395LLVM_READNONE
396bool isInlinableLiteral64(int64_t Literal, bool HasInv2Pi);
397
398LLVM_READNONE
399bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi);
400
Matt Arsenault4bd72362016-12-10 00:39:12 +0000401LLVM_READNONE
402bool isInlinableLiteral16(int16_t Literal, bool HasInv2Pi);
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000403
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000404LLVM_READNONE
405bool isInlinableLiteralV216(int32_t Literal, bool HasInv2Pi);
406
Matt Arsenault894e53d2017-07-26 20:39:42 +0000407bool isArgPassedInSGPR(const Argument *Arg);
Tom Stellard08efb7e2017-01-27 18:41:14 +0000408
409/// \returns The encoding that will be used for \p ByteOffset in the SMRD
410/// offset field.
411int64_t getSMRDEncodedOffset(const MCSubtargetInfo &ST, int64_t ByteOffset);
412
413/// \returns true if this offset is small enough to fit in the SMRD
414/// offset field. \p ByteOffset should be the offset in bytes and
415/// not the encoded offset.
416bool isLegalSMRDImmOffset(const MCSubtargetInfo &ST, int64_t ByteOffset);
417
Alexander Timofeev2e5eece2018-03-05 15:12:21 +0000418/// \returns true if the intrinsic is divergent
419bool isIntrinsicSourceOfDivergence(unsigned IntrID);
420
Tom Stellard347ac792015-06-26 21:15:07 +0000421} // end namespace AMDGPU
422} // end namespace llvm
423
Eugene Zelenkod96089b2017-02-14 00:33:36 +0000424#endif // LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUBASEINFO_H