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