blob: 5b7af8268cdaf6ccf4a1835547fe0272301781c6 [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"
Scott Linder1e8c2c72018-06-21 19:38:56 +000019#include "llvm/Support/AMDHSAKernelDescriptor.h"
Eugene Zelenkod96089b2017-02-14 00:33:36 +000020#include "llvm/Support/Compiler.h"
21#include "llvm/Support/ErrorHandling.h"
22#include <cstdint>
Konstantin Zhuravlyov9c05b2b2017-10-14 15:40:33 +000023#include <string>
Eugene Zelenkod96089b2017-02-14 00:33:36 +000024#include <utility>
Matt Arsenault4bd72362016-12-10 00:39:12 +000025
Tom Stellard347ac792015-06-26 21:15:07 +000026namespace llvm {
27
Matt Arsenault894e53d2017-07-26 20:39:42 +000028class Argument;
Tom Stellard347ac792015-06-26 21:15:07 +000029class FeatureBitset;
Tom Stellardac00eb52015-12-15 16:26:16 +000030class Function;
Tom Stellarde3b5aea2015-12-02 17:00:42 +000031class GlobalValue;
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;
Scott Linder1e8c2c72018-06-21 19:38:56 +000037class MachineMemOperand;
Eugene Zelenkod96089b2017-02-14 00:33:36 +000038class Triple;
Tom Stellard347ac792015-06-26 21:15:07 +000039
40namespace AMDGPU {
Nicolai Haehnle0ab200b2018-06-21 13:36:44 +000041
42#define GET_MIMGBaseOpcode_DECL
Nicolai Haehnle7a9c03f2018-06-21 13:36:57 +000043#define GET_MIMGDim_DECL
Nicolai Haehnle0ab200b2018-06-21 13:36:44 +000044#define GET_MIMGEncoding_DECL
Ryan Taylor894c8fd2018-08-01 12:12:01 +000045#define GET_MIMGLZMapping_DECL
Nicolai Haehnle0ab200b2018-06-21 13:36:44 +000046#include "AMDGPUGenSearchableTables.inc"
47
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +000048namespace IsaInfo {
Sam Koltona3ec5c12016-10-07 14:46:06 +000049
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +000050enum {
51 // The closed Vulkan driver sets 96, which limits the wave count to 8 but
52 // doesn't spill SGPRs as much as when 80 is set.
Konstantin Zhuravlyovc72ece62018-05-16 20:47:48 +000053 FIXED_NUM_SGPRS_FOR_INIT_BUG = 96,
54 TRAP_NUM_SGPRS = 16
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +000055};
56
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000057/// Instruction set architecture version.
Tom Stellard347ac792015-06-26 21:15:07 +000058struct IsaVersion {
59 unsigned Major;
60 unsigned Minor;
61 unsigned Stepping;
62};
63
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +000064/// \returns Isa version for given subtarget \p Features.
Tom Stellard347ac792015-06-26 21:15:07 +000065IsaVersion getIsaVersion(const FeatureBitset &Features);
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +000066
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000067/// Streams isa version string for given subtarget \p STI into \p Stream.
Konstantin Zhuravlyov9c05b2b2017-10-14 15:40:33 +000068void streamIsaVersion(const MCSubtargetInfo *STI, raw_ostream &Stream);
69
Konstantin Zhuravlyov00f2cb12018-06-12 18:02:46 +000070/// \returns True if given subtarget \p STI supports code object version 3,
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +000071/// false otherwise.
Konstantin Zhuravlyov00f2cb12018-06-12 18:02:46 +000072bool hasCodeObjectV3(const MCSubtargetInfo *STI);
Konstantin Zhuravlyoveda425e2017-10-14 15:59:07 +000073
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +000074/// \returns Wavefront size for given subtarget \p Features.
75unsigned getWavefrontSize(const FeatureBitset &Features);
76
77/// \returns Local memory size in bytes for given subtarget \p Features.
78unsigned getLocalMemorySize(const FeatureBitset &Features);
79
80/// \returns Number of execution units per compute unit for given subtarget \p
81/// Features.
82unsigned getEUsPerCU(const FeatureBitset &Features);
83
84/// \returns Maximum number of work groups per compute unit for given subtarget
85/// \p Features and limited by given \p FlatWorkGroupSize.
86unsigned getMaxWorkGroupsPerCU(const FeatureBitset &Features,
87 unsigned FlatWorkGroupSize);
88
89/// \returns Maximum number of waves per compute unit for given subtarget \p
90/// Features without any kind of limitation.
91unsigned getMaxWavesPerCU(const FeatureBitset &Features);
92
93/// \returns Maximum number of waves per compute unit for given subtarget \p
94/// Features and limited by given \p FlatWorkGroupSize.
95unsigned getMaxWavesPerCU(const FeatureBitset &Features,
96 unsigned FlatWorkGroupSize);
97
98/// \returns Minimum number of waves per execution unit for given subtarget \p
99/// Features.
100unsigned getMinWavesPerEU(const FeatureBitset &Features);
101
102/// \returns Maximum number of waves per execution unit for given subtarget \p
103/// Features without any kind of limitation.
Tom Stellardc5a154d2018-06-28 23:47:12 +0000104unsigned getMaxWavesPerEU();
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000105
106/// \returns Maximum number of waves per execution unit for given subtarget \p
107/// Features and limited by given \p FlatWorkGroupSize.
108unsigned getMaxWavesPerEU(const FeatureBitset &Features,
109 unsigned FlatWorkGroupSize);
110
111/// \returns Minimum flat work group size for given subtarget \p Features.
112unsigned getMinFlatWorkGroupSize(const FeatureBitset &Features);
113
114/// \returns Maximum flat work group size for given subtarget \p Features.
115unsigned getMaxFlatWorkGroupSize(const FeatureBitset &Features);
116
117/// \returns Number of waves per work group for given subtarget \p Features and
118/// limited by given \p FlatWorkGroupSize.
119unsigned getWavesPerWorkGroup(const FeatureBitset &Features,
120 unsigned FlatWorkGroupSize);
121
122/// \returns SGPR allocation granularity for given subtarget \p Features.
123unsigned getSGPRAllocGranule(const FeatureBitset &Features);
124
125/// \returns SGPR encoding granularity for given subtarget \p Features.
126unsigned getSGPREncodingGranule(const FeatureBitset &Features);
127
128/// \returns Total number of SGPRs for given subtarget \p Features.
129unsigned getTotalNumSGPRs(const FeatureBitset &Features);
130
131/// \returns Addressable number of SGPRs for given subtarget \p Features.
132unsigned getAddressableNumSGPRs(const FeatureBitset &Features);
133
134/// \returns Minimum number of SGPRs that meets the given number of waves per
135/// execution unit requirement for given subtarget \p Features.
136unsigned getMinNumSGPRs(const FeatureBitset &Features, unsigned WavesPerEU);
137
138/// \returns Maximum number of SGPRs that meets the given number of waves per
139/// execution unit requirement for given subtarget \p Features.
140unsigned getMaxNumSGPRs(const FeatureBitset &Features, unsigned WavesPerEU,
141 bool Addressable);
142
Scott Linder1e8c2c72018-06-21 19:38:56 +0000143/// \returns Number of extra SGPRs implicitly required by given subtarget \p
144/// Features when the given special registers are used.
145unsigned getNumExtraSGPRs(const FeatureBitset &Features, bool VCCUsed,
146 bool FlatScrUsed, bool XNACKUsed);
147
148/// \returns Number of extra SGPRs implicitly required by given subtarget \p
149/// Features when the given special registers are used. XNACK is inferred from
150/// \p Features.
151unsigned getNumExtraSGPRs(const FeatureBitset &Features, bool VCCUsed,
152 bool FlatScrUsed);
153
154/// \returns Number of SGPR blocks needed for given subtarget \p Features when
155/// \p NumSGPRs are used. \p NumSGPRs should already include any special
156/// register counts.
157unsigned getNumSGPRBlocks(const FeatureBitset &Features, unsigned NumSGPRs);
158
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000159/// \returns VGPR allocation granularity for given subtarget \p Features.
160unsigned getVGPRAllocGranule(const FeatureBitset &Features);
161
162/// \returns VGPR encoding granularity for given subtarget \p Features.
163unsigned getVGPREncodingGranule(const FeatureBitset &Features);
164
165/// \returns Total number of VGPRs for given subtarget \p Features.
166unsigned getTotalNumVGPRs(const FeatureBitset &Features);
167
168/// \returns Addressable number of VGPRs for given subtarget \p Features.
169unsigned getAddressableNumVGPRs(const FeatureBitset &Features);
170
171/// \returns Minimum number of VGPRs that meets given number of waves per
172/// execution unit requirement for given subtarget \p Features.
173unsigned getMinNumVGPRs(const FeatureBitset &Features, unsigned WavesPerEU);
174
175/// \returns Maximum number of VGPRs that meets given number of waves per
176/// execution unit requirement for given subtarget \p Features.
177unsigned getMaxNumVGPRs(const FeatureBitset &Features, unsigned WavesPerEU);
178
Scott Linder1e8c2c72018-06-21 19:38:56 +0000179/// \returns Number of VGPR blocks needed for given subtarget \p Features when
180/// \p NumVGPRs are used.
181unsigned getNumVGPRBlocks(const FeatureBitset &Features, unsigned NumSGPRs);
182
Eugene Zelenkod96089b2017-02-14 00:33:36 +0000183} // end namespace IsaInfo
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000184
185LLVM_READONLY
186int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx);
187
Nicolai Haehnle7a9c03f2018-06-21 13:36:57 +0000188struct MIMGBaseOpcodeInfo {
189 MIMGBaseOpcode BaseOpcode;
190 bool Store;
191 bool Atomic;
192 bool AtomicX2;
193 bool Sampler;
194
195 uint8_t NumExtraArgs;
196 bool Gradients;
197 bool Coordinates;
198 bool LodOrClampOrMip;
199 bool HasD16;
200};
201
202LLVM_READONLY
203const MIMGBaseOpcodeInfo *getMIMGBaseOpcodeInfo(unsigned BaseOpcode);
204
205struct MIMGDimInfo {
206 MIMGDim Dim;
207 uint8_t NumCoords;
208 uint8_t NumGradients;
209 bool DA;
210};
211
212LLVM_READONLY
213const MIMGDimInfo *getMIMGDimInfo(unsigned Dim);
214
Ryan Taylor894c8fd2018-08-01 12:12:01 +0000215struct MIMGLZMappingInfo {
216 MIMGBaseOpcode L;
217 MIMGBaseOpcode LZ;
218};
219
220LLVM_READONLY
221const MIMGLZMappingInfo *getMIMGLZMappingInfo(unsigned L);
222
Nicolai Haehnle7a9c03f2018-06-21 13:36:57 +0000223LLVM_READONLY
224int getMIMGOpcode(unsigned BaseOpcode, unsigned MIMGEncoding,
225 unsigned VDataDwords, unsigned VAddrDwords);
226
Matt Arsenaultcad7fa82017-12-13 21:07:51 +0000227LLVM_READONLY
Nicolai Haehnle0ab200b2018-06-21 13:36:44 +0000228int getMaskedMIMGOp(unsigned Opc, unsigned NewChannels);
Nicolai Haehnlef2674312018-06-21 13:36:01 +0000229
230LLVM_READONLY
Matt Arsenaultcad7fa82017-12-13 21:07:51 +0000231int getMCOpcode(uint16_t Opcode, unsigned Gen);
232
Tom Stellardff7416b2015-06-26 21:58:31 +0000233void initDefaultAMDKernelCodeT(amd_kernel_code_t &Header,
234 const FeatureBitset &Features);
Tom Stellard9760f032015-12-03 03:34:32 +0000235
Scott Linder1e8c2c72018-06-21 19:38:56 +0000236amdhsa::kernel_descriptor_t getDefaultAmdhsaKernelDescriptor();
237
Konstantin Zhuravlyov435151a2017-11-01 19:12:38 +0000238bool isGroupSegment(const GlobalValue *GV);
239bool isGlobalSegment(const GlobalValue *GV);
240bool isReadOnlySegment(const GlobalValue *GV);
Tom Stellarde3b5aea2015-12-02 17:00:42 +0000241
Konstantin Zhuravlyov08326b62016-10-20 18:12:38 +0000242/// \returns True if constants should be emitted to .text section for given
243/// target triple \p TT, false otherwise.
244bool shouldEmitConstantsToTextSection(const Triple &TT);
245
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000246/// \returns Integer value requested using \p F's \p Name attribute.
247///
248/// \returns \p Default if attribute is not present.
249///
250/// \returns \p Default and emits error if requested value cannot be converted
251/// to integer.
Matt Arsenault83002722016-05-12 02:45:18 +0000252int getIntegerAttribute(const Function &F, StringRef Name, int Default);
253
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +0000254/// \returns A pair of integer values requested using \p F's \p Name attribute
255/// in "first[,second]" format ("second" is optional unless \p OnlyFirstRequired
256/// is false).
257///
258/// \returns \p Default if attribute is not present.
259///
260/// \returns \p Default and emits error if one of the requested values cannot be
261/// converted to integer, or \p OnlyFirstRequired is false and "second" value is
262/// not present.
263std::pair<int, int> getIntegerPairAttribute(const Function &F,
264 StringRef Name,
265 std::pair<int, int> Default,
266 bool OnlyFirstRequired = false);
267
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000268/// \returns Vmcnt bit mask for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000269unsigned getVmcntBitMask(const IsaInfo::IsaVersion &Version);
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +0000270
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000271/// \returns Expcnt bit mask for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000272unsigned getExpcntBitMask(const IsaInfo::IsaVersion &Version);
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +0000273
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000274/// \returns Lgkmcnt bit mask for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000275unsigned getLgkmcntBitMask(const IsaInfo::IsaVersion &Version);
276
277/// \returns Waitcnt bit mask for given isa \p Version.
278unsigned getWaitcntBitMask(const IsaInfo::IsaVersion &Version);
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +0000279
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000280/// \returns Decoded Vmcnt from given \p Waitcnt for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000281unsigned decodeVmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt);
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +0000282
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000283/// \returns Decoded Expcnt from given \p Waitcnt for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000284unsigned decodeExpcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt);
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000285
286/// \returns Decoded Lgkmcnt from given \p Waitcnt for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000287unsigned decodeLgkmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt);
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000288
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000289/// Decodes Vmcnt, Expcnt and Lgkmcnt from given \p Waitcnt for given isa
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000290/// \p Version, and writes decoded values into \p Vmcnt, \p Expcnt and
291/// \p Lgkmcnt respectively.
292///
293/// \details \p Vmcnt, \p Expcnt and \p Lgkmcnt are decoded as follows:
Matt Arsenaulte823d922017-02-18 18:29:53 +0000294/// \p Vmcnt = \p Waitcnt[3:0] (pre-gfx9 only)
295/// \p Vmcnt = \p Waitcnt[3:0] | \p Waitcnt[15:14] (gfx9+ only)
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000296/// \p Expcnt = \p Waitcnt[6:4]
297/// \p Lgkmcnt = \p Waitcnt[11:8]
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000298void decodeWaitcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt,
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000299 unsigned &Vmcnt, unsigned &Expcnt, unsigned &Lgkmcnt);
300
301/// \returns \p Waitcnt with encoded \p Vmcnt for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000302unsigned encodeVmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt,
303 unsigned Vmcnt);
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000304
305/// \returns \p Waitcnt with encoded \p Expcnt for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000306unsigned encodeExpcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt,
307 unsigned Expcnt);
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000308
309/// \returns \p Waitcnt with encoded \p Lgkmcnt for given isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000310unsigned encodeLgkmcnt(const IsaInfo::IsaVersion &Version, unsigned Waitcnt,
311 unsigned Lgkmcnt);
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000312
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000313/// Encodes \p Vmcnt, \p Expcnt and \p Lgkmcnt into Waitcnt for given isa
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000314/// \p Version.
315///
316/// \details \p Vmcnt, \p Expcnt and \p Lgkmcnt are encoded as follows:
Matt Arsenaulte823d922017-02-18 18:29:53 +0000317/// Waitcnt[3:0] = \p Vmcnt (pre-gfx9 only)
318/// Waitcnt[3:0] = \p Vmcnt[3:0] (gfx9+ only)
319/// Waitcnt[6:4] = \p Expcnt
320/// Waitcnt[11:8] = \p Lgkmcnt
321/// Waitcnt[15:14] = \p Vmcnt[5:4] (gfx9+ only)
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000322///
323/// \returns Waitcnt with encoded \p Vmcnt, \p Expcnt and \p Lgkmcnt for given
324/// isa \p Version.
Konstantin Zhuravlyov9f89ede2017-02-08 14:05:23 +0000325unsigned encodeWaitcnt(const IsaInfo::IsaVersion &Version,
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +0000326 unsigned Vmcnt, unsigned Expcnt, unsigned Lgkmcnt);
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +0000327
Marek Olsakfccabaf2016-01-13 11:45:36 +0000328unsigned getInitialPSInputAddr(const Function &F);
329
Matt Arsenaulte622dc32017-04-11 22:29:24 +0000330LLVM_READNONE
331bool isShader(CallingConv::ID CC);
332
333LLVM_READNONE
334bool isCompute(CallingConv::ID CC);
335
336LLVM_READNONE
337bool isEntryFunctionCC(CallingConv::ID CC);
338
Matt Arsenaultefa9f4b2017-04-11 22:29:28 +0000339// FIXME: Remove this when calling conventions cleaned up
340LLVM_READNONE
341inline bool isKernel(CallingConv::ID CC) {
342 switch (CC) {
Matt Arsenaultefa9f4b2017-04-11 22:29:28 +0000343 case CallingConv::AMDGPU_KERNEL:
344 case CallingConv::SPIR_KERNEL:
345 return true;
346 default:
347 return false;
348 }
349}
Tom Stellardac00eb52015-12-15 16:26:16 +0000350
Dmitry Preobrazhensky3afbd822018-01-10 14:22:19 +0000351bool hasXNACK(const MCSubtargetInfo &STI);
Dmitry Preobrazhenskye3271ae2018-02-05 12:45:43 +0000352bool hasMIMG_R128(const MCSubtargetInfo &STI);
Dmitry Preobrazhensky0a1ff462018-02-05 14:18:53 +0000353bool hasPackedD16(const MCSubtargetInfo &STI);
Dmitry Preobrazhenskye3271ae2018-02-05 12:45:43 +0000354
Tom Stellard2b65ed32015-12-21 18:44:27 +0000355bool isSI(const MCSubtargetInfo &STI);
356bool isCI(const MCSubtargetInfo &STI);
357bool isVI(const MCSubtargetInfo &STI);
Sam Koltonf7659d712017-05-23 10:08:55 +0000358bool isGFX9(const MCSubtargetInfo &STI);
359
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000360/// Is Reg - scalar register
Sam Koltonf7659d712017-05-23 10:08:55 +0000361bool isSGPR(unsigned Reg, const MCRegisterInfo* TRI);
Tom Stellard2b65ed32015-12-21 18:44:27 +0000362
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000363/// Is there any intersection between registers
Dmitry Preobrazhenskydc4ac822017-06-21 14:41:34 +0000364bool isRegIntersect(unsigned Reg0, unsigned Reg1, const MCRegisterInfo* TRI);
365
Tom Stellard2b65ed32015-12-21 18:44:27 +0000366/// If \p Reg is a pseudo reg, return the correct hardware register given
367/// \p STI otherwise return \p Reg.
368unsigned getMCReg(unsigned Reg, const MCSubtargetInfo &STI);
369
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000370/// Convert hardware register \p Reg to a pseudo register
Dmitry Preobrazhensky03880f82017-03-03 14:31:06 +0000371LLVM_READNONE
372unsigned mc2PseudoReg(unsigned Reg);
373
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000374/// Can this operand also contain immediate values?
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000375bool isSISrcOperand(const MCInstrDesc &Desc, unsigned OpNo);
376
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000377/// Is this floating-point operand?
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000378bool isSISrcFPOperand(const MCInstrDesc &Desc, unsigned OpNo);
379
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000380/// Does this opearnd support only inlinable literals?
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000381bool isSISrcInlinableOperand(const MCInstrDesc &Desc, unsigned OpNo);
382
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000383/// Get the size in bits of a register from the register class \p RC.
Tom Stellardb133fbb2016-10-27 23:05:31 +0000384unsigned getRegBitWidth(unsigned RCID);
385
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000386/// Get the size in bits of a register from the register class \p RC.
Krzysztof Parzyszekc8715502016-10-19 17:40:36 +0000387unsigned getRegBitWidth(const MCRegisterClass &RC);
388
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000389/// Get size of register operand
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000390unsigned getRegOperandSize(const MCRegisterInfo *MRI, const MCInstrDesc &Desc,
391 unsigned OpNo);
392
Matt Arsenault4bd72362016-12-10 00:39:12 +0000393LLVM_READNONE
394inline unsigned getOperandSize(const MCOperandInfo &OpInfo) {
395 switch (OpInfo.OperandType) {
396 case AMDGPU::OPERAND_REG_IMM_INT32:
397 case AMDGPU::OPERAND_REG_IMM_FP32:
398 case AMDGPU::OPERAND_REG_INLINE_C_INT32:
399 case AMDGPU::OPERAND_REG_INLINE_C_FP32:
400 return 4;
401
402 case AMDGPU::OPERAND_REG_IMM_INT64:
403 case AMDGPU::OPERAND_REG_IMM_FP64:
404 case AMDGPU::OPERAND_REG_INLINE_C_INT64:
405 case AMDGPU::OPERAND_REG_INLINE_C_FP64:
406 return 8;
407
408 case AMDGPU::OPERAND_REG_IMM_INT16:
409 case AMDGPU::OPERAND_REG_IMM_FP16:
410 case AMDGPU::OPERAND_REG_INLINE_C_INT16:
411 case AMDGPU::OPERAND_REG_INLINE_C_FP16:
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000412 case AMDGPU::OPERAND_REG_INLINE_C_V2INT16:
413 case AMDGPU::OPERAND_REG_INLINE_C_V2FP16:
Matt Arsenault4bd72362016-12-10 00:39:12 +0000414 return 2;
415
416 default:
417 llvm_unreachable("unhandled operand type");
418 }
419}
420
421LLVM_READNONE
422inline unsigned getOperandSize(const MCInstrDesc &Desc, unsigned OpNo) {
423 return getOperandSize(Desc.OpInfo[OpNo]);
424}
425
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000426/// Is this literal inlinable
Matt Arsenault26faed32016-12-05 22:26:17 +0000427LLVM_READNONE
428bool isInlinableLiteral64(int64_t Literal, bool HasInv2Pi);
429
430LLVM_READNONE
431bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi);
432
Matt Arsenault4bd72362016-12-10 00:39:12 +0000433LLVM_READNONE
434bool isInlinableLiteral16(int16_t Literal, bool HasInv2Pi);
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000435
Matt Arsenault9be7b0d2017-02-27 18:49:11 +0000436LLVM_READNONE
437bool isInlinableLiteralV216(int32_t Literal, bool HasInv2Pi);
438
Matt Arsenault894e53d2017-07-26 20:39:42 +0000439bool isArgPassedInSGPR(const Argument *Arg);
Tom Stellard08efb7e2017-01-27 18:41:14 +0000440
441/// \returns The encoding that will be used for \p ByteOffset in the SMRD
442/// offset field.
443int64_t getSMRDEncodedOffset(const MCSubtargetInfo &ST, int64_t ByteOffset);
444
445/// \returns true if this offset is small enough to fit in the SMRD
446/// offset field. \p ByteOffset should be the offset in bytes and
447/// not the encoded offset.
448bool isLegalSMRDImmOffset(const MCSubtargetInfo &ST, int64_t ByteOffset);
449
Alexander Timofeev2e5eece2018-03-05 15:12:21 +0000450/// \returns true if the intrinsic is divergent
451bool isIntrinsicSourceOfDivergence(unsigned IntrID);
452
Tom Stellard347ac792015-06-26 21:15:07 +0000453} // end namespace AMDGPU
454} // end namespace llvm
455
Eugene Zelenkod96089b2017-02-14 00:33:36 +0000456#endif // LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUBASEINFO_H