2020-01-06 11:15:44 +01:00
|
|
|
//===-- R600AsmPrinter.cpp - R600 Assembly printer ------------------------===//
|
2018-05-24 22:02:01 +02:00
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-05-24 22:02:01 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
/// \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"
|
2021-01-20 13:48:02 +01:00
|
|
|
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
|
2018-05-24 22:02:01 +02:00
|
|
|
#include "R600Defines.h"
|
|
|
|
#include "R600MachineFunctionInfo.h"
|
2021-01-20 13:48:02 +01:00
|
|
|
#include "R600Subtarget.h"
|
2018-05-24 22:02:01 +02:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-29 17:25:22 +01:00
|
|
|
OutStreamer->emitInt32(RsrcReg);
|
2020-02-15 07:40:47 +01:00
|
|
|
OutStreamer->emitIntValue(S_NUM_GPRS(MaxGPR + 1) |
|
2018-05-24 22:02:01 +02:00
|
|
|
S_STACK_SIZE(MFI->CFStackSize), 4);
|
2020-02-29 17:25:22 +01:00
|
|
|
OutStreamer->emitInt32(R_02880C_DB_SHADER_CONTROL);
|
|
|
|
OutStreamer->emitInt32(S_02880C_KILL_ENABLE(killPixel));
|
2018-05-24 22:02:01 +02:00
|
|
|
|
|
|
|
if (AMDGPU::isCompute(MF.getFunction().getCallingConv())) {
|
2020-02-29 17:25:22 +01:00
|
|
|
OutStreamer->emitInt32(R_0288E8_SQ_LDS_ALLOC);
|
2020-02-15 07:40:47 +01:00
|
|
|
OutStreamer->emitIntValue(alignTo(MFI->getLDSSize(), 4) >> 2, 4);
|
2018-05-24 22:02:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool R600AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
|
|
|
|
2018-05-31 06:08:08 +02:00
|
|
|
|
|
|
|
// Functions needs to be cacheline (256B) aligned.
|
2019-09-27 14:54:21 +02:00
|
|
|
MF.ensureAlignment(Align(256));
|
2018-05-31 06:08:08 +02:00
|
|
|
|
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);
|
|
|
|
|
2020-02-13 22:10:49 +01:00
|
|
|
emitFunctionBody();
|
2018-05-24 22:02:01 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|