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" |
Matt Arsenault | ff98241 | 2016-06-20 18:13:04 +0000 | [diff] [blame] | 34 | #include "llvm/IR/DiagnosticInfo.h" |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 35 | #include "llvm/MC/MCContext.h" |
| 36 | #include "llvm/MC/MCSectionELF.h" |
| 37 | #include "llvm/MC/MCStreamer.h" |
| 38 | #include "llvm/Support/ELF.h" |
| 39 | #include "llvm/Support/MathExtras.h" |
| 40 | #include "llvm/Support/TargetRegistry.h" |
| 41 | #include "llvm/Target/TargetLoweringObjectFile.h" |
| 42 | |
| 43 | using namespace llvm; |
| 44 | |
| 45 | // TODO: This should get the default rounding mode from the kernel. We just set |
| 46 | // the default here, but this could change if the OpenCL rounding mode pragmas |
| 47 | // are used. |
| 48 | // |
| 49 | // The denormal mode here should match what is reported by the OpenCL runtime |
| 50 | // for the CL_FP_DENORM bit from CL_DEVICE_{HALF|SINGLE|DOUBLE}_FP_CONFIG, but |
| 51 | // can also be override to flush with the -cl-denorms-are-zero compiler flag. |
| 52 | // |
| 53 | // AMD OpenCL only sets flush none and reports CL_FP_DENORM for double |
| 54 | // precision, and leaves single precision to flush all and does not report |
| 55 | // CL_FP_DENORM for CL_DEVICE_SINGLE_FP_CONFIG. Mesa's OpenCL currently reports |
| 56 | // CL_FP_DENORM for both. |
| 57 | // |
| 58 | // FIXME: It seems some instructions do not support single precision denormals |
| 59 | // regardless of the mode (exp_*_f32, rcp_*_f32, rsq_*_f32, rsq_*f32, sqrt_f32, |
| 60 | // and sin_f32, cos_f32 on most parts). |
| 61 | |
| 62 | // We want to use these instructions, and using fp32 denormals also causes |
| 63 | // instructions to run at the double precision rate for the device so it's |
| 64 | // probably best to just report no single precision denormals. |
| 65 | static uint32_t getFPMode(const MachineFunction &F) { |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 66 | const SISubtarget& ST = F.getSubtarget<SISubtarget>(); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 67 | // TODO: Is there any real use for the flush in only / flush out only modes? |
| 68 | |
| 69 | uint32_t FP32Denormals = |
| 70 | ST.hasFP32Denormals() ? FP_DENORM_FLUSH_NONE : FP_DENORM_FLUSH_IN_FLUSH_OUT; |
| 71 | |
| 72 | uint32_t FP64Denormals = |
| 73 | ST.hasFP64Denormals() ? FP_DENORM_FLUSH_NONE : FP_DENORM_FLUSH_IN_FLUSH_OUT; |
| 74 | |
| 75 | return FP_ROUND_MODE_SP(FP_ROUND_ROUND_TO_NEAREST) | |
| 76 | FP_ROUND_MODE_DP(FP_ROUND_ROUND_TO_NEAREST) | |
| 77 | FP_DENORM_MODE_SP(FP32Denormals) | |
| 78 | FP_DENORM_MODE_DP(FP64Denormals); |
| 79 | } |
| 80 | |
| 81 | static AsmPrinter * |
| 82 | createAMDGPUAsmPrinterPass(TargetMachine &tm, |
| 83 | std::unique_ptr<MCStreamer> &&Streamer) { |
| 84 | return new AMDGPUAsmPrinter(tm, std::move(Streamer)); |
| 85 | } |
| 86 | |
| 87 | extern "C" void LLVMInitializeAMDGPUAsmPrinter() { |
Mehdi Amini | f42454b | 2016-10-09 23:00:34 +0000 | [diff] [blame] | 88 | TargetRegistry::RegisterAsmPrinter(getTheAMDGPUTarget(), |
| 89 | createAMDGPUAsmPrinterPass); |
| 90 | TargetRegistry::RegisterAsmPrinter(getTheGCNTarget(), |
| 91 | createAMDGPUAsmPrinterPass); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | AMDGPUAsmPrinter::AMDGPUAsmPrinter(TargetMachine &TM, |
| 95 | std::unique_ptr<MCStreamer> Streamer) |
Matt Arsenault | 11f7402 | 2016-10-06 17:19:11 +0000 | [diff] [blame] | 96 | : AsmPrinter(TM, std::move(Streamer)) {} |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 97 | |
Mehdi Amini | 117296c | 2016-10-01 02:56:57 +0000 | [diff] [blame] | 98 | StringRef AMDGPUAsmPrinter::getPassName() const { |
Matt Arsenault | f9245b7 | 2016-07-22 17:01:25 +0000 | [diff] [blame] | 99 | return "AMDGPU Assembly Printer"; |
| 100 | } |
| 101 | |
Konstantin Zhuravlyov | 7498cd6 | 2017-03-22 22:32:22 +0000 | [diff] [blame] | 102 | const MCSubtargetInfo* AMDGPUAsmPrinter::getSTI() const { |
| 103 | return TM.getMCSubtargetInfo(); |
| 104 | } |
| 105 | |
| 106 | AMDGPUTargetStreamer& AMDGPUAsmPrinter::getTargetStreamer() const { |
| 107 | return static_cast<AMDGPUTargetStreamer&>(*OutStreamer->getTargetStreamer()); |
| 108 | } |
| 109 | |
Tom Stellard | f421837 | 2016-01-12 17:18:17 +0000 | [diff] [blame] | 110 | void AMDGPUAsmPrinter::EmitStartOfAsmFile(Module &M) { |
| 111 | if (TM.getTargetTriple().getOS() != Triple::AMDHSA) |
| 112 | return; |
| 113 | |
Konstantin Zhuravlyov | 9f89ede | 2017-02-08 14:05:23 +0000 | [diff] [blame] | 114 | AMDGPU::IsaInfo::IsaVersion ISA = |
Konstantin Zhuravlyov | 7498cd6 | 2017-03-22 22:32:22 +0000 | [diff] [blame] | 115 | AMDGPU::IsaInfo::getIsaVersion(getSTI()->getFeatureBits()); |
Yaxun Liu | d6fbe65 | 2016-11-10 21:18:49 +0000 | [diff] [blame] | 116 | |
Konstantin Zhuravlyov | 7498cd6 | 2017-03-22 22:32:22 +0000 | [diff] [blame] | 117 | getTargetStreamer().EmitDirectiveHSACodeObjectVersion(2, 1); |
| 118 | getTargetStreamer().EmitDirectiveHSACodeObjectISA( |
| 119 | ISA.Major, ISA.Minor, ISA.Stepping, "AMD", "AMDGPU"); |
| 120 | getTargetStreamer().EmitStartOfCodeObjectMetadata( |
| 121 | getSTI()->getFeatureBits(), M); |
| 122 | } |
| 123 | |
| 124 | void AMDGPUAsmPrinter::EmitEndOfAsmFile(Module &M) { |
| 125 | if (TM.getTargetTriple().getOS() != Triple::AMDHSA) |
| 126 | return; |
| 127 | |
| 128 | getTargetStreamer().EmitEndOfCodeObjectMetadata(getSTI()->getFeatureBits()); |
Tom Stellard | f421837 | 2016-01-12 17:18:17 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Matt Arsenault | 6bc43d8 | 2016-10-06 16:20:41 +0000 | [diff] [blame] | 131 | bool AMDGPUAsmPrinter::isBlockOnlyReachableByFallthrough( |
| 132 | const MachineBasicBlock *MBB) const { |
| 133 | if (!AsmPrinter::isBlockOnlyReachableByFallthrough(MBB)) |
| 134 | return false; |
| 135 | |
| 136 | if (MBB->empty()) |
| 137 | return true; |
| 138 | |
| 139 | // If this is a block implementing a long branch, an expression relative to |
| 140 | // the start of the block is needed. to the start of the block. |
| 141 | // XXX - Is there a smarter way to check this? |
| 142 | return (MBB->back().getOpcode() != AMDGPU::S_SETPC_B64); |
| 143 | } |
| 144 | |
Tom Stellard | f151a45 | 2015-06-26 21:14:58 +0000 | [diff] [blame] | 145 | void AMDGPUAsmPrinter::EmitFunctionBodyStart() { |
| 146 | const AMDGPUSubtarget &STM = MF->getSubtarget<AMDGPUSubtarget>(); |
| 147 | SIProgramInfo KernelInfo; |
Tom Stellard | 2f3f985 | 2017-01-25 01:25:13 +0000 | [diff] [blame] | 148 | if (STM.isAmdCodeObjectV2(*MF)) { |
Tom Stellard | f151a45 | 2015-06-26 21:14:58 +0000 | [diff] [blame] | 149 | getSIProgramInfo(KernelInfo, *MF); |
| 150 | EmitAmdKernelCodeT(*MF, KernelInfo); |
| 151 | } |
Konstantin Zhuravlyov | 7498cd6 | 2017-03-22 22:32:22 +0000 | [diff] [blame] | 152 | |
| 153 | if (TM.getTargetTriple().getOS() != Triple::AMDHSA) |
| 154 | return; |
| 155 | getTargetStreamer().EmitKernelCodeObjectMetadata(*MF->getFunction()); |
Tom Stellard | f151a45 | 2015-06-26 21:14:58 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Tom Stellard | 1e1b05d | 2015-11-06 11:45:14 +0000 | [diff] [blame] | 158 | void AMDGPUAsmPrinter::EmitFunctionEntryLabel() { |
| 159 | const SIMachineFunctionInfo *MFI = MF->getInfo<SIMachineFunctionInfo>(); |
| 160 | const AMDGPUSubtarget &STM = MF->getSubtarget<AMDGPUSubtarget>(); |
Tom Stellard | 2f3f985 | 2017-01-25 01:25:13 +0000 | [diff] [blame] | 161 | if (MFI->isKernel() && STM.isAmdCodeObjectV2(*MF)) { |
Tom Stellard | 1b9748c | 2016-09-26 17:29:25 +0000 | [diff] [blame] | 162 | SmallString<128> SymbolName; |
| 163 | getNameWithPrefix(SymbolName, MF->getFunction()), |
Konstantin Zhuravlyov | 7498cd6 | 2017-03-22 22:32:22 +0000 | [diff] [blame] | 164 | getTargetStreamer().EmitAMDGPUSymbolType( |
| 165 | SymbolName, ELF::STT_AMDGPU_HSA_KERNEL); |
Tom Stellard | 1e1b05d | 2015-11-06 11:45:14 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | AsmPrinter::EmitFunctionEntryLabel(); |
| 169 | } |
| 170 | |
Tom Stellard | e3b5aea | 2015-12-02 17:00:42 +0000 | [diff] [blame] | 171 | void AMDGPUAsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) { |
| 172 | |
Tom Stellard | 00f2f91 | 2015-12-02 19:47:57 +0000 | [diff] [blame] | 173 | // Group segment variables aren't emitted in HSA. |
| 174 | if (AMDGPU::isGroupSegment(GV)) |
| 175 | return; |
| 176 | |
Tom Stellard | fcfaea4 | 2016-05-05 17:03:33 +0000 | [diff] [blame] | 177 | AsmPrinter::EmitGlobalVariable(GV); |
Tom Stellard | e3b5aea | 2015-12-02 17:00:42 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 180 | bool AMDGPUAsmPrinter::runOnMachineFunction(MachineFunction &MF) { |
| 181 | |
| 182 | // The starting address of all shader programs must be 256 bytes aligned. |
| 183 | MF.setAlignment(8); |
| 184 | |
| 185 | SetupMachineFunction(MF); |
| 186 | |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 187 | const AMDGPUSubtarget &STM = MF.getSubtarget<AMDGPUSubtarget>(); |
Konstantin Zhuravlyov | 67a6d54 | 2017-01-06 17:02:10 +0000 | [diff] [blame] | 188 | MCContext &Context = getObjFileLowering().getContext(); |
| 189 | if (!STM.isAmdHsaOS()) { |
| 190 | MCSectionELF *ConfigSection = |
| 191 | Context.getELFSection(".AMDGPU.config", ELF::SHT_PROGBITS, 0); |
| 192 | OutStreamer->SwitchSection(ConfigSection); |
| 193 | } |
| 194 | |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 195 | SIProgramInfo KernelInfo; |
Tom Stellard | f151a45 | 2015-06-26 21:14:58 +0000 | [diff] [blame] | 196 | if (STM.getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS) { |
Matt Arsenault | 297ae31 | 2015-08-15 00:12:39 +0000 | [diff] [blame] | 197 | getSIProgramInfo(KernelInfo, MF); |
Tom Stellard | f151a45 | 2015-06-26 21:14:58 +0000 | [diff] [blame] | 198 | if (!STM.isAmdHsaOS()) { |
Tom Stellard | f151a45 | 2015-06-26 21:14:58 +0000 | [diff] [blame] | 199 | EmitProgramInfoSI(MF, KernelInfo); |
| 200 | } |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 201 | } else { |
| 202 | EmitProgramInfoR600(MF); |
| 203 | } |
| 204 | |
| 205 | DisasmLines.clear(); |
| 206 | HexLines.clear(); |
| 207 | DisasmLineMaxLen = 0; |
| 208 | |
| 209 | EmitFunctionBody(); |
| 210 | |
| 211 | if (isVerbose()) { |
| 212 | MCSectionELF *CommentSection = |
| 213 | Context.getELFSection(".AMDGPU.csdata", ELF::SHT_PROGBITS, 0); |
| 214 | OutStreamer->SwitchSection(CommentSection); |
| 215 | |
| 216 | if (STM.getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS) { |
| 217 | OutStreamer->emitRawComment(" Kernel info:", false); |
| 218 | OutStreamer->emitRawComment(" codeLenInByte = " + Twine(KernelInfo.CodeLen), |
| 219 | false); |
| 220 | OutStreamer->emitRawComment(" NumSgprs: " + Twine(KernelInfo.NumSGPR), |
| 221 | false); |
| 222 | OutStreamer->emitRawComment(" NumVgprs: " + Twine(KernelInfo.NumVGPR), |
| 223 | false); |
| 224 | OutStreamer->emitRawComment(" FloatMode: " + Twine(KernelInfo.FloatMode), |
| 225 | false); |
| 226 | OutStreamer->emitRawComment(" IeeeMode: " + Twine(KernelInfo.IEEEMode), |
| 227 | false); |
| 228 | OutStreamer->emitRawComment(" ScratchSize: " + Twine(KernelInfo.ScratchSize), |
| 229 | false); |
Matt Arsenault | fd8ab09 | 2016-04-14 22:11:51 +0000 | [diff] [blame] | 230 | OutStreamer->emitRawComment(" LDSByteSize: " + Twine(KernelInfo.LDSSize) + |
| 231 | " bytes/workgroup (compile time only)", false); |
Matt Arsenault | d41c0db | 2015-11-05 05:27:07 +0000 | [diff] [blame] | 232 | |
Konstantin Zhuravlyov | 1d65026 | 2016-09-06 20:22:28 +0000 | [diff] [blame] | 233 | OutStreamer->emitRawComment(" SGPRBlocks: " + |
| 234 | Twine(KernelInfo.SGPRBlocks), false); |
| 235 | OutStreamer->emitRawComment(" VGPRBlocks: " + |
| 236 | Twine(KernelInfo.VGPRBlocks), false); |
| 237 | |
| 238 | OutStreamer->emitRawComment(" NumSGPRsForWavesPerEU: " + |
| 239 | Twine(KernelInfo.NumSGPRsForWavesPerEU), false); |
| 240 | OutStreamer->emitRawComment(" NumVGPRsForWavesPerEU: " + |
| 241 | Twine(KernelInfo.NumVGPRsForWavesPerEU), false); |
| 242 | |
Konstantin Zhuravlyov | 1d99c4d | 2016-04-26 15:43:14 +0000 | [diff] [blame] | 243 | OutStreamer->emitRawComment(" ReservedVGPRFirst: " + Twine(KernelInfo.ReservedVGPRFirst), |
| 244 | false); |
| 245 | OutStreamer->emitRawComment(" ReservedVGPRCount: " + Twine(KernelInfo.ReservedVGPRCount), |
| 246 | false); |
| 247 | |
Konstantin Zhuravlyov | f2f3d14 | 2016-06-25 03:11:28 +0000 | [diff] [blame] | 248 | if (MF.getSubtarget<SISubtarget>().debuggerEmitPrologue()) { |
| 249 | OutStreamer->emitRawComment(" DebuggerWavefrontPrivateSegmentOffsetSGPR: s" + |
| 250 | Twine(KernelInfo.DebuggerWavefrontPrivateSegmentOffsetSGPR), false); |
| 251 | OutStreamer->emitRawComment(" DebuggerPrivateSegmentBufferSGPR: s" + |
| 252 | Twine(KernelInfo.DebuggerPrivateSegmentBufferSGPR), false); |
| 253 | } |
| 254 | |
Matt Arsenault | d41c0db | 2015-11-05 05:27:07 +0000 | [diff] [blame] | 255 | OutStreamer->emitRawComment(" COMPUTE_PGM_RSRC2:USER_SGPR: " + |
Matt Arsenault | 8246d4a | 2015-11-11 00:27:46 +0000 | [diff] [blame] | 256 | Twine(G_00B84C_USER_SGPR(KernelInfo.ComputePGMRSrc2)), |
Matt Arsenault | d41c0db | 2015-11-05 05:27:07 +0000 | [diff] [blame] | 257 | false); |
Wei Ding | 205bfdb | 2017-02-10 02:15:29 +0000 | [diff] [blame] | 258 | OutStreamer->emitRawComment(" COMPUTE_PGM_RSRC2:TRAP_HANDLER: " + |
| 259 | Twine(G_00B84C_TRAP_HANDLER(KernelInfo.ComputePGMRSrc2)), |
| 260 | false); |
Matt Arsenault | 8246d4a | 2015-11-11 00:27:46 +0000 | [diff] [blame] | 261 | OutStreamer->emitRawComment(" COMPUTE_PGM_RSRC2:TGID_X_EN: " + |
| 262 | Twine(G_00B84C_TGID_X_EN(KernelInfo.ComputePGMRSrc2)), |
| 263 | false); |
| 264 | OutStreamer->emitRawComment(" COMPUTE_PGM_RSRC2:TGID_Y_EN: " + |
| 265 | Twine(G_00B84C_TGID_Y_EN(KernelInfo.ComputePGMRSrc2)), |
| 266 | false); |
| 267 | OutStreamer->emitRawComment(" COMPUTE_PGM_RSRC2:TGID_Z_EN: " + |
| 268 | Twine(G_00B84C_TGID_Z_EN(KernelInfo.ComputePGMRSrc2)), |
| 269 | false); |
| 270 | OutStreamer->emitRawComment(" COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: " + |
| 271 | Twine(G_00B84C_TIDIG_COMP_CNT(KernelInfo.ComputePGMRSrc2)), |
| 272 | false); |
| 273 | |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 274 | } else { |
| 275 | R600MachineFunctionInfo *MFI = MF.getInfo<R600MachineFunctionInfo>(); |
| 276 | OutStreamer->emitRawComment( |
Matt Arsenault | f9245b7 | 2016-07-22 17:01:25 +0000 | [diff] [blame] | 277 | Twine("SQ_PGM_RESOURCES:STACK_SIZE = " + Twine(MFI->CFStackSize))); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 278 | } |
| 279 | } |
| 280 | |
| 281 | if (STM.dumpCode()) { |
| 282 | |
| 283 | OutStreamer->SwitchSection( |
| 284 | Context.getELFSection(".AMDGPU.disasm", ELF::SHT_NOTE, 0)); |
| 285 | |
| 286 | for (size_t i = 0; i < DisasmLines.size(); ++i) { |
| 287 | std::string Comment(DisasmLineMaxLen - DisasmLines[i].size(), ' '); |
| 288 | Comment += " ; " + HexLines[i] + "\n"; |
| 289 | |
| 290 | OutStreamer->EmitBytes(StringRef(DisasmLines[i])); |
| 291 | OutStreamer->EmitBytes(StringRef(Comment)); |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | return false; |
| 296 | } |
| 297 | |
| 298 | void AMDGPUAsmPrinter::EmitProgramInfoR600(const MachineFunction &MF) { |
| 299 | unsigned MaxGPR = 0; |
| 300 | bool killPixel = false; |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 301 | const R600Subtarget &STM = MF.getSubtarget<R600Subtarget>(); |
| 302 | const R600RegisterInfo *RI = STM.getRegisterInfo(); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 303 | const R600MachineFunctionInfo *MFI = MF.getInfo<R600MachineFunctionInfo>(); |
| 304 | |
| 305 | for (const MachineBasicBlock &MBB : MF) { |
| 306 | for (const MachineInstr &MI : MBB) { |
| 307 | if (MI.getOpcode() == AMDGPU::KILLGT) |
| 308 | killPixel = true; |
| 309 | unsigned numOperands = MI.getNumOperands(); |
| 310 | for (unsigned op_idx = 0; op_idx < numOperands; op_idx++) { |
| 311 | const MachineOperand &MO = MI.getOperand(op_idx); |
| 312 | if (!MO.isReg()) |
| 313 | continue; |
| 314 | unsigned HWReg = RI->getEncodingValue(MO.getReg()) & 0xff; |
| 315 | |
| 316 | // Register with value > 127 aren't GPR |
| 317 | if (HWReg > 127) |
| 318 | continue; |
| 319 | MaxGPR = std::max(MaxGPR, HWReg); |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | unsigned RsrcReg; |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 325 | if (STM.getGeneration() >= R600Subtarget::EVERGREEN) { |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 326 | // Evergreen / Northern Islands |
Nicolai Haehnle | df3a20c | 2016-04-06 19:40:20 +0000 | [diff] [blame] | 327 | switch (MF.getFunction()->getCallingConv()) { |
Justin Bogner | cd1d5aa | 2016-08-17 20:30:52 +0000 | [diff] [blame] | 328 | default: LLVM_FALLTHROUGH; |
Nicolai Haehnle | df3a20c | 2016-04-06 19:40:20 +0000 | [diff] [blame] | 329 | case CallingConv::AMDGPU_CS: RsrcReg = R_0288D4_SQ_PGM_RESOURCES_LS; break; |
| 330 | case CallingConv::AMDGPU_GS: RsrcReg = R_028878_SQ_PGM_RESOURCES_GS; break; |
| 331 | case CallingConv::AMDGPU_PS: RsrcReg = R_028844_SQ_PGM_RESOURCES_PS; break; |
| 332 | case CallingConv::AMDGPU_VS: RsrcReg = R_028860_SQ_PGM_RESOURCES_VS; break; |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 333 | } |
| 334 | } else { |
| 335 | // R600 / R700 |
Nicolai Haehnle | df3a20c | 2016-04-06 19:40:20 +0000 | [diff] [blame] | 336 | switch (MF.getFunction()->getCallingConv()) { |
Justin Bogner | cd1d5aa | 2016-08-17 20:30:52 +0000 | [diff] [blame] | 337 | default: LLVM_FALLTHROUGH; |
| 338 | case CallingConv::AMDGPU_GS: LLVM_FALLTHROUGH; |
| 339 | case CallingConv::AMDGPU_CS: LLVM_FALLTHROUGH; |
Nicolai Haehnle | df3a20c | 2016-04-06 19:40:20 +0000 | [diff] [blame] | 340 | case CallingConv::AMDGPU_VS: RsrcReg = R_028868_SQ_PGM_RESOURCES_VS; break; |
| 341 | case CallingConv::AMDGPU_PS: RsrcReg = R_028850_SQ_PGM_RESOURCES_PS; break; |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | |
| 345 | OutStreamer->EmitIntValue(RsrcReg, 4); |
| 346 | OutStreamer->EmitIntValue(S_NUM_GPRS(MaxGPR + 1) | |
Matt Arsenault | f9245b7 | 2016-07-22 17:01:25 +0000 | [diff] [blame] | 347 | S_STACK_SIZE(MFI->CFStackSize), 4); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 348 | OutStreamer->EmitIntValue(R_02880C_DB_SHADER_CONTROL, 4); |
| 349 | OutStreamer->EmitIntValue(S_02880C_KILL_ENABLE(killPixel), 4); |
| 350 | |
Nicolai Haehnle | df3a20c | 2016-04-06 19:40:20 +0000 | [diff] [blame] | 351 | if (AMDGPU::isCompute(MF.getFunction()->getCallingConv())) { |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 352 | OutStreamer->EmitIntValue(R_0288E8_SQ_LDS_ALLOC, 4); |
Matt Arsenault | 52ef401 | 2016-07-26 16:45:58 +0000 | [diff] [blame] | 353 | OutStreamer->EmitIntValue(alignTo(MFI->getLDSSize(), 4) >> 2, 4); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | |
| 357 | void AMDGPUAsmPrinter::getSIProgramInfo(SIProgramInfo &ProgInfo, |
| 358 | const MachineFunction &MF) const { |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 359 | const SISubtarget &STM = MF.getSubtarget<SISubtarget>(); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 360 | const SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>(); |
| 361 | uint64_t CodeSize = 0; |
| 362 | unsigned MaxSGPR = 0; |
| 363 | unsigned MaxVGPR = 0; |
| 364 | bool VCCUsed = false; |
| 365 | bool FlatUsed = false; |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 366 | const SIRegisterInfo *RI = STM.getRegisterInfo(); |
| 367 | const SIInstrInfo *TII = STM.getInstrInfo(); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 368 | |
| 369 | for (const MachineBasicBlock &MBB : MF) { |
| 370 | for (const MachineInstr &MI : MBB) { |
| 371 | // TODO: CodeSize should account for multiple functions. |
Matt Arsenault | c574686 | 2015-08-12 09:04:44 +0000 | [diff] [blame] | 372 | |
| 373 | // TODO: Should we count size of debug info? |
| 374 | if (MI.isDebugValue()) |
| 375 | continue; |
| 376 | |
Matt Arsenault | 10c17ca | 2016-10-06 10:13:23 +0000 | [diff] [blame] | 377 | if (isVerbose()) |
| 378 | CodeSize += TII->getInstSizeInBytes(MI); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 379 | |
| 380 | unsigned numOperands = MI.getNumOperands(); |
| 381 | for (unsigned op_idx = 0; op_idx < numOperands; op_idx++) { |
| 382 | const MachineOperand &MO = MI.getOperand(op_idx); |
| 383 | unsigned width = 0; |
| 384 | bool isSGPR = false; |
| 385 | |
Matt Arsenault | d2c7589 | 2015-10-01 21:51:59 +0000 | [diff] [blame] | 386 | if (!MO.isReg()) |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 387 | continue; |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 388 | |
Matt Arsenault | d2c7589 | 2015-10-01 21:51:59 +0000 | [diff] [blame] | 389 | unsigned reg = MO.getReg(); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 390 | switch (reg) { |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 391 | case AMDGPU::EXEC: |
Nicolai Haehnle | 7483937 | 2016-04-19 21:58:17 +0000 | [diff] [blame] | 392 | case AMDGPU::EXEC_LO: |
| 393 | case AMDGPU::EXEC_HI: |
Matt Arsenault | d2c7589 | 2015-10-01 21:51:59 +0000 | [diff] [blame] | 394 | case AMDGPU::SCC: |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 395 | case AMDGPU::M0: |
Matt Arsenault | e823d92 | 2017-02-18 18:29:53 +0000 | [diff] [blame] | 396 | case AMDGPU::SRC_SHARED_BASE: |
| 397 | case AMDGPU::SRC_SHARED_LIMIT: |
| 398 | case AMDGPU::SRC_PRIVATE_BASE: |
| 399 | case AMDGPU::SRC_PRIVATE_LIMIT: |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 400 | continue; |
Matt Arsenault | d2c7589 | 2015-10-01 21:51:59 +0000 | [diff] [blame] | 401 | |
| 402 | case AMDGPU::VCC: |
| 403 | case AMDGPU::VCC_LO: |
| 404 | case AMDGPU::VCC_HI: |
| 405 | VCCUsed = true; |
| 406 | continue; |
| 407 | |
| 408 | case AMDGPU::FLAT_SCR: |
| 409 | case AMDGPU::FLAT_SCR_LO: |
| 410 | case AMDGPU::FLAT_SCR_HI: |
Marek Olsak | 693e9be | 2016-12-09 19:49:48 +0000 | [diff] [blame] | 411 | // Even if FLAT_SCRATCH is implicitly used, it has no effect if flat |
| 412 | // instructions aren't used to access the scratch buffer. |
| 413 | if (MFI->hasFlatScratchInit()) |
| 414 | FlatUsed = true; |
Matt Arsenault | d2c7589 | 2015-10-01 21:51:59 +0000 | [diff] [blame] | 415 | continue; |
| 416 | |
Artem Tamazov | eb4d5a9 | 2016-04-13 16:18:41 +0000 | [diff] [blame] | 417 | case AMDGPU::TBA: |
| 418 | case AMDGPU::TBA_LO: |
| 419 | case AMDGPU::TBA_HI: |
| 420 | case AMDGPU::TMA: |
| 421 | case AMDGPU::TMA_LO: |
| 422 | case AMDGPU::TMA_HI: |
Matt Arsenault | b06db8f | 2016-07-26 21:03:36 +0000 | [diff] [blame] | 423 | llvm_unreachable("trap handler registers should not be used"); |
Artem Tamazov | eb4d5a9 | 2016-04-13 16:18:41 +0000 | [diff] [blame] | 424 | |
Matt Arsenault | d2c7589 | 2015-10-01 21:51:59 +0000 | [diff] [blame] | 425 | default: |
| 426 | break; |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | if (AMDGPU::SReg_32RegClass.contains(reg)) { |
Matt Arsenault | b06db8f | 2016-07-26 21:03:36 +0000 | [diff] [blame] | 430 | assert(!AMDGPU::TTMP_32RegClass.contains(reg) && |
| 431 | "trap handler registers should not be used"); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 432 | isSGPR = true; |
| 433 | width = 1; |
| 434 | } else if (AMDGPU::VGPR_32RegClass.contains(reg)) { |
| 435 | isSGPR = false; |
| 436 | width = 1; |
| 437 | } else if (AMDGPU::SReg_64RegClass.contains(reg)) { |
Matt Arsenault | b06db8f | 2016-07-26 21:03:36 +0000 | [diff] [blame] | 438 | assert(!AMDGPU::TTMP_64RegClass.contains(reg) && |
| 439 | "trap handler registers should not be used"); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 440 | isSGPR = true; |
| 441 | width = 2; |
| 442 | } else if (AMDGPU::VReg_64RegClass.contains(reg)) { |
| 443 | isSGPR = false; |
| 444 | width = 2; |
| 445 | } else if (AMDGPU::VReg_96RegClass.contains(reg)) { |
| 446 | isSGPR = false; |
| 447 | width = 3; |
| 448 | } else if (AMDGPU::SReg_128RegClass.contains(reg)) { |
| 449 | isSGPR = true; |
| 450 | width = 4; |
| 451 | } else if (AMDGPU::VReg_128RegClass.contains(reg)) { |
| 452 | isSGPR = false; |
| 453 | width = 4; |
| 454 | } else if (AMDGPU::SReg_256RegClass.contains(reg)) { |
| 455 | isSGPR = true; |
| 456 | width = 8; |
| 457 | } else if (AMDGPU::VReg_256RegClass.contains(reg)) { |
| 458 | isSGPR = false; |
| 459 | width = 8; |
| 460 | } else if (AMDGPU::SReg_512RegClass.contains(reg)) { |
| 461 | isSGPR = true; |
| 462 | width = 16; |
| 463 | } else if (AMDGPU::VReg_512RegClass.contains(reg)) { |
| 464 | isSGPR = false; |
| 465 | width = 16; |
| 466 | } else { |
| 467 | llvm_unreachable("Unknown register class"); |
| 468 | } |
| 469 | unsigned hwReg = RI->getEncodingValue(reg) & 0xff; |
| 470 | unsigned maxUsed = hwReg + width - 1; |
| 471 | if (isSGPR) { |
| 472 | MaxSGPR = maxUsed > MaxSGPR ? maxUsed : MaxSGPR; |
| 473 | } else { |
| 474 | MaxVGPR = maxUsed > MaxVGPR ? maxUsed : MaxVGPR; |
| 475 | } |
| 476 | } |
| 477 | } |
| 478 | } |
| 479 | |
Nicolai Haehnle | 3c05d6d | 2016-01-07 17:10:20 +0000 | [diff] [blame] | 480 | unsigned ExtraSGPRs = 0; |
| 481 | |
| 482 | if (VCCUsed) |
| 483 | ExtraSGPRs = 2; |
| 484 | |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 485 | if (STM.getGeneration() < SISubtarget::VOLCANIC_ISLANDS) { |
Nicolai Haehnle | 3c05d6d | 2016-01-07 17:10:20 +0000 | [diff] [blame] | 486 | if (FlatUsed) |
| 487 | ExtraSGPRs = 4; |
| 488 | } else { |
| 489 | if (STM.isXNACKEnabled()) |
| 490 | ExtraSGPRs = 4; |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 491 | |
Nicolai Haehnle | 5b50497 | 2016-01-04 23:35:53 +0000 | [diff] [blame] | 492 | if (FlatUsed) |
Nicolai Haehnle | 3c05d6d | 2016-01-07 17:10:20 +0000 | [diff] [blame] | 493 | ExtraSGPRs = 6; |
Tom Stellard | caaa3aa | 2015-12-17 17:05:09 +0000 | [diff] [blame] | 494 | } |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 495 | |
Konstantin Zhuravlyov | e03b1d7 | 2017-02-08 13:02:33 +0000 | [diff] [blame] | 496 | unsigned ExtraVGPRs = STM.getReservedNumVGPRs(MF); |
Konstantin Zhuravlyov | f2f3d14 | 2016-06-25 03:11:28 +0000 | [diff] [blame] | 497 | |
Marek Olsak | 91f22fb | 2016-12-09 19:49:40 +0000 | [diff] [blame] | 498 | // Check the addressable register limit before we add ExtraSGPRs. |
| 499 | if (STM.getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS && |
| 500 | !STM.hasSGPRInitBug()) { |
Konstantin Zhuravlyov | e03b1d7 | 2017-02-08 13:02:33 +0000 | [diff] [blame] | 501 | unsigned MaxAddressableNumSGPRs = STM.getAddressableNumSGPRs(); |
Marek Olsak | 91f22fb | 2016-12-09 19:49:40 +0000 | [diff] [blame] | 502 | if (MaxSGPR + 1 > MaxAddressableNumSGPRs) { |
| 503 | // This can happen due to a compiler bug or when using inline asm. |
| 504 | LLVMContext &Ctx = MF.getFunction()->getContext(); |
| 505 | DiagnosticInfoResourceLimit Diag(*MF.getFunction(), |
| 506 | "addressable scalar registers", |
| 507 | MaxSGPR + 1, DS_Error, |
Konstantin Zhuravlyov | 9f89ede | 2017-02-08 14:05:23 +0000 | [diff] [blame] | 508 | DK_ResourceLimit, |
| 509 | MaxAddressableNumSGPRs); |
Marek Olsak | 91f22fb | 2016-12-09 19:49:40 +0000 | [diff] [blame] | 510 | Ctx.diagnose(Diag); |
| 511 | MaxSGPR = MaxAddressableNumSGPRs - 1; |
| 512 | } |
| 513 | } |
| 514 | |
Konstantin Zhuravlyov | 1d65026 | 2016-09-06 20:22:28 +0000 | [diff] [blame] | 515 | // Account for extra SGPRs and VGPRs reserved for debugger use. |
| 516 | MaxSGPR += ExtraSGPRs; |
Konstantin Zhuravlyov | e03b1d7 | 2017-02-08 13:02:33 +0000 | [diff] [blame] | 517 | MaxVGPR += ExtraVGPRs; |
Konstantin Zhuravlyov | 1d65026 | 2016-09-06 20:22:28 +0000 | [diff] [blame] | 518 | |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 519 | // We found the maximum register index. They start at 0, so add one to get the |
| 520 | // number of registers. |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 521 | ProgInfo.NumSGPR = MaxSGPR + 1; |
Konstantin Zhuravlyov | e03b1d7 | 2017-02-08 13:02:33 +0000 | [diff] [blame] | 522 | ProgInfo.NumVGPR = MaxVGPR + 1; |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 523 | |
Konstantin Zhuravlyov | 1d65026 | 2016-09-06 20:22:28 +0000 | [diff] [blame] | 524 | // Adjust number of registers used to meet default/requested minimum/maximum |
| 525 | // number of waves per execution unit request. |
| 526 | ProgInfo.NumSGPRsForWavesPerEU = std::max( |
Konstantin Zhuravlyov | e03b1d7 | 2017-02-08 13:02:33 +0000 | [diff] [blame] | 527 | ProgInfo.NumSGPR, STM.getMinNumSGPRs(MFI->getMaxWavesPerEU())); |
Konstantin Zhuravlyov | 1d65026 | 2016-09-06 20:22:28 +0000 | [diff] [blame] | 528 | ProgInfo.NumVGPRsForWavesPerEU = std::max( |
Konstantin Zhuravlyov | e03b1d7 | 2017-02-08 13:02:33 +0000 | [diff] [blame] | 529 | ProgInfo.NumVGPR, STM.getMinNumVGPRs(MFI->getMaxWavesPerEU())); |
Konstantin Zhuravlyov | 1d65026 | 2016-09-06 20:22:28 +0000 | [diff] [blame] | 530 | |
Marek Olsak | 91f22fb | 2016-12-09 19:49:40 +0000 | [diff] [blame] | 531 | if (STM.getGeneration() <= AMDGPUSubtarget::SEA_ISLANDS || |
| 532 | STM.hasSGPRInitBug()) { |
Konstantin Zhuravlyov | 9f89ede | 2017-02-08 14:05:23 +0000 | [diff] [blame] | 533 | unsigned MaxAddressableNumSGPRs = STM.getAddressableNumSGPRs(); |
| 534 | if (ProgInfo.NumSGPR > MaxAddressableNumSGPRs) { |
| 535 | // This can happen due to a compiler bug or when using inline asm to use |
| 536 | // the registers which are usually reserved for vcc etc. |
Marek Olsak | 91f22fb | 2016-12-09 19:49:40 +0000 | [diff] [blame] | 537 | LLVMContext &Ctx = MF.getFunction()->getContext(); |
| 538 | DiagnosticInfoResourceLimit Diag(*MF.getFunction(), |
| 539 | "scalar registers", |
| 540 | ProgInfo.NumSGPR, DS_Error, |
Konstantin Zhuravlyov | 9f89ede | 2017-02-08 14:05:23 +0000 | [diff] [blame] | 541 | DK_ResourceLimit, |
| 542 | MaxAddressableNumSGPRs); |
Marek Olsak | 91f22fb | 2016-12-09 19:49:40 +0000 | [diff] [blame] | 543 | Ctx.diagnose(Diag); |
Konstantin Zhuravlyov | 9f89ede | 2017-02-08 14:05:23 +0000 | [diff] [blame] | 544 | ProgInfo.NumSGPR = MaxAddressableNumSGPRs; |
| 545 | ProgInfo.NumSGPRsForWavesPerEU = MaxAddressableNumSGPRs; |
Marek Olsak | 91f22fb | 2016-12-09 19:49:40 +0000 | [diff] [blame] | 546 | } |
Matt Arsenault | 4eae301 | 2016-10-28 20:31:47 +0000 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | if (STM.hasSGPRInitBug()) { |
Konstantin Zhuravlyov | 9f89ede | 2017-02-08 14:05:23 +0000 | [diff] [blame] | 550 | ProgInfo.NumSGPR = |
| 551 | AMDGPU::IsaInfo::FIXED_NUM_SGPRS_FOR_INIT_BUG; |
| 552 | ProgInfo.NumSGPRsForWavesPerEU = |
| 553 | AMDGPU::IsaInfo::FIXED_NUM_SGPRS_FOR_INIT_BUG; |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 554 | } |
| 555 | |
Matt Arsenault | 41003af | 2015-11-30 21:16:07 +0000 | [diff] [blame] | 556 | if (MFI->NumUserSGPRs > STM.getMaxNumUserSGPRs()) { |
| 557 | LLVMContext &Ctx = MF.getFunction()->getContext(); |
Matt Arsenault | ff98241 | 2016-06-20 18:13:04 +0000 | [diff] [blame] | 558 | DiagnosticInfoResourceLimit Diag(*MF.getFunction(), "user SGPRs", |
| 559 | MFI->NumUserSGPRs, DS_Error); |
| 560 | Ctx.diagnose(Diag); |
Matt Arsenault | 41003af | 2015-11-30 21:16:07 +0000 | [diff] [blame] | 561 | } |
| 562 | |
Matt Arsenault | 52ef401 | 2016-07-26 16:45:58 +0000 | [diff] [blame] | 563 | if (MFI->getLDSSize() > static_cast<unsigned>(STM.getLocalMemorySize())) { |
Matt Arsenault | 1c4d0ef | 2016-04-28 19:37:35 +0000 | [diff] [blame] | 564 | LLVMContext &Ctx = MF.getFunction()->getContext(); |
Matt Arsenault | ff98241 | 2016-06-20 18:13:04 +0000 | [diff] [blame] | 565 | DiagnosticInfoResourceLimit Diag(*MF.getFunction(), "local memory", |
Matt Arsenault | 52ef401 | 2016-07-26 16:45:58 +0000 | [diff] [blame] | 566 | MFI->getLDSSize(), DS_Error); |
Matt Arsenault | ff98241 | 2016-06-20 18:13:04 +0000 | [diff] [blame] | 567 | Ctx.diagnose(Diag); |
Matt Arsenault | 1c4d0ef | 2016-04-28 19:37:35 +0000 | [diff] [blame] | 568 | } |
| 569 | |
Konstantin Zhuravlyov | 1d65026 | 2016-09-06 20:22:28 +0000 | [diff] [blame] | 570 | // SGPRBlocks is actual number of SGPR blocks minus 1. |
| 571 | ProgInfo.SGPRBlocks = alignTo(ProgInfo.NumSGPRsForWavesPerEU, |
Konstantin Zhuravlyov | e22fbcb | 2017-02-08 13:18:40 +0000 | [diff] [blame] | 572 | STM.getSGPREncodingGranule()); |
| 573 | ProgInfo.SGPRBlocks = ProgInfo.SGPRBlocks / STM.getSGPREncodingGranule() - 1; |
Konstantin Zhuravlyov | 1d65026 | 2016-09-06 20:22:28 +0000 | [diff] [blame] | 574 | |
| 575 | // VGPRBlocks is actual number of VGPR blocks minus 1. |
| 576 | ProgInfo.VGPRBlocks = alignTo(ProgInfo.NumVGPRsForWavesPerEU, |
Konstantin Zhuravlyov | e22fbcb | 2017-02-08 13:18:40 +0000 | [diff] [blame] | 577 | STM.getVGPREncodingGranule()); |
| 578 | ProgInfo.VGPRBlocks = ProgInfo.VGPRBlocks / STM.getVGPREncodingGranule() - 1; |
Konstantin Zhuravlyov | e03b1d7 | 2017-02-08 13:02:33 +0000 | [diff] [blame] | 579 | |
Konstantin Zhuravlyov | 9f89ede | 2017-02-08 14:05:23 +0000 | [diff] [blame] | 580 | // Record first reserved VGPR and number of reserved VGPRs. |
Konstantin Zhuravlyov | e03b1d7 | 2017-02-08 13:02:33 +0000 | [diff] [blame] | 581 | ProgInfo.ReservedVGPRFirst = STM.debuggerReserveRegs() ? MaxVGPR + 1 : 0; |
| 582 | ProgInfo.ReservedVGPRCount = STM.getReservedNumVGPRs(MF); |
| 583 | |
| 584 | // Update DebuggerWavefrontPrivateSegmentOffsetSGPR and |
| 585 | // DebuggerPrivateSegmentBufferSGPR fields if "amdgpu-debugger-emit-prologue" |
| 586 | // attribute was requested. |
| 587 | if (STM.debuggerEmitPrologue()) { |
| 588 | ProgInfo.DebuggerWavefrontPrivateSegmentOffsetSGPR = |
| 589 | RI->getHWRegIndex(MFI->getScratchWaveOffsetReg()); |
| 590 | ProgInfo.DebuggerPrivateSegmentBufferSGPR = |
| 591 | RI->getHWRegIndex(MFI->getScratchRSrcReg()); |
| 592 | } |
Konstantin Zhuravlyov | 1d65026 | 2016-09-06 20:22:28 +0000 | [diff] [blame] | 593 | |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 594 | // Set the value to initialize FP_ROUND and FP_DENORM parts of the mode |
| 595 | // register. |
| 596 | ProgInfo.FloatMode = getFPMode(MF); |
| 597 | |
Wei Ding | 3cb2a1e | 2016-10-19 22:34:49 +0000 | [diff] [blame] | 598 | ProgInfo.IEEEMode = STM.enableIEEEBit(MF); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 599 | |
Matt Arsenault | 7293f98 | 2016-01-28 20:53:35 +0000 | [diff] [blame] | 600 | // Make clamp modifier on NaN input returns 0. |
Matt Arsenault | 2fdf2a1 | 2017-02-21 23:35:48 +0000 | [diff] [blame] | 601 | ProgInfo.DX10Clamp = STM.enableDX10Clamp(); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 602 | |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 603 | const MachineFrameInfo &FrameInfo = MF.getFrameInfo(); |
| 604 | ProgInfo.ScratchSize = FrameInfo.getStackSize(); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 605 | |
| 606 | ProgInfo.FlatUsed = FlatUsed; |
| 607 | ProgInfo.VCCUsed = VCCUsed; |
| 608 | ProgInfo.CodeLen = CodeSize; |
| 609 | |
| 610 | unsigned LDSAlignShift; |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 611 | if (STM.getGeneration() < SISubtarget::SEA_ISLANDS) { |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 612 | // LDS is allocated in 64 dword blocks. |
| 613 | LDSAlignShift = 8; |
| 614 | } else { |
| 615 | // LDS is allocated in 128 dword blocks. |
| 616 | LDSAlignShift = 9; |
| 617 | } |
| 618 | |
Konstantin Zhuravlyov | 1d65026 | 2016-09-06 20:22:28 +0000 | [diff] [blame] | 619 | unsigned LDSSpillSize = |
| 620 | MFI->LDSWaveSpillSize * MFI->getMaxFlatWorkGroupSize(); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 621 | |
Matt Arsenault | 52ef401 | 2016-07-26 16:45:58 +0000 | [diff] [blame] | 622 | ProgInfo.LDSSize = MFI->getLDSSize() + LDSSpillSize; |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 623 | ProgInfo.LDSBlocks = |
Aaron Ballman | ef0fe1e | 2016-03-30 21:30:00 +0000 | [diff] [blame] | 624 | alignTo(ProgInfo.LDSSize, 1ULL << LDSAlignShift) >> LDSAlignShift; |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 625 | |
| 626 | // Scratch is allocated in 256 dword blocks. |
| 627 | unsigned ScratchAlignShift = 10; |
| 628 | // We need to program the hardware with the amount of scratch memory that |
| 629 | // is used by the entire wave. ProgInfo.ScratchSize is the amount of |
| 630 | // scratch memory used per thread. |
| 631 | ProgInfo.ScratchBlocks = |
Rui Ueyama | da00f2f | 2016-01-14 21:06:47 +0000 | [diff] [blame] | 632 | alignTo(ProgInfo.ScratchSize * STM.getWavefrontSize(), |
Aaron Ballman | ef0fe1e | 2016-03-30 21:30:00 +0000 | [diff] [blame] | 633 | 1ULL << ScratchAlignShift) >> |
Rui Ueyama | da00f2f | 2016-01-14 21:06:47 +0000 | [diff] [blame] | 634 | ScratchAlignShift; |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 635 | |
| 636 | ProgInfo.ComputePGMRSrc1 = |
| 637 | S_00B848_VGPRS(ProgInfo.VGPRBlocks) | |
| 638 | S_00B848_SGPRS(ProgInfo.SGPRBlocks) | |
| 639 | S_00B848_PRIORITY(ProgInfo.Priority) | |
| 640 | S_00B848_FLOAT_MODE(ProgInfo.FloatMode) | |
| 641 | S_00B848_PRIV(ProgInfo.Priv) | |
| 642 | S_00B848_DX10_CLAMP(ProgInfo.DX10Clamp) | |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 643 | S_00B848_DEBUG_MODE(ProgInfo.DebugMode) | |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 644 | S_00B848_IEEE_MODE(ProgInfo.IEEEMode); |
| 645 | |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 646 | // 0 = X, 1 = XY, 2 = XYZ |
| 647 | unsigned TIDIGCompCnt = 0; |
| 648 | if (MFI->hasWorkItemIDZ()) |
| 649 | TIDIGCompCnt = 2; |
| 650 | else if (MFI->hasWorkItemIDY()) |
| 651 | TIDIGCompCnt = 1; |
| 652 | |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 653 | ProgInfo.ComputePGMRSrc2 = |
| 654 | S_00B84C_SCRATCH_EN(ProgInfo.ScratchBlocks > 0) | |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 655 | S_00B84C_USER_SGPR(MFI->getNumUserSGPRs()) | |
Wei Ding | 205bfdb | 2017-02-10 02:15:29 +0000 | [diff] [blame] | 656 | S_00B84C_TRAP_HANDLER(STM.isTrapHandlerEnabled()) | |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 657 | S_00B84C_TGID_X_EN(MFI->hasWorkGroupIDX()) | |
| 658 | S_00B84C_TGID_Y_EN(MFI->hasWorkGroupIDY()) | |
| 659 | S_00B84C_TGID_Z_EN(MFI->hasWorkGroupIDZ()) | |
| 660 | S_00B84C_TG_SIZE_EN(MFI->hasWorkGroupInfo()) | |
| 661 | S_00B84C_TIDIG_COMP_CNT(TIDIGCompCnt) | |
| 662 | S_00B84C_EXCP_EN_MSB(0) | |
| 663 | S_00B84C_LDS_SIZE(ProgInfo.LDSBlocks) | |
| 664 | S_00B84C_EXCP_EN(0); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 665 | } |
| 666 | |
Nicolai Haehnle | df3a20c | 2016-04-06 19:40:20 +0000 | [diff] [blame] | 667 | static unsigned getRsrcReg(CallingConv::ID CallConv) { |
| 668 | switch (CallConv) { |
Justin Bogner | cd1d5aa | 2016-08-17 20:30:52 +0000 | [diff] [blame] | 669 | default: LLVM_FALLTHROUGH; |
Nicolai Haehnle | df3a20c | 2016-04-06 19:40:20 +0000 | [diff] [blame] | 670 | case CallingConv::AMDGPU_CS: return R_00B848_COMPUTE_PGM_RSRC1; |
| 671 | case CallingConv::AMDGPU_GS: return R_00B228_SPI_SHADER_PGM_RSRC1_GS; |
| 672 | case CallingConv::AMDGPU_PS: return R_00B028_SPI_SHADER_PGM_RSRC1_PS; |
| 673 | case CallingConv::AMDGPU_VS: return R_00B128_SPI_SHADER_PGM_RSRC1_VS; |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 674 | } |
| 675 | } |
| 676 | |
| 677 | void AMDGPUAsmPrinter::EmitProgramInfoSI(const MachineFunction &MF, |
| 678 | const SIProgramInfo &KernelInfo) { |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 679 | const SISubtarget &STM = MF.getSubtarget<SISubtarget>(); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 680 | const SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>(); |
Nicolai Haehnle | df3a20c | 2016-04-06 19:40:20 +0000 | [diff] [blame] | 681 | unsigned RsrcReg = getRsrcReg(MF.getFunction()->getCallingConv()); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 682 | |
Nicolai Haehnle | df3a20c | 2016-04-06 19:40:20 +0000 | [diff] [blame] | 683 | if (AMDGPU::isCompute(MF.getFunction()->getCallingConv())) { |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 684 | OutStreamer->EmitIntValue(R_00B848_COMPUTE_PGM_RSRC1, 4); |
| 685 | |
| 686 | OutStreamer->EmitIntValue(KernelInfo.ComputePGMRSrc1, 4); |
| 687 | |
| 688 | OutStreamer->EmitIntValue(R_00B84C_COMPUTE_PGM_RSRC2, 4); |
| 689 | OutStreamer->EmitIntValue(KernelInfo.ComputePGMRSrc2, 4); |
| 690 | |
| 691 | OutStreamer->EmitIntValue(R_00B860_COMPUTE_TMPRING_SIZE, 4); |
| 692 | OutStreamer->EmitIntValue(S_00B860_WAVESIZE(KernelInfo.ScratchBlocks), 4); |
| 693 | |
| 694 | // TODO: Should probably note flat usage somewhere. SC emits a "FlatPtr32 = |
| 695 | // 0" comment but I don't see a corresponding field in the register spec. |
| 696 | } else { |
| 697 | OutStreamer->EmitIntValue(RsrcReg, 4); |
| 698 | OutStreamer->EmitIntValue(S_00B028_VGPRS(KernelInfo.VGPRBlocks) | |
| 699 | S_00B028_SGPRS(KernelInfo.SGPRBlocks), 4); |
Nicolai Haehnle | df3a20c | 2016-04-06 19:40:20 +0000 | [diff] [blame] | 700 | if (STM.isVGPRSpillingEnabled(*MF.getFunction())) { |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 701 | OutStreamer->EmitIntValue(R_0286E8_SPI_TMPRING_SIZE, 4); |
| 702 | OutStreamer->EmitIntValue(S_0286E8_WAVESIZE(KernelInfo.ScratchBlocks), 4); |
| 703 | } |
| 704 | } |
| 705 | |
Nicolai Haehnle | df3a20c | 2016-04-06 19:40:20 +0000 | [diff] [blame] | 706 | if (MF.getFunction()->getCallingConv() == CallingConv::AMDGPU_PS) { |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 707 | OutStreamer->EmitIntValue(R_00B02C_SPI_SHADER_PGM_RSRC2_PS, 4); |
| 708 | OutStreamer->EmitIntValue(S_00B02C_EXTRA_LDS_SIZE(KernelInfo.LDSBlocks), 4); |
| 709 | OutStreamer->EmitIntValue(R_0286CC_SPI_PS_INPUT_ENA, 4); |
Marek Olsak | fccabaf | 2016-01-13 11:45:36 +0000 | [diff] [blame] | 710 | OutStreamer->EmitIntValue(MFI->PSInputEna, 4); |
| 711 | OutStreamer->EmitIntValue(R_0286D0_SPI_PS_INPUT_ADDR, 4); |
| 712 | OutStreamer->EmitIntValue(MFI->getPSInputAddr(), 4); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 713 | } |
Marek Olsak | 0532c19 | 2016-07-13 17:35:15 +0000 | [diff] [blame] | 714 | |
| 715 | OutStreamer->EmitIntValue(R_SPILLED_SGPRS, 4); |
| 716 | OutStreamer->EmitIntValue(MFI->getNumSpilledSGPRs(), 4); |
| 717 | OutStreamer->EmitIntValue(R_SPILLED_VGPRS, 4); |
| 718 | OutStreamer->EmitIntValue(MFI->getNumSpilledVGPRs(), 4); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 719 | } |
| 720 | |
Matt Arsenault | 24ee078 | 2016-02-12 02:40:47 +0000 | [diff] [blame] | 721 | // This is supposed to be log2(Size) |
| 722 | static amd_element_byte_size_t getElementByteSizeValue(unsigned Size) { |
| 723 | switch (Size) { |
| 724 | case 4: |
| 725 | return AMD_ELEMENT_4_BYTES; |
| 726 | case 8: |
| 727 | return AMD_ELEMENT_8_BYTES; |
| 728 | case 16: |
| 729 | return AMD_ELEMENT_16_BYTES; |
| 730 | default: |
| 731 | llvm_unreachable("invalid private_element_size"); |
| 732 | } |
| 733 | } |
| 734 | |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 735 | void AMDGPUAsmPrinter::EmitAmdKernelCodeT(const MachineFunction &MF, |
Tom Stellard | ff7416b | 2015-06-26 21:58:31 +0000 | [diff] [blame] | 736 | const SIProgramInfo &KernelInfo) const { |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 737 | const SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>(); |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 738 | const SISubtarget &STM = MF.getSubtarget<SISubtarget>(); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 739 | amd_kernel_code_t header; |
| 740 | |
Tom Stellard | ff7416b | 2015-06-26 21:58:31 +0000 | [diff] [blame] | 741 | AMDGPU::initDefaultAMDKernelCodeT(header, STM.getFeatureBits()); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 742 | |
| 743 | header.compute_pgm_resource_registers = |
| 744 | KernelInfo.ComputePGMRSrc1 | |
| 745 | (KernelInfo.ComputePGMRSrc2 << 32); |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 746 | header.code_properties = AMD_CODE_PROPERTY_IS_PTR64; |
| 747 | |
Matt Arsenault | 24ee078 | 2016-02-12 02:40:47 +0000 | [diff] [blame] | 748 | |
| 749 | AMD_HSA_BITS_SET(header.code_properties, |
| 750 | AMD_CODE_PROPERTY_PRIVATE_ELEMENT_SIZE, |
| 751 | getElementByteSizeValue(STM.getMaxPrivateElementSize())); |
| 752 | |
Matt Arsenault | 26f8f3d | 2015-11-30 21:16:03 +0000 | [diff] [blame] | 753 | if (MFI->hasPrivateSegmentBuffer()) { |
| 754 | header.code_properties |= |
| 755 | AMD_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_BUFFER; |
| 756 | } |
| 757 | |
| 758 | if (MFI->hasDispatchPtr()) |
| 759 | header.code_properties |= AMD_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_PTR; |
| 760 | |
| 761 | if (MFI->hasQueuePtr()) |
| 762 | header.code_properties |= AMD_CODE_PROPERTY_ENABLE_SGPR_QUEUE_PTR; |
| 763 | |
| 764 | if (MFI->hasKernargSegmentPtr()) |
| 765 | header.code_properties |= AMD_CODE_PROPERTY_ENABLE_SGPR_KERNARG_SEGMENT_PTR; |
| 766 | |
| 767 | if (MFI->hasDispatchID()) |
| 768 | header.code_properties |= AMD_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_ID; |
| 769 | |
| 770 | if (MFI->hasFlatScratchInit()) |
| 771 | header.code_properties |= AMD_CODE_PROPERTY_ENABLE_SGPR_FLAT_SCRATCH_INIT; |
| 772 | |
| 773 | // TODO: Private segment size |
| 774 | |
| 775 | if (MFI->hasGridWorkgroupCountX()) { |
| 776 | header.code_properties |= |
| 777 | AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_X; |
| 778 | } |
| 779 | |
| 780 | if (MFI->hasGridWorkgroupCountY()) { |
| 781 | header.code_properties |= |
| 782 | AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_Y; |
| 783 | } |
| 784 | |
| 785 | if (MFI->hasGridWorkgroupCountZ()) { |
| 786 | header.code_properties |= |
| 787 | AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_Z; |
| 788 | } |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 789 | |
Tom Stellard | 48f29f2 | 2015-11-26 00:43:29 +0000 | [diff] [blame] | 790 | if (MFI->hasDispatchPtr()) |
| 791 | header.code_properties |= AMD_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_PTR; |
| 792 | |
Konstantin Zhuravlyov | f2f3d14 | 2016-06-25 03:11:28 +0000 | [diff] [blame] | 793 | if (STM.debuggerSupported()) |
| 794 | header.code_properties |= AMD_CODE_PROPERTY_IS_DEBUG_SUPPORTED; |
| 795 | |
Nicolai Haehnle | 5b50497 | 2016-01-04 23:35:53 +0000 | [diff] [blame] | 796 | if (STM.isXNACKEnabled()) |
| 797 | header.code_properties |= AMD_CODE_PROPERTY_IS_XNACK_SUPPORTED; |
| 798 | |
Matt Arsenault | 52ef401 | 2016-07-26 16:45:58 +0000 | [diff] [blame] | 799 | // FIXME: Should use getKernArgSize |
Tom Stellard | e88bbc3 | 2016-09-23 01:33:26 +0000 | [diff] [blame] | 800 | header.kernarg_segment_byte_size = |
Tom Stellard | 2f3f985 | 2017-01-25 01:25:13 +0000 | [diff] [blame] | 801 | STM.getKernArgSegmentSize(MF, MFI->getABIArgOffset()); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 802 | header.wavefront_sgpr_count = KernelInfo.NumSGPR; |
| 803 | header.workitem_vgpr_count = KernelInfo.NumVGPR; |
Tom Stellard | a495307 | 2015-12-15 22:55:30 +0000 | [diff] [blame] | 804 | header.workitem_private_segment_byte_size = KernelInfo.ScratchSize; |
Tom Stellard | 7750f4e | 2015-12-15 23:15:25 +0000 | [diff] [blame] | 805 | header.workgroup_group_segment_byte_size = KernelInfo.LDSSize; |
Konstantin Zhuravlyov | 1d99c4d | 2016-04-26 15:43:14 +0000 | [diff] [blame] | 806 | header.reserved_vgpr_first = KernelInfo.ReservedVGPRFirst; |
| 807 | header.reserved_vgpr_count = KernelInfo.ReservedVGPRCount; |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 808 | |
Tom Stellard | 175959e | 2016-12-06 21:53:10 +0000 | [diff] [blame] | 809 | // These alignment values are specified in powers of two, so alignment = |
| 810 | // 2^n. The minimum alignment is 2^4 = 16. |
| 811 | header.kernarg_segment_alignment = std::max((size_t)4, |
| 812 | countTrailingZeros(MFI->getMaxKernArgAlign())); |
| 813 | |
Konstantin Zhuravlyov | f2f3d14 | 2016-06-25 03:11:28 +0000 | [diff] [blame] | 814 | if (STM.debuggerEmitPrologue()) { |
| 815 | header.debug_wavefront_private_segment_offset_sgpr = |
| 816 | KernelInfo.DebuggerWavefrontPrivateSegmentOffsetSGPR; |
| 817 | header.debug_private_segment_buffer_sgpr = |
| 818 | KernelInfo.DebuggerPrivateSegmentBufferSGPR; |
| 819 | } |
| 820 | |
Tom Stellard | fcfaea4 | 2016-05-05 17:03:33 +0000 | [diff] [blame] | 821 | OutStreamer->SwitchSection(getObjFileLowering().getTextSection()); |
Konstantin Zhuravlyov | 7498cd6 | 2017-03-22 22:32:22 +0000 | [diff] [blame] | 822 | getTargetStreamer().EmitAMDKernelCodeT(header); |
Tom Stellard | 45bb48e | 2015-06-13 03:28:10 +0000 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | bool AMDGPUAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, |
| 826 | unsigned AsmVariant, |
| 827 | const char *ExtraCode, raw_ostream &O) { |
| 828 | if (ExtraCode && ExtraCode[0]) { |
| 829 | if (ExtraCode[1] != 0) |
| 830 | return true; // Unknown modifier. |
| 831 | |
| 832 | switch (ExtraCode[0]) { |
| 833 | default: |
| 834 | // See if this is a generic print operand |
| 835 | return AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, O); |
| 836 | case 'r': |
| 837 | break; |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | AMDGPUInstPrinter::printRegOperand(MI->getOperand(OpNo).getReg(), O, |
| 842 | *TM.getSubtargetImpl(*MF->getFunction())->getRegisterInfo()); |
| 843 | return false; |
| 844 | } |