1 //===-- MipsAsmPrinter.h - Mips LLVM Assembly Printer ----------*- C++ -*--===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // Mips Assembly printer class. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef MIPSASMPRINTER_H 15 #define MIPSASMPRINTER_H 16 17 #include "Mips16HardFloatInfo.h" 18 #include "MipsMCInstLower.h" 19 #include "MipsMachineFunction.h" 20 #include "MipsSubtarget.h" 21 #include "llvm/CodeGen/AsmPrinter.h" 22 #include "llvm/Support/Compiler.h" 23 #include "llvm/Target/TargetMachine.h" 24 25 namespace llvm { 26 class MCStreamer; 27 class MachineInstr; 28 class MachineBasicBlock; 29 class MipsTargetStreamer; 30 class Module; 31 class raw_ostream; 32 33 class LLVM_LIBRARY_VISIBILITY MipsAsmPrinter : public AsmPrinter { 34 MipsTargetStreamer &getTargetStreamer(); 35 36 void EmitInstrWithMacroNoAT(const MachineInstr *MI); 37 38 private: 39 // tblgen'erated function. 40 bool emitPseudoExpansionLowering(MCStreamer &OutStreamer, 41 const MachineInstr *MI); 42 43 // Emit PseudoReturn, PseudoReturn64, PseudoIndirectBranch, 44 // and PseudoIndirectBranch64 as a JR, JR_MM, JALR, or JALR64 as appropriate 45 // for the target. 46 void emitPseudoIndirectBranch(MCStreamer &OutStreamer, 47 const MachineInstr *MI); 48 49 // lowerOperand - Convert a MachineOperand into the equivalent MCOperand. 50 bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp); 51 52 /// MCP - Keep a pointer to constantpool entries of the current 53 /// MachineFunction. 54 const MachineConstantPool *MCP; 55 56 /// InConstantPool - Maintain state when emitting a sequence of constant 57 /// pool entries so we can properly mark them as data regions. 58 bool InConstantPool; 59 60 std::map<const char *, const llvm::Mips16HardFloatInfo::FuncSignature *> 61 StubsNeeded; 62 63 void EmitJal(MCSymbol *Symbol); 64 65 void EmitInstrReg(unsigned Opcode, unsigned Reg); 66 67 void EmitInstrRegReg(unsigned Opcode, unsigned Reg1, unsigned Reg2); 68 69 void EmitInstrRegRegReg(unsigned Opcode, unsigned Reg1, unsigned Reg2, 70 unsigned Reg3); 71 72 void EmitMovFPIntPair(unsigned MovOpc, unsigned Reg1, unsigned Reg2, 73 unsigned FPReg1, unsigned FPReg2, bool LE); 74 75 void EmitSwapFPIntParams(Mips16HardFloatInfo::FPParamVariant, bool LE, 76 bool ToFP); 77 78 void EmitSwapFPIntRetval(Mips16HardFloatInfo::FPReturnVariant, bool LE); 79 80 void EmitFPCallStub(const char *, const Mips16HardFloatInfo::FuncSignature *); 81 82 void NaClAlignIndirectJumpTargets(MachineFunction &MF); 83 84 bool isLongBranchPseudo(int Opcode) const; 85 86 public: 87 88 const MipsSubtarget *Subtarget; 89 const MipsFunctionInfo *MipsFI; 90 MipsMCInstLower MCInstLowering; 91 92 explicit MipsAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) 93 : AsmPrinter(TM, Streamer), MCP(nullptr), InConstantPool(false), 94 MCInstLowering(*this) { 95 Subtarget = &TM.getSubtarget<MipsSubtarget>(); 96 } 97 98 const char *getPassName() const override { 99 return "Mips Assembly Printer"; 100 } 101 102 bool runOnMachineFunction(MachineFunction &MF) override; 103 104 void EmitConstantPool() override { 105 bool UsingConstantPools = 106 (Subtarget->inMips16Mode() && Subtarget->useConstantIslands()); 107 if (!UsingConstantPools) 108 AsmPrinter::EmitConstantPool(); 109 // we emit constant pools customly! 110 } 111 112 void EmitInstruction(const MachineInstr *MI) override; 113 void printSavedRegsBitmask(); 114 void emitFrameDirective(); 115 const char *getCurrentABIString() const; 116 void EmitFunctionEntryLabel() override; 117 void EmitFunctionBodyStart() override; 118 void EmitFunctionBodyEnd() override; 119 bool isBlockOnlyReachableByFallthrough( 120 const MachineBasicBlock* MBB) const override; 121 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, 122 unsigned AsmVariant, const char *ExtraCode, 123 raw_ostream &O) override; 124 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum, 125 unsigned AsmVariant, const char *ExtraCode, 126 raw_ostream &O) override; 127 void printOperand(const MachineInstr *MI, int opNum, raw_ostream &O); 128 void printUnsignedImm(const MachineInstr *MI, int opNum, raw_ostream &O); 129 void printUnsignedImm8(const MachineInstr *MI, int opNum, raw_ostream &O); 130 void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &O); 131 void printMemOperandEA(const MachineInstr *MI, int opNum, raw_ostream &O); 132 void printFCCOperand(const MachineInstr *MI, int opNum, raw_ostream &O, 133 const char *Modifier = nullptr); 134 void EmitStartOfAsmFile(Module &M) override; 135 void EmitEndOfAsmFile(Module &M) override; 136 void PrintDebugValueComment(const MachineInstr *MI, raw_ostream &OS); 137 }; 138 } 139 140 #endif 141 142