2018-05-24 22:02:01 +02:00
|
|
|
//===-- R600AsmPrinter.cpp - R600 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 R600AsmPrinter 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 "R600AsmPrinter.h"
|
|
|
|
#include "AMDGPUSubtarget.h"
|
|
|
|
#include "R600Defines.h"
|
|
|
|
#include "R600MachineFunctionInfo.h"
|
|
|
|
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
|
|
|
|
#include "llvm/BinaryFormat/ELF.h"
|
|
|
|
#include "llvm/MC/MCContext.h"
|
|
|
|
#include "llvm/MC/MCSectionELF.h"
|
|
|
|
#include "llvm/MC/MCStreamer.h"
|
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
AsmPrinter *
|
|
|
|
llvm::createR600AsmPrinterPass(TargetMachine &TM,
|
|
|
|
std::unique_ptr<MCStreamer> &&Streamer) {
|
|
|
|
return new R600AsmPrinter(TM, std::move(Streamer));
|
|
|
|
}
|
|
|
|
|
|
|
|
R600AsmPrinter::R600AsmPrinter(TargetMachine &TM,
|
|
|
|
std::unique_ptr<MCStreamer> Streamer)
|
|
|
|
: AsmPrinter(TM, std::move(Streamer)) { }
|
|
|
|
|
|
|
|
StringRef R600AsmPrinter::getPassName() const {
|
|
|
|
return "R600 Assembly Printer";
|
|
|
|
}
|
|
|
|
|
|
|
|
void R600AsmPrinter::EmitProgramInfoR600(const MachineFunction &MF) {
|
|
|
|
unsigned MaxGPR = 0;
|
|
|
|
bool killPixel = false;
|
|
|
|
const R600Subtarget &STM = MF.getSubtarget<R600Subtarget>();
|
|
|
|
const R600RegisterInfo *RI = STM.getRegisterInfo();
|
|
|
|
const R600MachineFunctionInfo *MFI = MF.getInfo<R600MachineFunctionInfo>();
|
|
|
|
|
|
|
|
for (const MachineBasicBlock &MBB : MF) {
|
|
|
|
for (const MachineInstr &MI : MBB) {
|
AMDGPU: Separate R600 and GCN TableGen files
Summary:
We now have two sets of generated TableGen files, one for R600 and one
for GCN, so each sub-target now has its own tables of instructions,
registers, ISel patterns, etc. This should help reduce compile time
since each sub-target now only has to consider information that
is specific to itself. This will also help prevent the R600
sub-target from slowing down new features for GCN, like disassembler
support, GlobalISel, etc.
Reviewers: arsenm, nhaehnle, jvesely
Reviewed By: arsenm
Subscribers: MatzeB, kzhuravl, wdng, mgorny, yaxunl, dstuttard, tpr, t-tye, javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D46365
llvm-svn: 335942
2018-06-29 01:47:12 +02:00
|
|
|
if (MI.getOpcode() == R600::KILLGT)
|
2018-05-24 22:02:01 +02:00
|
|
|
killPixel = true;
|
|
|
|
unsigned numOperands = MI.getNumOperands();
|
|
|
|
for (unsigned op_idx = 0; op_idx < numOperands; op_idx++) {
|
|
|
|
const MachineOperand &MO = MI.getOperand(op_idx);
|
|
|
|
if (!MO.isReg())
|
|
|
|
continue;
|
|
|
|
unsigned HWReg = RI->getHWRegIndex(MO.getReg());
|
|
|
|
|
|
|
|
// Register with value > 127 aren't GPR
|
|
|
|
if (HWReg > 127)
|
|
|
|
continue;
|
|
|
|
MaxGPR = std::max(MaxGPR, HWReg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned RsrcReg;
|
2018-07-11 22:59:01 +02:00
|
|
|
if (STM.getGeneration() >= AMDGPUSubtarget::EVERGREEN) {
|
2018-05-24 22:02:01 +02:00
|
|
|
// Evergreen / Northern Islands
|
|
|
|
switch (MF.getFunction().getCallingConv()) {
|
|
|
|
default: LLVM_FALLTHROUGH;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// R600 / R700
|
|
|
|
switch (MF.getFunction().getCallingConv()) {
|
|
|
|
default: LLVM_FALLTHROUGH;
|
|
|
|
case CallingConv::AMDGPU_GS: LLVM_FALLTHROUGH;
|
|
|
|
case CallingConv::AMDGPU_CS: LLVM_FALLTHROUGH;
|
|
|
|
case CallingConv::AMDGPU_VS: RsrcReg = R_028868_SQ_PGM_RESOURCES_VS; break;
|
|
|
|
case CallingConv::AMDGPU_PS: RsrcReg = R_028850_SQ_PGM_RESOURCES_PS; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OutStreamer->EmitIntValue(RsrcReg, 4);
|
|
|
|
OutStreamer->EmitIntValue(S_NUM_GPRS(MaxGPR + 1) |
|
|
|
|
S_STACK_SIZE(MFI->CFStackSize), 4);
|
|
|
|
OutStreamer->EmitIntValue(R_02880C_DB_SHADER_CONTROL, 4);
|
|
|
|
OutStreamer->EmitIntValue(S_02880C_KILL_ENABLE(killPixel), 4);
|
|
|
|
|
|
|
|
if (AMDGPU::isCompute(MF.getFunction().getCallingConv())) {
|
|
|
|
OutStreamer->EmitIntValue(R_0288E8_SQ_LDS_ALLOC, 4);
|
|
|
|
OutStreamer->EmitIntValue(alignTo(MFI->getLDSSize(), 4) >> 2, 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool R600AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
|
|
|
|
2018-05-31 06:08:08 +02:00
|
|
|
|
|
|
|
// Functions needs to be cacheline (256B) aligned.
|
|
|
|
MF.ensureAlignment(8);
|
|
|
|
|
2018-05-24 22:02:01 +02:00
|
|
|
SetupMachineFunction(MF);
|
|
|
|
|
|
|
|
MCContext &Context = getObjFileLowering().getContext();
|
|
|
|
MCSectionELF *ConfigSection =
|
|
|
|
Context.getELFSection(".AMDGPU.config", ELF::SHT_PROGBITS, 0);
|
|
|
|
OutStreamer->SwitchSection(ConfigSection);
|
|
|
|
|
|
|
|
EmitProgramInfoR600(MF);
|
|
|
|
|
|
|
|
EmitFunctionBody();
|
|
|
|
|
|
|
|
if (isVerbose()) {
|
|
|
|
MCSectionELF *CommentSection =
|
|
|
|
Context.getELFSection(".AMDGPU.csdata", ELF::SHT_PROGBITS, 0);
|
|
|
|
OutStreamer->SwitchSection(CommentSection);
|
|
|
|
|
|
|
|
R600MachineFunctionInfo *MFI = MF.getInfo<R600MachineFunctionInfo>();
|
|
|
|
OutStreamer->emitRawComment(
|
|
|
|
Twine("SQ_PGM_RESOURCES:STACK_SIZE = " + Twine(MFI->CFStackSize)));
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|