blob: 3101b96c8eb08f985e0135c00077a671d581f6c2 [file] [log] [blame]
Tom Stellard347ac792015-06-26 21:15:07 +00001//===-- AMDGPUBaseInfo.h - Top level definitions for AMDGPU -----*- C++ -*-===//
2//
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
13#include "AMDKernelCodeT.h"
Nicolai Haehnledf3a20c2016-04-06 19:40:20 +000014#include "llvm/IR/CallingConv.h"
Tom Stellard347ac792015-06-26 21:15:07 +000015
Sam Koltona3ec5c12016-10-07 14:46:06 +000016#define GET_INSTRINFO_OPERAND_ENUM
17#include "AMDGPUGenInstrInfo.inc"
18#undef GET_INSTRINFO_OPERAND_ENUM
19
Tom Stellard347ac792015-06-26 21:15:07 +000020namespace llvm {
21
22class FeatureBitset;
Tom Stellardac00eb52015-12-15 16:26:16 +000023class Function;
Tom Stellarde3b5aea2015-12-02 17:00:42 +000024class GlobalValue;
Tom Stellarde135ffd2015-09-25 21:41:28 +000025class MCContext;
Sam Kolton1eeb11b2016-09-09 14:44:04 +000026class MCInstrDesc;
Krzysztof Parzyszekc8715502016-10-19 17:40:36 +000027class MCRegisterClass;
Sam Kolton1eeb11b2016-09-09 14:44:04 +000028class MCRegisterInfo;
Tom Stellarde135ffd2015-09-25 21:41:28 +000029class MCSection;
Tom Stellard2b65ed32015-12-21 18:44:27 +000030class MCSubtargetInfo;
Tom Stellard347ac792015-06-26 21:15:07 +000031
32namespace AMDGPU {
33
Sam Koltona3ec5c12016-10-07 14:46:06 +000034LLVM_READONLY
35int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx);
36
Tom Stellard347ac792015-06-26 21:15:07 +000037struct IsaVersion {
38 unsigned Major;
39 unsigned Minor;
40 unsigned Stepping;
41};
42
43IsaVersion getIsaVersion(const FeatureBitset &Features);
Tom Stellardff7416b2015-06-26 21:58:31 +000044void initDefaultAMDKernelCodeT(amd_kernel_code_t &Header,
45 const FeatureBitset &Features);
Tom Stellarde135ffd2015-09-25 21:41:28 +000046MCSection *getHSATextSection(MCContext &Ctx);
Tom Stellard347ac792015-06-26 21:15:07 +000047
Tom Stellard00f2f912015-12-02 19:47:57 +000048MCSection *getHSADataGlobalAgentSection(MCContext &Ctx);
49
50MCSection *getHSADataGlobalProgramSection(MCContext &Ctx);
51
Tom Stellard9760f032015-12-03 03:34:32 +000052MCSection *getHSARodataReadonlyAgentSection(MCContext &Ctx);
53
Tom Stellarde3b5aea2015-12-02 17:00:42 +000054bool isGroupSegment(const GlobalValue *GV);
Tom Stellard00f2f912015-12-02 19:47:57 +000055bool isGlobalSegment(const GlobalValue *GV);
56bool isReadOnlySegment(const GlobalValue *GV);
Tom Stellarde3b5aea2015-12-02 17:00:42 +000057
Konstantin Zhuravlyov08326b62016-10-20 18:12:38 +000058/// \returns True if constants should be emitted to .text section for given
59/// target triple \p TT, false otherwise.
60bool shouldEmitConstantsToTextSection(const Triple &TT);
61
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +000062/// \returns Integer value requested using \p F's \p Name attribute.
63///
64/// \returns \p Default if attribute is not present.
65///
66/// \returns \p Default and emits error if requested value cannot be converted
67/// to integer.
Matt Arsenault83002722016-05-12 02:45:18 +000068int getIntegerAttribute(const Function &F, StringRef Name, int Default);
69
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +000070/// \returns A pair of integer values requested using \p F's \p Name attribute
71/// in "first[,second]" format ("second" is optional unless \p OnlyFirstRequired
72/// is false).
73///
74/// \returns \p Default if attribute is not present.
75///
76/// \returns \p Default and emits error if one of the requested values cannot be
77/// converted to integer, or \p OnlyFirstRequired is false and "second" value is
78/// not present.
79std::pair<int, int> getIntegerPairAttribute(const Function &F,
80 StringRef Name,
81 std::pair<int, int> Default,
82 bool OnlyFirstRequired = false);
83
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +000084/// \returns Waitcnt bit mask for given isa \p Version.
85unsigned getWaitcntBitMask(IsaVersion Version);
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +000086
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +000087/// \returns Vmcnt bit mask for given isa \p Version.
88unsigned getVmcntBitMask(IsaVersion Version);
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +000089
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +000090/// \returns Expcnt bit mask for given isa \p Version.
91unsigned getExpcntBitMask(IsaVersion Version);
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +000092
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +000093/// \returns Lgkmcnt bit mask for given isa \p Version.
94unsigned getLgkmcntBitMask(IsaVersion Version);
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +000095
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +000096/// \returns Decoded Vmcnt from given \p Waitcnt for given isa \p Version.
97unsigned decodeVmcnt(IsaVersion Version, unsigned Waitcnt);
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +000098
Konstantin Zhuravlyovcdd45472016-10-11 18:58:22 +000099/// \returns Decoded Expcnt from given \p Waitcnt for given isa \p Version.
100unsigned decodeExpcnt(IsaVersion Version, unsigned Waitcnt);
101
102/// \returns Decoded Lgkmcnt from given \p Waitcnt for given isa \p Version.
103unsigned decodeLgkmcnt(IsaVersion Version, unsigned Waitcnt);
104
105/// \brief Decodes Vmcnt, Expcnt and Lgkmcnt from given \p Waitcnt for given isa
106/// \p Version, and writes decoded values into \p Vmcnt, \p Expcnt and
107/// \p Lgkmcnt respectively.
108///
109/// \details \p Vmcnt, \p Expcnt and \p Lgkmcnt are decoded as follows:
110/// \p Vmcnt = \p Waitcnt[3:0]
111/// \p Expcnt = \p Waitcnt[6:4]
112/// \p Lgkmcnt = \p Waitcnt[11:8]
113void decodeWaitcnt(IsaVersion Version, unsigned Waitcnt,
114 unsigned &Vmcnt, unsigned &Expcnt, unsigned &Lgkmcnt);
115
116/// \returns \p Waitcnt with encoded \p Vmcnt for given isa \p Version.
117unsigned encodeVmcnt(IsaVersion Version, unsigned Waitcnt, unsigned Vmcnt);
118
119/// \returns \p Waitcnt with encoded \p Expcnt for given isa \p Version.
120unsigned encodeExpcnt(IsaVersion Version, unsigned Waitcnt, unsigned Expcnt);
121
122/// \returns \p Waitcnt with encoded \p Lgkmcnt for given isa \p Version.
123unsigned encodeLgkmcnt(IsaVersion Version, unsigned Waitcnt, unsigned Lgkmcnt);
124
125/// \brief Encodes \p Vmcnt, \p Expcnt and \p Lgkmcnt into Waitcnt for given isa
126/// \p Version.
127///
128/// \details \p Vmcnt, \p Expcnt and \p Lgkmcnt are encoded as follows:
129/// Waitcnt[3:0] = \p Vmcnt
130/// Waitcnt[6:4] = \p Expcnt
131/// Waitcnt[11:8] = \p Lgkmcnt
132///
133/// \returns Waitcnt with encoded \p Vmcnt, \p Expcnt and \p Lgkmcnt for given
134/// isa \p Version.
135unsigned encodeWaitcnt(IsaVersion Version,
136 unsigned Vmcnt, unsigned Expcnt, unsigned Lgkmcnt);
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +0000137
Marek Olsakfccabaf2016-01-13 11:45:36 +0000138unsigned getInitialPSInputAddr(const Function &F);
139
Nicolai Haehnledf3a20c2016-04-06 19:40:20 +0000140bool isShader(CallingConv::ID cc);
141bool isCompute(CallingConv::ID cc);
Tom Stellardac00eb52015-12-15 16:26:16 +0000142
Tom Stellard2b65ed32015-12-21 18:44:27 +0000143bool isSI(const MCSubtargetInfo &STI);
144bool isCI(const MCSubtargetInfo &STI);
145bool isVI(const MCSubtargetInfo &STI);
146
147/// If \p Reg is a pseudo reg, return the correct hardware register given
148/// \p STI otherwise return \p Reg.
149unsigned getMCReg(unsigned Reg, const MCSubtargetInfo &STI);
150
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000151/// \brief Can this operand also contain immediate values?
152bool isSISrcOperand(const MCInstrDesc &Desc, unsigned OpNo);
153
154/// \brief Is this floating-point operand?
155bool isSISrcFPOperand(const MCInstrDesc &Desc, unsigned OpNo);
156
157/// \brief Does this opearnd support only inlinable literals?
158bool isSISrcInlinableOperand(const MCInstrDesc &Desc, unsigned OpNo);
159
Krzysztof Parzyszekc8715502016-10-19 17:40:36 +0000160/// \brief Get the size in bits of a register from the register class \p RC.
Tom Stellardb133fbb2016-10-27 23:05:31 +0000161unsigned getRegBitWidth(unsigned RCID);
162
163/// \brief Get the size in bits of a register from the register class \p RC.
Krzysztof Parzyszekc8715502016-10-19 17:40:36 +0000164unsigned getRegBitWidth(const MCRegisterClass &RC);
165
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000166/// \brief Get size of register operand
167unsigned getRegOperandSize(const MCRegisterInfo *MRI, const MCInstrDesc &Desc,
168 unsigned OpNo);
169
170/// \brief Is this literal inlinable
Matt Arsenault26faed32016-12-05 22:26:17 +0000171LLVM_READNONE
172bool isInlinableLiteral64(int64_t Literal, bool HasInv2Pi);
173
174LLVM_READNONE
175bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi);
176
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000177
Tom Stellard347ac792015-06-26 21:15:07 +0000178} // end namespace AMDGPU
179} // end namespace llvm
180
181#endif