summaryrefslogtreecommitdiff
path: root/llvm/lib/Target/AMDGPU/AMDGPUMCInstLower.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Target/AMDGPU/AMDGPUMCInstLower.cpp')
-rw-r--r--llvm/lib/Target/AMDGPU/AMDGPUMCInstLower.cpp111
1 files changed, 10 insertions, 101 deletions
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUMCInstLower.cpp b/llvm/lib/Target/AMDGPU/AMDGPUMCInstLower.cpp
index 3dd27f1996d6..3fad7e192195 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUMCInstLower.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUMCInstLower.cpp
@@ -12,11 +12,11 @@
//===----------------------------------------------------------------------===//
//
+#include "AMDGPUMCInstLower.h"
#include "AMDGPUAsmPrinter.h"
#include "AMDGPUTargetMachine.h"
#include "MCTargetDesc/AMDGPUInstPrinter.h"
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
-#include "R600AsmPrinter.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/IR/Constants.h"
@@ -34,36 +34,6 @@
using namespace llvm;
-namespace {
-
-class AMDGPUMCInstLower {
- MCContext &Ctx;
- const TargetSubtargetInfo &ST;
- const AsmPrinter ≈
-
-public:
- AMDGPUMCInstLower(MCContext &ctx, const TargetSubtargetInfo &ST,
- const AsmPrinter &AP);
-
- bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const;
-
- /// Lower a MachineInstr to an MCInst
- void lower(const MachineInstr *MI, MCInst &OutMI) const;
-
-};
-
-class R600MCInstLower : public AMDGPUMCInstLower {
-public:
- R600MCInstLower(MCContext &ctx, const R600Subtarget &ST,
- const AsmPrinter &AP);
-
- /// Lower a MachineInstr to an MCInst
- void lower(const MachineInstr *MI, MCInst &OutMI) const;
-};
-
-
-} // End anonymous namespace
-
#include "AMDGPUGenMCPseudoLowering.inc"
AMDGPUMCInstLower::AMDGPUMCInstLower(MCContext &ctx,
@@ -150,7 +120,8 @@ void AMDGPUMCInstLower::lower(const MachineInstr *MI, MCInst &OutMI) const {
// FIXME: Should be able to handle this with emitPseudoExpansionLowering. We
// need to select it to the subtarget specific version, and there's no way to
// do that with a single pseudo source operation.
- if (Opcode == AMDGPU::S_SETPC_B64_return)
+ if (Opcode == AMDGPU::S_SETPC_B64_return ||
+ Opcode == AMDGPU::S_SETPC_B64_return_gfx)
Opcode = AMDGPU::S_SETPC_B64;
else if (Opcode == AMDGPU::SI_CALL) {
// SI_CALL is just S_SWAPPC_B64 with an additional operand to track the
@@ -194,30 +165,6 @@ bool AMDGPUAsmPrinter::lowerOperand(const MachineOperand &MO,
return MCInstLowering.lowerOperand(MO, MCOp);
}
-static const MCExpr *lowerAddrSpaceCast(const TargetMachine &TM,
- const Constant *CV,
- MCContext &OutContext) {
- // TargetMachine does not support llvm-style cast. Use C++-style cast.
- // This is safe since TM is always of type AMDGPUTargetMachine or its
- // derived class.
- auto &AT = static_cast<const AMDGPUTargetMachine&>(TM);
- auto *CE = dyn_cast<ConstantExpr>(CV);
-
- // Lower null pointers in private and local address space.
- // Clang generates addrspacecast for null pointers in private and local
- // address space, which needs to be lowered.
- if (CE && CE->getOpcode() == Instruction::AddrSpaceCast) {
- auto Op = CE->getOperand(0);
- auto SrcAddr = Op->getType()->getPointerAddressSpace();
- if (Op->isNullValue() && AT.getNullPointerValue(SrcAddr) == 0) {
- auto DstAddr = CE->getType()->getPointerAddressSpace();
- return MCConstantExpr::create(AT.getNullPointerValue(DstAddr),
- OutContext);
- }
- }
- return nullptr;
-}
-
const MCExpr *AMDGPUAsmPrinter::lowerConstant(const Constant *CV) {
if (const MCExpr *E = lowerAddrSpaceCast(TM, CV, OutContext))
return E;
@@ -267,12 +214,18 @@ void AMDGPUAsmPrinter::emitInstruction(const MachineInstr *MI) {
return;
}
+ if (MI->isMetaInstruction()) {
+ if (isVerbose())
+ OutStreamer->emitRawComment(" meta instruction");
+ return;
+ }
+
MCInst TmpInst;
MCInstLowering.lower(MI, TmpInst);
EmitToStreamer(*OutStreamer, TmpInst);
#ifdef EXPENSIVE_CHECKS
- // Sanity-check getInstSizeInBytes on explicitly specified CPUs (it cannot
+ // Check getInstSizeInBytes on explicitly specified CPUs (it cannot
// work correctly for the generic CPU).
//
// The isPseudo check really shouldn't be here, but unfortunately there are
@@ -325,47 +278,3 @@ void AMDGPUAsmPrinter::emitInstruction(const MachineInstr *MI) {
}
}
}
-
-R600MCInstLower::R600MCInstLower(MCContext &Ctx, const R600Subtarget &ST,
- const AsmPrinter &AP) :
- AMDGPUMCInstLower(Ctx, ST, AP) { }
-
-void R600MCInstLower::lower(const MachineInstr *MI, MCInst &OutMI) const {
- OutMI.setOpcode(MI->getOpcode());
- for (const MachineOperand &MO : MI->explicit_operands()) {
- MCOperand MCOp;
- lowerOperand(MO, MCOp);
- OutMI.addOperand(MCOp);
- }
-}
-
-void R600AsmPrinter::emitInstruction(const MachineInstr *MI) {
- const R600Subtarget &STI = MF->getSubtarget<R600Subtarget>();
- R600MCInstLower MCInstLowering(OutContext, STI, *this);
-
- StringRef Err;
- if (!STI.getInstrInfo()->verifyInstruction(*MI, Err)) {
- LLVMContext &C = MI->getParent()->getParent()->getFunction().getContext();
- C.emitError("Illegal instruction detected: " + Err);
- MI->print(errs());
- }
-
- if (MI->isBundle()) {
- const MachineBasicBlock *MBB = MI->getParent();
- MachineBasicBlock::const_instr_iterator I = ++MI->getIterator();
- while (I != MBB->instr_end() && I->isInsideBundle()) {
- emitInstruction(&*I);
- ++I;
- }
- } else {
- MCInst TmpInst;
- MCInstLowering.lower(MI, TmpInst);
- EmitToStreamer(*OutStreamer, TmpInst);
- }
-}
-
-const MCExpr *R600AsmPrinter::lowerConstant(const Constant *CV) {
- if (const MCExpr *E = lowerAddrSpaceCast(TM, CV, OutContext))
- return E;
- return AsmPrinter::lowerConstant(CV);
-}