Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 1 | //===-- 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 | |
| 19 | #include "AMDGPUAsmPrinter.h" |
Tom Stellard | 347ac79 | 2015-06-26 21:15:07 +0000 | [diff] [blame] | 20 | #include "MCTargetDesc/AMDGPUTargetStreamer.h" |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 21 | #include "InstPrinter/AMDGPUInstPrinter.h" |
Tom Stellard | 347ac79 | 2015-06-26 21:15:07 +0000 | [diff] [blame] | 22 | #include "Utils/AMDGPUBaseInfo.h" |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 23 | #include "AMDGPU.h" |
| 24 | #include "AMDKernelCodeT.h" |
| 25 | #include "AMDGPUSubtarget.h" |
| 26 | #include "R600Defines.h" |
| 27 | #include "R600MachineFunctionInfo.h" |
| 28 | #include "R600RegisterInfo.h" |
| 29 | #include "SIDefines.h" |
| 30 | #include "SIMachineFunctionInfo.h" |
Matt Arsenault | a9720c6 | 2016-06-20 17:51:32 +0000 | [diff] [blame^] | 31 | #include "SIInstrInfo.h" |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 32 | #include "SIRegisterInfo.h" |
| 33 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 34 | #include "llvm/MC/MCContext.h" |
| 35 | #include "llvm/MC/MCSectionELF.h" |
| 36 | #include "llvm/MC/MCStreamer.h" |
| 37 | #include "llvm/Support/ELF.h" |
| 38 | #include "llvm/Support/MathExtras.h" |
| 39 | #include "llvm/Support/TargetRegistry.h" |
| 40 | #include "llvm/Target/TargetLoweringObjectFile.h" |
| 41 | |
| 42 | using namespace llvm; |
| 43 | |
| 44 | // TODO: This should get the default rounding mode from the kernel. We just set |
| 45 | // the default here, but this could change if the OpenCL rounding mode pragmas |
| 46 | // are used. |
| 47 | // |
| 48 | // The denormal mode here should match what is reported by the OpenCL runtime |
| 49 | // for the CL_FP_DENORM bit from CL_DEVICE_{HALF|SINGLE|DOUBLE}_FP_CONFIG, but |
| 50 | // can also be override to flush with the -cl-denorms-are-zero compiler flag. |
| 51 | // |
| 52 | // AMD OpenCL only sets flush none and reports CL_FP_DENORM for double |
| 53 | // precision, and leaves single precision to flush all and does not report |
| 54 | // CL_FP_DENORM for CL_DEVICE_SINGLE_FP_CONFIG. Mesa's OpenCL currently reports |
| 55 | // CL_FP_DENORM for both. |
| 56 | // |
| 57 | // FIXME: It seems some instructions do not support single precision denormals |
| 58 | // regardless of the mode (exp_*_f32, rcp_*_f32, rsq_*_f32, rsq_*f32, sqrt_f32, |
| 59 | // and sin_f32, cos_f32 on most parts). |
| 60 | |
| 61 | // We want to use these instructions, and using fp32 denormals also causes |
| 62 | // instructions to run at the double precision rate for the device so it's |
| 63 | // probably best to just report no single precision denormals. |
| 64 | static uint32_t getFPMode(const MachineFunction &F) { |
| 65 | const AMDGPUSubtarget& ST = F.getSubtarget<AMDGPUSubtarget>(); |
| 66 | // TODO: Is there any real use for the flush in only / flush out only modes? |
| 67 | |
| 68 | uint32_t FP32Denormals = |
| 69 | ST.hasFP32Denormals() ? FP_DENORM_FLUSH_NONE : FP_DENORM_FLUSH_IN_FLUSH_OUT; |
| 70 | |
| 71 | uint32_t FP64Denormals = |
| 72 | ST.hasFP64Denormals() ? FP_DENORM_FLUSH_NONE : FP_DENORM_FLUSH_IN_FLUSH_OUT; |
| 73 | |
| 74 | return FP_ROUND_MODE_SP(FP_ROUND_ROUND_TO_NEAREST) | |
| 75 | FP_ROUND_MODE_DP(FP_ROUND_ROUND_TO_NEAREST) | |
| 76 | FP_DENORM_MODE_SP(FP32Denormals) | |
| 77 | FP_DENORM_MODE_DP(FP64Denormals); |
| 78 | } |
| 79 | |
| 80 | static AsmPrinter * |
| 81 | createAMDGPUAsmPrinterPass(TargetMachine &tm, |
| 82 | std::unique_ptr<MCStreamer> &&Streamer) { |
| 83 | return new AMDGPUAsmPrinter(tm, std::move(Streamer)); |
| 84 | } |
| 85 | |
| 86 | extern "C" void LLVMInitializeAMDGPUAsmPrinter() { |
| 87 | TargetRegistry::RegisterAsmPrinter(TheAMDGPUTarget, createAMDGPUAsmPrinterPass); |
| 88 | TargetRegistry::RegisterAsmPrinter(TheGCNTarget, createAMDGPUAsmPrinterPass); |
| 89 | } |
| 90 | |
| 91 | AMDGPUAsmPrinter::AMDGPUAsmPrinter(TargetMachine &TM, |
| 92 | std::unique_ptr<MCStreamer> Streamer) |
| 93 | : AsmPrinter(TM, std::move(Streamer)) {} |
| 94 | |
Tom Stellard | f421837 | 2016-01-12 17:18:17 +0000 | [diff] [blame] | 95 | void AMDGPUAsmPrinter::EmitStartOfAsmFile(Module &M) { |
| 96 | if (TM.getTargetTriple().getOS() != Triple::AMDHSA) |
| 97 | return; |
| 98 | |
| 99 | // Need to construct an MCSubtargetInfo here in case we have no functions |
| 100 | // in the module. |
| 101 | std::unique_ptr<MCSubtargetInfo> STI(TM.getTarget().createMCSubtargetInfo( |
| 102 | TM.getTargetTriple().str(), TM.getTargetCPU(), |
| 103 | TM.getTargetFeatureString())); |
| 104 | |
| 105 | AMDGPUTargetStreamer *TS = |
| 106 | static_cast<AMDGPUTargetStreamer *>(OutStreamer->getTargetStreamer()); |
| 107 | |
Tom Stellard | fcfaea4 | 2016-05-05 17:03:33 +0000 | [diff] [blame] | 108 | TS->EmitDirectiveHSACodeObjectVersion(2, 0); |
| 109 | |
Tom Stellard | f421837 | 2016-01-12 17:18:17 +0000 | [diff] [blame] | 110 | AMDGPU::IsaVersion ISA = AMDGPU::getIsaVersion(STI->getFeatureBits()); |
| 111 | TS->EmitDirectiveHSACodeObjectISA(ISA.Major, ISA.Minor, ISA.Stepping, |
| 112 | "AMD", "AMDGPU"); |
| 113 | } |
| 114 | |
Tom Stellard | f151a45 | 2015-06-26 21:14:58 +0000 | [diff] [blame] | 115 | void AMDGPUAsmPrinter::EmitFunctionBodyStart() { |
| 116 | const AMDGPUSubtarget &STM = MF->getSubtarget<AMDGPUSubtarget>(); |
| 117 | SIProgramInfo KernelInfo; |
| 118 | if (STM.isAmdHsaOS()) { |
| 119 | getSIProgramInfo(KernelInfo, *MF); |
| 120 | EmitAmdKernelCodeT(*MF, KernelInfo); |
| 121 | } |
| 122 | } |
| 123 | |
Tom Stellard | 1e1b05d | 2015-11-06 11:45:14 +0000 | [diff] [blame] | 124 | void AMDGPUAsmPrinter::EmitFunctionEntryLabel() { |
| 125 | const SIMachineFunctionInfo *MFI = MF->getInfo<SIMachineFunctionInfo>(); |
| 126 | const AMDGPUSubtarget &STM = MF->getSubtarget<AMDGPUSubtarget>(); |
| 127 | if (MFI->isKernel() && STM.isAmdHsaOS()) { |
| 128 | AMDGPUTargetStreamer *TS = |
| 129 | static_cast<AMDGPUTargetStreamer *>(OutStreamer->getTargetStreamer()); |
| 130 | TS->EmitAMDGPUSymbolType(CurrentFnSym->getName(), |
| 131 | ELF::STT_AMDGPU_HSA_KERNEL); |
| 132 | } |
| 133 | |
| 134 | AsmPrinter::EmitFunctionEntryLabel(); |
| 135 | } |
| 136 | |
Tom Stellard | e3b5aea | 2015-12-02 17:00:42 +0000 | [diff] [blame] | 137 | void AMDGPUAsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) { |
| 138 | |
Tom Stellard | 00f2f91 | 2015-12-02 19:47:57 +0000 | [diff] [blame] | 139 | // Group segment variables aren't emitted in HSA. |
| 140 | if (AMDGPU::isGroupSegment(GV)) |
| 141 | return; |
| 142 | |
Tom Stellard | fcfaea4 | 2016-05-05 17:03:33 +0000 | [diff] [blame] | 143 | AsmPrinter::EmitGlobalVariable(GV); |
Tom Stellard | e3b5aea | 2015-12-02 17:00:42 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 146 | bool AMDGPUAsmPrinter::runOnMachineFunction(MachineFunction &MF) { |
| 147 | |
| 148 | // The starting address of all shader programs must be 256 bytes aligned. |
| 149 | MF.setAlignment(8); |
| 150 | |
| 151 | SetupMachineFunction(MF); |
| 152 | |
| 153 | MCContext &Context = getObjFileLowering().getContext(); |
| 154 | MCSectionELF *ConfigSection = |
| 155 | Context.getELFSection(".AMDGPU.config", ELF::SHT_PROGBITS, 0); |
| 156 | OutStreamer->SwitchSection(ConfigSection); |
| 157 | |
| 158 | const AMDGPUSubtarget &STM = MF.getSubtarget<AMDGPUSubtarget>(); |
| 159 | SIProgramInfo KernelInfo; |
Tom Stellard | f151a45 | 2015-06-26 21:14:58 +0000 | [diff] [blame] | 160 | if (STM.getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS) { |
Matt Arsenault | 297ae31 | 2015-08-15 00:12:39 +0000 | [diff] [blame] | 161 | getSIProgramInfo(KernelInfo, MF); |
Tom Stellard | f151a45 | 2015-06-26 21:14:58 +0000 | [diff] [blame] | 162 | if (!STM.isAmdHsaOS()) { |
Tom Stellard | f151a45 | 2015-06-26 21:14:58 +0000 | [diff] [blame] | 163 | EmitProgramInfoSI(MF, KernelInfo); |
| 164 | } |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 165 | } else { |
| 166 | EmitProgramInfoR600(MF); |
| 167 | } |
| 168 | |
| 169 | DisasmLines.clear(); |
| 170 | HexLines.clear(); |
| 171 | DisasmLineMaxLen = 0; |
| 172 | |
| 173 | EmitFunctionBody(); |
| 174 | |
| 175 | if (isVerbose()) { |
| 176 | MCSectionELF *CommentSection = |
| 177 | Context.getELFSection(".AMDGPU.csdata", ELF::SHT_PROGBITS, 0); |
| 178 | OutStreamer->SwitchSection(CommentSection); |
| 179 | |
| 180 | if (STM.getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS) { |
| 181 | OutStreamer->emitRawComment(" Kernel info:", false); |
| 182 | OutStreamer->emitRawComment(" codeLenInByte = " + Twine(KernelInfo.CodeLen), |
| 183 | false); |
| 184 | OutStreamer->emitRawComment(" NumSgprs: " + Twine(KernelInfo.NumSGPR), |
| 185 | false); |
| 186 | OutStreamer->emitRawComment(" NumVgprs: " + Twine(KernelInfo.NumVGPR), |
| 187 | false); |
| 188 | OutStreamer->emitRawComment(" FloatMode: " + Twine(KernelInfo.FloatMode), |
| 189 | false); |
| 190 | OutStreamer->emitRawComment(" IeeeMode: " + Twine(KernelInfo.IEEEMode), |
| 191 | false); |
| 192 | OutStreamer->emitRawComment(" ScratchSize: " + Twine(KernelInfo.ScratchSize), |
| 193 | false); |
Matt Arsenault | fd8ab09 | 2016-04-14 22:11:51 +0000 | [diff] [blame] | 194 | OutStreamer->emitRawComment(" LDSByteSize: " + Twine(KernelInfo.LDSSize) + |
| 195 | " bytes/workgroup (compile time only)", false); |
Matt Arsenault | d41c0db | 2015-11-05 05:27:07 +0000 | [diff] [blame] | 196 | |
Konstantin Zhuravlyov | 1d99c4d | 2016-04-26 15:43:14 +0000 | [diff] [blame] | 197 | OutStreamer->emitRawComment(" ReservedVGPRFirst: " + Twine(KernelInfo.ReservedVGPRFirst), |
| 198 | false); |
| 199 | OutStreamer->emitRawComment(" ReservedVGPRCount: " + Twine(KernelInfo.ReservedVGPRCount), |
| 200 | false); |
| 201 | |
Matt Arsenault | d41c0db | 2015-11-05 05:27:07 +0000 | [diff] [blame] | 202 | OutStreamer->emitRawComment(" COMPUTE_PGM_RSRC2:USER_SGPR: " + |
Matt Arsenault | 8246d4a | 2015-11-11 00:27:46 +0000 | [diff] [blame] | 203 | Twine(G_00B84C_USER_SGPR(KernelInfo.ComputePGMRSrc2)), |
Matt Arsenault | d41c0db | 2015-11-05 05:27:07 +0000 | [diff] [blame] | 204 | false); |
Matt Arsenault | 8246d4a | 2015-11-11 00:27:46 +0000 | [diff] [blame] | 205 | OutStreamer->emitRawComment(" COMPUTE_PGM_RSRC2:TGID_X_EN: " + |
| 206 | Twine(G_00B84C_TGID_X_EN(KernelInfo.ComputePGMRSrc2)), |
| 207 | false); |
| 208 | OutStreamer->emitRawComment(" COMPUTE_PGM_RSRC2:TGID_Y_EN: " + |
| 209 | Twine(G_00B84C_TGID_Y_EN(KernelInfo.ComputePGMRSrc2)), |
| 210 | false); |
| 211 | OutStreamer->emitRawComment(" COMPUTE_PGM_RSRC2:TGID_Z_EN: " + |
| 212 | Twine(G_00B84C_TGID_Z_EN(KernelInfo.ComputePGMRSrc2)), |
| 213 | false); |
| 214 | OutStreamer->emitRawComment(" COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: " + |
| 215 | Twine(G_00B84C_TIDIG_COMP_CNT(KernelInfo.ComputePGMRSrc2)), |
| 216 | false); |
| 217 | |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 218 | } else { |
| 219 | R600MachineFunctionInfo *MFI = MF.getInfo<R600MachineFunctionInfo>(); |
| 220 | OutStreamer->emitRawComment( |
| 221 | Twine("SQ_PGM_RESOURCES:STACK_SIZE = " + Twine(MFI->StackSize))); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | if (STM.dumpCode()) { |
| 226 | |
| 227 | OutStreamer->SwitchSection( |
| 228 | Context.getELFSection(".AMDGPU.disasm", ELF::SHT_NOTE, 0)); |
| 229 | |
| 230 | for (size_t i = 0; i < DisasmLines.size(); ++i) { |
| 231 | std::string Comment(DisasmLineMaxLen - DisasmLines[i].size(), ' '); |
| 232 | Comment += " ; " + HexLines[i] + "\n"; |
| 233 | |
| 234 | OutStreamer->EmitBytes(StringRef(DisasmLines[i])); |
| 235 | OutStreamer->EmitBytes(StringRef(Comment)); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | return false; |
| 240 | } |
| 241 | |
| 242 | void AMDGPUAsmPrinter::EmitProgramInfoR600(const MachineFunction &MF) { |
| 243 | unsigned MaxGPR = 0; |
| 244 | bool killPixel = false; |
| 245 | const AMDGPUSubtarget &STM = MF.getSubtarget<AMDGPUSubtarget>(); |
| 246 | const R600RegisterInfo *RI = |
| 247 | static_cast<const R600RegisterInfo *>(STM.getRegisterInfo()); |
| 248 | const R600MachineFunctionInfo *MFI = MF.getInfo<R600MachineFunctionInfo>(); |
| 249 | |
| 250 | for (const MachineBasicBlock &MBB : MF) { |
| 251 | for (const MachineInstr &MI : MBB) { |
| 252 | if (MI.getOpcode() == AMDGPU::KILLGT) |
| 253 | killPixel = true; |
| 254 | unsigned numOperands = MI.getNumOperands(); |
| 255 | for (unsigned op_idx = 0; op_idx < numOperands; op_idx++) { |
| 256 | const MachineOperand &MO = MI.getOperand(op_idx); |
| 257 | if (!MO.isReg()) |
| 258 | continue; |
| 259 | unsigned HWReg = RI->getEncodingValue(MO.getReg()) & 0xff; |
| 260 | |
| 261 | // Register with value > 127 aren't GPR |
| 262 | if (HWReg > 127) |
| 263 | continue; |
| 264 | MaxGPR = std::max(MaxGPR, HWReg); |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | unsigned RsrcReg; |
| 270 | if (STM.getGeneration() >= AMDGPUSubtarget::EVERGREEN) { |
| 271 | // Evergreen / Northern Islands |
Nicolai Haehnle | df3a20c | 2016-04-06 19:40:20 +0000 | [diff] [blame] | 272 | switch (MF.getFunction()->getCallingConv()) { |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 273 | default: // Fall through |
Nicolai Haehnle | df3a20c | 2016-04-06 19:40:20 +0000 | [diff] [blame] | 274 | case CallingConv::AMDGPU_CS: RsrcReg = R_0288D4_SQ_PGM_RESOURCES_LS; break; |
| 275 | case CallingConv::AMDGPU_GS: RsrcReg = R_028878_SQ_PGM_RESOURCES_GS; break; |
| 276 | case CallingConv::AMDGPU_PS: RsrcReg = R_028844_SQ_PGM_RESOURCES_PS; break; |
| 277 | case CallingConv::AMDGPU_VS: RsrcReg = R_028860_SQ_PGM_RESOURCES_VS; break; |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 278 | } |
| 279 | } else { |
| 280 | // R600 / R700 |
Nicolai Haehnle | df3a20c | 2016-04-06 19:40:20 +0000 | [diff] [blame] | 281 | switch (MF.getFunction()->getCallingConv()) { |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 282 | default: // Fall through |
Nicolai Haehnle | df3a20c | 2016-04-06 19:40:20 +0000 | [diff] [blame] | 283 | case CallingConv::AMDGPU_GS: // Fall through |
| 284 | case CallingConv::AMDGPU_CS: // Fall through |
| 285 | case CallingConv::AMDGPU_VS: RsrcReg = R_028868_SQ_PGM_RESOURCES_VS; break; |
| 286 | case CallingConv::AMDGPU_PS: RsrcReg = R_028850_SQ_PGM_RESOURCES_PS; break; |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | |
| 290 | OutStreamer->EmitIntValue(RsrcReg, 4); |
| 291 | OutStreamer->EmitIntValue(S_NUM_GPRS(MaxGPR + 1) | |
| 292 | S_STACK_SIZE(MFI->StackSize), 4); |
| 293 | OutStreamer->EmitIntValue(R_02880C_DB_SHADER_CONTROL, 4); |
| 294 | OutStreamer->EmitIntValue(S_02880C_KILL_ENABLE(killPixel), 4); |
| 295 | |
Nicolai Haehnle | df3a20c | 2016-04-06 19:40:20 +0000 | [diff] [blame] | 296 | if (AMDGPU::isCompute(MF.getFunction()->getCallingConv())) { |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 297 | OutStreamer->EmitIntValue(R_0288E8_SQ_LDS_ALLOC, 4); |
Rui Ueyama | da00f2f | 2016-01-14 21:06:47 +0000 | [diff] [blame] | 298 | OutStreamer->EmitIntValue(alignTo(MFI->LDSSize, 4) >> 2, 4); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 299 | } |
| 300 | } |
| 301 | |
| 302 | void AMDGPUAsmPrinter::getSIProgramInfo(SIProgramInfo &ProgInfo, |
| 303 | const MachineFunction &MF) const { |
| 304 | const AMDGPUSubtarget &STM = MF.getSubtarget<AMDGPUSubtarget>(); |
| 305 | const SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>(); |
| 306 | uint64_t CodeSize = 0; |
| 307 | unsigned MaxSGPR = 0; |
| 308 | unsigned MaxVGPR = 0; |
| 309 | bool VCCUsed = false; |
| 310 | bool FlatUsed = false; |
| 311 | const SIRegisterInfo *RI = |
| 312 | static_cast<const SIRegisterInfo *>(STM.getRegisterInfo()); |
Matt Arsenault | a9720c6 | 2016-06-20 17:51:32 +0000 | [diff] [blame^] | 313 | const SIInstrInfo *TII = |
| 314 | static_cast<const SIInstrInfo *>(STM.getInstrInfo()); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 315 | |
| 316 | for (const MachineBasicBlock &MBB : MF) { |
| 317 | for (const MachineInstr &MI : MBB) { |
| 318 | // TODO: CodeSize should account for multiple functions. |
Matt Arsenault | c574686 | 2015-08-12 09:04:44 +0000 | [diff] [blame] | 319 | |
| 320 | // TODO: Should we count size of debug info? |
| 321 | if (MI.isDebugValue()) |
| 322 | continue; |
| 323 | |
Matt Arsenault | a9720c6 | 2016-06-20 17:51:32 +0000 | [diff] [blame^] | 324 | CodeSize += TII->getInstSizeInBytes(MI); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 325 | |
| 326 | unsigned numOperands = MI.getNumOperands(); |
| 327 | for (unsigned op_idx = 0; op_idx < numOperands; op_idx++) { |
| 328 | const MachineOperand &MO = MI.getOperand(op_idx); |
| 329 | unsigned width = 0; |
| 330 | bool isSGPR = false; |
| 331 | |
Matt Arsenault | d2c7589 | 2015-10-01 21:51:59 +0000 | [diff] [blame] | 332 | if (!MO.isReg()) |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 333 | continue; |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 334 | |
Matt Arsenault | d2c7589 | 2015-10-01 21:51:59 +0000 | [diff] [blame] | 335 | unsigned reg = MO.getReg(); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 336 | switch (reg) { |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 337 | case AMDGPU::EXEC: |
Nicolai Haehnle | 7483937 | 2016-04-19 21:58:17 +0000 | [diff] [blame] | 338 | case AMDGPU::EXEC_LO: |
| 339 | case AMDGPU::EXEC_HI: |
Matt Arsenault | d2c7589 | 2015-10-01 21:51:59 +0000 | [diff] [blame] | 340 | case AMDGPU::SCC: |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 341 | case AMDGPU::M0: |
| 342 | continue; |
Matt Arsenault | d2c7589 | 2015-10-01 21:51:59 +0000 | [diff] [blame] | 343 | |
| 344 | case AMDGPU::VCC: |
| 345 | case AMDGPU::VCC_LO: |
| 346 | case AMDGPU::VCC_HI: |
| 347 | VCCUsed = true; |
| 348 | continue; |
| 349 | |
| 350 | case AMDGPU::FLAT_SCR: |
| 351 | case AMDGPU::FLAT_SCR_LO: |
| 352 | case AMDGPU::FLAT_SCR_HI: |
| 353 | FlatUsed = true; |
| 354 | continue; |
| 355 | |
Artem Tamazov | eb4d5a9 | 2016-04-13 16:18:41 +0000 | [diff] [blame] | 356 | case AMDGPU::TBA: |
| 357 | case AMDGPU::TBA_LO: |
| 358 | case AMDGPU::TBA_HI: |
| 359 | case AMDGPU::TMA: |
| 360 | case AMDGPU::TMA_LO: |
| 361 | case AMDGPU::TMA_HI: |
| 362 | llvm_unreachable("Trap Handler registers should not be used"); |
| 363 | continue; |
| 364 | |
Matt Arsenault | d2c7589 | 2015-10-01 21:51:59 +0000 | [diff] [blame] | 365 | default: |
| 366 | break; |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | if (AMDGPU::SReg_32RegClass.contains(reg)) { |
Artem Tamazov | eb4d5a9 | 2016-04-13 16:18:41 +0000 | [diff] [blame] | 370 | if (AMDGPU::TTMP_32RegClass.contains(reg)) { |
| 371 | llvm_unreachable("Trap Handler registers should not be used"); |
| 372 | } |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 373 | isSGPR = true; |
| 374 | width = 1; |
| 375 | } else if (AMDGPU::VGPR_32RegClass.contains(reg)) { |
| 376 | isSGPR = false; |
| 377 | width = 1; |
| 378 | } else if (AMDGPU::SReg_64RegClass.contains(reg)) { |
Artem Tamazov | eb4d5a9 | 2016-04-13 16:18:41 +0000 | [diff] [blame] | 379 | if (AMDGPU::TTMP_64RegClass.contains(reg)) { |
| 380 | llvm_unreachable("Trap Handler registers should not be used"); |
| 381 | } |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 382 | isSGPR = true; |
| 383 | width = 2; |
| 384 | } else if (AMDGPU::VReg_64RegClass.contains(reg)) { |
| 385 | isSGPR = false; |
| 386 | width = 2; |
| 387 | } else if (AMDGPU::VReg_96RegClass.contains(reg)) { |
| 388 | isSGPR = false; |
| 389 | width = 3; |
| 390 | } else if (AMDGPU::SReg_128RegClass.contains(reg)) { |
| 391 | isSGPR = true; |
| 392 | width = 4; |
| 393 | } else if (AMDGPU::VReg_128RegClass.contains(reg)) { |
| 394 | isSGPR = false; |
| 395 | width = 4; |
| 396 | } else if (AMDGPU::SReg_256RegClass.contains(reg)) { |
| 397 | isSGPR = true; |
| 398 | width = 8; |
| 399 | } else if (AMDGPU::VReg_256RegClass.contains(reg)) { |
| 400 | isSGPR = false; |
| 401 | width = 8; |
| 402 | } else if (AMDGPU::SReg_512RegClass.contains(reg)) { |
| 403 | isSGPR = true; |
| 404 | width = 16; |
| 405 | } else if (AMDGPU::VReg_512RegClass.contains(reg)) { |
| 406 | isSGPR = false; |
| 407 | width = 16; |
| 408 | } else { |
| 409 | llvm_unreachable("Unknown register class"); |
| 410 | } |
| 411 | unsigned hwReg = RI->getEncodingValue(reg) & 0xff; |
| 412 | unsigned maxUsed = hwReg + width - 1; |
| 413 | if (isSGPR) { |
| 414 | MaxSGPR = maxUsed > MaxSGPR ? maxUsed : MaxSGPR; |
| 415 | } else { |
| 416 | MaxVGPR = maxUsed > MaxVGPR ? maxUsed : MaxVGPR; |
| 417 | } |
| 418 | } |
| 419 | } |
| 420 | } |
| 421 | |
Nicolai Haehnle | 3c05d6d | 2016-01-07 17:10:20 +0000 | [diff] [blame] | 422 | unsigned ExtraSGPRs = 0; |
| 423 | |
| 424 | if (VCCUsed) |
| 425 | ExtraSGPRs = 2; |
| 426 | |
| 427 | if (STM.getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS) { |
| 428 | if (FlatUsed) |
| 429 | ExtraSGPRs = 4; |
| 430 | } else { |
| 431 | if (STM.isXNACKEnabled()) |
| 432 | ExtraSGPRs = 4; |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 433 | |
Nicolai Haehnle | 5b50497 | 2016-01-04 23:35:53 +0000 | [diff] [blame] | 434 | if (FlatUsed) |
Nicolai Haehnle | 3c05d6d | 2016-01-07 17:10:20 +0000 | [diff] [blame] | 435 | ExtraSGPRs = 6; |
Tom Stellard | caaa3aa | 2015-12-17 17:05:09 +0000 | [diff] [blame] | 436 | } |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 437 | |
Nicolai Haehnle | 3c05d6d | 2016-01-07 17:10:20 +0000 | [diff] [blame] | 438 | MaxSGPR += ExtraSGPRs; |
| 439 | |
Konstantin Zhuravlyov | 29ddd2b | 2016-05-24 18:37:18 +0000 | [diff] [blame] | 440 | // Record first reserved register and reserved register count fields, and |
| 441 | // update max register counts if "amdgpu-debugger-reserve-regs" attribute was |
| 442 | // specified. |
| 443 | if (STM.debuggerReserveRegs()) { |
Konstantin Zhuravlyov | 1d99c4d | 2016-04-26 15:43:14 +0000 | [diff] [blame] | 444 | ProgInfo.ReservedVGPRFirst = MaxVGPR + 1; |
Konstantin Zhuravlyov | 29ddd2b | 2016-05-24 18:37:18 +0000 | [diff] [blame] | 445 | ProgInfo.ReservedVGPRCount = MFI->getDebuggerReservedVGPRCount(); |
| 446 | MaxVGPR += MFI->getDebuggerReservedVGPRCount(); |
Konstantin Zhuravlyov | 1d99c4d | 2016-04-26 15:43:14 +0000 | [diff] [blame] | 447 | } |
| 448 | |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 449 | // We found the maximum register index. They start at 0, so add one to get the |
| 450 | // number of registers. |
| 451 | ProgInfo.NumVGPR = MaxVGPR + 1; |
| 452 | ProgInfo.NumSGPR = MaxSGPR + 1; |
| 453 | |
| 454 | if (STM.hasSGPRInitBug()) { |
Matt Arsenault | 417c93e | 2015-06-17 20:55:25 +0000 | [diff] [blame] | 455 | if (ProgInfo.NumSGPR > AMDGPUSubtarget::FIXED_SGPR_COUNT_FOR_INIT_BUG) { |
| 456 | LLVMContext &Ctx = MF.getFunction()->getContext(); |
| 457 | Ctx.emitError("too many SGPRs used with the SGPR init bug"); |
| 458 | } |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 459 | |
| 460 | ProgInfo.NumSGPR = AMDGPUSubtarget::FIXED_SGPR_COUNT_FOR_INIT_BUG; |
| 461 | } |
| 462 | |
Matt Arsenault | 41003af | 2015-11-30 21:16:07 +0000 | [diff] [blame] | 463 | if (MFI->NumUserSGPRs > STM.getMaxNumUserSGPRs()) { |
| 464 | LLVMContext &Ctx = MF.getFunction()->getContext(); |
| 465 | Ctx.emitError("too many user SGPRs used"); |
| 466 | } |
| 467 | |
Matt Arsenault | 1c4d0ef | 2016-04-28 19:37:35 +0000 | [diff] [blame] | 468 | if (MFI->LDSSize > static_cast<unsigned>(STM.getLocalMemorySize())) { |
| 469 | LLVMContext &Ctx = MF.getFunction()->getContext(); |
| 470 | Ctx.emitError("LDS size exceeds device maximum"); |
| 471 | } |
| 472 | |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 473 | ProgInfo.VGPRBlocks = (ProgInfo.NumVGPR - 1) / 4; |
| 474 | ProgInfo.SGPRBlocks = (ProgInfo.NumSGPR - 1) / 8; |
| 475 | // Set the value to initialize FP_ROUND and FP_DENORM parts of the mode |
| 476 | // register. |
| 477 | ProgInfo.FloatMode = getFPMode(MF); |
| 478 | |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 479 | ProgInfo.IEEEMode = 0; |
| 480 | |
Matt Arsenault | 7293f98 | 2016-01-28 20:53:35 +0000 | [diff] [blame] | 481 | // Make clamp modifier on NaN input returns 0. |
| 482 | ProgInfo.DX10Clamp = 1; |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 483 | |
| 484 | const MachineFrameInfo *FrameInfo = MF.getFrameInfo(); |
Matt Arsenault | f4dfc1a | 2016-03-01 04:58:20 +0000 | [diff] [blame] | 485 | ProgInfo.ScratchSize = FrameInfo->getStackSize(); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 486 | |
| 487 | ProgInfo.FlatUsed = FlatUsed; |
| 488 | ProgInfo.VCCUsed = VCCUsed; |
| 489 | ProgInfo.CodeLen = CodeSize; |
| 490 | |
| 491 | unsigned LDSAlignShift; |
| 492 | if (STM.getGeneration() < AMDGPUSubtarget::SEA_ISLANDS) { |
| 493 | // LDS is allocated in 64 dword blocks. |
| 494 | LDSAlignShift = 8; |
| 495 | } else { |
| 496 | // LDS is allocated in 128 dword blocks. |
| 497 | LDSAlignShift = 9; |
| 498 | } |
| 499 | |
| 500 | unsigned LDSSpillSize = MFI->LDSWaveSpillSize * |
| 501 | MFI->getMaximumWorkGroupSize(MF); |
| 502 | |
| 503 | ProgInfo.LDSSize = MFI->LDSSize + LDSSpillSize; |
| 504 | ProgInfo.LDSBlocks = |
Aaron Ballman | ef0fe1e | 2016-03-30 21:30:00 +0000 | [diff] [blame] | 505 | alignTo(ProgInfo.LDSSize, 1ULL << LDSAlignShift) >> LDSAlignShift; |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 506 | |
| 507 | // Scratch is allocated in 256 dword blocks. |
| 508 | unsigned ScratchAlignShift = 10; |
| 509 | // We need to program the hardware with the amount of scratch memory that |
| 510 | // is used by the entire wave. ProgInfo.ScratchSize is the amount of |
| 511 | // scratch memory used per thread. |
| 512 | ProgInfo.ScratchBlocks = |
Rui Ueyama | da00f2f | 2016-01-14 21:06:47 +0000 | [diff] [blame] | 513 | alignTo(ProgInfo.ScratchSize * STM.getWavefrontSize(), |
Aaron Ballman | ef0fe1e | 2016-03-30 21:30:00 +0000 | [diff] [blame] | 514 | 1ULL << ScratchAlignShift) >> |
Rui Ueyama | da00f2f | 2016-01-14 21:06:47 +0000 | [diff] [blame] | 515 | ScratchAlignShift; |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 516 | |
| 517 | ProgInfo.ComputePGMRSrc1 = |
| 518 | S_00B848_VGPRS(ProgInfo.VGPRBlocks) | |
| 519 | S_00B848_SGPRS(ProgInfo.SGPRBlocks) | |
| 520 | S_00B848_PRIORITY(ProgInfo.Priority) | |
| 521 | S_00B848_FLOAT_MODE(ProgInfo.FloatMode) | |
| 522 | S_00B848_PRIV(ProgInfo.Priv) | |
| 523 | S_00B848_DX10_CLAMP(ProgInfo.DX10Clamp) | |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 524 | S_00B848_DEBUG_MODE(ProgInfo.DebugMode) | |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 525 | S_00B848_IEEE_MODE(ProgInfo.IEEEMode); |
| 526 | |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 527 | // 0 = X, 1 = XY, 2 = XYZ |
| 528 | unsigned TIDIGCompCnt = 0; |
| 529 | if (MFI->hasWorkItemIDZ()) |
| 530 | TIDIGCompCnt = 2; |
| 531 | else if (MFI->hasWorkItemIDY()) |
| 532 | TIDIGCompCnt = 1; |
| 533 | |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 534 | ProgInfo.ComputePGMRSrc2 = |
| 535 | S_00B84C_SCRATCH_EN(ProgInfo.ScratchBlocks > 0) | |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 536 | S_00B84C_USER_SGPR(MFI->getNumUserSGPRs()) | |
| 537 | S_00B84C_TGID_X_EN(MFI->hasWorkGroupIDX()) | |
| 538 | S_00B84C_TGID_Y_EN(MFI->hasWorkGroupIDY()) | |
| 539 | S_00B84C_TGID_Z_EN(MFI->hasWorkGroupIDZ()) | |
| 540 | S_00B84C_TG_SIZE_EN(MFI->hasWorkGroupInfo()) | |
| 541 | S_00B84C_TIDIG_COMP_CNT(TIDIGCompCnt) | |
| 542 | S_00B84C_EXCP_EN_MSB(0) | |
| 543 | S_00B84C_LDS_SIZE(ProgInfo.LDSBlocks) | |
| 544 | S_00B84C_EXCP_EN(0); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 545 | } |
| 546 | |
Nicolai Haehnle | df3a20c | 2016-04-06 19:40:20 +0000 | [diff] [blame] | 547 | static unsigned getRsrcReg(CallingConv::ID CallConv) { |
| 548 | switch (CallConv) { |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 549 | default: // Fall through |
Nicolai Haehnle | df3a20c | 2016-04-06 19:40:20 +0000 | [diff] [blame] | 550 | case CallingConv::AMDGPU_CS: return R_00B848_COMPUTE_PGM_RSRC1; |
| 551 | case CallingConv::AMDGPU_GS: return R_00B228_SPI_SHADER_PGM_RSRC1_GS; |
| 552 | case CallingConv::AMDGPU_PS: return R_00B028_SPI_SHADER_PGM_RSRC1_PS; |
| 553 | case CallingConv::AMDGPU_VS: return R_00B128_SPI_SHADER_PGM_RSRC1_VS; |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 554 | } |
| 555 | } |
| 556 | |
| 557 | void AMDGPUAsmPrinter::EmitProgramInfoSI(const MachineFunction &MF, |
| 558 | const SIProgramInfo &KernelInfo) { |
| 559 | const AMDGPUSubtarget &STM = MF.getSubtarget<AMDGPUSubtarget>(); |
| 560 | const SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>(); |
Nicolai Haehnle | df3a20c | 2016-04-06 19:40:20 +0000 | [diff] [blame] | 561 | unsigned RsrcReg = getRsrcReg(MF.getFunction()->getCallingConv()); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 562 | |
Nicolai Haehnle | df3a20c | 2016-04-06 19:40:20 +0000 | [diff] [blame] | 563 | if (AMDGPU::isCompute(MF.getFunction()->getCallingConv())) { |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 564 | OutStreamer->EmitIntValue(R_00B848_COMPUTE_PGM_RSRC1, 4); |
| 565 | |
| 566 | OutStreamer->EmitIntValue(KernelInfo.ComputePGMRSrc1, 4); |
| 567 | |
| 568 | OutStreamer->EmitIntValue(R_00B84C_COMPUTE_PGM_RSRC2, 4); |
| 569 | OutStreamer->EmitIntValue(KernelInfo.ComputePGMRSrc2, 4); |
| 570 | |
| 571 | OutStreamer->EmitIntValue(R_00B860_COMPUTE_TMPRING_SIZE, 4); |
| 572 | OutStreamer->EmitIntValue(S_00B860_WAVESIZE(KernelInfo.ScratchBlocks), 4); |
| 573 | |
| 574 | // TODO: Should probably note flat usage somewhere. SC emits a "FlatPtr32 = |
| 575 | // 0" comment but I don't see a corresponding field in the register spec. |
| 576 | } else { |
| 577 | OutStreamer->EmitIntValue(RsrcReg, 4); |
| 578 | OutStreamer->EmitIntValue(S_00B028_VGPRS(KernelInfo.VGPRBlocks) | |
| 579 | S_00B028_SGPRS(KernelInfo.SGPRBlocks), 4); |
Nicolai Haehnle | df3a20c | 2016-04-06 19:40:20 +0000 | [diff] [blame] | 580 | if (STM.isVGPRSpillingEnabled(*MF.getFunction())) { |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 581 | OutStreamer->EmitIntValue(R_0286E8_SPI_TMPRING_SIZE, 4); |
| 582 | OutStreamer->EmitIntValue(S_0286E8_WAVESIZE(KernelInfo.ScratchBlocks), 4); |
| 583 | } |
| 584 | } |
| 585 | |
Nicolai Haehnle | df3a20c | 2016-04-06 19:40:20 +0000 | [diff] [blame] | 586 | if (MF.getFunction()->getCallingConv() == CallingConv::AMDGPU_PS) { |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 587 | OutStreamer->EmitIntValue(R_00B02C_SPI_SHADER_PGM_RSRC2_PS, 4); |
| 588 | OutStreamer->EmitIntValue(S_00B02C_EXTRA_LDS_SIZE(KernelInfo.LDSBlocks), 4); |
| 589 | OutStreamer->EmitIntValue(R_0286CC_SPI_PS_INPUT_ENA, 4); |
Marek Olsak | fccabaf | 2016-01-13 11:45:36 +0000 | [diff] [blame] | 590 | OutStreamer->EmitIntValue(MFI->PSInputEna, 4); |
| 591 | OutStreamer->EmitIntValue(R_0286D0_SPI_PS_INPUT_ADDR, 4); |
| 592 | OutStreamer->EmitIntValue(MFI->getPSInputAddr(), 4); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 593 | } |
| 594 | } |
| 595 | |
Matt Arsenault | 24ee078 | 2016-02-12 02:40:47 +0000 | [diff] [blame] | 596 | // This is supposed to be log2(Size) |
| 597 | static amd_element_byte_size_t getElementByteSizeValue(unsigned Size) { |
| 598 | switch (Size) { |
| 599 | case 4: |
| 600 | return AMD_ELEMENT_4_BYTES; |
| 601 | case 8: |
| 602 | return AMD_ELEMENT_8_BYTES; |
| 603 | case 16: |
| 604 | return AMD_ELEMENT_16_BYTES; |
| 605 | default: |
| 606 | llvm_unreachable("invalid private_element_size"); |
| 607 | } |
| 608 | } |
| 609 | |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 610 | void AMDGPUAsmPrinter::EmitAmdKernelCodeT(const MachineFunction &MF, |
Tom Stellard | ff7416b | 2015-06-26 21:58:31 +0000 | [diff] [blame] | 611 | const SIProgramInfo &KernelInfo) const { |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 612 | const SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>(); |
| 613 | const AMDGPUSubtarget &STM = MF.getSubtarget<AMDGPUSubtarget>(); |
| 614 | amd_kernel_code_t header; |
| 615 | |
Tom Stellard | ff7416b | 2015-06-26 21:58:31 +0000 | [diff] [blame] | 616 | AMDGPU::initDefaultAMDKernelCodeT(header, STM.getFeatureBits()); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 617 | |
| 618 | header.compute_pgm_resource_registers = |
| 619 | KernelInfo.ComputePGMRSrc1 | |
| 620 | (KernelInfo.ComputePGMRSrc2 << 32); |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 621 | header.code_properties = AMD_CODE_PROPERTY_IS_PTR64; |
| 622 | |
Matt Arsenault | 24ee078 | 2016-02-12 02:40:47 +0000 | [diff] [blame] | 623 | |
| 624 | AMD_HSA_BITS_SET(header.code_properties, |
| 625 | AMD_CODE_PROPERTY_PRIVATE_ELEMENT_SIZE, |
| 626 | getElementByteSizeValue(STM.getMaxPrivateElementSize())); |
| 627 | |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 628 | if (MFI->hasPrivateSegmentBuffer()) { |
| 629 | header.code_properties |= |
| 630 | AMD_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_BUFFER; |
| 631 | } |
| 632 | |
| 633 | if (MFI->hasDispatchPtr()) |
| 634 | header.code_properties |= AMD_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_PTR; |
| 635 | |
| 636 | if (MFI->hasQueuePtr()) |
| 637 | header.code_properties |= AMD_CODE_PROPERTY_ENABLE_SGPR_QUEUE_PTR; |
| 638 | |
| 639 | if (MFI->hasKernargSegmentPtr()) |
| 640 | header.code_properties |= AMD_CODE_PROPERTY_ENABLE_SGPR_KERNARG_SEGMENT_PTR; |
| 641 | |
| 642 | if (MFI->hasDispatchID()) |
| 643 | header.code_properties |= AMD_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_ID; |
| 644 | |
| 645 | if (MFI->hasFlatScratchInit()) |
| 646 | header.code_properties |= AMD_CODE_PROPERTY_ENABLE_SGPR_FLAT_SCRATCH_INIT; |
| 647 | |
| 648 | // TODO: Private segment size |
| 649 | |
| 650 | if (MFI->hasGridWorkgroupCountX()) { |
| 651 | header.code_properties |= |
| 652 | AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_X; |
| 653 | } |
| 654 | |
| 655 | if (MFI->hasGridWorkgroupCountY()) { |
| 656 | header.code_properties |= |
| 657 | AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_Y; |
| 658 | } |
| 659 | |
| 660 | if (MFI->hasGridWorkgroupCountZ()) { |
| 661 | header.code_properties |= |
| 662 | AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_Z; |
| 663 | } |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 664 | |
Tom Stellard | 48f29f2 | 2015-11-26 00:43:29 +0000 | [diff] [blame] | 665 | if (MFI->hasDispatchPtr()) |
| 666 | header.code_properties |= AMD_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_PTR; |
| 667 | |
Nicolai Haehnle | 5b50497 | 2016-01-04 23:35:53 +0000 | [diff] [blame] | 668 | if (STM.isXNACKEnabled()) |
| 669 | header.code_properties |= AMD_CODE_PROPERTY_IS_XNACK_SUPPORTED; |
| 670 | |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 671 | header.kernarg_segment_byte_size = MFI->ABIArgOffset; |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 672 | header.wavefront_sgpr_count = KernelInfo.NumSGPR; |
| 673 | header.workitem_vgpr_count = KernelInfo.NumVGPR; |
Tom Stellard | a495307 | 2015-12-15 22:55:30 +0000 | [diff] [blame] | 674 | header.workitem_private_segment_byte_size = KernelInfo.ScratchSize; |
Tom Stellard | 7750f4e | 2015-12-15 23:15:25 +0000 | [diff] [blame] | 675 | header.workgroup_group_segment_byte_size = KernelInfo.LDSSize; |
Konstantin Zhuravlyov | 1d99c4d | 2016-04-26 15:43:14 +0000 | [diff] [blame] | 676 | header.reserved_vgpr_first = KernelInfo.ReservedVGPRFirst; |
| 677 | header.reserved_vgpr_count = KernelInfo.ReservedVGPRCount; |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 678 | |
Tom Stellard | ff7416b | 2015-06-26 21:58:31 +0000 | [diff] [blame] | 679 | AMDGPUTargetStreamer *TS = |
| 680 | static_cast<AMDGPUTargetStreamer *>(OutStreamer->getTargetStreamer()); |
Tom Stellard | fcfaea4 | 2016-05-05 17:03:33 +0000 | [diff] [blame] | 681 | |
| 682 | OutStreamer->SwitchSection(getObjFileLowering().getTextSection()); |
Tom Stellard | ff7416b | 2015-06-26 21:58:31 +0000 | [diff] [blame] | 683 | TS->EmitAMDKernelCodeT(header); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | bool AMDGPUAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, |
| 687 | unsigned AsmVariant, |
| 688 | const char *ExtraCode, raw_ostream &O) { |
| 689 | if (ExtraCode && ExtraCode[0]) { |
| 690 | if (ExtraCode[1] != 0) |
| 691 | return true; // Unknown modifier. |
| 692 | |
| 693 | switch (ExtraCode[0]) { |
| 694 | default: |
| 695 | // See if this is a generic print operand |
| 696 | return AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, O); |
| 697 | case 'r': |
| 698 | break; |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | AMDGPUInstPrinter::printRegOperand(MI->getOperand(OpNo).getReg(), O, |
| 703 | *TM.getSubtargetImpl(*MF->getFunction())->getRegisterInfo()); |
| 704 | return false; |
| 705 | } |