2006-02-05 13:50:24 +08:00
|
|
|
//===-- SparcAsmPrinter.cpp - Sparc LLVM assembly writer ------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-02-05 13:50:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains a printer that converts from our internal representation
|
|
|
|
// of machine-dependent LLVM code to GAS-format SPARC assembly language.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Sparc.h"
|
2013-12-26 09:49:59 +08:00
|
|
|
#include "InstPrinter/SparcInstPrinter.h"
|
|
|
|
#include "MCTargetDesc/SparcMCExpr.h"
|
2014-01-07 19:48:04 +08:00
|
|
|
#include "SparcInstrInfo.h"
|
|
|
|
#include "SparcTargetMachine.h"
|
|
|
|
#include "SparcTargetStreamer.h"
|
2006-02-05 13:50:24 +08:00
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2014-01-28 10:52:26 +08:00
|
|
|
#include "llvm/CodeGen/MachineModuleInfoImpls.h"
|
2013-09-22 08:42:30 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2014-01-28 10:52:26 +08:00
|
|
|
#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
|
2014-01-08 05:19:40 +08:00
|
|
|
#include "llvm/IR/Mangler.h"
|
2009-08-23 04:48:53 +08:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2013-12-26 09:49:59 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
|
|
|
#include "llvm/MC/MCInst.h"
|
2010-02-10 08:36:00 +08:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2009-09-14 01:14:04 +08:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2011-08-25 02:08:43 +08:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2010-04-04 16:18:47 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2006-02-05 13:50:24 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 10:41:26 +08:00
|
|
|
#define DEBUG_TYPE "asm-printer"
|
|
|
|
|
2006-12-20 06:59:26 +08:00
|
|
|
namespace {
|
2009-10-25 14:33:48 +08:00
|
|
|
class SparcAsmPrinter : public AsmPrinter {
|
2013-12-26 09:49:59 +08:00
|
|
|
SparcTargetStreamer &getTargetStreamer() {
|
2014-01-14 09:21:46 +08:00
|
|
|
return static_cast<SparcTargetStreamer &>(
|
2015-04-25 03:11:51 +08:00
|
|
|
*OutStreamer->getTargetStreamer());
|
2013-12-26 09:49:59 +08:00
|
|
|
}
|
2009-02-24 16:30:20 +08:00
|
|
|
public:
|
2015-01-19 04:29:04 +08:00
|
|
|
explicit SparcAsmPrinter(TargetMachine &TM,
|
|
|
|
std::unique_ptr<MCStreamer> Streamer)
|
|
|
|
: AsmPrinter(TM, std::move(Streamer)) {}
|
2006-02-05 13:50:24 +08:00
|
|
|
|
2016-10-01 10:56:57 +08:00
|
|
|
StringRef getPassName() const override { return "Sparc Assembly Printer"; }
|
2006-02-05 13:50:24 +08:00
|
|
|
|
2010-04-04 12:47:45 +08:00
|
|
|
void printOperand(const MachineInstr *MI, int opNum, raw_ostream &OS);
|
|
|
|
void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &OS,
|
2014-04-25 13:30:21 +08:00
|
|
|
const char *Modifier = nullptr);
|
2006-02-05 13:50:24 +08:00
|
|
|
|
2014-04-29 15:57:13 +08:00
|
|
|
void EmitFunctionBodyStart() override;
|
|
|
|
void EmitInstruction(const MachineInstr *MI) override;
|
2013-12-26 09:49:59 +08:00
|
|
|
|
|
|
|
static const char *getRegisterName(unsigned RegNo) {
|
|
|
|
return SparcInstPrinter::getRegisterName(RegNo);
|
2010-01-28 09:48:52 +08:00
|
|
|
}
|
2009-09-14 04:08:00 +08:00
|
|
|
|
2008-10-10 18:15:03 +08:00
|
|
|
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
2010-04-04 13:29:35 +08:00
|
|
|
unsigned AsmVariant, const char *ExtraCode,
|
2014-04-29 15:57:13 +08:00
|
|
|
raw_ostream &O) override;
|
2008-10-10 18:15:03 +08:00
|
|
|
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
|
2010-04-04 13:29:35 +08:00
|
|
|
unsigned AsmVariant, const char *ExtraCode,
|
2014-04-29 15:57:13 +08:00
|
|
|
raw_ostream &O) override;
|
2014-01-22 08:13:18 +08:00
|
|
|
|
2014-01-29 07:38:16 +08:00
|
|
|
void LowerGETPCXAndEmitMCInsts(const MachineInstr *MI,
|
|
|
|
const MCSubtargetInfo &STI);
|
2014-01-22 08:13:18 +08:00
|
|
|
|
2006-02-05 13:50:24 +08:00
|
|
|
};
|
|
|
|
} // end of anonymous namespace
|
|
|
|
|
2014-01-22 08:13:18 +08:00
|
|
|
static MCOperand createSparcMCOperand(SparcMCExpr::VariantKind Kind,
|
|
|
|
MCSymbol *Sym, MCContext &OutContext) {
|
2015-05-30 09:25:56 +08:00
|
|
|
const MCSymbolRefExpr *MCSym = MCSymbolRefExpr::create(Sym,
|
2013-12-26 09:49:59 +08:00
|
|
|
OutContext);
|
2015-05-30 09:25:56 +08:00
|
|
|
const SparcMCExpr *expr = SparcMCExpr::create(Kind, MCSym, OutContext);
|
2015-05-14 02:37:00 +08:00
|
|
|
return MCOperand::createExpr(expr);
|
2014-01-22 08:13:18 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
static MCOperand createPCXCallOP(MCSymbol *Label,
|
|
|
|
MCContext &OutContext) {
|
|
|
|
return createSparcMCOperand(SparcMCExpr::VK_Sparc_None, Label, OutContext);
|
2013-12-26 09:49:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static MCOperand createPCXRelExprOp(SparcMCExpr::VariantKind Kind,
|
|
|
|
MCSymbol *GOTLabel, MCSymbol *StartLabel,
|
|
|
|
MCSymbol *CurLabel,
|
|
|
|
MCContext &OutContext)
|
|
|
|
{
|
2015-05-30 09:25:56 +08:00
|
|
|
const MCSymbolRefExpr *GOT = MCSymbolRefExpr::create(GOTLabel, OutContext);
|
|
|
|
const MCSymbolRefExpr *Start = MCSymbolRefExpr::create(StartLabel,
|
2013-12-26 09:49:59 +08:00
|
|
|
OutContext);
|
2015-05-30 09:25:56 +08:00
|
|
|
const MCSymbolRefExpr *Cur = MCSymbolRefExpr::create(CurLabel,
|
2013-12-26 09:49:59 +08:00
|
|
|
OutContext);
|
|
|
|
|
2015-05-30 09:25:56 +08:00
|
|
|
const MCBinaryExpr *Sub = MCBinaryExpr::createSub(Cur, Start, OutContext);
|
|
|
|
const MCBinaryExpr *Add = MCBinaryExpr::createAdd(GOT, Sub, OutContext);
|
|
|
|
const SparcMCExpr *expr = SparcMCExpr::create(Kind,
|
2013-12-26 09:49:59 +08:00
|
|
|
Add, OutContext);
|
2015-05-14 02:37:00 +08:00
|
|
|
return MCOperand::createExpr(expr);
|
2013-12-26 09:49:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void EmitCall(MCStreamer &OutStreamer,
|
2014-01-29 07:12:42 +08:00
|
|
|
MCOperand &Callee,
|
|
|
|
const MCSubtargetInfo &STI)
|
2013-12-26 09:49:59 +08:00
|
|
|
{
|
|
|
|
MCInst CallInst;
|
|
|
|
CallInst.setOpcode(SP::CALL);
|
|
|
|
CallInst.addOperand(Callee);
|
2014-01-29 07:12:42 +08:00
|
|
|
OutStreamer.EmitInstruction(CallInst, STI);
|
2013-12-26 09:49:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void EmitSETHI(MCStreamer &OutStreamer,
|
2014-01-29 07:12:42 +08:00
|
|
|
MCOperand &Imm, MCOperand &RD,
|
|
|
|
const MCSubtargetInfo &STI)
|
2013-12-26 09:49:59 +08:00
|
|
|
{
|
|
|
|
MCInst SETHIInst;
|
|
|
|
SETHIInst.setOpcode(SP::SETHIi);
|
|
|
|
SETHIInst.addOperand(RD);
|
|
|
|
SETHIInst.addOperand(Imm);
|
2014-01-29 07:12:42 +08:00
|
|
|
OutStreamer.EmitInstruction(SETHIInst, STI);
|
2013-12-26 09:49:59 +08:00
|
|
|
}
|
|
|
|
|
2014-01-22 08:13:18 +08:00
|
|
|
static void EmitBinary(MCStreamer &OutStreamer, unsigned Opcode,
|
2014-01-29 07:12:42 +08:00
|
|
|
MCOperand &RS1, MCOperand &Src2, MCOperand &RD,
|
|
|
|
const MCSubtargetInfo &STI)
|
2013-12-26 09:49:59 +08:00
|
|
|
{
|
2014-01-22 08:13:18 +08:00
|
|
|
MCInst Inst;
|
|
|
|
Inst.setOpcode(Opcode);
|
|
|
|
Inst.addOperand(RD);
|
|
|
|
Inst.addOperand(RS1);
|
|
|
|
Inst.addOperand(Src2);
|
2014-01-29 07:12:42 +08:00
|
|
|
OutStreamer.EmitInstruction(Inst, STI);
|
2014-01-22 08:13:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void EmitOR(MCStreamer &OutStreamer,
|
2014-01-29 07:12:42 +08:00
|
|
|
MCOperand &RS1, MCOperand &Imm, MCOperand &RD,
|
|
|
|
const MCSubtargetInfo &STI) {
|
|
|
|
EmitBinary(OutStreamer, SP::ORri, RS1, Imm, RD, STI);
|
2013-12-26 09:49:59 +08:00
|
|
|
}
|
|
|
|
|
2014-01-06 04:26:05 +08:00
|
|
|
static void EmitADD(MCStreamer &OutStreamer,
|
2014-01-29 07:12:42 +08:00
|
|
|
MCOperand &RS1, MCOperand &RS2, MCOperand &RD,
|
|
|
|
const MCSubtargetInfo &STI) {
|
|
|
|
EmitBinary(OutStreamer, SP::ADDrr, RS1, RS2, RD, STI);
|
2014-01-22 08:13:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void EmitSHL(MCStreamer &OutStreamer,
|
2014-01-29 07:12:42 +08:00
|
|
|
MCOperand &RS1, MCOperand &Imm, MCOperand &RD,
|
|
|
|
const MCSubtargetInfo &STI) {
|
|
|
|
EmitBinary(OutStreamer, SP::SLLri, RS1, Imm, RD, STI);
|
2014-01-22 08:13:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void EmitHiLo(MCStreamer &OutStreamer, MCSymbol *GOTSym,
|
|
|
|
SparcMCExpr::VariantKind HiKind,
|
|
|
|
SparcMCExpr::VariantKind LoKind,
|
|
|
|
MCOperand &RD,
|
2014-01-29 07:12:42 +08:00
|
|
|
MCContext &OutContext,
|
|
|
|
const MCSubtargetInfo &STI) {
|
2014-01-22 08:13:18 +08:00
|
|
|
|
|
|
|
MCOperand hi = createSparcMCOperand(HiKind, GOTSym, OutContext);
|
|
|
|
MCOperand lo = createSparcMCOperand(LoKind, GOTSym, OutContext);
|
2014-01-29 07:12:42 +08:00
|
|
|
EmitSETHI(OutStreamer, hi, RD, STI);
|
|
|
|
EmitOR(OutStreamer, RD, lo, RD, STI);
|
2013-12-26 09:49:59 +08:00
|
|
|
}
|
|
|
|
|
2014-01-29 07:12:42 +08:00
|
|
|
void SparcAsmPrinter::LowerGETPCXAndEmitMCInsts(const MachineInstr *MI,
|
|
|
|
const MCSubtargetInfo &STI)
|
2013-12-26 09:49:59 +08:00
|
|
|
{
|
|
|
|
MCSymbol *GOTLabel =
|
2015-05-19 02:43:14 +08:00
|
|
|
OutContext.getOrCreateSymbol(Twine("_GLOBAL_OFFSET_TABLE_"));
|
2013-12-26 09:49:59 +08:00
|
|
|
|
2014-01-22 08:13:18 +08:00
|
|
|
const MachineOperand &MO = MI->getOperand(0);
|
2013-12-26 09:49:59 +08:00
|
|
|
assert(MO.getReg() != SP::O7 &&
|
|
|
|
"%o7 is assigned as destination for getpcx!");
|
|
|
|
|
2015-05-14 02:37:00 +08:00
|
|
|
MCOperand MCRegOP = MCOperand::createReg(MO.getReg());
|
2014-01-22 08:13:18 +08:00
|
|
|
|
|
|
|
|
2016-06-28 02:37:44 +08:00
|
|
|
if (!isPositionIndependent()) {
|
2014-01-22 08:13:18 +08:00
|
|
|
// Just load the address of GOT to MCRegOP.
|
|
|
|
switch(TM.getCodeModel()) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unsupported absolute code model");
|
|
|
|
case CodeModel::Small:
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitHiLo(*OutStreamer, GOTLabel,
|
2014-01-22 08:13:18 +08:00
|
|
|
SparcMCExpr::VK_Sparc_HI, SparcMCExpr::VK_Sparc_LO,
|
2014-01-29 07:38:16 +08:00
|
|
|
MCRegOP, OutContext, STI);
|
2014-01-22 08:13:18 +08:00
|
|
|
break;
|
|
|
|
case CodeModel::Medium: {
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitHiLo(*OutStreamer, GOTLabel,
|
2014-01-22 08:13:18 +08:00
|
|
|
SparcMCExpr::VK_Sparc_H44, SparcMCExpr::VK_Sparc_M44,
|
2014-01-29 07:38:16 +08:00
|
|
|
MCRegOP, OutContext, STI);
|
2015-05-30 09:25:56 +08:00
|
|
|
MCOperand imm = MCOperand::createExpr(MCConstantExpr::create(12,
|
2014-01-22 08:13:18 +08:00
|
|
|
OutContext));
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitSHL(*OutStreamer, MCRegOP, imm, MCRegOP, STI);
|
2014-01-22 08:13:18 +08:00
|
|
|
MCOperand lo = createSparcMCOperand(SparcMCExpr::VK_Sparc_L44,
|
|
|
|
GOTLabel, OutContext);
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitOR(*OutStreamer, MCRegOP, lo, MCRegOP, STI);
|
2014-01-22 08:13:18 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CodeModel::Large: {
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitHiLo(*OutStreamer, GOTLabel,
|
2014-01-22 08:13:18 +08:00
|
|
|
SparcMCExpr::VK_Sparc_HH, SparcMCExpr::VK_Sparc_HM,
|
2014-01-29 07:38:16 +08:00
|
|
|
MCRegOP, OutContext, STI);
|
2015-05-30 09:25:56 +08:00
|
|
|
MCOperand imm = MCOperand::createExpr(MCConstantExpr::create(32,
|
2014-01-22 08:13:18 +08:00
|
|
|
OutContext));
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitSHL(*OutStreamer, MCRegOP, imm, MCRegOP, STI);
|
2014-01-22 08:13:18 +08:00
|
|
|
// Use register %o7 to load the lower 32 bits.
|
2015-05-14 02:37:00 +08:00
|
|
|
MCOperand RegO7 = MCOperand::createReg(SP::O7);
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitHiLo(*OutStreamer, GOTLabel,
|
2014-01-22 08:13:18 +08:00
|
|
|
SparcMCExpr::VK_Sparc_HI, SparcMCExpr::VK_Sparc_LO,
|
2014-01-29 07:38:16 +08:00
|
|
|
RegO7, OutContext, STI);
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitADD(*OutStreamer, MCRegOP, RegO7, MCRegOP, STI);
|
2014-01-22 08:13:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-19 02:43:14 +08:00
|
|
|
MCSymbol *StartLabel = OutContext.createTempSymbol();
|
|
|
|
MCSymbol *EndLabel = OutContext.createTempSymbol();
|
|
|
|
MCSymbol *SethiLabel = OutContext.createTempSymbol();
|
2014-01-22 08:13:18 +08:00
|
|
|
|
2015-05-14 02:37:00 +08:00
|
|
|
MCOperand RegO7 = MCOperand::createReg(SP::O7);
|
2013-12-26 09:49:59 +08:00
|
|
|
|
|
|
|
// <StartLabel>:
|
|
|
|
// call <EndLabel>
|
|
|
|
// <SethiLabel>:
|
|
|
|
// sethi %hi(_GLOBAL_OFFSET_TABLE_+(<SethiLabel>-<StartLabel>)), <MO>
|
|
|
|
// <EndLabel>:
|
|
|
|
// or <MO>, %lo(_GLOBAL_OFFSET_TABLE_+(<EndLabel>-<StartLabel>))), <MO>
|
|
|
|
// add <MO>, %o7, <MO>
|
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitLabel(StartLabel);
|
2013-12-26 09:49:59 +08:00
|
|
|
MCOperand Callee = createPCXCallOP(EndLabel, OutContext);
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitCall(*OutStreamer, Callee, STI);
|
|
|
|
OutStreamer->EmitLabel(SethiLabel);
|
2014-02-07 12:24:35 +08:00
|
|
|
MCOperand hiImm = createPCXRelExprOp(SparcMCExpr::VK_Sparc_PC22,
|
2013-12-26 09:49:59 +08:00
|
|
|
GOTLabel, StartLabel, SethiLabel,
|
|
|
|
OutContext);
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitSETHI(*OutStreamer, hiImm, MCRegOP, STI);
|
|
|
|
OutStreamer->EmitLabel(EndLabel);
|
2014-02-07 12:24:35 +08:00
|
|
|
MCOperand loImm = createPCXRelExprOp(SparcMCExpr::VK_Sparc_PC10,
|
2013-12-26 09:49:59 +08:00
|
|
|
GOTLabel, StartLabel, EndLabel,
|
|
|
|
OutContext);
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitOR(*OutStreamer, MCRegOP, loImm, MCRegOP, STI);
|
|
|
|
EmitADD(*OutStreamer, MCRegOP, RegO7, MCRegOP, STI);
|
2013-12-26 09:49:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SparcAsmPrinter::EmitInstruction(const MachineInstr *MI)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (MI->getOpcode()) {
|
|
|
|
default: break;
|
|
|
|
case TargetOpcode::DBG_VALUE:
|
|
|
|
// FIXME: Debug Value.
|
|
|
|
return;
|
|
|
|
case SP::GETPCX:
|
2014-01-29 07:12:42 +08:00
|
|
|
LowerGETPCXAndEmitMCInsts(MI, getSubtargetInfo());
|
2013-12-26 09:49:59 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-02-23 04:49:58 +08:00
|
|
|
MachineBasicBlock::const_instr_iterator I = MI->getIterator();
|
|
|
|
MachineBasicBlock::const_instr_iterator E = MI->getParent()->instr_end();
|
2014-01-12 03:38:03 +08:00
|
|
|
do {
|
|
|
|
MCInst TmpInst;
|
2015-10-20 08:59:43 +08:00
|
|
|
LowerSparcMachineInstrToMCInst(&*I, TmpInst, *this);
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, TmpInst);
|
2014-01-12 03:38:03 +08:00
|
|
|
} while ((++I != E) && I->isInsideBundle()); // Delay slot check.
|
2013-12-26 09:49:59 +08:00
|
|
|
}
|
2006-02-05 13:50:24 +08:00
|
|
|
|
2013-09-22 08:42:30 +08:00
|
|
|
void SparcAsmPrinter::EmitFunctionBodyStart() {
|
2015-01-31 07:46:43 +08:00
|
|
|
if (!MF->getSubtarget<SparcSubtarget>().is64Bit())
|
2013-09-22 08:42:30 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
const MachineRegisterInfo &MRI = MF->getRegInfo();
|
|
|
|
const unsigned globalRegs[] = { SP::G2, SP::G3, SP::G6, SP::G7, 0 };
|
|
|
|
for (unsigned i = 0; globalRegs[i] != 0; ++i) {
|
|
|
|
unsigned reg = globalRegs[i];
|
2013-11-25 02:41:49 +08:00
|
|
|
if (MRI.use_empty(reg))
|
2013-09-22 08:42:30 +08:00
|
|
|
continue;
|
2013-12-26 09:49:59 +08:00
|
|
|
|
|
|
|
if (reg == SP::G6 || reg == SP::G7)
|
|
|
|
getTargetStreamer().emitSparcRegisterIgnore(reg);
|
|
|
|
else
|
|
|
|
getTargetStreamer().emitSparcRegisterScratch(reg);
|
2013-09-22 08:42:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-04 12:47:45 +08:00
|
|
|
void SparcAsmPrinter::printOperand(const MachineInstr *MI, int opNum,
|
|
|
|
raw_ostream &O) {
|
2015-07-16 14:11:10 +08:00
|
|
|
const DataLayout &DL = getDataLayout();
|
2006-02-05 13:50:24 +08:00
|
|
|
const MachineOperand &MO = MI->getOperand (opNum);
|
2014-02-07 10:36:06 +08:00
|
|
|
SparcMCExpr::VariantKind TF = (SparcMCExpr::VariantKind) MO.getTargetFlags();
|
|
|
|
|
2013-04-14 12:35:19 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
// Verify the target flags.
|
|
|
|
if (MO.isGlobal() || MO.isSymbol() || MO.isCPI()) {
|
|
|
|
if (MI->getOpcode() == SP::CALL)
|
2014-02-07 10:36:06 +08:00
|
|
|
assert(TF == SparcMCExpr::VK_Sparc_None &&
|
2013-04-14 12:35:19 +08:00
|
|
|
"Cannot handle target flags on call address");
|
2013-12-29 15:15:09 +08:00
|
|
|
else if (MI->getOpcode() == SP::SETHIi || MI->getOpcode() == SP::SETHIXi)
|
2014-02-07 10:36:06 +08:00
|
|
|
assert((TF == SparcMCExpr::VK_Sparc_HI
|
|
|
|
|| TF == SparcMCExpr::VK_Sparc_H44
|
|
|
|
|| TF == SparcMCExpr::VK_Sparc_HH
|
|
|
|
|| TF == SparcMCExpr::VK_Sparc_TLS_GD_HI22
|
|
|
|
|| TF == SparcMCExpr::VK_Sparc_TLS_LDM_HI22
|
|
|
|
|| TF == SparcMCExpr::VK_Sparc_TLS_LDO_HIX22
|
|
|
|
|| TF == SparcMCExpr::VK_Sparc_TLS_IE_HI22
|
|
|
|
|| TF == SparcMCExpr::VK_Sparc_TLS_LE_HIX22) &&
|
2013-04-14 12:35:19 +08:00
|
|
|
"Invalid target flags for address operand on sethi");
|
2013-09-22 14:48:52 +08:00
|
|
|
else if (MI->getOpcode() == SP::TLS_CALL)
|
2014-02-07 10:36:06 +08:00
|
|
|
assert((TF == SparcMCExpr::VK_Sparc_None
|
|
|
|
|| TF == SparcMCExpr::VK_Sparc_TLS_GD_CALL
|
|
|
|
|| TF == SparcMCExpr::VK_Sparc_TLS_LDM_CALL) &&
|
2013-09-22 14:48:52 +08:00
|
|
|
"Cannot handle target flags on tls call address");
|
|
|
|
else if (MI->getOpcode() == SP::TLS_ADDrr)
|
2014-02-07 10:36:06 +08:00
|
|
|
assert((TF == SparcMCExpr::VK_Sparc_TLS_GD_ADD
|
|
|
|
|| TF == SparcMCExpr::VK_Sparc_TLS_LDM_ADD
|
|
|
|
|| TF == SparcMCExpr::VK_Sparc_TLS_LDO_ADD
|
|
|
|
|| TF == SparcMCExpr::VK_Sparc_TLS_IE_ADD) &&
|
2013-09-22 14:48:52 +08:00
|
|
|
"Cannot handle target flags on add for TLS");
|
|
|
|
else if (MI->getOpcode() == SP::TLS_LDrr)
|
2014-02-07 10:36:06 +08:00
|
|
|
assert(TF == SparcMCExpr::VK_Sparc_TLS_IE_LD &&
|
2013-09-22 14:48:52 +08:00
|
|
|
"Cannot handle target flags on ld for TLS");
|
|
|
|
else if (MI->getOpcode() == SP::TLS_LDXrr)
|
2014-02-07 10:36:06 +08:00
|
|
|
assert(TF == SparcMCExpr::VK_Sparc_TLS_IE_LDX &&
|
2013-09-22 14:48:52 +08:00
|
|
|
"Cannot handle target flags on ldx for TLS");
|
2013-12-29 15:15:09 +08:00
|
|
|
else if (MI->getOpcode() == SP::XORri || MI->getOpcode() == SP::XORXri)
|
2014-02-07 10:36:06 +08:00
|
|
|
assert((TF == SparcMCExpr::VK_Sparc_TLS_LDO_LOX10
|
|
|
|
|| TF == SparcMCExpr::VK_Sparc_TLS_LE_LOX10) &&
|
2013-09-22 14:48:52 +08:00
|
|
|
"Cannot handle target flags on xor for TLS");
|
2013-04-14 12:35:19 +08:00
|
|
|
else
|
2014-02-07 10:36:06 +08:00
|
|
|
assert((TF == SparcMCExpr::VK_Sparc_LO
|
|
|
|
|| TF == SparcMCExpr::VK_Sparc_M44
|
|
|
|
|| TF == SparcMCExpr::VK_Sparc_L44
|
|
|
|
|| TF == SparcMCExpr::VK_Sparc_HM
|
|
|
|
|| TF == SparcMCExpr::VK_Sparc_TLS_GD_LO10
|
|
|
|
|| TF == SparcMCExpr::VK_Sparc_TLS_LDM_LO10
|
|
|
|
|| TF == SparcMCExpr::VK_Sparc_TLS_IE_LO10 ) &&
|
2013-04-14 12:35:19 +08:00
|
|
|
"Invalid target flags for small address operand");
|
2006-02-05 13:50:24 +08:00
|
|
|
}
|
2013-04-14 12:35:19 +08:00
|
|
|
#endif
|
|
|
|
|
2014-02-07 10:36:06 +08:00
|
|
|
|
|
|
|
bool CloseParen = SparcMCExpr::printVariantKind(O, TF);
|
2013-04-14 12:35:19 +08:00
|
|
|
|
2006-02-05 13:50:24 +08:00
|
|
|
switch (MO.getType()) {
|
2006-05-05 02:05:43 +08:00
|
|
|
case MachineOperand::MO_Register:
|
2011-11-07 04:37:06 +08:00
|
|
|
O << "%" << StringRef(getRegisterName(MO.getReg())).lower();
|
2006-02-05 13:50:24 +08:00
|
|
|
break;
|
|
|
|
|
2006-05-05 01:21:20 +08:00
|
|
|
case MachineOperand::MO_Immediate:
|
2007-12-31 04:49:49 +08:00
|
|
|
O << (int)MO.getImm();
|
2006-02-05 13:50:24 +08:00
|
|
|
break;
|
2006-04-23 02:53:45 +08:00
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
2015-06-09 08:31:39 +08:00
|
|
|
MO.getMBB()->getSymbol()->print(O, MAI);
|
2006-02-05 13:50:24 +08:00
|
|
|
return;
|
|
|
|
case MachineOperand::MO_GlobalAddress:
|
2015-06-09 08:31:39 +08:00
|
|
|
getSymbol(MO.getGlobal())->print(O, MAI);
|
2006-02-05 13:50:24 +08:00
|
|
|
break;
|
2013-06-03 13:58:33 +08:00
|
|
|
case MachineOperand::MO_BlockAddress:
|
|
|
|
O << GetBlockAddressSymbol(MO.getBlockAddress())->getName();
|
|
|
|
break;
|
2006-02-05 13:50:24 +08:00
|
|
|
case MachineOperand::MO_ExternalSymbol:
|
|
|
|
O << MO.getSymbolName();
|
|
|
|
break;
|
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
2015-07-16 14:11:10 +08:00
|
|
|
O << DL.getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << "_"
|
2007-12-31 07:10:15 +08:00
|
|
|
<< MO.getIndex();
|
2006-02-05 13:50:24 +08:00
|
|
|
break;
|
2016-05-26 15:28:31 +08:00
|
|
|
case MachineOperand::MO_Metadata:
|
|
|
|
MO.getMetadata()->printAsOperand(O, MMI->getModule());
|
|
|
|
break;
|
2006-02-05 13:50:24 +08:00
|
|
|
default:
|
2009-07-15 00:55:14 +08:00
|
|
|
llvm_unreachable("<unknown operand type>");
|
2006-02-05 13:50:24 +08:00
|
|
|
}
|
|
|
|
if (CloseParen) O << ")";
|
|
|
|
}
|
|
|
|
|
2006-02-10 15:35:42 +08:00
|
|
|
void SparcAsmPrinter::printMemOperand(const MachineInstr *MI, int opNum,
|
2010-04-04 12:47:45 +08:00
|
|
|
raw_ostream &O, const char *Modifier) {
|
|
|
|
printOperand(MI, opNum, O);
|
2008-08-07 17:51:25 +08:00
|
|
|
|
2006-02-10 15:35:42 +08:00
|
|
|
// If this is an ADD operand, emit it like normal operands.
|
|
|
|
if (Modifier && !strcmp(Modifier, "arith")) {
|
|
|
|
O << ", ";
|
2010-04-04 12:47:45 +08:00
|
|
|
printOperand(MI, opNum+1, O);
|
2006-02-10 15:35:42 +08:00
|
|
|
return;
|
|
|
|
}
|
2008-08-07 17:51:25 +08:00
|
|
|
|
2008-10-03 23:45:36 +08:00
|
|
|
if (MI->getOperand(opNum+1).isReg() &&
|
2006-02-05 13:50:24 +08:00
|
|
|
MI->getOperand(opNum+1).getReg() == SP::G0)
|
|
|
|
return; // don't print "+%g0"
|
2008-10-03 23:45:36 +08:00
|
|
|
if (MI->getOperand(opNum+1).isImm() &&
|
2007-12-31 04:49:49 +08:00
|
|
|
MI->getOperand(opNum+1).getImm() == 0)
|
2006-02-05 13:50:24 +08:00
|
|
|
return; // don't print "+0"
|
2008-08-07 17:51:25 +08:00
|
|
|
|
2006-02-05 13:50:24 +08:00
|
|
|
O << "+";
|
2013-04-14 12:35:19 +08:00
|
|
|
printOperand(MI, opNum+1, O);
|
2006-02-05 13:50:24 +08:00
|
|
|
}
|
|
|
|
|
2008-10-10 18:15:03 +08:00
|
|
|
/// PrintAsmOperand - Print out an operand for an inline asm expression.
|
|
|
|
///
|
|
|
|
bool SparcAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
|
|
|
unsigned AsmVariant,
|
2010-04-04 13:29:35 +08:00
|
|
|
const char *ExtraCode,
|
|
|
|
raw_ostream &O) {
|
2008-10-11 04:29:50 +08:00
|
|
|
if (ExtraCode && ExtraCode[0]) {
|
|
|
|
if (ExtraCode[1] != 0) return true; // Unknown modifier.
|
|
|
|
|
|
|
|
switch (ExtraCode[0]) {
|
2012-06-26 21:49:27 +08:00
|
|
|
default:
|
|
|
|
// See if this is a generic print operand
|
|
|
|
return AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, O);
|
2016-05-26 15:28:31 +08:00
|
|
|
case 'f':
|
2008-10-11 04:29:50 +08:00
|
|
|
case 'r':
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-10-10 18:15:03 +08:00
|
|
|
|
2010-04-04 12:47:45 +08:00
|
|
|
printOperand(MI, OpNo, O);
|
2008-10-10 18:15:03 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SparcAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
|
2010-04-04 13:29:35 +08:00
|
|
|
unsigned OpNo, unsigned AsmVariant,
|
|
|
|
const char *ExtraCode,
|
|
|
|
raw_ostream &O) {
|
2008-10-10 18:15:03 +08:00
|
|
|
if (ExtraCode && ExtraCode[0])
|
|
|
|
return true; // Unknown modifier
|
|
|
|
|
|
|
|
O << '[';
|
2010-04-04 12:47:45 +08:00
|
|
|
printMemOperand(MI, OpNo, O);
|
2008-10-10 18:15:03 +08:00
|
|
|
O << ']';
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2009-06-17 04:12:29 +08:00
|
|
|
|
2009-06-24 07:59:40 +08:00
|
|
|
// Force static initialization.
|
2013-06-05 02:33:25 +08:00
|
|
|
extern "C" void LLVMInitializeSparcAsmPrinter() {
|
2016-10-10 07:00:34 +08:00
|
|
|
RegisterAsmPrinter<SparcAsmPrinter> X(getTheSparcTarget());
|
|
|
|
RegisterAsmPrinter<SparcAsmPrinter> Y(getTheSparcV9Target());
|
|
|
|
RegisterAsmPrinter<SparcAsmPrinter> Z(getTheSparcelTarget());
|
2009-07-16 04:24:03 +08:00
|
|
|
}
|