Have the MipsAsmPrinter fp stub emission code take a custom
[oota-llvm.git] / lib / Target / Mips / MipsAsmPrinter.h
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 LLVM_LIB_TARGET_MIPS_MIPSASMPRINTER_H
15 #define LLVM_LIB_TARGET_MIPS_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() const;
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 emitInlineAsmStart() const override;
64
65   void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
66                         const MCSubtargetInfo *EndInfo) const override;
67
68   void EmitJal(const MCSubtargetInfo &STI, MCSymbol *Symbol);
69
70   void EmitInstrReg(const MCSubtargetInfo &STI, unsigned Opcode, unsigned Reg);
71
72   void EmitInstrRegReg(const MCSubtargetInfo &STI, unsigned Opcode,
73                        unsigned Reg1, unsigned Reg2);
74
75   void EmitInstrRegRegReg(const MCSubtargetInfo &STI, unsigned Opcode,
76                           unsigned Reg1, unsigned Reg2, unsigned Reg3);
77
78   void EmitMovFPIntPair(const MCSubtargetInfo &STI, unsigned MovOpc,
79                         unsigned Reg1, unsigned Reg2, unsigned FPReg1,
80                         unsigned FPReg2, bool LE);
81
82   void EmitSwapFPIntParams(const MCSubtargetInfo &STI,
83                            Mips16HardFloatInfo::FPParamVariant, bool LE,
84                            bool ToFP);
85
86   void EmitSwapFPIntRetval(const MCSubtargetInfo &STI,
87                            Mips16HardFloatInfo::FPReturnVariant, bool LE);
88
89   void EmitFPCallStub(const char *, const Mips16HardFloatInfo::FuncSignature *);
90
91   void NaClAlignIndirectJumpTargets(MachineFunction &MF);
92
93   bool isLongBranchPseudo(int Opcode) const;
94
95 public:
96
97   const MipsSubtarget *Subtarget;
98   const MipsFunctionInfo *MipsFI;
99   MipsMCInstLower MCInstLowering;
100
101   // We initialize the subtarget here and in runOnMachineFunction
102   // since there are certain target specific flags (ABI) that could
103   // reside on the TargetMachine, but are on the subtarget currently
104   // and we need them for the beginning of file output before we've
105   // seen a single function.
106   explicit MipsAsmPrinter(TargetMachine &TM,
107                           std::unique_ptr<MCStreamer> Streamer)
108       : AsmPrinter(TM, std::move(Streamer)), MCP(nullptr),
109         InConstantPool(false), MCInstLowering(*this) {}
110
111   const char *getPassName() const override {
112     return "Mips Assembly Printer";
113   }
114
115   bool runOnMachineFunction(MachineFunction &MF) override;
116
117   void EmitConstantPool() override {
118     bool UsingConstantPools =
119       (Subtarget->inMips16Mode() && Subtarget->useConstantIslands());
120     if (!UsingConstantPools)
121       AsmPrinter::EmitConstantPool();
122     // we emit constant pools customly!
123   }
124
125   void EmitInstruction(const MachineInstr *MI) override;
126   void printSavedRegsBitmask();
127   void emitFrameDirective();
128   const char *getCurrentABIString() const;
129   void EmitFunctionEntryLabel() override;
130   void EmitFunctionBodyStart() override;
131   void EmitFunctionBodyEnd() override;
132   bool isBlockOnlyReachableByFallthrough(
133                                    const MachineBasicBlock* MBB) const override;
134   bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
135                        unsigned AsmVariant, const char *ExtraCode,
136                        raw_ostream &O) override;
137   bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
138                              unsigned AsmVariant, const char *ExtraCode,
139                              raw_ostream &O) override;
140   void printOperand(const MachineInstr *MI, int opNum, raw_ostream &O);
141   void printUnsignedImm(const MachineInstr *MI, int opNum, raw_ostream &O);
142   void printUnsignedImm8(const MachineInstr *MI, int opNum, raw_ostream &O);
143   void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &O);
144   void printMemOperandEA(const MachineInstr *MI, int opNum, raw_ostream &O);
145   void printFCCOperand(const MachineInstr *MI, int opNum, raw_ostream &O,
146                        const char *Modifier = nullptr);
147   void printRegisterList(const MachineInstr *MI, int opNum, raw_ostream &O);
148   void EmitStartOfAsmFile(Module &M) override;
149   void EmitEndOfAsmFile(Module &M) override;
150   void PrintDebugValueComment(const MachineInstr *MI, raw_ostream &OS);
151 };
152 }
153
154 #endif
155