1 //===-- MipsAsmPrinter.h - Mips LLVM Assembly Printer ----------*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Mips Assembly printer class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_MIPS_MIPSASMPRINTER_H
15 #define LLVM_LIB_TARGET_MIPS_MIPSASMPRINTER_H
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"
28 class MachineBasicBlock;
29 class MipsTargetStreamer;
33 class LLVM_LIBRARY_VISIBILITY MipsAsmPrinter : public AsmPrinter {
34 MipsTargetStreamer &getTargetStreamer();
36 void EmitInstrWithMacroNoAT(const MachineInstr *MI);
39 // tblgen'erated function.
40 bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
41 const MachineInstr *MI);
43 // Emit PseudoReturn, PseudoReturn64, PseudoIndirectBranch,
44 // and PseudoIndirectBranch64 as a JR, JR_MM, JALR, or JALR64 as appropriate
46 void emitPseudoIndirectBranch(MCStreamer &OutStreamer,
47 const MachineInstr *MI);
49 // lowerOperand - Convert a MachineOperand into the equivalent MCOperand.
50 bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp);
52 /// MCP - Keep a pointer to constantpool entries of the current
54 const MachineConstantPool *MCP;
56 /// InConstantPool - Maintain state when emitting a sequence of constant
57 /// pool entries so we can properly mark them as data regions.
60 std::map<const char *, const llvm::Mips16HardFloatInfo::FuncSignature *>
63 void EmitJal(MCSymbol *Symbol);
65 void EmitInstrReg(unsigned Opcode, unsigned Reg);
67 void EmitInstrRegReg(unsigned Opcode, unsigned Reg1, unsigned Reg2);
69 void EmitInstrRegRegReg(unsigned Opcode, unsigned Reg1, unsigned Reg2,
72 void EmitMovFPIntPair(unsigned MovOpc, unsigned Reg1, unsigned Reg2,
73 unsigned FPReg1, unsigned FPReg2, bool LE);
75 void EmitSwapFPIntParams(Mips16HardFloatInfo::FPParamVariant, bool LE,
78 void EmitSwapFPIntRetval(Mips16HardFloatInfo::FPReturnVariant, bool LE);
80 void EmitFPCallStub(const char *, const Mips16HardFloatInfo::FuncSignature *);
82 void NaClAlignIndirectJumpTargets(MachineFunction &MF);
84 bool isLongBranchPseudo(int Opcode) const;
88 const MipsSubtarget *Subtarget;
89 const MipsFunctionInfo *MipsFI;
90 MipsMCInstLower MCInstLowering;
92 // We initialize the subtarget here and in runOnMachineFunction
93 // since there are certain target specific flags (ABI) that could
94 // reside on the TargetMachine, but are on the subtarget currently
95 // and we need them for the beginning of file output before we've
96 // seen a single function.
97 explicit MipsAsmPrinter(TargetMachine &TM, MCStreamer &Streamer)
98 : AsmPrinter(TM, Streamer), MCP(nullptr), InConstantPool(false),
99 Subtarget(&TM.getSubtarget<MipsSubtarget>()), MCInstLowering(*this) {}
101 const char *getPassName() const override {
102 return "Mips Assembly Printer";
105 bool runOnMachineFunction(MachineFunction &MF) override;
107 void EmitConstantPool() override {
108 bool UsingConstantPools =
109 (Subtarget->inMips16Mode() && Subtarget->useConstantIslands());
110 if (!UsingConstantPools)
111 AsmPrinter::EmitConstantPool();
112 // we emit constant pools customly!
115 void EmitInstruction(const MachineInstr *MI) override;
116 void printSavedRegsBitmask();
117 void emitFrameDirective();
118 const char *getCurrentABIString() const;
119 void EmitFunctionEntryLabel() override;
120 void EmitFunctionBodyStart() override;
121 void EmitFunctionBodyEnd() override;
122 bool isBlockOnlyReachableByFallthrough(
123 const MachineBasicBlock* MBB) const override;
124 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
125 unsigned AsmVariant, const char *ExtraCode,
126 raw_ostream &O) override;
127 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
128 unsigned AsmVariant, const char *ExtraCode,
129 raw_ostream &O) override;
130 void printOperand(const MachineInstr *MI, int opNum, raw_ostream &O);
131 void printUnsignedImm(const MachineInstr *MI, int opNum, raw_ostream &O);
132 void printUnsignedImm8(const MachineInstr *MI, int opNum, raw_ostream &O);
133 void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &O);
134 void printMemOperandEA(const MachineInstr *MI, int opNum, raw_ostream &O);
135 void printFCCOperand(const MachineInstr *MI, int opNum, raw_ostream &O,
136 const char *Modifier = nullptr);
137 void EmitStartOfAsmFile(Module &M) override;
138 void EmitEndOfAsmFile(Module &M) override;
139 void PrintDebugValueComment(const MachineInstr *MI, raw_ostream &OS);