LLVM 19.0.0git
SIProgramInfo.cpp
Go to the documentation of this file.
1//===-- SIProgramInfo.cpp ----------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10///
11/// The SIProgramInfo tracks resource usage and hardware flags for kernels and
12/// entry functions.
13//
14//===----------------------------------------------------------------------===//
15//
16
17#include "SIProgramInfo.h"
18#include "GCNSubtarget.h"
19#include "SIDefines.h"
21#include "llvm/MC/MCExpr.h"
22
23using namespace llvm;
24
26 MCContext &Ctx = MF.getContext();
27
28 const MCExpr *ZeroExpr = MCConstantExpr::create(0, Ctx);
29
30 VGPRBlocks = ZeroExpr;
31 SGPRBlocks = ZeroExpr;
32 Priority = 0;
33 FloatMode = 0;
34 Priv = 0;
35 DX10Clamp = 0;
36 DebugMode = 0;
37 IEEEMode = 0;
38 WgpMode = 0;
39 MemOrdered = 0;
40 RrWgMode = 0;
41 ScratchSize = ZeroExpr;
42
43 LDSBlocks = 0;
44 ScratchBlocks = ZeroExpr;
45
46 ScratchEnable = ZeroExpr;
47 UserSGPR = 0;
49 TGIdXEnable = 0;
50 TGIdYEnable = 0;
51 TGIdZEnable = 0;
52 TGSizeEnable = 0;
54 EXCPEnMSB = 0;
55 LdsSize = 0;
56 EXCPEnable = 0;
57
58 ComputePGMRSrc3GFX90A = ZeroExpr;
59
60 NumVGPR = ZeroExpr;
61 NumArchVGPR = ZeroExpr;
62 NumAccVGPR = ZeroExpr;
63 AccumOffset = ZeroExpr;
64 TgSplit = 0;
65 NumSGPR = ZeroExpr;
66 SGPRSpill = 0;
67 VGPRSpill = 0;
68 LDSSize = 0;
69 FlatUsed = ZeroExpr;
70
71 NumSGPRsForWavesPerEU = ZeroExpr;
72 NumVGPRsForWavesPerEU = ZeroExpr;
73 Occupancy = ZeroExpr;
74 DynamicCallStack = ZeroExpr;
75 VCCUsed = ZeroExpr;
76}
77
79 const GCNSubtarget &ST) {
80 uint64_t Reg = S_00B848_PRIORITY(ProgInfo.Priority) |
82 S_00B848_PRIV(ProgInfo.Priv) |
84 S_00B848_WGP_MODE(ProgInfo.WgpMode) |
86
87 if (ST.hasDX10ClampMode())
88 Reg |= S_00B848_DX10_CLAMP(ProgInfo.DX10Clamp);
89
90 if (ST.hasIEEEMode())
91 Reg |= S_00B848_IEEE_MODE(ProgInfo.IEEEMode);
92
93 if (ST.hasRrWGMode())
94 Reg |= S_00B848_RR_WG_MODE(ProgInfo.RrWgMode);
95
96 return Reg;
97}
98
99static uint64_t getPGMRSrc1Reg(const SIProgramInfo &ProgInfo,
100 CallingConv::ID CC, const GCNSubtarget &ST) {
101 uint64_t Reg = S_00B848_PRIORITY(ProgInfo.Priority) |
103 S_00B848_PRIV(ProgInfo.Priv) |
105
106 if (ST.hasDX10ClampMode())
107 Reg |= S_00B848_DX10_CLAMP(ProgInfo.DX10Clamp);
108
109 if (ST.hasIEEEMode())
110 Reg |= S_00B848_IEEE_MODE(ProgInfo.IEEEMode);
111
112 if (ST.hasRrWGMode())
113 Reg |= S_00B848_RR_WG_MODE(ProgInfo.RrWgMode);
114
115 switch (CC) {
117 Reg |= S_00B028_MEM_ORDERED(ProgInfo.MemOrdered);
118 break;
120 Reg |= S_00B128_MEM_ORDERED(ProgInfo.MemOrdered);
121 break;
123 Reg |= S_00B228_WGP_MODE(ProgInfo.WgpMode) |
125 break;
127 Reg |= S_00B428_WGP_MODE(ProgInfo.WgpMode) |
129 break;
130 default:
131 break;
132 }
133 return Reg;
134}
135
137 uint64_t Reg = S_00B84C_USER_SGPR(ProgInfo.UserSGPR) |
145 S_00B84C_LDS_SIZE(ProgInfo.LdsSize) |
147
148 return Reg;
149}
150
151static const MCExpr *MaskShift(const MCExpr *Val, uint32_t Mask, uint32_t Shift,
152 MCContext &Ctx) {
153 if (Mask) {
154 const MCExpr *MaskExpr = MCConstantExpr::create(Mask, Ctx);
155 Val = MCBinaryExpr::createAnd(Val, MaskExpr, Ctx);
156 }
157 if (Shift) {
158 const MCExpr *ShiftExpr = MCConstantExpr::create(Shift, Ctx);
159 Val = MCBinaryExpr::createShl(Val, ShiftExpr, Ctx);
160 }
161 return Val;
162}
163
165 int64_t VBlocks, SBlocks;
166 VGPRBlocks->evaluateAsAbsolute(VBlocks);
167 SGPRBlocks->evaluateAsAbsolute(SBlocks);
168
169 uint64_t Reg = S_00B848_VGPRS(static_cast<uint64_t>(VBlocks)) |
170 S_00B848_SGPRS(static_cast<uint64_t>(SBlocks)) |
171 getComputePGMRSrc1Reg(*this, ST);
172
173 return Reg;
174}
175
177 const GCNSubtarget &ST) const {
178 if (AMDGPU::isCompute(CC)) {
179 return getComputePGMRSrc1(ST);
180 }
181 int64_t VBlocks, SBlocks;
182 VGPRBlocks->evaluateAsAbsolute(VBlocks);
183 SGPRBlocks->evaluateAsAbsolute(SBlocks);
184
185 return getPGMRSrc1Reg(*this, CC, ST) |
186 S_00B848_VGPRS(static_cast<uint64_t>(VBlocks)) |
187 S_00B848_SGPRS(static_cast<uint64_t>(SBlocks));
188}
189
191 int64_t ScratchEn;
192 ScratchEnable->evaluateAsAbsolute(ScratchEn);
193 return ScratchEn | getComputePGMRSrc2Reg(*this);
194}
195
198 return getComputePGMRSrc2();
199
200 return 0;
201}
202
204 MCContext &Ctx) const {
205 uint64_t Reg = getComputePGMRSrc1Reg(*this, ST);
206 const MCExpr *RegExpr = MCConstantExpr::create(Reg, Ctx);
207 const MCExpr *Res = MCBinaryExpr::createOr(
208 MaskShift(VGPRBlocks, /*Mask=*/0x3F, /*Shift=*/0, Ctx),
209 MaskShift(SGPRBlocks, /*Mask=*/0xF, /*Shift=*/6, Ctx), Ctx);
210 return MCBinaryExpr::createOr(RegExpr, Res, Ctx);
211}
212
214 const GCNSubtarget &ST,
215 MCContext &Ctx) const {
216 if (AMDGPU::isCompute(CC)) {
217 return getComputePGMRSrc1(ST, Ctx);
218 }
219
220 uint64_t Reg = getPGMRSrc1Reg(*this, CC, ST);
221 const MCExpr *RegExpr = MCConstantExpr::create(Reg, Ctx);
222 const MCExpr *Res = MCBinaryExpr::createOr(
223 MaskShift(VGPRBlocks, /*Mask=*/0x3F, /*Shift=*/0, Ctx),
224 MaskShift(SGPRBlocks, /*Mask=*/0xF, /*Shift=*/6, Ctx), Ctx);
225 return MCBinaryExpr::createOr(RegExpr, Res, Ctx);
226}
227
229 uint64_t Reg = getComputePGMRSrc2Reg(*this);
230 const MCExpr *RegExpr = MCConstantExpr::create(Reg, Ctx);
231 return MCBinaryExpr::createOr(ScratchEnable, RegExpr, Ctx);
232}
233
235 MCContext &Ctx) const {
237 return getComputePGMRSrc2(Ctx);
238
239 return MCConstantExpr::create(0, Ctx);
240}
AMD GCN specific subclass of TargetSubtarget.
#define S_00B84C_EXCP_EN(x)
Definition: SIDefines.h:1112
#define S_00B428_MEM_ORDERED(x)
Definition: SIDefines.h:1073
#define S_00B028_MEM_ORDERED(x)
Definition: SIDefines.h:1049
#define S_00B84C_TGID_Z_EN(x)
Definition: SIDefines.h:1095
#define S_00B228_WGP_MODE(x)
Definition: SIDefines.h:1061
#define S_00B848_MEM_ORDERED(x)
Definition: SIDefines.h:1150
#define S_00B228_MEM_ORDERED(x)
Definition: SIDefines.h:1064
#define S_00B848_RR_WG_MODE(x)
Definition: SIDefines.h:1138
#define S_00B84C_TGID_X_EN(x)
Definition: SIDefines.h:1089
#define S_00B848_DEBUG_MODE(x)
Definition: SIDefines.h:1141
#define S_00B428_WGP_MODE(x)
Definition: SIDefines.h:1070
#define S_00B848_PRIV(x)
Definition: SIDefines.h:1132
#define S_00B84C_TG_SIZE_EN(x)
Definition: SIDefines.h:1098
#define S_00B84C_TIDIG_COMP_CNT(x)
Definition: SIDefines.h:1101
#define S_00B84C_LDS_SIZE(x)
Definition: SIDefines.h:1109
#define S_00B84C_USER_SGPR(x)
Definition: SIDefines.h:1083
#define S_00B84C_TRAP_HANDLER(x)
Definition: SIDefines.h:1086
#define S_00B84C_TGID_Y_EN(x)
Definition: SIDefines.h:1092
#define S_00B128_MEM_ORDERED(x)
Definition: SIDefines.h:1056
#define S_00B848_WGP_MODE(x)
Definition: SIDefines.h:1147
#define S_00B848_SGPRS(x)
Definition: SIDefines.h:1123
#define S_00B84C_EXCP_EN_MSB(x)
Definition: SIDefines.h:1105
#define S_00B848_DX10_CLAMP(x)
Definition: SIDefines.h:1135
#define S_00B848_VGPRS(x)
Definition: SIDefines.h:1120
#define S_00B848_PRIORITY(x)
Definition: SIDefines.h:1126
#define S_00B848_IEEE_MODE(x)
Definition: SIDefines.h:1144
#define S_00B848_FLOAT_MODE(x)
Definition: SIDefines.h:1129
static uint64_t getComputePGMRSrc2Reg(const SIProgramInfo &ProgInfo)
static uint64_t getPGMRSrc1Reg(const SIProgramInfo &ProgInfo, CallingConv::ID CC, const GCNSubtarget &ST)
static uint64_t getComputePGMRSrc1Reg(const SIProgramInfo &ProgInfo, const GCNSubtarget &ST)
static const MCExpr * MaskShift(const MCExpr *Val, uint32_t Mask, uint32_t Shift, MCContext &Ctx)
Defines struct to track resource usage and hardware flags for kernels and entry functions.
static const MCBinaryExpr * createAnd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:541
static const MCBinaryExpr * createOr(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:601
static const MCBinaryExpr * createShl(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:606
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition: MCExpr.cpp:194
Context object for machine code objects.
Definition: MCContext.h:81
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
MCContext & getContext() const
bool isCompute(CallingConv::ID cc)
@ AMDGPU_VS
Used for Mesa vertex shaders, or AMDPAL last shader stage before rasterization (vertex shader if tess...
Definition: CallingConv.h:188
@ AMDGPU_HS
Used for Mesa/AMDPAL hull shaders (= tessellation control shaders).
Definition: CallingConv.h:206
@ AMDGPU_GS
Used for Mesa/AMDPAL geometry shaders.
Definition: CallingConv.h:191
@ AMDGPU_PS
Used for Mesa/AMDPAL pixel shaders.
Definition: CallingConv.h:194
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Track resource usage for kernels / entry functions.
Definition: SIProgramInfo.h:31
const MCExpr * NumSGPR
Definition: SIProgramInfo.h:70
const MCExpr * ComputePGMRSrc3GFX90A
Definition: SIProgramInfo.h:63
const MCExpr * NumArchVGPR
Definition: SIProgramInfo.h:66
const MCExpr * VGPRBlocks
Definition: SIProgramInfo.h:33
const MCExpr * ScratchBlocks
Definition: SIProgramInfo.h:48
const MCExpr * VCCUsed
Definition: SIProgramInfo.h:90
uint64_t getComputePGMRSrc1(const GCNSubtarget &ST) const
Compute the value of the ComputePGMRsrc1 register.
const MCExpr * FlatUsed
Definition: SIProgramInfo.h:74
uint32_t TrapHandlerEnable
Definition: SIProgramInfo.h:53
const MCExpr * ScratchEnable
Definition: SIProgramInfo.h:51
uint64_t getComputePGMRSrc2() const
Compute the value of the ComputePGMRsrc2 register.
const MCExpr * AccumOffset
Definition: SIProgramInfo.h:68
const MCExpr * NumAccVGPR
Definition: SIProgramInfo.h:67
const MCExpr * DynamicCallStack
Definition: SIProgramInfo.h:87
const MCExpr * SGPRBlocks
Definition: SIProgramInfo.h:34
const MCExpr * NumVGPRsForWavesPerEU
Definition: SIProgramInfo.h:80
const MCExpr * NumVGPR
Definition: SIProgramInfo.h:65
uint64_t getPGMRSrc2(CallingConv::ID CC) const
const MCExpr * Occupancy
Definition: SIProgramInfo.h:83
const MCExpr * ScratchSize
Definition: SIProgramInfo.h:44
const MCExpr * NumSGPRsForWavesPerEU
Definition: SIProgramInfo.h:77
void reset(const MachineFunction &MF)
uint64_t getPGMRSrc1(CallingConv::ID CC, const GCNSubtarget &ST) const