]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/Mips/MipsTargetStreamer.h
MFV: r325668
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / Mips / MipsTargetStreamer.h
1 //===-- MipsTargetStreamer.h - Mips Target Streamer ------------*- 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 #ifndef LLVM_LIB_TARGET_MIPS_MIPSTARGETSTREAMER_H
11 #define LLVM_LIB_TARGET_MIPS_MIPSTARGETSTREAMER_H
12
13 #include "MCTargetDesc/MipsABIFlagsSection.h"
14 #include "MCTargetDesc/MipsABIInfo.h"
15 #include "llvm/ADT/Optional.h"
16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/MC/MCELFStreamer.h"
18 #include "llvm/MC/MCRegisterInfo.h"
19 #include "llvm/MC/MCStreamer.h"
20
21 namespace llvm {
22
23 struct MipsABIFlagsSection;
24
25 class MipsTargetStreamer : public MCTargetStreamer {
26 public:
27   MipsTargetStreamer(MCStreamer &S);
28
29   virtual void setPic(bool Value) {}
30
31   virtual void emitDirectiveSetMicroMips();
32   virtual void emitDirectiveSetNoMicroMips();
33   virtual void setUsesMicroMips();
34   virtual void emitDirectiveSetMips16();
35   virtual void emitDirectiveSetNoMips16();
36
37   virtual void emitDirectiveSetReorder();
38   virtual void emitDirectiveSetNoReorder();
39   virtual void emitDirectiveSetMacro();
40   virtual void emitDirectiveSetNoMacro();
41   virtual void emitDirectiveSetMsa();
42   virtual void emitDirectiveSetNoMsa();
43   virtual void emitDirectiveSetMt();
44   virtual void emitDirectiveSetNoMt();
45   virtual void emitDirectiveSetAt();
46   virtual void emitDirectiveSetAtWithArg(unsigned RegNo);
47   virtual void emitDirectiveSetNoAt();
48   virtual void emitDirectiveEnd(StringRef Name);
49
50   virtual void emitDirectiveEnt(const MCSymbol &Symbol);
51   virtual void emitDirectiveAbiCalls();
52   virtual void emitDirectiveNaN2008();
53   virtual void emitDirectiveNaNLegacy();
54   virtual void emitDirectiveOptionPic0();
55   virtual void emitDirectiveOptionPic2();
56   virtual void emitDirectiveInsn();
57   virtual void emitFrame(unsigned StackReg, unsigned StackSize,
58                          unsigned ReturnReg);
59   virtual void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff);
60   virtual void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff);
61
62   virtual void emitDirectiveSetArch(StringRef Arch);
63   virtual void emitDirectiveSetMips0();
64   virtual void emitDirectiveSetMips1();
65   virtual void emitDirectiveSetMips2();
66   virtual void emitDirectiveSetMips3();
67   virtual void emitDirectiveSetMips4();
68   virtual void emitDirectiveSetMips5();
69   virtual void emitDirectiveSetMips32();
70   virtual void emitDirectiveSetMips32R2();
71   virtual void emitDirectiveSetMips32R3();
72   virtual void emitDirectiveSetMips32R5();
73   virtual void emitDirectiveSetMips32R6();
74   virtual void emitDirectiveSetMips64();
75   virtual void emitDirectiveSetMips64R2();
76   virtual void emitDirectiveSetMips64R3();
77   virtual void emitDirectiveSetMips64R5();
78   virtual void emitDirectiveSetMips64R6();
79   virtual void emitDirectiveSetDsp();
80   virtual void emitDirectiveSetNoDsp();
81   virtual void emitDirectiveSetPop();
82   virtual void emitDirectiveSetPush();
83   virtual void emitDirectiveSetSoftFloat();
84   virtual void emitDirectiveSetHardFloat();
85
86   // PIC support
87   virtual void emitDirectiveCpLoad(unsigned RegNo);
88   virtual bool emitDirectiveCpRestore(int Offset,
89                                       function_ref<unsigned()> GetATReg,
90                                       SMLoc IDLoc, const MCSubtargetInfo *STI);
91   virtual void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
92                                     const MCSymbol &Sym, bool IsReg);
93   virtual void emitDirectiveCpreturn(unsigned SaveLocation,
94                                      bool SaveLocationIsRegister);
95
96   // FP abiflags directives
97   virtual void emitDirectiveModuleFP();
98   virtual void emitDirectiveModuleOddSPReg();
99   virtual void emitDirectiveModuleSoftFloat();
100   virtual void emitDirectiveModuleHardFloat();
101   virtual void emitDirectiveModuleMT();
102   virtual void emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value);
103   virtual void emitDirectiveSetOddSPReg();
104   virtual void emitDirectiveSetNoOddSPReg();
105
106   void emitR(unsigned Opcode, unsigned Reg0, SMLoc IDLoc,
107              const MCSubtargetInfo *STI);
108   void emitII(unsigned Opcode, int16_t Imm1, int16_t Imm2, SMLoc IDLoc,
109               const MCSubtargetInfo *STI);
110   void emitRX(unsigned Opcode, unsigned Reg0, MCOperand Op1, SMLoc IDLoc,
111               const MCSubtargetInfo *STI);
112   void emitRI(unsigned Opcode, unsigned Reg0, int32_t Imm, SMLoc IDLoc,
113               const MCSubtargetInfo *STI);
114   void emitRR(unsigned Opcode, unsigned Reg0, unsigned Reg1, SMLoc IDLoc,
115               const MCSubtargetInfo *STI);
116   void emitRRX(unsigned Opcode, unsigned Reg0, unsigned Reg1, MCOperand Op2,
117                SMLoc IDLoc, const MCSubtargetInfo *STI);
118   void emitRRR(unsigned Opcode, unsigned Reg0, unsigned Reg1, unsigned Reg2,
119                SMLoc IDLoc, const MCSubtargetInfo *STI);
120   void emitRRI(unsigned Opcode, unsigned Reg0, unsigned Reg1, int16_t Imm,
121                SMLoc IDLoc, const MCSubtargetInfo *STI);
122   void emitAddu(unsigned DstReg, unsigned SrcReg, unsigned TrgReg, bool Is64Bit,
123                 const MCSubtargetInfo *STI);
124   void emitDSLL(unsigned DstReg, unsigned SrcReg, int16_t ShiftAmount,
125                 SMLoc IDLoc, const MCSubtargetInfo *STI);
126   void emitEmptyDelaySlot(bool hasShortDelaySlot, SMLoc IDLoc,
127                           const MCSubtargetInfo *STI);
128   void emitNop(SMLoc IDLoc, const MCSubtargetInfo *STI);
129
130   /// Emit a store instruction with an offset. If the offset is out of range
131   /// then it will be synthesized using the assembler temporary.
132   ///
133   /// GetATReg() is a callback that can be used to obtain the current assembler
134   /// temporary and is only called when the assembler temporary is required. It
135   /// must handle the case where no assembler temporary is available (typically
136   /// by reporting an error).
137   void emitStoreWithImmOffset(unsigned Opcode, unsigned SrcReg,
138                               unsigned BaseReg, int64_t Offset,
139                               function_ref<unsigned()> GetATReg, SMLoc IDLoc,
140                               const MCSubtargetInfo *STI);
141   void emitStoreWithSymOffset(unsigned Opcode, unsigned SrcReg,
142                               unsigned BaseReg, MCOperand &HiOperand,
143                               MCOperand &LoOperand, unsigned ATReg, SMLoc IDLoc,
144                               const MCSubtargetInfo *STI);
145   void emitLoadWithImmOffset(unsigned Opcode, unsigned DstReg, unsigned BaseReg,
146                              int64_t Offset, unsigned TmpReg, SMLoc IDLoc,
147                              const MCSubtargetInfo *STI);
148   void emitLoadWithSymOffset(unsigned Opcode, unsigned DstReg, unsigned BaseReg,
149                              MCOperand &HiOperand, MCOperand &LoOperand,
150                              unsigned ATReg, SMLoc IDLoc,
151                              const MCSubtargetInfo *STI);
152   void emitGPRestore(int Offset, SMLoc IDLoc, const MCSubtargetInfo *STI);
153
154   void forbidModuleDirective() { ModuleDirectiveAllowed = false; }
155   void reallowModuleDirective() { ModuleDirectiveAllowed = true; }
156   bool isModuleDirectiveAllowed() { return ModuleDirectiveAllowed; }
157
158   // This method enables template classes to set internal abi flags
159   // structure values.
160   template <class PredicateLibrary>
161   void updateABIInfo(const PredicateLibrary &P) {
162     ABI = P.getABI();
163     ABIFlagsSection.setAllFromPredicates(P);
164   }
165
166   MipsABIFlagsSection &getABIFlagsSection() { return ABIFlagsSection; }
167   const MipsABIInfo &getABI() const {
168     assert(ABI.hasValue() && "ABI hasn't been set!");
169     return *ABI;
170   }
171
172 protected:
173   llvm::Optional<MipsABIInfo> ABI;
174   MipsABIFlagsSection ABIFlagsSection;
175
176   bool GPRInfoSet;
177   unsigned GPRBitMask;
178   int GPROffset;
179
180   bool FPRInfoSet;
181   unsigned FPRBitMask;
182   int FPROffset;
183
184   bool FrameInfoSet;
185   int FrameOffset;
186   unsigned FrameReg;
187   unsigned ReturnReg;
188
189 private:
190   bool ModuleDirectiveAllowed;
191 };
192
193 // This part is for ascii assembly output
194 class MipsTargetAsmStreamer : public MipsTargetStreamer {
195   formatted_raw_ostream &OS;
196
197 public:
198   MipsTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
199   void emitDirectiveSetMicroMips() override;
200   void emitDirectiveSetNoMicroMips() override;
201   void emitDirectiveSetMips16() override;
202   void emitDirectiveSetNoMips16() override;
203
204   void emitDirectiveSetReorder() override;
205   void emitDirectiveSetNoReorder() override;
206   void emitDirectiveSetMacro() override;
207   void emitDirectiveSetNoMacro() override;
208   void emitDirectiveSetMsa() override;
209   void emitDirectiveSetNoMsa() override;
210   void emitDirectiveSetMt() override;
211   void emitDirectiveSetNoMt() override;
212   void emitDirectiveSetAt() override;
213   void emitDirectiveSetAtWithArg(unsigned RegNo) override;
214   void emitDirectiveSetNoAt() override;
215   void emitDirectiveEnd(StringRef Name) override;
216
217   void emitDirectiveEnt(const MCSymbol &Symbol) override;
218   void emitDirectiveAbiCalls() override;
219   void emitDirectiveNaN2008() override;
220   void emitDirectiveNaNLegacy() override;
221   void emitDirectiveOptionPic0() override;
222   void emitDirectiveOptionPic2() override;
223   void emitDirectiveInsn() override;
224   void emitFrame(unsigned StackReg, unsigned StackSize,
225                  unsigned ReturnReg) override;
226   void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override;
227   void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override;
228
229   void emitDirectiveSetArch(StringRef Arch) override;
230   void emitDirectiveSetMips0() override;
231   void emitDirectiveSetMips1() override;
232   void emitDirectiveSetMips2() override;
233   void emitDirectiveSetMips3() override;
234   void emitDirectiveSetMips4() override;
235   void emitDirectiveSetMips5() override;
236   void emitDirectiveSetMips32() override;
237   void emitDirectiveSetMips32R2() override;
238   void emitDirectiveSetMips32R3() override;
239   void emitDirectiveSetMips32R5() override;
240   void emitDirectiveSetMips32R6() override;
241   void emitDirectiveSetMips64() override;
242   void emitDirectiveSetMips64R2() override;
243   void emitDirectiveSetMips64R3() override;
244   void emitDirectiveSetMips64R5() override;
245   void emitDirectiveSetMips64R6() override;
246   void emitDirectiveSetDsp() override;
247   void emitDirectiveSetNoDsp() override;
248   void emitDirectiveSetPop() override;
249   void emitDirectiveSetPush() override;
250   void emitDirectiveSetSoftFloat() override;
251   void emitDirectiveSetHardFloat() override;
252
253   // PIC support
254   void emitDirectiveCpLoad(unsigned RegNo) override;
255
256   /// Emit a .cprestore directive.  If the offset is out of range then it will
257   /// be synthesized using the assembler temporary.
258   ///
259   /// GetATReg() is a callback that can be used to obtain the current assembler
260   /// temporary and is only called when the assembler temporary is required. It
261   /// must handle the case where no assembler temporary is available (typically
262   /// by reporting an error).
263   bool emitDirectiveCpRestore(int Offset, function_ref<unsigned()> GetATReg,
264                               SMLoc IDLoc, const MCSubtargetInfo *STI) override;
265   void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
266                             const MCSymbol &Sym, bool IsReg) override;
267   void emitDirectiveCpreturn(unsigned SaveLocation,
268                              bool SaveLocationIsRegister) override;
269
270   // FP abiflags directives
271   void emitDirectiveModuleFP() override;
272   void emitDirectiveModuleOddSPReg() override;
273   void emitDirectiveModuleSoftFloat() override;
274   void emitDirectiveModuleHardFloat() override;
275   void emitDirectiveModuleMT() override;
276   void emitDirectiveSetFp(MipsABIFlagsSection::FpABIKind Value) override;
277   void emitDirectiveSetOddSPReg() override;
278   void emitDirectiveSetNoOddSPReg() override;
279 };
280
281 // This part is for ELF object output
282 class MipsTargetELFStreamer : public MipsTargetStreamer {
283   bool MicroMipsEnabled;
284   const MCSubtargetInfo &STI;
285   bool Pic;
286
287 public:
288   bool isMicroMipsEnabled() const { return MicroMipsEnabled; }
289   MCELFStreamer &getStreamer();
290   MipsTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI);
291
292   void setPic(bool Value) override { Pic = Value; }
293
294   void emitLabel(MCSymbol *Symbol) override;
295   void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
296   void finish() override;
297
298   void emitDirectiveSetMicroMips() override;
299   void emitDirectiveSetNoMicroMips() override;
300   void setUsesMicroMips() override;
301   void emitDirectiveSetMips16() override;
302
303   void emitDirectiveSetNoReorder() override;
304   void emitDirectiveEnd(StringRef Name) override;
305
306   void emitDirectiveEnt(const MCSymbol &Symbol) override;
307   void emitDirectiveAbiCalls() override;
308   void emitDirectiveNaN2008() override;
309   void emitDirectiveNaNLegacy() override;
310   void emitDirectiveOptionPic0() override;
311   void emitDirectiveOptionPic2() override;
312   void emitDirectiveInsn() override;
313   void emitFrame(unsigned StackReg, unsigned StackSize,
314                  unsigned ReturnReg) override;
315   void emitMask(unsigned CPUBitmask, int CPUTopSavedRegOff) override;
316   void emitFMask(unsigned FPUBitmask, int FPUTopSavedRegOff) override;
317
318   // PIC support
319   void emitDirectiveCpLoad(unsigned RegNo) override;
320   bool emitDirectiveCpRestore(int Offset, function_ref<unsigned()> GetATReg,
321                               SMLoc IDLoc, const MCSubtargetInfo *STI) override;
322   void emitDirectiveCpsetup(unsigned RegNo, int RegOrOffset,
323                             const MCSymbol &Sym, bool IsReg) override;
324   void emitDirectiveCpreturn(unsigned SaveLocation,
325                              bool SaveLocationIsRegister) override;
326
327   void emitMipsAbiFlags();
328 };
329 }
330 #endif