36#define DEBUG_TYPE "asm-printer"
42 *OutStreamer->getTargetStreamer());
46 std::unique_ptr<MCStreamer> Streamer)
53 const char *Modifier =
nullptr);
140 EmitBinary(OutStreamer, SP::ORri, RS1, Imm, RD, STI);
146 EmitBinary(OutStreamer, SP::ADDrr, RS1, RS2, RD, STI);
152 EmitBinary(OutStreamer, SP::SLLri, RS1, Imm, RD, STI);
166 EmitOR(OutStreamer, RD, lo, RD, STI);
169void SparcAsmPrinter::LowerGETPCXAndEmitMCInsts(
const MachineInstr *
MI,
173 OutContext.getOrCreateSymbol(
Twine(
"_GLOBAL_OFFSET_TABLE_"));
177 "%o7 is assigned as destination for getpcx!");
182 if (!isPositionIndependent()) {
184 switch(
TM.getCodeModel()) {
190 MCRegOP, OutContext, STI);
195 MCRegOP, OutContext, STI);
198 EmitSHL(*OutStreamer, MCRegOP, imm, MCRegOP, STI);
200 GOTLabel, OutContext);
201 EmitOR(*OutStreamer, MCRegOP, lo, MCRegOP, STI);
207 MCRegOP, OutContext, STI);
210 EmitSHL(*OutStreamer, MCRegOP, imm, MCRegOP, STI);
215 RegO7, OutContext, STI);
216 EmitADD(*OutStreamer, MCRegOP, RegO7, MCRegOP, STI);
222 MCSymbol *StartLabel = OutContext.createTempSymbol();
223 MCSymbol *EndLabel = OutContext.createTempSymbol();
224 MCSymbol *SethiLabel = OutContext.createTempSymbol();
236 OutStreamer->emitLabel(StartLabel);
238 EmitCall(*OutStreamer, Callee, STI);
239 OutStreamer->emitLabel(SethiLabel);
241 GOTLabel, StartLabel, SethiLabel,
243 EmitSETHI(*OutStreamer, hiImm, MCRegOP, STI);
244 OutStreamer->emitLabel(EndLabel);
246 GOTLabel, StartLabel, EndLabel,
248 EmitOR(*OutStreamer, MCRegOP, loImm, MCRegOP, STI);
249 EmitADD(*OutStreamer, MCRegOP, RegO7, MCRegOP, STI);
253 Sparc_MC::verifyInstructionPredicates(
MI->getOpcode(),
254 getSubtargetInfo().getFeatureBits());
256 switch (
MI->getOpcode()) {
258 case TargetOpcode::DBG_VALUE:
262 LowerGETPCXAndEmitMCInsts(
MI, getSubtargetInfo());
270 EmitToStreamer(*OutStreamer, TmpInst);
271 }
while ((++
I !=
E) &&
I->isInsideBundle());
274void SparcAsmPrinter::emitFunctionBodyStart() {
279 const unsigned globalRegs[] = { SP::G2, SP::G3, SP::G6, SP::G7, 0 };
280 for (
unsigned i = 0; globalRegs[i] != 0; ++i) {
281 unsigned reg = globalRegs[i];
282 if (
MRI.use_empty(reg))
285 if (reg == SP::G6 || reg == SP::G7)
286 getTargetStreamer().emitSparcRegisterIgnore(reg);
288 getTargetStreamer().emitSparcRegisterScratch(reg);
292void SparcAsmPrinter::printOperand(
const MachineInstr *
MI,
int opNum,
301 if (
MI->getOpcode() == SP::CALL)
303 "Cannot handle target flags on call address");
304 else if (
MI->getOpcode() == SP::SETHIi ||
MI->getOpcode() == SP::SETHIXi)
314 "Invalid target flags for address operand on sethi");
315 else if (
MI->getOpcode() == SP::TLS_CALL)
319 "Cannot handle target flags on tls call address");
320 else if (
MI->getOpcode() == SP::TLS_ADDrr)
325 "Cannot handle target flags on add for TLS");
326 else if (
MI->getOpcode() == SP::TLS_LDrr)
328 "Cannot handle target flags on ld for TLS");
329 else if (
MI->getOpcode() == SP::TLS_LDXrr)
331 "Cannot handle target flags on ldx for TLS");
332 else if (
MI->getOpcode() == SP::XORri ||
MI->getOpcode() == SP::XORXri)
335 "Cannot handle target flags on xor for TLS");
344 "Invalid target flags for small address operand");
363 PrintSymbolOperand(MO, O);
372 O <<
DL.getPrivateGlobalPrefix() <<
"CPI" << getFunctionNumber() <<
"_"
381 if (CloseParen)
O <<
")";
384void SparcAsmPrinter::printMemOperand(
const MachineInstr *
MI,
int opNum,
389 if (Modifier && !strcmp(Modifier,
"arith")) {
395 if (
MI->getOperand(opNum+1).isReg() &&
396 MI->getOperand(opNum+1).getReg() == SP::G0)
398 if (
MI->getOperand(opNum+1).isImm() &&
399 MI->getOperand(opNum+1).getImm() == 0)
408bool SparcAsmPrinter::PrintAsmOperand(
const MachineInstr *
MI,
unsigned OpNo,
409 const char *ExtraCode,
411 if (ExtraCode && ExtraCode[0]) {
412 if (ExtraCode[1] != 0)
return true;
414 switch (ExtraCode[0]) {
429bool SparcAsmPrinter::PrintAsmMemoryOperand(
const MachineInstr *
MI,
431 const char *ExtraCode,
433 if (ExtraCode && ExtraCode[0])
unsigned const MachineRegisterInfo * MRI
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_EXTERNAL_VISIBILITY
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static std::string getRegisterName(const TargetRegisterInfo *TRI, Register Reg)
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
const char LLVMTargetMachineRef TM
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool printOperand(raw_ostream &OS, const SelectionDAG *G, const SDValue Value)
static void printMemOperand(raw_ostream &OS, const MachineMemOperand &MMO, const MachineFunction *MF, const Module *M, const MachineFrameInfo *MFI, const TargetInstrInfo *TII, LLVMContext &Ctx)
static MCOperand createSparcMCOperand(SparcMCExpr::VariantKind Kind, MCSymbol *Sym, MCContext &OutContext)
static MCOperand createPCXCallOP(MCSymbol *Label, MCContext &OutContext)
static void EmitSHL(MCStreamer &OutStreamer, MCOperand &RS1, MCOperand &Imm, MCOperand &RD, const MCSubtargetInfo &STI)
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeSparcAsmPrinter()
static void EmitCall(MCStreamer &OutStreamer, MCOperand &Callee, const MCSubtargetInfo &STI)
static void EmitSETHI(MCStreamer &OutStreamer, MCOperand &Imm, MCOperand &RD, const MCSubtargetInfo &STI)
static void EmitOR(MCStreamer &OutStreamer, MCOperand &RS1, MCOperand &Imm, MCOperand &RD, const MCSubtargetInfo &STI)
static void EmitBinary(MCStreamer &OutStreamer, unsigned Opcode, MCOperand &RS1, MCOperand &Src2, MCOperand &RD, const MCSubtargetInfo &STI)
static MCOperand createPCXRelExprOp(SparcMCExpr::VariantKind Kind, MCSymbol *GOTLabel, MCSymbol *StartLabel, MCSymbol *CurLabel, MCContext &OutContext)
static void EmitADD(MCStreamer &OutStreamer, MCOperand &RS1, MCOperand &RS2, MCOperand &RD, const MCSubtargetInfo &STI)
static void EmitHiLo(MCStreamer &OutStreamer, MCSymbol *GOTSym, SparcMCExpr::VariantKind HiKind, SparcMCExpr::VariantKind LoKind, MCOperand &RD, MCContext &OutContext, const MCSubtargetInfo &STI)
This class is intended to be used as a driving class for all asm writers.
virtual void emitInstruction(const MachineInstr *)
Targets should implement this to emit instructions.
virtual void emitFunctionBodyStart()
Targets can override this to emit stuff before the first basic block in the function.
virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant.
This class represents a function call, abstracting a target machine's calling convention.
A parsed version of the target data layout string in and methods for querying it.
Binary assembler expressions.
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Context object for machine code objects.
Instances of this class represent a single low-level machine instruction.
void addOperand(const MCOperand Op)
void setOpcode(unsigned Op)
Instances of this class represent operands of the MCInst class.
static MCOperand createReg(unsigned Reg)
static MCOperand createExpr(const MCExpr *Val)
Wrapper class representing physical registers. Should be passed by value.
Streaming machine code generation interface.
virtual void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI)
Emit the given Instruction into the current section.
Generic base class for all target subtargets.
Represent a reference to a symbol from inside an expression.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
const MDNode * getMetadata() const
MachineBasicBlock * getMBB() const
bool isCPI() const
isCPI - Tests if this is a MO_ConstantPoolIndex operand.
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
const BlockAddress * getBlockAddress() const
unsigned getTargetFlags() const
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
const char * getSymbolName() const
Register getReg() const
getReg - Returns the register number.
@ MO_Immediate
Immediate operand.
@ MO_ConstantPoolIndex
Address of indexed Constant in Constant Pool.
@ MO_GlobalAddress
Address of a global value.
@ MO_BlockAddress
Address of a basic block.
@ MO_MachineBasicBlock
MachineBasicBlock reference.
@ MO_Register
Register operand.
@ MO_ExternalSymbol
Name of external global symbol.
@ MO_Metadata
Metadata reference (for debug info)
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
static const char * getRegisterName(MCRegister Reg, unsigned AltIdx=SP::NoRegAltName)
static const SparcMCExpr * create(VariantKind Kind, const MCExpr *Expr, MCContext &Ctx)
static bool printVariantKind(raw_ostream &OS, VariantKind Kind)
StringRef - Represent a constant reference to a string, i.e.
std::string lower() const
Primary interface to the complete machine description for the target machine.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Iterator for intrusive lists based on ilist_node.
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
Target & getTheSparcTarget()
Target & getTheSparcV9Target()
void LowerSparcMachineInstrToMCInst(const MachineInstr *MI, MCInst &OutMI, AsmPrinter &AP)
Target & getTheSparcelTarget()
ArrayRef< int > lo(ArrayRef< int > Vuu)
RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...