blob: 95788766d35e79067c388ae7d682b977f3a26656 [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;
27class MCRegisterInfo;
Tom Stellarde135ffd2015-09-25 21:41:28 +000028class MCSection;
Tom Stellard2b65ed32015-12-21 18:44:27 +000029class MCSubtargetInfo;
Tom Stellard347ac792015-06-26 21:15:07 +000030
31namespace AMDGPU {
32
Sam Koltona3ec5c12016-10-07 14:46:06 +000033LLVM_READONLY
34int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx);
35
Tom Stellard347ac792015-06-26 21:15:07 +000036struct IsaVersion {
37 unsigned Major;
38 unsigned Minor;
39 unsigned Stepping;
40};
41
42IsaVersion getIsaVersion(const FeatureBitset &Features);
Tom Stellardff7416b2015-06-26 21:58:31 +000043void initDefaultAMDKernelCodeT(amd_kernel_code_t &Header,
44 const FeatureBitset &Features);
Tom Stellarde135ffd2015-09-25 21:41:28 +000045MCSection *getHSATextSection(MCContext &Ctx);
Tom Stellard347ac792015-06-26 21:15:07 +000046
Tom Stellard00f2f912015-12-02 19:47:57 +000047MCSection *getHSADataGlobalAgentSection(MCContext &Ctx);
48
49MCSection *getHSADataGlobalProgramSection(MCContext &Ctx);
50
Tom Stellard9760f032015-12-03 03:34:32 +000051MCSection *getHSARodataReadonlyAgentSection(MCContext &Ctx);
52
Tom Stellarde3b5aea2015-12-02 17:00:42 +000053bool isGroupSegment(const GlobalValue *GV);
Tom Stellard00f2f912015-12-02 19:47:57 +000054bool isGlobalSegment(const GlobalValue *GV);
55bool isReadOnlySegment(const GlobalValue *GV);
Tom Stellarde3b5aea2015-12-02 17:00:42 +000056
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +000057/// \returns Integer value requested using \p F's \p Name attribute.
58///
59/// \returns \p Default if attribute is not present.
60///
61/// \returns \p Default and emits error if requested value cannot be converted
62/// to integer.
Matt Arsenault83002722016-05-12 02:45:18 +000063int getIntegerAttribute(const Function &F, StringRef Name, int Default);
64
Konstantin Zhuravlyov1d650262016-09-06 20:22:28 +000065/// \returns A pair of integer values requested using \p F's \p Name attribute
66/// in "first[,second]" format ("second" is optional unless \p OnlyFirstRequired
67/// is false).
68///
69/// \returns \p Default if attribute is not present.
70///
71/// \returns \p Default and emits error if one of the requested values cannot be
72/// converted to integer, or \p OnlyFirstRequired is false and "second" value is
73/// not present.
74std::pair<int, int> getIntegerPairAttribute(const Function &F,
75 StringRef Name,
76 std::pair<int, int> Default,
77 bool OnlyFirstRequired = false);
78
Konstantin Zhuravlyov836cbff2016-09-30 17:01:40 +000079/// \returns VMCNT bit mask for given isa \p Version.
80unsigned getVmcntMask(IsaVersion Version);
81
82/// \returns VMCNT bit shift for given isa \p Version.
83unsigned getVmcntShift(IsaVersion Version);
84
85/// \returns EXPCNT bit mask for given isa \p Version.
86unsigned getExpcntMask(IsaVersion Version);
87
88/// \returns EXPCNT bit shift for given isa \p Version.
89unsigned getExpcntShift(IsaVersion Version);
90
91/// \returns LGKMCNT bit mask for given isa \p Version.
92unsigned getLgkmcntMask(IsaVersion Version);
93
94/// \returns LGKMCNT bit shift for given isa \p Version.
95unsigned getLgkmcntShift(IsaVersion Version);
96
Marek Olsakfccabaf2016-01-13 11:45:36 +000097unsigned getInitialPSInputAddr(const Function &F);
98
Nicolai Haehnledf3a20c2016-04-06 19:40:20 +000099bool isShader(CallingConv::ID cc);
100bool isCompute(CallingConv::ID cc);
Tom Stellardac00eb52015-12-15 16:26:16 +0000101
Tom Stellard2b65ed32015-12-21 18:44:27 +0000102bool isSI(const MCSubtargetInfo &STI);
103bool isCI(const MCSubtargetInfo &STI);
104bool isVI(const MCSubtargetInfo &STI);
105
106/// If \p Reg is a pseudo reg, return the correct hardware register given
107/// \p STI otherwise return \p Reg.
108unsigned getMCReg(unsigned Reg, const MCSubtargetInfo &STI);
109
Sam Kolton1eeb11b2016-09-09 14:44:04 +0000110/// \brief Can this operand also contain immediate values?
111bool isSISrcOperand(const MCInstrDesc &Desc, unsigned OpNo);
112
113/// \brief Is this floating-point operand?
114bool isSISrcFPOperand(const MCInstrDesc &Desc, unsigned OpNo);
115
116/// \brief Does this opearnd support only inlinable literals?
117bool isSISrcInlinableOperand(const MCInstrDesc &Desc, unsigned OpNo);
118
119/// \brief Get size of register operand
120unsigned getRegOperandSize(const MCRegisterInfo *MRI, const MCInstrDesc &Desc,
121 unsigned OpNo);
122
123/// \brief Is this literal inlinable
124bool isInlinableLiteral64(int64_t Literal, bool IsVI);
125bool isInlinableLiteral32(int32_t Literal, bool IsVI);
126
Tom Stellard347ac792015-06-26 21:15:07 +0000127} // end namespace AMDGPU
128} // end namespace llvm
129
130#endif