37 #define DEBUG_TYPE "asm-printer"
43 *OutStreamer->getTargetStreamer());
47 std::unique_ptr<MCStreamer> Streamer)
50 const char *getPassName()
const override {
51 return "Sparc Assembly Printer";
56 const char *Modifier =
nullptr);
59 void EmitFunctionBodyStart()
override;
66 bool PrintAsmOperand(
const MachineInstr *MI,
unsigned OpNo,
67 unsigned AsmVariant,
const char *ExtraCode,
69 bool PrintAsmMemoryOperand(
const MachineInstr *MI,
unsigned OpNo,
70 unsigned AsmVariant,
const char *ExtraCode,
146 EmitBinary(OutStreamer, SP::ORri, RS1, Imm, RD, STI);
152 EmitBinary(OutStreamer, SP::ADDrr, RS1, RS2, RD, STI);
158 EmitBinary(OutStreamer, SP::SLLri, RS1, Imm, RD, STI);
172 EmitOR(OutStreamer, RD, lo, RD, STI);
175 void SparcAsmPrinter::LowerGETPCXAndEmitMCInsts(
const MachineInstr *
MI,
179 OutContext.getOrCreateSymbol(
Twine(
"_GLOBAL_OFFSET_TABLE_"));
182 assert(MO.
getReg() != SP::O7 &&
183 "%o7 is assigned as destination for getpcx!");
190 switch(
TM.getCodeModel()) {
196 MCRegOP, OutContext, STI);
201 MCRegOP, OutContext, STI);
204 EmitSHL(*OutStreamer, MCRegOP, imm, MCRegOP, STI);
206 GOTLabel, OutContext);
207 EmitOR(*OutStreamer, MCRegOP, lo, MCRegOP, STI);
213 MCRegOP, OutContext, STI);
216 EmitSHL(*OutStreamer, MCRegOP, imm, MCRegOP, STI);
221 RegO7, OutContext, STI);
222 EmitADD(*OutStreamer, MCRegOP, RegO7, MCRegOP, STI);
228 MCSymbol *StartLabel = OutContext.createTempSymbol();
229 MCSymbol *EndLabel = OutContext.createTempSymbol();
230 MCSymbol *SethiLabel = OutContext.createTempSymbol();
242 OutStreamer->EmitLabel(StartLabel);
244 EmitCall(*OutStreamer, Callee, STI);
245 OutStreamer->EmitLabel(SethiLabel);
247 GOTLabel, StartLabel, SethiLabel,
249 EmitSETHI(*OutStreamer, hiImm, MCRegOP, STI);
250 OutStreamer->EmitLabel(EndLabel);
252 GOTLabel, StartLabel, EndLabel,
254 EmitOR(*OutStreamer, MCRegOP, loImm, MCRegOP, STI);
255 EmitADD(*OutStreamer, MCRegOP, RegO7, MCRegOP, STI);
258 void SparcAsmPrinter::EmitInstruction(
const MachineInstr *MI)
267 LowerGETPCXAndEmitMCInsts(MI, getSubtargetInfo());
275 EmitToStreamer(*OutStreamer, TmpInst);
276 }
while ((++I != E) && I->isInsideBundle());
279 void SparcAsmPrinter::EmitFunctionBodyStart() {
284 const unsigned globalRegs[] = { SP::G2, SP::G3, SP::G6, SP::G7, 0 };
285 for (
unsigned i = 0; globalRegs[i] != 0; ++i) {
286 unsigned reg = globalRegs[i];
290 if (reg == SP::G6 || reg == SP::G7)
291 getTargetStreamer().emitSparcRegisterIgnore(reg);
293 getTargetStreamer().emitSparcRegisterScratch(reg);
308 "Cannot handle target flags on call address");
318 "Invalid target flags for address operand on sethi");
323 "Cannot handle target flags on tls call address");
324 else if (MI->
getOpcode() == SP::TLS_ADDrr)
329 "Cannot handle target flags on add for TLS");
330 else if (MI->
getOpcode() == SP::TLS_LDrr)
332 "Cannot handle target flags on ld for TLS");
333 else if (MI->
getOpcode() == SP::TLS_LDXrr)
335 "Cannot handle target flags on ldx for TLS");
339 "Cannot handle target flags on xor for TLS");
348 "Invalid target flags for small address operand");
367 getSymbol(MO.
getGlobal())->print(O, MAI);
382 if (CloseParen) O <<
")";
385 void SparcAsmPrinter::printMemOperand(
const MachineInstr *MI,
int opNum,
390 if (Modifier && !strcmp(Modifier,
"arith")) {
409 bool SparcAsmPrinter::PrintAsmOperand(
const MachineInstr *MI,
unsigned OpNo,
411 const char *ExtraCode,
413 if (ExtraCode && ExtraCode[0]) {
414 if (ExtraCode[1] != 0)
return true;
416 switch (ExtraCode[0]) {
430 bool SparcAsmPrinter::PrintAsmMemoryOperand(
const MachineInstr *MI,
431 unsigned OpNo,
unsigned AsmVariant,
432 const char *ExtraCode,
434 if (ExtraCode && ExtraCode[0])
438 printMemOperand(MI, OpNo, O);
A parsed version of the target data layout string in and methods for querying it. ...
const GlobalValue * getGlobal() const
static MCOperand createPCXRelExprOp(SparcMCExpr::VariantKind Kind, MCSymbol *GOTLabel, MCSymbol *StartLabel, MCSymbol *CurLabel, MCContext &OutContext)
instr_iterator instr_end()
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
MachineBasicBlock * getMBB() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
static MCOperand createExpr(const MCExpr *Val)
static bool printVariantKind(raw_ostream &OS, VariantKind Kind)
CallInst - This class represents a function call, abstracting a target machine's calling convention...
const char * getPrivateGlobalPrefix() const
MachineBasicBlock reference.
const char * getSymbolName() const
virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI)
Emit the given Instruction into the current section.
static MCOperand createReg(unsigned Reg)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static const char * getRegisterName(unsigned RegNo)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
static void EmitHiLo(MCStreamer &OutStreamer, MCSymbol *GOTSym, SparcMCExpr::VariantKind HiKind, SparcMCExpr::VariantKind LoKind, MCOperand &RD, MCContext &OutContext, const MCSubtargetInfo &STI)
Name of external global symbol.
static StringRef getName(Value *V)
Represent a reference to a symbol from inside an expression.
static void printOperand(raw_ostream &OS, uint8_t Opcode, unsigned OperandIdx, uint64_t Operand, uint64_t CodeAlignmentFactor, int64_t DataAlignmentFactor)
Print Opcode's operand number OperandIdx which has value Operand.
bool isCPI() const
isCPI - Tests if this is a MO_ConstantPoolIndex operand.
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
Context object for machine code objects.
static std::string getRegisterName(const TargetRegisterInfo *TRI, unsigned Reg)
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Instances of this class represent a single low-level machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
DBG_VALUE - a mapping of the llvm.dbg.value intrinsic.
static void EmitSHL(MCStreamer &OutStreamer, MCOperand &RS1, MCOperand &Imm, MCOperand &RD, const MCSubtargetInfo &STI)
Address of a global value.
unsigned getTargetFlags() const
Streaming machine code generation interface.
static void EmitBinary(MCStreamer &OutStreamer, unsigned Opcode, MCOperand &RS1, MCOperand &Src2, MCOperand &RD, const MCSubtargetInfo &STI)
static void EmitCall(MCStreamer &OutStreamer, MCOperand &Callee, const MCSubtargetInfo &STI)
const MachineOperand & getOperand(unsigned i) const
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant...
This class is intended to be used as a driving class for all asm writers.
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
static void EmitOR(MCStreamer &OutStreamer, MCOperand &RS1, MCOperand &Imm, MCOperand &RD, const MCSubtargetInfo &STI)
Address of a basic block.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
static void EmitADD(MCStreamer &OutStreamer, MCOperand &RS1, MCOperand &RS2, MCOperand &RD, const MCSubtargetInfo &STI)
Binary assembler expressions.
MCSymbol * getSymbol() const
getSymbol - Return the MCSymbol for this basic block.
void LLVMInitializeSparcAsmPrinter()
void setOpcode(unsigned Op)
MachineOperand class - Representation of each machine instruction operand.
static MCOperand createPCXCallOP(MCSymbol *Label, MCContext &OutContext)
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
void LowerSparcMachineInstrToMCInst(const MachineInstr *MI, MCInst &OutMI, AsmPrinter &AP)
MCSubtargetInfo - Generic base class for all target subtargets.
static const SparcMCExpr * create(VariantKind Kind, const MCExpr *Expr, MCContext &Ctx)
unsigned getReg() const
getReg - Returns the register number.
const ARM::ArchExtKind Kind
RegisterAsmPrinter - Helper template for registering a target specific assembly printer, for use in the target machine initialization function.
This class implements an extremely fast bulk output stream that can only output to a stream...
static void EmitSETHI(MCStreamer &OutStreamer, MCOperand &Imm, MCOperand &RD, const MCSubtargetInfo &STI)
Primary interface to the complete machine description for the target machine.
void addOperand(const MCOperand &Op)
StringRef - Represent a constant reference to a string, i.e.
const BlockAddress * getBlockAddress() const
Address of indexed Constant in Constant Pool.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
Instances of this class represent operands of the MCInst class.
std::string lower() const
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
static MCOperand createSparcMCOperand(SparcMCExpr::VariantKind Kind, MCSymbol *Sym, MCContext &OutContext)
bool use_empty(unsigned RegNo) const
use_empty - Return true if there are no instructions using the specified register.