mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 03:33:20 +01:00
AMDGPU: Support using tablegened MC pseudo expansions
Make the necessary refactorings to make use of PseudoInstExpansion llvm-svn: 283467
This commit is contained in:
parent
fd3556d19d
commit
0866d7f210
@ -15,10 +15,13 @@
|
|||||||
#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H
|
#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H
|
||||||
#define LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H
|
#define LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H
|
||||||
|
|
||||||
|
#include "AMDGPUMCInstLower.h"
|
||||||
|
|
||||||
#include "llvm/CodeGen/AsmPrinter.h"
|
#include "llvm/CodeGen/AsmPrinter.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
class MCOperand;
|
||||||
|
|
||||||
class AMDGPUAsmPrinter final : public AsmPrinter {
|
class AMDGPUAsmPrinter final : public AsmPrinter {
|
||||||
private:
|
private:
|
||||||
@ -120,6 +123,15 @@ public:
|
|||||||
|
|
||||||
StringRef getPassName() const override;
|
StringRef getPassName() const override;
|
||||||
|
|
||||||
|
/// \brief Wrapper for MCInstLowering.lowerOperand() for the tblgen'erated
|
||||||
|
/// pseudo lowering.
|
||||||
|
bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const;
|
||||||
|
|
||||||
|
/// \brief tblgen'erated driver function for lowering simple MI->MC pseudo
|
||||||
|
/// instructions.
|
||||||
|
bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
|
||||||
|
const MachineInstr *MI);
|
||||||
|
|
||||||
/// Implemented in AMDGPUMCInstLower.cpp
|
/// Implemented in AMDGPUMCInstLower.cpp
|
||||||
void EmitInstruction(const MachineInstr *MI) override;
|
void EmitInstruction(const MachineInstr *MI) override;
|
||||||
|
|
||||||
|
@ -36,6 +36,9 @@
|
|||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
|
#include "AMDGPUGenMCPseudoLowering.inc"
|
||||||
|
|
||||||
|
|
||||||
AMDGPUMCInstLower::AMDGPUMCInstLower(MCContext &ctx, const AMDGPUSubtarget &st,
|
AMDGPUMCInstLower::AMDGPUMCInstLower(MCContext &ctx, const AMDGPUSubtarget &st,
|
||||||
const AsmPrinter &ap):
|
const AsmPrinter &ap):
|
||||||
Ctx(ctx), ST(st), AP(ap) { }
|
Ctx(ctx), ST(st), AP(ap) { }
|
||||||
@ -68,6 +71,43 @@ const MCExpr *AMDGPUMCInstLower::getLongBranchBlockExpr(
|
|||||||
return MCBinaryExpr::createSub(SrcBBSym, DestBBSym, Ctx);
|
return MCBinaryExpr::createSub(SrcBBSym, DestBBSym, Ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AMDGPUMCInstLower::lowerOperand(const MachineOperand &MO,
|
||||||
|
MCOperand &MCOp) const {
|
||||||
|
switch (MO.getType()) {
|
||||||
|
default:
|
||||||
|
llvm_unreachable("unknown operand type");
|
||||||
|
case MachineOperand::MO_Immediate:
|
||||||
|
MCOp = MCOperand::createImm(MO.getImm());
|
||||||
|
return true;
|
||||||
|
case MachineOperand::MO_Register:
|
||||||
|
MCOp = MCOperand::createReg(AMDGPU::getMCReg(MO.getReg(), ST));
|
||||||
|
return true;
|
||||||
|
case MachineOperand::MO_MachineBasicBlock:
|
||||||
|
MCOp = MCOperand::createExpr(MCSymbolRefExpr::create(
|
||||||
|
MO.getMBB()->getSymbol(), Ctx));
|
||||||
|
return true;
|
||||||
|
case MachineOperand::MO_GlobalAddress: {
|
||||||
|
const GlobalValue *GV = MO.getGlobal();
|
||||||
|
SmallString<128> SymbolName;
|
||||||
|
AP.getNameWithPrefix(SymbolName, GV);
|
||||||
|
MCSymbol *Sym = Ctx.getOrCreateSymbol(SymbolName);
|
||||||
|
const MCExpr *SymExpr =
|
||||||
|
MCSymbolRefExpr::create(Sym, getVariantKind(MO.getTargetFlags()),Ctx);
|
||||||
|
const MCExpr *Expr = MCBinaryExpr::createAdd(SymExpr,
|
||||||
|
MCConstantExpr::create(MO.getOffset(), Ctx), Ctx);
|
||||||
|
MCOp = MCOperand::createExpr(Expr);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case MachineOperand::MO_ExternalSymbol: {
|
||||||
|
MCSymbol *Sym = Ctx.getOrCreateSymbol(StringRef(MO.getSymbolName()));
|
||||||
|
Sym->setExternal(true);
|
||||||
|
const MCSymbolRefExpr *Expr = MCSymbolRefExpr::create(Sym, Ctx);
|
||||||
|
MCOp = MCOperand::createExpr(Expr);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AMDGPUMCInstLower::lower(const MachineInstr *MI, MCInst &OutMI) const {
|
void AMDGPUMCInstLower::lower(const MachineInstr *MI, MCInst &OutMI) const {
|
||||||
|
|
||||||
int MCOpcode = ST.getInstrInfo()->pseudoToMCOpcode(MI->getOpcode());
|
int MCOpcode = ST.getInstrInfo()->pseudoToMCOpcode(MI->getOpcode());
|
||||||
@ -82,54 +122,22 @@ void AMDGPUMCInstLower::lower(const MachineInstr *MI, MCInst &OutMI) const {
|
|||||||
|
|
||||||
for (const MachineOperand &MO : MI->explicit_operands()) {
|
for (const MachineOperand &MO : MI->explicit_operands()) {
|
||||||
MCOperand MCOp;
|
MCOperand MCOp;
|
||||||
switch (MO.getType()) {
|
lowerOperand(MO, MCOp);
|
||||||
default:
|
|
||||||
llvm_unreachable("unknown operand type");
|
|
||||||
case MachineOperand::MO_Immediate:
|
|
||||||
MCOp = MCOperand::createImm(MO.getImm());
|
|
||||||
break;
|
|
||||||
case MachineOperand::MO_Register:
|
|
||||||
MCOp = MCOperand::createReg(AMDGPU::getMCReg(MO.getReg(), ST));
|
|
||||||
break;
|
|
||||||
case MachineOperand::MO_MachineBasicBlock:
|
|
||||||
if (MO.getTargetFlags() != 0) {
|
|
||||||
MCOp = MCOperand::createExpr(
|
|
||||||
getLongBranchBlockExpr(*MI->getParent(), MO));
|
|
||||||
} else {
|
|
||||||
MCOp = MCOperand::createExpr(
|
|
||||||
MCSymbolRefExpr::create(MO.getMBB()->getSymbol(), Ctx));
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
case MachineOperand::MO_GlobalAddress: {
|
|
||||||
const GlobalValue *GV = MO.getGlobal();
|
|
||||||
SmallString<128> SymbolName;
|
|
||||||
AP.getNameWithPrefix(SymbolName, GV);
|
|
||||||
MCSymbol *Sym = Ctx.getOrCreateSymbol(SymbolName);
|
|
||||||
const MCExpr *SymExpr =
|
|
||||||
MCSymbolRefExpr::create(Sym, getVariantKind(MO.getTargetFlags()),Ctx);
|
|
||||||
const MCExpr *Expr = MCBinaryExpr::createAdd(SymExpr,
|
|
||||||
MCConstantExpr::create(MO.getOffset(), Ctx), Ctx);
|
|
||||||
MCOp = MCOperand::createExpr(Expr);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case MachineOperand::MO_ExternalSymbol: {
|
|
||||||
MCSymbol *Sym = Ctx.getOrCreateSymbol(StringRef(MO.getSymbolName()));
|
|
||||||
Sym->setExternal(true);
|
|
||||||
const MCSymbolRefExpr *Expr = MCSymbolRefExpr::create(Sym, Ctx);
|
|
||||||
MCOp = MCOperand::createExpr(Expr);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case MachineOperand::MO_MCSymbol:
|
|
||||||
MCOp = MCOperand::createExpr(
|
|
||||||
MCSymbolRefExpr::create(MO.getMCSymbol(), Ctx));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
OutMI.addOperand(MCOp);
|
OutMI.addOperand(MCOp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AMDGPUAsmPrinter::lowerOperand(const MachineOperand &MO,
|
||||||
|
MCOperand &MCOp) const {
|
||||||
|
const AMDGPUSubtarget &STI = MF->getSubtarget<AMDGPUSubtarget>();
|
||||||
|
AMDGPUMCInstLower MCInstLowering(OutContext, STI, *this);
|
||||||
|
return MCInstLowering.lowerOperand(MO, MCOp);
|
||||||
|
}
|
||||||
|
|
||||||
void AMDGPUAsmPrinter::EmitInstruction(const MachineInstr *MI) {
|
void AMDGPUAsmPrinter::EmitInstruction(const MachineInstr *MI) {
|
||||||
|
if (emitPseudoExpansionLowering(*OutStreamer, MI))
|
||||||
|
return;
|
||||||
|
|
||||||
const AMDGPUSubtarget &STI = MF->getSubtarget<AMDGPUSubtarget>();
|
const AMDGPUSubtarget &STI = MF->getSubtarget<AMDGPUSubtarget>();
|
||||||
AMDGPUMCInstLower MCInstLowering(OutContext, STI, *this);
|
AMDGPUMCInstLower MCInstLowering(OutContext, STI, *this);
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ class MachineOperand;
|
|||||||
class MCContext;
|
class MCContext;
|
||||||
class MCExpr;
|
class MCExpr;
|
||||||
class MCInst;
|
class MCInst;
|
||||||
|
class MCOperand;
|
||||||
|
|
||||||
class AMDGPUMCInstLower {
|
class AMDGPUMCInstLower {
|
||||||
MCContext &Ctx;
|
MCContext &Ctx;
|
||||||
@ -33,6 +34,8 @@ public:
|
|||||||
AMDGPUMCInstLower(MCContext &ctx, const AMDGPUSubtarget &ST,
|
AMDGPUMCInstLower(MCContext &ctx, const AMDGPUSubtarget &ST,
|
||||||
const AsmPrinter &AP);
|
const AsmPrinter &AP);
|
||||||
|
|
||||||
|
bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const;
|
||||||
|
|
||||||
/// \brief Lower a MachineInstr to an MCInst
|
/// \brief Lower a MachineInstr to an MCInst
|
||||||
void lower(const MachineInstr *MI, MCInst &OutMI) const;
|
void lower(const MachineInstr *MI, MCInst &OutMI) const;
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ tablegen(LLVM AMDGPUGenDFAPacketizer.inc -gen-dfa-packetizer)
|
|||||||
tablegen(LLVM AMDGPUGenAsmWriter.inc -gen-asm-writer)
|
tablegen(LLVM AMDGPUGenAsmWriter.inc -gen-asm-writer)
|
||||||
tablegen(LLVM AMDGPUGenAsmMatcher.inc -gen-asm-matcher)
|
tablegen(LLVM AMDGPUGenAsmMatcher.inc -gen-asm-matcher)
|
||||||
tablegen(LLVM AMDGPUGenDisassemblerTables.inc -gen-disassembler)
|
tablegen(LLVM AMDGPUGenDisassemblerTables.inc -gen-disassembler)
|
||||||
|
tablegen(LLVM AMDGPUGenMCPseudoLowering.inc -gen-pseudo-lowering)
|
||||||
add_public_tablegen_target(AMDGPUCommonTableGen)
|
add_public_tablegen_target(AMDGPUCommonTableGen)
|
||||||
|
|
||||||
# List of all GlobalISel files.
|
# List of all GlobalISel files.
|
||||||
|
Loading…
Reference in New Issue
Block a user