15 #define DEBUG_TYPE "asm-printer"
38 virtual const char *getPassName()
const {
39 return "Sparc Assembly Printer";
44 const char *Modifier = 0);
47 virtual void EmitFunctionBodyStart();
51 printInstruction(MI, OS);
52 OutStreamer.EmitRawText(OS.
str());
55 static const char *getRegisterName(
unsigned RegNo);
57 bool PrintAsmOperand(
const MachineInstr *MI,
unsigned OpNo,
58 unsigned AsmVariant,
const char *ExtraCode,
60 bool PrintAsmMemoryOperand(
const MachineInstr *MI,
unsigned OpNo,
61 unsigned AsmVariant,
const char *ExtraCode,
68 void EmitGlobalRegisterDecl(
unsigned reg) {
74 << ((reg == SP::G6 || reg == SP::G7)?
"#ignore" :
"#scratch");
75 OutStreamer.EmitRawText(OS.
str());
81 #include "SparcGenAsmWriter.inc"
83 void SparcAsmPrinter::EmitFunctionBodyStart() {
88 const unsigned globalRegs[] = { SP::G2, SP::G3, SP::G6, SP::G7, 0 };
89 for (
unsigned i = 0; globalRegs[i] != 0; ++i) {
90 unsigned reg = globalRegs[i];
93 EmitGlobalRegisterDecl(reg);
97 void SparcAsmPrinter::printOperand(
const MachineInstr *
MI,
int opNum,
106 "Cannot handle target flags on call address");
114 "Invalid target flags for address operand on sethi");
119 "Cannot handle target flags on tls call address");
120 else if (MI->
getOpcode() == SP::TLS_ADDrr)
123 "Cannot handle target flags on add for TLS");
124 else if (MI->
getOpcode() == SP::TLS_LDrr)
126 "Cannot handle target flags on ld for TLS");
127 else if (MI->
getOpcode() == SP::TLS_LDXrr)
129 "Cannot handle target flags on ldx for TLS");
132 "Cannot handle target flags on xor for TLS");
139 "Invalid target flags for small address operand");
143 bool CloseParen =
true;
198 O << MAI->getPrivateGlobalPrefix() <<
"CPI" << getFunctionNumber() <<
"_"
204 if (CloseParen) O <<
")";
207 void SparcAsmPrinter::printMemOperand(
const MachineInstr *MI,
int opNum,
209 printOperand(MI, opNum, O);
212 if (Modifier && !
strcmp(Modifier,
"arith")) {
214 printOperand(MI, opNum+1, O);
226 printOperand(MI, opNum+1, O);
229 bool SparcAsmPrinter::printGetPCX(
const MachineInstr *MI,
unsigned opNum,
231 std::string operand =
"";
237 "Operand is not a physical register ");
238 assert(MO.
getReg() != SP::O7 &&
239 "%o7 is assigned as destination for getpcx!");
247 O <<
'\n' <<
".LLGETPCH" << mfNum <<
'_' << bbNum <<
":\n";
248 O <<
"\tcall\t.LLGETPC" << mfNum <<
'_' << bbNum <<
'\n' ;
251 <<
"%hi(_GLOBAL_OFFSET_TABLE_+(.-.LLGETPCH" << mfNum <<
'_' << bbNum
252 <<
")), " << operand <<
'\n' ;
254 O <<
".LLGETPC" << mfNum <<
'_' << bbNum <<
":\n" ;
255 O <<
"\tor\t" << operand
256 <<
", %lo(_GLOBAL_OFFSET_TABLE_+(.-.LLGETPCH" << mfNum <<
'_' << bbNum
257 <<
")), " << operand <<
'\n';
258 O <<
"\tadd\t" << operand <<
", %o7, " << operand <<
'\n';
263 void SparcAsmPrinter::printCCOperand(
const MachineInstr *MI,
int opNum,
271 bool SparcAsmPrinter::PrintAsmOperand(
const MachineInstr *MI,
unsigned OpNo,
273 const char *ExtraCode,
275 if (ExtraCode && ExtraCode[0]) {
276 if (ExtraCode[1] != 0)
return true;
278 switch (ExtraCode[0]) {
287 printOperand(MI, OpNo, O);
292 bool SparcAsmPrinter::PrintAsmMemoryOperand(
const MachineInstr *MI,
293 unsigned OpNo,
unsigned AsmVariant,
294 const char *ExtraCode,
296 if (ExtraCode && ExtraCode[0])
300 printMemOperand(MI, OpNo, O);
311 bool SparcAsmPrinter::
332 while (I != Pred->
begin() && !(--
I)->isTerminator())
334 return I == Pred->
end() || !I->isBarrier();
int strcmp(const char *s1, const char *s2);
const MachineFunction * getParent() const
const GlobalValue * getGlobal() const
MachineBasicBlock * getMBB() const
const char * getSymbolName() const
unsigned getFunctionNumber() const
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
static const char * SPARCCondCodeToString(SPCC::CondCodes CC)
#define llvm_unreachable(msg)
bool isReg() const
isReg - Tests if this is a MO_Register 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.
Address of indexed Constant in Constant Pool.
const MachineBasicBlock * getParent() const
unsigned getTargetFlags() const
const MachineOperand & getOperand(unsigned i) const
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS)
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
pred_iterator pred_begin()
MCSymbol * getSymbol() const
std::vector< MachineBasicBlock * >::const_iterator const_pred_iterator
void LLVMInitializeSparcAsmPrinter()
MachineOperandType getType() const
bundle_iterator< const MachineInstr, const_instr_iterator > const_iterator
static bool isPhysicalRegister(unsigned Reg)
bool isLandingPad() const
std::string getName(ID id, ArrayRef< Type * > Tys=None)
unsigned getReg() const
getReg - Returns the register number.
Address of a basic block.
bool isPhysRegUsed(unsigned Reg) const
const BlockAddress * getBlockAddress() const
const MCRegisterInfo & MRI
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
bool isLayoutSuccessor(const MachineBasicBlock *MBB) const
static RegisterPass< NVPTXAllocaHoisting > X("alloca-hoisting","Hoisting alloca instructions in non-entry ""blocks to the entry block")
std::string lower() const
MachineBasicBlock reference.
Address of a global value.
Name of external global symbol.