blob: aaef1405157e8074676d883861f0cdb2e11a0b40 [file] [log] [blame]
Tom Stellard75aadc22012-12-11 21:25:42 +00001//===-- AMDGPUAsmPrinter.cpp - AMDGPU Assebly printer --------------------===//
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/// \file
11///
12/// The AMDGPUAsmPrinter is used to print both assembly string and also binary
13/// code. When passed an MCAsmStreamer it prints assembly and when passed
14/// an MCObjectStreamer it outputs binary code.
15//
16//===----------------------------------------------------------------------===//
17//
18
Tom Stellard75aadc22012-12-11 21:25:42 +000019#include "AMDGPUAsmPrinter.h"
20#include "AMDGPU.h"
Tom Stellard2e59a452014-06-13 01:32:00 +000021#include "AMDGPUSubtarget.h"
Tom Stellard043de4c2013-05-06 17:50:51 +000022#include "R600Defines.h"
Vincent Lejeune117f0752013-04-23 17:34:12 +000023#include "R600MachineFunctionInfo.h"
Vincent Lejeune98a73802013-04-17 15:17:25 +000024#include "R600RegisterInfo.h"
Benjamin Kramerd78bb462013-05-23 17:10:37 +000025#include "SIDefines.h"
26#include "SIMachineFunctionInfo.h"
27#include "SIRegisterInfo.h"
Tom Stellard3a7beafb32013-04-15 17:51:30 +000028#include "llvm/MC/MCContext.h"
29#include "llvm/MC/MCSectionELF.h"
Tom Stellard75aadc22012-12-11 21:25:42 +000030#include "llvm/MC/MCStreamer.h"
Tom Stellard3a7beafb32013-04-15 17:51:30 +000031#include "llvm/Support/ELF.h"
Tom Stellardc026e8b2013-06-28 15:47:08 +000032#include "llvm/Support/MathExtras.h"
Tom Stellard75aadc22012-12-11 21:25:42 +000033#include "llvm/Support/TargetRegistry.h"
Chandler Carruthbe810232013-01-02 10:22:59 +000034#include "llvm/Target/TargetLoweringObjectFile.h"
Tom Stellard75aadc22012-12-11 21:25:42 +000035
36using namespace llvm;
37
Matt Arsenault0989d512014-06-26 17:22:30 +000038// TODO: This should get the default rounding mode from the kernel. We just set
39// the default here, but this could change if the OpenCL rounding mode pragmas
40// are used.
41//
42// The denormal mode here should match what is reported by the OpenCL runtime
43// for the CL_FP_DENORM bit from CL_DEVICE_{HALF|SINGLE|DOUBLE}_FP_CONFIG, but
44// can also be override to flush with the -cl-denorms-are-zero compiler flag.
45//
46// AMD OpenCL only sets flush none and reports CL_FP_DENORM for double
47// precision, and leaves single precision to flush all and does not report
48// CL_FP_DENORM for CL_DEVICE_SINGLE_FP_CONFIG. Mesa's OpenCL currently reports
49// CL_FP_DENORM for both.
Matt Arsenaultc6ae7b42014-07-14 23:40:43 +000050//
51// FIXME: It seems some instructions do not support single precision denormals
52// regardless of the mode (exp_*_f32, rcp_*_f32, rsq_*_f32, rsq_*f32, sqrt_f32,
53// and sin_f32, cos_f32 on most parts).
54
55// We want to use these instructions, and using fp32 denormals also causes
56// instructions to run at the double precision rate for the device so it's
57// probably best to just report no single precision denormals.
Matt Arsenaultf171cf22014-07-14 23:40:49 +000058static uint32_t getFPMode(const MachineFunction &F) {
59 const AMDGPUSubtarget& ST = F.getTarget().getSubtarget<AMDGPUSubtarget>();
60 // TODO: Is there any real use for the flush in only / flush out only modes?
61
62 uint32_t FP32Denormals =
63 ST.hasFP32Denormals() ? FP_DENORM_FLUSH_NONE : FP_DENORM_FLUSH_IN_FLUSH_OUT;
64
65 uint32_t FP64Denormals =
66 ST.hasFP64Denormals() ? FP_DENORM_FLUSH_NONE : FP_DENORM_FLUSH_IN_FLUSH_OUT;
67
Matt Arsenault0989d512014-06-26 17:22:30 +000068 return FP_ROUND_MODE_SP(FP_ROUND_ROUND_TO_NEAREST) |
69 FP_ROUND_MODE_DP(FP_ROUND_ROUND_TO_NEAREST) |
Matt Arsenaultf171cf22014-07-14 23:40:49 +000070 FP_DENORM_MODE_SP(FP32Denormals) |
71 FP_DENORM_MODE_DP(FP64Denormals);
Matt Arsenault0989d512014-06-26 17:22:30 +000072}
Tom Stellard75aadc22012-12-11 21:25:42 +000073
74static AsmPrinter *createAMDGPUAsmPrinterPass(TargetMachine &tm,
75 MCStreamer &Streamer) {
76 return new AMDGPUAsmPrinter(tm, Streamer);
77}
78
79extern "C" void LLVMInitializeR600AsmPrinter() {
80 TargetRegistry::RegisterAsmPrinter(TheAMDGPUTarget, createAMDGPUAsmPrinterPass);
81}
82
Tom Stellarded699252013-10-12 05:02:51 +000083AMDGPUAsmPrinter::AMDGPUAsmPrinter(TargetMachine &TM, MCStreamer &Streamer)
Matt Arsenault89cc49f2013-12-05 05:15:35 +000084 : AsmPrinter(TM, Streamer) {
Rafael Espindola277f9062014-01-31 22:14:06 +000085 DisasmEnabled = TM.getSubtarget<AMDGPUSubtarget>().dumpCode();
Tom Stellarded699252013-10-12 05:02:51 +000086}
87
Tom Stellard75aadc22012-12-11 21:25:42 +000088bool AMDGPUAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
Tom Stellard75aadc22012-12-11 21:25:42 +000089 SetupMachineFunction(MF);
Matt Arsenault89cc49f2013-12-05 05:15:35 +000090
Rafael Espindola19656ba2014-01-31 21:54:49 +000091 OutStreamer.emitRawComment(Twine('@') + MF.getName() + Twine(':'));
Vincent Lejeune98a73802013-04-17 15:17:25 +000092
Tom Stellarded699252013-10-12 05:02:51 +000093 MCContext &Context = getObjFileLowering().getContext();
94 const MCSectionELF *ConfigSection = Context.getELFSection(".AMDGPU.config",
Tom Stellard34e40682013-04-24 23:56:14 +000095 ELF::SHT_PROGBITS, 0,
Vincent Lejeune98a73802013-04-17 15:17:25 +000096 SectionKind::getReadOnly());
97 OutStreamer.SwitchSection(ConfigSection);
Matt Arsenault89cc49f2013-12-05 05:15:35 +000098
Tom Stellarded699252013-10-12 05:02:51 +000099 const AMDGPUSubtarget &STM = TM.getSubtarget<AMDGPUSubtarget>();
Matt Arsenault89cc49f2013-12-05 05:15:35 +0000100 SIProgramInfo KernelInfo;
Tom Stellarda6c6e1b2013-06-07 20:37:48 +0000101 if (STM.getGeneration() > AMDGPUSubtarget::NORTHERN_ISLANDS) {
Matt Arsenaulte500e322014-04-15 22:40:47 +0000102 getSIProgramInfo(KernelInfo, MF);
Matt Arsenault89cc49f2013-12-05 05:15:35 +0000103 EmitProgramInfoSI(MF, KernelInfo);
Vincent Lejeune98a73802013-04-17 15:17:25 +0000104 } else {
105 EmitProgramInfoR600(MF);
Tom Stellard75aadc22012-12-11 21:25:42 +0000106 }
Tom Stellarded699252013-10-12 05:02:51 +0000107
108 DisasmLines.clear();
109 HexLines.clear();
110 DisasmLineMaxLen = 0;
111
Tom Stellard3a7beafb32013-04-15 17:51:30 +0000112 OutStreamer.SwitchSection(getObjFileLowering().getTextSection());
Tom Stellard75aadc22012-12-11 21:25:42 +0000113 EmitFunctionBody();
Tom Stellarded699252013-10-12 05:02:51 +0000114
Rafael Espindola887541f2014-01-31 22:08:19 +0000115 if (isVerbose()) {
Matt Arsenault89cc49f2013-12-05 05:15:35 +0000116 const MCSectionELF *CommentSection
117 = Context.getELFSection(".AMDGPU.csdata",
118 ELF::SHT_PROGBITS, 0,
119 SectionKind::getReadOnly());
120 OutStreamer.SwitchSection(CommentSection);
121
Matt Arsenaulte500e322014-04-15 22:40:47 +0000122 if (STM.getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS) {
Rafael Espindola98f5b542014-01-27 00:19:41 +0000123 OutStreamer.emitRawComment(" Kernel info:", false);
Matt Arsenaulte500e322014-04-15 22:40:47 +0000124 OutStreamer.emitRawComment(" codeLenInByte = " + Twine(KernelInfo.CodeLen),
125 false);
Rafael Espindola98f5b542014-01-27 00:19:41 +0000126 OutStreamer.emitRawComment(" NumSgprs: " + Twine(KernelInfo.NumSGPR),
Rafael Espindolabcf890b2014-01-27 00:16:00 +0000127 false);
Rafael Espindola98f5b542014-01-27 00:19:41 +0000128 OutStreamer.emitRawComment(" NumVgprs: " + Twine(KernelInfo.NumVGPR),
Rafael Espindolabcf890b2014-01-27 00:16:00 +0000129 false);
Matt Arsenault0989d512014-06-26 17:22:30 +0000130 OutStreamer.emitRawComment(" FloatMode: " + Twine(KernelInfo.FloatMode),
131 false);
132 OutStreamer.emitRawComment(" IeeeMode: " + Twine(KernelInfo.IEEEMode),
133 false);
Tom Stellard08b6af92014-01-22 21:55:35 +0000134 } else {
135 R600MachineFunctionInfo *MFI = MF.getInfo<R600MachineFunctionInfo>();
Rafael Espindola887541f2014-01-31 22:08:19 +0000136 OutStreamer.emitRawComment(
Tom Stellard08b6af92014-01-22 21:55:35 +0000137 Twine("SQ_PGM_RESOURCES:STACK_SIZE = " + Twine(MFI->StackSize)));
138 }
Matt Arsenault89cc49f2013-12-05 05:15:35 +0000139 }
140
Tom Stellarded699252013-10-12 05:02:51 +0000141 if (STM.dumpCode()) {
142#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
143 MF.dump();
144#endif
145
146 if (DisasmEnabled) {
147 OutStreamer.SwitchSection(Context.getELFSection(".AMDGPU.disasm",
148 ELF::SHT_NOTE, 0,
149 SectionKind::getReadOnly()));
150
151 for (size_t i = 0; i < DisasmLines.size(); ++i) {
152 std::string Comment(DisasmLineMaxLen - DisasmLines[i].size(), ' ');
153 Comment += " ; " + HexLines[i] + "\n";
154
155 OutStreamer.EmitBytes(StringRef(DisasmLines[i]));
156 OutStreamer.EmitBytes(StringRef(Comment));
157 }
158 }
159 }
160
Tom Stellard75aadc22012-12-11 21:25:42 +0000161 return false;
162}
163
Matt Arsenaultd32dbb62014-07-13 03:06:43 +0000164void AMDGPUAsmPrinter::EmitProgramInfoR600(const MachineFunction &MF) {
Vincent Lejeune98a73802013-04-17 15:17:25 +0000165 unsigned MaxGPR = 0;
Vincent Lejeune4a0beb52013-04-30 00:13:13 +0000166 bool killPixel = false;
Matt Arsenaultd32dbb62014-07-13 03:06:43 +0000167 const R600RegisterInfo *RI
168 = static_cast<const R600RegisterInfo*>(TM.getRegisterInfo());
169 const R600MachineFunctionInfo *MFI = MF.getInfo<R600MachineFunctionInfo>();
Tom Stellard043de4c2013-05-06 17:50:51 +0000170 const AMDGPUSubtarget &STM = TM.getSubtarget<AMDGPUSubtarget>();
Vincent Lejeune98a73802013-04-17 15:17:25 +0000171
Matt Arsenaultd32dbb62014-07-13 03:06:43 +0000172 for (const MachineBasicBlock &MBB : MF) {
173 for (const MachineInstr &MI : MBB) {
Vincent Lejeune4a0beb52013-04-30 00:13:13 +0000174 if (MI.getOpcode() == AMDGPU::KILLGT)
175 killPixel = true;
Vincent Lejeune98a73802013-04-17 15:17:25 +0000176 unsigned numOperands = MI.getNumOperands();
177 for (unsigned op_idx = 0; op_idx < numOperands; op_idx++) {
Matt Arsenaultd32dbb62014-07-13 03:06:43 +0000178 const MachineOperand &MO = MI.getOperand(op_idx);
Vincent Lejeune98a73802013-04-17 15:17:25 +0000179 if (!MO.isReg())
180 continue;
181 unsigned HWReg = RI->getEncodingValue(MO.getReg()) & 0xff;
182
183 // Register with value > 127 aren't GPR
184 if (HWReg > 127)
185 continue;
186 MaxGPR = std::max(MaxGPR, HWReg);
187 }
188 }
189 }
Tom Stellard043de4c2013-05-06 17:50:51 +0000190
191 unsigned RsrcReg;
Tom Stellarda6c6e1b2013-06-07 20:37:48 +0000192 if (STM.getGeneration() >= AMDGPUSubtarget::EVERGREEN) {
Tom Stellard043de4c2013-05-06 17:50:51 +0000193 // Evergreen / Northern Islands
Matt Arsenault762af962014-07-13 03:06:39 +0000194 switch (MFI->getShaderType()) {
Tom Stellard043de4c2013-05-06 17:50:51 +0000195 default: // Fall through
196 case ShaderType::COMPUTE: RsrcReg = R_0288D4_SQ_PGM_RESOURCES_LS; break;
197 case ShaderType::GEOMETRY: RsrcReg = R_028878_SQ_PGM_RESOURCES_GS; break;
198 case ShaderType::PIXEL: RsrcReg = R_028844_SQ_PGM_RESOURCES_PS; break;
199 case ShaderType::VERTEX: RsrcReg = R_028860_SQ_PGM_RESOURCES_VS; break;
200 }
201 } else {
202 // R600 / R700
Matt Arsenault762af962014-07-13 03:06:39 +0000203 switch (MFI->getShaderType()) {
Tom Stellard043de4c2013-05-06 17:50:51 +0000204 default: // Fall through
205 case ShaderType::GEOMETRY: // Fall through
206 case ShaderType::COMPUTE: // Fall through
207 case ShaderType::VERTEX: RsrcReg = R_028868_SQ_PGM_RESOURCES_VS; break;
208 case ShaderType::PIXEL: RsrcReg = R_028850_SQ_PGM_RESOURCES_PS; break;
209 }
210 }
211
212 OutStreamer.EmitIntValue(RsrcReg, 4);
213 OutStreamer.EmitIntValue(S_NUM_GPRS(MaxGPR + 1) |
214 S_STACK_SIZE(MFI->StackSize), 4);
215 OutStreamer.EmitIntValue(R_02880C_DB_SHADER_CONTROL, 4);
216 OutStreamer.EmitIntValue(S_02880C_KILL_ENABLE(killPixel), 4);
Tom Stellardc026e8b2013-06-28 15:47:08 +0000217
Matt Arsenault762af962014-07-13 03:06:39 +0000218 if (MFI->getShaderType() == ShaderType::COMPUTE) {
Tom Stellardc026e8b2013-06-28 15:47:08 +0000219 OutStreamer.EmitIntValue(R_0288E8_SQ_LDS_ALLOC, 4);
220 OutStreamer.EmitIntValue(RoundUpToAlignment(MFI->LDSSize, 4) >> 2, 4);
221 }
Vincent Lejeune98a73802013-04-17 15:17:25 +0000222}
223
Matt Arsenaulte500e322014-04-15 22:40:47 +0000224void AMDGPUAsmPrinter::getSIProgramInfo(SIProgramInfo &ProgInfo,
Matt Arsenaultd32dbb62014-07-13 03:06:43 +0000225 const MachineFunction &MF) const {
Matt Arsenaulte500e322014-04-15 22:40:47 +0000226 uint64_t CodeSize = 0;
Tom Stellard75aadc22012-12-11 21:25:42 +0000227 unsigned MaxSGPR = 0;
228 unsigned MaxVGPR = 0;
229 bool VCCUsed = false;
Matt Arsenaultd32dbb62014-07-13 03:06:43 +0000230 const SIRegisterInfo *RI
231 = static_cast<const SIRegisterInfo*>(TM.getRegisterInfo());
Tom Stellard75aadc22012-12-11 21:25:42 +0000232
Matt Arsenaultd32dbb62014-07-13 03:06:43 +0000233 for (const MachineBasicBlock &MBB : MF) {
234 for (const MachineInstr &MI : MBB) {
Matt Arsenaulte500e322014-04-15 22:40:47 +0000235 // TODO: CodeSize should account for multiple functions.
236 CodeSize += MI.getDesc().Size;
237
Tom Stellard75aadc22012-12-11 21:25:42 +0000238 unsigned numOperands = MI.getNumOperands();
239 for (unsigned op_idx = 0; op_idx < numOperands; op_idx++) {
Matt Arsenaultd32dbb62014-07-13 03:06:43 +0000240 const MachineOperand &MO = MI.getOperand(op_idx);
Tom Stellard75aadc22012-12-11 21:25:42 +0000241 unsigned width = 0;
242 bool isSGPR = false;
Matt Arsenaulta64ee172014-01-08 21:47:14 +0000243
Tom Stellard75aadc22012-12-11 21:25:42 +0000244 if (!MO.isReg()) {
245 continue;
246 }
Matt Arsenaulta64ee172014-01-08 21:47:14 +0000247 unsigned reg = MO.getReg();
Tom Stellardfbe435d2014-03-17 17:03:51 +0000248 if (reg == AMDGPU::VCC || reg == AMDGPU::VCC_LO ||
249 reg == AMDGPU::VCC_HI) {
Tom Stellard75aadc22012-12-11 21:25:42 +0000250 VCCUsed = true;
251 continue;
252 }
Matt Arsenault65864e32013-10-22 21:11:31 +0000253
Tom Stellard75aadc22012-12-11 21:25:42 +0000254 switch (reg) {
255 default: break;
Matt Arsenault65864e32013-10-22 21:11:31 +0000256 case AMDGPU::SCC:
Tom Stellard75aadc22012-12-11 21:25:42 +0000257 case AMDGPU::EXEC:
Tom Stellard75aadc22012-12-11 21:25:42 +0000258 case AMDGPU::M0:
259 continue;
260 }
261
262 if (AMDGPU::SReg_32RegClass.contains(reg)) {
263 isSGPR = true;
264 width = 1;
265 } else if (AMDGPU::VReg_32RegClass.contains(reg)) {
266 isSGPR = false;
267 width = 1;
268 } else if (AMDGPU::SReg_64RegClass.contains(reg)) {
269 isSGPR = true;
270 width = 2;
271 } else if (AMDGPU::VReg_64RegClass.contains(reg)) {
272 isSGPR = false;
273 width = 2;
Christian Konig8b1ed282013-04-10 08:39:16 +0000274 } else if (AMDGPU::VReg_96RegClass.contains(reg)) {
275 isSGPR = false;
276 width = 3;
Tom Stellard75aadc22012-12-11 21:25:42 +0000277 } else if (AMDGPU::SReg_128RegClass.contains(reg)) {
278 isSGPR = true;
279 width = 4;
280 } else if (AMDGPU::VReg_128RegClass.contains(reg)) {
281 isSGPR = false;
282 width = 4;
283 } else if (AMDGPU::SReg_256RegClass.contains(reg)) {
284 isSGPR = true;
285 width = 8;
Tom Stellard538ceeb2013-02-07 17:02:09 +0000286 } else if (AMDGPU::VReg_256RegClass.contains(reg)) {
287 isSGPR = false;
288 width = 8;
Tom Stellarda66cafa2013-10-23 00:44:12 +0000289 } else if (AMDGPU::SReg_512RegClass.contains(reg)) {
290 isSGPR = true;
291 width = 16;
Tom Stellard538ceeb2013-02-07 17:02:09 +0000292 } else if (AMDGPU::VReg_512RegClass.contains(reg)) {
293 isSGPR = false;
294 width = 16;
Tom Stellard75aadc22012-12-11 21:25:42 +0000295 } else {
Matt Arsenaulteaa3a7e2013-12-10 21:37:42 +0000296 llvm_unreachable("Unknown register class");
Tom Stellard75aadc22012-12-11 21:25:42 +0000297 }
Matt Arsenaulta64ee172014-01-08 21:47:14 +0000298 unsigned hwReg = RI->getEncodingValue(reg) & 0xff;
299 unsigned maxUsed = hwReg + width - 1;
Tom Stellard75aadc22012-12-11 21:25:42 +0000300 if (isSGPR) {
301 MaxSGPR = maxUsed > MaxSGPR ? maxUsed : MaxSGPR;
302 } else {
303 MaxVGPR = maxUsed > MaxVGPR ? maxUsed : MaxVGPR;
304 }
305 }
306 }
307 }
Matt Arsenault89cc49f2013-12-05 05:15:35 +0000308
309 if (VCCUsed)
Tom Stellard75aadc22012-12-11 21:25:42 +0000310 MaxSGPR += 2;
Matt Arsenault89cc49f2013-12-05 05:15:35 +0000311
Matt Arsenaulte500e322014-04-15 22:40:47 +0000312 ProgInfo.NumVGPR = MaxVGPR;
Matt Arsenault0989d512014-06-26 17:22:30 +0000313 ProgInfo.NumSGPR = MaxSGPR;
314
315 // Set the value to initialize FP_ROUND and FP_DENORM parts of the mode
316 // register.
317 ProgInfo.FloatMode = getFPMode(MF);
318
319 // XXX: Not quite sure what this does, but sc seems to unset this.
320 ProgInfo.IEEEMode = 0;
321
322 // Do not clamp NAN to 0.
323 ProgInfo.DX10Clamp = 0;
324
325 ProgInfo.CodeLen = CodeSize;
Matt Arsenault89cc49f2013-12-05 05:15:35 +0000326}
327
Matt Arsenaultd32dbb62014-07-13 03:06:43 +0000328void AMDGPUAsmPrinter::EmitProgramInfoSI(const MachineFunction &MF,
Matt Arsenault89cc49f2013-12-05 05:15:35 +0000329 const SIProgramInfo &KernelInfo) {
330 const AMDGPUSubtarget &STM = TM.getSubtarget<AMDGPUSubtarget>();
Matt Arsenaultd32dbb62014-07-13 03:06:43 +0000331 const SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>();
Matt Arsenault0989d512014-06-26 17:22:30 +0000332
Tom Stellardcb97e3a2013-04-15 17:51:35 +0000333 unsigned RsrcReg;
Matt Arsenault762af962014-07-13 03:06:39 +0000334 switch (MFI->getShaderType()) {
Tom Stellardcb97e3a2013-04-15 17:51:35 +0000335 default: // Fall through
336 case ShaderType::COMPUTE: RsrcReg = R_00B848_COMPUTE_PGM_RSRC1; break;
337 case ShaderType::GEOMETRY: RsrcReg = R_00B228_SPI_SHADER_PGM_RSRC1_GS; break;
338 case ShaderType::PIXEL: RsrcReg = R_00B028_SPI_SHADER_PGM_RSRC1_PS; break;
339 case ShaderType::VERTEX: RsrcReg = R_00B128_SPI_SHADER_PGM_RSRC1_VS; break;
340 }
341
Tom Stellard6e1ee472013-10-29 16:37:28 +0000342 unsigned LDSAlignShift;
343 if (STM.getGeneration() < AMDGPUSubtarget::SEA_ISLANDS) {
Matt Arsenault0989d512014-06-26 17:22:30 +0000344 // LDS is allocated in 64 dword blocks.
Tom Stellard6e1ee472013-10-29 16:37:28 +0000345 LDSAlignShift = 8;
346 } else {
Matt Arsenault0989d512014-06-26 17:22:30 +0000347 // LDS is allocated in 128 dword blocks.
Tom Stellard6e1ee472013-10-29 16:37:28 +0000348 LDSAlignShift = 9;
349 }
Matt Arsenault0989d512014-06-26 17:22:30 +0000350
Tom Stellard6e1ee472013-10-29 16:37:28 +0000351 unsigned LDSBlocks =
Matt Arsenault0989d512014-06-26 17:22:30 +0000352 RoundUpToAlignment(MFI->LDSSize, 1 << LDSAlignShift) >> LDSAlignShift;
Tom Stellard6e1ee472013-10-29 16:37:28 +0000353
Matt Arsenault762af962014-07-13 03:06:39 +0000354 if (MFI->getShaderType() == ShaderType::COMPUTE) {
Matt Arsenault0989d512014-06-26 17:22:30 +0000355 OutStreamer.EmitIntValue(R_00B848_COMPUTE_PGM_RSRC1, 4);
356
357 const uint32_t ComputePGMRSrc1 =
358 S_00B848_VGPRS(KernelInfo.NumVGPR / 4) |
359 S_00B848_SGPRS(KernelInfo.NumSGPR / 8) |
360 S_00B848_PRIORITY(KernelInfo.Priority) |
361 S_00B848_FLOAT_MODE(KernelInfo.FloatMode) |
362 S_00B848_PRIV(KernelInfo.Priv) |
363 S_00B848_DX10_CLAMP(KernelInfo.DX10Clamp) |
364 S_00B848_IEEE_MODE(KernelInfo.DebugMode) |
365 S_00B848_IEEE_MODE(KernelInfo.IEEEMode);
366
367 OutStreamer.EmitIntValue(ComputePGMRSrc1, 4);
368
Michel Danzer49812b52013-07-10 16:37:07 +0000369 OutStreamer.EmitIntValue(R_00B84C_COMPUTE_PGM_RSRC2, 4);
Tom Stellard6e1ee472013-10-29 16:37:28 +0000370 OutStreamer.EmitIntValue(S_00B84C_LDS_SIZE(LDSBlocks), 4);
Matt Arsenault0989d512014-06-26 17:22:30 +0000371 } else {
372 OutStreamer.EmitIntValue(RsrcReg, 4);
373 OutStreamer.EmitIntValue(S_00B028_VGPRS(KernelInfo.NumVGPR / 4) |
374 S_00B028_SGPRS(KernelInfo.NumSGPR / 8), 4);
Michel Danzer49812b52013-07-10 16:37:07 +0000375 }
Matt Arsenault0989d512014-06-26 17:22:30 +0000376
Matt Arsenault762af962014-07-13 03:06:39 +0000377 if (MFI->getShaderType() == ShaderType::PIXEL) {
Michel Danzer49812b52013-07-10 16:37:07 +0000378 OutStreamer.EmitIntValue(R_00B02C_SPI_SHADER_PGM_RSRC2_PS, 4);
Tom Stellard6e1ee472013-10-29 16:37:28 +0000379 OutStreamer.EmitIntValue(S_00B02C_EXTRA_LDS_SIZE(LDSBlocks), 4);
Tom Stellardcb97e3a2013-04-15 17:51:35 +0000380 OutStreamer.EmitIntValue(R_0286CC_SPI_PS_INPUT_ENA, 4);
381 OutStreamer.EmitIntValue(MFI->PSInputAddr, 4);
382 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000383}