2012-12-12 05:25:42 +08:00
|
|
|
//===-- AMDGPUAsmPrinter.cpp - AMDGPU Assebly printer --------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
/// \file
|
|
|
|
///
|
|
|
|
/// The AMDGPUAsmPrinter is used to print both assembly string and also binary
|
|
|
|
/// code. When passed an MCAsmStreamer it prints assembly and when passed
|
|
|
|
/// an MCObjectStreamer it outputs binary code.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "AMDGPUAsmPrinter.h"
|
2017-03-27 22:04:01 +08:00
|
|
|
#include "AMDGPUTargetMachine.h"
|
2015-06-27 05:15:07 +08:00
|
|
|
#include "MCTargetDesc/AMDGPUTargetStreamer.h"
|
2015-04-08 09:09:26 +08:00
|
|
|
#include "InstPrinter/AMDGPUInstPrinter.h"
|
2015-06-27 05:15:07 +08:00
|
|
|
#include "Utils/AMDGPUBaseInfo.h"
|
2012-12-12 05:25:42 +08:00
|
|
|
#include "AMDGPU.h"
|
2014-06-13 09:32:00 +08:00
|
|
|
#include "AMDGPUSubtarget.h"
|
2013-05-07 01:50:51 +08:00
|
|
|
#include "R600Defines.h"
|
2013-04-24 01:34:12 +08:00
|
|
|
#include "R600MachineFunctionInfo.h"
|
2013-04-17 23:17:25 +08:00
|
|
|
#include "R600RegisterInfo.h"
|
2013-05-24 01:10:37 +08:00
|
|
|
#include "SIDefines.h"
|
|
|
|
#include "SIMachineFunctionInfo.h"
|
2016-06-21 01:51:32 +08:00
|
|
|
#include "SIInstrInfo.h"
|
2013-05-24 01:10:37 +08:00
|
|
|
#include "SIRegisterInfo.h"
|
2014-07-21 23:45:01 +08:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2016-06-21 02:13:04 +08:00
|
|
|
#include "llvm/IR/DiagnosticInfo.h"
|
2013-04-16 01:51:30 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
|
|
|
#include "llvm/MC/MCSectionELF.h"
|
2012-12-12 05:25:42 +08:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2013-04-16 01:51:30 +08:00
|
|
|
#include "llvm/Support/ELF.h"
|
2013-06-28 23:47:08 +08:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
2012-12-12 05:25:42 +08:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2013-01-02 18:22:59 +08:00
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
2012-12-12 05:25:42 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-06-27 01:22:30 +08:00
|
|
|
// TODO: This should get the default rounding mode from the kernel. We just set
|
|
|
|
// the default here, but this could change if the OpenCL rounding mode pragmas
|
|
|
|
// are used.
|
|
|
|
//
|
|
|
|
// The denormal mode here should match what is reported by the OpenCL runtime
|
|
|
|
// for the CL_FP_DENORM bit from CL_DEVICE_{HALF|SINGLE|DOUBLE}_FP_CONFIG, but
|
|
|
|
// can also be override to flush with the -cl-denorms-are-zero compiler flag.
|
|
|
|
//
|
|
|
|
// AMD OpenCL only sets flush none and reports CL_FP_DENORM for double
|
|
|
|
// precision, and leaves single precision to flush all and does not report
|
|
|
|
// CL_FP_DENORM for CL_DEVICE_SINGLE_FP_CONFIG. Mesa's OpenCL currently reports
|
|
|
|
// CL_FP_DENORM for both.
|
2014-07-15 07:40:43 +08:00
|
|
|
//
|
|
|
|
// FIXME: It seems some instructions do not support single precision denormals
|
|
|
|
// regardless of the mode (exp_*_f32, rcp_*_f32, rsq_*_f32, rsq_*f32, sqrt_f32,
|
|
|
|
// and sin_f32, cos_f32 on most parts).
|
|
|
|
|
|
|
|
// We want to use these instructions, and using fp32 denormals also causes
|
|
|
|
// instructions to run at the double precision rate for the device so it's
|
|
|
|
// probably best to just report no single precision denormals.
|
2014-07-15 07:40:49 +08:00
|
|
|
static uint32_t getFPMode(const MachineFunction &F) {
|
2016-06-24 14:30:11 +08:00
|
|
|
const SISubtarget& ST = F.getSubtarget<SISubtarget>();
|
2014-07-15 07:40:49 +08:00
|
|
|
// TODO: Is there any real use for the flush in only / flush out only modes?
|
|
|
|
|
|
|
|
uint32_t FP32Denormals =
|
|
|
|
ST.hasFP32Denormals() ? FP_DENORM_FLUSH_NONE : FP_DENORM_FLUSH_IN_FLUSH_OUT;
|
|
|
|
|
|
|
|
uint32_t FP64Denormals =
|
|
|
|
ST.hasFP64Denormals() ? FP_DENORM_FLUSH_NONE : FP_DENORM_FLUSH_IN_FLUSH_OUT;
|
|
|
|
|
2014-06-27 01:22:30 +08:00
|
|
|
return FP_ROUND_MODE_SP(FP_ROUND_ROUND_TO_NEAREST) |
|
|
|
|
FP_ROUND_MODE_DP(FP_ROUND_ROUND_TO_NEAREST) |
|
2014-07-15 07:40:49 +08:00
|
|
|
FP_DENORM_MODE_SP(FP32Denormals) |
|
|
|
|
FP_DENORM_MODE_DP(FP64Denormals);
|
2014-06-27 01:22:30 +08:00
|
|
|
}
|
2012-12-12 05:25:42 +08:00
|
|
|
|
2015-01-19 04:29:04 +08:00
|
|
|
static AsmPrinter *
|
|
|
|
createAMDGPUAsmPrinterPass(TargetMachine &tm,
|
|
|
|
std::unique_ptr<MCStreamer> &&Streamer) {
|
|
|
|
return new AMDGPUAsmPrinter(tm, std::move(Streamer));
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
|
|
|
|
2015-06-13 11:28:10 +08:00
|
|
|
extern "C" void LLVMInitializeAMDGPUAsmPrinter() {
|
2016-10-10 07:00:34 +08:00
|
|
|
TargetRegistry::RegisterAsmPrinter(getTheAMDGPUTarget(),
|
|
|
|
createAMDGPUAsmPrinterPass);
|
|
|
|
TargetRegistry::RegisterAsmPrinter(getTheGCNTarget(),
|
|
|
|
createAMDGPUAsmPrinterPass);
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
|
|
|
|
2015-01-19 04:29:04 +08:00
|
|
|
AMDGPUAsmPrinter::AMDGPUAsmPrinter(TargetMachine &TM,
|
|
|
|
std::unique_ptr<MCStreamer> Streamer)
|
2017-03-27 22:04:01 +08:00
|
|
|
: AsmPrinter(TM, std::move(Streamer)) {
|
|
|
|
AMDGPUASI = static_cast<AMDGPUTargetMachine*>(&TM)->getAMDGPUAS();
|
|
|
|
}
|
2013-10-12 13:02:51 +08:00
|
|
|
|
2016-10-01 10:56:57 +08:00
|
|
|
StringRef AMDGPUAsmPrinter::getPassName() const {
|
2016-07-23 01:01:25 +08:00
|
|
|
return "AMDGPU Assembly Printer";
|
|
|
|
}
|
|
|
|
|
2017-03-23 06:32:22 +08:00
|
|
|
const MCSubtargetInfo* AMDGPUAsmPrinter::getSTI() const {
|
|
|
|
return TM.getMCSubtargetInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
AMDGPUTargetStreamer& AMDGPUAsmPrinter::getTargetStreamer() const {
|
|
|
|
return static_cast<AMDGPUTargetStreamer&>(*OutStreamer->getTargetStreamer());
|
|
|
|
}
|
|
|
|
|
2016-01-13 01:18:17 +08:00
|
|
|
void AMDGPUAsmPrinter::EmitStartOfAsmFile(Module &M) {
|
|
|
|
if (TM.getTargetTriple().getOS() != Triple::AMDHSA)
|
|
|
|
return;
|
|
|
|
|
2017-03-23 06:32:22 +08:00
|
|
|
AMDGPU::IsaInfo::IsaVersion ISA =
|
|
|
|
AMDGPU::IsaInfo::getIsaVersion(getSTI()->getFeatureBits());
|
2016-01-13 01:18:17 +08:00
|
|
|
|
2017-03-23 06:32:22 +08:00
|
|
|
getTargetStreamer().EmitDirectiveHSACodeObjectVersion(2, 1);
|
|
|
|
getTargetStreamer().EmitDirectiveHSACodeObjectISA(
|
|
|
|
ISA.Major, ISA.Minor, ISA.Stepping, "AMD", "AMDGPU");
|
2017-03-23 07:27:09 +08:00
|
|
|
getTargetStreamer().EmitStartOfCodeObjectMetadata(M);
|
2017-03-23 06:32:22 +08:00
|
|
|
}
|
2016-05-06 01:03:33 +08:00
|
|
|
|
2017-03-23 06:32:22 +08:00
|
|
|
void AMDGPUAsmPrinter::EmitEndOfAsmFile(Module &M) {
|
|
|
|
if (TM.getTargetTriple().getOS() != Triple::AMDHSA)
|
|
|
|
return;
|
2016-11-11 05:18:49 +08:00
|
|
|
|
2017-03-23 07:27:09 +08:00
|
|
|
getTargetStreamer().EmitEndOfCodeObjectMetadata();
|
2016-01-13 01:18:17 +08:00
|
|
|
}
|
|
|
|
|
2016-10-07 00:20:41 +08:00
|
|
|
bool AMDGPUAsmPrinter::isBlockOnlyReachableByFallthrough(
|
|
|
|
const MachineBasicBlock *MBB) const {
|
|
|
|
if (!AsmPrinter::isBlockOnlyReachableByFallthrough(MBB))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (MBB->empty())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// If this is a block implementing a long branch, an expression relative to
|
|
|
|
// the start of the block is needed. to the start of the block.
|
|
|
|
// XXX - Is there a smarter way to check this?
|
|
|
|
return (MBB->back().getOpcode() != AMDGPU::S_SETPC_B64);
|
|
|
|
}
|
|
|
|
|
2015-06-27 05:14:58 +08:00
|
|
|
void AMDGPUAsmPrinter::EmitFunctionBodyStart() {
|
|
|
|
const AMDGPUSubtarget &STM = MF->getSubtarget<AMDGPUSubtarget>();
|
|
|
|
SIProgramInfo KernelInfo;
|
2017-03-23 06:54:39 +08:00
|
|
|
amd_kernel_code_t KernelCode;
|
2017-01-25 09:25:13 +08:00
|
|
|
if (STM.isAmdCodeObjectV2(*MF)) {
|
2015-06-27 05:14:58 +08:00
|
|
|
getSIProgramInfo(KernelInfo, *MF);
|
2017-03-23 06:54:39 +08:00
|
|
|
getAmdKernelCode(KernelCode, KernelInfo, *MF);
|
|
|
|
|
|
|
|
OutStreamer->SwitchSection(getObjFileLowering().getTextSection());
|
|
|
|
getTargetStreamer().EmitAMDKernelCodeT(KernelCode);
|
2015-06-27 05:14:58 +08:00
|
|
|
}
|
2017-03-23 06:32:22 +08:00
|
|
|
|
|
|
|
if (TM.getTargetTriple().getOS() != Triple::AMDHSA)
|
|
|
|
return;
|
2017-03-23 06:54:39 +08:00
|
|
|
getTargetStreamer().EmitKernelCodeObjectMetadata(*MF->getFunction(),
|
|
|
|
KernelCode);
|
2015-06-27 05:14:58 +08:00
|
|
|
}
|
|
|
|
|
2015-11-06 19:45:14 +08:00
|
|
|
void AMDGPUAsmPrinter::EmitFunctionEntryLabel() {
|
|
|
|
const SIMachineFunctionInfo *MFI = MF->getInfo<SIMachineFunctionInfo>();
|
|
|
|
const AMDGPUSubtarget &STM = MF->getSubtarget<AMDGPUSubtarget>();
|
2017-03-31 07:58:04 +08:00
|
|
|
if (MFI->isEntryFunction() && STM.isAmdCodeObjectV2(*MF)) {
|
2016-09-27 01:29:25 +08:00
|
|
|
SmallString<128> SymbolName;
|
|
|
|
getNameWithPrefix(SymbolName, MF->getFunction()),
|
2017-03-23 06:32:22 +08:00
|
|
|
getTargetStreamer().EmitAMDGPUSymbolType(
|
|
|
|
SymbolName, ELF::STT_AMDGPU_HSA_KERNEL);
|
2015-11-06 19:45:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
AsmPrinter::EmitFunctionEntryLabel();
|
|
|
|
}
|
|
|
|
|
2015-12-03 01:00:42 +08:00
|
|
|
void AMDGPUAsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
|
|
|
|
|
2015-12-03 03:47:57 +08:00
|
|
|
// Group segment variables aren't emitted in HSA.
|
2017-03-27 22:04:01 +08:00
|
|
|
if (AMDGPU::isGroupSegment(GV, AMDGPUASI))
|
2015-12-03 03:47:57 +08:00
|
|
|
return;
|
|
|
|
|
2016-05-06 01:03:33 +08:00
|
|
|
AsmPrinter::EmitGlobalVariable(GV);
|
2015-12-03 01:00:42 +08:00
|
|
|
}
|
|
|
|
|
2012-12-12 05:25:42 +08:00
|
|
|
bool AMDGPUAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
2014-10-04 03:02:02 +08:00
|
|
|
|
|
|
|
// The starting address of all shader programs must be 256 bytes aligned.
|
|
|
|
MF.setAlignment(8);
|
|
|
|
|
2012-12-12 05:25:42 +08:00
|
|
|
SetupMachineFunction(MF);
|
2013-12-05 13:15:35 +08:00
|
|
|
|
2017-01-07 01:02:10 +08:00
|
|
|
const AMDGPUSubtarget &STM = MF.getSubtarget<AMDGPUSubtarget>();
|
2013-10-12 13:02:51 +08:00
|
|
|
MCContext &Context = getObjFileLowering().getContext();
|
2017-01-07 01:02:10 +08:00
|
|
|
if (!STM.isAmdHsaOS()) {
|
|
|
|
MCSectionELF *ConfigSection =
|
|
|
|
Context.getELFSection(".AMDGPU.config", ELF::SHT_PROGBITS, 0);
|
|
|
|
OutStreamer->SwitchSection(ConfigSection);
|
|
|
|
}
|
2013-12-05 13:15:35 +08:00
|
|
|
|
|
|
|
SIProgramInfo KernelInfo;
|
2015-06-27 05:14:58 +08:00
|
|
|
if (STM.getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS) {
|
2015-08-15 08:12:39 +08:00
|
|
|
getSIProgramInfo(KernelInfo, MF);
|
2015-06-27 05:14:58 +08:00
|
|
|
if (!STM.isAmdHsaOS()) {
|
|
|
|
EmitProgramInfoSI(MF, KernelInfo);
|
|
|
|
}
|
2013-04-17 23:17:25 +08:00
|
|
|
} else {
|
|
|
|
EmitProgramInfoR600(MF);
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
2013-10-12 13:02:51 +08:00
|
|
|
|
|
|
|
DisasmLines.clear();
|
|
|
|
HexLines.clear();
|
|
|
|
DisasmLineMaxLen = 0;
|
|
|
|
|
2012-12-12 05:25:42 +08:00
|
|
|
EmitFunctionBody();
|
2013-10-12 13:02:51 +08:00
|
|
|
|
2014-02-01 06:08:19 +08:00
|
|
|
if (isVerbose()) {
|
2015-05-22 03:20:38 +08:00
|
|
|
MCSectionELF *CommentSection =
|
2015-01-30 01:33:21 +08:00
|
|
|
Context.getELFSection(".AMDGPU.csdata", ELF::SHT_PROGBITS, 0);
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->SwitchSection(CommentSection);
|
2013-12-05 13:15:35 +08:00
|
|
|
|
2014-04-16 06:40:47 +08:00
|
|
|
if (STM.getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS) {
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->emitRawComment(" Kernel info:", false);
|
|
|
|
OutStreamer->emitRawComment(" codeLenInByte = " + Twine(KernelInfo.CodeLen),
|
|
|
|
false);
|
|
|
|
OutStreamer->emitRawComment(" NumSgprs: " + Twine(KernelInfo.NumSGPR),
|
|
|
|
false);
|
|
|
|
OutStreamer->emitRawComment(" NumVgprs: " + Twine(KernelInfo.NumVGPR),
|
|
|
|
false);
|
|
|
|
OutStreamer->emitRawComment(" FloatMode: " + Twine(KernelInfo.FloatMode),
|
|
|
|
false);
|
|
|
|
OutStreamer->emitRawComment(" IeeeMode: " + Twine(KernelInfo.IEEEMode),
|
|
|
|
false);
|
|
|
|
OutStreamer->emitRawComment(" ScratchSize: " + Twine(KernelInfo.ScratchSize),
|
|
|
|
false);
|
2016-04-15 06:11:51 +08:00
|
|
|
OutStreamer->emitRawComment(" LDSByteSize: " + Twine(KernelInfo.LDSSize) +
|
|
|
|
" bytes/workgroup (compile time only)", false);
|
2015-11-05 13:27:07 +08:00
|
|
|
|
2016-09-07 04:22:28 +08:00
|
|
|
OutStreamer->emitRawComment(" SGPRBlocks: " +
|
|
|
|
Twine(KernelInfo.SGPRBlocks), false);
|
|
|
|
OutStreamer->emitRawComment(" VGPRBlocks: " +
|
|
|
|
Twine(KernelInfo.VGPRBlocks), false);
|
|
|
|
|
|
|
|
OutStreamer->emitRawComment(" NumSGPRsForWavesPerEU: " +
|
|
|
|
Twine(KernelInfo.NumSGPRsForWavesPerEU), false);
|
|
|
|
OutStreamer->emitRawComment(" NumVGPRsForWavesPerEU: " +
|
|
|
|
Twine(KernelInfo.NumVGPRsForWavesPerEU), false);
|
|
|
|
|
2016-04-26 23:43:14 +08:00
|
|
|
OutStreamer->emitRawComment(" ReservedVGPRFirst: " + Twine(KernelInfo.ReservedVGPRFirst),
|
|
|
|
false);
|
|
|
|
OutStreamer->emitRawComment(" ReservedVGPRCount: " + Twine(KernelInfo.ReservedVGPRCount),
|
|
|
|
false);
|
|
|
|
|
2016-06-25 11:11:28 +08:00
|
|
|
if (MF.getSubtarget<SISubtarget>().debuggerEmitPrologue()) {
|
|
|
|
OutStreamer->emitRawComment(" DebuggerWavefrontPrivateSegmentOffsetSGPR: s" +
|
|
|
|
Twine(KernelInfo.DebuggerWavefrontPrivateSegmentOffsetSGPR), false);
|
|
|
|
OutStreamer->emitRawComment(" DebuggerPrivateSegmentBufferSGPR: s" +
|
|
|
|
Twine(KernelInfo.DebuggerPrivateSegmentBufferSGPR), false);
|
|
|
|
}
|
|
|
|
|
2015-11-05 13:27:07 +08:00
|
|
|
OutStreamer->emitRawComment(" COMPUTE_PGM_RSRC2:USER_SGPR: " +
|
2015-11-11 08:27:46 +08:00
|
|
|
Twine(G_00B84C_USER_SGPR(KernelInfo.ComputePGMRSrc2)),
|
|
|
|
false);
|
2017-02-10 10:15:29 +08:00
|
|
|
OutStreamer->emitRawComment(" COMPUTE_PGM_RSRC2:TRAP_HANDLER: " +
|
|
|
|
Twine(G_00B84C_TRAP_HANDLER(KernelInfo.ComputePGMRSrc2)),
|
|
|
|
false);
|
2015-11-11 08:27:46 +08:00
|
|
|
OutStreamer->emitRawComment(" COMPUTE_PGM_RSRC2:TGID_X_EN: " +
|
|
|
|
Twine(G_00B84C_TGID_X_EN(KernelInfo.ComputePGMRSrc2)),
|
|
|
|
false);
|
|
|
|
OutStreamer->emitRawComment(" COMPUTE_PGM_RSRC2:TGID_Y_EN: " +
|
|
|
|
Twine(G_00B84C_TGID_Y_EN(KernelInfo.ComputePGMRSrc2)),
|
2015-11-05 13:27:07 +08:00
|
|
|
false);
|
2015-11-11 08:27:46 +08:00
|
|
|
OutStreamer->emitRawComment(" COMPUTE_PGM_RSRC2:TGID_Z_EN: " +
|
|
|
|
Twine(G_00B84C_TGID_Z_EN(KernelInfo.ComputePGMRSrc2)),
|
|
|
|
false);
|
|
|
|
OutStreamer->emitRawComment(" COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: " +
|
|
|
|
Twine(G_00B84C_TIDIG_COMP_CNT(KernelInfo.ComputePGMRSrc2)),
|
|
|
|
false);
|
|
|
|
|
2014-01-23 05:55:35 +08:00
|
|
|
} else {
|
|
|
|
R600MachineFunctionInfo *MFI = MF.getInfo<R600MachineFunctionInfo>();
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->emitRawComment(
|
2016-07-23 01:01:25 +08:00
|
|
|
Twine("SQ_PGM_RESOURCES:STACK_SIZE = " + Twine(MFI->CFStackSize)));
|
2014-01-23 05:55:35 +08:00
|
|
|
}
|
2013-12-05 13:15:35 +08:00
|
|
|
}
|
|
|
|
|
2015-02-19 09:10:49 +08:00
|
|
|
if (STM.dumpCode()) {
|
2015-01-07 01:59:56 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->SwitchSection(
|
2015-01-30 01:33:21 +08:00
|
|
|
Context.getELFSection(".AMDGPU.disasm", ELF::SHT_NOTE, 0));
|
2015-01-07 01:59:56 +08:00
|
|
|
|
|
|
|
for (size_t i = 0; i < DisasmLines.size(); ++i) {
|
|
|
|
std::string Comment(DisasmLineMaxLen - DisasmLines[i].size(), ' ');
|
|
|
|
Comment += " ; " + HexLines[i] + "\n";
|
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitBytes(StringRef(DisasmLines[i]));
|
|
|
|
OutStreamer->EmitBytes(StringRef(Comment));
|
2013-10-12 13:02:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-12 05:25:42 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-13 11:06:43 +08:00
|
|
|
void AMDGPUAsmPrinter::EmitProgramInfoR600(const MachineFunction &MF) {
|
2013-04-17 23:17:25 +08:00
|
|
|
unsigned MaxGPR = 0;
|
2013-04-30 08:13:13 +08:00
|
|
|
bool killPixel = false;
|
2016-06-24 14:30:11 +08:00
|
|
|
const R600Subtarget &STM = MF.getSubtarget<R600Subtarget>();
|
|
|
|
const R600RegisterInfo *RI = STM.getRegisterInfo();
|
2014-07-13 11:06:43 +08:00
|
|
|
const R600MachineFunctionInfo *MFI = MF.getInfo<R600MachineFunctionInfo>();
|
2013-04-17 23:17:25 +08:00
|
|
|
|
2014-07-13 11:06:43 +08:00
|
|
|
for (const MachineBasicBlock &MBB : MF) {
|
|
|
|
for (const MachineInstr &MI : MBB) {
|
2013-04-30 08:13:13 +08:00
|
|
|
if (MI.getOpcode() == AMDGPU::KILLGT)
|
|
|
|
killPixel = true;
|
2013-04-17 23:17:25 +08:00
|
|
|
unsigned numOperands = MI.getNumOperands();
|
|
|
|
for (unsigned op_idx = 0; op_idx < numOperands; op_idx++) {
|
2014-07-13 11:06:43 +08:00
|
|
|
const MachineOperand &MO = MI.getOperand(op_idx);
|
2013-04-17 23:17:25 +08:00
|
|
|
if (!MO.isReg())
|
|
|
|
continue;
|
|
|
|
unsigned HWReg = RI->getEncodingValue(MO.getReg()) & 0xff;
|
|
|
|
|
|
|
|
// Register with value > 127 aren't GPR
|
|
|
|
if (HWReg > 127)
|
|
|
|
continue;
|
|
|
|
MaxGPR = std::max(MaxGPR, HWReg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-07 01:50:51 +08:00
|
|
|
|
|
|
|
unsigned RsrcReg;
|
2016-06-24 14:30:11 +08:00
|
|
|
if (STM.getGeneration() >= R600Subtarget::EVERGREEN) {
|
2013-05-07 01:50:51 +08:00
|
|
|
// Evergreen / Northern Islands
|
2016-04-07 03:40:20 +08:00
|
|
|
switch (MF.getFunction()->getCallingConv()) {
|
2016-08-18 04:30:52 +08:00
|
|
|
default: LLVM_FALLTHROUGH;
|
2016-04-07 03:40:20 +08:00
|
|
|
case CallingConv::AMDGPU_CS: RsrcReg = R_0288D4_SQ_PGM_RESOURCES_LS; break;
|
|
|
|
case CallingConv::AMDGPU_GS: RsrcReg = R_028878_SQ_PGM_RESOURCES_GS; break;
|
|
|
|
case CallingConv::AMDGPU_PS: RsrcReg = R_028844_SQ_PGM_RESOURCES_PS; break;
|
|
|
|
case CallingConv::AMDGPU_VS: RsrcReg = R_028860_SQ_PGM_RESOURCES_VS; break;
|
2013-05-07 01:50:51 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// R600 / R700
|
2016-04-07 03:40:20 +08:00
|
|
|
switch (MF.getFunction()->getCallingConv()) {
|
2016-08-18 04:30:52 +08:00
|
|
|
default: LLVM_FALLTHROUGH;
|
|
|
|
case CallingConv::AMDGPU_GS: LLVM_FALLTHROUGH;
|
|
|
|
case CallingConv::AMDGPU_CS: LLVM_FALLTHROUGH;
|
2016-04-07 03:40:20 +08:00
|
|
|
case CallingConv::AMDGPU_VS: RsrcReg = R_028868_SQ_PGM_RESOURCES_VS; break;
|
|
|
|
case CallingConv::AMDGPU_PS: RsrcReg = R_028850_SQ_PGM_RESOURCES_PS; break;
|
2013-05-07 01:50:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitIntValue(RsrcReg, 4);
|
|
|
|
OutStreamer->EmitIntValue(S_NUM_GPRS(MaxGPR + 1) |
|
2016-07-23 01:01:25 +08:00
|
|
|
S_STACK_SIZE(MFI->CFStackSize), 4);
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitIntValue(R_02880C_DB_SHADER_CONTROL, 4);
|
|
|
|
OutStreamer->EmitIntValue(S_02880C_KILL_ENABLE(killPixel), 4);
|
2013-06-28 23:47:08 +08:00
|
|
|
|
2016-04-07 03:40:20 +08:00
|
|
|
if (AMDGPU::isCompute(MF.getFunction()->getCallingConv())) {
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitIntValue(R_0288E8_SQ_LDS_ALLOC, 4);
|
2016-07-27 00:45:58 +08:00
|
|
|
OutStreamer->EmitIntValue(alignTo(MFI->getLDSSize(), 4) >> 2, 4);
|
2013-06-28 23:47:08 +08:00
|
|
|
}
|
2013-04-17 23:17:25 +08:00
|
|
|
}
|
|
|
|
|
2014-04-16 06:40:47 +08:00
|
|
|
void AMDGPUAsmPrinter::getSIProgramInfo(SIProgramInfo &ProgInfo,
|
2014-07-13 11:06:43 +08:00
|
|
|
const MachineFunction &MF) const {
|
2016-06-24 14:30:11 +08:00
|
|
|
const SISubtarget &STM = MF.getSubtarget<SISubtarget>();
|
2014-12-03 05:28:53 +08:00
|
|
|
const SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>();
|
2014-04-16 06:40:47 +08:00
|
|
|
uint64_t CodeSize = 0;
|
2012-12-12 05:25:42 +08:00
|
|
|
unsigned MaxSGPR = 0;
|
|
|
|
unsigned MaxVGPR = 0;
|
|
|
|
bool VCCUsed = false;
|
2014-09-15 23:41:53 +08:00
|
|
|
bool FlatUsed = false;
|
2016-06-24 14:30:11 +08:00
|
|
|
const SIRegisterInfo *RI = STM.getRegisterInfo();
|
|
|
|
const SIInstrInfo *TII = STM.getInstrInfo();
|
2012-12-12 05:25:42 +08:00
|
|
|
|
2014-07-13 11:06:43 +08:00
|
|
|
for (const MachineBasicBlock &MBB : MF) {
|
|
|
|
for (const MachineInstr &MI : MBB) {
|
2014-04-16 06:40:47 +08:00
|
|
|
// TODO: CodeSize should account for multiple functions.
|
2015-08-12 17:04:44 +08:00
|
|
|
|
|
|
|
// TODO: Should we count size of debug info?
|
|
|
|
if (MI.isDebugValue())
|
|
|
|
continue;
|
|
|
|
|
2016-10-06 18:13:23 +08:00
|
|
|
if (isVerbose())
|
|
|
|
CodeSize += TII->getInstSizeInBytes(MI);
|
2014-04-16 06:40:47 +08:00
|
|
|
|
2012-12-12 05:25:42 +08:00
|
|
|
unsigned numOperands = MI.getNumOperands();
|
|
|
|
for (unsigned op_idx = 0; op_idx < numOperands; op_idx++) {
|
2014-07-13 11:06:43 +08:00
|
|
|
const MachineOperand &MO = MI.getOperand(op_idx);
|
2012-12-12 05:25:42 +08:00
|
|
|
unsigned width = 0;
|
|
|
|
bool isSGPR = false;
|
2014-01-09 05:47:14 +08:00
|
|
|
|
2015-10-02 05:51:59 +08:00
|
|
|
if (!MO.isReg())
|
2012-12-12 05:25:42 +08:00
|
|
|
continue;
|
2015-10-02 05:51:59 +08:00
|
|
|
|
2014-01-09 05:47:14 +08:00
|
|
|
unsigned reg = MO.getReg();
|
2015-10-02 05:51:59 +08:00
|
|
|
switch (reg) {
|
|
|
|
case AMDGPU::EXEC:
|
2016-04-20 05:58:17 +08:00
|
|
|
case AMDGPU::EXEC_LO:
|
|
|
|
case AMDGPU::EXEC_HI:
|
2015-10-02 05:51:59 +08:00
|
|
|
case AMDGPU::SCC:
|
|
|
|
case AMDGPU::M0:
|
2017-02-19 02:29:53 +08:00
|
|
|
case AMDGPU::SRC_SHARED_BASE:
|
|
|
|
case AMDGPU::SRC_SHARED_LIMIT:
|
|
|
|
case AMDGPU::SRC_PRIVATE_BASE:
|
|
|
|
case AMDGPU::SRC_PRIVATE_LIMIT:
|
2015-10-02 05:51:59 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
case AMDGPU::VCC:
|
|
|
|
case AMDGPU::VCC_LO:
|
|
|
|
case AMDGPU::VCC_HI:
|
2012-12-12 05:25:42 +08:00
|
|
|
VCCUsed = true;
|
|
|
|
continue;
|
2015-10-02 05:51:59 +08:00
|
|
|
|
|
|
|
case AMDGPU::FLAT_SCR:
|
|
|
|
case AMDGPU::FLAT_SCR_LO:
|
|
|
|
case AMDGPU::FLAT_SCR_HI:
|
2016-12-10 03:49:48 +08:00
|
|
|
// Even if FLAT_SCRATCH is implicitly used, it has no effect if flat
|
|
|
|
// instructions aren't used to access the scratch buffer.
|
|
|
|
if (MFI->hasFlatScratchInit())
|
|
|
|
FlatUsed = true;
|
2014-09-15 23:41:53 +08:00
|
|
|
continue;
|
2013-10-23 05:11:31 +08:00
|
|
|
|
2016-04-14 00:18:41 +08:00
|
|
|
case AMDGPU::TBA:
|
|
|
|
case AMDGPU::TBA_LO:
|
|
|
|
case AMDGPU::TBA_HI:
|
|
|
|
case AMDGPU::TMA:
|
|
|
|
case AMDGPU::TMA_LO:
|
|
|
|
case AMDGPU::TMA_HI:
|
2016-07-27 05:03:36 +08:00
|
|
|
llvm_unreachable("trap handler registers should not be used");
|
2016-04-14 00:18:41 +08:00
|
|
|
|
2015-10-02 05:51:59 +08:00
|
|
|
default:
|
|
|
|
break;
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (AMDGPU::SReg_32RegClass.contains(reg)) {
|
2016-07-27 05:03:36 +08:00
|
|
|
assert(!AMDGPU::TTMP_32RegClass.contains(reg) &&
|
|
|
|
"trap handler registers should not be used");
|
2012-12-12 05:25:42 +08:00
|
|
|
isSGPR = true;
|
|
|
|
width = 1;
|
2015-01-08 04:59:25 +08:00
|
|
|
} else if (AMDGPU::VGPR_32RegClass.contains(reg)) {
|
2012-12-12 05:25:42 +08:00
|
|
|
isSGPR = false;
|
|
|
|
width = 1;
|
|
|
|
} else if (AMDGPU::SReg_64RegClass.contains(reg)) {
|
2016-07-27 05:03:36 +08:00
|
|
|
assert(!AMDGPU::TTMP_64RegClass.contains(reg) &&
|
|
|
|
"trap handler registers should not be used");
|
2012-12-12 05:25:42 +08:00
|
|
|
isSGPR = true;
|
|
|
|
width = 2;
|
|
|
|
} else if (AMDGPU::VReg_64RegClass.contains(reg)) {
|
|
|
|
isSGPR = false;
|
|
|
|
width = 2;
|
2013-04-10 16:39:16 +08:00
|
|
|
} else if (AMDGPU::VReg_96RegClass.contains(reg)) {
|
|
|
|
isSGPR = false;
|
|
|
|
width = 3;
|
2012-12-12 05:25:42 +08:00
|
|
|
} else if (AMDGPU::SReg_128RegClass.contains(reg)) {
|
|
|
|
isSGPR = true;
|
|
|
|
width = 4;
|
|
|
|
} else if (AMDGPU::VReg_128RegClass.contains(reg)) {
|
|
|
|
isSGPR = false;
|
|
|
|
width = 4;
|
|
|
|
} else if (AMDGPU::SReg_256RegClass.contains(reg)) {
|
|
|
|
isSGPR = true;
|
|
|
|
width = 8;
|
2013-02-08 01:02:09 +08:00
|
|
|
} else if (AMDGPU::VReg_256RegClass.contains(reg)) {
|
|
|
|
isSGPR = false;
|
|
|
|
width = 8;
|
2013-10-23 08:44:12 +08:00
|
|
|
} else if (AMDGPU::SReg_512RegClass.contains(reg)) {
|
|
|
|
isSGPR = true;
|
|
|
|
width = 16;
|
2013-02-08 01:02:09 +08:00
|
|
|
} else if (AMDGPU::VReg_512RegClass.contains(reg)) {
|
|
|
|
isSGPR = false;
|
|
|
|
width = 16;
|
2012-12-12 05:25:42 +08:00
|
|
|
} else {
|
2013-12-11 05:37:42 +08:00
|
|
|
llvm_unreachable("Unknown register class");
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
2014-01-09 05:47:14 +08:00
|
|
|
unsigned hwReg = RI->getEncodingValue(reg) & 0xff;
|
|
|
|
unsigned maxUsed = hwReg + width - 1;
|
2012-12-12 05:25:42 +08:00
|
|
|
if (isSGPR) {
|
|
|
|
MaxSGPR = maxUsed > MaxSGPR ? maxUsed : MaxSGPR;
|
|
|
|
} else {
|
|
|
|
MaxVGPR = maxUsed > MaxVGPR ? maxUsed : MaxVGPR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-05 13:15:35 +08:00
|
|
|
|
AMDGPU/SI: xnack_mask is always reserved on VI
Summary:
Somehow, I first interpreted the docs as saying space for xnack_mask is only
reserved when XNACK is enabled via SH_MEM_CONFIG. I felt uneasy about this and
went back to actually test what is happening, and it turns out that xnack_mask
is always reserved at least on Tonga and Carrizo, in the sense that flat_scr
is always fixed below the SGPRs that are used to implement xnack_mask, whether
or not they are actually used.
I confirmed this by writing a shader using inline assembly to tease out the
aliasing between flat_scratch and regular SGPRs. For example, on Tonga, where
we fix the number of SGPRs to 80, s[74:75] aliases flat_scratch (so
xnack_mask is s[76:77] and vcc is s[78:79]).
This patch changes both the calculation of the total number of SGPRs and the
various register reservations to account for this.
It ought to be possible to use the gap left by xnack_mask when the feature
isn't used, but this patch doesn't try to do that. (Note that the same applies
to vcc.)
Note that previously, even before my earlier change in r256794, the SGPRs that
alias to xnack_mask could end up being used as well when flat_scr was unused
and the total number of SGPRs happened to fall on the right alignment
(e.g. highest regular SGPR being used s29 and VCC used would lead to number
of SGPRs being 32, where s28 and s29 alias with xnack_mask). So if there
were some conflict due to such aliasing, we should have noticed that already.
Reviewers: arsenm, tstellarAMD
Subscribers: arsenm, llvm-commits
Differential Revision: http://reviews.llvm.org/D15898
llvm-svn: 257073
2016-01-08 01:10:20 +08:00
|
|
|
unsigned ExtraSGPRs = 0;
|
2013-12-05 13:15:35 +08:00
|
|
|
|
AMDGPU/SI: xnack_mask is always reserved on VI
Summary:
Somehow, I first interpreted the docs as saying space for xnack_mask is only
reserved when XNACK is enabled via SH_MEM_CONFIG. I felt uneasy about this and
went back to actually test what is happening, and it turns out that xnack_mask
is always reserved at least on Tonga and Carrizo, in the sense that flat_scr
is always fixed below the SGPRs that are used to implement xnack_mask, whether
or not they are actually used.
I confirmed this by writing a shader using inline assembly to tease out the
aliasing between flat_scratch and regular SGPRs. For example, on Tonga, where
we fix the number of SGPRs to 80, s[74:75] aliases flat_scratch (so
xnack_mask is s[76:77] and vcc is s[78:79]).
This patch changes both the calculation of the total number of SGPRs and the
various register reservations to account for this.
It ought to be possible to use the gap left by xnack_mask when the feature
isn't used, but this patch doesn't try to do that. (Note that the same applies
to vcc.)
Note that previously, even before my earlier change in r256794, the SGPRs that
alias to xnack_mask could end up being used as well when flat_scr was unused
and the total number of SGPRs happened to fall on the right alignment
(e.g. highest regular SGPR being used s29 and VCC used would lead to number
of SGPRs being 32, where s28 and s29 alias with xnack_mask). So if there
were some conflict due to such aliasing, we should have noticed that already.
Reviewers: arsenm, tstellarAMD
Subscribers: arsenm, llvm-commits
Differential Revision: http://reviews.llvm.org/D15898
llvm-svn: 257073
2016-01-08 01:10:20 +08:00
|
|
|
if (VCCUsed)
|
|
|
|
ExtraSGPRs = 2;
|
2016-01-05 07:35:53 +08:00
|
|
|
|
2016-06-24 14:30:11 +08:00
|
|
|
if (STM.getGeneration() < SISubtarget::VOLCANIC_ISLANDS) {
|
AMDGPU/SI: xnack_mask is always reserved on VI
Summary:
Somehow, I first interpreted the docs as saying space for xnack_mask is only
reserved when XNACK is enabled via SH_MEM_CONFIG. I felt uneasy about this and
went back to actually test what is happening, and it turns out that xnack_mask
is always reserved at least on Tonga and Carrizo, in the sense that flat_scr
is always fixed below the SGPRs that are used to implement xnack_mask, whether
or not they are actually used.
I confirmed this by writing a shader using inline assembly to tease out the
aliasing between flat_scratch and regular SGPRs. For example, on Tonga, where
we fix the number of SGPRs to 80, s[74:75] aliases flat_scratch (so
xnack_mask is s[76:77] and vcc is s[78:79]).
This patch changes both the calculation of the total number of SGPRs and the
various register reservations to account for this.
It ought to be possible to use the gap left by xnack_mask when the feature
isn't used, but this patch doesn't try to do that. (Note that the same applies
to vcc.)
Note that previously, even before my earlier change in r256794, the SGPRs that
alias to xnack_mask could end up being used as well when flat_scr was unused
and the total number of SGPRs happened to fall on the right alignment
(e.g. highest regular SGPR being used s29 and VCC used would lead to number
of SGPRs being 32, where s28 and s29 alias with xnack_mask). So if there
were some conflict due to such aliasing, we should have noticed that already.
Reviewers: arsenm, tstellarAMD
Subscribers: arsenm, llvm-commits
Differential Revision: http://reviews.llvm.org/D15898
llvm-svn: 257073
2016-01-08 01:10:20 +08:00
|
|
|
if (FlatUsed)
|
|
|
|
ExtraSGPRs = 4;
|
|
|
|
} else {
|
2016-01-05 07:35:53 +08:00
|
|
|
if (STM.isXNACKEnabled())
|
AMDGPU/SI: xnack_mask is always reserved on VI
Summary:
Somehow, I first interpreted the docs as saying space for xnack_mask is only
reserved when XNACK is enabled via SH_MEM_CONFIG. I felt uneasy about this and
went back to actually test what is happening, and it turns out that xnack_mask
is always reserved at least on Tonga and Carrizo, in the sense that flat_scr
is always fixed below the SGPRs that are used to implement xnack_mask, whether
or not they are actually used.
I confirmed this by writing a shader using inline assembly to tease out the
aliasing between flat_scratch and regular SGPRs. For example, on Tonga, where
we fix the number of SGPRs to 80, s[74:75] aliases flat_scratch (so
xnack_mask is s[76:77] and vcc is s[78:79]).
This patch changes both the calculation of the total number of SGPRs and the
various register reservations to account for this.
It ought to be possible to use the gap left by xnack_mask when the feature
isn't used, but this patch doesn't try to do that. (Note that the same applies
to vcc.)
Note that previously, even before my earlier change in r256794, the SGPRs that
alias to xnack_mask could end up being used as well when flat_scr was unused
and the total number of SGPRs happened to fall on the right alignment
(e.g. highest regular SGPR being used s29 and VCC used would lead to number
of SGPRs being 32, where s28 and s29 alias with xnack_mask). So if there
were some conflict due to such aliasing, we should have noticed that already.
Reviewers: arsenm, tstellarAMD
Subscribers: arsenm, llvm-commits
Differential Revision: http://reviews.llvm.org/D15898
llvm-svn: 257073
2016-01-08 01:10:20 +08:00
|
|
|
ExtraSGPRs = 4;
|
|
|
|
|
|
|
|
if (FlatUsed)
|
|
|
|
ExtraSGPRs = 6;
|
2015-12-18 01:05:09 +08:00
|
|
|
}
|
2014-09-15 23:41:53 +08:00
|
|
|
|
2017-02-08 21:02:33 +08:00
|
|
|
unsigned ExtraVGPRs = STM.getReservedNumVGPRs(MF);
|
2016-06-25 11:11:28 +08:00
|
|
|
|
2016-12-10 03:49:40 +08:00
|
|
|
// Check the addressable register limit before we add ExtraSGPRs.
|
|
|
|
if (STM.getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS &&
|
|
|
|
!STM.hasSGPRInitBug()) {
|
2017-02-08 21:02:33 +08:00
|
|
|
unsigned MaxAddressableNumSGPRs = STM.getAddressableNumSGPRs();
|
2016-12-10 03:49:40 +08:00
|
|
|
if (MaxSGPR + 1 > MaxAddressableNumSGPRs) {
|
|
|
|
// This can happen due to a compiler bug or when using inline asm.
|
|
|
|
LLVMContext &Ctx = MF.getFunction()->getContext();
|
|
|
|
DiagnosticInfoResourceLimit Diag(*MF.getFunction(),
|
|
|
|
"addressable scalar registers",
|
|
|
|
MaxSGPR + 1, DS_Error,
|
2017-02-08 22:05:23 +08:00
|
|
|
DK_ResourceLimit,
|
|
|
|
MaxAddressableNumSGPRs);
|
2016-12-10 03:49:40 +08:00
|
|
|
Ctx.diagnose(Diag);
|
|
|
|
MaxSGPR = MaxAddressableNumSGPRs - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-07 04:22:28 +08:00
|
|
|
// Account for extra SGPRs and VGPRs reserved for debugger use.
|
|
|
|
MaxSGPR += ExtraSGPRs;
|
2017-02-08 21:02:33 +08:00
|
|
|
MaxVGPR += ExtraVGPRs;
|
2016-09-07 04:22:28 +08:00
|
|
|
|
2014-09-12 06:51:37 +08:00
|
|
|
// We found the maximum register index. They start at 0, so add one to get the
|
|
|
|
// number of registers.
|
|
|
|
ProgInfo.NumSGPR = MaxSGPR + 1;
|
2017-02-08 21:02:33 +08:00
|
|
|
ProgInfo.NumVGPR = MaxVGPR + 1;
|
2014-06-27 01:22:30 +08:00
|
|
|
|
2016-09-07 04:22:28 +08:00
|
|
|
// Adjust number of registers used to meet default/requested minimum/maximum
|
|
|
|
// number of waves per execution unit request.
|
|
|
|
ProgInfo.NumSGPRsForWavesPerEU = std::max(
|
2017-02-08 21:02:33 +08:00
|
|
|
ProgInfo.NumSGPR, STM.getMinNumSGPRs(MFI->getMaxWavesPerEU()));
|
2016-09-07 04:22:28 +08:00
|
|
|
ProgInfo.NumVGPRsForWavesPerEU = std::max(
|
2017-02-08 21:02:33 +08:00
|
|
|
ProgInfo.NumVGPR, STM.getMinNumVGPRs(MFI->getMaxWavesPerEU()));
|
2016-09-07 04:22:28 +08:00
|
|
|
|
2016-12-10 03:49:40 +08:00
|
|
|
if (STM.getGeneration() <= AMDGPUSubtarget::SEA_ISLANDS ||
|
|
|
|
STM.hasSGPRInitBug()) {
|
2017-02-08 22:05:23 +08:00
|
|
|
unsigned MaxAddressableNumSGPRs = STM.getAddressableNumSGPRs();
|
|
|
|
if (ProgInfo.NumSGPR > MaxAddressableNumSGPRs) {
|
|
|
|
// This can happen due to a compiler bug or when using inline asm to use
|
|
|
|
// the registers which are usually reserved for vcc etc.
|
2016-12-10 03:49:40 +08:00
|
|
|
LLVMContext &Ctx = MF.getFunction()->getContext();
|
|
|
|
DiagnosticInfoResourceLimit Diag(*MF.getFunction(),
|
|
|
|
"scalar registers",
|
|
|
|
ProgInfo.NumSGPR, DS_Error,
|
2017-02-08 22:05:23 +08:00
|
|
|
DK_ResourceLimit,
|
|
|
|
MaxAddressableNumSGPRs);
|
2016-12-10 03:49:40 +08:00
|
|
|
Ctx.diagnose(Diag);
|
2017-02-08 22:05:23 +08:00
|
|
|
ProgInfo.NumSGPR = MaxAddressableNumSGPRs;
|
|
|
|
ProgInfo.NumSGPRsForWavesPerEU = MaxAddressableNumSGPRs;
|
2016-12-10 03:49:40 +08:00
|
|
|
}
|
2016-10-29 04:31:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (STM.hasSGPRInitBug()) {
|
2017-02-08 22:05:23 +08:00
|
|
|
ProgInfo.NumSGPR =
|
|
|
|
AMDGPU::IsaInfo::FIXED_NUM_SGPRS_FOR_INIT_BUG;
|
|
|
|
ProgInfo.NumSGPRsForWavesPerEU =
|
|
|
|
AMDGPU::IsaInfo::FIXED_NUM_SGPRS_FOR_INIT_BUG;
|
2015-03-09 23:48:09 +08:00
|
|
|
}
|
|
|
|
|
2015-12-01 05:16:07 +08:00
|
|
|
if (MFI->NumUserSGPRs > STM.getMaxNumUserSGPRs()) {
|
|
|
|
LLVMContext &Ctx = MF.getFunction()->getContext();
|
2016-06-21 02:13:04 +08:00
|
|
|
DiagnosticInfoResourceLimit Diag(*MF.getFunction(), "user SGPRs",
|
|
|
|
MFI->NumUserSGPRs, DS_Error);
|
|
|
|
Ctx.diagnose(Diag);
|
2015-12-01 05:16:07 +08:00
|
|
|
}
|
|
|
|
|
2016-07-27 00:45:58 +08:00
|
|
|
if (MFI->getLDSSize() > static_cast<unsigned>(STM.getLocalMemorySize())) {
|
2016-04-29 03:37:35 +08:00
|
|
|
LLVMContext &Ctx = MF.getFunction()->getContext();
|
2016-06-21 02:13:04 +08:00
|
|
|
DiagnosticInfoResourceLimit Diag(*MF.getFunction(), "local memory",
|
2016-07-27 00:45:58 +08:00
|
|
|
MFI->getLDSSize(), DS_Error);
|
2016-06-21 02:13:04 +08:00
|
|
|
Ctx.diagnose(Diag);
|
2016-04-29 03:37:35 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:22:28 +08:00
|
|
|
// SGPRBlocks is actual number of SGPR blocks minus 1.
|
|
|
|
ProgInfo.SGPRBlocks = alignTo(ProgInfo.NumSGPRsForWavesPerEU,
|
2017-02-08 21:18:40 +08:00
|
|
|
STM.getSGPREncodingGranule());
|
|
|
|
ProgInfo.SGPRBlocks = ProgInfo.SGPRBlocks / STM.getSGPREncodingGranule() - 1;
|
2016-09-07 04:22:28 +08:00
|
|
|
|
|
|
|
// VGPRBlocks is actual number of VGPR blocks minus 1.
|
|
|
|
ProgInfo.VGPRBlocks = alignTo(ProgInfo.NumVGPRsForWavesPerEU,
|
2017-02-08 21:18:40 +08:00
|
|
|
STM.getVGPREncodingGranule());
|
|
|
|
ProgInfo.VGPRBlocks = ProgInfo.VGPRBlocks / STM.getVGPREncodingGranule() - 1;
|
2017-02-08 21:02:33 +08:00
|
|
|
|
2017-02-08 22:05:23 +08:00
|
|
|
// Record first reserved VGPR and number of reserved VGPRs.
|
2017-02-08 21:02:33 +08:00
|
|
|
ProgInfo.ReservedVGPRFirst = STM.debuggerReserveRegs() ? MaxVGPR + 1 : 0;
|
|
|
|
ProgInfo.ReservedVGPRCount = STM.getReservedNumVGPRs(MF);
|
|
|
|
|
|
|
|
// Update DebuggerWavefrontPrivateSegmentOffsetSGPR and
|
|
|
|
// DebuggerPrivateSegmentBufferSGPR fields if "amdgpu-debugger-emit-prologue"
|
|
|
|
// attribute was requested.
|
|
|
|
if (STM.debuggerEmitPrologue()) {
|
|
|
|
ProgInfo.DebuggerWavefrontPrivateSegmentOffsetSGPR =
|
|
|
|
RI->getHWRegIndex(MFI->getScratchWaveOffsetReg());
|
|
|
|
ProgInfo.DebuggerPrivateSegmentBufferSGPR =
|
|
|
|
RI->getHWRegIndex(MFI->getScratchRSrcReg());
|
|
|
|
}
|
2016-09-07 04:22:28 +08:00
|
|
|
|
2014-06-27 01:22:30 +08:00
|
|
|
// Set the value to initialize FP_ROUND and FP_DENORM parts of the mode
|
|
|
|
// register.
|
|
|
|
ProgInfo.FloatMode = getFPMode(MF);
|
|
|
|
|
2016-10-20 06:34:49 +08:00
|
|
|
ProgInfo.IEEEMode = STM.enableIEEEBit(MF);
|
2014-06-27 01:22:30 +08:00
|
|
|
|
2016-01-29 04:53:35 +08:00
|
|
|
// Make clamp modifier on NaN input returns 0.
|
2017-02-22 07:35:48 +08:00
|
|
|
ProgInfo.DX10Clamp = STM.enableDX10Clamp();
|
2014-06-27 01:22:30 +08:00
|
|
|
|
2016-07-29 02:40:00 +08:00
|
|
|
const MachineFrameInfo &FrameInfo = MF.getFrameInfo();
|
|
|
|
ProgInfo.ScratchSize = FrameInfo.getStackSize();
|
2014-07-21 23:45:01 +08:00
|
|
|
|
2014-09-15 23:41:53 +08:00
|
|
|
ProgInfo.FlatUsed = FlatUsed;
|
|
|
|
ProgInfo.VCCUsed = VCCUsed;
|
2014-06-27 01:22:30 +08:00
|
|
|
ProgInfo.CodeLen = CodeSize;
|
2013-04-16 01:51:35 +08:00
|
|
|
|
2013-10-30 00:37:28 +08:00
|
|
|
unsigned LDSAlignShift;
|
2016-06-24 14:30:11 +08:00
|
|
|
if (STM.getGeneration() < SISubtarget::SEA_ISLANDS) {
|
2014-06-27 01:22:30 +08:00
|
|
|
// LDS is allocated in 64 dword blocks.
|
2013-10-30 00:37:28 +08:00
|
|
|
LDSAlignShift = 8;
|
|
|
|
} else {
|
2014-06-27 01:22:30 +08:00
|
|
|
// LDS is allocated in 128 dword blocks.
|
2013-10-30 00:37:28 +08:00
|
|
|
LDSAlignShift = 9;
|
|
|
|
}
|
2014-06-27 01:22:30 +08:00
|
|
|
|
2016-09-07 04:22:28 +08:00
|
|
|
unsigned LDSSpillSize =
|
|
|
|
MFI->LDSWaveSpillSize * MFI->getMaxFlatWorkGroupSize();
|
2014-09-24 09:33:17 +08:00
|
|
|
|
2016-07-27 00:45:58 +08:00
|
|
|
ProgInfo.LDSSize = MFI->getLDSSize() + LDSSpillSize;
|
2014-12-03 05:28:53 +08:00
|
|
|
ProgInfo.LDSBlocks =
|
2016-03-31 05:30:00 +08:00
|
|
|
alignTo(ProgInfo.LDSSize, 1ULL << LDSAlignShift) >> LDSAlignShift;
|
2013-10-30 00:37:28 +08:00
|
|
|
|
2014-07-21 23:45:01 +08:00
|
|
|
// Scratch is allocated in 256 dword blocks.
|
|
|
|
unsigned ScratchAlignShift = 10;
|
|
|
|
// We need to program the hardware with the amount of scratch memory that
|
2014-12-03 05:28:53 +08:00
|
|
|
// is used by the entire wave. ProgInfo.ScratchSize is the amount of
|
2014-07-21 23:45:01 +08:00
|
|
|
// scratch memory used per thread.
|
2014-12-03 05:28:53 +08:00
|
|
|
ProgInfo.ScratchBlocks =
|
2016-01-15 05:06:47 +08:00
|
|
|
alignTo(ProgInfo.ScratchSize * STM.getWavefrontSize(),
|
2016-03-31 05:30:00 +08:00
|
|
|
1ULL << ScratchAlignShift) >>
|
2016-01-15 05:06:47 +08:00
|
|
|
ScratchAlignShift;
|
2014-07-21 23:45:01 +08:00
|
|
|
|
2014-12-03 05:28:53 +08:00
|
|
|
ProgInfo.ComputePGMRSrc1 =
|
|
|
|
S_00B848_VGPRS(ProgInfo.VGPRBlocks) |
|
|
|
|
S_00B848_SGPRS(ProgInfo.SGPRBlocks) |
|
|
|
|
S_00B848_PRIORITY(ProgInfo.Priority) |
|
|
|
|
S_00B848_FLOAT_MODE(ProgInfo.FloatMode) |
|
|
|
|
S_00B848_PRIV(ProgInfo.Priv) |
|
|
|
|
S_00B848_DX10_CLAMP(ProgInfo.DX10Clamp) |
|
2015-12-01 05:16:03 +08:00
|
|
|
S_00B848_DEBUG_MODE(ProgInfo.DebugMode) |
|
2014-12-03 05:28:53 +08:00
|
|
|
S_00B848_IEEE_MODE(ProgInfo.IEEEMode);
|
|
|
|
|
2015-12-01 05:16:03 +08:00
|
|
|
// 0 = X, 1 = XY, 2 = XYZ
|
|
|
|
unsigned TIDIGCompCnt = 0;
|
|
|
|
if (MFI->hasWorkItemIDZ())
|
|
|
|
TIDIGCompCnt = 2;
|
|
|
|
else if (MFI->hasWorkItemIDY())
|
|
|
|
TIDIGCompCnt = 1;
|
|
|
|
|
2014-12-03 05:28:53 +08:00
|
|
|
ProgInfo.ComputePGMRSrc2 =
|
|
|
|
S_00B84C_SCRATCH_EN(ProgInfo.ScratchBlocks > 0) |
|
2015-12-01 05:16:03 +08:00
|
|
|
S_00B84C_USER_SGPR(MFI->getNumUserSGPRs()) |
|
2017-02-10 10:15:29 +08:00
|
|
|
S_00B84C_TRAP_HANDLER(STM.isTrapHandlerEnabled()) |
|
2015-12-01 05:16:03 +08:00
|
|
|
S_00B84C_TGID_X_EN(MFI->hasWorkGroupIDX()) |
|
|
|
|
S_00B84C_TGID_Y_EN(MFI->hasWorkGroupIDY()) |
|
|
|
|
S_00B84C_TGID_Z_EN(MFI->hasWorkGroupIDZ()) |
|
|
|
|
S_00B84C_TG_SIZE_EN(MFI->hasWorkGroupInfo()) |
|
|
|
|
S_00B84C_TIDIG_COMP_CNT(TIDIGCompCnt) |
|
|
|
|
S_00B84C_EXCP_EN_MSB(0) |
|
|
|
|
S_00B84C_LDS_SIZE(ProgInfo.LDSBlocks) |
|
|
|
|
S_00B84C_EXCP_EN(0);
|
2014-12-03 05:28:53 +08:00
|
|
|
}
|
|
|
|
|
2016-04-07 03:40:20 +08:00
|
|
|
static unsigned getRsrcReg(CallingConv::ID CallConv) {
|
|
|
|
switch (CallConv) {
|
2016-08-18 04:30:52 +08:00
|
|
|
default: LLVM_FALLTHROUGH;
|
2016-04-07 03:40:20 +08:00
|
|
|
case CallingConv::AMDGPU_CS: return R_00B848_COMPUTE_PGM_RSRC1;
|
|
|
|
case CallingConv::AMDGPU_GS: return R_00B228_SPI_SHADER_PGM_RSRC1_GS;
|
|
|
|
case CallingConv::AMDGPU_PS: return R_00B028_SPI_SHADER_PGM_RSRC1_PS;
|
|
|
|
case CallingConv::AMDGPU_VS: return R_00B128_SPI_SHADER_PGM_RSRC1_VS;
|
2014-12-03 05:28:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUAsmPrinter::EmitProgramInfoSI(const MachineFunction &MF,
|
|
|
|
const SIProgramInfo &KernelInfo) {
|
2016-06-24 14:30:11 +08:00
|
|
|
const SISubtarget &STM = MF.getSubtarget<SISubtarget>();
|
2014-12-03 05:28:53 +08:00
|
|
|
const SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>();
|
2016-04-07 03:40:20 +08:00
|
|
|
unsigned RsrcReg = getRsrcReg(MF.getFunction()->getCallingConv());
|
2014-09-20 04:42:37 +08:00
|
|
|
|
2016-04-07 03:40:20 +08:00
|
|
|
if (AMDGPU::isCompute(MF.getFunction()->getCallingConv())) {
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitIntValue(R_00B848_COMPUTE_PGM_RSRC1, 4);
|
2014-06-27 01:22:30 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitIntValue(KernelInfo.ComputePGMRSrc1, 4);
|
2014-06-27 01:22:30 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitIntValue(R_00B84C_COMPUTE_PGM_RSRC2, 4);
|
|
|
|
OutStreamer->EmitIntValue(KernelInfo.ComputePGMRSrc2, 4);
|
2014-07-21 23:45:01 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitIntValue(R_00B860_COMPUTE_TMPRING_SIZE, 4);
|
|
|
|
OutStreamer->EmitIntValue(S_00B860_WAVESIZE(KernelInfo.ScratchBlocks), 4);
|
2014-09-15 23:41:53 +08:00
|
|
|
|
|
|
|
// TODO: Should probably note flat usage somewhere. SC emits a "FlatPtr32 =
|
|
|
|
// 0" comment but I don't see a corresponding field in the register spec.
|
2014-06-27 01:22:30 +08:00
|
|
|
} else {
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitIntValue(RsrcReg, 4);
|
|
|
|
OutStreamer->EmitIntValue(S_00B028_VGPRS(KernelInfo.VGPRBlocks) |
|
|
|
|
S_00B028_SGPRS(KernelInfo.SGPRBlocks), 4);
|
2016-04-07 03:40:20 +08:00
|
|
|
if (STM.isVGPRSpillingEnabled(*MF.getFunction())) {
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitIntValue(R_0286E8_SPI_TMPRING_SIZE, 4);
|
|
|
|
OutStreamer->EmitIntValue(S_0286E8_WAVESIZE(KernelInfo.ScratchBlocks), 4);
|
2015-01-21 03:33:04 +08:00
|
|
|
}
|
2013-07-11 00:37:07 +08:00
|
|
|
}
|
2014-06-27 01:22:30 +08:00
|
|
|
|
2016-04-07 03:40:20 +08:00
|
|
|
if (MF.getFunction()->getCallingConv() == CallingConv::AMDGPU_PS) {
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitIntValue(R_00B02C_SPI_SHADER_PGM_RSRC2_PS, 4);
|
|
|
|
OutStreamer->EmitIntValue(S_00B02C_EXTRA_LDS_SIZE(KernelInfo.LDSBlocks), 4);
|
|
|
|
OutStreamer->EmitIntValue(R_0286CC_SPI_PS_INPUT_ENA, 4);
|
2017-04-12 06:29:24 +08:00
|
|
|
OutStreamer->EmitIntValue(MFI->getPSInputEnable(), 4);
|
2016-01-13 19:45:36 +08:00
|
|
|
OutStreamer->EmitIntValue(R_0286D0_SPI_PS_INPUT_ADDR, 4);
|
|
|
|
OutStreamer->EmitIntValue(MFI->getPSInputAddr(), 4);
|
2013-04-16 01:51:35 +08:00
|
|
|
}
|
2016-07-14 01:35:15 +08:00
|
|
|
|
|
|
|
OutStreamer->EmitIntValue(R_SPILLED_SGPRS, 4);
|
|
|
|
OutStreamer->EmitIntValue(MFI->getNumSpilledSGPRs(), 4);
|
|
|
|
OutStreamer->EmitIntValue(R_SPILLED_VGPRS, 4);
|
|
|
|
OutStreamer->EmitIntValue(MFI->getNumSpilledVGPRs(), 4);
|
2012-12-12 05:25:42 +08:00
|
|
|
}
|
2014-12-03 06:00:07 +08:00
|
|
|
|
2016-02-12 10:40:47 +08:00
|
|
|
// This is supposed to be log2(Size)
|
|
|
|
static amd_element_byte_size_t getElementByteSizeValue(unsigned Size) {
|
|
|
|
switch (Size) {
|
|
|
|
case 4:
|
|
|
|
return AMD_ELEMENT_4_BYTES;
|
|
|
|
case 8:
|
|
|
|
return AMD_ELEMENT_8_BYTES;
|
|
|
|
case 16:
|
|
|
|
return AMD_ELEMENT_16_BYTES;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("invalid private_element_size");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-23 06:54:39 +08:00
|
|
|
void AMDGPUAsmPrinter::getAmdKernelCode(amd_kernel_code_t &Out,
|
|
|
|
const SIProgramInfo &KernelInfo,
|
|
|
|
const MachineFunction &MF) const {
|
2014-12-03 06:00:07 +08:00
|
|
|
const SIMachineFunctionInfo *MFI = MF.getInfo<SIMachineFunctionInfo>();
|
2016-06-24 14:30:11 +08:00
|
|
|
const SISubtarget &STM = MF.getSubtarget<SISubtarget>();
|
2014-12-03 06:00:07 +08:00
|
|
|
|
2017-03-23 06:54:39 +08:00
|
|
|
AMDGPU::initDefaultAMDKernelCodeT(Out, STM.getFeatureBits());
|
2014-12-03 06:00:07 +08:00
|
|
|
|
2017-03-23 06:54:39 +08:00
|
|
|
Out.compute_pgm_resource_registers =
|
2014-12-03 06:00:07 +08:00
|
|
|
KernelInfo.ComputePGMRSrc1 |
|
|
|
|
(KernelInfo.ComputePGMRSrc2 << 32);
|
2017-03-23 06:54:39 +08:00
|
|
|
Out.code_properties = AMD_CODE_PROPERTY_IS_PTR64;
|
2016-02-12 10:40:47 +08:00
|
|
|
|
2017-03-23 06:54:39 +08:00
|
|
|
AMD_HSA_BITS_SET(Out.code_properties,
|
2016-02-12 10:40:47 +08:00
|
|
|
AMD_CODE_PROPERTY_PRIVATE_ELEMENT_SIZE,
|
|
|
|
getElementByteSizeValue(STM.getMaxPrivateElementSize()));
|
|
|
|
|
2015-12-01 05:16:03 +08:00
|
|
|
if (MFI->hasPrivateSegmentBuffer()) {
|
2017-03-23 06:54:39 +08:00
|
|
|
Out.code_properties |=
|
2015-12-01 05:16:03 +08:00
|
|
|
AMD_CODE_PROPERTY_ENABLE_SGPR_PRIVATE_SEGMENT_BUFFER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MFI->hasDispatchPtr())
|
2017-03-23 06:54:39 +08:00
|
|
|
Out.code_properties |= AMD_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_PTR;
|
2015-12-01 05:16:03 +08:00
|
|
|
|
|
|
|
if (MFI->hasQueuePtr())
|
2017-03-23 06:54:39 +08:00
|
|
|
Out.code_properties |= AMD_CODE_PROPERTY_ENABLE_SGPR_QUEUE_PTR;
|
2015-12-01 05:16:03 +08:00
|
|
|
|
|
|
|
if (MFI->hasKernargSegmentPtr())
|
2017-03-23 06:54:39 +08:00
|
|
|
Out.code_properties |= AMD_CODE_PROPERTY_ENABLE_SGPR_KERNARG_SEGMENT_PTR;
|
2015-12-01 05:16:03 +08:00
|
|
|
|
|
|
|
if (MFI->hasDispatchID())
|
2017-03-23 06:54:39 +08:00
|
|
|
Out.code_properties |= AMD_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_ID;
|
2015-12-01 05:16:03 +08:00
|
|
|
|
|
|
|
if (MFI->hasFlatScratchInit())
|
2017-03-23 06:54:39 +08:00
|
|
|
Out.code_properties |= AMD_CODE_PROPERTY_ENABLE_SGPR_FLAT_SCRATCH_INIT;
|
2015-12-01 05:16:03 +08:00
|
|
|
|
|
|
|
if (MFI->hasGridWorkgroupCountX()) {
|
2017-03-23 06:54:39 +08:00
|
|
|
Out.code_properties |=
|
2015-12-01 05:16:03 +08:00
|
|
|
AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_X;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MFI->hasGridWorkgroupCountY()) {
|
2017-03-23 06:54:39 +08:00
|
|
|
Out.code_properties |=
|
2015-12-01 05:16:03 +08:00
|
|
|
AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_Y;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MFI->hasGridWorkgroupCountZ()) {
|
2017-03-23 06:54:39 +08:00
|
|
|
Out.code_properties |=
|
2015-12-01 05:16:03 +08:00
|
|
|
AMD_CODE_PROPERTY_ENABLE_SGPR_GRID_WORKGROUP_COUNT_Z;
|
|
|
|
}
|
2014-12-03 06:00:07 +08:00
|
|
|
|
2015-11-26 08:43:29 +08:00
|
|
|
if (MFI->hasDispatchPtr())
|
2017-03-23 06:54:39 +08:00
|
|
|
Out.code_properties |= AMD_CODE_PROPERTY_ENABLE_SGPR_DISPATCH_PTR;
|
2015-11-26 08:43:29 +08:00
|
|
|
|
2016-06-25 11:11:28 +08:00
|
|
|
if (STM.debuggerSupported())
|
2017-03-23 06:54:39 +08:00
|
|
|
Out.code_properties |= AMD_CODE_PROPERTY_IS_DEBUG_SUPPORTED;
|
2016-06-25 11:11:28 +08:00
|
|
|
|
2016-01-05 07:35:53 +08:00
|
|
|
if (STM.isXNACKEnabled())
|
2017-03-23 06:54:39 +08:00
|
|
|
Out.code_properties |= AMD_CODE_PROPERTY_IS_XNACK_SUPPORTED;
|
2016-01-05 07:35:53 +08:00
|
|
|
|
2016-07-27 00:45:58 +08:00
|
|
|
// FIXME: Should use getKernArgSize
|
2017-03-23 06:54:39 +08:00
|
|
|
Out.kernarg_segment_byte_size =
|
2017-01-25 09:25:13 +08:00
|
|
|
STM.getKernArgSegmentSize(MF, MFI->getABIArgOffset());
|
2017-03-23 06:54:39 +08:00
|
|
|
Out.wavefront_sgpr_count = KernelInfo.NumSGPR;
|
|
|
|
Out.workitem_vgpr_count = KernelInfo.NumVGPR;
|
|
|
|
Out.workitem_private_segment_byte_size = KernelInfo.ScratchSize;
|
|
|
|
Out.workgroup_group_segment_byte_size = KernelInfo.LDSSize;
|
|
|
|
Out.reserved_vgpr_first = KernelInfo.ReservedVGPRFirst;
|
|
|
|
Out.reserved_vgpr_count = KernelInfo.ReservedVGPRCount;
|
2014-12-03 06:00:07 +08:00
|
|
|
|
2016-12-07 05:53:10 +08:00
|
|
|
// These alignment values are specified in powers of two, so alignment =
|
|
|
|
// 2^n. The minimum alignment is 2^4 = 16.
|
2017-03-23 06:54:39 +08:00
|
|
|
Out.kernarg_segment_alignment = std::max((size_t)4,
|
2016-12-07 05:53:10 +08:00
|
|
|
countTrailingZeros(MFI->getMaxKernArgAlign()));
|
|
|
|
|
2016-06-25 11:11:28 +08:00
|
|
|
if (STM.debuggerEmitPrologue()) {
|
2017-03-23 06:54:39 +08:00
|
|
|
Out.debug_wavefront_private_segment_offset_sgpr =
|
2016-06-25 11:11:28 +08:00
|
|
|
KernelInfo.DebuggerWavefrontPrivateSegmentOffsetSGPR;
|
2017-03-23 06:54:39 +08:00
|
|
|
Out.debug_private_segment_buffer_sgpr =
|
2016-06-25 11:11:28 +08:00
|
|
|
KernelInfo.DebuggerPrivateSegmentBufferSGPR;
|
|
|
|
}
|
2014-12-03 06:00:07 +08:00
|
|
|
}
|
2015-04-08 09:09:26 +08:00
|
|
|
|
|
|
|
bool AMDGPUAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
|
|
|
unsigned AsmVariant,
|
|
|
|
const char *ExtraCode, raw_ostream &O) {
|
|
|
|
if (ExtraCode && ExtraCode[0]) {
|
|
|
|
if (ExtraCode[1] != 0)
|
|
|
|
return true; // Unknown modifier.
|
|
|
|
|
|
|
|
switch (ExtraCode[0]) {
|
|
|
|
default:
|
|
|
|
// See if this is a generic print operand
|
|
|
|
return AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, O);
|
|
|
|
case 'r':
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AMDGPUInstPrinter::printRegOperand(MI->getOperand(OpNo).getReg(), O,
|
|
|
|
*TM.getSubtargetImpl(*MF->getFunction())->getRegisterInfo());
|
|
|
|
return false;
|
|
|
|
}
|