]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/Mips/MipsAsmPrinter.h
Merge ^/head r327169 through r327340.
[FreeBSD/FreeBSD.git] / contrib / llvm / 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 "MipsSubtarget.h"
20 #include "llvm/CodeGen/AsmPrinter.h"
21 #include "llvm/MC/MCStreamer.h"
22 #include "llvm/Support/Compiler.h"
23 #include <algorithm>
24 #include <map>
25 #include <memory>
26
27 namespace llvm {
28
29 class MCOperand;
30 class MCSubtargetInfo;
31 class MCSymbol;
32 class MachineBasicBlock;
33 class MachineConstantPool;
34 class MachineFunction;
35 class MachineInstr;
36 class MachineOperand;
37 class MipsFunctionInfo;
38 class MipsTargetStreamer;
39 class Module;
40 class raw_ostream;
41 class TargetMachine;
42
43 class LLVM_LIBRARY_VISIBILITY MipsAsmPrinter : public AsmPrinter {
44   MipsTargetStreamer &getTargetStreamer() const;
45
46   void EmitInstrWithMacroNoAT(const MachineInstr *MI);
47
48   //===------------------------------------------------------------------===//
49   // XRay implementation
50   //===------------------------------------------------------------------===//
51
52 public:
53   // XRay-specific lowering for Mips.
54   void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI);
55   void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr &MI);
56   void LowerPATCHABLE_TAIL_CALL(const MachineInstr &MI);
57
58 private:
59   /// MCP - Keep a pointer to constantpool entries of the current
60   /// MachineFunction.
61   const MachineConstantPool *MCP = nullptr;
62
63   /// InConstantPool - Maintain state when emitting a sequence of constant
64   /// pool entries so we can properly mark them as data regions.
65   bool InConstantPool = false;
66
67   std::map<const char *, const Mips16HardFloatInfo::FuncSignature *>
68       StubsNeeded;
69
70   void EmitSled(const MachineInstr &MI, SledKind Kind);
71
72   // tblgen'erated function.
73   bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,
74                                    const MachineInstr *MI);
75
76   // Emit PseudoReturn, PseudoReturn64, PseudoIndirectBranch,
77   // and PseudoIndirectBranch64 as a JR, JR_MM, JALR, or JALR64 as appropriate
78   // for the target.
79   void emitPseudoIndirectBranch(MCStreamer &OutStreamer,
80                                 const MachineInstr *MI);
81
82   // lowerOperand - Convert a MachineOperand into the equivalent MCOperand.
83   bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp);
84
85   void emitInlineAsmStart() const override;
86
87   void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
88                         const MCSubtargetInfo *EndInfo) const override;
89
90   void EmitJal(const MCSubtargetInfo &STI, MCSymbol *Symbol);
91
92   void EmitInstrReg(const MCSubtargetInfo &STI, unsigned Opcode, unsigned Reg);
93
94   void EmitInstrRegReg(const MCSubtargetInfo &STI, unsigned Opcode,
95                        unsigned Reg1, unsigned Reg2);
96
97   void EmitInstrRegRegReg(const MCSubtargetInfo &STI, unsigned Opcode,
98                           unsigned Reg1, unsigned Reg2, unsigned Reg3);
99
100   void EmitMovFPIntPair(const MCSubtargetInfo &STI, unsigned MovOpc,
101                         unsigned Reg1, unsigned Reg2, unsigned FPReg1,
102                         unsigned FPReg2, bool LE);
103
104   void EmitSwapFPIntParams(const MCSubtargetInfo &STI,
105                            Mips16HardFloatInfo::FPParamVariant, bool LE,
106                            bool ToFP);
107
108   void EmitSwapFPIntRetval(const MCSubtargetInfo &STI,
109                            Mips16HardFloatInfo::FPReturnVariant, bool LE);
110
111   void EmitFPCallStub(const char *, const Mips16HardFloatInfo::FuncSignature *);
112
113   void NaClAlignIndirectJumpTargets(MachineFunction &MF);
114
115   bool isLongBranchPseudo(int Opcode) const;
116
117 public:
118   const MipsSubtarget *Subtarget;
119   const MipsFunctionInfo *MipsFI;
120   MipsMCInstLower MCInstLowering;
121
122   explicit MipsAsmPrinter(TargetMachine &TM,
123                           std::unique_ptr<MCStreamer> Streamer)
124       : AsmPrinter(TM, std::move(Streamer)), MCInstLowering(*this) {}
125
126   StringRef getPassName() const override { return "Mips Assembly Printer"; }
127
128   bool runOnMachineFunction(MachineFunction &MF) override;
129
130   void EmitConstantPool() override {
131     bool UsingConstantPools =
132       (Subtarget->inMips16Mode() && Subtarget->useConstantIslands());
133     if (!UsingConstantPools)
134       AsmPrinter::EmitConstantPool();
135     // we emit constant pools customly!
136   }
137
138   void EmitInstruction(const MachineInstr *MI) override;
139   void printSavedRegsBitmask();
140   void emitFrameDirective();
141   const char *getCurrentABIString() const;
142   void EmitFunctionEntryLabel() override;
143   void EmitFunctionBodyStart() override;
144   void EmitFunctionBodyEnd() override;
145   void EmitBasicBlockEnd(const MachineBasicBlock &MBB) override;
146   bool isBlockOnlyReachableByFallthrough(
147                                    const MachineBasicBlock* MBB) const override;
148   bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
149                        unsigned AsmVariant, const char *ExtraCode,
150                        raw_ostream &O) override;
151   bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,
152                              unsigned AsmVariant, const char *ExtraCode,
153                              raw_ostream &O) override;
154   void printOperand(const MachineInstr *MI, int opNum, raw_ostream &O);
155   void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &O);
156   void printMemOperandEA(const MachineInstr *MI, int opNum, raw_ostream &O);
157   void printFCCOperand(const MachineInstr *MI, int opNum, raw_ostream &O,
158                        const char *Modifier = nullptr);
159   void printRegisterList(const MachineInstr *MI, int opNum, raw_ostream &O);
160   void EmitStartOfAsmFile(Module &M) override;
161   void EmitEndOfAsmFile(Module &M) override;
162   void PrintDebugValueComment(const MachineInstr *MI, raw_ostream &OS);
163   void EmitDebugThreadLocal(const MCExpr *Value, unsigned Size) const override;
164 };
165
166 } // end namespace llvm
167
168 #endif // LLVM_LIB_TARGET_MIPS_MIPSASMPRINTER_H