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