LLVM API Documentation
00001 //===-- MipsAsmPrinter.h - Mips LLVM Assembly Printer ----------*- C++ -*--===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // Mips Assembly printer class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_LIB_TARGET_MIPS_MIPSASMPRINTER_H 00015 #define LLVM_LIB_TARGET_MIPS_MIPSASMPRINTER_H 00016 00017 #include "Mips16HardFloatInfo.h" 00018 #include "MipsMCInstLower.h" 00019 #include "MipsMachineFunction.h" 00020 #include "MipsSubtarget.h" 00021 #include "llvm/CodeGen/AsmPrinter.h" 00022 #include "llvm/Support/Compiler.h" 00023 #include "llvm/Target/TargetMachine.h" 00024 00025 namespace llvm { 00026 class MCStreamer; 00027 class MachineInstr; 00028 class MachineBasicBlock; 00029 class MipsTargetStreamer; 00030 class Module; 00031 class raw_ostream; 00032 00033 class LLVM_LIBRARY_VISIBILITY MipsAsmPrinter : public AsmPrinter { 00034 MipsTargetStreamer &getTargetStreamer(); 00035 00036 void EmitInstrWithMacroNoAT(const MachineInstr *MI); 00037 00038 private: 00039 // tblgen'erated function. 00040 bool emitPseudoExpansionLowering(MCStreamer &OutStreamer, 00041 const MachineInstr *MI); 00042 00043 // Emit PseudoReturn, PseudoReturn64, PseudoIndirectBranch, 00044 // and PseudoIndirectBranch64 as a JR, JR_MM, JALR, or JALR64 as appropriate 00045 // for the target. 00046 void emitPseudoIndirectBranch(MCStreamer &OutStreamer, 00047 const MachineInstr *MI); 00048 00049 // lowerOperand - Convert a MachineOperand into the equivalent MCOperand. 00050 bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp); 00051 00052 /// MCP - Keep a pointer to constantpool entries of the current 00053 /// MachineFunction. 00054 const MachineConstantPool *MCP; 00055 00056 /// InConstantPool - Maintain state when emitting a sequence of constant 00057 /// pool entries so we can properly mark them as data regions. 00058 bool InConstantPool; 00059 00060 std::map<const char *, const llvm::Mips16HardFloatInfo::FuncSignature *> 00061 StubsNeeded; 00062 00063 void EmitJal(MCSymbol *Symbol); 00064 00065 void EmitInstrReg(unsigned Opcode, unsigned Reg); 00066 00067 void EmitInstrRegReg(unsigned Opcode, unsigned Reg1, unsigned Reg2); 00068 00069 void EmitInstrRegRegReg(unsigned Opcode, unsigned Reg1, unsigned Reg2, 00070 unsigned Reg3); 00071 00072 void EmitMovFPIntPair(unsigned MovOpc, unsigned Reg1, unsigned Reg2, 00073 unsigned FPReg1, unsigned FPReg2, bool LE); 00074 00075 void EmitSwapFPIntParams(Mips16HardFloatInfo::FPParamVariant, bool LE, 00076 bool ToFP); 00077 00078 void EmitSwapFPIntRetval(Mips16HardFloatInfo::FPReturnVariant, bool LE); 00079 00080 void EmitFPCallStub(const char *, const Mips16HardFloatInfo::FuncSignature *); 00081 00082 void NaClAlignIndirectJumpTargets(MachineFunction &MF); 00083 00084 bool isLongBranchPseudo(int Opcode) const; 00085 00086 public: 00087 00088 const MipsSubtarget *Subtarget; 00089 const MipsFunctionInfo *MipsFI; 00090 MipsMCInstLower MCInstLowering; 00091 00092 // We initialize the subtarget here and in runOnMachineFunction 00093 // since there are certain target specific flags (ABI) that could 00094 // reside on the TargetMachine, but are on the subtarget currently 00095 // and we need them for the beginning of file output before we've 00096 // seen a single function. 00097 explicit MipsAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) 00098 : AsmPrinter(TM, Streamer), MCP(nullptr), InConstantPool(false), 00099 Subtarget(&TM.getSubtarget<MipsSubtarget>()), MCInstLowering(*this) {} 00100 00101 const char *getPassName() const override { 00102 return "Mips Assembly Printer"; 00103 } 00104 00105 bool runOnMachineFunction(MachineFunction &MF) override; 00106 00107 void EmitConstantPool() override { 00108 bool UsingConstantPools = 00109 (Subtarget->inMips16Mode() && Subtarget->useConstantIslands()); 00110 if (!UsingConstantPools) 00111 AsmPrinter::EmitConstantPool(); 00112 // we emit constant pools customly! 00113 } 00114 00115 void EmitInstruction(const MachineInstr *MI) override; 00116 void printSavedRegsBitmask(); 00117 void emitFrameDirective(); 00118 const char *getCurrentABIString() const; 00119 void EmitFunctionEntryLabel() override; 00120 void EmitFunctionBodyStart() override; 00121 void EmitFunctionBodyEnd() override; 00122 bool isBlockOnlyReachableByFallthrough( 00123 const MachineBasicBlock* MBB) const override; 00124 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, 00125 unsigned AsmVariant, const char *ExtraCode, 00126 raw_ostream &O) override; 00127 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum, 00128 unsigned AsmVariant, const char *ExtraCode, 00129 raw_ostream &O) override; 00130 void printOperand(const MachineInstr *MI, int opNum, raw_ostream &O); 00131 void printUnsignedImm(const MachineInstr *MI, int opNum, raw_ostream &O); 00132 void printUnsignedImm8(const MachineInstr *MI, int opNum, raw_ostream &O); 00133 void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &O); 00134 void printMemOperandEA(const MachineInstr *MI, int opNum, raw_ostream &O); 00135 void printFCCOperand(const MachineInstr *MI, int opNum, raw_ostream &O, 00136 const char *Modifier = nullptr); 00137 void EmitStartOfAsmFile(Module &M) override; 00138 void EmitEndOfAsmFile(Module &M) override; 00139 void PrintDebugValueComment(const MachineInstr *MI, raw_ostream &OS); 00140 }; 00141 } 00142 00143 #endif 00144